@d-id/client-sdk 1.1.0-beta.4 → 1.1.0-beta.6

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