@convai/web-sdk 1.8.0-beta.4 → 1.8.0-beta.6

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 (68) hide show
  1. package/README.md +64 -3
  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 +109 -1
  11. package/dist/core/ConvaiClient.d.ts.map +1 -1
  12. package/dist/core/ConvaiClient.js +642 -49
  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 +14 -0
  19. package/dist/core/MessageHandler.d.ts.map +1 -1
  20. package/dist/core/MessageHandler.js +111 -5
  21. package/dist/core/MessageHandler.js.map +1 -1
  22. package/dist/core/SSESession.d.ts +15 -0
  23. package/dist/core/SSESession.d.ts.map +1 -1
  24. package/dist/core/SSESession.js +92 -3
  25. package/dist/core/SSESession.js.map +1 -1
  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 +1 -0
  31. package/dist/core/connectRequest.d.ts.map +1 -1
  32. package/dist/core/connectRequest.js +11 -0
  33. package/dist/core/connectRequest.js.map +1 -1
  34. package/dist/core/index.d.ts +5 -0
  35. package/dist/core/index.d.ts.map +1 -1
  36. package/dist/core/index.js +6 -0
  37. package/dist/core/index.js.map +1 -1
  38. package/dist/core/rosterRequest.d.ts +57 -0
  39. package/dist/core/rosterRequest.d.ts.map +1 -0
  40. package/dist/core/rosterRequest.js +210 -0
  41. package/dist/core/rosterRequest.js.map +1 -0
  42. package/dist/core/types.d.ts +717 -7
  43. package/dist/core/types.d.ts.map +1 -1
  44. package/dist/core/types.js.map +1 -1
  45. package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts.map +1 -1
  46. package/dist/react/components/rtc-widget/components/MarkdownRenderer.js +39 -44
  47. package/dist/react/components/rtc-widget/components/MarkdownRenderer.js.map +1 -1
  48. package/dist/react/hooks/useConvaiClient.d.ts.map +1 -1
  49. package/dist/react/hooks/useConvaiClient.js +15 -2
  50. package/dist/react/hooks/useConvaiClient.js.map +1 -1
  51. package/dist/utils/inlineMarkdown.d.ts +38 -0
  52. package/dist/utils/inlineMarkdown.d.ts.map +1 -0
  53. package/dist/utils/inlineMarkdown.js +106 -0
  54. package/dist/utils/inlineMarkdown.js.map +1 -0
  55. package/dist/vanilla/AudioRenderer.d.ts.map +1 -1
  56. package/dist/vanilla/AudioRenderer.js +6 -0
  57. package/dist/vanilla/AudioRenderer.js.map +1 -1
  58. package/dist/vanilla/ConvaiWidget.d.ts.map +1 -1
  59. package/dist/vanilla/ConvaiWidget.js +71 -57
  60. package/dist/vanilla/ConvaiWidget.js.map +1 -1
  61. package/dist/vanilla/index.d.ts +2 -0
  62. package/dist/vanilla/index.d.ts.map +1 -1
  63. package/dist/vanilla/index.js +2 -0
  64. package/dist/vanilla/index.js.map +1 -1
  65. package/dist/version.d.ts +1 -1
  66. package/dist/version.js +1 -1
  67. package/dist/version.js.map +1 -1
  68. package/package.json +1 -1
@@ -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.
@@ -113,6 +115,17 @@ export interface ServerResponseExtras {
113
115
  has_speak_tag?: boolean;
114
116
  text?: string;
115
117
  room_name?: string;
118
+ command_id?: string;
119
+ room_session_id?: string;
120
+ previous_membership_id?: string | null;
121
+ active_membership_id?: string | null;
122
+ previous_active_membership_id?: string | null;
123
+ route_epoch?: number;
124
+ roster_epoch?: number;
125
+ changed?: boolean;
126
+ added?: unknown[];
127
+ removed_membership_ids?: string[];
128
+ code?: string;
116
129
  supported_types?: string[];
117
130
  vision_buffer?: VisionBufferStatus;
118
131
  requested_respond_mode?: RespondMode;
@@ -265,6 +278,11 @@ export interface RespondModesConfig {
265
278
  trigger?: RespondMode;
266
279
  sceneMetadata?: RespondMode;
267
280
  }
281
+ /** Client-requested action/model output protocol versions. */
282
+ export interface ActionProtocolCapabilities {
283
+ actionProtocolVersion: 1 | 2;
284
+ modelOutputVersion?: 1 | 2;
285
+ }
268
286
  export interface VisionSamplingWindowConfig {
269
287
  count: number;
270
288
  intervalMs: number;
@@ -394,8 +412,101 @@ export interface ConvaiConfig {
394
412
  /** Your Convai API key or Auth Token (at least one is required) */
395
413
  apiKey?: string;
396
414
  authToken?: string;
397
- /** The Character ID to connect to (required) */
398
- characterId: string;
415
+ /**
416
+ * The Character ID to connect to (required).
417
+ *
418
+ * May also carry a version selector suffix (`<uuid>-draft`, `<uuid>-latest`,
419
+ * `<uuid>-1.2`); `characterVersion` is the clearer way to say the same thing.
420
+ *
421
+ * Optional only because a multi-character room supplies `characters`
422
+ * instead. Exactly one of the two is required, and a version selector is not
423
+ * accepted inside a roster entry.
424
+ */
425
+ characterId?: string;
426
+ /**
427
+ * Which version of the character to run (optional).
428
+ *
429
+ * - `"draft"` — the editable draft, so you can test unreleased changes
430
+ * - `"latest"` — the promoted latest release
431
+ * - `"1.2"` / `"1.2.3"` — an immutable tagged version
432
+ *
433
+ * Omit it to let the runtime pick the effective latest revision, which is
434
+ * also how characters that predate versioning behave. The selector is joined
435
+ * to `characterId` on the wire as `<uuid>-<selector>`; `client.characterId`
436
+ * keeps returning the bare UUID.
437
+ *
438
+ * @example
439
+ * ```ts
440
+ * const client = new ConvaiClient({
441
+ * apiKey: 'YOUR_API_KEY',
442
+ * characterId: 'YOUR_CHARACTER_ID',
443
+ * characterVersion: 'draft',
444
+ * });
445
+ * ```
446
+ */
447
+ characterVersion?: CharacterVersionSelector | null;
448
+ /**
449
+ * Base URL of the Character REST platform used by `client.characterVersions`
450
+ * (optional, defaults to `https://api2.convai.com`). Point it at
451
+ * `https://api2-stg.convai.com` to author against staging.
452
+ */
453
+ characterApiUrl?: string;
454
+ /**
455
+ * Ordered roster of character instances for a multi-character room. Pass this
456
+ * *instead of* `characterId` -- exactly one of the two is valid.
457
+ *
458
+ * Every entry becomes a distinct membership with its own actor, LiveKit
459
+ * participant, voice, history and lifecycle. The same `characterId` may
460
+ * appear more than once; each copy is an independent clone addressed by its
461
+ * own `membershipId`. `characters[0]` is the initial active member.
462
+ *
463
+ * Roster rooms require the LiveKit transport, a nonblank `endUserId`, and the
464
+ * `MULTI_CHARACTER_V0` entitlement on the publisher.
465
+ *
466
+ * @example
467
+ * ```ts
468
+ * const client = new ConvaiClient({
469
+ * apiKey: 'YOUR_API_KEY',
470
+ * endUserId: 'player-42',
471
+ * characters: [
472
+ * { characterId: GUIDE }, // initial active member
473
+ * { characterId: ASSESSOR },
474
+ * { characterId: GUIDE }, // a second, independent copy of GUIDE
475
+ * ],
476
+ * });
477
+ * ```
478
+ */
479
+ characters?: ConvaiCharacterSpec[];
480
+ /**
481
+ * Publisher-scoped room grouping and topology key (1-128 chars of letters,
482
+ * digits, hyphen or underscore). A matching create request reuses the
483
+ * existing room; reusing the key with a different ordered roster, creator or
484
+ * capacity is rejected with `ROSTER_FINGERPRINT_MISMATCH`. Reordering the
485
+ * same characters counts as different, because it changes the initial member.
486
+ *
487
+ * This does not raise human capacity on its own -- see `maxNumParticipants`.
488
+ */
489
+ sharedSessionKey?: string;
490
+ /**
491
+ * Idempotency key for one logical connect (1-128 chars, same charset as
492
+ * `sharedSessionKey`). Reuse it only when retrying with an identical payload:
493
+ * within the replay window a completed attempt returns its original response
494
+ * and token, while a changed payload or a still-running original is rejected.
495
+ */
496
+ connectAttemptId?: string;
497
+ /**
498
+ * Maximum number of distinct human speakers in a roster room. Characters do
499
+ * not count toward it. Defaults to the server's value of 1, which admits no
500
+ * second human -- raise it before expecting `joinRoom()` to succeed.
501
+ */
502
+ maxNumParticipants?: number;
503
+ /**
504
+ * Bounded retry when a roster room is still provisioning (409
505
+ * `ROSTER_PROVISIONING_IN_PROGRESS`). Defaults to four attempts starting at
506
+ * 500ms and doubling with jitter. Pass `false` to surface the error instead
507
+ * and retry in application code.
508
+ */
509
+ rosterProvisioningRetry?: RosterProvisioningRetry | false;
399
510
  /** Temporary character state of mind sent as `state_of_mind` on connect. */
400
511
  stateOfMind?: string | null;
401
512
  /**
@@ -455,6 +566,13 @@ export interface ConvaiConfig {
455
566
  visionInputConfig?: VisionInputConfig;
456
567
  /** Connect-time respond-mode defaults by modality. */
457
568
  respondModes?: RespondModesConfig;
569
+ /** Client-requested action/model output protocol versions. */
570
+ capabilities?: ActionProtocolCapabilities;
571
+ /** Descriptive objects visible in the scene at connection time. */
572
+ sceneDescription?: Array<{
573
+ name: string;
574
+ description: string;
575
+ }>;
458
576
  /**
459
577
  * WebRTC ICE transport policy for the LiveKit connection (default: "relay").
460
578
  * "relay" forces TURN-only (reliable against Convai's hosted LiveKit which
@@ -564,6 +682,12 @@ export interface ConvaiConfig {
564
682
  /** Object description or properties */
565
683
  description: string;
566
684
  }>;
685
+ /** Client-executed tools negotiated by action protocol v2. */
686
+ tools?: Array<{
687
+ name: string;
688
+ description: string;
689
+ inputSchema: Record<string, unknown>;
690
+ }>;
567
691
  /** Name of the object the character is currently focused on. Must match one of objects[].name. */
568
692
  current_attention_object?: string;
569
693
  };
@@ -617,6 +741,37 @@ export interface ConvaiConfig {
617
741
  * Enable debug mode for additional logging and diagnostics (default: false).
618
742
  */
619
743
  debug?: boolean;
744
+ /** Optional per-session response lifecycle contract override. */
745
+ useResponseLifecycleContract?: boolean;
746
+ /**
747
+ * Keep links in the character's text output (default: server-side, currently off).
748
+ *
749
+ * Core-service flattens the LLM's markdown before streaming `bot-llm-text`,
750
+ * which also drops link targets: `[Doc](https://…/a.pdf)` reaches the client
751
+ * as `Doc`. With this on, the session preserves `[text](url)`, `![alt](url)`
752
+ * and bare `http(s)://` URLs verbatim (trailing sentence punctuation stays
753
+ * outside the URL, non-http(s) schemes are still stripped) while bold,
754
+ * headings, tables and code are flattened as before. Speech is unaffected —
755
+ * URLs are never read aloud.
756
+ *
757
+ * Both widgets render the preserved form as clickable links, with inline
758
+ * previews for image and video URLs. If you render `chatMessages` yourself,
759
+ * expect markdown links in `content` once this is on.
760
+ *
761
+ * Sent as `preserve_links_in_output` on `/connect`; omitted when undefined so
762
+ * the server's own default applies. If you build the `/connect` request
763
+ * server-side for `connectWithConnectionData()`, add the field there.
764
+ *
765
+ * @example
766
+ * ```typescript
767
+ * const client = new ConvaiClient({
768
+ * apiKey: 'your-api-key',
769
+ * characterId: 'your-character-id',
770
+ * preserveLinksInOutput: true,
771
+ * });
772
+ * ```
773
+ */
774
+ preserveLinksInOutput?: boolean;
620
775
  /**
621
776
  * Log decoded RTVI data messages to the browser console (default: true).
622
777
  * Set to false to silence incoming and outgoing RTVI message logs.
@@ -641,11 +796,254 @@ export interface SendUserTextMessageOptions {
641
796
  logicalTurnId?: string;
642
797
  /** User-selected temporary emotion to apply before processing the text. */
643
798
  stateOfMind?: string | null;
799
+ /** Latest request-scoped dynamic context to include in this same interaction. */
800
+ dynamicInfo?: DynamicInfo;
644
801
  }
645
802
  /**
646
803
  * The body returned by POST /connect. The embed receives this from a
647
804
  * customer-hosted proxy route rather than fetching it directly.
648
805
  */
806
+ /**
807
+ * One ordered character instance requested for a multi-character room.
808
+ *
809
+ * Repeating a `characterId` is legal and intentional: each entry becomes an
810
+ * independent clone with its own membership, session, participant and voice.
811
+ */
812
+ export interface ConvaiCharacterSpec {
813
+ /**
814
+ * Bare character UUID. Version selectors (`<uuid>-draft`, `<uuid>-1.2`) are
815
+ * accepted by single-character `characterId` but rejected inside a roster --
816
+ * the runtime types roster entries as plain UUIDs.
817
+ */
818
+ characterId: string;
819
+ /**
820
+ * Resume this instance's prior conversation history. Must be unique across
821
+ * the roster, and must belong to the same publisher, speaker and character.
822
+ */
823
+ characterSessionId?: string;
824
+ }
825
+ /**
826
+ * Dispatch state of one roster member, as reported by `/connect`.
827
+ *
828
+ * These describe provisioning only and never readiness. A member becomes
829
+ * usable when its own `bot-ready` arrives -- `dispatch_accepted` is not
830
+ * `bot-ready`. The union deliberately has no member that could be mistaken for
831
+ * a ready state; the separate `character-status` event carries those.
832
+ */
833
+ export type CharacterProvisioningStatus = "dispatch_queued" | "dispatch_accepted" | "dispatch_failed";
834
+ /** One concrete character instance in a roster room. */
835
+ export interface ConvaiCharacterInstance {
836
+ /** Primary key for this instance. Address members by this, never by `characterId`. */
837
+ membershipId: string;
838
+ /** The authored character this instance runs. Not unique across a roster. */
839
+ characterId: string;
840
+ /** Backend session for support correlation. */
841
+ sessionId: string | null;
842
+ /** This instance's conversation/history session. */
843
+ characterSessionId: string | null;
844
+ /** Stable LiveKit identity, always `character:{membershipId}`. */
845
+ participantIdentity: string;
846
+ /** True for `characters[0]`, the initially active member. */
847
+ isInitial: boolean;
848
+ provisioningStatus: CharacterProvisioningStatus;
849
+ /**
850
+ * The character's display name, when the runtime sends one. Saves a separate
851
+ * `character/get` call just to label a member in the UI. Undocumented in the
852
+ * published contract but returned by the live API, so treat it as optional.
853
+ */
854
+ displayName: string | null;
855
+ /** Character description, when the runtime sends one. */
856
+ description: string | null;
857
+ /** Populated when `provisioningStatus` is `dispatch_failed`. */
858
+ failureCode: string | null;
859
+ /** True once this member's own `bot-ready` has arrived. */
860
+ isReady: boolean;
861
+ }
862
+ /**
863
+ * Server-owned snapshot of a multi-character room. Null for single-character
864
+ * sessions.
865
+ */
866
+ export interface ConvaiRoomSession {
867
+ /** Durable room identity. Use it to join, and to correlate with support. */
868
+ roomSessionId: string;
869
+ roomName: string | null;
870
+ /** Trace id of the `/connect` that produced this room. Quote it in bug reports. */
871
+ requestTraceId: string | null;
872
+ /** Membership currently authorised to consume user turns. */
873
+ activeMembershipId: string | null;
874
+ /** Monotonic version of the active target; fences target switches. */
875
+ routeEpoch: number;
876
+ /** Monotonic version of roster composition; fences add/remove. */
877
+ rosterEpoch: number;
878
+ /** True when at least one member already failed dispatch. */
879
+ partialDispatch: boolean;
880
+ characters: ConvaiCharacterInstance[];
881
+ }
882
+ /** Result of a successful target switch. */
883
+ export interface ActiveCharacterChange {
884
+ /** Membership that was active before, or null. */
885
+ previous: string | null;
886
+ /** Membership now authorised to consume user turns, or null when all gates are closed. */
887
+ active: string | null;
888
+ routeEpoch: number;
889
+ }
890
+ /** Result of a successful roster mutation. */
891
+ export interface CharacterRosterChange {
892
+ added: ConvaiCharacterInstance[];
893
+ removed: ConvaiCharacterInstance[];
894
+ /** The roster after the change. */
895
+ characters: ConvaiCharacterInstance[];
896
+ rosterEpoch: number;
897
+ routeEpoch: number;
898
+ activeMembershipId: string | null;
899
+ }
900
+ /** Options for adding and removing roster members on a live room. */
901
+ export interface UpdateCharacterRosterOptions {
902
+ /** Members to add. Repeating an existing characterId creates another clone. */
903
+ add?: ConvaiCharacterSpec[];
904
+ /** Membership ids to remove. Never characterIds -- clones make those ambiguous. */
905
+ remove?: string[];
906
+ /**
907
+ * Member to take over routing when the active one is removed. Must be a ready
908
+ * member that survives the change. Chosen automatically when omitted.
909
+ */
910
+ replacementTarget?: string;
911
+ }
912
+ /** Options for joining an existing multi-character room. */
913
+ export interface JoinRoomOptions {
914
+ /** Preferred locator. Exactly one of this or `sharedSessionKey`. */
915
+ roomSessionId?: string;
916
+ /** Publisher-scoped alternative locator. */
917
+ sharedSessionKey?: string;
918
+ /** Required and nonblank; identifies the joining human. */
919
+ endUserId: string;
920
+ endUserMetadata?: Record<string, unknown>;
921
+ /** Idempotency key for retrying this join. */
922
+ connectAttemptId?: string;
923
+ }
924
+ /**
925
+ * Lifecycle transition of one roster member, after `/connect` has returned.
926
+ *
927
+ * `bot-ready` remains the readiness authority: do not enable interaction from a
928
+ * `ready` status alone. This event's real job is reporting a member that was
929
+ * added at runtime, or one whose dispatch failed in the background.
930
+ */
931
+ export interface CharacterStatusEvent {
932
+ status: "starting" | "ready" | "failed";
933
+ membershipId: string;
934
+ characterId: string;
935
+ characterSessionId: string | null;
936
+ participantIdentity: string;
937
+ roomSessionId: string | null;
938
+ rosterEpoch: number | null;
939
+ /** Set when `status` is `failed`, e.g. `ACTOR_ASSIGNMENT_FAILED`. */
940
+ failureCode: string | null;
941
+ }
942
+ /**
943
+ * An audio track bound to the character instance that publishes it.
944
+ *
945
+ * In a multi-character room `membershipId` is always set -- a track that
946
+ * cannot be attributed to a roster member is dropped, never surfaced against
947
+ * the active character. In a single-character room it is null.
948
+ */
949
+ export interface CharacterAudioTrackEvent {
950
+ membershipId: string | null;
951
+ characterId: string | null;
952
+ /** LiveKit participant identity; `character:{membershipId}` in a roster. */
953
+ participantIdentity: string;
954
+ track: MediaStreamTrack;
955
+ }
956
+ /**
957
+ * A finalized turn's usage/cost breakdown, streamed by the server after
958
+ * {@link IConvaiClient.toggleUsageUpdates} enables it. The shape is
959
+ * server-defined and informational; treat unknown fields as opaque.
960
+ */
961
+ export type UsageUpdate = Record<string, unknown>;
962
+ /**
963
+ * Every event the client emits, with its payload.
964
+ *
965
+ * `on()` is typed against this map, so a misspelt event name or a listener
966
+ * with the wrong signature fails to compile. Payloads the server defines as
967
+ * opaque blobs (blendshape frames, metrics, usage) are left as records rather
968
+ * than guessed at.
969
+ */
970
+ export interface ConvaiEventMap {
971
+ connect: [];
972
+ connected: [];
973
+ disconnect: [reason: DisconnectReason | null];
974
+ disconnected: [];
975
+ error: [error: unknown];
976
+ stateChange: [state: ConvaiClientState];
977
+ botReady: [];
978
+ characterSessionId: [characterSessionId: string];
979
+ interactionCreated: [data: InteractionCreated];
980
+ message: [message: ChatMessage];
981
+ messagesChange: [messages: ChatMessage[]];
982
+ userTranscriptionChange: [transcription: string];
983
+ speakingChange: [isSpeaking: boolean];
984
+ listeningChange: [isListening: boolean];
985
+ botRespondingChange: [isResponding: boolean];
986
+ turnEnd: [turn: {
987
+ sessionId: number;
988
+ duration: number;
989
+ timestamp: number;
990
+ }];
991
+ conversationStart: [
992
+ start: {
993
+ sessionId: number;
994
+ userMessage: string;
995
+ timestamp: number;
996
+ }
997
+ ];
998
+ emotionChange: [emotion: {
999
+ emotion: string;
1000
+ scale?: number;
1001
+ } | null];
1002
+ actionResponse: [data: ActionResponseEvent];
1003
+ serverResponse: [response: ServerResponse];
1004
+ botOutput: [data: Record<string, unknown>];
1005
+ botTtsText: [data: {
1006
+ text: string;
1007
+ }];
1008
+ botTtsStarted: [];
1009
+ botTtsStopped: [];
1010
+ botTurnCompleted: [data: unknown];
1011
+ userMuteStarted: [];
1012
+ userMuteStopped: [];
1013
+ idleWarning: [data: {
1014
+ remainingSeconds: number | null;
1015
+ }];
1016
+ llmNoResponse: [];
1017
+ metrics: [data: Record<string, unknown>];
1018
+ usageUpdate: [data: UsageUpdate];
1019
+ blendshapes: [data: Record<string, unknown>];
1020
+ blendshapeCancel: [data: Record<string, unknown>];
1021
+ blendshapeStatsReceived: [stats: Record<string, unknown>];
1022
+ botAudioTrack: [track: MediaStreamTrack];
1023
+ audioStateChange: [enabled: boolean];
1024
+ videoStateChange: [enabled: boolean];
1025
+ screenShareStateChange: [active: boolean];
1026
+ characterReady: [instance: ConvaiCharacterInstance | undefined];
1027
+ characterStatus: [status: CharacterStatusEvent];
1028
+ activeCharacterChange: [change: ActiveCharacterChange];
1029
+ rosterChange: [change: CharacterRosterChange];
1030
+ characterAudioTrack: [event: CharacterAudioTrackEvent];
1031
+ }
1032
+ /** A transcript line inserted locally by {@link IConvaiClient.appendMessage}. */
1033
+ export interface AppendMessageOptions {
1034
+ sender: "user" | "bot";
1035
+ content: string;
1036
+ /** Attribute the line to a roster member, in a multi-character room. */
1037
+ membershipId?: string;
1038
+ characterId?: string;
1039
+ }
1040
+ /** Bounded retry for a roster room that is still provisioning. */
1041
+ export interface RosterProvisioningRetry {
1042
+ /** Total attempts including the first. Default 4. */
1043
+ attempts?: number;
1044
+ /** Delay before the second attempt; doubles with jitter. Default 500. */
1045
+ initialDelayMs?: number;
1046
+ }
649
1047
  export interface ConnectionData {
650
1048
  /** LiveKit room URL, or the WebSocket URL when the transport is websocket. */
651
1049
  room_url: string;
@@ -679,6 +1077,14 @@ export interface ChatMessage {
679
1077
  * - `llm-no-response`: LLM deliberately did not respond (abstain); `content` is always `""`
680
1078
  */
681
1079
  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';
1080
+ /**
1081
+ * Which character instance produced this message, in a multi-character room.
1082
+ * Undefined in single-character sessions. Attribute UI to this, never to
1083
+ * `characterId` -- two clones of one character share a `characterId`.
1084
+ */
1085
+ membershipId?: string;
1086
+ /** The authored character behind {@link membershipId}. Not unique across a roster. */
1087
+ characterId?: string;
682
1088
  /** The text content of the message */
683
1089
  content: string;
684
1090
  /** ISO timestamp string of when the message was created */
@@ -784,6 +1190,16 @@ export interface ConvaiClientState {
784
1190
  * @see DisconnectReason
785
1191
  */
786
1192
  disconnectReason: DisconnectReason | null;
1193
+ /**
1194
+ * Character instances in a multi-character room, in roster order. Empty for
1195
+ * single-character sessions, so a check on `length` distinguishes the two.
1196
+ */
1197
+ characters: ConvaiCharacterInstance[];
1198
+ /**
1199
+ * Membership currently receiving user turns, or null. Only this member
1200
+ * consumes interaction input.
1201
+ */
1202
+ activeMembershipId: string | null;
787
1203
  }
788
1204
  /**
789
1205
  * Audio control interface for managing microphone
@@ -801,7 +1217,10 @@ export interface AudioControls {
801
1217
  getAudioDevices: () => Promise<MediaDeviceInfo[]>;
802
1218
  startAudioLevelMonitoring: () => void;
803
1219
  stopAudioLevelMonitoring: () => void;
804
- on: (event: string, callback: (...args: any[]) => void) => () => void;
1220
+ on: {
1221
+ <E extends keyof ConvaiEventMap>(event: E, callback: (...args: ConvaiEventMap[E]) => void): () => void;
1222
+ (event: string, callback: (...args: any[]) => void): () => void;
1223
+ };
805
1224
  off: (event: string, callback: (...args: any[]) => void) => void;
806
1225
  }
807
1226
  /**
@@ -824,7 +1243,10 @@ export interface VideoControls {
824
1243
  publishCanvas: (canvas: HTMLCanvasElement, options?: PublishCanvasOptions) => Promise<VisionSourceHandle>;
825
1244
  publishVideoTrack: (track: MediaStreamTrack, options?: PublishVideoTrackOptions) => Promise<VisionSourceHandle>;
826
1245
  unpublishVisionSource: (source?: VisionSourceHandle | MediaStreamTrack) => Promise<void>;
827
- on: (event: string, callback: (...args: any[]) => void) => () => void;
1246
+ on: {
1247
+ <E extends keyof ConvaiEventMap>(event: E, callback: (...args: ConvaiEventMap[E]) => void): () => void;
1248
+ (event: string, callback: (...args: any[]) => void): () => void;
1249
+ };
828
1250
  off: (event: string, callback: (...args: any[]) => void) => void;
829
1251
  }
830
1252
  /**
@@ -838,7 +1260,10 @@ export interface ScreenShareControls {
838
1260
  toggleScreenShare: () => Promise<void>;
839
1261
  enableScreenShareWithAudio: () => Promise<void>;
840
1262
  getScreenShareTracks: () => Promise<any[]>;
841
- on: (event: string, callback: (...args: any[]) => void) => () => void;
1263
+ on: {
1264
+ <E extends keyof ConvaiEventMap>(event: E, callback: (...args: ConvaiEventMap[E]) => void): () => void;
1265
+ (event: string, callback: (...args: any[]) => void): () => void;
1266
+ };
842
1267
  off: (event: string, callback: (...args: any[]) => void) => void;
843
1268
  }
844
1269
  /**
@@ -872,6 +1297,202 @@ export interface ScreenShareControls {
872
1297
  * });
873
1298
  * ```
874
1299
  */
1300
+ /**
1301
+ * Character Versioning API Types
1302
+ *
1303
+ * Shapes returned by the Character REST platform's `/character/versions/*`
1304
+ * routes. Field names are kept as the API sends them.
1305
+ */
1306
+ /** One immutable, tagged character version. */
1307
+ export interface CharacterVersionInfo {
1308
+ /** Semantic tag, e.g. `"1.2"` or `"1.2.3"` */
1309
+ version: string;
1310
+ /** Immutable revision backing this tag */
1311
+ revision_id: string;
1312
+ /** Whether `latest` currently points at this tag */
1313
+ is_latest: boolean;
1314
+ created_by: string;
1315
+ /** ISO-8601 timestamp */
1316
+ created_at: string;
1317
+ is_deprecated: boolean;
1318
+ /** ISO-8601 timestamp, or null when not deprecated */
1319
+ deprecated_at: string | null;
1320
+ }
1321
+ /** Response from `CharacterVersionManager.list()`. */
1322
+ export interface CharacterVersionList {
1323
+ /** Released versions, newest first as returned by the API */
1324
+ items: CharacterVersionInfo[];
1325
+ /** Revision `latest` resolves to, or null before any release */
1326
+ latest_revision_id: string | null;
1327
+ /** Tag `latest` points at, or null when latest is an unpromoted revision */
1328
+ latest_version: string | null;
1329
+ /** Editable draft revision, or null for a legacy character that has not been bootstrapped */
1330
+ draft_revision_id: string | null;
1331
+ /** Released revision the draft was branched from */
1332
+ draft_parent_revision_id: string | null;
1333
+ draft_parent_version: string | null;
1334
+ /** True when the draft differs from its released parent */
1335
+ has_unpublished_changes: boolean;
1336
+ /** True when `latest` points at a tagged version rather than a loose revision */
1337
+ latest_is_promoted: boolean;
1338
+ }
1339
+ /** Voice details attached to a resolved version when `includeRuntimeSettings` is set. */
1340
+ export interface CharacterRuntimeVoice {
1341
+ voice_value: string;
1342
+ voice_name: string;
1343
+ provider: string;
1344
+ lang_codes: string[] | null;
1345
+ accessibility: string | null;
1346
+ gender: string | null;
1347
+ voice_data: Record<string, unknown> | null;
1348
+ }
1349
+ /** Live (unversioned) runtime settings returned alongside a resolved version. */
1350
+ export interface CharacterRuntimeSettings {
1351
+ schema_version: 1;
1352
+ stt_provider: string | null;
1353
+ voice: CharacterRuntimeVoice | null;
1354
+ }
1355
+ /** Response from `CharacterVersionManager.resolve()`. */
1356
+ export interface ResolvedCharacterVersion {
1357
+ character_id: string;
1358
+ /** The reference that was resolved, e.g. `<uuid>-draft` */
1359
+ requested_reference: string;
1360
+ /** Immutable revision, or null for a legacy character with no revision yet */
1361
+ revision_id: string | null;
1362
+ /** Tag when the reference resolved to a tagged version */
1363
+ version: string | null;
1364
+ is_latest: boolean;
1365
+ /** The full character configuration snapshot */
1366
+ payload: Record<string, unknown>;
1367
+ runtime_settings?: CharacterRuntimeSettings | null;
1368
+ }
1369
+ /** Options for `CharacterVersionManager.resolve()`. */
1370
+ export interface ResolveCharacterVersionOptions {
1371
+ /**
1372
+ * Also return the live voice and STT settings (default: false).
1373
+ * Only a trusted service identity may ask for these; an API key is
1374
+ * answered with `403 Runtime settings require a trusted service identity`.
1375
+ */
1376
+ includeRuntimeSettings?: boolean;
1377
+ }
1378
+ /** Response from `CharacterVersionManager.bootstrap()`. */
1379
+ export interface CharacterDraftBootstrapResult {
1380
+ character_id: string;
1381
+ draft_revision_id: string;
1382
+ /** False when the character already had a draft */
1383
+ created: boolean;
1384
+ }
1385
+ /** One side of a version comparison. */
1386
+ export interface CharacterVersionDiffSide {
1387
+ /** The selector that was compared: `draft`, `latest`, or a tag */
1388
+ selector: string;
1389
+ revision_id: string | null;
1390
+ version: string | null;
1391
+ is_latest: boolean;
1392
+ }
1393
+ /** One field-level change in a raw diff. */
1394
+ export interface CharacterVersionRawChange {
1395
+ /** JSON path into the character payload */
1396
+ path: string;
1397
+ change_type: "added" | "removed" | "modified";
1398
+ before?: unknown;
1399
+ after?: unknown;
1400
+ }
1401
+ /** One human-labelled change in a semantic diff; revertable one at a time. */
1402
+ export interface CharacterVersionSemanticChange {
1403
+ change_id: string;
1404
+ semantic_key: string;
1405
+ label: string;
1406
+ category: string;
1407
+ change_type: "added" | "removed" | "modified";
1408
+ before?: unknown;
1409
+ after?: unknown;
1410
+ source_paths: string[];
1411
+ can_revert: boolean;
1412
+ revert_disabled_reason?: string | null;
1413
+ integrity_warning?: string | null;
1414
+ }
1415
+ /** Response from `CharacterVersionManager.diff()` with `view: "raw"` (the default). */
1416
+ export interface CharacterVersionRawDiff {
1417
+ view?: "raw";
1418
+ character_id: string;
1419
+ from: CharacterVersionDiffSide;
1420
+ to: CharacterVersionDiffSide;
1421
+ change_count: number;
1422
+ changes: CharacterVersionRawChange[];
1423
+ }
1424
+ /** Response from `CharacterVersionManager.diff()` with `view: "semantic"`. */
1425
+ export interface CharacterVersionSemanticDiff {
1426
+ view: "semantic";
1427
+ semantic_schema_version: number;
1428
+ character_id: string;
1429
+ from: CharacterVersionDiffSide;
1430
+ to: CharacterVersionDiffSide;
1431
+ draft_revision_id: string | null;
1432
+ change_count: number;
1433
+ changes: CharacterVersionSemanticChange[];
1434
+ }
1435
+ export type CharacterVersionDiff = CharacterVersionRawDiff | CharacterVersionSemanticDiff;
1436
+ /** Options for `CharacterVersionManager.diff()`. */
1437
+ export interface CharacterVersionDiffOptions {
1438
+ /** `"raw"` lists JSON paths; `"semantic"` groups them into labelled, revertable changes. Default `"raw"`. */
1439
+ view?: "raw" | "semantic";
1440
+ }
1441
+ /** Options for `CharacterVersionManager.create()`. */
1442
+ export interface CreateCharacterVersionOptions {
1443
+ /** Point `latest` at the new version immediately (default: false) */
1444
+ makeLatest?: boolean;
1445
+ }
1446
+ /** Options for `CharacterVersionManager.revert()`. */
1447
+ export interface RevertCharacterChangeOptions {
1448
+ /** Version the draft is being compared against — the change is reverted to this side */
1449
+ from: string;
1450
+ /** `change_id` from a semantic diff */
1451
+ changeId: string;
1452
+ /** Draft revision the caller last saw; the request fails if the draft moved */
1453
+ expectedDraftRevisionId: string;
1454
+ }
1455
+ /** Response from `CharacterVersionManager.revert()`. */
1456
+ export interface RevertCharacterChangeResult {
1457
+ character_id: string;
1458
+ reverted_change_id: string;
1459
+ previous_draft_revision_id: string;
1460
+ /** The new draft revision after the revert */
1461
+ draft_revision_id: string;
1462
+ /** Semantic diff between `from` and the new draft */
1463
+ diff: CharacterVersionSemanticDiff;
1464
+ }
1465
+ /** Response from `CharacterVersionManager.discardDraft()`. */
1466
+ export interface DiscardCharacterDraftResult {
1467
+ character_id: string;
1468
+ previous_draft_revision_id: string;
1469
+ /** The fresh draft, restored from its released parent */
1470
+ draft_revision_id: string;
1471
+ draft_parent_revision_id: string;
1472
+ draft_parent_version: string;
1473
+ }
1474
+ /** Response from `CharacterVersionManager.fork()`. */
1475
+ export interface ForkCharacterVersionResult {
1476
+ character_id: string;
1477
+ /** Tag the draft was replaced with */
1478
+ source_version: string;
1479
+ draft_revision_id: string;
1480
+ latest_revision_id: string | null;
1481
+ has_unpublished_changes: boolean;
1482
+ }
1483
+ /** Options for constructing a `CharacterVersionManager` directly. */
1484
+ export interface CharacterVersionManagerOptions {
1485
+ /** Bare character UUID (a suffixed reference is accepted and stripped) */
1486
+ characterId: string;
1487
+ /** Convai API key, sent as `CONVAI-API-KEY` */
1488
+ apiKey?: string;
1489
+ /** Convai personal access token, sent as `Authorization: Bearer` (alternative to `apiKey`) */
1490
+ personalAccessToken?: string;
1491
+ /** Character REST platform origin (default: `https://api2.convai.com`) */
1492
+ baseUrl?: string;
1493
+ /** Workspace scope, forwarded as `workspace_id` on every call */
1494
+ workspaceId?: string;
1495
+ }
875
1496
  /**
876
1497
  * Memory API Types
877
1498
  * Types for Convai's long-term memory management APIs
@@ -1024,8 +1645,12 @@ export interface IConvaiClient {
1024
1645
  readonly apiKey?: string | null;
1025
1646
  /** Auth token used for the current connection, if authToken was used (null otherwise) */
1026
1647
  readonly authToken?: string | null;
1027
- /** Character ID used for the current connection (null if not connected) */
1648
+ /** Bare character UUID used for the current connection (null if not connected) */
1028
1649
  readonly characterId: string | null;
1650
+ /** Version selector in effect for the current connection (`draft`, `latest`, or a tag); null when unversioned or not connected */
1651
+ readonly characterVersion: CharacterVersionSelector | null;
1652
+ /** The reference sent to the runtime: `characterId` joined with `characterVersion` (null if not connected) */
1653
+ readonly characterReference: string | null;
1029
1654
  /** Internal LiveKit Room instance (for advanced usage) */
1030
1655
  readonly room: Room;
1031
1656
  /** Array of all chat messages in the current conversation */
@@ -1059,6 +1684,24 @@ export interface IConvaiClient {
1059
1684
  * ```
1060
1685
  */
1061
1686
  readonly memoryManager: import('./MemoryManager.js').MemoryManager | null;
1687
+ /**
1688
+ * Character version manager for the configured character.
1689
+ *
1690
+ * Lists, compares, releases, promotes and discards character versions
1691
+ * through the Character REST platform. Available as soon as the client has
1692
+ * an `apiKey` and `characterId` — before connecting, so an app can pick a
1693
+ * version and then connect to it. Null without an API key.
1694
+ *
1695
+ * @example
1696
+ * ```typescript
1697
+ * const versions = client.characterVersions;
1698
+ * if (versions) {
1699
+ * const { items, draft_revision_id } = await versions.list();
1700
+ * await versions.create('1.0', { makeLatest: true });
1701
+ * }
1702
+ * ```
1703
+ */
1704
+ readonly characterVersions: import('./CharacterVersionManager.js').CharacterVersionManager | null;
1062
1705
  /**
1063
1706
  * Connect to a Convai character.
1064
1707
  */
@@ -1083,6 +1726,70 @@ export interface IConvaiClient {
1083
1726
  * await client.connectWithConnectionData(data)
1084
1727
  */
1085
1728
  connectWithConnectionData: (data: ConnectionData, config?: ConvaiConfig) => Promise<void>;
1729
+ /**
1730
+ * Join an existing multi-character room by `roomSessionId` or
1731
+ * `sharedSessionKey`. The roster is server-owned, so no character topology is
1732
+ * sent; joining never spawns, removes or repairs a character.
1733
+ *
1734
+ * @example
1735
+ * ```ts
1736
+ * await client.joinRoom({ roomSessionId: 'the-room-id', endUserId: 'player-99' })
1737
+ * ```
1738
+ */
1739
+ joinRoom: (options: JoinRoomOptions) => Promise<void>;
1740
+ /** Server-owned snapshot of a multi-character room (null when single-character) */
1741
+ readonly roomSession: ConvaiRoomSession | null;
1742
+ /** Character instances in roster order; empty for a single-character session */
1743
+ readonly characters: ConvaiCharacterInstance[];
1744
+ /** Membership currently receiving user turns, or null */
1745
+ readonly activeMembershipId: string | null;
1746
+ /**
1747
+ * Insert a message into the transcript locally, without sending it to the
1748
+ * character. Use it for client-side lines -- a greeting, a system notice,
1749
+ * replayed history -- that must appear in the chat but must never reach
1750
+ * the LLM or be billed as a turn. Not `sendUserTextMessage`: nothing is
1751
+ * transmitted. Returns the message that was added.
1752
+ *
1753
+ * @example
1754
+ * ```ts
1755
+ * client.appendMessage({ sender: 'bot', content: 'Welcome back!' })
1756
+ * ```
1757
+ */
1758
+ appendMessage: (message: AppendMessageOptions) => ChatMessage;
1759
+ /**
1760
+ * Opt in or out of `usageUpdate` events -- the server's per-turn usage and
1761
+ * cost breakdown. Informational only; billing is unaffected.
1762
+ *
1763
+ * @example
1764
+ * ```ts
1765
+ * client.toggleUsageUpdates(true)
1766
+ * client.on('usageUpdate', (u) => console.log(u))
1767
+ * ```
1768
+ */
1769
+ toggleUsageUpdates: (enabled: boolean) => void;
1770
+ /**
1771
+ * Route subsequent user turns to a different character instance. Pass null to
1772
+ * close every input gate so no member hears the user.
1773
+ *
1774
+ * Resolves on the server's acknowledgement. Retries once against the
1775
+ * server's authoritative epoch when another participant switched first.
1776
+ *
1777
+ * @example
1778
+ * ```ts
1779
+ * await client.setInteractionTarget(assessor.membershipId)
1780
+ * client.sendUserTextMessage('Now grade me.')
1781
+ * ```
1782
+ */
1783
+ setInteractionTarget: (membershipId: string | null) => Promise<ActiveCharacterChange>;
1784
+ /**
1785
+ * Add or remove character instances on a live room, without reconnecting.
1786
+ *
1787
+ * @example
1788
+ * ```ts
1789
+ * await client.updateCharacterRoster({ add: [{ characterId: NARRATOR }] })
1790
+ * ```
1791
+ */
1792
+ updateCharacterRoster: (options: UpdateCharacterRosterOptions) => Promise<CharacterRosterChange>;
1086
1793
  /** Disconnect from the current character session */
1087
1794
  disconnect: () => Promise<void>;
1088
1795
  /** Reconnect - disconnect and connect again using stored config */
@@ -1219,7 +1926,10 @@ export interface IConvaiClient {
1219
1926
  * @param callback Callback function
1220
1927
  * @returns Unsubscribe function
1221
1928
  */
1222
- on: (event: string, callback: (...args: any[]) => void) => () => void;
1929
+ on: {
1930
+ <E extends keyof ConvaiEventMap>(event: E, callback: (...args: ConvaiEventMap[E]) => void): () => void;
1931
+ (event: string, callback: (...args: any[]) => void): () => void;
1932
+ };
1223
1933
  /**
1224
1934
  * Unsubscribe from an event
1225
1935
  * @param event Event name