@runtypelabs/persona 4.19.0 → 4.21.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 (77) 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-CG-bLFmk.d.cts → types-B_JdVK9o.d.cts} +2 -0
  4. package/dist/animations/{types-CG-bLFmk.d.ts → types-B_JdVK9o.d.ts} +2 -0
  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 +2 -0
  8. package/dist/animations-extra.d.ts +2 -0
  9. package/dist/approval-ui.d.cts +99 -5
  10. package/dist/approval-ui.d.ts +99 -5
  11. package/dist/artifacts-ui.d.cts +99 -5
  12. package/dist/artifacts-ui.d.ts +99 -5
  13. package/dist/codegen.cjs +1 -1
  14. package/dist/codegen.js +1 -1
  15. package/dist/context-mentions.d.cts +99 -5
  16. package/dist/context-mentions.d.ts +99 -5
  17. package/dist/event-stream-view.d.cts +99 -5
  18. package/dist/event-stream-view.d.ts +99 -5
  19. package/dist/forms-ui.d.cts +123 -9
  20. package/dist/forms-ui.d.ts +123 -9
  21. package/dist/history-view.d.cts +2 -0
  22. package/dist/history-view.d.ts +2 -0
  23. package/dist/index.cjs +51 -51
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +128 -10
  26. package/dist/index.d.ts +128 -10
  27. package/dist/index.global.js +34 -34
  28. package/dist/index.global.js.map +1 -1
  29. package/dist/index.js +51 -51
  30. package/dist/index.js.map +1 -1
  31. package/dist/launcher.global.js.map +1 -1
  32. package/dist/session-reconnect.d.cts +99 -5
  33. package/dist/session-reconnect.d.ts +99 -5
  34. package/dist/smart-dom-reader.d.cts +99 -5
  35. package/dist/smart-dom-reader.d.ts +99 -5
  36. package/dist/theme-editor-preview.cjs +53 -53
  37. package/dist/theme-editor-preview.d.cts +99 -5
  38. package/dist/theme-editor-preview.d.ts +99 -5
  39. package/dist/theme-editor-preview.js +31 -31
  40. package/dist/theme-editor.d.cts +99 -5
  41. package/dist/theme-editor.d.ts +99 -5
  42. package/dist/theme-reference.cjs +1 -1
  43. package/dist/theme-reference.d.cts +46 -5
  44. package/dist/theme-reference.d.ts +46 -5
  45. package/dist/theme-reference.js +1 -1
  46. package/dist/webmcp-runtime.d.cts +16 -0
  47. package/dist/webmcp-runtime.d.ts +16 -0
  48. package/dist/widget.css +1 -1
  49. package/package.json +1 -1
  50. package/src/client-visitor-history.test.ts +342 -3
  51. package/src/client.test.ts +141 -3
  52. package/src/client.ts +157 -39
  53. package/src/components/composer-actions.ts +27 -1
  54. package/src/components/composer-model-picker.ts +4 -14
  55. package/src/components/composer-overflow-menu.ts +14 -0
  56. package/src/components/composer-parts.ts +20 -0
  57. package/src/generated/runtype-openapi-contract.ts +2 -0
  58. package/src/index-core.ts +2 -0
  59. package/src/session.ts +139 -103
  60. package/src/session.webmcp.test.ts +48 -1
  61. package/src/styles/widget-styles.test.ts +83 -1
  62. package/src/styles/widget.css +50 -14
  63. package/src/theme-reference.ts +1 -1
  64. package/src/types/theme.ts +47 -5
  65. package/src/types.ts +63 -0
  66. package/src/ui.composer-action-visibility.test.ts +202 -0
  67. package/src/ui.composer-models.test.ts +37 -0
  68. package/src/ui.composer-modes.test.ts +82 -0
  69. package/src/ui.composer-overflow.test.ts +78 -0
  70. package/src/ui.history-lifecycle.test.ts +2 -2
  71. package/src/ui.ts +77 -6
  72. package/src/utils/__snapshots__/tokens-parity.test.ts.snap +1633 -686
  73. package/src/utils/composer-modes.test.ts +33 -0
  74. package/src/utils/composer-modes.ts +19 -2
  75. package/src/utils/tokens-parity.test.ts +20 -0
  76. package/src/utils/tokens.test.ts +76 -0
  77. package/src/utils/tokens.ts +4 -4
package/src/ui.ts CHANGED
@@ -8370,6 +8370,22 @@ export const createAgentExperience = (
8370
8370
  const stored = persistentMetadata[key];
8371
8371
  return typeof stored === 'string' ? stored : null;
8372
8372
  };
8373
+ const readStoredResumableHandle = (): {
8374
+ executionId: string;
8375
+ after: string;
8376
+ } | null => {
8377
+ const stored = persistentMetadata.durableResume;
8378
+ if (!stored || typeof stored !== 'object') return null;
8379
+ const candidate = stored as Record<string, unknown>;
8380
+ return typeof candidate.executionId === 'string' &&
8381
+ candidate.executionId.length > 0 &&
8382
+ typeof candidate.after === 'string' &&
8383
+ candidate.after.length > 0
8384
+ ? { executionId: candidate.executionId, after: candidate.after }
8385
+ : null;
8386
+ };
8387
+ const personaOwnsClientTokenRecovery =
8388
+ Boolean(config.clientToken) && typeof config.reconnectStream !== "function";
8373
8389
  if (config.clientToken) {
8374
8390
  config = {
8375
8391
  ...config,
@@ -8394,11 +8410,11 @@ export const createAgentExperience = (
8394
8410
  };
8395
8411
  }
8396
8412
 
8397
- // Visitor-history credential store, keyed on (clientToken, keyPrefix,
8398
- // persistence-disabled). Owned here and injected into every client the
8399
- // session builds; `update()` rebuilds it when that tuple changes.
8413
+ // Exact-browser visitor credential store, keyed on (clientToken, keyPrefix,
8414
+ // persistence-disabled). Durable reconnect and optional visitor history use
8415
+ // the same credential but negotiate independent server capabilities.
8400
8416
  const historyStoreToken = (): string | null =>
8401
- config.features?.history?.enabled === true ? (config.clientToken ?? null) : null;
8417
+ config.clientToken ?? null;
8402
8418
  const buildVisitorStore = (token: string) =>
8403
8419
  createVisitorStore(token, currentKeyPrefix(), config.persistState === false);
8404
8420
  const initialStoreToken = historyStoreToken();
@@ -8446,6 +8462,16 @@ export const createAgentExperience = (
8446
8462
  pendingDisplayProjections: pending,
8447
8463
  }));
8448
8464
  },
8465
+ getStoredResumableHandle: readStoredResumableHandle,
8466
+ setStoredResumableHandle: (handle) => {
8467
+ if (!handle) {
8468
+ dropMetadataKey('durableResume');
8469
+ return;
8470
+ }
8471
+ updateSessionMetadata((prev) => ({ ...prev, durableResume: handle }));
8472
+ },
8473
+ shouldResumeDurableConversation: () =>
8474
+ personaOwnsClientTokenRecovery && readStoredResumableHandle() !== null,
8449
8475
  ...(hostOwnsConversationId
8450
8476
  ? {}
8451
8477
  : {
@@ -8463,6 +8489,46 @@ export const createAgentExperience = (
8463
8489
  },
8464
8490
  }),
8465
8491
  };
8492
+
8493
+ // Runtype client-token widgets already possess the session, conversation,
8494
+ // and exact-browser visitor credential needed by the public reconnect route.
8495
+ // Install Persona's existing reconnect hooks by default so this mode follows
8496
+ // the same path as host-configured durable dashboard chats.
8497
+ if (personaOwnsClientTokenRecovery) {
8498
+ const hostExecutionState = config.onExecutionState;
8499
+ const recoveryWindow = mount.ownerDocument.defaultView;
8500
+ let pageExitInProgress = false;
8501
+ const markPageExit = () => {
8502
+ pageExitInProgress = true;
8503
+ };
8504
+ const markPageActive = () => {
8505
+ pageExitInProgress = false;
8506
+ };
8507
+ recoveryWindow?.addEventListener("beforeunload", markPageExit);
8508
+ recoveryWindow?.addEventListener("pagehide", markPageExit);
8509
+ recoveryWindow?.addEventListener("pageshow", markPageActive);
8510
+ destroyCallbacks.push(() => {
8511
+ recoveryWindow?.removeEventListener("beforeunload", markPageExit);
8512
+ recoveryWindow?.removeEventListener("pagehide", markPageExit);
8513
+ recoveryWindow?.removeEventListener("pageshow", markPageActive);
8514
+ });
8515
+ config = {
8516
+ ...config,
8517
+ reconnectStream:
8518
+ config.reconnectStream ??
8519
+ ((ctx) => session.getClient().reconnectClientTokenStream(ctx)),
8520
+ onExecutionState: (handle) => {
8521
+ if (handle || !pageExitInProgress) {
8522
+ historyInternals.setStoredResumableHandle?.(
8523
+ handle
8524
+ ? { executionId: handle.executionId, after: handle.lastEventId }
8525
+ : null
8526
+ );
8527
+ }
8528
+ hostExecutionState?.(handle);
8529
+ },
8530
+ };
8531
+ }
8466
8532
  const syncVisitorStore = () => {
8467
8533
  const token = historyStoreToken();
8468
8534
  if (
@@ -11297,8 +11363,13 @@ export const createAgentExperience = (
11297
11363
  // the restored conversation. Fires AFTER hydration so the trailing partial
11298
11364
  // assistant bubble exists for the replay to append to.
11299
11365
  const maybeBootResume = () => {
11300
- if (config.resume && typeof config.reconnectStream === "function") {
11301
- session.resumeFromHandle(config.resume);
11366
+ const resume =
11367
+ config.resume ??
11368
+ (personaOwnsClientTokenRecovery
11369
+ ? historyInternals.getStoredResumableHandle?.()
11370
+ : null);
11371
+ if (resume && typeof config.reconnectStream === "function") {
11372
+ session.resumeFromHandle(resume);
11302
11373
  }
11303
11374
  };
11304
11375