@opencx/widget-react-headless 5.10.0 → 5.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +16 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1127 -1112
- package/dist/index.js.map +1 -1
- package/dist/package.json.d.ts +1 -1
- package/dist/src/WidgetProvider.d.ts.map +1 -1
- package/dist/src/agent-chat/useAgentChat.d.ts.map +1 -1
- package/dist/src/hooks/useMessages.d.ts +1 -0
- package/dist/src/hooks/useMessages.d.ts.map +1 -1
- package/dist/src/hooks/useSessions.d.ts.map +1 -1
- package/dist/src/hooks/useTokenRenewal.d.ts +10 -0
- package/dist/src/hooks/useTokenRenewal.d.ts.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
var
|
|
1
|
+
var tn = (t) => {
|
|
2
2
|
throw TypeError(t);
|
|
3
3
|
};
|
|
4
|
-
var
|
|
5
|
-
var V = (t, e,
|
|
6
|
-
import H, { useSyncExternalStore as zt, useRef as R, useMemo as X, useEffect as F, useState as J, useCallback as z, createContext as He, useContext as Fe, memo as
|
|
7
|
-
import { isAgentStreamKeepalive as $
|
|
8
|
-
import { safeParseAsync as
|
|
4
|
+
var nn = (t, e, n) => e.has(t) || tn("Cannot " + n);
|
|
5
|
+
var V = (t, e, n) => (nn(t, e, "read from private field"), n ? n.call(t) : e.get(t)), ge = (t, e, n) => e.has(t) ? tn("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, n), Q = (t, e, n, r) => (nn(t, e, "write to private field"), r ? r.call(t, n) : e.set(t, n), n);
|
|
6
|
+
import H, { useSyncExternalStore as zt, useRef as R, useMemo as X, useEffect as F, useState as J, useCallback as z, createContext as He, useContext as Fe, memo as kr, useLayoutEffect as jr } from "react";
|
|
7
|
+
import { isAgentStreamKeepalive as $r, log as le, isRecord as _n, genUuid as Rt, buildSendMessageBody as Fr, isAgentOrAiMessage as Ur, resolveClientPresentation as qr, ConnectionRequestExpiredError as zr, ConnectionAttemptUnavailableError as Zr, PrimitiveState as Rn, WidgetCtx as Vr, resolveSidebarMode as Br, resolveSidebarSide as Wr, normalizeCompanionLayouts as Jr, resolveCompanionDefaultLayout as Hr } from "@opencx/widget-core";
|
|
8
|
+
import { safeParseAsync as Yr, lazy as Kr, unknown as Gr, union as Qr, string as Xr, record as es, object as ts, number as ns, null as rs, never as ss, looseObject as as, literal as is, instanceof as os, enum as ls, discriminatedUnion as cs, custom as us, boolean as ds, array as ps } from "zod/v4";
|
|
9
9
|
import { toJSONSchema as fs } from "zod/v4/core";
|
|
10
10
|
import "react/jsx-runtime";
|
|
11
11
|
import { z as L } from "zod";
|
|
12
|
-
const
|
|
12
|
+
const Pn = "5.12.0";
|
|
13
13
|
function K(t) {
|
|
14
14
|
return zt(t.subscribe, t.get, t.get);
|
|
15
15
|
}
|
|
16
16
|
function ms({
|
|
17
17
|
turnSources: t,
|
|
18
18
|
liveItems: e,
|
|
19
|
-
isStreaming:
|
|
20
|
-
lastMessageIsFromUser:
|
|
19
|
+
isStreaming: n,
|
|
20
|
+
lastMessageIsFromUser: r
|
|
21
21
|
}) {
|
|
22
22
|
var o;
|
|
23
|
-
if (
|
|
23
|
+
if (n || r) return null;
|
|
24
24
|
const s = e.length > 0 ? e : (o = t.at(-1)) == null ? void 0 : o.items;
|
|
25
25
|
return s ? gs(s) : null;
|
|
26
26
|
}
|
|
27
27
|
function gs(t) {
|
|
28
28
|
for (let e = t.length - 1; e >= 0; e--) {
|
|
29
|
-
const
|
|
30
|
-
if ((
|
|
29
|
+
const n = t[e];
|
|
30
|
+
if ((n == null ? void 0 : n.kind) === "questions") return n.request;
|
|
31
31
|
}
|
|
32
32
|
return null;
|
|
33
33
|
}
|
|
34
|
-
const
|
|
35
|
-
var ee = class
|
|
34
|
+
const On = "vercel.ai.error", hs = Symbol.for(On);
|
|
35
|
+
var ee = class Nn extends Error {
|
|
36
36
|
/**
|
|
37
37
|
* Creates an AI SDK Error.
|
|
38
38
|
*
|
|
@@ -41,8 +41,8 @@ var ee = class Or extends Error {
|
|
|
41
41
|
* @param {string} params.message - The error message.
|
|
42
42
|
* @param {unknown} [params.cause] - The underlying cause of the error.
|
|
43
43
|
*/
|
|
44
|
-
constructor({ name: e, message:
|
|
45
|
-
super(
|
|
44
|
+
constructor({ name: e, message: n, cause: r }) {
|
|
45
|
+
super(n), this[hs] = !0, this.name = e, this.cause = r;
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Checks if the given error is an AI SDK Error.
|
|
@@ -50,86 +50,86 @@ var ee = class Or extends Error {
|
|
|
50
50
|
* @returns {boolean} True if the error is an AI SDK Error, false otherwise.
|
|
51
51
|
*/
|
|
52
52
|
static isInstance(e) {
|
|
53
|
-
return
|
|
53
|
+
return Nn.hasMarker(e, On);
|
|
54
54
|
}
|
|
55
|
-
static hasMarker(e,
|
|
56
|
-
const
|
|
57
|
-
return e != null && typeof e == "object" &&
|
|
55
|
+
static hasMarker(e, n) {
|
|
56
|
+
const r = Symbol.for(n);
|
|
57
|
+
return e != null && typeof e == "object" && r in e && typeof e[r] == "boolean" && e[r] === !0;
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
|
-
const
|
|
61
|
-
var
|
|
62
|
-
constructor({ message: t, url: e, requestBodyValues:
|
|
60
|
+
const Dn = "AI_APICallError", Ln = `vercel.ai.error.${Dn}`, ys = Symbol.for(Ln);
|
|
61
|
+
var kn = class extends ee {
|
|
62
|
+
constructor({ message: t, url: e, requestBodyValues: n, statusCode: r, responseHeaders: s, responseBody: o, cause: l, isRetryable: u = r != null && (r === 408 || r === 409 || r === 429 || r >= 500), data: y }) {
|
|
63
63
|
super({
|
|
64
|
-
name:
|
|
64
|
+
name: Dn,
|
|
65
65
|
message: t,
|
|
66
66
|
cause: l
|
|
67
|
-
}), this[ys] = !0, this.url = e, this.requestBodyValues =
|
|
67
|
+
}), this[ys] = !0, this.url = e, this.requestBodyValues = n, this.statusCode = r, this.responseHeaders = s, this.responseBody = o, this.isRetryable = u, this.data = y;
|
|
68
68
|
}
|
|
69
69
|
static isInstance(t) {
|
|
70
|
-
return ee.hasMarker(t,
|
|
70
|
+
return ee.hasMarker(t, Ln);
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
|
-
const
|
|
73
|
+
const jn = "AI_EmptyResponseBodyError", $n = `vercel.ai.error.${jn}`, vs = Symbol.for($n);
|
|
74
74
|
var ft = class extends ee {
|
|
75
75
|
constructor({ message: t = "Empty response body" } = {}) {
|
|
76
76
|
super({
|
|
77
|
-
name:
|
|
77
|
+
name: jn,
|
|
78
78
|
message: t
|
|
79
79
|
}), this[vs] = !0;
|
|
80
80
|
}
|
|
81
81
|
static isInstance(t) {
|
|
82
|
-
return ee.hasMarker(t,
|
|
82
|
+
return ee.hasMarker(t, $n);
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
|
-
function
|
|
85
|
+
function Fn(t) {
|
|
86
86
|
return t == null ? "unknown error" : typeof t == "string" ? t : t instanceof Error ? t.toString() : JSON.stringify(t);
|
|
87
87
|
}
|
|
88
|
-
const
|
|
88
|
+
const Un = "AI_InvalidArgumentError", qn = `vercel.ai.error.${Un}`, bs = Symbol.for(qn);
|
|
89
89
|
var Ss = class extends ee {
|
|
90
|
-
constructor({ message: e, cause:
|
|
90
|
+
constructor({ message: e, cause: n, argument: r }) {
|
|
91
91
|
super({
|
|
92
|
-
name:
|
|
92
|
+
name: Un,
|
|
93
93
|
message: e,
|
|
94
|
-
cause:
|
|
95
|
-
}), this[bs] = !0, this.argument =
|
|
94
|
+
cause: n
|
|
95
|
+
}), this[bs] = !0, this.argument = r;
|
|
96
96
|
}
|
|
97
97
|
static isInstance(e) {
|
|
98
|
-
return ee.hasMarker(e,
|
|
98
|
+
return ee.hasMarker(e, qn);
|
|
99
99
|
}
|
|
100
100
|
};
|
|
101
|
-
const
|
|
102
|
-
var
|
|
101
|
+
const zn = "AI_JSONParseError", Zn = `vercel.ai.error.${zn}`, Is = Symbol.for(Zn);
|
|
102
|
+
var rn = class extends ee {
|
|
103
103
|
constructor({ text: t, cause: e }) {
|
|
104
104
|
super({
|
|
105
|
-
name:
|
|
105
|
+
name: zn,
|
|
106
106
|
message: `JSON parsing failed: Text: ${t}.
|
|
107
|
-
Error message: ${
|
|
107
|
+
Error message: ${Fn(e)}`,
|
|
108
108
|
cause: e
|
|
109
109
|
}), this[Is] = !0, this.text = t;
|
|
110
110
|
}
|
|
111
111
|
static isInstance(t) {
|
|
112
|
-
return ee.hasMarker(t,
|
|
112
|
+
return ee.hasMarker(t, Zn);
|
|
113
113
|
}
|
|
114
114
|
};
|
|
115
|
-
const
|
|
115
|
+
const Vn = "AI_TypeValidationError", Bn = `vercel.ai.error.${Vn}`, Es = Symbol.for(Bn);
|
|
116
116
|
var mt = class $t extends ee {
|
|
117
|
-
constructor({ value: e, cause:
|
|
117
|
+
constructor({ value: e, cause: n, context: r }) {
|
|
118
118
|
let s = "Type validation failed";
|
|
119
|
-
if (
|
|
119
|
+
if (r != null && r.field && (s += ` for ${r.field}`), r != null && r.entityName || r != null && r.entityId) {
|
|
120
120
|
s += " (";
|
|
121
121
|
const o = [];
|
|
122
|
-
|
|
122
|
+
r.entityName && o.push(r.entityName), r.entityId && o.push(`id: "${r.entityId}"`), s += o.join(", "), s += ")";
|
|
123
123
|
}
|
|
124
124
|
super({
|
|
125
|
-
name:
|
|
125
|
+
name: Vn,
|
|
126
126
|
message: `${s}: Value: ${JSON.stringify(e)}.
|
|
127
|
-
Error message: ${
|
|
128
|
-
cause:
|
|
129
|
-
}), this[Es] = !0, this.value = e, this.context =
|
|
127
|
+
Error message: ${Fn(n)}`,
|
|
128
|
+
cause: n
|
|
129
|
+
}), this[Es] = !0, this.value = e, this.context = r;
|
|
130
130
|
}
|
|
131
131
|
static isInstance(e) {
|
|
132
|
-
return ee.hasMarker(e,
|
|
132
|
+
return ee.hasMarker(e, Bn);
|
|
133
133
|
}
|
|
134
134
|
/**
|
|
135
135
|
* Wraps an error into a TypeValidationError.
|
|
@@ -142,33 +142,33 @@ Error message: ${$r(r)}`,
|
|
|
142
142
|
* @param {TypeValidationContext} params.context - Optional context about what is being validated.
|
|
143
143
|
* @returns {TypeValidationError} A TypeValidationError instance.
|
|
144
144
|
*/
|
|
145
|
-
static wrap({ value: e, cause:
|
|
145
|
+
static wrap({ value: e, cause: n, context: r }) {
|
|
146
146
|
var s, o, l;
|
|
147
|
-
return $t.isInstance(
|
|
147
|
+
return $t.isInstance(n) && n.value === e && ((s = n.context) == null ? void 0 : s.field) === (r == null ? void 0 : r.field) && ((o = n.context) == null ? void 0 : o.entityName) === (r == null ? void 0 : r.entityName) && ((l = n.context) == null ? void 0 : l.entityId) === (r == null ? void 0 : r.entityId) ? n : new $t({
|
|
148
148
|
value: e,
|
|
149
|
-
cause:
|
|
150
|
-
context:
|
|
149
|
+
cause: n,
|
|
150
|
+
context: r
|
|
151
151
|
});
|
|
152
152
|
}
|
|
153
153
|
};
|
|
154
|
-
const
|
|
154
|
+
const Wn = "AI_UnsupportedFunctionalityError", Jn = `vercel.ai.error.${Wn}`, Cs = Symbol.for(Jn);
|
|
155
155
|
var ws = class extends ee {
|
|
156
156
|
constructor({ functionality: t, message: e = `'${t}' functionality not supported.` }) {
|
|
157
157
|
super({
|
|
158
|
-
name:
|
|
158
|
+
name: Wn,
|
|
159
159
|
message: e
|
|
160
160
|
}), this[Cs] = !0, this.functionality = t;
|
|
161
161
|
}
|
|
162
162
|
static isInstance(t) {
|
|
163
|
-
return ee.hasMarker(t,
|
|
163
|
+
return ee.hasMarker(t, Jn);
|
|
164
164
|
}
|
|
165
165
|
};
|
|
166
166
|
class Pt extends Error {
|
|
167
|
-
constructor(e,
|
|
168
|
-
super(e), this.name = "ParseError", this.type =
|
|
167
|
+
constructor(e, n) {
|
|
168
|
+
super(e), this.name = "ParseError", this.type = n.type, this.field = n.field, this.value = n.value, this.line = n.line;
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
|
-
const
|
|
171
|
+
const sn = 10, As = 13, Oe = 32;
|
|
172
172
|
function Ot(t) {
|
|
173
173
|
}
|
|
174
174
|
function xs(t) {
|
|
@@ -176,7 +176,7 @@ function xs(t) {
|
|
|
176
176
|
throw new TypeError(
|
|
177
177
|
"`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?"
|
|
178
178
|
);
|
|
179
|
-
const { onEvent: e = Ot, onError:
|
|
179
|
+
const { onEvent: e = Ot, onError: n = Ot, onRetry: r = Ot, onComment: s, maxBufferSize: o } = t, l = [];
|
|
180
180
|
let u = 0, y = !0, g, i = "", d = 0, p, b = !1;
|
|
181
181
|
function P(c) {
|
|
182
182
|
if (b)
|
|
@@ -200,7 +200,7 @@ function xs(t) {
|
|
|
200
200
|
f !== "" && (l.push(f), u = f.length), M();
|
|
201
201
|
}
|
|
202
202
|
function M() {
|
|
203
|
-
o !== void 0 && (u + i.length <= o || (b = !0, l.length = 0, u = 0, g = void 0, i = "", d = 0, p = void 0,
|
|
203
|
+
o !== void 0 && (u + i.length <= o || (b = !0, l.length = 0, u = 0, g = void 0, i = "", d = 0, p = void 0, n(
|
|
204
204
|
new Pt(`Buffered data exceeded max buffer size of ${o} characters`, {
|
|
205
205
|
type: "max-buffer-size-exceeded"
|
|
206
206
|
})
|
|
@@ -218,16 +218,16 @@ function xs(t) {
|
|
|
218
218
|
continue;
|
|
219
219
|
}
|
|
220
220
|
const h = c.charCodeAt(m);
|
|
221
|
-
if (
|
|
221
|
+
if (an(c, m, h)) {
|
|
222
222
|
const S = c.charCodeAt(m + 5) === Oe ? m + 6 : m + 5, N = c.slice(S, f);
|
|
223
|
-
if (d === 0 && c.charCodeAt(f + 1) ===
|
|
223
|
+
if (d === 0 && c.charCodeAt(f + 1) === sn) {
|
|
224
224
|
e({ id: g, event: p, data: N }), g = void 0, i = "", p = void 0, m = f + 2, f = c.indexOf(`
|
|
225
225
|
`, m);
|
|
226
226
|
continue;
|
|
227
227
|
}
|
|
228
228
|
i = d === 0 ? N : `${i}
|
|
229
229
|
${N}`, d++;
|
|
230
|
-
} else
|
|
230
|
+
} else on(c, m, h) ? p = c.slice(
|
|
231
231
|
c.charCodeAt(m + 6) === Oe ? m + 7 : m + 6,
|
|
232
232
|
f
|
|
233
233
|
) || void 0 : x(c, m, f);
|
|
@@ -242,7 +242,7 @@ ${N}`, d++;
|
|
|
242
242
|
let S = -1;
|
|
243
243
|
if (f !== -1 && h !== -1 ? S = f < h ? f : h : f !== -1 ? f === c.length - 1 ? S = -1 : S = f : h !== -1 && (S = h), S === -1)
|
|
244
244
|
break;
|
|
245
|
-
x(c, m, S), m = S + 1, c.charCodeAt(m - 1) === As && c.charCodeAt(m) ===
|
|
245
|
+
x(c, m, S), m = S + 1, c.charCodeAt(m - 1) === As && c.charCodeAt(m) === sn && m++;
|
|
246
246
|
}
|
|
247
247
|
return c.slice(m);
|
|
248
248
|
}
|
|
@@ -252,37 +252,37 @@ ${N}`, d++;
|
|
|
252
252
|
return;
|
|
253
253
|
}
|
|
254
254
|
const h = c.charCodeAt(m);
|
|
255
|
-
if (
|
|
256
|
-
const
|
|
255
|
+
if (an(c, m, h)) {
|
|
256
|
+
const k = c.charCodeAt(m + 5) === Oe ? m + 6 : m + 5, $ = c.slice(k, f);
|
|
257
257
|
i = d === 0 ? $ : `${i}
|
|
258
258
|
${$}`, d++;
|
|
259
259
|
return;
|
|
260
260
|
}
|
|
261
|
-
if (
|
|
261
|
+
if (on(c, m, h)) {
|
|
262
262
|
p = c.slice(c.charCodeAt(m + 6) === Oe ? m + 7 : m + 6, f) || void 0;
|
|
263
263
|
return;
|
|
264
264
|
}
|
|
265
265
|
if (h === 105 && c.charCodeAt(m + 1) === 100 && c.charCodeAt(m + 2) === 58) {
|
|
266
|
-
const
|
|
267
|
-
g =
|
|
266
|
+
const k = c.slice(c.charCodeAt(m + 3) === Oe ? m + 4 : m + 3, f);
|
|
267
|
+
g = k.includes("\0") ? void 0 : k;
|
|
268
268
|
return;
|
|
269
269
|
}
|
|
270
270
|
if (h === 58) {
|
|
271
271
|
if (s) {
|
|
272
|
-
const
|
|
273
|
-
s(
|
|
272
|
+
const k = c.slice(m, f);
|
|
273
|
+
s(k.slice(c.charCodeAt(m + 1) === Oe ? 2 : 1));
|
|
274
274
|
}
|
|
275
275
|
return;
|
|
276
276
|
}
|
|
277
277
|
const S = c.slice(m, f), N = S.indexOf(":");
|
|
278
278
|
if (N === -1) {
|
|
279
|
-
|
|
279
|
+
C(S, "", S);
|
|
280
280
|
return;
|
|
281
281
|
}
|
|
282
282
|
const D = S.slice(0, N), B = S.charCodeAt(N + 1) === Oe ? 2 : 1, W = S.slice(N + B);
|
|
283
|
-
|
|
283
|
+
C(D, W, S);
|
|
284
284
|
}
|
|
285
|
-
function
|
|
285
|
+
function C(c, m, f) {
|
|
286
286
|
switch (c) {
|
|
287
287
|
case "event":
|
|
288
288
|
p = m || void 0;
|
|
@@ -295,7 +295,7 @@ ${m}`, d++;
|
|
|
295
295
|
g = m.includes("\0") ? void 0 : m;
|
|
296
296
|
break;
|
|
297
297
|
case "retry":
|
|
298
|
-
/^\d+$/.test(m) ?
|
|
298
|
+
/^\d+$/.test(m) ? r(parseInt(m, 10)) : n(
|
|
299
299
|
new Pt(`Invalid \`retry\` value: "${m}"`, {
|
|
300
300
|
type: "invalid-retry",
|
|
301
301
|
value: m,
|
|
@@ -304,7 +304,7 @@ ${m}`, d++;
|
|
|
304
304
|
);
|
|
305
305
|
break;
|
|
306
306
|
default:
|
|
307
|
-
|
|
307
|
+
n(
|
|
308
308
|
new Pt(
|
|
309
309
|
`Unknown field "${c.length > 20 ? `${c.slice(0, 20)}…` : c}"`,
|
|
310
310
|
{ type: "unknown-field", field: c, value: m, line: f }
|
|
@@ -320,23 +320,23 @@ ${m}`, d++;
|
|
|
320
320
|
data: i
|
|
321
321
|
}), g = void 0, i = "", d = 0, p = void 0;
|
|
322
322
|
}
|
|
323
|
-
function
|
|
323
|
+
function w(c = {}) {
|
|
324
324
|
if (c.consume && l.length > 0) {
|
|
325
325
|
const m = l.join("");
|
|
326
326
|
x(m, 0, m.length);
|
|
327
327
|
}
|
|
328
328
|
y = !0, g = void 0, i = "", d = 0, p = void 0, l.length = 0, u = 0, b = !1;
|
|
329
329
|
}
|
|
330
|
-
return { feed: P, reset:
|
|
330
|
+
return { feed: P, reset: w };
|
|
331
331
|
}
|
|
332
|
-
function
|
|
333
|
-
return
|
|
332
|
+
function an(t, e, n) {
|
|
333
|
+
return n === 100 && t.charCodeAt(e + 1) === 97 && t.charCodeAt(e + 2) === 116 && t.charCodeAt(e + 3) === 97 && t.charCodeAt(e + 4) === 58;
|
|
334
334
|
}
|
|
335
|
-
function
|
|
336
|
-
return
|
|
335
|
+
function on(t, e, n) {
|
|
336
|
+
return n === 101 && t.charCodeAt(e + 1) === 118 && t.charCodeAt(e + 2) === 101 && t.charCodeAt(e + 3) === 110 && t.charCodeAt(e + 4) === 116 && t.charCodeAt(e + 5) === 58;
|
|
337
337
|
}
|
|
338
338
|
class Ts extends TransformStream {
|
|
339
|
-
constructor({ onError: e, onRetry:
|
|
339
|
+
constructor({ onError: e, onRetry: n, onComment: r, maxBufferSize: s } = {}) {
|
|
340
340
|
let o;
|
|
341
341
|
super({
|
|
342
342
|
start(l) {
|
|
@@ -347,8 +347,8 @@ class Ts extends TransformStream {
|
|
|
347
347
|
onError(u) {
|
|
348
348
|
typeof e == "function" && e(u), (e === "terminate" || u.type === "max-buffer-size-exceeded") && l.error(u);
|
|
349
349
|
},
|
|
350
|
-
onRetry:
|
|
351
|
-
onComment:
|
|
350
|
+
onRetry: n,
|
|
351
|
+
onComment: r,
|
|
352
352
|
maxBufferSize: s
|
|
353
353
|
});
|
|
354
354
|
},
|
|
@@ -362,47 +362,47 @@ new TextDecoder();
|
|
|
362
362
|
function Ze(t) {
|
|
363
363
|
if (t == null) return {};
|
|
364
364
|
const e = {};
|
|
365
|
-
if (t instanceof Headers) t.forEach((
|
|
366
|
-
e[
|
|
365
|
+
if (t instanceof Headers) t.forEach((n, r) => {
|
|
366
|
+
e[r.toLowerCase()] = n;
|
|
367
367
|
});
|
|
368
368
|
else {
|
|
369
369
|
Array.isArray(t) || (t = Object.entries(t));
|
|
370
|
-
for (const [
|
|
370
|
+
for (const [n, r] of t) r != null && (e[n.toLowerCase()] = r);
|
|
371
371
|
}
|
|
372
372
|
return e;
|
|
373
373
|
}
|
|
374
|
-
const te = ({ prefix: t, size: e = 16, alphabet:
|
|
374
|
+
const te = ({ prefix: t, size: e = 16, alphabet: n = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", separator: r = "-" } = {}) => {
|
|
375
375
|
const s = () => {
|
|
376
|
-
const o =
|
|
377
|
-
for (let u = 0; u < e; u++) l[u] =
|
|
376
|
+
const o = n.length, l = new Array(e);
|
|
377
|
+
for (let u = 0; u < e; u++) l[u] = n[Math.random() * o | 0];
|
|
378
378
|
return l.join("");
|
|
379
379
|
};
|
|
380
380
|
if (t == null) return s;
|
|
381
|
-
if (
|
|
381
|
+
if (n.includes(r)) throw new Ss({
|
|
382
382
|
argument: "separator",
|
|
383
|
-
message: `The separator "${
|
|
383
|
+
message: `The separator "${r}" must not be part of the alphabet "${n}".`
|
|
384
384
|
});
|
|
385
|
-
return () => `${t}${
|
|
385
|
+
return () => `${t}${r}${s()}`;
|
|
386
386
|
}, Ms = te();
|
|
387
387
|
function _s(t) {
|
|
388
388
|
var e;
|
|
389
389
|
return ((e = globalThis.Buffer) == null ? void 0 : e.isBuffer(t)) ?? !1;
|
|
390
390
|
}
|
|
391
391
|
const Rs = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/, Ps = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
|
|
392
|
-
function
|
|
392
|
+
function ln(t) {
|
|
393
393
|
const e = JSON.parse(t);
|
|
394
394
|
return e === null || typeof e != "object" || Rs.test(t) === !1 && Ps.test(t) === !1 ? e : Os(e);
|
|
395
395
|
}
|
|
396
396
|
function Os(t) {
|
|
397
397
|
let e = [t];
|
|
398
398
|
for (; e.length; ) {
|
|
399
|
-
const
|
|
399
|
+
const n = e;
|
|
400
400
|
e = [];
|
|
401
|
-
for (const
|
|
402
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
403
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
404
|
-
for (const s in
|
|
405
|
-
const o =
|
|
401
|
+
for (const r of n) {
|
|
402
|
+
if (Object.prototype.hasOwnProperty.call(r, "__proto__")) throw new SyntaxError("Object contains forbidden prototype property");
|
|
403
|
+
if (Object.prototype.hasOwnProperty.call(r, "constructor") && r.constructor !== null && typeof r.constructor == "object" && Object.prototype.hasOwnProperty.call(r.constructor, "prototype")) throw new SyntaxError("Object contains forbidden prototype property");
|
|
404
|
+
for (const s in r) {
|
|
405
|
+
const o = r[s];
|
|
406
406
|
o && typeof o == "object" && e.push(o);
|
|
407
407
|
}
|
|
408
408
|
}
|
|
@@ -414,30 +414,30 @@ function Ns(t) {
|
|
|
414
414
|
try {
|
|
415
415
|
Error.stackTraceLimit = 0;
|
|
416
416
|
} catch {
|
|
417
|
-
return
|
|
417
|
+
return ln(t);
|
|
418
418
|
}
|
|
419
419
|
try {
|
|
420
|
-
return
|
|
420
|
+
return ln(t);
|
|
421
421
|
} finally {
|
|
422
422
|
Error.stackTraceLimit = e;
|
|
423
423
|
}
|
|
424
424
|
}
|
|
425
425
|
function Zt(t) {
|
|
426
426
|
if (t.type === "object" || Array.isArray(t.type) && t.type.includes("object")) {
|
|
427
|
-
const { additionalProperties:
|
|
428
|
-
t.additionalProperties =
|
|
429
|
-
const { properties:
|
|
430
|
-
if (
|
|
427
|
+
const { additionalProperties: n } = t;
|
|
428
|
+
t.additionalProperties = n != null && typeof n != "boolean" ? Me(n) : !1;
|
|
429
|
+
const { properties: r } = t;
|
|
430
|
+
if (r != null) for (const s of Object.keys(r)) r[s] = Me(r[s]);
|
|
431
431
|
}
|
|
432
432
|
t.items != null && (t.items = Array.isArray(t.items) ? t.items.map(Me) : Me(t.items)), t.anyOf != null && (t.anyOf = t.anyOf.map(Me)), t.allOf != null && (t.allOf = t.allOf.map(Me)), t.oneOf != null && (t.oneOf = t.oneOf.map(Me));
|
|
433
433
|
const { definitions: e } = t;
|
|
434
|
-
if (e != null) for (const
|
|
434
|
+
if (e != null) for (const n of Object.keys(e)) e[n] = Me(e[n]);
|
|
435
435
|
return t;
|
|
436
436
|
}
|
|
437
437
|
function Me(t) {
|
|
438
438
|
return typeof t == "boolean" ? t : Zt(t);
|
|
439
439
|
}
|
|
440
|
-
const Ds = Symbol("Let zodToJsonSchema decide on which parser to use"),
|
|
440
|
+
const Ds = Symbol("Let zodToJsonSchema decide on which parser to use"), cn = {
|
|
441
441
|
name: void 0,
|
|
442
442
|
$refStrategy: "root",
|
|
443
443
|
basePath: ["#"],
|
|
@@ -458,52 +458,52 @@ const Ds = Symbol("Let zodToJsonSchema decide on which parser to use"), lr = {
|
|
|
458
458
|
base64Strategy: "contentEncoding:base64",
|
|
459
459
|
nameStrategy: "ref"
|
|
460
460
|
}, Ls = (t) => typeof t == "string" ? {
|
|
461
|
-
...
|
|
461
|
+
...cn,
|
|
462
462
|
name: t
|
|
463
463
|
} : {
|
|
464
|
-
...
|
|
464
|
+
...cn,
|
|
465
465
|
...t
|
|
466
466
|
};
|
|
467
467
|
function ue() {
|
|
468
468
|
return {};
|
|
469
469
|
}
|
|
470
|
-
function
|
|
471
|
-
var
|
|
472
|
-
const
|
|
473
|
-
return (
|
|
470
|
+
function ks(t, e) {
|
|
471
|
+
var r, s, o;
|
|
472
|
+
const n = { type: "array" };
|
|
473
|
+
return (r = t.type) != null && r._def && ((o = (s = t.type) == null ? void 0 : s._def) == null ? void 0 : o.typeName) !== "ZodAny" && (n.items = q(t.type._def, {
|
|
474
474
|
...e,
|
|
475
475
|
currentPath: [...e.currentPath, "items"]
|
|
476
|
-
})), t.minLength && (
|
|
476
|
+
})), t.minLength && (n.minItems = t.minLength.value), t.maxLength && (n.maxItems = t.maxLength.value), t.exactLength && (n.minItems = t.exactLength.value, n.maxItems = t.exactLength.value), n;
|
|
477
477
|
}
|
|
478
|
-
function
|
|
478
|
+
function js(t) {
|
|
479
479
|
const e = {
|
|
480
480
|
type: "integer",
|
|
481
481
|
format: "int64"
|
|
482
482
|
};
|
|
483
483
|
if (!t.checks) return e;
|
|
484
|
-
for (const
|
|
484
|
+
for (const n of t.checks) switch (n.kind) {
|
|
485
485
|
case "min":
|
|
486
|
-
|
|
486
|
+
n.inclusive ? e.minimum = n.value : e.exclusiveMinimum = n.value;
|
|
487
487
|
break;
|
|
488
488
|
case "max":
|
|
489
|
-
|
|
489
|
+
n.inclusive ? e.maximum = n.value : e.exclusiveMaximum = n.value;
|
|
490
490
|
break;
|
|
491
491
|
case "multipleOf":
|
|
492
|
-
e.multipleOf =
|
|
492
|
+
e.multipleOf = n.value;
|
|
493
493
|
}
|
|
494
494
|
return e;
|
|
495
495
|
}
|
|
496
496
|
function $s() {
|
|
497
497
|
return { type: "boolean" };
|
|
498
498
|
}
|
|
499
|
-
function
|
|
499
|
+
function Hn(t, e) {
|
|
500
500
|
return q(t.type._def, e);
|
|
501
501
|
}
|
|
502
502
|
const Fs = (t, e) => q(t.innerType._def, e);
|
|
503
|
-
function
|
|
504
|
-
const
|
|
505
|
-
if (Array.isArray(
|
|
506
|
-
switch (
|
|
503
|
+
function Yn(t, e, n) {
|
|
504
|
+
const r = n ?? e.dateStrategy;
|
|
505
|
+
if (Array.isArray(r)) return { anyOf: r.map((s) => Yn(t, e, s)) };
|
|
506
|
+
switch (r) {
|
|
507
507
|
case "string":
|
|
508
508
|
case "format:date-time":
|
|
509
509
|
return {
|
|
@@ -524,12 +524,12 @@ const Us = (t) => {
|
|
|
524
524
|
type: "integer",
|
|
525
525
|
format: "unix-time"
|
|
526
526
|
};
|
|
527
|
-
for (const
|
|
527
|
+
for (const n of t.checks) switch (n.kind) {
|
|
528
528
|
case "min":
|
|
529
|
-
e.minimum =
|
|
529
|
+
e.minimum = n.value;
|
|
530
530
|
break;
|
|
531
531
|
case "max":
|
|
532
|
-
e.maximum =
|
|
532
|
+
e.maximum = n.value;
|
|
533
533
|
}
|
|
534
534
|
return e;
|
|
535
535
|
};
|
|
@@ -550,7 +550,7 @@ function Zs(t) {
|
|
|
550
550
|
}
|
|
551
551
|
const Vs = (t) => "type" in t && t.type === "string" ? !1 : "allOf" in t;
|
|
552
552
|
function Bs(t, e) {
|
|
553
|
-
const
|
|
553
|
+
const n = [q(t.left._def, {
|
|
554
554
|
...e,
|
|
555
555
|
currentPath: [
|
|
556
556
|
...e.currentPath,
|
|
@@ -564,18 +564,18 @@ function Bs(t, e) {
|
|
|
564
564
|
"allOf",
|
|
565
565
|
"1"
|
|
566
566
|
]
|
|
567
|
-
})].filter((s) => !!s),
|
|
568
|
-
return
|
|
569
|
-
if (Vs(s))
|
|
567
|
+
})].filter((s) => !!s), r = [];
|
|
568
|
+
return n.forEach((s) => {
|
|
569
|
+
if (Vs(s)) r.push(...s.allOf);
|
|
570
570
|
else {
|
|
571
571
|
let o = s;
|
|
572
572
|
if ("additionalProperties" in s && s.additionalProperties === !1) {
|
|
573
573
|
const { additionalProperties: l, ...u } = s;
|
|
574
574
|
o = u;
|
|
575
575
|
}
|
|
576
|
-
|
|
576
|
+
r.push(o);
|
|
577
577
|
}
|
|
578
|
-
}),
|
|
578
|
+
}), r.length ? { allOf: r } : void 0;
|
|
579
579
|
}
|
|
580
580
|
function Ws(t) {
|
|
581
581
|
const e = typeof t.value;
|
|
@@ -627,100 +627,100 @@ const he = {
|
|
|
627
627
|
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
628
628
|
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
629
629
|
};
|
|
630
|
-
function
|
|
631
|
-
const
|
|
632
|
-
if (t.checks) for (const
|
|
630
|
+
function Kn(t, e) {
|
|
631
|
+
const n = { type: "string" };
|
|
632
|
+
if (t.checks) for (const r of t.checks) switch (r.kind) {
|
|
633
633
|
case "min":
|
|
634
|
-
|
|
634
|
+
n.minLength = typeof n.minLength == "number" ? Math.max(n.minLength, r.value) : r.value;
|
|
635
635
|
break;
|
|
636
636
|
case "max":
|
|
637
|
-
|
|
637
|
+
n.maxLength = typeof n.maxLength == "number" ? Math.min(n.maxLength, r.value) : r.value;
|
|
638
638
|
break;
|
|
639
639
|
case "email":
|
|
640
640
|
switch (e.emailStrategy) {
|
|
641
641
|
case "format:email":
|
|
642
|
-
ye(
|
|
642
|
+
ye(n, "email", r.message, e);
|
|
643
643
|
break;
|
|
644
644
|
case "format:idn-email":
|
|
645
|
-
ye(
|
|
645
|
+
ye(n, "idn-email", r.message, e);
|
|
646
646
|
break;
|
|
647
647
|
case "pattern:zod":
|
|
648
|
-
|
|
648
|
+
se(n, he.email, r.message, e);
|
|
649
649
|
}
|
|
650
650
|
break;
|
|
651
651
|
case "url":
|
|
652
|
-
ye(
|
|
652
|
+
ye(n, "uri", r.message, e);
|
|
653
653
|
break;
|
|
654
654
|
case "uuid":
|
|
655
|
-
ye(
|
|
655
|
+
ye(n, "uuid", r.message, e);
|
|
656
656
|
break;
|
|
657
657
|
case "regex":
|
|
658
|
-
|
|
658
|
+
se(n, r.regex, r.message, e);
|
|
659
659
|
break;
|
|
660
660
|
case "cuid":
|
|
661
|
-
|
|
661
|
+
se(n, he.cuid, r.message, e);
|
|
662
662
|
break;
|
|
663
663
|
case "cuid2":
|
|
664
|
-
|
|
664
|
+
se(n, he.cuid2, r.message, e);
|
|
665
665
|
break;
|
|
666
666
|
case "startsWith":
|
|
667
|
-
|
|
667
|
+
se(n, RegExp(`^${Dt(r.value, e)}`), r.message, e);
|
|
668
668
|
break;
|
|
669
669
|
case "endsWith":
|
|
670
|
-
|
|
670
|
+
se(n, RegExp(`${Dt(r.value, e)}$`), r.message, e);
|
|
671
671
|
break;
|
|
672
672
|
case "datetime":
|
|
673
|
-
ye(
|
|
673
|
+
ye(n, "date-time", r.message, e);
|
|
674
674
|
break;
|
|
675
675
|
case "date":
|
|
676
|
-
ye(
|
|
676
|
+
ye(n, "date", r.message, e);
|
|
677
677
|
break;
|
|
678
678
|
case "time":
|
|
679
|
-
ye(
|
|
679
|
+
ye(n, "time", r.message, e);
|
|
680
680
|
break;
|
|
681
681
|
case "duration":
|
|
682
|
-
ye(
|
|
682
|
+
ye(n, "duration", r.message, e);
|
|
683
683
|
break;
|
|
684
684
|
case "length":
|
|
685
|
-
|
|
685
|
+
n.minLength = typeof n.minLength == "number" ? Math.max(n.minLength, r.value) : r.value, n.maxLength = typeof n.maxLength == "number" ? Math.min(n.maxLength, r.value) : r.value;
|
|
686
686
|
break;
|
|
687
687
|
case "includes":
|
|
688
|
-
|
|
688
|
+
se(n, RegExp(Dt(r.value, e)), r.message, e);
|
|
689
689
|
break;
|
|
690
690
|
case "ip":
|
|
691
|
-
|
|
691
|
+
r.version !== "v6" && ye(n, "ipv4", r.message, e), r.version !== "v4" && ye(n, "ipv6", r.message, e);
|
|
692
692
|
break;
|
|
693
693
|
case "base64url":
|
|
694
|
-
|
|
694
|
+
se(n, he.base64url, r.message, e);
|
|
695
695
|
break;
|
|
696
696
|
case "jwt":
|
|
697
|
-
|
|
697
|
+
se(n, he.jwt, r.message, e);
|
|
698
698
|
break;
|
|
699
699
|
case "cidr":
|
|
700
|
-
|
|
700
|
+
r.version !== "v6" && se(n, he.ipv4Cidr, r.message, e), r.version !== "v4" && se(n, he.ipv6Cidr, r.message, e);
|
|
701
701
|
break;
|
|
702
702
|
case "emoji":
|
|
703
|
-
|
|
703
|
+
se(n, he.emoji(), r.message, e);
|
|
704
704
|
break;
|
|
705
705
|
case "ulid":
|
|
706
|
-
|
|
706
|
+
se(n, he.ulid, r.message, e);
|
|
707
707
|
break;
|
|
708
708
|
case "base64":
|
|
709
709
|
switch (e.base64Strategy) {
|
|
710
710
|
case "format:binary":
|
|
711
|
-
ye(
|
|
711
|
+
ye(n, "binary", r.message, e);
|
|
712
712
|
break;
|
|
713
713
|
case "contentEncoding:base64":
|
|
714
|
-
|
|
714
|
+
n.contentEncoding = "base64";
|
|
715
715
|
break;
|
|
716
716
|
case "pattern:zod":
|
|
717
|
-
|
|
717
|
+
se(n, he.base64, r.message, e);
|
|
718
718
|
}
|
|
719
719
|
break;
|
|
720
720
|
case "nanoid":
|
|
721
|
-
|
|
721
|
+
se(n, he.nanoid, r.message, e);
|
|
722
722
|
}
|
|
723
|
-
return
|
|
723
|
+
return n;
|
|
724
724
|
}
|
|
725
725
|
function Dt(t, e) {
|
|
726
726
|
return e.patternStrategy === "escape" ? Hs(t) : t;
|
|
@@ -728,67 +728,67 @@ function Dt(t, e) {
|
|
|
728
728
|
const Js = /* @__PURE__ */ new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
729
729
|
function Hs(t) {
|
|
730
730
|
let e = "";
|
|
731
|
-
for (let
|
|
732
|
-
Js.has(t[
|
|
731
|
+
for (let n = 0; n < t.length; n++)
|
|
732
|
+
Js.has(t[n]) || (e += "\\"), e += t[n];
|
|
733
733
|
return e;
|
|
734
734
|
}
|
|
735
|
-
function ye(t, e,
|
|
735
|
+
function ye(t, e, n, r) {
|
|
736
736
|
var s;
|
|
737
737
|
t.format || (s = t.anyOf) != null && s.some((o) => o.format) ? (t.anyOf || (t.anyOf = []), t.format && (t.anyOf.push({ format: t.format }), delete t.format), t.anyOf.push({
|
|
738
738
|
format: e,
|
|
739
|
-
...
|
|
739
|
+
...n && r.errorMessages && { errorMessage: { format: n } }
|
|
740
740
|
})) : t.format = e;
|
|
741
741
|
}
|
|
742
|
-
function
|
|
742
|
+
function se(t, e, n, r) {
|
|
743
743
|
var s;
|
|
744
744
|
t.pattern || (s = t.allOf) != null && s.some((o) => o.pattern) ? (t.allOf || (t.allOf = []), t.pattern && (t.allOf.push({ pattern: t.pattern }), delete t.pattern), t.allOf.push({
|
|
745
|
-
pattern:
|
|
746
|
-
...
|
|
747
|
-
})) : t.pattern =
|
|
745
|
+
pattern: un(e, r),
|
|
746
|
+
...n && r.errorMessages && { errorMessage: { pattern: n } }
|
|
747
|
+
})) : t.pattern = un(e, r);
|
|
748
748
|
}
|
|
749
|
-
function
|
|
749
|
+
function un(t, e) {
|
|
750
750
|
var y;
|
|
751
751
|
if (!e.applyRegexFlags || !t.flags) return t.source;
|
|
752
|
-
const
|
|
752
|
+
const n = {
|
|
753
753
|
i: t.flags.includes("i"),
|
|
754
754
|
m: t.flags.includes("m"),
|
|
755
755
|
s: t.flags.includes("s")
|
|
756
|
-
},
|
|
756
|
+
}, r = n.i ? t.source.toLowerCase() : t.source;
|
|
757
757
|
let s = "", o = !1, l = !1, u = !1;
|
|
758
|
-
for (let g = 0; g <
|
|
758
|
+
for (let g = 0; g < r.length; g++) {
|
|
759
759
|
if (o) {
|
|
760
|
-
s +=
|
|
760
|
+
s += r[g], o = !1;
|
|
761
761
|
continue;
|
|
762
762
|
}
|
|
763
|
-
if (
|
|
763
|
+
if (n.i) {
|
|
764
764
|
if (l) {
|
|
765
|
-
if (
|
|
766
|
-
u ? (s +=
|
|
765
|
+
if (r[g].match(/[a-z]/)) {
|
|
766
|
+
u ? (s += r[g], s += `${r[g - 2]}-${r[g]}`.toUpperCase(), u = !1) : r[g + 1] === "-" && ((y = r[g + 2]) != null && y.match(/[a-z]/)) ? (s += r[g], u = !0) : s += `${r[g]}${r[g].toUpperCase()}`;
|
|
767
767
|
continue;
|
|
768
768
|
}
|
|
769
|
-
} else if (
|
|
770
|
-
s += `[${
|
|
769
|
+
} else if (r[g].match(/[a-z]/)) {
|
|
770
|
+
s += `[${r[g]}${r[g].toUpperCase()}]`;
|
|
771
771
|
continue;
|
|
772
772
|
}
|
|
773
773
|
}
|
|
774
|
-
if (
|
|
775
|
-
if (
|
|
774
|
+
if (n.m) {
|
|
775
|
+
if (r[g] === "^") {
|
|
776
776
|
s += `(^|(?<=[\r
|
|
777
777
|
]))`;
|
|
778
778
|
continue;
|
|
779
|
-
} else if (
|
|
779
|
+
} else if (r[g] === "$") {
|
|
780
780
|
s += `($|(?=[\r
|
|
781
781
|
]))`;
|
|
782
782
|
continue;
|
|
783
783
|
}
|
|
784
784
|
}
|
|
785
|
-
if (
|
|
786
|
-
s += l ? `${
|
|
787
|
-
` : `[${
|
|
785
|
+
if (n.s && r[g] === ".") {
|
|
786
|
+
s += l ? `${r[g]}\r
|
|
787
|
+
` : `[${r[g]}\r
|
|
788
788
|
]`;
|
|
789
789
|
continue;
|
|
790
790
|
}
|
|
791
|
-
s +=
|
|
791
|
+
s += r[g], r[g] === "\\" ? o = !0 : l && r[g] === "]" ? l = !1 : !l && r[g] === "[" && (l = !0);
|
|
792
792
|
}
|
|
793
793
|
try {
|
|
794
794
|
new RegExp(s);
|
|
@@ -797,38 +797,38 @@ function cr(t, e) {
|
|
|
797
797
|
}
|
|
798
798
|
return s;
|
|
799
799
|
}
|
|
800
|
-
function
|
|
801
|
-
var
|
|
802
|
-
const
|
|
800
|
+
function Gn(t, e) {
|
|
801
|
+
var r, s, o, l, u;
|
|
802
|
+
const n = {
|
|
803
803
|
type: "object",
|
|
804
804
|
additionalProperties: q(t.valueType._def, {
|
|
805
805
|
...e,
|
|
806
806
|
currentPath: [...e.currentPath, "additionalProperties"]
|
|
807
807
|
}) ?? e.allowedAdditionalProperties
|
|
808
808
|
};
|
|
809
|
-
if (((
|
|
810
|
-
const { type: y, ...g } =
|
|
809
|
+
if (((r = t.keyType) == null ? void 0 : r._def.typeName) === "ZodString" && ((s = t.keyType._def.checks) != null && s.length)) {
|
|
810
|
+
const { type: y, ...g } = Kn(t.keyType._def, e);
|
|
811
811
|
return {
|
|
812
|
-
...
|
|
812
|
+
...n,
|
|
813
813
|
propertyNames: g
|
|
814
814
|
};
|
|
815
815
|
} else {
|
|
816
816
|
if (((o = t.keyType) == null ? void 0 : o._def.typeName) === "ZodEnum") return {
|
|
817
|
-
...
|
|
817
|
+
...n,
|
|
818
818
|
propertyNames: { enum: t.keyType._def.values }
|
|
819
819
|
};
|
|
820
820
|
if (((l = t.keyType) == null ? void 0 : l._def.typeName) === "ZodBranded" && t.keyType._def.type._def.typeName === "ZodString" && ((u = t.keyType._def.type._def.checks) != null && u.length)) {
|
|
821
|
-
const { type: y, ...g } =
|
|
821
|
+
const { type: y, ...g } = Hn(t.keyType._def, e);
|
|
822
822
|
return {
|
|
823
|
-
...
|
|
823
|
+
...n,
|
|
824
824
|
propertyNames: g
|
|
825
825
|
};
|
|
826
826
|
}
|
|
827
827
|
}
|
|
828
|
-
return
|
|
828
|
+
return n;
|
|
829
829
|
}
|
|
830
830
|
function Ys(t, e) {
|
|
831
|
-
return e.mapStrategy === "record" ?
|
|
831
|
+
return e.mapStrategy === "record" ? Gn(t, e) : {
|
|
832
832
|
type: "array",
|
|
833
833
|
maxItems: 125,
|
|
834
834
|
items: {
|
|
@@ -856,10 +856,10 @@ function Ys(t, e) {
|
|
|
856
856
|
};
|
|
857
857
|
}
|
|
858
858
|
function Ks(t) {
|
|
859
|
-
const e = t.values,
|
|
859
|
+
const e = t.values, n = Object.keys(t.values).filter((s) => typeof e[e[s]] != "number").map((s) => e[s]), r = Array.from(new Set(n.map((s) => typeof s)));
|
|
860
860
|
return {
|
|
861
|
-
type:
|
|
862
|
-
enum:
|
|
861
|
+
type: r.length === 1 ? r[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
862
|
+
enum: n
|
|
863
863
|
};
|
|
864
864
|
}
|
|
865
865
|
function Gs() {
|
|
@@ -876,15 +876,15 @@ const Ft = {
|
|
|
876
876
|
ZodNull: "null"
|
|
877
877
|
};
|
|
878
878
|
function Xs(t, e) {
|
|
879
|
-
const
|
|
880
|
-
if (
|
|
881
|
-
const
|
|
879
|
+
const n = t.options instanceof Map ? Array.from(t.options.values()) : t.options;
|
|
880
|
+
if (n.every((r) => r._def.typeName in Ft && (!r._def.checks || !r._def.checks.length))) {
|
|
881
|
+
const r = n.reduce((s, o) => {
|
|
882
882
|
const l = Ft[o._def.typeName];
|
|
883
883
|
return l && !s.includes(l) ? [...s, l] : s;
|
|
884
884
|
}, []);
|
|
885
|
-
return { type:
|
|
886
|
-
} else if (
|
|
887
|
-
const
|
|
885
|
+
return { type: r.length > 1 ? r : r[0] };
|
|
886
|
+
} else if (n.every((r) => r._def.typeName === "ZodLiteral" && !r.description)) {
|
|
887
|
+
const r = n.reduce((s, o) => {
|
|
888
888
|
const l = typeof o._def.value;
|
|
889
889
|
switch (l) {
|
|
890
890
|
case "string":
|
|
@@ -899,29 +899,29 @@ function Xs(t, e) {
|
|
|
899
899
|
return s;
|
|
900
900
|
}
|
|
901
901
|
}, []);
|
|
902
|
-
if (
|
|
903
|
-
const s =
|
|
902
|
+
if (r.length === n.length) {
|
|
903
|
+
const s = r.filter((o, l, u) => u.indexOf(o) === l);
|
|
904
904
|
return {
|
|
905
905
|
type: s.length > 1 ? s : s[0],
|
|
906
|
-
enum:
|
|
906
|
+
enum: n.reduce((o, l) => o.includes(l._def.value) ? o : [...o, l._def.value], [])
|
|
907
907
|
};
|
|
908
908
|
}
|
|
909
|
-
} else if (
|
|
909
|
+
} else if (n.every((r) => r._def.typeName === "ZodEnum")) return {
|
|
910
910
|
type: "string",
|
|
911
|
-
enum:
|
|
911
|
+
enum: n.reduce((r, s) => [...r, ...s._def.values.filter((o) => !r.includes(o))], [])
|
|
912
912
|
};
|
|
913
913
|
return ea(t, e);
|
|
914
914
|
}
|
|
915
915
|
const ea = (t, e) => {
|
|
916
|
-
const
|
|
916
|
+
const n = (t.options instanceof Map ? Array.from(t.options.values()) : t.options).map((r, s) => q(r._def, {
|
|
917
917
|
...e,
|
|
918
918
|
currentPath: [
|
|
919
919
|
...e.currentPath,
|
|
920
920
|
"anyOf",
|
|
921
921
|
`${s}`
|
|
922
922
|
]
|
|
923
|
-
})).filter((
|
|
924
|
-
return
|
|
923
|
+
})).filter((r) => !!r && (!e.strictUnions || typeof r == "object" && Object.keys(r).length > 0));
|
|
924
|
+
return n.length ? { anyOf: n } : void 0;
|
|
925
925
|
};
|
|
926
926
|
function ta(t, e) {
|
|
927
927
|
if ([
|
|
@@ -931,7 +931,7 @@ function ta(t, e) {
|
|
|
931
931
|
"ZodBoolean",
|
|
932
932
|
"ZodNull"
|
|
933
933
|
].includes(t.innerType._def.typeName) && (!t.innerType._def.checks || !t.innerType._def.checks.length)) return { type: [Ft[t.innerType._def.typeName], "null"] };
|
|
934
|
-
const
|
|
934
|
+
const n = q(t.innerType._def, {
|
|
935
935
|
...e,
|
|
936
936
|
currentPath: [
|
|
937
937
|
...e.currentPath,
|
|
@@ -939,31 +939,31 @@ function ta(t, e) {
|
|
|
939
939
|
"0"
|
|
940
940
|
]
|
|
941
941
|
});
|
|
942
|
-
return
|
|
942
|
+
return n && { anyOf: [n, { type: "null" }] };
|
|
943
943
|
}
|
|
944
|
-
function
|
|
944
|
+
function na(t) {
|
|
945
945
|
const e = { type: "number" };
|
|
946
946
|
if (!t.checks) return e;
|
|
947
|
-
for (const
|
|
947
|
+
for (const n of t.checks) switch (n.kind) {
|
|
948
948
|
case "int":
|
|
949
949
|
e.type = "integer";
|
|
950
950
|
break;
|
|
951
951
|
case "min":
|
|
952
|
-
|
|
952
|
+
n.inclusive ? e.minimum = n.value : e.exclusiveMinimum = n.value;
|
|
953
953
|
break;
|
|
954
954
|
case "max":
|
|
955
|
-
|
|
955
|
+
n.inclusive ? e.maximum = n.value : e.exclusiveMaximum = n.value;
|
|
956
956
|
break;
|
|
957
957
|
case "multipleOf":
|
|
958
|
-
e.multipleOf =
|
|
958
|
+
e.multipleOf = n.value;
|
|
959
959
|
}
|
|
960
960
|
return e;
|
|
961
961
|
}
|
|
962
|
-
function
|
|
963
|
-
const
|
|
962
|
+
function ra(t, e) {
|
|
963
|
+
const n = {
|
|
964
964
|
type: "object",
|
|
965
965
|
properties: {}
|
|
966
|
-
},
|
|
966
|
+
}, r = [], s = t.shape();
|
|
967
967
|
for (const l in s) {
|
|
968
968
|
let u = s[l];
|
|
969
969
|
if (u === void 0 || u._def === void 0) continue;
|
|
@@ -980,11 +980,11 @@ function na(t, e) {
|
|
|
980
980
|
l
|
|
981
981
|
]
|
|
982
982
|
});
|
|
983
|
-
g !== void 0 && (
|
|
983
|
+
g !== void 0 && (n.properties[l] = g, y || r.push(l));
|
|
984
984
|
}
|
|
985
|
-
|
|
985
|
+
r.length && (n.required = r);
|
|
986
986
|
const o = sa(t, e);
|
|
987
|
-
return o !== void 0 && (
|
|
987
|
+
return o !== void 0 && (n.additionalProperties = o), n;
|
|
988
988
|
}
|
|
989
989
|
function sa(t, e) {
|
|
990
990
|
if (t.catchall._def.typeName !== "ZodNever") return q(t.catchall._def, {
|
|
@@ -1008,9 +1008,9 @@ function aa(t) {
|
|
|
1008
1008
|
}
|
|
1009
1009
|
}
|
|
1010
1010
|
const ia = (t, e) => {
|
|
1011
|
-
var
|
|
1012
|
-
if (e.currentPath.toString() === ((
|
|
1013
|
-
const
|
|
1011
|
+
var r;
|
|
1012
|
+
if (e.currentPath.toString() === ((r = e.propertyPath) == null ? void 0 : r.toString())) return q(t.innerType._def, e);
|
|
1013
|
+
const n = q(t.innerType._def, {
|
|
1014
1014
|
...e,
|
|
1015
1015
|
currentPath: [
|
|
1016
1016
|
...e.currentPath,
|
|
@@ -1018,11 +1018,11 @@ const ia = (t, e) => {
|
|
|
1018
1018
|
"1"
|
|
1019
1019
|
]
|
|
1020
1020
|
});
|
|
1021
|
-
return
|
|
1021
|
+
return n ? { anyOf: [{ not: ue() }, n] } : ue();
|
|
1022
1022
|
}, oa = (t, e) => {
|
|
1023
1023
|
if (e.pipeStrategy === "input") return q(t.in._def, e);
|
|
1024
1024
|
if (e.pipeStrategy === "output") return q(t.out._def, e);
|
|
1025
|
-
const
|
|
1025
|
+
const n = q(t.in._def, {
|
|
1026
1026
|
...e,
|
|
1027
1027
|
currentPath: [
|
|
1028
1028
|
...e.currentPath,
|
|
@@ -1030,20 +1030,20 @@ const ia = (t, e) => {
|
|
|
1030
1030
|
"0"
|
|
1031
1031
|
]
|
|
1032
1032
|
});
|
|
1033
|
-
return { allOf: [
|
|
1033
|
+
return { allOf: [n, q(t.out._def, {
|
|
1034
1034
|
...e,
|
|
1035
1035
|
currentPath: [
|
|
1036
1036
|
...e.currentPath,
|
|
1037
1037
|
"allOf",
|
|
1038
|
-
|
|
1038
|
+
n ? "1" : "0"
|
|
1039
1039
|
]
|
|
1040
|
-
})].filter((
|
|
1040
|
+
})].filter((r) => r !== void 0) };
|
|
1041
1041
|
};
|
|
1042
1042
|
function la(t, e) {
|
|
1043
1043
|
return q(t.type._def, e);
|
|
1044
1044
|
}
|
|
1045
1045
|
function ca(t, e) {
|
|
1046
|
-
const
|
|
1046
|
+
const n = {
|
|
1047
1047
|
type: "array",
|
|
1048
1048
|
uniqueItems: !0,
|
|
1049
1049
|
items: q(t.valueType._def, {
|
|
@@ -1051,20 +1051,20 @@ function ca(t, e) {
|
|
|
1051
1051
|
currentPath: [...e.currentPath, "items"]
|
|
1052
1052
|
})
|
|
1053
1053
|
};
|
|
1054
|
-
return t.minSize && (
|
|
1054
|
+
return t.minSize && (n.minItems = t.minSize.value), t.maxSize && (n.maxItems = t.maxSize.value), n;
|
|
1055
1055
|
}
|
|
1056
1056
|
function ua(t, e) {
|
|
1057
1057
|
return t.rest ? {
|
|
1058
1058
|
type: "array",
|
|
1059
1059
|
minItems: t.items.length,
|
|
1060
|
-
items: t.items.map((
|
|
1060
|
+
items: t.items.map((n, r) => q(n._def, {
|
|
1061
1061
|
...e,
|
|
1062
1062
|
currentPath: [
|
|
1063
1063
|
...e.currentPath,
|
|
1064
1064
|
"items",
|
|
1065
|
-
`${
|
|
1065
|
+
`${r}`
|
|
1066
1066
|
]
|
|
1067
|
-
})).reduce((
|
|
1067
|
+
})).reduce((n, r) => r === void 0 ? n : [...n, r], []),
|
|
1068
1068
|
additionalItems: q(t.rest._def, {
|
|
1069
1069
|
...e,
|
|
1070
1070
|
currentPath: [...e.currentPath, "additionalItems"]
|
|
@@ -1073,14 +1073,14 @@ function ua(t, e) {
|
|
|
1073
1073
|
type: "array",
|
|
1074
1074
|
minItems: t.items.length,
|
|
1075
1075
|
maxItems: t.items.length,
|
|
1076
|
-
items: t.items.map((
|
|
1076
|
+
items: t.items.map((n, r) => q(n._def, {
|
|
1077
1077
|
...e,
|
|
1078
1078
|
currentPath: [
|
|
1079
1079
|
...e.currentPath,
|
|
1080
1080
|
"items",
|
|
1081
|
-
`${
|
|
1081
|
+
`${r}`
|
|
1082
1082
|
]
|
|
1083
|
-
})).reduce((
|
|
1083
|
+
})).reduce((n, r) => r === void 0 ? n : [...n, r], [])
|
|
1084
1084
|
};
|
|
1085
1085
|
}
|
|
1086
1086
|
function da() {
|
|
@@ -1089,35 +1089,35 @@ function da() {
|
|
|
1089
1089
|
function pa() {
|
|
1090
1090
|
return ue();
|
|
1091
1091
|
}
|
|
1092
|
-
const fa = (t, e) => q(t.innerType._def, e), ma = (t, e,
|
|
1092
|
+
const fa = (t, e) => q(t.innerType._def, e), ma = (t, e, n) => {
|
|
1093
1093
|
switch (e) {
|
|
1094
1094
|
case "ZodString":
|
|
1095
|
-
return
|
|
1095
|
+
return Kn(t, n);
|
|
1096
1096
|
case "ZodNumber":
|
|
1097
|
-
return
|
|
1097
|
+
return na(t);
|
|
1098
1098
|
case "ZodObject":
|
|
1099
|
-
return
|
|
1099
|
+
return ra(t, n);
|
|
1100
1100
|
case "ZodBigInt":
|
|
1101
|
-
return
|
|
1101
|
+
return js(t);
|
|
1102
1102
|
case "ZodBoolean":
|
|
1103
1103
|
return $s();
|
|
1104
1104
|
case "ZodDate":
|
|
1105
|
-
return
|
|
1105
|
+
return Yn(t, n);
|
|
1106
1106
|
case "ZodUndefined":
|
|
1107
1107
|
return da();
|
|
1108
1108
|
case "ZodNull":
|
|
1109
1109
|
return Qs();
|
|
1110
1110
|
case "ZodArray":
|
|
1111
|
-
return
|
|
1111
|
+
return ks(t, n);
|
|
1112
1112
|
case "ZodUnion":
|
|
1113
1113
|
case "ZodDiscriminatedUnion":
|
|
1114
|
-
return Xs(t,
|
|
1114
|
+
return Xs(t, n);
|
|
1115
1115
|
case "ZodIntersection":
|
|
1116
|
-
return Bs(t,
|
|
1116
|
+
return Bs(t, n);
|
|
1117
1117
|
case "ZodTuple":
|
|
1118
|
-
return ua(t,
|
|
1118
|
+
return ua(t, n);
|
|
1119
1119
|
case "ZodRecord":
|
|
1120
|
-
return
|
|
1120
|
+
return Gn(t, n);
|
|
1121
1121
|
case "ZodLiteral":
|
|
1122
1122
|
return Ws(t);
|
|
1123
1123
|
case "ZodEnum":
|
|
@@ -1125,58 +1125,58 @@ const fa = (t, e) => q(t.innerType._def, e), ma = (t, e, r) => {
|
|
|
1125
1125
|
case "ZodNativeEnum":
|
|
1126
1126
|
return Ks(t);
|
|
1127
1127
|
case "ZodNullable":
|
|
1128
|
-
return ta(t,
|
|
1128
|
+
return ta(t, n);
|
|
1129
1129
|
case "ZodOptional":
|
|
1130
|
-
return ia(t,
|
|
1130
|
+
return ia(t, n);
|
|
1131
1131
|
case "ZodMap":
|
|
1132
|
-
return Ys(t,
|
|
1132
|
+
return Ys(t, n);
|
|
1133
1133
|
case "ZodSet":
|
|
1134
|
-
return ca(t,
|
|
1134
|
+
return ca(t, n);
|
|
1135
1135
|
case "ZodLazy":
|
|
1136
1136
|
return () => t.getter()._def;
|
|
1137
1137
|
case "ZodPromise":
|
|
1138
|
-
return la(t,
|
|
1138
|
+
return la(t, n);
|
|
1139
1139
|
case "ZodNaN":
|
|
1140
1140
|
case "ZodNever":
|
|
1141
1141
|
return Gs();
|
|
1142
1142
|
case "ZodEffects":
|
|
1143
|
-
return zs(t,
|
|
1143
|
+
return zs(t, n);
|
|
1144
1144
|
case "ZodAny":
|
|
1145
1145
|
return ue();
|
|
1146
1146
|
case "ZodUnknown":
|
|
1147
1147
|
return pa();
|
|
1148
1148
|
case "ZodDefault":
|
|
1149
|
-
return qs(t,
|
|
1149
|
+
return qs(t, n);
|
|
1150
1150
|
case "ZodBranded":
|
|
1151
|
-
return
|
|
1151
|
+
return Hn(t, n);
|
|
1152
1152
|
case "ZodReadonly":
|
|
1153
|
-
return fa(t,
|
|
1153
|
+
return fa(t, n);
|
|
1154
1154
|
case "ZodCatch":
|
|
1155
|
-
return Fs(t,
|
|
1155
|
+
return Fs(t, n);
|
|
1156
1156
|
case "ZodPipeline":
|
|
1157
|
-
return oa(t,
|
|
1157
|
+
return oa(t, n);
|
|
1158
1158
|
case "ZodFunction":
|
|
1159
1159
|
case "ZodVoid":
|
|
1160
1160
|
case "ZodSymbol":
|
|
1161
1161
|
return;
|
|
1162
1162
|
default:
|
|
1163
|
-
return /* @__PURE__ */ ((
|
|
1163
|
+
return /* @__PURE__ */ ((r) => {
|
|
1164
1164
|
})();
|
|
1165
1165
|
}
|
|
1166
1166
|
}, ga = (t, e) => {
|
|
1167
|
-
let
|
|
1168
|
-
for (;
|
|
1169
|
-
return [(t.length -
|
|
1167
|
+
let n = 0;
|
|
1168
|
+
for (; n < t.length && n < e.length && t[n] === e[n]; n++) ;
|
|
1169
|
+
return [(t.length - n).toString(), ...e.slice(n)].join("/");
|
|
1170
1170
|
};
|
|
1171
|
-
function q(t, e,
|
|
1171
|
+
function q(t, e, n = !1) {
|
|
1172
1172
|
var u;
|
|
1173
|
-
const
|
|
1173
|
+
const r = e.seen.get(t);
|
|
1174
1174
|
if (e.override) {
|
|
1175
|
-
const y = (u = e.override) == null ? void 0 : u.call(e, t, e,
|
|
1175
|
+
const y = (u = e.override) == null ? void 0 : u.call(e, t, e, r, n);
|
|
1176
1176
|
if (y !== Ds) return y;
|
|
1177
1177
|
}
|
|
1178
|
-
if (
|
|
1179
|
-
const y = ha(
|
|
1178
|
+
if (r && !n) {
|
|
1179
|
+
const y = ha(r, e);
|
|
1180
1180
|
if (y !== void 0) return y;
|
|
1181
1181
|
}
|
|
1182
1182
|
const s = {
|
|
@@ -1200,61 +1200,61 @@ const ha = (t, e) => {
|
|
|
1200
1200
|
return { $ref: ga(e.currentPath, t.path) };
|
|
1201
1201
|
case "none":
|
|
1202
1202
|
case "seen":
|
|
1203
|
-
return t.path.length < e.currentPath.length && t.path.every((
|
|
1203
|
+
return t.path.length < e.currentPath.length && t.path.every((n, r) => e.currentPath[r] === n) ? (console.warn(`Recursive reference detected at ${e.currentPath.join("/")}! Defaulting to any`), ue()) : e.$refStrategy === "seen" ? ue() : void 0;
|
|
1204
1204
|
}
|
|
1205
|
-
}, ya = (t, e,
|
|
1206
|
-
const e = Ls(t),
|
|
1205
|
+
}, ya = (t, e, n) => (t.description && (n.description = t.description), n), va = (t) => {
|
|
1206
|
+
const e = Ls(t), n = e.name !== void 0 ? [
|
|
1207
1207
|
...e.basePath,
|
|
1208
1208
|
e.definitionPath,
|
|
1209
1209
|
e.name
|
|
1210
1210
|
] : e.basePath;
|
|
1211
1211
|
return {
|
|
1212
1212
|
...e,
|
|
1213
|
-
currentPath:
|
|
1213
|
+
currentPath: n,
|
|
1214
1214
|
propertyPath: void 0,
|
|
1215
|
-
seen: new Map(Object.entries(e.definitions).map(([
|
|
1215
|
+
seen: new Map(Object.entries(e.definitions).map(([r, s]) => [s._def, {
|
|
1216
1216
|
def: s._def,
|
|
1217
1217
|
path: [
|
|
1218
1218
|
...e.basePath,
|
|
1219
1219
|
e.definitionPath,
|
|
1220
|
-
|
|
1220
|
+
r
|
|
1221
1221
|
],
|
|
1222
1222
|
jsonSchema: void 0
|
|
1223
1223
|
}]))
|
|
1224
1224
|
};
|
|
1225
1225
|
}, ba = (t, e) => {
|
|
1226
|
-
const
|
|
1227
|
-
let
|
|
1226
|
+
const n = va(e);
|
|
1227
|
+
let r = typeof e == "object" && e.definitions ? Object.entries(e.definitions).reduce((y, [g, i]) => ({
|
|
1228
1228
|
...y,
|
|
1229
1229
|
[g]: q(i._def, {
|
|
1230
|
-
...
|
|
1230
|
+
...n,
|
|
1231
1231
|
currentPath: [
|
|
1232
|
-
...
|
|
1233
|
-
|
|
1232
|
+
...n.basePath,
|
|
1233
|
+
n.definitionPath,
|
|
1234
1234
|
g
|
|
1235
1235
|
]
|
|
1236
1236
|
}, !0) ?? ue()
|
|
1237
1237
|
}), {}) : void 0;
|
|
1238
|
-
const s = typeof e == "string" ? e : (e == null ? void 0 : e.nameStrategy) === "title" || e == null ? void 0 : e.name, o = q(t._def, s === void 0 ?
|
|
1239
|
-
...
|
|
1238
|
+
const s = typeof e == "string" ? e : (e == null ? void 0 : e.nameStrategy) === "title" || e == null ? void 0 : e.name, o = q(t._def, s === void 0 ? n : {
|
|
1239
|
+
...n,
|
|
1240
1240
|
currentPath: [
|
|
1241
|
-
...
|
|
1242
|
-
|
|
1241
|
+
...n.basePath,
|
|
1242
|
+
n.definitionPath,
|
|
1243
1243
|
s
|
|
1244
1244
|
]
|
|
1245
1245
|
}, !1) ?? ue(), l = typeof e == "object" && e.name !== void 0 && e.nameStrategy === "title" ? e.name : void 0;
|
|
1246
1246
|
l !== void 0 && (o.title = l);
|
|
1247
|
-
const u = s === void 0 ?
|
|
1247
|
+
const u = s === void 0 ? r ? {
|
|
1248
1248
|
...o,
|
|
1249
|
-
[
|
|
1249
|
+
[n.definitionPath]: r
|
|
1250
1250
|
} : o : {
|
|
1251
1251
|
$ref: [
|
|
1252
|
-
...
|
|
1253
|
-
|
|
1252
|
+
...n.$refStrategy === "relative" ? [] : n.basePath,
|
|
1253
|
+
n.definitionPath,
|
|
1254
1254
|
s
|
|
1255
1255
|
].join("/"),
|
|
1256
|
-
[
|
|
1257
|
-
...
|
|
1256
|
+
[n.definitionPath]: {
|
|
1257
|
+
...r,
|
|
1258
1258
|
[s]: o
|
|
1259
1259
|
}
|
|
1260
1260
|
};
|
|
@@ -1282,22 +1282,22 @@ function Ea(t) {
|
|
|
1282
1282
|
type: "object",
|
|
1283
1283
|
properties: {},
|
|
1284
1284
|
additionalProperties: !1
|
|
1285
|
-
}) : Ia(t) ? t : "~standard" in t ? t["~standard"].vendor === "zod" ?
|
|
1285
|
+
}) : Ia(t) ? t : "~standard" in t ? t["~standard"].vendor === "zod" ? Qn(t) : Ca(t) : t();
|
|
1286
1286
|
}
|
|
1287
1287
|
function Ca(t) {
|
|
1288
1288
|
return vt(() => {
|
|
1289
1289
|
if (!wa(t)) throw new Error(`Standard schema vendor '${t["~standard"].vendor}' does not support JSON Schema conversion.`);
|
|
1290
1290
|
return Zt(t["~standard"].jsonSchema.input({ target: "draft-07" }));
|
|
1291
1291
|
}, { validate: async (e) => {
|
|
1292
|
-
const
|
|
1293
|
-
return "value" in
|
|
1292
|
+
const n = await t["~standard"].validate(e);
|
|
1293
|
+
return "value" in n ? {
|
|
1294
1294
|
success: !0,
|
|
1295
|
-
value:
|
|
1295
|
+
value: n.value
|
|
1296
1296
|
} : {
|
|
1297
1297
|
success: !1,
|
|
1298
1298
|
error: new mt({
|
|
1299
1299
|
value: e,
|
|
1300
|
-
cause:
|
|
1300
|
+
cause: n.issues
|
|
1301
1301
|
})
|
|
1302
1302
|
};
|
|
1303
1303
|
} });
|
|
@@ -1306,14 +1306,14 @@ function wa(t) {
|
|
|
1306
1306
|
return t["~standard"].jsonSchema != null;
|
|
1307
1307
|
}
|
|
1308
1308
|
function Aa(t, e) {
|
|
1309
|
-
return vt(() => ba(t, { $refStrategy: "none" }), { validate: async (
|
|
1310
|
-
const
|
|
1311
|
-
return
|
|
1309
|
+
return vt(() => ba(t, { $refStrategy: "none" }), { validate: async (n) => {
|
|
1310
|
+
const r = await t.safeParseAsync(n);
|
|
1311
|
+
return r.success ? {
|
|
1312
1312
|
success: !0,
|
|
1313
|
-
value:
|
|
1313
|
+
value: r.data
|
|
1314
1314
|
} : {
|
|
1315
1315
|
success: !1,
|
|
1316
|
-
error:
|
|
1316
|
+
error: r.error
|
|
1317
1317
|
};
|
|
1318
1318
|
} });
|
|
1319
1319
|
}
|
|
@@ -1322,45 +1322,45 @@ function xa(t, e) {
|
|
|
1322
1322
|
target: "draft-7",
|
|
1323
1323
|
io: "input",
|
|
1324
1324
|
reused: "inline"
|
|
1325
|
-
})), { validate: async (
|
|
1326
|
-
const
|
|
1327
|
-
return
|
|
1325
|
+
})), { validate: async (n) => {
|
|
1326
|
+
const r = await Yr(t, n);
|
|
1327
|
+
return r.success ? {
|
|
1328
1328
|
success: !0,
|
|
1329
|
-
value:
|
|
1329
|
+
value: r.data
|
|
1330
1330
|
} : {
|
|
1331
1331
|
success: !1,
|
|
1332
|
-
error:
|
|
1332
|
+
error: r.error
|
|
1333
1333
|
};
|
|
1334
1334
|
} });
|
|
1335
1335
|
}
|
|
1336
1336
|
function Ta(t) {
|
|
1337
1337
|
return "_zod" in t;
|
|
1338
1338
|
}
|
|
1339
|
-
function
|
|
1339
|
+
function Qn(t, e) {
|
|
1340
1340
|
return Ta(t) ? xa(t) : Aa(t);
|
|
1341
1341
|
}
|
|
1342
|
-
async function
|
|
1343
|
-
const
|
|
1342
|
+
async function dn({ value: t, schema: e, context: n }) {
|
|
1343
|
+
const r = await Xn({
|
|
1344
1344
|
value: t,
|
|
1345
1345
|
schema: e,
|
|
1346
|
-
context:
|
|
1346
|
+
context: n
|
|
1347
1347
|
});
|
|
1348
|
-
if (!
|
|
1348
|
+
if (!r.success) throw mt.wrap({
|
|
1349
1349
|
value: t,
|
|
1350
|
-
cause:
|
|
1351
|
-
context:
|
|
1350
|
+
cause: r.error,
|
|
1351
|
+
context: n
|
|
1352
1352
|
});
|
|
1353
|
-
return
|
|
1353
|
+
return r.value;
|
|
1354
1354
|
}
|
|
1355
|
-
async function
|
|
1356
|
-
const
|
|
1355
|
+
async function Xn({ value: t, schema: e, context: n }) {
|
|
1356
|
+
const r = Ea(e);
|
|
1357
1357
|
try {
|
|
1358
|
-
if (
|
|
1358
|
+
if (r.validate == null) return {
|
|
1359
1359
|
success: !0,
|
|
1360
1360
|
value: t,
|
|
1361
1361
|
rawValue: t
|
|
1362
1362
|
};
|
|
1363
|
-
const s = await
|
|
1363
|
+
const s = await r.validate(t);
|
|
1364
1364
|
return s.success ? {
|
|
1365
1365
|
success: !0,
|
|
1366
1366
|
value: s.value,
|
|
@@ -1370,7 +1370,7 @@ async function Qr({ value: t, schema: e, context: r }) {
|
|
|
1370
1370
|
error: mt.wrap({
|
|
1371
1371
|
value: t,
|
|
1372
1372
|
cause: s.error,
|
|
1373
|
-
context:
|
|
1373
|
+
context: n
|
|
1374
1374
|
}),
|
|
1375
1375
|
rawValue: t
|
|
1376
1376
|
};
|
|
@@ -1380,7 +1380,7 @@ async function Qr({ value: t, schema: e, context: r }) {
|
|
|
1380
1380
|
error: mt.wrap({
|
|
1381
1381
|
value: t,
|
|
1382
1382
|
cause: s,
|
|
1383
|
-
context:
|
|
1383
|
+
context: n
|
|
1384
1384
|
}),
|
|
1385
1385
|
rawValue: t
|
|
1386
1386
|
};
|
|
@@ -1388,30 +1388,30 @@ async function Qr({ value: t, schema: e, context: r }) {
|
|
|
1388
1388
|
}
|
|
1389
1389
|
async function qt({ text: t, schema: e }) {
|
|
1390
1390
|
try {
|
|
1391
|
-
const
|
|
1391
|
+
const n = Ns(t);
|
|
1392
1392
|
return e == null ? {
|
|
1393
1393
|
success: !0,
|
|
1394
|
-
value:
|
|
1395
|
-
rawValue:
|
|
1396
|
-
} : await
|
|
1397
|
-
value:
|
|
1394
|
+
value: n,
|
|
1395
|
+
rawValue: n
|
|
1396
|
+
} : await Xn({
|
|
1397
|
+
value: n,
|
|
1398
1398
|
schema: e
|
|
1399
1399
|
});
|
|
1400
|
-
} catch (
|
|
1400
|
+
} catch (n) {
|
|
1401
1401
|
return {
|
|
1402
1402
|
success: !1,
|
|
1403
|
-
error:
|
|
1403
|
+
error: rn.isInstance(n) ? n : new rn({
|
|
1404
1404
|
text: t,
|
|
1405
|
-
cause:
|
|
1405
|
+
cause: n
|
|
1406
1406
|
}),
|
|
1407
1407
|
rawValue: void 0
|
|
1408
1408
|
};
|
|
1409
1409
|
}
|
|
1410
1410
|
}
|
|
1411
1411
|
function Ma({ stream: t, schema: e }) {
|
|
1412
|
-
return t.pipeThrough(new TextDecoderStream()).pipeThrough(new Ts()).pipeThrough(new TransformStream({ async transform({ data:
|
|
1413
|
-
|
|
1414
|
-
text:
|
|
1412
|
+
return t.pipeThrough(new TextDecoderStream()).pipeThrough(new Ts()).pipeThrough(new TransformStream({ async transform({ data: n }, r) {
|
|
1413
|
+
n !== "[DONE]" && r.enqueue(await qt({
|
|
1414
|
+
text: n,
|
|
1415
1415
|
schema: e
|
|
1416
1416
|
}));
|
|
1417
1417
|
} }));
|
|
@@ -1423,43 +1423,43 @@ new TextDecoder();
|
|
|
1423
1423
|
function _a(t) {
|
|
1424
1424
|
return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
|
|
1425
1425
|
}
|
|
1426
|
-
const
|
|
1426
|
+
const er = "AI_InvalidArgumentError", tr = `vercel.ai.error.${er}`, Ra = Symbol.for(tr);
|
|
1427
1427
|
var ut = class extends ee {
|
|
1428
|
-
constructor({ parameter: t, value: e, message:
|
|
1428
|
+
constructor({ parameter: t, value: e, message: n }) {
|
|
1429
1429
|
super({
|
|
1430
|
-
name:
|
|
1431
|
-
message: `Invalid argument for parameter ${t}: ${
|
|
1430
|
+
name: er,
|
|
1431
|
+
message: `Invalid argument for parameter ${t}: ${n}`
|
|
1432
1432
|
}), this[Ra] = !0, this.parameter = t, this.value = e;
|
|
1433
1433
|
}
|
|
1434
1434
|
static isInstance(t) {
|
|
1435
|
-
return ee.hasMarker(t,
|
|
1435
|
+
return ee.hasMarker(t, tr);
|
|
1436
1436
|
}
|
|
1437
1437
|
};
|
|
1438
|
-
const
|
|
1438
|
+
const nr = "AI_UIMessageStreamError", rr = `vercel.ai.error.${nr}`, Pa = Symbol.for(rr);
|
|
1439
1439
|
var Ne = class extends ee {
|
|
1440
|
-
constructor({ chunkType: t, chunkId: e, message:
|
|
1440
|
+
constructor({ chunkType: t, chunkId: e, message: n }) {
|
|
1441
1441
|
super({
|
|
1442
|
-
name:
|
|
1443
|
-
message:
|
|
1442
|
+
name: nr,
|
|
1443
|
+
message: n
|
|
1444
1444
|
}), this[Pa] = !0, this.chunkType = t, this.chunkId = e;
|
|
1445
1445
|
}
|
|
1446
1446
|
static isInstance(t) {
|
|
1447
|
-
return ee.hasMarker(t,
|
|
1447
|
+
return ee.hasMarker(t, rr);
|
|
1448
1448
|
}
|
|
1449
1449
|
};
|
|
1450
|
-
function
|
|
1450
|
+
function sr(t, e) {
|
|
1451
1451
|
if (t === void 0 && e === void 0) return;
|
|
1452
1452
|
if (t === void 0) return e;
|
|
1453
1453
|
if (e === void 0) return t;
|
|
1454
|
-
const
|
|
1455
|
-
for (const
|
|
1456
|
-
if (!(
|
|
1457
|
-
const s = e[
|
|
1454
|
+
const n = { ...t };
|
|
1455
|
+
for (const r in e)
|
|
1456
|
+
if (!(r === "__proto__" || r === "constructor" || r === "prototype") && Object.prototype.hasOwnProperty.call(e, r)) {
|
|
1457
|
+
const s = e[r];
|
|
1458
1458
|
if (s === void 0) continue;
|
|
1459
|
-
const o =
|
|
1460
|
-
l && u ? r
|
|
1459
|
+
const o = r in t ? t[r] : void 0, l = s !== null && typeof s == "object" && !Array.isArray(s) && !(s instanceof Date) && !(s instanceof RegExp), u = o != null && typeof o == "object" && !Array.isArray(o) && !(o instanceof Date) && !(o instanceof RegExp);
|
|
1460
|
+
l && u ? n[r] = sr(o, s) : n[r] = s;
|
|
1461
1461
|
}
|
|
1462
|
-
return
|
|
1462
|
+
return n;
|
|
1463
1463
|
}
|
|
1464
1464
|
const a = {
|
|
1465
1465
|
array: ps,
|
|
@@ -1468,17 +1468,17 @@ const a = {
|
|
|
1468
1468
|
discriminatedUnion: cs,
|
|
1469
1469
|
enum: ls,
|
|
1470
1470
|
instanceof: os,
|
|
1471
|
-
lazy:
|
|
1471
|
+
lazy: Kr,
|
|
1472
1472
|
literal: is,
|
|
1473
1473
|
looseObject: as,
|
|
1474
1474
|
never: ss,
|
|
1475
|
-
null:
|
|
1476
|
-
number:
|
|
1475
|
+
null: rs,
|
|
1476
|
+
number: ns,
|
|
1477
1477
|
object: ts,
|
|
1478
1478
|
record: es,
|
|
1479
|
-
string:
|
|
1480
|
-
union:
|
|
1481
|
-
unknown:
|
|
1479
|
+
string: Xr,
|
|
1480
|
+
union: Qr,
|
|
1481
|
+
unknown: Gr
|
|
1482
1482
|
}, $e = a.lazy(() => a.union([
|
|
1483
1483
|
a.null(),
|
|
1484
1484
|
a.string(),
|
|
@@ -1491,7 +1491,7 @@ const a = {
|
|
|
1491
1491
|
a.instanceof(Uint8Array),
|
|
1492
1492
|
a.instanceof(ArrayBuffer),
|
|
1493
1493
|
a.custom(_s, { message: "Must be a Buffer" })
|
|
1494
|
-
]), Vt = a.record(a.string(), a.string()),
|
|
1494
|
+
]), Vt = a.record(a.string(), a.string()), ar = a.object({
|
|
1495
1495
|
type: a.literal("text"),
|
|
1496
1496
|
text: a.string(),
|
|
1497
1497
|
providerOptions: _.optional()
|
|
@@ -1504,7 +1504,7 @@ const a = {
|
|
|
1504
1504
|
]),
|
|
1505
1505
|
mediaType: a.string().optional(),
|
|
1506
1506
|
providerOptions: _.optional()
|
|
1507
|
-
}),
|
|
1507
|
+
}), ir = a.discriminatedUnion("type", [
|
|
1508
1508
|
a.object({
|
|
1509
1509
|
type: a.literal("data"),
|
|
1510
1510
|
data: et
|
|
@@ -1527,10 +1527,10 @@ const a = {
|
|
|
1527
1527
|
}), a.object({
|
|
1528
1528
|
type: a.literal("url"),
|
|
1529
1529
|
url: a.instanceof(URL)
|
|
1530
|
-
})]),
|
|
1530
|
+
})]), or = a.object({
|
|
1531
1531
|
type: a.literal("file"),
|
|
1532
1532
|
data: a.union([
|
|
1533
|
-
|
|
1533
|
+
ir,
|
|
1534
1534
|
et,
|
|
1535
1535
|
a.instanceof(URL),
|
|
1536
1536
|
Vt
|
|
@@ -1546,7 +1546,7 @@ const a = {
|
|
|
1546
1546
|
type: a.literal("custom"),
|
|
1547
1547
|
kind: a.string().transform((t) => t),
|
|
1548
1548
|
providerOptions: _.optional()
|
|
1549
|
-
}),
|
|
1549
|
+
}), ka = a.object({
|
|
1550
1550
|
type: a.literal("reasoning-file"),
|
|
1551
1551
|
data: a.union([
|
|
1552
1552
|
Na,
|
|
@@ -1555,7 +1555,7 @@ const a = {
|
|
|
1555
1555
|
]),
|
|
1556
1556
|
mediaType: a.string(),
|
|
1557
1557
|
providerOptions: _.optional()
|
|
1558
|
-
}),
|
|
1558
|
+
}), ja = a.object({
|
|
1559
1559
|
type: a.literal("tool-call"),
|
|
1560
1560
|
toolCallId: a.string(),
|
|
1561
1561
|
toolName: a.string(),
|
|
@@ -1598,7 +1598,7 @@ const a = {
|
|
|
1598
1598
|
}),
|
|
1599
1599
|
a.object({
|
|
1600
1600
|
type: a.literal("file"),
|
|
1601
|
-
data:
|
|
1601
|
+
data: ir,
|
|
1602
1602
|
mediaType: a.string(),
|
|
1603
1603
|
filename: a.string().optional(),
|
|
1604
1604
|
providerOptions: _.optional()
|
|
@@ -1653,7 +1653,7 @@ const a = {
|
|
|
1653
1653
|
})
|
|
1654
1654
|
]))
|
|
1655
1655
|
})
|
|
1656
|
-
]),
|
|
1656
|
+
]), lr = a.object({
|
|
1657
1657
|
type: a.literal("tool-result"),
|
|
1658
1658
|
toolCallId: a.string(),
|
|
1659
1659
|
toolName: a.string(),
|
|
@@ -1679,27 +1679,27 @@ const a = {
|
|
|
1679
1679
|
}), za = a.object({
|
|
1680
1680
|
role: a.literal("user"),
|
|
1681
1681
|
content: a.union([a.string(), a.array(a.union([
|
|
1682
|
-
|
|
1682
|
+
ar,
|
|
1683
1683
|
Oa,
|
|
1684
|
-
|
|
1684
|
+
or
|
|
1685
1685
|
]))]),
|
|
1686
1686
|
providerOptions: _.optional()
|
|
1687
1687
|
}), Za = a.object({
|
|
1688
1688
|
role: a.literal("assistant"),
|
|
1689
1689
|
content: a.union([a.string(), a.array(a.union([
|
|
1690
|
-
|
|
1690
|
+
ar,
|
|
1691
1691
|
La,
|
|
1692
|
-
|
|
1692
|
+
or,
|
|
1693
1693
|
Da,
|
|
1694
|
-
ja,
|
|
1695
1694
|
ka,
|
|
1696
|
-
|
|
1695
|
+
ja,
|
|
1696
|
+
lr,
|
|
1697
1697
|
Fa
|
|
1698
1698
|
]))]),
|
|
1699
1699
|
providerOptions: _.optional()
|
|
1700
1700
|
}), Va = a.object({
|
|
1701
1701
|
role: a.literal("tool"),
|
|
1702
|
-
content: a.array(a.union([
|
|
1702
|
+
content: a.array(a.union([lr, Ua])),
|
|
1703
1703
|
providerOptions: _.optional()
|
|
1704
1704
|
});
|
|
1705
1705
|
a.union([
|
|
@@ -1710,19 +1710,19 @@ a.union([
|
|
|
1710
1710
|
]);
|
|
1711
1711
|
function Ba(t) {
|
|
1712
1712
|
const e = ["ROOT"];
|
|
1713
|
-
let
|
|
1713
|
+
let n = -1, r = null, s = 0;
|
|
1714
1714
|
function o(i) {
|
|
1715
1715
|
return i >= "0" && i <= "9" || i >= "A" && i <= "F" || i >= "a" && i <= "f";
|
|
1716
1716
|
}
|
|
1717
1717
|
function l(i, d, p) {
|
|
1718
1718
|
switch (i) {
|
|
1719
1719
|
case '"':
|
|
1720
|
-
|
|
1720
|
+
n = d, e.pop(), e.push(p), e.push("INSIDE_STRING");
|
|
1721
1721
|
break;
|
|
1722
1722
|
case "f":
|
|
1723
1723
|
case "t":
|
|
1724
1724
|
case "n":
|
|
1725
|
-
|
|
1725
|
+
n = d, r = d, e.pop(), e.push(p), e.push("INSIDE_LITERAL");
|
|
1726
1726
|
break;
|
|
1727
1727
|
case "-":
|
|
1728
1728
|
e.pop(), e.push(p), e.push("INSIDE_NUMBER");
|
|
@@ -1737,13 +1737,13 @@ function Ba(t) {
|
|
|
1737
1737
|
case "7":
|
|
1738
1738
|
case "8":
|
|
1739
1739
|
case "9":
|
|
1740
|
-
|
|
1740
|
+
n = d, e.pop(), e.push(p), e.push("INSIDE_NUMBER");
|
|
1741
1741
|
break;
|
|
1742
1742
|
case "{":
|
|
1743
|
-
|
|
1743
|
+
n = d, e.pop(), e.push(p), e.push("INSIDE_OBJECT_START");
|
|
1744
1744
|
break;
|
|
1745
1745
|
case "[":
|
|
1746
|
-
|
|
1746
|
+
n = d, e.pop(), e.push(p), e.push("INSIDE_ARRAY_START");
|
|
1747
1747
|
}
|
|
1748
1748
|
}
|
|
1749
1749
|
function u(i, d) {
|
|
@@ -1752,7 +1752,7 @@ function Ba(t) {
|
|
|
1752
1752
|
e.pop(), e.push("INSIDE_OBJECT_AFTER_COMMA");
|
|
1753
1753
|
break;
|
|
1754
1754
|
case "}":
|
|
1755
|
-
|
|
1755
|
+
n = d, e.pop();
|
|
1756
1756
|
}
|
|
1757
1757
|
}
|
|
1758
1758
|
function y(i, d) {
|
|
@@ -1761,7 +1761,7 @@ function Ba(t) {
|
|
|
1761
1761
|
e.pop(), e.push("INSIDE_ARRAY_AFTER_COMMA");
|
|
1762
1762
|
break;
|
|
1763
1763
|
case "]":
|
|
1764
|
-
|
|
1764
|
+
n = d, e.pop();
|
|
1765
1765
|
}
|
|
1766
1766
|
}
|
|
1767
1767
|
for (let i = 0; i < t.length; i++) {
|
|
@@ -1776,7 +1776,7 @@ function Ba(t) {
|
|
|
1776
1776
|
e.pop(), e.push("INSIDE_OBJECT_KEY");
|
|
1777
1777
|
break;
|
|
1778
1778
|
case "}":
|
|
1779
|
-
|
|
1779
|
+
n = i, e.pop();
|
|
1780
1780
|
}
|
|
1781
1781
|
break;
|
|
1782
1782
|
case "INSIDE_OBJECT_AFTER_COMMA":
|
|
@@ -1806,22 +1806,22 @@ function Ba(t) {
|
|
|
1806
1806
|
case "INSIDE_STRING":
|
|
1807
1807
|
switch (d) {
|
|
1808
1808
|
case '"':
|
|
1809
|
-
e.pop(),
|
|
1809
|
+
e.pop(), n = i;
|
|
1810
1810
|
break;
|
|
1811
1811
|
case "\\":
|
|
1812
1812
|
e.push("INSIDE_STRING_ESCAPE");
|
|
1813
1813
|
break;
|
|
1814
1814
|
default:
|
|
1815
|
-
|
|
1815
|
+
n = i;
|
|
1816
1816
|
}
|
|
1817
1817
|
break;
|
|
1818
1818
|
case "INSIDE_ARRAY_START":
|
|
1819
1819
|
switch (d) {
|
|
1820
1820
|
case "]":
|
|
1821
|
-
|
|
1821
|
+
n = i, e.pop();
|
|
1822
1822
|
break;
|
|
1823
1823
|
default:
|
|
1824
|
-
|
|
1824
|
+
n = i, l(d, i, "INSIDE_ARRAY_AFTER_VALUE");
|
|
1825
1825
|
}
|
|
1826
1826
|
break;
|
|
1827
1827
|
case "INSIDE_ARRAY_AFTER_VALUE":
|
|
@@ -1830,20 +1830,20 @@ function Ba(t) {
|
|
|
1830
1830
|
e.pop(), e.push("INSIDE_ARRAY_AFTER_COMMA");
|
|
1831
1831
|
break;
|
|
1832
1832
|
case "]":
|
|
1833
|
-
|
|
1833
|
+
n = i, e.pop();
|
|
1834
1834
|
break;
|
|
1835
1835
|
default:
|
|
1836
|
-
|
|
1836
|
+
n = i;
|
|
1837
1837
|
}
|
|
1838
1838
|
break;
|
|
1839
1839
|
case "INSIDE_ARRAY_AFTER_COMMA":
|
|
1840
1840
|
l(d, i, "INSIDE_ARRAY_AFTER_VALUE");
|
|
1841
1841
|
break;
|
|
1842
1842
|
case "INSIDE_STRING_ESCAPE":
|
|
1843
|
-
e.pop(), d === "u" ? (s = 0, e.push("INSIDE_STRING_UNICODE_ESCAPE")) :
|
|
1843
|
+
e.pop(), d === "u" ? (s = 0, e.push("INSIDE_STRING_UNICODE_ESCAPE")) : n = i;
|
|
1844
1844
|
break;
|
|
1845
1845
|
case "INSIDE_STRING_UNICODE_ESCAPE":
|
|
1846
|
-
o(d) && (s++, s === 4 && (e.pop(),
|
|
1846
|
+
o(d) && (s++, s === 4 && (e.pop(), n = i));
|
|
1847
1847
|
break;
|
|
1848
1848
|
case "INSIDE_NUMBER":
|
|
1849
1849
|
switch (d) {
|
|
@@ -1857,7 +1857,7 @@ function Ba(t) {
|
|
|
1857
1857
|
case "7":
|
|
1858
1858
|
case "8":
|
|
1859
1859
|
case "9":
|
|
1860
|
-
|
|
1860
|
+
n = i;
|
|
1861
1861
|
break;
|
|
1862
1862
|
case "e":
|
|
1863
1863
|
case "E":
|
|
@@ -1878,13 +1878,13 @@ function Ba(t) {
|
|
|
1878
1878
|
}
|
|
1879
1879
|
break;
|
|
1880
1880
|
case "INSIDE_LITERAL": {
|
|
1881
|
-
const p = t.substring(
|
|
1882
|
-
!"false".startsWith(p) && !"true".startsWith(p) && !"null".startsWith(p) ? (e.pop(), e[e.length - 1] === "INSIDE_OBJECT_AFTER_VALUE" ? u(d, i) : e[e.length - 1] === "INSIDE_ARRAY_AFTER_VALUE" && y(d, i)) :
|
|
1881
|
+
const p = t.substring(r, i + 1);
|
|
1882
|
+
!"false".startsWith(p) && !"true".startsWith(p) && !"null".startsWith(p) ? (e.pop(), e[e.length - 1] === "INSIDE_OBJECT_AFTER_VALUE" ? u(d, i) : e[e.length - 1] === "INSIDE_ARRAY_AFTER_VALUE" && y(d, i)) : n = i;
|
|
1883
1883
|
break;
|
|
1884
1884
|
}
|
|
1885
1885
|
}
|
|
1886
1886
|
}
|
|
1887
|
-
let g = t.slice(0,
|
|
1887
|
+
let g = t.slice(0, n + 1);
|
|
1888
1888
|
for (let i = e.length - 1; i >= 0; i--) switch (e[i]) {
|
|
1889
1889
|
case "INSIDE_STRING":
|
|
1890
1890
|
g += '"';
|
|
@@ -1903,7 +1903,7 @@ function Ba(t) {
|
|
|
1903
1903
|
g += "]";
|
|
1904
1904
|
break;
|
|
1905
1905
|
case "INSIDE_LITERAL": {
|
|
1906
|
-
const d = t.substring(
|
|
1906
|
+
const d = t.substring(r, t.length);
|
|
1907
1907
|
"true".startsWith(d) ? g += "true".slice(d.length) : "false".startsWith(d) ? g += "false".slice(d.length) : "null".startsWith(d) && (g += "null".slice(d.length));
|
|
1908
1908
|
}
|
|
1909
1909
|
}
|
|
@@ -1972,7 +1972,7 @@ const Ja = a.object({
|
|
|
1972
1972
|
startIndex: a.number().int().nonnegative().optional(),
|
|
1973
1973
|
endIndex: a.number().int().nonnegative().optional(),
|
|
1974
1974
|
citedText: a.string().optional()
|
|
1975
|
-
}), Ge = a.record(a.string(), $e.optional()), Ha = Sa(() =>
|
|
1975
|
+
}), Ge = a.record(a.string(), $e.optional()), Ha = Sa(() => Qn(a.union([
|
|
1976
1976
|
a.looseObject({
|
|
1977
1977
|
type: a.literal("text-start"),
|
|
1978
1978
|
id: a.string(),
|
|
@@ -2167,30 +2167,30 @@ function Be() {
|
|
|
2167
2167
|
function gt(t) {
|
|
2168
2168
|
return t.type.startsWith("tool-");
|
|
2169
2169
|
}
|
|
2170
|
-
function
|
|
2170
|
+
function cr(t) {
|
|
2171
2171
|
return t.type === "dynamic-tool";
|
|
2172
2172
|
}
|
|
2173
2173
|
function pe(t) {
|
|
2174
|
-
return gt(t) ||
|
|
2174
|
+
return gt(t) || cr(t);
|
|
2175
2175
|
}
|
|
2176
2176
|
function ht(t) {
|
|
2177
2177
|
return t.type.split("-").slice(1).join("-");
|
|
2178
2178
|
}
|
|
2179
2179
|
function Ka(t) {
|
|
2180
|
-
return
|
|
2180
|
+
return cr(t) ? t.toolName : ht(t);
|
|
2181
2181
|
}
|
|
2182
|
-
function
|
|
2183
|
-
const
|
|
2182
|
+
function ur({ lastMessage: t, messageId: e }) {
|
|
2183
|
+
const n = (t == null ? void 0 : t.role) === "assistant" ? t : {
|
|
2184
2184
|
id: e,
|
|
2185
2185
|
metadata: void 0,
|
|
2186
2186
|
role: "assistant",
|
|
2187
2187
|
parts: []
|
|
2188
|
-
},
|
|
2188
|
+
}, r = Be(), s = n.parts.findLastIndex((l) => l.type === "step-start");
|
|
2189
2189
|
let o = 0;
|
|
2190
|
-
for (const l of
|
|
2190
|
+
for (const l of n.parts.slice(s + 1)) {
|
|
2191
2191
|
if (!pe(l)) continue;
|
|
2192
2192
|
const u = o;
|
|
2193
|
-
gt(l) && o++, l.state === "input-streaming" && (
|
|
2193
|
+
gt(l) && o++, l.state === "input-streaming" && (r[l.toolCallId] = {
|
|
2194
2194
|
text: l.rawInput ?? "",
|
|
2195
2195
|
inputEncoding: l.inputEncoding,
|
|
2196
2196
|
index: u,
|
|
@@ -2201,16 +2201,16 @@ function un({ lastMessage: t, messageId: e }) {
|
|
|
2201
2201
|
});
|
|
2202
2202
|
}
|
|
2203
2203
|
return {
|
|
2204
|
-
message:
|
|
2204
|
+
message: n,
|
|
2205
2205
|
activeTextParts: Be(),
|
|
2206
2206
|
activeReasoningParts: Be(),
|
|
2207
|
-
partialToolCalls:
|
|
2207
|
+
partialToolCalls: r
|
|
2208
2208
|
};
|
|
2209
2209
|
}
|
|
2210
|
-
function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas:
|
|
2210
|
+
function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdateMessageJob: r, onError: s, onToolCall: o, onData: l, resetStateOnMessageIdChange: u = !1, resetStateOnFirstMessageStart: y = !1 }) {
|
|
2211
2211
|
let g = !0;
|
|
2212
2212
|
return t.pipeThrough(new TransformStream({ async transform(i, d) {
|
|
2213
|
-
await
|
|
2213
|
+
await r(async ({ state: p, write: b }) => {
|
|
2214
2214
|
function P() {
|
|
2215
2215
|
const c = p.message.parts;
|
|
2216
2216
|
let m = c.length - 1;
|
|
@@ -2251,7 +2251,7 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: r, runUpdate
|
|
|
2251
2251
|
});
|
|
2252
2252
|
return m;
|
|
2253
2253
|
}
|
|
2254
|
-
function
|
|
2254
|
+
function C(c, m) {
|
|
2255
2255
|
const f = m ?? P().find((N) => gt(N) && N.toolCallId === c.toolCallId), h = c, S = f;
|
|
2256
2256
|
if (f != null) {
|
|
2257
2257
|
f.state = c.state, S.type = `tool-${c.toolName}`, S.input = h.input, S.output = h.output, S.errorText = h.errorText, S.rawInput = h.rawInput, h.inputEncoding != null ? S.inputEncoding = h.inputEncoding : delete S.inputEncoding, S.preliminary = h.preliminary, c.title !== void 0 && (S.title = c.title), c.toolMetadata !== void 0 && (S.toolMetadata = c.toolMetadata), S.providerExecuted = h.providerExecuted ?? f.providerExecuted;
|
|
@@ -2305,10 +2305,10 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: r, runUpdate
|
|
|
2305
2305
|
...h.providerMetadata != null && !(c.state === "output-available" || c.state === "output-error") ? { callProviderMetadata: h.providerMetadata } : {}
|
|
2306
2306
|
});
|
|
2307
2307
|
}
|
|
2308
|
-
async function
|
|
2308
|
+
async function w(c) {
|
|
2309
2309
|
if (c != null) {
|
|
2310
|
-
const m = p.message.metadata != null ?
|
|
2311
|
-
e != null && await
|
|
2310
|
+
const m = p.message.metadata != null ? sr(p.message.metadata, c) : c;
|
|
2311
|
+
e != null && await dn({
|
|
2312
2312
|
value: m,
|
|
2313
2313
|
schema: e,
|
|
2314
2314
|
context: {
|
|
@@ -2437,7 +2437,7 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: r, runUpdate
|
|
|
2437
2437
|
title: i.title,
|
|
2438
2438
|
toolMetadata: i.toolMetadata,
|
|
2439
2439
|
providerMetadata: i.providerMetadata
|
|
2440
|
-
}) :
|
|
2440
|
+
}) : C({
|
|
2441
2441
|
toolCallId: i.toolCallId,
|
|
2442
2442
|
toolName: i.toolName,
|
|
2443
2443
|
state: "input-streaming",
|
|
@@ -2468,7 +2468,7 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: r, runUpdate
|
|
|
2468
2468
|
rawInput: c.text,
|
|
2469
2469
|
title: c.title,
|
|
2470
2470
|
toolMetadata: c.toolMetadata
|
|
2471
|
-
}) :
|
|
2471
|
+
}) : C({
|
|
2472
2472
|
toolCallId: i.toolCallId,
|
|
2473
2473
|
toolName: c.toolName,
|
|
2474
2474
|
state: "input-streaming",
|
|
@@ -2490,7 +2490,7 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: r, runUpdate
|
|
|
2490
2490
|
providerMetadata: i.providerMetadata,
|
|
2491
2491
|
title: i.title,
|
|
2492
2492
|
toolMetadata: i.toolMetadata
|
|
2493
|
-
}) :
|
|
2493
|
+
}) : C({
|
|
2494
2494
|
toolCallId: i.toolCallId,
|
|
2495
2495
|
toolName: i.toolName,
|
|
2496
2496
|
state: "input-available",
|
|
@@ -2512,7 +2512,7 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: r, runUpdate
|
|
|
2512
2512
|
providerExecuted: i.providerExecuted,
|
|
2513
2513
|
providerMetadata: i.providerMetadata,
|
|
2514
2514
|
toolMetadata: i.toolMetadata
|
|
2515
|
-
}) :
|
|
2515
|
+
}) : C({
|
|
2516
2516
|
toolCallId: i.toolCallId,
|
|
2517
2517
|
toolName: i.toolName,
|
|
2518
2518
|
state: "output-error",
|
|
@@ -2564,7 +2564,7 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: r, runUpdate
|
|
|
2564
2564
|
providerMetadata: i.providerMetadata,
|
|
2565
2565
|
title: c.title,
|
|
2566
2566
|
toolMetadata: i.toolMetadata ?? c.toolMetadata
|
|
2567
|
-
}, c) :
|
|
2567
|
+
}, c) : C({
|
|
2568
2568
|
toolCallId: i.toolCallId,
|
|
2569
2569
|
toolName: ht(c),
|
|
2570
2570
|
state: "output-available",
|
|
@@ -2590,7 +2590,7 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: r, runUpdate
|
|
|
2590
2590
|
providerMetadata: i.providerMetadata,
|
|
2591
2591
|
title: c.title,
|
|
2592
2592
|
toolMetadata: i.toolMetadata ?? c.toolMetadata
|
|
2593
|
-
}, c) :
|
|
2593
|
+
}, c) : C({
|
|
2594
2594
|
toolCallId: i.toolCallId,
|
|
2595
2595
|
toolName: ht(c),
|
|
2596
2596
|
state: "output-error",
|
|
@@ -2616,28 +2616,28 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: r, runUpdate
|
|
|
2616
2616
|
}
|
|
2617
2617
|
case "start": {
|
|
2618
2618
|
const c = y && g || u && i.messageId != null && i.messageId !== p.message.id;
|
|
2619
|
-
g = !1, c && Object.assign(p,
|
|
2619
|
+
g = !1, c && Object.assign(p, ur({
|
|
2620
2620
|
lastMessage: void 0,
|
|
2621
2621
|
messageId: i.messageId ?? p.message.id
|
|
2622
|
-
}), { finishReason: void 0 }), i.messageId != null && (p.message.id = i.messageId), await
|
|
2622
|
+
}), { finishReason: void 0 }), i.messageId != null && (p.message.id = i.messageId), await w(i.messageMetadata), (c || i.messageId != null || i.messageMetadata != null) && b({ updateStatus: !1 });
|
|
2623
2623
|
break;
|
|
2624
2624
|
}
|
|
2625
2625
|
case "finish":
|
|
2626
|
-
i.finishReason != null && (p.finishReason = i.finishReason), await
|
|
2626
|
+
i.finishReason != null && (p.finishReason = i.finishReason), await w(i.messageMetadata), i.messageMetadata != null && b();
|
|
2627
2627
|
break;
|
|
2628
2628
|
case "message-metadata":
|
|
2629
|
-
await
|
|
2629
|
+
await w(i.messageMetadata), i.messageMetadata != null && b();
|
|
2630
2630
|
break;
|
|
2631
2631
|
case "error":
|
|
2632
2632
|
s == null || s(new Error(i.errorText));
|
|
2633
2633
|
break;
|
|
2634
2634
|
default:
|
|
2635
2635
|
if (Ya(i)) {
|
|
2636
|
-
if ((
|
|
2636
|
+
if ((n == null ? void 0 : n[i.type]) != null) {
|
|
2637
2637
|
const f = p.message.parts.findIndex((S) => "id" in S && "data" in S && S.id === i.id && S.type === i.type), h = f >= 0 ? f : p.message.parts.length;
|
|
2638
|
-
await
|
|
2638
|
+
await dn({
|
|
2639
2639
|
value: i.data,
|
|
2640
|
-
schema:
|
|
2640
|
+
schema: n[i.type],
|
|
2641
2641
|
context: {
|
|
2642
2642
|
field: `message.parts[${h}].data`,
|
|
2643
2643
|
entityName: i.type,
|
|
@@ -2658,28 +2658,28 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: r, runUpdate
|
|
|
2658
2658
|
});
|
|
2659
2659
|
} }));
|
|
2660
2660
|
}
|
|
2661
|
-
async function Qa({ stream: t, onError: e, abortSignal:
|
|
2662
|
-
const
|
|
2663
|
-
|
|
2661
|
+
async function Qa({ stream: t, onError: e, abortSignal: n }) {
|
|
2662
|
+
const r = t.getReader(), s = () => {
|
|
2663
|
+
r.cancel().catch(() => {
|
|
2664
2664
|
});
|
|
2665
2665
|
};
|
|
2666
|
-
|
|
2666
|
+
n != null && n.aborted ? s() : n == null || n.addEventListener("abort", s, { once: !0 });
|
|
2667
2667
|
try {
|
|
2668
2668
|
for (; ; ) {
|
|
2669
|
-
const { done: o } = await
|
|
2669
|
+
const { done: o } = await r.read();
|
|
2670
2670
|
if (o) break;
|
|
2671
2671
|
}
|
|
2672
2672
|
} catch (o) {
|
|
2673
2673
|
e == null || e(o);
|
|
2674
2674
|
} finally {
|
|
2675
|
-
|
|
2675
|
+
n == null || n.removeEventListener("abort", s), r.releaseLock();
|
|
2676
2676
|
}
|
|
2677
2677
|
}
|
|
2678
2678
|
function Xa() {
|
|
2679
2679
|
let t, e;
|
|
2680
2680
|
return {
|
|
2681
|
-
promise: new Promise((
|
|
2682
|
-
t =
|
|
2681
|
+
promise: new Promise((n, r) => {
|
|
2682
|
+
t = n, e = r;
|
|
2683
2683
|
}),
|
|
2684
2684
|
resolve: t,
|
|
2685
2685
|
reject: e
|
|
@@ -2737,12 +2737,12 @@ var ei = class {
|
|
|
2737
2737
|
}
|
|
2738
2738
|
}
|
|
2739
2739
|
async run(t) {
|
|
2740
|
-
return new Promise((e,
|
|
2740
|
+
return new Promise((e, n) => {
|
|
2741
2741
|
this.queue.push(async () => {
|
|
2742
2742
|
try {
|
|
2743
2743
|
await t(), e();
|
|
2744
|
-
} catch (
|
|
2745
|
-
r
|
|
2744
|
+
} catch (r) {
|
|
2745
|
+
n(r);
|
|
2746
2746
|
}
|
|
2747
2747
|
}), this.processQueue();
|
|
2748
2748
|
});
|
|
@@ -2791,14 +2791,14 @@ te({
|
|
|
2791
2791
|
prefix: "call",
|
|
2792
2792
|
size: 24
|
|
2793
2793
|
});
|
|
2794
|
-
async function
|
|
2795
|
-
const
|
|
2796
|
-
return new
|
|
2797
|
-
message:
|
|
2794
|
+
async function pn({ response: t, url: e, fallbackMessage: n }) {
|
|
2795
|
+
const r = await t.text();
|
|
2796
|
+
return new kn({
|
|
2797
|
+
message: r || n,
|
|
2798
2798
|
url: e,
|
|
2799
2799
|
requestBodyValues: void 0,
|
|
2800
2800
|
statusCode: t.status,
|
|
2801
|
-
responseBody:
|
|
2801
|
+
responseBody: r
|
|
2802
2802
|
});
|
|
2803
2803
|
}
|
|
2804
2804
|
async function ti(t) {
|
|
@@ -2808,11 +2808,11 @@ async function ti(t) {
|
|
|
2808
2808
|
message: "FileList is not supported in the current environment"
|
|
2809
2809
|
});
|
|
2810
2810
|
return Promise.all(Array.from(t).map(async (e) => {
|
|
2811
|
-
const { name:
|
|
2811
|
+
const { name: n, type: r } = e;
|
|
2812
2812
|
return {
|
|
2813
2813
|
type: "file",
|
|
2814
|
-
mediaType:
|
|
2815
|
-
filename:
|
|
2814
|
+
mediaType: r,
|
|
2815
|
+
filename: n,
|
|
2816
2816
|
url: await new Promise((s, o) => {
|
|
2817
2817
|
const l = new FileReader();
|
|
2818
2818
|
l.onload = (u) => {
|
|
@@ -2823,25 +2823,25 @@ async function ti(t) {
|
|
|
2823
2823
|
};
|
|
2824
2824
|
}));
|
|
2825
2825
|
}
|
|
2826
|
-
function
|
|
2827
|
-
const
|
|
2828
|
-
return `${
|
|
2826
|
+
function ni(t, e) {
|
|
2827
|
+
const n = t.search(/[?#]/), r = n === -1 ? t : t.slice(0, n), s = n === -1 ? "" : t.slice(n);
|
|
2828
|
+
return `${r.endsWith("/") && e.startsWith("/") ? r.slice(0, -1) : r}${e}${s}`;
|
|
2829
2829
|
}
|
|
2830
|
-
var
|
|
2831
|
-
constructor({ api: t = "/api/chat", credentials: e, headers:
|
|
2832
|
-
this.api = t, this.credentials = e, this.headers =
|
|
2830
|
+
var ri = class {
|
|
2831
|
+
constructor({ api: t = "/api/chat", credentials: e, headers: n, body: r, fetch: s, prepareSendMessagesRequest: o, prepareReconnectToStreamRequest: l }) {
|
|
2832
|
+
this.api = t, this.credentials = e, this.headers = n, this.body = r, this.fetch = s, this.prepareSendMessagesRequest = o, this.prepareReconnectToStreamRequest = l;
|
|
2833
2833
|
}
|
|
2834
2834
|
async sendMessages({ abortSignal: t, ...e }) {
|
|
2835
2835
|
var p;
|
|
2836
|
-
const
|
|
2837
|
-
...Ze(
|
|
2836
|
+
const n = await Ve(this.body), r = await Ve(this.headers), s = await Ve(this.credentials), o = {
|
|
2837
|
+
...Ze(r),
|
|
2838
2838
|
...Ze(e.headers)
|
|
2839
2839
|
}, l = await ((p = this.prepareSendMessagesRequest) == null ? void 0 : p.call(this, {
|
|
2840
2840
|
api: this.api,
|
|
2841
2841
|
id: e.chatId,
|
|
2842
2842
|
messages: e.messages,
|
|
2843
2843
|
body: {
|
|
2844
|
-
...
|
|
2844
|
+
...n,
|
|
2845
2845
|
...e.body
|
|
2846
2846
|
},
|
|
2847
2847
|
headers: o,
|
|
@@ -2850,7 +2850,7 @@ var ni = class {
|
|
|
2850
2850
|
trigger: e.trigger,
|
|
2851
2851
|
messageId: e.messageId
|
|
2852
2852
|
})), u = (l == null ? void 0 : l.api) ?? this.api, y = (l == null ? void 0 : l.headers) !== void 0 ? Ze(l.headers) : o, g = (l == null ? void 0 : l.body) !== void 0 ? l.body : {
|
|
2853
|
-
...
|
|
2853
|
+
...n,
|
|
2854
2854
|
...e.body,
|
|
2855
2855
|
id: e.chatId,
|
|
2856
2856
|
messages: e.messages,
|
|
@@ -2866,7 +2866,7 @@ var ni = class {
|
|
|
2866
2866
|
credentials: i,
|
|
2867
2867
|
signal: t
|
|
2868
2868
|
});
|
|
2869
|
-
if (!d.ok) throw await
|
|
2869
|
+
if (!d.ok) throw await pn({
|
|
2870
2870
|
response: d,
|
|
2871
2871
|
url: u,
|
|
2872
2872
|
fallbackMessage: "Failed to fetch the chat response."
|
|
@@ -2876,8 +2876,8 @@ var ni = class {
|
|
|
2876
2876
|
}
|
|
2877
2877
|
async reconnectToStream(t) {
|
|
2878
2878
|
var i;
|
|
2879
|
-
const e = await Ve(this.body),
|
|
2880
|
-
...Ze(
|
|
2879
|
+
const e = await Ve(this.body), n = await Ve(this.headers), r = await Ve(this.credentials), s = {
|
|
2880
|
+
...Ze(n),
|
|
2881
2881
|
...Ze(t.headers)
|
|
2882
2882
|
}, o = await ((i = this.prepareReconnectToStreamRequest) == null ? void 0 : i.call(this, {
|
|
2883
2883
|
api: this.api,
|
|
@@ -2887,7 +2887,7 @@ var ni = class {
|
|
|
2887
2887
|
...t.body
|
|
2888
2888
|
},
|
|
2889
2889
|
headers: s,
|
|
2890
|
-
credentials:
|
|
2890
|
+
credentials: r,
|
|
2891
2891
|
requestMetadata: t.metadata
|
|
2892
2892
|
}));
|
|
2893
2893
|
let l = o == null ? void 0 : o.api;
|
|
@@ -2897,16 +2897,16 @@ var ni = class {
|
|
|
2897
2897
|
value: t.chatId,
|
|
2898
2898
|
message: 'Chat IDs must not be "." or ".." when using the default reconnect URL.'
|
|
2899
2899
|
});
|
|
2900
|
-
l =
|
|
2900
|
+
l = ni(this.api, `/${encodeURIComponent(t.chatId)}/stream`);
|
|
2901
2901
|
}
|
|
2902
|
-
const u = (o == null ? void 0 : o.headers) !== void 0 ? Ze(o.headers) : s, y = (o == null ? void 0 : o.credentials) ??
|
|
2902
|
+
const u = (o == null ? void 0 : o.headers) !== void 0 ? Ze(o.headers) : s, y = (o == null ? void 0 : o.credentials) ?? r, g = await (this.fetch ?? globalThis.fetch)(l, {
|
|
2903
2903
|
method: "GET",
|
|
2904
2904
|
headers: u,
|
|
2905
2905
|
credentials: y,
|
|
2906
2906
|
signal: t.abortSignal
|
|
2907
2907
|
});
|
|
2908
2908
|
if (g.status === 204) return null;
|
|
2909
|
-
if (!g.ok) throw await
|
|
2909
|
+
if (!g.ok) throw await pn({
|
|
2910
2910
|
response: g,
|
|
2911
2911
|
url: l,
|
|
2912
2912
|
fallbackMessage: "Failed to fetch the chat response."
|
|
@@ -2914,7 +2914,7 @@ var ni = class {
|
|
|
2914
2914
|
if (!g.body) throw new ft({ message: "The response body is empty." });
|
|
2915
2915
|
return this.processResponseStream(g.body);
|
|
2916
2916
|
}
|
|
2917
|
-
}, yt = class extends
|
|
2917
|
+
}, yt = class extends ri {
|
|
2918
2918
|
constructor({ resumeStreamIsReplay: t = !0, ...e } = {}) {
|
|
2919
2919
|
super(e), this.resumeStreamIsReplay = t;
|
|
2920
2920
|
}
|
|
@@ -2922,16 +2922,16 @@ var ni = class {
|
|
|
2922
2922
|
return Ma({
|
|
2923
2923
|
stream: t,
|
|
2924
2924
|
schema: Ha
|
|
2925
|
-
}).pipeThrough(new TransformStream({ async transform(e,
|
|
2925
|
+
}).pipeThrough(new TransformStream({ async transform(e, n) {
|
|
2926
2926
|
if (!e.success) throw e.error;
|
|
2927
|
-
|
|
2927
|
+
n.enqueue(e.value);
|
|
2928
2928
|
} }));
|
|
2929
2929
|
}
|
|
2930
2930
|
}, si = class {
|
|
2931
2931
|
get id() {
|
|
2932
2932
|
return this._id ?? (this._id = this.generateId());
|
|
2933
2933
|
}
|
|
2934
|
-
constructor({ generateId: t = Ms, id: e, transport:
|
|
2934
|
+
constructor({ generateId: t = Ms, id: e, transport: n = new yt(), messageMetadataSchema: r, dataPartSchemas: s, state: o, onError: l, onToolCall: u, onFinish: y, onData: g, sendAutomaticallyWhen: i }) {
|
|
2935
2935
|
this.pendingMessagePreparations = /* @__PURE__ */ new Set(), this.interruptedMessageIds = /* @__PURE__ */ new Set(), this.activeResponse = void 0, this.activeResumeRequest = void 0, this.resumableStreamState = void 0, this.jobExecutor = new ei(), this.activeStopCount = 0, this.stopGeneration = 0, this.sendMessage = async (d, p) => {
|
|
2936
2936
|
var P;
|
|
2937
2937
|
if (d == null) {
|
|
@@ -2939,9 +2939,9 @@ var ni = class {
|
|
|
2939
2939
|
if (M == null) {
|
|
2940
2940
|
M = (P = this.lastMessage) == null ? void 0 : P.id;
|
|
2941
2941
|
for (let x = this.state.messages.length - 1; x >= 0; x--) {
|
|
2942
|
-
const
|
|
2943
|
-
if (
|
|
2944
|
-
M =
|
|
2942
|
+
const C = this.state.messages[x];
|
|
2943
|
+
if (C.role === "assistant" && C.parts.some((I) => pe(I) && I.state === "approval-responded")) {
|
|
2944
|
+
M = C.id;
|
|
2945
2945
|
break;
|
|
2946
2946
|
}
|
|
2947
2947
|
}
|
|
@@ -3022,41 +3022,41 @@ var ni = class {
|
|
|
3022
3022
|
}, this.clearError = () => {
|
|
3023
3023
|
this.status === "error" && (this.state.error = void 0, this.setStatus({ status: "ready" }));
|
|
3024
3024
|
}, this.addToolApprovalResponse = async ({ id: d, approved: p, reason: b, options: P }) => this.jobExecutor.run(async () => {
|
|
3025
|
-
const M = this.state.messages, O = (
|
|
3026
|
-
...
|
|
3025
|
+
const M = this.state.messages, O = (C) => pe(C) && C.state === "approval-requested" && C.approval.id === d ? {
|
|
3026
|
+
...C,
|
|
3027
3027
|
state: "approval-responded",
|
|
3028
3028
|
approval: {
|
|
3029
|
-
...
|
|
3029
|
+
...C.approval,
|
|
3030
3030
|
id: d,
|
|
3031
3031
|
approved: p,
|
|
3032
3032
|
reason: b
|
|
3033
3033
|
}
|
|
3034
|
-
} :
|
|
3034
|
+
} : C, x = M.findIndex((C) => C.parts.some((I) => pe(I) && I.state === "approval-requested" && I.approval.id === d));
|
|
3035
3035
|
if (x !== -1) {
|
|
3036
|
-
const
|
|
3036
|
+
const C = M[x];
|
|
3037
3037
|
this.state.replaceMessage(x, {
|
|
3038
|
-
...
|
|
3039
|
-
parts:
|
|
3040
|
-
}), this.pendingApprovalMessageId =
|
|
3038
|
+
...C,
|
|
3039
|
+
parts: C.parts.map(O)
|
|
3040
|
+
}), this.pendingApprovalMessageId = C.id;
|
|
3041
3041
|
}
|
|
3042
3042
|
if (this.activeResponse && (this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(O)), x !== -1 && this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) {
|
|
3043
|
-
const
|
|
3044
|
-
|
|
3045
|
-
var
|
|
3046
|
-
const I = x === -1 ? (
|
|
3043
|
+
const C = await this.shouldSendAutomatically(M[x].id);
|
|
3044
|
+
C && this.runAutomaticRequest(() => {
|
|
3045
|
+
var w;
|
|
3046
|
+
const I = x === -1 ? (w = this.lastMessage) == null ? void 0 : w.id : M[x].id;
|
|
3047
3047
|
return this.makeRequestForToolApproval({
|
|
3048
3048
|
messageId: I,
|
|
3049
3049
|
messageIndex: x,
|
|
3050
3050
|
...P
|
|
3051
3051
|
});
|
|
3052
|
-
},
|
|
3052
|
+
}, C);
|
|
3053
3053
|
}
|
|
3054
3054
|
}), this.addToolOutput = async ({ state: d, toolCallId: p, output: b, errorText: P, options: M }) => this.jobExecutor.run(async () => {
|
|
3055
3055
|
const O = this.state.messages, x = (I) => {
|
|
3056
3056
|
if (!pe(I) || I.toolCallId !== p) return I;
|
|
3057
|
-
const { approval:
|
|
3058
|
-
...
|
|
3059
|
-
approved:
|
|
3057
|
+
const { approval: w, ...c } = I, m = (w == null ? void 0 : w.approved) === !0 ? { approval: {
|
|
3058
|
+
...w,
|
|
3059
|
+
approved: w.approved
|
|
3060
3060
|
} } : {};
|
|
3061
3061
|
return d === "output-error" ? {
|
|
3062
3062
|
...c,
|
|
@@ -3073,19 +3073,19 @@ var ni = class {
|
|
|
3073
3073
|
output: b,
|
|
3074
3074
|
errorText: void 0
|
|
3075
3075
|
};
|
|
3076
|
-
},
|
|
3077
|
-
if (
|
|
3078
|
-
const I = O[
|
|
3079
|
-
this.state.replaceMessage(
|
|
3076
|
+
}, C = O.findIndex((I) => I.parts.some((w) => pe(w) && w.toolCallId === p));
|
|
3077
|
+
if (C !== -1) {
|
|
3078
|
+
const I = O[C];
|
|
3079
|
+
this.state.replaceMessage(C, {
|
|
3080
3080
|
...I,
|
|
3081
3081
|
parts: I.parts.map(x)
|
|
3082
3082
|
});
|
|
3083
3083
|
}
|
|
3084
|
-
if (this.activeResponse && (this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(x)),
|
|
3085
|
-
const I = await this.shouldSendAutomatically(O[
|
|
3084
|
+
if (this.activeResponse && (this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(x)), C !== -1 && this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) {
|
|
3085
|
+
const I = await this.shouldSendAutomatically(O[C].id);
|
|
3086
3086
|
I && this.runAutomaticRequest(() => this.makeRequest({
|
|
3087
3087
|
trigger: "submit-message",
|
|
3088
|
-
messageId: O[
|
|
3088
|
+
messageId: O[C].id,
|
|
3089
3089
|
...M
|
|
3090
3090
|
}), I);
|
|
3091
3091
|
}
|
|
@@ -3101,7 +3101,7 @@ var ni = class {
|
|
|
3101
3101
|
}, this.dispose = async () => {
|
|
3102
3102
|
var d, p;
|
|
3103
3103
|
await this.stop(), (p = (d = this.transport).close) == null || p.call(d);
|
|
3104
|
-
}, this._id = e, this.transport =
|
|
3104
|
+
}, this._id = e, this.transport = n, this.generateId = t, this.messageMetadataSchema = r, this.dataPartSchemas = s, this.state = o, this.onError = l, this.onToolCall = u, this.onFinish = y, this.onData = g, this.sendAutomaticallyWhen = i;
|
|
3105
3105
|
}
|
|
3106
3106
|
/**
|
|
3107
3107
|
* Hook status:
|
|
@@ -3134,22 +3134,22 @@ var ni = class {
|
|
|
3134
3134
|
this.state.messages = t;
|
|
3135
3135
|
}
|
|
3136
3136
|
async shouldSendAutomatically(t = ((e) => (e = this.lastMessage) == null ? void 0 : e.id)()) {
|
|
3137
|
-
var
|
|
3138
|
-
const
|
|
3139
|
-
return !this.sendAutomaticallyWhen ||
|
|
3137
|
+
var r, s;
|
|
3138
|
+
const n = (o) => o != null && this.interruptedMessageIds.has(o);
|
|
3139
|
+
return !this.sendAutomaticallyWhen || n(t) || n((r = this.lastMessage) == null ? void 0 : r.id) ? !1 : await this.sendAutomaticallyWhen({ messages: this.state.messages }) && !n(t) && !n((s = this.lastMessage) == null ? void 0 : s.id);
|
|
3140
3140
|
}
|
|
3141
3141
|
async runAutomaticRequest(t, e) {
|
|
3142
|
-
const
|
|
3143
|
-
(e ?? await this.shouldSendAutomatically()) && (
|
|
3142
|
+
const n = this.stopGeneration, r = this.activeStopCount > 0;
|
|
3143
|
+
(e ?? await this.shouldSendAutomatically()) && (r || n !== this.stopGeneration || this.activeStopCount > 0 || await t());
|
|
3144
3144
|
}
|
|
3145
|
-
async makeRequestForToolApproval({ messageId: t, messageIndex: e, ...
|
|
3145
|
+
async makeRequestForToolApproval({ messageId: t, messageIndex: e, ...n }) {
|
|
3146
3146
|
var s;
|
|
3147
|
-
const
|
|
3148
|
-
|
|
3147
|
+
const r = t != null && t === this.pendingApprovalMessageId;
|
|
3148
|
+
r && (this.pendingApprovalMessageId = void 0), await this.makeRequest({
|
|
3149
3149
|
trigger: "submit-message",
|
|
3150
3150
|
messageId: t,
|
|
3151
|
-
...
|
|
3152
|
-
}),
|
|
3151
|
+
...n
|
|
3152
|
+
}), r && this.status === "error" && this.pendingApprovalMessageId == null && (this.pendingApprovalMessageId = ((s = this.state.messages[e]) == null ? void 0 : s.id) ?? t);
|
|
3153
3153
|
}
|
|
3154
3154
|
async makeRequest(t) {
|
|
3155
3155
|
const e = Xa();
|
|
@@ -3162,7 +3162,7 @@ var ni = class {
|
|
|
3162
3162
|
e.resolve();
|
|
3163
3163
|
}
|
|
3164
3164
|
}
|
|
3165
|
-
async makeRequestImpl({ trigger: t, metadata: e, headers:
|
|
3165
|
+
async makeRequestImpl({ trigger: t, metadata: e, headers: n, body: r, messageId: s, completionPromise: o }) {
|
|
3166
3166
|
var c, m;
|
|
3167
3167
|
t !== "resume-stream" && (this.resumableStreamState = void 0);
|
|
3168
3168
|
const l = new AbortController(), u = t === "resume-stream" ? {
|
|
@@ -3179,8 +3179,8 @@ var ni = class {
|
|
|
3179
3179
|
chatId: this.id,
|
|
3180
3180
|
abortSignal: l.signal,
|
|
3181
3181
|
metadata: e,
|
|
3182
|
-
headers:
|
|
3183
|
-
body:
|
|
3182
|
+
headers: n,
|
|
3183
|
+
body: r
|
|
3184
3184
|
});
|
|
3185
3185
|
if (l.signal.aborted || !y()) {
|
|
3186
3186
|
await (f == null ? void 0 : f.cancel().catch(() => {
|
|
@@ -3209,17 +3209,17 @@ var ni = class {
|
|
|
3209
3209
|
error: void 0
|
|
3210
3210
|
});
|
|
3211
3211
|
const d = this.lastMessage, p = t === "submit-message" && s != null ? this.state.messages.findIndex((f) => f.id === s) : this.state.messages.length - 1, b = p === -1 ? d : this.state.messages[p], P = b == null ? void 0 : b.id, M = t === "resume-stream" && (b == null ? void 0 : b.role) === "assistant" && b.parts.some((f) => pe(f) && (f.state === "input-streaming" || f.state === "input-available" && f.providerExecuted || f.state === "approval-responded")) ? this.state.snapshot(b) : void 0, O = p !== -1 && p < this.state.messages.length - 1 && (b == null ? void 0 : b.role) === "assistant";
|
|
3212
|
-
let x = !1,
|
|
3212
|
+
let x = !1, C = !1, I = !1, w;
|
|
3213
3213
|
try {
|
|
3214
3214
|
const f = {
|
|
3215
|
-
state: t === "resume-stream" && this.resumableStreamState != null ? this.resumableStreamState :
|
|
3215
|
+
state: t === "resume-stream" && this.resumableStreamState != null ? this.resumableStreamState : ur({
|
|
3216
3216
|
lastMessage: t === "resume-stream" ? M : t === "regenerate-message" ? void 0 : this.state.snapshot(b),
|
|
3217
3217
|
messageId: this.generateId()
|
|
3218
3218
|
}),
|
|
3219
3219
|
abortController: l,
|
|
3220
3220
|
completionPromise: o
|
|
3221
3221
|
};
|
|
3222
|
-
|
|
3222
|
+
w = f, f.abortController.signal.addEventListener("abort", () => {
|
|
3223
3223
|
x = !0;
|
|
3224
3224
|
}), this.activeResponse = f;
|
|
3225
3225
|
let h;
|
|
@@ -3228,8 +3228,8 @@ var ni = class {
|
|
|
3228
3228
|
messages: this.state.messages,
|
|
3229
3229
|
abortSignal: f.abortController.signal,
|
|
3230
3230
|
metadata: e,
|
|
3231
|
-
headers:
|
|
3232
|
-
body:
|
|
3231
|
+
headers: n,
|
|
3232
|
+
body: r,
|
|
3233
3233
|
trigger: t,
|
|
3234
3234
|
messageId: s
|
|
3235
3235
|
});
|
|
@@ -3241,7 +3241,7 @@ var ni = class {
|
|
|
3241
3241
|
const B = this.state.messages.findLastIndex((W) => W.id === f.state.message.id);
|
|
3242
3242
|
if (B !== -1) this.state.replaceMessage(B, f.state.message);
|
|
3243
3243
|
else if (O) {
|
|
3244
|
-
const W = this.state.messages.findLastIndex((
|
|
3244
|
+
const W = this.state.messages.findLastIndex((k) => k.id === P);
|
|
3245
3245
|
W !== -1 ? this.state.replaceMessage(W, f.state.message) : this.state.pushMessage(f.state.message);
|
|
3246
3246
|
} else this.state.pushMessage(f.state.message);
|
|
3247
3247
|
}
|
|
@@ -3269,56 +3269,56 @@ var ni = class {
|
|
|
3269
3269
|
y() && (this.setStatus({ status: "ready" }), this.resumableStreamState === f.state && (this.resumableStreamState = void 0));
|
|
3270
3270
|
} catch (f) {
|
|
3271
3271
|
if (x || f.name === "AbortError")
|
|
3272
|
-
return x = !0, y() && (this.setStatus({ status: "ready" }), this.resumableStreamState === (
|
|
3272
|
+
return x = !0, y() && (this.setStatus({ status: "ready" }), this.resumableStreamState === (w == null ? void 0 : w.state) && (this.resumableStreamState = void 0)), null;
|
|
3273
3273
|
if (!y()) return null;
|
|
3274
3274
|
if (I = !0, f instanceof TypeError) {
|
|
3275
3275
|
const h = f.message.toLowerCase();
|
|
3276
|
-
|
|
3276
|
+
C = h.includes("fetch") || h.includes("network") || h === "load failed";
|
|
3277
3277
|
}
|
|
3278
|
-
|
|
3278
|
+
C ? this.resumableStreamState = w == null ? void 0 : w.state : this.resumableStreamState === (w == null ? void 0 : w.state) && (this.resumableStreamState = void 0), this.onError && f instanceof Error && this.onError(f), this.setStatus({
|
|
3279
3279
|
status: "error",
|
|
3280
3280
|
error: f
|
|
3281
3281
|
});
|
|
3282
3282
|
} finally {
|
|
3283
3283
|
try {
|
|
3284
|
-
if (
|
|
3285
|
-
const { message: f, finishReason: h } =
|
|
3284
|
+
if (w) {
|
|
3285
|
+
const { message: f, finishReason: h } = w.state;
|
|
3286
3286
|
h === "interrupted" ? this.interruptedMessageIds.add(f.id) : !x && !I && this.interruptedMessageIds.delete(f.id), (m = this.onFinish) == null || m.call(this, {
|
|
3287
|
-
message:
|
|
3287
|
+
message: w.state.message,
|
|
3288
3288
|
messages: this.state.messages,
|
|
3289
3289
|
isAbort: x,
|
|
3290
|
-
isDisconnect:
|
|
3290
|
+
isDisconnect: C,
|
|
3291
3291
|
isError: I,
|
|
3292
|
-
finishReason:
|
|
3292
|
+
finishReason: w.state.finishReason
|
|
3293
3293
|
});
|
|
3294
3294
|
}
|
|
3295
3295
|
} finally {
|
|
3296
|
-
this.activeResponse ===
|
|
3296
|
+
this.activeResponse === w && (this.activeResponse = void 0), g();
|
|
3297
3297
|
}
|
|
3298
3298
|
}
|
|
3299
|
-
!x && !I && (
|
|
3299
|
+
!x && !I && (w == null ? void 0 : w.state.finishReason) !== "interrupted" && await this.runAutomaticRequest(() => {
|
|
3300
3300
|
var f;
|
|
3301
3301
|
return this.makeRequest({
|
|
3302
3302
|
trigger: "submit-message",
|
|
3303
3303
|
messageId: (f = this.lastMessage) == null ? void 0 : f.id,
|
|
3304
3304
|
metadata: e,
|
|
3305
|
-
headers:
|
|
3306
|
-
body:
|
|
3305
|
+
headers: n,
|
|
3306
|
+
body: r
|
|
3307
3307
|
});
|
|
3308
3308
|
});
|
|
3309
3309
|
}
|
|
3310
|
-
}, Lt,
|
|
3310
|
+
}, Lt, fn;
|
|
3311
3311
|
function ai() {
|
|
3312
|
-
if (
|
|
3313
|
-
|
|
3314
|
-
function t(e,
|
|
3312
|
+
if (fn) return Lt;
|
|
3313
|
+
fn = 1;
|
|
3314
|
+
function t(e, n) {
|
|
3315
3315
|
if (typeof e != "function")
|
|
3316
3316
|
throw new TypeError(`Expected the first argument to be a \`function\`, got \`${typeof e}\`.`);
|
|
3317
|
-
let
|
|
3317
|
+
let r, s = 0;
|
|
3318
3318
|
return function(...l) {
|
|
3319
|
-
clearTimeout(
|
|
3320
|
-
const u = Date.now(), y = u - s, g =
|
|
3321
|
-
g <= 0 ? (s = u, e.apply(this, l)) :
|
|
3319
|
+
clearTimeout(r);
|
|
3320
|
+
const u = Date.now(), y = u - s, g = n - y;
|
|
3321
|
+
g <= 0 ? (s = u, e.apply(this, l)) : r = setTimeout(() => {
|
|
3322
3322
|
s = Date.now(), e.apply(this, l);
|
|
3323
3323
|
}, g);
|
|
3324
3324
|
};
|
|
@@ -3333,49 +3333,49 @@ function li(t, e) {
|
|
|
3333
3333
|
function ci(t) {
|
|
3334
3334
|
return Array.isArray(t) ? [...t] : t != null && typeof t == "object" && (Object.getPrototypeOf(t) === Object.prototype || Object.getPrototypeOf(t) === null) ? { ...t } : t;
|
|
3335
3335
|
}
|
|
3336
|
-
var ce, We, Je, De, Le,
|
|
3336
|
+
var ce, We, Je, De, Le, ke, _e, Qe, Xe, Tn, ui = (Tn = class {
|
|
3337
3337
|
constructor(t = []) {
|
|
3338
3338
|
ge(this, ce);
|
|
3339
3339
|
ge(this, We);
|
|
3340
3340
|
ge(this, Je);
|
|
3341
3341
|
ge(this, De);
|
|
3342
3342
|
ge(this, Le);
|
|
3343
|
-
ge(this,
|
|
3343
|
+
ge(this, ke);
|
|
3344
3344
|
ge(this, _e);
|
|
3345
3345
|
ge(this, Qe);
|
|
3346
3346
|
ge(this, Xe);
|
|
3347
|
-
Q(this, We, "ready"), Q(this, Je, void 0), Q(this, De, /* @__PURE__ */ new Set()), Q(this, Le, /* @__PURE__ */ new Set()), Q(this,
|
|
3347
|
+
Q(this, We, "ready"), Q(this, Je, void 0), Q(this, De, /* @__PURE__ */ new Set()), Q(this, Le, /* @__PURE__ */ new Set()), Q(this, ke, /* @__PURE__ */ new Set()), this.pushMessage = (e) => {
|
|
3348
3348
|
Q(this, ce, V(this, ce).concat(e)), V(this, _e).call(this);
|
|
3349
3349
|
}, this.popMessage = () => {
|
|
3350
3350
|
Q(this, ce, V(this, ce).slice(0, -1)), V(this, _e).call(this);
|
|
3351
|
-
}, this.replaceMessage = (e,
|
|
3351
|
+
}, this.replaceMessage = (e, n) => {
|
|
3352
3352
|
Q(this, ce, [
|
|
3353
3353
|
...V(this, ce).slice(0, e),
|
|
3354
|
-
this.snapshot(
|
|
3354
|
+
this.snapshot(n),
|
|
3355
3355
|
...V(this, ce).slice(e + 1)
|
|
3356
3356
|
]), V(this, _e).call(this);
|
|
3357
3357
|
}, this.snapshot = (e) => {
|
|
3358
3358
|
if (e == null || typeof e != "object" || !("parts" in e) || !Array.isArray(e.parts)) return e;
|
|
3359
|
-
const
|
|
3360
|
-
...
|
|
3361
|
-
parts:
|
|
3359
|
+
const n = e, r = {
|
|
3360
|
+
...n,
|
|
3361
|
+
parts: n.parts.map((s) => ({ ...s }))
|
|
3362
3362
|
};
|
|
3363
|
-
return "metadata" in
|
|
3364
|
-
}, this["~registerMessagesCallback"] = (e,
|
|
3365
|
-
const
|
|
3366
|
-
return V(this, De).add(
|
|
3367
|
-
V(this, De).delete(
|
|
3363
|
+
return "metadata" in n && (r.metadata = ci(n.metadata)), r;
|
|
3364
|
+
}, this["~registerMessagesCallback"] = (e, n) => {
|
|
3365
|
+
const r = n ? li(e, n) : e;
|
|
3366
|
+
return V(this, De).add(r), () => {
|
|
3367
|
+
V(this, De).delete(r);
|
|
3368
3368
|
};
|
|
3369
3369
|
}, this["~registerStatusCallback"] = (e) => (V(this, Le).add(e), () => {
|
|
3370
3370
|
V(this, Le).delete(e);
|
|
3371
|
-
}), this["~registerErrorCallback"] = (e) => (V(this,
|
|
3372
|
-
V(this,
|
|
3371
|
+
}), this["~registerErrorCallback"] = (e) => (V(this, ke).add(e), () => {
|
|
3372
|
+
V(this, ke).delete(e);
|
|
3373
3373
|
}), Q(this, _e, () => {
|
|
3374
3374
|
V(this, De).forEach((e) => e());
|
|
3375
3375
|
}), Q(this, Qe, () => {
|
|
3376
3376
|
V(this, Le).forEach((e) => e());
|
|
3377
3377
|
}), Q(this, Xe, () => {
|
|
3378
|
-
V(this,
|
|
3378
|
+
V(this, ke).forEach((e) => e());
|
|
3379
3379
|
}), Q(this, ce, t);
|
|
3380
3380
|
}
|
|
3381
3381
|
get status() {
|
|
@@ -3396,30 +3396,30 @@ var ce, We, Je, De, Le, je, _e, Qe, Xe, xr, ui = (xr = class {
|
|
|
3396
3396
|
set messages(t) {
|
|
3397
3397
|
Q(this, ce, [...t]), V(this, _e).call(this);
|
|
3398
3398
|
}
|
|
3399
|
-
}, ce = new WeakMap(), We = new WeakMap(), Je = new WeakMap(), De = new WeakMap(), Le = new WeakMap(),
|
|
3400
|
-
constructor({ messages: e, ...
|
|
3401
|
-
const
|
|
3399
|
+
}, ce = new WeakMap(), We = new WeakMap(), Je = new WeakMap(), De = new WeakMap(), Le = new WeakMap(), ke = new WeakMap(), _e = new WeakMap(), Qe = new WeakMap(), Xe = new WeakMap(), Tn), je, Mn, di = (Mn = class extends si {
|
|
3400
|
+
constructor({ messages: e, ...n }) {
|
|
3401
|
+
const r = new ui(e);
|
|
3402
3402
|
super({
|
|
3403
|
-
...
|
|
3404
|
-
state:
|
|
3403
|
+
...n,
|
|
3404
|
+
state: r
|
|
3405
3405
|
});
|
|
3406
|
-
ge(this,
|
|
3407
|
-
this["~registerMessagesCallback"] = (s, o) => V(this,
|
|
3406
|
+
ge(this, je);
|
|
3407
|
+
this["~registerMessagesCallback"] = (s, o) => V(this, je)["~registerMessagesCallback"](s, o), this["~registerStatusCallback"] = (s) => V(this, je)["~registerStatusCallback"](s), this["~registerErrorCallback"] = (s) => V(this, je)["~registerErrorCallback"](s), Q(this, je, r);
|
|
3408
3408
|
}
|
|
3409
|
-
},
|
|
3409
|
+
}, je = new WeakMap(), Mn);
|
|
3410
3410
|
const dt = /* @__PURE__ */ new WeakMap();
|
|
3411
3411
|
function pi({ chat: t, state: e }) {
|
|
3412
3412
|
if (document.visibilityState !== "visible" || e.pendingVisibilityResume != null) return;
|
|
3413
|
-
const
|
|
3413
|
+
const n = () => dt.get(t) === e && e.registrations.size > 0, r = () => {
|
|
3414
3414
|
e.pendingVisibilityResume = void 0;
|
|
3415
3415
|
};
|
|
3416
|
-
e.pendingVisibilityResume = t["~resumeStreamIfDisconnected"]({ shouldResume: () =>
|
|
3416
|
+
e.pendingVisibilityResume = t["~resumeStreamIfDisconnected"]({ shouldResume: () => n() && document.visibilityState === "visible" }).then(r, r);
|
|
3417
3417
|
}
|
|
3418
3418
|
function fi({ chat: t, registration: e }) {
|
|
3419
|
-
let
|
|
3420
|
-
if (
|
|
3419
|
+
let n = dt.get(t);
|
|
3420
|
+
if (n == null) {
|
|
3421
3421
|
const o = { registrations: /* @__PURE__ */ new Set() };
|
|
3422
|
-
if (dt.set(t, o),
|
|
3422
|
+
if (dt.set(t, o), n = o, typeof document < "u") {
|
|
3423
3423
|
const l = () => pi({
|
|
3424
3424
|
chat: t,
|
|
3425
3425
|
state: o
|
|
@@ -3429,10 +3429,10 @@ function fi({ chat: t, registration: e }) {
|
|
|
3429
3429
|
};
|
|
3430
3430
|
}
|
|
3431
3431
|
}
|
|
3432
|
-
const { registrations:
|
|
3433
|
-
return
|
|
3432
|
+
const { registrations: r } = n, s = r.size === 0;
|
|
3433
|
+
return r.add(e), s && t.status !== "submitted" && t.status !== "streaming" && t.resumeStream(), () => {
|
|
3434
3434
|
var o;
|
|
3435
|
-
|
|
3435
|
+
r.delete(e), r.size === 0 && ((o = n.cleanupVisibilityListener) == null || o.call(n), dt.delete(t));
|
|
3436
3436
|
};
|
|
3437
3437
|
}
|
|
3438
3438
|
function ct(t) {
|
|
@@ -3443,22 +3443,22 @@ function ct(t) {
|
|
|
3443
3443
|
error: t.error
|
|
3444
3444
|
};
|
|
3445
3445
|
}
|
|
3446
|
-
function
|
|
3446
|
+
function mn(t, e) {
|
|
3447
3447
|
return t.chat === e.chat && t.messages === e.messages && t.status === e.status && t.error === e.error;
|
|
3448
3448
|
}
|
|
3449
|
-
function mi({ throttle: t, experimental_throttle: e, resume:
|
|
3449
|
+
function mi({ throttle: t, experimental_throttle: e, resume: n = !1, ...r } = {}) {
|
|
3450
3450
|
const s = t ?? e, o = R({}), l = R({});
|
|
3451
|
-
"chat" in
|
|
3452
|
-
onToolCall:
|
|
3453
|
-
onData:
|
|
3454
|
-
onFinish:
|
|
3455
|
-
onError:
|
|
3456
|
-
sendAutomaticallyWhen:
|
|
3457
|
-
transport:
|
|
3451
|
+
"chat" in r || (l.current = {
|
|
3452
|
+
onToolCall: r.onToolCall,
|
|
3453
|
+
onData: r.onData,
|
|
3454
|
+
onFinish: r.onFinish,
|
|
3455
|
+
onError: r.onError,
|
|
3456
|
+
sendAutomaticallyWhen: r.sendAutomaticallyWhen,
|
|
3457
|
+
transport: r.transport
|
|
3458
3458
|
});
|
|
3459
3459
|
let u;
|
|
3460
3460
|
const y = () => l.current.transport ?? u ?? (u = new yt()), g = {
|
|
3461
|
-
...
|
|
3461
|
+
...r,
|
|
3462
3462
|
transport: {
|
|
3463
3463
|
get resumeStreamIsReplay() {
|
|
3464
3464
|
return y().resumeStreamIsReplay;
|
|
@@ -3467,28 +3467,28 @@ function mi({ throttle: t, experimental_throttle: e, resume: r = !1, ...n } = {}
|
|
|
3467
3467
|
reconnectToStream: (I) => y().reconnectToStream(I)
|
|
3468
3468
|
},
|
|
3469
3469
|
onToolCall: (I) => {
|
|
3470
|
-
var
|
|
3471
|
-
return (c = (
|
|
3470
|
+
var w, c;
|
|
3471
|
+
return (c = (w = l.current).onToolCall) == null ? void 0 : c.call(w, I);
|
|
3472
3472
|
},
|
|
3473
3473
|
onData: (I) => {
|
|
3474
|
-
var
|
|
3475
|
-
return (c = (
|
|
3474
|
+
var w, c;
|
|
3475
|
+
return (c = (w = l.current).onData) == null ? void 0 : c.call(w, I);
|
|
3476
3476
|
},
|
|
3477
3477
|
onFinish: (I) => {
|
|
3478
|
-
var
|
|
3479
|
-
return (c = (
|
|
3478
|
+
var w, c;
|
|
3479
|
+
return (c = (w = l.current).onFinish) == null ? void 0 : c.call(w, I);
|
|
3480
3480
|
},
|
|
3481
3481
|
onError: (I) => {
|
|
3482
|
-
var
|
|
3483
|
-
return (c = (
|
|
3482
|
+
var w, c;
|
|
3483
|
+
return (c = (w = l.current).onError) == null ? void 0 : c.call(w, I);
|
|
3484
3484
|
},
|
|
3485
3485
|
sendAutomaticallyWhen: (I) => {
|
|
3486
|
-
var
|
|
3487
|
-
return ((c = (
|
|
3486
|
+
var w, c;
|
|
3487
|
+
return ((c = (w = l.current).sendAutomaticallyWhen) == null ? void 0 : c.call(w, I)) ?? !1;
|
|
3488
3488
|
}
|
|
3489
|
-
}, i = "chat" in
|
|
3490
|
-
chat: "chat" in
|
|
3491
|
-
isExternallyManaged: "chat" in
|
|
3489
|
+
}, i = "chat" in r ? r.chat : r.id, { chat: d, isExternallyManaged: p } = X(() => ({
|
|
3490
|
+
chat: "chat" in r ? r.chat : new di(g),
|
|
3491
|
+
isExternallyManaged: "chat" in r
|
|
3492
3492
|
}), [i]);
|
|
3493
3493
|
F(() => {
|
|
3494
3494
|
if (!p)
|
|
@@ -3499,33 +3499,33 @@ function mi({ throttle: t, experimental_throttle: e, resume: r = !1, ...n } = {}
|
|
|
3499
3499
|
const [b, P] = J(() => ct(d));
|
|
3500
3500
|
b.chat !== d && P(ct(d)), F(() => {
|
|
3501
3501
|
let I = !0;
|
|
3502
|
-
const
|
|
3502
|
+
const w = () => {
|
|
3503
3503
|
if (!I) return;
|
|
3504
3504
|
const f = ct(d);
|
|
3505
|
-
P((h) => h.chat !== d ||
|
|
3505
|
+
P((h) => h.chat !== d || mn(h, f) ? h : f);
|
|
3506
3506
|
}, c = [
|
|
3507
|
-
d["~registerMessagesCallback"](
|
|
3508
|
-
d["~registerStatusCallback"](
|
|
3509
|
-
d["~registerErrorCallback"](
|
|
3507
|
+
d["~registerMessagesCallback"](w, s),
|
|
3508
|
+
d["~registerStatusCallback"](w),
|
|
3509
|
+
d["~registerErrorCallback"](w)
|
|
3510
3510
|
], m = ct(d);
|
|
3511
|
-
return P((f) =>
|
|
3511
|
+
return P((f) => mn(f, m) ? f : m), () => {
|
|
3512
3512
|
I = !1, c.forEach((f) => f());
|
|
3513
3513
|
};
|
|
3514
3514
|
}, [d, s]);
|
|
3515
|
-
const { messages: M, status: O, error: x } = b,
|
|
3515
|
+
const { messages: M, status: O, error: x } = b, C = z((I) => {
|
|
3516
3516
|
typeof I == "function" && (I = I(d.messages)), d.messages = I;
|
|
3517
3517
|
}, [d]);
|
|
3518
3518
|
return F(() => {
|
|
3519
|
-
if (
|
|
3519
|
+
if (n) return fi({
|
|
3520
3520
|
chat: d,
|
|
3521
3521
|
registration: o.current
|
|
3522
3522
|
});
|
|
3523
|
-
}, [
|
|
3523
|
+
}, [n, d]), {
|
|
3524
3524
|
get id() {
|
|
3525
3525
|
return d.id;
|
|
3526
3526
|
},
|
|
3527
3527
|
messages: M,
|
|
3528
|
-
setMessages:
|
|
3528
|
+
setMessages: C,
|
|
3529
3529
|
sendMessage: d.sendMessage,
|
|
3530
3530
|
regenerate: d.regenerate,
|
|
3531
3531
|
clearError: d.clearError,
|
|
@@ -3541,7 +3541,7 @@ function mi({ throttle: t, experimental_throttle: e, resume: r = !1, ...n } = {}
|
|
|
3541
3541
|
addToolApprovalResponse: d.addToolApprovalResponse
|
|
3542
3542
|
};
|
|
3543
3543
|
}
|
|
3544
|
-
class
|
|
3544
|
+
class gn {
|
|
3545
3545
|
constructor(e) {
|
|
3546
3546
|
this.buffer = [], this.cap = Math.max(1, Math.floor(e));
|
|
3547
3547
|
}
|
|
@@ -3568,23 +3568,23 @@ class mr {
|
|
|
3568
3568
|
* nothing matches. Used by the queue pill's per-message remove button.
|
|
3569
3569
|
*/
|
|
3570
3570
|
removeWhere(e) {
|
|
3571
|
-
const
|
|
3572
|
-
if (
|
|
3573
|
-
const [
|
|
3574
|
-
return
|
|
3571
|
+
const n = this.buffer.findIndex(e);
|
|
3572
|
+
if (n === -1) return null;
|
|
3573
|
+
const [r] = this.buffer.splice(n, 1);
|
|
3574
|
+
return r ?? null;
|
|
3575
3575
|
}
|
|
3576
3576
|
}
|
|
3577
|
-
function
|
|
3578
|
-
const
|
|
3579
|
-
if (
|
|
3577
|
+
function hn(t, e) {
|
|
3578
|
+
const n = t.flatMap((r) => {
|
|
3579
|
+
if (r.kind === "text" && r.streaming && (e == null ? void 0 : e.streaming) === !1)
|
|
3580
3580
|
return [];
|
|
3581
|
-
if (
|
|
3582
|
-
const s =
|
|
3581
|
+
if (r.kind !== "steps") return [r];
|
|
3582
|
+
const s = r.steps.flatMap((o) => o.kind === "reasoning" ? (e == null ? void 0 : e.reasoning) === !1 ? [] : [o] : (e == null ? void 0 : e.toolActivity) === "hidden" ? [] : (e == null ? void 0 : e.toolActivity) === "status" && ("input" in o || "output" in o) ? [{ kind: o.kind, label: o.label, done: o.done }] : [o]);
|
|
3583
3583
|
return s.length === 0 ? [] : [
|
|
3584
|
-
s.length ===
|
|
3584
|
+
s.length === r.steps.length && s.every((o, l) => o === r.steps[l]) ? r : { ...r, steps: s }
|
|
3585
3585
|
];
|
|
3586
3586
|
});
|
|
3587
|
-
return
|
|
3587
|
+
return n.length === t.length && n.every((r, s) => r === t[s]) ? t : n;
|
|
3588
3588
|
}
|
|
3589
3589
|
const gi = L.union([
|
|
3590
3590
|
L.string(),
|
|
@@ -3612,20 +3612,20 @@ function Si(t) {
|
|
|
3612
3612
|
function Ii(t, e) {
|
|
3613
3613
|
return {
|
|
3614
3614
|
request_id: t.request_id ?? e ?? "req-clarification",
|
|
3615
|
-
questions: t.questions.map((
|
|
3616
|
-
id:
|
|
3617
|
-
prompt:
|
|
3618
|
-
selection:
|
|
3619
|
-
options:
|
|
3620
|
-
(s, o) => typeof s == "string" ? { id: `q${
|
|
3621
|
-
id: s.id ?? `q${
|
|
3615
|
+
questions: t.questions.map((n, r) => ({
|
|
3616
|
+
id: n.id ?? `q${r}`,
|
|
3617
|
+
prompt: n.prompt,
|
|
3618
|
+
selection: n.selection,
|
|
3619
|
+
options: n.options.map(
|
|
3620
|
+
(s, o) => typeof s == "string" ? { id: `q${r}-o${o}`, label: s } : {
|
|
3621
|
+
id: s.id ?? `q${r}-o${o}`,
|
|
3622
3622
|
label: s.label
|
|
3623
3623
|
}
|
|
3624
3624
|
).filter((s) => !Si(s.label))
|
|
3625
3625
|
}))
|
|
3626
3626
|
};
|
|
3627
3627
|
}
|
|
3628
|
-
function
|
|
3628
|
+
function kt(t) {
|
|
3629
3629
|
try {
|
|
3630
3630
|
return JSON.parse(t);
|
|
3631
3631
|
} catch {
|
|
@@ -3634,38 +3634,38 @@ function jt(t) {
|
|
|
3634
3634
|
}
|
|
3635
3635
|
function Ei(t) {
|
|
3636
3636
|
if (t == null) return null;
|
|
3637
|
-
if (typeof t == "string") return
|
|
3637
|
+
if (typeof t == "string") return kt(t);
|
|
3638
3638
|
if (Array.isArray(t)) {
|
|
3639
3639
|
for (const e of t)
|
|
3640
3640
|
if (e && typeof e == "object" && "text" in e) {
|
|
3641
|
-
const
|
|
3642
|
-
if (typeof
|
|
3641
|
+
const n = e.text;
|
|
3642
|
+
if (typeof n == "string") return kt(n);
|
|
3643
3643
|
}
|
|
3644
3644
|
return null;
|
|
3645
3645
|
}
|
|
3646
3646
|
if (typeof t == "object") {
|
|
3647
3647
|
if ("text" in t) {
|
|
3648
3648
|
const e = t.text;
|
|
3649
|
-
if (typeof e == "string") return
|
|
3649
|
+
if (typeof e == "string") return kt(e);
|
|
3650
3650
|
}
|
|
3651
3651
|
return t;
|
|
3652
3652
|
}
|
|
3653
3653
|
return null;
|
|
3654
3654
|
}
|
|
3655
|
-
function
|
|
3656
|
-
const
|
|
3657
|
-
if (
|
|
3658
|
-
const
|
|
3659
|
-
return
|
|
3655
|
+
function yn(t, e) {
|
|
3656
|
+
const n = Ei(t);
|
|
3657
|
+
if (n == null) return null;
|
|
3658
|
+
const r = yi.safeParse(n);
|
|
3659
|
+
return r.success ? Ii(r.data, e) : null;
|
|
3660
3660
|
}
|
|
3661
3661
|
function xo(t, e) {
|
|
3662
|
-
const
|
|
3663
|
-
for (const
|
|
3664
|
-
const s = e.get(
|
|
3665
|
-
s === void 0 || s.trim() === "" ||
|
|
3662
|
+
const n = [];
|
|
3663
|
+
for (const r of t.questions) {
|
|
3664
|
+
const s = e.get(r.id);
|
|
3665
|
+
s === void 0 || s.trim() === "" || n.push(`Q: ${r.prompt}
|
|
3666
3666
|
A: ${s.trim()}`);
|
|
3667
3667
|
}
|
|
3668
|
-
return
|
|
3668
|
+
return n.join(`
|
|
3669
3669
|
|
|
3670
3670
|
`);
|
|
3671
3671
|
}
|
|
@@ -3675,7 +3675,7 @@ const Ci = L.object({
|
|
|
3675
3675
|
name: L.string().min(1).max(120)
|
|
3676
3676
|
}), wi = L.object({
|
|
3677
3677
|
connection_required: Ci
|
|
3678
|
-
}),
|
|
3678
|
+
}), vn = "data-spec", Ai = L.object({ label: L.string(), done: L.boolean() }), xi = L.object({
|
|
3679
3679
|
plan: L.array(
|
|
3680
3680
|
L.object({
|
|
3681
3681
|
step: L.string(),
|
|
@@ -3684,13 +3684,13 @@ const Ci = L.object({
|
|
|
3684
3684
|
)
|
|
3685
3685
|
});
|
|
3686
3686
|
function pt(t) {
|
|
3687
|
-
const e = [],
|
|
3687
|
+
const e = [], n = (l) => {
|
|
3688
3688
|
const u = e.at(-1);
|
|
3689
3689
|
(u == null ? void 0 : u.kind) === "steps" ? u.steps.push(l) : e.push({ kind: "steps", steps: [l] });
|
|
3690
|
-
},
|
|
3690
|
+
}, r = (l) => l === "output-available" || l === "output-error";
|
|
3691
3691
|
let s = null, o;
|
|
3692
3692
|
for (const l of t)
|
|
3693
|
-
if (!$
|
|
3693
|
+
if (!$r(l) && dr(l) !== "highlight_element") {
|
|
3694
3694
|
if (l.state === "output-available" && (l.type === "dynamic-tool" || l.type.startsWith("tool-"))) {
|
|
3695
3695
|
const u = wi.safeParse(l.output);
|
|
3696
3696
|
if (u.success) {
|
|
@@ -3711,13 +3711,13 @@ function pt(t) {
|
|
|
3711
3711
|
u.success && (o ? o.plan = u.data.plan : (o = { kind: "plan", plan: u.data.plan }, e.push(o)));
|
|
3712
3712
|
} else if (l.type === "data-tool-activity") {
|
|
3713
3713
|
const u = Ai.safeParse(l.data);
|
|
3714
|
-
u.success &&
|
|
3714
|
+
u.success && n({
|
|
3715
3715
|
kind: "tool",
|
|
3716
3716
|
label: u.data.label,
|
|
3717
3717
|
done: u.data.done
|
|
3718
3718
|
});
|
|
3719
|
-
} else if (l.type ===
|
|
3720
|
-
s || (s = { kind: "spec", parts: [] }, e.push(s)), s.parts.push({ type:
|
|
3719
|
+
} else if (l.type === vn)
|
|
3720
|
+
s || (s = { kind: "spec", parts: [] }, e.push(s)), s.parts.push({ type: vn, data: l.data });
|
|
3721
3721
|
else if (l.type === "text") {
|
|
3722
3722
|
const u = typeof l.text == "string" ? l.text : "";
|
|
3723
3723
|
u.trim().length > 0 && e.push({
|
|
@@ -3725,47 +3725,47 @@ function pt(t) {
|
|
|
3725
3725
|
text: u,
|
|
3726
3726
|
...l.state === "streaming" ? { streaming: !0 } : {}
|
|
3727
3727
|
});
|
|
3728
|
-
} else l.type === "reasoning" ?
|
|
3728
|
+
} else l.type === "reasoning" ? n({
|
|
3729
3729
|
kind: "reasoning",
|
|
3730
3730
|
label: typeof l.text == "string" ? l.text : "",
|
|
3731
3731
|
done: l.state !== "streaming"
|
|
3732
|
-
}) : l.type === "dynamic-tool" ?
|
|
3732
|
+
}) : l.type === "dynamic-tool" ? n({
|
|
3733
3733
|
kind: "tool",
|
|
3734
3734
|
label: typeof l.toolName == "string" ? l.toolName : "tool",
|
|
3735
|
-
done:
|
|
3736
|
-
...
|
|
3737
|
-
}) : l.type.startsWith("tool-") &&
|
|
3735
|
+
done: r(l.state),
|
|
3736
|
+
...bn(l)
|
|
3737
|
+
}) : l.type.startsWith("tool-") && n({
|
|
3738
3738
|
kind: "tool",
|
|
3739
3739
|
label: l.type.slice(5),
|
|
3740
|
-
done:
|
|
3741
|
-
...
|
|
3740
|
+
done: r(l.state),
|
|
3741
|
+
...bn(l)
|
|
3742
3742
|
});
|
|
3743
3743
|
}
|
|
3744
3744
|
return e;
|
|
3745
3745
|
}
|
|
3746
|
-
function
|
|
3746
|
+
function dr(t) {
|
|
3747
3747
|
return t.type === "dynamic-tool" ? typeof t.toolName == "string" ? t.toolName : void 0 : t.type.startsWith("tool-") ? t.type.slice(5) : void 0;
|
|
3748
3748
|
}
|
|
3749
3749
|
function Ti(t) {
|
|
3750
|
-
return vi(
|
|
3750
|
+
return vi(dr(t));
|
|
3751
3751
|
}
|
|
3752
3752
|
function Mi(t) {
|
|
3753
|
-
const e = typeof t.toolCallId == "string" ? t.toolCallId : void 0,
|
|
3754
|
-
return
|
|
3753
|
+
const e = typeof t.toolCallId == "string" ? t.toolCallId : void 0, n = yn(t.output, e) ?? yn(t.input, e);
|
|
3754
|
+
return n ? { kind: "questions", request: n } : null;
|
|
3755
3755
|
}
|
|
3756
|
-
function
|
|
3756
|
+
function bn(t) {
|
|
3757
3757
|
return {
|
|
3758
3758
|
...t.input === void 0 ? {} : { input: t.input },
|
|
3759
3759
|
...t.output === void 0 ? {} : { output: t.output }
|
|
3760
3760
|
};
|
|
3761
3761
|
}
|
|
3762
3762
|
function _i(t, e) {
|
|
3763
|
-
const
|
|
3764
|
-
return e != null && e.toolActivity &&
|
|
3763
|
+
const n = [];
|
|
3764
|
+
return e != null && e.toolActivity && n.push(
|
|
3765
3765
|
`toolActivity=${encodeURIComponent(e.toolActivity)}`
|
|
3766
|
-
), (e == null ? void 0 : e.reasoning) !== void 0 &&
|
|
3766
|
+
), (e == null ? void 0 : e.reasoning) !== void 0 && n.push(`reasoning=${String(e.reasoning)}`), n.length === 0 ? t : `${t}${t.includes("?") ? "&" : "?"}${n.join("&")}`;
|
|
3767
3767
|
}
|
|
3768
|
-
function
|
|
3768
|
+
function Sn(t) {
|
|
3769
3769
|
return ({ id: e }) => ({
|
|
3770
3770
|
api: t.reconnectApi(e),
|
|
3771
3771
|
headers: t.headers()
|
|
@@ -3773,15 +3773,15 @@ function br(t) {
|
|
|
3773
3773
|
}
|
|
3774
3774
|
const Ri = [0, 500, 1500];
|
|
3775
3775
|
function Pi(t, e) {
|
|
3776
|
-
return new Promise((
|
|
3776
|
+
return new Promise((n) => {
|
|
3777
3777
|
if (t === 0 || e != null && e.aborted) {
|
|
3778
|
-
|
|
3778
|
+
n();
|
|
3779
3779
|
return;
|
|
3780
3780
|
}
|
|
3781
|
-
const
|
|
3782
|
-
clearTimeout(s), e == null || e.removeEventListener("abort",
|
|
3783
|
-
}, s = setTimeout(
|
|
3784
|
-
e == null || e.addEventListener("abort",
|
|
3781
|
+
const r = () => {
|
|
3782
|
+
clearTimeout(s), e == null || e.removeEventListener("abort", r), n();
|
|
3783
|
+
}, s = setTimeout(r, t);
|
|
3784
|
+
e == null || e.addEventListener("abort", r);
|
|
3785
3785
|
});
|
|
3786
3786
|
}
|
|
3787
3787
|
function Oi(t) {
|
|
@@ -3795,18 +3795,18 @@ class Ni extends yt {
|
|
|
3795
3795
|
fetch: e.fetch,
|
|
3796
3796
|
// Every send carries its full body; a send without one is a programming
|
|
3797
3797
|
// error, and an empty body would be rejected server-side just as loudly.
|
|
3798
|
-
prepareSendMessagesRequest: ({ body:
|
|
3799
|
-
prepareReconnectToStreamRequest:
|
|
3798
|
+
prepareSendMessagesRequest: ({ body: n }) => ({ body: n ?? {} }),
|
|
3799
|
+
prepareReconnectToStreamRequest: Sn(e)
|
|
3800
3800
|
}), this.agentOptions = e;
|
|
3801
3801
|
}
|
|
3802
3802
|
async sendMessages(e) {
|
|
3803
3803
|
try {
|
|
3804
3804
|
return await super.sendMessages(e);
|
|
3805
|
-
} catch (
|
|
3806
|
-
const
|
|
3807
|
-
if (
|
|
3808
|
-
return this.readThroughRecoveryFetch(
|
|
3809
|
-
chatId:
|
|
3805
|
+
} catch (n) {
|
|
3806
|
+
const r = Oi(e.body);
|
|
3807
|
+
if (r === void 0) throw n;
|
|
3808
|
+
return this.readThroughRecoveryFetch(n, "send", {
|
|
3809
|
+
chatId: r,
|
|
3810
3810
|
headers: e.headers,
|
|
3811
3811
|
metadata: e.metadata,
|
|
3812
3812
|
abortSignal: e.abortSignal
|
|
@@ -3816,12 +3816,12 @@ class Ni extends yt {
|
|
|
3816
3816
|
async reconnectToStream(e) {
|
|
3817
3817
|
try {
|
|
3818
3818
|
return await super.reconnectToStream(e);
|
|
3819
|
-
} catch (
|
|
3820
|
-
return this.readThroughRecoveryFetch(
|
|
3819
|
+
} catch (n) {
|
|
3820
|
+
return this.readThroughRecoveryFetch(n, "resume", e);
|
|
3821
3821
|
}
|
|
3822
3822
|
}
|
|
3823
3823
|
/** The recovered stream; otherwise the original error is rethrown. */
|
|
3824
|
-
async readThroughRecoveryFetch(e,
|
|
3824
|
+
async readThroughRecoveryFetch(e, n, r) {
|
|
3825
3825
|
var l, u, y, g, i;
|
|
3826
3826
|
if (!ft.isInstance(e)) throw e;
|
|
3827
3827
|
const s = (u = (l = this.agentOptions).recoveryFetch) == null ? void 0 : u.call(l);
|
|
@@ -3830,20 +3830,20 @@ class Ni extends yt {
|
|
|
3830
3830
|
api: this.agentOptions.api,
|
|
3831
3831
|
headers: () => this.agentOptions.headers(),
|
|
3832
3832
|
fetch: s,
|
|
3833
|
-
prepareReconnectToStreamRequest:
|
|
3833
|
+
prepareReconnectToStreamRequest: Sn(
|
|
3834
3834
|
this.agentOptions
|
|
3835
3835
|
)
|
|
3836
3836
|
});
|
|
3837
3837
|
for (const d of Ri) {
|
|
3838
|
-
if (await Pi(d,
|
|
3838
|
+
if (await Pi(d, r.abortSignal), (y = r.abortSignal) != null && y.aborted) throw e;
|
|
3839
3839
|
let p;
|
|
3840
3840
|
try {
|
|
3841
|
-
p = await o.reconnectToStream(
|
|
3841
|
+
p = await o.reconnectToStream(r);
|
|
3842
3842
|
} catch (b) {
|
|
3843
3843
|
throw le.warn("agent chat recovery read failed", b), e;
|
|
3844
3844
|
}
|
|
3845
3845
|
if (p)
|
|
3846
|
-
return (i = (g = this.agentOptions).onRecovered) == null || i.call(g,
|
|
3846
|
+
return (i = (g = this.agentOptions).onRecovered) == null || i.call(g, n, e), p;
|
|
3847
3847
|
}
|
|
3848
3848
|
throw e;
|
|
3849
3849
|
}
|
|
@@ -3854,16 +3854,16 @@ function Di(t) {
|
|
|
3854
3854
|
function Li({
|
|
3855
3855
|
existing: t,
|
|
3856
3856
|
fetched: e,
|
|
3857
|
-
refreshItems:
|
|
3857
|
+
refreshItems: n = !1
|
|
3858
3858
|
}) {
|
|
3859
|
-
const
|
|
3859
|
+
const r = new Map(
|
|
3860
3860
|
t.map((u) => [u.turnId, u])
|
|
3861
3861
|
), s = /* @__PURE__ */ new Set(), o = [];
|
|
3862
3862
|
for (const u of e.turns) {
|
|
3863
3863
|
if (s.add(u.turn_id), u.message_uuids.length === 0) continue;
|
|
3864
|
-
const y =
|
|
3865
|
-
if (y && !
|
|
3866
|
-
|
|
3864
|
+
const y = r.get(u.turn_id);
|
|
3865
|
+
if (y && !n) {
|
|
3866
|
+
ki(y.rowIds, u.message_uuids) ? o.push(y) : o.push({ ...y, rowIds: u.message_uuids });
|
|
3867
3867
|
continue;
|
|
3868
3868
|
}
|
|
3869
3869
|
if (u.ui_parts !== null) {
|
|
@@ -3881,12 +3881,12 @@ function Li({
|
|
|
3881
3881
|
s.has(u.turnId) || o.push(u);
|
|
3882
3882
|
return o.length === t.length && o.every((u, y) => u === t[y]) ? t : o;
|
|
3883
3883
|
}
|
|
3884
|
-
const
|
|
3885
|
-
function
|
|
3884
|
+
const ki = (t, e) => t.length === e.length && t.every((n, r) => n === e[r]), ji = (t) => Array.isArray(t) && t.every((e) => typeof e == "string");
|
|
3885
|
+
function In(t) {
|
|
3886
3886
|
for (const e of t) {
|
|
3887
3887
|
if (e.type !== "data-turn-settled") continue;
|
|
3888
|
-
const
|
|
3889
|
-
return !
|
|
3888
|
+
const n = e.data;
|
|
3889
|
+
return !_n(n) || typeof n.turn_id != "string" || !ji(n.message_uuids) ? null : { turnId: n.turn_id, rowIds: n.message_uuids };
|
|
3890
3890
|
}
|
|
3891
3891
|
return null;
|
|
3892
3892
|
}
|
|
@@ -3904,36 +3904,36 @@ function $i(t) {
|
|
|
3904
3904
|
async function Fi({
|
|
3905
3905
|
api: t,
|
|
3906
3906
|
sessionId: e,
|
|
3907
|
-
chatStop:
|
|
3907
|
+
chatStop: n
|
|
3908
3908
|
}) {
|
|
3909
3909
|
try {
|
|
3910
|
-
await
|
|
3910
|
+
await n();
|
|
3911
3911
|
} finally {
|
|
3912
3912
|
e && await t.stopStream(e);
|
|
3913
3913
|
}
|
|
3914
3914
|
}
|
|
3915
3915
|
const Ui = /^[A-Za-z0-9_$.]{1,100}$/;
|
|
3916
|
-
function
|
|
3916
|
+
function En(t) {
|
|
3917
3917
|
const e = Ui.test(t.name) ? t.name : "Error";
|
|
3918
3918
|
if (ft.isInstance(t))
|
|
3919
3919
|
return { kind: "empty_body", error_name: e };
|
|
3920
|
-
if (
|
|
3921
|
-
const
|
|
3922
|
-
return
|
|
3920
|
+
if (kn.isInstance(t)) {
|
|
3921
|
+
const n = t.statusCode;
|
|
3922
|
+
return n !== void 0 && n >= 100 && n <= 599 ? { kind: "http_error", error_name: e, http_status: n } : { kind: "http_error", error_name: e };
|
|
3923
3923
|
}
|
|
3924
3924
|
if (t instanceof TypeError) {
|
|
3925
|
-
const
|
|
3926
|
-
if (
|
|
3925
|
+
const n = t.message.toLowerCase();
|
|
3926
|
+
if (n.includes("fetch") || n.includes("network") || n === "load failed")
|
|
3927
3927
|
return { kind: "network", error_name: e };
|
|
3928
3928
|
}
|
|
3929
3929
|
return { kind: "other", error_name: e };
|
|
3930
3930
|
}
|
|
3931
|
-
const
|
|
3931
|
+
const Cn = 20, qi = [1e3, 3e3, 8e3], zi = "highlight_element", Zi = "act_on_page";
|
|
3932
3932
|
function Vi({
|
|
3933
3933
|
widgetCtx: t,
|
|
3934
3934
|
config: e,
|
|
3935
|
-
sessionId:
|
|
3936
|
-
persistedMessages:
|
|
3935
|
+
sessionId: n,
|
|
3936
|
+
persistedMessages: r
|
|
3937
3937
|
}) {
|
|
3938
3938
|
var Qt, Xt;
|
|
3939
3939
|
const { api: s, messageCtx: o } = t, l = R(e);
|
|
@@ -3953,7 +3953,10 @@ function Vi({
|
|
|
3953
3953
|
),
|
|
3954
3954
|
// Resolved per request too, so a `streamingFetch` swapped on a live
|
|
3955
3955
|
// provider carries the next send.
|
|
3956
|
-
fetch: (v, E) => (l.current.streamingFetch ?? globalThis.fetch)(
|
|
3956
|
+
fetch: (v, E) => s.withRenewal(l.current.streamingFetch ?? globalThis.fetch)(
|
|
3957
|
+
v,
|
|
3958
|
+
E
|
|
3959
|
+
),
|
|
3957
3960
|
// A `streamingFetch` whose response cannot be read (one rebuilt with
|
|
3958
3961
|
// React Native's global Response) leaves the reply to the global
|
|
3959
3962
|
// fetch, which streams on Expo SDK 57. Without a `streamingFetch` the global
|
|
@@ -3965,9 +3968,9 @@ function Vi({
|
|
|
3965
3968
|
onRecovered: (v, E) => i.current(v, E)
|
|
3966
3969
|
}),
|
|
3967
3970
|
[s]
|
|
3968
|
-
), [p, b] = J(null), P = R(!1), [M] = J(Rt), O = R(Promise.resolve()), x = R(0),
|
|
3969
|
-
() =>
|
|
3970
|
-
[
|
|
3971
|
+
), [p, b] = J(null), P = R(!1), [M] = J(Rt), O = R(Promise.resolve()), x = R(0), C = R(0), I = R(n), w = X(
|
|
3972
|
+
() => n !== null && !(I.current === null && x.current > 0),
|
|
3973
|
+
[n]
|
|
3971
3974
|
), c = R(() => {
|
|
3972
3975
|
}), {
|
|
3973
3976
|
status: m,
|
|
@@ -3978,8 +3981,8 @@ function Vi({
|
|
|
3978
3981
|
clearError: D,
|
|
3979
3982
|
resumeStream: B
|
|
3980
3983
|
} = mi({
|
|
3981
|
-
id:
|
|
3982
|
-
resume:
|
|
3984
|
+
id: n ?? M,
|
|
3985
|
+
resume: w,
|
|
3983
3986
|
transport: d,
|
|
3984
3987
|
// Batch token updates: without it every streamed token re-renders the
|
|
3985
3988
|
// whole chat surface (transcript + composer), which stutters on long
|
|
@@ -3989,32 +3992,32 @@ function Vi({
|
|
|
3989
3992
|
onFinish: b
|
|
3990
3993
|
}), W = R(f);
|
|
3991
3994
|
W.current = f;
|
|
3992
|
-
const
|
|
3995
|
+
const k = R(new gn(Cn));
|
|
3993
3996
|
F(() => {
|
|
3994
3997
|
if (!p || p.messages !== f) return;
|
|
3995
3998
|
const { isAbort: v, isDisconnect: E, isError: T, message: A } = p;
|
|
3996
|
-
v || E || T ||
|
|
3997
|
-
lastAIResMightSolveUserIssue:
|
|
3999
|
+
v || E || T || k.current.size > 0 || o.state.setPartial({
|
|
4000
|
+
lastAIResMightSolveUserIssue: _n(A.metadata) && A.metadata.mightSolveUserIssue === !0
|
|
3998
4001
|
});
|
|
3999
4002
|
}, [p, f, o]);
|
|
4000
4003
|
const $ = R("idle"), [Se, Ie] = J(!1), [ve, ae] = J(0), [G, de] = J(!1), fe = R(G);
|
|
4001
4004
|
fe.current = G;
|
|
4002
|
-
const [Ee, U] = J([]), [ie, Ce] = J([]), [me,
|
|
4003
|
-
Ye.current = v,
|
|
4004
|
-
}, []), Ue = R(null), we = R(null), Ae = R(null), Wt = R(
|
|
4005
|
-
Wt.current =
|
|
4005
|
+
const [Ee, U] = J([]), [ie, Ce] = J([]), [me, Cr] = J(null), Ye = R(null), Re = z((v) => {
|
|
4006
|
+
Ye.current = v, Cr(v);
|
|
4007
|
+
}, []), Ue = R(null), we = R(null), Ae = R(null), Wt = R(n);
|
|
4008
|
+
Wt.current = n;
|
|
4006
4009
|
const Jt = (v, E, T) => {
|
|
4007
4010
|
const A = Wt.current;
|
|
4008
4011
|
A && s.reportClientStreamError(A, {
|
|
4009
|
-
...
|
|
4012
|
+
...En(v),
|
|
4010
4013
|
phase: E,
|
|
4011
4014
|
recovered: T,
|
|
4012
|
-
widget_version:
|
|
4015
|
+
widget_version: Pn,
|
|
4013
4016
|
platform: typeof navigator < "u" && navigator.product === "ReactNative" ? "react-native" : "web"
|
|
4014
4017
|
});
|
|
4015
4018
|
};
|
|
4016
4019
|
c.current = (v) => {
|
|
4017
|
-
le.error("agent chat stream error", v),
|
|
4020
|
+
le.error("agent chat stream error", v), En(v).kind === "empty_body" && le.error(
|
|
4018
4021
|
"the streaming response has no readable body. In React Native, pass `streamingFetch` from `expo/fetch` and return its response unchanged: React Native's global Response cannot stream."
|
|
4019
4022
|
);
|
|
4020
4023
|
const E = $.current === "in-flight" ? "send" : "resume", T = we.current;
|
|
@@ -4030,20 +4033,20 @@ function Vi({
|
|
|
4030
4033
|
"the `streamingFetch` response has no readable body, so replies are read through the global fetch instead. Return the `expo/fetch` response unchanged to stream it directly."
|
|
4031
4034
|
)), Jt(E, v, !0);
|
|
4032
4035
|
};
|
|
4033
|
-
const qe = R(m), Ke = I.current ===
|
|
4036
|
+
const qe = R(m), Ke = I.current === n, Et = R(null), Ct = R(null), Yt = R(S), xe = R(m);
|
|
4034
4037
|
xe.current = m;
|
|
4035
4038
|
const tt = z((v, E) => {
|
|
4036
|
-
const T =
|
|
4039
|
+
const T = In(v.parts);
|
|
4037
4040
|
if (!T || T.rowIds.length === 0) return;
|
|
4038
4041
|
const A = pt(v.parts);
|
|
4039
4042
|
A.length !== 0 && U(
|
|
4040
|
-
(
|
|
4041
|
-
...
|
|
4043
|
+
(j) => j.some((Y) => Y.turnId === T.turnId) ? j : [
|
|
4044
|
+
...j,
|
|
4042
4045
|
{ key: E, turnId: T.turnId, rowIds: T.rowIds, items: A }
|
|
4043
4046
|
]
|
|
4044
4047
|
);
|
|
4045
4048
|
}, []), Kt = z(
|
|
4046
|
-
(v) =>
|
|
4049
|
+
(v) => Fr({
|
|
4047
4050
|
config: l.current,
|
|
4048
4051
|
input: v.input,
|
|
4049
4052
|
uuid: v.retryUuid ?? v.userMessage.id,
|
|
@@ -4058,17 +4061,17 @@ function Vi({
|
|
|
4058
4061
|
const v = Yt.current;
|
|
4059
4062
|
Yt.current = S;
|
|
4060
4063
|
const E = I.current;
|
|
4061
|
-
if (E ===
|
|
4062
|
-
if (I.current =
|
|
4064
|
+
if (E === n) return;
|
|
4065
|
+
if (I.current = n, E === null) {
|
|
4063
4066
|
U([]);
|
|
4064
4067
|
return;
|
|
4065
4068
|
}
|
|
4066
4069
|
const T = xe.current === "submitted" || xe.current === "streaming" || qe.current === "submitted" || qe.current === "streaming" || $.current === "in-flight";
|
|
4067
|
-
|
|
4070
|
+
C.current += 1, x.current = 0, O.current = Promise.resolve(), k.current = new gn(Cn), $.current = "idle", Ie(!1), we.current = null, Ae.current = null, Ue.current = null, b(null), P.current = !1, Ct.current = null, Et.current = m === "submitted" || m === "streaming" ? m : null, qe.current = "ready", xe.current = "ready", D(), ae((A) => A + 1), de(!1), U([]), Re(null), T && Promise.resolve().then(() => v()).catch((A) => {
|
|
4068
4071
|
le.error("agent chat client stream cancel failed", A);
|
|
4069
4072
|
});
|
|
4070
|
-
}, [
|
|
4071
|
-
var
|
|
4073
|
+
}, [n, m, S, D, Re]), F(() => {
|
|
4074
|
+
var j, Y;
|
|
4072
4075
|
const v = Et.current;
|
|
4073
4076
|
if (v !== null && m === v) {
|
|
4074
4077
|
qe.current = "ready";
|
|
@@ -4077,7 +4080,7 @@ function Vi({
|
|
|
4077
4080
|
Et.current = null;
|
|
4078
4081
|
const E = qe.current;
|
|
4079
4082
|
if (qe.current = m, (m === "submitted" || m === "streaming") && (E !== "submitted" && E !== "streaming" && Ye.current === null && Re(`turn-resumed-${Rt()}`), de(!0)), m === "streaming") {
|
|
4080
|
-
const Z = (
|
|
4083
|
+
const Z = (j = we.current) == null ? void 0 : j.userMessage.id;
|
|
4081
4084
|
Z && o.markUserMessageDelivered(Z);
|
|
4082
4085
|
return;
|
|
4083
4086
|
}
|
|
@@ -4092,21 +4095,21 @@ function Vi({
|
|
|
4092
4095
|
const Pe = (Y = we.current) == null ? void 0 : Y.userMessage.id;
|
|
4093
4096
|
Pe && o.markUserMessageDelivered(Pe);
|
|
4094
4097
|
} else Z && E !== "streaming" && we.current && o.releaseUnsentOptionPick(we.current.input);
|
|
4095
|
-
$.current === "stopping" || (
|
|
4098
|
+
$.current === "stopping" || (n ? ($.current = "reconciling", t.reconcileAfterStream(n).catch((Pe) => {
|
|
4096
4099
|
le.error("agent chat post-turn reconcile failed", Pe);
|
|
4097
4100
|
}).finally(() => {
|
|
4098
4101
|
$.current === "reconciling" && ($.current = "idle"), ae((Pe) => Pe + 1);
|
|
4099
4102
|
})) : de(!1));
|
|
4100
4103
|
}
|
|
4101
|
-
if ($.current !== "idle" || !
|
|
4102
|
-
const A =
|
|
4104
|
+
if ($.current !== "idle" || !n || fe.current && m !== "error") return;
|
|
4105
|
+
const A = k.current.dequeueNext();
|
|
4103
4106
|
A && ($.current = "in-flight", Ie(!1), we.current = A, Ae.current = null, b(null), P.current = !1, Re(`turn-${A.userMessage.id}`), o.appendUserMessageIfAbsent(A.userMessage), ae((Z) => Z + 1), h(
|
|
4104
4107
|
{ text: A.userMessage.content },
|
|
4105
4108
|
{ body: Kt(A) }
|
|
4106
4109
|
));
|
|
4107
4110
|
}, [
|
|
4108
4111
|
m,
|
|
4109
|
-
|
|
4112
|
+
n,
|
|
4110
4113
|
ve,
|
|
4111
4114
|
h,
|
|
4112
4115
|
o,
|
|
@@ -4118,15 +4121,15 @@ function Vi({
|
|
|
4118
4121
|
]);
|
|
4119
4122
|
const Gt = z(
|
|
4120
4123
|
(v) => {
|
|
4121
|
-
const E =
|
|
4124
|
+
const E = C.current;
|
|
4122
4125
|
x.current++;
|
|
4123
4126
|
const A = O.current.then(
|
|
4124
4127
|
async () => {
|
|
4125
|
-
if (E !==
|
|
4126
|
-
const
|
|
4127
|
-
if (!Z || E !==
|
|
4128
|
+
if (E !== C.current) return;
|
|
4129
|
+
const j = $.current, Z = xe.current === "submitted" || xe.current === "streaming" || j !== "idle" || fe.current || k.current.size > 0 ? Bi(o.buildQueuedUserMessage(v)) : await o.stageUserTurn(v, { pending: !0 });
|
|
4130
|
+
if (!Z || E !== C.current) return;
|
|
4128
4131
|
const re = { ...Z, input: v };
|
|
4129
|
-
if (!
|
|
4132
|
+
if (!k.current.enqueue(re)) {
|
|
4130
4133
|
le.warn("agent chat queue full; rejecting newest send", {
|
|
4131
4134
|
rejectedMessageId: re.userMessage.id
|
|
4132
4135
|
});
|
|
@@ -4135,7 +4138,7 @@ function Vi({
|
|
|
4135
4138
|
ae((be) => be + 1), o.notifySendAccepted(v);
|
|
4136
4139
|
}
|
|
4137
4140
|
).finally(() => {
|
|
4138
|
-
E ===
|
|
4141
|
+
E === C.current && x.current--;
|
|
4139
4142
|
});
|
|
4140
4143
|
return O.current = A.then(
|
|
4141
4144
|
() => {
|
|
@@ -4145,13 +4148,13 @@ function Vi({
|
|
|
4145
4148
|
), A;
|
|
4146
4149
|
},
|
|
4147
4150
|
[o]
|
|
4148
|
-
),
|
|
4151
|
+
), wr = z(() => {
|
|
4149
4152
|
var Y;
|
|
4150
4153
|
const v = we.current;
|
|
4151
4154
|
if (!v) return;
|
|
4152
|
-
const E = v.input.optionReply, T = E ?
|
|
4155
|
+
const E = v.input.optionReply, T = E ? r.find((Z) => Z.id === E.messageId) : void 0, A = T && Ur(T) ? (Y = T.messageOptions) == null ? void 0 : Y.pickedOptionId : null;
|
|
4153
4156
|
if (E && A && A !== E.optionId) return;
|
|
4154
|
-
if (!
|
|
4157
|
+
if (!k.current.enqueue({
|
|
4155
4158
|
...v,
|
|
4156
4159
|
retryUuid: Rt()
|
|
4157
4160
|
})) {
|
|
@@ -4159,52 +4162,52 @@ function Vi({
|
|
|
4159
4162
|
return;
|
|
4160
4163
|
}
|
|
4161
4164
|
E && o.setMessageOptionPick(E.messageId, E.optionId), D(), ae((Z) => Z + 1);
|
|
4162
|
-
}, [D, o,
|
|
4165
|
+
}, [D, o, r]), Ar = z(
|
|
4163
4166
|
(v) => {
|
|
4164
|
-
const E =
|
|
4167
|
+
const E = k.current.removeWhere(
|
|
4165
4168
|
(T) => T.userMessage.id === v
|
|
4166
4169
|
);
|
|
4167
4170
|
E && (o.releaseUnsentOptionPick(E.input), ae((T) => T + 1));
|
|
4168
4171
|
},
|
|
4169
4172
|
[o]
|
|
4170
|
-
),
|
|
4173
|
+
), xr = z(() => {
|
|
4171
4174
|
$.current = "stopping", Ie(!0), P.current = !1;
|
|
4172
|
-
const v =
|
|
4173
|
-
Fi({ api: s, sessionId:
|
|
4174
|
-
v ===
|
|
4175
|
+
const v = C.current;
|
|
4176
|
+
Fi({ api: s, sessionId: n, chatStop: S }).then(() => {
|
|
4177
|
+
v === C.current && (P.current = !0);
|
|
4175
4178
|
}).catch((E) => {
|
|
4176
4179
|
le.error("agent chat stop failed", E);
|
|
4177
4180
|
}).then(() => {
|
|
4178
|
-
if (v ===
|
|
4179
|
-
if (!
|
|
4181
|
+
if (v === C.current) {
|
|
4182
|
+
if (!n) {
|
|
4180
4183
|
de(!1);
|
|
4181
4184
|
return;
|
|
4182
4185
|
}
|
|
4183
|
-
return t.reconcileAfterStream(
|
|
4186
|
+
return t.reconcileAfterStream(n).catch((E) => {
|
|
4184
4187
|
le.error("agent chat post-stop reconcile failed", E);
|
|
4185
4188
|
});
|
|
4186
4189
|
}
|
|
4187
4190
|
}).finally(() => {
|
|
4188
|
-
v ===
|
|
4191
|
+
v === C.current && ($.current = "idle", ae((E) => E + 1));
|
|
4189
4192
|
});
|
|
4190
|
-
}, [s,
|
|
4193
|
+
}, [s, n, S, t]);
|
|
4191
4194
|
F(() => {
|
|
4192
4195
|
const v = {
|
|
4193
4196
|
send: Gt,
|
|
4194
|
-
hasPendingWork: () => x.current > 0 || fe.current ||
|
|
4197
|
+
hasPendingWork: () => x.current > 0 || fe.current || k.current.size > 0 || $.current !== "idle" || xe.current === "submitted" || xe.current === "streaming"
|
|
4195
4198
|
};
|
|
4196
4199
|
return o.registerAgentHandlers(v), () => o.unregisterAgentHandlers(v);
|
|
4197
4200
|
}, [o, Gt]);
|
|
4198
|
-
const
|
|
4199
|
-
F(() => Ce([]), [
|
|
4200
|
-
var
|
|
4201
|
-
if (!
|
|
4202
|
-
const v =
|
|
4203
|
-
Ct.current = { sessionId:
|
|
4201
|
+
const nt = (Qt = e.presentation) == null ? void 0 : Qt.toolActivity, rt = (Xt = e.presentation) == null ? void 0 : Xt.reasoning;
|
|
4202
|
+
F(() => Ce([]), [n]), F(() => {
|
|
4203
|
+
var j, Y;
|
|
4204
|
+
if (!n) return;
|
|
4205
|
+
const v = nt === void 0 && rt === void 0 ? void 0 : { toolActivity: nt, reasoning: rt }, E = Ct.current, T = (E == null ? void 0 : E.sessionId) === n && (((j = E.presentation) == null ? void 0 : j.toolActivity) !== nt || ((Y = E.presentation) == null ? void 0 : Y.reasoning) !== rt);
|
|
4206
|
+
Ct.current = { sessionId: n, presentation: v };
|
|
4204
4207
|
let A = !1;
|
|
4205
4208
|
return (async () => {
|
|
4206
4209
|
try {
|
|
4207
|
-
const Z = v === void 0 ? await s.getAgentTurnMessages(
|
|
4210
|
+
const Z = v === void 0 ? await s.getAgentTurnMessages(n) : await s.getAgentTurnMessages(n, v);
|
|
4208
4211
|
if (!Z || A) return;
|
|
4209
4212
|
Ce(Z.handled_connection_request_ids), U(
|
|
4210
4213
|
(re) => Li({ existing: re, fetched: Z, refreshItems: T })
|
|
@@ -4215,8 +4218,8 @@ function Vi({
|
|
|
4215
4218
|
})(), () => {
|
|
4216
4219
|
A = !0;
|
|
4217
4220
|
};
|
|
4218
|
-
}, [
|
|
4219
|
-
const [wt,
|
|
4221
|
+
}, [n, s, nt, rt]);
|
|
4222
|
+
const [wt, Tr] = J(() => /* @__PURE__ */ new Set()), st = R(wt), At = R(/* @__PURE__ */ new Set()), at = X(() => {
|
|
4220
4223
|
if (Se || m !== "streaming" && m !== "submitted")
|
|
4221
4224
|
return [];
|
|
4222
4225
|
const v = f.at(-1);
|
|
@@ -4224,16 +4227,16 @@ function Vi({
|
|
|
4224
4227
|
const E = [];
|
|
4225
4228
|
for (const T of v.parts) {
|
|
4226
4229
|
if (!pe(T)) continue;
|
|
4227
|
-
const A = Ka(T),
|
|
4228
|
-
|
|
4229
|
-
key: `${
|
|
4230
|
-
type:
|
|
4230
|
+
const A = Ka(T), j = A === zi ? "highlight-element" : A === Zi ? "act-on-page" : null;
|
|
4231
|
+
j && T.state === "input-available" && E.push({
|
|
4232
|
+
key: `${n ?? "pending"}:${T.toolCallId}`,
|
|
4233
|
+
type: j,
|
|
4231
4234
|
input: T.input,
|
|
4232
4235
|
callId: T.toolCallId
|
|
4233
4236
|
});
|
|
4234
4237
|
}
|
|
4235
4238
|
return E;
|
|
4236
|
-
}, [f,
|
|
4239
|
+
}, [f, n, m, Se]), Mr = X(
|
|
4237
4240
|
() => at.filter(
|
|
4238
4241
|
(v) => u && y && (v.type !== "act-on-page" || g) && !wt.has(v.key)
|
|
4239
4242
|
),
|
|
@@ -4246,16 +4249,16 @@ function Vi({
|
|
|
4246
4249
|
]
|
|
4247
4250
|
), xt = z(
|
|
4248
4251
|
(v, E, T, A) => {
|
|
4249
|
-
if (!
|
|
4250
|
-
const
|
|
4251
|
-
if (st.current.has(
|
|
4252
|
-
At.current.delete(
|
|
4252
|
+
if (!n) return;
|
|
4253
|
+
const j = `${n}:${v}`;
|
|
4254
|
+
if (st.current.has(j)) return;
|
|
4255
|
+
At.current.delete(j);
|
|
4253
4256
|
const Y = new Set(st.current);
|
|
4254
|
-
if (Y.add(
|
|
4257
|
+
if (Y.add(j), Y.size > 200) {
|
|
4255
4258
|
const Z = Y.values().next().value;
|
|
4256
4259
|
Z !== void 0 && Y.delete(Z);
|
|
4257
4260
|
}
|
|
4258
|
-
st.current = Y,
|
|
4261
|
+
st.current = Y, Tr(Y), s.sendPageReply(n, {
|
|
4259
4262
|
callId: v,
|
|
4260
4263
|
outcome: E,
|
|
4261
4264
|
...T ? { detail: T } : {},
|
|
@@ -4265,19 +4268,19 @@ function Vi({
|
|
|
4265
4268
|
...t.features.pageContext && A ? { controls: A.controls, truncated: A.truncated } : {}
|
|
4266
4269
|
});
|
|
4267
4270
|
},
|
|
4268
|
-
[s,
|
|
4269
|
-
), [
|
|
4271
|
+
[s, n, t]
|
|
4272
|
+
), [_r, Tt] = J(null), Te = R(
|
|
4270
4273
|
/* @__PURE__ */ new Map()
|
|
4271
|
-
),
|
|
4274
|
+
), Rr = z(
|
|
4272
4275
|
(v) => new Promise((E) => {
|
|
4273
|
-
const T = `${
|
|
4276
|
+
const T = `${n ?? "pending"}:${v.callId}`;
|
|
4274
4277
|
if (st.current.has(T)) {
|
|
4275
4278
|
E(!1);
|
|
4276
4279
|
return;
|
|
4277
4280
|
}
|
|
4278
4281
|
At.current.add(T), Te.current.forEach((A) => A(!1)), Te.current.clear(), Te.current.set(v.callId, E), Tt(v);
|
|
4279
4282
|
}),
|
|
4280
|
-
[
|
|
4283
|
+
[n]
|
|
4281
4284
|
), Mt = z((v, E) => {
|
|
4282
4285
|
const T = Te.current.get(v);
|
|
4283
4286
|
Te.current.delete(v), Tt(
|
|
@@ -4299,39 +4302,39 @@ function Vi({
|
|
|
4299
4302
|
F(() => {
|
|
4300
4303
|
var Z;
|
|
4301
4304
|
const v = Ae.current;
|
|
4302
|
-
if (N === void 0 || oe || !v || !
|
|
4303
|
-
const E = v.kind === "send" ? v.wireId : (Z =
|
|
4305
|
+
if (N === void 0 || oe || !v || !n) return;
|
|
4306
|
+
const E = v.kind === "send" ? v.wireId : (Z = r.findLast(
|
|
4304
4307
|
(re) => re.type === "USER" && !re.pending
|
|
4305
4308
|
)) == null ? void 0 : Z.id;
|
|
4306
4309
|
if (E === void 0) return;
|
|
4307
|
-
const T = new Set(
|
|
4308
|
-
let A = !1,
|
|
4310
|
+
const T = new Set(r.map((re) => re.id));
|
|
4311
|
+
let A = !1, j;
|
|
4309
4312
|
const Y = async (re) => {
|
|
4310
4313
|
let be;
|
|
4311
4314
|
try {
|
|
4312
|
-
be = await s.getAgentTurnMessages(
|
|
4315
|
+
be = await s.getAgentTurnMessages(n);
|
|
4313
4316
|
} catch (lt) {
|
|
4314
4317
|
le.warn("agent chat failed-turn check failed", lt);
|
|
4315
4318
|
return;
|
|
4316
4319
|
}
|
|
4317
4320
|
if (A || Ae.current !== v) return;
|
|
4318
4321
|
if (be == null ? void 0 : be.turns.some(
|
|
4319
|
-
(lt) => (lt.input_message_uuids ?? []).includes(E) && lt.message_uuids.some((
|
|
4322
|
+
(lt) => (lt.input_message_uuids ?? []).includes(E) && lt.message_uuids.some((Lr) => T.has(Lr))
|
|
4320
4323
|
)) {
|
|
4321
4324
|
Ae.current = null, v.kind === "send" && o.markUserMessageDelivered(v.bubbleId), D();
|
|
4322
4325
|
return;
|
|
4323
4326
|
}
|
|
4324
|
-
const [
|
|
4325
|
-
|
|
4327
|
+
const [en, ...Dr] = re;
|
|
4328
|
+
en !== void 0 && (j = setTimeout(() => void Y(Dr), en));
|
|
4326
4329
|
};
|
|
4327
4330
|
return Y(qi), () => {
|
|
4328
|
-
A = !0,
|
|
4331
|
+
A = !0, j !== void 0 && clearTimeout(j);
|
|
4329
4332
|
};
|
|
4330
4333
|
}, [
|
|
4331
4334
|
N,
|
|
4332
4335
|
oe,
|
|
4333
|
-
n,
|
|
4334
4336
|
r,
|
|
4337
|
+
n,
|
|
4335
4338
|
s,
|
|
4336
4339
|
o,
|
|
4337
4340
|
D
|
|
@@ -4339,7 +4342,7 @@ function Vi({
|
|
|
4339
4342
|
() => () => {
|
|
4340
4343
|
Te.current.forEach((v) => v(!1)), Te.current.clear();
|
|
4341
4344
|
},
|
|
4342
|
-
[
|
|
4345
|
+
[n]
|
|
4343
4346
|
), F(() => {
|
|
4344
4347
|
if (oe && !Se) return;
|
|
4345
4348
|
const v = Te.current;
|
|
@@ -4352,8 +4355,8 @@ function Vi({
|
|
|
4352
4355
|
E && E.role === "assistant" && tt(E, v);
|
|
4353
4356
|
}, [f, oe, tt]);
|
|
4354
4357
|
const _t = z(() => {
|
|
4355
|
-
|
|
4356
|
-
}, [
|
|
4358
|
+
n && (oe || N === void 0 && !G || B());
|
|
4359
|
+
}, [n, oe, G, N, B]);
|
|
4357
4360
|
F(
|
|
4358
4361
|
() => $i(_t),
|
|
4359
4362
|
[_t]
|
|
@@ -4365,22 +4368,22 @@ function Vi({
|
|
|
4365
4368
|
if (Ye.current === Ue.current && (p == null ? void 0 : p.messages) === f && !p.isError && !p.isDisconnect && (!p.isAbort || P.current) && !pt(p.message.parts).some(
|
|
4366
4369
|
(A) => A.kind !== "steps"
|
|
4367
4370
|
)) {
|
|
4368
|
-
const A =
|
|
4371
|
+
const A = r.findLast((j) => j.type === "USER");
|
|
4369
4372
|
A && o.state.setPartial({ settledAgentUserMessageId: A.id }), v();
|
|
4370
4373
|
return;
|
|
4371
4374
|
}
|
|
4372
4375
|
if (p && p.messages !== f) return;
|
|
4373
|
-
const E = f.at(-1), T = (E == null ? void 0 : E.role) === "assistant" ?
|
|
4376
|
+
const E = f.at(-1), T = (E == null ? void 0 : E.role) === "assistant" ? In(E.parts) : null;
|
|
4374
4377
|
if (T && T.rowIds.length > 0) {
|
|
4375
|
-
const A = new Set(
|
|
4376
|
-
T.rowIds.every((
|
|
4378
|
+
const A = new Set(r.map((j) => j.id));
|
|
4379
|
+
T.rowIds.every((j) => A.has(j)) && v();
|
|
4377
4380
|
return;
|
|
4378
4381
|
}
|
|
4379
|
-
for (let A =
|
|
4380
|
-
const
|
|
4381
|
-
if (
|
|
4382
|
-
if (
|
|
4383
|
-
if (!(
|
|
4382
|
+
for (let A = r.length - 1; A >= 0; A -= 1) {
|
|
4383
|
+
const j = r[A];
|
|
4384
|
+
if (j) {
|
|
4385
|
+
if (j.type === "USER") return;
|
|
4386
|
+
if (!(j.type !== "AI" && j.type !== "AGENT")) {
|
|
4384
4387
|
v();
|
|
4385
4388
|
return;
|
|
4386
4389
|
}
|
|
@@ -4389,21 +4392,21 @@ function Vi({
|
|
|
4389
4392
|
}, [
|
|
4390
4393
|
oe,
|
|
4391
4394
|
G,
|
|
4392
|
-
|
|
4395
|
+
r,
|
|
4393
4396
|
Re,
|
|
4394
4397
|
p,
|
|
4395
4398
|
f,
|
|
4396
4399
|
o,
|
|
4397
4400
|
ve
|
|
4398
4401
|
]);
|
|
4399
|
-
const ze =
|
|
4402
|
+
const ze = qr(
|
|
4400
4403
|
t.agent.presentation,
|
|
4401
4404
|
e.presentation
|
|
4402
|
-
), it = ze == null ? void 0 : ze.toolActivity, ot = ze == null ? void 0 : ze.reasoning,
|
|
4405
|
+
), it = ze == null ? void 0 : ze.toolActivity, ot = ze == null ? void 0 : ze.reasoning, Pr = X(() => {
|
|
4403
4406
|
if (!Ke || me === null || m === "submitted" || !oe && !G)
|
|
4404
4407
|
return [];
|
|
4405
4408
|
const v = f.at(-1);
|
|
4406
|
-
return !v || v.role !== "assistant" ? [] :
|
|
4409
|
+
return !v || v.role !== "assistant" ? [] : hn(pt(v.parts), {
|
|
4407
4410
|
toolActivity: it,
|
|
4408
4411
|
reasoning: ot
|
|
4409
4412
|
});
|
|
@@ -4416,47 +4419,47 @@ function Vi({
|
|
|
4416
4419
|
ot,
|
|
4417
4420
|
Ke,
|
|
4418
4421
|
me
|
|
4419
|
-
]),
|
|
4422
|
+
]), Or = X(
|
|
4420
4423
|
() => Ke ? Ee.flatMap((v) => {
|
|
4421
|
-
const E =
|
|
4424
|
+
const E = hn(v.items, {
|
|
4422
4425
|
toolActivity: it,
|
|
4423
4426
|
reasoning: ot
|
|
4424
4427
|
});
|
|
4425
4428
|
return E.length === 0 ? [] : [E === v.items ? v : { ...v, items: E }];
|
|
4426
4429
|
}) : [],
|
|
4427
4430
|
[Ee, it, ot, Ke]
|
|
4428
|
-
),
|
|
4429
|
-
() =>
|
|
4431
|
+
), Nr = X(
|
|
4432
|
+
() => k.current.items.filter((v) => !v.input.background).map((v) => v.userMessage),
|
|
4430
4433
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- queueRef is mutable; queueVersion is the signal
|
|
4431
4434
|
[ve]
|
|
4432
4435
|
);
|
|
4433
4436
|
return {
|
|
4434
4437
|
isStreaming: oe,
|
|
4435
|
-
liveItems:
|
|
4438
|
+
liveItems: Pr,
|
|
4436
4439
|
/** Finished turns' render sources — see `TurnRenderSource`. */
|
|
4437
|
-
turnSources:
|
|
4440
|
+
turnSources: Or,
|
|
4438
4441
|
/** The live turn's node key (stable through the retained promotion). */
|
|
4439
4442
|
liveTurnKey: me,
|
|
4440
4443
|
/** The last turn failed — the transcript renders a visible error row. */
|
|
4441
4444
|
turnFailed: N !== void 0,
|
|
4442
|
-
retryFailedTurn:
|
|
4445
|
+
retryFailedTurn: wr,
|
|
4443
4446
|
resumeInterruptedTurn: _t,
|
|
4444
|
-
queuedUserMessages:
|
|
4445
|
-
removeQueued:
|
|
4446
|
-
stop:
|
|
4447
|
-
pageEffects:
|
|
4447
|
+
queuedUserMessages: Nr,
|
|
4448
|
+
removeQueued: Ar,
|
|
4449
|
+
stop: xr,
|
|
4450
|
+
pageEffects: Mr,
|
|
4448
4451
|
replyToPageCall: xt,
|
|
4449
|
-
pendingPageAction:
|
|
4450
|
-
requestPageActionConsent:
|
|
4452
|
+
pendingPageAction: _r,
|
|
4453
|
+
requestPageActionConsent: Rr,
|
|
4451
4454
|
resolvePageAction: Mt,
|
|
4452
4455
|
handledConnectionRequestIds: ie,
|
|
4453
|
-
sourceSessionId: Ke ?
|
|
4456
|
+
sourceSessionId: Ke ? n : null
|
|
4454
4457
|
};
|
|
4455
4458
|
}
|
|
4456
4459
|
function Bi(t) {
|
|
4457
4460
|
return t ? { ...t, initialMessages: [] } : null;
|
|
4458
4461
|
}
|
|
4459
|
-
const
|
|
4462
|
+
const wn = 2e3, An = 6e5, Wi = 1e4, bt = He(null), Ji = (t, e) => e === "dismiss" ? {
|
|
4460
4463
|
content: `Continue without connecting ${t.name}.`,
|
|
4461
4464
|
connectionRequestId: t.request_id
|
|
4462
4465
|
} : e === "renew" ? {
|
|
@@ -4475,20 +4478,20 @@ const Cr = 2e3, wr = 6e5, Wi = 1e4, bt = He(null), Ji = (t, e) => e === "dismiss
|
|
|
4475
4478
|
function Hi({
|
|
4476
4479
|
children: t,
|
|
4477
4480
|
request: e,
|
|
4478
|
-
widgetCtx:
|
|
4479
|
-
onHandled:
|
|
4481
|
+
widgetCtx: n,
|
|
4482
|
+
onHandled: r
|
|
4480
4483
|
}) {
|
|
4481
4484
|
const [s, o] = J("idle"), [l, u] = J(null), [y, g] = J(
|
|
4482
4485
|
null
|
|
4483
|
-
), [i, d] = J(null), p = R(new AbortController()), b = R(null), P = R(/* @__PURE__ */ new Set()), M = R(null), O = R(null), x = R(null),
|
|
4486
|
+
), [i, d] = J(null), p = R(new AbortController()), b = R(null), P = R(/* @__PURE__ */ new Set()), M = R(null), O = R(null), x = R(null), C = R(!0), I = R((e == null ? void 0 : e.request_id) ?? null);
|
|
4484
4487
|
I.current = (e == null ? void 0 : e.request_id) ?? null;
|
|
4485
|
-
const
|
|
4488
|
+
const w = z(() => {
|
|
4486
4489
|
var D;
|
|
4487
4490
|
p.current.abort(), (D = b.current) == null || D.close(), b.current = null;
|
|
4488
4491
|
}, []);
|
|
4489
|
-
F(() => (
|
|
4490
|
-
|
|
4491
|
-
}), [
|
|
4492
|
+
F(() => (w(), x.current = null, O.current = null, M.current = null, o("idle"), u(null), g(null), d(null), w), [w, e == null ? void 0 : e.request_id, e == null ? void 0 : e.server_id, n]), F(() => (C.current = !0, () => {
|
|
4493
|
+
C.current = !1, w();
|
|
4494
|
+
}), [w]);
|
|
4492
4495
|
const c = z(
|
|
4493
4496
|
async (D) => {
|
|
4494
4497
|
if (!e) return;
|
|
@@ -4497,65 +4500,65 @@ function Hi({
|
|
|
4497
4500
|
P.current.add(B), M.current = D, g(D), d(null);
|
|
4498
4501
|
let W = !1;
|
|
4499
4502
|
try {
|
|
4500
|
-
await
|
|
4503
|
+
await n.messageCtx.sendMessage({
|
|
4501
4504
|
...Ji(e, D),
|
|
4502
4505
|
onAccepted: () => {
|
|
4503
|
-
W = !0,
|
|
4506
|
+
W = !0, r(e.request_id);
|
|
4504
4507
|
}
|
|
4505
|
-
}),
|
|
4508
|
+
}), C.current && I.current === B && !W && d(
|
|
4506
4509
|
D === "renew" ? "Could not request a new connection. Try again." : "Could not continue your request. Try again."
|
|
4507
4510
|
);
|
|
4508
4511
|
} catch {
|
|
4509
|
-
|
|
4512
|
+
C.current && I.current === B && d(
|
|
4510
4513
|
D === "renew" ? "Could not request a new connection. Try again." : "Could not continue your request. Try again."
|
|
4511
4514
|
);
|
|
4512
4515
|
} finally {
|
|
4513
|
-
P.current.delete(B),
|
|
4516
|
+
P.current.delete(B), C.current && I.current === B && g(null);
|
|
4514
4517
|
}
|
|
4515
4518
|
},
|
|
4516
|
-
[
|
|
4519
|
+
[r, e, n]
|
|
4517
4520
|
), m = z(async () => {
|
|
4518
4521
|
var B, W;
|
|
4519
4522
|
if (!e) return;
|
|
4520
|
-
|
|
4523
|
+
w(), x.current = e.request_id, p.current = new AbortController();
|
|
4521
4524
|
const { signal: D } = p.current;
|
|
4522
4525
|
o("loading"), M.current = null, u(null), d(null);
|
|
4523
4526
|
try {
|
|
4524
4527
|
b.current = window.open("about:blank", "_blank"), b.current && (b.current.opener = null);
|
|
4525
|
-
const
|
|
4528
|
+
const k = await n.api.startConnection(
|
|
4526
4529
|
e.server_id,
|
|
4527
4530
|
e.request_id,
|
|
4528
4531
|
D
|
|
4529
4532
|
);
|
|
4530
4533
|
if (D.aborted) return;
|
|
4531
|
-
const $ = new URL(
|
|
4534
|
+
const $ = new URL(k.authorization_url);
|
|
4532
4535
|
if (!($.protocol === "https:" || $.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes($.hostname)) || $.username || $.password)
|
|
4533
4536
|
throw new Error("Invalid connection page");
|
|
4534
4537
|
u({
|
|
4535
4538
|
url: $.href,
|
|
4536
4539
|
host: $.host,
|
|
4537
|
-
completion:
|
|
4538
|
-
...
|
|
4539
|
-
}), O.current = Date.now() +
|
|
4540
|
-
} catch (
|
|
4540
|
+
completion: k.completion,
|
|
4541
|
+
...k.completion === "oauth" ? { attemptId: k.attempt_id } : {}
|
|
4542
|
+
}), O.current = Date.now() + An, (B = b.current) != null && B.closed ? (b.current = null, o("ready")) : b.current ? (b.current.location.replace($.href), o("waiting")) : o("ready");
|
|
4543
|
+
} catch (k) {
|
|
4541
4544
|
if (D.aborted) return;
|
|
4542
|
-
if ((W = b.current) == null || W.close(), b.current = null, u(null), o("idle"),
|
|
4545
|
+
if ((W = b.current) == null || W.close(), b.current = null, u(null), o("idle"), k instanceof zr) {
|
|
4543
4546
|
await c("renew");
|
|
4544
4547
|
return;
|
|
4545
4548
|
}
|
|
4546
4549
|
d(
|
|
4547
|
-
|
|
4550
|
+
k instanceof Error ? k.message : "Could not start the connection."
|
|
4548
4551
|
);
|
|
4549
4552
|
}
|
|
4550
|
-
}, [
|
|
4553
|
+
}, [w, e, c, n]);
|
|
4551
4554
|
F(() => {
|
|
4552
4555
|
if (s !== "waiting" && s !== "ready" || !l || !e)
|
|
4553
4556
|
return;
|
|
4554
4557
|
const D = new AbortController();
|
|
4555
4558
|
let B;
|
|
4556
|
-
const W = O.current ?? Date.now() +
|
|
4559
|
+
const W = O.current ?? Date.now() + An;
|
|
4557
4560
|
O.current = W;
|
|
4558
|
-
let
|
|
4561
|
+
let k = 0, $ = document.hidden || !document.hasFocus(), Se = !1;
|
|
4559
4562
|
const Ie = () => {
|
|
4560
4563
|
$ = !0;
|
|
4561
4564
|
}, ve = () => {
|
|
@@ -4568,7 +4571,7 @@ function Hi({
|
|
|
4568
4571
|
}, de = setTimeout(
|
|
4569
4572
|
() => G("Connection timed out. Try again."),
|
|
4570
4573
|
Math.max(0, W - Date.now())
|
|
4571
|
-
), fe = (U =
|
|
4574
|
+
), fe = (U = wn) => {
|
|
4572
4575
|
B = setTimeout(Ee, U);
|
|
4573
4576
|
}, Ee = async () => {
|
|
4574
4577
|
var U, ie, Ce;
|
|
@@ -4589,13 +4592,13 @@ function Hi({
|
|
|
4589
4592
|
return;
|
|
4590
4593
|
}
|
|
4591
4594
|
try {
|
|
4592
|
-
const me = await
|
|
4595
|
+
const me = await n.api.getConnectionAttempt(
|
|
4593
4596
|
e.server_id,
|
|
4594
4597
|
l.attemptId,
|
|
4595
4598
|
D.signal
|
|
4596
4599
|
);
|
|
4597
4600
|
if (D.signal.aborted) return;
|
|
4598
|
-
if (
|
|
4601
|
+
if (k = 0, me === "connected") {
|
|
4599
4602
|
(ie = b.current) == null || ie.close(), b.current = null, o("connected");
|
|
4600
4603
|
return;
|
|
4601
4604
|
}
|
|
@@ -4614,13 +4617,13 @@ function Hi({
|
|
|
4614
4617
|
(Ce = b.current) != null && Ce.closed && (b.current = null, o("ready")), fe();
|
|
4615
4618
|
} catch (me) {
|
|
4616
4619
|
if (D.signal.aborted) return;
|
|
4617
|
-
if (me instanceof
|
|
4620
|
+
if (me instanceof Zr) {
|
|
4618
4621
|
G(me.message);
|
|
4619
4622
|
return;
|
|
4620
4623
|
}
|
|
4621
|
-
|
|
4624
|
+
k += 1, fe(
|
|
4622
4625
|
Math.min(
|
|
4623
|
-
|
|
4626
|
+
wn * 2 ** (k - 1),
|
|
4624
4627
|
Wi
|
|
4625
4628
|
)
|
|
4626
4629
|
);
|
|
@@ -4629,12 +4632,12 @@ function Hi({
|
|
|
4629
4632
|
return Ee(), () => {
|
|
4630
4633
|
D.abort(), B && clearTimeout(B), de && clearTimeout(de), window.removeEventListener("blur", Ie), window.removeEventListener("focus", ve), document.removeEventListener("visibilitychange", ae);
|
|
4631
4634
|
};
|
|
4632
|
-
}, [l, s, e,
|
|
4635
|
+
}, [l, s, e, n]), F(() => {
|
|
4633
4636
|
s !== "connected" && s !== "external" || x.current !== (e == null ? void 0 : e.request_id) || c(s === "external" ? "external" : "resume");
|
|
4634
4637
|
}, [s, e == null ? void 0 : e.request_id, c]);
|
|
4635
4638
|
const f = z(() => o("waiting"), []), h = z(async () => {
|
|
4636
|
-
|
|
4637
|
-
}, [
|
|
4639
|
+
w(), u(null), o("idle"), await c("dismiss");
|
|
4640
|
+
}, [w, c]), S = z(async () => {
|
|
4638
4641
|
const D = M.current;
|
|
4639
4642
|
if (D) {
|
|
4640
4643
|
await c(D);
|
|
@@ -4719,16 +4722,16 @@ const Bt = {
|
|
|
4719
4722
|
pendingClarification: null,
|
|
4720
4723
|
pendingConnection: null
|
|
4721
4724
|
}, St = He(null);
|
|
4722
|
-
function
|
|
4725
|
+
function pr() {
|
|
4723
4726
|
return Fe(St) ?? Bt;
|
|
4724
4727
|
}
|
|
4725
4728
|
function Gi({
|
|
4726
4729
|
children: t,
|
|
4727
4730
|
widgetCtx: e,
|
|
4728
|
-
config:
|
|
4731
|
+
config: n
|
|
4729
4732
|
}) {
|
|
4730
4733
|
var ve, ae, G, de, fe, Ee;
|
|
4731
|
-
const
|
|
4734
|
+
const r = K(e.sessionCtx.sessionState), s = K(e.messageCtx.state), {
|
|
4732
4735
|
isStreaming: o,
|
|
4733
4736
|
liveItems: l,
|
|
4734
4737
|
turnSources: u,
|
|
@@ -4742,17 +4745,17 @@ function Gi({
|
|
|
4742
4745
|
pageEffects: M,
|
|
4743
4746
|
replyToPageCall: O,
|
|
4744
4747
|
pendingPageAction: x,
|
|
4745
|
-
requestPageActionConsent:
|
|
4748
|
+
requestPageActionConsent: C,
|
|
4746
4749
|
resolvePageAction: I,
|
|
4747
|
-
handledConnectionRequestIds:
|
|
4750
|
+
handledConnectionRequestIds: w,
|
|
4748
4751
|
sourceSessionId: c
|
|
4749
4752
|
} = Vi({
|
|
4750
4753
|
widgetCtx: e,
|
|
4751
|
-
config:
|
|
4752
|
-
sessionId: ((ve =
|
|
4754
|
+
config: n,
|
|
4755
|
+
sessionId: ((ve = r.session) == null ? void 0 : ve.id) ?? null,
|
|
4753
4756
|
persistedMessages: s.messages
|
|
4754
|
-
}), m = ((ae = s.messages.at(-1)) == null ? void 0 : ae.type) === "USER", f = R(/* @__PURE__ */ new Set()), h = R(((G =
|
|
4755
|
-
h.current !== S && (h.current = S, f.current.clear()),
|
|
4757
|
+
}), m = ((ae = s.messages.at(-1)) == null ? void 0 : ae.type) === "USER", f = R(/* @__PURE__ */ new Set()), h = R(((G = r.session) == null ? void 0 : G.id) ?? null), S = ((de = r.session) == null ? void 0 : de.id) ?? null;
|
|
4758
|
+
h.current !== S && (h.current = S, f.current.clear()), w.forEach(
|
|
4756
4759
|
(U) => f.current.add(U)
|
|
4757
4760
|
);
|
|
4758
4761
|
const N = (fe = [
|
|
@@ -4760,7 +4763,7 @@ function Gi({
|
|
|
4760
4763
|
...l
|
|
4761
4764
|
].findLast(
|
|
4762
4765
|
(U) => U.kind === "connection" && !f.current.has(U.request.request_id)
|
|
4763
|
-
)) == null ? void 0 : fe.request, [D, B] = J({ sessionId: S, request: null }), W = ((Ee =
|
|
4766
|
+
)) == null ? void 0 : fe.request, [D, B] = J({ sessionId: S, request: null }), W = ((Ee = n.capabilities) == null ? void 0 : Ee.connections) === !0, k = W && S !== null && D.sessionId === S ? D.request : null;
|
|
4764
4767
|
F(() => {
|
|
4765
4768
|
!W || S === null || c !== S || B((U) => {
|
|
4766
4769
|
const ie = U.sessionId === S && U.request && !f.current.has(U.request.request_id) ? U.request : N ?? null;
|
|
@@ -4770,9 +4773,9 @@ function Gi({
|
|
|
4770
4773
|
S,
|
|
4771
4774
|
c,
|
|
4772
4775
|
N,
|
|
4773
|
-
|
|
4776
|
+
w,
|
|
4774
4777
|
W,
|
|
4775
|
-
|
|
4778
|
+
k
|
|
4776
4779
|
]);
|
|
4777
4780
|
const $ = z((U) => {
|
|
4778
4781
|
f.current.add(U), B(
|
|
@@ -4796,9 +4799,9 @@ function Gi({
|
|
|
4796
4799
|
pageEffects: M,
|
|
4797
4800
|
replyToPageCall: O,
|
|
4798
4801
|
pendingPageAction: x,
|
|
4799
|
-
requestPageActionConsent:
|
|
4802
|
+
requestPageActionConsent: C,
|
|
4800
4803
|
resolvePageAction: I,
|
|
4801
|
-
pendingConnection:
|
|
4804
|
+
pendingConnection: k,
|
|
4802
4805
|
pendingClarification: ms({
|
|
4803
4806
|
turnSources: u,
|
|
4804
4807
|
liveItems: l,
|
|
@@ -4820,103 +4823,103 @@ function Gi({
|
|
|
4820
4823
|
M,
|
|
4821
4824
|
O,
|
|
4822
4825
|
x,
|
|
4823
|
-
|
|
4826
|
+
C,
|
|
4824
4827
|
I,
|
|
4825
4828
|
m,
|
|
4826
|
-
|
|
4829
|
+
k
|
|
4827
4830
|
]
|
|
4828
4831
|
), Ie = /* @__PURE__ */ H.createElement(St.Provider, { value: Se }, t);
|
|
4829
4832
|
return /* @__PURE__ */ H.createElement(
|
|
4830
4833
|
Hi,
|
|
4831
4834
|
{
|
|
4832
|
-
request:
|
|
4835
|
+
request: k,
|
|
4833
4836
|
widgetCtx: e,
|
|
4834
4837
|
onHandled: $
|
|
4835
4838
|
},
|
|
4836
4839
|
Ie
|
|
4837
4840
|
);
|
|
4838
4841
|
}
|
|
4839
|
-
function
|
|
4842
|
+
function fr({
|
|
4840
4843
|
children: t,
|
|
4841
4844
|
widgetCtx: e,
|
|
4842
|
-
config:
|
|
4845
|
+
config: n
|
|
4843
4846
|
}) {
|
|
4844
|
-
return K(e.messageCtx.state), e.streaming ? /* @__PURE__ */ H.createElement(Gi, { widgetCtx: e, config:
|
|
4847
|
+
return K(e.messageCtx.state), e.streaming ? /* @__PURE__ */ H.createElement(Gi, { widgetCtx: e, config: n }, t) : /* @__PURE__ */ H.createElement(St.Provider, { value: Bt }, t);
|
|
4845
4848
|
}
|
|
4846
4849
|
class Qi {
|
|
4847
4850
|
constructor(e) {
|
|
4848
4851
|
this.root = e, this.nextId = 1, this.mountVersion = 0, this.disposed = !1, this.mount = () => {
|
|
4849
|
-
const
|
|
4852
|
+
const r = ++this.mountVersion;
|
|
4850
4853
|
this.root.routerCtx.navigateConversation = this.open;
|
|
4851
4854
|
const s = this.state.get().chats.find((o) => o.id === this.state.get().activeId);
|
|
4852
4855
|
return s.ctx === this.root ? this.root.sessionCtx.restoreActiveSessionTracking() : this.root.sessionCtx.trackActiveSession(s.ctx.sessionCtx), () => {
|
|
4853
4856
|
queueMicrotask(() => {
|
|
4854
|
-
this.mountVersion ===
|
|
4857
|
+
this.mountVersion === r && this.dispose();
|
|
4855
4858
|
});
|
|
4856
4859
|
};
|
|
4857
4860
|
}, this.dispose = () => {
|
|
4858
4861
|
if (!this.disposed) {
|
|
4859
4862
|
this.disposed = !0, this.root.routerCtx.navigateConversation === this.open && (this.root.routerCtx.navigateConversation = void 0, this.root.sessionCtx.restoreActiveSessionTracking());
|
|
4860
|
-
for (const
|
|
4861
|
-
|
|
4863
|
+
for (const r of this.state.get().chats)
|
|
4864
|
+
r.ctx !== this.root && r.ctx.releaseConversation();
|
|
4862
4865
|
this.state.set({ chats: [], activeId: 0 });
|
|
4863
4866
|
}
|
|
4864
|
-
}, this.select = (
|
|
4867
|
+
}, this.select = (r) => {
|
|
4865
4868
|
if (this.disposed) return;
|
|
4866
|
-
const s = this.state.get().chats.find((o) => o.id ===
|
|
4869
|
+
const s = this.state.get().chats.find((o) => o.id === r);
|
|
4867
4870
|
s && (s.ctx.routerCtx.navigateConversation = this.open, s.ctx.routerCtx.state.setPartial({
|
|
4868
4871
|
screen: s.ctx.contactCtx.shouldCollectData() ? "welcome" : "chat"
|
|
4869
4872
|
}), this.root.sessionCtx.trackActiveSession(s.ctx.sessionCtx), this.state.setPartial({
|
|
4870
|
-
activeId:
|
|
4873
|
+
activeId: r,
|
|
4871
4874
|
chats: this.state.get().chats.map(
|
|
4872
|
-
(o) => o.id ===
|
|
4875
|
+
(o) => o.id === r ? { ...o, closed: !1 } : o
|
|
4873
4876
|
)
|
|
4874
4877
|
}));
|
|
4875
|
-
}, this.close = (
|
|
4878
|
+
}, this.close = (r) => {
|
|
4876
4879
|
if (this.disposed) return;
|
|
4877
|
-
const { chats: s, activeId: o } = this.state.get(), l = s.findIndex((d) => d.id ===
|
|
4880
|
+
const { chats: s, activeId: o } = this.state.get(), l = s.findIndex((d) => d.id === r && !d.closed), u = s[l];
|
|
4878
4881
|
if (!u) return;
|
|
4879
|
-
const y = this.isWorking(u), g = y ? s.map((d) => d.id ===
|
|
4882
|
+
const y = this.isWorking(u), g = y ? s.map((d) => d.id === r ? { ...d, closed: !0 } : d) : s.filter((d) => d.id !== r);
|
|
4880
4883
|
let i = g.find((d) => d.id === o && !d.closed) ?? g.slice(0, l).reverse().find((d) => !d.closed) ?? g.find((d) => !d.closed);
|
|
4881
4884
|
i || (i = this.makeChat(this.root.createConversation()), g.push(i)), i.ctx.routerCtx.navigateConversation = this.open, this.root.sessionCtx.trackActiveSession(i.ctx.sessionCtx), this.state.set({ chats: g, activeId: i.id }), y || this.releaseChat(u);
|
|
4882
|
-
}, this.canCreateChat = () => !this.disposed && (!this.root.config.oneOpenSessionAllowed || !this.state.get().chats.some(({ ctx:
|
|
4883
|
-
const { session: s, isCreatingSession: o } =
|
|
4885
|
+
}, this.canCreateChat = () => !this.disposed && (!this.root.config.oneOpenSessionAllowed || !this.state.get().chats.some(({ ctx: r }) => {
|
|
4886
|
+
const { session: s, isCreatingSession: o } = r.sessionCtx.sessionState.get();
|
|
4884
4887
|
return (s == null ? void 0 : s.isOpened) || o;
|
|
4885
|
-
}) && !this.root.sessionCtx.sessionsState.get().data.some((
|
|
4888
|
+
}) && !this.root.sessionCtx.sessionsState.get().data.some((r) => r.isOpened)), this.open = (r) => {
|
|
4886
4889
|
var y, g, i, d;
|
|
4887
4890
|
if (this.disposed) return;
|
|
4888
4891
|
const { chats: s } = this.state.get();
|
|
4889
|
-
if (!
|
|
4890
|
-
const o =
|
|
4892
|
+
if (!r && !this.canCreateChat()) return;
|
|
4893
|
+
const o = r ? s.find(
|
|
4891
4894
|
({ ctx: p }) => {
|
|
4892
4895
|
var b;
|
|
4893
|
-
return ((b = p.sessionCtx.sessionState.get().session) == null ? void 0 : b.id) ===
|
|
4896
|
+
return ((b = p.sessionCtx.sessionState.get().session) == null ? void 0 : b.id) === r;
|
|
4894
4897
|
}
|
|
4895
4898
|
) : s.find((p) => this.isEmpty(p));
|
|
4896
4899
|
if (o)
|
|
4897
4900
|
return this.select(o.id), (g = (y = this.root.config.hooks) == null ? void 0 : y.onNavigateToChat) == null || g.call(y, {
|
|
4898
4901
|
session: o.ctx.sessionCtx.sessionState.get().session ?? void 0
|
|
4899
4902
|
}), o.ctx;
|
|
4900
|
-
const l =
|
|
4901
|
-
if (
|
|
4903
|
+
const l = r ? this.root.sessionCtx.sessionsState.get().data.find((p) => p.id === r) : void 0;
|
|
4904
|
+
if (r && !l) return;
|
|
4902
4905
|
const u = s.find((p) => this.isEmpty(p)) ?? this.makeChat(this.root.createConversation());
|
|
4903
4906
|
return l && (s.includes(u) && u.ctx.resetChat(), u.ctx.sessionCtx.sessionState.setPartial({ session: l })), s.includes(u) || this.state.setPartial({ chats: [...s, u] }), this.select(u.id), (d = (i = this.root.config.hooks) == null ? void 0 : i.onNavigateToChat) == null || d.call(i, { session: l }), u.ctx;
|
|
4904
|
-
}, this.update = (
|
|
4905
|
-
const o = this.state.get().chats.find((u) => u.id ===
|
|
4907
|
+
}, this.update = (r, s) => {
|
|
4908
|
+
const o = this.state.get().chats.find((u) => u.id === r);
|
|
4906
4909
|
if (!o) return;
|
|
4907
4910
|
const l = { ...o, ...s };
|
|
4908
4911
|
if (l.closed && !this.isWorking(l)) {
|
|
4909
4912
|
this.state.setPartial({
|
|
4910
|
-
chats: this.state.get().chats.filter((u) => u.id !==
|
|
4913
|
+
chats: this.state.get().chats.filter((u) => u.id !== r)
|
|
4911
4914
|
}), this.releaseChat(l);
|
|
4912
4915
|
return;
|
|
4913
4916
|
}
|
|
4914
4917
|
l.title === o.title && l.working === o.working && l.hasSession === o.hasSession && l.hasDraft === o.hasDraft && l.ui === o.ui && l.connection === o.connection || this.state.setPartial({
|
|
4915
|
-
chats: this.state.get().chats.map((u) => u.id ===
|
|
4918
|
+
chats: this.state.get().chats.map((u) => u.id === r ? { ...u, ...s } : u)
|
|
4916
4919
|
});
|
|
4917
4920
|
};
|
|
4918
|
-
const
|
|
4919
|
-
this.state = new
|
|
4921
|
+
const n = this.makeChat(e);
|
|
4922
|
+
this.state = new Rn({ chats: [n], activeId: n.id });
|
|
4920
4923
|
}
|
|
4921
4924
|
makeChat(e) {
|
|
4922
4925
|
return {
|
|
@@ -4937,19 +4940,19 @@ class Qi {
|
|
|
4937
4940
|
return e.ui.isStreaming || e.ctx.messageCtx.state.get().isSendingMessage || e.ctx.sessionCtx.sessionState.get().isCreatingSession;
|
|
4938
4941
|
}
|
|
4939
4942
|
isEmpty(e) {
|
|
4940
|
-
const { session:
|
|
4941
|
-
return !e.closed && !
|
|
4943
|
+
const { session: n } = e.ctx.sessionCtx.sessionState.get(), { text: r, mentions: s } = e.ctx.messageCtx.draftState.get();
|
|
4944
|
+
return !e.closed && !n && !this.isWorking(e) && !e.ctx.messageCtx.state.get().messages.length && !r && !s.length && !e.ctx.uploadCtx.state.get().length;
|
|
4942
4945
|
}
|
|
4943
4946
|
}
|
|
4944
|
-
const
|
|
4945
|
-
function
|
|
4946
|
-
const t = Fe(
|
|
4947
|
+
const mr = He(null), Xi = new Rn({ chats: [], activeId: 0 });
|
|
4948
|
+
function gr() {
|
|
4949
|
+
const t = Fe(mr), e = K((t == null ? void 0 : t.state) ?? Xi), n = e.chats.filter((s) => !s.closed), r = n.filter(
|
|
4947
4950
|
(s) => s.hasSession || s.working || s.hasDraft || s.title
|
|
4948
4951
|
);
|
|
4949
|
-
return { workspace: t, chats:
|
|
4952
|
+
return { workspace: t, chats: n, openChats: r, activeId: e.activeId };
|
|
4950
4953
|
}
|
|
4951
4954
|
function Mo() {
|
|
4952
|
-
const { workspace: t, ...e } =
|
|
4955
|
+
const { workspace: t, ...e } = gr();
|
|
4953
4956
|
if (!t)
|
|
4954
4957
|
throw new Error("Companion chats require a conversation workspace");
|
|
4955
4958
|
return {
|
|
@@ -4962,42 +4965,42 @@ function Mo() {
|
|
|
4962
4965
|
function eo({
|
|
4963
4966
|
chatId: t,
|
|
4964
4967
|
ctx: e,
|
|
4965
|
-
workspace:
|
|
4968
|
+
workspace: n
|
|
4966
4969
|
}) {
|
|
4967
|
-
const
|
|
4970
|
+
const r = pr(), s = Ki(), o = K(e.messageCtx.state), l = K(e.sessionCtx.sessionState), u = K(e.messageCtx.draftState), y = K(e.uploadCtx.state), g = o.messages.find(
|
|
4968
4971
|
(P) => P.type === "USER"
|
|
4969
|
-
), i = (g == null ? void 0 : g.type) === "USER" ? g.content.slice(0, 60) : "", d =
|
|
4972
|
+
), i = (g == null ? void 0 : g.type) === "USER" ? g.content.slice(0, 60) : "", d = r.isStreaming || o.isSendingMessage || l.isCreatingSession, p = !!l.session, b = !!u.text || u.mentions.length > 0 || y.length > 0;
|
|
4970
4973
|
return F(
|
|
4971
|
-
() =>
|
|
4974
|
+
() => n.update(t, {
|
|
4972
4975
|
title: i,
|
|
4973
4976
|
working: d,
|
|
4974
4977
|
hasSession: p,
|
|
4975
4978
|
hasDraft: b,
|
|
4976
|
-
ui:
|
|
4979
|
+
ui: r,
|
|
4977
4980
|
connection: s
|
|
4978
4981
|
}),
|
|
4979
|
-
[
|
|
4982
|
+
[n, t, i, d, p, b, r, s]
|
|
4980
4983
|
), null;
|
|
4981
4984
|
}
|
|
4982
|
-
const to =
|
|
4985
|
+
const to = kr(function({
|
|
4983
4986
|
chatId: e,
|
|
4984
|
-
ctx:
|
|
4985
|
-
config:
|
|
4987
|
+
ctx: n,
|
|
4988
|
+
config: r,
|
|
4986
4989
|
workspace: s
|
|
4987
4990
|
}) {
|
|
4988
|
-
return /* @__PURE__ */ H.createElement(
|
|
4991
|
+
return /* @__PURE__ */ H.createElement(fr, { widgetCtx: n, config: r }, /* @__PURE__ */ H.createElement(eo, { chatId: e, ctx: n, workspace: s }));
|
|
4989
4992
|
});
|
|
4990
|
-
function
|
|
4993
|
+
function no({
|
|
4991
4994
|
widgetCtx: t,
|
|
4992
4995
|
config: e = t.config,
|
|
4993
|
-
children:
|
|
4996
|
+
children: n
|
|
4994
4997
|
}) {
|
|
4995
|
-
const
|
|
4998
|
+
const r = X(
|
|
4996
4999
|
() => new Qi(t),
|
|
4997
5000
|
[t]
|
|
4998
5001
|
);
|
|
4999
|
-
F(() =>
|
|
5000
|
-
const { chats: s, activeId: o } = K(
|
|
5002
|
+
F(() => r.mount(), [r]);
|
|
5003
|
+
const { chats: s, activeId: o } = K(r.state), l = s.find((y) => y.id === o), u = X(
|
|
5001
5004
|
() => s.map((y) => /* @__PURE__ */ H.createElement(
|
|
5002
5005
|
to,
|
|
5003
5006
|
{
|
|
@@ -5005,40 +5008,40 @@ function ro({
|
|
|
5005
5008
|
chatId: y.id,
|
|
5006
5009
|
ctx: y.ctx,
|
|
5007
5010
|
config: e,
|
|
5008
|
-
workspace:
|
|
5011
|
+
workspace: r
|
|
5009
5012
|
}
|
|
5010
5013
|
)),
|
|
5011
|
-
[s, e,
|
|
5014
|
+
[s, e, r]
|
|
5012
5015
|
);
|
|
5013
|
-
return /* @__PURE__ */ H.createElement(
|
|
5016
|
+
return /* @__PURE__ */ H.createElement(mr.Provider, { value: r }, u, /* @__PURE__ */ H.createElement(Yi, { connection: l.connection }, /* @__PURE__ */ H.createElement(St.Provider, { value: l.ui }, n(l.ctx))));
|
|
5014
5017
|
}
|
|
5015
|
-
class
|
|
5018
|
+
class ro {
|
|
5016
5019
|
constructor(e) {
|
|
5017
5020
|
this.components = [];
|
|
5018
|
-
const { components:
|
|
5019
|
-
if (
|
|
5021
|
+
const { components: n } = e;
|
|
5022
|
+
if (n && n.forEach((r) => this.register(r)), this.components.length === 0)
|
|
5020
5023
|
throw new Error("No components registered");
|
|
5021
5024
|
if (!this.get("fallback"))
|
|
5022
5025
|
throw new Error("No fallback component registered");
|
|
5023
5026
|
}
|
|
5024
5027
|
register(e) {
|
|
5025
|
-
const
|
|
5026
|
-
(
|
|
5028
|
+
const n = this.components.findIndex(
|
|
5029
|
+
(r) => r.key.toUpperCase() === e.key.toUpperCase()
|
|
5027
5030
|
);
|
|
5028
|
-
return
|
|
5031
|
+
return n !== -1 ? this.components[n] = e : this.components.push(e), this;
|
|
5029
5032
|
}
|
|
5030
5033
|
get(e) {
|
|
5031
|
-
const
|
|
5032
|
-
(
|
|
5034
|
+
const n = this.components.find(
|
|
5035
|
+
(r) => r.key.toUpperCase() === e.toUpperCase()
|
|
5033
5036
|
);
|
|
5034
|
-
return
|
|
5037
|
+
return n || null;
|
|
5035
5038
|
}
|
|
5036
5039
|
getComponent(e) {
|
|
5037
|
-
var
|
|
5038
|
-
return (
|
|
5040
|
+
var n;
|
|
5041
|
+
return (n = this.get(e)) == null ? void 0 : n.component;
|
|
5039
5042
|
}
|
|
5040
5043
|
}
|
|
5041
|
-
const
|
|
5044
|
+
const xn = L.object({
|
|
5042
5045
|
org_id: L.string(),
|
|
5043
5046
|
contact: L.object({ id: L.string(), verified: L.boolean() }),
|
|
5044
5047
|
mcp_access: L.object({
|
|
@@ -5049,16 +5052,16 @@ const Ar = L.object({
|
|
|
5049
5052
|
L.object({
|
|
5050
5053
|
sub: L.object({
|
|
5051
5054
|
type: L.literal("widget-contact"),
|
|
5052
|
-
payload:
|
|
5055
|
+
payload: xn
|
|
5053
5056
|
})
|
|
5054
5057
|
}).transform(({ sub: t }) => t.payload),
|
|
5055
|
-
|
|
5058
|
+
xn
|
|
5056
5059
|
]), ao = (t) => {
|
|
5057
5060
|
const e = t.split(".")[1];
|
|
5058
5061
|
if (!e) return null;
|
|
5059
5062
|
try {
|
|
5060
|
-
const
|
|
5061
|
-
atob(`${
|
|
5063
|
+
const n = e.replace(/-/g, "+").replace(/_/g, "/"), r = "=".repeat((4 - n.length % 4) % 4), s = Uint8Array.from(
|
|
5064
|
+
atob(`${n}${r}`),
|
|
5062
5065
|
(o) => o.charCodeAt(0)
|
|
5063
5066
|
);
|
|
5064
5067
|
return JSON.parse(new TextDecoder().decode(s));
|
|
@@ -5067,38 +5070,38 @@ const Ar = L.object({
|
|
|
5067
5070
|
}
|
|
5068
5071
|
}, io = (t) => {
|
|
5069
5072
|
var s, o;
|
|
5070
|
-
const e = t.user,
|
|
5071
|
-
if (!
|
|
5073
|
+
const e = t.user, n = e == null ? void 0 : e.token;
|
|
5074
|
+
if (!n)
|
|
5072
5075
|
return JSON.stringify({
|
|
5073
5076
|
apiUrl: t.apiUrl ?? null,
|
|
5074
5077
|
botToken: t.token,
|
|
5075
5078
|
externalId: (e == null ? void 0 : e.externalId) ?? null,
|
|
5076
5079
|
verifiedOwner: null
|
|
5077
5080
|
});
|
|
5078
|
-
const
|
|
5079
|
-
return
|
|
5081
|
+
const r = so.safeParse(ao(n));
|
|
5082
|
+
return r.success ? JSON.stringify({
|
|
5080
5083
|
apiUrl: t.apiUrl ?? null,
|
|
5081
5084
|
botToken: t.token,
|
|
5082
5085
|
externalId: e.externalId ?? null,
|
|
5083
5086
|
verifiedOwner: {
|
|
5084
|
-
orgId:
|
|
5085
|
-
contactId:
|
|
5086
|
-
verified:
|
|
5087
|
-
accountId: ((s =
|
|
5088
|
-
serverIds: [...((o =
|
|
5087
|
+
orgId: r.data.org_id,
|
|
5088
|
+
contactId: r.data.contact.id,
|
|
5089
|
+
verified: r.data.contact.verified,
|
|
5090
|
+
accountId: ((s = r.data.mcp_access) == null ? void 0 : s.account_id) ?? null,
|
|
5091
|
+
serverIds: [...((o = r.data.mcp_access) == null ? void 0 : o.server_ids) ?? []].sort()
|
|
5089
5092
|
}
|
|
5090
5093
|
}) : JSON.stringify({
|
|
5091
5094
|
apiUrl: t.apiUrl ?? null,
|
|
5092
5095
|
botToken: t.token,
|
|
5093
5096
|
externalId: e.externalId ?? null,
|
|
5094
|
-
opaqueToken:
|
|
5097
|
+
opaqueToken: n
|
|
5095
5098
|
});
|
|
5096
|
-
},
|
|
5099
|
+
}, hr = He(null);
|
|
5097
5100
|
function _o({
|
|
5098
5101
|
options: t,
|
|
5099
5102
|
children: e,
|
|
5100
|
-
components:
|
|
5101
|
-
storage:
|
|
5103
|
+
components: n,
|
|
5104
|
+
storage: r,
|
|
5102
5105
|
loadingComponent: s,
|
|
5103
5106
|
errorComponent: o
|
|
5104
5107
|
}) {
|
|
@@ -5106,14 +5109,14 @@ function _o({
|
|
|
5106
5109
|
const l = R(Promise.resolve()), u = R(t);
|
|
5107
5110
|
u.current = t;
|
|
5108
5111
|
const y = io(t), g = R(null), i = R(null), d = R(null), [p, b] = J({ status: "loading" }), P = X(
|
|
5109
|
-
() => new
|
|
5110
|
-
components:
|
|
5112
|
+
() => new ro({
|
|
5113
|
+
components: n
|
|
5111
5114
|
}),
|
|
5112
|
-
[
|
|
5115
|
+
[n]
|
|
5113
5116
|
);
|
|
5114
5117
|
if (F(() => {
|
|
5115
|
-
var
|
|
5116
|
-
if (((
|
|
5118
|
+
var w, c, m;
|
|
5119
|
+
if (((w = d.current) == null ? void 0 : w.identity) !== y) {
|
|
5117
5120
|
const f = (c = d.current) == null ? void 0 : c.widgetCtx.dispose({
|
|
5118
5121
|
clearActiveSession: !0
|
|
5119
5122
|
});
|
|
@@ -5125,19 +5128,19 @@ function _o({
|
|
|
5125
5128
|
((m = i.current) == null ? void 0 : m.identity) !== y && (b({ status: "loading" }), i.current = {
|
|
5126
5129
|
identity: y,
|
|
5127
5130
|
request: l.current.then(
|
|
5128
|
-
() =>
|
|
5131
|
+
() => Vr.initialize({
|
|
5129
5132
|
config: t,
|
|
5130
|
-
storage:
|
|
5133
|
+
storage: r,
|
|
5131
5134
|
getClientCapabilities: () => u.current.capabilities,
|
|
5132
5135
|
getRequestConfig: () => u.current
|
|
5133
5136
|
})
|
|
5134
5137
|
)
|
|
5135
5138
|
});
|
|
5136
|
-
const
|
|
5137
|
-
|
|
5139
|
+
const C = i.current.request, I = i.current.identity;
|
|
5140
|
+
C.then(
|
|
5138
5141
|
(f) => {
|
|
5139
5142
|
var h;
|
|
5140
|
-
if (((h = i.current) == null ? void 0 : h.request) !==
|
|
5143
|
+
if (((h = i.current) == null ? void 0 : h.request) !== C) {
|
|
5141
5144
|
f.dispose();
|
|
5142
5145
|
return;
|
|
5143
5146
|
}
|
|
@@ -5149,7 +5152,7 @@ function _o({
|
|
|
5149
5152
|
},
|
|
5150
5153
|
(f) => {
|
|
5151
5154
|
var S;
|
|
5152
|
-
if (((S = i.current) == null ? void 0 : S.request) !==
|
|
5155
|
+
if (((S = i.current) == null ? void 0 : S.request) !== C) return;
|
|
5153
5156
|
const h = f instanceof Error ? f : new Error("Widget initialization failed", { cause: f });
|
|
5154
5157
|
le.error("widget initialization failed", h), b({
|
|
5155
5158
|
status: "error",
|
|
@@ -5158,40 +5161,47 @@ function _o({
|
|
|
5158
5161
|
});
|
|
5159
5162
|
}
|
|
5160
5163
|
);
|
|
5161
|
-
}, [y, t,
|
|
5164
|
+
}, [y, t, r]), F(
|
|
5162
5165
|
() => () => {
|
|
5163
|
-
var
|
|
5164
|
-
i.current = null, (
|
|
5166
|
+
var C;
|
|
5167
|
+
i.current = null, (C = d.current) == null || C.widgetCtx.dispose(), d.current = null;
|
|
5165
5168
|
},
|
|
5166
5169
|
[]
|
|
5167
|
-
),
|
|
5168
|
-
var
|
|
5169
|
-
p.status !== "ready" || p.identity !== y || (
|
|
5170
|
-
}, [(x = t.user) == null ? void 0 : x.token, y, p]),
|
|
5170
|
+
), jr(() => {
|
|
5171
|
+
var C;
|
|
5172
|
+
p.status !== "ready" || p.identity !== y || (C = t.user) != null && C.token && (p.widgetCtx.api.setAuthToken(t.user.token), p.widgetCtx.tokenRenewalCtx.track(t.user.token));
|
|
5173
|
+
}, [(x = t.user) == null ? void 0 : x.token, y, p]), F(() => {
|
|
5174
|
+
if (p.status !== "ready" || typeof document > "u")
|
|
5175
|
+
return;
|
|
5176
|
+
const C = p.widgetCtx.tokenRenewalCtx, I = () => {
|
|
5177
|
+
document.visibilityState === "visible" && C.onVisible();
|
|
5178
|
+
};
|
|
5179
|
+
return document.addEventListener("visibilitychange", I), () => document.removeEventListener("visibilitychange", I);
|
|
5180
|
+
}, [p]), p.status === "loading" || "identity" in p && p.identity !== y)
|
|
5171
5181
|
return s ? /* @__PURE__ */ H.createElement(H.Fragment, null, s) : null;
|
|
5172
5182
|
if (p.status === "error")
|
|
5173
5183
|
return o ? /* @__PURE__ */ H.createElement(H.Fragment, null, o(p.error)) : null;
|
|
5174
|
-
const { widgetCtx: M } = p, O = (
|
|
5175
|
-
|
|
5184
|
+
const { widgetCtx: M } = p, O = (C, I) => /* @__PURE__ */ H.createElement(
|
|
5185
|
+
hr.Provider,
|
|
5176
5186
|
{
|
|
5177
5187
|
value: {
|
|
5178
|
-
widgetCtx:
|
|
5188
|
+
widgetCtx: C,
|
|
5179
5189
|
config: t,
|
|
5180
|
-
components:
|
|
5190
|
+
components: n,
|
|
5181
5191
|
componentStore: P,
|
|
5182
|
-
version:
|
|
5192
|
+
version: Pn,
|
|
5183
5193
|
contentIframeRef: g
|
|
5184
5194
|
}
|
|
5185
5195
|
},
|
|
5186
5196
|
I
|
|
5187
5197
|
);
|
|
5188
|
-
return t.displayMode === "companion" && !t.inline ? /* @__PURE__ */ H.createElement(
|
|
5198
|
+
return t.displayMode === "companion" && !t.inline ? /* @__PURE__ */ H.createElement(no, { widgetCtx: M, config: t }, (C) => O(C, e)) : O(
|
|
5189
5199
|
M,
|
|
5190
|
-
/* @__PURE__ */ H.createElement(
|
|
5200
|
+
/* @__PURE__ */ H.createElement(fr, { key: y, widgetCtx: M, config: t }, e)
|
|
5191
5201
|
);
|
|
5192
5202
|
}
|
|
5193
|
-
function
|
|
5194
|
-
const t = Fe(
|
|
5203
|
+
function ne() {
|
|
5204
|
+
const t = Fe(hr);
|
|
5195
5205
|
if (!t)
|
|
5196
5206
|
throw new Error("useWidget must be used within a WidgetProvider");
|
|
5197
5207
|
return t;
|
|
@@ -5200,67 +5210,71 @@ function Ro({
|
|
|
5200
5210
|
liveItems: t,
|
|
5201
5211
|
turnSources: e
|
|
5202
5212
|
}) {
|
|
5203
|
-
var
|
|
5204
|
-
const
|
|
5205
|
-
if (
|
|
5213
|
+
var r;
|
|
5214
|
+
const n = t.findLast((s) => s.kind === "plan");
|
|
5215
|
+
if (n) return n.plan;
|
|
5206
5216
|
for (let s = e.length - 1; s >= 0; s--) {
|
|
5207
|
-
const o = (
|
|
5217
|
+
const o = (r = e[s]) == null ? void 0 : r.items.findLast(
|
|
5208
5218
|
(l) => l.kind === "plan"
|
|
5209
5219
|
);
|
|
5210
5220
|
if (o) return o.plan;
|
|
5211
5221
|
}
|
|
5212
5222
|
}
|
|
5213
5223
|
function Po() {
|
|
5214
|
-
const { config: t, widgetCtx: e } =
|
|
5224
|
+
const { config: t, widgetCtx: e } = ne(), { name: n, avatarUrl: r } = e.agent, s = t.bot;
|
|
5215
5225
|
return X(
|
|
5216
5226
|
() => ({
|
|
5217
5227
|
isAi: !0,
|
|
5218
5228
|
id: null,
|
|
5219
|
-
name: (s == null ? void 0 : s.name) ??
|
|
5220
|
-
avatarUrl: (s == null ? void 0 : s.avatarUrl) ??
|
|
5229
|
+
name: (s == null ? void 0 : s.name) ?? n,
|
|
5230
|
+
avatarUrl: (s == null ? void 0 : s.avatarUrl) ?? r,
|
|
5221
5231
|
avatar: s == null ? void 0 : s.avatar
|
|
5222
5232
|
}),
|
|
5223
|
-
[s == null ? void 0 : s.name, s == null ? void 0 : s.avatarUrl, s == null ? void 0 : s.avatar,
|
|
5233
|
+
[s == null ? void 0 : s.name, s == null ? void 0 : s.avatarUrl, s == null ? void 0 : s.avatar, n, r]
|
|
5224
5234
|
);
|
|
5225
5235
|
}
|
|
5226
5236
|
function It() {
|
|
5227
|
-
const { config: t } =
|
|
5237
|
+
const { config: t } = ne();
|
|
5228
5238
|
return t;
|
|
5229
5239
|
}
|
|
5230
5240
|
function Oo() {
|
|
5231
|
-
const { config: t } =
|
|
5241
|
+
const { config: t } = ne();
|
|
5232
5242
|
return t.displayMode ?? "popover";
|
|
5233
5243
|
}
|
|
5234
5244
|
function No() {
|
|
5235
|
-
const { widgetCtx: t } =
|
|
5245
|
+
const { widgetCtx: t } = ne();
|
|
5236
5246
|
return {
|
|
5237
5247
|
contactState: K(t.contactCtx.state),
|
|
5238
5248
|
createUnverifiedContact: t.contactCtx.createUnverifiedContact
|
|
5239
5249
|
};
|
|
5240
5250
|
}
|
|
5251
|
+
function Do() {
|
|
5252
|
+
const { widgetCtx: t } = ne(), { ended: e } = K(t.tokenRenewalCtx.state);
|
|
5253
|
+
return { sessionEnded: e };
|
|
5254
|
+
}
|
|
5241
5255
|
function oo() {
|
|
5242
5256
|
const [t, e] = J("ltr");
|
|
5243
5257
|
return F(() => {
|
|
5244
|
-
const
|
|
5258
|
+
const n = () => {
|
|
5245
5259
|
typeof document > "u" || e(
|
|
5246
5260
|
window.getComputedStyle((window.top || window).document.body).direction
|
|
5247
5261
|
);
|
|
5248
5262
|
};
|
|
5249
|
-
|
|
5250
|
-
const
|
|
5251
|
-
return
|
|
5263
|
+
n();
|
|
5264
|
+
const r = new MutationObserver(n);
|
|
5265
|
+
return r.observe(document.documentElement, {
|
|
5252
5266
|
attributes: !0,
|
|
5253
5267
|
attributeFilter: ["dir"]
|
|
5254
|
-
}),
|
|
5268
|
+
}), r.observe(document.body, {
|
|
5255
5269
|
attributes: !0,
|
|
5256
5270
|
attributeFilter: ["dir"]
|
|
5257
|
-
}), window.addEventListener("languagechange",
|
|
5258
|
-
|
|
5271
|
+
}), window.addEventListener("languagechange", n), () => {
|
|
5272
|
+
r.disconnect(), window.removeEventListener("languagechange", n);
|
|
5259
5273
|
};
|
|
5260
5274
|
}, []), { dir: t };
|
|
5261
5275
|
}
|
|
5262
|
-
const lo = 500,
|
|
5263
|
-
function
|
|
5276
|
+
const lo = 500, jt = "opencx:context-changed";
|
|
5277
|
+
function yr() {
|
|
5264
5278
|
if (typeof window > "u") return null;
|
|
5265
5279
|
try {
|
|
5266
5280
|
const t = window.top ?? window;
|
|
@@ -5270,30 +5284,30 @@ function yn() {
|
|
|
5270
5284
|
}
|
|
5271
5285
|
}
|
|
5272
5286
|
function co(t) {
|
|
5273
|
-
const e =
|
|
5287
|
+
const e = yr();
|
|
5274
5288
|
if (!e) return () => {
|
|
5275
5289
|
};
|
|
5276
|
-
const
|
|
5277
|
-
(s == null ? void 0 : s.type) ===
|
|
5290
|
+
const n = (s) => {
|
|
5291
|
+
(s == null ? void 0 : s.type) === jt && (vr += 1), t();
|
|
5278
5292
|
};
|
|
5279
|
-
e.addEventListener("popstate",
|
|
5280
|
-
const
|
|
5293
|
+
e.addEventListener("popstate", n), e.addEventListener("hashchange", n), e.addEventListener(jt, n);
|
|
5294
|
+
const r = e.setInterval(n, lo);
|
|
5281
5295
|
return () => {
|
|
5282
|
-
e.removeEventListener("popstate",
|
|
5296
|
+
e.removeEventListener("popstate", n), e.removeEventListener("hashchange", n), e.removeEventListener(jt, n), e.clearInterval(r);
|
|
5283
5297
|
};
|
|
5284
5298
|
}
|
|
5285
|
-
let
|
|
5299
|
+
let vr = 0;
|
|
5286
5300
|
function uo() {
|
|
5287
5301
|
var t;
|
|
5288
|
-
return `${
|
|
5302
|
+
return `${vr}|${((t = yr()) == null ? void 0 : t.location.href) ?? ""}`;
|
|
5289
5303
|
}
|
|
5290
|
-
function
|
|
5304
|
+
function Lo() {
|
|
5291
5305
|
return zt(co, uo, () => "");
|
|
5292
5306
|
}
|
|
5293
|
-
function
|
|
5294
|
-
const { widgetCtx: t } =
|
|
5307
|
+
function br() {
|
|
5308
|
+
const { widgetCtx: t } = ne(), e = K(t.messageCtx.state), { isStreaming: n } = pr();
|
|
5295
5309
|
return {
|
|
5296
|
-
messagesState:
|
|
5310
|
+
messagesState: n ? { ...e, isSendingMessage: !0, isSendingMessageToAI: !0 } : e,
|
|
5297
5311
|
sendMessage: t.messageCtx.sendMessage,
|
|
5298
5312
|
// Composer ↑/↓ recall. Owned by MessageCtx so it is scoped to this widget
|
|
5299
5313
|
// instance and cleared with the conversation.
|
|
@@ -5301,15 +5315,15 @@ function bn() {
|
|
|
5301
5315
|
getSentTextHistory: t.messageCtx.getSentTextHistory
|
|
5302
5316
|
};
|
|
5303
5317
|
}
|
|
5304
|
-
function
|
|
5318
|
+
function Sr() {
|
|
5305
5319
|
var y;
|
|
5306
|
-
const { widgetCtx: t } =
|
|
5307
|
-
openSessions:
|
|
5308
|
-
closedSessions:
|
|
5309
|
-
}), [
|
|
5320
|
+
const { widgetCtx: t } = ne(), { oneOpenSessionAllowed: e } = It(), n = K(t.sessionCtx.sessionState), r = K(t.sessionCtx.sessionsState), { openSessions: s, closedSessions: o } = X(() => ({
|
|
5321
|
+
openSessions: r.data.filter((g) => g.isOpened === !0),
|
|
5322
|
+
closedSessions: r.data.filter((g) => g.isOpened === !1)
|
|
5323
|
+
}), [r.data]), { workspace: l } = gr(), u = l ? l.canCreateChat() : !e || s.length === 0 && !n.isCreatingSession && !((y = n.session) != null && y.isOpened);
|
|
5310
5324
|
return {
|
|
5311
|
-
sessionState:
|
|
5312
|
-
sessionsState:
|
|
5325
|
+
sessionState: n,
|
|
5326
|
+
sessionsState: r,
|
|
5313
5327
|
loadMoreSessions: t.sessionCtx.loadMoreSessions,
|
|
5314
5328
|
resolveSession: t.sessionCtx.resolveSession,
|
|
5315
5329
|
createStateCheckpoint: t.sessionCtx.createStateCheckpoint,
|
|
@@ -5318,13 +5332,13 @@ function Sn() {
|
|
|
5318
5332
|
canCreateNewSession: u
|
|
5319
5333
|
};
|
|
5320
5334
|
}
|
|
5321
|
-
function
|
|
5335
|
+
function ko() {
|
|
5322
5336
|
var l, u;
|
|
5323
|
-
const { sessionState: t } =
|
|
5324
|
-
return { isAwaitingBotReply: !!(e.isSendingMessageToAI || (
|
|
5337
|
+
const { sessionState: t } = Sr(), { messagesState: e } = br(), n = ((l = t.session) == null ? void 0 : l.assignee.kind) === "ai", r = (u = e.messages) == null ? void 0 : u.at(-1), s = (r == null ? void 0 : r.type) === "USER" && r.id !== e.settledAgentUserMessageId;
|
|
5338
|
+
return { isAwaitingBotReply: !!(e.isSendingMessageToAI || (n || t.isCreatingSession) && (e.isSendingMessage || s)) };
|
|
5325
5339
|
}
|
|
5326
5340
|
function po() {
|
|
5327
|
-
const { widgetCtx: t } =
|
|
5341
|
+
const { widgetCtx: t } = ne();
|
|
5328
5342
|
return {
|
|
5329
5343
|
routerState: K(t.routerCtx.state),
|
|
5330
5344
|
toHomeScreen: t.routerCtx.toHomeScreen,
|
|
@@ -5334,29 +5348,29 @@ function po() {
|
|
|
5334
5348
|
};
|
|
5335
5349
|
}
|
|
5336
5350
|
function jo() {
|
|
5337
|
-
const { widgetCtx: t } =
|
|
5351
|
+
const { widgetCtx: t } = ne(), { unreadSessionIds: e, count: n } = K(
|
|
5338
5352
|
t.unreadCtx.state
|
|
5339
|
-
),
|
|
5353
|
+
), r = z(
|
|
5340
5354
|
(s) => e.includes(s),
|
|
5341
5355
|
[e]
|
|
5342
5356
|
);
|
|
5343
|
-
return { count:
|
|
5357
|
+
return { count: n, hasUnread: n > 0, unreadSessionIds: e, isUnread: r };
|
|
5344
5358
|
}
|
|
5345
|
-
const
|
|
5346
|
-
function
|
|
5347
|
-
const e = It(), [
|
|
5359
|
+
const Ir = He(null);
|
|
5360
|
+
function $o({ children: t }) {
|
|
5361
|
+
const e = It(), [n, r] = J(() => e.inline ? !0 : e.isOpen ?? !1);
|
|
5348
5362
|
return F(() => {
|
|
5349
|
-
|
|
5363
|
+
r((s) => e.isOpen ?? s);
|
|
5350
5364
|
}, [e.isOpen]), F(() => {
|
|
5351
5365
|
const s = e.openAfterNSeconds;
|
|
5352
5366
|
if (typeof s != "number" || isNaN(s))
|
|
5353
5367
|
return;
|
|
5354
|
-
const o = setTimeout(() =>
|
|
5368
|
+
const o = setTimeout(() => r(!0), s * 1e3);
|
|
5355
5369
|
return () => clearTimeout(o);
|
|
5356
|
-
}, [e.openAfterNSeconds]), /* @__PURE__ */ H.createElement(
|
|
5370
|
+
}, [e.openAfterNSeconds]), /* @__PURE__ */ H.createElement(Ir.Provider, { value: { isOpen: n, setIsOpen: r } }, t);
|
|
5357
5371
|
}
|
|
5358
5372
|
function fo() {
|
|
5359
|
-
const t = Fe(
|
|
5373
|
+
const t = Fe(Ir);
|
|
5360
5374
|
if (!t)
|
|
5361
5375
|
throw new Error(
|
|
5362
5376
|
"useWidgetTrigger must be used within a WidgetTriggerProvider"
|
|
@@ -5364,16 +5378,16 @@ function fo() {
|
|
|
5364
5378
|
return t;
|
|
5365
5379
|
}
|
|
5366
5380
|
const mo = (t) => (document.addEventListener("visibilitychange", t), () => document.removeEventListener("visibilitychange", t)), go = () => document.visibilityState !== "hidden";
|
|
5367
|
-
function
|
|
5381
|
+
function Fo({
|
|
5368
5382
|
transcriptVisible: t = !0
|
|
5369
5383
|
} = {}) {
|
|
5370
|
-
const { widgetCtx: e } =
|
|
5384
|
+
const { widgetCtx: e } = ne(), { isOpen: n } = fo(), { routerState: r } = po(), { session: s } = K(e.sessionCtx.sessionState), { isInitialFetchLoading: o } = K(
|
|
5371
5385
|
e.messageCtx.state
|
|
5372
5386
|
), l = zt(
|
|
5373
5387
|
mo,
|
|
5374
5388
|
go,
|
|
5375
5389
|
() => !0
|
|
5376
|
-
), u =
|
|
5390
|
+
), u = n && l && t && r.screen === "chat" && !o ? (s == null ? void 0 : s.id) ?? null : null;
|
|
5377
5391
|
F(() => {
|
|
5378
5392
|
e.unreadCtx.setViewingSessionId(u);
|
|
5379
5393
|
}, [e, u]), F(
|
|
@@ -5381,47 +5395,47 @@ function $o({
|
|
|
5381
5395
|
[e]
|
|
5382
5396
|
);
|
|
5383
5397
|
}
|
|
5384
|
-
function
|
|
5398
|
+
function Uo() {
|
|
5385
5399
|
const {
|
|
5386
5400
|
widgetCtx: { uploadCtx: t }
|
|
5387
|
-
} =
|
|
5388
|
-
() => e.filter((
|
|
5401
|
+
} = ne(), e = K(t.state), n = X(
|
|
5402
|
+
() => e.filter((r) => r.status === "success" && r.fileUrl),
|
|
5389
5403
|
[e]
|
|
5390
5404
|
);
|
|
5391
5405
|
return {
|
|
5392
5406
|
allFiles: e,
|
|
5393
5407
|
appendFiles: t.appendFiles,
|
|
5394
5408
|
handleCancelUpload: t.cancel,
|
|
5395
|
-
successFiles:
|
|
5409
|
+
successFiles: n,
|
|
5396
5410
|
emptyTheFiles: t.reset,
|
|
5397
|
-
getFileById: (
|
|
5398
|
-
getUploadProgress: (
|
|
5411
|
+
getFileById: (r) => e.find((s) => s.id === r),
|
|
5412
|
+
getUploadProgress: (r) => {
|
|
5399
5413
|
var s;
|
|
5400
|
-
return ((s = e.find((o) => o.id ===
|
|
5414
|
+
return ((s = e.find((o) => o.id === r)) == null ? void 0 : s.progress) ?? 0;
|
|
5401
5415
|
},
|
|
5402
|
-
getUploadStatus: (
|
|
5416
|
+
getUploadStatus: (r) => {
|
|
5403
5417
|
var s;
|
|
5404
|
-
return (s = e.find((o) => o.id ===
|
|
5418
|
+
return (s = e.find((o) => o.id === r)) == null ? void 0 : s.status;
|
|
5405
5419
|
},
|
|
5406
|
-
hasErrors: e.some((
|
|
5407
|
-
isUploading: e.some((
|
|
5420
|
+
hasErrors: e.some((r) => r.status === "error"),
|
|
5421
|
+
isUploading: e.some((r) => r.status === "uploading")
|
|
5408
5422
|
};
|
|
5409
5423
|
}
|
|
5410
5424
|
function ho(t) {
|
|
5411
5425
|
return t !== "fullscreen";
|
|
5412
5426
|
}
|
|
5413
|
-
const
|
|
5414
|
-
function
|
|
5427
|
+
const Er = He(null);
|
|
5428
|
+
function qo({ children: t }) {
|
|
5415
5429
|
var s, o;
|
|
5416
|
-
const { companion: e } = It(), { dir:
|
|
5430
|
+
const { companion: e } = It(), { dir: n } = oo(), { widgetCtx: r } = ne();
|
|
5417
5431
|
return /* @__PURE__ */ H.createElement(
|
|
5418
5432
|
yo,
|
|
5419
5433
|
{
|
|
5420
5434
|
configuredDefaultLayout: e == null ? void 0 : e.defaultLayout,
|
|
5421
5435
|
configuredLayouts: e == null ? void 0 : e.layouts,
|
|
5422
|
-
configuredSidebarSide:
|
|
5423
|
-
configuredSidebarMode:
|
|
5424
|
-
storage:
|
|
5436
|
+
configuredSidebarSide: Wr((s = e == null ? void 0 : e.sidebar) == null ? void 0 : s.side, n),
|
|
5437
|
+
configuredSidebarMode: Br((o = e == null ? void 0 : e.sidebar) == null ? void 0 : o.mode),
|
|
5438
|
+
storage: r.storageCtx
|
|
5425
5439
|
},
|
|
5426
5440
|
t
|
|
5427
5441
|
);
|
|
@@ -5429,12 +5443,12 @@ function Uo({ children: t }) {
|
|
|
5429
5443
|
function yo({
|
|
5430
5444
|
configuredDefaultLayout: t,
|
|
5431
5445
|
configuredLayouts: e,
|
|
5432
|
-
configuredSidebarSide:
|
|
5433
|
-
configuredSidebarMode:
|
|
5446
|
+
configuredSidebarSide: n,
|
|
5447
|
+
configuredSidebarMode: r,
|
|
5434
5448
|
storage: s,
|
|
5435
5449
|
children: o
|
|
5436
5450
|
}) {
|
|
5437
|
-
const l =
|
|
5451
|
+
const l = Jr(e), u = Hr(
|
|
5438
5452
|
t,
|
|
5439
5453
|
l
|
|
5440
5454
|
), y = l.join("|"), [g, i] = J(u), [d, p] = J({
|
|
@@ -5452,14 +5466,14 @@ function yo({
|
|
|
5452
5466
|
const M = (h) => {
|
|
5453
5467
|
b(h), P.current.includes(h) && ho(h) && (s == null || s.setCompanionLayout(h).catch(() => {
|
|
5454
5468
|
}));
|
|
5455
|
-
}, [O, x] = J(
|
|
5456
|
-
side:
|
|
5457
|
-
mode:
|
|
5469
|
+
}, [O, x] = J(n), [C, I] = J(r), [w, c] = J({
|
|
5470
|
+
side: n,
|
|
5471
|
+
mode: r
|
|
5458
5472
|
});
|
|
5459
|
-
(
|
|
5460
|
-
side:
|
|
5461
|
-
mode:
|
|
5462
|
-
}),
|
|
5473
|
+
(w.side !== n || w.mode !== r) && (c({
|
|
5474
|
+
side: n,
|
|
5475
|
+
mode: r
|
|
5476
|
+
}), w.side !== n && x(n), w.mode !== r && I(r)), F(() => {
|
|
5463
5477
|
if (!s) return;
|
|
5464
5478
|
let h = !1;
|
|
5465
5479
|
return s.getCompanionLayout().then((S) => {
|
|
@@ -5489,7 +5503,7 @@ function yo({
|
|
|
5489
5503
|
[s]
|
|
5490
5504
|
);
|
|
5491
5505
|
return /* @__PURE__ */ H.createElement(
|
|
5492
|
-
|
|
5506
|
+
Er.Provider,
|
|
5493
5507
|
{
|
|
5494
5508
|
value: {
|
|
5495
5509
|
layout: g,
|
|
@@ -5499,24 +5513,24 @@ function yo({
|
|
|
5499
5513
|
defaultLayout: u,
|
|
5500
5514
|
sidebarSide: O,
|
|
5501
5515
|
setSidebarSide: m,
|
|
5502
|
-
sidebarMode:
|
|
5516
|
+
sidebarMode: C,
|
|
5503
5517
|
setSidebarMode: f
|
|
5504
5518
|
}
|
|
5505
5519
|
},
|
|
5506
5520
|
o
|
|
5507
5521
|
);
|
|
5508
5522
|
}
|
|
5509
|
-
function
|
|
5510
|
-
const t = Fe(
|
|
5523
|
+
function zo() {
|
|
5524
|
+
const t = Fe(Er);
|
|
5511
5525
|
if (!t)
|
|
5512
5526
|
throw new Error(
|
|
5513
5527
|
"useWidgetLayout must be used within a WidgetLayoutProvider"
|
|
5514
5528
|
);
|
|
5515
5529
|
return t;
|
|
5516
5530
|
}
|
|
5517
|
-
function
|
|
5531
|
+
function Zo() {
|
|
5518
5532
|
var u, y;
|
|
5519
|
-
const { widgetCtx: t } =
|
|
5533
|
+
const { widgetCtx: t } = ne(), { modesComponents: e } = It(), { sessionState: n } = Sr(), r = t.modes, s = (u = n.session) == null ? void 0 : u.modeId, o = r.find((g) => g.id === s), l = (y = e == null ? void 0 : e.find(
|
|
5520
5534
|
(g) => {
|
|
5521
5535
|
var i, d;
|
|
5522
5536
|
return [
|
|
@@ -5527,19 +5541,19 @@ function zo() {
|
|
|
5527
5541
|
}
|
|
5528
5542
|
)) == null ? void 0 : y.component;
|
|
5529
5543
|
return {
|
|
5530
|
-
modes:
|
|
5544
|
+
modes: r,
|
|
5531
5545
|
modesComponents: e,
|
|
5532
5546
|
activeModeId: s,
|
|
5533
5547
|
activeMode: o,
|
|
5534
5548
|
Component: l
|
|
5535
5549
|
};
|
|
5536
5550
|
}
|
|
5537
|
-
function
|
|
5538
|
-
const { widgetCtx: t } =
|
|
5551
|
+
function Vo() {
|
|
5552
|
+
const { widgetCtx: t } = ne(), {
|
|
5539
5553
|
messagesState: { messages: e }
|
|
5540
|
-
} =
|
|
5541
|
-
csatRequestedMessage:
|
|
5542
|
-
isCsatRequested:
|
|
5554
|
+
} = br(), {
|
|
5555
|
+
csatRequestedMessage: n,
|
|
5556
|
+
isCsatRequested: r,
|
|
5543
5557
|
csatSubmittedMessage: s,
|
|
5544
5558
|
isCsatSubmitted: o,
|
|
5545
5559
|
submittedScore: l,
|
|
@@ -5561,19 +5575,19 @@ function Zo() {
|
|
|
5561
5575
|
}, [e]);
|
|
5562
5576
|
return {
|
|
5563
5577
|
submitCsat: t.csatCtx.submitCsat,
|
|
5564
|
-
csatRequestedMessage:
|
|
5565
|
-
isCsatRequested:
|
|
5578
|
+
csatRequestedMessage: n,
|
|
5579
|
+
isCsatRequested: r,
|
|
5566
5580
|
csatSubmittedMessage: s,
|
|
5567
5581
|
isCsatSubmitted: o,
|
|
5568
5582
|
submittedScore: l,
|
|
5569
5583
|
submittedFeedback: u
|
|
5570
5584
|
};
|
|
5571
5585
|
}
|
|
5572
|
-
function
|
|
5573
|
-
const { widgetCtx: e } =
|
|
5586
|
+
function Bo(t) {
|
|
5587
|
+
const { widgetCtx: e } = ne(), n = e.dictationCtx, r = K(n.state), s = R(t);
|
|
5574
5588
|
s.current = t;
|
|
5575
5589
|
const o = z(() => {
|
|
5576
|
-
|
|
5590
|
+
n.start({
|
|
5577
5591
|
getValue: () => s.current.getValue(),
|
|
5578
5592
|
setValue: (u) => s.current.setValue(u),
|
|
5579
5593
|
onSend: () => {
|
|
@@ -5581,24 +5595,24 @@ function Vo(t) {
|
|
|
5581
5595
|
return (y = (u = s.current).onSend) == null ? void 0 : y.call(u);
|
|
5582
5596
|
}
|
|
5583
5597
|
});
|
|
5584
|
-
}, [
|
|
5585
|
-
|
|
5586
|
-
}, [
|
|
5587
|
-
return F(() => () =>
|
|
5598
|
+
}, [n]), l = z(() => {
|
|
5599
|
+
n.isActive() ? n.stop() : o();
|
|
5600
|
+
}, [n, o]);
|
|
5601
|
+
return F(() => () => n.stop({ executeFinalCommand: !1 }), [n]), {
|
|
5588
5602
|
enabled: e.features.dictation,
|
|
5589
|
-
status:
|
|
5590
|
-
error:
|
|
5591
|
-
isActive:
|
|
5603
|
+
status: r.status,
|
|
5604
|
+
error: r.error,
|
|
5605
|
+
isActive: r.status !== "idle",
|
|
5592
5606
|
/** 0..1 mic level — read inside a rAF loop, not a render. */
|
|
5593
|
-
levelRef:
|
|
5607
|
+
levelRef: n.levelRef,
|
|
5594
5608
|
start: o,
|
|
5595
|
-
stop:
|
|
5609
|
+
stop: n.stop,
|
|
5596
5610
|
toggle: l,
|
|
5597
|
-
prewarm:
|
|
5611
|
+
prewarm: n.prewarm
|
|
5598
5612
|
};
|
|
5599
5613
|
}
|
|
5600
|
-
function
|
|
5601
|
-
const { widgetCtx: t } =
|
|
5614
|
+
function Wo() {
|
|
5615
|
+
const { widgetCtx: t } = ne(), e = t.messageCtx.draftState, n = K(e), r = z(
|
|
5602
5616
|
(l) => {
|
|
5603
5617
|
e.setPartial({
|
|
5604
5618
|
text: typeof l == "function" ? l(e.get().text) : l
|
|
@@ -5613,41 +5627,42 @@ function Bo() {
|
|
|
5613
5627
|
},
|
|
5614
5628
|
[e]
|
|
5615
5629
|
), o = z(
|
|
5616
|
-
(l =
|
|
5617
|
-
[e,
|
|
5630
|
+
(l = n) => e.get() !== l ? !1 : (e.reset(), !0),
|
|
5631
|
+
[e, n]
|
|
5618
5632
|
);
|
|
5619
|
-
return { ...
|
|
5633
|
+
return { ...n, setText: r, setMentions: s, clearSubmitted: o };
|
|
5620
5634
|
}
|
|
5621
5635
|
export {
|
|
5622
|
-
|
|
5623
|
-
|
|
5636
|
+
jt as HOST_CONTEXT_CHANGED_EVENT,
|
|
5637
|
+
qo as WidgetLayoutProvider,
|
|
5624
5638
|
_o as WidgetProvider,
|
|
5625
|
-
|
|
5626
|
-
|
|
5639
|
+
$o as WidgetTriggerProvider,
|
|
5640
|
+
hn as applyPresentation,
|
|
5627
5641
|
xo as formatAskQuestionsAnswers,
|
|
5628
5642
|
Ro as sessionPlan,
|
|
5629
|
-
|
|
5643
|
+
pr as useAgentChatUi,
|
|
5630
5644
|
Po as useBot,
|
|
5631
5645
|
Mo as useCompanionChats,
|
|
5632
|
-
|
|
5646
|
+
Wo as useComposerDraft,
|
|
5633
5647
|
It as useConfig,
|
|
5634
5648
|
To as useConnection,
|
|
5635
5649
|
No as useContact,
|
|
5636
|
-
|
|
5637
|
-
|
|
5650
|
+
Vo as useCsat,
|
|
5651
|
+
Bo as useDictation,
|
|
5638
5652
|
Oo as useDisplayMode,
|
|
5639
5653
|
oo as useDocumentDir,
|
|
5640
|
-
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
|
|
5654
|
+
Lo as useHostLocation,
|
|
5655
|
+
ko as useIsAwaitingBotReply,
|
|
5656
|
+
br as useMessages,
|
|
5657
|
+
Zo as useModes,
|
|
5644
5658
|
K as usePrimitiveState,
|
|
5645
|
-
|
|
5659
|
+
Sr as useSessions,
|
|
5660
|
+
Do as useTokenRenewal,
|
|
5646
5661
|
jo as useUnread,
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
|
|
5662
|
+
Fo as useUnreadViewing,
|
|
5663
|
+
Uo as useUploadFiles,
|
|
5664
|
+
ne as useWidget,
|
|
5665
|
+
zo as useWidgetLayout,
|
|
5651
5666
|
po as useWidgetRouter,
|
|
5652
5667
|
fo as useWidgetTrigger
|
|
5653
5668
|
};
|