@d-id/client-sdk 1.1.29 → 1.1.30-staging.138

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