@runtypelabs/persona 4.14.0 → 4.15.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 (81) hide show
  1. package/README.md +4 -4
  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-DveIaNx6.d.cts → types-BpWGm7_6.d.cts} +17 -0
  5. package/dist/animations/{types-DveIaNx6.d.ts → types-BpWGm7_6.d.ts} +17 -0
  6. package/dist/animations/wipe.d.cts +1 -1
  7. package/dist/animations/wipe.d.ts +1 -1
  8. package/dist/chunk-QJ4LV2KW.js +1 -0
  9. package/dist/codegen.cjs +12 -11
  10. package/dist/codegen.js +14 -13
  11. package/dist/{context-mentions-ONG7A7M6.js → context-mentions-BTSTIBFC.js} +1 -1
  12. package/dist/context-mentions.cjs +11 -8
  13. package/dist/context-mentions.d.cts +241 -16
  14. package/dist/context-mentions.d.ts +241 -16
  15. package/dist/context-mentions.js +11 -8
  16. package/dist/index.cjs +67 -66
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +301 -41
  19. package/dist/index.d.ts +301 -41
  20. package/dist/index.global.js +59 -56
  21. package/dist/index.global.js.map +1 -1
  22. package/dist/index.js +67 -66
  23. package/dist/index.js.map +1 -1
  24. package/dist/launcher.global.js +5 -2
  25. package/dist/launcher.global.js.map +1 -1
  26. package/dist/smart-dom-reader.d.cts +241 -16
  27. package/dist/smart-dom-reader.d.ts +241 -16
  28. package/dist/theme-editor-preview.cjs +66 -66
  29. package/dist/theme-editor-preview.d.cts +255 -17
  30. package/dist/theme-editor-preview.d.ts +255 -17
  31. package/dist/theme-editor-preview.js +56 -56
  32. package/dist/theme-editor.cjs +5 -5
  33. package/dist/theme-editor.d.cts +242 -17
  34. package/dist/theme-editor.d.ts +242 -17
  35. package/dist/theme-editor.js +7 -7
  36. package/dist/theme-reference.cjs +1 -1
  37. package/dist/theme-reference.d.cts +38 -0
  38. package/dist/theme-reference.d.ts +38 -0
  39. package/dist/theme-reference.js +1 -1
  40. package/dist/widget.css +1 -1
  41. package/package.json +1 -1
  42. package/src/ask-user-question-tool.ts +10 -7
  43. package/src/components/artifact-preview.ts +1 -1
  44. package/src/components/composer-parts.test.ts +103 -4
  45. package/src/components/composer-parts.ts +53 -15
  46. package/src/components/messages.ts +5 -2
  47. package/src/components/panel.ts +31 -5
  48. package/src/components/pill-composer-builder.test.ts +18 -0
  49. package/src/components/suggestions.test.ts +233 -0
  50. package/src/components/suggestions.ts +463 -81
  51. package/src/components/widget-view.ts +4 -0
  52. package/src/defaults.ts +5 -3
  53. package/src/generated/runtype-openapi-contract.ts +17 -0
  54. package/src/index-core.ts +18 -2
  55. package/src/launcher-global.ts +1 -1
  56. package/src/plugins/types.ts +71 -3
  57. package/src/presets.ts +3 -3
  58. package/src/session.ts +10 -8
  59. package/src/styles/widget-styles.test.ts +162 -0
  60. package/src/styles/widget.css +430 -0
  61. package/src/suggest-replies-tool.test.ts +233 -2
  62. package/src/suggest-replies-tool.ts +115 -39
  63. package/src/theme-editor/preview-utils.test.ts +34 -0
  64. package/src/theme-editor/preview-utils.ts +77 -2
  65. package/src/theme-editor/sections.test.ts +33 -0
  66. package/src/theme-editor/sections.ts +53 -5
  67. package/src/theme-reference.ts +9 -2
  68. package/src/types/theme.ts +32 -0
  69. package/src/types.ts +152 -16
  70. package/src/ui.detached-panel.test.ts +1 -1
  71. package/src/ui.suggest-replies.test.ts +1066 -1
  72. package/src/ui.ts +268 -20
  73. package/src/utils/artifact-file.test.ts +1 -1
  74. package/src/utils/code-generators.test.ts +40 -0
  75. package/src/utils/code-generators.ts +22 -0
  76. package/src/utils/config-merge.test.ts +24 -0
  77. package/src/utils/icons.test.ts +26 -0
  78. package/src/utils/icons.ts +8 -0
  79. package/src/utils/theme.test.ts +79 -0
  80. package/src/utils/tokens.ts +64 -0
  81. package/dist/chunk-MMUPR2JW.js +0 -1
@@ -1,5 +1,39 @@
1
1
  import { IconNode } from 'lucide';
2
2
 
3
+ type AgentWidgetTransformSuggestionsContext = {
4
+ /**
5
+ * Fresh copy of the suggestions entering this plugin, already normalized:
6
+ * shorthand strings expanded and the effective send/fill behavior resolved.
7
+ */
8
+ suggestions: AgentWidgetResolvedSuggestion[];
9
+ surface: AgentWidgetSuggestionSurface;
10
+ source: AgentWidgetSuggestionSource;
11
+ config: AgentWidgetConfig;
12
+ };
13
+ type AgentWidgetRenderSuggestionContext = {
14
+ /** Fully normalized suggestion, including the effective send/fill behavior. */
15
+ suggestion: AgentWidgetResolvedSuggestion;
16
+ index: number;
17
+ surface: AgentWidgetSuggestionSurface;
18
+ source: AgentWidgetSuggestionSource;
19
+ variant: AgentWidgetSuggestionVariant;
20
+ streaming: boolean;
21
+ config: AgentWidgetConfig;
22
+ /** Build Persona's standard chip, card, or list item. */
23
+ defaultRenderer: () => HTMLElement;
24
+ /**
25
+ * Run the normal selection pipeline: DOM event, plugin selection hooks, then
26
+ * send or fill. Custom renderers should call this instead of sending directly.
27
+ */
28
+ select: () => void;
29
+ };
30
+ type AgentWidgetSuggestionSelectContext = {
31
+ suggestion: AgentWidgetResolvedSuggestion;
32
+ surface: AgentWidgetSuggestionSurface;
33
+ source: AgentWidgetSuggestionSource;
34
+ variant: AgentWidgetSuggestionVariant;
35
+ config: AgentWidgetConfig;
36
+ };
3
37
  /**
4
38
  * Plugin interface for customizing widget components
5
39
  */
@@ -12,6 +46,25 @@ interface AgentWidgetPlugin {
12
46
  * Optional priority (higher = runs first). Default: 0
13
47
  */
14
48
  priority?: number;
49
+ /**
50
+ * Transform, filter, enrich, or reorder suggestions. Hooks receive normalized
51
+ * items and compose in plugin priority order; the return value may use the
52
+ * loose shape (string shorthand included) and is re-normalized before the next
53
+ * hook. A per-item `behavior` set here survives. `maxItems` caps the list
54
+ * after the full chain. Return an empty array to hide the surface.
55
+ */
56
+ transformSuggestions?: (context: AgentWidgetTransformSuggestionsContext) => AgentWidgetSuggestion[];
57
+ /**
58
+ * Render one starter or follow-up suggestion. Return null to use Persona's
59
+ * default chip/card/list renderer. Call `select()` from custom interaction
60
+ * controls to preserve events, selection hooks, and send/fill behavior.
61
+ */
62
+ renderSuggestion?: (context: AgentWidgetRenderSuggestionContext) => HTMLElement | null;
63
+ /**
64
+ * Observe or intercept a suggestion selection. Return false to cancel the
65
+ * built-in send/fill action. Hooks run in plugin priority order.
66
+ */
67
+ onSuggestionSelect?: (context: AgentWidgetSuggestionSelectContext) => void | boolean;
15
68
  /**
16
69
  * Custom renderer for message bubbles
17
70
  * Return null to use default renderer
@@ -607,6 +660,14 @@ interface ReasoningBubbleTokens {
607
660
  interface ComposerChromeTokens {
608
661
  /** Box-shadow on the composer form (raw CSS, e.g. `none`). */
609
662
  shadow: string;
663
+ /** Inner padding of the composer form (raw CSS shorthand). @default "0.75rem 1rem" */
664
+ padding?: string;
665
+ /** Gap between the textarea row and the actions row. @default "0.5rem" */
666
+ gap?: string;
667
+ /** Composer textarea font-size. @default "0.875rem" */
668
+ fontSize?: string;
669
+ /** Composer textarea line-height. @default "1.25rem" */
670
+ lineHeight?: string;
610
671
  }
611
672
  /** Artifact toolbar chrome. */
612
673
  interface ArtifactToolbarTokens {
@@ -756,6 +817,26 @@ interface ScrollToBottomTokens extends ComponentTokenSet {
756
817
  fontSize?: string;
757
818
  iconSize?: string;
758
819
  }
820
+ /** Visual tokens shared by one suggestion presentation variant. */
821
+ interface SuggestionVariantTokens extends ComponentTokenSet {
822
+ gap?: string;
823
+ minHeight?: string;
824
+ fontSize?: string;
825
+ lineHeight?: string;
826
+ iconSize?: string;
827
+ hoverBackground?: TokenReference<'color'>;
828
+ hoverForeground?: TokenReference<'color'>;
829
+ hoverBorder?: TokenReference<'color'>;
830
+ pressedBackground?: TokenReference<'color'>;
831
+ focusRing?: TokenReference<'color'>;
832
+ disabledOpacity?: string;
833
+ }
834
+ /** Starter and follow-up suggestion chrome. */
835
+ interface SuggestionTokens {
836
+ chip: SuggestionVariantTokens;
837
+ card: SuggestionVariantTokens;
838
+ list: SuggestionVariantTokens;
839
+ }
759
840
  /** Toggle group chrome (used by createToggleGroup). */
760
841
  interface ToggleGroupTokens {
761
842
  /** Gap between toggle buttons. Default: 0 (connected). */
@@ -786,6 +867,8 @@ interface ComponentTokens {
786
867
  labelButton?: LabelButtonTokens;
787
868
  /** Scroll-to-bottom indicator styling tokens. */
788
869
  scrollToBottom?: ScrollToBottomTokens;
870
+ /** Starter prompt and follow-up suggestion styling tokens. */
871
+ suggestion?: SuggestionTokens;
789
872
  /** Toggle group styling tokens. */
790
873
  toggleGroup?: ToggleGroupTokens;
791
874
  /** Artifact toolbar, tab strip, and pane chrome. */
@@ -1080,7 +1163,24 @@ type RuntypeExecutionStreamEvent = ({
1080
1163
  type: "source";
1081
1164
  url?: string;
1082
1165
  [key: string]: unknown;
1166
+ } | {
1167
+ executionId: string;
1168
+ iteration?: number;
1169
+ seq: number;
1170
+ state: Record<string, unknown>;
1171
+ type: "state_snapshot";
1083
1172
  } | ({
1173
+ executionId: string;
1174
+ iteration?: number;
1175
+ patch: Array<{
1176
+ from?: string;
1177
+ op: "add" | "remove" | "replace" | "move" | "copy" | "test";
1178
+ path: string;
1179
+ value?: unknown;
1180
+ }>;
1181
+ seq: number;
1182
+ type: "state_delta";
1183
+ }) | ({
1084
1184
  executionId: string;
1085
1185
  hiddenParameterNames?: Array<string>;
1086
1186
  iteration?: number;
@@ -1322,6 +1422,7 @@ declare const LUCIDE_ICONS: {
1322
1422
  readonly plus: IconNode;
1323
1423
  readonly minus: IconNode;
1324
1424
  readonly pencil: IconNode;
1425
+ readonly "pen-line": IconNode;
1325
1426
  readonly trash: IconNode;
1326
1427
  readonly "trash-2": IconNode;
1327
1428
  readonly save: IconNode;
@@ -1364,11 +1465,13 @@ declare const LUCIDE_ICONS: {
1364
1465
  readonly folder: IconNode;
1365
1466
  readonly "folder-open": IconNode;
1366
1467
  readonly files: IconNode;
1468
+ readonly "chart-column": IconNode;
1367
1469
  readonly sparkles: IconNode;
1368
1470
  readonly zap: IconNode;
1369
1471
  readonly sun: IconNode;
1370
1472
  readonly moon: IconNode;
1371
1473
  readonly flag: IconNode;
1474
+ readonly lightbulb: IconNode;
1372
1475
  readonly monitor: IconNode;
1373
1476
  readonly smartphone: IconNode;
1374
1477
  };
@@ -3327,10 +3430,13 @@ type AgentWidgetFeatureFlags = {
3327
3430
  */
3328
3431
  askUserQuestion?: AgentWidgetAskUserQuestionFeature;
3329
3432
  /**
3330
- * Built-in `suggest_replies` quick-reply chips. When the assistant invokes
3331
- * the tool, the widget shows the suggestions as tappable chips above the
3332
- * composer (reusing the suggestion-chips surface) and immediately resumes
3333
- * the execution: fire-and-forget, no user input awaited.
3433
+ * Built-in `suggest_replies` follow-ups. When the assistant invokes the
3434
+ * tool, the widget shows the suggestions using `suggestions.followUps` and
3435
+ * immediately resumes the execution: fire-and-forget, no user input awaited.
3436
+ *
3437
+ * @deprecated Both keys moved to `suggestions.followUps`: use
3438
+ * `suggestions.followUps.enabled` and `suggestions.followUps.expose`. This
3439
+ * alias keeps working per key, with `suggestions.followUps` winning.
3334
3440
  */
3335
3441
  suggestReplies?: AgentWidgetSuggestRepliesFeature;
3336
3442
  };
@@ -3370,11 +3476,12 @@ type WidgetPreferenceSlice = {
3370
3476
  };
3371
3477
  };
3372
3478
  /**
3373
- * Feature config for the built-in `suggest_replies` quick-reply chips.
3374
- * Chips render in the existing suggestions slot above the composer and are
3375
- * styled by the widget-level `suggestionChipsConfig`. A tapped chip is sent
3376
- * verbatim as the user's next message; chips clear once any user message
3377
- * follows them.
3479
+ * Feature config for the built-in `suggest_replies` follow-ups.
3480
+ *
3481
+ * @deprecated Both keys moved to `suggestions.followUps`
3482
+ * (`suggestions.followUps.enabled` / `suggestions.followUps.expose`), which
3483
+ * also owns presentation, placement, and send/fill behavior. Resolution is
3484
+ * per key with `suggestions.followUps` winning; removal waits for 5.0.
3378
3485
  */
3379
3486
  type AgentWidgetSuggestRepliesFeature = {
3380
3487
  /**
@@ -3382,14 +3489,18 @@ type AgentWidgetSuggestRepliesFeature = {
3382
3489
  * renders as a regular tool bubble and is NOT auto-resumed: only set this
3383
3490
  * with no server-side `suggest_replies` declaration, or the execution
3384
3491
  * parks awaiting a resume that never comes.
3492
+ * @deprecated Use `suggestions.followUps.enabled`.
3385
3493
  */
3386
3494
  enabled?: boolean;
3387
3495
  /**
3388
3496
  * Advertise the built-in `suggest_replies` tool to the agent on every
3389
3497
  * dispatch via `clientTools[]`: no server-side `runtimeTools` declaration
3390
- * needed. Defaults to `false`: flows that already declare the tool via
3391
- * `runtimeTools` would otherwise present it to the model twice. Ignored
3392
- * when `enabled` is `false`.
3498
+ * needed. Defaults to `false`. Declare the tool in one place: the API
3499
+ * dedupes a double declaration by name with `clientTools[]` winning, so the
3500
+ * model still sees exactly one tool, but the widget's description and schema
3501
+ * win and the effective tool type becomes `local` (the execution pauses and
3502
+ * the widget auto-resumes it). Ignored when `enabled` is `false`.
3503
+ * @deprecated Use `suggestions.followUps.expose`.
3393
3504
  */
3394
3505
  expose?: boolean;
3395
3506
  };
@@ -3459,10 +3570,13 @@ type AgentWidgetAskUserQuestionFeature = {
3459
3570
  * matching {@link AskUserQuestionPayload}; when the model calls it, the
3460
3571
  * existing answer-pill sheet renders and the answer resumes the execution.
3461
3572
  *
3462
- * Defaults to `false`: flows that already declare `ask_user_question` via
3463
- * `runtimeTools` would otherwise present the tool to the model twice.
3464
- * Ignored when `enabled` is `false`: never offer the agent a question
3465
- * tool the widget can't render an answer UI for.
3573
+ * Defaults to `false`. Declare the tool in one place: the API dedupes a
3574
+ * double declaration by name with `clientTools[]` winning, so the model
3575
+ * still sees exactly one tool, but the widget's description and schema win
3576
+ * and the effective tool type becomes `local` (the execution pauses and the
3577
+ * widget resumes it with the user's answer). Ignored when `enabled` is
3578
+ * `false`: never offer the agent a question tool the widget can't render an
3579
+ * answer UI for.
3466
3580
  */
3467
3581
  expose?: boolean;
3468
3582
  /** Slide-in animation duration in ms. Defaults to 180. */
@@ -3935,6 +4049,10 @@ type AgentWidgetSendButtonConfig = {
3935
4049
  paddingY?: string;
3936
4050
  iconText?: string;
3937
4051
  iconName?: string;
4052
+ /** Icon glyph box in icon mode, e.g. "20px". Defaults to half of `size`. */
4053
+ iconSize?: string;
4054
+ /** Stroke width for the icon glyph, in viewBox units. Default 2. */
4055
+ iconStrokeWidth?: number;
3938
4056
  useIcon?: boolean;
3939
4057
  tooltipText?: string;
3940
4058
  showTooltip?: boolean;
@@ -4658,6 +4776,109 @@ type AgentWidgetSuggestionChipsConfig = {
4658
4776
  paddingX?: string;
4659
4777
  paddingY?: string;
4660
4778
  };
4779
+ /** A suggested next action shown to the user. Strings remain supported as shorthand. */
4780
+ type AgentWidgetSuggestion = string | {
4781
+ /** Stable analytics / DOM identity. Falls back to the prompt or label. */
4782
+ id?: string;
4783
+ /** Concise visible action label. */
4784
+ label: string;
4785
+ /** Text placed in the composer or sent. Defaults to `label`. */
4786
+ prompt?: string;
4787
+ /** Optional supporting copy, most useful with the `card` variant. */
4788
+ description?: string;
4789
+ /** Optional icon from Persona's bundled Lucide registry. */
4790
+ icon?: IconName;
4791
+ /**
4792
+ * CSS color for this item's glyph. Tints the icon only: label, border,
4793
+ * and background stay neutral. Ignored without an `icon`.
4794
+ */
4795
+ iconColor?: string;
4796
+ /** Override the surface's click behavior for this item. */
4797
+ behavior?: AgentWidgetSuggestionBehavior;
4798
+ /** Visually promote one high-confidence action. */
4799
+ emphasis?: "default" | "primary";
4800
+ };
4801
+ type AgentWidgetSuggestionBehavior = "send" | "fill";
4802
+ type AgentWidgetSuggestionVariant = "chip" | "card" | "list";
4803
+ type AgentWidgetSuggestionSurface = "starter" | "followUp";
4804
+ /**
4805
+ * Who produced the rendered suggestions: static config, the agent's
4806
+ * `suggest_replies` tool, or `controller.setFollowUpSuggestions`.
4807
+ */
4808
+ type AgentWidgetSuggestionSource = "config" | "agent" | "host";
4809
+ /**
4810
+ * A suggestion after Persona has normalized shorthand strings and resolved the
4811
+ * effective click behavior. Plugin hooks receive this stable shape.
4812
+ */
4813
+ type AgentWidgetResolvedSuggestion = {
4814
+ id: string;
4815
+ label: string;
4816
+ prompt: string;
4817
+ description?: string;
4818
+ icon?: IconName;
4819
+ /** CSS color for the glyph only; never the label, border, or background. */
4820
+ iconColor?: string;
4821
+ behavior: AgentWidgetSuggestionBehavior;
4822
+ emphasis: "default" | "primary";
4823
+ };
4824
+ /** Presentation keys shared by every suggestion surface. */
4825
+ type AgentWidgetSuggestionSurfaceConfig = {
4826
+ /** Item density. Defaults to `card` for starters and `chip` for follow-ups. */
4827
+ variant?: AgentWidgetSuggestionVariant;
4828
+ /** Default click behavior, overridable per item. Defaults to `send`. */
4829
+ behavior?: AgentWidgetSuggestionBehavior;
4830
+ /**
4831
+ * Layout for items past the surface width. Defaults to `wrap` for starters
4832
+ * and `scroll` for follow-ups. Applies to the `chip` variant only; the
4833
+ * `card` and `list` layouts manage their own stacking.
4834
+ */
4835
+ overflow?: "scroll" | "wrap";
4836
+ /** Maximum visible items. Defaults to 4. */
4837
+ maxItems?: number;
4838
+ };
4839
+ type AgentWidgetStarterSuggestionsConfig = AgentWidgetSuggestionSurfaceConfig & {
4840
+ /** Suggestions shown before the first user message. */
4841
+ items?: AgentWidgetSuggestion[];
4842
+ /**
4843
+ * `auto` uses the welcome surface when the welcome card renders and the
4844
+ * composer otherwise. Explicit values are literal: `welcome` renders
4845
+ * nothing when the welcome card is hidden. Defaults to `auto`.
4846
+ */
4847
+ placement?: "auto" | "welcome" | "composer";
4848
+ };
4849
+ type AgentWidgetFollowUpSuggestionsConfig = AgentWidgetSuggestionSurfaceConfig & {
4850
+ /**
4851
+ * Enable the built-in `suggest_replies` follow-ups. Defaults to true. When
4852
+ * false, `suggest_replies` renders as a regular tool bubble and is NOT
4853
+ * auto-resumed: only set this with no server-side `suggest_replies`
4854
+ * declaration, or the execution parks awaiting a resume that never comes.
4855
+ */
4856
+ enabled?: boolean;
4857
+ /**
4858
+ * Advertise the built-in `suggest_replies` tool to the agent on every
4859
+ * dispatch via `clientTools[]`: no server-side `runtimeTools` declaration
4860
+ * needed. Defaults to `false`. Declare the tool in one place: the API
4861
+ * dedupes a double declaration by name with `clientTools[]` winning, so
4862
+ * the model still sees exactly one tool, but the widget's description and
4863
+ * schema win and the effective tool type becomes `local` (the execution
4864
+ * pauses and the widget auto-resumes it). Ignored when `enabled` is
4865
+ * `false`.
4866
+ */
4867
+ expose?: boolean;
4868
+ /**
4869
+ * `auto` places follow-ups after the transcript in regular panels and above
4870
+ * the composer in composer-bar mode. Defaults to `auto`.
4871
+ */
4872
+ placement?: "auto" | "after-message" | "composer";
4873
+ };
4874
+ /**
4875
+ * Structured suggestions configuration. The legacy `suggestionChips` and
4876
+ * `suggestionChipsConfig` fields remain supported for backwards compatibility.
4877
+ */
4878
+ type AgentWidgetSuggestionsConfig = {
4879
+ starters?: AgentWidgetStarterSuggestionsConfig;
4880
+ followUps?: AgentWidgetFollowUpSuggestionsConfig;
4881
+ };
4661
4882
  /**
4662
4883
  * Interface for pluggable stream parsers that extract text from streaming responses.
4663
4884
  * Parsers handle incremental parsing to extract text values from structured formats (JSON, XML, etc.).
@@ -5839,7 +6060,11 @@ type AgentWidgetConfig = {
5839
6060
  * with `initialArtifacts`.
5840
6061
  */
5841
6062
  initialSelectedArtifactId?: string | null;
6063
+ /** Rich starter and follow-up suggestion surfaces. */
6064
+ suggestions?: AgentWidgetSuggestionsConfig;
6065
+ /** @deprecated Prefer `suggestions.starters.items`. */
5842
6066
  suggestionChips?: string[];
6067
+ /** @deprecated Prefer semantic tokens under `theme.components.suggestion`. */
5843
6068
  suggestionChipsConfig?: AgentWidgetSuggestionChipsConfig;
5844
6069
  debug?: boolean;
5845
6070
  formEndpoint?: string;