@runtypelabs/persona 1.44.2 → 1.46.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
@@ -65,6 +65,15 @@ interface AgentWidgetPlugin {
65
65
  defaultRenderer: () => HTMLElement;
66
66
  config: AgentWidgetConfig;
67
67
  }) => HTMLElement | null;
68
+ /**
69
+ * Custom renderer for approval bubbles
70
+ * Return null to use default renderer
71
+ */
72
+ renderApproval?: (context: {
73
+ message: AgentWidgetMessage;
74
+ defaultRenderer: () => HTMLElement;
75
+ config: AgentWidgetConfig;
76
+ }) => HTMLElement | null;
68
77
  /**
69
78
  * Custom renderer for loading indicator
70
79
  * Return null to use default renderer (or config-based renderer)
@@ -431,6 +440,14 @@ type AgentWidgetControllerEventMap = {
431
440
  "eventStream:closed": {
432
441
  timestamp: number;
433
442
  };
443
+ "approval:requested": {
444
+ approval: AgentWidgetApproval;
445
+ message: AgentWidgetMessage;
446
+ };
447
+ "approval:resolved": {
448
+ approval: AgentWidgetApproval;
449
+ decision: string;
450
+ };
434
451
  };
435
452
  type AgentWidgetFeatureFlags = {
436
453
  showReasoning?: boolean;
@@ -748,6 +765,49 @@ type AgentWidgetVoiceRecognitionConfig = {
748
765
  showRecordingIndicator?: boolean;
749
766
  autoResume?: boolean | "assistant";
750
767
  };
768
+ /**
769
+ * Configuration for tool approval bubbles.
770
+ * Controls styling, labels, and behavior of the approval UI.
771
+ */
772
+ type AgentWidgetApprovalConfig = {
773
+ /** Background color of the approval bubble */
774
+ backgroundColor?: string;
775
+ /** Border color of the approval bubble */
776
+ borderColor?: string;
777
+ /** Color for the title text */
778
+ titleColor?: string;
779
+ /** Color for the description text */
780
+ descriptionColor?: string;
781
+ /** Background color for the approve button */
782
+ approveButtonColor?: string;
783
+ /** Text color for the approve button */
784
+ approveButtonTextColor?: string;
785
+ /** Background color for the deny button */
786
+ denyButtonColor?: string;
787
+ /** Text color for the deny button */
788
+ denyButtonTextColor?: string;
789
+ /** Background color for the parameters block */
790
+ parameterBackgroundColor?: string;
791
+ /** Text color for the parameters block */
792
+ parameterTextColor?: string;
793
+ /** Title text displayed above the description */
794
+ title?: string;
795
+ /** Label for the approve button */
796
+ approveLabel?: string;
797
+ /** Label for the deny button */
798
+ denyLabel?: string;
799
+ /**
800
+ * Custom handler for approval decisions.
801
+ * Return void to let the SDK auto-resolve via the API,
802
+ * or return a Response/ReadableStream for custom handling.
803
+ */
804
+ onDecision?: (data: {
805
+ approvalId: string;
806
+ executionId: string;
807
+ agentId: string;
808
+ toolName: string;
809
+ }, decision: 'approved' | 'denied') => Promise<Response | ReadableStream<Uint8Array> | void>;
810
+ };
751
811
  type AgentWidgetToolCallConfig = {
752
812
  backgroundColor?: string;
753
813
  borderColor?: string;
@@ -1760,6 +1820,13 @@ type AgentWidgetConfig = {
1760
1820
  */
1761
1821
  colorScheme?: 'auto' | 'light' | 'dark';
1762
1822
  features?: AgentWidgetFeatureFlags;
1823
+ /**
1824
+ * When true, focus the chat input after the panel opens and the open animation completes.
1825
+ * Applies to launcher mode (user click, controller.open(), autoExpand) and inline mode (on init).
1826
+ * Skip when voice is active to avoid stealing focus from voice UI.
1827
+ * @default false
1828
+ */
1829
+ autoFocusInput?: boolean;
1763
1830
  launcher?: AgentWidgetLauncherConfig;
1764
1831
  initialMessages?: AgentWidgetMessage[];
1765
1832
  suggestionChips?: string[];
@@ -1771,6 +1838,23 @@ type AgentWidgetConfig = {
1771
1838
  statusIndicator?: AgentWidgetStatusIndicatorConfig;
1772
1839
  voiceRecognition?: AgentWidgetVoiceRecognitionConfig;
1773
1840
  toolCall?: AgentWidgetToolCallConfig;
1841
+ /**
1842
+ * Configuration for tool approval bubbles.
1843
+ * Set to `false` to disable built-in approval handling entirely.
1844
+ *
1845
+ * @example
1846
+ * ```typescript
1847
+ * config: {
1848
+ * approval: {
1849
+ * title: "Permission Required",
1850
+ * approveLabel: "Allow",
1851
+ * denyLabel: "Block",
1852
+ * approveButtonColor: "#16a34a"
1853
+ * }
1854
+ * }
1855
+ * ```
1856
+ */
1857
+ approval?: AgentWidgetApprovalConfig | false;
1774
1858
  postprocessMessage?: (context: {
1775
1859
  text: string;
1776
1860
  message: AgentWidgetMessage;
@@ -2110,7 +2194,22 @@ type AgentWidgetToolCall = {
2110
2194
  completedAt?: number;
2111
2195
  durationMs?: number;
2112
2196
  };
2113
- type AgentWidgetMessageVariant = "assistant" | "reasoning" | "tool";
2197
+ /**
2198
+ * Represents a tool approval request in the chat conversation.
2199
+ * Created when the agent requires human approval before executing a tool.
2200
+ */
2201
+ type AgentWidgetApproval = {
2202
+ id: string;
2203
+ status: "pending" | "approved" | "denied" | "timeout";
2204
+ agentId: string;
2205
+ executionId: string;
2206
+ toolName: string;
2207
+ toolType?: string;
2208
+ description: string;
2209
+ parameters?: unknown;
2210
+ resolvedAt?: number;
2211
+ };
2212
+ type AgentWidgetMessageVariant = "assistant" | "reasoning" | "tool" | "approval";
2114
2213
  /**
2115
2214
  * Represents a message in the chat conversation.
2116
2215
  *
@@ -2145,6 +2244,8 @@ type AgentWidgetMessage = {
2145
2244
  reasoning?: AgentWidgetReasoning;
2146
2245
  toolCall?: AgentWidgetToolCall;
2147
2246
  tools?: AgentWidgetToolCall[];
2247
+ /** Approval data for messages with variant "approval" */
2248
+ approval?: AgentWidgetApproval;
2148
2249
  viaVoice?: boolean;
2149
2250
  /**
2150
2251
  * Raw structured payload for this message (e.g., JSON action response).
@@ -2409,6 +2510,21 @@ declare class AgentWidgetClient {
2409
2510
  * Agent mode dispatch
2410
2511
  */
2411
2512
  private dispatchAgent;
2513
+ /**
2514
+ * Process an external SSE stream through the SDK's event pipeline.
2515
+ * This allows piping responses from endpoints like agent approval
2516
+ * through the same message/tool/reasoning handling as dispatch().
2517
+ */
2518
+ processStream(body: ReadableStream<Uint8Array>, onEvent: SSEHandler, assistantMessageId?: string): Promise<void>;
2519
+ /**
2520
+ * Send an approval decision to the API and return the response
2521
+ * for streaming continuation.
2522
+ */
2523
+ resolveApproval(approval: {
2524
+ agentId: string;
2525
+ executionId: string;
2526
+ approvalId: string;
2527
+ }, decision: 'approved' | 'denied'): Promise<Response>;
2412
2528
  private buildAgentPayload;
2413
2529
  private buildPayload;
2414
2530
  /**
@@ -2604,6 +2720,19 @@ declare class AgentWidgetSession {
2604
2720
  * session.continueConversation();
2605
2721
  */
2606
2722
  continueConversation(): Promise<void>;
2723
+ /**
2724
+ * Connect an external SSE stream (e.g. from an approval endpoint) and
2725
+ * process it through the SDK's native event pipeline.
2726
+ */
2727
+ connectStream(stream: ReadableStream<Uint8Array>, options?: {
2728
+ assistantMessageId?: string;
2729
+ }): Promise<void>;
2730
+ /**
2731
+ * Resolve a tool approval request (approve or deny).
2732
+ * Updates the approval message status, calls the API (or custom onDecision),
2733
+ * and pipes the response stream through connectStream().
2734
+ */
2735
+ resolveApproval(approval: AgentWidgetApproval, decision: 'approved' | 'denied'): Promise<void>;
2607
2736
  cancel(): void;
2608
2737
  clearMessages(): void;
2609
2738
  hydrateMessages(messages: AgentWidgetMessage[]): void;
@@ -2722,6 +2851,13 @@ type Controller = {
2722
2851
  showNPSFeedback: (options?: Partial<NPSFeedbackOptions>) => void;
2723
2852
  submitCSATFeedback: (rating: number, comment?: string) => Promise<void>;
2724
2853
  submitNPSFeedback: (rating: number, comment?: string) => Promise<void>;
2854
+ /**
2855
+ * Connect an external SSE stream and process it through the SDK's
2856
+ * native event pipeline (tools, reasoning, streaming text, etc.).
2857
+ */
2858
+ connectStream: (stream: ReadableStream<Uint8Array>, options?: {
2859
+ assistantMessageId?: string;
2860
+ }) => Promise<void>;
2725
2861
  /** Push a raw event into the event stream buffer (for testing/debugging) */
2726
2862
  __pushEventStreamEvent: (event: {
2727
2863
  type: string;
@@ -2733,6 +2869,17 @@ type Controller = {
2733
2869
  hideEventStream: () => void;
2734
2870
  /** Returns current visibility state of the event stream panel */
2735
2871
  isEventStreamVisible: () => boolean;
2872
+ /**
2873
+ * Focus the chat input. Returns true if focus succeeded, false if panel is closed
2874
+ * (launcher mode) or textarea is unavailable.
2875
+ */
2876
+ focusInput: () => boolean;
2877
+ /**
2878
+ * Programmatically resolve a pending approval.
2879
+ * @param approvalId - The approval ID to resolve
2880
+ * @param decision - "approved" or "denied"
2881
+ */
2882
+ resolveApproval: (approvalId: string, decision: 'approved' | 'denied') => Promise<void>;
2736
2883
  };
2737
2884
  declare const createAgentExperience: (mount: HTMLElement, initialConfig?: AgentWidgetConfig, runtimeOptions?: {
2738
2885
  debugTools?: boolean;
@@ -3493,4 +3640,4 @@ declare const getHeaderLayout: (layoutName: string) => HeaderLayoutRenderer;
3493
3640
  */
3494
3641
  declare const buildHeaderWithLayout: (config: AgentWidgetConfig, layoutConfig?: AgentWidgetHeaderLayoutConfig, context?: Partial<HeaderLayoutContext>) => HeaderElements;
3495
3642
 
3496
- export { type AgentConfig, type AgentExecutionState, type AgentLoopConfig, type AgentMessageMetadata, type AgentRequestOptions, type AgentWidgetAgentRequestPayload, type AgentWidgetAttachmentsConfig, type AgentWidgetAvatarConfig, AgentWidgetClient, type AgentWidgetConfig, type AgentWidgetController, type AgentWidgetControllerEventMap, type AgentWidgetCustomFetch, type AgentWidgetEvent, type AgentWidgetFeatureFlags, type AgentWidgetHeaderLayoutConfig, type AgentWidgetHeadersFunction, type AgentWidgetInitHandle, type AgentWidgetInitOptions, type AgentWidgetLauncherConfig, type AgentWidgetLayoutConfig, type AgentWidgetLoadingIndicatorConfig, type AgentWidgetMarkdownConfig, type AgentWidgetMarkdownOptions, type AgentWidgetMarkdownRendererOverrides, type AgentWidgetMessage, type AgentWidgetMessageActionsConfig, type AgentWidgetMessageFeedback, type AgentWidgetMessageLayoutConfig, type AgentWidgetPlugin, type AgentWidgetRequestPayload, type AgentWidgetSSEEventParser, type AgentWidgetSSEEventResult, AgentWidgetSession, type AgentWidgetSessionStatus, type AgentWidgetStreamParser, type AgentWidgetStreamParserResult, type AgentWidgetTheme, type AgentWidgetTimestampConfig, AttachmentManager, type AttachmentManagerConfig, type CSATFeedbackOptions, type ClientChatRequest, type ClientFeedbackRequest, type ClientFeedbackType, type ClientInitResponse, type ClientSession, type CodeFormat, type CodeGeneratorHooks, type CodeGeneratorOptions, type ComponentContext, type ComponentDirective, type ComponentRenderer, type ComposerBuildContext, type ComposerElements, type ContentPart, type CreateStandardBubbleOptions, DEFAULT_DARK_THEME, DEFAULT_LIGHT_THEME, DEFAULT_WIDGET_CONFIG, type EventStreamBadgeColor, type EventStreamConfig, type EventStreamPayloadRenderContext, type EventStreamRowRenderContext, type EventStreamToolbarRenderContext, type EventStreamViewRenderContext, type HeaderBuildContext, type HeaderElements, type HeaderLayoutContext, type HeaderLayoutRenderer, type HeaderRenderContext, type IdleIndicatorRenderContext, type ImageContentPart, type InjectAssistantMessageOptions, type InjectMessageOptions, type InjectSystemMessageOptions, type InjectUserMessageOptions, type LoadingIndicatorRenderContext, type LoadingIndicatorRenderer, type MarkdownProcessorOptions, type MessageActionCallbacks, type MessageContent, type MessageRenderContext, type MessageTransform, type NPSFeedbackOptions, type PendingAttachment, type SSEEventCallback, type SSEEventRecord, type SlotRenderContext, type SlotRenderer, type TextContentPart, VERSION, type WidgetLayoutSlot, attachHeaderToContainer, buildComposer, buildDefaultHeader, buildExpandedHeader, buildHeader, buildHeaderWithLayout, buildMinimalHeader, componentRegistry, createActionManager, createAgentExperience, createBubbleWithLayout, createCSATFeedback, createComponentMiddleware, createComponentStreamParser, createDirectivePostprocessor, createFlexibleJsonStreamParser, createImagePart, createJsonStreamParser, createLocalStorageAdapter, createMarkdownProcessor, createMarkdownProcessorFromConfig, createMessageActions, createNPSFeedback, createPlainTextParser, createRegexJsonParser, createStandardBubble, createTextPart, createTypingIndicator, createXmlParser, initAgentWidget as default, defaultActionHandlers, defaultJsonActionParser, directivePostprocessor, escapeHtml, extractComponentDirectiveFromMessage, fileToImagePart, generateAssistantMessageId, generateCodeSnippet, generateMessageId, generateUserMessageId, getDisplayText, getHeaderLayout, getImageParts, hasComponentDirective, hasImages, headerLayouts, initAgentWidget, isComponentDirectiveType, markdownPostprocessor, mergeWithDefaults, normalizeContent, pluginRegistry, renderComponentDirective, renderLoadingIndicatorWithFallback, validateImageFile };
3643
+ export { type AgentConfig, type AgentExecutionState, type AgentLoopConfig, type AgentMessageMetadata, type AgentRequestOptions, type AgentWidgetAgentRequestPayload, type AgentWidgetApproval, type AgentWidgetApprovalConfig, type AgentWidgetAttachmentsConfig, type AgentWidgetAvatarConfig, AgentWidgetClient, type AgentWidgetConfig, type AgentWidgetController, type AgentWidgetControllerEventMap, type AgentWidgetCustomFetch, type AgentWidgetEvent, type AgentWidgetFeatureFlags, type AgentWidgetHeaderLayoutConfig, type AgentWidgetHeadersFunction, type AgentWidgetInitHandle, type AgentWidgetInitOptions, type AgentWidgetLauncherConfig, type AgentWidgetLayoutConfig, type AgentWidgetLoadingIndicatorConfig, type AgentWidgetMarkdownConfig, type AgentWidgetMarkdownOptions, type AgentWidgetMarkdownRendererOverrides, type AgentWidgetMessage, type AgentWidgetMessageActionsConfig, type AgentWidgetMessageFeedback, type AgentWidgetMessageLayoutConfig, type AgentWidgetPlugin, type AgentWidgetRequestPayload, type AgentWidgetSSEEventParser, type AgentWidgetSSEEventResult, AgentWidgetSession, type AgentWidgetSessionStatus, type AgentWidgetStreamParser, type AgentWidgetStreamParserResult, type AgentWidgetTheme, type AgentWidgetTimestampConfig, AttachmentManager, type AttachmentManagerConfig, type CSATFeedbackOptions, type ClientChatRequest, type ClientFeedbackRequest, type ClientFeedbackType, type ClientInitResponse, type ClientSession, type CodeFormat, type CodeGeneratorHooks, type CodeGeneratorOptions, type ComponentContext, type ComponentDirective, type ComponentRenderer, type ComposerBuildContext, type ComposerElements, type ContentPart, type CreateStandardBubbleOptions, DEFAULT_DARK_THEME, DEFAULT_LIGHT_THEME, DEFAULT_WIDGET_CONFIG, type EventStreamBadgeColor, type EventStreamConfig, type EventStreamPayloadRenderContext, type EventStreamRowRenderContext, type EventStreamToolbarRenderContext, type EventStreamViewRenderContext, type HeaderBuildContext, type HeaderElements, type HeaderLayoutContext, type HeaderLayoutRenderer, type HeaderRenderContext, type IdleIndicatorRenderContext, type ImageContentPart, type InjectAssistantMessageOptions, type InjectMessageOptions, type InjectSystemMessageOptions, type InjectUserMessageOptions, type LoadingIndicatorRenderContext, type LoadingIndicatorRenderer, type MarkdownProcessorOptions, type MessageActionCallbacks, type MessageContent, type MessageRenderContext, type MessageTransform, type NPSFeedbackOptions, type PendingAttachment, type SSEEventCallback, type SSEEventRecord, type SlotRenderContext, type SlotRenderer, type TextContentPart, VERSION, type WidgetLayoutSlot, attachHeaderToContainer, buildComposer, buildDefaultHeader, buildExpandedHeader, buildHeader, buildHeaderWithLayout, buildMinimalHeader, componentRegistry, createActionManager, createAgentExperience, createBubbleWithLayout, createCSATFeedback, createComponentMiddleware, createComponentStreamParser, createDirectivePostprocessor, createFlexibleJsonStreamParser, createImagePart, createJsonStreamParser, createLocalStorageAdapter, createMarkdownProcessor, createMarkdownProcessorFromConfig, createMessageActions, createNPSFeedback, createPlainTextParser, createRegexJsonParser, createStandardBubble, createTextPart, createTypingIndicator, createXmlParser, initAgentWidget as default, defaultActionHandlers, defaultJsonActionParser, directivePostprocessor, escapeHtml, extractComponentDirectiveFromMessage, fileToImagePart, generateAssistantMessageId, generateCodeSnippet, generateMessageId, generateUserMessageId, getDisplayText, getHeaderLayout, getImageParts, hasComponentDirective, hasImages, headerLayouts, initAgentWidget, isComponentDirectiveType, markdownPostprocessor, mergeWithDefaults, normalizeContent, pluginRegistry, renderComponentDirective, renderLoadingIndicatorWithFallback, validateImageFile };
package/dist/index.d.ts CHANGED
@@ -65,6 +65,15 @@ interface AgentWidgetPlugin {
65
65
  defaultRenderer: () => HTMLElement;
66
66
  config: AgentWidgetConfig;
67
67
  }) => HTMLElement | null;
68
+ /**
69
+ * Custom renderer for approval bubbles
70
+ * Return null to use default renderer
71
+ */
72
+ renderApproval?: (context: {
73
+ message: AgentWidgetMessage;
74
+ defaultRenderer: () => HTMLElement;
75
+ config: AgentWidgetConfig;
76
+ }) => HTMLElement | null;
68
77
  /**
69
78
  * Custom renderer for loading indicator
70
79
  * Return null to use default renderer (or config-based renderer)
@@ -431,6 +440,14 @@ type AgentWidgetControllerEventMap = {
431
440
  "eventStream:closed": {
432
441
  timestamp: number;
433
442
  };
443
+ "approval:requested": {
444
+ approval: AgentWidgetApproval;
445
+ message: AgentWidgetMessage;
446
+ };
447
+ "approval:resolved": {
448
+ approval: AgentWidgetApproval;
449
+ decision: string;
450
+ };
434
451
  };
435
452
  type AgentWidgetFeatureFlags = {
436
453
  showReasoning?: boolean;
@@ -748,6 +765,49 @@ type AgentWidgetVoiceRecognitionConfig = {
748
765
  showRecordingIndicator?: boolean;
749
766
  autoResume?: boolean | "assistant";
750
767
  };
768
+ /**
769
+ * Configuration for tool approval bubbles.
770
+ * Controls styling, labels, and behavior of the approval UI.
771
+ */
772
+ type AgentWidgetApprovalConfig = {
773
+ /** Background color of the approval bubble */
774
+ backgroundColor?: string;
775
+ /** Border color of the approval bubble */
776
+ borderColor?: string;
777
+ /** Color for the title text */
778
+ titleColor?: string;
779
+ /** Color for the description text */
780
+ descriptionColor?: string;
781
+ /** Background color for the approve button */
782
+ approveButtonColor?: string;
783
+ /** Text color for the approve button */
784
+ approveButtonTextColor?: string;
785
+ /** Background color for the deny button */
786
+ denyButtonColor?: string;
787
+ /** Text color for the deny button */
788
+ denyButtonTextColor?: string;
789
+ /** Background color for the parameters block */
790
+ parameterBackgroundColor?: string;
791
+ /** Text color for the parameters block */
792
+ parameterTextColor?: string;
793
+ /** Title text displayed above the description */
794
+ title?: string;
795
+ /** Label for the approve button */
796
+ approveLabel?: string;
797
+ /** Label for the deny button */
798
+ denyLabel?: string;
799
+ /**
800
+ * Custom handler for approval decisions.
801
+ * Return void to let the SDK auto-resolve via the API,
802
+ * or return a Response/ReadableStream for custom handling.
803
+ */
804
+ onDecision?: (data: {
805
+ approvalId: string;
806
+ executionId: string;
807
+ agentId: string;
808
+ toolName: string;
809
+ }, decision: 'approved' | 'denied') => Promise<Response | ReadableStream<Uint8Array> | void>;
810
+ };
751
811
  type AgentWidgetToolCallConfig = {
752
812
  backgroundColor?: string;
753
813
  borderColor?: string;
@@ -1760,6 +1820,13 @@ type AgentWidgetConfig = {
1760
1820
  */
1761
1821
  colorScheme?: 'auto' | 'light' | 'dark';
1762
1822
  features?: AgentWidgetFeatureFlags;
1823
+ /**
1824
+ * When true, focus the chat input after the panel opens and the open animation completes.
1825
+ * Applies to launcher mode (user click, controller.open(), autoExpand) and inline mode (on init).
1826
+ * Skip when voice is active to avoid stealing focus from voice UI.
1827
+ * @default false
1828
+ */
1829
+ autoFocusInput?: boolean;
1763
1830
  launcher?: AgentWidgetLauncherConfig;
1764
1831
  initialMessages?: AgentWidgetMessage[];
1765
1832
  suggestionChips?: string[];
@@ -1771,6 +1838,23 @@ type AgentWidgetConfig = {
1771
1838
  statusIndicator?: AgentWidgetStatusIndicatorConfig;
1772
1839
  voiceRecognition?: AgentWidgetVoiceRecognitionConfig;
1773
1840
  toolCall?: AgentWidgetToolCallConfig;
1841
+ /**
1842
+ * Configuration for tool approval bubbles.
1843
+ * Set to `false` to disable built-in approval handling entirely.
1844
+ *
1845
+ * @example
1846
+ * ```typescript
1847
+ * config: {
1848
+ * approval: {
1849
+ * title: "Permission Required",
1850
+ * approveLabel: "Allow",
1851
+ * denyLabel: "Block",
1852
+ * approveButtonColor: "#16a34a"
1853
+ * }
1854
+ * }
1855
+ * ```
1856
+ */
1857
+ approval?: AgentWidgetApprovalConfig | false;
1774
1858
  postprocessMessage?: (context: {
1775
1859
  text: string;
1776
1860
  message: AgentWidgetMessage;
@@ -2110,7 +2194,22 @@ type AgentWidgetToolCall = {
2110
2194
  completedAt?: number;
2111
2195
  durationMs?: number;
2112
2196
  };
2113
- type AgentWidgetMessageVariant = "assistant" | "reasoning" | "tool";
2197
+ /**
2198
+ * Represents a tool approval request in the chat conversation.
2199
+ * Created when the agent requires human approval before executing a tool.
2200
+ */
2201
+ type AgentWidgetApproval = {
2202
+ id: string;
2203
+ status: "pending" | "approved" | "denied" | "timeout";
2204
+ agentId: string;
2205
+ executionId: string;
2206
+ toolName: string;
2207
+ toolType?: string;
2208
+ description: string;
2209
+ parameters?: unknown;
2210
+ resolvedAt?: number;
2211
+ };
2212
+ type AgentWidgetMessageVariant = "assistant" | "reasoning" | "tool" | "approval";
2114
2213
  /**
2115
2214
  * Represents a message in the chat conversation.
2116
2215
  *
@@ -2145,6 +2244,8 @@ type AgentWidgetMessage = {
2145
2244
  reasoning?: AgentWidgetReasoning;
2146
2245
  toolCall?: AgentWidgetToolCall;
2147
2246
  tools?: AgentWidgetToolCall[];
2247
+ /** Approval data for messages with variant "approval" */
2248
+ approval?: AgentWidgetApproval;
2148
2249
  viaVoice?: boolean;
2149
2250
  /**
2150
2251
  * Raw structured payload for this message (e.g., JSON action response).
@@ -2409,6 +2510,21 @@ declare class AgentWidgetClient {
2409
2510
  * Agent mode dispatch
2410
2511
  */
2411
2512
  private dispatchAgent;
2513
+ /**
2514
+ * Process an external SSE stream through the SDK's event pipeline.
2515
+ * This allows piping responses from endpoints like agent approval
2516
+ * through the same message/tool/reasoning handling as dispatch().
2517
+ */
2518
+ processStream(body: ReadableStream<Uint8Array>, onEvent: SSEHandler, assistantMessageId?: string): Promise<void>;
2519
+ /**
2520
+ * Send an approval decision to the API and return the response
2521
+ * for streaming continuation.
2522
+ */
2523
+ resolveApproval(approval: {
2524
+ agentId: string;
2525
+ executionId: string;
2526
+ approvalId: string;
2527
+ }, decision: 'approved' | 'denied'): Promise<Response>;
2412
2528
  private buildAgentPayload;
2413
2529
  private buildPayload;
2414
2530
  /**
@@ -2604,6 +2720,19 @@ declare class AgentWidgetSession {
2604
2720
  * session.continueConversation();
2605
2721
  */
2606
2722
  continueConversation(): Promise<void>;
2723
+ /**
2724
+ * Connect an external SSE stream (e.g. from an approval endpoint) and
2725
+ * process it through the SDK's native event pipeline.
2726
+ */
2727
+ connectStream(stream: ReadableStream<Uint8Array>, options?: {
2728
+ assistantMessageId?: string;
2729
+ }): Promise<void>;
2730
+ /**
2731
+ * Resolve a tool approval request (approve or deny).
2732
+ * Updates the approval message status, calls the API (or custom onDecision),
2733
+ * and pipes the response stream through connectStream().
2734
+ */
2735
+ resolveApproval(approval: AgentWidgetApproval, decision: 'approved' | 'denied'): Promise<void>;
2607
2736
  cancel(): void;
2608
2737
  clearMessages(): void;
2609
2738
  hydrateMessages(messages: AgentWidgetMessage[]): void;
@@ -2722,6 +2851,13 @@ type Controller = {
2722
2851
  showNPSFeedback: (options?: Partial<NPSFeedbackOptions>) => void;
2723
2852
  submitCSATFeedback: (rating: number, comment?: string) => Promise<void>;
2724
2853
  submitNPSFeedback: (rating: number, comment?: string) => Promise<void>;
2854
+ /**
2855
+ * Connect an external SSE stream and process it through the SDK's
2856
+ * native event pipeline (tools, reasoning, streaming text, etc.).
2857
+ */
2858
+ connectStream: (stream: ReadableStream<Uint8Array>, options?: {
2859
+ assistantMessageId?: string;
2860
+ }) => Promise<void>;
2725
2861
  /** Push a raw event into the event stream buffer (for testing/debugging) */
2726
2862
  __pushEventStreamEvent: (event: {
2727
2863
  type: string;
@@ -2733,6 +2869,17 @@ type Controller = {
2733
2869
  hideEventStream: () => void;
2734
2870
  /** Returns current visibility state of the event stream panel */
2735
2871
  isEventStreamVisible: () => boolean;
2872
+ /**
2873
+ * Focus the chat input. Returns true if focus succeeded, false if panel is closed
2874
+ * (launcher mode) or textarea is unavailable.
2875
+ */
2876
+ focusInput: () => boolean;
2877
+ /**
2878
+ * Programmatically resolve a pending approval.
2879
+ * @param approvalId - The approval ID to resolve
2880
+ * @param decision - "approved" or "denied"
2881
+ */
2882
+ resolveApproval: (approvalId: string, decision: 'approved' | 'denied') => Promise<void>;
2736
2883
  };
2737
2884
  declare const createAgentExperience: (mount: HTMLElement, initialConfig?: AgentWidgetConfig, runtimeOptions?: {
2738
2885
  debugTools?: boolean;
@@ -3493,4 +3640,4 @@ declare const getHeaderLayout: (layoutName: string) => HeaderLayoutRenderer;
3493
3640
  */
3494
3641
  declare const buildHeaderWithLayout: (config: AgentWidgetConfig, layoutConfig?: AgentWidgetHeaderLayoutConfig, context?: Partial<HeaderLayoutContext>) => HeaderElements;
3495
3642
 
3496
- export { type AgentConfig, type AgentExecutionState, type AgentLoopConfig, type AgentMessageMetadata, type AgentRequestOptions, type AgentWidgetAgentRequestPayload, type AgentWidgetAttachmentsConfig, type AgentWidgetAvatarConfig, AgentWidgetClient, type AgentWidgetConfig, type AgentWidgetController, type AgentWidgetControllerEventMap, type AgentWidgetCustomFetch, type AgentWidgetEvent, type AgentWidgetFeatureFlags, type AgentWidgetHeaderLayoutConfig, type AgentWidgetHeadersFunction, type AgentWidgetInitHandle, type AgentWidgetInitOptions, type AgentWidgetLauncherConfig, type AgentWidgetLayoutConfig, type AgentWidgetLoadingIndicatorConfig, type AgentWidgetMarkdownConfig, type AgentWidgetMarkdownOptions, type AgentWidgetMarkdownRendererOverrides, type AgentWidgetMessage, type AgentWidgetMessageActionsConfig, type AgentWidgetMessageFeedback, type AgentWidgetMessageLayoutConfig, type AgentWidgetPlugin, type AgentWidgetRequestPayload, type AgentWidgetSSEEventParser, type AgentWidgetSSEEventResult, AgentWidgetSession, type AgentWidgetSessionStatus, type AgentWidgetStreamParser, type AgentWidgetStreamParserResult, type AgentWidgetTheme, type AgentWidgetTimestampConfig, AttachmentManager, type AttachmentManagerConfig, type CSATFeedbackOptions, type ClientChatRequest, type ClientFeedbackRequest, type ClientFeedbackType, type ClientInitResponse, type ClientSession, type CodeFormat, type CodeGeneratorHooks, type CodeGeneratorOptions, type ComponentContext, type ComponentDirective, type ComponentRenderer, type ComposerBuildContext, type ComposerElements, type ContentPart, type CreateStandardBubbleOptions, DEFAULT_DARK_THEME, DEFAULT_LIGHT_THEME, DEFAULT_WIDGET_CONFIG, type EventStreamBadgeColor, type EventStreamConfig, type EventStreamPayloadRenderContext, type EventStreamRowRenderContext, type EventStreamToolbarRenderContext, type EventStreamViewRenderContext, type HeaderBuildContext, type HeaderElements, type HeaderLayoutContext, type HeaderLayoutRenderer, type HeaderRenderContext, type IdleIndicatorRenderContext, type ImageContentPart, type InjectAssistantMessageOptions, type InjectMessageOptions, type InjectSystemMessageOptions, type InjectUserMessageOptions, type LoadingIndicatorRenderContext, type LoadingIndicatorRenderer, type MarkdownProcessorOptions, type MessageActionCallbacks, type MessageContent, type MessageRenderContext, type MessageTransform, type NPSFeedbackOptions, type PendingAttachment, type SSEEventCallback, type SSEEventRecord, type SlotRenderContext, type SlotRenderer, type TextContentPart, VERSION, type WidgetLayoutSlot, attachHeaderToContainer, buildComposer, buildDefaultHeader, buildExpandedHeader, buildHeader, buildHeaderWithLayout, buildMinimalHeader, componentRegistry, createActionManager, createAgentExperience, createBubbleWithLayout, createCSATFeedback, createComponentMiddleware, createComponentStreamParser, createDirectivePostprocessor, createFlexibleJsonStreamParser, createImagePart, createJsonStreamParser, createLocalStorageAdapter, createMarkdownProcessor, createMarkdownProcessorFromConfig, createMessageActions, createNPSFeedback, createPlainTextParser, createRegexJsonParser, createStandardBubble, createTextPart, createTypingIndicator, createXmlParser, initAgentWidget as default, defaultActionHandlers, defaultJsonActionParser, directivePostprocessor, escapeHtml, extractComponentDirectiveFromMessage, fileToImagePart, generateAssistantMessageId, generateCodeSnippet, generateMessageId, generateUserMessageId, getDisplayText, getHeaderLayout, getImageParts, hasComponentDirective, hasImages, headerLayouts, initAgentWidget, isComponentDirectiveType, markdownPostprocessor, mergeWithDefaults, normalizeContent, pluginRegistry, renderComponentDirective, renderLoadingIndicatorWithFallback, validateImageFile };
3643
+ export { type AgentConfig, type AgentExecutionState, type AgentLoopConfig, type AgentMessageMetadata, type AgentRequestOptions, type AgentWidgetAgentRequestPayload, type AgentWidgetApproval, type AgentWidgetApprovalConfig, type AgentWidgetAttachmentsConfig, type AgentWidgetAvatarConfig, AgentWidgetClient, type AgentWidgetConfig, type AgentWidgetController, type AgentWidgetControllerEventMap, type AgentWidgetCustomFetch, type AgentWidgetEvent, type AgentWidgetFeatureFlags, type AgentWidgetHeaderLayoutConfig, type AgentWidgetHeadersFunction, type AgentWidgetInitHandle, type AgentWidgetInitOptions, type AgentWidgetLauncherConfig, type AgentWidgetLayoutConfig, type AgentWidgetLoadingIndicatorConfig, type AgentWidgetMarkdownConfig, type AgentWidgetMarkdownOptions, type AgentWidgetMarkdownRendererOverrides, type AgentWidgetMessage, type AgentWidgetMessageActionsConfig, type AgentWidgetMessageFeedback, type AgentWidgetMessageLayoutConfig, type AgentWidgetPlugin, type AgentWidgetRequestPayload, type AgentWidgetSSEEventParser, type AgentWidgetSSEEventResult, AgentWidgetSession, type AgentWidgetSessionStatus, type AgentWidgetStreamParser, type AgentWidgetStreamParserResult, type AgentWidgetTheme, type AgentWidgetTimestampConfig, AttachmentManager, type AttachmentManagerConfig, type CSATFeedbackOptions, type ClientChatRequest, type ClientFeedbackRequest, type ClientFeedbackType, type ClientInitResponse, type ClientSession, type CodeFormat, type CodeGeneratorHooks, type CodeGeneratorOptions, type ComponentContext, type ComponentDirective, type ComponentRenderer, type ComposerBuildContext, type ComposerElements, type ContentPart, type CreateStandardBubbleOptions, DEFAULT_DARK_THEME, DEFAULT_LIGHT_THEME, DEFAULT_WIDGET_CONFIG, type EventStreamBadgeColor, type EventStreamConfig, type EventStreamPayloadRenderContext, type EventStreamRowRenderContext, type EventStreamToolbarRenderContext, type EventStreamViewRenderContext, type HeaderBuildContext, type HeaderElements, type HeaderLayoutContext, type HeaderLayoutRenderer, type HeaderRenderContext, type IdleIndicatorRenderContext, type ImageContentPart, type InjectAssistantMessageOptions, type InjectMessageOptions, type InjectSystemMessageOptions, type InjectUserMessageOptions, type LoadingIndicatorRenderContext, type LoadingIndicatorRenderer, type MarkdownProcessorOptions, type MessageActionCallbacks, type MessageContent, type MessageRenderContext, type MessageTransform, type NPSFeedbackOptions, type PendingAttachment, type SSEEventCallback, type SSEEventRecord, type SlotRenderContext, type SlotRenderer, type TextContentPart, VERSION, type WidgetLayoutSlot, attachHeaderToContainer, buildComposer, buildDefaultHeader, buildExpandedHeader, buildHeader, buildHeaderWithLayout, buildMinimalHeader, componentRegistry, createActionManager, createAgentExperience, createBubbleWithLayout, createCSATFeedback, createComponentMiddleware, createComponentStreamParser, createDirectivePostprocessor, createFlexibleJsonStreamParser, createImagePart, createJsonStreamParser, createLocalStorageAdapter, createMarkdownProcessor, createMarkdownProcessorFromConfig, createMessageActions, createNPSFeedback, createPlainTextParser, createRegexJsonParser, createStandardBubble, createTextPart, createTypingIndicator, createXmlParser, initAgentWidget as default, defaultActionHandlers, defaultJsonActionParser, directivePostprocessor, escapeHtml, extractComponentDirectiveFromMessage, fileToImagePart, generateAssistantMessageId, generateCodeSnippet, generateMessageId, generateUserMessageId, getDisplayText, getHeaderLayout, getImageParts, hasComponentDirective, hasImages, headerLayouts, initAgentWidget, isComponentDirectiveType, markdownPostprocessor, mergeWithDefaults, normalizeContent, pluginRegistry, renderComponentDirective, renderLoadingIndicatorWithFallback, validateImageFile };