@ai-gui/core 0.22.1 → 0.23.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 +27 -0
- package/dist/index.d.cts +19 -4
- package/dist/index.d.ts +19 -4
- package/dist/index.js +27 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1466,8 +1466,32 @@ function samePlugins(a, b) {
|
|
|
1466
1466
|
if (!a || !b || a.length !== b.length) return false;
|
|
1467
1467
|
return a.every((plugin, index) => plugin === b[index]);
|
|
1468
1468
|
}
|
|
1469
|
+
/**
|
|
1470
|
+
* Reject anything in the list that is not a plugin, naming what to do about it.
|
|
1471
|
+
*
|
|
1472
|
+
* Every plugin package exports a factory, so `plugins: [katex]` instead of `plugins: [katex()]` is
|
|
1473
|
+
* the easiest mistake to make — and it used to be the quietest. A function has a `name` of its
|
|
1474
|
+
* own, `"katex"`, so the renderer accepted it, found no `extendParser` and no `nodeRenderers`, and
|
|
1475
|
+
* did nothing: no error, no warning, markdown still rendering, only the maths and the diagrams
|
|
1476
|
+
* missing. A product can ship like that and nobody notices until someone asks why an equation is
|
|
1477
|
+
* plain text. Misconfiguration should be loud, so this throws.
|
|
1478
|
+
*/
|
|
1479
|
+
function assertPlugins(plugins, label = "plugins") {
|
|
1480
|
+
if (!plugins) return;
|
|
1481
|
+
plugins.forEach((plugin, index) => {
|
|
1482
|
+
const at = `${label}[${index}]`;
|
|
1483
|
+
if (typeof plugin === "function") {
|
|
1484
|
+
const called = plugin.name ? `${plugin.name}()` : "the factory";
|
|
1485
|
+
throw new TypeError(`${at} is a factory function, not a plugin. Call it: ${called}`);
|
|
1486
|
+
}
|
|
1487
|
+
if (plugin === null || typeof plugin !== "object") throw new TypeError(`${at} is ${plugin === null ? "null" : typeof plugin}, not a plugin object`);
|
|
1488
|
+
const { name } = plugin;
|
|
1489
|
+
if (typeof name !== "string" || name.length === 0) throw new TypeError(`${at} has no \`name\`. A plugin needs one: its stylesheet and its debug events are keyed by it`);
|
|
1490
|
+
});
|
|
1491
|
+
}
|
|
1469
1492
|
/** Merge every plugin's `nodeRenderers` into a single map (later plugins win). */
|
|
1470
1493
|
function collectNodeRenderers(plugins = [], debugOptions = {}) {
|
|
1494
|
+
assertPlugins(plugins);
|
|
1471
1495
|
const map = {};
|
|
1472
1496
|
const target = debugOptions.debugTarget;
|
|
1473
1497
|
const debug = target ? void 0 : debugOptions.debug === true ? new DebugEmitter("renderer", debugOptions) : void 0;
|
|
@@ -2069,6 +2093,7 @@ var Renderer = class {
|
|
|
2069
2093
|
debug;
|
|
2070
2094
|
constructor(options = {}) {
|
|
2071
2095
|
this.options = options;
|
|
2096
|
+
assertPlugins(options.plugins);
|
|
2072
2097
|
this.debug = new DebugEmitter(this.debugSource, options);
|
|
2073
2098
|
this.sanitize = options.sanitize === false ? false : typeof options.sanitize === "object" ? options.sanitize : {};
|
|
2074
2099
|
this.registerPluginCards(options.plugins);
|
|
@@ -2094,6 +2119,7 @@ var Renderer = class {
|
|
|
2094
2119
|
* Passing the same plugins again is a no-op, so a host may call this on every render.
|
|
2095
2120
|
*/
|
|
2096
2121
|
setPlugins(plugins) {
|
|
2122
|
+
assertPlugins(plugins);
|
|
2097
2123
|
if (samePlugins(this.options.plugins, plugins)) return;
|
|
2098
2124
|
this.options = {
|
|
2099
2125
|
...this.options,
|
|
@@ -2889,6 +2915,7 @@ exports.Renderer = Renderer
|
|
|
2889
2915
|
exports.StreamRouter = StreamRouter
|
|
2890
2916
|
exports.actionOutcome = actionOutcome
|
|
2891
2917
|
exports.applyPatches = applyPatches
|
|
2918
|
+
exports.assertPlugins = assertPlugins
|
|
2892
2919
|
exports.availableLocales = availableLocales
|
|
2893
2920
|
exports.baseCss = baseCss
|
|
2894
2921
|
exports.buildSystemPrompt = buildSystemPrompt
|
package/dist/index.d.cts
CHANGED
|
@@ -255,6 +255,12 @@ interface AIGuiPlugin {
|
|
|
255
255
|
/**
|
|
256
256
|
* LLM-facing guidance describing this plugin's fence syntax.
|
|
257
257
|
*
|
|
258
|
+
* A host does not read this field itself: `buildSystemPrompt({ registry, plugins, locale })`
|
|
259
|
+
* collects the card specs and every enabled plugin's spec in one call, already in the product's
|
|
260
|
+
* language. Assembling it by hand — reading each plugin's spec, joining them, writing the
|
|
261
|
+
* localized wording again — reinvents that badly, and a plugin added later is then missing from
|
|
262
|
+
* the prompt while its renderer is installed.
|
|
263
|
+
*
|
|
258
264
|
* Receives the locale asked of `buildSystemPrompt`, so the rules can be written in the language
|
|
259
265
|
* the product answers in — a Chinese persona followed by English rules reads as a contradiction
|
|
260
266
|
* to the model. Plugins that only ship English simply ignore the argument.
|
|
@@ -284,9 +290,7 @@ interface FeedOptions {
|
|
|
284
290
|
signal?: AbortSignal;
|
|
285
291
|
}
|
|
286
292
|
type FeedChunk = string | Uint8Array;
|
|
287
|
-
type FeedSource = AsyncIterable<FeedChunk> | ReadableStream<FeedChunk>;
|
|
288
|
-
|
|
289
|
-
//#endregion
|
|
293
|
+
type FeedSource = AsyncIterable<FeedChunk> | ReadableStream<FeedChunk>; //#endregion
|
|
290
294
|
//#region src/card-registry.d.ts
|
|
291
295
|
interface CardParseResult {
|
|
292
296
|
data: unknown;
|
|
@@ -684,6 +688,17 @@ declare function loadPlugins(source?: PluginSource): AIGuiPlugin[] | Promise<AIG
|
|
|
684
688
|
* What matters is the members, not the array.
|
|
685
689
|
*/
|
|
686
690
|
declare function samePlugins(a?: AIGuiPlugin[], b?: AIGuiPlugin[]): boolean;
|
|
691
|
+
/**
|
|
692
|
+
* Reject anything in the list that is not a plugin, naming what to do about it.
|
|
693
|
+
*
|
|
694
|
+
* Every plugin package exports a factory, so `plugins: [katex]` instead of `plugins: [katex()]` is
|
|
695
|
+
* the easiest mistake to make — and it used to be the quietest. A function has a `name` of its
|
|
696
|
+
* own, `"katex"`, so the renderer accepted it, found no `extendParser` and no `nodeRenderers`, and
|
|
697
|
+
* did nothing: no error, no warning, markdown still rendering, only the maths and the diagrams
|
|
698
|
+
* missing. A product can ship like that and nobody notices until someone asks why an equation is
|
|
699
|
+
* plain text. Misconfiguration should be loud, so this throws.
|
|
700
|
+
*/
|
|
701
|
+
declare function assertPlugins(plugins: readonly unknown[] | undefined, label?: string): void;
|
|
687
702
|
/** Merge every plugin's `nodeRenderers` into a single map (later plugins win). */
|
|
688
703
|
declare function collectNodeRenderers(plugins?: AIGuiPlugin[], debugOptions?: CollectNodeRendererOptions): Record<string, NodeRenderer>;
|
|
689
704
|
/** The set of node types claimed by the given plugins. */
|
|
@@ -985,4 +1000,4 @@ declare function mockModelStream(events: Iterable<ModelStreamEvent> | AsyncItera
|
|
|
985
1000
|
declare function readableBytes(chunks: Iterable<string | Uint8Array> | AsyncIterable<string | Uint8Array>): ReadableStream<Uint8Array>;
|
|
986
1001
|
|
|
987
1002
|
//#endregion
|
|
988
|
-
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, CardDef, CardJSONError, CardLimitError, CardListener, 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, availableLocales, baseCss, buildSystemPrompt, 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 };
|
|
1003
|
+
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, CardDef, CardJSONError, CardLimitError, CardListener, 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, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -255,6 +255,12 @@ interface AIGuiPlugin {
|
|
|
255
255
|
/**
|
|
256
256
|
* LLM-facing guidance describing this plugin's fence syntax.
|
|
257
257
|
*
|
|
258
|
+
* A host does not read this field itself: `buildSystemPrompt({ registry, plugins, locale })`
|
|
259
|
+
* collects the card specs and every enabled plugin's spec in one call, already in the product's
|
|
260
|
+
* language. Assembling it by hand — reading each plugin's spec, joining them, writing the
|
|
261
|
+
* localized wording again — reinvents that badly, and a plugin added later is then missing from
|
|
262
|
+
* the prompt while its renderer is installed.
|
|
263
|
+
*
|
|
258
264
|
* Receives the locale asked of `buildSystemPrompt`, so the rules can be written in the language
|
|
259
265
|
* the product answers in — a Chinese persona followed by English rules reads as a contradiction
|
|
260
266
|
* to the model. Plugins that only ship English simply ignore the argument.
|
|
@@ -284,9 +290,7 @@ interface FeedOptions {
|
|
|
284
290
|
signal?: AbortSignal;
|
|
285
291
|
}
|
|
286
292
|
type FeedChunk = string | Uint8Array;
|
|
287
|
-
type FeedSource = AsyncIterable<FeedChunk> | ReadableStream<FeedChunk>;
|
|
288
|
-
|
|
289
|
-
//#endregion
|
|
293
|
+
type FeedSource = AsyncIterable<FeedChunk> | ReadableStream<FeedChunk>; //#endregion
|
|
290
294
|
//#region src/card-registry.d.ts
|
|
291
295
|
interface CardParseResult {
|
|
292
296
|
data: unknown;
|
|
@@ -684,6 +688,17 @@ declare function loadPlugins(source?: PluginSource): AIGuiPlugin[] | Promise<AIG
|
|
|
684
688
|
* What matters is the members, not the array.
|
|
685
689
|
*/
|
|
686
690
|
declare function samePlugins(a?: AIGuiPlugin[], b?: AIGuiPlugin[]): boolean;
|
|
691
|
+
/**
|
|
692
|
+
* Reject anything in the list that is not a plugin, naming what to do about it.
|
|
693
|
+
*
|
|
694
|
+
* Every plugin package exports a factory, so `plugins: [katex]` instead of `plugins: [katex()]` is
|
|
695
|
+
* the easiest mistake to make — and it used to be the quietest. A function has a `name` of its
|
|
696
|
+
* own, `"katex"`, so the renderer accepted it, found no `extendParser` and no `nodeRenderers`, and
|
|
697
|
+
* did nothing: no error, no warning, markdown still rendering, only the maths and the diagrams
|
|
698
|
+
* missing. A product can ship like that and nobody notices until someone asks why an equation is
|
|
699
|
+
* plain text. Misconfiguration should be loud, so this throws.
|
|
700
|
+
*/
|
|
701
|
+
declare function assertPlugins(plugins: readonly unknown[] | undefined, label?: string): void;
|
|
687
702
|
/** Merge every plugin's `nodeRenderers` into a single map (later plugins win). */
|
|
688
703
|
declare function collectNodeRenderers(plugins?: AIGuiPlugin[], debugOptions?: CollectNodeRendererOptions): Record<string, NodeRenderer>;
|
|
689
704
|
/** The set of node types claimed by the given plugins. */
|
|
@@ -985,4 +1000,4 @@ declare function mockModelStream(events: Iterable<ModelStreamEvent> | AsyncItera
|
|
|
985
1000
|
declare function readableBytes(chunks: Iterable<string | Uint8Array> | AsyncIterable<string | Uint8Array>): ReadableStream<Uint8Array>;
|
|
986
1001
|
|
|
987
1002
|
//#endregion
|
|
988
|
-
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, CardDef, CardJSONError, CardLimitError, CardListener, 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, availableLocales, baseCss, buildSystemPrompt, 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 };
|
|
1003
|
+
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, CardDef, CardJSONError, CardLimitError, CardListener, 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, 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 };
|
package/dist/index.js
CHANGED
|
@@ -1442,8 +1442,32 @@ function samePlugins(a, b) {
|
|
|
1442
1442
|
if (!a || !b || a.length !== b.length) return false;
|
|
1443
1443
|
return a.every((plugin, index) => plugin === b[index]);
|
|
1444
1444
|
}
|
|
1445
|
+
/**
|
|
1446
|
+
* Reject anything in the list that is not a plugin, naming what to do about it.
|
|
1447
|
+
*
|
|
1448
|
+
* Every plugin package exports a factory, so `plugins: [katex]` instead of `plugins: [katex()]` is
|
|
1449
|
+
* the easiest mistake to make — and it used to be the quietest. A function has a `name` of its
|
|
1450
|
+
* own, `"katex"`, so the renderer accepted it, found no `extendParser` and no `nodeRenderers`, and
|
|
1451
|
+
* did nothing: no error, no warning, markdown still rendering, only the maths and the diagrams
|
|
1452
|
+
* missing. A product can ship like that and nobody notices until someone asks why an equation is
|
|
1453
|
+
* plain text. Misconfiguration should be loud, so this throws.
|
|
1454
|
+
*/
|
|
1455
|
+
function assertPlugins(plugins, label = "plugins") {
|
|
1456
|
+
if (!plugins) return;
|
|
1457
|
+
plugins.forEach((plugin, index) => {
|
|
1458
|
+
const at = `${label}[${index}]`;
|
|
1459
|
+
if (typeof plugin === "function") {
|
|
1460
|
+
const called = plugin.name ? `${plugin.name}()` : "the factory";
|
|
1461
|
+
throw new TypeError(`${at} is a factory function, not a plugin. Call it: ${called}`);
|
|
1462
|
+
}
|
|
1463
|
+
if (plugin === null || typeof plugin !== "object") throw new TypeError(`${at} is ${plugin === null ? "null" : typeof plugin}, not a plugin object`);
|
|
1464
|
+
const { name } = plugin;
|
|
1465
|
+
if (typeof name !== "string" || name.length === 0) throw new TypeError(`${at} has no \`name\`. A plugin needs one: its stylesheet and its debug events are keyed by it`);
|
|
1466
|
+
});
|
|
1467
|
+
}
|
|
1445
1468
|
/** Merge every plugin's `nodeRenderers` into a single map (later plugins win). */
|
|
1446
1469
|
function collectNodeRenderers(plugins = [], debugOptions = {}) {
|
|
1470
|
+
assertPlugins(plugins);
|
|
1447
1471
|
const map = {};
|
|
1448
1472
|
const target = debugOptions.debugTarget;
|
|
1449
1473
|
const debug = target ? void 0 : debugOptions.debug === true ? new DebugEmitter("renderer", debugOptions) : void 0;
|
|
@@ -2045,6 +2069,7 @@ var Renderer = class {
|
|
|
2045
2069
|
debug;
|
|
2046
2070
|
constructor(options = {}) {
|
|
2047
2071
|
this.options = options;
|
|
2072
|
+
assertPlugins(options.plugins);
|
|
2048
2073
|
this.debug = new DebugEmitter(this.debugSource, options);
|
|
2049
2074
|
this.sanitize = options.sanitize === false ? false : typeof options.sanitize === "object" ? options.sanitize : {};
|
|
2050
2075
|
this.registerPluginCards(options.plugins);
|
|
@@ -2070,6 +2095,7 @@ var Renderer = class {
|
|
|
2070
2095
|
* Passing the same plugins again is a no-op, so a host may call this on every render.
|
|
2071
2096
|
*/
|
|
2072
2097
|
setPlugins(plugins) {
|
|
2098
|
+
assertPlugins(plugins);
|
|
2073
2099
|
if (samePlugins(this.options.plugins, plugins)) return;
|
|
2074
2100
|
this.options = {
|
|
2075
2101
|
...this.options,
|
|
@@ -2835,4 +2861,4 @@ function delay(ms, signal) {
|
|
|
2835
2861
|
}
|
|
2836
2862
|
|
|
2837
2863
|
//#endregion
|
|
2838
|
-
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, availableLocales, baseCss, buildSystemPrompt, 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 };
|
|
2864
|
+
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, 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 };
|
package/package.json
CHANGED