@convai/web-sdk 1.8.0 → 1.9.0-beta.0
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 +213 -45
- 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/CharacterVersionManager.d.ts +100 -0
- package/dist/core/CharacterVersionManager.d.ts.map +1 -0
- package/dist/core/CharacterVersionManager.js +227 -0
- package/dist/core/CharacterVersionManager.js.map +1 -0
- package/dist/core/ConvaiClient.d.ts +190 -1
- package/dist/core/ConvaiClient.d.ts.map +1 -1
- package/dist/core/ConvaiClient.js +1328 -289
- 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 +26 -2
- package/dist/core/MessageHandler.d.ts.map +1 -1
- package/dist/core/MessageHandler.js +397 -32
- package/dist/core/MessageHandler.js.map +1 -1
- package/dist/core/SSESession.d.ts +74 -0
- package/dist/core/SSESession.d.ts.map +1 -0
- package/dist/core/SSESession.js +499 -0
- package/dist/core/SSESession.js.map +1 -0
- package/dist/core/characterReference.d.ts +40 -0
- package/dist/core/characterReference.d.ts.map +1 -0
- package/dist/core/characterReference.js +72 -0
- package/dist/core/characterReference.js.map +1 -0
- package/dist/core/connectRequest.d.ts +17 -4
- package/dist/core/connectRequest.d.ts.map +1 -1
- package/dist/core/connectRequest.js +28 -17
- package/dist/core/connectRequest.js.map +1 -1
- package/dist/core/index.d.ts +8 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +13 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/logicalTurn.d.ts +4 -6
- package/dist/core/logicalTurn.d.ts.map +1 -1
- package/dist/core/logicalTurn.js +29 -4
- package/dist/core/logicalTurn.js.map +1 -1
- package/dist/core/modelOutput.d.ts.map +1 -1
- package/dist/core/modelOutput.js +2 -2
- package/dist/core/modelOutput.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 +869 -22
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/embed/ConvaiChatElement.d.ts +77 -1
- package/dist/embed/ConvaiChatElement.d.ts.map +1 -1
- package/dist/embed/ConvaiChatElement.js +433 -54
- package/dist/embed/ConvaiChatElement.js.map +1 -1
- package/dist/embed/chat-embed-v1.js +136 -35
- package/dist/embed/chat-embed-v1.js.map +4 -4
- package/dist/react/components/ConvaiWidget.d.ts.map +1 -1
- package/dist/react/components/ConvaiWidget.js +6 -1
- package/dist/react/components/ConvaiWidget.js.map +1 -1
- package/dist/react/components/rtc-widget/components/AudioVisualizer.d.ts.map +1 -1
- package/dist/react/components/rtc-widget/components/AudioVisualizer.js +28 -1
- package/dist/react/components/rtc-widget/components/AudioVisualizer.js.map +1 -1
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts +7 -0
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts.map +1 -1
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.js +135 -46
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.js.map +1 -1
- package/dist/react/components/rtc-widget/components/UserMessage.js +1 -1
- package/dist/react/components/rtc-widget/components/UserMessage.js.map +1 -1
- package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.d.ts.map +1 -1
- package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js +93 -49
- package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js.map +1 -1
- package/dist/react/hooks/useConvaiClient.d.ts.map +1 -1
- package/dist/react/hooks/useConvaiClient.js +17 -2
- package/dist/react/hooks/useConvaiClient.js.map +1 -1
- package/dist/react/index.d.ts +4 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +8 -1
- package/dist/react/index.js.map +1 -1
- package/dist/utils/inlineMarkdown.d.ts +60 -0
- package/dist/utils/inlineMarkdown.d.ts.map +1 -0
- package/dist/utils/inlineMarkdown.js +183 -0
- package/dist/utils/inlineMarkdown.js.map +1 -0
- package/dist/vanilla/AudioRenderer.d.ts +3 -1
- package/dist/vanilla/AudioRenderer.d.ts.map +1 -1
- package/dist/vanilla/AudioRenderer.js +8 -2
- package/dist/vanilla/AudioRenderer.js.map +1 -1
- package/dist/vanilla/ConvaiWidget.d.ts.map +1 -1
- package/dist/vanilla/ConvaiWidget.js +1122 -302
- package/dist/vanilla/ConvaiWidget.js.map +1 -1
- package/dist/vanilla/WidgetEventSubscriptions.d.ts +1 -1
- package/dist/vanilla/WidgetEventSubscriptions.d.ts.map +1 -1
- package/dist/vanilla/WidgetEventSubscriptions.js +5 -0
- package/dist/vanilla/WidgetEventSubscriptions.js.map +1 -1
- package/dist/vanilla/icons.d.ts.map +1 -1
- package/dist/vanilla/icons.js +62 -15
- package/dist/vanilla/icons.js.map +1 -1
- package/dist/vanilla/index.d.ts +6 -2
- package/dist/vanilla/index.d.ts.map +1 -1
- package/dist/vanilla/index.js +5 -1
- package/dist/vanilla/index.js.map +1 -1
- package/dist/vanilla/styles.d.ts +18 -1
- package/dist/vanilla/styles.d.ts.map +1 -1
- package/dist/vanilla/styles.js +141 -29
- package/dist/vanilla/styles.js.map +1 -1
- package/dist/vanilla/types.d.ts +74 -0
- package/dist/vanilla/types.d.ts.map +1 -1
- package/dist/vanilla/types.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +45 -18
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Character references.
|
|
3
|
+
*
|
|
4
|
+
* The runtime accepts a bare character UUID or a UUID followed by a version
|
|
5
|
+
* selector: `<uuid>-draft`, `<uuid>-latest`, or `<uuid>-1.2[.3]`. The SDK
|
|
6
|
+
* keeps the two halves apart — the bare UUID still names the character for
|
|
7
|
+
* memory, character info and analytics, while the joined reference is what
|
|
8
|
+
* goes on the wire to `/connect` and the interaction API.
|
|
9
|
+
*/
|
|
10
|
+
const UUID_PATTERN = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}";
|
|
11
|
+
const VERSION_TAG_PATTERN = "(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)(?:\\.(?:0|[1-9]\\d*))?";
|
|
12
|
+
const UUID_RE = new RegExp(`^${UUID_PATTERN}$`);
|
|
13
|
+
const SELECTOR_RE = new RegExp(`^(?:draft|latest|${VERSION_TAG_PATTERN})$`);
|
|
14
|
+
const REFERENCE_RE = new RegExp(`^(${UUID_PATTERN})(?:-(draft|latest|${VERSION_TAG_PATTERN}))?$`);
|
|
15
|
+
/** True when `value` is `draft`, `latest`, or a `major.minor[.patch]` tag. */
|
|
16
|
+
export function isCharacterVersionSelector(value) {
|
|
17
|
+
return typeof value === "string" && SELECTOR_RE.test(value);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Split a character id that may already carry a selector suffix. Returns null
|
|
21
|
+
* when the value is neither a UUID nor a versioned reference — callers that
|
|
22
|
+
* accept opaque ids (legacy non-UUID characters) fall back to the raw string.
|
|
23
|
+
*/
|
|
24
|
+
export function parseCharacterReference(value) {
|
|
25
|
+
const match = REFERENCE_RE.exec(value.trim());
|
|
26
|
+
if (!match)
|
|
27
|
+
return null;
|
|
28
|
+
const characterId = match[1].toLowerCase();
|
|
29
|
+
const version = match[2] ?? null;
|
|
30
|
+
return {
|
|
31
|
+
characterId,
|
|
32
|
+
version,
|
|
33
|
+
reference: version ? `${characterId}-${version}` : characterId,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Combine a `characterId` and an optional `characterVersion` config field into
|
|
38
|
+
* the reference sent to the runtime.
|
|
39
|
+
*
|
|
40
|
+
* - `characterId` may be a bare UUID or already carry a selector.
|
|
41
|
+
* - `characterVersion` must be a valid selector when provided.
|
|
42
|
+
* - Supplying both is allowed only when they agree.
|
|
43
|
+
* - A non-UUID `characterId` cannot be versioned.
|
|
44
|
+
*/
|
|
45
|
+
export function resolveCharacterReference(characterId, characterVersion) {
|
|
46
|
+
const parsed = parseCharacterReference(characterId);
|
|
47
|
+
if (characterVersion != null && characterVersion !== "") {
|
|
48
|
+
if (!isCharacterVersionSelector(characterVersion)) {
|
|
49
|
+
throw new Error(`characterVersion must be "draft", "latest", or a major.minor[.patch] tag; received ${JSON.stringify(characterVersion)}`);
|
|
50
|
+
}
|
|
51
|
+
if (!parsed) {
|
|
52
|
+
throw new Error("characterVersion requires characterId to be a character UUID");
|
|
53
|
+
}
|
|
54
|
+
if (parsed.version && parsed.version !== characterVersion) {
|
|
55
|
+
throw new Error(`characterId already selects version "${parsed.version}" but characterVersion is "${characterVersion}"`);
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
characterId: parsed.characterId,
|
|
59
|
+
version: characterVersion,
|
|
60
|
+
reference: `${parsed.characterId}-${characterVersion}`,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (parsed)
|
|
64
|
+
return parsed;
|
|
65
|
+
// Not a UUID: pass through untouched so legacy ids keep working.
|
|
66
|
+
return { characterId, version: null, reference: characterId };
|
|
67
|
+
}
|
|
68
|
+
/** True when `value` is a bare character UUID. */
|
|
69
|
+
export function isCharacterUuid(value) {
|
|
70
|
+
return UUID_RE.test(value);
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=characterReference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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,CAAC;QACxD,IAAI,CAAC,0BAA0B,CAAC,gBAAgB,CAAC,EAAE,CAAC;YAClD,MAAM,IAAI,KAAK,CACb,sFAAsF,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,EAAE,CACzH,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CACb,8DAA8D,CAC/D,CAAC;QACJ,CAAC;QACD,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,KAAK,gBAAgB,EAAE,CAAC;YAC1D,MAAM,IAAI,KAAK,CACb,wCAAwC,MAAM,CAAC,OAAO,8BAA8B,gBAAgB,GAAG,CACxG,CAAC;QACJ,CAAC;QACD,OAAO;YACL,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,OAAO,EAAE,gBAAgB;YACzB,SAAS,EAAE,GAAG,MAAM,CAAC,WAAW,IAAI,gBAAgB,EAAE;SACvD,CAAC;IACJ,CAAC;IAED,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAE1B,iEAAiE;IACjE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;AAChE,CAAC;AAED,kDAAkD;AAClD,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["/**\n * Character references.\n *\n * The runtime accepts a bare character UUID or a UUID followed by a version\n * selector: `<uuid>-draft`, `<uuid>-latest`, or `<uuid>-1.2[.3]`. The SDK\n * keeps the two halves apart — the bare UUID still names the character for\n * memory, character info and analytics, while the joined reference is what\n * goes on the wire to `/connect` and the interaction API.\n */\n\n/** A version selector: the editable draft, the promoted latest, or an immutable tag. */\nexport type CharacterVersionSelector = \"draft\" | \"latest\" | (string & {});\n\nconst UUID_PATTERN =\n \"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\";\nconst VERSION_TAG_PATTERN = \"(?:0|[1-9]\\\\d*)\\\\.(?:0|[1-9]\\\\d*)(?:\\\\.(?:0|[1-9]\\\\d*))?\";\n\nconst UUID_RE = new RegExp(`^${UUID_PATTERN}$`);\nconst SELECTOR_RE = new RegExp(`^(?:draft|latest|${VERSION_TAG_PATTERN})$`);\nconst REFERENCE_RE = new RegExp(\n `^(${UUID_PATTERN})(?:-(draft|latest|${VERSION_TAG_PATTERN}))?$`,\n);\n\nexport interface CharacterReference {\n /** The bare character UUID, lower-cased. */\n characterId: string;\n /** The selector, or null for a bare reference. */\n version: CharacterVersionSelector | null;\n /** What goes on the wire: the UUID, or `<uuid>-<selector>`. */\n reference: string;\n}\n\n/** True when `value` is `draft`, `latest`, or a `major.minor[.patch]` tag. */\nexport function isCharacterVersionSelector(value: unknown): value is CharacterVersionSelector {\n return typeof value === \"string\" && SELECTOR_RE.test(value);\n}\n\n/**\n * Split a character id that may already carry a selector suffix. Returns null\n * when the value is neither a UUID nor a versioned reference — callers that\n * accept opaque ids (legacy non-UUID characters) fall back to the raw string.\n */\nexport function parseCharacterReference(value: string): CharacterReference | null {\n const match = REFERENCE_RE.exec(value.trim());\n if (!match) return null;\n const characterId = match[1].toLowerCase();\n const version = (match[2] as CharacterVersionSelector | undefined) ?? null;\n return {\n characterId,\n version,\n reference: version ? `${characterId}-${version}` : characterId,\n };\n}\n\n/**\n * Combine a `characterId` and an optional `characterVersion` config field into\n * the reference sent to the runtime.\n *\n * - `characterId` may be a bare UUID or already carry a selector.\n * - `characterVersion` must be a valid selector when provided.\n * - Supplying both is allowed only when they agree.\n * - A non-UUID `characterId` cannot be versioned.\n */\nexport function resolveCharacterReference(\n characterId: string,\n characterVersion?: CharacterVersionSelector | null,\n): CharacterReference {\n const parsed = parseCharacterReference(characterId);\n\n if (characterVersion != null && characterVersion !== \"\") {\n if (!isCharacterVersionSelector(characterVersion)) {\n throw new Error(\n `characterVersion must be \"draft\", \"latest\", or a major.minor[.patch] tag; received ${JSON.stringify(characterVersion)}`,\n );\n }\n if (!parsed) {\n throw new Error(\n \"characterVersion requires characterId to be a character UUID\",\n );\n }\n if (parsed.version && parsed.version !== characterVersion) {\n throw new Error(\n `characterId already selects version \"${parsed.version}\" but characterVersion is \"${characterVersion}\"`,\n );\n }\n return {\n characterId: parsed.characterId,\n version: characterVersion,\n reference: `${parsed.characterId}-${characterVersion}`,\n };\n }\n\n if (parsed) return parsed;\n\n // Not a UUID: pass through untouched so legacy ids keep working.\n return { characterId, version: null, reference: characterId };\n}\n\n/** True when `value` is a bare character UUID. */\nexport function isCharacterUuid(value: string): boolean {\n return UUID_RE.test(value);\n}\n"]}
|
|
@@ -4,7 +4,7 @@ export interface BlendshapeConnectRequestConfig {
|
|
|
4
4
|
blendshape_config: {
|
|
5
5
|
enable_chunking: true;
|
|
6
6
|
chunk_size: number;
|
|
7
|
-
format: "arkit" | "mha";
|
|
7
|
+
format: "arkit" | "mha" | "cc4_extended" | "cc5_hd" | "visemes";
|
|
8
8
|
frames_buffer_duration: number;
|
|
9
9
|
output_fps: number;
|
|
10
10
|
deliver_chunks_ahead?: true;
|
|
@@ -18,7 +18,6 @@ export interface ClientToolConnectRequestDeclaration {
|
|
|
18
18
|
export interface ProtocolCapabilitiesConnectRequest {
|
|
19
19
|
action_protocol_version?: 1 | 2;
|
|
20
20
|
model_output_version?: 1 | 2;
|
|
21
|
-
bot_llm_text_mode?: "legacy" | "raw";
|
|
22
21
|
}
|
|
23
22
|
/**
|
|
24
23
|
* Serialize only explicitly selected capabilities.
|
|
@@ -33,8 +32,6 @@ export declare function serializeClientTools(tools: ClientToolDeclaration[]): Cl
|
|
|
33
32
|
export declare function validateActionProtocolSelection(requestedVersion: 1 | 2 | undefined, selectedVersion: unknown): void;
|
|
34
33
|
/** Reject unsupported model-output versions, downgrades, and unsolicited v2 upgrades. */
|
|
35
34
|
export declare function validateModelOutputVersionSelection(requestedVersion: 1 | 2 | undefined, selectedVersion: unknown): 1 | 2;
|
|
36
|
-
/** Reject unsupported text modes, raw downgrades, and unsolicited raw upgrades. */
|
|
37
|
-
export declare function validateBotLlmTextModeSelection(requestedMode: "legacy" | "raw" | undefined, selectedMode: unknown): void;
|
|
38
35
|
/**
|
|
39
36
|
* Build the lipsync part of the /connect request.
|
|
40
37
|
*
|
|
@@ -44,4 +41,20 @@ export declare function validateBotLlmTextModeSelection(requestedMode: "legacy"
|
|
|
44
41
|
* to the legacy paced path with deliver_chunks_ahead: false.
|
|
45
42
|
*/
|
|
46
43
|
export declare function buildBlendshapeConnectConfig(config: Pick<ConvaiConfig, "enableLipsync" | "blendshapeConfig">): BlendshapeConnectRequestConfig;
|
|
44
|
+
export declare function buildEmotionConnectConfig(config: Pick<ConvaiConfig, "enableEmotion" | "emotionConfig">): Record<string, unknown> | undefined;
|
|
45
|
+
/** The `action_config` block as sent on the wire; tools are already serialized. */
|
|
46
|
+
export interface ActionConnectRequestConfig {
|
|
47
|
+
actions: string[];
|
|
48
|
+
characters: {
|
|
49
|
+
name: string;
|
|
50
|
+
bio: string;
|
|
51
|
+
}[];
|
|
52
|
+
objects: {
|
|
53
|
+
name: string;
|
|
54
|
+
description: string;
|
|
55
|
+
}[];
|
|
56
|
+
current_attention_object?: string;
|
|
57
|
+
tools?: ClientToolConnectRequestDeclaration[];
|
|
58
|
+
}
|
|
59
|
+
export declare function buildActionConnectConfig(config: Pick<ConvaiConfig, "actionConfig">): ActionConnectRequestConfig | undefined;
|
|
47
60
|
//# sourceMappingURL=connectRequest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connectRequest.d.ts","sourceRoot":"","sources":["../../src/core/connectRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,YAAY,EACZ,UAAU,EACV,0BAA0B,EAC3B,MAAM,SAAS,CAAC;AAEjB,MAAM,WAAW,8BAA8B;IAC7C,mBAAmB,EAAE,W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nC,eAAe,EAAE,OAAO,GACvB,IAAI,CAkBN;AAED,yFAAyF;AACzF,wBAAgB,mCAAmC,CACjD,gBAAgB,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,EACnC,eAAe,EAAE,OAAO,GACvB,CAAC,GAAG,CAAC,CAoBP;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,eAAe,GAAG,kBAAkB,CAAC,GAC/D,8BAA8B,CAuBhC;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,eAAe,GAAG,eAAe,CAAC,GAC5D,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAYrC;AAED,mFAAmF;AACnF,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC5C,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACjD,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,KAAK,CAAC,EAAE,mCAAmC,EAAE,CAAC;CAC/C;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,cAAc,CAAC,GACzC,0BAA0B,GAAG,SAAS,CAYxC"}
|
|
@@ -14,9 +14,6 @@ export function serializeProtocolCapabilities(capabilities) {
|
|
|
14
14
|
...(capabilities.modelOutputVersion !== undefined && {
|
|
15
15
|
model_output_version: capabilities.modelOutputVersion,
|
|
16
16
|
}),
|
|
17
|
-
...(capabilities.botLlmTextMode !== undefined && {
|
|
18
|
-
bot_llm_text_mode: capabilities.botLlmTextMode,
|
|
19
|
-
}),
|
|
20
17
|
};
|
|
21
18
|
return Object.keys(serialized).length > 0 ? serialized : undefined;
|
|
22
19
|
}
|
|
@@ -57,20 +54,6 @@ export function validateModelOutputVersionSelection(requestedVersion, selectedVe
|
|
|
57
54
|
}
|
|
58
55
|
return selectedVersion === 2 ? 2 : 1;
|
|
59
56
|
}
|
|
60
|
-
/** Reject unsupported text modes, raw downgrades, and unsolicited raw upgrades. */
|
|
61
|
-
export function validateBotLlmTextModeSelection(requestedMode, selectedMode) {
|
|
62
|
-
if (selectedMode != null &&
|
|
63
|
-
selectedMode !== "legacy" &&
|
|
64
|
-
selectedMode !== "raw") {
|
|
65
|
-
throw new Error(`Core selected unsupported bot LLM text mode: ${String(selectedMode)}`);
|
|
66
|
-
}
|
|
67
|
-
if (requestedMode === "raw" && selectedMode !== "raw") {
|
|
68
|
-
throw new Error("Core did not select requested raw bot LLM text mode");
|
|
69
|
-
}
|
|
70
|
-
if (selectedMode === "raw" && requestedMode !== "raw") {
|
|
71
|
-
throw new Error("Core selected raw bot LLM text mode without an explicit client opt-in");
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
57
|
/**
|
|
75
58
|
* Build the lipsync part of the /connect request.
|
|
76
59
|
*
|
|
@@ -100,4 +83,32 @@ export function buildBlendshapeConnectConfig(config) {
|
|
|
100
83
|
},
|
|
101
84
|
};
|
|
102
85
|
}
|
|
86
|
+
export function buildEmotionConnectConfig(config) {
|
|
87
|
+
if (config.enableEmotion !== true)
|
|
88
|
+
return undefined;
|
|
89
|
+
const emotionConfig = config.emotionConfig;
|
|
90
|
+
if (emotionConfig?.provider === "nrclex") {
|
|
91
|
+
return {
|
|
92
|
+
provider: emotionConfig.provider,
|
|
93
|
+
min_word_threshold: emotionConfig.min_word_threshold ?? 3,
|
|
94
|
+
low_intensity_threshold: emotionConfig.low_intensity_threshold ?? 0.33,
|
|
95
|
+
high_intensity_threshold: emotionConfig.high_intensity_threshold ?? 0.66,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return { provider: emotionConfig?.provider ?? "llm" };
|
|
99
|
+
}
|
|
100
|
+
export function buildActionConnectConfig(config) {
|
|
101
|
+
const actionConfig = config.actionConfig;
|
|
102
|
+
if (!actionConfig)
|
|
103
|
+
return undefined;
|
|
104
|
+
return {
|
|
105
|
+
actions: actionConfig.actions,
|
|
106
|
+
objects: actionConfig.objects,
|
|
107
|
+
characters: actionConfig.characters,
|
|
108
|
+
...(actionConfig.current_attention_object && {
|
|
109
|
+
current_attention_object: actionConfig.current_attention_object,
|
|
110
|
+
}),
|
|
111
|
+
...(actionConfig.tools && { tools: serializeClientTools(actionConfig.tools) }),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
103
114
|
//# sourceMappingURL=connectRequest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connectRequest.js","sourceRoot":"","sources":["../../src/core/connectRequest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"connectRequest.js","sourceRoot":"","sources":["../../src/core/connectRequest.ts"],"names":[],"mappings":"AA8BA;;;;;GAKG;AACH,MAAM,UAAU,6BAA6B,CAC3C,YAAoD;IAEpD,IAAI,CAAC,YAAY;QAAE,OAAO,SAAS,CAAC;IAEpC,MAAM,UAAU,GAAuC;QACrD,GAAG,CAAC,YAAY,CAAC,qBAAqB,KAAK,SAAS,IAAI;YACtD,uBAAuB,EAAE,YAAY,CAAC,qBAAqB;SAC5D,CAAC;QACF,GAAG,CAAC,YAAY,CAAC,kBAAkB,KAAK,SAAS,IAAI;YACnD,oBAAoB,EAAE,YAAY,CAAC,kBAAkB;SACtD,CAAC;KACH,CAAC;IAEF,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;AACrE,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,oBAAoB,CAClC,KAA8B;IAE9B,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC1B,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SACzE,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,QAAQ,IAAI,KAAK,EAAE,CAAC;AACxD,CAAC;AAWD,MAAM,UAAU,wBAAwB,CACtC,MAA0C;IAE1C,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;IACzC,IAAI,CAAC,YAAY;QAAE,OAAO,SAAS,CAAC;IACpC,OAAO;QACL,OAAO,EAAE,YAAY,CAAC,OAAO;QAC7B,OAAO,EAAE,YAAY,CAAC,OAAO;QAC7B,UAAU,EAAE,YAAY,CAAC,UAAU;QACnC,GAAG,CAAC,YAAY,CAAC,wBAAwB,IAAI;YAC3C,wBAAwB,EAAE,YAAY,CAAC,wBAAwB;SAChE,CAAC;QACF,GAAG,CAAC,YAAY,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,oBAAoB,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;KAC/E,CAAC;AACJ,CAAC","sourcesContent":["import type {\n ClientToolDeclaration,\n ConvaiConfig,\n JsonObject,\n ProtocolCapabilitiesConfig,\n} from \"./types\";\n\nexport interface BlendshapeConnectRequestConfig {\n blendshape_provider: \"neurosync\" | \"not_provided\";\n blendshape_config: {\n enable_chunking: true;\n chunk_size: number;\n format: \"arkit\" | \"mha\" | \"cc4_extended\" | \"cc5_hd\" | \"visemes\";\n frames_buffer_duration: number;\n output_fps: number;\n deliver_chunks_ahead?: true;\n };\n}\n\nexport interface ClientToolConnectRequestDeclaration {\n name: string;\n description: string;\n input_schema: JsonObject;\n}\n\nexport interface ProtocolCapabilitiesConnectRequest {\n action_protocol_version?: 1 | 2;\n model_output_version?: 1 | 2;\n}\n\n/**\n * Serialize only explicitly selected capabilities.\n *\n * Returning undefined for an omitted or empty config keeps legacy /connect\n * request bodies unchanged, including for clients using strict wire snapshots.\n */\nexport function serializeProtocolCapabilities(\n capabilities: ProtocolCapabilitiesConfig | undefined,\n): ProtocolCapabilitiesConnectRequest | undefined {\n if (!capabilities) return undefined;\n\n const serialized: ProtocolCapabilitiesConnectRequest = {\n ...(capabilities.actionProtocolVersion !== undefined && {\n action_protocol_version: capabilities.actionProtocolVersion,\n }),\n ...(capabilities.modelOutputVersion !== undefined && {\n model_output_version: capabilities.modelOutputVersion,\n }),\n };\n\n return Object.keys(serialized).length > 0 ? serialized : undefined;\n}\n\n/** Serialize the public camelCase SDK shape to Core's snake_case wire contract. */\nexport function serializeClientTools(\n tools: ClientToolDeclaration[],\n): ClientToolConnectRequestDeclaration[] {\n return tools.map((tool) => ({\n name: tool.name,\n description: tool.description,\n input_schema: tool.inputSchema,\n }));\n}\n\n/** Reject unsupported action versions, downgrades, and unsolicited v2 upgrades. */\nexport function validateActionProtocolSelection(\n requestedVersion: 1 | 2 | undefined,\n selectedVersion: unknown,\n): void {\n if (\n selectedVersion != null &&\n selectedVersion !== 1 &&\n selectedVersion !== 2\n ) {\n throw new Error(\n `Core selected unsupported action protocol version: ${String(selectedVersion)}`,\n );\n }\n if (requestedVersion === 2 && selectedVersion !== 2) {\n throw new Error(\"Core did not select requested action protocol version 2\");\n }\n if (selectedVersion === 2 && requestedVersion !== 2) {\n throw new Error(\n \"Core selected action protocol version 2 without an explicit client opt-in\",\n );\n }\n}\n\n/** Reject unsupported model-output versions, downgrades, and unsolicited v2 upgrades. */\nexport function validateModelOutputVersionSelection(\n requestedVersion: 1 | 2 | undefined,\n selectedVersion: unknown,\n): 1 | 2 {\n if (\n selectedVersion != null &&\n selectedVersion !== 1 &&\n selectedVersion !== 2\n ) {\n throw new Error(\n `Core selected unsupported model output version: ${String(selectedVersion)}`,\n );\n }\n if (requestedVersion === 2 && selectedVersion !== 2) {\n throw new Error(\"Core did not select requested model output version 2\");\n }\n if (selectedVersion === 2 && requestedVersion !== 2) {\n throw new Error(\n \"Core selected model output version 2 without an explicit client opt-in\",\n );\n }\n\n return selectedVersion === 2 ? 2 : 1;\n}\n\n/**\n * Build the lipsync part of the /connect request.\n *\n * Ahead-delivery changes the client contract because frames can arrive before\n * bot-started-speaking and cancellation must be handled with owner metadata.\n * It is the default now that server support is verified; callers can fall back\n * to the legacy paced path with deliver_chunks_ahead: false.\n */\nexport function buildBlendshapeConnectConfig(\n config: Pick<ConvaiConfig, \"enableLipsync\" | \"blendshapeConfig\">,\n): BlendshapeConnectRequestConfig {\n const deliverChunksAhead =\n config.enableLipsync === true &&\n config.blendshapeConfig?.deliver_chunks_ahead !== false;\n\n return {\n blendshape_provider: config.enableLipsync ? \"neurosync\" : \"not_provided\",\n blendshape_config: {\n enable_chunking: true,\n chunk_size: 10,\n format: config.blendshapeConfig?.format || \"mha\",\n frames_buffer_duration:\n config.blendshapeConfig?.frames_buffer_duration ?? 0.1,\n // In the legacy paced path, output_fps is a delivery cadence and the SDK\n // player keeps its 60fps visual timeline. Only ahead-delivery treats\n // output_fps as a client-visible timeline override because chunks carry\n // fps metadata.\n output_fps: deliverChunksAhead\n ? config.blendshapeConfig?.output_fps ?? 60\n : 90,\n ...(deliverChunksAhead ? { deliver_chunks_ahead: true } : {}),\n },\n };\n}\n\nexport function buildEmotionConnectConfig(\n config: Pick<ConvaiConfig, \"enableEmotion\" | \"emotionConfig\">,\n): Record<string, unknown> | undefined {\n if (config.enableEmotion !== true) return undefined;\n const emotionConfig = config.emotionConfig;\n if (emotionConfig?.provider === \"nrclex\") {\n return {\n provider: emotionConfig.provider,\n min_word_threshold: emotionConfig.min_word_threshold ?? 3,\n low_intensity_threshold: emotionConfig.low_intensity_threshold ?? 0.33,\n high_intensity_threshold: emotionConfig.high_intensity_threshold ?? 0.66,\n };\n }\n return { provider: emotionConfig?.provider ?? \"llm\" };\n}\n\n/** The `action_config` block as sent on the wire; tools are already serialized. */\nexport interface ActionConnectRequestConfig {\n actions: string[];\n characters: { name: string; bio: string }[];\n objects: { name: string; description: string }[];\n current_attention_object?: string;\n tools?: ClientToolConnectRequestDeclaration[];\n}\n\nexport function buildActionConnectConfig(\n config: Pick<ConvaiConfig, \"actionConfig\">,\n): ActionConnectRequestConfig | undefined {\n const actionConfig = config.actionConfig;\n if (!actionConfig) return undefined;\n return {\n actions: actionConfig.actions,\n objects: actionConfig.objects,\n characters: actionConfig.characters,\n ...(actionConfig.current_attention_object && {\n current_attention_object: actionConfig.current_attention_object,\n }),\n ...(actionConfig.tools && { tools: serializeClientTools(actionConfig.tools) }),\n };\n}\n\n"]}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ConvaiClient } from './ConvaiClient.js';
|
|
1
|
+
export { ActionResultAckError, ConvaiClient } from './ConvaiClient.js';
|
|
2
2
|
export * from './types.js';
|
|
3
3
|
export { getDisconnectReasonMessage } from './types.js';
|
|
4
4
|
export type { ConvaiClient as ConvaiClientType } from './ConvaiClient.js';
|
|
@@ -7,9 +7,16 @@ export { VideoManager } from './VideoManager.js';
|
|
|
7
7
|
export { ScreenShareManager } from './ScreenShareManager.js';
|
|
8
8
|
export { MessageHandler } from './MessageHandler.js';
|
|
9
9
|
export { MemoryManager } from './MemoryManager.js';
|
|
10
|
+
export { CharacterRoster } from './CharacterRoster.js';
|
|
11
|
+
export { ConvaiRoomError } from './ConvaiRoomError.js';
|
|
12
|
+
export { MULTI_CHARACTER_MAX_CHARACTERS, isRosterConfig, } from './rosterRequest.js';
|
|
13
|
+
export { CharacterVersionManager, CharacterApiError, DEFAULT_CHARACTER_API_URL, } from './CharacterVersionManager.js';
|
|
14
|
+
export { parseCharacterReference, resolveCharacterReference, isCharacterVersionSelector, isCharacterUuid, } from './characterReference.js';
|
|
10
15
|
export { BlendshapeQueue } from './BlendshapeQueue.js';
|
|
11
16
|
export type { TurnStats, BlendshapeChunkMetadata } from './BlendshapeQueue.js';
|
|
12
17
|
export { EventEmitter } from './EventEmitter.js';
|
|
18
|
+
export { parseInlineMarkdown, mediaKindForUrl, isSafeHref, compactUrl } from '../utils/inlineMarkdown.js';
|
|
19
|
+
export type { InlineNode, MediaKind } from '../utils/inlineMarkdown.js';
|
|
13
20
|
export { ModelOutputExtensionRegistry, isJsonObject, isJsonValue, parseModelOutputMessage, } from './modelOutput.js';
|
|
14
21
|
export type { ExtensionRenderResult, ModelOutputExtensionRenderer, } from './modelOutput.js';
|
|
15
22
|
//# sourceMappingURL=index.d.ts.map
|
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;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGpE,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,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;AAGnC,OAAO,EACL,uBAAuB,EACvB,yBAAyB,EACzB,0BAA0B,EAC1B,eAAe,GAChB,MAAM,sBAAsB,CAAC;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;AAO9C,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACvG,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAErE,OAAO,EACL,4BAA4B,EAC5B,YAAY,EACZ,WAAW,EACX,uBAAuB,GACxB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,qBAAqB,EACrB,4BAA4B,GAC7B,MAAM,eAAe,CAAC"}
|
package/dist/core/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Main client
|
|
2
|
-
export { ConvaiClient } from './ConvaiClient.js';
|
|
2
|
+
export { ActionResultAckError, ConvaiClient } from './ConvaiClient.js';
|
|
3
3
|
// Types (including IConvaiClient interface)
|
|
4
4
|
export * from './types.js';
|
|
5
5
|
// Helper functions
|
|
@@ -10,9 +10,21 @@ 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';
|
|
16
|
+
export { CharacterVersionManager, CharacterApiError, DEFAULT_CHARACTER_API_URL, } from './CharacterVersionManager.js';
|
|
17
|
+
// Character reference helpers (version selectors)
|
|
18
|
+
export { parseCharacterReference, resolveCharacterReference, isCharacterVersionSelector, isCharacterUuid, } from './characterReference.js';
|
|
13
19
|
// Blendshape queue for lipsync
|
|
14
20
|
export { BlendshapeQueue } from './BlendshapeQueue.js';
|
|
15
21
|
// Event Emitter (for advanced usage)
|
|
16
22
|
export { EventEmitter } from './EventEmitter.js';
|
|
23
|
+
// Inline markdown tokenizer. `bot-llm-text` arrives as a plain string, so a
|
|
24
|
+
// custom chat UI — anything not using ConvaiWidget — needs this to turn one
|
|
25
|
+
// line of it into links, images and bare URLs. Only the scheme allowlist in
|
|
26
|
+
// `isSafeHref` becomes a link, so a renderer built on these nodes cannot emit
|
|
27
|
+
// a javascript: href however the server framed it.
|
|
28
|
+
export { parseInlineMarkdown, mediaKindForUrl, isSafeHref, compactUrl } from '../utils/inlineMarkdown.js';
|
|
17
29
|
export { ModelOutputExtensionRegistry, isJsonObject, isJsonValue, parseModelOutputMessage, } from './modelOutput.js';
|
|
18
30
|
//# sourceMappingURL=index.js.map
|
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;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEpE,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;AAE9C,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAC5E,8EAA8E;AAC9E,mDAAmD;AACnD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGvG,OAAO,EACL,4BAA4B,EAC5B,YAAY,EACZ,WAAW,EACX,uBAAuB,GACxB,MAAM,eAAe,CAAC","sourcesContent":["// Main client\nexport { ActionResultAckError, 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\n// Inline markdown tokenizer. `bot-llm-text` arrives as a plain string, so a\n// custom chat UI — anything not using ConvaiWidget — needs this to turn one\n// line of it into links, images and bare URLs. Only the scheme allowlist in\n// `isSafeHref` becomes a link, so a renderer built on these nodes cannot emit\n// a javascript: href however the server framed it.\nexport { parseInlineMarkdown, mediaKindForUrl, isSafeHref, compactUrl } from '../utils/inlineMarkdown';\nexport type { InlineNode, MediaKind } from '../utils/inlineMarkdown';\n\nexport {\n ModelOutputExtensionRegistry,\n isJsonObject,\n isJsonValue,\n parseModelOutputMessage,\n} from './modelOutput';\nexport type {\n ExtensionRenderResult,\n ModelOutputExtensionRenderer,\n} from './modelOutput';\n"]}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/** Maximum wire size for a logical turn identifier, in UTF-8 bytes. */
|
|
2
2
|
export declare const LOGICAL_TURN_ID_MAX_UTF8_BYTES = 128;
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
* Identifiers are preserved exactly. They must contain at least one
|
|
7
|
-
* non-whitespace character and fit within the bounded RTVI field.
|
|
8
|
-
*/
|
|
3
|
+
/** Maximum wire size for a model invocation identifier, in UTF-8 bytes. */
|
|
4
|
+
export declare const OUTPUT_ID_MAX_UTF8_BYTES = 128;
|
|
9
5
|
export declare function isValidLogicalTurnId(value: unknown): value is string;
|
|
6
|
+
/** Return whether a Core model invocation id is safe to retain and expose. */
|
|
7
|
+
export declare function isValidOutputId(value: unknown): value is string;
|
|
10
8
|
//# sourceMappingURL=logicalTurn.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logicalTurn.d.ts","sourceRoot":"","sources":["../../src/core/logicalTurn.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,eAAO,MAAM,8BAA8B,MAAM,CAAC;AAElD
|
|
1
|
+
{"version":3,"file":"logicalTurn.d.ts","sourceRoot":"","sources":["../../src/core/logicalTurn.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,eAAO,MAAM,8BAA8B,MAAM,CAAC;AAElD,2EAA2E;AAC3E,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAoC5C,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAKpE;AAED,8EAA8E;AAC9E,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE/D"}
|
package/dist/core/logicalTurn.js
CHANGED
|
@@ -1,16 +1,41 @@
|
|
|
1
1
|
/** Maximum wire size for a logical turn identifier, in UTF-8 bytes. */
|
|
2
2
|
export const LOGICAL_TURN_ID_MAX_UTF8_BYTES = 128;
|
|
3
|
+
/** Maximum wire size for a model invocation identifier, in UTF-8 bytes. */
|
|
4
|
+
export const OUTPUT_ID_MAX_UTF8_BYTES = 128;
|
|
5
|
+
/** Reject lone UTF-16 surrogates instead of silently encoding U+FFFD. */
|
|
6
|
+
function isWellFormedUtf16(value) {
|
|
7
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
8
|
+
const codeUnit = value.charCodeAt(index);
|
|
9
|
+
if (codeUnit >= 0xd800 && codeUnit <= 0xdbff) {
|
|
10
|
+
const next = value.charCodeAt(index + 1);
|
|
11
|
+
if (!(next >= 0xdc00 && next <= 0xdfff))
|
|
12
|
+
return false;
|
|
13
|
+
index += 1;
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (codeUnit >= 0xdc00 && codeUnit <= 0xdfff)
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
3
21
|
/**
|
|
4
22
|
* Return whether a logical turn identifier is safe to place on the wire.
|
|
5
23
|
*
|
|
6
24
|
* Identifiers are preserved exactly. They must contain at least one
|
|
7
25
|
* non-whitespace character and fit within the bounded RTVI field.
|
|
8
26
|
*/
|
|
9
|
-
|
|
27
|
+
function isValidBoundedCorrelationId(value, maxUtf8Bytes) {
|
|
10
28
|
return (typeof value === "string" &&
|
|
11
29
|
value.trim().length > 0 &&
|
|
12
|
-
value
|
|
13
|
-
|
|
14
|
-
|
|
30
|
+
isWellFormedUtf16(value) &&
|
|
31
|
+
value.length <= maxUtf8Bytes &&
|
|
32
|
+
new TextEncoder().encode(value).byteLength <= maxUtf8Bytes);
|
|
33
|
+
}
|
|
34
|
+
export function isValidLogicalTurnId(value) {
|
|
35
|
+
return isValidBoundedCorrelationId(value, LOGICAL_TURN_ID_MAX_UTF8_BYTES);
|
|
36
|
+
}
|
|
37
|
+
/** Return whether a Core model invocation id is safe to retain and expose. */
|
|
38
|
+
export function isValidOutputId(value) {
|
|
39
|
+
return isValidBoundedCorrelationId(value, OUTPUT_ID_MAX_UTF8_BYTES);
|
|
15
40
|
}
|
|
16
41
|
//# sourceMappingURL=logicalTurn.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logicalTurn.js","sourceRoot":"","sources":["../../src/core/logicalTurn.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,MAAM,CAAC,MAAM,8BAA8B,GAAG,GAAG,CAAC;AAElD
|
|
1
|
+
{"version":3,"file":"logicalTurn.js","sourceRoot":"","sources":["../../src/core/logicalTurn.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,MAAM,CAAC,MAAM,8BAA8B,GAAG,GAAG,CAAC;AAElD,2EAA2E;AAC3E,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAE5C,yEAAyE;AACzE,SAAS,iBAAiB,CAAC,KAAa;IACtC,KAAK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TES = 128;\n\n/** Maximum wire size for a model invocation identifier, in UTF-8 bytes. */\nexport const OUTPUT_ID_MAX_UTF8_BYTES = 128;\n\n/** Reject lone UTF-16 surrogates instead of silently encoding U+FFFD. */\nfunction isWellFormedUtf16(value: string): boolean {\n for (let index = 0; index < value.length; index += 1) {\n const codeUnit = value.charCodeAt(index);\n if (codeUnit >= 0xd800 && codeUnit <= 0xdbff) {\n const next = value.charCodeAt(index + 1);\n if (!(next >= 0xdc00 && next <= 0xdfff)) return false;\n index += 1;\n continue;\n }\n if (codeUnit >= 0xdc00 && codeUnit <= 0xdfff) return false;\n }\n return true;\n}\n\n/**\n * Return whether a logical turn identifier is safe to place on the wire.\n *\n * Identifiers are preserved exactly. They must contain at least one\n * non-whitespace character and fit within the bounded RTVI field.\n */\nfunction isValidBoundedCorrelationId(\n value: unknown,\n maxUtf8Bytes: number,\n): value is string {\n return (\n typeof value === \"string\" &&\n value.trim().length > 0 &&\n isWellFormedUtf16(value) &&\n value.length <= maxUtf8Bytes &&\n new TextEncoder().encode(value).byteLength <= maxUtf8Bytes\n );\n}\n\nexport function isValidLogicalTurnId(value: unknown): value is string {\n return isValidBoundedCorrelationId(\n value,\n LOGICAL_TURN_ID_MAX_UTF8_BYTES,\n );\n}\n\n/** Return whether a Core model invocation id is safe to retain and expose. */\nexport function isValidOutputId(value: unknown): value is string {\n return isValidBoundedCorrelationId(value, OUTPUT_ID_MAX_UTF8_BYTES);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modelOutput.d.ts","sourceRoot":"","sources":["../../src/core/modelOutput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,wBAAwB,EAExB,kBAAkB,EACnB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"modelOutput.d.ts","sourceRoot":"","sources":["../../src/core/modelOutput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,wBAAwB,EAExB,kBAAkB,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
2
|
function isRecord(value) {
|
|
3
3
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
4
4
|
return false;
|
|
@@ -113,7 +113,7 @@ export function parseModelOutputMessage(value) {
|
|
|
113
113
|
if (!isRecord(value) ||
|
|
114
114
|
value.type !== "model-output" ||
|
|
115
115
|
value.version !== 2 ||
|
|
116
|
-
!
|
|
116
|
+
!isValidOutputId(value.output_id) ||
|
|
117
117
|
(hasLogicalTurnId && !isValidLogicalTurnId(value.logical_turn_id)) ||
|
|
118
118
|
![
|
|
119
119
|
"text",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modelOutput.js","sourceRoot":"","sources":["../../src/core/modelOutput.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,SAAS,QAAQ,CAAC,KAAc;IAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACxE,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/C,OAAO,SAAS,KAAK,MAAM,CAAC,SAAS,IAAI,SAAS,KAAK,IAAI,CAAC;AAC9D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,KAAc;IACtD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACvC,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;QAClC,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC;YACzB,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE;YACzC,CAAC,CAAC,KAAK,CAAC;IACZ,CAAC;IACD,IACE,KAAK,CAAC,IAAI,KAAK,gBAAgB;QAC/B,Q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\n} from \"./types\";\nimport { isValidLogicalTurnId } from \"./logicalTurn.js\";\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return false;\n }\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Normalize canonical model-output delivery across transports.\n *\n * LiveKit delivers the RTVI frame as a top-level message with its payload in\n * `data`; WebSocket delivery wraps that same payload in `server-message`.\n */\nexport function extractModelOutputPayload(value: unknown): unknown | undefined {\n if (!isRecord(value)) return undefined;\n if (value.type === \"model-output\") {\n return isRecord(value.data)\n ? { ...value.data, type: \"model-output\" }\n : value;\n }\n if (\n value.type === \"server-message\" &&\n isRecord(value.data) &&\n value.data.type === \"model-output\"\n ) {\n return value.data;\n }\n return undefined;\n}\n\nfunction isOptionalString(value: unknown): value is string | null | undefined {\n return value === undefined || value === null || typeof value === \"string\";\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value.trim().length > 0;\n}\n\nexport function isJsonValue(\n value: unknown,\n ancestors: Set<unknown> = new Set(),\n): value is import(\"./types\").JsonValue {\n if (\n value === null ||\n typeof value === \"string\" ||\n typeof value === \"boolean\"\n ) {\n return true;\n }\n if (typeof value === \"number\") return Number.isFinite(value);\n if (typeof value !== \"object\") return false;\n if (ancestors.has(value)) return false;\n\n ancestors.add(value);\n const valid = Array.isArray(value)\n ? value.every((item) => isJsonValue(item, ancestors))\n : isRecord(value) &&\n Object.values(value).every((item) => isJsonValue(item, ancestors));\n ancestors.delete(value);\n return valid;\n}\n\nexport function isJsonObject(value: unknown): value is JsonObject {\n return isRecord(value) && isJsonValue(value);\n}\n\nfunction parseModelOutputItem(value: unknown): ModelOutputItem | null {\n if (!isRecord(value) || typeof value.type !== \"string\") return null;\n\n switch (value.type) {\n case \"message\":\n if (\n value.role !== \"assistant\" ||\n (value.channel !== \"final\" && value.channel !== \"commentary\") ||\n typeof value.content !== \"string\"\n ) {\n return null;\n }\n return value as unknown as ModelOutputItem;\n case \"emotion\":\n if (\n !isNonEmptyString(value.name) ||\n (value.scale !== 1 && value.scale !== 2 && value.scale !== 3)\n ) {\n return null;\n }\n return value as unknown as ModelOutputItem;\n case \"semantic_action\":\n if (\n !isNonEmptyString(value.id) ||\n !isNonEmptyString(value.name) ||\n !isOptionalString(value.target)\n ) {\n return null;\n }\n return value as unknown as ModelOutputItem;\n case \"tool_call\":\n if (\n !isNonEmptyString(value.id) ||\n !isNonEmptyString(value.name) ||\n !isOptionalString(value.target) ||\n !isJsonObject(value.arguments)\n ) {\n return null;\n }\n return value as unknown as ModelOutputItem;\n case \"extension\":\n if (\n !isNonEmptyString(value.schema) ||\n !Number.isInteger(value.version) ||\n (value.version as number) < 1 ||\n !isJsonObject(value.payload) ||\n !isOptionalString(value.fallback)\n ) {\n return null;\n }\n return value as unknown as ModelOutputItem;\n default:\n return null;\n }\n}\n\n/**\n * Validate a canonical Core model-output message.\n *\n * Unknown item types and malformed executable items fail the whole envelope\n * closed. The exact `raw` field is never parsed to discover actions.\n */\nexport function parseModelOutputMessage(value: unknown): ModelOutputMessage | null {\n const hasLogicalTurnId =\n isRecord(value) &&\n Object.prototype.hasOwnProperty.call(value, \"logical_turn_id\");\n if (\n !isRecord(value) ||\n value.type !== \"model-output\" ||\n value.version !== 2 ||\n !isNonEmptyString(value.output_id) ||\n (hasLogicalTurnId && !isValidLogicalTurnId(value.logical_turn_id)) ||\n ![\n \"text\",\n \"convai-combined-json\",\n \"semantic-actions-json\",\n \"client-tool-calls-json\",\n ].includes(value.format as string) ||\n typeof value.raw !== \"string\" ||\n value.final !== true ||\n !Array.isArray(value.items)\n ) {\n return null;\n }\n\n const items = value.items.map(parseModelOutputItem);\n if (items.some((item) => item === null)) return null;\n\n const actionItemIds = new Set<string>();\n for (const item of items as ModelOutputItem[]) {\n if (item.type !== \"semantic_action\" && item.type !== \"tool_call\") continue;\n if (actionItemIds.has(item.id)) return null;\n actionItemIds.add(item.id);\n }\n\n return {\n type: \"model-output\",\n version: 2,\n output_id: value.output_id,\n ...(hasLogicalTurnId && {\n logical_turn_id: value.logical_turn_id as string,\n }),\n format: value.format as ModelOutputMessage[\"format\"],\n raw: value.raw,\n items: items as ModelOutputItem[],\n final: true,\n };\n}\n\nexport type ExtensionRenderResult<T> =\n | { status: \"rendered\"; value: T }\n | { status: \"fallback\"; fallback: string }\n | { status: \"unhandled\" };\n\nexport type ModelOutputExtensionRenderer<T> = (\n item: ModelOutputExtensionItem,\n) => T;\n\n/**\n * UI-framework-neutral registry for developer extension renderers.\n *\n * The SDK never evaluates extension payloads. Applications explicitly\n * register a renderer for one schema/version pair and receive JSON data.\n */\nexport class ModelOutputExtensionRegistry<T> {\n private readonly renderers = new Map<\n string,\n ModelOutputExtensionRenderer<T>\n >();\n\n register(\n schema: string,\n version: number,\n renderer: ModelOutputExtensionRenderer<T>,\n ): () => void {\n if (!schema.trim() || !Number.isInteger(version) || version < 1) {\n throw new Error(\"Extension schema and positive integer version are required\");\n }\n const key = this.key(schema, version);\n this.renderers.set(key, renderer);\n return () => {\n if (this.renderers.get(key) === renderer) this.renderers.delete(key);\n };\n }\n\n render(item: ModelOutputExtensionItem): ExtensionRenderResult<T> {\n const renderer = this.renderers.get(this.key(item.schema, item.version));\n if (renderer) return { status: \"rendered\", value: renderer(item) };\n if (item.fallback !== null && item.fallback !== undefined) {\n return { status: \"fallback\", fallback: item.fallback };\n }\n return { status: \"unhandled\" };\n }\n\n private key(schema: string, version: number): string {\n return `${schema}@${version}`;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"modelOutput.js","sourceRoot":"","sources":["../../src/core/modelOutput.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,oBAAoB,EACpB,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAE1B,SAAS,QAAQ,CAAC,KAAc;IAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,K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AG,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QACzE,IAAI,QAAQ;YAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACnE,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC1D,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;QACzD,CAAC;QACD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;IACjC,CAAC;IAEO,GAAG,CAAC,MAAc,EAAE,OAAe;QACzC,OAAO,GAAG,MAAM,IAAI,OAAO,EAAE,CAAC;IAChC,CAAC;CACF","sourcesContent":["import type {\n JsonObject,\n ModelOutputExtensionItem,\n ModelOutputItem,\n ModelOutputMessage,\n} from \"./types\";\nimport {\n isValidLogicalTurnId,\n isValidOutputId,\n} from \"./logicalTurn.js\";\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return false;\n }\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Normalize canonical model-output delivery across transports.\n *\n * LiveKit delivers the RTVI frame as a top-level message with its payload in\n * `data`; WebSocket delivery wraps that same payload in `server-message`.\n */\nexport function extractModelOutputPayload(value: unknown): unknown | undefined {\n if (!isRecord(value)) return undefined;\n if (value.type === \"model-output\") {\n return isRecord(value.data)\n ? { ...value.data, type: \"model-output\" }\n : value;\n }\n if (\n value.type === \"server-message\" &&\n isRecord(value.data) &&\n value.data.type === \"model-output\"\n ) {\n return value.data;\n }\n return undefined;\n}\n\nfunction isOptionalString(value: unknown): value is string | null | undefined {\n return value === undefined || value === null || typeof value === \"string\";\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value.trim().length > 0;\n}\n\nexport function isJsonValue(\n value: unknown,\n ancestors: Set<unknown> = new Set(),\n): value is import(\"./types\").JsonValue {\n if (\n value === null ||\n typeof value === \"string\" ||\n typeof value === \"boolean\"\n ) {\n return true;\n }\n if (typeof value === \"number\") return Number.isFinite(value);\n if (typeof value !== \"object\") return false;\n if (ancestors.has(value)) return false;\n\n ancestors.add(value);\n const valid = Array.isArray(value)\n ? value.every((item) => isJsonValue(item, ancestors))\n : isRecord(value) &&\n Object.values(value).every((item) => isJsonValue(item, ancestors));\n ancestors.delete(value);\n return valid;\n}\n\nexport function isJsonObject(value: unknown): value is JsonObject {\n return isRecord(value) && isJsonValue(value);\n}\n\nfunction parseModelOutputItem(value: unknown): ModelOutputItem | null {\n if (!isRecord(value) || typeof value.type !== \"string\") return null;\n\n switch (value.type) {\n case \"message\":\n if (\n value.role !== \"assistant\" ||\n (value.channel !== \"final\" && value.channel !== \"commentary\") ||\n typeof value.content !== \"string\"\n ) {\n return null;\n }\n return value as unknown as ModelOutputItem;\n case \"emotion\":\n if (\n !isNonEmptyString(value.name) ||\n (value.scale !== 1 && value.scale !== 2 && value.scale !== 3)\n ) {\n return null;\n }\n return value as unknown as ModelOutputItem;\n case \"semantic_action\":\n if (\n !isNonEmptyString(value.id) ||\n !isNonEmptyString(value.name) ||\n !isOptionalString(value.target)\n ) {\n return null;\n }\n return value as unknown as ModelOutputItem;\n case \"tool_call\":\n if (\n !isNonEmptyString(value.id) ||\n !isNonEmptyString(value.name) ||\n !isOptionalString(value.target) ||\n !isJsonObject(value.arguments)\n ) {\n return null;\n }\n return value as unknown as ModelOutputItem;\n case \"extension\":\n if (\n !isNonEmptyString(value.schema) ||\n !Number.isInteger(value.version) ||\n (value.version as number) < 1 ||\n !isJsonObject(value.payload) ||\n !isOptionalString(value.fallback)\n ) {\n return null;\n }\n return value as unknown as ModelOutputItem;\n default:\n return null;\n }\n}\n\n/**\n * Validate a canonical Core model-output message.\n *\n * Unknown item types and malformed executable items fail the whole envelope\n * closed. The exact `raw` field is never parsed to discover actions.\n */\nexport function parseModelOutputMessage(value: unknown): ModelOutputMessage | null {\n const hasLogicalTurnId =\n isRecord(value) &&\n Object.prototype.hasOwnProperty.call(value, \"logical_turn_id\");\n if (\n !isRecord(value) ||\n value.type !== \"model-output\" ||\n value.version !== 2 ||\n !isValidOutputId(value.output_id) ||\n (hasLogicalTurnId && !isValidLogicalTurnId(value.logical_turn_id)) ||\n ![\n \"text\",\n \"convai-combined-json\",\n \"semantic-actions-json\",\n \"client-tool-calls-json\",\n ].includes(value.format as string) ||\n typeof value.raw !== \"string\" ||\n value.final !== true ||\n !Array.isArray(value.items)\n ) {\n return null;\n }\n\n const items = value.items.map(parseModelOutputItem);\n if (items.some((item) => item === null)) return null;\n\n const actionItemIds = new Set<string>();\n for (const item of items as ModelOutputItem[]) {\n if (item.type !== \"semantic_action\" && item.type !== \"tool_call\") continue;\n if (actionItemIds.has(item.id)) return null;\n actionItemIds.add(item.id);\n }\n\n return {\n type: \"model-output\",\n version: 2,\n output_id: value.output_id,\n ...(hasLogicalTurnId && {\n logical_turn_id: value.logical_turn_id as string,\n }),\n format: value.format as ModelOutputMessage[\"format\"],\n raw: value.raw,\n items: items as ModelOutputItem[],\n final: true,\n };\n}\n\nexport type ExtensionRenderResult<T> =\n | { status: \"rendered\"; value: T }\n | { status: \"fallback\"; fallback: string }\n | { status: \"unhandled\" };\n\nexport type ModelOutputExtensionRenderer<T> = (\n item: ModelOutputExtensionItem,\n) => T;\n\n/**\n * UI-framework-neutral registry for developer extension renderers.\n *\n * The SDK never evaluates extension payloads. Applications explicitly\n * register a renderer for one schema/version pair and receive JSON data.\n */\nexport class ModelOutputExtensionRegistry<T> {\n private readonly renderers = new Map<\n string,\n ModelOutputExtensionRenderer<T>\n >();\n\n register(\n schema: string,\n version: number,\n renderer: ModelOutputExtensionRenderer<T>,\n ): () => void {\n if (!schema.trim() || !Number.isInteger(version) || version < 1) {\n throw new Error(\"Extension schema and positive integer version are required\");\n }\n const key = this.key(schema, version);\n this.renderers.set(key, renderer);\n return () => {\n if (this.renderers.get(key) === renderer) this.renderers.delete(key);\n };\n }\n\n render(item: ModelOutputExtensionItem): ExtensionRenderResult<T> {\n const renderer = this.renderers.get(this.key(item.schema, item.version));\n if (renderer) return { status: \"rendered\", value: renderer(item) };\n if (item.fallback !== null && item.fallback !== undefined) {\n return { status: \"fallback\", fallback: item.fallback };\n }\n return { status: \"unhandled\" };\n }\n\n private key(schema: string, version: number): string {\n return `${schema}@${version}`;\n }\n}\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"}
|