@d-id/client-sdk 1.1.66 → 1.1.67
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.
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { c as De, C as O, S as
|
|
1
|
+
import { c as De, C as O, S as p, a as Fe, b as Ne, A as m, d as Ue, l as de, e as v, f as N, g as je, h as xe, i as A, n as Oe } from "./index-DxHW-jum.js";
|
|
2
2
|
function Je(T, L, g, i) {
|
|
3
|
-
const
|
|
3
|
+
const M = De(T, `${L}/v2/agents/${g}`, i);
|
|
4
4
|
return {
|
|
5
5
|
async createStream(l) {
|
|
6
|
-
return
|
|
6
|
+
return M.post("/sessions", l);
|
|
7
7
|
}
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
const Be = {
|
|
11
|
-
[
|
|
12
|
-
[
|
|
11
|
+
[p.ChatAnswer]: O.Answer,
|
|
12
|
+
[p.ChatPartial]: O.Partial
|
|
13
13
|
}, ue = 2e4;
|
|
14
14
|
async function Qe() {
|
|
15
15
|
try {
|
|
@@ -21,52 +21,52 @@ async function Qe() {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
const qe = {
|
|
24
|
-
excellent:
|
|
25
|
-
good:
|
|
26
|
-
poor:
|
|
27
|
-
lost:
|
|
28
|
-
unknown:
|
|
29
|
-
},
|
|
24
|
+
excellent: N.Strong,
|
|
25
|
+
good: N.Strong,
|
|
26
|
+
poor: N.Weak,
|
|
27
|
+
lost: N.Unknown,
|
|
28
|
+
unknown: N.Unknown
|
|
29
|
+
}, U = JSON.stringify({
|
|
30
30
|
kind: "InternalServerError",
|
|
31
31
|
description: "Stream Error"
|
|
32
32
|
});
|
|
33
|
-
function
|
|
34
|
-
var i,
|
|
35
|
-
throw L("Failed to connect to LiveKit room:", T), (i = g.onConnectionStateChange) == null || i.call(g, v.Fail, "internal:init-error"), (
|
|
33
|
+
function pe(T, L, g) {
|
|
34
|
+
var i, M;
|
|
35
|
+
throw L("Failed to connect to LiveKit room:", T), (i = g.onConnectionStateChange) == null || i.call(g, v.Fail, "internal:init-error"), (M = g.onError) == null || M.call(g, T, { sessionId: "" }), T;
|
|
36
36
|
}
|
|
37
37
|
async function We(T, L, g) {
|
|
38
38
|
var re;
|
|
39
|
-
const i = Fe(g.debug || !1, "LiveKitStreamingManager"), { Room:
|
|
39
|
+
const i = Fe(g.debug || !1, "LiveKitStreamingManager"), { Room: M, RoomEvent: l, ConnectionState: k, Track: H } = await Qe(), { callbacks: n, auth: le, baseURL: he, analytics: G } = g;
|
|
40
40
|
let a = null, w = !1;
|
|
41
41
|
const X = Ne.Fluent;
|
|
42
42
|
let R = null;
|
|
43
43
|
const P = { isPublishing: !1, publication: null }, J = { isPublishing: !1, publication: null };
|
|
44
|
-
let h = null, f = null,
|
|
45
|
-
a = new
|
|
44
|
+
let h = null, f = null, j = null, _ = !1;
|
|
45
|
+
a = new M({
|
|
46
46
|
adaptiveStream: !1,
|
|
47
47
|
// Must be false to use mediaStreamTrack directly
|
|
48
48
|
dynacast: !0
|
|
49
49
|
});
|
|
50
|
-
let E = null, b = m.Idle,
|
|
51
|
-
const ge = Je(
|
|
52
|
-
let C,
|
|
50
|
+
let E = null, b = m.Idle, I = !0;
|
|
51
|
+
const ge = Je(le, he || Ue, T, n.onError);
|
|
52
|
+
let C, $, K, Y = !0;
|
|
53
53
|
try {
|
|
54
54
|
const e = await ge.createStream({
|
|
55
55
|
transport: L.transport,
|
|
56
56
|
chat_persist: L.chat_persist ?? !0
|
|
57
57
|
}), { id: t, session_token: r, session_url: o, interrupt_enabled: c } = e;
|
|
58
|
-
(re = n.onStreamCreated) == null || re.call(n, { session_id: t, stream_id: t, agent_id: T }), C = t,
|
|
58
|
+
(re = n.onStreamCreated) == null || re.call(n, { session_id: t, stream_id: t, agent_id: T }), C = t, $ = r, K = o, Y = c ?? !0, await a.prepareConnection(K, $);
|
|
59
59
|
} catch (e) {
|
|
60
|
-
|
|
60
|
+
pe(e, i, n);
|
|
61
61
|
}
|
|
62
|
-
if (
|
|
62
|
+
if (!K || !$ || !C)
|
|
63
63
|
return Promise.reject(new Error("Failed to initialize LiveKit stream"));
|
|
64
|
-
a.on(l.ConnectionStateChanged, me).on(l.ConnectionQualityChanged, Ce).on(l.ParticipantConnected, Se).on(l.ParticipantDisconnected, Te).on(l.TrackSubscribed, ve).on(l.TrackUnsubscribed, we).on(l.DataReceived, Pe).on(l.MediaDevicesError, Le).on(l.TranscriptionReceived, fe).on(l.EncryptionError,
|
|
64
|
+
a.on(l.ConnectionStateChanged, me).on(l.ConnectionQualityChanged, Ce).on(l.ParticipantConnected, Se).on(l.ParticipantDisconnected, Te).on(l.TrackSubscribed, ve).on(l.TrackUnsubscribed, we).on(l.DataReceived, Pe).on(l.MediaDevicesError, Le).on(l.TranscriptionReceived, fe).on(l.EncryptionError, Me).on(l.TrackSubscriptionFailed, ke);
|
|
65
65
|
function fe(e, t) {
|
|
66
66
|
t != null && t.isLocal && (de.update(), b === m.Talking && (b = m.Idle));
|
|
67
67
|
}
|
|
68
68
|
try {
|
|
69
|
-
await a.connect(
|
|
69
|
+
await a.connect(K, $), i("LiveKit room joined successfully"), E = setTimeout(() => {
|
|
70
70
|
var e;
|
|
71
71
|
i(
|
|
72
72
|
`Track subscription timeout - no track subscribed within ${ue / 1e3} seconds after connect`
|
|
@@ -76,7 +76,7 @@ async function We(T, L, g) {
|
|
|
76
76
|
}), (e = n.onError) == null || e.call(n, new Error("Track subscription timeout"), { sessionId: C }), W("internal:track-subscription-timeout");
|
|
77
77
|
}, ue);
|
|
78
78
|
} catch (e) {
|
|
79
|
-
|
|
79
|
+
pe(e, i, n);
|
|
80
80
|
}
|
|
81
81
|
G.enrich({
|
|
82
82
|
"stream-type": X
|
|
@@ -84,19 +84,19 @@ async function We(T, L, g) {
|
|
|
84
84
|
function me(e) {
|
|
85
85
|
var t, r, o, c;
|
|
86
86
|
switch (i("Connection state changed:", e), e) {
|
|
87
|
-
case
|
|
87
|
+
case k.Connecting:
|
|
88
88
|
i("CALLBACK: onConnectionStateChange(Connecting)"), (t = n.onConnectionStateChange) == null || t.call(n, v.Connecting, "livekit:connecting");
|
|
89
89
|
break;
|
|
90
|
-
case
|
|
90
|
+
case k.Connected:
|
|
91
91
|
i("LiveKit room connected successfully"), w = !0;
|
|
92
92
|
break;
|
|
93
|
-
case
|
|
94
|
-
i("LiveKit room disconnected"), w = !1,
|
|
93
|
+
case k.Disconnected:
|
|
94
|
+
i("LiveKit room disconnected"), w = !1, _ = !1, P.publication = null, J.publication = null, (r = n.onConnectionStateChange) == null || r.call(n, v.Disconnected, "livekit:disconnected");
|
|
95
95
|
break;
|
|
96
|
-
case
|
|
96
|
+
case k.Reconnecting:
|
|
97
97
|
i("LiveKit room reconnecting..."), (o = n.onConnectionStateChange) == null || o.call(n, v.Connecting, "livekit:reconnecting");
|
|
98
98
|
break;
|
|
99
|
-
case
|
|
99
|
+
case k.SignalReconnecting:
|
|
100
100
|
i("LiveKit room signal reconnecting..."), (c = n.onConnectionStateChange) == null || c.call(n, v.Connecting, "livekit:signal-reconnecting");
|
|
101
101
|
break;
|
|
102
102
|
}
|
|
@@ -113,14 +113,14 @@ async function We(T, L, g) {
|
|
|
113
113
|
}
|
|
114
114
|
function ye() {
|
|
115
115
|
var e;
|
|
116
|
-
|
|
116
|
+
j !== A.Start && (i("CALLBACK: onVideoStateChange(Start)"), j = A.Start, (e = n.onVideoStateChange) == null || e.call(n, A.Start));
|
|
117
117
|
}
|
|
118
118
|
function Z(e) {
|
|
119
119
|
var t;
|
|
120
|
-
|
|
120
|
+
j !== A.Stop && (i("CALLBACK: onVideoStateChange(Stop)"), j = A.Stop, (t = n.onVideoStateChange) == null || t.call(n, A.Stop, e));
|
|
121
121
|
}
|
|
122
122
|
function ve(e, t, r) {
|
|
123
|
-
var c, s,
|
|
123
|
+
var c, s, u;
|
|
124
124
|
i(`Track subscribed: ${e.kind} from ${r.identity}`);
|
|
125
125
|
const o = e.mediaStreamTrack;
|
|
126
126
|
if (!o) {
|
|
@@ -131,16 +131,16 @@ async function We(T, L, g) {
|
|
|
131
131
|
() => e.getRTCStatsReport(),
|
|
132
132
|
({ sttLatency: d, serviceLatency: S }) => {
|
|
133
133
|
var oe, ae, ce;
|
|
134
|
-
const
|
|
135
|
-
let
|
|
134
|
+
const D = de.get(!0);
|
|
135
|
+
let F = 0;
|
|
136
136
|
if (d) {
|
|
137
137
|
const se = ((ae = (oe = h == null ? void 0 : h.getReport()) == null ? void 0 : oe.webRTCStats) == null ? void 0 : ae.avgRtt) ?? 0;
|
|
138
|
-
|
|
138
|
+
F = se > 0 ? Math.round(se * 1e3) : 0;
|
|
139
139
|
}
|
|
140
|
-
const
|
|
141
|
-
(ce = n.onFirstAudioDetected) == null || ce.call(n, { latency:
|
|
140
|
+
const V = D > 0 ? D + (d ?? 0) + F : void 0, y = V !== void 0 && S !== void 0 ? V - S : void 0;
|
|
141
|
+
(ce = n.onFirstAudioDetected) == null || ce.call(n, { latency: V, networkLatency: y });
|
|
142
142
|
}
|
|
143
|
-
)), e.kind === "video" && ((c = n.onStreamReady) == null || c.call(n), i("CALLBACK: onSrcObjectReady"), (s = n.onSrcObjectReady) == null || s.call(n, R),
|
|
143
|
+
)), e.kind === "video" && ((c = n.onStreamReady) == null || c.call(n), i("CALLBACK: onSrcObjectReady"), (s = n.onSrcObjectReady) == null || s.call(n, R), _ || (_ = !0, i("CALLBACK: onConnectionStateChange(Connected)"), (u = n.onConnectionStateChange) == null || u.call(n, v.Connected, "livekit:track-subscribed")), h = je(
|
|
144
144
|
() => e.getRTCStatsReport(),
|
|
145
145
|
() => w,
|
|
146
146
|
Oe,
|
|
@@ -158,31 +158,32 @@ async function We(T, L, g) {
|
|
|
158
158
|
r && ((o = n.onMessage) == null || o.call(n, r, { event: r, ...t }));
|
|
159
159
|
}
|
|
160
160
|
function B(e, t) {
|
|
161
|
-
var r, o, c, s;
|
|
162
|
-
if (e ===
|
|
163
|
-
|
|
161
|
+
var r, o, c, s, u;
|
|
162
|
+
if (e === p.ToolCallStarted) {
|
|
163
|
+
const d = t;
|
|
164
|
+
I = d.interruptible !== !1, (r = n.onInterruptibleChange) == null || r.call(n, I), b = m.ToolActive, (o = n.onAgentActivityStateChange) == null || o.call(n, m.ToolActive), (c = n.onToolEvent) == null || c.call(n, p.ToolCallStarted, d);
|
|
164
165
|
return;
|
|
165
166
|
}
|
|
166
|
-
if (e ===
|
|
167
|
-
(
|
|
167
|
+
if (e === p.ToolCallDone) {
|
|
168
|
+
(s = n.onToolEvent) == null || s.call(n, p.ToolCallDone, t);
|
|
168
169
|
return;
|
|
169
170
|
}
|
|
170
|
-
e ===
|
|
171
|
+
e === p.ToolCallError && ((u = n.onToolEvent) == null || u.call(n, p.ToolCallError, t));
|
|
171
172
|
}
|
|
172
173
|
function Ee(e, t) {
|
|
173
|
-
var r, o, c, s,
|
|
174
|
-
if (
|
|
174
|
+
var r, o, c, s, u;
|
|
175
|
+
if (I = ((r = t.metadata) == null ? void 0 : r.interruptible) !== !1, (o = n.onInterruptibleChange) == null || o.call(n, I), e === p.StreamVideoCreated) {
|
|
175
176
|
b = m.Talking, (c = n.onAgentActivityStateChange) == null || c.call(n, m.Talking), f == null || f.arm({
|
|
176
177
|
sttLatency: (s = t == null ? void 0 : t.stt) == null ? void 0 : s.latency,
|
|
177
178
|
serviceLatency: t == null ? void 0 : t.serviceLatency
|
|
178
179
|
});
|
|
179
180
|
return;
|
|
180
181
|
}
|
|
181
|
-
|
|
182
|
+
I && (b = m.Idle, (u = n.onAgentActivityStateChange) == null || u.call(n, m.Idle));
|
|
182
183
|
}
|
|
183
184
|
function x(e, t) {
|
|
184
|
-
var s,
|
|
185
|
-
const r = ((
|
|
185
|
+
var s, u, d, S;
|
|
186
|
+
const r = ((u = (s = h == null ? void 0 : h.getReport()) == null ? void 0 : s.webRTCStats) == null ? void 0 : u.avgRtt) ?? 0, o = r > 0 ? Math.round(r / 2 * 1e3) : 0, c = { ...t, downstreamNetworkLatency: o };
|
|
186
187
|
g.debug && ((d = t == null ? void 0 : t.metadata) != null && d.sentiment) && (c.sentiment = {
|
|
187
188
|
id: t.metadata.sentiment.id,
|
|
188
189
|
name: t.metadata.sentiment.sentiment
|
|
@@ -196,37 +197,37 @@ async function We(T, L, g) {
|
|
|
196
197
|
});
|
|
197
198
|
}
|
|
198
199
|
const Re = {
|
|
199
|
-
[
|
|
200
|
-
[
|
|
201
|
-
[
|
|
202
|
-
[
|
|
203
|
-
[
|
|
204
|
-
[
|
|
205
|
-
[
|
|
206
|
-
[
|
|
207
|
-
[
|
|
208
|
-
[
|
|
200
|
+
[p.ChatAnswer]: ee,
|
|
201
|
+
[p.ChatPartial]: ee,
|
|
202
|
+
[p.ToolCallStarted]: B,
|
|
203
|
+
[p.ToolCallDone]: B,
|
|
204
|
+
[p.ToolCallError]: B,
|
|
205
|
+
[p.StreamVideoCreated]: x,
|
|
206
|
+
[p.StreamVideoDone]: x,
|
|
207
|
+
[p.StreamVideoError]: x,
|
|
208
|
+
[p.StreamVideoRejected]: x,
|
|
209
|
+
[p.ChatAudioTranscribed]: Ae
|
|
209
210
|
};
|
|
210
211
|
function Pe(e, t, r, o) {
|
|
211
212
|
const c = new TextDecoder().decode(e);
|
|
212
213
|
try {
|
|
213
|
-
const s = JSON.parse(c),
|
|
214
|
-
if (i("Data received:", { subject:
|
|
215
|
-
const d = Re[
|
|
216
|
-
d == null || d(
|
|
214
|
+
const s = JSON.parse(c), u = o || s.subject;
|
|
215
|
+
if (i("Data received:", { subject: u, data: s }), !u) return;
|
|
216
|
+
const d = Re[u];
|
|
217
|
+
d == null || d(u, s);
|
|
217
218
|
} catch (s) {
|
|
218
219
|
i("Failed to parse data channel message:", s);
|
|
219
220
|
}
|
|
220
221
|
}
|
|
221
222
|
function Le(e) {
|
|
222
223
|
var t;
|
|
223
|
-
i("Media devices error:", e), (t = n.onError) == null || t.call(n, new Error(
|
|
224
|
+
i("Media devices error:", e), (t = n.onError) == null || t.call(n, new Error(U), { sessionId: C });
|
|
224
225
|
}
|
|
225
|
-
function
|
|
226
|
+
function Me(e) {
|
|
226
227
|
var t;
|
|
227
|
-
i("Encryption error:", e), (t = n.onError) == null || t.call(n, new Error(
|
|
228
|
+
i("Encryption error:", e), (t = n.onError) == null || t.call(n, new Error(U), { sessionId: C });
|
|
228
229
|
}
|
|
229
|
-
function
|
|
230
|
+
function ke(e, t, r) {
|
|
230
231
|
i("Track subscription failed:", { trackSid: e, participant: t, reason: r });
|
|
231
232
|
}
|
|
232
233
|
function be(e, t, r) {
|
|
@@ -239,25 +240,25 @@ async function We(T, L, g) {
|
|
|
239
240
|
return null;
|
|
240
241
|
}
|
|
241
242
|
async function ne(e, t, r, o, c, s) {
|
|
242
|
-
var
|
|
243
|
+
var D, F, V;
|
|
243
244
|
if (!w || !a)
|
|
244
245
|
throw i(`Room is not connected, cannot publish ${o} stream`), new Error("Room is not connected");
|
|
245
246
|
if (e.isPublishing) {
|
|
246
247
|
i(`${o} publish already in progress, skipping`);
|
|
247
248
|
return;
|
|
248
249
|
}
|
|
249
|
-
const
|
|
250
|
-
if (
|
|
250
|
+
const u = r(t);
|
|
251
|
+
if (u.length === 0)
|
|
251
252
|
throw new Error(`No ${o} track found in the provided MediaStream`);
|
|
252
|
-
const d =
|
|
253
|
+
const d = u[0], S = be(d, o, c());
|
|
253
254
|
if (S) {
|
|
254
255
|
i(`${o} track is already published, skipping`, {
|
|
255
256
|
trackId: d.id,
|
|
256
|
-
publishedTrackId: (
|
|
257
|
+
publishedTrackId: (F = (D = S.track) == null ? void 0 : D.mediaStreamTrack) == null ? void 0 : F.id
|
|
257
258
|
}), e.publication = S;
|
|
258
259
|
return;
|
|
259
260
|
}
|
|
260
|
-
if ((
|
|
261
|
+
if ((V = e.publication) != null && V.track) {
|
|
261
262
|
const y = e.publication.track.mediaStreamTrack;
|
|
262
263
|
y !== d && (y == null ? void 0 : y.id) !== d.id && (i(`Unpublishing existing ${o} track before publishing new one`), await s());
|
|
263
264
|
}
|
|
@@ -328,7 +329,7 @@ async function We(T, L, g) {
|
|
|
328
329
|
async function z(e, t) {
|
|
329
330
|
var r, o;
|
|
330
331
|
if (!w || !a) {
|
|
331
|
-
i("Room is not connected for sending messages"), (r = n.onError) == null || r.call(n, new Error(
|
|
332
|
+
i("Room is not connected for sending messages"), (r = n.onError) == null || r.call(n, new Error(U), {
|
|
332
333
|
sessionId: C
|
|
333
334
|
});
|
|
334
335
|
return;
|
|
@@ -336,7 +337,7 @@ async function We(T, L, g) {
|
|
|
336
337
|
try {
|
|
337
338
|
await a.localParticipant.sendText(e, { topic: t }), i("Message sent successfully:", e);
|
|
338
339
|
} catch (c) {
|
|
339
|
-
i("Failed to send message:", c), (o = n.onError) == null || o.call(n, new Error(
|
|
340
|
+
i("Failed to send message:", c), (o = n.onError) == null || o.call(n, new Error(U), { sessionId: C });
|
|
340
341
|
}
|
|
341
342
|
}
|
|
342
343
|
async function ie(e) {
|
|
@@ -345,7 +346,7 @@ async function We(T, L, g) {
|
|
|
345
346
|
const o = JSON.parse(e).topic;
|
|
346
347
|
return z("", o);
|
|
347
348
|
} catch (r) {
|
|
348
|
-
i("Failed to send data channel message:", r), (t = n.onError) == null || t.call(n, new Error(
|
|
349
|
+
i("Failed to send data channel message:", r), (t = n.onError) == null || t.call(n, new Error(U), { sessionId: C });
|
|
349
350
|
}
|
|
350
351
|
}
|
|
351
352
|
function _e(e) {
|
|
@@ -357,7 +358,7 @@ async function We(T, L, g) {
|
|
|
357
358
|
}
|
|
358
359
|
async function W(e) {
|
|
359
360
|
var t, r;
|
|
360
|
-
E && (clearTimeout(E), E = null), f == null || f.destroy(), f = null, a && ((t = n.onConnectionStateChange) == null || t.call(n, v.Disconnecting, e), await Promise.all([Q(), q()]), await a.disconnect()), Ve(), w = !1,
|
|
361
|
+
E && (clearTimeout(E), E = null), f == null || f.destroy(), f = null, a && ((t = n.onConnectionStateChange) == null || t.call(n, v.Disconnecting, e), await Promise.all([Q(), q()]), await a.disconnect()), Ve(), w = !1, _ = !1, (r = n.onAgentActivityStateChange) == null || r.call(n, m.Idle), b = m.Idle;
|
|
361
362
|
}
|
|
362
363
|
return {
|
|
363
364
|
speak(e) {
|
|
@@ -371,15 +372,15 @@ async function We(T, L, g) {
|
|
|
371
372
|
disconnect: () => W("user:disconnect"),
|
|
372
373
|
async reconnect() {
|
|
373
374
|
var e, t;
|
|
374
|
-
if ((a == null ? void 0 : a.state) ===
|
|
375
|
+
if ((a == null ? void 0 : a.state) === k.Connected) {
|
|
375
376
|
i("Room is already connected");
|
|
376
377
|
return;
|
|
377
378
|
}
|
|
378
|
-
if (!a ||
|
|
379
|
+
if (!a || !K || !$)
|
|
379
380
|
throw i("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
|
|
380
|
-
i("Reconnecting to LiveKit room, state:", a.state),
|
|
381
|
+
i("Reconnecting to LiveKit room, state:", a.state), _ = !1, (e = n.onConnectionStateChange) == null || e.call(n, v.Connecting, "user:reconnect");
|
|
381
382
|
try {
|
|
382
|
-
if (await a.connect(
|
|
383
|
+
if (await a.connect(K, $), i("Room reconnected"), w = !0, a.remoteParticipants.size === 0) {
|
|
383
384
|
if (i("Waiting for agent to join..."), !await new Promise((o) => {
|
|
384
385
|
const c = setTimeout(() => {
|
|
385
386
|
a == null || a.off(l.ParticipantConnected, s), o(!1);
|
|
@@ -418,10 +419,10 @@ async function We(T, L, g) {
|
|
|
418
419
|
streamId: C,
|
|
419
420
|
streamType: X,
|
|
420
421
|
interruptAvailable: Y,
|
|
421
|
-
isInterruptible:
|
|
422
|
+
isInterruptible: I
|
|
422
423
|
};
|
|
423
424
|
}
|
|
424
425
|
export {
|
|
425
426
|
We as createLiveKitStreamingManager,
|
|
426
|
-
|
|
427
|
+
pe as handleInitError
|
|
427
428
|
};
|