@d-id/client-sdk 1.1.57 → 1.1.58-staging.273

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