@d-id/client-sdk 1.1.0-beta.2 → 1.1.0-beta.20

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