@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
@@ -1,4 +1,6 @@
1
1
  import { Room, DisconnectReason as LiveKitDisconnectReason } from 'livekit-client';
2
+ import type { CharacterVersionSelector } from "./characterReference.js";
3
+ export type { CharacterVersionSelector, CharacterReference } from "./characterReference.js";
2
4
  import { BlendshapeQueue } from './BlendshapeQueue.js';
3
5
  /**
4
6
  * LiveKit disconnect reasons.
@@ -122,6 +124,17 @@ export interface ServerResponseExtras {
122
124
  has_speak_tag?: boolean;
123
125
  text?: string;
124
126
  room_name?: string;
127
+ command_id?: string;
128
+ room_session_id?: string;
129
+ previous_membership_id?: string | null;
130
+ active_membership_id?: string | null;
131
+ previous_active_membership_id?: string | null;
132
+ route_epoch?: number;
133
+ roster_epoch?: number;
134
+ changed?: boolean;
135
+ added?: unknown[];
136
+ removed_membership_ids?: string[];
137
+ code?: string;
125
138
  supported_types?: string[];
126
139
  vision_buffer?: VisionBufferStatus;
127
140
  requested_respond_mode?: RespondMode;
@@ -221,15 +234,16 @@ export interface ProtocolCapabilitiesConfig {
221
234
  actionProtocolVersion?: 1 | 2;
222
235
  /** Opt in to canonical typed model output. Omitted connections remain v1. */
223
236
  modelOutputVersion?: 1 | 2;
237
+ }
238
+ /** One raw provider-output chunk emitted only by negotiated model output v2. */
239
+ export interface BotLlmTextRawEvent {
240
+ text: string;
241
+ logical_turn_id: string;
224
242
  /**
225
- * Select what Core streams through the existing `bot-llm-text` event.
226
- *
227
- * `"raw"` is an explicit opt-in to the complete user-visible provider output
228
- * before action/display parsing. Omit this field for the legacy filtered text
229
- * stream. `"legacy"` is available when an application needs to state that
230
- * choice explicitly.
243
+ * Core-owned identifier for the individual model invocation that produced
244
+ * this chunk. Absent when connected to an older v2 Core.
231
245
  */
232
- botLlmTextMode?: "legacy" | "raw";
246
+ output_id?: string;
233
247
  }
234
248
  export interface ModelOutputMessageItem {
235
249
  type: "message";
@@ -266,6 +280,10 @@ export type ModelOutputItem = ModelOutputMessageItem | ModelOutputEmotionItem |
266
280
  export interface ModelOutputMessage {
267
281
  type: "model-output";
268
282
  version: 2;
283
+ /**
284
+ * Core-owned provider invocation id. Distinct projections from the same
285
+ * invocation can share this value and are emitted in arrival order.
286
+ */
269
287
  output_id: string;
270
288
  /**
271
289
  * Stable identifier shared by every output envelope for one logical turn.
@@ -290,6 +308,29 @@ export interface ActionResult {
290
308
  error?: JsonValue;
291
309
  characterSessionId?: string;
292
310
  }
311
+ /** Successful server acknowledgement for one correlated action result. */
312
+ export interface ActionResultAck {
313
+ toolCallId: string;
314
+ status: "success";
315
+ message: string | null;
316
+ /** True when Core had already accepted the same terminal result. */
317
+ idempotent: boolean;
318
+ }
319
+ /**
320
+ * Controls acknowledgement waiting for
321
+ * {@link IConvaiClient.sendActionResultAndWait}.
322
+ */
323
+ export interface ActionResultAckOptions {
324
+ /** Maximum wait for Core's acknowledgement. Defaults to 10 seconds. */
325
+ timeoutMs?: number;
326
+ /**
327
+ * Cancels acknowledgement waiting. An already-aborted signal prevents
328
+ * publication.
329
+ */
330
+ signal?: AbortSignal;
331
+ }
332
+ /** Machine-readable reason exposed by `ActionResultAckError`. */
333
+ export type ActionResultAckFailureReason = "server_error" | "publication_error" | "timeout" | "aborted" | "duplicate_in_flight";
293
334
  /**
294
335
  * Payload of the `actionResponse` event. Actions execute sequentially; an
295
336
  * empty array is a valid "no action" turn.
@@ -494,8 +535,101 @@ export interface ConvaiConfig {
494
535
  /** Your Convai API key or Auth Token (at least one is required) */
495
536
  apiKey?: string;
496
537
  authToken?: string;
497
- /** The Character ID to connect to (required) */
498
- characterId: string;
538
+ /**
539
+ * The Character ID to connect to (required).
540
+ *
541
+ * May also carry a version selector suffix (`<uuid>-draft`, `<uuid>-latest`,
542
+ * `<uuid>-1.2`); `characterVersion` is the clearer way to say the same thing.
543
+ *
544
+ * Optional only because a multi-character room supplies `characters`
545
+ * instead. Exactly one of the two is required, and a version selector is not
546
+ * accepted inside a roster entry.
547
+ */
548
+ characterId?: string;
549
+ /**
550
+ * Which version of the character to run (optional).
551
+ *
552
+ * - `"draft"` — the editable draft, so you can test unreleased changes
553
+ * - `"latest"` — the promoted latest release
554
+ * - `"1.2"` / `"1.2.3"` — an immutable tagged version
555
+ *
556
+ * Omit it to let the runtime pick the effective latest revision, which is
557
+ * also how characters that predate versioning behave. The selector is joined
558
+ * to `characterId` on the wire as `<uuid>-<selector>`; `client.characterId`
559
+ * keeps returning the bare UUID.
560
+ *
561
+ * @example
562
+ * ```ts
563
+ * const client = new ConvaiClient({
564
+ * apiKey: 'YOUR_API_KEY',
565
+ * characterId: 'YOUR_CHARACTER_ID',
566
+ * characterVersion: 'draft',
567
+ * });
568
+ * ```
569
+ */
570
+ characterVersion?: CharacterVersionSelector | null;
571
+ /**
572
+ * Base URL of the Character REST platform used by `client.characterVersions`
573
+ * (optional, defaults to `https://api2.convai.com`). Point it at
574
+ * `https://api2-stg.convai.com` to author against staging.
575
+ */
576
+ characterApiUrl?: string;
577
+ /**
578
+ * Ordered roster of character instances for a multi-character room. Pass this
579
+ * *instead of* `characterId` -- exactly one of the two is valid.
580
+ *
581
+ * Every entry becomes a distinct membership with its own actor, LiveKit
582
+ * participant, voice, history and lifecycle. The same `characterId` may
583
+ * appear more than once; each copy is an independent clone addressed by its
584
+ * own `membershipId`. `characters[0]` is the initial active member.
585
+ *
586
+ * Roster rooms require the LiveKit transport, a nonblank `endUserId`, and the
587
+ * `MULTI_CHARACTER_V0` entitlement on the publisher.
588
+ *
589
+ * @example
590
+ * ```ts
591
+ * const client = new ConvaiClient({
592
+ * apiKey: 'YOUR_API_KEY',
593
+ * endUserId: 'player-42',
594
+ * characters: [
595
+ * { characterId: GUIDE }, // initial active member
596
+ * { characterId: ASSESSOR },
597
+ * { characterId: GUIDE }, // a second, independent copy of GUIDE
598
+ * ],
599
+ * });
600
+ * ```
601
+ */
602
+ characters?: ConvaiCharacterSpec[];
603
+ /**
604
+ * Publisher-scoped room grouping and topology key (1-128 chars of letters,
605
+ * digits, hyphen or underscore). A matching create request reuses the
606
+ * existing room; reusing the key with a different ordered roster, creator or
607
+ * capacity is rejected with `ROSTER_FINGERPRINT_MISMATCH`. Reordering the
608
+ * same characters counts as different, because it changes the initial member.
609
+ *
610
+ * This does not raise human capacity on its own -- see `maxNumParticipants`.
611
+ */
612
+ sharedSessionKey?: string;
613
+ /**
614
+ * Idempotency key for one logical connect (1-128 chars, same charset as
615
+ * `sharedSessionKey`). Reuse it only when retrying with an identical payload:
616
+ * within the replay window a completed attempt returns its original response
617
+ * and token, while a changed payload or a still-running original is rejected.
618
+ */
619
+ connectAttemptId?: string;
620
+ /**
621
+ * Maximum number of distinct human speakers in a roster room. Characters do
622
+ * not count toward it. Defaults to the server's value of 1, which admits no
623
+ * second human -- raise it before expecting `joinRoom()` to succeed.
624
+ */
625
+ maxNumParticipants?: number;
626
+ /**
627
+ * Bounded retry when a roster room is still provisioning (409
628
+ * `ROSTER_PROVISIONING_IN_PROGRESS`). Defaults to four attempts starting at
629
+ * 500ms and doubling with jitter. Pass `false` to surface the error instead
630
+ * and retry in application code.
631
+ */
632
+ rosterProvisioningRetry?: RosterProvisioningRetry | false;
499
633
  /** Temporary character state of mind sent as `state_of_mind` on connect. */
500
634
  stateOfMind?: string | null;
501
635
  /**
@@ -521,8 +655,19 @@ export interface ConvaiConfig {
521
655
  endUserMetadata?: Record<string, unknown>;
522
656
  /** Custom Convai API URL (optional, defaults to production endpoint) */
523
657
  url?: string;
524
- /** Transport layer to use. Default: "livekit". Use "websocket" for Pipecat WebSocket transport. */
525
- transport?: "livekit" | "websocket";
658
+ /** Transport layer to use. Default: "livekit". */
659
+ transport?: "livekit" | "websocket" | "sse";
660
+ /** SSE interaction endpoint. Supplying this also selects the SSE transport when transport is omitted. */
661
+ interactionApiUrl?: string;
662
+ /**
663
+ * Mint a fresh single-use Workspace preview grant for each HTTP interaction.
664
+ * SSE only; mutually exclusive with apiKey/authToken and end-user overrides.
665
+ * Honor signal cancellation. Never return an owner or Workspace runtime key.
666
+ * Failed/ambiguous requests are not automatically replayed.
667
+ */
668
+ interactionCredentialProvider?: (signal: AbortSignal) => Promise<{
669
+ authToken: string;
670
+ }>;
526
671
  /** Explicit protocol opt-ins. Omit to preserve the legacy v1 wire contract. */
527
672
  capabilities?: ProtocolCapabilitiesConfig;
528
673
  /**
@@ -553,8 +698,27 @@ export interface ConvaiConfig {
553
698
  * visionInputConfig.enabled=false to opt out while keeping the video channel.
554
699
  */
555
700
  visionInputConfig?: VisionInputConfig;
701
+ /**
702
+ * Controls whether Core injects its vision-state instructions into the model prompt.
703
+ * Omit this option (or use `"auto"`) to preserve the existing runtime behavior.
704
+ * Use `"disabled"` for metadata-only sessions that must not advertise or deny
705
+ * visual perception.
706
+ */
707
+ visionPromptMode?: "auto" | "disabled";
556
708
  /** Connect-time respond-mode defaults by modality. */
557
709
  respondModes?: RespondModesConfig;
710
+ /** Descriptive objects visible in the scene at connection time. */
711
+ sceneDescription?: Array<{
712
+ name: string;
713
+ description: string;
714
+ }>;
715
+ /**
716
+ * WebRTC ICE transport policy for the LiveKit connection (default: "relay").
717
+ * "relay" forces TURN-only (reliable against Convai's hosted LiveKit which
718
+ * provides TURN). Set "all" to also allow host/srflx candidates when the
719
+ * LiveKit has no TURN server (e.g. local dev).
720
+ */
721
+ iceTransportPolicy?: RTCIceTransportPolicy;
558
722
  /** Enable text-to-speech audio generation (default: true) */
559
723
  ttsEnabled?: boolean;
560
724
  /**
@@ -568,7 +732,15 @@ export interface ConvaiConfig {
568
732
  /** Blendshape configuration for facial animation format */
569
733
  blendshapeConfig?: {
570
734
  /** Format of blendshapes: "arkit" or "mha" (Meta Human Animation, default: "mha") */
571
- format?: "arkit" | "mha";
735
+ /**
736
+ * Blendshape stream format (default: "mha"). Server-verified set:
737
+ * - "mha" — 251 channels (Unreal MetaHuman Animation, CTRL_expressions_*)
738
+ * - "arkit" — 61 channels (Apple ARKit names)
739
+ * - "cc4_extended" — 170 channels (Reallusion CC4 ExpressionPlus)
740
+ * - "cc5_hd" — accepted by the server but currently delivers no frames
741
+ * - "visemes" — 15 channels (OVR viseme set)
742
+ */
743
+ format?: "arkit" | "mha" | "cc4_extended" | "cc5_hd" | "visemes";
572
744
  /**
573
745
  * Custom mapper function to transform incoming blendshapes.
574
746
  * Use this to map Convai blendshapes to your character's morph targets.
@@ -598,7 +770,7 @@ export interface ConvaiConfig {
598
770
  */
599
771
  frames_buffer_duration?: number;
600
772
  /**
601
- * Enable server ahead-delivery for NeuroSync chunks.
773
+ * Enable server ahead-delivery for NeuroSync chunks (default: true).
602
774
  *
603
775
  * Defaults to `true` when `enableLipsync` is on. The server may send
604
776
  * indexed blendshape chunks before audio playback, so use the SDK
@@ -704,6 +876,37 @@ export interface ConvaiConfig {
704
876
  * Enable debug mode for additional logging and diagnostics (default: false).
705
877
  */
706
878
  debug?: boolean;
879
+ /** Optional per-session response lifecycle contract override. */
880
+ useResponseLifecycleContract?: boolean;
881
+ /**
882
+ * Keep links in the character's text output (default: server-side, currently off).
883
+ *
884
+ * Core-service flattens the LLM's markdown before streaming `bot-llm-text`,
885
+ * which also drops link targets: `[Doc](https://…/a.pdf)` reaches the client
886
+ * as `Doc`. With this on, the session preserves `[text](url)`, `![alt](url)`
887
+ * and bare `http(s)://` URLs verbatim (trailing sentence punctuation stays
888
+ * outside the URL, non-http(s) schemes are still stripped) while bold,
889
+ * headings, tables and code are flattened as before. Speech is unaffected —
890
+ * URLs are never read aloud.
891
+ *
892
+ * Both widgets render the preserved form as clickable links, with inline
893
+ * previews for image and video URLs. If you render `chatMessages` yourself,
894
+ * expect markdown links in `content` once this is on.
895
+ *
896
+ * Sent as `preserve_links_in_output` on `/connect`; omitted when undefined so
897
+ * the server's own default applies. If you build the `/connect` request
898
+ * server-side for `connectWithConnectionData()`, add the field there.
899
+ *
900
+ * @example
901
+ * ```typescript
902
+ * const client = new ConvaiClient({
903
+ * apiKey: 'your-api-key',
904
+ * characterId: 'your-character-id',
905
+ * preserveLinksInOutput: true,
906
+ * });
907
+ * ```
908
+ */
909
+ preserveLinksInOutput?: boolean;
707
910
  /**
708
911
  * Log decoded RTVI data messages to the browser console (default: true).
709
912
  * Set to false to silence incoming and outgoing RTVI message logs.
@@ -722,10 +925,294 @@ export interface ConvaiConfig {
722
925
  extraMetadata?: Record<string, unknown>;
723
926
  };
724
927
  }
928
+ /** Optional metadata for a text interaction. */
929
+ export interface SendUserTextMessageOptions {
930
+ /** Stable logical-turn identity used by clients that correlate responses. */
931
+ logicalTurnId?: string;
932
+ /** User-selected temporary emotion to apply before processing the text. */
933
+ stateOfMind?: string | null;
934
+ /** Latest request-scoped dynamic context to include in this same interaction. */
935
+ dynamicInfo?: DynamicInfo;
936
+ }
937
+ /**
938
+ * The body returned by POST /connect. The embed receives this from a
939
+ * customer-hosted proxy route rather than fetching it directly.
940
+ */
941
+ /**
942
+ * One ordered character instance requested for a multi-character room.
943
+ *
944
+ * Repeating a `characterId` is legal and intentional: each entry becomes an
945
+ * independent clone with its own membership, session, participant and voice.
946
+ */
947
+ export interface ConvaiCharacterSpec {
948
+ /**
949
+ * Bare character UUID. Version selectors (`<uuid>-draft`, `<uuid>-1.2`) are
950
+ * accepted by single-character `characterId` but rejected inside a roster --
951
+ * the runtime types roster entries as plain UUIDs.
952
+ */
953
+ characterId: string;
954
+ /**
955
+ * Resume this instance's prior conversation history. Must be unique across
956
+ * the roster, and must belong to the same publisher, speaker and character.
957
+ */
958
+ characterSessionId?: string;
959
+ }
960
+ /**
961
+ * Dispatch state of one roster member, as reported by `/connect`.
962
+ *
963
+ * These describe provisioning only and never readiness. A member becomes
964
+ * usable when its own `bot-ready` arrives -- `dispatch_accepted` is not
965
+ * `bot-ready`. The union deliberately has no member that could be mistaken for
966
+ * a ready state; the separate `character-status` event carries those.
967
+ */
968
+ export type CharacterProvisioningStatus = "dispatch_queued" | "dispatch_accepted" | "dispatch_failed";
969
+ /** One concrete character instance in a roster room. */
970
+ export interface ConvaiCharacterInstance {
971
+ /** Primary key for this instance. Address members by this, never by `characterId`. */
972
+ membershipId: string;
973
+ /** The authored character this instance runs. Not unique across a roster. */
974
+ characterId: string;
975
+ /** Backend session for support correlation. */
976
+ sessionId: string | null;
977
+ /** This instance's conversation/history session. */
978
+ characterSessionId: string | null;
979
+ /** Stable LiveKit identity, always `character:{membershipId}`. */
980
+ participantIdentity: string;
981
+ /** True for `characters[0]`, the initially active member. */
982
+ isInitial: boolean;
983
+ provisioningStatus: CharacterProvisioningStatus;
984
+ /**
985
+ * The character's display name, when the runtime sends one. Saves a separate
986
+ * `character/get` call just to label a member in the UI. Undocumented in the
987
+ * published contract but returned by the live API, so treat it as optional.
988
+ */
989
+ displayName: string | null;
990
+ /** Character description, when the runtime sends one. */
991
+ description: string | null;
992
+ /** Populated when `provisioningStatus` is `dispatch_failed`. */
993
+ failureCode: string | null;
994
+ /** True once this member's own `bot-ready` has arrived. */
995
+ isReady: boolean;
996
+ }
997
+ /**
998
+ * Server-owned snapshot of a multi-character room. Null for single-character
999
+ * sessions.
1000
+ */
1001
+ export interface ConvaiRoomSession {
1002
+ /** Durable room identity. Use it to join, and to correlate with support. */
1003
+ roomSessionId: string;
1004
+ roomName: string | null;
1005
+ /** Trace id of the `/connect` that produced this room. Quote it in bug reports. */
1006
+ requestTraceId: string | null;
1007
+ /** Membership currently authorised to consume user turns. */
1008
+ activeMembershipId: string | null;
1009
+ /** Monotonic version of the active target; fences target switches. */
1010
+ routeEpoch: number;
1011
+ /** Monotonic version of roster composition; fences add/remove. */
1012
+ rosterEpoch: number;
1013
+ /** True when at least one member already failed dispatch. */
1014
+ partialDispatch: boolean;
1015
+ characters: ConvaiCharacterInstance[];
1016
+ }
1017
+ /** Result of a successful target switch. */
1018
+ export interface ActiveCharacterChange {
1019
+ /** Membership that was active before, or null. */
1020
+ previous: string | null;
1021
+ /** Membership now authorised to consume user turns, or null when all gates are closed. */
1022
+ active: string | null;
1023
+ routeEpoch: number;
1024
+ }
1025
+ /** Result of a successful roster mutation. */
1026
+ export interface CharacterRosterChange {
1027
+ added: ConvaiCharacterInstance[];
1028
+ removed: ConvaiCharacterInstance[];
1029
+ /** The roster after the change. */
1030
+ characters: ConvaiCharacterInstance[];
1031
+ rosterEpoch: number;
1032
+ routeEpoch: number;
1033
+ activeMembershipId: string | null;
1034
+ }
1035
+ /** Options for adding and removing roster members on a live room. */
1036
+ export interface UpdateCharacterRosterOptions {
1037
+ /** Members to add. Repeating an existing characterId creates another clone. */
1038
+ add?: ConvaiCharacterSpec[];
1039
+ /** Membership ids to remove. Never characterIds -- clones make those ambiguous. */
1040
+ remove?: string[];
1041
+ /**
1042
+ * Member to take over routing when the active one is removed. Must be a ready
1043
+ * member that survives the change. Chosen automatically when omitted.
1044
+ */
1045
+ replacementTarget?: string;
1046
+ }
1047
+ /** Options for joining an existing multi-character room. */
1048
+ export interface JoinRoomOptions {
1049
+ /** Preferred locator. Exactly one of this or `sharedSessionKey`. */
1050
+ roomSessionId?: string;
1051
+ /** Publisher-scoped alternative locator. */
1052
+ sharedSessionKey?: string;
1053
+ /** Required and nonblank; identifies the joining human. */
1054
+ endUserId: string;
1055
+ endUserMetadata?: Record<string, unknown>;
1056
+ /** Idempotency key for retrying this join. */
1057
+ connectAttemptId?: string;
1058
+ }
1059
+ /**
1060
+ * Lifecycle transition of one roster member, after `/connect` has returned.
1061
+ *
1062
+ * `bot-ready` remains the readiness authority: do not enable interaction from a
1063
+ * `ready` status alone. This event's real job is reporting a member that was
1064
+ * added at runtime, or one whose dispatch failed in the background.
1065
+ */
1066
+ export interface CharacterStatusEvent {
1067
+ status: "starting" | "ready" | "failed";
1068
+ membershipId: string;
1069
+ characterId: string;
1070
+ characterSessionId: string | null;
1071
+ participantIdentity: string;
1072
+ roomSessionId: string | null;
1073
+ rosterEpoch: number | null;
1074
+ /** Set when `status` is `failed`, e.g. `ACTOR_ASSIGNMENT_FAILED`. */
1075
+ failureCode: string | null;
1076
+ }
1077
+ /**
1078
+ * An audio track bound to the character instance that publishes it.
1079
+ *
1080
+ * In a multi-character room `membershipId` is always set -- a track that
1081
+ * cannot be attributed to a roster member is dropped, never surfaced against
1082
+ * the active character. In a single-character room it is null.
1083
+ */
1084
+ export interface CharacterAudioTrackEvent {
1085
+ membershipId: string | null;
1086
+ characterId: string | null;
1087
+ /** LiveKit participant identity; `character:{membershipId}` in a roster. */
1088
+ participantIdentity: string;
1089
+ track: MediaStreamTrack;
1090
+ }
1091
+ /**
1092
+ * A finalized turn's usage/cost breakdown, streamed by the server after
1093
+ * {@link IConvaiClient.toggleUsageUpdates} enables it. The shape is
1094
+ * server-defined and informational; treat unknown fields as opaque.
1095
+ */
1096
+ export type UsageUpdate = Record<string, unknown>;
1097
+ /**
1098
+ * Every event the client emits, with its payload.
1099
+ *
1100
+ * `on()` is typed against this map, so a listener for a known event gets its
1101
+ * payload inferred instead of `any`. The plain-string signature is kept so
1102
+ * existing callers and dynamic event names keep compiling, which also means a
1103
+ * misspelt literal is not a compile error. Payloads the server defines as
1104
+ * opaque blobs (blendshape frames, metrics, usage) are left as records rather
1105
+ * than guessed at.
1106
+ */
1107
+ export interface ConvaiEventMap {
1108
+ connect: [];
1109
+ connected: [];
1110
+ disconnect: [reason: DisconnectReason | null];
1111
+ disconnected: [];
1112
+ error: [error: unknown];
1113
+ stateChange: [state: ConvaiClientState];
1114
+ botReady: [];
1115
+ characterSessionId: [characterSessionId: string];
1116
+ interactionCreated: [data: InteractionCreated];
1117
+ message: [message: ChatMessage];
1118
+ messagesChange: [messages: ChatMessage[]];
1119
+ userTranscriptionChange: [transcription: string];
1120
+ speakingChange: [isSpeaking: boolean];
1121
+ listeningChange: [isListening: boolean];
1122
+ botRespondingChange: [isResponding: boolean];
1123
+ turnEnd: [turn: {
1124
+ sessionId: number;
1125
+ duration: number;
1126
+ timestamp: number;
1127
+ }];
1128
+ conversationStart: [
1129
+ start: {
1130
+ sessionId: number;
1131
+ userMessage: string;
1132
+ timestamp: number;
1133
+ }
1134
+ ];
1135
+ emotionChange: [emotion: {
1136
+ emotion: string;
1137
+ scale?: number;
1138
+ } | null];
1139
+ actionResponse: [data: ActionResponseEvent];
1140
+ serverResponse: [response: ServerResponse];
1141
+ botOutput: [data: {
1142
+ text: string;
1143
+ spoken: boolean;
1144
+ aggregatedBy: string;
1145
+ }];
1146
+ botTtsText: [data: {
1147
+ text: string;
1148
+ }];
1149
+ botTtsStarted: [];
1150
+ botTtsStopped: [];
1151
+ botTurnCompleted: [data: unknown];
1152
+ userMuteStarted: [];
1153
+ userMuteStopped: [];
1154
+ idleWarning: [data: {
1155
+ remainingSeconds: number | null;
1156
+ }];
1157
+ llmNoResponse: [];
1158
+ metrics: [data: Record<string, unknown>];
1159
+ usageUpdate: [data: UsageUpdate];
1160
+ blendshapes: [data: Record<string, unknown>];
1161
+ blendshapeCancel: [data: Record<string, unknown>];
1162
+ blendshapeStatsReceived: [stats: Record<string, unknown>];
1163
+ botAudioTrack: [track: MediaStreamTrack];
1164
+ audioStateChange: [enabled: boolean];
1165
+ videoStateChange: [enabled: boolean];
1166
+ screenShareStateChange: [active: boolean];
1167
+ characterReady: [instance: ConvaiCharacterInstance | undefined];
1168
+ characterStatus: [status: CharacterStatusEvent];
1169
+ activeCharacterChange: [change: ActiveCharacterChange];
1170
+ rosterChange: [change: CharacterRosterChange];
1171
+ characterAudioTrack: [event: CharacterAudioTrackEvent];
1172
+ actionResultAck: [ack: ActionResultAck];
1173
+ modelOutputProtocolError: [data: ModelOutputProtocolError];
1174
+ modelOutput: [data: ModelOutputMessage];
1175
+ botLlmTextRaw: [data: BotLlmTextRawEvent];
1176
+ }
1177
+ /**
1178
+ * Preserve typed callbacks for known events while permitting callers that
1179
+ * intentionally enumerate runtime event names. A string literal outside the
1180
+ * map resolves to `never`, so misspellings still fail at compile time.
1181
+ */
1182
+ export type ConvaiEventCallback<E extends string> = E extends keyof ConvaiEventMap ? (...args: ConvaiEventMap[E]) => void : string extends E ? (...args: any[]) => void : never;
1183
+ /** A transcript line inserted locally by {@link IConvaiClient.appendMessage}. */
1184
+ export interface AppendMessageOptions {
1185
+ sender: "user" | "bot";
1186
+ content: string;
1187
+ /** Attribute the line to a roster member, in a multi-character room. */
1188
+ membershipId?: string;
1189
+ characterId?: string;
1190
+ }
1191
+ /** Bounded retry for a roster room that is still provisioning. */
1192
+ export interface RosterProvisioningRetry {
1193
+ /** Total attempts including the first. Default 4. */
1194
+ attempts?: number;
1195
+ /** Delay before the second attempt; doubles with jitter. Default 500. */
1196
+ initialDelayMs?: number;
1197
+ }
1198
+ export interface ConnectionData {
1199
+ /** LiveKit room URL, or the WebSocket URL when the transport is websocket. */
1200
+ room_url: string;
1201
+ /** LiveKit access token. Absent on the WebSocket transport. */
1202
+ token?: string;
1203
+ character_session_id?: string;
1204
+ end_user_id?: string;
1205
+ end_user_metadata?: Record<string, unknown>;
1206
+ }
725
1207
  /** Options for connecting to a published text-chat session. */
726
1208
  export interface PublishedChatConnectOptions {
727
1209
  /** Core API origin (defaults to the production realtime API). */
728
1210
  url?: string;
1211
+ /**
1212
+ * WebRTC ICE transport policy (defaults to "relay" for Convai-hosted
1213
+ * LiveKit). Set "all" for a deployment that has no TURN server.
1214
+ */
1215
+ iceTransportPolicy?: RTCIceTransportPolicy;
729
1216
  /** Cancels the grant exchange and tears down an in-progress connection. */
730
1217
  signal?: AbortSignal;
731
1218
  /**
@@ -742,7 +1229,12 @@ export interface ChatMessage {
742
1229
  /** Unique identifier for the message */
743
1230
  id: string;
744
1231
  /**
745
- * Client-owned logical turn id for a correlated v2 voice transcription.
1232
+ * Core-owned identifier for the individual model invocation that produced
1233
+ * this bot row. Absent for legacy sessions and older v2 Core versions.
1234
+ */
1235
+ outputId?: string;
1236
+ /**
1237
+ * Immutable logical turn id for correlated v2 user speech and bot text.
746
1238
  * Absent for legacy sessions and uncorrelated messages.
747
1239
  */
748
1240
  logicalTurnId?: string;
@@ -763,6 +1255,14 @@ export interface ChatMessage {
763
1255
  * - `llm-no-response`: LLM deliberately did not respond (abstain); `content` is always `""`
764
1256
  */
765
1257
  type: 'user' | 'convai' | 'emotion' | 'behavior-tree' | 'action' | 'user-transcription' | 'bot-llm-text' | 'bot-output' | 'bot-emotion' | 'user-llm-text' | 'interrupt-bot' | 'idle-warning' | 'llm-no-response';
1258
+ /**
1259
+ * Which character instance produced this message, in a multi-character room.
1260
+ * Undefined in single-character sessions. Attribute UI to this, never to
1261
+ * `characterId` -- two clones of one character share a `characterId`.
1262
+ */
1263
+ membershipId?: string;
1264
+ /** The authored character behind {@link membershipId}. Not unique across a roster. */
1265
+ characterId?: string;
766
1266
  /** The text content of the message */
767
1267
  content: string;
768
1268
  /** ISO timestamp string of when the message was created */
@@ -868,6 +1368,16 @@ export interface ConvaiClientState {
868
1368
  * @see DisconnectReason
869
1369
  */
870
1370
  disconnectReason: DisconnectReason | null;
1371
+ /**
1372
+ * Character instances in a multi-character room, in roster order. Empty for
1373
+ * single-character sessions, so a check on `length` distinguishes the two.
1374
+ */
1375
+ characters: ConvaiCharacterInstance[];
1376
+ /**
1377
+ * Membership currently receiving user turns, or null. Only this member
1378
+ * consumes interaction input.
1379
+ */
1380
+ activeMembershipId: string | null;
871
1381
  }
872
1382
  /**
873
1383
  * Audio control interface for managing microphone
@@ -885,7 +1395,10 @@ export interface AudioControls {
885
1395
  getAudioDevices: () => Promise<MediaDeviceInfo[]>;
886
1396
  startAudioLevelMonitoring: () => void;
887
1397
  stopAudioLevelMonitoring: () => void;
888
- on: (event: string, callback: (...args: any[]) => void) => () => void;
1398
+ on: {
1399
+ <E extends keyof ConvaiEventMap>(event: E, callback: (...args: ConvaiEventMap[E]) => void): () => void;
1400
+ (event: string, callback: (...args: any[]) => void): () => void;
1401
+ };
889
1402
  off: (event: string, callback: (...args: any[]) => void) => void;
890
1403
  }
891
1404
  /**
@@ -908,7 +1421,10 @@ export interface VideoControls {
908
1421
  publishCanvas: (canvas: HTMLCanvasElement, options?: PublishCanvasOptions) => Promise<VisionSourceHandle>;
909
1422
  publishVideoTrack: (track: MediaStreamTrack, options?: PublishVideoTrackOptions) => Promise<VisionSourceHandle>;
910
1423
  unpublishVisionSource: (source?: VisionSourceHandle | MediaStreamTrack) => Promise<void>;
911
- on: (event: string, callback: (...args: any[]) => void) => () => void;
1424
+ on: {
1425
+ <E extends keyof ConvaiEventMap>(event: E, callback: (...args: ConvaiEventMap[E]) => void): () => void;
1426
+ (event: string, callback: (...args: any[]) => void): () => void;
1427
+ };
912
1428
  off: (event: string, callback: (...args: any[]) => void) => void;
913
1429
  }
914
1430
  /**
@@ -922,7 +1438,10 @@ export interface ScreenShareControls {
922
1438
  toggleScreenShare: () => Promise<void>;
923
1439
  enableScreenShareWithAudio: () => Promise<void>;
924
1440
  getScreenShareTracks: () => Promise<any[]>;
925
- on: (event: string, callback: (...args: any[]) => void) => () => void;
1441
+ on: {
1442
+ <E extends keyof ConvaiEventMap>(event: E, callback: (...args: ConvaiEventMap[E]) => void): () => void;
1443
+ (event: string, callback: (...args: any[]) => void): () => void;
1444
+ };
926
1445
  off: (event: string, callback: (...args: any[]) => void) => void;
927
1446
  }
928
1447
  /**
@@ -956,6 +1475,202 @@ export interface ScreenShareControls {
956
1475
  * });
957
1476
  * ```
958
1477
  */
1478
+ /**
1479
+ * Character Versioning API Types
1480
+ *
1481
+ * Shapes returned by the Character REST platform's `/character/versions/*`
1482
+ * routes. Field names are kept as the API sends them.
1483
+ */
1484
+ /** One immutable, tagged character version. */
1485
+ export interface CharacterVersionInfo {
1486
+ /** Semantic tag, e.g. `"1.2"` or `"1.2.3"` */
1487
+ version: string;
1488
+ /** Immutable revision backing this tag */
1489
+ revision_id: string;
1490
+ /** Whether `latest` currently points at this tag */
1491
+ is_latest: boolean;
1492
+ created_by: string;
1493
+ /** ISO-8601 timestamp */
1494
+ created_at: string;
1495
+ is_deprecated: boolean;
1496
+ /** ISO-8601 timestamp, or null when not deprecated */
1497
+ deprecated_at: string | null;
1498
+ }
1499
+ /** Response from `CharacterVersionManager.list()`. */
1500
+ export interface CharacterVersionList {
1501
+ /** Released versions, newest first as returned by the API */
1502
+ items: CharacterVersionInfo[];
1503
+ /** Revision `latest` resolves to, or null before any release */
1504
+ latest_revision_id: string | null;
1505
+ /** Tag `latest` points at, or null when latest is an unpromoted revision */
1506
+ latest_version: string | null;
1507
+ /** Editable draft revision, or null for a legacy character that has not been bootstrapped */
1508
+ draft_revision_id: string | null;
1509
+ /** Released revision the draft was branched from */
1510
+ draft_parent_revision_id: string | null;
1511
+ draft_parent_version: string | null;
1512
+ /** True when the draft differs from its released parent */
1513
+ has_unpublished_changes: boolean;
1514
+ /** True when `latest` points at a tagged version rather than a loose revision */
1515
+ latest_is_promoted: boolean;
1516
+ }
1517
+ /** Voice details attached to a resolved version when `includeRuntimeSettings` is set. */
1518
+ export interface CharacterRuntimeVoice {
1519
+ voice_value: string;
1520
+ voice_name: string;
1521
+ provider: string;
1522
+ lang_codes: string[] | null;
1523
+ accessibility: string | null;
1524
+ gender: string | null;
1525
+ voice_data: Record<string, unknown> | null;
1526
+ }
1527
+ /** Live (unversioned) runtime settings returned alongside a resolved version. */
1528
+ export interface CharacterRuntimeSettings {
1529
+ schema_version: 1;
1530
+ stt_provider: string | null;
1531
+ voice: CharacterRuntimeVoice | null;
1532
+ }
1533
+ /** Response from `CharacterVersionManager.resolve()`. */
1534
+ export interface ResolvedCharacterVersion {
1535
+ character_id: string;
1536
+ /** The reference that was resolved, e.g. `<uuid>-draft` */
1537
+ requested_reference: string;
1538
+ /** Immutable revision, or null for a legacy character with no revision yet */
1539
+ revision_id: string | null;
1540
+ /** Tag when the reference resolved to a tagged version */
1541
+ version: string | null;
1542
+ is_latest: boolean;
1543
+ /** The full character configuration snapshot */
1544
+ payload: Record<string, unknown>;
1545
+ runtime_settings?: CharacterRuntimeSettings | null;
1546
+ }
1547
+ /** Options for `CharacterVersionManager.resolve()`. */
1548
+ export interface ResolveCharacterVersionOptions {
1549
+ /**
1550
+ * Also return the live voice and STT settings (default: false).
1551
+ * Only a trusted service identity may ask for these; an API key is
1552
+ * answered with `403 Runtime settings require a trusted service identity`.
1553
+ */
1554
+ includeRuntimeSettings?: boolean;
1555
+ }
1556
+ /** Response from `CharacterVersionManager.bootstrap()`. */
1557
+ export interface CharacterDraftBootstrapResult {
1558
+ character_id: string;
1559
+ draft_revision_id: string;
1560
+ /** False when the character already had a draft */
1561
+ created: boolean;
1562
+ }
1563
+ /** One side of a version comparison. */
1564
+ export interface CharacterVersionDiffSide {
1565
+ /** The selector that was compared: `draft`, `latest`, or a tag */
1566
+ selector: string;
1567
+ revision_id: string | null;
1568
+ version: string | null;
1569
+ is_latest: boolean;
1570
+ }
1571
+ /** One field-level change in a raw diff. */
1572
+ export interface CharacterVersionRawChange {
1573
+ /** JSON path into the character payload */
1574
+ path: string;
1575
+ change_type: "added" | "removed" | "modified";
1576
+ before?: unknown;
1577
+ after?: unknown;
1578
+ }
1579
+ /** One human-labelled change in a semantic diff; revertable one at a time. */
1580
+ export interface CharacterVersionSemanticChange {
1581
+ change_id: string;
1582
+ semantic_key: string;
1583
+ label: string;
1584
+ category: string;
1585
+ change_type: "added" | "removed" | "modified";
1586
+ before?: unknown;
1587
+ after?: unknown;
1588
+ source_paths: string[];
1589
+ can_revert: boolean;
1590
+ revert_disabled_reason?: string | null;
1591
+ integrity_warning?: string | null;
1592
+ }
1593
+ /** Response from `CharacterVersionManager.diff()` with `view: "raw"` (the default). */
1594
+ export interface CharacterVersionRawDiff {
1595
+ view?: "raw";
1596
+ character_id: string;
1597
+ from: CharacterVersionDiffSide;
1598
+ to: CharacterVersionDiffSide;
1599
+ change_count: number;
1600
+ changes: CharacterVersionRawChange[];
1601
+ }
1602
+ /** Response from `CharacterVersionManager.diff()` with `view: "semantic"`. */
1603
+ export interface CharacterVersionSemanticDiff {
1604
+ view: "semantic";
1605
+ semantic_schema_version: number;
1606
+ character_id: string;
1607
+ from: CharacterVersionDiffSide;
1608
+ to: CharacterVersionDiffSide;
1609
+ draft_revision_id: string | null;
1610
+ change_count: number;
1611
+ changes: CharacterVersionSemanticChange[];
1612
+ }
1613
+ export type CharacterVersionDiff = CharacterVersionRawDiff | CharacterVersionSemanticDiff;
1614
+ /** Options for `CharacterVersionManager.diff()`. */
1615
+ export interface CharacterVersionDiffOptions {
1616
+ /** `"raw"` lists JSON paths; `"semantic"` groups them into labelled, revertable changes. Default `"raw"`. */
1617
+ view?: "raw" | "semantic";
1618
+ }
1619
+ /** Options for `CharacterVersionManager.create()`. */
1620
+ export interface CreateCharacterVersionOptions {
1621
+ /** Point `latest` at the new version immediately (default: false) */
1622
+ makeLatest?: boolean;
1623
+ }
1624
+ /** Options for `CharacterVersionManager.revert()`. */
1625
+ export interface RevertCharacterChangeOptions {
1626
+ /** Version the draft is being compared against — the change is reverted to this side */
1627
+ from: string;
1628
+ /** `change_id` from a semantic diff */
1629
+ changeId: string;
1630
+ /** Draft revision the caller last saw; the request fails if the draft moved */
1631
+ expectedDraftRevisionId: string;
1632
+ }
1633
+ /** Response from `CharacterVersionManager.revert()`. */
1634
+ export interface RevertCharacterChangeResult {
1635
+ character_id: string;
1636
+ reverted_change_id: string;
1637
+ previous_draft_revision_id: string;
1638
+ /** The new draft revision after the revert */
1639
+ draft_revision_id: string;
1640
+ /** Semantic diff between `from` and the new draft */
1641
+ diff: CharacterVersionSemanticDiff;
1642
+ }
1643
+ /** Response from `CharacterVersionManager.discardDraft()`. */
1644
+ export interface DiscardCharacterDraftResult {
1645
+ character_id: string;
1646
+ previous_draft_revision_id: string;
1647
+ /** The fresh draft, restored from its released parent */
1648
+ draft_revision_id: string;
1649
+ draft_parent_revision_id: string;
1650
+ draft_parent_version: string;
1651
+ }
1652
+ /** Response from `CharacterVersionManager.fork()`. */
1653
+ export interface ForkCharacterVersionResult {
1654
+ character_id: string;
1655
+ /** Tag the draft was replaced with */
1656
+ source_version: string;
1657
+ draft_revision_id: string;
1658
+ latest_revision_id: string | null;
1659
+ has_unpublished_changes: boolean;
1660
+ }
1661
+ /** Options for constructing a `CharacterVersionManager` directly. */
1662
+ export interface CharacterVersionManagerOptions {
1663
+ /** Bare character UUID (a suffixed reference is accepted and stripped) */
1664
+ characterId: string;
1665
+ /** Convai API key, sent as `CONVAI-API-KEY` */
1666
+ apiKey?: string;
1667
+ /** Convai personal access token, sent as `Authorization: Bearer` (alternative to `apiKey`) */
1668
+ personalAccessToken?: string;
1669
+ /** Character REST platform origin (default: `https://api2.convai.com`) */
1670
+ baseUrl?: string;
1671
+ /** Workspace scope, forwarded as `workspace_id` on every call */
1672
+ workspaceId?: string;
1673
+ }
959
1674
  /**
960
1675
  * Memory API Types
961
1676
  * Types for Convai's long-term memory management APIs
@@ -1110,8 +1825,12 @@ export interface IConvaiClient {
1110
1825
  readonly apiKey?: string | null;
1111
1826
  /** Auth token used for the current connection, if authToken was used (null otherwise) */
1112
1827
  readonly authToken?: string | null;
1113
- /** Character ID used for the current connection (null if not connected) */
1828
+ /** Bare character UUID used for the current connection (null if not connected) */
1114
1829
  readonly characterId: string | null;
1830
+ /** Version selector in effect for the current connection (`draft`, `latest`, or a tag); null when unversioned or not connected */
1831
+ readonly characterVersion: CharacterVersionSelector | null;
1832
+ /** The reference sent to the runtime: `characterId` joined with `characterVersion` (null if not connected) */
1833
+ readonly characterReference: string | null;
1115
1834
  /** Internal LiveKit Room instance (for advanced usage) */
1116
1835
  readonly room: Room;
1117
1836
  /** Array of all chat messages in the current conversation */
@@ -1147,22 +1866,150 @@ export interface IConvaiClient {
1147
1866
  * ```
1148
1867
  */
1149
1868
  readonly memoryManager: import('./MemoryManager.js').MemoryManager | null;
1869
+ /**
1870
+ * Character version manager for the configured character.
1871
+ *
1872
+ * Lists, compares, releases, promotes and discards character versions
1873
+ * through the Character REST platform. Available as soon as the client has
1874
+ * an `apiKey` and `characterId` — before connecting, so an app can pick a
1875
+ * version and then connect to it. Null without an API key.
1876
+ *
1877
+ * @example
1878
+ * ```typescript
1879
+ * const versions = client.characterVersions;
1880
+ * if (versions) {
1881
+ * const { items, draft_revision_id } = await versions.list();
1882
+ * await versions.create('1.0', { makeLatest: true });
1883
+ * }
1884
+ * ```
1885
+ */
1886
+ readonly characterVersions: import('./CharacterVersionManager.js').CharacterVersionManager | null;
1150
1887
  /**
1151
1888
  * Connect to a Convai character.
1152
1889
  */
1153
1890
  connect: (config?: ConvaiConfig) => Promise<void>;
1154
- /** Connect to a published text chat with a short-lived, single-use grant. */
1891
+ /**
1892
+ * Connect to a published text chat with a short-lived, single-use grant.
1893
+ *
1894
+ * Obtain the grant from the public publication endpoint immediately before
1895
+ * connecting. This path needs no API key or character ID in the browser and
1896
+ * creates a data-only, text-chat session. Request a fresh grant for every
1897
+ * later session or reconnect attempt.
1898
+ *
1899
+ * @example
1900
+ * ```ts
1901
+ * import { ConvaiClient } from '@convai/web-sdk/core'
1902
+ * import { requestPublishedChatGrant } from '@convai/web-sdk/embed'
1903
+ *
1904
+ * const client = new ConvaiClient()
1905
+ * const launchToken = await requestPublishedChatGrant(
1906
+ * 'https://character-api.example.com/chat-publications/PUBLICATION_ID/launch-grants',
1907
+ * )
1908
+ * await client.connectWithPublicationGrant(launchToken, {
1909
+ * url: 'https://realtime.example.com',
1910
+ * })
1911
+ * ```
1912
+ */
1155
1913
  connectWithPublicationGrant?: (launchToken: string, options?: PublishedChatConnectOptions) => Promise<void>;
1914
+ /**
1915
+ * Complete a connection from an already-fetched /connect response body.
1916
+ *
1917
+ * `connect()` fetches /connect and then calls this internally. Call it
1918
+ * directly when the response was obtained elsewhere — a server-side session
1919
+ * manager, or the embed's connect-proxy flow, where the API key must never
1920
+ * reach the browser.
1921
+ *
1922
+ * @example
1923
+ * // Server (customer's backend): holds the API key, calls Convai's
1924
+ * // /connect, and relays the response body verbatim.
1925
+ * // Browser: never sees the API key, only the relayed response.
1926
+ * const data = await fetch('/api/convai-connect', {
1927
+ * method: 'POST',
1928
+ * headers: { 'Content-Type': 'application/json' },
1929
+ * body: JSON.stringify({ characterId: 'your-character-id' }),
1930
+ * }).then(r => r.json())
1931
+ * await client.connectWithConnectionData(data)
1932
+ */
1933
+ connectWithConnectionData: (data: ConnectionData, config?: ConvaiConfig) => Promise<void>;
1934
+ /**
1935
+ * Join an existing multi-character room by `roomSessionId` or
1936
+ * `sharedSessionKey`. The roster is server-owned, so no character topology is
1937
+ * sent; joining never spawns, removes or repairs a character.
1938
+ *
1939
+ * @example
1940
+ * ```ts
1941
+ * await client.joinRoom({ roomSessionId: 'the-room-id', endUserId: 'player-99' })
1942
+ * ```
1943
+ */
1944
+ joinRoom: (options: JoinRoomOptions) => Promise<void>;
1945
+ /** Server-owned snapshot of a multi-character room (null when single-character) */
1946
+ readonly roomSession: ConvaiRoomSession | null;
1947
+ /** Character instances in roster order; empty for a single-character session */
1948
+ readonly characters: ConvaiCharacterInstance[];
1949
+ /** Membership currently receiving user turns, or null */
1950
+ readonly activeMembershipId: string | null;
1951
+ /**
1952
+ * Insert a message into the transcript locally, without sending it to the
1953
+ * character. Use it for client-side lines -- a greeting, a system notice,
1954
+ * replayed history -- that must appear in the chat but must never reach
1955
+ * the LLM or be billed as a turn. Not `sendUserTextMessage`: nothing is
1956
+ * transmitted. Returns the message that was added.
1957
+ *
1958
+ * @example
1959
+ * ```ts
1960
+ * client.appendMessage({ sender: 'bot', content: 'Welcome back!' })
1961
+ * ```
1962
+ */
1963
+ appendMessage: (message: AppendMessageOptions) => ChatMessage;
1964
+ /**
1965
+ * Opt in or out of `usageUpdate` events -- the server's per-turn usage and
1966
+ * cost breakdown. Informational only; billing is unaffected.
1967
+ *
1968
+ * @example
1969
+ * ```ts
1970
+ * client.toggleUsageUpdates(true)
1971
+ * client.on('usageUpdate', (u) => console.log(u))
1972
+ * ```
1973
+ */
1974
+ toggleUsageUpdates: (enabled: boolean) => void;
1975
+ /**
1976
+ * Route subsequent user turns to a different character instance. Pass null to
1977
+ * close every input gate so no member hears the user.
1978
+ *
1979
+ * Resolves on the server's acknowledgement. Retries once against the
1980
+ * server's authoritative epoch when another participant switched first.
1981
+ *
1982
+ * @example
1983
+ * ```ts
1984
+ * await client.setInteractionTarget(assessor.membershipId)
1985
+ * client.sendUserTextMessage('Now grade me.')
1986
+ * ```
1987
+ */
1988
+ setInteractionTarget: (membershipId: string | null) => Promise<ActiveCharacterChange>;
1989
+ /**
1990
+ * Add or remove character instances on a live room, without reconnecting.
1991
+ *
1992
+ * @example
1993
+ * ```ts
1994
+ * await client.updateCharacterRoster({ add: [{ characterId: NARRATOR }] })
1995
+ * ```
1996
+ */
1997
+ updateCharacterRoster: (options: UpdateCharacterRosterOptions) => Promise<CharacterRosterChange>;
1156
1998
  /** Disconnect from the current character session */
1157
1999
  disconnect: () => Promise<void>;
1158
2000
  /** Reconnect - disconnect and connect again using stored config */
1159
2001
  reconnect: () => Promise<void>;
1160
2002
  /** Reset the session ID to start a new conversation (clears history) */
1161
2003
  resetSession: () => void;
1162
- /** Send a text message to the character, optionally with a v2 turn id. */
2004
+ /** Send a text message to the character */
1163
2005
  sendUserTextMessage: (text: string, options?: SendUserTextMessageOptions) => void;
1164
2006
  /** Return a correlated terminal result for a v2 client tool call. */
1165
2007
  sendActionResult: (result: ActionResult) => void;
2008
+ /**
2009
+ * Publish one correlated terminal result and wait for Core's matching
2010
+ * `server-response` acknowledgement.
2011
+ */
2012
+ sendActionResultAndWait: (result: ActionResult, options?: ActionResultAckOptions) => Promise<ActionResultAck>;
1166
2013
  /**
1167
2014
  * Send a trigger message to invoke specific character actions or responses.
1168
2015
  * @param triggerName - Name of the trigger to invoke
@@ -1291,12 +2138,12 @@ export interface IConvaiClient {
1291
2138
  * @param callback Callback function
1292
2139
  * @returns Unsubscribe function
1293
2140
  */
1294
- on: (event: string, callback: (...args: any[]) => void) => () => void;
2141
+ on: <E extends string>(event: E, callback: ConvaiEventCallback<E>) => () => void;
1295
2142
  /**
1296
2143
  * Unsubscribe from an event
1297
2144
  * @param event Event name
1298
2145
  * @param callback Callback function to remove
1299
2146
  */
1300
- off: (event: string, callback: (...args: any[]) => void) => void;
2147
+ off: <E extends string>(event: E, callback: ConvaiEventCallback<E>) => void;
1301
2148
  }
1302
2149
  //# sourceMappingURL=types.d.ts.map