@runtypelabs/persona 4.5.0 → 4.6.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 (42) 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-CSmiKRVa.d.cts} +11 -0
  4. package/dist/animations/{types-C6tFDxKy.d.ts → types-CSmiKRVa.d.ts} +11 -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 +4 -4
  9. package/dist/codegen.js +4 -4
  10. package/dist/index.cjs +51 -51
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +238 -3
  13. package/dist/index.d.ts +238 -3
  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 +95 -0
  23. package/dist/smart-dom-reader.d.ts +95 -0
  24. package/dist/theme-editor-preview.cjs +48 -48
  25. package/dist/theme-editor-preview.d.cts +135 -1
  26. package/dist/theme-editor-preview.d.ts +135 -1
  27. package/dist/theme-editor-preview.js +48 -48
  28. package/dist/theme-editor.d.cts +95 -0
  29. package/dist/theme-editor.d.ts +95 -0
  30. package/package.json +5 -3
  31. package/src/client.ts +55 -9
  32. package/src/generated/runtype-openapi-contract.ts +16 -1
  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
  41. package/src/utils/morph.test.ts +47 -0
  42. package/src/utils/morph.ts +18 -0
package/dist/index.d.cts CHANGED
@@ -812,6 +812,7 @@ type RuntypeExecutionStreamEvent = ({
812
812
  };
813
813
  type: "execution_complete";
814
814
  }) | ({
815
+ blockReason?: string;
815
816
  code?: string;
816
817
  completedAt?: string;
817
818
  error: string | {
@@ -1066,6 +1067,7 @@ type RuntypeExecutionStreamEvent = ({
1066
1067
  startedAt?: string;
1067
1068
  subagent?: {
1068
1069
  agentName?: string;
1070
+ parentToolCallId?: string;
1069
1071
  toolName: string;
1070
1072
  };
1071
1073
  timeout?: number;
@@ -1082,12 +1084,15 @@ type RuntypeExecutionStreamEvent = ({
1082
1084
  seq: number;
1083
1085
  type: "approval_complete";
1084
1086
  }) | ({
1087
+ awaitReason?: string;
1085
1088
  awaitedAt?: string;
1089
+ crawlId?: string;
1086
1090
  executionId: string;
1087
1091
  origin?: "webmcp" | "sdk";
1088
1092
  pageOrigin?: string;
1089
1093
  parameters?: Record<string, unknown>;
1090
1094
  seq: number;
1095
+ stepId?: string;
1091
1096
  toolCallId?: string;
1092
1097
  toolId?: string;
1093
1098
  toolName?: string;
@@ -1156,6 +1161,7 @@ type RuntypeFlowSSEEvent = {
1156
1161
  totalTokensUsed?: number;
1157
1162
  type: "flow_complete";
1158
1163
  } | ({
1164
+ blockReason?: string;
1159
1165
  code?: string;
1160
1166
  error: string | {
1161
1167
  code: string;
@@ -1176,13 +1182,18 @@ type RuntypeFlowSSEEvent = {
1176
1182
  type: "flow_error";
1177
1183
  upgradeUrl?: string;
1178
1184
  }) | ({
1185
+ approvalId?: string;
1186
+ awaitReason?: string;
1179
1187
  awaitedAt: string;
1188
+ crawlId?: string;
1180
1189
  executionId?: string;
1181
1190
  flowId: string;
1182
1191
  origin?: "webmcp" | "sdk";
1183
1192
  pageOrigin?: string;
1184
1193
  parameters?: Record<string, unknown>;
1185
1194
  seq?: number;
1195
+ stepId?: string;
1196
+ timeout?: number;
1186
1197
  toolCallId?: string;
1187
1198
  toolId?: string;
1188
1199
  toolName?: string;
@@ -1425,7 +1436,7 @@ type RuntypeClientInitResponse = {
1425
1436
  welcomeMessage?: string | null;
1426
1437
  };
1427
1438
  expiresAt: string;
1428
- flow: {
1439
+ flow?: {
1429
1440
  description?: string | null;
1430
1441
  id: string;
1431
1442
  name?: string | null;
@@ -1446,6 +1457,10 @@ type RuntypeClientChatRequest = {
1446
1457
  untrustedContentHint?: boolean;
1447
1458
  }>;
1448
1459
  clientToolsFingerprint?: string;
1460
+ identityProof?: {
1461
+ provider: string;
1462
+ token: string;
1463
+ };
1449
1464
  inputs?: Record<string, unknown>;
1450
1465
  messages: Array<{
1451
1466
  content: string | (Array<{
@@ -1888,6 +1903,27 @@ type AgentExecutionState = {
1888
1903
  completedAt?: number;
1889
1904
  stopReason?: 'complete' | 'end_turn' | 'max_turns' | 'max_cost' | 'timeout' | 'error';
1890
1905
  };
1906
+ /**
1907
+ * The coordinates needed to resume a durable agent turn after the SSE
1908
+ * connection drops (any resumable, server-persisted execution, e.g. Claude
1909
+ * Managed agents or async/background runs). Held on the session while a
1910
+ * resumable stream is in flight
1911
+ * and surfaced to the host via {@link AgentWidgetConfig.onExecutionState} so it
1912
+ * can persist `{ executionId, lastEventId }` next to its own `conversationId`
1913
+ * for the tab-reload path.
1914
+ *
1915
+ * `conversationId` is intentionally absent: it is host-owned (it lives in the
1916
+ * host's `reconnectStream`/`customFetch` closure; the widget never sees it).
1917
+ */
1918
+ type ResumableHandle = {
1919
+ /** The durable turn to reconnect to (from `agentMetadata.executionId`). */
1920
+ executionId: string;
1921
+ /** Highest SSE `id:` seq applied: the `?after=` reconnect cursor. */
1922
+ lastEventId: string;
1923
+ /** The open assistant message being streamed into, kept open on resume. */
1924
+ assistantMessageId: string;
1925
+ status: 'running';
1926
+ };
1891
1927
  /**
1892
1928
  * Metadata attached to messages created during agent execution.
1893
1929
  */
@@ -2170,6 +2206,22 @@ type AgentWidgetControllerEventMap = {
2170
2206
  approval: AgentWidgetApproval;
2171
2207
  decision: string;
2172
2208
  };
2209
+ /** A durable stream dropped; the widget is about to reconnect. */
2210
+ "stream:paused": {
2211
+ executionId: string;
2212
+ after: string;
2213
+ };
2214
+ /** A reconnect attempt is in flight (`attempt` is 1-based). */
2215
+ "stream:resuming": {
2216
+ executionId: string;
2217
+ after: string;
2218
+ attempt: number;
2219
+ };
2220
+ /** The durable turn resumed and reached its terminal after a reconnect. */
2221
+ "stream:resumed": {
2222
+ executionId: string;
2223
+ after: string;
2224
+ };
2173
2225
  };
2174
2226
  /**
2175
2227
  * Layout for the artifact split / drawer (CSS lengths unless noted).
@@ -3278,6 +3330,10 @@ type AgentWidgetStatusIndicatorConfig = {
3278
3330
  connectingText?: string;
3279
3331
  connectedText?: string;
3280
3332
  errorText?: string;
3333
+ /** Status text while a dropped durable stream is awaiting reconnect. */
3334
+ pausedText?: string;
3335
+ /** Status text while a reconnect attempt is in flight. */
3336
+ resumingText?: string;
3281
3337
  };
3282
3338
  type AgentWidgetVoiceRecognitionConfig = {
3283
3339
  enabled?: boolean;
@@ -5469,6 +5525,65 @@ type AgentWidgetConfig = {
5469
5525
  * ```
5470
5526
  */
5471
5527
  customFetch?: AgentWidgetCustomFetch;
5528
+ /**
5529
+ * Durable-session reconnect transport (host-owned, symmetric to
5530
+ * {@link customFetch}). When a durable agent stream drops mid-turn (any
5531
+ * resumable, server-persisted execution, e.g. Claude Managed agents or
5532
+ * async/background runs), the widget calls this to fetch the read-only
5533
+ * reconnect stream and pipes its body through the normal event pipeline to
5534
+ * resume from where it left off.
5535
+ *
5536
+ * The host closure owns `agentId` / `conversationId` / base URL / auth and
5537
+ * builds the events request, e.g.:
5538
+ *
5539
+ * ```typescript
5540
+ * reconnectStream: ({ executionId, after, signal }) =>
5541
+ * fetch(
5542
+ * `${baseUrl}/v1/agents/${agentId}/executions/${executionId}` +
5543
+ * `/events?conversationId=${conversationId}&after=${after}`,
5544
+ * { headers: { Authorization: `Bearer ${token}`, "X-Persona-Version": ver }, signal }
5545
+ * )
5546
+ * ```
5547
+ *
5548
+ * Resolve with a `text/event-stream` `Response`. Throw or resolve non-ok to
5549
+ * signal "this attempt failed" (the widget backs off and retries, then gives
5550
+ * up after the bounded attempts). Reconnect only ever arms on the durable
5551
+ * lane (streams carrying SSE `id:` lines); without this hook a drop finalizes
5552
+ * exactly as before.
5553
+ */
5554
+ reconnectStream?: (ctx: {
5555
+ executionId: string;
5556
+ after: string;
5557
+ signal: AbortSignal;
5558
+ }) => Promise<Response>;
5559
+ /**
5560
+ * Tuning for the auto-reconnect backoff. Defaults to ~5 attempts over ~30s
5561
+ * (`backoffMs: [1000, 2000, 4000, 8000, 8000]`).
5562
+ */
5563
+ reconnect?: {
5564
+ /** Max reconnect attempts before giving up and finalizing. @default backoffMs.length */
5565
+ maxAttempts?: number;
5566
+ /** Per-attempt delay (ms) before each retry. @default [1000, 2000, 4000, 8000, 8000] */
5567
+ backoffMs?: number[];
5568
+ };
5569
+ /**
5570
+ * Called whenever the durable resume handle changes: created when a durable
5571
+ * turn starts streaming, updated as the cursor advances (throttled), and
5572
+ * `null` when the turn finishes, errors, or is torn down. Persist
5573
+ * `{ executionId, lastEventId }` next to your `conversationId` and pass it
5574
+ * back via {@link resume} on the next mount to survive a tab reload.
5575
+ */
5576
+ onExecutionState?: (handle: ResumableHandle | null) => void;
5577
+ /**
5578
+ * Resume a durable turn on boot (tab-reload path). When present alongside
5579
+ * {@link reconnectStream}, the widget enters `resuming` immediately on mount
5580
+ * and reconnects from `after`, replaying everything past the cursor into the
5581
+ * restored conversation.
5582
+ */
5583
+ resume?: {
5584
+ executionId: string;
5585
+ after: string;
5586
+ };
5472
5587
  /**
5473
5588
  * Custom SSE event parser for non-standard streaming response formats.
5474
5589
  *
@@ -6011,9 +6126,27 @@ type AgentWidgetEvent = {
6011
6126
  } | {
6012
6127
  type: "status";
6013
6128
  status: "connecting" | "connected" | "error" | "idle";
6129
+ /**
6130
+ * Set on the `idle` emitted from a graceful execution terminal
6131
+ * (`execution_complete`). Distinguishes a real finish from the plain
6132
+ * `idle` the dispatch wrappers emit in their `finally` on a dropped
6133
+ * connection. The durable-reconnect drop detection keys off this.
6134
+ */
6135
+ terminal?: boolean;
6014
6136
  } | {
6015
6137
  type: "error";
6016
6138
  error: Error;
6139
+ }
6140
+ /**
6141
+ * Durable-session reconnect cursor. Carries the SSE `id:` line (the durable
6142
+ * row seq) of a fully-parsed frame so the session can track `lastEventId`
6143
+ * and resume from `?after=<id>` after a drop. Only emitted on the durable
6144
+ * lane (any resumable execution that stamps `id:` lines, e.g. Claude Managed
6145
+ * agents or async/background runs).
6146
+ */
6147
+ | {
6148
+ type: "cursor";
6149
+ id: string;
6017
6150
  } | {
6018
6151
  type: "artifact_start";
6019
6152
  id: string;
@@ -6243,7 +6376,7 @@ declare class AgentWidgetClient {
6243
6376
  * This allows piping responses from endpoints like agent approval
6244
6377
  * through the same message/tool/reasoning handling as dispatch().
6245
6378
  */
6246
- processStream(body: ReadableStream<Uint8Array>, onEvent: SSEHandler, assistantMessageId?: string): Promise<void>;
6379
+ processStream(body: ReadableStream<Uint8Array>, onEvent: SSEHandler, assistantMessageId?: string, seedContent?: string): Promise<void>;
6247
6380
  /**
6248
6381
  * Send an approval decision to the API and return the response
6249
6382
  * for streaming continuation.
@@ -6358,7 +6491,7 @@ declare class ReadAloudController {
6358
6491
  private set;
6359
6492
  }
6360
6493
 
6361
- type AgentWidgetSessionStatus = "idle" | "connecting" | "connected" | "error";
6494
+ type AgentWidgetSessionStatus = "idle" | "connecting" | "connected" | "error" | "paused" | "resuming";
6362
6495
  type SessionCallbacks = {
6363
6496
  onMessagesChanged: (messages: AgentWidgetMessage[]) => void;
6364
6497
  onStatusChanged: (status: AgentWidgetSessionStatus) => void;
@@ -6369,6 +6502,17 @@ type SessionCallbacks = {
6369
6502
  artifacts: PersonaArtifactRecord[];
6370
6503
  selectedId: string | null;
6371
6504
  }) => void;
6505
+ /**
6506
+ * Durable-session reconnect lifecycle, surfaced so the UI can map it to the
6507
+ * public `stream:paused` / `stream:resuming` / `stream:resumed` controller
6508
+ * events. `paused` fires once on the drop, `resuming` once per attempt,
6509
+ * `resumed` when a reconnect reaches its terminal.
6510
+ */
6511
+ onReconnect?: (event: {
6512
+ phase: "paused" | "resuming" | "resumed";
6513
+ handle: ResumableHandle;
6514
+ attempt?: number;
6515
+ }) => void;
6372
6516
  };
6373
6517
  declare class AgentWidgetSession {
6374
6518
  private config;
@@ -6381,6 +6525,12 @@ declare class AgentWidgetSession {
6381
6525
  private sequenceCounter;
6382
6526
  private clientSession;
6383
6527
  private agentExecution;
6528
+ private resumable;
6529
+ private activeAssistantMessageId;
6530
+ private reconnecting;
6531
+ private reconnectController;
6532
+ private reconnectControllerPromise;
6533
+ private executionStateTimer;
6384
6534
  private artifacts;
6385
6535
  private selectedArtifactId;
6386
6536
  private webMcpInflightKeys;
@@ -6652,6 +6802,19 @@ declare class AgentWidgetSession {
6652
6802
  connectStream(stream: ReadableStream<Uint8Array>, options?: {
6653
6803
  assistantMessageId?: string;
6654
6804
  allowReentry?: boolean;
6805
+ /**
6806
+ * Durable reconnect: keep the assistant message identified by
6807
+ * `assistantMessageId` OPEN so the replayed deltas keep filling it. The
6808
+ * default stale-finalize pass would otherwise seal the very bubble we're
6809
+ * resuming into.
6810
+ */
6811
+ preserveAssistantId?: boolean;
6812
+ /**
6813
+ * Durable reconnect: text already shown in the resumed bubble, so the
6814
+ * fresh stream's accumulator continues from it (the replay carries only
6815
+ * post-cursor deltas, not the full text).
6816
+ */
6817
+ seedContent?: string;
6655
6818
  }): Promise<void>;
6656
6819
  /**
6657
6820
  * Install the native approval-bubble confirm handler on the WebMCP bridge
@@ -6835,6 +6998,73 @@ declare class AgentWidgetSession {
6835
6998
  hydrateMessages(messages: AgentWidgetMessage[]): void;
6836
6999
  hydrateArtifacts(artifacts: PersonaArtifactRecord[], selectedId?: string | null): void;
6837
7000
  private handleEvent;
7001
+ /**
7002
+ * Record the latest SSE `id:` cursor and (lazily) form/advance the resume
7003
+ * handle. Needs an executionId (lifted into `agentExecution` from the same
7004
+ * frame's metadata, handled before this trailing cursor event) and the active
7005
+ * assistant message id.
7006
+ */
7007
+ private trackCursor;
7008
+ /**
7009
+ * The drop gate: is this stream-end a dropped connection we should reconnect,
7010
+ * rather than a graceful finish or an intentional `step_await` pause? ALL must
7011
+ * hold (see plan §Design overview keystone 3).
7012
+ */
7013
+ private isDurableDrop;
7014
+ /**
7015
+ * True when the run is parked awaiting user input (an unanswered
7016
+ * `ask_user_question` / local-tool await, or a pending approval). Those end
7017
+ * the stream with `idle` and no terminal too, but are NOT drops.
7018
+ */
7019
+ private isAwaitPending;
7020
+ /**
7021
+ * Enter the reconnect flow. Keeps the assistant bubble open and `streaming`
7022
+ * true, flips to `resuming`, and kicks the bounded backoff loop. Re-entrant
7023
+ * calls (a second drop while reconnecting) are no-ops.
7024
+ */
7025
+ private beginReconnect;
7026
+ /**
7027
+ * Lazily import and instantiate the reconnect controller. Cached so repeated
7028
+ * reconnects reuse one controller (and one module load). Deliberately kept off
7029
+ * every hot path (`sendMessage` / `cancel` / `teardownReconnect`) so a widget
7030
+ * that never reconnects never pulls the chunk.
7031
+ */
7032
+ private loadReconnectController;
7033
+ /** The narrow surface the lazily-loaded reconnect loop drives. */
7034
+ private buildReconnectHost;
7035
+ /** Public manual retry (e.g. a "Reconnect" button). */
7036
+ reconnectNow(): void;
7037
+ /**
7038
+ * Resume a durable turn on boot (tab-reload path). Re-opens the trailing
7039
+ * assistant bubble (or mints one), restores the execution/handle, and
7040
+ * reconnects from the persisted cursor. No-op without `reconnectStream`.
7041
+ */
7042
+ resumeFromHandle(resume: {
7043
+ executionId: string;
7044
+ after: string;
7045
+ }): void;
7046
+ /**
7047
+ * Reopen the trailing assistant bubble (the persisted partial) so replayed
7048
+ * deltas append to it. Returns its id, or null if the last turn doesn't end
7049
+ * in a plain assistant message.
7050
+ */
7051
+ private reopenTrailingAssistant;
7052
+ /**
7053
+ * Tear down any in-flight/pending reconnect and clear the resume handle. Runs
7054
+ * on every new turn / cancel / hydrate, so it must NOT pull the reconnect
7055
+ * chunk: it only delegates to the controller if one was already created.
7056
+ */
7057
+ private teardownReconnect;
7058
+ /** Drop the resume handle and notify the host (`onExecutionState(null)`). */
7059
+ private clearResumable;
7060
+ /**
7061
+ * Surface the resume handle to the host for persistence. Immediate on
7062
+ * create/clear; trailing-edge throttled on cursor advances so it isn't called
7063
+ * per delta.
7064
+ */
7065
+ private notifyExecutionState;
7066
+ /** The current durable resume handle, if any (read-only). */
7067
+ getResumableHandle(): ResumableHandle | null;
6838
7068
  private setStatus;
6839
7069
  private setStreaming;
6840
7070
  /**
@@ -7013,6 +7243,11 @@ type Controller = {
7013
7243
  clearChat: () => void;
7014
7244
  setMessage: (message: string) => boolean;
7015
7245
  submitMessage: (message?: string) => boolean;
7246
+ /**
7247
+ * Manually retry a dropped durable stream (e.g. from a "Reconnect" button).
7248
+ * No-op unless a resumable durable turn dropped and `reconnectStream` is set.
7249
+ */
7250
+ reconnect: () => void;
7016
7251
  startVoiceRecognition: () => boolean;
7017
7252
  stopVoiceRecognition: () => boolean;
7018
7253
  /**