vanilla-agent 1.21.0 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -0
- package/dist/index.cjs +28 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +469 -30
- package/dist/index.d.ts +469 -30
- package/dist/index.global.js +60 -56
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +28 -24
- package/dist/index.js.map +1 -1
- package/dist/install.global.js +1 -1
- package/dist/install.global.js.map +1 -1
- package/dist/widget.css +409 -0
- package/package.json +2 -2
- package/src/client.ts +392 -3
- package/src/components/feedback.ts +377 -0
- package/src/components/message-bubble.ts +208 -4
- package/src/components/messages.ts +10 -3
- package/src/defaults.ts +15 -0
- package/src/index.ts +23 -3
- package/src/install.ts +69 -7
- package/src/session.ts +132 -4
- package/src/styles/widget.css +409 -0
- package/src/types.ts +209 -0
- package/src/ui.ts +121 -4
- package/src/utils/message-id.ts +35 -0
package/dist/index.d.cts
CHANGED
|
@@ -89,6 +89,7 @@ type AgentWidgetRequestPayload = {
|
|
|
89
89
|
messages: AgentWidgetRequestPayloadMessage[];
|
|
90
90
|
flowId?: string;
|
|
91
91
|
context?: Record<string, unknown>;
|
|
92
|
+
metadata?: Record<string, unknown>;
|
|
92
93
|
};
|
|
93
94
|
type AgentWidgetRequestMiddlewareContext = {
|
|
94
95
|
payload: AgentWidgetRequestPayload;
|
|
@@ -135,6 +136,64 @@ type AgentWidgetActionEventPayload = {
|
|
|
135
136
|
action: AgentWidgetParsedAction;
|
|
136
137
|
message: AgentWidgetMessage;
|
|
137
138
|
};
|
|
139
|
+
/**
|
|
140
|
+
* Feedback event payload for upvote/downvote actions on messages
|
|
141
|
+
*/
|
|
142
|
+
type AgentWidgetMessageFeedback = {
|
|
143
|
+
type: "upvote" | "downvote";
|
|
144
|
+
messageId: string;
|
|
145
|
+
message: AgentWidgetMessage;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Configuration for message action buttons (copy, upvote, downvote)
|
|
149
|
+
*/
|
|
150
|
+
type AgentWidgetMessageActionsConfig = {
|
|
151
|
+
/**
|
|
152
|
+
* Enable/disable message actions entirely
|
|
153
|
+
* @default true
|
|
154
|
+
*/
|
|
155
|
+
enabled?: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Show copy button
|
|
158
|
+
* @default true
|
|
159
|
+
*/
|
|
160
|
+
showCopy?: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Show upvote button
|
|
163
|
+
* @default false (requires backend)
|
|
164
|
+
*/
|
|
165
|
+
showUpvote?: boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Show downvote button
|
|
168
|
+
* @default false (requires backend)
|
|
169
|
+
*/
|
|
170
|
+
showDownvote?: boolean;
|
|
171
|
+
/**
|
|
172
|
+
* Visibility mode: 'always' shows buttons always, 'hover' shows on hover only
|
|
173
|
+
* @default 'hover'
|
|
174
|
+
*/
|
|
175
|
+
visibility?: "always" | "hover";
|
|
176
|
+
/**
|
|
177
|
+
* Horizontal alignment of action buttons
|
|
178
|
+
* @default 'right'
|
|
179
|
+
*/
|
|
180
|
+
align?: "left" | "center" | "right";
|
|
181
|
+
/**
|
|
182
|
+
* Layout style for action buttons
|
|
183
|
+
* - 'pill-inside': Compact floating pill around just the buttons (default for hover)
|
|
184
|
+
* - 'row-inside': Full-width row at the bottom of the message
|
|
185
|
+
* @default 'pill-inside'
|
|
186
|
+
*/
|
|
187
|
+
layout?: "pill-inside" | "row-inside";
|
|
188
|
+
/**
|
|
189
|
+
* Callback when user submits feedback (upvote/downvote)
|
|
190
|
+
*/
|
|
191
|
+
onFeedback?: (feedback: AgentWidgetMessageFeedback) => void;
|
|
192
|
+
/**
|
|
193
|
+
* Callback when user copies a message
|
|
194
|
+
*/
|
|
195
|
+
onCopy?: (message: AgentWidgetMessage) => void;
|
|
196
|
+
};
|
|
138
197
|
type AgentWidgetStateEvent = {
|
|
139
198
|
open: boolean;
|
|
140
199
|
source: "user" | "auto" | "api" | "system";
|
|
@@ -154,6 +213,8 @@ type AgentWidgetControllerEventMap = {
|
|
|
154
213
|
"widget:opened": AgentWidgetStateEvent;
|
|
155
214
|
"widget:closed": AgentWidgetStateEvent;
|
|
156
215
|
"widget:state": AgentWidgetStateSnapshot;
|
|
216
|
+
"message:feedback": AgentWidgetMessageFeedback;
|
|
217
|
+
"message:copy": AgentWidgetMessage;
|
|
157
218
|
};
|
|
158
219
|
type AgentWidgetFeatureFlags = {
|
|
159
220
|
showReasoning?: boolean;
|
|
@@ -464,6 +525,77 @@ type AgentWidgetCustomFetch = (url: string, init: RequestInit, payload: AgentWid
|
|
|
464
525
|
* Dynamic headers function - called before each request
|
|
465
526
|
*/
|
|
466
527
|
type AgentWidgetHeadersFunction = () => Record<string, string> | Promise<Record<string, string>>;
|
|
528
|
+
/**
|
|
529
|
+
* Session information returned after client token initialization.
|
|
530
|
+
* Contains session ID, expiry time, flow info, and config from the server.
|
|
531
|
+
*/
|
|
532
|
+
type ClientSession = {
|
|
533
|
+
/** Unique session identifier */
|
|
534
|
+
sessionId: string;
|
|
535
|
+
/** When the session expires */
|
|
536
|
+
expiresAt: Date;
|
|
537
|
+
/** Flow information */
|
|
538
|
+
flow: {
|
|
539
|
+
id: string;
|
|
540
|
+
name: string;
|
|
541
|
+
description: string | null;
|
|
542
|
+
};
|
|
543
|
+
/** Configuration from the server */
|
|
544
|
+
config: {
|
|
545
|
+
welcomeMessage: string | null;
|
|
546
|
+
placeholder: string;
|
|
547
|
+
theme: Record<string, unknown> | null;
|
|
548
|
+
};
|
|
549
|
+
};
|
|
550
|
+
/**
|
|
551
|
+
* Raw API response from /v1/client/init endpoint
|
|
552
|
+
*/
|
|
553
|
+
type ClientInitResponse = {
|
|
554
|
+
session_id: string;
|
|
555
|
+
expires_at: string;
|
|
556
|
+
flow: {
|
|
557
|
+
id: string;
|
|
558
|
+
name: string;
|
|
559
|
+
description: string | null;
|
|
560
|
+
};
|
|
561
|
+
config: {
|
|
562
|
+
welcome_message: string | null;
|
|
563
|
+
placeholder: string;
|
|
564
|
+
theme: Record<string, unknown> | null;
|
|
565
|
+
};
|
|
566
|
+
};
|
|
567
|
+
/**
|
|
568
|
+
* Request payload for /v1/client/chat endpoint
|
|
569
|
+
*/
|
|
570
|
+
type ClientChatRequest = {
|
|
571
|
+
session_id: string;
|
|
572
|
+
messages: Array<{
|
|
573
|
+
id?: string;
|
|
574
|
+
role: 'user' | 'assistant' | 'system';
|
|
575
|
+
content: string;
|
|
576
|
+
}>;
|
|
577
|
+
/** ID for the expected assistant response message */
|
|
578
|
+
assistant_message_id?: string;
|
|
579
|
+
metadata?: Record<string, unknown>;
|
|
580
|
+
context?: Record<string, unknown>;
|
|
581
|
+
};
|
|
582
|
+
/**
|
|
583
|
+
* Feedback types supported by the API
|
|
584
|
+
*/
|
|
585
|
+
type ClientFeedbackType = 'upvote' | 'downvote' | 'copy' | 'csat' | 'nps';
|
|
586
|
+
/**
|
|
587
|
+
* Request payload for /v1/client/feedback endpoint
|
|
588
|
+
*/
|
|
589
|
+
type ClientFeedbackRequest = {
|
|
590
|
+
session_id: string;
|
|
591
|
+
/** Required for upvote, downvote, copy feedback types */
|
|
592
|
+
message_id?: string;
|
|
593
|
+
type: ClientFeedbackType;
|
|
594
|
+
/** Required for csat (1-5) and nps (0-10) feedback types */
|
|
595
|
+
rating?: number;
|
|
596
|
+
/** Optional comment for any feedback type */
|
|
597
|
+
comment?: string;
|
|
598
|
+
};
|
|
467
599
|
/**
|
|
468
600
|
* Context provided to header render functions
|
|
469
601
|
*/
|
|
@@ -877,6 +1009,47 @@ type AgentWidgetMarkdownConfig = {
|
|
|
877
1009
|
type AgentWidgetConfig = {
|
|
878
1010
|
apiUrl?: string;
|
|
879
1011
|
flowId?: string;
|
|
1012
|
+
/**
|
|
1013
|
+
* Client token for direct browser-to-API communication.
|
|
1014
|
+
* When set, the widget uses /v1/client/* endpoints instead of /v1/dispatch.
|
|
1015
|
+
* Mutually exclusive with apiKey/headers authentication.
|
|
1016
|
+
*
|
|
1017
|
+
* @example
|
|
1018
|
+
* ```typescript
|
|
1019
|
+
* config: {
|
|
1020
|
+
* clientToken: 'ct_live_flow01k7_a8b9c0d1e2f3g4h5i6j7k8l9'
|
|
1021
|
+
* }
|
|
1022
|
+
* ```
|
|
1023
|
+
*/
|
|
1024
|
+
clientToken?: string;
|
|
1025
|
+
/**
|
|
1026
|
+
* Callback when session is initialized (client token mode only).
|
|
1027
|
+
* Receives session info including expiry time.
|
|
1028
|
+
*
|
|
1029
|
+
* @example
|
|
1030
|
+
* ```typescript
|
|
1031
|
+
* config: {
|
|
1032
|
+
* onSessionInit: (session) => {
|
|
1033
|
+
* console.log('Session started:', session.sessionId);
|
|
1034
|
+
* }
|
|
1035
|
+
* }
|
|
1036
|
+
* ```
|
|
1037
|
+
*/
|
|
1038
|
+
onSessionInit?: (session: ClientSession) => void;
|
|
1039
|
+
/**
|
|
1040
|
+
* Callback when session expires or errors (client token mode only).
|
|
1041
|
+
* Widget should prompt user to refresh.
|
|
1042
|
+
*
|
|
1043
|
+
* @example
|
|
1044
|
+
* ```typescript
|
|
1045
|
+
* config: {
|
|
1046
|
+
* onSessionExpired: () => {
|
|
1047
|
+
* alert('Your session has expired. Please refresh the page.');
|
|
1048
|
+
* }
|
|
1049
|
+
* }
|
|
1050
|
+
* ```
|
|
1051
|
+
*/
|
|
1052
|
+
onSessionExpired?: () => void;
|
|
880
1053
|
/**
|
|
881
1054
|
* Static headers to include with each request.
|
|
882
1055
|
* For dynamic headers (e.g., auth tokens), use `getHeaders` instead.
|
|
@@ -1108,6 +1281,30 @@ type AgentWidgetConfig = {
|
|
|
1108
1281
|
* ```
|
|
1109
1282
|
*/
|
|
1110
1283
|
markdown?: AgentWidgetMarkdownConfig;
|
|
1284
|
+
/**
|
|
1285
|
+
* Configuration for message action buttons (copy, upvote, downvote).
|
|
1286
|
+
* Shows action buttons on assistant messages for user feedback.
|
|
1287
|
+
*
|
|
1288
|
+
* @example
|
|
1289
|
+
* ```typescript
|
|
1290
|
+
* config: {
|
|
1291
|
+
* messageActions: {
|
|
1292
|
+
* enabled: true,
|
|
1293
|
+
* showCopy: true,
|
|
1294
|
+
* showUpvote: true,
|
|
1295
|
+
* showDownvote: true,
|
|
1296
|
+
* visibility: 'hover',
|
|
1297
|
+
* onFeedback: (feedback) => {
|
|
1298
|
+
* console.log('Feedback:', feedback.type, feedback.messageId);
|
|
1299
|
+
* },
|
|
1300
|
+
* onCopy: (message) => {
|
|
1301
|
+
* console.log('Copied message:', message.id);
|
|
1302
|
+
* }
|
|
1303
|
+
* }
|
|
1304
|
+
* }
|
|
1305
|
+
* ```
|
|
1306
|
+
*/
|
|
1307
|
+
messageActions?: AgentWidgetMessageActionsConfig;
|
|
1111
1308
|
};
|
|
1112
1309
|
type AgentWidgetMessageRole = "user" | "assistant" | "system";
|
|
1113
1310
|
type AgentWidgetReasoning = {
|
|
@@ -1184,6 +1381,132 @@ type AgentWidgetInitOptions = {
|
|
|
1184
1381
|
debugTools?: boolean;
|
|
1185
1382
|
};
|
|
1186
1383
|
|
|
1384
|
+
type DispatchOptions = {
|
|
1385
|
+
messages: AgentWidgetMessage[];
|
|
1386
|
+
signal?: AbortSignal;
|
|
1387
|
+
/** Pre-generated ID for the expected assistant response (for feedback tracking) */
|
|
1388
|
+
assistantMessageId?: string;
|
|
1389
|
+
};
|
|
1390
|
+
type SSEHandler = (event: AgentWidgetEvent) => void;
|
|
1391
|
+
declare class AgentWidgetClient {
|
|
1392
|
+
private config;
|
|
1393
|
+
private readonly apiUrl;
|
|
1394
|
+
private readonly headers;
|
|
1395
|
+
private readonly debug;
|
|
1396
|
+
private readonly createStreamParser;
|
|
1397
|
+
private readonly contextProviders;
|
|
1398
|
+
private readonly requestMiddleware?;
|
|
1399
|
+
private readonly customFetch?;
|
|
1400
|
+
private readonly parseSSEEvent?;
|
|
1401
|
+
private readonly getHeaders?;
|
|
1402
|
+
private clientSession;
|
|
1403
|
+
private sessionInitPromise;
|
|
1404
|
+
constructor(config?: AgentWidgetConfig);
|
|
1405
|
+
/**
|
|
1406
|
+
* Check if running in client token mode
|
|
1407
|
+
*/
|
|
1408
|
+
isClientTokenMode(): boolean;
|
|
1409
|
+
/**
|
|
1410
|
+
* Get the appropriate API URL based on mode
|
|
1411
|
+
*/
|
|
1412
|
+
private getClientApiUrl;
|
|
1413
|
+
/**
|
|
1414
|
+
* Get the current client session (if any)
|
|
1415
|
+
*/
|
|
1416
|
+
getClientSession(): ClientSession | null;
|
|
1417
|
+
/**
|
|
1418
|
+
* Initialize session for client token mode.
|
|
1419
|
+
* Called automatically on first message if not already initialized.
|
|
1420
|
+
*/
|
|
1421
|
+
initSession(): Promise<ClientSession>;
|
|
1422
|
+
private _doInitSession;
|
|
1423
|
+
/**
|
|
1424
|
+
* Clear the current client session
|
|
1425
|
+
*/
|
|
1426
|
+
clearClientSession(): void;
|
|
1427
|
+
/**
|
|
1428
|
+
* Get the feedback API URL
|
|
1429
|
+
*/
|
|
1430
|
+
private getFeedbackApiUrl;
|
|
1431
|
+
/**
|
|
1432
|
+
* Send feedback for a message (client token mode only).
|
|
1433
|
+
* Supports upvote, downvote, copy, csat, and nps feedback types.
|
|
1434
|
+
*
|
|
1435
|
+
* @param feedback - The feedback request payload
|
|
1436
|
+
* @returns Promise that resolves when feedback is sent successfully
|
|
1437
|
+
* @throws Error if not in client token mode or if session is invalid
|
|
1438
|
+
*
|
|
1439
|
+
* @example
|
|
1440
|
+
* ```typescript
|
|
1441
|
+
* // Message feedback (upvote/downvote/copy)
|
|
1442
|
+
* await client.sendFeedback({
|
|
1443
|
+
* session_id: sessionId,
|
|
1444
|
+
* message_id: messageId,
|
|
1445
|
+
* type: 'upvote'
|
|
1446
|
+
* });
|
|
1447
|
+
*
|
|
1448
|
+
* // CSAT feedback (1-5 rating)
|
|
1449
|
+
* await client.sendFeedback({
|
|
1450
|
+
* session_id: sessionId,
|
|
1451
|
+
* type: 'csat',
|
|
1452
|
+
* rating: 5,
|
|
1453
|
+
* comment: 'Great experience!'
|
|
1454
|
+
* });
|
|
1455
|
+
*
|
|
1456
|
+
* // NPS feedback (0-10 rating)
|
|
1457
|
+
* await client.sendFeedback({
|
|
1458
|
+
* session_id: sessionId,
|
|
1459
|
+
* type: 'nps',
|
|
1460
|
+
* rating: 9
|
|
1461
|
+
* });
|
|
1462
|
+
* ```
|
|
1463
|
+
*/
|
|
1464
|
+
sendFeedback(feedback: ClientFeedbackRequest): Promise<void>;
|
|
1465
|
+
/**
|
|
1466
|
+
* Submit message feedback (upvote, downvote, or copy).
|
|
1467
|
+
* Convenience method for sendFeedback with message-level feedback.
|
|
1468
|
+
*
|
|
1469
|
+
* @param messageId - The ID of the message to provide feedback for
|
|
1470
|
+
* @param type - The feedback type: 'upvote', 'downvote', or 'copy'
|
|
1471
|
+
*/
|
|
1472
|
+
submitMessageFeedback(messageId: string, type: 'upvote' | 'downvote' | 'copy'): Promise<void>;
|
|
1473
|
+
/**
|
|
1474
|
+
* Submit CSAT (Customer Satisfaction) feedback.
|
|
1475
|
+
* Convenience method for sendFeedback with CSAT feedback.
|
|
1476
|
+
*
|
|
1477
|
+
* @param rating - Rating from 1 to 5
|
|
1478
|
+
* @param comment - Optional comment
|
|
1479
|
+
*/
|
|
1480
|
+
submitCSATFeedback(rating: number, comment?: string): Promise<void>;
|
|
1481
|
+
/**
|
|
1482
|
+
* Submit NPS (Net Promoter Score) feedback.
|
|
1483
|
+
* Convenience method for sendFeedback with NPS feedback.
|
|
1484
|
+
*
|
|
1485
|
+
* @param rating - Rating from 0 to 10
|
|
1486
|
+
* @param comment - Optional comment
|
|
1487
|
+
*/
|
|
1488
|
+
submitNPSFeedback(rating: number, comment?: string): Promise<void>;
|
|
1489
|
+
/**
|
|
1490
|
+
* Send a message - handles both proxy and client token modes
|
|
1491
|
+
*/
|
|
1492
|
+
dispatch(options: DispatchOptions, onEvent: SSEHandler): Promise<void>;
|
|
1493
|
+
/**
|
|
1494
|
+
* Client token mode dispatch
|
|
1495
|
+
*/
|
|
1496
|
+
private dispatchClientToken;
|
|
1497
|
+
/**
|
|
1498
|
+
* Proxy mode dispatch (original implementation)
|
|
1499
|
+
*/
|
|
1500
|
+
private dispatchProxy;
|
|
1501
|
+
private buildPayload;
|
|
1502
|
+
/**
|
|
1503
|
+
* Handle custom SSE event parsing via parseSSEEvent callback
|
|
1504
|
+
* Returns true if event was handled, false otherwise
|
|
1505
|
+
*/
|
|
1506
|
+
private handleCustomSSEEvent;
|
|
1507
|
+
private streamResponse;
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1187
1510
|
type AgentWidgetSessionStatus = "idle" | "connecting" | "connected" | "error";
|
|
1188
1511
|
type SessionCallbacks = {
|
|
1189
1512
|
onMessagesChanged: (messages: AgentWidgetMessage[]) => void;
|
|
@@ -1200,7 +1523,62 @@ declare class AgentWidgetSession {
|
|
|
1200
1523
|
private streaming;
|
|
1201
1524
|
private abortController;
|
|
1202
1525
|
private sequenceCounter;
|
|
1526
|
+
private clientSession;
|
|
1203
1527
|
constructor(config: AgentWidgetConfig | undefined, callbacks: SessionCallbacks);
|
|
1528
|
+
/**
|
|
1529
|
+
* Check if running in client token mode
|
|
1530
|
+
*/
|
|
1531
|
+
isClientTokenMode(): boolean;
|
|
1532
|
+
/**
|
|
1533
|
+
* Initialize the client session (for client token mode).
|
|
1534
|
+
* This is called automatically on first message, but can be called
|
|
1535
|
+
* explicitly to pre-initialize the session and get config from server.
|
|
1536
|
+
*/
|
|
1537
|
+
initClientSession(): Promise<ClientSession | null>;
|
|
1538
|
+
/**
|
|
1539
|
+
* Set the client session after initialization
|
|
1540
|
+
*/
|
|
1541
|
+
setClientSession(session: ClientSession): void;
|
|
1542
|
+
/**
|
|
1543
|
+
* Get current client session
|
|
1544
|
+
*/
|
|
1545
|
+
getClientSession(): ClientSession | null;
|
|
1546
|
+
/**
|
|
1547
|
+
* Check if session is valid and not expired
|
|
1548
|
+
*/
|
|
1549
|
+
isSessionValid(): boolean;
|
|
1550
|
+
/**
|
|
1551
|
+
* Clear session (on expiry or error)
|
|
1552
|
+
*/
|
|
1553
|
+
clearClientSession(): void;
|
|
1554
|
+
/**
|
|
1555
|
+
* Get the underlying client instance (for advanced use cases like feedback)
|
|
1556
|
+
*/
|
|
1557
|
+
getClient(): AgentWidgetClient;
|
|
1558
|
+
/**
|
|
1559
|
+
* Submit message feedback (upvote, downvote, or copy) to the API.
|
|
1560
|
+
* Only available in client token mode.
|
|
1561
|
+
*
|
|
1562
|
+
* @param messageId - The ID of the message to provide feedback for
|
|
1563
|
+
* @param type - The feedback type: 'upvote', 'downvote', or 'copy'
|
|
1564
|
+
*/
|
|
1565
|
+
submitMessageFeedback(messageId: string, type: 'upvote' | 'downvote' | 'copy'): Promise<void>;
|
|
1566
|
+
/**
|
|
1567
|
+
* Submit CSAT (Customer Satisfaction) feedback to the API.
|
|
1568
|
+
* Only available in client token mode.
|
|
1569
|
+
*
|
|
1570
|
+
* @param rating - Rating from 1 to 5
|
|
1571
|
+
* @param comment - Optional comment
|
|
1572
|
+
*/
|
|
1573
|
+
submitCSATFeedback(rating: number, comment?: string): Promise<void>;
|
|
1574
|
+
/**
|
|
1575
|
+
* Submit NPS (Net Promoter Score) feedback to the API.
|
|
1576
|
+
* Only available in client token mode.
|
|
1577
|
+
*
|
|
1578
|
+
* @param rating - Rating from 0 to 10
|
|
1579
|
+
* @param comment - Optional comment
|
|
1580
|
+
*/
|
|
1581
|
+
submitNPSFeedback(rating: number, comment?: string): Promise<void>;
|
|
1204
1582
|
updateConfig(next: AgentWidgetConfig): void;
|
|
1205
1583
|
getMessages(): AgentWidgetMessage[];
|
|
1206
1584
|
getStatus(): AgentWidgetSessionStatus;
|
|
@@ -1222,6 +1600,62 @@ declare class AgentWidgetSession {
|
|
|
1222
1600
|
private sortMessages;
|
|
1223
1601
|
}
|
|
1224
1602
|
|
|
1603
|
+
/**
|
|
1604
|
+
* Feedback UI components for CSAT and NPS collection
|
|
1605
|
+
*/
|
|
1606
|
+
type CSATFeedbackOptions = {
|
|
1607
|
+
/** Callback when user submits CSAT feedback */
|
|
1608
|
+
onSubmit: (rating: number, comment?: string) => void | Promise<void>;
|
|
1609
|
+
/** Callback when user dismisses the feedback form */
|
|
1610
|
+
onDismiss?: () => void;
|
|
1611
|
+
/** Title text */
|
|
1612
|
+
title?: string;
|
|
1613
|
+
/** Subtitle/question text */
|
|
1614
|
+
subtitle?: string;
|
|
1615
|
+
/** Placeholder for optional comment field */
|
|
1616
|
+
commentPlaceholder?: string;
|
|
1617
|
+
/** Submit button text */
|
|
1618
|
+
submitText?: string;
|
|
1619
|
+
/** Skip button text */
|
|
1620
|
+
skipText?: string;
|
|
1621
|
+
/** Show comment field */
|
|
1622
|
+
showComment?: boolean;
|
|
1623
|
+
/** Rating labels (5 items for ratings 1-5) */
|
|
1624
|
+
ratingLabels?: [string, string, string, string, string];
|
|
1625
|
+
};
|
|
1626
|
+
type NPSFeedbackOptions = {
|
|
1627
|
+
/** Callback when user submits NPS feedback */
|
|
1628
|
+
onSubmit: (rating: number, comment?: string) => void | Promise<void>;
|
|
1629
|
+
/** Callback when user dismisses the feedback form */
|
|
1630
|
+
onDismiss?: () => void;
|
|
1631
|
+
/** Title text */
|
|
1632
|
+
title?: string;
|
|
1633
|
+
/** Subtitle/question text */
|
|
1634
|
+
subtitle?: string;
|
|
1635
|
+
/** Placeholder for optional comment field */
|
|
1636
|
+
commentPlaceholder?: string;
|
|
1637
|
+
/** Submit button text */
|
|
1638
|
+
submitText?: string;
|
|
1639
|
+
/** Skip button text */
|
|
1640
|
+
skipText?: string;
|
|
1641
|
+
/** Show comment field */
|
|
1642
|
+
showComment?: boolean;
|
|
1643
|
+
/** Low label (left side) */
|
|
1644
|
+
lowLabel?: string;
|
|
1645
|
+
/** High label (right side) */
|
|
1646
|
+
highLabel?: string;
|
|
1647
|
+
};
|
|
1648
|
+
/**
|
|
1649
|
+
* Create a CSAT (Customer Satisfaction) feedback form
|
|
1650
|
+
* Rating scale: 1-5
|
|
1651
|
+
*/
|
|
1652
|
+
declare function createCSATFeedback(options: CSATFeedbackOptions): HTMLElement;
|
|
1653
|
+
/**
|
|
1654
|
+
* Create an NPS (Net Promoter Score) feedback form
|
|
1655
|
+
* Rating scale: 0-10
|
|
1656
|
+
*/
|
|
1657
|
+
declare function createNPSFeedback(options: NPSFeedbackOptions): HTMLElement;
|
|
1658
|
+
|
|
1225
1659
|
type Controller = {
|
|
1226
1660
|
update: (config: AgentWidgetConfig) => void;
|
|
1227
1661
|
destroy: () => void;
|
|
@@ -1243,6 +1677,10 @@ type Controller = {
|
|
|
1243
1677
|
isOpen: () => boolean;
|
|
1244
1678
|
isVoiceActive: () => boolean;
|
|
1245
1679
|
getState: () => AgentWidgetStateSnapshot;
|
|
1680
|
+
showCSATFeedback: (options?: Partial<CSATFeedbackOptions>) => void;
|
|
1681
|
+
showNPSFeedback: (options?: Partial<NPSFeedbackOptions>) => void;
|
|
1682
|
+
submitCSATFeedback: (rating: number, comment?: string) => Promise<void>;
|
|
1683
|
+
submitNPSFeedback: (rating: number, comment?: string) => Promise<void>;
|
|
1246
1684
|
};
|
|
1247
1685
|
declare const createAgentExperience: (mount: HTMLElement, initialConfig?: AgentWidgetConfig, runtimeOptions?: {
|
|
1248
1686
|
debugTools?: boolean;
|
|
@@ -1254,33 +1692,6 @@ type AgentWidgetInitHandle = AgentWidgetController & {
|
|
|
1254
1692
|
};
|
|
1255
1693
|
declare const initAgentWidget: (options: AgentWidgetInitOptions) => AgentWidgetInitHandle;
|
|
1256
1694
|
|
|
1257
|
-
type DispatchOptions = {
|
|
1258
|
-
messages: AgentWidgetMessage[];
|
|
1259
|
-
signal?: AbortSignal;
|
|
1260
|
-
};
|
|
1261
|
-
type SSEHandler = (event: AgentWidgetEvent) => void;
|
|
1262
|
-
declare class AgentWidgetClient {
|
|
1263
|
-
private config;
|
|
1264
|
-
private readonly apiUrl;
|
|
1265
|
-
private readonly headers;
|
|
1266
|
-
private readonly debug;
|
|
1267
|
-
private readonly createStreamParser;
|
|
1268
|
-
private readonly contextProviders;
|
|
1269
|
-
private readonly requestMiddleware?;
|
|
1270
|
-
private readonly customFetch?;
|
|
1271
|
-
private readonly parseSSEEvent?;
|
|
1272
|
-
private readonly getHeaders?;
|
|
1273
|
-
constructor(config?: AgentWidgetConfig);
|
|
1274
|
-
dispatch(options: DispatchOptions, onEvent: SSEHandler): Promise<void>;
|
|
1275
|
-
private buildPayload;
|
|
1276
|
-
/**
|
|
1277
|
-
* Handle custom SSE event parsing via parseSSEEvent callback
|
|
1278
|
-
* Returns true if event was handled, false otherwise
|
|
1279
|
-
*/
|
|
1280
|
-
private handleCustomSSEEvent;
|
|
1281
|
-
private streamResponse;
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
1695
|
declare const createLocalStorageAdapter: (key?: string) => AgentWidgetStorageAdapter;
|
|
1285
1696
|
|
|
1286
1697
|
type ActionManagerProcessContext = {
|
|
@@ -1416,6 +1827,26 @@ declare const createFlexibleJsonStreamParser: (textExtractor?: (parsed: any) =>
|
|
|
1416
1827
|
*/
|
|
1417
1828
|
declare const createXmlParser: () => AgentWidgetStreamParser;
|
|
1418
1829
|
|
|
1830
|
+
/**
|
|
1831
|
+
* Message ID utilities for client-side message tracking
|
|
1832
|
+
* Used for feedback integration with the Travrse API
|
|
1833
|
+
*/
|
|
1834
|
+
/**
|
|
1835
|
+
* Generate a unique message ID for tracking
|
|
1836
|
+
* Format: msg_{timestamp_base36}_{random_8chars}
|
|
1837
|
+
*/
|
|
1838
|
+
declare function generateMessageId(): string;
|
|
1839
|
+
/**
|
|
1840
|
+
* Generate a unique user message ID
|
|
1841
|
+
* Format: usr_{timestamp_base36}_{random_8chars}
|
|
1842
|
+
*/
|
|
1843
|
+
declare function generateUserMessageId(): string;
|
|
1844
|
+
/**
|
|
1845
|
+
* Generate a unique assistant message ID
|
|
1846
|
+
* Format: ast_{timestamp_base36}_{random_8chars}
|
|
1847
|
+
*/
|
|
1848
|
+
declare function generateAssistantMessageId(): string;
|
|
1849
|
+
|
|
1419
1850
|
type CodeFormat = "esm" | "script-installer" | "script-manual" | "script-advanced" | "react-component" | "react-advanced";
|
|
1420
1851
|
declare function generateCodeSnippet(config: any, format?: CodeFormat): string;
|
|
1421
1852
|
|
|
@@ -1537,17 +1968,25 @@ type MessageTransform = (context: {
|
|
|
1537
1968
|
streaming: boolean;
|
|
1538
1969
|
raw?: string;
|
|
1539
1970
|
}) => string;
|
|
1971
|
+
type MessageActionCallbacks = {
|
|
1972
|
+
onCopy?: (message: AgentWidgetMessage) => void;
|
|
1973
|
+
onFeedback?: (feedback: AgentWidgetMessageFeedback) => void;
|
|
1974
|
+
};
|
|
1540
1975
|
declare const createTypingIndicator: () => HTMLElement;
|
|
1976
|
+
/**
|
|
1977
|
+
* Create message action buttons (copy, upvote, downvote)
|
|
1978
|
+
*/
|
|
1979
|
+
declare const createMessageActions: (message: AgentWidgetMessage, actionsConfig: AgentWidgetMessageActionsConfig, callbacks?: MessageActionCallbacks) => HTMLElement;
|
|
1541
1980
|
/**
|
|
1542
1981
|
* Create standard message bubble
|
|
1543
1982
|
* Supports layout configuration for avatars, timestamps, and visual presets
|
|
1544
1983
|
*/
|
|
1545
|
-
declare const createStandardBubble: (message: AgentWidgetMessage, transform: MessageTransform, layoutConfig?: AgentWidgetMessageLayoutConfig) => HTMLElement;
|
|
1984
|
+
declare const createStandardBubble: (message: AgentWidgetMessage, transform: MessageTransform, layoutConfig?: AgentWidgetMessageLayoutConfig, actionsConfig?: AgentWidgetMessageActionsConfig, actionCallbacks?: MessageActionCallbacks) => HTMLElement;
|
|
1546
1985
|
/**
|
|
1547
1986
|
* Create bubble with custom renderer support
|
|
1548
1987
|
* Uses custom renderer if provided in layout config, otherwise falls back to standard bubble
|
|
1549
1988
|
*/
|
|
1550
|
-
declare const createBubbleWithLayout: (message: AgentWidgetMessage, transform: MessageTransform, layoutConfig?: AgentWidgetMessageLayoutConfig) => HTMLElement;
|
|
1989
|
+
declare const createBubbleWithLayout: (message: AgentWidgetMessage, transform: MessageTransform, layoutConfig?: AgentWidgetMessageLayoutConfig, actionsConfig?: AgentWidgetMessageActionsConfig, actionCallbacks?: MessageActionCallbacks) => HTMLElement;
|
|
1551
1990
|
|
|
1552
1991
|
/**
|
|
1553
1992
|
* Options for component middleware
|
|
@@ -1684,4 +2123,4 @@ declare const getHeaderLayout: (layoutName: string) => HeaderLayoutRenderer;
|
|
|
1684
2123
|
*/
|
|
1685
2124
|
declare const buildHeaderWithLayout: (config: AgentWidgetConfig, layoutConfig?: AgentWidgetHeaderLayoutConfig, context?: Partial<HeaderLayoutContext>) => HeaderElements;
|
|
1686
2125
|
|
|
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 };
|
|
2126
|
+
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 CSATFeedbackOptions, type ClientChatRequest, type ClientFeedbackRequest, type ClientFeedbackType, 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 NPSFeedbackOptions, type SlotRenderContext, type SlotRenderer, type WidgetLayoutSlot, attachHeaderToContainer, buildComposer, buildDefaultHeader, buildExpandedHeader, buildHeader, buildHeaderWithLayout, buildMinimalHeader, componentRegistry, createActionManager, createAgentExperience, createBubbleWithLayout, createCSATFeedback, createComponentMiddleware, createComponentStreamParser, createDirectivePostprocessor, createFlexibleJsonStreamParser, createJsonStreamParser, createLocalStorageAdapter, createMarkdownProcessor, createMarkdownProcessorFromConfig, createMessageActions, createNPSFeedback, createPlainTextParser, createRegexJsonParser, createStandardBubble, createTypingIndicator, createXmlParser, initAgentWidget as default, defaultActionHandlers, defaultJsonActionParser, directivePostprocessor, escapeHtml, extractComponentDirectiveFromMessage, generateAssistantMessageId, generateCodeSnippet, generateMessageId, generateUserMessageId, getHeaderLayout, hasComponentDirective, headerLayouts, initAgentWidget, isComponentDirectiveType, markdownPostprocessor, mergeWithDefaults, pluginRegistry, renderComponentDirective };
|