@runtypelabs/persona 3.29.1 → 3.31.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 (68) hide show
  1. package/README.md +15 -2547
  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-B_Qazlm4.d.cts → types-quh7NmYD.d.cts} +9 -0
  5. package/dist/animations/{types-B_Qazlm4.d.ts → types-quh7NmYD.d.ts} +9 -0
  6. package/dist/animations/wipe.d.cts +1 -1
  7. package/dist/animations/wipe.d.ts +1 -1
  8. package/dist/codegen.cjs +6 -6
  9. package/dist/codegen.js +4 -4
  10. package/dist/index.cjs +50 -50
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +164 -7
  13. package/dist/index.d.ts +164 -7
  14. package/dist/index.global.js +60 -60
  15. package/dist/index.global.js.map +1 -1
  16. package/dist/index.js +49 -49
  17. package/dist/index.js.map +1 -1
  18. package/dist/launcher.global.js +2 -2
  19. package/dist/launcher.global.js.map +1 -1
  20. package/dist/plugin-kit.cjs +1 -0
  21. package/dist/plugin-kit.d.cts +98 -0
  22. package/dist/plugin-kit.d.ts +98 -0
  23. package/dist/plugin-kit.js +1 -0
  24. package/dist/smart-dom-reader.d.cts +157 -4
  25. package/dist/smart-dom-reader.d.ts +157 -4
  26. package/dist/theme-editor.cjs +40 -40
  27. package/dist/theme-editor.d.cts +161 -6
  28. package/dist/theme-editor.d.ts +161 -6
  29. package/dist/theme-editor.js +40 -40
  30. package/dist/theme-reference.cjs +1 -1
  31. package/dist/theme-reference.d.cts +2 -0
  32. package/dist/theme-reference.d.ts +2 -0
  33. package/dist/theme-reference.js +1 -1
  34. package/dist/widget.css +19 -0
  35. package/package.json +8 -2
  36. package/src/client.ts +6 -0
  37. package/src/components/approval-bubble.test.ts +320 -0
  38. package/src/components/approval-bubble.ts +190 -20
  39. package/src/components/launcher.ts +6 -3
  40. package/src/components/panel.ts +7 -1
  41. package/src/components/tool-bubble.test.ts +39 -0
  42. package/src/components/tool-bubble.ts +4 -0
  43. package/src/defaults.ts +14 -0
  44. package/src/generated/runtype-openapi-contract.ts +4 -0
  45. package/src/index-core.ts +1 -0
  46. package/src/plugin-kit.test.ts +230 -0
  47. package/src/plugin-kit.ts +294 -0
  48. package/src/plugins/types.ts +49 -2
  49. package/src/session.test.ts +161 -0
  50. package/src/session.ts +41 -3
  51. package/src/styles/widget.css +19 -0
  52. package/src/theme-editor/preview-utils.test.ts +10 -0
  53. package/src/theme-editor/preview-utils.ts +29 -1
  54. package/src/theme-editor/sections.test.ts +17 -0
  55. package/src/theme-editor/sections.ts +31 -0
  56. package/src/theme-reference.ts +2 -2
  57. package/src/types/theme.ts +2 -0
  58. package/src/types.ts +109 -2
  59. package/src/ui.approval-plugin.test.ts +204 -0
  60. package/src/ui.scroll.test.ts +383 -0
  61. package/src/ui.ts +539 -56
  62. package/src/utils/auto-follow.test.ts +91 -0
  63. package/src/utils/auto-follow.ts +68 -0
  64. package/src/utils/theme.test.ts +6 -2
  65. package/src/utils/theme.ts +0 -8
  66. package/src/utils/tokens.ts +6 -1
  67. package/src/webmcp-bridge.test.ts +66 -0
  68. package/src/webmcp-bridge.ts +49 -0
@@ -416,13 +416,59 @@ interface AgentWidgetPlugin {
416
416
  config: AgentWidgetConfig;
417
417
  }) => HTMLElement | null;
418
418
  /**
419
- * Custom renderer for approval bubbles
420
- * Return null to use default renderer
419
+ * Custom renderer for approval bubbles.
420
+ *
421
+ * Return an `HTMLElement` to fully own the approval UI, `defaultRenderer()`
422
+ * to render (or wrap) the built-in bubble, or `null` to fall through to the
423
+ * default. Unlike the built-in bubble — whose Approve/Deny buttons are wired
424
+ * via delegation — a fully custom element resolves the approval by calling
425
+ * the `approve`/`deny` callbacks. Both route through the same path the
426
+ * built-in buttons use (optimistic update, `onDecision`, in-place anchoring).
427
+ *
428
+ * An approval is a single binary gate, so there are exactly two outcomes.
429
+ * Pass `{ remember: true }` to flag a "remember this" affordance (e.g. an
430
+ * "Always allow" button); the current approval resolves identically, but the
431
+ * flag is forwarded to `config.approval.onDecision` so you can persist a
432
+ * don't-ask-again policy for future approvals.
433
+ *
434
+ * `renderApproval` is called again whenever the approval's status changes, so
435
+ * branch on `message.approval?.status` to render the resolved state (and tear
436
+ * down any global listeners you added while pending).
437
+ *
438
+ * @example
439
+ * ```typescript
440
+ * // An alternative prompt: "Always allow" / "Allow once" / "Deny".
441
+ * renderApproval: ({ message, approve, deny }) => {
442
+ * const approval = message.approval;
443
+ * if (!approval || approval.status !== "pending") return null; // default renders resolved state
444
+ * const root = document.createElement("div");
445
+ * root.textContent = `${approval.toolName} requires approval`;
446
+ *
447
+ * const always = document.createElement("button");
448
+ * always.textContent = "Always allow";
449
+ * always.addEventListener("click", () => approve({ remember: true }));
450
+ *
451
+ * const once = document.createElement("button");
452
+ * once.textContent = "Allow once";
453
+ * once.addEventListener("click", () => approve());
454
+ *
455
+ * const no = document.createElement("button");
456
+ * no.textContent = "Deny";
457
+ * no.addEventListener("click", () => deny());
458
+ *
459
+ * root.append(always, once, no);
460
+ * return root;
461
+ * }
462
+ * ```
421
463
  */
422
464
  renderApproval?: (context: {
423
465
  message: AgentWidgetMessage;
424
466
  defaultRenderer: () => HTMLElement;
425
467
  config: AgentWidgetConfig;
468
+ /** Resolve this approval as approved. Pass `{ remember: true }` for an "Always allow" affordance. */
469
+ approve: (options?: AgentWidgetApprovalDecisionOptions) => void;
470
+ /** Resolve this approval as denied. Pass `{ remember: true }` for an "Always deny" affordance. */
471
+ deny: (options?: AgentWidgetApprovalDecisionOptions) => void;
426
472
  }) => HTMLElement | null;
427
473
  /**
428
474
  * Custom renderer for loading indicator
@@ -797,6 +843,8 @@ interface ApprovalTokens {
797
843
  background: TokenReference<'color'>;
798
844
  border: TokenReference<'color'>;
799
845
  text: TokenReference<'color'>;
846
+ /** Box-shadow for the approval bubble (token ref or raw CSS, e.g. `none`). */
847
+ shadow: string;
800
848
  };
801
849
  approve: ComponentTokenSet;
802
850
  deny: ComponentTokenSet;
@@ -1113,6 +1161,7 @@ type RuntypeAgentSSEEvent = {
1113
1161
  };
1114
1162
  iteration?: number;
1115
1163
  parameters?: Record<string, unknown>;
1164
+ reason?: string;
1116
1165
  seq: number;
1117
1166
  startedAt: string;
1118
1167
  timeout: number;
@@ -1384,6 +1433,7 @@ type RuntypeFlowSSEEvent = {
1384
1433
  when: string;
1385
1434
  } | {
1386
1435
  executionId?: string;
1436
+ reason?: string;
1387
1437
  seq?: number;
1388
1438
  type: "step_await";
1389
1439
  [key: string]: unknown;
@@ -1715,6 +1765,12 @@ type WebMcpConfirmInfo = {
1715
1765
  toolName: string;
1716
1766
  args: unknown;
1717
1767
  description?: string;
1768
+ /**
1769
+ * Display title the tool declared via the WebMCP spec's
1770
+ * `ToolDescriptor.title` (e.g. `"Add to Cart"`). Absent when the tool
1771
+ * didn't declare one.
1772
+ */
1773
+ title?: string;
1718
1774
  annotations?: {
1719
1775
  readOnlyHint?: boolean;
1720
1776
  untrustedContentHint?: boolean;
@@ -2110,6 +2166,29 @@ type AgentWidgetArtifactsFeature = {
2110
2166
  defaultRenderer: () => HTMLElement;
2111
2167
  }) => HTMLElement | null;
2112
2168
  };
2169
+ /**
2170
+ * How the transcript scrolls while an assistant response streams in.
2171
+ *
2172
+ * - `"follow"` (default): keep the newest content pinned to the bottom of the
2173
+ * viewport, pausing when the user scrolls up and resuming when they return
2174
+ * to the bottom.
2175
+ * - `"anchor-top"`: on send, scroll the user's message near the top of the
2176
+ * viewport and hold it there while the response streams in beneath it
2177
+ * (ChatGPT-style). The transcript never auto-scrolls during streaming.
2178
+ * - `"none"`: never auto-scroll; the scroll-to-bottom affordance is the only
2179
+ * way back to the latest content.
2180
+ */
2181
+ type AgentWidgetScrollMode = "follow" | "anchor-top" | "none";
2182
+ type AgentWidgetScrollBehaviorFeature = {
2183
+ /** Scroll behavior during streamed responses. @default "follow" */
2184
+ mode?: AgentWidgetScrollMode;
2185
+ /**
2186
+ * Gap (px) kept between the anchored user message and the top of the
2187
+ * viewport in `"anchor-top"` mode.
2188
+ * @default 16
2189
+ */
2190
+ anchorTopOffset?: number;
2191
+ };
2113
2192
  type AgentWidgetScrollToBottomFeature = {
2114
2193
  /**
2115
2194
  * When true, Persona shows a scroll-to-bottom affordance when the user breaks
@@ -2373,6 +2452,8 @@ type AgentWidgetFeatureFlags = {
2373
2452
  composerHistory?: boolean;
2374
2453
  /** Shared transcript + event stream scroll-to-bottom affordance. */
2375
2454
  scrollToBottom?: AgentWidgetScrollToBottomFeature;
2455
+ /** Transcript scroll behavior during streamed responses. */
2456
+ scrollBehavior?: AgentWidgetScrollBehaviorFeature;
2376
2457
  /** Collapsed transcript behavior for tool call rows. */
2377
2458
  toolCallDisplay?: AgentWidgetToolCallDisplayFeature;
2378
2459
  /** Collapsed transcript behavior for reasoning rows. */
@@ -3029,6 +3110,22 @@ type TextToSpeechConfig = {
3029
3110
  /** Speech pitch (0 - 2). Default: 1 */
3030
3111
  pitch?: number;
3031
3112
  };
3113
+ /**
3114
+ * Extra context for an approval decision, surfaced to `onDecision` and to the
3115
+ * `approve`/`deny` callbacks passed to the `renderApproval` plugin hook.
3116
+ */
3117
+ type AgentWidgetApprovalDecisionOptions = {
3118
+ /**
3119
+ * The user chose a "remember this" affordance (e.g. an "Always allow"
3120
+ * button) rather than a one-time decision. The widget resolves the *current*
3121
+ * approval identically whether or not this is set — an approval bubble is a
3122
+ * single binary gate (`approved`/`denied`). Persisting a don't-ask-again
3123
+ * policy for *future* approvals (auto-resolving them, or not surfacing them)
3124
+ * is the integrator's responsibility, typically inside `onDecision`.
3125
+ * Defaults to absent/`false`.
3126
+ */
3127
+ remember?: boolean;
3128
+ };
3032
3129
  /**
3033
3130
  * Configuration for tool approval bubbles.
3034
3131
  * Controls styling, labels, and behavior of the approval UI.
@@ -3038,6 +3135,8 @@ type AgentWidgetApprovalConfig = {
3038
3135
  backgroundColor?: string;
3039
3136
  /** Border color of the approval bubble */
3040
3137
  borderColor?: string;
3138
+ /** Box-shadow for the approval bubble; pass `"none"` to remove it. Overrides the default `persona-shadow-sm`. */
3139
+ shadow?: string;
3041
3140
  /** Color for the title text */
3042
3141
  titleColor?: string;
3043
3142
  /** Color for the description text */
@@ -3060,20 +3159,67 @@ type AgentWidgetApprovalConfig = {
3060
3159
  approveLabel?: string;
3061
3160
  /** Label for the deny button */
3062
3161
  denyLabel?: string;
3162
+ /**
3163
+ * Color for the agent-authored reason line (the agent's per-call
3164
+ * justification, shown attributed below the summary when present).
3165
+ */
3166
+ reasonColor?: string;
3167
+ /**
3168
+ * Label prefix for the agent-authored reason line.
3169
+ * Defaults to "Agent's stated reason:".
3170
+ */
3171
+ reasonLabel?: string;
3172
+ /**
3173
+ * How the technical details (the tool's agent-facing description and the
3174
+ * raw parameters JSON) are presented:
3175
+ * - `"collapsed"` (default) — hidden behind a "Show details" toggle
3176
+ * - `"expanded"` — visible, with the toggle available to hide them
3177
+ * - `"hidden"` — never rendered
3178
+ */
3179
+ detailsDisplay?: "collapsed" | "expanded" | "hidden";
3180
+ /** Label for the toggle that reveals the technical details */
3181
+ showDetailsLabel?: string;
3182
+ /** Label for the toggle that hides the technical details */
3183
+ hideDetailsLabel?: string;
3184
+ /**
3185
+ * Build the user-facing summary line for an approval request. Overrides the
3186
+ * default "The assistant wants to use “Tool name”." copy. Return a falsy
3187
+ * value to fall back to the default for that approval. `displayTitle` is
3188
+ * the display name the tool declared via the WebMCP spec's
3189
+ * `ToolDescriptor.title`, when one exists.
3190
+ */
3191
+ formatDescription?: (approval: {
3192
+ toolName: string;
3193
+ toolType?: string;
3194
+ description: string;
3195
+ parameters?: unknown;
3196
+ displayTitle?: string;
3197
+ /**
3198
+ * Agent-authored justification for this specific call, when the agent
3199
+ * provided one. It is the agent's own claim — if you fold it into the
3200
+ * summary, keep it attributed to the agent.
3201
+ */
3202
+ reason?: string;
3203
+ }) => string | undefined;
3063
3204
  /**
3064
3205
  * Custom handler for approval decisions.
3065
3206
  * Return void to let the SDK auto-resolve via the API,
3066
3207
  * or return a Response/ReadableStream for custom handling.
3208
+ *
3209
+ * `options.remember` is `true` when the decision came from a "remember this"
3210
+ * affordance (e.g. an "Always allow" button in a custom `renderApproval`
3211
+ * plugin). Use it to persist a don't-ask-again policy for future approvals;
3212
+ * the current approval resolves the same way regardless.
3067
3213
  */
3068
3214
  onDecision?: (data: {
3069
3215
  approvalId: string;
3070
3216
  executionId: string;
3071
3217
  agentId: string;
3072
3218
  toolName: string;
3073
- }, decision: 'approved' | 'denied') => Promise<Response | ReadableStream<Uint8Array> | void>;
3219
+ }, decision: 'approved' | 'denied', options?: AgentWidgetApprovalDecisionOptions) => Promise<Response | ReadableStream<Uint8Array> | void>;
3074
3220
  };
3075
3221
  type AgentWidgetToolCallConfig = {
3076
- /** Box-shadow for tool-call bubbles; overrides `theme.toolBubbleShadow` when set. */
3222
+ /** Box-shadow for tool-call bubbles; pass `"none"` to remove it. Overrides the `components.toolBubble.shadow` token / `--persona-tool-bubble-shadow`. */
3077
3223
  shadow?: string;
3078
3224
  /** Background color of the tool call bubble container. */
3079
3225
  backgroundColor?: string;
@@ -4863,6 +5009,13 @@ type AgentWidgetApproval = {
4863
5009
  toolName: string;
4864
5010
  toolType?: string;
4865
5011
  description: string;
5012
+ /**
5013
+ * Agent-authored justification for this specific call (the agent's own
5014
+ * claim about its intent, extracted server-side from the reserved
5015
+ * `_approvalReason` parameter). Render it attributed to the agent and as
5016
+ * plain text — it is approver context, not a system statement.
5017
+ */
5018
+ reason?: string;
4866
5019
  parameters?: unknown;
4867
5020
  resolvedAt?: number;
4868
5021
  };