@d-id/client-sdk 1.1.0-beta.12 → 1.1.0-beta.13

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,23 +1,23 @@
1
- var me = Object.defineProperty;
2
- var ge = (e, t, a) => t in e ? me(e, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[t] = a;
3
- var q = (e, t, a) => (ge(e, typeof t != "symbol" ? t + "" : t, a), a);
4
- class Q extends Error {
1
+ var he = Object.defineProperty;
2
+ var we = (e, t, a) => t in e ? he(e, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[t] = a;
3
+ var V = (e, t, a) => (we(e, typeof t != "symbol" ? t + "" : t, a), a);
4
+ class Z extends Error {
5
5
  constructor({
6
6
  kind: a,
7
7
  description: r,
8
- error: o
8
+ error: s
9
9
  }) {
10
10
  super(JSON.stringify({
11
11
  kind: a,
12
12
  description: r
13
13
  }));
14
- q(this, "kind");
15
- q(this, "description");
16
- q(this, "error");
17
- this.kind = a, this.description = r, this.error = o;
14
+ V(this, "kind");
15
+ V(this, "description");
16
+ V(this, "error");
17
+ this.kind = a, this.description = r, this.error = s;
18
18
  }
19
19
  }
20
- class he extends Q {
20
+ class pe extends Z {
21
21
  constructor(t, a) {
22
22
  super({
23
23
  kind: "ChatCreationFailed",
@@ -25,7 +25,7 @@ class he extends Q {
25
25
  });
26
26
  }
27
27
  }
28
- class we extends Q {
28
+ class ye extends Z {
29
29
  constructor(t) {
30
30
  super({
31
31
  kind: "ChatModeDowngraded",
@@ -33,17 +33,17 @@ class we extends Q {
33
33
  });
34
34
  }
35
35
  }
36
- class W extends Q {
36
+ class K extends Z {
37
37
  constructor(a, r) {
38
38
  super({
39
39
  kind: "ValidationError",
40
40
  description: a
41
41
  });
42
- q(this, "key");
42
+ V(this, "key");
43
43
  this.key = r;
44
44
  }
45
45
  }
46
- class pe extends Q {
46
+ class ve extends Z {
47
47
  constructor(t) {
48
48
  super({
49
49
  kind: "WSError",
@@ -51,8 +51,8 @@ class pe extends Q {
51
51
  });
52
52
  }
53
53
  }
54
- var ye = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(ye || {}), ve = /* @__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))(ve || {}), ke = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(ke || {}), De = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(De || {}), b = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e))(b || {}), U = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(U || {}), Re = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Re || {}), Ce = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Ce || {}), Se = /* @__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))(Se || {}), ae = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(ae || {});
55
- const Ee = (e) => {
54
+ var ke = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(ke || {}), De = /* @__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))(De || {}), Ce = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ce || {}), Re = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Re || {}), T = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e))(T || {}), 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 || {}), Se = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Se || {}), Ie = /* @__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))(Ie || {}), se = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(se || {});
55
+ const Me = (e) => {
56
56
  switch (e) {
57
57
  case "clip":
58
58
  return "clip";
@@ -62,21 +62,21 @@ const Ee = (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 || {}), V = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(V || {}), X = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(X || {}), N = /* @__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.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(N || {}), M = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(M || {}), J = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(J || {}), _e = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(_e || {}), Me = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Me || {});
66
- const Ie = 45 * 1e3, be = "X-Playground-Chat", Y = "https://api.d-id.com", Te = "wss://notifications.d-id.com", je = "79f81a83a67430be2bc0fd61042b8faa", ie = (e) => new Promise((t) => setTimeout(t, e)), K = (e = 16) => {
65
+ var p = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(p || {}), X = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(X || {}), Y = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(Y || {}), x = /* @__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))(x || {}), _ = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(_ || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}), _e = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(_e || {}), Te = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Te || {});
66
+ const be = 45 * 1e3, je = "X-Playground-Chat", Q = "https://api.d-id.com", Pe = "wss://notifications.d-id.com", Ae = "79f81a83a67430be2bc0fd61042b8faa", oe = (e) => new Promise((t) => setTimeout(t, e)), q = (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
- }, Pe = (e) => [b.TextOnly, b.Playground, b.Maintenance].includes(e);
70
- function Ae(e, t) {
69
+ }, Be = (e) => [T.TextOnly, T.Playground, T.Maintenance].includes(e);
70
+ function $e(e, t) {
71
71
  let a;
72
72
  return {
73
- promise: new Promise((o, s) => {
74
- a = setTimeout(() => s(new Error(t)), e);
73
+ promise: new Promise((s, i) => {
74
+ a = setTimeout(() => i(new Error(t)), e);
75
75
  }),
76
76
  clear: () => clearTimeout(a)
77
77
  };
78
78
  }
79
- async function G(e, t) {
79
+ async function O(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,
@@ -87,225 +87,225 @@ async function G(e, t) {
87
87
  })
88
88
  };
89
89
  let r;
90
- for (let o = 1; o <= a.limit; o++)
90
+ for (let s = 1; s <= a.limit; s++)
91
91
  try {
92
92
  if (!a.timeout)
93
93
  return await e();
94
94
  const {
95
- promise: s,
96
- clear: n
97
- } = Ae(a.timeout, a.timeoutErrorMessage), c = e().finally(n);
98
- return await Promise.race([c, s]);
99
- } catch (s) {
100
- if (r = s, !a.shouldRetryFn(s) || o >= a.limit)
101
- throw s;
102
- await ie(a.delayMs), a.onRetry(s);
95
+ promise: i,
96
+ clear: c
97
+ } = $e(a.timeout, a.timeoutErrorMessage), n = e().finally(c);
98
+ return await Promise.race([n, i]);
99
+ } catch (i) {
100
+ if (r = i, !a.shouldRetryFn(i) || s >= a.limit)
101
+ throw i;
102
+ await oe(a.delayMs), a.onRetry(i);
103
103
  }
104
104
  throw r;
105
105
  }
106
- function se() {
106
+ function ce() {
107
107
  let e = window.localStorage.getItem("did_external_key_id");
108
108
  if (!e) {
109
- let t = K();
109
+ let t = q();
110
110
  window.localStorage.setItem("did_external_key_id", t), e = t;
111
111
  }
112
112
  return e;
113
113
  }
114
- let Be = K();
115
- function oe(e) {
114
+ let Le = q();
115
+ function de(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}.${se()}_${Be}`;
121
+ return `Client-Key ${e.clientKey}.${ce()}_${Le}`;
122
122
  throw new Error(`Unknown auth type: ${e}`);
123
123
  }
124
- const $e = (e) => G(e, {
124
+ const ze = (e) => O(e, {
125
125
  limit: 3,
126
126
  delayMs: 1e3,
127
127
  timeout: 0,
128
128
  shouldRetryFn: (t) => t.status === 429
129
129
  });
130
- function ee(e, t = Y, a) {
131
- const r = async (o, s) => {
130
+ function te(e, t = Q, a) {
131
+ const r = async (s, i) => {
132
132
  const {
133
- skipErrorHandler: n,
134
- ...c
135
- } = s || {}, i = await $e(() => fetch(t + (o != null && o.startsWith("/") ? o : `/${o}`), {
136
- ...c,
133
+ skipErrorHandler: c,
134
+ ...n
135
+ } = i || {}, o = await ze(() => fetch(t + (s != null && s.startsWith("/") ? s : `/${s}`), {
136
+ ...n,
137
137
  headers: {
138
- ...c.headers,
139
- Authorization: oe(e),
138
+ ...n.headers,
139
+ Authorization: de(e),
140
140
  "Content-Type": "application/json"
141
141
  }
142
142
  }));
143
- if (!i.ok) {
144
- let d = await i.text().catch(() => `Failed to fetch with status ${i.status}`);
143
+ if (!o.ok) {
144
+ let d = await o.text().catch(() => `Failed to fetch with status ${o.status}`);
145
145
  const u = new Error(d);
146
- throw a && !n && a(u, {
147
- url: o,
148
- options: c,
149
- headers: i.headers
146
+ throw a && !c && a(u, {
147
+ url: s,
148
+ options: n,
149
+ headers: o.headers
150
150
  }), u;
151
151
  }
152
- return i.json();
152
+ return o.json();
153
153
  };
154
154
  return {
155
- get(o, s) {
156
- return r(o, {
157
- ...s,
155
+ get(s, i) {
156
+ return r(s, {
157
+ ...i,
158
158
  method: "GET"
159
159
  });
160
160
  },
161
- post(o, s, n) {
162
- return r(o, {
163
- ...n,
164
- body: JSON.stringify(s),
161
+ post(s, i, c) {
162
+ return r(s, {
163
+ ...c,
164
+ body: JSON.stringify(i),
165
165
  method: "POST"
166
166
  });
167
167
  },
168
- delete(o, s, n) {
169
- return r(o, {
170
- ...n,
171
- body: JSON.stringify(s),
168
+ delete(s, i, c) {
169
+ return r(s, {
170
+ ...c,
171
+ body: JSON.stringify(i),
172
172
  method: "DELETE"
173
173
  });
174
174
  },
175
- patch(o, s, n) {
176
- return r(o, {
177
- ...n,
178
- body: JSON.stringify(s),
175
+ patch(s, i, c) {
176
+ return r(s, {
177
+ ...c,
178
+ body: JSON.stringify(i),
179
179
  method: "PATCH"
180
180
  });
181
181
  }
182
182
  };
183
183
  }
184
- function ce(e, t = Y, a) {
185
- const r = ee(e, `${t}/agents`, a);
184
+ function le(e, t = Q, a) {
185
+ const r = te(e, `${t}/agents`, a);
186
186
  return {
187
- create(o, s) {
188
- return r.post("/", o, s);
187
+ create(s, i) {
188
+ return r.post("/", s, i);
189
189
  },
190
- getAgents(o, s) {
191
- return r.get(`/${o ? `?tag=${o}` : ""}`, s).then((n) => n ?? []);
190
+ getAgents(s, i) {
191
+ return r.get(`/${s ? `?tag=${s}` : ""}`, i).then((c) => c ?? []);
192
192
  },
193
- getById(o, s) {
194
- return r.get(`/${o}`, s);
193
+ getById(s, i) {
194
+ return r.get(`/${s}`, i);
195
195
  },
196
- delete(o, s) {
197
- return r.delete(`/${o}`, void 0, s);
196
+ delete(s, i) {
197
+ return r.delete(`/${s}`, void 0, i);
198
198
  },
199
- update(o, s, n) {
200
- return r.patch(`/${o}`, s, n);
199
+ update(s, i, c) {
200
+ return r.patch(`/${s}`, i, c);
201
201
  },
202
- newChat(o, s, n) {
203
- return r.post(`/${o}/chat`, s, n);
202
+ newChat(s, i, c) {
203
+ return r.post(`/${s}/chat`, i, c);
204
204
  },
205
- chat(o, s, n, c) {
206
- return r.post(`/${o}/chat/${s}`, n, c);
205
+ chat(s, i, c, n) {
206
+ return r.post(`/${s}/chat/${i}`, c, n);
207
207
  },
208
- createRating(o, s, n, c) {
209
- return r.post(`/${o}/chat/${s}/ratings`, n, c);
208
+ createRating(s, i, c, n) {
209
+ return r.post(`/${s}/chat/${i}/ratings`, c, n);
210
210
  },
211
- updateRating(o, s, n, c, i) {
212
- return r.patch(`/${o}/chat/${s}/ratings/${n}`, c, i);
211
+ updateRating(s, i, c, n, o) {
212
+ return r.patch(`/${s}/chat/${i}/ratings/${c}`, n, o);
213
213
  },
214
- deleteRating(o, s, n, c) {
215
- return r.delete(`/${o}/chat/${s}/ratings/${n}`, c);
214
+ deleteRating(s, i, c, n) {
215
+ return r.delete(`/${s}/chat/${i}/ratings/${c}`, n);
216
216
  },
217
- getSTTToken(o, s) {
218
- return r.get(`/${o}/stt-token`, s);
217
+ getSTTToken(s, i) {
218
+ return r.get(`/${s}/stt-token`, i);
219
219
  }
220
220
  };
221
221
  }
222
- const de = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type;
223
- function Le(e) {
224
- var o, s, n, c;
222
+ const ue = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type;
223
+ function Ne(e) {
224
+ var s, i, c, n;
225
225
  const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", a = () => {
226
- const i = navigator.platform;
227
- return i.toLowerCase().includes("win") ? "Windows" : i.toLowerCase().includes("mac") ? "Mac OS X" : i.toLowerCase().includes("linux") ? "Linux" : "Unknown";
226
+ const o = navigator.platform;
227
+ return o.toLowerCase().includes("win") ? "Windows" : o.toLowerCase().includes("mac") ? "Mac OS X" : o.toLowerCase().includes("linux") ? "Linux" : "Unknown";
228
228
  }, r = e.presenter;
229
229
  return {
230
230
  $os: `${a()}`,
231
231
  isMobile: `${t() == "Mobile"}`,
232
232
  browser: navigator.userAgent,
233
233
  origin: window.location.origin,
234
- agentType: de(r),
234
+ agentType: ue(r),
235
235
  agentVoice: {
236
- voiceId: (s = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : s.voice_id,
237
- provider: (c = (n = e.presenter) == null ? void 0 : n.voice) == null ? void 0 : c.type
236
+ voiceId: (i = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : i.voice_id,
237
+ provider: (n = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : n.type
238
238
  }
239
239
  };
240
240
  }
241
- const ze = (e) => e.reduce((t, a) => t + a, 0), te = (e) => ze(e) / e.length;
241
+ const Fe = (e) => e.reduce((t, a) => t + a, 0), re = (e) => Fe(e) / e.length;
242
242
  function xe(e, t, a) {
243
- var i, d, u;
243
+ var o, d, u;
244
244
  const {
245
245
  event: r,
246
- ...o
246
+ ...s
247
247
  } = e, {
248
- template: s
248
+ template: i
249
249
  } = (t == null ? void 0 : t.llm) || {}, {
250
- language: n
251
- } = ((i = t == null ? void 0 : t.presenter) == null ? void 0 : i.voice) || {};
250
+ language: c
251
+ } = ((o = t == null ? void 0 : t.presenter) == null ? void 0 : o.voice) || {};
252
252
  return {
253
- ...o,
253
+ ...s,
254
254
  llm: {
255
- ...o.llm,
256
- template: s
255
+ ...s.llm,
256
+ template: i
257
257
  },
258
258
  script: {
259
- ...o.script,
259
+ ...s.script,
260
260
  provider: {
261
- ...(d = o == null ? void 0 : o.script) == null ? void 0 : d.provider,
262
- language: n
261
+ ...(d = s == null ? void 0 : s.script) == null ? void 0 : d.provider,
262
+ language: c
263
263
  }
264
264
  },
265
265
  stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (u = t == null ? void 0 : t.presenter) == null ? void 0 : u.stitch : void 0,
266
266
  ...a
267
267
  };
268
268
  }
269
- let Z = {};
270
- const Fe = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
271
- function Ne(e) {
272
- var s, n, c, i, d, u;
273
- const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", a = e.agent.presenter, r = (s = e.agent.llm) == null ? void 0 : s.prompt_customization, o = {
269
+ let G = {};
270
+ const Je = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
271
+ function We(e) {
272
+ var i, c, n, o, d, u;
273
+ const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", a = e.agent.presenter, r = (i = e.agent.llm) == null ? void 0 : i.prompt_customization, s = {
274
274
  token: e.token || "testKey",
275
- distinct_id: e.distinctId || se(),
275
+ distinct_id: e.distinctId || ce(),
276
276
  agentId: e.agent.id,
277
- agentType: de(a),
277
+ agentType: ue(a),
278
278
  owner_id: e.agent.owner_id ?? "",
279
- promptVersion: (n = e.agent.llm) == null ? void 0 : n.prompt_version,
279
+ promptVersion: (c = e.agent.llm) == null ? void 0 : c.prompt_version,
280
280
  behavior: {
281
281
  role: r == null ? void 0 : r.role,
282
282
  personality: r == null ? void 0 : r.personality,
283
- instructions: (c = e.agent.llm) == null ? void 0 : c.instructions
283
+ instructions: (n = e.agent.llm) == null ? void 0 : n.instructions
284
284
  },
285
- temperature: (i = e.agent.llm) == null ? void 0 : i.temperature,
285
+ temperature: (o = e.agent.llm) == null ? void 0 : o.temperature,
286
286
  knowledgeSource: r == null ? void 0 : r.knowledge_source,
287
287
  starterQuestionsCount: (u = (d = e.agent.knowledge) == null ? void 0 : d.starter_message) == null ? void 0 : u.length,
288
288
  topicsToAvoid: r == null ? void 0 : r.topics_to_avoid,
289
289
  maxResponseLength: r == null ? void 0 : r.max_response_length
290
290
  };
291
291
  return {
292
- ...o,
292
+ ...s,
293
293
  additionalProperties: {},
294
294
  isEnabled: e.isEnabled ?? !0,
295
- getRandom: K,
295
+ getRandom: q,
296
296
  enrich(h) {
297
297
  this.additionalProperties = {
298
298
  ...this.additionalProperties,
299
299
  ...h
300
300
  };
301
301
  },
302
- async track(h, _) {
302
+ async track(h, b) {
303
303
  if (!this.isEnabled)
304
304
  return Promise.resolve();
305
305
  const {
306
- audioPath: k,
307
- ...D
308
- } = _ || {}, R = {
306
+ audioPath: R,
307
+ ...k
308
+ } = b || {}, D = {
309
309
  method: "POST",
310
310
  headers: {
311
311
  "Content-Type": "application/x-www-form-urlencoded"
@@ -315,8 +315,8 @@ function Ne(e) {
315
315
  event: h,
316
316
  properties: {
317
317
  ...this.additionalProperties,
318
- ...D,
319
- ...o,
318
+ ...k,
319
+ ...s,
320
320
  source: t,
321
321
  time: Date.now(),
322
322
  $insert_id: this.getRandom(),
@@ -329,32 +329,32 @@ function Ne(e) {
329
329
  })
330
330
  };
331
331
  try {
332
- return await fetch(Fe, R).then((S) => S.json());
333
- } catch (S) {
334
- return console.error(S);
332
+ return await fetch(Je, D).then((C) => C.json());
333
+ } catch (C) {
334
+ return console.error(C);
335
335
  }
336
336
  },
337
- linkTrack(h, _, k, D) {
338
- Z[h] || (Z[h] = {
337
+ linkTrack(h, b, R, k) {
338
+ G[h] || (G[h] = {
339
339
  events: {},
340
340
  resolvedDependencies: []
341
- }), D.includes(k) || D.push(k);
342
- const R = Z[h];
343
- if (R.events[k] = {
344
- props: _
345
- }, R.resolvedDependencies.push(k), D.every((B) => R.resolvedDependencies.includes(B))) {
346
- const B = D.reduce((l, m) => R.events[m] ? {
347
- ...l,
348
- ...R.events[m].props
349
- } : l, {});
350
- this.track(h, B), R.resolvedDependencies = R.resolvedDependencies.filter((l) => !D.includes(l)), D.forEach((l) => {
351
- delete R.events[l];
341
+ }), k.includes(R) || k.push(R);
342
+ const D = G[h];
343
+ if (D.events[R] = {
344
+ props: b
345
+ }, D.resolvedDependencies.push(R), k.every((L) => D.resolvedDependencies.includes(L))) {
346
+ const L = k.reduce((P, l) => D.events[l] ? {
347
+ ...P,
348
+ ...D.events[l].props
349
+ } : P, {});
350
+ this.track(h, L), D.resolvedDependencies = D.resolvedDependencies.filter((P) => !k.includes(P)), k.forEach((P) => {
351
+ delete D.events[P];
352
352
  });
353
353
  }
354
354
  }
355
355
  };
356
356
  }
357
- function Je() {
357
+ function Ue() {
358
358
  let e = 0;
359
359
  return {
360
360
  reset: () => e = 0,
@@ -362,97 +362,115 @@ function Je() {
362
362
  get: (t = !1) => t ? Date.now() - e : e
363
363
  };
364
364
  }
365
- const F = Je();
366
- function le(e) {
367
- return e === b.Playground ? {
365
+ const J = Ue();
366
+ function fe(e) {
367
+ return e === T.Playground ? {
368
368
  headers: {
369
- [be]: "true"
369
+ [je]: "true"
370
370
  }
371
371
  } : {};
372
372
  }
373
- async function ue(e, t, a, r, o = !1, s) {
373
+ async function me(e, t, a, r, s = !1, i) {
374
374
  try {
375
- return !s && r !== b.DirectPlayback && (s = await t.newChat(e.id, {
376
- persist: o
377
- }, le(r)), a.track("agent-chat", {
375
+ return !i && r !== T.DirectPlayback && (i = await t.newChat(e.id, {
376
+ persist: s
377
+ }, fe(r)), a.track("agent-chat", {
378
378
  event: "created",
379
- chat_id: s.id,
379
+ chat_id: i.id,
380
380
  agent_id: e.id,
381
381
  mode: r
382
382
  })), {
383
- chat: s,
384
- chatMode: (s == null ? void 0 : s.chat_mode) ?? r
383
+ chat: i,
384
+ chatMode: (i == null ? void 0 : i.chat_mode) ?? r
385
385
  };
386
- } catch (n) {
386
+ } catch (c) {
387
387
  try {
388
- const c = JSON.parse(n.message);
389
- if ((c == null ? void 0 : c.kind) === "InsufficientCreditsError")
388
+ const n = JSON.parse(c.message);
389
+ if ((n == null ? void 0 : n.kind) === "InsufficientCreditsError")
390
390
  throw new Error("InsufficientCreditsError");
391
- } catch (c) {
392
- console.error("Error parsing the error message:", c);
391
+ } catch (n) {
392
+ console.error("Error parsing the error message:", n);
393
393
  }
394
394
  throw new Error("Cannot create new chat");
395
395
  }
396
396
  }
397
- function We(e) {
397
+ function Ke(e) {
398
398
  return e && e.length > 0 ? e : [];
399
399
  }
400
- function Ue(e) {
400
+ function He(e, t, a, r, s) {
401
+ if (!e || !t)
402
+ throw new Error("Please connect to the agent first");
403
+ if (!e.interruptEnabled)
404
+ throw new Error("Interrupt is not enabled for this stream");
405
+ if (a !== W.Fluent)
406
+ throw new Error("Interrupt only available for Fluent streams");
407
+ if (!r && !s)
408
+ throw new Error("No active video to interrupt");
409
+ }
410
+ async function ne(e, t) {
411
+ const a = {
412
+ type: x.StreamInterrupt,
413
+ videoId: t,
414
+ timestamp: Date.now()
415
+ };
416
+ e.sendDataChannelMessage(JSON.stringify(a));
417
+ }
418
+ function qe(e) {
401
419
  return new Promise((t, a) => {
402
420
  const {
403
421
  callbacks: r,
404
- host: o,
405
- auth: s
422
+ host: s,
423
+ auth: i
406
424
  } = e, {
407
- onMessage: n = null,
408
- onOpen: c = null,
409
- onClose: i = null,
425
+ onMessage: c = null,
426
+ onOpen: n = null,
427
+ onClose: o = null,
410
428
  onError: d = null
411
- } = r || {}, u = new WebSocket(`${o}?authorization=${oe(s)}`);
412
- u.onmessage = n, u.onclose = i, u.onerror = (h) => {
429
+ } = r || {}, u = new WebSocket(`${s}?authorization=${de(i)}`);
430
+ u.onmessage = c, u.onclose = o, u.onerror = (h) => {
413
431
  console.error(h), d == null || d("Websocket failed to connect", h), a(h);
414
432
  }, u.onopen = (h) => {
415
- c == null || c(h), t(u);
433
+ n == null || n(h), t(u);
416
434
  };
417
435
  });
418
436
  }
419
- async function Ke(e) {
437
+ async function Ve(e) {
420
438
  const {
421
439
  retries: t = 1
422
440
  } = e;
423
441
  let a = null;
424
442
  for (let r = 0; (a == null ? void 0 : a.readyState) !== WebSocket.OPEN; r++)
425
443
  try {
426
- a = await Ue(e);
427
- } catch (o) {
444
+ a = await qe(e);
445
+ } catch (s) {
428
446
  if (r === t)
429
- throw o;
430
- await ie(r * 500);
447
+ throw s;
448
+ await oe(r * 500);
431
449
  }
432
450
  return a;
433
451
  }
434
- async function He(e, t, a) {
435
- const r = a != null && a.onMessage ? [a.onMessage] : [], o = await Ke({
452
+ async function Xe(e, t, a) {
453
+ const r = a != null && a.onMessage ? [a.onMessage] : [], s = await Ve({
436
454
  auth: e,
437
455
  host: t,
438
456
  callbacks: {
439
- onError: (s) => {
440
- var n;
441
- return (n = a.onError) == null ? void 0 : n.call(a, new pe(s));
457
+ onError: (i) => {
458
+ var c;
459
+ return (c = a.onError) == null ? void 0 : c.call(a, new ve(i));
442
460
  },
443
- onMessage(s) {
444
- const n = JSON.parse(s.data);
445
- r.forEach((c) => c(n.event, n));
461
+ onMessage(i) {
462
+ const c = JSON.parse(i.data);
463
+ r.forEach((n) => n(c.event, c));
446
464
  }
447
465
  }
448
466
  });
449
467
  return {
450
- socket: o,
451
- disconnect: () => o.close(),
452
- subscribeToEvents: (s) => r.push(s)
468
+ socket: s,
469
+ disconnect: () => s.close(),
470
+ subscribeToEvents: (i) => r.push(i)
453
471
  };
454
472
  }
455
- function qe(e) {
473
+ function Ye(e) {
456
474
  if (e.answer !== void 0)
457
475
  return e.answer;
458
476
  let t = 0, a = "";
@@ -460,130 +478,130 @@ function qe(e) {
460
478
  a += e[t++];
461
479
  return a;
462
480
  }
463
- function Ve(e, t, a, r, o) {
464
- const s = r.messages[r.messages.length - 1];
465
- if (!(e === U.Partial || e === U.Answer) || (s == null ? void 0 : s.role) !== "assistant")
481
+ function Qe(e, t, a, r, s) {
482
+ const i = r.messages[r.messages.length - 1];
483
+ if (!(e === H.Partial || e === H.Answer) || (i == null ? void 0 : i.role) !== "assistant")
466
484
  return;
467
485
  const {
468
- content: n,
469
- sequence: c
486
+ content: c,
487
+ sequence: n
470
488
  } = t;
471
- e === U.Partial ? a[c] = n : a.answer = n;
472
- const i = qe(a);
473
- (s.content !== i || e === U.Answer) && (s.content = i, o == null || o([...r.messages], e));
489
+ e === H.Partial ? a[n] = c : a.answer = c;
490
+ const o = Ye(a);
491
+ (i.content !== o || e === H.Answer) && (i.content = o, s == null || s([...r.messages], e));
474
492
  }
475
- function Xe(e, t, a, r, o) {
476
- let s = {};
493
+ function Ze(e, t, a, r, s) {
494
+ let i = {};
477
495
  return {
478
- clearQueue: () => s = {},
479
- onMessage: (n, c) => {
480
- var i, d;
481
- if ("content" in c)
482
- Ve(n, c, s, t, a.callbacks.onNewMessage), n === U.Answer && e.track("agent-message-received", {
496
+ clearQueue: () => i = {},
497
+ onMessage: (c, n) => {
498
+ var o, d;
499
+ if ("content" in n)
500
+ Qe(c, n, i, t, a.callbacks.onNewMessage), c === H.Answer && e.track("agent-message-received", {
483
501
  messages: t.messages.length,
484
502
  mode: t.chatMode
485
503
  });
486
504
  else {
487
- const u = N, h = [u.StreamVideoDone, u.StreamVideoError, u.StreamVideoRejected], _ = [u.StreamFailed, u.StreamVideoError, u.StreamVideoRejected], k = xe(c, r, {
505
+ const u = x, h = [u.StreamVideoDone, u.StreamVideoError, u.StreamVideoRejected], b = [u.StreamFailed, u.StreamVideoError, u.StreamVideoRejected], R = xe(n, r, {
488
506
  mode: t.chatMode
489
507
  });
490
- if (n = n, n === u.StreamVideoCreated)
491
- e.linkTrack("agent-video", k, u.StreamVideoCreated, ["start"]);
492
- else if (h.includes(n)) {
493
- const D = n.split("/")[1];
494
- _.includes(n) ? e.track("agent-video", {
495
- ...k,
496
- event: D
508
+ if (c = c, c === u.StreamVideoCreated)
509
+ e.linkTrack("agent-video", R, u.StreamVideoCreated, ["start"]);
510
+ else if (h.includes(c)) {
511
+ const k = c.split("/")[1];
512
+ b.includes(c) ? e.track("agent-video", {
513
+ ...R,
514
+ event: k
497
515
  }) : e.linkTrack("agent-video", {
498
- ...k,
499
- event: D
500
- }, n, ["done"]);
516
+ ...R,
517
+ event: k
518
+ }, c, ["done"]);
501
519
  }
502
- _.includes(n) && ((d = (i = a.callbacks).onError) == null || d.call(i, new Error(`Stream failed with event ${n}`), {
503
- data: c
504
- })), c.event === u.StreamDone && o();
520
+ b.includes(c) && ((d = (o = a.callbacks).onError) == null || d.call(o, new Error(`Stream failed with event ${c}`), {
521
+ data: n
522
+ })), n.event === u.StreamDone && s();
505
523
  }
506
524
  }
507
525
  };
508
526
  }
509
- function Ye(e, t, a, r) {
510
- const o = ee(e, `${t}/agents/${a}`, r);
527
+ function Ge(e, t, a, r) {
528
+ const s = te(e, `${t}/agents/${a}`, r);
511
529
  return {
512
- createStream(s) {
513
- return o.post("/streams", {
514
- output_resolution: s.output_resolution,
515
- compatibility_mode: s.compatibility_mode,
516
- stream_warmup: s.stream_warmup,
517
- session_timeout: s.session_timeout,
518
- fluent: s.fluent
519
- });
520
- },
521
- startConnection(s, n, c) {
522
- return o.post(`/streams/${s}/sdp`, {
523
- session_id: c,
524
- answer: n
530
+ createStream(i) {
531
+ return s.post("/streams", {
532
+ output_resolution: i.output_resolution,
533
+ compatibility_mode: i.compatibility_mode,
534
+ stream_warmup: i.stream_warmup,
535
+ session_timeout: i.session_timeout,
536
+ fluent: i.fluent
525
537
  });
526
538
  },
527
- addIceCandidate(s, n, c) {
528
- return o.post(`/streams/${s}/ice`, {
529
- session_id: c,
530
- ...n
539
+ startConnection(i, c, n) {
540
+ return s.post(`/streams/${i}/sdp`, {
541
+ session_id: n,
542
+ answer: c
531
543
  });
532
544
  },
533
- sendStreamRequest(s, n, c) {
534
- return o.post(`/streams/${s}`, {
545
+ addIceCandidate(i, c, n) {
546
+ return s.post(`/streams/${i}/ice`, {
535
547
  session_id: n,
536
548
  ...c
537
549
  });
538
550
  },
539
- close(s, n) {
540
- return o.delete(`/streams/${s}`, {
541
- session_id: n
551
+ sendStreamRequest(i, c, n) {
552
+ return s.post(`/streams/${i}`, {
553
+ session_id: c,
554
+ ...n
555
+ });
556
+ },
557
+ close(i, c) {
558
+ return s.delete(`/streams/${i}`, {
559
+ session_id: c
542
560
  });
543
561
  }
544
562
  };
545
563
  }
546
- function Qe(e, t, a, r) {
547
- const o = ee(e, `${t}/agents/${a}`, r);
564
+ function Oe(e, t, a, r) {
565
+ const s = te(e, `${t}/agents/${a}`, r);
548
566
  return {
549
- createStream(s, n) {
550
- return o.post("/streams", {
551
- driver_url: s.driver_url,
552
- face: s.face,
553
- config: s.config,
554
- output_resolution: s.output_resolution,
555
- compatibility_mode: s.compatibility_mode,
556
- stream_warmup: s.stream_warmup,
557
- session_timeout: s.session_timeout,
558
- fluent: s.fluent
559
- }, n);
560
- },
561
- startConnection(s, n, c, i) {
562
- return o.post(`/streams/${s}/sdp`, {
563
- session_id: c,
564
- answer: n
565
- }, i);
567
+ createStream(i, c) {
568
+ return s.post("/streams", {
569
+ driver_url: i.driver_url,
570
+ face: i.face,
571
+ config: i.config,
572
+ output_resolution: i.output_resolution,
573
+ compatibility_mode: i.compatibility_mode,
574
+ stream_warmup: i.stream_warmup,
575
+ session_timeout: i.session_timeout,
576
+ fluent: i.fluent
577
+ }, c);
566
578
  },
567
- addIceCandidate(s, n, c, i) {
568
- return o.post(`/streams/${s}/ice`, {
569
- session_id: c,
570
- ...n
571
- }, i);
579
+ startConnection(i, c, n, o) {
580
+ return s.post(`/streams/${i}/sdp`, {
581
+ session_id: n,
582
+ answer: c
583
+ }, o);
572
584
  },
573
- sendStreamRequest(s, n, c, i) {
574
- return o.post(`/streams/${s}`, {
585
+ addIceCandidate(i, c, n, o) {
586
+ return s.post(`/streams/${i}/ice`, {
575
587
  session_id: n,
576
588
  ...c
577
- }, i);
589
+ }, o);
578
590
  },
579
- close(s, n, c) {
580
- return o.delete(`/streams/${s}`, {
581
- session_id: n
582
- }, c);
591
+ sendStreamRequest(i, c, n, o) {
592
+ return s.post(`/streams/${i}`, {
593
+ session_id: c,
594
+ ...n
595
+ }, o);
596
+ },
597
+ close(i, c, n) {
598
+ return s.delete(`/streams/${i}`, {
599
+ session_id: c
600
+ }, n);
583
601
  }
584
602
  };
585
603
  }
586
- function Ze(e, t, a) {
604
+ function et(e, t, a) {
587
605
  const r = (t.timestamp - e.timestamp) / 1e3;
588
606
  return {
589
607
  duration: r,
@@ -603,19 +621,19 @@ function Ze(e, t, a) {
603
621
  lowFpsCount: a
604
622
  };
605
623
  }
606
- function Ge(e) {
624
+ function tt(e) {
607
625
  return e.filter((t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0).map((t) => {
608
626
  const {
609
627
  timestamp: a,
610
628
  ...r
611
- } = t, o = [];
612
- return t.freezeCount > 0 && o.push("freeze"), t.framesPerSecond < 21 && o.push("low fps"), t.framesDropped > 0 && o.push("frames dropped"), t.packetsLost > 0 && o.push("packet loss"), {
629
+ } = t, s = [];
630
+ return t.freezeCount > 0 && s.push("freeze"), t.framesPerSecond < 21 && s.push("low fps"), t.framesDropped > 0 && s.push("frames dropped"), t.packetsLost > 0 && s.push("packet loss"), {
613
631
  ...r,
614
- causes: o
632
+ causes: s
615
633
  };
616
634
  });
617
635
  }
618
- function Oe(e) {
636
+ function rt(e) {
619
637
  let t = "", a = 0;
620
638
  for (const r of e.values())
621
639
  if (r && r.type === "codec" && r.mimeType.startsWith("video") && (t = r.mimeType.split("/")[1]), r && r.type === "candidate-pair" && (a = r.currentRoundTripTime), r && r.type === "inbound-rtp" && r.kind === "video")
@@ -640,91 +658,91 @@ function Oe(e) {
640
658
  };
641
659
  return {};
642
660
  }
643
- function et(e, t, a) {
644
- const r = e.map((i, d) => d === 0 ? a ? {
645
- timestamp: i.timestamp,
661
+ function nt(e, t, a) {
662
+ const r = e.map((o, d) => d === 0 ? a ? {
663
+ timestamp: o.timestamp,
646
664
  duration: 0,
647
- rtt: i.rtt,
648
- bytesReceived: i.bytesReceived - a.bytesReceived,
649
- bitrate: (i.bytesReceived - a.bytesReceived) * 8 / (t / 1e3),
650
- packetsReceived: i.packetsReceived - a.packetsReceived,
651
- packetsLost: i.packetsLost - a.packetsLost,
652
- framesDropped: i.framesDropped - a.framesDropped,
653
- framesDecoded: i.framesDecoded - a.framesDecoded,
654
- jitter: i.jitter,
655
- jitterBufferDelay: i.jitterBufferDelay - a.jitterBufferDelay,
656
- jitterBufferEmittedCount: i.jitterBufferEmittedCount - a.jitterBufferEmittedCount,
657
- avgJitterDelayInInterval: (i.jitterBufferDelay - a.jitterBufferDelay) / (i.jitterBufferEmittedCount - a.jitterBufferEmittedCount),
658
- framesPerSecond: i.framesPerSecond,
659
- freezeCount: i.freezeCount - a.freezeCount,
660
- freezeDuration: i.freezeDuration - a.freezeDuration
665
+ rtt: o.rtt,
666
+ bytesReceived: o.bytesReceived - a.bytesReceived,
667
+ bitrate: (o.bytesReceived - a.bytesReceived) * 8 / (t / 1e3),
668
+ packetsReceived: o.packetsReceived - a.packetsReceived,
669
+ packetsLost: o.packetsLost - a.packetsLost,
670
+ framesDropped: o.framesDropped - a.framesDropped,
671
+ framesDecoded: o.framesDecoded - a.framesDecoded,
672
+ jitter: o.jitter,
673
+ jitterBufferDelay: o.jitterBufferDelay - a.jitterBufferDelay,
674
+ jitterBufferEmittedCount: o.jitterBufferEmittedCount - a.jitterBufferEmittedCount,
675
+ avgJitterDelayInInterval: (o.jitterBufferDelay - a.jitterBufferDelay) / (o.jitterBufferEmittedCount - a.jitterBufferEmittedCount),
676
+ framesPerSecond: o.framesPerSecond,
677
+ freezeCount: o.freezeCount - a.freezeCount,
678
+ freezeDuration: o.freezeDuration - a.freezeDuration
661
679
  } : {
662
- timestamp: i.timestamp,
663
- rtt: i.rtt,
680
+ timestamp: o.timestamp,
681
+ rtt: o.rtt,
664
682
  duration: 0,
665
- bytesReceived: i.bytesReceived,
666
- bitrate: i.bytesReceived * 8 / (t / 1e3),
667
- packetsReceived: i.packetsReceived,
668
- packetsLost: i.packetsLost,
669
- framesDropped: i.framesDropped,
670
- framesDecoded: i.framesDecoded,
671
- jitter: i.jitter,
672
- jitterBufferDelay: i.jitterBufferDelay,
673
- jitterBufferEmittedCount: i.jitterBufferEmittedCount,
674
- avgJitterDelayInInterval: i.jitterBufferDelay / i.jitterBufferEmittedCount,
675
- framesPerSecond: i.framesPerSecond,
676
- freezeCount: i.freezeCount,
677
- freezeDuration: i.freezeDuration
683
+ bytesReceived: o.bytesReceived,
684
+ bitrate: o.bytesReceived * 8 / (t / 1e3),
685
+ packetsReceived: o.packetsReceived,
686
+ packetsLost: o.packetsLost,
687
+ framesDropped: o.framesDropped,
688
+ framesDecoded: o.framesDecoded,
689
+ jitter: o.jitter,
690
+ jitterBufferDelay: o.jitterBufferDelay,
691
+ jitterBufferEmittedCount: o.jitterBufferEmittedCount,
692
+ avgJitterDelayInInterval: o.jitterBufferDelay / o.jitterBufferEmittedCount,
693
+ framesPerSecond: o.framesPerSecond,
694
+ freezeCount: o.freezeCount,
695
+ freezeDuration: o.freezeDuration
678
696
  } : {
679
- timestamp: i.timestamp,
697
+ timestamp: o.timestamp,
680
698
  duration: t * d / 1e3,
681
- rtt: i.rtt,
682
- bytesReceived: i.bytesReceived - e[d - 1].bytesReceived,
683
- bitrate: (i.bytesReceived - e[d - 1].bytesReceived) * 8 / (t / 1e3),
684
- packetsReceived: i.packetsReceived - e[d - 1].packetsReceived,
685
- packetsLost: i.packetsLost - e[d - 1].packetsLost,
686
- framesDropped: i.framesDropped - e[d - 1].framesDropped,
687
- framesDecoded: i.framesDecoded - e[d - 1].framesDecoded,
688
- jitter: i.jitter,
689
- jitterBufferDelay: i.jitterBufferDelay - e[d - 1].jitterBufferDelay,
690
- jitterBufferEmittedCount: i.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount,
691
- avgJitterDelayInInterval: (i.jitterBufferDelay - e[d - 1].jitterBufferDelay) / (i.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount),
692
- framesPerSecond: i.framesPerSecond,
693
- freezeCount: i.freezeCount - e[d - 1].freezeCount,
694
- freezeDuration: i.freezeDuration - e[d - 1].freezeDuration
695
- }), o = Ge(r), s = o.reduce((i, d) => i + (d.causes.includes("low fps") ? 1 : 0), 0), n = r.filter((i) => !!i.avgJitterDelayInInterval).map((i) => i.avgJitterDelayInInterval), c = r.filter((i) => !!i.rtt).map((i) => i.rtt);
699
+ rtt: o.rtt,
700
+ bytesReceived: o.bytesReceived - e[d - 1].bytesReceived,
701
+ bitrate: (o.bytesReceived - e[d - 1].bytesReceived) * 8 / (t / 1e3),
702
+ packetsReceived: o.packetsReceived - e[d - 1].packetsReceived,
703
+ packetsLost: o.packetsLost - e[d - 1].packetsLost,
704
+ framesDropped: o.framesDropped - e[d - 1].framesDropped,
705
+ framesDecoded: o.framesDecoded - e[d - 1].framesDecoded,
706
+ jitter: o.jitter,
707
+ jitterBufferDelay: o.jitterBufferDelay - e[d - 1].jitterBufferDelay,
708
+ jitterBufferEmittedCount: o.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount,
709
+ avgJitterDelayInInterval: (o.jitterBufferDelay - e[d - 1].jitterBufferDelay) / (o.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount),
710
+ framesPerSecond: o.framesPerSecond,
711
+ freezeCount: o.freezeCount - e[d - 1].freezeCount,
712
+ freezeDuration: o.freezeDuration - e[d - 1].freezeDuration
713
+ }), s = tt(r), i = s.reduce((o, d) => o + (d.causes.includes("low fps") ? 1 : 0), 0), c = r.filter((o) => !!o.avgJitterDelayInInterval).map((o) => o.avgJitterDelayInInterval), n = r.filter((o) => !!o.rtt).map((o) => o.rtt);
696
714
  return {
697
715
  webRTCStats: {
698
- anomalies: o,
699
- minRtt: Math.min(...c),
700
- avgRtt: te(c),
701
- maxRtt: Math.max(...c),
702
- aggregateReport: Ze(e[0], e[e.length - 1], s),
703
- minJitterDelayInInterval: Math.min(...n),
704
- maxJitterDelayInInterval: Math.max(...n),
705
- avgJitterDelayInInterval: te(n)
716
+ anomalies: s,
717
+ minRtt: Math.min(...n),
718
+ avgRtt: re(n),
719
+ maxRtt: Math.max(...n),
720
+ aggregateReport: et(e[0], e[e.length - 1], i),
721
+ minJitterDelayInInterval: Math.min(...c),
722
+ maxJitterDelayInInterval: Math.max(...c),
723
+ avgJitterDelayInInterval: re(c)
706
724
  },
707
725
  codec: e[0].codec,
708
726
  resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
709
727
  };
710
728
  }
711
- const O = 100, tt = Math.max(Math.ceil(400 / O), 1), rt = 0.25, nt = 0.28;
712
- function at() {
729
+ const ee = 100, at = Math.max(Math.ceil(400 / ee), 1), it = 0.25, st = 0.28;
730
+ function ot() {
713
731
  let e = 0, t, a, r = 0;
714
- return (o) => {
715
- for (const s of o.values())
716
- if (s && s.type === "inbound-rtp" && s.kind === "video") {
717
- const n = s.jitterBufferDelay, c = s.jitterBufferEmittedCount;
718
- if (a && c > a) {
719
- const u = n - t, h = c - a;
732
+ return (s) => {
733
+ for (const i of s.values())
734
+ if (i && i.type === "inbound-rtp" && i.kind === "video") {
735
+ const c = i.jitterBufferDelay, n = i.jitterBufferEmittedCount;
736
+ if (a && n > a) {
737
+ const u = c - t, h = n - a;
720
738
  r = u / h;
721
739
  }
722
- t = n, a = c;
723
- const i = s.framesDecoded, d = i - e > 0;
724
- return e = i, {
740
+ t = c, a = n;
741
+ const o = i.framesDecoded, d = o - e > 0;
742
+ return e = o, {
725
743
  isReceiving: d,
726
744
  avgJitterDelayInInterval: r,
727
- freezeCount: s.freezeCount
745
+ freezeCount: i.freezeCount
728
746
  };
729
747
  }
730
748
  return {
@@ -733,50 +751,50 @@ function at() {
733
751
  };
734
752
  };
735
753
  }
736
- function it(e, t, a, r, o, s = !1) {
737
- let n = [], c, i = 0, d = !1, u = V.Unknown, h = V.Unknown, _ = 0, k = 0;
738
- const D = at();
754
+ function ct(e, t, a, r, s, i = !1) {
755
+ let c = [], n, o = 0, d = !1, u = X.Unknown, h = X.Unknown, b = 0, R = 0;
756
+ const k = ot();
739
757
  return setInterval(async () => {
740
- const R = await e.getStats(), {
741
- isReceiving: S,
742
- avgJitterDelayInInterval: B,
743
- freezeCount: l
744
- } = D(R), m = Oe(R);
745
- if (S)
746
- i = 0, _ = l - k, h = B < rt ? V.Strong : B > nt && _ > 1 ? V.Weak : u, h !== u && (o == null || o(h), u = h, k += _, _ = 0), d || (r == null || r(p.Start), c = n[n.length - 1], n = [], d = !0), n.push(m);
747
- else if (d && (i++, i >= tt)) {
748
- const y = et(n, O, c);
749
- r == null || r(p.Stop, y), t() || a(), k = l, d = !1;
758
+ const D = await e.getStats(), {
759
+ isReceiving: C,
760
+ avgJitterDelayInInterval: L,
761
+ freezeCount: P
762
+ } = k(D), l = rt(D);
763
+ if (C)
764
+ o = 0, b = P - R, h = L < it ? X.Strong : L > st && b > 1 ? X.Weak : u, h !== u && (s == null || s(h), u = h, R += b, b = 0), d || (r == null || r(p.Start), n = c[c.length - 1], c = [], d = !0), c.push(l);
765
+ else if (d && (o++, o >= at)) {
766
+ const w = nt(c, ee, n);
767
+ r == null || r(p.Stop, w), t() || a(), R = P, d = !1;
750
768
  }
751
- }, O);
769
+ }, ee);
752
770
  }
753
- let fe = !1;
754
- const x = (e, t) => fe && console.log(e, t), st = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
755
- function re(e) {
771
+ let ge = !1;
772
+ const $ = (e, t) => ge && console.log(e, t), dt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
773
+ function ae(e) {
756
774
  switch (e) {
757
775
  case "connected":
758
- return M.Connected;
776
+ return _.Connected;
759
777
  case "checking":
760
- return M.Connecting;
778
+ return _.Connecting;
761
779
  case "failed":
762
- return M.Fail;
780
+ return _.Fail;
763
781
  case "new":
764
- return M.New;
782
+ return _.New;
765
783
  case "closed":
766
- return M.Closed;
784
+ return _.Closed;
767
785
  case "disconnected":
768
- return M.Disconnected;
786
+ return _.Disconnected;
769
787
  case "completed":
770
- return M.Completed;
788
+ return _.Completed;
771
789
  default:
772
- return M.New;
790
+ return _.New;
773
791
  }
774
792
  }
775
- function ot(e) {
793
+ function lt(e) {
776
794
  const [t, a = ""] = e.split(/:(.+)/);
777
795
  try {
778
796
  const r = JSON.parse(a);
779
- return x("parsed data channel message", {
797
+ return $("parsed data channel message", {
780
798
  subject: t,
781
799
  data: r
782
800
  }), {
@@ -784,7 +802,7 @@ function ot(e) {
784
802
  data: r
785
803
  };
786
804
  } catch (r) {
787
- return x("Failed to parse data channel message, returning data as string", {
805
+ return $("Failed to parse data channel message, returning data as string", {
788
806
  subject: t,
789
807
  rawData: a,
790
808
  error: r
@@ -794,7 +812,7 @@ function ot(e) {
794
812
  };
795
813
  }
796
814
  }
797
- function ct({
815
+ function ut({
798
816
  statsSignal: e,
799
817
  dataChannelSignal: t,
800
818
  onVideoStateChange: a,
@@ -802,186 +820,207 @@ function ct({
802
820
  }) {
803
821
  e === p.Start && t === p.Start ? a == null || a(p.Start) : e === p.Stop && t === p.Stop && (a == null || a(p.Stop, r));
804
822
  }
805
- function dt({
823
+ function ft({
806
824
  statsSignal: e,
807
825
  dataChannelSignal: t,
808
826
  onVideoStateChange: a,
809
827
  onAgentActivityStateChange: r,
810
- report: o
828
+ report: s
811
829
  }) {
812
- e === p.Start ? a == null || a(p.Start) : e === p.Stop && (a == null || a(p.Stop, o)), t === p.Start ? r == null || r(X.Talking) : t === p.Stop && (r == null || r(X.Idle));
830
+ e === p.Start ? a == null || a(p.Start) : e === p.Stop && (a == null || a(p.Stop, s)), t === p.Start ? r == null || r(Y.Talking) : t === p.Stop && (r == null || r(Y.Idle));
813
831
  }
814
- function ne({
832
+ function ie({
815
833
  statsSignal: e,
816
834
  dataChannelSignal: t,
817
835
  onVideoStateChange: a,
818
836
  onAgentActivityStateChange: r,
819
- streamType: o,
820
- report: s
837
+ streamType: s,
838
+ report: i
821
839
  }) {
822
- o === J.Legacy ? ct({
840
+ s === W.Legacy ? ut({
823
841
  statsSignal: e,
824
842
  dataChannelSignal: t,
825
843
  onVideoStateChange: a,
826
- report: s
827
- }) : o === J.Fluent && dt({
844
+ report: i
845
+ }) : s === W.Fluent && ft({
828
846
  statsSignal: e,
829
847
  dataChannelSignal: t,
830
848
  onVideoStateChange: a,
831
849
  onAgentActivityStateChange: r,
832
- report: s
850
+ report: i
833
851
  });
834
852
  }
835
- async function lt(e, t, {
853
+ async function mt(e, t, {
836
854
  debug: a = !1,
837
855
  callbacks: r,
838
- auth: o,
839
- baseURL: s = Y,
840
- analytics: n
856
+ auth: s,
857
+ baseURL: i = Q,
858
+ analytics: c
841
859
  }) {
842
- fe = a;
843
- let c = !1, i = !1, d = p.Stop, u = p.Stop;
860
+ ge = a;
861
+ let n = !1, o = !1, d = p.Stop, u = p.Stop;
844
862
  const {
845
863
  startConnection: h,
846
- sendStreamRequest: _,
847
- close: k,
848
- createStream: D,
849
- addIceCandidate: R
850
- } = t.videoType === ae.Clip ? Ye(o, s, e, r.onError) : Qe(o, s, e, r.onError), {
851
- id: S,
852
- offer: B,
853
- ice_servers: l,
854
- session_id: m,
855
- fluent: y
856
- } = await D(t), w = new st({
857
- iceServers: l
858
- }), T = w.createDataChannel("JanusDataChannel");
859
- if (!m)
864
+ sendStreamRequest: b,
865
+ close: R,
866
+ createStream: k,
867
+ addIceCandidate: D
868
+ } = t.videoType === se.Clip ? Ge(s, i, e, r.onError) : Oe(s, i, e, r.onError), {
869
+ id: C,
870
+ offer: L,
871
+ ice_servers: P,
872
+ session_id: l,
873
+ fluent: w,
874
+ interrupt_enabled: y
875
+ } = await k(t), g = new dt({
876
+ iceServers: P
877
+ }), E = g.createDataChannel("JanusDataChannel");
878
+ if (!l)
860
879
  throw new Error("Could not create session_id");
861
- const v = y ? J.Fluent : J.Legacy;
862
- n.enrich({
880
+ const v = w ? W.Fluent : W.Legacy;
881
+ c.enrich({
863
882
  "stream-type": v
864
883
  });
865
- const j = t.stream_warmup && !y, P = () => c, $ = () => {
884
+ const A = t.stream_warmup && !w, B = () => n, z = () => {
866
885
  var f;
867
- c = !0, i && ((f = r.onConnectionStateChange) == null || f.call(r, M.Connected));
868
- }, C = it(w, P, $, (f, g) => ne({
886
+ n = !0, o && ((f = r.onConnectionStateChange) == null || f.call(r, _.Connected));
887
+ }, S = ct(g, B, z, (f, m) => ie({
869
888
  statsSignal: u = f,
870
- dataChannelSignal: v === J.Legacy ? d : void 0,
889
+ dataChannelSignal: v === W.Legacy ? d : void 0,
871
890
  onVideoStateChange: r.onVideoStateChange,
872
891
  onAgentActivityStateChange: r.onAgentActivityStateChange,
873
- report: g,
892
+ report: m,
874
893
  streamType: v
875
894
  }), (f) => {
876
- var g;
877
- return (g = r.onConnectivityStateChange) == null ? void 0 : g.call(r, f);
878
- }, j);
879
- w.onicecandidate = (f) => {
880
- var g;
881
- x("peerConnection.onicecandidate", f);
895
+ var m;
896
+ return (m = r.onConnectivityStateChange) == null ? void 0 : m.call(r, f);
897
+ }, A);
898
+ g.onicecandidate = (f) => {
899
+ var m;
900
+ $("peerConnection.onicecandidate", f);
882
901
  try {
883
- f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? R(S, {
902
+ f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? D(C, {
884
903
  candidate: f.candidate.candidate,
885
904
  sdpMid: f.candidate.sdpMid,
886
905
  sdpMLineIndex: f.candidate.sdpMLineIndex
887
- }, m) : R(S, {
906
+ }, l) : D(C, {
888
907
  candidate: null
889
- }, m);
890
- } catch (A) {
891
- (g = r.onError) == null || g.call(r, A, {
892
- streamId: S
908
+ }, l);
909
+ } catch (j) {
910
+ (m = r.onError) == null || m.call(r, j, {
911
+ streamId: C
893
912
  });
894
913
  }
895
- }, T.onopen = () => {
896
- i = !0, (!j || c) && $();
914
+ }, E.onopen = () => {
915
+ o = !0, (!A || n) && z();
897
916
  };
898
917
  function I(f) {
899
- d = f === N.StreamStarted ? p.Start : p.Stop, ne({
900
- statsSignal: v === J.Legacy ? u : void 0,
918
+ d = f === x.StreamStarted ? p.Start : p.Stop, ie({
919
+ statsSignal: v === W.Legacy ? u : void 0,
901
920
  dataChannelSignal: d,
902
921
  onVideoStateChange: r.onVideoStateChange,
903
922
  onAgentActivityStateChange: r.onAgentActivityStateChange,
904
923
  streamType: v
905
924
  });
906
925
  }
907
- function E(f, g) {
908
- const A = typeof g == "string" ? g : g == null ? void 0 : g.metadata;
909
- A && n.enrich({
910
- streamMetadata: A
911
- }), n.track("agent-chat", {
926
+ function M(f, m) {
927
+ const j = typeof m == "string" ? m : m == null ? void 0 : m.metadata;
928
+ j && c.enrich({
929
+ streamMetadata: j
930
+ }), c.track("agent-chat", {
912
931
  event: "ready"
913
932
  });
914
933
  }
915
- const L = {
916
- [N.StreamStarted]: I,
917
- [N.StreamDone]: I,
918
- [N.StreamReady]: E
934
+ const N = {
935
+ [x.StreamStarted]: I,
936
+ [x.StreamDone]: I,
937
+ [x.StreamReady]: M
919
938
  };
920
- T.onmessage = (f) => {
921
- var H;
939
+ E.onmessage = (f) => {
940
+ var U;
922
941
  const {
923
- subject: g,
924
- data: A
925
- } = ot(f.data);
926
- (H = L[g]) == null || H.call(L, g, A);
927
- }, w.oniceconnectionstatechange = () => {
928
- var g;
929
- x("peerConnection.oniceconnectionstatechange => " + w.iceConnectionState);
930
- const f = re(w.iceConnectionState);
931
- f !== M.Connected && ((g = r.onConnectionStateChange) == null || g.call(r, f));
932
- }, w.ontrack = (f) => {
933
- var g;
934
- x("peerConnection.ontrack", f), (g = r.onSrcObjectReady) == null || g.call(r, f.streams[0]);
935
- }, await w.setRemoteDescription(B), x("set remote description OK");
936
- const z = await w.createAnswer();
937
- return x("create answer OK"), await w.setLocalDescription(z), x("set local description OK"), await h(S, z, m), x("start connection OK"), {
942
+ subject: m,
943
+ data: j
944
+ } = lt(f.data);
945
+ (U = N[m]) == null || U.call(N, m, j);
946
+ }, g.oniceconnectionstatechange = () => {
947
+ var m;
948
+ $("peerConnection.oniceconnectionstatechange => " + g.iceConnectionState);
949
+ const f = ae(g.iceConnectionState);
950
+ f !== _.Connected && ((m = r.onConnectionStateChange) == null || m.call(r, f));
951
+ }, g.ontrack = (f) => {
952
+ var m;
953
+ $("peerConnection.ontrack", f), (m = r.onSrcObjectReady) == null || m.call(r, f.streams[0]);
954
+ }, await g.setRemoteDescription(L), $("set remote description OK");
955
+ const F = await g.createAnswer();
956
+ return $("create answer OK"), await g.setLocalDescription(F), $("set local description OK"), await h(C, F, l), $("start connection OK"), {
938
957
  /**
939
958
  * Method to send request to server to get clip or talk depend on you payload
940
959
  * @param payload
941
960
  */
942
961
  speak(f) {
943
- return _(S, m, f);
962
+ return b(C, l, f);
944
963
  },
945
964
  /**
946
965
  * Method to close RTC connection
947
966
  */
948
967
  async disconnect() {
949
968
  var f;
950
- if (S) {
951
- const g = re(w.iceConnectionState);
952
- if (w) {
953
- if (g === M.New) {
954
- clearInterval(C);
969
+ if (C) {
970
+ const m = ae(g.iceConnectionState);
971
+ if (g) {
972
+ if (m === _.New) {
973
+ clearInterval(S);
955
974
  return;
956
975
  }
957
- w.close(), w.oniceconnectionstatechange = null, w.onnegotiationneeded = null, w.onicecandidate = null, w.ontrack = null;
976
+ g.close(), g.oniceconnectionstatechange = null, g.onnegotiationneeded = null, g.onicecandidate = null, g.ontrack = null;
958
977
  }
959
978
  try {
960
- g === M.Connected && await k(S, m).catch((A) => {
979
+ m === _.Connected && await R(C, l).catch((j) => {
961
980
  });
962
- } catch (A) {
963
- x("Error on close stream connection", A);
981
+ } catch (j) {
982
+ $("Error on close stream connection", j);
964
983
  }
965
- (f = r.onAgentActivityStateChange) == null || f.call(r, X.Idle), clearInterval(C);
984
+ (f = r.onAgentActivityStateChange) == null || f.call(r, Y.Idle), clearInterval(S);
985
+ }
986
+ },
987
+ /**
988
+ * Method to send data channel messages to the server
989
+ */
990
+ sendDataChannelMessage(f) {
991
+ var m, j;
992
+ if (!n || E.readyState !== "open") {
993
+ $("Data channel is not ready for sending messages"), (m = r.onError) == null || m.call(r, new Error("Data channel is not ready for sending messages"), {
994
+ streamId: C
995
+ });
996
+ return;
997
+ }
998
+ try {
999
+ E.send(f);
1000
+ } catch (U) {
1001
+ $("Error sending data channel message", U), (j = r.onError) == null || j.call(r, U, {
1002
+ streamId: C
1003
+ });
966
1004
  }
967
1005
  },
968
1006
  /**
969
1007
  * Session identifier information, should be returned in the body of all streaming requests
970
1008
  */
971
- sessionId: m,
1009
+ sessionId: l,
972
1010
  /**
973
1011
  * Id of current RTC stream
974
1012
  */
975
- streamId: S,
976
- streamType: v
1013
+ streamId: C,
1014
+ streamType: v,
1015
+ interruptEnabled: y
977
1016
  };
978
1017
  }
979
- function ut(e, t) {
1018
+ function gt(e, t) {
980
1019
  const {
981
1020
  streamOptions: a
982
1021
  } = t ?? {};
983
1022
  return {
984
- videoType: Ee(e.presenter.type),
1023
+ videoType: Me(e.presenter.type),
985
1024
  output_resolution: a == null ? void 0 : a.outputResolution,
986
1025
  session_timeout: a == null ? void 0 : a.sessionTimeout,
987
1026
  stream_warmup: a == null ? void 0 : a.streamWarmup,
@@ -989,380 +1028,394 @@ function ut(e, t) {
989
1028
  fluent: a == null ? void 0 : a.fluent
990
1029
  };
991
1030
  }
992
- function ft(e, t, a, r, o) {
993
- o === J.Fluent ? mt(e, t, a, r, o) : ht(e, t, a, r, o);
1031
+ function ht(e, t, a, r, s) {
1032
+ s === W.Fluent ? wt(e, t, a, r, s) : yt(e, t, a, r, s);
994
1033
  }
995
- function mt(e, t, a, r, o) {
1034
+ function wt(e, t, a, r, s) {
996
1035
  e === p.Start ? r.track("stream-session", {
997
1036
  event: "start",
998
- "stream-type": o
1037
+ "stream-type": s
999
1038
  }) : e === p.Stop && r.track("stream-session", {
1000
1039
  event: "stop",
1001
1040
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1002
1041
  background: t.presenter.type === "clip" && t.presenter.background,
1003
- "stream-type": o,
1042
+ "stream-type": s,
1004
1043
  ...a
1005
1044
  });
1006
1045
  }
1007
- function gt(e, t, a, r) {
1008
- F.get() <= 0 || (e === p.Start ? a.linkTrack("agent-video", {
1046
+ function pt(e, t, a, r) {
1047
+ J.get() <= 0 || (e === p.Start ? a.linkTrack("agent-video", {
1009
1048
  event: "start",
1010
- latency: F.get(!0),
1049
+ latency: J.get(!0),
1011
1050
  "stream-type": r
1012
- }, "start", [N.StreamVideoCreated]) : e === p.Stop && a.linkTrack("agent-video", {
1051
+ }, "start", [x.StreamVideoCreated]) : e === p.Stop && a.linkTrack("agent-video", {
1013
1052
  event: "stop",
1014
1053
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1015
1054
  background: t.presenter.type === "clip" && t.presenter.background,
1016
1055
  "stream-type": r
1017
- }, "done", [N.StreamVideoDone]));
1056
+ }, "done", [x.StreamVideoDone]));
1018
1057
  }
1019
- function ht(e, t, a, r, o) {
1020
- F.get() <= 0 || (e === p.Start ? r.linkTrack("agent-video", {
1058
+ function yt(e, t, a, r, s) {
1059
+ J.get() <= 0 || (e === p.Start ? r.linkTrack("agent-video", {
1021
1060
  event: "start",
1022
- latency: F.get(!0),
1023
- "stream-type": o
1024
- }, "start", [N.StreamVideoCreated]) : e === p.Stop && r.linkTrack("agent-video", {
1061
+ latency: J.get(!0),
1062
+ "stream-type": s
1063
+ }, "start", [x.StreamVideoCreated]) : e === p.Stop && r.linkTrack("agent-video", {
1025
1064
  event: "stop",
1026
1065
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1027
1066
  background: t.presenter.type === "clip" && t.presenter.background,
1028
- "stream-type": o,
1067
+ "stream-type": s,
1029
1068
  ...a
1030
- }, "done", [N.StreamVideoDone]));
1069
+ }, "done", [x.StreamVideoDone]));
1031
1070
  }
1032
- function wt(e, t, a) {
1033
- return F.reset(), new Promise(async (r, o) => {
1071
+ function vt(e, t, a) {
1072
+ return J.reset(), new Promise(async (r, s) => {
1034
1073
  try {
1035
- const s = await lt(e.id, ut(e, t), {
1074
+ const i = await mt(e.id, gt(e, t), {
1036
1075
  ...t,
1037
1076
  analytics: a,
1038
1077
  callbacks: {
1039
1078
  ...t.callbacks,
1040
- onConnectionStateChange: (n) => {
1041
- var c, i;
1042
- (i = (c = t.callbacks).onConnectionStateChange) == null || i.call(c, n), n === M.Connected && r(s);
1079
+ onConnectionStateChange: (c) => {
1080
+ var n, o;
1081
+ (o = (n = t.callbacks).onConnectionStateChange) == null || o.call(n, c), c === _.Connected && r(i);
1043
1082
  },
1044
- onVideoStateChange: (n, c) => {
1045
- var i, d;
1046
- (d = (i = t.callbacks).onVideoStateChange) == null || d.call(i, n), ft(n, e, c, a, s.streamType);
1083
+ onVideoStateChange: (c, n) => {
1084
+ var o, d;
1085
+ (d = (o = t.callbacks).onVideoStateChange) == null || d.call(o, c), ht(c, e, n, a, i.streamType);
1047
1086
  },
1048
- onAgentActivityStateChange: (n) => {
1049
- var c, i;
1050
- (i = (c = t.callbacks).onAgentActivityStateChange) == null || i.call(c, n), gt(n === X.Talking ? p.Start : p.Stop, e, a, s.streamType);
1087
+ onAgentActivityStateChange: (c) => {
1088
+ var n, o;
1089
+ (o = (n = t.callbacks).onAgentActivityStateChange) == null || o.call(n, c), pt(c === Y.Talking ? p.Start : p.Stop, e, a, i.streamType);
1051
1090
  }
1052
1091
  }
1053
1092
  });
1054
- } catch (s) {
1055
- o(s);
1093
+ } catch (i) {
1094
+ s(i);
1056
1095
  }
1057
1096
  });
1058
1097
  }
1059
- async function pt(e, t, a, r, o) {
1060
- var i, d, u, h;
1098
+ async function kt(e, t, a, r, s) {
1099
+ var o, d, u, h;
1061
1100
  const {
1062
- chat: s,
1063
- chatMode: n
1064
- } = await ue(e, a, r, t.mode, t.persistentChat, o);
1065
- if (n && n !== t.mode && (t.mode = n, (d = (i = t.callbacks).onModeChange) == null || d.call(i, n), n === b.TextOnly))
1066
- return (h = (u = t.callbacks).onError) == null || h.call(u, new we(n)), {
1067
- chat: s
1101
+ chat: i,
1102
+ chatMode: c
1103
+ } = await me(e, a, r, t.mode, t.persistentChat, s);
1104
+ if (c && c !== t.mode && (t.mode = c, (d = (o = t.callbacks).onModeChange) == null || d.call(o, c), c === T.TextOnly))
1105
+ return (h = (u = t.callbacks).onError) == null || h.call(u, new ye(c)), {
1106
+ chat: i
1068
1107
  };
1069
- const c = await wt(e, t, r);
1108
+ const n = await vt(e, t, r);
1070
1109
  return {
1071
- chat: s,
1072
- streamingManager: c
1110
+ chat: i,
1111
+ streamingManager: n
1073
1112
  };
1074
1113
  }
1075
- async function vt(e, t) {
1076
- var R, S, B;
1077
- let a = !0;
1078
- const r = t.mixpanelKey || je, o = t.wsURL || Te, s = t.baseURL || Y, n = {
1114
+ async function Ct(e, t) {
1115
+ var C, L, P;
1116
+ let a = !0, r = !1;
1117
+ const s = t.mixpanelKey || Ae, i = t.wsURL || Pe, c = t.baseURL || Q, n = {
1079
1118
  messages: [],
1080
- chatMode: t.mode || b.Functional
1081
- }, c = ce(t.auth, s, t.callbacks.onError), i = await c.getById(e), d = Ne({
1082
- token: r,
1083
- agent: i,
1119
+ chatMode: t.mode || T.Functional
1120
+ }, o = le(t.auth, c, t.callbacks.onError), d = await o.getById(e), u = We({
1121
+ token: s,
1122
+ agent: d,
1084
1123
  isEnabled: t.enableAnalitics,
1085
1124
  distinctId: t.distinctId
1086
1125
  }), {
1087
- onMessage: u,
1088
- clearQueue: h
1089
- } = Xe(d, n, t, i, () => {
1126
+ onMessage: h,
1127
+ clearQueue: b
1128
+ } = Ze(u, n, t, d, () => {
1090
1129
  var l;
1091
1130
  return (l = n.socketManager) == null ? void 0 : l.disconnect();
1092
1131
  });
1093
- n.messages = We(t.initialMessages), (S = (R = t.callbacks).onNewMessage) == null || S.call(R, [...n.messages], "answer"), d.track("agent-sdk", {
1132
+ n.messages = Ke(t.initialMessages), (L = (C = t.callbacks).onNewMessage) == null || L.call(C, [...n.messages], "answer"), u.track("agent-sdk", {
1094
1133
  event: "loaded",
1095
- ...Le(i)
1134
+ ...Ne(d)
1096
1135
  });
1097
- async function _(l) {
1098
- var j, P, $, C, I, E, L;
1099
- (P = (j = t.callbacks).onConnectionStateChange) == null || P.call(j, M.Connecting), F.reset(), l && !a && (delete n.chat, (C = ($ = t.callbacks).onNewMessage) == null || C.call($, [...n.messages], "answer"));
1100
- const m = t.mode === b.DirectPlayback ? Promise.resolve(void 0) : He(t.auth, o, {
1101
- onMessage: u,
1136
+ async function R(l) {
1137
+ var A, B, z, S, I, M, N;
1138
+ (B = (A = t.callbacks).onConnectionStateChange) == null || B.call(A, _.Connecting), J.reset(), r = !1, l && !a && (delete n.chat, (S = (z = t.callbacks).onNewMessage) == null || S.call(z, [...n.messages], "answer"));
1139
+ const w = t.mode === T.DirectPlayback ? Promise.resolve(void 0) : Xe(t.auth, i, {
1140
+ onMessage: h,
1102
1141
  onError: t.callbacks.onError
1103
- }), y = G(() => pt(i, t, c, d, n.chat), {
1142
+ }), y = O(() => kt(d, t, o, u, n.chat), {
1104
1143
  limit: 3,
1105
- timeout: Ie,
1144
+ timeout: be,
1106
1145
  timeoutErrorMessage: "Timeout initializing the stream",
1107
1146
  // Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
1108
- shouldRetryFn: (z) => (z == null ? void 0 : z.message) !== "Could not connect" && z.status !== 429,
1147
+ shouldRetryFn: (F) => (F == null ? void 0 : F.message) !== "Could not connect" && F.status !== 429,
1109
1148
  delayMs: 1e3
1110
- }).catch((z) => {
1111
- var f, g;
1112
- throw D(b.Maintenance), (g = (f = t.callbacks).onConnectionStateChange) == null || g.call(f, M.Fail), z;
1113
- }), [w, {
1114
- streamingManager: T,
1149
+ }).catch((F) => {
1150
+ var f, m;
1151
+ throw D(T.Maintenance), (m = (f = t.callbacks).onConnectionStateChange) == null || m.call(f, _.Fail), F;
1152
+ }), [g, {
1153
+ streamingManager: E,
1115
1154
  chat: v
1116
- }] = await Promise.all([m, y]);
1117
- v && v.id !== ((I = n.chat) == null ? void 0 : I.id) && ((L = (E = t.callbacks).onNewChat) == null || L.call(E, v.id)), n.streamingManager = T, n.socketManager = w, n.chat = v, a = !1, D((v == null ? void 0 : v.chat_mode) ?? t.mode ?? b.Functional);
1155
+ }] = await Promise.all([w, y]);
1156
+ v && v.id !== ((I = n.chat) == null ? void 0 : I.id) && ((N = (M = t.callbacks).onNewChat) == null || N.call(M, v.id)), n.streamingManager = E, n.socketManager = g, n.chat = v, a = !1, D((v == null ? void 0 : v.chat_mode) ?? t.mode ?? T.Functional);
1118
1157
  }
1119
1158
  async function k() {
1120
- var l, m, y, w;
1121
- (l = n.socketManager) == null || l.disconnect(), await ((m = n.streamingManager) == null ? void 0 : m.disconnect()), delete n.streamingManager, delete n.socketManager, (w = (y = t.callbacks).onConnectionStateChange) == null || w.call(y, M.Disconnected);
1159
+ var l, w, y, g;
1160
+ (l = n.socketManager) == null || l.disconnect(), await ((w = n.streamingManager) == null ? void 0 : w.disconnect()), r = !1, delete n.streamingManager, delete n.socketManager, (g = (y = t.callbacks).onConnectionStateChange) == null || g.call(y, _.Disconnected);
1122
1161
  }
1123
1162
  async function D(l) {
1124
- var m, y;
1125
- l !== n.chatMode && (d.track("agent-mode-change", {
1163
+ var w, y;
1164
+ l !== n.chatMode && (u.track("agent-mode-change", {
1126
1165
  mode: l
1127
- }), n.chatMode = l, n.chatMode !== b.Functional && await k(), (y = (m = t.callbacks).onModeChange) == null || y.call(m, l));
1166
+ }), n.chatMode = l, n.chatMode !== T.Functional && await k(), (y = (w = t.callbacks).onModeChange) == null || y.call(w, l));
1128
1167
  }
1129
1168
  return {
1130
- agent: i,
1169
+ agent: d,
1131
1170
  getStreamType: () => {
1132
1171
  var l;
1133
1172
  return (l = n.streamingManager) == null ? void 0 : l.streamType;
1134
1173
  },
1135
- starterMessages: ((B = i.knowledge) == null ? void 0 : B.starter_message) || [],
1136
- getSTTToken: () => c.getSTTToken(i.id),
1174
+ getIsInterruptEnabled: () => {
1175
+ var l;
1176
+ return ((l = n.streamingManager) == null ? void 0 : l.interruptEnabled) ?? !1;
1177
+ },
1178
+ starterMessages: ((P = d.knowledge) == null ? void 0 : P.starter_message) || [],
1179
+ getSTTToken: () => o.getSTTToken(d.id),
1137
1180
  changeMode: D,
1138
- enrichAnalytics: d.enrich,
1181
+ enrichAnalytics: u.enrich,
1139
1182
  async connect() {
1140
1183
  var l;
1141
- await _(!0), d.track("agent-chat", {
1184
+ await R(!0), u.track("agent-chat", {
1142
1185
  event: "connect",
1143
1186
  chatId: (l = n.chat) == null ? void 0 : l.id,
1144
- agentId: i.id,
1187
+ agentId: d.id,
1145
1188
  mode: n.chatMode
1146
1189
  });
1147
1190
  },
1148
1191
  async reconnect() {
1149
1192
  var l;
1150
- await k(), await _(!1), d.track("agent-chat", {
1193
+ await k(), await R(!1), u.track("agent-chat", {
1151
1194
  event: "reconnect",
1152
1195
  chatId: (l = n.chat) == null ? void 0 : l.id,
1153
- agentId: i.id,
1196
+ agentId: d.id,
1154
1197
  mode: n.chatMode
1155
1198
  });
1156
1199
  },
1157
1200
  async disconnect() {
1158
1201
  var l;
1159
- await k(), d.track("agent-chat", {
1202
+ await k(), u.track("agent-chat", {
1160
1203
  event: "disconnect",
1161
1204
  chatId: (l = n.chat) == null ? void 0 : l.id,
1162
- agentId: i.id,
1205
+ agentId: d.id,
1163
1206
  mode: n.chatMode
1164
1207
  });
1165
1208
  },
1166
1209
  async chat(l) {
1167
- var T, v, j, P, $;
1168
- const m = () => {
1169
- if (t.mode === b.DirectPlayback)
1170
- throw new W("Direct playback is enabled, chat is disabled");
1210
+ var E, v, A, B, z;
1211
+ const w = () => {
1212
+ if (t.mode === T.DirectPlayback)
1213
+ throw new K("Direct playback is enabled, chat is disabled");
1171
1214
  if (l.length >= 800)
1172
- throw new W("Message cannot be more than 800 characters");
1215
+ throw new K("Message cannot be more than 800 characters");
1173
1216
  if (l.length === 0)
1174
- throw new W("Message cannot be empty");
1175
- if (n.chatMode === b.Maintenance)
1176
- throw new W("Chat is in maintenance mode");
1177
- if (![b.TextOnly, b.Playground].includes(n.chatMode)) {
1217
+ throw new K("Message cannot be empty");
1218
+ if (n.chatMode === T.Maintenance)
1219
+ throw new K("Chat is in maintenance mode");
1220
+ if (![T.TextOnly, T.Playground].includes(n.chatMode)) {
1178
1221
  if (!n.streamingManager)
1179
- throw new W("Streaming manager is not initialized");
1222
+ throw new K("Streaming manager is not initialized");
1180
1223
  if (!n.chat)
1181
- throw new W("Chat is not initialized");
1224
+ throw new K("Chat is not initialized");
1182
1225
  }
1183
1226
  }, y = async () => {
1184
- var C, I;
1227
+ var S, I;
1185
1228
  if (!n.chat) {
1186
- const E = await ue(i, c, d, n.chatMode, t.persistentChat);
1187
- if (!E.chat)
1188
- throw new he(n.chatMode, !!t.persistentChat);
1189
- n.chat = E.chat, (I = (C = t.callbacks).onNewChat) == null || I.call(C, n.chat.id);
1229
+ const M = await me(d, o, u, n.chatMode, t.persistentChat);
1230
+ if (!M.chat)
1231
+ throw new pe(n.chatMode, !!t.persistentChat);
1232
+ n.chat = M.chat, (I = (S = t.callbacks).onNewChat) == null || I.call(S, n.chat.id);
1190
1233
  }
1191
1234
  return n.chat.id;
1192
- }, w = async (C, I) => G(() => {
1193
- var E, L;
1194
- return c.chat(i.id, I, {
1235
+ }, g = async (S, I) => O(() => {
1236
+ var M, N;
1237
+ return o.chat(d.id, I, {
1195
1238
  chatMode: n.chatMode,
1196
- streamId: (E = n.streamingManager) == null ? void 0 : E.streamId,
1197
- sessionId: (L = n.streamingManager) == null ? void 0 : L.sessionId,
1198
- messages: C.map(({
1199
- matches: z,
1239
+ streamId: (M = n.streamingManager) == null ? void 0 : M.streamId,
1240
+ sessionId: (N = n.streamingManager) == null ? void 0 : N.sessionId,
1241
+ messages: S.map(({
1242
+ matches: F,
1200
1243
  ...f
1201
1244
  }) => f)
1202
1245
  }, {
1203
- ...le(n.chatMode),
1246
+ ...fe(n.chatMode),
1204
1247
  skipErrorHandler: !0
1205
1248
  });
1206
1249
  }, {
1207
1250
  limit: 2,
1208
- shouldRetryFn: (E) => {
1209
- var f, g, A, H;
1210
- const L = (f = E == null ? void 0 : E.message) == null ? void 0 : f.includes("missing or invalid session_id");
1211
- return !((g = E == null ? void 0 : E.message) == null ? void 0 : g.includes("Stream Error")) && !L ? ((H = (A = t.callbacks).onError) == null || H.call(A, E), !1) : !0;
1251
+ shouldRetryFn: (M) => {
1252
+ var f, m, j, U;
1253
+ const N = (f = M == null ? void 0 : M.message) == null ? void 0 : f.includes("missing or invalid session_id");
1254
+ return !((m = M == null ? void 0 : M.message) == null ? void 0 : m.includes("Stream Error")) && !N ? ((U = (j = t.callbacks).onError) == null || U.call(j, M), !1) : !0;
1212
1255
  },
1213
1256
  onRetry: async () => {
1214
- await k(), await _(!1);
1257
+ await k(), await R(!1);
1215
1258
  }
1216
1259
  });
1217
1260
  try {
1218
- h(), m(), n.messages.push({
1219
- id: K(),
1261
+ b(), w(), n.messages.push({
1262
+ id: q(),
1220
1263
  role: "user",
1221
1264
  content: l,
1222
- created_at: new Date(F.update()).toISOString()
1223
- }), (v = (T = t.callbacks).onNewMessage) == null || v.call(T, [...n.messages], "user");
1224
- const C = await y(), I = await w([...n.messages], C);
1265
+ created_at: new Date(J.update()).toISOString()
1266
+ }), (v = (E = t.callbacks).onNewMessage) == null || v.call(E, [...n.messages], "user");
1267
+ const S = await y(), I = await g([...n.messages], S);
1225
1268
  return n.messages.push({
1226
- id: K(),
1269
+ id: q(),
1227
1270
  role: "assistant",
1228
1271
  content: I.result || "",
1229
1272
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
1230
1273
  context: I.context,
1231
- matches: I.matches
1232
- }), d.track("agent-message-send", {
1274
+ matches: I.matches,
1275
+ videoId: I.videoId
1276
+ }), r && I.videoId && n.streamingManager && (r = !1, n.messages[n.messages.length - 1].interrupted = !0, await ne(n.streamingManager, I.videoId)), u.track("agent-message-send", {
1233
1277
  event: "success",
1234
1278
  mode: n.chatMode,
1235
1279
  messages: n.messages.length + 1
1236
- }), I.result && ((P = (j = t.callbacks).onNewMessage) == null || P.call(j, [...n.messages], "answer"), d.track("agent-message-received", {
1237
- latency: F.get(!0),
1280
+ }), I.result && ((B = (A = t.callbacks).onNewMessage) == null || B.call(A, [...n.messages], "answer"), u.track("agent-message-received", {
1281
+ latency: J.get(!0),
1238
1282
  mode: n.chatMode,
1239
1283
  messages: n.messages.length
1240
1284
  })), I;
1241
- } catch (C) {
1242
- throw (($ = n.messages[n.messages.length - 1]) == null ? void 0 : $.role) === "assistant" && n.messages.pop(), d.track("agent-message-send", {
1285
+ } catch (S) {
1286
+ throw r = !1, ((z = n.messages[n.messages.length - 1]) == null ? void 0 : z.role) === "assistant" && n.messages.pop(), u.track("agent-message-send", {
1243
1287
  event: "error",
1244
1288
  mode: n.chatMode,
1245
1289
  messages: n.messages.length
1246
- }), C;
1290
+ }), S;
1247
1291
  }
1248
1292
  },
1249
- rate(l, m, y) {
1250
- var v, j, P, $;
1251
- const w = n.messages.find((C) => C.id === l);
1293
+ rate(l, w, y) {
1294
+ var v, A, B, z;
1295
+ const g = n.messages.find((S) => S.id === l);
1252
1296
  if (n.chat) {
1253
- if (!w)
1297
+ if (!g)
1254
1298
  throw new Error("Message not found");
1255
1299
  } else
1256
1300
  throw new Error("Chat is not initialized");
1257
- const T = ((v = w.matches) == null ? void 0 : v.map((C) => [C.document_id, C.id])) ?? [];
1258
- return d.track("agent-rate", {
1301
+ const E = ((v = g.matches) == null ? void 0 : v.map((S) => [S.document_id, S.id])) ?? [];
1302
+ return u.track("agent-rate", {
1259
1303
  event: y ? "update" : "create",
1260
- thumb: m === 1 ? "up" : "down",
1261
- knowledge_id: ((j = i.knowledge) == null ? void 0 : j.id) ?? "",
1304
+ thumb: w === 1 ? "up" : "down",
1305
+ knowledge_id: ((A = d.knowledge) == null ? void 0 : A.id) ?? "",
1262
1306
  mode: n.chatMode,
1263
- matches: T,
1264
- score: m
1265
- }), y ? c.updateRating(i.id, n.chat.id, y, {
1266
- knowledge_id: ((P = i.knowledge) == null ? void 0 : P.id) ?? "",
1307
+ matches: E,
1308
+ score: w
1309
+ }), y ? o.updateRating(d.id, n.chat.id, y, {
1310
+ knowledge_id: ((B = d.knowledge) == null ? void 0 : B.id) ?? "",
1267
1311
  message_id: l,
1268
- matches: T,
1269
- score: m
1270
- }) : c.createRating(i.id, n.chat.id, {
1271
- knowledge_id: (($ = i.knowledge) == null ? void 0 : $.id) ?? "",
1312
+ matches: E,
1313
+ score: w
1314
+ }) : o.createRating(d.id, n.chat.id, {
1315
+ knowledge_id: ((z = d.knowledge) == null ? void 0 : z.id) ?? "",
1272
1316
  message_id: l,
1273
- matches: T,
1274
- score: m
1317
+ matches: E,
1318
+ score: w
1275
1319
  });
1276
1320
  },
1277
1321
  deleteRate(l) {
1278
- var m;
1322
+ var w;
1279
1323
  if (!n.chat)
1280
1324
  throw new Error("Chat is not initialized");
1281
- return d.track("agent-rate-delete", {
1325
+ return u.track("agent-rate-delete", {
1282
1326
  type: "text",
1283
- chat_id: (m = n.chat) == null ? void 0 : m.id,
1327
+ chat_id: (w = n.chat) == null ? void 0 : w.id,
1284
1328
  id: l,
1285
1329
  mode: n.chatMode
1286
- }), c.deleteRating(i.id, n.chat.id, l);
1330
+ }), o.deleteRating(d.id, n.chat.id, l);
1287
1331
  },
1288
1332
  async speak(l) {
1289
- var T, v, j, P;
1333
+ var E, v, A, B;
1290
1334
  if (!n.streamingManager)
1291
1335
  throw new Error("Please connect to the agent first");
1292
- function m() {
1336
+ function w() {
1293
1337
  if (typeof l == "string") {
1294
- if (!i.presenter.voice)
1338
+ if (!d.presenter.voice)
1295
1339
  throw new Error("Presenter voice is not initialized");
1296
1340
  return {
1297
1341
  type: "text",
1298
- provider: i.presenter.voice,
1342
+ provider: d.presenter.voice,
1299
1343
  input: l,
1300
1344
  ssml: !1
1301
1345
  };
1302
1346
  }
1303
1347
  if (l.type === "text" && !l.provider) {
1304
- if (!i.presenter.voice)
1348
+ if (!d.presenter.voice)
1305
1349
  throw new Error("Presenter voice is not initialized");
1306
1350
  return {
1307
1351
  type: "text",
1308
- provider: i.presenter.voice,
1352
+ provider: d.presenter.voice,
1309
1353
  input: l.input,
1310
1354
  ssml: l.ssml
1311
1355
  };
1312
1356
  }
1313
1357
  return l;
1314
1358
  }
1315
- const y = m();
1316
- d.track("agent-speak", y), F.update(), (T = n.chat) != null && T.id && y.type === "text" && (n.messages.push({
1317
- id: K(),
1359
+ const y = w();
1360
+ u.track("agent-speak", y), J.update(), (E = n.chat) != null && E.id && y.type === "text" && (n.messages.push({
1361
+ id: q(),
1318
1362
  role: "assistant",
1319
1363
  content: y.input,
1320
- created_at: new Date(F.get(!0)).toISOString()
1321
- }), (j = (v = t.callbacks).onNewMessage) == null || j.call(v, [...n.messages], "answer"));
1322
- const w = Pe(n.chatMode);
1323
- return n.chat && w ? {
1364
+ created_at: new Date(J.get(!0)).toISOString()
1365
+ }), (A = (v = t.callbacks).onNewMessage) == null || A.call(v, [...n.messages], "answer"));
1366
+ const g = Be(n.chatMode);
1367
+ return n.chat && g ? {
1324
1368
  duration: 0,
1325
1369
  status: "success"
1326
1370
  } : n.streamingManager.speak({
1327
1371
  script: y,
1328
1372
  metadata: {
1329
- chat_id: (P = n.chat) == null ? void 0 : P.id,
1330
- agent_id: i.id
1373
+ chat_id: (B = n.chat) == null ? void 0 : B.id,
1374
+ agent_id: d.id
1331
1375
  }
1332
1376
  });
1377
+ },
1378
+ async interrupt() {
1379
+ var y, g, E;
1380
+ const l = n.messages[n.messages.length - 1], w = (l == null ? void 0 : l.role) === "user";
1381
+ if (He(n.streamingManager, n.chat, (y = n.streamingManager) == null ? void 0 : y.streamType, w, !!(l != null && l.videoId)), w) {
1382
+ r = !0;
1383
+ return;
1384
+ }
1385
+ l.interrupted = !0, (E = (g = t.callbacks).onNewMessage) == null || E.call(g, [...n.messages], "answer"), ne(n.streamingManager, l == null ? void 0 : l.videoId);
1333
1386
  }
1334
1387
  };
1335
1388
  }
1336
- function kt(e, t, a) {
1389
+ function Rt(e, t, a) {
1337
1390
  const {
1338
1391
  getById: r
1339
- } = ce(t, a || Y);
1392
+ } = le(t, a || Q);
1340
1393
  return r(e);
1341
1394
  }
1342
1395
  export {
1343
- X as AgentActivityState,
1344
- ke as AgentStatus,
1345
- he as ChatCreationFailed,
1346
- b as ChatMode,
1347
- we as ChatModeDowngraded,
1348
- U as ChatProgress,
1349
- M as ConnectionState,
1350
- V as ConnectivityState,
1351
- Se as DocumentType,
1352
- Ce as KnowledgeType,
1353
- ve as PlanGroup,
1396
+ Y as AgentActivityState,
1397
+ Ce as AgentStatus,
1398
+ pe as ChatCreationFailed,
1399
+ T as ChatMode,
1400
+ ye as ChatModeDowngraded,
1401
+ H as ChatProgress,
1402
+ _ as ConnectionState,
1403
+ X as ConnectivityState,
1404
+ Ie as DocumentType,
1405
+ Se as KnowledgeType,
1406
+ De as PlanGroup,
1354
1407
  _e as Providers,
1355
- De as RateState,
1356
- N as StreamEvents,
1357
- J as StreamType,
1408
+ Re as RateState,
1409
+ x as StreamEvents,
1410
+ W as StreamType,
1358
1411
  p as StreamingState,
1359
- Re as Subject,
1360
- ye as UserPlan,
1361
- W as ValidationError,
1362
- ae as VideoType,
1363
- Me as VoiceAccess,
1364
- pe as WsError,
1365
- vt as createAgentManager,
1366
- kt as getAgent,
1367
- Ee as mapVideoType
1412
+ Ee as Subject,
1413
+ ke as UserPlan,
1414
+ K as ValidationError,
1415
+ se as VideoType,
1416
+ Te as VoiceAccess,
1417
+ ve as WsError,
1418
+ Ct as createAgentManager,
1419
+ Rt as getAgent,
1420
+ Me as mapVideoType
1368
1421
  };