@convai/web-sdk 1.8.0-beta.5 → 1.8.0-beta.7
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 +333 -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 +152 -2
- package/dist/core/ConvaiClient.d.ts.map +1 -1
- package/dist/core/ConvaiClient.js +1036 -49
- 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 +25 -0
- package/dist/core/MessageHandler.d.ts.map +1 -1
- package/dist/core/MessageHandler.js +431 -30
- 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 +38 -2
- package/dist/core/connectRequest.d.ts.map +1 -1
- package/dist/core/connectRequest.js +57 -0
- package/dist/core/connectRequest.js.map +1 -1
- package/dist/core/index.d.ts +6 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +5 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/logicalTurn.d.ts +4 -1
- package/dist/core/logicalTurn.d.ts.map +1 -1
- package/dist/core/logicalTurn.js +35 -4
- package/dist/core/logicalTurn.js.map +1 -1
- package/dist/core/modelOutput.d.ts +40 -0
- package/dist/core/modelOutput.d.ts.map +1 -0
- package/dist/core/modelOutput.js +187 -0
- package/dist/core/modelOutput.js.map +1 -0
- package/dist/core/publishedChat.d.ts +9 -0
- package/dist/core/publishedChat.d.ts.map +1 -0
- package/dist/core/publishedChat.js +13 -0
- package/dist/core/publishedChat.js.map +1 -0
- 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 +667 -10
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/embed/ConvaiChatElement.d.ts +27 -0
- package/dist/embed/ConvaiChatElement.d.ts.map +1 -0
- package/dist/embed/ConvaiChatElement.js +300 -0
- package/dist/embed/ConvaiChatElement.js.map +1 -0
- package/dist/embed/browser.d.ts +3 -0
- package/dist/embed/browser.d.ts.map +1 -0
- package/dist/embed/browser.js +5 -0
- package/dist/embed/browser.js.map +1 -0
- package/dist/embed/chat-embed-v1.js +100 -0
- package/dist/embed/chat-embed-v1.js.map +7 -0
- package/dist/embed/index.d.ts +9 -0
- package/dist/embed/index.d.ts.map +1 -0
- package/dist/embed/index.js +9 -0
- package/dist/embed/index.js.map +1 -0
- package/dist/embed/publicationApi.d.ts +23 -0
- package/dist/embed/publicationApi.d.ts.map +1 -0
- package/dist/embed/publicationApi.js +141 -0
- package/dist/embed/publicationApi.js.map +1 -0
- package/dist/react/components/ConvaiWidget.d.ts +11 -1
- package/dist/react/components/ConvaiWidget.d.ts.map +1 -1
- package/dist/react/components/ConvaiWidget.js +67 -11
- package/dist/react/components/ConvaiWidget.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/components/rtc-widget/components/conviComponents/SettingsTray.d.ts +1 -1
- package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.d.ts.map +1 -1
- package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.js +2 -2
- package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.js.map +1 -1
- package/dist/react/hooks/useConvaiClient.d.ts +2 -0
- package/dist/react/hooks/useConvaiClient.d.ts.map +1 -1
- package/dist/react/hooks/useConvaiClient.js +16 -0
- package/dist/react/hooks/useConvaiClient.js.map +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +1 -1
- package/dist/react/index.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 +224 -89
- package/dist/vanilla/ConvaiWidget.js.map +1 -1
- package/dist/vanilla/WidgetEventSubscriptions.d.ts +15 -0
- package/dist/vanilla/WidgetEventSubscriptions.d.ts.map +1 -0
- package/dist/vanilla/WidgetEventSubscriptions.js +37 -0
- package/dist/vanilla/WidgetEventSubscriptions.js.map +1 -0
- package/dist/vanilla/index.d.ts +2 -1
- package/dist/vanilla/index.d.ts.map +1 -1
- package/dist/vanilla/index.js +2 -1
- package/dist/vanilla/index.js.map +1 -1
- package/dist/vanilla/types.d.ts +8 -1
- 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.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +19 -6
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed failure from a room-topology request (`connect()` with a roster, or
|
|
3
|
+
* `joinRoom()`).
|
|
4
|
+
*
|
|
5
|
+
* The runtime answers these with a named code and a `request_trace_id`, and the
|
|
6
|
+
* backend's whole troubleshooting procedure starts from that trace id — it
|
|
7
|
+
* correlates API logs, room records, membership rows, actor logs and LiveKit.
|
|
8
|
+
* A plain `Error` throws it away, so this class carries it through to the
|
|
9
|
+
* caller alongside the status and the machine-readable code.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ConvaiRoomError extends Error {
|
|
12
|
+
readonly status: number;
|
|
13
|
+
/** Named code such as `ROSTER_FINGERPRINT_MISMATCH`, or null when the body carried none. */
|
|
14
|
+
readonly code: string | null;
|
|
15
|
+
/** Quote this to backend support; it correlates every log for the request. */
|
|
16
|
+
readonly requestTraceId: string | null;
|
|
17
|
+
/** The parsed response body, or the raw text when it was not JSON. */
|
|
18
|
+
readonly detail: unknown;
|
|
19
|
+
constructor(message: string, status: number, code: string | null, requestTraceId: string | null, detail: unknown);
|
|
20
|
+
/**
|
|
21
|
+
* True when retrying the identical payload can plausibly succeed.
|
|
22
|
+
*
|
|
23
|
+
* Only the two "still working on it" conflicts qualify. A fingerprint
|
|
24
|
+
* mismatch means the topology genuinely differs, and a capacity or
|
|
25
|
+
* entitlement rejection will not change on its own — retrying those just
|
|
26
|
+
* burns the room's provisioning window.
|
|
27
|
+
*/
|
|
28
|
+
get isRetryable(): boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Pull a named code out of a parsed error body.
|
|
32
|
+
*
|
|
33
|
+
* The runtime is not consistent about where it puts one: some rejections carry
|
|
34
|
+
* `{ code }`, some put the name in `detail` as a bare string, and some nest it
|
|
35
|
+
* under `detail.code`. A code is never synthesised from the status — callers
|
|
36
|
+
* branch on it, and inventing `"CONFLICT"` for every 409 would make
|
|
37
|
+
* `ROSTER_FINGERPRINT_MISMATCH` and `ROSTER_PROVISIONING_IN_PROGRESS`
|
|
38
|
+
* indistinguishable, which is exactly the distinction that decides whether to
|
|
39
|
+
* retry.
|
|
40
|
+
*/
|
|
41
|
+
export declare function extractRoomErrorCode(body: unknown): string | null;
|
|
42
|
+
/** Pull the trace id out of a parsed body, wherever the layer put it. */
|
|
43
|
+
export declare function extractRequestTraceId(body: unknown): string | null;
|
|
44
|
+
/** Human-readable message from a body, falling back to the status. */
|
|
45
|
+
export declare function extractRoomErrorMessage(body: unknown, status: number): string;
|
|
46
|
+
/** Build a `ConvaiRoomError` from a response status and its parsed body. */
|
|
47
|
+
export declare function roomErrorFromResponse(status: number, body: unknown): ConvaiRoomError;
|
|
48
|
+
//# sourceMappingURL=ConvaiRoomError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConvaiRoomError.d.ts","sourceRoot":"","sources":["../../src/core/ConvaiRoomError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,4FAA4F;IAC5F,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,8EAA8E;IAC9E,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;gBAGvB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,cAAc,EAAE,MAAM,GAAG,IAAI,EAC7B,MAAM,EAAE,OAAO;IAUjB;;;;;;;OAOG;IACH,IAAI,WAAW,IAAI,OAAO,CAMzB;CACF;AAKD;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAgBjE;AAUD,yEAAyE;AACzE,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAUlE;AAED,sEAAsE;AACtE,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAc7E;AAED,4EAA4E;AAC5E,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,GACZ,eAAe,CAQjB"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed failure from a room-topology request (`connect()` with a roster, or
|
|
3
|
+
* `joinRoom()`).
|
|
4
|
+
*
|
|
5
|
+
* The runtime answers these with a named code and a `request_trace_id`, and the
|
|
6
|
+
* backend's whole troubleshooting procedure starts from that trace id — it
|
|
7
|
+
* correlates API logs, room records, membership rows, actor logs and LiveKit.
|
|
8
|
+
* A plain `Error` throws it away, so this class carries it through to the
|
|
9
|
+
* caller alongside the status and the machine-readable code.
|
|
10
|
+
*/
|
|
11
|
+
export class ConvaiRoomError extends Error {
|
|
12
|
+
constructor(message, status, code, requestTraceId, detail) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = "ConvaiRoomError";
|
|
15
|
+
this.status = status;
|
|
16
|
+
this.code = code;
|
|
17
|
+
this.requestTraceId = requestTraceId;
|
|
18
|
+
this.detail = detail;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* True when retrying the identical payload can plausibly succeed.
|
|
22
|
+
*
|
|
23
|
+
* Only the two "still working on it" conflicts qualify. A fingerprint
|
|
24
|
+
* mismatch means the topology genuinely differs, and a capacity or
|
|
25
|
+
* entitlement rejection will not change on its own — retrying those just
|
|
26
|
+
* burns the room's provisioning window.
|
|
27
|
+
*/
|
|
28
|
+
get isRetryable() {
|
|
29
|
+
if (this.status !== 409)
|
|
30
|
+
return false;
|
|
31
|
+
return (this.code === "ROSTER_PROVISIONING_IN_PROGRESS" ||
|
|
32
|
+
this.code === "CONNECT_ATTEMPT_IN_PROGRESS");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** Response bodies differ by layer; a code can arrive under any of these. */
|
|
36
|
+
const CODE_KEYS = ["code", "error_code", "detail_code"];
|
|
37
|
+
/**
|
|
38
|
+
* Pull a named code out of a parsed error body.
|
|
39
|
+
*
|
|
40
|
+
* The runtime is not consistent about where it puts one: some rejections carry
|
|
41
|
+
* `{ code }`, some put the name in `detail` as a bare string, and some nest it
|
|
42
|
+
* under `detail.code`. A code is never synthesised from the status — callers
|
|
43
|
+
* branch on it, and inventing `"CONFLICT"` for every 409 would make
|
|
44
|
+
* `ROSTER_FINGERPRINT_MISMATCH` and `ROSTER_PROVISIONING_IN_PROGRESS`
|
|
45
|
+
* indistinguishable, which is exactly the distinction that decides whether to
|
|
46
|
+
* retry.
|
|
47
|
+
*/
|
|
48
|
+
export function extractRoomErrorCode(body) {
|
|
49
|
+
if (typeof body === "string")
|
|
50
|
+
return looksLikeCode(body) ? body : null;
|
|
51
|
+
if (typeof body !== "object" || body === null)
|
|
52
|
+
return null;
|
|
53
|
+
const record = body;
|
|
54
|
+
for (const key of CODE_KEYS) {
|
|
55
|
+
const value = record[key];
|
|
56
|
+
if (typeof value === "string" && value)
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
const detail = record.detail;
|
|
60
|
+
if (typeof detail === "string")
|
|
61
|
+
return looksLikeCode(detail) ? detail : null;
|
|
62
|
+
if (typeof detail === "object" && detail !== null) {
|
|
63
|
+
return extractRoomErrorCode(detail);
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* A code is SCREAMING_SNAKE_CASE. `detail` is also where human prose lands
|
|
69
|
+
* ("Human room capacity reached"), so shape is what tells the two apart.
|
|
70
|
+
*/
|
|
71
|
+
function looksLikeCode(value) {
|
|
72
|
+
return /^[A-Z][A-Z0-9_]{2,}$/.test(value.trim());
|
|
73
|
+
}
|
|
74
|
+
/** Pull the trace id out of a parsed body, wherever the layer put it. */
|
|
75
|
+
export function extractRequestTraceId(body) {
|
|
76
|
+
if (typeof body !== "object" || body === null)
|
|
77
|
+
return null;
|
|
78
|
+
const record = body;
|
|
79
|
+
const direct = record.request_trace_id;
|
|
80
|
+
if (typeof direct === "string" && direct)
|
|
81
|
+
return direct;
|
|
82
|
+
const detail = record.detail;
|
|
83
|
+
if (typeof detail === "object" && detail !== null) {
|
|
84
|
+
return extractRequestTraceId(detail);
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
/** Human-readable message from a body, falling back to the status. */
|
|
89
|
+
export function extractRoomErrorMessage(body, status) {
|
|
90
|
+
if (typeof body === "string" && body.trim())
|
|
91
|
+
return body.trim();
|
|
92
|
+
if (typeof body === "object" && body !== null) {
|
|
93
|
+
const record = body;
|
|
94
|
+
for (const key of ["message", "detail", "error"]) {
|
|
95
|
+
const value = record[key];
|
|
96
|
+
if (typeof value === "string" && value.trim())
|
|
97
|
+
return value.trim();
|
|
98
|
+
if (typeof value === "object" && value !== null) {
|
|
99
|
+
const nested = extractRoomErrorMessage(value, status);
|
|
100
|
+
if (!nested.startsWith("Room request failed"))
|
|
101
|
+
return nested;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return `Room request failed with HTTP ${status}`;
|
|
106
|
+
}
|
|
107
|
+
/** Build a `ConvaiRoomError` from a response status and its parsed body. */
|
|
108
|
+
export function roomErrorFromResponse(status, body) {
|
|
109
|
+
return new ConvaiRoomError(extractRoomErrorMessage(body, status), status, extractRoomErrorCode(body), extractRequestTraceId(body), body);
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=ConvaiRoomError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConvaiRoomError.js","sourceRoot":"","sources":["../../src/core/ConvaiRoomError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IASxC,YACE,OAAe,EACf,MAAc,EACd,IAAmB,EACnB,cAA6B,EAC7B,MAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GA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K,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBAChD,MAAM,MAAM,GAAG,uBAAuB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;gBACtD,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,qBAAqB,CAAC;oBAAE,OAAO,MAAM,CAAC;YAC/D,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,iCAAiC,MAAM,EAAE,CAAC;AACnD,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,qBAAqB,CACnC,MAAc,EACd,IAAa;IAEb,OAAO,IAAI,eAAe,CACxB,uBAAuB,CAAC,IAAI,EAAE,MAAM,CAAC,EACrC,MAAM,EACN,oBAAoB,CAAC,IAAI,CAAC,EAC1B,qBAAqB,CAAC,IAAI,CAAC,EAC3B,IAAI,CACL,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Typed failure from a room-topology request (`connect()` with a roster, or\n * `joinRoom()`).\n *\n * The runtime answers these with a named code and a `request_trace_id`, and the\n * backend's whole troubleshooting procedure starts from that trace id — it\n * correlates API logs, room records, membership rows, actor logs and LiveKit.\n * A plain `Error` throws it away, so this class carries it through to the\n * caller alongside the status and the machine-readable code.\n */\nexport class ConvaiRoomError extends Error {\n readonly status: number;\n /** Named code such as `ROSTER_FINGERPRINT_MISMATCH`, or null when the body carried none. */\n readonly code: string | null;\n /** Quote this to backend support; it correlates every log for the request. */\n readonly requestTraceId: string | null;\n /** The parsed response body, or the raw text when it was not JSON. */\n readonly detail: unknown;\n\n constructor(\n message: string,\n status: number,\n code: string | null,\n requestTraceId: string | null,\n detail: unknown,\n ) {\n super(message);\n this.name = \"ConvaiRoomError\";\n this.status = status;\n this.code = code;\n this.requestTraceId = requestTraceId;\n this.detail = detail;\n }\n\n /**\n * True when retrying the identical payload can plausibly succeed.\n *\n * Only the two \"still working on it\" conflicts qualify. A fingerprint\n * mismatch means the topology genuinely differs, and a capacity or\n * entitlement rejection will not change on its own — retrying those just\n * burns the room's provisioning window.\n */\n get isRetryable(): boolean {\n if (this.status !== 409) return false;\n return (\n this.code === \"ROSTER_PROVISIONING_IN_PROGRESS\" ||\n this.code === \"CONNECT_ATTEMPT_IN_PROGRESS\"\n );\n }\n}\n\n/** Response bodies differ by layer; a code can arrive under any of these. */\nconst CODE_KEYS = [\"code\", \"error_code\", \"detail_code\"] as const;\n\n/**\n * Pull a named code out of a parsed error body.\n *\n * The runtime is not consistent about where it puts one: some rejections carry\n * `{ code }`, some put the name in `detail` as a bare string, and some nest it\n * under `detail.code`. A code is never synthesised from the status — callers\n * branch on it, and inventing `\"CONFLICT\"` for every 409 would make\n * `ROSTER_FINGERPRINT_MISMATCH` and `ROSTER_PROVISIONING_IN_PROGRESS`\n * indistinguishable, which is exactly the distinction that decides whether to\n * retry.\n */\nexport function extractRoomErrorCode(body: unknown): string | null {\n if (typeof body === \"string\") return looksLikeCode(body) ? body : null;\n if (typeof body !== \"object\" || body === null) return null;\n\n const record = body as Record<string, unknown>;\n for (const key of CODE_KEYS) {\n const value = record[key];\n if (typeof value === \"string\" && value) return value;\n }\n\n const detail = record.detail;\n if (typeof detail === \"string\") return looksLikeCode(detail) ? detail : null;\n if (typeof detail === \"object\" && detail !== null) {\n return extractRoomErrorCode(detail);\n }\n return null;\n}\n\n/**\n * A code is SCREAMING_SNAKE_CASE. `detail` is also where human prose lands\n * (\"Human room capacity reached\"), so shape is what tells the two apart.\n */\nfunction looksLikeCode(value: string): boolean {\n return /^[A-Z][A-Z0-9_]{2,}$/.test(value.trim());\n}\n\n/** Pull the trace id out of a parsed body, wherever the layer put it. */\nexport function extractRequestTraceId(body: unknown): string | null {\n if (typeof body !== \"object\" || body === null) return null;\n const record = body as Record<string, unknown>;\n const direct = record.request_trace_id;\n if (typeof direct === \"string\" && direct) return direct;\n const detail = record.detail;\n if (typeof detail === \"object\" && detail !== null) {\n return extractRequestTraceId(detail);\n }\n return null;\n}\n\n/** Human-readable message from a body, falling back to the status. */\nexport function extractRoomErrorMessage(body: unknown, status: number): string {\n if (typeof body === \"string\" && body.trim()) return body.trim();\n if (typeof body === \"object\" && body !== null) {\n const record = body as Record<string, unknown>;\n for (const key of [\"message\", \"detail\", \"error\"]) {\n const value = record[key];\n if (typeof value === \"string\" && value.trim()) return value.trim();\n if (typeof value === \"object\" && value !== null) {\n const nested = extractRoomErrorMessage(value, status);\n if (!nested.startsWith(\"Room request failed\")) return nested;\n }\n }\n }\n return `Room request failed with HTTP ${status}`;\n}\n\n/** Build a `ConvaiRoomError` from a response status and its parsed body. */\nexport function roomErrorFromResponse(\n status: number,\n body: unknown,\n): ConvaiRoomError {\n return new ConvaiRoomError(\n extractRoomErrorMessage(body, status),\n status,\n extractRoomErrorCode(body),\n extractRequestTraceId(body),\n body,\n );\n}\n"]}
|
|
@@ -18,6 +18,9 @@ export declare class MessageHandler extends EventEmitter {
|
|
|
18
18
|
private totalBlendshapesReceived;
|
|
19
19
|
private blendshapeQueue;
|
|
20
20
|
private _currentEmotion;
|
|
21
|
+
private modelOutputVersion;
|
|
22
|
+
private seenModelOutputPayloads;
|
|
23
|
+
private seenModelOutputPayloadCharacters;
|
|
21
24
|
private seenBotOutputSegments;
|
|
22
25
|
private readonly _boundHandleDataReceived;
|
|
23
26
|
constructor(room?: Room);
|
|
@@ -29,6 +32,8 @@ export declare class MessageHandler extends EventEmitter {
|
|
|
29
32
|
* Enable or disable console logging for decoded incoming RTVI messages.
|
|
30
33
|
*/
|
|
31
34
|
setRtviMessageLogging(enabled: boolean): void;
|
|
35
|
+
/** Select the server-negotiated canonical output version for this session. */
|
|
36
|
+
setModelOutputVersion(version: 1 | 2): void;
|
|
32
37
|
/**
|
|
33
38
|
* Get current chat messages
|
|
34
39
|
*/
|
|
@@ -80,12 +85,32 @@ export declare class MessageHandler extends EventEmitter {
|
|
|
80
85
|
*/
|
|
81
86
|
private handleDataReceived;
|
|
82
87
|
private _handleActionResponse;
|
|
88
|
+
private _handleModelOutput;
|
|
89
|
+
private _clearModelOutputReplayLedger;
|
|
90
|
+
private _handleBotLlmTextRaw;
|
|
83
91
|
private lifecycleOwner;
|
|
84
92
|
private numberOrUndefined;
|
|
93
|
+
private transcriptionLogicalTurnId;
|
|
85
94
|
/**
|
|
86
95
|
* Public entry point for WebSocket transport to inject messages into the same pipeline.
|
|
87
96
|
*/
|
|
88
97
|
handleDataReceivedPublic(payload: Uint8Array): void;
|
|
98
|
+
/** Append a submitted text message without waiting for a server echo. */
|
|
99
|
+
addUserTextMessage(text: string): void;
|
|
100
|
+
/**
|
|
101
|
+
* Insert a message into the transcript locally. Nothing is transmitted and
|
|
102
|
+
* no LLM turn is billed -- this is for client-side lines (a greeting, a
|
|
103
|
+
* system notice, a replayed history entry) that must appear in the chat.
|
|
104
|
+
*
|
|
105
|
+
* Subscribers see it through the same `messagesChange` as a live message,
|
|
106
|
+
* so React and the widgets pick it up with no special casing.
|
|
107
|
+
*/
|
|
108
|
+
appendLocalMessage(message: {
|
|
109
|
+
sender: "user" | "bot";
|
|
110
|
+
content: string;
|
|
111
|
+
membershipId?: string;
|
|
112
|
+
characterId?: string;
|
|
113
|
+
}): ChatMessage;
|
|
89
114
|
/**
|
|
90
115
|
* Reset message state
|
|
91
116
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageHandler.d.ts","sourceRoot":"","sources":["../../src/core/MessageHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAa,MAAM,gBAAgB,CAAC;AACjD,OAAO,
|
|
1
|
+
{"version":3,"file":"MessageHandler.d.ts","sourceRoot":"","sources":["../../src/core/MessageHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAa,MAAM,gBAAgB,CAAC;AACjD,OAAO,EACL,WAAW,EAQZ,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAM9C,OAAO,EACL,eAAe,EAEhB,MAAM,mBAAmB,CAAC;AA8B3B;;;GAGG;AACH,qBAAa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