@runtypelabs/persona 4.6.1 → 4.8.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 (120) hide show
  1. package/dist/animations/glyph-cycle.cjs +2 -2
  2. package/dist/animations/glyph-cycle.d.cts +1 -1
  3. package/dist/animations/glyph-cycle.d.ts +1 -1
  4. package/dist/animations/glyph-cycle.js +2 -2
  5. package/dist/animations/{types-CSmiKRVa.d.cts → types-BsZtXPKK.d.cts} +43 -3
  6. package/dist/animations/{types-CSmiKRVa.d.ts → types-BsZtXPKK.d.ts} +43 -3
  7. package/dist/animations/wipe.cjs +2 -2
  8. package/dist/animations/wipe.d.cts +1 -1
  9. package/dist/animations/wipe.d.ts +1 -1
  10. package/dist/chunk-5EIIHQLQ.js +1 -0
  11. package/dist/codegen.cjs +12 -12
  12. package/dist/codegen.js +14 -14
  13. package/dist/index.cjs +91 -68
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +918 -174
  16. package/dist/index.d.ts +918 -174
  17. package/dist/index.global.js +81 -57
  18. package/dist/index.global.js.map +1 -1
  19. package/dist/index.js +89 -66
  20. package/dist/index.js.map +1 -1
  21. package/dist/install.global.js +1 -1
  22. package/dist/install.global.js.map +1 -1
  23. package/dist/launcher.global.js +3 -2
  24. package/dist/launcher.global.js.map +1 -1
  25. package/dist/markdown-parsers.js +24 -24
  26. package/dist/plugin-kit.cjs +1 -1
  27. package/dist/plugin-kit.js +1 -1
  28. package/dist/runtype-tts-entry-UJAEF7NZ.js +1 -0
  29. package/dist/runtype-tts.js +1 -1
  30. package/dist/session-reconnect-JKIJBHS5.js +1 -0
  31. package/dist/smart-dom-reader.cjs +17 -17
  32. package/dist/smart-dom-reader.d.cts +753 -15
  33. package/dist/smart-dom-reader.d.ts +753 -15
  34. package/dist/smart-dom-reader.js +17 -17
  35. package/dist/testing.cjs +3 -3
  36. package/dist/testing.js +3 -3
  37. package/dist/theme-editor-preview.cjs +81 -58
  38. package/dist/theme-editor-preview.d.cts +761 -15
  39. package/dist/theme-editor-preview.d.ts +761 -15
  40. package/dist/theme-editor-preview.js +81 -58
  41. package/dist/theme-editor.cjs +6 -6
  42. package/dist/theme-editor.d.cts +753 -15
  43. package/dist/theme-editor.d.ts +753 -15
  44. package/dist/theme-editor.js +10 -10
  45. package/dist/theme-reference.cjs +1 -1
  46. package/dist/theme-reference.d.cts +74 -0
  47. package/dist/theme-reference.d.ts +74 -0
  48. package/dist/theme-reference.js +1 -1
  49. package/dist/voice-worklet-player.cjs +2 -2
  50. package/dist/voice-worklet-player.js +2 -2
  51. package/dist/webmcp-polyfill.js +2 -2
  52. package/dist/widget.css +1 -1
  53. package/package.json +2 -3
  54. package/src/artifacts-session.test.ts +178 -0
  55. package/src/client.test.ts +500 -1
  56. package/src/client.ts +285 -93
  57. package/src/components/artifact-card.test.ts +333 -0
  58. package/src/components/artifact-card.ts +75 -28
  59. package/src/components/artifact-inline.test.ts +1328 -0
  60. package/src/components/artifact-inline.ts +920 -0
  61. package/src/components/artifact-pane.test.ts +1042 -0
  62. package/src/components/artifact-pane.ts +440 -131
  63. package/src/components/artifact-preview.test.ts +1155 -0
  64. package/src/components/artifact-preview.ts +994 -0
  65. package/src/components/pill-composer-builder.test.ts +6 -2
  66. package/src/components/pill-composer-builder.ts +6 -6
  67. package/src/components/reasoning-bubble.ts +1 -13
  68. package/src/components/registry.ts +38 -3
  69. package/src/components/tool-bubble.ts +1 -13
  70. package/src/defaults.ts +1 -0
  71. package/src/generated/runtype-openapi-contract.ts +55 -3
  72. package/src/index-core.ts +20 -1
  73. package/src/index.ts +8 -0
  74. package/src/markdown-parsers-loader.test.ts +158 -0
  75. package/src/markdown-parsers-loader.ts +74 -9
  76. package/src/runtime/host-layout.test.ts +163 -0
  77. package/src/runtime/host-layout.ts +110 -7
  78. package/src/runtime/init.ts +18 -61
  79. package/src/runtime/persist-state.test.ts +118 -0
  80. package/src/session.ts +76 -22
  81. package/src/styles/widget.css +773 -26
  82. package/src/theme-editor/preview.ts +2 -0
  83. package/src/theme-editor/sections.test.ts +26 -1
  84. package/src/theme-editor/sections.ts +10 -2
  85. package/src/theme-reference.ts +2 -2
  86. package/src/tool-call-display-defaults.test.ts +1 -0
  87. package/src/types/theme.ts +77 -0
  88. package/src/types.ts +516 -17
  89. package/src/ui.artifact-pane-gating.test.ts +636 -0
  90. package/src/ui.component-directive.test.ts +104 -0
  91. package/src/ui.composer-bar.test.ts +60 -2
  92. package/src/ui.detached-panel.test.ts +1049 -0
  93. package/src/ui.scroll-additive.test.ts +1 -1
  94. package/src/ui.streaming-coalescing.test.ts +312 -0
  95. package/src/ui.tool-display.test.ts +51 -0
  96. package/src/ui.ts +933 -214
  97. package/src/utils/artifact-custom-actions.ts +128 -0
  98. package/src/utils/artifact-display.test.ts +42 -0
  99. package/src/utils/artifact-display.ts +84 -0
  100. package/src/utils/artifact-file.test.ts +116 -0
  101. package/src/utils/artifact-file.ts +117 -0
  102. package/src/utils/artifact-gate.test.ts +112 -5
  103. package/src/utils/artifact-gate.ts +39 -14
  104. package/src/utils/artifact-loading-status.ts +55 -0
  105. package/src/utils/artifact-status-label.ts +190 -0
  106. package/src/utils/buttons.ts +7 -1
  107. package/src/utils/code-highlight.test.ts +186 -0
  108. package/src/utils/code-highlight.ts +400 -0
  109. package/src/utils/icons.ts +2 -0
  110. package/src/utils/roving-tablist.test.ts +152 -0
  111. package/src/utils/roving-tablist.ts +111 -0
  112. package/src/utils/spinner.ts +45 -0
  113. package/src/utils/theme.test.ts +48 -0
  114. package/src/utils/theme.ts +7 -0
  115. package/src/utils/tokens.ts +91 -0
  116. package/src/utils/tool-loading-animation.test.ts +32 -0
  117. package/src/utils/tool-loading-animation.ts +24 -0
  118. package/dist/chunk-DFBSCFYN.js +0 -1
  119. package/dist/runtype-tts-entry-HFUV2UF7.js +0 -1
  120. package/dist/session-reconnect-U77QFUR7.js +0 -1
package/src/session.ts CHANGED
@@ -28,6 +28,10 @@ import {
28
28
  generateAssistantMessageId
29
29
  } from "./utils/message-id";
30
30
  import { IMAGE_ONLY_MESSAGE_FALLBACK_TEXT } from "./utils/content";
31
+ import {
32
+ buildArtifactRefRawContent,
33
+ resolveArtifactDisplayMode
34
+ } from "./utils/artifact-display";
31
35
  import type {
32
36
  VoiceProvider,
33
37
  VoiceStatus,
@@ -2607,33 +2611,82 @@ export class AgentWidgetSession {
2607
2611
  const id =
2608
2612
  manual.id ||
2609
2613
  `art_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 9)}`;
2610
- if (manual.artifactType === "markdown") {
2611
- const rec: PersonaArtifactRecord = {
2612
- id,
2613
- artifactType: "markdown",
2614
- title: manual.title,
2615
- status: "complete",
2616
- markdown: manual.content
2617
- };
2618
- this.artifacts.set(id, rec);
2619
- this.selectedArtifactId = id;
2620
- this.emitArtifactsState();
2621
- return rec;
2622
- }
2623
- const rec: PersonaArtifactRecord = {
2624
- id,
2625
- artifactType: "component",
2626
- title: manual.title,
2627
- status: "complete",
2628
- component: manual.component,
2629
- props: manual.props ?? {}
2630
- };
2614
+ const rec: PersonaArtifactRecord =
2615
+ manual.artifactType === "markdown"
2616
+ ? {
2617
+ id,
2618
+ artifactType: "markdown",
2619
+ title: manual.title,
2620
+ status: "complete",
2621
+ markdown: manual.content,
2622
+ ...(manual.file ? { file: manual.file } : {})
2623
+ }
2624
+ : {
2625
+ id,
2626
+ artifactType: "component",
2627
+ title: manual.title,
2628
+ status: "complete",
2629
+ component: manual.component,
2630
+ props: manual.props ?? {}
2631
+ };
2631
2632
  this.artifacts.set(id, rec);
2632
2633
  this.selectedArtifactId = id;
2633
2634
  this.emitArtifactsState();
2635
+ if (manual.transcript !== false) {
2636
+ this.injectArtifactRefBlock(rec);
2637
+ }
2634
2638
  return rec;
2635
2639
  }
2636
2640
 
2641
+ /**
2642
+ * Injects (or refreshes) the in-thread artifact block for a programmatically
2643
+ * upserted artifact, matching the streamed UX: the resolved display mode
2644
+ * picks the component ("card"/"panel" → reference card, "inline" → inline
2645
+ * preview).
2646
+ *
2647
+ * Unlike the streamed path (which embeds content on `artifact_complete`),
2648
+ * the programmatic record is complete up front, so the final markdown /
2649
+ * file meta / component name + props are embedded immediately and the block
2650
+ * hydrates after a refresh without the original registry state.
2651
+ *
2652
+ * A re-upsert of the same id rebuilds the existing block's persisted
2653
+ * rawContent in place (the registry is not persisted, so hydration reads
2654
+ * these props); without this the block would keep the first version's
2655
+ * content after a refresh.
2656
+ */
2657
+ private injectArtifactRefBlock(rec: PersonaArtifactRecord): void {
2658
+ const refId = `artifact-ref-${rec.id}`;
2659
+ const displayMode = resolveArtifactDisplayMode(
2660
+ this.config.features?.artifacts,
2661
+ rec.artifactType
2662
+ );
2663
+ const rawContent = buildArtifactRefRawContent(displayMode, {
2664
+ artifactId: rec.id,
2665
+ title: rec.title,
2666
+ artifactType: rec.artifactType,
2667
+ status: "complete",
2668
+ ...(rec.file ? { file: rec.file } : {}),
2669
+ ...(rec.component ? { component: rec.component } : {}),
2670
+ ...(rec.props ? { componentProps: rec.props } : {}),
2671
+ ...(rec.markdown !== undefined ? { markdown: rec.markdown } : {})
2672
+ });
2673
+ // Re-upsert: mutate the STORED message (inject stores a copy via
2674
+ // ensureSequence, so a local copy would be lost) and notify so the
2675
+ // transcript re-renders and persistence picks up the new version.
2676
+ const existing = this.messages.find((m) => m.id === refId);
2677
+ if (existing) {
2678
+ existing.rawContent = rawContent;
2679
+ existing.streaming = false;
2680
+ this.callbacks.onMessagesChanged([...this.messages]);
2681
+ return;
2682
+ }
2683
+ this.injectAssistantMessage({
2684
+ id: refId,
2685
+ content: "",
2686
+ rawContent
2687
+ });
2688
+ }
2689
+
2637
2690
  private clearArtifactState(): void {
2638
2691
  if (this.artifacts.size === 0 && this.selectedArtifactId === null) return;
2639
2692
  this.artifacts.clear();
@@ -2657,7 +2710,8 @@ export class AgentWidgetSession {
2657
2710
  artifactType: "markdown",
2658
2711
  title: ev.title,
2659
2712
  status: "streaming",
2660
- markdown: ""
2713
+ markdown: "",
2714
+ ...(ev.file ? { file: ev.file } : {})
2661
2715
  });
2662
2716
  } else {
2663
2717
  this.artifacts.set(ev.id, {