@livekit/agents-plugin-liveavatar 1.3.0 → 1.3.3

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.
@@ -0,0 +1,148 @@
1
+ import { type APIConnectOptions, voice } from '@livekit/agents';
2
+ import { type Room } from '@livekit/rtc-node';
3
+ import { type VideoQuality } from './api.js';
4
+ /**
5
+ * Options for configuring an AvatarSession.
6
+ *
7
+ * Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/avatar.py - 47-58 lines
8
+ */
9
+ export interface AvatarSessionOptions {
10
+ /** The LiveAvatar avatar id. Falls back to the `LIVEAVATAR_AVATAR_ID` env var. */
11
+ avatarId?: string;
12
+ /** Override the LiveAvatar API base URL. */
13
+ apiUrl?: string;
14
+ /** LiveAvatar API key. Falls back to the `LIVEAVATAR_API_KEY` env var. */
15
+ apiKey?: string;
16
+ /** When true, use the LiveAvatar sandbox (1 minute connection limit). */
17
+ isSandbox?: boolean;
18
+ /** Avatar video quality. When omitted, the LiveAvatar service decides. */
19
+ videoQuality?: VideoQuality;
20
+ /** Identity for the avatar participant. Defaults to `liveavatar-avatar-agent`. */
21
+ avatarParticipantIdentity?: string;
22
+ /** Display name for the avatar participant. Defaults to `liveavatar-avatar-agent`. */
23
+ avatarParticipantName?: string;
24
+ /** API retry/timeout options. */
25
+ connOptions?: APIConnectOptions;
26
+ }
27
+ /**
28
+ * Optional LiveKit credentials for {@link AvatarSession.start}; falls back to env vars.
29
+ */
30
+ export interface StartOptions {
31
+ livekitUrl?: string;
32
+ livekitApiKey?: string;
33
+ livekitApiSecret?: string;
34
+ }
35
+ /**
36
+ * A LiveAvatar interactive avatar session.
37
+ *
38
+ * This class manages the connection between a LiveKit agent and a LiveAvatar avatar:
39
+ * it brings up a LiveAvatar streaming session, opens the realtime websocket, captures
40
+ * the agent's audio output, and forwards it (resampled, base64-encoded) to the avatar
41
+ * service. Inbound websocket events drive playback start/finish notifications back into
42
+ * the agent session so the speech handle can complete correctly.
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const avatar = new AvatarSession({
47
+ * avatarId: 'your-avatar-id',
48
+ * apiKey: process.env.LIVEAVATAR_API_KEY,
49
+ * videoQuality: 'high',
50
+ * });
51
+ * await avatar.start(agentSession, room);
52
+ * ```
53
+ *
54
+ * Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/avatar.py
55
+ */
56
+ export declare class AvatarSession {
57
+ #private;
58
+ private avatarId;
59
+ private apiUrl?;
60
+ private apiKey;
61
+ private isSandbox;
62
+ private videoQuality;
63
+ private avatarParticipantIdentity;
64
+ private avatarParticipantName;
65
+ private connOptions;
66
+ private api;
67
+ private sessionId;
68
+ private sessionToken;
69
+ private wsUrl;
70
+ private audioBuffer?;
71
+ private msgChannel?;
72
+ private msgChannelClosed;
73
+ private mainTaskPromise?;
74
+ private agentSession?;
75
+ private room?;
76
+ private localParticipantIdentity;
77
+ private audioResampler;
78
+ private resamplerInputRate;
79
+ private audioPlaying;
80
+ private avatarSpeaking;
81
+ private avatarInterrupted;
82
+ private playbackPosition;
83
+ private sessionConnectedFuture;
84
+ private chunkInterrupted;
85
+ private closing;
86
+ constructor(options?: AvatarSessionOptions);
87
+ /**
88
+ * Start the avatar session and wire it into the agent session's audio output.
89
+ *
90
+ * Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/avatar.py - 89-178 lines
91
+ */
92
+ start(agentSession: voice.AgentSession, room: Room, options?: StartOptions): Promise<void>;
93
+ /**
94
+ * Stop the avatar session, drain queues, and close the websocket.
95
+ */
96
+ aclose(): Promise<void>;
97
+ /**
98
+ * Send an event over the websocket message queue.
99
+ *
100
+ * Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/avatar.py - 207-209 lines
101
+ */
102
+ sendEvent(msg: Record<string, unknown>): void;
103
+ private closeMsgChannel;
104
+ /**
105
+ * Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/avatar.py - 180-196 lines
106
+ *
107
+ * Gates everything on the `wasCapturing` flag carried by the `clear_buffer`
108
+ * event (set synchronously inside `QueueAudioOutput.clearBuffer`):
109
+ *
110
+ * 1. `notifyPlaybackFinished` only fires when a segment was actually in
111
+ * flight, so the base class's segment-count bookkeeping stays balanced
112
+ * even when an interrupt lands in the window between `super.captureFrame`
113
+ * incrementing `playbackSegmentsCount` and `forwardAudio` consuming the
114
+ * frame.
115
+ * 2. `chunkInterrupted` is only flipped when there's an actual segment to
116
+ * interrupt. If `wasCapturing` is false (e.g. `clearBuffer` is called
117
+ * after `flush` has already written its `AudioSegmentEnd`), setting
118
+ * `chunkInterrupted` would otherwise carry over and discard the first
119
+ * frame of the *next* segment.
120
+ */
121
+ private onClearBuffer;
122
+ /**
123
+ * Resample frame to {@link SAMPLE_RATE} mono. Mirrors the lazy resampler swap
124
+ * in the Python plugin: when the input rate changes we discard the old resampler.
125
+ *
126
+ * Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/avatar.py - 198-216 lines
127
+ */
128
+ private resampleAudio;
129
+ /**
130
+ * Main task: opens the websocket and runs forward/send/recv/keep-alive loops.
131
+ *
132
+ * Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/avatar.py - 218-308 lines
133
+ */
134
+ private mainTask;
135
+ /**
136
+ * Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/avatar.py - 310-311 lines
137
+ */
138
+ private handleAgentSpeakInterrupted;
139
+ /**
140
+ * Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/avatar.py - 313-322 lines
141
+ */
142
+ private handleAgentSpeakEnded;
143
+ /**
144
+ * Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/avatar.py - 324-327 lines
145
+ */
146
+ private handleAgentSpeakStarted;
147
+ }
148
+ //# sourceMappingURL=avatar.d.ts.map
@@ -0,0 +1,148 @@
1
+ import { type APIConnectOptions, voice } from '@livekit/agents';
2
+ import { type Room } from '@livekit/rtc-node';
3
+ import { type VideoQuality } from './api.js';
4
+ /**
5
+ * Options for configuring an AvatarSession.
6
+ *
7
+ * Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/avatar.py - 47-58 lines
8
+ */
9
+ export interface AvatarSessionOptions {
10
+ /** The LiveAvatar avatar id. Falls back to the `LIVEAVATAR_AVATAR_ID` env var. */
11
+ avatarId?: string;
12
+ /** Override the LiveAvatar API base URL. */
13
+ apiUrl?: string;
14
+ /** LiveAvatar API key. Falls back to the `LIVEAVATAR_API_KEY` env var. */
15
+ apiKey?: string;
16
+ /** When true, use the LiveAvatar sandbox (1 minute connection limit). */
17
+ isSandbox?: boolean;
18
+ /** Avatar video quality. When omitted, the LiveAvatar service decides. */
19
+ videoQuality?: VideoQuality;
20
+ /** Identity for the avatar participant. Defaults to `liveavatar-avatar-agent`. */
21
+ avatarParticipantIdentity?: string;
22
+ /** Display name for the avatar participant. Defaults to `liveavatar-avatar-agent`. */
23
+ avatarParticipantName?: string;
24
+ /** API retry/timeout options. */
25
+ connOptions?: APIConnectOptions;
26
+ }
27
+ /**
28
+ * Optional LiveKit credentials for {@link AvatarSession.start}; falls back to env vars.
29
+ */
30
+ export interface StartOptions {
31
+ livekitUrl?: string;
32
+ livekitApiKey?: string;
33
+ livekitApiSecret?: string;
34
+ }
35
+ /**
36
+ * A LiveAvatar interactive avatar session.
37
+ *
38
+ * This class manages the connection between a LiveKit agent and a LiveAvatar avatar:
39
+ * it brings up a LiveAvatar streaming session, opens the realtime websocket, captures
40
+ * the agent's audio output, and forwards it (resampled, base64-encoded) to the avatar
41
+ * service. Inbound websocket events drive playback start/finish notifications back into
42
+ * the agent session so the speech handle can complete correctly.
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const avatar = new AvatarSession({
47
+ * avatarId: 'your-avatar-id',
48
+ * apiKey: process.env.LIVEAVATAR_API_KEY,
49
+ * videoQuality: 'high',
50
+ * });
51
+ * await avatar.start(agentSession, room);
52
+ * ```
53
+ *
54
+ * Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/avatar.py
55
+ */
56
+ export declare class AvatarSession {
57
+ #private;
58
+ private avatarId;
59
+ private apiUrl?;
60
+ private apiKey;
61
+ private isSandbox;
62
+ private videoQuality;
63
+ private avatarParticipantIdentity;
64
+ private avatarParticipantName;
65
+ private connOptions;
66
+ private api;
67
+ private sessionId;
68
+ private sessionToken;
69
+ private wsUrl;
70
+ private audioBuffer?;
71
+ private msgChannel?;
72
+ private msgChannelClosed;
73
+ private mainTaskPromise?;
74
+ private agentSession?;
75
+ private room?;
76
+ private localParticipantIdentity;
77
+ private audioResampler;
78
+ private resamplerInputRate;
79
+ private audioPlaying;
80
+ private avatarSpeaking;
81
+ private avatarInterrupted;
82
+ private playbackPosition;
83
+ private sessionConnectedFuture;
84
+ private chunkInterrupted;
85
+ private closing;
86
+ constructor(options?: AvatarSessionOptions);
87
+ /**
88
+ * Start the avatar session and wire it into the agent session's audio output.
89
+ *
90
+ * Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/avatar.py - 89-178 lines
91
+ */
92
+ start(agentSession: voice.AgentSession, room: Room, options?: StartOptions): Promise<void>;
93
+ /**
94
+ * Stop the avatar session, drain queues, and close the websocket.
95
+ */
96
+ aclose(): Promise<void>;
97
+ /**
98
+ * Send an event over the websocket message queue.
99
+ *
100
+ * Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/avatar.py - 207-209 lines
101
+ */
102
+ sendEvent(msg: Record<string, unknown>): void;
103
+ private closeMsgChannel;
104
+ /**
105
+ * Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/avatar.py - 180-196 lines
106
+ *
107
+ * Gates everything on the `wasCapturing` flag carried by the `clear_buffer`
108
+ * event (set synchronously inside `QueueAudioOutput.clearBuffer`):
109
+ *
110
+ * 1. `notifyPlaybackFinished` only fires when a segment was actually in
111
+ * flight, so the base class's segment-count bookkeeping stays balanced
112
+ * even when an interrupt lands in the window between `super.captureFrame`
113
+ * incrementing `playbackSegmentsCount` and `forwardAudio` consuming the
114
+ * frame.
115
+ * 2. `chunkInterrupted` is only flipped when there's an actual segment to
116
+ * interrupt. If `wasCapturing` is false (e.g. `clearBuffer` is called
117
+ * after `flush` has already written its `AudioSegmentEnd`), setting
118
+ * `chunkInterrupted` would otherwise carry over and discard the first
119
+ * frame of the *next* segment.
120
+ */
121
+ private onClearBuffer;
122
+ /**
123
+ * Resample frame to {@link SAMPLE_RATE} mono. Mirrors the lazy resampler swap
124
+ * in the Python plugin: when the input rate changes we discard the old resampler.
125
+ *
126
+ * Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/avatar.py - 198-216 lines
127
+ */
128
+ private resampleAudio;
129
+ /**
130
+ * Main task: opens the websocket and runs forward/send/recv/keep-alive loops.
131
+ *
132
+ * Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/avatar.py - 218-308 lines
133
+ */
134
+ private mainTask;
135
+ /**
136
+ * Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/avatar.py - 310-311 lines
137
+ */
138
+ private handleAgentSpeakInterrupted;
139
+ /**
140
+ * Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/avatar.py - 313-322 lines
141
+ */
142
+ private handleAgentSpeakEnded;
143
+ /**
144
+ * Ref: python livekit-plugins/livekit-plugins-liveavatar/livekit/plugins/liveavatar/avatar.py - 324-327 lines
145
+ */
146
+ private handleAgentSpeakStarted;
147
+ }
148
+ //# sourceMappingURL=avatar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"avatar.d.ts","sourceRoot":"","sources":["../src/avatar.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,iBAAiB,EAOtB,KAAK,EACN,MAAM,iBAAiB,CAAC;AACzB,OA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