@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 u, a as Fe, b as Ne, A as m, d as Ue, l as de, e as v, f as F, g as je, h as xe, i as A, n as Oe } from "./index-Bxdy--2d.js";
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 k = De(T, `${L}/v2/agents/${g}`, i);
3
+ const M = De(T, `${L}/v2/agents/${g}`, i);
4
4
  return {
5
5
  async createStream(l) {
6
- return k.post("/sessions", l);
6
+ return M.post("/sessions", l);
7
7
  }
8
8
  };
9
9
  }
10
10
  const Be = {
11
- [u.ChatAnswer]: O.Answer,
12
- [u.ChatPartial]: O.Partial
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: F.Strong,
25
- good: F.Strong,
26
- poor: F.Weak,
27
- lost: F.Unknown,
28
- unknown: F.Unknown
29
- }, N = JSON.stringify({
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 le(T, L, g) {
34
- var i, k;
35
- throw L("Failed to connect to LiveKit room:", T), (i = g.onConnectionStateChange) == null || i.call(g, v.Fail, "internal:init-error"), (k = g.onError) == null || k.call(g, T, { sessionId: "" }), T;
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: k, RoomEvent: l, ConnectionState: M, Track: H } = await Qe(), { callbacks: n, auth: pe, baseURL: he, analytics: G } = g;
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, U = null, V = !1;
45
- a = new k({
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, j = !0;
51
- const ge = Je(pe, he || Ue, T, n.onError);
52
- let C, I, $, Y = !0;
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, I = r, $ = o, Y = c ?? !0, await a.prepareConnection($, I);
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
- le(e, i, n);
60
+ pe(e, i, n);
61
61
  }
62
- if (!$ || !I || !C)
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, ke).on(l.TrackSubscriptionFailed, Me);
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($, I), i("LiveKit room joined successfully"), E = setTimeout(() => {
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
- le(e, i, n);
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 M.Connecting:
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 M.Connected:
90
+ case k.Connected:
91
91
  i("LiveKit room connected successfully"), w = !0;
92
92
  break;
93
- case M.Disconnected:
94
- i("LiveKit room disconnected"), w = !1, V = !1, P.publication = null, J.publication = null, (r = n.onConnectionStateChange) == null || r.call(n, v.Disconnected, "livekit:disconnected");
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 M.Reconnecting:
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 M.SignalReconnecting:
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
- U !== A.Start && (i("CALLBACK: onVideoStateChange(Start)"), U = A.Start, (e = n.onVideoStateChange) == null || e.call(n, A.Start));
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
- U !== A.Stop && (i("CALLBACK: onVideoStateChange(Stop)"), U = A.Stop, (t = n.onVideoStateChange) == null || t.call(n, A.Stop, e));
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, p;
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 _ = de.get(!0);
135
- let D = 0;
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
- D = se > 0 ? Math.round(se * 1e3) : 0;
138
+ F = se > 0 ? Math.round(se * 1e3) : 0;
139
139
  }
140
- const K = _ > 0 ? _ + (d ?? 0) + D : void 0, y = K !== void 0 && S !== void 0 ? K - S : void 0;
141
- (ce = n.onFirstAudioDetected) == null || ce.call(n, { latency: K, networkLatency: y });
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), V || (V = !0, i("CALLBACK: onConnectionStateChange(Connected)"), (p = n.onConnectionStateChange) == null || p.call(n, v.Connected, "livekit:track-subscribed")), h = je(
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 === u.ToolCallStarted) {
163
- b = m.ToolActive, (r = n.onAgentActivityStateChange) == null || r.call(n, m.ToolActive), (o = n.onToolEvent) == null || o.call(n, u.ToolCallStarted, t);
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 === u.ToolCallDone) {
167
- (c = n.onToolEvent) == null || c.call(n, u.ToolCallDone, t);
167
+ if (e === p.ToolCallDone) {
168
+ (s = n.onToolEvent) == null || s.call(n, p.ToolCallDone, t);
168
169
  return;
169
170
  }
170
- e === u.ToolCallError && ((s = n.onToolEvent) == null || s.call(n, u.ToolCallError, t));
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, p;
174
- if (j = ((r = t.metadata) == null ? void 0 : r.interruptible) !== !1, (o = n.onInterruptibleChange) == null || o.call(n, j), e === u.StreamVideoCreated) {
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
- j && (b = m.Idle, (p = n.onAgentActivityStateChange) == null || p.call(n, m.Idle));
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, p, d, S;
185
- const r = ((p = (s = h == null ? void 0 : h.getReport()) == null ? void 0 : s.webRTCStats) == null ? void 0 : p.avgRtt) ?? 0, o = r > 0 ? Math.round(r / 2 * 1e3) : 0, c = { ...t, downstreamNetworkLatency: o };
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
- [u.ChatAnswer]: ee,
200
- [u.ChatPartial]: ee,
201
- [u.ToolCallStarted]: B,
202
- [u.ToolCallDone]: B,
203
- [u.ToolCallError]: B,
204
- [u.StreamVideoCreated]: x,
205
- [u.StreamVideoDone]: x,
206
- [u.StreamVideoError]: x,
207
- [u.StreamVideoRejected]: x,
208
- [u.ChatAudioTranscribed]: Ae
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), p = o || s.subject;
214
- if (i("Data received:", { subject: p, data: s }), !p) return;
215
- const d = Re[p];
216
- d == null || d(p, s);
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(N), { sessionId: C });
224
+ i("Media devices error:", e), (t = n.onError) == null || t.call(n, new Error(U), { sessionId: C });
224
225
  }
225
- function ke(e) {
226
+ function Me(e) {
226
227
  var t;
227
- i("Encryption error:", e), (t = n.onError) == null || t.call(n, new Error(N), { sessionId: C });
228
+ i("Encryption error:", e), (t = n.onError) == null || t.call(n, new Error(U), { sessionId: C });
228
229
  }
229
- function Me(e, t, r) {
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 _, D, K;
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 p = r(t);
250
- if (p.length === 0)
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 = p[0], S = be(d, o, c());
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: (D = (_ = S.track) == null ? void 0 : _.mediaStreamTrack) == null ? void 0 : D.id
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 ((K = e.publication) != null && K.track) {
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(N), {
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(N), { sessionId: C });
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(N), { sessionId: C });
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, V = !1, (r = n.onAgentActivityStateChange) == null || r.call(n, m.Idle), b = m.Idle;
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) === M.Connected) {
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 || !$ || !I)
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), V = !1, (e = n.onConnectionStateChange) == null || e.call(n, v.Connecting, "user:reconnect");
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($, I), i("Room reconnected"), w = !0, a.remoteParticipants.size === 0) {
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: j
422
+ isInterruptible: I
422
423
  };
423
424
  }
424
425
  export {
425
426
  We as createLiveKitStreamingManager,
426
- le as handleInitError
427
+ pe as handleInitError
427
428
  };
@@ -162,6 +162,7 @@ export interface ToolCallStartedPayload {
162
162
  name: string;
163
163
  input: Record<string, unknown>;
164
164
  output: Record<string, unknown>;
165
+ interruptible: boolean;
165
166
  timestamp: string;
166
167
  }
167
168
  export interface ToolCallDonePayload {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@d-id/client-sdk",
3
3
  "private": false,
4
- "version": "1.1.66",
4
+ "version": "1.1.67",
5
5
  "type": "module",
6
6
  "description": "d-id client sdk",
7
7
  "repository": {