@ai-gui/core 0.2.0 → 0.4.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/README.md +78 -0
- package/dist/index.cjs +1647 -41
- package/dist/index.d.cts +434 -8
- package/dist/index.d.ts +434 -8
- package/dist/index.js +1610 -41
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -47,6 +47,58 @@ interface SanitizeHtmlOptions {
|
|
|
47
47
|
*/
|
|
48
48
|
declare function sanitizeHtml(html: string, options?: SanitizeHtmlOptions): string;
|
|
49
49
|
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/debug-events.d.ts
|
|
52
|
+
type DebugSource = "renderer" | "action-runtime" | "card-store";
|
|
53
|
+
interface DebugEvent<TData extends Record<string, unknown> = Record<string, unknown>> {
|
|
54
|
+
type: string;
|
|
55
|
+
source: DebugSource;
|
|
56
|
+
timestamp: number;
|
|
57
|
+
sequence: number;
|
|
58
|
+
data: TData;
|
|
59
|
+
}
|
|
60
|
+
type DebugEventListener = (event: DebugEvent) => void;
|
|
61
|
+
interface DebugEventTarget {
|
|
62
|
+
readonly debugSource: DebugSource;
|
|
63
|
+
subscribeDebug(listener: DebugEventListener): () => void;
|
|
64
|
+
}
|
|
65
|
+
interface DebugOptions {
|
|
66
|
+
debug?: boolean;
|
|
67
|
+
onDebugEvent?: DebugEventListener;
|
|
68
|
+
maxStringLength?: number;
|
|
69
|
+
maxDepth?: number;
|
|
70
|
+
maxNodes?: number;
|
|
71
|
+
redact?: (context: DebugRedactContext) => boolean;
|
|
72
|
+
}
|
|
73
|
+
interface DebugRedactContext {
|
|
74
|
+
key: string;
|
|
75
|
+
path: readonly (string | number)[];
|
|
76
|
+
value: unknown;
|
|
77
|
+
}
|
|
78
|
+
interface DebugInstrumentationTarget extends DebugEventTarget {
|
|
79
|
+
readonly debugEnabled: boolean;
|
|
80
|
+
emitDebug(type: string, data?: Record<string, unknown>): void;
|
|
81
|
+
}
|
|
82
|
+
interface SafeDebugValueOptions {
|
|
83
|
+
maxStringLength?: number;
|
|
84
|
+
maxDepth?: number;
|
|
85
|
+
maxNodes?: number;
|
|
86
|
+
redact?: DebugOptions["redact"];
|
|
87
|
+
}
|
|
88
|
+
declare class DebugEmitter {
|
|
89
|
+
private readonly enabled;
|
|
90
|
+
private readonly source;
|
|
91
|
+
private readonly limits;
|
|
92
|
+
private readonly listeners;
|
|
93
|
+
private sequence;
|
|
94
|
+
constructor(source: DebugSource, options?: DebugOptions);
|
|
95
|
+
get active(): boolean;
|
|
96
|
+
get available(): boolean;
|
|
97
|
+
subscribe(listener: DebugEventListener): () => void;
|
|
98
|
+
emit(type: string, data?: Record<string, unknown>): void;
|
|
99
|
+
}
|
|
100
|
+
declare function safeDebugValue(value: unknown, options?: SafeDebugValueOptions): unknown;
|
|
101
|
+
|
|
50
102
|
//#endregion
|
|
51
103
|
//#region src/types.d.ts
|
|
52
104
|
/** Framework-agnostic render node. */
|
|
@@ -62,6 +114,7 @@ interface ASTNode {
|
|
|
62
114
|
complete?: boolean;
|
|
63
115
|
/** card-specific payload */
|
|
64
116
|
card?: {
|
|
117
|
+
id?: string;
|
|
65
118
|
type: string;
|
|
66
119
|
data: unknown;
|
|
67
120
|
complete: boolean;
|
|
@@ -100,14 +153,40 @@ type RenderOutput = {
|
|
|
100
153
|
data: unknown;
|
|
101
154
|
} | {
|
|
102
155
|
kind: "mount";
|
|
103
|
-
mount: (el: HTMLElement) => void | (() => void);
|
|
156
|
+
mount: (el: HTMLElement, context: RenderMountContext) => void | (() => void);
|
|
104
157
|
};
|
|
158
|
+
interface MountCardSlotRequest {
|
|
159
|
+
type: string;
|
|
160
|
+
data: unknown;
|
|
161
|
+
}
|
|
162
|
+
interface MountedCardSlot {
|
|
163
|
+
update(data: unknown): void;
|
|
164
|
+
destroy(): void;
|
|
165
|
+
}
|
|
166
|
+
interface RenderMountContext {
|
|
167
|
+
mountCard?: (host: HTMLElement, request: MountCardSlotRequest) => MountedCardSlot | undefined;
|
|
168
|
+
}
|
|
105
169
|
type NodeRenderer = (node: ASTNode) => RenderOutput | Promise<RenderOutput>;
|
|
170
|
+
interface PluginCommitContext {
|
|
171
|
+
readonly generation: number;
|
|
172
|
+
emitDebug(type: string, data?: Record<string, unknown>): void;
|
|
173
|
+
}
|
|
174
|
+
type KnownJSONSchemaType = "object" | "array" | "string" | "number" | "integer" | "boolean" | "null";
|
|
106
175
|
interface JSONSchema {
|
|
107
|
-
type?: string;
|
|
176
|
+
type?: KnownJSONSchemaType | (string & {});
|
|
108
177
|
properties?: Record<string, JSONSchema>;
|
|
109
178
|
items?: JSONSchema;
|
|
110
|
-
required?: string[];
|
|
179
|
+
required?: readonly string[];
|
|
180
|
+
additionalProperties?: boolean | JSONSchema;
|
|
181
|
+
enum?: readonly unknown[];
|
|
182
|
+
const?: unknown;
|
|
183
|
+
minLength?: number;
|
|
184
|
+
maxLength?: number;
|
|
185
|
+
pattern?: string;
|
|
186
|
+
minimum?: number;
|
|
187
|
+
maximum?: number;
|
|
188
|
+
minItems?: number;
|
|
189
|
+
maxItems?: number;
|
|
111
190
|
[k: string]: unknown;
|
|
112
191
|
}
|
|
113
192
|
interface CardDef<TData = unknown, TComponent = unknown> {
|
|
@@ -124,11 +203,13 @@ interface AIGuiPlugin {
|
|
|
124
203
|
cards?: CardDef[];
|
|
125
204
|
nodeRenderers?: Record<string, NodeRenderer>;
|
|
126
205
|
isBlockComplete?: (nodeType: string, raw: string) => boolean;
|
|
206
|
+
/** Runs synchronously after the AST is finalized and before patches are dispatched. */
|
|
207
|
+
onASTCommit?: (nodes: readonly ASTNode[], context: PluginCommitContext) => void;
|
|
127
208
|
css?: string;
|
|
128
209
|
/** LLM-facing guidance describing this plugin's fence syntax. */
|
|
129
|
-
promptSpec?: string;
|
|
210
|
+
promptSpec?: string | (() => string);
|
|
130
211
|
}
|
|
131
|
-
interface RendererOptions {
|
|
212
|
+
interface RendererOptions extends DebugOptions {
|
|
132
213
|
registry?: CardRegistry;
|
|
133
214
|
plugins?: AIGuiPlugin[];
|
|
134
215
|
sanitize?: boolean | SanitizeHtmlOptions;
|
|
@@ -154,13 +235,288 @@ declare class CardRegistry {
|
|
|
154
235
|
register(def: CardDef): void;
|
|
155
236
|
has(type: string): boolean;
|
|
156
237
|
getRender(type: string): unknown;
|
|
238
|
+
get(type: string): Readonly<CardDef> | undefined;
|
|
239
|
+
list(): Readonly<CardDef>[];
|
|
157
240
|
parse(type: string, rawJson: string): CardParseResult;
|
|
158
|
-
|
|
241
|
+
validate(type: string, data: unknown): boolean;
|
|
242
|
+
private validateDefinition;
|
|
159
243
|
toPromptSpec(): string;
|
|
160
244
|
get size(): number;
|
|
161
245
|
toJSONSchema(): JSONSchema;
|
|
162
246
|
}
|
|
163
247
|
|
|
248
|
+
//#endregion
|
|
249
|
+
//#region src/card-store.d.ts
|
|
250
|
+
declare const CARD_ID_MAX_LENGTH = 256;
|
|
251
|
+
declare const CARD_JSON_MAX_DEPTH = 32;
|
|
252
|
+
declare const CARD_JSON_MAX_NODES = 10000;
|
|
253
|
+
declare const CARD_PATCH_BATCH_MAX_SIZE = 100;
|
|
254
|
+
type CardAction = {
|
|
255
|
+
status: "idle";
|
|
256
|
+
} | {
|
|
257
|
+
status: "loading";
|
|
258
|
+
actionId: string;
|
|
259
|
+
} | {
|
|
260
|
+
status: "success";
|
|
261
|
+
actionId: string;
|
|
262
|
+
} | {
|
|
263
|
+
status: "error";
|
|
264
|
+
actionId: string;
|
|
265
|
+
error: CardActionError;
|
|
266
|
+
};
|
|
267
|
+
interface CardActionError {
|
|
268
|
+
name: string;
|
|
269
|
+
message: string;
|
|
270
|
+
}
|
|
271
|
+
interface CardRecord {
|
|
272
|
+
readonly id: string;
|
|
273
|
+
readonly type: string;
|
|
274
|
+
readonly data: unknown;
|
|
275
|
+
readonly revision: number;
|
|
276
|
+
readonly action: CardAction;
|
|
277
|
+
}
|
|
278
|
+
interface CardPatch {
|
|
279
|
+
op: "merge" | "replace";
|
|
280
|
+
cardId: string;
|
|
281
|
+
data: unknown;
|
|
282
|
+
revision?: number;
|
|
283
|
+
}
|
|
284
|
+
interface CardPatchBatch {
|
|
285
|
+
op: "batch";
|
|
286
|
+
patches: CardPatch[];
|
|
287
|
+
}
|
|
288
|
+
type CardPatchResult = CardPatch | CardPatchBatch;
|
|
289
|
+
interface CardSnapshot {
|
|
290
|
+
version: 1;
|
|
291
|
+
cards: Array<Pick<CardRecord, "id" | "type" | "data" | "revision">>;
|
|
292
|
+
}
|
|
293
|
+
interface CardStoreOptions extends DebugOptions {
|
|
294
|
+
registry?: CardRegistry;
|
|
295
|
+
}
|
|
296
|
+
type CardListener = (card: CardRecord | undefined) => void;
|
|
297
|
+
type CardStoreListener = (cards: readonly CardRecord[]) => void;
|
|
298
|
+
declare class CardStore {
|
|
299
|
+
readonly debugSource: "card-store";
|
|
300
|
+
private readonly registry?;
|
|
301
|
+
private cards;
|
|
302
|
+
private lastMutationEpoch;
|
|
303
|
+
private mutationEpoch;
|
|
304
|
+
private readonly listeners;
|
|
305
|
+
private readonly allListeners;
|
|
306
|
+
private readonly debug;
|
|
307
|
+
constructor(options?: CardStoreOptions);
|
|
308
|
+
register(input: {
|
|
309
|
+
id: string;
|
|
310
|
+
type: string;
|
|
311
|
+
data: unknown;
|
|
312
|
+
}): CardRecord;
|
|
313
|
+
get(id: string): CardRecord | undefined;
|
|
314
|
+
list(): CardRecord[];
|
|
315
|
+
subscribe(id: string, listener: CardListener): () => void;
|
|
316
|
+
subscribeAll(listener: CardStoreListener): () => void;
|
|
317
|
+
subscribeDebug(listener: DebugEventListener): () => void;
|
|
318
|
+
apply(patch: CardPatch): CardRecord;
|
|
319
|
+
applyAll(patches: readonly CardPatch[]): CardRecord[];
|
|
320
|
+
delete(id: string): boolean;
|
|
321
|
+
clear(): void;
|
|
322
|
+
snapshot(): CardSnapshot;
|
|
323
|
+
restore(snapshot: CardSnapshot): void;
|
|
324
|
+
beginAction(id: string, actionId: string): boolean;
|
|
325
|
+
succeedAction(id: string, actionId: string): boolean;
|
|
326
|
+
failAction(id: string, actionId: string, error: unknown): boolean;
|
|
327
|
+
cancelAction(id: string, actionId: string): boolean;
|
|
328
|
+
isActionCurrent(id: string, actionId: string): boolean;
|
|
329
|
+
revisions(): ReadonlyMap<string, number>;
|
|
330
|
+
captureMutationEpoch(): number;
|
|
331
|
+
applyActionResult(result: CardPatchResult, startedEpoch: number): CardRecord[];
|
|
332
|
+
private preparePatch;
|
|
333
|
+
private assertValid;
|
|
334
|
+
private setAction;
|
|
335
|
+
private nextMutationEpoch;
|
|
336
|
+
private notify;
|
|
337
|
+
private notifyOne;
|
|
338
|
+
private notifyAll;
|
|
339
|
+
}
|
|
340
|
+
declare class CardStoreError extends Error {
|
|
341
|
+
constructor(message: string, options?: ErrorOptions);
|
|
342
|
+
}
|
|
343
|
+
declare class CardNotFoundError extends CardStoreError {
|
|
344
|
+
constructor(id: string);
|
|
345
|
+
}
|
|
346
|
+
declare class CardTypeConflictError extends CardStoreError {
|
|
347
|
+
constructor(id: string, currentType: string, nextType: string);
|
|
348
|
+
}
|
|
349
|
+
declare class CardValidationError extends CardStoreError {
|
|
350
|
+
constructor(type: string);
|
|
351
|
+
}
|
|
352
|
+
declare class CardRevisionConflictError extends CardStoreError {
|
|
353
|
+
constructor(id: string, expected: number, actual: number);
|
|
354
|
+
}
|
|
355
|
+
declare class CardJSONError extends CardStoreError {}
|
|
356
|
+
declare class CardLimitError extends CardStoreError {}
|
|
357
|
+
declare class CardSnapshotError extends CardStoreError {}
|
|
358
|
+
declare function isCardPatchResult(value: unknown): value is CardPatchResult;
|
|
359
|
+
|
|
360
|
+
//#endregion
|
|
361
|
+
//#region src/json-schema.d.ts
|
|
362
|
+
interface JSONSchemaValidationResult {
|
|
363
|
+
valid: boolean;
|
|
364
|
+
issues: string[];
|
|
365
|
+
}
|
|
366
|
+
/** Small, dependency-free validator for the JSON Schema subset used by AIGUI definitions. */
|
|
367
|
+
declare function validateJSONSchema(schema: JSONSchema, value: unknown): JSONSchemaValidationResult;
|
|
368
|
+
|
|
369
|
+
//#endregion
|
|
370
|
+
//#region src/actions.d.ts
|
|
371
|
+
interface ActionContext {
|
|
372
|
+
signal: AbortSignal;
|
|
373
|
+
actionId: string;
|
|
374
|
+
cardType?: string;
|
|
375
|
+
cardId?: string;
|
|
376
|
+
}
|
|
377
|
+
interface ActionDefinition<TParams = unknown, TResult = unknown> {
|
|
378
|
+
type: string;
|
|
379
|
+
schema?: JSONSchema;
|
|
380
|
+
run: (params: TParams, context: ActionContext) => TResult | Promise<TResult>;
|
|
381
|
+
}
|
|
382
|
+
interface ActionRegisterOptions {
|
|
383
|
+
override?: boolean;
|
|
384
|
+
}
|
|
385
|
+
declare class ActionRegistry {
|
|
386
|
+
private actions;
|
|
387
|
+
register<TParams, TResult>(definition: ActionDefinition<TParams, TResult>, options?: ActionRegisterOptions): void;
|
|
388
|
+
has(type: string): boolean;
|
|
389
|
+
get(type: string): ActionDefinition<any, unknown> | undefined;
|
|
390
|
+
list(): ActionDefinition<any, unknown>[];
|
|
391
|
+
}
|
|
392
|
+
interface ActionRequest<TParams = unknown> {
|
|
393
|
+
type: string;
|
|
394
|
+
params: TParams;
|
|
395
|
+
cardType?: string;
|
|
396
|
+
cardId?: string;
|
|
397
|
+
}
|
|
398
|
+
interface ActionDispatchOptions {
|
|
399
|
+
signal?: AbortSignal;
|
|
400
|
+
timeoutMs?: number;
|
|
401
|
+
owner?: object;
|
|
402
|
+
}
|
|
403
|
+
type ActionStatus = "idle" | "pending" | "success" | "error" | "cancelled";
|
|
404
|
+
interface ActionStateBase {
|
|
405
|
+
key: string;
|
|
406
|
+
type: string;
|
|
407
|
+
cardType?: string;
|
|
408
|
+
cardId?: string;
|
|
409
|
+
actionId?: string;
|
|
410
|
+
}
|
|
411
|
+
type ActionState = (ActionStateBase & {
|
|
412
|
+
status: "idle";
|
|
413
|
+
}) | (ActionStateBase & {
|
|
414
|
+
status: "pending";
|
|
415
|
+
actionId: string;
|
|
416
|
+
}) | (ActionStateBase & {
|
|
417
|
+
status: "success";
|
|
418
|
+
actionId: string;
|
|
419
|
+
result: unknown;
|
|
420
|
+
}) | (ActionStateBase & {
|
|
421
|
+
status: "error";
|
|
422
|
+
actionId: string;
|
|
423
|
+
error: ActionRuntimeError;
|
|
424
|
+
}) | (ActionStateBase & {
|
|
425
|
+
status: "cancelled";
|
|
426
|
+
actionId: string;
|
|
427
|
+
error: ActionAbortedError;
|
|
428
|
+
});
|
|
429
|
+
interface ActionEventBase {
|
|
430
|
+
key: string;
|
|
431
|
+
type: string;
|
|
432
|
+
params: unknown;
|
|
433
|
+
actionId: string;
|
|
434
|
+
cardType?: string;
|
|
435
|
+
cardId?: string;
|
|
436
|
+
}
|
|
437
|
+
type ActionStartEvent = ActionEventBase;
|
|
438
|
+
type ActionSuccessEvent = ActionEventBase & {
|
|
439
|
+
result: unknown;
|
|
440
|
+
};
|
|
441
|
+
type ActionErrorEvent = ActionEventBase & {
|
|
442
|
+
error: ActionRuntimeError;
|
|
443
|
+
};
|
|
444
|
+
interface ActionRuntimeOptions extends DebugOptions {
|
|
445
|
+
registry: ActionRegistry;
|
|
446
|
+
cardStore?: CardStore;
|
|
447
|
+
timeoutMs?: number;
|
|
448
|
+
onActionStart?: (event: ActionStartEvent) => void;
|
|
449
|
+
onActionSuccess?: (event: ActionSuccessEvent) => void;
|
|
450
|
+
onActionError?: (event: ActionErrorEvent) => void;
|
|
451
|
+
}
|
|
452
|
+
type ActionStateListener = (state: ActionState) => void;
|
|
453
|
+
declare class ActionRuntime {
|
|
454
|
+
readonly debugSource: "action-runtime";
|
|
455
|
+
private readonly registry;
|
|
456
|
+
private readonly cardStore?;
|
|
457
|
+
private readonly defaultTimeoutMs?;
|
|
458
|
+
private readonly onActionStart?;
|
|
459
|
+
private readonly onActionSuccess?;
|
|
460
|
+
private readonly onActionError?;
|
|
461
|
+
private readonly states;
|
|
462
|
+
private readonly pending;
|
|
463
|
+
private readonly listeners;
|
|
464
|
+
private readonly defaultOwner;
|
|
465
|
+
private readonly runtimeId;
|
|
466
|
+
private generation;
|
|
467
|
+
private nextActionId;
|
|
468
|
+
private destroyed;
|
|
469
|
+
private readonly debug;
|
|
470
|
+
constructor(options: ActionRuntimeOptions);
|
|
471
|
+
dispatch<TResult = unknown>(request: ActionRequest, options?: ActionDispatchOptions): Promise<TResult>;
|
|
472
|
+
getState(key: string): ActionState;
|
|
473
|
+
/** Check the runtime allowlist without exposing executable action definitions. */
|
|
474
|
+
hasAction(type: string): boolean;
|
|
475
|
+
/** List registered action names without exposing executable definitions. */
|
|
476
|
+
listActionTypes(): readonly string[];
|
|
477
|
+
subscribe(listener: ActionStateListener): () => void;
|
|
478
|
+
subscribeDebug(listener: DebugEventListener): () => void;
|
|
479
|
+
cancel(key: string): boolean;
|
|
480
|
+
reset(): void;
|
|
481
|
+
destroy(): void;
|
|
482
|
+
private rejectPreflight;
|
|
483
|
+
private isPublic;
|
|
484
|
+
private commit;
|
|
485
|
+
private notify;
|
|
486
|
+
}
|
|
487
|
+
declare function createActionRuntime(options: ActionRuntimeOptions): ActionRuntime;
|
|
488
|
+
declare class ActionRuntimeError extends Error {
|
|
489
|
+
constructor(message: string, options?: ErrorOptions);
|
|
490
|
+
}
|
|
491
|
+
declare class ActionAlreadyRegisteredError extends ActionRuntimeError {
|
|
492
|
+
constructor(type: string);
|
|
493
|
+
}
|
|
494
|
+
declare class ActionNotFoundError extends ActionRuntimeError {
|
|
495
|
+
constructor(type: string);
|
|
496
|
+
}
|
|
497
|
+
declare class ActionValidationError extends ActionRuntimeError {
|
|
498
|
+
readonly actionType: string;
|
|
499
|
+
readonly issues: string[];
|
|
500
|
+
constructor(actionType: string, issues: string[]);
|
|
501
|
+
}
|
|
502
|
+
declare class ActionExecutionError extends ActionRuntimeError {
|
|
503
|
+
constructor(type: string, cause: unknown);
|
|
504
|
+
}
|
|
505
|
+
declare class ActionAbortedError extends ActionRuntimeError {
|
|
506
|
+
constructor(type: string);
|
|
507
|
+
}
|
|
508
|
+
declare class ActionTimeoutError extends ActionRuntimeError {
|
|
509
|
+
readonly timeoutMs: number;
|
|
510
|
+
constructor(type: string, timeoutMs: number);
|
|
511
|
+
}
|
|
512
|
+
declare class ActionDestroyedError extends ActionRuntimeError {
|
|
513
|
+
constructor();
|
|
514
|
+
}
|
|
515
|
+
declare function getActionKey(type: string, cardType?: string, cardId?: string): string;
|
|
516
|
+
declare function getIdleActionState(key: string): Extract<ActionState, {
|
|
517
|
+
status: "idle";
|
|
518
|
+
}>;
|
|
519
|
+
|
|
164
520
|
//#endregion
|
|
165
521
|
//#region src/parser.d.ts
|
|
166
522
|
interface ParserOptions {
|
|
@@ -186,8 +542,11 @@ declare function createParserWithMetadata(options?: ParserOptions): (src: string
|
|
|
186
542
|
|
|
187
543
|
//#endregion
|
|
188
544
|
//#region src/plugins.d.ts
|
|
545
|
+
interface CollectNodeRendererOptions extends DebugOptions {
|
|
546
|
+
debugTarget?: DebugInstrumentationTarget;
|
|
547
|
+
}
|
|
189
548
|
/** Merge every plugin's `nodeRenderers` into a single map (later plugins win). */
|
|
190
|
-
declare function collectNodeRenderers(plugins?: AIGuiPlugin[]): Record<string, NodeRenderer>;
|
|
549
|
+
declare function collectNodeRenderers(plugins?: AIGuiPlugin[], debugOptions?: CollectNodeRendererOptions): Record<string, NodeRenderer>;
|
|
191
550
|
/** The set of node types claimed by the given plugins. */
|
|
192
551
|
declare function pluginNodeTypes(plugins?: AIGuiPlugin[]): Set<string>;
|
|
193
552
|
|
|
@@ -206,6 +565,7 @@ declare function applyPatches(nodes: ASTNode[], patches: Patch[]): ASTNode[];
|
|
|
206
565
|
* the resulting patches via `onPatch`.
|
|
207
566
|
*/
|
|
208
567
|
declare class Renderer {
|
|
568
|
+
readonly debugSource: "renderer";
|
|
209
569
|
private buffer;
|
|
210
570
|
private prevAst;
|
|
211
571
|
private parse;
|
|
@@ -216,8 +576,12 @@ declare class Renderer {
|
|
|
216
576
|
private activeFeed?;
|
|
217
577
|
private renderScheduled;
|
|
218
578
|
private scheduleGeneration;
|
|
579
|
+
private readonly debug;
|
|
219
580
|
constructor(options?: RendererOptions);
|
|
581
|
+
get debugEnabled(): boolean;
|
|
582
|
+
emitDebug(type: string, data?: Record<string, unknown>): void;
|
|
220
583
|
push(chunk: string): void;
|
|
584
|
+
subscribeDebug(listener: DebugEventListener): () => void;
|
|
221
585
|
feed(source: FeedSource, options?: FeedOptions): Promise<void>;
|
|
222
586
|
reset(): void;
|
|
223
587
|
/** Immediately render pending buffered input, bypassing the scheduler. */
|
|
@@ -225,6 +589,7 @@ declare class Renderer {
|
|
|
225
589
|
private scheduleRender;
|
|
226
590
|
private cancelActiveFeed;
|
|
227
591
|
private render;
|
|
592
|
+
private sanitizeNodesWithDebug;
|
|
228
593
|
}
|
|
229
594
|
|
|
230
595
|
//#endregion
|
|
@@ -268,4 +633,65 @@ interface BuildSystemPromptOptions {
|
|
|
268
633
|
declare function buildSystemPrompt(options?: BuildSystemPromptOptions): string;
|
|
269
634
|
|
|
270
635
|
//#endregion
|
|
271
|
-
|
|
636
|
+
//#region src/model-stream.d.ts
|
|
637
|
+
interface Citation {
|
|
638
|
+
type?: string;
|
|
639
|
+
id?: string;
|
|
640
|
+
url?: string;
|
|
641
|
+
title?: string;
|
|
642
|
+
citedText?: string;
|
|
643
|
+
[key: string]: unknown;
|
|
644
|
+
}
|
|
645
|
+
interface Usage {
|
|
646
|
+
inputTokens?: number;
|
|
647
|
+
outputTokens?: number;
|
|
648
|
+
totalTokens?: number;
|
|
649
|
+
[key: string]: unknown;
|
|
650
|
+
}
|
|
651
|
+
type ModelStreamEvent = {
|
|
652
|
+
type: "content";
|
|
653
|
+
delta: string;
|
|
654
|
+
} | {
|
|
655
|
+
type: "reasoning";
|
|
656
|
+
delta: string;
|
|
657
|
+
} | {
|
|
658
|
+
type: "citation";
|
|
659
|
+
data: Citation;
|
|
660
|
+
} | {
|
|
661
|
+
type: "usage";
|
|
662
|
+
data: Usage;
|
|
663
|
+
} | {
|
|
664
|
+
type: "error";
|
|
665
|
+
error: unknown;
|
|
666
|
+
};
|
|
667
|
+
type ByteStreamSource = Response | ReadableStream<Uint8Array> | AsyncIterable<Uint8Array | string>;
|
|
668
|
+
interface StreamParseOptions {
|
|
669
|
+
signal?: AbortSignal;
|
|
670
|
+
onMalformed?: (error: Error, input: string) => "skip" | void;
|
|
671
|
+
}
|
|
672
|
+
interface SSEOptions extends StreamParseOptions {
|
|
673
|
+
parseJSON?: boolean;
|
|
674
|
+
doneData?: string | false;
|
|
675
|
+
}
|
|
676
|
+
interface SSEEvent<T = string> {
|
|
677
|
+
data: T;
|
|
678
|
+
event?: string;
|
|
679
|
+
id?: string;
|
|
680
|
+
retry?: number;
|
|
681
|
+
}
|
|
682
|
+
declare function parseSSE(source: ByteStreamSource, options: SSEOptions & {
|
|
683
|
+
parseJSON: true;
|
|
684
|
+
}): AsyncGenerator<SSEEvent<unknown>>;
|
|
685
|
+
declare function parseSSE(source: ByteStreamSource, options?: SSEOptions): AsyncGenerator<SSEEvent<string>>;
|
|
686
|
+
declare function jsonLines<T = unknown>(source: ByteStreamSource, options?: StreamParseOptions): AsyncGenerator<T>;
|
|
687
|
+
declare const ndjson: typeof jsonLines;
|
|
688
|
+
declare function textLines(source: ByteStreamSource, options?: Pick<StreamParseOptions, "signal">): AsyncGenerator<string>;
|
|
689
|
+
declare function contentDeltas(events: AsyncIterable<ModelStreamEvent>): AsyncGenerator<string>;
|
|
690
|
+
declare function mockModelStream(events: Iterable<ModelStreamEvent> | AsyncIterable<ModelStreamEvent>, options?: {
|
|
691
|
+
delayMs?: number;
|
|
692
|
+
signal?: AbortSignal;
|
|
693
|
+
}): AsyncGenerator<ModelStreamEvent>;
|
|
694
|
+
declare function readableBytes(chunks: Iterable<string | Uint8Array> | AsyncIterable<string | Uint8Array>): ReadableStream<Uint8Array>;
|
|
695
|
+
|
|
696
|
+
//#endregion
|
|
697
|
+
export { AIGuiPlugin, ASTNode, ActionAbortedError, ActionAlreadyRegisteredError, ActionContext, ActionDefinition, ActionDestroyedError, ActionDispatchOptions, ActionErrorEvent, ActionEventBase, ActionExecutionError, ActionNotFoundError, 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, DebugEmitter, DebugEvent, DebugEventListener, DebugEventTarget, DebugInstrumentationTarget, DebugOptions, DebugRedactContext, DebugSource, FeedChunk, FeedOptions, FeedSource, JSONSchema, JSONSchemaValidationResult, ModelStreamEvent, MountCardSlotRequest, MountedCardSlot, NodeRenderer, ParseResult, ParserOptions, PartialJSONResult, Patch, PluginCommitContext, RenderMountContext, RenderOutput, Renderer, RendererOptions, SSEEvent, SSEOptions, SafeDebugValueOptions, SanitizeHtmlOptions, SourceBlock, StreamParseOptions, StreamRouter, Usage, applyPatches, buildSystemPrompt, collectNodeRenderers, contentDeltas, createActionRuntime, createParser, createParserWithMetadata, diffAst, getActionKey, getIdleActionState, isCardPatchResult, jsonLines, mockModelStream, ndjson, parsePartialJSON, parseSSE, pluginNodeTypes, readableBytes, repairMarkdown, safeDebugValue, sanitizeHtml, textLines, validateJSONSchema };
|