@opencx/widget-core 5.1.0 → 5.3.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,81 +1,81 @@
1
- import { z as m } from "zod";
2
- import te from "openapi-fetch";
3
- import se from "lodash.isequal";
1
+ import { z as h } from "zod";
2
+ import se from "openapi-fetch";
3
+ import oe from "lodash.isequal";
4
4
  import { v4 as N } from "uuid";
5
- const Wa = (i) => i.type === "data-keepalive", $a = (i) => i.type === "data-turn-steered", L = m.object({ const: m.string(), title: m.string().optional() }), oe = m.object({
6
- type: m.enum(["string", "number", "integer", "boolean", "array"]),
7
- title: m.string().optional(),
8
- description: m.string().optional(),
9
- default: m.union([m.string(), m.number(), m.boolean(), m.array(m.string())]).optional(),
10
- enum: m.array(m.string()).optional(),
11
- oneOf: m.array(L).optional(),
12
- items: m.object({
13
- enum: m.array(m.string()).optional(),
14
- anyOf: m.array(L).optional()
5
+ const Wa = (i) => i.type === "data-keepalive", $a = (i) => i.type === "data-turn-steered", L = h.object({ const: h.string(), title: h.string().optional() }), ne = h.object({
6
+ type: h.enum(["string", "number", "integer", "boolean", "array"]),
7
+ title: h.string().optional(),
8
+ description: h.string().optional(),
9
+ default: h.union([h.string(), h.number(), h.boolean(), h.array(h.string())]).optional(),
10
+ enum: h.array(h.string()).optional(),
11
+ oneOf: h.array(L).optional(),
12
+ items: h.object({
13
+ enum: h.array(h.string()).optional(),
14
+ anyOf: h.array(L).optional()
15
15
  }).optional(),
16
- minItems: m.number().int().nonnegative().optional(),
17
- maxItems: m.number().int().nonnegative().optional(),
18
- minimum: m.number().optional(),
19
- maximum: m.number().optional(),
20
- minLength: m.number().optional(),
21
- maxLength: m.number().optional(),
22
- format: m.string().optional()
23
- }), ne = m.array(
24
- m.object({
25
- id: m.string(),
26
- serverId: m.string(),
27
- serverName: m.string(),
28
- expiresAt: m.number(),
29
- approvalKey: m.string().optional(),
30
- form: m.object({
31
- message: m.string(),
32
- requestedSchema: m.object({
33
- properties: m.record(m.string(), oe),
34
- required: m.array(m.string()).optional()
16
+ minItems: h.number().int().nonnegative().optional(),
17
+ maxItems: h.number().int().nonnegative().optional(),
18
+ minimum: h.number().optional(),
19
+ maximum: h.number().optional(),
20
+ minLength: h.number().optional(),
21
+ maxLength: h.number().optional(),
22
+ format: h.string().optional()
23
+ }), ie = h.array(
24
+ h.object({
25
+ id: h.string(),
26
+ serverId: h.string(),
27
+ serverName: h.string(),
28
+ expiresAt: h.number(),
29
+ approvalKey: h.string().optional(),
30
+ form: h.object({
31
+ message: h.string(),
32
+ requestedSchema: h.object({
33
+ properties: h.record(h.string(), ne),
34
+ required: h.array(h.string()).optional()
35
35
  })
36
36
  })
37
37
  })
38
- ), ie = m.array(
39
- m.object({
40
- key: m.string(),
41
- serverId: m.string(),
42
- serverName: m.string(),
43
- message: m.string(),
44
- toolName: m.string()
38
+ ), re = h.array(
39
+ h.object({
40
+ key: h.string(),
41
+ serverId: h.string(),
42
+ serverName: h.string(),
43
+ message: h.string(),
44
+ toolName: h.string()
45
45
  })
46
- ), F = "[opencx]", g = {
46
+ ), O = "[opencx]", k = {
47
47
  warn: (i, ...e) => {
48
- console.warn(`${F} ${i}`, ...e);
48
+ console.warn(`${O} ${i}`, ...e);
49
49
  },
50
50
  error: (i, ...e) => {
51
- console.error(`${F} ${i}`, ...e);
51
+ console.error(`${O} ${i}`, ...e);
52
52
  }
53
- }, re = (i) => {
54
- g.error("request failed", i.error);
55
53
  }, _e = (i) => {
56
- const e = te({
54
+ k.error("request failed", i.error);
55
+ }, le = (i) => {
56
+ const e = se({
57
57
  baseUrl: i.baseUrl
58
58
  }), a = {
59
59
  onRequest: i.onRequest,
60
60
  onResponse: i.onResponse,
61
- onError: i.onError || re
61
+ onError: i.onError || _e
62
62
  };
63
63
  return e.use(a), e;
64
64
  };
65
- class le extends Error {
65
+ class ce extends Error {
66
66
  constructor() {
67
67
  super("This connection request expired. Preparing a new request."), this.name = "ConnectionRequestExpiredError";
68
68
  }
69
69
  }
70
- class ce extends Error {
70
+ class pe extends Error {
71
71
  constructor() {
72
72
  super("This connection attempt is no longer available."), this.name = "ConnectionAttemptUnavailableError";
73
73
  }
74
74
  }
75
- const pe = "/backend/widget/v5/chat/stream", de = "/backend/widget/v5/chat/{sessionId}/stream", O = (i, e, a) => `${i.replace(/\/$/, "")}${a ? e.replace("{sessionId}", encodeURIComponent(a)) : e}`;
75
+ const de = "/backend/widget/v5/chat/stream", ue = "/backend/widget/v5/chat/{sessionId}/stream", F = (i, e, a) => `${i.replace(/\/$/, "")}${a ? e.replace("{sessionId}", encodeURIComponent(a)) : e}`;
76
76
  class U {
77
77
  constructor({ config: e }) {
78
- var r, l;
78
+ var r, c;
79
79
  this.userToken = null, this.constructClientOptions = (s) => {
80
80
  const t = this.config.apiUrl || "https://api.open.cx", n = {
81
81
  "X-Bot-Token": this.config.token,
@@ -87,11 +87,11 @@ class U {
87
87
  }, this.createOpenAPIClient = ({
88
88
  baseUrl: s,
89
89
  headers: t
90
- }) => _e({
90
+ }) => le({
91
91
  baseUrl: s,
92
92
  onRequest: ({ request: n }) => {
93
- Object.entries(t).forEach(([c, d]) => {
94
- d && n.headers.set(c, d);
93
+ Object.entries(t).forEach(([l, d]) => {
94
+ d && n.headers.set(l, d);
95
95
  });
96
96
  }
97
97
  }), this.listApprovalPreferences = async () => {
@@ -100,23 +100,23 @@ class U {
100
100
  { headers: t }
101
101
  );
102
102
  if (!n.ok) throw new Error("Could not load permissions.");
103
- return ie.parse(await n.json());
103
+ return re.parse(await n.json());
104
104
  }, this.revokeApprovalPreference = async (s, t) => {
105
- const { baseUrl: n, headers: c } = this.getStreamAuthContext();
105
+ const { baseUrl: n, headers: l } = this.getStreamAuthContext();
106
106
  if (!(await fetch(
107
107
  `${n}/backend/widget/v5/connections/${encodeURIComponent(s)}/approval-preferences/${encodeURIComponent(t)}`,
108
- { method: "DELETE", headers: c }
108
+ { method: "DELETE", headers: l }
109
109
  )).ok) throw new Error("Could not reset permission.");
110
110
  }, this.listElicitations = async (s, t) => {
111
- const { baseUrl: n, headers: c } = this.getStreamAuthContext(), d = await fetch(
111
+ const { baseUrl: n, headers: l } = this.getStreamAuthContext(), d = await fetch(
112
112
  `${n}/backend/widget/v5/connections/elicitation/${encodeURIComponent(s)}`,
113
- { headers: c, signal: t }
113
+ { headers: l, signal: t }
114
114
  );
115
115
  if (!d.ok) throw new Error("Could not load the request.");
116
- return ne.parse(await d.json());
116
+ return ie.parse(await d.json());
117
117
  }, this.answerElicitation = async (s, t, n) => {
118
- const { baseUrl: c, headers: d } = this.getStreamAuthContext(), _ = await fetch(
119
- `${c}/backend/widget/v5/connections/elicitation/${encodeURIComponent(s)}/${encodeURIComponent(t)}`,
118
+ const { baseUrl: l, headers: d } = this.getStreamAuthContext(), _ = await fetch(
119
+ `${l}/backend/widget/v5/connections/elicitation/${encodeURIComponent(s)}/${encodeURIComponent(t)}`,
120
120
  {
121
121
  method: "POST",
122
122
  headers: { ...d, "Content-Type": "application/json" },
@@ -136,7 +136,7 @@ class U {
136
136
  throw new Error("Could not load connections. Sign in and try again.");
137
137
  return t;
138
138
  }, this.startConnection = async (s, t, n) => {
139
- const { data: c, error: d, response: _ } = await this.client.POST(
139
+ const { data: l, error: d, response: _ } = await this.client.POST(
140
140
  "/backend/widget/v5/connections/{serverId}/start",
141
141
  {
142
142
  params: { path: { serverId: s } },
@@ -144,14 +144,14 @@ class U {
144
144
  signal: n
145
145
  }
146
146
  );
147
- if (_.status === 410) throw new le();
147
+ if (_.status === 410) throw new ce();
148
148
  if (_.status === 404)
149
149
  throw new Error("This connection request is no longer available.");
150
- if (d || !c)
150
+ if (d || !l)
151
151
  throw new Error("Could not start this connection. Please try again.");
152
- return c;
152
+ return l;
153
153
  }, this.getConnectionAttempt = async (s, t, n) => {
154
- const { data: c, error: d, response: _ } = await this.client.GET(
154
+ const { data: l, error: d, response: _ } = await this.client.GET(
155
155
  "/backend/widget/v5/connections/{serverId}/attempts/{attemptId}",
156
156
  {
157
157
  params: { path: { serverId: s, attemptId: t } },
@@ -159,10 +159,10 @@ class U {
159
159
  }
160
160
  );
161
161
  if ([401, 403, 404].includes(_.status))
162
- throw new ce();
163
- if (d || !c)
162
+ throw new pe();
163
+ if (d || !l)
164
164
  throw new Error(`Could not check the connection (${_.status}).`);
165
- return c.status;
165
+ return l.status;
166
166
  }, this.disconnectConnection = async (s) => {
167
167
  const { error: t } = await this.client.DELETE(
168
168
  "/backend/widget/v5/connections/{serverId}",
@@ -177,14 +177,14 @@ class U {
177
177
  this.client = this.createOpenAPIClient({ baseUrl: t, headers: n });
178
178
  }, this.getStreamAuthContext = () => {
179
179
  const { baseUrl: s, headers: t } = this.constructClientOptions(this.userToken), n = {};
180
- for (const [c, d] of Object.entries(t))
181
- typeof d == "string" && (["content-type", "accept"].includes(c.toLowerCase()) || (n[c] = d));
180
+ for (const [l, d] of Object.entries(t))
181
+ typeof d == "string" && (["content-type", "accept"].includes(l.toLowerCase()) || (n[l] = d));
182
182
  return { baseUrl: s, headers: n };
183
183
  }, this.getStreamTransportOptions = () => {
184
184
  const { baseUrl: s, headers: t } = this.getStreamAuthContext();
185
185
  return {
186
- api: O(s, pe),
187
- reconnectApi: (n) => O(s, de, n),
186
+ api: F(s, de),
187
+ reconnectApi: (n) => F(s, ue, n),
188
188
  headers: t
189
189
  };
190
190
  }, this.stopStream = async (s) => {
@@ -203,7 +203,7 @@ class U {
203
203
  } catch {
204
204
  }
205
205
  }, this.getAgentTurnMessages = async (s, t) => {
206
- const { data: n, response: c } = await this.client.GET(
206
+ const { data: n, response: l } = await this.client.GET(
207
207
  "/backend/widget/v5/chat/{sessionId}/messages",
208
208
  {
209
209
  params: {
@@ -218,7 +218,7 @@ class U {
218
218
  return n ? {
219
219
  ...n,
220
220
  handled_connection_request_ids: n.handled_connection_request_ids ?? []
221
- } : (g.warn("agent turn messages fetch failed", c.status), null);
221
+ } : (k.warn("agent turn messages fetch failed", l.status), null);
222
222
  }, this.createDictationSession = async ({
223
223
  language: s
224
224
  }) => {
@@ -267,7 +267,7 @@ class U {
267
267
  file: s,
268
268
  abortSignal: t,
269
269
  onProgress: n
270
- }) => new Promise((c, d) => {
270
+ }) => new Promise((l, d) => {
271
271
  var f;
272
272
  const _ = new FormData();
273
273
  _.append("file", s);
@@ -278,18 +278,18 @@ class U {
278
278
  d(new DOMException("Aborted", "AbortError"));
279
279
  return;
280
280
  }
281
- p.upload.addEventListener("progress", (b) => {
282
- if (b.lengthComputable && n) {
283
- const y = Math.round(b.loaded / b.total * 100);
281
+ p.upload.addEventListener("progress", (v) => {
282
+ if (v.lengthComputable && n) {
283
+ const y = Math.round(v.loaded / v.total * 100);
284
284
  n(y);
285
285
  }
286
286
  }), p.addEventListener("load", () => {
287
287
  if (p.status >= 200 && p.status < 300)
288
288
  try {
289
- const b = JSON.parse(p.responseText);
290
- c(b);
291
- } catch (b) {
292
- d(new Error(`Failed to parse response: ${b}`));
289
+ const v = JSON.parse(p.responseText);
290
+ l(v);
291
+ } catch (v) {
292
+ d(new Error(`Failed to parse response: ${v}`));
293
293
  }
294
294
  else
295
295
  d(new Error(`Upload failed with status: ${p.status}`));
@@ -298,8 +298,8 @@ class U {
298
298
  }), p.addEventListener("timeout", () => {
299
299
  d(new Error("Upload timed out"));
300
300
  });
301
- const { baseUrl: u } = this.constructClientOptions(this.userToken), k = `${u}/backend/widget/v2/upload`;
302
- p.open("POST", k), p.setRequestHeader("X-Bot-Token", this.config.token), this.userToken ?? ((f = this.config.user) == null ? void 0 : f.token) ? p.setRequestHeader("Authorization", `Bearer ${this.userToken}`) : g.error("user token not set"), p.send(_);
301
+ const { baseUrl: u } = this.constructClientOptions(this.userToken), g = `${u}/backend/widget/v2/upload`;
302
+ p.open("POST", g), p.setRequestHeader("X-Bot-Token", this.config.token), this.userToken ?? ((f = this.config.user) == null ? void 0 : f.token) ? p.setRequestHeader("Authorization", `Bearer ${this.userToken}`) : k.error("user token not set"), p.send(_);
303
303
  }), this.vote = async (s) => await this.client.POST("/backend/widget/v2/chat/vote", { body: s }), this.resolveSession = async (s, t) => await this.client.POST("/backend/widget/v2/session/resolve", {
304
304
  body: s,
305
305
  signal: t
@@ -307,18 +307,18 @@ class U {
307
307
  body: s
308
308
  }), 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;
309
309
  const { baseUrl: a, headers: o } = this.constructClientOptions(
310
- (l = e.user) == null ? void 0 : l.token
310
+ (c = e.user) == null ? void 0 : c.token
311
311
  );
312
312
  this.client = this.createOpenAPIClient({ baseUrl: a, headers: o });
313
313
  }
314
314
  }
315
- function ue(i, e) {
316
- g.error(`missing case for ${i} in ${e}`);
315
+ function me(i, e) {
316
+ k.error(`missing case for ${i} in ${e}`);
317
317
  }
318
318
  class S {
319
319
  constructor(e) {
320
320
  this.subscribers = /* @__PURE__ */ new Set(), this.get = () => this.state, this.set = (a) => {
321
- se(this.state, a) || (this.state = a, this.notifySubscribers(a));
321
+ oe(this.state, a) || (this.state = a, this.notifySubscribers(a));
322
322
  }, this.setPartial = (a) => {
323
323
  if (a == null) return;
324
324
  const o = { ...this.state, ...a };
@@ -329,8 +329,8 @@ class S {
329
329
  Array.from(this.subscribers).forEach((r) => {
330
330
  try {
331
331
  r(a);
332
- } catch (l) {
333
- g.error("state subscriber threw", l);
332
+ } catch (c) {
333
+ k.error("state subscriber threw", c);
334
334
  }
335
335
  });
336
336
  }, this.subscribe = (a) => (this.subscribers.add(a), () => {
@@ -338,7 +338,7 @@ class S {
338
338
  }), this.state = e, this.initialState = e;
339
339
  }
340
340
  }
341
- class Z {
341
+ class W {
342
342
  constructor() {
343
343
  this.state = new S({
344
344
  isPolling: !1,
@@ -352,10 +352,10 @@ class Z {
352
352
  this.abortController = new AbortController(), this.state.setPartial({ isPolling: !0 });
353
353
  try {
354
354
  await e(this.abortController.signal);
355
- } catch (l) {
355
+ } catch (c) {
356
356
  if (this.abortController.signal.aborted)
357
357
  return;
358
- g.error("failed to poll", l), this.state.setPartial({ isError: !0 });
358
+ k.error("failed to poll", c), this.state.setPartial({ isError: !0 });
359
359
  } finally {
360
360
  this.state.setPartial({ isPolling: !1 });
361
361
  }
@@ -367,7 +367,7 @@ class Z {
367
367
  };
368
368
  }
369
369
  }
370
- function W(i) {
370
+ function $(i) {
371
371
  try {
372
372
  const e = i();
373
373
  return e instanceof Promise ? e.then((a) => ({ data: a })).catch((a) => ({ error: a })) : { data: e };
@@ -375,15 +375,15 @@ function W(i) {
375
375
  return { error: e };
376
376
  }
377
377
  }
378
- class me {
378
+ class he {
379
379
  constructor({
380
380
  api: e,
381
381
  config: a,
382
382
  sessionCtx: o,
383
383
  messageCtx: r,
384
- sessionPollingIntervalSeconds: l
384
+ sessionPollingIntervalSeconds: c
385
385
  }) {
386
- this.poller = new Z(), this.fetchSessionAndFullHistoryAbortController = new AbortController(), this.reconcileAbortController = new AbortController(), this.subscriptions = [], this.reconcilingSessionId = null, this.registerPolling = () => {
386
+ this.poller = new W(), this.fetchSessionAndFullHistoryAbortController = new AbortController(), this.reconcileAbortController = new AbortController(), this.subscriptions = [], this.reconcilingSessionId = null, this.registerPolling = () => {
387
387
  this.subscriptions.push(
388
388
  this.sessionCtx.sessionState.subscribe(({ session: s }) => {
389
389
  s != null && s.id ? this.poller.startPolling(async (t) => {
@@ -402,7 +402,7 @@ class me {
402
402
  abortSignal: this.fetchSessionAndFullHistoryAbortController.signal
403
403
  });
404
404
  } catch (t) {
405
- this.fetchSessionAndFullHistoryAbortController.signal.aborted || g.error("failed to fetch session and full history", t);
405
+ this.fetchSessionAndFullHistoryAbortController.signal.aborted || k.error("failed to fetch session and full history", t);
406
406
  }
407
407
  else
408
408
  this.fetchSessionAndFullHistoryAbortController.abort();
@@ -431,12 +431,13 @@ class me {
431
431
  }) => {
432
432
  const n = this.messageCtx.state.get().messages.length === 0;
433
433
  n && this.messageCtx.state.setPartial({ isInitialFetchLoading: !0 });
434
- const { data: c } = await this.api.pollSessionAndHistory({
434
+ const { data: l } = await this.api.pollSessionAndHistory({
435
435
  sessionId: s,
436
436
  abortSignal: t
437
437
  });
438
- if (c != null && c.session && (this.sessionCtx.sessionState.setPartial({ session: c.session }), this.sessionCtx.setSessions([c.session])), c != null && c.history && c.history.length > 0) {
439
- const d = this.messageCtx.state.get().messages, _ = c.history.map(this.mapHistoryToMessage).filter((p) => p !== null).filter(
438
+ if (l != null && l.session && (this.sessionCtx.sessionState.setPartial({ session: l.session }), this.sessionCtx.setSessions([l.session])), l != null && l.history && l.history.length > 0) {
439
+ this.reconcileOptionPicks(l.history);
440
+ const d = this.messageCtx.state.get().messages, _ = l.history.map(this.mapHistoryToMessage).filter((p) => p !== null).filter(
440
441
  (p) => !d.some((u) => u.id === p.id)
441
442
  );
442
443
  if (_.length > 0)
@@ -451,6 +452,12 @@ class me {
451
452
  this.messageCtx.dispatchToOnMessageReceivedHook(p);
452
453
  }
453
454
  this.messageCtx.state.get().isInitialFetchLoading && this.messageCtx.state.setPartial({ isInitialFetchLoading: !1 });
455
+ }, this.reconcileOptionPicks = (s) => {
456
+ var t;
457
+ for (const n of s) {
458
+ const l = (t = n.messageOptions) == null ? void 0 : t.pickedOptionId;
459
+ l && this.messageCtx.setMessageOptionPick(n.publicId, l);
460
+ }
454
461
  }, this.mapHistoryToMessage = (s) => {
455
462
  var n;
456
463
  const t = {
@@ -484,10 +491,11 @@ class me {
484
491
  id: null,
485
492
  isAi: !1
486
493
  },
487
- ...this.constructReplyTo(s)
494
+ ...this.constructReplyTo(s),
495
+ ...s.messageOptions ? { messageOptions: s.messageOptions } : {}
488
496
  };
489
497
  if (s.sender.kind === "ai") {
490
- const c = s.actionCalls && s.actionCalls.length > 0 ? s.actionCalls[s.actionCalls.length - 1] : void 0;
498
+ const l = s.actionCalls && s.actionCalls.length > 0 ? s.actionCalls[s.actionCalls.length - 1] : void 0;
491
499
  return {
492
500
  ...t,
493
501
  type: "AI",
@@ -502,27 +510,27 @@ class me {
502
510
  },
503
511
  data: {
504
512
  message: s.content.text || "",
505
- action: c ? {
506
- name: c.actionName,
507
- data: this.extractActionResult(c)
513
+ action: l ? {
514
+ name: l.actionName,
515
+ data: this.extractActionResult(l)
508
516
  } : void 0
509
517
  },
510
518
  ...this.constructReplyTo(s)
511
519
  };
512
520
  }
513
521
  if (s.sender.kind === "system") {
514
- const c = this.constructSystemMessage(s);
515
- return c === null ? null : { ...c };
522
+ const l = this.constructSystemMessage(s);
523
+ return l === null ? null : { ...l };
516
524
  }
517
525
  return null;
518
526
  }, this.constructReplyTo = (s) => {
519
527
  if (!s.replyTo) return {};
520
- const { publicId: t, text: n, sender: c } = s.replyTo;
528
+ const { publicId: t, text: n, sender: l } = s.replyTo;
521
529
  return {
522
530
  replyTo: {
523
531
  id: t,
524
532
  text: n,
525
- sender: c
533
+ sender: l
526
534
  }
527
535
  };
528
536
  }, this.constructSystemMessage = (s) => {
@@ -563,7 +571,7 @@ class me {
563
571
  case "none":
564
572
  return null;
565
573
  default:
566
- return ue(
574
+ return me(
567
575
  s.systemMessagePayload,
568
576
  this.constructSystemMessage.name
569
577
  ), null;
@@ -572,14 +580,14 @@ class me {
572
580
  const t = s.result;
573
581
  if (t === null || typeof t != "object") return t;
574
582
  if ("responseBodyText" in t && typeof t.responseBodyText == "string") {
575
- const n = t.responseBodyText, c = W(() => JSON.parse(n)).data;
576
- if (c) return c;
583
+ const n = t.responseBodyText, l = $(() => JSON.parse(n)).data;
584
+ if (l) return l;
577
585
  }
578
586
  return s.result;
579
- }, this.api = e, this.config = a, this.sessionCtx = o, this.messageCtx = r, this.sessionPollingIntervalSeconds = l, this.registerPolling();
587
+ }, this.api = e, this.config = a, this.sessionCtx = o, this.messageCtx = r, this.sessionPollingIntervalSeconds = c, this.registerPolling();
580
588
  }
581
589
  }
582
- class he {
590
+ class ge {
583
591
  constructor({
584
592
  config: e,
585
593
  api: a,
@@ -587,15 +595,15 @@ class he {
587
595
  }) {
588
596
  var r;
589
597
  this.shouldCollectData = () => {
590
- var l;
591
- return !!(!((l = this.state.get().contact) != null && l.token) && this.config.collectUserData);
598
+ var c;
599
+ return !!(!((c = this.state.get().contact) != null && c.token) && this.config.collectUserData);
592
600
  }, this.autoCreateUnverifiedUserIfNotExists = async () => {
593
- var l, s, t, n, c, d, _, p, u, h, k, v, f, b;
594
- if (!((l = this.config.user) != null && l.token)) {
601
+ var c, s, t, n, l, d, _, p, u, m, g, b, f, v;
602
+ if (!((c = this.config.user) != null && c.token)) {
595
603
  if (this.config.collectUserData && !((t = (s = this.config.user) == null ? void 0 : s.data) != null && t.email)) {
596
604
  if ((n = this.config.extraDataCollectionFields) != null && n.length)
597
605
  return;
598
- const y = await ((c = this.storageCtx) == null ? void 0 : c.getContactToken());
606
+ const y = await ((l = this.storageCtx) == null ? void 0 : l.getContactToken());
599
607
  y && await this.setUnverifiedContact(y);
600
608
  return;
601
609
  }
@@ -607,47 +615,47 @@ class he {
607
615
  }
608
616
  }
609
617
  await this.createUnverifiedContact({
610
- email: (h = (u = this.config.user) == null ? void 0 : u.data) == null ? void 0 : h.email,
611
- non_verified_name: (v = (k = this.config.user) == null ? void 0 : k.data) == null ? void 0 : v.name,
612
- non_verified_custom_data: (b = (f = this.config.user) == null ? void 0 : f.data) == null ? void 0 : b.customData
618
+ email: (m = (u = this.config.user) == null ? void 0 : u.data) == null ? void 0 : m.email,
619
+ non_verified_name: (b = (g = this.config.user) == null ? void 0 : g.data) == null ? void 0 : b.name,
620
+ non_verified_custom_data: (v = (f = this.config.user) == null ? void 0 : f.data) == null ? void 0 : v.customData
613
621
  });
614
622
  }
615
- }, this.createUnverifiedContact = async (l, s) => {
623
+ }, this.createUnverifiedContact = async (c, s) => {
616
624
  this.state.setPartial({ extraCollectedData: s });
617
625
  try {
618
626
  this.state.setPartial({
619
627
  isCreatingUnverifiedContact: !0,
620
628
  isErrorCreatingUnverifiedContact: !1
621
629
  });
622
- const { data: t } = await this.api.createUnverifiedContact(l);
630
+ const { data: t } = await this.api.createUnverifiedContact(c);
623
631
  t != null && t.token ? await this.setUnverifiedContact(t.token) : this.state.setPartial({ isErrorCreatingUnverifiedContact: !0 });
624
632
  } catch (t) {
625
- this.state.setPartial({ isErrorCreatingUnverifiedContact: !0 }), g.error("failed to create an unverified contact", {
633
+ this.state.setPartial({ isErrorCreatingUnverifiedContact: !0 }), k.error("failed to create an unverified contact", {
626
634
  _e: t instanceof Error ? t.message : String(t)
627
635
  });
628
636
  } finally {
629
637
  this.state.setPartial({ isCreatingUnverifiedContact: !1 });
630
638
  }
631
639
  }, this.recoverFromStaleToken = async () => {
632
- var l, s, t, n, c, d, _, p, u, h;
633
- if ((l = this.config.user) != null && l.token) return !1;
640
+ var c, s, t, n, l, d, _, p, u, m;
641
+ if ((c = this.config.user) != null && c.token) return !1;
634
642
  this.api.setAuthToken(""), this.state.setPartial({ contact: null });
635
643
  try {
636
644
  await ((s = this.storageCtx) == null ? void 0 : s.clearContactToken()), await ((t = this.storageCtx) == null ? void 0 : t.clearActiveSessionId());
637
- } catch (k) {
638
- g.warn("failed to clear a stale contact token", {
639
- error: k instanceof Error ? k.message : String(k)
645
+ } catch (g) {
646
+ k.warn("failed to clear a stale contact token", {
647
+ error: g instanceof Error ? g.message : String(g)
640
648
  });
641
649
  }
642
650
  return await this.createUnverifiedContact({
643
- email: (c = (n = this.config.user) == null ? void 0 : n.data) == null ? void 0 : c.email,
651
+ email: (l = (n = this.config.user) == null ? void 0 : n.data) == null ? void 0 : l.email,
644
652
  non_verified_name: (_ = (d = this.config.user) == null ? void 0 : d.data) == null ? void 0 : _.name,
645
653
  non_verified_custom_data: (u = (p = this.config.user) == null ? void 0 : p.data) == null ? void 0 : u.customData
646
- }), !!((h = this.state.get().contact) != null && h.token);
647
- }, this.setUnverifiedContact = async (l) => {
648
- var n, c, d, _;
649
- const s = await ((n = this.storageCtx) == null ? void 0 : n.getExternalContactId()), t = ((c = this.config.user) == null ? void 0 : c.externalId) || s || N();
650
- this.api.setAuthToken(l), await ((d = this.storageCtx) == null ? void 0 : d.setContactToken(l)), await ((_ = this.storageCtx) == null ? void 0 : _.setExternalContactId(t)), this.state.setPartial({ contact: { token: l, externalId: t } });
654
+ }), !!((m = this.state.get().contact) != null && m.token);
655
+ }, this.setUnverifiedContact = async (c) => {
656
+ var n, l, d, _;
657
+ const s = await ((n = this.storageCtx) == null ? void 0 : n.getExternalContactId()), t = ((l = this.config.user) == null ? void 0 : l.externalId) || s || N();
658
+ this.api.setAuthToken(c), await ((d = this.storageCtx) == null ? void 0 : d.setContactToken(c)), await ((_ = this.storageCtx) == null ? void 0 : _.setExternalContactId(t)), this.state.setPartial({ contact: { token: c, externalId: t } });
651
659
  }, this.config = e, this.storageCtx = o, this.api = a, this.state = new S({
652
660
  contact: (r = e.user) != null && r.token ? {
653
661
  token: e.user.token,
@@ -660,7 +668,7 @@ class he {
660
668
  }), this.autoCreateUnverifiedUserIfNotExists();
661
669
  }
662
670
  }
663
- class ge {
671
+ class ke {
664
672
  constructor(e) {
665
673
  this.api = e, this.state = new S([]), this.controllers = /* @__PURE__ */ new Map(), this.appendFiles = (a) => {
666
674
  const o = a.map(
@@ -712,16 +720,16 @@ class ge {
712
720
  function q() {
713
721
  return N();
714
722
  }
715
- class ke {
723
+ class be {
716
724
  constructor({
717
725
  api: e,
718
726
  sessionCtx: a,
719
727
  messageCtx: o
720
728
  }) {
721
729
  this.submitCsat = async (r) => {
722
- var c;
723
- const l = (c = this.sessionCtx.sessionState.get().session) == null ? void 0 : c.id;
724
- if (!l)
730
+ var l;
731
+ const c = (l = this.sessionCtx.sessionState.get().session) == null ? void 0 : l.id;
732
+ if (!c)
725
733
  return { data: null, error: "No session id found" };
726
734
  const s = q();
727
735
  this.messageCtx.state.setPartial({
@@ -744,13 +752,13 @@ class ke {
744
752
  const { data: t, error: n } = await this.api.submitCsat({
745
753
  ...r,
746
754
  system_message_uuid: s,
747
- session_id: l
755
+ session_id: c
748
756
  });
749
757
  return { data: t, error: n };
750
758
  }, this.api = e, this.sessionCtx = a, this.messageCtx = o;
751
759
  }
752
760
  }
753
- const be = [
761
+ const ve = [
754
762
  {
755
763
  action: "newparagraph",
756
764
  phrases: {
@@ -825,7 +833,7 @@ const be = [
825
833
  it: ["invia messaggio"]
826
834
  }
827
835
  }
828
- ], ve = [
836
+ ], fe = [
829
837
  "en",
830
838
  "es",
831
839
  "fr",
@@ -833,18 +841,18 @@ const be = [
833
841
  "pt",
834
842
  "it"
835
843
  ];
836
- function fe(i) {
837
- return ve.includes(i);
838
- }
839
844
  function ye(i) {
840
- return i.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
845
+ return fe.includes(i);
841
846
  }
842
847
  function we(i) {
843
- const e = be.flatMap(
848
+ return i.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
849
+ }
850
+ function je(i) {
851
+ const e = ve.flatMap(
844
852
  (r) => i.flatMap(
845
- (l) => r.phrases[l].map((s) => ({ phrase: s, action: r.action }))
853
+ (c) => r.phrases[c].map((s) => ({ phrase: s, action: r.action }))
846
854
  )
847
- ), a = e.map((r) => ye(r.phrase)).sort((r, l) => l.length - r.length).join("|"), o = String.raw`(?<=^\s{0,3}|[.!?\n]\s{0,3})`;
855
+ ), a = e.map((r) => we(r.phrase)).sort((r, c) => c.length - r.length).join("|"), o = String.raw`(?<=^\s{0,3}|[.!?\n]\s{0,3})`;
848
856
  return {
849
857
  regex: new RegExp(
850
858
  `${o}(${a})` + String.raw`([.,!?;:])(?=\s|$)`,
@@ -862,18 +870,18 @@ function we(i) {
862
870
  }
863
871
  const B = /* @__PURE__ */ new Map();
864
872
  function M(i) {
865
- const e = i && fe(i) && i !== "en" ? i : null, a = e ?? "en";
873
+ const e = i && ye(i) && i !== "en" ? i : null, a = e ?? "en";
866
874
  let o = B.get(a);
867
- return o || (o = we(e ? ["en", e] : ["en"]), B.set(a, o)), o;
875
+ return o || (o = je(e ? ["en", e] : ["en"]), B.set(a, o)), o;
868
876
  }
869
- function je(i) {
877
+ function Se(i) {
870
878
  const e = i.replace(/\s+$/, "");
871
879
  if (!e) return "";
872
880
  const a = e.replace(/[.!?]+$/, "");
873
881
  let o = -1;
874
882
  for (let r = a.length - 1; r >= 0; r--) {
875
- const l = a[r];
876
- if (l === "." || l === "!" || l === "?" || l === `
883
+ const c = a[r];
884
+ if (c === "." || c === "!" || c === "?" || c === `
877
885
  `) {
878
886
  o = r + 1;
879
887
  break;
@@ -882,17 +890,17 @@ function je(i) {
882
890
  return o === -1 ? "" : `${a.slice(0, o)} `.replace(/\n $/, `
883
891
  `);
884
892
  }
885
- const Se = new RegExp(
893
+ const ze = new RegExp(
886
894
  String.raw`(^- |\n(?:- )?)(\p{Ll})`,
887
895
  "gu"
888
896
  );
889
- function ze(i) {
897
+ function Ce(i) {
890
898
  return i.replace(
891
- Se,
899
+ ze,
892
900
  (e, a, o) => a + o.toUpperCase()
893
901
  );
894
902
  }
895
- function Ce(i) {
903
+ function xe(i) {
896
904
  return i.length <= 3 && /^\s*$/.test(i) ? !0 : /[.!?\n]\s{0,3}$/.test(i.slice(-6));
897
905
  }
898
906
  class E {
@@ -902,29 +910,29 @@ class E {
902
910
  * result never depends on delta chunking.
903
911
  */
904
912
  static process(e, a) {
905
- const o = M(a == null ? void 0 : a.language), r = a != null && a.final ? "" : E.commandPrefixTail(e, a == null ? void 0 : a.language), l = e.slice(0, e.length - r.length), s = a != null && a.final ? o.finalRegex : o.regex;
906
- let t = "", n = null, c = 0;
907
- for (const _ of Array.from(l.matchAll(s))) {
913
+ const o = M(a == null ? void 0 : a.language), r = a != null && a.final ? "" : E.commandPrefixTail(e, a == null ? void 0 : a.language), c = e.slice(0, e.length - r.length), s = a != null && a.final ? o.finalRegex : o.regex;
914
+ let t = "", n = null, l = 0;
915
+ for (const _ of Array.from(c.matchAll(s))) {
908
916
  const [, p = ""] = _, u = o.phraseToAction.get(p.toLowerCase());
909
917
  if (u)
910
- if (t += l.slice(c, _.index), c = _.index + _[0].length, u === "newline") t = `${t.replace(/[ \t]+$/, "")}
918
+ if (t += c.slice(l, _.index), l = _.index + _[0].length, u === "newline") t = `${t.replace(/[ \t]+$/, "")}
911
919
  `;
912
920
  else if (u === "newparagraph")
913
921
  t = `${t.replace(/[ \t]+$/, "")}
914
922
 
915
923
  `;
916
924
  else if (u === "bullet") {
917
- const h = t.replace(/[ \t]+$/, "");
918
- t = h === "" || h.endsWith(`
919
- `) ? `${h}- ` : `${h}
925
+ const m = t.replace(/[ \t]+$/, "");
926
+ t = m === "" || m.endsWith(`
927
+ `) ? `${m}- ` : `${m}
920
928
  - `;
921
- } else if (u === "scratch") t = je(t);
929
+ } else if (u === "scratch") t = Se(t);
922
930
  else {
923
931
  n = u === "send" ? "send" : "stop";
924
932
  break;
925
933
  }
926
934
  }
927
- return n === null && (t += l.slice(c)), { text: ze(
935
+ return n === null && (t += c.slice(l)), { text: Ce(
928
936
  t.replace(/^\s+/, "").replace(/[ \t]+\n/g, `
929
937
  `).replace(/\n[ \t]+/g, `
930
938
  `).replace(/(^|\n)- +/g, "$1- ").replace(/ {2,}/g, " ").replace(/\n{3,}/g, `
@@ -943,13 +951,13 @@ class E {
943
951
  */
944
952
  static commandPrefixTail(e, a) {
945
953
  const o = M(a), r = Math.min(e.length, o.longestPhrase + 2);
946
- for (let l = r; l > 0; l--) {
947
- const s = e.length - l;
948
- if (!Ce(e.slice(0, s))) continue;
954
+ for (let c = r; c > 0; c--) {
955
+ const s = e.length - c;
956
+ if (!xe(e.slice(0, s))) continue;
949
957
  const t = e.slice(s).toLowerCase(), n = t.replace(/^\s+/, "");
950
958
  if (n) {
951
- for (const c of Array.from(o.phraseToAction.keys()))
952
- if (c.startsWith(n))
959
+ for (const l of Array.from(o.phraseToAction.keys()))
960
+ if (l.startsWith(n))
953
961
  return e.slice(s + (t.length - n.length));
954
962
  }
955
963
  }
@@ -965,7 +973,7 @@ class E {
965
973
  return o ? M(a).phraseToAction.has(o) : !1;
966
974
  }
967
975
  }
968
- const xe = 55, qe = 90;
976
+ const qe = 55, Ee = 90;
969
977
  class V {
970
978
  /**
971
979
  * Next paced step toward `processed`: normally one word per tick so text
@@ -979,7 +987,7 @@ class V {
979
987
  }) {
980
988
  if (a.length <= e.length) return a;
981
989
  const o = a.length - e.length;
982
- if (o > qe)
990
+ if (o > Ee)
983
991
  return a.slice(0, e.length + Math.ceil(o / 3));
984
992
  let r = e.length;
985
993
  for (; r < a.length && /\s/.test(a.charAt(r)); ) r++;
@@ -995,8 +1003,8 @@ class V {
995
1003
  return o && /^[a-z]{2,3}$/.test(o) ? o : void 0;
996
1004
  }
997
1005
  }
998
- const Ee = 2e4;
999
- class Ae {
1006
+ const Ae = 2e4;
1007
+ class Pe {
1000
1008
  constructor() {
1001
1009
  this.cached = null, this.inflight = null;
1002
1010
  }
@@ -1004,7 +1012,7 @@ class Ae {
1004
1012
  get() {
1005
1013
  if (!this.cached) return null;
1006
1014
  const e = Date.parse(this.cached.expiresAt);
1007
- return Number.isNaN(e) || e - Date.now() < Ee ? (this.cached = null, null) : this.cached;
1015
+ return Number.isNaN(e) || e - Date.now() < Ae ? (this.cached = null, null) : this.cached;
1008
1016
  }
1009
1017
  /**
1010
1018
  * Resolve a mint, deduping concurrent requests (hover-prewarm racing a
@@ -1024,7 +1032,7 @@ class Ae {
1024
1032
  function H(i) {
1025
1033
  return typeof i == "object" && i !== null && !Array.isArray(i);
1026
1034
  }
1027
- function Pe(i) {
1035
+ function Te(i) {
1028
1036
  if (!H(i) || typeof i.type != "string") return null;
1029
1037
  const e = H(i.error) ? i.error : null;
1030
1038
  return {
@@ -1033,26 +1041,26 @@ function Pe(i) {
1033
1041
  errorMessage: e && typeof e.message == "string" ? e.message : void 0
1034
1042
  };
1035
1043
  }
1036
- const Te = "https://api.openai.com/v1/realtime/calls", Ie = 600 * 1e3, Me = 15e3, De = 5e3;
1044
+ const Ie = "https://api.openai.com/v1/realtime/calls", Me = 600 * 1e3, De = 15e3, Ne = 5e3;
1037
1045
  class T extends Error {
1038
1046
  }
1039
- class Ne {
1047
+ class Re {
1040
1048
  constructor({
1041
1049
  mintToken: e,
1042
1050
  onDelta: a,
1043
1051
  onState: o,
1044
1052
  onError: r,
1045
- onLevel: l
1053
+ onLevel: c
1046
1054
  }) {
1047
- 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 = a, this.onState = o, this.onError = r, this.onLevel = l;
1055
+ 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 = a, this.onState = o, this.onError = r, this.onLevel = c;
1048
1056
  }
1049
1057
  async start() {
1050
1058
  if (this.state === "idle") {
1051
1059
  this.setState("connecting"), this.timers.push(
1052
1060
  setTimeout(() => {
1053
1061
  this.state === "connecting" && this.fail("unavailable");
1054
- }, Me)
1055
- ), this.timers.push(setTimeout(() => this.stop(), Ie));
1062
+ }, De)
1063
+ ), this.timers.push(setTimeout(() => this.stop(), Me));
1056
1064
  try {
1057
1065
  const e = this.requestMicrophone();
1058
1066
  e.then((d) => {
@@ -1067,9 +1075,9 @@ class Ne {
1067
1075
  this.stream = a, this.startLevelMeter(a);
1068
1076
  const r = new RTCPeerConnection();
1069
1077
  this.pc = r;
1070
- const [l] = a.getAudioTracks();
1071
- if (!l) throw new T("No audio track");
1072
- r.addTrack(l, a);
1078
+ const [c] = a.getAudioTracks();
1079
+ if (!c) throw new T("No audio track");
1080
+ r.addTrack(c, a);
1073
1081
  const s = r.createDataChannel("oai-events");
1074
1082
  this.dc = s, s.addEventListener(
1075
1083
  "message",
@@ -1084,12 +1092,12 @@ class Ne {
1084
1092
  r.connectionState === "disconnected" && this.timers.push(
1085
1093
  setTimeout(() => {
1086
1094
  this.pc === r && r.connectionState !== "connected" && this.fail("unavailable");
1087
- }, De)
1095
+ }, Ne)
1088
1096
  );
1089
1097
  });
1090
1098
  const t = await r.createOffer();
1091
1099
  if (this.isTornDown() || (await r.setLocalDescription(t), this.isTornDown())) return;
1092
- const n = await fetch(Te, {
1100
+ const n = await fetch(Ie, {
1093
1101
  method: "POST",
1094
1102
  headers: {
1095
1103
  Authorization: `Bearer ${o.token}`,
@@ -1099,11 +1107,11 @@ class Ne {
1099
1107
  });
1100
1108
  if (!n.ok)
1101
1109
  throw new Error(`Realtime handshake failed (${n.status})`);
1102
- const c = await n.text();
1110
+ const l = await n.text();
1103
1111
  if (this.isTornDown()) return;
1104
- await r.setRemoteDescription({ type: "answer", sdp: c });
1112
+ await r.setRemoteDescription({ type: "answer", sdp: l });
1105
1113
  } catch (e) {
1106
- e instanceof T ? this.fail("microphone") : (g.error("dictation session failed to start", {
1114
+ e instanceof T ? this.fail("microphone") : (k.error("dictation session failed to start", {
1107
1115
  _e: e instanceof Error ? e.message : String(e)
1108
1116
  }), this.fail("unavailable"));
1109
1117
  }
@@ -1136,23 +1144,23 @@ class Ne {
1136
1144
  try {
1137
1145
  a = JSON.parse(e);
1138
1146
  } catch {
1139
- this.loggedParseFailure || (this.loggedParseFailure = !0, g.error("dictation server event was not valid JSON", {
1147
+ this.loggedParseFailure || (this.loggedParseFailure = !0, k.error("dictation server event was not valid JSON", {
1140
1148
  snippet: e.slice(0, 120)
1141
1149
  }));
1142
1150
  return;
1143
1151
  }
1144
- const o = Pe(a);
1152
+ const o = Te(a);
1145
1153
  if (!o) return;
1146
- const { type: r, delta: l } = o;
1154
+ const { type: r, delta: c } = o;
1147
1155
  if (r === "session.created" || r === "transcription_session.created") {
1148
1156
  this.setState("listening");
1149
1157
  return;
1150
1158
  }
1151
- if (r === "conversation.item.input_audio_transcription.delta" && l) {
1152
- this.state === "connecting" && this.setState("listening"), this.onDelta(l);
1159
+ if (r === "conversation.item.input_audio_transcription.delta" && c) {
1160
+ this.state === "connecting" && this.setState("listening"), this.onDelta(c);
1153
1161
  return;
1154
1162
  }
1155
- r === "error" && (g.error("dictation server event error", {
1163
+ r === "error" && (k.error("dictation server event error", {
1156
1164
  _e: o.errorMessage ?? "unknown"
1157
1165
  }), this.fail("unavailable"));
1158
1166
  }
@@ -1163,20 +1171,20 @@ class Ne {
1163
1171
  this.audioContext = a;
1164
1172
  const o = a.createMediaStreamSource(e), r = a.createAnalyser();
1165
1173
  r.fftSize = 512, o.connect(r);
1166
- const l = new Uint8Array(r.frequencyBinCount), s = () => {
1167
- var c;
1168
- r.getByteTimeDomainData(l);
1174
+ const c = new Uint8Array(r.frequencyBinCount), s = () => {
1175
+ var l;
1176
+ r.getByteTimeDomainData(c);
1169
1177
  let t = 0;
1170
- for (let d = 0; d < l.length; d++) {
1171
- const _ = ((l[d] ?? 128) - 128) / 128;
1178
+ for (let d = 0; d < c.length; d++) {
1179
+ const _ = ((c[d] ?? 128) - 128) / 128;
1172
1180
  t += _ * _;
1173
1181
  }
1174
- const n = Math.sqrt(t / l.length);
1175
- (c = this.onLevel) == null || c.call(this, Math.min(1, n * 4)), this.levelRaf = requestAnimationFrame(s);
1182
+ const n = Math.sqrt(t / c.length);
1183
+ (l = this.onLevel) == null || l.call(this, Math.min(1, n * 4)), this.levelRaf = requestAnimationFrame(s);
1176
1184
  };
1177
1185
  this.levelRaf = requestAnimationFrame(s);
1178
1186
  } catch (a) {
1179
- g.error("dictation level meter unavailable", {
1187
+ k.error("dictation level meter unavailable", {
1180
1188
  _e: a instanceof Error ? a.message : String(a)
1181
1189
  });
1182
1190
  }
@@ -1189,9 +1197,9 @@ class Ne {
1189
1197
  }
1190
1198
  teardown() {
1191
1199
  var e, a, o, r;
1192
- this.timers.forEach((l) => clearTimeout(l)), this.timers = [], this.levelRaf && cancelAnimationFrame(this.levelRaf), this.levelRaf = 0, (e = this.dc) == null || e.close(), this.dc = null, (a = this.pc) == null || a.close(), this.pc = null, (o = this.stream) == null || o.getTracks().forEach((l) => l.stop()), this.stream = null, (r = this.audioContext) == null || r.close().catch((l) => {
1193
- g.error("failed to close dictation audio context", {
1194
- _e: String(l)
1200
+ this.timers.forEach((c) => clearTimeout(c)), this.timers = [], this.levelRaf && cancelAnimationFrame(this.levelRaf), this.levelRaf = 0, (e = this.dc) == null || e.close(), this.dc = null, (a = this.pc) == null || a.close(), this.pc = null, (o = this.stream) == null || o.getTracks().forEach((c) => c.stop()), this.stream = null, (r = this.audioContext) == null || r.close().catch((c) => {
1201
+ k.error("failed to close dictation audio context", {
1202
+ _e: String(c)
1195
1203
  });
1196
1204
  }), this.audioContext = null;
1197
1205
  }
@@ -1199,12 +1207,12 @@ class Ne {
1199
1207
  this.state !== e && (this.state = e, this.onState(e));
1200
1208
  }
1201
1209
  }
1202
- const Re = 1300, Ke = { status: "idle", error: null };
1203
- class Le {
1210
+ const Ke = 1300, Le = { status: "idle", error: null };
1211
+ class Oe {
1204
1212
  constructor({ api: e, config: a }) {
1205
- this.state = new S(Ke), this.levelRef = { current: 0 }, this.mintCache = new Ae(), 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 = () => {
1213
+ this.state = new S(Le), this.levelRef = { current: 0 }, this.mintCache = new Pe(), 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 = () => {
1206
1214
  this.mintToken().catch((o) => {
1207
- this.mintCache.clear(), g.error("dictation token prewarm failed", {
1215
+ this.mintCache.clear(), k.error("dictation token prewarm failed", {
1208
1216
  _e: o instanceof Error ? o.message : String(o)
1209
1217
  });
1210
1218
  });
@@ -1212,24 +1220,24 @@ class Le {
1212
1220
  this.session && this.teardown(), this.target = o, this.language = V.languageHint(
1213
1221
  this.config.language ?? navigator.language
1214
1222
  ), this.prefix = o.getValue(), this.raw = "", this.processed = "", this.displayed = "";
1215
- const r = new Ne({
1223
+ const r = new Re({
1216
1224
  mintToken: this.mintToken,
1217
- onLevel: (l) => {
1218
- this.levelRef.current = l;
1225
+ onLevel: (c) => {
1226
+ this.levelRef.current = c;
1219
1227
  },
1220
- onState: (l) => {
1221
- r === this.session && (l === "connecting" && this.state.set({ status: "connecting", error: null }), l === "listening" && this.state.set({ status: "listening", error: null }), l === "stopped" && this.teardown());
1228
+ onState: (c) => {
1229
+ r === this.session && (c === "connecting" && this.state.set({ status: "connecting", error: null }), c === "listening" && this.state.set({ status: "listening", error: null }), c === "stopped" && this.teardown());
1222
1230
  },
1223
- onError: (l) => {
1224
- r === this.session && (this.mintCache.clear(), this.teardown({ error: l, executeFinalCommand: !1 }));
1231
+ onError: (c) => {
1232
+ r === this.session && (this.mintCache.clear(), this.teardown({ error: c, executeFinalCommand: !1 }));
1225
1233
  },
1226
- onDelta: (l) => {
1234
+ onDelta: (c) => {
1227
1235
  if (r !== this.session || !this.target) return;
1228
1236
  if (!this.isConsistent()) {
1229
1237
  this.teardown();
1230
1238
  return;
1231
1239
  }
1232
- this.raw += l;
1240
+ this.raw += c;
1233
1241
  const s = this.ingest();
1234
1242
  if (s === "stop") {
1235
1243
  this.teardown();
@@ -1247,7 +1255,7 @@ class Le {
1247
1255
  this.raw = `${this.raw}.`;
1248
1256
  const t = this.ingest();
1249
1257
  t === "stop" ? this.teardown() : t === "send" && this.teardown({ send: !0 });
1250
- }, Re));
1258
+ }, Ke));
1251
1259
  }
1252
1260
  });
1253
1261
  this.session = r, this.state.set({ status: "connecting", error: null }), this.dripTimer = setInterval(() => {
@@ -1263,7 +1271,7 @@ class Le {
1263
1271
  })
1264
1272
  );
1265
1273
  }
1266
- }, xe), r.start();
1274
+ }, qe), r.start();
1267
1275
  }, this.stop = (o) => {
1268
1276
  this.session && this.teardown(o);
1269
1277
  }, this.mintToken = async () => this.mintCache.resolve(
@@ -1290,7 +1298,7 @@ class Le {
1290
1298
  this.silenceTimer && clearTimeout(this.silenceTimer), this.silenceTimer = null;
1291
1299
  }
1292
1300
  teardown(e) {
1293
- var l;
1301
+ var c;
1294
1302
  const a = this.session, o = this.target;
1295
1303
  this.dripTimer && clearInterval(this.dripTimer), this.dripTimer = null, this.stopSilenceTimer();
1296
1304
  let r = (e == null ? void 0 : e.send) ?? !1;
@@ -1298,7 +1306,7 @@ class Le {
1298
1306
  const s = this.ingest({ final: !0 });
1299
1307
  (e == null ? void 0 : e.executeFinalCommand) !== !1 && s === "send" && (r = !0), this.processed !== this.displayed && this.applyDisplayed(this.processed);
1300
1308
  }
1301
- this.session = null, this.target = null, a == null || a.stop(), this.levelRef.current = 0, this.state.set({ status: "idle", error: (e == null ? void 0 : e.error) ?? null }), r && ((l = o == null ? void 0 : o.onSend) == null || l.call(o));
1309
+ this.session = null, this.target = null, a == null || a.stop(), this.levelRef.current = 0, this.state.set({ status: "idle", error: (e == null ? void 0 : e.error) ?? null }), r && ((c = o == null ? void 0 : o.onSend) == null || c.call(o));
1302
1310
  }
1303
1311
  }
1304
1312
  const Fe = {
@@ -1410,7 +1418,7 @@ const Fe = {
1410
1418
  zoom_out: "تصغير",
1411
1419
  reset_zoom: "إعادة تعيين التكبير",
1412
1420
  support_chat_aria_label: "دردشة الدعم"
1413
- }, Oe = {
1421
+ }, Ue = {
1414
1422
  write_a_message_placeholder: "একটি বার্তা লিখুন...",
1415
1423
  your_issue_has_been_resolved: "আপনার সমস্যা সমাধান হয়েছে!",
1416
1424
  new_conversation: "নতুন কথোপকথন",
@@ -1507,7 +1515,7 @@ const Fe = {
1507
1515
  zoom_out: "ছোট করুন",
1508
1516
  reset_zoom: "জুম রিসেট করুন",
1509
1517
  support_chat_aria_label: "সাপোর্ট চ্যাট"
1510
- }, Ue = {
1518
+ }, Be = {
1511
1519
  write_a_message_placeholder: "Напишете съобщение...",
1512
1520
  your_issue_has_been_resolved: "Вашият проблем е разрешен!",
1513
1521
  new_conversation: "Нов разговор",
@@ -1604,7 +1612,7 @@ const Fe = {
1604
1612
  zoom_out: "Намаляване",
1605
1613
  reset_zoom: "Нулиране на мащаба",
1606
1614
  support_chat_aria_label: "Чат за поддръжка"
1607
- }, Be = {
1615
+ }, Ve = {
1608
1616
  write_a_message_placeholder: "Napište zprávu...",
1609
1617
  your_issue_has_been_resolved: "Váš problém byl vyřešen!",
1610
1618
  new_conversation: "Nová konverzace",
@@ -1701,7 +1709,7 @@ const Fe = {
1701
1709
  zoom_out: "Oddálit",
1702
1710
  reset_zoom: "Obnovit přiblížení",
1703
1711
  support_chat_aria_label: "Chat podpory"
1704
- }, Ve = {
1712
+ }, He = {
1705
1713
  write_a_message_placeholder: "Skriv en besked...",
1706
1714
  your_issue_has_been_resolved: "Dit problem er løst!",
1707
1715
  new_conversation: "Ny samtale",
@@ -1798,7 +1806,7 @@ const Fe = {
1798
1806
  zoom_out: "Zoom ud",
1799
1807
  reset_zoom: "Nulstil zoom",
1800
1808
  support_chat_aria_label: "Supportchat"
1801
- }, He = {
1809
+ }, Ge = {
1802
1810
  write_a_message_placeholder: "Γράψτε ένα μήνυμα...",
1803
1811
  your_issue_has_been_resolved: "Το πρόβλημά σας επιλύθηκε!",
1804
1812
  new_conversation: "Νέα συνομιλία",
@@ -1895,7 +1903,7 @@ const Fe = {
1895
1903
  zoom_out: "Σμίκρυνση",
1896
1904
  reset_zoom: "Επαναφορά ζουμ",
1897
1905
  support_chat_aria_label: "Συνομιλία υποστήριξης"
1898
- }, Ge = {
1906
+ }, Ze = {
1899
1907
  write_a_message_placeholder: "Nachricht schreiben...",
1900
1908
  your_issue_has_been_resolved: "Ihr Problem wurde gelöst!",
1901
1909
  new_conversation: "Neue Konversation",
@@ -1992,7 +2000,7 @@ const Fe = {
1992
2000
  zoom_out: "Verkleinern",
1993
2001
  reset_zoom: "Zoom zurücksetzen",
1994
2002
  support_chat_aria_label: "Support-Chat"
1995
- }, $ = {
2003
+ }, J = {
1996
2004
  write_a_message_placeholder: "Write a message...",
1997
2005
  your_issue_has_been_resolved: "Your issue has been resolved!",
1998
2006
  new_conversation: "New conversation",
@@ -2101,7 +2109,7 @@ const Fe = {
2101
2109
  zoom_out: "Zoom out",
2102
2110
  reset_zoom: "Reset zoom",
2103
2111
  support_chat_aria_label: "Support chat"
2104
- }, Ze = {
2112
+ }, We = {
2105
2113
  write_a_message_placeholder: "Escribe un mensaje...",
2106
2114
  your_issue_has_been_resolved: "¡Tu problema fue resuelto!",
2107
2115
  new_conversation: "Nueva conversación",
@@ -2198,7 +2206,7 @@ const Fe = {
2198
2206
  zoom_out: "Alejar",
2199
2207
  reset_zoom: "Restablecer zoom",
2200
2208
  support_chat_aria_label: "Chat de soporte"
2201
- }, We = {
2209
+ }, $e = {
2202
2210
  write_a_message_placeholder: "Magsulat ng mensahe...",
2203
2211
  your_issue_has_been_resolved: "Nalutas na ang iyong isyu!",
2204
2212
  new_conversation: "Bagong usapan",
@@ -2295,7 +2303,7 @@ const Fe = {
2295
2303
  zoom_out: "Paliitin",
2296
2304
  reset_zoom: "I-reset ang zoom",
2297
2305
  support_chat_aria_label: "Chat ng suporta"
2298
- }, $e = {
2306
+ }, Je = {
2299
2307
  write_a_message_placeholder: "Kirjoita viesti...",
2300
2308
  your_issue_has_been_resolved: "Ongelmasi on ratkaistu!",
2301
2309
  new_conversation: "Uusi keskustelu",
@@ -2392,7 +2400,7 @@ const Fe = {
2392
2400
  zoom_out: "Loitonna",
2393
2401
  reset_zoom: "Palauta zoomaus",
2394
2402
  support_chat_aria_label: "Tukichat"
2395
- }, Je = {
2403
+ }, Ye = {
2396
2404
  write_a_message_placeholder: "Écrivez un message...",
2397
2405
  your_issue_has_been_resolved: "Votre problème a été résolu !",
2398
2406
  new_conversation: "Nouvelle conversation",
@@ -2489,7 +2497,7 @@ const Fe = {
2489
2497
  zoom_out: "Zoom arrière",
2490
2498
  reset_zoom: "Réinitialiser le zoom",
2491
2499
  support_chat_aria_label: "Chat de support"
2492
- }, Ye = {
2500
+ }, Xe = {
2493
2501
  write_a_message_placeholder: "एक संदेश लिखें...",
2494
2502
  your_issue_has_been_resolved: "आपकी समस्या हल हो गई है!",
2495
2503
  new_conversation: "नई बातचीत",
@@ -2586,7 +2594,7 @@ const Fe = {
2586
2594
  zoom_out: "ज़ूम आउट",
2587
2595
  reset_zoom: "ज़ूम रीसेट करें",
2588
2596
  support_chat_aria_label: "सहायता चैट"
2589
- }, Xe = {
2597
+ }, Qe = {
2590
2598
  write_a_message_placeholder: "Scrivi un messaggio...",
2591
2599
  your_issue_has_been_resolved: "Il tuo problema è stato risolto!",
2592
2600
  new_conversation: "Nuova conversazione",
@@ -2683,7 +2691,7 @@ const Fe = {
2683
2691
  zoom_out: "Riduci",
2684
2692
  reset_zoom: "Reimposta zoom",
2685
2693
  support_chat_aria_label: "Chat di supporto"
2686
- }, Qe = {
2694
+ }, ea = {
2687
2695
  write_a_message_placeholder: "メッセージを入力...",
2688
2696
  your_issue_has_been_resolved: "問題が解決しました!",
2689
2697
  new_conversation: "新しい会話",
@@ -2780,7 +2788,7 @@ const Fe = {
2780
2788
  zoom_out: "縮小",
2781
2789
  reset_zoom: "ズームをリセット",
2782
2790
  support_chat_aria_label: "サポートチャット"
2783
- }, ea = {
2791
+ }, aa = {
2784
2792
  write_a_message_placeholder: "메시지를 입력하세요...",
2785
2793
  your_issue_has_been_resolved: "문제가 해결되었습니다!",
2786
2794
  new_conversation: "새 대화",
@@ -2877,7 +2885,7 @@ const Fe = {
2877
2885
  zoom_out: "축소",
2878
2886
  reset_zoom: "확대/축소 초기화",
2879
2887
  support_chat_aria_label: "고객 지원 채팅"
2880
- }, aa = {
2888
+ }, ta = {
2881
2889
  write_a_message_placeholder: "Schrijf een bericht...",
2882
2890
  your_issue_has_been_resolved: "Uw probleem is opgelost!",
2883
2891
  new_conversation: "Nieuw gesprek",
@@ -2974,7 +2982,7 @@ const Fe = {
2974
2982
  zoom_out: "Uitzoomen",
2975
2983
  reset_zoom: "Zoom herstellen",
2976
2984
  support_chat_aria_label: "Supportchat"
2977
- }, ta = {
2985
+ }, sa = {
2978
2986
  write_a_message_placeholder: "Skriv en melding...",
2979
2987
  your_issue_has_been_resolved: "Problemet ditt er løst!",
2980
2988
  new_conversation: "Ny samtale",
@@ -3071,7 +3079,7 @@ const Fe = {
3071
3079
  zoom_out: "Zoom ut",
3072
3080
  reset_zoom: "Tilbakestill zoom",
3073
3081
  support_chat_aria_label: "Support-chat"
3074
- }, sa = {
3082
+ }, oa = {
3075
3083
  write_a_message_placeholder: "Napisz wiadomość...",
3076
3084
  your_issue_has_been_resolved: "Twój problem został rozwiązany!",
3077
3085
  new_conversation: "Nowa rozmowa",
@@ -3168,7 +3176,7 @@ const Fe = {
3168
3176
  zoom_out: "Pomniejsz",
3169
3177
  reset_zoom: "Resetuj powiększenie",
3170
3178
  support_chat_aria_label: "Czat pomocy"
3171
- }, oa = {
3179
+ }, na = {
3172
3180
  write_a_message_placeholder: "Escreva uma mensagem...",
3173
3181
  your_issue_has_been_resolved: "Seu problema foi resolvido!",
3174
3182
  new_conversation: "Nova conversa",
@@ -3265,7 +3273,7 @@ const Fe = {
3265
3273
  zoom_out: "Reduzir",
3266
3274
  reset_zoom: "Redefinir zoom",
3267
3275
  support_chat_aria_label: "Chat de suporte"
3268
- }, na = {
3276
+ }, ia = {
3269
3277
  write_a_message_placeholder: "Scrie un mesaj...",
3270
3278
  your_issue_has_been_resolved: "Problema ta a fost rezolvată!",
3271
3279
  new_conversation: "Conversație nouă",
@@ -3362,7 +3370,7 @@ const Fe = {
3362
3370
  zoom_out: "Micșorează",
3363
3371
  reset_zoom: "Resetează zoomul",
3364
3372
  support_chat_aria_label: "Chat de asistență"
3365
- }, ia = {
3373
+ }, ra = {
3366
3374
  write_a_message_placeholder: "Skriv ett meddelande...",
3367
3375
  your_issue_has_been_resolved: "Ditt problem har lösts!",
3368
3376
  new_conversation: "Ny konversation",
@@ -3459,7 +3467,7 @@ const Fe = {
3459
3467
  zoom_out: "Zooma ut",
3460
3468
  reset_zoom: "Återställ zoom",
3461
3469
  support_chat_aria_label: "Supportchatt"
3462
- }, ra = {
3470
+ }, _a = {
3463
3471
  write_a_message_placeholder: "Напишите сообщение...",
3464
3472
  your_issue_has_been_resolved: "Ваша проблема решена!",
3465
3473
  new_conversation: "Новый разговор",
@@ -3556,7 +3564,7 @@ const Fe = {
3556
3564
  zoom_out: "Уменьшить",
3557
3565
  reset_zoom: "Сбросить масштаб",
3558
3566
  support_chat_aria_label: "Чат поддержки"
3559
- }, _a = {
3567
+ }, la = {
3560
3568
  write_a_message_placeholder: "เขียนข้อความ...",
3561
3569
  your_issue_has_been_resolved: "ปัญหาของคุณได้รับการแก้ไขแล้ว!",
3562
3570
  new_conversation: "การสนทนาใหม่",
@@ -3653,7 +3661,7 @@ const Fe = {
3653
3661
  zoom_out: "ย่อ",
3654
3662
  reset_zoom: "รีเซ็ตการซูม",
3655
3663
  support_chat_aria_label: "แชทฝ่ายสนับสนุน"
3656
- }, la = {
3664
+ }, ca = {
3657
3665
  write_a_message_placeholder: "Bir mesaj yazın...",
3658
3666
  your_issue_has_been_resolved: "Sorununuz çözüldü!",
3659
3667
  new_conversation: "Yeni konuşma",
@@ -3750,7 +3758,7 @@ const Fe = {
3750
3758
  zoom_out: "Uzaklaştır",
3751
3759
  reset_zoom: "Yakınlaştırmayı sıfırla",
3752
3760
  support_chat_aria_label: "Destek sohbeti"
3753
- }, ca = {
3761
+ }, pa = {
3754
3762
  write_a_message_placeholder: "پیغام لکھیں...",
3755
3763
  your_issue_has_been_resolved: "آپ کا مسئلہ حل ہو گیا ہے!",
3756
3764
  new_conversation: "نئی گفتگو",
@@ -3847,7 +3855,7 @@ const Fe = {
3847
3855
  zoom_out: "زوم آؤٹ",
3848
3856
  reset_zoom: "زوم دوبارہ ترتیب دیں",
3849
3857
  support_chat_aria_label: "سپورٹ چیٹ"
3850
- }, pa = {
3858
+ }, da = {
3851
3859
  write_a_message_placeholder: "Viết tin nhắn...",
3852
3860
  your_issue_has_been_resolved: "Vấn đề của bạn đã được giải quyết!",
3853
3861
  new_conversation: "Cuộc trò chuyện mới",
@@ -3944,7 +3952,7 @@ const Fe = {
3944
3952
  zoom_out: "Thu nhỏ",
3945
3953
  reset_zoom: "Đặt lại thu phóng",
3946
3954
  support_chat_aria_label: "Trò chuyện hỗ trợ"
3947
- }, da = {
3955
+ }, ua = {
3948
3956
  write_a_message_placeholder: "写一条消息...",
3949
3957
  your_issue_has_been_resolved: "您的问题已解决!",
3950
3958
  new_conversation: "新对话",
@@ -4041,7 +4049,7 @@ const Fe = {
4041
4049
  zoom_out: "缩小",
4042
4050
  reset_zoom: "重置缩放",
4043
4051
  support_chat_aria_label: "支持对话"
4044
- }, ua = {
4052
+ }, ma = {
4045
4053
  write_a_message_placeholder: "Napišite poruku...",
4046
4054
  your_issue_has_been_resolved: "Vaš problem je riješen!",
4047
4055
  new_conversation: "Novi razgovor",
@@ -4138,7 +4146,7 @@ const Fe = {
4138
4146
  zoom_out: "Udalji",
4139
4147
  reset_zoom: "Poništi zumiranje",
4140
4148
  support_chat_aria_label: "Chat za podršku"
4141
- }, ma = {
4149
+ }, ha = {
4142
4150
  write_a_message_placeholder: "Kirjuta sõnum...",
4143
4151
  your_issue_has_been_resolved: "Teie probleem on lahendatud!",
4144
4152
  new_conversation: "Uus vestlus",
@@ -4235,7 +4243,7 @@ const Fe = {
4235
4243
  zoom_out: "Vähenda",
4236
4244
  reset_zoom: "Lähtesta suurendus",
4237
4245
  support_chat_aria_label: "Tugivestlus"
4238
- }, ha = {
4246
+ }, ga = {
4239
4247
  write_a_message_placeholder: "Írjon üzenetet...",
4240
4248
  your_issue_has_been_resolved: "A problémája megoldódott!",
4241
4249
  new_conversation: "Új beszélgetés",
@@ -4332,7 +4340,7 @@ const Fe = {
4332
4340
  zoom_out: "Kicsinyítés",
4333
4341
  reset_zoom: "Nagyítás visszaállítása",
4334
4342
  support_chat_aria_label: "Ügyfélszolgálati chat"
4335
- }, ga = {
4343
+ }, ka = {
4336
4344
  write_a_message_placeholder: "Skrifaðu skilaboð...",
4337
4345
  your_issue_has_been_resolved: "Málið þitt hefur verið leyst!",
4338
4346
  new_conversation: "Nýtt samtal",
@@ -4429,7 +4437,7 @@ const Fe = {
4429
4437
  zoom_out: "Minnka aðdrátt",
4430
4438
  reset_zoom: "Endurstilla aðdrátt",
4431
4439
  support_chat_aria_label: "Þjónustuspjall"
4432
- }, ka = {
4440
+ }, ba = {
4433
4441
  write_a_message_placeholder: "Rakstiet ziņojumu...",
4434
4442
  your_issue_has_been_resolved: "Jūsu problēma ir atrisināta!",
4435
4443
  new_conversation: "Jauna saruna",
@@ -4526,7 +4534,7 @@ const Fe = {
4526
4534
  zoom_out: "Attālināt",
4527
4535
  reset_zoom: "Atiestatīt tālummaiņu",
4528
4536
  support_chat_aria_label: "Atbalsta tērzēšana"
4529
- }, ba = {
4537
+ }, va = {
4530
4538
  write_a_message_placeholder: "Parašykite žinutę...",
4531
4539
  your_issue_has_been_resolved: "Jūsų problema išspręsta!",
4532
4540
  new_conversation: "Naujas pokalbis",
@@ -4623,7 +4631,7 @@ const Fe = {
4623
4631
  zoom_out: "Nutolinti",
4624
4632
  reset_zoom: "Atstatyti mastelį",
4625
4633
  support_chat_aria_label: "Pagalbos pokalbis"
4626
- }, va = {
4634
+ }, fa = {
4627
4635
  write_a_message_placeholder: "Schreift eng Noriicht...",
4628
4636
  your_issue_has_been_resolved: "Äert Problem gouf geléist!",
4629
4637
  new_conversation: "Nei Konversatioun",
@@ -4720,7 +4728,7 @@ const Fe = {
4720
4728
  zoom_out: "Erauszoomen",
4721
4729
  reset_zoom: "Zoom zrécksetzen",
4722
4730
  support_chat_aria_label: "Support-Chat"
4723
- }, fa = {
4731
+ }, ya = {
4724
4732
  write_a_message_placeholder: "Ikteb messaġġ...",
4725
4733
  your_issue_has_been_resolved: "Il-problema tiegħek ġiet riżolta!",
4726
4734
  new_conversation: "Konversazzjoni ġdida",
@@ -4817,7 +4825,7 @@ const Fe = {
4817
4825
  zoom_out: "Ċekken",
4818
4826
  reset_zoom: "Irrisettja ż-zoom",
4819
4827
  support_chat_aria_label: "Chat ta’ appoġġ"
4820
- }, ya = {
4828
+ }, wa = {
4821
4829
  write_a_message_placeholder: "Skriv en melding...",
4822
4830
  your_issue_has_been_resolved: "Saken din er løst!",
4823
4831
  new_conversation: "Ny samtale",
@@ -4914,7 +4922,7 @@ const Fe = {
4914
4922
  zoom_out: "Zoom ut",
4915
4923
  reset_zoom: "Tilbakestill zoom",
4916
4924
  support_chat_aria_label: "Support-chat"
4917
- }, wa = {
4925
+ }, ja = {
4918
4926
  write_a_message_placeholder: "Napíšte správu...",
4919
4927
  your_issue_has_been_resolved: "Váš problém bol vyriešený!",
4920
4928
  new_conversation: "Nová konverzácia",
@@ -5011,82 +5019,82 @@ const Fe = {
5011
5019
  zoom_out: "Oddialiť",
5012
5020
  reset_zoom: "Obnoviť priblíženie",
5013
5021
  support_chat_aria_label: "Chat podpory"
5014
- }, J = {
5022
+ }, Y = {
5015
5023
  ar: Fe,
5016
- bn: Oe,
5017
- bg: Ue,
5018
- cs: Be,
5019
- da: Ve,
5020
- de: Ge,
5021
- el: He,
5022
- en: $,
5023
- es: Ze,
5024
- et: ma,
5025
- fi: $e,
5026
- fil: We,
5027
- fr: Je,
5028
- hi: Ye,
5029
- hr: ua,
5030
- hu: ha,
5031
- is: ga,
5032
- it: Xe,
5033
- ja: Qe,
5034
- ko: ea,
5035
- lb: va,
5036
- lt: ba,
5037
- lv: ka,
5038
- mt: fa,
5039
- nb: ya,
5040
- nl: aa,
5041
- no: ta,
5042
- pl: sa,
5043
- pt: oa,
5044
- ro: na,
5045
- ru: ra,
5046
- sk: wa,
5047
- sv: ia,
5048
- th: _a,
5049
- tr: la,
5050
- ur: ca,
5051
- vi: pa,
5052
- "zh-cn": da
5053
- }, ja = Object.keys(J);
5054
- function Sa(i) {
5055
- return ja.includes(i);
5024
+ bn: Ue,
5025
+ bg: Be,
5026
+ cs: Ve,
5027
+ da: He,
5028
+ de: Ze,
5029
+ el: Ge,
5030
+ en: J,
5031
+ es: We,
5032
+ et: ha,
5033
+ fi: Je,
5034
+ fil: $e,
5035
+ fr: Ye,
5036
+ hi: Xe,
5037
+ hr: ma,
5038
+ hu: ga,
5039
+ is: ka,
5040
+ it: Qe,
5041
+ ja: ea,
5042
+ ko: aa,
5043
+ lb: fa,
5044
+ lt: va,
5045
+ lv: ba,
5046
+ mt: ya,
5047
+ nb: wa,
5048
+ nl: ta,
5049
+ no: sa,
5050
+ pl: oa,
5051
+ pt: na,
5052
+ ro: ia,
5053
+ ru: _a,
5054
+ sk: ja,
5055
+ sv: ra,
5056
+ th: la,
5057
+ tr: ca,
5058
+ ur: pa,
5059
+ vi: da,
5060
+ "zh-cn": ua
5061
+ }, Sa = Object.keys(Y);
5062
+ function za(i) {
5063
+ return Sa.includes(i);
5056
5064
  }
5057
- const za = /* @__PURE__ */ new Set(["ar", "ur"]);
5065
+ const Ca = /* @__PURE__ */ new Set(["ar", "ur"]);
5058
5066
  function Ja(i) {
5059
- return za.has(i);
5067
+ return Ca.has(i);
5060
5068
  }
5061
- function Ca(i) {
5062
- return Sa(i) ? i : "en";
5069
+ function xa(i) {
5070
+ return za(i) ? i : "en";
5063
5071
  }
5064
- function xa(i, e, a, o) {
5065
- var l;
5066
- const r = ((l = a == null ? void 0 : a[e]) == null ? void 0 : l[i]) || J[e][i] || $[i] || i;
5072
+ function qa(i, e, a, o) {
5073
+ var c;
5074
+ const r = ((c = a == null ? void 0 : a[e]) == null ? void 0 : c[i]) || Y[e][i] || J[i] || i;
5067
5075
  return o ? r.replace(
5068
5076
  /\{(\w+)\}/g,
5069
5077
  (s, t) => t in o ? String(o[t]) : s
5070
5078
  ) : r;
5071
5079
  }
5072
- function qa(i, e, a) {
5073
- return xa(
5080
+ function Ea(i, e, a) {
5081
+ return qa(
5074
5082
  e,
5075
- Ca(i.language),
5083
+ xa(i.language),
5076
5084
  i.translationOverrides,
5077
5085
  a
5078
5086
  );
5079
5087
  }
5080
- class Ea {
5088
+ class Aa {
5081
5089
  constructor({
5082
5090
  config: e,
5083
5091
  api: a,
5084
5092
  contactCtx: o,
5085
5093
  storageCtx: r,
5086
- sessionsPollingIntervalSeconds: l,
5094
+ sessionsPollingIntervalSeconds: c,
5087
5095
  sharedSessions: s
5088
5096
  }) {
5089
- this.sessionsRefresher = new Z(), this.persistedSessionId = null, this.sessionAbortController = new AbortController(), this.sessionState = new S({
5097
+ this.sessionsRefresher = new W(), this.persistedSessionId = null, this.sessionAbortController = new AbortController(), this.sessionState = new S({
5090
5098
  session: null,
5091
5099
  isCreatingSession: !1,
5092
5100
  isResolvingSession: !1
@@ -5114,10 +5122,10 @@ class Ea {
5114
5122
  }, this.persistSession = ({ session: t }) => {
5115
5123
  const n = this.storageCtx;
5116
5124
  if (!n) return;
5117
- const c = t != null && t.isOpened ? t.id : null;
5118
- if (c === this.persistedSessionId || !c && this.persistedSessionId === null) return;
5119
- this.persistedSessionId = c, (c ? n.setActiveSessionId(c) : n.clearActiveSessionId()).catch((_) => {
5120
- g.warn("failed to persist the active session", {
5125
+ const l = t != null && t.isOpened ? t.id : null;
5126
+ if (l === this.persistedSessionId || !l && this.persistedSessionId === null) return;
5127
+ this.persistedSessionId = l, (l ? n.setActiveSessionId(l) : n.clearActiveSessionId()).catch((_) => {
5128
+ k.warn("failed to persist the active session", {
5121
5129
  error: _ instanceof Error ? _.message : String(_)
5122
5130
  });
5123
5131
  });
@@ -5143,18 +5151,18 @@ class Ea {
5143
5151
  this.sessionsState.get().didStartInitialFetch === !1 && this.sessionsState.setPartial({ didStartInitialFetch: !0 }), await this.refreshSessions(), this.sessionsState.get().isInitialFetchLoading === !0 && this.sessionsState.setPartial({ isInitialFetchLoading: !1 });
5144
5152
  }, this.sessionsPollingIntervalSeconds * 1e3);
5145
5153
  }, this.dispose = ({ clearActiveSession: t = !1 } = {}) => {
5146
- var n, c;
5147
- if (this.sessionsRefresher.reset(), this.sessionAbortController.abort(), (n = this.stopPersistingSession) == null || n.call(this), this.stopPersistingSession = void 0, (c = this.stopWaitingForContact) == null || c.call(this), this.stopWaitingForContact = void 0, this.sessionState.reset(), t && this.storageCtx)
5154
+ var n, l;
5155
+ if (this.sessionsRefresher.reset(), this.sessionAbortController.abort(), (n = this.stopPersistingSession) == null || n.call(this), this.stopPersistingSession = void 0, (l = this.stopWaitingForContact) == null || l.call(this), this.stopWaitingForContact = void 0, this.sessionState.reset(), t && this.storageCtx)
5148
5156
  return this.persistedSessionId = null, this.storageCtx.clearActiveSessionId().catch((d) => {
5149
- g.warn("failed to clear the replaced session", {
5157
+ k.warn("failed to clear the replaced session", {
5150
5158
  error: d instanceof Error ? d.message : String(d)
5151
5159
  });
5152
5160
  });
5153
5161
  }, this.getParsedCustomData = () => Object.fromEntries(
5154
5162
  Object.entries(this.config.sessionCustomData || {}).map(
5155
5163
  ([t, n]) => {
5156
- var c;
5157
- return typeof n == "string" ? [t, n] : typeof n == "boolean" ? [t, n] : typeof n == "number" ? [t, n] : [t, ((c = W(() => JSON.stringify(n))) == null ? void 0 : c.data) || ""];
5164
+ var l;
5165
+ return typeof n == "string" ? [t, n] : typeof n == "boolean" ? [t, n] : typeof n == "number" ? [t, n] : [t, ((l = $(() => JSON.stringify(n))) == null ? void 0 : l.data) || ""];
5158
5166
  }
5159
5167
  )
5160
5168
  ), this.createSession = async () => {
@@ -5166,18 +5174,18 @@ class Ea {
5166
5174
  if (n.session) return n.session;
5167
5175
  if (n.status === 401 && await this.contactCtx.recoverFromStaleToken()) {
5168
5176
  if (t.aborted) return null;
5169
- const c = await this.requestSession(t);
5170
- return t.aborted ? null : c.session ? c.session : (g.error("failed to create session", c.error), null);
5177
+ const l = await this.requestSession(t);
5178
+ return t.aborted ? null : l.session ? l.session : (k.error("failed to create session", l.error), null);
5171
5179
  }
5172
- return g.error("failed to create session", n.error), null;
5180
+ return k.error("failed to create session", n.error), null;
5173
5181
  } catch (n) {
5174
- return t.aborted || g.error("failed to create session", n), null;
5182
+ return t.aborted || k.error("failed to create session", n), null;
5175
5183
  } finally {
5176
5184
  t.aborted || this.sessionState.setPartial({ isCreatingSession: !1 });
5177
5185
  }
5178
5186
  }, this.requestSession = async (t) => {
5179
- var u, h, k;
5180
- const n = (u = this.contactCtx.state.get().contact) == null ? void 0 : u.externalId, c = {
5187
+ var u, m, g;
5188
+ const n = (u = this.contactCtx.state.get().contact) == null ? void 0 : u.externalId, l = {
5181
5189
  ...this.getParsedCustomData(),
5182
5190
  ...n ? { external_id: n } : {}
5183
5191
  }, {
@@ -5186,7 +5194,7 @@ class Ea {
5186
5194
  response: p
5187
5195
  } = await this.api.createSession(
5188
5196
  {
5189
- customData: Object.keys(c).length > 0 ? c : void 0
5197
+ customData: Object.keys(l).length > 0 ? l : void 0
5190
5198
  },
5191
5199
  t
5192
5200
  );
@@ -5194,9 +5202,9 @@ class Ea {
5194
5202
  return { session: null, status: p == null ? void 0 : p.status, error: _ };
5195
5203
  this.sessionState.setPartial({ session: d });
5196
5204
  try {
5197
- (k = (h = this.config.hooks) == null ? void 0 : h.onSessionCreated) == null || k.call(h, { session: d });
5198
- } catch (v) {
5199
- g.error("onSessionCreated hook failed", v);
5205
+ (g = (m = this.config.hooks) == null ? void 0 : m.onSessionCreated) == null || g.call(m, { session: d });
5206
+ } catch (b) {
5207
+ k.error("onSessionCreated hook failed", b);
5200
5208
  }
5201
5209
  return { session: d, status: p.status, error: void 0 };
5202
5210
  }, this.loadMoreSessions = async () => {
@@ -5205,18 +5213,18 @@ class Ea {
5205
5213
  cursor: this.sessionsState.get().cursor
5206
5214
  });
5207
5215
  if (t) {
5208
- const c = [...this.sessionsState.get().data, ...t.items].filter(
5216
+ const l = [...this.sessionsState.get().data, ...t.items].filter(
5209
5217
  (d, _, p) => _ === p.findIndex((u) => d.id === u.id)
5210
5218
  );
5211
5219
  this.sessionsState.setPartial({
5212
- data: c,
5220
+ data: l,
5213
5221
  cursor: t.next || void 0,
5214
5222
  isLastPage: t.next === null
5215
5223
  });
5216
5224
  }
5217
5225
  }, this.getSessions = async ({ cursor: t }) => {
5218
- var c, d;
5219
- if (!((c = this.contactCtx.state.get().contact) != null && c.token)) return { data: null };
5226
+ var l, d;
5227
+ if (!((l = this.contactCtx.state.get().contact) != null && l.token)) return { data: null };
5220
5228
  const n = (d = this.contactCtx.state.get().contact) == null ? void 0 : d.externalId;
5221
5229
  return await this.api.getSessions({
5222
5230
  cursor: t,
@@ -5226,7 +5234,7 @@ class Ea {
5226
5234
  });
5227
5235
  }, this.setSessions = (t) => {
5228
5236
  const n = [...t, ...this.sessionsState.get().data].filter(
5229
- (c, d, _) => d === _.findIndex((p) => c.id === p.id)
5237
+ (l, d, _) => d === _.findIndex((p) => l.id === p.id)
5230
5238
  );
5231
5239
  this.sessionsState.setPartial({ data: n });
5232
5240
  }, this.refreshSessions = async () => {
@@ -5237,31 +5245,31 @@ class Ea {
5237
5245
  if (!t || !t.isOpened)
5238
5246
  return { success: !1, error: "Session is not opened" };
5239
5247
  this.sessionState.setPartial({ isResolvingSession: !0 });
5240
- const { signal: n } = this.sessionAbortController, c = await this.api.resolveSession({ session_id: t.id }, n).catch((p) => {
5248
+ const { signal: n } = this.sessionAbortController, l = await this.api.resolveSession({ session_id: t.id }, n).catch((p) => {
5241
5249
  if (n.aborted) return null;
5242
5250
  throw p;
5243
5251
  });
5244
- if (!c || n.aborted)
5252
+ if (!l || n.aborted)
5245
5253
  return { success: !1, error: "Session was reset" };
5246
- const { data: d, error: _ } = c;
5254
+ const { data: d, error: _ } = l;
5247
5255
  return d ? (this.sessionState.setPartial({ session: d, isResolvingSession: !1 }), { success: !0, data: d }) : (this.sessionState.setPartial({ isResolvingSession: !1 }), { success: !1, error: _ });
5248
5256
  }, this.createStateCheckpoint = async (t) => {
5249
5257
  var d;
5250
5258
  const n = (d = this.sessionState.get().session) == null ? void 0 : d.id;
5251
5259
  if (!n) return;
5252
- const { data: c } = await this.api.createStateCheckpoint({
5260
+ const { data: l } = await this.api.createStateCheckpoint({
5253
5261
  session_id: n,
5254
5262
  payload: t
5255
5263
  });
5256
- return c != null && c.success ? { success: !0 } : { success: !1 };
5257
- }, this.config = e, this.api = a, this.contactCtx = o, this.storageCtx = r, this.sessionsPollingIntervalSeconds = l, s ? this.sessionsState = s : this.registerSessionsRefresherWrapper(), this.registerActiveSessionPersistence();
5264
+ return l != null && l.success ? { success: !0 } : { success: !1 };
5265
+ }, this.config = e, this.api = a, this.contactCtx = o, this.storageCtx = r, this.sessionsPollingIntervalSeconds = c, s ? this.sessionsState = s : this.registerSessionsRefresherWrapper(), this.registerActiveSessionPersistence();
5258
5266
  }
5259
5267
  }
5260
- const Aa = (i, e, { sendsPageContext: a }) => {
5261
- const o = Ia(i), r = a && e.mentions && e.mentions.length > 0 ? { mentions: e.mentions.map(Pa) } : void 0, l = a && (e.clientContext || r) ? { ...o, ...e.clientContext, ...r } : o, s = e.connectionRequestId ? {
5262
- ...l,
5268
+ const Pa = (i, e, { sendsPageContext: a }) => {
5269
+ const o = Ma(i), r = a && e.mentions && e.mentions.length > 0 ? { mentions: e.mentions.map(Ta) } : void 0, c = a && (e.clientContext || r) ? { ...o, ...e.clientContext, ...r } : o, s = e.connectionRequestId ? {
5270
+ ...c,
5263
5271
  opencx__connection_request_id: e.connectionRequestId
5264
- } : l, t = e.withPageEntity === !1 && s && "entity" in s ? Ta(s, "entity") : s;
5272
+ } : c, t = e.withPageEntity === !1 && s && "entity" in s ? Ia(s, "entity") : s;
5265
5273
  return {
5266
5274
  clientContext: e.background ? { ...t, opencx__background: !0 } : t,
5267
5275
  custom_data: {
@@ -5269,39 +5277,39 @@ const Aa = (i, e, { sendsPageContext: a }) => {
5269
5277
  ...e.customData || {}
5270
5278
  }
5271
5279
  };
5272
- }, Pa = ({ type: i, id: e, title: a, meta: o }) => ({
5280
+ }, Ta = ({ type: i, id: e, title: a, meta: o }) => ({
5273
5281
  type: i,
5274
5282
  id: e,
5275
5283
  title: a,
5276
5284
  ...o ? { meta: o } : {}
5277
- }), Ta = (i, e) => {
5285
+ }), Ia = (i, e) => {
5278
5286
  const { [e]: a, ...o } = i;
5279
5287
  return Object.keys(o).length > 0 ? o : void 0;
5280
- }, Ia = (i) => {
5288
+ }, Ma = (i) => {
5281
5289
  if (typeof i.context != "function") return i.context;
5282
5290
  try {
5283
5291
  return i.context();
5284
5292
  } catch (e) {
5285
- g.error("context getter threw; sending without context", e);
5293
+ k.error("context getter threw; sending without context", e);
5286
5294
  return;
5287
5295
  }
5288
- }, Ma = (i) => {
5296
+ }, Da = (i) => {
5289
5297
  const e = i.features, a = {
5290
5298
  page_context: (e == null ? void 0 : e.pageContext) === !0,
5291
5299
  client_tools: (e == null ? void 0 : e.pageContext) === !0 && (e == null ? void 0 : e.clientTools) === !0,
5292
5300
  page_actions: (e == null ? void 0 : e.pageContext) === !0 && (e == null ? void 0 : e.clientTools) === !0 && (e == null ? void 0 : e.pageActions) === !0
5293
5301
  };
5294
5302
  return e && (e.preamble !== void 0 && (a.preamble = e.preamble), e.inlineUi !== void 0 && (a.inline_ui = e.inlineUi)), a;
5295
- }, Da = ({
5303
+ }, Na = ({
5296
5304
  config: i,
5297
5305
  input: e,
5298
5306
  uuid: a,
5299
5307
  sessionId: o,
5300
5308
  content: r,
5301
- initialMessages: l,
5309
+ initialMessages: c,
5302
5310
  sendsPageContext: s
5303
5311
  }) => {
5304
- var t, n, c, d;
5312
+ var t, n, l, d;
5305
5313
  return {
5306
5314
  uuid: a,
5307
5315
  bot_token: i.token,
@@ -5311,18 +5319,22 @@ const Aa = (i, e, { sendsPageContext: a }) => {
5311
5319
  session_id: o,
5312
5320
  content: r,
5313
5321
  attachments: e.attachments,
5314
- ...Aa(i, e, { sendsPageContext: s }),
5322
+ ...Pa(i, e, { sendsPageContext: s }),
5315
5323
  language: i.language,
5316
- features: Ma(i),
5324
+ features: Da(i),
5317
5325
  presentation: i.presentation,
5318
5326
  capabilities: {
5319
5327
  connections: ((t = i.capabilities) == null ? void 0 : t.connections) === !0,
5320
5328
  structured_questions: (n = i.capabilities) == null ? void 0 : n.structuredQuestions,
5321
- rich_replies: (c = i.capabilities) == null ? void 0 : c.richReplies,
5329
+ rich_replies: (l = i.capabilities) == null ? void 0 : l.richReplies,
5322
5330
  page_effects: (d = i.capabilities) == null ? void 0 : d.pageEffects
5323
5331
  },
5324
5332
  exit_mode_prompt: e.exitModePrompt,
5325
- initial_messages: l.length > 0 ? l.map((_) => ({ uuid: _.id, content: _.data.message })) : void 0
5333
+ option_reply: e.optionReply ? {
5334
+ message_id: e.optionReply.messageId,
5335
+ option_id: e.optionReply.optionId
5336
+ } : void 0,
5337
+ initial_messages: c.length > 0 ? c.map((_) => ({ uuid: _.id, content: _.data.message })) : void 0
5326
5338
  };
5327
5339
  }, x = class x {
5328
5340
  constructor({
@@ -5330,11 +5342,11 @@ const Aa = (i, e, { sendsPageContext: a }) => {
5330
5342
  api: a,
5331
5343
  sessionCtx: o,
5332
5344
  contactCtx: r,
5333
- streaming: l,
5345
+ streaming: c,
5334
5346
  sendsPageContext: s,
5335
5347
  getClientCapabilities: t,
5336
5348
  getRequestConfig: n,
5337
- isStreaming: c,
5349
+ isStreaming: l,
5338
5350
  getSendsPageContext: d
5339
5351
  }) {
5340
5352
  this.state = new S({
@@ -5364,24 +5376,24 @@ const Aa = (i, e, { sendsPageContext: a }) => {
5364
5376
  }, this.unregisterAgentHandlers = (_) => {
5365
5377
  this.agentHandlers === _ && (this.agentHandlers = null);
5366
5378
  }, this.dispatchToOnMessageReceivedHook = (_) => {
5367
- var u, h;
5379
+ var u, m;
5368
5380
  if (_.type === "USER" || this.messageIdsDispatchedToOnMessageReceivedHook.has(_.id))
5369
5381
  return;
5370
5382
  const p = this.sessionCtx.sessionState.get().session;
5371
- p && (this.messageIdsDispatchedToOnMessageReceivedHook.add(_.id), (h = (u = this.config.hooks) == null ? void 0 : u.onMessageReceived) == null || h.call(u, { message: _, session: p }));
5383
+ p && (this.messageIdsDispatchedToOnMessageReceivedHook.add(_.id), (m = (u = this.config.hooks) == null ? void 0 : u.onMessageReceived) == null || m.call(u, { message: _, session: p }));
5372
5384
  }, this.markAsDispatchedToOnMessageReceivedHook = (_) => {
5373
5385
  _.forEach(
5374
5386
  (p) => this.messageIdsDispatchedToOnMessageReceivedHook.add(p)
5375
5387
  );
5376
5388
  }, this.buildPersistentInitialMessages = () => {
5377
5389
  var p, u;
5378
- return !((p = this.sessionCtx.sessionState.get().session) != null && p.id) && this.state.get().messages.length === 0 && ((u = this.config.advancedInitialMessages) == null ? void 0 : u.some((h) => h.persistent)) ? (this.config.advancedInitialMessages || []).filter((h) => h.persistent).map(
5379
- (h) => ({
5390
+ return !((p = this.sessionCtx.sessionState.get().session) != null && p.id) && this.state.get().messages.length === 0 && ((u = this.config.advancedInitialMessages) == null ? void 0 : u.some((m) => m.persistent)) ? (this.config.advancedInitialMessages || []).filter((m) => m.persistent).map(
5391
+ (m) => ({
5380
5392
  id: q(),
5381
5393
  component: "bot_message",
5382
5394
  type: "AI",
5383
5395
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
5384
- data: { message: h.message },
5396
+ data: { message: m.message },
5385
5397
  agent: this.config.bot ? { ...this.config.bot, isAi: !0, id: null } : void 0
5386
5398
  })
5387
5399
  ) : [];
@@ -5394,46 +5406,50 @@ const Aa = (i, e, { sendsPageContext: a }) => {
5394
5406
  return ((p = this.sessionCtx.sessionState.get().session) == null ? void 0 : p.id) ?? null;
5395
5407
  }, this.rollbackOptimisticMessages = (_) => {
5396
5408
  if (_.length === 0) return;
5397
- const p = new Set(_), u = this.state.get().messages, h = u.filter((k) => !p.has(k.id));
5398
- h.length !== u.length && this.state.setPartial({ messages: h });
5409
+ const p = new Set(_), u = this.state.get().messages, m = u.filter((g) => !p.has(g.id));
5410
+ m.length !== u.length && this.state.setPartial({ messages: m });
5399
5411
  }, this.notifySendAccepted = (_) => {
5400
5412
  var p;
5413
+ _.optionReply && this.setMessageOptionPick(
5414
+ _.optionReply.messageId,
5415
+ _.optionReply.optionId
5416
+ );
5401
5417
  try {
5402
5418
  (p = _.onAccepted) == null || p.call(_);
5403
5419
  } catch (u) {
5404
- g.error("send acceptance callback failed", u);
5420
+ k.error("send acceptance callback failed", u);
5405
5421
  }
5406
5422
  }, this.stageUserTurn = async (_, { pending: p }) => {
5407
- const u = this.captureConversation(), h = this.buildUserMessage(_);
5408
- if (!h) return null;
5409
- const k = p ? { ...h, pending: !0 } : h, v = this.buildPersistentInitialMessages(), f = [
5410
- ...v.map((y) => y.id),
5411
- k.id
5423
+ const u = this.captureConversation(), m = this.buildUserMessage(_);
5424
+ if (!m) return null;
5425
+ const g = p ? { ...m, pending: !0 } : m, b = this.buildPersistentInitialMessages(), f = [
5426
+ ...b.map((y) => y.id),
5427
+ g.id
5412
5428
  ];
5413
5429
  this.state.setPartial({
5414
5430
  messages: [
5415
- ...v,
5431
+ ...b,
5416
5432
  ...this.state.get().messages,
5417
- ...k.background ? [] : [k]
5433
+ ...g.background ? [] : [g]
5418
5434
  ]
5419
5435
  });
5420
- let b;
5436
+ let v;
5421
5437
  try {
5422
- b = await this.ensureSessionId();
5438
+ v = await this.ensureSessionId();
5423
5439
  } catch (y) {
5424
5440
  if (!u()) return null;
5425
5441
  throw this.rollbackOptimisticMessages(f), y;
5426
5442
  }
5427
- return u() ? b ? { sessionId: b, userMessage: k, initialMessages: v } : (this.rollbackOptimisticMessages(f), null) : null;
5443
+ return u() ? v ? { sessionId: v, userMessage: g, initialMessages: b } : (this.rollbackOptimisticMessages(f), null) : null;
5428
5444
  }, this.buildQueuedUserMessage = (_) => {
5429
- var h;
5445
+ var m;
5430
5446
  const p = this.buildUserMessage(_);
5431
5447
  if (!p) return null;
5432
- const u = (h = this.sessionCtx.sessionState.get().session) == null ? void 0 : h.id;
5448
+ const u = (m = this.sessionCtx.sessionState.get().session) == null ? void 0 : m.id;
5433
5449
  return u ? { sessionId: u, userMessage: { ...p, pending: !0 } } : null;
5434
5450
  }, this.buildUserMessage = (_) => {
5435
5451
  var p;
5436
- return !_.content.trim() && (!_.attachments || _.attachments.length === 0) ? (g.warn("cannot send an empty message of no content or attachments"), null) : {
5452
+ return !_.content.trim() && (!_.attachments || _.attachments.length === 0) ? (k.warn("cannot send an empty message of no content or attachments"), null) : {
5437
5453
  ...this.toUserMessage(
5438
5454
  _.content.trim(),
5439
5455
  _.attachments || void 0,
@@ -5448,17 +5464,30 @@ const Aa = (i, e, { sendsPageContext: a }) => {
5448
5464
  p.some((u) => u.id === _.id) || this.state.setPartial({ messages: [...p, _] });
5449
5465
  }, this.markUserMessageDelivered = (_) => {
5450
5466
  const p = this.state.get().messages, u = p.findIndex(
5451
- (v) => v.id === _ && v.type === "USER" && v.pending
5467
+ (b) => b.id === _ && b.type === "USER" && b.pending
5452
5468
  );
5453
5469
  if (u === -1) return;
5454
- const h = p[u];
5455
- if (!h || h.type !== "USER") return;
5456
- const k = [...p];
5457
- k[u] = { ...h, pending: !1 }, this.state.setPartial({
5458
- messages: k
5470
+ const m = p[u];
5471
+ if (!m || m.type !== "USER") return;
5472
+ const g = [...p];
5473
+ g[u] = { ...m, pending: !1 }, this.state.setPartial({
5474
+ messages: g
5459
5475
  });
5476
+ }, this.setMessageOptionPick = (_, p) => {
5477
+ const u = this.state.get().messages, m = u.findIndex((f) => f.id === _), g = u[m];
5478
+ if (!g || g.type !== "AGENT" || !g.messageOptions || g.messageOptions.pickedOptionId === p) return;
5479
+ const b = [...u];
5480
+ b[m] = {
5481
+ ...g,
5482
+ messageOptions: { ...g.messageOptions, pickedOptionId: p }
5483
+ }, this.state.setPartial({ messages: b });
5484
+ }, this.releaseFailedOptionPick = (_) => {
5485
+ var g;
5486
+ if (!_.optionReply) return;
5487
+ const { messageId: p, optionId: u } = _.optionReply, m = this.state.get().messages.find((b) => b.id === p);
5488
+ (m == null ? void 0 : m.type) !== "AGENT" || ((g = m.messageOptions) == null ? void 0 : g.pickedOptionId) !== u || this.setMessageOptionPick(p, null);
5460
5489
  }, this.sendMessage = async (_) => {
5461
- var u, h, k, v, f;
5490
+ var u, m, g, b, f;
5462
5491
  if (this.streaming) {
5463
5492
  if (!this.agentHandlers) {
5464
5493
  this.bufferedAgentSends.push(_);
@@ -5469,32 +5498,32 @@ const Aa = (i, e, { sendsPageContext: a }) => {
5469
5498
  }
5470
5499
  let p;
5471
5500
  try {
5472
- const b = this.sessionCtx.sessionState.get().session, z = (b == null ? void 0 : b.assignee.kind) === "ai", X = this.state.get().isSendingMessageToAI, A = this.state.get().messages.at(-1);
5473
- if (this.blocksSendWhileAwaitingReply && (X || // If last message is from user, then bot response did not arrive yet
5501
+ const v = this.sessionCtx.sessionState.get().session, z = (v == null ? void 0 : v.assignee.kind) === "ai", Q = this.state.get().isSendingMessageToAI, A = this.state.get().messages.at(-1);
5502
+ if (this.blocksSendWhileAwaitingReply && (Q || // If last message is from user, then bot response did not arrive yet
5474
5503
  z && (A == null ? void 0 : A.type) === "USER" && A.id !== this.state.get().settledAgentUserMessageId)) {
5475
- g.warn("cannot send messages while awaiting AI response");
5504
+ k.warn("cannot send messages while awaiting AI response");
5476
5505
  return;
5477
5506
  }
5478
5507
  this.sendMessageAbortController.abort("Superseded by a newer message"), this.sendMessageAbortController = new AbortController(), p = this.sendMessageAbortController, this.state.setPartial({
5479
5508
  lastAIResMightSolveUserIssue: !1,
5480
5509
  isSendingMessage: !0,
5481
- isSendingMessageToAI: !!z || !b
5510
+ isSendingMessageToAI: !!z || !v
5482
5511
  });
5483
5512
  const R = await this.stageUserTurn(_, { pending: !1 });
5484
5513
  if (!R) return;
5485
- const { sessionId: Q, userMessage: K, initialMessages: ee } = R;
5514
+ const { sessionId: ee, userMessage: K, initialMessages: ae } = R;
5486
5515
  this.notifySendAccepted(_);
5487
5516
  const { data: w } = await this.api.sendMessage(
5488
- Da({
5517
+ Na({
5489
5518
  config: {
5490
5519
  ...this.getRequestConfig(),
5491
5520
  capabilities: this.getClientCapabilities()
5492
5521
  },
5493
5522
  input: _,
5494
5523
  uuid: K.id,
5495
- sessionId: Q,
5524
+ sessionId: ee,
5496
5525
  content: K.content,
5497
- initialMessages: ee,
5526
+ initialMessages: ae,
5498
5527
  sendsPageContext: this.sendsPageContext
5499
5528
  }),
5500
5529
  p.signal
@@ -5504,52 +5533,53 @@ const Aa = (i, e, { sendsPageContext: a }) => {
5504
5533
  if (C) {
5505
5534
  const P = this.state.get().messages;
5506
5535
  if (!!P.some(
5507
- (ae) => ae.id === C.id
5536
+ (te) => te.id === C.id
5508
5537
  )) {
5509
5538
  this.state.setPartial({
5510
- lastAIResMightSolveUserIssue: ((u = w.autopilotResponse) == null ? void 0 : u.mightSolveUserIssue) || ((h = w.uiResponse) == null ? void 0 : h.mightSolveUserIssue)
5539
+ lastAIResMightSolveUserIssue: ((u = w.autopilotResponse) == null ? void 0 : u.mightSolveUserIssue) || ((m = w.uiResponse) == null ? void 0 : m.mightSolveUserIssue)
5511
5540
  });
5512
5541
  return;
5513
5542
  }
5514
5543
  this.state.setPartial({
5515
5544
  messages: [...P, C],
5516
- lastAIResMightSolveUserIssue: ((k = w.autopilotResponse) == null ? void 0 : k.mightSolveUserIssue) || ((v = w.uiResponse) == null ? void 0 : v.mightSolveUserIssue)
5545
+ lastAIResMightSolveUserIssue: ((g = w.autopilotResponse) == null ? void 0 : g.mightSolveUserIssue) || ((b = w.uiResponse) == null ? void 0 : b.mightSolveUserIssue)
5517
5546
  }), this.dispatchToOnMessageReceivedHook(C);
5518
5547
  }
5519
5548
  w.session && this.sessionCtx.sessionState.setPartial({ session: w.session });
5520
5549
  } else {
5550
+ this.releaseFailedOptionPick(_);
5521
5551
  const C = this.toBotErrorMessage(
5522
- ((f = w == null ? void 0 : w.error) == null ? void 0 : f.message) || qa(this.config, "turn_failed_message")
5552
+ ((f = w == null ? void 0 : w.error) == null ? void 0 : f.message) || Ea(this.config, "turn_failed_message")
5523
5553
  ), P = this.state.get().messages;
5524
5554
  this.state.setPartial({
5525
5555
  messages: [...P, C]
5526
5556
  });
5527
5557
  }
5528
- } catch (b) {
5529
- p != null && p.signal.aborted || g.error("failed to send message", b);
5558
+ } catch (v) {
5559
+ p != null && p.signal.aborted || (this.releaseFailedOptionPick(_), k.error("failed to send message", v));
5530
5560
  } finally {
5531
5561
  p != null && p.signal.aborted || this.state.setPartial({
5532
5562
  isSendingMessage: !1,
5533
5563
  isSendingMessageToAI: !1
5534
5564
  });
5535
5565
  }
5536
- }, this.toUserMessage = (_, p, u, h) => {
5537
- const k = (() => {
5566
+ }, this.toUserMessage = (_, p, u, m) => {
5567
+ const g = (() => {
5538
5568
  const f = this.contactCtx.state.get().extraCollectedData;
5539
5569
  return this.state.get().messages.length === 0 && f && Object.keys(f).length > 0 ? `${Object.entries(f).filter(([y, z]) => !!z).map(([y, z]) => `${y}: ${z}`).join(`
5540
5570
  `)}
5541
5571
 
5542
5572
  ${_}` : _;
5543
- })(), v = (/* @__PURE__ */ new Date()).toISOString();
5573
+ })(), b = (/* @__PURE__ */ new Date()).toISOString();
5544
5574
  return {
5545
5575
  id: q(),
5546
5576
  type: "USER",
5547
- deliveredAt: v,
5548
- content: k,
5577
+ deliveredAt: b,
5578
+ content: g,
5549
5579
  attachments: p,
5550
5580
  markedElements: u,
5551
- mentions: h,
5552
- timestamp: v
5581
+ mentions: m,
5582
+ timestamp: b
5553
5583
  };
5554
5584
  }, this.toBotMessage = (_) => {
5555
5585
  var p;
@@ -5584,7 +5614,7 @@ ${_}` : _;
5584
5614
  variant: "error",
5585
5615
  action: void 0
5586
5616
  }
5587
- }), this.config = e, this.getClientCapabilities = t ?? (() => this.getRequestConfig().capabilities), this.api = a, this.sessionCtx = o, this.contactCtx = r, this.isStreaming = c ?? (() => l), this.getRequestConfig = n ?? (() => this.config), this.getSendsPageContext = d ?? (() => s);
5617
+ }), this.config = e, this.getClientCapabilities = t ?? (() => this.getRequestConfig().capabilities), this.api = a, this.sessionCtx = o, this.contactCtx = r, this.isStreaming = l ?? (() => c), this.getRequestConfig = n ?? (() => this.config), this.getSendsPageContext = d ?? (() => s);
5588
5618
  }
5589
5619
  /**
5590
5620
  * Current transport choice. The org or this embed may request polling
@@ -5600,10 +5630,10 @@ ${_}` : _;
5600
5630
  static dispatchToEngine(e, a) {
5601
5631
  try {
5602
5632
  Promise.resolve(e.send(a)).catch((o) => {
5603
- g.error("streaming send failed", o);
5633
+ k.error("streaming send failed", o);
5604
5634
  });
5605
5635
  } catch (o) {
5606
- g.error("streaming send failed", o);
5636
+ k.error("streaming send failed", o);
5607
5637
  }
5608
5638
  }
5609
5639
  get hasPendingAgentWork() {
@@ -5622,14 +5652,14 @@ ${_}` : _;
5622
5652
  if (!Array.isArray(a)) return;
5623
5653
  const o = a.flatMap((r) => {
5624
5654
  if (typeof r != "object" || r === null) return [];
5625
- const l = r.elements, s = Array.isArray(l) ? l[0] : void 0, t = typeof s == "object" && s !== null && "name" in s ? s.name : void 0;
5655
+ const c = r.elements, s = Array.isArray(c) ? c[0] : void 0, t = typeof s == "object" && s !== null && "name" in s ? s.name : void 0;
5626
5656
  if (typeof t != "string" || t.length === 0) return [];
5627
- const n = r.note, c = r.snapshotUrl;
5657
+ const n = r.note, l = r.snapshotUrl;
5628
5658
  return [
5629
5659
  {
5630
5660
  name: t,
5631
5661
  ...typeof n == "string" && n.length > 0 ? { note: n } : {},
5632
- ...typeof c == "string" && c.length > 0 ? { snapshotUrl: c } : {},
5662
+ ...typeof l == "string" && l.length > 0 ? { snapshotUrl: l } : {},
5633
5663
  mark: r
5634
5664
  }
5635
5665
  ];
@@ -5646,7 +5676,7 @@ ${_}` : _;
5646
5676
  };
5647
5677
  x.SENT_TEXT_HISTORY_MAX = 50;
5648
5678
  let D = x;
5649
- class Na {
5679
+ class Ra {
5650
5680
  constructor(e) {
5651
5681
  var a, o;
5652
5682
  this.widget = e, this.subscriptions = [], this.disposed = !1, this.restorableSessionId = null, this.didReadStoredSession = !1, this.readStoredSession = () => {
@@ -5662,9 +5692,9 @@ class Na {
5662
5692
  }, this.registerRoutingListener = () => {
5663
5693
  this.subscriptions.push(
5664
5694
  this.contactCtx.state.subscribe(({ contact: r }) => {
5665
- var l;
5695
+ var c;
5666
5696
  r != null && r.token && this.state.get().screen === "welcome" && this.state.setPartial({
5667
- screen: (l = this.config.router) != null && l.chatScreenOnly ? "chat" : "sessions"
5697
+ screen: (c = this.config.router) != null && c.chatScreenOnly ? "chat" : "sessions"
5668
5698
  });
5669
5699
  })
5670
5700
  ), this.subscriptions.push(
@@ -5672,12 +5702,12 @@ class Na {
5672
5702
  );
5673
5703
  }, this.routeFromSessions = ({
5674
5704
  isInitialFetchLoading: r,
5675
- data: l
5705
+ data: c
5676
5706
  }) => {
5677
- var s, t, n, c, d;
5707
+ var s, t, n, l, d;
5678
5708
  if (!(this.disposed || !this.didReadStoredSession)) {
5679
5709
  if (this.restorableSessionId && !((s = this.sessionCtx.sessionState.get().session) != null && s.id)) {
5680
- const _ = l.find(
5710
+ const _ = c.find(
5681
5711
  (p) => p.id === this.restorableSessionId && p.isOpened
5682
5712
  );
5683
5713
  if (_) {
@@ -5690,10 +5720,10 @@ class Na {
5690
5720
  if ((t = this.config.router) != null && t.chatScreenOnly && // Do not route to a chat if we are currently inside one already
5691
5721
  // This also applies to newly created sessions; the new session will be in `sessionState` before it is refreshed and included in `sessionsState`
5692
5722
  !((n = this.sessionCtx.sessionState.get().session) != null && n.id)) {
5693
- const _ = (c = l.find((p) => p.isOpened)) == null ? void 0 : c.id;
5723
+ const _ = (l = c.find((p) => p.isOpened)) == null ? void 0 : l.id;
5694
5724
  return _ ? this.toChatScreen(_) : void 0;
5695
5725
  }
5696
- l.length || ((d = this.config.router) == null ? void 0 : d.goToChatIfNoSessions) !== !1 && !r && this.state.get().screen !== "chat" && this.toChatScreen();
5726
+ c.length || ((d = this.config.router) == null ? void 0 : d.goToChatIfNoSessions) !== !1 && !r && this.state.get().screen !== "chat" && this.toChatScreen();
5697
5727
  }
5698
5728
  }, this.dispose = () => {
5699
5729
  this.disposed = !0, this.subscriptions.forEach((r) => r()), this.subscriptions = [], this.navigateConversation = void 0;
@@ -5703,18 +5733,18 @@ class Na {
5703
5733
  var s, t;
5704
5734
  if (this.navigateConversation) return this.navigateConversation(r);
5705
5735
  this.resetChat();
5706
- let l;
5736
+ let c;
5707
5737
  if (r) {
5708
- if (l = this.sessionCtx.sessionsState.get().data.find((n) => n.id === r), !l) return;
5709
- this.sessionCtx.sessionState.setPartial({ session: l });
5738
+ if (c = this.sessionCtx.sessionsState.get().data.find((n) => n.id === r), !c) return;
5739
+ this.sessionCtx.sessionState.setPartial({ session: c });
5710
5740
  }
5711
- return this.state.setPartial({ screen: "chat" }), (t = (s = this.config.hooks) == null ? void 0 : s.onNavigateToChat) == null || t.call(s, { session: l }), this.widget;
5741
+ return this.state.setPartial({ screen: "chat" }), (t = (s = this.config.hooks) == null ? void 0 : s.onNavigateToChat) == null || t.call(s, { session: c }), this.widget;
5712
5742
  }, this.config = e.config, this.contactCtx = e.contactCtx, this.sessionCtx = e.sessionCtx, this.resetChat = e.resetChat, this.state = new S({
5713
5743
  screen: this.contactCtx.shouldCollectData() ? "welcome" : (a = this.config.router) != null && a.chatScreenOnly ? "chat" : "sessions"
5714
5744
  }), this.shouldRestoreLastSession = ((o = this.config.router) == null ? void 0 : o.restoreLastSession) ?? !1, this.readStoredSession(), this.registerRoutingListener();
5715
5745
  }
5716
5746
  }
5717
- class Ra {
5747
+ class Ka {
5718
5748
  constructor({
5719
5749
  storage: e,
5720
5750
  config: a
@@ -5737,8 +5767,8 @@ class Ra {
5737
5767
  }, this.getExternalContactId = async () => this.storage.get(this.KEYS.externalContactId(this.config.token)), this.companionKey = (o) => this.KEYS.companionPreference(this.config.token, o), this.getFiniteNumber = async (o) => {
5738
5768
  const r = await this.storage.get(o);
5739
5769
  if (r === null) return null;
5740
- const l = Number(r);
5741
- return Number.isFinite(l) ? l : null;
5770
+ const c = Number(r);
5771
+ return Number.isFinite(c) ? c : null;
5742
5772
  }, this.getCompanionPillOffsetX = async () => this.getFiniteNumber(this.companionKey("pill-offset-x")), this.setCompanionPillOffsetX = async (o) => {
5743
5773
  Number.isFinite(o) && await this.storage.set(this.companionKey("pill-offset-x"), String(o));
5744
5774
  }, this.getCompanionSidebarWidth = async () => this.getFiniteNumber(this.companionKey("sidebar-width")), this.setCompanionSidebarWidth = async (o) => {
@@ -5761,7 +5791,7 @@ class Ra {
5761
5791
  }, this.storage = e, this.config = a;
5762
5792
  }
5763
5793
  }
5764
- function Ka({
5794
+ function La({
5765
5795
  org: i,
5766
5796
  agent: e
5767
5797
  }) {
@@ -5790,20 +5820,23 @@ function Ka({
5790
5820
  }
5791
5821
  };
5792
5822
  }
5793
- function La(i, e) {
5823
+ function G(i, e) {
5794
5824
  return i && e !== !1;
5795
5825
  }
5796
- function Fa(i, e) {
5826
+ function Oa(i, e) {
5797
5827
  const a = e.features;
5798
5828
  return {
5799
- dictation: La(i.features.dictation, a == null ? void 0 : a.dictation),
5800
- attachments: i.features.attachments,
5829
+ dictation: G(i.features.dictation, a == null ? void 0 : a.dictation),
5830
+ attachments: G(
5831
+ i.features.attachments,
5832
+ a == null ? void 0 : a.attachments
5833
+ ),
5801
5834
  pageContext: i.features.pageContext && (a == null ? void 0 : a.pageContext) === !0,
5802
5835
  clientTools: i.features.clientTools && i.features.pageContext && (a == null ? void 0 : a.pageContext) === !0 && (a == null ? void 0 : a.clientTools) === !0,
5803
5836
  pageActions: i.features.pageActions && i.features.clientTools && i.features.pageContext && (a == null ? void 0 : a.pageContext) === !0 && (a == null ? void 0 : a.clientTools) === !0 && (a == null ? void 0 : a.pageActions) === !0
5804
5837
  };
5805
5838
  }
5806
- class Oa extends Error {
5839
+ class Fa extends Error {
5807
5840
  constructor(e, a, o) {
5808
5841
  super(a), this.name = "WidgetInitializationError", this.code = e, this.details = o;
5809
5842
  }
@@ -5814,13 +5847,13 @@ const j = class j {
5814
5847
  storage: a,
5815
5848
  getClientCapabilities: o,
5816
5849
  getRequestConfig: r,
5817
- modes: l,
5850
+ modes: c,
5818
5851
  org: s,
5819
5852
  agent: t,
5820
5853
  parent: n
5821
5854
  }) {
5822
5855
  if (this.modes = [], this.disposed = !1, this.createConversation = () => {
5823
- const c = new j({
5856
+ const l = new j({
5824
5857
  config: {
5825
5858
  ...this.config,
5826
5859
  router: {
@@ -5837,25 +5870,25 @@ const j = class j {
5837
5870
  getRequestConfig: this.getRequestConfig,
5838
5871
  getClientCapabilities: this.getClientCapabilities
5839
5872
  });
5840
- return c.routerCtx.state.setPartial({
5873
+ return l.routerCtx.state.setPartial({
5841
5874
  screen: this.contactCtx.shouldCollectData() ? "welcome" : "chat"
5842
- }), c;
5843
- }, this.releaseConversation = () => this.dispose(), this.dispose = ({ clearActiveSession: c = !1 } = {}) => {
5875
+ }), l;
5876
+ }, this.releaseConversation = () => this.dispose(), this.dispose = ({ clearActiveSession: l = !1 } = {}) => {
5844
5877
  if (this.disposed) return;
5845
5878
  this.disposed = !0, this.routerCtx.dispose(), this.activeSessionPollingCtx.dispose();
5846
- const d = this.sessionCtx.dispose({ clearActiveSession: c });
5879
+ const d = this.sessionCtx.dispose({ clearActiveSession: l });
5847
5880
  return this.messageCtx.reset(), this.uploadCtx.reset(), this.dictationCtx.stop({ executeFinalCommand: !1 }), d;
5848
5881
  }, this.resetChat = () => {
5849
5882
  this.sessionCtx.reset(), this.messageCtx.reset(), this.uploadCtx.reset();
5850
- }, this.reconcileAfterStream = (c) => this.activeSessionPollingCtx.reconcileAfterStream(c), !j.pollingIntervalsSeconds)
5883
+ }, this.reconcileAfterStream = (l) => this.activeSessionPollingCtx.reconcileAfterStream(l), !j.pollingIntervalsSeconds)
5851
5884
  throw Error(
5852
5885
  "Widget polling values are not defined, did you call WidgetCtx.initialize()"
5853
5886
  );
5854
- this.config = e, this.getRequestConfig = r ?? (() => this.config), this.getClientCapabilities = o, this.org = s, this.agent = t, this.api = (n == null ? void 0 : n.api) ?? new U({ config: e }), this.storageCtx = (n == null ? void 0 : n.storageCtx) ?? (a ? new Ra({ storage: a, config: e }) : void 0), this.modes = l, this.contactCtx = (n == null ? void 0 : n.contactCtx) ?? new he({
5887
+ this.config = e, this.getRequestConfig = r ?? (() => this.config), this.getClientCapabilities = o, this.org = s, this.agent = t, this.api = (n == null ? void 0 : n.api) ?? new U({ config: e }), this.storageCtx = (n == null ? void 0 : n.storageCtx) ?? (a ? new Ka({ storage: a, config: e }) : void 0), this.modes = c, this.contactCtx = (n == null ? void 0 : n.contactCtx) ?? new ge({
5855
5888
  api: this.api,
5856
5889
  config: this.config,
5857
5890
  storageCtx: this.storageCtx
5858
- }), this.sessionCtx = new Ea({
5891
+ }), this.sessionCtx = new Aa({
5859
5892
  config: this.config,
5860
5893
  api: this.api,
5861
5894
  contactCtx: this.contactCtx,
@@ -5876,20 +5909,20 @@ const j = class j {
5876
5909
  getSendsPageContext: () => this.features.pageContext,
5877
5910
  getClientCapabilities: o,
5878
5911
  getRequestConfig: r
5879
- }), this.uploadCtx = new ge(this.api), this.csatCtx = new ke({
5912
+ }), this.uploadCtx = new ke(this.api), this.csatCtx = new be({
5880
5913
  api: this.api,
5881
5914
  sessionCtx: this.sessionCtx,
5882
5915
  messageCtx: this.messageCtx
5883
- }), this.dictationCtx = new Le({
5916
+ }), this.dictationCtx = new Oe({
5884
5917
  api: this.api,
5885
5918
  config: this.config
5886
- }), this.activeSessionPollingCtx = new me({
5919
+ }), this.activeSessionPollingCtx = new he({
5887
5920
  api: this.api,
5888
5921
  config: this.config,
5889
5922
  sessionCtx: this.sessionCtx,
5890
5923
  messageCtx: this.messageCtx,
5891
5924
  sessionPollingIntervalSeconds: j.pollingIntervalsSeconds.session
5892
- }), this.routerCtx = new Na(this);
5925
+ }), this.routerCtx = new Ra(this);
5893
5926
  }
5894
5927
  get streaming() {
5895
5928
  var e, a;
@@ -5900,7 +5933,7 @@ const j = class j {
5900
5933
  * answers the UI asks for, resolved against the current options.
5901
5934
  */
5902
5935
  get features() {
5903
- return Fa(this.agent, this.getRequestConfig());
5936
+ return Oa(this.agent, this.getRequestConfig());
5904
5937
  }
5905
5938
  };
5906
5939
  j.pollingIntervalsSeconds = null, j.initialize = async ({
@@ -5910,32 +5943,32 @@ j.pollingIntervalsSeconds = null, j.initialize = async ({
5910
5943
  getRequestConfig: r
5911
5944
  }) => {
5912
5945
  var s, t;
5913
- const l = await new U({
5946
+ const c = await new U({
5914
5947
  config: e
5915
5948
  }).getExternalWidgetConfig();
5916
- if (!l.data)
5917
- throw g.error("widget config fetch failed", l.error), new Oa(
5949
+ if (!c.data)
5950
+ throw k.error("widget config fetch failed", c.error), new Fa(
5918
5951
  "config-fetch-failed",
5919
5952
  "Failed to fetch widget config",
5920
- l.error
5953
+ c.error
5921
5954
  );
5922
5955
  return j.pollingIntervalsSeconds = {
5923
- session: ((s = l.data) == null ? void 0 : s.sessionPollingIntervalSeconds) || 10,
5924
- sessions: ((t = l.data) == null ? void 0 : t.sessionsPollingIntervalSeconds) || 60
5956
+ session: ((s = c.data) == null ? void 0 : s.sessionPollingIntervalSeconds) || 10,
5957
+ sessions: ((t = c.data) == null ? void 0 : t.sessionsPollingIntervalSeconds) || 60
5925
5958
  }, new j({
5926
5959
  config: e,
5927
5960
  storage: a,
5928
5961
  getClientCapabilities: o,
5929
5962
  getRequestConfig: r,
5930
- modes: l.data.modes || [],
5963
+ modes: c.data.modes || [],
5931
5964
  org: {
5932
- id: l.data.org.id,
5933
- name: l.data.org.name
5965
+ id: c.data.org.id,
5966
+ name: c.data.org.name
5934
5967
  },
5935
- agent: Ka(l.data)
5968
+ agent: La(c.data)
5936
5969
  });
5937
5970
  };
5938
- let G = j;
5971
+ let Z = j;
5939
5972
  function Ya(i, e) {
5940
5973
  return i ? {
5941
5974
  streaming: i.streaming && (e == null ? void 0 : e.streaming) !== !1,
@@ -5961,18 +5994,18 @@ const I = [
5961
5994
  ], Ua = new Set(
5962
5995
  I
5963
5996
  );
5964
- function Y(i) {
5997
+ function X(i) {
5965
5998
  return Ua.has(i);
5966
5999
  }
5967
6000
  function Qa(i) {
5968
6001
  if (!Array.isArray(i)) return I;
5969
6002
  const e = [], a = /* @__PURE__ */ new Set();
5970
6003
  for (const o of i)
5971
- !Y(o) || a.has(o) || (a.add(o), e.push(o));
6004
+ !X(o) || a.has(o) || (a.add(o), e.push(o));
5972
6005
  return e.length > 0 ? e : I;
5973
6006
  }
5974
6007
  function et(i, e) {
5975
- return Y(i) && e.includes(i) ? i : e[0] ?? I[0];
6008
+ return X(i) && e.includes(i) ? i : e[0] ?? I[0];
5976
6009
  }
5977
6010
  function at(i, e) {
5978
6011
  return i === "left" || i === "right" ? i : e === "rtl" ? "left" : "right";
@@ -5981,29 +6014,29 @@ function tt(i) {
5981
6014
  return i === "docked" ? "docked" : "floating";
5982
6015
  }
5983
6016
  export {
5984
- ce as ConnectionAttemptUnavailableError,
5985
- le as ConnectionRequestExpiredError,
6017
+ pe as ConnectionAttemptUnavailableError,
6018
+ ce as ConnectionRequestExpiredError,
5986
6019
  Xa as DictationLevelSmoother,
5987
6020
  S as PrimitiveState,
5988
- G as WidgetCtx,
5989
- Oa as WidgetInitializationError,
5990
- Da as buildSendMessageBody,
6021
+ Z as WidgetCtx,
6022
+ Fa as WidgetInitializationError,
6023
+ Na as buildSendMessageBody,
5991
6024
  q as genUuid,
5992
- xa as getTranslation,
6025
+ qa as getTranslation,
5993
6026
  Wa as isAgentStreamKeepalive,
5994
- ue as isExhaustive,
6027
+ me as isExhaustive,
5995
6028
  H as isRecord,
5996
6029
  Ja as isRtlLanguage,
5997
- Sa as isSupportedLanguage,
6030
+ za as isSupportedLanguage,
5998
6031
  $a as isTurnSteeredPart,
5999
- g as log,
6032
+ k as log,
6000
6033
  Qa as normalizeCompanionLayouts,
6001
6034
  Ya as resolveClientPresentation,
6002
6035
  et as resolveCompanionDefaultLayout,
6003
- Ia as resolveConfigContext,
6004
- Ca as resolveLanguage,
6036
+ Ma as resolveConfigContext,
6037
+ xa as resolveLanguage,
6005
6038
  tt as resolveSidebarMode,
6006
6039
  at as resolveSidebarSide,
6007
- qa as translate
6040
+ Ea as translate
6008
6041
  };
6009
6042
  //# sourceMappingURL=index.js.map