@convai/web-sdk 1.3.2-beta.0 → 1.4.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +258 -6
- package/dist/core/AudioManager.d.ts +4 -0
- package/dist/core/AudioManager.d.ts.map +1 -1
- package/dist/core/AudioManager.js +26 -0
- package/dist/core/AudioManager.js.map +1 -1
- package/dist/core/ConvaiClient.d.ts +34 -0
- package/dist/core/ConvaiClient.d.ts.map +1 -1
- package/dist/core/ConvaiClient.js +302 -225
- package/dist/core/ConvaiClient.js.map +1 -1
- package/dist/core/MessageHandler.d.ts +10 -0
- package/dist/core/MessageHandler.d.ts.map +1 -1
- package/dist/core/MessageHandler.js +86 -22
- package/dist/core/MessageHandler.js.map +1 -1
- package/dist/core/WebSocketSession.d.ts +45 -0
- package/dist/core/WebSocketSession.d.ts.map +1 -0
- package/dist/core/WebSocketSession.js +133 -0
- package/dist/core/WebSocketSession.js.map +1 -0
- package/dist/core/types.d.ts +77 -49
- package/dist/core/types.d.ts.map +1 -1
- package/dist/react/components/ConvaiWidget.d.ts.map +1 -1
- package/dist/react/components/ConvaiWidget.js +25 -14
- package/dist/react/components/ConvaiWidget.js.map +1 -1
- 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/vanilla/AudioRenderer.d.ts +6 -0
- package/dist/vanilla/AudioRenderer.d.ts.map +1 -1
- package/dist/vanilla/AudioRenderer.js +21 -0
- package/dist/vanilla/AudioRenderer.js.map +1 -1
- package/dist/vanilla/types.d.ts +3 -1
- package/dist/vanilla/types.d.ts.map +1 -1
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -18,8 +18,11 @@ This document is written as a complete implementation reference, from first setu
|
|
|
18
18
|
- [5. Build a Chatbot from Scratch](#5-build-a-chatbot-from-scratch)
|
|
19
19
|
- [6. Core Concepts and Lifecycle](#6-core-concepts-and-lifecycle)
|
|
20
20
|
- [7. Configuration Reference (`ConvaiConfig`)](#7-configuration-reference-convaiconfig)
|
|
21
|
+
- [Transport Options](#transport-options)
|
|
21
22
|
- [8. Core API Reference (`ConvaiClient`)](#8-core-api-reference-convaiclient)
|
|
22
23
|
- [Idle management and LLM silence handling](#idle-management-and-llm-silence-handling)
|
|
24
|
+
- [Server acknowledgments (`serverResponse`)](#server-acknowledgments-serverresponse)
|
|
25
|
+
- [Interaction lifecycle (`interactionCreated`)](#interaction-lifecycle-interactioncreated)
|
|
23
26
|
- [9. Memory Management API](#9-memory-management-api)
|
|
24
27
|
- [10. Message Semantics and Turn Completion](#10-message-semantics-and-turn-completion)
|
|
25
28
|
- [11. React API Reference](#11-react-api-reference)
|
|
@@ -147,6 +150,7 @@ Do not hardcode credentials in source files.
|
|
|
147
150
|
VITE_CONVAI_API_KEY=<YOUR_CONVAI_API_KEY>
|
|
148
151
|
VITE_CONVAI_CHARACTER_ID=<YOUR_CONVAI_CHARACTER_ID>
|
|
149
152
|
VITE_CONVAI_API_URL=<OPTIONAL_CONVAI_BASE_URL>
|
|
153
|
+
VITE_CONVAI_LOG_RTVI_MESSAGES=false # optional; incoming/outgoing RTVI logs are on by default
|
|
150
154
|
```
|
|
151
155
|
|
|
152
156
|
Use these values through your build system (`import.meta.env`, process env injection, or server-provided config).
|
|
@@ -417,6 +421,7 @@ Both React and vanilla widgets:
|
|
|
417
421
|
|
|
418
422
|
| Field | Type | Required | Default | Description |
|
|
419
423
|
| ----------------------------------------- | ------------------ | -------- | -------------------- | ----------------------------------------------------------------------------------- |
|
|
424
|
+
| `transport` | `"livekit" \| "websocket"` | No | `"livekit"` | Transport layer for the session. See [Transport Options](#transport-options). |
|
|
420
425
|
| `apiKey` | `string` | Yes | - | Convai API key. |
|
|
421
426
|
| `characterId` | `string` | Yes | - | Target character identifier. |
|
|
422
427
|
| `endUserId` | `string` | No | `undefined` | Stable end-user identity for memory/analytics continuity. |
|
|
@@ -432,6 +437,54 @@ Both React and vanilla widgets:
|
|
|
432
437
|
| `actionConfig` | object | No | `undefined` | Action and scene-context metadata (actions, characters, objects, attention object). |
|
|
433
438
|
| `dynamicInfo` | `string` | No | `undefined` | Dynamic contextual information about the current situation sent to the LLM. |
|
|
434
439
|
| `keepInContext` | `boolean` | No | `false` | Keep dynamic info in context as a static prompt. When true, persists throughout session; when false, allows updates via updateContext() or updateDynamicInfo(). |
|
|
440
|
+
| `logRtviMessages` | `boolean` | No | `true` | Log incoming and outgoing decoded RTVI data messages to the browser console. Set to `false` to disable. |
|
|
441
|
+
|
|
442
|
+
### Transport Options
|
|
443
|
+
|
|
444
|
+
The SDK supports two transport layers, selectable via the `transport` config field.
|
|
445
|
+
|
|
446
|
+
#### `"livekit"` (default)
|
|
447
|
+
|
|
448
|
+
Uses WebRTC via LiveKit. This is the default and is recommended for most use cases.
|
|
449
|
+
|
|
450
|
+
- Full duplex audio with echo cancellation and noise suppression
|
|
451
|
+
- Hardware-accelerated media pipeline in the browser
|
|
452
|
+
- Supports video, camera, and screen share
|
|
453
|
+
- Requires WebRTC support in the browser (all modern browsers)
|
|
454
|
+
|
|
455
|
+
#### `"websocket"` _(new in v1.4.0)_
|
|
456
|
+
|
|
457
|
+
Uses a WebSocket connection via the [Pipecat RTVI](https://github.com/pipecat-ai/pipecat) protocol. Useful when WebRTC is unavailable or undesirable (e.g. certain network environments, proxied deployments, or server-side rendering contexts).
|
|
458
|
+
|
|
459
|
+
- Audio over WebSocket — no WebRTC peer connection required
|
|
460
|
+
- Same event model and `ConvaiClient` API as the LiveKit transport
|
|
461
|
+
- Lipsync (`enableLipsync`) is supported
|
|
462
|
+
- Video, camera, and screen share are not available
|
|
463
|
+
- Slightly higher latency than WebRTC in typical network conditions
|
|
464
|
+
|
|
465
|
+
**Usage:**
|
|
466
|
+
|
|
467
|
+
```ts
|
|
468
|
+
const client = useConvaiClient({
|
|
469
|
+
apiKey: "...",
|
|
470
|
+
characterId: "...",
|
|
471
|
+
transport: "websocket",
|
|
472
|
+
});
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
or in vanilla:
|
|
476
|
+
|
|
477
|
+
```ts
|
|
478
|
+
const client = new ConvaiClient({
|
|
479
|
+
apiKey: "...",
|
|
480
|
+
characterId: "...",
|
|
481
|
+
transport: "websocket",
|
|
482
|
+
});
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
Everything else — events, `sendUserTextMessage`, `updateContext`, `actionConfig`, lipsync — works identically regardless of transport. You can switch between `"livekit"` and `"websocket"` by changing one field.
|
|
486
|
+
|
|
487
|
+
---
|
|
435
488
|
|
|
436
489
|
## 8. Core API Reference (`ConvaiClient`)
|
|
437
490
|
|
|
@@ -451,6 +504,9 @@ For TypeScript, use the types exported from the main package or core:
|
|
|
451
504
|
- **`ChatMessage`** — Single message in `client.chatMessages`.
|
|
452
505
|
- **`ConvaiMetrics`** — Metrics event structure containing data, timestamp, and unique identifier.
|
|
453
506
|
- **`AudioControls`**, **`VideoControls`**, **`ScreenShareControls`** — Types for the control managers exposed as `client.audioControls`, `client.videoControls`, `client.screenShareControls`.
|
|
507
|
+
- **`ServerResponse`** — Payload of the `serverResponse` event. Contains `event_type`, `status`, `message`, and `extras`. See [Server acknowledgments](#server-acknowledgments-serverresponse).
|
|
508
|
+
- **`ServerResponseExtras`** — Token-tracking and metadata returned in `serverResponse.extras` for each event type (e.g. `token_count`, `remaining_tokens`, `content` for `context-update`).
|
|
509
|
+
- **`InteractionCreated`** — Payload of the `interactionCreated` event. Contains `interactionId` and `characterSessionId`. See [Interaction lifecycle](#interaction-lifecycle-interactioncreated).
|
|
454
510
|
|
|
455
511
|
Example:
|
|
456
512
|
|
|
@@ -524,6 +580,8 @@ new ConvaiClient(config?: ConvaiConfig)
|
|
|
524
580
|
| `metrics` | `Record<string, unknown>` | Metrics data received from server. Multiple metrics events may occur per conversation. |
|
|
525
581
|
| `idleWarning` | `{ remainingSeconds: number \| null }` | Server warns that the session will be disconnected due to inactivity. `remainingSeconds` is the countdown until disconnection. Call `resetIdleTimer()` on any user activity to keep the session alive. |
|
|
526
582
|
| `llmNoResponse` | `void` | LLM explicitly chose not to respond (e.g. via an abstain tool call). Use this to clear any "thinking" indicator without expecting a reply. |
|
|
583
|
+
| `serverResponse` | `ServerResponse` | Server acknowledgment for every client-sent message. Contains `event_type` (which message triggered it), `status` (`"success"` \| `"error"` \| `"processing"` \| `"pending"`), `message` (human-readable description), and `extras` (event-specific data such as token counts for `context-update`). See [Server acknowledgments](#server-acknowledgments-serverresponse). |
|
|
584
|
+
| `interactionCreated` | `InteractionCreated` | Server assigned an interaction ID to this session. Contains `interactionId` and `characterSessionId`. Fire-once per session; useful for analytics and session tracking. See [Interaction lifecycle](#interaction-lifecycle-interactioncreated). |
|
|
527
585
|
|
|
528
586
|
### Control manager APIs
|
|
529
587
|
|
|
@@ -678,11 +736,13 @@ convaiClient.updateDynamicInfo("");
|
|
|
678
736
|
|
|
679
737
|
`updateContext()` gives you surgical control over the system instruction. It supports three modes and a `run_llm` flag that controls whether the LLM is triggered after the update.
|
|
680
738
|
|
|
681
|
-
| Field
|
|
682
|
-
|
|
683
|
-
| `
|
|
684
|
-
| `
|
|
685
|
-
| `
|
|
739
|
+
| Field | Values | Description |
|
|
740
|
+
|----------------------------|-----------------------------------------|--------------------------------------------------------------|
|
|
741
|
+
| `text` | `string` | The context text to apply. Required unless `mode` is `"reset"` or only `current_attention_object` is being updated. |
|
|
742
|
+
| `mode` | `"append"` \| `"replace"` \| `"reset"` | How the text is applied to the existing context. Defaults to `"append"`. |
|
|
743
|
+
| `run_llm` | `"true"` \| `"false"` \| `"auto"` | `"true"` runs the LLM immediately; `"false"` only updates the prompt; `"auto"` lets the LLM decide. Defaults to `"auto"`. |
|
|
744
|
+
| `current_attention_object` | `string` | Updates the object the character is currently focused on. Must match one of the `objects[].name` values from `actionConfig`. Pass an empty string to clear. |
|
|
745
|
+
| `remove_static` | `boolean` | Only applies when `mode` is `"reset"`. If `true`, also clears the static context (the `dynamicInfo` set at connect time). Defaults to `false`. |
|
|
686
746
|
|
|
687
747
|
```tsx
|
|
688
748
|
// Append new information and run the LLM immediately
|
|
@@ -699,11 +759,28 @@ convaiClient.updateContext({
|
|
|
699
759
|
run_llm: "false",
|
|
700
760
|
});
|
|
701
761
|
|
|
702
|
-
// Clear context
|
|
762
|
+
// Clear runtime context only (preserves static context from connect-time dynamicInfo)
|
|
703
763
|
convaiClient.updateContext({
|
|
704
764
|
mode: "reset",
|
|
705
765
|
run_llm: "auto",
|
|
706
766
|
});
|
|
767
|
+
|
|
768
|
+
// Clear everything — both runtime and static context
|
|
769
|
+
convaiClient.updateContext({
|
|
770
|
+
mode: "reset",
|
|
771
|
+
remove_static: true,
|
|
772
|
+
run_llm: "false",
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
// Update only the attention object without touching context text
|
|
776
|
+
convaiClient.updateContext({
|
|
777
|
+
current_attention_object: "golden_sword",
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
// Clear the attention object
|
|
781
|
+
convaiClient.updateContext({
|
|
782
|
+
current_attention_object: "",
|
|
783
|
+
});
|
|
707
784
|
```
|
|
708
785
|
|
|
709
786
|
**When to use each `run_llm` value:**
|
|
@@ -922,6 +999,181 @@ const unsubNoResponse = client.on("llmNoResponse", () => {
|
|
|
922
999
|
});
|
|
923
1000
|
```
|
|
924
1001
|
|
|
1002
|
+
### Server acknowledgments (`serverResponse`)
|
|
1003
|
+
|
|
1004
|
+
The server sends a `serverResponse` back for every message your client sends (`context-update`, `tts-toggle`, `trigger-message`, etc.). It tells you whether the server accepted or rejected the request, and for `context-update` it returns the current token budget so you can manage context size in real time.
|
|
1005
|
+
|
|
1006
|
+
The dynamic context budget is **50,000 estimated tokens** total: up to 20,000 for static context (set at connect time via `dynamicInfo`) and up to 30,000 for runtime context (`updateContext` calls). When the runtime budget fills up the server keeps the newest updates and silently trims the oldest, so track `remaining_tokens` if your application sends context at high frequency.
|
|
1007
|
+
|
|
1008
|
+
#### React
|
|
1009
|
+
|
|
1010
|
+
```tsx
|
|
1011
|
+
import { useConvaiClient } from "@convai/web-sdk";
|
|
1012
|
+
import { useState, useEffect } from "react";
|
|
1013
|
+
import type { ServerResponse } from "@convai/web-sdk";
|
|
1014
|
+
|
|
1015
|
+
function ContextMonitor() {
|
|
1016
|
+
const convaiClient = useConvaiClient({ /* config */ });
|
|
1017
|
+
const [tokenUsage, setTokenUsage] = useState<{ used: number; max: number } | null>(null);
|
|
1018
|
+
const [contextError, setContextError] = useState<string | null>(null);
|
|
1019
|
+
|
|
1020
|
+
useEffect(() => {
|
|
1021
|
+
const unsub = convaiClient.on("serverResponse", (response: ServerResponse) => {
|
|
1022
|
+
// Track token budget after every context update
|
|
1023
|
+
if (response.event_type === "context-update" && response.extras) {
|
|
1024
|
+
const { token_count, max_tokens } = response.extras;
|
|
1025
|
+
setTokenUsage({ used: token_count ?? 0, max: max_tokens ?? 50000 });
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
// Surface errors to the UI
|
|
1029
|
+
if (response.status === "error") {
|
|
1030
|
+
setContextError(`[${response.event_type}] ${response.message}`);
|
|
1031
|
+
} else {
|
|
1032
|
+
setContextError(null);
|
|
1033
|
+
}
|
|
1034
|
+
});
|
|
1035
|
+
|
|
1036
|
+
return unsub;
|
|
1037
|
+
}, [convaiClient]);
|
|
1038
|
+
|
|
1039
|
+
const pushContext = () => {
|
|
1040
|
+
convaiClient.updateContext({ text: "Player entered the dungeon.", mode: "append", run_llm: "false" });
|
|
1041
|
+
};
|
|
1042
|
+
|
|
1043
|
+
const resetContext = () => {
|
|
1044
|
+
convaiClient.updateContext({ mode: "reset", remove_static: false });
|
|
1045
|
+
};
|
|
1046
|
+
|
|
1047
|
+
return (
|
|
1048
|
+
<div>
|
|
1049
|
+
<button onClick={pushContext}>Push context</button>
|
|
1050
|
+
<button onClick={resetContext}>Reset context</button>
|
|
1051
|
+
{tokenUsage && (
|
|
1052
|
+
<p>
|
|
1053
|
+
Context: {tokenUsage.used} / {tokenUsage.max} tokens
|
|
1054
|
+
{tokenUsage.used / tokenUsage.max > 0.8 && " ⚠️ approaching limit"}
|
|
1055
|
+
</p>
|
|
1056
|
+
)}
|
|
1057
|
+
{contextError && <p style={{ color: "red" }}>Error: {contextError}</p>}
|
|
1058
|
+
</div>
|
|
1059
|
+
);
|
|
1060
|
+
}
|
|
1061
|
+
```
|
|
1062
|
+
|
|
1063
|
+
#### Vanilla TypeScript
|
|
1064
|
+
|
|
1065
|
+
```ts
|
|
1066
|
+
import { ConvaiClient } from "@convai/web-sdk/core";
|
|
1067
|
+
import type { ServerResponse } from "@convai/web-sdk/core";
|
|
1068
|
+
|
|
1069
|
+
const client = new ConvaiClient({ apiKey: "...", characterId: "..." });
|
|
1070
|
+
await client.connect();
|
|
1071
|
+
|
|
1072
|
+
client.on("serverResponse", (response: ServerResponse) => {
|
|
1073
|
+
if (response.event_type === "context-update" && response.extras) {
|
|
1074
|
+
const { token_count, max_tokens, remaining_tokens } = response.extras;
|
|
1075
|
+
updateTokenBar(token_count ?? 0, max_tokens ?? 50000);
|
|
1076
|
+
|
|
1077
|
+
if ((remaining_tokens ?? Infinity) < 5000) {
|
|
1078
|
+
showWarning("Context nearing limit — oldest updates will be trimmed.");
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
if (response.status === "error") {
|
|
1083
|
+
showError(`${response.event_type} failed: ${response.message}`);
|
|
1084
|
+
|
|
1085
|
+
// Context limit exceeded — reset runtime context and retry
|
|
1086
|
+
if (response.event_type === "context-update") {
|
|
1087
|
+
client.updateContext({ mode: "reset" });
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
});
|
|
1091
|
+
|
|
1092
|
+
// Push game state silently (no LLM trigger)
|
|
1093
|
+
function syncGameState(state: GameState) {
|
|
1094
|
+
client.updateContext({
|
|
1095
|
+
text: `Health: ${state.health}%, location: ${state.location}, enemies: ${state.enemies}`,
|
|
1096
|
+
mode: "replace",
|
|
1097
|
+
run_llm: "false",
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
// Notify the bot of a narrative event and trigger a response
|
|
1102
|
+
function onQuestComplete(questName: string) {
|
|
1103
|
+
client.updateContext({
|
|
1104
|
+
text: `Player just completed: ${questName}`,
|
|
1105
|
+
mode: "append",
|
|
1106
|
+
run_llm: "true",
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
// Clear everything at scene change
|
|
1111
|
+
function onSceneChange() {
|
|
1112
|
+
client.updateContext({ mode: "reset", remove_static: false });
|
|
1113
|
+
}
|
|
1114
|
+
```
|
|
1115
|
+
|
|
1116
|
+
### Interaction lifecycle (`interactionCreated`)
|
|
1117
|
+
|
|
1118
|
+
The server fires `interactionCreated` once per session after connecting, assigning a stable `interactionId` to the conversation. Use it for analytics, crash reporting, or correlating client-side events with server-side logs.
|
|
1119
|
+
|
|
1120
|
+
#### React
|
|
1121
|
+
|
|
1122
|
+
```tsx
|
|
1123
|
+
import { useConvaiClient } from "@convai/web-sdk";
|
|
1124
|
+
import { useEffect, useRef } from "react";
|
|
1125
|
+
import type { InteractionCreated } from "@convai/web-sdk";
|
|
1126
|
+
|
|
1127
|
+
function ConvaiSession() {
|
|
1128
|
+
const convaiClient = useConvaiClient({ /* config */ });
|
|
1129
|
+
const interactionIdRef = useRef<string | null>(null);
|
|
1130
|
+
|
|
1131
|
+
useEffect(() => {
|
|
1132
|
+
const unsub = convaiClient.on("interactionCreated", ({ interactionId, characterSessionId }: InteractionCreated) => {
|
|
1133
|
+
interactionIdRef.current = interactionId;
|
|
1134
|
+
|
|
1135
|
+
// Tag your analytics session
|
|
1136
|
+
analytics.identify({ interactionId, characterSessionId });
|
|
1137
|
+
});
|
|
1138
|
+
|
|
1139
|
+
return unsub;
|
|
1140
|
+
}, [convaiClient]);
|
|
1141
|
+
|
|
1142
|
+
const handleSend = (text: string) => {
|
|
1143
|
+
convaiClient.sendUserTextMessage(text);
|
|
1144
|
+
|
|
1145
|
+
// Attach the interaction ID to any events you fire
|
|
1146
|
+
analytics.track("message_sent", { interactionId: interactionIdRef.current, text });
|
|
1147
|
+
};
|
|
1148
|
+
|
|
1149
|
+
return <YourChatUI onSend={handleSend} />;
|
|
1150
|
+
}
|
|
1151
|
+
```
|
|
1152
|
+
|
|
1153
|
+
#### Vanilla TypeScript
|
|
1154
|
+
|
|
1155
|
+
```ts
|
|
1156
|
+
import { ConvaiClient } from "@convai/web-sdk/core";
|
|
1157
|
+
import type { InteractionCreated } from "@convai/web-sdk/core";
|
|
1158
|
+
|
|
1159
|
+
const client = new ConvaiClient({ apiKey: "...", characterId: "..." });
|
|
1160
|
+
|
|
1161
|
+
let interactionId: string | null = null;
|
|
1162
|
+
|
|
1163
|
+
client.on("interactionCreated", ({ interactionId: id, characterSessionId }: InteractionCreated) => {
|
|
1164
|
+
interactionId = id;
|
|
1165
|
+
sessionStorage.setItem("convai_interaction_id", id);
|
|
1166
|
+
sessionStorage.setItem("convai_session_id", characterSessionId);
|
|
1167
|
+
});
|
|
1168
|
+
|
|
1169
|
+
await client.connect();
|
|
1170
|
+
|
|
1171
|
+
// Later — include the ID when reporting errors or events
|
|
1172
|
+
window.onerror = (msg) => {
|
|
1173
|
+
reportError({ msg, interactionId });
|
|
1174
|
+
};
|
|
1175
|
+
```
|
|
1176
|
+
|
|
925
1177
|
### Advanced core classes (`@convai/web-sdk/core`)
|
|
926
1178
|
|
|
927
1179
|
These are exported for advanced and custom pipeline use-cases.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Room } from "livekit-client";
|
|
2
2
|
import { AudioControls } from "./types";
|
|
3
3
|
import { EventEmitter } from "./EventEmitter";
|
|
4
|
+
import type { WebSocketSession } from "./WebSocketSession";
|
|
4
5
|
/**
|
|
5
6
|
* Manages audio controls for LiveKit room
|
|
6
7
|
* Provides methods to enable/disable microphone, manage audio devices,
|
|
@@ -8,10 +9,13 @@ import { EventEmitter } from "./EventEmitter";
|
|
|
8
9
|
*/
|
|
9
10
|
export declare class AudioManager extends EventEmitter implements AudioControls {
|
|
10
11
|
private room;
|
|
12
|
+
private _wsSession;
|
|
11
13
|
private _isAudioEnabled;
|
|
12
14
|
private _isAudioMuted;
|
|
13
15
|
private _audioLevel;
|
|
14
16
|
constructor(room?: Room);
|
|
17
|
+
setWebSocketSession(session: WebSocketSession | null): void;
|
|
18
|
+
syncWsAudioState(isEnabled: boolean): void;
|
|
15
19
|
get isAudioEnabled(): boolean;
|
|
16
20
|
get isAudioMuted(): boolean;
|
|
17
21
|
get audioLevel(): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AudioManager.d.ts","sourceRoot":"","sources":["../../src/core/AudioManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"AudioManager.d.ts","sourceRoot":"","sources":["../../src/core/AudioManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,YAAa,YAAW,aAAa;IACrE,OAAO,CAAC,IAAI,CAAqB;IACjC,OAAO,CAAC,UAAU,CAAiC;IACnD,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,aAAa,CAAkB;IACvC,OAAO,CAAC,WAAW,CAAa;gBAEpB,IAAI,CAAC,EAAE,IAAI;IAOvB,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,GAAG,IAAI;IAI3D,gBAAgB,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI;IAS1C,IAAI,cAAc,IAAI,OAAO,CAE5B;IAED,IAAI,YAAY,IAAI,OAAO,CAE1B;IAED,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAczB;;OAEG;IACH,OAAO,CAAC,cAAc;IA2CtB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAKxB;;;;OAIG;IACH,iBAAiB,CAAC,OAAO,GAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,IAAI;IA0CzD;;OAEG;IACH,OAAO,CAAC,WAAW;IAInB;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IA2BlC;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAwCnC;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhC;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAIlC;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAQlC;;OAEG;IACG,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYrD;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IAUnD;;OAEG;IACH,yBAAyB,IAAI,IAAI;IAOjC;;OAEG;IACH,wBAAwB,IAAI,IAAI;IAIhC;;OAEG;IACH,KAAK,IAAI,IAAI;CAUd"}
|
|
@@ -8,6 +8,7 @@ export class AudioManager extends EventEmitter {
|
|
|
8
8
|
constructor(room) {
|
|
9
9
|
super();
|
|
10
10
|
this.room = null;
|
|
11
|
+
this._wsSession = null;
|
|
11
12
|
this._isAudioEnabled = false;
|
|
12
13
|
this._isAudioMuted = false;
|
|
13
14
|
this._audioLevel = 0;
|
|
@@ -15,6 +16,17 @@ export class AudioManager extends EventEmitter {
|
|
|
15
16
|
this.setRoom(room);
|
|
16
17
|
}
|
|
17
18
|
}
|
|
19
|
+
setWebSocketSession(session) {
|
|
20
|
+
this._wsSession = session;
|
|
21
|
+
}
|
|
22
|
+
syncWsAudioState(isEnabled) {
|
|
23
|
+
this._isAudioEnabled = isEnabled;
|
|
24
|
+
this._isAudioMuted = !isEnabled;
|
|
25
|
+
this.emit("audioStateChange", {
|
|
26
|
+
isAudioMuted: this._isAudioMuted,
|
|
27
|
+
isAudioEnabled: this._isAudioEnabled,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
18
30
|
get isAudioEnabled() {
|
|
19
31
|
return this._isAudioEnabled;
|
|
20
32
|
}
|
|
@@ -134,6 +146,13 @@ export class AudioManager extends EventEmitter {
|
|
|
134
146
|
* Enable audio
|
|
135
147
|
*/
|
|
136
148
|
async enableAudio() {
|
|
149
|
+
if (this._wsSession) {
|
|
150
|
+
this._wsSession.enableMic(true);
|
|
151
|
+
this._isAudioEnabled = true;
|
|
152
|
+
this._isAudioMuted = false;
|
|
153
|
+
this.emit('audioStateChange', { isAudioMuted: false, isAudioEnabled: true, audioLevel: this._audioLevel });
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
137
156
|
if (!this.room) {
|
|
138
157
|
throw new Error('Room not initialized');
|
|
139
158
|
}
|
|
@@ -155,6 +174,13 @@ export class AudioManager extends EventEmitter {
|
|
|
155
174
|
* Disable audio and completely release microphone
|
|
156
175
|
*/
|
|
157
176
|
async disableAudio() {
|
|
177
|
+
if (this._wsSession) {
|
|
178
|
+
this._wsSession.enableMic(false);
|
|
179
|
+
this._isAudioEnabled = false;
|
|
180
|
+
this._isAudioMuted = true;
|
|
181
|
+
this.emit('audioStateChange', { isAudioMuted: true, isAudioEnabled: false, audioLevel: 0 });
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
158
184
|
if (!this.room) {
|
|
159
185
|
throw new Error('Room not initialized');
|
|
160
186
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AudioManager.js","sourceRoot":"","sources":["../../src/core/AudioManager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"AudioManager.js","sourceRoot":"","sources":["../../src/core/AudioManager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C;;;;GAIG;AACH,MAAM,OAAO,YAAa,SAAQ,YAAY;IAO5C,YAAY,IAAW;QACrB,KAAK,EAAE,CAAC;QAPF,SAAI,GAAgB,IAAI,CAAC;QACzB,eAAU,GAA4B,IAAI,CAAC;QAC3C,oBAAe,GAAY,KAAK,CAAC;QACjC,kBAAa,GAAY,KAAK,CAAC;QAC/B,gBAAW,GAAW,CAAC,CAAC;QAI9B,IAAI,IAAI,EAAE,CAAC;YACT,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,OAAgC;QAClD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC;IAC5B,CAAC;IAED,gBAAgB,CAAC,SAAkB;QACjC,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,CAAC,SAAS,CAAC;QAChC,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE;YAC5B,YAAY,EAAE,IAAI,CAAC,aAAa;YAChC,cAAc,EAAE,IAAI,CAAC,eAAe;SACrC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,IAAU;QAChB,mCAAmC;QACnC,IA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 @@ export declare class ConvaiClient extends EventEmitter implements IConvaiClient
|
|
|
54
54
|
private _storedConfig;
|
|
55
55
|
private _endUserId;
|
|
56
56
|
private _endUserMetadata;
|
|
57
|
+
private _wsSession;
|
|
58
|
+
private _activeTransport;
|
|
59
|
+
private _logRtviMessages;
|
|
60
|
+
private _clientReadyRetryTimer;
|
|
61
|
+
private _clientReadyTimeoutTimer;
|
|
62
|
+
private _clientReadyMsgId;
|
|
63
|
+
private static readonly CLIENT_READY_RETRY_MS;
|
|
64
|
+
private static readonly CLIENT_READY_TIMEOUT_MS;
|
|
57
65
|
private _audioManager;
|
|
58
66
|
private _videoManager;
|
|
59
67
|
private _screenShareManager;
|
|
@@ -94,10 +102,28 @@ export declare class ConvaiClient extends EventEmitter implements IConvaiClient
|
|
|
94
102
|
* Update state and emit changes
|
|
95
103
|
*/
|
|
96
104
|
private updateState;
|
|
105
|
+
/**
|
|
106
|
+
* Send a data message via the active transport.
|
|
107
|
+
* For LiveKit: publishes via the data channel.
|
|
108
|
+
* For WebSocket: sends via PipecatClient.sendClientMessage (wrapped in {t,d} envelope).
|
|
109
|
+
*/
|
|
110
|
+
private publishMessage;
|
|
111
|
+
/**
|
|
112
|
+
* Returns true when a message can be sent on the active transport.
|
|
113
|
+
*/
|
|
114
|
+
private isTransportReady;
|
|
97
115
|
/**
|
|
98
116
|
* Connect to a Convai character
|
|
99
117
|
*/
|
|
100
118
|
connect(config?: ConvaiConfig): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* RTVI client-ready handshake. Server-side gates bot-ready emission on
|
|
121
|
+
* receipt of client-ready (and re-emits bot-ready on every client-ready),
|
|
122
|
+
* so we can retry until we hear bot-ready back. Closes the race where the
|
|
123
|
+
* bot publishes bot-ready before the client data-channel is subscribed.
|
|
124
|
+
*/
|
|
125
|
+
private _startClientReadyHandshake;
|
|
126
|
+
private _stopClientReadyHandshake;
|
|
101
127
|
/**
|
|
102
128
|
* Disconnect from the current character session
|
|
103
129
|
*/
|
|
@@ -169,6 +195,14 @@ export declare class ConvaiClient extends EventEmitter implements IConvaiClient
|
|
|
169
195
|
* ```
|
|
170
196
|
*/
|
|
171
197
|
updateContext(options: ContextUpdateOptions): void;
|
|
198
|
+
/**
|
|
199
|
+
* Send descriptive scene updates. Use when environment description changes
|
|
200
|
+
* and the bot should know what is visible or nearby. Does not modify action_config.
|
|
201
|
+
*/
|
|
202
|
+
updateSceneMetadata(items: Array<{
|
|
203
|
+
name: string;
|
|
204
|
+
description: string;
|
|
205
|
+
}>): void;
|
|
172
206
|
/**
|
|
173
207
|
* Toggle text-to-speech on or off
|
|
174
208
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConvaiClient.d.ts","sourceRoot":"","sources":["../../src/core/ConvaiClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,
|
|
1
|
+
{"version":3,"file":"ConvaiClient.d.ts","sourceRoot":"","sources":["../../src/core/ConvaiClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EAML,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,WAAW,EAEX,aAAa,EACb,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,WAAW,EACX,oBAAoB,EAGrB,MAAM,SAAS,CAAC;AAKjB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAahD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,qBAAa,YAAa,SAAQ,YAAa,YAAW,aAAa;IACrE,OAAO,CAAC,KAAK,CAAO;IACpB,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,eAAe,CAAkC;IACzD,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAA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