@runtypelabs/persona 4.17.1 → 4.18.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.
Files changed (158) hide show
  1. package/dist/chunk-3I2S3I5P.js +1 -0
  2. package/dist/chunk-76IELU7F.js +1 -0
  3. package/dist/chunk-EFJBUH5F.js +1 -0
  4. package/dist/chunk-PDPVORUF.js +1 -0
  5. package/dist/chunk-Q735PSZL.js +1 -0
  6. package/dist/chunk-VK6JOIYJ.js +1 -0
  7. package/dist/codegen.cjs +4 -4
  8. package/dist/codegen.js +4 -4
  9. package/dist/{context-mentions-BTSTIBFC.js → context-mentions-MJL6S6P2.js} +1 -1
  10. package/dist/context-mentions.cjs +9 -8
  11. package/dist/context-mentions.d.cts +1212 -14
  12. package/dist/context-mentions.d.ts +1212 -14
  13. package/dist/context-mentions.js +9 -8
  14. package/dist/event-stream-view-4EZ7BGFK.js +1 -0
  15. package/dist/event-stream-view.cjs +129 -0
  16. package/dist/event-stream-view.d.cts +8384 -0
  17. package/dist/event-stream-view.d.ts +8384 -0
  18. package/dist/event-stream-view.js +129 -0
  19. package/dist/history-view-BD6OXLNA.js +898 -0
  20. package/dist/history-view.cjs +898 -0
  21. package/dist/history-view.d.cts +1461 -0
  22. package/dist/history-view.d.ts +1461 -0
  23. package/dist/history-view.js +898 -0
  24. package/dist/index.cjs +77 -77
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +1987 -17
  27. package/dist/index.d.ts +1987 -17
  28. package/dist/index.global.js +67 -66
  29. package/dist/index.global.js.map +1 -1
  30. package/dist/index.js +77 -77
  31. package/dist/index.js.map +1 -1
  32. package/dist/launcher.global.js +5 -4
  33. package/dist/launcher.global.js.map +1 -1
  34. package/dist/plugin-kit.cjs +1 -1
  35. package/dist/plugin-kit.d.cts +0 -8
  36. package/dist/plugin-kit.d.ts +0 -8
  37. package/dist/plugin-kit.js +1 -1
  38. package/dist/smart-dom-reader.d.cts +1212 -14
  39. package/dist/smart-dom-reader.d.ts +1212 -14
  40. package/dist/theme-editor-preview.cjs +970 -73
  41. package/dist/theme-editor-preview.d.cts +1331 -15
  42. package/dist/theme-editor-preview.d.ts +1331 -15
  43. package/dist/theme-editor-preview.js +81 -81
  44. package/dist/theme-editor.cjs +7 -7
  45. package/dist/theme-editor.d.cts +1215 -15
  46. package/dist/theme-editor.d.ts +1215 -15
  47. package/dist/theme-editor.js +9 -9
  48. package/dist/theme-reference.cjs +1 -1
  49. package/dist/theme-reference.d.cts +226 -7
  50. package/dist/theme-reference.d.ts +226 -7
  51. package/dist/theme-reference.js +1 -1
  52. package/dist/widget.css +1 -1
  53. package/package.json +16 -4
  54. package/src/client-history-rest.test.ts +1034 -0
  55. package/src/client-visitor-history.test.ts +596 -0
  56. package/src/client.ts +1040 -24
  57. package/src/components/artifact-inline.ts +8 -1
  58. package/src/components/artifact-pane.test.ts +278 -1
  59. package/src/components/artifact-pane.ts +135 -67
  60. package/src/components/artifact-preview.test.ts +14 -1
  61. package/src/components/artifact-preview.ts +9 -0
  62. package/src/components/header-builder.ts +3 -0
  63. package/src/components/header-layouts.test.ts +171 -7
  64. package/src/components/header-layouts.ts +83 -53
  65. package/src/components/header-parts.test.ts +154 -1
  66. package/src/components/header-parts.ts +266 -138
  67. package/src/components/history-confirm-dialog.ts +177 -0
  68. package/src/components/history-shell-copy.ts +99 -0
  69. package/src/components/history-view/announcer.ts +40 -0
  70. package/src/components/history-view/copy.ts +105 -0
  71. package/src/components/history-view/css.ts +1078 -0
  72. package/src/components/history-view/grouping.test.ts +142 -0
  73. package/src/components/history-view/grouping.ts +142 -0
  74. package/src/components/history-view/icons.ts +73 -0
  75. package/src/components/history-view/rows.ts +341 -0
  76. package/src/components/history-view/state.ts +309 -0
  77. package/src/components/history-view.test.ts +2660 -0
  78. package/src/components/history-view.ts +1891 -0
  79. package/src/components/launcher-surface.test.ts +133 -0
  80. package/src/components/launcher.test.ts +18 -0
  81. package/src/components/launcher.ts +7 -7
  82. package/src/components/panel.ts +17 -7
  83. package/src/components/welcome.ts +72 -2
  84. package/src/defaults.ts +36 -3
  85. package/src/event-stream-view-bundle.test.ts +69 -0
  86. package/src/event-stream-view-entry.ts +19 -0
  87. package/src/event-stream-view-loader.ts +31 -0
  88. package/src/event-stream-view.ts +19 -0
  89. package/src/generated/runtype-openapi-contract.ts +1 -0
  90. package/src/history-render.ts +325 -0
  91. package/src/history-view-bundle.test.ts +78 -0
  92. package/src/history-view-entry.ts +41 -0
  93. package/src/history-view-loader.test.ts +30 -0
  94. package/src/history-view-loader.ts +32 -0
  95. package/src/history-view.ts +28 -0
  96. package/src/index-core.ts +50 -2
  97. package/src/index-global.ts +55 -0
  98. package/src/internal/demo-history-provider.test.ts +402 -0
  99. package/src/internal/demo-history-provider.ts +689 -0
  100. package/src/internal/history-provider-registry.ts +25 -0
  101. package/src/internal/history-provider.ts +150 -0
  102. package/src/internal/runtype-history-provider.test.ts +313 -0
  103. package/src/internal/runtype-history-provider.ts +240 -0
  104. package/src/plugin-kit.test.ts +16 -0
  105. package/src/plugin-kit.ts +13 -5
  106. package/src/plugins/types.ts +177 -1
  107. package/src/session-history.test.ts +1397 -0
  108. package/src/session.ts +1200 -26
  109. package/src/styles/widget-styles.test.ts +133 -0
  110. package/src/styles/widget.css +227 -8
  111. package/src/theme-editor/preview-utils.test.ts +19 -0
  112. package/src/theme-editor/preview-utils.ts +15 -1
  113. package/src/theme-editor/preview.ts +7 -1
  114. package/src/theme-editor/role-mappings.ts +4 -1
  115. package/src/theme-editor/sections.test.ts +168 -1
  116. package/src/theme-editor/sections.ts +136 -7
  117. package/src/theme-editor/webmcp/summary.ts +16 -2
  118. package/src/theme-reference.ts +20 -6
  119. package/src/types/theme.ts +213 -7
  120. package/src/types.ts +927 -7
  121. package/src/ui.artifact-rail-resize.test.ts +235 -0
  122. package/src/ui.attachments-drop.test.ts +1 -0
  123. package/src/ui.header-update-stability.test.ts +2 -2
  124. package/src/ui.history-chunk.test.ts +72 -0
  125. package/src/ui.history-config-provider.test.ts +318 -0
  126. package/src/ui.history-controller.test.ts +711 -0
  127. package/src/ui.history-lifecycle.test.ts +456 -0
  128. package/src/ui.history-render-hooks.test.ts +904 -0
  129. package/src/ui.history-shell.test.ts +1887 -0
  130. package/src/ui.rail-overlay.test.ts +573 -0
  131. package/src/ui.rail-resize.test.ts +284 -0
  132. package/src/ui.rebuild-composer.test.ts +21 -0
  133. package/src/ui.render-welcome.test.ts +42 -0
  134. package/src/ui.shortcuts.test.ts +166 -0
  135. package/src/ui.ts +3071 -240
  136. package/src/utils/__fixtures__/client-conversation-history-wire.json +108 -0
  137. package/src/utils/artifact-file.ts +15 -0
  138. package/src/utils/artifact-gate.test.ts +4 -0
  139. package/src/utils/artifact-gate.ts +13 -17
  140. package/src/utils/artifact-resize.test.ts +28 -0
  141. package/src/utils/artifact-resize.ts +9 -2
  142. package/src/utils/buttons.ts +188 -1
  143. package/src/utils/config-merge.test.ts +91 -0
  144. package/src/utils/dropdown.ts +10 -1
  145. package/src/utils/history-messages.test.ts +284 -0
  146. package/src/utils/history-messages.ts +284 -0
  147. package/src/utils/icons.ts +3 -0
  148. package/src/utils/shortcuts.test.ts +288 -0
  149. package/src/utils/shortcuts.ts +221 -0
  150. package/src/utils/theme.test.ts +501 -4
  151. package/src/utils/theme.ts +42 -3
  152. package/src/utils/tokens.ts +153 -15
  153. package/src/utils/tooltip-timing.ts +4 -0
  154. package/src/utils/tooltip.test.ts +249 -7
  155. package/src/utils/tooltip.ts +146 -4
  156. package/src/utils/visitor-store.test.ts +425 -0
  157. package/src/utils/visitor-store.ts +337 -0
  158. package/dist/chunk-QJ4LV2KW.js +0 -1
@@ -21,6 +21,8 @@ interface AgentWidgetPluginStorage {
21
21
  remove: (key: string) => void;
22
22
  }
23
23
 
24
+ type ShortcutScope = "widget" | "page";
25
+
24
26
  type AgentWidgetTransformSuggestionsContext = {
25
27
  /**
26
28
  * Fresh copy of the suggestions entering this plugin, already normalized:
@@ -69,6 +71,37 @@ type AgentWidgetRenderWelcomeContext = {
69
71
  /** Teardown for this render; runs before the next one and on destroy. */
70
72
  onCleanup: (fn: () => void) => void;
71
73
  };
74
+ /** Context for one `railSections` entry. Frozen per invocation. */
75
+ type AgentWidgetRailSectionContext = {
76
+ /** Current rail width state. The section re-renders whenever this flips. */
77
+ collapsed: boolean;
78
+ presentation: ResolvedHistoryPresentation;
79
+ /** The same frozen action path the default rows and `renderHistoryView` use. */
80
+ actions: AgentWidgetHistoryRenderActions;
81
+ };
82
+ /** A plugin-contributed navigation section in the history rail. */
83
+ type AgentWidgetRailSection = {
84
+ /** Stable identity, stamped as `data-persona-rail-section`. */
85
+ id: string;
86
+ /** Default `"above-conversations"`. */
87
+ placement?: AgentWidgetHistoryRailSection["placement"];
88
+ /** Optional heading, styled like a conversation date-group heading. */
89
+ title?: string;
90
+ /** Section body. Null renders nothing for the current state. */
91
+ render: (context: AgentWidgetRailSectionContext) => Element | null;
92
+ };
93
+ /** A plugin-contributed keyboard shortcut, bound per widget instance. */
94
+ type AgentWidgetPluginShortcut = {
95
+ /** Stable identity, used in duplicate/throw warnings. */
96
+ id: string;
97
+ /** e.g. `"mod+b"`. "mod" is Command on Apple platforms, Control elsewhere. */
98
+ combo: string;
99
+ /** Default `"widget"`: fires only from inside the widget mount. */
100
+ scope?: ShortcutScope;
101
+ /** Returning false skips the binding for this keypress. */
102
+ when?: () => boolean;
103
+ run: () => void;
104
+ };
72
105
  type AgentWidgetSuggestionSelectContext = {
73
106
  suggestion: AgentWidgetResolvedSuggestion;
74
107
  surface: AgentWidgetSuggestionSurface;
@@ -339,6 +372,10 @@ interface AgentWidgetPlugin {
339
372
  * Custom renderer for loading indicator
340
373
  * Return null to use default renderer (or config-based renderer)
341
374
  *
375
+ * Covers the streaming indicator ('inline', 'standalone') and the transcript
376
+ * skeleton shown while a conversation opened from the Messages list loads
377
+ * ('conversation-open').
378
+ *
342
379
  * @example
343
380
  * ```typescript
344
381
  * renderLoadingIndicator: ({ location, defaultRenderer }) => {
@@ -390,6 +427,118 @@ interface AgentWidgetPlugin {
390
427
  * Return null to use default renderer.
391
428
  */
392
429
  renderEventStreamPayload?: (context: EventStreamPayloadRenderContext) => HTMLElement | null;
430
+ /**
431
+ * Replace the complete history ("Messages") navigation contents in either
432
+ * host. Plugins run by priority and the first non-null element wins; null
433
+ * falls through to the default full view, which then applies the first
434
+ * non-null header/row/state hook at each slot.
435
+ *
436
+ * Calling `defaultRenderer()` bypasses this hook only: the default view is
437
+ * built and its lower-level slots still arbitrate, including this plugin's.
438
+ * Return it (or an element containing it) to compose rather than replace.
439
+ *
440
+ * The hook replaces contents, not orchestration. Persona keeps placement,
441
+ * open/close, responsive rail <-> panel movement, inertness, Escape, the
442
+ * confirmation dialogs, live announcements, and focus fallback. Fetch nothing
443
+ * directly: `actions.refresh()` is the only way to reload the list.
444
+ *
445
+ * @example
446
+ * ```typescript
447
+ * renderHistoryView: ({ conversations, actions, presentation, onCleanup }) => {
448
+ * const rail = document.createElement("nav");
449
+ * rail.dataset.presentation = presentation;
450
+ * for (const conversation of conversations) {
451
+ * const row = document.createElement("button");
452
+ * row.textContent = conversation.title;
453
+ * row.addEventListener("click", () => void actions.openConversation(conversation.id));
454
+ * rail.appendChild(row);
455
+ * }
456
+ * const timer = setInterval(() => void actions.refresh(), 60_000);
457
+ * onCleanup(() => clearInterval(timer));
458
+ * return rail;
459
+ * }
460
+ * ```
461
+ */
462
+ renderHistoryView?: (context: AgentWidgetRenderHistoryViewContext) => HTMLElement | null;
463
+ /**
464
+ * Replace the standard Messages header while retaining its list/state UI.
465
+ * Return null to use the default top bar. A custom header may not remove the
466
+ * keyboard close path or falsify the resolved open state.
467
+ */
468
+ renderHistoryHeader?: (context: AgentWidgetRenderHistoryHeaderContext) => HTMLElement | null;
469
+ /**
470
+ * Replace one conversation row while retaining standard paging/grouping.
471
+ * Return null to use the default row.
472
+ */
473
+ renderHistoryConversation?: (context: AgentWidgetRenderHistoryConversationContext) => HTMLElement | null;
474
+ /**
475
+ * Replace loading, empty, error, authentication, rate-limit, or recovery
476
+ * content in the list region. Return null to use the default block.
477
+ */
478
+ renderHistoryState?: (context: AgentWidgetRenderHistoryStateContext) => HTMLElement | null;
479
+ /**
480
+ * Replace the transcript-level error surface shown when opening a
481
+ * conversation from the Messages list fails. Plugins run by priority and
482
+ * the first non-null element wins; null falls through to the default block.
483
+ *
484
+ * Persona keeps the centered transcript column, the alert role, and the
485
+ * composer gate around the returned element. `retry`/`back` are the only
486
+ * exits: both route through the token-guarded open flow, so do not fetch
487
+ * directly. `back` is absent when there is no Messages surface to return
488
+ * to; do not render a back affordance without it.
489
+ */
490
+ renderHistoryOpenError?: (context: AgentWidgetRenderHistoryOpenErrorContext) => HTMLElement | null;
491
+ /**
492
+ * Contribute navigation sections to the history rail, stacked around the
493
+ * conversation list in `placement` order. Rail only: the panel presentation
494
+ * renders none of them, and `features.history.rail.sections` (config) comes
495
+ * first inside each bucket, then plugins in plugin order.
496
+ *
497
+ * `render` is re-invoked with the new `collapsed` value whenever the rail
498
+ * collapses or expands, and its return replaces the previous content;
499
+ * returning null renders nothing for that state. A throwing `render` warns
500
+ * once and drops that section only, leaving the rest of the rail alone. An id
501
+ * a config section already owns is dropped with a warning.
502
+ *
503
+ * Keep heavy UI in the host bundle: `render` may return a skeleton and
504
+ * hydrate it after the host's own dynamic import resolves.
505
+ *
506
+ * @example
507
+ * ```typescript
508
+ * railSections: [
509
+ * {
510
+ * id: "pinned",
511
+ * title: "Pinned",
512
+ * render: ({ collapsed, actions }) => {
513
+ * if (collapsed) return null;
514
+ * const list = document.createElement("div");
515
+ * const row = document.createElement("button");
516
+ * row.textContent = "Weekly report";
517
+ * row.addEventListener("click", () => void actions.openConversation("c1"));
518
+ * list.appendChild(row);
519
+ * return list;
520
+ * }
521
+ * }
522
+ * ]
523
+ * ```
524
+ */
525
+ railSections?: AgentWidgetRailSection[];
526
+ /**
527
+ * Keyboard shortcuts registered for the lifetime of each widget instance the
528
+ * plugin is active in, and unregistered on its teardown. `combo` is written
529
+ * as `"mod+b"` / `"mod+shift+k"`, where "mod" is Command on Apple platforms
530
+ * and Control elsewhere. `scope` defaults to `"widget"` (only while focus is
531
+ * inside the mount); `when` returning false skips the keypress. A combo
532
+ * another binding already owns warns and is ignored, first registration wins.
533
+ *
534
+ * @example
535
+ * ```typescript
536
+ * shortcuts: [
537
+ * { id: "open-inbox", combo: "mod+shift+i", run: () => openInbox() }
538
+ * ]
539
+ * ```
540
+ */
541
+ shortcuts?: AgentWidgetPluginShortcut[];
393
542
  /**
394
543
  * Called when plugin is registered
395
544
  */
@@ -548,6 +697,10 @@ interface SemanticTokens {
548
697
  }
549
698
  interface ComponentTokenSet {
550
699
  background?: TokenReference<'color'>;
700
+ /**
701
+ * Text and glyph color on `background`. `HeaderTokens` also derives its
702
+ * unset text, icon, and border colors from this pair.
703
+ */
551
704
  foreground?: TokenReference<'color'>;
552
705
  border?: TokenReference<'color'>;
553
706
  borderRadius?: TokenReference<'radius'>;
@@ -575,6 +728,15 @@ interface LauncherTokens extends ComponentTokenSet {
575
728
  size: string;
576
729
  iconSize: string;
577
730
  shadow: TokenReference<'shadow'>;
731
+ /**
732
+ * Stroke weight of the launcher glyphs, the agent icon and the
733
+ * call-to-action arrow alike. Unitless, and must be a STRING (`"1.75"`,
734
+ * never `1.75`: the token resolver silently skips numbers). Applied as CSS,
735
+ * so it beats the attribute the icons render with. Inert for emoji / image
736
+ * launchers, which have no svg.
737
+ * @default "1.5", matching the header's controlStrokeWidth
738
+ */
739
+ iconStrokeWidth?: string;
578
740
  }
579
741
  interface PanelTokens extends ComponentTokenSet {
580
742
  width: string;
@@ -595,28 +757,212 @@ interface TextStyleTokens {
595
757
  letterSpacing?: string;
596
758
  color?: TokenReference<'color'>;
597
759
  }
760
+ /**
761
+ * Header band tokens. `background` plus `foreground` (inherited from
762
+ * `ComponentTokenSet`) is the pair that colors the band: `foreground` anchors
763
+ * the header text, and every text, action-icon, and border color the theme
764
+ * leaves unset derives from the pair. Derivation only fills unset keys, so an
765
+ * explicit key always wins, and `iconBackground` / `iconForeground` (the avatar
766
+ * tile) keep their own defaults rather than deriving.
767
+ */
598
768
  interface HeaderTokens extends ComponentTokenSet {
599
769
  background: TokenReference<'color'>;
600
- border: TokenReference<'color'>;
770
+ /**
771
+ * Hairline under the header. Unset, it derives as
772
+ * `color-mix(in srgb, foreground 14%, background)`, then the divider color.
773
+ */
774
+ border?: TokenReference<'color'>;
601
775
  borderRadius: TokenReference<'radius'>;
602
776
  /** Background of the rounded avatar tile next to the title (Lucide / emoji / image). */
603
777
  iconBackground: TokenReference<'color'>;
604
778
  /** Foreground (glyph stroke or emoji text) on the header avatar tile. */
605
779
  iconForeground: TokenReference<'color'>;
606
- /** Legacy alias of `title.color`; `title.color` wins when both are set. */
607
- titleForeground: TokenReference<'color'>;
608
- /** Legacy alias of `subtitle.color`; `subtitle.color` wins when both are set. */
609
- subtitleForeground: TokenReference<'color'>;
780
+ /**
781
+ * Legacy alias of `title.color`; `title.color` wins when both are set.
782
+ * Unset, the title takes `foreground`, then the primary color.
783
+ */
784
+ titleForeground?: TokenReference<'color'>;
785
+ /**
786
+ * Legacy alias of `subtitle.color`; `subtitle.color` wins when both are set.
787
+ * Unset, the subtitle takes `color-mix(in srgb, foreground 72%, background)`,
788
+ * then the muted text color.
789
+ */
790
+ subtitleForeground?: TokenReference<'color'>;
610
791
  /** Header title typography (next to the icon, or minimal layout title). */
611
792
  title?: TextStyleTokens;
612
793
  /** Header subtitle typography, for the line under the title. */
613
794
  subtitle?: TextStyleTokens;
614
- /** Default color for clear / close icon buttons when launcher overrides are unset. */
615
- actionIconForeground: TokenReference<'color'>;
795
+ /**
796
+ * Default color for clear / close icon buttons when launcher overrides are
797
+ * unset. Itself unset, it takes the same
798
+ * `color-mix(in srgb, foreground 72%, background)` as the subtitle, then the
799
+ * muted text color.
800
+ */
801
+ actionIconForeground?: TokenReference<'color'>;
802
+ /**
803
+ * Edge of every header icon button: close, clear chat, `trailingActions`, and
804
+ * the Messages toggle. Per-control config keys (`launcher.closeButtonSize`,
805
+ * `launcher.clearChat.size`) still win. Coarse pointers floor the hit area at
806
+ * 40px regardless. @default "32px"
807
+ */
808
+ controlSize?: string;
809
+ /** Glyph box inside a header control. @default "20px" */
810
+ controlIconSize?: string;
811
+ /**
812
+ * Stroke weight of the glyph inside a header control. Unitless, as an SVG
813
+ * stroke-width (e.g. `"1.75"`). Sparse-viewBox glyphs (the close X) render
814
+ * at 0.7 of it so their heavier visible weight still matches a dense
815
+ * sibling. @default "1.5"
816
+ */
817
+ controlStrokeWidth?: string;
616
818
  /** Box-shadow on the header (e.g., a fade shadow to replace the default border). */
617
819
  shadow?: string;
618
820
  /** Override the header bottom border (e.g., `none`). */
619
821
  borderBottom?: string;
822
+ /**
823
+ * Floor for the header strip's height (e.g. `"56px"`). Pin it together with
824
+ * `components.history.railHeader.minHeight` so the Messages rail header and
825
+ * the conversation header read as one continuous band.
826
+ */
827
+ minHeight?: string;
828
+ }
829
+ /** Messages (conversation history) surfaces. */
830
+ interface HistoryTokens {
831
+ /**
832
+ * The Messages rail's own top strip, which runs beside the widget header
833
+ * when `features.history.presentation` resolves to `rail`.
834
+ */
835
+ railHeader?: {
836
+ /** Strip background. Defaults to the rail's surface color. */
837
+ background?: TokenReference<'color'>;
838
+ /** Full border-bottom shorthand (raw CSS, e.g. `"1px solid #e5e7eb"`). @default "0" */
839
+ border?: string;
840
+ /** Strip height floor. Defaults to `components.header.minHeight`, then 56px. */
841
+ minHeight?: string;
842
+ /**
843
+ * The strip's view title ("Messages"). 14px/600 in the text color by
844
+ * default; set the type keys to restyle it.
845
+ */
846
+ title?: TextStyleTokens;
847
+ };
848
+ /**
849
+ * The "Conversations" heading over the list block. Visible in rail
850
+ * presentation only (the panel keeps it screen-reader-only). 14px/600 in
851
+ * the text color by default. Every key is pinned in the widget CSS, so
852
+ * host-page heading rules never restyle it.
853
+ */
854
+ listHeading?: TextStyleTokens;
855
+ /**
856
+ * The muted sub-headers inside the Messages surface: date groups ("Today",
857
+ * "Yesterday") and rail nav section titles (`features.history.rail.sections`
858
+ * `title`, e.g. "Workspace"). 13px/500 in the muted text color in the rail
859
+ * (the panel keeps date groups screen-reader-only). Every key is pinned in
860
+ * the widget CSS, so host-page heading rules never restyle them.
861
+ */
862
+ groupHeading?: TextStyleTokens;
863
+ /**
864
+ * The floating rail that a collapsed
865
+ * `features.history.rail.collapsedBehavior: "overlay"` opens on hover. It
866
+ * hangs below the trigger in the conversation header; its width and edge
867
+ * stay `features.history.rail` geometry, not tokens.
868
+ */
869
+ overlay?: {
870
+ /** Gap from the trigger, the docked edge, and the bottom. @default "8px" */
871
+ margin?: string;
872
+ /** Corner radius, on all four corners. @default "16px" */
873
+ borderRadius?: string;
874
+ /** Elevation over the conversation. @default "0 12px 40px rgba(0, 0, 0, 0.25)" */
875
+ shadow?: string;
876
+ /** Surface behind the rail. Defaults to the rail's own surface color. */
877
+ background?: TokenReference<'color'>;
878
+ };
879
+ /**
880
+ * Destructive action text (row Delete, "Delete all conversations").
881
+ * Defaults to `palette.colors.error.600` in light schemes and a lighter
882
+ * red in the built-in dark theme so the 14px labels keep AA contrast.
883
+ */
884
+ dangerForeground?: TokenReference<'color'>;
885
+ /**
886
+ * The delete/forget confirmation dialog the shell shows for destructive
887
+ * history actions. The danger pair is always emitted (`--persona-danger`
888
+ * / `--persona-danger-fg`); scrim and shadow keep the built-in look when
889
+ * unset.
890
+ */
891
+ confirm?: {
892
+ /**
893
+ * Destructive button fill. Defaults to `palette.colors.error.700` in
894
+ * light schemes and `error.600` in the built-in dark theme.
895
+ */
896
+ dangerBackground?: TokenReference<'color'>;
897
+ /** Destructive button label. @default "#ffffff" */
898
+ dangerForeground?: TokenReference<'color'>;
899
+ /** Overlay behind the dialog. @default "rgba(15, 23, 42, 0.45)" */
900
+ scrim?: TokenReference<'color'>;
901
+ /** Card elevation (raw CSS shadow). */
902
+ shadow?: string;
903
+ };
904
+ /** The per-row overflow menu in the Messages list (rail and panel). */
905
+ menu?: {
906
+ /**
907
+ * Menu surface. Defaults to the list surface lifted 8% toward white so
908
+ * the menu reads as elevated in dark schemes.
909
+ */
910
+ background?: TokenReference<'color'>;
911
+ /** Corner radius. @default "12px" */
912
+ borderRadius?: string;
913
+ };
914
+ /**
915
+ * Enter/exit motion of the Messages surface. Only the body slides; the bar
916
+ * is persistent chrome and never animates. Durations are milliseconds and 0
917
+ * disables that leg; `prefers-reduced-motion` always wins over these.
918
+ */
919
+ motion?: {
920
+ /** Entrance slide-and-fade duration: bare ms number, or a CSS time string. @default 180 */
921
+ enterDurationMs?: number | string;
922
+ /** Entrance easing. @default "cubic-bezier(0, 0, 0.2, 1)" */
923
+ enterEasing?: string;
924
+ /** Exit slide-and-fade duration: bare ms number, or a CSS time string. @default 160 */
925
+ exitDurationMs?: number | string;
926
+ /** Exit easing. @default "cubic-bezier(0.4, 0, 1, 1)" */
927
+ exitEasing?: string;
928
+ };
929
+ }
930
+ /**
931
+ * The portaled icon-control tooltip (header controls, composer buttons) and
932
+ * its trailing shortcut hint chip. Unset keys keep the built-in dark look.
933
+ */
934
+ interface TooltipTokens {
935
+ /** Bubble and arrow fill. @default "#111827" */
936
+ background?: TokenReference<'color'>;
937
+ /** Label color. @default "#ffffff" */
938
+ foreground?: TokenReference<'color'>;
939
+ /** Trailing shortcut hint color. @default "rgba(255, 255, 255, 0.55)" */
940
+ hintForeground?: TokenReference<'color'>;
941
+ /** Bubble corner radius. Defaults to `palette.radius.sm`. */
942
+ borderRadius?: TokenReference<'radius'>;
943
+ /** Label type size. @default "12px" */
944
+ fontSize?: string;
945
+ /** Bubble inset, full CSS shorthand. @default "6px 12px" */
946
+ padding?: TokenReference<'spacing'>;
947
+ /** Bubble box-shadow (token ref or raw CSS, e.g. `none`). */
948
+ shadow?: string;
949
+ /** Render the caret pointing at the control. @default true */
950
+ arrow?: boolean;
951
+ /** Wrap width. @default "min(320px, calc(100vw - 16px))" */
952
+ maxWidth?: string;
953
+ }
954
+ /**
955
+ * The hover-revealed action row under a message (copy, vote, read aloud).
956
+ * Unset keys inherit the shared ghost icon-button wash, which is already
957
+ * scheme-aware, so most themes never need this group.
958
+ */
959
+ interface MessageActionsTokens {
960
+ /** Hover fill. Defaults to `components.button.ghost.hoverBackground`. */
961
+ hoverBackground?: TokenReference<'color'>;
962
+ /** Hover icon color. Defaults to `semantic.colors.text`. */
963
+ hoverForeground?: TokenReference<'color'>;
964
+ /** Button corner radius. Defaults to `palette.radius.md`. */
965
+ borderRadius?: TokenReference<'radius'>;
620
966
  }
621
967
  interface MessageTokens {
622
968
  user: {
@@ -962,7 +1308,13 @@ interface ComponentTokens {
962
1308
  launcher: LauncherTokens;
963
1309
  panel: PanelTokens;
964
1310
  header: HeaderTokens;
1311
+ /** Messages rail chrome. */
1312
+ history?: HistoryTokens;
1313
+ /** Portaled icon-control tooltip and its shortcut hint chip. */
1314
+ tooltip?: TooltipTokens;
965
1315
  message: MessageTokens;
1316
+ /** Hover-revealed per-message action row (copy, vote, read aloud). */
1317
+ messageActions?: MessageActionsTokens;
966
1318
  /** Welcome / intro card shown above the message list. */
967
1319
  introCard?: IntroCardTokens;
968
1320
  /** Markdown surfaces (chat + artifact pane). */
@@ -1461,6 +1813,101 @@ type TargetResolver = (id: string) => {
1461
1813
  payload: Record<string, unknown>;
1462
1814
  };
1463
1815
 
1816
+ /**
1817
+ * History provider seam (`docs/visitor-history-implementation-plan.md` D9).
1818
+ * Session/UI history code depends on this interface, never on
1819
+ * `AgentWidgetClient`.
1820
+ *
1821
+ * The module stays under `internal/` but its contract is public: `index-core.ts`
1822
+ * re-exports these declarations so integrators can implement
1823
+ * `features.history.provider`. The provider REGISTRY beside it stays private.
1824
+ */
1825
+
1826
+ /** Fixed for the lifetime of one opened history view/action chain. */
1827
+ interface HistoryOperationContext {
1828
+ scope: HistoryScope;
1829
+ }
1830
+ /**
1831
+ * An authorized-but-not-yet-applied conversation activation. The provider must
1832
+ * not mutate the active chat until `commit()`.
1833
+ */
1834
+ interface PreparedHistoryActivation {
1835
+ conversationId: string;
1836
+ conversationRevision: string;
1837
+ /** Apply the already-authorized provider-specific transport/session binding. */
1838
+ commit(): void | Promise<void>;
1839
+ /** Idempotently abandon a stale/superseded activation without changing chat. */
1840
+ discard(): void;
1841
+ }
1842
+ interface HistoryListOptions {
1843
+ cursor?: string;
1844
+ limit?: number;
1845
+ targetId?: string;
1846
+ context: HistoryOperationContext;
1847
+ }
1848
+ interface HistoryListResult {
1849
+ items: HistoryConversationSummary[];
1850
+ nextCursor: string | null;
1851
+ }
1852
+ interface HistoryPageOptions {
1853
+ cursor?: string;
1854
+ /** Lets the provider synthesize stable timestamps across page boundaries. */
1855
+ beforeCreatedAt?: string;
1856
+ context: HistoryOperationContext;
1857
+ }
1858
+ interface HistoryPageResult {
1859
+ summary: HistoryConversationSummary;
1860
+ /** Already mapped; the visitor-visible projection lives in `content`. */
1861
+ messages: AgentWidgetMessage[];
1862
+ conversationRevision: string;
1863
+ /** Follow for the next older page. `null` at the start of the transcript. */
1864
+ nextCursor: string | null;
1865
+ }
1866
+ interface HistoryDeleteAllOptions {
1867
+ /** Absent means the whole authorized scope, never the UI default. */
1868
+ targetId?: string;
1869
+ context: HistoryOperationContext;
1870
+ }
1871
+ /** The contract a `features.history.provider` implementation satisfies. */
1872
+ interface HistoryProvider {
1873
+ readonly capabilities: {
1874
+ scopes: readonly HistoryScope[];
1875
+ };
1876
+ getIdentityStatus(): HistoryIdentityStatus;
1877
+ subscribeIdentityStatus(callback: (status: HistoryIdentityStatus) => void): () => void;
1878
+ list(opts: HistoryListOptions): Promise<HistoryListResult>;
1879
+ getPage(id: string, opts: HistoryPageOptions): Promise<HistoryPageResult>;
1880
+ prepareOpen(id: string, opts: {
1881
+ context: HistoryOperationContext;
1882
+ }): Promise<PreparedHistoryActivation>;
1883
+ prepareStartNew(opts: {
1884
+ context: HistoryOperationContext;
1885
+ }): Promise<PreparedHistoryActivation>;
1886
+ delete(id: string, opts: {
1887
+ context: HistoryOperationContext;
1888
+ }): Promise<void>;
1889
+ deleteAll(opts: HistoryDeleteAllOptions): Promise<{
1890
+ deleted: number;
1891
+ }>;
1892
+ /**
1893
+ * Optional capability: visitor-scoped rename/star. Absence hides every
1894
+ * update affordance (star glyphs, built-in title-menu actions). A user-set
1895
+ * title pins: the provider must never let a later auto-generated title
1896
+ * overwrite one set through this call.
1897
+ */
1898
+ update?(id: string, patch: HistoryConversationPatch, opts: {
1899
+ context: HistoryOperationContext;
1900
+ }): Promise<HistoryConversationSummary>;
1901
+ /**
1902
+ * Optional capability. Absence hides "forget this device". Resolves (never
1903
+ * rejects) on remote failure; credentials are cleared in `finally` either way.
1904
+ */
1905
+ resetDevice?(): Promise<{
1906
+ remoteRevocationConfirmed: boolean;
1907
+ }>;
1908
+ subscribeAvailability?(callback: (available: boolean) => void): () => void;
1909
+ }
1910
+
1464
1911
  /**
1465
1912
  * Curated registry of lucide icons available to `renderLucideIcon`.
1466
1913
  *
@@ -1545,6 +1992,7 @@ declare const LUCIDE_ICONS: {
1545
1992
  readonly "ellipsis-vertical": IconNode;
1546
1993
  readonly menu: IconNode;
1547
1994
  readonly house: IconNode;
1995
+ readonly "panel-left": IconNode;
1548
1996
  readonly plus: IconNode;
1549
1997
  readonly minus: IconNode;
1550
1998
  readonly pencil: IconNode;
@@ -2656,6 +3104,59 @@ type AgentWidgetControllerEventMap = {
2656
3104
  executionId: string;
2657
3105
  after: string;
2658
3106
  };
3107
+ /**
3108
+ * History (Messages) surface events. Payloads are sanitized: never a visitor
3109
+ * token, identity proof, visitor/end-user id, or backend diagnostic string.
3110
+ */
3111
+ "history:opened": {
3112
+ presentation: ResolvedHistoryPresentation;
3113
+ returnSurface: HistoryReturnSurface;
3114
+ timestamp: number;
3115
+ };
3116
+ "history:closed": {
3117
+ returnSurface: HistoryReturnSurface;
3118
+ timestamp: number;
3119
+ };
3120
+ "history:conversationOpened": {
3121
+ conversationId: string;
3122
+ /** List title of the opened conversation; null when not yet known. */
3123
+ title: string | null;
3124
+ scope: HistoryScope;
3125
+ timestamp: number;
3126
+ };
3127
+ /**
3128
+ * A replacement conversation was committed (header action, in-panel "New
3129
+ * conversation", or `startNewConversation()`). `history:closed` alone cannot
3130
+ * distinguish this commit from a plain close.
3131
+ */
3132
+ "history:conversationStarted": {
3133
+ /** `null` when the provider committed without returning a record id. */
3134
+ conversationId: string | null;
3135
+ timestamp: number;
3136
+ };
3137
+ "history:conversationDeleted": {
3138
+ conversationId: string;
3139
+ scope: HistoryScope;
3140
+ /** The deleted record was the open one, so the transcript was replaced. */
3141
+ wasActive: boolean;
3142
+ timestamp: number;
3143
+ };
3144
+ "history:cleared": {
3145
+ deleted: number;
3146
+ scope: HistoryScope;
3147
+ /** `null` is a deliberate headless client-token-wide delete. */
3148
+ targetId: string | null;
3149
+ timestamp: number;
3150
+ };
3151
+ "history:identityReset": {
3152
+ remoteRevocationConfirmed: boolean;
3153
+ timestamp: number;
3154
+ };
3155
+ /** Deduped: emitted only when the discriminated state or reason changes. */
3156
+ "history:identityStatusChanged": {
3157
+ status: HistoryIdentityStatus;
3158
+ timestamp: number;
3159
+ };
2659
3160
  };
2660
3161
  /**
2661
3162
  * Layout for the artifact split / drawer (CSS lengths unless noted).
@@ -2796,6 +3297,8 @@ type AgentWidgetArtifactsLayoutConfig = {
2796
3297
  documentToolbarToggleActiveBackground?: string;
2797
3298
  /** Active view/source toggle border color. Sets `--persona-artifact-doc-toggle-active-border`. */
2798
3299
  documentToolbarToggleActiveBorderColor?: string;
3300
+ /** Active view/source toggle icon color (defaults to `documentToolbarIconColor`). Sets `--persona-artifact-doc-toggle-active-color`. */
3301
+ documentToolbarToggleActiveColor?: string;
2799
3302
  /** Show an expand/collapse toggle in the artifact toolbar (both presets). Expanded fills the widget with the pane and hides the chat column. Default: false. */
2800
3303
  showExpandToggle?: boolean;
2801
3304
  /** Show the copy control in the `default` toolbar preset (the `document` preset always shows it). Default: false. */
@@ -2808,13 +3311,20 @@ type AgentWidgetArtifactsLayoutConfig = {
2808
3311
  /** Tab fade width (CSS length). @default 24px */
2809
3312
  tabFadeSize?: string;
2810
3313
  /**
2811
- * Invoked when the document toolbar Refresh control is used (before the pane re-renders).
2812
- * Use to replay `connectStream`, refetch, etc.
3314
+ * Invoked when the document toolbar Refresh control is used (before the pane
3315
+ * re-renders). The button renders only while this handler is set: the refresh
3316
+ * glyph universally reads "reload this preview" (Claude artifacts, v0), so
3317
+ * keep the handler scoped to refreshing the rendered artifact — regenerating
3318
+ * content or resetting the conversation belongs to message-level or
3319
+ * conversation-level controls, not artifact chrome.
2813
3320
  */
2814
3321
  onDocumentToolbarRefresh?: () => void | Promise<void>;
2815
3322
  /**
2816
3323
  * Optional copy dropdown entries (shown when `documentToolbarShowCopyChevron` is true and this array is non-empty).
2817
3324
  * The main Copy control still performs default copy unless `onDocumentToolbarCopyMenuSelect` handles everything.
3325
+ * Without a handler, built-in ids work out of the box: `download` saves the
3326
+ * artifact (real filename/MIME for file artifacts, `<title>.md` otherwise);
3327
+ * `markdown`/`md` and `json`/`source` copy that form to the clipboard.
2818
3328
  */
2819
3329
  documentToolbarCopyMenuItems?: Array<{
2820
3330
  id: string;
@@ -2822,13 +3332,24 @@ type AgentWidgetArtifactsLayoutConfig = {
2822
3332
  }>;
2823
3333
  /**
2824
3334
  * When set, invoked for the chevron menu (and can override default copy per `actionId`).
3335
+ * Return `false` to fall through to the widget's built-in behavior for that
3336
+ * action id (`download` saves the artifact; copy ids copy); any other return
3337
+ * value keeps the handler's outcome as final.
2825
3338
  */
2826
3339
  onDocumentToolbarCopyMenuSelect?: (payload: {
2827
3340
  actionId: string;
2828
3341
  artifactId: string | null;
2829
3342
  markdown: string;
2830
3343
  jsonPayload: string;
2831
- }) => void | Promise<void>;
3344
+ /** File metadata when the selected artifact is a previewable file. */
3345
+ file?: PersonaArtifactFileMeta;
3346
+ /** Filename the built-in download would use (file basename, or `<title>.md`). */
3347
+ suggestedFilename: string;
3348
+ /** MIME type paired with `suggestedFilename`. */
3349
+ mime: string;
3350
+ /** Raw content the built-in download would write (unfenced source for file artifacts). */
3351
+ content: string;
3352
+ }) => void | boolean | Promise<void | boolean>;
2832
3353
  };
2833
3354
  /**
2834
3355
  * Where the artifact body renders by default. Every mode shows the compact
@@ -3671,6 +4192,11 @@ type AgentWidgetFeatureFlags = {
3671
4192
  * pills + optional free-text input.
3672
4193
  */
3673
4194
  askUserQuestion?: AgentWidgetAskUserQuestionFeature;
4195
+ /**
4196
+ * Per-visitor conversation history. Client token mode only; disabled by
4197
+ * default so no capability flag is sent on init and no UI mounts.
4198
+ */
4199
+ history?: AgentWidgetHistoryFeature;
3674
4200
  /**
3675
4201
  * Built-in `suggest_replies` follow-ups. When the assistant invokes the
3676
4202
  * tool, the widget shows the suggestions using `suggestions.followUps` and
@@ -3863,6 +4389,604 @@ type AgentWidgetAskUserQuestionFeature = {
3863
4389
  /** Style overrides for the sheet and pills. */
3864
4390
  styles?: AgentWidgetAskUserQuestionStyles;
3865
4391
  };
4392
+ /**
4393
+ * Copy overrides for the visitor-facing conversation history surface. These are
4394
+ * the widget's only localization mechanism for history, so every user-visible
4395
+ * history string is listed here.
4396
+ */
4397
+ interface AgentWidgetHistoryCopy {
4398
+ /** Title of the history view. Defaults to "Messages". */
4399
+ viewTitle?: string;
4400
+ /** Heading shown when the visitor has no stored conversations. */
4401
+ emptyTitle?: string;
4402
+ /** Body text shown when the visitor has no stored conversations. */
4403
+ emptyDescription?: string;
4404
+ /** Heading shown when a history request fails. */
4405
+ errorTitle?: string;
4406
+ /** Body text shown when a history request fails. */
4407
+ errorDescription?: string;
4408
+ /** Label for the retry action on the error state. */
4409
+ retryLabel?: string;
4410
+ /** Heading shown after a 429 rate-limited history response. */
4411
+ rateLimitedTitle?: string;
4412
+ /** Body text shown after a 429 rate-limited history response. */
4413
+ rateLimitedDescription?: string;
4414
+ /** Confirmation prompt before deleting a single conversation. */
4415
+ deleteConversationConfirm?: string;
4416
+ /** Confirmation prompt before deleting every conversation in the active scope. */
4417
+ clearHistoryConfirm?: string;
4418
+ /** Confirmation prompt before detaching this browser from its history identity. */
4419
+ resetIdentityConfirm?: string;
4420
+ /** Label for the action that starts a new server conversation. */
4421
+ newConversationLabel?: string;
4422
+ /** Label for the action that prepends the previous transcript page. */
4423
+ showEarlierMessagesLabel?: string;
4424
+ /** Accessible label for the transcript skeleton while a conversation loads. */
4425
+ openConversationLoadingLabel?: string;
4426
+ /** Body text when a selected conversation failed to load. */
4427
+ openConversationErrorTitle?: string;
4428
+ /** Label for the retry action after a conversation failed to load. */
4429
+ openConversationRetryLabel?: string;
4430
+ /** Label for the return-to-messages action after a conversation failed to load. */
4431
+ openConversationBackLabel?: string;
4432
+ /** Status notice after a deleted conversation was recovered into a fresh one. */
4433
+ conversationDeletedNotice?: string;
4434
+ /** Status notice after this browser was detached from its history identity. */
4435
+ identityResetNotice?: string;
4436
+ /** Status notice when a local reset succeeded but server revocation was unconfirmed. */
4437
+ identityResetUnconfirmedNotice?: string;
4438
+ /** Pinned group heading for starred conversations. */
4439
+ groupStarred?: string;
4440
+ /** Time-group heading for conversations updated today. */
4441
+ groupToday?: string;
4442
+ /** Time-group heading for conversations updated yesterday. */
4443
+ groupYesterday?: string;
4444
+ /** Time-group heading for the trailing 7-day window. */
4445
+ groupPrevious7Days?: string;
4446
+ /** Time-group heading for the trailing 30-day window. */
4447
+ groupPrevious30Days?: string;
4448
+ /** Time-group heading for older conversations, grouped by month and year. */
4449
+ groupMonthYear?: string;
4450
+ /** Scope title when history is limited to this browser. */
4451
+ browserOnlyTitle?: string;
4452
+ /** Scope description when history is limited to this browser. */
4453
+ browserOnlyDescription?: string;
4454
+ /** Scope title while an identity proof is being resolved. */
4455
+ verifyingTitle?: string;
4456
+ /** Scope description while an identity proof is being resolved. */
4457
+ verifyingDescription?: string;
4458
+ /** Scope title when history is available across signed-in devices. */
4459
+ verifiedTitle?: string;
4460
+ /** Scope description when history is available across signed-in devices. */
4461
+ verifiedDescription?: string;
4462
+ /** Scope title when the visitor must sign in again to view account history. */
4463
+ authenticationRequiredTitle?: string;
4464
+ /** Scope description when the visitor must sign in again to view account history. */
4465
+ authenticationRequiredDescription?: string;
4466
+ /** Scope title when the host identity provider threw or rejected. */
4467
+ identityProviderFailedTitle?: string;
4468
+ /** Scope description when the host identity provider threw or rejected. */
4469
+ identityProviderFailedDescription?: string;
4470
+ /** Scope title when the server did not admit a supplied identity proof. */
4471
+ proofNotAdmittedTitle?: string;
4472
+ /** Scope description when the server did not admit a supplied identity proof. */
4473
+ proofNotAdmittedDescription?: string;
4474
+ /** Label for the action that retries identity resolution. */
4475
+ retryIdentityLabel?: string;
4476
+ /** Accessible name of the header control that opens history. */
4477
+ openHistoryLabel?: string;
4478
+ /** Accessible name of that control while a turn is streaming or resuming. */
4479
+ openHistoryBusyLabel?: string;
4480
+ /** Least-destructive action in every history confirmation dialog. */
4481
+ confirmCancelLabel?: string;
4482
+ /** Heading of the delete-one confirmation. */
4483
+ deleteConversationConfirmTitle?: string;
4484
+ /** Confirming action of the delete-one confirmation. */
4485
+ deleteConversationConfirmLabel?: string;
4486
+ /** Heading of the delete-all confirmation. */
4487
+ clearHistoryConfirmTitle?: string;
4488
+ /** Confirming action of the delete-all confirmation. */
4489
+ clearHistoryConfirmLabel?: string;
4490
+ /** Delete-all body used when the resolved scope is the signed-in user. */
4491
+ clearHistoryVerifiedConfirm?: string;
4492
+ /** Heading of the forget-this-device confirmation. */
4493
+ resetIdentityConfirmTitle?: string;
4494
+ /** Confirming action of the forget-this-device confirmation. */
4495
+ resetIdentityConfirmLabel?: string;
4496
+ /** Panel back control; returns to the surface that opened Messages. */
4497
+ backLabel?: string;
4498
+ /** Rail close control, shown only when the rail is not collapsible. */
4499
+ closeLabel?: string;
4500
+ /** Rail collapse toggle while the rail is expanded. */
4501
+ collapseLabel?: string;
4502
+ /** Rail collapse toggle while the rail is collapsed to icons. */
4503
+ expandLabel?: string;
4504
+ /** Accessible name of the docked rail's drag-resize handle. */
4505
+ resizeLabel?: string;
4506
+ /** Accessible status while the first page loads. */
4507
+ loadingLabel?: string;
4508
+ /** Label of the paging action below the last group. */
4509
+ loadMoreLabel?: string;
4510
+ /** Label of that action while its page is in flight. */
4511
+ loadingMoreLabel?: string;
4512
+ /**
4513
+ * Heading over the conversation list. Visible in rail presentation, where it
4514
+ * carries the list overflow trigger; sr-only in panel presentation.
4515
+ */
4516
+ conversationsTitle?: string;
4517
+ /** Accessible name of the per-row overflow trigger and its menu. */
4518
+ rowActionsLabel?: string;
4519
+ /** Accessible name of the list-level overflow trigger and its menu. */
4520
+ listOptionsLabel?: string;
4521
+ /** Delete item inside the per-row overflow menu. */
4522
+ deleteConversationLabel?: string;
4523
+ /** Delete-all item inside the list overflow menu. */
4524
+ clearHistoryLabel?: string;
4525
+ /** Forget-this-device item inside the list overflow menu. */
4526
+ resetIdentityLabel?: string;
4527
+ /** Row message count. `{count}` placeholder. */
4528
+ messageCountLabel?: string;
4529
+ /** Row message count for exactly one message. */
4530
+ messageCountLabelOne?: string;
4531
+ /** Announced after a single conversation was deleted. */
4532
+ conversationRemovedNotice?: string;
4533
+ /** Announced after every conversation in scope was deleted. */
4534
+ historyClearedNotice?: string;
4535
+ /** Heading shown when history is unavailable for this surface. */
4536
+ unavailableTitle?: string;
4537
+ /** Body text shown when history is unavailable for this surface. */
4538
+ unavailableDescription?: string;
4539
+ /** Heading of the post-deletion replacement-init recovery state. */
4540
+ newConversationRequiredTitle?: string;
4541
+ /** Body text of the post-deletion replacement-init recovery state. */
4542
+ newConversationRequiredDescription?: string;
4543
+ /** Rate-limited wait guidance. `{seconds}` placeholder. */
4544
+ rateLimitedWaitDescription?: string;
4545
+ /** Row-adjacent error after a failed open. */
4546
+ openFailedLabel?: string;
4547
+ /** Row-adjacent error after a failed delete. */
4548
+ deleteFailedLabel?: string;
4549
+ /** Relative time for the most recent bucket. */
4550
+ relativeNow?: string;
4551
+ /** Relative time in minutes. `{value}` placeholder. */
4552
+ relativeMinutes?: string;
4553
+ /** Relative time in hours. `{value}` placeholder. */
4554
+ relativeHours?: string;
4555
+ /** Relative time in days. `{value}` placeholder. */
4556
+ relativeDays?: string;
4557
+ /** Relative time in weeks. `{value}` placeholder. */
4558
+ relativeWeeks?: string;
4559
+ /** Relative time in years. `{value}` placeholder. */
4560
+ relativeYears?: string;
4561
+ }
4562
+ /**
4563
+ * One row in a `features.history.rail.sections` navigation section. Icon
4564
+ * precedence, highest first: `renderIcon`, then `iconUrl`, then `icon`.
4565
+ * Whichever resolves first is built once and reused for the item's lifetime.
4566
+ */
4567
+ interface AgentWidgetHistoryRailSectionItem {
4568
+ /** Stable identity, stamped as `data-persona-rail-item`. */
4569
+ id: string;
4570
+ /** Visible text, and the default `aria-label` of the button. */
4571
+ label: string;
4572
+ /**
4573
+ * Lucide name from the widget's built-in icon registry (see `IconName`). A
4574
+ * name outside the registry warns once and the row renders label-only.
4575
+ */
4576
+ icon?: IconName | (string & {});
4577
+ /** Image URL or data URI, rendered as a decorative `img` in the icon slot. */
4578
+ iconUrl?: string;
4579
+ /** Full custom icon node. Returning null renders the row label-only. */
4580
+ renderIcon?: () => Element | null;
4581
+ /** Small trailing text chip, for a count or a short status word. */
4582
+ badge?: string;
4583
+ /** Invoked on click. A throw is caught and warned once per section. */
4584
+ onSelect: () => void;
4585
+ }
4586
+ /** One navigation section in the history rail, above or below the list. */
4587
+ interface AgentWidgetHistoryRailSection {
4588
+ /** Stable identity, stamped as `data-persona-rail-section`. */
4589
+ id: string;
4590
+ /** Optional heading, styled like a conversation date-group heading. */
4591
+ title?: string;
4592
+ /** Default `"above-conversations"`. */
4593
+ placement?: "above-conversations" | "below-conversations" | "footer";
4594
+ items: AgentWidgetHistoryRailSectionItem[];
4595
+ }
4596
+ /**
4597
+ * Host-defined item in the list overflow menu (the `…` beside the
4598
+ * conversation-list heading). Rendered above the built-in destructive items.
4599
+ */
4600
+ interface AgentWidgetHistoryListAction {
4601
+ /** Stable identity; keeps menu focus keys stable across re-renders. */
4602
+ id: string;
4603
+ label: string;
4604
+ /** Destructive (red) styling like the built-in delete-all. Default false. */
4605
+ danger?: boolean;
4606
+ /** Receives the conversation summaries loaded at selection time. */
4607
+ onSelect: (context: {
4608
+ conversations: HistoryConversationSummary[];
4609
+ }) => void | Promise<void>;
4610
+ }
4611
+ /**
4612
+ * Feature config for per-visitor conversation history. Without a `provider`,
4613
+ * client token mode only: the built-in Runtype backend needs one, so the UI
4614
+ * never renders for proxy/agent sessions. A `provider` lifts that restriction.
4615
+ */
4616
+ interface AgentWidgetHistoryFeature {
4617
+ /** Master switch. Default false: no capability flag on init, no UI. */
4618
+ enabled?: boolean;
4619
+ /**
4620
+ * Custom conversation-history backend. Supply one to run the history UX
4621
+ * (list, open, delete, delete-all, header title binding) against your own
4622
+ * storage in ANY session mode, including a custom `apiUrl` backend with no
4623
+ * client token. Omitted, history falls back to the built-in Runtype backend,
4624
+ * which requires client token mode.
4625
+ *
4626
+ * Pass either an instance or a factory. The factory form is called once per
4627
+ * widget instance, so a single script-tag config object (assembled before
4628
+ * install) can back several widgets without sharing provider state. Passing a
4629
+ * new factory identity through `update()` rebuilds the provider.
4630
+ *
4631
+ * Failures are signalled by throwing `HistoryProviderError` with a `code` from
4632
+ * `HistoryProviderErrorCode`. The view branches on that code alone: it never
4633
+ * reads message text, and an untyped throw degrades to a generic error state.
4634
+ *
4635
+ * `prepareOpen`/`prepareStartNew` resolve BEFORE anything visible changes:
4636
+ * they return a `PreparedHistoryActivation` whose `commit()` applies the
4637
+ * already-authorized binding and whose `discard()` idempotently abandons a
4638
+ * superseded activation, leaving the active chat untouched. The widget calls
4639
+ * exactly one of the two per prepared activation.
4640
+ *
4641
+ * Optional capabilities hide their affordances when absent: no `update`
4642
+ * removes the rename/star actions (including the built-in title-menu `star`),
4643
+ * and no `resetDevice` removes "forget this device".
4644
+ *
4645
+ * The provider's `capabilities.scopes` is authoritative: the widget derives a
4646
+ * default scope (`"verified-user"` when `getIdentityProof` is configured,
4647
+ * otherwise `"browser"`) and narrows it to what the provider advertises, so a
4648
+ * browser-only provider is never asked for a scope it cannot serve. An
4649
+ * explicit `features.history.scope` is a hard request and still fails closed
4650
+ * with `unsupported_scope`. `getIdentityProof` is never called for a supplied
4651
+ * provider, and `HistoryOperationContext` carries only the resolved scope;
4652
+ * report your own identity through `getIdentityStatus()` /
4653
+ * `subscribeIdentityStatus()`, which is what the scope banner and its retry
4654
+ * affordance read.
4655
+ *
4656
+ * Reopening the last conversation after a page reload is the host's job: the
4657
+ * widget's boot resume runs only on the built-in Runtype path, so with a
4658
+ * supplied provider the transcript is restored by the storage adapter while
4659
+ * `getActiveConversationId()` starts null (no active row, no
4660
+ * conversation-bound header title) until something opens a conversation.
4661
+ * Persist the id yourself and call `controller.openConversation(id)` on ready
4662
+ * if you want the last conversation to come back automatically.
4663
+ *
4664
+ * @example
4665
+ * ```js
4666
+ * features: { history: { enabled: true, provider: () => myProvider } }
4667
+ * ```
4668
+ */
4669
+ provider?: HistoryProvider | (() => HistoryProvider);
4670
+ /** Page size for the conversation list (default 25, server max 100). */
4671
+ pageSize?: number;
4672
+ /**
4673
+ * Default history placement. "panel" replaces the conversation surface;
4674
+ * "rail" requests a side navigation host whenever it is at least 720px wide
4675
+ * and collapses to panel below that; "auto" uses rail only for a wide inline
4676
+ * or docked shell and keeps floating launchers panel-based at every width.
4677
+ * Default "panel".
4678
+ */
4679
+ presentation?: "panel" | "rail" | "auto";
4680
+ /**
4681
+ * Geometry of the rail navigation column. `side` picks the edge it docks to
4682
+ * (default "left", beside the conversation); `width` is its fixed width in
4683
+ * px, clamped to 200-400 (default 260). `collapsible` (default true) puts a
4684
+ * collapse toggle in the rail header that shrinks it to a 52px icon rail, and
4685
+ * `defaultCollapsed` (default false) picks the state a visitor who has never
4686
+ * toggled it starts in. The chosen state is remembered per visitor alongside
4687
+ * the other `persistState` keys. Ignored in panel presentation.
4688
+ */
4689
+ rail?: {
4690
+ side?: "left" | "right";
4691
+ width?: number;
4692
+ collapsible?: boolean;
4693
+ defaultCollapsed?: boolean;
4694
+ /**
4695
+ * Drag handle on the docked rail's divider edge, resizing it live within
4696
+ * the same 200 to 400 clamp `width` takes. Default false. The chosen width
4697
+ * is remembered per visitor alongside the other `persistState` keys and
4698
+ * outranks a later `width` update, the way the collapsed state does; the
4699
+ * floating overlay rail inherits it but is never itself resizable, and a
4700
+ * collapsed icon column ignores it until it expands again.
4701
+ */
4702
+ resizable?: boolean;
4703
+ /**
4704
+ * Shape of the COLLAPSED rail. `"icon-rail"` (default) keeps the 52px icon
4705
+ * column beside the conversation. `"overlay"` removes the column entirely:
4706
+ * a trigger takes the leading edge of the conversation header, hovering or
4707
+ * tapping it floats the expanded rail over the conversation, and clicking
4708
+ * it pins the rail back open. The floating rail is transient, so leaving
4709
+ * it, Escape, a click outside, or selecting a conversation all dismiss it;
4710
+ * its own header toggle docks it instead, being the control the pointer
4711
+ * finds there. Geometry follows `width` and `side`; the collapsed rail's
4712
+ * chunk is not loaded until the first hover. Ignored when `collapsible` is
4713
+ * false or in panel presentation.
4714
+ */
4715
+ collapsedBehavior?: "icon-rail" | "overlay";
4716
+ /**
4717
+ * One brand declaration, placed in both of the rail's identity spots: the
4718
+ * header's heading area when expanded (the mark leading, `copy.viewTitle`
4719
+ * beside it as the wordmark), and the collapse toggle's rest face when the
4720
+ * rail is collapsed, where hover and keyboard focus reveal the panel glyph
4721
+ * under it. A coarse pointer keeps the glyph, having no hover to reveal it
4722
+ * with. Icon precedence, highest first: `render`, then `iconUrl`, then
4723
+ * `icon`. `render` receives the placement through `ctx.collapsed` (`true`
4724
+ * is the collapsed toggle face) and may return null to skip that spot.
4725
+ * `renderHeader` outranks this for the heading area; the collapsed face is
4726
+ * this slot's alone. Decorative either way: the view's accessible name
4727
+ * still comes from `copy.viewTitle`, and the toggle keeps its own label.
4728
+ * Ignored in panel presentation.
4729
+ */
4730
+ brand?: {
4731
+ /** Lucide name from the built-in registry; an unknown one warns once. */
4732
+ icon?: IconName | (string & {});
4733
+ /** Image URL or data URI, rendered as a decorative `img`. */
4734
+ iconUrl?: string;
4735
+ /** Full custom node. A throw warns once and drops the brand. */
4736
+ render?: (context: {
4737
+ collapsed: boolean;
4738
+ }) => Element | null;
4739
+ };
4740
+ /**
4741
+ * Full override of the rail header's identity area, outranking `brand`
4742
+ * there, re-invoked whenever the collapsed state changes. Return null to
4743
+ * leave the area empty, which leaves the collapse toggle standing alone.
4744
+ * The accessible name of the
4745
+ * view comes from `copy.viewTitle` either way: the heading stays in the
4746
+ * DOM, visually hidden, whenever this renders. Ignored in panel
4747
+ * presentation.
4748
+ */
4749
+ renderHeader?: (context: {
4750
+ collapsed: boolean;
4751
+ defaultTitle: string;
4752
+ }) => Element | null;
4753
+ /**
4754
+ * Extra navigation sections stacked around the conversation list, in array
4755
+ * order within each `placement` bucket. Rail-only in this release: a move
4756
+ * into panel presentation removes them and a move back re-renders them.
4757
+ */
4758
+ sections?: AgentWidgetHistoryRailSection[];
4759
+ /**
4760
+ * Keyboard shortcut for the collapse toggle, e.g. `"mod+b"` ("mod" is
4761
+ * Command on Apple platforms, Control elsewhere). Undefined by default, so
4762
+ * an embedded widget never claims a host page's keys. The same declaration
4763
+ * drives the binding, the toggle's tooltip hint chip, and its
4764
+ * `aria-keyshortcuts`.
4765
+ */
4766
+ collapseShortcut?: string | false;
4767
+ /**
4768
+ * Where `collapseShortcut` listens. Default `"widget"`: only while focus is
4769
+ * inside the widget. `"page"` claims the combo document-wide, which suits a
4770
+ * fullscreen widget that IS the app.
4771
+ */
4772
+ collapseShortcutScope?: "widget" | "page";
4773
+ };
4774
+ /**
4775
+ * History scope. Defaults to "verified-user" when getIdentityProof exists,
4776
+ * otherwise "browser". Before this browser has been identity-bound, a null
4777
+ * proof falls back to browser scope for that operation. Once visitor.endUserId
4778
+ * is non-null, a null proof fails closed until the host resets history identity.
4779
+ *
4780
+ * With a `provider`, this is a hard request: the provider must advertise it
4781
+ * in `capabilities.scopes` or every history operation fails with
4782
+ * `unsupported_scope`. Leave it unset to let the provider's advertised scope
4783
+ * win.
4784
+ */
4785
+ scope?: HistoryScope;
4786
+ /** Copy overrides. Every user-visible history string must be here. */
4787
+ copy?: AgentWidgetHistoryCopy;
4788
+ /**
4789
+ * Date bucketing of the conversation list. `"time"` (default) groups rows
4790
+ * under Today, Yesterday, Previous 7 days, Previous 30 days, and month
4791
+ * headings. `"none"` renders one flat list in server order instead, the
4792
+ * recents-style sidebar. Starred conversations keep their pinned group
4793
+ * either way.
4794
+ */
4795
+ grouping?: "time" | "none";
4796
+ /**
4797
+ * Leading avatar on each conversation row. Unset, rows show the launcher's
4798
+ * image mark (`launcher.iconUrl`) when one exists and are text-only
4799
+ * otherwise, the assistant-list default. Pass an image URL or a glyph to
4800
+ * always show a mark, or false to force text-only rows.
4801
+ */
4802
+ rowAvatar?: boolean | string;
4803
+ /** Show the evidence-based history scope/status beneath the Messages heading. Default true. */
4804
+ showScopeStatus?: boolean;
4805
+ /**
4806
+ * Visitor-facing delete of a single conversation via each row's overflow
4807
+ * menu. Default true. False hides the control only: it changes nothing about
4808
+ * what is stored or for how long, and custom row slots still receive
4809
+ * `requestDelete`. Turn off for deployments that treat conversations as
4810
+ * business records.
4811
+ */
4812
+ showDelete?: boolean;
4813
+ /**
4814
+ * The "Delete all conversations" item in the Messages overflow menu. Default
4815
+ * true. False hides the control only; storage and retention are unchanged.
4816
+ * The identity reset item is separate and unaffected.
4817
+ */
4818
+ showDeleteAll?: boolean;
4819
+ /**
4820
+ * Host items appended to the list overflow menu, above the built-in
4821
+ * destructive actions. The trigger renders whenever any item exists, so
4822
+ * these keep the menu alive even with `showDeleteAll: false`.
4823
+ */
4824
+ listActions?: AgentWidgetHistoryListAction[];
4825
+ }
4826
+ /** Resolved scope for a logical history operation. */
4827
+ type HistoryScope = "browser" | "verified-user";
4828
+ /** `presentation` after it has been resolved against the host container width. */
4829
+ type ResolvedHistoryPresentation = "panel" | "rail";
4830
+ /**
4831
+ * The surface Messages returns to on back/Escape. `"home"` only when a Home
4832
+ * Screen composition opened it; the core header button always records
4833
+ * `"conversation"`.
4834
+ */
4835
+ type HistoryReturnSurface = "home" | "conversation";
4836
+ /**
4837
+ * Evidence-based history identity state. Never inferred from the mere presence
4838
+ * of `getIdentityProof`, and never carries token, visitor, or end-user values.
4839
+ */
4840
+ type HistoryIdentityStatus = {
4841
+ state: "browser_only";
4842
+ reason: "configured_browser_scope" | "no_identity_provider" | "proof_unavailable_before_binding";
4843
+ } | {
4844
+ state: "verifying";
4845
+ } | {
4846
+ state: "verified";
4847
+ } | {
4848
+ state: "authentication_required";
4849
+ reason: "proof_unavailable_after_binding" | "invalid_identity_proof";
4850
+ } | {
4851
+ state: "identity_provider_failed";
4852
+ } | {
4853
+ state: "configuration_error";
4854
+ reason: "proof_not_admitted";
4855
+ } | {
4856
+ state: "resetting";
4857
+ } | {
4858
+ state: "unavailable";
4859
+ reason: "history_disabled" | "ineligible_mode";
4860
+ };
4861
+ /** Fully defaulted history copy. Every user-visible history string. */
4862
+ type ResolvedHistoryCopy = Required<AgentWidgetHistoryCopy>;
4863
+ /** List-region state handed to render hooks. */
4864
+ type HistoryViewState = {
4865
+ kind: "loading";
4866
+ phase: "initial" | "refresh" | "load-more";
4867
+ } | {
4868
+ kind: "ready";
4869
+ } | {
4870
+ kind: "empty";
4871
+ } | {
4872
+ kind: "error";
4873
+ reason: "unavailable" | "authentication_failed" | "authentication_required" | "identity_provider_failed" | "proof_not_admitted" | "unsupported_scope" | "unknown";
4874
+ retryable: boolean;
4875
+ } | {
4876
+ kind: "rate_limited";
4877
+ retryAfterSeconds: number;
4878
+ } | {
4879
+ kind: "new_conversation_required";
4880
+ };
4881
+ /** The single in-flight history operation, or `null` when idle. */
4882
+ type HistoryPendingAction = {
4883
+ kind: "refresh" | "load-more" | "start-new" | "clear" | "reset";
4884
+ } | {
4885
+ kind: "open" | "delete";
4886
+ conversationId: string;
4887
+ } | null;
4888
+ /**
4889
+ * Every history operation a render hook may invoke. Each routes through the
4890
+ * same controller/session path as the default renderer, so busy gating,
4891
+ * selection epochs, and confirmations behave identically.
4892
+ */
4893
+ type AgentWidgetHistoryRenderActions = {
4894
+ refresh(): Promise<void>;
4895
+ loadMore(): Promise<void>;
4896
+ openConversation(conversationId: string): Promise<void>;
4897
+ startNewConversation(): Promise<void>;
4898
+ /** Each request method opens Persona's accessible confirmation first. */
4899
+ requestDeleteConversation(conversationId: string): Promise<"deleted" | "cancelled">;
4900
+ requestClearConversationHistory(): Promise<"cleared" | "cancelled">;
4901
+ requestResetHistoryIdentity(): Promise<{
4902
+ outcome: "cancelled";
4903
+ } | {
4904
+ outcome: "reset";
4905
+ remoteRevocationConfirmed: boolean;
4906
+ }>;
4907
+ close(): void;
4908
+ };
4909
+ /** Context for `renderHistoryView`. Frozen snapshot; no provider or credentials. */
4910
+ type AgentWidgetRenderHistoryViewContext = {
4911
+ conversations: readonly HistoryConversationSummary[];
4912
+ activeConversationId: string | null;
4913
+ state: HistoryViewState;
4914
+ pendingAction: HistoryPendingAction;
4915
+ identityStatus: HistoryIdentityStatus;
4916
+ nextCursor: string | null;
4917
+ presentation: ResolvedHistoryPresentation;
4918
+ returnSurface: HistoryReturnSurface;
4919
+ config: AgentWidgetConfig;
4920
+ copy: ResolvedHistoryCopy;
4921
+ actions: AgentWidgetHistoryRenderActions;
4922
+ /** The default full view. Bypasses this hook only; lower slots still apply. */
4923
+ defaultRenderer(): HTMLElement;
4924
+ /** Re-run arbitration with the current snapshot. Inert after close/destroy. */
4925
+ requestRender(): void;
4926
+ /** Teardown for this render; runs before the next one and on close. */
4927
+ onCleanup(callback: () => void): void;
4928
+ };
4929
+ /** Context for `renderHistoryConversation` (one list row). */
4930
+ type AgentWidgetRenderHistoryConversationContext = {
4931
+ conversation: HistoryConversationSummary;
4932
+ active: boolean;
4933
+ pending: "opening" | "deleting" | null;
4934
+ presentation: ResolvedHistoryPresentation;
4935
+ config: AgentWidgetConfig;
4936
+ open(): Promise<void>;
4937
+ requestDelete(): Promise<"deleted" | "cancelled">;
4938
+ defaultRenderer(): HTMLElement;
4939
+ };
4940
+ /** Context for `renderHistoryHeader` (the Messages top bar). */
4941
+ type AgentWidgetRenderHistoryHeaderContext = {
4942
+ presentation: ResolvedHistoryPresentation;
4943
+ returnSurface: HistoryReturnSurface;
4944
+ identityStatus: HistoryIdentityStatus;
4945
+ pendingAction: HistoryPendingAction;
4946
+ config: AgentWidgetConfig;
4947
+ copy: ResolvedHistoryCopy;
4948
+ actions: Pick<AgentWidgetHistoryRenderActions, "close" | "startNewConversation">;
4949
+ defaultRenderer(): HTMLElement;
4950
+ };
4951
+ /**
4952
+ * Context for `renderHistoryState`. Invoked only for non-ready list states;
4953
+ * `retry`/`startNewConversation` are present only where they are safe, so
4954
+ * custom DOM never infers recovery behavior.
4955
+ */
4956
+ type AgentWidgetRenderHistoryStateContext = {
4957
+ state: Exclude<HistoryViewState, {
4958
+ kind: "ready";
4959
+ }>;
4960
+ identityStatus: HistoryIdentityStatus;
4961
+ presentation: ResolvedHistoryPresentation;
4962
+ config: AgentWidgetConfig;
4963
+ copy: ResolvedHistoryCopy;
4964
+ retry?: () => Promise<void>;
4965
+ startNewConversation?: () => Promise<void>;
4966
+ defaultRenderer(): HTMLElement;
4967
+ };
4968
+ /**
4969
+ * Context for `renderHistoryOpenError` (the transcript-level surface shown
4970
+ * when opening a conversation from the Messages list fails). `retry` and
4971
+ * `back` are the only exits: both route through the token-guarded open flow,
4972
+ * so custom DOM must not fetch on its own. `back` is present only when the
4973
+ * Messages surface is available to return to.
4974
+ */
4975
+ type AgentWidgetRenderHistoryOpenErrorContext = {
4976
+ conversationId: string;
4977
+ config: AgentWidgetConfig;
4978
+ /** Resolved shell copy the default surface renders. */
4979
+ copy: {
4980
+ title: string;
4981
+ retryLabel: string;
4982
+ backLabel: string;
4983
+ };
4984
+ /** Re-runs the open through Persona's token-guarded flow. */
4985
+ retry: () => void;
4986
+ /** Returns to the Messages list. Absent when history is unavailable. */
4987
+ back?: () => void;
4988
+ defaultRenderer(): HTMLElement;
4989
+ };
3866
4990
  type SSEEventRecord = {
3867
4991
  id: string;
3868
4992
  type: string;
@@ -4335,6 +5459,24 @@ type AgentWidgetLauncherTeaserConfig = {
4335
5459
  */
4336
5460
  dismissLabel?: string;
4337
5461
  };
5462
+ /**
5463
+ * Timing for the portaled icon-control tooltip (header, composer, rail).
5464
+ * Keyboard focus always opens immediately. Hover waits `delayMs` unless
5465
+ * another tooltip closed within `skipDelayMs` (toolbar scan).
5466
+ */
5467
+ type AgentWidgetTooltipConfig = {
5468
+ /**
5469
+ * Milliseconds to wait on hover before the first tooltip appears.
5470
+ * `0` restores the previous instant-open behavior.
5471
+ * @default 200
5472
+ */
5473
+ delayMs?: number;
5474
+ /**
5475
+ * After a tooltip closes, later hovers in this window skip `delayMs`.
5476
+ * @default 300
5477
+ */
5478
+ skipDelayMs?: number;
5479
+ };
4338
5480
  type AgentWidgetSendButtonConfig = {
4339
5481
  borderWidth?: string;
4340
5482
  borderColor?: string;
@@ -5350,6 +6492,21 @@ type ClientSession = {
5350
6492
  name: string;
5351
6493
  description: string | null;
5352
6494
  };
6495
+ /**
6496
+ * Active conversation record for this session. Optional only for rolling-deploy
6497
+ * compatibility with servers that predate the visitor history contract.
6498
+ */
6499
+ conversationId?: string;
6500
+ /**
6501
+ * Canonical resolved chat target (flow or agent). Normalized from the response
6502
+ * `targetId`, falling back to `flow.id` during rolling deployment. History code
6503
+ * reads this, never widget config.
6504
+ */
6505
+ targetId?: string;
6506
+ /** Opaque change token; differs whenever the conversation transcript mutated. */
6507
+ conversationRevision?: string;
6508
+ /** Visitor grant backing history. `token` appears only at mint. */
6509
+ visitor?: ClientVisitorGrant;
5353
6510
  /** Configuration from the server */
5354
6511
  config: {
5355
6512
  welcomeMessage: string | null;
@@ -5357,6 +6514,43 @@ type ClientSession = {
5357
6514
  theme: Record<string, unknown> | null;
5358
6515
  };
5359
6516
  };
6517
+ /**
6518
+ * Visitor credential and identity acknowledgement returned by /v1/client/init.
6519
+ * `expiresAt` stays the wire string: it is a server-slid idle window the widget
6520
+ * never evaluates locally.
6521
+ */
6522
+ type ClientVisitorGrant = {
6523
+ id: string;
6524
+ /** Replacement secret. Present only at mint; persist it before anything else. */
6525
+ token?: string;
6526
+ expiresAt: string;
6527
+ endUserId: string | null;
6528
+ /** Server acknowledgement of the supplied identity proof. Status metadata only. */
6529
+ identityStatus?: "not_provided" | "admitted" | "ignored";
6530
+ };
6531
+ /**
6532
+ * One conversation row, normalized at the Runtype boundary. The deprecated wire
6533
+ * `flowId` alias never escapes that boundary: history code reads `targetId`.
6534
+ */
6535
+ type HistoryConversationSummary = {
6536
+ id: string;
6537
+ /** Server-generated; rendered verbatim, never derived locally. */
6538
+ title: string;
6539
+ /** Resolved chat target (flow or agent); `null` when the server omits it. */
6540
+ targetId: string | null;
6541
+ /** Server-produced plain-text preview; `null` when unavailable. */
6542
+ preview: string | null;
6543
+ messageCount: number;
6544
+ createdAt: string;
6545
+ updatedAt: string;
6546
+ /** Visitor-pinned flag. Absent when the provider has no update capability. */
6547
+ starred?: boolean;
6548
+ };
6549
+ /** Visitor-editable conversation metadata. Absent fields are left unchanged. */
6550
+ type HistoryConversationPatch = {
6551
+ title?: string;
6552
+ starred?: boolean;
6553
+ };
5360
6554
  /** Icon button in the header title row (minimal layout). */
5361
6555
  type AgentWidgetHeaderTrailingAction = {
5362
6556
  id: string;
@@ -5375,6 +6569,13 @@ type AgentWidgetHeaderTrailingAction = {
5375
6569
  destructive?: boolean;
5376
6570
  dividerBefore?: boolean;
5377
6571
  }>;
6572
+ /**
6573
+ * Keyboard shortcut that activates this action, e.g. `"mod+shift+h"` ("mod"
6574
+ * is Command on Apple platforms, Control elsewhere). Fires only while focus
6575
+ * is inside the widget, and also drives the button's tooltip hint chip and
6576
+ * its `aria-keyshortcuts`.
6577
+ */
6578
+ shortcut?: string;
5378
6579
  };
5379
6580
  /**
5380
6581
  * Context provided to header render functions
@@ -5418,6 +6619,15 @@ type AgentWidgetHeaderLayoutConfig = {
5418
6619
  showIcon?: boolean;
5419
6620
  /** Show/hide the title */
5420
6621
  showTitle?: boolean;
6622
+ /**
6623
+ * What the header title (or `titleMenu` label) displays. `"static"`
6624
+ * (default) always shows `launcher.title`. `"conversation"` shows the active
6625
+ * conversation's title — the Claude-style pairing for a `titleMenu` holding
6626
+ * conversation actions — falling back to `launcher.title` while no titled
6627
+ * conversation is open (fresh chat, cleared history, or before the history
6628
+ * view has loaded titles). Requires `features.history` for titles to exist.
6629
+ */
6630
+ titleSource?: "static" | "conversation";
5421
6631
  /** Show/hide the subtitle */
5422
6632
  showSubtitle?: boolean;
5423
6633
  /** Show/hide the close button */
@@ -5468,8 +6678,16 @@ type AgentWidgetHeaderLayoutConfig = {
5468
6678
  destructive?: boolean;
5469
6679
  dividerBefore?: boolean;
5470
6680
  }>;
5471
- /** Called when a menu item is selected. */
5472
- onSelect: (id: string) => void;
6681
+ /**
6682
+ * Called when a menu item is selected. Returning `false` (sync or via
6683
+ * promise) falls through to the widget built-ins, mirroring the artifact
6684
+ * copy-menu contract: id `star` toggles the active conversation's star and
6685
+ * id `delete` runs the shell's confirm-then-delete on it (both require
6686
+ * `features.history` and, for star, a provider with the update
6687
+ * capability). `rename` has no built-in: hosts own the rename UI and call
6688
+ * `renameConversation()`.
6689
+ */
6690
+ onSelect: (id: string) => void | boolean | Promise<void | boolean>;
5473
6691
  /** Hover pill style. */
5474
6692
  hover?: {
5475
6693
  background?: string;
@@ -6040,15 +7258,20 @@ type LoadingIndicatorRenderContext = {
6040
7258
  */
6041
7259
  config: AgentWidgetConfig;
6042
7260
  /**
6043
- * Current streaming state (always true when indicator is shown)
7261
+ * Current streaming state. Always true for 'inline' and 'standalone';
7262
+ * false for 'conversation-open' (a history fetch, not a stream).
6044
7263
  */
6045
7264
  streaming: boolean;
6046
7265
  /**
6047
7266
  * Location where the indicator is rendered:
6048
7267
  * - 'inline': Inside a streaming assistant message bubble (when content is empty)
6049
7268
  * - 'standalone': Separate bubble while waiting for stream to start
7269
+ * - 'conversation-open': Transcript stand-in while a conversation opened
7270
+ * from the Messages list is being fetched. The returned element is mounted
7271
+ * inside Persona's centered transcript column, which keeps the status
7272
+ * role, announcement label, and composer gating.
6050
7273
  */
6051
- location: 'inline' | 'standalone';
7274
+ location: 'inline' | 'standalone' | 'conversation-open';
6052
7275
  /**
6053
7276
  * Function to render the default 3-dot bouncing indicator.
6054
7277
  * Call this if you want to use the default for certain cases.
@@ -6347,6 +7570,28 @@ type AgentWidgetConfig = {
6347
7570
  * ```
6348
7571
  */
6349
7572
  setStoredSessionId?: (sessionId: string) => void;
7573
+ /**
7574
+ * Called immediately before any cross-device history request and before a
7575
+ * conversationId resume of a conversation discovered on another device.
7576
+ * Return a fresh end-user access token (rt_eu_… / JWT). Null uses exact-browser
7577
+ * scope only for a never-bound visitor; a previously bound visitor fails closed
7578
+ * until resetHistoryIdentity() runs. Never cached by the widget.
7579
+ */
7580
+ getIdentityProof?: () => string | null | Promise<string | null>;
7581
+ /**
7582
+ * Read the persisted active conversation id (client token mode only).
7583
+ * Called only after the internal stored-state bootstrap gate resolves.
7584
+ */
7585
+ getStoredConversationId?: () => string | null;
7586
+ /** Persist the active conversation id so a later boot reopens the same record. */
7587
+ setStoredConversationId?: (conversationId: string) => void;
7588
+ /** Drop the persisted active conversation id (new conversation, deletion, reset). */
7589
+ clearStoredConversationId?: () => void;
7590
+ /**
7591
+ * Drop the persisted session id. Dedicated clear seam: it avoids widening
7592
+ * `setStoredSessionId` and its existing host call sites.
7593
+ */
7594
+ clearStoredSessionId?: () => void;
6350
7595
  /**
6351
7596
  * Static headers to include with each request.
6352
7597
  * For dynamic headers (e.g., auth tokens), use `getHeaders` instead.
@@ -6426,6 +7671,12 @@ type AgentWidgetConfig = {
6426
7671
  * @default false
6427
7672
  */
6428
7673
  autoFocusInput?: boolean;
7674
+ /**
7675
+ * Hover timing for the portaled control tooltip. Keyboard focus is
7676
+ * always immediate. Unset keys keep the ChatGPT/Claude defaults
7677
+ * (`delayMs: 200`, `skipDelayMs: 300`).
7678
+ */
7679
+ tooltip?: AgentWidgetTooltipConfig;
6429
7680
  launcher?: AgentWidgetLauncherConfig;
6430
7681
  initialMessages?: AgentWidgetMessage[];
6431
7682
  /**
@@ -7591,6 +8842,71 @@ type Controller = {
7591
8842
  * forwarded to `config.approval.onDecision`.
7592
8843
  */
7593
8844
  resolveApproval: (approvalId: string, decision: 'approved' | 'denied', options?: AgentWidgetApprovalDecisionOptions) => Promise<void>;
8845
+ /** Pass-through list, for headless hosts rendering their own navigation. */
8846
+ listConversations: (opts?: {
8847
+ cursor?: string;
8848
+ limit?: number;
8849
+ targetId?: string;
8850
+ scope?: HistoryScope;
8851
+ }) => Promise<{
8852
+ items: HistoryConversationSummary[];
8853
+ nextCursor: string | null;
8854
+ }>;
8855
+ /** The open conversation's record id; null for a fresh unsaved chat. */
8856
+ getActiveConversationId: () => string | null;
8857
+ /**
8858
+ * Full open flow: transactional resume, hydration, and scroll restore.
8859
+ * `focus: true` moves focus to the composer; the programmatic default
8860
+ * leaves focus alone (an embedded widget must not scroll the host page
8861
+ * on a boot-time reopen).
8862
+ */
8863
+ openConversation: (conversationId: string, opts?: {
8864
+ focus?: boolean;
8865
+ }) => Promise<void>;
8866
+ /** Clean local state plus a new owned server conversation. `focus` as on `openConversation`. */
8867
+ startNewConversation: (opts?: {
8868
+ focus?: boolean;
8869
+ }) => Promise<void>;
8870
+ /** Permanently delete one server record; the active one is replaced. */
8871
+ deleteConversation: (conversationId: string) => Promise<void>;
8872
+ /**
8873
+ * Visitor-scoped rename. Requires a provider with the update capability;
8874
+ * a user-set title pins, so a later auto-generated title never overwrites it.
8875
+ */
8876
+ renameConversation: (conversationId: string, title: string) => Promise<HistoryConversationSummary>;
8877
+ /** Visitor-scoped star/unstar. Requires a provider with the update capability. */
8878
+ setConversationStarred: (conversationId: string, starred: boolean) => Promise<HistoryConversationSummary>;
8879
+ /**
8880
+ * Permanently delete every record in the resolved scope. Defaults to the
8881
+ * active target filter; `allTargets` is a deliberate client-token-wide delete.
8882
+ */
8883
+ clearConversationHistory: (opts?: {
8884
+ targetId?: string;
8885
+ allTargets?: boolean;
8886
+ scope?: HistoryScope;
8887
+ }) => Promise<{
8888
+ deleted: number;
8889
+ }>;
8890
+ /**
8891
+ * Revoke this browser's history credential and wipe it locally. Resolves
8892
+ * (never rejects) on remote failure; rejection is reserved for misuse.
8893
+ * Required host logout wiring.
8894
+ */
8895
+ resetHistoryIdentity: () => Promise<{
8896
+ remoteRevocationConfirmed: boolean;
8897
+ }>;
8898
+ /** Latest sanitized identity state; carries no token, proof, or identity id. */
8899
+ getHistoryIdentityStatus: () => HistoryIdentityStatus;
8900
+ /** `focus: false` keeps focus where it is (programmatic/preview opens). */
8901
+ showHistory: (opts?: {
8902
+ returnSurface?: HistoryReturnSurface;
8903
+ focus?: boolean;
8904
+ }) => Promise<void>;
8905
+ /** `restoreFocus: false` leaves focus untouched on close. */
8906
+ hideHistory: (opts?: {
8907
+ restoreFocus?: boolean;
8908
+ }) => void;
8909
+ isHistoryVisible: () => boolean;
7594
8910
  };
7595
8911
  type AgentWidgetController = Controller;
7596
8912
 
@@ -7600,7 +8916,7 @@ type AgentWidgetController = Controller;
7600
8916
  * advanced preview system. Separate file for code-splitting.
7601
8917
  */
7602
8918
 
7603
- type PreviewScene = 'home' | 'conversation' | 'follow-ups' | 'minimized' | 'artifact';
8919
+ type PreviewScene = 'home' | 'conversation' | 'follow-ups' | 'minimized' | 'artifact' | 'messages';
7604
8920
 
7605
8921
  /**
7606
8922
  * Imperative preview renderer for the theme editor.