@d-id/client-sdk 1.1.58 → 1.1.60-staging.277

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,16 +1,16 @@
1
- var wt = Object.defineProperty;
2
- var yt = (e, n, i) => n in e ? wt(e, n, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[n] = i;
3
- var Ce = (e, n, i) => yt(e, typeof n != "symbol" ? n + "" : n, i);
4
- class Me extends Error {
5
- constructor({ kind: i, description: r, error: o }) {
1
+ var Et = Object.defineProperty;
2
+ var Mt = (e, n, i) => n in e ? Et(e, n, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[n] = i;
3
+ var Ce = (e, n, i) => Mt(e, typeof n != "symbol" ? n + "" : n, i);
4
+ class Ie extends Error {
5
+ constructor({ kind: i, description: r, error: s }) {
6
6
  super(JSON.stringify({ kind: i, description: r }));
7
7
  Ce(this, "kind");
8
8
  Ce(this, "description");
9
9
  Ce(this, "error");
10
- this.kind = i, this.description = r, this.error = o;
10
+ this.kind = i, this.description = r, this.error = s;
11
11
  }
12
12
  }
13
- class vt extends Me {
13
+ class kt extends Ie {
14
14
  constructor(n, i) {
15
15
  super({
16
16
  kind: "ChatCreationFailed",
@@ -18,25 +18,25 @@ class vt extends Me {
18
18
  });
19
19
  }
20
20
  }
21
- class Ct extends Me {
21
+ class It extends Ie {
22
22
  constructor(n) {
23
23
  super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${n}` });
24
24
  }
25
25
  }
26
- class me extends Me {
26
+ class me extends Ie {
27
27
  constructor(i, r) {
28
28
  super({ kind: "ValidationError", description: i });
29
29
  Ce(this, "key");
30
30
  this.key = r;
31
31
  }
32
32
  }
33
- class St extends Me {
33
+ class Dt extends Ie {
34
34
  constructor(n) {
35
35
  super({ kind: "WSError", description: n });
36
36
  }
37
37
  }
38
- var Rt = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Rt || {}), Tt = /* @__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))(Tt || {}), kt = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(kt || {}), Et = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Et || {}), O = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(O || {}), X = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(X || {}), Mt = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Mt || {}), Dt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Dt || {}), It = /* @__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))(It || {}), nt = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(nt || {});
39
- const zn = (e) => {
38
+ var At = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(At || {}), _t = /* @__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))(_t || {}), bt = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(bt || {}), Lt = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Lt || {}), O = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(O || {}), X = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(X || {}), Pt = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Pt || {}), xt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(xt || {}), $t = /* @__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))($t || {}), dt = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(dt || {});
39
+ const Hn = (e) => {
40
40
  switch (e) {
41
41
  case "clip":
42
42
  return "clip";
@@ -48,12 +48,12 @@ const zn = (e) => {
48
48
  throw new Error(`Unknown video type: ${e}`);
49
49
  }
50
50
  };
51
- var T = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(T || {}), ae = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ae || {}), W = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(W || {}), D = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", 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.ToolCalling = "tool/calling", e.ToolResult = "tool/result", e))(D || {}), L = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnecting = "disconnecting", e.Disconnected = "disconnected", e))(L || {}), se = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(se || {}), Be = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Be || {}), At = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(At || {}), _t = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(_t || {});
52
- const bt = 45 * 1e3, Pt = "X-Playground-Chat", Te = "https://api.d-id.com", Lt = "wss://notifications.d-id.com", $t = "79f81a83a67430be2bc0fd61042b8faa", jt = (...e) => {
53
- }, rt = (e) => new Promise((n) => setTimeout(n, e)), ge = (e = 16) => {
51
+ var E = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(E || {}), ae = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ae || {}), W = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(W || {}), M = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", 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.ToolCallStarted = "tool-call/started", e.ToolCallDone = "tool-call/done", e.ToolCallError = "tool-call/error", e))(M || {}), x = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnecting = "disconnecting", e.Disconnected = "disconnected", e))(x || {}), se = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(se || {}), Ne = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Ne || {}), jt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(jt || {}), Bt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Bt || {});
52
+ const Ft = 45 * 1e3, Nt = "X-Playground-Chat", Ee = "https://api.d-id.com", Kt = "wss://notifications.d-id.com", zt = "79f81a83a67430be2bc0fd61042b8faa", Vt = (...e) => {
53
+ }, ut = (e) => new Promise((n) => setTimeout(n, e)), ge = (e = 16) => {
54
54
  const n = new Uint8Array(e);
55
55
  return window.crypto.getRandomValues(n), Array.from(n, (i) => i.toString(16).padStart(2, "0")).join("").slice(0, 13);
56
- }, it = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, xt = (e) => {
56
+ }, lt = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, Ut = (e) => {
57
57
  switch (e.type) {
58
58
  case "expressive":
59
59
  return "v4";
@@ -62,17 +62,58 @@ const bt = 45 * 1e3, Pt = "X-Playground-Chat", Te = "https://api.d-id.com", Lt =
62
62
  case "talk":
63
63
  return "v2";
64
64
  }
65
- }, Bt = (e) => e.type === "talk" ? e.source_url : e.presenter_id, Fe = (e) => e === nt.Expressive, Ft = (e) => [O.TextOnly, O.Playground, O.Maintenance].includes(e), at = (e) => e && [O.DirectPlayback, O.Off].includes(e);
66
- function zt(e, n) {
65
+ }, Jt = (e) => e.type === "talk" ? e.source_url : e.presenter_id, Ke = (e) => e === dt.Expressive, Ot = (e) => [O.TextOnly, O.Playground, O.Maintenance].includes(e), ft = (e) => e && [O.DirectPlayback, O.Off].includes(e), Qe = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, Xe = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, Ye = new RegExp("(?<!!)\\[([^\\[\\]]+)\\]\\(([^)\\s]+)\\)", "g"), Ge = /<a\s+href="([^"]*)"[^>]*?>([^<]*)<\/a>/gi;
66
+ function Wt(e) {
67
+ if (e.length === 0)
68
+ return [];
69
+ const n = [];
70
+ let i;
71
+ for (Qe.lastIndex = 0; (i = Qe.exec(e)) !== null; )
72
+ n.push({
73
+ index: i.index,
74
+ length: i[0].length,
75
+ part: { type: "video", src: i[3], alt: i[1], thumbnail: i[2] }
76
+ });
77
+ for (Xe.lastIndex = 0; (i = Xe.exec(e)) !== null; )
78
+ if (!n.some((o) => i.index >= o.index && i.index < o.index + o.length)) {
79
+ const o = i[2], c = { type: "image", src: o, alt: i[1] };
80
+ o.toLowerCase().endsWith(".gif") && (c.mimeType = "image/gif"), n.push({ index: i.index, length: i[0].length, part: c });
81
+ }
82
+ for (Ye.lastIndex = 0; (i = Ye.exec(e)) !== null; )
83
+ n.some((o) => i.index >= o.index && i.index < o.index + o.length) || n.push({
84
+ index: i.index,
85
+ length: i[0].length,
86
+ part: { type: "link", href: i[2], label: i[1] }
87
+ });
88
+ for (Ge.lastIndex = 0; (i = Ge.exec(e)) !== null; )
89
+ n.some((o) => i.index >= o.index && i.index < o.index + o.length) || n.push({
90
+ index: i.index,
91
+ length: i[0].length,
92
+ part: { type: "link", href: i[1], label: i[2] }
93
+ });
94
+ if (n.length === 0)
95
+ return [{ type: "text", text: e }];
96
+ n.sort((a, o) => a.index - o.index);
97
+ const r = [];
98
+ let s = 0;
99
+ for (const a of n)
100
+ a.index > s && r.push({ type: "text", text: e.slice(s, a.index) }), r.push(a.part), s = a.index + a.length;
101
+ return s < e.length && r.push({ type: "text", text: e.slice(s) }), r;
102
+ }
103
+ let Ze = "", Pe = [];
104
+ function Te(e) {
105
+ return e === Ze || (Ze = e, Pe = Wt(e)), Pe;
106
+ }
107
+ function Ht(e, n) {
67
108
  let i;
68
109
  return {
69
- promise: new Promise((o, a) => {
110
+ promise: new Promise((s, a) => {
70
111
  i = setTimeout(() => a(new Error(n)), e);
71
112
  }),
72
113
  clear: () => clearTimeout(i)
73
114
  };
74
115
  }
75
- async function Pe(e, n) {
116
+ async function xe(e, n) {
76
117
  const i = {
77
118
  limit: (n == null ? void 0 : n.limit) ?? 3,
78
119
  delayMs: (n == null ? void 0 : n.delayMs) ?? 0,
@@ -83,20 +124,20 @@ async function Pe(e, n) {
83
124
  })
84
125
  };
85
126
  let r;
86
- for (let o = 1; o <= i.limit; o++)
127
+ for (let s = 1; s <= i.limit; s++)
87
128
  try {
88
129
  if (!i.timeout)
89
130
  return await e();
90
- const { promise: a, clear: s } = zt(i.timeout, i.timeoutErrorMessage), d = e().finally(s);
91
- return await Promise.race([d, a]);
131
+ const { promise: a, clear: o } = Ht(i.timeout, i.timeoutErrorMessage), c = e().finally(o);
132
+ return await Promise.race([c, a]);
92
133
  } catch (a) {
93
- if (r = a, !i.shouldRetryFn(a) || o >= i.limit)
134
+ if (r = a, !i.shouldRetryFn(a) || s >= i.limit)
94
135
  throw a;
95
- await rt(i.delayMs), i.onRetry(a);
136
+ await ut(i.delayMs), i.onRetry(a);
96
137
  }
97
138
  throw r;
98
139
  }
99
- function Le(e) {
140
+ function $e(e) {
100
141
  if (e !== void 0)
101
142
  return window.localStorage.setItem("did_external_key_id", e), e;
102
143
  let n = window.localStorage.getItem("did_external_key_id");
@@ -106,96 +147,96 @@ function Le(e) {
106
147
  }
107
148
  return n;
108
149
  }
109
- let Kt = ge();
110
- function ot(e, n) {
150
+ let qt = ge();
151
+ function mt(e, n) {
111
152
  if (e.type === "bearer")
112
153
  return `Bearer ${e.token}`;
113
154
  if (e.type === "basic")
114
155
  return `Basic ${"token" in e ? e.token : btoa(`${e.username}:${e.password}`)}`;
115
156
  if (e.type === "key")
116
- return `Client-Key ${e.clientKey}.${Le(n)}_${Kt}`;
157
+ return `Client-Key ${e.clientKey}.${$e(n)}_${qt}`;
117
158
  throw new Error(`Unknown auth type: ${e}`);
118
159
  }
119
- const Nt = (e) => Pe(e, {
160
+ const Qt = (e) => xe(e, {
120
161
  limit: 3,
121
162
  delayMs: 1e3,
122
163
  timeout: 0,
123
164
  shouldRetryFn: (n) => n.status === 429
124
165
  });
125
- function ze(e, n = Te, i, r) {
126
- const o = async (a, s) => {
127
- const { skipErrorHandler: d, ...t } = s || {}, c = await Nt(
166
+ function ze(e, n = Ee, i, r) {
167
+ const s = async (a, o) => {
168
+ const { skipErrorHandler: c, ...t } = o || {}, d = await Qt(
128
169
  () => fetch(n + (a != null && a.startsWith("/") ? a : `/${a}`), {
129
170
  ...t,
130
171
  headers: {
131
172
  ...t.headers,
132
- Authorization: ot(e, r),
173
+ Authorization: mt(e, r),
133
174
  "Content-Type": "application/json"
134
175
  }
135
176
  })
136
177
  );
137
- if (!c.ok) {
138
- let h = await c.text().catch(() => `Failed to fetch with status ${c.status}`);
178
+ if (!d.ok) {
179
+ let h = await d.text().catch(() => `Failed to fetch with status ${d.status}`);
139
180
  const g = new Error(h);
140
- throw i && !d && i(g, { url: a, options: t, headers: c.headers }), g;
181
+ throw i && !c && i(g, { url: a, options: t, headers: d.headers }), g;
141
182
  }
142
- return c.json();
183
+ return d.json();
143
184
  };
144
185
  return {
145
- get(a, s) {
146
- return o(a, { ...s, method: "GET" });
186
+ get(a, o) {
187
+ return s(a, { ...o, method: "GET" });
147
188
  },
148
- post(a, s, d) {
149
- return o(a, { ...d, body: JSON.stringify(s), method: "POST" });
189
+ post(a, o, c) {
190
+ return s(a, { ...c, body: JSON.stringify(o), method: "POST" });
150
191
  },
151
- delete(a, s, d) {
152
- return o(a, { ...d, body: JSON.stringify(s), method: "DELETE" });
192
+ delete(a, o, c) {
193
+ return s(a, { ...c, body: JSON.stringify(o), method: "DELETE" });
153
194
  },
154
- patch(a, s, d) {
155
- return o(a, { ...d, body: JSON.stringify(s), method: "PATCH" });
195
+ patch(a, o, c) {
196
+ return s(a, { ...c, body: JSON.stringify(o), method: "PATCH" });
156
197
  }
157
198
  };
158
199
  }
159
- function Vt(e, n = Te, i, r) {
160
- const o = ze(e, `${n}/agents`, i, r);
200
+ function Xt(e, n = Ee, i, r) {
201
+ const s = ze(e, `${n}/agents`, i, r);
161
202
  return {
162
- create(a, s) {
163
- return o.post("/", a, s);
203
+ create(a, o) {
204
+ return s.post("/", a, o);
164
205
  },
165
- getAgents(a, s) {
166
- return o.get(`/${a ? `?tag=${a}` : ""}`, s).then((d) => d ?? []);
206
+ getAgents(a, o) {
207
+ return s.get(`/${a ? `?tag=${a}` : ""}`, o).then((c) => c ?? []);
167
208
  },
168
- getById(a, s) {
169
- return o.get(`/${a}`, s);
209
+ getById(a, o) {
210
+ return s.get(`/${a}`, o);
170
211
  },
171
- delete(a, s) {
172
- return o.delete(`/${a}`, void 0, s);
212
+ delete(a, o) {
213
+ return s.delete(`/${a}`, void 0, o);
173
214
  },
174
- update(a, s, d) {
175
- return o.patch(`/${a}`, s, d);
215
+ update(a, o, c) {
216
+ return s.patch(`/${a}`, o, c);
176
217
  },
177
- newChat(a, s, d) {
178
- return o.post(`/${a}/chat`, s, d);
218
+ newChat(a, o, c) {
219
+ return s.post(`/${a}/chat`, o, c);
179
220
  },
180
- chat(a, s, d, t) {
181
- return o.post(`/${a}/chat/${s}`, d, t);
221
+ chat(a, o, c, t) {
222
+ return s.post(`/${a}/chat/${o}`, c, t);
182
223
  },
183
- createRating(a, s, d, t) {
184
- return o.post(`/${a}/chat/${s}/ratings`, d, t);
224
+ createRating(a, o, c, t) {
225
+ return s.post(`/${a}/chat/${o}/ratings`, c, t);
185
226
  },
186
- updateRating(a, s, d, t, c) {
187
- return o.patch(`/${a}/chat/${s}/ratings/${d}`, t, c);
227
+ updateRating(a, o, c, t, d) {
228
+ return s.patch(`/${a}/chat/${o}/ratings/${c}`, t, d);
188
229
  },
189
- deleteRating(a, s, d, t) {
190
- return o.delete(`/${a}/chat/${s}/ratings/${d}`, t);
230
+ deleteRating(a, o, c, t) {
231
+ return s.delete(`/${a}/chat/${o}/ratings/${c}`, t);
191
232
  },
192
- getSTTToken(a, s) {
193
- return o.get(`/${a}/stt-token`, s);
233
+ getSTTToken(a, o) {
234
+ return s.get(`/${a}/stt-token`, o);
194
235
  }
195
236
  };
196
237
  }
197
- function Jt(e) {
198
- var o, a, s, d;
238
+ function Yt(e) {
239
+ var s, a, o, c;
199
240
  const n = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", i = () => {
200
241
  const t = navigator.platform;
201
242
  return t.toLowerCase().includes("win") ? "Windows" : t.toLowerCase().includes("mac") ? "Mac OS X" : t.toLowerCase().includes("linux") ? "Linux" : "Unknown";
@@ -205,30 +246,30 @@ function Jt(e) {
205
246
  isMobile: `${n() == "Mobile"}`,
206
247
  browser: navigator.userAgent,
207
248
  origin: window.location.origin,
208
- agentType: it(r),
249
+ agentType: lt(r),
209
250
  agentVoice: {
210
- voiceId: (a = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : a.voice_id,
211
- provider: (d = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : d.type
251
+ voiceId: (a = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : a.voice_id,
252
+ provider: (c = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : c.type
212
253
  }
213
254
  };
214
255
  }
215
- function Ut(e) {
216
- var i, r, o, a, s, d;
256
+ function Gt(e) {
257
+ var i, r, s, a, o, c;
217
258
  const n = (i = e.llm) == null ? void 0 : i.prompt_customization;
218
259
  return {
219
- agentType: it(e.presenter),
220
- presenterType: xt(e.presenter),
221
- presenter: Bt(e.presenter),
260
+ agentType: lt(e.presenter),
261
+ presenterType: Ut(e.presenter),
262
+ presenter: Jt(e.presenter),
222
263
  owner_id: e.owner_id ?? "",
223
264
  promptVersion: (r = e.llm) == null ? void 0 : r.prompt_version,
224
265
  behavior: {
225
266
  role: n == null ? void 0 : n.role,
226
267
  personality: n == null ? void 0 : n.personality,
227
- instructions: (o = e.llm) == null ? void 0 : o.instructions
268
+ instructions: (s = e.llm) == null ? void 0 : s.instructions
228
269
  },
229
270
  temperature: (a = e.llm) == null ? void 0 : a.temperature,
230
271
  knowledgeSource: n == null ? void 0 : n.knowledge_source,
231
- starterQuestionsCount: (d = (s = e.knowledge) == null ? void 0 : s.starter_message) == null ? void 0 : d.length,
272
+ starterQuestionsCount: (c = (o = e.knowledge) == null ? void 0 : o.starter_message) == null ? void 0 : c.length,
232
273
  topicsToAvoid: n == null ? void 0 : n.topics_to_avoid,
233
274
  maxResponseLength: n == null ? void 0 : n.max_response_length,
234
275
  agentId: e.id,
@@ -237,30 +278,30 @@ function Ut(e) {
237
278
  ...e.access === "public" ? { from: "agent-template" } : {}
238
279
  };
239
280
  }
240
- const Ot = (e) => e.reduce((n, i) => n + i, 0), He = (e) => Ot(e) / e.length;
241
- function Wt(e, n, i) {
242
- var t, c, h;
243
- const { event: r, ...o } = e, { template: a } = (n == null ? void 0 : n.llm) || {}, { language: s } = ((t = n == null ? void 0 : n.presenter) == null ? void 0 : t.voice) || {};
281
+ const Zt = (e) => e.reduce((n, i) => n + i, 0), et = (e) => Zt(e) / e.length;
282
+ function en(e, n, i) {
283
+ var t, d, h;
284
+ const { event: r, ...s } = e, { template: a } = (n == null ? void 0 : n.llm) || {}, { language: o } = ((t = n == null ? void 0 : n.presenter) == null ? void 0 : t.voice) || {};
244
285
  return {
245
- ...o,
246
- llm: { ...o.llm, template: a },
247
- script: { ...o.script, provider: { ...(c = o == null ? void 0 : o.script) == null ? void 0 : c.provider, language: s } },
286
+ ...s,
287
+ llm: { ...s.llm, template: a },
288
+ script: { ...s.script, provider: { ...(d = s == null ? void 0 : s.script) == null ? void 0 : d.provider, language: o } },
248
289
  stitch: (n == null ? void 0 : n.presenter.type) === "talk" ? (h = n == null ? void 0 : n.presenter) == null ? void 0 : h.stitch : void 0,
249
290
  ...i
250
291
  };
251
292
  }
252
- function qe(e) {
293
+ function tt(e) {
253
294
  "requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
254
295
  }
255
- const Ht = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
256
- function qt(e) {
296
+ const tn = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
297
+ function nn(e) {
257
298
  const n = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", i = {};
258
299
  return {
259
300
  token: e.token || "testKey",
260
- distinct_id: Le(e.externalId),
301
+ distinct_id: $e(e.externalId),
261
302
  agentId: e.agentId,
262
303
  additionalProperties: {
263
- id: Le(e.externalId),
304
+ id: $e(e.externalId),
264
305
  ...e.mixpanelAdditionalProperties || {}
265
306
  },
266
307
  isEnabled: e.isEnabled ?? !0,
@@ -268,10 +309,10 @@ function qt(e) {
268
309
  enrich(r) {
269
310
  this.additionalProperties = { ...this.additionalProperties, ...r };
270
311
  },
271
- async track(r, o, a) {
312
+ async track(r, s, a) {
272
313
  if (!this.isEnabled)
273
314
  return Promise.resolve();
274
- const { audioPath: s, ...d } = o || {}, t = a || Date.now(), c = {
315
+ const { audioPath: o, ...c } = s || {}, t = a || Date.now(), d = {
275
316
  method: "POST",
276
317
  headers: {
277
318
  "Content-Type": "application/x-www-form-urlencoded"
@@ -282,7 +323,7 @@ function qt(e) {
282
323
  event: r,
283
324
  properties: {
284
325
  ...this.additionalProperties,
285
- ...d,
326
+ ...c,
286
327
  agentId: this.agentId,
287
328
  source: n,
288
329
  token: this.token,
@@ -297,25 +338,25 @@ function qt(e) {
297
338
  ])
298
339
  })
299
340
  };
300
- return fetch(Ht, c).catch((h) => console.error("Analytics tracking error:", h)), Promise.resolve();
341
+ return fetch(tn, d).catch((h) => console.error("Analytics tracking error:", h)), Promise.resolve();
301
342
  },
302
- linkTrack(r, o, a, s) {
303
- i[r] || (i[r] = { events: {}, resolvedDependencies: [] }), s.includes(a) || s.push(a);
304
- const d = i[r];
305
- if (d.events[a] = { props: o }, d.resolvedDependencies.push(a), s.every(
306
- (c) => d.resolvedDependencies.includes(c)
343
+ linkTrack(r, s, a, o) {
344
+ i[r] || (i[r] = { events: {}, resolvedDependencies: [] }), o.includes(a) || o.push(a);
345
+ const c = i[r];
346
+ if (c.events[a] = { props: s }, c.resolvedDependencies.push(a), o.every(
347
+ (d) => c.resolvedDependencies.includes(d)
307
348
  )) {
308
- const c = s.reduce((h, g) => d.events[g] ? { ...h, ...d.events[g].props } : h, {});
309
- this.track(r, c), d.resolvedDependencies = d.resolvedDependencies.filter(
310
- (h) => !s.includes(h)
311
- ), s.forEach((h) => {
312
- delete d.events[h];
349
+ const d = o.reduce((h, g) => c.events[g] ? { ...h, ...c.events[g].props } : h, {});
350
+ this.track(r, d), c.resolvedDependencies = c.resolvedDependencies.filter(
351
+ (h) => !o.includes(h)
352
+ ), o.forEach((h) => {
353
+ delete c.events[h];
313
354
  });
314
355
  }
315
356
  }
316
357
  };
317
358
  }
318
- function Ke() {
359
+ function Ve() {
319
360
  let e = 0;
320
361
  return {
321
362
  reset: () => e = 0,
@@ -323,22 +364,22 @@ function Ke() {
323
364
  get: (n = !1) => n ? Date.now() - e : e
324
365
  };
325
366
  }
326
- const oe = Ke(), $e = Ke(), Qe = Ke();
327
- function st(e) {
328
- return e === O.Playground ? { headers: { [Pt]: "true" } } : {};
367
+ const oe = Ve(), je = Ve(), nt = Ve();
368
+ function gt(e) {
369
+ return e === O.Playground ? { headers: { [Nt]: "true" } } : {};
329
370
  }
330
- async function ct(e, n, i, r, o = !1, a) {
371
+ async function ht(e, n, i, r, s = !1, a) {
331
372
  try {
332
- return !a && !at(r) && (a = await n.newChat(e.id, { persist: o }, st(r)), i.track("agent-chat", {
373
+ return !a && !ft(r) && (a = await n.newChat(e.id, { persist: s }, gt(r)), i.track("agent-chat", {
333
374
  event: "created",
334
375
  chatId: a.id,
335
376
  mode: r
336
377
  })), { chat: a, chatMode: (a == null ? void 0 : a.chat_mode) ?? r };
337
- } catch (s) {
338
- throw Qt(s) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
378
+ } catch (o) {
379
+ throw rn(o) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
339
380
  }
340
381
  }
341
- const Qt = (e) => {
382
+ const rn = (e) => {
342
383
  try {
343
384
  const n = JSON.parse(e.message);
344
385
  return n == null ? void 0 : n.kind;
@@ -346,22 +387,22 @@ const Qt = (e) => {
346
387
  return "UnknownError";
347
388
  }
348
389
  };
349
- function Xt(e) {
390
+ function an(e) {
350
391
  return e && e.length > 0 ? e : [];
351
392
  }
352
- function Yt(e, n, i, r) {
353
- const o = ze(e, `${n}/v2/agents/${i}`, r);
393
+ function on(e, n, i, r) {
394
+ const s = ze(e, `${n}/v2/agents/${i}`, r);
354
395
  return {
355
396
  async createStream(a) {
356
- return o.post("/sessions", a);
397
+ return s.post("/sessions", a);
357
398
  }
358
399
  };
359
400
  }
360
- const dt = (e, n) => (i, r) => e && console.log(`[${n}] ${i}`, r ?? ""), Gt = {
361
- [D.ChatAnswer]: X.Answer,
362
- [D.ChatPartial]: X.Partial
401
+ const pt = (e, n) => (i, r) => e && console.log(`[${n}] ${i}`, r ?? ""), sn = {
402
+ [M.ChatAnswer]: X.Answer,
403
+ [M.ChatPartial]: X.Partial
363
404
  };
364
- function Zt(e, n, i) {
405
+ function cn(e, n, i) {
365
406
  const r = (n.timestamp - e.timestamp) / 1e3;
366
407
  return {
367
408
  duration: r,
@@ -381,23 +422,23 @@ function Zt(e, n, i) {
381
422
  lowFpsCount: i
382
423
  };
383
424
  }
384
- function en(e) {
425
+ function dn(e) {
385
426
  return e.filter(
386
427
  (n) => n.freezeCount > 0 || n.framesPerSecond < 21 || n.framesDropped > 0 || n.packetsLost > 0
387
428
  ).map((n) => {
388
- const { timestamp: i, ...r } = n, o = [];
389
- return n.freezeCount > 0 && o.push("freeze"), n.framesPerSecond < 21 && o.push("low fps"), n.framesDropped > 0 && o.push("frames dropped"), n.packetsLost > 0 && o.push("packet loss"), {
429
+ const { timestamp: i, ...r } = n, s = [];
430
+ return n.freezeCount > 0 && s.push("freeze"), n.framesPerSecond < 21 && s.push("low fps"), n.framesDropped > 0 && s.push("frames dropped"), n.packetsLost > 0 && s.push("packet loss"), {
390
431
  ...r,
391
- causes: o
432
+ causes: s
392
433
  };
393
434
  });
394
435
  }
395
- function tn(e) {
436
+ function un(e) {
396
437
  let n = "", i = 0;
397
438
  for (const r of e.values()) {
398
439
  if (r && r.type === "codec" && r.mimeType.startsWith("video") && (n = r.mimeType.split("/")[1]), r && r.type === "candidate-pair") {
399
- const o = r.currentRoundTripTime, s = r.nominated === !0;
400
- o > 0 && (s || i === 0) && (i = o);
440
+ const s = r.currentRoundTripTime, o = r.nominated === !0;
441
+ s > 0 && (o || i === 0) && (i = s);
401
442
  }
402
443
  if (r && r.type === "inbound-rtp" && r.kind === "video")
403
444
  return {
@@ -422,8 +463,8 @@ function tn(e) {
422
463
  }
423
464
  return {};
424
465
  }
425
- function Xe(e, n, i) {
426
- const r = e.map((t, c) => c === 0 ? i ? {
466
+ function rt(e, n, i) {
467
+ const r = e.map((t, d) => d === 0 ? i ? {
427
468
  timestamp: t.timestamp,
428
469
  duration: 0,
429
470
  rtt: t.rtt,
@@ -459,127 +500,127 @@ function Xe(e, n, i) {
459
500
  freezeDuration: t.freezeDuration
460
501
  } : {
461
502
  timestamp: t.timestamp,
462
- duration: n * c / 1e3,
503
+ duration: n * d / 1e3,
463
504
  rtt: t.rtt,
464
- bytesReceived: t.bytesReceived - e[c - 1].bytesReceived,
465
- bitrate: (t.bytesReceived - e[c - 1].bytesReceived) * 8 / (n / 1e3),
466
- packetsReceived: t.packetsReceived - e[c - 1].packetsReceived,
467
- packetsLost: t.packetsLost - e[c - 1].packetsLost,
468
- framesDropped: t.framesDropped - e[c - 1].framesDropped,
469
- framesDecoded: t.framesDecoded - e[c - 1].framesDecoded,
505
+ bytesReceived: t.bytesReceived - e[d - 1].bytesReceived,
506
+ bitrate: (t.bytesReceived - e[d - 1].bytesReceived) * 8 / (n / 1e3),
507
+ packetsReceived: t.packetsReceived - e[d - 1].packetsReceived,
508
+ packetsLost: t.packetsLost - e[d - 1].packetsLost,
509
+ framesDropped: t.framesDropped - e[d - 1].framesDropped,
510
+ framesDecoded: t.framesDecoded - e[d - 1].framesDecoded,
470
511
  jitter: t.jitter,
471
- jitterBufferDelay: t.jitterBufferDelay - e[c - 1].jitterBufferDelay,
472
- jitterBufferEmittedCount: t.jitterBufferEmittedCount - e[c - 1].jitterBufferEmittedCount,
473
- avgJitterDelayInInterval: (t.jitterBufferDelay - e[c - 1].jitterBufferDelay) / (t.jitterBufferEmittedCount - e[c - 1].jitterBufferEmittedCount),
512
+ jitterBufferDelay: t.jitterBufferDelay - e[d - 1].jitterBufferDelay,
513
+ jitterBufferEmittedCount: t.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount,
514
+ avgJitterDelayInInterval: (t.jitterBufferDelay - e[d - 1].jitterBufferDelay) / (t.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount),
474
515
  framesPerSecond: t.framesPerSecond,
475
- freezeCount: t.freezeCount - e[c - 1].freezeCount,
476
- freezeDuration: t.freezeDuration - e[c - 1].freezeDuration
477
- }), o = en(r), a = o.reduce((t, c) => t + (c.causes.includes("low fps") ? 1 : 0), 0), s = r.filter((t) => !!t.avgJitterDelayInInterval).map((t) => t.avgJitterDelayInInterval), d = r.filter((t) => !!t.rtt).map((t) => t.rtt);
516
+ freezeCount: t.freezeCount - e[d - 1].freezeCount,
517
+ freezeDuration: t.freezeDuration - e[d - 1].freezeDuration
518
+ }), s = dn(r), a = s.reduce((t, d) => t + (d.causes.includes("low fps") ? 1 : 0), 0), o = r.filter((t) => !!t.avgJitterDelayInInterval).map((t) => t.avgJitterDelayInInterval), c = r.filter((t) => !!t.rtt).map((t) => t.rtt);
478
519
  return {
479
520
  webRTCStats: {
480
- anomalies: o,
481
- minRtt: Math.min(...d),
482
- avgRtt: He(d),
483
- maxRtt: Math.max(...d),
484
- aggregateReport: Zt(e[0], e[e.length - 1], a),
485
- minJitterDelayInInterval: Math.min(...s),
486
- maxJitterDelayInInterval: Math.max(...s),
487
- avgJitterDelayInInterval: He(s)
521
+ anomalies: s,
522
+ minRtt: Math.min(...c),
523
+ avgRtt: et(c),
524
+ maxRtt: Math.max(...c),
525
+ aggregateReport: cn(e[0], e[e.length - 1], a),
526
+ minJitterDelayInInterval: Math.min(...o),
527
+ maxJitterDelayInInterval: Math.max(...o),
528
+ avgJitterDelayInInterval: et(o)
488
529
  },
489
530
  codec: e[0].codec,
490
531
  resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
491
532
  };
492
533
  }
493
- function ut(e, n) {
534
+ function wt(e, n) {
494
535
  for (const i of e.values())
495
536
  if ((i == null ? void 0 : i.type) === "inbound-rtp" && i.kind === n)
496
537
  return i;
497
538
  return null;
498
539
  }
499
540
  const Se = 10;
500
- function nn(e, n) {
501
- let i = !1, r = !1, o = null, a = 0, s = 0, d = {};
541
+ function ln(e, n) {
542
+ let i = !1, r = !1, s = null, a = 0, o = 0, c = {};
502
543
  async function t() {
503
544
  if (i) {
504
545
  try {
505
- const c = await e();
506
- if (!c) {
507
- o = setTimeout(t, Se);
546
+ const d = await e();
547
+ if (!d) {
548
+ s = setTimeout(t, Se);
508
549
  return;
509
550
  }
510
- const h = ut(c, "audio");
551
+ const h = wt(d, "audio");
511
552
  if (!h) {
512
- o = setTimeout(t, Se);
553
+ s = setTimeout(t, Se);
513
554
  return;
514
555
  }
515
556
  const g = h.totalAudioEnergy ?? 0, l = h.totalSamplesReceived ?? 0;
516
557
  if (!r) {
517
- a = g, s = l, r = !0, o = setTimeout(t, Se);
558
+ a = g, o = l, r = !0, s = setTimeout(t, Se);
518
559
  return;
519
560
  }
520
- const v = g - a, P = l - s;
521
- if (a = g, s = l, P > 0 && v > 0) {
522
- i = !1, n(d);
561
+ const v = g - a, P = l - o;
562
+ if (a = g, o = l, P > 0 && v > 0) {
563
+ i = !1, n(c);
523
564
  return;
524
565
  }
525
566
  } catch {
526
567
  }
527
- i && (o = setTimeout(t, Se));
568
+ i && (s = setTimeout(t, Se));
528
569
  }
529
570
  }
530
571
  return {
531
- arm(c = {}) {
532
- d = c, i = !0, r = !1, performance.now(), o !== null && clearTimeout(o), o = setTimeout(t, Se);
572
+ arm(d = {}) {
573
+ c = d, i = !0, r = !1, performance.now(), s !== null && clearTimeout(s), s = setTimeout(t, Se);
533
574
  },
534
575
  destroy() {
535
- i = !1, o !== null && (clearTimeout(o), o = null);
576
+ i = !1, s !== null && (clearTimeout(s), s = null);
536
577
  }
537
578
  };
538
579
  }
539
- const Ee = 100, rn = Math.max(Math.ceil(400 / Ee), 1), an = 0.25, on = 0.28;
540
- function sn() {
580
+ const ke = 100, fn = Math.max(Math.ceil(400 / ke), 1), mn = 0.25, gn = 0.28;
581
+ function hn() {
541
582
  let e = 0, n, i, r = 0;
542
- return (o) => {
543
- const a = ut(o, "video");
583
+ return (s) => {
584
+ const a = wt(s, "video");
544
585
  if (!a)
545
586
  return { isReceiving: !1, avgJitterDelayInInterval: r };
546
- const s = a.jitterBufferDelay, d = a.jitterBufferEmittedCount;
547
- if (i && d > i) {
548
- const h = s - n, g = d - i;
587
+ const o = a.jitterBufferDelay, c = a.jitterBufferEmittedCount;
588
+ if (i && c > i) {
589
+ const h = o - n, g = c - i;
549
590
  r = h / g;
550
591
  }
551
- n = s, i = d;
552
- const t = a.framesDecoded, c = t - e > 0;
553
- return e = t, { isReceiving: c, avgJitterDelayInInterval: r, freezeCount: a.freezeCount };
592
+ n = o, i = c;
593
+ const t = a.framesDecoded, d = t - e > 0;
594
+ return e = t, { isReceiving: d, avgJitterDelayInInterval: r, freezeCount: a.freezeCount };
554
595
  };
555
596
  }
556
- function lt(e, n, i, r, o) {
557
- let a = null, s = [], d, t = 0, c = !1, h = ae.Unknown, g = ae.Unknown, l = 0, v = 0;
558
- const P = sn();
559
- async function z() {
560
- const x = await e();
561
- if (!x)
597
+ function yt(e, n, i, r, s) {
598
+ let a = null, o = [], c, t = 0, d = !1, h = ae.Unknown, g = ae.Unknown, l = 0, v = 0;
599
+ const P = hn();
600
+ async function N() {
601
+ const B = await e();
602
+ if (!B)
562
603
  return;
563
- const { isReceiving: F, avgJitterDelayInInterval: M, freezeCount: E } = P(x), Y = tn(x);
604
+ const { isReceiving: F, avgJitterDelayInInterval: I, freezeCount: k } = P(B), Y = un(B);
564
605
  if (F)
565
- t = 0, l = E - v, g = M < an ? ae.Strong : M > on && l > 1 ? ae.Weak : h, g !== h && (o == null || o(g), h = g, v += l, l = 0), c || (r == null || r(T.Start), d = s[s.length - 1], s = [], c = !0), s.push(Y);
566
- else if (c && (t++, t >= rn)) {
567
- const Q = Xe(s, Ee, d);
568
- r == null || r(T.Stop, Q), n() || i(), v = E, c = !1;
606
+ t = 0, l = k - v, g = I < mn ? ae.Strong : I > gn && l > 1 ? ae.Weak : h, g !== h && (s == null || s(g), h = g, v += l, l = 0), d || (r == null || r(E.Start), c = o[o.length - 1], o = [], d = !0), o.push(Y);
607
+ else if (d && (t++, t >= fn)) {
608
+ const Q = rt(o, ke, c);
609
+ r == null || r(E.Stop, Q), n() || i(), v = k, d = !1;
569
610
  }
570
611
  }
571
612
  return {
572
613
  start: () => {
573
- a || (a = setInterval(z, Ee));
614
+ a || (a = setInterval(N, ke));
574
615
  },
575
616
  stop: () => {
576
617
  a && (clearInterval(a), a = null);
577
618
  },
578
- getReport: () => Xe(s, Ee, d)
619
+ getReport: () => rt(o, ke, c)
579
620
  };
580
621
  }
581
- const Ye = 2e4;
582
- async function cn() {
622
+ const it = 2e4;
623
+ async function pn() {
583
624
  try {
584
625
  return await import("./livekit-client.esm-RGXA_gNu.js");
585
626
  } catch {
@@ -588,7 +629,7 @@ async function cn() {
588
629
  );
589
630
  }
590
631
  }
591
- const dn = {
632
+ const wn = {
592
633
  excellent: ae.Strong,
593
634
  good: ae.Strong,
594
635
  poor: ae.Weak,
@@ -598,55 +639,55 @@ const dn = {
598
639
  kind: "InternalServerError",
599
640
  description: "Stream Error"
600
641
  });
601
- var Ne = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e))(Ne || {});
602
- function je(e, n, i) {
603
- var r, o;
604
- throw n("Failed to connect to LiveKit room:", e), (r = i.onConnectionStateChange) == null || r.call(i, L.Fail, "internal:init-error"), (o = i.onError) == null || o.call(i, e, { sessionId: "" }), e;
642
+ var Ue = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e))(Ue || {});
643
+ function Be(e, n, i) {
644
+ var r, s;
645
+ throw n("Failed to connect to LiveKit room:", e), (r = i.onConnectionStateChange) == null || r.call(i, x.Fail, "internal:init-error"), (s = i.onError) == null || s.call(i, e, { sessionId: "" }), e;
605
646
  }
606
- async function un(e, n, i) {
607
- var Ve;
608
- const r = dt(i.debug || !1, "LiveKitStreamingManager"), { Room: o, RoomEvent: a, ConnectionState: s, Track: d } = await cn(), { callbacks: t, auth: c, baseURL: h, analytics: g } = i;
647
+ async function yn(e, n, i) {
648
+ var Je;
649
+ const r = pt(i.debug || !1, "LiveKitStreamingManager"), { Room: s, RoomEvent: a, ConnectionState: o, Track: c } = await pn(), { callbacks: t, auth: d, baseURL: h, analytics: g } = i;
609
650
  let l = null, v = !1;
610
651
  const P = se.Fluent;
611
- let z = null;
612
- const x = { isPublishing: !1, publication: null }, F = { isPublishing: !1, publication: null };
613
- let M = null, E = null, Y = null, Q = !1;
614
- l = new o({
652
+ let N = null;
653
+ const B = { isPublishing: !1, publication: null }, F = { isPublishing: !1, publication: null };
654
+ let I = null, k = null, Y = null, Q = !1;
655
+ l = new s({
615
656
  adaptiveStream: !1,
616
657
  // Must be false to use mediaStreamTrack directly
617
658
  dynacast: !0
618
659
  });
619
- let J = null, te = W.Idle, ne = !0;
620
- const $ = Yt(c, h || Te, e, t.onError);
660
+ let U = null, te = W.Idle, ne = !0;
661
+ const $ = on(d, h || Ee, e, t.onError);
621
662
  let K, H, re, de = !0;
622
663
  try {
623
664
  const u = await $.createStream({
624
665
  transport: n.transport,
625
666
  chat_persist: n.chat_persist ?? !0
626
667
  }), { id: m, session_token: p, session_url: S, interrupt_enabled: _ } = u;
627
- (Ve = t.onStreamCreated) == null || Ve.call(t, { session_id: m, stream_id: m, agent_id: e }), K = m, H = p, re = S, de = _ ?? !0, await l.prepareConnection(re, H);
668
+ (Je = t.onStreamCreated) == null || Je.call(t, { session_id: m, stream_id: m, agent_id: e }), K = m, H = p, re = S, de = _ ?? !0, await l.prepareConnection(re, H);
628
669
  } catch (u) {
629
- je(u, r, t);
670
+ Be(u, r, t);
630
671
  }
631
672
  if (!re || !H || !K)
632
673
  return Promise.reject(new Error("Failed to initialize LiveKit stream"));
633
- l.on(a.ConnectionStateChanged, f).on(a.ConnectionQualityChanged, C).on(a.ParticipantConnected, R).on(a.ParticipantDisconnected, A).on(a.TrackSubscribed, U).on(a.TrackUnsubscribed, w).on(a.DataReceived, N).on(a.MediaDevicesError, ee).on(a.TranscriptionReceived, ue).on(a.EncryptionError, De).on(a.TrackSubscriptionFailed, le);
674
+ l.on(a.ConnectionStateChanged, f).on(a.ConnectionQualityChanged, C).on(a.ParticipantConnected, R).on(a.ParticipantDisconnected, A).on(a.TrackSubscribed, J).on(a.TrackUnsubscribed, w).on(a.DataReceived, z).on(a.MediaDevicesError, ee).on(a.TranscriptionReceived, ue).on(a.EncryptionError, De).on(a.TrackSubscriptionFailed, le);
634
675
  function ue(u, m) {
635
676
  var p;
636
677
  m != null && m.isLocal && (oe.update(), te === W.Talking && ((p = t.onInterruptDetected) == null || p.call(t, { type: "audio" }), te = W.Idle));
637
678
  }
638
679
  try {
639
- await l.connect(re, H), r("LiveKit room joined successfully"), J = setTimeout(() => {
680
+ await l.connect(re, H), r("LiveKit room joined successfully"), U = setTimeout(() => {
640
681
  var u;
641
682
  r(
642
- `Track subscription timeout - no track subscribed within ${Ye / 1e3} seconds after connect`
643
- ), J = null, g.track("connectivity-error", {
683
+ `Track subscription timeout - no track subscribed within ${it / 1e3} seconds after connect`
684
+ ), U = null, g.track("connectivity-error", {
644
685
  error: "Track subscription timeout",
645
686
  sessionId: K
646
- }), (u = t.onError) == null || u.call(t, new Error("Track subscription timeout"), { sessionId: K }), be("internal:track-subscription-timeout");
647
- }, Ye);
687
+ }), (u = t.onError) == null || u.call(t, new Error("Track subscription timeout"), { sessionId: K }), Le("internal:track-subscription-timeout");
688
+ }, it);
648
689
  } catch (u) {
649
- je(u, r, t);
690
+ Be(u, r, t);
650
691
  }
651
692
  g.enrich({
652
693
  "stream-type": P
@@ -654,92 +695,96 @@ async function un(e, n, i) {
654
695
  function f(u) {
655
696
  var m, p, S, _;
656
697
  switch (r("Connection state changed:", u), u) {
657
- case s.Connecting:
658
- r("CALLBACK: onConnectionStateChange(Connecting)"), (m = t.onConnectionStateChange) == null || m.call(t, L.Connecting, "livekit:connecting");
698
+ case o.Connecting:
699
+ r("CALLBACK: onConnectionStateChange(Connecting)"), (m = t.onConnectionStateChange) == null || m.call(t, x.Connecting, "livekit:connecting");
659
700
  break;
660
- case s.Connected:
701
+ case o.Connected:
661
702
  r("LiveKit room connected successfully"), v = !0;
662
703
  break;
663
- case s.Disconnected:
664
- r("LiveKit room disconnected"), v = !1, Q = !1, x.publication = null, F.publication = null, (p = t.onConnectionStateChange) == null || p.call(t, L.Disconnected, "livekit:disconnected");
704
+ case o.Disconnected:
705
+ r("LiveKit room disconnected"), v = !1, Q = !1, B.publication = null, F.publication = null, (p = t.onConnectionStateChange) == null || p.call(t, x.Disconnected, "livekit:disconnected");
665
706
  break;
666
- case s.Reconnecting:
667
- r("LiveKit room reconnecting..."), (S = t.onConnectionStateChange) == null || S.call(t, L.Connecting, "livekit:reconnecting");
707
+ case o.Reconnecting:
708
+ r("LiveKit room reconnecting..."), (S = t.onConnectionStateChange) == null || S.call(t, x.Connecting, "livekit:reconnecting");
668
709
  break;
669
- case s.SignalReconnecting:
670
- r("LiveKit room signal reconnecting..."), (_ = t.onConnectionStateChange) == null || _.call(t, L.Connecting, "livekit:signal-reconnecting");
710
+ case o.SignalReconnecting:
711
+ r("LiveKit room signal reconnecting..."), (_ = t.onConnectionStateChange) == null || _.call(t, x.Connecting, "livekit:signal-reconnecting");
671
712
  break;
672
713
  }
673
714
  }
674
715
  function C(u, m) {
675
716
  var p;
676
- r("Connection quality:", u), m != null && m.isLocal && ((p = t.onConnectivityStateChange) == null || p.call(t, dn[u]));
717
+ r("Connection quality:", u), m != null && m.isLocal && ((p = t.onConnectivityStateChange) == null || p.call(t, wn[u]));
677
718
  }
678
719
  function R(u) {
679
720
  r("Participant connected:", u.identity);
680
721
  }
681
722
  function A(u) {
682
- r("Participant disconnected:", u.identity), be("livekit:participant-disconnected");
723
+ r("Participant disconnected:", u.identity), Le("livekit:participant-disconnected");
683
724
  }
684
- function I() {
725
+ function D() {
685
726
  var u;
686
- Y !== T.Start && (r("CALLBACK: onVideoStateChange(Start)"), Y = T.Start, (u = t.onVideoStateChange) == null || u.call(t, T.Start));
727
+ Y !== E.Start && (r("CALLBACK: onVideoStateChange(Start)"), Y = E.Start, (u = t.onVideoStateChange) == null || u.call(t, E.Start));
687
728
  }
688
729
  function b(u) {
689
730
  var m;
690
- Y !== T.Stop && (r("CALLBACK: onVideoStateChange(Stop)"), Y = T.Stop, (m = t.onVideoStateChange) == null || m.call(t, T.Stop, u));
731
+ Y !== E.Stop && (r("CALLBACK: onVideoStateChange(Stop)"), Y = E.Stop, (m = t.onVideoStateChange) == null || m.call(t, E.Stop, u));
691
732
  }
692
- function U(u, m, p) {
693
- var _, j, q;
733
+ function J(u, m, p) {
734
+ var _, L, q;
694
735
  r(`Track subscribed: ${u.kind} from ${p.identity}`);
695
736
  const S = u.mediaStreamTrack;
696
737
  if (!S) {
697
738
  r(`No mediaStreamTrack available for ${u.kind}`);
698
739
  return;
699
740
  }
700
- z ? (z.addTrack(S), r(`Added ${u.kind} track to shared MediaStream`)) : (z = new MediaStream([S]), r(`Created shared MediaStream with ${u.kind} track`)), u.kind === "audio" && (E = nn(
741
+ N ? (N.addTrack(S), r(`Added ${u.kind} track to shared MediaStream`)) : (N = new MediaStream([S]), r(`Created shared MediaStream with ${u.kind} track`)), u.kind === "audio" && (k = ln(
701
742
  () => u.getRTCStatsReport(),
702
743
  ({ sttLatency: V, serviceLatency: ie }) => {
703
- var Je, Ue, Oe;
744
+ var Oe, We, He;
704
745
  const ye = oe.get(!0);
705
746
  let ve = 0;
706
747
  if (V) {
707
- const We = ((Ue = (Je = M == null ? void 0 : M.getReport()) == null ? void 0 : Je.webRTCStats) == null ? void 0 : Ue.avgRtt) ?? 0;
708
- ve = We > 0 ? Math.round(We * 1e3) : 0;
748
+ const qe = ((We = (Oe = I == null ? void 0 : I.getReport()) == null ? void 0 : Oe.webRTCStats) == null ? void 0 : We.avgRtt) ?? 0;
749
+ ve = qe > 0 ? Math.round(qe * 1e3) : 0;
709
750
  }
710
751
  const fe = ye > 0 ? ye + (V ?? 0) + ve : void 0, ce = fe !== void 0 && ie !== void 0 ? fe - ie : void 0;
711
- (Oe = t.onFirstAudioDetected) == null || Oe.call(t, { latency: fe, networkLatency: ce });
752
+ (He = t.onFirstAudioDetected) == null || He.call(t, { latency: fe, networkLatency: ce });
712
753
  }
713
- )), u.kind === "video" && ((_ = t.onStreamReady) == null || _.call(t), r("CALLBACK: onSrcObjectReady"), (j = t.onSrcObjectReady) == null || j.call(t, z), Q || (Q = !0, r("CALLBACK: onConnectionStateChange(Connected)"), (q = t.onConnectionStateChange) == null || q.call(t, L.Connected, "livekit:track-subscribed")), M = lt(
754
+ )), u.kind === "video" && ((_ = t.onStreamReady) == null || _.call(t), r("CALLBACK: onSrcObjectReady"), (L = t.onSrcObjectReady) == null || L.call(t, N), Q || (Q = !0, r("CALLBACK: onConnectionStateChange(Connected)"), (q = t.onConnectionStateChange) == null || q.call(t, x.Connected, "livekit:track-subscribed")), I = yt(
714
755
  () => u.getRTCStatsReport(),
715
756
  () => v,
716
- jt,
757
+ Vt,
717
758
  (V, ie) => {
718
- r(`Video state change: ${V}`), V === T.Start ? (J && (clearTimeout(J), J = null, r("Track subscription timeout cleared")), I()) : V === T.Stop && b(ie);
759
+ r(`Video state change: ${V}`), V === E.Start ? (U && (clearTimeout(U), U = null, r("Track subscription timeout cleared")), D()) : V === E.Stop && b(ie);
719
760
  }
720
- ), M.start());
761
+ ), I.start());
721
762
  }
722
763
  function w(u, m, p) {
723
- r(`Track unsubscribed: ${u.kind} from ${p.identity}`), u.kind === "audio" && (E == null || E.destroy(), E = null), u.kind === "video" && (b(M == null ? void 0 : M.getReport()), M == null || M.stop(), M = null);
764
+ r(`Track unsubscribed: ${u.kind} from ${p.identity}`), u.kind === "audio" && (k == null || k.destroy(), k = null), u.kind === "video" && (b(I == null ? void 0 : I.getReport()), I == null || I.stop(), I = null);
724
765
  }
725
766
  function y(u, m) {
726
767
  var S;
727
- const p = Gt[u];
768
+ const p = sn[u];
728
769
  p && ((S = t.onMessage) == null || S.call(t, p, { event: p, ...m }));
729
770
  }
730
- function k(u, m) {
731
- var p, S, _;
732
- if (u === D.ToolCalling) {
733
- te = W.ToolActive, (p = t.onAgentActivityStateChange) == null || p.call(t, W.ToolActive), (S = t.onToolEvent) == null || S.call(t, D.ToolCalling, m);
771
+ function T(u, m) {
772
+ var p, S, _, L;
773
+ if (u === M.ToolCallStarted) {
774
+ te = W.ToolActive, (p = t.onAgentActivityStateChange) == null || p.call(t, W.ToolActive), (S = t.onToolEvent) == null || S.call(t, M.ToolCallStarted, m);
775
+ return;
776
+ }
777
+ if (u === M.ToolCallDone) {
778
+ (_ = t.onToolEvent) == null || _.call(t, M.ToolCallDone, m);
734
779
  return;
735
780
  }
736
- u === D.ToolResult && ((_ = t.onToolEvent) == null || _.call(t, D.ToolResult, m));
781
+ u === M.ToolCallError && ((L = t.onToolEvent) == null || L.call(t, M.ToolCallError, m));
737
782
  }
738
- function B(u, m) {
739
- var p, S, _, j, q;
740
- if (ne = ((p = m.metadata) == null ? void 0 : p.interruptible) !== !1, (S = t.onInterruptibleChange) == null || S.call(t, ne), u === D.StreamVideoCreated) {
741
- te = W.Talking, (_ = t.onAgentActivityStateChange) == null || _.call(t, W.Talking), E == null || E.arm({
742
- sttLatency: (j = m == null ? void 0 : m.stt) == null ? void 0 : j.latency,
783
+ function j(u, m) {
784
+ var p, S, _, L, q;
785
+ if (ne = ((p = m.metadata) == null ? void 0 : p.interruptible) !== !1, (S = t.onInterruptibleChange) == null || S.call(t, ne), u === M.StreamVideoCreated) {
786
+ te = W.Talking, (_ = t.onAgentActivityStateChange) == null || _.call(t, W.Talking), k == null || k.arm({
787
+ sttLatency: (L = m == null ? void 0 : m.stt) == null ? void 0 : L.latency,
743
788
  serviceLatency: m == null ? void 0 : m.serviceLatency
744
789
  });
745
790
  return;
@@ -747,12 +792,12 @@ async function un(e, n, i) {
747
792
  ne && (te = W.Idle, (q = t.onAgentActivityStateChange) == null || q.call(t, W.Idle));
748
793
  }
749
794
  function G(u, m) {
750
- var j, q, V, ie;
751
- const p = ((q = (j = M == null ? void 0 : M.getReport()) == null ? void 0 : j.webRTCStats) == null ? void 0 : q.avgRtt) ?? 0, S = p > 0 ? Math.round(p / 2 * 1e3) : 0, _ = { ...m, downstreamNetworkLatency: S };
795
+ var L, q, V, ie;
796
+ const p = ((q = (L = I == null ? void 0 : I.getReport()) == null ? void 0 : L.webRTCStats) == null ? void 0 : q.avgRtt) ?? 0, S = p > 0 ? Math.round(p / 2 * 1e3) : 0, _ = { ...m, downstreamNetworkLatency: S };
752
797
  i.debug && ((V = m == null ? void 0 : m.metadata) != null && V.sentiment) && (_.sentiment = {
753
798
  id: m.metadata.sentiment.id,
754
799
  name: m.metadata.sentiment.sentiment
755
- }), (ie = t.onMessage) == null || ie.call(t, u, _), B(u, m);
800
+ }), (ie = t.onMessage) == null || ie.call(t, u, _), j(u, m);
756
801
  }
757
802
  function he(u, m) {
758
803
  var p;
@@ -762,25 +807,26 @@ async function un(e, n, i) {
762
807
  });
763
808
  }
764
809
  const Z = {
765
- [D.ChatAnswer]: y,
766
- [D.ChatPartial]: y,
767
- [D.ToolCalling]: k,
768
- [D.ToolResult]: k,
769
- [D.StreamVideoCreated]: G,
770
- [D.StreamVideoDone]: G,
771
- [D.StreamVideoError]: G,
772
- [D.StreamVideoRejected]: G,
773
- [D.ChatAudioTranscribed]: he
810
+ [M.ChatAnswer]: y,
811
+ [M.ChatPartial]: y,
812
+ [M.ToolCallStarted]: T,
813
+ [M.ToolCallDone]: T,
814
+ [M.ToolCallError]: T,
815
+ [M.StreamVideoCreated]: G,
816
+ [M.StreamVideoDone]: G,
817
+ [M.StreamVideoError]: G,
818
+ [M.StreamVideoRejected]: G,
819
+ [M.ChatAudioTranscribed]: he
774
820
  };
775
- function N(u, m, p, S) {
821
+ function z(u, m, p, S) {
776
822
  const _ = new TextDecoder().decode(u);
777
823
  try {
778
- const j = JSON.parse(_), q = S || j.subject;
779
- if (r("Data received:", { subject: q, data: j }), !q) return;
824
+ const L = JSON.parse(_), q = S || L.subject;
825
+ if (r("Data received:", { subject: q, data: L }), !q) return;
780
826
  const V = Z[q];
781
- V == null || V(q, j);
782
- } catch (j) {
783
- r("Failed to parse data channel message:", j);
827
+ V == null || V(q, L);
828
+ } catch (L) {
829
+ r("Failed to parse data channel message:", L);
784
830
  }
785
831
  }
786
832
  function ee(u) {
@@ -794,16 +840,16 @@ async function un(e, n, i) {
794
840
  function le(u, m, p) {
795
841
  r("Track subscription failed:", { trackSid: u, participant: m, reason: p });
796
842
  }
797
- function ke(u, m, p) {
843
+ function Me(u, m, p) {
798
844
  for (const [S, _] of p)
799
845
  if (_.source === m && _.track) {
800
- const j = _.track.mediaStreamTrack;
801
- if (j === u || (j == null ? void 0 : j.id) === u.id)
846
+ const L = _.track.mediaStreamTrack;
847
+ if (L === u || (L == null ? void 0 : L.id) === u.id)
802
848
  return _;
803
849
  }
804
850
  return null;
805
851
  }
806
- async function pe(u, m, p, S, _, j) {
852
+ async function pe(u, m, p, S, _, L) {
807
853
  var ye, ve, fe;
808
854
  if (!v || !l)
809
855
  throw r(`Room is not connected, cannot publish ${S} stream`), new Error("Room is not connected");
@@ -814,7 +860,7 @@ async function un(e, n, i) {
814
860
  const q = p(m);
815
861
  if (q.length === 0)
816
862
  throw new Error(`No ${S} track found in the provided MediaStream`);
817
- const V = q[0], ie = ke(V, S, _());
863
+ const V = q[0], ie = Me(V, S, _());
818
864
  if (ie) {
819
865
  r(`${S} track is already published, skipping`, {
820
866
  trackId: V.id,
@@ -824,7 +870,7 @@ async function un(e, n, i) {
824
870
  }
825
871
  if ((fe = u.publication) != null && fe.track) {
826
872
  const ce = u.publication.track.mediaStreamTrack;
827
- ce !== V && (ce == null ? void 0 : ce.id) !== V.id && (r(`Unpublishing existing ${S} track before publishing new one`), await j());
873
+ ce !== V && (ce == null ? void 0 : ce.id) !== V.id && (r(`Unpublishing existing ${S} track before publishing new one`), await L());
828
874
  }
829
875
  r(`Publishing ${S} track from provided MediaStream`, { trackId: V.id }), u.isPublishing = !0;
830
876
  try {
@@ -845,36 +891,36 @@ async function un(e, n, i) {
845
891
  u.publication = null;
846
892
  }
847
893
  }
848
- async function ft(u) {
894
+ async function vt(u) {
849
895
  return pe(
850
- x,
896
+ B,
851
897
  u,
852
898
  (m) => m.getAudioTracks(),
853
- d.Source.Microphone,
899
+ c.Source.Microphone,
854
900
  () => l.localParticipant.audioTrackPublications,
855
- Ie
901
+ Ae
856
902
  );
857
903
  }
858
- async function Ie() {
859
- return we(x, "Microphone");
904
+ async function Ae() {
905
+ return we(B, "Microphone");
860
906
  }
861
- async function mt(u) {
907
+ async function Ct(u) {
862
908
  return pe(
863
909
  F,
864
910
  u,
865
911
  (m) => m.getVideoTracks(),
866
- d.Source.Camera,
912
+ c.Source.Camera,
867
913
  () => l.localParticipant.videoTrackPublications,
868
- Ae
914
+ _e
869
915
  );
870
916
  }
871
- async function Ae() {
917
+ async function _e() {
872
918
  return we(F, "Camera");
873
919
  }
874
- function gt() {
875
- z && (z.getTracks().forEach((u) => u.stop()), z = null);
920
+ function St() {
921
+ N && (N.getTracks().forEach((u) => u.stop()), N = null);
876
922
  }
877
- async function _e(u, m) {
923
+ async function be(u, m) {
878
924
  var p, S;
879
925
  if (!v || !l) {
880
926
  r("Room is not connected for sending messages"), (p = t.onError) == null || p.call(t, new Error(Re), {
@@ -888,68 +934,68 @@ async function un(e, n, i) {
888
934
  r("Failed to send message:", _), (S = t.onError) == null || S.call(t, new Error(Re), { sessionId: K });
889
935
  }
890
936
  }
891
- async function ht(u) {
937
+ async function Rt(u) {
892
938
  var m;
893
939
  try {
894
940
  const S = JSON.parse(u).topic;
895
- return _e("", S);
941
+ return be("", S);
896
942
  } catch (p) {
897
943
  r("Failed to send data channel message:", p), (m = t.onError) == null || m.call(t, new Error(Re), { sessionId: K });
898
944
  }
899
945
  }
900
- function pt(u) {
901
- return _e(
946
+ function Tt(u) {
947
+ return be(
902
948
  u,
903
949
  "lk.chat"
904
950
  /* Chat */
905
951
  );
906
952
  }
907
- async function be(u) {
953
+ async function Le(u) {
908
954
  var m, p;
909
- J && (clearTimeout(J), J = null), E == null || E.destroy(), E = null, l && ((m = t.onConnectionStateChange) == null || m.call(t, L.Disconnecting, u), await Promise.all([Ie(), Ae()]), await l.disconnect()), gt(), v = !1, Q = !1, (p = t.onAgentActivityStateChange) == null || p.call(t, W.Idle), te = W.Idle;
955
+ U && (clearTimeout(U), U = null), k == null || k.destroy(), k = null, l && ((m = t.onConnectionStateChange) == null || m.call(t, x.Disconnecting, u), await Promise.all([Ae(), _e()]), await l.disconnect()), St(), v = !1, Q = !1, (p = t.onAgentActivityStateChange) == null || p.call(t, W.Idle), te = W.Idle;
910
956
  }
911
957
  return {
912
958
  speak(u) {
913
959
  const m = typeof u == "string" ? u : JSON.stringify(u);
914
- return _e(
960
+ return be(
915
961
  m,
916
962
  "did.speak"
917
963
  /* Speak */
918
964
  );
919
965
  },
920
- disconnect: () => be("user:disconnect"),
966
+ disconnect: () => Le("user:disconnect"),
921
967
  async reconnect() {
922
968
  var u, m;
923
- if ((l == null ? void 0 : l.state) === s.Connected) {
969
+ if ((l == null ? void 0 : l.state) === o.Connected) {
924
970
  r("Room is already connected");
925
971
  return;
926
972
  }
927
973
  if (!l || !re || !H)
928
974
  throw r("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
929
- r("Reconnecting to LiveKit room, state:", l.state), Q = !1, (u = t.onConnectionStateChange) == null || u.call(t, L.Connecting, "user:reconnect");
975
+ r("Reconnecting to LiveKit room, state:", l.state), Q = !1, (u = t.onConnectionStateChange) == null || u.call(t, x.Connecting, "user:reconnect");
930
976
  try {
931
977
  if (await l.connect(re, H), r("Room reconnected"), v = !0, l.remoteParticipants.size === 0) {
932
978
  if (r("Waiting for agent to join..."), !await new Promise((S) => {
933
979
  const _ = setTimeout(() => {
934
- l == null || l.off(a.ParticipantConnected, j), S(!1);
935
- }, 5e3), j = () => {
936
- clearTimeout(_), l == null || l.off(a.ParticipantConnected, j), S(!0);
980
+ l == null || l.off(a.ParticipantConnected, L), S(!1);
981
+ }, 5e3), L = () => {
982
+ clearTimeout(_), l == null || l.off(a.ParticipantConnected, L), S(!0);
937
983
  };
938
- l == null || l.on(a.ParticipantConnected, j);
984
+ l == null || l.on(a.ParticipantConnected, L);
939
985
  }))
940
986
  throw r("Agent did not join within timeout"), await l.disconnect(), new Error("Agent did not rejoin the room");
941
987
  r("Agent joined, reconnection successful");
942
988
  }
943
989
  } catch (p) {
944
- throw r("Failed to reconnect:", p), (m = t.onConnectionStateChange) == null || m.call(t, L.Fail, "user:reconnect-failed"), p;
990
+ throw r("Failed to reconnect:", p), (m = t.onConnectionStateChange) == null || m.call(t, x.Fail, "user:reconnect-failed"), p;
945
991
  }
946
992
  },
947
- sendDataChannelMessage: ht,
948
- sendTextMessage: pt,
949
- publishMicrophoneStream: ft,
950
- unpublishMicrophoneStream: Ie,
951
- publishCameraStream: mt,
952
- unpublishCameraStream: Ae,
993
+ sendDataChannelMessage: Rt,
994
+ sendTextMessage: Tt,
995
+ publishMicrophoneStream: vt,
996
+ unpublishMicrophoneStream: Ae,
997
+ publishCameraStream: Ct,
998
+ unpublishCameraStream: _e,
953
999
  registerRpcMethod(u, m) {
954
1000
  l == null || l.registerRpcMethod(u, m);
955
1001
  },
@@ -963,13 +1009,13 @@ async function un(e, n, i) {
963
1009
  isInterruptible: ne
964
1010
  };
965
1011
  }
966
- const ln = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1012
+ const vn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
967
1013
  __proto__: null,
968
- DataChannelTopic: Ne,
969
- createLiveKitStreamingManager: un,
970
- handleInitError: je
1014
+ DataChannelTopic: Ue,
1015
+ createLiveKitStreamingManager: yn,
1016
+ handleInitError: Be
971
1017
  }, Symbol.toStringTag, { value: "Module" }));
972
- function fn(e, n, i) {
1018
+ function Cn(e, n, i) {
973
1019
  if (!e)
974
1020
  throw new Error("Please connect to the agent first");
975
1021
  if (!e.interruptAvailable)
@@ -979,66 +1025,66 @@ function fn(e, n, i) {
979
1025
  if (!i)
980
1026
  throw new Error("No active video to interrupt");
981
1027
  }
982
- async function mn(e, n) {
1028
+ async function Sn(e, n) {
983
1029
  const i = {
984
- type: D.StreamInterrupt,
1030
+ type: M.StreamInterrupt,
985
1031
  videoId: n,
986
1032
  timestamp: Date.now()
987
1033
  };
988
1034
  e.sendDataChannelMessage(JSON.stringify(i));
989
1035
  }
990
- async function gn(e) {
1036
+ async function Rn(e) {
991
1037
  const n = {
992
- topic: Ne.Interrupt
1038
+ topic: Ue.Interrupt
993
1039
  };
994
1040
  e.sendDataChannelMessage(JSON.stringify(n));
995
1041
  }
996
- function hn(e) {
1042
+ function Tn(e) {
997
1043
  return new Promise((n, i) => {
998
- const { callbacks: r, host: o, auth: a, externalId: s } = e, { onMessage: d = null, onOpen: t = null, onClose: c = null, onError: h = null } = r || {}, g = new WebSocket(`${o}?authorization=${encodeURIComponent(ot(a, s))}`);
999
- g.onmessage = d, g.onclose = c, g.onerror = (l) => {
1044
+ const { callbacks: r, host: s, auth: a, externalId: o } = e, { onMessage: c = null, onOpen: t = null, onClose: d = null, onError: h = null } = r || {}, g = new WebSocket(`${s}?authorization=${encodeURIComponent(mt(a, o))}`);
1045
+ g.onmessage = c, g.onclose = d, g.onerror = (l) => {
1000
1046
  console.error(l), h == null || h("Websocket failed to connect", l), i(l);
1001
1047
  }, g.onopen = (l) => {
1002
1048
  t == null || t(l), n(g);
1003
1049
  };
1004
1050
  });
1005
1051
  }
1006
- async function pn(e) {
1052
+ async function En(e) {
1007
1053
  const { retries: n = 1 } = e;
1008
1054
  let i = null;
1009
1055
  for (let r = 0; (i == null ? void 0 : i.readyState) !== WebSocket.OPEN; r++)
1010
1056
  try {
1011
- i = await hn(e);
1012
- } catch (o) {
1057
+ i = await Tn(e);
1058
+ } catch (s) {
1013
1059
  if (r === n)
1014
- throw o;
1015
- await rt(r * 500);
1060
+ throw s;
1061
+ await ut(r * 500);
1016
1062
  }
1017
1063
  return i;
1018
1064
  }
1019
- async function wn(e, n, i, r) {
1020
- const o = i != null && i.onMessage ? [i.onMessage] : [], a = await pn({
1065
+ async function Mn(e, n, i, r) {
1066
+ const s = i != null && i.onMessage ? [i.onMessage] : [], a = await En({
1021
1067
  auth: e,
1022
1068
  host: n,
1023
1069
  externalId: r,
1024
1070
  callbacks: {
1025
- onError: (s) => {
1026
- var d;
1027
- return (d = i.onError) == null ? void 0 : d.call(i, new St(s));
1071
+ onError: (o) => {
1072
+ var c;
1073
+ return (c = i.onError) == null ? void 0 : c.call(i, new Dt(o));
1028
1074
  },
1029
- onMessage(s) {
1030
- const d = JSON.parse(s.data);
1031
- o.forEach((t) => t(d.event, d));
1075
+ onMessage(o) {
1076
+ const c = JSON.parse(o.data);
1077
+ s.forEach((t) => t(c.event, c));
1032
1078
  }
1033
1079
  }
1034
1080
  });
1035
1081
  return {
1036
1082
  socket: a,
1037
1083
  disconnect: () => a.close(),
1038
- subscribeToEvents: (s) => o.push(s)
1084
+ subscribeToEvents: (o) => s.push(o)
1039
1085
  };
1040
1086
  }
1041
- function yn(e) {
1087
+ function kn(e) {
1042
1088
  if (e.answer !== void 0)
1043
1089
  return e.answer;
1044
1090
  let n = 0, i = "";
@@ -1046,219 +1092,221 @@ function yn(e) {
1046
1092
  i += e[n++];
1047
1093
  return i;
1048
1094
  }
1049
- function vn(e, n, i) {
1095
+ function In(e, n, i) {
1050
1096
  if (!e.content)
1051
1097
  return;
1052
1098
  const r = n.messages[n.messages.length - 1];
1053
1099
  (r == null ? void 0 : r.role) === "assistant" && !r.interrupted && (r.interrupted = !0);
1054
- const o = {
1100
+ const s = {
1055
1101
  id: e.id || `user-${Date.now()}`,
1056
1102
  role: e.role,
1057
1103
  content: e.content,
1104
+ parts: Te(e.content),
1058
1105
  created_at: e.created_at || (/* @__PURE__ */ new Date()).toISOString(),
1059
1106
  transcribed: !0
1060
1107
  };
1061
- n.messages.push(o), i == null || i([...n.messages], "user");
1108
+ n.messages.push(s), i == null || i([...n.messages], "user");
1062
1109
  }
1063
- function Cn(e, n, i, r, o) {
1110
+ function Dn(e, n, i, r, s, a) {
1064
1111
  if (e === X.Transcribe && n.content) {
1065
- vn(n, r, o);
1112
+ In(n, r, s);
1066
1113
  return;
1067
1114
  }
1068
1115
  if (!(e === X.Partial || e === X.Answer))
1069
1116
  return;
1070
- const a = r.messages[r.messages.length - 1];
1071
- let s;
1072
- if (a != null && a.transcribed && a.role === "user")
1073
- e === X.Answer && n.content, s = {
1117
+ const o = r.messages[r.messages.length - 1], c = n.id && (o == null ? void 0 : o.role) === "assistant" && o.id !== n.id;
1118
+ let t;
1119
+ if ((o == null ? void 0 : o.role) === "assistant" && !c)
1120
+ t = o;
1121
+ else if (!o || o.transcribed && o.role === "user" || c)
1122
+ c && a(), t = {
1074
1123
  id: n.id || `assistant-${Date.now()}`,
1075
1124
  role: n.role || "assistant",
1076
1125
  content: n.content || "",
1126
+ parts: [],
1077
1127
  created_at: n.created_at || (/* @__PURE__ */ new Date()).toISOString()
1078
- }, r.messages.push(s);
1079
- else if ((a == null ? void 0 : a.role) === "assistant")
1080
- s = a;
1128
+ }, r.messages.push(t);
1081
1129
  else
1082
1130
  return;
1083
- const { content: d, sequence: t } = n;
1084
- e === X.Partial ? i[t] = d : i.answer = d;
1085
- const c = yn(i);
1086
- (s.content !== c || e === X.Answer) && (s.content = c, o == null || o([...r.messages], e));
1131
+ const { content: d, sequence: h } = n;
1132
+ e === X.Partial ? i[h] = d : i.answer = d;
1133
+ const g = kn(i);
1134
+ (t.content !== g || e === X.Answer) && (t.content = g, t.parts = Te(g), s == null || s([...r.messages], e));
1087
1135
  }
1088
- function Sn(e, n, i, r, o) {
1136
+ function An(e, n, i, r, s) {
1089
1137
  let a = {};
1090
- const s = () => a = {};
1091
- let d = "answer";
1092
- const t = (c, h) => {
1138
+ const o = () => a = {};
1139
+ let c = "answer";
1140
+ const t = (d, h) => {
1093
1141
  var g, l;
1094
- h === "user" && s(), d = h, (l = (g = i.callbacks).onNewMessage) == null || l.call(g, c, h);
1142
+ h === "user" && o(), c = h, (l = (g = i.callbacks).onNewMessage) == null || l.call(g, d, h);
1095
1143
  };
1096
1144
  return {
1097
- clearQueue: s,
1098
- onMessage: (c, h) => {
1145
+ clearQueue: o,
1146
+ onMessage: (d, h) => {
1099
1147
  var g, l;
1100
1148
  if ("content" in h) {
1101
- const v = c === D.ChatAnswer ? X.Answer : c === D.ChatAudioTranscribed ? X.Transcribe : c;
1102
- Cn(v, h, a, n, t), v === X.Answer && e.track("agent-message-received", {
1149
+ const v = d === M.ChatAnswer ? X.Answer : d === M.ChatAudioTranscribed ? X.Transcribe : d;
1150
+ Dn(v, h, a, n, t, o), v === X.Answer && e.track("agent-message-received", {
1103
1151
  content: h.content,
1104
1152
  messages: n.messages.length,
1105
1153
  mode: n.chatMode
1106
1154
  });
1107
1155
  } else {
1108
- const v = D, P = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], z = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], x = Wt(h, r, { mode: n.chatMode });
1109
- if (c = c, c === v.StreamVideoCreated && (e.linkTrack("agent-video", x, v.StreamVideoCreated, ["start"]), h.sentiment)) {
1156
+ const v = M, P = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], N = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], B = en(h, r, { mode: n.chatMode });
1157
+ if (d = d, d === v.StreamVideoCreated && (e.linkTrack("agent-video", B, v.StreamVideoCreated, ["start"]), h.sentiment)) {
1110
1158
  const F = n.messages[n.messages.length - 1];
1111
1159
  if ((F == null ? void 0 : F.role) === "assistant") {
1112
- const M = { ...F, sentiment: h.sentiment };
1113
- n.messages[n.messages.length - 1] = M, t == null || t([...n.messages], d);
1160
+ const I = { ...F, sentiment: h.sentiment };
1161
+ n.messages[n.messages.length - 1] = I, t == null || t([...n.messages], c);
1114
1162
  }
1115
1163
  }
1116
- if (P.includes(c)) {
1117
- const F = c.split("/")[1];
1118
- z.includes(c) ? e.track("agent-video", { ...x, event: F }) : e.linkTrack("agent-video", { ...x, event: F }, c, ["done"]);
1164
+ if (P.includes(d)) {
1165
+ const F = d.split("/")[1];
1166
+ N.includes(d) ? e.track("agent-video", { ...B, event: F }) : e.linkTrack("agent-video", { ...B, event: F }, d, ["done"]);
1119
1167
  }
1120
- z.includes(c) && ((l = (g = i.callbacks).onError) == null || l.call(g, new Error(`Stream failed with event ${c}`), { data: h })), h.event === v.StreamDone && o();
1168
+ N.includes(d) && ((l = (g = i.callbacks).onError) == null || l.call(g, new Error(`Stream failed with event ${d}`), { data: h })), h.event === v.StreamDone && s();
1121
1169
  }
1122
1170
  }
1123
1171
  };
1124
1172
  }
1125
- function Rn(e, n, i, r) {
1126
- const o = ze(e, `${n}/agents/${i}`, r);
1173
+ function _n(e, n, i, r) {
1174
+ const s = ze(e, `${n}/agents/${i}`, r);
1127
1175
  return {
1128
- createStream(a, s) {
1129
- return o.post("/streams", a, { signal: s });
1176
+ createStream(a, o) {
1177
+ return s.post("/streams", a, { signal: o });
1130
1178
  },
1131
- startConnection(a, s, d, t) {
1132
- return o.post(
1179
+ startConnection(a, o, c, t) {
1180
+ return s.post(
1133
1181
  `/streams/${a}/sdp`,
1134
1182
  {
1135
- session_id: d,
1136
- answer: s
1183
+ session_id: c,
1184
+ answer: o
1137
1185
  },
1138
1186
  { signal: t }
1139
1187
  );
1140
1188
  },
1141
- addIceCandidate(a, s, d, t) {
1142
- return o.post(
1189
+ addIceCandidate(a, o, c, t) {
1190
+ return s.post(
1143
1191
  `/streams/${a}/ice`,
1144
1192
  {
1145
- session_id: d,
1146
- ...s
1193
+ session_id: c,
1194
+ ...o
1147
1195
  },
1148
1196
  { signal: t }
1149
1197
  );
1150
1198
  },
1151
- sendStreamRequest(a, s, d) {
1152
- return o.post(`/streams/${a}`, {
1153
- session_id: s,
1154
- ...d
1199
+ sendStreamRequest(a, o, c) {
1200
+ return s.post(`/streams/${a}`, {
1201
+ session_id: o,
1202
+ ...c
1155
1203
  });
1156
1204
  },
1157
- close(a, s) {
1158
- return o.delete(`/streams/${a}`, { session_id: s });
1205
+ close(a, o) {
1206
+ return s.delete(`/streams/${a}`, { session_id: o });
1159
1207
  }
1160
1208
  };
1161
1209
  }
1162
- const Tn = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
1163
- function Ge(e) {
1210
+ const bn = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
1211
+ function at(e) {
1164
1212
  switch (e) {
1165
1213
  case "connected":
1166
- return L.Connected;
1214
+ return x.Connected;
1167
1215
  case "checking":
1168
- return L.Connecting;
1216
+ return x.Connecting;
1169
1217
  case "failed":
1170
- return L.Fail;
1218
+ return x.Fail;
1171
1219
  case "new":
1172
- return L.New;
1220
+ return x.New;
1173
1221
  case "closed":
1174
- return L.Closed;
1222
+ return x.Closed;
1175
1223
  case "disconnected":
1176
- return L.Disconnected;
1224
+ return x.Disconnected;
1177
1225
  case "completed":
1178
- return L.Completed;
1226
+ return x.Completed;
1179
1227
  default:
1180
- return L.New;
1228
+ return x.New;
1181
1229
  }
1182
1230
  }
1183
- const kn = (e) => (n) => {
1231
+ const Ln = (e) => (n) => {
1184
1232
  const [i, r = ""] = n.split(/:(.+)/);
1185
1233
  try {
1186
- const o = JSON.parse(r);
1187
- return e("parsed data channel message", { subject: i, data: o }), { subject: i, data: o };
1188
- } catch (o) {
1189
- return e("Failed to parse data channel message, returning data as string", { subject: i, rawData: r, error: o }), { subject: i, data: r };
1234
+ const s = JSON.parse(r);
1235
+ return e("parsed data channel message", { subject: i, data: s }), { subject: i, data: s };
1236
+ } catch (s) {
1237
+ return e("Failed to parse data channel message, returning data as string", { subject: i, rawData: r, error: s }), { subject: i, data: r };
1190
1238
  }
1191
1239
  };
1192
- function En({
1240
+ function Pn({
1193
1241
  statsSignal: e,
1194
1242
  dataChannelSignal: n,
1195
1243
  onVideoStateChange: i,
1196
1244
  report: r,
1197
- log: o
1245
+ log: s
1198
1246
  }) {
1199
- e === T.Start && n === T.Start ? (o("CALLBACK: onVideoStateChange(Start)"), i == null || i(T.Start)) : e === T.Stop && n === T.Stop && (o("CALLBACK: onVideoStateChange(Stop)"), i == null || i(T.Stop, r));
1247
+ e === E.Start && n === E.Start ? (s("CALLBACK: onVideoStateChange(Start)"), i == null || i(E.Start)) : e === E.Stop && n === E.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), i == null || i(E.Stop, r));
1200
1248
  }
1201
- function Mn({
1249
+ function xn({
1202
1250
  statsSignal: e,
1203
1251
  dataChannelSignal: n,
1204
1252
  onVideoStateChange: i,
1205
1253
  onAgentActivityStateChange: r,
1206
- report: o,
1254
+ report: s,
1207
1255
  log: a
1208
1256
  }) {
1209
- e === T.Start ? (a("CALLBACK: onVideoStateChange(Start)"), i == null || i(T.Start)) : e === T.Stop && (a("CALLBACK: onVideoStateChange(Stop)"), i == null || i(T.Stop, o)), n === T.Start ? r == null || r(W.Talking) : n === T.Stop && (r == null || r(W.Idle));
1257
+ e === E.Start ? (a("CALLBACK: onVideoStateChange(Start)"), i == null || i(E.Start)) : e === E.Stop && (a("CALLBACK: onVideoStateChange(Stop)"), i == null || i(E.Stop, s)), n === E.Start ? r == null || r(W.Talking) : n === E.Stop && (r == null || r(W.Idle));
1210
1258
  }
1211
- function Ze({
1259
+ function ot({
1212
1260
  statsSignal: e,
1213
1261
  dataChannelSignal: n,
1214
1262
  onVideoStateChange: i,
1215
1263
  onAgentActivityStateChange: r,
1216
- streamType: o,
1264
+ streamType: s,
1217
1265
  report: a,
1218
- log: s
1266
+ log: o
1219
1267
  }) {
1220
- o === se.Legacy ? En({ statsSignal: e, dataChannelSignal: n, onVideoStateChange: i, report: a, log: s }) : o === se.Fluent && Mn({
1268
+ s === se.Legacy ? Pn({ statsSignal: e, dataChannelSignal: n, onVideoStateChange: i, report: a, log: o }) : s === se.Fluent && xn({
1221
1269
  statsSignal: e,
1222
1270
  dataChannelSignal: n,
1223
1271
  onVideoStateChange: i,
1224
1272
  onAgentActivityStateChange: r,
1225
1273
  report: a,
1226
- log: s
1274
+ log: o
1227
1275
  });
1228
1276
  }
1229
- async function Dn(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = Te, analytics: s }, d) {
1230
- var U;
1231
- const t = dt(i, "WebRTCStreamingManager"), c = kn(t);
1232
- let h = !1, g = !1, l = T.Stop, v = T.Stop;
1233
- const { startConnection: P, sendStreamRequest: z, close: x, createStream: F, addIceCandidate: M } = Rn(
1234
- o,
1277
+ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee, analytics: o }, c) {
1278
+ var J;
1279
+ const t = pt(i, "WebRTCStreamingManager"), d = Ln(t);
1280
+ let h = !1, g = !1, l = E.Stop, v = E.Stop;
1281
+ const { startConnection: P, sendStreamRequest: N, close: B, createStream: F, addIceCandidate: I } = _n(
1282
+ s,
1235
1283
  a,
1236
1284
  e,
1237
1285
  r.onError
1238
1286
  ), {
1239
- id: E,
1287
+ id: k,
1240
1288
  offer: Y,
1241
1289
  ice_servers: Q,
1242
- session_id: J,
1290
+ session_id: U,
1243
1291
  fluent: te,
1244
1292
  interrupt_enabled: ne
1245
- } = await F(n, d);
1246
- (U = r.onStreamCreated) == null || U.call(r, { stream_id: E, session_id: J, agent_id: e });
1247
- const $ = new Tn({ iceServers: Q }), K = $.createDataChannel("JanusDataChannel");
1248
- if (!J)
1293
+ } = await F(n, c);
1294
+ (J = r.onStreamCreated) == null || J.call(r, { stream_id: k, session_id: U, agent_id: e });
1295
+ const $ = new bn({ iceServers: Q }), K = $.createDataChannel("JanusDataChannel");
1296
+ if (!U)
1249
1297
  throw new Error("Could not create session_id");
1250
1298
  const H = te ? se.Fluent : se.Legacy;
1251
- s.enrich({
1299
+ o.enrich({
1252
1300
  "stream-type": H
1253
1301
  });
1254
1302
  const re = n.stream_warmup && !te, de = () => h, ue = () => {
1255
1303
  var w;
1256
- h = !0, g && (t("CALLBACK: onConnectionStateChange(Connected)"), (w = r.onConnectionStateChange) == null || w.call(r, L.Connected));
1257
- }, f = lt(
1304
+ h = !0, g && (t("CALLBACK: onConnectionStateChange(Connected)"), (w = r.onConnectionStateChange) == null || w.call(r, x.Connected));
1305
+ }, f = yt(
1258
1306
  () => $.getStats(),
1259
1307
  de,
1260
1308
  ue,
1261
- (w, y) => Ze({
1309
+ (w, y) => ot({
1262
1310
  statsSignal: v = w,
1263
1311
  dataChannelSignal: H === se.Legacy ? l : void 0,
1264
1312
  onVideoStateChange: r.onVideoStateChange,
@@ -1276,18 +1324,18 @@ async function Dn(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = Te,
1276
1324
  var y;
1277
1325
  t("peerConnection.onicecandidate", w);
1278
1326
  try {
1279
- w.candidate && w.candidate.sdpMid && w.candidate.sdpMLineIndex !== null ? M(
1280
- E,
1327
+ w.candidate && w.candidate.sdpMid && w.candidate.sdpMLineIndex !== null ? I(
1328
+ k,
1281
1329
  {
1282
1330
  candidate: w.candidate.candidate,
1283
1331
  sdpMid: w.candidate.sdpMid,
1284
1332
  sdpMLineIndex: w.candidate.sdpMLineIndex
1285
1333
  },
1286
- J,
1287
- d
1288
- ) : M(E, { candidate: null }, J, d);
1289
- } catch (k) {
1290
- (y = r.onError) == null || y.call(r, k, { streamId: E });
1334
+ U,
1335
+ c
1336
+ ) : I(k, { candidate: null }, U, c);
1337
+ } catch (T) {
1338
+ (y = r.onError) == null || y.call(r, T, { streamId: k });
1291
1339
  }
1292
1340
  }, K.onopen = () => {
1293
1341
  g = !0, (!re || h) && ue();
@@ -1297,11 +1345,11 @@ async function Dn(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = Te,
1297
1345
  (y = r.onVideoIdChange) == null || y.call(r, w);
1298
1346
  };
1299
1347
  function R(w, y) {
1300
- if (w === D.StreamStarted && typeof y == "object" && "metadata" in y) {
1301
- const k = y.metadata;
1302
- C(k.videoId);
1348
+ if (w === M.StreamStarted && typeof y == "object" && "metadata" in y) {
1349
+ const T = y.metadata;
1350
+ C(T.videoId);
1303
1351
  }
1304
- w === D.StreamDone && C(null), l = w === D.StreamStarted ? T.Start : T.Stop, Ze({
1352
+ w === M.StreamDone && C(null), l = w === M.StreamStarted ? E.Start : E.Stop, ot({
1305
1353
  statsSignal: H === se.Legacy ? v : void 0,
1306
1354
  dataChannelSignal: l,
1307
1355
  onVideoStateChange: r.onVideoStateChange,
@@ -1311,56 +1359,56 @@ async function Dn(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = Te,
1311
1359
  });
1312
1360
  }
1313
1361
  function A(w, y) {
1314
- var B;
1315
- const k = typeof y == "string" ? y : y == null ? void 0 : y.metadata;
1316
- k && s.enrich({ streamMetadata: k }), (B = r.onStreamReady) == null || B.call(r);
1362
+ var j;
1363
+ const T = typeof y == "string" ? y : y == null ? void 0 : y.metadata;
1364
+ T && o.enrich({ streamMetadata: T }), (j = r.onStreamReady) == null || j.call(r);
1317
1365
  }
1318
- const I = {
1319
- [D.StreamStarted]: R,
1320
- [D.StreamDone]: R,
1321
- [D.StreamReady]: A
1366
+ const D = {
1367
+ [M.StreamStarted]: R,
1368
+ [M.StreamDone]: R,
1369
+ [M.StreamReady]: A
1322
1370
  };
1323
1371
  K.onmessage = (w) => {
1324
- var B;
1325
- const { subject: y, data: k } = c(w.data);
1326
- (B = I[y]) == null || B.call(I, y, k);
1372
+ var j;
1373
+ const { subject: y, data: T } = d(w.data);
1374
+ (j = D[y]) == null || j.call(D, y, T);
1327
1375
  }, $.oniceconnectionstatechange = () => {
1328
1376
  var y;
1329
1377
  t("peerConnection.oniceconnectionstatechange => " + $.iceConnectionState);
1330
- const w = Ge($.iceConnectionState);
1331
- w !== L.Connected && ((y = r.onConnectionStateChange) == null || y.call(r, w));
1378
+ const w = at($.iceConnectionState);
1379
+ w !== x.Connected && ((y = r.onConnectionStateChange) == null || y.call(r, w));
1332
1380
  }, $.ontrack = (w) => {
1333
1381
  var y;
1334
1382
  t("peerConnection.ontrack", w), t("CALLBACK: onSrcObjectReady"), (y = r.onSrcObjectReady) == null || y.call(r, w.streams[0]);
1335
1383
  }, await $.setRemoteDescription(Y), t("set remote description OK");
1336
1384
  const b = await $.createAnswer();
1337
- return t("create answer OK"), await $.setLocalDescription(b), t("set local description OK"), await P(E, b, J, d), t("start connection OK"), {
1385
+ return t("create answer OK"), await $.setLocalDescription(b), t("set local description OK"), await P(k, b, U, c), t("start connection OK"), {
1338
1386
  /**
1339
1387
  * Method to send request to server to get clip or talk depend on you payload
1340
1388
  * @param payload
1341
1389
  */
1342
1390
  speak(w) {
1343
- return z(E, J, w);
1391
+ return N(k, U, w);
1344
1392
  },
1345
1393
  /**
1346
1394
  * Method to close RTC connection
1347
1395
  */
1348
1396
  async disconnect() {
1349
1397
  var w;
1350
- if (E) {
1351
- const y = Ge($.iceConnectionState);
1398
+ if (k) {
1399
+ const y = at($.iceConnectionState);
1352
1400
  if ($) {
1353
- if (y === L.New) {
1401
+ if (y === x.New) {
1354
1402
  f.stop();
1355
1403
  return;
1356
1404
  }
1357
1405
  $.close(), $.oniceconnectionstatechange = null, $.onnegotiationneeded = null, $.onicecandidate = null, $.ontrack = null;
1358
1406
  }
1359
1407
  try {
1360
- y === L.Connected && await x(E, J).catch((k) => {
1408
+ y === x.Connected && await B(k, U).catch((T) => {
1361
1409
  });
1362
- } catch (k) {
1363
- t("Error on close stream connection", k);
1410
+ } catch (T) {
1411
+ t("Error on close stream connection", T);
1364
1412
  }
1365
1413
  (w = r.onAgentActivityStateChange) == null || w.call(r, W.Idle), f.stop();
1366
1414
  }
@@ -1369,65 +1417,65 @@ async function Dn(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = Te,
1369
1417
  * Method to send data channel messages to the server
1370
1418
  */
1371
1419
  sendDataChannelMessage(w) {
1372
- var y, k;
1420
+ var y, T;
1373
1421
  if (!h || K.readyState !== "open") {
1374
1422
  t("Data channel is not ready for sending messages"), (y = r.onError) == null || y.call(r, new Error("Data channel is not ready for sending messages"), {
1375
- streamId: E
1423
+ streamId: k
1376
1424
  });
1377
1425
  return;
1378
1426
  }
1379
1427
  try {
1380
1428
  K.send(w);
1381
- } catch (B) {
1382
- t("Error sending data channel message", B), (k = r.onError) == null || k.call(r, B, { streamId: E });
1429
+ } catch (j) {
1430
+ t("Error sending data channel message", j), (T = r.onError) == null || T.call(r, j, { streamId: k });
1383
1431
  }
1384
1432
  },
1385
1433
  /**
1386
1434
  * Session identifier information, should be returned in the body of all streaming requests
1387
1435
  */
1388
- sessionId: J,
1436
+ sessionId: U,
1389
1437
  /**
1390
1438
  * Id of current RTC stream
1391
1439
  */
1392
- streamId: E,
1440
+ streamId: k,
1393
1441
  streamType: H,
1394
1442
  interruptAvailable: ne ?? !1,
1395
1443
  isInterruptible: !0
1396
1444
  };
1397
1445
  }
1398
- var xe = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(xe || {});
1399
- async function In(e, n, i, r) {
1400
- const o = e.id;
1446
+ var Fe = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(Fe || {});
1447
+ async function jn(e, n, i, r) {
1448
+ const s = e.id;
1401
1449
  switch (n.version) {
1402
1450
  case "v1": {
1403
- const { version: a, ...s } = n;
1404
- return Dn(o, s, i, r);
1451
+ const { version: a, ...o } = n;
1452
+ return $n(s, o, i, r);
1405
1453
  }
1406
1454
  case "v2": {
1407
- const { version: a, ...s } = n;
1408
- switch (s.transport.provider) {
1409
- case Be.Livekit:
1410
- const { createLiveKitStreamingManager: d } = await Promise.resolve().then(() => ln);
1411
- return d(o, s, i);
1455
+ const { version: a, ...o } = n;
1456
+ switch (o.transport.provider) {
1457
+ case Ne.Livekit:
1458
+ const { createLiveKitStreamingManager: c } = await Promise.resolve().then(() => vn);
1459
+ return c(s, o, i);
1412
1460
  default:
1413
- throw new Error(`Unsupported transport provider: ${s.transport.provider}`);
1461
+ throw new Error(`Unsupported transport provider: ${o.transport.provider}`);
1414
1462
  }
1415
1463
  }
1416
1464
  default:
1417
1465
  throw new Error(`Invalid stream version: ${n.version}`);
1418
1466
  }
1419
1467
  }
1420
- const An = "cht";
1421
- function _n() {
1468
+ const Bn = "cht";
1469
+ function Fn() {
1422
1470
  return {
1423
1471
  transport: {
1424
- provider: Be.Livekit
1472
+ provider: Ne.Livekit
1425
1473
  }
1426
1474
  };
1427
1475
  }
1428
- function bn(e) {
1429
- var o, a;
1430
- const { streamOptions: n } = e ?? {}, i = ((o = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : o.plan) !== void 0 ? {
1476
+ function Nn(e) {
1477
+ var s, a;
1478
+ const { streamOptions: n } = e ?? {}, i = ((s = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : s.plan) !== void 0 ? {
1431
1479
  plan: (a = e.mixpanelAdditionalProperties) == null ? void 0 : a.plan
1432
1480
  } : void 0;
1433
1481
  return { ...{
@@ -1438,28 +1486,28 @@ function bn(e) {
1438
1486
  fluent: n == null ? void 0 : n.fluent
1439
1487
  }, ...i && { end_user_data: i } };
1440
1488
  }
1441
- function Pn(e, n) {
1442
- return Fe(e.presenter.type) ? { version: xe.V2, ..._n() } : { version: xe.V1, ...bn(n) };
1489
+ function Kn(e, n) {
1490
+ return Ke(e.presenter.type) ? { version: Fe.V2, ...Fn() } : { version: Fe.V1, ...Nn(n) };
1443
1491
  }
1444
- function Ln(e, n, i) {
1492
+ function zn(e, n, i) {
1445
1493
  i.track("agent-connection-state-change", { state: e, ...n && { reason: n } });
1446
1494
  }
1447
- function $n(e, n, i, r, o) {
1448
- o === se.Fluent ? jn(e, n, i, r, o) : xn(e, n, i, r, o);
1495
+ function Vn(e, n, i, r, s) {
1496
+ s === se.Fluent ? Un(e, n, i, r, s) : Jn(e, n, i, r, s);
1449
1497
  }
1450
- function jn(e, n, i, r, o) {
1451
- e === T.Start ? r.track("stream-session", { event: "start", "stream-type": o }) : e === T.Stop && r.track("stream-session", {
1498
+ function Un(e, n, i, r, s) {
1499
+ e === E.Start ? r.track("stream-session", { event: "start", "stream-type": s }) : e === E.Stop && r.track("stream-session", {
1452
1500
  event: "stop",
1453
1501
  is_greenscreen: n.presenter.type === "clip" && n.presenter.is_greenscreen,
1454
1502
  background: n.presenter.type === "clip" && n.presenter.background,
1455
- "stream-type": o,
1503
+ "stream-type": s,
1456
1504
  ...i
1457
1505
  });
1458
1506
  }
1459
- function et(e, n, i, r, o) {
1460
- e === T.Start ? i.linkTrack("agent-video", { event: "start", ...o, "stream-type": r }, "start", [
1461
- D.StreamVideoCreated
1462
- ]) : e === T.Stop && i.linkTrack(
1507
+ function st(e, n, i, r, s) {
1508
+ e === E.Start ? i.linkTrack("agent-video", { event: "start", ...s, "stream-type": r }, "start", [
1509
+ M.StreamVideoCreated
1510
+ ]) : e === E.Stop && i.linkTrack(
1463
1511
  "agent-video",
1464
1512
  {
1465
1513
  event: "stop",
@@ -1468,39 +1516,39 @@ function et(e, n, i, r, o) {
1468
1516
  "stream-type": r
1469
1517
  },
1470
1518
  "done",
1471
- [D.StreamVideoDone]
1519
+ [M.StreamVideoDone]
1472
1520
  );
1473
1521
  }
1474
- function xn(e, n, i, r, o) {
1475
- e === T.Start ? r.linkTrack(
1522
+ function Jn(e, n, i, r, s) {
1523
+ e === E.Start ? r.linkTrack(
1476
1524
  "agent-video",
1477
- { event: "start", latency: oe.get(!0), "stream-type": o },
1525
+ { event: "start", latency: oe.get(!0), "stream-type": s },
1478
1526
  "start",
1479
- [D.StreamVideoCreated]
1480
- ) : e === T.Stop && r.linkTrack(
1527
+ [M.StreamVideoCreated]
1528
+ ) : e === E.Stop && r.linkTrack(
1481
1529
  "agent-video",
1482
1530
  {
1483
1531
  event: "stop",
1484
1532
  is_greenscreen: n.presenter.type === "clip" && n.presenter.is_greenscreen,
1485
1533
  background: n.presenter.type === "clip" && n.presenter.background,
1486
- "stream-type": o,
1534
+ "stream-type": s,
1487
1535
  ...i
1488
1536
  },
1489
1537
  "done",
1490
- [D.StreamVideoDone]
1538
+ [M.StreamVideoDone]
1491
1539
  );
1492
1540
  }
1493
- function tt(e, n, i, r) {
1494
- return oe.reset(), Qe.update(), new Promise(async (o, a) => {
1541
+ function ct(e, n, i, r) {
1542
+ return oe.reset(), nt.update(), new Promise(async (s, a) => {
1495
1543
  try {
1496
- let s, d = !1;
1497
- const t = Pn(e, n);
1544
+ let o, c = !1;
1545
+ const t = Kn(e, n);
1498
1546
  i.enrich({
1499
1547
  "stream-version": t.version.toString()
1500
1548
  });
1501
- let c = null;
1549
+ let d = null;
1502
1550
  const h = e.presenter.type === "expressive";
1503
- s = await In(
1551
+ o = await jn(
1504
1552
  e,
1505
1553
  t,
1506
1554
  {
@@ -1510,131 +1558,131 @@ function tt(e, n, i, r) {
1510
1558
  ...n.callbacks,
1511
1559
  onConnectionStateChange: (g, l) => {
1512
1560
  var v, P;
1513
- (P = (v = n.callbacks).onConnectionStateChange) == null || P.call(v, g), Ln(g, l, i), g === L.Connected && (s ? o(s) : d = !0);
1561
+ (P = (v = n.callbacks).onConnectionStateChange) == null || P.call(v, g), zn(g, l, i), g === x.Connected && (o ? s(o) : c = !0);
1514
1562
  },
1515
1563
  onVideoStateChange: (g, l) => {
1516
1564
  var v, P;
1517
- (P = (v = n.callbacks).onVideoStateChange) == null || P.call(v, g), $n(
1565
+ (P = (v = n.callbacks).onVideoStateChange) == null || P.call(v, g), Vn(
1518
1566
  g,
1519
1567
  e,
1520
1568
  l,
1521
1569
  i,
1522
- s.streamType
1570
+ o.streamType
1523
1571
  );
1524
1572
  },
1525
1573
  onAgentActivityStateChange: (g) => {
1526
1574
  var l, v;
1527
- (v = (l = n.callbacks).onAgentActivityStateChange) == null || v.call(l, g), g === W.Talking ? ($e.update(), c = (P) => {
1528
- et(
1529
- T.Start,
1575
+ (v = (l = n.callbacks).onAgentActivityStateChange) == null || v.call(l, g), g === W.Talking ? (je.update(), d = (P) => {
1576
+ st(
1577
+ E.Start,
1530
1578
  e,
1531
1579
  i,
1532
- s.streamType,
1580
+ o.streamType,
1533
1581
  P
1534
- ), c = null;
1535
- }, h || c({ latency: oe.get(!0) })) : ($e.reset(), c = null, et(
1536
- T.Stop,
1582
+ ), d = null;
1583
+ }, h || d({ latency: oe.get(!0) })) : (je.reset(), d = null, st(
1584
+ E.Stop,
1537
1585
  e,
1538
1586
  i,
1539
- s.streamType
1587
+ o.streamType
1540
1588
  ));
1541
1589
  },
1542
1590
  onFirstAudioDetected: (g) => {
1543
- c == null || c(g);
1591
+ d == null || d(g);
1544
1592
  },
1545
1593
  onStreamReady: () => {
1546
- const g = Qe.get(!0);
1594
+ const g = nt.get(!0);
1547
1595
  i.track("agent-chat", { event: "ready", latency: g });
1548
1596
  }
1549
1597
  }
1550
1598
  },
1551
1599
  r
1552
- ), d && o(s);
1553
- } catch (s) {
1554
- a(s);
1600
+ ), c && s(o);
1601
+ } catch (o) {
1602
+ a(o);
1555
1603
  }
1556
1604
  });
1557
1605
  }
1558
- async function Bn(e, n, i, r, o) {
1606
+ async function On(e, n, i, r, s) {
1559
1607
  var h, g, l, v;
1560
1608
  const a = async () => {
1561
- if (Fe(e.presenter.type)) {
1562
- const P = await tt(e, n, r), z = `${An}_${P.sessionId}`, x = (/* @__PURE__ */ new Date()).toISOString();
1609
+ if (Ke(e.presenter.type)) {
1610
+ const P = await ct(e, n, r), N = `${Bn}_${P.sessionId}`, B = (/* @__PURE__ */ new Date()).toISOString();
1563
1611
  return { chatResult: {
1564
1612
  chatMode: O.Functional,
1565
1613
  chat: {
1566
- id: z,
1614
+ id: N,
1567
1615
  agent_id: e.id,
1568
1616
  owner_id: e.owner_id ?? "",
1569
- created: x,
1570
- modified: x,
1571
- agent_id__created_at: x,
1572
- agent_id__modified_at: x,
1617
+ created: B,
1618
+ modified: B,
1619
+ agent_id__created_at: B,
1620
+ agent_id__modified_at: B,
1573
1621
  chat_mode: O.Functional,
1574
1622
  messages: []
1575
1623
  }
1576
1624
  }, streamingManager: P };
1577
1625
  } else {
1578
- const P = new AbortController(), z = P.signal;
1579
- let x;
1626
+ const P = new AbortController(), N = P.signal;
1627
+ let B;
1580
1628
  try {
1581
- const F = ct(
1629
+ const F = ht(
1582
1630
  e,
1583
1631
  i,
1584
1632
  r,
1585
1633
  n.mode,
1586
1634
  n.persistentChat,
1587
- o
1588
- ), M = tt(e, n, r, z).then((Q) => (x = Q, Q)), [E, Y] = await Promise.all([F, M]);
1589
- return { chatResult: E, streamingManager: Y };
1635
+ s
1636
+ ), I = ct(e, n, r, N).then((Q) => (B = Q, Q)), [k, Y] = await Promise.all([F, I]);
1637
+ return { chatResult: k, streamingManager: Y };
1590
1638
  } catch (F) {
1591
- throw P.abort(), x && await x.disconnect().catch(() => {
1639
+ throw P.abort(), B && await B.disconnect().catch(() => {
1592
1640
  }), F;
1593
1641
  }
1594
1642
  }
1595
- }, { chatResult: s, streamingManager: d } = await a(), { chat: t, chatMode: c } = s;
1596
- return c && n.mode !== void 0 && c !== n.mode && (n.mode = c, (g = (h = n.callbacks).onModeChange) == null || g.call(h, c), c !== O.Functional) ? ((v = (l = n.callbacks).onError) == null || v.call(l, new Ct(c)), d == null || d.disconnect(), { chat: t }) : { chat: t, streamingManager: d };
1643
+ }, { chatResult: o, streamingManager: c } = await a(), { chat: t, chatMode: d } = o;
1644
+ return d && n.mode !== void 0 && d !== n.mode && (n.mode = d, (g = (h = n.callbacks).onModeChange) == null || g.call(h, d), d !== O.Functional) ? ((v = (l = n.callbacks).onError) == null || v.call(l, new It(d)), c == null || c.disconnect(), { chat: t }) : { chat: t, streamingManager: c };
1597
1645
  }
1598
- async function Kn(e, n) {
1646
+ async function qn(e, n) {
1599
1647
  var H, re, de, ue;
1600
1648
  let i = !0, r = null;
1601
- const o = n.mixpanelKey || $t, a = n.wsURL || Lt, s = n.baseURL || Te, d = n.mode || O.Functional, t = {
1649
+ const s = n.mixpanelKey || zt, a = n.wsURL || Kt, o = n.baseURL || Ee, c = n.mode || O.Functional, t = {
1602
1650
  messages: [],
1603
- chatMode: d
1604
- }, c = qt({
1605
- token: o,
1651
+ chatMode: c
1652
+ }, d = nn({
1653
+ token: s,
1606
1654
  agentId: e,
1607
1655
  isEnabled: n.enableAnalitics,
1608
1656
  externalId: n.externalId,
1609
1657
  mixpanelAdditionalProperties: n.mixpanelAdditionalProperties
1610
1658
  }), h = Date.now();
1611
- qe(() => {
1612
- c.track("agent-sdk", { event: "init" }, h);
1659
+ tt(() => {
1660
+ d.track("agent-sdk", { event: "init" }, h);
1613
1661
  });
1614
- const g = Vt(n.auth, s, n.callbacks.onError, n.externalId), l = await g.getById(e);
1662
+ const g = Xt(n.auth, o, n.callbacks.onError, n.externalId), l = await g.getById(e);
1615
1663
  n.debug = n.debug || ((H = l == null ? void 0 : l.advanced_settings) == null ? void 0 : H.ui_debug_mode);
1616
- const v = Fe(l.presenter.type);
1617
- c.enrich(Ut(l));
1618
- const { onMessage: P, clearQueue: z } = Sn(c, t, n, l, () => {
1664
+ const v = Ke(l.presenter.type);
1665
+ d.enrich(Gt(l));
1666
+ const { onMessage: P, clearQueue: N } = An(d, t, n, l, () => {
1619
1667
  var f, C, R;
1620
- (f = t.socketManager) == null || f.disconnect(), (R = (C = n.callbacks).onConnectionStateChange) == null || R.call(C, L.Disconnected);
1668
+ (f = t.socketManager) == null || f.disconnect(), (R = (C = n.callbacks).onConnectionStateChange) == null || R.call(C, x.Disconnected);
1621
1669
  });
1622
- t.messages = Xt(n.initialMessages), (de = (re = n.callbacks).onNewMessage) == null || de.call(re, [...t.messages], "answer");
1623
- const x = (f) => {
1670
+ t.messages = an(n.initialMessages), (de = (re = n.callbacks).onNewMessage) == null || de.call(re, [...t.messages], "answer");
1671
+ const B = (f) => {
1624
1672
  r = f;
1625
1673
  }, F = ({ type: f }) => {
1626
- var R, A, I, b, U;
1674
+ var R, A, D, b, J;
1627
1675
  if (!((R = t.streamingManager) != null && R.interruptAvailable) || !((A = t.streamingManager) != null && A.isInterruptible)) return;
1628
1676
  const C = t.messages[t.messages.length - 1];
1629
- c.track("agent-video-interrupt", {
1677
+ d.track("agent-video-interrupt", {
1630
1678
  type: f || "click",
1631
- video_duration_to_interrupt: $e.get(!0),
1679
+ video_duration_to_interrupt: je.get(!0),
1632
1680
  message_duration_to_interrupt: oe.get(!0)
1633
- }), C.interrupted = !0, (b = (I = n.callbacks).onNewMessage) == null || b.call(I, [...t.messages], "answer"), v ? gn(t.streamingManager) : (fn(t.streamingManager, (U = t.streamingManager) == null ? void 0 : U.streamType, r), mn(t.streamingManager, r));
1634
- }, M = /* @__PURE__ */ new Map();
1635
- function E(f) {
1681
+ }), C.interrupted = !0, (b = (D = n.callbacks).onNewMessage) == null || b.call(D, [...t.messages], "answer"), v ? Rn(t.streamingManager) : (Cn(t.streamingManager, (J = t.streamingManager) == null ? void 0 : J.streamType, r), Sn(t.streamingManager, r));
1682
+ }, I = /* @__PURE__ */ new Map();
1683
+ function k(f) {
1636
1684
  return async (C) => {
1637
- const R = M.get(f);
1685
+ const R = I.get(f);
1638
1686
  if (!R)
1639
1687
  throw new Error(`No handler registered for client tool: ${f}`);
1640
1688
  try {
@@ -1647,71 +1695,71 @@ async function Kn(e, n) {
1647
1695
  }
1648
1696
  function Y() {
1649
1697
  var f, C, R, A;
1650
- for (const [I] of M)
1651
- (C = (f = t.streamingManager) == null ? void 0 : f.unregisterRpcMethod) == null || C.call(f, I), (A = (R = t.streamingManager) == null ? void 0 : R.registerRpcMethod) == null || A.call(R, I, E(I));
1698
+ for (const [D] of I)
1699
+ (C = (f = t.streamingManager) == null ? void 0 : f.unregisterRpcMethod) == null || C.call(f, D), (A = (R = t.streamingManager) == null ? void 0 : R.registerRpcMethod) == null || A.call(R, D, k(D));
1652
1700
  }
1653
1701
  function Q(f, C) {
1654
- var A, I;
1655
- const R = !M.has(f);
1656
- M.set(f, C), R && ((I = (A = t.streamingManager) == null ? void 0 : A.registerRpcMethod) == null || I.call(A, f, E(f)));
1702
+ var A, D;
1703
+ const R = !I.has(f);
1704
+ I.set(f, C), R && ((D = (A = t.streamingManager) == null ? void 0 : A.registerRpcMethod) == null || D.call(A, f, k(f)));
1657
1705
  }
1658
- function J(f) {
1706
+ function U(f) {
1659
1707
  var C, R;
1660
- M.delete(f), (R = (C = t.streamingManager) == null ? void 0 : C.unregisterRpcMethod) == null || R.call(C, f);
1708
+ I.delete(f), (R = (C = t.streamingManager) == null ? void 0 : C.unregisterRpcMethod) == null || R.call(C, f);
1661
1709
  }
1662
1710
  const te = Date.now();
1663
- qe(() => {
1664
- c.track("agent-sdk", { event: "loaded", ...Jt(l) }, te);
1711
+ tt(() => {
1712
+ d.track("agent-sdk", { event: "loaded", ...Yt(l) }, te);
1665
1713
  });
1666
1714
  async function ne(f) {
1667
- var U, w, y, k, B, G, he;
1668
- (w = (U = n.callbacks).onConnectionStateChange) == null || w.call(U, L.Connecting), oe.reset(), f && !i && (delete t.chat, (k = (y = n.callbacks).onNewMessage) == null || k.call(y, [...t.messages], "answer"));
1669
- const C = d === O.DirectPlayback || v ? Promise.resolve(void 0) : wn(
1715
+ var J, w, y, T, j, G, he;
1716
+ (w = (J = n.callbacks).onConnectionStateChange) == null || w.call(J, x.Connecting), oe.reset(), f && !i && (delete t.chat, (T = (y = n.callbacks).onNewMessage) == null || T.call(y, [...t.messages], "answer"));
1717
+ const C = c === O.DirectPlayback || v ? Promise.resolve(void 0) : Mn(
1670
1718
  n.auth,
1671
1719
  a,
1672
1720
  { onMessage: P, onError: n.callbacks.onError },
1673
1721
  n.externalId
1674
- ), R = Pe(
1675
- () => Bn(
1722
+ ), R = xe(
1723
+ () => On(
1676
1724
  l,
1677
1725
  {
1678
1726
  ...n,
1679
- mode: d,
1727
+ mode: c,
1680
1728
  callbacks: {
1681
1729
  ...n.callbacks,
1682
- onVideoIdChange: x,
1730
+ onVideoIdChange: B,
1683
1731
  onMessage: P,
1684
1732
  onInterruptDetected: F
1685
1733
  }
1686
1734
  },
1687
1735
  g,
1688
- c,
1736
+ d,
1689
1737
  t.chat
1690
1738
  ),
1691
1739
  {
1692
1740
  limit: 3,
1693
- timeout: bt,
1741
+ timeout: Ft,
1694
1742
  timeoutErrorMessage: "Timeout initializing the stream",
1695
1743
  shouldRetryFn: (Z) => (Z == null ? void 0 : Z.message) !== "Could not connect" && Z.status !== 429 && (Z == null ? void 0 : Z.message) !== "InsufficientCreditsError",
1696
1744
  delayMs: 1e3
1697
1745
  }
1698
1746
  ).catch((Z) => {
1699
- var N, ee;
1700
- throw K(O.Maintenance), (ee = (N = n.callbacks).onConnectionStateChange) == null || ee.call(N, L.Fail), Z;
1701
- }), [A, { streamingManager: I, chat: b }] = await Promise.all([C, R]);
1702
- b && b.id !== ((B = t.chat) == null ? void 0 : B.id) && ((he = (G = n.callbacks).onNewChat) == null || he.call(G, b.id)), t.streamingManager = I, t.socketManager = A, t.chat = b, Y(), i = !1, c.enrich({
1747
+ var z, ee;
1748
+ throw K(O.Maintenance), (ee = (z = n.callbacks).onConnectionStateChange) == null || ee.call(z, x.Fail), Z;
1749
+ }), [A, { streamingManager: D, chat: b }] = await Promise.all([C, R]);
1750
+ b && b.id !== ((j = t.chat) == null ? void 0 : j.id) && ((he = (G = n.callbacks).onNewChat) == null || he.call(G, b.id)), t.streamingManager = D, t.socketManager = A, t.chat = b, Y(), i = !1, d.enrich({
1703
1751
  chatId: b == null ? void 0 : b.id,
1704
- streamId: I == null ? void 0 : I.streamId,
1752
+ streamId: D == null ? void 0 : D.streamId,
1705
1753
  mode: t.chatMode
1706
- }), K((b == null ? void 0 : b.chat_mode) ?? d);
1754
+ }), K((b == null ? void 0 : b.chat_mode) ?? c);
1707
1755
  }
1708
1756
  async function $() {
1709
1757
  var f, C, R, A;
1710
- (f = t.socketManager) == null || f.disconnect(), await ((C = t.streamingManager) == null ? void 0 : C.disconnect()), delete t.streamingManager, delete t.socketManager, (A = (R = n.callbacks).onConnectionStateChange) == null || A.call(R, L.Disconnected);
1758
+ (f = t.socketManager) == null || f.disconnect(), await ((C = t.streamingManager) == null ? void 0 : C.disconnect()), delete t.streamingManager, delete t.socketManager, (A = (R = n.callbacks).onConnectionStateChange) == null || A.call(R, x.Disconnected);
1711
1759
  }
1712
1760
  async function K(f) {
1713
1761
  var C, R;
1714
- f !== t.chatMode && (c.track("agent-mode-change", { mode: f }), t.chatMode = f, t.chatMode !== O.Functional && await $(), (R = (C = n.callbacks).onModeChange) == null || R.call(C, f));
1762
+ f !== t.chatMode && (d.track("agent-mode-change", { mode: f }), t.chatMode = f, t.chatMode !== O.Functional && await $(), (R = (C = n.callbacks).onModeChange) == null || R.call(C, f));
1715
1763
  }
1716
1764
  return {
1717
1765
  agent: l,
@@ -1726,9 +1774,9 @@ async function Kn(e, n) {
1726
1774
  starterMessages: ((ue = l.knowledge) == null ? void 0 : ue.starter_message) || [],
1727
1775
  getSTTToken: () => g.getSTTToken(l.id),
1728
1776
  changeMode: K,
1729
- enrichAnalytics: c.enrich,
1777
+ enrichAnalytics: d.enrich,
1730
1778
  async connect() {
1731
- await ne(!0), c.track("agent-chat", {
1779
+ await ne(!0), d.track("agent-chat", {
1732
1780
  event: "connect",
1733
1781
  mode: t.chatMode
1734
1782
  });
@@ -1737,7 +1785,7 @@ async function Kn(e, n) {
1737
1785
  const f = t.streamingManager;
1738
1786
  if (v && (f != null && f.reconnect)) {
1739
1787
  try {
1740
- await f.reconnect(), c.track("agent-chat", {
1788
+ await f.reconnect(), d.track("agent-chat", {
1741
1789
  event: "reconnect",
1742
1790
  mode: t.chatMode
1743
1791
  });
@@ -1746,13 +1794,13 @@ async function Kn(e, n) {
1746
1794
  }
1747
1795
  return;
1748
1796
  }
1749
- await $(), await ne(!1), c.track("agent-chat", {
1797
+ await $(), await ne(!1), d.track("agent-chat", {
1750
1798
  event: "reconnect",
1751
1799
  mode: t.chatMode
1752
1800
  });
1753
1801
  },
1754
1802
  async disconnect() {
1755
- await $(), c.track("agent-chat", {
1803
+ await $(), d.track("agent-chat", {
1756
1804
  event: "disconnect",
1757
1805
  mode: t.chatMode
1758
1806
  });
@@ -1780,10 +1828,10 @@ async function Kn(e, n) {
1780
1828
  return t.streamingManager.unpublishCameraStream();
1781
1829
  },
1782
1830
  async chat(f) {
1783
- var I, b, U, w, y;
1831
+ var D, b, J, w, y;
1784
1832
  const C = () => {
1785
- if (at(d))
1786
- throw new me(`${d} is enabled, chat is disabled`);
1833
+ if (ft(c))
1834
+ throw new me(`${c} is enabled, chat is disabled`);
1787
1835
  if (f.length >= 800)
1788
1836
  throw new me("Message cannot be more than 800 characters");
1789
1837
  if (f.length === 0)
@@ -1797,47 +1845,47 @@ async function Kn(e, n) {
1797
1845
  throw new me("Chat is not initialized");
1798
1846
  }
1799
1847
  }, R = async () => {
1800
- var k, B;
1848
+ var T, j;
1801
1849
  if (!t.chat) {
1802
- const G = await ct(
1850
+ const G = await ht(
1803
1851
  l,
1804
1852
  g,
1805
- c,
1853
+ d,
1806
1854
  t.chatMode,
1807
1855
  n.persistentChat
1808
1856
  );
1809
1857
  if (!G.chat)
1810
- throw new vt(t.chatMode, !!n.persistentChat);
1811
- t.chat = G.chat, (B = (k = n.callbacks).onNewChat) == null || B.call(k, t.chat.id);
1858
+ throw new kt(t.chatMode, !!n.persistentChat);
1859
+ t.chat = G.chat, (j = (T = n.callbacks).onNewChat) == null || j.call(T, t.chat.id);
1812
1860
  }
1813
1861
  return t.chat.id;
1814
- }, A = async (k, B) => {
1862
+ }, A = async (T, j) => {
1815
1863
  const G = t.chatMode === O.Playground;
1816
- return Pe(v && !G ? async () => {
1817
- var N, ee;
1818
- return await ((ee = (N = t.streamingManager) == null ? void 0 : N.sendTextMessage) == null ? void 0 : ee.call(N, f)), Promise.resolve({});
1864
+ return xe(v && !G ? async () => {
1865
+ var z, ee;
1866
+ return await ((ee = (z = t.streamingManager) == null ? void 0 : z.sendTextMessage) == null ? void 0 : ee.call(z, f)), Promise.resolve({});
1819
1867
  } : async () => {
1820
- var N, ee;
1868
+ var z, ee;
1821
1869
  return g.chat(
1822
1870
  l.id,
1823
- B,
1871
+ j,
1824
1872
  {
1825
1873
  chatMode: t.chatMode,
1826
- streamId: (N = t.streamingManager) == null ? void 0 : N.streamId,
1874
+ streamId: (z = t.streamingManager) == null ? void 0 : z.streamId,
1827
1875
  sessionId: (ee = t.streamingManager) == null ? void 0 : ee.sessionId,
1828
- messages: k.map(({ matches: De, ...le }) => le)
1876
+ messages: T.map(({ matches: De, ...le }) => le)
1829
1877
  },
1830
1878
  {
1831
- ...st(t.chatMode),
1879
+ ...gt(t.chatMode),
1832
1880
  skipErrorHandler: !0
1833
1881
  }
1834
1882
  );
1835
1883
  }, {
1836
1884
  limit: 2,
1837
- shouldRetryFn: (N) => {
1838
- var le, ke, pe, we;
1839
- const ee = (le = N == null ? void 0 : N.message) == null ? void 0 : le.includes("missing or invalid session_id");
1840
- return !((ke = N == null ? void 0 : N.message) == null ? void 0 : ke.includes("Stream Error")) && !ee ? ((we = (pe = n.callbacks).onError) == null || we.call(pe, N), !1) : !0;
1885
+ shouldRetryFn: (z) => {
1886
+ var le, Me, pe, we;
1887
+ const ee = (le = z == null ? void 0 : z.message) == null ? void 0 : le.includes("missing or invalid session_id");
1888
+ return !((Me = z == null ? void 0 : z.message) == null ? void 0 : Me.includes("Stream Error")) && !ee ? ((we = (pe = n.callbacks).onError) == null || we.call(pe, z), !1) : !0;
1841
1889
  },
1842
1890
  onRetry: async () => {
1843
1891
  await $(), await ne(!1);
@@ -1845,67 +1893,69 @@ async function Kn(e, n) {
1845
1893
  });
1846
1894
  };
1847
1895
  try {
1848
- z(), C(), t.messages.push({
1896
+ N(), C(), t.messages.push({
1849
1897
  id: ge(),
1850
1898
  role: "user",
1851
1899
  content: f,
1900
+ parts: Te(f),
1852
1901
  created_at: new Date(oe.update()).toISOString()
1853
- }), (b = (I = n.callbacks).onNewMessage) == null || b.call(I, [...t.messages], "user");
1854
- const k = await R(), B = await A([...t.messages], k);
1902
+ }), (b = (D = n.callbacks).onNewMessage) == null || b.call(D, [...t.messages], "user");
1903
+ const T = await R(), j = await A([...t.messages], T);
1855
1904
  return t.messages.push({
1856
1905
  id: ge(),
1857
1906
  role: "assistant",
1858
- content: B.result || "",
1907
+ content: j.result || "",
1908
+ parts: Te(j.result || ""),
1859
1909
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
1860
- context: B.context,
1861
- matches: B.matches
1862
- }), c.track("agent-message-send", {
1910
+ context: j.context,
1911
+ matches: j.matches
1912
+ }), d.track("agent-message-send", {
1863
1913
  event: "success",
1864
1914
  messages: t.messages.length + 1
1865
- }), B.result && ((w = (U = n.callbacks).onNewMessage) == null || w.call(U, [...t.messages], "answer"), c.track("agent-message-received", {
1915
+ }), j.result && ((w = (J = n.callbacks).onNewMessage) == null || w.call(J, [...t.messages], "answer"), d.track("agent-message-received", {
1866
1916
  latency: oe.get(!0),
1867
1917
  messages: t.messages.length
1868
- })), B;
1869
- } catch (k) {
1870
- throw ((y = t.messages[t.messages.length - 1]) == null ? void 0 : y.role) === "assistant" && t.messages.pop(), c.track("agent-message-send", {
1918
+ })), j;
1919
+ } catch (T) {
1920
+ throw ((y = t.messages[t.messages.length - 1]) == null ? void 0 : y.role) === "assistant" && t.messages.pop(), d.track("agent-message-send", {
1871
1921
  event: "error",
1872
1922
  messages: t.messages.length
1873
- }), k;
1923
+ }), T;
1874
1924
  }
1875
1925
  },
1876
1926
  rate(f, C, R) {
1877
- var b, U, w, y;
1878
- const A = t.messages.find((k) => k.id === f);
1927
+ var b, J, w, y;
1928
+ const A = t.messages.find((T) => T.id === f);
1879
1929
  if (t.chat) {
1880
1930
  if (!A)
1881
1931
  throw new Error("Message not found");
1882
1932
  } else throw new Error("Chat is not initialized");
1883
- const I = ((b = A.matches) == null ? void 0 : b.map((k) => [k.document_id, k.id])) ?? [];
1884
- return c.track("agent-rate", {
1933
+ const D = ((b = A.matches) == null ? void 0 : b.map((T) => [T.document_id, T.id])) ?? [];
1934
+ return d.track("agent-rate", {
1885
1935
  event: R ? "update" : "create",
1886
1936
  thumb: C === 1 ? "up" : "down",
1887
- knowledge_id: ((U = l.knowledge) == null ? void 0 : U.id) ?? "",
1888
- matches: I,
1937
+ knowledge_id: ((J = l.knowledge) == null ? void 0 : J.id) ?? "",
1938
+ matches: D,
1889
1939
  score: C
1890
1940
  }), R ? g.updateRating(l.id, t.chat.id, R, {
1891
1941
  knowledge_id: ((w = l.knowledge) == null ? void 0 : w.id) ?? "",
1892
1942
  message_id: f,
1893
- matches: I,
1943
+ matches: D,
1894
1944
  score: C
1895
1945
  }) : g.createRating(l.id, t.chat.id, {
1896
1946
  knowledge_id: ((y = l.knowledge) == null ? void 0 : y.id) ?? "",
1897
1947
  message_id: f,
1898
- matches: I,
1948
+ matches: D,
1899
1949
  score: C
1900
1950
  });
1901
1951
  },
1902
1952
  deleteRate(f) {
1903
1953
  if (!t.chat)
1904
1954
  throw new Error("Chat is not initialized");
1905
- return c.track("agent-rate-delete", { type: "text" }), g.deleteRating(l.id, t.chat.id, f);
1955
+ return d.track("agent-rate-delete", { type: "text" }), g.deleteRating(l.id, t.chat.id, f);
1906
1956
  },
1907
1957
  async speak(f) {
1908
- var I, b, U;
1958
+ var D, b, J;
1909
1959
  function C() {
1910
1960
  if (typeof f == "string") {
1911
1961
  if (!l.presenter.voice)
@@ -1930,12 +1980,13 @@ async function Kn(e, n) {
1930
1980
  return f;
1931
1981
  }
1932
1982
  const R = C();
1933
- if (c.track("agent-speak", R), oe.update(), t.messages && R.type === "text" && (t.messages.push({
1983
+ if (d.track("agent-speak", R), oe.update(), t.messages && R.type === "text" && (t.messages.push({
1934
1984
  id: ge(),
1935
1985
  role: "assistant",
1936
1986
  content: R.input,
1987
+ parts: Te(R.input),
1937
1988
  created_at: (/* @__PURE__ */ new Date()).toISOString()
1938
- }), (b = (I = n.callbacks).onNewMessage) == null || b.call(I, [...t.messages], "answer")), Ft(t.chatMode))
1989
+ }), (b = (D = n.callbacks).onNewMessage) == null || b.call(D, [...t.messages], "answer")), Ot(t.chatMode))
1939
1990
  return {
1940
1991
  duration: 0,
1941
1992
  video_id: "",
@@ -1945,38 +1996,39 @@ async function Kn(e, n) {
1945
1996
  throw new Error("Please connect to the agent first");
1946
1997
  return t.streamingManager.speak({
1947
1998
  script: R,
1948
- metadata: { chat_id: (U = t.chat) == null ? void 0 : U.id, agent_id: l.id }
1999
+ metadata: { chat_id: (J = t.chat) == null ? void 0 : J.id, agent_id: l.id }
1949
2000
  });
1950
2001
  },
1951
2002
  interrupt: F,
1952
2003
  registerClientTool: Q,
1953
- unregisterClientTool: J
2004
+ unregisterClientTool: U
1954
2005
  };
1955
2006
  }
1956
2007
  export {
1957
2008
  W as AgentActivityState,
1958
- kt as AgentStatus,
1959
- vt as ChatCreationFailed,
2009
+ bt as AgentStatus,
2010
+ kt as ChatCreationFailed,
1960
2011
  O as ChatMode,
1961
- Ct as ChatModeDowngraded,
2012
+ It as ChatModeDowngraded,
1962
2013
  X as ChatProgress,
1963
- L as ConnectionState,
2014
+ x as ConnectionState,
1964
2015
  ae as ConnectivityState,
1965
- It as DocumentType,
1966
- Dt as KnowledgeType,
1967
- Tt as PlanGroup,
1968
- At as Providers,
1969
- Et as RateState,
1970
- D as StreamEvents,
2016
+ $t as DocumentType,
2017
+ xt as KnowledgeType,
2018
+ _t as PlanGroup,
2019
+ jt as Providers,
2020
+ Lt as RateState,
2021
+ M as StreamEvents,
1971
2022
  se as StreamType,
1972
- T as StreamingState,
1973
- Mt as Subject,
1974
- Be as TransportProvider,
1975
- Rt as UserPlan,
2023
+ E as StreamingState,
2024
+ Pt as Subject,
2025
+ Ne as TransportProvider,
2026
+ At as UserPlan,
1976
2027
  me as ValidationError,
1977
- nt as VideoType,
1978
- _t as VoiceAccess,
1979
- St as WsError,
1980
- Kn as createAgentManager,
1981
- zn as mapVideoType
2028
+ dt as VideoType,
2029
+ Bt as VoiceAccess,
2030
+ Dt as WsError,
2031
+ qn as createAgentManager,
2032
+ Hn as mapVideoType,
2033
+ Wt as parseMessageParts
1982
2034
  };