@opencx/widget-core 5.0.0-beta.1 → 5.0.0-beta.10

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.
Files changed (141) hide show
  1. package/dist/index.cjs +9 -9
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +1608 -901
  4. package/dist/index.js.map +1 -1
  5. package/dist/src/api/api-caller.d.ts +102 -3
  6. package/dist/src/api/api-caller.d.ts.map +1 -1
  7. package/dist/src/api/elicitation.d.ts +60 -0
  8. package/dist/src/api/elicitation.d.ts.map +1 -0
  9. package/dist/src/api/schema.d.ts +596 -41
  10. package/dist/src/api/schema.d.ts.map +1 -1
  11. package/dist/src/context/active-session-polling.ctx.d.ts +11 -1
  12. package/dist/src/context/active-session-polling.ctx.d.ts.map +1 -1
  13. package/dist/src/context/message.ctx.d.ts +25 -6
  14. package/dist/src/context/message.ctx.d.ts.map +1 -1
  15. package/dist/src/context/resolve-client-presentation.d.ts +5 -0
  16. package/dist/src/context/resolve-client-presentation.d.ts.map +1 -0
  17. package/dist/src/context/router.ctx.d.ts +8 -10
  18. package/dist/src/context/router.ctx.d.ts.map +1 -1
  19. package/dist/src/context/session.ctx.d.ts +18 -1
  20. package/dist/src/context/session.ctx.d.ts.map +1 -1
  21. package/dist/src/context/upload.ctx.d.ts +23 -0
  22. package/dist/src/context/upload.ctx.d.ts.map +1 -0
  23. package/dist/src/context/widget-agent.d.ts +4 -4
  24. package/dist/src/context/widget-agent.d.ts.map +1 -1
  25. package/dist/src/context/widget.ctx.d.ts +19 -6
  26. package/dist/src/context/widget.ctx.d.ts.map +1 -1
  27. package/dist/src/index.d.ts +5 -0
  28. package/dist/src/index.d.ts.map +1 -1
  29. package/dist/src/translation/ar.d.ts.map +1 -1
  30. package/dist/src/translation/bg.d.ts.map +1 -1
  31. package/dist/src/translation/bn.d.ts.map +1 -1
  32. package/dist/src/translation/cs.d.ts.map +1 -1
  33. package/dist/src/translation/da.d.ts.map +1 -1
  34. package/dist/src/translation/de.d.ts.map +1 -1
  35. package/dist/src/translation/el.d.ts.map +1 -1
  36. package/dist/src/translation/en.d.ts.map +1 -1
  37. package/dist/src/translation/es.d.ts.map +1 -1
  38. package/dist/src/translation/et.d.ts.map +1 -1
  39. package/dist/src/translation/fi.d.ts.map +1 -1
  40. package/dist/src/translation/fil.d.ts.map +1 -1
  41. package/dist/src/translation/fr.d.ts.map +1 -1
  42. package/dist/src/translation/hi.d.ts.map +1 -1
  43. package/dist/src/translation/hr.d.ts.map +1 -1
  44. package/dist/src/translation/hu.d.ts.map +1 -1
  45. package/dist/src/translation/index.d.ts +24 -0
  46. package/dist/src/translation/index.d.ts.map +1 -1
  47. package/dist/src/translation/is.d.ts.map +1 -1
  48. package/dist/src/translation/it.d.ts.map +1 -1
  49. package/dist/src/translation/ja.d.ts.map +1 -1
  50. package/dist/src/translation/ko.d.ts.map +1 -1
  51. package/dist/src/translation/lb.d.ts.map +1 -1
  52. package/dist/src/translation/lt.d.ts.map +1 -1
  53. package/dist/src/translation/lv.d.ts.map +1 -1
  54. package/dist/src/translation/mt.d.ts.map +1 -1
  55. package/dist/src/translation/nb.d.ts.map +1 -1
  56. package/dist/src/translation/nl.d.ts.map +1 -1
  57. package/dist/src/translation/no.d.ts.map +1 -1
  58. package/dist/src/translation/pl.d.ts.map +1 -1
  59. package/dist/src/translation/pt.d.ts.map +1 -1
  60. package/dist/src/translation/ro.d.ts.map +1 -1
  61. package/dist/src/translation/ru.d.ts.map +1 -1
  62. package/dist/src/translation/sk.d.ts.map +1 -1
  63. package/dist/src/translation/sv.d.ts.map +1 -1
  64. package/dist/src/translation/th.d.ts.map +1 -1
  65. package/dist/src/translation/tr.d.ts.map +1 -1
  66. package/dist/src/translation/ur.d.ts.map +1 -1
  67. package/dist/src/translation/vi.d.ts.map +1 -1
  68. package/dist/src/translation/zh-cn.d.ts.map +1 -1
  69. package/dist/src/types/component-name.d.ts +1 -1
  70. package/dist/src/types/component-name.d.ts.map +1 -1
  71. package/dist/src/types/messages.d.ts +14 -1
  72. package/dist/src/types/messages.d.ts.map +1 -1
  73. package/dist/src/types/widget-config.d.ts +29 -6
  74. package/dist/src/types/widget-config.d.ts.map +1 -1
  75. package/package.json +6 -5
  76. package/dist/src/__tests__/api/agent-stream-parts.spec.d.ts +0 -2
  77. package/dist/src/__tests__/api/agent-stream-parts.spec.d.ts.map +0 -1
  78. package/dist/src/__tests__/api/dictation-mint-cache.spec.d.ts +0 -2
  79. package/dist/src/__tests__/api/dictation-mint-cache.spec.d.ts.map +0 -1
  80. package/dist/src/__tests__/api/widget-api-wire.spec.d.ts +0 -2
  81. package/dist/src/__tests__/api/widget-api-wire.spec.d.ts.map +0 -1
  82. package/dist/src/__tests__/api-caller.mock.d.ts +0 -2
  83. package/dist/src/__tests__/api-caller.mock.d.ts.map +0 -1
  84. package/dist/src/__tests__/context/contact/auth/auto-create-unverified-anonymous.spec.d.ts +0 -1
  85. package/dist/src/__tests__/context/contact/auth/auto-create-unverified-anonymous.spec.d.ts.map +0 -1
  86. package/dist/src/__tests__/context/contact/auth/auto-create-unverified-with-user-data-provided-by-org.spec.d.ts +0 -1
  87. package/dist/src/__tests__/context/contact/auth/auto-create-unverified-with-user-data-provided-by-org.spec.d.ts.map +0 -1
  88. package/dist/src/__tests__/context/contact/auth/manually-create-unverified-with-user-data-provided-by-user.spec.d.ts +0 -1
  89. package/dist/src/__tests__/context/contact/auth/manually-create-unverified-with-user-data-provided-by-user.spec.d.ts.map +0 -1
  90. package/dist/src/__tests__/context/contact/auth/with-secure-token.spec.d.ts +0 -1
  91. package/dist/src/__tests__/context/contact/auth/with-secure-token.spec.d.ts.map +0 -1
  92. package/dist/src/__tests__/context/contact/should-collect-data.spec.d.ts +0 -1
  93. package/dist/src/__tests__/context/contact/should-collect-data.spec.d.ts.map +0 -1
  94. package/dist/src/__tests__/context/contact-ctx.create-failure.spec.d.ts +0 -2
  95. package/dist/src/__tests__/context/contact-ctx.create-failure.spec.d.ts.map +0 -1
  96. package/dist/src/__tests__/context/dictation-ctx.spec.d.ts +0 -1
  97. package/dist/src/__tests__/context/dictation-ctx.spec.d.ts.map +0 -1
  98. package/dist/src/__tests__/context/message/merge-send-context.spec.d.ts +0 -2
  99. package/dist/src/__tests__/context/message/merge-send-context.spec.d.ts.map +0 -1
  100. package/dist/src/__tests__/context/message/on-message-received-hook.spec.d.ts +0 -1
  101. package/dist/src/__tests__/context/message/on-message-received-hook.spec.d.ts.map +0 -1
  102. package/dist/src/__tests__/context/message/pending-user-messages.spec.d.ts +0 -1
  103. package/dist/src/__tests__/context/message/pending-user-messages.spec.d.ts.map +0 -1
  104. package/dist/src/__tests__/context/message/sent-text-history.spec.d.ts +0 -1
  105. package/dist/src/__tests__/context/message/sent-text-history.spec.d.ts.map +0 -1
  106. package/dist/src/__tests__/context/message-ctx.agent-handlers.spec.d.ts +0 -2
  107. package/dist/src/__tests__/context/message-ctx.agent-handlers.spec.d.ts.map +0 -1
  108. package/dist/src/__tests__/context/message-ctx.client-context.spec.d.ts +0 -2
  109. package/dist/src/__tests__/context/message-ctx.client-context.spec.d.ts.map +0 -1
  110. package/dist/src/__tests__/context/message-ctx.mentions.spec.d.ts +0 -2
  111. package/dist/src/__tests__/context/message-ctx.mentions.spec.d.ts.map +0 -1
  112. package/dist/src/__tests__/context/message-ctx.page-mark-chips.spec.d.ts +0 -2
  113. package/dist/src/__tests__/context/message-ctx.page-mark-chips.spec.d.ts.map +0 -1
  114. package/dist/src/__tests__/context/message-ctx.send-acceptance.spec.d.ts +0 -2
  115. package/dist/src/__tests__/context/message-ctx.send-acceptance.spec.d.ts.map +0 -1
  116. package/dist/src/__tests__/context/message-ctx.send-features.spec.d.ts +0 -2
  117. package/dist/src/__tests__/context/message-ctx.send-features.spec.d.ts.map +0 -1
  118. package/dist/src/__tests__/context/reconcile-after-stream.spec.d.ts +0 -1
  119. package/dist/src/__tests__/context/reconcile-after-stream.spec.d.ts.map +0 -1
  120. package/dist/src/__tests__/context/restore-last-session.spec.d.ts +0 -2
  121. package/dist/src/__tests__/context/restore-last-session.spec.d.ts.map +0 -1
  122. package/dist/src/__tests__/context/session-ctx.stale-token-retry.spec.d.ts +0 -2
  123. package/dist/src/__tests__/context/session-ctx.stale-token-retry.spec.d.ts.map +0 -1
  124. package/dist/src/__tests__/context/storage-ctx.spec.d.ts +0 -2
  125. package/dist/src/__tests__/context/storage-ctx.spec.d.ts.map +0 -1
  126. package/dist/src/__tests__/context/streaming-engine.spec.d.ts +0 -1
  127. package/dist/src/__tests__/context/streaming-engine.spec.d.ts.map +0 -1
  128. package/dist/src/__tests__/context/widget-ctx.features.spec.d.ts +0 -1
  129. package/dist/src/__tests__/context/widget-ctx.features.spec.d.ts.map +0 -1
  130. package/dist/src/__tests__/dictation/dictation-commands.utils.spec.d.ts +0 -2
  131. package/dist/src/__tests__/dictation/dictation-commands.utils.spec.d.ts.map +0 -1
  132. package/dist/src/__tests__/test-utils.d.ts +0 -448
  133. package/dist/src/__tests__/test-utils.d.ts.map +0 -1
  134. package/dist/src/__tests__/translation.spec.d.ts +0 -2
  135. package/dist/src/__tests__/translation.spec.d.ts.map +0 -1
  136. package/dist/src/__tests__/utils/Poller.spec.d.ts +0 -2
  137. package/dist/src/__tests__/utils/Poller.spec.d.ts.map +0 -1
  138. package/dist/src/__tests__/utils/PrimitiveState.spec.d.ts +0 -2
  139. package/dist/src/__tests__/utils/PrimitiveState.spec.d.ts.map +0 -1
  140. package/dist/src/__tests__/utils/companion-layout.spec.d.ts +0 -2
  141. package/dist/src/__tests__/utils/companion-layout.spec.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,174 +1,324 @@
1
- import Y from "openapi-fetch";
2
- import Q from "lodash.isequal";
3
- import { v4 as B } from "uuid";
4
- const Na = (i) => i.type === "data-keepalive", Ra = (i) => i.type === "data-turn-steered", N = "[opencx]", u = {
1
+ import { z as h } from "zod";
2
+ import se from "openapi-fetch";
3
+ import oe from "lodash.isequal";
4
+ import { v4 as N } from "uuid";
5
+ const Ga = (i) => i.type === "data-keepalive", $a = (i) => i.type === "data-turn-steered", F = 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(F).optional(),
12
+ items: h.object({
13
+ enum: h.array(h.string()).optional(),
14
+ anyOf: h.array(F).optional()
15
+ }).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
+ })
36
+ })
37
+ })
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
+ })
46
+ ), O = "[opencx]", k = {
5
47
  warn: (i, ...e) => {
6
- console.warn(`${N} ${i}`, ...e);
48
+ console.warn(`${O} ${i}`, ...e);
7
49
  },
8
50
  error: (i, ...e) => {
9
- console.error(`${N} ${i}`, ...e);
51
+ console.error(`${O} ${i}`, ...e);
10
52
  }
11
- }, X = (i) => {
12
- u.error("request failed", i.error);
13
- }, ee = (i) => {
14
- const e = Y({
53
+ }, _e = (i) => {
54
+ k.error("request failed", i.error);
55
+ }, le = (i) => {
56
+ const e = se({
15
57
  baseUrl: i.baseUrl
16
58
  }), t = {
17
59
  onRequest: i.onRequest,
18
60
  onResponse: i.onResponse,
19
- onError: i.onError || X
61
+ onError: i.onError || _e
20
62
  };
21
63
  return e.use(t), e;
22
- }, ae = "/backend/widget/v5/chat/stream", te = "/backend/widget/v5/chat/{sessionId}/stream", R = (i, e, t) => `${i.replace(/\/$/, "")}${t ? e.replace("{sessionId}", encodeURIComponent(t)) : e}`;
23
- class K {
64
+ };
65
+ class ce extends Error {
66
+ constructor() {
67
+ super("This connection request expired. Preparing a new request."), this.name = "ConnectionRequestExpiredError";
68
+ }
69
+ }
70
+ class pe extends Error {
71
+ constructor() {
72
+ super("This connection attempt is no longer available."), this.name = "ConnectionAttemptUnavailableError";
73
+ }
74
+ }
75
+ const de = "/backend/widget/v5/chat/stream", ue = "/backend/widget/v5/chat/{sessionId}/stream", U = (i, e, t) => `${i.replace(/\/$/, "")}${t ? e.replace("{sessionId}", encodeURIComponent(t)) : e}`;
76
+ class B {
24
77
  constructor({ config: e }) {
25
- var _, l;
26
- this.userToken = null, this.constructClientOptions = (a) => {
27
- const n = this.config.apiUrl || "https://api.open.cx", s = {
78
+ var r, l;
79
+ this.userToken = null, this.constructClientOptions = (s) => {
80
+ const a = this.config.apiUrl || "https://api.open.cx", n = {
28
81
  "X-Bot-Token": this.config.token,
29
82
  "Content-Type": "application/json",
30
83
  Accept: "application/json",
31
- Authorization: a ? `Bearer ${a}` : void 0
84
+ Authorization: s ? `Bearer ${s}` : void 0
32
85
  };
33
- return { baseUrl: n, headers: s };
86
+ return { baseUrl: a, headers: n };
34
87
  }, this.createOpenAPIClient = ({
35
- baseUrl: a,
36
- headers: n
37
- }) => ee({
38
- baseUrl: a,
39
- onRequest: ({ request: s }) => {
40
- Object.entries(n).forEach(([r, c]) => {
41
- c && s.headers.set(r, c);
88
+ baseUrl: s,
89
+ headers: a
90
+ }) => le({
91
+ baseUrl: s,
92
+ onRequest: ({ request: n }) => {
93
+ Object.entries(a).forEach(([c, d]) => {
94
+ d && n.headers.set(c, d);
42
95
  });
43
96
  }
44
- }), this.setAuthToken = (a) => {
45
- this.userToken = a;
46
- const { baseUrl: n, headers: s } = this.constructClientOptions(a);
47
- this.client = this.createOpenAPIClient({ baseUrl: n, headers: s });
97
+ }), this.listApprovalPreferences = async () => {
98
+ const { baseUrl: s, headers: a } = this.getStreamAuthContext(), n = await fetch(
99
+ `${s}/backend/widget/v5/connections/approval-preferences`,
100
+ { headers: a }
101
+ );
102
+ if (!n.ok) throw new Error("Could not load permissions.");
103
+ return re.parse(await n.json());
104
+ }, this.revokeApprovalPreference = async (s, a) => {
105
+ const { baseUrl: n, headers: c } = this.getStreamAuthContext();
106
+ if (!(await fetch(
107
+ `${n}/backend/widget/v5/connections/${encodeURIComponent(s)}/approval-preferences/${encodeURIComponent(a)}`,
108
+ { method: "DELETE", headers: c }
109
+ )).ok) throw new Error("Could not reset permission.");
110
+ }, this.listElicitations = async (s, a) => {
111
+ const { baseUrl: n, headers: c } = this.getStreamAuthContext(), d = await fetch(
112
+ `${n}/backend/widget/v5/connections/elicitation/${encodeURIComponent(s)}`,
113
+ { headers: c, signal: a }
114
+ );
115
+ if (!d.ok) throw new Error("Could not load the request.");
116
+ return ie.parse(await d.json());
117
+ }, this.answerElicitation = async (s, a, n) => {
118
+ const { baseUrl: c, headers: d } = this.getStreamAuthContext(), _ = await fetch(
119
+ `${c}/backend/widget/v5/connections/elicitation/${encodeURIComponent(s)}/${encodeURIComponent(a)}`,
120
+ {
121
+ method: "POST",
122
+ headers: { ...d, "Content-Type": "application/json" },
123
+ body: JSON.stringify(n)
124
+ }
125
+ );
126
+ if (!_.ok)
127
+ throw new Error(
128
+ _.status === 400 ? "Check your answers and try again." : "This request has ended. Ask the agent to try again."
129
+ );
130
+ }, this.listConnections = async (s) => {
131
+ const { data: a, error: n } = await this.client.GET(
132
+ "/backend/widget/v5/connections",
133
+ { signal: s }
134
+ );
135
+ if (n || !a)
136
+ throw new Error("Could not load connections. Sign in and try again.");
137
+ return a;
138
+ }, this.startConnection = async (s, a, n) => {
139
+ const { data: c, error: d, response: _ } = await this.client.POST(
140
+ "/backend/widget/v5/connections/{serverId}/start",
141
+ {
142
+ params: { path: { serverId: s } },
143
+ body: { request_id: a },
144
+ signal: n
145
+ }
146
+ );
147
+ if (_.status === 410) throw new ce();
148
+ if (_.status === 404)
149
+ throw new Error("This connection request is no longer available.");
150
+ if (d || !c)
151
+ throw new Error("Could not start this connection. Please try again.");
152
+ return c;
153
+ }, this.getConnectionAttempt = async (s, a, n) => {
154
+ const { data: c, error: d, response: _ } = await this.client.GET(
155
+ "/backend/widget/v5/connections/{serverId}/attempts/{attemptId}",
156
+ {
157
+ params: { path: { serverId: s, attemptId: a } },
158
+ signal: n
159
+ }
160
+ );
161
+ if ([401, 403, 404].includes(_.status))
162
+ throw new pe();
163
+ if (d || !c)
164
+ throw new Error(`Could not check the connection (${_.status}).`);
165
+ return c.status;
166
+ }, this.disconnectConnection = async (s) => {
167
+ const { error: a } = await this.client.DELETE(
168
+ "/backend/widget/v5/connections/{serverId}",
169
+ {
170
+ params: { path: { serverId: s } }
171
+ }
172
+ );
173
+ if (a) throw new Error("Could not disconnect. Please try again.");
174
+ }, this.setAuthToken = (s) => {
175
+ this.userToken = s;
176
+ const { baseUrl: a, headers: n } = this.constructClientOptions(s);
177
+ this.client = this.createOpenAPIClient({ baseUrl: a, headers: n });
48
178
  }, this.getStreamAuthContext = () => {
49
- const { baseUrl: a, headers: n } = this.constructClientOptions(this.userToken), s = {};
50
- for (const [r, c] of Object.entries(n))
51
- typeof c == "string" && (["content-type", "accept"].includes(r.toLowerCase()) || (s[r] = c));
52
- return { baseUrl: a, headers: s };
179
+ const { baseUrl: s, headers: a } = this.constructClientOptions(this.userToken), n = {};
180
+ for (const [c, d] of Object.entries(a))
181
+ typeof d == "string" && (["content-type", "accept"].includes(c.toLowerCase()) || (n[c] = d));
182
+ return { baseUrl: s, headers: n };
53
183
  }, this.getStreamTransportOptions = () => {
54
- const { baseUrl: a, headers: n } = this.getStreamAuthContext();
184
+ const { baseUrl: s, headers: a } = this.getStreamAuthContext();
55
185
  return {
56
- api: R(a, ae),
57
- reconnectApi: (s) => R(a, te, s),
58
- headers: n
186
+ api: U(s, de),
187
+ reconnectApi: (n) => U(s, ue, n),
188
+ headers: a
59
189
  };
60
- }, this.stopStream = async (a) => {
61
- const { response: n } = await this.client.POST(
190
+ }, this.stopStream = async (s) => {
191
+ const { response: a } = await this.client.POST(
62
192
  "/backend/widget/v5/chat/{sessionId}/stop",
63
- { params: { path: { sessionId: a } } }
193
+ { params: { path: { sessionId: s } } }
64
194
  );
65
- if (!n.ok)
66
- throw new Error(`Failed to stop stream: ${n.status}`);
67
- }, this.getAgentTurnMessages = async (a) => {
68
- const { data: n, response: s } = await this.client.GET(
195
+ if (!a.ok)
196
+ throw new Error(`Failed to stop stream: ${a.status}`);
197
+ }, this.sendPageReply = async (s, a) => {
198
+ try {
199
+ await this.client.POST("/backend/widget/v5/chat/{sessionId}/page-reply", {
200
+ params: { path: { sessionId: s } },
201
+ body: a
202
+ });
203
+ } catch {
204
+ }
205
+ }, this.getAgentTurnMessages = async (s, a) => {
206
+ const { data: n, response: c } = await this.client.GET(
69
207
  "/backend/widget/v5/chat/{sessionId}/messages",
70
- { params: { path: { sessionId: a } } }
208
+ {
209
+ params: {
210
+ path: { sessionId: s },
211
+ query: {
212
+ toolActivity: a == null ? void 0 : a.toolActivity,
213
+ reasoning: (a == null ? void 0 : a.reasoning) === void 0 ? void 0 : a.reasoning ? "true" : "false"
214
+ }
215
+ }
216
+ }
71
217
  );
72
- return n || (u.warn("agent turn messages fetch failed", s.status), null);
218
+ return n ? {
219
+ ...n,
220
+ handled_connection_request_ids: n.handled_connection_request_ids ?? []
221
+ } : (k.warn("agent turn messages fetch failed", c.status), null);
73
222
  }, this.createDictationSession = async ({
74
- language: a
223
+ language: s
75
224
  }) => {
76
- const { data: n, response: s } = await this.client.POST(
225
+ const { data: a, response: n } = await this.client.POST(
77
226
  "/backend/widget/v5/dictation/sessions",
78
- { body: a ? { language: a } : {} }
227
+ { body: s ? { language: s } : {} }
79
228
  );
80
- if (!n)
81
- throw new Error(`Failed to start dictation: ${s.status}`);
82
- return n;
229
+ if (!a)
230
+ throw new Error(`Failed to start dictation: ${n.status}`);
231
+ return a;
83
232
  }, this.getExternalWidgetConfig = async () => await this.client.GET("/backend/widget/v2/config", {
84
233
  params: {
85
234
  header: { "x-bot-token": this.config.token }
86
235
  }
87
- }), this.sendMessage = async (a, n) => await this.client.POST("/backend/widget/v2/chat/send", {
88
- body: a,
89
- signal: n
90
- }), this.createUnverifiedContact = async (a) => await this.client.POST(
236
+ }), this.sendMessage = async (s, a) => await this.client.POST("/backend/widget/v2/chat/send", {
237
+ body: s,
238
+ signal: a
239
+ }), this.createUnverifiedContact = async (s) => await this.client.POST(
91
240
  "/backend/widget/v2/contact/create-unverified",
92
241
  {
93
242
  params: { header: { "x-bot-token": this.config.token } },
94
- body: a
243
+ body: s
95
244
  }
96
- ), this.createSession = async (a) => await this.client.POST("/backend/widget/v2/create-session", {
97
- body: a
245
+ ), this.createSession = async (s, a) => await this.client.POST("/backend/widget/v2/create-session", {
246
+ body: s,
247
+ signal: a
98
248
  }), this.pollSessionAndHistory = async ({
99
- sessionId: a,
100
- abortSignal: n
249
+ sessionId: s,
250
+ abortSignal: a
101
251
  }) => await this.client.GET("/backend/widget/v2/poll/{sessionId}", {
102
- params: { path: { sessionId: a } },
103
- signal: n
252
+ params: { path: { sessionId: s } },
253
+ signal: a
104
254
  }), this.getSessions = async ({
105
- cursor: a,
106
- filters: n,
107
- abortSignal: s
255
+ cursor: s,
256
+ filters: a,
257
+ abortSignal: n
108
258
  }) => await this.client.GET("/backend/widget/v2/sessions", {
109
259
  params: {
110
260
  query: {
111
- offset: a,
112
- filters: JSON.stringify(n)
261
+ offset: s,
262
+ filters: JSON.stringify(a)
113
263
  }
114
264
  },
115
- signal: s
265
+ signal: n
116
266
  }), this.uploadFile = async ({
117
- file: a,
118
- abortSignal: n,
119
- onProgress: s
120
- }) => new Promise((r, c) => {
121
- var w;
122
- const p = new FormData();
123
- p.append("file", a);
124
- const d = new XMLHttpRequest();
125
- if (n && (n.addEventListener("abort", () => {
126
- d.abort(), c(new DOMException("Aborted", "AbortError"));
127
- }), n.aborted)) {
128
- c(new DOMException("Aborted", "AbortError"));
267
+ file: s,
268
+ abortSignal: a,
269
+ onProgress: n
270
+ }) => new Promise((c, d) => {
271
+ var f;
272
+ const _ = new FormData();
273
+ _.append("file", s);
274
+ const p = new XMLHttpRequest();
275
+ if (a && (a.addEventListener("abort", () => {
276
+ p.abort(), d(new DOMException("Aborted", "AbortError"));
277
+ }), a.aborted)) {
278
+ d(new DOMException("Aborted", "AbortError"));
129
279
  return;
130
280
  }
131
- d.upload.addEventListener("progress", (b) => {
132
- if (b.lengthComputable && s) {
133
- const f = Math.round(b.loaded / b.total * 100);
134
- s(f);
281
+ p.upload.addEventListener("progress", (b) => {
282
+ if (b.lengthComputable && n) {
283
+ const w = Math.round(b.loaded / b.total * 100);
284
+ n(w);
135
285
  }
136
- }), d.addEventListener("load", () => {
137
- if (d.status >= 200 && d.status < 300)
286
+ }), p.addEventListener("load", () => {
287
+ if (p.status >= 200 && p.status < 300)
138
288
  try {
139
- const b = JSON.parse(d.responseText);
140
- r(b);
289
+ const b = JSON.parse(p.responseText);
290
+ c(b);
141
291
  } catch (b) {
142
- c(new Error(`Failed to parse response: ${b}`));
292
+ d(new Error(`Failed to parse response: ${b}`));
143
293
  }
144
294
  else
145
- c(new Error(`Upload failed with status: ${d.status}`));
146
- }), d.addEventListener("error", () => {
147
- c(new Error("Network error occurred"));
148
- }), d.addEventListener("timeout", () => {
149
- c(new Error("Upload timed out"));
295
+ d(new Error(`Upload failed with status: ${p.status}`));
296
+ }), p.addEventListener("error", () => {
297
+ d(new Error("Network error occurred"));
298
+ }), p.addEventListener("timeout", () => {
299
+ d(new Error("Upload timed out"));
150
300
  });
151
- const { baseUrl: m } = this.constructClientOptions(this.userToken), g = `${m}/backend/widget/v2/upload`;
152
- d.open("POST", g), d.setRequestHeader("X-Bot-Token", this.config.token), this.userToken ?? ((w = this.config.user) == null ? void 0 : w.token) ? d.setRequestHeader("Authorization", `Bearer ${this.userToken}`) : u.error("user token not set"), d.send(p);
153
- }), this.vote = async (a) => await this.client.POST("/backend/widget/v2/chat/vote", { body: a }), this.resolveSession = async (a, n) => await this.client.POST("/backend/widget/v2/session/resolve", {
154
- body: a,
155
- signal: n
156
- }), this.createStateCheckpoint = async (a) => await this.client.POST("/backend/widget/v2/checkpoint", {
157
- body: a
158
- }), this.submitCsat = async (a) => await this.client.POST("/backend/widget/v2/submit-csat", { body: a }), this.config = e, this.userToken = ((_ = e.user) == null ? void 0 : _.token) || null;
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
+ }), this.vote = async (s) => await this.client.POST("/backend/widget/v2/chat/vote", { body: s }), this.resolveSession = async (s, a) => await this.client.POST("/backend/widget/v2/session/resolve", {
304
+ body: s,
305
+ signal: a
306
+ }), this.createStateCheckpoint = async (s) => await this.client.POST("/backend/widget/v2/checkpoint", {
307
+ body: s
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;
159
309
  const { baseUrl: t, headers: o } = this.constructClientOptions(
160
310
  (l = e.user) == null ? void 0 : l.token
161
311
  );
162
312
  this.client = this.createOpenAPIClient({ baseUrl: t, headers: o });
163
313
  }
164
314
  }
165
- function se(i, e) {
166
- u.error(`missing case for ${i} in ${e}`);
315
+ function me(i, e) {
316
+ k.error(`missing case for ${i} in ${e}`);
167
317
  }
168
- class j {
318
+ class S {
169
319
  constructor(e) {
170
320
  this.subscribers = /* @__PURE__ */ new Set(), this.get = () => this.state, this.set = (t) => {
171
- Q(this.state, t) || (this.state = t, this.notifySubscribers(t));
321
+ oe(this.state, t) || (this.state = t, this.notifySubscribers(t));
172
322
  }, this.setPartial = (t) => {
173
323
  if (t == null) return;
174
324
  const o = { ...this.state, ...t };
@@ -176,11 +326,11 @@ class j {
176
326
  }, this.reset = () => {
177
327
  this.set(this.initialState);
178
328
  }, this.notifySubscribers = (t) => {
179
- Array.from(this.subscribers).forEach((_) => {
329
+ Array.from(this.subscribers).forEach((r) => {
180
330
  try {
181
- _(t);
331
+ r(t);
182
332
  } catch (l) {
183
- u.error("state subscriber threw", l);
333
+ k.error("state subscriber threw", l);
184
334
  }
185
335
  });
186
336
  }, this.subscribe = (t) => (this.subscribers.add(t), () => {
@@ -188,9 +338,9 @@ class j {
188
338
  }), this.state = e, this.initialState = e;
189
339
  }
190
340
  }
191
- class V {
341
+ class G {
192
342
  constructor() {
193
- this.state = new j({
343
+ this.state = new S({
194
344
  isPolling: !1,
195
345
  isError: !1
196
346
  }), this.abortController = new AbortController(), this.reset = () => {
@@ -198,26 +348,26 @@ class V {
198
348
  this.abortController.abort("Resetting poller"), (e = this.stopPolling) == null || e.call(this), this.stopPolling = null;
199
349
  }, this.stopPolling = null, this.startPolling = (e, t) => {
200
350
  if (this.stopPolling) return;
201
- const o = [], _ = async () => {
351
+ const o = [], r = async () => {
202
352
  this.abortController = new AbortController(), this.state.setPartial({ isPolling: !0 });
203
353
  try {
204
354
  await e(this.abortController.signal);
205
355
  } catch (l) {
206
356
  if (this.abortController.signal.aborted)
207
357
  return;
208
- u.error("failed to poll", l), this.state.setPartial({ isError: !0 });
358
+ k.error("failed to poll", l), this.state.setPartial({ isError: !0 });
209
359
  } finally {
210
360
  this.state.setPartial({ isPolling: !1 });
211
361
  }
212
- this.abortController.signal.aborted || o.push(setTimeout(_, t));
362
+ this.abortController.signal.aborted || o.push(setTimeout(r, t));
213
363
  };
214
- _(), this.stopPolling = () => {
364
+ r(), this.stopPolling = () => {
215
365
  o.forEach(clearTimeout), this.state.reset();
216
366
  };
217
367
  };
218
368
  }
219
369
  }
220
- function H(i) {
370
+ function $(i) {
221
371
  try {
222
372
  const e = i();
223
373
  return e instanceof Promise ? e.then((t) => ({ data: t })).catch((t) => ({ error: t })) : { data: e };
@@ -225,257 +375,280 @@ function H(i) {
225
375
  return { error: e };
226
376
  }
227
377
  }
228
- class ne {
378
+ class he {
229
379
  constructor({
230
380
  api: e,
231
381
  config: t,
232
382
  sessionCtx: o,
233
- messageCtx: _,
383
+ messageCtx: r,
234
384
  sessionPollingIntervalSeconds: l
235
385
  }) {
236
- this.poller = new V(), this.fetchSessionAndFullHistoryAbortController = new AbortController(), this.reconcileAbortController = new AbortController(), this.reconcilingSessionId = null, this.registerPolling = () => {
237
- this.sessionCtx.sessionState.subscribe(({ session: a }) => {
238
- a != null && a.id ? this.poller.startPolling(async (n) => {
239
- this.fetchSessionAndHistory({ sessionId: a.id, abortSignal: n });
240
- }, this.sessionPollingIntervalSeconds * 1e3) : this.poller.reset();
241
- }), this.sessionCtx.sessionState.subscribe(({ session: a }) => {
242
- if (a != null && a.id && !a.isOpened)
243
- try {
244
- this.fetchSessionAndFullHistoryAbortController = new AbortController(), this.fetchSessionAndHistory({
245
- sessionId: a.id,
246
- abortSignal: this.fetchSessionAndFullHistoryAbortController.signal
386
+ this.poller = new G(), this.fetchSessionAndFullHistoryAbortController = new AbortController(), this.reconcileAbortController = new AbortController(), this.subscriptions = [], this.reconcilingSessionId = null, this.registerPolling = () => {
387
+ this.subscriptions.push(
388
+ this.sessionCtx.sessionState.subscribe(({ session: s }) => {
389
+ s != null && s.id ? this.poller.startPolling(async (a) => {
390
+ this.fetchSessionAndHistory({
391
+ sessionId: s.id,
392
+ abortSignal: a
247
393
  });
248
- } catch (n) {
249
- this.fetchSessionAndFullHistoryAbortController.signal.aborted || u.error("failed to fetch session and full history", n);
250
- }
251
- else
252
- this.fetchSessionAndFullHistoryAbortController.abort();
253
- }), this.sessionCtx.sessionState.subscribe(({ session: a }) => {
254
- this.reconcilingSessionId !== null && (a == null ? void 0 : a.id) !== this.reconcilingSessionId && this.reconcileAbortController.abort();
255
- });
256
- }, this.reconcileAfterStream = async (a) => {
394
+ }, this.sessionPollingIntervalSeconds * 1e3) : this.poller.reset();
395
+ })
396
+ ), this.subscriptions.push(
397
+ this.sessionCtx.sessionState.subscribe(({ session: s }) => {
398
+ if (s != null && s.id && !s.isOpened)
399
+ try {
400
+ this.fetchSessionAndFullHistoryAbortController = new AbortController(), this.fetchSessionAndHistory({
401
+ sessionId: s.id,
402
+ abortSignal: this.fetchSessionAndFullHistoryAbortController.signal
403
+ });
404
+ } catch (a) {
405
+ this.fetchSessionAndFullHistoryAbortController.signal.aborted || k.error("failed to fetch session and full history", a);
406
+ }
407
+ else
408
+ this.fetchSessionAndFullHistoryAbortController.abort();
409
+ })
410
+ ), this.subscriptions.push(
411
+ this.sessionCtx.sessionState.subscribe(({ session: s }) => {
412
+ this.reconcilingSessionId !== null && (s == null ? void 0 : s.id) !== this.reconcilingSessionId && this.reconcileAbortController.abort();
413
+ })
414
+ );
415
+ }, this.dispose = () => {
416
+ this.poller.reset(), this.fetchSessionAndFullHistoryAbortController.abort(), this.reconcileAbortController.abort(), this.reconcilingSessionId = null, this.subscriptions.forEach((s) => s()), this.subscriptions = [];
417
+ }, this.reconcileAfterStream = async (s) => {
257
418
  this.reconcileAbortController.abort(), this.reconcileAbortController = new AbortController();
258
- const { signal: n } = this.reconcileAbortController;
259
- this.reconcilingSessionId = a;
419
+ const { signal: a } = this.reconcileAbortController;
420
+ this.reconcilingSessionId = s;
260
421
  try {
261
- await this.fetchSessionAndHistory({ sessionId: a, abortSignal: n });
262
- } catch (s) {
263
- if (!n.aborted) throw s;
422
+ await this.fetchSessionAndHistory({ sessionId: s, abortSignal: a });
423
+ } catch (n) {
424
+ if (!a.aborted) throw n;
264
425
  } finally {
265
- this.reconcilingSessionId === a && (this.reconcilingSessionId = null);
426
+ this.reconcilingSessionId === s && (this.reconcilingSessionId = null);
266
427
  }
267
428
  }, this.fetchSessionAndHistory = async ({
268
- sessionId: a,
269
- abortSignal: n
429
+ sessionId: s,
430
+ abortSignal: a
270
431
  }) => {
271
- const s = this.messageCtx.state.get().messages.length === 0;
272
- s && this.messageCtx.state.setPartial({ isInitialFetchLoading: !0 });
273
- const { data: r } = await this.api.pollSessionAndHistory({
274
- sessionId: a,
275
- abortSignal: n
432
+ const n = this.messageCtx.state.get().messages.length === 0;
433
+ n && this.messageCtx.state.setPartial({ isInitialFetchLoading: !0 });
434
+ const { data: c } = await this.api.pollSessionAndHistory({
435
+ sessionId: s,
436
+ abortSignal: a
276
437
  });
277
- if (r != null && r.session && (this.sessionCtx.sessionState.setPartial({ session: r.session }), this.sessionCtx.setSessions([r.session])), r != null && r.history && r.history.length > 0) {
278
- const c = this.messageCtx.state.get().messages, p = r.history.map(this.mapHistoryToMessage).filter((d) => d !== null).filter(
279
- (d) => !c.some((m) => m.id === d.id)
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(
440
+ (p) => !d.some((u) => u.id === p.id)
280
441
  );
281
- if (p.length > 0)
442
+ if (_.length > 0)
282
443
  if (this.messageCtx.state.setPartial({
283
- messages: [...c, ...p]
284
- }), s)
444
+ messages: [...d, ..._]
445
+ }), n)
285
446
  this.messageCtx.markAsDispatchedToOnMessageReceivedHook(
286
- p.map((d) => d.id)
447
+ _.map((p) => p.id)
287
448
  );
288
449
  else
289
- for (const d of p)
290
- this.messageCtx.dispatchToOnMessageReceivedHook(d);
450
+ for (const p of _)
451
+ this.messageCtx.dispatchToOnMessageReceivedHook(p);
291
452
  }
292
453
  this.messageCtx.state.get().isInitialFetchLoading && this.messageCtx.state.setPartial({ isInitialFetchLoading: !1 });
293
- }, this.mapHistoryToMessage = (a) => {
294
- var s;
295
- const n = {
296
- id: a.publicId,
297
- timestamp: a.sentAt || "",
298
- attachments: a.attachments || void 0
454
+ }, this.mapHistoryToMessage = (s) => {
455
+ var n;
456
+ const a = {
457
+ id: s.publicId,
458
+ timestamp: s.sentAt || "",
459
+ attachments: s.attachments || void 0
299
460
  };
300
- if (a.sender.kind === "user")
461
+ if (s.sender.kind === "user")
301
462
  return {
302
- ...n,
463
+ ...a,
303
464
  type: "USER",
304
- content: a.content.text || "",
465
+ content: s.content.text || "",
305
466
  // Backend field name (schema.ts) → widget vocabulary.
306
- markedElements: a.pickedElements
467
+ markedElements: s.pickedElements
307
468
  };
308
- if (a.sender.kind === "agent")
469
+ if (s.sender.kind === "agent")
309
470
  return {
310
- ...n,
471
+ ...a,
311
472
  type: "AGENT",
312
473
  component: "agent_message",
313
474
  data: {
314
- message: a.content.text || ""
475
+ message: s.content.text || ""
315
476
  },
316
477
  agent: {
317
- name: a.sender.name || "",
478
+ name: s.sender.name || "",
318
479
  // Do not set avatarUrl from config here... let it be taken from the config at render time
319
480
  // Only set avatar url from the backend's response
320
- avatarUrl: a.sender.avatar || null,
321
- avatar: a.sender.avatar || null,
481
+ avatarUrl: s.sender.avatar || null,
482
+ avatar: s.sender.avatar || null,
322
483
  id: null,
323
484
  isAi: !1
324
- }
485
+ },
486
+ ...this.constructReplyTo(s)
325
487
  };
326
- if (a.sender.kind === "ai") {
327
- const r = a.actionCalls && a.actionCalls.length > 0 ? a.actionCalls[a.actionCalls.length - 1] : void 0;
488
+ if (s.sender.kind === "ai") {
489
+ const c = s.actionCalls && s.actionCalls.length > 0 ? s.actionCalls[s.actionCalls.length - 1] : void 0;
328
490
  return {
329
- ...n,
491
+ ...a,
330
492
  type: "AI",
331
493
  component: "bot_message",
332
494
  agent: {
333
495
  id: null,
334
- name: ((s = this.config.bot) == null ? void 0 : s.name) || "",
496
+ name: ((n = this.config.bot) == null ? void 0 : n.name) || "",
335
497
  isAi: !0,
336
498
  // Do not set avatarUrl from config here... let it be taken from the config at render time
337
499
  avatarUrl: null,
338
500
  avatar: null
339
501
  },
340
502
  data: {
341
- message: a.content.text || "",
342
- action: r ? {
343
- name: r.actionName,
344
- data: this.extractActionResult(r)
503
+ message: s.content.text || "",
504
+ action: c ? {
505
+ name: c.actionName,
506
+ data: this.extractActionResult(c)
345
507
  } : void 0
346
- }
508
+ },
509
+ ...this.constructReplyTo(s)
347
510
  };
348
511
  }
349
- if (a.sender.kind === "system") {
350
- const r = this.constructSystemMessage(a);
351
- return r === null ? null : { ...r };
512
+ if (s.sender.kind === "system") {
513
+ const c = this.constructSystemMessage(s);
514
+ return c === null ? null : { ...c };
352
515
  }
353
516
  return null;
354
- }, this.constructSystemMessage = (a) => {
355
- if (!a || !a.systemMessagePayload) return null;
356
- switch (a.systemMessagePayload.type) {
517
+ }, this.constructReplyTo = (s) => {
518
+ if (!s.replyTo) return {};
519
+ const { publicId: a, text: n, sender: c } = s.replyTo;
520
+ return {
521
+ replyTo: {
522
+ id: a,
523
+ text: n,
524
+ sender: c
525
+ }
526
+ };
527
+ }, this.constructSystemMessage = (s) => {
528
+ if (!s || !s.systemMessagePayload) return null;
529
+ switch (s.systemMessagePayload.type) {
357
530
  case "state_checkpoint":
358
531
  return {
359
- id: a.publicId,
532
+ id: s.publicId,
360
533
  type: "SYSTEM",
361
534
  subtype: "state_checkpoint",
362
- data: { payload: a.systemMessagePayload.payload },
363
- timestamp: a.sentAt || "",
535
+ data: { payload: s.systemMessagePayload.payload },
536
+ timestamp: s.sentAt || "",
364
537
  attachments: void 0
365
538
  };
366
539
  case "csat_requested":
367
540
  return {
368
- id: a.publicId,
541
+ id: s.publicId,
369
542
  type: "SYSTEM",
370
543
  subtype: "csat_requested",
371
544
  data: { payload: void 0 },
372
- timestamp: a.sentAt || "",
545
+ timestamp: s.sentAt || "",
373
546
  attachments: void 0
374
547
  };
375
548
  case "csat_submitted":
376
549
  return {
377
- id: a.publicId,
550
+ id: s.publicId,
378
551
  type: "SYSTEM",
379
552
  subtype: "csat_submitted",
380
553
  data: {
381
554
  payload: {
382
- score: a.systemMessagePayload.payload.score ?? void 0,
383
- feedback: a.systemMessagePayload.payload.feedback ?? void 0
555
+ score: s.systemMessagePayload.payload.score ?? void 0,
556
+ feedback: s.systemMessagePayload.payload.feedback ?? void 0
384
557
  }
385
558
  },
386
- timestamp: a.sentAt || "",
559
+ timestamp: s.sentAt || "",
387
560
  attachments: void 0
388
561
  };
389
562
  case "none":
390
563
  return null;
391
564
  default:
392
- return se(
393
- a.systemMessagePayload,
565
+ return me(
566
+ s.systemMessagePayload,
394
567
  this.constructSystemMessage.name
395
568
  ), null;
396
569
  }
397
- }, this.extractActionResult = (a) => {
398
- const n = a.result;
399
- if (n === null || typeof n != "object") return n;
400
- if ("responseBodyText" in n && typeof n.responseBodyText == "string") {
401
- const s = n.responseBodyText, r = H(() => JSON.parse(s)).data;
402
- if (r) return r;
570
+ }, this.extractActionResult = (s) => {
571
+ const a = s.result;
572
+ if (a === null || typeof a != "object") return a;
573
+ if ("responseBodyText" in a && typeof a.responseBodyText == "string") {
574
+ const n = a.responseBodyText, c = $(() => JSON.parse(n)).data;
575
+ if (c) return c;
403
576
  }
404
- return a.result;
405
- }, this.api = e, this.config = t, this.sessionCtx = o, this.messageCtx = _, this.sessionPollingIntervalSeconds = l, this.registerPolling();
577
+ return s.result;
578
+ }, this.api = e, this.config = t, this.sessionCtx = o, this.messageCtx = r, this.sessionPollingIntervalSeconds = l, this.registerPolling();
406
579
  }
407
580
  }
408
- class oe {
581
+ class ge {
409
582
  constructor({
410
583
  config: e,
411
584
  api: t,
412
585
  storageCtx: o
413
586
  }) {
414
- var _;
587
+ var r;
415
588
  this.shouldCollectData = () => {
416
589
  var l;
417
590
  return !!(!((l = this.state.get().contact) != null && l.token) && this.config.collectUserData);
418
591
  }, this.autoCreateUnverifiedUserIfNotExists = async () => {
419
- var l, a, n, s, r, c, p, d, m, h, g, y, w, b;
592
+ var l, s, a, n, c, d, _, p, u, m, g, v, f, b;
420
593
  if (!((l = this.config.user) != null && l.token)) {
421
- if (this.config.collectUserData && !((n = (a = this.config.user) == null ? void 0 : a.data) != null && n.email)) {
422
- if ((s = this.config.extraDataCollectionFields) != null && s.length)
594
+ if (this.config.collectUserData && !((a = (s = this.config.user) == null ? void 0 : s.data) != null && a.email)) {
595
+ if ((n = this.config.extraDataCollectionFields) != null && n.length)
423
596
  return;
424
- const f = await ((r = this.storageCtx) == null ? void 0 : r.getContactToken());
425
- f && await this.setUnverifiedContact(f);
597
+ const w = await ((c = this.storageCtx) == null ? void 0 : c.getContactToken());
598
+ w && await this.setUnverifiedContact(w);
426
599
  return;
427
600
  }
428
- if (!((p = (c = this.config.user) == null ? void 0 : c.data) != null && p.email)) {
429
- const f = await ((d = this.storageCtx) == null ? void 0 : d.getContactToken());
430
- if (f) {
431
- await this.setUnverifiedContact(f);
601
+ if (!((_ = (d = this.config.user) == null ? void 0 : d.data) != null && _.email)) {
602
+ const w = await ((p = this.storageCtx) == null ? void 0 : p.getContactToken());
603
+ if (w) {
604
+ await this.setUnverifiedContact(w);
432
605
  return;
433
606
  }
434
607
  }
435
608
  await this.createUnverifiedContact({
436
- email: (h = (m = this.config.user) == null ? void 0 : m.data) == null ? void 0 : h.email,
437
- non_verified_name: (y = (g = this.config.user) == null ? void 0 : g.data) == null ? void 0 : y.name,
438
- non_verified_custom_data: (b = (w = this.config.user) == null ? void 0 : w.data) == null ? void 0 : b.customData
609
+ email: (m = (u = this.config.user) == null ? void 0 : u.data) == null ? void 0 : m.email,
610
+ non_verified_name: (v = (g = this.config.user) == null ? void 0 : g.data) == null ? void 0 : v.name,
611
+ non_verified_custom_data: (b = (f = this.config.user) == null ? void 0 : f.data) == null ? void 0 : b.customData
439
612
  });
440
613
  }
441
- }, this.createUnverifiedContact = async (l, a) => {
442
- this.state.setPartial({ extraCollectedData: a });
614
+ }, this.createUnverifiedContact = async (l, s) => {
615
+ this.state.setPartial({ extraCollectedData: s });
443
616
  try {
444
617
  this.state.setPartial({
445
618
  isCreatingUnverifiedContact: !0,
446
619
  isErrorCreatingUnverifiedContact: !1
447
620
  });
448
- const { data: n } = await this.api.createUnverifiedContact(l);
449
- n != null && n.token ? await this.setUnverifiedContact(n.token) : this.state.setPartial({ isErrorCreatingUnverifiedContact: !0 });
450
- } catch (n) {
451
- this.state.setPartial({ isErrorCreatingUnverifiedContact: !0 }), u.error("failed to create an unverified contact", {
452
- _e: n instanceof Error ? n.message : String(n)
621
+ const { data: a } = await this.api.createUnverifiedContact(l);
622
+ a != null && a.token ? await this.setUnverifiedContact(a.token) : this.state.setPartial({ isErrorCreatingUnverifiedContact: !0 });
623
+ } catch (a) {
624
+ this.state.setPartial({ isErrorCreatingUnverifiedContact: !0 }), k.error("failed to create an unverified contact", {
625
+ _e: a instanceof Error ? a.message : String(a)
453
626
  });
454
627
  } finally {
455
628
  this.state.setPartial({ isCreatingUnverifiedContact: !1 });
456
629
  }
457
630
  }, this.recoverFromStaleToken = async () => {
458
- var l, a, n, s, r, c, p, d, m, h;
631
+ var l, s, a, n, c, d, _, p, u, m;
459
632
  if ((l = this.config.user) != null && l.token) return !1;
460
633
  this.api.setAuthToken(""), this.state.setPartial({ contact: null });
461
634
  try {
462
- await ((a = this.storageCtx) == null ? void 0 : a.clearContactToken()), await ((n = this.storageCtx) == null ? void 0 : n.clearActiveSessionId());
635
+ await ((s = this.storageCtx) == null ? void 0 : s.clearContactToken()), await ((a = this.storageCtx) == null ? void 0 : a.clearActiveSessionId());
463
636
  } catch (g) {
464
- u.warn("failed to clear a stale contact token", {
637
+ k.warn("failed to clear a stale contact token", {
465
638
  error: g instanceof Error ? g.message : String(g)
466
639
  });
467
640
  }
468
641
  return await this.createUnverifiedContact({
469
- email: (r = (s = this.config.user) == null ? void 0 : s.data) == null ? void 0 : r.email,
470
- non_verified_name: (p = (c = this.config.user) == null ? void 0 : c.data) == null ? void 0 : p.name,
471
- non_verified_custom_data: (m = (d = this.config.user) == null ? void 0 : d.data) == null ? void 0 : m.customData
472
- }), !!((h = this.state.get().contact) != null && h.token);
642
+ email: (c = (n = this.config.user) == null ? void 0 : n.data) == null ? void 0 : c.email,
643
+ non_verified_name: (_ = (d = this.config.user) == null ? void 0 : d.data) == null ? void 0 : _.name,
644
+ non_verified_custom_data: (u = (p = this.config.user) == null ? void 0 : p.data) == null ? void 0 : u.customData
645
+ }), !!((m = this.state.get().contact) != null && m.token);
473
646
  }, this.setUnverifiedContact = async (l) => {
474
- var s, r, c, p;
475
- const a = await ((s = this.storageCtx) == null ? void 0 : s.getExternalContactId()), n = ((r = this.config.user) == null ? void 0 : r.externalId) || a || B();
476
- this.api.setAuthToken(l), await ((c = this.storageCtx) == null ? void 0 : c.setContactToken(l)), await ((p = this.storageCtx) == null ? void 0 : p.setExternalContactId(n)), this.state.setPartial({ contact: { token: l, externalId: n } });
477
- }, this.config = e, this.storageCtx = o, this.api = t, this.state = new j({
478
- contact: (_ = e.user) != null && _.token ? {
647
+ var n, c, d, _;
648
+ const s = await ((n = this.storageCtx) == null ? void 0 : n.getExternalContactId()), a = ((c = this.config.user) == null ? void 0 : c.externalId) || s || N();
649
+ this.api.setAuthToken(l), await ((d = this.storageCtx) == null ? void 0 : d.setContactToken(l)), await ((_ = this.storageCtx) == null ? void 0 : _.setExternalContactId(a)), this.state.setPartial({ contact: { token: l, externalId: a } });
650
+ }, this.config = e, this.storageCtx = o, this.api = t, this.state = new S({
651
+ contact: (r = e.user) != null && r.token ? {
479
652
  token: e.user.token,
480
653
  // Set optional externalId from config... not local storage
481
654
  externalId: e.user.externalId
@@ -486,48 +659,97 @@ class oe {
486
659
  }), this.autoCreateUnverifiedUserIfNotExists();
487
660
  }
488
661
  }
662
+ class ke {
663
+ constructor(e) {
664
+ this.api = e, this.state = new S([]), this.controllers = /* @__PURE__ */ new Map(), this.appendFiles = (t) => {
665
+ const o = t.map(
666
+ (r) => ({
667
+ file: r,
668
+ id: N(),
669
+ status: "pending",
670
+ progress: 0
671
+ })
672
+ );
673
+ this.state.set([...this.state.get(), ...o]), o.forEach((r) => void this.upload(r));
674
+ }, this.cancel = (t) => {
675
+ var o;
676
+ (o = this.controllers.get(t)) == null || o.abort(), this.controllers.delete(t), this.state.set(this.state.get().filter((r) => r.id !== t));
677
+ }, this.reset = () => {
678
+ this.controllers.forEach((t) => t.abort()), this.controllers.clear(), this.state.reset();
679
+ };
680
+ }
681
+ update(e, t) {
682
+ this.state.set(
683
+ this.state.get().map((o) => o.id === e ? { ...o, ...t } : o)
684
+ );
685
+ }
686
+ async upload(e) {
687
+ const t = new AbortController();
688
+ this.controllers.set(e.id, t), this.update(e.id, { status: "uploading" });
689
+ try {
690
+ const o = await this.api.uploadFile({
691
+ file: e.file,
692
+ abortSignal: t.signal,
693
+ onProgress: (r) => this.update(e.id, { progress: r })
694
+ });
695
+ this.update(e.id, {
696
+ status: "success",
697
+ fileUrl: o.fileUrl,
698
+ progress: 100
699
+ });
700
+ } catch (o) {
701
+ t.signal.aborted || this.update(e.id, {
702
+ status: "error",
703
+ progress: 0,
704
+ error: o instanceof Error ? o.message : "Upload failed"
705
+ });
706
+ } finally {
707
+ this.controllers.delete(e.id);
708
+ }
709
+ }
710
+ }
489
711
  function x() {
490
- return B();
712
+ return N();
491
713
  }
492
- class ie {
714
+ class be {
493
715
  constructor({
494
716
  api: e,
495
717
  sessionCtx: t,
496
718
  messageCtx: o
497
719
  }) {
498
- this.submitCsat = async (_) => {
499
- var r;
500
- const l = (r = this.sessionCtx.sessionState.get().session) == null ? void 0 : r.id;
720
+ this.submitCsat = async (r) => {
721
+ var c;
722
+ const l = (c = this.sessionCtx.sessionState.get().session) == null ? void 0 : c.id;
501
723
  if (!l)
502
724
  return { data: null, error: "No session id found" };
503
- const a = x();
725
+ const s = x();
504
726
  this.messageCtx.state.setPartial({
505
727
  messages: [
506
728
  ...this.messageCtx.state.get().messages,
507
729
  {
508
- id: a,
730
+ id: s,
509
731
  type: "SYSTEM",
510
732
  subtype: "csat_submitted",
511
733
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
512
734
  data: {
513
735
  payload: {
514
- score: _.score,
515
- feedback: _.feedback
736
+ score: r.score,
737
+ feedback: r.feedback
516
738
  }
517
739
  }
518
740
  }
519
741
  ]
520
742
  });
521
- const { data: n, error: s } = await this.api.submitCsat({
522
- ..._,
523
- system_message_uuid: a,
743
+ const { data: a, error: n } = await this.api.submitCsat({
744
+ ...r,
745
+ system_message_uuid: s,
524
746
  session_id: l
525
747
  });
526
- return { data: n, error: s };
748
+ return { data: a, error: n };
527
749
  }, this.api = e, this.sessionCtx = t, this.messageCtx = o;
528
750
  }
529
751
  }
530
- const re = [
752
+ const ve = [
531
753
  {
532
754
  action: "newparagraph",
533
755
  phrases: {
@@ -602,7 +824,7 @@ const re = [
602
824
  it: ["invia messaggio"]
603
825
  }
604
826
  }
605
- ], _e = [
827
+ ], fe = [
606
828
  "en",
607
829
  "es",
608
830
  "fr",
@@ -610,18 +832,18 @@ const re = [
610
832
  "pt",
611
833
  "it"
612
834
  ];
613
- function le(i) {
614
- return _e.includes(i);
835
+ function ye(i) {
836
+ return fe.includes(i);
615
837
  }
616
- function ce(i) {
838
+ function we(i) {
617
839
  return i.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
618
840
  }
619
- function pe(i) {
620
- const e = re.flatMap(
621
- (_) => i.flatMap(
622
- (l) => _.phrases[l].map((a) => ({ phrase: a, action: _.action }))
841
+ function je(i) {
842
+ const e = ve.flatMap(
843
+ (r) => i.flatMap(
844
+ (l) => r.phrases[l].map((s) => ({ phrase: s, action: r.action }))
623
845
  )
624
- ), t = e.map((_) => ce(_.phrase)).sort((_, l) => l.length - _.length).join("|"), o = String.raw`(?<=^\s{0,3}|[.!?\n]\s{0,3})`;
846
+ ), t = e.map((r) => we(r.phrase)).sort((r, l) => l.length - r.length).join("|"), o = String.raw`(?<=^\s{0,3}|[.!?\n]\s{0,3})`;
625
847
  return {
626
848
  regex: new RegExp(
627
849
  `${o}(${t})` + String.raw`([.,!?;:])(?=\s|$)`,
@@ -632,82 +854,82 @@ function pe(i) {
632
854
  "giu"
633
855
  ),
634
856
  phraseToAction: new Map(
635
- e.map((_) => [_.phrase.toLowerCase(), _.action])
857
+ e.map((r) => [r.phrase.toLowerCase(), r.action])
636
858
  ),
637
- longestPhrase: Math.max(...e.map((_) => _.phrase.length))
859
+ longestPhrase: Math.max(...e.map((r) => r.phrase.length))
638
860
  };
639
861
  }
640
- const L = /* @__PURE__ */ new Map();
641
- function T(i) {
642
- const e = i && le(i) && i !== "en" ? i : null, t = e ?? "en";
643
- let o = L.get(t);
644
- return o || (o = pe(e ? ["en", e] : ["en"]), L.set(t, o)), o;
862
+ const V = /* @__PURE__ */ new Map();
863
+ function I(i) {
864
+ const e = i && ye(i) && i !== "en" ? i : null, t = e ?? "en";
865
+ let o = V.get(t);
866
+ return o || (o = je(e ? ["en", e] : ["en"]), V.set(t, o)), o;
645
867
  }
646
- function de(i) {
868
+ function Se(i) {
647
869
  const e = i.replace(/\s+$/, "");
648
870
  if (!e) return "";
649
871
  const t = e.replace(/[.!?]+$/, "");
650
872
  let o = -1;
651
- for (let _ = t.length - 1; _ >= 0; _--) {
652
- const l = t[_];
873
+ for (let r = t.length - 1; r >= 0; r--) {
874
+ const l = t[r];
653
875
  if (l === "." || l === "!" || l === "?" || l === `
654
876
  `) {
655
- o = _ + 1;
877
+ o = r + 1;
656
878
  break;
657
879
  }
658
880
  }
659
881
  return o === -1 ? "" : `${t.slice(0, o)} `.replace(/\n $/, `
660
882
  `);
661
883
  }
662
- const me = new RegExp(
884
+ const ze = new RegExp(
663
885
  String.raw`(^- |\n(?:- )?)(\p{Ll})`,
664
886
  "gu"
665
887
  );
666
- function ue(i) {
888
+ function Ce(i) {
667
889
  return i.replace(
668
- me,
890
+ ze,
669
891
  (e, t, o) => t + o.toUpperCase()
670
892
  );
671
893
  }
672
- function he(i) {
894
+ function xe(i) {
673
895
  return i.length <= 3 && /^\s*$/.test(i) ? !0 : /[.!?\n]\s{0,3}$/.test(i.slice(-6));
674
896
  }
675
- class C {
897
+ class q {
676
898
  /**
677
899
  * Process the full raw transcript accumulated so far into insertable text.
678
900
  * Pure and deterministic: always called with the entire raw string so the
679
901
  * result never depends on delta chunking.
680
902
  */
681
903
  static process(e, t) {
682
- const o = T(t == null ? void 0 : t.language), _ = t != null && t.final ? "" : C.commandPrefixTail(e, t == null ? void 0 : t.language), l = e.slice(0, e.length - _.length), a = t != null && t.final ? o.finalRegex : o.regex;
683
- let n = "", s = null, r = 0;
684
- for (const p of Array.from(l.matchAll(a))) {
685
- const [, d = ""] = p, m = o.phraseToAction.get(d.toLowerCase());
686
- if (m)
687
- if (n += l.slice(r, p.index), r = p.index + p[0].length, m === "newline") n = `${n.replace(/[ \t]+$/, "")}
904
+ const o = I(t == null ? void 0 : t.language), r = t != null && t.final ? "" : q.commandPrefixTail(e, t == null ? void 0 : t.language), l = e.slice(0, e.length - r.length), s = t != null && t.final ? o.finalRegex : o.regex;
905
+ let a = "", n = null, c = 0;
906
+ for (const _ of Array.from(l.matchAll(s))) {
907
+ const [, p = ""] = _, u = o.phraseToAction.get(p.toLowerCase());
908
+ if (u)
909
+ if (a += l.slice(c, _.index), c = _.index + _[0].length, u === "newline") a = `${a.replace(/[ \t]+$/, "")}
688
910
  `;
689
- else if (m === "newparagraph")
690
- n = `${n.replace(/[ \t]+$/, "")}
911
+ else if (u === "newparagraph")
912
+ a = `${a.replace(/[ \t]+$/, "")}
691
913
 
692
914
  `;
693
- else if (m === "bullet") {
694
- const h = n.replace(/[ \t]+$/, "");
695
- n = h === "" || h.endsWith(`
696
- `) ? `${h}- ` : `${h}
915
+ else if (u === "bullet") {
916
+ const m = a.replace(/[ \t]+$/, "");
917
+ a = m === "" || m.endsWith(`
918
+ `) ? `${m}- ` : `${m}
697
919
  - `;
698
- } else if (m === "scratch") n = de(n);
920
+ } else if (u === "scratch") a = Se(a);
699
921
  else {
700
- s = m === "send" ? "send" : "stop";
922
+ n = u === "send" ? "send" : "stop";
701
923
  break;
702
924
  }
703
925
  }
704
- return s === null && (n += l.slice(r)), { text: ue(
705
- n.replace(/^\s+/, "").replace(/[ \t]+\n/g, `
926
+ return n === null && (a += l.slice(c)), { text: Ce(
927
+ a.replace(/^\s+/, "").replace(/[ \t]+\n/g, `
706
928
  `).replace(/\n[ \t]+/g, `
707
929
  `).replace(/(^|\n)- +/g, "$1- ").replace(/ {2,}/g, " ").replace(/\n{3,}/g, `
708
930
 
709
931
  `)
710
- ), pendingTail: _, control: s };
932
+ ), pendingTail: r, control: n };
711
933
  }
712
934
  /**
713
935
  * Longest suffix of `raw` that could still become a command — a proper
@@ -719,15 +941,15 @@ class C {
719
941
  * mid-sentence.
720
942
  */
721
943
  static commandPrefixTail(e, t) {
722
- const o = T(t), _ = Math.min(e.length, o.longestPhrase + 2);
723
- for (let l = _; l > 0; l--) {
724
- const a = e.length - l;
725
- if (!he(e.slice(0, a))) continue;
726
- const n = e.slice(a).toLowerCase(), s = n.replace(/^\s+/, "");
727
- if (s) {
728
- for (const r of Array.from(o.phraseToAction.keys()))
729
- if (r.startsWith(s))
730
- return e.slice(a + (n.length - s.length));
944
+ const o = I(t), r = Math.min(e.length, o.longestPhrase + 2);
945
+ for (let l = r; l > 0; l--) {
946
+ const s = e.length - l;
947
+ if (!xe(e.slice(0, s))) continue;
948
+ const a = e.slice(s).toLowerCase(), n = a.replace(/^\s+/, "");
949
+ if (n) {
950
+ for (const c of Array.from(o.phraseToAction.keys()))
951
+ if (c.startsWith(n))
952
+ return e.slice(s + (a.length - n.length));
731
953
  }
732
954
  }
733
955
  return "";
@@ -738,12 +960,12 @@ class C {
738
960
  * the manager's silence timer.
739
961
  */
740
962
  static pendingTailIsCompletePhrase(e, t) {
741
- const o = C.commandPrefixTail(e, t).trim().toLowerCase();
742
- return o ? T(t).phraseToAction.has(o) : !1;
963
+ const o = q.commandPrefixTail(e, t).trim().toLowerCase();
964
+ return o ? I(t).phraseToAction.has(o) : !1;
743
965
  }
744
966
  }
745
- const ge = 55, ke = 90;
746
- class F {
967
+ const qe = 55, Ee = 90;
968
+ class H {
747
969
  /**
748
970
  * Next paced step toward `processed`: normally one word per tick so text
749
971
  * flows evenly instead of landing in bursty chunks; proportionally larger
@@ -756,12 +978,12 @@ class F {
756
978
  }) {
757
979
  if (t.length <= e.length) return t;
758
980
  const o = t.length - e.length;
759
- if (o > ke)
981
+ if (o > Ee)
760
982
  return t.slice(0, e.length + Math.ceil(o / 3));
761
- let _ = e.length;
762
- for (; _ < t.length && /\s/.test(t.charAt(_)); ) _++;
763
- for (; _ < t.length && !/\s/.test(t.charAt(_)); ) _++;
764
- return _ - e.length > 12 && (_ = e.length + 6), t.slice(0, Math.max(_, e.length + 1));
983
+ let r = e.length;
984
+ for (; r < t.length && /\s/.test(t.charAt(r)); ) r++;
985
+ for (; r < t.length && !/\s/.test(t.charAt(r)); ) r++;
986
+ return r - e.length > 12 && (r = e.length + 6), t.slice(0, Math.max(r, e.length + 1));
765
987
  }
766
988
  /** Normalize a BCP-47 browser locale into the hint OpenAI accepts. */
767
989
  static languageHint(e) {
@@ -772,8 +994,8 @@ class F {
772
994
  return o && /^[a-z]{2,3}$/.test(o) ? o : void 0;
773
995
  }
774
996
  }
775
- const be = 2e4;
776
- class fe {
997
+ const Ae = 2e4;
998
+ class Pe {
777
999
  constructor() {
778
1000
  this.cached = null, this.inflight = null;
779
1001
  }
@@ -781,7 +1003,7 @@ class fe {
781
1003
  get() {
782
1004
  if (!this.cached) return null;
783
1005
  const e = Date.parse(this.cached.expiresAt);
784
- return Number.isNaN(e) || e - Date.now() < be ? (this.cached = null, null) : this.cached;
1006
+ return Number.isNaN(e) || e - Date.now() < Ae ? (this.cached = null, null) : this.cached;
785
1007
  }
786
1008
  /**
787
1009
  * Resolve a mint, deduping concurrent requests (hover-prewarm racing a
@@ -798,89 +1020,89 @@ class fe {
798
1020
  this.cached = null;
799
1021
  }
800
1022
  }
801
- function O(i) {
1023
+ function Z(i) {
802
1024
  return typeof i == "object" && i !== null && !Array.isArray(i);
803
1025
  }
804
- function ve(i) {
805
- if (!O(i) || typeof i.type != "string") return null;
806
- const e = O(i.error) ? i.error : null;
1026
+ function Te(i) {
1027
+ if (!Z(i) || typeof i.type != "string") return null;
1028
+ const e = Z(i.error) ? i.error : null;
807
1029
  return {
808
1030
  type: i.type,
809
1031
  delta: typeof i.delta == "string" ? i.delta : void 0,
810
1032
  errorMessage: e && typeof e.message == "string" ? e.message : void 0
811
1033
  };
812
1034
  }
813
- const ye = "https://api.openai.com/v1/realtime/calls", we = 10 * 60 * 1e3, je = 15e3, Se = 5e3;
814
- class E extends Error {
1035
+ const Ie = "https://api.openai.com/v1/realtime/calls", Me = 600 * 1e3, De = 15e3, Ne = 5e3;
1036
+ class P extends Error {
815
1037
  }
816
- class ze {
1038
+ class Re {
817
1039
  constructor({
818
1040
  mintToken: e,
819
1041
  onDelta: t,
820
1042
  onState: o,
821
- onError: _,
1043
+ onError: r,
822
1044
  onLevel: l
823
1045
  }) {
824
- this.state = "idle", this.pc = null, this.dc = null, this.stream = null, this.audioContext = null, this.levelRaf = 0, this.timers = [], this.loggedParseFailure = !1, this.mintToken = e, this.onDelta = t, this.onState = o, this.onError = _, this.onLevel = l;
1046
+ this.state = "idle", this.pc = null, this.dc = null, this.stream = null, this.audioContext = null, this.levelRaf = 0, this.timers = [], this.loggedParseFailure = !1, this.mintToken = e, this.onDelta = t, this.onState = o, this.onError = r, this.onLevel = l;
825
1047
  }
826
1048
  async start() {
827
1049
  if (this.state === "idle") {
828
1050
  this.setState("connecting"), this.timers.push(
829
1051
  setTimeout(() => {
830
1052
  this.state === "connecting" && this.fail("unavailable");
831
- }, je)
832
- ), this.timers.push(setTimeout(() => this.stop(), we));
1053
+ }, De)
1054
+ ), this.timers.push(setTimeout(() => this.stop(), Me));
833
1055
  try {
834
1056
  const e = this.requestMicrophone();
835
- e.then((c) => {
836
- (this.isTornDown() || this.stream && this.stream !== c) && c.getTracks().forEach((p) => p.stop());
1057
+ e.then((d) => {
1058
+ (this.isTornDown() || this.stream && this.stream !== d) && d.getTracks().forEach((_) => _.stop());
837
1059
  }).catch(() => {
838
1060
  });
839
1061
  const [t, o] = await Promise.all([e, this.mintToken()]);
840
1062
  if (this.isTornDown()) {
841
- t.getTracks().forEach((c) => c.stop());
1063
+ t.getTracks().forEach((d) => d.stop());
842
1064
  return;
843
1065
  }
844
1066
  this.stream = t, this.startLevelMeter(t);
845
- const _ = new RTCPeerConnection();
846
- this.pc = _;
1067
+ const r = new RTCPeerConnection();
1068
+ this.pc = r;
847
1069
  const [l] = t.getAudioTracks();
848
- if (!l) throw new E("No audio track");
849
- _.addTrack(l, t);
850
- const a = _.createDataChannel("oai-events");
851
- this.dc = a, a.addEventListener(
1070
+ if (!l) throw new P("No audio track");
1071
+ r.addTrack(l, t);
1072
+ const s = r.createDataChannel("oai-events");
1073
+ this.dc = s, s.addEventListener(
852
1074
  "message",
853
- (c) => this.handleServerEvent(c.data)
854
- ), a.addEventListener("open", () => {
1075
+ (d) => this.handleServerEvent(d.data)
1076
+ ), s.addEventListener("open", () => {
855
1077
  this.state === "connecting" && this.setState("listening");
856
- }), _.addEventListener("connectionstatechange", () => {
857
- if (_.connectionState === "failed") {
1078
+ }), r.addEventListener("connectionstatechange", () => {
1079
+ if (r.connectionState === "failed") {
858
1080
  this.fail("unavailable");
859
1081
  return;
860
1082
  }
861
- _.connectionState === "disconnected" && this.timers.push(
1083
+ r.connectionState === "disconnected" && this.timers.push(
862
1084
  setTimeout(() => {
863
- this.pc === _ && _.connectionState !== "connected" && this.fail("unavailable");
864
- }, Se)
1085
+ this.pc === r && r.connectionState !== "connected" && this.fail("unavailable");
1086
+ }, Ne)
865
1087
  );
866
1088
  });
867
- const n = await _.createOffer();
868
- await _.setLocalDescription(n);
869
- const s = await fetch(ye, {
1089
+ const a = await r.createOffer();
1090
+ await r.setLocalDescription(a);
1091
+ const n = await fetch(Ie, {
870
1092
  method: "POST",
871
1093
  headers: {
872
1094
  Authorization: `Bearer ${o.token}`,
873
1095
  "Content-Type": "application/sdp"
874
1096
  },
875
- body: n.sdp
1097
+ body: a.sdp
876
1098
  });
877
- if (!s.ok)
878
- throw new Error(`Realtime handshake failed (${s.status})`);
879
- const r = await s.text();
1099
+ if (!n.ok)
1100
+ throw new Error(`Realtime handshake failed (${n.status})`);
1101
+ const c = await n.text();
880
1102
  if (this.isTornDown()) return;
881
- await _.setRemoteDescription({ type: "answer", sdp: r });
1103
+ await r.setRemoteDescription({ type: "answer", sdp: c });
882
1104
  } catch (e) {
883
- e instanceof E ? this.fail("microphone") : (u.error("dictation session failed to start", {
1105
+ e instanceof P ? this.fail("microphone") : (k.error("dictation session failed to start", {
884
1106
  _e: e instanceof Error ? e.message : String(e)
885
1107
  }), this.fail("unavailable"));
886
1108
  }
@@ -892,7 +1114,7 @@ class ze {
892
1114
  async requestMicrophone() {
893
1115
  var e;
894
1116
  if (!((e = navigator.mediaDevices) != null && e.getUserMedia))
895
- throw new E("Microphone is not supported");
1117
+ throw new P("Microphone is not supported");
896
1118
  try {
897
1119
  return await navigator.mediaDevices.getUserMedia({
898
1120
  audio: {
@@ -902,7 +1124,7 @@ class ze {
902
1124
  }
903
1125
  });
904
1126
  } catch (t) {
905
- throw new E(
1127
+ throw new P(
906
1128
  t instanceof DOMException ? t.name : "Could not access the microphone"
907
1129
  );
908
1130
  }
@@ -913,23 +1135,23 @@ class ze {
913
1135
  try {
914
1136
  t = JSON.parse(e);
915
1137
  } catch {
916
- this.loggedParseFailure || (this.loggedParseFailure = !0, u.error("dictation server event was not valid JSON", {
1138
+ this.loggedParseFailure || (this.loggedParseFailure = !0, k.error("dictation server event was not valid JSON", {
917
1139
  snippet: e.slice(0, 120)
918
1140
  }));
919
1141
  return;
920
1142
  }
921
- const o = ve(t);
1143
+ const o = Te(t);
922
1144
  if (!o) return;
923
- const { type: _, delta: l } = o;
924
- if (_ === "session.created" || _ === "transcription_session.created") {
1145
+ const { type: r, delta: l } = o;
1146
+ if (r === "session.created" || r === "transcription_session.created") {
925
1147
  this.setState("listening");
926
1148
  return;
927
1149
  }
928
- if (_ === "conversation.item.input_audio_transcription.delta" && l) {
1150
+ if (r === "conversation.item.input_audio_transcription.delta" && l) {
929
1151
  this.state === "connecting" && this.setState("listening"), this.onDelta(l);
930
1152
  return;
931
1153
  }
932
- _ === "error" && (u.error("dictation server event error", {
1154
+ r === "error" && (k.error("dictation server event error", {
933
1155
  _e: o.errorMessage ?? "unknown"
934
1156
  }), this.fail("unavailable"));
935
1157
  }
@@ -938,22 +1160,22 @@ class ze {
938
1160
  try {
939
1161
  const t = new AudioContext();
940
1162
  this.audioContext = t;
941
- const o = t.createMediaStreamSource(e), _ = t.createAnalyser();
942
- _.fftSize = 512, o.connect(_);
943
- const l = new Uint8Array(_.frequencyBinCount), a = () => {
944
- var r;
945
- _.getByteTimeDomainData(l);
946
- let n = 0;
947
- for (let c = 0; c < l.length; c++) {
948
- const p = ((l[c] ?? 128) - 128) / 128;
949
- n += p * p;
1163
+ const o = t.createMediaStreamSource(e), r = t.createAnalyser();
1164
+ r.fftSize = 512, o.connect(r);
1165
+ const l = new Uint8Array(r.frequencyBinCount), s = () => {
1166
+ var c;
1167
+ r.getByteTimeDomainData(l);
1168
+ let a = 0;
1169
+ for (let d = 0; d < l.length; d++) {
1170
+ const _ = ((l[d] ?? 128) - 128) / 128;
1171
+ a += _ * _;
950
1172
  }
951
- const s = Math.sqrt(n / l.length);
952
- (r = this.onLevel) == null || r.call(this, Math.min(1, s * 4)), this.levelRaf = requestAnimationFrame(a);
1173
+ const n = Math.sqrt(a / l.length);
1174
+ (c = this.onLevel) == null || c.call(this, Math.min(1, n * 4)), this.levelRaf = requestAnimationFrame(s);
953
1175
  };
954
- this.levelRaf = requestAnimationFrame(a);
1176
+ this.levelRaf = requestAnimationFrame(s);
955
1177
  } catch (t) {
956
- u.error("dictation level meter unavailable", {
1178
+ k.error("dictation level meter unavailable", {
957
1179
  _e: t instanceof Error ? t.message : String(t)
958
1180
  });
959
1181
  }
@@ -965,9 +1187,9 @@ class ze {
965
1187
  this.isTornDown() || (this.teardown(), this.setState("error"), this.onError(e));
966
1188
  }
967
1189
  teardown() {
968
- var e, t, o, _;
969
- 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, (t = this.pc) == null || t.close(), this.pc = null, (o = this.stream) == null || o.getTracks().forEach((l) => l.stop()), this.stream = null, (_ = this.audioContext) == null || _.close().catch((l) => {
970
- u.error("failed to close dictation audio context", {
1190
+ var e, t, o, r;
1191
+ 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, (t = this.pc) == null || t.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) => {
1192
+ k.error("failed to close dictation audio context", {
971
1193
  _e: String(l)
972
1194
  });
973
1195
  }), this.audioContext = null;
@@ -976,71 +1198,71 @@ class ze {
976
1198
  this.state !== e && (this.state = e, this.onState(e));
977
1199
  }
978
1200
  }
979
- const xe = 1300, Ce = { status: "idle", error: null };
980
- class qe {
1201
+ const Ke = 1300, Le = { status: "idle", error: null };
1202
+ class Fe {
981
1203
  constructor({ api: e, config: t }) {
982
- this.state = new j(Ce), this.levelRef = { current: 0 }, this.mintCache = new fe(), 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 = () => {
1204
+ 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 = () => {
983
1205
  this.mintToken().catch((o) => {
984
- this.mintCache.clear(), u.error("dictation token prewarm failed", {
1206
+ this.mintCache.clear(), k.error("dictation token prewarm failed", {
985
1207
  _e: o instanceof Error ? o.message : String(o)
986
1208
  });
987
1209
  });
988
1210
  }, this.start = (o) => {
989
- this.session && this.teardown(), this.target = o, this.language = F.languageHint(
1211
+ this.session && this.teardown(), this.target = o, this.language = H.languageHint(
990
1212
  this.config.language ?? navigator.language
991
1213
  ), this.prefix = o.getValue(), this.raw = "", this.processed = "", this.displayed = "";
992
- const _ = new ze({
1214
+ const r = new Re({
993
1215
  mintToken: this.mintToken,
994
1216
  onLevel: (l) => {
995
1217
  this.levelRef.current = l;
996
1218
  },
997
1219
  onState: (l) => {
998
- _ === this.session && (l === "connecting" && this.state.set({ status: "connecting", error: null }), l === "listening" && this.state.set({ status: "listening", error: null }), l === "stopped" && this.teardown());
1220
+ 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());
999
1221
  },
1000
1222
  onError: (l) => {
1001
- _ === this.session && (this.mintCache.clear(), this.teardown({ error: l, executeFinalCommand: !1 }));
1223
+ r === this.session && (this.mintCache.clear(), this.teardown({ error: l, executeFinalCommand: !1 }));
1002
1224
  },
1003
1225
  onDelta: (l) => {
1004
- if (_ !== this.session || !this.target) return;
1226
+ if (r !== this.session || !this.target) return;
1005
1227
  if (!this.isConsistent()) {
1006
1228
  this.teardown();
1007
1229
  return;
1008
1230
  }
1009
1231
  this.raw += l;
1010
- const a = this.ingest();
1011
- if (a === "stop") {
1232
+ const s = this.ingest();
1233
+ if (s === "stop") {
1012
1234
  this.teardown();
1013
1235
  return;
1014
1236
  }
1015
- if (a === "send") {
1237
+ if (s === "send") {
1016
1238
  this.teardown({ send: !0 });
1017
1239
  return;
1018
1240
  }
1019
- this.stopSilenceTimer(), C.pendingTailIsCompletePhrase(
1241
+ this.stopSilenceTimer(), q.pendingTailIsCompletePhrase(
1020
1242
  this.raw,
1021
1243
  this.language
1022
1244
  ) && (this.silenceTimer = setTimeout(() => {
1023
- if (_ !== this.session) return;
1245
+ if (r !== this.session) return;
1024
1246
  this.raw = `${this.raw}.`;
1025
- const n = this.ingest();
1026
- n === "stop" ? this.teardown() : n === "send" && this.teardown({ send: !0 });
1027
- }, xe));
1247
+ const a = this.ingest();
1248
+ a === "stop" ? this.teardown() : a === "send" && this.teardown({ send: !0 });
1249
+ }, Ke));
1028
1250
  }
1029
1251
  });
1030
- this.session = _, this.state.set({ status: "connecting", error: null }), this.dripTimer = setInterval(() => {
1252
+ this.session = r, this.state.set({ status: "connecting", error: null }), this.dripTimer = setInterval(() => {
1031
1253
  if (this.target && this.processed !== this.displayed) {
1032
1254
  if (!this.isConsistent()) {
1033
1255
  this.teardown();
1034
1256
  return;
1035
1257
  }
1036
1258
  this.applyDisplayed(
1037
- F.nextDripText({
1259
+ H.nextDripText({
1038
1260
  displayed: this.displayed,
1039
1261
  processed: this.processed
1040
1262
  })
1041
1263
  );
1042
1264
  }
1043
- }, ge), _.start();
1265
+ }, qe), r.start();
1044
1266
  }, this.stop = () => {
1045
1267
  this.session && this.teardown();
1046
1268
  }, this.mintToken = async () => this.mintCache.resolve(
@@ -1057,7 +1279,7 @@ class qe {
1057
1279
  /** Process the transcript and apply the outcome. Shared by the delta path,
1058
1280
  * the silence timer, and (with `final`) teardown. Returns the control. */
1059
1281
  ingest(e) {
1060
- const t = C.process(this.raw, {
1282
+ const t = q.process(this.raw, {
1061
1283
  language: this.language,
1062
1284
  final: e == null ? void 0 : e.final
1063
1285
  });
@@ -1070,15 +1292,15 @@ class qe {
1070
1292
  var l;
1071
1293
  const t = this.session, o = this.target;
1072
1294
  this.dripTimer && clearInterval(this.dripTimer), this.dripTimer = null, this.stopSilenceTimer();
1073
- let _ = (e == null ? void 0 : e.send) ?? !1;
1295
+ let r = (e == null ? void 0 : e.send) ?? !1;
1074
1296
  if (o && this.isConsistent()) {
1075
- const a = this.ingest({ final: !0 });
1076
- (e == null ? void 0 : e.executeFinalCommand) !== !1 && a === "send" && (_ = !0), this.processed !== this.displayed && this.applyDisplayed(this.processed);
1297
+ const s = this.ingest({ final: !0 });
1298
+ (e == null ? void 0 : e.executeFinalCommand) !== !1 && s === "send" && (r = !0), this.processed !== this.displayed && this.applyDisplayed(this.processed);
1077
1299
  }
1078
- this.session = null, this.target = null, t == null || t.stop(), this.levelRef.current = 0, this.state.set({ status: "idle", error: (e == null ? void 0 : e.error) ?? null }), _ && ((l = o == null ? void 0 : o.onSend) == null || l.call(o));
1300
+ this.session = null, this.target = null, t == null || t.stop(), this.levelRef.current = 0, this.state.set({ status: "idle", error: (e == null ? void 0 : e.error) ?? null }), r && ((l = o == null ? void 0 : o.onSend) == null || l.call(o));
1079
1301
  }
1080
1302
  }
1081
- const Ee = {
1303
+ const Oe = {
1082
1304
  write_a_message_placeholder: "اكتب رسالة...",
1083
1305
  your_issue_has_been_resolved: "تم حل مشكلتك!",
1084
1306
  new_conversation: "محادثة جديدة",
@@ -1102,7 +1324,19 @@ const Ee = {
1102
1324
  companion_layout_floating: "عائم",
1103
1325
  companion_layout_sidebar: "الشريط الجانبي",
1104
1326
  companion_layout_fullscreen: "ملء الشاشة",
1327
+ companion_close_chat: "إغلاق {title}",
1105
1328
  companion_close: "إغلاق",
1329
+ companion_switch_chat: "تبديل المحادثة",
1330
+ companion_viewing: "تعرض الآن",
1331
+ companion_working: "قيد العمل",
1332
+ companion_open: "مفتوحة",
1333
+ companion_closed: "مغلقة",
1334
+ companion_draft: "مسودة",
1335
+ companion_chats: "الجلسات النشطة",
1336
+ companion_chat_number: "محادثة {count}",
1337
+ companion_active_chats: "{count} جلسات نشطة",
1338
+ companion_other_sessions: "الجلسات المفتوحة الأخرى: {count}",
1339
+ companion_working_chats: "{count} قيد العمل",
1106
1340
  companion_history: "سجل المحادثات",
1107
1341
  companion_expand_chat: "توسيع المحادثة",
1108
1342
  companion_sidebar_dock_label: "الإرساء",
@@ -1165,8 +1399,17 @@ const Ee = {
1165
1399
  questions_next: "التالي",
1166
1400
  questions_send: "إرسال",
1167
1401
  questions_type_answer: "سأكتبها بنفسي",
1168
- questions_answer_placeholder: "اكتب إجابتك…"
1169
- }, Pe = {
1402
+ questions_answer_placeholder: "اكتب إجابتك…",
1403
+ close_conversation_title: "إغلاق المحادثة",
1404
+ close_conversation_description: "هل أنت متأكد أنك تريد إغلاق هذه المحادثة؟",
1405
+ close_conversation_cancel: "لا",
1406
+ close_conversation_confirm: "نعم",
1407
+ dialog_close: "إغلاق",
1408
+ zoom_in: "تكبير",
1409
+ zoom_out: "تصغير",
1410
+ reset_zoom: "إعادة تعيين التكبير",
1411
+ support_chat_aria_label: "دردشة الدعم"
1412
+ }, Ue = {
1170
1413
  write_a_message_placeholder: "একটি বার্তা লিখুন...",
1171
1414
  your_issue_has_been_resolved: "আপনার সমস্যা সমাধান হয়েছে!",
1172
1415
  new_conversation: "নতুন কথোপকথন",
@@ -1253,8 +1496,17 @@ const Ee = {
1253
1496
  questions_next: "পরবর্তী",
1254
1497
  questions_send: "পাঠান",
1255
1498
  questions_type_answer: "আমি লিখে দিচ্ছি",
1256
- questions_answer_placeholder: "আপনার উত্তর লিখুন…"
1257
- }, Te = {
1499
+ questions_answer_placeholder: "আপনার উত্তর লিখুন…",
1500
+ close_conversation_title: "কথোপকথন বন্ধ করুন",
1501
+ close_conversation_description: "আপনি কি নিশ্চিত যে আপনি এই কথোপকথনটি বন্ধ করতে চান?",
1502
+ close_conversation_cancel: "না",
1503
+ close_conversation_confirm: "হ্যাঁ",
1504
+ dialog_close: "বন্ধ করুন",
1505
+ zoom_in: "বড় করুন",
1506
+ zoom_out: "ছোট করুন",
1507
+ reset_zoom: "জুম রিসেট করুন",
1508
+ support_chat_aria_label: "সাপোর্ট চ্যাট"
1509
+ }, Be = {
1258
1510
  write_a_message_placeholder: "Напишете съобщение...",
1259
1511
  your_issue_has_been_resolved: "Вашият проблем е разрешен!",
1260
1512
  new_conversation: "Нов разговор",
@@ -1341,8 +1593,17 @@ const Ee = {
1341
1593
  questions_next: "Напред",
1342
1594
  questions_send: "Изпрати",
1343
1595
  questions_type_answer: "Ще напиша сам",
1344
- questions_answer_placeholder: "Напишете отговора си…"
1345
- }, Ae = {
1596
+ questions_answer_placeholder: "Напишете отговора си…",
1597
+ close_conversation_title: "Затваряне на разговора",
1598
+ close_conversation_description: "Сигурни ли сте, че искате да затворите този разговор?",
1599
+ close_conversation_cancel: "Не",
1600
+ close_conversation_confirm: "Да",
1601
+ dialog_close: "Затваряне",
1602
+ zoom_in: "Увеличаване",
1603
+ zoom_out: "Намаляване",
1604
+ reset_zoom: "Нулиране на мащаба",
1605
+ support_chat_aria_label: "Чат за поддръжка"
1606
+ }, Ve = {
1346
1607
  write_a_message_placeholder: "Napište zprávu...",
1347
1608
  your_issue_has_been_resolved: "Váš problém byl vyřešen!",
1348
1609
  new_conversation: "Nová konverzace",
@@ -1429,8 +1690,17 @@ const Ee = {
1429
1690
  questions_next: "Další",
1430
1691
  questions_send: "Odeslat",
1431
1692
  questions_type_answer: "Napíšu to sám",
1432
- questions_answer_placeholder: "Napište svou odpověď…"
1433
- }, Me = {
1693
+ questions_answer_placeholder: "Napište svou odpověď…",
1694
+ close_conversation_title: "Uzavřít konverzaci",
1695
+ close_conversation_description: "Opravdu chcete tuto konverzaci uzavřít?",
1696
+ close_conversation_cancel: "Ne",
1697
+ close_conversation_confirm: "Ano",
1698
+ dialog_close: "Zavřít",
1699
+ zoom_in: "Přiblížit",
1700
+ zoom_out: "Oddálit",
1701
+ reset_zoom: "Obnovit přiblížení",
1702
+ support_chat_aria_label: "Chat podpory"
1703
+ }, He = {
1434
1704
  write_a_message_placeholder: "Skriv en besked...",
1435
1705
  your_issue_has_been_resolved: "Dit problem er løst!",
1436
1706
  new_conversation: "Ny samtale",
@@ -1517,8 +1787,17 @@ const Ee = {
1517
1787
  questions_next: "Næste",
1518
1788
  questions_send: "Send",
1519
1789
  questions_type_answer: "Jeg skriver det selv",
1520
- questions_answer_placeholder: "Skriv dit svar…"
1521
- }, Ie = {
1790
+ questions_answer_placeholder: "Skriv dit svar…",
1791
+ close_conversation_title: "Luk samtale",
1792
+ close_conversation_description: "Er du sikker på, at du vil lukke denne samtale?",
1793
+ close_conversation_cancel: "Nej",
1794
+ close_conversation_confirm: "Ja",
1795
+ dialog_close: "Luk",
1796
+ zoom_in: "Zoom ind",
1797
+ zoom_out: "Zoom ud",
1798
+ reset_zoom: "Nulstil zoom",
1799
+ support_chat_aria_label: "Supportchat"
1800
+ }, Ze = {
1522
1801
  write_a_message_placeholder: "Γράψτε ένα μήνυμα...",
1523
1802
  your_issue_has_been_resolved: "Το πρόβλημά σας επιλύθηκε!",
1524
1803
  new_conversation: "Νέα συνομιλία",
@@ -1605,8 +1884,17 @@ const Ee = {
1605
1884
  questions_next: "Επόμενο",
1606
1885
  questions_send: "Αποστολή",
1607
1886
  questions_type_answer: "Θα το γράψω",
1608
- questions_answer_placeholder: "Γράψτε την απάντησή σας…"
1609
- }, De = {
1887
+ questions_answer_placeholder: "Γράψτε την απάντησή σας…",
1888
+ close_conversation_title: "Κλείσιμο συνομιλίας",
1889
+ close_conversation_description: "Είστε βέβαιοι ότι θέλετε να κλείσετε αυτήν τη συνομιλία;",
1890
+ close_conversation_cancel: "Όχι",
1891
+ close_conversation_confirm: "Ναι",
1892
+ dialog_close: "Κλείσιμο",
1893
+ zoom_in: "Μεγέθυνση",
1894
+ zoom_out: "Σμίκρυνση",
1895
+ reset_zoom: "Επαναφορά ζουμ",
1896
+ support_chat_aria_label: "Συνομιλία υποστήριξης"
1897
+ }, We = {
1610
1898
  write_a_message_placeholder: "Nachricht schreiben...",
1611
1899
  your_issue_has_been_resolved: "Ihr Problem wurde gelöst!",
1612
1900
  new_conversation: "Neue Konversation",
@@ -1693,8 +1981,17 @@ const Ee = {
1693
1981
  questions_next: "Weiter",
1694
1982
  questions_send: "Senden",
1695
1983
  questions_type_answer: "Ich schreibe es selbst",
1696
- questions_answer_placeholder: "Antwort eingeben…"
1697
- }, Ne = {
1984
+ questions_answer_placeholder: "Antwort eingeben…",
1985
+ close_conversation_title: "Konversation schließen",
1986
+ close_conversation_description: "Möchten Sie diese Konversation wirklich schließen?",
1987
+ close_conversation_cancel: "Nein",
1988
+ close_conversation_confirm: "Ja",
1989
+ dialog_close: "Schließen",
1990
+ zoom_in: "Vergrößern",
1991
+ zoom_out: "Verkleinern",
1992
+ reset_zoom: "Zoom zurücksetzen",
1993
+ support_chat_aria_label: "Support-Chat"
1994
+ }, J = {
1698
1995
  write_a_message_placeholder: "Write a message...",
1699
1996
  your_issue_has_been_resolved: "Your issue has been resolved!",
1700
1997
  new_conversation: "New conversation",
@@ -1718,7 +2015,19 @@ const Ee = {
1718
2015
  companion_layout_floating: "Floating",
1719
2016
  companion_layout_sidebar: "Sidebar",
1720
2017
  companion_layout_fullscreen: "Fullscreen",
2018
+ companion_close_chat: "Close {title}",
1721
2019
  companion_close: "Close",
2020
+ companion_switch_chat: "Switch chat",
2021
+ companion_viewing: "Viewing",
2022
+ companion_working: "Working",
2023
+ companion_open: "Open",
2024
+ companion_closed: "Closed",
2025
+ companion_draft: "Draft",
2026
+ companion_chats: "Active sessions",
2027
+ companion_chat_number: "Chat {count}",
2028
+ companion_active_chats: "{count} active sessions",
2029
+ companion_other_sessions: "Other open sessions: {count}",
2030
+ companion_working_chats: "{count} working",
1722
2031
  companion_history: "Conversation history",
1723
2032
  companion_expand_chat: "Expand chat",
1724
2033
  companion_sidebar_dock_label: "Dock",
@@ -1781,8 +2090,17 @@ const Ee = {
1781
2090
  questions_next: "Next",
1782
2091
  questions_send: "Send",
1783
2092
  questions_type_answer: "I'll type it",
1784
- questions_answer_placeholder: "Type your answer…"
1785
- }, Re = {
2093
+ questions_answer_placeholder: "Type your answer…",
2094
+ close_conversation_title: "Close conversation",
2095
+ close_conversation_description: "Are you sure you want to close this conversation?",
2096
+ close_conversation_cancel: "No",
2097
+ close_conversation_confirm: "Yes",
2098
+ dialog_close: "Close",
2099
+ zoom_in: "Zoom in",
2100
+ zoom_out: "Zoom out",
2101
+ reset_zoom: "Reset zoom",
2102
+ support_chat_aria_label: "Support chat"
2103
+ }, Ge = {
1786
2104
  write_a_message_placeholder: "Escribe un mensaje...",
1787
2105
  your_issue_has_been_resolved: "¡Tu problema fue resuelto!",
1788
2106
  new_conversation: "Nueva conversación",
@@ -1869,8 +2187,17 @@ const Ee = {
1869
2187
  questions_next: "Siguiente",
1870
2188
  questions_send: "Enviar",
1871
2189
  questions_type_answer: "Lo escribo yo",
1872
- questions_answer_placeholder: "Escribe tu respuesta…"
1873
- }, Ke = {
2190
+ questions_answer_placeholder: "Escribe tu respuesta…",
2191
+ close_conversation_title: "Cerrar conversación",
2192
+ close_conversation_description: "¿Seguro que quieres cerrar esta conversación?",
2193
+ close_conversation_cancel: "No",
2194
+ close_conversation_confirm: "Sí",
2195
+ dialog_close: "Cerrar",
2196
+ zoom_in: "Acercar",
2197
+ zoom_out: "Alejar",
2198
+ reset_zoom: "Restablecer zoom",
2199
+ support_chat_aria_label: "Chat de soporte"
2200
+ }, $e = {
1874
2201
  write_a_message_placeholder: "Magsulat ng mensahe...",
1875
2202
  your_issue_has_been_resolved: "Nalutas na ang iyong isyu!",
1876
2203
  new_conversation: "Bagong usapan",
@@ -1957,8 +2284,17 @@ const Ee = {
1957
2284
  questions_next: "Susunod",
1958
2285
  questions_send: "Ipadala",
1959
2286
  questions_type_answer: "Ako na ang magta-type",
1960
- questions_answer_placeholder: "I-type ang iyong sagot…"
1961
- }, Le = {
2287
+ questions_answer_placeholder: "I-type ang iyong sagot…",
2288
+ close_conversation_title: "Isara ang usapan",
2289
+ close_conversation_description: "Sigurado ka bang gusto mong isara ang usapang ito?",
2290
+ close_conversation_cancel: "Hindi",
2291
+ close_conversation_confirm: "Oo",
2292
+ dialog_close: "Isara",
2293
+ zoom_in: "Palakihin",
2294
+ zoom_out: "Paliitin",
2295
+ reset_zoom: "I-reset ang zoom",
2296
+ support_chat_aria_label: "Chat ng suporta"
2297
+ }, Je = {
1962
2298
  write_a_message_placeholder: "Kirjoita viesti...",
1963
2299
  your_issue_has_been_resolved: "Ongelmasi on ratkaistu!",
1964
2300
  new_conversation: "Uusi keskustelu",
@@ -2045,8 +2381,17 @@ const Ee = {
2045
2381
  questions_next: "Seuraava",
2046
2382
  questions_send: "Lähetä",
2047
2383
  questions_type_answer: "Kirjoitan itse",
2048
- questions_answer_placeholder: "Kirjoita vastauksesi…"
2049
- }, Fe = {
2384
+ questions_answer_placeholder: "Kirjoita vastauksesi…",
2385
+ close_conversation_title: "Sulje keskustelu",
2386
+ close_conversation_description: "Haluatko varmasti sulkea tämän keskustelun?",
2387
+ close_conversation_cancel: "Ei",
2388
+ close_conversation_confirm: "Kyllä",
2389
+ dialog_close: "Sulje",
2390
+ zoom_in: "Lähennä",
2391
+ zoom_out: "Loitonna",
2392
+ reset_zoom: "Palauta zoomaus",
2393
+ support_chat_aria_label: "Tukichat"
2394
+ }, Ye = {
2050
2395
  write_a_message_placeholder: "Écrivez un message...",
2051
2396
  your_issue_has_been_resolved: "Votre problème a été résolu !",
2052
2397
  new_conversation: "Nouvelle conversation",
@@ -2133,8 +2478,17 @@ const Ee = {
2133
2478
  questions_next: "Suivant",
2134
2479
  questions_send: "Envoyer",
2135
2480
  questions_type_answer: "Je préfère écrire",
2136
- questions_answer_placeholder: "Écrivez votre réponse…"
2137
- }, Oe = {
2481
+ questions_answer_placeholder: "Écrivez votre réponse…",
2482
+ close_conversation_title: "Fermer la conversation",
2483
+ close_conversation_description: "Voulez-vous vraiment fermer cette conversation ?",
2484
+ close_conversation_cancel: "Non",
2485
+ close_conversation_confirm: "Oui",
2486
+ dialog_close: "Fermer",
2487
+ zoom_in: "Zoom avant",
2488
+ zoom_out: "Zoom arrière",
2489
+ reset_zoom: "Réinitialiser le zoom",
2490
+ support_chat_aria_label: "Chat de support"
2491
+ }, Qe = {
2138
2492
  write_a_message_placeholder: "एक संदेश लिखें...",
2139
2493
  your_issue_has_been_resolved: "आपकी समस्या हल हो गई है!",
2140
2494
  new_conversation: "नई बातचीत",
@@ -2221,8 +2575,17 @@ const Ee = {
2221
2575
  questions_next: "आगे",
2222
2576
  questions_send: "भेजें",
2223
2577
  questions_type_answer: "मैं खुद लिखूंगा",
2224
- questions_answer_placeholder: "अपना उत्तर लिखें…"
2225
- }, Ue = {
2578
+ questions_answer_placeholder: "अपना उत्तर लिखें…",
2579
+ close_conversation_title: "बातचीत बंद करें",
2580
+ close_conversation_description: "क्या आप वाकई इस बातचीत को बंद करना चाहते हैं?",
2581
+ close_conversation_cancel: "नहीं",
2582
+ close_conversation_confirm: "हाँ",
2583
+ dialog_close: "बंद करें",
2584
+ zoom_in: "ज़ूम इन",
2585
+ zoom_out: "ज़ूम आउट",
2586
+ reset_zoom: "ज़ूम रीसेट करें",
2587
+ support_chat_aria_label: "सहायता चैट"
2588
+ }, Xe = {
2226
2589
  write_a_message_placeholder: "Scrivi un messaggio...",
2227
2590
  your_issue_has_been_resolved: "Il tuo problema è stato risolto!",
2228
2591
  new_conversation: "Nuova conversazione",
@@ -2309,8 +2672,17 @@ const Ee = {
2309
2672
  questions_next: "Avanti",
2310
2673
  questions_send: "Invia",
2311
2674
  questions_type_answer: "Lo scrivo io",
2312
- questions_answer_placeholder: "Scrivi la tua risposta…"
2313
- }, Be = {
2675
+ questions_answer_placeholder: "Scrivi la tua risposta…",
2676
+ close_conversation_title: "Chiudi conversazione",
2677
+ close_conversation_description: "Vuoi davvero chiudere questa conversazione?",
2678
+ close_conversation_cancel: "No",
2679
+ close_conversation_confirm: "Sì",
2680
+ dialog_close: "Chiudi",
2681
+ zoom_in: "Ingrandisci",
2682
+ zoom_out: "Riduci",
2683
+ reset_zoom: "Reimposta zoom",
2684
+ support_chat_aria_label: "Chat di supporto"
2685
+ }, ea = {
2314
2686
  write_a_message_placeholder: "メッセージを入力...",
2315
2687
  your_issue_has_been_resolved: "問題が解決しました!",
2316
2688
  new_conversation: "新しい会話",
@@ -2397,8 +2769,17 @@ const Ee = {
2397
2769
  questions_next: "次へ",
2398
2770
  questions_send: "送信",
2399
2771
  questions_type_answer: "自分で入力する",
2400
- questions_answer_placeholder: "回答を入力してください…"
2401
- }, Ve = {
2772
+ questions_answer_placeholder: "回答を入力してください…",
2773
+ close_conversation_title: "会話を終了",
2774
+ close_conversation_description: "この会話を終了してもよろしいですか?",
2775
+ close_conversation_cancel: "いいえ",
2776
+ close_conversation_confirm: "はい",
2777
+ dialog_close: "閉じる",
2778
+ zoom_in: "拡大",
2779
+ zoom_out: "縮小",
2780
+ reset_zoom: "ズームをリセット",
2781
+ support_chat_aria_label: "サポートチャット"
2782
+ }, aa = {
2402
2783
  write_a_message_placeholder: "메시지를 입력하세요...",
2403
2784
  your_issue_has_been_resolved: "문제가 해결되었습니다!",
2404
2785
  new_conversation: "새 대화",
@@ -2485,8 +2866,17 @@ const Ee = {
2485
2866
  questions_next: "다음",
2486
2867
  questions_send: "보내기",
2487
2868
  questions_type_answer: "직접 입력할게요",
2488
- questions_answer_placeholder: "답변을 입력하세요…"
2489
- }, He = {
2869
+ questions_answer_placeholder: "답변을 입력하세요…",
2870
+ close_conversation_title: "대화 종료",
2871
+ close_conversation_description: "이 대화를 종료하시겠습니까?",
2872
+ close_conversation_cancel: "아니요",
2873
+ close_conversation_confirm: "예",
2874
+ dialog_close: "닫기",
2875
+ zoom_in: "확대",
2876
+ zoom_out: "축소",
2877
+ reset_zoom: "확대/축소 초기화",
2878
+ support_chat_aria_label: "고객 지원 채팅"
2879
+ }, ta = {
2490
2880
  write_a_message_placeholder: "Schrijf een bericht...",
2491
2881
  your_issue_has_been_resolved: "Uw probleem is opgelost!",
2492
2882
  new_conversation: "Nieuw gesprek",
@@ -2573,8 +2963,17 @@ const Ee = {
2573
2963
  questions_next: "Volgende",
2574
2964
  questions_send: "Verzenden",
2575
2965
  questions_type_answer: "Ik typ het zelf",
2576
- questions_answer_placeholder: "Typ je antwoord…"
2577
- }, Ge = {
2966
+ questions_answer_placeholder: "Typ je antwoord…",
2967
+ close_conversation_title: "Gesprek sluiten",
2968
+ close_conversation_description: "Weet je zeker dat je dit gesprek wilt sluiten?",
2969
+ close_conversation_cancel: "Nee",
2970
+ close_conversation_confirm: "Ja",
2971
+ dialog_close: "Sluiten",
2972
+ zoom_in: "Inzoomen",
2973
+ zoom_out: "Uitzoomen",
2974
+ reset_zoom: "Zoom herstellen",
2975
+ support_chat_aria_label: "Supportchat"
2976
+ }, sa = {
2578
2977
  write_a_message_placeholder: "Skriv en melding...",
2579
2978
  your_issue_has_been_resolved: "Problemet ditt er løst!",
2580
2979
  new_conversation: "Ny samtale",
@@ -2661,8 +3060,17 @@ const Ee = {
2661
3060
  questions_next: "Neste",
2662
3061
  questions_send: "Send",
2663
3062
  questions_type_answer: "Jeg skriver det selv",
2664
- questions_answer_placeholder: "Skriv svaret ditt…"
2665
- }, We = {
3063
+ questions_answer_placeholder: "Skriv svaret ditt…",
3064
+ close_conversation_title: "Lukk samtale",
3065
+ close_conversation_description: "Er du sikker på at du vil lukke denne samtalen?",
3066
+ close_conversation_cancel: "Nei",
3067
+ close_conversation_confirm: "Ja",
3068
+ dialog_close: "Lukk",
3069
+ zoom_in: "Zoom inn",
3070
+ zoom_out: "Zoom ut",
3071
+ reset_zoom: "Tilbakestill zoom",
3072
+ support_chat_aria_label: "Support-chat"
3073
+ }, oa = {
2666
3074
  write_a_message_placeholder: "Napisz wiadomość...",
2667
3075
  your_issue_has_been_resolved: "Twój problem został rozwiązany!",
2668
3076
  new_conversation: "Nowa rozmowa",
@@ -2749,8 +3157,17 @@ const Ee = {
2749
3157
  questions_next: "Dalej",
2750
3158
  questions_send: "Wyślij",
2751
3159
  questions_type_answer: "Napiszę sam",
2752
- questions_answer_placeholder: "Wpisz swoją odpowiedź…"
2753
- }, $e = {
3160
+ questions_answer_placeholder: "Wpisz swoją odpowiedź…",
3161
+ close_conversation_title: "Zamknij rozmowę",
3162
+ close_conversation_description: "Czy na pewno chcesz zamknąć tę rozmowę?",
3163
+ close_conversation_cancel: "Nie",
3164
+ close_conversation_confirm: "Tak",
3165
+ dialog_close: "Zamknij",
3166
+ zoom_in: "Powiększ",
3167
+ zoom_out: "Pomniejsz",
3168
+ reset_zoom: "Resetuj powiększenie",
3169
+ support_chat_aria_label: "Czat pomocy"
3170
+ }, na = {
2754
3171
  write_a_message_placeholder: "Escreva uma mensagem...",
2755
3172
  your_issue_has_been_resolved: "Seu problema foi resolvido!",
2756
3173
  new_conversation: "Nova conversa",
@@ -2837,8 +3254,17 @@ const Ee = {
2837
3254
  questions_next: "Seguinte",
2838
3255
  questions_send: "Enviar",
2839
3256
  questions_type_answer: "Prefiro escrever",
2840
- questions_answer_placeholder: "Escreva a sua resposta…"
2841
- }, Ze = {
3257
+ questions_answer_placeholder: "Escreva a sua resposta…",
3258
+ close_conversation_title: "Encerrar conversa",
3259
+ close_conversation_description: "Tem certeza de que deseja encerrar esta conversa?",
3260
+ close_conversation_cancel: "Não",
3261
+ close_conversation_confirm: "Sim",
3262
+ dialog_close: "Fechar",
3263
+ zoom_in: "Ampliar",
3264
+ zoom_out: "Reduzir",
3265
+ reset_zoom: "Redefinir zoom",
3266
+ support_chat_aria_label: "Chat de suporte"
3267
+ }, ia = {
2842
3268
  write_a_message_placeholder: "Scrie un mesaj...",
2843
3269
  your_issue_has_been_resolved: "Problema ta a fost rezolvată!",
2844
3270
  new_conversation: "Conversație nouă",
@@ -2925,8 +3351,17 @@ const Ee = {
2925
3351
  questions_next: "Înainte",
2926
3352
  questions_send: "Trimite",
2927
3353
  questions_type_answer: "Scriu eu",
2928
- questions_answer_placeholder: "Scrieți răspunsul dvs.…"
2929
- }, Je = {
3354
+ questions_answer_placeholder: "Scrieți răspunsul dvs.…",
3355
+ close_conversation_title: "Închide conversația",
3356
+ close_conversation_description: "Sigur vrei să închizi această conversație?",
3357
+ close_conversation_cancel: "Nu",
3358
+ close_conversation_confirm: "Da",
3359
+ dialog_close: "Închide",
3360
+ zoom_in: "Mărește",
3361
+ zoom_out: "Micșorează",
3362
+ reset_zoom: "Resetează zoomul",
3363
+ support_chat_aria_label: "Chat de asistență"
3364
+ }, ra = {
2930
3365
  write_a_message_placeholder: "Skriv ett meddelande...",
2931
3366
  your_issue_has_been_resolved: "Ditt problem har lösts!",
2932
3367
  new_conversation: "Ny konversation",
@@ -3013,8 +3448,17 @@ const Ee = {
3013
3448
  questions_next: "Nästa",
3014
3449
  questions_send: "Skicka",
3015
3450
  questions_type_answer: "Jag skriver själv",
3016
- questions_answer_placeholder: "Skriv ditt svar…"
3017
- }, Ye = {
3451
+ questions_answer_placeholder: "Skriv ditt svar…",
3452
+ close_conversation_title: "Avsluta konversation",
3453
+ close_conversation_description: "Är du säker på att du vill avsluta den här konversationen?",
3454
+ close_conversation_cancel: "Nej",
3455
+ close_conversation_confirm: "Ja",
3456
+ dialog_close: "Stäng",
3457
+ zoom_in: "Zooma in",
3458
+ zoom_out: "Zooma ut",
3459
+ reset_zoom: "Återställ zoom",
3460
+ support_chat_aria_label: "Supportchatt"
3461
+ }, _a = {
3018
3462
  write_a_message_placeholder: "Напишите сообщение...",
3019
3463
  your_issue_has_been_resolved: "Ваша проблема решена!",
3020
3464
  new_conversation: "Новый разговор",
@@ -3101,8 +3545,17 @@ const Ee = {
3101
3545
  questions_next: "Далее",
3102
3546
  questions_send: "Отправить",
3103
3547
  questions_type_answer: "Напишу сам",
3104
- questions_answer_placeholder: "Напишите ваш ответ…"
3105
- }, Qe = {
3548
+ questions_answer_placeholder: "Напишите ваш ответ…",
3549
+ close_conversation_title: "Закрыть разговор",
3550
+ close_conversation_description: "Вы уверены, что хотите закрыть этот разговор?",
3551
+ close_conversation_cancel: "Нет",
3552
+ close_conversation_confirm: "Да",
3553
+ dialog_close: "Закрыть",
3554
+ zoom_in: "Увеличить",
3555
+ zoom_out: "Уменьшить",
3556
+ reset_zoom: "Сбросить масштаб",
3557
+ support_chat_aria_label: "Чат поддержки"
3558
+ }, la = {
3106
3559
  write_a_message_placeholder: "เขียนข้อความ...",
3107
3560
  your_issue_has_been_resolved: "ปัญหาของคุณได้รับการแก้ไขแล้ว!",
3108
3561
  new_conversation: "การสนทนาใหม่",
@@ -3189,8 +3642,17 @@ const Ee = {
3189
3642
  questions_next: "ถัดไป",
3190
3643
  questions_send: "ส่ง",
3191
3644
  questions_type_answer: "ขอพิมพ์เอง",
3192
- questions_answer_placeholder: "พิมพ์คำตอบของคุณ…"
3193
- }, Xe = {
3645
+ questions_answer_placeholder: "พิมพ์คำตอบของคุณ…",
3646
+ close_conversation_title: "ปิดการสนทนา",
3647
+ close_conversation_description: "คุณแน่ใจหรือไม่ว่าต้องการปิดการสนทนานี้?",
3648
+ close_conversation_cancel: "ไม่",
3649
+ close_conversation_confirm: "ใช่",
3650
+ dialog_close: "ปิด",
3651
+ zoom_in: "ขยาย",
3652
+ zoom_out: "ย่อ",
3653
+ reset_zoom: "รีเซ็ตการซูม",
3654
+ support_chat_aria_label: "แชทฝ่ายสนับสนุน"
3655
+ }, ca = {
3194
3656
  write_a_message_placeholder: "Bir mesaj yazın...",
3195
3657
  your_issue_has_been_resolved: "Sorununuz çözüldü!",
3196
3658
  new_conversation: "Yeni konuşma",
@@ -3277,8 +3739,17 @@ const Ee = {
3277
3739
  questions_next: "İleri",
3278
3740
  questions_send: "Gönder",
3279
3741
  questions_type_answer: "Kendim yazayım",
3280
- questions_answer_placeholder: "Yanıtınızı yazın…"
3281
- }, ea = {
3742
+ questions_answer_placeholder: "Yanıtınızı yazın…",
3743
+ close_conversation_title: "Görüşmeyi kapat",
3744
+ close_conversation_description: "Bu görüşmeyi kapatmak istediğinizden emin misiniz?",
3745
+ close_conversation_cancel: "Hayır",
3746
+ close_conversation_confirm: "Evet",
3747
+ dialog_close: "Kapat",
3748
+ zoom_in: "Yakınlaştır",
3749
+ zoom_out: "Uzaklaştır",
3750
+ reset_zoom: "Yakınlaştırmayı sıfırla",
3751
+ support_chat_aria_label: "Destek sohbeti"
3752
+ }, pa = {
3282
3753
  write_a_message_placeholder: "پیغام لکھیں...",
3283
3754
  your_issue_has_been_resolved: "آپ کا مسئلہ حل ہو گیا ہے!",
3284
3755
  new_conversation: "نئی گفتگو",
@@ -3365,8 +3836,17 @@ const Ee = {
3365
3836
  questions_next: "اگلا",
3366
3837
  questions_send: "بھیجیں",
3367
3838
  questions_type_answer: "میں خود لکھوں گا",
3368
- questions_answer_placeholder: "اپنا جواب لکھیں…"
3369
- }, aa = {
3839
+ questions_answer_placeholder: "اپنا جواب لکھیں…",
3840
+ close_conversation_title: "گفتگو بند کریں",
3841
+ close_conversation_description: "کیا آپ واقعی یہ گفتگو بند کرنا چاہتے ہیں؟",
3842
+ close_conversation_cancel: "نہیں",
3843
+ close_conversation_confirm: "ہاں",
3844
+ dialog_close: "بند کریں",
3845
+ zoom_in: "زوم اِن",
3846
+ zoom_out: "زوم آؤٹ",
3847
+ reset_zoom: "زوم دوبارہ ترتیب دیں",
3848
+ support_chat_aria_label: "سپورٹ چیٹ"
3849
+ }, da = {
3370
3850
  write_a_message_placeholder: "Viết tin nhắn...",
3371
3851
  your_issue_has_been_resolved: "Vấn đề của bạn đã được giải quyết!",
3372
3852
  new_conversation: "Cuộc trò chuyện mới",
@@ -3453,8 +3933,17 @@ const Ee = {
3453
3933
  questions_next: "Tiếp theo",
3454
3934
  questions_send: "Gửi",
3455
3935
  questions_type_answer: "Tôi sẽ tự nhập",
3456
- questions_answer_placeholder: "Nhập câu trả lời của bạn…"
3457
- }, ta = {
3936
+ questions_answer_placeholder: "Nhập câu trả lời của bạn…",
3937
+ close_conversation_title: "Đóng cuộc trò chuyện",
3938
+ close_conversation_description: "Bạn có chắc muốn đóng cuộc trò chuyện này không?",
3939
+ close_conversation_cancel: "Không",
3940
+ close_conversation_confirm: "Có",
3941
+ dialog_close: "Đóng",
3942
+ zoom_in: "Phóng to",
3943
+ zoom_out: "Thu nhỏ",
3944
+ reset_zoom: "Đặt lại thu phóng",
3945
+ support_chat_aria_label: "Trò chuyện hỗ trợ"
3946
+ }, ua = {
3458
3947
  write_a_message_placeholder: "写一条消息...",
3459
3948
  your_issue_has_been_resolved: "您的问题已解决!",
3460
3949
  new_conversation: "新对话",
@@ -3541,8 +4030,17 @@ const Ee = {
3541
4030
  questions_next: "下一步",
3542
4031
  questions_send: "发送",
3543
4032
  questions_type_answer: "我自己输入",
3544
- questions_answer_placeholder: "输入你的回答…"
3545
- }, sa = {
4033
+ questions_answer_placeholder: "输入你的回答…",
4034
+ close_conversation_title: "结束对话",
4035
+ close_conversation_description: "确定要结束此对话吗?",
4036
+ close_conversation_cancel: "否",
4037
+ close_conversation_confirm: "是",
4038
+ dialog_close: "关闭",
4039
+ zoom_in: "放大",
4040
+ zoom_out: "缩小",
4041
+ reset_zoom: "重置缩放",
4042
+ support_chat_aria_label: "支持对话"
4043
+ }, ma = {
3546
4044
  write_a_message_placeholder: "Napišite poruku...",
3547
4045
  your_issue_has_been_resolved: "Vaš problem je riješen!",
3548
4046
  new_conversation: "Novi razgovor",
@@ -3629,8 +4127,17 @@ const Ee = {
3629
4127
  questions_next: "Dalje",
3630
4128
  questions_send: "Pošalji",
3631
4129
  questions_type_answer: "Napisat ću sam",
3632
- questions_answer_placeholder: "Napišite svoj odgovor…"
3633
- }, na = {
4130
+ questions_answer_placeholder: "Napišite svoj odgovor…",
4131
+ close_conversation_title: "Zatvori razgovor",
4132
+ close_conversation_description: "Jeste li sigurni da želite zatvoriti ovaj razgovor?",
4133
+ close_conversation_cancel: "Ne",
4134
+ close_conversation_confirm: "Da",
4135
+ dialog_close: "Zatvori",
4136
+ zoom_in: "Približi",
4137
+ zoom_out: "Udalji",
4138
+ reset_zoom: "Poništi zumiranje",
4139
+ support_chat_aria_label: "Chat za podršku"
4140
+ }, ha = {
3634
4141
  write_a_message_placeholder: "Kirjuta sõnum...",
3635
4142
  your_issue_has_been_resolved: "Teie probleem on lahendatud!",
3636
4143
  new_conversation: "Uus vestlus",
@@ -3717,8 +4224,17 @@ const Ee = {
3717
4224
  questions_next: "Edasi",
3718
4225
  questions_send: "Saada",
3719
4226
  questions_type_answer: "Kirjutan ise",
3720
- questions_answer_placeholder: "Kirjutage oma vastus…"
3721
- }, oa = {
4227
+ questions_answer_placeholder: "Kirjutage oma vastus…",
4228
+ close_conversation_title: "Sulge vestlus",
4229
+ close_conversation_description: "Kas soovite kindlasti selle vestluse sulgeda?",
4230
+ close_conversation_cancel: "Ei",
4231
+ close_conversation_confirm: "Jah",
4232
+ dialog_close: "Sulge",
4233
+ zoom_in: "Suurenda",
4234
+ zoom_out: "Vähenda",
4235
+ reset_zoom: "Lähtesta suurendus",
4236
+ support_chat_aria_label: "Tugivestlus"
4237
+ }, ga = {
3722
4238
  write_a_message_placeholder: "Írjon üzenetet...",
3723
4239
  your_issue_has_been_resolved: "A problémája megoldódott!",
3724
4240
  new_conversation: "Új beszélgetés",
@@ -3805,8 +4321,17 @@ const Ee = {
3805
4321
  questions_next: "Tovább",
3806
4322
  questions_send: "Küldés",
3807
4323
  questions_type_answer: "Inkább leírom",
3808
- questions_answer_placeholder: "Írja le a válaszát…"
3809
- }, ia = {
4324
+ questions_answer_placeholder: "Írja le a válaszát…",
4325
+ close_conversation_title: "Beszélgetés lezárása",
4326
+ close_conversation_description: "Biztosan lezárja ezt a beszélgetést?",
4327
+ close_conversation_cancel: "Nem",
4328
+ close_conversation_confirm: "Igen",
4329
+ dialog_close: "Bezárás",
4330
+ zoom_in: "Nagyítás",
4331
+ zoom_out: "Kicsinyítés",
4332
+ reset_zoom: "Nagyítás visszaállítása",
4333
+ support_chat_aria_label: "Ügyfélszolgálati chat"
4334
+ }, ka = {
3810
4335
  write_a_message_placeholder: "Skrifaðu skilaboð...",
3811
4336
  your_issue_has_been_resolved: "Málið þitt hefur verið leyst!",
3812
4337
  new_conversation: "Nýtt samtal",
@@ -3893,8 +4418,17 @@ const Ee = {
3893
4418
  questions_next: "Áfram",
3894
4419
  questions_send: "Senda",
3895
4420
  questions_type_answer: "Ég skrifa það",
3896
- questions_answer_placeholder: "Skrifaðu svarið þitt…"
3897
- }, ra = {
4421
+ questions_answer_placeholder: "Skrifaðu svarið þitt…",
4422
+ close_conversation_title: "Loka samtali",
4423
+ close_conversation_description: "Ertu viss um að þú viljir loka þessu samtali?",
4424
+ close_conversation_cancel: "Nei",
4425
+ close_conversation_confirm: "Já",
4426
+ dialog_close: "Loka",
4427
+ zoom_in: "Auka aðdrátt",
4428
+ zoom_out: "Minnka aðdrátt",
4429
+ reset_zoom: "Endurstilla aðdrátt",
4430
+ support_chat_aria_label: "Þjónustuspjall"
4431
+ }, ba = {
3898
4432
  write_a_message_placeholder: "Rakstiet ziņojumu...",
3899
4433
  your_issue_has_been_resolved: "Jūsu problēma ir atrisināta!",
3900
4434
  new_conversation: "Jauna saruna",
@@ -3981,8 +4515,17 @@ const Ee = {
3981
4515
  questions_next: "Tālāk",
3982
4516
  questions_send: "Sūtīt",
3983
4517
  questions_type_answer: "Rakstīšu pats",
3984
- questions_answer_placeholder: "Ierakstiet savu atbildi…"
3985
- }, _a = {
4518
+ questions_answer_placeholder: "Ierakstiet savu atbildi…",
4519
+ close_conversation_title: "Aizvērt sarunu",
4520
+ close_conversation_description: "Vai tiešām vēlaties aizvērt šo sarunu?",
4521
+ close_conversation_cancel: "Nē",
4522
+ close_conversation_confirm: "Jā",
4523
+ dialog_close: "Aizvērt",
4524
+ zoom_in: "Pietuvināt",
4525
+ zoom_out: "Attālināt",
4526
+ reset_zoom: "Atiestatīt tālummaiņu",
4527
+ support_chat_aria_label: "Atbalsta tērzēšana"
4528
+ }, va = {
3986
4529
  write_a_message_placeholder: "Parašykite žinutę...",
3987
4530
  your_issue_has_been_resolved: "Jūsų problema išspręsta!",
3988
4531
  new_conversation: "Naujas pokalbis",
@@ -4069,8 +4612,17 @@ const Ee = {
4069
4612
  questions_next: "Toliau",
4070
4613
  questions_send: "Siųsti",
4071
4614
  questions_type_answer: "Parašysiu pats",
4072
- questions_answer_placeholder: "Parašykite savo atsakymą…"
4073
- }, la = {
4615
+ questions_answer_placeholder: "Parašykite savo atsakymą…",
4616
+ close_conversation_title: "Uždaryti pokalbį",
4617
+ close_conversation_description: "Ar tikrai norite uždaryti šį pokalbį?",
4618
+ close_conversation_cancel: "Ne",
4619
+ close_conversation_confirm: "Taip",
4620
+ dialog_close: "Uždaryti",
4621
+ zoom_in: "Priartinti",
4622
+ zoom_out: "Nutolinti",
4623
+ reset_zoom: "Atstatyti mastelį",
4624
+ support_chat_aria_label: "Pagalbos pokalbis"
4625
+ }, fa = {
4074
4626
  write_a_message_placeholder: "Schreift eng Noriicht...",
4075
4627
  your_issue_has_been_resolved: "Äert Problem gouf geléist!",
4076
4628
  new_conversation: "Nei Konversatioun",
@@ -4157,8 +4709,17 @@ const Ee = {
4157
4709
  questions_next: "Weider",
4158
4710
  questions_send: "Schécken",
4159
4711
  questions_type_answer: "Ech schreiwen et selwer",
4160
- questions_answer_placeholder: "Schreift Är Äntwert…"
4161
- }, ca = {
4712
+ questions_answer_placeholder: "Schreift Är Äntwert…",
4713
+ close_conversation_title: "Konversatioun zoumaachen",
4714
+ close_conversation_description: "Wëllt Dir dës Konversatioun wierklech zoumaachen?",
4715
+ close_conversation_cancel: "Nee",
4716
+ close_conversation_confirm: "Jo",
4717
+ dialog_close: "Zoumaachen",
4718
+ zoom_in: "Erazoomen",
4719
+ zoom_out: "Erauszoomen",
4720
+ reset_zoom: "Zoom zrécksetzen",
4721
+ support_chat_aria_label: "Support-Chat"
4722
+ }, ya = {
4162
4723
  write_a_message_placeholder: "Ikteb messaġġ...",
4163
4724
  your_issue_has_been_resolved: "Il-problema tiegħek ġiet riżolta!",
4164
4725
  new_conversation: "Konversazzjoni ġdida",
@@ -4245,8 +4806,17 @@ const Ee = {
4245
4806
  questions_next: "Li jmiss",
4246
4807
  questions_send: "Ibgħat",
4247
4808
  questions_type_answer: "Nikteb jien",
4248
- questions_answer_placeholder: "Ikteb it-tweġiba tiegħek…"
4249
- }, pa = {
4809
+ questions_answer_placeholder: "Ikteb it-tweġiba tiegħek…",
4810
+ close_conversation_title: "Agħlaq il-konversazzjoni",
4811
+ close_conversation_description: "Żgur li trid tagħlaq din il-konversazzjoni?",
4812
+ close_conversation_cancel: "Le",
4813
+ close_conversation_confirm: "Iva",
4814
+ dialog_close: "Agħlaq",
4815
+ zoom_in: "Kabbar",
4816
+ zoom_out: "Ċekken",
4817
+ reset_zoom: "Irrisettja ż-zoom",
4818
+ support_chat_aria_label: "Chat ta’ appoġġ"
4819
+ }, wa = {
4250
4820
  write_a_message_placeholder: "Skriv en melding...",
4251
4821
  your_issue_has_been_resolved: "Saken din er løst!",
4252
4822
  new_conversation: "Ny samtale",
@@ -4333,8 +4903,17 @@ const Ee = {
4333
4903
  questions_next: "Neste",
4334
4904
  questions_send: "Send",
4335
4905
  questions_type_answer: "Jeg skriver det selv",
4336
- questions_answer_placeholder: "Skriv svaret ditt…"
4337
- }, da = {
4906
+ questions_answer_placeholder: "Skriv svaret ditt…",
4907
+ close_conversation_title: "Lukk samtale",
4908
+ close_conversation_description: "Er du sikker på at du vil lukke denne samtalen?",
4909
+ close_conversation_cancel: "Nei",
4910
+ close_conversation_confirm: "Ja",
4911
+ dialog_close: "Lukk",
4912
+ zoom_in: "Zoom inn",
4913
+ zoom_out: "Zoom ut",
4914
+ reset_zoom: "Tilbakestill zoom",
4915
+ support_chat_aria_label: "Support-chat"
4916
+ }, ja = {
4338
4917
  write_a_message_placeholder: "Napíšte správu...",
4339
4918
  your_issue_has_been_resolved: "Váš problém bol vyriešený!",
4340
4919
  new_conversation: "Nová konverzácia",
@@ -4421,86 +5000,96 @@ const Ee = {
4421
5000
  questions_next: "Ďalej",
4422
5001
  questions_send: "Odoslať",
4423
5002
  questions_type_answer: "Napíšem to sám",
4424
- questions_answer_placeholder: "Napíšte svoju odpoveď…"
4425
- }, G = {
4426
- ar: Ee,
4427
- bn: Pe,
4428
- bg: Te,
4429
- cs: Ae,
4430
- da: Me,
4431
- de: De,
4432
- el: Ie,
4433
- en: Ne,
4434
- es: Re,
4435
- et: na,
4436
- fi: Le,
4437
- fil: Ke,
4438
- fr: Fe,
4439
- hi: Oe,
4440
- hr: sa,
4441
- hu: oa,
4442
- is: ia,
4443
- it: Ue,
4444
- ja: Be,
4445
- ko: Ve,
4446
- lb: la,
4447
- lt: _a,
4448
- lv: ra,
4449
- mt: ca,
4450
- nb: pa,
4451
- nl: He,
4452
- no: Ge,
4453
- pl: We,
4454
- pt: $e,
4455
- ro: Ze,
4456
- ru: Ye,
4457
- sk: da,
4458
- sv: Je,
4459
- th: Qe,
4460
- tr: Xe,
4461
- ur: ea,
4462
- vi: aa,
4463
- "zh-cn": ta
4464
- }, ma = Object.keys(G);
4465
- function ua(i) {
4466
- return ma.includes(i);
5003
+ questions_answer_placeholder: "Napíšte svoju odpoveď…",
5004
+ close_conversation_title: "Uzavrieť konverzáciu",
5005
+ close_conversation_description: "Naozaj chcete túto konverzáciu uzavrieť?",
5006
+ close_conversation_cancel: "Nie",
5007
+ close_conversation_confirm: "Áno",
5008
+ dialog_close: "Zavrieť",
5009
+ zoom_in: "Priblížiť",
5010
+ zoom_out: "Oddialiť",
5011
+ reset_zoom: "Obnoviť priblíženie",
5012
+ support_chat_aria_label: "Chat podpory"
5013
+ }, Y = {
5014
+ ar: Oe,
5015
+ bn: Ue,
5016
+ bg: Be,
5017
+ cs: Ve,
5018
+ da: He,
5019
+ de: We,
5020
+ el: Ze,
5021
+ en: J,
5022
+ es: Ge,
5023
+ et: ha,
5024
+ fi: Je,
5025
+ fil: $e,
5026
+ fr: Ye,
5027
+ hi: Qe,
5028
+ hr: ma,
5029
+ hu: ga,
5030
+ is: ka,
5031
+ it: Xe,
5032
+ ja: ea,
5033
+ ko: aa,
5034
+ lb: fa,
5035
+ lt: va,
5036
+ lv: ba,
5037
+ mt: ya,
5038
+ nb: wa,
5039
+ nl: ta,
5040
+ no: sa,
5041
+ pl: oa,
5042
+ pt: na,
5043
+ ro: ia,
5044
+ ru: _a,
5045
+ sk: ja,
5046
+ sv: ra,
5047
+ th: la,
5048
+ tr: ca,
5049
+ ur: pa,
5050
+ vi: da,
5051
+ "zh-cn": ua
5052
+ }, Sa = Object.keys(Y);
5053
+ function za(i) {
5054
+ return Sa.includes(i);
4467
5055
  }
4468
- const ha = /* @__PURE__ */ new Set(["ar", "ur"]);
4469
- function Ka(i) {
4470
- return ha.has(i);
5056
+ const Ca = /* @__PURE__ */ new Set(["ar", "ur"]);
5057
+ function Ja(i) {
5058
+ return Ca.has(i);
4471
5059
  }
4472
- function ga(i) {
4473
- return ua(i) ? i : "en";
5060
+ function xa(i) {
5061
+ return za(i) ? i : "en";
4474
5062
  }
4475
- function ka(i, e, t, o) {
5063
+ function qa(i, e, t, o) {
4476
5064
  var l;
4477
- const _ = ((l = t == null ? void 0 : t[e]) == null ? void 0 : l[i]) || G[e][i];
4478
- return o ? _.replace(
5065
+ const r = ((l = t == null ? void 0 : t[e]) == null ? void 0 : l[i]) || Y[e][i] || J[i] || i;
5066
+ return o ? r.replace(
4479
5067
  /\{(\w+)\}/g,
4480
- (a, n) => n in o ? String(o[n]) : a
4481
- ) : _;
5068
+ (s, a) => a in o ? String(o[a]) : s
5069
+ ) : r;
4482
5070
  }
4483
- function ba(i, e, t) {
4484
- return ka(
5071
+ function Ea(i, e, t) {
5072
+ return qa(
4485
5073
  e,
4486
- ga(i.language),
5074
+ xa(i.language),
4487
5075
  i.translationOverrides,
4488
5076
  t
4489
5077
  );
4490
5078
  }
4491
- class fa {
5079
+ class Aa {
4492
5080
  constructor({
4493
5081
  config: e,
4494
5082
  api: t,
4495
5083
  contactCtx: o,
4496
- storageCtx: _,
4497
- sessionsPollingIntervalSeconds: l
5084
+ storageCtx: r,
5085
+ sessionsPollingIntervalSeconds: l,
5086
+ sharedSessions: s
4498
5087
  }) {
4499
- this.sessionsRefresher = new V(), this.persistedSessionId = null, this.sessionState = new j({
5088
+ this.sessionsRefresher = new G(), this.persistedSessionId = null, this.sessionAbortController = new AbortController(), this.sessionState = new S({
4500
5089
  session: null,
4501
5090
  isCreatingSession: !1,
4502
5091
  isResolvingSession: !1
4503
- }), this.sessionsState = new j({
5092
+ }), this.sessionsState = new S({
4504
5093
  data: [],
4505
5094
  cursor: void 0,
4506
5095
  isLastPage: !1,
@@ -4510,14 +5099,25 @@ class fa {
4510
5099
  */
4511
5100
  isInitialFetchLoading: !0
4512
5101
  }), this.registerActiveSessionPersistence = () => {
4513
- const a = this.storageCtx;
4514
- a && this.sessionState.subscribe(({ session: n }) => {
4515
- const s = n != null && n.isOpened ? n.id : null;
4516
- if (s === this.persistedSessionId || !s && this.persistedSessionId === null) return;
4517
- this.persistedSessionId = s, (s ? a.setActiveSessionId(s) : a.clearActiveSessionId()).catch((c) => {
4518
- u.warn("failed to persist the active session", {
4519
- error: c instanceof Error ? c.message : String(c)
4520
- });
5102
+ this.storageCtx && (this.stopPersistingSession = this.sessionState.subscribe(
5103
+ this.persistSession
5104
+ ));
5105
+ }, this.restoreActiveSessionTracking = () => {
5106
+ var a;
5107
+ (a = this.stopPersistingSession) == null || a.call(this), this.stopPersistingSession = void 0, this.registerActiveSessionPersistence();
5108
+ }, this.trackActiveSession = (a) => {
5109
+ var n;
5110
+ (n = this.stopPersistingSession) == null || n.call(this), this.stopPersistingSession = a.sessionState.subscribe(
5111
+ this.persistSession
5112
+ ), this.persistSession(a.sessionState.get());
5113
+ }, this.persistSession = ({ session: a }) => {
5114
+ const n = this.storageCtx;
5115
+ if (!n) return;
5116
+ const c = a != null && a.isOpened ? a.id : null;
5117
+ if (c === this.persistedSessionId || !c && this.persistedSessionId === null) return;
5118
+ this.persistedSessionId = c, (c ? n.setActiveSessionId(c) : n.clearActiveSessionId()).catch((_) => {
5119
+ k.warn("failed to persist the active session", {
5120
+ error: _ instanceof Error ? _.message : String(_)
4521
5121
  });
4522
5122
  });
4523
5123
  }, this.getLastActiveSessionId = async () => {
@@ -4528,78 +5128,95 @@ class fa {
4528
5128
  return null;
4529
5129
  }
4530
5130
  }, this.reset = async () => {
4531
- this.sessionState.reset();
5131
+ this.sessionAbortController.abort(), this.sessionAbortController = new AbortController(), this.sessionState.reset();
4532
5132
  }, this.registerSessionsRefresherWrapper = () => {
4533
5133
  var a;
4534
5134
  // If the widget config was initially provided with a contact token, no state change would be triggered, so we just fetch
4535
- (a = this.contactCtx.state.get().contact) != null && a.token && !this.sessionsState.get().didStartInitialFetch ? this.registerSessionsRefresher() : this.contactCtx.state.subscribe(({ contact: n }) => {
4536
- n != null && n.token && !this.sessionsState.get().didStartInitialFetch && this.registerSessionsRefresher();
4537
- });
5135
+ (a = this.contactCtx.state.get().contact) != null && a.token && !this.sessionsState.get().didStartInitialFetch ? this.registerSessionsRefresher() : this.stopWaitingForContact = this.contactCtx.state.subscribe(
5136
+ ({ contact: n }) => {
5137
+ n != null && n.token && !this.sessionsState.get().didStartInitialFetch && this.registerSessionsRefresher();
5138
+ }
5139
+ );
4538
5140
  }, this.registerSessionsRefresher = () => {
4539
5141
  this.sessionsRefresher.startPolling(async () => {
4540
5142
  this.sessionsState.get().didStartInitialFetch === !1 && this.sessionsState.setPartial({ didStartInitialFetch: !0 }), await this.refreshSessions(), this.sessionsState.get().isInitialFetchLoading === !0 && this.sessionsState.setPartial({ isInitialFetchLoading: !1 });
4541
5143
  }, this.sessionsPollingIntervalSeconds * 1e3);
5144
+ }, this.dispose = ({ clearActiveSession: a = !1 } = {}) => {
5145
+ var n, c;
5146
+ 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(), a && this.storageCtx)
5147
+ return this.persistedSessionId = null, this.storageCtx.clearActiveSessionId().catch((d) => {
5148
+ k.warn("failed to clear the replaced session", {
5149
+ error: d instanceof Error ? d.message : String(d)
5150
+ });
5151
+ });
4542
5152
  }, this.getParsedCustomData = () => Object.fromEntries(
4543
5153
  Object.entries(this.config.sessionCustomData || {}).map(
4544
5154
  ([a, n]) => {
4545
- var s;
4546
- return typeof n == "string" ? [a, n] : typeof n == "boolean" ? [a, n] : typeof n == "number" ? [a, n] : [a, ((s = H(() => JSON.stringify(n))) == null ? void 0 : s.data) || ""];
5155
+ var c;
5156
+ return typeof n == "string" ? [a, n] : typeof n == "boolean" ? [a, n] : typeof n == "number" ? [a, n] : [a, ((c = $(() => JSON.stringify(n))) == null ? void 0 : c.data) || ""];
4547
5157
  }
4548
5158
  )
4549
5159
  ), this.createSession = async () => {
5160
+ const { signal: a } = this.sessionAbortController;
4550
5161
  this.sessionState.setPartial({ session: null, isCreatingSession: !0 });
4551
5162
  try {
4552
- const a = await this.requestSession();
4553
- if (a.session) return a.session;
4554
- if (a.status === 401 && await this.contactCtx.recoverFromStaleToken()) {
4555
- const n = await this.requestSession();
4556
- return n.session ? n.session : (u.error("failed to create session", n.error), null);
5163
+ const n = await this.requestSession(a);
5164
+ if (a.aborted) return null;
5165
+ if (n.session) return n.session;
5166
+ if (n.status === 401 && await this.contactCtx.recoverFromStaleToken()) {
5167
+ if (a.aborted) return null;
5168
+ const c = await this.requestSession(a);
5169
+ return a.aborted ? null : c.session ? c.session : (k.error("failed to create session", c.error), null);
4557
5170
  }
4558
- return u.error("failed to create session", a.error), null;
4559
- } catch (a) {
4560
- return u.error("failed to create session", a), null;
5171
+ return k.error("failed to create session", n.error), null;
5172
+ } catch (n) {
5173
+ return a.aborted || k.error("failed to create session", n), null;
4561
5174
  } finally {
4562
- this.sessionState.setPartial({ isCreatingSession: !1 });
5175
+ a.aborted || this.sessionState.setPartial({ isCreatingSession: !1 });
4563
5176
  }
4564
- }, this.requestSession = async () => {
4565
- var p, d, m;
4566
- const a = (p = this.contactCtx.state.get().contact) == null ? void 0 : p.externalId, n = {
5177
+ }, this.requestSession = async (a) => {
5178
+ var u, m, g;
5179
+ const n = (u = this.contactCtx.state.get().contact) == null ? void 0 : u.externalId, c = {
4567
5180
  ...this.getParsedCustomData(),
4568
- ...a ? { external_id: a } : {}
5181
+ ...n ? { external_id: n } : {}
4569
5182
  }, {
4570
- data: s,
4571
- error: r,
4572
- response: c
4573
- } = await this.api.createSession({
4574
- customData: Object.keys(n).length > 0 ? n : void 0
4575
- });
4576
- if (!s) return { session: null, status: c == null ? void 0 : c.status, error: r };
4577
- this.sessionState.setPartial({ session: s });
5183
+ data: d,
5184
+ error: _,
5185
+ response: p
5186
+ } = await this.api.createSession(
5187
+ {
5188
+ customData: Object.keys(c).length > 0 ? c : void 0
5189
+ },
5190
+ a
5191
+ );
5192
+ if (a.aborted || !d)
5193
+ return { session: null, status: p == null ? void 0 : p.status, error: _ };
5194
+ this.sessionState.setPartial({ session: d });
4578
5195
  try {
4579
- (m = (d = this.config.hooks) == null ? void 0 : d.onSessionCreated) == null || m.call(d, { session: s });
4580
- } catch (h) {
4581
- u.error("onSessionCreated hook failed", h);
5196
+ (g = (m = this.config.hooks) == null ? void 0 : m.onSessionCreated) == null || g.call(m, { session: d });
5197
+ } catch (v) {
5198
+ k.error("onSessionCreated hook failed", v);
4582
5199
  }
4583
- return { session: s, status: c.status, error: void 0 };
5200
+ return { session: d, status: p.status, error: void 0 };
4584
5201
  }, this.loadMoreSessions = async () => {
4585
5202
  if (this.sessionsState.get().isLastPage) return;
4586
5203
  const { data: a } = await this.getSessions({
4587
5204
  cursor: this.sessionsState.get().cursor
4588
5205
  });
4589
5206
  if (a) {
4590
- const s = [...this.sessionsState.get().data, ...a.items].filter(
4591
- (r, c, p) => c === p.findIndex((d) => r.id === d.id)
5207
+ const c = [...this.sessionsState.get().data, ...a.items].filter(
5208
+ (d, _, p) => _ === p.findIndex((u) => d.id === u.id)
4592
5209
  );
4593
5210
  this.sessionsState.setPartial({
4594
- data: s,
5211
+ data: c,
4595
5212
  cursor: a.next || void 0,
4596
5213
  isLastPage: a.next === null
4597
5214
  });
4598
5215
  }
4599
5216
  }, this.getSessions = async ({ cursor: a }) => {
4600
- var s, r;
4601
- if (!((s = this.contactCtx.state.get().contact) != null && s.token)) return { data: null };
4602
- const n = (r = this.contactCtx.state.get().contact) == null ? void 0 : r.externalId;
5217
+ var c, d;
5218
+ if (!((c = this.contactCtx.state.get().contact) != null && c.token)) return { data: null };
5219
+ const n = (d = this.contactCtx.state.get().contact) == null ? void 0 : d.externalId;
4603
5220
  return await this.api.getSessions({
4604
5221
  cursor: a,
4605
5222
  filters: n ? {
@@ -4608,7 +5225,7 @@ class fa {
4608
5225
  });
4609
5226
  }, this.setSessions = (a) => {
4610
5227
  const n = [...a, ...this.sessionsState.get().data].filter(
4611
- (s, r, c) => r === c.findIndex((p) => s.id === p.id)
5228
+ (c, d, _) => d === _.findIndex((p) => c.id === p.id)
4612
5229
  );
4613
5230
  this.sessionsState.setPartial({ data: n });
4614
5231
  }, this.refreshSessions = async () => {
@@ -4619,62 +5236,69 @@ class fa {
4619
5236
  if (!a || !a.isOpened)
4620
5237
  return { success: !1, error: "Session is not opened" };
4621
5238
  this.sessionState.setPartial({ isResolvingSession: !0 });
4622
- const { data: n, error: s } = await this.api.resolveSession({
4623
- session_id: a.id
5239
+ const { signal: n } = this.sessionAbortController, c = await this.api.resolveSession({ session_id: a.id }, n).catch((p) => {
5240
+ if (n.aborted) return null;
5241
+ throw p;
4624
5242
  });
4625
- return n ? (this.sessionState.setPartial({ session: n, isResolvingSession: !1 }), { success: !0, data: n }) : (this.sessionState.setPartial({ isResolvingSession: !1 }), { success: !1, error: s });
5243
+ if (!c || n.aborted)
5244
+ return { success: !1, error: "Session was reset" };
5245
+ const { data: d, error: _ } = c;
5246
+ return d ? (this.sessionState.setPartial({ session: d, isResolvingSession: !1 }), { success: !0, data: d }) : (this.sessionState.setPartial({ isResolvingSession: !1 }), { success: !1, error: _ });
4626
5247
  }, this.createStateCheckpoint = async (a) => {
4627
- var r;
4628
- const n = (r = this.sessionState.get().session) == null ? void 0 : r.id;
5248
+ var d;
5249
+ const n = (d = this.sessionState.get().session) == null ? void 0 : d.id;
4629
5250
  if (!n) return;
4630
- const { data: s } = await this.api.createStateCheckpoint({
5251
+ const { data: c } = await this.api.createStateCheckpoint({
4631
5252
  session_id: n,
4632
5253
  payload: a
4633
5254
  });
4634
- return s != null && s.success ? { success: !0 } : { success: !1 };
4635
- }, this.config = e, this.api = t, this.contactCtx = o, this.storageCtx = _, this.sessionsPollingIntervalSeconds = l, this.registerSessionsRefresherWrapper(), this.registerActiveSessionPersistence();
5255
+ return c != null && c.success ? { success: !0 } : { success: !1 };
5256
+ }, this.config = e, this.api = t, this.contactCtx = o, this.storageCtx = r, this.sessionsPollingIntervalSeconds = l, s ? this.sessionsState = s : this.registerSessionsRefresherWrapper(), this.registerActiveSessionPersistence();
4636
5257
  }
4637
5258
  }
4638
- const va = (i, e, { sendsPageContext: t }) => {
4639
- const o = ja(i), _ = t && e.mentions && e.mentions.length > 0 ? { mentions: e.mentions.map(ya) } : void 0, l = t && (e.clientContext || _) ? { ...o, ...e.clientContext, ..._ } : o;
5259
+ const Pa = (i, e, { sendsPageContext: t }) => {
5260
+ const o = Ma(i), r = t && e.mentions && e.mentions.length > 0 ? { mentions: e.mentions.map(Ta) } : void 0, l = t && (e.clientContext || r) ? { ...o, ...e.clientContext, ...r } : o, s = e.connectionRequestId ? {
5261
+ ...l,
5262
+ opencx__connection_request_id: e.connectionRequestId
5263
+ } : l, a = e.withPageEntity === !1 && s && "entity" in s ? Ia(s, "entity") : s;
4640
5264
  return {
4641
- clientContext: e.withPageEntity === !1 && l && "entity" in l ? wa(l, "entity") : l,
5265
+ clientContext: e.background ? { ...a, opencx__background: !0 } : a,
4642
5266
  custom_data: {
4643
5267
  ...i.messageCustomData || {},
4644
5268
  ...e.customData || {}
4645
5269
  }
4646
5270
  };
4647
- }, ya = ({ type: i, id: e, title: t, meta: o }) => ({
5271
+ }, Ta = ({ type: i, id: e, title: t, meta: o }) => ({
4648
5272
  type: i,
4649
5273
  id: e,
4650
5274
  title: t,
4651
5275
  ...o ? { meta: o } : {}
4652
- }), wa = (i, e) => {
5276
+ }), Ia = (i, e) => {
4653
5277
  const { [e]: t, ...o } = i;
4654
5278
  return Object.keys(o).length > 0 ? o : void 0;
4655
- }, ja = (i) => {
5279
+ }, Ma = (i) => {
4656
5280
  if (typeof i.context != "function") return i.context;
4657
5281
  try {
4658
5282
  return i.context();
4659
5283
  } catch (e) {
4660
- u.error("context getter threw; sending without context", e);
5284
+ k.error("context getter threw; sending without context", e);
4661
5285
  return;
4662
5286
  }
4663
- }, Sa = (i) => {
5287
+ }, Da = (i) => {
4664
5288
  const e = i.features;
4665
5289
  if (!e) return;
4666
5290
  const t = {};
4667
5291
  return e.preamble !== void 0 && (t.preamble = e.preamble), e.inlineUi !== void 0 && (t.inline_ui = e.inlineUi), e.pageContext !== void 0 && (t.page_context = e.pageContext), e.clientTools !== void 0 && (t.client_tools = e.clientTools), Object.keys(t).length > 0 ? t : void 0;
4668
- }, za = ({
5292
+ }, Na = ({
4669
5293
  config: i,
4670
5294
  input: e,
4671
5295
  uuid: t,
4672
5296
  sessionId: o,
4673
- content: _,
5297
+ content: r,
4674
5298
  initialMessages: l,
4675
- sendsPageContext: a
5299
+ sendsPageContext: s
4676
5300
  }) => {
4677
- var n;
5301
+ var a, n, c, d, _, p, u, m;
4678
5302
  return {
4679
5303
  uuid: t,
4680
5304
  bot_token: i.token,
@@ -4682,227 +5306,253 @@ const va = (i, e, { sendsPageContext: t }) => {
4682
5306
  query_params: i.queryParams,
4683
5307
  body_properties: i.bodyProperties,
4684
5308
  session_id: o,
4685
- content: _,
5309
+ content: r,
4686
5310
  attachments: e.attachments,
4687
- ...va(i, e, { sendsPageContext: a }),
5311
+ ...Pa(i, e, { sendsPageContext: s }),
4688
5312
  language: i.language,
4689
- features: Sa(i),
4690
- capabilities: ((n = i.capabilities) == null ? void 0 : n.structuredQuestions) === void 0 ? void 0 : { structured_questions: i.capabilities.structuredQuestions },
5313
+ features: Da(i),
5314
+ presentation: i.presentation,
5315
+ capabilities: [
5316
+ (a = i.capabilities) == null ? void 0 : a.connections,
5317
+ (n = i.capabilities) == null ? void 0 : n.structuredQuestions,
5318
+ (c = i.capabilities) == null ? void 0 : c.richReplies,
5319
+ (d = i.capabilities) == null ? void 0 : d.pageEffects
5320
+ ].some((g) => g !== void 0) ? {
5321
+ connections: (_ = i.capabilities) == null ? void 0 : _.connections,
5322
+ structured_questions: (p = i.capabilities) == null ? void 0 : p.structuredQuestions,
5323
+ rich_replies: (u = i.capabilities) == null ? void 0 : u.richReplies,
5324
+ page_effects: (m = i.capabilities) == null ? void 0 : m.pageEffects
5325
+ } : void 0,
4691
5326
  exit_mode_prompt: e.exitModePrompt,
4692
- initial_messages: l.length > 0 ? l.map((s) => ({ uuid: s.id, content: s.data.message })) : void 0
5327
+ initial_messages: l.length > 0 ? l.map((g) => ({ uuid: g.id, content: g.data.message })) : void 0
4693
5328
  };
4694
- }, z = class z {
5329
+ }, C = class C {
4695
5330
  constructor({
4696
5331
  config: e,
4697
5332
  api: t,
4698
5333
  sessionCtx: o,
4699
- contactCtx: _,
5334
+ contactCtx: r,
4700
5335
  streaming: l,
4701
- sendsPageContext: a,
4702
- getClientCapabilities: n
5336
+ sendsPageContext: s,
5337
+ getClientCapabilities: a,
5338
+ getRequestConfig: n,
5339
+ isStreaming: c,
5340
+ getSendsPageContext: d
4703
5341
  }) {
4704
- this.state = new j({
5342
+ this.state = new S({
4705
5343
  messages: [],
4706
5344
  isSendingMessage: !1,
4707
5345
  isSendingMessageToAI: !1,
5346
+ settledAgentUserMessageId: null,
4708
5347
  lastAIResMightSolveUserIssue: !1,
4709
5348
  isInitialFetchLoading: !1
5349
+ }), this.draftState = new S({
5350
+ text: "",
5351
+ mentions: []
4710
5352
  }), this.agentHandlers = null, this.bufferedAgentSends = [], this.sendMessageAbortController = new AbortController(), this.messageIdsDispatchedToOnMessageReceivedHook = /* @__PURE__ */ new Set(), this.sentTextHistory = [], this.reset = () => {
4711
- this.sendMessageAbortController.abort("Resetting chat"), this.bufferedAgentSends = [], this.state.reset(), this.messageIdsDispatchedToOnMessageReceivedHook.clear(), this.sentTextHistory = [];
4712
- }, this.rememberSentText = (s) => {
4713
- const r = s.trim();
4714
- !r || this.sentTextHistory.at(-1) === r || (this.sentTextHistory.push(r), this.sentTextHistory.length > z.SENT_TEXT_HISTORY_MAX && this.sentTextHistory.shift());
4715
- }, this.getSentTextHistory = () => this.sentTextHistory, this.registerAgentHandlers = (s) => {
4716
- this.agentHandlers = s;
4717
- const r = this.bufferedAgentSends;
4718
- this.bufferedAgentSends = [], r.forEach((c) => {
4719
- z.dispatchToEngine(s, c);
5353
+ this.sendMessageAbortController.abort("Resetting chat"), this.bufferedAgentSends = [], this.state.reset(), this.messageIdsDispatchedToOnMessageReceivedHook.clear(), this.sentTextHistory = [], this.draftState.reset();
5354
+ }, this.rememberSentText = (_) => {
5355
+ const p = _.trim();
5356
+ !p || this.sentTextHistory.at(-1) === p || (this.sentTextHistory.push(p), this.sentTextHistory.length > C.SENT_TEXT_HISTORY_MAX && this.sentTextHistory.shift());
5357
+ }, this.getSentTextHistory = () => this.sentTextHistory, this.registerAgentHandlers = (_) => {
5358
+ this.agentHandlers = _;
5359
+ const p = this.bufferedAgentSends;
5360
+ this.bufferedAgentSends = [], p.forEach((u) => {
5361
+ C.dispatchToEngine(_, u);
4720
5362
  });
4721
- }, this.unregisterAgentHandlers = (s) => {
4722
- this.agentHandlers === s && (this.agentHandlers = null);
4723
- }, this.dispatchToOnMessageReceivedHook = (s) => {
4724
- var c, p;
4725
- if (s.type === "USER" || this.messageIdsDispatchedToOnMessageReceivedHook.has(s.id))
5363
+ }, this.unregisterAgentHandlers = (_) => {
5364
+ this.agentHandlers === _ && (this.agentHandlers = null);
5365
+ }, this.dispatchToOnMessageReceivedHook = (_) => {
5366
+ var u, m;
5367
+ if (_.type === "USER" || this.messageIdsDispatchedToOnMessageReceivedHook.has(_.id))
4726
5368
  return;
4727
- const r = this.sessionCtx.sessionState.get().session;
4728
- r && (this.messageIdsDispatchedToOnMessageReceivedHook.add(s.id), (p = (c = this.config.hooks) == null ? void 0 : c.onMessageReceived) == null || p.call(c, { message: s, session: r }));
4729
- }, this.markAsDispatchedToOnMessageReceivedHook = (s) => {
4730
- s.forEach(
4731
- (r) => this.messageIdsDispatchedToOnMessageReceivedHook.add(r)
5369
+ const p = this.sessionCtx.sessionState.get().session;
5370
+ p && (this.messageIdsDispatchedToOnMessageReceivedHook.add(_.id), (m = (u = this.config.hooks) == null ? void 0 : u.onMessageReceived) == null || m.call(u, { message: _, session: p }));
5371
+ }, this.markAsDispatchedToOnMessageReceivedHook = (_) => {
5372
+ _.forEach(
5373
+ (p) => this.messageIdsDispatchedToOnMessageReceivedHook.add(p)
4732
5374
  );
4733
5375
  }, this.buildPersistentInitialMessages = () => {
4734
- var r, c;
4735
- return !((r = this.sessionCtx.sessionState.get().session) != null && r.id) && this.state.get().messages.length === 0 && ((c = this.config.advancedInitialMessages) == null ? void 0 : c.some((p) => p.persistent)) ? (this.config.advancedInitialMessages || []).filter((p) => p.persistent).map(
4736
- (p) => ({
5376
+ var p, u;
5377
+ 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(
5378
+ (m) => ({
4737
5379
  id: x(),
4738
5380
  component: "bot_message",
4739
5381
  type: "AI",
4740
5382
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
4741
- data: { message: p.message },
5383
+ data: { message: m.message },
4742
5384
  agent: this.config.bot ? { ...this.config.bot, isAi: !0, id: null } : void 0
4743
5385
  })
4744
5386
  ) : [];
4745
5387
  }, this.ensureSessionId = async () => {
4746
- var s, r;
4747
- if (!((s = this.sessionCtx.sessionState.get().session) != null && s.id)) {
5388
+ var _, p;
5389
+ if (!((_ = this.sessionCtx.sessionState.get().session) != null && _.id)) {
4748
5390
  if (!await this.sessionCtx.createSession()) return null;
4749
5391
  this.sessionCtx.refreshSessions();
4750
5392
  }
4751
- return ((r = this.sessionCtx.sessionState.get().session) == null ? void 0 : r.id) ?? null;
4752
- }, this.rollbackOptimisticMessages = (s) => {
4753
- if (s.length === 0) return;
4754
- const r = new Set(s), c = this.state.get().messages, p = c.filter((d) => !r.has(d.id));
4755
- p.length !== c.length && this.state.setPartial({ messages: p });
4756
- }, this.notifySendAccepted = (s) => {
4757
- var r;
5393
+ return ((p = this.sessionCtx.sessionState.get().session) == null ? void 0 : p.id) ?? null;
5394
+ }, this.rollbackOptimisticMessages = (_) => {
5395
+ if (_.length === 0) return;
5396
+ const p = new Set(_), u = this.state.get().messages, m = u.filter((g) => !p.has(g.id));
5397
+ m.length !== u.length && this.state.setPartial({ messages: m });
5398
+ }, this.notifySendAccepted = (_) => {
5399
+ var p;
4758
5400
  try {
4759
- (r = s.onAccepted) == null || r.call(s);
4760
- } catch (c) {
4761
- u.error("send acceptance callback failed", c);
5401
+ (p = _.onAccepted) == null || p.call(_);
5402
+ } catch (u) {
5403
+ k.error("send acceptance callback failed", u);
4762
5404
  }
4763
- }, this.stageUserTurn = async (s, { pending: r }) => {
4764
- const c = this.buildUserMessage(s);
4765
- if (!c) return null;
4766
- const p = r ? { ...c, pending: !0 } : c, d = this.buildPersistentInitialMessages(), m = [
4767
- ...d.map((g) => g.id),
4768
- p.id
5405
+ }, this.stageUserTurn = async (_, { pending: p }) => {
5406
+ const u = this.buildUserMessage(_);
5407
+ if (!u) return null;
5408
+ const m = p ? { ...u, pending: !0 } : u, g = this.buildPersistentInitialMessages(), v = [
5409
+ ...g.map((b) => b.id),
5410
+ m.id
4769
5411
  ];
4770
5412
  this.state.setPartial({
4771
- messages: [...d, ...this.state.get().messages, p]
5413
+ messages: [
5414
+ ...g,
5415
+ ...this.state.get().messages,
5416
+ ...m.background ? [] : [m]
5417
+ ]
4772
5418
  });
4773
- let h;
5419
+ let f;
4774
5420
  try {
4775
- h = await this.ensureSessionId();
4776
- } catch (g) {
4777
- throw this.rollbackOptimisticMessages(m), g;
5421
+ f = await this.ensureSessionId();
5422
+ } catch (b) {
5423
+ throw this.rollbackOptimisticMessages(v), b;
4778
5424
  }
4779
- return h ? { sessionId: h, userMessage: p, initialMessages: d } : (this.rollbackOptimisticMessages(m), null);
4780
- }, this.buildQueuedUserMessage = (s) => {
5425
+ return f ? { sessionId: f, userMessage: m, initialMessages: g } : (this.rollbackOptimisticMessages(v), null);
5426
+ }, this.buildQueuedUserMessage = (_) => {
5427
+ var m;
5428
+ const p = this.buildUserMessage(_);
5429
+ if (!p) return null;
5430
+ const u = (m = this.sessionCtx.sessionState.get().session) == null ? void 0 : m.id;
5431
+ return u ? { sessionId: u, userMessage: { ...p, pending: !0 } } : null;
5432
+ }, this.buildUserMessage = (_) => {
4781
5433
  var p;
4782
- const r = this.buildUserMessage(s);
4783
- if (!r) return null;
4784
- const c = (p = this.sessionCtx.sessionState.get().session) == null ? void 0 : p.id;
4785
- return c ? { sessionId: c, userMessage: { ...r, pending: !0 } } : null;
4786
- }, this.buildUserMessage = (s) => {
4787
- var r;
4788
- return !s.content.trim() && (!s.attachments || s.attachments.length === 0) ? (u.warn("cannot send an empty message of no content or attachments"), null) : this.toUserMessage(
4789
- s.content.trim(),
4790
- s.attachments || void 0,
4791
- this.sendsPageContext ? z.markedElementNames(s.clientContext) : void 0,
4792
- this.sendsPageContext && ((r = s.mentions) != null && r.length) ? s.mentions : void 0
4793
- );
4794
- }, this.appendUserMessageIfAbsent = (s) => {
4795
- const r = this.state.get().messages;
4796
- r.some((c) => c.id === s.id) || this.state.setPartial({ messages: [...r, s] });
4797
- }, this.markUserMessageDelivered = (s) => {
4798
- const r = this.state.get().messages, c = r.findIndex(
4799
- (m) => m.id === s && m.type === "USER" && m.pending
5434
+ return !_.content.trim() && (!_.attachments || _.attachments.length === 0) ? (k.warn("cannot send an empty message of no content or attachments"), null) : {
5435
+ ...this.toUserMessage(
5436
+ _.content.trim(),
5437
+ _.attachments || void 0,
5438
+ this.sendsPageContext ? C.markedElementNames(_.clientContext) : void 0,
5439
+ this.sendsPageContext && ((p = _.mentions) != null && p.length) ? _.mentions : void 0
5440
+ ),
5441
+ ..._.background ? { background: !0 } : {}
5442
+ };
5443
+ }, this.appendUserMessageIfAbsent = (_) => {
5444
+ if (_.background) return;
5445
+ const p = this.state.get().messages;
5446
+ p.some((u) => u.id === _.id) || this.state.setPartial({ messages: [...p, _] });
5447
+ }, this.markUserMessageDelivered = (_) => {
5448
+ const p = this.state.get().messages, u = p.findIndex(
5449
+ (v) => v.id === _ && v.type === "USER" && v.pending
4800
5450
  );
4801
- if (c === -1) return;
4802
- const p = r[c];
4803
- if (!p || p.type !== "USER") return;
4804
- const d = [...r];
4805
- d[c] = { ...p, pending: !1 }, this.state.setPartial({
4806
- messages: d
5451
+ if (u === -1) return;
5452
+ const m = p[u];
5453
+ if (!m || m.type !== "USER") return;
5454
+ const g = [...p];
5455
+ g[u] = { ...m, pending: !1 }, this.state.setPartial({
5456
+ messages: g
4807
5457
  });
4808
- }, this.sendMessage = async (s) => {
4809
- var c, p, d, m, h;
5458
+ }, this.sendMessage = async (_) => {
5459
+ var u, m, g, v, f;
4810
5460
  if (this.streaming) {
4811
5461
  if (!this.agentHandlers) {
4812
- this.bufferedAgentSends.push(s);
5462
+ this.bufferedAgentSends.push(_);
4813
5463
  return;
4814
5464
  }
4815
- await this.agentHandlers.send(s);
5465
+ await this.agentHandlers.send(_);
4816
5466
  return;
4817
5467
  }
4818
- let r;
5468
+ let p;
4819
5469
  try {
4820
- const g = this.sessionCtx.sessionState.get().session, w = (g == null ? void 0 : g.assignee.kind) === "ai", b = this.state.get().isSendingMessageToAI, f = this.state.get().messages.at(-1);
4821
- if (this.blocksSendWhileAwaitingReply && (b || // If last message is from user, then bot response did not arrive yet
4822
- w && (f == null ? void 0 : f.type) === "USER")) {
4823
- u.warn("cannot send messages while awaiting AI response");
5470
+ const b = this.sessionCtx.sessionState.get().session, R = (b == null ? void 0 : b.assignee.kind) === "ai", X = this.state.get().isSendingMessageToAI, E = this.state.get().messages.at(-1);
5471
+ if (this.blocksSendWhileAwaitingReply && (X || // If last message is from user, then bot response did not arrive yet
5472
+ R && (E == null ? void 0 : E.type) === "USER" && E.id !== this.state.get().settledAgentUserMessageId)) {
5473
+ k.warn("cannot send messages while awaiting AI response");
4824
5474
  return;
4825
5475
  }
4826
- this.sendMessageAbortController.abort("Superseded by a newer message"), this.sendMessageAbortController = new AbortController(), r = this.sendMessageAbortController, this.state.setPartial({
5476
+ this.sendMessageAbortController.abort("Superseded by a newer message"), this.sendMessageAbortController = new AbortController(), p = this.sendMessageAbortController, this.state.setPartial({
4827
5477
  lastAIResMightSolveUserIssue: !1,
4828
5478
  isSendingMessage: !0,
4829
- isSendingMessageToAI: !!w || !g
5479
+ isSendingMessageToAI: !!R || !b
4830
5480
  });
4831
- const I = await this.stageUserTurn(s, { pending: !1 });
4832
- if (!I) return;
4833
- const { sessionId: $, userMessage: D, initialMessages: Z } = I;
4834
- this.notifySendAccepted(s);
4835
- const { data: k } = await this.api.sendMessage(
4836
- za({
5481
+ const K = await this.stageUserTurn(_, { pending: !1 });
5482
+ if (!K) return;
5483
+ const { sessionId: ee, userMessage: L, initialMessages: ae } = K;
5484
+ this.notifySendAccepted(_);
5485
+ const { data: y } = await this.api.sendMessage(
5486
+ Na({
4837
5487
  config: {
4838
- ...this.config,
5488
+ ...this.getRequestConfig(),
4839
5489
  capabilities: this.getClientCapabilities()
4840
5490
  },
4841
- input: s,
4842
- uuid: D.id,
4843
- sessionId: $,
4844
- content: D.content,
4845
- initialMessages: Z,
5491
+ input: _,
5492
+ uuid: L.id,
5493
+ sessionId: ee,
5494
+ content: L.content,
5495
+ initialMessages: ae,
4846
5496
  sendsPageContext: this.sendsPageContext
4847
5497
  }),
4848
- r.signal
5498
+ p.signal
4849
5499
  );
4850
- if (k != null && k.success) {
4851
- const S = this.toBotMessage(k);
4852
- if (S) {
4853
- const q = this.state.get().messages;
4854
- if (!!q.some(
4855
- (J) => J.id === S.id
5500
+ if (y != null && y.success) {
5501
+ const z = this.toBotMessage(y);
5502
+ if (z) {
5503
+ const A = this.state.get().messages;
5504
+ if (!!A.some(
5505
+ (te) => te.id === z.id
4856
5506
  )) {
4857
5507
  this.state.setPartial({
4858
- lastAIResMightSolveUserIssue: ((c = k.autopilotResponse) == null ? void 0 : c.mightSolveUserIssue) || ((p = k.uiResponse) == null ? void 0 : p.mightSolveUserIssue)
5508
+ lastAIResMightSolveUserIssue: ((u = y.autopilotResponse) == null ? void 0 : u.mightSolveUserIssue) || ((m = y.uiResponse) == null ? void 0 : m.mightSolveUserIssue)
4859
5509
  });
4860
5510
  return;
4861
5511
  }
4862
5512
  this.state.setPartial({
4863
- messages: [...q, S],
4864
- lastAIResMightSolveUserIssue: ((d = k.autopilotResponse) == null ? void 0 : d.mightSolveUserIssue) || ((m = k.uiResponse) == null ? void 0 : m.mightSolveUserIssue)
4865
- }), this.dispatchToOnMessageReceivedHook(S);
5513
+ messages: [...A, z],
5514
+ lastAIResMightSolveUserIssue: ((g = y.autopilotResponse) == null ? void 0 : g.mightSolveUserIssue) || ((v = y.uiResponse) == null ? void 0 : v.mightSolveUserIssue)
5515
+ }), this.dispatchToOnMessageReceivedHook(z);
4866
5516
  }
4867
- k.session && this.sessionCtx.sessionState.setPartial({ session: k.session });
5517
+ y.session && this.sessionCtx.sessionState.setPartial({ session: y.session });
4868
5518
  } else {
4869
- const S = this.toBotErrorMessage(
4870
- ((h = k == null ? void 0 : k.error) == null ? void 0 : h.message) || ba(this.config, "turn_failed_message")
4871
- ), q = this.state.get().messages;
5519
+ const z = this.toBotErrorMessage(
5520
+ ((f = y == null ? void 0 : y.error) == null ? void 0 : f.message) || Ea(this.config, "turn_failed_message")
5521
+ ), A = this.state.get().messages;
4872
5522
  this.state.setPartial({
4873
- messages: [...q, S]
5523
+ messages: [...A, z]
4874
5524
  });
4875
5525
  }
4876
- } catch (g) {
4877
- r != null && r.signal.aborted || u.error("failed to send message", g);
5526
+ } catch (b) {
5527
+ p != null && p.signal.aborted || k.error("failed to send message", b);
4878
5528
  } finally {
4879
- r != null && r.signal.aborted || this.state.setPartial({
5529
+ p != null && p.signal.aborted || this.state.setPartial({
4880
5530
  isSendingMessage: !1,
4881
5531
  isSendingMessageToAI: !1
4882
5532
  });
4883
5533
  }
4884
- }, this.toUserMessage = (s, r, c, p) => {
4885
- const d = (() => {
4886
- const m = this.contactCtx.state.get().extraCollectedData;
4887
- return this.state.get().messages.length === 0 && m && Object.keys(m).length > 0 ? `${Object.entries(m).filter(([g, y]) => !!y).map(([g, y]) => `${g}: ${y}`).join(`
5534
+ }, this.toUserMessage = (_, p, u, m) => {
5535
+ const g = (() => {
5536
+ const v = this.contactCtx.state.get().extraCollectedData;
5537
+ return this.state.get().messages.length === 0 && v && Object.keys(v).length > 0 ? `${Object.entries(v).filter(([b, w]) => !!w).map(([b, w]) => `${b}: ${w}`).join(`
4888
5538
  `)}
4889
5539
 
4890
- ${s}` : s;
5540
+ ${_}` : _;
4891
5541
  })();
4892
5542
  return {
4893
5543
  id: x(),
4894
5544
  type: "USER",
4895
- content: d,
4896
- attachments: r,
4897
- markedElements: c,
4898
- mentions: p,
5545
+ content: g,
5546
+ attachments: p,
5547
+ markedElements: u,
5548
+ mentions: m,
4899
5549
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
4900
5550
  };
4901
- }, this.toBotMessage = (s) => {
4902
- var r;
4903
- return s.success && s.autopilotResponse ? {
5551
+ }, this.toBotMessage = (_) => {
5552
+ var p;
5553
+ return _.success && _.autopilotResponse ? {
4904
5554
  type: "AI",
4905
- id: s.autopilotResponse.id || x(),
5555
+ id: _.autopilotResponse.id || x(),
4906
5556
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
4907
5557
  component: "bot_message",
4908
5558
  agent: this.config.bot ? {
@@ -4914,35 +5564,49 @@ ${s}` : s;
4914
5564
  id: null
4915
5565
  } : void 0,
4916
5566
  data: {
4917
- message: s.autopilotResponse.value.content,
4918
- action: (r = s.uiResponse) != null && r.value.name ? {
4919
- name: s.uiResponse.value.name,
4920
- data: s.uiResponse.value.request_response
5567
+ message: _.autopilotResponse.value.content,
5568
+ action: (p = _.uiResponse) != null && p.value.name ? {
5569
+ name: _.uiResponse.value.name,
5570
+ data: _.uiResponse.value.request_response
4921
5571
  } : void 0
4922
5572
  }
4923
5573
  } : null;
4924
- }, this.toBotErrorMessage = (s) => ({
5574
+ }, this.toBotErrorMessage = (_) => ({
4925
5575
  type: "AI",
4926
5576
  id: x(),
4927
5577
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
4928
5578
  component: "bot_message",
4929
5579
  data: {
4930
- message: s,
5580
+ message: _,
4931
5581
  variant: "error",
4932
5582
  action: void 0
4933
5583
  }
4934
- }), this.config = e, this.getClientCapabilities = n ?? (() => this.config.capabilities), this.api = t, this.sessionCtx = o, this.contactCtx = _, this.streaming = l, this.sendsPageContext = a;
5584
+ }), this.config = e, this.getClientCapabilities = a ?? (() => this.getRequestConfig().capabilities), this.api = t, this.sessionCtx = o, this.contactCtx = r, this.isStreaming = c ?? (() => l), this.getRequestConfig = n ?? (() => this.config), this.getSendsPageContext = d ?? (() => s);
5585
+ }
5586
+ /**
5587
+ * Current transport choice. The org or this embed may request polling
5588
+ * independently of the server's agent version.
5589
+ */
5590
+ get streaming() {
5591
+ return this.isStreaming();
5592
+ }
5593
+ get sendsPageContext() {
5594
+ return this.getSendsPageContext();
4935
5595
  }
4936
5596
  /** Hand a send to the streaming engine; its failure can never propagate. */
4937
5597
  static dispatchToEngine(e, t) {
4938
5598
  try {
4939
5599
  Promise.resolve(e.send(t)).catch((o) => {
4940
- u.error("streaming send failed", o);
5600
+ k.error("streaming send failed", o);
4941
5601
  });
4942
5602
  } catch (o) {
4943
- u.error("streaming send failed", o);
5603
+ k.error("streaming send failed", o);
4944
5604
  }
4945
5605
  }
5606
+ get hasPendingAgentWork() {
5607
+ var e, t;
5608
+ return this.bufferedAgentSends.length > 0 || (((t = (e = this.agentHandlers) == null ? void 0 : e.hasPendingWork) == null ? void 0 : t.call(e)) ?? !1);
5609
+ }
4946
5610
  /**
4947
5611
  * Defensive read of `clientContext.page_marks` → the user bubble's context
4948
5612
  * chips: each mark contributes the element it was placed on, the note the
@@ -4953,17 +5617,17 @@ ${s}` : s;
4953
5617
  static markedElementNames(e) {
4954
5618
  const t = e == null ? void 0 : e.page_marks;
4955
5619
  if (!Array.isArray(t)) return;
4956
- const o = t.flatMap((_) => {
4957
- if (typeof _ != "object" || _ === null) return [];
4958
- const l = _.elements, a = Array.isArray(l) ? l[0] : void 0, n = typeof a == "object" && a !== null && "name" in a ? a.name : void 0;
4959
- if (typeof n != "string" || n.length === 0) return [];
4960
- const s = _.note, r = _.snapshotUrl;
5620
+ const o = t.flatMap((r) => {
5621
+ if (typeof r != "object" || r === null) return [];
5622
+ const l = r.elements, s = Array.isArray(l) ? l[0] : void 0, a = typeof s == "object" && s !== null && "name" in s ? s.name : void 0;
5623
+ if (typeof a != "string" || a.length === 0) return [];
5624
+ const n = r.note, c = r.snapshotUrl;
4961
5625
  return [
4962
5626
  {
4963
- name: n,
4964
- ...typeof s == "string" && s.length > 0 ? { note: s } : {},
4965
- ...typeof r == "string" && r.length > 0 ? { snapshotUrl: r } : {},
4966
- mark: _
5627
+ name: a,
5628
+ ...typeof n == "string" && n.length > 0 ? { note: n } : {},
5629
+ ...typeof c == "string" && c.length > 0 ? { snapshotUrl: c } : {},
5630
+ mark: r
4967
5631
  }
4968
5632
  ];
4969
5633
  });
@@ -4977,77 +5641,77 @@ ${s}` : s;
4977
5641
  return !this.streaming && this.config.disableSendingWhenAwaitingAIReply !== !1;
4978
5642
  }
4979
5643
  };
4980
- z.SENT_TEXT_HISTORY_MAX = 50;
4981
- let M = z;
4982
- class xa {
4983
- constructor({
4984
- config: e,
4985
- contactCtx: t,
4986
- sessionCtx: o,
4987
- resetChat: _
4988
- }) {
4989
- var l, a;
4990
- this.restorableSessionId = null, this.didReadStoredSession = !1, this.readStoredSession = () => {
5644
+ C.SENT_TEXT_HISTORY_MAX = 50;
5645
+ let D = C;
5646
+ class Ra {
5647
+ constructor(e) {
5648
+ var t, o;
5649
+ this.widget = e, this.subscriptions = [], this.disposed = !1, this.restorableSessionId = null, this.didReadStoredSession = !1, this.readStoredSession = () => {
4991
5650
  if (!this.shouldRestoreLastSession) {
4992
5651
  this.didReadStoredSession = !0;
4993
5652
  return;
4994
5653
  }
4995
- this.sessionCtx.getLastActiveSessionId().then((n) => {
4996
- this.restorableSessionId = n;
5654
+ this.sessionCtx.getLastActiveSessionId().then((r) => {
5655
+ this.restorableSessionId = r;
4997
5656
  }).finally(() => {
4998
5657
  this.didReadStoredSession = !0, this.routeFromSessions(this.sessionCtx.sessionsState.get());
4999
5658
  });
5000
5659
  }, this.registerRoutingListener = () => {
5001
- this.contactCtx.state.subscribe(({ contact: n }) => {
5002
- var s;
5003
- n != null && n.token && this.state.get().screen === "welcome" && this.state.setPartial({
5004
- screen: (s = this.config.router) != null && s.chatScreenOnly ? "chat" : "sessions"
5005
- });
5006
- }), this.sessionCtx.sessionsState.subscribe(this.routeFromSessions);
5660
+ this.subscriptions.push(
5661
+ this.contactCtx.state.subscribe(({ contact: r }) => {
5662
+ var l;
5663
+ r != null && r.token && this.state.get().screen === "welcome" && this.state.setPartial({
5664
+ screen: (l = this.config.router) != null && l.chatScreenOnly ? "chat" : "sessions"
5665
+ });
5666
+ })
5667
+ ), this.subscriptions.push(
5668
+ this.sessionCtx.sessionsState.subscribe(this.routeFromSessions)
5669
+ );
5007
5670
  }, this.routeFromSessions = ({
5008
- isInitialFetchLoading: n,
5009
- data: s
5671
+ isInitialFetchLoading: r,
5672
+ data: l
5010
5673
  }) => {
5011
- var r, c, p, d, m;
5012
- if (this.didReadStoredSession) {
5013
- if (this.restorableSessionId && !((r = this.sessionCtx.sessionState.get().session) != null && r.id)) {
5014
- const h = s.find(
5015
- (g) => g.id === this.restorableSessionId && g.isOpened
5674
+ var s, a, n, c, d;
5675
+ if (!(this.disposed || !this.didReadStoredSession)) {
5676
+ if (this.restorableSessionId && !((s = this.sessionCtx.sessionState.get().session) != null && s.id)) {
5677
+ const _ = l.find(
5678
+ (p) => p.id === this.restorableSessionId && p.isOpened
5016
5679
  );
5017
- if (h) {
5018
- this.restorableSessionId = null, this.toChatScreen(h.id);
5680
+ if (_) {
5681
+ this.restorableSessionId = null, this.toChatScreen(_.id);
5019
5682
  return;
5020
5683
  }
5021
- if (n) return;
5684
+ if (r) return;
5022
5685
  this.restorableSessionId = null;
5023
5686
  }
5024
- if ((c = this.config.router) != null && c.chatScreenOnly && // Do not route to a chat if we are currently inside one already
5687
+ if ((a = this.config.router) != null && a.chatScreenOnly && // Do not route to a chat if we are currently inside one already
5025
5688
  // This also applies to newly created sessions; the new session will be in `sessionState` before it is refreshed and included in `sessionsState`
5026
- !((p = this.sessionCtx.sessionState.get().session) != null && p.id)) {
5027
- const h = (d = s.find((g) => g.isOpened)) == null ? void 0 : d.id;
5028
- return h ? this.toChatScreen(h) : void 0;
5689
+ !((n = this.sessionCtx.sessionState.get().session) != null && n.id)) {
5690
+ const _ = (c = l.find((p) => p.isOpened)) == null ? void 0 : c.id;
5691
+ return _ ? this.toChatScreen(_) : void 0;
5029
5692
  }
5030
- s.length || ((m = this.config.router) == null ? void 0 : m.goToChatIfNoSessions) !== !1 && !n && this.state.get().screen !== "chat" && this.toChatScreen();
5693
+ l.length || ((d = this.config.router) == null ? void 0 : d.goToChatIfNoSessions) !== !1 && !r && this.state.get().screen !== "chat" && this.toChatScreen();
5031
5694
  }
5695
+ }, this.dispose = () => {
5696
+ this.disposed = !0, this.subscriptions.forEach((r) => r()), this.subscriptions = [], this.navigateConversation = void 0;
5032
5697
  }, this.toSessionsScreen = () => {
5033
- this.resetChat(), this.state.setPartial({ screen: "sessions" });
5034
- }, this.toChatScreen = (n) => {
5035
- var r, c;
5698
+ this.navigateConversation || this.resetChat(), this.state.setPartial({ screen: "sessions" });
5699
+ }, this.toChatScreen = (r) => {
5700
+ var s, a;
5701
+ if (this.navigateConversation) return this.navigateConversation(r);
5036
5702
  this.resetChat();
5037
- let s;
5038
- if (n) {
5039
- if (s = this.sessionCtx.sessionsState.get().data.find((p) => p.id === n), !s) return;
5040
- this.sessionCtx.sessionState.setPartial({ session: s });
5703
+ let l;
5704
+ if (r) {
5705
+ if (l = this.sessionCtx.sessionsState.get().data.find((n) => n.id === r), !l) return;
5706
+ this.sessionCtx.sessionState.setPartial({ session: l });
5041
5707
  }
5042
- this.state.setPartial({ screen: "chat" }), (c = (r = this.config.hooks) == null ? void 0 : r.onNavigateToChat) == null || c.call(r, {
5043
- session: s
5044
- });
5045
- }, this.config = e, this.contactCtx = t, this.sessionCtx = o, this.resetChat = _, this.state = new j({
5046
- screen: this.contactCtx.shouldCollectData() ? "welcome" : (l = this.config.router) != null && l.chatScreenOnly ? "chat" : "sessions"
5047
- }), this.shouldRestoreLastSession = ((a = this.config.router) == null ? void 0 : a.restoreLastSession) ?? !1, this.readStoredSession(), this.registerRoutingListener();
5708
+ return this.state.setPartial({ screen: "chat" }), (a = (s = this.config.hooks) == null ? void 0 : s.onNavigateToChat) == null || a.call(s, { session: l }), this.widget;
5709
+ }, this.config = e.config, this.contactCtx = e.contactCtx, this.sessionCtx = e.sessionCtx, this.resetChat = e.resetChat, this.state = new S({
5710
+ screen: this.contactCtx.shouldCollectData() ? "welcome" : (t = this.config.router) != null && t.chatScreenOnly ? "chat" : "sessions"
5711
+ }), this.shouldRestoreLastSession = ((o = this.config.router) == null ? void 0 : o.restoreLastSession) ?? !1, this.readStoredSession(), this.registerRoutingListener();
5048
5712
  }
5049
5713
  }
5050
- class Ca {
5714
+ class Ka {
5051
5715
  constructor({
5052
5716
  storage: e,
5053
5717
  config: t
@@ -5055,7 +5719,7 @@ class Ca {
5055
5719
  this.KEYS = {
5056
5720
  contactToken: (o) => `opencx-widget:org-token-${o}:contact-token`,
5057
5721
  externalContactId: (o) => `opencx-widget:org-token-${o}:external-contact-id`,
5058
- companionPreference: (o, _) => `opencx-widget:org-token-${o}:companion-${_}`,
5722
+ companionPreference: (o, r) => `opencx-widget:org-token-${o}:companion-${r}`,
5059
5723
  activeSession: (o) => `opencx-widget:org-token-${o}:active-session`
5060
5724
  }, this.setContactToken = async (o) => {
5061
5725
  await this.storage.set(this.KEYS.contactToken(this.config.token), o);
@@ -5068,9 +5732,9 @@ class Ca {
5068
5732
  }, this.setExternalContactId = async (o) => {
5069
5733
  await this.storage.set(this.KEYS.externalContactId(this.config.token), o);
5070
5734
  }, 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) => {
5071
- const _ = await this.storage.get(o);
5072
- if (_ === null) return null;
5073
- const l = Number(_);
5735
+ const r = await this.storage.get(o);
5736
+ if (r === null) return null;
5737
+ const l = Number(r);
5074
5738
  return Number.isFinite(l) ? l : null;
5075
5739
  }, this.getCompanionPillOffsetX = async () => this.getFiniteNumber(this.companionKey("pill-offset-x")), this.setCompanionPillOffsetX = async (o) => {
5076
5740
  Number.isFinite(o) && await this.storage.set(this.companionKey("pill-offset-x"), String(o));
@@ -5094,7 +5758,7 @@ class Ca {
5094
5758
  }, this.storage = e, this.config = t;
5095
5759
  }
5096
5760
  }
5097
- function qa({
5761
+ function La({
5098
5762
  org: i,
5099
5763
  agent: e
5100
5764
  }) {
@@ -5102,6 +5766,7 @@ function qa({
5102
5766
  name: e.name,
5103
5767
  avatarUrl: e.avatar_url,
5104
5768
  streaming: e.streaming,
5769
+ ...e.presentation ? { presentation: e.presentation } : {},
5105
5770
  features: {
5106
5771
  dictation: e.features.dictation,
5107
5772
  attachments: e.features.attachments,
@@ -5120,56 +5785,85 @@ function qa({
5120
5785
  }
5121
5786
  };
5122
5787
  }
5123
- function A(i, e) {
5788
+ function M(i, e) {
5124
5789
  return i && e !== !1;
5125
5790
  }
5126
- function Ea(i, e) {
5791
+ function Fa(i, e) {
5127
5792
  const t = e.features;
5128
5793
  return {
5129
- dictation: A(i.features.dictation, t == null ? void 0 : t.dictation),
5794
+ dictation: M(i.features.dictation, t == null ? void 0 : t.dictation),
5130
5795
  attachments: i.features.attachments,
5131
- pageContext: A(
5796
+ pageContext: M(
5132
5797
  i.features.pageContext,
5133
5798
  t == null ? void 0 : t.pageContext
5134
5799
  ),
5135
- clientTools: A(
5800
+ clientTools: M(
5136
5801
  i.features.clientTools,
5137
5802
  t == null ? void 0 : t.clientTools
5138
5803
  )
5139
5804
  };
5140
5805
  }
5141
- class Pa extends Error {
5806
+ class Oa extends Error {
5142
5807
  constructor(e, t, o) {
5143
5808
  super(t), this.name = "WidgetInitializationError", this.code = e, this.details = o;
5144
5809
  }
5145
5810
  }
5146
- const v = class v {
5811
+ const j = class j {
5147
5812
  constructor({
5148
5813
  config: e,
5149
5814
  storage: t,
5150
5815
  getClientCapabilities: o,
5151
- modes: _,
5152
- org: l,
5153
- agent: a
5816
+ getRequestConfig: r,
5817
+ modes: l,
5818
+ org: s,
5819
+ agent: a,
5820
+ parent: n
5154
5821
  }) {
5155
- if (this.modes = [], this.resetChat = () => {
5156
- this.sessionCtx.reset(), this.messageCtx.reset();
5157
- }, this.reconcileAfterStream = (n) => this.activeSessionPollingCtx.reconcileAfterStream(n), !v.pollingIntervalsSeconds)
5822
+ if (this.modes = [], this.disposed = !1, this.createConversation = () => {
5823
+ const c = new j({
5824
+ config: {
5825
+ ...this.config,
5826
+ router: {
5827
+ ...this.config.router,
5828
+ restoreLastSession: !1,
5829
+ chatScreenOnly: !1,
5830
+ goToChatIfNoSessions: !1
5831
+ }
5832
+ },
5833
+ modes: this.modes,
5834
+ org: this.org,
5835
+ agent: this.agent,
5836
+ parent: this,
5837
+ getRequestConfig: this.getRequestConfig,
5838
+ getClientCapabilities: this.getClientCapabilities
5839
+ });
5840
+ return c.routerCtx.state.setPartial({
5841
+ screen: this.contactCtx.shouldCollectData() ? "welcome" : "chat"
5842
+ }), c;
5843
+ }, this.releaseConversation = () => this.dispose(), this.dispose = ({ clearActiveSession: c = !1 } = {}) => {
5844
+ if (this.disposed) return;
5845
+ this.disposed = !0, this.routerCtx.dispose(), this.activeSessionPollingCtx.dispose();
5846
+ const d = this.sessionCtx.dispose({ clearActiveSession: c });
5847
+ return this.messageCtx.reset(), this.uploadCtx.reset(), this.dictationCtx.stop(), d;
5848
+ }, this.resetChat = () => {
5849
+ this.sessionCtx.reset(), this.messageCtx.reset(), this.uploadCtx.reset();
5850
+ }, this.reconcileAfterStream = (c) => this.activeSessionPollingCtx.reconcileAfterStream(c), !j.pollingIntervalsSeconds)
5158
5851
  throw Error(
5159
5852
  "Widget polling values are not defined, did you call WidgetCtx.initialize()"
5160
5853
  );
5161
- this.config = e, this.org = l, this.agent = a, this.features = Ea(a, e), this.api = new K({ config: e }), this.storageCtx = t ? new Ca({ storage: t, config: e }) : void 0, this.modes = _, this.contactCtx = new oe({
5854
+ this.config = e, this.getRequestConfig = r ?? (() => this.config), this.getClientCapabilities = o, this.org = s, this.agent = a, this.api = (n == null ? void 0 : n.api) ?? new B({ config: e }), this.storageCtx = (n == null ? void 0 : n.storageCtx) ?? (t ? new Ka({ storage: t, config: e }) : void 0), this.modes = l, this.contactCtx = (n == null ? void 0 : n.contactCtx) ?? new ge({
5162
5855
  api: this.api,
5163
5856
  config: this.config,
5164
5857
  storageCtx: this.storageCtx
5165
- }), this.sessionCtx = new fa({
5858
+ }), this.sessionCtx = new Aa({
5166
5859
  config: this.config,
5167
5860
  api: this.api,
5168
5861
  contactCtx: this.contactCtx,
5169
5862
  // Remembers the open conversation so a reload can return to it.
5170
- storageCtx: this.storageCtx,
5171
- sessionsPollingIntervalSeconds: v.pollingIntervalsSeconds.sessions
5172
- }), this.messageCtx = new M({
5863
+ storageCtx: n ? void 0 : this.storageCtx,
5864
+ sharedSessions: n == null ? void 0 : n.sessionCtx.sessionsState,
5865
+ sessionsPollingIntervalSeconds: j.pollingIntervalsSeconds.sessions
5866
+ }), this.messageCtx = new D({
5173
5867
  config: this.config,
5174
5868
  api: this.api,
5175
5869
  sessionCtx: this.sessionCtx,
@@ -5177,69 +5871,79 @@ const v = class v {
5177
5871
  // Streaming orgs send their turns over the AI SDK transport instead of
5178
5872
  // the blocking bot-chat send.
5179
5873
  streaming: this.streaming,
5874
+ isStreaming: () => this.streaming,
5180
5875
  sendsPageContext: this.features.pageContext,
5181
- getClientCapabilities: o
5182
- }), this.csatCtx = new ie({
5876
+ getSendsPageContext: () => this.features.pageContext,
5877
+ getClientCapabilities: o,
5878
+ getRequestConfig: r
5879
+ }), this.uploadCtx = new ke(this.api), this.csatCtx = new be({
5183
5880
  api: this.api,
5184
5881
  sessionCtx: this.sessionCtx,
5185
5882
  messageCtx: this.messageCtx
5186
- }), this.dictationCtx = new qe({
5883
+ }), this.dictationCtx = new Fe({
5187
5884
  api: this.api,
5188
5885
  config: this.config
5189
- }), this.activeSessionPollingCtx = new ne({
5886
+ }), this.activeSessionPollingCtx = new he({
5190
5887
  api: this.api,
5191
5888
  config: this.config,
5192
5889
  sessionCtx: this.sessionCtx,
5193
5890
  messageCtx: this.messageCtx,
5194
- sessionPollingIntervalSeconds: v.pollingIntervalsSeconds.session
5195
- }), this.routerCtx = new xa({
5196
- config: this.config,
5197
- contactCtx: this.contactCtx,
5198
- sessionCtx: this.sessionCtx,
5199
- resetChat: this.resetChat
5200
- });
5891
+ sessionPollingIntervalSeconds: j.pollingIntervalsSeconds.session
5892
+ }), this.routerCtx = new Ra(this);
5893
+ }
5894
+ get streaming() {
5895
+ var e, t;
5896
+ return (e = this.messageCtx) != null && e.hasPendingAgentWork ? !0 : (t = this.messageCtx) != null && t.state.get().isSendingMessage ? !1 : this.agent.streaming && this.getRequestConfig().streaming !== !1;
5201
5897
  }
5202
5898
  /**
5203
- * Whether turns stream (the v5 agent-chat engine) or use the blocking
5204
- * bot-chat send. Decided by the SERVER per org; the single source for every
5205
- * "which engine?" decision in the widget.
5899
+ * The org's features narrowed by this embed's `config.features` — the
5900
+ * answers the UI asks for, resolved against the current options.
5206
5901
  */
5207
- get streaming() {
5208
- return this.agent.streaming;
5902
+ get features() {
5903
+ return Fa(this.agent, this.getRequestConfig());
5209
5904
  }
5210
5905
  };
5211
- v.pollingIntervalsSeconds = null, v.initialize = async ({
5906
+ j.pollingIntervalsSeconds = null, j.initialize = async ({
5212
5907
  config: e,
5213
5908
  storage: t,
5214
- getClientCapabilities: o
5909
+ getClientCapabilities: o,
5910
+ getRequestConfig: r
5215
5911
  }) => {
5216
- var l, a;
5217
- const _ = await new K({
5912
+ var s, a;
5913
+ const l = await new B({
5218
5914
  config: e
5219
5915
  }).getExternalWidgetConfig();
5220
- if (!_.data)
5221
- throw u.error("widget config fetch failed", _.error), new Pa(
5916
+ if (!l.data)
5917
+ throw k.error("widget config fetch failed", l.error), new Oa(
5222
5918
  "config-fetch-failed",
5223
5919
  "Failed to fetch widget config",
5224
- _.error
5920
+ l.error
5225
5921
  );
5226
- return v.pollingIntervalsSeconds = {
5227
- session: ((l = _.data) == null ? void 0 : l.sessionPollingIntervalSeconds) || 10,
5228
- sessions: ((a = _.data) == null ? void 0 : a.sessionsPollingIntervalSeconds) || 60
5229
- }, new v({
5922
+ return j.pollingIntervalsSeconds = {
5923
+ session: ((s = l.data) == null ? void 0 : s.sessionPollingIntervalSeconds) || 10,
5924
+ sessions: ((a = l.data) == null ? void 0 : a.sessionsPollingIntervalSeconds) || 60
5925
+ }, new j({
5230
5926
  config: e,
5231
5927
  storage: t,
5232
5928
  getClientCapabilities: o,
5233
- modes: _.data.modes || [],
5929
+ getRequestConfig: r,
5930
+ modes: l.data.modes || [],
5234
5931
  org: {
5235
- id: _.data.org.id,
5236
- name: _.data.org.name
5932
+ id: l.data.org.id,
5933
+ name: l.data.org.name
5237
5934
  },
5238
- agent: qa(_.data)
5935
+ agent: La(l.data)
5239
5936
  });
5240
5937
  };
5241
- let U = v;
5242
- class La {
5938
+ let W = j;
5939
+ function Ya(i, e) {
5940
+ return i ? {
5941
+ streaming: i.streaming && (e == null ? void 0 : e.streaming) !== !1,
5942
+ toolActivity: i.toolActivity === "hidden" || (e == null ? void 0 : e.toolActivity) === "hidden" ? "hidden" : i.toolActivity === "status" || (e == null ? void 0 : e.toolActivity) === "status" ? "status" : "details",
5943
+ reasoning: i.reasoning && (e == null ? void 0 : e.reasoning) !== !1
5944
+ } : e;
5945
+ }
5946
+ class Qa {
5243
5947
  constructor({ attack: e, release: t }) {
5244
5948
  this.value = 0, this.attack = e, this.release = t;
5245
5949
  }
@@ -5250,53 +5954,56 @@ class La {
5250
5954
  return this.value;
5251
5955
  }
5252
5956
  }
5253
- const P = [
5957
+ const T = [
5254
5958
  "compact",
5255
5959
  "sidebar",
5256
5960
  "fullscreen"
5257
- ], Ta = new Set(
5258
- P
5961
+ ], Ua = new Set(
5962
+ T
5259
5963
  );
5260
- function W(i) {
5261
- return Ta.has(i);
5964
+ function Q(i) {
5965
+ return Ua.has(i);
5262
5966
  }
5263
- function Fa(i) {
5264
- if (!Array.isArray(i)) return P;
5967
+ function Xa(i) {
5968
+ if (!Array.isArray(i)) return T;
5265
5969
  const e = [], t = /* @__PURE__ */ new Set();
5266
5970
  for (const o of i)
5267
- !W(o) || t.has(o) || (t.add(o), e.push(o));
5268
- return e.length > 0 ? e : P;
5971
+ !Q(o) || t.has(o) || (t.add(o), e.push(o));
5972
+ return e.length > 0 ? e : T;
5269
5973
  }
5270
- function Oa(i, e) {
5271
- return W(i) && e.includes(i) ? i : e[0] ?? P[0];
5974
+ function et(i, e) {
5975
+ return Q(i) && e.includes(i) ? i : e[0] ?? T[0];
5272
5976
  }
5273
- function Ua(i, e) {
5977
+ function at(i, e) {
5274
5978
  return i === "left" || i === "right" ? i : e === "rtl" ? "left" : "right";
5275
5979
  }
5276
- function Ba(i) {
5980
+ function tt(i) {
5277
5981
  return i === "docked" ? "docked" : "floating";
5278
5982
  }
5279
5983
  export {
5280
- La as DictationLevelSmoother,
5281
- j as PrimitiveState,
5282
- U as WidgetCtx,
5283
- Pa as WidgetInitializationError,
5284
- za as buildSendMessageBody,
5984
+ pe as ConnectionAttemptUnavailableError,
5985
+ ce as ConnectionRequestExpiredError,
5986
+ Qa as DictationLevelSmoother,
5987
+ S as PrimitiveState,
5988
+ W as WidgetCtx,
5989
+ Oa as WidgetInitializationError,
5990
+ Na as buildSendMessageBody,
5285
5991
  x as genUuid,
5286
- ka as getTranslation,
5287
- Na as isAgentStreamKeepalive,
5288
- se as isExhaustive,
5289
- O as isRecord,
5290
- Ka as isRtlLanguage,
5291
- ua as isSupportedLanguage,
5292
- Ra as isTurnSteeredPart,
5293
- u as log,
5294
- Fa as normalizeCompanionLayouts,
5295
- Oa as resolveCompanionDefaultLayout,
5296
- ja as resolveConfigContext,
5297
- ga as resolveLanguage,
5298
- Ba as resolveSidebarMode,
5299
- Ua as resolveSidebarSide,
5300
- ba as translate
5992
+ qa as getTranslation,
5993
+ Ga as isAgentStreamKeepalive,
5994
+ me as isExhaustive,
5995
+ Z as isRecord,
5996
+ Ja as isRtlLanguage,
5997
+ za as isSupportedLanguage,
5998
+ $a as isTurnSteeredPart,
5999
+ k as log,
6000
+ Xa as normalizeCompanionLayouts,
6001
+ Ya as resolveClientPresentation,
6002
+ et as resolveCompanionDefaultLayout,
6003
+ Ma as resolveConfigContext,
6004
+ xa as resolveLanguage,
6005
+ tt as resolveSidebarMode,
6006
+ at as resolveSidebarSide,
6007
+ Ea as translate
5301
6008
  };
5302
6009
  //# sourceMappingURL=index.js.map