@opencx/widget-core 5.4.2 → 5.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
import se from "lodash.isequal";
|
|
2
2
|
import { z as h } from "zod";
|
|
3
3
|
import oe from "openapi-fetch";
|
|
4
|
-
import { v4 as
|
|
5
|
-
const
|
|
4
|
+
import { v4 as N } from "uuid";
|
|
5
|
+
const O = "[opencx]", b = {
|
|
6
6
|
warn: (i, ...e) => {
|
|
7
|
-
console.warn(`${
|
|
7
|
+
console.warn(`${O} ${i}`, ...e);
|
|
8
8
|
},
|
|
9
9
|
error: (i, ...e) => {
|
|
10
|
-
console.error(`${
|
|
10
|
+
console.error(`${O} ${i}`, ...e);
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
-
class
|
|
13
|
+
class z {
|
|
14
14
|
constructor(e) {
|
|
15
|
-
this.subscribers = /* @__PURE__ */ new Set(), this.get = () => this.state, this.set = (
|
|
16
|
-
se(this.state,
|
|
17
|
-
}, this.setPartial = (
|
|
18
|
-
if (
|
|
19
|
-
const o = { ...this.state, ...
|
|
15
|
+
this.subscribers = /* @__PURE__ */ new Set(), this.get = () => this.state, this.set = (s) => {
|
|
16
|
+
se(this.state, s) || (this.state = s, this.notifySubscribers(s));
|
|
17
|
+
}, this.setPartial = (s) => {
|
|
18
|
+
if (s == null) return;
|
|
19
|
+
const o = { ...this.state, ...s };
|
|
20
20
|
this.set(o);
|
|
21
21
|
}, this.reset = () => {
|
|
22
22
|
this.set(this.initialState);
|
|
23
|
-
}, this.notifySubscribers = (
|
|
23
|
+
}, this.notifySubscribers = (s) => {
|
|
24
24
|
Array.from(this.subscribers).forEach((r) => {
|
|
25
25
|
try {
|
|
26
|
-
r(
|
|
26
|
+
r(s);
|
|
27
27
|
} catch (_) {
|
|
28
|
-
|
|
28
|
+
b.error("state subscriber threw", _);
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
|
-
}, this.subscribe = (
|
|
32
|
-
this.subscribers.delete(
|
|
31
|
+
}, this.subscribe = (s) => (this.subscribers.add(s), () => {
|
|
32
|
+
this.subscribers.delete(s);
|
|
33
33
|
}), this.state = e, this.initialState = e;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -37,56 +37,56 @@ const ne = 5e3;
|
|
|
37
37
|
class ie {
|
|
38
38
|
constructor({
|
|
39
39
|
config: e,
|
|
40
|
-
api:
|
|
40
|
+
api: s,
|
|
41
41
|
sessionsState: o,
|
|
42
42
|
setSessions: r
|
|
43
43
|
}) {
|
|
44
|
-
this.state = new
|
|
44
|
+
this.state = new z({ unreadSessionIds: [], count: 0 }), this.viewingSessionId = null, this.readsInFlight = /* @__PURE__ */ new Set(), this.retryTimer = null, this.lastNotifiedCount = null, this.subscriptions = [], this.disposed = !1, this.reportedSessionIds = /* @__PURE__ */ new Set(), this.dispose = () => {
|
|
45
45
|
this.disposed = !0, this.subscriptions.forEach((_) => _()), this.subscriptions = [], this.viewingSessionId = null, this.retryTimer && clearTimeout(this.retryTimer), this.retryTimer = null;
|
|
46
46
|
}, this.setViewingSessionId = (_) => {
|
|
47
47
|
this.viewingSessionId = _, this.evaluate(this.sessionsState.get().data);
|
|
48
48
|
}, this.evaluate = (_) => {
|
|
49
|
-
const
|
|
49
|
+
const t = [];
|
|
50
50
|
for (const a of _) {
|
|
51
51
|
if (a.id === this.viewingSessionId) {
|
|
52
52
|
(a.unread === !0 || a.unread === !1 && !this.reportedSessionIds.has(a.id)) && this.markViewedSessionRead(a.id);
|
|
53
53
|
continue;
|
|
54
54
|
}
|
|
55
|
-
a.unread === !0 &&
|
|
55
|
+
a.unread === !0 && t.push(a.id);
|
|
56
56
|
}
|
|
57
|
-
this.state.set({ unreadSessionIds:
|
|
57
|
+
this.state.set({ unreadSessionIds: t, count: t.length }), this.notifyCount(t.length);
|
|
58
58
|
}, this.markViewedSessionRead = (_) => {
|
|
59
59
|
if (this.readsInFlight.has(_)) return;
|
|
60
60
|
this.readsInFlight.add(_);
|
|
61
|
-
let
|
|
61
|
+
let t = !1;
|
|
62
62
|
this.api.markSessionRead({ sessionId: _ }).then(({ data: a }) => {
|
|
63
63
|
if (!a || this.disposed) return;
|
|
64
64
|
this.reportedSessionIds.add(_);
|
|
65
65
|
const n = this.sessionsState.get().data.find((c) => c.id === a.id);
|
|
66
|
-
n && re(n, a) ?
|
|
66
|
+
n && re(n, a) ? t = !0 : this.setSessions([a]);
|
|
67
67
|
}).catch((a) => {
|
|
68
|
-
|
|
68
|
+
b.warn("failed to mark the session read", {
|
|
69
69
|
sessionId: _,
|
|
70
70
|
error: a instanceof Error ? a.message : String(a)
|
|
71
71
|
}), this.scheduleRetry();
|
|
72
72
|
}).finally(() => {
|
|
73
|
-
this.readsInFlight.delete(_),
|
|
73
|
+
this.readsInFlight.delete(_), t && !this.disposed && this.evaluate(this.sessionsState.get().data);
|
|
74
74
|
});
|
|
75
75
|
}, this.scheduleRetry = () => {
|
|
76
76
|
this.retryTimer || this.disposed || (this.retryTimer = setTimeout(() => {
|
|
77
77
|
this.retryTimer = null, this.evaluate(this.sessionsState.get().data);
|
|
78
78
|
}, ne));
|
|
79
79
|
}, this.notifyCount = (_) => {
|
|
80
|
-
var
|
|
80
|
+
var t, a;
|
|
81
81
|
if (_ !== this.lastNotifiedCount) {
|
|
82
82
|
this.lastNotifiedCount = _;
|
|
83
83
|
try {
|
|
84
|
-
(a = (
|
|
84
|
+
(a = (t = this.config.hooks) == null ? void 0 : t.onUnreadCountChange) == null || a.call(t, _);
|
|
85
85
|
} catch (n) {
|
|
86
|
-
|
|
86
|
+
b.error("onUnreadCountChange hook failed", n);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
}, this.config = e, this.api =
|
|
89
|
+
}, this.config = e, this.api = s, this.sessionsState = o, this.setSessions = r, this.subscriptions.push(
|
|
90
90
|
o.subscribe(({ data: _ }) => this.evaluate(_))
|
|
91
91
|
);
|
|
92
92
|
}
|
|
@@ -94,16 +94,16 @@ class ie {
|
|
|
94
94
|
function re(i, e) {
|
|
95
95
|
return new Date(i.updatedAt).getTime() > new Date(e.updatedAt).getTime();
|
|
96
96
|
}
|
|
97
|
-
const Ya = (i) => i.type === "data-keepalive",
|
|
97
|
+
const Ya = (i) => i.type === "data-keepalive", Qa = (i) => i.type === "data-turn-steered", F = h.object({ const: h.string(), title: h.string().optional() }), _e = h.object({
|
|
98
98
|
type: h.enum(["string", "number", "integer", "boolean", "array"]),
|
|
99
99
|
title: h.string().optional(),
|
|
100
100
|
description: h.string().optional(),
|
|
101
101
|
default: h.union([h.string(), h.number(), h.boolean(), h.array(h.string())]).optional(),
|
|
102
102
|
enum: h.array(h.string()).optional(),
|
|
103
|
-
oneOf: h.array(
|
|
103
|
+
oneOf: h.array(F).optional(),
|
|
104
104
|
items: h.object({
|
|
105
105
|
enum: h.array(h.string()).optional(),
|
|
106
|
-
anyOf: h.array(
|
|
106
|
+
anyOf: h.array(F).optional()
|
|
107
107
|
}).optional(),
|
|
108
108
|
minItems: h.number().int().nonnegative().optional(),
|
|
109
109
|
maxItems: h.number().int().nonnegative().optional(),
|
|
@@ -136,16 +136,16 @@ const Ya = (i) => i.type === "data-keepalive", Xa = (i) => i.type === "data-turn
|
|
|
136
136
|
toolName: h.string()
|
|
137
137
|
})
|
|
138
138
|
), pe = (i) => {
|
|
139
|
-
|
|
139
|
+
b.error("request failed", i.error);
|
|
140
140
|
}, de = (i) => {
|
|
141
141
|
const e = oe({
|
|
142
142
|
baseUrl: i.baseUrl
|
|
143
|
-
}),
|
|
143
|
+
}), s = {
|
|
144
144
|
onRequest: i.onRequest,
|
|
145
145
|
onResponse: i.onResponse,
|
|
146
146
|
onError: i.onError || pe
|
|
147
147
|
};
|
|
148
|
-
return e.use(
|
|
148
|
+
return e.use(s), e;
|
|
149
149
|
};
|
|
150
150
|
class ue extends Error {
|
|
151
151
|
constructor() {
|
|
@@ -157,51 +157,51 @@ class me extends Error {
|
|
|
157
157
|
super("This connection attempt is no longer available."), this.name = "ConnectionAttemptUnavailableError";
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
-
const he = "/backend/widget/v5/chat/stream", ge = "/backend/widget/v5/chat/{sessionId}/stream",
|
|
161
|
-
class
|
|
160
|
+
const he = "/backend/widget/v5/chat/stream", ge = "/backend/widget/v5/chat/{sessionId}/stream", U = (i, e, s) => `${i.replace(/\/$/, "")}${s ? e.replace("{sessionId}", encodeURIComponent(s)) : e}`;
|
|
161
|
+
class B {
|
|
162
162
|
constructor({ config: e }) {
|
|
163
163
|
var r, _;
|
|
164
|
-
this.userToken = null, this.constructClientOptions = (
|
|
164
|
+
this.userToken = null, this.constructClientOptions = (t) => {
|
|
165
165
|
const a = this.config.apiUrl || "https://api.open.cx", n = {
|
|
166
166
|
"X-Bot-Token": this.config.token,
|
|
167
167
|
"Content-Type": "application/json",
|
|
168
168
|
Accept: "application/json",
|
|
169
|
-
Authorization:
|
|
169
|
+
Authorization: t ? `Bearer ${t}` : void 0
|
|
170
170
|
};
|
|
171
171
|
return { baseUrl: a, headers: n };
|
|
172
172
|
}, this.createOpenAPIClient = ({
|
|
173
|
-
baseUrl:
|
|
173
|
+
baseUrl: t,
|
|
174
174
|
headers: a
|
|
175
175
|
}) => de({
|
|
176
|
-
baseUrl:
|
|
176
|
+
baseUrl: t,
|
|
177
177
|
onRequest: ({ request: n }) => {
|
|
178
178
|
Object.entries(a).forEach(([c, d]) => {
|
|
179
179
|
d && n.headers.set(c, d);
|
|
180
180
|
});
|
|
181
181
|
}
|
|
182
182
|
}), this.listApprovalPreferences = async () => {
|
|
183
|
-
const { baseUrl:
|
|
184
|
-
`${
|
|
183
|
+
const { baseUrl: t, headers: a } = this.getStreamAuthContext(), n = await fetch(
|
|
184
|
+
`${t}/backend/widget/v5/connections/approval-preferences`,
|
|
185
185
|
{ headers: a }
|
|
186
186
|
);
|
|
187
187
|
if (!n.ok) throw new Error("Could not load permissions.");
|
|
188
188
|
return ce.parse(await n.json());
|
|
189
|
-
}, this.revokeApprovalPreference = async (
|
|
189
|
+
}, this.revokeApprovalPreference = async (t, a) => {
|
|
190
190
|
const { baseUrl: n, headers: c } = this.getStreamAuthContext();
|
|
191
191
|
if (!(await fetch(
|
|
192
|
-
`${n}/backend/widget/v5/connections/${encodeURIComponent(
|
|
192
|
+
`${n}/backend/widget/v5/connections/${encodeURIComponent(t)}/approval-preferences/${encodeURIComponent(a)}`,
|
|
193
193
|
{ method: "DELETE", headers: c }
|
|
194
194
|
)).ok) throw new Error("Could not reset permission.");
|
|
195
|
-
}, this.listElicitations = async (
|
|
195
|
+
}, this.listElicitations = async (t, a) => {
|
|
196
196
|
const { baseUrl: n, headers: c } = this.getStreamAuthContext(), d = await fetch(
|
|
197
|
-
`${n}/backend/widget/v5/connections/elicitation/${encodeURIComponent(
|
|
197
|
+
`${n}/backend/widget/v5/connections/elicitation/${encodeURIComponent(t)}`,
|
|
198
198
|
{ headers: c, signal: a }
|
|
199
199
|
);
|
|
200
200
|
if (!d.ok) throw new Error("Could not load the request.");
|
|
201
201
|
return le.parse(await d.json());
|
|
202
|
-
}, this.answerElicitation = async (
|
|
202
|
+
}, this.answerElicitation = async (t, a, n) => {
|
|
203
203
|
const { baseUrl: c, headers: d } = this.getStreamAuthContext(), l = await fetch(
|
|
204
|
-
`${c}/backend/widget/v5/connections/elicitation/${encodeURIComponent(
|
|
204
|
+
`${c}/backend/widget/v5/connections/elicitation/${encodeURIComponent(t)}/${encodeURIComponent(a)}`,
|
|
205
205
|
{
|
|
206
206
|
method: "POST",
|
|
207
207
|
headers: { ...d, "Content-Type": "application/json" },
|
|
@@ -212,19 +212,19 @@ class U {
|
|
|
212
212
|
throw new Error(
|
|
213
213
|
l.status === 400 ? "Check your answers and try again." : "This request has ended. Ask the agent to try again."
|
|
214
214
|
);
|
|
215
|
-
}, this.listConnections = async (
|
|
215
|
+
}, this.listConnections = async (t) => {
|
|
216
216
|
const { data: a, error: n } = await this.client.GET(
|
|
217
217
|
"/backend/widget/v5/connections",
|
|
218
|
-
{ signal:
|
|
218
|
+
{ signal: t }
|
|
219
219
|
);
|
|
220
220
|
if (n || !a)
|
|
221
221
|
throw new Error("Could not load connections. Sign in and try again.");
|
|
222
222
|
return a;
|
|
223
|
-
}, this.startConnection = async (
|
|
223
|
+
}, this.startConnection = async (t, a, n) => {
|
|
224
224
|
const { data: c, error: d, response: l } = await this.client.POST(
|
|
225
225
|
"/backend/widget/v5/connections/{serverId}/start",
|
|
226
226
|
{
|
|
227
|
-
params: { path: { serverId:
|
|
227
|
+
params: { path: { serverId: t } },
|
|
228
228
|
body: { request_id: a },
|
|
229
229
|
signal: n
|
|
230
230
|
}
|
|
@@ -235,11 +235,11 @@ class U {
|
|
|
235
235
|
if (d || !c)
|
|
236
236
|
throw new Error("Could not start this connection. Please try again.");
|
|
237
237
|
return c;
|
|
238
|
-
}, this.getConnectionAttempt = async (
|
|
238
|
+
}, this.getConnectionAttempt = async (t, a, n) => {
|
|
239
239
|
const { data: c, error: d, response: l } = await this.client.GET(
|
|
240
240
|
"/backend/widget/v5/connections/{serverId}/attempts/{attemptId}",
|
|
241
241
|
{
|
|
242
|
-
params: { path: { serverId:
|
|
242
|
+
params: { path: { serverId: t, attemptId: a } },
|
|
243
243
|
signal: n
|
|
244
244
|
}
|
|
245
245
|
);
|
|
@@ -248,51 +248,51 @@ class U {
|
|
|
248
248
|
if (d || !c)
|
|
249
249
|
throw new Error(`Could not check the connection (${l.status}).`);
|
|
250
250
|
return c.status;
|
|
251
|
-
}, this.disconnectConnection = async (
|
|
251
|
+
}, this.disconnectConnection = async (t) => {
|
|
252
252
|
const { error: a } = await this.client.DELETE(
|
|
253
253
|
"/backend/widget/v5/connections/{serverId}",
|
|
254
254
|
{
|
|
255
|
-
params: { path: { serverId:
|
|
255
|
+
params: { path: { serverId: t } }
|
|
256
256
|
}
|
|
257
257
|
);
|
|
258
258
|
if (a) throw new Error("Could not disconnect. Please try again.");
|
|
259
|
-
}, this.setAuthToken = (
|
|
260
|
-
this.userToken =
|
|
261
|
-
const { baseUrl: a, headers: n } = this.constructClientOptions(
|
|
259
|
+
}, this.setAuthToken = (t) => {
|
|
260
|
+
this.userToken = t;
|
|
261
|
+
const { baseUrl: a, headers: n } = this.constructClientOptions(t);
|
|
262
262
|
this.client = this.createOpenAPIClient({ baseUrl: a, headers: n });
|
|
263
263
|
}, this.getStreamAuthContext = () => {
|
|
264
|
-
const { baseUrl:
|
|
264
|
+
const { baseUrl: t, headers: a } = this.constructClientOptions(this.userToken), n = {};
|
|
265
265
|
for (const [c, d] of Object.entries(a))
|
|
266
266
|
typeof d == "string" && (["content-type", "accept"].includes(c.toLowerCase()) || (n[c] = d));
|
|
267
|
-
return { baseUrl:
|
|
267
|
+
return { baseUrl: t, headers: n };
|
|
268
268
|
}, this.getStreamTransportOptions = () => {
|
|
269
|
-
const { baseUrl:
|
|
269
|
+
const { baseUrl: t, headers: a } = this.getStreamAuthContext();
|
|
270
270
|
return {
|
|
271
|
-
api:
|
|
272
|
-
reconnectApi: (n) =>
|
|
271
|
+
api: U(t, he),
|
|
272
|
+
reconnectApi: (n) => U(t, ge, n),
|
|
273
273
|
headers: a
|
|
274
274
|
};
|
|
275
|
-
}, this.stopStream = async (
|
|
275
|
+
}, this.stopStream = async (t) => {
|
|
276
276
|
const { response: a } = await this.client.POST(
|
|
277
277
|
"/backend/widget/v5/chat/{sessionId}/stop",
|
|
278
|
-
{ params: { path: { sessionId:
|
|
278
|
+
{ params: { path: { sessionId: t } } }
|
|
279
279
|
);
|
|
280
280
|
if (!a.ok)
|
|
281
281
|
throw new Error(`Failed to stop stream: ${a.status}`);
|
|
282
|
-
}, this.sendPageReply = async (
|
|
282
|
+
}, this.sendPageReply = async (t, a) => {
|
|
283
283
|
try {
|
|
284
284
|
await this.client.POST("/backend/widget/v5/chat/{sessionId}/page-reply", {
|
|
285
|
-
params: { path: { sessionId:
|
|
285
|
+
params: { path: { sessionId: t } },
|
|
286
286
|
body: a
|
|
287
287
|
});
|
|
288
288
|
} catch {
|
|
289
289
|
}
|
|
290
|
-
}, this.getAgentTurnMessages = async (
|
|
290
|
+
}, this.getAgentTurnMessages = async (t, a) => {
|
|
291
291
|
const { data: n, response: c } = await this.client.GET(
|
|
292
292
|
"/backend/widget/v5/chat/{sessionId}/messages",
|
|
293
293
|
{
|
|
294
294
|
params: {
|
|
295
|
-
path: { sessionId:
|
|
295
|
+
path: { sessionId: t },
|
|
296
296
|
query: {
|
|
297
297
|
toolActivity: a == null ? void 0 : a.toolActivity,
|
|
298
298
|
reasoning: (a == null ? void 0 : a.reasoning) === void 0 ? void 0 : a.reasoning ? "true" : "false"
|
|
@@ -303,13 +303,13 @@ class U {
|
|
|
303
303
|
return n ? {
|
|
304
304
|
...n,
|
|
305
305
|
handled_connection_request_ids: n.handled_connection_request_ids ?? []
|
|
306
|
-
} : (
|
|
306
|
+
} : (b.warn("agent turn messages fetch failed", c.status), null);
|
|
307
307
|
}, this.createDictationSession = async ({
|
|
308
|
-
language:
|
|
308
|
+
language: t
|
|
309
309
|
}) => {
|
|
310
310
|
const { data: a, response: n } = await this.client.POST(
|
|
311
311
|
"/backend/widget/v5/dictation/sessions",
|
|
312
|
-
{ body:
|
|
312
|
+
{ body: t ? { language: t } : {} }
|
|
313
313
|
);
|
|
314
314
|
if (!a)
|
|
315
315
|
throw new Error(`Failed to start dictation: ${n.status}`);
|
|
@@ -318,53 +318,53 @@ class U {
|
|
|
318
318
|
params: {
|
|
319
319
|
header: { "x-bot-token": this.config.token }
|
|
320
320
|
}
|
|
321
|
-
}), this.sendMessage = async (
|
|
322
|
-
body:
|
|
321
|
+
}), this.sendMessage = async (t, a) => await this.client.POST("/backend/widget/v2/chat/send", {
|
|
322
|
+
body: t,
|
|
323
323
|
signal: a
|
|
324
|
-
}), this.createUnverifiedContact = async (
|
|
324
|
+
}), this.createUnverifiedContact = async (t) => await this.client.POST(
|
|
325
325
|
"/backend/widget/v2/contact/create-unverified",
|
|
326
326
|
{
|
|
327
327
|
params: { header: { "x-bot-token": this.config.token } },
|
|
328
|
-
body:
|
|
328
|
+
body: t
|
|
329
329
|
}
|
|
330
|
-
), this.createSession = async (
|
|
331
|
-
body:
|
|
330
|
+
), this.createSession = async (t, a) => await this.client.POST("/backend/widget/v2/create-session", {
|
|
331
|
+
body: t,
|
|
332
332
|
signal: a
|
|
333
333
|
}), this.pollSessionAndHistory = async ({
|
|
334
|
-
sessionId:
|
|
334
|
+
sessionId: t,
|
|
335
335
|
abortSignal: a
|
|
336
336
|
}) => await this.client.GET("/backend/widget/v2/poll/{sessionId}", {
|
|
337
|
-
params: { path: { sessionId:
|
|
337
|
+
params: { path: { sessionId: t } },
|
|
338
338
|
signal: a
|
|
339
339
|
}), this.markSessionRead = async ({
|
|
340
|
-
sessionId:
|
|
340
|
+
sessionId: t,
|
|
341
341
|
abortSignal: a
|
|
342
342
|
}) => await this.client.POST(
|
|
343
343
|
"/backend/widget/v2/session/{sessionId}/read",
|
|
344
344
|
{
|
|
345
|
-
params: { path: { sessionId:
|
|
345
|
+
params: { path: { sessionId: t } },
|
|
346
346
|
signal: a
|
|
347
347
|
}
|
|
348
348
|
), this.getSessions = async ({
|
|
349
|
-
cursor:
|
|
349
|
+
cursor: t,
|
|
350
350
|
filters: a,
|
|
351
351
|
abortSignal: n
|
|
352
352
|
}) => await this.client.GET("/backend/widget/v2/sessions", {
|
|
353
353
|
params: {
|
|
354
354
|
query: {
|
|
355
|
-
offset:
|
|
355
|
+
offset: t,
|
|
356
356
|
filters: JSON.stringify(a)
|
|
357
357
|
}
|
|
358
358
|
},
|
|
359
359
|
signal: n
|
|
360
360
|
}), this.uploadFile = async ({
|
|
361
|
-
file:
|
|
361
|
+
file: t,
|
|
362
362
|
abortSignal: a,
|
|
363
363
|
onProgress: n
|
|
364
364
|
}) => new Promise((c, d) => {
|
|
365
|
-
var
|
|
365
|
+
var y;
|
|
366
366
|
const l = new FormData();
|
|
367
|
-
l.append("file",
|
|
367
|
+
l.append("file", t);
|
|
368
368
|
const p = new XMLHttpRequest();
|
|
369
369
|
if (a && (a.addEventListener("abort", () => {
|
|
370
370
|
p.abort(), d(new DOMException("Aborted", "AbortError"));
|
|
@@ -372,18 +372,18 @@ class U {
|
|
|
372
372
|
d(new DOMException("Aborted", "AbortError"));
|
|
373
373
|
return;
|
|
374
374
|
}
|
|
375
|
-
p.upload.addEventListener("progress", (
|
|
376
|
-
if (
|
|
377
|
-
const
|
|
378
|
-
n(
|
|
375
|
+
p.upload.addEventListener("progress", (f) => {
|
|
376
|
+
if (f.lengthComputable && n) {
|
|
377
|
+
const w = Math.round(f.loaded / f.total * 100);
|
|
378
|
+
n(w);
|
|
379
379
|
}
|
|
380
380
|
}), p.addEventListener("load", () => {
|
|
381
381
|
if (p.status >= 200 && p.status < 300)
|
|
382
382
|
try {
|
|
383
|
-
const
|
|
384
|
-
c(
|
|
385
|
-
} catch (
|
|
386
|
-
d(new Error(`Failed to parse response: ${
|
|
383
|
+
const f = JSON.parse(p.responseText);
|
|
384
|
+
c(f);
|
|
385
|
+
} catch (f) {
|
|
386
|
+
d(new Error(`Failed to parse response: ${f}`));
|
|
387
387
|
}
|
|
388
388
|
else
|
|
389
389
|
d(new Error(`Upload failed with status: ${p.status}`));
|
|
@@ -393,31 +393,31 @@ class U {
|
|
|
393
393
|
d(new Error("Upload timed out"));
|
|
394
394
|
});
|
|
395
395
|
const { baseUrl: u } = this.constructClientOptions(this.userToken), g = `${u}/backend/widget/v2/upload`;
|
|
396
|
-
p.open("POST", g), p.setRequestHeader("X-Bot-Token", this.config.token), this.userToken ?? ((
|
|
397
|
-
}), this.vote = async (
|
|
398
|
-
body:
|
|
396
|
+
p.open("POST", g), p.setRequestHeader("X-Bot-Token", this.config.token), this.userToken ?? ((y = this.config.user) == null ? void 0 : y.token) ? p.setRequestHeader("Authorization", `Bearer ${this.userToken}`) : b.error("user token not set"), p.send(l);
|
|
397
|
+
}), this.vote = async (t) => await this.client.POST("/backend/widget/v2/chat/vote", { body: t }), this.resolveSession = async (t, a) => await this.client.POST("/backend/widget/v2/session/resolve", {
|
|
398
|
+
body: t,
|
|
399
399
|
signal: a
|
|
400
|
-
}), this.createStateCheckpoint = async (
|
|
401
|
-
body:
|
|
402
|
-
}), this.submitCsat = async (
|
|
403
|
-
const { baseUrl:
|
|
400
|
+
}), this.createStateCheckpoint = async (t) => await this.client.POST("/backend/widget/v2/checkpoint", {
|
|
401
|
+
body: t
|
|
402
|
+
}), this.submitCsat = async (t) => await this.client.POST("/backend/widget/v2/submit-csat", { body: t }), this.config = e, this.userToken = ((r = e.user) == null ? void 0 : r.token) || null;
|
|
403
|
+
const { baseUrl: s, headers: o } = this.constructClientOptions(
|
|
404
404
|
(_ = e.user) == null ? void 0 : _.token
|
|
405
405
|
);
|
|
406
|
-
this.client = this.createOpenAPIClient({ baseUrl:
|
|
406
|
+
this.client = this.createOpenAPIClient({ baseUrl: s, headers: o });
|
|
407
407
|
}
|
|
408
408
|
}
|
|
409
409
|
function ke(i, e) {
|
|
410
|
-
|
|
410
|
+
b.error(`missing case for ${i} in ${e}`);
|
|
411
411
|
}
|
|
412
|
-
class
|
|
412
|
+
class $ {
|
|
413
413
|
constructor() {
|
|
414
|
-
this.state = new
|
|
414
|
+
this.state = new z({
|
|
415
415
|
isPolling: !1,
|
|
416
416
|
isError: !1
|
|
417
417
|
}), this.abortController = new AbortController(), this.reset = () => {
|
|
418
418
|
var e;
|
|
419
419
|
this.abortController.abort("Resetting poller"), (e = this.stopPolling) == null || e.call(this), this.stopPolling = null;
|
|
420
|
-
}, this.stopPolling = null, this.startPolling = (e,
|
|
420
|
+
}, this.stopPolling = null, this.startPolling = (e, s) => {
|
|
421
421
|
if (this.stopPolling) return;
|
|
422
422
|
const o = [], r = async () => {
|
|
423
423
|
this.abortController = new AbortController(), this.state.setPartial({ isPolling: !0 });
|
|
@@ -426,11 +426,11 @@ class W {
|
|
|
426
426
|
} catch (_) {
|
|
427
427
|
if (this.abortController.signal.aborted)
|
|
428
428
|
return;
|
|
429
|
-
|
|
429
|
+
b.error("failed to poll", _), this.state.setPartial({ isError: !0 });
|
|
430
430
|
} finally {
|
|
431
431
|
this.state.setPartial({ isPolling: !1 });
|
|
432
432
|
}
|
|
433
|
-
this.abortController.signal.aborted || o.push(setTimeout(r,
|
|
433
|
+
this.abortController.signal.aborted || o.push(setTimeout(r, s));
|
|
434
434
|
};
|
|
435
435
|
r(), this.stopPolling = () => {
|
|
436
436
|
o.forEach(clearTimeout), this.state.reset();
|
|
@@ -438,10 +438,10 @@ class W {
|
|
|
438
438
|
};
|
|
439
439
|
}
|
|
440
440
|
}
|
|
441
|
-
function
|
|
441
|
+
function J(i) {
|
|
442
442
|
try {
|
|
443
443
|
const e = i();
|
|
444
|
-
return e instanceof Promise ? e.then((
|
|
444
|
+
return e instanceof Promise ? e.then((s) => ({ data: s })).catch((s) => ({ error: s })) : { data: e };
|
|
445
445
|
} catch (e) {
|
|
446
446
|
return { error: e };
|
|
447
447
|
}
|
|
@@ -449,124 +449,141 @@ function $(i) {
|
|
|
449
449
|
class be {
|
|
450
450
|
constructor({
|
|
451
451
|
api: e,
|
|
452
|
-
config:
|
|
452
|
+
config: s,
|
|
453
453
|
sessionCtx: o,
|
|
454
454
|
messageCtx: r,
|
|
455
455
|
sessionPollingIntervalSeconds: _
|
|
456
456
|
}) {
|
|
457
|
-
this.poller = new
|
|
457
|
+
this.poller = new $(), this.fetchSessionAndFullHistoryAbortController = new AbortController(), this.reconcileAbortController = new AbortController(), this.subscriptions = [], this.reconcilingSessionId = null, this.seenHistoryIds = /* @__PURE__ */ new Set(), this.removedHistoryIds = /* @__PURE__ */ new Set(), this.protectedUntilSeq = /* @__PURE__ */ new Map(), this.landedPollSessionId = null, this.pollSeq = 0, this.lastAppliedSeq = 0, this.removableAfterSeq = 0, this.registerPolling = () => {
|
|
458
458
|
this.subscriptions.push(
|
|
459
|
-
this.sessionCtx.sessionState.subscribe(({ session:
|
|
460
|
-
|
|
459
|
+
this.sessionCtx.sessionState.subscribe(({ session: t }) => {
|
|
460
|
+
((t == null ? void 0 : t.id) ?? null) !== this.landedPollSessionId && (this.seenHistoryIds = /* @__PURE__ */ new Set(), this.removedHistoryIds = /* @__PURE__ */ new Set(), this.protectedUntilSeq = /* @__PURE__ */ new Map(), this.removableAfterSeq = 0, this.landedPollSessionId = null);
|
|
461
|
+
})
|
|
462
|
+
), this.subscriptions.push(
|
|
463
|
+
this.sessionCtx.sessionState.subscribe(({ session: t }) => {
|
|
464
|
+
t != null && t.id ? this.poller.startPolling(async (a) => {
|
|
461
465
|
this.fetchSessionAndHistory({
|
|
462
|
-
sessionId:
|
|
466
|
+
sessionId: t.id,
|
|
463
467
|
abortSignal: a
|
|
464
468
|
});
|
|
465
469
|
}, this.sessionPollingIntervalSeconds * 1e3) : this.poller.reset();
|
|
466
470
|
})
|
|
467
471
|
), this.subscriptions.push(
|
|
468
|
-
this.sessionCtx.sessionState.subscribe(({ session:
|
|
469
|
-
if (
|
|
472
|
+
this.sessionCtx.sessionState.subscribe(({ session: t }) => {
|
|
473
|
+
if (t != null && t.id && !t.isOpened)
|
|
470
474
|
try {
|
|
471
475
|
this.fetchSessionAndFullHistoryAbortController = new AbortController(), this.fetchSessionAndHistory({
|
|
472
|
-
sessionId:
|
|
476
|
+
sessionId: t.id,
|
|
473
477
|
abortSignal: this.fetchSessionAndFullHistoryAbortController.signal
|
|
474
478
|
});
|
|
475
479
|
} catch (a) {
|
|
476
|
-
this.fetchSessionAndFullHistoryAbortController.signal.aborted ||
|
|
480
|
+
this.fetchSessionAndFullHistoryAbortController.signal.aborted || b.error("failed to fetch session and full history", a);
|
|
477
481
|
}
|
|
478
482
|
else
|
|
479
483
|
this.fetchSessionAndFullHistoryAbortController.abort();
|
|
480
484
|
})
|
|
481
485
|
), this.subscriptions.push(
|
|
482
|
-
this.sessionCtx.sessionState.subscribe(({ session:
|
|
483
|
-
this.reconcilingSessionId !== null && (
|
|
486
|
+
this.sessionCtx.sessionState.subscribe(({ session: t }) => {
|
|
487
|
+
this.reconcilingSessionId !== null && (t == null ? void 0 : t.id) !== this.reconcilingSessionId && this.reconcileAbortController.abort();
|
|
484
488
|
})
|
|
485
489
|
);
|
|
486
490
|
}, this.dispose = () => {
|
|
487
|
-
this.poller.reset(), this.fetchSessionAndFullHistoryAbortController.abort(), this.reconcileAbortController.abort(), this.reconcilingSessionId = null, this.subscriptions.forEach((
|
|
488
|
-
}, this.reconcileAfterStream = async (
|
|
491
|
+
this.poller.reset(), this.fetchSessionAndFullHistoryAbortController.abort(), this.reconcileAbortController.abort(), this.reconcilingSessionId = null, this.subscriptions.forEach((t) => t()), this.subscriptions = [];
|
|
492
|
+
}, this.reconcileAfterStream = async (t) => {
|
|
489
493
|
this.reconcileAbortController.abort(), this.reconcileAbortController = new AbortController();
|
|
490
494
|
const { signal: a } = this.reconcileAbortController;
|
|
491
|
-
this.reconcilingSessionId =
|
|
495
|
+
this.reconcilingSessionId = t;
|
|
492
496
|
try {
|
|
493
|
-
await this.fetchSessionAndHistory({ sessionId:
|
|
497
|
+
await this.fetchSessionAndHistory({ sessionId: t, abortSignal: a });
|
|
494
498
|
} catch (n) {
|
|
495
499
|
if (!a.aborted) throw n;
|
|
496
500
|
} finally {
|
|
497
|
-
this.reconcilingSessionId ===
|
|
501
|
+
this.reconcilingSessionId === t && (this.reconcilingSessionId = null);
|
|
498
502
|
}
|
|
499
503
|
}, this.fetchSessionAndHistory = async ({
|
|
500
|
-
sessionId:
|
|
504
|
+
sessionId: t,
|
|
501
505
|
abortSignal: a
|
|
502
506
|
}) => {
|
|
503
|
-
const n = this.messageCtx.state.get().messages.length === 0;
|
|
507
|
+
const n = this.landedPollSessionId !== t && this.messageCtx.state.get().messages.length === 0;
|
|
504
508
|
n && this.messageCtx.state.setPartial({ isInitialFetchLoading: !0 });
|
|
505
|
-
const { data:
|
|
506
|
-
sessionId:
|
|
509
|
+
const c = ++this.pollSeq, { data: d } = await this.api.pollSessionAndHistory({
|
|
510
|
+
sessionId: t,
|
|
507
511
|
abortSignal: a
|
|
508
512
|
});
|
|
509
|
-
if (
|
|
510
|
-
this.
|
|
511
|
-
|
|
512
|
-
|
|
513
|
+
if (d != null && d.session && (this.sessionCtx.sessionState.setPartial({ session: d.session }), this.sessionCtx.setSessions([d.session])), d != null && d.history) {
|
|
514
|
+
const l = c < this.lastAppliedSeq, p = !l && c > this.removableAfterSeq;
|
|
515
|
+
l || (this.lastAppliedSeq = c), p && (this.removableAfterSeq = this.pollSeq), this.landedPollSessionId = t, d.history.length > 0 && this.reconcileOptionPicks(d.history);
|
|
516
|
+
const u = new Set(d.history.map((k) => k.publicId)), m = p ? Array.from(this.seenHistoryIds).filter((k) => !u.has(k)) : [], g = new Set(
|
|
517
|
+
m.filter((k) => (this.protectedUntilSeq.get(k) ?? 0) < c)
|
|
518
|
+
);
|
|
519
|
+
p ? this.seenHistoryIds = /* @__PURE__ */ new Set([
|
|
520
|
+
...Array.from(u),
|
|
521
|
+
...m.filter((k) => !g.has(k))
|
|
522
|
+
]) : u.forEach((k) => this.seenHistoryIds.add(k)), g.forEach((k) => this.removedHistoryIds.add(k));
|
|
523
|
+
const v = this.messageCtx.state.get().messages, y = d.history.map(this.mapHistoryToMessage).filter((k) => k !== null).filter((k) => !this.removedHistoryIds.has(k.id)).filter(
|
|
524
|
+
(k) => !v.some((M) => M.id === k.id)
|
|
525
|
+
);
|
|
526
|
+
p || y.forEach(
|
|
527
|
+
(k) => this.protectedUntilSeq.set(k.id, this.pollSeq)
|
|
513
528
|
);
|
|
514
|
-
|
|
529
|
+
let f = !1;
|
|
530
|
+
const w = v.flatMap((k) => g.has(k.id) ? [] : "replyTo" in k && k.replyTo && g.has(k.replyTo.id) ? (f = !0, [{ ...k, replyTo: void 0 }]) : [k]);
|
|
531
|
+
if (y.length > 0 || w.length !== v.length || f)
|
|
515
532
|
if (this.messageCtx.state.setPartial({
|
|
516
|
-
messages: [...
|
|
533
|
+
messages: [...w, ...y]
|
|
517
534
|
}), n)
|
|
518
535
|
this.messageCtx.markAsDispatchedToOnMessageReceivedHook(
|
|
519
|
-
|
|
536
|
+
y.map((k) => k.id)
|
|
520
537
|
);
|
|
521
538
|
else
|
|
522
|
-
for (const
|
|
523
|
-
this.messageCtx.dispatchToOnMessageReceivedHook(
|
|
539
|
+
for (const k of y)
|
|
540
|
+
this.messageCtx.dispatchToOnMessageReceivedHook(k);
|
|
524
541
|
}
|
|
525
542
|
this.messageCtx.state.get().isInitialFetchLoading && this.messageCtx.state.setPartial({ isInitialFetchLoading: !1 });
|
|
526
|
-
}, this.reconcileOptionPicks = (
|
|
543
|
+
}, this.reconcileOptionPicks = (t) => {
|
|
527
544
|
var a;
|
|
528
|
-
for (const n of
|
|
545
|
+
for (const n of t) {
|
|
529
546
|
const c = (a = n.messageOptions) == null ? void 0 : a.pickedOptionId;
|
|
530
547
|
c && this.messageCtx.setMessageOptionPick(n.publicId, c);
|
|
531
548
|
}
|
|
532
|
-
}, this.mapHistoryToMessage = (
|
|
549
|
+
}, this.mapHistoryToMessage = (t) => {
|
|
533
550
|
var n;
|
|
534
551
|
const a = {
|
|
535
|
-
id:
|
|
536
|
-
timestamp:
|
|
537
|
-
attachments:
|
|
552
|
+
id: t.publicId,
|
|
553
|
+
timestamp: t.sentAt || "",
|
|
554
|
+
attachments: t.attachments || void 0
|
|
538
555
|
};
|
|
539
|
-
if (
|
|
556
|
+
if (t.sender.kind === "user")
|
|
540
557
|
return {
|
|
541
558
|
...a,
|
|
542
559
|
type: "USER",
|
|
543
560
|
deliveredAt: a.timestamp,
|
|
544
|
-
content:
|
|
561
|
+
content: t.content.text || "",
|
|
545
562
|
// Backend field name (schema.ts) → widget vocabulary.
|
|
546
|
-
markedElements:
|
|
563
|
+
markedElements: t.pickedElements
|
|
547
564
|
};
|
|
548
|
-
if (
|
|
565
|
+
if (t.sender.kind === "agent")
|
|
549
566
|
return {
|
|
550
567
|
...a,
|
|
551
568
|
type: "AGENT",
|
|
552
569
|
component: "agent_message",
|
|
553
570
|
data: {
|
|
554
|
-
message:
|
|
571
|
+
message: t.content.text || ""
|
|
555
572
|
},
|
|
556
573
|
agent: {
|
|
557
|
-
name:
|
|
574
|
+
name: t.sender.name || "",
|
|
558
575
|
// Do not set avatarUrl from config here... let it be taken from the config at render time
|
|
559
576
|
// Only set avatar url from the backend's response
|
|
560
|
-
avatarUrl:
|
|
561
|
-
avatar:
|
|
577
|
+
avatarUrl: t.sender.avatar || null,
|
|
578
|
+
avatar: t.sender.avatar || null,
|
|
562
579
|
id: null,
|
|
563
580
|
isAi: !1
|
|
564
581
|
},
|
|
565
|
-
...this.constructReplyTo(
|
|
566
|
-
...
|
|
582
|
+
...this.constructReplyTo(t),
|
|
583
|
+
...t.messageOptions ? { messageOptions: t.messageOptions } : {}
|
|
567
584
|
};
|
|
568
|
-
if (
|
|
569
|
-
const c =
|
|
585
|
+
if (t.sender.kind === "ai") {
|
|
586
|
+
const c = t.actionCalls && t.actionCalls.length > 0 ? t.actionCalls[t.actionCalls.length - 1] : void 0;
|
|
570
587
|
return {
|
|
571
588
|
...a,
|
|
572
589
|
type: "AI",
|
|
@@ -580,23 +597,23 @@ class be {
|
|
|
580
597
|
avatar: null
|
|
581
598
|
},
|
|
582
599
|
data: {
|
|
583
|
-
message:
|
|
600
|
+
message: t.content.text || "",
|
|
584
601
|
action: c ? {
|
|
585
602
|
name: c.actionName,
|
|
586
603
|
data: this.extractActionResult(c)
|
|
587
604
|
} : void 0
|
|
588
605
|
},
|
|
589
|
-
...this.constructReplyTo(
|
|
606
|
+
...this.constructReplyTo(t)
|
|
590
607
|
};
|
|
591
608
|
}
|
|
592
|
-
if (
|
|
593
|
-
const c = this.constructSystemMessage(
|
|
609
|
+
if (t.sender.kind === "system") {
|
|
610
|
+
const c = this.constructSystemMessage(t);
|
|
594
611
|
return c === null ? null : { ...c };
|
|
595
612
|
}
|
|
596
613
|
return null;
|
|
597
|
-
}, this.constructReplyTo = (
|
|
598
|
-
if (!
|
|
599
|
-
const { publicId: a, text: n, sender: c } =
|
|
614
|
+
}, this.constructReplyTo = (t) => {
|
|
615
|
+
if (!t.replyTo) return {};
|
|
616
|
+
const { publicId: a, text: n, sender: c } = t.replyTo;
|
|
600
617
|
return {
|
|
601
618
|
replyTo: {
|
|
602
619
|
id: a,
|
|
@@ -604,64 +621,64 @@ class be {
|
|
|
604
621
|
sender: c
|
|
605
622
|
}
|
|
606
623
|
};
|
|
607
|
-
}, this.constructSystemMessage = (
|
|
608
|
-
if (!
|
|
609
|
-
switch (
|
|
624
|
+
}, this.constructSystemMessage = (t) => {
|
|
625
|
+
if (!t || !t.systemMessagePayload) return null;
|
|
626
|
+
switch (t.systemMessagePayload.type) {
|
|
610
627
|
case "state_checkpoint":
|
|
611
628
|
return {
|
|
612
|
-
id:
|
|
629
|
+
id: t.publicId,
|
|
613
630
|
type: "SYSTEM",
|
|
614
631
|
subtype: "state_checkpoint",
|
|
615
|
-
data: { payload:
|
|
616
|
-
timestamp:
|
|
632
|
+
data: { payload: t.systemMessagePayload.payload },
|
|
633
|
+
timestamp: t.sentAt || "",
|
|
617
634
|
attachments: void 0
|
|
618
635
|
};
|
|
619
636
|
case "csat_requested":
|
|
620
637
|
return {
|
|
621
|
-
id:
|
|
638
|
+
id: t.publicId,
|
|
622
639
|
type: "SYSTEM",
|
|
623
640
|
subtype: "csat_requested",
|
|
624
641
|
data: { payload: void 0 },
|
|
625
|
-
timestamp:
|
|
642
|
+
timestamp: t.sentAt || "",
|
|
626
643
|
attachments: void 0
|
|
627
644
|
};
|
|
628
645
|
case "csat_submitted":
|
|
629
646
|
return {
|
|
630
|
-
id:
|
|
647
|
+
id: t.publicId,
|
|
631
648
|
type: "SYSTEM",
|
|
632
649
|
subtype: "csat_submitted",
|
|
633
650
|
data: {
|
|
634
651
|
payload: {
|
|
635
|
-
score:
|
|
636
|
-
feedback:
|
|
652
|
+
score: t.systemMessagePayload.payload.score ?? void 0,
|
|
653
|
+
feedback: t.systemMessagePayload.payload.feedback ?? void 0
|
|
637
654
|
}
|
|
638
655
|
},
|
|
639
|
-
timestamp:
|
|
656
|
+
timestamp: t.sentAt || "",
|
|
640
657
|
attachments: void 0
|
|
641
658
|
};
|
|
642
659
|
case "none":
|
|
643
660
|
return null;
|
|
644
661
|
default:
|
|
645
662
|
return ke(
|
|
646
|
-
|
|
663
|
+
t.systemMessagePayload,
|
|
647
664
|
this.constructSystemMessage.name
|
|
648
665
|
), null;
|
|
649
666
|
}
|
|
650
|
-
}, this.extractActionResult = (
|
|
651
|
-
const a =
|
|
667
|
+
}, this.extractActionResult = (t) => {
|
|
668
|
+
const a = t.result;
|
|
652
669
|
if (a === null || typeof a != "object") return a;
|
|
653
670
|
if ("responseBodyText" in a && typeof a.responseBodyText == "string") {
|
|
654
|
-
const n = a.responseBodyText, c =
|
|
671
|
+
const n = a.responseBodyText, c = J(() => JSON.parse(n)).data;
|
|
655
672
|
if (c) return c;
|
|
656
673
|
}
|
|
657
|
-
return
|
|
658
|
-
}, this.api = e, this.config =
|
|
674
|
+
return t.result;
|
|
675
|
+
}, this.api = e, this.config = s, this.sessionCtx = o, this.messageCtx = r, this.sessionPollingIntervalSeconds = _, this.registerPolling();
|
|
659
676
|
}
|
|
660
677
|
}
|
|
661
678
|
class ve {
|
|
662
679
|
constructor({
|
|
663
680
|
config: e,
|
|
664
|
-
api:
|
|
681
|
+
api: s,
|
|
665
682
|
storageCtx: o
|
|
666
683
|
}) {
|
|
667
684
|
var r;
|
|
@@ -669,30 +686,30 @@ class ve {
|
|
|
669
686
|
var _;
|
|
670
687
|
return !!(!((_ = this.state.get().contact) != null && _.token) && this.config.collectUserData);
|
|
671
688
|
}, this.autoCreateUnverifiedUserIfNotExists = async () => {
|
|
672
|
-
var _,
|
|
689
|
+
var _, t, a, n, c, d, l, p, u, m, g, v, y, f;
|
|
673
690
|
if (!((_ = this.config.user) != null && _.token)) {
|
|
674
|
-
if (this.config.collectUserData && !((a = (
|
|
691
|
+
if (this.config.collectUserData && !((a = (t = this.config.user) == null ? void 0 : t.data) != null && a.email)) {
|
|
675
692
|
if ((n = this.config.extraDataCollectionFields) != null && n.length)
|
|
676
693
|
return;
|
|
677
|
-
const
|
|
678
|
-
|
|
694
|
+
const w = await ((c = this.storageCtx) == null ? void 0 : c.getContactToken());
|
|
695
|
+
w && await this.setUnverifiedContact(w);
|
|
679
696
|
return;
|
|
680
697
|
}
|
|
681
698
|
if (!((l = (d = this.config.user) == null ? void 0 : d.data) != null && l.email)) {
|
|
682
|
-
const
|
|
683
|
-
if (
|
|
684
|
-
await this.setUnverifiedContact(
|
|
699
|
+
const w = await ((p = this.storageCtx) == null ? void 0 : p.getContactToken());
|
|
700
|
+
if (w) {
|
|
701
|
+
await this.setUnverifiedContact(w);
|
|
685
702
|
return;
|
|
686
703
|
}
|
|
687
704
|
}
|
|
688
705
|
await this.createUnverifiedContact({
|
|
689
706
|
email: (m = (u = this.config.user) == null ? void 0 : u.data) == null ? void 0 : m.email,
|
|
690
|
-
non_verified_name: (
|
|
691
|
-
non_verified_custom_data: (
|
|
707
|
+
non_verified_name: (v = (g = this.config.user) == null ? void 0 : g.data) == null ? void 0 : v.name,
|
|
708
|
+
non_verified_custom_data: (f = (y = this.config.user) == null ? void 0 : y.data) == null ? void 0 : f.customData
|
|
692
709
|
});
|
|
693
710
|
}
|
|
694
|
-
}, this.createUnverifiedContact = async (_,
|
|
695
|
-
this.state.setPartial({ extraCollectedData:
|
|
711
|
+
}, this.createUnverifiedContact = async (_, t) => {
|
|
712
|
+
this.state.setPartial({ extraCollectedData: t });
|
|
696
713
|
try {
|
|
697
714
|
this.state.setPartial({
|
|
698
715
|
isCreatingUnverifiedContact: !0,
|
|
@@ -701,20 +718,20 @@ class ve {
|
|
|
701
718
|
const { data: a } = await this.api.createUnverifiedContact(_);
|
|
702
719
|
a != null && a.token ? await this.setUnverifiedContact(a.token) : this.state.setPartial({ isErrorCreatingUnverifiedContact: !0 });
|
|
703
720
|
} catch (a) {
|
|
704
|
-
this.state.setPartial({ isErrorCreatingUnverifiedContact: !0 }),
|
|
721
|
+
this.state.setPartial({ isErrorCreatingUnverifiedContact: !0 }), b.error("failed to create an unverified contact", {
|
|
705
722
|
_e: a instanceof Error ? a.message : String(a)
|
|
706
723
|
});
|
|
707
724
|
} finally {
|
|
708
725
|
this.state.setPartial({ isCreatingUnverifiedContact: !1 });
|
|
709
726
|
}
|
|
710
727
|
}, this.recoverFromStaleToken = async () => {
|
|
711
|
-
var _,
|
|
728
|
+
var _, t, a, n, c, d, l, p, u, m;
|
|
712
729
|
if ((_ = this.config.user) != null && _.token) return !1;
|
|
713
730
|
this.api.setAuthToken(""), this.state.setPartial({ contact: null });
|
|
714
731
|
try {
|
|
715
|
-
await ((
|
|
732
|
+
await ((t = this.storageCtx) == null ? void 0 : t.clearContactToken()), await ((a = this.storageCtx) == null ? void 0 : a.clearActiveSessionId());
|
|
716
733
|
} catch (g) {
|
|
717
|
-
|
|
734
|
+
b.warn("failed to clear a stale contact token", {
|
|
718
735
|
error: g instanceof Error ? g.message : String(g)
|
|
719
736
|
});
|
|
720
737
|
}
|
|
@@ -725,9 +742,9 @@ class ve {
|
|
|
725
742
|
}), !!((m = this.state.get().contact) != null && m.token);
|
|
726
743
|
}, this.setUnverifiedContact = async (_) => {
|
|
727
744
|
var n, c, d, l;
|
|
728
|
-
const
|
|
745
|
+
const t = await ((n = this.storageCtx) == null ? void 0 : n.getExternalContactId()), a = ((c = this.config.user) == null ? void 0 : c.externalId) || t || N();
|
|
729
746
|
this.api.setAuthToken(_), await ((d = this.storageCtx) == null ? void 0 : d.setContactToken(_)), await ((l = this.storageCtx) == null ? void 0 : l.setExternalContactId(a)), this.state.setPartial({ contact: { token: _, externalId: a } });
|
|
730
|
-
}, this.config = e, this.storageCtx = o, this.api =
|
|
747
|
+
}, this.config = e, this.storageCtx = o, this.api = s, this.state = new z({
|
|
731
748
|
contact: (r = e.user) != null && r.token ? {
|
|
732
749
|
token: e.user.token,
|
|
733
750
|
// Set optional externalId from config... not local storage
|
|
@@ -741,35 +758,35 @@ class ve {
|
|
|
741
758
|
}
|
|
742
759
|
class fe {
|
|
743
760
|
constructor(e) {
|
|
744
|
-
this.api = e, this.state = new
|
|
745
|
-
const o =
|
|
761
|
+
this.api = e, this.state = new z([]), this.controllers = /* @__PURE__ */ new Map(), this.appendFiles = (s) => {
|
|
762
|
+
const o = s.map(
|
|
746
763
|
(r) => ({
|
|
747
764
|
file: r,
|
|
748
|
-
id:
|
|
765
|
+
id: N(),
|
|
749
766
|
status: "pending",
|
|
750
767
|
progress: 0
|
|
751
768
|
})
|
|
752
769
|
);
|
|
753
770
|
this.state.set([...this.state.get(), ...o]), o.forEach((r) => void this.upload(r));
|
|
754
|
-
}, this.cancel = (
|
|
771
|
+
}, this.cancel = (s) => {
|
|
755
772
|
var o;
|
|
756
|
-
(o = this.controllers.get(
|
|
773
|
+
(o = this.controllers.get(s)) == null || o.abort(), this.controllers.delete(s), this.state.set(this.state.get().filter((r) => r.id !== s));
|
|
757
774
|
}, this.reset = () => {
|
|
758
|
-
this.controllers.forEach((
|
|
775
|
+
this.controllers.forEach((s) => s.abort()), this.controllers.clear(), this.state.reset();
|
|
759
776
|
};
|
|
760
777
|
}
|
|
761
|
-
update(e,
|
|
778
|
+
update(e, s) {
|
|
762
779
|
this.state.set(
|
|
763
|
-
this.state.get().map((o) => o.id === e ? { ...o, ...
|
|
780
|
+
this.state.get().map((o) => o.id === e ? { ...o, ...s } : o)
|
|
764
781
|
);
|
|
765
782
|
}
|
|
766
783
|
async upload(e) {
|
|
767
|
-
const
|
|
768
|
-
this.controllers.set(e.id,
|
|
784
|
+
const s = new AbortController();
|
|
785
|
+
this.controllers.set(e.id, s), this.update(e.id, { status: "uploading" });
|
|
769
786
|
try {
|
|
770
787
|
const o = await this.api.uploadFile({
|
|
771
788
|
file: e.file,
|
|
772
|
-
abortSignal:
|
|
789
|
+
abortSignal: s.signal,
|
|
773
790
|
onProgress: (r) => this.update(e.id, { progress: r })
|
|
774
791
|
});
|
|
775
792
|
this.update(e.id, {
|
|
@@ -778,7 +795,7 @@ class fe {
|
|
|
778
795
|
progress: 100
|
|
779
796
|
});
|
|
780
797
|
} catch (o) {
|
|
781
|
-
|
|
798
|
+
s.signal.aborted || this.update(e.id, {
|
|
782
799
|
status: "error",
|
|
783
800
|
progress: 0,
|
|
784
801
|
error: o instanceof Error ? o.message : "Upload failed"
|
|
@@ -789,12 +806,12 @@ class fe {
|
|
|
789
806
|
}
|
|
790
807
|
}
|
|
791
808
|
function q() {
|
|
792
|
-
return
|
|
809
|
+
return N();
|
|
793
810
|
}
|
|
794
811
|
class ye {
|
|
795
812
|
constructor({
|
|
796
813
|
api: e,
|
|
797
|
-
sessionCtx:
|
|
814
|
+
sessionCtx: s,
|
|
798
815
|
messageCtx: o
|
|
799
816
|
}) {
|
|
800
817
|
this.submitCsat = async (r) => {
|
|
@@ -802,12 +819,12 @@ class ye {
|
|
|
802
819
|
const _ = (c = this.sessionCtx.sessionState.get().session) == null ? void 0 : c.id;
|
|
803
820
|
if (!_)
|
|
804
821
|
return { data: null, error: "No session id found" };
|
|
805
|
-
const
|
|
822
|
+
const t = q();
|
|
806
823
|
this.messageCtx.state.setPartial({
|
|
807
824
|
messages: [
|
|
808
825
|
...this.messageCtx.state.get().messages,
|
|
809
826
|
{
|
|
810
|
-
id:
|
|
827
|
+
id: t,
|
|
811
828
|
type: "SYSTEM",
|
|
812
829
|
subtype: "csat_submitted",
|
|
813
830
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -822,11 +839,11 @@ class ye {
|
|
|
822
839
|
});
|
|
823
840
|
const { data: a, error: n } = await this.api.submitCsat({
|
|
824
841
|
...r,
|
|
825
|
-
system_message_uuid:
|
|
842
|
+
system_message_uuid: t,
|
|
826
843
|
session_id: _
|
|
827
844
|
});
|
|
828
845
|
return { data: a, error: n };
|
|
829
|
-
}, this.api = e, this.sessionCtx =
|
|
846
|
+
}, this.api = e, this.sessionCtx = s, this.messageCtx = o;
|
|
830
847
|
}
|
|
831
848
|
}
|
|
832
849
|
const we = [
|
|
@@ -921,16 +938,16 @@ function ze(i) {
|
|
|
921
938
|
function Ce(i) {
|
|
922
939
|
const e = we.flatMap(
|
|
923
940
|
(r) => i.flatMap(
|
|
924
|
-
(_) => r.phrases[_].map((
|
|
941
|
+
(_) => r.phrases[_].map((t) => ({ phrase: t, action: r.action }))
|
|
925
942
|
)
|
|
926
|
-
),
|
|
943
|
+
), s = e.map((r) => ze(r.phrase)).sort((r, _) => _.length - r.length).join("|"), o = String.raw`(?<=^\s{0,3}|[.!?\n]\s{0,3})`;
|
|
927
944
|
return {
|
|
928
945
|
regex: new RegExp(
|
|
929
|
-
`${o}(${
|
|
946
|
+
`${o}(${s})` + String.raw`([.,!?;:])(?=\s|$)`,
|
|
930
947
|
"giu"
|
|
931
948
|
),
|
|
932
949
|
finalRegex: new RegExp(
|
|
933
|
-
`${o}(${
|
|
950
|
+
`${o}(${s})` + String.raw`([.,!?;:]?)(?=\s|$)`,
|
|
934
951
|
"giu"
|
|
935
952
|
),
|
|
936
953
|
phraseToAction: new Map(
|
|
@@ -939,51 +956,51 @@ function Ce(i) {
|
|
|
939
956
|
longestPhrase: Math.max(...e.map((r) => r.phrase.length))
|
|
940
957
|
};
|
|
941
958
|
}
|
|
942
|
-
const
|
|
943
|
-
function
|
|
944
|
-
const e = i && Se(i) && i !== "en" ? i : null,
|
|
945
|
-
let o =
|
|
946
|
-
return o || (o = Ce(e ? ["en", e] : ["en"]),
|
|
959
|
+
const H = /* @__PURE__ */ new Map();
|
|
960
|
+
function D(i) {
|
|
961
|
+
const e = i && Se(i) && i !== "en" ? i : null, s = e ?? "en";
|
|
962
|
+
let o = H.get(s);
|
|
963
|
+
return o || (o = Ce(e ? ["en", e] : ["en"]), H.set(s, o)), o;
|
|
947
964
|
}
|
|
948
965
|
function xe(i) {
|
|
949
966
|
const e = i.replace(/\s+$/, "");
|
|
950
967
|
if (!e) return "";
|
|
951
|
-
const
|
|
968
|
+
const s = e.replace(/[.!?]+$/, "");
|
|
952
969
|
let o = -1;
|
|
953
|
-
for (let r =
|
|
954
|
-
const _ =
|
|
970
|
+
for (let r = s.length - 1; r >= 0; r--) {
|
|
971
|
+
const _ = s[r];
|
|
955
972
|
if (_ === "." || _ === "!" || _ === "?" || _ === `
|
|
956
973
|
`) {
|
|
957
974
|
o = r + 1;
|
|
958
975
|
break;
|
|
959
976
|
}
|
|
960
977
|
}
|
|
961
|
-
return o === -1 ? "" : `${
|
|
978
|
+
return o === -1 ? "" : `${s.slice(0, o)} `.replace(/\n $/, `
|
|
962
979
|
`);
|
|
963
980
|
}
|
|
964
981
|
const qe = new RegExp(
|
|
965
982
|
String.raw`(^- |\n(?:- )?)(\p{Ll})`,
|
|
966
983
|
"gu"
|
|
967
984
|
);
|
|
968
|
-
function
|
|
985
|
+
function Ae(i) {
|
|
969
986
|
return i.replace(
|
|
970
987
|
qe,
|
|
971
|
-
(e,
|
|
988
|
+
(e, s, o) => s + o.toUpperCase()
|
|
972
989
|
);
|
|
973
990
|
}
|
|
974
|
-
function
|
|
991
|
+
function Ee(i) {
|
|
975
992
|
return i.length <= 3 && /^\s*$/.test(i) ? !0 : /[.!?\n]\s{0,3}$/.test(i.slice(-6));
|
|
976
993
|
}
|
|
977
|
-
class
|
|
994
|
+
class A {
|
|
978
995
|
/**
|
|
979
996
|
* Process the full raw transcript accumulated so far into insertable text.
|
|
980
997
|
* Pure and deterministic: always called with the entire raw string so the
|
|
981
998
|
* result never depends on delta chunking.
|
|
982
999
|
*/
|
|
983
|
-
static process(e,
|
|
984
|
-
const o =
|
|
1000
|
+
static process(e, s) {
|
|
1001
|
+
const o = D(s == null ? void 0 : s.language), r = s != null && s.final ? "" : A.commandPrefixTail(e, s == null ? void 0 : s.language), _ = e.slice(0, e.length - r.length), t = s != null && s.final ? o.finalRegex : o.regex;
|
|
985
1002
|
let a = "", n = null, c = 0;
|
|
986
|
-
for (const l of Array.from(_.matchAll(
|
|
1003
|
+
for (const l of Array.from(_.matchAll(t))) {
|
|
987
1004
|
const [, p = ""] = l, u = o.phraseToAction.get(p.toLowerCase());
|
|
988
1005
|
if (u)
|
|
989
1006
|
if (a += _.slice(c, l.index), c = l.index + l[0].length, u === "newline") a = `${a.replace(/[ \t]+$/, "")}
|
|
@@ -1003,7 +1020,7 @@ class E {
|
|
|
1003
1020
|
break;
|
|
1004
1021
|
}
|
|
1005
1022
|
}
|
|
1006
|
-
return n === null && (a += _.slice(c)), { text:
|
|
1023
|
+
return n === null && (a += _.slice(c)), { text: Ae(
|
|
1007
1024
|
a.replace(/^\s+/, "").replace(/[ \t]+\n/g, `
|
|
1008
1025
|
`).replace(/\n[ \t]+/g, `
|
|
1009
1026
|
`).replace(/(^|\n)- +/g, "$1- ").replace(/ {2,}/g, " ").replace(/\n{3,}/g, `
|
|
@@ -1020,16 +1037,16 @@ class E {
|
|
|
1020
1037
|
* control command from an intermediate delta would stop or submit
|
|
1021
1038
|
* mid-sentence.
|
|
1022
1039
|
*/
|
|
1023
|
-
static commandPrefixTail(e,
|
|
1024
|
-
const o =
|
|
1040
|
+
static commandPrefixTail(e, s) {
|
|
1041
|
+
const o = D(s), r = Math.min(e.length, o.longestPhrase + 2);
|
|
1025
1042
|
for (let _ = r; _ > 0; _--) {
|
|
1026
|
-
const
|
|
1027
|
-
if (!
|
|
1028
|
-
const a = e.slice(
|
|
1043
|
+
const t = e.length - _;
|
|
1044
|
+
if (!Ee(e.slice(0, t))) continue;
|
|
1045
|
+
const a = e.slice(t).toLowerCase(), n = a.replace(/^\s+/, "");
|
|
1029
1046
|
if (n) {
|
|
1030
1047
|
for (const c of Array.from(o.phraseToAction.keys()))
|
|
1031
1048
|
if (c.startsWith(n))
|
|
1032
|
-
return e.slice(
|
|
1049
|
+
return e.slice(t + (a.length - n.length));
|
|
1033
1050
|
}
|
|
1034
1051
|
}
|
|
1035
1052
|
return "";
|
|
@@ -1039,9 +1056,9 @@ class E {
|
|
|
1039
1056
|
* prefix) — i.e. a silence pause would resolve it into a command. Used by
|
|
1040
1057
|
* the manager's silence timer.
|
|
1041
1058
|
*/
|
|
1042
|
-
static pendingTailIsCompletePhrase(e,
|
|
1043
|
-
const o =
|
|
1044
|
-
return o ?
|
|
1059
|
+
static pendingTailIsCompletePhrase(e, s) {
|
|
1060
|
+
const o = A.commandPrefixTail(e, s).trim().toLowerCase();
|
|
1061
|
+
return o ? D(s).phraseToAction.has(o) : !1;
|
|
1045
1062
|
}
|
|
1046
1063
|
}
|
|
1047
1064
|
const Pe = 55, Te = 90;
|
|
@@ -1054,23 +1071,23 @@ class V {
|
|
|
1054
1071
|
*/
|
|
1055
1072
|
static nextDripText({
|
|
1056
1073
|
displayed: e,
|
|
1057
|
-
processed:
|
|
1074
|
+
processed: s
|
|
1058
1075
|
}) {
|
|
1059
|
-
if (
|
|
1060
|
-
const o =
|
|
1076
|
+
if (s.length <= e.length) return s;
|
|
1077
|
+
const o = s.length - e.length;
|
|
1061
1078
|
if (o > Te)
|
|
1062
|
-
return
|
|
1079
|
+
return s.slice(0, e.length + Math.ceil(o / 3));
|
|
1063
1080
|
let r = e.length;
|
|
1064
|
-
for (; r <
|
|
1065
|
-
for (; r <
|
|
1066
|
-
return r - e.length > 12 && (r = e.length + 6),
|
|
1081
|
+
for (; r < s.length && /\s/.test(s.charAt(r)); ) r++;
|
|
1082
|
+
for (; r < s.length && !/\s/.test(s.charAt(r)); ) r++;
|
|
1083
|
+
return r - e.length > 12 && (r = e.length + 6), s.slice(0, Math.max(r, e.length + 1));
|
|
1067
1084
|
}
|
|
1068
1085
|
/** Normalize a BCP-47 browser locale into the hint OpenAI accepts. */
|
|
1069
1086
|
static languageHint(e) {
|
|
1070
1087
|
if (!e) return;
|
|
1071
|
-
const
|
|
1072
|
-
if (/^zh-(cn|tw|hk)$/.test(
|
|
1073
|
-
const o =
|
|
1088
|
+
const s = e.toLowerCase();
|
|
1089
|
+
if (/^zh-(cn|tw|hk)$/.test(s)) return s;
|
|
1090
|
+
const o = s.split("-")[0];
|
|
1074
1091
|
return o && /^[a-z]{2,3}$/.test(o) ? o : void 0;
|
|
1075
1092
|
}
|
|
1076
1093
|
}
|
|
@@ -1090,8 +1107,8 @@ class Me {
|
|
|
1090
1107
|
* click reuses the same in-flight promise instead of double-minting).
|
|
1091
1108
|
*/
|
|
1092
1109
|
async resolve(e) {
|
|
1093
|
-
const
|
|
1094
|
-
return
|
|
1110
|
+
const s = this.get();
|
|
1111
|
+
return s || (this.inflight || (this.inflight = e().then((o) => (this.cached = o, o)).finally(() => {
|
|
1095
1112
|
this.inflight = null;
|
|
1096
1113
|
})), this.inflight);
|
|
1097
1114
|
}
|
|
@@ -1100,12 +1117,12 @@ class Me {
|
|
|
1100
1117
|
this.cached = null;
|
|
1101
1118
|
}
|
|
1102
1119
|
}
|
|
1103
|
-
function
|
|
1120
|
+
function G(i) {
|
|
1104
1121
|
return typeof i == "object" && i !== null && !Array.isArray(i);
|
|
1105
1122
|
}
|
|
1106
1123
|
function De(i) {
|
|
1107
|
-
if (!
|
|
1108
|
-
const e =
|
|
1124
|
+
if (!G(i) || typeof i.type != "string") return null;
|
|
1125
|
+
const e = G(i.error) ? i.error : null;
|
|
1109
1126
|
return {
|
|
1110
1127
|
type: i.type,
|
|
1111
1128
|
delta: typeof i.delta == "string" ? i.delta : void 0,
|
|
@@ -1118,12 +1135,12 @@ class T extends Error {
|
|
|
1118
1135
|
class Oe {
|
|
1119
1136
|
constructor({
|
|
1120
1137
|
mintToken: e,
|
|
1121
|
-
onDelta:
|
|
1138
|
+
onDelta: s,
|
|
1122
1139
|
onState: o,
|
|
1123
1140
|
onError: r,
|
|
1124
1141
|
onLevel: _
|
|
1125
1142
|
}) {
|
|
1126
|
-
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 =
|
|
1143
|
+
this.state = "idle", this.pc = null, this.dc = null, this.stream = null, this.audioContext = null, this.levelRaf = 0, this.timers = [], this.loggedParseFailure = !1, this.mintToken = e, this.onDelta = s, this.onState = o, this.onError = r, this.onLevel = _;
|
|
1127
1144
|
}
|
|
1128
1145
|
async start() {
|
|
1129
1146
|
if (this.state === "idle") {
|
|
@@ -1138,22 +1155,22 @@ class Oe {
|
|
|
1138
1155
|
this.isTornDown() || this.stream && this.stream !== d ? d.getTracks().forEach((l) => l.stop()) : this.stream = d;
|
|
1139
1156
|
}).catch(() => {
|
|
1140
1157
|
});
|
|
1141
|
-
const [
|
|
1158
|
+
const [s, o] = await Promise.all([e, this.mintToken()]);
|
|
1142
1159
|
if (this.isTornDown()) {
|
|
1143
|
-
|
|
1160
|
+
s.getTracks().forEach((d) => d.stop());
|
|
1144
1161
|
return;
|
|
1145
1162
|
}
|
|
1146
|
-
this.stream =
|
|
1163
|
+
this.stream = s, this.startLevelMeter(s);
|
|
1147
1164
|
const r = new RTCPeerConnection();
|
|
1148
1165
|
this.pc = r;
|
|
1149
|
-
const [_] =
|
|
1166
|
+
const [_] = s.getAudioTracks();
|
|
1150
1167
|
if (!_) throw new T("No audio track");
|
|
1151
|
-
r.addTrack(_,
|
|
1152
|
-
const
|
|
1153
|
-
this.dc =
|
|
1168
|
+
r.addTrack(_, s);
|
|
1169
|
+
const t = r.createDataChannel("oai-events");
|
|
1170
|
+
this.dc = t, t.addEventListener(
|
|
1154
1171
|
"message",
|
|
1155
1172
|
(d) => this.handleServerEvent(d.data)
|
|
1156
|
-
),
|
|
1173
|
+
), t.addEventListener("open", () => {
|
|
1157
1174
|
this.state === "connecting" && this.setState("listening");
|
|
1158
1175
|
}), r.addEventListener("connectionstatechange", () => {
|
|
1159
1176
|
if (r.connectionState === "failed") {
|
|
@@ -1182,7 +1199,7 @@ class Oe {
|
|
|
1182
1199
|
if (this.isTornDown()) return;
|
|
1183
1200
|
await r.setRemoteDescription({ type: "answer", sdp: c });
|
|
1184
1201
|
} catch (e) {
|
|
1185
|
-
e instanceof T ? this.fail("microphone") : (
|
|
1202
|
+
e instanceof T ? this.fail("microphone") : (b.error("dictation session failed to start", {
|
|
1186
1203
|
_e: e instanceof Error ? e.message : String(e)
|
|
1187
1204
|
}), this.fail("unavailable"));
|
|
1188
1205
|
}
|
|
@@ -1203,24 +1220,24 @@ class Oe {
|
|
|
1203
1220
|
autoGainControl: !0
|
|
1204
1221
|
}
|
|
1205
1222
|
});
|
|
1206
|
-
} catch (
|
|
1223
|
+
} catch (s) {
|
|
1207
1224
|
throw new T(
|
|
1208
|
-
|
|
1225
|
+
s instanceof DOMException ? s.name : "Could not access the microphone"
|
|
1209
1226
|
);
|
|
1210
1227
|
}
|
|
1211
1228
|
}
|
|
1212
1229
|
handleServerEvent(e) {
|
|
1213
1230
|
if (typeof e != "string") return;
|
|
1214
|
-
let
|
|
1231
|
+
let s;
|
|
1215
1232
|
try {
|
|
1216
|
-
|
|
1233
|
+
s = JSON.parse(e);
|
|
1217
1234
|
} catch {
|
|
1218
|
-
this.loggedParseFailure || (this.loggedParseFailure = !0,
|
|
1235
|
+
this.loggedParseFailure || (this.loggedParseFailure = !0, b.error("dictation server event was not valid JSON", {
|
|
1219
1236
|
snippet: e.slice(0, 120)
|
|
1220
1237
|
}));
|
|
1221
1238
|
return;
|
|
1222
1239
|
}
|
|
1223
|
-
const o = De(
|
|
1240
|
+
const o = De(s);
|
|
1224
1241
|
if (!o) return;
|
|
1225
1242
|
const { type: r, delta: _ } = o;
|
|
1226
1243
|
if (r === "session.created" || r === "transcription_session.created") {
|
|
@@ -1231,18 +1248,18 @@ class Oe {
|
|
|
1231
1248
|
this.state === "connecting" && this.setState("listening"), this.onDelta(_);
|
|
1232
1249
|
return;
|
|
1233
1250
|
}
|
|
1234
|
-
r === "error" && (
|
|
1251
|
+
r === "error" && (b.error("dictation server event error", {
|
|
1235
1252
|
_e: o.errorMessage ?? "unknown"
|
|
1236
1253
|
}), this.fail("unavailable"));
|
|
1237
1254
|
}
|
|
1238
1255
|
startLevelMeter(e) {
|
|
1239
1256
|
if (this.onLevel)
|
|
1240
1257
|
try {
|
|
1241
|
-
const
|
|
1242
|
-
this.audioContext =
|
|
1243
|
-
const o =
|
|
1258
|
+
const s = new AudioContext();
|
|
1259
|
+
this.audioContext = s;
|
|
1260
|
+
const o = s.createMediaStreamSource(e), r = s.createAnalyser();
|
|
1244
1261
|
r.fftSize = 512, o.connect(r);
|
|
1245
|
-
const _ = new Uint8Array(r.frequencyBinCount),
|
|
1262
|
+
const _ = new Uint8Array(r.frequencyBinCount), t = () => {
|
|
1246
1263
|
var c;
|
|
1247
1264
|
r.getByteTimeDomainData(_);
|
|
1248
1265
|
let a = 0;
|
|
@@ -1251,12 +1268,12 @@ class Oe {
|
|
|
1251
1268
|
a += l * l;
|
|
1252
1269
|
}
|
|
1253
1270
|
const n = Math.sqrt(a / _.length);
|
|
1254
|
-
(c = this.onLevel) == null || c.call(this, Math.min(1, n * 4)), this.levelRaf = requestAnimationFrame(
|
|
1271
|
+
(c = this.onLevel) == null || c.call(this, Math.min(1, n * 4)), this.levelRaf = requestAnimationFrame(t);
|
|
1255
1272
|
};
|
|
1256
|
-
this.levelRaf = requestAnimationFrame(
|
|
1257
|
-
} catch (
|
|
1258
|
-
|
|
1259
|
-
_e:
|
|
1273
|
+
this.levelRaf = requestAnimationFrame(t);
|
|
1274
|
+
} catch (s) {
|
|
1275
|
+
b.error("dictation level meter unavailable", {
|
|
1276
|
+
_e: s instanceof Error ? s.message : String(s)
|
|
1260
1277
|
});
|
|
1261
1278
|
}
|
|
1262
1279
|
}
|
|
@@ -1267,9 +1284,9 @@ class Oe {
|
|
|
1267
1284
|
this.isTornDown() || (this.teardown(), this.setState("error"), this.onError(e));
|
|
1268
1285
|
}
|
|
1269
1286
|
teardown() {
|
|
1270
|
-
var e,
|
|
1271
|
-
this.timers.forEach((_) => clearTimeout(_)), this.timers = [], this.levelRaf && cancelAnimationFrame(this.levelRaf), this.levelRaf = 0, (e = this.dc) == null || e.close(), this.dc = null, (
|
|
1272
|
-
|
|
1287
|
+
var e, s, o, r;
|
|
1288
|
+
this.timers.forEach((_) => clearTimeout(_)), this.timers = [], this.levelRaf && cancelAnimationFrame(this.levelRaf), this.levelRaf = 0, (e = this.dc) == null || e.close(), this.dc = null, (s = this.pc) == null || s.close(), this.pc = null, (o = this.stream) == null || o.getTracks().forEach((_) => _.stop()), this.stream = null, (r = this.audioContext) == null || r.close().catch((_) => {
|
|
1289
|
+
b.error("failed to close dictation audio context", {
|
|
1273
1290
|
_e: String(_)
|
|
1274
1291
|
});
|
|
1275
1292
|
}), this.audioContext = null;
|
|
@@ -1280,10 +1297,10 @@ class Oe {
|
|
|
1280
1297
|
}
|
|
1281
1298
|
const Fe = 1300, Ue = { status: "idle", error: null };
|
|
1282
1299
|
class Be {
|
|
1283
|
-
constructor({ api: e, config:
|
|
1284
|
-
this.state = new
|
|
1300
|
+
constructor({ api: e, config: s }) {
|
|
1301
|
+
this.state = new z(Ue), this.levelRef = { current: 0 }, this.mintCache = new Me(), this.session = null, this.target = null, this.prefix = "", this.raw = "", this.processed = "", this.displayed = "", this.dripTimer = null, this.silenceTimer = null, this.isActive = () => this.session !== null, this.prewarm = () => {
|
|
1285
1302
|
this.mintToken().catch((o) => {
|
|
1286
|
-
this.mintCache.clear(),
|
|
1303
|
+
this.mintCache.clear(), b.error("dictation token prewarm failed", {
|
|
1287
1304
|
_e: o instanceof Error ? o.message : String(o)
|
|
1288
1305
|
});
|
|
1289
1306
|
});
|
|
@@ -1309,16 +1326,16 @@ class Be {
|
|
|
1309
1326
|
return;
|
|
1310
1327
|
}
|
|
1311
1328
|
this.raw += _;
|
|
1312
|
-
const
|
|
1313
|
-
if (
|
|
1329
|
+
const t = this.ingest();
|
|
1330
|
+
if (t === "stop") {
|
|
1314
1331
|
this.teardown();
|
|
1315
1332
|
return;
|
|
1316
1333
|
}
|
|
1317
|
-
if (
|
|
1334
|
+
if (t === "send") {
|
|
1318
1335
|
this.teardown({ send: !0 });
|
|
1319
1336
|
return;
|
|
1320
1337
|
}
|
|
1321
|
-
this.stopSilenceTimer(),
|
|
1338
|
+
this.stopSilenceTimer(), A.pendingTailIsCompletePhrase(
|
|
1322
1339
|
this.raw,
|
|
1323
1340
|
this.language
|
|
1324
1341
|
) && (this.silenceTimer = setTimeout(() => {
|
|
@@ -1347,7 +1364,7 @@ class Be {
|
|
|
1347
1364
|
this.session && this.teardown(o);
|
|
1348
1365
|
}, this.mintToken = async () => this.mintCache.resolve(
|
|
1349
1366
|
() => this.api.createDictationSession({ language: this.language })
|
|
1350
|
-
), this.api = e, this.config =
|
|
1367
|
+
), this.api = e, this.config = s;
|
|
1351
1368
|
}
|
|
1352
1369
|
/** Applied text = prefix + dictated. A mismatch means the visitor edited. */
|
|
1353
1370
|
isConsistent() {
|
|
@@ -1359,28 +1376,28 @@ class Be {
|
|
|
1359
1376
|
/** Process the transcript and apply the outcome. Shared by the delta path,
|
|
1360
1377
|
* the silence timer, and (with `final`) teardown. Returns the control. */
|
|
1361
1378
|
ingest(e) {
|
|
1362
|
-
const
|
|
1379
|
+
const s = A.process(this.raw, {
|
|
1363
1380
|
language: this.language,
|
|
1364
1381
|
final: e == null ? void 0 : e.final
|
|
1365
1382
|
});
|
|
1366
|
-
return this.processed =
|
|
1383
|
+
return this.processed = s.text, s.text.startsWith(this.displayed) || this.applyDisplayed(s.text), s.control;
|
|
1367
1384
|
}
|
|
1368
1385
|
stopSilenceTimer() {
|
|
1369
1386
|
this.silenceTimer && clearTimeout(this.silenceTimer), this.silenceTimer = null;
|
|
1370
1387
|
}
|
|
1371
1388
|
teardown(e) {
|
|
1372
1389
|
var _;
|
|
1373
|
-
const
|
|
1390
|
+
const s = this.session, o = this.target;
|
|
1374
1391
|
this.dripTimer && clearInterval(this.dripTimer), this.dripTimer = null, this.stopSilenceTimer();
|
|
1375
1392
|
let r = (e == null ? void 0 : e.send) ?? !1;
|
|
1376
1393
|
if (o && this.isConsistent()) {
|
|
1377
|
-
const
|
|
1378
|
-
(e == null ? void 0 : e.executeFinalCommand) !== !1 &&
|
|
1394
|
+
const t = this.ingest({ final: !0 });
|
|
1395
|
+
(e == null ? void 0 : e.executeFinalCommand) !== !1 && t === "send" && (r = !0), this.processed !== this.displayed && this.applyDisplayed(this.processed);
|
|
1379
1396
|
}
|
|
1380
|
-
this.session = null, this.target = null,
|
|
1397
|
+
this.session = null, this.target = null, s == null || s.stop(), this.levelRef.current = 0, this.state.set({ status: "idle", error: (e == null ? void 0 : e.error) ?? null }), r && ((_ = o == null ? void 0 : o.onSend) == null || _.call(o));
|
|
1381
1398
|
}
|
|
1382
1399
|
}
|
|
1383
|
-
const
|
|
1400
|
+
const He = {
|
|
1384
1401
|
write_a_message_placeholder: "اكتب رسالة...",
|
|
1385
1402
|
your_issue_has_been_resolved: "تم حل مشكلتك!",
|
|
1386
1403
|
new_conversation: "محادثة جديدة",
|
|
@@ -1490,7 +1507,7 @@ const Ve = {
|
|
|
1490
1507
|
zoom_out: "تصغير",
|
|
1491
1508
|
reset_zoom: "إعادة تعيين التكبير",
|
|
1492
1509
|
support_chat_aria_label: "دردشة الدعم"
|
|
1493
|
-
},
|
|
1510
|
+
}, Ve = {
|
|
1494
1511
|
write_a_message_placeholder: "একটি বার্তা লিখুন...",
|
|
1495
1512
|
your_issue_has_been_resolved: "আপনার সমস্যা সমাধান হয়েছে!",
|
|
1496
1513
|
new_conversation: "নতুন কথোপকথন",
|
|
@@ -2072,7 +2089,7 @@ const Ve = {
|
|
|
2072
2089
|
zoom_out: "Verkleinern",
|
|
2073
2090
|
reset_zoom: "Zoom zurücksetzen",
|
|
2074
2091
|
support_chat_aria_label: "Support-Chat"
|
|
2075
|
-
},
|
|
2092
|
+
}, Y = {
|
|
2076
2093
|
write_a_message_placeholder: "Write a message...",
|
|
2077
2094
|
your_issue_has_been_resolved: "Your issue has been resolved!",
|
|
2078
2095
|
new_conversation: "New conversation",
|
|
@@ -2279,7 +2296,7 @@ const Ve = {
|
|
|
2279
2296
|
zoom_out: "Alejar",
|
|
2280
2297
|
reset_zoom: "Restablecer zoom",
|
|
2281
2298
|
support_chat_aria_label: "Chat de soporte"
|
|
2282
|
-
},
|
|
2299
|
+
}, Qe = {
|
|
2283
2300
|
write_a_message_placeholder: "Magsulat ng mensahe...",
|
|
2284
2301
|
your_issue_has_been_resolved: "Nalutas na ang iyong isyu!",
|
|
2285
2302
|
new_conversation: "Bagong usapan",
|
|
@@ -2376,7 +2393,7 @@ const Ve = {
|
|
|
2376
2393
|
zoom_out: "Paliitin",
|
|
2377
2394
|
reset_zoom: "I-reset ang zoom",
|
|
2378
2395
|
support_chat_aria_label: "Chat ng suporta"
|
|
2379
|
-
},
|
|
2396
|
+
}, Xe = {
|
|
2380
2397
|
write_a_message_placeholder: "Kirjoita viesti...",
|
|
2381
2398
|
your_issue_has_been_resolved: "Ongelmasi on ratkaistu!",
|
|
2382
2399
|
new_conversation: "Uusi keskustelu",
|
|
@@ -5092,19 +5109,19 @@ const Ve = {
|
|
|
5092
5109
|
zoom_out: "Oddialiť",
|
|
5093
5110
|
reset_zoom: "Obnoviť priblíženie",
|
|
5094
5111
|
support_chat_aria_label: "Chat podpory"
|
|
5095
|
-
},
|
|
5096
|
-
ar:
|
|
5097
|
-
bn:
|
|
5112
|
+
}, Q = {
|
|
5113
|
+
ar: He,
|
|
5114
|
+
bn: Ve,
|
|
5098
5115
|
bg: Ge,
|
|
5099
5116
|
cs: Ze,
|
|
5100
5117
|
da: We,
|
|
5101
5118
|
de: Je,
|
|
5102
5119
|
el: $e,
|
|
5103
|
-
en:
|
|
5120
|
+
en: Y,
|
|
5104
5121
|
es: Ye,
|
|
5105
5122
|
et: ba,
|
|
5106
|
-
fi:
|
|
5107
|
-
fil:
|
|
5123
|
+
fi: Xe,
|
|
5124
|
+
fil: Qe,
|
|
5108
5125
|
fr: ea,
|
|
5109
5126
|
hi: aa,
|
|
5110
5127
|
hr: ka,
|
|
@@ -5131,47 +5148,47 @@ const Ve = {
|
|
|
5131
5148
|
ur: ma,
|
|
5132
5149
|
vi: ha,
|
|
5133
5150
|
"zh-cn": ga
|
|
5134
|
-
}, xa = Object.keys(
|
|
5151
|
+
}, xa = Object.keys(Q);
|
|
5135
5152
|
function qa(i) {
|
|
5136
5153
|
return xa.includes(i);
|
|
5137
5154
|
}
|
|
5138
|
-
const
|
|
5139
|
-
function
|
|
5140
|
-
return
|
|
5155
|
+
const Aa = /* @__PURE__ */ new Set(["ar", "ur"]);
|
|
5156
|
+
function Xa(i) {
|
|
5157
|
+
return Aa.has(i);
|
|
5141
5158
|
}
|
|
5142
|
-
function
|
|
5159
|
+
function Ea(i) {
|
|
5143
5160
|
return qa(i) ? i : "en";
|
|
5144
5161
|
}
|
|
5145
|
-
function Pa(i, e,
|
|
5162
|
+
function Pa(i, e, s, o) {
|
|
5146
5163
|
var _;
|
|
5147
|
-
const r = ((_ =
|
|
5164
|
+
const r = ((_ = s == null ? void 0 : s[e]) == null ? void 0 : _[i]) || Q[e][i] || Y[i] || i;
|
|
5148
5165
|
return o ? r.replace(
|
|
5149
5166
|
/\{(\w+)\}/g,
|
|
5150
|
-
(
|
|
5167
|
+
(t, a) => a in o ? String(o[a]) : t
|
|
5151
5168
|
) : r;
|
|
5152
5169
|
}
|
|
5153
|
-
function Ta(i, e,
|
|
5170
|
+
function Ta(i, e, s) {
|
|
5154
5171
|
return Pa(
|
|
5155
5172
|
e,
|
|
5156
|
-
|
|
5173
|
+
Ea(i.language),
|
|
5157
5174
|
i.translationOverrides,
|
|
5158
|
-
|
|
5175
|
+
s
|
|
5159
5176
|
);
|
|
5160
5177
|
}
|
|
5161
5178
|
class Ia {
|
|
5162
5179
|
constructor({
|
|
5163
5180
|
config: e,
|
|
5164
|
-
api:
|
|
5181
|
+
api: s,
|
|
5165
5182
|
contactCtx: o,
|
|
5166
5183
|
storageCtx: r,
|
|
5167
5184
|
sessionsPollingIntervalSeconds: _,
|
|
5168
|
-
sharedSessions:
|
|
5185
|
+
sharedSessions: t
|
|
5169
5186
|
}) {
|
|
5170
|
-
this.sessionsRefresher = new
|
|
5187
|
+
this.sessionsRefresher = new $(), this.persistedSessionId = null, this.sessionAbortController = new AbortController(), this.sessionState = new z({
|
|
5171
5188
|
session: null,
|
|
5172
5189
|
isCreatingSession: !1,
|
|
5173
5190
|
isResolvingSession: !1
|
|
5174
|
-
}), this.sessionsState = new
|
|
5191
|
+
}), this.sessionsState = new z({
|
|
5175
5192
|
data: [],
|
|
5176
5193
|
cursor: void 0,
|
|
5177
5194
|
isLastPage: !1,
|
|
@@ -5198,7 +5215,7 @@ class Ia {
|
|
|
5198
5215
|
const c = a != null && a.isOpened ? a.id : null;
|
|
5199
5216
|
if (c === this.persistedSessionId || !c && this.persistedSessionId === null) return;
|
|
5200
5217
|
this.persistedSessionId = c, (c ? n.setActiveSessionId(c) : n.clearActiveSessionId()).catch((l) => {
|
|
5201
|
-
|
|
5218
|
+
b.warn("failed to persist the active session", {
|
|
5202
5219
|
error: l instanceof Error ? l.message : String(l)
|
|
5203
5220
|
});
|
|
5204
5221
|
});
|
|
@@ -5227,7 +5244,7 @@ class Ia {
|
|
|
5227
5244
|
var n, c;
|
|
5228
5245
|
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)
|
|
5229
5246
|
return this.persistedSessionId = null, this.storageCtx.clearActiveSessionId().catch((d) => {
|
|
5230
|
-
|
|
5247
|
+
b.warn("failed to clear the replaced session", {
|
|
5231
5248
|
error: d instanceof Error ? d.message : String(d)
|
|
5232
5249
|
});
|
|
5233
5250
|
});
|
|
@@ -5235,7 +5252,7 @@ class Ia {
|
|
|
5235
5252
|
Object.entries(this.config.sessionCustomData || {}).map(
|
|
5236
5253
|
([a, n]) => {
|
|
5237
5254
|
var c;
|
|
5238
|
-
return typeof n == "string" ? [a, n] : typeof n == "boolean" ? [a, n] : typeof n == "number" ? [a, n] : [a, ((c =
|
|
5255
|
+
return typeof n == "string" ? [a, n] : typeof n == "boolean" ? [a, n] : typeof n == "number" ? [a, n] : [a, ((c = J(() => JSON.stringify(n))) == null ? void 0 : c.data) || ""];
|
|
5239
5256
|
}
|
|
5240
5257
|
)
|
|
5241
5258
|
), this.createSession = async () => {
|
|
@@ -5248,11 +5265,11 @@ class Ia {
|
|
|
5248
5265
|
if (n.status === 401 && await this.contactCtx.recoverFromStaleToken()) {
|
|
5249
5266
|
if (a.aborted) return null;
|
|
5250
5267
|
const c = await this.requestSession(a);
|
|
5251
|
-
return a.aborted ? null : c.session ? c.session : (
|
|
5268
|
+
return a.aborted ? null : c.session ? c.session : (b.error("failed to create session", c.error), null);
|
|
5252
5269
|
}
|
|
5253
|
-
return
|
|
5270
|
+
return b.error("failed to create session", n.error), null;
|
|
5254
5271
|
} catch (n) {
|
|
5255
|
-
return a.aborted ||
|
|
5272
|
+
return a.aborted || b.error("failed to create session", n), null;
|
|
5256
5273
|
} finally {
|
|
5257
5274
|
a.aborted || this.sessionState.setPartial({ isCreatingSession: !1 });
|
|
5258
5275
|
}
|
|
@@ -5276,8 +5293,8 @@ class Ia {
|
|
|
5276
5293
|
this.sessionState.setPartial({ session: d }), this.setSessions([d]);
|
|
5277
5294
|
try {
|
|
5278
5295
|
(g = (m = this.config.hooks) == null ? void 0 : m.onSessionCreated) == null || g.call(m, { session: d });
|
|
5279
|
-
} catch (
|
|
5280
|
-
|
|
5296
|
+
} catch (v) {
|
|
5297
|
+
b.error("onSessionCreated hook failed", v);
|
|
5281
5298
|
}
|
|
5282
5299
|
return { session: d, status: p.status, error: void 0 };
|
|
5283
5300
|
}, this.loadMoreSessions = async () => {
|
|
@@ -5335,14 +5352,14 @@ class Ia {
|
|
|
5335
5352
|
payload: a
|
|
5336
5353
|
});
|
|
5337
5354
|
return c != null && c.success ? { success: !0 } : { success: !1 };
|
|
5338
|
-
}, this.config = e, this.api =
|
|
5355
|
+
}, this.config = e, this.api = s, this.contactCtx = o, this.storageCtx = r, this.sessionsPollingIntervalSeconds = _, t ? this.sessionsState = t : this.registerSessionsRefresherWrapper(), this.registerActiveSessionPersistence();
|
|
5339
5356
|
}
|
|
5340
5357
|
}
|
|
5341
|
-
const Ma = (i, e, { sendsPageContext:
|
|
5342
|
-
const o = Na(i), r =
|
|
5358
|
+
const Ma = (i, e, { sendsPageContext: s }) => {
|
|
5359
|
+
const o = Na(i), r = s && e.mentions && e.mentions.length > 0 ? { mentions: e.mentions.map(Da) } : void 0, _ = s && (e.clientContext || r) ? { ...o, ...e.clientContext, ...r } : o, t = e.connectionRequestId ? {
|
|
5343
5360
|
..._,
|
|
5344
5361
|
opencx__connection_request_id: e.connectionRequestId
|
|
5345
|
-
} : _, a = e.withPageEntity === !1 &&
|
|
5362
|
+
} : _, a = e.withPageEntity === !1 && t && "entity" in t ? Ra(t, "entity") : t;
|
|
5346
5363
|
return {
|
|
5347
5364
|
clientContext: e.background ? { ...a, opencx__background: !0 } : a,
|
|
5348
5365
|
custom_data: {
|
|
@@ -5350,41 +5367,41 @@ const Ma = (i, e, { sendsPageContext: t }) => {
|
|
|
5350
5367
|
...e.customData || {}
|
|
5351
5368
|
}
|
|
5352
5369
|
};
|
|
5353
|
-
}, Da = ({ type: i, id: e, title:
|
|
5370
|
+
}, Da = ({ type: i, id: e, title: s, meta: o }) => ({
|
|
5354
5371
|
type: i,
|
|
5355
5372
|
id: e,
|
|
5356
|
-
title:
|
|
5373
|
+
title: s,
|
|
5357
5374
|
...o ? { meta: o } : {}
|
|
5358
5375
|
}), Ra = (i, e) => {
|
|
5359
|
-
const { [e]:
|
|
5376
|
+
const { [e]: s, ...o } = i;
|
|
5360
5377
|
return Object.keys(o).length > 0 ? o : void 0;
|
|
5361
5378
|
}, Na = (i) => {
|
|
5362
5379
|
if (typeof i.context != "function") return i.context;
|
|
5363
5380
|
try {
|
|
5364
5381
|
return i.context();
|
|
5365
5382
|
} catch (e) {
|
|
5366
|
-
|
|
5383
|
+
b.error("context getter threw; sending without context", e);
|
|
5367
5384
|
return;
|
|
5368
5385
|
}
|
|
5369
5386
|
}, Ka = (i) => {
|
|
5370
|
-
const e = i.features,
|
|
5387
|
+
const e = i.features, s = {
|
|
5371
5388
|
page_context: (e == null ? void 0 : e.pageContext) === !0,
|
|
5372
5389
|
client_tools: (e == null ? void 0 : e.pageContext) === !0 && (e == null ? void 0 : e.clientTools) === !0,
|
|
5373
5390
|
page_actions: (e == null ? void 0 : e.pageContext) === !0 && (e == null ? void 0 : e.clientTools) === !0 && (e == null ? void 0 : e.pageActions) === !0
|
|
5374
5391
|
};
|
|
5375
|
-
return e && (e.preamble !== void 0 && (
|
|
5392
|
+
return e && (e.preamble !== void 0 && (s.preamble = e.preamble), e.inlineUi !== void 0 && (s.inline_ui = e.inlineUi)), s;
|
|
5376
5393
|
}, La = ({
|
|
5377
5394
|
config: i,
|
|
5378
5395
|
input: e,
|
|
5379
|
-
uuid:
|
|
5396
|
+
uuid: s,
|
|
5380
5397
|
sessionId: o,
|
|
5381
5398
|
content: r,
|
|
5382
5399
|
initialMessages: _,
|
|
5383
|
-
sendsPageContext:
|
|
5400
|
+
sendsPageContext: t
|
|
5384
5401
|
}) => {
|
|
5385
5402
|
var a, n, c, d;
|
|
5386
5403
|
return {
|
|
5387
|
-
uuid:
|
|
5404
|
+
uuid: s,
|
|
5388
5405
|
bot_token: i.token,
|
|
5389
5406
|
headers: i.headers,
|
|
5390
5407
|
query_params: i.queryParams,
|
|
@@ -5392,7 +5409,7 @@ const Ma = (i, e, { sendsPageContext: t }) => {
|
|
|
5392
5409
|
session_id: o,
|
|
5393
5410
|
content: r,
|
|
5394
5411
|
attachments: e.attachments,
|
|
5395
|
-
...Ma(i, e, { sendsPageContext:
|
|
5412
|
+
...Ma(i, e, { sendsPageContext: t }),
|
|
5396
5413
|
language: i.language,
|
|
5397
5414
|
features: Ka(i),
|
|
5398
5415
|
presentation: i.presentation,
|
|
@@ -5412,24 +5429,24 @@ const Ma = (i, e, { sendsPageContext: t }) => {
|
|
|
5412
5429
|
}, x = class x {
|
|
5413
5430
|
constructor({
|
|
5414
5431
|
config: e,
|
|
5415
|
-
api:
|
|
5432
|
+
api: s,
|
|
5416
5433
|
sessionCtx: o,
|
|
5417
5434
|
contactCtx: r,
|
|
5418
5435
|
streaming: _,
|
|
5419
|
-
sendsPageContext:
|
|
5436
|
+
sendsPageContext: t,
|
|
5420
5437
|
getClientCapabilities: a,
|
|
5421
5438
|
getRequestConfig: n,
|
|
5422
5439
|
isStreaming: c,
|
|
5423
5440
|
getSendsPageContext: d
|
|
5424
5441
|
}) {
|
|
5425
|
-
this.state = new
|
|
5442
|
+
this.state = new z({
|
|
5426
5443
|
messages: [],
|
|
5427
5444
|
isSendingMessage: !1,
|
|
5428
5445
|
isSendingMessageToAI: !1,
|
|
5429
5446
|
settledAgentUserMessageId: null,
|
|
5430
5447
|
lastAIResMightSolveUserIssue: !1,
|
|
5431
5448
|
isInitialFetchLoading: !1
|
|
5432
|
-
}), this.draftState = new
|
|
5449
|
+
}), this.draftState = new z({
|
|
5433
5450
|
text: "",
|
|
5434
5451
|
mentions: []
|
|
5435
5452
|
}), this.agentHandlers = null, this.bufferedAgentSends = [], this.sendMessageAbortController = new AbortController(), this.conversationGeneration = 0, this.captureConversation = () => {
|
|
@@ -5490,30 +5507,30 @@ const Ma = (i, e, { sendsPageContext: t }) => {
|
|
|
5490
5507
|
try {
|
|
5491
5508
|
(p = l.onAccepted) == null || p.call(l);
|
|
5492
5509
|
} catch (u) {
|
|
5493
|
-
|
|
5510
|
+
b.error("send acceptance callback failed", u);
|
|
5494
5511
|
}
|
|
5495
5512
|
}, this.stageUserTurn = async (l, { pending: p }) => {
|
|
5496
5513
|
const u = this.captureConversation(), m = this.buildUserMessage(l);
|
|
5497
5514
|
if (!m) return null;
|
|
5498
|
-
const g = p ? { ...m, pending: !0 } : m,
|
|
5499
|
-
...
|
|
5515
|
+
const g = p ? { ...m, pending: !0 } : m, v = this.buildPersistentInitialMessages(), y = [
|
|
5516
|
+
...v.map((w) => w.id),
|
|
5500
5517
|
g.id
|
|
5501
5518
|
];
|
|
5502
5519
|
this.state.setPartial({
|
|
5503
5520
|
messages: [
|
|
5504
|
-
...
|
|
5521
|
+
...v,
|
|
5505
5522
|
...this.state.get().messages,
|
|
5506
5523
|
...g.background ? [] : [g]
|
|
5507
5524
|
]
|
|
5508
5525
|
});
|
|
5509
|
-
let
|
|
5526
|
+
let f;
|
|
5510
5527
|
try {
|
|
5511
|
-
|
|
5512
|
-
} catch (
|
|
5528
|
+
f = await this.ensureSessionId();
|
|
5529
|
+
} catch (w) {
|
|
5513
5530
|
if (!u()) return null;
|
|
5514
|
-
throw this.rollbackOptimisticMessages(
|
|
5531
|
+
throw this.rollbackOptimisticMessages(y), w;
|
|
5515
5532
|
}
|
|
5516
|
-
return u() ?
|
|
5533
|
+
return u() ? f ? { sessionId: f, userMessage: g, initialMessages: v } : (this.rollbackOptimisticMessages(y), null) : null;
|
|
5517
5534
|
}, this.buildQueuedUserMessage = (l) => {
|
|
5518
5535
|
var m;
|
|
5519
5536
|
const p = this.buildUserMessage(l);
|
|
@@ -5522,7 +5539,7 @@ const Ma = (i, e, { sendsPageContext: t }) => {
|
|
|
5522
5539
|
return u ? { sessionId: u, userMessage: { ...p, pending: !0 } } : null;
|
|
5523
5540
|
}, this.buildUserMessage = (l) => {
|
|
5524
5541
|
var p;
|
|
5525
|
-
return !l.content.trim() && (!l.attachments || l.attachments.length === 0) ? (
|
|
5542
|
+
return !l.content.trim() && (!l.attachments || l.attachments.length === 0) ? (b.warn("cannot send an empty message of no content or attachments"), null) : {
|
|
5526
5543
|
...this.toUserMessage(
|
|
5527
5544
|
l.content.trim(),
|
|
5528
5545
|
l.attachments || void 0,
|
|
@@ -5537,7 +5554,7 @@ const Ma = (i, e, { sendsPageContext: t }) => {
|
|
|
5537
5554
|
p.some((u) => u.id === l.id) || this.state.setPartial({ messages: [...p, l] });
|
|
5538
5555
|
}, this.markUserMessageDelivered = (l) => {
|
|
5539
5556
|
const p = this.state.get().messages, u = p.findIndex(
|
|
5540
|
-
(
|
|
5557
|
+
(v) => v.id === l && v.type === "USER" && v.pending
|
|
5541
5558
|
);
|
|
5542
5559
|
if (u === -1) return;
|
|
5543
5560
|
const m = p[u];
|
|
@@ -5547,20 +5564,20 @@ const Ma = (i, e, { sendsPageContext: t }) => {
|
|
|
5547
5564
|
messages: g
|
|
5548
5565
|
});
|
|
5549
5566
|
}, this.setMessageOptionPick = (l, p) => {
|
|
5550
|
-
const u = this.state.get().messages, m = u.findIndex((
|
|
5567
|
+
const u = this.state.get().messages, m = u.findIndex((y) => y.id === l), g = u[m];
|
|
5551
5568
|
if (!g || g.type !== "AGENT" || !g.messageOptions || g.messageOptions.pickedOptionId === p) return;
|
|
5552
|
-
const
|
|
5553
|
-
|
|
5569
|
+
const v = [...u];
|
|
5570
|
+
v[m] = {
|
|
5554
5571
|
...g,
|
|
5555
5572
|
messageOptions: { ...g.messageOptions, pickedOptionId: p }
|
|
5556
|
-
}, this.state.setPartial({ messages:
|
|
5573
|
+
}, this.state.setPartial({ messages: v });
|
|
5557
5574
|
}, this.releaseFailedOptionPick = (l) => {
|
|
5558
5575
|
var g;
|
|
5559
5576
|
if (!l.optionReply) return;
|
|
5560
|
-
const { messageId: p, optionId: u } = l.optionReply, m = this.state.get().messages.find((
|
|
5577
|
+
const { messageId: p, optionId: u } = l.optionReply, m = this.state.get().messages.find((v) => v.id === p);
|
|
5561
5578
|
(m == null ? void 0 : m.type) !== "AGENT" || ((g = m.messageOptions) == null ? void 0 : g.pickedOptionId) !== u || this.setMessageOptionPick(p, null);
|
|
5562
5579
|
}, this.sendMessage = async (l) => {
|
|
5563
|
-
var u, m, g,
|
|
5580
|
+
var u, m, g, v, y;
|
|
5564
5581
|
if (this.streaming) {
|
|
5565
5582
|
if (!this.agentHandlers) {
|
|
5566
5583
|
this.bufferedAgentSends.push(l);
|
|
@@ -5571,65 +5588,65 @@ const Ma = (i, e, { sendsPageContext: t }) => {
|
|
|
5571
5588
|
}
|
|
5572
5589
|
let p;
|
|
5573
5590
|
try {
|
|
5574
|
-
const
|
|
5575
|
-
if (this.blocksSendWhileAwaitingReply && (
|
|
5576
|
-
|
|
5577
|
-
|
|
5591
|
+
const f = this.sessionCtx.sessionState.get().session, k = (f == null ? void 0 : f.assignee.kind) === "ai", M = this.state.get().isSendingMessageToAI, E = this.state.get().messages.at(-1);
|
|
5592
|
+
if (this.blocksSendWhileAwaitingReply && (M || // If last message is from user, then bot response did not arrive yet
|
|
5593
|
+
k && (E == null ? void 0 : E.type) === "USER" && E.id !== this.state.get().settledAgentUserMessageId)) {
|
|
5594
|
+
b.warn("cannot send messages while awaiting AI response");
|
|
5578
5595
|
return;
|
|
5579
5596
|
}
|
|
5580
5597
|
this.sendMessageAbortController.abort("Superseded by a newer message"), this.sendMessageAbortController = new AbortController(), p = this.sendMessageAbortController, this.state.setPartial({
|
|
5581
5598
|
lastAIResMightSolveUserIssue: !1,
|
|
5582
5599
|
isSendingMessage: !0,
|
|
5583
|
-
isSendingMessageToAI: !!
|
|
5600
|
+
isSendingMessageToAI: !!k || !f
|
|
5584
5601
|
});
|
|
5585
|
-
const
|
|
5586
|
-
if (!
|
|
5587
|
-
const { sessionId: ee, userMessage:
|
|
5602
|
+
const K = await this.stageUserTurn(l, { pending: !1 });
|
|
5603
|
+
if (!K) return;
|
|
5604
|
+
const { sessionId: ee, userMessage: L, initialMessages: ae } = K;
|
|
5588
5605
|
this.notifySendAccepted(l);
|
|
5589
|
-
const { data:
|
|
5606
|
+
const { data: j } = await this.api.sendMessage(
|
|
5590
5607
|
La({
|
|
5591
5608
|
config: {
|
|
5592
5609
|
...this.getRequestConfig(),
|
|
5593
5610
|
capabilities: this.getClientCapabilities()
|
|
5594
5611
|
},
|
|
5595
5612
|
input: l,
|
|
5596
|
-
uuid:
|
|
5613
|
+
uuid: L.id,
|
|
5597
5614
|
sessionId: ee,
|
|
5598
|
-
content:
|
|
5615
|
+
content: L.content,
|
|
5599
5616
|
initialMessages: ae,
|
|
5600
5617
|
sendsPageContext: this.sendsPageContext
|
|
5601
5618
|
}),
|
|
5602
5619
|
p.signal
|
|
5603
5620
|
);
|
|
5604
|
-
if (
|
|
5605
|
-
const C = this.toBotMessage(
|
|
5621
|
+
if (j != null && j.success) {
|
|
5622
|
+
const C = this.toBotMessage(j);
|
|
5606
5623
|
if (C) {
|
|
5607
5624
|
const P = this.state.get().messages;
|
|
5608
5625
|
if (!!P.some(
|
|
5609
5626
|
(te) => te.id === C.id
|
|
5610
5627
|
)) {
|
|
5611
5628
|
this.state.setPartial({
|
|
5612
|
-
lastAIResMightSolveUserIssue: ((u =
|
|
5629
|
+
lastAIResMightSolveUserIssue: ((u = j.autopilotResponse) == null ? void 0 : u.mightSolveUserIssue) || ((m = j.uiResponse) == null ? void 0 : m.mightSolveUserIssue)
|
|
5613
5630
|
});
|
|
5614
5631
|
return;
|
|
5615
5632
|
}
|
|
5616
5633
|
this.state.setPartial({
|
|
5617
5634
|
messages: [...P, C],
|
|
5618
|
-
lastAIResMightSolveUserIssue: ((g =
|
|
5635
|
+
lastAIResMightSolveUserIssue: ((g = j.autopilotResponse) == null ? void 0 : g.mightSolveUserIssue) || ((v = j.uiResponse) == null ? void 0 : v.mightSolveUserIssue)
|
|
5619
5636
|
}), this.dispatchToOnMessageReceivedHook(C);
|
|
5620
5637
|
}
|
|
5621
|
-
|
|
5638
|
+
j.session && this.sessionCtx.sessionState.setPartial({ session: j.session });
|
|
5622
5639
|
} else {
|
|
5623
5640
|
this.releaseFailedOptionPick(l);
|
|
5624
5641
|
const C = this.toBotErrorMessage(
|
|
5625
|
-
((
|
|
5642
|
+
((y = j == null ? void 0 : j.error) == null ? void 0 : y.message) || Ta(this.config, "turn_failed_message")
|
|
5626
5643
|
), P = this.state.get().messages;
|
|
5627
5644
|
this.state.setPartial({
|
|
5628
5645
|
messages: [...P, C]
|
|
5629
5646
|
});
|
|
5630
5647
|
}
|
|
5631
|
-
} catch (
|
|
5632
|
-
p != null && p.signal.aborted || (this.releaseFailedOptionPick(l),
|
|
5648
|
+
} catch (f) {
|
|
5649
|
+
p != null && p.signal.aborted || (this.releaseFailedOptionPick(l), b.error("failed to send message", f));
|
|
5633
5650
|
} finally {
|
|
5634
5651
|
p != null && p.signal.aborted || this.state.setPartial({
|
|
5635
5652
|
isSendingMessage: !1,
|
|
@@ -5638,21 +5655,21 @@ const Ma = (i, e, { sendsPageContext: t }) => {
|
|
|
5638
5655
|
}
|
|
5639
5656
|
}, this.toUserMessage = (l, p, u, m) => {
|
|
5640
5657
|
const g = (() => {
|
|
5641
|
-
const
|
|
5642
|
-
return this.state.get().messages.length === 0 &&
|
|
5658
|
+
const y = this.contactCtx.state.get().extraCollectedData;
|
|
5659
|
+
return this.state.get().messages.length === 0 && y && Object.keys(y).length > 0 ? `${Object.entries(y).filter(([w, k]) => !!k).map(([w, k]) => `${w}: ${k}`).join(`
|
|
5643
5660
|
`)}
|
|
5644
5661
|
|
|
5645
5662
|
${l}` : l;
|
|
5646
|
-
})(),
|
|
5663
|
+
})(), v = (/* @__PURE__ */ new Date()).toISOString();
|
|
5647
5664
|
return {
|
|
5648
5665
|
id: q(),
|
|
5649
5666
|
type: "USER",
|
|
5650
|
-
deliveredAt:
|
|
5667
|
+
deliveredAt: v,
|
|
5651
5668
|
content: g,
|
|
5652
5669
|
attachments: p,
|
|
5653
5670
|
markedElements: u,
|
|
5654
5671
|
mentions: m,
|
|
5655
|
-
timestamp:
|
|
5672
|
+
timestamp: v
|
|
5656
5673
|
};
|
|
5657
5674
|
}, this.toBotMessage = (l) => {
|
|
5658
5675
|
var p;
|
|
@@ -5687,7 +5704,7 @@ ${l}` : l;
|
|
|
5687
5704
|
variant: "error",
|
|
5688
5705
|
action: void 0
|
|
5689
5706
|
}
|
|
5690
|
-
}), this.config = e, this.getClientCapabilities = a ?? (() => this.getRequestConfig().capabilities), this.api =
|
|
5707
|
+
}), this.config = e, this.getClientCapabilities = a ?? (() => this.getRequestConfig().capabilities), this.api = s, this.sessionCtx = o, this.contactCtx = r, this.isStreaming = c ?? (() => _), this.getRequestConfig = n ?? (() => this.config), this.getSendsPageContext = d ?? (() => t);
|
|
5691
5708
|
}
|
|
5692
5709
|
/**
|
|
5693
5710
|
* Current transport choice. The org or this embed may request polling
|
|
@@ -5700,18 +5717,18 @@ ${l}` : l;
|
|
|
5700
5717
|
return this.getSendsPageContext();
|
|
5701
5718
|
}
|
|
5702
5719
|
/** Hand a send to the streaming engine; its failure can never propagate. */
|
|
5703
|
-
static dispatchToEngine(e,
|
|
5720
|
+
static dispatchToEngine(e, s) {
|
|
5704
5721
|
try {
|
|
5705
|
-
Promise.resolve(e.send(
|
|
5706
|
-
|
|
5722
|
+
Promise.resolve(e.send(s)).catch((o) => {
|
|
5723
|
+
b.error("streaming send failed", o);
|
|
5707
5724
|
});
|
|
5708
5725
|
} catch (o) {
|
|
5709
|
-
|
|
5726
|
+
b.error("streaming send failed", o);
|
|
5710
5727
|
}
|
|
5711
5728
|
}
|
|
5712
5729
|
get hasPendingAgentWork() {
|
|
5713
|
-
var e,
|
|
5714
|
-
return this.bufferedAgentSends.length > 0 || (((
|
|
5730
|
+
var e, s;
|
|
5731
|
+
return this.bufferedAgentSends.length > 0 || (((s = (e = this.agentHandlers) == null ? void 0 : e.hasPendingWork) == null ? void 0 : s.call(e)) ?? !1);
|
|
5715
5732
|
}
|
|
5716
5733
|
/**
|
|
5717
5734
|
* Defensive read of `clientContext.page_marks` → the user bubble's context
|
|
@@ -5721,11 +5738,11 @@ ${l}` : l;
|
|
|
5721
5738
|
* without a usable name are dropped.
|
|
5722
5739
|
*/
|
|
5723
5740
|
static markedElementNames(e) {
|
|
5724
|
-
const
|
|
5725
|
-
if (!Array.isArray(
|
|
5726
|
-
const o =
|
|
5741
|
+
const s = e == null ? void 0 : e.page_marks;
|
|
5742
|
+
if (!Array.isArray(s)) return;
|
|
5743
|
+
const o = s.flatMap((r) => {
|
|
5727
5744
|
if (typeof r != "object" || r === null) return [];
|
|
5728
|
-
const _ = r.elements,
|
|
5745
|
+
const _ = r.elements, t = Array.isArray(_) ? _[0] : void 0, a = typeof t == "object" && t !== null && "name" in t ? t.name : void 0;
|
|
5729
5746
|
if (typeof a != "string" || a.length === 0) return [];
|
|
5730
5747
|
const n = r.note, c = r.snapshotUrl;
|
|
5731
5748
|
return [
|
|
@@ -5748,10 +5765,10 @@ ${l}` : l;
|
|
|
5748
5765
|
}
|
|
5749
5766
|
};
|
|
5750
5767
|
x.SENT_TEXT_HISTORY_MAX = 50;
|
|
5751
|
-
let
|
|
5768
|
+
let R = x;
|
|
5752
5769
|
class Oa {
|
|
5753
5770
|
constructor(e) {
|
|
5754
|
-
var
|
|
5771
|
+
var s, o;
|
|
5755
5772
|
this.widget = e, this.subscriptions = [], this.disposed = !1, this.restorableSessionId = null, this.didReadStoredSession = !1, this.readStoredSession = () => {
|
|
5756
5773
|
if (!this.shouldRestoreLastSession) {
|
|
5757
5774
|
this.didReadStoredSession = !0;
|
|
@@ -5777,9 +5794,9 @@ class Oa {
|
|
|
5777
5794
|
isInitialFetchLoading: r,
|
|
5778
5795
|
data: _
|
|
5779
5796
|
}) => {
|
|
5780
|
-
var
|
|
5797
|
+
var t, a, n, c, d;
|
|
5781
5798
|
if (!(this.disposed || !this.didReadStoredSession)) {
|
|
5782
|
-
if (this.restorableSessionId && !((
|
|
5799
|
+
if (this.restorableSessionId && !((t = this.sessionCtx.sessionState.get().session) != null && t.id)) {
|
|
5783
5800
|
const l = _.find(
|
|
5784
5801
|
(p) => p.id === this.restorableSessionId && p.isOpened
|
|
5785
5802
|
);
|
|
@@ -5803,7 +5820,7 @@ class Oa {
|
|
|
5803
5820
|
}, this.toSessionsScreen = () => {
|
|
5804
5821
|
this.navigateConversation || this.resetChat(), this.state.setPartial({ screen: "sessions" });
|
|
5805
5822
|
}, this.toChatScreen = (r) => {
|
|
5806
|
-
var
|
|
5823
|
+
var t, a;
|
|
5807
5824
|
if (this.navigateConversation) return this.navigateConversation(r);
|
|
5808
5825
|
this.resetChat();
|
|
5809
5826
|
let _;
|
|
@@ -5811,16 +5828,16 @@ class Oa {
|
|
|
5811
5828
|
if (_ = this.sessionCtx.sessionsState.get().data.find((n) => n.id === r), !_) return;
|
|
5812
5829
|
this.sessionCtx.sessionState.setPartial({ session: _ });
|
|
5813
5830
|
}
|
|
5814
|
-
return this.state.setPartial({ screen: "chat" }), (a = (
|
|
5815
|
-
}, this.config = e.config, this.contactCtx = e.contactCtx, this.sessionCtx = e.sessionCtx, this.resetChat = e.resetChat, this.state = new
|
|
5816
|
-
screen: this.contactCtx.shouldCollectData() ? "welcome" : (
|
|
5831
|
+
return this.state.setPartial({ screen: "chat" }), (a = (t = this.config.hooks) == null ? void 0 : t.onNavigateToChat) == null || a.call(t, { session: _ }), this.widget;
|
|
5832
|
+
}, this.config = e.config, this.contactCtx = e.contactCtx, this.sessionCtx = e.sessionCtx, this.resetChat = e.resetChat, this.state = new z({
|
|
5833
|
+
screen: this.contactCtx.shouldCollectData() ? "welcome" : (s = this.config.router) != null && s.chatScreenOnly ? "chat" : "sessions"
|
|
5817
5834
|
}), this.shouldRestoreLastSession = ((o = this.config.router) == null ? void 0 : o.restoreLastSession) ?? !1, this.readStoredSession(), this.registerRoutingListener();
|
|
5818
5835
|
}
|
|
5819
5836
|
}
|
|
5820
5837
|
class Fa {
|
|
5821
5838
|
constructor({
|
|
5822
5839
|
storage: e,
|
|
5823
|
-
config:
|
|
5840
|
+
config: s
|
|
5824
5841
|
}) {
|
|
5825
5842
|
this.KEYS = {
|
|
5826
5843
|
contactToken: (o) => `opencx-widget:org-token-${o}:contact-token`,
|
|
@@ -5861,7 +5878,7 @@ class Fa {
|
|
|
5861
5878
|
return o === "docked" || o === "floating" ? o : null;
|
|
5862
5879
|
}, this.setCompanionSidebarMode = async (o) => {
|
|
5863
5880
|
await this.storage.set(this.companionKey("sidebar-mode"), o);
|
|
5864
|
-
}, this.storage = e, this.config =
|
|
5881
|
+
}, this.storage = e, this.config = s;
|
|
5865
5882
|
}
|
|
5866
5883
|
}
|
|
5867
5884
|
function Ua({
|
|
@@ -5893,40 +5910,40 @@ function Ua({
|
|
|
5893
5910
|
}
|
|
5894
5911
|
};
|
|
5895
5912
|
}
|
|
5896
|
-
function
|
|
5913
|
+
function Z(i, e) {
|
|
5897
5914
|
return i && e !== !1;
|
|
5898
5915
|
}
|
|
5899
5916
|
function Ba(i, e) {
|
|
5900
|
-
const
|
|
5917
|
+
const s = e.features;
|
|
5901
5918
|
return {
|
|
5902
|
-
dictation:
|
|
5903
|
-
attachments:
|
|
5919
|
+
dictation: Z(i.features.dictation, s == null ? void 0 : s.dictation),
|
|
5920
|
+
attachments: Z(
|
|
5904
5921
|
i.features.attachments,
|
|
5905
|
-
|
|
5922
|
+
s == null ? void 0 : s.attachments
|
|
5906
5923
|
),
|
|
5907
|
-
pageContext: i.features.pageContext && (
|
|
5908
|
-
clientTools: i.features.clientTools && i.features.pageContext && (
|
|
5909
|
-
pageActions: i.features.pageActions && i.features.clientTools && i.features.pageContext && (
|
|
5924
|
+
pageContext: i.features.pageContext && (s == null ? void 0 : s.pageContext) === !0,
|
|
5925
|
+
clientTools: i.features.clientTools && i.features.pageContext && (s == null ? void 0 : s.pageContext) === !0 && (s == null ? void 0 : s.clientTools) === !0,
|
|
5926
|
+
pageActions: i.features.pageActions && i.features.clientTools && i.features.pageContext && (s == null ? void 0 : s.pageContext) === !0 && (s == null ? void 0 : s.clientTools) === !0 && (s == null ? void 0 : s.pageActions) === !0
|
|
5910
5927
|
};
|
|
5911
5928
|
}
|
|
5912
|
-
class
|
|
5913
|
-
constructor(e,
|
|
5914
|
-
super(
|
|
5929
|
+
class Ha extends Error {
|
|
5930
|
+
constructor(e, s, o) {
|
|
5931
|
+
super(s), this.name = "WidgetInitializationError", this.code = e, this.details = o;
|
|
5915
5932
|
}
|
|
5916
5933
|
}
|
|
5917
|
-
const
|
|
5934
|
+
const S = class S {
|
|
5918
5935
|
constructor({
|
|
5919
5936
|
config: e,
|
|
5920
|
-
storage:
|
|
5937
|
+
storage: s,
|
|
5921
5938
|
getClientCapabilities: o,
|
|
5922
5939
|
getRequestConfig: r,
|
|
5923
5940
|
modes: _,
|
|
5924
|
-
org:
|
|
5941
|
+
org: t,
|
|
5925
5942
|
agent: a,
|
|
5926
5943
|
parent: n
|
|
5927
5944
|
}) {
|
|
5928
5945
|
if (this.modes = [], this.disposed = !1, this.createConversation = () => {
|
|
5929
|
-
const c = new
|
|
5946
|
+
const c = new S({
|
|
5930
5947
|
config: {
|
|
5931
5948
|
...this.config,
|
|
5932
5949
|
router: {
|
|
@@ -5953,11 +5970,11 @@ const j = class j {
|
|
|
5953
5970
|
return this.messageCtx.reset(), this.uploadCtx.reset(), this.dictationCtx.stop({ executeFinalCommand: !1 }), d;
|
|
5954
5971
|
}, this.resetChat = () => {
|
|
5955
5972
|
this.sessionCtx.reset(), this.messageCtx.reset(), this.uploadCtx.reset();
|
|
5956
|
-
}, this.reconcileAfterStream = (c) => this.activeSessionPollingCtx.reconcileAfterStream(c), !
|
|
5973
|
+
}, this.reconcileAfterStream = (c) => this.activeSessionPollingCtx.reconcileAfterStream(c), !S.pollingIntervalsSeconds)
|
|
5957
5974
|
throw Error(
|
|
5958
5975
|
"Widget polling values are not defined, did you call WidgetCtx.initialize()"
|
|
5959
5976
|
);
|
|
5960
|
-
this.config = e, this.getRequestConfig = r ?? (() => this.config), this.getClientCapabilities = o, this.org =
|
|
5977
|
+
this.config = e, this.getRequestConfig = r ?? (() => this.config), this.getClientCapabilities = o, this.org = t, this.agent = a, this.api = (n == null ? void 0 : n.api) ?? new B({ config: e }), this.storageCtx = (n == null ? void 0 : n.storageCtx) ?? (s ? new Fa({ storage: s, config: e }) : void 0), this.modes = _, this.contactCtx = (n == null ? void 0 : n.contactCtx) ?? new ve({
|
|
5961
5978
|
api: this.api,
|
|
5962
5979
|
config: this.config,
|
|
5963
5980
|
storageCtx: this.storageCtx
|
|
@@ -5968,13 +5985,13 @@ const j = class j {
|
|
|
5968
5985
|
// Remembers the open conversation so a reload can return to it.
|
|
5969
5986
|
storageCtx: n ? void 0 : this.storageCtx,
|
|
5970
5987
|
sharedSessions: n == null ? void 0 : n.sessionCtx.sessionsState,
|
|
5971
|
-
sessionsPollingIntervalSeconds:
|
|
5988
|
+
sessionsPollingIntervalSeconds: S.pollingIntervalsSeconds.sessions
|
|
5972
5989
|
}), this.ownsUnreadCtx = !n, this.unreadCtx = (n == null ? void 0 : n.unreadCtx) ?? new ie({
|
|
5973
5990
|
config: this.config,
|
|
5974
5991
|
api: this.api,
|
|
5975
5992
|
sessionsState: this.sessionCtx.sessionsState,
|
|
5976
5993
|
setSessions: this.sessionCtx.setSessions
|
|
5977
|
-
}), this.messageCtx = new
|
|
5994
|
+
}), this.messageCtx = new R({
|
|
5978
5995
|
config: this.config,
|
|
5979
5996
|
api: this.api,
|
|
5980
5997
|
sessionCtx: this.sessionCtx,
|
|
@@ -5999,12 +6016,12 @@ const j = class j {
|
|
|
5999
6016
|
config: this.config,
|
|
6000
6017
|
sessionCtx: this.sessionCtx,
|
|
6001
6018
|
messageCtx: this.messageCtx,
|
|
6002
|
-
sessionPollingIntervalSeconds:
|
|
6019
|
+
sessionPollingIntervalSeconds: S.pollingIntervalsSeconds.session
|
|
6003
6020
|
}), this.routerCtx = new Oa(this);
|
|
6004
6021
|
}
|
|
6005
6022
|
get streaming() {
|
|
6006
|
-
var e,
|
|
6007
|
-
return (e = this.messageCtx) != null && e.hasPendingAgentWork ? !0 : (
|
|
6023
|
+
var e, s;
|
|
6024
|
+
return (e = this.messageCtx) != null && e.hasPendingAgentWork ? !0 : (s = this.messageCtx) != null && s.state.get().isSendingMessage ? !1 : this.agent.streaming && this.getRequestConfig().streaming === !0;
|
|
6008
6025
|
}
|
|
6009
6026
|
/**
|
|
6010
6027
|
* The org's features narrowed by this embed's `config.features` — the
|
|
@@ -6014,28 +6031,28 @@ const j = class j {
|
|
|
6014
6031
|
return Ba(this.agent, this.getRequestConfig());
|
|
6015
6032
|
}
|
|
6016
6033
|
};
|
|
6017
|
-
|
|
6034
|
+
S.pollingIntervalsSeconds = null, S.initialize = async ({
|
|
6018
6035
|
config: e,
|
|
6019
|
-
storage:
|
|
6036
|
+
storage: s,
|
|
6020
6037
|
getClientCapabilities: o,
|
|
6021
6038
|
getRequestConfig: r
|
|
6022
6039
|
}) => {
|
|
6023
|
-
var
|
|
6024
|
-
const _ = await new
|
|
6040
|
+
var t, a;
|
|
6041
|
+
const _ = await new B({
|
|
6025
6042
|
config: e
|
|
6026
6043
|
}).getExternalWidgetConfig();
|
|
6027
6044
|
if (!_.data)
|
|
6028
|
-
throw
|
|
6045
|
+
throw b.error("widget config fetch failed", _.error), new Ha(
|
|
6029
6046
|
"config-fetch-failed",
|
|
6030
6047
|
"Failed to fetch widget config",
|
|
6031
6048
|
_.error
|
|
6032
6049
|
);
|
|
6033
|
-
return
|
|
6034
|
-
session: ((
|
|
6050
|
+
return S.pollingIntervalsSeconds = {
|
|
6051
|
+
session: ((t = _.data) == null ? void 0 : t.sessionPollingIntervalSeconds) || 10,
|
|
6035
6052
|
sessions: ((a = _.data) == null ? void 0 : a.sessionsPollingIntervalSeconds) || 60
|
|
6036
|
-
}, new
|
|
6053
|
+
}, new S({
|
|
6037
6054
|
config: e,
|
|
6038
|
-
storage:
|
|
6055
|
+
storage: s,
|
|
6039
6056
|
getClientCapabilities: o,
|
|
6040
6057
|
getRequestConfig: r,
|
|
6041
6058
|
modes: _.data.modes || [],
|
|
@@ -6046,7 +6063,7 @@ j.pollingIntervalsSeconds = null, j.initialize = async ({
|
|
|
6046
6063
|
agent: Ua(_.data)
|
|
6047
6064
|
});
|
|
6048
6065
|
};
|
|
6049
|
-
let
|
|
6066
|
+
let W = S;
|
|
6050
6067
|
function et(i, e) {
|
|
6051
6068
|
return i ? {
|
|
6052
6069
|
streaming: i.streaming && (e == null ? void 0 : e.streaming) !== !1,
|
|
@@ -6055,8 +6072,8 @@ function et(i, e) {
|
|
|
6055
6072
|
} : e;
|
|
6056
6073
|
}
|
|
6057
6074
|
class at {
|
|
6058
|
-
constructor({ attack: e, release:
|
|
6059
|
-
this.value = 0, this.attack = e, this.release =
|
|
6075
|
+
constructor({ attack: e, release: s }) {
|
|
6076
|
+
this.value = 0, this.attack = e, this.release = s;
|
|
6060
6077
|
}
|
|
6061
6078
|
next(e) {
|
|
6062
6079
|
return this.value += (e - this.value) * (e > this.value ? this.attack : this.release), this.value;
|
|
@@ -6069,17 +6086,17 @@ const I = [
|
|
|
6069
6086
|
"compact",
|
|
6070
6087
|
"sidebar",
|
|
6071
6088
|
"fullscreen"
|
|
6072
|
-
],
|
|
6089
|
+
], Va = new Set(
|
|
6073
6090
|
I
|
|
6074
6091
|
);
|
|
6075
6092
|
function X(i) {
|
|
6076
|
-
return
|
|
6093
|
+
return Va.has(i);
|
|
6077
6094
|
}
|
|
6078
6095
|
function tt(i) {
|
|
6079
6096
|
if (!Array.isArray(i)) return I;
|
|
6080
|
-
const e = [],
|
|
6097
|
+
const e = [], s = /* @__PURE__ */ new Set();
|
|
6081
6098
|
for (const o of i)
|
|
6082
|
-
!X(o) ||
|
|
6099
|
+
!X(o) || s.has(o) || (s.add(o), e.push(o));
|
|
6083
6100
|
return e.length > 0 ? e : I;
|
|
6084
6101
|
}
|
|
6085
6102
|
function st(i, e) {
|
|
@@ -6095,25 +6112,25 @@ export {
|
|
|
6095
6112
|
me as ConnectionAttemptUnavailableError,
|
|
6096
6113
|
ue as ConnectionRequestExpiredError,
|
|
6097
6114
|
at as DictationLevelSmoother,
|
|
6098
|
-
|
|
6115
|
+
z as PrimitiveState,
|
|
6099
6116
|
ie as UnreadCtx,
|
|
6100
|
-
|
|
6101
|
-
|
|
6117
|
+
W as WidgetCtx,
|
|
6118
|
+
Ha as WidgetInitializationError,
|
|
6102
6119
|
La as buildSendMessageBody,
|
|
6103
6120
|
q as genUuid,
|
|
6104
6121
|
Pa as getTranslation,
|
|
6105
6122
|
Ya as isAgentStreamKeepalive,
|
|
6106
6123
|
ke as isExhaustive,
|
|
6107
|
-
|
|
6108
|
-
|
|
6124
|
+
G as isRecord,
|
|
6125
|
+
Xa as isRtlLanguage,
|
|
6109
6126
|
qa as isSupportedLanguage,
|
|
6110
|
-
|
|
6111
|
-
|
|
6127
|
+
Qa as isTurnSteeredPart,
|
|
6128
|
+
b as log,
|
|
6112
6129
|
tt as normalizeCompanionLayouts,
|
|
6113
6130
|
et as resolveClientPresentation,
|
|
6114
6131
|
st as resolveCompanionDefaultLayout,
|
|
6115
6132
|
Na as resolveConfigContext,
|
|
6116
|
-
|
|
6133
|
+
Ea as resolveLanguage,
|
|
6117
6134
|
nt as resolveSidebarMode,
|
|
6118
6135
|
ot as resolveSidebarSide,
|
|
6119
6136
|
Ta as translate
|