@opencx/widget-core 5.0.0-beta.1 → 5.0.0-beta.2
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.cjs +9 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +969 -851
- package/dist/index.js.map +1 -1
- package/dist/src/__tests__/context/upload.ctx.spec.d.ts +2 -0
- package/dist/src/__tests__/context/upload.ctx.spec.d.ts.map +1 -0
- package/dist/src/__tests__/context/widget-ctx.conversations.spec.d.ts +1 -0
- package/dist/src/__tests__/context/widget-ctx.conversations.spec.d.ts.map +1 -0
- package/dist/src/__tests__/test-utils.d.ts +1 -0
- package/dist/src/__tests__/test-utils.d.ts.map +1 -1
- package/dist/src/api/api-caller.d.ts +2 -1
- package/dist/src/api/api-caller.d.ts.map +1 -1
- package/dist/src/context/message.ctx.d.ts +5 -0
- package/dist/src/context/message.ctx.d.ts.map +1 -1
- package/dist/src/context/router.ctx.d.ts +8 -10
- package/dist/src/context/router.ctx.d.ts.map +1 -1
- package/dist/src/context/session.ctx.d.ts +13 -1
- package/dist/src/context/session.ctx.d.ts.map +1 -1
- package/dist/src/context/upload.ctx.d.ts +23 -0
- package/dist/src/context/upload.ctx.d.ts.map +1 -0
- package/dist/src/context/widget.ctx.d.ts +6 -0
- package/dist/src/context/widget.ctx.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/translation/ar.d.ts.map +1 -1
- package/dist/src/translation/en.d.ts.map +1 -1
- package/dist/src/translation/index.d.ts +12 -0
- package/dist/src/translation/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,130 +1,131 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { v4 as
|
|
4
|
-
const
|
|
5
|
-
warn: (
|
|
6
|
-
console.warn(`${
|
|
1
|
+
import Q from "openapi-fetch";
|
|
2
|
+
import X from "lodash.isequal";
|
|
3
|
+
import { v4 as I } from "uuid";
|
|
4
|
+
const Ra = (_) => _.type === "data-keepalive", Ka = (_) => _.type === "data-turn-steered", R = "[opencx]", m = {
|
|
5
|
+
warn: (_, ...e) => {
|
|
6
|
+
console.warn(`${R} ${_}`, ...e);
|
|
7
7
|
},
|
|
8
|
-
error: (
|
|
9
|
-
console.error(`${
|
|
8
|
+
error: (_, ...e) => {
|
|
9
|
+
console.error(`${R} ${_}`, ...e);
|
|
10
10
|
}
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
},
|
|
14
|
-
const e =
|
|
15
|
-
baseUrl:
|
|
16
|
-
}),
|
|
17
|
-
onRequest:
|
|
18
|
-
onResponse:
|
|
19
|
-
onError:
|
|
11
|
+
}, ee = (_) => {
|
|
12
|
+
m.error("request failed", _.error);
|
|
13
|
+
}, ae = (_) => {
|
|
14
|
+
const e = Q({
|
|
15
|
+
baseUrl: _.baseUrl
|
|
16
|
+
}), a = {
|
|
17
|
+
onRequest: _.onRequest,
|
|
18
|
+
onResponse: _.onResponse,
|
|
19
|
+
onError: _.onError || ee
|
|
20
20
|
};
|
|
21
|
-
return e.use(
|
|
22
|
-
},
|
|
23
|
-
class
|
|
21
|
+
return e.use(a), e;
|
|
22
|
+
}, te = "/backend/widget/v5/chat/stream", se = "/backend/widget/v5/chat/{sessionId}/stream", K = (_, e, a) => `${_.replace(/\/$/, "")}${a ? e.replace("{sessionId}", encodeURIComponent(a)) : e}`;
|
|
23
|
+
class L {
|
|
24
24
|
constructor({ config: e }) {
|
|
25
|
-
var
|
|
26
|
-
this.userToken = null, this.constructClientOptions = (
|
|
27
|
-
const
|
|
25
|
+
var i, l;
|
|
26
|
+
this.userToken = null, this.constructClientOptions = (o) => {
|
|
27
|
+
const t = this.config.apiUrl || "https://api.open.cx", s = {
|
|
28
28
|
"X-Bot-Token": this.config.token,
|
|
29
29
|
"Content-Type": "application/json",
|
|
30
30
|
Accept: "application/json",
|
|
31
|
-
Authorization:
|
|
31
|
+
Authorization: o ? `Bearer ${o}` : void 0
|
|
32
32
|
};
|
|
33
|
-
return { baseUrl:
|
|
33
|
+
return { baseUrl: t, headers: s };
|
|
34
34
|
}, this.createOpenAPIClient = ({
|
|
35
|
-
baseUrl:
|
|
36
|
-
headers:
|
|
37
|
-
}) =>
|
|
38
|
-
baseUrl:
|
|
35
|
+
baseUrl: o,
|
|
36
|
+
headers: t
|
|
37
|
+
}) => ae({
|
|
38
|
+
baseUrl: o,
|
|
39
39
|
onRequest: ({ request: s }) => {
|
|
40
|
-
Object.entries(
|
|
40
|
+
Object.entries(t).forEach(([r, c]) => {
|
|
41
41
|
c && s.headers.set(r, c);
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
|
-
}), this.setAuthToken = (
|
|
45
|
-
this.userToken =
|
|
46
|
-
const { baseUrl:
|
|
47
|
-
this.client = this.createOpenAPIClient({ baseUrl:
|
|
44
|
+
}), this.setAuthToken = (o) => {
|
|
45
|
+
this.userToken = o;
|
|
46
|
+
const { baseUrl: t, headers: s } = this.constructClientOptions(o);
|
|
47
|
+
this.client = this.createOpenAPIClient({ baseUrl: t, headers: s });
|
|
48
48
|
}, this.getStreamAuthContext = () => {
|
|
49
|
-
const { baseUrl:
|
|
50
|
-
for (const [r, c] of Object.entries(
|
|
49
|
+
const { baseUrl: o, headers: t } = this.constructClientOptions(this.userToken), s = {};
|
|
50
|
+
for (const [r, c] of Object.entries(t))
|
|
51
51
|
typeof c == "string" && (["content-type", "accept"].includes(r.toLowerCase()) || (s[r] = c));
|
|
52
|
-
return { baseUrl:
|
|
52
|
+
return { baseUrl: o, headers: s };
|
|
53
53
|
}, this.getStreamTransportOptions = () => {
|
|
54
|
-
const { baseUrl:
|
|
54
|
+
const { baseUrl: o, headers: t } = this.getStreamAuthContext();
|
|
55
55
|
return {
|
|
56
|
-
api:
|
|
57
|
-
reconnectApi: (s) =>
|
|
58
|
-
headers:
|
|
56
|
+
api: K(o, te),
|
|
57
|
+
reconnectApi: (s) => K(o, se, s),
|
|
58
|
+
headers: t
|
|
59
59
|
};
|
|
60
|
-
}, this.stopStream = async (
|
|
61
|
-
const { response:
|
|
60
|
+
}, this.stopStream = async (o) => {
|
|
61
|
+
const { response: t } = await this.client.POST(
|
|
62
62
|
"/backend/widget/v5/chat/{sessionId}/stop",
|
|
63
|
-
{ params: { path: { sessionId:
|
|
63
|
+
{ params: { path: { sessionId: o } } }
|
|
64
64
|
);
|
|
65
|
-
if (!
|
|
66
|
-
throw new Error(`Failed to stop stream: ${
|
|
67
|
-
}, this.getAgentTurnMessages = async (
|
|
68
|
-
const { data:
|
|
65
|
+
if (!t.ok)
|
|
66
|
+
throw new Error(`Failed to stop stream: ${t.status}`);
|
|
67
|
+
}, this.getAgentTurnMessages = async (o) => {
|
|
68
|
+
const { data: t, response: s } = await this.client.GET(
|
|
69
69
|
"/backend/widget/v5/chat/{sessionId}/messages",
|
|
70
|
-
{ params: { path: { sessionId:
|
|
70
|
+
{ params: { path: { sessionId: o } } }
|
|
71
71
|
);
|
|
72
|
-
return
|
|
72
|
+
return t || (m.warn("agent turn messages fetch failed", s.status), null);
|
|
73
73
|
}, this.createDictationSession = async ({
|
|
74
|
-
language:
|
|
74
|
+
language: o
|
|
75
75
|
}) => {
|
|
76
|
-
const { data:
|
|
76
|
+
const { data: t, response: s } = await this.client.POST(
|
|
77
77
|
"/backend/widget/v5/dictation/sessions",
|
|
78
|
-
{ body:
|
|
78
|
+
{ body: o ? { language: o } : {} }
|
|
79
79
|
);
|
|
80
|
-
if (!
|
|
80
|
+
if (!t)
|
|
81
81
|
throw new Error(`Failed to start dictation: ${s.status}`);
|
|
82
|
-
return
|
|
82
|
+
return t;
|
|
83
83
|
}, this.getExternalWidgetConfig = async () => await this.client.GET("/backend/widget/v2/config", {
|
|
84
84
|
params: {
|
|
85
85
|
header: { "x-bot-token": this.config.token }
|
|
86
86
|
}
|
|
87
|
-
}), this.sendMessage = async (
|
|
88
|
-
body:
|
|
89
|
-
signal:
|
|
90
|
-
}), this.createUnverifiedContact = async (
|
|
87
|
+
}), this.sendMessage = async (o, t) => await this.client.POST("/backend/widget/v2/chat/send", {
|
|
88
|
+
body: o,
|
|
89
|
+
signal: t
|
|
90
|
+
}), this.createUnverifiedContact = async (o) => await this.client.POST(
|
|
91
91
|
"/backend/widget/v2/contact/create-unverified",
|
|
92
92
|
{
|
|
93
93
|
params: { header: { "x-bot-token": this.config.token } },
|
|
94
|
-
body:
|
|
94
|
+
body: o
|
|
95
95
|
}
|
|
96
|
-
), this.createSession = async (
|
|
97
|
-
body:
|
|
96
|
+
), this.createSession = async (o, t) => await this.client.POST("/backend/widget/v2/create-session", {
|
|
97
|
+
body: o,
|
|
98
|
+
signal: t
|
|
98
99
|
}), this.pollSessionAndHistory = async ({
|
|
99
|
-
sessionId:
|
|
100
|
-
abortSignal:
|
|
100
|
+
sessionId: o,
|
|
101
|
+
abortSignal: t
|
|
101
102
|
}) => await this.client.GET("/backend/widget/v2/poll/{sessionId}", {
|
|
102
|
-
params: { path: { sessionId:
|
|
103
|
-
signal:
|
|
103
|
+
params: { path: { sessionId: o } },
|
|
104
|
+
signal: t
|
|
104
105
|
}), this.getSessions = async ({
|
|
105
|
-
cursor:
|
|
106
|
-
filters:
|
|
106
|
+
cursor: o,
|
|
107
|
+
filters: t,
|
|
107
108
|
abortSignal: s
|
|
108
109
|
}) => await this.client.GET("/backend/widget/v2/sessions", {
|
|
109
110
|
params: {
|
|
110
111
|
query: {
|
|
111
|
-
offset:
|
|
112
|
-
filters: JSON.stringify(
|
|
112
|
+
offset: o,
|
|
113
|
+
filters: JSON.stringify(t)
|
|
113
114
|
}
|
|
114
115
|
},
|
|
115
116
|
signal: s
|
|
116
117
|
}), this.uploadFile = async ({
|
|
117
|
-
file:
|
|
118
|
-
abortSignal:
|
|
118
|
+
file: o,
|
|
119
|
+
abortSignal: t,
|
|
119
120
|
onProgress: s
|
|
120
121
|
}) => new Promise((r, c) => {
|
|
121
|
-
var
|
|
122
|
+
var j;
|
|
122
123
|
const p = new FormData();
|
|
123
|
-
p.append("file",
|
|
124
|
+
p.append("file", o);
|
|
124
125
|
const d = new XMLHttpRequest();
|
|
125
|
-
if (
|
|
126
|
+
if (t && (t.addEventListener("abort", () => {
|
|
126
127
|
d.abort(), c(new DOMException("Aborted", "AbortError"));
|
|
127
|
-
}),
|
|
128
|
+
}), t.aborted)) {
|
|
128
129
|
c(new DOMException("Aborted", "AbortError"));
|
|
129
130
|
return;
|
|
130
131
|
}
|
|
@@ -148,135 +149,135 @@ class K {
|
|
|
148
149
|
}), d.addEventListener("timeout", () => {
|
|
149
150
|
c(new Error("Upload timed out"));
|
|
150
151
|
});
|
|
151
|
-
const { baseUrl:
|
|
152
|
-
d.open("POST",
|
|
153
|
-
}), this.vote = async (
|
|
154
|
-
body:
|
|
155
|
-
signal:
|
|
156
|
-
}), this.createStateCheckpoint = async (
|
|
157
|
-
body:
|
|
158
|
-
}), this.submitCsat = async (
|
|
159
|
-
const { baseUrl:
|
|
152
|
+
const { baseUrl: u } = this.constructClientOptions(this.userToken), h = `${u}/backend/widget/v2/upload`;
|
|
153
|
+
d.open("POST", h), d.setRequestHeader("X-Bot-Token", this.config.token), this.userToken ?? ((j = this.config.user) == null ? void 0 : j.token) ? d.setRequestHeader("Authorization", `Bearer ${this.userToken}`) : m.error("user token not set"), d.send(p);
|
|
154
|
+
}), this.vote = async (o) => await this.client.POST("/backend/widget/v2/chat/vote", { body: o }), this.resolveSession = async (o, t) => await this.client.POST("/backend/widget/v2/session/resolve", {
|
|
155
|
+
body: o,
|
|
156
|
+
signal: t
|
|
157
|
+
}), this.createStateCheckpoint = async (o) => await this.client.POST("/backend/widget/v2/checkpoint", {
|
|
158
|
+
body: o
|
|
159
|
+
}), this.submitCsat = async (o) => await this.client.POST("/backend/widget/v2/submit-csat", { body: o }), this.config = e, this.userToken = ((i = e.user) == null ? void 0 : i.token) || null;
|
|
160
|
+
const { baseUrl: a, headers: n } = this.constructClientOptions(
|
|
160
161
|
(l = e.user) == null ? void 0 : l.token
|
|
161
162
|
);
|
|
162
|
-
this.client = this.createOpenAPIClient({ baseUrl:
|
|
163
|
+
this.client = this.createOpenAPIClient({ baseUrl: a, headers: n });
|
|
163
164
|
}
|
|
164
165
|
}
|
|
165
|
-
function
|
|
166
|
-
|
|
166
|
+
function ne(_, e) {
|
|
167
|
+
m.error(`missing case for ${_} in ${e}`);
|
|
167
168
|
}
|
|
168
|
-
class
|
|
169
|
+
class w {
|
|
169
170
|
constructor(e) {
|
|
170
|
-
this.subscribers = /* @__PURE__ */ new Set(), this.get = () => this.state, this.set = (
|
|
171
|
-
|
|
172
|
-
}, this.setPartial = (
|
|
173
|
-
if (
|
|
174
|
-
const
|
|
175
|
-
this.set(
|
|
171
|
+
this.subscribers = /* @__PURE__ */ new Set(), this.get = () => this.state, this.set = (a) => {
|
|
172
|
+
X(this.state, a) || (this.state = a, this.notifySubscribers(a));
|
|
173
|
+
}, this.setPartial = (a) => {
|
|
174
|
+
if (a == null) return;
|
|
175
|
+
const n = { ...this.state, ...a };
|
|
176
|
+
this.set(n);
|
|
176
177
|
}, this.reset = () => {
|
|
177
178
|
this.set(this.initialState);
|
|
178
|
-
}, this.notifySubscribers = (
|
|
179
|
-
Array.from(this.subscribers).forEach((
|
|
179
|
+
}, this.notifySubscribers = (a) => {
|
|
180
|
+
Array.from(this.subscribers).forEach((i) => {
|
|
180
181
|
try {
|
|
181
|
-
|
|
182
|
+
i(a);
|
|
182
183
|
} catch (l) {
|
|
183
|
-
|
|
184
|
+
m.error("state subscriber threw", l);
|
|
184
185
|
}
|
|
185
186
|
});
|
|
186
|
-
}, this.subscribe = (
|
|
187
|
-
this.subscribers.delete(
|
|
187
|
+
}, this.subscribe = (a) => (this.subscribers.add(a), () => {
|
|
188
|
+
this.subscribers.delete(a);
|
|
188
189
|
}), this.state = e, this.initialState = e;
|
|
189
190
|
}
|
|
190
191
|
}
|
|
191
192
|
class V {
|
|
192
193
|
constructor() {
|
|
193
|
-
this.state = new
|
|
194
|
+
this.state = new w({
|
|
194
195
|
isPolling: !1,
|
|
195
196
|
isError: !1
|
|
196
197
|
}), this.abortController = new AbortController(), this.reset = () => {
|
|
197
198
|
var e;
|
|
198
199
|
this.abortController.abort("Resetting poller"), (e = this.stopPolling) == null || e.call(this), this.stopPolling = null;
|
|
199
|
-
}, this.stopPolling = null, this.startPolling = (e,
|
|
200
|
+
}, this.stopPolling = null, this.startPolling = (e, a) => {
|
|
200
201
|
if (this.stopPolling) return;
|
|
201
|
-
const
|
|
202
|
+
const n = [], i = async () => {
|
|
202
203
|
this.abortController = new AbortController(), this.state.setPartial({ isPolling: !0 });
|
|
203
204
|
try {
|
|
204
205
|
await e(this.abortController.signal);
|
|
205
206
|
} catch (l) {
|
|
206
207
|
if (this.abortController.signal.aborted)
|
|
207
208
|
return;
|
|
208
|
-
|
|
209
|
+
m.error("failed to poll", l), this.state.setPartial({ isError: !0 });
|
|
209
210
|
} finally {
|
|
210
211
|
this.state.setPartial({ isPolling: !1 });
|
|
211
212
|
}
|
|
212
|
-
this.abortController.signal.aborted ||
|
|
213
|
+
this.abortController.signal.aborted || n.push(setTimeout(i, a));
|
|
213
214
|
};
|
|
214
|
-
|
|
215
|
-
|
|
215
|
+
i(), this.stopPolling = () => {
|
|
216
|
+
n.forEach(clearTimeout), this.state.reset();
|
|
216
217
|
};
|
|
217
218
|
};
|
|
218
219
|
}
|
|
219
220
|
}
|
|
220
|
-
function H(
|
|
221
|
+
function H(_) {
|
|
221
222
|
try {
|
|
222
|
-
const e =
|
|
223
|
-
return e instanceof Promise ? e.then((
|
|
223
|
+
const e = _();
|
|
224
|
+
return e instanceof Promise ? e.then((a) => ({ data: a })).catch((a) => ({ error: a })) : { data: e };
|
|
224
225
|
} catch (e) {
|
|
225
226
|
return { error: e };
|
|
226
227
|
}
|
|
227
228
|
}
|
|
228
|
-
class
|
|
229
|
+
class oe {
|
|
229
230
|
constructor({
|
|
230
231
|
api: e,
|
|
231
|
-
config:
|
|
232
|
-
sessionCtx:
|
|
233
|
-
messageCtx:
|
|
232
|
+
config: a,
|
|
233
|
+
sessionCtx: n,
|
|
234
|
+
messageCtx: i,
|
|
234
235
|
sessionPollingIntervalSeconds: l
|
|
235
236
|
}) {
|
|
236
237
|
this.poller = new V(), this.fetchSessionAndFullHistoryAbortController = new AbortController(), this.reconcileAbortController = new AbortController(), this.reconcilingSessionId = null, this.registerPolling = () => {
|
|
237
|
-
this.sessionCtx.sessionState.subscribe(({ session:
|
|
238
|
-
|
|
239
|
-
this.fetchSessionAndHistory({ sessionId:
|
|
238
|
+
this.sessionCtx.sessionState.subscribe(({ session: o }) => {
|
|
239
|
+
o != null && o.id ? this.poller.startPolling(async (t) => {
|
|
240
|
+
this.fetchSessionAndHistory({ sessionId: o.id, abortSignal: t });
|
|
240
241
|
}, this.sessionPollingIntervalSeconds * 1e3) : this.poller.reset();
|
|
241
|
-
}), this.sessionCtx.sessionState.subscribe(({ session:
|
|
242
|
-
if (
|
|
242
|
+
}), this.sessionCtx.sessionState.subscribe(({ session: o }) => {
|
|
243
|
+
if (o != null && o.id && !o.isOpened)
|
|
243
244
|
try {
|
|
244
245
|
this.fetchSessionAndFullHistoryAbortController = new AbortController(), this.fetchSessionAndHistory({
|
|
245
|
-
sessionId:
|
|
246
|
+
sessionId: o.id,
|
|
246
247
|
abortSignal: this.fetchSessionAndFullHistoryAbortController.signal
|
|
247
248
|
});
|
|
248
|
-
} catch (
|
|
249
|
-
this.fetchSessionAndFullHistoryAbortController.signal.aborted ||
|
|
249
|
+
} catch (t) {
|
|
250
|
+
this.fetchSessionAndFullHistoryAbortController.signal.aborted || m.error("failed to fetch session and full history", t);
|
|
250
251
|
}
|
|
251
252
|
else
|
|
252
253
|
this.fetchSessionAndFullHistoryAbortController.abort();
|
|
253
|
-
}), this.sessionCtx.sessionState.subscribe(({ session:
|
|
254
|
-
this.reconcilingSessionId !== null && (
|
|
254
|
+
}), this.sessionCtx.sessionState.subscribe(({ session: o }) => {
|
|
255
|
+
this.reconcilingSessionId !== null && (o == null ? void 0 : o.id) !== this.reconcilingSessionId && this.reconcileAbortController.abort();
|
|
255
256
|
});
|
|
256
|
-
}, this.reconcileAfterStream = async (
|
|
257
|
+
}, this.reconcileAfterStream = async (o) => {
|
|
257
258
|
this.reconcileAbortController.abort(), this.reconcileAbortController = new AbortController();
|
|
258
|
-
const { signal:
|
|
259
|
-
this.reconcilingSessionId =
|
|
259
|
+
const { signal: t } = this.reconcileAbortController;
|
|
260
|
+
this.reconcilingSessionId = o;
|
|
260
261
|
try {
|
|
261
|
-
await this.fetchSessionAndHistory({ sessionId:
|
|
262
|
+
await this.fetchSessionAndHistory({ sessionId: o, abortSignal: t });
|
|
262
263
|
} catch (s) {
|
|
263
|
-
if (!
|
|
264
|
+
if (!t.aborted) throw s;
|
|
264
265
|
} finally {
|
|
265
|
-
this.reconcilingSessionId ===
|
|
266
|
+
this.reconcilingSessionId === o && (this.reconcilingSessionId = null);
|
|
266
267
|
}
|
|
267
268
|
}, this.fetchSessionAndHistory = async ({
|
|
268
|
-
sessionId:
|
|
269
|
-
abortSignal:
|
|
269
|
+
sessionId: o,
|
|
270
|
+
abortSignal: t
|
|
270
271
|
}) => {
|
|
271
272
|
const s = this.messageCtx.state.get().messages.length === 0;
|
|
272
273
|
s && this.messageCtx.state.setPartial({ isInitialFetchLoading: !0 });
|
|
273
274
|
const { data: r } = await this.api.pollSessionAndHistory({
|
|
274
|
-
sessionId:
|
|
275
|
-
abortSignal:
|
|
275
|
+
sessionId: o,
|
|
276
|
+
abortSignal: t
|
|
276
277
|
});
|
|
277
278
|
if (r != null && r.session && (this.sessionCtx.sessionState.setPartial({ session: r.session }), this.sessionCtx.setSessions([r.session])), r != null && r.history && r.history.length > 0) {
|
|
278
279
|
const c = this.messageCtx.state.get().messages, p = r.history.map(this.mapHistoryToMessage).filter((d) => d !== null).filter(
|
|
279
|
-
(d) => !c.some((
|
|
280
|
+
(d) => !c.some((u) => u.id === d.id)
|
|
280
281
|
);
|
|
281
282
|
if (p.length > 0)
|
|
282
283
|
if (this.messageCtx.state.setPartial({
|
|
@@ -290,43 +291,43 @@ class ne {
|
|
|
290
291
|
this.messageCtx.dispatchToOnMessageReceivedHook(d);
|
|
291
292
|
}
|
|
292
293
|
this.messageCtx.state.get().isInitialFetchLoading && this.messageCtx.state.setPartial({ isInitialFetchLoading: !1 });
|
|
293
|
-
}, this.mapHistoryToMessage = (
|
|
294
|
+
}, this.mapHistoryToMessage = (o) => {
|
|
294
295
|
var s;
|
|
295
|
-
const
|
|
296
|
-
id:
|
|
297
|
-
timestamp:
|
|
298
|
-
attachments:
|
|
296
|
+
const t = {
|
|
297
|
+
id: o.publicId,
|
|
298
|
+
timestamp: o.sentAt || "",
|
|
299
|
+
attachments: o.attachments || void 0
|
|
299
300
|
};
|
|
300
|
-
if (
|
|
301
|
+
if (o.sender.kind === "user")
|
|
301
302
|
return {
|
|
302
|
-
...
|
|
303
|
+
...t,
|
|
303
304
|
type: "USER",
|
|
304
|
-
content:
|
|
305
|
+
content: o.content.text || "",
|
|
305
306
|
// Backend field name (schema.ts) → widget vocabulary.
|
|
306
|
-
markedElements:
|
|
307
|
+
markedElements: o.pickedElements
|
|
307
308
|
};
|
|
308
|
-
if (
|
|
309
|
+
if (o.sender.kind === "agent")
|
|
309
310
|
return {
|
|
310
|
-
...
|
|
311
|
+
...t,
|
|
311
312
|
type: "AGENT",
|
|
312
313
|
component: "agent_message",
|
|
313
314
|
data: {
|
|
314
|
-
message:
|
|
315
|
+
message: o.content.text || ""
|
|
315
316
|
},
|
|
316
317
|
agent: {
|
|
317
|
-
name:
|
|
318
|
+
name: o.sender.name || "",
|
|
318
319
|
// Do not set avatarUrl from config here... let it be taken from the config at render time
|
|
319
320
|
// Only set avatar url from the backend's response
|
|
320
|
-
avatarUrl:
|
|
321
|
-
avatar:
|
|
321
|
+
avatarUrl: o.sender.avatar || null,
|
|
322
|
+
avatar: o.sender.avatar || null,
|
|
322
323
|
id: null,
|
|
323
324
|
isAi: !1
|
|
324
325
|
}
|
|
325
326
|
};
|
|
326
|
-
if (
|
|
327
|
-
const r =
|
|
327
|
+
if (o.sender.kind === "ai") {
|
|
328
|
+
const r = o.actionCalls && o.actionCalls.length > 0 ? o.actionCalls[o.actionCalls.length - 1] : void 0;
|
|
328
329
|
return {
|
|
329
|
-
...
|
|
330
|
+
...t,
|
|
330
331
|
type: "AI",
|
|
331
332
|
component: "bot_message",
|
|
332
333
|
agent: {
|
|
@@ -338,7 +339,7 @@ class ne {
|
|
|
338
339
|
avatar: null
|
|
339
340
|
},
|
|
340
341
|
data: {
|
|
341
|
-
message:
|
|
342
|
+
message: o.content.text || "",
|
|
342
343
|
action: r ? {
|
|
343
344
|
name: r.actionName,
|
|
344
345
|
data: this.extractActionResult(r)
|
|
@@ -346,79 +347,79 @@ class ne {
|
|
|
346
347
|
}
|
|
347
348
|
};
|
|
348
349
|
}
|
|
349
|
-
if (
|
|
350
|
-
const r = this.constructSystemMessage(
|
|
350
|
+
if (o.sender.kind === "system") {
|
|
351
|
+
const r = this.constructSystemMessage(o);
|
|
351
352
|
return r === null ? null : { ...r };
|
|
352
353
|
}
|
|
353
354
|
return null;
|
|
354
|
-
}, this.constructSystemMessage = (
|
|
355
|
-
if (!
|
|
356
|
-
switch (
|
|
355
|
+
}, this.constructSystemMessage = (o) => {
|
|
356
|
+
if (!o || !o.systemMessagePayload) return null;
|
|
357
|
+
switch (o.systemMessagePayload.type) {
|
|
357
358
|
case "state_checkpoint":
|
|
358
359
|
return {
|
|
359
|
-
id:
|
|
360
|
+
id: o.publicId,
|
|
360
361
|
type: "SYSTEM",
|
|
361
362
|
subtype: "state_checkpoint",
|
|
362
|
-
data: { payload:
|
|
363
|
-
timestamp:
|
|
363
|
+
data: { payload: o.systemMessagePayload.payload },
|
|
364
|
+
timestamp: o.sentAt || "",
|
|
364
365
|
attachments: void 0
|
|
365
366
|
};
|
|
366
367
|
case "csat_requested":
|
|
367
368
|
return {
|
|
368
|
-
id:
|
|
369
|
+
id: o.publicId,
|
|
369
370
|
type: "SYSTEM",
|
|
370
371
|
subtype: "csat_requested",
|
|
371
372
|
data: { payload: void 0 },
|
|
372
|
-
timestamp:
|
|
373
|
+
timestamp: o.sentAt || "",
|
|
373
374
|
attachments: void 0
|
|
374
375
|
};
|
|
375
376
|
case "csat_submitted":
|
|
376
377
|
return {
|
|
377
|
-
id:
|
|
378
|
+
id: o.publicId,
|
|
378
379
|
type: "SYSTEM",
|
|
379
380
|
subtype: "csat_submitted",
|
|
380
381
|
data: {
|
|
381
382
|
payload: {
|
|
382
|
-
score:
|
|
383
|
-
feedback:
|
|
383
|
+
score: o.systemMessagePayload.payload.score ?? void 0,
|
|
384
|
+
feedback: o.systemMessagePayload.payload.feedback ?? void 0
|
|
384
385
|
}
|
|
385
386
|
},
|
|
386
|
-
timestamp:
|
|
387
|
+
timestamp: o.sentAt || "",
|
|
387
388
|
attachments: void 0
|
|
388
389
|
};
|
|
389
390
|
case "none":
|
|
390
391
|
return null;
|
|
391
392
|
default:
|
|
392
|
-
return
|
|
393
|
-
|
|
393
|
+
return ne(
|
|
394
|
+
o.systemMessagePayload,
|
|
394
395
|
this.constructSystemMessage.name
|
|
395
396
|
), null;
|
|
396
397
|
}
|
|
397
|
-
}, this.extractActionResult = (
|
|
398
|
-
const
|
|
399
|
-
if (
|
|
400
|
-
if ("responseBodyText" in
|
|
401
|
-
const s =
|
|
398
|
+
}, this.extractActionResult = (o) => {
|
|
399
|
+
const t = o.result;
|
|
400
|
+
if (t === null || typeof t != "object") return t;
|
|
401
|
+
if ("responseBodyText" in t && typeof t.responseBodyText == "string") {
|
|
402
|
+
const s = t.responseBodyText, r = H(() => JSON.parse(s)).data;
|
|
402
403
|
if (r) return r;
|
|
403
404
|
}
|
|
404
|
-
return
|
|
405
|
-
}, this.api = e, this.config =
|
|
405
|
+
return o.result;
|
|
406
|
+
}, this.api = e, this.config = a, this.sessionCtx = n, this.messageCtx = i, this.sessionPollingIntervalSeconds = l, this.registerPolling();
|
|
406
407
|
}
|
|
407
408
|
}
|
|
408
|
-
class
|
|
409
|
+
class ie {
|
|
409
410
|
constructor({
|
|
410
411
|
config: e,
|
|
411
|
-
api:
|
|
412
|
-
storageCtx:
|
|
412
|
+
api: a,
|
|
413
|
+
storageCtx: n
|
|
413
414
|
}) {
|
|
414
|
-
var
|
|
415
|
+
var i;
|
|
415
416
|
this.shouldCollectData = () => {
|
|
416
417
|
var l;
|
|
417
418
|
return !!(!((l = this.state.get().contact) != null && l.token) && this.config.collectUserData);
|
|
418
419
|
}, this.autoCreateUnverifiedUserIfNotExists = async () => {
|
|
419
|
-
var l,
|
|
420
|
+
var l, o, t, s, r, c, p, d, u, g, h, v, j, b;
|
|
420
421
|
if (!((l = this.config.user) != null && l.token)) {
|
|
421
|
-
if (this.config.collectUserData && !((
|
|
422
|
+
if (this.config.collectUserData && !((t = (o = this.config.user) == null ? void 0 : o.data) != null && t.email)) {
|
|
422
423
|
if ((s = this.config.extraDataCollectionFields) != null && s.length)
|
|
423
424
|
return;
|
|
424
425
|
const f = await ((r = this.storageCtx) == null ? void 0 : r.getContactToken());
|
|
@@ -433,49 +434,49 @@ class oe {
|
|
|
433
434
|
}
|
|
434
435
|
}
|
|
435
436
|
await this.createUnverifiedContact({
|
|
436
|
-
email: (
|
|
437
|
-
non_verified_name: (
|
|
438
|
-
non_verified_custom_data: (b = (
|
|
437
|
+
email: (g = (u = this.config.user) == null ? void 0 : u.data) == null ? void 0 : g.email,
|
|
438
|
+
non_verified_name: (v = (h = this.config.user) == null ? void 0 : h.data) == null ? void 0 : v.name,
|
|
439
|
+
non_verified_custom_data: (b = (j = this.config.user) == null ? void 0 : j.data) == null ? void 0 : b.customData
|
|
439
440
|
});
|
|
440
441
|
}
|
|
441
|
-
}, this.createUnverifiedContact = async (l,
|
|
442
|
-
this.state.setPartial({ extraCollectedData:
|
|
442
|
+
}, this.createUnverifiedContact = async (l, o) => {
|
|
443
|
+
this.state.setPartial({ extraCollectedData: o });
|
|
443
444
|
try {
|
|
444
445
|
this.state.setPartial({
|
|
445
446
|
isCreatingUnverifiedContact: !0,
|
|
446
447
|
isErrorCreatingUnverifiedContact: !1
|
|
447
448
|
});
|
|
448
|
-
const { data:
|
|
449
|
-
|
|
450
|
-
} catch (
|
|
451
|
-
this.state.setPartial({ isErrorCreatingUnverifiedContact: !0 }),
|
|
452
|
-
_e:
|
|
449
|
+
const { data: t } = await this.api.createUnverifiedContact(l);
|
|
450
|
+
t != null && t.token ? await this.setUnverifiedContact(t.token) : this.state.setPartial({ isErrorCreatingUnverifiedContact: !0 });
|
|
451
|
+
} catch (t) {
|
|
452
|
+
this.state.setPartial({ isErrorCreatingUnverifiedContact: !0 }), m.error("failed to create an unverified contact", {
|
|
453
|
+
_e: t instanceof Error ? t.message : String(t)
|
|
453
454
|
});
|
|
454
455
|
} finally {
|
|
455
456
|
this.state.setPartial({ isCreatingUnverifiedContact: !1 });
|
|
456
457
|
}
|
|
457
458
|
}, this.recoverFromStaleToken = async () => {
|
|
458
|
-
var l,
|
|
459
|
+
var l, o, t, s, r, c, p, d, u, g;
|
|
459
460
|
if ((l = this.config.user) != null && l.token) return !1;
|
|
460
461
|
this.api.setAuthToken(""), this.state.setPartial({ contact: null });
|
|
461
462
|
try {
|
|
462
|
-
await ((
|
|
463
|
-
} catch (
|
|
464
|
-
|
|
465
|
-
error:
|
|
463
|
+
await ((o = this.storageCtx) == null ? void 0 : o.clearContactToken()), await ((t = this.storageCtx) == null ? void 0 : t.clearActiveSessionId());
|
|
464
|
+
} catch (h) {
|
|
465
|
+
m.warn("failed to clear a stale contact token", {
|
|
466
|
+
error: h instanceof Error ? h.message : String(h)
|
|
466
467
|
});
|
|
467
468
|
}
|
|
468
469
|
return await this.createUnverifiedContact({
|
|
469
470
|
email: (r = (s = this.config.user) == null ? void 0 : s.data) == null ? void 0 : r.email,
|
|
470
471
|
non_verified_name: (p = (c = this.config.user) == null ? void 0 : c.data) == null ? void 0 : p.name,
|
|
471
|
-
non_verified_custom_data: (
|
|
472
|
-
}), !!((
|
|
472
|
+
non_verified_custom_data: (u = (d = this.config.user) == null ? void 0 : d.data) == null ? void 0 : u.customData
|
|
473
|
+
}), !!((g = this.state.get().contact) != null && g.token);
|
|
473
474
|
}, this.setUnverifiedContact = async (l) => {
|
|
474
475
|
var s, r, c, p;
|
|
475
|
-
const
|
|
476
|
-
this.api.setAuthToken(l), await ((c = this.storageCtx) == null ? void 0 : c.setContactToken(l)), await ((p = this.storageCtx) == null ? void 0 : p.setExternalContactId(
|
|
477
|
-
}, this.config = e, this.storageCtx =
|
|
478
|
-
contact: (
|
|
476
|
+
const o = await ((s = this.storageCtx) == null ? void 0 : s.getExternalContactId()), t = ((r = this.config.user) == null ? void 0 : r.externalId) || o || I();
|
|
477
|
+
this.api.setAuthToken(l), await ((c = this.storageCtx) == null ? void 0 : c.setContactToken(l)), await ((p = this.storageCtx) == null ? void 0 : p.setExternalContactId(t)), this.state.setPartial({ contact: { token: l, externalId: t } });
|
|
478
|
+
}, this.config = e, this.storageCtx = n, this.api = a, this.state = new w({
|
|
479
|
+
contact: (i = e.user) != null && i.token ? {
|
|
479
480
|
token: e.user.token,
|
|
480
481
|
// Set optional externalId from config... not local storage
|
|
481
482
|
externalId: e.user.externalId
|
|
@@ -486,48 +487,97 @@ class oe {
|
|
|
486
487
|
}), this.autoCreateUnverifiedUserIfNotExists();
|
|
487
488
|
}
|
|
488
489
|
}
|
|
489
|
-
|
|
490
|
-
|
|
490
|
+
class re {
|
|
491
|
+
constructor(e) {
|
|
492
|
+
this.api = e, this.state = new w([]), this.controllers = /* @__PURE__ */ new Map(), this.appendFiles = (a) => {
|
|
493
|
+
const n = a.map(
|
|
494
|
+
(i) => ({
|
|
495
|
+
file: i,
|
|
496
|
+
id: I(),
|
|
497
|
+
status: "pending",
|
|
498
|
+
progress: 0
|
|
499
|
+
})
|
|
500
|
+
);
|
|
501
|
+
this.state.set([...this.state.get(), ...n]), n.forEach((i) => void this.upload(i));
|
|
502
|
+
}, this.cancel = (a) => {
|
|
503
|
+
var n;
|
|
504
|
+
(n = this.controllers.get(a)) == null || n.abort(), this.controllers.delete(a), this.state.set(this.state.get().filter((i) => i.id !== a));
|
|
505
|
+
}, this.reset = () => {
|
|
506
|
+
this.controllers.forEach((a) => a.abort()), this.controllers.clear(), this.state.reset();
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
update(e, a) {
|
|
510
|
+
this.state.set(
|
|
511
|
+
this.state.get().map((n) => n.id === e ? { ...n, ...a } : n)
|
|
512
|
+
);
|
|
513
|
+
}
|
|
514
|
+
async upload(e) {
|
|
515
|
+
const a = new AbortController();
|
|
516
|
+
this.controllers.set(e.id, a), this.update(e.id, { status: "uploading" });
|
|
517
|
+
try {
|
|
518
|
+
const n = await this.api.uploadFile({
|
|
519
|
+
file: e.file,
|
|
520
|
+
abortSignal: a.signal,
|
|
521
|
+
onProgress: (i) => this.update(e.id, { progress: i })
|
|
522
|
+
});
|
|
523
|
+
this.update(e.id, {
|
|
524
|
+
status: "success",
|
|
525
|
+
fileUrl: n.fileUrl,
|
|
526
|
+
progress: 100
|
|
527
|
+
});
|
|
528
|
+
} catch (n) {
|
|
529
|
+
a.signal.aborted || this.update(e.id, {
|
|
530
|
+
status: "error",
|
|
531
|
+
progress: 0,
|
|
532
|
+
error: n instanceof Error ? n.message : "Upload failed"
|
|
533
|
+
});
|
|
534
|
+
} finally {
|
|
535
|
+
this.controllers.delete(e.id);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
function z() {
|
|
540
|
+
return I();
|
|
491
541
|
}
|
|
492
|
-
class
|
|
542
|
+
class _e {
|
|
493
543
|
constructor({
|
|
494
544
|
api: e,
|
|
495
|
-
sessionCtx:
|
|
496
|
-
messageCtx:
|
|
545
|
+
sessionCtx: a,
|
|
546
|
+
messageCtx: n
|
|
497
547
|
}) {
|
|
498
|
-
this.submitCsat = async (
|
|
548
|
+
this.submitCsat = async (i) => {
|
|
499
549
|
var r;
|
|
500
550
|
const l = (r = this.sessionCtx.sessionState.get().session) == null ? void 0 : r.id;
|
|
501
551
|
if (!l)
|
|
502
552
|
return { data: null, error: "No session id found" };
|
|
503
|
-
const
|
|
553
|
+
const o = z();
|
|
504
554
|
this.messageCtx.state.setPartial({
|
|
505
555
|
messages: [
|
|
506
556
|
...this.messageCtx.state.get().messages,
|
|
507
557
|
{
|
|
508
|
-
id:
|
|
558
|
+
id: o,
|
|
509
559
|
type: "SYSTEM",
|
|
510
560
|
subtype: "csat_submitted",
|
|
511
561
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
512
562
|
data: {
|
|
513
563
|
payload: {
|
|
514
|
-
score:
|
|
515
|
-
feedback:
|
|
564
|
+
score: i.score,
|
|
565
|
+
feedback: i.feedback
|
|
516
566
|
}
|
|
517
567
|
}
|
|
518
568
|
}
|
|
519
569
|
]
|
|
520
570
|
});
|
|
521
|
-
const { data:
|
|
522
|
-
...
|
|
523
|
-
system_message_uuid:
|
|
571
|
+
const { data: t, error: s } = await this.api.submitCsat({
|
|
572
|
+
...i,
|
|
573
|
+
system_message_uuid: o,
|
|
524
574
|
session_id: l
|
|
525
575
|
});
|
|
526
|
-
return { data:
|
|
527
|
-
}, this.api = e, this.sessionCtx =
|
|
576
|
+
return { data: t, error: s };
|
|
577
|
+
}, this.api = e, this.sessionCtx = a, this.messageCtx = n;
|
|
528
578
|
}
|
|
529
579
|
}
|
|
530
|
-
const
|
|
580
|
+
const le = [
|
|
531
581
|
{
|
|
532
582
|
action: "newparagraph",
|
|
533
583
|
phrases: {
|
|
@@ -602,7 +652,7 @@ const re = [
|
|
|
602
652
|
it: ["invia messaggio"]
|
|
603
653
|
}
|
|
604
654
|
}
|
|
605
|
-
],
|
|
655
|
+
], ce = [
|
|
606
656
|
"en",
|
|
607
657
|
"es",
|
|
608
658
|
"fr",
|
|
@@ -610,67 +660,67 @@ const re = [
|
|
|
610
660
|
"pt",
|
|
611
661
|
"it"
|
|
612
662
|
];
|
|
613
|
-
function
|
|
614
|
-
return
|
|
663
|
+
function pe(_) {
|
|
664
|
+
return ce.includes(_);
|
|
615
665
|
}
|
|
616
|
-
function
|
|
617
|
-
return
|
|
666
|
+
function de(_) {
|
|
667
|
+
return _.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
618
668
|
}
|
|
619
|
-
function
|
|
620
|
-
const e =
|
|
621
|
-
(
|
|
622
|
-
(l) =>
|
|
669
|
+
function ue(_) {
|
|
670
|
+
const e = le.flatMap(
|
|
671
|
+
(i) => _.flatMap(
|
|
672
|
+
(l) => i.phrases[l].map((o) => ({ phrase: o, action: i.action }))
|
|
623
673
|
)
|
|
624
|
-
),
|
|
674
|
+
), a = e.map((i) => de(i.phrase)).sort((i, l) => l.length - i.length).join("|"), n = String.raw`(?<=^\s{0,3}|[.!?\n]\s{0,3})`;
|
|
625
675
|
return {
|
|
626
676
|
regex: new RegExp(
|
|
627
|
-
`${
|
|
677
|
+
`${n}(${a})` + String.raw`([.,!?;:])(?=\s|$)`,
|
|
628
678
|
"giu"
|
|
629
679
|
),
|
|
630
680
|
finalRegex: new RegExp(
|
|
631
|
-
`${
|
|
681
|
+
`${n}(${a})` + String.raw`([.,!?;:]?)(?=\s|$)`,
|
|
632
682
|
"giu"
|
|
633
683
|
),
|
|
634
684
|
phraseToAction: new Map(
|
|
635
|
-
e.map((
|
|
685
|
+
e.map((i) => [i.phrase.toLowerCase(), i.action])
|
|
636
686
|
),
|
|
637
|
-
longestPhrase: Math.max(...e.map((
|
|
687
|
+
longestPhrase: Math.max(...e.map((i) => i.phrase.length))
|
|
638
688
|
};
|
|
639
689
|
}
|
|
640
|
-
const
|
|
641
|
-
function
|
|
642
|
-
const e =
|
|
643
|
-
let
|
|
644
|
-
return
|
|
690
|
+
const F = /* @__PURE__ */ new Map();
|
|
691
|
+
function A(_) {
|
|
692
|
+
const e = _ && pe(_) && _ !== "en" ? _ : null, a = e ?? "en";
|
|
693
|
+
let n = F.get(a);
|
|
694
|
+
return n || (n = ue(e ? ["en", e] : ["en"]), F.set(a, n)), n;
|
|
645
695
|
}
|
|
646
|
-
function
|
|
647
|
-
const e =
|
|
696
|
+
function me(_) {
|
|
697
|
+
const e = _.replace(/\s+$/, "");
|
|
648
698
|
if (!e) return "";
|
|
649
|
-
const
|
|
650
|
-
let
|
|
651
|
-
for (let
|
|
652
|
-
const l =
|
|
699
|
+
const a = e.replace(/[.!?]+$/, "");
|
|
700
|
+
let n = -1;
|
|
701
|
+
for (let i = a.length - 1; i >= 0; i--) {
|
|
702
|
+
const l = a[i];
|
|
653
703
|
if (l === "." || l === "!" || l === "?" || l === `
|
|
654
704
|
`) {
|
|
655
|
-
|
|
705
|
+
n = i + 1;
|
|
656
706
|
break;
|
|
657
707
|
}
|
|
658
708
|
}
|
|
659
|
-
return
|
|
709
|
+
return n === -1 ? "" : `${a.slice(0, n)} `.replace(/\n $/, `
|
|
660
710
|
`);
|
|
661
711
|
}
|
|
662
|
-
const
|
|
712
|
+
const he = new RegExp(
|
|
663
713
|
String.raw`(^- |\n(?:- )?)(\p{Ll})`,
|
|
664
714
|
"gu"
|
|
665
715
|
);
|
|
666
|
-
function
|
|
667
|
-
return
|
|
668
|
-
|
|
669
|
-
(e,
|
|
716
|
+
function ge(_) {
|
|
717
|
+
return _.replace(
|
|
718
|
+
he,
|
|
719
|
+
(e, a, n) => a + n.toUpperCase()
|
|
670
720
|
);
|
|
671
721
|
}
|
|
672
|
-
function
|
|
673
|
-
return
|
|
722
|
+
function ke(_) {
|
|
723
|
+
return _.length <= 3 && /^\s*$/.test(_) ? !0 : /[.!?\n]\s{0,3}$/.test(_.slice(-6));
|
|
674
724
|
}
|
|
675
725
|
class C {
|
|
676
726
|
/**
|
|
@@ -678,36 +728,36 @@ class C {
|
|
|
678
728
|
* Pure and deterministic: always called with the entire raw string so the
|
|
679
729
|
* result never depends on delta chunking.
|
|
680
730
|
*/
|
|
681
|
-
static process(e,
|
|
682
|
-
const
|
|
683
|
-
let
|
|
684
|
-
for (const p of Array.from(l.matchAll(
|
|
685
|
-
const [, d = ""] = p,
|
|
686
|
-
if (
|
|
687
|
-
if (
|
|
731
|
+
static process(e, a) {
|
|
732
|
+
const n = A(a == null ? void 0 : a.language), i = a != null && a.final ? "" : C.commandPrefixTail(e, a == null ? void 0 : a.language), l = e.slice(0, e.length - i.length), o = a != null && a.final ? n.finalRegex : n.regex;
|
|
733
|
+
let t = "", s = null, r = 0;
|
|
734
|
+
for (const p of Array.from(l.matchAll(o))) {
|
|
735
|
+
const [, d = ""] = p, u = n.phraseToAction.get(d.toLowerCase());
|
|
736
|
+
if (u)
|
|
737
|
+
if (t += l.slice(r, p.index), r = p.index + p[0].length, u === "newline") t = `${t.replace(/[ \t]+$/, "")}
|
|
688
738
|
`;
|
|
689
|
-
else if (
|
|
690
|
-
|
|
739
|
+
else if (u === "newparagraph")
|
|
740
|
+
t = `${t.replace(/[ \t]+$/, "")}
|
|
691
741
|
|
|
692
742
|
`;
|
|
693
|
-
else if (
|
|
694
|
-
const
|
|
695
|
-
|
|
696
|
-
`) ? `${
|
|
743
|
+
else if (u === "bullet") {
|
|
744
|
+
const g = t.replace(/[ \t]+$/, "");
|
|
745
|
+
t = g === "" || g.endsWith(`
|
|
746
|
+
`) ? `${g}- ` : `${g}
|
|
697
747
|
- `;
|
|
698
|
-
} else if (
|
|
748
|
+
} else if (u === "scratch") t = me(t);
|
|
699
749
|
else {
|
|
700
|
-
s =
|
|
750
|
+
s = u === "send" ? "send" : "stop";
|
|
701
751
|
break;
|
|
702
752
|
}
|
|
703
753
|
}
|
|
704
|
-
return s === null && (
|
|
705
|
-
|
|
754
|
+
return s === null && (t += l.slice(r)), { text: ge(
|
|
755
|
+
t.replace(/^\s+/, "").replace(/[ \t]+\n/g, `
|
|
706
756
|
`).replace(/\n[ \t]+/g, `
|
|
707
757
|
`).replace(/(^|\n)- +/g, "$1- ").replace(/ {2,}/g, " ").replace(/\n{3,}/g, `
|
|
708
758
|
|
|
709
759
|
`)
|
|
710
|
-
), pendingTail:
|
|
760
|
+
), pendingTail: i, control: s };
|
|
711
761
|
}
|
|
712
762
|
/**
|
|
713
763
|
* Longest suffix of `raw` that could still become a command — a proper
|
|
@@ -718,16 +768,16 @@ class C {
|
|
|
718
768
|
* control command from an intermediate delta would stop or submit
|
|
719
769
|
* mid-sentence.
|
|
720
770
|
*/
|
|
721
|
-
static commandPrefixTail(e,
|
|
722
|
-
const
|
|
723
|
-
for (let l =
|
|
724
|
-
const
|
|
725
|
-
if (!
|
|
726
|
-
const
|
|
771
|
+
static commandPrefixTail(e, a) {
|
|
772
|
+
const n = A(a), i = Math.min(e.length, n.longestPhrase + 2);
|
|
773
|
+
for (let l = i; l > 0; l--) {
|
|
774
|
+
const o = e.length - l;
|
|
775
|
+
if (!ke(e.slice(0, o))) continue;
|
|
776
|
+
const t = e.slice(o).toLowerCase(), s = t.replace(/^\s+/, "");
|
|
727
777
|
if (s) {
|
|
728
|
-
for (const r of Array.from(
|
|
778
|
+
for (const r of Array.from(n.phraseToAction.keys()))
|
|
729
779
|
if (r.startsWith(s))
|
|
730
|
-
return e.slice(
|
|
780
|
+
return e.slice(o + (t.length - s.length));
|
|
731
781
|
}
|
|
732
782
|
}
|
|
733
783
|
return "";
|
|
@@ -737,13 +787,13 @@ class C {
|
|
|
737
787
|
* prefix) — i.e. a silence pause would resolve it into a command. Used by
|
|
738
788
|
* the manager's silence timer.
|
|
739
789
|
*/
|
|
740
|
-
static pendingTailIsCompletePhrase(e,
|
|
741
|
-
const
|
|
742
|
-
return
|
|
790
|
+
static pendingTailIsCompletePhrase(e, a) {
|
|
791
|
+
const n = C.commandPrefixTail(e, a).trim().toLowerCase();
|
|
792
|
+
return n ? A(a).phraseToAction.has(n) : !1;
|
|
743
793
|
}
|
|
744
794
|
}
|
|
745
|
-
const
|
|
746
|
-
class
|
|
795
|
+
const be = 55, fe = 90;
|
|
796
|
+
class O {
|
|
747
797
|
/**
|
|
748
798
|
* Next paced step toward `processed`: normally one word per tick so text
|
|
749
799
|
* flows evenly instead of landing in bursty chunks; proportionally larger
|
|
@@ -752,28 +802,28 @@ class F {
|
|
|
752
802
|
*/
|
|
753
803
|
static nextDripText({
|
|
754
804
|
displayed: e,
|
|
755
|
-
processed:
|
|
805
|
+
processed: a
|
|
756
806
|
}) {
|
|
757
|
-
if (
|
|
758
|
-
const
|
|
759
|
-
if (
|
|
760
|
-
return
|
|
761
|
-
let
|
|
762
|
-
for (;
|
|
763
|
-
for (;
|
|
764
|
-
return
|
|
807
|
+
if (a.length <= e.length) return a;
|
|
808
|
+
const n = a.length - e.length;
|
|
809
|
+
if (n > fe)
|
|
810
|
+
return a.slice(0, e.length + Math.ceil(n / 3));
|
|
811
|
+
let i = e.length;
|
|
812
|
+
for (; i < a.length && /\s/.test(a.charAt(i)); ) i++;
|
|
813
|
+
for (; i < a.length && !/\s/.test(a.charAt(i)); ) i++;
|
|
814
|
+
return i - e.length > 12 && (i = e.length + 6), a.slice(0, Math.max(i, e.length + 1));
|
|
765
815
|
}
|
|
766
816
|
/** Normalize a BCP-47 browser locale into the hint OpenAI accepts. */
|
|
767
817
|
static languageHint(e) {
|
|
768
818
|
if (!e) return;
|
|
769
|
-
const
|
|
770
|
-
if (/^zh-(cn|tw|hk)$/.test(
|
|
771
|
-
const
|
|
772
|
-
return
|
|
819
|
+
const a = e.toLowerCase();
|
|
820
|
+
if (/^zh-(cn|tw|hk)$/.test(a)) return a;
|
|
821
|
+
const n = a.split("-")[0];
|
|
822
|
+
return n && /^[a-z]{2,3}$/.test(n) ? n : void 0;
|
|
773
823
|
}
|
|
774
824
|
}
|
|
775
|
-
const
|
|
776
|
-
class
|
|
825
|
+
const ve = 2e4;
|
|
826
|
+
class ye {
|
|
777
827
|
constructor() {
|
|
778
828
|
this.cached = null, this.inflight = null;
|
|
779
829
|
}
|
|
@@ -781,15 +831,15 @@ class fe {
|
|
|
781
831
|
get() {
|
|
782
832
|
if (!this.cached) return null;
|
|
783
833
|
const e = Date.parse(this.cached.expiresAt);
|
|
784
|
-
return Number.isNaN(e) || e - Date.now() <
|
|
834
|
+
return Number.isNaN(e) || e - Date.now() < ve ? (this.cached = null, null) : this.cached;
|
|
785
835
|
}
|
|
786
836
|
/**
|
|
787
837
|
* Resolve a mint, deduping concurrent requests (hover-prewarm racing a
|
|
788
838
|
* click reuses the same in-flight promise instead of double-minting).
|
|
789
839
|
*/
|
|
790
840
|
async resolve(e) {
|
|
791
|
-
const
|
|
792
|
-
return
|
|
841
|
+
const a = this.get();
|
|
842
|
+
return a || (this.inflight || (this.inflight = e().then((n) => (this.cached = n, n)).finally(() => {
|
|
793
843
|
this.inflight = null;
|
|
794
844
|
})), this.inflight);
|
|
795
845
|
}
|
|
@@ -798,89 +848,89 @@ class fe {
|
|
|
798
848
|
this.cached = null;
|
|
799
849
|
}
|
|
800
850
|
}
|
|
801
|
-
function
|
|
802
|
-
return typeof
|
|
851
|
+
function U(_) {
|
|
852
|
+
return typeof _ == "object" && _ !== null && !Array.isArray(_);
|
|
803
853
|
}
|
|
804
|
-
function
|
|
805
|
-
if (!
|
|
806
|
-
const e =
|
|
854
|
+
function we(_) {
|
|
855
|
+
if (!U(_) || typeof _.type != "string") return null;
|
|
856
|
+
const e = U(_.error) ? _.error : null;
|
|
807
857
|
return {
|
|
808
|
-
type:
|
|
809
|
-
delta: typeof
|
|
858
|
+
type: _.type,
|
|
859
|
+
delta: typeof _.delta == "string" ? _.delta : void 0,
|
|
810
860
|
errorMessage: e && typeof e.message == "string" ? e.message : void 0
|
|
811
861
|
};
|
|
812
862
|
}
|
|
813
|
-
const
|
|
863
|
+
const je = "https://api.openai.com/v1/realtime/calls", Se = 10 * 60 * 1e3, xe = 15e3, ze = 5e3;
|
|
814
864
|
class E extends Error {
|
|
815
865
|
}
|
|
816
|
-
class
|
|
866
|
+
class Ce {
|
|
817
867
|
constructor({
|
|
818
868
|
mintToken: e,
|
|
819
|
-
onDelta:
|
|
820
|
-
onState:
|
|
821
|
-
onError:
|
|
869
|
+
onDelta: a,
|
|
870
|
+
onState: n,
|
|
871
|
+
onError: i,
|
|
822
872
|
onLevel: l
|
|
823
873
|
}) {
|
|
824
|
-
this.state = "idle", this.pc = null, this.dc = null, this.stream = null, this.audioContext = null, this.levelRaf = 0, this.timers = [], this.loggedParseFailure = !1, this.mintToken = e, this.onDelta =
|
|
874
|
+
this.state = "idle", this.pc = null, this.dc = null, this.stream = null, this.audioContext = null, this.levelRaf = 0, this.timers = [], this.loggedParseFailure = !1, this.mintToken = e, this.onDelta = a, this.onState = n, this.onError = i, this.onLevel = l;
|
|
825
875
|
}
|
|
826
876
|
async start() {
|
|
827
877
|
if (this.state === "idle") {
|
|
828
878
|
this.setState("connecting"), this.timers.push(
|
|
829
879
|
setTimeout(() => {
|
|
830
880
|
this.state === "connecting" && this.fail("unavailable");
|
|
831
|
-
},
|
|
832
|
-
), this.timers.push(setTimeout(() => this.stop(),
|
|
881
|
+
}, xe)
|
|
882
|
+
), this.timers.push(setTimeout(() => this.stop(), Se));
|
|
833
883
|
try {
|
|
834
884
|
const e = this.requestMicrophone();
|
|
835
885
|
e.then((c) => {
|
|
836
886
|
(this.isTornDown() || this.stream && this.stream !== c) && c.getTracks().forEach((p) => p.stop());
|
|
837
887
|
}).catch(() => {
|
|
838
888
|
});
|
|
839
|
-
const [
|
|
889
|
+
const [a, n] = await Promise.all([e, this.mintToken()]);
|
|
840
890
|
if (this.isTornDown()) {
|
|
841
|
-
|
|
891
|
+
a.getTracks().forEach((c) => c.stop());
|
|
842
892
|
return;
|
|
843
893
|
}
|
|
844
|
-
this.stream =
|
|
845
|
-
const
|
|
846
|
-
this.pc =
|
|
847
|
-
const [l] =
|
|
894
|
+
this.stream = a, this.startLevelMeter(a);
|
|
895
|
+
const i = new RTCPeerConnection();
|
|
896
|
+
this.pc = i;
|
|
897
|
+
const [l] = a.getAudioTracks();
|
|
848
898
|
if (!l) throw new E("No audio track");
|
|
849
|
-
|
|
850
|
-
const
|
|
851
|
-
this.dc =
|
|
899
|
+
i.addTrack(l, a);
|
|
900
|
+
const o = i.createDataChannel("oai-events");
|
|
901
|
+
this.dc = o, o.addEventListener(
|
|
852
902
|
"message",
|
|
853
903
|
(c) => this.handleServerEvent(c.data)
|
|
854
|
-
),
|
|
904
|
+
), o.addEventListener("open", () => {
|
|
855
905
|
this.state === "connecting" && this.setState("listening");
|
|
856
|
-
}),
|
|
857
|
-
if (
|
|
906
|
+
}), i.addEventListener("connectionstatechange", () => {
|
|
907
|
+
if (i.connectionState === "failed") {
|
|
858
908
|
this.fail("unavailable");
|
|
859
909
|
return;
|
|
860
910
|
}
|
|
861
|
-
|
|
911
|
+
i.connectionState === "disconnected" && this.timers.push(
|
|
862
912
|
setTimeout(() => {
|
|
863
|
-
this.pc ===
|
|
864
|
-
},
|
|
913
|
+
this.pc === i && i.connectionState !== "connected" && this.fail("unavailable");
|
|
914
|
+
}, ze)
|
|
865
915
|
);
|
|
866
916
|
});
|
|
867
|
-
const
|
|
868
|
-
await
|
|
869
|
-
const s = await fetch(
|
|
917
|
+
const t = await i.createOffer();
|
|
918
|
+
await i.setLocalDescription(t);
|
|
919
|
+
const s = await fetch(je, {
|
|
870
920
|
method: "POST",
|
|
871
921
|
headers: {
|
|
872
|
-
Authorization: `Bearer ${
|
|
922
|
+
Authorization: `Bearer ${n.token}`,
|
|
873
923
|
"Content-Type": "application/sdp"
|
|
874
924
|
},
|
|
875
|
-
body:
|
|
925
|
+
body: t.sdp
|
|
876
926
|
});
|
|
877
927
|
if (!s.ok)
|
|
878
928
|
throw new Error(`Realtime handshake failed (${s.status})`);
|
|
879
929
|
const r = await s.text();
|
|
880
930
|
if (this.isTornDown()) return;
|
|
881
|
-
await
|
|
931
|
+
await i.setRemoteDescription({ type: "answer", sdp: r });
|
|
882
932
|
} catch (e) {
|
|
883
|
-
e instanceof E ? this.fail("microphone") : (
|
|
933
|
+
e instanceof E ? this.fail("microphone") : (m.error("dictation session failed to start", {
|
|
884
934
|
_e: e instanceof Error ? e.message : String(e)
|
|
885
935
|
}), this.fail("unavailable"));
|
|
886
936
|
}
|
|
@@ -901,60 +951,60 @@ class ze {
|
|
|
901
951
|
autoGainControl: !0
|
|
902
952
|
}
|
|
903
953
|
});
|
|
904
|
-
} catch (
|
|
954
|
+
} catch (a) {
|
|
905
955
|
throw new E(
|
|
906
|
-
|
|
956
|
+
a instanceof DOMException ? a.name : "Could not access the microphone"
|
|
907
957
|
);
|
|
908
958
|
}
|
|
909
959
|
}
|
|
910
960
|
handleServerEvent(e) {
|
|
911
961
|
if (typeof e != "string") return;
|
|
912
|
-
let
|
|
962
|
+
let a;
|
|
913
963
|
try {
|
|
914
|
-
|
|
964
|
+
a = JSON.parse(e);
|
|
915
965
|
} catch {
|
|
916
|
-
this.loggedParseFailure || (this.loggedParseFailure = !0,
|
|
966
|
+
this.loggedParseFailure || (this.loggedParseFailure = !0, m.error("dictation server event was not valid JSON", {
|
|
917
967
|
snippet: e.slice(0, 120)
|
|
918
968
|
}));
|
|
919
969
|
return;
|
|
920
970
|
}
|
|
921
|
-
const
|
|
922
|
-
if (!
|
|
923
|
-
const { type:
|
|
924
|
-
if (
|
|
971
|
+
const n = we(a);
|
|
972
|
+
if (!n) return;
|
|
973
|
+
const { type: i, delta: l } = n;
|
|
974
|
+
if (i === "session.created" || i === "transcription_session.created") {
|
|
925
975
|
this.setState("listening");
|
|
926
976
|
return;
|
|
927
977
|
}
|
|
928
|
-
if (
|
|
978
|
+
if (i === "conversation.item.input_audio_transcription.delta" && l) {
|
|
929
979
|
this.state === "connecting" && this.setState("listening"), this.onDelta(l);
|
|
930
980
|
return;
|
|
931
981
|
}
|
|
932
|
-
|
|
933
|
-
_e:
|
|
982
|
+
i === "error" && (m.error("dictation server event error", {
|
|
983
|
+
_e: n.errorMessage ?? "unknown"
|
|
934
984
|
}), this.fail("unavailable"));
|
|
935
985
|
}
|
|
936
986
|
startLevelMeter(e) {
|
|
937
987
|
if (this.onLevel)
|
|
938
988
|
try {
|
|
939
|
-
const
|
|
940
|
-
this.audioContext =
|
|
941
|
-
const
|
|
942
|
-
|
|
943
|
-
const l = new Uint8Array(
|
|
989
|
+
const a = new AudioContext();
|
|
990
|
+
this.audioContext = a;
|
|
991
|
+
const n = a.createMediaStreamSource(e), i = a.createAnalyser();
|
|
992
|
+
i.fftSize = 512, n.connect(i);
|
|
993
|
+
const l = new Uint8Array(i.frequencyBinCount), o = () => {
|
|
944
994
|
var r;
|
|
945
|
-
|
|
946
|
-
let
|
|
995
|
+
i.getByteTimeDomainData(l);
|
|
996
|
+
let t = 0;
|
|
947
997
|
for (let c = 0; c < l.length; c++) {
|
|
948
998
|
const p = ((l[c] ?? 128) - 128) / 128;
|
|
949
|
-
|
|
999
|
+
t += p * p;
|
|
950
1000
|
}
|
|
951
|
-
const s = Math.sqrt(
|
|
952
|
-
(r = this.onLevel) == null || r.call(this, Math.min(1, s * 4)), this.levelRaf = requestAnimationFrame(
|
|
1001
|
+
const s = Math.sqrt(t / l.length);
|
|
1002
|
+
(r = this.onLevel) == null || r.call(this, Math.min(1, s * 4)), this.levelRaf = requestAnimationFrame(o);
|
|
953
1003
|
};
|
|
954
|
-
this.levelRaf = requestAnimationFrame(
|
|
955
|
-
} catch (
|
|
956
|
-
|
|
957
|
-
_e:
|
|
1004
|
+
this.levelRaf = requestAnimationFrame(o);
|
|
1005
|
+
} catch (a) {
|
|
1006
|
+
m.error("dictation level meter unavailable", {
|
|
1007
|
+
_e: a instanceof Error ? a.message : String(a)
|
|
958
1008
|
});
|
|
959
1009
|
}
|
|
960
1010
|
}
|
|
@@ -965,9 +1015,9 @@ class ze {
|
|
|
965
1015
|
this.isTornDown() || (this.teardown(), this.setState("error"), this.onError(e));
|
|
966
1016
|
}
|
|
967
1017
|
teardown() {
|
|
968
|
-
var e,
|
|
969
|
-
this.timers.forEach((l) => clearTimeout(l)), this.timers = [], this.levelRaf && cancelAnimationFrame(this.levelRaf), this.levelRaf = 0, (e = this.dc) == null || e.close(), this.dc = null, (
|
|
970
|
-
|
|
1018
|
+
var e, a, n, i;
|
|
1019
|
+
this.timers.forEach((l) => clearTimeout(l)), this.timers = [], this.levelRaf && cancelAnimationFrame(this.levelRaf), this.levelRaf = 0, (e = this.dc) == null || e.close(), this.dc = null, (a = this.pc) == null || a.close(), this.pc = null, (n = this.stream) == null || n.getTracks().forEach((l) => l.stop()), this.stream = null, (i = this.audioContext) == null || i.close().catch((l) => {
|
|
1020
|
+
m.error("failed to close dictation audio context", {
|
|
971
1021
|
_e: String(l)
|
|
972
1022
|
});
|
|
973
1023
|
}), this.audioContext = null;
|
|
@@ -976,43 +1026,43 @@ class ze {
|
|
|
976
1026
|
this.state !== e && (this.state = e, this.onState(e));
|
|
977
1027
|
}
|
|
978
1028
|
}
|
|
979
|
-
const
|
|
980
|
-
class
|
|
981
|
-
constructor({ api: e, config:
|
|
982
|
-
this.state = new
|
|
983
|
-
this.mintToken().catch((
|
|
984
|
-
this.mintCache.clear(),
|
|
985
|
-
_e:
|
|
1029
|
+
const qe = 1300, Ee = { status: "idle", error: null };
|
|
1030
|
+
class Pe {
|
|
1031
|
+
constructor({ api: e, config: a }) {
|
|
1032
|
+
this.state = new w(Ee), this.levelRef = { current: 0 }, this.mintCache = new ye(), 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 = () => {
|
|
1033
|
+
this.mintToken().catch((n) => {
|
|
1034
|
+
this.mintCache.clear(), m.error("dictation token prewarm failed", {
|
|
1035
|
+
_e: n instanceof Error ? n.message : String(n)
|
|
986
1036
|
});
|
|
987
1037
|
});
|
|
988
|
-
}, this.start = (
|
|
989
|
-
this.session && this.teardown(), this.target =
|
|
1038
|
+
}, this.start = (n) => {
|
|
1039
|
+
this.session && this.teardown(), this.target = n, this.language = O.languageHint(
|
|
990
1040
|
this.config.language ?? navigator.language
|
|
991
|
-
), this.prefix =
|
|
992
|
-
const
|
|
1041
|
+
), this.prefix = n.getValue(), this.raw = "", this.processed = "", this.displayed = "";
|
|
1042
|
+
const i = new Ce({
|
|
993
1043
|
mintToken: this.mintToken,
|
|
994
1044
|
onLevel: (l) => {
|
|
995
1045
|
this.levelRef.current = l;
|
|
996
1046
|
},
|
|
997
1047
|
onState: (l) => {
|
|
998
|
-
|
|
1048
|
+
i === this.session && (l === "connecting" && this.state.set({ status: "connecting", error: null }), l === "listening" && this.state.set({ status: "listening", error: null }), l === "stopped" && this.teardown());
|
|
999
1049
|
},
|
|
1000
1050
|
onError: (l) => {
|
|
1001
|
-
|
|
1051
|
+
i === this.session && (this.mintCache.clear(), this.teardown({ error: l, executeFinalCommand: !1 }));
|
|
1002
1052
|
},
|
|
1003
1053
|
onDelta: (l) => {
|
|
1004
|
-
if (
|
|
1054
|
+
if (i !== this.session || !this.target) return;
|
|
1005
1055
|
if (!this.isConsistent()) {
|
|
1006
1056
|
this.teardown();
|
|
1007
1057
|
return;
|
|
1008
1058
|
}
|
|
1009
1059
|
this.raw += l;
|
|
1010
|
-
const
|
|
1011
|
-
if (
|
|
1060
|
+
const o = this.ingest();
|
|
1061
|
+
if (o === "stop") {
|
|
1012
1062
|
this.teardown();
|
|
1013
1063
|
return;
|
|
1014
1064
|
}
|
|
1015
|
-
if (
|
|
1065
|
+
if (o === "send") {
|
|
1016
1066
|
this.teardown({ send: !0 });
|
|
1017
1067
|
return;
|
|
1018
1068
|
}
|
|
@@ -1020,32 +1070,32 @@ class qe {
|
|
|
1020
1070
|
this.raw,
|
|
1021
1071
|
this.language
|
|
1022
1072
|
) && (this.silenceTimer = setTimeout(() => {
|
|
1023
|
-
if (
|
|
1073
|
+
if (i !== this.session) return;
|
|
1024
1074
|
this.raw = `${this.raw}.`;
|
|
1025
|
-
const
|
|
1026
|
-
|
|
1027
|
-
},
|
|
1075
|
+
const t = this.ingest();
|
|
1076
|
+
t === "stop" ? this.teardown() : t === "send" && this.teardown({ send: !0 });
|
|
1077
|
+
}, qe));
|
|
1028
1078
|
}
|
|
1029
1079
|
});
|
|
1030
|
-
this.session =
|
|
1080
|
+
this.session = i, this.state.set({ status: "connecting", error: null }), this.dripTimer = setInterval(() => {
|
|
1031
1081
|
if (this.target && this.processed !== this.displayed) {
|
|
1032
1082
|
if (!this.isConsistent()) {
|
|
1033
1083
|
this.teardown();
|
|
1034
1084
|
return;
|
|
1035
1085
|
}
|
|
1036
1086
|
this.applyDisplayed(
|
|
1037
|
-
|
|
1087
|
+
O.nextDripText({
|
|
1038
1088
|
displayed: this.displayed,
|
|
1039
1089
|
processed: this.processed
|
|
1040
1090
|
})
|
|
1041
1091
|
);
|
|
1042
1092
|
}
|
|
1043
|
-
},
|
|
1093
|
+
}, be), i.start();
|
|
1044
1094
|
}, this.stop = () => {
|
|
1045
1095
|
this.session && this.teardown();
|
|
1046
1096
|
}, this.mintToken = async () => this.mintCache.resolve(
|
|
1047
1097
|
() => this.api.createDictationSession({ language: this.language })
|
|
1048
|
-
), this.api = e, this.config =
|
|
1098
|
+
), this.api = e, this.config = a;
|
|
1049
1099
|
}
|
|
1050
1100
|
/** Applied text = prefix + dictated. A mismatch means the visitor edited. */
|
|
1051
1101
|
isConsistent() {
|
|
@@ -1057,28 +1107,28 @@ class qe {
|
|
|
1057
1107
|
/** Process the transcript and apply the outcome. Shared by the delta path,
|
|
1058
1108
|
* the silence timer, and (with `final`) teardown. Returns the control. */
|
|
1059
1109
|
ingest(e) {
|
|
1060
|
-
const
|
|
1110
|
+
const a = C.process(this.raw, {
|
|
1061
1111
|
language: this.language,
|
|
1062
1112
|
final: e == null ? void 0 : e.final
|
|
1063
1113
|
});
|
|
1064
|
-
return this.processed =
|
|
1114
|
+
return this.processed = a.text, a.text.startsWith(this.displayed) || this.applyDisplayed(a.text), a.control;
|
|
1065
1115
|
}
|
|
1066
1116
|
stopSilenceTimer() {
|
|
1067
1117
|
this.silenceTimer && clearTimeout(this.silenceTimer), this.silenceTimer = null;
|
|
1068
1118
|
}
|
|
1069
1119
|
teardown(e) {
|
|
1070
1120
|
var l;
|
|
1071
|
-
const
|
|
1121
|
+
const a = this.session, n = this.target;
|
|
1072
1122
|
this.dripTimer && clearInterval(this.dripTimer), this.dripTimer = null, this.stopSilenceTimer();
|
|
1073
|
-
let
|
|
1074
|
-
if (
|
|
1075
|
-
const
|
|
1076
|
-
(e == null ? void 0 : e.executeFinalCommand) !== !1 &&
|
|
1123
|
+
let i = (e == null ? void 0 : e.send) ?? !1;
|
|
1124
|
+
if (n && this.isConsistent()) {
|
|
1125
|
+
const o = this.ingest({ final: !0 });
|
|
1126
|
+
(e == null ? void 0 : e.executeFinalCommand) !== !1 && o === "send" && (i = !0), this.processed !== this.displayed && this.applyDisplayed(this.processed);
|
|
1077
1127
|
}
|
|
1078
|
-
this.session = null, this.target = null,
|
|
1128
|
+
this.session = null, this.target = null, a == null || a.stop(), this.levelRef.current = 0, this.state.set({ status: "idle", error: (e == null ? void 0 : e.error) ?? null }), i && ((l = n == null ? void 0 : n.onSend) == null || l.call(n));
|
|
1079
1129
|
}
|
|
1080
1130
|
}
|
|
1081
|
-
const
|
|
1131
|
+
const Ae = {
|
|
1082
1132
|
write_a_message_placeholder: "اكتب رسالة...",
|
|
1083
1133
|
your_issue_has_been_resolved: "تم حل مشكلتك!",
|
|
1084
1134
|
new_conversation: "محادثة جديدة",
|
|
@@ -1102,7 +1152,19 @@ const Ee = {
|
|
|
1102
1152
|
companion_layout_floating: "عائم",
|
|
1103
1153
|
companion_layout_sidebar: "الشريط الجانبي",
|
|
1104
1154
|
companion_layout_fullscreen: "ملء الشاشة",
|
|
1155
|
+
companion_close_chat: "إغلاق {title}",
|
|
1105
1156
|
companion_close: "إغلاق",
|
|
1157
|
+
companion_switch_chat: "تبديل المحادثة",
|
|
1158
|
+
companion_viewing: "تعرض الآن",
|
|
1159
|
+
companion_working: "قيد العمل",
|
|
1160
|
+
companion_open: "مفتوحة",
|
|
1161
|
+
companion_closed: "مغلقة",
|
|
1162
|
+
companion_draft: "مسودة",
|
|
1163
|
+
companion_chats: "الجلسات النشطة",
|
|
1164
|
+
companion_chat_number: "محادثة {count}",
|
|
1165
|
+
companion_active_chats: "{count} جلسات نشطة",
|
|
1166
|
+
companion_other_sessions: "الجلسات المفتوحة الأخرى: {count}",
|
|
1167
|
+
companion_working_chats: "{count} قيد العمل",
|
|
1106
1168
|
companion_history: "سجل المحادثات",
|
|
1107
1169
|
companion_expand_chat: "توسيع المحادثة",
|
|
1108
1170
|
companion_sidebar_dock_label: "الإرساء",
|
|
@@ -1166,7 +1228,7 @@ const Ee = {
|
|
|
1166
1228
|
questions_send: "إرسال",
|
|
1167
1229
|
questions_type_answer: "سأكتبها بنفسي",
|
|
1168
1230
|
questions_answer_placeholder: "اكتب إجابتك…"
|
|
1169
|
-
},
|
|
1231
|
+
}, Te = {
|
|
1170
1232
|
write_a_message_placeholder: "একটি বার্তা লিখুন...",
|
|
1171
1233
|
your_issue_has_been_resolved: "আপনার সমস্যা সমাধান হয়েছে!",
|
|
1172
1234
|
new_conversation: "নতুন কথোপকথন",
|
|
@@ -1254,7 +1316,7 @@ const Ee = {
|
|
|
1254
1316
|
questions_send: "পাঠান",
|
|
1255
1317
|
questions_type_answer: "আমি লিখে দিচ্ছি",
|
|
1256
1318
|
questions_answer_placeholder: "আপনার উত্তর লিখুন…"
|
|
1257
|
-
},
|
|
1319
|
+
}, Me = {
|
|
1258
1320
|
write_a_message_placeholder: "Напишете съобщение...",
|
|
1259
1321
|
your_issue_has_been_resolved: "Вашият проблем е разрешен!",
|
|
1260
1322
|
new_conversation: "Нов разговор",
|
|
@@ -1342,7 +1404,7 @@ const Ee = {
|
|
|
1342
1404
|
questions_send: "Изпрати",
|
|
1343
1405
|
questions_type_answer: "Ще напиша сам",
|
|
1344
1406
|
questions_answer_placeholder: "Напишете отговора си…"
|
|
1345
|
-
},
|
|
1407
|
+
}, Ie = {
|
|
1346
1408
|
write_a_message_placeholder: "Napište zprávu...",
|
|
1347
1409
|
your_issue_has_been_resolved: "Váš problém byl vyřešen!",
|
|
1348
1410
|
new_conversation: "Nová konverzace",
|
|
@@ -1430,7 +1492,7 @@ const Ee = {
|
|
|
1430
1492
|
questions_send: "Odeslat",
|
|
1431
1493
|
questions_type_answer: "Napíšu to sám",
|
|
1432
1494
|
questions_answer_placeholder: "Napište svou odpověď…"
|
|
1433
|
-
},
|
|
1495
|
+
}, De = {
|
|
1434
1496
|
write_a_message_placeholder: "Skriv en besked...",
|
|
1435
1497
|
your_issue_has_been_resolved: "Dit problem er løst!",
|
|
1436
1498
|
new_conversation: "Ny samtale",
|
|
@@ -1518,7 +1580,7 @@ const Ee = {
|
|
|
1518
1580
|
questions_send: "Send",
|
|
1519
1581
|
questions_type_answer: "Jeg skriver det selv",
|
|
1520
1582
|
questions_answer_placeholder: "Skriv dit svar…"
|
|
1521
|
-
},
|
|
1583
|
+
}, Ne = {
|
|
1522
1584
|
write_a_message_placeholder: "Γράψτε ένα μήνυμα...",
|
|
1523
1585
|
your_issue_has_been_resolved: "Το πρόβλημά σας επιλύθηκε!",
|
|
1524
1586
|
new_conversation: "Νέα συνομιλία",
|
|
@@ -1606,7 +1668,7 @@ const Ee = {
|
|
|
1606
1668
|
questions_send: "Αποστολή",
|
|
1607
1669
|
questions_type_answer: "Θα το γράψω",
|
|
1608
1670
|
questions_answer_placeholder: "Γράψτε την απάντησή σας…"
|
|
1609
|
-
},
|
|
1671
|
+
}, Re = {
|
|
1610
1672
|
write_a_message_placeholder: "Nachricht schreiben...",
|
|
1611
1673
|
your_issue_has_been_resolved: "Ihr Problem wurde gelöst!",
|
|
1612
1674
|
new_conversation: "Neue Konversation",
|
|
@@ -1694,7 +1756,7 @@ const Ee = {
|
|
|
1694
1756
|
questions_send: "Senden",
|
|
1695
1757
|
questions_type_answer: "Ich schreibe es selbst",
|
|
1696
1758
|
questions_answer_placeholder: "Antwort eingeben…"
|
|
1697
|
-
},
|
|
1759
|
+
}, G = {
|
|
1698
1760
|
write_a_message_placeholder: "Write a message...",
|
|
1699
1761
|
your_issue_has_been_resolved: "Your issue has been resolved!",
|
|
1700
1762
|
new_conversation: "New conversation",
|
|
@@ -1718,7 +1780,19 @@ const Ee = {
|
|
|
1718
1780
|
companion_layout_floating: "Floating",
|
|
1719
1781
|
companion_layout_sidebar: "Sidebar",
|
|
1720
1782
|
companion_layout_fullscreen: "Fullscreen",
|
|
1783
|
+
companion_close_chat: "Close {title}",
|
|
1721
1784
|
companion_close: "Close",
|
|
1785
|
+
companion_switch_chat: "Switch chat",
|
|
1786
|
+
companion_viewing: "Viewing",
|
|
1787
|
+
companion_working: "Working",
|
|
1788
|
+
companion_open: "Open",
|
|
1789
|
+
companion_closed: "Closed",
|
|
1790
|
+
companion_draft: "Draft",
|
|
1791
|
+
companion_chats: "Active sessions",
|
|
1792
|
+
companion_chat_number: "Chat {count}",
|
|
1793
|
+
companion_active_chats: "{count} active sessions",
|
|
1794
|
+
companion_other_sessions: "Other open sessions: {count}",
|
|
1795
|
+
companion_working_chats: "{count} working",
|
|
1722
1796
|
companion_history: "Conversation history",
|
|
1723
1797
|
companion_expand_chat: "Expand chat",
|
|
1724
1798
|
companion_sidebar_dock_label: "Dock",
|
|
@@ -1782,7 +1856,7 @@ const Ee = {
|
|
|
1782
1856
|
questions_send: "Send",
|
|
1783
1857
|
questions_type_answer: "I'll type it",
|
|
1784
1858
|
questions_answer_placeholder: "Type your answer…"
|
|
1785
|
-
},
|
|
1859
|
+
}, Ke = {
|
|
1786
1860
|
write_a_message_placeholder: "Escribe un mensaje...",
|
|
1787
1861
|
your_issue_has_been_resolved: "¡Tu problema fue resuelto!",
|
|
1788
1862
|
new_conversation: "Nueva conversación",
|
|
@@ -1870,7 +1944,7 @@ const Ee = {
|
|
|
1870
1944
|
questions_send: "Enviar",
|
|
1871
1945
|
questions_type_answer: "Lo escribo yo",
|
|
1872
1946
|
questions_answer_placeholder: "Escribe tu respuesta…"
|
|
1873
|
-
},
|
|
1947
|
+
}, Le = {
|
|
1874
1948
|
write_a_message_placeholder: "Magsulat ng mensahe...",
|
|
1875
1949
|
your_issue_has_been_resolved: "Nalutas na ang iyong isyu!",
|
|
1876
1950
|
new_conversation: "Bagong usapan",
|
|
@@ -1958,7 +2032,7 @@ const Ee = {
|
|
|
1958
2032
|
questions_send: "Ipadala",
|
|
1959
2033
|
questions_type_answer: "Ako na ang magta-type",
|
|
1960
2034
|
questions_answer_placeholder: "I-type ang iyong sagot…"
|
|
1961
|
-
},
|
|
2035
|
+
}, Fe = {
|
|
1962
2036
|
write_a_message_placeholder: "Kirjoita viesti...",
|
|
1963
2037
|
your_issue_has_been_resolved: "Ongelmasi on ratkaistu!",
|
|
1964
2038
|
new_conversation: "Uusi keskustelu",
|
|
@@ -2046,7 +2120,7 @@ const Ee = {
|
|
|
2046
2120
|
questions_send: "Lähetä",
|
|
2047
2121
|
questions_type_answer: "Kirjoitan itse",
|
|
2048
2122
|
questions_answer_placeholder: "Kirjoita vastauksesi…"
|
|
2049
|
-
},
|
|
2123
|
+
}, Oe = {
|
|
2050
2124
|
write_a_message_placeholder: "Écrivez un message...",
|
|
2051
2125
|
your_issue_has_been_resolved: "Votre problème a été résolu !",
|
|
2052
2126
|
new_conversation: "Nouvelle conversation",
|
|
@@ -2134,7 +2208,7 @@ const Ee = {
|
|
|
2134
2208
|
questions_send: "Envoyer",
|
|
2135
2209
|
questions_type_answer: "Je préfère écrire",
|
|
2136
2210
|
questions_answer_placeholder: "Écrivez votre réponse…"
|
|
2137
|
-
},
|
|
2211
|
+
}, Ue = {
|
|
2138
2212
|
write_a_message_placeholder: "एक संदेश लिखें...",
|
|
2139
2213
|
your_issue_has_been_resolved: "आपकी समस्या हल हो गई है!",
|
|
2140
2214
|
new_conversation: "नई बातचीत",
|
|
@@ -2222,7 +2296,7 @@ const Ee = {
|
|
|
2222
2296
|
questions_send: "भेजें",
|
|
2223
2297
|
questions_type_answer: "मैं खुद लिखूंगा",
|
|
2224
2298
|
questions_answer_placeholder: "अपना उत्तर लिखें…"
|
|
2225
|
-
},
|
|
2299
|
+
}, Be = {
|
|
2226
2300
|
write_a_message_placeholder: "Scrivi un messaggio...",
|
|
2227
2301
|
your_issue_has_been_resolved: "Il tuo problema è stato risolto!",
|
|
2228
2302
|
new_conversation: "Nuova conversazione",
|
|
@@ -2310,7 +2384,7 @@ const Ee = {
|
|
|
2310
2384
|
questions_send: "Invia",
|
|
2311
2385
|
questions_type_answer: "Lo scrivo io",
|
|
2312
2386
|
questions_answer_placeholder: "Scrivi la tua risposta…"
|
|
2313
|
-
},
|
|
2387
|
+
}, Ve = {
|
|
2314
2388
|
write_a_message_placeholder: "メッセージを入力...",
|
|
2315
2389
|
your_issue_has_been_resolved: "問題が解決しました!",
|
|
2316
2390
|
new_conversation: "新しい会話",
|
|
@@ -2398,7 +2472,7 @@ const Ee = {
|
|
|
2398
2472
|
questions_send: "送信",
|
|
2399
2473
|
questions_type_answer: "自分で入力する",
|
|
2400
2474
|
questions_answer_placeholder: "回答を入力してください…"
|
|
2401
|
-
},
|
|
2475
|
+
}, He = {
|
|
2402
2476
|
write_a_message_placeholder: "메시지를 입력하세요...",
|
|
2403
2477
|
your_issue_has_been_resolved: "문제가 해결되었습니다!",
|
|
2404
2478
|
new_conversation: "새 대화",
|
|
@@ -2486,7 +2560,7 @@ const Ee = {
|
|
|
2486
2560
|
questions_send: "보내기",
|
|
2487
2561
|
questions_type_answer: "직접 입력할게요",
|
|
2488
2562
|
questions_answer_placeholder: "답변을 입력하세요…"
|
|
2489
|
-
},
|
|
2563
|
+
}, Ge = {
|
|
2490
2564
|
write_a_message_placeholder: "Schrijf een bericht...",
|
|
2491
2565
|
your_issue_has_been_resolved: "Uw probleem is opgelost!",
|
|
2492
2566
|
new_conversation: "Nieuw gesprek",
|
|
@@ -2574,7 +2648,7 @@ const Ee = {
|
|
|
2574
2648
|
questions_send: "Verzenden",
|
|
2575
2649
|
questions_type_answer: "Ik typ het zelf",
|
|
2576
2650
|
questions_answer_placeholder: "Typ je antwoord…"
|
|
2577
|
-
},
|
|
2651
|
+
}, We = {
|
|
2578
2652
|
write_a_message_placeholder: "Skriv en melding...",
|
|
2579
2653
|
your_issue_has_been_resolved: "Problemet ditt er løst!",
|
|
2580
2654
|
new_conversation: "Ny samtale",
|
|
@@ -2662,7 +2736,7 @@ const Ee = {
|
|
|
2662
2736
|
questions_send: "Send",
|
|
2663
2737
|
questions_type_answer: "Jeg skriver det selv",
|
|
2664
2738
|
questions_answer_placeholder: "Skriv svaret ditt…"
|
|
2665
|
-
},
|
|
2739
|
+
}, $e = {
|
|
2666
2740
|
write_a_message_placeholder: "Napisz wiadomość...",
|
|
2667
2741
|
your_issue_has_been_resolved: "Twój problem został rozwiązany!",
|
|
2668
2742
|
new_conversation: "Nowa rozmowa",
|
|
@@ -2750,7 +2824,7 @@ const Ee = {
|
|
|
2750
2824
|
questions_send: "Wyślij",
|
|
2751
2825
|
questions_type_answer: "Napiszę sam",
|
|
2752
2826
|
questions_answer_placeholder: "Wpisz swoją odpowiedź…"
|
|
2753
|
-
},
|
|
2827
|
+
}, Ze = {
|
|
2754
2828
|
write_a_message_placeholder: "Escreva uma mensagem...",
|
|
2755
2829
|
your_issue_has_been_resolved: "Seu problema foi resolvido!",
|
|
2756
2830
|
new_conversation: "Nova conversa",
|
|
@@ -2838,7 +2912,7 @@ const Ee = {
|
|
|
2838
2912
|
questions_send: "Enviar",
|
|
2839
2913
|
questions_type_answer: "Prefiro escrever",
|
|
2840
2914
|
questions_answer_placeholder: "Escreva a sua resposta…"
|
|
2841
|
-
},
|
|
2915
|
+
}, Je = {
|
|
2842
2916
|
write_a_message_placeholder: "Scrie un mesaj...",
|
|
2843
2917
|
your_issue_has_been_resolved: "Problema ta a fost rezolvată!",
|
|
2844
2918
|
new_conversation: "Conversație nouă",
|
|
@@ -2926,7 +3000,7 @@ const Ee = {
|
|
|
2926
3000
|
questions_send: "Trimite",
|
|
2927
3001
|
questions_type_answer: "Scriu eu",
|
|
2928
3002
|
questions_answer_placeholder: "Scrieți răspunsul dvs.…"
|
|
2929
|
-
},
|
|
3003
|
+
}, Ye = {
|
|
2930
3004
|
write_a_message_placeholder: "Skriv ett meddelande...",
|
|
2931
3005
|
your_issue_has_been_resolved: "Ditt problem har lösts!",
|
|
2932
3006
|
new_conversation: "Ny konversation",
|
|
@@ -3014,7 +3088,7 @@ const Ee = {
|
|
|
3014
3088
|
questions_send: "Skicka",
|
|
3015
3089
|
questions_type_answer: "Jag skriver själv",
|
|
3016
3090
|
questions_answer_placeholder: "Skriv ditt svar…"
|
|
3017
|
-
},
|
|
3091
|
+
}, Qe = {
|
|
3018
3092
|
write_a_message_placeholder: "Напишите сообщение...",
|
|
3019
3093
|
your_issue_has_been_resolved: "Ваша проблема решена!",
|
|
3020
3094
|
new_conversation: "Новый разговор",
|
|
@@ -3102,7 +3176,7 @@ const Ee = {
|
|
|
3102
3176
|
questions_send: "Отправить",
|
|
3103
3177
|
questions_type_answer: "Напишу сам",
|
|
3104
3178
|
questions_answer_placeholder: "Напишите ваш ответ…"
|
|
3105
|
-
},
|
|
3179
|
+
}, Xe = {
|
|
3106
3180
|
write_a_message_placeholder: "เขียนข้อความ...",
|
|
3107
3181
|
your_issue_has_been_resolved: "ปัญหาของคุณได้รับการแก้ไขแล้ว!",
|
|
3108
3182
|
new_conversation: "การสนทนาใหม่",
|
|
@@ -3190,7 +3264,7 @@ const Ee = {
|
|
|
3190
3264
|
questions_send: "ส่ง",
|
|
3191
3265
|
questions_type_answer: "ขอพิมพ์เอง",
|
|
3192
3266
|
questions_answer_placeholder: "พิมพ์คำตอบของคุณ…"
|
|
3193
|
-
},
|
|
3267
|
+
}, ea = {
|
|
3194
3268
|
write_a_message_placeholder: "Bir mesaj yazın...",
|
|
3195
3269
|
your_issue_has_been_resolved: "Sorununuz çözüldü!",
|
|
3196
3270
|
new_conversation: "Yeni konuşma",
|
|
@@ -3278,7 +3352,7 @@ const Ee = {
|
|
|
3278
3352
|
questions_send: "Gönder",
|
|
3279
3353
|
questions_type_answer: "Kendim yazayım",
|
|
3280
3354
|
questions_answer_placeholder: "Yanıtınızı yazın…"
|
|
3281
|
-
},
|
|
3355
|
+
}, aa = {
|
|
3282
3356
|
write_a_message_placeholder: "پیغام لکھیں...",
|
|
3283
3357
|
your_issue_has_been_resolved: "آپ کا مسئلہ حل ہو گیا ہے!",
|
|
3284
3358
|
new_conversation: "نئی گفتگو",
|
|
@@ -3366,7 +3440,7 @@ const Ee = {
|
|
|
3366
3440
|
questions_send: "بھیجیں",
|
|
3367
3441
|
questions_type_answer: "میں خود لکھوں گا",
|
|
3368
3442
|
questions_answer_placeholder: "اپنا جواب لکھیں…"
|
|
3369
|
-
},
|
|
3443
|
+
}, ta = {
|
|
3370
3444
|
write_a_message_placeholder: "Viết tin nhắn...",
|
|
3371
3445
|
your_issue_has_been_resolved: "Vấn đề của bạn đã được giải quyết!",
|
|
3372
3446
|
new_conversation: "Cuộc trò chuyện mới",
|
|
@@ -3454,7 +3528,7 @@ const Ee = {
|
|
|
3454
3528
|
questions_send: "Gửi",
|
|
3455
3529
|
questions_type_answer: "Tôi sẽ tự nhập",
|
|
3456
3530
|
questions_answer_placeholder: "Nhập câu trả lời của bạn…"
|
|
3457
|
-
},
|
|
3531
|
+
}, sa = {
|
|
3458
3532
|
write_a_message_placeholder: "写一条消息...",
|
|
3459
3533
|
your_issue_has_been_resolved: "您的问题已解决!",
|
|
3460
3534
|
new_conversation: "新对话",
|
|
@@ -3542,7 +3616,7 @@ const Ee = {
|
|
|
3542
3616
|
questions_send: "发送",
|
|
3543
3617
|
questions_type_answer: "我自己输入",
|
|
3544
3618
|
questions_answer_placeholder: "输入你的回答…"
|
|
3545
|
-
},
|
|
3619
|
+
}, na = {
|
|
3546
3620
|
write_a_message_placeholder: "Napišite poruku...",
|
|
3547
3621
|
your_issue_has_been_resolved: "Vaš problem je riješen!",
|
|
3548
3622
|
new_conversation: "Novi razgovor",
|
|
@@ -3630,7 +3704,7 @@ const Ee = {
|
|
|
3630
3704
|
questions_send: "Pošalji",
|
|
3631
3705
|
questions_type_answer: "Napisat ću sam",
|
|
3632
3706
|
questions_answer_placeholder: "Napišite svoj odgovor…"
|
|
3633
|
-
},
|
|
3707
|
+
}, oa = {
|
|
3634
3708
|
write_a_message_placeholder: "Kirjuta sõnum...",
|
|
3635
3709
|
your_issue_has_been_resolved: "Teie probleem on lahendatud!",
|
|
3636
3710
|
new_conversation: "Uus vestlus",
|
|
@@ -3718,7 +3792,7 @@ const Ee = {
|
|
|
3718
3792
|
questions_send: "Saada",
|
|
3719
3793
|
questions_type_answer: "Kirjutan ise",
|
|
3720
3794
|
questions_answer_placeholder: "Kirjutage oma vastus…"
|
|
3721
|
-
},
|
|
3795
|
+
}, ia = {
|
|
3722
3796
|
write_a_message_placeholder: "Írjon üzenetet...",
|
|
3723
3797
|
your_issue_has_been_resolved: "A problémája megoldódott!",
|
|
3724
3798
|
new_conversation: "Új beszélgetés",
|
|
@@ -3806,7 +3880,7 @@ const Ee = {
|
|
|
3806
3880
|
questions_send: "Küldés",
|
|
3807
3881
|
questions_type_answer: "Inkább leírom",
|
|
3808
3882
|
questions_answer_placeholder: "Írja le a válaszát…"
|
|
3809
|
-
},
|
|
3883
|
+
}, ra = {
|
|
3810
3884
|
write_a_message_placeholder: "Skrifaðu skilaboð...",
|
|
3811
3885
|
your_issue_has_been_resolved: "Málið þitt hefur verið leyst!",
|
|
3812
3886
|
new_conversation: "Nýtt samtal",
|
|
@@ -3894,7 +3968,7 @@ const Ee = {
|
|
|
3894
3968
|
questions_send: "Senda",
|
|
3895
3969
|
questions_type_answer: "Ég skrifa það",
|
|
3896
3970
|
questions_answer_placeholder: "Skrifaðu svarið þitt…"
|
|
3897
|
-
},
|
|
3971
|
+
}, _a = {
|
|
3898
3972
|
write_a_message_placeholder: "Rakstiet ziņojumu...",
|
|
3899
3973
|
your_issue_has_been_resolved: "Jūsu problēma ir atrisināta!",
|
|
3900
3974
|
new_conversation: "Jauna saruna",
|
|
@@ -3982,7 +4056,7 @@ const Ee = {
|
|
|
3982
4056
|
questions_send: "Sūtīt",
|
|
3983
4057
|
questions_type_answer: "Rakstīšu pats",
|
|
3984
4058
|
questions_answer_placeholder: "Ierakstiet savu atbildi…"
|
|
3985
|
-
},
|
|
4059
|
+
}, la = {
|
|
3986
4060
|
write_a_message_placeholder: "Parašykite žinutę...",
|
|
3987
4061
|
your_issue_has_been_resolved: "Jūsų problema išspręsta!",
|
|
3988
4062
|
new_conversation: "Naujas pokalbis",
|
|
@@ -4070,7 +4144,7 @@ const Ee = {
|
|
|
4070
4144
|
questions_send: "Siųsti",
|
|
4071
4145
|
questions_type_answer: "Parašysiu pats",
|
|
4072
4146
|
questions_answer_placeholder: "Parašykite savo atsakymą…"
|
|
4073
|
-
},
|
|
4147
|
+
}, ca = {
|
|
4074
4148
|
write_a_message_placeholder: "Schreift eng Noriicht...",
|
|
4075
4149
|
your_issue_has_been_resolved: "Äert Problem gouf geléist!",
|
|
4076
4150
|
new_conversation: "Nei Konversatioun",
|
|
@@ -4158,7 +4232,7 @@ const Ee = {
|
|
|
4158
4232
|
questions_send: "Schécken",
|
|
4159
4233
|
questions_type_answer: "Ech schreiwen et selwer",
|
|
4160
4234
|
questions_answer_placeholder: "Schreift Är Äntwert…"
|
|
4161
|
-
},
|
|
4235
|
+
}, pa = {
|
|
4162
4236
|
write_a_message_placeholder: "Ikteb messaġġ...",
|
|
4163
4237
|
your_issue_has_been_resolved: "Il-problema tiegħek ġiet riżolta!",
|
|
4164
4238
|
new_conversation: "Konversazzjoni ġdida",
|
|
@@ -4246,7 +4320,7 @@ const Ee = {
|
|
|
4246
4320
|
questions_send: "Ibgħat",
|
|
4247
4321
|
questions_type_answer: "Nikteb jien",
|
|
4248
4322
|
questions_answer_placeholder: "Ikteb it-tweġiba tiegħek…"
|
|
4249
|
-
},
|
|
4323
|
+
}, da = {
|
|
4250
4324
|
write_a_message_placeholder: "Skriv en melding...",
|
|
4251
4325
|
your_issue_has_been_resolved: "Saken din er løst!",
|
|
4252
4326
|
new_conversation: "Ny samtale",
|
|
@@ -4334,7 +4408,7 @@ const Ee = {
|
|
|
4334
4408
|
questions_send: "Send",
|
|
4335
4409
|
questions_type_answer: "Jeg skriver det selv",
|
|
4336
4410
|
questions_answer_placeholder: "Skriv svaret ditt…"
|
|
4337
|
-
},
|
|
4411
|
+
}, ua = {
|
|
4338
4412
|
write_a_message_placeholder: "Napíšte správu...",
|
|
4339
4413
|
your_issue_has_been_resolved: "Váš problém bol vyriešený!",
|
|
4340
4414
|
new_conversation: "Nová konverzácia",
|
|
@@ -4422,85 +4496,86 @@ const Ee = {
|
|
|
4422
4496
|
questions_send: "Odoslať",
|
|
4423
4497
|
questions_type_answer: "Napíšem to sám",
|
|
4424
4498
|
questions_answer_placeholder: "Napíšte svoju odpoveď…"
|
|
4425
|
-
},
|
|
4426
|
-
ar:
|
|
4427
|
-
bn:
|
|
4428
|
-
bg:
|
|
4429
|
-
cs:
|
|
4430
|
-
da:
|
|
4431
|
-
de:
|
|
4432
|
-
el:
|
|
4433
|
-
en:
|
|
4434
|
-
es:
|
|
4435
|
-
et:
|
|
4436
|
-
fi:
|
|
4437
|
-
fil:
|
|
4438
|
-
fr:
|
|
4439
|
-
hi:
|
|
4440
|
-
hr:
|
|
4441
|
-
hu:
|
|
4442
|
-
is:
|
|
4443
|
-
it:
|
|
4444
|
-
ja:
|
|
4445
|
-
ko:
|
|
4446
|
-
lb:
|
|
4447
|
-
lt:
|
|
4448
|
-
lv:
|
|
4449
|
-
mt:
|
|
4450
|
-
nb:
|
|
4451
|
-
nl:
|
|
4452
|
-
no:
|
|
4453
|
-
pl:
|
|
4454
|
-
pt:
|
|
4455
|
-
ro:
|
|
4456
|
-
ru:
|
|
4457
|
-
sk:
|
|
4458
|
-
sv:
|
|
4459
|
-
th:
|
|
4460
|
-
tr:
|
|
4461
|
-
ur:
|
|
4462
|
-
vi:
|
|
4463
|
-
"zh-cn":
|
|
4464
|
-
}, ma = Object.keys(
|
|
4465
|
-
function
|
|
4466
|
-
return ma.includes(
|
|
4499
|
+
}, W = {
|
|
4500
|
+
ar: Ae,
|
|
4501
|
+
bn: Te,
|
|
4502
|
+
bg: Me,
|
|
4503
|
+
cs: Ie,
|
|
4504
|
+
da: De,
|
|
4505
|
+
de: Re,
|
|
4506
|
+
el: Ne,
|
|
4507
|
+
en: G,
|
|
4508
|
+
es: Ke,
|
|
4509
|
+
et: oa,
|
|
4510
|
+
fi: Fe,
|
|
4511
|
+
fil: Le,
|
|
4512
|
+
fr: Oe,
|
|
4513
|
+
hi: Ue,
|
|
4514
|
+
hr: na,
|
|
4515
|
+
hu: ia,
|
|
4516
|
+
is: ra,
|
|
4517
|
+
it: Be,
|
|
4518
|
+
ja: Ve,
|
|
4519
|
+
ko: He,
|
|
4520
|
+
lb: ca,
|
|
4521
|
+
lt: la,
|
|
4522
|
+
lv: _a,
|
|
4523
|
+
mt: pa,
|
|
4524
|
+
nb: da,
|
|
4525
|
+
nl: Ge,
|
|
4526
|
+
no: We,
|
|
4527
|
+
pl: $e,
|
|
4528
|
+
pt: Ze,
|
|
4529
|
+
ro: Je,
|
|
4530
|
+
ru: Qe,
|
|
4531
|
+
sk: ua,
|
|
4532
|
+
sv: Ye,
|
|
4533
|
+
th: Xe,
|
|
4534
|
+
tr: ea,
|
|
4535
|
+
ur: aa,
|
|
4536
|
+
vi: ta,
|
|
4537
|
+
"zh-cn": sa
|
|
4538
|
+
}, ma = Object.keys(W);
|
|
4539
|
+
function ha(_) {
|
|
4540
|
+
return ma.includes(_);
|
|
4467
4541
|
}
|
|
4468
|
-
const
|
|
4469
|
-
function
|
|
4470
|
-
return
|
|
4542
|
+
const ga = /* @__PURE__ */ new Set(["ar", "ur"]);
|
|
4543
|
+
function La(_) {
|
|
4544
|
+
return ga.has(_);
|
|
4471
4545
|
}
|
|
4472
|
-
function
|
|
4473
|
-
return
|
|
4546
|
+
function ka(_) {
|
|
4547
|
+
return ha(_) ? _ : "en";
|
|
4474
4548
|
}
|
|
4475
|
-
function
|
|
4549
|
+
function ba(_, e, a, n) {
|
|
4476
4550
|
var l;
|
|
4477
|
-
const
|
|
4478
|
-
return
|
|
4551
|
+
const i = ((l = a == null ? void 0 : a[e]) == null ? void 0 : l[_]) || W[e][_] || G[_] || _;
|
|
4552
|
+
return n ? i.replace(
|
|
4479
4553
|
/\{(\w+)\}/g,
|
|
4480
|
-
(
|
|
4481
|
-
) :
|
|
4554
|
+
(o, t) => t in n ? String(n[t]) : o
|
|
4555
|
+
) : i;
|
|
4482
4556
|
}
|
|
4483
|
-
function
|
|
4484
|
-
return
|
|
4557
|
+
function fa(_, e, a) {
|
|
4558
|
+
return ba(
|
|
4485
4559
|
e,
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4560
|
+
ka(_.language),
|
|
4561
|
+
_.translationOverrides,
|
|
4562
|
+
a
|
|
4489
4563
|
);
|
|
4490
4564
|
}
|
|
4491
|
-
class
|
|
4565
|
+
class va {
|
|
4492
4566
|
constructor({
|
|
4493
4567
|
config: e,
|
|
4494
|
-
api:
|
|
4495
|
-
contactCtx:
|
|
4496
|
-
storageCtx:
|
|
4497
|
-
sessionsPollingIntervalSeconds: l
|
|
4568
|
+
api: a,
|
|
4569
|
+
contactCtx: n,
|
|
4570
|
+
storageCtx: i,
|
|
4571
|
+
sessionsPollingIntervalSeconds: l,
|
|
4572
|
+
sharedSessions: o
|
|
4498
4573
|
}) {
|
|
4499
|
-
this.sessionsRefresher = new V(), this.persistedSessionId = null, this.sessionState = new
|
|
4574
|
+
this.sessionsRefresher = new V(), this.persistedSessionId = null, this.sessionAbortController = new AbortController(), this.sessionState = new w({
|
|
4500
4575
|
session: null,
|
|
4501
4576
|
isCreatingSession: !1,
|
|
4502
4577
|
isResolvingSession: !1
|
|
4503
|
-
}), this.sessionsState = new
|
|
4578
|
+
}), this.sessionsState = new w({
|
|
4504
4579
|
data: [],
|
|
4505
4580
|
cursor: void 0,
|
|
4506
4581
|
isLastPage: !1,
|
|
@@ -4510,14 +4585,25 @@ class fa {
|
|
|
4510
4585
|
*/
|
|
4511
4586
|
isInitialFetchLoading: !0
|
|
4512
4587
|
}), this.registerActiveSessionPersistence = () => {
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4588
|
+
this.storageCtx && (this.stopPersistingSession = this.sessionState.subscribe(
|
|
4589
|
+
this.persistSession
|
|
4590
|
+
));
|
|
4591
|
+
}, this.restoreActiveSessionTracking = () => {
|
|
4592
|
+
var t;
|
|
4593
|
+
(t = this.stopPersistingSession) == null || t.call(this), this.stopPersistingSession = void 0, this.registerActiveSessionPersistence();
|
|
4594
|
+
}, this.trackActiveSession = (t) => {
|
|
4595
|
+
var s;
|
|
4596
|
+
(s = this.stopPersistingSession) == null || s.call(this), this.stopPersistingSession = t.sessionState.subscribe(
|
|
4597
|
+
this.persistSession
|
|
4598
|
+
), this.persistSession(t.sessionState.get());
|
|
4599
|
+
}, this.persistSession = ({ session: t }) => {
|
|
4600
|
+
const s = this.storageCtx;
|
|
4601
|
+
if (!s) return;
|
|
4602
|
+
const r = t != null && t.isOpened ? t.id : null;
|
|
4603
|
+
if (r === this.persistedSessionId || !r && this.persistedSessionId === null) return;
|
|
4604
|
+
this.persistedSessionId = r, (r ? s.setActiveSessionId(r) : s.clearActiveSessionId()).catch((p) => {
|
|
4605
|
+
m.warn("failed to persist the active session", {
|
|
4606
|
+
error: p instanceof Error ? p.message : String(p)
|
|
4521
4607
|
});
|
|
4522
4608
|
});
|
|
4523
4609
|
}, this.getLastActiveSessionId = async () => {
|
|
@@ -4528,12 +4614,12 @@ class fa {
|
|
|
4528
4614
|
return null;
|
|
4529
4615
|
}
|
|
4530
4616
|
}, this.reset = async () => {
|
|
4531
|
-
this.sessionState.reset();
|
|
4617
|
+
this.sessionAbortController.abort(), this.sessionAbortController = new AbortController(), this.sessionState.reset();
|
|
4532
4618
|
}, this.registerSessionsRefresherWrapper = () => {
|
|
4533
|
-
var
|
|
4619
|
+
var t;
|
|
4534
4620
|
// If the widget config was initially provided with a contact token, no state change would be triggered, so we just fetch
|
|
4535
|
-
(
|
|
4536
|
-
|
|
4621
|
+
(t = this.contactCtx.state.get().contact) != null && t.token && !this.sessionsState.get().didStartInitialFetch ? this.registerSessionsRefresher() : this.contactCtx.state.subscribe(({ contact: s }) => {
|
|
4622
|
+
s != null && s.token && !this.sessionsState.get().didStartInitialFetch && this.registerSessionsRefresher();
|
|
4537
4623
|
});
|
|
4538
4624
|
}, this.registerSessionsRefresher = () => {
|
|
4539
4625
|
this.sessionsRefresher.startPolling(async () => {
|
|
@@ -4541,182 +4627,196 @@ class fa {
|
|
|
4541
4627
|
}, this.sessionsPollingIntervalSeconds * 1e3);
|
|
4542
4628
|
}, this.getParsedCustomData = () => Object.fromEntries(
|
|
4543
4629
|
Object.entries(this.config.sessionCustomData || {}).map(
|
|
4544
|
-
([
|
|
4545
|
-
var
|
|
4546
|
-
return typeof
|
|
4630
|
+
([t, s]) => {
|
|
4631
|
+
var r;
|
|
4632
|
+
return typeof s == "string" ? [t, s] : typeof s == "boolean" ? [t, s] : typeof s == "number" ? [t, s] : [t, ((r = H(() => JSON.stringify(s))) == null ? void 0 : r.data) || ""];
|
|
4547
4633
|
}
|
|
4548
4634
|
)
|
|
4549
4635
|
), this.createSession = async () => {
|
|
4636
|
+
const { signal: t } = this.sessionAbortController;
|
|
4550
4637
|
this.sessionState.setPartial({ session: null, isCreatingSession: !0 });
|
|
4551
4638
|
try {
|
|
4552
|
-
const
|
|
4553
|
-
if (
|
|
4554
|
-
if (
|
|
4555
|
-
|
|
4556
|
-
|
|
4639
|
+
const s = await this.requestSession(t);
|
|
4640
|
+
if (t.aborted) return null;
|
|
4641
|
+
if (s.session) return s.session;
|
|
4642
|
+
if (s.status === 401 && await this.contactCtx.recoverFromStaleToken()) {
|
|
4643
|
+
if (t.aborted) return null;
|
|
4644
|
+
const r = await this.requestSession(t);
|
|
4645
|
+
return t.aborted ? null : r.session ? r.session : (m.error("failed to create session", r.error), null);
|
|
4557
4646
|
}
|
|
4558
|
-
return
|
|
4559
|
-
} catch (
|
|
4560
|
-
return
|
|
4647
|
+
return m.error("failed to create session", s.error), null;
|
|
4648
|
+
} catch (s) {
|
|
4649
|
+
return t.aborted || m.error("failed to create session", s), null;
|
|
4561
4650
|
} finally {
|
|
4562
|
-
this.sessionState.setPartial({ isCreatingSession: !1 });
|
|
4651
|
+
t.aborted || this.sessionState.setPartial({ isCreatingSession: !1 });
|
|
4563
4652
|
}
|
|
4564
|
-
}, this.requestSession = async () => {
|
|
4565
|
-
var
|
|
4566
|
-
const
|
|
4653
|
+
}, this.requestSession = async (t) => {
|
|
4654
|
+
var u, g, h;
|
|
4655
|
+
const s = (u = this.contactCtx.state.get().contact) == null ? void 0 : u.externalId, r = {
|
|
4567
4656
|
...this.getParsedCustomData(),
|
|
4568
|
-
...
|
|
4657
|
+
...s ? { external_id: s } : {}
|
|
4569
4658
|
}, {
|
|
4570
|
-
data:
|
|
4571
|
-
error:
|
|
4572
|
-
response:
|
|
4573
|
-
} = await this.api.createSession(
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4659
|
+
data: c,
|
|
4660
|
+
error: p,
|
|
4661
|
+
response: d
|
|
4662
|
+
} = await this.api.createSession(
|
|
4663
|
+
{
|
|
4664
|
+
customData: Object.keys(r).length > 0 ? r : void 0
|
|
4665
|
+
},
|
|
4666
|
+
t
|
|
4667
|
+
);
|
|
4668
|
+
if (t.aborted || !c)
|
|
4669
|
+
return { session: null, status: d == null ? void 0 : d.status, error: p };
|
|
4670
|
+
this.sessionState.setPartial({ session: c });
|
|
4578
4671
|
try {
|
|
4579
|
-
(
|
|
4580
|
-
} catch (
|
|
4581
|
-
|
|
4672
|
+
(h = (g = this.config.hooks) == null ? void 0 : g.onSessionCreated) == null || h.call(g, { session: c });
|
|
4673
|
+
} catch (v) {
|
|
4674
|
+
m.error("onSessionCreated hook failed", v);
|
|
4582
4675
|
}
|
|
4583
|
-
return { session:
|
|
4676
|
+
return { session: c, status: d.status, error: void 0 };
|
|
4584
4677
|
}, this.loadMoreSessions = async () => {
|
|
4585
4678
|
if (this.sessionsState.get().isLastPage) return;
|
|
4586
|
-
const { data:
|
|
4679
|
+
const { data: t } = await this.getSessions({
|
|
4587
4680
|
cursor: this.sessionsState.get().cursor
|
|
4588
4681
|
});
|
|
4589
|
-
if (
|
|
4590
|
-
const
|
|
4591
|
-
(
|
|
4682
|
+
if (t) {
|
|
4683
|
+
const r = [...this.sessionsState.get().data, ...t.items].filter(
|
|
4684
|
+
(c, p, d) => p === d.findIndex((u) => c.id === u.id)
|
|
4592
4685
|
);
|
|
4593
4686
|
this.sessionsState.setPartial({
|
|
4594
|
-
data:
|
|
4595
|
-
cursor:
|
|
4596
|
-
isLastPage:
|
|
4687
|
+
data: r,
|
|
4688
|
+
cursor: t.next || void 0,
|
|
4689
|
+
isLastPage: t.next === null
|
|
4597
4690
|
});
|
|
4598
4691
|
}
|
|
4599
|
-
}, this.getSessions = async ({ cursor:
|
|
4600
|
-
var
|
|
4601
|
-
if (!((
|
|
4602
|
-
const
|
|
4692
|
+
}, this.getSessions = async ({ cursor: t }) => {
|
|
4693
|
+
var r, c;
|
|
4694
|
+
if (!((r = this.contactCtx.state.get().contact) != null && r.token)) return { data: null };
|
|
4695
|
+
const s = (c = this.contactCtx.state.get().contact) == null ? void 0 : c.externalId;
|
|
4603
4696
|
return await this.api.getSessions({
|
|
4604
|
-
cursor:
|
|
4605
|
-
filters:
|
|
4606
|
-
external_id:
|
|
4697
|
+
cursor: t,
|
|
4698
|
+
filters: s ? {
|
|
4699
|
+
external_id: s
|
|
4607
4700
|
} : {}
|
|
4608
4701
|
});
|
|
4609
|
-
}, this.setSessions = (
|
|
4610
|
-
const
|
|
4611
|
-
(
|
|
4702
|
+
}, this.setSessions = (t) => {
|
|
4703
|
+
const s = [...t, ...this.sessionsState.get().data].filter(
|
|
4704
|
+
(r, c, p) => c === p.findIndex((d) => r.id === d.id)
|
|
4612
4705
|
);
|
|
4613
|
-
this.sessionsState.setPartial({ data:
|
|
4706
|
+
this.sessionsState.setPartial({ data: s });
|
|
4614
4707
|
}, this.refreshSessions = async () => {
|
|
4615
|
-
const { data:
|
|
4616
|
-
|
|
4708
|
+
const { data: t } = await this.getSessions({ cursor: void 0 });
|
|
4709
|
+
t && this.setSessions(t.items);
|
|
4617
4710
|
}, this.resolveSession = async () => {
|
|
4618
|
-
const
|
|
4619
|
-
if (!
|
|
4711
|
+
const t = this.sessionState.get().session;
|
|
4712
|
+
if (!t || !t.isOpened)
|
|
4620
4713
|
return { success: !1, error: "Session is not opened" };
|
|
4621
4714
|
this.sessionState.setPartial({ isResolvingSession: !0 });
|
|
4622
|
-
const {
|
|
4623
|
-
|
|
4715
|
+
const { signal: s } = this.sessionAbortController, r = await this.api.resolveSession({ session_id: t.id }, s).catch((d) => {
|
|
4716
|
+
if (s.aborted) return null;
|
|
4717
|
+
throw d;
|
|
4624
4718
|
});
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4719
|
+
if (!r || s.aborted)
|
|
4720
|
+
return { success: !1, error: "Session was reset" };
|
|
4721
|
+
const { data: c, error: p } = r;
|
|
4722
|
+
return c ? (this.sessionState.setPartial({ session: c, isResolvingSession: !1 }), { success: !0, data: c }) : (this.sessionState.setPartial({ isResolvingSession: !1 }), { success: !1, error: p });
|
|
4723
|
+
}, this.createStateCheckpoint = async (t) => {
|
|
4724
|
+
var c;
|
|
4725
|
+
const s = (c = this.sessionState.get().session) == null ? void 0 : c.id;
|
|
4726
|
+
if (!s) return;
|
|
4727
|
+
const { data: r } = await this.api.createStateCheckpoint({
|
|
4728
|
+
session_id: s,
|
|
4729
|
+
payload: t
|
|
4633
4730
|
});
|
|
4634
|
-
return
|
|
4635
|
-
}, this.config = e, this.api =
|
|
4731
|
+
return r != null && r.success ? { success: !0 } : { success: !1 };
|
|
4732
|
+
}, this.config = e, this.api = a, this.contactCtx = n, this.storageCtx = i, this.sessionsPollingIntervalSeconds = l, o ? this.sessionsState = o : this.registerSessionsRefresherWrapper(), this.registerActiveSessionPersistence();
|
|
4636
4733
|
}
|
|
4637
4734
|
}
|
|
4638
|
-
const
|
|
4639
|
-
const
|
|
4735
|
+
const ya = (_, e, { sendsPageContext: a }) => {
|
|
4736
|
+
const n = Sa(_), i = a && e.mentions && e.mentions.length > 0 ? { mentions: e.mentions.map(wa) } : void 0, l = a && (e.clientContext || i) ? { ...n, ...e.clientContext, ...i } : n;
|
|
4640
4737
|
return {
|
|
4641
|
-
clientContext: e.withPageEntity === !1 && l && "entity" in l ?
|
|
4738
|
+
clientContext: e.withPageEntity === !1 && l && "entity" in l ? ja(l, "entity") : l,
|
|
4642
4739
|
custom_data: {
|
|
4643
|
-
...
|
|
4740
|
+
..._.messageCustomData || {},
|
|
4644
4741
|
...e.customData || {}
|
|
4645
4742
|
}
|
|
4646
4743
|
};
|
|
4647
|
-
},
|
|
4648
|
-
type:
|
|
4744
|
+
}, wa = ({ type: _, id: e, title: a, meta: n }) => ({
|
|
4745
|
+
type: _,
|
|
4649
4746
|
id: e,
|
|
4650
|
-
title:
|
|
4651
|
-
...
|
|
4652
|
-
}),
|
|
4653
|
-
const { [e]:
|
|
4654
|
-
return Object.keys(
|
|
4655
|
-
},
|
|
4656
|
-
if (typeof
|
|
4747
|
+
title: a,
|
|
4748
|
+
...n ? { meta: n } : {}
|
|
4749
|
+
}), ja = (_, e) => {
|
|
4750
|
+
const { [e]: a, ...n } = _;
|
|
4751
|
+
return Object.keys(n).length > 0 ? n : void 0;
|
|
4752
|
+
}, Sa = (_) => {
|
|
4753
|
+
if (typeof _.context != "function") return _.context;
|
|
4657
4754
|
try {
|
|
4658
|
-
return
|
|
4755
|
+
return _.context();
|
|
4659
4756
|
} catch (e) {
|
|
4660
|
-
|
|
4757
|
+
m.error("context getter threw; sending without context", e);
|
|
4661
4758
|
return;
|
|
4662
4759
|
}
|
|
4663
|
-
},
|
|
4664
|
-
const e =
|
|
4760
|
+
}, xa = (_) => {
|
|
4761
|
+
const e = _.features;
|
|
4665
4762
|
if (!e) return;
|
|
4666
|
-
const
|
|
4667
|
-
return e.preamble !== void 0 && (
|
|
4763
|
+
const a = {};
|
|
4764
|
+
return e.preamble !== void 0 && (a.preamble = e.preamble), e.inlineUi !== void 0 && (a.inline_ui = e.inlineUi), e.pageContext !== void 0 && (a.page_context = e.pageContext), e.clientTools !== void 0 && (a.client_tools = e.clientTools), Object.keys(a).length > 0 ? a : void 0;
|
|
4668
4765
|
}, za = ({
|
|
4669
|
-
config:
|
|
4766
|
+
config: _,
|
|
4670
4767
|
input: e,
|
|
4671
|
-
uuid:
|
|
4672
|
-
sessionId:
|
|
4673
|
-
content:
|
|
4768
|
+
uuid: a,
|
|
4769
|
+
sessionId: n,
|
|
4770
|
+
content: i,
|
|
4674
4771
|
initialMessages: l,
|
|
4675
|
-
sendsPageContext:
|
|
4772
|
+
sendsPageContext: o
|
|
4676
4773
|
}) => {
|
|
4677
|
-
var
|
|
4774
|
+
var t;
|
|
4678
4775
|
return {
|
|
4679
|
-
uuid:
|
|
4680
|
-
bot_token:
|
|
4681
|
-
headers:
|
|
4682
|
-
query_params:
|
|
4683
|
-
body_properties:
|
|
4684
|
-
session_id:
|
|
4685
|
-
content:
|
|
4776
|
+
uuid: a,
|
|
4777
|
+
bot_token: _.token,
|
|
4778
|
+
headers: _.headers,
|
|
4779
|
+
query_params: _.queryParams,
|
|
4780
|
+
body_properties: _.bodyProperties,
|
|
4781
|
+
session_id: n,
|
|
4782
|
+
content: i,
|
|
4686
4783
|
attachments: e.attachments,
|
|
4687
|
-
...
|
|
4688
|
-
language:
|
|
4689
|
-
features:
|
|
4690
|
-
capabilities: ((
|
|
4784
|
+
...ya(_, e, { sendsPageContext: o }),
|
|
4785
|
+
language: _.language,
|
|
4786
|
+
features: xa(_),
|
|
4787
|
+
capabilities: ((t = _.capabilities) == null ? void 0 : t.structuredQuestions) === void 0 ? void 0 : { structured_questions: _.capabilities.structuredQuestions },
|
|
4691
4788
|
exit_mode_prompt: e.exitModePrompt,
|
|
4692
4789
|
initial_messages: l.length > 0 ? l.map((s) => ({ uuid: s.id, content: s.data.message })) : void 0
|
|
4693
4790
|
};
|
|
4694
|
-
},
|
|
4791
|
+
}, x = class x {
|
|
4695
4792
|
constructor({
|
|
4696
4793
|
config: e,
|
|
4697
|
-
api:
|
|
4698
|
-
sessionCtx:
|
|
4699
|
-
contactCtx:
|
|
4794
|
+
api: a,
|
|
4795
|
+
sessionCtx: n,
|
|
4796
|
+
contactCtx: i,
|
|
4700
4797
|
streaming: l,
|
|
4701
|
-
sendsPageContext:
|
|
4702
|
-
getClientCapabilities:
|
|
4798
|
+
sendsPageContext: o,
|
|
4799
|
+
getClientCapabilities: t
|
|
4703
4800
|
}) {
|
|
4704
|
-
this.state = new
|
|
4801
|
+
this.state = new w({
|
|
4705
4802
|
messages: [],
|
|
4706
4803
|
isSendingMessage: !1,
|
|
4707
4804
|
isSendingMessageToAI: !1,
|
|
4708
4805
|
lastAIResMightSolveUserIssue: !1,
|
|
4709
4806
|
isInitialFetchLoading: !1
|
|
4807
|
+
}), this.draftState = new w({
|
|
4808
|
+
text: "",
|
|
4809
|
+
mentions: []
|
|
4710
4810
|
}), this.agentHandlers = null, this.bufferedAgentSends = [], this.sendMessageAbortController = new AbortController(), this.messageIdsDispatchedToOnMessageReceivedHook = /* @__PURE__ */ new Set(), this.sentTextHistory = [], this.reset = () => {
|
|
4711
|
-
this.sendMessageAbortController.abort("Resetting chat"), this.bufferedAgentSends = [], this.state.reset(), this.messageIdsDispatchedToOnMessageReceivedHook.clear(), this.sentTextHistory = [];
|
|
4811
|
+
this.sendMessageAbortController.abort("Resetting chat"), this.bufferedAgentSends = [], this.state.reset(), this.messageIdsDispatchedToOnMessageReceivedHook.clear(), this.sentTextHistory = [], this.draftState.reset();
|
|
4712
4812
|
}, this.rememberSentText = (s) => {
|
|
4713
4813
|
const r = s.trim();
|
|
4714
|
-
!r || this.sentTextHistory.at(-1) === r || (this.sentTextHistory.push(r), this.sentTextHistory.length >
|
|
4814
|
+
!r || this.sentTextHistory.at(-1) === r || (this.sentTextHistory.push(r), this.sentTextHistory.length > x.SENT_TEXT_HISTORY_MAX && this.sentTextHistory.shift());
|
|
4715
4815
|
}, this.getSentTextHistory = () => this.sentTextHistory, this.registerAgentHandlers = (s) => {
|
|
4716
4816
|
this.agentHandlers = s;
|
|
4717
4817
|
const r = this.bufferedAgentSends;
|
|
4718
4818
|
this.bufferedAgentSends = [], r.forEach((c) => {
|
|
4719
|
-
|
|
4819
|
+
x.dispatchToEngine(s, c);
|
|
4720
4820
|
});
|
|
4721
4821
|
}, this.unregisterAgentHandlers = (s) => {
|
|
4722
4822
|
this.agentHandlers === s && (this.agentHandlers = null);
|
|
@@ -4734,7 +4834,7 @@ const va = (i, e, { sendsPageContext: t }) => {
|
|
|
4734
4834
|
var r, c;
|
|
4735
4835
|
return !((r = this.sessionCtx.sessionState.get().session) != null && r.id) && this.state.get().messages.length === 0 && ((c = this.config.advancedInitialMessages) == null ? void 0 : c.some((p) => p.persistent)) ? (this.config.advancedInitialMessages || []).filter((p) => p.persistent).map(
|
|
4736
4836
|
(p) => ({
|
|
4737
|
-
id:
|
|
4837
|
+
id: z(),
|
|
4738
4838
|
component: "bot_message",
|
|
4739
4839
|
type: "AI",
|
|
4740
4840
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -4758,25 +4858,25 @@ const va = (i, e, { sendsPageContext: t }) => {
|
|
|
4758
4858
|
try {
|
|
4759
4859
|
(r = s.onAccepted) == null || r.call(s);
|
|
4760
4860
|
} catch (c) {
|
|
4761
|
-
|
|
4861
|
+
m.error("send acceptance callback failed", c);
|
|
4762
4862
|
}
|
|
4763
4863
|
}, this.stageUserTurn = async (s, { pending: r }) => {
|
|
4764
4864
|
const c = this.buildUserMessage(s);
|
|
4765
4865
|
if (!c) return null;
|
|
4766
|
-
const p = r ? { ...c, pending: !0 } : c, d = this.buildPersistentInitialMessages(),
|
|
4767
|
-
...d.map((
|
|
4866
|
+
const p = r ? { ...c, pending: !0 } : c, d = this.buildPersistentInitialMessages(), u = [
|
|
4867
|
+
...d.map((h) => h.id),
|
|
4768
4868
|
p.id
|
|
4769
4869
|
];
|
|
4770
4870
|
this.state.setPartial({
|
|
4771
4871
|
messages: [...d, ...this.state.get().messages, p]
|
|
4772
4872
|
});
|
|
4773
|
-
let
|
|
4873
|
+
let g;
|
|
4774
4874
|
try {
|
|
4775
|
-
|
|
4776
|
-
} catch (
|
|
4777
|
-
throw this.rollbackOptimisticMessages(
|
|
4875
|
+
g = await this.ensureSessionId();
|
|
4876
|
+
} catch (h) {
|
|
4877
|
+
throw this.rollbackOptimisticMessages(u), h;
|
|
4778
4878
|
}
|
|
4779
|
-
return
|
|
4879
|
+
return g ? { sessionId: g, userMessage: p, initialMessages: d } : (this.rollbackOptimisticMessages(u), null);
|
|
4780
4880
|
}, this.buildQueuedUserMessage = (s) => {
|
|
4781
4881
|
var p;
|
|
4782
4882
|
const r = this.buildUserMessage(s);
|
|
@@ -4785,10 +4885,10 @@ const va = (i, e, { sendsPageContext: t }) => {
|
|
|
4785
4885
|
return c ? { sessionId: c, userMessage: { ...r, pending: !0 } } : null;
|
|
4786
4886
|
}, this.buildUserMessage = (s) => {
|
|
4787
4887
|
var r;
|
|
4788
|
-
return !s.content.trim() && (!s.attachments || s.attachments.length === 0) ? (
|
|
4888
|
+
return !s.content.trim() && (!s.attachments || s.attachments.length === 0) ? (m.warn("cannot send an empty message of no content or attachments"), null) : this.toUserMessage(
|
|
4789
4889
|
s.content.trim(),
|
|
4790
4890
|
s.attachments || void 0,
|
|
4791
|
-
this.sendsPageContext ?
|
|
4891
|
+
this.sendsPageContext ? x.markedElementNames(s.clientContext) : void 0,
|
|
4792
4892
|
this.sendsPageContext && ((r = s.mentions) != null && r.length) ? s.mentions : void 0
|
|
4793
4893
|
);
|
|
4794
4894
|
}, this.appendUserMessageIfAbsent = (s) => {
|
|
@@ -4796,7 +4896,7 @@ const va = (i, e, { sendsPageContext: t }) => {
|
|
|
4796
4896
|
r.some((c) => c.id === s.id) || this.state.setPartial({ messages: [...r, s] });
|
|
4797
4897
|
}, this.markUserMessageDelivered = (s) => {
|
|
4798
4898
|
const r = this.state.get().messages, c = r.findIndex(
|
|
4799
|
-
(
|
|
4899
|
+
(u) => u.id === s && u.type === "USER" && u.pending
|
|
4800
4900
|
);
|
|
4801
4901
|
if (c === -1) return;
|
|
4802
4902
|
const p = r[c];
|
|
@@ -4806,7 +4906,7 @@ const va = (i, e, { sendsPageContext: t }) => {
|
|
|
4806
4906
|
messages: d
|
|
4807
4907
|
});
|
|
4808
4908
|
}, this.sendMessage = async (s) => {
|
|
4809
|
-
var c, p, d,
|
|
4909
|
+
var c, p, d, u, g;
|
|
4810
4910
|
if (this.streaming) {
|
|
4811
4911
|
if (!this.agentHandlers) {
|
|
4812
4912
|
this.bufferedAgentSends.push(s);
|
|
@@ -4817,20 +4917,20 @@ const va = (i, e, { sendsPageContext: t }) => {
|
|
|
4817
4917
|
}
|
|
4818
4918
|
let r;
|
|
4819
4919
|
try {
|
|
4820
|
-
const
|
|
4920
|
+
const h = this.sessionCtx.sessionState.get().session, j = (h == null ? void 0 : h.assignee.kind) === "ai", b = this.state.get().isSendingMessageToAI, f = this.state.get().messages.at(-1);
|
|
4821
4921
|
if (this.blocksSendWhileAwaitingReply && (b || // If last message is from user, then bot response did not arrive yet
|
|
4822
|
-
|
|
4823
|
-
|
|
4922
|
+
j && (f == null ? void 0 : f.type) === "USER")) {
|
|
4923
|
+
m.warn("cannot send messages while awaiting AI response");
|
|
4824
4924
|
return;
|
|
4825
4925
|
}
|
|
4826
4926
|
this.sendMessageAbortController.abort("Superseded by a newer message"), this.sendMessageAbortController = new AbortController(), r = this.sendMessageAbortController, this.state.setPartial({
|
|
4827
4927
|
lastAIResMightSolveUserIssue: !1,
|
|
4828
4928
|
isSendingMessage: !0,
|
|
4829
|
-
isSendingMessageToAI: !!
|
|
4929
|
+
isSendingMessageToAI: !!j || !h
|
|
4830
4930
|
});
|
|
4831
|
-
const
|
|
4832
|
-
if (!
|
|
4833
|
-
const { sessionId:
|
|
4931
|
+
const D = await this.stageUserTurn(s, { pending: !1 });
|
|
4932
|
+
if (!D) return;
|
|
4933
|
+
const { sessionId: Z, userMessage: N, initialMessages: J } = D;
|
|
4834
4934
|
this.notifySendAccepted(s);
|
|
4835
4935
|
const { data: k } = await this.api.sendMessage(
|
|
4836
4936
|
za({
|
|
@@ -4839,10 +4939,10 @@ const va = (i, e, { sendsPageContext: t }) => {
|
|
|
4839
4939
|
capabilities: this.getClientCapabilities()
|
|
4840
4940
|
},
|
|
4841
4941
|
input: s,
|
|
4842
|
-
uuid:
|
|
4843
|
-
sessionId:
|
|
4844
|
-
content:
|
|
4845
|
-
initialMessages:
|
|
4942
|
+
uuid: N.id,
|
|
4943
|
+
sessionId: Z,
|
|
4944
|
+
content: N.content,
|
|
4945
|
+
initialMessages: J,
|
|
4846
4946
|
sendsPageContext: this.sendsPageContext
|
|
4847
4947
|
}),
|
|
4848
4948
|
r.signal
|
|
@@ -4852,7 +4952,7 @@ const va = (i, e, { sendsPageContext: t }) => {
|
|
|
4852
4952
|
if (S) {
|
|
4853
4953
|
const q = this.state.get().messages;
|
|
4854
4954
|
if (!!q.some(
|
|
4855
|
-
(
|
|
4955
|
+
(Y) => Y.id === S.id
|
|
4856
4956
|
)) {
|
|
4857
4957
|
this.state.setPartial({
|
|
4858
4958
|
lastAIResMightSolveUserIssue: ((c = k.autopilotResponse) == null ? void 0 : c.mightSolveUserIssue) || ((p = k.uiResponse) == null ? void 0 : p.mightSolveUserIssue)
|
|
@@ -4861,20 +4961,20 @@ const va = (i, e, { sendsPageContext: t }) => {
|
|
|
4861
4961
|
}
|
|
4862
4962
|
this.state.setPartial({
|
|
4863
4963
|
messages: [...q, S],
|
|
4864
|
-
lastAIResMightSolveUserIssue: ((d = k.autopilotResponse) == null ? void 0 : d.mightSolveUserIssue) || ((
|
|
4964
|
+
lastAIResMightSolveUserIssue: ((d = k.autopilotResponse) == null ? void 0 : d.mightSolveUserIssue) || ((u = k.uiResponse) == null ? void 0 : u.mightSolveUserIssue)
|
|
4865
4965
|
}), this.dispatchToOnMessageReceivedHook(S);
|
|
4866
4966
|
}
|
|
4867
4967
|
k.session && this.sessionCtx.sessionState.setPartial({ session: k.session });
|
|
4868
4968
|
} else {
|
|
4869
4969
|
const S = this.toBotErrorMessage(
|
|
4870
|
-
((
|
|
4970
|
+
((g = k == null ? void 0 : k.error) == null ? void 0 : g.message) || fa(this.config, "turn_failed_message")
|
|
4871
4971
|
), q = this.state.get().messages;
|
|
4872
4972
|
this.state.setPartial({
|
|
4873
4973
|
messages: [...q, S]
|
|
4874
4974
|
});
|
|
4875
4975
|
}
|
|
4876
|
-
} catch (
|
|
4877
|
-
r != null && r.signal.aborted ||
|
|
4976
|
+
} catch (h) {
|
|
4977
|
+
r != null && r.signal.aborted || m.error("failed to send message", h);
|
|
4878
4978
|
} finally {
|
|
4879
4979
|
r != null && r.signal.aborted || this.state.setPartial({
|
|
4880
4980
|
isSendingMessage: !1,
|
|
@@ -4883,14 +4983,14 @@ const va = (i, e, { sendsPageContext: t }) => {
|
|
|
4883
4983
|
}
|
|
4884
4984
|
}, this.toUserMessage = (s, r, c, p) => {
|
|
4885
4985
|
const d = (() => {
|
|
4886
|
-
const
|
|
4887
|
-
return this.state.get().messages.length === 0 &&
|
|
4986
|
+
const u = this.contactCtx.state.get().extraCollectedData;
|
|
4987
|
+
return this.state.get().messages.length === 0 && u && Object.keys(u).length > 0 ? `${Object.entries(u).filter(([h, v]) => !!v).map(([h, v]) => `${h}: ${v}`).join(`
|
|
4888
4988
|
`)}
|
|
4889
4989
|
|
|
4890
4990
|
${s}` : s;
|
|
4891
4991
|
})();
|
|
4892
4992
|
return {
|
|
4893
|
-
id:
|
|
4993
|
+
id: z(),
|
|
4894
4994
|
type: "USER",
|
|
4895
4995
|
content: d,
|
|
4896
4996
|
attachments: r,
|
|
@@ -4902,7 +5002,7 @@ ${s}` : s;
|
|
|
4902
5002
|
var r;
|
|
4903
5003
|
return s.success && s.autopilotResponse ? {
|
|
4904
5004
|
type: "AI",
|
|
4905
|
-
id: s.autopilotResponse.id ||
|
|
5005
|
+
id: s.autopilotResponse.id || z(),
|
|
4906
5006
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4907
5007
|
component: "bot_message",
|
|
4908
5008
|
agent: this.config.bot ? {
|
|
@@ -4923,7 +5023,7 @@ ${s}` : s;
|
|
|
4923
5023
|
} : null;
|
|
4924
5024
|
}, this.toBotErrorMessage = (s) => ({
|
|
4925
5025
|
type: "AI",
|
|
4926
|
-
id:
|
|
5026
|
+
id: z(),
|
|
4927
5027
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4928
5028
|
component: "bot_message",
|
|
4929
5029
|
data: {
|
|
@@ -4931,16 +5031,16 @@ ${s}` : s;
|
|
|
4931
5031
|
variant: "error",
|
|
4932
5032
|
action: void 0
|
|
4933
5033
|
}
|
|
4934
|
-
}), this.config = e, this.getClientCapabilities =
|
|
5034
|
+
}), this.config = e, this.getClientCapabilities = t ?? (() => this.config.capabilities), this.api = a, this.sessionCtx = n, this.contactCtx = i, this.streaming = l, this.sendsPageContext = o;
|
|
4935
5035
|
}
|
|
4936
5036
|
/** Hand a send to the streaming engine; its failure can never propagate. */
|
|
4937
|
-
static dispatchToEngine(e,
|
|
5037
|
+
static dispatchToEngine(e, a) {
|
|
4938
5038
|
try {
|
|
4939
|
-
Promise.resolve(e.send(
|
|
4940
|
-
|
|
5039
|
+
Promise.resolve(e.send(a)).catch((n) => {
|
|
5040
|
+
m.error("streaming send failed", n);
|
|
4941
5041
|
});
|
|
4942
|
-
} catch (
|
|
4943
|
-
|
|
5042
|
+
} catch (n) {
|
|
5043
|
+
m.error("streaming send failed", n);
|
|
4944
5044
|
}
|
|
4945
5045
|
}
|
|
4946
5046
|
/**
|
|
@@ -4951,23 +5051,23 @@ ${s}` : s;
|
|
|
4951
5051
|
* without a usable name are dropped.
|
|
4952
5052
|
*/
|
|
4953
5053
|
static markedElementNames(e) {
|
|
4954
|
-
const
|
|
4955
|
-
if (!Array.isArray(
|
|
4956
|
-
const
|
|
4957
|
-
if (typeof
|
|
4958
|
-
const l =
|
|
4959
|
-
if (typeof
|
|
4960
|
-
const s =
|
|
5054
|
+
const a = e == null ? void 0 : e.page_marks;
|
|
5055
|
+
if (!Array.isArray(a)) return;
|
|
5056
|
+
const n = a.flatMap((i) => {
|
|
5057
|
+
if (typeof i != "object" || i === null) return [];
|
|
5058
|
+
const l = i.elements, o = Array.isArray(l) ? l[0] : void 0, t = typeof o == "object" && o !== null && "name" in o ? o.name : void 0;
|
|
5059
|
+
if (typeof t != "string" || t.length === 0) return [];
|
|
5060
|
+
const s = i.note, r = i.snapshotUrl;
|
|
4961
5061
|
return [
|
|
4962
5062
|
{
|
|
4963
|
-
name:
|
|
5063
|
+
name: t,
|
|
4964
5064
|
...typeof s == "string" && s.length > 0 ? { note: s } : {},
|
|
4965
5065
|
...typeof r == "string" && r.length > 0 ? { snapshotUrl: r } : {},
|
|
4966
|
-
mark:
|
|
5066
|
+
mark: i
|
|
4967
5067
|
}
|
|
4968
5068
|
];
|
|
4969
5069
|
});
|
|
4970
|
-
return
|
|
5070
|
+
return n.length > 0 ? n : void 0;
|
|
4971
5071
|
}
|
|
4972
5072
|
/**
|
|
4973
5073
|
* The blocking engine refuses a send while the AI reply is pending unless
|
|
@@ -4977,125 +5077,125 @@ ${s}` : s;
|
|
|
4977
5077
|
return !this.streaming && this.config.disableSendingWhenAwaitingAIReply !== !1;
|
|
4978
5078
|
}
|
|
4979
5079
|
};
|
|
4980
|
-
|
|
4981
|
-
let M =
|
|
4982
|
-
class
|
|
4983
|
-
constructor({
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
sessionCtx: o,
|
|
4987
|
-
resetChat: _
|
|
4988
|
-
}) {
|
|
4989
|
-
var l, a;
|
|
4990
|
-
this.restorableSessionId = null, this.didReadStoredSession = !1, this.readStoredSession = () => {
|
|
5080
|
+
x.SENT_TEXT_HISTORY_MAX = 50;
|
|
5081
|
+
let M = x;
|
|
5082
|
+
class Ca {
|
|
5083
|
+
constructor(e) {
|
|
5084
|
+
var a, n;
|
|
5085
|
+
this.widget = e, this.subscriptions = [], this.disposed = !1, this.restorableSessionId = null, this.didReadStoredSession = !1, this.readStoredSession = () => {
|
|
4991
5086
|
if (!this.shouldRestoreLastSession) {
|
|
4992
5087
|
this.didReadStoredSession = !0;
|
|
4993
5088
|
return;
|
|
4994
5089
|
}
|
|
4995
|
-
this.sessionCtx.getLastActiveSessionId().then((
|
|
4996
|
-
this.restorableSessionId =
|
|
5090
|
+
this.sessionCtx.getLastActiveSessionId().then((i) => {
|
|
5091
|
+
this.restorableSessionId = i;
|
|
4997
5092
|
}).finally(() => {
|
|
4998
5093
|
this.didReadStoredSession = !0, this.routeFromSessions(this.sessionCtx.sessionsState.get());
|
|
4999
5094
|
});
|
|
5000
5095
|
}, this.registerRoutingListener = () => {
|
|
5001
|
-
this.
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5096
|
+
this.subscriptions.push(
|
|
5097
|
+
this.contactCtx.state.subscribe(({ contact: i }) => {
|
|
5098
|
+
var l;
|
|
5099
|
+
i != null && i.token && this.state.get().screen === "welcome" && this.state.setPartial({
|
|
5100
|
+
screen: (l = this.config.router) != null && l.chatScreenOnly ? "chat" : "sessions"
|
|
5101
|
+
});
|
|
5102
|
+
})
|
|
5103
|
+
), this.subscriptions.push(
|
|
5104
|
+
this.sessionCtx.sessionsState.subscribe(this.routeFromSessions)
|
|
5105
|
+
);
|
|
5007
5106
|
}, this.routeFromSessions = ({
|
|
5008
|
-
isInitialFetchLoading:
|
|
5009
|
-
data:
|
|
5107
|
+
isInitialFetchLoading: i,
|
|
5108
|
+
data: l
|
|
5010
5109
|
}) => {
|
|
5011
|
-
var
|
|
5012
|
-
if (this.didReadStoredSession) {
|
|
5013
|
-
if (this.restorableSessionId && !((
|
|
5014
|
-
const
|
|
5015
|
-
(
|
|
5110
|
+
var o, t, s, r, c;
|
|
5111
|
+
if (!(this.disposed || !this.didReadStoredSession)) {
|
|
5112
|
+
if (this.restorableSessionId && !((o = this.sessionCtx.sessionState.get().session) != null && o.id)) {
|
|
5113
|
+
const p = l.find(
|
|
5114
|
+
(d) => d.id === this.restorableSessionId && d.isOpened
|
|
5016
5115
|
);
|
|
5017
|
-
if (
|
|
5018
|
-
this.restorableSessionId = null, this.toChatScreen(
|
|
5116
|
+
if (p) {
|
|
5117
|
+
this.restorableSessionId = null, this.toChatScreen(p.id);
|
|
5019
5118
|
return;
|
|
5020
5119
|
}
|
|
5021
|
-
if (
|
|
5120
|
+
if (i) return;
|
|
5022
5121
|
this.restorableSessionId = null;
|
|
5023
5122
|
}
|
|
5024
|
-
if ((
|
|
5123
|
+
if ((t = this.config.router) != null && t.chatScreenOnly && // Do not route to a chat if we are currently inside one already
|
|
5025
5124
|
// This also applies to newly created sessions; the new session will be in `sessionState` before it is refreshed and included in `sessionsState`
|
|
5026
|
-
!((
|
|
5027
|
-
const
|
|
5028
|
-
return
|
|
5125
|
+
!((s = this.sessionCtx.sessionState.get().session) != null && s.id)) {
|
|
5126
|
+
const p = (r = l.find((d) => d.isOpened)) == null ? void 0 : r.id;
|
|
5127
|
+
return p ? this.toChatScreen(p) : void 0;
|
|
5029
5128
|
}
|
|
5030
|
-
|
|
5129
|
+
l.length || ((c = this.config.router) == null ? void 0 : c.goToChatIfNoSessions) !== !1 && !i && this.state.get().screen !== "chat" && this.toChatScreen();
|
|
5031
5130
|
}
|
|
5131
|
+
}, this.dispose = () => {
|
|
5132
|
+
this.disposed = !0, this.subscriptions.forEach((i) => i()), this.subscriptions = [], this.navigateConversation = void 0;
|
|
5032
5133
|
}, this.toSessionsScreen = () => {
|
|
5033
|
-
this.resetChat(), this.state.setPartial({ screen: "sessions" });
|
|
5034
|
-
}, this.toChatScreen = (
|
|
5035
|
-
var
|
|
5134
|
+
this.navigateConversation || this.resetChat(), this.state.setPartial({ screen: "sessions" });
|
|
5135
|
+
}, this.toChatScreen = (i) => {
|
|
5136
|
+
var o, t;
|
|
5137
|
+
if (this.navigateConversation) return this.navigateConversation(i);
|
|
5036
5138
|
this.resetChat();
|
|
5037
|
-
let
|
|
5038
|
-
if (
|
|
5039
|
-
if (
|
|
5040
|
-
this.sessionCtx.sessionState.setPartial({ session:
|
|
5139
|
+
let l;
|
|
5140
|
+
if (i) {
|
|
5141
|
+
if (l = this.sessionCtx.sessionsState.get().data.find((s) => s.id === i), !l) return;
|
|
5142
|
+
this.sessionCtx.sessionState.setPartial({ session: l });
|
|
5041
5143
|
}
|
|
5042
|
-
this.state.setPartial({ screen: "chat" }), (
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
}, this.
|
|
5046
|
-
screen: this.contactCtx.shouldCollectData() ? "welcome" : (l = this.config.router) != null && l.chatScreenOnly ? "chat" : "sessions"
|
|
5047
|
-
}), this.shouldRestoreLastSession = ((a = this.config.router) == null ? void 0 : a.restoreLastSession) ?? !1, this.readStoredSession(), this.registerRoutingListener();
|
|
5144
|
+
return this.state.setPartial({ screen: "chat" }), (t = (o = this.config.hooks) == null ? void 0 : o.onNavigateToChat) == null || t.call(o, { session: l }), this.widget;
|
|
5145
|
+
}, this.config = e.config, this.contactCtx = e.contactCtx, this.sessionCtx = e.sessionCtx, this.resetChat = e.resetChat, this.state = new w({
|
|
5146
|
+
screen: this.contactCtx.shouldCollectData() ? "welcome" : (a = this.config.router) != null && a.chatScreenOnly ? "chat" : "sessions"
|
|
5147
|
+
}), this.shouldRestoreLastSession = ((n = this.config.router) == null ? void 0 : n.restoreLastSession) ?? !1, this.readStoredSession(), this.registerRoutingListener();
|
|
5048
5148
|
}
|
|
5049
5149
|
}
|
|
5050
|
-
class
|
|
5150
|
+
class qa {
|
|
5051
5151
|
constructor({
|
|
5052
5152
|
storage: e,
|
|
5053
|
-
config:
|
|
5153
|
+
config: a
|
|
5054
5154
|
}) {
|
|
5055
5155
|
this.KEYS = {
|
|
5056
|
-
contactToken: (
|
|
5057
|
-
externalContactId: (
|
|
5058
|
-
companionPreference: (
|
|
5059
|
-
activeSession: (
|
|
5060
|
-
}, this.setContactToken = async (
|
|
5061
|
-
await this.storage.set(this.KEYS.contactToken(this.config.token),
|
|
5156
|
+
contactToken: (n) => `opencx-widget:org-token-${n}:contact-token`,
|
|
5157
|
+
externalContactId: (n) => `opencx-widget:org-token-${n}:external-contact-id`,
|
|
5158
|
+
companionPreference: (n, i) => `opencx-widget:org-token-${n}:companion-${i}`,
|
|
5159
|
+
activeSession: (n) => `opencx-widget:org-token-${n}:active-session`
|
|
5160
|
+
}, this.setContactToken = async (n) => {
|
|
5161
|
+
await this.storage.set(this.KEYS.contactToken(this.config.token), n);
|
|
5062
5162
|
}, this.getContactToken = async () => this.storage.get(this.KEYS.contactToken(this.config.token)), this.clearContactToken = async () => {
|
|
5063
5163
|
await this.storage.remove(this.KEYS.contactToken(this.config.token));
|
|
5064
|
-
}, this.activeSessionKey = () => this.KEYS.activeSession(this.config.token), this.getActiveSessionId = async () => this.storage.get(this.activeSessionKey()), this.setActiveSessionId = async (
|
|
5065
|
-
await this.storage.set(this.activeSessionKey(),
|
|
5164
|
+
}, this.activeSessionKey = () => this.KEYS.activeSession(this.config.token), this.getActiveSessionId = async () => this.storage.get(this.activeSessionKey()), this.setActiveSessionId = async (n) => {
|
|
5165
|
+
await this.storage.set(this.activeSessionKey(), n);
|
|
5066
5166
|
}, this.clearActiveSessionId = async () => {
|
|
5067
5167
|
await this.storage.remove(this.activeSessionKey());
|
|
5068
|
-
}, this.setExternalContactId = async (
|
|
5069
|
-
await this.storage.set(this.KEYS.externalContactId(this.config.token),
|
|
5070
|
-
}, this.getExternalContactId = async () => this.storage.get(this.KEYS.externalContactId(this.config.token)), this.companionKey = (
|
|
5071
|
-
const
|
|
5072
|
-
if (
|
|
5073
|
-
const l = Number(
|
|
5168
|
+
}, this.setExternalContactId = async (n) => {
|
|
5169
|
+
await this.storage.set(this.KEYS.externalContactId(this.config.token), n);
|
|
5170
|
+
}, this.getExternalContactId = async () => this.storage.get(this.KEYS.externalContactId(this.config.token)), this.companionKey = (n) => this.KEYS.companionPreference(this.config.token, n), this.getFiniteNumber = async (n) => {
|
|
5171
|
+
const i = await this.storage.get(n);
|
|
5172
|
+
if (i === null) return null;
|
|
5173
|
+
const l = Number(i);
|
|
5074
5174
|
return Number.isFinite(l) ? l : null;
|
|
5075
|
-
}, this.getCompanionPillOffsetX = async () => this.getFiniteNumber(this.companionKey("pill-offset-x")), this.setCompanionPillOffsetX = async (
|
|
5076
|
-
Number.isFinite(
|
|
5077
|
-
}, this.getCompanionSidebarWidth = async () => this.getFiniteNumber(this.companionKey("sidebar-width")), this.setCompanionSidebarWidth = async (
|
|
5078
|
-
Number.isFinite(
|
|
5175
|
+
}, this.getCompanionPillOffsetX = async () => this.getFiniteNumber(this.companionKey("pill-offset-x")), this.setCompanionPillOffsetX = async (n) => {
|
|
5176
|
+
Number.isFinite(n) && await this.storage.set(this.companionKey("pill-offset-x"), String(n));
|
|
5177
|
+
}, this.getCompanionSidebarWidth = async () => this.getFiniteNumber(this.companionKey("sidebar-width")), this.setCompanionSidebarWidth = async (n) => {
|
|
5178
|
+
Number.isFinite(n) && await this.storage.set(this.companionKey("sidebar-width"), String(n));
|
|
5079
5179
|
}, this.getCompanionSidebarSide = async () => {
|
|
5080
|
-
const
|
|
5081
|
-
return
|
|
5082
|
-
}, this.setCompanionSidebarSide = async (
|
|
5083
|
-
await this.storage.set(this.companionKey("sidebar-side"),
|
|
5180
|
+
const n = await this.storage.get(this.companionKey("sidebar-side"));
|
|
5181
|
+
return n === "left" || n === "right" ? n : null;
|
|
5182
|
+
}, this.setCompanionSidebarSide = async (n) => {
|
|
5183
|
+
await this.storage.set(this.companionKey("sidebar-side"), n);
|
|
5084
5184
|
}, this.getCompanionLayout = async () => {
|
|
5085
|
-
const
|
|
5086
|
-
return
|
|
5087
|
-
}, this.setCompanionLayout = async (
|
|
5088
|
-
await this.storage.set(this.companionKey("layout"),
|
|
5185
|
+
const n = await this.storage.get(this.companionKey("layout"));
|
|
5186
|
+
return n === "compact" || n === "sidebar" ? n : null;
|
|
5187
|
+
}, this.setCompanionLayout = async (n) => {
|
|
5188
|
+
await this.storage.set(this.companionKey("layout"), n);
|
|
5089
5189
|
}, this.getCompanionSidebarMode = async () => {
|
|
5090
|
-
const
|
|
5091
|
-
return
|
|
5092
|
-
}, this.setCompanionSidebarMode = async (
|
|
5093
|
-
await this.storage.set(this.companionKey("sidebar-mode"),
|
|
5094
|
-
}, this.storage = e, this.config =
|
|
5190
|
+
const n = await this.storage.get(this.companionKey("sidebar-mode"));
|
|
5191
|
+
return n === "docked" || n === "floating" ? n : null;
|
|
5192
|
+
}, this.setCompanionSidebarMode = async (n) => {
|
|
5193
|
+
await this.storage.set(this.companionKey("sidebar-mode"), n);
|
|
5194
|
+
}, this.storage = e, this.config = a;
|
|
5095
5195
|
}
|
|
5096
5196
|
}
|
|
5097
|
-
function
|
|
5098
|
-
org:
|
|
5197
|
+
function Ea({
|
|
5198
|
+
org: _,
|
|
5099
5199
|
agent: e
|
|
5100
5200
|
}) {
|
|
5101
5201
|
return e ? {
|
|
@@ -5109,7 +5209,7 @@ function qa({
|
|
|
5109
5209
|
clientTools: e.features.client_tools
|
|
5110
5210
|
}
|
|
5111
5211
|
} : {
|
|
5112
|
-
name:
|
|
5212
|
+
name: _.name,
|
|
5113
5213
|
avatarUrl: null,
|
|
5114
5214
|
streaming: !1,
|
|
5115
5215
|
features: {
|
|
@@ -5120,55 +5220,78 @@ function qa({
|
|
|
5120
5220
|
}
|
|
5121
5221
|
};
|
|
5122
5222
|
}
|
|
5123
|
-
function
|
|
5124
|
-
return
|
|
5223
|
+
function T(_, e) {
|
|
5224
|
+
return _ && e !== !1;
|
|
5125
5225
|
}
|
|
5126
|
-
function
|
|
5127
|
-
const
|
|
5226
|
+
function Pa(_, e) {
|
|
5227
|
+
const a = e.features;
|
|
5128
5228
|
return {
|
|
5129
|
-
dictation:
|
|
5130
|
-
attachments:
|
|
5131
|
-
pageContext:
|
|
5132
|
-
|
|
5133
|
-
|
|
5229
|
+
dictation: T(_.features.dictation, a == null ? void 0 : a.dictation),
|
|
5230
|
+
attachments: _.features.attachments,
|
|
5231
|
+
pageContext: T(
|
|
5232
|
+
_.features.pageContext,
|
|
5233
|
+
a == null ? void 0 : a.pageContext
|
|
5134
5234
|
),
|
|
5135
|
-
clientTools:
|
|
5136
|
-
|
|
5137
|
-
|
|
5235
|
+
clientTools: T(
|
|
5236
|
+
_.features.clientTools,
|
|
5237
|
+
a == null ? void 0 : a.clientTools
|
|
5138
5238
|
)
|
|
5139
5239
|
};
|
|
5140
5240
|
}
|
|
5141
|
-
class
|
|
5142
|
-
constructor(e,
|
|
5143
|
-
super(
|
|
5241
|
+
class Aa extends Error {
|
|
5242
|
+
constructor(e, a, n) {
|
|
5243
|
+
super(a), this.name = "WidgetInitializationError", this.code = e, this.details = n;
|
|
5144
5244
|
}
|
|
5145
5245
|
}
|
|
5146
|
-
const
|
|
5246
|
+
const y = class y {
|
|
5147
5247
|
constructor({
|
|
5148
5248
|
config: e,
|
|
5149
|
-
storage:
|
|
5150
|
-
getClientCapabilities:
|
|
5151
|
-
modes:
|
|
5249
|
+
storage: a,
|
|
5250
|
+
getClientCapabilities: n,
|
|
5251
|
+
modes: i,
|
|
5152
5252
|
org: l,
|
|
5153
|
-
agent:
|
|
5253
|
+
agent: o,
|
|
5254
|
+
parent: t
|
|
5154
5255
|
}) {
|
|
5155
|
-
if (this.modes = [], this.
|
|
5156
|
-
|
|
5157
|
-
|
|
5256
|
+
if (this.modes = [], this.createConversation = () => {
|
|
5257
|
+
const s = new y({
|
|
5258
|
+
config: {
|
|
5259
|
+
...this.config,
|
|
5260
|
+
router: {
|
|
5261
|
+
...this.config.router,
|
|
5262
|
+
restoreLastSession: !1,
|
|
5263
|
+
chatScreenOnly: !1,
|
|
5264
|
+
goToChatIfNoSessions: !1
|
|
5265
|
+
}
|
|
5266
|
+
},
|
|
5267
|
+
modes: this.modes,
|
|
5268
|
+
org: this.org,
|
|
5269
|
+
agent: this.agent,
|
|
5270
|
+
parent: this
|
|
5271
|
+
});
|
|
5272
|
+
return s.routerCtx.state.setPartial({
|
|
5273
|
+
screen: this.contactCtx.shouldCollectData() ? "welcome" : "chat"
|
|
5274
|
+
}), s;
|
|
5275
|
+
}, this.releaseConversation = () => {
|
|
5276
|
+
this.routerCtx.dispose(), this.resetChat();
|
|
5277
|
+
}, this.resetChat = () => {
|
|
5278
|
+
this.sessionCtx.reset(), this.messageCtx.reset(), this.uploadCtx.reset();
|
|
5279
|
+
}, this.reconcileAfterStream = (s) => this.activeSessionPollingCtx.reconcileAfterStream(s), !y.pollingIntervalsSeconds)
|
|
5158
5280
|
throw Error(
|
|
5159
5281
|
"Widget polling values are not defined, did you call WidgetCtx.initialize()"
|
|
5160
5282
|
);
|
|
5161
|
-
this.config = e, this.org = l, this.agent =
|
|
5283
|
+
this.config = e, this.org = l, this.agent = o, this.features = Pa(o, e), this.api = (t == null ? void 0 : t.api) ?? new L({ config: e }), this.storageCtx = (t == null ? void 0 : t.storageCtx) ?? (a ? new qa({ storage: a, config: e }) : void 0), this.modes = i, this.contactCtx = (t == null ? void 0 : t.contactCtx) ?? new ie({
|
|
5162
5284
|
api: this.api,
|
|
5163
5285
|
config: this.config,
|
|
5164
5286
|
storageCtx: this.storageCtx
|
|
5165
|
-
}), this.sessionCtx = new
|
|
5287
|
+
}), this.sessionCtx = new va({
|
|
5166
5288
|
config: this.config,
|
|
5167
5289
|
api: this.api,
|
|
5168
5290
|
contactCtx: this.contactCtx,
|
|
5169
5291
|
// Remembers the open conversation so a reload can return to it.
|
|
5170
|
-
storageCtx: this.storageCtx,
|
|
5171
|
-
|
|
5292
|
+
storageCtx: t ? void 0 : this.storageCtx,
|
|
5293
|
+
sharedSessions: t == null ? void 0 : t.sessionCtx.sessionsState,
|
|
5294
|
+
sessionsPollingIntervalSeconds: y.pollingIntervalsSeconds.sessions
|
|
5172
5295
|
}), this.messageCtx = new M({
|
|
5173
5296
|
config: this.config,
|
|
5174
5297
|
api: this.api,
|
|
@@ -5178,26 +5301,21 @@ const v = class v {
|
|
|
5178
5301
|
// the blocking bot-chat send.
|
|
5179
5302
|
streaming: this.streaming,
|
|
5180
5303
|
sendsPageContext: this.features.pageContext,
|
|
5181
|
-
getClientCapabilities:
|
|
5182
|
-
}), this.csatCtx = new
|
|
5304
|
+
getClientCapabilities: n
|
|
5305
|
+
}), this.uploadCtx = new re(this.api), this.csatCtx = new _e({
|
|
5183
5306
|
api: this.api,
|
|
5184
5307
|
sessionCtx: this.sessionCtx,
|
|
5185
5308
|
messageCtx: this.messageCtx
|
|
5186
|
-
}), this.dictationCtx = new
|
|
5309
|
+
}), this.dictationCtx = new Pe({
|
|
5187
5310
|
api: this.api,
|
|
5188
5311
|
config: this.config
|
|
5189
|
-
}), this.activeSessionPollingCtx = new
|
|
5312
|
+
}), this.activeSessionPollingCtx = new oe({
|
|
5190
5313
|
api: this.api,
|
|
5191
5314
|
config: this.config,
|
|
5192
5315
|
sessionCtx: this.sessionCtx,
|
|
5193
5316
|
messageCtx: this.messageCtx,
|
|
5194
|
-
sessionPollingIntervalSeconds:
|
|
5195
|
-
}), this.routerCtx = new
|
|
5196
|
-
config: this.config,
|
|
5197
|
-
contactCtx: this.contactCtx,
|
|
5198
|
-
sessionCtx: this.sessionCtx,
|
|
5199
|
-
resetChat: this.resetChat
|
|
5200
|
-
});
|
|
5317
|
+
sessionPollingIntervalSeconds: y.pollingIntervalsSeconds.session
|
|
5318
|
+
}), this.routerCtx = new Ca(this);
|
|
5201
5319
|
}
|
|
5202
5320
|
/**
|
|
5203
5321
|
* Whether turns stream (the v5 agent-chat engine) or use the blocking
|
|
@@ -5208,40 +5326,40 @@ const v = class v {
|
|
|
5208
5326
|
return this.agent.streaming;
|
|
5209
5327
|
}
|
|
5210
5328
|
};
|
|
5211
|
-
|
|
5329
|
+
y.pollingIntervalsSeconds = null, y.initialize = async ({
|
|
5212
5330
|
config: e,
|
|
5213
|
-
storage:
|
|
5214
|
-
getClientCapabilities:
|
|
5331
|
+
storage: a,
|
|
5332
|
+
getClientCapabilities: n
|
|
5215
5333
|
}) => {
|
|
5216
|
-
var l,
|
|
5217
|
-
const
|
|
5334
|
+
var l, o;
|
|
5335
|
+
const i = await new L({
|
|
5218
5336
|
config: e
|
|
5219
5337
|
}).getExternalWidgetConfig();
|
|
5220
|
-
if (!
|
|
5221
|
-
throw
|
|
5338
|
+
if (!i.data)
|
|
5339
|
+
throw m.error("widget config fetch failed", i.error), new Aa(
|
|
5222
5340
|
"config-fetch-failed",
|
|
5223
5341
|
"Failed to fetch widget config",
|
|
5224
|
-
|
|
5342
|
+
i.error
|
|
5225
5343
|
);
|
|
5226
|
-
return
|
|
5227
|
-
session: ((l =
|
|
5228
|
-
sessions: ((
|
|
5229
|
-
}, new
|
|
5344
|
+
return y.pollingIntervalsSeconds = {
|
|
5345
|
+
session: ((l = i.data) == null ? void 0 : l.sessionPollingIntervalSeconds) || 10,
|
|
5346
|
+
sessions: ((o = i.data) == null ? void 0 : o.sessionsPollingIntervalSeconds) || 60
|
|
5347
|
+
}, new y({
|
|
5230
5348
|
config: e,
|
|
5231
|
-
storage:
|
|
5232
|
-
getClientCapabilities:
|
|
5233
|
-
modes:
|
|
5349
|
+
storage: a,
|
|
5350
|
+
getClientCapabilities: n,
|
|
5351
|
+
modes: i.data.modes || [],
|
|
5234
5352
|
org: {
|
|
5235
|
-
id:
|
|
5236
|
-
name:
|
|
5353
|
+
id: i.data.org.id,
|
|
5354
|
+
name: i.data.org.name
|
|
5237
5355
|
},
|
|
5238
|
-
agent:
|
|
5356
|
+
agent: Ea(i.data)
|
|
5239
5357
|
});
|
|
5240
5358
|
};
|
|
5241
|
-
let
|
|
5242
|
-
class
|
|
5243
|
-
constructor({ attack: e, release:
|
|
5244
|
-
this.value = 0, this.attack = e, this.release =
|
|
5359
|
+
let B = y;
|
|
5360
|
+
class Fa {
|
|
5361
|
+
constructor({ attack: e, release: a }) {
|
|
5362
|
+
this.value = 0, this.attack = e, this.release = a;
|
|
5245
5363
|
}
|
|
5246
5364
|
next(e) {
|
|
5247
5365
|
return this.value += (e - this.value) * (e > this.value ? this.attack : this.release), this.value;
|
|
@@ -5257,46 +5375,46 @@ const P = [
|
|
|
5257
5375
|
], Ta = new Set(
|
|
5258
5376
|
P
|
|
5259
5377
|
);
|
|
5260
|
-
function
|
|
5261
|
-
return Ta.has(
|
|
5378
|
+
function $(_) {
|
|
5379
|
+
return Ta.has(_);
|
|
5262
5380
|
}
|
|
5263
|
-
function
|
|
5264
|
-
if (!Array.isArray(
|
|
5265
|
-
const e = [],
|
|
5266
|
-
for (const
|
|
5267
|
-
|
|
5381
|
+
function Oa(_) {
|
|
5382
|
+
if (!Array.isArray(_)) return P;
|
|
5383
|
+
const e = [], a = /* @__PURE__ */ new Set();
|
|
5384
|
+
for (const n of _)
|
|
5385
|
+
!$(n) || a.has(n) || (a.add(n), e.push(n));
|
|
5268
5386
|
return e.length > 0 ? e : P;
|
|
5269
5387
|
}
|
|
5270
|
-
function
|
|
5271
|
-
return
|
|
5388
|
+
function Ua(_, e) {
|
|
5389
|
+
return $(_) && e.includes(_) ? _ : e[0] ?? P[0];
|
|
5272
5390
|
}
|
|
5273
|
-
function
|
|
5274
|
-
return
|
|
5391
|
+
function Ba(_, e) {
|
|
5392
|
+
return _ === "left" || _ === "right" ? _ : e === "rtl" ? "left" : "right";
|
|
5275
5393
|
}
|
|
5276
|
-
function
|
|
5277
|
-
return
|
|
5394
|
+
function Va(_) {
|
|
5395
|
+
return _ === "docked" ? "docked" : "floating";
|
|
5278
5396
|
}
|
|
5279
5397
|
export {
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5398
|
+
Fa as DictationLevelSmoother,
|
|
5399
|
+
w as PrimitiveState,
|
|
5400
|
+
B as WidgetCtx,
|
|
5401
|
+
Aa as WidgetInitializationError,
|
|
5284
5402
|
za as buildSendMessageBody,
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
|
|
5299
|
-
|
|
5300
|
-
|
|
5403
|
+
z as genUuid,
|
|
5404
|
+
ba as getTranslation,
|
|
5405
|
+
Ra as isAgentStreamKeepalive,
|
|
5406
|
+
ne as isExhaustive,
|
|
5407
|
+
U as isRecord,
|
|
5408
|
+
La as isRtlLanguage,
|
|
5409
|
+
ha as isSupportedLanguage,
|
|
5410
|
+
Ka as isTurnSteeredPart,
|
|
5411
|
+
m as log,
|
|
5412
|
+
Oa as normalizeCompanionLayouts,
|
|
5413
|
+
Ua as resolveCompanionDefaultLayout,
|
|
5414
|
+
Sa as resolveConfigContext,
|
|
5415
|
+
ka as resolveLanguage,
|
|
5416
|
+
Va as resolveSidebarMode,
|
|
5417
|
+
Ba as resolveSidebarSide,
|
|
5418
|
+
fa as translate
|
|
5301
5419
|
};
|
|
5302
5420
|
//# sourceMappingURL=index.js.map
|