@runtypelabs/persona 3.37.0 → 4.1.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 (55) hide show
  1. package/README.md +4 -5
  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-DgYsuwXL.d.cts → types-B_xbfvR0.d.cts} +263 -181
  5. package/dist/animations/{types-DgYsuwXL.d.ts → types-B_xbfvR0.d.ts} +263 -181
  6. package/dist/animations/wipe.d.cts +1 -1
  7. package/dist/animations/wipe.d.ts +1 -1
  8. package/dist/codegen.cjs +1 -1
  9. package/dist/codegen.js +1 -1
  10. package/dist/index.cjs +54 -52
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +328 -839
  13. package/dist/index.d.ts +328 -839
  14. package/dist/index.global.js +41 -39
  15. package/dist/index.global.js.map +1 -1
  16. package/dist/index.js +54 -52
  17. package/dist/index.js.map +1 -1
  18. package/dist/install.global.js +1 -1
  19. package/dist/install.global.js.map +1 -1
  20. package/dist/smart-dom-reader.d.cts +269 -192
  21. package/dist/smart-dom-reader.d.ts +269 -192
  22. package/dist/theme-editor-preview.cjs +55 -53
  23. package/dist/theme-editor-preview.d.cts +269 -192
  24. package/dist/theme-editor-preview.d.ts +269 -192
  25. package/dist/theme-editor-preview.js +57 -55
  26. package/dist/theme-editor.d.cts +269 -192
  27. package/dist/theme-editor.d.ts +269 -192
  28. package/dist/widget.css +14 -0
  29. package/package.json +1 -1
  30. package/src/client.test.ts +446 -1041
  31. package/src/client.ts +684 -967
  32. package/src/components/message-bubble.ts +7 -0
  33. package/src/components/tool-bubble.ts +46 -33
  34. package/src/generated/runtype-openapi-contract.ts +210 -714
  35. package/src/index-core.ts +2 -3
  36. package/src/install.test.ts +1 -34
  37. package/src/install.ts +1 -26
  38. package/src/runtime/init.test.ts +8 -67
  39. package/src/runtime/init.ts +2 -17
  40. package/src/session.test.ts +8 -8
  41. package/src/session.ts +1 -1
  42. package/src/styles/widget.css +14 -0
  43. package/src/types.ts +12 -13
  44. package/src/ui.postprocess.test.ts +107 -0
  45. package/src/ui.ts +45 -5
  46. package/src/utils/__fixtures__/unified-translator.oracle.ts +62 -14
  47. package/src/utils/copy-selection.test.ts +37 -0
  48. package/src/utils/copy-selection.ts +19 -0
  49. package/src/utils/event-stream-capture.test.ts +9 -64
  50. package/src/utils/streaming-table.test.ts +100 -0
  51. package/src/utils/streaming-table.ts +103 -0
  52. package/src/utils/sequence-buffer.test.ts +0 -256
  53. package/src/utils/sequence-buffer.ts +0 -130
  54. package/src/utils/unified-event-bridge.test.ts +0 -263
  55. package/src/utils/unified-event-bridge.ts +0 -431
package/README.md CHANGED
@@ -96,7 +96,6 @@ const docked = initAgentWidget({
96
96
  | `config` | `AgentWidgetConfig` | Widget configuration object (see the [Configuration Reference](./docs/CONFIGURATION-REFERENCE.md)). |
97
97
  | `useShadowDom` | `boolean` | Use Shadow DOM for style isolation (default: `false`). |
98
98
  | `onChatReady` | `() => void` | Callback fired when the widget is initialized and its API is callable. |
99
- | `onReady` | `() => void` | **Deprecated** alias of `onChatReady`; still works, removed in the next major. |
100
99
  | `windowKey` | `string` | If provided, stores the controller on `window[windowKey]` for global access. Automatically cleaned up on `destroy()`. |
101
100
 
102
101
  When `config.launcher.mountMode` is `'docked'`, `target` is treated as the page container that Persona should wrap. Use a concrete element such as `#workspace-main`; `body` and `html` are rejected.
@@ -125,9 +124,9 @@ The full reference lives in [`docs/`](./docs/) and the theming guide:
125
124
  - [Code Generator](./docs/CODE-GENERATOR.md): `@runtypelabs/persona/codegen` options for CLI/server-side snippet generation
126
125
  - [THEME-CONFIG.md](./THEME-CONFIG.md): the complete theme and design-token reference
127
126
 
128
- ### Optional proxy server
127
+ ### Optional Runtype proxy server
129
128
 
130
- The proxy server handles flow configuration and forwards requests to Runtype. You can configure it in three ways:
129
+ The `@runtypelabs/persona-proxy` package handles flow configuration and forwards requests to Runtype. You can configure it in three ways:
131
130
 
132
131
  **Option 1: Use default flow (recommended for getting started)**
133
132
 
@@ -201,9 +200,9 @@ Add `RUNTYPE_API_KEY` to your environment. The proxy constructs the Runtype payl
201
200
 
202
201
  ### Development notes
203
202
 
204
- - The widget streams results using SSE and mirrors Runtype flow/agent events, including `step_await` local-tool pauses and `/resume` continuations.
203
+ - The widget streams results using SSE and mirrors Persona's unified flow/agent events (which Runtype implements natively), including `await` local-tool pauses and `/resume` continuations.
205
204
  - Tailwind classes are prefixed with `tvw-` and scoped to `[data-persona-root]`, so they won't collide with the host page.
206
- - Run `pnpm dev` from the repository root to boot the example proxy (`examples/vercel-edge`) and the vanilla demo (`examples/embedded-app`).
205
+ - Run `pnpm dev` from the repository root to boot the example Runtype proxy (`examples/vercel-edge`) and the vanilla demo (`apps/web`).
207
206
  - The proxy prefers port `43111` but automatically selects the next free port if needed.
208
207
  - `features.askUserQuestion.expose` and `features.suggestReplies.expose` advertise built-in LOCAL client tools through `clientTools[]`; leave `expose` off if the flow already declares those tools server-side.
209
208
  - `webmcp: { enabled: true }` snapshots page-registered tools on `document.modelContext`, sends them as `clientTools[]`, executes returned `webmcp:*` calls in the browser, and resumes the paused execution.
@@ -1,4 +1,4 @@
1
- import { S as StreamAnimationPlugin } from './types-DgYsuwXL.cjs';
1
+ import { S as StreamAnimationPlugin } from './types-B_xbfvR0.cjs';
2
2
 
3
3
  declare const glyphCycle: StreamAnimationPlugin;
4
4
 
@@ -1,4 +1,4 @@
1
- import { S as StreamAnimationPlugin } from './types-DgYsuwXL.js';
1
+ import { S as StreamAnimationPlugin } from './types-B_xbfvR0.js';
2
2
 
3
3
  declare const glyphCycle: StreamAnimationPlugin;
4
4
 
@@ -1,54 +1,77 @@
1
- type RuntypeAgentSSEEvent = {
2
- agentId: string;
3
- agentName: string;
4
- config?: {
5
- enableReflection?: boolean;
6
- model?: string;
7
- };
1
+ type RuntypeExecutionStreamEvent = ({
2
+ agentId?: string;
3
+ agentName?: string;
4
+ config?: Record<string, unknown>;
8
5
  executionId: string;
9
- maxTurns: number;
6
+ flowId?: string;
7
+ flowName?: string;
8
+ kind: "agent" | "flow";
9
+ maxTurns?: number;
10
10
  seq: number;
11
+ source?: string;
11
12
  startedAt: string;
12
- type: "agent_start";
13
- } | {
13
+ totalSteps?: number;
14
+ type: "execution_start";
15
+ }) | ({
16
+ completedAt?: string;
17
+ durationMs?: number;
14
18
  executionId: string;
15
- iteration: number;
16
- maxTurns: number;
19
+ failedSteps?: number;
20
+ finalOutput?: string;
21
+ iterations?: number;
22
+ kind: "agent" | "flow";
17
23
  seq: number;
18
- startedAt: string;
24
+ stopReason?: string;
25
+ success: boolean;
26
+ successfulSteps?: number;
19
27
  totalCost?: number;
20
- type: "agent_iteration_start";
21
- } | ({
28
+ totalSteps?: number;
29
+ totalTokens?: {
30
+ input: number;
31
+ output: number;
32
+ };
33
+ type: "execution_complete";
34
+ }) | ({
35
+ code?: string;
36
+ completedAt?: string;
37
+ error: string | {
38
+ code: string;
39
+ details?: Record<string, unknown>;
40
+ message: string;
41
+ };
22
42
  executionId: string;
23
- iteration: number;
24
- role: "user" | "assistant" | "system";
43
+ kind: "agent" | "flow";
25
44
  seq: number;
26
- turnId: string;
27
- turnIndex: number;
28
- type: "agent_turn_start";
45
+ type: "execution_error";
46
+ upgradeUrl?: string;
29
47
  }) | ({
30
- contentType: "text" | "thinking" | "tool_input";
31
- delta: string;
32
48
  executionId: string;
33
- iteration: number;
49
+ id: string;
50
+ iteration?: number;
51
+ role: "user" | "assistant" | "system";
34
52
  seq: number;
35
- turnId: string;
36
- type: "agent_turn_delta";
53
+ turnIndex?: number;
54
+ type: "turn_start";
37
55
  }) | ({
38
- completedAt: string;
56
+ completedAt?: string;
39
57
  content?: string;
40
58
  cost?: number;
41
- estimatedContextBreakdown?: {
42
- categories: Record<string, {
43
- chars: number;
44
- estimatedTokens: number;
59
+ executionId: string;
60
+ fallback?: {
61
+ attempts: Array<{
62
+ attempt: number;
63
+ error?: string;
64
+ model?: string;
65
+ success: boolean;
66
+ type: "retry" | "model" | "message" | "flow";
45
67
  }>;
46
- contextWindowSize?: number;
47
- estimatedTotalTokens: number;
48
- estimatedUtilizationPercent?: number;
68
+ exhausted: boolean;
69
+ model?: string;
70
+ reason?: string | null;
71
+ used: boolean;
49
72
  };
50
- executionId: string;
51
- iteration: number;
73
+ id: string;
74
+ iteration?: number;
52
75
  role: "user" | "assistant" | "system";
53
76
  seq: number;
54
77
  stopReason?: "end_turn" | "max_tool_calls" | "length" | "content_filter" | "error" | "unknown";
@@ -56,207 +79,260 @@ type RuntypeAgentSSEEvent = {
56
79
  input: number;
57
80
  output: number;
58
81
  };
59
- turnId: string;
60
- type: "agent_turn_complete";
82
+ type: "turn_complete";
83
+ }) | {
84
+ executionId: string;
85
+ id: string;
86
+ index?: number;
87
+ name?: string;
88
+ outputVariable?: string;
89
+ seq: number;
90
+ startedAt?: string;
91
+ stepType?: string;
92
+ totalSteps?: number;
93
+ type: "step_start";
94
+ } | ({
95
+ completedAt?: string;
96
+ durationMs?: number;
97
+ error?: string;
98
+ executionId: string;
99
+ fallback?: {
100
+ attempts: Array<{
101
+ attempt: number;
102
+ error?: string;
103
+ model?: string;
104
+ success: boolean;
105
+ type: "retry" | "model" | "message" | "flow";
106
+ }>;
107
+ exhausted: boolean;
108
+ model?: string;
109
+ reason?: string | null;
110
+ used: boolean;
111
+ };
112
+ id: string;
113
+ name?: string;
114
+ result?: unknown;
115
+ seq: number;
116
+ stepType?: string;
117
+ stopReason?: "end_turn" | "max_tool_calls" | "length" | "content_filter" | "error" | "unknown";
118
+ success?: boolean;
119
+ tokensUsed?: number;
120
+ type: "step_complete";
121
+ unresolvedVariables?: Array<string>;
122
+ }) | {
123
+ executionId: string;
124
+ id: string;
125
+ index?: number;
126
+ name?: string;
127
+ seq: number;
128
+ skippedAt?: string;
129
+ stepType?: string;
130
+ totalSteps?: number;
131
+ type: "step_skip";
132
+ when?: string;
133
+ } | ({
134
+ executionId: string;
135
+ id: string;
136
+ parentToolCallId?: string;
137
+ role?: "user" | "assistant" | "system";
138
+ seq: number;
139
+ stepId?: string;
140
+ turnId?: string;
141
+ type: "text_start";
142
+ }) | {
143
+ delta: string;
144
+ executionId: string;
145
+ id: string;
146
+ seq: number;
147
+ type: "text_delta";
148
+ } | {
149
+ executionId: string;
150
+ id: string;
151
+ seq: number;
152
+ text?: string;
153
+ type: "text_complete";
154
+ } | ({
155
+ executionId: string;
156
+ id: string;
157
+ parentToolCallId?: string;
158
+ scope?: "turn" | "loop";
159
+ seq: number;
160
+ type: "reasoning_start";
161
+ }) | {
162
+ delta: string;
163
+ executionId: string;
164
+ id: string;
165
+ seq: number;
166
+ type: "reasoning_delta";
167
+ } | ({
168
+ executionId: string;
169
+ id: string;
170
+ scope?: "turn" | "loop";
171
+ seq: number;
172
+ text?: string;
173
+ type: "reasoning_complete";
61
174
  }) | ({
62
175
  executionId: string;
63
- iteration: number;
176
+ id: string;
177
+ mediaType: string;
178
+ role?: "user" | "assistant" | "system";
179
+ seq: number;
180
+ toolCallId?: string;
181
+ type: "media_start";
182
+ }) | {
183
+ delta: string;
184
+ executionId: string;
185
+ id: string;
186
+ seq: number;
187
+ type: "media_delta";
188
+ } | {
189
+ data?: string;
190
+ executionId: string;
191
+ id: string;
192
+ mediaType?: string;
193
+ seq: number;
194
+ toolCallId?: string;
195
+ type: "media_complete";
196
+ url?: string;
197
+ } | ({
198
+ artifactType: "markdown" | "component";
199
+ component?: string;
200
+ executionId?: string;
201
+ id: string;
202
+ seq?: number;
203
+ title?: string;
204
+ type: "artifact_start";
205
+ }) | {
206
+ delta: string;
207
+ executionId?: string;
208
+ id: string;
209
+ seq?: number;
210
+ type: "artifact_delta";
211
+ } | {
212
+ component: string;
213
+ executionId?: string;
214
+ id: string;
215
+ props: Record<string, unknown>;
216
+ seq?: number;
217
+ type: "artifact_update";
218
+ } | {
219
+ executionId?: string;
220
+ id: string;
221
+ seq?: number;
222
+ type: "artifact_complete";
223
+ } | {
224
+ executionId: string;
225
+ id?: string;
226
+ seq: number;
227
+ sourceType?: string;
228
+ title?: string;
229
+ type: "source";
230
+ url?: string;
231
+ [key: string]: unknown;
232
+ } | ({
233
+ executionId: string;
234
+ hiddenParameterNames?: Array<string>;
235
+ iteration?: number;
64
236
  origin?: "webmcp" | "sdk";
65
237
  pageOrigin?: string;
66
238
  parameters?: Record<string, unknown>;
67
239
  seq: number;
240
+ startedAt?: string;
241
+ stepId?: string;
68
242
  toolCallId: string;
69
243
  toolName: string;
70
- toolType: "flow" | "mcp" | "builtin" | "custom" | "external" | "advisor" | "subagent" | "local";
71
- type: "agent_tool_start";
244
+ toolType: string;
245
+ type: "tool_start";
72
246
  }) | {
73
247
  delta: string;
74
248
  executionId: string;
75
- iteration: number;
76
249
  seq: number;
77
250
  toolCallId: string;
78
- type: "agent_tool_delta";
251
+ type: "tool_input_delta";
79
252
  } | {
80
- delta: string;
81
253
  executionId: string;
82
- iteration: number;
254
+ hiddenParameterNames?: Array<string>;
255
+ parameters: Record<string, unknown>;
83
256
  seq: number;
84
257
  toolCallId: string;
85
- type: "agent_tool_input_delta";
258
+ toolName?: string;
259
+ type: "tool_input_complete";
86
260
  } | {
261
+ delta: string;
87
262
  executionId: string;
88
- hiddenParameterNames?: Array<string>;
89
- iteration: number;
90
- parameters: Record<string, unknown>;
91
263
  seq: number;
92
264
  toolCallId: string;
93
- toolName: string;
94
- type: "agent_tool_input_complete";
265
+ type: "tool_output_delta";
95
266
  } | {
267
+ error?: string;
96
268
  executionId: string;
97
269
  executionTime?: number;
98
- iteration: number;
270
+ iteration?: number;
99
271
  result?: unknown;
100
272
  seq: number;
273
+ stepId?: string;
101
274
  success: boolean;
102
275
  toolCallId: string;
103
- toolName: string;
104
- type: "agent_tool_complete";
105
- } | ({
106
- executionId?: string;
107
- iteration: number;
108
- media: Array<({
109
- annotations?: {
110
- audience?: Array<"user" | "assistant">;
111
- };
112
- data: string;
113
- mediaType: string;
114
- type: "media";
115
- }) | ({
116
- annotations?: {
117
- audience?: Array<"user" | "assistant">;
118
- };
119
- mediaType?: string;
120
- type: "image-url";
121
- url: string;
122
- }) | ({
123
- annotations?: {
124
- audience?: Array<"user" | "assistant">;
125
- };
126
- mediaType: string;
127
- type: "file-url";
128
- url: string;
129
- })>;
130
- seq?: number;
131
- toolCallId: string;
132
- toolName: string;
133
- type: "agent_media";
134
- }) | {
276
+ toolName?: string;
277
+ type: "tool_complete";
278
+ } | {
135
279
  approvalId: string;
136
- description: string;
280
+ description?: string;
137
281
  executionId: string;
138
- externalAgent?: {
139
- contextId?: string;
140
- taskId?: string;
141
- };
142
282
  iteration?: number;
143
283
  parameters?: Record<string, unknown>;
144
284
  reason?: string;
145
285
  seq: number;
146
- startedAt: string;
147
- timeout: number;
148
- toolCallId: string;
286
+ startedAt?: string;
287
+ subagent?: {
288
+ agentName?: string;
289
+ toolName: string;
290
+ };
291
+ timeout?: number;
292
+ toolCallId?: string;
149
293
  toolName: string;
150
- toolType: string;
151
- type: "agent_approval_start";
294
+ toolType?: string;
295
+ type: "approval_start";
152
296
  } | ({
153
297
  approvalId: string;
154
- completedAt: string;
298
+ completedAt?: string;
155
299
  decision: "approved" | "denied" | "timeout";
156
300
  executionId: string;
157
- resolvedBy: "user" | "system";
301
+ resolvedBy?: "user" | "system";
158
302
  seq: number;
159
- type: "agent_approval_complete";
303
+ type: "approval_complete";
160
304
  }) | ({
161
- awaitedAt: string;
305
+ awaitedAt?: string;
162
306
  executionId: string;
163
307
  origin?: "webmcp" | "sdk";
164
308
  pageOrigin?: string;
165
309
  parameters?: Record<string, unknown>;
166
310
  seq: number;
167
311
  toolCallId?: string;
168
- toolId: string;
169
- toolName: string;
170
- type: "agent_await";
171
- }) | {
172
- completedAt: string;
173
- cost?: number;
174
- duration?: number;
175
- estimatedContextBreakdown?: {
176
- categories: Record<string, {
177
- chars: number;
178
- estimatedTokens: number;
179
- }>;
180
- contextWindowSize?: number;
181
- estimatedTotalTokens: number;
182
- estimatedUtilizationPercent?: number;
183
- };
184
- executionId: string;
185
- iteration: number;
186
- output?: string;
187
- runningTotalCost?: number;
188
- seq: number;
189
- stopConditionMet: boolean;
190
- tokens?: {
191
- input: number;
192
- output: number;
193
- };
194
- toolCallsMade: number;
195
- type: "agent_iteration_complete";
196
- } | {
197
- executionId: string;
198
- iteration: number;
199
- reflection?: string;
200
- seq: number;
201
- timestamp?: string;
202
- type: "agent_reflection";
203
- } | {
204
- activatedCapabilities: Array<string>;
205
- executionId: string;
206
- iteration: number;
207
- seq: number;
208
- skill: string;
209
- timestamp?: string;
210
- toolCallId: string;
211
- type: "agent_skill_loaded";
212
- } | ({
213
- executionId: string;
214
- iteration: number;
215
- outcome: "pending_approval" | "auto_published";
216
- proposalId?: string;
217
- seq: number;
218
- skill: string;
219
- timestamp?: string;
220
- toolCallId: string;
221
- type: "agent_skill_proposed";
312
+ toolId?: string;
313
+ toolName?: string;
314
+ type: "await";
222
315
  }) | ({
223
- agentId: string;
224
- completedAt: string;
225
- duration?: number;
226
- error?: string;
227
- executionId: string;
228
- externalAgent?: {
229
- contextId?: string;
230
- taskId?: string;
231
- };
232
- finalOutput?: string;
233
- iterations: number;
234
- seq: number;
235
- stopReason: "complete" | "end_turn" | "max_turns" | "max_cost" | "timeout" | "error";
236
- success: boolean;
237
- totalCost?: number;
238
- totalTokens?: {
239
- input: number;
240
- output: number;
241
- };
242
- type: "agent_complete";
243
- }) | {
244
- error: {
316
+ error: string | {
245
317
  code: string;
246
318
  details?: Record<string, unknown>;
247
319
  message: string;
248
320
  };
249
321
  executionId: string;
250
- iteration?: number;
251
- recoverable: boolean;
322
+ recoverable?: boolean;
252
323
  seq: number;
253
- timestamp?: string;
254
- type: "agent_error";
255
- } | {
324
+ type: "error";
325
+ }) | {
256
326
  executionId: string;
257
327
  seq: number;
258
328
  timestamp: string;
259
- type: "agent_ping";
329
+ type: "ping";
330
+ } | {
331
+ executionId?: string;
332
+ name: string;
333
+ seq?: number;
334
+ type: "custom";
335
+ value?: unknown;
260
336
  };
261
337
  type RuntypeFlowSSEEvent = {
262
338
  executionContext?: Record<string, unknown>;
@@ -554,9 +630,9 @@ type RuntypeFlowSSEEvent = {
554
630
  type RuntypeStreamEventOf<U, T extends string> = Extract<U, {
555
631
  type: T;
556
632
  }>;
557
- type RuntypeAgentTurnCompleteEvent = RuntypeStreamEventOf<RuntypeAgentSSEEvent, "agent_turn_complete">;
633
+ type RuntypeTurnCompleteEvent = RuntypeStreamEventOf<RuntypeExecutionStreamEvent, "turn_complete">;
558
634
  type RuntypeStepCompleteEvent = RuntypeStreamEventOf<RuntypeFlowSSEEvent, "step_complete">;
559
- type RuntypeStopReasonKind = NonNullable<RuntypeAgentTurnCompleteEvent["stopReason"] | RuntypeStepCompleteEvent["stopReason"]>;
635
+ type RuntypeStopReasonKind = NonNullable<RuntypeTurnCompleteEvent["stopReason"] | RuntypeStepCompleteEvent["stopReason"]>;
560
636
 
561
637
  /**
562
638
  * Text content part for multi-modal messages
@@ -752,6 +828,12 @@ type AgentWidgetReasoning = {
752
828
  id: string;
753
829
  status: "pending" | "streaming" | "complete";
754
830
  chunks: string[];
831
+ /**
832
+ * Reasoning channel scope (unified spec). `"turn"` is ordinary per-turn
833
+ * thinking; `"loop"` is a cross-iteration agent reflection (the fold that
834
+ * replaced the legacy `agent_reflection` event). Absent for legacy streams.
835
+ */
836
+ scope?: "turn" | "loop";
755
837
  startedAt?: number;
756
838
  completedAt?: number;
757
839
  durationMs?: number;