@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
@@ -1696,6 +1696,11 @@ type RuntypeExecutionStreamEvent = ({
1696
1696
  iteration?: number;
1697
1697
  role: "user" | "assistant" | "system";
1698
1698
  seq: number;
1699
+ subagent?: {
1700
+ agentName?: string;
1701
+ parentToolCallId?: string;
1702
+ toolName: string;
1703
+ };
1699
1704
  turnIndex?: number;
1700
1705
  type: "turn_start";
1701
1706
  }) | ({
@@ -1730,12 +1735,61 @@ type RuntypeExecutionStreamEvent = ({
1730
1735
  role: "user" | "assistant" | "system";
1731
1736
  seq: number;
1732
1737
  stopReason?: "end_turn" | "max_tool_calls" | "length" | "content_filter" | "error" | "unknown";
1738
+ subagent?: {
1739
+ agentName?: string;
1740
+ parentToolCallId?: string;
1741
+ toolName: string;
1742
+ };
1733
1743
  tokens?: {
1734
1744
  input: number;
1735
1745
  output: number;
1736
1746
  };
1737
1747
  type: "turn_complete";
1738
1748
  }) | {
1749
+ executionId: string;
1750
+ id: string;
1751
+ iteration?: number;
1752
+ model?: string;
1753
+ ordinal: number;
1754
+ provider?: string;
1755
+ seq: number;
1756
+ startedAt?: string;
1757
+ stepId?: string;
1758
+ subagent?: {
1759
+ agentName?: string;
1760
+ parentToolCallId?: string;
1761
+ toolName: string;
1762
+ };
1763
+ turnId?: string;
1764
+ type: "model_call_start";
1765
+ } | {
1766
+ completedAt?: string;
1767
+ cost?: number;
1768
+ durationMs?: number;
1769
+ executionId: string;
1770
+ finishReason?: string;
1771
+ id: string;
1772
+ iteration?: number;
1773
+ model?: string;
1774
+ ordinal: number;
1775
+ provider?: string;
1776
+ responseModel?: string;
1777
+ seq: number;
1778
+ subagent?: {
1779
+ agentName?: string;
1780
+ parentToolCallId?: string;
1781
+ toolName: string;
1782
+ };
1783
+ success?: boolean;
1784
+ tokens?: {
1785
+ cacheRead?: number;
1786
+ cacheWrite?: number;
1787
+ input: number;
1788
+ output: number;
1789
+ };
1790
+ turnId?: string;
1791
+ type: "model_call_complete";
1792
+ } | {
1739
1793
  executionId: string;
1740
1794
  id: string;
1741
1795
  index?: number;
@@ -1744,6 +1798,11 @@ type RuntypeExecutionStreamEvent = ({
1744
1798
  seq: number;
1745
1799
  startedAt?: string;
1746
1800
  stepType?: string;
1801
+ subagent?: {
1802
+ agentName?: string;
1803
+ parentToolCallId?: string;
1804
+ toolName: string;
1805
+ };
1747
1806
  totalSteps?: number;
1748
1807
  type: "step_start";
1749
1808
  } | ({
@@ -1771,6 +1830,11 @@ type RuntypeExecutionStreamEvent = ({
1771
1830
  seq: number;
1772
1831
  stepType?: string;
1773
1832
  stopReason?: "end_turn" | "max_tool_calls" | "length" | "content_filter" | "error" | "unknown";
1833
+ subagent?: {
1834
+ agentName?: string;
1835
+ parentToolCallId?: string;
1836
+ toolName: string;
1837
+ };
1774
1838
  success?: boolean;
1775
1839
  tokensUsed?: number;
1776
1840
  type: "step_complete";
@@ -1793,6 +1857,11 @@ type RuntypeExecutionStreamEvent = ({
1793
1857
  role?: "user" | "assistant" | "system";
1794
1858
  seq: number;
1795
1859
  stepId?: string;
1860
+ subagent?: {
1861
+ agentName?: string;
1862
+ parentToolCallId?: string;
1863
+ toolName: string;
1864
+ };
1796
1865
  turnId?: string;
1797
1866
  type: "text_start";
1798
1867
  }) | {
@@ -1800,11 +1869,21 @@ type RuntypeExecutionStreamEvent = ({
1800
1869
  executionId: string;
1801
1870
  id: string;
1802
1871
  seq: number;
1872
+ subagent?: {
1873
+ agentName?: string;
1874
+ parentToolCallId?: string;
1875
+ toolName: string;
1876
+ };
1803
1877
  type: "text_delta";
1804
1878
  } | {
1805
1879
  executionId: string;
1806
1880
  id: string;
1807
1881
  seq: number;
1882
+ subagent?: {
1883
+ agentName?: string;
1884
+ parentToolCallId?: string;
1885
+ toolName: string;
1886
+ };
1808
1887
  text?: string;
1809
1888
  type: "text_complete";
1810
1889
  } | ({
@@ -1813,18 +1892,33 @@ type RuntypeExecutionStreamEvent = ({
1813
1892
  parentToolCallId?: string;
1814
1893
  scope?: "turn" | "loop";
1815
1894
  seq: number;
1895
+ subagent?: {
1896
+ agentName?: string;
1897
+ parentToolCallId?: string;
1898
+ toolName: string;
1899
+ };
1816
1900
  type: "reasoning_start";
1817
1901
  }) | {
1818
1902
  delta: string;
1819
1903
  executionId: string;
1820
1904
  id: string;
1821
1905
  seq: number;
1906
+ subagent?: {
1907
+ agentName?: string;
1908
+ parentToolCallId?: string;
1909
+ toolName: string;
1910
+ };
1822
1911
  type: "reasoning_delta";
1823
1912
  } | ({
1824
1913
  executionId: string;
1825
1914
  id: string;
1826
1915
  scope?: "turn" | "loop";
1827
1916
  seq: number;
1917
+ subagent?: {
1918
+ agentName?: string;
1919
+ parentToolCallId?: string;
1920
+ toolName: string;
1921
+ };
1828
1922
  text?: string;
1829
1923
  type: "reasoning_complete";
1830
1924
  }) | ({
@@ -1917,6 +2011,11 @@ type RuntypeExecutionStreamEvent = ({
1917
2011
  seq: number;
1918
2012
  startedAt?: string;
1919
2013
  stepId?: string;
2014
+ subagent?: {
2015
+ agentName?: string;
2016
+ parentToolCallId?: string;
2017
+ toolName: string;
2018
+ };
1920
2019
  toolCallId: string;
1921
2020
  toolName: string;
1922
2021
  toolType: string;
@@ -1925,6 +2024,11 @@ type RuntypeExecutionStreamEvent = ({
1925
2024
  delta: string;
1926
2025
  executionId: string;
1927
2026
  seq: number;
2027
+ subagent?: {
2028
+ agentName?: string;
2029
+ parentToolCallId?: string;
2030
+ toolName: string;
2031
+ };
1928
2032
  toolCallId: string;
1929
2033
  type: "tool_input_delta";
1930
2034
  } | {
@@ -1932,6 +2036,11 @@ type RuntypeExecutionStreamEvent = ({
1932
2036
  hiddenParameterNames?: Array<string>;
1933
2037
  parameters: Record<string, unknown>;
1934
2038
  seq: number;
2039
+ subagent?: {
2040
+ agentName?: string;
2041
+ parentToolCallId?: string;
2042
+ toolName: string;
2043
+ };
1935
2044
  toolCallId: string;
1936
2045
  toolName?: string;
1937
2046
  type: "tool_input_complete";
@@ -1949,6 +2058,11 @@ type RuntypeExecutionStreamEvent = ({
1949
2058
  result?: unknown;
1950
2059
  seq: number;
1951
2060
  stepId?: string;
2061
+ subagent?: {
2062
+ agentName?: string;
2063
+ parentToolCallId?: string;
2064
+ toolName: string;
2065
+ };
1952
2066
  success: boolean;
1953
2067
  toolCallId: string;
1954
2068
  toolCost?: number;
@@ -2028,6 +2142,19 @@ type RuntypeExecutionStreamEvent = ({
2028
2142
  recoverable?: boolean;
2029
2143
  seq: number;
2030
2144
  type: "error";
2145
+ }) | ({
2146
+ epoch: number;
2147
+ executionId: string;
2148
+ kind: "compaction";
2149
+ outcome?: "ok" | "failed" | "gap" | "skipped";
2150
+ phase: "start" | "complete";
2151
+ reason: "threshold" | "overflow" | "manual" | "surface_policy" | "provider_mismatch";
2152
+ seq: number;
2153
+ strategy: "provider_native" | "summary";
2154
+ tier: number;
2155
+ tokensAfter?: number;
2156
+ tokensBefore?: number;
2157
+ type: "context_notice";
2031
2158
  }) | {
2032
2159
  executionId: string;
2033
2160
  seq: number;
@@ -3087,15 +3214,15 @@ type AgentMessageMetadata = {
3087
3214
  */
3088
3215
  parentStepId?: string;
3089
3216
  /**
3090
- * Set to `true` on a tool-variant message produced from a `step_await`
3217
+ * Set to `true` on a tool-variant message produced from an `await`
3091
3218
  * event (`awaitReason: "local_tool_required"`). Signals to UI code that
3092
3219
  * the tool call is a LOCAL tool and the server is paused waiting for a
3093
3220
  * `POST /v1/dispatch/resume` with the user's answer keyed by tool name.
3094
3221
  */
3095
3222
  awaitingLocalTool?: boolean;
3096
3223
  /**
3097
- * The provider per-call id (`toolu_…`) carried on the `step_await` /
3098
- * `flow_await` events for a LOCAL tool (core#3878). Present only when the
3224
+ * The provider per-call id (`toolu_…`) carried on the `await`
3225
+ * event for a LOCAL tool (core#3878). Present only when the
3099
3226
  * server emits it. Two PARALLEL calls to the same tool in one turn share a
3100
3227
  * `toolName` (and a collapsed `toolId`) but get DISTINCT `webMcpToolCallId`s,
3101
3228
  * so this is the key the widget batches a single `/resume` on: preferred
@@ -5245,7 +5372,7 @@ type EventStreamConfig = {
5245
5372
  /**
5246
5373
  * Custom badge color mappings by event type prefix or exact type.
5247
5374
  * Keys are matched as exact match first, then prefix match (keys ending with "_").
5248
- * @example { "flow_": { bg: "#dcfce7", text: "#166534" }, "error": { bg: "#fecaca", text: "#991b1b" } }
5375
+ * @example { "execution_": { bg: "#dcfce7", text: "#166534" }, "error": { bg: "#fecaca", text: "#991b1b" } }
5249
5376
  */
5250
5377
  badgeColors?: Record<string, EventStreamBadgeColor>;
5251
5378
  /**
@@ -6666,9 +6793,13 @@ interface VoiceProvider {
6666
6793
  * `isFinal=false` is a live interim update (user partials, or assistant deltas
6667
6794
  * on providers that stream them); `isFinal=true` finalizes that role's text.
6668
6795
  * On the realtime `runtype` path, interim updates fire for the `user` only and
6669
- * the `assistant` arrives as a single final.
6796
+ * the `assistant` arrives as a single final. Providers with overlapping turns
6797
+ * must include the same turnId on user and assistant finals; without IDs,
6798
+ * providers must discard cancelled output before emitting the next user final.
6670
6799
  */
6671
- onTranscript?(callback: (role: 'user' | 'assistant', text: string, isFinal: boolean) => void): void;
6800
+ onTranscript?(callback: (role: 'user' | 'assistant', text: string, isFinal: boolean, metadata?: {
6801
+ turnId?: string;
6802
+ }) => void): void;
6672
6803
  /** Register a callback for per-turn latency metrics (realtime path). */
6673
6804
  onMetrics?(callback: (metrics: VoiceMetrics) => void): void;
6674
6805
  /**
@@ -8981,16 +9112,16 @@ type AgentWidgetConfig = {
8981
9112
  *
8982
9113
  * @example
8983
9114
  * ```typescript
8984
- * // For Runtype API format
9115
+ * // For a custom backend (Runtype unified events are handled natively)
8985
9116
  * config: {
8986
9117
  * parseSSEEvent: (data) => {
8987
- * if ((data.type === 'step_delta' || data.type === 'step_chunk') && (data.delta || data.chunk)) {
8988
- * return { text: data.delta ?? data.chunk };
9118
+ * if (data.type === 'token' && typeof data.value === 'string') {
9119
+ * return { text: data.value };
8989
9120
  * }
8990
- * if (data.type === 'flow_complete') {
9121
+ * if (data.type === 'done') {
8991
9122
  * return { done: true };
8992
9123
  * }
8993
- * if (data.type === 'step_error') {
9124
+ * if (data.type === 'failure') {
8994
9125
  * return { error: data.error };
8995
9126
  * }
8996
9127
  * return null; // Ignore other events
@@ -9181,7 +9312,7 @@ type AgentWidgetReasoning = {
9181
9312
  /**
9182
9313
  * Reasoning channel scope (wire spec). `"turn"` is ordinary per-turn
9183
9314
  * thinking; `"loop"` is a cross-iteration agent reflection (the fold that
9184
- * replaced the legacy `agent_reflection` event). Absent for legacy streams.
9315
+ * replaced the legacy `agent_reflection` event). Optional when the stream does not specify a scope.
9185
9316
  */
9186
9317
  scope?: "turn" | "loop";
9187
9318
  startedAt?: number;
@@ -9195,6 +9326,9 @@ type AgentWidgetToolCall = {
9195
9326
  args?: unknown;
9196
9327
  chunks?: string[];
9197
9328
  result?: unknown;
9329
+ /** Whether the tool succeeded; failure does not necessarily end the execution. */
9330
+ success?: boolean;
9331
+ error?: string;
9198
9332
  duration?: number;
9199
9333
  startedAt?: number;
9200
9334
  completedAt?: number;
@@ -9225,7 +9359,7 @@ type AgentWidgetApproval = {
9225
9359
  type AgentWidgetMessageVariant = "assistant" | "reasoning" | "tool" | "approval";
9226
9360
  /**
9227
9361
  * Per-turn / per-step stop reason emitted by the runtime on
9228
- * `agent_turn_complete` and `step_complete` SSE events. The vocabulary is
9362
+ * `turn_complete` and `step_complete` SSE events. The vocabulary is
9229
9363
  * owned by the upstream Runtype API: do not extend without coordination.
9230
9364
  *
9231
9365
  * - `end_turn`: natural completion (no affordance needed)
@@ -9356,7 +9490,7 @@ type AgentWidgetMessage = {
9356
9490
  */
9357
9491
  agentMetadata?: AgentMessageMetadata;
9358
9492
  /**
9359
- * Per-turn stop reason reported by the runtime on `agent_turn_complete`
9493
+ * Per-turn stop reason reported by the runtime on `turn_complete`
9360
9494
  * (agent-loop path) or the last `step_complete` for a prompt step
9361
9495
  * (dispatch / flow path). Absent when the API did not report a value.
9362
9496
  *
@@ -1696,6 +1696,11 @@ type RuntypeExecutionStreamEvent = ({
1696
1696
  iteration?: number;
1697
1697
  role: "user" | "assistant" | "system";
1698
1698
  seq: number;
1699
+ subagent?: {
1700
+ agentName?: string;
1701
+ parentToolCallId?: string;
1702
+ toolName: string;
1703
+ };
1699
1704
  turnIndex?: number;
1700
1705
  type: "turn_start";
1701
1706
  }) | ({
@@ -1730,12 +1735,61 @@ type RuntypeExecutionStreamEvent = ({
1730
1735
  role: "user" | "assistant" | "system";
1731
1736
  seq: number;
1732
1737
  stopReason?: "end_turn" | "max_tool_calls" | "length" | "content_filter" | "error" | "unknown";
1738
+ subagent?: {
1739
+ agentName?: string;
1740
+ parentToolCallId?: string;
1741
+ toolName: string;
1742
+ };
1733
1743
  tokens?: {
1734
1744
  input: number;
1735
1745
  output: number;
1736
1746
  };
1737
1747
  type: "turn_complete";
1738
1748
  }) | {
1749
+ executionId: string;
1750
+ id: string;
1751
+ iteration?: number;
1752
+ model?: string;
1753
+ ordinal: number;
1754
+ provider?: string;
1755
+ seq: number;
1756
+ startedAt?: string;
1757
+ stepId?: string;
1758
+ subagent?: {
1759
+ agentName?: string;
1760
+ parentToolCallId?: string;
1761
+ toolName: string;
1762
+ };
1763
+ turnId?: string;
1764
+ type: "model_call_start";
1765
+ } | {
1766
+ completedAt?: string;
1767
+ cost?: number;
1768
+ durationMs?: number;
1769
+ executionId: string;
1770
+ finishReason?: string;
1771
+ id: string;
1772
+ iteration?: number;
1773
+ model?: string;
1774
+ ordinal: number;
1775
+ provider?: string;
1776
+ responseModel?: string;
1777
+ seq: number;
1778
+ subagent?: {
1779
+ agentName?: string;
1780
+ parentToolCallId?: string;
1781
+ toolName: string;
1782
+ };
1783
+ success?: boolean;
1784
+ tokens?: {
1785
+ cacheRead?: number;
1786
+ cacheWrite?: number;
1787
+ input: number;
1788
+ output: number;
1789
+ };
1790
+ turnId?: string;
1791
+ type: "model_call_complete";
1792
+ } | {
1739
1793
  executionId: string;
1740
1794
  id: string;
1741
1795
  index?: number;
@@ -1744,6 +1798,11 @@ type RuntypeExecutionStreamEvent = ({
1744
1798
  seq: number;
1745
1799
  startedAt?: string;
1746
1800
  stepType?: string;
1801
+ subagent?: {
1802
+ agentName?: string;
1803
+ parentToolCallId?: string;
1804
+ toolName: string;
1805
+ };
1747
1806
  totalSteps?: number;
1748
1807
  type: "step_start";
1749
1808
  } | ({
@@ -1771,6 +1830,11 @@ type RuntypeExecutionStreamEvent = ({
1771
1830
  seq: number;
1772
1831
  stepType?: string;
1773
1832
  stopReason?: "end_turn" | "max_tool_calls" | "length" | "content_filter" | "error" | "unknown";
1833
+ subagent?: {
1834
+ agentName?: string;
1835
+ parentToolCallId?: string;
1836
+ toolName: string;
1837
+ };
1774
1838
  success?: boolean;
1775
1839
  tokensUsed?: number;
1776
1840
  type: "step_complete";
@@ -1793,6 +1857,11 @@ type RuntypeExecutionStreamEvent = ({
1793
1857
  role?: "user" | "assistant" | "system";
1794
1858
  seq: number;
1795
1859
  stepId?: string;
1860
+ subagent?: {
1861
+ agentName?: string;
1862
+ parentToolCallId?: string;
1863
+ toolName: string;
1864
+ };
1796
1865
  turnId?: string;
1797
1866
  type: "text_start";
1798
1867
  }) | {
@@ -1800,11 +1869,21 @@ type RuntypeExecutionStreamEvent = ({
1800
1869
  executionId: string;
1801
1870
  id: string;
1802
1871
  seq: number;
1872
+ subagent?: {
1873
+ agentName?: string;
1874
+ parentToolCallId?: string;
1875
+ toolName: string;
1876
+ };
1803
1877
  type: "text_delta";
1804
1878
  } | {
1805
1879
  executionId: string;
1806
1880
  id: string;
1807
1881
  seq: number;
1882
+ subagent?: {
1883
+ agentName?: string;
1884
+ parentToolCallId?: string;
1885
+ toolName: string;
1886
+ };
1808
1887
  text?: string;
1809
1888
  type: "text_complete";
1810
1889
  } | ({
@@ -1813,18 +1892,33 @@ type RuntypeExecutionStreamEvent = ({
1813
1892
  parentToolCallId?: string;
1814
1893
  scope?: "turn" | "loop";
1815
1894
  seq: number;
1895
+ subagent?: {
1896
+ agentName?: string;
1897
+ parentToolCallId?: string;
1898
+ toolName: string;
1899
+ };
1816
1900
  type: "reasoning_start";
1817
1901
  }) | {
1818
1902
  delta: string;
1819
1903
  executionId: string;
1820
1904
  id: string;
1821
1905
  seq: number;
1906
+ subagent?: {
1907
+ agentName?: string;
1908
+ parentToolCallId?: string;
1909
+ toolName: string;
1910
+ };
1822
1911
  type: "reasoning_delta";
1823
1912
  } | ({
1824
1913
  executionId: string;
1825
1914
  id: string;
1826
1915
  scope?: "turn" | "loop";
1827
1916
  seq: number;
1917
+ subagent?: {
1918
+ agentName?: string;
1919
+ parentToolCallId?: string;
1920
+ toolName: string;
1921
+ };
1828
1922
  text?: string;
1829
1923
  type: "reasoning_complete";
1830
1924
  }) | ({
@@ -1917,6 +2011,11 @@ type RuntypeExecutionStreamEvent = ({
1917
2011
  seq: number;
1918
2012
  startedAt?: string;
1919
2013
  stepId?: string;
2014
+ subagent?: {
2015
+ agentName?: string;
2016
+ parentToolCallId?: string;
2017
+ toolName: string;
2018
+ };
1920
2019
  toolCallId: string;
1921
2020
  toolName: string;
1922
2021
  toolType: string;
@@ -1925,6 +2024,11 @@ type RuntypeExecutionStreamEvent = ({
1925
2024
  delta: string;
1926
2025
  executionId: string;
1927
2026
  seq: number;
2027
+ subagent?: {
2028
+ agentName?: string;
2029
+ parentToolCallId?: string;
2030
+ toolName: string;
2031
+ };
1928
2032
  toolCallId: string;
1929
2033
  type: "tool_input_delta";
1930
2034
  } | {
@@ -1932,6 +2036,11 @@ type RuntypeExecutionStreamEvent = ({
1932
2036
  hiddenParameterNames?: Array<string>;
1933
2037
  parameters: Record<string, unknown>;
1934
2038
  seq: number;
2039
+ subagent?: {
2040
+ agentName?: string;
2041
+ parentToolCallId?: string;
2042
+ toolName: string;
2043
+ };
1935
2044
  toolCallId: string;
1936
2045
  toolName?: string;
1937
2046
  type: "tool_input_complete";
@@ -1949,6 +2058,11 @@ type RuntypeExecutionStreamEvent = ({
1949
2058
  result?: unknown;
1950
2059
  seq: number;
1951
2060
  stepId?: string;
2061
+ subagent?: {
2062
+ agentName?: string;
2063
+ parentToolCallId?: string;
2064
+ toolName: string;
2065
+ };
1952
2066
  success: boolean;
1953
2067
  toolCallId: string;
1954
2068
  toolCost?: number;
@@ -2028,6 +2142,19 @@ type RuntypeExecutionStreamEvent = ({
2028
2142
  recoverable?: boolean;
2029
2143
  seq: number;
2030
2144
  type: "error";
2145
+ }) | ({
2146
+ epoch: number;
2147
+ executionId: string;
2148
+ kind: "compaction";
2149
+ outcome?: "ok" | "failed" | "gap" | "skipped";
2150
+ phase: "start" | "complete";
2151
+ reason: "threshold" | "overflow" | "manual" | "surface_policy" | "provider_mismatch";
2152
+ seq: number;
2153
+ strategy: "provider_native" | "summary";
2154
+ tier: number;
2155
+ tokensAfter?: number;
2156
+ tokensBefore?: number;
2157
+ type: "context_notice";
2031
2158
  }) | {
2032
2159
  executionId: string;
2033
2160
  seq: number;
@@ -3087,15 +3214,15 @@ type AgentMessageMetadata = {
3087
3214
  */
3088
3215
  parentStepId?: string;
3089
3216
  /**
3090
- * Set to `true` on a tool-variant message produced from a `step_await`
3217
+ * Set to `true` on a tool-variant message produced from an `await`
3091
3218
  * event (`awaitReason: "local_tool_required"`). Signals to UI code that
3092
3219
  * the tool call is a LOCAL tool and the server is paused waiting for a
3093
3220
  * `POST /v1/dispatch/resume` with the user's answer keyed by tool name.
3094
3221
  */
3095
3222
  awaitingLocalTool?: boolean;
3096
3223
  /**
3097
- * The provider per-call id (`toolu_…`) carried on the `step_await` /
3098
- * `flow_await` events for a LOCAL tool (core#3878). Present only when the
3224
+ * The provider per-call id (`toolu_…`) carried on the `await`
3225
+ * event for a LOCAL tool (core#3878). Present only when the
3099
3226
  * server emits it. Two PARALLEL calls to the same tool in one turn share a
3100
3227
  * `toolName` (and a collapsed `toolId`) but get DISTINCT `webMcpToolCallId`s,
3101
3228
  * so this is the key the widget batches a single `/resume` on: preferred
@@ -5245,7 +5372,7 @@ type EventStreamConfig = {
5245
5372
  /**
5246
5373
  * Custom badge color mappings by event type prefix or exact type.
5247
5374
  * Keys are matched as exact match first, then prefix match (keys ending with "_").
5248
- * @example { "flow_": { bg: "#dcfce7", text: "#166534" }, "error": { bg: "#fecaca", text: "#991b1b" } }
5375
+ * @example { "execution_": { bg: "#dcfce7", text: "#166534" }, "error": { bg: "#fecaca", text: "#991b1b" } }
5249
5376
  */
5250
5377
  badgeColors?: Record<string, EventStreamBadgeColor>;
5251
5378
  /**
@@ -6666,9 +6793,13 @@ interface VoiceProvider {
6666
6793
  * `isFinal=false` is a live interim update (user partials, or assistant deltas
6667
6794
  * on providers that stream them); `isFinal=true` finalizes that role's text.
6668
6795
  * On the realtime `runtype` path, interim updates fire for the `user` only and
6669
- * the `assistant` arrives as a single final.
6796
+ * the `assistant` arrives as a single final. Providers with overlapping turns
6797
+ * must include the same turnId on user and assistant finals; without IDs,
6798
+ * providers must discard cancelled output before emitting the next user final.
6670
6799
  */
6671
- onTranscript?(callback: (role: 'user' | 'assistant', text: string, isFinal: boolean) => void): void;
6800
+ onTranscript?(callback: (role: 'user' | 'assistant', text: string, isFinal: boolean, metadata?: {
6801
+ turnId?: string;
6802
+ }) => void): void;
6672
6803
  /** Register a callback for per-turn latency metrics (realtime path). */
6673
6804
  onMetrics?(callback: (metrics: VoiceMetrics) => void): void;
6674
6805
  /**
@@ -8981,16 +9112,16 @@ type AgentWidgetConfig = {
8981
9112
  *
8982
9113
  * @example
8983
9114
  * ```typescript
8984
- * // For Runtype API format
9115
+ * // For a custom backend (Runtype unified events are handled natively)
8985
9116
  * config: {
8986
9117
  * parseSSEEvent: (data) => {
8987
- * if ((data.type === 'step_delta' || data.type === 'step_chunk') && (data.delta || data.chunk)) {
8988
- * return { text: data.delta ?? data.chunk };
9118
+ * if (data.type === 'token' && typeof data.value === 'string') {
9119
+ * return { text: data.value };
8989
9120
  * }
8990
- * if (data.type === 'flow_complete') {
9121
+ * if (data.type === 'done') {
8991
9122
  * return { done: true };
8992
9123
  * }
8993
- * if (data.type === 'step_error') {
9124
+ * if (data.type === 'failure') {
8994
9125
  * return { error: data.error };
8995
9126
  * }
8996
9127
  * return null; // Ignore other events
@@ -9181,7 +9312,7 @@ type AgentWidgetReasoning = {
9181
9312
  /**
9182
9313
  * Reasoning channel scope (wire spec). `"turn"` is ordinary per-turn
9183
9314
  * thinking; `"loop"` is a cross-iteration agent reflection (the fold that
9184
- * replaced the legacy `agent_reflection` event). Absent for legacy streams.
9315
+ * replaced the legacy `agent_reflection` event). Optional when the stream does not specify a scope.
9185
9316
  */
9186
9317
  scope?: "turn" | "loop";
9187
9318
  startedAt?: number;
@@ -9195,6 +9326,9 @@ type AgentWidgetToolCall = {
9195
9326
  args?: unknown;
9196
9327
  chunks?: string[];
9197
9328
  result?: unknown;
9329
+ /** Whether the tool succeeded; failure does not necessarily end the execution. */
9330
+ success?: boolean;
9331
+ error?: string;
9198
9332
  duration?: number;
9199
9333
  startedAt?: number;
9200
9334
  completedAt?: number;
@@ -9225,7 +9359,7 @@ type AgentWidgetApproval = {
9225
9359
  type AgentWidgetMessageVariant = "assistant" | "reasoning" | "tool" | "approval";
9226
9360
  /**
9227
9361
  * Per-turn / per-step stop reason emitted by the runtime on
9228
- * `agent_turn_complete` and `step_complete` SSE events. The vocabulary is
9362
+ * `turn_complete` and `step_complete` SSE events. The vocabulary is
9229
9363
  * owned by the upstream Runtype API: do not extend without coordination.
9230
9364
  *
9231
9365
  * - `end_turn`: natural completion (no affordance needed)
@@ -9356,7 +9490,7 @@ type AgentWidgetMessage = {
9356
9490
  */
9357
9491
  agentMetadata?: AgentMessageMetadata;
9358
9492
  /**
9359
- * Per-turn stop reason reported by the runtime on `agent_turn_complete`
9493
+ * Per-turn stop reason reported by the runtime on `turn_complete`
9360
9494
  * (agent-loop path) or the last `step_complete` for a prompt step
9361
9495
  * (dispatch / flow path). Absent when the API did not report a value.
9362
9496
  *
package/dist/codegen.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var w=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var R=(e,i)=>{for(var r in i)w(e,r,{get:i[r],enumerable:!0})},W=(e,i,r,s)=>{if(i&&typeof i=="object"||typeof i=="function")for(let a of T(i))!M.call(e,a)&&a!==r&&w(e,a,{get:()=>i[a],enumerable:!(s=_(i,a))||s.enumerable});return e};var H=e=>W(w({},"__esModule",{value:!0}),e);var z={};R(z,{generateCodeSnippet:()=>P});module.exports=H(z);var S="4.22.0";var j=S;function $(e){return e?.cdnBase?.trim().replace(/\/+$/,"").replace(/[\\'"<>`]/g,r=>`%${r.charCodeAt(0).toString(16).toUpperCase().padStart(2,"0")}`)||`https://cdn.jsdelivr.net/npm/@runtypelabs/persona@${j}/dist`}function u(e){if(e!==void 0)return typeof e=="string"?e:Array.isArray(e)?`[${e.map(i=>i.toString()).join(", ")}]`:e.toString()}function q(e){if(e)return{getHeaders:u(e.getHeaders),onFeedback:u(e.onFeedback),onCopy:u(e.onCopy),requestMiddleware:u(e.requestMiddleware),actionHandlers:u(e.actionHandlers),actionParsers:u(e.actionParsers),postprocessMessage:u(e.postprocessMessage),contextProviders:u(e.contextProviders),streamParser:u(e.streamParser)}}var A=`({ text, message }: any) => {
1
+ "use strict";var w=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var R=(e,i)=>{for(var r in i)w(e,r,{get:i[r],enumerable:!0})},W=(e,i,r,s)=>{if(i&&typeof i=="object"||typeof i=="function")for(let a of T(i))!M.call(e,a)&&a!==r&&w(e,a,{get:()=>i[a],enumerable:!(s=_(i,a))||s.enumerable});return e};var H=e=>W(w({},"__esModule",{value:!0}),e);var z={};R(z,{generateCodeSnippet:()=>P});module.exports=H(z);var S="4.22.1";var j=S;function $(e){return e?.cdnBase?.trim().replace(/\/+$/,"").replace(/[\\'"<>`]/g,r=>`%${r.charCodeAt(0).toString(16).toUpperCase().padStart(2,"0")}`)||`https://cdn.jsdelivr.net/npm/@runtypelabs/persona@${j}/dist`}function u(e){if(e!==void 0)return typeof e=="string"?e:Array.isArray(e)?`[${e.map(i=>i.toString()).join(", ")}]`:e.toString()}function q(e){if(e)return{getHeaders:u(e.getHeaders),onFeedback:u(e.onFeedback),onCopy:u(e.onCopy),requestMiddleware:u(e.requestMiddleware),actionHandlers:u(e.actionHandlers),actionParsers:u(e.actionParsers),postprocessMessage:u(e.postprocessMessage),contextProviders:u(e.contextProviders),streamParser:u(e.streamParser)}}var A=`({ text, message }: any) => {
2
2
  const jsonSource = (message as any).rawContent || text || message.content;
3
3
  if (!jsonSource || typeof jsonSource !== 'string') return null;
4
4
  let cleanJson = jsonSource
package/dist/codegen.js CHANGED
@@ -1,4 +1,4 @@
1
- var x="4.22.0";var S=x;function w(e){return e?.cdnBase?.trim().replace(/\/+$/,"").replace(/[\\'"<>`]/g,r=>`%${r.charCodeAt(0).toString(16).toUpperCase().padStart(2,"0")}`)||`https://cdn.jsdelivr.net/npm/@runtypelabs/persona@${S}/dist`}function u(e){if(e!==void 0)return typeof e=="string"?e:Array.isArray(e)?`[${e.map(i=>i.toString()).join(", ")}]`:e.toString()}function I(e){if(e)return{getHeaders:u(e.getHeaders),onFeedback:u(e.onFeedback),onCopy:u(e.onCopy),requestMiddleware:u(e.requestMiddleware),actionHandlers:u(e.actionHandlers),actionParsers:u(e.actionParsers),postprocessMessage:u(e.postprocessMessage),contextProviders:u(e.contextProviders),streamParser:u(e.streamParser)}}var j=`({ text, message }: any) => {
1
+ var x="4.22.1";var S=x;function w(e){return e?.cdnBase?.trim().replace(/\/+$/,"").replace(/[\\'"<>`]/g,r=>`%${r.charCodeAt(0).toString(16).toUpperCase().padStart(2,"0")}`)||`https://cdn.jsdelivr.net/npm/@runtypelabs/persona@${S}/dist`}function u(e){if(e!==void 0)return typeof e=="string"?e:Array.isArray(e)?`[${e.map(i=>i.toString()).join(", ")}]`:e.toString()}function I(e){if(e)return{getHeaders:u(e.getHeaders),onFeedback:u(e.onFeedback),onCopy:u(e.onCopy),requestMiddleware:u(e.requestMiddleware),actionHandlers:u(e.actionHandlers),actionParsers:u(e.actionParsers),postprocessMessage:u(e.postprocessMessage),contextProviders:u(e.contextProviders),streamParser:u(e.streamParser)}}var j=`({ text, message }: any) => {
2
2
  const jsonSource = (message as any).rawContent || text || message.content;
3
3
  if (!jsonSource || typeof jsonSource !== 'string') return null;
4
4
  let cleanJson = jsonSource