@chatbase-co/voice-sdk 0.1.2
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/LICENSE +21 -0
- package/README.md +75 -0
- package/THIRD_PARTY_LICENSES.md +185 -0
- package/dist/index.cjs +39 -0
- package/dist/index.d.cts +85 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.global.js +39 -0
- package/dist/index.js +39 -0
- package/package.json +54 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `data` object returned by
|
|
3
|
+
* `POST /api/v2/agents/{agentId}/voice/sessions`. Only `participantToken`
|
|
4
|
+
* is required to connect — pass the whole object through.
|
|
5
|
+
*/
|
|
6
|
+
type VoiceSession = {
|
|
7
|
+
/** Short-lived token scoped to this session's room. */
|
|
8
|
+
participantToken: string;
|
|
9
|
+
/** Optional voice server address override; omitted by the API. */
|
|
10
|
+
serverUrl?: string;
|
|
11
|
+
sessionId?: string;
|
|
12
|
+
roomName?: string;
|
|
13
|
+
maxDurationSeconds?: number;
|
|
14
|
+
conversationId?: string;
|
|
15
|
+
userId?: string;
|
|
16
|
+
};
|
|
17
|
+
type ConnectionState = 'connecting' | 'connected' | 'reconnecting' | 'disconnected' | 'error';
|
|
18
|
+
type AgentState = 'initializing' | 'listening' | 'thinking' | 'speaking';
|
|
19
|
+
type TranscriptSegment = {
|
|
20
|
+
/**
|
|
21
|
+
* Full text of the segment so far. Segments grow while being spoken —
|
|
22
|
+
* re-render the segment identified by `segmentId` on every event.
|
|
23
|
+
*/
|
|
24
|
+
text: string;
|
|
25
|
+
speaker: 'user' | 'agent';
|
|
26
|
+
segmentId: string;
|
|
27
|
+
};
|
|
28
|
+
type ChatbaseVoiceEvents = {
|
|
29
|
+
/** Connection lifecycle of the session transport. */
|
|
30
|
+
connectionState: (state: ConnectionState) => void;
|
|
31
|
+
/** What the agent is doing: initializing, listening, thinking, speaking. */
|
|
32
|
+
agentState: (state: AgentState) => void;
|
|
33
|
+
/** Live transcripts of both sides, streamed while spoken. */
|
|
34
|
+
transcript: (segment: TranscriptSegment) => void;
|
|
35
|
+
/** The session ended (client disconnect, duration limit, credits, …). */
|
|
36
|
+
sessionEnd: (reason?: string) => void;
|
|
37
|
+
/** A non-fatal problem (e.g. microphone unavailable) or connect failure. */
|
|
38
|
+
error: (error: Error) => void;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A real-time voice session with a Chatbase agent.
|
|
43
|
+
*
|
|
44
|
+
* Mint a session server-side with `POST /api/v2/agents/{agentId}/voice/sessions`
|
|
45
|
+
* (the API key must never reach the client), hand the response `data` to
|
|
46
|
+
* `connect()`, and the agent joins automatically: its audio plays, transcripts
|
|
47
|
+
* and state stream through the events, and the microphone is live for
|
|
48
|
+
* barge-in. One instance handles one session; `connect()` again after
|
|
49
|
+
* `disconnect()` for the next.
|
|
50
|
+
*/
|
|
51
|
+
declare class ChatbaseVoice {
|
|
52
|
+
private room;
|
|
53
|
+
private readonly serverUrl;
|
|
54
|
+
private readonly audioElements;
|
|
55
|
+
private readonly listeners;
|
|
56
|
+
constructor(options?: {
|
|
57
|
+
serverUrl?: string;
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* Join the session. Accepts the `data` object returned by the voice
|
|
61
|
+
* sessions endpoint, or just the `participantToken` string. Enables the
|
|
62
|
+
* microphone if the user allows it; without mic permission the session
|
|
63
|
+
* continues in text mode (`sendText` still gets spoken replies).
|
|
64
|
+
*/
|
|
65
|
+
connect(session: VoiceSession | string): Promise<void>;
|
|
66
|
+
/** Leave the session. The agent hangs up and `sessionEnd` fires. */
|
|
67
|
+
disconnect(): Promise<void>;
|
|
68
|
+
/** Stop sending microphone audio. The session stays alive. */
|
|
69
|
+
mute(): Promise<void>;
|
|
70
|
+
/** Resume sending microphone audio. */
|
|
71
|
+
unmute(): Promise<void>;
|
|
72
|
+
get isMuted(): boolean;
|
|
73
|
+
/** The local microphone stream, e.g. for a waveform visualization. */
|
|
74
|
+
get localAudioStream(): MediaStream | null;
|
|
75
|
+
/** Send a text message into the live session; the agent replies with speech. */
|
|
76
|
+
sendText(message: string): Promise<void>;
|
|
77
|
+
/** Subscribe to a session event. Returns an unsubscribe function. */
|
|
78
|
+
on<E extends keyof ChatbaseVoiceEvents>(event: E, listener: ChatbaseVoiceEvents[E]): () => void;
|
|
79
|
+
off<E extends keyof ChatbaseVoiceEvents>(event: E, listener: ChatbaseVoiceEvents[E]): void;
|
|
80
|
+
private emit;
|
|
81
|
+
private requireRoom;
|
|
82
|
+
private wire;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { type AgentState, ChatbaseVoice, type ChatbaseVoiceEvents, type ConnectionState, type TranscriptSegment, type VoiceSession };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `data` object returned by
|
|
3
|
+
* `POST /api/v2/agents/{agentId}/voice/sessions`. Only `participantToken`
|
|
4
|
+
* is required to connect — pass the whole object through.
|
|
5
|
+
*/
|
|
6
|
+
type VoiceSession = {
|
|
7
|
+
/** Short-lived token scoped to this session's room. */
|
|
8
|
+
participantToken: string;
|
|
9
|
+
/** Optional voice server address override; omitted by the API. */
|
|
10
|
+
serverUrl?: string;
|
|
11
|
+
sessionId?: string;
|
|
12
|
+
roomName?: string;
|
|
13
|
+
maxDurationSeconds?: number;
|
|
14
|
+
conversationId?: string;
|
|
15
|
+
userId?: string;
|
|
16
|
+
};
|
|
17
|
+
type ConnectionState = 'connecting' | 'connected' | 'reconnecting' | 'disconnected' | 'error';
|
|
18
|
+
type AgentState = 'initializing' | 'listening' | 'thinking' | 'speaking';
|
|
19
|
+
type TranscriptSegment = {
|
|
20
|
+
/**
|
|
21
|
+
* Full text of the segment so far. Segments grow while being spoken —
|
|
22
|
+
* re-render the segment identified by `segmentId` on every event.
|
|
23
|
+
*/
|
|
24
|
+
text: string;
|
|
25
|
+
speaker: 'user' | 'agent';
|
|
26
|
+
segmentId: string;
|
|
27
|
+
};
|
|
28
|
+
type ChatbaseVoiceEvents = {
|
|
29
|
+
/** Connection lifecycle of the session transport. */
|
|
30
|
+
connectionState: (state: ConnectionState) => void;
|
|
31
|
+
/** What the agent is doing: initializing, listening, thinking, speaking. */
|
|
32
|
+
agentState: (state: AgentState) => void;
|
|
33
|
+
/** Live transcripts of both sides, streamed while spoken. */
|
|
34
|
+
transcript: (segment: TranscriptSegment) => void;
|
|
35
|
+
/** The session ended (client disconnect, duration limit, credits, …). */
|
|
36
|
+
sessionEnd: (reason?: string) => void;
|
|
37
|
+
/** A non-fatal problem (e.g. microphone unavailable) or connect failure. */
|
|
38
|
+
error: (error: Error) => void;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A real-time voice session with a Chatbase agent.
|
|
43
|
+
*
|
|
44
|
+
* Mint a session server-side with `POST /api/v2/agents/{agentId}/voice/sessions`
|
|
45
|
+
* (the API key must never reach the client), hand the response `data` to
|
|
46
|
+
* `connect()`, and the agent joins automatically: its audio plays, transcripts
|
|
47
|
+
* and state stream through the events, and the microphone is live for
|
|
48
|
+
* barge-in. One instance handles one session; `connect()` again after
|
|
49
|
+
* `disconnect()` for the next.
|
|
50
|
+
*/
|
|
51
|
+
declare class ChatbaseVoice {
|
|
52
|
+
private room;
|
|
53
|
+
private readonly serverUrl;
|
|
54
|
+
private readonly audioElements;
|
|
55
|
+
private readonly listeners;
|
|
56
|
+
constructor(options?: {
|
|
57
|
+
serverUrl?: string;
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* Join the session. Accepts the `data` object returned by the voice
|
|
61
|
+
* sessions endpoint, or just the `participantToken` string. Enables the
|
|
62
|
+
* microphone if the user allows it; without mic permission the session
|
|
63
|
+
* continues in text mode (`sendText` still gets spoken replies).
|
|
64
|
+
*/
|
|
65
|
+
connect(session: VoiceSession | string): Promise<void>;
|
|
66
|
+
/** Leave the session. The agent hangs up and `sessionEnd` fires. */
|
|
67
|
+
disconnect(): Promise<void>;
|
|
68
|
+
/** Stop sending microphone audio. The session stays alive. */
|
|
69
|
+
mute(): Promise<void>;
|
|
70
|
+
/** Resume sending microphone audio. */
|
|
71
|
+
unmute(): Promise<void>;
|
|
72
|
+
get isMuted(): boolean;
|
|
73
|
+
/** The local microphone stream, e.g. for a waveform visualization. */
|
|
74
|
+
get localAudioStream(): MediaStream | null;
|
|
75
|
+
/** Send a text message into the live session; the agent replies with speech. */
|
|
76
|
+
sendText(message: string): Promise<void>;
|
|
77
|
+
/** Subscribe to a session event. Returns an unsubscribe function. */
|
|
78
|
+
on<E extends keyof ChatbaseVoiceEvents>(event: E, listener: ChatbaseVoiceEvents[E]): () => void;
|
|
79
|
+
off<E extends keyof ChatbaseVoiceEvents>(event: E, listener: ChatbaseVoiceEvents[E]): void;
|
|
80
|
+
private emit;
|
|
81
|
+
private requireRoom;
|
|
82
|
+
private wire;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { type AgentState, ChatbaseVoice, type ChatbaseVoiceEvents, type ConnectionState, type TranscriptSegment, type VoiceSession };
|