@convai/web-sdk 1.8.0-beta.5 → 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.
- package/README.md +49 -13
- package/dist/core/CharacterRoster.d.ts +84 -0
- package/dist/core/CharacterRoster.d.ts.map +1 -0
- package/dist/core/CharacterRoster.js +348 -0
- package/dist/core/CharacterRoster.js.map +1 -0
- package/dist/core/ConvaiClient.d.ts +94 -1
- package/dist/core/ConvaiClient.d.ts.map +1 -1
- package/dist/core/ConvaiClient.js +583 -47
- package/dist/core/ConvaiClient.js.map +1 -1
- package/dist/core/ConvaiRoomError.d.ts +48 -0
- package/dist/core/ConvaiRoomError.d.ts.map +1 -0
- package/dist/core/ConvaiRoomError.js +111 -0
- package/dist/core/ConvaiRoomError.js.map +1 -0
- package/dist/core/MessageHandler.d.ts +14 -0
- package/dist/core/MessageHandler.d.ts.map +1 -1
- package/dist/core/MessageHandler.js +111 -5
- package/dist/core/MessageHandler.js.map +1 -1
- package/dist/core/SSESession.d.ts +15 -0
- package/dist/core/SSESession.d.ts.map +1 -1
- package/dist/core/SSESession.js +92 -3
- package/dist/core/SSESession.js.map +1 -1
- package/dist/core/connectRequest.d.ts +1 -0
- package/dist/core/connectRequest.d.ts.map +1 -1
- package/dist/core/connectRequest.js +11 -0
- package/dist/core/connectRequest.js.map +1 -1
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +3 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/rosterRequest.d.ts +57 -0
- package/dist/core/rosterRequest.d.ts.map +1 -0
- package/dist/core/rosterRequest.js +210 -0
- package/dist/core/rosterRequest.js.map +1 -0
- package/dist/core/types.d.ts +462 -5
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts.map +1 -1
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.js +39 -44
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.js.map +1 -1
- package/dist/react/hooks/useConvaiClient.d.ts.map +1 -1
- package/dist/react/hooks/useConvaiClient.js +8 -0
- package/dist/react/hooks/useConvaiClient.js.map +1 -1
- package/dist/utils/inlineMarkdown.d.ts +38 -0
- package/dist/utils/inlineMarkdown.d.ts.map +1 -0
- package/dist/utils/inlineMarkdown.js +106 -0
- package/dist/utils/inlineMarkdown.js.map +1 -0
- package/dist/vanilla/AudioRenderer.d.ts.map +1 -1
- package/dist/vanilla/AudioRenderer.js +6 -0
- package/dist/vanilla/AudioRenderer.js.map +1 -1
- package/dist/vanilla/ConvaiWidget.d.ts.map +1 -1
- package/dist/vanilla/ConvaiWidget.js +71 -57
- package/dist/vanilla/ConvaiWidget.js.map +1 -1
- package/dist/vanilla/index.d.ts +1 -0
- package/dist/vanilla/index.d.ts.map +1 -1
- package/dist/vanilla/index.js +1 -0
- package/dist/vanilla/index.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +1 -1
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAGrD,YAAY,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGvE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MA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AC;AAG9B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAG5E,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/core/index.js
CHANGED
|
@@ -10,6 +10,9 @@ export { VideoManager } from './VideoManager.js';
|
|
|
10
10
|
export { ScreenShareManager } from './ScreenShareManager.js';
|
|
11
11
|
export { MessageHandler } from './MessageHandler.js';
|
|
12
12
|
export { MemoryManager } from './MemoryManager.js';
|
|
13
|
+
export { CharacterRoster } from './CharacterRoster.js';
|
|
14
|
+
export { ConvaiRoomError } from './ConvaiRoomError.js';
|
|
15
|
+
export { MULTI_CHARACTER_MAX_CHARACTERS, isRosterConfig, } from './rosterRequest.js';
|
|
13
16
|
export { CharacterVersionManager, CharacterApiError, DEFAULT_CHARACTER_API_URL, } from './CharacterVersionManager.js';
|
|
14
17
|
// Character reference helpers (version selectors)
|
|
15
18
|
export { parseCharacterReference, resolveCharacterReference, isCharacterVersionSelector, isCharacterUuid, } from './characterReference.js';
|
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,4CAA4C;AAC5C,cAAc,SAAS,CAAC;AAExB,mBAAmB;AACnB,OAAO,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAKrD,gCAAgC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;AAEnC,kDAAkD;AAClD,OAAO,EACL,uBAAuB,EACvB,yBAAyB,EACzB,0BAA0B,EAC1B,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAE9B,+BAA+B;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,qCAAqC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["// Main client\nexport { ConvaiClient } from './ConvaiClient';\n\n// Types (including IConvaiClient interface)\nexport * from './types';\n\n// Helper functions\nexport { getDisconnectReasonMessage } from './types';\n\n// Type alias for easier usage\nexport type { ConvaiClient as ConvaiClientType } from './ConvaiClient';\n\n// Managers (for advanced usage)\nexport { AudioManager } from './AudioManager';\nexport { VideoManager } from './VideoManager';\nexport { ScreenShareManager } from './ScreenShareManager';\nexport { MessageHandler } from './MessageHandler';\nexport { MemoryManager } from './MemoryManager';\nexport {\n CharacterVersionManager,\n CharacterApiError,\n DEFAULT_CHARACTER_API_URL,\n} from './CharacterVersionManager';\n\n// Character reference helpers (version selectors)\nexport {\n parseCharacterReference,\n resolveCharacterReference,\n isCharacterVersionSelector,\n isCharacterUuid,\n} from './characterReference';\n\n// Blendshape queue for lipsync\nexport { BlendshapeQueue } from './BlendshapeQueue';\nexport type { TurnStats, BlendshapeChunkMetadata } from './BlendshapeQueue';\n\n// Event Emitter (for advanced usage)\nexport { EventEmitter } from './EventEmitter';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,4CAA4C;AAC5C,cAAc,SAAS,CAAC;AAExB,mBAAmB;AACnB,OAAO,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAKrD,gCAAgC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EACL,8BAA8B,EAC9B,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;AAEnC,kDAAkD;AAClD,OAAO,EACL,uBAAuB,EACvB,yBAAyB,EACzB,0BAA0B,EAC1B,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAE9B,+BAA+B;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,qCAAqC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["// Main client\nexport { ConvaiClient } from './ConvaiClient';\n\n// Types (including IConvaiClient interface)\nexport * from './types';\n\n// Helper functions\nexport { getDisconnectReasonMessage } from './types';\n\n// Type alias for easier usage\nexport type { ConvaiClient as ConvaiClientType } from './ConvaiClient';\n\n// Managers (for advanced usage)\nexport { AudioManager } from './AudioManager';\nexport { VideoManager } from './VideoManager';\nexport { ScreenShareManager } from './ScreenShareManager';\nexport { MessageHandler } from './MessageHandler';\nexport { MemoryManager } from './MemoryManager';\nexport { CharacterRoster } from './CharacterRoster';\nexport { ConvaiRoomError } from './ConvaiRoomError';\nexport {\n MULTI_CHARACTER_MAX_CHARACTERS,\n isRosterConfig,\n} from './rosterRequest';\nexport {\n CharacterVersionManager,\n CharacterApiError,\n DEFAULT_CHARACTER_API_URL,\n} from './CharacterVersionManager';\n\n// Character reference helpers (version selectors)\nexport {\n parseCharacterReference,\n resolveCharacterReference,\n isCharacterVersionSelector,\n isCharacterUuid,\n} from './characterReference';\n\n// Blendshape queue for lipsync\nexport { BlendshapeQueue } from './BlendshapeQueue';\nexport type { TurnStats, BlendshapeChunkMetadata } from './BlendshapeQueue';\n\n// Event Emitter (for advanced usage)\nexport { EventEmitter } from './EventEmitter';\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ConvaiConfig, JoinRoomOptions } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Validation and request-body construction for multi-character rooms.
|
|
4
|
+
*
|
|
5
|
+
* Pure: no transport, no client state. Every rule below runs before a request
|
|
6
|
+
* is built, so an illegal topology costs nothing and reports the rule it broke
|
|
7
|
+
* rather than a 422 from the runtime.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Server-wide roster cap. Checked client-side only to fail fast with a clear
|
|
11
|
+
* message — the server stays authoritative, and a plan may configure a lower
|
|
12
|
+
* `max_characters` that surfaces as 403 `MULTI_CHARACTER_ROSTER_LIMIT_EXCEEDED`.
|
|
13
|
+
* This is an operational limit, not a protocol maximum, so it must not leak
|
|
14
|
+
* into any public type.
|
|
15
|
+
*/
|
|
16
|
+
export declare const MULTI_CHARACTER_MAX_CHARACTERS = 50;
|
|
17
|
+
/** True when this config asks for a multi-character room. */
|
|
18
|
+
export declare function isRosterConfig(config: Pick<ConvaiConfig, "characters">): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Validate a roster create config.
|
|
21
|
+
*
|
|
22
|
+
* Throws on the first broken rule. Ordered so the most structural problems
|
|
23
|
+
* (which topology did you mean?) report before the detail ones.
|
|
24
|
+
*/
|
|
25
|
+
export declare function validateRosterConfig(config: ConvaiConfig): void;
|
|
26
|
+
/**
|
|
27
|
+
* Reject a config that negotiates v2 output protocols alongside room options
|
|
28
|
+
* the runtime cannot combine them with.
|
|
29
|
+
*
|
|
30
|
+
* Verified against staging 2026-09-08: `capabilities.actionProtocolVersion: 2`
|
|
31
|
+
* or `modelOutputVersion: 2` is answered with 422
|
|
32
|
+
* `unsupported_action_protocol_topology` / `unsupported_model_output_topology`
|
|
33
|
+
* unless the request uses `mode='create'`, a singular `characterId`, no
|
|
34
|
+
* `sharedSessionKey`, and `maxNumParticipants` of 1. Version 1 carries no such
|
|
35
|
+
* constraint.
|
|
36
|
+
*
|
|
37
|
+
* The published contract mentions only the multi-character half of this. The
|
|
38
|
+
* `sharedSessionKey` and `maxNumParticipants` constraints bite in
|
|
39
|
+
* single-character sessions too, which is why this runs on every connect
|
|
40
|
+
* rather than only the roster path.
|
|
41
|
+
*/
|
|
42
|
+
export declare function validateProtocolTopology(config: ConvaiConfig): void;
|
|
43
|
+
/** Validate join options. */
|
|
44
|
+
export declare function validateJoinOptions(options: JoinRoomOptions): void;
|
|
45
|
+
/**
|
|
46
|
+
* The roster half of a create request. Merged into the existing single-character
|
|
47
|
+
* body by the caller, so every current option (blendshape, TTS/STT, dynamic
|
|
48
|
+
* info, action, scene, VAD, vision) continues to apply to every member.
|
|
49
|
+
*/
|
|
50
|
+
export declare function buildRosterConnectFields(config: ConvaiConfig): Record<string, unknown>;
|
|
51
|
+
/**
|
|
52
|
+
* The complete join request body. A join carries a locator and the human, and
|
|
53
|
+
* nothing else — the roster is loaded from persisted room state, and resending
|
|
54
|
+
* topology is rejected.
|
|
55
|
+
*/
|
|
56
|
+
export declare function buildJoinRequestBody(options: JoinRoomOptions): Record<string, unknown>;
|
|
57
|
+
//# sourceMappingURL=rosterRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rosterRequest.d.ts","sourceRoot":"","sources":["../../src/core/rosterRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,YAAY,EACZ,eAAe,EAChB,MAAM,SAAS,CAAC;AAGjB;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,8BAA8B,KAAK,CAAC;AAKjD,6DAA6D;AAC7D,wBAAgB,cAAc,CAC5B,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,GACvC,OAAO,CAET;AAeD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CA8E/D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CA+BnE;AAED,6BAA6B;AAC7B,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,CAuBlE;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,YAAY,GACnB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA0BzB;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,eAAe,GACvB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAezB"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { isCharacterUuid } from "./characterReference.js";
|
|
2
|
+
/**
|
|
3
|
+
* Validation and request-body construction for multi-character rooms.
|
|
4
|
+
*
|
|
5
|
+
* Pure: no transport, no client state. Every rule below runs before a request
|
|
6
|
+
* is built, so an illegal topology costs nothing and reports the rule it broke
|
|
7
|
+
* rather than a 422 from the runtime.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Server-wide roster cap. Checked client-side only to fail fast with a clear
|
|
11
|
+
* message — the server stays authoritative, and a plan may configure a lower
|
|
12
|
+
* `max_characters` that surfaces as 403 `MULTI_CHARACTER_ROSTER_LIMIT_EXCEEDED`.
|
|
13
|
+
* This is an operational limit, not a protocol maximum, so it must not leak
|
|
14
|
+
* into any public type.
|
|
15
|
+
*/
|
|
16
|
+
export const MULTI_CHARACTER_MAX_CHARACTERS = 50;
|
|
17
|
+
/** `shared_session_key` and `connect_attempt_id` share one charset. */
|
|
18
|
+
const KEY_PATTERN = /^[A-Za-z0-9_-]{1,128}$/;
|
|
19
|
+
/** True when this config asks for a multi-character room. */
|
|
20
|
+
export function isRosterConfig(config) {
|
|
21
|
+
return Array.isArray(config.characters) && config.characters.length > 0;
|
|
22
|
+
}
|
|
23
|
+
function assertKey(value, field) {
|
|
24
|
+
if (value === undefined)
|
|
25
|
+
return;
|
|
26
|
+
if (!KEY_PATTERN.test(value)) {
|
|
27
|
+
throw new Error(`${field} must be 1-128 characters of letters, digits, hyphen or underscore`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function nonblank(value) {
|
|
31
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Validate a roster create config.
|
|
35
|
+
*
|
|
36
|
+
* Throws on the first broken rule. Ordered so the most structural problems
|
|
37
|
+
* (which topology did you mean?) report before the detail ones.
|
|
38
|
+
*/
|
|
39
|
+
export function validateRosterConfig(config) {
|
|
40
|
+
const characters = config.characters ?? [];
|
|
41
|
+
if (config.characterId) {
|
|
42
|
+
throw new Error("Pass either characterId or characters, not both");
|
|
43
|
+
}
|
|
44
|
+
if (characters.length === 0) {
|
|
45
|
+
throw new Error("characters must contain at least one entry");
|
|
46
|
+
}
|
|
47
|
+
if (characters.length > MULTI_CHARACTER_MAX_CHARACTERS) {
|
|
48
|
+
throw new Error(`characters accepts at most ${MULTI_CHARACTER_MAX_CHARACTERS} entries; ` +
|
|
49
|
+
`your plan may allow fewer`);
|
|
50
|
+
}
|
|
51
|
+
const seenSessions = new Set();
|
|
52
|
+
characters.forEach((spec, index) => {
|
|
53
|
+
if (!spec || !nonblank(spec.characterId)) {
|
|
54
|
+
throw new Error(`characters[${index}] requires a characterId`);
|
|
55
|
+
}
|
|
56
|
+
// A roster entry is typed as a bare UUID on the runtime. The version
|
|
57
|
+
// selectors that single-character `characterId` has accepted since
|
|
58
|
+
// 1.8.0-beta.5 are a 422 here, and the failure would otherwise only show
|
|
59
|
+
// up as an opaque validation error from the server.
|
|
60
|
+
if (!isCharacterUuid(spec.characterId.trim())) {
|
|
61
|
+
throw new Error(`characters[${index}].characterId must be a bare character UUID; ` +
|
|
62
|
+
`version selectors are not supported inside a roster`);
|
|
63
|
+
}
|
|
64
|
+
if (spec.characterSessionId !== undefined) {
|
|
65
|
+
if (!nonblank(spec.characterSessionId)) {
|
|
66
|
+
throw new Error(`characters[${index}].characterSessionId must be nonblank when supplied`);
|
|
67
|
+
}
|
|
68
|
+
if (seenSessions.has(spec.characterSessionId)) {
|
|
69
|
+
throw new Error(`characters[${index}].characterSessionId is repeated; resume ids must be unique within the roster`);
|
|
70
|
+
}
|
|
71
|
+
seenSessions.add(spec.characterSessionId);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
if (config.characterSessionId) {
|
|
75
|
+
throw new Error("characterSessionId is not valid with characters; use characters[].characterSessionId");
|
|
76
|
+
}
|
|
77
|
+
if (!nonblank(config.endUserId)) {
|
|
78
|
+
throw new Error("characters requires a nonblank endUserId");
|
|
79
|
+
}
|
|
80
|
+
if (config.transport && config.transport !== "livekit") {
|
|
81
|
+
throw new Error("Multi-character rooms require the LiveKit transport");
|
|
82
|
+
}
|
|
83
|
+
if (config.interactionApiUrl) {
|
|
84
|
+
throw new Error("Multi-character rooms require the LiveKit transport; interactionApiUrl selects SSE");
|
|
85
|
+
}
|
|
86
|
+
if (config.characterVersion) {
|
|
87
|
+
throw new Error("characterVersion applies to a single character; roster entries take bare UUIDs");
|
|
88
|
+
}
|
|
89
|
+
assertKey(config.sharedSessionKey, "sharedSessionKey");
|
|
90
|
+
assertKey(config.connectAttemptId, "connectAttemptId");
|
|
91
|
+
if (config.maxNumParticipants !== undefined &&
|
|
92
|
+
(!Number.isInteger(config.maxNumParticipants) ||
|
|
93
|
+
config.maxNumParticipants < 1)) {
|
|
94
|
+
throw new Error("maxNumParticipants must be a positive integer");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Reject a config that negotiates v2 output protocols alongside room options
|
|
99
|
+
* the runtime cannot combine them with.
|
|
100
|
+
*
|
|
101
|
+
* Verified against staging 2026-09-08: `capabilities.actionProtocolVersion: 2`
|
|
102
|
+
* or `modelOutputVersion: 2` is answered with 422
|
|
103
|
+
* `unsupported_action_protocol_topology` / `unsupported_model_output_topology`
|
|
104
|
+
* unless the request uses `mode='create'`, a singular `characterId`, no
|
|
105
|
+
* `sharedSessionKey`, and `maxNumParticipants` of 1. Version 1 carries no such
|
|
106
|
+
* constraint.
|
|
107
|
+
*
|
|
108
|
+
* The published contract mentions only the multi-character half of this. The
|
|
109
|
+
* `sharedSessionKey` and `maxNumParticipants` constraints bite in
|
|
110
|
+
* single-character sessions too, which is why this runs on every connect
|
|
111
|
+
* rather than only the roster path.
|
|
112
|
+
*/
|
|
113
|
+
export function validateProtocolTopology(config) {
|
|
114
|
+
const negotiatesV2 = config.capabilities?.actionProtocolVersion === 2 ||
|
|
115
|
+
config.capabilities?.modelOutputVersion === 2;
|
|
116
|
+
if (!negotiatesV2) {
|
|
117
|
+
// Tools need v2, so without it they are refused whatever the topology.
|
|
118
|
+
if (config.actionConfig?.tools?.length) {
|
|
119
|
+
throw new Error("actionConfig.tools requires capabilities.actionProtocolVersion: 2");
|
|
120
|
+
}
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const offenders = [];
|
|
124
|
+
if (isRosterConfig(config))
|
|
125
|
+
offenders.push("characters");
|
|
126
|
+
if (config.sharedSessionKey)
|
|
127
|
+
offenders.push("sharedSessionKey");
|
|
128
|
+
if (config.maxNumParticipants !== undefined && config.maxNumParticipants !== 1) {
|
|
129
|
+
offenders.push("maxNumParticipants greater than 1");
|
|
130
|
+
}
|
|
131
|
+
if (offenders.length === 0)
|
|
132
|
+
return;
|
|
133
|
+
throw new Error(`Negotiated v2 output protocols require a single-character room: ` +
|
|
134
|
+
`remove ${offenders.join(", ")}, or drop capabilities to version 1. ` +
|
|
135
|
+
(offenders.includes("characters")
|
|
136
|
+
? "Multi-character rooms cannot use action protocol v2, and therefore cannot use client tools. "
|
|
137
|
+
: "") +
|
|
138
|
+
"The runtime rejects this combination with unsupported_action_protocol_topology.");
|
|
139
|
+
}
|
|
140
|
+
/** Validate join options. */
|
|
141
|
+
export function validateJoinOptions(options) {
|
|
142
|
+
const locators = Number(nonblank(options?.roomSessionId)) +
|
|
143
|
+
Number(nonblank(options?.sharedSessionKey));
|
|
144
|
+
if (locators !== 1) {
|
|
145
|
+
throw new Error("joinRoom requires exactly one of roomSessionId or sharedSessionKey");
|
|
146
|
+
}
|
|
147
|
+
if (!nonblank(options.endUserId)) {
|
|
148
|
+
throw new Error("joinRoom requires a nonblank endUserId");
|
|
149
|
+
}
|
|
150
|
+
// Guard the shape even though the type forbids it: a plain-JS caller, or a
|
|
151
|
+
// config object spread in wholesale, would otherwise send topology that the
|
|
152
|
+
// runtime rejects with a less specific message.
|
|
153
|
+
const stray = options;
|
|
154
|
+
if (stray.characters || stray.characterId || stray.characterSessionId) {
|
|
155
|
+
throw new Error("joinRoom must not carry character topology; the room's roster is server-owned");
|
|
156
|
+
}
|
|
157
|
+
assertKey(options.sharedSessionKey, "sharedSessionKey");
|
|
158
|
+
assertKey(options.connectAttemptId, "connectAttemptId");
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The roster half of a create request. Merged into the existing single-character
|
|
162
|
+
* body by the caller, so every current option (blendshape, TTS/STT, dynamic
|
|
163
|
+
* info, action, scene, VAD, vision) continues to apply to every member.
|
|
164
|
+
*/
|
|
165
|
+
export function buildRosterConnectFields(config) {
|
|
166
|
+
const characters = (config.characters ?? []).map((spec) => ({
|
|
167
|
+
character_id: spec.characterId.trim(),
|
|
168
|
+
...(spec.characterSessionId
|
|
169
|
+
? { character_session_id: spec.characterSessionId }
|
|
170
|
+
: {}),
|
|
171
|
+
}));
|
|
172
|
+
return {
|
|
173
|
+
// Both carry server defaults that already match, but a roster room is
|
|
174
|
+
// rejected outright without them, so they are stated rather than assumed.
|
|
175
|
+
mode: "create",
|
|
176
|
+
spawn_agent: true,
|
|
177
|
+
characters,
|
|
178
|
+
...(config.sharedSessionKey
|
|
179
|
+
? { shared_session_key: config.sharedSessionKey }
|
|
180
|
+
: {}),
|
|
181
|
+
...(config.connectAttemptId
|
|
182
|
+
? { connect_attempt_id: config.connectAttemptId }
|
|
183
|
+
: {}),
|
|
184
|
+
...(config.maxNumParticipants !== undefined
|
|
185
|
+
? { max_num_participants: config.maxNumParticipants }
|
|
186
|
+
: {}),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* The complete join request body. A join carries a locator and the human, and
|
|
191
|
+
* nothing else — the roster is loaded from persisted room state, and resending
|
|
192
|
+
* topology is rejected.
|
|
193
|
+
*/
|
|
194
|
+
export function buildJoinRequestBody(options) {
|
|
195
|
+
return {
|
|
196
|
+
mode: "join",
|
|
197
|
+
transport: "livekit",
|
|
198
|
+
...(options.roomSessionId
|
|
199
|
+
? { room_session_id: options.roomSessionId }
|
|
200
|
+
: { shared_session_key: options.sharedSessionKey }),
|
|
201
|
+
end_user_id: options.endUserId,
|
|
202
|
+
...(options.endUserMetadata
|
|
203
|
+
? { end_user_metadata: options.endUserMetadata }
|
|
204
|
+
: {}),
|
|
205
|
+
...(options.connectAttemptId
|
|
206
|
+
? { connect_attempt_id: options.connectAttemptId }
|
|
207
|
+
: {}),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=rosterRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rosterRequest.js","sourceRoot":"","sources":["../../src/core/rosterRequest.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,EAAE,CAAC;AAEjD,uEAAuE;AACvE,MAAM,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AE,OAAO,CAAC,eAAe,EAAE;YAChD,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,OAAO,CAAC,gBAAgB;YAC1B,CAAC,CAAC,EAAE,kBAAkB,EAAE,OAAO,CAAC,gBAAgB,EAAE;YAClD,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC","sourcesContent":["import type {\n ConvaiCharacterSpec,\n ConvaiConfig,\n JoinRoomOptions,\n} from \"./types\";\nimport { isCharacterUuid } from \"./characterReference\";\n\n/**\n * Validation and request-body construction for multi-character rooms.\n *\n * Pure: no transport, no client state. Every rule below runs before a request\n * is built, so an illegal topology costs nothing and reports the rule it broke\n * rather than a 422 from the runtime.\n */\n\n/**\n * Server-wide roster cap. Checked client-side only to fail fast with a clear\n * message — the server stays authoritative, and a plan may configure a lower\n * `max_characters` that surfaces as 403 `MULTI_CHARACTER_ROSTER_LIMIT_EXCEEDED`.\n * This is an operational limit, not a protocol maximum, so it must not leak\n * into any public type.\n */\nexport const MULTI_CHARACTER_MAX_CHARACTERS = 50;\n\n/** `shared_session_key` and `connect_attempt_id` share one charset. */\nconst KEY_PATTERN = /^[A-Za-z0-9_-]{1,128}$/;\n\n/** True when this config asks for a multi-character room. */\nexport function isRosterConfig(\n config: Pick<ConvaiConfig, \"characters\">,\n): boolean {\n return Array.isArray(config.characters) && config.characters.length > 0;\n}\n\nfunction assertKey(value: string | undefined, field: string): void {\n if (value === undefined) return;\n if (!KEY_PATTERN.test(value)) {\n throw new Error(\n `${field} must be 1-128 characters of letters, digits, hyphen or underscore`,\n );\n }\n}\n\nfunction nonblank(value: string | undefined | null): boolean {\n return typeof value === \"string\" && value.trim().length > 0;\n}\n\n/**\n * Validate a roster create config.\n *\n * Throws on the first broken rule. Ordered so the most structural problems\n * (which topology did you mean?) report before the detail ones.\n */\nexport function validateRosterConfig(config: ConvaiConfig): void {\n const characters = config.characters ?? [];\n\n if (config.characterId) {\n throw new Error(\"Pass either characterId or characters, not both\");\n }\n if (characters.length === 0) {\n throw new Error(\"characters must contain at least one entry\");\n }\n if (characters.length > MULTI_CHARACTER_MAX_CHARACTERS) {\n throw new Error(\n `characters accepts at most ${MULTI_CHARACTER_MAX_CHARACTERS} entries; ` +\n `your plan may allow fewer`,\n );\n }\n\n const seenSessions = new Set<string>();\n characters.forEach((spec, index) => {\n if (!spec || !nonblank(spec.characterId)) {\n throw new Error(\n `characters[${index}] requires a characterId`,\n );\n }\n // A roster entry is typed as a bare UUID on the runtime. The version\n // selectors that single-character `characterId` has accepted since\n // 1.8.0-beta.5 are a 422 here, and the failure would otherwise only show\n // up as an opaque validation error from the server.\n if (!isCharacterUuid(spec.characterId.trim())) {\n throw new Error(\n `characters[${index}].characterId must be a bare character UUID; ` +\n `version selectors are not supported inside a roster`,\n );\n }\n if (spec.characterSessionId !== undefined) {\n if (!nonblank(spec.characterSessionId)) {\n throw new Error(\n `characters[${index}].characterSessionId must be nonblank when supplied`,\n );\n }\n if (seenSessions.has(spec.characterSessionId)) {\n throw new Error(\n `characters[${index}].characterSessionId is repeated; resume ids must be unique within the roster`,\n );\n }\n seenSessions.add(spec.characterSessionId);\n }\n });\n\n if (config.characterSessionId) {\n throw new Error(\n \"characterSessionId is not valid with characters; use characters[].characterSessionId\",\n );\n }\n if (!nonblank(config.endUserId)) {\n throw new Error(\"characters requires a nonblank endUserId\");\n }\n if (config.transport && config.transport !== \"livekit\") {\n throw new Error(\"Multi-character rooms require the LiveKit transport\");\n }\n if (config.interactionApiUrl) {\n throw new Error(\n \"Multi-character rooms require the LiveKit transport; interactionApiUrl selects SSE\",\n );\n }\n if (config.characterVersion) {\n throw new Error(\n \"characterVersion applies to a single character; roster entries take bare UUIDs\",\n );\n }\n assertKey(config.sharedSessionKey, \"sharedSessionKey\");\n assertKey(config.connectAttemptId, \"connectAttemptId\");\n if (\n config.maxNumParticipants !== undefined &&\n (!Number.isInteger(config.maxNumParticipants) ||\n config.maxNumParticipants < 1)\n ) {\n throw new Error(\"maxNumParticipants must be a positive integer\");\n }\n}\n\n/**\n * Reject a config that negotiates v2 output protocols alongside room options\n * the runtime cannot combine them with.\n *\n * Verified against staging 2026-09-08: `capabilities.actionProtocolVersion: 2`\n * or `modelOutputVersion: 2` is answered with 422\n * `unsupported_action_protocol_topology` / `unsupported_model_output_topology`\n * unless the request uses `mode='create'`, a singular `characterId`, no\n * `sharedSessionKey`, and `maxNumParticipants` of 1. Version 1 carries no such\n * constraint.\n *\n * The published contract mentions only the multi-character half of this. The\n * `sharedSessionKey` and `maxNumParticipants` constraints bite in\n * single-character sessions too, which is why this runs on every connect\n * rather than only the roster path.\n */\nexport function validateProtocolTopology(config: ConvaiConfig): void {\n const negotiatesV2 =\n config.capabilities?.actionProtocolVersion === 2 ||\n config.capabilities?.modelOutputVersion === 2;\n\n if (!negotiatesV2) {\n // Tools need v2, so without it they are refused whatever the topology.\n if (config.actionConfig?.tools?.length) {\n throw new Error(\n \"actionConfig.tools requires capabilities.actionProtocolVersion: 2\",\n );\n }\n return;\n }\n\n const offenders: string[] = [];\n if (isRosterConfig(config)) offenders.push(\"characters\");\n if (config.sharedSessionKey) offenders.push(\"sharedSessionKey\");\n if (config.maxNumParticipants !== undefined && config.maxNumParticipants !== 1) {\n offenders.push(\"maxNumParticipants greater than 1\");\n }\n if (offenders.length === 0) return;\n\n throw new Error(\n `Negotiated v2 output protocols require a single-character room: ` +\n `remove ${offenders.join(\", \")}, or drop capabilities to version 1. ` +\n (offenders.includes(\"characters\")\n ? \"Multi-character rooms cannot use action protocol v2, and therefore cannot use client tools. \"\n : \"\") +\n \"The runtime rejects this combination with unsupported_action_protocol_topology.\",\n );\n}\n\n/** Validate join options. */\nexport function validateJoinOptions(options: JoinRoomOptions): void {\n const locators =\n Number(nonblank(options?.roomSessionId)) +\n Number(nonblank(options?.sharedSessionKey));\n if (locators !== 1) {\n throw new Error(\n \"joinRoom requires exactly one of roomSessionId or sharedSessionKey\",\n );\n }\n if (!nonblank(options.endUserId)) {\n throw new Error(\"joinRoom requires a nonblank endUserId\");\n }\n // Guard the shape even though the type forbids it: a plain-JS caller, or a\n // config object spread in wholesale, would otherwise send topology that the\n // runtime rejects with a less specific message.\n const stray = options as unknown as Record<string, unknown>;\n if (stray.characters || stray.characterId || stray.characterSessionId) {\n throw new Error(\n \"joinRoom must not carry character topology; the room's roster is server-owned\",\n );\n }\n assertKey(options.sharedSessionKey, \"sharedSessionKey\");\n assertKey(options.connectAttemptId, \"connectAttemptId\");\n}\n\n/**\n * The roster half of a create request. Merged into the existing single-character\n * body by the caller, so every current option (blendshape, TTS/STT, dynamic\n * info, action, scene, VAD, vision) continues to apply to every member.\n */\nexport function buildRosterConnectFields(\n config: ConvaiConfig,\n): Record<string, unknown> {\n const characters = (config.characters ?? []).map(\n (spec: ConvaiCharacterSpec) => ({\n character_id: spec.characterId.trim(),\n ...(spec.characterSessionId\n ? { character_session_id: spec.characterSessionId }\n : {}),\n }),\n );\n\n return {\n // Both carry server defaults that already match, but a roster room is\n // rejected outright without them, so they are stated rather than assumed.\n mode: \"create\",\n spawn_agent: true,\n characters,\n ...(config.sharedSessionKey\n ? { shared_session_key: config.sharedSessionKey }\n : {}),\n ...(config.connectAttemptId\n ? { connect_attempt_id: config.connectAttemptId }\n : {}),\n ...(config.maxNumParticipants !== undefined\n ? { max_num_participants: config.maxNumParticipants }\n : {}),\n };\n}\n\n/**\n * The complete join request body. A join carries a locator and the human, and\n * nothing else — the roster is loaded from persisted room state, and resending\n * topology is rejected.\n */\nexport function buildJoinRequestBody(\n options: JoinRoomOptions,\n): Record<string, unknown> {\n return {\n mode: \"join\",\n transport: \"livekit\",\n ...(options.roomSessionId\n ? { room_session_id: options.roomSessionId }\n : { shared_session_key: options.sharedSessionKey }),\n end_user_id: options.endUserId,\n ...(options.endUserMetadata\n ? { end_user_metadata: options.endUserMetadata }\n : {}),\n ...(options.connectAttemptId\n ? { connect_attempt_id: options.connectAttemptId }\n : {}),\n };\n}\n"]}
|