@runtypelabs/persona 4.2.1 → 4.3.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 (45) hide show
  1. package/README.md +22 -6
  2. package/dist/animations/glyph-cycle.d.cts +1 -1
  3. package/dist/animations/glyph-cycle.d.ts +1 -1
  4. package/dist/animations/{types-B_xbfvR0.d.cts → types-C6tFDxKy.d.cts} +1 -1
  5. package/dist/animations/{types-B_xbfvR0.d.ts → types-C6tFDxKy.d.ts} +1 -1
  6. package/dist/animations/wipe.d.cts +1 -1
  7. package/dist/animations/wipe.d.ts +1 -1
  8. package/dist/codegen.cjs +6 -6
  9. package/dist/codegen.js +9 -9
  10. package/dist/index.cjs +32 -32
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +101 -3
  13. package/dist/index.d.ts +101 -3
  14. package/dist/index.global.js +23 -23
  15. package/dist/index.global.js.map +1 -1
  16. package/dist/index.js +32 -32
  17. package/dist/index.js.map +1 -1
  18. package/dist/install.global.js +1 -1
  19. package/dist/install.global.js.map +1 -1
  20. package/dist/launcher.global.js.map +1 -1
  21. package/dist/smart-dom-reader.d.cts +76 -1
  22. package/dist/smart-dom-reader.d.ts +76 -1
  23. package/dist/theme-editor-preview.cjs +27 -27
  24. package/dist/theme-editor-preview.d.cts +76 -1
  25. package/dist/theme-editor-preview.d.ts +76 -1
  26. package/dist/theme-editor-preview.js +29 -29
  27. package/dist/theme-editor.cjs +1 -1
  28. package/dist/theme-editor.d.cts +76 -1
  29. package/dist/theme-editor.d.ts +76 -1
  30. package/dist/theme-editor.js +1 -1
  31. package/dist/widget.css +3 -0
  32. package/package.json +1 -1
  33. package/src/client.test.ts +221 -29
  34. package/src/client.ts +71 -24
  35. package/src/defaults.ts +2 -0
  36. package/src/index-core.ts +2 -0
  37. package/src/install.ts +9 -1
  38. package/src/session.ts +6 -3
  39. package/src/session.voice.test.ts +65 -0
  40. package/src/styles/widget.css +3 -0
  41. package/src/types.ts +57 -2
  42. package/src/utils/__fixtures__/unified-translator.oracle.ts +3 -3
  43. package/src/utils/code-generators.ts +10 -0
  44. package/src/utils/target.test.ts +51 -0
  45. package/src/utils/target.ts +90 -0
@@ -1654,6 +1654,32 @@ type RuntypeTurnCompleteEvent = RuntypeStreamEventOf<RuntypeExecutionStreamEvent
1654
1654
  type RuntypeStepCompleteEvent = RuntypeStreamEventOf<RuntypeFlowSSEEvent, "step_complete">;
1655
1655
  type RuntypeStopReasonKind = NonNullable<RuntypeTurnCompleteEvent["stopReason"] | RuntypeStepCompleteEvent["stopReason"]>;
1656
1656
 
1657
+ /**
1658
+ * Target resolution for the normalized, backend-neutral `target` field.
1659
+ *
1660
+ * `target` is a single string that selects which backend resource a widget
1661
+ * talks to, optimized for a browser widget (always serializable, no live
1662
+ * objects). Three shapes are supported:
1663
+ *
1664
+ * - Runtype TypeID (no prefix): `"agent_…"` / `"flow_…"` route to the
1665
+ * Runtype agent/flow paths. The TypeID prefix is self-describing, so no
1666
+ * wrapper is needed for the common case.
1667
+ * - Provider-prefixed: `"<provider>:<id>"` is handed to the matching
1668
+ * `targetProviders[provider]` resolver, which returns the dispatch payload
1669
+ * fragment for that backend (e.g. `eve`, `langgraph`). `"runtype:…"` is a
1670
+ * built-in that re-detects a TypeID.
1671
+ * - Bare name: `"support"` requires a `targetProviders.default` resolver,
1672
+ * otherwise it throws (a bare name is ambiguous without one).
1673
+ *
1674
+ * Resolvers are registered, not passed as the value, which keeps `target`
1675
+ * itself a plain string that survives script-tag installs, `data-config`,
1676
+ * persisted state, and codegen.
1677
+ */
1678
+ /** Resolver for a provider-prefixed (or default) target id. */
1679
+ type TargetResolver = (id: string) => {
1680
+ payload: Record<string, unknown>;
1681
+ };
1682
+
1657
1683
  /**
1658
1684
  * Text content part for multi-modal messages
1659
1685
  */
@@ -1720,6 +1746,9 @@ type AgentWidgetRequestPayloadMessage = {
1720
1746
  type AgentWidgetRequestPayload = {
1721
1747
  messages: AgentWidgetRequestPayloadMessage[];
1722
1748
  flowId?: string;
1749
+ agent?: {
1750
+ agentId: string;
1751
+ };
1723
1752
  context?: Record<string, unknown>;
1724
1753
  metadata?: Record<string, unknown>;
1725
1754
  /** Per-turn template variables for /v1/client/chat (merged as root-level {{var}} in Runtype). */
@@ -4751,6 +4780,52 @@ type AgentWidgetLoadingIndicatorConfig = {
4751
4780
  type AgentWidgetConfig = {
4752
4781
  apiUrl?: string;
4753
4782
  flowId?: string;
4783
+ /**
4784
+ * Persisted Runtype agent ID to execute.
4785
+ *
4786
+ * This is the primary Runtype entry point for simple agent-backed widgets.
4787
+ * It is mutually exclusive with `flowId` and with inline `agent` configs.
4788
+ * Voice and Runtype TTS providers inherit this value unless they specify their
4789
+ * own feature-scoped agent ID.
4790
+ */
4791
+ agentId?: string;
4792
+ /**
4793
+ * Normalized, backend-neutral routing target. A single string that selects
4794
+ * the backend resource to talk to, optimized for portability across
4795
+ * frameworks (it is always serializable: no live objects).
4796
+ *
4797
+ * Shapes:
4798
+ * - Runtype TypeID (no prefix): `"agent_…"` / `"flow_…"` route to the
4799
+ * Runtype agent/flow paths (the prefix is self-describing).
4800
+ * - Provider-prefixed: `"<provider>:<id>"` is resolved by
4801
+ * `targetProviders[provider]` (e.g. `"eve:support"`). `"runtype:…"` is a
4802
+ * built-in that re-detects a TypeID.
4803
+ * - Bare name: `"support"` requires a `targetProviders.default` resolver.
4804
+ *
4805
+ * Mutually exclusive with `agentId`, `flowId`, and inline `agent`. Prefer
4806
+ * `target` for backend-agnostic apps; use `agentId`/`flowId` for the explicit
4807
+ * Runtype path.
4808
+ *
4809
+ * @example
4810
+ * ```typescript
4811
+ * config: { target: "agent_01k..." } // Runtype agent
4812
+ * config: { target: "flow_01k..." } // Runtype flow
4813
+ * config: { // custom backend
4814
+ * apiUrl: "/api/chat",
4815
+ * target: "eve:support",
4816
+ * targetProviders: { eve: (id) => ({ payload: { assistant: id } }) },
4817
+ * }
4818
+ * ```
4819
+ */
4820
+ target?: string;
4821
+ /**
4822
+ * Prefix-keyed resolvers for `target` strings of the form
4823
+ * `"<provider>:<id>"`. Each resolver maps the id to the dispatch-payload
4824
+ * fragment its backend expects. Register a `default` resolver to also accept
4825
+ * bare (unprefixed, non-TypeID) target names. The built-in `runtype` provider
4826
+ * is always available and does not need to be registered.
4827
+ */
4828
+ targetProviders?: Record<string, TargetResolver>;
4754
4829
  /**
4755
4830
  * Override the assistant-bubble copy shown when a dispatch fails before any
4756
4831
  * response streams back (connection refused, CORS, 4xx/5xx, malformed
@@ -5436,7 +5511,7 @@ type AgentWidgetReasoning = {
5436
5511
  status: "pending" | "streaming" | "complete";
5437
5512
  chunks: string[];
5438
5513
  /**
5439
- * Reasoning channel scope (unified spec). `"turn"` is ordinary per-turn
5514
+ * Reasoning channel scope (wire spec). `"turn"` is ordinary per-turn
5440
5515
  * thinking; `"loop"` is a cross-iteration agent reflection (the fold that
5441
5516
  * replaced the legacy `agent_reflection` event). Absent for legacy streams.
5442
5517
  */
@@ -1654,6 +1654,32 @@ type RuntypeTurnCompleteEvent = RuntypeStreamEventOf<RuntypeExecutionStreamEvent
1654
1654
  type RuntypeStepCompleteEvent = RuntypeStreamEventOf<RuntypeFlowSSEEvent, "step_complete">;
1655
1655
  type RuntypeStopReasonKind = NonNullable<RuntypeTurnCompleteEvent["stopReason"] | RuntypeStepCompleteEvent["stopReason"]>;
1656
1656
 
1657
+ /**
1658
+ * Target resolution for the normalized, backend-neutral `target` field.
1659
+ *
1660
+ * `target` is a single string that selects which backend resource a widget
1661
+ * talks to, optimized for a browser widget (always serializable, no live
1662
+ * objects). Three shapes are supported:
1663
+ *
1664
+ * - Runtype TypeID (no prefix): `"agent_…"` / `"flow_…"` route to the
1665
+ * Runtype agent/flow paths. The TypeID prefix is self-describing, so no
1666
+ * wrapper is needed for the common case.
1667
+ * - Provider-prefixed: `"<provider>:<id>"` is handed to the matching
1668
+ * `targetProviders[provider]` resolver, which returns the dispatch payload
1669
+ * fragment for that backend (e.g. `eve`, `langgraph`). `"runtype:…"` is a
1670
+ * built-in that re-detects a TypeID.
1671
+ * - Bare name: `"support"` requires a `targetProviders.default` resolver,
1672
+ * otherwise it throws (a bare name is ambiguous without one).
1673
+ *
1674
+ * Resolvers are registered, not passed as the value, which keeps `target`
1675
+ * itself a plain string that survives script-tag installs, `data-config`,
1676
+ * persisted state, and codegen.
1677
+ */
1678
+ /** Resolver for a provider-prefixed (or default) target id. */
1679
+ type TargetResolver = (id: string) => {
1680
+ payload: Record<string, unknown>;
1681
+ };
1682
+
1657
1683
  /**
1658
1684
  * Text content part for multi-modal messages
1659
1685
  */
@@ -1720,6 +1746,9 @@ type AgentWidgetRequestPayloadMessage = {
1720
1746
  type AgentWidgetRequestPayload = {
1721
1747
  messages: AgentWidgetRequestPayloadMessage[];
1722
1748
  flowId?: string;
1749
+ agent?: {
1750
+ agentId: string;
1751
+ };
1723
1752
  context?: Record<string, unknown>;
1724
1753
  metadata?: Record<string, unknown>;
1725
1754
  /** Per-turn template variables for /v1/client/chat (merged as root-level {{var}} in Runtype). */
@@ -4751,6 +4780,52 @@ type AgentWidgetLoadingIndicatorConfig = {
4751
4780
  type AgentWidgetConfig = {
4752
4781
  apiUrl?: string;
4753
4782
  flowId?: string;
4783
+ /**
4784
+ * Persisted Runtype agent ID to execute.
4785
+ *
4786
+ * This is the primary Runtype entry point for simple agent-backed widgets.
4787
+ * It is mutually exclusive with `flowId` and with inline `agent` configs.
4788
+ * Voice and Runtype TTS providers inherit this value unless they specify their
4789
+ * own feature-scoped agent ID.
4790
+ */
4791
+ agentId?: string;
4792
+ /**
4793
+ * Normalized, backend-neutral routing target. A single string that selects
4794
+ * the backend resource to talk to, optimized for portability across
4795
+ * frameworks (it is always serializable: no live objects).
4796
+ *
4797
+ * Shapes:
4798
+ * - Runtype TypeID (no prefix): `"agent_…"` / `"flow_…"` route to the
4799
+ * Runtype agent/flow paths (the prefix is self-describing).
4800
+ * - Provider-prefixed: `"<provider>:<id>"` is resolved by
4801
+ * `targetProviders[provider]` (e.g. `"eve:support"`). `"runtype:…"` is a
4802
+ * built-in that re-detects a TypeID.
4803
+ * - Bare name: `"support"` requires a `targetProviders.default` resolver.
4804
+ *
4805
+ * Mutually exclusive with `agentId`, `flowId`, and inline `agent`. Prefer
4806
+ * `target` for backend-agnostic apps; use `agentId`/`flowId` for the explicit
4807
+ * Runtype path.
4808
+ *
4809
+ * @example
4810
+ * ```typescript
4811
+ * config: { target: "agent_01k..." } // Runtype agent
4812
+ * config: { target: "flow_01k..." } // Runtype flow
4813
+ * config: { // custom backend
4814
+ * apiUrl: "/api/chat",
4815
+ * target: "eve:support",
4816
+ * targetProviders: { eve: (id) => ({ payload: { assistant: id } }) },
4817
+ * }
4818
+ * ```
4819
+ */
4820
+ target?: string;
4821
+ /**
4822
+ * Prefix-keyed resolvers for `target` strings of the form
4823
+ * `"<provider>:<id>"`. Each resolver maps the id to the dispatch-payload
4824
+ * fragment its backend expects. Register a `default` resolver to also accept
4825
+ * bare (unprefixed, non-TypeID) target names. The built-in `runtype` provider
4826
+ * is always available and does not need to be registered.
4827
+ */
4828
+ targetProviders?: Record<string, TargetResolver>;
4754
4829
  /**
4755
4830
  * Override the assistant-bubble copy shown when a dispatch fails before any
4756
4831
  * response streams back (connection refused, CORS, 4xx/5xx, malformed
@@ -5436,7 +5511,7 @@ type AgentWidgetReasoning = {
5436
5511
  status: "pending" | "streaming" | "complete";
5437
5512
  chunks: string[];
5438
5513
  /**
5439
- * Reasoning channel scope (unified spec). `"turn"` is ordinary per-turn
5514
+ * Reasoning channel scope (wire spec). `"turn"` is ordinary per-turn
5440
5515
  * thinking; `"loop"` is a cross-iteration agent reflection (the fold that
5441
5516
  * replaced the legacy `agent_reflection` event). Absent for legacy streams.
5442
5517
  */