@d-id/client-sdk 1.0.19-beta.36 → 1.0.19-beta.37

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
@@ -1,16 +1,20 @@
1
1
  const S = "https://api.d-id.com", Q = "wss://notifications.d-id.com";
2
+ function X() {
3
+ let e = window.localStorage.getItem("external_key_d_id");
4
+ return e || (e = Math.random().toString(16).slice(2), window.localStorage.setItem("external_key_d_id", e)), e;
5
+ }
2
6
  function U(e) {
3
7
  if (e.type === "bearer")
4
8
  return `Bearer ${e.token}`;
5
9
  if (e.type === "basic")
6
10
  return `Basic ${btoa(`${e.username}:${e.password}`)}`;
7
11
  if (e.type === "key")
8
- return `Client-Key ${e.clientKey}.${e.externalId}`;
12
+ return `Client-Key ${e.clientKey}.${X()}`;
9
13
  throw new Error(`Unknown auth type: ${e}`);
10
14
  }
11
- function b(e, s = S) {
15
+ function b(e, i = S) {
12
16
  const n = async (t, r) => {
13
- const a = await fetch(s + (t != null && t.startsWith("/") ? t : `/${t}`), {
17
+ const a = await fetch(i + (t != null && t.startsWith("/") ? t : `/${t}`), {
14
18
  ...r,
15
19
  headers: {
16
20
  ...r == null ? void 0 : r.headers,
@@ -54,8 +58,8 @@ function b(e, s = S) {
54
58
  }
55
59
  };
56
60
  }
57
- function F(e, s = S) {
58
- const n = b(e, `${s}/agents`);
61
+ function F(e, i = S) {
62
+ const n = b(e, `${i}/agents`);
59
63
  return {
60
64
  create(t, r) {
61
65
  return n.post("/", t, r);
@@ -80,8 +84,8 @@ function F(e, s = S) {
80
84
  }
81
85
  };
82
86
  }
83
- function X(e, s = S) {
84
- const n = b(e, `${s}/knowledge`);
87
+ function Y(e, i = S) {
88
+ const n = b(e, `${i}/knowledge`);
85
89
  return {
86
90
  createKnowledge(t, r) {
87
91
  return n.post("/", t, r);
@@ -117,8 +121,8 @@ function X(e, s = S) {
117
121
  }
118
122
  };
119
123
  }
120
- function Y(e, s = S) {
121
- const n = b(e, `${s}/chats/ratings`);
124
+ function Z(e, i = S) {
125
+ const n = b(e, `${i}/chats/ratings`);
122
126
  return {
123
127
  create(t, r) {
124
128
  return n.post("/", t, r);
@@ -134,9 +138,9 @@ function Y(e, s = S) {
134
138
  }
135
139
  };
136
140
  }
137
- const Z = (e) => new Promise((s) => setTimeout(s, e));
138
- function O(e) {
139
- return new Promise((s, n) => {
141
+ const O = (e) => new Promise((i) => setTimeout(i, e));
142
+ function j(e) {
143
+ return new Promise((i, n) => {
140
144
  const {
141
145
  callbacks: t,
142
146
  host: r,
@@ -148,31 +152,31 @@ function O(e) {
148
152
  onError: f = null
149
153
  } = t || {}, m = new WebSocket(`${r}?authorization=${U(a)}`);
150
154
  m.onmessage = d, m.onclose = g, m.onerror = (l) => {
151
- console.log(l), f == null || f(l), n(l);
155
+ console.error(l), f == null || f(l), n(l);
152
156
  }, m.onopen = (l) => {
153
- u == null || u(l), s(m);
157
+ u == null || u(l), i(m);
154
158
  };
155
159
  });
156
160
  }
157
- async function j(e) {
161
+ async function ee(e) {
158
162
  const {
159
- retries: s = 1
163
+ retries: i = 1
160
164
  } = e;
161
165
  let n = null;
162
166
  for (let t = 0; (n == null ? void 0 : n.readyState) !== WebSocket.OPEN; t++)
163
167
  try {
164
- n = await O(e);
168
+ n = await j(e);
165
169
  } catch (r) {
166
- if (t === s)
170
+ if (t === i)
167
171
  throw r;
168
- await Z(t * 500);
172
+ await O(t * 500);
169
173
  }
170
174
  return n;
171
175
  }
172
- async function ee(e, s, n) {
173
- const t = n ? [n] : [], r = await j({
176
+ async function te(e, i, n) {
177
+ const t = n ? [n] : [], r = await ee({
174
178
  auth: e,
175
- host: s,
179
+ host: i,
176
180
  callbacks: {
177
181
  onMessage: (a) => {
178
182
  const d = JSON.parse(a.data);
@@ -186,8 +190,8 @@ async function ee(e, s, n) {
186
190
  subscribeToEvents: (a) => t.push(a)
187
191
  };
188
192
  }
189
- var te = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(te || {}), ne = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(ne || {}), A = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(A || {}), _ = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e))(_ || {}), re = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(re || {}), ae = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e))(ae || {}), K = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(K || {}), se = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(se || {}), ie = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(ie || {}), oe = /* @__PURE__ */ ((e) => (e.Pdf = "pdf", e.Text = "text", e.Html = "html", e.Word = "word", e.Json = "json", e.Markdown = "markdown", e.Csv = "csv", e.Excel = "excel", e.Powerpoint = "powerpoint", e.Archive = "archive", e.Image = "image", e.Audio = "audio", e.Video = "video", e))(oe || {}), I = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(I || {});
190
- function ce(e) {
193
+ var ne = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(ne || {}), re = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(re || {}), _ = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(_ || {}), A = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e))(A || {}), ae = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(ae || {}), ie = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e))(ie || {}), K = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(K || {}), se = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(se || {}), oe = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(oe || {}), ce = /* @__PURE__ */ ((e) => (e.Pdf = "pdf", e.Text = "text", e.Html = "html", e.Word = "word", e.Json = "json", e.Markdown = "markdown", e.Csv = "csv", e.Excel = "excel", e.Powerpoint = "powerpoint", e.Archive = "archive", e.Image = "image", e.Audio = "audio", e.Video = "video", e))(ce || {}), I = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(I || {});
194
+ function de(e) {
191
195
  return e.presenter.type === I.Clip ? {
192
196
  videoType: I.Clip,
193
197
  driver_id: e.presenter.driver_id,
@@ -197,12 +201,12 @@ function ce(e) {
197
201
  source_url: e.presenter.source_url
198
202
  };
199
203
  }
200
- function H(e, s, n, t) {
204
+ function H(e, i, n, t) {
201
205
  return new Promise(async (r, a) => {
202
- const d = await me(ce(e), {
203
- ...s,
206
+ const d = await fe(de(e), {
207
+ ...i,
204
208
  callbacks: {
205
- ...s.callbacks,
209
+ ...i.callbacks,
206
210
  onConnectionStateChange: async (u) => {
207
211
  var g, f;
208
212
  if (u === "connected")
@@ -216,12 +220,12 @@ function H(e, s, n, t) {
216
220
  }
217
221
  else
218
222
  u === "failed" && a(new Error("Cannot create connection"));
219
- (f = (g = s.callbacks).onConnectionStateChange) == null || f.call(g, u);
223
+ (f = (g = i.callbacks).onConnectionStateChange) == null || f.call(g, u);
220
224
  },
221
225
  // TODO remove when webscoket will return partial
222
226
  onMessage: (u, g) => {
223
227
  var f, m;
224
- u === _.ChatAnswer && (console.log("ChatAnswer", u, g), (m = (f = s.callbacks).onChatEvents) == null || m.call(f, K.Answer, {
228
+ u === A.ChatAnswer && (console.log("ChatAnswer", u, g), (m = (f = i.callbacks).onChatEvents) == null || m.call(f, K.Answer, {
225
229
  content: g,
226
230
  event: K.Answer
227
231
  }));
@@ -230,58 +234,58 @@ function H(e, s, n, t) {
230
234
  });
231
235
  });
232
236
  }
233
- function we(e, s, n) {
234
- return F(s, n || S).getById(e);
237
+ function pe(e, i, n) {
238
+ return F(i, n || S).getById(e);
235
239
  }
236
- async function pe(e, s) {
240
+ async function he(e, i) {
237
241
  var k, M;
238
- const n = s.baseURL || S, t = s.wsURL || Q, r = new AbortController(), a = F(s.auth, n), d = Y(s.auth, n), u = X(s.auth, n), g = await a.getById(e);
239
- (M = (k = s.callbacks) == null ? void 0 : k.onAgentReady) == null || M.call(k, g);
240
- const f = await ee(s.auth, t, s.callbacks.onChatEvents);
242
+ const n = i.baseURL || S, t = i.wsURL || Q, r = new AbortController(), a = F(i.auth, n), d = Z(i.auth, n), u = Y(i.auth, n), g = await a.getById(e);
243
+ (M = (k = i.callbacks) == null ? void 0 : k.onAgentReady) == null || M.call(k, g);
244
+ const f = await te(i.auth, t, i.callbacks.onChatEvents);
241
245
  let {
242
246
  chat: m,
243
247
  streamingManager: l
244
- } = await H(g, s, a);
248
+ } = await H(g, i, a);
245
249
  return {
246
250
  agent: g,
247
251
  chatId: m.id,
248
252
  async reconnectToChat() {
249
253
  const {
250
- streamingManager: i
251
- } = await H(g, s, a, m);
252
- l = i;
254
+ streamingManager: s
255
+ } = await H(g, i, a, m);
256
+ l = s;
253
257
  },
254
258
  terminate() {
255
259
  return r.abort(), f.terminate(), l.terminate();
256
260
  },
257
- chat(i) {
261
+ chat(s) {
258
262
  return a.chat(e, m.id, {
259
263
  sessionId: l.sessionId,
260
264
  streamId: l.streamId,
261
- messages: i
265
+ messages: s
262
266
  }, {
263
267
  signal: r.signal
264
268
  });
265
269
  },
266
- rate(i, o) {
267
- return o ? d.update(o, i) : d.create(i);
270
+ rate(s, o) {
271
+ return o ? d.update(o, s) : d.create(s);
268
272
  },
269
- deleteRate(i) {
270
- return d.delete(i);
273
+ deleteRate(s) {
274
+ return d.delete(s);
271
275
  },
272
- speak(i) {
276
+ speak(s) {
273
277
  function o() {
274
- if (i.type === "text")
278
+ if (s.type === "text")
275
279
  return {
276
280
  type: "text",
277
- provider: i.provider,
278
- input: i.input,
279
- ssml: i.ssml || !1
281
+ provider: s.provider,
282
+ input: s.input,
283
+ ssml: s.ssml || !1
280
284
  };
281
- if (i.type === "audio")
285
+ if (s.type === "audio")
282
286
  return {
283
287
  type: "audio",
284
- audio_url: i.audio_url
288
+ audio_url: s.audio_url
285
289
  };
286
290
  throw new Error("Invalid payload");
287
291
  }
@@ -290,13 +294,13 @@ async function pe(e, s) {
290
294
  });
291
295
  },
292
296
  async getStarterMessages() {
293
- var i;
294
- return (i = g.knowledge) != null && i.id ? u.getKnowledge(g.knowledge.id).then((o) => (o == null ? void 0 : o.starter_message) || []) : [];
297
+ var s;
298
+ return (s = g.knowledge) != null && s.id ? u.getKnowledge(g.knowledge.id).then((o) => (o == null ? void 0 : o.starter_message) || []) : [];
295
299
  }
296
300
  };
297
301
  }
298
- function de(e, s) {
299
- const n = b(e, s);
302
+ function le(e, i) {
303
+ const n = b(e, i);
300
304
  return {
301
305
  createStream(t) {
302
306
  return n.post("/clips/streams", {
@@ -330,8 +334,8 @@ function de(e, s) {
330
334
  }
331
335
  };
332
336
  }
333
- function le(e, s) {
334
- const n = b(e, s);
337
+ function ue(e, i) {
338
+ const n = b(e, i);
335
339
  return {
336
340
  createStream(t, r) {
337
341
  return n.post("/talks/streams", {
@@ -366,13 +370,13 @@ function le(e, s) {
366
370
  }
367
371
  };
368
372
  }
369
- function ue(e, s) {
370
- return e.map((n, t) => t === 0 ? s ? {
373
+ function ge(e, i) {
374
+ return e.map((n, t) => t === 0 ? i ? {
371
375
  index: t,
372
376
  timestamp: n.timestamp,
373
- bytesReceived: n.bytesReceived - s.bytesReceived,
374
- packetsReceived: n.packetsReceived - s.packetsReceived,
375
- packetsLost: n.packetsLost - s.packetsLost,
377
+ bytesReceived: n.bytesReceived - i.bytesReceived,
378
+ packetsReceived: n.packetsReceived - i.packetsReceived,
379
+ packetsLost: n.packetsLost - i.packetsLost,
376
380
  jitter: n.jitter,
377
381
  frameWidth: n.frameWidth,
378
382
  frameHeight: n.frameHeight,
@@ -400,14 +404,14 @@ function ue(e, s) {
400
404
  });
401
405
  }
402
406
  let T = !1;
403
- const C = (e, s) => T && console.log(e, s), ge = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
404
- async function me(e, {
405
- debug: s = !1,
407
+ const C = (e, i) => T && console.log(e, i), me = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
408
+ async function fe(e, {
409
+ debug: i = !1,
406
410
  callbacks: n,
407
411
  auth: t,
408
412
  baseURL: r = S
409
413
  }) {
410
- T = s;
414
+ T = i;
411
415
  const a = {
412
416
  ...n
413
417
  }, {
@@ -416,16 +420,16 @@ async function me(e, {
416
420
  close: g,
417
421
  createStream: f,
418
422
  addIceCandidate: m
419
- } = e.videoType === I.Clip ? de(t, r) : le(t, r), {
423
+ } = e.videoType === I.Clip ? le(t, r) : ue(t, r), {
420
424
  id: l,
421
425
  offer: k,
422
426
  ice_servers: M,
423
- session_id: i
424
- } = await f(e), o = new ge({
427
+ session_id: s
428
+ } = await f(e), o = new me({
425
429
  iceServers: M
426
430
  }), E = o.createDataChannel("JanusDataChannel");
427
431
  let v = [], R = 0, P = 0, y, x, W;
428
- if (!i)
432
+ if (!s)
429
433
  throw new Error("Could not create session_id");
430
434
  (() => {
431
435
  W = setInterval(() => {
@@ -443,9 +447,9 @@ async function me(e, {
443
447
  R = v.length;
444
448
  else {
445
449
  const J = v.slice(R), D = R === 0 ? void 0 : v[R - 1];
446
- L = ue(J, D), L = L.sort((V, G) => G.packetsLost - V.packetsLost).slice(0, 5);
450
+ L = ge(J, D), L = L.sort((V, G) => G.packetsLost - V.packetsLost).slice(0, 5);
447
451
  }
448
- (h = a.onVideoStateChange) == null || h.call(a, y ? A.Start : A.Stop, L);
452
+ (h = a.onVideoStateChange) == null || h.call(a, y ? _.Start : _.Stop, L);
449
453
  }
450
454
  }
451
455
  v.push(p);
@@ -462,7 +466,7 @@ async function me(e, {
462
466
  candidate: c.candidate.candidate,
463
467
  sdpMid: c.candidate.sdpMid,
464
468
  sdpMLineIndex: c.candidate.sdpMLineIndex
465
- }, i);
469
+ }, s);
466
470
  }, o.oniceconnectionstatechange = () => {
467
471
  var c;
468
472
  C("peerConnection.oniceconnectionstatechange => " + o.iceConnectionState), (c = a.onConnectionStateChange) == null || c.call(a, o.iceConnectionState);
@@ -473,33 +477,33 @@ async function me(e, {
473
477
  var w, p;
474
478
  if (E.readyState === "open") {
475
479
  const [h, $] = c.data.split(":");
476
- h === _.StreamStarted ? console.log("StreamStarted", h, $) : h === _.StreamDone ? console.log("StreamDone") : h === _.StreamFailed ? ((w = a.onVideoStateChange) == null || w.call(a, A.Stop, {
480
+ h === A.StreamStarted ? console.log("StreamStarted", h, $) : h === A.StreamDone ? console.log("StreamDone") : h === A.StreamFailed ? ((w = a.onVideoStateChange) == null || w.call(a, _.Stop, {
477
481
  event: h,
478
482
  data: $
479
483
  }), v = [], R = 0, P = 0, y = !1, console.log("StreamFailed")) : (p = a.onMessage) == null || p.call(a, h, decodeURIComponent($));
480
484
  }
481
485
  }, await o.setRemoteDescription(k), C("set remote description OK");
482
486
  const B = await o.createAnswer();
483
- return C("create answer OK"), await o.setLocalDescription(B), C("set local description OK"), await d(l, B, i), C("start connection OK"), {
487
+ return C("create answer OK"), await o.setLocalDescription(B), C("set local description OK"), await d(l, B, s), C("start connection OK"), {
484
488
  /**
485
489
  * Method to send request to server to get clip or talk depend on you payload
486
490
  * @param payload
487
491
  */
488
492
  speak(c) {
489
- return u(l, i, c);
493
+ return u(l, s, c);
490
494
  },
491
495
  /**
492
496
  * Method to close RTC connection
493
497
  */
494
498
  async terminate() {
495
499
  var c, w;
496
- l && (o && (o.close(), o.oniceconnectionstatechange = null, o.onnegotiationneeded = null, o.onicecandidate = null, o.ontrack = null, clearInterval(x)), await g(l, i).catch((p) => {
497
- }), (c = a.onConnectionStateChange) == null || c.call(a, "closed"), (w = a.onVideoStateChange) == null || w.call(a, A.Stop), q(), clearInterval(W));
500
+ l && (o && (o.close(), o.oniceconnectionstatechange = null, o.onnegotiationneeded = null, o.onicecandidate = null, o.ontrack = null, clearInterval(x)), await g(l, s).catch((p) => {
501
+ }), (c = a.onConnectionStateChange) == null || c.call(a, "closed"), (w = a.onVideoStateChange) == null || w.call(a, _.Stop), q(), clearInterval(W));
498
502
  },
499
503
  /**
500
504
  * Session identifier information, should be returned in the body of all streaming requests
501
505
  */
502
- sessionId: i,
506
+ sessionId: s,
503
507
  /**
504
508
  * Id of current RTC stream
505
509
  */
@@ -515,21 +519,21 @@ async function me(e, {
515
519
  };
516
520
  }
517
521
  export {
518
- ae as ChatMode,
522
+ ie as ChatMode,
519
523
  K as ChatProgress,
520
- oe as DocumentType,
521
- ie as KnowledgeType,
522
- te as Providers,
523
- re as RateState,
524
- ee as SocketManager,
525
- _ as StreamEvents,
524
+ ce as DocumentType,
525
+ oe as KnowledgeType,
526
+ ne as Providers,
527
+ ae as RateState,
528
+ te as SocketManager,
529
+ A as StreamEvents,
526
530
  se as Subject,
527
- ne as VoiceAccess,
528
- pe as createAgentManager,
531
+ re as VoiceAccess,
532
+ he as createAgentManager,
529
533
  F as createAgentsApi,
530
534
  b as createClient,
531
- X as createKnowledgeApi,
532
- Y as createRatingsApi,
533
- me as createStreamingManager,
534
- we as getAgent
535
+ Y as createKnowledgeApi,
536
+ Z as createRatingsApi,
537
+ fe as createStreamingManager,
538
+ pe as getAgent
535
539
  };
@@ -1 +1 @@
1
- (function(d,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(d=typeof globalThis<"u"?globalThis:d||self,p(d.index={}))})(this,function(d){"use strict";const p="https://api.d-id.com",j="wss://notifications.d-id.com";function W(e){if(e.type==="bearer")return`Bearer ${e.token}`;if(e.type==="basic")return`Basic ${btoa(`${e.username}:${e.password}`)}`;if(e.type==="key")return`Client-Key ${e.clientKey}.${e.externalId}`;throw new Error(`Unknown auth type: ${e}`)}function k(e,i=p){const n=async(t,a)=>{const r=await fetch(i+(t!=null&&t.startsWith("/")?t:`/${t}`),{...a,headers:{...a==null?void 0:a.headers,Authorization:W(e),"Content-Type":"application/json"}});if(!r.ok){let l=await r.text().catch(()=>"Failed to fetch");throw new Error(l)}return r.json()};return{get(t,a){return n(t,{...a,method:"GET"})},post(t,a,r){return n(t,{...r,body:JSON.stringify(a),method:"POST"})},delete(t,a,r){return n(t,{...r,body:JSON.stringify(a),method:"DELETE"})},patch(t,a,r){return n(t,{...r,body:JSON.stringify(a),method:"PATCH"})}}}function T(e,i=p){const n=k(e,`${i}/agents`);return{create(t,a){return n.post("/",t,a)},getAgents(t,a){return n.get(`/${t?`?tag=${t}`:""}`,a).then(r=>r??[])},getById(t,a){return n.get(`/${t}`,a)},delete(t,a){return n.delete(`/${t}`,void 0,a)},update(t,a,r){return n.patch(`/${t}`,a,r)},newChat(t,a){return n.post(`/${t}/chat`,void 0,a)},chat(t,a,r,l){return n.post(`/${t}/chat/${a}`,r,l)}}}function B(e,i=p){const n=k(e,`${i}/knowledge`);return{createKnowledge(t,a){return n.post("/",t,a)},getKnowledgeBase(t){return n.get("/",t)},getKnowledge(t,a){return n.get(`/${t}`,a)},deleteKnowledge(t,a){return n.delete(`/${t}`,void 0,a)},createDocument(t,a,r){return n.post(`/${t}/documents`,a,r)},deleteDocument(t,a,r){return n.delete(`/${t}/documents/${a}`,void 0,r)},getDocuments(t,a){return n.get(`/${t}/documents`,a)},getDocument(t,a,r){return n.get(`/${t}/documents/${a}`,r)},getRecords(t,a,r){return n.get(`/${t}/documents/${a}/records`,r)},query(t,a,r){return n.post(`/${t}/query`,{query:a},r)}}}function H(e,i=p){const n=k(e,`${i}/chats/ratings`);return{create(t,a){return n.post("/",t,a)},getByKnowledge(t,a){return n.get(`/${t}`,a).then(r=>r??[])},update(t,a,r){return n.patch(`/${t}`,a,r)},delete(t,a){return n.delete(`/${t}`,a)}}}const ee=e=>new Promise(i=>setTimeout(i,e));function te(e){return new Promise((i,n)=>{const{callbacks:t,host:a,auth:r}=e,{onMessage:l=null,onOpen:g=null,onClose:m=null,onError:w=null}=t||{},f=new WebSocket(`${a}?authorization=${W(r)}`);f.onmessage=l,f.onclose=m,f.onerror=u=>{console.log(u),w==null||w(u),n(u)},f.onopen=u=>{g==null||g(u),i(f)}})}async function ne(e){const{retries:i=1}=e;let n=null;for(let t=0;(n==null?void 0:n.readyState)!==WebSocket.OPEN;t++)try{n=await te(e)}catch(a){if(t===i)throw a;await ee(t*500)}return n}async function U(e,i,n){const t=n?[n]:[],a=await ne({auth:e,host:i,callbacks:{onMessage:r=>{const l=JSON.parse(r.data);t.forEach(g=>g(l.event,l))}}});return{socket:a,terminate:()=>a.close(),subscribeToEvents:r=>t.push(r)}}var F=(e=>(e.Amazon="amazon",e.Microsoft="microsoft",e.Afflorithmics="afflorithmics",e.Elevenlabs="elevenlabs",e))(F||{}),q=(e=>(e.Public="public",e.Premium="premium",e.Private="private",e))(q||{}),_=(e=>(e.Start="START",e.Stop="STOP",e))(_||{}),R=(e=>(e.ChatAnswer="chat/answer",e.ChatPartial="chat/partial",e.StreamDone="stream/done",e.StreamStarted="stream/started",e.StreamFailed="stream/error",e))(R||{}),N=(e=>(e.Unrated="Unrated",e.Positive="Positive",e.Negative="Negative",e))(N||{}),z=(e=>(e.Functional="Functional",e.TextOnly="TextOnly",e.Maintenance="Maintenance",e))(z||{}),P=(e=>(e.Embed="embed",e.Query="query",e.Partial="partial",e.Answer="answer",e.Complete="done",e))(P||{}),J=(e=>(e.KnowledgeProcessing="knowledge/processing",e.KnowledgeIndexing="knowledge/indexing",e.KnowledgeFailed="knowledge/error",e.KnowledgeDone="knowledge/done",e))(J||{}),D=(e=>(e.Knowledge="knowledge",e.Document="document",e.Record="record",e))(D||{}),V=(e=>(e.Pdf="pdf",e.Text="text",e.Html="html",e.Word="word",e.Json="json",e.Markdown="markdown",e.Csv="csv",e.Excel="excel",e.Powerpoint="powerpoint",e.Archive="archive",e.Image="image",e.Audio="audio",e.Video="video",e))(V||{}),I=(e=>(e.Clip="clip",e.Talk="talk",e))(I||{});function ae(e){return e.presenter.type===I.Clip?{videoType:I.Clip,driver_id:e.presenter.driver_id,presenter_id:e.presenter.presenter_id}:{videoType:I.Talk,source_url:e.presenter.source_url}}function G(e,i,n,t){return new Promise(async(a,r)=>{const l=await X(ae(e),{...i,callbacks:{...i.callbacks,onConnectionStateChange:async g=>{var m,w;if(g==="connected")try{t||(t=await n.newChat(e.id)),a({chat:t,streamingManager:l})}catch(f){console.error(f),r(new Error("Cannot create new chat"))}else g==="failed"&&r(new Error("Cannot create connection"));(w=(m=i.callbacks).onConnectionStateChange)==null||w.call(m,g)},onMessage:(g,m)=>{var w,f;g===R.ChatAnswer&&(console.log("ChatAnswer",g,m),(f=(w=i.callbacks).onChatEvents)==null||f.call(w,P.Answer,{content:m,event:P.Answer}))}}})})}function re(e,i,n){return T(i,n||p).getById(e)}async function ie(e,i){var $,L;const n=i.baseURL||p,t=i.wsURL||j,a=new AbortController,r=T(i.auth,n),l=H(i.auth,n),g=B(i.auth,n),m=await r.getById(e);(L=($=i.callbacks)==null?void 0:$.onAgentReady)==null||L.call($,m);const w=await U(i.auth,t,i.callbacks.onChatEvents);let{chat:f,streamingManager:u}=await G(m,i,r);return{agent:m,chatId:f.id,async reconnectToChat(){const{streamingManager:s}=await G(m,i,r,f);u=s},terminate(){return a.abort(),w.terminate(),u.terminate()},chat(s){return r.chat(e,f.id,{sessionId:u.sessionId,streamId:u.streamId,messages:s},{signal:a.signal})},rate(s,c){return c?l.update(c,s):l.create(s)},deleteRate(s){return l.delete(s)},speak(s){function c(){if(s.type==="text")return{type:"text",provider:s.provider,input:s.input,ssml:s.ssml||!1};if(s.type==="audio")return{type:"audio",audio_url:s.audio_url};throw new Error("Invalid payload")}return u.speak({script:c()})},async getStarterMessages(){var s;return(s=m.knowledge)!=null&&s.id?g.getKnowledge(m.knowledge.id).then(c=>(c==null?void 0:c.starter_message)||[]):[]}}}function se(e,i){const n=k(e,i);return{createStream(t){return n.post("/clips/streams",{driver_id:t.driver_id,presenter_id:t.presenter_id,compatibility_mode:t.compatibility_mode})},startConnection(t,a,r){return n.post(`/clips/streams/${t}/sdp`,{session_id:r,answer:a})},addIceCandidate(t,a,r){return n.post(`/clips/streams/${t}/ice`,{session_id:r,...a})},sendStreamRequest(t,a,r){return n.post(`/clips/streams/${t}`,{session_id:a,...r})},close(t,a){return n.delete(`/clips/streams/${t}`,{session_id:a})}}}function ce(e,i){const n=k(e,i);return{createStream(t,a){return n.post("/talks/streams",{source_url:t.source_url,driver_url:t.driver_url,face:t.face,config:t.config},a)},startConnection(t,a,r,l){return n.post(`/talks/streams/${t}/sdp`,{session_id:r,answer:a},l)},addIceCandidate(t,a,r,l){return n.post(`/talks/streams/${t}/ice`,{session_id:r,...a},l)},sendStreamRequest(t,a,r,l){return n.post(`/talks/streams/${t}`,{session_id:a,...r},l)},close(t,a,r){return n.delete(`/talks/streams/${t}`,{session_id:a},r)}}}function oe(e,i){return e.map((n,t)=>t===0?i?{index:t,timestamp:n.timestamp,bytesReceived:n.bytesReceived-i.bytesReceived,packetsReceived:n.packetsReceived-i.packetsReceived,packetsLost:n.packetsLost-i.packetsLost,jitter:n.jitter,frameWidth:n.frameWidth,frameHeight:n.frameHeight,frameRate:n.frameRate}:{index:t,timestamp:n.timestamp,bytesReceived:n.bytesReceived,packetsReceived:n.packetsReceived,packetsLost:n.packetsLost,jitter:n.jitter,frameWidth:n.frameWidth,frameHeight:n.frameHeight,frameRate:n.frameRate}:{index:t,timestamp:n.timestamp,bytesReceived:n.bytesReceived-e[t-1].bytesReceived,packetsReceived:n.packetsReceived-e[t-1].packetsReceived,packetsLost:n.packetsLost-e[t-1].packetsLost,jitter:n.jitter,frameWidth:n.frameWidth,frameHeight:n.frameHeight,frameRate:n.frameRate})}let Q=!1;const y=(e,i)=>Q&&console.log(e,i),de=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function X(e,{debug:i=!1,callbacks:n,auth:t,baseURL:a=p}){Q=i;const r={...n},{startConnection:l,sendStreamRequest:g,close:m,createStream:w,addIceCandidate:f}=e.videoType===I.Clip?se(t,a):ce(t,a),{id:u,offer:$,ice_servers:L,session_id:s}=await w(e),c=new de({iceServers:L}),Y=c.createDataChannel("JanusDataChannel");let S=[],b=0,K=0,A,Z,x;if(!s)throw new Error("Could not create session_id");(()=>{x=setInterval(()=>{c.getStats().then(h=>{h.forEach(v=>{var C;if(v.type==="inbound-rtp"&&v.kind==="video"){if(K=S.length-1,v&&S[K]){const M=v.bytesReceived,ue=S[K].bytesReceived;let ge=A;A=M-ue>0;let E;if(ge!==A){if(A)b=S.length;else{const me=S.slice(b),fe=b===0?void 0:S[b-1];E=oe(me,fe),E=E.sort((we,he)=>he.packetsLost-we.packetsLost).slice(0,5)}(C=r.onVideoStateChange)==null||C.call(r,A?_.Start:_.Stop,E)}}S.push(v)}})})},500)})();const le=()=>{clearInterval(Z)};c.onicecandidate=o=>{y("peerConnection.onicecandidate",o),o.candidate&&o.candidate.sdpMid&&o.candidate.sdpMLineIndex!==null&&f(u,{candidate:o.candidate.candidate,sdpMid:o.candidate.sdpMid,sdpMLineIndex:o.candidate.sdpMLineIndex},s)},c.oniceconnectionstatechange=()=>{var o;y("peerConnection.oniceconnectionstatechange => "+c.iceConnectionState),(o=r.onConnectionStateChange)==null||o.call(r,c.iceConnectionState)},c.ontrack=o=>{var h;y("peerConnection.ontrack",o),(h=r.onSrcObjectReady)==null||h.call(r,o.streams[0])},Y.onmessage=o=>{var h,v;if(Y.readyState==="open"){const[C,M]=o.data.split(":");C===R.StreamStarted?console.log("StreamStarted",C,M):C===R.StreamDone?console.log("StreamDone"):C===R.StreamFailed?((h=r.onVideoStateChange)==null||h.call(r,_.Stop,{event:C,data:M}),S=[],b=0,K=0,A=!1,console.log("StreamFailed")):(v=r.onMessage)==null||v.call(r,C,decodeURIComponent(M))}},await c.setRemoteDescription($),y("set remote description OK");const O=await c.createAnswer();return y("create answer OK"),await c.setLocalDescription(O),y("set local description OK"),await l(u,O,s),y("start connection OK"),{speak(o){return g(u,s,o)},async terminate(){var o,h;u&&(c&&(c.close(),c.oniceconnectionstatechange=null,c.onnegotiationneeded=null,c.onicecandidate=null,c.ontrack=null,clearInterval(Z)),await m(u,s).catch(v=>{}),(o=r.onConnectionStateChange)==null||o.call(r,"closed"),(h=r.onVideoStateChange)==null||h.call(r,_.Stop),le(),clearInterval(x))},sessionId:s,streamId:u,onCallback(o,h){r[o]=h}}}d.ChatMode=z,d.ChatProgress=P,d.DocumentType=V,d.KnowledgeType=D,d.Providers=F,d.RateState=N,d.SocketManager=U,d.StreamEvents=R,d.Subject=J,d.VoiceAccess=q,d.createAgentManager=ie,d.createAgentsApi=T,d.createClient=k,d.createKnowledgeApi=B,d.createRatingsApi=H,d.createStreamingManager=X,d.getAgent=re,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
1
+ (function(d,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(d=typeof globalThis<"u"?globalThis:d||self,p(d.index={}))})(this,function(d){"use strict";const p="https://api.d-id.com",j="wss://notifications.d-id.com";function ee(){let e=window.localStorage.getItem("external_key_d_id");return e||(e=Math.random().toString(16).slice(2),window.localStorage.setItem("external_key_d_id",e)),e}function W(e){if(e.type==="bearer")return`Bearer ${e.token}`;if(e.type==="basic")return`Basic ${btoa(`${e.username}:${e.password}`)}`;if(e.type==="key")return`Client-Key ${e.clientKey}.${ee()}`;throw new Error(`Unknown auth type: ${e}`)}function k(e,i=p){const n=async(t,a)=>{const r=await fetch(i+(t!=null&&t.startsWith("/")?t:`/${t}`),{...a,headers:{...a==null?void 0:a.headers,Authorization:W(e),"Content-Type":"application/json"}});if(!r.ok){let l=await r.text().catch(()=>"Failed to fetch");throw new Error(l)}return r.json()};return{get(t,a){return n(t,{...a,method:"GET"})},post(t,a,r){return n(t,{...r,body:JSON.stringify(a),method:"POST"})},delete(t,a,r){return n(t,{...r,body:JSON.stringify(a),method:"DELETE"})},patch(t,a,r){return n(t,{...r,body:JSON.stringify(a),method:"PATCH"})}}}function T(e,i=p){const n=k(e,`${i}/agents`);return{create(t,a){return n.post("/",t,a)},getAgents(t,a){return n.get(`/${t?`?tag=${t}`:""}`,a).then(r=>r??[])},getById(t,a){return n.get(`/${t}`,a)},delete(t,a){return n.delete(`/${t}`,void 0,a)},update(t,a,r){return n.patch(`/${t}`,a,r)},newChat(t,a){return n.post(`/${t}/chat`,void 0,a)},chat(t,a,r,l){return n.post(`/${t}/chat/${a}`,r,l)}}}function B(e,i=p){const n=k(e,`${i}/knowledge`);return{createKnowledge(t,a){return n.post("/",t,a)},getKnowledgeBase(t){return n.get("/",t)},getKnowledge(t,a){return n.get(`/${t}`,a)},deleteKnowledge(t,a){return n.delete(`/${t}`,void 0,a)},createDocument(t,a,r){return n.post(`/${t}/documents`,a,r)},deleteDocument(t,a,r){return n.delete(`/${t}/documents/${a}`,void 0,r)},getDocuments(t,a){return n.get(`/${t}/documents`,a)},getDocument(t,a,r){return n.get(`/${t}/documents/${a}`,r)},getRecords(t,a,r){return n.get(`/${t}/documents/${a}/records`,r)},query(t,a,r){return n.post(`/${t}/query`,{query:a},r)}}}function H(e,i=p){const n=k(e,`${i}/chats/ratings`);return{create(t,a){return n.post("/",t,a)},getByKnowledge(t,a){return n.get(`/${t}`,a).then(r=>r??[])},update(t,a,r){return n.patch(`/${t}`,a,r)},delete(t,a){return n.delete(`/${t}`,a)}}}const te=e=>new Promise(i=>setTimeout(i,e));function ne(e){return new Promise((i,n)=>{const{callbacks:t,host:a,auth:r}=e,{onMessage:l=null,onOpen:g=null,onClose:m=null,onError:w=null}=t||{},f=new WebSocket(`${a}?authorization=${W(r)}`);f.onmessage=l,f.onclose=m,f.onerror=u=>{console.error(u),w==null||w(u),n(u)},f.onopen=u=>{g==null||g(u),i(f)}})}async function ae(e){const{retries:i=1}=e;let n=null;for(let t=0;(n==null?void 0:n.readyState)!==WebSocket.OPEN;t++)try{n=await ne(e)}catch(a){if(t===i)throw a;await te(t*500)}return n}async function U(e,i,n){const t=n?[n]:[],a=await ae({auth:e,host:i,callbacks:{onMessage:r=>{const l=JSON.parse(r.data);t.forEach(g=>g(l.event,l))}}});return{socket:a,terminate:()=>a.close(),subscribeToEvents:r=>t.push(r)}}var F=(e=>(e.Amazon="amazon",e.Microsoft="microsoft",e.Afflorithmics="afflorithmics",e.Elevenlabs="elevenlabs",e))(F||{}),q=(e=>(e.Public="public",e.Premium="premium",e.Private="private",e))(q||{}),_=(e=>(e.Start="START",e.Stop="STOP",e))(_||{}),R=(e=>(e.ChatAnswer="chat/answer",e.ChatPartial="chat/partial",e.StreamDone="stream/done",e.StreamStarted="stream/started",e.StreamFailed="stream/error",e))(R||{}),N=(e=>(e.Unrated="Unrated",e.Positive="Positive",e.Negative="Negative",e))(N||{}),z=(e=>(e.Functional="Functional",e.TextOnly="TextOnly",e.Maintenance="Maintenance",e))(z||{}),P=(e=>(e.Embed="embed",e.Query="query",e.Partial="partial",e.Answer="answer",e.Complete="done",e))(P||{}),J=(e=>(e.KnowledgeProcessing="knowledge/processing",e.KnowledgeIndexing="knowledge/indexing",e.KnowledgeFailed="knowledge/error",e.KnowledgeDone="knowledge/done",e))(J||{}),D=(e=>(e.Knowledge="knowledge",e.Document="document",e.Record="record",e))(D||{}),V=(e=>(e.Pdf="pdf",e.Text="text",e.Html="html",e.Word="word",e.Json="json",e.Markdown="markdown",e.Csv="csv",e.Excel="excel",e.Powerpoint="powerpoint",e.Archive="archive",e.Image="image",e.Audio="audio",e.Video="video",e))(V||{}),I=(e=>(e.Clip="clip",e.Talk="talk",e))(I||{});function re(e){return e.presenter.type===I.Clip?{videoType:I.Clip,driver_id:e.presenter.driver_id,presenter_id:e.presenter.presenter_id}:{videoType:I.Talk,source_url:e.presenter.source_url}}function G(e,i,n,t){return new Promise(async(a,r)=>{const l=await x(re(e),{...i,callbacks:{...i.callbacks,onConnectionStateChange:async g=>{var m,w;if(g==="connected")try{t||(t=await n.newChat(e.id)),a({chat:t,streamingManager:l})}catch(f){console.error(f),r(new Error("Cannot create new chat"))}else g==="failed"&&r(new Error("Cannot create connection"));(w=(m=i.callbacks).onConnectionStateChange)==null||w.call(m,g)},onMessage:(g,m)=>{var w,f;g===R.ChatAnswer&&(console.log("ChatAnswer",g,m),(f=(w=i.callbacks).onChatEvents)==null||f.call(w,P.Answer,{content:m,event:P.Answer}))}}})})}function ie(e,i,n){return T(i,n||p).getById(e)}async function se(e,i){var $,L;const n=i.baseURL||p,t=i.wsURL||j,a=new AbortController,r=T(i.auth,n),l=H(i.auth,n),g=B(i.auth,n),m=await r.getById(e);(L=($=i.callbacks)==null?void 0:$.onAgentReady)==null||L.call($,m);const w=await U(i.auth,t,i.callbacks.onChatEvents);let{chat:f,streamingManager:u}=await G(m,i,r);return{agent:m,chatId:f.id,async reconnectToChat(){const{streamingManager:s}=await G(m,i,r,f);u=s},terminate(){return a.abort(),w.terminate(),u.terminate()},chat(s){return r.chat(e,f.id,{sessionId:u.sessionId,streamId:u.streamId,messages:s},{signal:a.signal})},rate(s,o){return o?l.update(o,s):l.create(s)},deleteRate(s){return l.delete(s)},speak(s){function o(){if(s.type==="text")return{type:"text",provider:s.provider,input:s.input,ssml:s.ssml||!1};if(s.type==="audio")return{type:"audio",audio_url:s.audio_url};throw new Error("Invalid payload")}return u.speak({script:o()})},async getStarterMessages(){var s;return(s=m.knowledge)!=null&&s.id?g.getKnowledge(m.knowledge.id).then(o=>(o==null?void 0:o.starter_message)||[]):[]}}}function oe(e,i){const n=k(e,i);return{createStream(t){return n.post("/clips/streams",{driver_id:t.driver_id,presenter_id:t.presenter_id,compatibility_mode:t.compatibility_mode})},startConnection(t,a,r){return n.post(`/clips/streams/${t}/sdp`,{session_id:r,answer:a})},addIceCandidate(t,a,r){return n.post(`/clips/streams/${t}/ice`,{session_id:r,...a})},sendStreamRequest(t,a,r){return n.post(`/clips/streams/${t}`,{session_id:a,...r})},close(t,a){return n.delete(`/clips/streams/${t}`,{session_id:a})}}}function ce(e,i){const n=k(e,i);return{createStream(t,a){return n.post("/talks/streams",{source_url:t.source_url,driver_url:t.driver_url,face:t.face,config:t.config},a)},startConnection(t,a,r,l){return n.post(`/talks/streams/${t}/sdp`,{session_id:r,answer:a},l)},addIceCandidate(t,a,r,l){return n.post(`/talks/streams/${t}/ice`,{session_id:r,...a},l)},sendStreamRequest(t,a,r,l){return n.post(`/talks/streams/${t}`,{session_id:a,...r},l)},close(t,a,r){return n.delete(`/talks/streams/${t}`,{session_id:a},r)}}}function de(e,i){return e.map((n,t)=>t===0?i?{index:t,timestamp:n.timestamp,bytesReceived:n.bytesReceived-i.bytesReceived,packetsReceived:n.packetsReceived-i.packetsReceived,packetsLost:n.packetsLost-i.packetsLost,jitter:n.jitter,frameWidth:n.frameWidth,frameHeight:n.frameHeight,frameRate:n.frameRate}:{index:t,timestamp:n.timestamp,bytesReceived:n.bytesReceived,packetsReceived:n.packetsReceived,packetsLost:n.packetsLost,jitter:n.jitter,frameWidth:n.frameWidth,frameHeight:n.frameHeight,frameRate:n.frameRate}:{index:t,timestamp:n.timestamp,bytesReceived:n.bytesReceived-e[t-1].bytesReceived,packetsReceived:n.packetsReceived-e[t-1].packetsReceived,packetsLost:n.packetsLost-e[t-1].packetsLost,jitter:n.jitter,frameWidth:n.frameWidth,frameHeight:n.frameHeight,frameRate:n.frameRate})}let Q=!1;const y=(e,i)=>Q&&console.log(e,i),le=(window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection).bind(window);async function x(e,{debug:i=!1,callbacks:n,auth:t,baseURL:a=p}){Q=i;const r={...n},{startConnection:l,sendStreamRequest:g,close:m,createStream:w,addIceCandidate:f}=e.videoType===I.Clip?oe(t,a):ce(t,a),{id:u,offer:$,ice_servers:L,session_id:s}=await w(e),o=new le({iceServers:L}),X=o.createDataChannel("JanusDataChannel");let C=[],M=0,K=0,A,Y,Z;if(!s)throw new Error("Could not create session_id");(()=>{Z=setInterval(()=>{o.getStats().then(h=>{h.forEach(v=>{var S;if(v.type==="inbound-rtp"&&v.kind==="video"){if(K=C.length-1,v&&C[K]){const b=v.bytesReceived,ge=C[K].bytesReceived;let me=A;A=b-ge>0;let E;if(me!==A){if(A)M=C.length;else{const fe=C.slice(M),we=M===0?void 0:C[M-1];E=de(fe,we),E=E.sort((he,pe)=>pe.packetsLost-he.packetsLost).slice(0,5)}(S=r.onVideoStateChange)==null||S.call(r,A?_.Start:_.Stop,E)}}C.push(v)}})})},500)})();const ue=()=>{clearInterval(Y)};o.onicecandidate=c=>{y("peerConnection.onicecandidate",c),c.candidate&&c.candidate.sdpMid&&c.candidate.sdpMLineIndex!==null&&f(u,{candidate:c.candidate.candidate,sdpMid:c.candidate.sdpMid,sdpMLineIndex:c.candidate.sdpMLineIndex},s)},o.oniceconnectionstatechange=()=>{var c;y("peerConnection.oniceconnectionstatechange => "+o.iceConnectionState),(c=r.onConnectionStateChange)==null||c.call(r,o.iceConnectionState)},o.ontrack=c=>{var h;y("peerConnection.ontrack",c),(h=r.onSrcObjectReady)==null||h.call(r,c.streams[0])},X.onmessage=c=>{var h,v;if(X.readyState==="open"){const[S,b]=c.data.split(":");S===R.StreamStarted?console.log("StreamStarted",S,b):S===R.StreamDone?console.log("StreamDone"):S===R.StreamFailed?((h=r.onVideoStateChange)==null||h.call(r,_.Stop,{event:S,data:b}),C=[],M=0,K=0,A=!1,console.log("StreamFailed")):(v=r.onMessage)==null||v.call(r,S,decodeURIComponent(b))}},await o.setRemoteDescription($),y("set remote description OK");const O=await o.createAnswer();return y("create answer OK"),await o.setLocalDescription(O),y("set local description OK"),await l(u,O,s),y("start connection OK"),{speak(c){return g(u,s,c)},async terminate(){var c,h;u&&(o&&(o.close(),o.oniceconnectionstatechange=null,o.onnegotiationneeded=null,o.onicecandidate=null,o.ontrack=null,clearInterval(Y)),await m(u,s).catch(v=>{}),(c=r.onConnectionStateChange)==null||c.call(r,"closed"),(h=r.onVideoStateChange)==null||h.call(r,_.Stop),ue(),clearInterval(Z))},sessionId:s,streamId:u,onCallback(c,h){r[c]=h}}}d.ChatMode=z,d.ChatProgress=P,d.DocumentType=V,d.KnowledgeType=D,d.Providers=F,d.RateState=N,d.SocketManager=U,d.StreamEvents=R,d.Subject=J,d.VoiceAccess=q,d.createAgentManager=se,d.createAgentsApi=T,d.createClient=k,d.createKnowledgeApi=B,d.createRatingsApi=H,d.createStreamingManager=x,d.getAgent=ie,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
@@ -1,4 +1,4 @@
1
- import { Agent, AgentPayload, Auth, Chat, ChatPayload, ChatResponse } from '../../types/index';
1
+ import { Agent, AgentPayload, Auth, Chat, ChatPayload, ChatResponse } from '../types/index';
2
2
  export declare function createAgentsApi(auth: Auth, host?: string): {
3
3
  create(payload: AgentPayload, options?: RequestInit): Promise<Agent>;
4
4
  getAgents(tag?: string, options?: RequestInit): Promise<Agent[]>;
@@ -1,2 +1,2 @@
1
- import { Auth, RtcApi } from '../../types/index';
1
+ import { Auth, RtcApi } from '../types/index';
2
2
  export declare function createApi(auth: Auth, host: string): RtcApi;
@@ -1,4 +1,4 @@
1
- import { Auth } from '../../types/auth';
1
+ import { Auth } from '../types/auth';
2
2
  export declare function createClient(auth: Auth, host?: string): {
3
3
  get<T = any>(url: string, options?: RequestInit): Promise<T>;
4
4
  post<T_1 = any>(url: string, body?: any, options?: RequestInit): Promise<T_1>;
@@ -1,4 +1,4 @@
1
- import { Auth, CreateDocumentPayload, DocumentData, KnowledgeData, KnowledgePayload, QueryResult, RecordData } from '../../types/index';
1
+ import { Auth, CreateDocumentPayload, DocumentData, KnowledgeData, KnowledgePayload, QueryResult, RecordData } from '../types/index';
2
2
  export declare function createKnowledgeApi(auth: Auth, host?: string): {
3
3
  createKnowledge(payload: KnowledgePayload, options?: RequestInit): Promise<KnowledgeData>;
4
4
  getKnowledgeBase(options?: RequestInit): Promise<KnowledgeData[]>;
@@ -1,4 +1,4 @@
1
- import { Auth, RatingEntity, RatingPayload } from '../../index';
1
+ import { Auth, RatingEntity, RatingPayload } from '../index';
2
2
  export declare function createRatingsApi(auth: Auth, host?: string): {
3
3
  create(payload: RatingPayload, options?: RequestInit): Promise<RatingEntity>;
4
4
  getByKnowledge(knowledgeId?: string, options?: RequestInit): Promise<RatingEntity[]>;
@@ -1,2 +1,2 @@
1
- import { Auth, RtcApi } from '../../types/index';
1
+ import { Auth, RtcApi } from '../types/index';
2
2
  export declare function createApi(auth: Auth, host: string): RtcApi;
@@ -1,2 +1,2 @@
1
- import { Auth } from '../../types/auth';
1
+ import { Auth } from '../types/auth';
2
2
  export declare function getAuthHeader(auth: Auth): string;
@@ -1,5 +1,5 @@
1
- import { Auth } from '../types/auth';
2
- import { ChatProgressCallback } from '..';
1
+ import { Auth } from './types/auth';
2
+ import { ChatProgressCallback } from '.';
3
3
  interface SocketManager {
4
4
  socket?: WebSocket;
5
5
  terminate: () => void;
@@ -1,5 +1,5 @@
1
- import { Agent, AgentManager, AgentManagerOptions } from '../types/index';
2
- import { Auth } from '..';
1
+ import { Agent, AgentManager, AgentManagerOptions } from './types/index';
2
+ import { Auth } from '.';
3
3
  export declare function getAgent(agentId: string, auth: Auth, baseURL?: string): Promise<Agent>;
4
4
  /**
5
5
  * Creates a new Agent Manager instance for interacting with an agent, chat, and related connections.
@@ -1,10 +1,10 @@
1
- import { CreateStreamOptions, ManagerCallbacks, PayloadType, StreamingManagerOptions } from '../types/index';
1
+ import { CreateStreamOptions, ManagerCallbacks, PayloadType, StreamingManagerOptions } from './types/index';
2
2
  export declare function createStreamingManager<T extends CreateStreamOptions>(agent: T, { debug, callbacks, auth, baseURL }: StreamingManagerOptions): Promise<{
3
3
  /**
4
4
  * Method to send request to server to get clip or talk depend on you payload
5
5
  * @param payload
6
6
  */
7
- speak(payload: PayloadType<T>): Promise<import('../types/index').SendStreamPayloadResponse>;
7
+ speak(payload: PayloadType<T>): Promise<import('./types/index').SendStreamPayloadResponse>;
8
8
  /**
9
9
  * Method to close RTC connection
10
10
  */
@@ -4,4 +4,3 @@ export declare const didSocketApiUrl: string;
4
4
  export declare const mixpanelKey: string;
5
5
  export declare const clientKey: string;
6
6
  export declare const agentId: string;
7
- export declare const externalId = "temp";
@@ -1,8 +1,8 @@
1
- export * from './lib/api/agents';
2
- export * from './lib/api/getClient';
3
- export * from './lib/api/knowledge';
4
- export * from './lib/api/ratings';
5
- export * from './lib/connectToSocket';
6
- export * from './lib/createAgentManager';
7
- export * from './lib/createStreamingManager';
1
+ export * from './api/agents';
2
+ export * from './api/getClient';
3
+ export * from './api/knowledge';
4
+ export * from './api/ratings';
5
+ export * from './connectToSocket';
6
+ export * from './createAgentManager';
7
+ export * from './createStreamingManager';
8
8
  export * from './types/index';
@@ -10,7 +10,6 @@ export interface BasicAuth {
10
10
  export interface ClientKeyAuth {
11
11
  type: 'key';
12
12
  clientKey: string;
13
- externalId: string;
14
13
  }
15
14
  export type Auth = BearerToken | BasicAuth | ClientKeyAuth;
16
15
  export interface GetAuthParams {
@@ -18,5 +17,4 @@ export interface GetAuthParams {
18
17
  username?: string | null;
19
18
  password?: string | null;
20
19
  clientKey?: string | null;
21
- externalId?: string | null;
22
20
  }
@@ -1,4 +1,4 @@
1
- import { SupportedStreamScipt } from '../../../types/StreamScript';
1
+ import { SupportedStreamScipt } from '../../StreamScript';
2
2
  import { Auth } from '../../auth';
3
3
  import { SendStreamPayloadResponse, StreamingState } from '../../stream';
4
4
  import { Agent } from './agent';
@@ -1,2 +1,2 @@
1
- import { SlimRTCStatsReport } from "../../types";
1
+ import { SlimRTCStatsReport } from "../types";
2
2
  export declare function createVideoStatsReport(stats: SlimRTCStatsReport[], previousStats?: SlimRTCStatsReport): SlimRTCStatsReport[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@d-id/client-sdk",
3
3
  "private": false,
4
- "version": "1.0.19-beta.36",
4
+ "version": "1.0.19-beta.37",
5
5
  "type": "module",
6
6
  "description": "d-id client sdk",
7
7
  "repository": {
@@ -25,7 +25,7 @@
25
25
  "dev": "vite",
26
26
  "build": "node ./infra/build.js -m production",
27
27
  "build:dev": "node ./infra/build.js -m development",
28
- "deploy:prod": "node ./infra/deploy.js --version patch",
28
+ "deploy:prod": "node ./infra/deploy.js --version beta",
29
29
  "preview": "vite preview",
30
30
  "test-build": "node .infra/build.js -m development",
31
31
  "build:docs": "typedoc"
@@ -40,9 +40,9 @@
40
40
  "prettier-plugin-organize-imports": "^3.2.4",
41
41
  "serverless": "3.32.2",
42
42
  "typedoc": "^0.25.7",
43
- "typescript": "^5.3.2",
44
- "vite": "^4.4.5",
45
- "vite-plugin-dts": "^3.6.0",
43
+ "typescript": "^5.3.3",
44
+ "vite": "^5.1.4",
45
+ "vite-plugin-dts": "^3.7.3",
46
46
  "vite-plugin-html-env": "^1.2.8"
47
47
  }
48
- }
48
+ }