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

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