vanilla-agent 1.21.0 → 1.22.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
@@ -135,6 +135,64 @@ type AgentWidgetActionEventPayload = {
135
135
  action: AgentWidgetParsedAction;
136
136
  message: AgentWidgetMessage;
137
137
  };
138
+ /**
139
+ * Feedback event payload for upvote/downvote actions on messages
140
+ */
141
+ type AgentWidgetMessageFeedback = {
142
+ type: "upvote" | "downvote";
143
+ messageId: string;
144
+ message: AgentWidgetMessage;
145
+ };
146
+ /**
147
+ * Configuration for message action buttons (copy, upvote, downvote)
148
+ */
149
+ type AgentWidgetMessageActionsConfig = {
150
+ /**
151
+ * Enable/disable message actions entirely
152
+ * @default true
153
+ */
154
+ enabled?: boolean;
155
+ /**
156
+ * Show copy button
157
+ * @default true
158
+ */
159
+ showCopy?: boolean;
160
+ /**
161
+ * Show upvote button
162
+ * @default false (requires backend)
163
+ */
164
+ showUpvote?: boolean;
165
+ /**
166
+ * Show downvote button
167
+ * @default false (requires backend)
168
+ */
169
+ showDownvote?: boolean;
170
+ /**
171
+ * Visibility mode: 'always' shows buttons always, 'hover' shows on hover only
172
+ * @default 'hover'
173
+ */
174
+ visibility?: "always" | "hover";
175
+ /**
176
+ * Horizontal alignment of action buttons
177
+ * @default 'right'
178
+ */
179
+ align?: "left" | "center" | "right";
180
+ /**
181
+ * Layout style for action buttons
182
+ * - 'pill-inside': Compact floating pill around just the buttons (default for hover)
183
+ * - 'row-inside': Full-width row at the bottom of the message
184
+ * @default 'pill-inside'
185
+ */
186
+ layout?: "pill-inside" | "row-inside";
187
+ /**
188
+ * Callback when user submits feedback (upvote/downvote)
189
+ */
190
+ onFeedback?: (feedback: AgentWidgetMessageFeedback) => void;
191
+ /**
192
+ * Callback when user copies a message
193
+ */
194
+ onCopy?: (message: AgentWidgetMessage) => void;
195
+ };
138
196
  type AgentWidgetStateEvent = {
139
197
  open: boolean;
140
198
  source: "user" | "auto" | "api" | "system";
@@ -154,6 +212,8 @@ type AgentWidgetControllerEventMap = {
154
212
  "widget:opened": AgentWidgetStateEvent;
155
213
  "widget:closed": AgentWidgetStateEvent;
156
214
  "widget:state": AgentWidgetStateSnapshot;
215
+ "message:feedback": AgentWidgetMessageFeedback;
216
+ "message:copy": AgentWidgetMessage;
157
217
  };
158
218
  type AgentWidgetFeatureFlags = {
159
219
  showReasoning?: boolean;
@@ -464,6 +524,55 @@ type AgentWidgetCustomFetch = (url: string, init: RequestInit, payload: AgentWid
464
524
  * Dynamic headers function - called before each request
465
525
  */
466
526
  type AgentWidgetHeadersFunction = () => Record<string, string> | Promise<Record<string, string>>;
527
+ /**
528
+ * Session information returned after client token initialization.
529
+ * Contains session ID, expiry time, flow info, and config from the server.
530
+ */
531
+ type ClientSession = {
532
+ /** Unique session identifier */
533
+ sessionId: string;
534
+ /** When the session expires */
535
+ expiresAt: Date;
536
+ /** Flow information */
537
+ flow: {
538
+ id: string;
539
+ name: string;
540
+ description: string | null;
541
+ };
542
+ /** Configuration from the server */
543
+ config: {
544
+ welcomeMessage: string | null;
545
+ placeholder: string;
546
+ theme: Record<string, unknown> | null;
547
+ };
548
+ };
549
+ /**
550
+ * Raw API response from /v1/client/init endpoint
551
+ */
552
+ type ClientInitResponse = {
553
+ session_id: string;
554
+ expires_at: string;
555
+ flow: {
556
+ id: string;
557
+ name: string;
558
+ description: string | null;
559
+ };
560
+ config: {
561
+ welcome_message: string | null;
562
+ placeholder: string;
563
+ theme: Record<string, unknown> | null;
564
+ };
565
+ };
566
+ /**
567
+ * Request payload for /v1/client/chat endpoint
568
+ */
569
+ type ClientChatRequest = {
570
+ session_id: string;
571
+ messages: Array<{
572
+ role: 'user' | 'assistant' | 'system';
573
+ content: string;
574
+ }>;
575
+ };
467
576
  /**
468
577
  * Context provided to header render functions
469
578
  */
@@ -877,6 +986,47 @@ type AgentWidgetMarkdownConfig = {
877
986
  type AgentWidgetConfig = {
878
987
  apiUrl?: string;
879
988
  flowId?: string;
989
+ /**
990
+ * Client token for direct browser-to-API communication.
991
+ * When set, the widget uses /v1/client/* endpoints instead of /v1/dispatch.
992
+ * Mutually exclusive with apiKey/headers authentication.
993
+ *
994
+ * @example
995
+ * ```typescript
996
+ * config: {
997
+ * clientToken: 'ct_live_flow01k7_a8b9c0d1e2f3g4h5i6j7k8l9'
998
+ * }
999
+ * ```
1000
+ */
1001
+ clientToken?: string;
1002
+ /**
1003
+ * Callback when session is initialized (client token mode only).
1004
+ * Receives session info including expiry time.
1005
+ *
1006
+ * @example
1007
+ * ```typescript
1008
+ * config: {
1009
+ * onSessionInit: (session) => {
1010
+ * console.log('Session started:', session.sessionId);
1011
+ * }
1012
+ * }
1013
+ * ```
1014
+ */
1015
+ onSessionInit?: (session: ClientSession) => void;
1016
+ /**
1017
+ * Callback when session expires or errors (client token mode only).
1018
+ * Widget should prompt user to refresh.
1019
+ *
1020
+ * @example
1021
+ * ```typescript
1022
+ * config: {
1023
+ * onSessionExpired: () => {
1024
+ * alert('Your session has expired. Please refresh the page.');
1025
+ * }
1026
+ * }
1027
+ * ```
1028
+ */
1029
+ onSessionExpired?: () => void;
880
1030
  /**
881
1031
  * Static headers to include with each request.
882
1032
  * For dynamic headers (e.g., auth tokens), use `getHeaders` instead.
@@ -1108,6 +1258,30 @@ type AgentWidgetConfig = {
1108
1258
  * ```
1109
1259
  */
1110
1260
  markdown?: AgentWidgetMarkdownConfig;
1261
+ /**
1262
+ * Configuration for message action buttons (copy, upvote, downvote).
1263
+ * Shows action buttons on assistant messages for user feedback.
1264
+ *
1265
+ * @example
1266
+ * ```typescript
1267
+ * config: {
1268
+ * messageActions: {
1269
+ * enabled: true,
1270
+ * showCopy: true,
1271
+ * showUpvote: true,
1272
+ * showDownvote: true,
1273
+ * visibility: 'hover',
1274
+ * onFeedback: (feedback) => {
1275
+ * console.log('Feedback:', feedback.type, feedback.messageId);
1276
+ * },
1277
+ * onCopy: (message) => {
1278
+ * console.log('Copied message:', message.id);
1279
+ * }
1280
+ * }
1281
+ * }
1282
+ * ```
1283
+ */
1284
+ messageActions?: AgentWidgetMessageActionsConfig;
1111
1285
  };
1112
1286
  type AgentWidgetMessageRole = "user" | "assistant" | "system";
1113
1287
  type AgentWidgetReasoning = {
@@ -1200,7 +1374,34 @@ declare class AgentWidgetSession {
1200
1374
  private streaming;
1201
1375
  private abortController;
1202
1376
  private sequenceCounter;
1377
+ private clientSession;
1203
1378
  constructor(config: AgentWidgetConfig | undefined, callbacks: SessionCallbacks);
1379
+ /**
1380
+ * Check if running in client token mode
1381
+ */
1382
+ isClientTokenMode(): boolean;
1383
+ /**
1384
+ * Initialize the client session (for client token mode).
1385
+ * This is called automatically on first message, but can be called
1386
+ * explicitly to pre-initialize the session and get config from server.
1387
+ */
1388
+ initClientSession(): Promise<ClientSession | null>;
1389
+ /**
1390
+ * Set the client session after initialization
1391
+ */
1392
+ setClientSession(session: ClientSession): void;
1393
+ /**
1394
+ * Get current client session
1395
+ */
1396
+ getClientSession(): ClientSession | null;
1397
+ /**
1398
+ * Check if session is valid and not expired
1399
+ */
1400
+ isSessionValid(): boolean;
1401
+ /**
1402
+ * Clear session (on expiry or error)
1403
+ */
1404
+ clearClientSession(): void;
1204
1405
  updateConfig(next: AgentWidgetConfig): void;
1205
1406
  getMessages(): AgentWidgetMessage[];
1206
1407
  getStatus(): AgentWidgetSessionStatus;
@@ -1270,8 +1471,43 @@ declare class AgentWidgetClient {
1270
1471
  private readonly customFetch?;
1271
1472
  private readonly parseSSEEvent?;
1272
1473
  private readonly getHeaders?;
1474
+ private clientSession;
1475
+ private sessionInitPromise;
1273
1476
  constructor(config?: AgentWidgetConfig);
1477
+ /**
1478
+ * Check if running in client token mode
1479
+ */
1480
+ isClientTokenMode(): boolean;
1481
+ /**
1482
+ * Get the appropriate API URL based on mode
1483
+ */
1484
+ private getClientApiUrl;
1485
+ /**
1486
+ * Get the current client session (if any)
1487
+ */
1488
+ getClientSession(): ClientSession | null;
1489
+ /**
1490
+ * Initialize session for client token mode.
1491
+ * Called automatically on first message if not already initialized.
1492
+ */
1493
+ initSession(): Promise<ClientSession>;
1494
+ private _doInitSession;
1495
+ /**
1496
+ * Clear the current client session
1497
+ */
1498
+ clearClientSession(): void;
1499
+ /**
1500
+ * Send a message - handles both proxy and client token modes
1501
+ */
1274
1502
  dispatch(options: DispatchOptions, onEvent: SSEHandler): Promise<void>;
1503
+ /**
1504
+ * Client token mode dispatch
1505
+ */
1506
+ private dispatchClientToken;
1507
+ /**
1508
+ * Proxy mode dispatch (original implementation)
1509
+ */
1510
+ private dispatchProxy;
1275
1511
  private buildPayload;
1276
1512
  /**
1277
1513
  * Handle custom SSE event parsing via parseSSEEvent callback
@@ -1537,17 +1773,25 @@ type MessageTransform = (context: {
1537
1773
  streaming: boolean;
1538
1774
  raw?: string;
1539
1775
  }) => string;
1776
+ type MessageActionCallbacks = {
1777
+ onCopy?: (message: AgentWidgetMessage) => void;
1778
+ onFeedback?: (feedback: AgentWidgetMessageFeedback) => void;
1779
+ };
1540
1780
  declare const createTypingIndicator: () => HTMLElement;
1781
+ /**
1782
+ * Create message action buttons (copy, upvote, downvote)
1783
+ */
1784
+ declare const createMessageActions: (message: AgentWidgetMessage, actionsConfig: AgentWidgetMessageActionsConfig, callbacks?: MessageActionCallbacks) => HTMLElement;
1541
1785
  /**
1542
1786
  * Create standard message bubble
1543
1787
  * Supports layout configuration for avatars, timestamps, and visual presets
1544
1788
  */
1545
- declare const createStandardBubble: (message: AgentWidgetMessage, transform: MessageTransform, layoutConfig?: AgentWidgetMessageLayoutConfig) => HTMLElement;
1789
+ declare const createStandardBubble: (message: AgentWidgetMessage, transform: MessageTransform, layoutConfig?: AgentWidgetMessageLayoutConfig, actionsConfig?: AgentWidgetMessageActionsConfig, actionCallbacks?: MessageActionCallbacks) => HTMLElement;
1546
1790
  /**
1547
1791
  * Create bubble with custom renderer support
1548
1792
  * Uses custom renderer if provided in layout config, otherwise falls back to standard bubble
1549
1793
  */
1550
- declare const createBubbleWithLayout: (message: AgentWidgetMessage, transform: MessageTransform, layoutConfig?: AgentWidgetMessageLayoutConfig) => HTMLElement;
1794
+ declare const createBubbleWithLayout: (message: AgentWidgetMessage, transform: MessageTransform, layoutConfig?: AgentWidgetMessageLayoutConfig, actionsConfig?: AgentWidgetMessageActionsConfig, actionCallbacks?: MessageActionCallbacks) => HTMLElement;
1551
1795
 
1552
1796
  /**
1553
1797
  * Options for component middleware
@@ -1684,4 +1928,4 @@ declare const getHeaderLayout: (layoutName: string) => HeaderLayoutRenderer;
1684
1928
  */
1685
1929
  declare const buildHeaderWithLayout: (config: AgentWidgetConfig, layoutConfig?: AgentWidgetHeaderLayoutConfig, context?: Partial<HeaderLayoutContext>) => HeaderElements;
1686
1930
 
1687
- export { type AgentWidgetAvatarConfig, AgentWidgetClient, type AgentWidgetConfig, type AgentWidgetController, type AgentWidgetCustomFetch, type AgentWidgetEvent, type AgentWidgetFeatureFlags, type AgentWidgetHeaderLayoutConfig, type AgentWidgetHeadersFunction, type AgentWidgetInitHandle, type AgentWidgetInitOptions, type AgentWidgetLauncherConfig, type AgentWidgetLayoutConfig, type AgentWidgetMarkdownConfig, type AgentWidgetMarkdownOptions, type AgentWidgetMarkdownRendererOverrides, type AgentWidgetMessage, type AgentWidgetMessageLayoutConfig, type AgentWidgetPlugin, type AgentWidgetRequestPayload, type AgentWidgetSSEEventParser, type AgentWidgetSSEEventResult, AgentWidgetSession, type AgentWidgetSessionStatus, type AgentWidgetStreamParser, type AgentWidgetStreamParserResult, type AgentWidgetTheme, type AgentWidgetTimestampConfig, type CodeFormat, type ComponentContext, type ComponentDirective, type ComponentRenderer, type ComposerBuildContext, type ComposerElements, DEFAULT_WIDGET_CONFIG, type HeaderBuildContext, type HeaderElements, type HeaderLayoutContext, type HeaderLayoutRenderer, type HeaderRenderContext, type MarkdownProcessorOptions, type MessageRenderContext, type MessageTransform, type SlotRenderContext, type SlotRenderer, type WidgetLayoutSlot, attachHeaderToContainer, buildComposer, buildDefaultHeader, buildExpandedHeader, buildHeader, buildHeaderWithLayout, buildMinimalHeader, componentRegistry, createActionManager, createAgentExperience, createBubbleWithLayout, createComponentMiddleware, createComponentStreamParser, createDirectivePostprocessor, createFlexibleJsonStreamParser, createJsonStreamParser, createLocalStorageAdapter, createMarkdownProcessor, createMarkdownProcessorFromConfig, createPlainTextParser, createRegexJsonParser, createStandardBubble, createTypingIndicator, createXmlParser, initAgentWidget as default, defaultActionHandlers, defaultJsonActionParser, directivePostprocessor, escapeHtml, extractComponentDirectiveFromMessage, generateCodeSnippet, getHeaderLayout, hasComponentDirective, headerLayouts, initAgentWidget, isComponentDirectiveType, markdownPostprocessor, mergeWithDefaults, pluginRegistry, renderComponentDirective };
1931
+ export { type AgentWidgetAvatarConfig, AgentWidgetClient, type AgentWidgetConfig, type AgentWidgetController, type AgentWidgetCustomFetch, type AgentWidgetEvent, type AgentWidgetFeatureFlags, type AgentWidgetHeaderLayoutConfig, type AgentWidgetHeadersFunction, type AgentWidgetInitHandle, type AgentWidgetInitOptions, type AgentWidgetLauncherConfig, type AgentWidgetLayoutConfig, 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, type ClientChatRequest, type ClientInitResponse, type ClientSession, type CodeFormat, type ComponentContext, type ComponentDirective, type ComponentRenderer, type ComposerBuildContext, type ComposerElements, DEFAULT_WIDGET_CONFIG, type HeaderBuildContext, type HeaderElements, type HeaderLayoutContext, type HeaderLayoutRenderer, type HeaderRenderContext, type MarkdownProcessorOptions, type MessageActionCallbacks, type MessageRenderContext, type MessageTransform, type SlotRenderContext, type SlotRenderer, type WidgetLayoutSlot, attachHeaderToContainer, buildComposer, buildDefaultHeader, buildExpandedHeader, buildHeader, buildHeaderWithLayout, buildMinimalHeader, componentRegistry, createActionManager, createAgentExperience, createBubbleWithLayout, createComponentMiddleware, createComponentStreamParser, createDirectivePostprocessor, createFlexibleJsonStreamParser, createJsonStreamParser, createLocalStorageAdapter, createMarkdownProcessor, createMarkdownProcessorFromConfig, createMessageActions, createPlainTextParser, createRegexJsonParser, createStandardBubble, createTypingIndicator, createXmlParser, initAgentWidget as default, defaultActionHandlers, defaultJsonActionParser, directivePostprocessor, escapeHtml, extractComponentDirectiveFromMessage, generateCodeSnippet, getHeaderLayout, hasComponentDirective, headerLayouts, initAgentWidget, isComponentDirectiveType, markdownPostprocessor, mergeWithDefaults, pluginRegistry, renderComponentDirective };
package/dist/index.d.ts CHANGED
@@ -135,6 +135,64 @@ type AgentWidgetActionEventPayload = {
135
135
  action: AgentWidgetParsedAction;
136
136
  message: AgentWidgetMessage;
137
137
  };
138
+ /**
139
+ * Feedback event payload for upvote/downvote actions on messages
140
+ */
141
+ type AgentWidgetMessageFeedback = {
142
+ type: "upvote" | "downvote";
143
+ messageId: string;
144
+ message: AgentWidgetMessage;
145
+ };
146
+ /**
147
+ * Configuration for message action buttons (copy, upvote, downvote)
148
+ */
149
+ type AgentWidgetMessageActionsConfig = {
150
+ /**
151
+ * Enable/disable message actions entirely
152
+ * @default true
153
+ */
154
+ enabled?: boolean;
155
+ /**
156
+ * Show copy button
157
+ * @default true
158
+ */
159
+ showCopy?: boolean;
160
+ /**
161
+ * Show upvote button
162
+ * @default false (requires backend)
163
+ */
164
+ showUpvote?: boolean;
165
+ /**
166
+ * Show downvote button
167
+ * @default false (requires backend)
168
+ */
169
+ showDownvote?: boolean;
170
+ /**
171
+ * Visibility mode: 'always' shows buttons always, 'hover' shows on hover only
172
+ * @default 'hover'
173
+ */
174
+ visibility?: "always" | "hover";
175
+ /**
176
+ * Horizontal alignment of action buttons
177
+ * @default 'right'
178
+ */
179
+ align?: "left" | "center" | "right";
180
+ /**
181
+ * Layout style for action buttons
182
+ * - 'pill-inside': Compact floating pill around just the buttons (default for hover)
183
+ * - 'row-inside': Full-width row at the bottom of the message
184
+ * @default 'pill-inside'
185
+ */
186
+ layout?: "pill-inside" | "row-inside";
187
+ /**
188
+ * Callback when user submits feedback (upvote/downvote)
189
+ */
190
+ onFeedback?: (feedback: AgentWidgetMessageFeedback) => void;
191
+ /**
192
+ * Callback when user copies a message
193
+ */
194
+ onCopy?: (message: AgentWidgetMessage) => void;
195
+ };
138
196
  type AgentWidgetStateEvent = {
139
197
  open: boolean;
140
198
  source: "user" | "auto" | "api" | "system";
@@ -154,6 +212,8 @@ type AgentWidgetControllerEventMap = {
154
212
  "widget:opened": AgentWidgetStateEvent;
155
213
  "widget:closed": AgentWidgetStateEvent;
156
214
  "widget:state": AgentWidgetStateSnapshot;
215
+ "message:feedback": AgentWidgetMessageFeedback;
216
+ "message:copy": AgentWidgetMessage;
157
217
  };
158
218
  type AgentWidgetFeatureFlags = {
159
219
  showReasoning?: boolean;
@@ -464,6 +524,55 @@ type AgentWidgetCustomFetch = (url: string, init: RequestInit, payload: AgentWid
464
524
  * Dynamic headers function - called before each request
465
525
  */
466
526
  type AgentWidgetHeadersFunction = () => Record<string, string> | Promise<Record<string, string>>;
527
+ /**
528
+ * Session information returned after client token initialization.
529
+ * Contains session ID, expiry time, flow info, and config from the server.
530
+ */
531
+ type ClientSession = {
532
+ /** Unique session identifier */
533
+ sessionId: string;
534
+ /** When the session expires */
535
+ expiresAt: Date;
536
+ /** Flow information */
537
+ flow: {
538
+ id: string;
539
+ name: string;
540
+ description: string | null;
541
+ };
542
+ /** Configuration from the server */
543
+ config: {
544
+ welcomeMessage: string | null;
545
+ placeholder: string;
546
+ theme: Record<string, unknown> | null;
547
+ };
548
+ };
549
+ /**
550
+ * Raw API response from /v1/client/init endpoint
551
+ */
552
+ type ClientInitResponse = {
553
+ session_id: string;
554
+ expires_at: string;
555
+ flow: {
556
+ id: string;
557
+ name: string;
558
+ description: string | null;
559
+ };
560
+ config: {
561
+ welcome_message: string | null;
562
+ placeholder: string;
563
+ theme: Record<string, unknown> | null;
564
+ };
565
+ };
566
+ /**
567
+ * Request payload for /v1/client/chat endpoint
568
+ */
569
+ type ClientChatRequest = {
570
+ session_id: string;
571
+ messages: Array<{
572
+ role: 'user' | 'assistant' | 'system';
573
+ content: string;
574
+ }>;
575
+ };
467
576
  /**
468
577
  * Context provided to header render functions
469
578
  */
@@ -877,6 +986,47 @@ type AgentWidgetMarkdownConfig = {
877
986
  type AgentWidgetConfig = {
878
987
  apiUrl?: string;
879
988
  flowId?: string;
989
+ /**
990
+ * Client token for direct browser-to-API communication.
991
+ * When set, the widget uses /v1/client/* endpoints instead of /v1/dispatch.
992
+ * Mutually exclusive with apiKey/headers authentication.
993
+ *
994
+ * @example
995
+ * ```typescript
996
+ * config: {
997
+ * clientToken: 'ct_live_flow01k7_a8b9c0d1e2f3g4h5i6j7k8l9'
998
+ * }
999
+ * ```
1000
+ */
1001
+ clientToken?: string;
1002
+ /**
1003
+ * Callback when session is initialized (client token mode only).
1004
+ * Receives session info including expiry time.
1005
+ *
1006
+ * @example
1007
+ * ```typescript
1008
+ * config: {
1009
+ * onSessionInit: (session) => {
1010
+ * console.log('Session started:', session.sessionId);
1011
+ * }
1012
+ * }
1013
+ * ```
1014
+ */
1015
+ onSessionInit?: (session: ClientSession) => void;
1016
+ /**
1017
+ * Callback when session expires or errors (client token mode only).
1018
+ * Widget should prompt user to refresh.
1019
+ *
1020
+ * @example
1021
+ * ```typescript
1022
+ * config: {
1023
+ * onSessionExpired: () => {
1024
+ * alert('Your session has expired. Please refresh the page.');
1025
+ * }
1026
+ * }
1027
+ * ```
1028
+ */
1029
+ onSessionExpired?: () => void;
880
1030
  /**
881
1031
  * Static headers to include with each request.
882
1032
  * For dynamic headers (e.g., auth tokens), use `getHeaders` instead.
@@ -1108,6 +1258,30 @@ type AgentWidgetConfig = {
1108
1258
  * ```
1109
1259
  */
1110
1260
  markdown?: AgentWidgetMarkdownConfig;
1261
+ /**
1262
+ * Configuration for message action buttons (copy, upvote, downvote).
1263
+ * Shows action buttons on assistant messages for user feedback.
1264
+ *
1265
+ * @example
1266
+ * ```typescript
1267
+ * config: {
1268
+ * messageActions: {
1269
+ * enabled: true,
1270
+ * showCopy: true,
1271
+ * showUpvote: true,
1272
+ * showDownvote: true,
1273
+ * visibility: 'hover',
1274
+ * onFeedback: (feedback) => {
1275
+ * console.log('Feedback:', feedback.type, feedback.messageId);
1276
+ * },
1277
+ * onCopy: (message) => {
1278
+ * console.log('Copied message:', message.id);
1279
+ * }
1280
+ * }
1281
+ * }
1282
+ * ```
1283
+ */
1284
+ messageActions?: AgentWidgetMessageActionsConfig;
1111
1285
  };
1112
1286
  type AgentWidgetMessageRole = "user" | "assistant" | "system";
1113
1287
  type AgentWidgetReasoning = {
@@ -1200,7 +1374,34 @@ declare class AgentWidgetSession {
1200
1374
  private streaming;
1201
1375
  private abortController;
1202
1376
  private sequenceCounter;
1377
+ private clientSession;
1203
1378
  constructor(config: AgentWidgetConfig | undefined, callbacks: SessionCallbacks);
1379
+ /**
1380
+ * Check if running in client token mode
1381
+ */
1382
+ isClientTokenMode(): boolean;
1383
+ /**
1384
+ * Initialize the client session (for client token mode).
1385
+ * This is called automatically on first message, but can be called
1386
+ * explicitly to pre-initialize the session and get config from server.
1387
+ */
1388
+ initClientSession(): Promise<ClientSession | null>;
1389
+ /**
1390
+ * Set the client session after initialization
1391
+ */
1392
+ setClientSession(session: ClientSession): void;
1393
+ /**
1394
+ * Get current client session
1395
+ */
1396
+ getClientSession(): ClientSession | null;
1397
+ /**
1398
+ * Check if session is valid and not expired
1399
+ */
1400
+ isSessionValid(): boolean;
1401
+ /**
1402
+ * Clear session (on expiry or error)
1403
+ */
1404
+ clearClientSession(): void;
1204
1405
  updateConfig(next: AgentWidgetConfig): void;
1205
1406
  getMessages(): AgentWidgetMessage[];
1206
1407
  getStatus(): AgentWidgetSessionStatus;
@@ -1270,8 +1471,43 @@ declare class AgentWidgetClient {
1270
1471
  private readonly customFetch?;
1271
1472
  private readonly parseSSEEvent?;
1272
1473
  private readonly getHeaders?;
1474
+ private clientSession;
1475
+ private sessionInitPromise;
1273
1476
  constructor(config?: AgentWidgetConfig);
1477
+ /**
1478
+ * Check if running in client token mode
1479
+ */
1480
+ isClientTokenMode(): boolean;
1481
+ /**
1482
+ * Get the appropriate API URL based on mode
1483
+ */
1484
+ private getClientApiUrl;
1485
+ /**
1486
+ * Get the current client session (if any)
1487
+ */
1488
+ getClientSession(): ClientSession | null;
1489
+ /**
1490
+ * Initialize session for client token mode.
1491
+ * Called automatically on first message if not already initialized.
1492
+ */
1493
+ initSession(): Promise<ClientSession>;
1494
+ private _doInitSession;
1495
+ /**
1496
+ * Clear the current client session
1497
+ */
1498
+ clearClientSession(): void;
1499
+ /**
1500
+ * Send a message - handles both proxy and client token modes
1501
+ */
1274
1502
  dispatch(options: DispatchOptions, onEvent: SSEHandler): Promise<void>;
1503
+ /**
1504
+ * Client token mode dispatch
1505
+ */
1506
+ private dispatchClientToken;
1507
+ /**
1508
+ * Proxy mode dispatch (original implementation)
1509
+ */
1510
+ private dispatchProxy;
1275
1511
  private buildPayload;
1276
1512
  /**
1277
1513
  * Handle custom SSE event parsing via parseSSEEvent callback
@@ -1537,17 +1773,25 @@ type MessageTransform = (context: {
1537
1773
  streaming: boolean;
1538
1774
  raw?: string;
1539
1775
  }) => string;
1776
+ type MessageActionCallbacks = {
1777
+ onCopy?: (message: AgentWidgetMessage) => void;
1778
+ onFeedback?: (feedback: AgentWidgetMessageFeedback) => void;
1779
+ };
1540
1780
  declare const createTypingIndicator: () => HTMLElement;
1781
+ /**
1782
+ * Create message action buttons (copy, upvote, downvote)
1783
+ */
1784
+ declare const createMessageActions: (message: AgentWidgetMessage, actionsConfig: AgentWidgetMessageActionsConfig, callbacks?: MessageActionCallbacks) => HTMLElement;
1541
1785
  /**
1542
1786
  * Create standard message bubble
1543
1787
  * Supports layout configuration for avatars, timestamps, and visual presets
1544
1788
  */
1545
- declare const createStandardBubble: (message: AgentWidgetMessage, transform: MessageTransform, layoutConfig?: AgentWidgetMessageLayoutConfig) => HTMLElement;
1789
+ declare const createStandardBubble: (message: AgentWidgetMessage, transform: MessageTransform, layoutConfig?: AgentWidgetMessageLayoutConfig, actionsConfig?: AgentWidgetMessageActionsConfig, actionCallbacks?: MessageActionCallbacks) => HTMLElement;
1546
1790
  /**
1547
1791
  * Create bubble with custom renderer support
1548
1792
  * Uses custom renderer if provided in layout config, otherwise falls back to standard bubble
1549
1793
  */
1550
- declare const createBubbleWithLayout: (message: AgentWidgetMessage, transform: MessageTransform, layoutConfig?: AgentWidgetMessageLayoutConfig) => HTMLElement;
1794
+ declare const createBubbleWithLayout: (message: AgentWidgetMessage, transform: MessageTransform, layoutConfig?: AgentWidgetMessageLayoutConfig, actionsConfig?: AgentWidgetMessageActionsConfig, actionCallbacks?: MessageActionCallbacks) => HTMLElement;
1551
1795
 
1552
1796
  /**
1553
1797
  * Options for component middleware
@@ -1684,4 +1928,4 @@ declare const getHeaderLayout: (layoutName: string) => HeaderLayoutRenderer;
1684
1928
  */
1685
1929
  declare const buildHeaderWithLayout: (config: AgentWidgetConfig, layoutConfig?: AgentWidgetHeaderLayoutConfig, context?: Partial<HeaderLayoutContext>) => HeaderElements;
1686
1930
 
1687
- export { type AgentWidgetAvatarConfig, AgentWidgetClient, type AgentWidgetConfig, type AgentWidgetController, type AgentWidgetCustomFetch, type AgentWidgetEvent, type AgentWidgetFeatureFlags, type AgentWidgetHeaderLayoutConfig, type AgentWidgetHeadersFunction, type AgentWidgetInitHandle, type AgentWidgetInitOptions, type AgentWidgetLauncherConfig, type AgentWidgetLayoutConfig, type AgentWidgetMarkdownConfig, type AgentWidgetMarkdownOptions, type AgentWidgetMarkdownRendererOverrides, type AgentWidgetMessage, type AgentWidgetMessageLayoutConfig, type AgentWidgetPlugin, type AgentWidgetRequestPayload, type AgentWidgetSSEEventParser, type AgentWidgetSSEEventResult, AgentWidgetSession, type AgentWidgetSessionStatus, type AgentWidgetStreamParser, type AgentWidgetStreamParserResult, type AgentWidgetTheme, type AgentWidgetTimestampConfig, type CodeFormat, type ComponentContext, type ComponentDirective, type ComponentRenderer, type ComposerBuildContext, type ComposerElements, DEFAULT_WIDGET_CONFIG, type HeaderBuildContext, type HeaderElements, type HeaderLayoutContext, type HeaderLayoutRenderer, type HeaderRenderContext, type MarkdownProcessorOptions, type MessageRenderContext, type MessageTransform, type SlotRenderContext, type SlotRenderer, type WidgetLayoutSlot, attachHeaderToContainer, buildComposer, buildDefaultHeader, buildExpandedHeader, buildHeader, buildHeaderWithLayout, buildMinimalHeader, componentRegistry, createActionManager, createAgentExperience, createBubbleWithLayout, createComponentMiddleware, createComponentStreamParser, createDirectivePostprocessor, createFlexibleJsonStreamParser, createJsonStreamParser, createLocalStorageAdapter, createMarkdownProcessor, createMarkdownProcessorFromConfig, createPlainTextParser, createRegexJsonParser, createStandardBubble, createTypingIndicator, createXmlParser, initAgentWidget as default, defaultActionHandlers, defaultJsonActionParser, directivePostprocessor, escapeHtml, extractComponentDirectiveFromMessage, generateCodeSnippet, getHeaderLayout, hasComponentDirective, headerLayouts, initAgentWidget, isComponentDirectiveType, markdownPostprocessor, mergeWithDefaults, pluginRegistry, renderComponentDirective };
1931
+ export { type AgentWidgetAvatarConfig, AgentWidgetClient, type AgentWidgetConfig, type AgentWidgetController, type AgentWidgetCustomFetch, type AgentWidgetEvent, type AgentWidgetFeatureFlags, type AgentWidgetHeaderLayoutConfig, type AgentWidgetHeadersFunction, type AgentWidgetInitHandle, type AgentWidgetInitOptions, type AgentWidgetLauncherConfig, type AgentWidgetLayoutConfig, 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, type ClientChatRequest, type ClientInitResponse, type ClientSession, type CodeFormat, type ComponentContext, type ComponentDirective, type ComponentRenderer, type ComposerBuildContext, type ComposerElements, DEFAULT_WIDGET_CONFIG, type HeaderBuildContext, type HeaderElements, type HeaderLayoutContext, type HeaderLayoutRenderer, type HeaderRenderContext, type MarkdownProcessorOptions, type MessageActionCallbacks, type MessageRenderContext, type MessageTransform, type SlotRenderContext, type SlotRenderer, type WidgetLayoutSlot, attachHeaderToContainer, buildComposer, buildDefaultHeader, buildExpandedHeader, buildHeader, buildHeaderWithLayout, buildMinimalHeader, componentRegistry, createActionManager, createAgentExperience, createBubbleWithLayout, createComponentMiddleware, createComponentStreamParser, createDirectivePostprocessor, createFlexibleJsonStreamParser, createJsonStreamParser, createLocalStorageAdapter, createMarkdownProcessor, createMarkdownProcessorFromConfig, createMessageActions, createPlainTextParser, createRegexJsonParser, createStandardBubble, createTypingIndicator, createXmlParser, initAgentWidget as default, defaultActionHandlers, defaultJsonActionParser, directivePostprocessor, escapeHtml, extractComponentDirectiveFromMessage, generateCodeSnippet, getHeaderLayout, hasComponentDirective, headerLayouts, initAgentWidget, isComponentDirectiveType, markdownPostprocessor, mergeWithDefaults, pluginRegistry, renderComponentDirective };