@runtypelabs/persona 4.22.0 → 4.22.1

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 (93) hide show
  1. package/dist/animations/glyph-cycle.d.cts +1 -1
  2. package/dist/animations/glyph-cycle.d.ts +1 -1
  3. package/dist/animations/{types-B_JdVK9o.d.cts → types-9Vxm-PPz.d.cts} +136 -6
  4. package/dist/animations/{types-B_JdVK9o.d.ts → types-9Vxm-PPz.d.ts} +136 -6
  5. package/dist/animations/wipe.d.cts +1 -1
  6. package/dist/animations/wipe.d.ts +1 -1
  7. package/dist/animations-extra.d.cts +136 -6
  8. package/dist/animations-extra.d.ts +136 -6
  9. package/dist/approval-ui.d.cts +148 -14
  10. package/dist/approval-ui.d.ts +148 -14
  11. package/dist/artifacts-ui.d.cts +148 -14
  12. package/dist/artifacts-ui.d.ts +148 -14
  13. package/dist/codegen.cjs +1 -1
  14. package/dist/codegen.js +1 -1
  15. package/dist/context-mentions.d.cts +148 -14
  16. package/dist/context-mentions.d.ts +148 -14
  17. package/dist/event-stream-view-GL3ADRY2.js +1 -0
  18. package/dist/event-stream-view.cjs +1 -1
  19. package/dist/event-stream-view.d.cts +148 -14
  20. package/dist/event-stream-view.d.ts +148 -14
  21. package/dist/event-stream-view.js +1 -1
  22. package/dist/forms-ui.d.cts +161 -23
  23. package/dist/forms-ui.d.ts +161 -23
  24. package/dist/history-view.d.cts +136 -6
  25. package/dist/history-view.d.ts +136 -6
  26. package/dist/index.cjs +67 -67
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +166 -27
  29. package/dist/index.d.ts +166 -27
  30. package/dist/index.global.js +51 -51
  31. package/dist/index.global.js.map +1 -1
  32. package/dist/index.js +67 -67
  33. package/dist/index.js.map +1 -1
  34. package/dist/session-reconnect.d.cts +148 -14
  35. package/dist/session-reconnect.d.ts +148 -14
  36. package/dist/smart-dom-reader.d.cts +148 -14
  37. package/dist/smart-dom-reader.d.ts +148 -14
  38. package/dist/testing.cjs +3 -3
  39. package/dist/testing.d.cts +3 -4
  40. package/dist/testing.d.ts +3 -4
  41. package/dist/testing.js +3 -3
  42. package/dist/theme-editor-preview.cjs +71 -71
  43. package/dist/theme-editor-preview.d.cts +148 -14
  44. package/dist/theme-editor-preview.d.ts +148 -14
  45. package/dist/theme-editor-preview.js +48 -48
  46. package/dist/theme-editor.d.cts +148 -14
  47. package/dist/theme-editor.d.ts +148 -14
  48. package/dist/voice-runtime.d.cts +6 -2
  49. package/dist/voice-runtime.d.ts +6 -2
  50. package/package.json +1 -1
  51. package/src/ask-user-question-tool.ts +1 -1
  52. package/src/client-history-rest.test.ts +2 -1
  53. package/src/client-visitor-history.test.ts +20 -4
  54. package/src/client.composer-options.test.ts +1 -1
  55. package/src/client.interrupt.test.ts +2 -2
  56. package/src/client.test.ts +477 -915
  57. package/src/client.ts +134 -494
  58. package/src/client.unified-tools.test.ts +76 -0
  59. package/src/components/event-stream-badge-theming.test.ts +3 -0
  60. package/src/components/event-stream-view.test.ts +76 -76
  61. package/src/components/event-stream-view.ts +5 -0
  62. package/src/components/tool-bubble.test.ts +12 -0
  63. package/src/components/tool-bubble.ts +13 -2
  64. package/src/event-stream-view-bundle.test.ts +2 -2
  65. package/src/generated/runtype-openapi-contract.ts +129 -1
  66. package/src/internal/runtype-history-provider.test.ts +2 -2
  67. package/src/session-history.test.ts +1 -1
  68. package/src/session.quote.test.ts +1 -1
  69. package/src/session.resubmit-from.test.ts +1 -1
  70. package/src/session.test.ts +5 -5
  71. package/src/session.ts +95 -36
  72. package/src/suggest-replies-tool.ts +1 -1
  73. package/src/testing/mock-stream.test.ts +37 -16
  74. package/src/testing/mock-stream.ts +14 -9
  75. package/src/types.ts +19 -14
  76. package/src/ui.ask-user-question-plugin.test.ts +7 -7
  77. package/src/ui.composer-defer-one.test.ts +6 -34
  78. package/src/ui.composer-draft-persistence.test.ts +1 -1
  79. package/src/ui.composer-quote.test.ts +1 -1
  80. package/src/ui.message-history-actions.test.ts +1 -1
  81. package/src/ui.streaming-coalescing.test.ts +10 -13
  82. package/src/ui.ts +67 -32
  83. package/src/ui.typing-indicator.test.ts +216 -0
  84. package/src/ui.voice-custom-provider.test.ts +211 -0
  85. package/src/utils/event-stream-buffer.test.ts +13 -13
  86. package/src/utils/event-stream-capture.test.ts +20 -20
  87. package/src/utils/throughput-tracker.test.ts +100 -142
  88. package/src/utils/throughput-tracker.ts +18 -132
  89. package/src/utils/voice-support.ts +18 -1
  90. package/src/voice/voice-turn-tracker.ts +18 -0
  91. package/src/webmcp-bridge.ts +1 -1
  92. package/dist/event-stream-view-FKWDY3UB.js +0 -1
  93. package/src/utils/__fixtures__/unified-translator.oracle.ts +0 -717
@@ -1963,6 +1963,11 @@ type RuntypeExecutionStreamEvent = ({
1963
1963
  iteration?: number;
1964
1964
  role: "user" | "assistant" | "system";
1965
1965
  seq: number;
1966
+ subagent?: {
1967
+ agentName?: string;
1968
+ parentToolCallId?: string;
1969
+ toolName: string;
1970
+ };
1966
1971
  turnIndex?: number;
1967
1972
  type: "turn_start";
1968
1973
  }) | ({
@@ -1997,12 +2002,61 @@ type RuntypeExecutionStreamEvent = ({
1997
2002
  role: "user" | "assistant" | "system";
1998
2003
  seq: number;
1999
2004
  stopReason?: "end_turn" | "max_tool_calls" | "length" | "content_filter" | "error" | "unknown";
2005
+ subagent?: {
2006
+ agentName?: string;
2007
+ parentToolCallId?: string;
2008
+ toolName: string;
2009
+ };
2000
2010
  tokens?: {
2001
2011
  input: number;
2002
2012
  output: number;
2003
2013
  };
2004
2014
  type: "turn_complete";
2005
2015
  }) | {
2016
+ executionId: string;
2017
+ id: string;
2018
+ iteration?: number;
2019
+ model?: string;
2020
+ ordinal: number;
2021
+ provider?: string;
2022
+ seq: number;
2023
+ startedAt?: string;
2024
+ stepId?: string;
2025
+ subagent?: {
2026
+ agentName?: string;
2027
+ parentToolCallId?: string;
2028
+ toolName: string;
2029
+ };
2030
+ turnId?: string;
2031
+ type: "model_call_start";
2032
+ } | {
2033
+ completedAt?: string;
2034
+ cost?: number;
2035
+ durationMs?: number;
2036
+ executionId: string;
2037
+ finishReason?: string;
2038
+ id: string;
2039
+ iteration?: number;
2040
+ model?: string;
2041
+ ordinal: number;
2042
+ provider?: string;
2043
+ responseModel?: string;
2044
+ seq: number;
2045
+ subagent?: {
2046
+ agentName?: string;
2047
+ parentToolCallId?: string;
2048
+ toolName: string;
2049
+ };
2050
+ success?: boolean;
2051
+ tokens?: {
2052
+ cacheRead?: number;
2053
+ cacheWrite?: number;
2054
+ input: number;
2055
+ output: number;
2056
+ };
2057
+ turnId?: string;
2058
+ type: "model_call_complete";
2059
+ } | {
2006
2060
  executionId: string;
2007
2061
  id: string;
2008
2062
  index?: number;
@@ -2011,6 +2065,11 @@ type RuntypeExecutionStreamEvent = ({
2011
2065
  seq: number;
2012
2066
  startedAt?: string;
2013
2067
  stepType?: string;
2068
+ subagent?: {
2069
+ agentName?: string;
2070
+ parentToolCallId?: string;
2071
+ toolName: string;
2072
+ };
2014
2073
  totalSteps?: number;
2015
2074
  type: "step_start";
2016
2075
  } | ({
@@ -2038,6 +2097,11 @@ type RuntypeExecutionStreamEvent = ({
2038
2097
  seq: number;
2039
2098
  stepType?: string;
2040
2099
  stopReason?: "end_turn" | "max_tool_calls" | "length" | "content_filter" | "error" | "unknown";
2100
+ subagent?: {
2101
+ agentName?: string;
2102
+ parentToolCallId?: string;
2103
+ toolName: string;
2104
+ };
2041
2105
  success?: boolean;
2042
2106
  tokensUsed?: number;
2043
2107
  type: "step_complete";
@@ -2060,6 +2124,11 @@ type RuntypeExecutionStreamEvent = ({
2060
2124
  role?: "user" | "assistant" | "system";
2061
2125
  seq: number;
2062
2126
  stepId?: string;
2127
+ subagent?: {
2128
+ agentName?: string;
2129
+ parentToolCallId?: string;
2130
+ toolName: string;
2131
+ };
2063
2132
  turnId?: string;
2064
2133
  type: "text_start";
2065
2134
  }) | {
@@ -2067,11 +2136,21 @@ type RuntypeExecutionStreamEvent = ({
2067
2136
  executionId: string;
2068
2137
  id: string;
2069
2138
  seq: number;
2139
+ subagent?: {
2140
+ agentName?: string;
2141
+ parentToolCallId?: string;
2142
+ toolName: string;
2143
+ };
2070
2144
  type: "text_delta";
2071
2145
  } | {
2072
2146
  executionId: string;
2073
2147
  id: string;
2074
2148
  seq: number;
2149
+ subagent?: {
2150
+ agentName?: string;
2151
+ parentToolCallId?: string;
2152
+ toolName: string;
2153
+ };
2075
2154
  text?: string;
2076
2155
  type: "text_complete";
2077
2156
  } | ({
@@ -2080,18 +2159,33 @@ type RuntypeExecutionStreamEvent = ({
2080
2159
  parentToolCallId?: string;
2081
2160
  scope?: "turn" | "loop";
2082
2161
  seq: number;
2162
+ subagent?: {
2163
+ agentName?: string;
2164
+ parentToolCallId?: string;
2165
+ toolName: string;
2166
+ };
2083
2167
  type: "reasoning_start";
2084
2168
  }) | {
2085
2169
  delta: string;
2086
2170
  executionId: string;
2087
2171
  id: string;
2088
2172
  seq: number;
2173
+ subagent?: {
2174
+ agentName?: string;
2175
+ parentToolCallId?: string;
2176
+ toolName: string;
2177
+ };
2089
2178
  type: "reasoning_delta";
2090
2179
  } | ({
2091
2180
  executionId: string;
2092
2181
  id: string;
2093
2182
  scope?: "turn" | "loop";
2094
2183
  seq: number;
2184
+ subagent?: {
2185
+ agentName?: string;
2186
+ parentToolCallId?: string;
2187
+ toolName: string;
2188
+ };
2095
2189
  text?: string;
2096
2190
  type: "reasoning_complete";
2097
2191
  }) | ({
@@ -2184,6 +2278,11 @@ type RuntypeExecutionStreamEvent = ({
2184
2278
  seq: number;
2185
2279
  startedAt?: string;
2186
2280
  stepId?: string;
2281
+ subagent?: {
2282
+ agentName?: string;
2283
+ parentToolCallId?: string;
2284
+ toolName: string;
2285
+ };
2187
2286
  toolCallId: string;
2188
2287
  toolName: string;
2189
2288
  toolType: string;
@@ -2192,6 +2291,11 @@ type RuntypeExecutionStreamEvent = ({
2192
2291
  delta: string;
2193
2292
  executionId: string;
2194
2293
  seq: number;
2294
+ subagent?: {
2295
+ agentName?: string;
2296
+ parentToolCallId?: string;
2297
+ toolName: string;
2298
+ };
2195
2299
  toolCallId: string;
2196
2300
  type: "tool_input_delta";
2197
2301
  } | {
@@ -2199,6 +2303,11 @@ type RuntypeExecutionStreamEvent = ({
2199
2303
  hiddenParameterNames?: Array<string>;
2200
2304
  parameters: Record<string, unknown>;
2201
2305
  seq: number;
2306
+ subagent?: {
2307
+ agentName?: string;
2308
+ parentToolCallId?: string;
2309
+ toolName: string;
2310
+ };
2202
2311
  toolCallId: string;
2203
2312
  toolName?: string;
2204
2313
  type: "tool_input_complete";
@@ -2216,6 +2325,11 @@ type RuntypeExecutionStreamEvent = ({
2216
2325
  result?: unknown;
2217
2326
  seq: number;
2218
2327
  stepId?: string;
2328
+ subagent?: {
2329
+ agentName?: string;
2330
+ parentToolCallId?: string;
2331
+ toolName: string;
2332
+ };
2219
2333
  success: boolean;
2220
2334
  toolCallId: string;
2221
2335
  toolCost?: number;
@@ -2295,6 +2409,19 @@ type RuntypeExecutionStreamEvent = ({
2295
2409
  recoverable?: boolean;
2296
2410
  seq: number;
2297
2411
  type: "error";
2412
+ }) | ({
2413
+ epoch: number;
2414
+ executionId: string;
2415
+ kind: "compaction";
2416
+ outcome?: "ok" | "failed" | "gap" | "skipped";
2417
+ phase: "start" | "complete";
2418
+ reason: "threshold" | "overflow" | "manual" | "surface_policy" | "provider_mismatch";
2419
+ seq: number;
2420
+ strategy: "provider_native" | "summary";
2421
+ tier: number;
2422
+ tokensAfter?: number;
2423
+ tokensBefore?: number;
2424
+ type: "context_notice";
2298
2425
  }) | {
2299
2426
  executionId: string;
2300
2427
  seq: number;
@@ -3354,15 +3481,15 @@ type AgentMessageMetadata = {
3354
3481
  */
3355
3482
  parentStepId?: string;
3356
3483
  /**
3357
- * Set to `true` on a tool-variant message produced from a `step_await`
3484
+ * Set to `true` on a tool-variant message produced from an `await`
3358
3485
  * event (`awaitReason: "local_tool_required"`). Signals to UI code that
3359
3486
  * the tool call is a LOCAL tool and the server is paused waiting for a
3360
3487
  * `POST /v1/dispatch/resume` with the user's answer keyed by tool name.
3361
3488
  */
3362
3489
  awaitingLocalTool?: boolean;
3363
3490
  /**
3364
- * The provider per-call id (`toolu_…`) carried on the `step_await` /
3365
- * `flow_await` events for a LOCAL tool (core#3878). Present only when the
3491
+ * The provider per-call id (`toolu_…`) carried on the `await`
3492
+ * event for a LOCAL tool (core#3878). Present only when the
3366
3493
  * server emits it. Two PARALLEL calls to the same tool in one turn share a
3367
3494
  * `toolName` (and a collapsed `toolId`) but get DISTINCT `webMcpToolCallId`s,
3368
3495
  * so this is the key the widget batches a single `/resume` on: preferred
@@ -5512,7 +5639,7 @@ type EventStreamConfig = {
5512
5639
  /**
5513
5640
  * Custom badge color mappings by event type prefix or exact type.
5514
5641
  * Keys are matched as exact match first, then prefix match (keys ending with "_").
5515
- * @example { "flow_": { bg: "#dcfce7", text: "#166534" }, "error": { bg: "#fecaca", text: "#991b1b" } }
5642
+ * @example { "execution_": { bg: "#dcfce7", text: "#166534" }, "error": { bg: "#fecaca", text: "#991b1b" } }
5516
5643
  */
5517
5644
  badgeColors?: Record<string, EventStreamBadgeColor>;
5518
5645
  /**
@@ -6933,9 +7060,13 @@ interface VoiceProvider {
6933
7060
  * `isFinal=false` is a live interim update (user partials, or assistant deltas
6934
7061
  * on providers that stream them); `isFinal=true` finalizes that role's text.
6935
7062
  * On the realtime `runtype` path, interim updates fire for the `user` only and
6936
- * the `assistant` arrives as a single final.
7063
+ * the `assistant` arrives as a single final. Providers with overlapping turns
7064
+ * must include the same turnId on user and assistant finals; without IDs,
7065
+ * providers must discard cancelled output before emitting the next user final.
6937
7066
  */
6938
- onTranscript?(callback: (role: 'user' | 'assistant', text: string, isFinal: boolean) => void): void;
7067
+ onTranscript?(callback: (role: 'user' | 'assistant', text: string, isFinal: boolean, metadata?: {
7068
+ turnId?: string;
7069
+ }) => void): void;
6939
7070
  /** Register a callback for per-turn latency metrics (realtime path). */
6940
7071
  onMetrics?(callback: (metrics: VoiceMetrics) => void): void;
6941
7072
  /**
@@ -9248,16 +9379,16 @@ type AgentWidgetConfig = {
9248
9379
  *
9249
9380
  * @example
9250
9381
  * ```typescript
9251
- * // For Runtype API format
9382
+ * // For a custom backend (Runtype unified events are handled natively)
9252
9383
  * config: {
9253
9384
  * parseSSEEvent: (data) => {
9254
- * if ((data.type === 'step_delta' || data.type === 'step_chunk') && (data.delta || data.chunk)) {
9255
- * return { text: data.delta ?? data.chunk };
9385
+ * if (data.type === 'token' && typeof data.value === 'string') {
9386
+ * return { text: data.value };
9256
9387
  * }
9257
- * if (data.type === 'flow_complete') {
9388
+ * if (data.type === 'done') {
9258
9389
  * return { done: true };
9259
9390
  * }
9260
- * if (data.type === 'step_error') {
9391
+ * if (data.type === 'failure') {
9261
9392
  * return { error: data.error };
9262
9393
  * }
9263
9394
  * return null; // Ignore other events
@@ -9448,7 +9579,7 @@ type AgentWidgetReasoning = {
9448
9579
  /**
9449
9580
  * Reasoning channel scope (wire spec). `"turn"` is ordinary per-turn
9450
9581
  * thinking; `"loop"` is a cross-iteration agent reflection (the fold that
9451
- * replaced the legacy `agent_reflection` event). Absent for legacy streams.
9582
+ * replaced the legacy `agent_reflection` event). Optional when the stream does not specify a scope.
9452
9583
  */
9453
9584
  scope?: "turn" | "loop";
9454
9585
  startedAt?: number;
@@ -9462,6 +9593,9 @@ type AgentWidgetToolCall = {
9462
9593
  args?: unknown;
9463
9594
  chunks?: string[];
9464
9595
  result?: unknown;
9596
+ /** Whether the tool succeeded; failure does not necessarily end the execution. */
9597
+ success?: boolean;
9598
+ error?: string;
9465
9599
  duration?: number;
9466
9600
  startedAt?: number;
9467
9601
  completedAt?: number;
@@ -9492,7 +9626,7 @@ type AgentWidgetApproval = {
9492
9626
  type AgentWidgetMessageVariant = "assistant" | "reasoning" | "tool" | "approval";
9493
9627
  /**
9494
9628
  * Per-turn / per-step stop reason emitted by the runtime on
9495
- * `agent_turn_complete` and `step_complete` SSE events. The vocabulary is
9629
+ * `turn_complete` and `step_complete` SSE events. The vocabulary is
9496
9630
  * owned by the upstream Runtype API: do not extend without coordination.
9497
9631
  *
9498
9632
  * - `end_turn`: natural completion (no affordance needed)
@@ -9623,7 +9757,7 @@ type AgentWidgetMessage = {
9623
9757
  */
9624
9758
  agentMetadata?: AgentMessageMetadata;
9625
9759
  /**
9626
- * Per-turn stop reason reported by the runtime on `agent_turn_complete`
9760
+ * Per-turn stop reason reported by the runtime on `turn_complete`
9627
9761
  * (agent-loop path) or the last `step_complete` for a prompt step
9628
9762
  * (dispatch / flow path). Absent when the API did not report a value.
9629
9763
  *
@@ -1963,6 +1963,11 @@ type RuntypeExecutionStreamEvent = ({
1963
1963
  iteration?: number;
1964
1964
  role: "user" | "assistant" | "system";
1965
1965
  seq: number;
1966
+ subagent?: {
1967
+ agentName?: string;
1968
+ parentToolCallId?: string;
1969
+ toolName: string;
1970
+ };
1966
1971
  turnIndex?: number;
1967
1972
  type: "turn_start";
1968
1973
  }) | ({
@@ -1997,12 +2002,61 @@ type RuntypeExecutionStreamEvent = ({
1997
2002
  role: "user" | "assistant" | "system";
1998
2003
  seq: number;
1999
2004
  stopReason?: "end_turn" | "max_tool_calls" | "length" | "content_filter" | "error" | "unknown";
2005
+ subagent?: {
2006
+ agentName?: string;
2007
+ parentToolCallId?: string;
2008
+ toolName: string;
2009
+ };
2000
2010
  tokens?: {
2001
2011
  input: number;
2002
2012
  output: number;
2003
2013
  };
2004
2014
  type: "turn_complete";
2005
2015
  }) | {
2016
+ executionId: string;
2017
+ id: string;
2018
+ iteration?: number;
2019
+ model?: string;
2020
+ ordinal: number;
2021
+ provider?: string;
2022
+ seq: number;
2023
+ startedAt?: string;
2024
+ stepId?: string;
2025
+ subagent?: {
2026
+ agentName?: string;
2027
+ parentToolCallId?: string;
2028
+ toolName: string;
2029
+ };
2030
+ turnId?: string;
2031
+ type: "model_call_start";
2032
+ } | {
2033
+ completedAt?: string;
2034
+ cost?: number;
2035
+ durationMs?: number;
2036
+ executionId: string;
2037
+ finishReason?: string;
2038
+ id: string;
2039
+ iteration?: number;
2040
+ model?: string;
2041
+ ordinal: number;
2042
+ provider?: string;
2043
+ responseModel?: string;
2044
+ seq: number;
2045
+ subagent?: {
2046
+ agentName?: string;
2047
+ parentToolCallId?: string;
2048
+ toolName: string;
2049
+ };
2050
+ success?: boolean;
2051
+ tokens?: {
2052
+ cacheRead?: number;
2053
+ cacheWrite?: number;
2054
+ input: number;
2055
+ output: number;
2056
+ };
2057
+ turnId?: string;
2058
+ type: "model_call_complete";
2059
+ } | {
2006
2060
  executionId: string;
2007
2061
  id: string;
2008
2062
  index?: number;
@@ -2011,6 +2065,11 @@ type RuntypeExecutionStreamEvent = ({
2011
2065
  seq: number;
2012
2066
  startedAt?: string;
2013
2067
  stepType?: string;
2068
+ subagent?: {
2069
+ agentName?: string;
2070
+ parentToolCallId?: string;
2071
+ toolName: string;
2072
+ };
2014
2073
  totalSteps?: number;
2015
2074
  type: "step_start";
2016
2075
  } | ({
@@ -2038,6 +2097,11 @@ type RuntypeExecutionStreamEvent = ({
2038
2097
  seq: number;
2039
2098
  stepType?: string;
2040
2099
  stopReason?: "end_turn" | "max_tool_calls" | "length" | "content_filter" | "error" | "unknown";
2100
+ subagent?: {
2101
+ agentName?: string;
2102
+ parentToolCallId?: string;
2103
+ toolName: string;
2104
+ };
2041
2105
  success?: boolean;
2042
2106
  tokensUsed?: number;
2043
2107
  type: "step_complete";
@@ -2060,6 +2124,11 @@ type RuntypeExecutionStreamEvent = ({
2060
2124
  role?: "user" | "assistant" | "system";
2061
2125
  seq: number;
2062
2126
  stepId?: string;
2127
+ subagent?: {
2128
+ agentName?: string;
2129
+ parentToolCallId?: string;
2130
+ toolName: string;
2131
+ };
2063
2132
  turnId?: string;
2064
2133
  type: "text_start";
2065
2134
  }) | {
@@ -2067,11 +2136,21 @@ type RuntypeExecutionStreamEvent = ({
2067
2136
  executionId: string;
2068
2137
  id: string;
2069
2138
  seq: number;
2139
+ subagent?: {
2140
+ agentName?: string;
2141
+ parentToolCallId?: string;
2142
+ toolName: string;
2143
+ };
2070
2144
  type: "text_delta";
2071
2145
  } | {
2072
2146
  executionId: string;
2073
2147
  id: string;
2074
2148
  seq: number;
2149
+ subagent?: {
2150
+ agentName?: string;
2151
+ parentToolCallId?: string;
2152
+ toolName: string;
2153
+ };
2075
2154
  text?: string;
2076
2155
  type: "text_complete";
2077
2156
  } | ({
@@ -2080,18 +2159,33 @@ type RuntypeExecutionStreamEvent = ({
2080
2159
  parentToolCallId?: string;
2081
2160
  scope?: "turn" | "loop";
2082
2161
  seq: number;
2162
+ subagent?: {
2163
+ agentName?: string;
2164
+ parentToolCallId?: string;
2165
+ toolName: string;
2166
+ };
2083
2167
  type: "reasoning_start";
2084
2168
  }) | {
2085
2169
  delta: string;
2086
2170
  executionId: string;
2087
2171
  id: string;
2088
2172
  seq: number;
2173
+ subagent?: {
2174
+ agentName?: string;
2175
+ parentToolCallId?: string;
2176
+ toolName: string;
2177
+ };
2089
2178
  type: "reasoning_delta";
2090
2179
  } | ({
2091
2180
  executionId: string;
2092
2181
  id: string;
2093
2182
  scope?: "turn" | "loop";
2094
2183
  seq: number;
2184
+ subagent?: {
2185
+ agentName?: string;
2186
+ parentToolCallId?: string;
2187
+ toolName: string;
2188
+ };
2095
2189
  text?: string;
2096
2190
  type: "reasoning_complete";
2097
2191
  }) | ({
@@ -2184,6 +2278,11 @@ type RuntypeExecutionStreamEvent = ({
2184
2278
  seq: number;
2185
2279
  startedAt?: string;
2186
2280
  stepId?: string;
2281
+ subagent?: {
2282
+ agentName?: string;
2283
+ parentToolCallId?: string;
2284
+ toolName: string;
2285
+ };
2187
2286
  toolCallId: string;
2188
2287
  toolName: string;
2189
2288
  toolType: string;
@@ -2192,6 +2291,11 @@ type RuntypeExecutionStreamEvent = ({
2192
2291
  delta: string;
2193
2292
  executionId: string;
2194
2293
  seq: number;
2294
+ subagent?: {
2295
+ agentName?: string;
2296
+ parentToolCallId?: string;
2297
+ toolName: string;
2298
+ };
2195
2299
  toolCallId: string;
2196
2300
  type: "tool_input_delta";
2197
2301
  } | {
@@ -2199,6 +2303,11 @@ type RuntypeExecutionStreamEvent = ({
2199
2303
  hiddenParameterNames?: Array<string>;
2200
2304
  parameters: Record<string, unknown>;
2201
2305
  seq: number;
2306
+ subagent?: {
2307
+ agentName?: string;
2308
+ parentToolCallId?: string;
2309
+ toolName: string;
2310
+ };
2202
2311
  toolCallId: string;
2203
2312
  toolName?: string;
2204
2313
  type: "tool_input_complete";
@@ -2216,6 +2325,11 @@ type RuntypeExecutionStreamEvent = ({
2216
2325
  result?: unknown;
2217
2326
  seq: number;
2218
2327
  stepId?: string;
2328
+ subagent?: {
2329
+ agentName?: string;
2330
+ parentToolCallId?: string;
2331
+ toolName: string;
2332
+ };
2219
2333
  success: boolean;
2220
2334
  toolCallId: string;
2221
2335
  toolCost?: number;
@@ -2295,6 +2409,19 @@ type RuntypeExecutionStreamEvent = ({
2295
2409
  recoverable?: boolean;
2296
2410
  seq: number;
2297
2411
  type: "error";
2412
+ }) | ({
2413
+ epoch: number;
2414
+ executionId: string;
2415
+ kind: "compaction";
2416
+ outcome?: "ok" | "failed" | "gap" | "skipped";
2417
+ phase: "start" | "complete";
2418
+ reason: "threshold" | "overflow" | "manual" | "surface_policy" | "provider_mismatch";
2419
+ seq: number;
2420
+ strategy: "provider_native" | "summary";
2421
+ tier: number;
2422
+ tokensAfter?: number;
2423
+ tokensBefore?: number;
2424
+ type: "context_notice";
2298
2425
  }) | {
2299
2426
  executionId: string;
2300
2427
  seq: number;
@@ -3354,15 +3481,15 @@ type AgentMessageMetadata = {
3354
3481
  */
3355
3482
  parentStepId?: string;
3356
3483
  /**
3357
- * Set to `true` on a tool-variant message produced from a `step_await`
3484
+ * Set to `true` on a tool-variant message produced from an `await`
3358
3485
  * event (`awaitReason: "local_tool_required"`). Signals to UI code that
3359
3486
  * the tool call is a LOCAL tool and the server is paused waiting for a
3360
3487
  * `POST /v1/dispatch/resume` with the user's answer keyed by tool name.
3361
3488
  */
3362
3489
  awaitingLocalTool?: boolean;
3363
3490
  /**
3364
- * The provider per-call id (`toolu_…`) carried on the `step_await` /
3365
- * `flow_await` events for a LOCAL tool (core#3878). Present only when the
3491
+ * The provider per-call id (`toolu_…`) carried on the `await`
3492
+ * event for a LOCAL tool (core#3878). Present only when the
3366
3493
  * server emits it. Two PARALLEL calls to the same tool in one turn share a
3367
3494
  * `toolName` (and a collapsed `toolId`) but get DISTINCT `webMcpToolCallId`s,
3368
3495
  * so this is the key the widget batches a single `/resume` on: preferred
@@ -5512,7 +5639,7 @@ type EventStreamConfig = {
5512
5639
  /**
5513
5640
  * Custom badge color mappings by event type prefix or exact type.
5514
5641
  * Keys are matched as exact match first, then prefix match (keys ending with "_").
5515
- * @example { "flow_": { bg: "#dcfce7", text: "#166534" }, "error": { bg: "#fecaca", text: "#991b1b" } }
5642
+ * @example { "execution_": { bg: "#dcfce7", text: "#166534" }, "error": { bg: "#fecaca", text: "#991b1b" } }
5516
5643
  */
5517
5644
  badgeColors?: Record<string, EventStreamBadgeColor>;
5518
5645
  /**
@@ -6933,9 +7060,13 @@ interface VoiceProvider {
6933
7060
  * `isFinal=false` is a live interim update (user partials, or assistant deltas
6934
7061
  * on providers that stream them); `isFinal=true` finalizes that role's text.
6935
7062
  * On the realtime `runtype` path, interim updates fire for the `user` only and
6936
- * the `assistant` arrives as a single final.
7063
+ * the `assistant` arrives as a single final. Providers with overlapping turns
7064
+ * must include the same turnId on user and assistant finals; without IDs,
7065
+ * providers must discard cancelled output before emitting the next user final.
6937
7066
  */
6938
- onTranscript?(callback: (role: 'user' | 'assistant', text: string, isFinal: boolean) => void): void;
7067
+ onTranscript?(callback: (role: 'user' | 'assistant', text: string, isFinal: boolean, metadata?: {
7068
+ turnId?: string;
7069
+ }) => void): void;
6939
7070
  /** Register a callback for per-turn latency metrics (realtime path). */
6940
7071
  onMetrics?(callback: (metrics: VoiceMetrics) => void): void;
6941
7072
  /**
@@ -9248,16 +9379,16 @@ type AgentWidgetConfig = {
9248
9379
  *
9249
9380
  * @example
9250
9381
  * ```typescript
9251
- * // For Runtype API format
9382
+ * // For a custom backend (Runtype unified events are handled natively)
9252
9383
  * config: {
9253
9384
  * parseSSEEvent: (data) => {
9254
- * if ((data.type === 'step_delta' || data.type === 'step_chunk') && (data.delta || data.chunk)) {
9255
- * return { text: data.delta ?? data.chunk };
9385
+ * if (data.type === 'token' && typeof data.value === 'string') {
9386
+ * return { text: data.value };
9256
9387
  * }
9257
- * if (data.type === 'flow_complete') {
9388
+ * if (data.type === 'done') {
9258
9389
  * return { done: true };
9259
9390
  * }
9260
- * if (data.type === 'step_error') {
9391
+ * if (data.type === 'failure') {
9261
9392
  * return { error: data.error };
9262
9393
  * }
9263
9394
  * return null; // Ignore other events
@@ -9448,7 +9579,7 @@ type AgentWidgetReasoning = {
9448
9579
  /**
9449
9580
  * Reasoning channel scope (wire spec). `"turn"` is ordinary per-turn
9450
9581
  * thinking; `"loop"` is a cross-iteration agent reflection (the fold that
9451
- * replaced the legacy `agent_reflection` event). Absent for legacy streams.
9582
+ * replaced the legacy `agent_reflection` event). Optional when the stream does not specify a scope.
9452
9583
  */
9453
9584
  scope?: "turn" | "loop";
9454
9585
  startedAt?: number;
@@ -9462,6 +9593,9 @@ type AgentWidgetToolCall = {
9462
9593
  args?: unknown;
9463
9594
  chunks?: string[];
9464
9595
  result?: unknown;
9596
+ /** Whether the tool succeeded; failure does not necessarily end the execution. */
9597
+ success?: boolean;
9598
+ error?: string;
9465
9599
  duration?: number;
9466
9600
  startedAt?: number;
9467
9601
  completedAt?: number;
@@ -9492,7 +9626,7 @@ type AgentWidgetApproval = {
9492
9626
  type AgentWidgetMessageVariant = "assistant" | "reasoning" | "tool" | "approval";
9493
9627
  /**
9494
9628
  * Per-turn / per-step stop reason emitted by the runtime on
9495
- * `agent_turn_complete` and `step_complete` SSE events. The vocabulary is
9629
+ * `turn_complete` and `step_complete` SSE events. The vocabulary is
9496
9630
  * owned by the upstream Runtype API: do not extend without coordination.
9497
9631
  *
9498
9632
  * - `end_turn`: natural completion (no affordance needed)
@@ -9623,7 +9757,7 @@ type AgentWidgetMessage = {
9623
9757
  */
9624
9758
  agentMetadata?: AgentMessageMetadata;
9625
9759
  /**
9626
- * Per-turn stop reason reported by the runtime on `agent_turn_complete`
9760
+ * Per-turn stop reason reported by the runtime on `turn_complete`
9627
9761
  * (agent-loop path) or the last `step_complete` for a prompt step
9628
9762
  * (dispatch / flow path). Absent when the API did not report a value.
9629
9763
  *
package/dist/testing.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var i=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var M=(t,e)=>{for(var r in e)i(t,r,{get:e[r],enumerable:!0})},E=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of k(e))!y.call(t,n)&&n!==r&&i(t,n,{get:()=>e[n],enumerable:!(s=l(e,n))||s.enumerable});return t};var x=t=>E(i({},"__esModule",{value:!0}),t);var f={};M(f,{buildAssistantTurnFrames:()=>u,createMockSSEResponse:()=>p,createMockSSEStream:()=>c});module.exports=x(f);var g=new TextEncoder,S=()=>new DOMException("The operation was aborted.","AbortError");function c(t,e){let r=e?.delayMs??100,s=e?.eventName?`event: ${e.eventName}
2
- `:"",n=e?.signal??null,o=0;return new ReadableStream({async pull(a){if(o>=t.length){a.close();return}if(n?.aborted){a.error(S());return}if(await new Promise(d=>setTimeout(d,r)),n?.aborted){a.error(S());return}let m=JSON.stringify(t[o]);a.enqueue(g.encode(`${s}data: ${m}
1
+ "use strict";var c=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var k=(t,e)=>{for(var r in e)c(t,r,{get:e[r],enumerable:!0})},M=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of x(e))!y.call(t,n)&&n!==r&&c(t,n,{get:()=>e[n],enumerable:!(s=l(e,n))||s.enumerable});return t};var E=t=>M(c({},"__esModule",{value:!0}),t);var g={};k(g,{buildAssistantTurnFrames:()=>p,createMockSSEResponse:()=>d,createMockSSEStream:()=>S});module.exports=E(g);var f=new TextEncoder,u=()=>new DOMException("The operation was aborted.","AbortError");function S(t,e){let r=e?.delayMs??100,s=e?.eventName?`event: ${e.eventName}
2
+ `:"",n=e?.signal??null,o=0;return new ReadableStream({async pull(a){if(o>=t.length){a.close();return}if(n?.aborted){a.error(u());return}if(await new Promise(m=>setTimeout(m,r)),n?.aborted){a.error(u());return}let i=JSON.stringify(t[o]);a.enqueue(f.encode(`${s}data: ${i}
3
3
 
4
- `)),o+=1}})}function u(t){let{executionId:e,text:r}=t,s=t.turnId??"turn-1",n=Math.max(1,t.chunkSize??32),o=[{type:"agent_turn_start",executionId:e,turnId:s}];for(let a=0;a<r.length;a+=n)o.push({type:"agent_turn_delta",executionId:e,turnId:s,delta:r.slice(a,a+n)});return o.push({type:"agent_turn_complete",executionId:e,turnId:s}),o}function p(t,e){let r=c(t,e);return new Response(r,{status:e?.status??200,headers:{"Content-Type":"text/event-stream",...e?.headers}})}0&&(module.exports={buildAssistantTurnFrames,createMockSSEResponse,createMockSSEStream});
4
+ `)),o+=1}})}function p(t){let{executionId:e,text:r}=t,s=t.turnId??"turn-1",n=`${s}-text`,o=Math.max(1,t.chunkSize??32),a=[{type:"turn_start",executionId:e,id:s,role:"assistant"},{type:"text_start",executionId:e,id:n,turnId:s,role:"assistant"}];for(let i=0;i<r.length;i+=o)a.push({type:"text_delta",executionId:e,id:n,delta:r.slice(i,i+o)});return a.push({type:"text_complete",executionId:e,id:n,text:r},{type:"turn_complete",executionId:e,id:s,role:"assistant",content:r}),a}function d(t,e){let r=S(t,e);return new Response(r,{status:e?.status??200,headers:{"Content-Type":"text/event-stream",...e?.headers}})}0&&(module.exports={buildAssistantTurnFrames,createMockSSEResponse,createMockSSEStream});
@@ -27,13 +27,12 @@ interface AssistantTurnFramesOptions {
27
27
  turnId?: string;
28
28
  /** Assistant text content to stream. */
29
29
  text: string;
30
- /** Approximate characters per `agent_turn_delta` frame. Default: 32. */
30
+ /** Approximate characters per `text_delta` frame. Default: 32. */
31
31
  chunkSize?: number;
32
32
  }
33
33
  /**
34
- * Builds the standard `agent_turn_start` → many `agent_turn_delta` → `agent_turn_complete`
35
- * frame sequence for simulating a streaming assistant reply. The frames drive the same
36
- * client pipeline as real SSE, so stream animations (typewriter, word-fade, etc.) engage.
34
+ * Builds a unified assistant turn with a text block. Execution lifecycle frames
35
+ * can be supplied by the caller when composing a multi-turn execution.
37
36
  */
38
37
  declare function buildAssistantTurnFrames(options: AssistantTurnFramesOptions): MockSSEFrame[];
39
38
  interface MockSSEResponseOptions extends CreateMockSSEStreamOptions {