@keyframelabs/elements 0.0.8 → 0.0.9
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/dist/index.js +20 -16
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createClient as w } from "@keyframelabs/sdk";
|
|
2
2
|
const l = 24e3;
|
|
3
|
-
function
|
|
3
|
+
function g(i) {
|
|
4
4
|
const e = atob(i), t = new Uint8Array(e.length);
|
|
5
5
|
for (let s = 0; s < e.length; s++)
|
|
6
6
|
t[s] = e.charCodeAt(s);
|
|
7
7
|
return t;
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function m(i) {
|
|
10
10
|
let e = "";
|
|
11
11
|
for (let t = 0; t < i.length; t++)
|
|
12
12
|
e += String.fromCharCode(i[t]);
|
|
@@ -113,7 +113,7 @@ class u {
|
|
|
113
113
|
this.events.emit("closed", { code: e, reason: t });
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
-
const
|
|
116
|
+
const A = "gemini-2.5-flash-native-audio-preview-12-2025", C = "wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent", k = "wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1alpha.GenerativeService.BidiGenerateContentConstrained";
|
|
117
117
|
class R extends u {
|
|
118
118
|
agentName = "GeminiLive";
|
|
119
119
|
async connect(e) {
|
|
@@ -122,7 +122,7 @@ class R extends u {
|
|
|
122
122
|
if (!e.apiKey)
|
|
123
123
|
throw new Error("Gemini API key is required");
|
|
124
124
|
e.inputSampleRate && (this.inputSampleRate = e.inputSampleRate);
|
|
125
|
-
const t = e.model ??
|
|
125
|
+
const t = e.model ?? A, n = (e.authType ?? "api_key") === "ephemeral_token" ? `${k}?access_token=${encodeURIComponent(e.apiKey)}` : `${C}?key=${encodeURIComponent(e.apiKey)}`;
|
|
126
126
|
return new Promise((a, r) => {
|
|
127
127
|
this.ws = new WebSocket(n), this.ws.onopen = () => {
|
|
128
128
|
const o = {
|
|
@@ -159,7 +159,7 @@ class R extends u {
|
|
|
159
159
|
this._state !== "speaking" && (this.events.emit("turnStart", void 0), this.setState("speaking"));
|
|
160
160
|
for (const n of s.modelTurn.parts) {
|
|
161
161
|
if (n.inlineData?.data) {
|
|
162
|
-
const a =
|
|
162
|
+
const a = g(n.inlineData.data);
|
|
163
163
|
this.events.emit("audio", a);
|
|
164
164
|
}
|
|
165
165
|
n.text && this.events.emit("transcript", {
|
|
@@ -181,7 +181,7 @@ class R extends u {
|
|
|
181
181
|
mediaChunks: [
|
|
182
182
|
{
|
|
183
183
|
mimeType: `audio/pcm;rate=${this.inputSampleRate}`,
|
|
184
|
-
data:
|
|
184
|
+
data: m(e)
|
|
185
185
|
}
|
|
186
186
|
]
|
|
187
187
|
}
|
|
@@ -282,7 +282,7 @@ class S extends u {
|
|
|
282
282
|
M.includes(o) && (this.events.emit("emotion", o), this.emotionEmittedForEventId = s);
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
|
-
let n =
|
|
285
|
+
let n = g(t.audio_base_64);
|
|
286
286
|
this.outputSampleRate !== l && (n = c(n, this.outputSampleRate, l)), this.events.emit("audio", n);
|
|
287
287
|
}
|
|
288
288
|
handleUserTranscript(e) {
|
|
@@ -295,11 +295,11 @@ class S extends u {
|
|
|
295
295
|
}
|
|
296
296
|
handleAgentResponse(e) {
|
|
297
297
|
const t = e.agent_response_event;
|
|
298
|
-
t?.agent_response && this.events.emit("transcript", {
|
|
298
|
+
t?.agent_response && (this.events.emit("turnEnd", void 0), this.setState("listening"), this.events.emit("transcript", {
|
|
299
299
|
role: "assistant",
|
|
300
300
|
text: t.agent_response,
|
|
301
301
|
isFinal: !0
|
|
302
|
-
});
|
|
302
|
+
}));
|
|
303
303
|
}
|
|
304
304
|
handleInterruption(e) {
|
|
305
305
|
const t = e.interruption_event;
|
|
@@ -310,7 +310,7 @@ class S extends u {
|
|
|
310
310
|
return;
|
|
311
311
|
let t = e;
|
|
312
312
|
this.sourceInputSampleRate !== this.expectedInputSampleRate && (t = c(e, this.sourceInputSampleRate, this.expectedInputSampleRate)), this.ws.send(JSON.stringify({
|
|
313
|
-
user_audio_chunk:
|
|
313
|
+
user_audio_chunk: m(t)
|
|
314
314
|
}));
|
|
315
315
|
}
|
|
316
316
|
/**
|
|
@@ -425,7 +425,7 @@ class O extends u {
|
|
|
425
425
|
handleMediaOutput(e) {
|
|
426
426
|
if (!e.media?.payload) return;
|
|
427
427
|
this._state !== "speaking" && (this.events.emit("turnStart", void 0), this.setState("speaking"));
|
|
428
|
-
let t =
|
|
428
|
+
let t = g(e.media.payload);
|
|
429
429
|
this.cartesiaOutputRate !== l && (t = c(t, this.cartesiaOutputRate, l)), this.events.emit("audio", t);
|
|
430
430
|
}
|
|
431
431
|
handleClear() {
|
|
@@ -440,7 +440,7 @@ class O extends u {
|
|
|
440
440
|
event: "media_input",
|
|
441
441
|
stream_id: this.streamId,
|
|
442
442
|
media: {
|
|
443
|
-
payload:
|
|
443
|
+
payload: m(t)
|
|
444
444
|
}
|
|
445
445
|
}));
|
|
446
446
|
}
|
|
@@ -686,7 +686,9 @@ class K {
|
|
|
686
686
|
onClose: () => {
|
|
687
687
|
this.mounted && this.callbacks.onDisconnect?.();
|
|
688
688
|
}
|
|
689
|
-
}), this.agent = y(e.voice_agent_details.type), this.agent.on("audio", (t) => this.session?.sendAudio(t)), this.agent.on("
|
|
689
|
+
}), this.agent = y(e.voice_agent_details.type), this.agent.on("audio", (t) => this.session?.sendAudio(t)), this.agent.on("turnEnd", () => this.session?.endAudioTurn()), this.agent.on("interrupted", () => {
|
|
690
|
+
this.session?.endAudioTurn(), this.session?.interrupt();
|
|
691
|
+
}), this.agent.on("stateChange", (t) => this.setAgentState(t)), this.agent.on("closed", () => {
|
|
690
692
|
this.mounted && this.callbacks.onDisconnect?.();
|
|
691
693
|
}), this.agent instanceof S && this.agent.on("emotion", (t) => this.session?.setEmotion(t)), await this.session.connect();
|
|
692
694
|
}
|
|
@@ -821,7 +823,9 @@ class B {
|
|
|
821
823
|
onClose: () => {
|
|
822
824
|
this.mounted && this.callbacks.onDisconnect?.();
|
|
823
825
|
}
|
|
824
|
-
}), this.agent = y(this.voiceAgentDetails.type), this.agent.on("audio", (e) => this.session?.sendAudio(e)), this.agent.on("
|
|
826
|
+
}), this.agent = y(this.voiceAgentDetails.type), this.agent.on("audio", (e) => this.session?.sendAudio(e)), this.agent.on("turnEnd", () => this.session?.endAudioTurn()), this.agent.on("interrupted", () => {
|
|
827
|
+
this.session?.endAudioTurn(), this.session?.interrupt();
|
|
828
|
+
}), this.agent.on("stateChange", (e) => this.setAgentState(e)), this.agent.on("closed", () => {
|
|
825
829
|
this.mounted && this.callbacks.onDisconnect?.();
|
|
826
830
|
}), this.agent instanceof S && this.agent.on("emotion", (e) => this.session?.setEmotion(e)), await this.session.connect();
|
|
827
831
|
}
|
|
@@ -871,8 +875,8 @@ export {
|
|
|
871
875
|
K as PersonaEmbed,
|
|
872
876
|
B as PersonaView,
|
|
873
877
|
l as SAMPLE_RATE,
|
|
874
|
-
|
|
875
|
-
|
|
878
|
+
g as base64ToBytes,
|
|
879
|
+
m as bytesToBase64,
|
|
876
880
|
y as createAgent,
|
|
877
881
|
E as createEventEmitter,
|
|
878
882
|
f as floatTo16BitPCM,
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.0.
|
|
7
|
+
"version": "0.0.9",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "./dist/index.js",
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@keyframelabs/sdk": "0.1.
|
|
22
|
+
"@keyframelabs/sdk": "0.1.7"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^25.0.9",
|