@runtypelabs/persona 1.46.0 → 1.47.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 CHANGED
@@ -1275,27 +1275,424 @@ This ensures all configuration values are set to sensible defaults while allowin
1275
1275
 
1276
1276
  ### Configuration reference
1277
1277
 
1278
+ All options are safe to mutate via `initAgentWidget(...).update(newConfig)`.
1279
+
1280
+ For detailed theme styling properties, see [THEME-CONFIG.md](./THEME-CONFIG.md).
1281
+
1282
+ #### Core
1283
+
1284
+ | Option | Type | Description |
1285
+ | --- | --- | --- |
1286
+ | `apiUrl` | `string` | Proxy endpoint for your chat backend. Defaults to Runtype's cloud API. |
1287
+ | `flowId` | `string` | Runtype flow ID. The client sends it to the proxy to select a specific flow. |
1288
+ | `debug` | `boolean` | Emits verbose logs to `console`. Default: `false`. |
1289
+ | `headers` | `Record<string, string>` | Static headers forwarded with each request. |
1290
+ | `getHeaders` | `() => Record<string, string> \| Promise<...>` | Dynamic headers function called before each request. Use for auth tokens that may change. |
1291
+ | `customFetch` | `(url, init, payload) => Promise<Response>` | Replace the default `fetch` entirely. Receives URL, RequestInit, and the payload. |
1292
+ | `parseSSEEvent` | `(eventData) => { text?, done?, error? } \| null` | Transform non-standard SSE events into the expected format. Return `null` to ignore an event. |
1293
+
1294
+ #### Client Token Mode
1295
+
1296
+ When `clientToken` is set, the widget uses `/v1/client/*` endpoints directly from the browser instead of `/v1/dispatch`.
1297
+
1298
+ | Option | Type | Description |
1299
+ | --- | --- | --- |
1300
+ | `clientToken` | `string` | Client token for direct browser-to-API communication (e.g. `ct_live_flow01k7_...`). Mutually exclusive with `headers` auth. |
1301
+ | `onSessionInit` | `(session: ClientSession) => void` | Called when the session is initialized. Receives session ID, expiry, flow info. |
1302
+ | `onSessionExpired` | `() => void` | Called when the session expires or errors. Prompt the user to refresh. |
1303
+ | `getStoredSessionId` | `() => string \| null` | Return a previously stored session ID for session resumption. |
1304
+ | `setStoredSessionId` | `(sessionId: string) => void` | Persist the session ID so conversations can be resumed later. |
1305
+
1306
+ ```typescript
1307
+ config: {
1308
+ clientToken: 'ct_live_flow01k7_a8b9c0d1e2f3g4h5i6j7k8l9',
1309
+ onSessionInit: (session) => console.log('Session:', session.sessionId),
1310
+ onSessionExpired: () => alert('Session expired — please refresh.'),
1311
+ getStoredSessionId: () => localStorage.getItem('session_id'),
1312
+ setStoredSessionId: (id) => localStorage.setItem('session_id', id)
1313
+ }
1314
+ ```
1315
+
1316
+ #### Agent Mode
1317
+
1318
+ Use agent loop execution instead of flow dispatch. Mutually exclusive with `flowId`.
1319
+
1320
+ | Option | Type | Description |
1321
+ | --- | --- | --- |
1322
+ | `agent` | `AgentConfig` | Agent configuration (see sub-table below). Enables agent loop execution. |
1323
+ | `agentOptions` | `AgentRequestOptions` | Options for agent execution requests. Default: `{ streamResponse: true, recordMode: 'virtual' }`. |
1324
+ | `iterationDisplay` | `'separate' \| 'merged'` | How multi-iteration output is shown. `'separate'`: new bubble per iteration. `'merged'`: single bubble. Default: `'separate'`. |
1325
+
1326
+ **`AgentConfig`**
1327
+
1328
+ | Property | Type | Description |
1329
+ | --- | --- | --- |
1330
+ | `name` | `string` | Agent display name. |
1331
+ | `model` | `string` | Model identifier (e.g. `'openai:gpt-4o-mini'`). |
1332
+ | `systemPrompt` | `string` | System prompt for the agent. |
1333
+ | `temperature` | `number?` | Temperature for model responses. |
1334
+ | `loopConfig` | `AgentLoopConfig?` | Loop behavior configuration (see below). |
1335
+
1336
+ **`AgentLoopConfig`**
1337
+
1338
+ | Property | Type | Description |
1339
+ | --- | --- | --- |
1340
+ | `maxIterations` | `number` | Maximum number of reasoning iterations. |
1341
+ | `stopCondition` | `'auto' \| string?` | `'auto'` for automatic detection, or a custom JS expression. |
1342
+ | `enableReflection` | `boolean?` | Enable periodic reflection during execution. |
1343
+ | `reflectionInterval` | `number?` | Number of iterations between reflections. |
1344
+
1345
+ **`AgentRequestOptions`**
1346
+
1347
+ | Property | Type | Description |
1348
+ | --- | --- | --- |
1349
+ | `streamResponse` | `boolean?` | Stream the response (should be `true` for widget usage). |
1350
+ | `recordMode` | `'virtual' \| 'existing' \| 'create'?` | Record persistence mode. |
1351
+ | `storeResults` | `boolean?` | Store results server-side. |
1352
+ | `debugMode` | `boolean?` | Enable debug mode for additional event data. |
1353
+
1354
+ ```typescript
1355
+ config: {
1356
+ agent: {
1357
+ name: 'Assistant',
1358
+ model: 'openai:gpt-4o-mini',
1359
+ systemPrompt: 'You are a helpful assistant.',
1360
+ loopConfig: { maxIterations: 3, stopCondition: 'auto' }
1361
+ },
1362
+ agentOptions: { streamResponse: true, recordMode: 'virtual' },
1363
+ iterationDisplay: 'merged'
1364
+ }
1365
+ ```
1366
+
1367
+ #### UI & Theme
1368
+
1369
+ | Option | Type | Description |
1370
+ | --- | --- | --- |
1371
+ | `theme` | `AgentWidgetTheme` | CSS variable overrides for colors, border radii, and visual styles. See [THEME-CONFIG.md](./THEME-CONFIG.md) for the full property list. |
1372
+ | `darkTheme` | `AgentWidgetTheme` | Theme overrides for dark mode. Falls back to `theme` when not provided. |
1373
+ | `colorScheme` | `'light' \| 'dark' \| 'auto'` | Color scheme mode. `'auto'` detects from `<html class="dark">` or `prefers-color-scheme`. Default: `'light'`. |
1374
+ | `copy` | `{ welcomeTitle?, welcomeSubtitle?, inputPlaceholder?, sendButtonLabel? }` | Customize user-facing text strings. |
1375
+ | `autoFocusInput` | `boolean` | Focus the chat input after the panel opens. Skips when voice is active. Default: `false`. |
1376
+ | `launcherWidth` | `string` | CSS width for the floating launcher panel (e.g. `'320px'`). Default: `'min(400px, calc(100vw - 24px))'`. |
1377
+
1378
+ #### Launcher
1379
+
1380
+ Controls the floating launcher button and panel.
1381
+
1382
+ | Option | Type | Description |
1383
+ | --- | --- | --- |
1384
+ | `launcher` | `AgentWidgetLauncherConfig` | Launcher button configuration (see key properties below). See [THEME-CONFIG.md](./THEME-CONFIG.md) for the full list of icon, button, and style properties. |
1385
+
1386
+ **Key `launcher` properties**
1387
+
1388
+ | Property | Type | Description |
1389
+ | --- | --- | --- |
1390
+ | `enabled` | `boolean?` | Show the launcher button. |
1391
+ | `autoExpand` | `boolean?` | Auto-open the chat panel on load. |
1392
+ | `title` | `string?` | Launcher header title text. |
1393
+ | `subtitle` | `string?` | Launcher header subtitle text. |
1394
+ | `iconUrl` | `string?` | URL for the launcher icon image. |
1395
+ | `position` | `'bottom-right' \| 'bottom-left' \| 'top-right' \| 'top-left'?` | Screen corner position. |
1396
+ | `width` | `string?` | Width of the launcher button. |
1397
+ | `fullHeight` | `boolean?` | Fill the full height of the container. Default: `false`. |
1398
+ | `sidebarMode` | `boolean?` | Flush sidebar layout with no border-radius or margins. Default: `false`. |
1399
+ | `sidebarWidth` | `string?` | Width when `sidebarMode` is true. Default: `'420px'`. |
1400
+ | `heightOffset` | `number?` | Pixels to subtract from panel height (for fixed headers, etc.). Default: `0`. |
1401
+ | `clearChat` | `AgentWidgetClearChatConfig?` | Clear chat button configuration (enabled, placement, icon, styling). |
1402
+ | `border` | `string?` | Border style for the launcher button. Default: `'1px solid #e5e7eb'`. |
1403
+ | `shadow` | `string?` | Box shadow for the launcher button. |
1404
+
1405
+ #### Layout
1406
+
1407
+ | Option | Type | Description |
1408
+ | --- | --- | --- |
1409
+ | `layout` | `AgentWidgetLayoutConfig` | Layout configuration (see sub-properties below). |
1410
+
1411
+ **`AgentWidgetLayoutConfig`**
1412
+
1413
+ | Property | Type | Description |
1414
+ | --- | --- | --- |
1415
+ | `showHeader` | `boolean?` | Show/hide the header section entirely. Default: `true`. |
1416
+ | `showFooter` | `boolean?` | Show/hide the footer/composer section entirely. Default: `true`. |
1417
+ | `header` | `AgentWidgetHeaderLayoutConfig?` | Header customization (see below). |
1418
+ | `messages` | `AgentWidgetMessageLayoutConfig?` | Message display customization (see below). |
1419
+ | `slots` | `Record<WidgetLayoutSlot, SlotRenderer>?` | Content injection into named slots. |
1420
+
1421
+ **`header`** — `AgentWidgetHeaderLayoutConfig`
1422
+
1423
+ | Property | Type | Description |
1424
+ | --- | --- | --- |
1425
+ | `layout` | `'default' \| 'minimal' \| 'expanded'?` | Header preset. |
1426
+ | `showIcon` | `boolean?` | Show/hide the header icon. |
1427
+ | `showTitle` | `boolean?` | Show/hide the title. |
1428
+ | `showSubtitle` | `boolean?` | Show/hide the subtitle. |
1429
+ | `showCloseButton` | `boolean?` | Show/hide the close button. |
1430
+ | `showClearChat` | `boolean?` | Show/hide the clear chat button. |
1431
+ | `render` | `(ctx: HeaderRenderContext) => HTMLElement?` | Custom renderer that replaces the entire header. |
1432
+
1433
+ **`messages`** — `AgentWidgetMessageLayoutConfig`
1434
+
1435
+ | Property | Type | Description |
1436
+ | --- | --- | --- |
1437
+ | `layout` | `'bubble' \| 'flat' \| 'minimal'?` | Message style preset. Default: `'bubble'`. |
1438
+ | `avatar` | `{ show?, position?, userAvatar?, assistantAvatar? }?` | Avatar configuration. |
1439
+ | `timestamp` | `{ show?, position?, format? }?` | Timestamp configuration. |
1440
+ | `groupConsecutive` | `boolean?` | Group consecutive messages from the same role. |
1441
+ | `renderUserMessage` | `(ctx: MessageRenderContext) => HTMLElement?` | Custom user message renderer. |
1442
+ | `renderAssistantMessage` | `(ctx: MessageRenderContext) => HTMLElement?` | Custom assistant message renderer. |
1443
+
1444
+ **Available `slots`**: `header-left`, `header-center`, `header-right`, `body-top`, `messages`, `body-bottom`, `footer-top`, `composer`, `footer-bottom`.
1445
+
1446
+ #### Message Display
1447
+
1448
+ | Option | Type | Description |
1449
+ | --- | --- | --- |
1450
+ | `postprocessMessage` | `(ctx: { text, message, streaming, raw? }) => string` | Transform message text before rendering (return HTML). |
1451
+ | `markdown` | `AgentWidgetMarkdownConfig` | Markdown rendering configuration (see sub-table). |
1452
+ | `messageActions` | `AgentWidgetMessageActionsConfig` | Action buttons on assistant messages (see sub-table). |
1453
+ | `loadingIndicator` | `AgentWidgetLoadingIndicatorConfig` | Customize the loading indicator (see sub-table). |
1454
+
1455
+ **`markdown`** — `AgentWidgetMarkdownConfig`
1456
+
1457
+ | Property | Type | Description |
1458
+ | --- | --- | --- |
1459
+ | `options` | `AgentWidgetMarkdownOptions?` | Marked parser options: `gfm` (default: `true`), `breaks` (default: `true`), `pedantic`, `headerIds`, `headerPrefix`, `mangle`, `silent`. |
1460
+ | `renderer` | `AgentWidgetMarkdownRendererOverrides?` | Custom renderers for elements: `heading`, `code`, `blockquote`, `table`, `link`, `image`, `list`, `listitem`, `paragraph`, `codespan`, `strong`, `em`, `hr`, `br`, `del`, `checkbox`, `html`, `text`. Return `false` to use default. |
1461
+ | `disableDefaultStyles` | `boolean?` | Skip all default markdown CSS styles. Default: `false`. |
1462
+
1463
+ **`messageActions`** — `AgentWidgetMessageActionsConfig`
1464
+
1465
+ | Property | Type | Description |
1466
+ | --- | --- | --- |
1467
+ | `enabled` | `boolean?` | Enable/disable message actions. Default: `true`. |
1468
+ | `showCopy` | `boolean?` | Show copy button. Default: `true`. |
1469
+ | `showUpvote` | `boolean?` | Show upvote button. Auto-submitted with `clientToken`. Default: `false`. |
1470
+ | `showDownvote` | `boolean?` | Show downvote button. Auto-submitted with `clientToken`. Default: `false`. |
1471
+ | `visibility` | `'always' \| 'hover'?` | Button visibility mode. Default: `'hover'`. |
1472
+ | `align` | `'left' \| 'center' \| 'right'?` | Horizontal alignment. Default: `'right'`. |
1473
+ | `layout` | `'pill-inside' \| 'row-inside'?` | Button layout style. Default: `'pill-inside'`. |
1474
+ | `onFeedback` | `(feedback: AgentWidgetMessageFeedback) => void?` | Callback on upvote/downvote. Called in addition to automatic submission with `clientToken`. |
1475
+ | `onCopy` | `(message: AgentWidgetMessage) => void?` | Callback on copy. Called in addition to automatic tracking with `clientToken`. |
1476
+
1477
+ **`loadingIndicator`** — `AgentWidgetLoadingIndicatorConfig`
1478
+
1479
+ | Property | Type | Description |
1480
+ | --- | --- | --- |
1481
+ | `showBubble` | `boolean?` | Show bubble background around standalone indicator. Default: `true`. |
1482
+ | `render` | `(ctx: LoadingIndicatorRenderContext) => HTMLElement \| null?` | Custom render function. Return `null` to hide. Add `data-preserve-animation="true"` for custom animations. |
1483
+ | `renderIdle` | `(ctx: IdleIndicatorRenderContext) => HTMLElement \| null?` | Custom idle state renderer (shown when not streaming). Return `null` to hide. |
1484
+
1485
+ #### Streaming & Parsing
1486
+
1487
+ | Option | Type | Description |
1488
+ | --- | --- | --- |
1489
+ | `parserType` | `'plain' \| 'json' \| 'regex-json' \| 'xml'` | Built-in parser selector. `'plain'` (default), `'json'` (partial-json), `'regex-json'` (regex-based), `'xml'`. |
1490
+ | `streamParser` | `() => AgentWidgetStreamParser` | Custom stream parser factory. Takes precedence over `parserType`. See [Stream Parser Configuration](#stream-parser-configuration). |
1491
+ | `enableComponentStreaming` | `boolean` | Update component props incrementally as they stream in. Default: `true`. |
1492
+
1493
+ #### Components
1494
+
1495
+ | Option | Type | Description |
1496
+ | --- | --- | --- |
1497
+ | `components` | `Record<string, AgentWidgetComponentRenderer>` | Registry of custom components rendered from JSON directives (`{"component": "Name", "props": {...}}`). Each renderer receives `(props, context)` and returns an `HTMLElement`. |
1498
+
1499
+ ```typescript
1500
+ config: {
1501
+ components: {
1502
+ ProductCard: (props, { message, config, updateProps }) => {
1503
+ const card = document.createElement('div');
1504
+ card.innerHTML = `<h3>${props.title}</h3><p>$${props.price}</p>`;
1505
+ return card;
1506
+ }
1507
+ }
1508
+ }
1509
+ ```
1510
+
1511
+ #### Voice Recognition
1512
+
1513
+ | Option | Type | Description |
1514
+ | --- | --- | --- |
1515
+ | `voiceRecognition` | `AgentWidgetVoiceRecognitionConfig` | Voice input configuration (see sub-table). |
1516
+
1517
+ **`voiceRecognition`** — `AgentWidgetVoiceRecognitionConfig`
1518
+
1519
+ | Property | Type | Description |
1520
+ | --- | --- | --- |
1521
+ | `enabled` | `boolean?` | Enable voice recognition. |
1522
+ | `pauseDuration` | `number?` | Silence duration (ms) before auto-stop. |
1523
+ | `processingText` | `string?` | Placeholder text while processing voice. Default: `'Processing voice...'`. |
1524
+ | `processingErrorText` | `string?` | Error text on voice failure. Default: `'Voice processing failed. Please try again.'`. |
1525
+ | `autoResume` | `boolean \| 'assistant'?` | Auto-resume listening after playback. `'assistant'` resumes after assistant finishes. |
1526
+ | `provider` | `{ type, browser?, runtype?, custom? }?` | Voice provider configuration (see below). |
1527
+ | `iconName`, `iconSize`, `iconColor`, `backgroundColor`, `borderColor`, `borderWidth`, `paddingX`, `paddingY`, `tooltipText`, `showTooltip`, `recordingIconColor`, `recordingBackgroundColor`, `recordingBorderColor`, `showRecordingIndicator` | various | Styling options for the voice button. See [THEME-CONFIG.md](./THEME-CONFIG.md). |
1528
+
1529
+ **`provider.browser`**
1530
+
1531
+ | Property | Type | Description |
1532
+ | --- | --- | --- |
1533
+ | `language` | `string?` | Recognition language (e.g. `'en-US'`). |
1534
+ | `continuous` | `boolean?` | Continuous listening mode. |
1535
+
1536
+ **`provider.runtype`**
1537
+
1538
+ | Property | Type | Description |
1539
+ | --- | --- | --- |
1540
+ | `agentId` | `string` | Runtype agent ID for server-side voice. |
1541
+ | `clientToken` | `string` | Client token for authentication. |
1542
+ | `host` | `string?` | API host override. |
1543
+ | `voiceId` | `string?` | Voice ID for TTS. |
1544
+ | `pauseDuration` | `number?` | Silence duration (ms) before auto-stop. Default: `2000`. |
1545
+ | `silenceThreshold` | `number?` | RMS volume threshold for silence detection. Default: `0.01`. |
1546
+
1547
+ ```typescript
1548
+ // Browser voice recognition
1549
+ config: {
1550
+ voiceRecognition: {
1551
+ enabled: true,
1552
+ provider: { type: 'browser', browser: { language: 'en-US' } }
1553
+ }
1554
+ }
1555
+
1556
+ // Runtype server-side voice
1557
+ config: {
1558
+ voiceRecognition: {
1559
+ enabled: true,
1560
+ provider: {
1561
+ type: 'runtype',
1562
+ runtype: { agentId: 'agent_01abc', clientToken: 'ct_live_...' }
1563
+ }
1564
+ }
1565
+ }
1566
+ ```
1567
+
1568
+ #### Text-to-Speech
1569
+
1570
+ | Option | Type | Description |
1571
+ | --- | --- | --- |
1572
+ | `textToSpeech` | `TextToSpeechConfig` | TTS configuration (see sub-table). |
1573
+
1574
+ **`textToSpeech`** — `TextToSpeechConfig`
1575
+
1576
+ | Property | Type | Description |
1577
+ | --- | --- | --- |
1578
+ | `enabled` | `boolean` | Enable text-to-speech for assistant messages. |
1579
+ | `provider` | `'browser' \| 'runtype'?` | `'browser'` uses Web Speech API (default). `'runtype'` delegates to server. |
1580
+ | `browserFallback` | `boolean?` | When provider is `'runtype'`, fall back to browser TTS for text-typed responses. Default: `false`. |
1581
+ | `voice` | `string?` | Browser TTS voice name (e.g. `'Google US English'`). |
1582
+ | `pickVoice` | `(voices: SpeechSynthesisVoice[]) => SpeechSynthesisVoice?` | Custom voice picker when `voice` is not set. |
1583
+ | `rate` | `number?` | Speech rate (0.1–10). Default: `1`. |
1584
+ | `pitch` | `number?` | Speech pitch (0–2). Default: `1`. |
1585
+
1586
+ ```typescript
1587
+ config: {
1588
+ textToSpeech: {
1589
+ enabled: true,
1590
+ provider: 'browser',
1591
+ voice: 'Google US English',
1592
+ rate: 1.2,
1593
+ pitch: 1.0
1594
+ }
1595
+ }
1596
+ ```
1597
+
1598
+ #### Tool Calls & Approvals
1599
+
1600
+ | Option | Type | Description |
1601
+ | --- | --- | --- |
1602
+ | `toolCall` | `AgentWidgetToolCallConfig` | Styling for tool call bubbles: `backgroundColor`, `borderColor`, `borderWidth`, `borderRadius`, `headerBackgroundColor`, `headerTextColor`, `contentBackgroundColor`, `contentTextColor`, `codeBlockBackgroundColor`, `codeBlockBorderColor`, `codeBlockTextColor`, `toggleTextColor`, `labelTextColor`, and padding options. |
1603
+ | `approval` | `AgentWidgetApprovalConfig \| false` | Tool approval bubble configuration. Set to `false` to disable built-in approval handling. |
1604
+
1605
+ **`approval`** — `AgentWidgetApprovalConfig`
1606
+
1607
+ | Property | Type | Description |
1608
+ | --- | --- | --- |
1609
+ | `title` | `string?` | Title text above the description. |
1610
+ | `approveLabel` | `string?` | Label for the approve button. |
1611
+ | `denyLabel` | `string?` | Label for the deny button. |
1612
+ | `backgroundColor`, `borderColor`, `titleColor`, `descriptionColor` | `string?` | Bubble styling. |
1613
+ | `approveButtonColor`, `approveButtonTextColor` | `string?` | Approve button styling. |
1614
+ | `denyButtonColor`, `denyButtonTextColor` | `string?` | Deny button styling. |
1615
+ | `parameterBackgroundColor`, `parameterTextColor` | `string?` | Parameters block styling. |
1616
+ | `onDecision` | `(data, decision) => Promise<Response \| ReadableStream \| void>?` | Custom approval handler. Return `void` for SDK auto-resolve. |
1617
+
1618
+ #### Suggestion Chips
1619
+
1278
1620
  | Option | Type | Description |
1279
1621
  | --- | --- | --- |
1280
- | `apiUrl` | `string` | Proxy endpoint for your chat backend (defaults to Runtype's cloud API). |
1281
- | `flowId` | `string` | Optional Runtype flow ID. If provided, the client sends it to the proxy which can use it to select a specific flow. |
1282
- | `headers` | `Record<string, string>` | Extra headers forwarded to your proxy. |
1283
- | `copy` | `{ welcomeTitle?, welcomeSubtitle?, inputPlaceholder?, sendButtonLabel? }` | Customize user-facing text. |
1284
- | `theme` | `{ primary?, secondary?, surface?, muted?, accent?, radiusSm?, radiusMd?, radiusLg?, radiusFull? }` | Override CSS variables for the widget. Colors: `primary` (text/UI), `secondary` (unused), `surface` (backgrounds), `muted` (secondary text), `accent` (buttons/links). Border radius: `radiusSm` (0.75rem, inputs), `radiusMd` (1rem, cards), `radiusLg` (1.5rem, panels/bubbles), `radiusFull` (9999px, pills/buttons). |
1285
- | `features` | `AgentWidgetFeatureFlags` | Toggle UI features: `showReasoning?` (show thinking bubbles, default: `true`), `showToolCalls?` (show tool usage bubbles, default: `true`), `showEventStreamToggle?` (show event stream inspector toggle in header, default: `false`). |
1286
- | `autoFocusInput` | `boolean` | When `true`, focus the chat input after the panel opens and the open animation completes. Applies to launcher mode (user click, `controller.open()`, `autoExpand`) and inline mode (on init). Skips when voice is active. Default: `false`. |
1287
- | `launcher` | `{ enabled?, autoExpand?, title?, subtitle?, iconUrl?, position? }` | Controls the floating launcher button. |
1288
- | `initialMessages` | `AgentWidgetMessage[]` | Seed the conversation transcript. |
1289
1622
  | `suggestionChips` | `string[]` | Render quick reply buttons above the composer. |
1290
- | `postprocessMessage` | `(ctx) => string` | Transform message text before it renders (return HTML). Combine with `markdownPostprocessor` for rich output. |
1291
- | `parserType` | `"plain" \| "json" \| "regex-json" \| "xml"` | Built-in parser type selector. Easy way to choose a parser without importing functions. Options: `"plain"` (default), `"json"` (partial-json), `"regex-json"` (regex-based), `"xml"`. If both `parserType` and `streamParser` are provided, `streamParser` takes precedence. |
1292
- | `streamParser` | `() => AgentWidgetStreamParser` | Custom stream parser for detecting formats and extracting text from streaming responses. Handles JSON, XML, or custom formats. See [Stream Parser Configuration](#stream-parser-configuration) below. |
1293
- | `clearChatHistoryStorageKey` | `string` | Additional localStorage key to clear when the clear chat button is clicked. The widget automatically clears `"persona-chat-history"` by default. Use this option to clear additional keys (e.g., if you're using a custom storage key). |
1294
- | `formEndpoint` | `string` | Endpoint used by built-in directives (defaults to `/form`). |
1295
- | `launcherWidth` | `string` | CSS width applied to the floating launcher panel (e.g. `320px`, `90vw`). Defaults to `min(400px, calc(100vw - 24px))`. |
1296
- | `debug` | `boolean` | Emits verbose logs to `console`. |
1623
+ | `suggestionChipsConfig` | `AgentWidgetSuggestionChipsConfig` | Chip styling: `fontFamily` (`'sans-serif' \| 'serif' \| 'mono'`), `fontWeight`, `paddingX`, `paddingY`. |
1297
1624
 
1298
- All options are safe to mutate via `initAgentWidget(...).update(newConfig)`.
1625
+ #### Input & Composer
1626
+
1627
+ | Option | Type | Description |
1628
+ | --- | --- | --- |
1629
+ | `sendButton` | `AgentWidgetSendButtonConfig` | Send button customization: `borderWidth`, `borderColor`, `paddingX`, `paddingY`, `iconText`, `iconName`, `useIcon`, `tooltipText`, `showTooltip`, `backgroundColor`, `textColor`, `size`. |
1630
+ | `attachments` | `AgentWidgetAttachmentsConfig` | File attachment configuration (see sub-table). |
1631
+ | `formEndpoint` | `string` | Endpoint used by built-in directives. Default: `'/form'`. |
1632
+
1633
+ **`attachments`** — `AgentWidgetAttachmentsConfig`
1634
+
1635
+ | Property | Type | Description |
1636
+ | --- | --- | --- |
1637
+ | `enabled` | `boolean?` | Enable file attachments. Default: `false`. |
1638
+ | `allowedTypes` | `string[]?` | Allowed MIME types. Default: `['image/png', 'image/jpeg', 'image/gif', 'image/webp']`. |
1639
+ | `maxFileSize` | `number?` | Maximum file size in bytes. Default: `10485760` (10 MB). |
1640
+ | `maxFiles` | `number?` | Maximum files per message. Default: `4`. |
1641
+ | `buttonIconName` | `string?` | Lucide icon name. Default: `'image-plus'`. |
1642
+ | `buttonTooltipText` | `string?` | Tooltip text. Default: `'Attach image'`. |
1643
+ | `onFileRejected` | `(file, reason: 'type' \| 'size' \| 'count') => void?` | Callback when a file is rejected. |
1644
+
1645
+ #### Status Indicator
1646
+
1647
+ | Option | Type | Description |
1648
+ | --- | --- | --- |
1649
+ | `statusIndicator` | `AgentWidgetStatusIndicatorConfig` | Connection status display: `visible`, `idleText`, `connectingText`, `connectedText`, `errorText`. |
1650
+
1651
+ #### Features
1652
+
1653
+ | Option | Type | Description |
1654
+ | --- | --- | --- |
1655
+ | `features` | `AgentWidgetFeatureFlags` | Feature flag toggles (see sub-table). |
1656
+
1657
+ **`features`** — `AgentWidgetFeatureFlags`
1658
+
1659
+ | Property | Type | Description |
1660
+ | --- | --- | --- |
1661
+ | `showReasoning` | `boolean?` | Show thinking/reasoning bubbles. Default: `true`. |
1662
+ | `showToolCalls` | `boolean?` | Show tool usage bubbles. Default: `true`. |
1663
+ | `showEventStreamToggle` | `boolean?` | Show the event stream inspector toggle in the header. Default: `false`. |
1664
+ | `eventStream` | `EventStreamConfig?` | Event stream inspector configuration: `badgeColors`, `timestampFormat`, `showSequenceNumbers`, `maxEvents`, `descriptionFields`, `classNames`. |
1665
+
1666
+ #### State & Storage
1667
+
1668
+ | Option | Type | Description |
1669
+ | --- | --- | --- |
1670
+ | `initialMessages` | `AgentWidgetMessage[]` | Seed the conversation transcript with initial messages. |
1671
+ | `persistState` | `boolean \| AgentWidgetPersistStateConfig` | Persist widget state across page navigations. `true` uses defaults (sessionStorage). |
1672
+ | `storageAdapter` | `AgentWidgetStorageAdapter` | Custom storage adapter with `load()`, `save(state)`, and `clear()` methods. |
1673
+ | `onStateLoaded` | `(state: AgentWidgetStoredState) => AgentWidgetStoredState` | Transform state after loading from storage but before widget initialization. |
1674
+ | `clearChatHistoryStorageKey` | `string` | Additional localStorage key to clear on chat reset. The widget clears `"persona-chat-history"` by default. |
1675
+
1676
+ **`persistState`** — `AgentWidgetPersistStateConfig`
1677
+
1678
+ | Property | Type | Description |
1679
+ | --- | --- | --- |
1680
+ | `storage` | `'local' \| 'session'?` | Storage type. Default: `'session'`. |
1681
+ | `keyPrefix` | `string?` | Prefix for storage keys. Default: `'persona-'`. |
1682
+ | `persist.openState` | `boolean?` | Persist widget open/closed state. Default: `true`. |
1683
+ | `persist.voiceState` | `boolean?` | Persist voice recognition state. Default: `true`. |
1684
+ | `persist.focusInput` | `boolean?` | Focus input when restoring open state. Default: `true`. |
1685
+ | `clearOnChatClear` | `boolean?` | Clear persisted state when chat is cleared. Default: `true`. |
1686
+
1687
+ #### Extensibility
1688
+
1689
+ | Option | Type | Description |
1690
+ | --- | --- | --- |
1691
+ | `plugins` | `AgentWidgetPlugin[]` | Plugin array for extending widget functionality. |
1692
+ | `contextProviders` | `AgentWidgetContextProvider[]` | Functions that inject additional context into each request payload. |
1693
+ | `requestMiddleware` | `AgentWidgetRequestMiddleware` | Transform the request payload before it is sent. |
1694
+ | `actionParsers` | `AgentWidgetActionParser[]` | Parse structured directives from assistant messages. |
1695
+ | `actionHandlers` | `AgentWidgetActionHandler[]` | Handle parsed actions (navigation, UI updates, etc.). |
1299
1696
 
1300
1697
  ### Stream Parser Configuration
1301
1698