import { JsonPatch, Spec, StreamChunk, EditMode, Catalog, SchemaDefinition } from '@json-render/core'; export { deepMergeSpec, diffToPatches } from '@json-render/core'; /** * Streaming YAML compiler that incrementally parses YAML text and emits * JSON Patch operations for each change detected. * * Same interface shape as `SpecStreamCompiler` from `@json-render/core`. */ interface YamlStreamCompiler { /** Push a chunk of text. Returns the current result and any new patches. */ push(chunk: string): { result: T; newPatches: JsonPatch[]; }; /** Flush remaining buffer and return the final result. */ flush(): { result: T; newPatches: JsonPatch[]; }; /** Get the current compiled result. */ getResult(): T; /** Get all patches that have been applied. */ getPatches(): JsonPatch[]; /** Reset the compiler to initial state. */ reset(initial?: Partial): void; } /** * Create a streaming YAML compiler. * * Incrementally parses YAML text as it arrives and emits JSON Patch * operations by diffing each successful parse against the previous snapshot. * * Uses `yaml.parse()` with YAML 1.2 defaults (the `yaml` v2 default). * YAML 1.2 does not coerce `yes`/`no`/`on`/`off` to booleans. * * @example * ```ts * const compiler = createYamlStreamCompiler(); * compiler.push("root: main\n"); * compiler.push("elements:\n main:\n type: Card\n"); * const { result } = compiler.flush(); * ``` */ declare function createYamlStreamCompiler = Record>(initial?: Partial): YamlStreamCompiler; declare const YAML_SPEC_FENCE = "```yaml-spec"; declare const YAML_EDIT_FENCE = "```yaml-edit"; declare const YAML_PATCH_FENCE = "```yaml-patch"; declare const DIFF_FENCE = "```diff"; declare const FENCE_CLOSE = "```"; interface YamlTransformOptions { /** Seed with a previous spec for multi-turn edit support. */ previousSpec?: Spec; } /** * Creates a `TransformStream` that intercepts AI SDK UI message stream chunks * and converts YAML spec/edit blocks into json-render patch data parts. * * Two fence types are recognised: * * 1. **`\`\`\`yaml-spec`** — Full YAML spec. Parsed progressively, emitting * patches as each new property is detected. * 2. **`\`\`\`yaml-edit`** — Partial YAML. Deep-merged with the current spec, * then diffed to produce patches. Only changed keys need to be included. * * Non-fenced text passes through unchanged as `text-delta` chunks, matching * the behaviour of `createJsonRenderTransform` from `@json-render/core`. */ declare function createYamlTransform(options?: YamlTransformOptions): TransformStream; /** * Convenience wrapper that pipes an AI SDK UI message stream through the * YAML transform, converting YAML spec/edit blocks into json-render patches. * * Drop-in replacement for `pipeJsonRender` from `@json-render/core`. * * @example * ```ts * import { pipeYamlRender } from "@json-render/yaml"; * * const stream = createUIMessageStream({ * execute: async ({ writer }) => { * writer.merge(pipeYamlRender(result.toUIMessageStream())); * }, * }); * return createUIMessageStreamResponse({ stream }); * ``` */ declare function pipeYamlRender(stream: ReadableStream, options?: YamlTransformOptions): ReadableStream; interface YamlPromptOptions { /** Custom system message intro. */ system?: string; /** * - `"standalone"` (default): LLM outputs only the YAML spec (no prose). * - `"inline"`: LLM responds conversationally, then wraps YAML in a fence. */ mode?: "standalone" | "inline"; /** Additional rules appended to the RULES section. */ customRules?: string[]; /** Edit modes to document. Default: `["merge"]` (yaml-edit). */ editModes?: EditMode[]; } /** * Generate a YAML-format system prompt from any json-render catalog. * * Works with catalogs from any renderer (`@json-render/react`, * `@json-render/vue`, etc.) — it only reads the catalog metadata. * * @example * ```ts * import { yamlPrompt } from "@json-render/yaml"; * const systemPrompt = yamlPrompt(catalog, { mode: "inline" }); * ``` */ declare function yamlPrompt(catalog: Catalog, options?: YamlPromptOptions): string; export { DIFF_FENCE, FENCE_CLOSE, YAML_EDIT_FENCE, YAML_PATCH_FENCE, YAML_SPEC_FENCE, type YamlPromptOptions, type YamlStreamCompiler, createYamlStreamCompiler, createYamlTransform, pipeYamlRender, yamlPrompt };