@d-id/client-sdk 1.1.31-staging.143 → 1.1.31

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 CHANGED
@@ -48,7 +48,7 @@ const gn = (e) => {
48
48
  throw new Error(`Unknown video type: ${e}`);
49
49
  }
50
50
  };
51
- var C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}), ie = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ie || {}), q = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e))(q || {}), j = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(j || {}), S = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(S || {}), ae = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(ae || {}), ye = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(ye || {}), ct = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(ct || {}), dt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(dt || {});
51
+ var C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}), re = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(re || {}), q = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e))(q || {}), j = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(j || {}), S = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(S || {}), ae = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(ae || {}), ye = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(ye || {}), ct = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(ct || {}), dt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(dt || {});
52
52
  const ut = 45 * 1e3, lt = "X-Playground-Chat", ge = "https://api.d-id.com", ft = "wss://notifications.d-id.com", mt = "79f81a83a67430be2bc0fd61042b8faa", Ue = (e) => new Promise((t) => setTimeout(t, e)), ue = (e = 16) => {
53
53
  const t = new Uint8Array(e);
54
54
  return window.crypto.getRandomValues(t), Array.from(t, (a) => a.toString(16).padStart(2, "0")).join("").slice(0, 13);
@@ -315,7 +315,7 @@ function _e() {
315
315
  get: (t = !1) => t ? Date.now() - e : e
316
316
  };
317
317
  }
318
- const ee = _e(), Re = _e(), Fe = _e();
318
+ const ie = _e(), Re = _e(), Fe = _e();
319
319
  function qe(e) {
320
320
  return e === N.Playground ? { headers: { [lt]: "true" } } : {};
321
321
  }
@@ -360,11 +360,11 @@ async function Se() {
360
360
  }
361
361
  }
362
362
  const Tt = {
363
- excellent: ie.Strong,
364
- good: ie.Strong,
365
- poor: ie.Weak,
366
- lost: ie.Unknown,
367
- unknown: ie.Unknown
363
+ excellent: re.Strong,
364
+ good: re.Strong,
365
+ poor: re.Weak,
366
+ lost: re.Unknown,
367
+ unknown: re.Unknown
368
368
  }, me = JSON.stringify({
369
369
  kind: "InternalServerError",
370
370
  description: "Stream Error"
@@ -388,10 +388,10 @@ async function _t(e, t, a) {
388
388
  let z = null;
389
389
  const T = 2e4;
390
390
  let W = q.Idle;
391
- const te = It(r, d || ge, e, i.onError);
391
+ const ee = It(r, d || ge, e, i.onError);
392
392
  let E, G, Z;
393
393
  try {
394
- const l = await te.createStream({
394
+ const l = await ee.createStream({
395
395
  transport_provider: ye.Livekit,
396
396
  chat_persist: t.chat_persist ?? !0
397
397
  }), { id: g, session_token: v, session_url: D } = l;
@@ -406,7 +406,7 @@ async function _t(e, t, a) {
406
406
  u.on(o.ConnectionStateChanged, y).on(o.ConnectionQualityChanged, k).on(o.ActiveSpeakersChanged, _).on(o.ParticipantConnected, b).on(o.ParticipantDisconnected, I).on(o.TrackSubscribed, U).on(o.TrackUnsubscribed, H).on(o.DataReceived, Q).on(o.MediaDevicesError, L).on(o.TranscriptionReceived, f).on(o.EncryptionError, K).on(o.TrackSubscriptionFailed, X), (be = i.onConnectionStateChange) == null || be.call(i, S.New);
407
407
  function f(l, g) {
408
408
  var v;
409
- g != null && g.isLocal && (ee.update(), W === q.Talking && ((v = i.onInterruptDetected) == null || v.call(i, { type: "audio" }), W = q.Idle));
409
+ g != null && g.isLocal && W === q.Talking && ((v = i.onInterruptDetected) == null || v.call(i, { type: "audio" }), W = q.Idle);
410
410
  }
411
411
  try {
412
412
  await u.connect(Z, G), n("LiveKit room joined successfully"), z = setTimeout(() => {
@@ -479,37 +479,37 @@ async function _t(e, t, a) {
479
479
  const A = new TextDecoder().decode(l);
480
480
  n("Data received:", A);
481
481
  try {
482
- const ne = JSON.parse(A), ce = D || ne.subject;
482
+ const te = JSON.parse(A), ce = D || te.subject;
483
483
  if (ce === j.ChatAnswer) {
484
- const re = Y.Answer;
485
- (O = i.onMessage) == null || O.call(i, re, {
486
- event: re,
487
- ...ne
484
+ const ne = Y.Answer;
485
+ (O = i.onMessage) == null || O.call(i, ne, {
486
+ event: ne,
487
+ ...te
488
488
  });
489
489
  } else if (ce === j.ChatPartial) {
490
- const re = Y.Partial;
491
- (x = i.onMessage) == null || x.call(i, re, {
492
- event: re,
493
- ...ne
490
+ const ne = Y.Partial;
491
+ (x = i.onMessage) == null || x.call(i, ne, {
492
+ event: ne,
493
+ ...te
494
494
  });
495
495
  } else if ([j.StreamVideoCreated, j.StreamVideoDone].includes(ce)) {
496
496
  W = ce === j.StreamVideoCreated ? q.Talking : q.Idle, (le = i.onAgentActivityStateChange) == null || le.call(i, W);
497
- const re = (ne == null ? void 0 : ne.role) || (g == null ? void 0 : g.identity) || "datachannel";
497
+ const ne = (te == null ? void 0 : te.role) || (g == null ? void 0 : g.identity) || "datachannel";
498
498
  (Le = i.onMessage) == null || Le.call(i, ce, {
499
- [re]: ne
499
+ [ne]: te
500
500
  });
501
501
  } else if (ce === j.ChatAudioTranscribed) {
502
- const re = Y.Transcribe;
503
- (je = i.onMessage) == null || je.call(i, re, {
504
- event: re,
505
- ...ne
502
+ const ne = Y.Transcribe;
503
+ (je = i.onMessage) == null || je.call(i, ne, {
504
+ event: ne,
505
+ ...te
506
506
  }), queueMicrotask(() => {
507
507
  var $e;
508
508
  ($e = i.onAgentActivityStateChange) == null || $e.call(i, q.Loading);
509
509
  });
510
510
  }
511
- } catch (ne) {
512
- n("Failed to parse data channel message:", ne);
511
+ } catch (te) {
512
+ n("Failed to parse data channel message:", te);
513
513
  }
514
514
  }
515
515
  function L(l) {
@@ -999,12 +999,12 @@ function Qt() {
999
999
  };
1000
1000
  }
1001
1001
  function Xt(e, t, a, n, s) {
1002
- let o = [], c, i = 0, r = !1, d = ie.Unknown, w = ie.Unknown, p = 0, u = 0;
1002
+ let o = [], c, i = 0, r = !1, d = re.Unknown, w = re.Unknown, p = 0, u = 0;
1003
1003
  const P = Qt();
1004
1004
  return setInterval(async () => {
1005
1005
  const $ = await e.getStats(), { isReceiving: B, avgJitterDelayInInterval: R, freezeCount: M } = P($), z = Wt($);
1006
1006
  if (B)
1007
- i = 0, p = M - u, w = R < qt ? ie.Strong : R > Ht && p > 1 ? ie.Weak : d, w !== d && (s == null || s(w), d = w, u += p, p = 0), r || (n == null || n(C.Start), c = o[o.length - 1], o = [], r = !0), o.push(z);
1007
+ i = 0, p = M - u, w = R < qt ? re.Strong : R > Ht && p > 1 ? re.Weak : d, w !== d && (s == null || s(w), d = w, u += p, p = 0), r || (n == null || n(C.Start), c = o[o.length - 1], o = [], r = !0), o.push(z);
1008
1008
  else if (r && (i++, i >= Ot)) {
1009
1009
  const T = Vt(o, Me, c);
1010
1010
  n == null || n(C.Stop, T), t() || a(), u = M, r = !1;
@@ -1086,14 +1086,14 @@ async function tn(e, t, { debug: a = !1, callbacks: n, auth: s, baseURL: o = ge,
1086
1086
  ), {
1087
1087
  id: T,
1088
1088
  offer: W,
1089
- ice_servers: te,
1089
+ ice_servers: ee,
1090
1090
  session_id: E,
1091
1091
  fluent: G,
1092
1092
  interrupt_enabled: Z,
1093
1093
  triggers_enabled: f
1094
1094
  } = await M(t, i);
1095
1095
  (V = n.onStreamCreated) == null || V.call(n, { stream_id: T, session_id: E, agent_id: e });
1096
- const y = new Yt({ iceServers: te }), k = y.createDataChannel("JanusDataChannel");
1096
+ const y = new Yt({ iceServers: ee }), k = y.createDataChannel("JanusDataChannel");
1097
1097
  if (!E)
1098
1098
  throw new Error("Could not create session_id");
1099
1099
  const _ = G ? ae.Fluent : ae.Legacy;
@@ -1299,9 +1299,9 @@ function dn(e, t, a, n, s) {
1299
1299
  });
1300
1300
  }
1301
1301
  function un(e, t, a, n) {
1302
- ee.get() <= 0 || (e === C.Start ? a.linkTrack(
1302
+ ie.get() <= 0 || (e === C.Start ? a.linkTrack(
1303
1303
  "agent-video",
1304
- { event: "start", latency: ee.get(!0), "stream-type": n },
1304
+ { event: "start", latency: ie.get(!0), "stream-type": n },
1305
1305
  "start",
1306
1306
  [j.StreamVideoCreated]
1307
1307
  ) : e === C.Stop && a.linkTrack(
@@ -1317,9 +1317,9 @@ function un(e, t, a, n) {
1317
1317
  ));
1318
1318
  }
1319
1319
  function ln(e, t, a, n, s) {
1320
- ee.get() <= 0 || (e === C.Start ? n.linkTrack(
1320
+ ie.get() <= 0 || (e === C.Start ? n.linkTrack(
1321
1321
  "agent-video",
1322
- { event: "start", latency: ee.get(!0), "stream-type": s },
1322
+ { event: "start", latency: ie.get(!0), "stream-type": s },
1323
1323
  "start",
1324
1324
  [j.StreamVideoCreated]
1325
1325
  ) : e === C.Stop && n.linkTrack(
@@ -1336,7 +1336,7 @@ function ln(e, t, a, n, s) {
1336
1336
  ));
1337
1337
  }
1338
1338
  function Ke(e, t, a, n) {
1339
- return ee.reset(), Fe.update(), new Promise(async (s, o) => {
1339
+ return ie.reset(), Fe.update(), new Promise(async (s, o) => {
1340
1340
  try {
1341
1341
  let c, i = !1;
1342
1342
  const r = sn(e, t);
@@ -1416,7 +1416,7 @@ async function fn(e, t, a, n, s) {
1416
1416
  t.mode,
1417
1417
  t.persistentChat,
1418
1418
  s
1419
- ), z = Ke(e, t, n, B).then((te) => (R = te, te)), [T, W] = await Promise.all([M, z]);
1419
+ ), z = Ke(e, t, n, B).then((ee) => (R = ee, ee)), [T, W] = await Promise.all([M, z]);
1420
1420
  return { chatResult: T, streamingManager: W };
1421
1421
  } catch (M) {
1422
1422
  throw $.abort(), R && await R.disconnect().catch(() => {
@@ -1463,7 +1463,7 @@ async function hn(e, t) {
1463
1463
  d.track("agent-video-interrupt", {
1464
1464
  type: f || "click",
1465
1465
  video_duration_to_interrupt: Re.get(!0),
1466
- message_duration_to_interrupt: ee.get(!0)
1466
+ message_duration_to_interrupt: ie.get(!0)
1467
1467
  }), y.interrupted = !0, (_ = (k = t.callbacks).onNewMessage) == null || _.call(k, [...r.messages], "answer"), P ? Lt(r.streamingManager) : (Pt(r.streamingManager, (b = r.streamingManager) == null ? void 0 : b.streamType, n), bt(r.streamingManager, n));
1468
1468
  }, z = Date.now();
1469
1469
  Be(() => {
@@ -1471,7 +1471,7 @@ async function hn(e, t) {
1471
1471
  });
1472
1472
  async function T(f) {
1473
1473
  var U, H, Q, L, K, X, oe;
1474
- (H = (U = t.callbacks).onConnectionStateChange) == null || H.call(U, S.Connecting), ee.reset(), f && !a && (delete r.chat, (L = (Q = t.callbacks).onNewMessage) == null || L.call(Q, [...r.messages], "answer"));
1474
+ (H = (U = t.callbacks).onConnectionStateChange) == null || H.call(U, S.Connecting), ie.reset(), f && !a && (delete r.chat, (L = (Q = t.callbacks).onNewMessage) == null || L.call(Q, [...r.messages], "answer"));
1475
1475
  const y = i === N.DirectPlayback || P ? Promise.resolve(void 0) : xt(
1476
1476
  t.auth,
1477
1477
  o,
@@ -1503,19 +1503,19 @@ async function hn(e, t) {
1503
1503
  }
1504
1504
  ).catch((V) => {
1505
1505
  var m, h;
1506
- throw te(N.Maintenance), (h = (m = t.callbacks).onConnectionStateChange) == null || h.call(m, S.Fail), V;
1506
+ throw ee(N.Maintenance), (h = (m = t.callbacks).onConnectionStateChange) == null || h.call(m, S.Fail), V;
1507
1507
  }), [_, { streamingManager: b, chat: I }] = await Promise.all([y, k]);
1508
1508
  I && I.id !== ((K = r.chat) == null ? void 0 : K.id) && ((oe = (X = t.callbacks).onNewChat) == null || oe.call(X, I.id)), r.streamingManager = b, r.socketManager = _, r.chat = I, a = !1, d.enrich({
1509
1509
  chatId: I == null ? void 0 : I.id,
1510
1510
  streamId: b == null ? void 0 : b.streamId,
1511
1511
  mode: r.chatMode
1512
- }), te((I == null ? void 0 : I.chat_mode) ?? i);
1512
+ }), ee((I == null ? void 0 : I.chat_mode) ?? i);
1513
1513
  }
1514
1514
  async function W() {
1515
1515
  var f, y, k, _;
1516
1516
  (f = r.socketManager) == null || f.disconnect(), await ((y = r.streamingManager) == null ? void 0 : y.disconnect()), delete r.streamingManager, delete r.socketManager, (_ = (k = t.callbacks).onConnectionStateChange) == null || _.call(k, S.Disconnected);
1517
1517
  }
1518
- async function te(f) {
1518
+ async function ee(f) {
1519
1519
  var y, k;
1520
1520
  f !== r.chatMode && (d.track("agent-mode-change", { mode: f }), r.chatMode = f, r.chatMode !== N.Functional && await W(), (k = (y = t.callbacks).onModeChange) == null || k.call(y, f));
1521
1521
  }
@@ -1535,7 +1535,7 @@ async function hn(e, t) {
1535
1535
  },
1536
1536
  starterMessages: ((Z = u.knowledge) == null ? void 0 : Z.starter_message) || [],
1537
1537
  getSTTToken: () => p.getSTTToken(u.id),
1538
- changeMode: te,
1538
+ changeMode: ee,
1539
1539
  enrichAnalytics: d.enrich,
1540
1540
  async connect() {
1541
1541
  await T(!0), d.track("agent-chat", {
@@ -1649,7 +1649,7 @@ async function hn(e, t) {
1649
1649
  id: ue(),
1650
1650
  role: "user",
1651
1651
  content: f,
1652
- created_at: new Date(ee.update()).toISOString()
1652
+ created_at: new Date(ie.update()).toISOString()
1653
1653
  }), (I = (b = t.callbacks).onNewMessage) == null || I.call(b, [...r.messages], "user");
1654
1654
  const L = await k(), K = await _([...r.messages], L);
1655
1655
  return r.messages.push({
@@ -1663,7 +1663,7 @@ async function hn(e, t) {
1663
1663
  event: "success",
1664
1664
  messages: r.messages.length + 1
1665
1665
  }), K.result && ((H = (U = t.callbacks).onNewMessage) == null || H.call(U, [...r.messages], "answer"), d.track("agent-message-received", {
1666
- latency: ee.get(!0),
1666
+ latency: ie.get(!0),
1667
1667
  messages: r.messages.length
1668
1668
  })), K;
1669
1669
  } catch (L) {
@@ -1730,7 +1730,7 @@ async function hn(e, t) {
1730
1730
  return f;
1731
1731
  }
1732
1732
  const k = y();
1733
- if (d.track("agent-speak", k), ee.update(), r.messages && k.type === "text" && (r.messages.push({
1733
+ if (d.track("agent-speak", k), ie.update(), r.messages && k.type === "text" && (r.messages.push({
1734
1734
  id: ue(),
1735
1735
  role: "assistant",
1736
1736
  content: k.input,
@@ -1759,7 +1759,7 @@ export {
1759
1759
  Ze as ChatModeDowngraded,
1760
1760
  Y as ChatProgress,
1761
1761
  S as ConnectionState,
1762
- ie as ConnectivityState,
1762
+ re as ConnectivityState,
1763
1763
  st as DocumentType,
1764
1764
  ot as KnowledgeType,
1765
1765
  nt as PlanGroup,