@d-id/client-sdk 1.1.14-staging.56 → 1.1.14-staging.58

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