vanilla-agent 1.4.1 → 1.6.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.d.cts CHANGED
@@ -75,6 +75,71 @@ interface AgentWidgetPlugin {
75
75
  onUnregister?: () => void;
76
76
  }
77
77
 
78
+ type AgentWidgetContextProviderContext = {
79
+ messages: AgentWidgetMessage[];
80
+ config: AgentWidgetConfig;
81
+ };
82
+ type AgentWidgetContextProvider = (context: AgentWidgetContextProviderContext) => Record<string, unknown> | void | Promise<Record<string, unknown> | void>;
83
+ type AgentWidgetRequestPayloadMessage = {
84
+ role: AgentWidgetMessageRole;
85
+ content: string;
86
+ createdAt: string;
87
+ };
88
+ type AgentWidgetRequestPayload = {
89
+ messages: AgentWidgetRequestPayloadMessage[];
90
+ flowId?: string;
91
+ context?: Record<string, unknown>;
92
+ };
93
+ type AgentWidgetRequestMiddlewareContext = {
94
+ payload: AgentWidgetRequestPayload;
95
+ config: AgentWidgetConfig;
96
+ };
97
+ type AgentWidgetRequestMiddleware = (context: AgentWidgetRequestMiddlewareContext) => AgentWidgetRequestPayload | void | Promise<AgentWidgetRequestPayload | void>;
98
+ type AgentWidgetParsedAction = {
99
+ type: string;
100
+ payload: Record<string, unknown>;
101
+ raw?: unknown;
102
+ };
103
+ type AgentWidgetActionParserInput = {
104
+ text: string;
105
+ message: AgentWidgetMessage;
106
+ };
107
+ type AgentWidgetActionParser = (input: AgentWidgetActionParserInput) => AgentWidgetParsedAction | null | undefined;
108
+ type AgentWidgetActionHandlerResult = {
109
+ handled?: boolean;
110
+ displayText?: string;
111
+ };
112
+ type AgentWidgetActionContext = {
113
+ message: AgentWidgetMessage;
114
+ metadata: Record<string, unknown>;
115
+ updateMetadata: (updater: (prev: Record<string, unknown>) => Record<string, unknown>) => void;
116
+ document: Document | null;
117
+ };
118
+ type AgentWidgetActionHandler = (action: AgentWidgetParsedAction, context: AgentWidgetActionContext) => AgentWidgetActionHandlerResult | void;
119
+ type AgentWidgetStoredState = {
120
+ messages?: AgentWidgetMessage[];
121
+ metadata?: Record<string, unknown>;
122
+ };
123
+ interface AgentWidgetStorageAdapter {
124
+ load?: () => AgentWidgetStoredState | null | Promise<AgentWidgetStoredState | null>;
125
+ save?: (state: AgentWidgetStoredState) => void | Promise<void>;
126
+ clear?: () => void | Promise<void>;
127
+ }
128
+ type AgentWidgetVoiceStateEvent = {
129
+ active: boolean;
130
+ source: "user" | "auto" | "restore" | "system";
131
+ timestamp: number;
132
+ };
133
+ type AgentWidgetActionEventPayload = {
134
+ action: AgentWidgetParsedAction;
135
+ message: AgentWidgetMessage;
136
+ };
137
+ type AgentWidgetControllerEventMap = {
138
+ "assistant:message": AgentWidgetMessage;
139
+ "assistant:complete": AgentWidgetMessage;
140
+ "voice:state": AgentWidgetVoiceStateEvent;
141
+ "action:detected": AgentWidgetActionEventPayload;
142
+ };
78
143
  type AgentWidgetFeatureFlags = {
79
144
  showReasoning?: boolean;
80
145
  showToolCalls?: boolean;
@@ -205,6 +270,7 @@ type AgentWidgetVoiceRecognitionConfig = {
205
270
  recordingBackgroundColor?: string;
206
271
  recordingBorderColor?: string;
207
272
  showRecordingIndicator?: boolean;
273
+ autoResume?: boolean | "assistant";
208
274
  };
209
275
  type AgentWidgetToolCallConfig = {
210
276
  backgroundColor?: string;
@@ -248,7 +314,9 @@ interface AgentWidgetStreamParserResult {
248
314
  */
249
315
  text: string | null;
250
316
  /**
251
- * Optional: The raw accumulated content (useful for middleware that needs the original format)
317
+ * The raw accumulated content. Built-in parsers always populate this so
318
+ * downstream middleware (action handlers, logging, etc.) can
319
+ * inspect/parse the original structured payload.
252
320
  */
253
321
  raw?: string;
254
322
  }
@@ -300,8 +368,14 @@ type AgentWidgetConfig = {
300
368
  text: string;
301
369
  message: AgentWidgetMessage;
302
370
  streaming: boolean;
371
+ raw?: string;
303
372
  }) => string;
304
373
  plugins?: AgentWidgetPlugin[];
374
+ contextProviders?: AgentWidgetContextProvider[];
375
+ requestMiddleware?: AgentWidgetRequestMiddleware;
376
+ actionParsers?: AgentWidgetActionParser[];
377
+ actionHandlers?: AgentWidgetActionHandler[];
378
+ storageAdapter?: AgentWidgetStorageAdapter;
305
379
  /**
306
380
  * Custom stream parser for extracting text from streaming structured responses.
307
381
  * Handles incremental parsing of JSON, XML, or other formats.
@@ -333,6 +407,31 @@ type AgentWidgetConfig = {
333
407
  * ```
334
408
  */
335
409
  clearChatHistoryStorageKey?: string;
410
+ /**
411
+ * Built-in parser type selector. Provides an easy way to choose a parser without importing functions.
412
+ * If both `parserType` and `streamParser` are provided, `streamParser` takes precedence.
413
+ *
414
+ * - `"plain"` - Plain text parser (default). Passes through text as-is.
415
+ * - `"json"` - JSON parser using partial-json. Extracts `text` field from JSON objects incrementally.
416
+ * - `"regex-json"` - Regex-based JSON parser. Less robust but faster fallback for simple JSON.
417
+ * - `"xml"` - XML parser. Extracts text content from XML tags.
418
+ *
419
+ * @example
420
+ * ```typescript
421
+ * config: {
422
+ * parserType: "json" // Use built-in JSON parser
423
+ * }
424
+ * ```
425
+ *
426
+ * @example
427
+ * ```typescript
428
+ * config: {
429
+ * parserType: "json",
430
+ * streamParser: () => customParser() // Custom parser overrides parserType
431
+ * }
432
+ * ```
433
+ */
434
+ parserType?: "plain" | "json" | "regex-json" | "xml";
336
435
  };
337
436
  type AgentWidgetMessageRole = "user" | "assistant" | "system";
338
437
  type AgentWidgetReasoning = {
@@ -384,6 +483,11 @@ type AgentWidgetMessage = {
384
483
  toolCall?: AgentWidgetToolCall;
385
484
  tools?: AgentWidgetToolCall[];
386
485
  viaVoice?: boolean;
486
+ /**
487
+ * Raw structured payload for this message (e.g., JSON action response).
488
+ * Populated automatically when structured parsers run.
489
+ */
490
+ rawContent?: string;
387
491
  };
388
492
  type AgentWidgetEvent = {
389
493
  type: "message";
@@ -401,29 +505,9 @@ type AgentWidgetInitOptions = {
401
505
  useShadowDom?: boolean;
402
506
  onReady?: () => void;
403
507
  windowKey?: string;
508
+ debugTools?: boolean;
404
509
  };
405
510
 
406
- type Controller = {
407
- update: (config: AgentWidgetConfig) => void;
408
- destroy: () => void;
409
- open: () => void;
410
- close: () => void;
411
- toggle: () => void;
412
- clearChat: () => void;
413
- setMessage: (message: string) => boolean;
414
- submitMessage: (message?: string) => boolean;
415
- startVoiceRecognition: () => boolean;
416
- stopVoiceRecognition: () => boolean;
417
- injectTestMessage: (event: AgentWidgetEvent) => void;
418
- };
419
- declare const createAgentExperience: (mount: HTMLElement, initialConfig?: AgentWidgetConfig) => Controller;
420
- type AgentWidgetController = Controller;
421
-
422
- type AgentWidgetInitHandle = AgentWidgetController & {
423
- host: HTMLElement;
424
- };
425
- declare const initAgentWidget: (options: AgentWidgetInitOptions) => AgentWidgetInitHandle;
426
-
427
511
  type AgentWidgetSessionStatus = "idle" | "connecting" | "connected" | "error";
428
512
  type SessionCallbacks = {
429
513
  onMessagesChanged: (messages: AgentWidgetMessage[]) => void;
@@ -451,6 +535,7 @@ declare class AgentWidgetSession {
451
535
  }): Promise<void>;
452
536
  cancel(): void;
453
537
  clearMessages(): void;
538
+ hydrateMessages(messages: AgentWidgetMessage[]): void;
454
539
  private handleEvent;
455
540
  private setStatus;
456
541
  private setStreaming;
@@ -461,6 +546,35 @@ declare class AgentWidgetSession {
461
546
  private sortMessages;
462
547
  }
463
548
 
549
+ type Controller = {
550
+ update: (config: AgentWidgetConfig) => void;
551
+ destroy: () => void;
552
+ open: () => void;
553
+ close: () => void;
554
+ toggle: () => void;
555
+ clearChat: () => void;
556
+ setMessage: (message: string) => boolean;
557
+ submitMessage: (message?: string) => boolean;
558
+ startVoiceRecognition: () => boolean;
559
+ stopVoiceRecognition: () => boolean;
560
+ injectTestMessage: (event: AgentWidgetEvent) => void;
561
+ getMessages: () => AgentWidgetMessage[];
562
+ getStatus: () => AgentWidgetSessionStatus;
563
+ getPersistentMetadata: () => Record<string, unknown>;
564
+ updatePersistentMetadata: (updater: (prev: Record<string, unknown>) => Record<string, unknown>) => void;
565
+ on: <K extends keyof AgentWidgetControllerEventMap>(event: K, handler: (payload: AgentWidgetControllerEventMap[K]) => void) => () => void;
566
+ off: <K extends keyof AgentWidgetControllerEventMap>(event: K, handler: (payload: AgentWidgetControllerEventMap[K]) => void) => void;
567
+ };
568
+ declare const createAgentExperience: (mount: HTMLElement, initialConfig?: AgentWidgetConfig, runtimeOptions?: {
569
+ debugTools?: boolean;
570
+ }) => Controller;
571
+ type AgentWidgetController = Controller;
572
+
573
+ type AgentWidgetInitHandle = AgentWidgetController & {
574
+ host: HTMLElement;
575
+ };
576
+ declare const initAgentWidget: (options: AgentWidgetInitOptions) => AgentWidgetInitHandle;
577
+
464
578
  type DispatchOptions = {
465
579
  messages: AgentWidgetMessage[];
466
580
  signal?: AbortSignal;
@@ -472,11 +586,37 @@ declare class AgentWidgetClient {
472
586
  private readonly headers;
473
587
  private readonly debug;
474
588
  private readonly createStreamParser;
589
+ private readonly contextProviders;
590
+ private readonly requestMiddleware?;
475
591
  constructor(config?: AgentWidgetConfig);
476
592
  dispatch(options: DispatchOptions, onEvent: SSEHandler): Promise<void>;
593
+ private buildPayload;
477
594
  private streamResponse;
478
595
  }
479
596
 
597
+ declare const createLocalStorageAdapter: (key?: string) => AgentWidgetStorageAdapter;
598
+
599
+ type ActionManagerProcessContext = {
600
+ text: string;
601
+ message: AgentWidgetMessage;
602
+ streaming: boolean;
603
+ raw?: string;
604
+ };
605
+ type ActionManagerOptions = {
606
+ parsers: AgentWidgetActionParser[];
607
+ handlers: AgentWidgetActionHandler[];
608
+ getMetadata: () => Record<string, unknown>;
609
+ updateMetadata: (updater: (prev: Record<string, unknown>) => Record<string, unknown>) => void;
610
+ emit: <K extends keyof AgentWidgetControllerEventMap>(event: K, payload: AgentWidgetControllerEventMap[K]) => void;
611
+ documentRef: Document | null;
612
+ };
613
+ declare const defaultJsonActionParser: AgentWidgetActionParser;
614
+ declare const defaultActionHandlers: Record<string, AgentWidgetActionHandler>;
615
+ declare const createActionManager: (options: ActionManagerOptions) => {
616
+ process: (context: ActionManagerProcessContext) => string | null;
617
+ syncFromMetadata: () => void;
618
+ };
619
+
480
620
  /**
481
621
  * Basic markdown renderer. Remember to sanitize the returned HTML if you render
482
622
  * untrusted content in your host page.
@@ -558,4 +698,4 @@ declare const DEFAULT_WIDGET_CONFIG: Partial<AgentWidgetConfig>;
558
698
  */
559
699
  declare function mergeWithDefaults(config?: Partial<AgentWidgetConfig>): Partial<AgentWidgetConfig>;
560
700
 
561
- export { AgentWidgetClient, type AgentWidgetConfig, type AgentWidgetController, type AgentWidgetEvent, type AgentWidgetFeatureFlags, type AgentWidgetInitHandle, type AgentWidgetInitOptions, type AgentWidgetLauncherConfig, type AgentWidgetMessage, type AgentWidgetPlugin, AgentWidgetSession, type AgentWidgetSessionStatus, type AgentWidgetStreamParser, type AgentWidgetStreamParserResult, type AgentWidgetTheme, DEFAULT_WIDGET_CONFIG, createAgentExperience, createJsonStreamParser, createPlainTextParser, createRegexJsonParser, createXmlParser, initAgentWidget as default, directivePostprocessor, escapeHtml, initAgentWidget, markdownPostprocessor, mergeWithDefaults, pluginRegistry };
701
+ export { AgentWidgetClient, type AgentWidgetConfig, type AgentWidgetController, type AgentWidgetEvent, type AgentWidgetFeatureFlags, type AgentWidgetInitHandle, type AgentWidgetInitOptions, type AgentWidgetLauncherConfig, type AgentWidgetMessage, type AgentWidgetPlugin, AgentWidgetSession, type AgentWidgetSessionStatus, type AgentWidgetStreamParser, type AgentWidgetStreamParserResult, type AgentWidgetTheme, DEFAULT_WIDGET_CONFIG, createActionManager, createAgentExperience, createJsonStreamParser, createLocalStorageAdapter, createPlainTextParser, createRegexJsonParser, createXmlParser, initAgentWidget as default, defaultActionHandlers, defaultJsonActionParser, directivePostprocessor, escapeHtml, initAgentWidget, markdownPostprocessor, mergeWithDefaults, pluginRegistry };
package/dist/index.d.ts CHANGED
@@ -75,6 +75,71 @@ interface AgentWidgetPlugin {
75
75
  onUnregister?: () => void;
76
76
  }
77
77
 
78
+ type AgentWidgetContextProviderContext = {
79
+ messages: AgentWidgetMessage[];
80
+ config: AgentWidgetConfig;
81
+ };
82
+ type AgentWidgetContextProvider = (context: AgentWidgetContextProviderContext) => Record<string, unknown> | void | Promise<Record<string, unknown> | void>;
83
+ type AgentWidgetRequestPayloadMessage = {
84
+ role: AgentWidgetMessageRole;
85
+ content: string;
86
+ createdAt: string;
87
+ };
88
+ type AgentWidgetRequestPayload = {
89
+ messages: AgentWidgetRequestPayloadMessage[];
90
+ flowId?: string;
91
+ context?: Record<string, unknown>;
92
+ };
93
+ type AgentWidgetRequestMiddlewareContext = {
94
+ payload: AgentWidgetRequestPayload;
95
+ config: AgentWidgetConfig;
96
+ };
97
+ type AgentWidgetRequestMiddleware = (context: AgentWidgetRequestMiddlewareContext) => AgentWidgetRequestPayload | void | Promise<AgentWidgetRequestPayload | void>;
98
+ type AgentWidgetParsedAction = {
99
+ type: string;
100
+ payload: Record<string, unknown>;
101
+ raw?: unknown;
102
+ };
103
+ type AgentWidgetActionParserInput = {
104
+ text: string;
105
+ message: AgentWidgetMessage;
106
+ };
107
+ type AgentWidgetActionParser = (input: AgentWidgetActionParserInput) => AgentWidgetParsedAction | null | undefined;
108
+ type AgentWidgetActionHandlerResult = {
109
+ handled?: boolean;
110
+ displayText?: string;
111
+ };
112
+ type AgentWidgetActionContext = {
113
+ message: AgentWidgetMessage;
114
+ metadata: Record<string, unknown>;
115
+ updateMetadata: (updater: (prev: Record<string, unknown>) => Record<string, unknown>) => void;
116
+ document: Document | null;
117
+ };
118
+ type AgentWidgetActionHandler = (action: AgentWidgetParsedAction, context: AgentWidgetActionContext) => AgentWidgetActionHandlerResult | void;
119
+ type AgentWidgetStoredState = {
120
+ messages?: AgentWidgetMessage[];
121
+ metadata?: Record<string, unknown>;
122
+ };
123
+ interface AgentWidgetStorageAdapter {
124
+ load?: () => AgentWidgetStoredState | null | Promise<AgentWidgetStoredState | null>;
125
+ save?: (state: AgentWidgetStoredState) => void | Promise<void>;
126
+ clear?: () => void | Promise<void>;
127
+ }
128
+ type AgentWidgetVoiceStateEvent = {
129
+ active: boolean;
130
+ source: "user" | "auto" | "restore" | "system";
131
+ timestamp: number;
132
+ };
133
+ type AgentWidgetActionEventPayload = {
134
+ action: AgentWidgetParsedAction;
135
+ message: AgentWidgetMessage;
136
+ };
137
+ type AgentWidgetControllerEventMap = {
138
+ "assistant:message": AgentWidgetMessage;
139
+ "assistant:complete": AgentWidgetMessage;
140
+ "voice:state": AgentWidgetVoiceStateEvent;
141
+ "action:detected": AgentWidgetActionEventPayload;
142
+ };
78
143
  type AgentWidgetFeatureFlags = {
79
144
  showReasoning?: boolean;
80
145
  showToolCalls?: boolean;
@@ -205,6 +270,7 @@ type AgentWidgetVoiceRecognitionConfig = {
205
270
  recordingBackgroundColor?: string;
206
271
  recordingBorderColor?: string;
207
272
  showRecordingIndicator?: boolean;
273
+ autoResume?: boolean | "assistant";
208
274
  };
209
275
  type AgentWidgetToolCallConfig = {
210
276
  backgroundColor?: string;
@@ -248,7 +314,9 @@ interface AgentWidgetStreamParserResult {
248
314
  */
249
315
  text: string | null;
250
316
  /**
251
- * Optional: The raw accumulated content (useful for middleware that needs the original format)
317
+ * The raw accumulated content. Built-in parsers always populate this so
318
+ * downstream middleware (action handlers, logging, etc.) can
319
+ * inspect/parse the original structured payload.
252
320
  */
253
321
  raw?: string;
254
322
  }
@@ -300,8 +368,14 @@ type AgentWidgetConfig = {
300
368
  text: string;
301
369
  message: AgentWidgetMessage;
302
370
  streaming: boolean;
371
+ raw?: string;
303
372
  }) => string;
304
373
  plugins?: AgentWidgetPlugin[];
374
+ contextProviders?: AgentWidgetContextProvider[];
375
+ requestMiddleware?: AgentWidgetRequestMiddleware;
376
+ actionParsers?: AgentWidgetActionParser[];
377
+ actionHandlers?: AgentWidgetActionHandler[];
378
+ storageAdapter?: AgentWidgetStorageAdapter;
305
379
  /**
306
380
  * Custom stream parser for extracting text from streaming structured responses.
307
381
  * Handles incremental parsing of JSON, XML, or other formats.
@@ -333,6 +407,31 @@ type AgentWidgetConfig = {
333
407
  * ```
334
408
  */
335
409
  clearChatHistoryStorageKey?: string;
410
+ /**
411
+ * Built-in parser type selector. Provides an easy way to choose a parser without importing functions.
412
+ * If both `parserType` and `streamParser` are provided, `streamParser` takes precedence.
413
+ *
414
+ * - `"plain"` - Plain text parser (default). Passes through text as-is.
415
+ * - `"json"` - JSON parser using partial-json. Extracts `text` field from JSON objects incrementally.
416
+ * - `"regex-json"` - Regex-based JSON parser. Less robust but faster fallback for simple JSON.
417
+ * - `"xml"` - XML parser. Extracts text content from XML tags.
418
+ *
419
+ * @example
420
+ * ```typescript
421
+ * config: {
422
+ * parserType: "json" // Use built-in JSON parser
423
+ * }
424
+ * ```
425
+ *
426
+ * @example
427
+ * ```typescript
428
+ * config: {
429
+ * parserType: "json",
430
+ * streamParser: () => customParser() // Custom parser overrides parserType
431
+ * }
432
+ * ```
433
+ */
434
+ parserType?: "plain" | "json" | "regex-json" | "xml";
336
435
  };
337
436
  type AgentWidgetMessageRole = "user" | "assistant" | "system";
338
437
  type AgentWidgetReasoning = {
@@ -384,6 +483,11 @@ type AgentWidgetMessage = {
384
483
  toolCall?: AgentWidgetToolCall;
385
484
  tools?: AgentWidgetToolCall[];
386
485
  viaVoice?: boolean;
486
+ /**
487
+ * Raw structured payload for this message (e.g., JSON action response).
488
+ * Populated automatically when structured parsers run.
489
+ */
490
+ rawContent?: string;
387
491
  };
388
492
  type AgentWidgetEvent = {
389
493
  type: "message";
@@ -401,29 +505,9 @@ type AgentWidgetInitOptions = {
401
505
  useShadowDom?: boolean;
402
506
  onReady?: () => void;
403
507
  windowKey?: string;
508
+ debugTools?: boolean;
404
509
  };
405
510
 
406
- type Controller = {
407
- update: (config: AgentWidgetConfig) => void;
408
- destroy: () => void;
409
- open: () => void;
410
- close: () => void;
411
- toggle: () => void;
412
- clearChat: () => void;
413
- setMessage: (message: string) => boolean;
414
- submitMessage: (message?: string) => boolean;
415
- startVoiceRecognition: () => boolean;
416
- stopVoiceRecognition: () => boolean;
417
- injectTestMessage: (event: AgentWidgetEvent) => void;
418
- };
419
- declare const createAgentExperience: (mount: HTMLElement, initialConfig?: AgentWidgetConfig) => Controller;
420
- type AgentWidgetController = Controller;
421
-
422
- type AgentWidgetInitHandle = AgentWidgetController & {
423
- host: HTMLElement;
424
- };
425
- declare const initAgentWidget: (options: AgentWidgetInitOptions) => AgentWidgetInitHandle;
426
-
427
511
  type AgentWidgetSessionStatus = "idle" | "connecting" | "connected" | "error";
428
512
  type SessionCallbacks = {
429
513
  onMessagesChanged: (messages: AgentWidgetMessage[]) => void;
@@ -451,6 +535,7 @@ declare class AgentWidgetSession {
451
535
  }): Promise<void>;
452
536
  cancel(): void;
453
537
  clearMessages(): void;
538
+ hydrateMessages(messages: AgentWidgetMessage[]): void;
454
539
  private handleEvent;
455
540
  private setStatus;
456
541
  private setStreaming;
@@ -461,6 +546,35 @@ declare class AgentWidgetSession {
461
546
  private sortMessages;
462
547
  }
463
548
 
549
+ type Controller = {
550
+ update: (config: AgentWidgetConfig) => void;
551
+ destroy: () => void;
552
+ open: () => void;
553
+ close: () => void;
554
+ toggle: () => void;
555
+ clearChat: () => void;
556
+ setMessage: (message: string) => boolean;
557
+ submitMessage: (message?: string) => boolean;
558
+ startVoiceRecognition: () => boolean;
559
+ stopVoiceRecognition: () => boolean;
560
+ injectTestMessage: (event: AgentWidgetEvent) => void;
561
+ getMessages: () => AgentWidgetMessage[];
562
+ getStatus: () => AgentWidgetSessionStatus;
563
+ getPersistentMetadata: () => Record<string, unknown>;
564
+ updatePersistentMetadata: (updater: (prev: Record<string, unknown>) => Record<string, unknown>) => void;
565
+ on: <K extends keyof AgentWidgetControllerEventMap>(event: K, handler: (payload: AgentWidgetControllerEventMap[K]) => void) => () => void;
566
+ off: <K extends keyof AgentWidgetControllerEventMap>(event: K, handler: (payload: AgentWidgetControllerEventMap[K]) => void) => void;
567
+ };
568
+ declare const createAgentExperience: (mount: HTMLElement, initialConfig?: AgentWidgetConfig, runtimeOptions?: {
569
+ debugTools?: boolean;
570
+ }) => Controller;
571
+ type AgentWidgetController = Controller;
572
+
573
+ type AgentWidgetInitHandle = AgentWidgetController & {
574
+ host: HTMLElement;
575
+ };
576
+ declare const initAgentWidget: (options: AgentWidgetInitOptions) => AgentWidgetInitHandle;
577
+
464
578
  type DispatchOptions = {
465
579
  messages: AgentWidgetMessage[];
466
580
  signal?: AbortSignal;
@@ -472,11 +586,37 @@ declare class AgentWidgetClient {
472
586
  private readonly headers;
473
587
  private readonly debug;
474
588
  private readonly createStreamParser;
589
+ private readonly contextProviders;
590
+ private readonly requestMiddleware?;
475
591
  constructor(config?: AgentWidgetConfig);
476
592
  dispatch(options: DispatchOptions, onEvent: SSEHandler): Promise<void>;
593
+ private buildPayload;
477
594
  private streamResponse;
478
595
  }
479
596
 
597
+ declare const createLocalStorageAdapter: (key?: string) => AgentWidgetStorageAdapter;
598
+
599
+ type ActionManagerProcessContext = {
600
+ text: string;
601
+ message: AgentWidgetMessage;
602
+ streaming: boolean;
603
+ raw?: string;
604
+ };
605
+ type ActionManagerOptions = {
606
+ parsers: AgentWidgetActionParser[];
607
+ handlers: AgentWidgetActionHandler[];
608
+ getMetadata: () => Record<string, unknown>;
609
+ updateMetadata: (updater: (prev: Record<string, unknown>) => Record<string, unknown>) => void;
610
+ emit: <K extends keyof AgentWidgetControllerEventMap>(event: K, payload: AgentWidgetControllerEventMap[K]) => void;
611
+ documentRef: Document | null;
612
+ };
613
+ declare const defaultJsonActionParser: AgentWidgetActionParser;
614
+ declare const defaultActionHandlers: Record<string, AgentWidgetActionHandler>;
615
+ declare const createActionManager: (options: ActionManagerOptions) => {
616
+ process: (context: ActionManagerProcessContext) => string | null;
617
+ syncFromMetadata: () => void;
618
+ };
619
+
480
620
  /**
481
621
  * Basic markdown renderer. Remember to sanitize the returned HTML if you render
482
622
  * untrusted content in your host page.
@@ -558,4 +698,4 @@ declare const DEFAULT_WIDGET_CONFIG: Partial<AgentWidgetConfig>;
558
698
  */
559
699
  declare function mergeWithDefaults(config?: Partial<AgentWidgetConfig>): Partial<AgentWidgetConfig>;
560
700
 
561
- export { AgentWidgetClient, type AgentWidgetConfig, type AgentWidgetController, type AgentWidgetEvent, type AgentWidgetFeatureFlags, type AgentWidgetInitHandle, type AgentWidgetInitOptions, type AgentWidgetLauncherConfig, type AgentWidgetMessage, type AgentWidgetPlugin, AgentWidgetSession, type AgentWidgetSessionStatus, type AgentWidgetStreamParser, type AgentWidgetStreamParserResult, type AgentWidgetTheme, DEFAULT_WIDGET_CONFIG, createAgentExperience, createJsonStreamParser, createPlainTextParser, createRegexJsonParser, createXmlParser, initAgentWidget as default, directivePostprocessor, escapeHtml, initAgentWidget, markdownPostprocessor, mergeWithDefaults, pluginRegistry };
701
+ export { AgentWidgetClient, type AgentWidgetConfig, type AgentWidgetController, type AgentWidgetEvent, type AgentWidgetFeatureFlags, type AgentWidgetInitHandle, type AgentWidgetInitOptions, type AgentWidgetLauncherConfig, type AgentWidgetMessage, type AgentWidgetPlugin, AgentWidgetSession, type AgentWidgetSessionStatus, type AgentWidgetStreamParser, type AgentWidgetStreamParserResult, type AgentWidgetTheme, DEFAULT_WIDGET_CONFIG, createActionManager, createAgentExperience, createJsonStreamParser, createLocalStorageAdapter, createPlainTextParser, createRegexJsonParser, createXmlParser, initAgentWidget as default, defaultActionHandlers, defaultJsonActionParser, directivePostprocessor, escapeHtml, initAgentWidget, markdownPostprocessor, mergeWithDefaults, pluginRegistry };