@convai/web-sdk 1.8.0 → 1.9.0-beta.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 (121) hide show
  1. package/README.md +213 -45
  2. package/dist/core/CharacterRoster.d.ts +84 -0
  3. package/dist/core/CharacterRoster.d.ts.map +1 -0
  4. package/dist/core/CharacterRoster.js +348 -0
  5. package/dist/core/CharacterRoster.js.map +1 -0
  6. package/dist/core/CharacterVersionManager.d.ts +100 -0
  7. package/dist/core/CharacterVersionManager.d.ts.map +1 -0
  8. package/dist/core/CharacterVersionManager.js +227 -0
  9. package/dist/core/CharacterVersionManager.js.map +1 -0
  10. package/dist/core/ConvaiClient.d.ts +190 -1
  11. package/dist/core/ConvaiClient.d.ts.map +1 -1
  12. package/dist/core/ConvaiClient.js +1328 -289
  13. package/dist/core/ConvaiClient.js.map +1 -1
  14. package/dist/core/ConvaiRoomError.d.ts +48 -0
  15. package/dist/core/ConvaiRoomError.d.ts.map +1 -0
  16. package/dist/core/ConvaiRoomError.js +111 -0
  17. package/dist/core/ConvaiRoomError.js.map +1 -0
  18. package/dist/core/MessageHandler.d.ts +26 -2
  19. package/dist/core/MessageHandler.d.ts.map +1 -1
  20. package/dist/core/MessageHandler.js +397 -32
  21. package/dist/core/MessageHandler.js.map +1 -1
  22. package/dist/core/SSESession.d.ts +74 -0
  23. package/dist/core/SSESession.d.ts.map +1 -0
  24. package/dist/core/SSESession.js +499 -0
  25. package/dist/core/SSESession.js.map +1 -0
  26. package/dist/core/characterReference.d.ts +40 -0
  27. package/dist/core/characterReference.d.ts.map +1 -0
  28. package/dist/core/characterReference.js +72 -0
  29. package/dist/core/characterReference.js.map +1 -0
  30. package/dist/core/connectRequest.d.ts +17 -4
  31. package/dist/core/connectRequest.d.ts.map +1 -1
  32. package/dist/core/connectRequest.js +28 -17
  33. package/dist/core/connectRequest.js.map +1 -1
  34. package/dist/core/index.d.ts +10 -1
  35. package/dist/core/index.d.ts.map +1 -1
  36. package/dist/core/index.js +14 -1
  37. package/dist/core/index.js.map +1 -1
  38. package/dist/core/logicalTurn.d.ts +4 -6
  39. package/dist/core/logicalTurn.d.ts.map +1 -1
  40. package/dist/core/logicalTurn.js +29 -4
  41. package/dist/core/logicalTurn.js.map +1 -1
  42. package/dist/core/modelOutput.d.ts.map +1 -1
  43. package/dist/core/modelOutput.js +2 -2
  44. package/dist/core/modelOutput.js.map +1 -1
  45. package/dist/core/rosterRequest.d.ts +57 -0
  46. package/dist/core/rosterRequest.d.ts.map +1 -0
  47. package/dist/core/rosterRequest.js +210 -0
  48. package/dist/core/rosterRequest.js.map +1 -0
  49. package/dist/core/types.d.ts +869 -22
  50. package/dist/core/types.d.ts.map +1 -1
  51. package/dist/core/types.js.map +1 -1
  52. package/dist/embed/ConvaiChatElement.d.ts +77 -1
  53. package/dist/embed/ConvaiChatElement.d.ts.map +1 -1
  54. package/dist/embed/ConvaiChatElement.js +433 -54
  55. package/dist/embed/ConvaiChatElement.js.map +1 -1
  56. package/dist/embed/chat-embed-v1.js +136 -35
  57. package/dist/embed/chat-embed-v1.js.map +4 -4
  58. package/dist/react/components/ConvaiWidget.d.ts.map +1 -1
  59. package/dist/react/components/ConvaiWidget.js +6 -1
  60. package/dist/react/components/ConvaiWidget.js.map +1 -1
  61. package/dist/react/components/rtc-widget/components/AudioVisualizer.d.ts.map +1 -1
  62. package/dist/react/components/rtc-widget/components/AudioVisualizer.js +28 -1
  63. package/dist/react/components/rtc-widget/components/AudioVisualizer.js.map +1 -1
  64. package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts +18 -0
  65. package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts.map +1 -1
  66. package/dist/react/components/rtc-widget/components/MarkdownRenderer.js +132 -63
  67. package/dist/react/components/rtc-widget/components/MarkdownRenderer.js.map +1 -1
  68. package/dist/react/components/rtc-widget/components/UserMessage.js +1 -1
  69. package/dist/react/components/rtc-widget/components/UserMessage.js.map +1 -1
  70. package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.d.ts.map +1 -1
  71. package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js +93 -49
  72. package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js.map +1 -1
  73. package/dist/react/hooks/useConvaiClient.d.ts.map +1 -1
  74. package/dist/react/hooks/useConvaiClient.js +17 -2
  75. package/dist/react/hooks/useConvaiClient.js.map +1 -1
  76. package/dist/react/index.d.ts +6 -1
  77. package/dist/react/index.d.ts.map +1 -1
  78. package/dist/react/index.js +9 -1
  79. package/dist/react/index.js.map +1 -1
  80. package/dist/utils/inlineMarkdown.d.ts +60 -0
  81. package/dist/utils/inlineMarkdown.d.ts.map +1 -0
  82. package/dist/utils/inlineMarkdown.js +183 -0
  83. package/dist/utils/inlineMarkdown.js.map +1 -0
  84. package/dist/utils/lightbox.d.ts +16 -0
  85. package/dist/utils/lightbox.d.ts.map +1 -0
  86. package/dist/utils/lightbox.js +95 -0
  87. package/dist/utils/lightbox.js.map +1 -0
  88. package/dist/utils/linkPresentation.d.ts +69 -0
  89. package/dist/utils/linkPresentation.d.ts.map +1 -0
  90. package/dist/utils/linkPresentation.js +358 -0
  91. package/dist/utils/linkPresentation.js.map +1 -0
  92. package/dist/vanilla/AudioRenderer.d.ts +3 -1
  93. package/dist/vanilla/AudioRenderer.d.ts.map +1 -1
  94. package/dist/vanilla/AudioRenderer.js +8 -2
  95. package/dist/vanilla/AudioRenderer.js.map +1 -1
  96. package/dist/vanilla/ConvaiWidget.d.ts.map +1 -1
  97. package/dist/vanilla/ConvaiWidget.js +1162 -315
  98. package/dist/vanilla/ConvaiWidget.js.map +1 -1
  99. package/dist/vanilla/WidgetEventSubscriptions.d.ts +1 -1
  100. package/dist/vanilla/WidgetEventSubscriptions.d.ts.map +1 -1
  101. package/dist/vanilla/WidgetEventSubscriptions.js +5 -0
  102. package/dist/vanilla/WidgetEventSubscriptions.js.map +1 -1
  103. package/dist/vanilla/icons.d.ts.map +1 -1
  104. package/dist/vanilla/icons.js +62 -15
  105. package/dist/vanilla/icons.js.map +1 -1
  106. package/dist/vanilla/index.d.ts +8 -2
  107. package/dist/vanilla/index.d.ts.map +1 -1
  108. package/dist/vanilla/index.js +6 -1
  109. package/dist/vanilla/index.js.map +1 -1
  110. package/dist/vanilla/styles.d.ts +18 -1
  111. package/dist/vanilla/styles.d.ts.map +1 -1
  112. package/dist/vanilla/styles.js +150 -29
  113. package/dist/vanilla/styles.js.map +1 -1
  114. package/dist/vanilla/types.d.ts +74 -0
  115. package/dist/vanilla/types.d.ts.map +1 -1
  116. package/dist/vanilla/types.js.map +1 -1
  117. package/dist/version.d.ts +1 -1
  118. package/dist/version.d.ts.map +1 -1
  119. package/dist/version.js +1 -1
  120. package/dist/version.js.map +1 -1
  121. package/package.json +44 -17
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  **Real-time conversational AI characters for the web.**
4
4
 
5
- [![npm](https://img.shields.io/npm/v/@convai/web-sdk/latest?label=npm&color=blue)](https://www.npmjs.com/package/@convai/web-sdk)
5
+ [![npm](https://img.shields.io/badge/npm-1.8.0--beta.7-blue)](https://www.npmjs.com/package/@convai/web-sdk)
6
6
  [![TypeScript](https://img.shields.io/badge/TypeScript-first-3178C6)](https://www.typescriptlang.org/)
7
7
  [![License](https://img.shields.io/badge/license-Apache--2.0-green)](./LICENSE)
8
8
 
@@ -10,29 +10,19 @@ TypeScript-first SDK for embedding Convai AI characters into React and vanilla J
10
10
 
11
11
  ---
12
12
 
13
- ## What's new in 1.8.0
14
-
15
- - **Protocol capabilities, opted into one at a time** — `capabilities`
16
- selects v2 correlated client tool calls, the canonical Core-validated
17
- `modelOutput` envelope, and raw `bot-llm-text` streaming, each independent
18
- of the others. Core must confirm a v2 capability or the SDK refuses the
19
- connection, so a half-upgraded backend fails at connect rather than
20
- mid-conversation. Omit the block entirely and nothing changes: existing
21
- connections and one-argument text messages stay on the v1 wire contract.
22
- [Options table.](./docs/convai_configuration.md#protocol-capabilities)
23
- - **Correlated action results and logical turns** — action results carry the
24
- call they answer, and turn correlation holds across multi-envelope and
25
- voice turns, so a response can be tied to its cause without guessing from
26
- arrival order.
27
- - **Extension renderer registry** — render custom model-output extensions
28
- without the SDK knowing your UI framework.
29
- - **Published chat without a credential** — a text-only connection method for
30
- published-chat launch grants, plus a native custom-element browser bundle
31
- at `dist/embed/chat-embed-v1.js` for iframe-free embeds. The embed never
32
- receives a publisher API key. [Usage below.](#published-text-chat)
33
- - **Loads in Node without a bundler** — emitted ESM carries explicit relative
34
- extensions, so the published package and the Chat Publish client resolve
35
- under plain Node resolution.
13
+ ## What's new in 1.8.0 (beta)
14
+
15
+ Install the beta with `npm install @convai/web-sdk@beta`.
16
+
17
+ - **Multi-character rooms** — connect a roster of characters with the `characters` config option (two copies of one character are two independent members), switch who answers with `setInteractionTarget()`, add or remove members live with `updateCharacterRoster()`, and let other participants join the same room with `joinRoom()`. Every transcript line, audio track and readiness event is attributed to a `membershipId`. [Usage below.](#multi-character-rooms-beta)
18
+ - **Agentic actions and canonical model output (v2)** — opt in with `capabilities`, declare client-executed tools in `actionConfig.tools`, consume typed `modelOutput` envelopes, return results with `sendActionResultAndWait()` for a correlated server acknowledgement, and read the raw provider stream through `botLlmTextRaw`. `visionPromptMode: "disabled"` keeps scene context without advertising visual perception. [Usage below.](#agentic-actions-and-canonical-model-output-v2)
19
+ - **Published text chat** — a credential-free, text-only connection for public chat pages: `connectWithPublicationGrant()`, `connectionType: "text"`, and the self-contained `<convai-chat>` browser bundle. [Usage below.](#published-text-chat)
20
+ - **Typed events** — `client.on(event, callback)` infers each callback's payload from the exported `ConvaiEventMap`, so `botReady`, `modelOutput`, `characterStatus` and the rest are checked at compile time. See the [events reference](docs/convai_events.md).
21
+ - **Local transcript lines and usage updates** — `appendMessage()` inserts a line into the transcript without sending anything, and `toggleUsageUpdates(true)` opts into per-turn `usageUpdate` cost breakdowns.
22
+ - **Character versioning** — connect to a character's editable draft, its promoted latest release, or an immutable tag with the `characterVersion` config option, and list, compare, release, promote, fork and discard versions through `client.characterVersions`. [Usage below.](#character-versioning-beta)
23
+ - **SSE interaction transport** — text-only streamed interactions through the interaction API, selected by `interactionApiUrl`; the one transport that runs under Node. [Usage below.](#sse-interaction-transport-beta)
24
+ - **Embeddable vanilla widget** — the vanilla widget runs inside a shadow root, with a character header and a connecting overlay, so it can be dropped into any page.
25
+ - **Node-importable dist** — `@convai/web-sdk/core`, `/vanilla`, `/vanilla/websocket` and `/lipsync-helpers` load in plain Node, SSR and Next.js server components.
36
26
 
37
27
  ### Previously in 1.7.0
38
28
 
@@ -41,7 +31,7 @@ TypeScript-first SDK for embedding Convai AI characters into React and vanilla J
41
31
  - **Lipsync naturalness pipeline** — modular naturalness processing with a tuned MetaHuman profile.
42
32
  - **Adaptive glass widget styling** — `ConvaiWidget` adapts to light and dark backgrounds.
43
33
 
44
- #### Previously in 1.6.0
34
+ ### 1.6.0
45
35
 
46
36
  - **Narrative Design template keys** — personalize one narrative graph per session: seed values at connect with the `narrativeTemplateKeys` config option, replace them mid-session with `updateTemplateKeys()`. [Usage below.](#narrative-design-template-keys)
47
37
  - **Typed parameterized actions** — `actionResponse` is now typed via the exported `ConvaiAction` / `ActionResponseEvent`, including the `target` of parameterized actions. [Usage below.](#actions)
@@ -58,6 +48,11 @@ TypeScript-first SDK for embedding Convai AI characters into React and vanilla J
58
48
  - **Dynamic context & vision** — inject text state, scene metadata, and LiveKit video frames mid-session
59
49
  - **Actions & Narrative Design** — typed action decisions with parameterized targets, named triggers, and per-session template keys
60
50
  - **Long-term memory** — persistent cross-session memories scoped to each end user
51
+ - **Multi-character rooms** — a roster of characters in one room, per-member attribution, live roster changes
52
+ - **Agentic actions (v2)** — client-executed tools, canonical model output, acknowledged action results, raw provider stream
53
+ - **Published text chat** — grant-based, credential-free text sessions and a drop-in `<convai-chat>` element
54
+ - **Typed events** — every `client.on` payload typed through `ConvaiEventMap`
55
+ - **Character versioning** — connect to a draft, latest, or tagged version, and manage releases from the client
61
56
  - **File upload** — send images to the character during a live session
62
57
  - **WebSocket transport** — opt-in alternative to WebRTC for constrained networks
63
58
  - **Auth tokens** — server-side token exchange for production deployments
@@ -117,6 +112,10 @@ window.addEventListener("beforeunload", () => {
117
112
 
118
113
  ### Published text chat
119
114
 
115
+ See the [Published text chat guide](./docs/convai_published_chat.md) for
116
+ React and vanilla integrations, lifecycle behavior, and the complete API
117
+ reference.
118
+
120
119
  Published chat pages use a short-lived launch grant instead of the publisher's
121
120
  API key. Native Web SDK integration is the recommended embed path; an iframe is
122
121
  not required. Obtain the grant from the public Character API and pass it to the
@@ -179,14 +178,17 @@ custom element:
179
178
  ```html
180
179
  <script
181
180
  type="module"
182
- src="https://cdn.jsdelivr.net/npm/@convai/web-sdk@latest/dist/embed/chat-embed-v1.js"
181
+ src="https://cdn.jsdelivr.net/npm/@convai/web-sdk@<SDK_VERSION>/dist/embed/chat-embed-v1.js"
183
182
  ></script>
184
183
  <convai-chat publication-id="PUBLICATION_UUID"></convai-chat>
185
184
  ```
186
185
 
187
186
  The element renders directly in the host page with Shadow DOM style isolation,
188
187
  automatically mints a fresh grant per connection, and emits `convai-ready`,
189
- `convai-disconnect`, and `convai-error` DOM events. The production bundle uses
188
+ `convai-disconnect`, `convai-error`, `convai-copy`, and `convai-session-reset`
189
+ DOM events. It accepts `full-window`, `display-name` and `image-url` alongside
190
+ the endpoint attributes, and is themed through `--convai-chat-*` custom
191
+ properties — see [the published chat guide](docs/convai_published_chat.md#the-convai-chat-element). The production bundle uses
190
192
  `https://api.convai.com` and `https://realtime-api.convai.com` only as defaults
191
193
  for a hand-written SaaS integration. Platform-generated snippets always emit
192
194
  the deployment's public Character API and Core endpoints explicitly, so an
@@ -201,6 +203,10 @@ still requires no credential:
201
203
  ></convai-chat>
202
204
  ```
203
205
 
206
+ Replace `<SDK_VERSION>` with the exact published package version. Do not use
207
+ `latest`: generated embed snippets must stay bound to the SDK version validated
208
+ for their target environment.
209
+
204
210
  Descriptor and grant endpoints must allow credential-free cross-origin `GET`
205
211
  and `POST` requests. The embed never receives a publisher API key, character
206
212
  configuration, or reusable launch token.
@@ -237,6 +243,12 @@ Full documentation is at **<a href="https://docs.convai.com/api-docs/plugins-and
237
243
  | <a href="https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk/error-handling" target="_blank" rel="noopener noreferrer">Error Handling</a> | `error`, `disconnect`, `serverResponse`, retry patterns |
238
244
  | <a href="https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk/auth-tokens" target="_blank" rel="noopener noreferrer">Auth Tokens</a> | Server-side token exchange for production |
239
245
  | <a href="https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk/websocket-transport-layer" target="_blank" rel="noopener noreferrer">WebSocket Transport</a> | Alternative transport for WebRTC-constrained environments |
246
+ | <a href="https://docs.convai.com/api-docs/plugins-and-integrations/web-plugins/convai-web-sdk" target="_blank" rel="noopener noreferrer">SSE Transport</a> | Text-only interaction transport; the one that runs under Node |
247
+ | [Character Versioning](docs/convai_character_versioning.md) | Connect to a draft, latest, or tagged version; list, compare, release and promote versions |
248
+ | [Multi-Character Rooms](docs/convai_multi_character.md) | Rosters, `joinRoom`, interaction targets, live roster updates, per-member attribution |
249
+ | [Published Text Chat](docs/convai_published_chat.md) | Grant-based text-only sessions, `<convai-chat>`, lifecycle and API reference |
250
+ | [Link Previews](docs/convai_link_previews.md) | Rendering links the character sends: previews, custom chat UIs, the scheme allowlist |
251
+ | [Events Reference (local)](docs/convai_events.md) | Every event with its typed payload, including the v2 and multi-character events |
240
252
 
241
253
  ---
242
254
 
@@ -253,6 +265,20 @@ Full documentation is at **<a href="https://docs.convai.com/api-docs/plugins-and
253
265
  | `@convai/web-sdk/lipsync-helpers` | Blendshape format utilities and queue helpers |
254
266
  | `@convai/web-sdk/vanilla/websocket` | **Opt-in.** Registers the WebSocket transport. Import alongside `/vanilla` when using `transport: "websocket"`. |
255
267
 
268
+ ### Module format
269
+
270
+ The package is ESM. Every entry point above also resolves through the `require`
271
+ and `default` conditions, so CommonJS tooling — Jest, ts-node, CJS bundlers —
272
+ can resolve and mock it:
273
+
274
+ ```js
275
+ const { ConvaiClient } = require('@convai/web-sdk/core')
276
+ ```
277
+
278
+ There is no separate CommonJS build; `require()` loads the ESM files directly,
279
+ which Node supports from **22.12** onward. On older Node, `import` it or let
280
+ your bundler handle the ESM.
281
+
256
282
  ---
257
283
 
258
284
  ## WebSocket transport
@@ -277,6 +303,134 @@ See the <a href="https://docs.convai.com/api-docs/plugins-and-integrations/web-p
277
303
 
278
304
  ---
279
305
 
306
+ ## SSE interaction transport (beta)
307
+
308
+ Use the interaction API for text-only integrations that need a streamed response:
309
+
310
+ ```ts
311
+ const client = new ConvaiClient({
312
+ apiKey: "...",
313
+ characterId: "...",
314
+ interactionApiUrl: "https://interaction-api-stg.convai.com/v1/interactions",
315
+ });
316
+
317
+ await client.connect();
318
+ client.sendUserTextMessage("Hello!");
319
+ ```
320
+
321
+ This sends each message as an SSE `POST` with `Authorization: Bearer ...`. Set `transport: "sse"`
322
+ explicitly if preferred. SSE carries text only — no voice, video, or lipsync — and it never calls
323
+ `/connect`, so `connect()` makes no network request and the session id arrives on the first
324
+ interaction via the `characterSessionId` event.
325
+
326
+ Because it needs neither WebRTC nor a DOM, this is the only transport that runs outside a browser.
327
+ Import `@convai/web-sdk/core` from Node, SSR, or a serverless function — not the root or `/react`
328
+ entry points, which pull in browser-only dependencies.
329
+
330
+ The interaction API is currently reachable at staging only; a production host is planned.
331
+ Full guide: [SSE Interaction Transport](docs/convai_sse_transport.md).
332
+
333
+ ---
334
+
335
+ ## Character versioning (beta)
336
+
337
+ Every character has an editable **draft** and, once released, immutable **tagged versions**
338
+ (`1.0`, `1.1`, …). A movable `latest` pointer names the release the runtime uses when a client
339
+ connects without a selector. Pick the version to run with `characterVersion`:
340
+
341
+ | `characterVersion` | Runs |
342
+ | ------------------ | ----------------------------------------------------------------- |
343
+ | *(omitted)* | The effective latest — how characters that predate versioning behave |
344
+ | `"draft"` | The editable draft, for testing unreleased changes |
345
+ | `"latest"` | The promoted latest release, explicitly |
346
+ | `"1.2"` / `"1.2.3"` | An immutable tagged version |
347
+
348
+ ```tsx
349
+ const client = useConvaiClient({
350
+ apiKey: "...",
351
+ characterId: "...",
352
+ characterVersion: "draft",
353
+ });
354
+ ```
355
+
356
+ On the wire the selector is joined to the id as `<uuid>-draft`; `client.characterId` keeps
357
+ returning the bare UUID, and `client.characterReference` returns the joined form.
358
+
359
+ Manage versions from the same client — `client.characterVersions` is available as soon as the
360
+ config has an `apiKey`, before connecting:
361
+
362
+ ```ts
363
+ const versions = client.characterVersions!;
364
+
365
+ const { has_unpublished_changes, draft_revision_id } = await versions.list();
366
+ const diff = await versions.diff("latest", "draft", { view: "semantic" });
367
+
368
+ await versions.create("1.1", { makeLatest: true }); // release the draft as a tag
369
+ await versions.promote("1.0"); // roll back: latest → 1.0
370
+ await versions.discardDraft(draft_revision_id!); // throw away unreleased edits
371
+ ```
372
+
373
+ `CharacterVersionManager` can also be constructed standalone with an `apiKey` or a Convai
374
+ personal access token; every method rejects with `CharacterApiError` (`status`, `detail`) on a
375
+ non-2xx answer. Point `characterApiUrl` at `https://api2-stg.convai.com` to author against
376
+ staging.
377
+
378
+ Explicit selectors are resolved by the runtime through the Character REST platform. Staging has
379
+ this today; production answers explicit selectors with `503` until it is promoted there.
380
+ Full guide: [Character Versioning](docs/convai_character_versioning.md).
381
+
382
+ ---
383
+
384
+
385
+ ## Multi-character rooms (beta)
386
+
387
+ Pass `characters` instead of `characterId` to open a room with several members.
388
+ `characters[0]` answers first; the same character id may appear more than once
389
+ and each entry is an independent member with its own `membershipId`. Roster
390
+ rooms need the LiveKit transport and a nonblank `endUserId`.
391
+
392
+ ```ts
393
+ const client = new ConvaiClient({
394
+ apiKey: "YOUR_API_KEY",
395
+ endUserId: "player-42",
396
+ characters: [
397
+ { characterId: GUIDE }, // initial active member
398
+ { characterId: ASSESSOR },
399
+ { characterId: GUIDE }, // a second, independent copy of the guide
400
+ ],
401
+ maxNumParticipants: 2,
402
+ });
403
+
404
+ client.on("characterReady", (member) => console.log("ready", member.membershipId));
405
+ client.on("characterStatus", ({ membershipId, status, failureCode }) => {
406
+ if (status === "failed") console.warn(membershipId, failureCode);
407
+ });
408
+
409
+ await client.connect();
410
+
411
+ // Route the next user turns to another member; null closes every gate.
412
+ await client.setInteractionTarget(client.characters[1].membershipId);
413
+
414
+ // Change the roster on a live room.
415
+ await client.updateCharacterRoster({ add: [{ characterId: GUIDE }] });
416
+ await client.updateCharacterRoster({ remove: [client.characters[0].membershipId] });
417
+
418
+ // Another participant joins the same room without sending any topology.
419
+ await other.joinRoom({ roomSessionId: client.roomSession!.roomSessionId, endUserId: "player-7" });
420
+ ```
421
+
422
+ Key points:
423
+
424
+ - `characters` and `characterId` are mutually exclusive, and roster entries take a bare character UUID (no `-draft` / `-1.2` selectors).
425
+ - `provisioningStatus` describes dispatch only; a member is usable when its own `characterReady` arrives.
426
+ - Transcript rows, `characterAudioTrack` events and `botReady` payloads carry `membershipId`, so two copies of one character never merge.
427
+ - Room-topology failures throw `ConvaiRoomError` with `status`, `code`, `requestTraceId` and `isRetryable`; the SDK retries `ROSTER_PROVISIONING_IN_PROGRESS` for you (`rosterProvisioningRetry`).
428
+ - Action protocol v2 and `actionConfig.tools` are single-character only and cannot be combined with a roster.
429
+
430
+ Full reference: [docs/convai_multi_character.md](docs/convai_multi_character.md).
431
+
432
+ ---
433
+
280
434
  ## Vision dynamic context beta
281
435
 
282
436
  Vision dynamic context is the default WebRTC/LiveKit vision path when `enableVideo: true`. Camera, screen, canvas, and custom video tracks can feed unified vision context; set `visionInputConfig.enabled: false` only when you need to keep the video channel while opting out.
@@ -352,7 +506,7 @@ dispatches only Core-validated `items`, and returns one correlated terminal
352
506
  result for every `tool_call`.
353
507
 
354
508
  ```ts
355
- import { ConvaiClient } from "@convai/web-sdk/core";
509
+ import { ConvaiClient, type ActionResult } from "@convai/web-sdk/core";
356
510
 
357
511
  const client = new ConvaiClient({
358
512
  apiKey: "...",
@@ -384,49 +538,63 @@ client.on("modelOutput", async (output) => {
384
538
  if (item.type === "message") renderAssistantText(item.content);
385
539
  if (item.type !== "tool_call") continue;
386
540
 
541
+ let terminalResult: ActionResult;
387
542
  try {
388
543
  const result = await executeApprovedTool(item.name, item.arguments);
389
- client.sendActionResult({
544
+ terminalResult = {
390
545
  id: item.id,
391
546
  status: "completed",
392
547
  output: result,
393
- });
548
+ };
394
549
  } catch (error) {
395
- client.sendActionResult({
550
+ terminalResult = {
396
551
  id: item.id,
397
552
  status: "error",
398
553
  error: { message: String(error) },
554
+ };
555
+ }
556
+
557
+ try {
558
+ const ack = await client.sendActionResultAndWait(terminalResult, {
559
+ timeoutMs: 10_000,
399
560
  });
561
+ markResultReported(item.id, ack.idempotent);
562
+ } catch (deliveryError) {
563
+ markResultDeliveryUncertain(item.id, deliveryError);
564
+ // If appropriate for your session lifecycle, retry `terminalResult`
565
+ // unchanged. Never execute the tool again merely because its ACK was lost.
400
566
  }
401
567
  }
402
568
  });
403
569
  ```
404
570
 
405
- ### Raw provider output in the existing text stream
571
+ ### Parallel raw provider output (v2)
406
572
 
407
- To display every user-visible provider output chunk before Core parses actions
408
- or display markup, explicitly select raw `bot-llm-text` mode:
573
+ Model output v2 may provide a separate diagnostics-only raw stream alongside
574
+ the unchanged `bot-llm-text` chat stream. Each chunk carries Core's stable
575
+ logical-turn correlation id and, on newer Core versions, an invocation id:
409
576
 
410
577
  ```ts
411
578
  const client = new ConvaiClient({
412
579
  apiKey: "...",
413
580
  characterId: "...",
414
- capabilities: { botLlmTextMode: "raw" },
581
+ capabilities: { modelOutputVersion: 2 },
415
582
  });
416
583
 
417
- client.on("message", (message) => {
418
- // The existing streaming message event now carries the raw bot-llm-text
419
- // chunks in provider order. Keep this display stream separate from speech.
420
- renderChat(message);
584
+ client.on("botLlmTextRaw", ({ text, logical_turn_id, output_id }) => {
585
+ appendRawDiagnostics(output_id ?? logical_turn_id, text);
421
586
  });
422
587
  ```
423
588
 
424
- Omitting `botLlmTextMode` preserves the legacy request and filtered text
425
- behavior. This capability is independent of `actionProtocolVersion` and
426
- `modelOutputVersion`.
427
-
428
- `raw` is retained for diagnostics and must never be executed or reparsed. When
429
- v2 is selected, the SDK suppresses the legacy `actionResponse` compatibility
589
+ The SDK ignores this channel unless Core negotiated `modelOutputVersion: 2`.
590
+ Raw chunks never enter `chatMessages`, bot output, TTS, speech, or response
591
+ lifecycle state. They are retained for diagnostics and must never be executed
592
+ or reparsed. The ordinary `bot-llm-text` text and cadence remain unchanged. On
593
+ v2 connections, `ChatMessage.outputId` matches the raw event's optional
594
+ `output_id` and the final `modelOutput.output_id`; `logicalTurnId`/
595
+ `logical_turn_id` still groups every invocation in the user turn. Older v2 Core
596
+ omits the invocation id, so applications can fall back to one turn-level raw
597
+ aggregate. Never correlate by arrival order. When v2 is selected, the SDK suppresses the legacy `actionResponse` compatibility
430
598
  projection so an application cannot execute the same operation twice.
431
599
 
432
600
  Developer-defined visual output uses data-only `extension` items. Applications
@@ -0,0 +1,84 @@
1
+ import type { ActiveCharacterChange, CharacterRosterChange, ConvaiCharacterInstance, ConvaiRoomSession, ServerResponseExtras, UpdateCharacterRosterOptions } from "./types.js";
2
+ export declare class CharacterRoster {
3
+ private _characters;
4
+ private _activeMembershipId;
5
+ private _roomSessionId;
6
+ private _roomName;
7
+ private _requestTraceId;
8
+ private _routeEpoch;
9
+ private _rosterEpoch;
10
+ private _partialDispatch;
11
+ /** Character instances in roster order. Empty in single-character mode. */
12
+ get characters(): ConvaiCharacterInstance[];
13
+ /** Membership currently receiving user turns, or null. */
14
+ get activeMembershipId(): string | null;
15
+ get roomSessionId(): string | null;
16
+ get routeEpoch(): number;
17
+ get rosterEpoch(): number;
18
+ /** True once a multi-character connect response has been applied. */
19
+ get isMultiCharacter(): boolean;
20
+ /** The server-owned snapshot, or null for a single-character session. */
21
+ get roomSession(): ConvaiRoomSession | null;
22
+ find(membershipId: string): ConvaiCharacterInstance | undefined;
23
+ /** Members that have sent their own `bot-ready`. */
24
+ get readyCharacters(): ConvaiCharacterInstance[];
25
+ /**
26
+ * Mark a member ready from its own `bot-ready`, filling in any detail the
27
+ * connect response did not yet have.
28
+ *
29
+ * Returns whether anything changed, so the caller only pushes state when it
30
+ * did. A single-character `bot-ready` also carries these fields, so nothing
31
+ * is tracked until a roster is actually seeded.
32
+ */
33
+ applyBotReady(about: Record<string, unknown> | undefined): boolean;
34
+ /**
35
+ * Apply a `character-status` transition. Readiness recorded here is
36
+ * bookkeeping for replacement selection; `bot-ready` remains what gates
37
+ * interaction.
38
+ */
39
+ applyCharacterStatus(status: {
40
+ membershipId: string;
41
+ status: "starting" | "ready" | "failed";
42
+ failureCode: string | null;
43
+ }): boolean;
44
+ /**
45
+ * Pick a member to take over routing when the active one is removed.
46
+ *
47
+ * The runtime refuses a replacement that has not sent `bot-ready`
48
+ * (`replacement_target_unavailable`), so ready survivors come first. Falling
49
+ * back to any survivor at least produces a nameable rejection rather than
50
+ * `replacement_target_required`.
51
+ */
52
+ pickReplacement(removing: string[]): string | undefined;
53
+ /** Payload that switches the active member. */
54
+ buildInteractionTarget(membershipId: string | null, commandId: string): Record<string, unknown>;
55
+ /** Payload that adds and removes members. */
56
+ buildRosterUpdate(options: UpdateCharacterRosterOptions, commandId: string): Record<string, unknown>;
57
+ /**
58
+ * Adopt the server's authoritative epochs and active member from any
59
+ * response, errors included.
60
+ *
61
+ * A `stale_route_epoch` rejection carries the real epoch, and adopting it is
62
+ * precisely what makes the single retry meaningful rather than a repeat of
63
+ * the same losing bet.
64
+ */
65
+ adoptEpochs(extras: ServerResponseExtras | null | undefined): void;
66
+ /**
67
+ * Apply a successful `interaction-target` ack. Returns the change even when
68
+ * the target did not move, so a caller awaiting the promise always learns the
69
+ * authoritative state.
70
+ */
71
+ applyInteractionTarget(extras: ServerResponseExtras | null | undefined): ActiveCharacterChange;
72
+ /** Apply a successful `character-roster-update` ack, mutating the roster. */
73
+ applyRosterUpdate(extras: ServerResponseExtras | null | undefined): CharacterRosterChange;
74
+ reset(): void;
75
+ /**
76
+ * Seed the roster from a `/connect` response, for either a create or a join.
77
+ *
78
+ * Returns false for a response with no `characters` array — that is an
79
+ * ordinary single-character session, and the roster stays empty so
80
+ * `isMultiCharacter` keeps distinguishing the two.
81
+ */
82
+ applyConnectResponse(data: Record<string, unknown>): boolean;
83
+ }
84
+ //# sourceMappingURL=CharacterRoster.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CharacterRoster.d.ts","sourceRoot":"","sources":["../../src/core/CharacterRoster.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EAErB,qBAAqB,EACrB,uBAAuB,EAEvB,iBAAiB,EACjB,oBAAoB,EACpB,4BAA4B,EAC7B,MAAM,SAAS,CAAC;AA8EjB,qBAAa,eAAe;IAC1B,OAAO,CAAC,WAAW,CAAiC;IACpD,OAAO,CAAC,mBAAmB,CAAuB;IAClD,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,gBAAgB,CAAS;IAEjC,2EAA2E;IAC3E,IAAI,UAAU,IAAI,uBAAuB,EAAE,CAE1C;IAED,0DAA0D;IAC1D,IAAI,kBAAkB,IAAI,MAAM,GAAG,IAAI,CAEtC;IAED,IAAI,aAAa,IAAI,MAAM,GAAG,IAAI,CAEjC;IAED,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,qEAAqE;IACrE,IAAI,gBAAgB,IAAI,OAAO,CAE9B;IAED,yEAAyE;IACzE,IAAI,WAAW,IAAI,iBAAiB,GAAG,IAAI,CAY1C;IAED,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,uBAAuB,GAAG,SAAS;IAI/D,oDAAoD;IACpD,IAAI,eAAe,IAAI,uBAAuB,EAAE,CAE/C;IAED;;;;;;;OAOG;IACH,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAAG,OAAO;IAyClE;;;;OAIG;IACH,oBAAoB,CAAC,MAAM,EAAE;QAC3B,YAAY,EAAE,MAAM,CAAC;QACrB,MAAM,EAAE,UAAU,GAAG,OAAO,GAAG,QAAQ,CAAC;QACxC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;KAC5B,GAAG,OAAO;IAiCX;;;;;;;OAOG;IACH,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS;IAUvD,+CAA+C;IAC/C,sBAAsB,CACpB,YAAY,EAAE,MAAM,GAAG,IAAI,EAC3B,SAAS,EAAE,MAAM,GAChB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAS1B,6CAA6C;IAC7C,iBAAiB,CACf,OAAO,EAAE,4BAA4B,EACrC,SAAS,EAAE,MAAM,GAChB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAmB1B;;;;;;;OAOG;IACH,WAAW,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI;IASlE;;;;OAIG;IACH,sBAAsB,CACpB,MAAM,EAAE,oBAAoB,GAAG,IAAI,GAAG,SAAS,GAC9C,qBAAqB;IAaxB,6EAA6E;IAC7E,iBAAiB,CACf,MAAM,EAAE,oBAAoB,GAAG,IAAI,GAAG,SAAS,GAC9C,qBAAqB;IAuDxB,KAAK,IAAI,IAAI;IAWb;;;;;;OAMG;IACH,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO;CA2B7D"}