@opencx/widget-core 5.5.0 → 5.6.0

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,43 +1,43 @@
1
- import se from "lodash.isequal";
1
+ import oe from "lodash.isequal";
2
2
  import { z as h } from "zod";
3
- import oe from "openapi-fetch";
4
- import { v4 as N } from "uuid";
5
- const O = "[opencx]", b = {
3
+ import ne from "openapi-fetch";
4
+ import { v4 as K } from "uuid";
5
+ const F = "[opencx]", b = {
6
6
  warn: (i, ...e) => {
7
- console.warn(`${O} ${i}`, ...e);
7
+ console.warn(`${F} ${i}`, ...e);
8
8
  },
9
9
  error: (i, ...e) => {
10
- console.error(`${O} ${i}`, ...e);
10
+ console.error(`${F} ${i}`, ...e);
11
11
  }
12
12
  };
13
13
  class z {
14
14
  constructor(e) {
15
- this.subscribers = /* @__PURE__ */ new Set(), this.get = () => this.state, this.set = (s) => {
16
- se(this.state, s) || (this.state = s, this.notifySubscribers(s));
17
- }, this.setPartial = (s) => {
18
- if (s == null) return;
19
- const o = { ...this.state, ...s };
15
+ this.subscribers = /* @__PURE__ */ new Set(), this.get = () => this.state, this.set = (t) => {
16
+ oe(this.state, t) || (this.state = t, this.notifySubscribers(t));
17
+ }, this.setPartial = (t) => {
18
+ if (t == null) return;
19
+ const o = { ...this.state, ...t };
20
20
  this.set(o);
21
21
  }, this.reset = () => {
22
22
  this.set(this.initialState);
23
- }, this.notifySubscribers = (s) => {
23
+ }, this.notifySubscribers = (t) => {
24
24
  Array.from(this.subscribers).forEach((r) => {
25
25
  try {
26
- r(s);
26
+ r(t);
27
27
  } catch (_) {
28
28
  b.error("state subscriber threw", _);
29
29
  }
30
30
  });
31
- }, this.subscribe = (s) => (this.subscribers.add(s), () => {
32
- this.subscribers.delete(s);
31
+ }, this.subscribe = (t) => (this.subscribers.add(t), () => {
32
+ this.subscribers.delete(t);
33
33
  }), this.state = e, this.initialState = e;
34
34
  }
35
35
  }
36
- const ne = 5e3;
37
- class ie {
36
+ const ie = 5e3;
37
+ class re {
38
38
  constructor({
39
39
  config: e,
40
- api: s,
40
+ api: t,
41
41
  sessionsState: o,
42
42
  setSessions: r
43
43
  }) {
@@ -46,64 +46,64 @@ class ie {
46
46
  }, this.setViewingSessionId = (_) => {
47
47
  this.viewingSessionId = _, this.evaluate(this.sessionsState.get().data);
48
48
  }, this.evaluate = (_) => {
49
- const t = [];
49
+ const s = [];
50
50
  for (const a of _) {
51
51
  if (a.id === this.viewingSessionId) {
52
52
  (a.unread === !0 || a.unread === !1 && !this.reportedSessionIds.has(a.id)) && this.markViewedSessionRead(a.id);
53
53
  continue;
54
54
  }
55
- a.unread === !0 && t.push(a.id);
55
+ a.unread === !0 && s.push(a.id);
56
56
  }
57
- this.state.set({ unreadSessionIds: t, count: t.length }), this.notifyCount(t.length);
57
+ this.state.set({ unreadSessionIds: s, count: s.length }), this.notifyCount(s.length);
58
58
  }, this.markViewedSessionRead = (_) => {
59
59
  if (this.readsInFlight.has(_)) return;
60
60
  this.readsInFlight.add(_);
61
- let t = !1;
61
+ let s = !1;
62
62
  this.api.markSessionRead({ sessionId: _ }).then(({ data: a }) => {
63
63
  if (!a || this.disposed) return;
64
64
  this.reportedSessionIds.add(_);
65
65
  const n = this.sessionsState.get().data.find((c) => c.id === a.id);
66
- n && re(n, a) ? t = !0 : this.setSessions([a]);
66
+ n && _e(n, a) ? s = !0 : this.setSessions([a]);
67
67
  }).catch((a) => {
68
68
  b.warn("failed to mark the session read", {
69
69
  sessionId: _,
70
70
  error: a instanceof Error ? a.message : String(a)
71
71
  }), this.scheduleRetry();
72
72
  }).finally(() => {
73
- this.readsInFlight.delete(_), t && !this.disposed && this.evaluate(this.sessionsState.get().data);
73
+ this.readsInFlight.delete(_), s && !this.disposed && this.evaluate(this.sessionsState.get().data);
74
74
  });
75
75
  }, this.scheduleRetry = () => {
76
76
  this.retryTimer || this.disposed || (this.retryTimer = setTimeout(() => {
77
77
  this.retryTimer = null, this.evaluate(this.sessionsState.get().data);
78
- }, ne));
78
+ }, ie));
79
79
  }, this.notifyCount = (_) => {
80
- var t, a;
80
+ var s, a;
81
81
  if (_ !== this.lastNotifiedCount) {
82
82
  this.lastNotifiedCount = _;
83
83
  try {
84
- (a = (t = this.config.hooks) == null ? void 0 : t.onUnreadCountChange) == null || a.call(t, _);
84
+ (a = (s = this.config.hooks) == null ? void 0 : s.onUnreadCountChange) == null || a.call(s, _);
85
85
  } catch (n) {
86
86
  b.error("onUnreadCountChange hook failed", n);
87
87
  }
88
88
  }
89
- }, this.config = e, this.api = s, this.sessionsState = o, this.setSessions = r, this.subscriptions.push(
89
+ }, this.config = e, this.api = t, this.sessionsState = o, this.setSessions = r, this.subscriptions.push(
90
90
  o.subscribe(({ data: _ }) => this.evaluate(_))
91
91
  );
92
92
  }
93
93
  }
94
- function re(i, e) {
94
+ function _e(i, e) {
95
95
  return new Date(i.updatedAt).getTime() > new Date(e.updatedAt).getTime();
96
96
  }
97
- const Ya = (i) => i.type === "data-keepalive", Qa = (i) => i.type === "data-turn-steered", F = h.object({ const: h.string(), title: h.string().optional() }), _e = h.object({
97
+ const Xa = (i) => i.type === "data-keepalive", et = (i) => i.type === "data-turn-steered", U = h.object({ const: h.string(), title: h.string().optional() }), le = h.object({
98
98
  type: h.enum(["string", "number", "integer", "boolean", "array"]),
99
99
  title: h.string().optional(),
100
100
  description: h.string().optional(),
101
101
  default: h.union([h.string(), h.number(), h.boolean(), h.array(h.string())]).optional(),
102
102
  enum: h.array(h.string()).optional(),
103
- oneOf: h.array(F).optional(),
103
+ oneOf: h.array(U).optional(),
104
104
  items: h.object({
105
105
  enum: h.array(h.string()).optional(),
106
- anyOf: h.array(F).optional()
106
+ anyOf: h.array(U).optional()
107
107
  }).optional(),
108
108
  minItems: h.number().int().nonnegative().optional(),
109
109
  maxItems: h.number().int().nonnegative().optional(),
@@ -112,7 +112,7 @@ const Ya = (i) => i.type === "data-keepalive", Qa = (i) => i.type === "data-turn
112
112
  minLength: h.number().optional(),
113
113
  maxLength: h.number().optional(),
114
114
  format: h.string().optional()
115
- }), le = h.array(
115
+ }), ce = h.array(
116
116
  h.object({
117
117
  id: h.string(),
118
118
  serverId: h.string(),
@@ -122,12 +122,12 @@ const Ya = (i) => i.type === "data-keepalive", Qa = (i) => i.type === "data-turn
122
122
  form: h.object({
123
123
  message: h.string(),
124
124
  requestedSchema: h.object({
125
- properties: h.record(h.string(), _e),
125
+ properties: h.record(h.string(), le),
126
126
  required: h.array(h.string()).optional()
127
127
  })
128
128
  })
129
129
  })
130
- ), ce = h.array(
130
+ ), pe = h.array(
131
131
  h.object({
132
132
  key: h.string(),
133
133
  serverId: h.string(),
@@ -135,73 +135,73 @@ const Ya = (i) => i.type === "data-keepalive", Qa = (i) => i.type === "data-turn
135
135
  message: h.string(),
136
136
  toolName: h.string()
137
137
  })
138
- ), pe = (i) => {
138
+ ), de = (i) => {
139
139
  b.error("request failed", i.error);
140
- }, de = (i) => {
141
- const e = oe({
140
+ }, ue = (i) => {
141
+ const e = ne({
142
142
  baseUrl: i.baseUrl
143
- }), s = {
143
+ }), t = {
144
144
  onRequest: i.onRequest,
145
145
  onResponse: i.onResponse,
146
- onError: i.onError || pe
146
+ onError: i.onError || de
147
147
  };
148
- return e.use(s), e;
148
+ return e.use(t), e;
149
149
  };
150
- class ue extends Error {
150
+ class me extends Error {
151
151
  constructor() {
152
152
  super("This connection request expired. Preparing a new request."), this.name = "ConnectionRequestExpiredError";
153
153
  }
154
154
  }
155
- class me extends Error {
155
+ class he extends Error {
156
156
  constructor() {
157
157
  super("This connection attempt is no longer available."), this.name = "ConnectionAttemptUnavailableError";
158
158
  }
159
159
  }
160
- const he = "/backend/widget/v5/chat/stream", ge = "/backend/widget/v5/chat/{sessionId}/stream", U = (i, e, s) => `${i.replace(/\/$/, "")}${s ? e.replace("{sessionId}", encodeURIComponent(s)) : e}`;
161
- class B {
160
+ const ge = "/backend/widget/v5/chat/stream", ke = "/backend/widget/v5/chat/{sessionId}/stream", B = (i, e, t) => `${i.replace(/\/$/, "")}${t ? e.replace("{sessionId}", encodeURIComponent(t)) : e}`;
161
+ class H {
162
162
  constructor({ config: e }) {
163
163
  var r, _;
164
- this.userToken = null, this.constructClientOptions = (t) => {
164
+ this.userToken = null, this.constructClientOptions = (s) => {
165
165
  const a = this.config.apiUrl || "https://api.open.cx", n = {
166
166
  "X-Bot-Token": this.config.token,
167
167
  "Content-Type": "application/json",
168
168
  Accept: "application/json",
169
- Authorization: t ? `Bearer ${t}` : void 0
169
+ Authorization: s ? `Bearer ${s}` : void 0
170
170
  };
171
171
  return { baseUrl: a, headers: n };
172
172
  }, this.createOpenAPIClient = ({
173
- baseUrl: t,
173
+ baseUrl: s,
174
174
  headers: a
175
- }) => de({
176
- baseUrl: t,
175
+ }) => ue({
176
+ baseUrl: s,
177
177
  onRequest: ({ request: n }) => {
178
178
  Object.entries(a).forEach(([c, d]) => {
179
179
  d && n.headers.set(c, d);
180
180
  });
181
181
  }
182
182
  }), this.listApprovalPreferences = async () => {
183
- const { baseUrl: t, headers: a } = this.getStreamAuthContext(), n = await fetch(
184
- `${t}/backend/widget/v5/connections/approval-preferences`,
183
+ const { baseUrl: s, headers: a } = this.getStreamAuthContext(), n = await fetch(
184
+ `${s}/backend/widget/v5/connections/approval-preferences`,
185
185
  { headers: a }
186
186
  );
187
187
  if (!n.ok) throw new Error("Could not load permissions.");
188
- return ce.parse(await n.json());
189
- }, this.revokeApprovalPreference = async (t, a) => {
188
+ return pe.parse(await n.json());
189
+ }, this.revokeApprovalPreference = async (s, a) => {
190
190
  const { baseUrl: n, headers: c } = this.getStreamAuthContext();
191
191
  if (!(await fetch(
192
- `${n}/backend/widget/v5/connections/${encodeURIComponent(t)}/approval-preferences/${encodeURIComponent(a)}`,
192
+ `${n}/backend/widget/v5/connections/${encodeURIComponent(s)}/approval-preferences/${encodeURIComponent(a)}`,
193
193
  { method: "DELETE", headers: c }
194
194
  )).ok) throw new Error("Could not reset permission.");
195
- }, this.listElicitations = async (t, a) => {
195
+ }, this.listElicitations = async (s, a) => {
196
196
  const { baseUrl: n, headers: c } = this.getStreamAuthContext(), d = await fetch(
197
- `${n}/backend/widget/v5/connections/elicitation/${encodeURIComponent(t)}`,
197
+ `${n}/backend/widget/v5/connections/elicitation/${encodeURIComponent(s)}`,
198
198
  { headers: c, signal: a }
199
199
  );
200
200
  if (!d.ok) throw new Error("Could not load the request.");
201
- return le.parse(await d.json());
202
- }, this.answerElicitation = async (t, a, n) => {
201
+ return ce.parse(await d.json());
202
+ }, this.answerElicitation = async (s, a, n) => {
203
203
  const { baseUrl: c, headers: d } = this.getStreamAuthContext(), l = await fetch(
204
- `${c}/backend/widget/v5/connections/elicitation/${encodeURIComponent(t)}/${encodeURIComponent(a)}`,
204
+ `${c}/backend/widget/v5/connections/elicitation/${encodeURIComponent(s)}/${encodeURIComponent(a)}`,
205
205
  {
206
206
  method: "POST",
207
207
  headers: { ...d, "Content-Type": "application/json" },
@@ -212,87 +212,87 @@ class B {
212
212
  throw new Error(
213
213
  l.status === 400 ? "Check your answers and try again." : "This request has ended. Ask the agent to try again."
214
214
  );
215
- }, this.listConnections = async (t) => {
215
+ }, this.listConnections = async (s) => {
216
216
  const { data: a, error: n } = await this.client.GET(
217
217
  "/backend/widget/v5/connections",
218
- { signal: t }
218
+ { signal: s }
219
219
  );
220
220
  if (n || !a)
221
221
  throw new Error("Could not load connections. Sign in and try again.");
222
222
  return a;
223
- }, this.startConnection = async (t, a, n) => {
223
+ }, this.startConnection = async (s, a, n) => {
224
224
  const { data: c, error: d, response: l } = await this.client.POST(
225
225
  "/backend/widget/v5/connections/{serverId}/start",
226
226
  {
227
- params: { path: { serverId: t } },
227
+ params: { path: { serverId: s } },
228
228
  body: { request_id: a },
229
229
  signal: n
230
230
  }
231
231
  );
232
- if (l.status === 410) throw new ue();
232
+ if (l.status === 410) throw new me();
233
233
  if (l.status === 404)
234
234
  throw new Error("This connection request is no longer available.");
235
235
  if (d || !c)
236
236
  throw new Error("Could not start this connection. Please try again.");
237
237
  return c;
238
- }, this.getConnectionAttempt = async (t, a, n) => {
238
+ }, this.getConnectionAttempt = async (s, a, n) => {
239
239
  const { data: c, error: d, response: l } = await this.client.GET(
240
240
  "/backend/widget/v5/connections/{serverId}/attempts/{attemptId}",
241
241
  {
242
- params: { path: { serverId: t, attemptId: a } },
242
+ params: { path: { serverId: s, attemptId: a } },
243
243
  signal: n
244
244
  }
245
245
  );
246
246
  if ([401, 403, 404].includes(l.status))
247
- throw new me();
247
+ throw new he();
248
248
  if (d || !c)
249
249
  throw new Error(`Could not check the connection (${l.status}).`);
250
250
  return c.status;
251
- }, this.disconnectConnection = async (t) => {
251
+ }, this.disconnectConnection = async (s) => {
252
252
  const { error: a } = await this.client.DELETE(
253
253
  "/backend/widget/v5/connections/{serverId}",
254
254
  {
255
- params: { path: { serverId: t } }
255
+ params: { path: { serverId: s } }
256
256
  }
257
257
  );
258
258
  if (a) throw new Error("Could not disconnect. Please try again.");
259
- }, this.setAuthToken = (t) => {
260
- this.userToken = t;
261
- const { baseUrl: a, headers: n } = this.constructClientOptions(t);
259
+ }, this.setAuthToken = (s) => {
260
+ this.userToken = s;
261
+ const { baseUrl: a, headers: n } = this.constructClientOptions(s);
262
262
  this.client = this.createOpenAPIClient({ baseUrl: a, headers: n });
263
263
  }, this.getStreamAuthContext = () => {
264
- const { baseUrl: t, headers: a } = this.constructClientOptions(this.userToken), n = {};
264
+ const { baseUrl: s, headers: a } = this.constructClientOptions(this.userToken), n = {};
265
265
  for (const [c, d] of Object.entries(a))
266
266
  typeof d == "string" && (["content-type", "accept"].includes(c.toLowerCase()) || (n[c] = d));
267
- return { baseUrl: t, headers: n };
267
+ return { baseUrl: s, headers: n };
268
268
  }, this.getStreamTransportOptions = () => {
269
- const { baseUrl: t, headers: a } = this.getStreamAuthContext();
269
+ const { baseUrl: s, headers: a } = this.getStreamAuthContext();
270
270
  return {
271
- api: U(t, he),
272
- reconnectApi: (n) => U(t, ge, n),
271
+ api: B(s, ge),
272
+ reconnectApi: (n) => B(s, ke, n),
273
273
  headers: a
274
274
  };
275
- }, this.stopStream = async (t) => {
275
+ }, this.stopStream = async (s) => {
276
276
  const { response: a } = await this.client.POST(
277
277
  "/backend/widget/v5/chat/{sessionId}/stop",
278
- { params: { path: { sessionId: t } } }
278
+ { params: { path: { sessionId: s } } }
279
279
  );
280
280
  if (!a.ok)
281
281
  throw new Error(`Failed to stop stream: ${a.status}`);
282
- }, this.sendPageReply = async (t, a) => {
282
+ }, this.sendPageReply = async (s, a) => {
283
283
  try {
284
284
  await this.client.POST("/backend/widget/v5/chat/{sessionId}/page-reply", {
285
- params: { path: { sessionId: t } },
285
+ params: { path: { sessionId: s } },
286
286
  body: a
287
287
  });
288
288
  } catch {
289
289
  }
290
- }, this.getAgentTurnMessages = async (t, a) => {
290
+ }, this.getAgentTurnMessages = async (s, a) => {
291
291
  const { data: n, response: c } = await this.client.GET(
292
292
  "/backend/widget/v5/chat/{sessionId}/messages",
293
293
  {
294
294
  params: {
295
- path: { sessionId: t },
295
+ path: { sessionId: s },
296
296
  query: {
297
297
  toolActivity: a == null ? void 0 : a.toolActivity,
298
298
  reasoning: (a == null ? void 0 : a.reasoning) === void 0 ? void 0 : a.reasoning ? "true" : "false"
@@ -305,11 +305,11 @@ class B {
305
305
  handled_connection_request_ids: n.handled_connection_request_ids ?? []
306
306
  } : (b.warn("agent turn messages fetch failed", c.status), null);
307
307
  }, this.createDictationSession = async ({
308
- language: t
308
+ language: s
309
309
  }) => {
310
310
  const { data: a, response: n } = await this.client.POST(
311
311
  "/backend/widget/v5/dictation/sessions",
312
- { body: t ? { language: t } : {} }
312
+ { body: s ? { language: s } : {} }
313
313
  );
314
314
  if (!a)
315
315
  throw new Error(`Failed to start dictation: ${n.status}`);
@@ -318,53 +318,53 @@ class B {
318
318
  params: {
319
319
  header: { "x-bot-token": this.config.token }
320
320
  }
321
- }), this.sendMessage = async (t, a) => await this.client.POST("/backend/widget/v2/chat/send", {
322
- body: t,
321
+ }), this.sendMessage = async (s, a) => await this.client.POST("/backend/widget/v2/chat/send", {
322
+ body: s,
323
323
  signal: a
324
- }), this.createUnverifiedContact = async (t) => await this.client.POST(
324
+ }), this.createUnverifiedContact = async (s) => await this.client.POST(
325
325
  "/backend/widget/v2/contact/create-unverified",
326
326
  {
327
327
  params: { header: { "x-bot-token": this.config.token } },
328
- body: t
328
+ body: s
329
329
  }
330
- ), this.createSession = async (t, a) => await this.client.POST("/backend/widget/v2/create-session", {
331
- body: t,
330
+ ), this.createSession = async (s, a) => await this.client.POST("/backend/widget/v2/create-session", {
331
+ body: s,
332
332
  signal: a
333
333
  }), this.pollSessionAndHistory = async ({
334
- sessionId: t,
334
+ sessionId: s,
335
335
  abortSignal: a
336
336
  }) => await this.client.GET("/backend/widget/v2/poll/{sessionId}", {
337
- params: { path: { sessionId: t } },
337
+ params: { path: { sessionId: s } },
338
338
  signal: a
339
339
  }), this.markSessionRead = async ({
340
- sessionId: t,
340
+ sessionId: s,
341
341
  abortSignal: a
342
342
  }) => await this.client.POST(
343
343
  "/backend/widget/v2/session/{sessionId}/read",
344
344
  {
345
- params: { path: { sessionId: t } },
345
+ params: { path: { sessionId: s } },
346
346
  signal: a
347
347
  }
348
348
  ), this.getSessions = async ({
349
- cursor: t,
349
+ cursor: s,
350
350
  filters: a,
351
351
  abortSignal: n
352
352
  }) => await this.client.GET("/backend/widget/v2/sessions", {
353
353
  params: {
354
354
  query: {
355
- offset: t,
355
+ offset: s,
356
356
  filters: JSON.stringify(a)
357
357
  }
358
358
  },
359
359
  signal: n
360
360
  }), this.uploadFile = async ({
361
- file: t,
361
+ file: s,
362
362
  abortSignal: a,
363
363
  onProgress: n
364
364
  }) => new Promise((c, d) => {
365
365
  var y;
366
366
  const l = new FormData();
367
- l.append("file", t);
367
+ l.append("file", s);
368
368
  const p = new XMLHttpRequest();
369
369
  if (a && (a.addEventListener("abort", () => {
370
370
  p.abort(), d(new DOMException("Aborted", "AbortError"));
@@ -372,18 +372,18 @@ class B {
372
372
  d(new DOMException("Aborted", "AbortError"));
373
373
  return;
374
374
  }
375
- p.upload.addEventListener("progress", (f) => {
376
- if (f.lengthComputable && n) {
377
- const w = Math.round(f.loaded / f.total * 100);
375
+ p.upload.addEventListener("progress", (v) => {
376
+ if (v.lengthComputable && n) {
377
+ const w = Math.round(v.loaded / v.total * 100);
378
378
  n(w);
379
379
  }
380
380
  }), p.addEventListener("load", () => {
381
381
  if (p.status >= 200 && p.status < 300)
382
382
  try {
383
- const f = JSON.parse(p.responseText);
384
- c(f);
385
- } catch (f) {
386
- d(new Error(`Failed to parse response: ${f}`));
383
+ const v = JSON.parse(p.responseText);
384
+ c(v);
385
+ } catch (v) {
386
+ d(new Error(`Failed to parse response: ${v}`));
387
387
  }
388
388
  else
389
389
  d(new Error(`Upload failed with status: ${p.status}`));
@@ -394,22 +394,22 @@ class B {
394
394
  });
395
395
  const { baseUrl: u } = this.constructClientOptions(this.userToken), g = `${u}/backend/widget/v2/upload`;
396
396
  p.open("POST", g), p.setRequestHeader("X-Bot-Token", this.config.token), this.userToken ?? ((y = this.config.user) == null ? void 0 : y.token) ? p.setRequestHeader("Authorization", `Bearer ${this.userToken}`) : b.error("user token not set"), p.send(l);
397
- }), this.vote = async (t) => await this.client.POST("/backend/widget/v2/chat/vote", { body: t }), this.resolveSession = async (t, a) => await this.client.POST("/backend/widget/v2/session/resolve", {
398
- body: t,
397
+ }), this.vote = async (s) => await this.client.POST("/backend/widget/v2/chat/vote", { body: s }), this.resolveSession = async (s, a) => await this.client.POST("/backend/widget/v2/session/resolve", {
398
+ body: s,
399
399
  signal: a
400
- }), this.createStateCheckpoint = async (t) => await this.client.POST("/backend/widget/v2/checkpoint", {
401
- body: t
402
- }), this.submitCsat = async (t) => await this.client.POST("/backend/widget/v2/submit-csat", { body: t }), this.config = e, this.userToken = ((r = e.user) == null ? void 0 : r.token) || null;
403
- const { baseUrl: s, headers: o } = this.constructClientOptions(
400
+ }), this.createStateCheckpoint = async (s) => await this.client.POST("/backend/widget/v2/checkpoint", {
401
+ body: s
402
+ }), this.submitCsat = async (s) => await this.client.POST("/backend/widget/v2/submit-csat", { body: s }), this.config = e, this.userToken = ((r = e.user) == null ? void 0 : r.token) || null;
403
+ const { baseUrl: t, headers: o } = this.constructClientOptions(
404
404
  (_ = e.user) == null ? void 0 : _.token
405
405
  );
406
- this.client = this.createOpenAPIClient({ baseUrl: s, headers: o });
406
+ this.client = this.createOpenAPIClient({ baseUrl: t, headers: o });
407
407
  }
408
408
  }
409
- function ke(i, e) {
409
+ function be(i, e) {
410
410
  b.error(`missing case for ${i} in ${e}`);
411
411
  }
412
- class $ {
412
+ class J {
413
413
  constructor() {
414
414
  this.state = new z({
415
415
  isPolling: !1,
@@ -417,7 +417,7 @@ class $ {
417
417
  }), this.abortController = new AbortController(), this.reset = () => {
418
418
  var e;
419
419
  this.abortController.abort("Resetting poller"), (e = this.stopPolling) == null || e.call(this), this.stopPolling = null;
420
- }, this.stopPolling = null, this.startPolling = (e, s) => {
420
+ }, this.stopPolling = null, this.startPolling = (e, t) => {
421
421
  if (this.stopPolling) return;
422
422
  const o = [], r = async () => {
423
423
  this.abortController = new AbortController(), this.state.setPartial({ isPolling: !0 });
@@ -430,7 +430,7 @@ class $ {
430
430
  } finally {
431
431
  this.state.setPartial({ isPolling: !1 });
432
432
  }
433
- this.abortController.signal.aborted || o.push(setTimeout(r, s));
433
+ this.abortController.signal.aborted || o.push(setTimeout(r, t));
434
434
  };
435
435
  r(), this.stopPolling = () => {
436
436
  o.forEach(clearTimeout), this.state.reset();
@@ -438,42 +438,42 @@ class $ {
438
438
  };
439
439
  }
440
440
  }
441
- function J(i) {
441
+ function Y(i) {
442
442
  try {
443
443
  const e = i();
444
- return e instanceof Promise ? e.then((s) => ({ data: s })).catch((s) => ({ error: s })) : { data: e };
444
+ return e instanceof Promise ? e.then((t) => ({ data: t })).catch((t) => ({ error: t })) : { data: e };
445
445
  } catch (e) {
446
446
  return { error: e };
447
447
  }
448
448
  }
449
- class be {
449
+ class fe {
450
450
  constructor({
451
451
  api: e,
452
- config: s,
452
+ config: t,
453
453
  sessionCtx: o,
454
454
  messageCtx: r,
455
455
  sessionPollingIntervalSeconds: _
456
456
  }) {
457
- this.poller = new $(), this.fetchSessionAndFullHistoryAbortController = new AbortController(), this.reconcileAbortController = new AbortController(), this.subscriptions = [], this.reconcilingSessionId = null, this.seenHistoryIds = /* @__PURE__ */ new Set(), this.removedHistoryIds = /* @__PURE__ */ new Set(), this.protectedUntilSeq = /* @__PURE__ */ new Map(), this.landedPollSessionId = null, this.pollSeq = 0, this.lastAppliedSeq = 0, this.removableAfterSeq = 0, this.registerPolling = () => {
457
+ this.poller = new J(), this.fetchSessionAndFullHistoryAbortController = new AbortController(), this.reconcileAbortController = new AbortController(), this.subscriptions = [], this.reconcilingSessionId = null, this.seenHistoryIds = /* @__PURE__ */ new Set(), this.removedHistoryIds = /* @__PURE__ */ new Set(), this.protectedUntilSeq = /* @__PURE__ */ new Map(), this.landedPollSessionId = null, this.pollSeq = 0, this.lastAppliedSeq = 0, this.removableAfterSeq = 0, this.registerPolling = () => {
458
458
  this.subscriptions.push(
459
- this.sessionCtx.sessionState.subscribe(({ session: t }) => {
460
- ((t == null ? void 0 : t.id) ?? null) !== this.landedPollSessionId && (this.seenHistoryIds = /* @__PURE__ */ new Set(), this.removedHistoryIds = /* @__PURE__ */ new Set(), this.protectedUntilSeq = /* @__PURE__ */ new Map(), this.removableAfterSeq = 0, this.landedPollSessionId = null);
459
+ this.sessionCtx.sessionState.subscribe(({ session: s }) => {
460
+ ((s == null ? void 0 : s.id) ?? null) !== this.landedPollSessionId && (this.seenHistoryIds = /* @__PURE__ */ new Set(), this.removedHistoryIds = /* @__PURE__ */ new Set(), this.protectedUntilSeq = /* @__PURE__ */ new Map(), this.removableAfterSeq = 0, this.landedPollSessionId = null);
461
461
  })
462
462
  ), this.subscriptions.push(
463
- this.sessionCtx.sessionState.subscribe(({ session: t }) => {
464
- t != null && t.id ? this.poller.startPolling(async (a) => {
463
+ this.sessionCtx.sessionState.subscribe(({ session: s }) => {
464
+ s != null && s.id ? this.poller.startPolling(async (a) => {
465
465
  this.fetchSessionAndHistory({
466
- sessionId: t.id,
466
+ sessionId: s.id,
467
467
  abortSignal: a
468
468
  });
469
469
  }, this.sessionPollingIntervalSeconds * 1e3) : this.poller.reset();
470
470
  })
471
471
  ), this.subscriptions.push(
472
- this.sessionCtx.sessionState.subscribe(({ session: t }) => {
473
- if (t != null && t.id && !t.isOpened)
472
+ this.sessionCtx.sessionState.subscribe(({ session: s }) => {
473
+ if (s != null && s.id && !s.isOpened)
474
474
  try {
475
475
  this.fetchSessionAndFullHistoryAbortController = new AbortController(), this.fetchSessionAndHistory({
476
- sessionId: t.id,
476
+ sessionId: s.id,
477
477
  abortSignal: this.fetchSessionAndFullHistoryAbortController.signal
478
478
  });
479
479
  } catch (a) {
@@ -483,36 +483,36 @@ class be {
483
483
  this.fetchSessionAndFullHistoryAbortController.abort();
484
484
  })
485
485
  ), this.subscriptions.push(
486
- this.sessionCtx.sessionState.subscribe(({ session: t }) => {
487
- this.reconcilingSessionId !== null && (t == null ? void 0 : t.id) !== this.reconcilingSessionId && this.reconcileAbortController.abort();
486
+ this.sessionCtx.sessionState.subscribe(({ session: s }) => {
487
+ this.reconcilingSessionId !== null && (s == null ? void 0 : s.id) !== this.reconcilingSessionId && this.reconcileAbortController.abort();
488
488
  })
489
489
  );
490
490
  }, this.dispose = () => {
491
- this.poller.reset(), this.fetchSessionAndFullHistoryAbortController.abort(), this.reconcileAbortController.abort(), this.reconcilingSessionId = null, this.subscriptions.forEach((t) => t()), this.subscriptions = [];
492
- }, this.reconcileAfterStream = async (t) => {
491
+ this.poller.reset(), this.fetchSessionAndFullHistoryAbortController.abort(), this.reconcileAbortController.abort(), this.reconcilingSessionId = null, this.subscriptions.forEach((s) => s()), this.subscriptions = [];
492
+ }, this.reconcileAfterStream = async (s) => {
493
493
  this.reconcileAbortController.abort(), this.reconcileAbortController = new AbortController();
494
494
  const { signal: a } = this.reconcileAbortController;
495
- this.reconcilingSessionId = t;
495
+ this.reconcilingSessionId = s;
496
496
  try {
497
- await this.fetchSessionAndHistory({ sessionId: t, abortSignal: a });
497
+ await this.fetchSessionAndHistory({ sessionId: s, abortSignal: a });
498
498
  } catch (n) {
499
499
  if (!a.aborted) throw n;
500
500
  } finally {
501
- this.reconcilingSessionId === t && (this.reconcilingSessionId = null);
501
+ this.reconcilingSessionId === s && (this.reconcilingSessionId = null);
502
502
  }
503
503
  }, this.fetchSessionAndHistory = async ({
504
- sessionId: t,
504
+ sessionId: s,
505
505
  abortSignal: a
506
506
  }) => {
507
- const n = this.landedPollSessionId !== t && this.messageCtx.state.get().messages.length === 0;
507
+ const n = this.landedPollSessionId !== s && this.messageCtx.state.get().messages.length === 0;
508
508
  n && this.messageCtx.state.setPartial({ isInitialFetchLoading: !0 });
509
509
  const c = ++this.pollSeq, { data: d } = await this.api.pollSessionAndHistory({
510
- sessionId: t,
510
+ sessionId: s,
511
511
  abortSignal: a
512
512
  });
513
513
  if (d != null && d.session && (this.sessionCtx.sessionState.setPartial({ session: d.session }), this.sessionCtx.setSessions([d.session])), d != null && d.history) {
514
514
  const l = c < this.lastAppliedSeq, p = !l && c > this.removableAfterSeq;
515
- l || (this.lastAppliedSeq = c), p && (this.removableAfterSeq = this.pollSeq), this.landedPollSessionId = t, d.history.length > 0 && this.reconcileOptionPicks(d.history);
515
+ l || (this.lastAppliedSeq = c), p && (this.removableAfterSeq = this.pollSeq), this.landedPollSessionId = s, d.history.length > 0 && this.reconcileOptionPicks(d.history);
516
516
  const u = new Set(d.history.map((k) => k.publicId)), m = p ? Array.from(this.seenHistoryIds).filter((k) => !u.has(k)) : [], g = new Set(
517
517
  m.filter((k) => (this.protectedUntilSeq.get(k) ?? 0) < c)
518
518
  );
@@ -520,15 +520,15 @@ class be {
520
520
  ...Array.from(u),
521
521
  ...m.filter((k) => !g.has(k))
522
522
  ]) : u.forEach((k) => this.seenHistoryIds.add(k)), g.forEach((k) => this.removedHistoryIds.add(k));
523
- const v = this.messageCtx.state.get().messages, y = d.history.map(this.mapHistoryToMessage).filter((k) => k !== null).filter((k) => !this.removedHistoryIds.has(k.id)).filter(
524
- (k) => !v.some((M) => M.id === k.id)
523
+ const f = this.messageCtx.state.get().messages, y = d.history.map(this.mapHistoryToMessage).filter((k) => k !== null).filter((k) => !this.removedHistoryIds.has(k.id)).filter(
524
+ (k) => !f.some((D) => D.id === k.id)
525
525
  );
526
526
  p || y.forEach(
527
527
  (k) => this.protectedUntilSeq.set(k.id, this.pollSeq)
528
528
  );
529
- let f = !1;
530
- const w = v.flatMap((k) => g.has(k.id) ? [] : "replyTo" in k && k.replyTo && g.has(k.replyTo.id) ? (f = !0, [{ ...k, replyTo: void 0 }]) : [k]);
531
- if (y.length > 0 || w.length !== v.length || f)
529
+ let v = !1;
530
+ const w = f.flatMap((k) => g.has(k.id) ? [] : "replyTo" in k && k.replyTo && g.has(k.replyTo.id) ? (v = !0, [{ ...k, replyTo: void 0 }]) : [k]);
531
+ if (y.length > 0 || w.length !== f.length || v)
532
532
  if (this.messageCtx.state.setPartial({
533
533
  messages: [...w, ...y]
534
534
  }), n)
@@ -540,50 +540,50 @@ class be {
540
540
  this.messageCtx.dispatchToOnMessageReceivedHook(k);
541
541
  }
542
542
  this.messageCtx.state.get().isInitialFetchLoading && this.messageCtx.state.setPartial({ isInitialFetchLoading: !1 });
543
- }, this.reconcileOptionPicks = (t) => {
543
+ }, this.reconcileOptionPicks = (s) => {
544
544
  var a;
545
- for (const n of t) {
545
+ for (const n of s) {
546
546
  const c = (a = n.messageOptions) == null ? void 0 : a.pickedOptionId;
547
547
  c && this.messageCtx.setMessageOptionPick(n.publicId, c);
548
548
  }
549
- }, this.mapHistoryToMessage = (t) => {
549
+ }, this.mapHistoryToMessage = (s) => {
550
550
  var n;
551
551
  const a = {
552
- id: t.publicId,
553
- timestamp: t.sentAt || "",
554
- attachments: t.attachments || void 0
552
+ id: s.publicId,
553
+ timestamp: s.sentAt || "",
554
+ attachments: s.attachments || void 0
555
555
  };
556
- if (t.sender.kind === "user")
556
+ if (s.sender.kind === "user")
557
557
  return {
558
558
  ...a,
559
559
  type: "USER",
560
560
  deliveredAt: a.timestamp,
561
- content: t.content.text || "",
561
+ content: s.content.text || "",
562
562
  // Backend field name (schema.ts) → widget vocabulary.
563
- markedElements: t.pickedElements
563
+ markedElements: s.pickedElements
564
564
  };
565
- if (t.sender.kind === "agent")
565
+ if (s.sender.kind === "agent")
566
566
  return {
567
567
  ...a,
568
568
  type: "AGENT",
569
569
  component: "agent_message",
570
570
  data: {
571
- message: t.content.text || ""
571
+ message: s.content.text || ""
572
572
  },
573
573
  agent: {
574
- name: t.sender.name || "",
574
+ name: s.sender.name || "",
575
575
  // Do not set avatarUrl from config here... let it be taken from the config at render time
576
576
  // Only set avatar url from the backend's response
577
- avatarUrl: t.sender.avatar || null,
578
- avatar: t.sender.avatar || null,
577
+ avatarUrl: s.sender.avatar || null,
578
+ avatar: s.sender.avatar || null,
579
579
  id: null,
580
580
  isAi: !1
581
581
  },
582
- ...this.constructReplyTo(t),
583
- ...t.messageOptions ? { messageOptions: t.messageOptions } : {}
582
+ ...this.constructReplyTo(s),
583
+ ...this.constructMessageOptions(s)
584
584
  };
585
- if (t.sender.kind === "ai") {
586
- const c = t.actionCalls && t.actionCalls.length > 0 ? t.actionCalls[t.actionCalls.length - 1] : void 0;
585
+ if (s.sender.kind === "ai") {
586
+ const c = s.actionCalls && s.actionCalls.length > 0 ? s.actionCalls[s.actionCalls.length - 1] : void 0;
587
587
  return {
588
588
  ...a,
589
589
  type: "AI",
@@ -597,23 +597,25 @@ class be {
597
597
  avatar: null
598
598
  },
599
599
  data: {
600
- message: t.content.text || "",
600
+ message: s.content.text || "",
601
601
  action: c ? {
602
602
  name: c.actionName,
603
603
  data: this.extractActionResult(c)
604
604
  } : void 0
605
605
  },
606
- ...this.constructReplyTo(t)
606
+ ...this.constructReplyTo(s),
607
+ // Workflow messages (a sent macro) arrive as AI and carry options too.
608
+ ...this.constructMessageOptions(s)
607
609
  };
608
610
  }
609
- if (t.sender.kind === "system") {
610
- const c = this.constructSystemMessage(t);
611
+ if (s.sender.kind === "system") {
612
+ const c = this.constructSystemMessage(s);
611
613
  return c === null ? null : { ...c };
612
614
  }
613
615
  return null;
614
- }, this.constructReplyTo = (t) => {
615
- if (!t.replyTo) return {};
616
- const { publicId: a, text: n, sender: c } = t.replyTo;
616
+ }, this.constructReplyTo = (s) => {
617
+ if (!s.replyTo) return {};
618
+ const { publicId: a, text: n, sender: c } = s.replyTo;
617
619
  return {
618
620
  replyTo: {
619
621
  id: a,
@@ -621,64 +623,64 @@ class be {
621
623
  sender: c
622
624
  }
623
625
  };
624
- }, this.constructSystemMessage = (t) => {
625
- if (!t || !t.systemMessagePayload) return null;
626
- switch (t.systemMessagePayload.type) {
626
+ }, this.constructMessageOptions = (s) => s.messageOptions ? { messageOptions: s.messageOptions } : {}, this.constructSystemMessage = (s) => {
627
+ if (!s || !s.systemMessagePayload) return null;
628
+ switch (s.systemMessagePayload.type) {
627
629
  case "state_checkpoint":
628
630
  return {
629
- id: t.publicId,
631
+ id: s.publicId,
630
632
  type: "SYSTEM",
631
633
  subtype: "state_checkpoint",
632
- data: { payload: t.systemMessagePayload.payload },
633
- timestamp: t.sentAt || "",
634
+ data: { payload: s.systemMessagePayload.payload },
635
+ timestamp: s.sentAt || "",
634
636
  attachments: void 0
635
637
  };
636
638
  case "csat_requested":
637
639
  return {
638
- id: t.publicId,
640
+ id: s.publicId,
639
641
  type: "SYSTEM",
640
642
  subtype: "csat_requested",
641
643
  data: { payload: void 0 },
642
- timestamp: t.sentAt || "",
644
+ timestamp: s.sentAt || "",
643
645
  attachments: void 0
644
646
  };
645
647
  case "csat_submitted":
646
648
  return {
647
- id: t.publicId,
649
+ id: s.publicId,
648
650
  type: "SYSTEM",
649
651
  subtype: "csat_submitted",
650
652
  data: {
651
653
  payload: {
652
- score: t.systemMessagePayload.payload.score ?? void 0,
653
- feedback: t.systemMessagePayload.payload.feedback ?? void 0
654
+ score: s.systemMessagePayload.payload.score ?? void 0,
655
+ feedback: s.systemMessagePayload.payload.feedback ?? void 0
654
656
  }
655
657
  },
656
- timestamp: t.sentAt || "",
658
+ timestamp: s.sentAt || "",
657
659
  attachments: void 0
658
660
  };
659
661
  case "none":
660
662
  return null;
661
663
  default:
662
- return ke(
663
- t.systemMessagePayload,
664
+ return be(
665
+ s.systemMessagePayload,
664
666
  this.constructSystemMessage.name
665
667
  ), null;
666
668
  }
667
- }, this.extractActionResult = (t) => {
668
- const a = t.result;
669
+ }, this.extractActionResult = (s) => {
670
+ const a = s.result;
669
671
  if (a === null || typeof a != "object") return a;
670
672
  if ("responseBodyText" in a && typeof a.responseBodyText == "string") {
671
- const n = a.responseBodyText, c = J(() => JSON.parse(n)).data;
673
+ const n = a.responseBodyText, c = Y(() => JSON.parse(n)).data;
672
674
  if (c) return c;
673
675
  }
674
- return t.result;
675
- }, this.api = e, this.config = s, this.sessionCtx = o, this.messageCtx = r, this.sessionPollingIntervalSeconds = _, this.registerPolling();
676
+ return s.result;
677
+ }, this.api = e, this.config = t, this.sessionCtx = o, this.messageCtx = r, this.sessionPollingIntervalSeconds = _, this.registerPolling();
676
678
  }
677
679
  }
678
680
  class ve {
679
681
  constructor({
680
682
  config: e,
681
- api: s,
683
+ api: t,
682
684
  storageCtx: o
683
685
  }) {
684
686
  var r;
@@ -686,9 +688,9 @@ class ve {
686
688
  var _;
687
689
  return !!(!((_ = this.state.get().contact) != null && _.token) && this.config.collectUserData);
688
690
  }, this.autoCreateUnverifiedUserIfNotExists = async () => {
689
- var _, t, a, n, c, d, l, p, u, m, g, v, y, f;
691
+ var _, s, a, n, c, d, l, p, u, m, g, f, y, v;
690
692
  if (!((_ = this.config.user) != null && _.token)) {
691
- if (this.config.collectUserData && !((a = (t = this.config.user) == null ? void 0 : t.data) != null && a.email)) {
693
+ if (this.config.collectUserData && !((a = (s = this.config.user) == null ? void 0 : s.data) != null && a.email)) {
692
694
  if ((n = this.config.extraDataCollectionFields) != null && n.length)
693
695
  return;
694
696
  const w = await ((c = this.storageCtx) == null ? void 0 : c.getContactToken());
@@ -704,12 +706,12 @@ class ve {
704
706
  }
705
707
  await this.createUnverifiedContact({
706
708
  email: (m = (u = this.config.user) == null ? void 0 : u.data) == null ? void 0 : m.email,
707
- non_verified_name: (v = (g = this.config.user) == null ? void 0 : g.data) == null ? void 0 : v.name,
708
- non_verified_custom_data: (f = (y = this.config.user) == null ? void 0 : y.data) == null ? void 0 : f.customData
709
+ non_verified_name: (f = (g = this.config.user) == null ? void 0 : g.data) == null ? void 0 : f.name,
710
+ non_verified_custom_data: (v = (y = this.config.user) == null ? void 0 : y.data) == null ? void 0 : v.customData
709
711
  });
710
712
  }
711
- }, this.createUnverifiedContact = async (_, t) => {
712
- this.state.setPartial({ extraCollectedData: t });
713
+ }, this.createUnverifiedContact = async (_, s) => {
714
+ this.state.setPartial({ extraCollectedData: s });
713
715
  try {
714
716
  this.state.setPartial({
715
717
  isCreatingUnverifiedContact: !0,
@@ -725,11 +727,11 @@ class ve {
725
727
  this.state.setPartial({ isCreatingUnverifiedContact: !1 });
726
728
  }
727
729
  }, this.recoverFromStaleToken = async () => {
728
- var _, t, a, n, c, d, l, p, u, m;
730
+ var _, s, a, n, c, d, l, p, u, m;
729
731
  if ((_ = this.config.user) != null && _.token) return !1;
730
732
  this.api.setAuthToken(""), this.state.setPartial({ contact: null });
731
733
  try {
732
- await ((t = this.storageCtx) == null ? void 0 : t.clearContactToken()), await ((a = this.storageCtx) == null ? void 0 : a.clearActiveSessionId());
734
+ await ((s = this.storageCtx) == null ? void 0 : s.clearContactToken()), await ((a = this.storageCtx) == null ? void 0 : a.clearActiveSessionId());
733
735
  } catch (g) {
734
736
  b.warn("failed to clear a stale contact token", {
735
737
  error: g instanceof Error ? g.message : String(g)
@@ -742,9 +744,9 @@ class ve {
742
744
  }), !!((m = this.state.get().contact) != null && m.token);
743
745
  }, this.setUnverifiedContact = async (_) => {
744
746
  var n, c, d, l;
745
- const t = await ((n = this.storageCtx) == null ? void 0 : n.getExternalContactId()), a = ((c = this.config.user) == null ? void 0 : c.externalId) || t || N();
747
+ const s = await ((n = this.storageCtx) == null ? void 0 : n.getExternalContactId()), a = ((c = this.config.user) == null ? void 0 : c.externalId) || s || K();
746
748
  this.api.setAuthToken(_), await ((d = this.storageCtx) == null ? void 0 : d.setContactToken(_)), await ((l = this.storageCtx) == null ? void 0 : l.setExternalContactId(a)), this.state.setPartial({ contact: { token: _, externalId: a } });
747
- }, this.config = e, this.storageCtx = o, this.api = s, this.state = new z({
749
+ }, this.config = e, this.storageCtx = o, this.api = t, this.state = new z({
748
750
  contact: (r = e.user) != null && r.token ? {
749
751
  token: e.user.token,
750
752
  // Set optional externalId from config... not local storage
@@ -756,37 +758,37 @@ class ve {
756
758
  }), this.autoCreateUnverifiedUserIfNotExists();
757
759
  }
758
760
  }
759
- class fe {
761
+ class ye {
760
762
  constructor(e) {
761
- this.api = e, this.state = new z([]), this.controllers = /* @__PURE__ */ new Map(), this.appendFiles = (s) => {
762
- const o = s.map(
763
+ this.api = e, this.state = new z([]), this.controllers = /* @__PURE__ */ new Map(), this.appendFiles = (t) => {
764
+ const o = t.map(
763
765
  (r) => ({
764
766
  file: r,
765
- id: N(),
767
+ id: K(),
766
768
  status: "pending",
767
769
  progress: 0
768
770
  })
769
771
  );
770
772
  this.state.set([...this.state.get(), ...o]), o.forEach((r) => void this.upload(r));
771
- }, this.cancel = (s) => {
773
+ }, this.cancel = (t) => {
772
774
  var o;
773
- (o = this.controllers.get(s)) == null || o.abort(), this.controllers.delete(s), this.state.set(this.state.get().filter((r) => r.id !== s));
775
+ (o = this.controllers.get(t)) == null || o.abort(), this.controllers.delete(t), this.state.set(this.state.get().filter((r) => r.id !== t));
774
776
  }, this.reset = () => {
775
- this.controllers.forEach((s) => s.abort()), this.controllers.clear(), this.state.reset();
777
+ this.controllers.forEach((t) => t.abort()), this.controllers.clear(), this.state.reset();
776
778
  };
777
779
  }
778
- update(e, s) {
780
+ update(e, t) {
779
781
  this.state.set(
780
- this.state.get().map((o) => o.id === e ? { ...o, ...s } : o)
782
+ this.state.get().map((o) => o.id === e ? { ...o, ...t } : o)
781
783
  );
782
784
  }
783
785
  async upload(e) {
784
- const s = new AbortController();
785
- this.controllers.set(e.id, s), this.update(e.id, { status: "uploading" });
786
+ const t = new AbortController();
787
+ this.controllers.set(e.id, t), this.update(e.id, { status: "uploading" });
786
788
  try {
787
789
  const o = await this.api.uploadFile({
788
790
  file: e.file,
789
- abortSignal: s.signal,
791
+ abortSignal: t.signal,
790
792
  onProgress: (r) => this.update(e.id, { progress: r })
791
793
  });
792
794
  this.update(e.id, {
@@ -795,7 +797,7 @@ class fe {
795
797
  progress: 100
796
798
  });
797
799
  } catch (o) {
798
- s.signal.aborted || this.update(e.id, {
800
+ t.signal.aborted || this.update(e.id, {
799
801
  status: "error",
800
802
  progress: 0,
801
803
  error: o instanceof Error ? o.message : "Upload failed"
@@ -806,12 +808,12 @@ class fe {
806
808
  }
807
809
  }
808
810
  function q() {
809
- return N();
811
+ return K();
810
812
  }
811
- class ye {
813
+ class we {
812
814
  constructor({
813
815
  api: e,
814
- sessionCtx: s,
816
+ sessionCtx: t,
815
817
  messageCtx: o
816
818
  }) {
817
819
  this.submitCsat = async (r) => {
@@ -819,12 +821,12 @@ class ye {
819
821
  const _ = (c = this.sessionCtx.sessionState.get().session) == null ? void 0 : c.id;
820
822
  if (!_)
821
823
  return { data: null, error: "No session id found" };
822
- const t = q();
824
+ const s = q();
823
825
  this.messageCtx.state.setPartial({
824
826
  messages: [
825
827
  ...this.messageCtx.state.get().messages,
826
828
  {
827
- id: t,
829
+ id: s,
828
830
  type: "SYSTEM",
829
831
  subtype: "csat_submitted",
830
832
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
@@ -839,14 +841,14 @@ class ye {
839
841
  });
840
842
  const { data: a, error: n } = await this.api.submitCsat({
841
843
  ...r,
842
- system_message_uuid: t,
844
+ system_message_uuid: s,
843
845
  session_id: _
844
846
  });
845
847
  return { data: a, error: n };
846
- }, this.api = e, this.sessionCtx = s, this.messageCtx = o;
848
+ }, this.api = e, this.sessionCtx = t, this.messageCtx = o;
847
849
  }
848
850
  }
849
- const we = [
851
+ const je = [
850
852
  {
851
853
  action: "newparagraph",
852
854
  phrases: {
@@ -921,7 +923,7 @@ const we = [
921
923
  it: ["invia messaggio"]
922
924
  }
923
925
  }
924
- ], je = [
926
+ ], Se = [
925
927
  "en",
926
928
  "es",
927
929
  "fr",
@@ -929,25 +931,25 @@ const we = [
929
931
  "pt",
930
932
  "it"
931
933
  ];
932
- function Se(i) {
933
- return je.includes(i);
934
- }
935
934
  function ze(i) {
936
- return i.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
935
+ return Se.includes(i);
937
936
  }
938
937
  function Ce(i) {
939
- const e = we.flatMap(
938
+ return i.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
939
+ }
940
+ function xe(i) {
941
+ const e = je.flatMap(
940
942
  (r) => i.flatMap(
941
- (_) => r.phrases[_].map((t) => ({ phrase: t, action: r.action }))
943
+ (_) => r.phrases[_].map((s) => ({ phrase: s, action: r.action }))
942
944
  )
943
- ), s = e.map((r) => ze(r.phrase)).sort((r, _) => _.length - r.length).join("|"), o = String.raw`(?<=^\s{0,3}|[.!?\n]\s{0,3})`;
945
+ ), t = e.map((r) => Ce(r.phrase)).sort((r, _) => _.length - r.length).join("|"), o = String.raw`(?<=^\s{0,3}|[.!?\n]\s{0,3})`;
944
946
  return {
945
947
  regex: new RegExp(
946
- `${o}(${s})` + String.raw`([.,!?;:])(?=\s|$)`,
948
+ `${o}(${t})` + String.raw`([.,!?;:])(?=\s|$)`,
947
949
  "giu"
948
950
  ),
949
951
  finalRegex: new RegExp(
950
- `${o}(${s})` + String.raw`([.,!?;:]?)(?=\s|$)`,
952
+ `${o}(${t})` + String.raw`([.,!?;:]?)(?=\s|$)`,
951
953
  "giu"
952
954
  ),
953
955
  phraseToAction: new Map(
@@ -956,39 +958,39 @@ function Ce(i) {
956
958
  longestPhrase: Math.max(...e.map((r) => r.phrase.length))
957
959
  };
958
960
  }
959
- const H = /* @__PURE__ */ new Map();
960
- function D(i) {
961
- const e = i && Se(i) && i !== "en" ? i : null, s = e ?? "en";
962
- let o = H.get(s);
963
- return o || (o = Ce(e ? ["en", e] : ["en"]), H.set(s, o)), o;
961
+ const V = /* @__PURE__ */ new Map();
962
+ function R(i) {
963
+ const e = i && ze(i) && i !== "en" ? i : null, t = e ?? "en";
964
+ let o = V.get(t);
965
+ return o || (o = xe(e ? ["en", e] : ["en"]), V.set(t, o)), o;
964
966
  }
965
- function xe(i) {
967
+ function qe(i) {
966
968
  const e = i.replace(/\s+$/, "");
967
969
  if (!e) return "";
968
- const s = e.replace(/[.!?]+$/, "");
970
+ const t = e.replace(/[.!?]+$/, "");
969
971
  let o = -1;
970
- for (let r = s.length - 1; r >= 0; r--) {
971
- const _ = s[r];
972
+ for (let r = t.length - 1; r >= 0; r--) {
973
+ const _ = t[r];
972
974
  if (_ === "." || _ === "!" || _ === "?" || _ === `
973
975
  `) {
974
976
  o = r + 1;
975
977
  break;
976
978
  }
977
979
  }
978
- return o === -1 ? "" : `${s.slice(0, o)} `.replace(/\n $/, `
980
+ return o === -1 ? "" : `${t.slice(0, o)} `.replace(/\n $/, `
979
981
  `);
980
982
  }
981
- const qe = new RegExp(
983
+ const Ae = new RegExp(
982
984
  String.raw`(^- |\n(?:- )?)(\p{Ll})`,
983
985
  "gu"
984
986
  );
985
- function Ae(i) {
987
+ function Ee(i) {
986
988
  return i.replace(
987
- qe,
988
- (e, s, o) => s + o.toUpperCase()
989
+ Ae,
990
+ (e, t, o) => t + o.toUpperCase()
989
991
  );
990
992
  }
991
- function Ee(i) {
993
+ function Pe(i) {
992
994
  return i.length <= 3 && /^\s*$/.test(i) ? !0 : /[.!?\n]\s{0,3}$/.test(i.slice(-6));
993
995
  }
994
996
  class A {
@@ -997,10 +999,10 @@ class A {
997
999
  * Pure and deterministic: always called with the entire raw string so the
998
1000
  * result never depends on delta chunking.
999
1001
  */
1000
- static process(e, s) {
1001
- const o = D(s == null ? void 0 : s.language), r = s != null && s.final ? "" : A.commandPrefixTail(e, s == null ? void 0 : s.language), _ = e.slice(0, e.length - r.length), t = s != null && s.final ? o.finalRegex : o.regex;
1002
+ static process(e, t) {
1003
+ const o = R(t == null ? void 0 : t.language), r = t != null && t.final ? "" : A.commandPrefixTail(e, t == null ? void 0 : t.language), _ = e.slice(0, e.length - r.length), s = t != null && t.final ? o.finalRegex : o.regex;
1002
1004
  let a = "", n = null, c = 0;
1003
- for (const l of Array.from(_.matchAll(t))) {
1005
+ for (const l of Array.from(_.matchAll(s))) {
1004
1006
  const [, p = ""] = l, u = o.phraseToAction.get(p.toLowerCase());
1005
1007
  if (u)
1006
1008
  if (a += _.slice(c, l.index), c = l.index + l[0].length, u === "newline") a = `${a.replace(/[ \t]+$/, "")}
@@ -1014,13 +1016,13 @@ class A {
1014
1016
  a = m === "" || m.endsWith(`
1015
1017
  `) ? `${m}- ` : `${m}
1016
1018
  - `;
1017
- } else if (u === "scratch") a = xe(a);
1019
+ } else if (u === "scratch") a = qe(a);
1018
1020
  else {
1019
1021
  n = u === "send" ? "send" : "stop";
1020
1022
  break;
1021
1023
  }
1022
1024
  }
1023
- return n === null && (a += _.slice(c)), { text: Ae(
1025
+ return n === null && (a += _.slice(c)), { text: Ee(
1024
1026
  a.replace(/^\s+/, "").replace(/[ \t]+\n/g, `
1025
1027
  `).replace(/\n[ \t]+/g, `
1026
1028
  `).replace(/(^|\n)- +/g, "$1- ").replace(/ {2,}/g, " ").replace(/\n{3,}/g, `
@@ -1037,16 +1039,16 @@ class A {
1037
1039
  * control command from an intermediate delta would stop or submit
1038
1040
  * mid-sentence.
1039
1041
  */
1040
- static commandPrefixTail(e, s) {
1041
- const o = D(s), r = Math.min(e.length, o.longestPhrase + 2);
1042
+ static commandPrefixTail(e, t) {
1043
+ const o = R(t), r = Math.min(e.length, o.longestPhrase + 2);
1042
1044
  for (let _ = r; _ > 0; _--) {
1043
- const t = e.length - _;
1044
- if (!Ee(e.slice(0, t))) continue;
1045
- const a = e.slice(t).toLowerCase(), n = a.replace(/^\s+/, "");
1045
+ const s = e.length - _;
1046
+ if (!Pe(e.slice(0, s))) continue;
1047
+ const a = e.slice(s).toLowerCase(), n = a.replace(/^\s+/, "");
1046
1048
  if (n) {
1047
1049
  for (const c of Array.from(o.phraseToAction.keys()))
1048
1050
  if (c.startsWith(n))
1049
- return e.slice(t + (a.length - n.length));
1051
+ return e.slice(s + (a.length - n.length));
1050
1052
  }
1051
1053
  }
1052
1054
  return "";
@@ -1056,13 +1058,13 @@ class A {
1056
1058
  * prefix) — i.e. a silence pause would resolve it into a command. Used by
1057
1059
  * the manager's silence timer.
1058
1060
  */
1059
- static pendingTailIsCompletePhrase(e, s) {
1060
- const o = A.commandPrefixTail(e, s).trim().toLowerCase();
1061
- return o ? D(s).phraseToAction.has(o) : !1;
1061
+ static pendingTailIsCompletePhrase(e, t) {
1062
+ const o = A.commandPrefixTail(e, t).trim().toLowerCase();
1063
+ return o ? R(t).phraseToAction.has(o) : !1;
1062
1064
  }
1063
1065
  }
1064
- const Pe = 55, Te = 90;
1065
- class V {
1066
+ const Te = 55, Ie = 90;
1067
+ class G {
1066
1068
  /**
1067
1069
  * Next paced step toward `processed`: normally one word per tick so text
1068
1070
  * flows evenly instead of landing in bursty chunks; proportionally larger
@@ -1071,28 +1073,28 @@ class V {
1071
1073
  */
1072
1074
  static nextDripText({
1073
1075
  displayed: e,
1074
- processed: s
1076
+ processed: t
1075
1077
  }) {
1076
- if (s.length <= e.length) return s;
1077
- const o = s.length - e.length;
1078
- if (o > Te)
1079
- return s.slice(0, e.length + Math.ceil(o / 3));
1078
+ if (t.length <= e.length) return t;
1079
+ const o = t.length - e.length;
1080
+ if (o > Ie)
1081
+ return t.slice(0, e.length + Math.ceil(o / 3));
1080
1082
  let r = e.length;
1081
- for (; r < s.length && /\s/.test(s.charAt(r)); ) r++;
1082
- for (; r < s.length && !/\s/.test(s.charAt(r)); ) r++;
1083
- return r - e.length > 12 && (r = e.length + 6), s.slice(0, Math.max(r, e.length + 1));
1083
+ for (; r < t.length && /\s/.test(t.charAt(r)); ) r++;
1084
+ for (; r < t.length && !/\s/.test(t.charAt(r)); ) r++;
1085
+ return r - e.length > 12 && (r = e.length + 6), t.slice(0, Math.max(r, e.length + 1));
1084
1086
  }
1085
1087
  /** Normalize a BCP-47 browser locale into the hint OpenAI accepts. */
1086
1088
  static languageHint(e) {
1087
1089
  if (!e) return;
1088
- const s = e.toLowerCase();
1089
- if (/^zh-(cn|tw|hk)$/.test(s)) return s;
1090
- const o = s.split("-")[0];
1090
+ const t = e.toLowerCase();
1091
+ if (/^zh-(cn|tw|hk)$/.test(t)) return t;
1092
+ const o = t.split("-")[0];
1091
1093
  return o && /^[a-z]{2,3}$/.test(o) ? o : void 0;
1092
1094
  }
1093
1095
  }
1094
- const Ie = 2e4;
1095
- class Me {
1096
+ const Me = 2e4;
1097
+ class De {
1096
1098
  constructor() {
1097
1099
  this.cached = null, this.inflight = null;
1098
1100
  }
@@ -1100,15 +1102,15 @@ class Me {
1100
1102
  get() {
1101
1103
  if (!this.cached) return null;
1102
1104
  const e = Date.parse(this.cached.expiresAt);
1103
- return Number.isNaN(e) || e - Date.now() < Ie ? (this.cached = null, null) : this.cached;
1105
+ return Number.isNaN(e) || e - Date.now() < Me ? (this.cached = null, null) : this.cached;
1104
1106
  }
1105
1107
  /**
1106
1108
  * Resolve a mint, deduping concurrent requests (hover-prewarm racing a
1107
1109
  * click reuses the same in-flight promise instead of double-minting).
1108
1110
  */
1109
1111
  async resolve(e) {
1110
- const s = this.get();
1111
- return s || (this.inflight || (this.inflight = e().then((o) => (this.cached = o, o)).finally(() => {
1112
+ const t = this.get();
1113
+ return t || (this.inflight || (this.inflight = e().then((o) => (this.cached = o, o)).finally(() => {
1112
1114
  this.inflight = null;
1113
1115
  })), this.inflight);
1114
1116
  }
@@ -1117,60 +1119,60 @@ class Me {
1117
1119
  this.cached = null;
1118
1120
  }
1119
1121
  }
1120
- function G(i) {
1122
+ function Z(i) {
1121
1123
  return typeof i == "object" && i !== null && !Array.isArray(i);
1122
1124
  }
1123
- function De(i) {
1124
- if (!G(i) || typeof i.type != "string") return null;
1125
- const e = G(i.error) ? i.error : null;
1125
+ function Re(i) {
1126
+ if (!Z(i) || typeof i.type != "string") return null;
1127
+ const e = Z(i.error) ? i.error : null;
1126
1128
  return {
1127
1129
  type: i.type,
1128
1130
  delta: typeof i.delta == "string" ? i.delta : void 0,
1129
1131
  errorMessage: e && typeof e.message == "string" ? e.message : void 0
1130
1132
  };
1131
1133
  }
1132
- const Re = "https://api.openai.com/v1/realtime/calls", Ne = 600 * 1e3, Ke = 15e3, Le = 5e3;
1134
+ const Ne = "https://api.openai.com/v1/realtime/calls", Ke = 600 * 1e3, Le = 15e3, Oe = 5e3;
1133
1135
  class T extends Error {
1134
1136
  }
1135
- class Oe {
1137
+ class Fe {
1136
1138
  constructor({
1137
1139
  mintToken: e,
1138
- onDelta: s,
1140
+ onDelta: t,
1139
1141
  onState: o,
1140
1142
  onError: r,
1141
1143
  onLevel: _
1142
1144
  }) {
1143
- this.state = "idle", this.pc = null, this.dc = null, this.stream = null, this.audioContext = null, this.levelRaf = 0, this.timers = [], this.loggedParseFailure = !1, this.mintToken = e, this.onDelta = s, this.onState = o, this.onError = r, this.onLevel = _;
1145
+ this.state = "idle", this.pc = null, this.dc = null, this.stream = null, this.audioContext = null, this.levelRaf = 0, this.timers = [], this.loggedParseFailure = !1, this.mintToken = e, this.onDelta = t, this.onState = o, this.onError = r, this.onLevel = _;
1144
1146
  }
1145
1147
  async start() {
1146
1148
  if (this.state === "idle") {
1147
1149
  this.setState("connecting"), this.timers.push(
1148
1150
  setTimeout(() => {
1149
1151
  this.state === "connecting" && this.fail("unavailable");
1150
- }, Ke)
1151
- ), this.timers.push(setTimeout(() => this.stop(), Ne));
1152
+ }, Le)
1153
+ ), this.timers.push(setTimeout(() => this.stop(), Ke));
1152
1154
  try {
1153
1155
  const e = this.requestMicrophone();
1154
1156
  e.then((d) => {
1155
1157
  this.isTornDown() || this.stream && this.stream !== d ? d.getTracks().forEach((l) => l.stop()) : this.stream = d;
1156
1158
  }).catch(() => {
1157
1159
  });
1158
- const [s, o] = await Promise.all([e, this.mintToken()]);
1160
+ const [t, o] = await Promise.all([e, this.mintToken()]);
1159
1161
  if (this.isTornDown()) {
1160
- s.getTracks().forEach((d) => d.stop());
1162
+ t.getTracks().forEach((d) => d.stop());
1161
1163
  return;
1162
1164
  }
1163
- this.stream = s, this.startLevelMeter(s);
1165
+ this.stream = t, this.startLevelMeter(t);
1164
1166
  const r = new RTCPeerConnection();
1165
1167
  this.pc = r;
1166
- const [_] = s.getAudioTracks();
1168
+ const [_] = t.getAudioTracks();
1167
1169
  if (!_) throw new T("No audio track");
1168
- r.addTrack(_, s);
1169
- const t = r.createDataChannel("oai-events");
1170
- this.dc = t, t.addEventListener(
1170
+ r.addTrack(_, t);
1171
+ const s = r.createDataChannel("oai-events");
1172
+ this.dc = s, s.addEventListener(
1171
1173
  "message",
1172
1174
  (d) => this.handleServerEvent(d.data)
1173
- ), t.addEventListener("open", () => {
1175
+ ), s.addEventListener("open", () => {
1174
1176
  this.state === "connecting" && this.setState("listening");
1175
1177
  }), r.addEventListener("connectionstatechange", () => {
1176
1178
  if (r.connectionState === "failed") {
@@ -1180,12 +1182,12 @@ class Oe {
1180
1182
  r.connectionState === "disconnected" && this.timers.push(
1181
1183
  setTimeout(() => {
1182
1184
  this.pc === r && r.connectionState !== "connected" && this.fail("unavailable");
1183
- }, Le)
1185
+ }, Oe)
1184
1186
  );
1185
1187
  });
1186
1188
  const a = await r.createOffer();
1187
1189
  if (this.isTornDown() || (await r.setLocalDescription(a), this.isTornDown())) return;
1188
- const n = await fetch(Re, {
1190
+ const n = await fetch(Ne, {
1189
1191
  method: "POST",
1190
1192
  headers: {
1191
1193
  Authorization: `Bearer ${o.token}`,
@@ -1220,24 +1222,24 @@ class Oe {
1220
1222
  autoGainControl: !0
1221
1223
  }
1222
1224
  });
1223
- } catch (s) {
1225
+ } catch (t) {
1224
1226
  throw new T(
1225
- s instanceof DOMException ? s.name : "Could not access the microphone"
1227
+ t instanceof DOMException ? t.name : "Could not access the microphone"
1226
1228
  );
1227
1229
  }
1228
1230
  }
1229
1231
  handleServerEvent(e) {
1230
1232
  if (typeof e != "string") return;
1231
- let s;
1233
+ let t;
1232
1234
  try {
1233
- s = JSON.parse(e);
1235
+ t = JSON.parse(e);
1234
1236
  } catch {
1235
1237
  this.loggedParseFailure || (this.loggedParseFailure = !0, b.error("dictation server event was not valid JSON", {
1236
1238
  snippet: e.slice(0, 120)
1237
1239
  }));
1238
1240
  return;
1239
1241
  }
1240
- const o = De(s);
1242
+ const o = Re(t);
1241
1243
  if (!o) return;
1242
1244
  const { type: r, delta: _ } = o;
1243
1245
  if (r === "session.created" || r === "transcription_session.created") {
@@ -1255,11 +1257,11 @@ class Oe {
1255
1257
  startLevelMeter(e) {
1256
1258
  if (this.onLevel)
1257
1259
  try {
1258
- const s = new AudioContext();
1259
- this.audioContext = s;
1260
- const o = s.createMediaStreamSource(e), r = s.createAnalyser();
1260
+ const t = new AudioContext();
1261
+ this.audioContext = t;
1262
+ const o = t.createMediaStreamSource(e), r = t.createAnalyser();
1261
1263
  r.fftSize = 512, o.connect(r);
1262
- const _ = new Uint8Array(r.frequencyBinCount), t = () => {
1264
+ const _ = new Uint8Array(r.frequencyBinCount), s = () => {
1263
1265
  var c;
1264
1266
  r.getByteTimeDomainData(_);
1265
1267
  let a = 0;
@@ -1268,12 +1270,12 @@ class Oe {
1268
1270
  a += l * l;
1269
1271
  }
1270
1272
  const n = Math.sqrt(a / _.length);
1271
- (c = this.onLevel) == null || c.call(this, Math.min(1, n * 4)), this.levelRaf = requestAnimationFrame(t);
1273
+ (c = this.onLevel) == null || c.call(this, Math.min(1, n * 4)), this.levelRaf = requestAnimationFrame(s);
1272
1274
  };
1273
- this.levelRaf = requestAnimationFrame(t);
1274
- } catch (s) {
1275
+ this.levelRaf = requestAnimationFrame(s);
1276
+ } catch (t) {
1275
1277
  b.error("dictation level meter unavailable", {
1276
- _e: s instanceof Error ? s.message : String(s)
1278
+ _e: t instanceof Error ? t.message : String(t)
1277
1279
  });
1278
1280
  }
1279
1281
  }
@@ -1284,8 +1286,8 @@ class Oe {
1284
1286
  this.isTornDown() || (this.teardown(), this.setState("error"), this.onError(e));
1285
1287
  }
1286
1288
  teardown() {
1287
- var e, s, o, r;
1288
- this.timers.forEach((_) => clearTimeout(_)), this.timers = [], this.levelRaf && cancelAnimationFrame(this.levelRaf), this.levelRaf = 0, (e = this.dc) == null || e.close(), this.dc = null, (s = this.pc) == null || s.close(), this.pc = null, (o = this.stream) == null || o.getTracks().forEach((_) => _.stop()), this.stream = null, (r = this.audioContext) == null || r.close().catch((_) => {
1289
+ var e, t, o, r;
1290
+ this.timers.forEach((_) => clearTimeout(_)), this.timers = [], this.levelRaf && cancelAnimationFrame(this.levelRaf), this.levelRaf = 0, (e = this.dc) == null || e.close(), this.dc = null, (t = this.pc) == null || t.close(), this.pc = null, (o = this.stream) == null || o.getTracks().forEach((_) => _.stop()), this.stream = null, (r = this.audioContext) == null || r.close().catch((_) => {
1289
1291
  b.error("failed to close dictation audio context", {
1290
1292
  _e: String(_)
1291
1293
  });
@@ -1295,20 +1297,20 @@ class Oe {
1295
1297
  this.state !== e && (this.state = e, this.onState(e));
1296
1298
  }
1297
1299
  }
1298
- const Fe = 1300, Ue = { status: "idle", error: null };
1299
- class Be {
1300
- constructor({ api: e, config: s }) {
1301
- this.state = new z(Ue), this.levelRef = { current: 0 }, this.mintCache = new Me(), this.session = null, this.target = null, this.prefix = "", this.raw = "", this.processed = "", this.displayed = "", this.dripTimer = null, this.silenceTimer = null, this.isActive = () => this.session !== null, this.prewarm = () => {
1300
+ const Ue = 1300, Be = { status: "idle", error: null };
1301
+ class He {
1302
+ constructor({ api: e, config: t }) {
1303
+ this.state = new z(Be), this.levelRef = { current: 0 }, this.mintCache = new De(), this.session = null, this.target = null, this.prefix = "", this.raw = "", this.processed = "", this.displayed = "", this.dripTimer = null, this.silenceTimer = null, this.isActive = () => this.session !== null, this.prewarm = () => {
1302
1304
  this.mintToken().catch((o) => {
1303
1305
  this.mintCache.clear(), b.error("dictation token prewarm failed", {
1304
1306
  _e: o instanceof Error ? o.message : String(o)
1305
1307
  });
1306
1308
  });
1307
1309
  }, this.start = (o) => {
1308
- this.session && this.teardown(), this.target = o, this.language = V.languageHint(
1310
+ this.session && this.teardown(), this.target = o, this.language = G.languageHint(
1309
1311
  this.config.language ?? navigator.language
1310
1312
  ), this.prefix = o.getValue(), this.raw = "", this.processed = "", this.displayed = "";
1311
- const r = new Oe({
1313
+ const r = new Fe({
1312
1314
  mintToken: this.mintToken,
1313
1315
  onLevel: (_) => {
1314
1316
  this.levelRef.current = _;
@@ -1326,12 +1328,12 @@ class Be {
1326
1328
  return;
1327
1329
  }
1328
1330
  this.raw += _;
1329
- const t = this.ingest();
1330
- if (t === "stop") {
1331
+ const s = this.ingest();
1332
+ if (s === "stop") {
1331
1333
  this.teardown();
1332
1334
  return;
1333
1335
  }
1334
- if (t === "send") {
1336
+ if (s === "send") {
1335
1337
  this.teardown({ send: !0 });
1336
1338
  return;
1337
1339
  }
@@ -1343,7 +1345,7 @@ class Be {
1343
1345
  this.raw = `${this.raw}.`;
1344
1346
  const a = this.ingest();
1345
1347
  a === "stop" ? this.teardown() : a === "send" && this.teardown({ send: !0 });
1346
- }, Fe));
1348
+ }, Ue));
1347
1349
  }
1348
1350
  });
1349
1351
  this.session = r, this.state.set({ status: "connecting", error: null }), this.dripTimer = setInterval(() => {
@@ -1353,18 +1355,18 @@ class Be {
1353
1355
  return;
1354
1356
  }
1355
1357
  this.applyDisplayed(
1356
- V.nextDripText({
1358
+ G.nextDripText({
1357
1359
  displayed: this.displayed,
1358
1360
  processed: this.processed
1359
1361
  })
1360
1362
  );
1361
1363
  }
1362
- }, Pe), r.start();
1364
+ }, Te), r.start();
1363
1365
  }, this.stop = (o) => {
1364
1366
  this.session && this.teardown(o);
1365
1367
  }, this.mintToken = async () => this.mintCache.resolve(
1366
1368
  () => this.api.createDictationSession({ language: this.language })
1367
- ), this.api = e, this.config = s;
1369
+ ), this.api = e, this.config = t;
1368
1370
  }
1369
1371
  /** Applied text = prefix + dictated. A mismatch means the visitor edited. */
1370
1372
  isConsistent() {
@@ -1376,28 +1378,28 @@ class Be {
1376
1378
  /** Process the transcript and apply the outcome. Shared by the delta path,
1377
1379
  * the silence timer, and (with `final`) teardown. Returns the control. */
1378
1380
  ingest(e) {
1379
- const s = A.process(this.raw, {
1381
+ const t = A.process(this.raw, {
1380
1382
  language: this.language,
1381
1383
  final: e == null ? void 0 : e.final
1382
1384
  });
1383
- return this.processed = s.text, s.text.startsWith(this.displayed) || this.applyDisplayed(s.text), s.control;
1385
+ return this.processed = t.text, t.text.startsWith(this.displayed) || this.applyDisplayed(t.text), t.control;
1384
1386
  }
1385
1387
  stopSilenceTimer() {
1386
1388
  this.silenceTimer && clearTimeout(this.silenceTimer), this.silenceTimer = null;
1387
1389
  }
1388
1390
  teardown(e) {
1389
1391
  var _;
1390
- const s = this.session, o = this.target;
1392
+ const t = this.session, o = this.target;
1391
1393
  this.dripTimer && clearInterval(this.dripTimer), this.dripTimer = null, this.stopSilenceTimer();
1392
1394
  let r = (e == null ? void 0 : e.send) ?? !1;
1393
1395
  if (o && this.isConsistent()) {
1394
- const t = this.ingest({ final: !0 });
1395
- (e == null ? void 0 : e.executeFinalCommand) !== !1 && t === "send" && (r = !0), this.processed !== this.displayed && this.applyDisplayed(this.processed);
1396
+ const s = this.ingest({ final: !0 });
1397
+ (e == null ? void 0 : e.executeFinalCommand) !== !1 && s === "send" && (r = !0), this.processed !== this.displayed && this.applyDisplayed(this.processed);
1396
1398
  }
1397
- this.session = null, this.target = null, s == null || s.stop(), this.levelRef.current = 0, this.state.set({ status: "idle", error: (e == null ? void 0 : e.error) ?? null }), r && ((_ = o == null ? void 0 : o.onSend) == null || _.call(o));
1399
+ this.session = null, this.target = null, t == null || t.stop(), this.levelRef.current = 0, this.state.set({ status: "idle", error: (e == null ? void 0 : e.error) ?? null }), r && ((_ = o == null ? void 0 : o.onSend) == null || _.call(o));
1398
1400
  }
1399
1401
  }
1400
- const He = {
1402
+ const Ve = {
1401
1403
  write_a_message_placeholder: "اكتب رسالة...",
1402
1404
  your_issue_has_been_resolved: "تم حل مشكلتك!",
1403
1405
  new_conversation: "محادثة جديدة",
@@ -1507,7 +1509,7 @@ const He = {
1507
1509
  zoom_out: "تصغير",
1508
1510
  reset_zoom: "إعادة تعيين التكبير",
1509
1511
  support_chat_aria_label: "دردشة الدعم"
1510
- }, Ve = {
1512
+ }, Ge = {
1511
1513
  write_a_message_placeholder: "একটি বার্তা লিখুন...",
1512
1514
  your_issue_has_been_resolved: "আপনার সমস্যা সমাধান হয়েছে!",
1513
1515
  new_conversation: "নতুন কথোপকথন",
@@ -1604,7 +1606,7 @@ const He = {
1604
1606
  zoom_out: "ছোট করুন",
1605
1607
  reset_zoom: "জুম রিসেট করুন",
1606
1608
  support_chat_aria_label: "সাপোর্ট চ্যাট"
1607
- }, Ge = {
1609
+ }, Ze = {
1608
1610
  write_a_message_placeholder: "Напишете съобщение...",
1609
1611
  your_issue_has_been_resolved: "Вашият проблем е разрешен!",
1610
1612
  new_conversation: "Нов разговор",
@@ -1701,7 +1703,7 @@ const He = {
1701
1703
  zoom_out: "Намаляване",
1702
1704
  reset_zoom: "Нулиране на мащаба",
1703
1705
  support_chat_aria_label: "Чат за поддръжка"
1704
- }, Ze = {
1706
+ }, We = {
1705
1707
  write_a_message_placeholder: "Napište zprávu...",
1706
1708
  your_issue_has_been_resolved: "Váš problém byl vyřešen!",
1707
1709
  new_conversation: "Nová konverzace",
@@ -1798,7 +1800,7 @@ const He = {
1798
1800
  zoom_out: "Oddálit",
1799
1801
  reset_zoom: "Obnovit přiblížení",
1800
1802
  support_chat_aria_label: "Chat podpory"
1801
- }, We = {
1803
+ }, $e = {
1802
1804
  write_a_message_placeholder: "Skriv en besked...",
1803
1805
  your_issue_has_been_resolved: "Dit problem er løst!",
1804
1806
  new_conversation: "Ny samtale",
@@ -1895,7 +1897,7 @@ const He = {
1895
1897
  zoom_out: "Zoom ud",
1896
1898
  reset_zoom: "Nulstil zoom",
1897
1899
  support_chat_aria_label: "Supportchat"
1898
- }, $e = {
1900
+ }, Je = {
1899
1901
  write_a_message_placeholder: "Γράψτε ένα μήνυμα...",
1900
1902
  your_issue_has_been_resolved: "Το πρόβλημά σας επιλύθηκε!",
1901
1903
  new_conversation: "Νέα συνομιλία",
@@ -1992,7 +1994,7 @@ const He = {
1992
1994
  zoom_out: "Σμίκρυνση",
1993
1995
  reset_zoom: "Επαναφορά ζουμ",
1994
1996
  support_chat_aria_label: "Συνομιλία υποστήριξης"
1995
- }, Je = {
1997
+ }, Ye = {
1996
1998
  write_a_message_placeholder: "Nachricht schreiben...",
1997
1999
  your_issue_has_been_resolved: "Ihr Problem wurde gelöst!",
1998
2000
  new_conversation: "Neue Konversation",
@@ -2089,7 +2091,7 @@ const He = {
2089
2091
  zoom_out: "Verkleinern",
2090
2092
  reset_zoom: "Zoom zurücksetzen",
2091
2093
  support_chat_aria_label: "Support-Chat"
2092
- }, Y = {
2094
+ }, Q = {
2093
2095
  write_a_message_placeholder: "Write a message...",
2094
2096
  your_issue_has_been_resolved: "Your issue has been resolved!",
2095
2097
  new_conversation: "New conversation",
@@ -2199,7 +2201,7 @@ const He = {
2199
2201
  zoom_out: "Zoom out",
2200
2202
  reset_zoom: "Reset zoom",
2201
2203
  support_chat_aria_label: "Support chat"
2202
- }, Ye = {
2204
+ }, Qe = {
2203
2205
  write_a_message_placeholder: "Escribe un mensaje...",
2204
2206
  your_issue_has_been_resolved: "¡Tu problema fue resuelto!",
2205
2207
  new_conversation: "Nueva conversación",
@@ -2296,7 +2298,7 @@ const He = {
2296
2298
  zoom_out: "Alejar",
2297
2299
  reset_zoom: "Restablecer zoom",
2298
2300
  support_chat_aria_label: "Chat de soporte"
2299
- }, Qe = {
2301
+ }, Xe = {
2300
2302
  write_a_message_placeholder: "Magsulat ng mensahe...",
2301
2303
  your_issue_has_been_resolved: "Nalutas na ang iyong isyu!",
2302
2304
  new_conversation: "Bagong usapan",
@@ -2393,7 +2395,7 @@ const He = {
2393
2395
  zoom_out: "Paliitin",
2394
2396
  reset_zoom: "I-reset ang zoom",
2395
2397
  support_chat_aria_label: "Chat ng suporta"
2396
- }, Xe = {
2398
+ }, ea = {
2397
2399
  write_a_message_placeholder: "Kirjoita viesti...",
2398
2400
  your_issue_has_been_resolved: "Ongelmasi on ratkaistu!",
2399
2401
  new_conversation: "Uusi keskustelu",
@@ -2490,7 +2492,7 @@ const He = {
2490
2492
  zoom_out: "Loitonna",
2491
2493
  reset_zoom: "Palauta zoomaus",
2492
2494
  support_chat_aria_label: "Tukichat"
2493
- }, ea = {
2495
+ }, aa = {
2494
2496
  write_a_message_placeholder: "Écrivez un message...",
2495
2497
  your_issue_has_been_resolved: "Votre problème a été résolu !",
2496
2498
  new_conversation: "Nouvelle conversation",
@@ -2587,7 +2589,7 @@ const He = {
2587
2589
  zoom_out: "Zoom arrière",
2588
2590
  reset_zoom: "Réinitialiser le zoom",
2589
2591
  support_chat_aria_label: "Chat de support"
2590
- }, aa = {
2592
+ }, ta = {
2591
2593
  write_a_message_placeholder: "एक संदेश लिखें...",
2592
2594
  your_issue_has_been_resolved: "आपकी समस्या हल हो गई है!",
2593
2595
  new_conversation: "नई बातचीत",
@@ -2684,7 +2686,7 @@ const He = {
2684
2686
  zoom_out: "ज़ूम आउट",
2685
2687
  reset_zoom: "ज़ूम रीसेट करें",
2686
2688
  support_chat_aria_label: "सहायता चैट"
2687
- }, ta = {
2689
+ }, sa = {
2688
2690
  write_a_message_placeholder: "Scrivi un messaggio...",
2689
2691
  your_issue_has_been_resolved: "Il tuo problema è stato risolto!",
2690
2692
  new_conversation: "Nuova conversazione",
@@ -2781,7 +2783,7 @@ const He = {
2781
2783
  zoom_out: "Riduci",
2782
2784
  reset_zoom: "Reimposta zoom",
2783
2785
  support_chat_aria_label: "Chat di supporto"
2784
- }, sa = {
2786
+ }, oa = {
2785
2787
  write_a_message_placeholder: "メッセージを入力...",
2786
2788
  your_issue_has_been_resolved: "問題が解決しました!",
2787
2789
  new_conversation: "新しい会話",
@@ -2878,7 +2880,7 @@ const He = {
2878
2880
  zoom_out: "縮小",
2879
2881
  reset_zoom: "ズームをリセット",
2880
2882
  support_chat_aria_label: "サポートチャット"
2881
- }, oa = {
2883
+ }, na = {
2882
2884
  write_a_message_placeholder: "메시지를 입력하세요...",
2883
2885
  your_issue_has_been_resolved: "문제가 해결되었습니다!",
2884
2886
  new_conversation: "새 대화",
@@ -2975,7 +2977,7 @@ const He = {
2975
2977
  zoom_out: "축소",
2976
2978
  reset_zoom: "확대/축소 초기화",
2977
2979
  support_chat_aria_label: "고객 지원 채팅"
2978
- }, na = {
2980
+ }, ia = {
2979
2981
  write_a_message_placeholder: "Schrijf een bericht...",
2980
2982
  your_issue_has_been_resolved: "Uw probleem is opgelost!",
2981
2983
  new_conversation: "Nieuw gesprek",
@@ -3072,7 +3074,7 @@ const He = {
3072
3074
  zoom_out: "Uitzoomen",
3073
3075
  reset_zoom: "Zoom herstellen",
3074
3076
  support_chat_aria_label: "Supportchat"
3075
- }, ia = {
3077
+ }, ra = {
3076
3078
  write_a_message_placeholder: "Skriv en melding...",
3077
3079
  your_issue_has_been_resolved: "Problemet ditt er løst!",
3078
3080
  new_conversation: "Ny samtale",
@@ -3169,7 +3171,7 @@ const He = {
3169
3171
  zoom_out: "Zoom ut",
3170
3172
  reset_zoom: "Tilbakestill zoom",
3171
3173
  support_chat_aria_label: "Support-chat"
3172
- }, ra = {
3174
+ }, _a = {
3173
3175
  write_a_message_placeholder: "Napisz wiadomość...",
3174
3176
  your_issue_has_been_resolved: "Twój problem został rozwiązany!",
3175
3177
  new_conversation: "Nowa rozmowa",
@@ -3266,7 +3268,7 @@ const He = {
3266
3268
  zoom_out: "Pomniejsz",
3267
3269
  reset_zoom: "Resetuj powiększenie",
3268
3270
  support_chat_aria_label: "Czat pomocy"
3269
- }, _a = {
3271
+ }, la = {
3270
3272
  write_a_message_placeholder: "Escreva uma mensagem...",
3271
3273
  your_issue_has_been_resolved: "Seu problema foi resolvido!",
3272
3274
  new_conversation: "Nova conversa",
@@ -3363,7 +3365,7 @@ const He = {
3363
3365
  zoom_out: "Reduzir",
3364
3366
  reset_zoom: "Redefinir zoom",
3365
3367
  support_chat_aria_label: "Chat de suporte"
3366
- }, la = {
3368
+ }, ca = {
3367
3369
  write_a_message_placeholder: "Scrie un mesaj...",
3368
3370
  your_issue_has_been_resolved: "Problema ta a fost rezolvată!",
3369
3371
  new_conversation: "Conversație nouă",
@@ -3460,7 +3462,7 @@ const He = {
3460
3462
  zoom_out: "Micșorează",
3461
3463
  reset_zoom: "Resetează zoomul",
3462
3464
  support_chat_aria_label: "Chat de asistență"
3463
- }, ca = {
3465
+ }, pa = {
3464
3466
  write_a_message_placeholder: "Skriv ett meddelande...",
3465
3467
  your_issue_has_been_resolved: "Ditt problem har lösts!",
3466
3468
  new_conversation: "Ny konversation",
@@ -3557,7 +3559,7 @@ const He = {
3557
3559
  zoom_out: "Zooma ut",
3558
3560
  reset_zoom: "Återställ zoom",
3559
3561
  support_chat_aria_label: "Supportchatt"
3560
- }, pa = {
3562
+ }, da = {
3561
3563
  write_a_message_placeholder: "Напишите сообщение...",
3562
3564
  your_issue_has_been_resolved: "Ваша проблема решена!",
3563
3565
  new_conversation: "Новый разговор",
@@ -3654,7 +3656,7 @@ const He = {
3654
3656
  zoom_out: "Уменьшить",
3655
3657
  reset_zoom: "Сбросить масштаб",
3656
3658
  support_chat_aria_label: "Чат поддержки"
3657
- }, da = {
3659
+ }, ua = {
3658
3660
  write_a_message_placeholder: "เขียนข้อความ...",
3659
3661
  your_issue_has_been_resolved: "ปัญหาของคุณได้รับการแก้ไขแล้ว!",
3660
3662
  new_conversation: "การสนทนาใหม่",
@@ -3751,7 +3753,7 @@ const He = {
3751
3753
  zoom_out: "ย่อ",
3752
3754
  reset_zoom: "รีเซ็ตการซูม",
3753
3755
  support_chat_aria_label: "แชทฝ่ายสนับสนุน"
3754
- }, ua = {
3756
+ }, ma = {
3755
3757
  write_a_message_placeholder: "Bir mesaj yazın...",
3756
3758
  your_issue_has_been_resolved: "Sorununuz çözüldü!",
3757
3759
  new_conversation: "Yeni konuşma",
@@ -3848,7 +3850,7 @@ const He = {
3848
3850
  zoom_out: "Uzaklaştır",
3849
3851
  reset_zoom: "Yakınlaştırmayı sıfırla",
3850
3852
  support_chat_aria_label: "Destek sohbeti"
3851
- }, ma = {
3853
+ }, ha = {
3852
3854
  write_a_message_placeholder: "پیغام لکھیں...",
3853
3855
  your_issue_has_been_resolved: "آپ کا مسئلہ حل ہو گیا ہے!",
3854
3856
  new_conversation: "نئی گفتگو",
@@ -3945,7 +3947,7 @@ const He = {
3945
3947
  zoom_out: "زوم آؤٹ",
3946
3948
  reset_zoom: "زوم دوبارہ ترتیب دیں",
3947
3949
  support_chat_aria_label: "سپورٹ چیٹ"
3948
- }, ha = {
3950
+ }, ga = {
3949
3951
  write_a_message_placeholder: "Viết tin nhắn...",
3950
3952
  your_issue_has_been_resolved: "Vấn đề của bạn đã được giải quyết!",
3951
3953
  new_conversation: "Cuộc trò chuyện mới",
@@ -4042,7 +4044,7 @@ const He = {
4042
4044
  zoom_out: "Thu nhỏ",
4043
4045
  reset_zoom: "Đặt lại thu phóng",
4044
4046
  support_chat_aria_label: "Trò chuyện hỗ trợ"
4045
- }, ga = {
4047
+ }, ka = {
4046
4048
  write_a_message_placeholder: "写一条消息...",
4047
4049
  your_issue_has_been_resolved: "您的问题已解决!",
4048
4050
  new_conversation: "新对话",
@@ -4139,7 +4141,7 @@ const He = {
4139
4141
  zoom_out: "缩小",
4140
4142
  reset_zoom: "重置缩放",
4141
4143
  support_chat_aria_label: "支持对话"
4142
- }, ka = {
4144
+ }, ba = {
4143
4145
  write_a_message_placeholder: "Napišite poruku...",
4144
4146
  your_issue_has_been_resolved: "Vaš problem je riješen!",
4145
4147
  new_conversation: "Novi razgovor",
@@ -4236,7 +4238,7 @@ const He = {
4236
4238
  zoom_out: "Udalji",
4237
4239
  reset_zoom: "Poništi zumiranje",
4238
4240
  support_chat_aria_label: "Chat za podršku"
4239
- }, ba = {
4241
+ }, fa = {
4240
4242
  write_a_message_placeholder: "Kirjuta sõnum...",
4241
4243
  your_issue_has_been_resolved: "Teie probleem on lahendatud!",
4242
4244
  new_conversation: "Uus vestlus",
@@ -4430,7 +4432,7 @@ const He = {
4430
4432
  zoom_out: "Kicsinyítés",
4431
4433
  reset_zoom: "Nagyítás visszaállítása",
4432
4434
  support_chat_aria_label: "Ügyfélszolgálati chat"
4433
- }, fa = {
4435
+ }, ya = {
4434
4436
  write_a_message_placeholder: "Skrifaðu skilaboð...",
4435
4437
  your_issue_has_been_resolved: "Málið þitt hefur verið leyst!",
4436
4438
  new_conversation: "Nýtt samtal",
@@ -4527,7 +4529,7 @@ const He = {
4527
4529
  zoom_out: "Minnka aðdrátt",
4528
4530
  reset_zoom: "Endurstilla aðdrátt",
4529
4531
  support_chat_aria_label: "Þjónustuspjall"
4530
- }, ya = {
4532
+ }, wa = {
4531
4533
  write_a_message_placeholder: "Rakstiet ziņojumu...",
4532
4534
  your_issue_has_been_resolved: "Jūsu problēma ir atrisināta!",
4533
4535
  new_conversation: "Jauna saruna",
@@ -4624,7 +4626,7 @@ const He = {
4624
4626
  zoom_out: "Attālināt",
4625
4627
  reset_zoom: "Atiestatīt tālummaiņu",
4626
4628
  support_chat_aria_label: "Atbalsta tērzēšana"
4627
- }, wa = {
4629
+ }, ja = {
4628
4630
  write_a_message_placeholder: "Parašykite žinutę...",
4629
4631
  your_issue_has_been_resolved: "Jūsų problema išspręsta!",
4630
4632
  new_conversation: "Naujas pokalbis",
@@ -4721,7 +4723,7 @@ const He = {
4721
4723
  zoom_out: "Nutolinti",
4722
4724
  reset_zoom: "Atstatyti mastelį",
4723
4725
  support_chat_aria_label: "Pagalbos pokalbis"
4724
- }, ja = {
4726
+ }, Sa = {
4725
4727
  write_a_message_placeholder: "Schreift eng Noriicht...",
4726
4728
  your_issue_has_been_resolved: "Äert Problem gouf geléist!",
4727
4729
  new_conversation: "Nei Konversatioun",
@@ -4818,7 +4820,7 @@ const He = {
4818
4820
  zoom_out: "Erauszoomen",
4819
4821
  reset_zoom: "Zoom zrécksetzen",
4820
4822
  support_chat_aria_label: "Support-Chat"
4821
- }, Sa = {
4823
+ }, za = {
4822
4824
  write_a_message_placeholder: "Ikteb messaġġ...",
4823
4825
  your_issue_has_been_resolved: "Il-problema tiegħek ġiet riżolta!",
4824
4826
  new_conversation: "Konversazzjoni ġdida",
@@ -4915,7 +4917,7 @@ const He = {
4915
4917
  zoom_out: "Ċekken",
4916
4918
  reset_zoom: "Irrisettja ż-zoom",
4917
4919
  support_chat_aria_label: "Chat ta’ appoġġ"
4918
- }, za = {
4920
+ }, Ca = {
4919
4921
  write_a_message_placeholder: "Skriv en melding...",
4920
4922
  your_issue_has_been_resolved: "Saken din er løst!",
4921
4923
  new_conversation: "Ny samtale",
@@ -5012,7 +5014,7 @@ const He = {
5012
5014
  zoom_out: "Zoom ut",
5013
5015
  reset_zoom: "Tilbakestill zoom",
5014
5016
  support_chat_aria_label: "Support-chat"
5015
- }, Ca = {
5017
+ }, xa = {
5016
5018
  write_a_message_placeholder: "Napíšte správu...",
5017
5019
  your_issue_has_been_resolved: "Váš problém bol vyriešený!",
5018
5020
  new_conversation: "Nová konverzácia",
@@ -5109,82 +5111,98 @@ const He = {
5109
5111
  zoom_out: "Oddialiť",
5110
5112
  reset_zoom: "Obnoviť priblíženie",
5111
5113
  support_chat_aria_label: "Chat podpory"
5112
- }, Q = {
5113
- ar: He,
5114
- bn: Ve,
5115
- bg: Ge,
5116
- cs: Ze,
5117
- da: We,
5118
- de: Je,
5119
- el: $e,
5120
- en: Y,
5121
- es: Ye,
5122
- et: ba,
5123
- fi: Xe,
5124
- fil: Qe,
5125
- fr: ea,
5126
- hi: aa,
5127
- hr: ka,
5114
+ }, X = {
5115
+ ar: Ve,
5116
+ bn: Ge,
5117
+ bg: Ze,
5118
+ cs: We,
5119
+ da: $e,
5120
+ de: Ye,
5121
+ el: Je,
5122
+ en: Q,
5123
+ es: Qe,
5124
+ et: fa,
5125
+ fi: ea,
5126
+ fil: Xe,
5127
+ fr: aa,
5128
+ hi: ta,
5129
+ hr: ba,
5128
5130
  hu: va,
5129
- is: fa,
5130
- it: ta,
5131
- ja: sa,
5132
- ko: oa,
5133
- lb: ja,
5134
- lt: wa,
5135
- lv: ya,
5136
- mt: Sa,
5137
- nb: za,
5138
- nl: na,
5139
- no: ia,
5140
- pl: ra,
5141
- pt: _a,
5142
- ro: la,
5143
- ru: pa,
5144
- sk: Ca,
5145
- sv: ca,
5146
- th: da,
5147
- tr: ua,
5148
- ur: ma,
5149
- vi: ha,
5150
- "zh-cn": ga
5151
- }, xa = Object.keys(Q);
5152
- function qa(i) {
5153
- return xa.includes(i);
5131
+ is: ya,
5132
+ it: sa,
5133
+ ja: oa,
5134
+ ko: na,
5135
+ lb: Sa,
5136
+ lt: ja,
5137
+ lv: wa,
5138
+ mt: za,
5139
+ nb: Ca,
5140
+ nl: ia,
5141
+ no: ra,
5142
+ pl: _a,
5143
+ pt: la,
5144
+ ro: ca,
5145
+ ru: da,
5146
+ sk: xa,
5147
+ sv: pa,
5148
+ th: ua,
5149
+ tr: ma,
5150
+ ur: ha,
5151
+ vi: ga,
5152
+ "zh-cn": ka
5153
+ }, qa = Object.keys(X);
5154
+ function Aa(i) {
5155
+ return qa.includes(i);
5154
5156
  }
5155
- const Aa = /* @__PURE__ */ new Set(["ar", "ur"]);
5156
- function Xa(i) {
5157
- return Aa.has(i);
5157
+ const Ea = /* @__PURE__ */ new Set(["ar", "ur"]);
5158
+ function at(i) {
5159
+ return Ea.has(i);
5158
5160
  }
5159
- function Ea(i) {
5160
- return qa(i) ? i : "en";
5161
+ function Pa(i) {
5162
+ return Aa(i) ? i : "en";
5161
5163
  }
5162
- function Pa(i, e, s, o) {
5164
+ function Ta(i, e, t, o) {
5163
5165
  var _;
5164
- const r = ((_ = s == null ? void 0 : s[e]) == null ? void 0 : _[i]) || Q[e][i] || Y[i] || i;
5166
+ const r = ((_ = t == null ? void 0 : t[e]) == null ? void 0 : _[i]) || X[e][i] || Q[i] || i;
5165
5167
  return o ? r.replace(
5166
5168
  /\{(\w+)\}/g,
5167
- (t, a) => a in o ? String(o[a]) : t
5169
+ (s, a) => a in o ? String(o[a]) : s
5168
5170
  ) : r;
5169
5171
  }
5170
- function Ta(i, e, s) {
5171
- return Pa(
5172
+ function Ia(i, e, t) {
5173
+ return Ta(
5172
5174
  e,
5173
- Ea(i.language),
5175
+ Pa(i.language),
5174
5176
  i.translationOverrides,
5175
- s
5177
+ t
5176
5178
  );
5177
5179
  }
5178
- class Ia {
5180
+ function I(i) {
5181
+ return i.type === "AGENT" || i.type === "AI";
5182
+ }
5183
+ function Ma(i, e) {
5184
+ var o;
5185
+ if ((e == null ? void 0 : e.isOpened) === !1) return null;
5186
+ const t = i.findLast(
5187
+ (r) => I(r) && !!r.messageOptions
5188
+ );
5189
+ return ((o = t == null ? void 0 : t.messageOptions) == null ? void 0 : o.pickedOptionId) === null ? t : null;
5190
+ }
5191
+ function tt(i, e) {
5192
+ var o, r;
5193
+ const t = Ma(i, e);
5194
+ return ((o = t == null ? void 0 : t.messageOptions) == null ? void 0 : o.requireTap) !== !0 ? !1 : ((r = i.findLast(I)) == null ? void 0 : r.id) === t.id;
5195
+ }
5196
+ class Da {
5179
5197
  constructor({
5180
5198
  config: e,
5181
- api: s,
5199
+ api: t,
5182
5200
  contactCtx: o,
5183
5201
  storageCtx: r,
5184
5202
  sessionsPollingIntervalSeconds: _,
5185
- sharedSessions: t
5203
+ sharedSessions: s
5186
5204
  }) {
5187
- this.sessionsRefresher = new $(), this.persistedSessionId = null, this.sessionAbortController = new AbortController(), this.sessionState = new z({
5205
+ this.sessionsRefresher = new J(), this.persistedSessionId = null, this.sessionAbortController = new AbortController(), this.sessionState = new z({
5188
5206
  session: null,
5189
5207
  isCreatingSession: !1,
5190
5208
  isResolvingSession: !1
@@ -5252,7 +5270,7 @@ class Ia {
5252
5270
  Object.entries(this.config.sessionCustomData || {}).map(
5253
5271
  ([a, n]) => {
5254
5272
  var c;
5255
- return typeof n == "string" ? [a, n] : typeof n == "boolean" ? [a, n] : typeof n == "number" ? [a, n] : [a, ((c = J(() => JSON.stringify(n))) == null ? void 0 : c.data) || ""];
5273
+ return typeof n == "string" ? [a, n] : typeof n == "boolean" ? [a, n] : typeof n == "number" ? [a, n] : [a, ((c = Y(() => JSON.stringify(n))) == null ? void 0 : c.data) || ""];
5256
5274
  }
5257
5275
  )
5258
5276
  ), this.createSession = async () => {
@@ -5293,8 +5311,8 @@ class Ia {
5293
5311
  this.sessionState.setPartial({ session: d }), this.setSessions([d]);
5294
5312
  try {
5295
5313
  (g = (m = this.config.hooks) == null ? void 0 : m.onSessionCreated) == null || g.call(m, { session: d });
5296
- } catch (v) {
5297
- b.error("onSessionCreated hook failed", v);
5314
+ } catch (f) {
5315
+ b.error("onSessionCreated hook failed", f);
5298
5316
  }
5299
5317
  return { session: d, status: p.status, error: void 0 };
5300
5318
  }, this.loadMoreSessions = async () => {
@@ -5352,14 +5370,14 @@ class Ia {
5352
5370
  payload: a
5353
5371
  });
5354
5372
  return c != null && c.success ? { success: !0 } : { success: !1 };
5355
- }, this.config = e, this.api = s, this.contactCtx = o, this.storageCtx = r, this.sessionsPollingIntervalSeconds = _, t ? this.sessionsState = t : this.registerSessionsRefresherWrapper(), this.registerActiveSessionPersistence();
5373
+ }, this.config = e, this.api = t, this.contactCtx = o, this.storageCtx = r, this.sessionsPollingIntervalSeconds = _, s ? this.sessionsState = s : this.registerSessionsRefresherWrapper(), this.registerActiveSessionPersistence();
5356
5374
  }
5357
5375
  }
5358
- const Ma = (i, e, { sendsPageContext: s }) => {
5359
- const o = Na(i), r = s && e.mentions && e.mentions.length > 0 ? { mentions: e.mentions.map(Da) } : void 0, _ = s && (e.clientContext || r) ? { ...o, ...e.clientContext, ...r } : o, t = e.connectionRequestId ? {
5376
+ const Ra = (i, e, { sendsPageContext: t }) => {
5377
+ const o = La(i), r = t && e.mentions && e.mentions.length > 0 ? { mentions: e.mentions.map(Na) } : void 0, _ = t && (e.clientContext || r) ? { ...o, ...e.clientContext, ...r } : o, s = e.connectionRequestId ? {
5360
5378
  ..._,
5361
5379
  opencx__connection_request_id: e.connectionRequestId
5362
- } : _, a = e.withPageEntity === !1 && t && "entity" in t ? Ra(t, "entity") : t;
5380
+ } : _, a = e.withPageEntity === !1 && s && "entity" in s ? Ka(s, "entity") : s;
5363
5381
  return {
5364
5382
  clientContext: e.background ? { ...a, opencx__background: !0 } : a,
5365
5383
  custom_data: {
@@ -5367,15 +5385,15 @@ const Ma = (i, e, { sendsPageContext: s }) => {
5367
5385
  ...e.customData || {}
5368
5386
  }
5369
5387
  };
5370
- }, Da = ({ type: i, id: e, title: s, meta: o }) => ({
5388
+ }, Na = ({ type: i, id: e, title: t, meta: o }) => ({
5371
5389
  type: i,
5372
5390
  id: e,
5373
- title: s,
5391
+ title: t,
5374
5392
  ...o ? { meta: o } : {}
5375
- }), Ra = (i, e) => {
5376
- const { [e]: s, ...o } = i;
5393
+ }), Ka = (i, e) => {
5394
+ const { [e]: t, ...o } = i;
5377
5395
  return Object.keys(o).length > 0 ? o : void 0;
5378
- }, Na = (i) => {
5396
+ }, La = (i) => {
5379
5397
  if (typeof i.context != "function") return i.context;
5380
5398
  try {
5381
5399
  return i.context();
@@ -5383,25 +5401,25 @@ const Ma = (i, e, { sendsPageContext: s }) => {
5383
5401
  b.error("context getter threw; sending without context", e);
5384
5402
  return;
5385
5403
  }
5386
- }, Ka = (i) => {
5387
- const e = i.features, s = {
5404
+ }, Oa = (i) => {
5405
+ const e = i.features, t = {
5388
5406
  page_context: (e == null ? void 0 : e.pageContext) === !0,
5389
5407
  client_tools: (e == null ? void 0 : e.pageContext) === !0 && (e == null ? void 0 : e.clientTools) === !0,
5390
5408
  page_actions: (e == null ? void 0 : e.pageContext) === !0 && (e == null ? void 0 : e.clientTools) === !0 && (e == null ? void 0 : e.pageActions) === !0
5391
5409
  };
5392
- return e && (e.preamble !== void 0 && (s.preamble = e.preamble), e.inlineUi !== void 0 && (s.inline_ui = e.inlineUi)), s;
5393
- }, La = ({
5410
+ return e && (e.preamble !== void 0 && (t.preamble = e.preamble), e.inlineUi !== void 0 && (t.inline_ui = e.inlineUi)), t;
5411
+ }, Fa = ({
5394
5412
  config: i,
5395
5413
  input: e,
5396
- uuid: s,
5414
+ uuid: t,
5397
5415
  sessionId: o,
5398
5416
  content: r,
5399
5417
  initialMessages: _,
5400
- sendsPageContext: t
5418
+ sendsPageContext: s
5401
5419
  }) => {
5402
5420
  var a, n, c, d;
5403
5421
  return {
5404
- uuid: s,
5422
+ uuid: t,
5405
5423
  bot_token: i.token,
5406
5424
  headers: i.headers,
5407
5425
  query_params: i.queryParams,
@@ -5409,9 +5427,9 @@ const Ma = (i, e, { sendsPageContext: s }) => {
5409
5427
  session_id: o,
5410
5428
  content: r,
5411
5429
  attachments: e.attachments,
5412
- ...Ma(i, e, { sendsPageContext: t }),
5430
+ ...Ra(i, e, { sendsPageContext: s }),
5413
5431
  language: i.language,
5414
- features: Ka(i),
5432
+ features: Oa(i),
5415
5433
  presentation: i.presentation,
5416
5434
  capabilities: {
5417
5435
  connections: ((a = i.capabilities) == null ? void 0 : a.connections) === !0,
@@ -5429,11 +5447,11 @@ const Ma = (i, e, { sendsPageContext: s }) => {
5429
5447
  }, x = class x {
5430
5448
  constructor({
5431
5449
  config: e,
5432
- api: s,
5450
+ api: t,
5433
5451
  sessionCtx: o,
5434
5452
  contactCtx: r,
5435
5453
  streaming: _,
5436
- sendsPageContext: t,
5454
+ sendsPageContext: s,
5437
5455
  getClientCapabilities: a,
5438
5456
  getRequestConfig: n,
5439
5457
  isStreaming: c,
@@ -5512,25 +5530,25 @@ const Ma = (i, e, { sendsPageContext: s }) => {
5512
5530
  }, this.stageUserTurn = async (l, { pending: p }) => {
5513
5531
  const u = this.captureConversation(), m = this.buildUserMessage(l);
5514
5532
  if (!m) return null;
5515
- const g = p ? { ...m, pending: !0 } : m, v = this.buildPersistentInitialMessages(), y = [
5516
- ...v.map((w) => w.id),
5533
+ const g = p ? { ...m, pending: !0 } : m, f = this.buildPersistentInitialMessages(), y = [
5534
+ ...f.map((w) => w.id),
5517
5535
  g.id
5518
5536
  ];
5519
5537
  this.state.setPartial({
5520
5538
  messages: [
5521
- ...v,
5539
+ ...f,
5522
5540
  ...this.state.get().messages,
5523
5541
  ...g.background ? [] : [g]
5524
5542
  ]
5525
5543
  });
5526
- let f;
5544
+ let v;
5527
5545
  try {
5528
- f = await this.ensureSessionId();
5546
+ v = await this.ensureSessionId();
5529
5547
  } catch (w) {
5530
5548
  if (!u()) return null;
5531
5549
  throw this.rollbackOptimisticMessages(y), w;
5532
5550
  }
5533
- return u() ? f ? { sessionId: f, userMessage: g, initialMessages: v } : (this.rollbackOptimisticMessages(y), null) : null;
5551
+ return u() ? v ? { sessionId: v, userMessage: g, initialMessages: f } : (this.rollbackOptimisticMessages(y), null) : null;
5534
5552
  }, this.buildQueuedUserMessage = (l) => {
5535
5553
  var m;
5536
5554
  const p = this.buildUserMessage(l);
@@ -5554,7 +5572,7 @@ const Ma = (i, e, { sendsPageContext: s }) => {
5554
5572
  p.some((u) => u.id === l.id) || this.state.setPartial({ messages: [...p, l] });
5555
5573
  }, this.markUserMessageDelivered = (l) => {
5556
5574
  const p = this.state.get().messages, u = p.findIndex(
5557
- (v) => v.id === l && v.type === "USER" && v.pending
5575
+ (f) => f.id === l && f.type === "USER" && f.pending
5558
5576
  );
5559
5577
  if (u === -1) return;
5560
5578
  const m = p[u];
@@ -5565,19 +5583,19 @@ const Ma = (i, e, { sendsPageContext: s }) => {
5565
5583
  });
5566
5584
  }, this.setMessageOptionPick = (l, p) => {
5567
5585
  const u = this.state.get().messages, m = u.findIndex((y) => y.id === l), g = u[m];
5568
- if (!g || g.type !== "AGENT" || !g.messageOptions || g.messageOptions.pickedOptionId === p) return;
5569
- const v = [...u];
5570
- v[m] = {
5586
+ if (!g || !I(g) || !g.messageOptions || g.messageOptions.pickedOptionId === p) return;
5587
+ const f = [...u];
5588
+ f[m] = {
5571
5589
  ...g,
5572
5590
  messageOptions: { ...g.messageOptions, pickedOptionId: p }
5573
- }, this.state.setPartial({ messages: v });
5574
- }, this.releaseFailedOptionPick = (l) => {
5591
+ }, this.state.setPartial({ messages: f });
5592
+ }, this.releaseUnsentOptionPick = (l) => {
5575
5593
  var g;
5576
5594
  if (!l.optionReply) return;
5577
- const { messageId: p, optionId: u } = l.optionReply, m = this.state.get().messages.find((v) => v.id === p);
5578
- (m == null ? void 0 : m.type) !== "AGENT" || ((g = m.messageOptions) == null ? void 0 : g.pickedOptionId) !== u || this.setMessageOptionPick(p, null);
5595
+ const { messageId: p, optionId: u } = l.optionReply, m = this.state.get().messages.find((f) => f.id === p);
5596
+ !m || !I(m) || ((g = m.messageOptions) == null ? void 0 : g.pickedOptionId) !== u || this.setMessageOptionPick(p, null);
5579
5597
  }, this.sendMessage = async (l) => {
5580
- var u, m, g, v, y;
5598
+ var u, m, g, f, y;
5581
5599
  if (this.streaming) {
5582
5600
  if (!this.agentHandlers) {
5583
5601
  this.bufferedAgentSends.push(l);
@@ -5588,8 +5606,8 @@ const Ma = (i, e, { sendsPageContext: s }) => {
5588
5606
  }
5589
5607
  let p;
5590
5608
  try {
5591
- const f = this.sessionCtx.sessionState.get().session, k = (f == null ? void 0 : f.assignee.kind) === "ai", M = this.state.get().isSendingMessageToAI, E = this.state.get().messages.at(-1);
5592
- if (this.blocksSendWhileAwaitingReply && (M || // If last message is from user, then bot response did not arrive yet
5609
+ const v = this.sessionCtx.sessionState.get().session, k = (v == null ? void 0 : v.assignee.kind) === "ai", D = this.state.get().isSendingMessageToAI, E = this.state.get().messages.at(-1);
5610
+ if (this.blocksSendWhileAwaitingReply && (D || // If last message is from user, then bot response did not arrive yet
5593
5611
  k && (E == null ? void 0 : E.type) === "USER" && E.id !== this.state.get().settledAgentUserMessageId)) {
5594
5612
  b.warn("cannot send messages while awaiting AI response");
5595
5613
  return;
@@ -5597,23 +5615,23 @@ const Ma = (i, e, { sendsPageContext: s }) => {
5597
5615
  this.sendMessageAbortController.abort("Superseded by a newer message"), this.sendMessageAbortController = new AbortController(), p = this.sendMessageAbortController, this.state.setPartial({
5598
5616
  lastAIResMightSolveUserIssue: !1,
5599
5617
  isSendingMessage: !0,
5600
- isSendingMessageToAI: !!k || !f
5618
+ isSendingMessageToAI: !!k || !v
5601
5619
  });
5602
- const K = await this.stageUserTurn(l, { pending: !1 });
5603
- if (!K) return;
5604
- const { sessionId: ee, userMessage: L, initialMessages: ae } = K;
5620
+ const L = await this.stageUserTurn(l, { pending: !1 });
5621
+ if (!L) return;
5622
+ const { sessionId: ae, userMessage: O, initialMessages: te } = L;
5605
5623
  this.notifySendAccepted(l);
5606
5624
  const { data: j } = await this.api.sendMessage(
5607
- La({
5625
+ Fa({
5608
5626
  config: {
5609
5627
  ...this.getRequestConfig(),
5610
5628
  capabilities: this.getClientCapabilities()
5611
5629
  },
5612
5630
  input: l,
5613
- uuid: L.id,
5614
- sessionId: ee,
5615
- content: L.content,
5616
- initialMessages: ae,
5631
+ uuid: O.id,
5632
+ sessionId: ae,
5633
+ content: O.content,
5634
+ initialMessages: te,
5617
5635
  sendsPageContext: this.sendsPageContext
5618
5636
  }),
5619
5637
  p.signal
@@ -5623,7 +5641,7 @@ const Ma = (i, e, { sendsPageContext: s }) => {
5623
5641
  if (C) {
5624
5642
  const P = this.state.get().messages;
5625
5643
  if (!!P.some(
5626
- (te) => te.id === C.id
5644
+ (se) => se.id === C.id
5627
5645
  )) {
5628
5646
  this.state.setPartial({
5629
5647
  lastAIResMightSolveUserIssue: ((u = j.autopilotResponse) == null ? void 0 : u.mightSolveUserIssue) || ((m = j.uiResponse) == null ? void 0 : m.mightSolveUserIssue)
@@ -5632,21 +5650,21 @@ const Ma = (i, e, { sendsPageContext: s }) => {
5632
5650
  }
5633
5651
  this.state.setPartial({
5634
5652
  messages: [...P, C],
5635
- lastAIResMightSolveUserIssue: ((g = j.autopilotResponse) == null ? void 0 : g.mightSolveUserIssue) || ((v = j.uiResponse) == null ? void 0 : v.mightSolveUserIssue)
5653
+ lastAIResMightSolveUserIssue: ((g = j.autopilotResponse) == null ? void 0 : g.mightSolveUserIssue) || ((f = j.uiResponse) == null ? void 0 : f.mightSolveUserIssue)
5636
5654
  }), this.dispatchToOnMessageReceivedHook(C);
5637
5655
  }
5638
5656
  j.session && this.sessionCtx.sessionState.setPartial({ session: j.session });
5639
5657
  } else {
5640
- this.releaseFailedOptionPick(l);
5658
+ this.releaseUnsentOptionPick(l);
5641
5659
  const C = this.toBotErrorMessage(
5642
- ((y = j == null ? void 0 : j.error) == null ? void 0 : y.message) || Ta(this.config, "turn_failed_message")
5660
+ ((y = j == null ? void 0 : j.error) == null ? void 0 : y.message) || Ia(this.config, "turn_failed_message")
5643
5661
  ), P = this.state.get().messages;
5644
5662
  this.state.setPartial({
5645
5663
  messages: [...P, C]
5646
5664
  });
5647
5665
  }
5648
- } catch (f) {
5649
- p != null && p.signal.aborted || (this.releaseFailedOptionPick(l), b.error("failed to send message", f));
5666
+ } catch (v) {
5667
+ p != null && p.signal.aborted || (this.releaseUnsentOptionPick(l), b.error("failed to send message", v));
5650
5668
  } finally {
5651
5669
  p != null && p.signal.aborted || this.state.setPartial({
5652
5670
  isSendingMessage: !1,
@@ -5660,16 +5678,16 @@ const Ma = (i, e, { sendsPageContext: s }) => {
5660
5678
  `)}
5661
5679
 
5662
5680
  ${l}` : l;
5663
- })(), v = (/* @__PURE__ */ new Date()).toISOString();
5681
+ })(), f = (/* @__PURE__ */ new Date()).toISOString();
5664
5682
  return {
5665
5683
  id: q(),
5666
5684
  type: "USER",
5667
- deliveredAt: v,
5685
+ deliveredAt: f,
5668
5686
  content: g,
5669
5687
  attachments: p,
5670
5688
  markedElements: u,
5671
5689
  mentions: m,
5672
- timestamp: v
5690
+ timestamp: f
5673
5691
  };
5674
5692
  }, this.toBotMessage = (l) => {
5675
5693
  var p;
@@ -5704,7 +5722,7 @@ ${l}` : l;
5704
5722
  variant: "error",
5705
5723
  action: void 0
5706
5724
  }
5707
- }), this.config = e, this.getClientCapabilities = a ?? (() => this.getRequestConfig().capabilities), this.api = s, this.sessionCtx = o, this.contactCtx = r, this.isStreaming = c ?? (() => _), this.getRequestConfig = n ?? (() => this.config), this.getSendsPageContext = d ?? (() => t);
5725
+ }), this.config = e, this.getClientCapabilities = a ?? (() => this.getRequestConfig().capabilities), this.api = t, this.sessionCtx = o, this.contactCtx = r, this.isStreaming = c ?? (() => _), this.getRequestConfig = n ?? (() => this.config), this.getSendsPageContext = d ?? (() => s);
5708
5726
  }
5709
5727
  /**
5710
5728
  * Current transport choice. The org or this embed may request polling
@@ -5717,9 +5735,9 @@ ${l}` : l;
5717
5735
  return this.getSendsPageContext();
5718
5736
  }
5719
5737
  /** Hand a send to the streaming engine; its failure can never propagate. */
5720
- static dispatchToEngine(e, s) {
5738
+ static dispatchToEngine(e, t) {
5721
5739
  try {
5722
- Promise.resolve(e.send(s)).catch((o) => {
5740
+ Promise.resolve(e.send(t)).catch((o) => {
5723
5741
  b.error("streaming send failed", o);
5724
5742
  });
5725
5743
  } catch (o) {
@@ -5727,8 +5745,8 @@ ${l}` : l;
5727
5745
  }
5728
5746
  }
5729
5747
  get hasPendingAgentWork() {
5730
- var e, s;
5731
- return this.bufferedAgentSends.length > 0 || (((s = (e = this.agentHandlers) == null ? void 0 : e.hasPendingWork) == null ? void 0 : s.call(e)) ?? !1);
5748
+ var e, t;
5749
+ return this.bufferedAgentSends.length > 0 || (((t = (e = this.agentHandlers) == null ? void 0 : e.hasPendingWork) == null ? void 0 : t.call(e)) ?? !1);
5732
5750
  }
5733
5751
  /**
5734
5752
  * Defensive read of `clientContext.page_marks` → the user bubble's context
@@ -5738,11 +5756,11 @@ ${l}` : l;
5738
5756
  * without a usable name are dropped.
5739
5757
  */
5740
5758
  static markedElementNames(e) {
5741
- const s = e == null ? void 0 : e.page_marks;
5742
- if (!Array.isArray(s)) return;
5743
- const o = s.flatMap((r) => {
5759
+ const t = e == null ? void 0 : e.page_marks;
5760
+ if (!Array.isArray(t)) return;
5761
+ const o = t.flatMap((r) => {
5744
5762
  if (typeof r != "object" || r === null) return [];
5745
- const _ = r.elements, t = Array.isArray(_) ? _[0] : void 0, a = typeof t == "object" && t !== null && "name" in t ? t.name : void 0;
5763
+ const _ = r.elements, s = Array.isArray(_) ? _[0] : void 0, a = typeof s == "object" && s !== null && "name" in s ? s.name : void 0;
5746
5764
  if (typeof a != "string" || a.length === 0) return [];
5747
5765
  const n = r.note, c = r.snapshotUrl;
5748
5766
  return [
@@ -5765,10 +5783,10 @@ ${l}` : l;
5765
5783
  }
5766
5784
  };
5767
5785
  x.SENT_TEXT_HISTORY_MAX = 50;
5768
- let R = x;
5769
- class Oa {
5786
+ let N = x;
5787
+ class Ua {
5770
5788
  constructor(e) {
5771
- var s, o;
5789
+ var t, o;
5772
5790
  this.widget = e, this.subscriptions = [], this.disposed = !1, this.restorableSessionId = null, this.didReadStoredSession = !1, this.readStoredSession = () => {
5773
5791
  if (!this.shouldRestoreLastSession) {
5774
5792
  this.didReadStoredSession = !0;
@@ -5794,9 +5812,9 @@ class Oa {
5794
5812
  isInitialFetchLoading: r,
5795
5813
  data: _
5796
5814
  }) => {
5797
- var t, a, n, c, d;
5815
+ var s, a, n, c, d;
5798
5816
  if (!(this.disposed || !this.didReadStoredSession)) {
5799
- if (this.restorableSessionId && !((t = this.sessionCtx.sessionState.get().session) != null && t.id)) {
5817
+ if (this.restorableSessionId && !((s = this.sessionCtx.sessionState.get().session) != null && s.id)) {
5800
5818
  const l = _.find(
5801
5819
  (p) => p.id === this.restorableSessionId && p.isOpened
5802
5820
  );
@@ -5820,7 +5838,7 @@ class Oa {
5820
5838
  }, this.toSessionsScreen = () => {
5821
5839
  this.navigateConversation || this.resetChat(), this.state.setPartial({ screen: "sessions" });
5822
5840
  }, this.toChatScreen = (r) => {
5823
- var t, a;
5841
+ var s, a;
5824
5842
  if (this.navigateConversation) return this.navigateConversation(r);
5825
5843
  this.resetChat();
5826
5844
  let _;
@@ -5828,16 +5846,16 @@ class Oa {
5828
5846
  if (_ = this.sessionCtx.sessionsState.get().data.find((n) => n.id === r), !_) return;
5829
5847
  this.sessionCtx.sessionState.setPartial({ session: _ });
5830
5848
  }
5831
- return this.state.setPartial({ screen: "chat" }), (a = (t = this.config.hooks) == null ? void 0 : t.onNavigateToChat) == null || a.call(t, { session: _ }), this.widget;
5849
+ return this.state.setPartial({ screen: "chat" }), (a = (s = this.config.hooks) == null ? void 0 : s.onNavigateToChat) == null || a.call(s, { session: _ }), this.widget;
5832
5850
  }, this.config = e.config, this.contactCtx = e.contactCtx, this.sessionCtx = e.sessionCtx, this.resetChat = e.resetChat, this.state = new z({
5833
- screen: this.contactCtx.shouldCollectData() ? "welcome" : (s = this.config.router) != null && s.chatScreenOnly ? "chat" : "sessions"
5851
+ screen: this.contactCtx.shouldCollectData() ? "welcome" : (t = this.config.router) != null && t.chatScreenOnly ? "chat" : "sessions"
5834
5852
  }), this.shouldRestoreLastSession = ((o = this.config.router) == null ? void 0 : o.restoreLastSession) ?? !1, this.readStoredSession(), this.registerRoutingListener();
5835
5853
  }
5836
5854
  }
5837
- class Fa {
5855
+ class Ba {
5838
5856
  constructor({
5839
5857
  storage: e,
5840
- config: s
5858
+ config: t
5841
5859
  }) {
5842
5860
  this.KEYS = {
5843
5861
  contactToken: (o) => `opencx-widget:org-token-${o}:contact-token`,
@@ -5878,10 +5896,10 @@ class Fa {
5878
5896
  return o === "docked" || o === "floating" ? o : null;
5879
5897
  }, this.setCompanionSidebarMode = async (o) => {
5880
5898
  await this.storage.set(this.companionKey("sidebar-mode"), o);
5881
- }, this.storage = e, this.config = s;
5899
+ }, this.storage = e, this.config = t;
5882
5900
  }
5883
5901
  }
5884
- function Ua({
5902
+ function Ha({
5885
5903
  org: i,
5886
5904
  agent: e
5887
5905
  }) {
@@ -5910,35 +5928,35 @@ function Ua({
5910
5928
  }
5911
5929
  };
5912
5930
  }
5913
- function Z(i, e) {
5931
+ function W(i, e) {
5914
5932
  return i && e !== !1;
5915
5933
  }
5916
- function Ba(i, e) {
5917
- const s = e.features;
5934
+ function Va(i, e) {
5935
+ const t = e.features;
5918
5936
  return {
5919
- dictation: Z(i.features.dictation, s == null ? void 0 : s.dictation),
5920
- attachments: Z(
5937
+ dictation: W(i.features.dictation, t == null ? void 0 : t.dictation),
5938
+ attachments: W(
5921
5939
  i.features.attachments,
5922
- s == null ? void 0 : s.attachments
5940
+ t == null ? void 0 : t.attachments
5923
5941
  ),
5924
- pageContext: i.features.pageContext && (s == null ? void 0 : s.pageContext) === !0,
5925
- clientTools: i.features.clientTools && i.features.pageContext && (s == null ? void 0 : s.pageContext) === !0 && (s == null ? void 0 : s.clientTools) === !0,
5926
- pageActions: i.features.pageActions && i.features.clientTools && i.features.pageContext && (s == null ? void 0 : s.pageContext) === !0 && (s == null ? void 0 : s.clientTools) === !0 && (s == null ? void 0 : s.pageActions) === !0
5942
+ pageContext: i.features.pageContext && (t == null ? void 0 : t.pageContext) === !0,
5943
+ clientTools: i.features.clientTools && i.features.pageContext && (t == null ? void 0 : t.pageContext) === !0 && (t == null ? void 0 : t.clientTools) === !0,
5944
+ pageActions: i.features.pageActions && i.features.clientTools && i.features.pageContext && (t == null ? void 0 : t.pageContext) === !0 && (t == null ? void 0 : t.clientTools) === !0 && (t == null ? void 0 : t.pageActions) === !0
5927
5945
  };
5928
5946
  }
5929
- class Ha extends Error {
5930
- constructor(e, s, o) {
5931
- super(s), this.name = "WidgetInitializationError", this.code = e, this.details = o;
5947
+ class Ga extends Error {
5948
+ constructor(e, t, o) {
5949
+ super(t), this.name = "WidgetInitializationError", this.code = e, this.details = o;
5932
5950
  }
5933
5951
  }
5934
5952
  const S = class S {
5935
5953
  constructor({
5936
5954
  config: e,
5937
- storage: s,
5955
+ storage: t,
5938
5956
  getClientCapabilities: o,
5939
5957
  getRequestConfig: r,
5940
5958
  modes: _,
5941
- org: t,
5959
+ org: s,
5942
5960
  agent: a,
5943
5961
  parent: n
5944
5962
  }) {
@@ -5974,11 +5992,11 @@ const S = class S {
5974
5992
  throw Error(
5975
5993
  "Widget polling values are not defined, did you call WidgetCtx.initialize()"
5976
5994
  );
5977
- this.config = e, this.getRequestConfig = r ?? (() => this.config), this.getClientCapabilities = o, this.org = t, this.agent = a, this.api = (n == null ? void 0 : n.api) ?? new B({ config: e }), this.storageCtx = (n == null ? void 0 : n.storageCtx) ?? (s ? new Fa({ storage: s, config: e }) : void 0), this.modes = _, this.contactCtx = (n == null ? void 0 : n.contactCtx) ?? new ve({
5995
+ this.config = e, this.getRequestConfig = r ?? (() => this.config), this.getClientCapabilities = o, this.org = s, this.agent = a, this.api = (n == null ? void 0 : n.api) ?? new H({ config: e }), this.storageCtx = (n == null ? void 0 : n.storageCtx) ?? (t ? new Ba({ storage: t, config: e }) : void 0), this.modes = _, this.contactCtx = (n == null ? void 0 : n.contactCtx) ?? new ve({
5978
5996
  api: this.api,
5979
5997
  config: this.config,
5980
5998
  storageCtx: this.storageCtx
5981
- }), this.sessionCtx = new Ia({
5999
+ }), this.sessionCtx = new Da({
5982
6000
  config: this.config,
5983
6001
  api: this.api,
5984
6002
  contactCtx: this.contactCtx,
@@ -5986,12 +6004,12 @@ const S = class S {
5986
6004
  storageCtx: n ? void 0 : this.storageCtx,
5987
6005
  sharedSessions: n == null ? void 0 : n.sessionCtx.sessionsState,
5988
6006
  sessionsPollingIntervalSeconds: S.pollingIntervalsSeconds.sessions
5989
- }), this.ownsUnreadCtx = !n, this.unreadCtx = (n == null ? void 0 : n.unreadCtx) ?? new ie({
6007
+ }), this.ownsUnreadCtx = !n, this.unreadCtx = (n == null ? void 0 : n.unreadCtx) ?? new re({
5990
6008
  config: this.config,
5991
6009
  api: this.api,
5992
6010
  sessionsState: this.sessionCtx.sessionsState,
5993
6011
  setSessions: this.sessionCtx.setSessions
5994
- }), this.messageCtx = new R({
6012
+ }), this.messageCtx = new N({
5995
6013
  config: this.config,
5996
6014
  api: this.api,
5997
6015
  sessionCtx: this.sessionCtx,
@@ -6004,55 +6022,55 @@ const S = class S {
6004
6022
  getSendsPageContext: () => this.features.pageContext,
6005
6023
  getClientCapabilities: o,
6006
6024
  getRequestConfig: r
6007
- }), this.uploadCtx = new fe(this.api), this.csatCtx = new ye({
6025
+ }), this.uploadCtx = new ye(this.api), this.csatCtx = new we({
6008
6026
  api: this.api,
6009
6027
  sessionCtx: this.sessionCtx,
6010
6028
  messageCtx: this.messageCtx
6011
- }), this.dictationCtx = new Be({
6029
+ }), this.dictationCtx = new He({
6012
6030
  api: this.api,
6013
6031
  config: this.config
6014
- }), this.activeSessionPollingCtx = new be({
6032
+ }), this.activeSessionPollingCtx = new fe({
6015
6033
  api: this.api,
6016
6034
  config: this.config,
6017
6035
  sessionCtx: this.sessionCtx,
6018
6036
  messageCtx: this.messageCtx,
6019
6037
  sessionPollingIntervalSeconds: S.pollingIntervalsSeconds.session
6020
- }), this.routerCtx = new Oa(this);
6038
+ }), this.routerCtx = new Ua(this);
6021
6039
  }
6022
6040
  get streaming() {
6023
- var e, s;
6024
- return (e = this.messageCtx) != null && e.hasPendingAgentWork ? !0 : (s = this.messageCtx) != null && s.state.get().isSendingMessage ? !1 : this.agent.streaming && this.getRequestConfig().streaming === !0;
6041
+ var e, t;
6042
+ return (e = this.messageCtx) != null && e.hasPendingAgentWork ? !0 : (t = this.messageCtx) != null && t.state.get().isSendingMessage ? !1 : this.agent.streaming && this.getRequestConfig().streaming === !0;
6025
6043
  }
6026
6044
  /**
6027
6045
  * The org's features narrowed by this embed's `config.features` — the
6028
6046
  * answers the UI asks for, resolved against the current options.
6029
6047
  */
6030
6048
  get features() {
6031
- return Ba(this.agent, this.getRequestConfig());
6049
+ return Va(this.agent, this.getRequestConfig());
6032
6050
  }
6033
6051
  };
6034
6052
  S.pollingIntervalsSeconds = null, S.initialize = async ({
6035
6053
  config: e,
6036
- storage: s,
6054
+ storage: t,
6037
6055
  getClientCapabilities: o,
6038
6056
  getRequestConfig: r
6039
6057
  }) => {
6040
- var t, a;
6041
- const _ = await new B({
6058
+ var s, a;
6059
+ const _ = await new H({
6042
6060
  config: e
6043
6061
  }).getExternalWidgetConfig();
6044
6062
  if (!_.data)
6045
- throw b.error("widget config fetch failed", _.error), new Ha(
6063
+ throw b.error("widget config fetch failed", _.error), new Ga(
6046
6064
  "config-fetch-failed",
6047
6065
  "Failed to fetch widget config",
6048
6066
  _.error
6049
6067
  );
6050
6068
  return S.pollingIntervalsSeconds = {
6051
- session: ((t = _.data) == null ? void 0 : t.sessionPollingIntervalSeconds) || 10,
6069
+ session: ((s = _.data) == null ? void 0 : s.sessionPollingIntervalSeconds) || 10,
6052
6070
  sessions: ((a = _.data) == null ? void 0 : a.sessionsPollingIntervalSeconds) || 60
6053
6071
  }, new S({
6054
6072
  config: e,
6055
- storage: s,
6073
+ storage: t,
6056
6074
  getClientCapabilities: o,
6057
6075
  getRequestConfig: r,
6058
6076
  modes: _.data.modes || [],
@@ -6060,20 +6078,20 @@ S.pollingIntervalsSeconds = null, S.initialize = async ({
6060
6078
  id: _.data.org.id,
6061
6079
  name: _.data.org.name
6062
6080
  },
6063
- agent: Ua(_.data)
6081
+ agent: Ha(_.data)
6064
6082
  });
6065
6083
  };
6066
- let W = S;
6067
- function et(i, e) {
6084
+ let $ = S;
6085
+ function st(i, e) {
6068
6086
  return i ? {
6069
6087
  streaming: i.streaming && (e == null ? void 0 : e.streaming) !== !1,
6070
6088
  toolActivity: i.toolActivity === "hidden" || (e == null ? void 0 : e.toolActivity) === "hidden" ? "hidden" : i.toolActivity === "status" || (e == null ? void 0 : e.toolActivity) === "status" ? "status" : "details",
6071
6089
  reasoning: i.reasoning && (e == null ? void 0 : e.reasoning) !== !1
6072
6090
  } : e;
6073
6091
  }
6074
- class at {
6075
- constructor({ attack: e, release: s }) {
6076
- this.value = 0, this.attack = e, this.release = s;
6092
+ class ot {
6093
+ constructor({ attack: e, release: t }) {
6094
+ this.value = 0, this.attack = e, this.release = t;
6077
6095
  }
6078
6096
  next(e) {
6079
6097
  return this.value += (e - this.value) * (e > this.value ? this.attack : this.release), this.value;
@@ -6082,57 +6100,60 @@ class at {
6082
6100
  return this.value;
6083
6101
  }
6084
6102
  }
6085
- const I = [
6103
+ const M = [
6086
6104
  "compact",
6087
6105
  "sidebar",
6088
6106
  "fullscreen"
6089
- ], Va = new Set(
6090
- I
6107
+ ], Za = new Set(
6108
+ M
6091
6109
  );
6092
- function X(i) {
6093
- return Va.has(i);
6110
+ function ee(i) {
6111
+ return Za.has(i);
6094
6112
  }
6095
- function tt(i) {
6096
- if (!Array.isArray(i)) return I;
6097
- const e = [], s = /* @__PURE__ */ new Set();
6113
+ function nt(i) {
6114
+ if (!Array.isArray(i)) return M;
6115
+ const e = [], t = /* @__PURE__ */ new Set();
6098
6116
  for (const o of i)
6099
- !X(o) || s.has(o) || (s.add(o), e.push(o));
6100
- return e.length > 0 ? e : I;
6117
+ !ee(o) || t.has(o) || (t.add(o), e.push(o));
6118
+ return e.length > 0 ? e : M;
6101
6119
  }
6102
- function st(i, e) {
6103
- return X(i) && e.includes(i) ? i : e[0] ?? I[0];
6120
+ function it(i, e) {
6121
+ return ee(i) && e.includes(i) ? i : e[0] ?? M[0];
6104
6122
  }
6105
- function ot(i, e) {
6123
+ function rt(i, e) {
6106
6124
  return i === "left" || i === "right" ? i : e === "rtl" ? "left" : "right";
6107
6125
  }
6108
- function nt(i) {
6126
+ function _t(i) {
6109
6127
  return i === "docked" ? "docked" : "floating";
6110
6128
  }
6111
6129
  export {
6112
- me as ConnectionAttemptUnavailableError,
6113
- ue as ConnectionRequestExpiredError,
6114
- at as DictationLevelSmoother,
6130
+ he as ConnectionAttemptUnavailableError,
6131
+ me as ConnectionRequestExpiredError,
6132
+ ot as DictationLevelSmoother,
6115
6133
  z as PrimitiveState,
6116
- ie as UnreadCtx,
6117
- W as WidgetCtx,
6118
- Ha as WidgetInitializationError,
6119
- La as buildSendMessageBody,
6134
+ re as UnreadCtx,
6135
+ $ as WidgetCtx,
6136
+ Ga as WidgetInitializationError,
6137
+ Fa as buildSendMessageBody,
6120
6138
  q as genUuid,
6121
- Pa as getTranslation,
6122
- Ya as isAgentStreamKeepalive,
6123
- ke as isExhaustive,
6124
- G as isRecord,
6125
- Xa as isRtlLanguage,
6126
- qa as isSupportedLanguage,
6127
- Qa as isTurnSteeredPart,
6139
+ Ta as getTranslation,
6140
+ I as isAgentOrAiMessage,
6141
+ Xa as isAgentStreamKeepalive,
6142
+ tt as isAwaitingRequiredTap,
6143
+ be as isExhaustive,
6144
+ Z as isRecord,
6145
+ at as isRtlLanguage,
6146
+ Aa as isSupportedLanguage,
6147
+ et as isTurnSteeredPart,
6128
6148
  b as log,
6129
- tt as normalizeCompanionLayouts,
6130
- et as resolveClientPresentation,
6131
- st as resolveCompanionDefaultLayout,
6132
- Na as resolveConfigContext,
6133
- Ea as resolveLanguage,
6134
- nt as resolveSidebarMode,
6135
- ot as resolveSidebarSide,
6136
- Ta as translate
6149
+ nt as normalizeCompanionLayouts,
6150
+ st as resolveClientPresentation,
6151
+ it as resolveCompanionDefaultLayout,
6152
+ La as resolveConfigContext,
6153
+ Pa as resolveLanguage,
6154
+ _t as resolveSidebarMode,
6155
+ rt as resolveSidebarSide,
6156
+ Ma as tappableOptionsMessage,
6157
+ Ia as translate
6137
6158
  };
6138
6159
  //# sourceMappingURL=index.js.map