@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
@@ -1385,6 +1385,32 @@ type RuntypeTurnCompleteEvent = RuntypeStreamEventOf<RuntypeExecutionStreamEvent
1385
1385
  type RuntypeStepCompleteEvent = RuntypeStreamEventOf<RuntypeFlowSSEEvent, "step_complete">;
1386
1386
  type RuntypeStopReasonKind = NonNullable<RuntypeTurnCompleteEvent["stopReason"] | RuntypeStepCompleteEvent["stopReason"]>;
1387
1387
 
1388
+ /**
1389
+ * Target resolution for the normalized, backend-neutral `target` field.
1390
+ *
1391
+ * `target` is a single string that selects which backend resource a widget
1392
+ * talks to, optimized for a browser widget (always serializable, no live
1393
+ * objects). Three shapes are supported:
1394
+ *
1395
+ * - Runtype TypeID (no prefix): `"agent_…"` / `"flow_…"` route to the
1396
+ * Runtype agent/flow paths. The TypeID prefix is self-describing, so no
1397
+ * wrapper is needed for the common case.
1398
+ * - Provider-prefixed: `"<provider>:<id>"` is handed to the matching
1399
+ * `targetProviders[provider]` resolver, which returns the dispatch payload
1400
+ * fragment for that backend (e.g. `eve`, `langgraph`). `"runtype:…"` is a
1401
+ * built-in that re-detects a TypeID.
1402
+ * - Bare name: `"support"` requires a `targetProviders.default` resolver,
1403
+ * otherwise it throws (a bare name is ambiguous without one).
1404
+ *
1405
+ * Resolvers are registered, not passed as the value, which keeps `target`
1406
+ * itself a plain string that survives script-tag installs, `data-config`,
1407
+ * persisted state, and codegen.
1408
+ */
1409
+ /** Resolver for a provider-prefixed (or default) target id. */
1410
+ type TargetResolver = (id: string) => {
1411
+ payload: Record<string, unknown>;
1412
+ };
1413
+
1388
1414
  /**
1389
1415
  * Text content part for multi-modal messages
1390
1416
  */
@@ -1451,6 +1477,9 @@ type AgentWidgetRequestPayloadMessage = {
1451
1477
  type AgentWidgetRequestPayload = {
1452
1478
  messages: AgentWidgetRequestPayloadMessage[];
1453
1479
  flowId?: string;
1480
+ agent?: {
1481
+ agentId: string;
1482
+ };
1454
1483
  context?: Record<string, unknown>;
1455
1484
  metadata?: Record<string, unknown>;
1456
1485
  /** Per-turn template variables for /v1/client/chat (merged as root-level {{var}} in Runtype). */
@@ -4565,6 +4594,52 @@ type AgentWidgetLoadingIndicatorConfig = {
4565
4594
  type AgentWidgetConfig = {
4566
4595
  apiUrl?: string;
4567
4596
  flowId?: string;
4597
+ /**
4598
+ * Persisted Runtype agent ID to execute.
4599
+ *
4600
+ * This is the primary Runtype entry point for simple agent-backed widgets.
4601
+ * It is mutually exclusive with `flowId` and with inline `agent` configs.
4602
+ * Voice and Runtype TTS providers inherit this value unless they specify their
4603
+ * own feature-scoped agent ID.
4604
+ */
4605
+ agentId?: string;
4606
+ /**
4607
+ * Normalized, backend-neutral routing target. A single string that selects
4608
+ * the backend resource to talk to, optimized for portability across
4609
+ * frameworks (it is always serializable: no live objects).
4610
+ *
4611
+ * Shapes:
4612
+ * - Runtype TypeID (no prefix): `"agent_…"` / `"flow_…"` route to the
4613
+ * Runtype agent/flow paths (the prefix is self-describing).
4614
+ * - Provider-prefixed: `"<provider>:<id>"` is resolved by
4615
+ * `targetProviders[provider]` (e.g. `"eve:support"`). `"runtype:…"` is a
4616
+ * built-in that re-detects a TypeID.
4617
+ * - Bare name: `"support"` requires a `targetProviders.default` resolver.
4618
+ *
4619
+ * Mutually exclusive with `agentId`, `flowId`, and inline `agent`. Prefer
4620
+ * `target` for backend-agnostic apps; use `agentId`/`flowId` for the explicit
4621
+ * Runtype path.
4622
+ *
4623
+ * @example
4624
+ * ```typescript
4625
+ * config: { target: "agent_01k..." } // Runtype agent
4626
+ * config: { target: "flow_01k..." } // Runtype flow
4627
+ * config: { // custom backend
4628
+ * apiUrl: "/api/chat",
4629
+ * target: "eve:support",
4630
+ * targetProviders: { eve: (id) => ({ payload: { assistant: id } }) },
4631
+ * }
4632
+ * ```
4633
+ */
4634
+ target?: string;
4635
+ /**
4636
+ * Prefix-keyed resolvers for `target` strings of the form
4637
+ * `"<provider>:<id>"`. Each resolver maps the id to the dispatch-payload
4638
+ * fragment its backend expects. Register a `default` resolver to also accept
4639
+ * bare (unprefixed, non-TypeID) target names. The built-in `runtype` provider
4640
+ * is always available and does not need to be registered.
4641
+ */
4642
+ targetProviders?: Record<string, TargetResolver>;
4568
4643
  /**
4569
4644
  * Override the assistant-bubble copy shown when a dispatch fails before any
4570
4645
  * response streams back (connection refused, CORS, 4xx/5xx, malformed
@@ -5250,7 +5325,7 @@ type AgentWidgetReasoning = {
5250
5325
  status: "pending" | "streaming" | "complete";
5251
5326
  chunks: string[];
5252
5327
  /**
5253
- * Reasoning channel scope (unified spec). `"turn"` is ordinary per-turn
5328
+ * Reasoning channel scope (wire spec). `"turn"` is ordinary per-turn
5254
5329
  * thinking; `"loop"` is a cross-iteration agent reflection (the fold that
5255
5330
  * replaced the legacy `agent_reflection` event). Absent for legacy streams.
5256
5331
  */
@@ -1385,6 +1385,32 @@ type RuntypeTurnCompleteEvent = RuntypeStreamEventOf<RuntypeExecutionStreamEvent
1385
1385
  type RuntypeStepCompleteEvent = RuntypeStreamEventOf<RuntypeFlowSSEEvent, "step_complete">;
1386
1386
  type RuntypeStopReasonKind = NonNullable<RuntypeTurnCompleteEvent["stopReason"] | RuntypeStepCompleteEvent["stopReason"]>;
1387
1387
 
1388
+ /**
1389
+ * Target resolution for the normalized, backend-neutral `target` field.
1390
+ *
1391
+ * `target` is a single string that selects which backend resource a widget
1392
+ * talks to, optimized for a browser widget (always serializable, no live
1393
+ * objects). Three shapes are supported:
1394
+ *
1395
+ * - Runtype TypeID (no prefix): `"agent_…"` / `"flow_…"` route to the
1396
+ * Runtype agent/flow paths. The TypeID prefix is self-describing, so no
1397
+ * wrapper is needed for the common case.
1398
+ * - Provider-prefixed: `"<provider>:<id>"` is handed to the matching
1399
+ * `targetProviders[provider]` resolver, which returns the dispatch payload
1400
+ * fragment for that backend (e.g. `eve`, `langgraph`). `"runtype:…"` is a
1401
+ * built-in that re-detects a TypeID.
1402
+ * - Bare name: `"support"` requires a `targetProviders.default` resolver,
1403
+ * otherwise it throws (a bare name is ambiguous without one).
1404
+ *
1405
+ * Resolvers are registered, not passed as the value, which keeps `target`
1406
+ * itself a plain string that survives script-tag installs, `data-config`,
1407
+ * persisted state, and codegen.
1408
+ */
1409
+ /** Resolver for a provider-prefixed (or default) target id. */
1410
+ type TargetResolver = (id: string) => {
1411
+ payload: Record<string, unknown>;
1412
+ };
1413
+
1388
1414
  /**
1389
1415
  * Text content part for multi-modal messages
1390
1416
  */
@@ -1451,6 +1477,9 @@ type AgentWidgetRequestPayloadMessage = {
1451
1477
  type AgentWidgetRequestPayload = {
1452
1478
  messages: AgentWidgetRequestPayloadMessage[];
1453
1479
  flowId?: string;
1480
+ agent?: {
1481
+ agentId: string;
1482
+ };
1454
1483
  context?: Record<string, unknown>;
1455
1484
  metadata?: Record<string, unknown>;
1456
1485
  /** Per-turn template variables for /v1/client/chat (merged as root-level {{var}} in Runtype). */
@@ -4565,6 +4594,52 @@ type AgentWidgetLoadingIndicatorConfig = {
4565
4594
  type AgentWidgetConfig = {
4566
4595
  apiUrl?: string;
4567
4596
  flowId?: string;
4597
+ /**
4598
+ * Persisted Runtype agent ID to execute.
4599
+ *
4600
+ * This is the primary Runtype entry point for simple agent-backed widgets.
4601
+ * It is mutually exclusive with `flowId` and with inline `agent` configs.
4602
+ * Voice and Runtype TTS providers inherit this value unless they specify their
4603
+ * own feature-scoped agent ID.
4604
+ */
4605
+ agentId?: string;
4606
+ /**
4607
+ * Normalized, backend-neutral routing target. A single string that selects
4608
+ * the backend resource to talk to, optimized for portability across
4609
+ * frameworks (it is always serializable: no live objects).
4610
+ *
4611
+ * Shapes:
4612
+ * - Runtype TypeID (no prefix): `"agent_…"` / `"flow_…"` route to the
4613
+ * Runtype agent/flow paths (the prefix is self-describing).
4614
+ * - Provider-prefixed: `"<provider>:<id>"` is resolved by
4615
+ * `targetProviders[provider]` (e.g. `"eve:support"`). `"runtype:…"` is a
4616
+ * built-in that re-detects a TypeID.
4617
+ * - Bare name: `"support"` requires a `targetProviders.default` resolver.
4618
+ *
4619
+ * Mutually exclusive with `agentId`, `flowId`, and inline `agent`. Prefer
4620
+ * `target` for backend-agnostic apps; use `agentId`/`flowId` for the explicit
4621
+ * Runtype path.
4622
+ *
4623
+ * @example
4624
+ * ```typescript
4625
+ * config: { target: "agent_01k..." } // Runtype agent
4626
+ * config: { target: "flow_01k..." } // Runtype flow
4627
+ * config: { // custom backend
4628
+ * apiUrl: "/api/chat",
4629
+ * target: "eve:support",
4630
+ * targetProviders: { eve: (id) => ({ payload: { assistant: id } }) },
4631
+ * }
4632
+ * ```
4633
+ */
4634
+ target?: string;
4635
+ /**
4636
+ * Prefix-keyed resolvers for `target` strings of the form
4637
+ * `"<provider>:<id>"`. Each resolver maps the id to the dispatch-payload
4638
+ * fragment its backend expects. Register a `default` resolver to also accept
4639
+ * bare (unprefixed, non-TypeID) target names. The built-in `runtype` provider
4640
+ * is always available and does not need to be registered.
4641
+ */
4642
+ targetProviders?: Record<string, TargetResolver>;
4568
4643
  /**
4569
4644
  * Override the assistant-bubble copy shown when a dispatch fails before any
4570
4645
  * response streams back (connection refused, CORS, 4xx/5xx, malformed
@@ -5250,7 +5325,7 @@ type AgentWidgetReasoning = {
5250
5325
  status: "pending" | "streaming" | "complete";
5251
5326
  chunks: string[];
5252
5327
  /**
5253
- * Reasoning channel scope (unified spec). `"turn"` is ordinary per-turn
5328
+ * Reasoning channel scope (wire spec). `"turn"` is ordinary per-turn
5254
5329
  * thinking; `"loop"` is a cross-iteration agent reflection (the fold that
5255
5330
  * replaced the legacy `agent_reflection` event). Absent for legacy streams.
5256
5331
  */