@runtypelabs/persona 3.17.0 → 3.19.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 (61) hide show
  1. package/README.md +143 -1
  2. package/dist/animations/glyph-cycle.d.cts +1 -1
  3. package/dist/animations/glyph-cycle.d.ts +1 -1
  4. package/dist/animations/{types-HPZY7oAI.d.cts → types-cwY5HaFD.d.cts} +25 -0
  5. package/dist/animations/{types-HPZY7oAI.d.ts → types-cwY5HaFD.d.ts} +25 -0
  6. package/dist/animations/wipe.d.cts +1 -1
  7. package/dist/animations/wipe.d.ts +1 -1
  8. package/dist/index.cjs +47 -47
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +580 -4
  11. package/dist/index.d.ts +580 -4
  12. package/dist/index.global.js +102 -1636
  13. package/dist/index.global.js.map +1 -1
  14. package/dist/index.js +45 -45
  15. package/dist/index.js.map +1 -1
  16. package/dist/theme-editor.cjs +2844 -752
  17. package/dist/theme-editor.d.cts +337 -1
  18. package/dist/theme-editor.d.ts +337 -1
  19. package/dist/theme-editor.js +2958 -752
  20. package/dist/theme-reference.cjs +1 -1
  21. package/dist/theme-reference.d.cts +14 -0
  22. package/dist/theme-reference.d.ts +14 -0
  23. package/dist/widget.css +780 -0
  24. package/package.json +1 -1
  25. package/src/client.test.ts +134 -0
  26. package/src/client.ts +71 -0
  27. package/src/components/ask-user-question-bubble.test.ts +583 -0
  28. package/src/components/ask-user-question-bubble.ts +924 -0
  29. package/src/components/composer-builder.test.ts +52 -0
  30. package/src/components/composer-builder.ts +67 -490
  31. package/src/components/composer-parts.test.ts +152 -0
  32. package/src/components/composer-parts.ts +452 -0
  33. package/src/components/header-builder.ts +22 -299
  34. package/src/components/header-parts.ts +360 -0
  35. package/src/components/messages.ts +33 -1
  36. package/src/components/panel.test.ts +61 -0
  37. package/src/components/panel.ts +303 -9
  38. package/src/components/pill-composer-builder.test.ts +85 -0
  39. package/src/components/pill-composer-builder.ts +183 -0
  40. package/src/defaults.ts +21 -0
  41. package/src/index.ts +20 -1
  42. package/src/plugins/types.ts +57 -0
  43. package/src/runtime/init.ts +4 -2
  44. package/src/runtime/persist-state.test.ts +152 -0
  45. package/src/session.test.ts +183 -0
  46. package/src/session.ts +242 -3
  47. package/src/styles/widget.css +780 -0
  48. package/src/types/theme.ts +15 -0
  49. package/src/types.ts +271 -1
  50. package/src/ui.ask-user-question-plugin.test.ts +649 -0
  51. package/src/ui.component-directive.test.ts +183 -0
  52. package/src/ui.composer-bar.test.ts +1009 -0
  53. package/src/ui.ts +1439 -76
  54. package/src/utils/attachment-manager.ts +1 -1
  55. package/src/utils/dock.test.ts +45 -0
  56. package/src/utils/dock.ts +3 -0
  57. package/src/utils/icons.ts +314 -58
  58. package/src/utils/storage.ts +10 -2
  59. package/src/utils/stream-animation.ts +7 -2
  60. package/src/utils/theme.test.ts +36 -0
  61. package/src/utils/tokens.ts +23 -0
@@ -237,6 +237,19 @@ export interface MessageTokens {
237
237
  border?: TokenReference<'color'>;
238
238
  }
239
239
 
240
+ /**
241
+ * Welcome / intro card rendered above the message list when no messages exist.
242
+ * Set `copy.showWelcomeCard: false` to hide it; use `layout.slots["body-top"]`
243
+ * to replace it wholesale.
244
+ */
245
+ export interface IntroCardTokens extends ComponentTokenSet {
246
+ background?: TokenReference<'color'>;
247
+ borderRadius?: TokenReference<'radius'>;
248
+ padding?: TokenReference<'spacing'>;
249
+ /** Box-shadow on the intro card (token ref or raw CSS, e.g. `none`). */
250
+ shadow?: string;
251
+ }
252
+
240
253
  /** Collapsible widget chrome (tool bubbles, reasoning bubbles, approval bubbles). */
241
254
  export interface CollapsibleWidgetTokens {
242
255
  /** Background for content areas. */
@@ -449,6 +462,8 @@ export interface ComponentTokens {
449
462
  panel: PanelTokens;
450
463
  header: HeaderTokens;
451
464
  message: MessageTokens;
465
+ /** Welcome / intro card shown above the message list. */
466
+ introCard?: IntroCardTokens;
452
467
  /** Markdown surfaces (chat + artifact pane). */
453
468
  markdown?: MarkdownTokens;
454
469
  voice: VoiceTokens;
package/src/types.ts CHANGED
@@ -205,6 +205,31 @@ export type AgentMessageMetadata = {
205
205
  * or `prompt` step inside the nested flow). Stable key for that step.
206
206
  */
207
207
  parentStepId?: string;
208
+ /**
209
+ * Set to `true` on a tool-variant message produced from a `step_await`
210
+ * event (`awaitReason: "local_tool_required"`). Signals to UI code that
211
+ * the tool call is a LOCAL tool and the server is paused waiting for a
212
+ * `POST /v1/dispatch/resume` with the user's answer keyed by tool name.
213
+ */
214
+ awaitingLocalTool?: boolean;
215
+ /**
216
+ * Set to `true` once the user has picked / typed / dismissed an answer for
217
+ * an `ask_user_question` tool call, so renderers stop re-mounting the
218
+ * answer-pill sheet for this tool call on subsequent render passes.
219
+ */
220
+ askUserQuestionAnswered?: boolean;
221
+ /**
222
+ * In-progress answers for a multi-question `ask_user_question` payload,
223
+ * keyed by question text. Persisted across refresh so the user lands back
224
+ * where they were if the page reloads mid-flow. Cleared once
225
+ * `askUserQuestionAnswered` flips to `true`.
226
+ */
227
+ askUserQuestionAnswers?: Record<string, string | string[]>;
228
+ /**
229
+ * Current page index for a multi-question `ask_user_question` payload's
230
+ * paginated stepper. Persists alongside `askUserQuestionAnswers`.
231
+ */
232
+ askUserQuestionIndex?: number;
208
233
  };
209
234
 
210
235
  export type AgentWidgetRequestMiddlewareContext = {
@@ -270,6 +295,8 @@ export type AgentWidgetActionHandler = (
270
295
  export type AgentWidgetStoredState = {
271
296
  messages?: AgentWidgetMessage[];
272
297
  metadata?: Record<string, unknown>;
298
+ artifacts?: PersonaArtifactRecord[];
299
+ selectedArtifactId?: string | null;
273
300
  };
274
301
 
275
302
  export interface AgentWidgetStorageAdapter {
@@ -857,6 +884,118 @@ export type AgentWidgetFeatureFlags = {
857
884
  artifacts?: AgentWidgetArtifactsFeature;
858
885
  /** Reveal animation for streaming assistant text. */
859
886
  streamAnimation?: AgentWidgetStreamAnimationFeature;
887
+ /**
888
+ * Built-in interactive answer-pill sheet shown when the assistant invokes
889
+ * the `ask_user_question` tool. Slides up over the composer with tappable
890
+ * pills + optional free-text input.
891
+ */
892
+ askUserQuestion?: AgentWidgetAskUserQuestionFeature;
893
+ };
894
+
895
+ /**
896
+ * Single selectable option in an `ask_user_question` prompt.
897
+ * Mirrors Anthropic's AskUserQuestion schema.
898
+ */
899
+ export type AskUserQuestionOption = {
900
+ /** Pill label (required). */
901
+ label: string;
902
+ /** Optional long-form description (shown as a subtitle on tap-hover). */
903
+ description?: string;
904
+ /** Optional rich preview — reserved for future rendering; ignored in v1. */
905
+ preview?: string;
906
+ };
907
+
908
+ /**
909
+ * A single question in an `ask_user_question` tool call.
910
+ * The tool may carry 1–8 prompts. When more than one is supplied, the built-in
911
+ * renderer paginates them as a "Question N of M" stepper with Back / Next /
912
+ * Submit-all controls; single-question payloads render without stepper chrome.
913
+ */
914
+ export type AskUserQuestionPrompt = {
915
+ /** The question text shown to the user. */
916
+ question: string;
917
+ /** Optional short header label (≤12 chars) used as a compact group title. */
918
+ header?: string;
919
+ /** 2–4 selectable options. */
920
+ options: AskUserQuestionOption[];
921
+ /** When true, the user can pick multiple options and submit together. Default false. */
922
+ multiSelect?: boolean;
923
+ /** When true, a free-text "Other…" pill expands to an input. Default true. */
924
+ allowFreeText?: boolean;
925
+ };
926
+
927
+ /** Parsed payload of an `ask_user_question` tool call. */
928
+ export type AskUserQuestionPayload = {
929
+ /** 1–8 questions. Anything beyond the renderer's cap is truncated with a console warning. */
930
+ questions: AskUserQuestionPrompt[];
931
+ };
932
+
933
+ /**
934
+ * Style overrides for the answer-pill sheet. All values are raw CSS strings
935
+ * and are plumbed through as CSS custom properties on the sheet root.
936
+ */
937
+ export type AgentWidgetAskUserQuestionStyles = {
938
+ sheetBackground?: string;
939
+ sheetBorder?: string;
940
+ sheetShadow?: string;
941
+ pillBackground?: string;
942
+ pillBackgroundSelected?: string;
943
+ pillTextColor?: string;
944
+ pillTextColorSelected?: string;
945
+ pillBorderRadius?: string;
946
+ customInputBackground?: string;
947
+ };
948
+
949
+ /**
950
+ * Feature config for the built-in `ask_user_question` answer-pill sheet.
951
+ * When a tool call with the name `ask_user_question` arrives, the widget
952
+ * renders an interactive sheet over the composer in place of the generic
953
+ * tool bubble.
954
+ */
955
+ export type AgentWidgetAskUserQuestionFeature = {
956
+ /** Enable the feature. Defaults to true. When false, `ask_user_question` renders as a regular tool bubble. */
957
+ enabled?: boolean;
958
+ /** Slide-in animation duration in ms. Defaults to 180. */
959
+ slideInMs?: number;
960
+ /** Label for the free-text pill. Defaults to "Other…". */
961
+ freeTextLabel?: string;
962
+ /** Placeholder text in the free-text input. Defaults to "Type your answer…". */
963
+ freeTextPlaceholder?: string;
964
+ /** Button label for submitting multi-select / free-text answers. Defaults to "Send". */
965
+ submitLabel?: string;
966
+ /** Button label advancing to the next question in grouped (paginated) payloads. Defaults to "Next". */
967
+ nextLabel?: string;
968
+ /** Button label moving back to the previous question in grouped payloads. Defaults to "Back". */
969
+ backLabel?: string;
970
+ /** Button label submitting all answers from the final page of a grouped payload. Defaults to "Submit all". */
971
+ submitAllLabel?: string;
972
+ /**
973
+ * In grouped (multi-question) mode, auto-advance to the next page after a
974
+ * single-select pill pick or free-text submit on intermediate pages.
975
+ * Defaults to `true`. The final page never auto-submits — users always
976
+ * confirm with an explicit "Submit all" click. Multi-select pages always
977
+ * require an explicit Next regardless of this setting.
978
+ */
979
+ groupedAutoAdvance?: boolean;
980
+ /**
981
+ * Visual layout for the option list.
982
+ * - `"rows"` (default) — full-width stacked rows with always-visible
983
+ * descriptions, right-edge number badges (single-select) or checkboxes
984
+ * (multi-select), and an always-visible inline "Other" input.
985
+ * - `"pills"` — legacy compact pill list with horizontal wrap; description
986
+ * surfaces as a tooltip and the "Other…" pill expands on click.
987
+ */
988
+ layout?: "rows" | "pills";
989
+ /**
990
+ * Button label for skipping the current question in grouped payloads.
991
+ * Defaults to "Skip". On intermediate pages Skip advances without recording
992
+ * an answer; on the final page Skip submits the partial answer record
993
+ * (skipped questions absent from the resolved object). For single-question
994
+ * payloads Skip behaves like dismiss.
995
+ */
996
+ skipLabel?: string;
997
+ /** Style overrides for the sheet and pills. */
998
+ styles?: AgentWidgetAskUserQuestionStyles;
860
999
  };
861
1000
 
862
1001
  export type SSEEventRecord = {
@@ -1011,6 +1150,103 @@ export type AgentWidgetDockConfig = {
1011
1150
  reveal?: "resize" | "overlay" | "push" | "emerge";
1012
1151
  };
1013
1152
 
1153
+ /**
1154
+ * Layout configuration for `mountMode: "composer-bar"`. Controls how the
1155
+ * collapsed pill is positioned and sized, and how the panel expands when
1156
+ * the user opens it.
1157
+ */
1158
+ export type AgentWidgetComposerBarConfig = {
1159
+ /**
1160
+ * Max-width of the collapsed pill composer at the bottom of the viewport.
1161
+ * @default "720px"
1162
+ */
1163
+ collapsedMaxWidth?: string;
1164
+ /**
1165
+ * Bottom offset (CSS length) from the viewport edge in the collapsed state.
1166
+ * @default "16px"
1167
+ */
1168
+ bottomOffset?: string;
1169
+ /**
1170
+ * Auto-expand the panel when the user submits a message while the composer
1171
+ * is collapsed. When false, the message still sends but the panel remains
1172
+ * collapsed (the host can drive expansion programmatically).
1173
+ * @default true
1174
+ */
1175
+ expandOnSubmit?: boolean;
1176
+ /**
1177
+ * Size of the expanded chat panel.
1178
+ * - `"anchored"` (default): the pill stays at the bottom of the viewport
1179
+ * and the chat history grows upward into a centered column above it.
1180
+ * Width is driven by `expandedMaxWidth`; the panel's top edge sits at
1181
+ * `expandedTopOffset` from the viewport top.
1182
+ * - `"fullscreen"`: covers the entire viewport (mobile-app style). Inner
1183
+ * content is centered horizontally via `contentMaxWidth`.
1184
+ * - `"modal"`: centered sheet with margins; size driven by
1185
+ * `modalMaxWidth` / `modalMaxHeight`.
1186
+ * @default "anchored"
1187
+ */
1188
+ expandedSize?: "anchored" | "fullscreen" | "modal";
1189
+ /**
1190
+ * When `expandedSize === "anchored"`, max-width of the expanded panel
1191
+ * column. Capped at `calc(100vw - 32px)` on narrow viewports.
1192
+ * @default "880px"
1193
+ */
1194
+ expandedMaxWidth?: string;
1195
+ /**
1196
+ * When `expandedSize === "anchored"`, distance from the viewport top to
1197
+ * the panel's top edge. Accepts any CSS length.
1198
+ * @default "5vh"
1199
+ */
1200
+ expandedTopOffset?: string;
1201
+ /**
1202
+ * Max-width applied to messages, composer form, suggestions, and
1203
+ * attachment previews so they center horizontally inside the expanded
1204
+ * panel. Falls back to `layout.contentMaxWidth` when set; otherwise
1205
+ * defaults to this value.
1206
+ * @default "720px"
1207
+ */
1208
+ contentMaxWidth?: string;
1209
+ /**
1210
+ * When `expandedSize === "modal"`, max-width of the expanded sheet.
1211
+ * @default "880px"
1212
+ */
1213
+ modalMaxWidth?: string;
1214
+ /**
1215
+ * When `expandedSize === "modal"`, max-height of the expanded sheet.
1216
+ * @default "min(90vh, 800px)"
1217
+ */
1218
+ modalMaxHeight?: string;
1219
+ /**
1220
+ * Configuration for the "peek" banner — the chrome-less row above the
1221
+ * collapsed pill that previews the most recent assistant message.
1222
+ */
1223
+ peek?: AgentWidgetComposerBarPeekConfig;
1224
+ };
1225
+
1226
+ /**
1227
+ * Configuration for the composer-bar peek banner. Reuses the same
1228
+ * `streamAnimation` shape developers already configure for the main message
1229
+ * stream, so the surface for animations is identical across both contexts.
1230
+ *
1231
+ * Resolution order:
1232
+ * - If `peek.streamAnimation` is set, those values apply to the peek.
1233
+ * - Otherwise the peek inherits from `features.streamAnimation`.
1234
+ *
1235
+ * Per-surface carve-outs:
1236
+ * - `bubbleClass` from a plugin (used by `pop-bubble`) is ignored — the peek
1237
+ * has no bubble analog.
1238
+ * - `containerClass`, `wrap` ("char" | "word"), `useCaret`, `placeholder`
1239
+ * ("skeleton"), `buffer` ("word" | "line"), `speed`, `duration`, and
1240
+ * custom plugins all apply unchanged.
1241
+ */
1242
+ export type AgentWidgetComposerBarPeekConfig = {
1243
+ /**
1244
+ * Reveal animation for the peek's trailing-message preview. Same shape as
1245
+ * `features.streamAnimation`. Omit to inherit from the main stream config.
1246
+ */
1247
+ streamAnimation?: AgentWidgetStreamAnimationFeature;
1248
+ };
1249
+
1014
1250
  export type AgentWidgetLauncherConfig = {
1015
1251
  enabled?: boolean;
1016
1252
  title?: string;
@@ -1025,14 +1261,22 @@ export type AgentWidgetLauncherConfig = {
1025
1261
  * Controls how the launcher panel is mounted relative to the host page.
1026
1262
  * - "floating": default floating launcher / panel behavior
1027
1263
  * - "docked": wraps the target container and renders as a sibling dock
1264
+ * - "composer-bar": persistent rounded-pill composer fixed to the bottom of
1265
+ * the viewport that morphs into a fullscreen (or modal) chat panel on
1266
+ * submit and minimizes back to the pill on close.
1028
1267
  *
1029
1268
  * @default "floating"
1030
1269
  */
1031
- mountMode?: "floating" | "docked";
1270
+ mountMode?: "floating" | "docked" | "composer-bar";
1032
1271
  /**
1033
1272
  * Layout configuration for docked mode.
1034
1273
  */
1035
1274
  dock?: AgentWidgetDockConfig;
1275
+ /**
1276
+ * Layout configuration for composer-bar mode.
1277
+ * Only applies when `mountMode === "composer-bar"`.
1278
+ */
1279
+ composerBar?: AgentWidgetComposerBarConfig;
1036
1280
  autoExpand?: boolean;
1037
1281
  width?: string;
1038
1282
  /**
@@ -2823,6 +3067,17 @@ export type AgentWidgetConfig = {
2823
3067
  autoFocusInput?: boolean;
2824
3068
  launcher?: AgentWidgetLauncherConfig;
2825
3069
  initialMessages?: AgentWidgetMessage[];
3070
+ /**
3071
+ * Artifacts to hydrate into the pane at init. Typically populated from
3072
+ * `storageAdapter.load()` alongside `initialMessages` so the artifact pane
3073
+ * survives a page refresh.
3074
+ */
3075
+ initialArtifacts?: PersonaArtifactRecord[];
3076
+ /**
3077
+ * Which artifact id (if any) should be selected in the pane at init. Paired
3078
+ * with `initialArtifacts`.
3079
+ */
3080
+ initialSelectedArtifactId?: string | null;
2826
3081
  suggestionChips?: string[];
2827
3082
  suggestionChipsConfig?: AgentWidgetSuggestionChipsConfig;
2828
3083
  debug?: boolean;
@@ -3207,6 +3462,13 @@ export type AgentWidgetConfig = {
3207
3462
  * When `true`, uses default settings with sessionStorage.
3208
3463
  * When an object, allows customizing storage type, key prefix, and what to persist.
3209
3464
  *
3465
+ * Setting this to `false` is the explicit kill-switch: it disables UI-state
3466
+ * persistence **and** message-history persistence. When `false`, any
3467
+ * `storageAdapter` you configure is ignored and the default localStorage
3468
+ * adapter is not created — no chat history is read or written. Pass `true`
3469
+ * (or omit) to keep the default behavior of persisting messages via the
3470
+ * configured `storageAdapter` (or the built-in localStorage adapter).
3471
+ *
3210
3472
  * @example
3211
3473
  * ```typescript
3212
3474
  * // Simple usage - persist open state in sessionStorage
@@ -3229,6 +3491,14 @@ export type AgentWidgetConfig = {
3229
3491
  * }
3230
3492
  * }
3231
3493
  * ```
3494
+ *
3495
+ * @example
3496
+ * ```typescript
3497
+ * // Ephemeral widget — no message history written anywhere
3498
+ * config: {
3499
+ * persistState: false
3500
+ * }
3501
+ * ```
3232
3502
  */
3233
3503
  persistState?: boolean | AgentWidgetPersistStateConfig;
3234
3504