@ai-gui/core 0.32.0 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -2660,19 +2660,52 @@ function isReadableStream$1(source) {
2660
2660
  //#endregion
2661
2661
  //#region src/build-system-prompt.ts
2662
2662
  /**
2663
+ * How to write a block, said once, before anything that describes one.
2664
+ *
2665
+ * Models reliably compress a fenced block onto a single line — opening fence,
2666
+ * name, payload and closing fence all together — and that is not a block at all: a
2667
+ * fence's info string may not contain backticks, so CommonMark reads the line
2668
+ * as an inline code span. The reader gets raw JSON running through the middle
2669
+ * of a sentence and no list. The mistake is invisible to the model, which
2670
+ * emitted valid-looking markup and never sees the page.
2671
+ *
2672
+ * Every spec below therefore shows the multi-line shape, and this states the
2673
+ * rule outright rather than leaving it to be inferred from examples.
2674
+ */
2675
+ const FENCING = {
2676
+ en: { rule: [
2677
+ "Blocks are fenced code blocks written across several lines: ``` and the block name on one",
2678
+ "line, the content on the lines after it, and ``` alone on the closing line. Never put the",
2679
+ "whole block on one line — that is inline code, not a block, and it renders as raw text."
2680
+ ].join("\n") },
2681
+ "zh-CN": { rule: ["块都是跨行写的围栏代码块:``` 和块名占一行,内容写在后面的行上,最后单独一行 ```。", "不要把整个块挤在一行——那是行内代码,不是块,会原样显示成一堆文本。"].join("\n") }
2682
+ };
2683
+ /**
2684
+ * The fencing rule in one locale.
2685
+ *
2686
+ * Exported for hosts that assemble the guidance themselves instead of calling
2687
+ * `buildSystemPrompt`; that function already includes it.
2688
+ */
2689
+ function fencingRule(locale) {
2690
+ return translate(FENCING, locale, "rule");
2691
+ }
2692
+ /**
2663
2693
  * Assembles the LLM system-prompt guidance: an optional base, the registered
2664
2694
  * cards' spec, and every plugin's promptSpec. Consumers prepend this to their
2665
2695
  * own system prompt so the model knows which fenced blocks it may emit.
2666
2696
  */
2667
2697
  function buildSystemPrompt(options = {}) {
2668
- const parts = [];
2669
- if (options.base) parts.push(options.base);
2698
+ const specs = [];
2670
2699
  const cardSpec = options.registry?.toPromptSpec();
2671
- if (cardSpec) parts.push(cardSpec);
2700
+ if (cardSpec) specs.push(cardSpec);
2672
2701
  for (const plugin of options.plugins ?? []) {
2673
2702
  const spec = typeof plugin.promptSpec === "function" ? plugin.promptSpec(options.locale) : plugin.promptSpec;
2674
- if (spec) parts.push(spec);
2703
+ if (spec) specs.push(spec);
2675
2704
  }
2705
+ const parts = [];
2706
+ if (options.base) parts.push(options.base);
2707
+ if (specs.length > 0) parts.push(fencingRule(options.locale));
2708
+ parts.push(...specs);
2676
2709
  return parts.join("\n\n");
2677
2710
  }
2678
2711
 
@@ -3006,6 +3039,7 @@ exports.diffAst = diffAst
3006
3039
  exports.downloadImage = downloadImage
3007
3040
  exports.exportRenderedImages = exportRenderedImages
3008
3041
  exports.exportSVGToImage = exportSVGToImage
3042
+ exports.fencingRule = fencingRule
3009
3043
  exports.getActionKey = getActionKey
3010
3044
  exports.getIdleActionState = getIdleActionState
3011
3045
  exports.injectPluginStyles = injectPluginStyles
package/dist/index.d.cts CHANGED
@@ -970,6 +970,13 @@ declare class StreamRouter {
970
970
 
971
971
  //#endregion
972
972
  //#region src/build-system-prompt.d.ts
973
+ /**
974
+ * The fencing rule in one locale.
975
+ *
976
+ * Exported for hosts that assemble the guidance themselves instead of calling
977
+ * `buildSystemPrompt`; that function already includes it.
978
+ */
979
+ declare function fencingRule(locale?: string): string;
973
980
  interface BuildSystemPromptOptions {
974
981
  base?: string;
975
982
  registry?: CardRegistry;
@@ -1052,4 +1059,4 @@ declare function mockModelStream(events: Iterable<ModelStreamEvent> | AsyncItera
1052
1059
  declare function readableBytes(chunks: Iterable<string | Uint8Array> | AsyncIterable<string | Uint8Array>): ReadableStream<Uint8Array>;
1053
1060
 
1054
1061
  //#endregion
1055
- export { AIGuiPlugin, ASTNode, ActionAbortedError, ActionAlreadyRegisteredError, ActionContext, ActionDefinition, ActionDestroyedError, ActionDispatchOptions, ActionErrorEvent, ActionEventBase, ActionExecutionError, ActionNotFoundError, ActionOutcome, ActionRegisterOptions, ActionRegistry, ActionRequest, ActionRuntime, ActionRuntimeError, ActionRuntimeOptions, ActionStartEvent, ActionState, ActionStateListener, ActionStatus, ActionSuccessEvent, ActionTimeoutError, ActionValidationError, BuildSystemPromptOptions, ByteStreamSource, CARD_ID_MAX_LENGTH, CARD_JSON_MAX_DEPTH, CARD_JSON_MAX_NODES, CARD_PATCH_BATCH_MAX_SIZE, CardAction, CardActionError, CardChannelOptions, CardDef, CardJSONError, CardLimitError, CardListener, CardMessage, CardNotFoundError, CardParseResult, CardPatch, CardPatchBatch, CardPatchResult, CardRecord, CardRegistry, CardRevisionConflictError, CardSnapshot, CardSnapshotError, CardStore, CardStoreError, CardStoreListener, CardStoreOptions, CardTypeConflictError, CardValidationError, ChannelSink, Citation, CollectNodeRendererOptions, DEFAULT_LOCALE, DebugEmitter, DebugEvent, DebugEventListener, DebugEventTarget, DebugInstrumentationTarget, DebugOptions, DebugRedactContext, DebugSource, ExportImageOptions, ExportedImage, FeedChunk, FeedOptions, FeedSource, JSONSchema, JSONSchemaValidationResult, Locale, MessageBundle, Messages, ModelStreamEvent, MountCardSlotRequest, MountedCardSlot, NodeRenderContext, NodeRenderer, OutcomeTone, ParseResult, ParserOptions, PartialJSONResult, Patch, PluginCommitContext, PluginSource, PluginStyle, PluginsLoader, RenderMountContext, RenderOutput, Renderer, RendererOptions, SSEEvent, SSEOptions, SafeDebugValueOptions, SanitizeHtmlOptions, SanitizeSetting, SourceBlock, StreamParseOptions, StreamRouter, Usage, actionOutcome, applyPatches, assertPlugins, availableLocales, baseCss, buildSystemPrompt, cardChannel, collectNodeRenderers, collectPluginStyles, contentDeltas, createActionRuntime, createParser, createParserWithMetadata, diffAst, downloadImage, exportRenderedImages, exportSVGToImage, getActionKey, getIdleActionState, injectPluginStyles, isCardPatchResult, jsonLines, loadPlugins, mockModelStream, ndjson, parsePartialJSON, parseSSE, pluginNodeTypes, readableBytes, repairMarkdown, resolveMessages, safeDebugValue, samePlugins, sanitizeHtml, sanitizeRenderedHtml, textLines, translate, translator, validateJSONSchema };
1062
+ export { AIGuiPlugin, ASTNode, ActionAbortedError, ActionAlreadyRegisteredError, ActionContext, ActionDefinition, ActionDestroyedError, ActionDispatchOptions, ActionErrorEvent, ActionEventBase, ActionExecutionError, ActionNotFoundError, ActionOutcome, ActionRegisterOptions, ActionRegistry, ActionRequest, ActionRuntime, ActionRuntimeError, ActionRuntimeOptions, ActionStartEvent, ActionState, ActionStateListener, ActionStatus, ActionSuccessEvent, ActionTimeoutError, ActionValidationError, BuildSystemPromptOptions, ByteStreamSource, CARD_ID_MAX_LENGTH, CARD_JSON_MAX_DEPTH, CARD_JSON_MAX_NODES, CARD_PATCH_BATCH_MAX_SIZE, CardAction, CardActionError, CardChannelOptions, CardDef, CardJSONError, CardLimitError, CardListener, CardMessage, CardNotFoundError, CardParseResult, CardPatch, CardPatchBatch, CardPatchResult, CardRecord, CardRegistry, CardRevisionConflictError, CardSnapshot, CardSnapshotError, CardStore, CardStoreError, CardStoreListener, CardStoreOptions, CardTypeConflictError, CardValidationError, ChannelSink, Citation, CollectNodeRendererOptions, DEFAULT_LOCALE, DebugEmitter, DebugEvent, DebugEventListener, DebugEventTarget, DebugInstrumentationTarget, DebugOptions, DebugRedactContext, DebugSource, ExportImageOptions, ExportedImage, FeedChunk, FeedOptions, FeedSource, JSONSchema, JSONSchemaValidationResult, Locale, MessageBundle, Messages, ModelStreamEvent, MountCardSlotRequest, MountedCardSlot, NodeRenderContext, NodeRenderer, OutcomeTone, ParseResult, ParserOptions, PartialJSONResult, Patch, PluginCommitContext, PluginSource, PluginStyle, PluginsLoader, RenderMountContext, RenderOutput, Renderer, RendererOptions, SSEEvent, SSEOptions, SafeDebugValueOptions, SanitizeHtmlOptions, SanitizeSetting, SourceBlock, StreamParseOptions, StreamRouter, Usage, actionOutcome, applyPatches, assertPlugins, availableLocales, baseCss, buildSystemPrompt, cardChannel, collectNodeRenderers, collectPluginStyles, contentDeltas, createActionRuntime, createParser, createParserWithMetadata, diffAst, downloadImage, exportRenderedImages, exportSVGToImage, fencingRule, getActionKey, getIdleActionState, injectPluginStyles, isCardPatchResult, jsonLines, loadPlugins, mockModelStream, ndjson, parsePartialJSON, parseSSE, pluginNodeTypes, readableBytes, repairMarkdown, resolveMessages, safeDebugValue, samePlugins, sanitizeHtml, sanitizeRenderedHtml, textLines, translate, translator, validateJSONSchema };
package/dist/index.d.ts CHANGED
@@ -970,6 +970,13 @@ declare class StreamRouter {
970
970
 
971
971
  //#endregion
972
972
  //#region src/build-system-prompt.d.ts
973
+ /**
974
+ * The fencing rule in one locale.
975
+ *
976
+ * Exported for hosts that assemble the guidance themselves instead of calling
977
+ * `buildSystemPrompt`; that function already includes it.
978
+ */
979
+ declare function fencingRule(locale?: string): string;
973
980
  interface BuildSystemPromptOptions {
974
981
  base?: string;
975
982
  registry?: CardRegistry;
@@ -1052,4 +1059,4 @@ declare function mockModelStream(events: Iterable<ModelStreamEvent> | AsyncItera
1052
1059
  declare function readableBytes(chunks: Iterable<string | Uint8Array> | AsyncIterable<string | Uint8Array>): ReadableStream<Uint8Array>;
1053
1060
 
1054
1061
  //#endregion
1055
- export { AIGuiPlugin, ASTNode, ActionAbortedError, ActionAlreadyRegisteredError, ActionContext, ActionDefinition, ActionDestroyedError, ActionDispatchOptions, ActionErrorEvent, ActionEventBase, ActionExecutionError, ActionNotFoundError, ActionOutcome, ActionRegisterOptions, ActionRegistry, ActionRequest, ActionRuntime, ActionRuntimeError, ActionRuntimeOptions, ActionStartEvent, ActionState, ActionStateListener, ActionStatus, ActionSuccessEvent, ActionTimeoutError, ActionValidationError, BuildSystemPromptOptions, ByteStreamSource, CARD_ID_MAX_LENGTH, CARD_JSON_MAX_DEPTH, CARD_JSON_MAX_NODES, CARD_PATCH_BATCH_MAX_SIZE, CardAction, CardActionError, CardChannelOptions, CardDef, CardJSONError, CardLimitError, CardListener, CardMessage, CardNotFoundError, CardParseResult, CardPatch, CardPatchBatch, CardPatchResult, CardRecord, CardRegistry, CardRevisionConflictError, CardSnapshot, CardSnapshotError, CardStore, CardStoreError, CardStoreListener, CardStoreOptions, CardTypeConflictError, CardValidationError, ChannelSink, Citation, CollectNodeRendererOptions, DEFAULT_LOCALE, DebugEmitter, DebugEvent, DebugEventListener, DebugEventTarget, DebugInstrumentationTarget, DebugOptions, DebugRedactContext, DebugSource, ExportImageOptions, ExportedImage, FeedChunk, FeedOptions, FeedSource, JSONSchema, JSONSchemaValidationResult, Locale, MessageBundle, Messages, ModelStreamEvent, MountCardSlotRequest, MountedCardSlot, NodeRenderContext, NodeRenderer, OutcomeTone, ParseResult, ParserOptions, PartialJSONResult, Patch, PluginCommitContext, PluginSource, PluginStyle, PluginsLoader, RenderMountContext, RenderOutput, Renderer, RendererOptions, SSEEvent, SSEOptions, SafeDebugValueOptions, SanitizeHtmlOptions, SanitizeSetting, SourceBlock, StreamParseOptions, StreamRouter, Usage, actionOutcome, applyPatches, assertPlugins, availableLocales, baseCss, buildSystemPrompt, cardChannel, collectNodeRenderers, collectPluginStyles, contentDeltas, createActionRuntime, createParser, createParserWithMetadata, diffAst, downloadImage, exportRenderedImages, exportSVGToImage, getActionKey, getIdleActionState, injectPluginStyles, isCardPatchResult, jsonLines, loadPlugins, mockModelStream, ndjson, parsePartialJSON, parseSSE, pluginNodeTypes, readableBytes, repairMarkdown, resolveMessages, safeDebugValue, samePlugins, sanitizeHtml, sanitizeRenderedHtml, textLines, translate, translator, validateJSONSchema };
1062
+ export { AIGuiPlugin, ASTNode, ActionAbortedError, ActionAlreadyRegisteredError, ActionContext, ActionDefinition, ActionDestroyedError, ActionDispatchOptions, ActionErrorEvent, ActionEventBase, ActionExecutionError, ActionNotFoundError, ActionOutcome, ActionRegisterOptions, ActionRegistry, ActionRequest, ActionRuntime, ActionRuntimeError, ActionRuntimeOptions, ActionStartEvent, ActionState, ActionStateListener, ActionStatus, ActionSuccessEvent, ActionTimeoutError, ActionValidationError, BuildSystemPromptOptions, ByteStreamSource, CARD_ID_MAX_LENGTH, CARD_JSON_MAX_DEPTH, CARD_JSON_MAX_NODES, CARD_PATCH_BATCH_MAX_SIZE, CardAction, CardActionError, CardChannelOptions, CardDef, CardJSONError, CardLimitError, CardListener, CardMessage, CardNotFoundError, CardParseResult, CardPatch, CardPatchBatch, CardPatchResult, CardRecord, CardRegistry, CardRevisionConflictError, CardSnapshot, CardSnapshotError, CardStore, CardStoreError, CardStoreListener, CardStoreOptions, CardTypeConflictError, CardValidationError, ChannelSink, Citation, CollectNodeRendererOptions, DEFAULT_LOCALE, DebugEmitter, DebugEvent, DebugEventListener, DebugEventTarget, DebugInstrumentationTarget, DebugOptions, DebugRedactContext, DebugSource, ExportImageOptions, ExportedImage, FeedChunk, FeedOptions, FeedSource, JSONSchema, JSONSchemaValidationResult, Locale, MessageBundle, Messages, ModelStreamEvent, MountCardSlotRequest, MountedCardSlot, NodeRenderContext, NodeRenderer, OutcomeTone, ParseResult, ParserOptions, PartialJSONResult, Patch, PluginCommitContext, PluginSource, PluginStyle, PluginsLoader, RenderMountContext, RenderOutput, Renderer, RendererOptions, SSEEvent, SSEOptions, SafeDebugValueOptions, SanitizeHtmlOptions, SanitizeSetting, SourceBlock, StreamParseOptions, StreamRouter, Usage, actionOutcome, applyPatches, assertPlugins, availableLocales, baseCss, buildSystemPrompt, cardChannel, collectNodeRenderers, collectPluginStyles, contentDeltas, createActionRuntime, createParser, createParserWithMetadata, diffAst, downloadImage, exportRenderedImages, exportSVGToImage, fencingRule, getActionKey, getIdleActionState, injectPluginStyles, isCardPatchResult, jsonLines, loadPlugins, mockModelStream, ndjson, parsePartialJSON, parseSSE, pluginNodeTypes, readableBytes, repairMarkdown, resolveMessages, safeDebugValue, samePlugins, sanitizeHtml, sanitizeRenderedHtml, textLines, translate, translator, validateJSONSchema };
package/dist/index.js CHANGED
@@ -2636,19 +2636,52 @@ function isReadableStream$1(source) {
2636
2636
  //#endregion
2637
2637
  //#region src/build-system-prompt.ts
2638
2638
  /**
2639
+ * How to write a block, said once, before anything that describes one.
2640
+ *
2641
+ * Models reliably compress a fenced block onto a single line — opening fence,
2642
+ * name, payload and closing fence all together — and that is not a block at all: a
2643
+ * fence's info string may not contain backticks, so CommonMark reads the line
2644
+ * as an inline code span. The reader gets raw JSON running through the middle
2645
+ * of a sentence and no list. The mistake is invisible to the model, which
2646
+ * emitted valid-looking markup and never sees the page.
2647
+ *
2648
+ * Every spec below therefore shows the multi-line shape, and this states the
2649
+ * rule outright rather than leaving it to be inferred from examples.
2650
+ */
2651
+ const FENCING = {
2652
+ en: { rule: [
2653
+ "Blocks are fenced code blocks written across several lines: ``` and the block name on one",
2654
+ "line, the content on the lines after it, and ``` alone on the closing line. Never put the",
2655
+ "whole block on one line — that is inline code, not a block, and it renders as raw text."
2656
+ ].join("\n") },
2657
+ "zh-CN": { rule: ["块都是跨行写的围栏代码块:``` 和块名占一行,内容写在后面的行上,最后单独一行 ```。", "不要把整个块挤在一行——那是行内代码,不是块,会原样显示成一堆文本。"].join("\n") }
2658
+ };
2659
+ /**
2660
+ * The fencing rule in one locale.
2661
+ *
2662
+ * Exported for hosts that assemble the guidance themselves instead of calling
2663
+ * `buildSystemPrompt`; that function already includes it.
2664
+ */
2665
+ function fencingRule(locale) {
2666
+ return translate(FENCING, locale, "rule");
2667
+ }
2668
+ /**
2639
2669
  * Assembles the LLM system-prompt guidance: an optional base, the registered
2640
2670
  * cards' spec, and every plugin's promptSpec. Consumers prepend this to their
2641
2671
  * own system prompt so the model knows which fenced blocks it may emit.
2642
2672
  */
2643
2673
  function buildSystemPrompt(options = {}) {
2644
- const parts = [];
2645
- if (options.base) parts.push(options.base);
2674
+ const specs = [];
2646
2675
  const cardSpec = options.registry?.toPromptSpec();
2647
- if (cardSpec) parts.push(cardSpec);
2676
+ if (cardSpec) specs.push(cardSpec);
2648
2677
  for (const plugin of options.plugins ?? []) {
2649
2678
  const spec = typeof plugin.promptSpec === "function" ? plugin.promptSpec(options.locale) : plugin.promptSpec;
2650
- if (spec) parts.push(spec);
2679
+ if (spec) specs.push(spec);
2651
2680
  }
2681
+ const parts = [];
2682
+ if (options.base) parts.push(options.base);
2683
+ if (specs.length > 0) parts.push(fencingRule(options.locale));
2684
+ parts.push(...specs);
2652
2685
  return parts.join("\n\n");
2653
2686
  }
2654
2687
 
@@ -2937,4 +2970,4 @@ function delay(ms, signal) {
2937
2970
  }
2938
2971
 
2939
2972
  //#endregion
2940
- export { ActionAbortedError, ActionAlreadyRegisteredError, ActionDestroyedError, ActionExecutionError, ActionNotFoundError, ActionRegistry, ActionRuntime, ActionRuntimeError, ActionTimeoutError, ActionValidationError, CARD_ID_MAX_LENGTH, CARD_JSON_MAX_DEPTH, CARD_JSON_MAX_NODES, CARD_PATCH_BATCH_MAX_SIZE, CardJSONError, CardLimitError, CardNotFoundError, CardRegistry, CardRevisionConflictError, CardSnapshotError, CardStore, CardStoreError, CardTypeConflictError, CardValidationError, DEFAULT_LOCALE, DebugEmitter, Renderer, StreamRouter, actionOutcome, applyPatches, assertPlugins, availableLocales, baseCss, buildSystemPrompt, cardChannel, collectNodeRenderers, collectPluginStyles, contentDeltas, createActionRuntime, createParser, createParserWithMetadata, diffAst, downloadImage, exportRenderedImages, exportSVGToImage, getActionKey, getIdleActionState, injectPluginStyles, isCardPatchResult, jsonLines, loadPlugins, mockModelStream, ndjson, parsePartialJSON, parseSSE, pluginNodeTypes, readableBytes, repairMarkdown, resolveMessages, safeDebugValue, samePlugins, sanitizeHtml, sanitizeRenderedHtml, textLines, translate, translator, validateJSONSchema };
2973
+ export { ActionAbortedError, ActionAlreadyRegisteredError, ActionDestroyedError, ActionExecutionError, ActionNotFoundError, ActionRegistry, ActionRuntime, ActionRuntimeError, ActionTimeoutError, ActionValidationError, CARD_ID_MAX_LENGTH, CARD_JSON_MAX_DEPTH, CARD_JSON_MAX_NODES, CARD_PATCH_BATCH_MAX_SIZE, CardJSONError, CardLimitError, CardNotFoundError, CardRegistry, CardRevisionConflictError, CardSnapshotError, CardStore, CardStoreError, CardTypeConflictError, CardValidationError, DEFAULT_LOCALE, DebugEmitter, Renderer, StreamRouter, actionOutcome, applyPatches, assertPlugins, availableLocales, baseCss, buildSystemPrompt, cardChannel, collectNodeRenderers, collectPluginStyles, contentDeltas, createActionRuntime, createParser, createParserWithMetadata, diffAst, downloadImage, exportRenderedImages, exportSVGToImage, fencingRule, getActionKey, getIdleActionState, injectPluginStyles, isCardPatchResult, jsonLines, loadPlugins, mockModelStream, ndjson, parsePartialJSON, parseSSE, pluginNodeTypes, readableBytes, repairMarkdown, resolveMessages, safeDebugValue, samePlugins, sanitizeHtml, sanitizeRenderedHtml, textLines, translate, translator, validateJSONSchema };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-gui/core",
3
- "version": "0.32.0",
3
+ "version": "0.34.0",
4
4
  "description": "Headless streaming renderer core for LLM-generated UI — markdown/JSON repair, card registry, AST diff, plugin engine, sanitizer.",
5
5
  "keywords": [
6
6
  "llm",