@d-id/client-sdk 1.1.0-beta.22 → 1.1.0-beta.24

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,6 +1,6 @@
1
- var ye = Object.defineProperty;
2
- var ve = (e, t, a) => t in e ? ye(e, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[t] = a;
3
- var X = (e, t, a) => (ve(e, typeof t != "symbol" ? t + "" : t, a), a);
1
+ var ve = Object.defineProperty;
2
+ var ke = (e, t, a) => t in e ? ve(e, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[t] = a;
3
+ var Y = (e, t, a) => (ke(e, typeof t != "symbol" ? t + "" : t, a), a);
4
4
  class Z extends Error {
5
5
  constructor({
6
6
  kind: a,
@@ -11,13 +11,13 @@ class Z extends Error {
11
11
  kind: a,
12
12
  description: n
13
13
  }));
14
- X(this, "kind");
15
- X(this, "description");
16
- X(this, "error");
14
+ Y(this, "kind");
15
+ Y(this, "description");
16
+ Y(this, "error");
17
17
  this.kind = a, this.description = n, this.error = s;
18
18
  }
19
19
  }
20
- class ke extends Z {
20
+ class De extends Z {
21
21
  constructor(t, a) {
22
22
  super({
23
23
  kind: "ChatCreationFailed",
@@ -25,7 +25,7 @@ class ke extends Z {
25
25
  });
26
26
  }
27
27
  }
28
- class De extends Z {
28
+ class Ce extends Z {
29
29
  constructor(t) {
30
30
  super({
31
31
  kind: "ChatModeDowngraded",
@@ -33,13 +33,13 @@ class De extends Z {
33
33
  });
34
34
  }
35
35
  }
36
- class K extends Z {
36
+ class H extends Z {
37
37
  constructor(a, n) {
38
38
  super({
39
39
  kind: "ValidationError",
40
40
  description: a
41
41
  });
42
- X(this, "key");
42
+ Y(this, "key");
43
43
  this.key = n;
44
44
  }
45
45
  }
@@ -51,7 +51,7 @@ class Re extends Z {
51
51
  });
52
52
  }
53
53
  }
54
- var Ce = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Ce || {}), _e = /* @__PURE__ */ ((e) => (e.TRIAL = "deid-trial", e.PRO = "deid-pro", e.ENTERPRISE = "deid-enterprise", e.LITE = "deid-lite", e.ADVANCED = "deid-advanced", e.BUILD = "deid-api-build", e.LAUNCH = "deid-api-launch", e.SCALE = "deid-api-scale", e))(_e || {}), Se = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Se || {}), Ie = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Ie || {}), A = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e))(A || {}), H = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(H || {}), Ee = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Ee || {}), Me = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Me || {}), Te = /* @__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))(Te || {}), ce = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(ce || {});
54
+ var _e = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(_e || {}), Se = /* @__PURE__ */ ((e) => (e.TRIAL = "deid-trial", e.PRO = "deid-pro", e.ENTERPRISE = "deid-enterprise", e.LITE = "deid-lite", e.ADVANCED = "deid-advanced", e.BUILD = "deid-api-build", e.LAUNCH = "deid-api-launch", e.SCALE = "deid-api-scale", e))(Se || {}), Ee = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ee || {}), Ie = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Ie || {}), A = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(A || {}), q = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(q || {}), Me = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Me || {}), Te = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Te || {}), je = /* @__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))(je || {}), ce = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(ce || {});
55
55
  const be = (e) => {
56
56
  switch (e) {
57
57
  case "clip":
@@ -62,12 +62,12 @@ const be = (e) => {
62
62
  throw new Error(`Unknown video type: ${e}`);
63
63
  }
64
64
  };
65
- var p = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(p || {}), Y = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(Y || {}), V = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(V || {}), F = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", 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))(F || {}), j = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(j || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}), je = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(je || {}), Pe = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Pe || {});
66
- const Ae = 45 * 1e3, Be = "X-Playground-Chat", Q = "https://api.d-id.com", $e = "wss://notifications.d-id.com", Le = "79f81a83a67430be2bc0fd61042b8faa", de = (e) => new Promise((t) => setTimeout(t, e)), q = (e = 16) => {
65
+ var p = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(p || {}), Q = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(Q || {}), X = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(X || {}), J = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", 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 || {}), j = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(j || {}), U = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(U || {}), Pe = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(Pe || {}), Ae = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Ae || {});
66
+ const $e = 45 * 1e3, Be = "X-Playground-Chat", O = "https://api.d-id.com", Le = "wss://notifications.d-id.com", ze = "79f81a83a67430be2bc0fd61042b8faa", de = (e) => new Promise((t) => setTimeout(t, e)), V = (e = 16) => {
67
67
  const t = new Uint8Array(e);
68
68
  return window.crypto.getRandomValues(t), Array.from(t, (a) => a.toString(16).padStart(2, "0")).join("").slice(0, 13);
69
- }, ze = (e) => [A.TextOnly, A.Playground, A.Maintenance].includes(e);
70
- function Ne(e, t) {
69
+ }, Ne = (e) => [A.TextOnly, A.Playground, A.Maintenance].includes(e), le = (e) => e && [A.DirectPlayback, A.Off].includes(e);
70
+ function xe(e, t) {
71
71
  let a;
72
72
  return {
73
73
  promise: new Promise((s, i) => {
@@ -76,7 +76,7 @@ function Ne(e, t) {
76
76
  clear: () => clearTimeout(a)
77
77
  };
78
78
  }
79
- async function ee(e, t) {
79
+ async function te(e, t) {
80
80
  const a = {
81
81
  limit: (t == null ? void 0 : t.limit) ?? 3,
82
82
  delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
@@ -94,7 +94,7 @@ async function ee(e, t) {
94
94
  const {
95
95
  promise: i,
96
96
  clear: o
97
- } = Ne(a.timeout, a.timeoutErrorMessage), c = e().finally(o);
97
+ } = xe(a.timeout, a.timeoutErrorMessage), c = e().finally(o);
98
98
  return await Promise.race([c, i]);
99
99
  } catch (i) {
100
100
  if (n = i, !a.shouldRetryFn(i) || s >= a.limit)
@@ -103,40 +103,40 @@ async function ee(e, t) {
103
103
  }
104
104
  throw n;
105
105
  }
106
- function le() {
106
+ function ue() {
107
107
  let e = window.localStorage.getItem("did_external_key_id");
108
108
  if (!e) {
109
- let t = q();
109
+ let t = V();
110
110
  window.localStorage.setItem("did_external_key_id", t), e = t;
111
111
  }
112
112
  return e;
113
113
  }
114
- let xe = q();
115
- function ue(e) {
114
+ let Fe = V();
115
+ function fe(e) {
116
116
  if (e.type === "bearer")
117
117
  return `Bearer ${e.token}`;
118
118
  if (e.type === "basic")
119
119
  return `Basic ${btoa(`${e.username}:${e.password}`)}`;
120
120
  if (e.type === "key")
121
- return `Client-Key ${e.clientKey}.${le()}_${xe}`;
121
+ return `Client-Key ${e.clientKey}.${ue()}_${Fe}`;
122
122
  throw new Error(`Unknown auth type: ${e}`);
123
123
  }
124
- const Fe = (e) => ee(e, {
124
+ const Je = (e) => te(e, {
125
125
  limit: 3,
126
126
  delayMs: 1e3,
127
127
  timeout: 0,
128
128
  shouldRetryFn: (t) => t.status === 429
129
129
  });
130
- function ne(e, t = Q, a) {
130
+ function ae(e, t = O, a) {
131
131
  const n = async (s, i) => {
132
132
  const {
133
133
  skipErrorHandler: o,
134
134
  ...c
135
- } = i || {}, r = await Fe(() => fetch(t + (s != null && s.startsWith("/") ? s : `/${s}`), {
135
+ } = i || {}, r = await Je(() => fetch(t + (s != null && s.startsWith("/") ? s : `/${s}`), {
136
136
  ...c,
137
137
  headers: {
138
138
  ...c.headers,
139
- Authorization: ue(e),
139
+ Authorization: fe(e),
140
140
  "Content-Type": "application/json"
141
141
  }
142
142
  }));
@@ -181,8 +181,8 @@ function ne(e, t = Q, a) {
181
181
  }
182
182
  };
183
183
  }
184
- function fe(e, t = Q, a) {
185
- const n = ne(e, `${t}/agents`, a);
184
+ function me(e, t = O, a) {
185
+ const n = ae(e, `${t}/agents`, a);
186
186
  return {
187
187
  create(s, i) {
188
188
  return n.post("/", s, i);
@@ -219,8 +219,8 @@ function fe(e, t = Q, a) {
219
219
  }
220
220
  };
221
221
  }
222
- const me = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type;
223
- function Je(e) {
222
+ const ge = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type;
223
+ function We(e) {
224
224
  var s, i, o, c;
225
225
  const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", a = () => {
226
226
  const r = navigator.platform;
@@ -231,15 +231,15 @@ function Je(e) {
231
231
  isMobile: `${t() == "Mobile"}`,
232
232
  browser: navigator.userAgent,
233
233
  origin: window.location.origin,
234
- agentType: me(n),
234
+ agentType: ge(n),
235
235
  agentVoice: {
236
236
  voiceId: (i = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : i.voice_id,
237
237
  provider: (c = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : c.type
238
238
  }
239
239
  };
240
240
  }
241
- const We = (e) => e.reduce((t, a) => t + a, 0), ie = (e) => We(e) / e.length;
242
- function Ue(e, t, a) {
241
+ const Ue = (e) => e.reduce((t, a) => t + a, 0), ie = (e) => Ue(e) / e.length;
242
+ function Ke(e, t, a) {
243
243
  var r, l, d;
244
244
  const {
245
245
  event: n,
@@ -267,14 +267,14 @@ function Ue(e, t, a) {
267
267
  };
268
268
  }
269
269
  let G = {};
270
- const Ke = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
271
- function He(e) {
270
+ const He = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
271
+ function qe(e) {
272
272
  var i, o, c, r, l, d;
273
273
  const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", a = e.agent.presenter, n = (i = e.agent.llm) == null ? void 0 : i.prompt_customization, s = {
274
274
  token: e.token || "testKey",
275
- distinct_id: e.distinctId || le(),
275
+ distinct_id: e.distinctId || ue(),
276
276
  agentId: e.agent.id,
277
- agentType: me(a),
277
+ agentType: ge(a),
278
278
  owner_id: e.agent.owner_id ?? "",
279
279
  promptVersion: (o = e.agent.llm) == null ? void 0 : o.prompt_version,
280
280
  behavior: {
@@ -292,20 +292,20 @@ function He(e) {
292
292
  ...s,
293
293
  additionalProperties: {},
294
294
  isEnabled: e.isEnabled ?? !0,
295
- getRandom: q,
295
+ getRandom: V,
296
296
  enrich(f) {
297
297
  this.additionalProperties = {
298
298
  ...this.additionalProperties,
299
299
  ...f
300
300
  };
301
301
  },
302
- async track(f, B) {
302
+ async track(f, $) {
303
303
  if (!this.isEnabled)
304
304
  return Promise.resolve();
305
305
  const {
306
- audioPath: M,
306
+ audioPath: I,
307
307
  ..._
308
- } = B || {}, k = {
308
+ } = $ || {}, D = {
309
309
  method: "POST",
310
310
  headers: {
311
311
  "Content-Type": "application/x-www-form-urlencoded"
@@ -329,32 +329,32 @@ function He(e) {
329
329
  })
330
330
  };
331
331
  try {
332
- return await fetch(Ke, k).then((D) => D.json());
333
- } catch (D) {
334
- return console.error(D);
332
+ return await fetch(He, D).then((v) => v.json());
333
+ } catch (v) {
334
+ return console.error(v);
335
335
  }
336
336
  },
337
- linkTrack(f, B, M, _) {
337
+ linkTrack(f, $, I, _) {
338
338
  G[f] || (G[f] = {
339
339
  events: {},
340
340
  resolvedDependencies: []
341
- }), _.includes(M) || _.push(M);
342
- const k = G[f];
343
- if (k.events[M] = {
344
- props: B
345
- }, k.resolvedDependencies.push(M), _.every((N) => k.resolvedDependencies.includes(N))) {
346
- const N = _.reduce((L, $) => k.events[$] ? {
341
+ }), _.includes(I) || _.push(I);
342
+ const D = G[f];
343
+ if (D.events[I] = {
344
+ props: $
345
+ }, D.resolvedDependencies.push(I), _.every((N) => D.resolvedDependencies.includes(N))) {
346
+ const N = _.reduce((L, b) => D.events[b] ? {
347
347
  ...L,
348
- ...k.events[$].props
348
+ ...D.events[b].props
349
349
  } : L, {});
350
- this.track(f, N), k.resolvedDependencies = k.resolvedDependencies.filter((L) => !_.includes(L)), _.forEach((L) => {
351
- delete k.events[L];
350
+ this.track(f, N), D.resolvedDependencies = D.resolvedDependencies.filter((L) => !_.includes(L)), _.forEach((L) => {
351
+ delete D.events[L];
352
352
  });
353
353
  }
354
354
  }
355
355
  };
356
356
  }
357
- function ge() {
357
+ function he() {
358
358
  let e = 0;
359
359
  return {
360
360
  reset: () => e = 0,
@@ -362,19 +362,19 @@ function ge() {
362
362
  get: (t = !1) => t ? Date.now() - e : e
363
363
  };
364
364
  }
365
- const x = ge(), te = ge();
366
- function he(e) {
365
+ const F = he(), re = he();
366
+ function we(e) {
367
367
  return e === A.Playground ? {
368
368
  headers: {
369
369
  [Be]: "true"
370
370
  }
371
371
  } : {};
372
372
  }
373
- async function we(e, t, a, n, s = !1, i) {
373
+ async function pe(e, t, a, n, s = !1, i) {
374
374
  try {
375
- return !i && n !== A.DirectPlayback && (i = await t.newChat(e.id, {
375
+ return !i && !le(n) && (i = await t.newChat(e.id, {
376
376
  persist: s
377
- }, he(n)), a.track("agent-chat", {
377
+ }, we(n)), a.track("agent-chat", {
378
378
  event: "created",
379
379
  chat_id: i.id,
380
380
  agent_id: e.id,
@@ -394,28 +394,28 @@ async function we(e, t, a, n, s = !1, i) {
394
394
  throw new Error("Cannot create new chat");
395
395
  }
396
396
  }
397
- function qe(e) {
397
+ function Ve(e) {
398
398
  return e && e.length > 0 ? e : [];
399
399
  }
400
- function Ve(e, t, a, n, s) {
401
- if (!e || !t)
400
+ function Xe(e, t, a, n) {
401
+ if (!e)
402
402
  throw new Error("Please connect to the agent first");
403
403
  if (!e.interruptAvailable)
404
404
  throw new Error("Interrupt is not enabled for this stream");
405
- if (a !== W.Fluent)
405
+ if (t !== U.Fluent)
406
406
  throw new Error("Interrupt only available for Fluent streams");
407
- if (!n && !s)
407
+ if (!a && !n)
408
408
  throw new Error("No active video to interrupt");
409
409
  }
410
- async function O(e, t) {
410
+ async function ee(e, t) {
411
411
  const a = {
412
- type: F.StreamInterrupt,
412
+ type: J.StreamInterrupt,
413
413
  videoId: t,
414
414
  timestamp: Date.now()
415
415
  };
416
416
  e.sendDataChannelMessage(JSON.stringify(a));
417
417
  }
418
- function Xe(e) {
418
+ function Ye(e) {
419
419
  return new Promise((t, a) => {
420
420
  const {
421
421
  callbacks: n,
@@ -426,7 +426,7 @@ function Xe(e) {
426
426
  onOpen: c = null,
427
427
  onClose: r = null,
428
428
  onError: l = null
429
- } = n || {}, d = new WebSocket(`${s}?authorization=${ue(i)}`);
429
+ } = n || {}, d = new WebSocket(`${s}?authorization=${fe(i)}`);
430
430
  d.onmessage = o, d.onclose = r, d.onerror = (f) => {
431
431
  console.error(f), l == null || l("Websocket failed to connect", f), a(f);
432
432
  }, d.onopen = (f) => {
@@ -434,14 +434,14 @@ function Xe(e) {
434
434
  };
435
435
  });
436
436
  }
437
- async function Ye(e) {
437
+ async function Qe(e) {
438
438
  const {
439
439
  retries: t = 1
440
440
  } = e;
441
441
  let a = null;
442
442
  for (let n = 0; (a == null ? void 0 : a.readyState) !== WebSocket.OPEN; n++)
443
443
  try {
444
- a = await Xe(e);
444
+ a = await Ye(e);
445
445
  } catch (s) {
446
446
  if (n === t)
447
447
  throw s;
@@ -449,8 +449,8 @@ async function Ye(e) {
449
449
  }
450
450
  return a;
451
451
  }
452
- async function Qe(e, t, a) {
453
- const n = a != null && a.onMessage ? [a.onMessage] : [], s = await Ye({
452
+ async function Oe(e, t, a) {
453
+ const n = a != null && a.onMessage ? [a.onMessage] : [], s = await Qe({
454
454
  auth: e,
455
455
  host: t,
456
456
  callbacks: {
@@ -480,52 +480,52 @@ function Ze(e) {
480
480
  }
481
481
  function Ge(e, t, a, n, s) {
482
482
  const i = n.messages[n.messages.length - 1];
483
- if (!(e === H.Partial || e === H.Answer) || (i == null ? void 0 : i.role) !== "assistant")
483
+ if (!(e === q.Partial || e === q.Answer) || (i == null ? void 0 : i.role) !== "assistant")
484
484
  return;
485
485
  const {
486
486
  content: o,
487
487
  sequence: c
488
488
  } = t;
489
- e === H.Partial ? a[c] = o : a.answer = o;
489
+ e === q.Partial ? a[c] = o : a.answer = o;
490
490
  const r = Ze(a);
491
- (i.content !== r || e === H.Answer) && (i.content = r, s == null || s([...n.messages], e));
491
+ (i.content !== r || e === q.Answer) && (i.content = r, s == null || s([...n.messages], e));
492
492
  }
493
- function Oe(e, t, a, n, s) {
493
+ function et(e, t, a, n, s) {
494
494
  let i = {};
495
495
  return {
496
496
  clearQueue: () => i = {},
497
497
  onMessage: (o, c) => {
498
498
  var r, l;
499
499
  if ("content" in c)
500
- Ge(o, c, i, t, a.callbacks.onNewMessage), o === H.Answer && e.track("agent-message-received", {
500
+ Ge(o, c, i, t, a.callbacks.onNewMessage), o === q.Answer && e.track("agent-message-received", {
501
501
  messages: t.messages.length,
502
502
  mode: t.chatMode
503
503
  });
504
504
  else {
505
- const d = F, f = [d.StreamVideoDone, d.StreamVideoError, d.StreamVideoRejected], B = [d.StreamFailed, d.StreamVideoError, d.StreamVideoRejected], M = Ue(c, n, {
505
+ const d = J, f = [d.StreamVideoDone, d.StreamVideoError, d.StreamVideoRejected], $ = [d.StreamFailed, d.StreamVideoError, d.StreamVideoRejected], I = Ke(c, n, {
506
506
  mode: t.chatMode
507
507
  });
508
508
  if (o = o, o === d.StreamVideoCreated)
509
- e.linkTrack("agent-video", M, d.StreamVideoCreated, ["start"]);
509
+ e.linkTrack("agent-video", I, d.StreamVideoCreated, ["start"]);
510
510
  else if (f.includes(o)) {
511
511
  const _ = o.split("/")[1];
512
- B.includes(o) ? e.track("agent-video", {
513
- ...M,
512
+ $.includes(o) ? e.track("agent-video", {
513
+ ...I,
514
514
  event: _
515
515
  }) : e.linkTrack("agent-video", {
516
- ...M,
516
+ ...I,
517
517
  event: _
518
518
  }, o, ["done"]);
519
519
  }
520
- B.includes(o) && ((l = (r = a.callbacks).onError) == null || l.call(r, new Error(`Stream failed with event ${o}`), {
520
+ $.includes(o) && ((l = (r = a.callbacks).onError) == null || l.call(r, new Error(`Stream failed with event ${o}`), {
521
521
  data: c
522
522
  })), c.event === d.StreamDone && s();
523
523
  }
524
524
  }
525
525
  };
526
526
  }
527
- function et(e, t, a, n) {
528
- const s = ne(e, `${t}/agents/${a}`, n);
527
+ function tt(e, t, a, n) {
528
+ const s = ae(e, `${t}/agents/${a}`, n);
529
529
  return {
530
530
  createStream(i) {
531
531
  return s.post("/streams", {
@@ -561,8 +561,8 @@ function et(e, t, a, n) {
561
561
  }
562
562
  };
563
563
  }
564
- function tt(e, t, a, n) {
565
- const s = ne(e, `${t}/agents/${a}`, n);
564
+ function rt(e, t, a, n) {
565
+ const s = ae(e, `${t}/agents/${a}`, n);
566
566
  return {
567
567
  createStream(i, o) {
568
568
  return s.post("/streams", {
@@ -601,7 +601,7 @@ function tt(e, t, a, n) {
601
601
  }
602
602
  };
603
603
  }
604
- function rt(e, t, a) {
604
+ function nt(e, t, a) {
605
605
  const n = (t.timestamp - e.timestamp) / 1e3;
606
606
  return {
607
607
  duration: n,
@@ -621,7 +621,7 @@ function rt(e, t, a) {
621
621
  lowFpsCount: a
622
622
  };
623
623
  }
624
- function nt(e) {
624
+ function at(e) {
625
625
  return e.filter((t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0).map((t) => {
626
626
  const {
627
627
  timestamp: a,
@@ -633,7 +633,7 @@ function nt(e) {
633
633
  };
634
634
  });
635
635
  }
636
- function at(e) {
636
+ function it(e) {
637
637
  let t = "", a = 0;
638
638
  for (const n of e.values())
639
639
  if (n && n.type === "codec" && n.mimeType.startsWith("video") && (t = n.mimeType.split("/")[1]), n && n.type === "candidate-pair" && (a = n.currentRoundTripTime), n && n.type === "inbound-rtp" && n.kind === "video")
@@ -658,7 +658,7 @@ function at(e) {
658
658
  };
659
659
  return {};
660
660
  }
661
- function it(e, t, a) {
661
+ function st(e, t, a) {
662
662
  const n = e.map((r, l) => l === 0 ? a ? {
663
663
  timestamp: r.timestamp,
664
664
  duration: 0,
@@ -710,14 +710,14 @@ function it(e, t, a) {
710
710
  framesPerSecond: r.framesPerSecond,
711
711
  freezeCount: r.freezeCount - e[l - 1].freezeCount,
712
712
  freezeDuration: r.freezeDuration - e[l - 1].freezeDuration
713
- }), s = nt(n), i = s.reduce((r, l) => r + (l.causes.includes("low fps") ? 1 : 0), 0), o = n.filter((r) => !!r.avgJitterDelayInInterval).map((r) => r.avgJitterDelayInInterval), c = n.filter((r) => !!r.rtt).map((r) => r.rtt);
713
+ }), s = at(n), i = s.reduce((r, l) => r + (l.causes.includes("low fps") ? 1 : 0), 0), o = n.filter((r) => !!r.avgJitterDelayInInterval).map((r) => r.avgJitterDelayInInterval), c = n.filter((r) => !!r.rtt).map((r) => r.rtt);
714
714
  return {
715
715
  webRTCStats: {
716
716
  anomalies: s,
717
717
  minRtt: Math.min(...c),
718
718
  avgRtt: ie(c),
719
719
  maxRtt: Math.max(...c),
720
- aggregateReport: rt(e[0], e[e.length - 1], i),
720
+ aggregateReport: nt(e[0], e[e.length - 1], i),
721
721
  minJitterDelayInInterval: Math.min(...o),
722
722
  maxJitterDelayInInterval: Math.max(...o),
723
723
  avgJitterDelayInInterval: ie(o)
@@ -726,8 +726,8 @@ function it(e, t, a) {
726
726
  resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
727
727
  };
728
728
  }
729
- const re = 100, st = Math.max(Math.ceil(400 / re), 1), ot = 0.25, ct = 0.28;
730
- function dt() {
729
+ const ne = 100, ot = Math.max(Math.ceil(400 / ne), 1), ct = 0.25, dt = 0.28;
730
+ function lt() {
731
731
  let e = 0, t, a, n = 0;
732
732
  return (s) => {
733
733
  for (const i of s.values())
@@ -751,25 +751,25 @@ function dt() {
751
751
  };
752
752
  };
753
753
  }
754
- function lt(e, t, a, n, s, i = !1) {
755
- let o = [], c, r = 0, l = !1, d = Y.Unknown, f = Y.Unknown, B = 0, M = 0;
756
- const _ = dt();
754
+ function ut(e, t, a, n, s, i = !1) {
755
+ let o = [], c, r = 0, l = !1, d = Q.Unknown, f = Q.Unknown, $ = 0, I = 0;
756
+ const _ = lt();
757
757
  return setInterval(async () => {
758
- const k = await e.getStats(), {
759
- isReceiving: D,
758
+ const D = await e.getStats(), {
759
+ isReceiving: v,
760
760
  avgJitterDelayInInterval: N,
761
761
  freezeCount: L
762
- } = _(k), $ = at(k);
763
- if (D)
764
- r = 0, B = L - M, f = N < ot ? Y.Strong : N > ct && B > 1 ? Y.Weak : d, f !== d && (s == null || s(f), d = f, M += B, B = 0), l || (n == null || n(p.Start), c = o[o.length - 1], o = [], l = !0), o.push($);
765
- else if (l && (r++, r >= st)) {
766
- const u = it(o, re, c);
767
- n == null || n(p.Stop, u), t() || a(), M = L, l = !1;
762
+ } = _(D), b = it(D);
763
+ if (v)
764
+ r = 0, $ = L - I, f = N < ct ? Q.Strong : N > dt && $ > 1 ? Q.Weak : d, f !== d && (s == null || s(f), d = f, I += $, $ = 0), l || (n == null || n(p.Start), c = o[o.length - 1], o = [], l = !0), o.push(b);
765
+ else if (l && (r++, r >= ot)) {
766
+ const u = st(o, ne, c);
767
+ n == null || n(p.Stop, u), t() || a(), I = L, l = !1;
768
768
  }
769
- }, re);
769
+ }, ne);
770
770
  }
771
- let pe = !1;
772
- const z = (e, t) => pe && console.log(e, t), ut = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
771
+ let ye = !1;
772
+ const z = (e, t) => ye && console.log(e, t), ft = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
773
773
  function se(e) {
774
774
  switch (e) {
775
775
  case "connected":
@@ -790,7 +790,7 @@ function se(e) {
790
790
  return j.New;
791
791
  }
792
792
  }
793
- function ft(e) {
793
+ function mt(e) {
794
794
  const [t, a = ""] = e.split(/:(.+)/);
795
795
  try {
796
796
  const n = JSON.parse(a);
@@ -812,7 +812,7 @@ function ft(e) {
812
812
  };
813
813
  }
814
814
  }
815
- function mt({
815
+ function gt({
816
816
  statsSignal: e,
817
817
  dataChannelSignal: t,
818
818
  onVideoStateChange: a,
@@ -820,14 +820,14 @@ function mt({
820
820
  }) {
821
821
  e === p.Start && t === p.Start ? a == null || a(p.Start) : e === p.Stop && t === p.Stop && (a == null || a(p.Stop, n));
822
822
  }
823
- function gt({
823
+ function ht({
824
824
  statsSignal: e,
825
825
  dataChannelSignal: t,
826
826
  onVideoStateChange: a,
827
827
  onAgentActivityStateChange: n,
828
828
  report: s
829
829
  }) {
830
- e === p.Start ? a == null || a(p.Start) : e === p.Stop && (a == null || a(p.Stop, s)), t === p.Start ? n == null || n(V.Talking) : t === p.Stop && (n == null || n(V.Idle));
830
+ e === p.Start ? a == null || a(p.Start) : e === p.Stop && (a == null || a(p.Stop, s)), t === p.Start ? n == null || n(X.Talking) : t === p.Stop && (n == null || n(X.Idle));
831
831
  }
832
832
  function oe({
833
833
  statsSignal: e,
@@ -837,12 +837,12 @@ function oe({
837
837
  streamType: s,
838
838
  report: i
839
839
  }) {
840
- s === W.Legacy ? mt({
840
+ s === U.Legacy ? gt({
841
841
  statsSignal: e,
842
842
  dataChannelSignal: t,
843
843
  onVideoStateChange: a,
844
844
  report: i
845
- }) : s === W.Fluent && gt({
845
+ }) : s === U.Fluent && ht({
846
846
  statsSignal: e,
847
847
  dataChannelSignal: t,
848
848
  onVideoStateChange: a,
@@ -850,99 +850,106 @@ function oe({
850
850
  report: i
851
851
  });
852
852
  }
853
- async function ht(e, t, {
853
+ async function wt(e, t, {
854
854
  debug: a = !1,
855
855
  callbacks: n,
856
856
  auth: s,
857
- baseURL: i = Q,
857
+ baseURL: i = O,
858
858
  analytics: o
859
859
  }) {
860
- pe = a;
860
+ var x;
861
+ ye = a;
861
862
  let c = !1, r = !1, l = p.Stop, d = p.Stop;
862
863
  const {
863
864
  startConnection: f,
864
- sendStreamRequest: B,
865
- close: M,
865
+ sendStreamRequest: $,
866
+ close: I,
866
867
  createStream: _,
867
- addIceCandidate: k
868
- } = t.videoType === ce.Clip ? et(s, i, e, n.onError) : tt(s, i, e, n.onError), {
869
- id: D,
868
+ addIceCandidate: D
869
+ } = t.videoType === ce.Clip ? tt(s, i, e, n.onError) : rt(s, i, e, n.onError), {
870
+ id: v,
870
871
  offer: N,
871
872
  ice_servers: L,
872
- session_id: $,
873
+ session_id: b,
873
874
  fluent: u,
874
875
  interrupt_enabled: w
875
- } = await _(t), g = new ut({
876
+ } = await _(t);
877
+ (x = n.onStreamCreated) == null || x.call(n, {
878
+ stream_id: v,
879
+ session_id: b,
880
+ agent_id: e
881
+ });
882
+ const g = new ft({
876
883
  iceServers: L
877
884
  }), S = g.createDataChannel("JanusDataChannel");
878
- if (!$)
885
+ if (!b)
879
886
  throw new Error("Could not create session_id");
880
- const R = u ? W.Fluent : W.Legacy;
887
+ const C = u ? U.Fluent : U.Legacy;
881
888
  o.enrich({
882
- "stream-type": R
889
+ "stream-type": C
883
890
  });
884
- const v = t.stream_warmup && !u, P = () => c, T = () => {
891
+ const k = t.stream_warmup && !u, P = () => c, M = () => {
885
892
  var m;
886
893
  c = !0, r && ((m = n.onConnectionStateChange) == null || m.call(n, j.Connected));
887
- }, b = lt(g, P, T, (m, h) => oe({
894
+ }, T = ut(g, P, M, (m, h) => oe({
888
895
  statsSignal: d = m,
889
- dataChannelSignal: R === W.Legacy ? l : void 0,
896
+ dataChannelSignal: C === U.Legacy ? l : void 0,
890
897
  onVideoStateChange: n.onVideoStateChange,
891
898
  onAgentActivityStateChange: n.onAgentActivityStateChange,
892
899
  report: h,
893
- streamType: R
900
+ streamType: C
894
901
  }), (m) => {
895
902
  var h;
896
903
  return (h = n.onConnectivityStateChange) == null ? void 0 : h.call(n, m);
897
- }, v);
904
+ }, k);
898
905
  g.onicecandidate = (m) => {
899
906
  var h;
900
907
  z("peerConnection.onicecandidate", m);
901
908
  try {
902
- m.candidate && m.candidate.sdpMid && m.candidate.sdpMLineIndex !== null ? k(D, {
909
+ m.candidate && m.candidate.sdpMid && m.candidate.sdpMLineIndex !== null ? D(v, {
903
910
  candidate: m.candidate.candidate,
904
911
  sdpMid: m.candidate.sdpMid,
905
912
  sdpMLineIndex: m.candidate.sdpMLineIndex
906
- }, $) : k(D, {
913
+ }, b) : D(v, {
907
914
  candidate: null
908
- }, $);
909
- } catch (E) {
910
- (h = n.onError) == null || h.call(n, E, {
911
- streamId: D
915
+ }, b);
916
+ } catch (B) {
917
+ (h = n.onError) == null || h.call(n, B, {
918
+ streamId: v
912
919
  });
913
920
  }
914
921
  }, S.onopen = () => {
915
- r = !0, (!v || c) && T();
922
+ r = !0, (!k || c) && M();
916
923
  };
917
924
  function y(m) {
918
- l = m === F.StreamStarted ? p.Start : p.Stop, oe({
919
- statsSignal: R === W.Legacy ? d : void 0,
925
+ l = m === J.StreamStarted ? p.Start : p.Stop, oe({
926
+ statsSignal: C === U.Legacy ? d : void 0,
920
927
  dataChannelSignal: l,
921
928
  onVideoStateChange: n.onVideoStateChange,
922
929
  onAgentActivityStateChange: n.onAgentActivityStateChange,
923
- streamType: R
930
+ streamType: C
924
931
  });
925
932
  }
926
- function I(m, h) {
927
- const E = typeof h == "string" ? h : h == null ? void 0 : h.metadata;
928
- E && o.enrich({
929
- streamMetadata: E
933
+ function E(m, h) {
934
+ const B = typeof h == "string" ? h : h == null ? void 0 : h.metadata;
935
+ B && o.enrich({
936
+ streamMetadata: B
930
937
  }), o.track("agent-chat", {
931
938
  event: "ready"
932
939
  });
933
940
  }
934
- const C = {
935
- [F.StreamStarted]: y,
936
- [F.StreamDone]: y,
937
- [F.StreamReady]: I
941
+ const R = {
942
+ [J.StreamStarted]: y,
943
+ [J.StreamDone]: y,
944
+ [J.StreamReady]: E
938
945
  };
939
946
  S.onmessage = (m) => {
940
- var U;
947
+ var K;
941
948
  const {
942
949
  subject: h,
943
- data: E
944
- } = ft(m.data);
945
- (U = C[h]) == null || U.call(C, h, E);
950
+ data: B
951
+ } = mt(m.data);
952
+ (K = R[h]) == null || K.call(R, h, B);
946
953
  }, g.oniceconnectionstatechange = () => {
947
954
  var h;
948
955
  z("peerConnection.oniceconnectionstatechange => " + g.iceConnectionState);
@@ -952,70 +959,70 @@ async function ht(e, t, {
952
959
  var h;
953
960
  z("peerConnection.ontrack", m), (h = n.onSrcObjectReady) == null || h.call(n, m.streams[0]);
954
961
  }, await g.setRemoteDescription(N), z("set remote description OK");
955
- const J = await g.createAnswer();
956
- return z("create answer OK"), await g.setLocalDescription(J), z("set local description OK"), await f(D, J, $), z("start connection OK"), {
962
+ const W = await g.createAnswer();
963
+ return z("create answer OK"), await g.setLocalDescription(W), z("set local description OK"), await f(v, W, b), z("start connection OK"), {
957
964
  /**
958
965
  * Method to send request to server to get clip or talk depend on you payload
959
966
  * @param payload
960
967
  */
961
968
  speak(m) {
962
- return B(D, $, m);
969
+ return $(v, b, m);
963
970
  },
964
971
  /**
965
972
  * Method to close RTC connection
966
973
  */
967
974
  async disconnect() {
968
975
  var m;
969
- if (D) {
976
+ if (v) {
970
977
  const h = se(g.iceConnectionState);
971
978
  if (g) {
972
979
  if (h === j.New) {
973
- clearInterval(b);
980
+ clearInterval(T);
974
981
  return;
975
982
  }
976
983
  g.close(), g.oniceconnectionstatechange = null, g.onnegotiationneeded = null, g.onicecandidate = null, g.ontrack = null;
977
984
  }
978
985
  try {
979
- h === j.Connected && await M(D, $).catch((E) => {
986
+ h === j.Connected && await I(v, b).catch((B) => {
980
987
  });
981
- } catch (E) {
982
- z("Error on close stream connection", E);
988
+ } catch (B) {
989
+ z("Error on close stream connection", B);
983
990
  }
984
- (m = n.onAgentActivityStateChange) == null || m.call(n, V.Idle), clearInterval(b);
991
+ (m = n.onAgentActivityStateChange) == null || m.call(n, X.Idle), clearInterval(T);
985
992
  }
986
993
  },
987
994
  /**
988
995
  * Method to send data channel messages to the server
989
996
  */
990
997
  sendDataChannelMessage(m) {
991
- var h, E;
998
+ var h, B;
992
999
  if (!c || S.readyState !== "open") {
993
1000
  z("Data channel is not ready for sending messages"), (h = n.onError) == null || h.call(n, new Error("Data channel is not ready for sending messages"), {
994
- streamId: D
1001
+ streamId: v
995
1002
  });
996
1003
  return;
997
1004
  }
998
1005
  try {
999
1006
  S.send(m);
1000
- } catch (U) {
1001
- z("Error sending data channel message", U), (E = n.onError) == null || E.call(n, U, {
1002
- streamId: D
1007
+ } catch (K) {
1008
+ z("Error sending data channel message", K), (B = n.onError) == null || B.call(n, K, {
1009
+ streamId: v
1003
1010
  });
1004
1011
  }
1005
1012
  },
1006
1013
  /**
1007
1014
  * Session identifier information, should be returned in the body of all streaming requests
1008
1015
  */
1009
- sessionId: $,
1016
+ sessionId: b,
1010
1017
  /**
1011
1018
  * Id of current RTC stream
1012
1019
  */
1013
- streamId: D,
1014
- streamType: R,
1020
+ streamId: v,
1021
+ streamType: C,
1015
1022
  interruptAvailable: w
1016
1023
  };
1017
1024
  }
1018
- function wt(e, t) {
1025
+ function pt(e, t) {
1019
1026
  const {
1020
1027
  streamOptions: a
1021
1028
  } = t ?? {};
@@ -1028,10 +1035,10 @@ function wt(e, t) {
1028
1035
  fluent: a == null ? void 0 : a.fluent
1029
1036
  };
1030
1037
  }
1031
- function pt(e, t, a, n, s) {
1032
- s === W.Fluent ? yt(e, t, a, n, s) : kt(e, t, a, n, s);
1033
- }
1034
1038
  function yt(e, t, a, n, s) {
1039
+ s === U.Fluent ? vt(e, t, a, n, s) : Dt(e, t, a, n, s);
1040
+ }
1041
+ function vt(e, t, a, n, s) {
1035
1042
  e === p.Start ? n.track("stream-session", {
1036
1043
  event: "start",
1037
1044
  "stream-type": s
@@ -1043,35 +1050,35 @@ function yt(e, t, a, n, s) {
1043
1050
  ...a
1044
1051
  });
1045
1052
  }
1046
- function vt(e, t, a, n) {
1047
- x.get() <= 0 || (e === p.Start ? a.linkTrack("agent-video", {
1053
+ function kt(e, t, a, n) {
1054
+ F.get() <= 0 || (e === p.Start ? a.linkTrack("agent-video", {
1048
1055
  event: "start",
1049
- latency: x.get(!0),
1056
+ latency: F.get(!0),
1050
1057
  "stream-type": n
1051
- }, "start", [F.StreamVideoCreated]) : e === p.Stop && a.linkTrack("agent-video", {
1058
+ }, "start", [J.StreamVideoCreated]) : e === p.Stop && a.linkTrack("agent-video", {
1052
1059
  event: "stop",
1053
1060
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1054
1061
  background: t.presenter.type === "clip" && t.presenter.background,
1055
1062
  "stream-type": n
1056
- }, "done", [F.StreamVideoDone]));
1063
+ }, "done", [J.StreamVideoDone]));
1057
1064
  }
1058
- function kt(e, t, a, n, s) {
1059
- x.get() <= 0 || (e === p.Start ? n.linkTrack("agent-video", {
1065
+ function Dt(e, t, a, n, s) {
1066
+ F.get() <= 0 || (e === p.Start ? n.linkTrack("agent-video", {
1060
1067
  event: "start",
1061
- latency: x.get(!0),
1068
+ latency: F.get(!0),
1062
1069
  "stream-type": s
1063
- }, "start", [F.StreamVideoCreated]) : e === p.Stop && n.linkTrack("agent-video", {
1070
+ }, "start", [J.StreamVideoCreated]) : e === p.Stop && n.linkTrack("agent-video", {
1064
1071
  event: "stop",
1065
1072
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1066
1073
  background: t.presenter.type === "clip" && t.presenter.background,
1067
1074
  "stream-type": s,
1068
1075
  ...a
1069
- }, "done", [F.StreamVideoDone]));
1076
+ }, "done", [J.StreamVideoDone]));
1070
1077
  }
1071
- function Dt(e, t, a) {
1072
- return x.reset(), new Promise(async (n, s) => {
1078
+ function Ct(e, t, a) {
1079
+ return F.reset(), new Promise(async (n, s) => {
1073
1080
  try {
1074
- const i = await ht(e.id, wt(e, t), {
1081
+ const i = await wt(e.id, pt(e, t), {
1075
1082
  ...t,
1076
1083
  analytics: a,
1077
1084
  callbacks: {
@@ -1082,11 +1089,11 @@ function Dt(e, t, a) {
1082
1089
  },
1083
1090
  onVideoStateChange: (o, c) => {
1084
1091
  var r, l;
1085
- (l = (r = t.callbacks).onVideoStateChange) == null || l.call(r, o), pt(o, e, c, a, i.streamType);
1092
+ (l = (r = t.callbacks).onVideoStateChange) == null || l.call(r, o), yt(o, e, c, a, i.streamType);
1086
1093
  },
1087
1094
  onAgentActivityStateChange: (o) => {
1088
1095
  var c, r;
1089
- (r = (c = t.callbacks).onAgentActivityStateChange) == null || r.call(c, o), o === V.Talking ? te.update() : te.reset(), vt(o === V.Talking ? p.Start : p.Stop, e, a, i.streamType);
1096
+ (r = (c = t.callbacks).onAgentActivityStateChange) == null || r.call(c, o), o === X.Talking ? re.update() : re.reset(), kt(o === X.Talking ? p.Start : p.Stop, e, a, i.streamType);
1090
1097
  }
1091
1098
  }
1092
1099
  });
@@ -1100,70 +1107,70 @@ async function Rt(e, t, a, n, s) {
1100
1107
  const {
1101
1108
  chat: i,
1102
1109
  chatMode: o
1103
- } = await we(e, a, n, t.mode, t.persistentChat, s);
1110
+ } = await pe(e, a, n, t.mode, t.persistentChat, s);
1104
1111
  if (o && o !== t.mode && (t.mode = o, (l = (r = t.callbacks).onModeChange) == null || l.call(r, o), o === A.TextOnly))
1105
- return (f = (d = t.callbacks).onError) == null || f.call(d, new De(o)), {
1112
+ return (f = (d = t.callbacks).onError) == null || f.call(d, new Ce(o)), {
1106
1113
  chat: i
1107
1114
  };
1108
- const c = await Dt(e, t, n);
1115
+ const c = await Ct(e, t, n);
1109
1116
  return {
1110
1117
  chat: i,
1111
1118
  streamingManager: c
1112
1119
  };
1113
1120
  }
1114
- async function _t(e, t) {
1115
- var N, L, $;
1121
+ async function St(e, t) {
1122
+ var N, L, b;
1116
1123
  let a = !0, n = !1, s = !1;
1117
- const i = t.mixpanelKey || Le, o = t.wsURL || $e, c = t.baseURL || Q, r = {
1124
+ const i = t.mixpanelKey || ze, o = t.wsURL || Le, c = t.baseURL || O, r = {
1118
1125
  messages: [],
1119
1126
  chatMode: t.mode || A.Functional
1120
- }, l = fe(t.auth, c, t.callbacks.onError), d = await l.getById(e), f = He({
1127
+ }, l = me(t.auth, c, t.callbacks.onError), d = await l.getById(e), f = qe({
1121
1128
  token: i,
1122
1129
  agent: d,
1123
1130
  isEnabled: t.enableAnalitics,
1124
1131
  distinctId: t.distinctId
1125
1132
  }), {
1126
- onMessage: B,
1127
- clearQueue: M
1128
- } = Oe(f, r, t, d, () => {
1133
+ onMessage: $,
1134
+ clearQueue: I
1135
+ } = et(f, r, t, d, () => {
1129
1136
  var u;
1130
1137
  return (u = r.socketManager) == null ? void 0 : u.disconnect();
1131
1138
  });
1132
- r.messages = qe(t.initialMessages), (L = (N = t.callbacks).onNewMessage) == null || L.call(N, [...r.messages], "answer"), f.track("agent-sdk", {
1139
+ r.messages = Ve(t.initialMessages), (L = (N = t.callbacks).onNewMessage) == null || L.call(N, [...r.messages], "answer"), f.track("agent-sdk", {
1133
1140
  event: "loaded",
1134
- ...Je(d)
1141
+ ...We(d)
1135
1142
  });
1136
1143
  async function _(u) {
1137
- var P, T, b, y, I, C, J;
1138
- (T = (P = t.callbacks).onConnectionStateChange) == null || T.call(P, j.Connecting), x.reset(), n = !1, s = !1, u && !a && (delete r.chat, (y = (b = t.callbacks).onNewMessage) == null || y.call(b, [...r.messages], "answer"));
1139
- const w = t.mode === A.DirectPlayback ? Promise.resolve(void 0) : Qe(t.auth, o, {
1140
- onMessage: B,
1144
+ var P, M, T, y, E, R, W;
1145
+ (M = (P = t.callbacks).onConnectionStateChange) == null || M.call(P, j.Connecting), F.reset(), n = !1, s = !1, u && !a && (delete r.chat, (y = (T = t.callbacks).onNewMessage) == null || y.call(T, [...r.messages], "answer"));
1146
+ const w = t.mode === A.DirectPlayback ? Promise.resolve(void 0) : Oe(t.auth, o, {
1147
+ onMessage: $,
1141
1148
  onError: t.callbacks.onError
1142
- }), g = ee(() => Rt(d, t, l, f, r.chat), {
1149
+ }), g = te(() => Rt(d, t, l, f, r.chat), {
1143
1150
  limit: 3,
1144
- timeout: Ae,
1151
+ timeout: $e,
1145
1152
  timeoutErrorMessage: "Timeout initializing the stream",
1146
1153
  // Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
1147
- shouldRetryFn: (m) => (m == null ? void 0 : m.message) !== "Could not connect" && m.status !== 429,
1154
+ shouldRetryFn: (x) => (x == null ? void 0 : x.message) !== "Could not connect" && x.status !== 429,
1148
1155
  delayMs: 1e3
1149
- }).catch((m) => {
1150
- var h, E;
1151
- throw D(A.Maintenance), (E = (h = t.callbacks).onConnectionStateChange) == null || E.call(h, j.Fail), m;
1156
+ }).catch((x) => {
1157
+ var m, h;
1158
+ throw v(A.Maintenance), (h = (m = t.callbacks).onConnectionStateChange) == null || h.call(m, j.Fail), x;
1152
1159
  }), [S, {
1153
- streamingManager: R,
1154
- chat: v
1160
+ streamingManager: C,
1161
+ chat: k
1155
1162
  }] = await Promise.all([w, g]);
1156
- v && v.id !== ((I = r.chat) == null ? void 0 : I.id) && ((J = (C = t.callbacks).onNewChat) == null || J.call(C, v.id)), r.streamingManager = R, r.socketManager = S, r.chat = v, a = !1, D((v == null ? void 0 : v.chat_mode) ?? t.mode ?? A.Functional);
1163
+ k && k.id !== ((E = r.chat) == null ? void 0 : E.id) && ((W = (R = t.callbacks).onNewChat) == null || W.call(R, k.id)), r.streamingManager = C, r.socketManager = S, r.chat = k, a = !1, v((k == null ? void 0 : k.chat_mode) ?? t.mode ?? A.Functional);
1157
1164
  }
1158
- async function k() {
1165
+ async function D() {
1159
1166
  var u, w, g, S;
1160
1167
  (u = r.socketManager) == null || u.disconnect(), await ((w = r.streamingManager) == null ? void 0 : w.disconnect()), n = !1, s = !1, delete r.streamingManager, delete r.socketManager, (S = (g = t.callbacks).onConnectionStateChange) == null || S.call(g, j.Disconnected);
1161
1168
  }
1162
- async function D(u) {
1169
+ async function v(u) {
1163
1170
  var w, g;
1164
1171
  u !== r.chatMode && (f.track("agent-mode-change", {
1165
1172
  mode: u
1166
- }), r.chatMode = u, r.chatMode !== A.Functional && await k(), (g = (w = t.callbacks).onModeChange) == null || g.call(w, u));
1173
+ }), r.chatMode = u, r.chatMode !== A.Functional && await D(), (g = (w = t.callbacks).onModeChange) == null || g.call(w, u));
1167
1174
  }
1168
1175
  return {
1169
1176
  agent: d,
@@ -1175,9 +1182,9 @@ async function _t(e, t) {
1175
1182
  var u;
1176
1183
  return ((u = r.streamingManager) == null ? void 0 : u.interruptAvailable) ?? !1;
1177
1184
  },
1178
- starterMessages: (($ = d.knowledge) == null ? void 0 : $.starter_message) || [],
1185
+ starterMessages: ((b = d.knowledge) == null ? void 0 : b.starter_message) || [],
1179
1186
  getSTTToken: () => l.getSTTToken(d.id),
1180
- changeMode: D,
1187
+ changeMode: v,
1181
1188
  enrichAnalytics: f.enrich,
1182
1189
  async connect() {
1183
1190
  var u;
@@ -1190,7 +1197,7 @@ async function _t(e, t) {
1190
1197
  },
1191
1198
  async reconnect() {
1192
1199
  var u;
1193
- await k(), await _(!1), f.track("agent-chat", {
1200
+ await D(), await _(!1), f.track("agent-chat", {
1194
1201
  event: "reconnect",
1195
1202
  chatId: (u = r.chat) == null ? void 0 : u.id,
1196
1203
  agentId: d.id,
@@ -1199,7 +1206,7 @@ async function _t(e, t) {
1199
1206
  },
1200
1207
  async disconnect() {
1201
1208
  var u;
1202
- await k(), f.track("agent-chat", {
1209
+ await D(), f.track("agent-chat", {
1203
1210
  event: "disconnect",
1204
1211
  chatId: (u = r.chat) == null ? void 0 : u.id,
1205
1212
  agentId: d.id,
@@ -1207,83 +1214,83 @@ async function _t(e, t) {
1207
1214
  });
1208
1215
  },
1209
1216
  async chat(u) {
1210
- var R, v, P, T, b;
1217
+ var C, k, P, M, T;
1211
1218
  const w = () => {
1212
- if (t.mode === A.DirectPlayback)
1213
- throw new K("Direct playback is enabled, chat is disabled");
1219
+ if (le(t.mode))
1220
+ throw new H(`${t.mode} is enabled, chat is disabled`);
1214
1221
  if (u.length >= 800)
1215
- throw new K("Message cannot be more than 800 characters");
1222
+ throw new H("Message cannot be more than 800 characters");
1216
1223
  if (u.length === 0)
1217
- throw new K("Message cannot be empty");
1224
+ throw new H("Message cannot be empty");
1218
1225
  if (r.chatMode === A.Maintenance)
1219
- throw new K("Chat is in maintenance mode");
1226
+ throw new H("Chat is in maintenance mode");
1220
1227
  if (![A.TextOnly, A.Playground].includes(r.chatMode)) {
1221
1228
  if (!r.streamingManager)
1222
- throw new K("Streaming manager is not initialized");
1229
+ throw new H("Streaming manager is not initialized");
1223
1230
  if (!r.chat)
1224
- throw new K("Chat is not initialized");
1231
+ throw new H("Chat is not initialized");
1225
1232
  }
1226
1233
  }, g = async () => {
1227
- var y, I;
1234
+ var y, E;
1228
1235
  if (!r.chat) {
1229
- const C = await we(d, l, f, r.chatMode, t.persistentChat);
1230
- if (!C.chat)
1231
- throw new ke(r.chatMode, !!t.persistentChat);
1232
- r.chat = C.chat, (I = (y = t.callbacks).onNewChat) == null || I.call(y, r.chat.id);
1236
+ const R = await pe(d, l, f, r.chatMode, t.persistentChat);
1237
+ if (!R.chat)
1238
+ throw new De(r.chatMode, !!t.persistentChat);
1239
+ r.chat = R.chat, (E = (y = t.callbacks).onNewChat) == null || E.call(y, r.chat.id);
1233
1240
  }
1234
1241
  return r.chat.id;
1235
- }, S = async (y, I) => ee(() => {
1236
- var C, J;
1237
- return l.chat(d.id, I, {
1242
+ }, S = async (y, E) => te(() => {
1243
+ var R, W;
1244
+ return l.chat(d.id, E, {
1238
1245
  chatMode: r.chatMode,
1239
- streamId: (C = r.streamingManager) == null ? void 0 : C.streamId,
1240
- sessionId: (J = r.streamingManager) == null ? void 0 : J.sessionId,
1246
+ streamId: (R = r.streamingManager) == null ? void 0 : R.streamId,
1247
+ sessionId: (W = r.streamingManager) == null ? void 0 : W.sessionId,
1241
1248
  messages: y.map(({
1242
- matches: m,
1243
- ...h
1244
- }) => h)
1249
+ matches: x,
1250
+ ...m
1251
+ }) => m)
1245
1252
  }, {
1246
- ...he(r.chatMode),
1253
+ ...we(r.chatMode),
1247
1254
  skipErrorHandler: !0
1248
1255
  });
1249
1256
  }, {
1250
1257
  limit: 2,
1251
- shouldRetryFn: (C) => {
1252
- var h, E, U, ae;
1253
- const J = (h = C == null ? void 0 : C.message) == null ? void 0 : h.includes("missing or invalid session_id");
1254
- return !((E = C == null ? void 0 : C.message) == null ? void 0 : E.includes("Stream Error")) && !J ? ((ae = (U = t.callbacks).onError) == null || ae.call(U, C), !1) : !0;
1258
+ shouldRetryFn: (R) => {
1259
+ var m, h, B, K;
1260
+ const W = (m = R == null ? void 0 : R.message) == null ? void 0 : m.includes("missing or invalid session_id");
1261
+ return !((h = R == null ? void 0 : R.message) == null ? void 0 : h.includes("Stream Error")) && !W ? ((K = (B = t.callbacks).onError) == null || K.call(B, R), !1) : !0;
1255
1262
  },
1256
1263
  onRetry: async () => {
1257
- await k(), await _(!1);
1264
+ await D(), await _(!1);
1258
1265
  }
1259
1266
  });
1260
1267
  try {
1261
- M(), w(), r.messages.push({
1262
- id: q(),
1268
+ I(), w(), r.messages.push({
1269
+ id: V(),
1263
1270
  role: "user",
1264
1271
  content: u,
1265
- created_at: new Date(x.update()).toISOString()
1266
- }), (v = (R = t.callbacks).onNewMessage) == null || v.call(R, [...r.messages], "user");
1267
- const y = await g(), I = await S([...r.messages], y);
1272
+ created_at: new Date(F.update()).toISOString()
1273
+ }), (k = (C = t.callbacks).onNewMessage) == null || k.call(C, [...r.messages], "user");
1274
+ const y = await g(), E = await S([...r.messages], y);
1268
1275
  return r.messages.push({
1269
- id: q(),
1276
+ id: V(),
1270
1277
  role: "assistant",
1271
- content: I.result || "",
1278
+ content: E.result || "",
1272
1279
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
1273
- context: I.context,
1274
- matches: I.matches,
1275
- videoId: I.videoId
1276
- }), n && I.videoId && r.streamingManager && (n = !1, r.messages[r.messages.length - 1].interrupted = !0, await O(r.streamingManager, I.videoId)), f.track("agent-message-send", {
1280
+ context: E.context,
1281
+ matches: E.matches,
1282
+ videoId: E.videoId
1283
+ }), n && E.videoId && r.streamingManager && (n = !1, r.messages[r.messages.length - 1].interrupted = !0, await ee(r.streamingManager, E.videoId)), f.track("agent-message-send", {
1277
1284
  event: "success",
1278
1285
  mode: r.chatMode,
1279
1286
  messages: r.messages.length + 1
1280
- }), I.result && ((T = (P = t.callbacks).onNewMessage) == null || T.call(P, [...r.messages], "answer"), f.track("agent-message-received", {
1281
- latency: x.get(!0),
1287
+ }), E.result && ((M = (P = t.callbacks).onNewMessage) == null || M.call(P, [...r.messages], "answer"), f.track("agent-message-received", {
1288
+ latency: F.get(!0),
1282
1289
  mode: r.chatMode,
1283
1290
  messages: r.messages.length
1284
- })), I;
1291
+ })), E;
1285
1292
  } catch (y) {
1286
- throw n = !1, ((b = r.messages[r.messages.length - 1]) == null ? void 0 : b.role) === "assistant" && r.messages.pop(), f.track("agent-message-send", {
1293
+ throw n = !1, ((T = r.messages[r.messages.length - 1]) == null ? void 0 : T.role) === "assistant" && r.messages.pop(), f.track("agent-message-send", {
1287
1294
  event: "error",
1288
1295
  mode: r.chatMode,
1289
1296
  messages: r.messages.length
@@ -1291,30 +1298,30 @@ async function _t(e, t) {
1291
1298
  }
1292
1299
  },
1293
1300
  rate(u, w, g) {
1294
- var v, P, T, b;
1301
+ var k, P, M, T;
1295
1302
  const S = r.messages.find((y) => y.id === u);
1296
1303
  if (r.chat) {
1297
1304
  if (!S)
1298
1305
  throw new Error("Message not found");
1299
1306
  } else
1300
1307
  throw new Error("Chat is not initialized");
1301
- const R = ((v = S.matches) == null ? void 0 : v.map((y) => [y.document_id, y.id])) ?? [];
1308
+ const C = ((k = S.matches) == null ? void 0 : k.map((y) => [y.document_id, y.id])) ?? [];
1302
1309
  return f.track("agent-rate", {
1303
1310
  event: g ? "update" : "create",
1304
1311
  thumb: w === 1 ? "up" : "down",
1305
1312
  knowledge_id: ((P = d.knowledge) == null ? void 0 : P.id) ?? "",
1306
1313
  mode: r.chatMode,
1307
- matches: R,
1314
+ matches: C,
1308
1315
  score: w
1309
1316
  }), g ? l.updateRating(d.id, r.chat.id, g, {
1310
- knowledge_id: ((T = d.knowledge) == null ? void 0 : T.id) ?? "",
1317
+ knowledge_id: ((M = d.knowledge) == null ? void 0 : M.id) ?? "",
1311
1318
  message_id: u,
1312
- matches: R,
1319
+ matches: C,
1313
1320
  score: w
1314
1321
  }) : l.createRating(d.id, r.chat.id, {
1315
- knowledge_id: ((b = d.knowledge) == null ? void 0 : b.id) ?? "",
1322
+ knowledge_id: ((T = d.knowledge) == null ? void 0 : T.id) ?? "",
1316
1323
  message_id: u,
1317
- matches: R,
1324
+ matches: C,
1318
1325
  score: w
1319
1326
  });
1320
1327
  },
@@ -1330,7 +1337,7 @@ async function _t(e, t) {
1330
1337
  }), l.deleteRating(d.id, r.chat.id, u);
1331
1338
  },
1332
1339
  async speak(u) {
1333
- var R, v, P, T, b;
1340
+ var C, k, P, M, T;
1334
1341
  function w() {
1335
1342
  if (typeof u == "string") {
1336
1343
  if (!d.presenter.voice)
@@ -1355,12 +1362,12 @@ async function _t(e, t) {
1355
1362
  return u;
1356
1363
  }
1357
1364
  const g = w();
1358
- if (f.track("agent-speak", g), x.update(), r.messages && g.type === "text" && (r.messages.push({
1359
- id: q(),
1365
+ if (f.track("agent-speak", g), F.update(), r.messages && g.type === "text" && (r.messages.push({
1366
+ id: V(),
1360
1367
  role: "assistant",
1361
1368
  content: g.input,
1362
- created_at: new Date(x.get(!0)).toISOString()
1363
- }), (v = (R = t.callbacks).onNewMessage) == null || v.call(R, [...r.messages], "answer")), ze(r.chatMode))
1369
+ created_at: new Date(F.get(!0)).toISOString()
1370
+ }), (k = (C = t.callbacks).onNewMessage) == null || k.call(C, [...r.messages], "answer")), Ne(r.chatMode))
1364
1371
  return {
1365
1372
  duration: 0,
1366
1373
  video_id: "",
@@ -1377,7 +1384,7 @@ async function _t(e, t) {
1377
1384
  agent_id: d.id
1378
1385
  }
1379
1386
  });
1380
- return s = !1, r.messages[r.messages.length - 1].videoId = y.video_id, n && y.video_id && r.streamingManager && (n = !1, r.messages[r.messages.length - 1].interrupted = !0, await O(r.streamingManager, y.video_id)), (b = (T = t.callbacks).onNewMessage) == null || b.call(T, [...r.messages], "answer"), y;
1387
+ return s = !1, r.messages[r.messages.length - 1].videoId = y.video_id, n && y.video_id && r.streamingManager && (n = !1, r.messages[r.messages.length - 1].interrupted = !0, await ee(r.streamingManager, y.video_id)), (T = (M = t.callbacks).onNewMessage) == null || T.call(M, [...r.messages], "answer"), y;
1381
1388
  } finally {
1382
1389
  s = !1;
1383
1390
  }
@@ -1385,15 +1392,15 @@ async function _t(e, t) {
1385
1392
  async interrupt({
1386
1393
  type: u
1387
1394
  }) {
1388
- var R, v, P, T, b;
1395
+ var C, k, P, M, T;
1389
1396
  const w = r.messages[r.messages.length - 1], g = (w == null ? void 0 : w.role) === "user", S = g || s;
1390
- if (Ve(r.streamingManager, r.chat, (R = r.streamingManager) == null ? void 0 : R.streamType, S, !!(w != null && w.videoId)), f.track("agent-video-interrupt", {
1397
+ if (Xe(r.streamingManager, (C = r.streamingManager) == null ? void 0 : C.streamType, S, !!(w != null && w.videoId)), f.track("agent-video-interrupt", {
1391
1398
  type: u || "click",
1392
- stream_id: (v = r.streamingManager) == null ? void 0 : v.streamId,
1399
+ stream_id: (k = r.streamingManager) == null ? void 0 : k.streamId,
1393
1400
  agent_id: d.id,
1394
1401
  owner_id: d.owner_id,
1395
- video_duration_to_interrupt: te.get(!0),
1396
- message_duration_to_interrupt: x.get(!0),
1402
+ video_duration_to_interrupt: re.get(!0),
1403
+ message_duration_to_interrupt: F.get(!0),
1397
1404
  chat_id: (P = r.chat) == null ? void 0 : P.id,
1398
1405
  mode: r.chatMode,
1399
1406
  queued_interrupt: g
@@ -1401,40 +1408,40 @@ async function _t(e, t) {
1401
1408
  n = !0;
1402
1409
  return;
1403
1410
  }
1404
- w.interrupted = !0, (b = (T = t.callbacks).onNewMessage) == null || b.call(T, [...r.messages], "answer"), O(r.streamingManager, w.videoId);
1411
+ w.interrupted = !0, (T = (M = t.callbacks).onNewMessage) == null || T.call(M, [...r.messages], "answer"), ee(r.streamingManager, w.videoId);
1405
1412
  }
1406
1413
  };
1407
1414
  }
1408
- function St(e, t, a) {
1415
+ function Et(e, t, a) {
1409
1416
  const {
1410
1417
  getById: n
1411
- } = fe(t, a || Q);
1418
+ } = me(t, a || O);
1412
1419
  return n(e);
1413
1420
  }
1414
1421
  export {
1415
- V as AgentActivityState,
1416
- Se as AgentStatus,
1417
- ke as ChatCreationFailed,
1422
+ X as AgentActivityState,
1423
+ Ee as AgentStatus,
1424
+ De as ChatCreationFailed,
1418
1425
  A as ChatMode,
1419
- De as ChatModeDowngraded,
1420
- H as ChatProgress,
1426
+ Ce as ChatModeDowngraded,
1427
+ q as ChatProgress,
1421
1428
  j as ConnectionState,
1422
- Y as ConnectivityState,
1423
- Te as DocumentType,
1424
- Me as KnowledgeType,
1425
- _e as PlanGroup,
1426
- je as Providers,
1429
+ Q as ConnectivityState,
1430
+ je as DocumentType,
1431
+ Te as KnowledgeType,
1432
+ Se as PlanGroup,
1433
+ Pe as Providers,
1427
1434
  Ie as RateState,
1428
- F as StreamEvents,
1429
- W as StreamType,
1435
+ J as StreamEvents,
1436
+ U as StreamType,
1430
1437
  p as StreamingState,
1431
- Ee as Subject,
1432
- Ce as UserPlan,
1433
- K as ValidationError,
1438
+ Me as Subject,
1439
+ _e as UserPlan,
1440
+ H as ValidationError,
1434
1441
  ce as VideoType,
1435
- Pe as VoiceAccess,
1442
+ Ae as VoiceAccess,
1436
1443
  Re as WsError,
1437
- _t as createAgentManager,
1438
- St as getAgent,
1444
+ St as createAgentManager,
1445
+ Et as getAgent,
1439
1446
  be as mapVideoType
1440
1447
  };