@runtypelabs/persona 4.5.0 → 4.6.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 (40) 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-C6tFDxKy.d.cts → types-8RICZWQe.d.cts} +6 -0
  4. package/dist/animations/{types-C6tFDxKy.d.ts → types-8RICZWQe.d.ts} +6 -0
  5. package/dist/animations/wipe.d.cts +1 -1
  6. package/dist/animations/wipe.d.ts +1 -1
  7. package/dist/chunk-DFBSCFYN.js +1 -0
  8. package/dist/codegen.cjs +1 -1
  9. package/dist/codegen.js +1 -1
  10. package/dist/index.cjs +51 -51
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +228 -2
  13. package/dist/index.d.ts +228 -2
  14. package/dist/index.global.js +37 -37
  15. package/dist/index.global.js.map +1 -1
  16. package/dist/index.js +51 -51
  17. package/dist/index.js.map +1 -1
  18. package/dist/launcher.global.js.map +1 -1
  19. package/dist/markdown-parsers-entry-NVFT3TE6.js +1 -0
  20. package/dist/runtype-tts-entry-HFUV2UF7.js +1 -0
  21. package/dist/session-reconnect-U77QFUR7.js +1 -0
  22. package/dist/smart-dom-reader.d.cts +90 -0
  23. package/dist/smart-dom-reader.d.ts +90 -0
  24. package/dist/theme-editor-preview.cjs +48 -48
  25. package/dist/theme-editor-preview.d.cts +130 -1
  26. package/dist/theme-editor-preview.d.ts +130 -1
  27. package/dist/theme-editor-preview.js +48 -48
  28. package/dist/theme-editor.d.cts +90 -0
  29. package/dist/theme-editor.d.ts +90 -0
  30. package/package.json +2 -2
  31. package/src/client.ts +48 -7
  32. package/src/generated/runtype-openapi-contract.ts +6 -0
  33. package/src/reconnect-wake.test.ts +162 -0
  34. package/src/reconnect.test.ts +430 -0
  35. package/src/session-reconnect.ts +282 -0
  36. package/src/session.ts +408 -5
  37. package/src/types.ts +107 -1
  38. package/src/ui.stream-animation-update.test.ts +99 -0
  39. package/src/ui.ts +71 -1
  40. package/src/utils/constants.ts +3 -1
@@ -1053,12 +1053,15 @@ type RuntypeExecutionStreamEvent = ({
1053
1053
  seq: number;
1054
1054
  type: "approval_complete";
1055
1055
  }) | ({
1056
+ awaitReason?: string;
1056
1057
  awaitedAt?: string;
1058
+ crawlId?: string;
1057
1059
  executionId: string;
1058
1060
  origin?: "webmcp" | "sdk";
1059
1061
  pageOrigin?: string;
1060
1062
  parameters?: Record<string, unknown>;
1061
1063
  seq: number;
1064
+ stepId?: string;
1062
1065
  toolCallId?: string;
1063
1066
  toolId?: string;
1064
1067
  toolName?: string;
@@ -1147,13 +1150,16 @@ type RuntypeFlowSSEEvent = {
1147
1150
  type: "flow_error";
1148
1151
  upgradeUrl?: string;
1149
1152
  }) | ({
1153
+ awaitReason?: string;
1150
1154
  awaitedAt: string;
1155
+ crawlId?: string;
1151
1156
  executionId?: string;
1152
1157
  flowId: string;
1153
1158
  origin?: "webmcp" | "sdk";
1154
1159
  pageOrigin?: string;
1155
1160
  parameters?: Record<string, unknown>;
1156
1161
  seq?: number;
1162
+ stepId?: string;
1157
1163
  toolCallId?: string;
1158
1164
  toolId?: string;
1159
1165
  toolName?: string;
@@ -1693,6 +1699,27 @@ type AgentWidgetWebMcpConfig = {
1693
1699
  */
1694
1700
  onConfirm?: WebMcpConfirmHandler;
1695
1701
  };
1702
+ /**
1703
+ * The coordinates needed to resume a durable agent turn after the SSE
1704
+ * connection drops (any resumable, server-persisted execution, e.g. Claude
1705
+ * Managed agents or async/background runs). Held on the session while a
1706
+ * resumable stream is in flight
1707
+ * and surfaced to the host via {@link AgentWidgetConfig.onExecutionState} so it
1708
+ * can persist `{ executionId, lastEventId }` next to its own `conversationId`
1709
+ * for the tab-reload path.
1710
+ *
1711
+ * `conversationId` is intentionally absent: it is host-owned (it lives in the
1712
+ * host's `reconnectStream`/`customFetch` closure; the widget never sees it).
1713
+ */
1714
+ type ResumableHandle = {
1715
+ /** The durable turn to reconnect to (from `agentMetadata.executionId`). */
1716
+ executionId: string;
1717
+ /** Highest SSE `id:` seq applied: the `?after=` reconnect cursor. */
1718
+ lastEventId: string;
1719
+ /** The open assistant message being streamed into, kept open on resume. */
1720
+ assistantMessageId: string;
1721
+ status: 'running';
1722
+ };
1696
1723
  /**
1697
1724
  * Metadata attached to messages created during agent execution.
1698
1725
  */
@@ -1975,6 +2002,22 @@ type AgentWidgetControllerEventMap = {
1975
2002
  approval: AgentWidgetApproval;
1976
2003
  decision: string;
1977
2004
  };
2005
+ /** A durable stream dropped; the widget is about to reconnect. */
2006
+ "stream:paused": {
2007
+ executionId: string;
2008
+ after: string;
2009
+ };
2010
+ /** A reconnect attempt is in flight (`attempt` is 1-based). */
2011
+ "stream:resuming": {
2012
+ executionId: string;
2013
+ after: string;
2014
+ attempt: number;
2015
+ };
2016
+ /** The durable turn resumed and reached its terminal after a reconnect. */
2017
+ "stream:resumed": {
2018
+ executionId: string;
2019
+ after: string;
2020
+ };
1978
2021
  };
1979
2022
  /**
1980
2023
  * Layout for the artifact split / drawer (CSS lengths unless noted).
@@ -3083,6 +3126,10 @@ type AgentWidgetStatusIndicatorConfig = {
3083
3126
  connectingText?: string;
3084
3127
  connectedText?: string;
3085
3128
  errorText?: string;
3129
+ /** Status text while a dropped durable stream is awaiting reconnect. */
3130
+ pausedText?: string;
3131
+ /** Status text while a reconnect attempt is in flight. */
3132
+ resumingText?: string;
3086
3133
  };
3087
3134
  type AgentWidgetVoiceRecognitionConfig = {
3088
3135
  enabled?: boolean;
@@ -5173,6 +5220,65 @@ type AgentWidgetConfig = {
5173
5220
  * ```
5174
5221
  */
5175
5222
  customFetch?: AgentWidgetCustomFetch;
5223
+ /**
5224
+ * Durable-session reconnect transport (host-owned, symmetric to
5225
+ * {@link customFetch}). When a durable agent stream drops mid-turn (any
5226
+ * resumable, server-persisted execution, e.g. Claude Managed agents or
5227
+ * async/background runs), the widget calls this to fetch the read-only
5228
+ * reconnect stream and pipes its body through the normal event pipeline to
5229
+ * resume from where it left off.
5230
+ *
5231
+ * The host closure owns `agentId` / `conversationId` / base URL / auth and
5232
+ * builds the events request, e.g.:
5233
+ *
5234
+ * ```typescript
5235
+ * reconnectStream: ({ executionId, after, signal }) =>
5236
+ * fetch(
5237
+ * `${baseUrl}/v1/agents/${agentId}/executions/${executionId}` +
5238
+ * `/events?conversationId=${conversationId}&after=${after}`,
5239
+ * { headers: { Authorization: `Bearer ${token}`, "X-Persona-Version": ver }, signal }
5240
+ * )
5241
+ * ```
5242
+ *
5243
+ * Resolve with a `text/event-stream` `Response`. Throw or resolve non-ok to
5244
+ * signal "this attempt failed" (the widget backs off and retries, then gives
5245
+ * up after the bounded attempts). Reconnect only ever arms on the durable
5246
+ * lane (streams carrying SSE `id:` lines); without this hook a drop finalizes
5247
+ * exactly as before.
5248
+ */
5249
+ reconnectStream?: (ctx: {
5250
+ executionId: string;
5251
+ after: string;
5252
+ signal: AbortSignal;
5253
+ }) => Promise<Response>;
5254
+ /**
5255
+ * Tuning for the auto-reconnect backoff. Defaults to ~5 attempts over ~30s
5256
+ * (`backoffMs: [1000, 2000, 4000, 8000, 8000]`).
5257
+ */
5258
+ reconnect?: {
5259
+ /** Max reconnect attempts before giving up and finalizing. @default backoffMs.length */
5260
+ maxAttempts?: number;
5261
+ /** Per-attempt delay (ms) before each retry. @default [1000, 2000, 4000, 8000, 8000] */
5262
+ backoffMs?: number[];
5263
+ };
5264
+ /**
5265
+ * Called whenever the durable resume handle changes: created when a durable
5266
+ * turn starts streaming, updated as the cursor advances (throttled), and
5267
+ * `null` when the turn finishes, errors, or is torn down. Persist
5268
+ * `{ executionId, lastEventId }` next to your `conversationId` and pass it
5269
+ * back via {@link resume} on the next mount to survive a tab reload.
5270
+ */
5271
+ onExecutionState?: (handle: ResumableHandle | null) => void;
5272
+ /**
5273
+ * Resume a durable turn on boot (tab-reload path). When present alongside
5274
+ * {@link reconnectStream}, the widget enters `resuming` immediately on mount
5275
+ * and reconnects from `after`, replaying everything past the cursor into the
5276
+ * restored conversation.
5277
+ */
5278
+ resume?: {
5279
+ executionId: string;
5280
+ after: string;
5281
+ };
5176
5282
  /**
5177
5283
  * Custom SSE event parser for non-standard streaming response formats.
5178
5284
  *
@@ -5715,9 +5821,27 @@ type AgentWidgetEvent = {
5715
5821
  } | {
5716
5822
  type: "status";
5717
5823
  status: "connecting" | "connected" | "error" | "idle";
5824
+ /**
5825
+ * Set on the `idle` emitted from a graceful execution terminal
5826
+ * (`execution_complete`). Distinguishes a real finish from the plain
5827
+ * `idle` the dispatch wrappers emit in their `finally` on a dropped
5828
+ * connection. The durable-reconnect drop detection keys off this.
5829
+ */
5830
+ terminal?: boolean;
5718
5831
  } | {
5719
5832
  type: "error";
5720
5833
  error: Error;
5834
+ }
5835
+ /**
5836
+ * Durable-session reconnect cursor. Carries the SSE `id:` line (the durable
5837
+ * row seq) of a fully-parsed frame so the session can track `lastEventId`
5838
+ * and resume from `?after=<id>` after a drop. Only emitted on the durable
5839
+ * lane (any resumable execution that stamps `id:` lines, e.g. Claude Managed
5840
+ * agents or async/background runs).
5841
+ */
5842
+ | {
5843
+ type: "cursor";
5844
+ id: string;
5721
5845
  } | {
5722
5846
  type: "artifact_start";
5723
5847
  id: string;
@@ -5738,7 +5862,7 @@ type AgentWidgetEvent = {
5738
5862
  id: string;
5739
5863
  };
5740
5864
 
5741
- type AgentWidgetSessionStatus = "idle" | "connecting" | "connected" | "error";
5865
+ type AgentWidgetSessionStatus = "idle" | "connecting" | "connected" | "error" | "paused" | "resuming";
5742
5866
 
5743
5867
  /**
5744
5868
  * Feedback UI components for CSAT and NPS collection
@@ -5795,6 +5919,11 @@ type Controller = {
5795
5919
  clearChat: () => void;
5796
5920
  setMessage: (message: string) => boolean;
5797
5921
  submitMessage: (message?: string) => boolean;
5922
+ /**
5923
+ * Manually retry a dropped durable stream (e.g. from a "Reconnect" button).
5924
+ * No-op unless a resumable durable turn dropped and `reconnectStream` is set.
5925
+ */
5926
+ reconnect: () => void;
5798
5927
  startVoiceRecognition: () => boolean;
5799
5928
  stopVoiceRecognition: () => boolean;
5800
5929
  /**
@@ -1053,12 +1053,15 @@ type RuntypeExecutionStreamEvent = ({
1053
1053
  seq: number;
1054
1054
  type: "approval_complete";
1055
1055
  }) | ({
1056
+ awaitReason?: string;
1056
1057
  awaitedAt?: string;
1058
+ crawlId?: string;
1057
1059
  executionId: string;
1058
1060
  origin?: "webmcp" | "sdk";
1059
1061
  pageOrigin?: string;
1060
1062
  parameters?: Record<string, unknown>;
1061
1063
  seq: number;
1064
+ stepId?: string;
1062
1065
  toolCallId?: string;
1063
1066
  toolId?: string;
1064
1067
  toolName?: string;
@@ -1147,13 +1150,16 @@ type RuntypeFlowSSEEvent = {
1147
1150
  type: "flow_error";
1148
1151
  upgradeUrl?: string;
1149
1152
  }) | ({
1153
+ awaitReason?: string;
1150
1154
  awaitedAt: string;
1155
+ crawlId?: string;
1151
1156
  executionId?: string;
1152
1157
  flowId: string;
1153
1158
  origin?: "webmcp" | "sdk";
1154
1159
  pageOrigin?: string;
1155
1160
  parameters?: Record<string, unknown>;
1156
1161
  seq?: number;
1162
+ stepId?: string;
1157
1163
  toolCallId?: string;
1158
1164
  toolId?: string;
1159
1165
  toolName?: string;
@@ -1693,6 +1699,27 @@ type AgentWidgetWebMcpConfig = {
1693
1699
  */
1694
1700
  onConfirm?: WebMcpConfirmHandler;
1695
1701
  };
1702
+ /**
1703
+ * The coordinates needed to resume a durable agent turn after the SSE
1704
+ * connection drops (any resumable, server-persisted execution, e.g. Claude
1705
+ * Managed agents or async/background runs). Held on the session while a
1706
+ * resumable stream is in flight
1707
+ * and surfaced to the host via {@link AgentWidgetConfig.onExecutionState} so it
1708
+ * can persist `{ executionId, lastEventId }` next to its own `conversationId`
1709
+ * for the tab-reload path.
1710
+ *
1711
+ * `conversationId` is intentionally absent: it is host-owned (it lives in the
1712
+ * host's `reconnectStream`/`customFetch` closure; the widget never sees it).
1713
+ */
1714
+ type ResumableHandle = {
1715
+ /** The durable turn to reconnect to (from `agentMetadata.executionId`). */
1716
+ executionId: string;
1717
+ /** Highest SSE `id:` seq applied: the `?after=` reconnect cursor. */
1718
+ lastEventId: string;
1719
+ /** The open assistant message being streamed into, kept open on resume. */
1720
+ assistantMessageId: string;
1721
+ status: 'running';
1722
+ };
1696
1723
  /**
1697
1724
  * Metadata attached to messages created during agent execution.
1698
1725
  */
@@ -1975,6 +2002,22 @@ type AgentWidgetControllerEventMap = {
1975
2002
  approval: AgentWidgetApproval;
1976
2003
  decision: string;
1977
2004
  };
2005
+ /** A durable stream dropped; the widget is about to reconnect. */
2006
+ "stream:paused": {
2007
+ executionId: string;
2008
+ after: string;
2009
+ };
2010
+ /** A reconnect attempt is in flight (`attempt` is 1-based). */
2011
+ "stream:resuming": {
2012
+ executionId: string;
2013
+ after: string;
2014
+ attempt: number;
2015
+ };
2016
+ /** The durable turn resumed and reached its terminal after a reconnect. */
2017
+ "stream:resumed": {
2018
+ executionId: string;
2019
+ after: string;
2020
+ };
1978
2021
  };
1979
2022
  /**
1980
2023
  * Layout for the artifact split / drawer (CSS lengths unless noted).
@@ -3083,6 +3126,10 @@ type AgentWidgetStatusIndicatorConfig = {
3083
3126
  connectingText?: string;
3084
3127
  connectedText?: string;
3085
3128
  errorText?: string;
3129
+ /** Status text while a dropped durable stream is awaiting reconnect. */
3130
+ pausedText?: string;
3131
+ /** Status text while a reconnect attempt is in flight. */
3132
+ resumingText?: string;
3086
3133
  };
3087
3134
  type AgentWidgetVoiceRecognitionConfig = {
3088
3135
  enabled?: boolean;
@@ -5173,6 +5220,65 @@ type AgentWidgetConfig = {
5173
5220
  * ```
5174
5221
  */
5175
5222
  customFetch?: AgentWidgetCustomFetch;
5223
+ /**
5224
+ * Durable-session reconnect transport (host-owned, symmetric to
5225
+ * {@link customFetch}). When a durable agent stream drops mid-turn (any
5226
+ * resumable, server-persisted execution, e.g. Claude Managed agents or
5227
+ * async/background runs), the widget calls this to fetch the read-only
5228
+ * reconnect stream and pipes its body through the normal event pipeline to
5229
+ * resume from where it left off.
5230
+ *
5231
+ * The host closure owns `agentId` / `conversationId` / base URL / auth and
5232
+ * builds the events request, e.g.:
5233
+ *
5234
+ * ```typescript
5235
+ * reconnectStream: ({ executionId, after, signal }) =>
5236
+ * fetch(
5237
+ * `${baseUrl}/v1/agents/${agentId}/executions/${executionId}` +
5238
+ * `/events?conversationId=${conversationId}&after=${after}`,
5239
+ * { headers: { Authorization: `Bearer ${token}`, "X-Persona-Version": ver }, signal }
5240
+ * )
5241
+ * ```
5242
+ *
5243
+ * Resolve with a `text/event-stream` `Response`. Throw or resolve non-ok to
5244
+ * signal "this attempt failed" (the widget backs off and retries, then gives
5245
+ * up after the bounded attempts). Reconnect only ever arms on the durable
5246
+ * lane (streams carrying SSE `id:` lines); without this hook a drop finalizes
5247
+ * exactly as before.
5248
+ */
5249
+ reconnectStream?: (ctx: {
5250
+ executionId: string;
5251
+ after: string;
5252
+ signal: AbortSignal;
5253
+ }) => Promise<Response>;
5254
+ /**
5255
+ * Tuning for the auto-reconnect backoff. Defaults to ~5 attempts over ~30s
5256
+ * (`backoffMs: [1000, 2000, 4000, 8000, 8000]`).
5257
+ */
5258
+ reconnect?: {
5259
+ /** Max reconnect attempts before giving up and finalizing. @default backoffMs.length */
5260
+ maxAttempts?: number;
5261
+ /** Per-attempt delay (ms) before each retry. @default [1000, 2000, 4000, 8000, 8000] */
5262
+ backoffMs?: number[];
5263
+ };
5264
+ /**
5265
+ * Called whenever the durable resume handle changes: created when a durable
5266
+ * turn starts streaming, updated as the cursor advances (throttled), and
5267
+ * `null` when the turn finishes, errors, or is torn down. Persist
5268
+ * `{ executionId, lastEventId }` next to your `conversationId` and pass it
5269
+ * back via {@link resume} on the next mount to survive a tab reload.
5270
+ */
5271
+ onExecutionState?: (handle: ResumableHandle | null) => void;
5272
+ /**
5273
+ * Resume a durable turn on boot (tab-reload path). When present alongside
5274
+ * {@link reconnectStream}, the widget enters `resuming` immediately on mount
5275
+ * and reconnects from `after`, replaying everything past the cursor into the
5276
+ * restored conversation.
5277
+ */
5278
+ resume?: {
5279
+ executionId: string;
5280
+ after: string;
5281
+ };
5176
5282
  /**
5177
5283
  * Custom SSE event parser for non-standard streaming response formats.
5178
5284
  *
@@ -5715,9 +5821,27 @@ type AgentWidgetEvent = {
5715
5821
  } | {
5716
5822
  type: "status";
5717
5823
  status: "connecting" | "connected" | "error" | "idle";
5824
+ /**
5825
+ * Set on the `idle` emitted from a graceful execution terminal
5826
+ * (`execution_complete`). Distinguishes a real finish from the plain
5827
+ * `idle` the dispatch wrappers emit in their `finally` on a dropped
5828
+ * connection. The durable-reconnect drop detection keys off this.
5829
+ */
5830
+ terminal?: boolean;
5718
5831
  } | {
5719
5832
  type: "error";
5720
5833
  error: Error;
5834
+ }
5835
+ /**
5836
+ * Durable-session reconnect cursor. Carries the SSE `id:` line (the durable
5837
+ * row seq) of a fully-parsed frame so the session can track `lastEventId`
5838
+ * and resume from `?after=<id>` after a drop. Only emitted on the durable
5839
+ * lane (any resumable execution that stamps `id:` lines, e.g. Claude Managed
5840
+ * agents or async/background runs).
5841
+ */
5842
+ | {
5843
+ type: "cursor";
5844
+ id: string;
5721
5845
  } | {
5722
5846
  type: "artifact_start";
5723
5847
  id: string;
@@ -5738,7 +5862,7 @@ type AgentWidgetEvent = {
5738
5862
  id: string;
5739
5863
  };
5740
5864
 
5741
- type AgentWidgetSessionStatus = "idle" | "connecting" | "connected" | "error";
5865
+ type AgentWidgetSessionStatus = "idle" | "connecting" | "connected" | "error" | "paused" | "resuming";
5742
5866
 
5743
5867
  /**
5744
5868
  * Feedback UI components for CSAT and NPS collection
@@ -5795,6 +5919,11 @@ type Controller = {
5795
5919
  clearChat: () => void;
5796
5920
  setMessage: (message: string) => boolean;
5797
5921
  submitMessage: (message?: string) => boolean;
5922
+ /**
5923
+ * Manually retry a dropped durable stream (e.g. from a "Reconnect" button).
5924
+ * No-op unless a resumable durable turn dropped and `reconnectStream` is set.
5925
+ */
5926
+ reconnect: () => void;
5798
5927
  startVoiceRecognition: () => boolean;
5799
5928
  stopVoiceRecognition: () => boolean;
5800
5929
  /**