@opencx/widget-react-headless 5.14.1 → 5.15.1
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 +13 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +502 -490
- 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/hooks/useTokenRenewal.d.ts +13 -4
- package/dist/src/hooks/useTokenRenewal.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { safeParseAsync as Yr, lazy as Kr, unknown as Gr, union as Qr, string as
|
|
|
9
9
|
import { toJSONSchema as fs } from "zod/v4/core";
|
|
10
10
|
import "react/jsx-runtime";
|
|
11
11
|
import { z as D } from "zod";
|
|
12
|
-
const Pn = "5.
|
|
12
|
+
const Pn = "5.15.1";
|
|
13
13
|
function K(t) {
|
|
14
14
|
return zt(t.subscribe, t.get, t.get);
|
|
15
15
|
}
|
|
@@ -59,12 +59,12 @@ var ee = class Nn extends Error {
|
|
|
59
59
|
};
|
|
60
60
|
const Ln = "AI_APICallError", Dn = `vercel.ai.error.${Ln}`, ys = Symbol.for(Dn);
|
|
61
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:
|
|
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
64
|
name: Ln,
|
|
65
65
|
message: t,
|
|
66
66
|
cause: l
|
|
67
|
-
}), this[ys] = !0, this.url = e, this.requestBodyValues = n, this.statusCode = r, this.responseHeaders = s, this.responseBody = o, this.isRetryable = u, this.data =
|
|
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
70
|
return ee.hasMarker(t, Dn);
|
|
@@ -177,15 +177,15 @@ function xs(t) {
|
|
|
177
177
|
"`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?"
|
|
178
178
|
);
|
|
179
179
|
const { onEvent: e = Ot, onError: n = Ot, onRetry: r = Ot, onComment: s, maxBufferSize: o } = t, l = [];
|
|
180
|
-
let u = 0,
|
|
181
|
-
function
|
|
180
|
+
let u = 0, y = !0, g, i = "", d = 0, p, b = !1;
|
|
181
|
+
function O(c) {
|
|
182
182
|
if (b)
|
|
183
183
|
throw new Error(
|
|
184
184
|
"Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing."
|
|
185
185
|
);
|
|
186
|
-
if (
|
|
187
|
-
const
|
|
188
|
-
|
|
186
|
+
if (y && (y = !1, c.charCodeAt(0) === 239 && c.charCodeAt(1) === 187 && c.charCodeAt(2) === 191 && (c = c.slice(3))), l.length === 0) {
|
|
187
|
+
const h = N(c);
|
|
188
|
+
h !== "" && (l.push(h), u = h.length), M();
|
|
189
189
|
return;
|
|
190
190
|
}
|
|
191
191
|
if (c.indexOf(`
|
|
@@ -196,7 +196,7 @@ function xs(t) {
|
|
|
196
196
|
l.push(c);
|
|
197
197
|
const m = l.join("");
|
|
198
198
|
l.length = 0, u = 0;
|
|
199
|
-
const f =
|
|
199
|
+
const f = N(m);
|
|
200
200
|
f !== "" && (l.push(f), u = f.length), M();
|
|
201
201
|
}
|
|
202
202
|
function M() {
|
|
@@ -206,7 +206,7 @@ function xs(t) {
|
|
|
206
206
|
})
|
|
207
207
|
)));
|
|
208
208
|
}
|
|
209
|
-
function
|
|
209
|
+
function N(c) {
|
|
210
210
|
let m = 0;
|
|
211
211
|
if (c.indexOf("\r") === -1) {
|
|
212
212
|
let f = c.indexOf(`
|
|
@@ -217,17 +217,17 @@ function xs(t) {
|
|
|
217
217
|
`, m);
|
|
218
218
|
continue;
|
|
219
219
|
}
|
|
220
|
-
const
|
|
221
|
-
if (an(c, m,
|
|
222
|
-
const
|
|
220
|
+
const h = c.charCodeAt(m);
|
|
221
|
+
if (an(c, m, h)) {
|
|
222
|
+
const I = c.charCodeAt(m + 5) === Oe ? m + 6 : m + 5, P = c.slice(I, f);
|
|
223
223
|
if (d === 0 && c.charCodeAt(f + 1) === sn) {
|
|
224
|
-
e({ id: g, event: p, data:
|
|
224
|
+
e({ id: g, event: p, data: P }), g = void 0, i = "", p = void 0, m = f + 2, f = c.indexOf(`
|
|
225
225
|
`, m);
|
|
226
226
|
continue;
|
|
227
227
|
}
|
|
228
|
-
i = d === 0 ?
|
|
229
|
-
${
|
|
230
|
-
} else on(c, m,
|
|
228
|
+
i = d === 0 ? P : `${i}
|
|
229
|
+
${P}`, d++;
|
|
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);
|
|
@@ -237,52 +237,52 @@ ${N}`, d++;
|
|
|
237
237
|
return c.slice(m);
|
|
238
238
|
}
|
|
239
239
|
for (; m < c.length; ) {
|
|
240
|
-
const f = c.indexOf("\r", m),
|
|
240
|
+
const f = c.indexOf("\r", m), h = c.indexOf(`
|
|
241
241
|
`, m);
|
|
242
|
-
let
|
|
243
|
-
if (f !== -1 &&
|
|
242
|
+
let I = -1;
|
|
243
|
+
if (f !== -1 && h !== -1 ? I = f < h ? f : h : f !== -1 ? f === c.length - 1 ? I = -1 : I = f : h !== -1 && (I = h), I === -1)
|
|
244
244
|
break;
|
|
245
|
-
x(c, m,
|
|
245
|
+
x(c, m, I), m = I + 1, c.charCodeAt(m - 1) === As && c.charCodeAt(m) === sn && m++;
|
|
246
246
|
}
|
|
247
247
|
return c.slice(m);
|
|
248
248
|
}
|
|
249
249
|
function x(c, m, f) {
|
|
250
250
|
if (m === f) {
|
|
251
|
-
|
|
251
|
+
S();
|
|
252
252
|
return;
|
|
253
253
|
}
|
|
254
|
-
const
|
|
255
|
-
if (an(c, m,
|
|
254
|
+
const h = c.charCodeAt(m);
|
|
255
|
+
if (an(c, m, h)) {
|
|
256
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 (on(c, m,
|
|
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
|
-
if (
|
|
265
|
+
if (h === 105 && c.charCodeAt(m + 1) === 100 && c.charCodeAt(m + 2) === 58) {
|
|
266
266
|
const k = c.slice(c.charCodeAt(m + 3) === Oe ? m + 4 : m + 3, f);
|
|
267
267
|
g = k.includes("\0") ? void 0 : k;
|
|
268
268
|
return;
|
|
269
269
|
}
|
|
270
|
-
if (
|
|
270
|
+
if (h === 58) {
|
|
271
271
|
if (s) {
|
|
272
272
|
const k = c.slice(m, f);
|
|
273
273
|
s(k.slice(c.charCodeAt(m + 1) === Oe ? 2 : 1));
|
|
274
274
|
}
|
|
275
275
|
return;
|
|
276
276
|
}
|
|
277
|
-
const
|
|
278
|
-
if (
|
|
279
|
-
|
|
277
|
+
const I = c.slice(m, f), P = I.indexOf(":");
|
|
278
|
+
if (P === -1) {
|
|
279
|
+
w(I, "", I);
|
|
280
280
|
return;
|
|
281
281
|
}
|
|
282
|
-
const L =
|
|
283
|
-
|
|
282
|
+
const L = I.slice(0, P), B = I.charCodeAt(P + 1) === Oe ? 2 : 1, W = I.slice(P + B);
|
|
283
|
+
w(L, W, I);
|
|
284
284
|
}
|
|
285
|
-
function
|
|
285
|
+
function w(c, m, f) {
|
|
286
286
|
switch (c) {
|
|
287
287
|
case "event":
|
|
288
288
|
p = m || void 0;
|
|
@@ -313,21 +313,21 @@ ${m}`, d++;
|
|
|
313
313
|
break;
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
|
-
function
|
|
316
|
+
function S() {
|
|
317
317
|
d > 0 && e({
|
|
318
318
|
id: g,
|
|
319
319
|
event: p,
|
|
320
320
|
data: i
|
|
321
321
|
}), g = void 0, i = "", d = 0, p = void 0;
|
|
322
322
|
}
|
|
323
|
-
function
|
|
323
|
+
function E(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:
|
|
330
|
+
return { feed: O, reset: E };
|
|
331
331
|
}
|
|
332
332
|
function an(t, e, n) {
|
|
333
333
|
return n === 100 && t.charCodeAt(e + 1) === 97 && t.charCodeAt(e + 2) === 116 && t.charCodeAt(e + 3) === 97 && t.charCodeAt(e + 4) === 58;
|
|
@@ -747,7 +747,7 @@ function se(t, e, n, r) {
|
|
|
747
747
|
})) : t.pattern = un(e, r);
|
|
748
748
|
}
|
|
749
749
|
function un(t, e) {
|
|
750
|
-
var
|
|
750
|
+
var y;
|
|
751
751
|
if (!e.applyRegexFlags || !t.flags) return t.source;
|
|
752
752
|
const n = {
|
|
753
753
|
i: t.flags.includes("i"),
|
|
@@ -763,7 +763,7 @@ function un(t, e) {
|
|
|
763
763
|
if (n.i) {
|
|
764
764
|
if (l) {
|
|
765
765
|
if (r[g].match(/[a-z]/)) {
|
|
766
|
-
u ? (s += r[g], s += `${r[g - 2]}-${r[g]}`.toUpperCase(), u = !1) : r[g + 1] === "-" && ((
|
|
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
769
|
} else if (r[g].match(/[a-z]/)) {
|
|
@@ -807,7 +807,7 @@ function Gn(t, e) {
|
|
|
807
807
|
}) ?? e.allowedAdditionalProperties
|
|
808
808
|
};
|
|
809
809
|
if (((r = t.keyType) == null ? void 0 : r._def.typeName) === "ZodString" && ((s = t.keyType._def.checks) != null && s.length)) {
|
|
810
|
-
const { type:
|
|
810
|
+
const { type: y, ...g } = Kn(t.keyType._def, e);
|
|
811
811
|
return {
|
|
812
812
|
...n,
|
|
813
813
|
propertyNames: g
|
|
@@ -818,7 +818,7 @@ function Gn(t, e) {
|
|
|
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:
|
|
821
|
+
const { type: y, ...g } = Hn(t.keyType._def, e);
|
|
822
822
|
return {
|
|
823
823
|
...n,
|
|
824
824
|
propertyNames: g
|
|
@@ -967,7 +967,7 @@ function ra(t, e) {
|
|
|
967
967
|
for (const l in s) {
|
|
968
968
|
let u = s[l];
|
|
969
969
|
if (u === void 0 || u._def === void 0) continue;
|
|
970
|
-
const
|
|
970
|
+
const y = aa(u), g = q(u._def, {
|
|
971
971
|
...e,
|
|
972
972
|
currentPath: [
|
|
973
973
|
...e.currentPath,
|
|
@@ -980,7 +980,7 @@ function ra(t, e) {
|
|
|
980
980
|
l
|
|
981
981
|
]
|
|
982
982
|
});
|
|
983
|
-
g !== void 0 && (n.properties[l] = g,
|
|
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);
|
|
@@ -1172,12 +1172,12 @@ function q(t, e, n = !1) {
|
|
|
1172
1172
|
var u;
|
|
1173
1173
|
const r = e.seen.get(t);
|
|
1174
1174
|
if (e.override) {
|
|
1175
|
-
const
|
|
1176
|
-
if (
|
|
1175
|
+
const y = (u = e.override) == null ? void 0 : u.call(e, t, e, r, n);
|
|
1176
|
+
if (y !== Ls) return y;
|
|
1177
1177
|
}
|
|
1178
1178
|
if (r && !n) {
|
|
1179
|
-
const
|
|
1180
|
-
if (
|
|
1179
|
+
const y = ha(r, e);
|
|
1180
|
+
if (y !== void 0) return y;
|
|
1181
1181
|
}
|
|
1182
1182
|
const s = {
|
|
1183
1183
|
def: t,
|
|
@@ -1187,8 +1187,8 @@ function q(t, e, n = !1) {
|
|
|
1187
1187
|
e.seen.set(t, s);
|
|
1188
1188
|
const o = ma(t, t.typeName, e), l = typeof o == "function" ? q(o(), e) : o;
|
|
1189
1189
|
if (l && ya(t, e, l), e.postProcess) {
|
|
1190
|
-
const
|
|
1191
|
-
return s.jsonSchema = l,
|
|
1190
|
+
const y = e.postProcess(l, t, e);
|
|
1191
|
+
return s.jsonSchema = l, y;
|
|
1192
1192
|
}
|
|
1193
1193
|
return s.jsonSchema = l, l;
|
|
1194
1194
|
}
|
|
@@ -1224,8 +1224,8 @@ const ha = (t, e) => {
|
|
|
1224
1224
|
};
|
|
1225
1225
|
}, ba = (t, e) => {
|
|
1226
1226
|
const n = va(e);
|
|
1227
|
-
let r = typeof e == "object" && e.definitions ? Object.entries(e.definitions).reduce((
|
|
1228
|
-
...
|
|
1227
|
+
let r = typeof e == "object" && e.definitions ? Object.entries(e.definitions).reduce((y, [g, i]) => ({
|
|
1228
|
+
...y,
|
|
1229
1229
|
[g]: q(i._def, {
|
|
1230
1230
|
...n,
|
|
1231
1231
|
currentPath: [
|
|
@@ -1755,7 +1755,7 @@ function Ba(t) {
|
|
|
1755
1755
|
n = d, e.pop();
|
|
1756
1756
|
}
|
|
1757
1757
|
}
|
|
1758
|
-
function
|
|
1758
|
+
function y(i, d) {
|
|
1759
1759
|
switch (i) {
|
|
1760
1760
|
case ",":
|
|
1761
1761
|
e.pop(), e.push("INSIDE_ARRAY_AFTER_COMMA");
|
|
@@ -1865,13 +1865,13 @@ function Ba(t) {
|
|
|
1865
1865
|
case ".":
|
|
1866
1866
|
break;
|
|
1867
1867
|
case ",":
|
|
1868
|
-
e.pop(), e[e.length - 1] === "INSIDE_ARRAY_AFTER_VALUE" &&
|
|
1868
|
+
e.pop(), e[e.length - 1] === "INSIDE_ARRAY_AFTER_VALUE" && y(d, i), e[e.length - 1] === "INSIDE_OBJECT_AFTER_VALUE" && u(d, i);
|
|
1869
1869
|
break;
|
|
1870
1870
|
case "}":
|
|
1871
1871
|
e.pop(), e[e.length - 1] === "INSIDE_OBJECT_AFTER_VALUE" && u(d, i);
|
|
1872
1872
|
break;
|
|
1873
1873
|
case "]":
|
|
1874
|
-
e.pop(), e[e.length - 1] === "INSIDE_ARRAY_AFTER_VALUE" &&
|
|
1874
|
+
e.pop(), e[e.length - 1] === "INSIDE_ARRAY_AFTER_VALUE" && y(d, i);
|
|
1875
1875
|
break;
|
|
1876
1876
|
default:
|
|
1877
1877
|
e.pop();
|
|
@@ -1879,7 +1879,7 @@ function Ba(t) {
|
|
|
1879
1879
|
break;
|
|
1880
1880
|
case "INSIDE_LITERAL": {
|
|
1881
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" &&
|
|
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
|
}
|
|
@@ -2207,27 +2207,27 @@ function ur({ lastMessage: t, messageId: e }) {
|
|
|
2207
2207
|
partialToolCalls: r
|
|
2208
2208
|
};
|
|
2209
2209
|
}
|
|
2210
|
-
function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdateMessageJob: r, onError: s, onToolCall: o, onData: l, resetStateOnMessageIdChange: u = !1, resetStateOnFirstMessageStart:
|
|
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
2213
|
await r(async ({ state: p, write: b }) => {
|
|
2214
|
-
function
|
|
2214
|
+
function O() {
|
|
2215
2215
|
const c = p.message.parts;
|
|
2216
2216
|
let m = c.length - 1;
|
|
2217
2217
|
for (; m >= 0 && c[m].type !== "step-start"; ) m--;
|
|
2218
2218
|
return c.slice(m + 1);
|
|
2219
2219
|
}
|
|
2220
2220
|
function M() {
|
|
2221
|
-
return
|
|
2221
|
+
return O().filter(pe);
|
|
2222
2222
|
}
|
|
2223
|
-
function
|
|
2223
|
+
function N(c) {
|
|
2224
2224
|
let m = M().find((f) => f.toolCallId === c);
|
|
2225
2225
|
if (m == null) {
|
|
2226
2226
|
const f = p.message.parts;
|
|
2227
|
-
for (let
|
|
2228
|
-
const
|
|
2229
|
-
if (pe(
|
|
2230
|
-
m =
|
|
2227
|
+
for (let h = f.length - 1; h >= 0; h--) {
|
|
2228
|
+
const I = f[h];
|
|
2229
|
+
if (pe(I) && I.toolCallId === c) {
|
|
2230
|
+
m = I;
|
|
2231
2231
|
break;
|
|
2232
2232
|
}
|
|
2233
2233
|
}
|
|
@@ -2241,8 +2241,8 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
|
|
|
2241
2241
|
}
|
|
2242
2242
|
function x(c) {
|
|
2243
2243
|
const m = p.message.parts.filter(pe).find((f) => {
|
|
2244
|
-
var
|
|
2245
|
-
return ((
|
|
2244
|
+
var h;
|
|
2245
|
+
return ((h = f.approval) == null ? void 0 : h.id) === c;
|
|
2246
2246
|
});
|
|
2247
2247
|
if (m == null) throw new Ne({
|
|
2248
2248
|
chunkType: "tool-approval-response",
|
|
@@ -2251,61 +2251,61 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
|
|
|
2251
2251
|
});
|
|
2252
2252
|
return m;
|
|
2253
2253
|
}
|
|
2254
|
-
function
|
|
2255
|
-
const f = m ??
|
|
2254
|
+
function w(c, m) {
|
|
2255
|
+
const f = m ?? O().find((P) => gt(P) && P.toolCallId === c.toolCallId), h = c, I = f;
|
|
2256
2256
|
if (f != null) {
|
|
2257
|
-
f.state = c.state,
|
|
2258
|
-
const
|
|
2259
|
-
if (
|
|
2257
|
+
f.state = c.state, I.type = `tool-${c.toolName}`, I.input = h.input, I.output = h.output, I.errorText = h.errorText, I.rawInput = h.rawInput, h.inputEncoding != null ? I.inputEncoding = h.inputEncoding : delete I.inputEncoding, I.preliminary = h.preliminary, c.title !== void 0 && (I.title = c.title), c.toolMetadata !== void 0 && (I.toolMetadata = c.toolMetadata), I.providerExecuted = h.providerExecuted ?? f.providerExecuted;
|
|
2258
|
+
const P = h.providerMetadata;
|
|
2259
|
+
if (P != null)
|
|
2260
2260
|
if (c.state === "output-available" || c.state === "output-error") {
|
|
2261
2261
|
const L = f;
|
|
2262
|
-
L.resultProviderMetadata =
|
|
2263
|
-
} else f.callProviderMetadata =
|
|
2262
|
+
L.resultProviderMetadata = P;
|
|
2263
|
+
} else f.callProviderMetadata = P;
|
|
2264
2264
|
} else p.message.parts.push({
|
|
2265
2265
|
type: `tool-${c.toolName}`,
|
|
2266
2266
|
toolCallId: c.toolCallId,
|
|
2267
2267
|
state: c.state,
|
|
2268
2268
|
title: c.title,
|
|
2269
2269
|
...c.toolMetadata !== void 0 ? { toolMetadata: c.toolMetadata } : {},
|
|
2270
|
-
input:
|
|
2271
|
-
...
|
|
2272
|
-
output:
|
|
2273
|
-
rawInput:
|
|
2274
|
-
errorText:
|
|
2275
|
-
providerExecuted:
|
|
2276
|
-
preliminary:
|
|
2277
|
-
...
|
|
2278
|
-
...
|
|
2270
|
+
input: h.input,
|
|
2271
|
+
...h.inputEncoding != null ? { inputEncoding: h.inputEncoding } : {},
|
|
2272
|
+
output: h.output,
|
|
2273
|
+
rawInput: h.rawInput,
|
|
2274
|
+
errorText: h.errorText,
|
|
2275
|
+
providerExecuted: h.providerExecuted,
|
|
2276
|
+
preliminary: h.preliminary,
|
|
2277
|
+
...h.providerMetadata != null && (c.state === "output-available" || c.state === "output-error") ? { resultProviderMetadata: h.providerMetadata } : {},
|
|
2278
|
+
...h.providerMetadata != null && !(c.state === "output-available" || c.state === "output-error") ? { callProviderMetadata: h.providerMetadata } : {}
|
|
2279
2279
|
});
|
|
2280
2280
|
}
|
|
2281
|
-
function
|
|
2282
|
-
const f = m ??
|
|
2281
|
+
function S(c, m) {
|
|
2282
|
+
const f = m ?? O().find((P) => P.type === "dynamic-tool" && P.toolCallId === c.toolCallId), h = c, I = f;
|
|
2283
2283
|
if (f != null) {
|
|
2284
|
-
f.state = c.state,
|
|
2285
|
-
const
|
|
2286
|
-
if (
|
|
2284
|
+
f.state = c.state, I.toolName = c.toolName, I.input = h.input, I.output = h.output, I.errorText = h.errorText, I.rawInput = h.rawInput, h.inputEncoding != null ? I.inputEncoding = h.inputEncoding : delete I.inputEncoding, I.preliminary = h.preliminary, c.title !== void 0 && (I.title = c.title), c.toolMetadata !== void 0 && (I.toolMetadata = c.toolMetadata), I.providerExecuted = h.providerExecuted ?? f.providerExecuted;
|
|
2285
|
+
const P = h.providerMetadata;
|
|
2286
|
+
if (P != null)
|
|
2287
2287
|
if (c.state === "output-available" || c.state === "output-error") {
|
|
2288
2288
|
const L = f;
|
|
2289
|
-
L.resultProviderMetadata =
|
|
2290
|
-
} else f.callProviderMetadata =
|
|
2289
|
+
L.resultProviderMetadata = P;
|
|
2290
|
+
} else f.callProviderMetadata = P;
|
|
2291
2291
|
} else p.message.parts.push({
|
|
2292
2292
|
type: "dynamic-tool",
|
|
2293
2293
|
toolName: c.toolName,
|
|
2294
2294
|
toolCallId: c.toolCallId,
|
|
2295
2295
|
state: c.state,
|
|
2296
|
-
input:
|
|
2297
|
-
...
|
|
2298
|
-
output:
|
|
2299
|
-
errorText:
|
|
2300
|
-
preliminary:
|
|
2301
|
-
providerExecuted:
|
|
2296
|
+
input: h.input,
|
|
2297
|
+
...h.inputEncoding != null ? { inputEncoding: h.inputEncoding } : {},
|
|
2298
|
+
output: h.output,
|
|
2299
|
+
errorText: h.errorText,
|
|
2300
|
+
preliminary: h.preliminary,
|
|
2301
|
+
providerExecuted: h.providerExecuted,
|
|
2302
2302
|
title: c.title,
|
|
2303
2303
|
...c.toolMetadata !== void 0 ? { toolMetadata: c.toolMetadata } : {},
|
|
2304
|
-
...
|
|
2305
|
-
...
|
|
2304
|
+
...h.providerMetadata != null && (c.state === "output-available" || c.state === "output-error") ? { resultProviderMetadata: h.providerMetadata } : {},
|
|
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 E(c) {
|
|
2309
2309
|
if (c != null) {
|
|
2310
2310
|
const m = p.message.metadata != null ? sr(p.message.metadata, c) : c;
|
|
2311
2311
|
e != null && await dn({
|
|
@@ -2418,7 +2418,7 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
|
|
|
2418
2418
|
}), b();
|
|
2419
2419
|
break;
|
|
2420
2420
|
case "tool-input-start": {
|
|
2421
|
-
const c =
|
|
2421
|
+
const c = O().filter(gt);
|
|
2422
2422
|
p.partialToolCalls[i.toolCallId] = {
|
|
2423
2423
|
text: "",
|
|
2424
2424
|
inputEncoding: i.inputEncoding,
|
|
@@ -2427,7 +2427,7 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
|
|
|
2427
2427
|
dynamic: i.dynamic,
|
|
2428
2428
|
title: i.title,
|
|
2429
2429
|
toolMetadata: i.toolMetadata
|
|
2430
|
-
}, i.dynamic ?
|
|
2430
|
+
}, i.dynamic ? S({
|
|
2431
2431
|
toolCallId: i.toolCallId,
|
|
2432
2432
|
toolName: i.toolName,
|
|
2433
2433
|
state: "input-streaming",
|
|
@@ -2437,7 +2437,7 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
|
|
|
2437
2437
|
title: i.title,
|
|
2438
2438
|
toolMetadata: i.toolMetadata,
|
|
2439
2439
|
providerMetadata: i.providerMetadata
|
|
2440
|
-
}) :
|
|
2440
|
+
}) : w({
|
|
2441
2441
|
toolCallId: i.toolCallId,
|
|
2442
2442
|
toolName: i.toolName,
|
|
2443
2443
|
state: "input-streaming",
|
|
@@ -2459,7 +2459,7 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
|
|
|
2459
2459
|
});
|
|
2460
2460
|
c.text += i.inputTextDelta;
|
|
2461
2461
|
const m = c.inputEncoding === "text" ? c.text : (await Wa(c.text)).value;
|
|
2462
|
-
c.dynamic ?
|
|
2462
|
+
c.dynamic ? S({
|
|
2463
2463
|
toolCallId: i.toolCallId,
|
|
2464
2464
|
toolName: c.toolName,
|
|
2465
2465
|
state: "input-streaming",
|
|
@@ -2468,7 +2468,7 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
|
|
|
2468
2468
|
rawInput: c.text,
|
|
2469
2469
|
title: c.title,
|
|
2470
2470
|
toolMetadata: c.toolMetadata
|
|
2471
|
-
}) :
|
|
2471
|
+
}) : w({
|
|
2472
2472
|
toolCallId: i.toolCallId,
|
|
2473
2473
|
toolName: c.toolName,
|
|
2474
2474
|
state: "input-streaming",
|
|
@@ -2481,7 +2481,7 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
|
|
|
2481
2481
|
break;
|
|
2482
2482
|
}
|
|
2483
2483
|
case "tool-input-available":
|
|
2484
|
-
i.dynamic ?
|
|
2484
|
+
i.dynamic ? S({
|
|
2485
2485
|
toolCallId: i.toolCallId,
|
|
2486
2486
|
toolName: i.toolName,
|
|
2487
2487
|
state: "input-available",
|
|
@@ -2490,7 +2490,7 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
|
|
|
2490
2490
|
providerMetadata: i.providerMetadata,
|
|
2491
2491
|
title: i.title,
|
|
2492
2492
|
toolMetadata: i.toolMetadata
|
|
2493
|
-
}) :
|
|
2493
|
+
}) : w({
|
|
2494
2494
|
toolCallId: i.toolCallId,
|
|
2495
2495
|
toolName: i.toolName,
|
|
2496
2496
|
state: "input-available",
|
|
@@ -2502,8 +2502,8 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
|
|
|
2502
2502
|
}), b(), o && !i.providerExecuted && await o({ toolCall: i });
|
|
2503
2503
|
break;
|
|
2504
2504
|
case "tool-input-error": {
|
|
2505
|
-
const c =
|
|
2506
|
-
(c != null ? c.type === "dynamic-tool" : i.dynamic) ?
|
|
2505
|
+
const c = O().filter(pe).find((m) => m.toolCallId === i.toolCallId);
|
|
2506
|
+
(c != null ? c.type === "dynamic-tool" : i.dynamic) ? S({
|
|
2507
2507
|
toolCallId: i.toolCallId,
|
|
2508
2508
|
toolName: i.toolName,
|
|
2509
2509
|
state: "output-error",
|
|
@@ -2512,7 +2512,7 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
|
|
|
2512
2512
|
providerExecuted: i.providerExecuted,
|
|
2513
2513
|
providerMetadata: i.providerMetadata,
|
|
2514
2514
|
toolMetadata: i.toolMetadata
|
|
2515
|
-
}) :
|
|
2515
|
+
}) : w({
|
|
2516
2516
|
toolCallId: i.toolCallId,
|
|
2517
2517
|
toolName: i.toolName,
|
|
2518
2518
|
state: "output-error",
|
|
@@ -2525,7 +2525,7 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
|
|
|
2525
2525
|
break;
|
|
2526
2526
|
}
|
|
2527
2527
|
case "tool-approval-request": {
|
|
2528
|
-
const c =
|
|
2528
|
+
const c = N(i.toolCallId);
|
|
2529
2529
|
c.state = "approval-requested", c.approval = {
|
|
2530
2530
|
id: i.approvalId,
|
|
2531
2531
|
...i.approvalDescriptor != null ? { descriptor: i.approvalDescriptor } : {},
|
|
@@ -2547,13 +2547,13 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
|
|
|
2547
2547
|
break;
|
|
2548
2548
|
}
|
|
2549
2549
|
case "tool-output-denied": {
|
|
2550
|
-
const c =
|
|
2550
|
+
const c = N(i.toolCallId);
|
|
2551
2551
|
c.state = "output-denied", b();
|
|
2552
2552
|
break;
|
|
2553
2553
|
}
|
|
2554
2554
|
case "tool-output-available": {
|
|
2555
|
-
const c =
|
|
2556
|
-
c.type === "dynamic-tool" ?
|
|
2555
|
+
const c = N(i.toolCallId);
|
|
2556
|
+
c.type === "dynamic-tool" ? S({
|
|
2557
2557
|
toolCallId: i.toolCallId,
|
|
2558
2558
|
toolName: c.toolName,
|
|
2559
2559
|
state: "output-available",
|
|
@@ -2564,7 +2564,7 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
|
|
|
2564
2564
|
providerMetadata: i.providerMetadata,
|
|
2565
2565
|
title: c.title,
|
|
2566
2566
|
toolMetadata: i.toolMetadata ?? c.toolMetadata
|
|
2567
|
-
}, c) :
|
|
2567
|
+
}, c) : w({
|
|
2568
2568
|
toolCallId: i.toolCallId,
|
|
2569
2569
|
toolName: ht(c),
|
|
2570
2570
|
state: "output-available",
|
|
@@ -2579,8 +2579,8 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
|
|
|
2579
2579
|
break;
|
|
2580
2580
|
}
|
|
2581
2581
|
case "tool-output-error": {
|
|
2582
|
-
const c =
|
|
2583
|
-
c.type === "dynamic-tool" ?
|
|
2582
|
+
const c = N(i.toolCallId);
|
|
2583
|
+
c.type === "dynamic-tool" ? S({
|
|
2584
2584
|
toolCallId: i.toolCallId,
|
|
2585
2585
|
toolName: c.toolName,
|
|
2586
2586
|
state: "output-error",
|
|
@@ -2590,7 +2590,7 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
|
|
|
2590
2590
|
providerMetadata: i.providerMetadata,
|
|
2591
2591
|
title: c.title,
|
|
2592
2592
|
toolMetadata: i.toolMetadata ?? c.toolMetadata
|
|
2593
|
-
}, c) :
|
|
2593
|
+
}, c) : w({
|
|
2594
2594
|
toolCallId: i.toolCallId,
|
|
2595
2595
|
toolName: ht(c),
|
|
2596
2596
|
state: "output-error",
|
|
@@ -2610,23 +2610,23 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
|
|
|
2610
2610
|
case "finish-step":
|
|
2611
2611
|
break;
|
|
2612
2612
|
case "reset-step": {
|
|
2613
|
-
const c =
|
|
2613
|
+
const c = O();
|
|
2614
2614
|
p.activeTextParts = Be(), p.activeReasoningParts = Be(), p.partialToolCalls = Be(), c.length > 0 && (p.message.parts.splice(p.message.parts.length - c.length, c.length), b());
|
|
2615
2615
|
break;
|
|
2616
2616
|
}
|
|
2617
2617
|
case "start": {
|
|
2618
|
-
const c =
|
|
2618
|
+
const c = y && g || u && i.messageId != null && i.messageId !== p.message.id;
|
|
2619
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 E(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 E(i.messageMetadata), i.messageMetadata != null && b();
|
|
2627
2627
|
break;
|
|
2628
2628
|
case "message-metadata":
|
|
2629
|
-
await
|
|
2629
|
+
await E(i.messageMetadata), i.messageMetadata != null && b();
|
|
2630
2630
|
break;
|
|
2631
2631
|
case "error":
|
|
2632
2632
|
s == null || s(new Error(i.errorText));
|
|
@@ -2634,12 +2634,12 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
|
|
|
2634
2634
|
default:
|
|
2635
2635
|
if (Ya(i)) {
|
|
2636
2636
|
if ((n == null ? void 0 : n[i.type]) != null) {
|
|
2637
|
-
const f = p.message.parts.findIndex((
|
|
2637
|
+
const f = p.message.parts.findIndex((I) => "id" in I && "data" in I && I.id === i.id && I.type === i.type), h = f >= 0 ? f : p.message.parts.length;
|
|
2638
2638
|
await dn({
|
|
2639
2639
|
value: i.data,
|
|
2640
2640
|
schema: n[i.type],
|
|
2641
2641
|
context: {
|
|
2642
|
-
field: `message.parts[${
|
|
2642
|
+
field: `message.parts[${h}].data`,
|
|
2643
2643
|
entityName: i.type,
|
|
2644
2644
|
entityId: i.id
|
|
2645
2645
|
}
|
|
@@ -2816,8 +2816,8 @@ async function ti(t) {
|
|
|
2816
2816
|
url: await new Promise((s, o) => {
|
|
2817
2817
|
const l = new FileReader();
|
|
2818
2818
|
l.onload = (u) => {
|
|
2819
|
-
var
|
|
2820
|
-
s((
|
|
2819
|
+
var y;
|
|
2820
|
+
s((y = u.target) == null ? void 0 : y.result);
|
|
2821
2821
|
}, l.onerror = (u) => o(u), l.readAsDataURL(e);
|
|
2822
2822
|
})
|
|
2823
2823
|
};
|
|
@@ -2849,7 +2849,7 @@ var ri = class {
|
|
|
2849
2849
|
requestMetadata: e.metadata,
|
|
2850
2850
|
trigger: e.trigger,
|
|
2851
2851
|
messageId: e.messageId
|
|
2852
|
-
})), u = (l == null ? void 0 : l.api) ?? this.api,
|
|
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,
|
|
@@ -2860,7 +2860,7 @@ var ri = class {
|
|
|
2860
2860
|
method: "POST",
|
|
2861
2861
|
headers: {
|
|
2862
2862
|
"content-type": "application/json",
|
|
2863
|
-
...
|
|
2863
|
+
...y
|
|
2864
2864
|
},
|
|
2865
2865
|
body: JSON.stringify(g),
|
|
2866
2866
|
credentials: i,
|
|
@@ -2899,10 +2899,10 @@ var ri = class {
|
|
|
2899
2899
|
});
|
|
2900
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,
|
|
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
|
-
credentials:
|
|
2905
|
+
credentials: y,
|
|
2906
2906
|
signal: t.abortSignal
|
|
2907
2907
|
});
|
|
2908
2908
|
if (g.status === 204) return null;
|
|
@@ -2931,25 +2931,25 @@ var ri = class {
|
|
|
2931
2931
|
get id() {
|
|
2932
2932
|
return this._id ?? (this._id = this.generateId());
|
|
2933
2933
|
}
|
|
2934
|
-
constructor({ generateId: t = Ms, id: e, transport: n = new yt(), messageMetadataSchema: r, dataPartSchemas: s, state: o, onError: l, onToolCall: u, onFinish:
|
|
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
|
-
var
|
|
2936
|
+
var O;
|
|
2937
2937
|
if (d == null) {
|
|
2938
2938
|
let M = this.pendingApprovalMessageId;
|
|
2939
2939
|
if (M == null) {
|
|
2940
|
-
M = (
|
|
2940
|
+
M = (O = this.lastMessage) == null ? void 0 : O.id;
|
|
2941
2941
|
for (let x = this.state.messages.length - 1; x >= 0; x--) {
|
|
2942
|
-
const
|
|
2943
|
-
if (
|
|
2944
|
-
M =
|
|
2942
|
+
const w = this.state.messages[x];
|
|
2943
|
+
if (w.role === "assistant" && w.parts.some((S) => pe(S) && S.state === "approval-responded")) {
|
|
2944
|
+
M = w.id;
|
|
2945
2945
|
break;
|
|
2946
2946
|
}
|
|
2947
2947
|
}
|
|
2948
2948
|
}
|
|
2949
|
-
const
|
|
2949
|
+
const N = M != null && M === this.pendingApprovalMessageId ? this.state.messages.findIndex((x) => x.id === M) : -1;
|
|
2950
2950
|
await this.makeRequestForToolApproval({
|
|
2951
2951
|
messageId: M,
|
|
2952
|
-
messageIndex:
|
|
2952
|
+
messageIndex: N,
|
|
2953
2953
|
...p
|
|
2954
2954
|
});
|
|
2955
2955
|
return;
|
|
@@ -2958,20 +2958,20 @@ var ri = class {
|
|
|
2958
2958
|
if ("text" in d || "files" in d) {
|
|
2959
2959
|
const M = new AbortController();
|
|
2960
2960
|
this.pendingMessagePreparations.add(M);
|
|
2961
|
-
let
|
|
2961
|
+
let N;
|
|
2962
2962
|
try {
|
|
2963
|
-
|
|
2963
|
+
N = Array.isArray(d.files) ? d.files : await ti(d.files);
|
|
2964
2964
|
} finally {
|
|
2965
2965
|
this.pendingMessagePreparations.delete(M);
|
|
2966
2966
|
}
|
|
2967
2967
|
if (M.signal.aborted) return;
|
|
2968
|
-
b = { parts: [...
|
|
2968
|
+
b = { parts: [...N, ..."text" in d && d.text != null ? [{
|
|
2969
2969
|
type: "text",
|
|
2970
2970
|
text: d.text
|
|
2971
2971
|
}] : []] };
|
|
2972
2972
|
} else b = d;
|
|
2973
2973
|
if (d.messageId != null) {
|
|
2974
|
-
const M = this.state.messages.findIndex((
|
|
2974
|
+
const M = this.state.messages.findIndex((N) => N.id === d.messageId);
|
|
2975
2975
|
if (M === -1) throw new ut({
|
|
2976
2976
|
parameter: "message.messageId",
|
|
2977
2977
|
value: d.messageId,
|
|
@@ -3000,7 +3000,7 @@ var ri = class {
|
|
|
3000
3000
|
...p
|
|
3001
3001
|
});
|
|
3002
3002
|
}, this.regenerate = async ({ messageId: d, ...p } = {}) => {
|
|
3003
|
-
const b = d == null ? this.state.messages.length - 1 : this.state.messages.findIndex((
|
|
3003
|
+
const b = d == null ? this.state.messages.length - 1 : this.state.messages.findIndex((O) => O.id === d);
|
|
3004
3004
|
if (b === -1) throw new ut({
|
|
3005
3005
|
parameter: "messageId",
|
|
3006
3006
|
value: d,
|
|
@@ -3021,73 +3021,73 @@ var ri = class {
|
|
|
3021
3021
|
this.resumableStreamState == null && p != null && (await p.completionPromise, this.resumableStreamState !== p.state) || this.resumableStreamState != null && d() && await this.resumeStream();
|
|
3022
3022
|
}, this.clearError = () => {
|
|
3023
3023
|
this.status === "error" && (this.state.error = void 0, this.setStatus({ status: "ready" }));
|
|
3024
|
-
}, this.addToolApprovalResponse = async ({ id: d, approved: p, reason: b, options:
|
|
3025
|
-
const M = this.state.messages,
|
|
3026
|
-
...
|
|
3024
|
+
}, this.addToolApprovalResponse = async ({ id: d, approved: p, reason: b, options: O }) => this.jobExecutor.run(async () => {
|
|
3025
|
+
const M = this.state.messages, N = (w) => pe(w) && w.state === "approval-requested" && w.approval.id === d ? {
|
|
3026
|
+
...w,
|
|
3027
3027
|
state: "approval-responded",
|
|
3028
3028
|
approval: {
|
|
3029
|
-
...
|
|
3029
|
+
...w.approval,
|
|
3030
3030
|
id: d,
|
|
3031
3031
|
approved: p,
|
|
3032
3032
|
reason: b
|
|
3033
3033
|
}
|
|
3034
|
-
} :
|
|
3034
|
+
} : w, x = M.findIndex((w) => w.parts.some((S) => pe(S) && S.state === "approval-requested" && S.approval.id === d));
|
|
3035
3035
|
if (x !== -1) {
|
|
3036
|
-
const
|
|
3036
|
+
const w = M[x];
|
|
3037
3037
|
this.state.replaceMessage(x, {
|
|
3038
|
-
...
|
|
3039
|
-
parts:
|
|
3040
|
-
}), this.pendingApprovalMessageId =
|
|
3038
|
+
...w,
|
|
3039
|
+
parts: w.parts.map(N)
|
|
3040
|
+
}), this.pendingApprovalMessageId = w.id;
|
|
3041
3041
|
}
|
|
3042
|
-
if (this.activeResponse && (this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(
|
|
3043
|
-
const
|
|
3044
|
-
|
|
3045
|
-
var
|
|
3046
|
-
const
|
|
3042
|
+
if (this.activeResponse && (this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(N)), x !== -1 && this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) {
|
|
3043
|
+
const w = await this.shouldSendAutomatically(M[x].id);
|
|
3044
|
+
w && this.runAutomaticRequest(() => {
|
|
3045
|
+
var E;
|
|
3046
|
+
const S = x === -1 ? (E = this.lastMessage) == null ? void 0 : E.id : M[x].id;
|
|
3047
3047
|
return this.makeRequestForToolApproval({
|
|
3048
|
-
messageId:
|
|
3048
|
+
messageId: S,
|
|
3049
3049
|
messageIndex: x,
|
|
3050
|
-
...
|
|
3050
|
+
...O
|
|
3051
3051
|
});
|
|
3052
|
-
},
|
|
3052
|
+
}, w);
|
|
3053
3053
|
}
|
|
3054
|
-
}), this.addToolOutput = async ({ state: d, toolCallId: p, output: b, errorText:
|
|
3055
|
-
const
|
|
3056
|
-
if (!pe(
|
|
3057
|
-
const { approval:
|
|
3058
|
-
...
|
|
3059
|
-
approved:
|
|
3054
|
+
}), this.addToolOutput = async ({ state: d, toolCallId: p, output: b, errorText: O, options: M }) => this.jobExecutor.run(async () => {
|
|
3055
|
+
const N = this.state.messages, x = (S) => {
|
|
3056
|
+
if (!pe(S) || S.toolCallId !== p) return S;
|
|
3057
|
+
const { approval: E, ...c } = S, m = (E == null ? void 0 : E.approved) === !0 ? { approval: {
|
|
3058
|
+
...E,
|
|
3059
|
+
approved: E.approved
|
|
3060
3060
|
} } : {};
|
|
3061
3061
|
return d === "output-error" ? {
|
|
3062
3062
|
...c,
|
|
3063
3063
|
...m,
|
|
3064
3064
|
state: d,
|
|
3065
|
-
input:
|
|
3065
|
+
input: S.input,
|
|
3066
3066
|
output: void 0,
|
|
3067
|
-
errorText:
|
|
3067
|
+
errorText: O
|
|
3068
3068
|
} : {
|
|
3069
3069
|
...c,
|
|
3070
3070
|
...m,
|
|
3071
3071
|
state: "output-available",
|
|
3072
|
-
input:
|
|
3072
|
+
input: S.input,
|
|
3073
3073
|
output: b,
|
|
3074
3074
|
errorText: void 0
|
|
3075
3075
|
};
|
|
3076
|
-
},
|
|
3077
|
-
if (
|
|
3078
|
-
const
|
|
3079
|
-
this.state.replaceMessage(
|
|
3080
|
-
...
|
|
3081
|
-
parts:
|
|
3076
|
+
}, w = N.findIndex((S) => S.parts.some((E) => pe(E) && E.toolCallId === p));
|
|
3077
|
+
if (w !== -1) {
|
|
3078
|
+
const S = N[w];
|
|
3079
|
+
this.state.replaceMessage(w, {
|
|
3080
|
+
...S,
|
|
3081
|
+
parts: S.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
|
|
3086
|
-
|
|
3084
|
+
if (this.activeResponse && (this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(x)), w !== -1 && this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen) {
|
|
3085
|
+
const S = await this.shouldSendAutomatically(N[w].id);
|
|
3086
|
+
S && this.runAutomaticRequest(() => this.makeRequest({
|
|
3087
3087
|
trigger: "submit-message",
|
|
3088
|
-
messageId:
|
|
3088
|
+
messageId: N[w].id,
|
|
3089
3089
|
...M
|
|
3090
|
-
}),
|
|
3090
|
+
}), S);
|
|
3091
3091
|
}
|
|
3092
3092
|
}), this.addToolResult = this.addToolOutput, this.stop = async () => {
|
|
3093
3093
|
this.activeStopCount++, this.stopGeneration++;
|
|
@@ -3101,7 +3101,7 @@ var ri = 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 = n, this.generateId = t, this.messageMetadataSchema = r, this.dataPartSchemas = s, this.state = o, this.onError = l, this.onToolCall = u, this.onFinish =
|
|
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:
|
|
@@ -3170,7 +3170,7 @@ var ri = class {
|
|
|
3170
3170
|
completionPromise: o
|
|
3171
3171
|
} : void 0;
|
|
3172
3172
|
u && ((c = this.activeResumeRequest) == null || c.abortController.abort(), this.activeResumeRequest = u);
|
|
3173
|
-
const
|
|
3173
|
+
const y = () => u == null || this.activeResumeRequest === u, g = () => {
|
|
3174
3174
|
this.activeResumeRequest === u && (this.activeResumeRequest = void 0);
|
|
3175
3175
|
};
|
|
3176
3176
|
let i;
|
|
@@ -3182,9 +3182,9 @@ var ri = class {
|
|
|
3182
3182
|
headers: n,
|
|
3183
3183
|
body: r
|
|
3184
3184
|
});
|
|
3185
|
-
if (l.signal.aborted || !
|
|
3185
|
+
if (l.signal.aborted || !y()) {
|
|
3186
3186
|
await (f == null ? void 0 : f.cancel().catch(() => {
|
|
3187
|
-
})),
|
|
3187
|
+
})), y() && (this.setStatus({ status: "ready" }), this.resumableStreamState = void 0), g();
|
|
3188
3188
|
return;
|
|
3189
3189
|
}
|
|
3190
3190
|
if (f == null) {
|
|
@@ -3194,10 +3194,10 @@ var ri = class {
|
|
|
3194
3194
|
i = f;
|
|
3195
3195
|
} catch (f) {
|
|
3196
3196
|
if (l.signal.aborted || f.name === "AbortError") {
|
|
3197
|
-
|
|
3197
|
+
y() && (this.setStatus({ status: "ready" }), this.resumableStreamState = void 0), g();
|
|
3198
3198
|
return;
|
|
3199
3199
|
}
|
|
3200
|
-
if (!
|
|
3200
|
+
if (!y()) return;
|
|
3201
3201
|
this.onError && f instanceof Error && this.onError(f), this.setStatus({
|
|
3202
3202
|
status: "error",
|
|
3203
3203
|
error: f
|
|
@@ -3208,8 +3208,8 @@ var ri = class {
|
|
|
3208
3208
|
status: "submitted",
|
|
3209
3209
|
error: void 0
|
|
3210
3210
|
});
|
|
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],
|
|
3212
|
-
let x = !1,
|
|
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], O = 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, N = p !== -1 && p < this.state.messages.length - 1 && (b == null ? void 0 : b.role) === "assistant";
|
|
3212
|
+
let x = !1, w = !1, S = !1, E;
|
|
3213
3213
|
try {
|
|
3214
3214
|
const f = {
|
|
3215
3215
|
state: t === "resume-stream" && this.resumableStreamState != null ? this.resumableStreamState : ur({
|
|
@@ -3219,11 +3219,11 @@ var ri = class {
|
|
|
3219
3219
|
abortController: l,
|
|
3220
3220
|
completionPromise: o
|
|
3221
3221
|
};
|
|
3222
|
-
|
|
3222
|
+
E = f, f.abortController.signal.addEventListener("abort", () => {
|
|
3223
3223
|
x = !0;
|
|
3224
3224
|
}), this.activeResponse = f;
|
|
3225
|
-
let
|
|
3226
|
-
t === "resume-stream" ?
|
|
3225
|
+
let h;
|
|
3226
|
+
t === "resume-stream" ? h = i : h = await this.transport.sendMessages({
|
|
3227
3227
|
chatId: this.id,
|
|
3228
3228
|
messages: this.state.messages,
|
|
3229
3229
|
abortSignal: f.abortController.signal,
|
|
@@ -3233,70 +3233,70 @@ var ri = class {
|
|
|
3233
3233
|
trigger: t,
|
|
3234
3234
|
messageId: s
|
|
3235
3235
|
});
|
|
3236
|
-
const
|
|
3236
|
+
const I = (P) => this.jobExecutor.run(() => f.abortController.signal.aborted ? Promise.resolve() : P({
|
|
3237
3237
|
state: f.state,
|
|
3238
3238
|
write: ({ updateStatus: L = !0 } = {}) => {
|
|
3239
3239
|
if (f.abortController.signal.aborted) return;
|
|
3240
3240
|
L && this.setStatus({ status: "streaming" });
|
|
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
|
-
else if (
|
|
3244
|
-
const W = this.state.messages.findLastIndex((k) => k.id ===
|
|
3243
|
+
else if (N) {
|
|
3244
|
+
const W = this.state.messages.findLastIndex((k) => k.id === O);
|
|
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
|
}
|
|
3248
3248
|
}));
|
|
3249
3249
|
if (await Qa({
|
|
3250
3250
|
stream: Ga({
|
|
3251
|
-
stream:
|
|
3251
|
+
stream: h,
|
|
3252
3252
|
resetStateOnMessageIdChange: t === "resume-stream",
|
|
3253
3253
|
resetStateOnFirstMessageStart: t === "resume-stream" && this.transport.resumeStreamIsReplay,
|
|
3254
3254
|
onToolCall: this.onToolCall,
|
|
3255
3255
|
onData: this.onData,
|
|
3256
3256
|
messageMetadataSchema: this.messageMetadataSchema,
|
|
3257
3257
|
dataPartSchemas: this.dataPartSchemas,
|
|
3258
|
-
runUpdateMessageJob:
|
|
3259
|
-
onError: (
|
|
3260
|
-
throw
|
|
3258
|
+
runUpdateMessageJob: I,
|
|
3259
|
+
onError: (P) => {
|
|
3260
|
+
throw P;
|
|
3261
3261
|
}
|
|
3262
3262
|
}),
|
|
3263
3263
|
abortSignal: f.abortController.signal,
|
|
3264
|
-
onError: (
|
|
3265
|
-
throw
|
|
3264
|
+
onError: (P) => {
|
|
3265
|
+
throw P;
|
|
3266
3266
|
}
|
|
3267
3267
|
}), x)
|
|
3268
|
-
return
|
|
3269
|
-
|
|
3268
|
+
return y() && (this.setStatus({ status: "ready" }), this.resumableStreamState === f.state && (this.resumableStreamState = void 0)), null;
|
|
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,
|
|
3273
|
-
if (!
|
|
3274
|
-
if (
|
|
3275
|
-
const
|
|
3276
|
-
|
|
3272
|
+
return x = !0, y() && (this.setStatus({ status: "ready" }), this.resumableStreamState === (E == null ? void 0 : E.state) && (this.resumableStreamState = void 0)), null;
|
|
3273
|
+
if (!y()) return null;
|
|
3274
|
+
if (S = !0, f instanceof TypeError) {
|
|
3275
|
+
const h = f.message.toLowerCase();
|
|
3276
|
+
w = h.includes("fetch") || h.includes("network") || h === "load failed";
|
|
3277
3277
|
}
|
|
3278
|
-
|
|
3278
|
+
w ? this.resumableStreamState = E == null ? void 0 : E.state : this.resumableStreamState === (E == null ? void 0 : E.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:
|
|
3286
|
-
|
|
3287
|
-
message:
|
|
3284
|
+
if (E) {
|
|
3285
|
+
const { message: f, finishReason: h } = E.state;
|
|
3286
|
+
h === "interrupted" ? this.interruptedMessageIds.add(f.id) : !x && !S && this.interruptedMessageIds.delete(f.id), (m = this.onFinish) == null || m.call(this, {
|
|
3287
|
+
message: E.state.message,
|
|
3288
3288
|
messages: this.state.messages,
|
|
3289
3289
|
isAbort: x,
|
|
3290
|
-
isDisconnect:
|
|
3291
|
-
isError:
|
|
3292
|
-
finishReason:
|
|
3290
|
+
isDisconnect: w,
|
|
3291
|
+
isError: S,
|
|
3292
|
+
finishReason: E.state.finishReason
|
|
3293
3293
|
});
|
|
3294
3294
|
}
|
|
3295
3295
|
} finally {
|
|
3296
|
-
this.activeResponse ===
|
|
3296
|
+
this.activeResponse === E && (this.activeResponse = void 0), g();
|
|
3297
3297
|
}
|
|
3298
3298
|
}
|
|
3299
|
-
!x && !
|
|
3299
|
+
!x && !S && (E == null ? void 0 : E.state.finishReason) !== "interrupted" && await this.runAutomaticRequest(() => {
|
|
3300
3300
|
var f;
|
|
3301
3301
|
return this.makeRequest({
|
|
3302
3302
|
trigger: "submit-message",
|
|
@@ -3317,7 +3317,7 @@ function ai() {
|
|
|
3317
3317
|
let r, s = 0;
|
|
3318
3318
|
return function(...l) {
|
|
3319
3319
|
clearTimeout(r);
|
|
3320
|
-
const u = Date.now(),
|
|
3320
|
+
const u = Date.now(), y = u - s, g = n - y;
|
|
3321
3321
|
g <= 0 ? (s = u, e.apply(this, l)) : r = setTimeout(() => {
|
|
3322
3322
|
s = Date.now(), e.apply(this, l);
|
|
3323
3323
|
}, g);
|
|
@@ -3457,34 +3457,34 @@ function mi({ throttle: t, experimental_throttle: e, resume: n = !1, ...r } = {}
|
|
|
3457
3457
|
transport: r.transport
|
|
3458
3458
|
});
|
|
3459
3459
|
let u;
|
|
3460
|
-
const
|
|
3460
|
+
const y = () => l.current.transport ?? u ?? (u = new yt()), g = {
|
|
3461
3461
|
...r,
|
|
3462
3462
|
transport: {
|
|
3463
3463
|
get resumeStreamIsReplay() {
|
|
3464
|
-
return
|
|
3464
|
+
return y().resumeStreamIsReplay;
|
|
3465
3465
|
},
|
|
3466
|
-
sendMessages: (
|
|
3467
|
-
reconnectToStream: (
|
|
3466
|
+
sendMessages: (S) => y().sendMessages(S),
|
|
3467
|
+
reconnectToStream: (S) => y().reconnectToStream(S)
|
|
3468
3468
|
},
|
|
3469
|
-
onToolCall: (
|
|
3470
|
-
var
|
|
3471
|
-
return (c = (
|
|
3469
|
+
onToolCall: (S) => {
|
|
3470
|
+
var E, c;
|
|
3471
|
+
return (c = (E = l.current).onToolCall) == null ? void 0 : c.call(E, S);
|
|
3472
3472
|
},
|
|
3473
|
-
onData: (
|
|
3474
|
-
var
|
|
3475
|
-
return (c = (
|
|
3473
|
+
onData: (S) => {
|
|
3474
|
+
var E, c;
|
|
3475
|
+
return (c = (E = l.current).onData) == null ? void 0 : c.call(E, S);
|
|
3476
3476
|
},
|
|
3477
|
-
onFinish: (
|
|
3478
|
-
var
|
|
3479
|
-
return (c = (
|
|
3477
|
+
onFinish: (S) => {
|
|
3478
|
+
var E, c;
|
|
3479
|
+
return (c = (E = l.current).onFinish) == null ? void 0 : c.call(E, S);
|
|
3480
3480
|
},
|
|
3481
|
-
onError: (
|
|
3482
|
-
var
|
|
3483
|
-
return (c = (
|
|
3481
|
+
onError: (S) => {
|
|
3482
|
+
var E, c;
|
|
3483
|
+
return (c = (E = l.current).onError) == null ? void 0 : c.call(E, S);
|
|
3484
3484
|
},
|
|
3485
|
-
sendAutomaticallyWhen: (
|
|
3486
|
-
var
|
|
3487
|
-
return ((c = (
|
|
3485
|
+
sendAutomaticallyWhen: (S) => {
|
|
3486
|
+
var E, c;
|
|
3487
|
+
return ((c = (E = l.current).sendAutomaticallyWhen) == null ? void 0 : c.call(E, S)) ?? !1;
|
|
3488
3488
|
}
|
|
3489
3489
|
}, i = "chat" in r ? r.chat : r.id, { chat: d, isExternallyManaged: p } = X(() => ({
|
|
3490
3490
|
chat: "chat" in r ? r.chat : new di(g),
|
|
@@ -3496,24 +3496,24 @@ function mi({ throttle: t, experimental_throttle: e, resume: n = !1, ...r } = {}
|
|
|
3496
3496
|
d.stop();
|
|
3497
3497
|
};
|
|
3498
3498
|
}, [d, p]);
|
|
3499
|
-
const [b,
|
|
3500
|
-
b.chat !== d &&
|
|
3501
|
-
let
|
|
3502
|
-
const
|
|
3503
|
-
if (!
|
|
3499
|
+
const [b, O] = J(() => ct(d));
|
|
3500
|
+
b.chat !== d && O(ct(d)), F(() => {
|
|
3501
|
+
let S = !0;
|
|
3502
|
+
const E = () => {
|
|
3503
|
+
if (!S) return;
|
|
3504
3504
|
const f = ct(d);
|
|
3505
|
-
|
|
3505
|
+
O((h) => h.chat !== d || mn(h, f) ? h : f);
|
|
3506
3506
|
}, c = [
|
|
3507
|
-
d["~registerMessagesCallback"](
|
|
3508
|
-
d["~registerStatusCallback"](
|
|
3509
|
-
d["~registerErrorCallback"](
|
|
3507
|
+
d["~registerMessagesCallback"](E, s),
|
|
3508
|
+
d["~registerStatusCallback"](E),
|
|
3509
|
+
d["~registerErrorCallback"](E)
|
|
3510
3510
|
], m = ct(d);
|
|
3511
|
-
return
|
|
3512
|
-
|
|
3511
|
+
return O((f) => mn(f, m) ? f : m), () => {
|
|
3512
|
+
S = !1, c.forEach((f) => f());
|
|
3513
3513
|
};
|
|
3514
3514
|
}, [d, s]);
|
|
3515
|
-
const { messages: M, status:
|
|
3516
|
-
typeof
|
|
3515
|
+
const { messages: M, status: N, error: x } = b, w = z((S) => {
|
|
3516
|
+
typeof S == "function" && (S = S(d.messages)), d.messages = S;
|
|
3517
3517
|
}, [d]);
|
|
3518
3518
|
return F(() => {
|
|
3519
3519
|
if (n) return fi({
|
|
@@ -3525,14 +3525,14 @@ function mi({ throttle: t, experimental_throttle: e, resume: n = !1, ...r } = {}
|
|
|
3525
3525
|
return d.id;
|
|
3526
3526
|
},
|
|
3527
3527
|
messages: M,
|
|
3528
|
-
setMessages:
|
|
3528
|
+
setMessages: w,
|
|
3529
3529
|
sendMessage: d.sendMessage,
|
|
3530
3530
|
regenerate: d.regenerate,
|
|
3531
3531
|
clearError: d.clearError,
|
|
3532
3532
|
stop: d.stop,
|
|
3533
3533
|
error: x,
|
|
3534
3534
|
resumeStream: d.resumeStream,
|
|
3535
|
-
status:
|
|
3535
|
+
status: N,
|
|
3536
3536
|
/**
|
|
3537
3537
|
* @deprecated Use `addToolOutput` instead.
|
|
3538
3538
|
*/
|
|
@@ -3822,7 +3822,7 @@ class Ni extends yt {
|
|
|
3822
3822
|
}
|
|
3823
3823
|
/** The recovered stream; otherwise the original error is rethrown. */
|
|
3824
3824
|
async readThroughRecoveryFetch(e, n, r) {
|
|
3825
|
-
var l, u,
|
|
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);
|
|
3828
3828
|
if (!s) throw e;
|
|
@@ -3835,7 +3835,7 @@ class Ni extends yt {
|
|
|
3835
3835
|
)
|
|
3836
3836
|
});
|
|
3837
3837
|
for (const d of Ri) {
|
|
3838
|
-
if (await Pi(d, r.abortSignal), (
|
|
3838
|
+
if (await Pi(d, r.abortSignal), (y = r.abortSignal) != null && y.aborted) throw e;
|
|
3839
3839
|
let p;
|
|
3840
3840
|
try {
|
|
3841
3841
|
p = await o.reconnectToStream(r);
|
|
@@ -3861,16 +3861,16 @@ function Di({
|
|
|
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
|
|
3865
|
-
if (
|
|
3866
|
-
ki(
|
|
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) {
|
|
3870
3870
|
const g = pt(u.ui_parts);
|
|
3871
3871
|
if (g.length === 0) continue;
|
|
3872
3872
|
o.push({
|
|
3873
|
-
key: (
|
|
3873
|
+
key: (y == null ? void 0 : y.key) ?? `turn-${u.turn_id}`,
|
|
3874
3874
|
turnId: u.turn_id,
|
|
3875
3875
|
rowIds: u.message_uuids,
|
|
3876
3876
|
items: g
|
|
@@ -3879,7 +3879,7 @@ function Di({
|
|
|
3879
3879
|
}
|
|
3880
3880
|
for (const u of t)
|
|
3881
3881
|
s.has(u.turnId) || o.push(u);
|
|
3882
|
-
return o.length === t.length && o.every((u,
|
|
3882
|
+
return o.length === t.length && o.every((u, y) => u === t[y]) ? t : o;
|
|
3883
3883
|
}
|
|
3884
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
3885
|
function In(t) {
|
|
@@ -3940,7 +3940,7 @@ function Vi({
|
|
|
3940
3940
|
l.current = e;
|
|
3941
3941
|
const {
|
|
3942
3942
|
pageContext: u,
|
|
3943
|
-
clientTools:
|
|
3943
|
+
clientTools: y,
|
|
3944
3944
|
pageActions: g
|
|
3945
3945
|
} = t.features, i = R(() => {
|
|
3946
3946
|
}), d = X(
|
|
@@ -3953,9 +3953,9 @@ 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,
|
|
3956
|
+
fetch: (v, C) => s.withRenewal(l.current.streamingFetch ?? globalThis.fetch)(
|
|
3957
3957
|
v,
|
|
3958
|
-
|
|
3958
|
+
C
|
|
3959
3959
|
),
|
|
3960
3960
|
// A `streamingFetch` whose response cannot be read (one rebuilt with
|
|
3961
3961
|
// React Native's global Response) leaves the reply to the global
|
|
@@ -3963,26 +3963,26 @@ function Vi({
|
|
|
3963
3963
|
// fetch already failed, so there is nothing else to try.
|
|
3964
3964
|
recoveryFetch: () => {
|
|
3965
3965
|
const v = l.current.streamingFetch;
|
|
3966
|
-
return v && v !== globalThis.fetch ? (
|
|
3966
|
+
return v && v !== globalThis.fetch ? (C, T) => globalThis.fetch(C, T) : void 0;
|
|
3967
3967
|
},
|
|
3968
|
-
onRecovered: (v,
|
|
3968
|
+
onRecovered: (v, C) => i.current(v, C)
|
|
3969
3969
|
}),
|
|
3970
3970
|
[s]
|
|
3971
|
-
), [p, b] = J(null),
|
|
3972
|
-
() => n !== null && !(
|
|
3971
|
+
), [p, b] = J(null), O = R(!1), [M] = J(Rt), N = R(Promise.resolve()), x = R(0), w = R(0), S = R(n), E = X(
|
|
3972
|
+
() => n !== null && !(S.current === null && x.current > 0),
|
|
3973
3973
|
[n]
|
|
3974
3974
|
), c = R(() => {
|
|
3975
3975
|
}), {
|
|
3976
3976
|
status: m,
|
|
3977
3977
|
messages: f,
|
|
3978
|
-
sendMessage:
|
|
3979
|
-
stop:
|
|
3980
|
-
error:
|
|
3978
|
+
sendMessage: h,
|
|
3979
|
+
stop: I,
|
|
3980
|
+
error: P,
|
|
3981
3981
|
clearError: L,
|
|
3982
3982
|
resumeStream: B
|
|
3983
3983
|
} = mi({
|
|
3984
3984
|
id: n ?? M,
|
|
3985
|
-
resume:
|
|
3985
|
+
resume: E,
|
|
3986
3986
|
transport: d,
|
|
3987
3987
|
// Batch token updates: without it every streamed token re-renders the
|
|
3988
3988
|
// whole chat surface (transcript + composer), which stutters on long
|
|
@@ -3995,8 +3995,8 @@ function Vi({
|
|
|
3995
3995
|
const k = R(new gn(Cn));
|
|
3996
3996
|
F(() => {
|
|
3997
3997
|
if (!p || p.messages !== f) return;
|
|
3998
|
-
const { isAbort: v, isDisconnect:
|
|
3999
|
-
v ||
|
|
3998
|
+
const { isAbort: v, isDisconnect: C, isError: T, message: A } = p;
|
|
3999
|
+
v || C || T || k.current.size > 0 || o.state.setPartial({
|
|
4000
4000
|
lastAIResMightSolveUserIssue: _n(A.metadata) && A.metadata.mightSolveUserIssue === !0
|
|
4001
4001
|
});
|
|
4002
4002
|
}, [p, f, o]);
|
|
@@ -4006,11 +4006,11 @@ function Vi({
|
|
|
4006
4006
|
Ye.current = v, Cr(v);
|
|
4007
4007
|
}, []), Ue = R(null), we = R(null), Ae = R(null), Wt = R(n);
|
|
4008
4008
|
Wt.current = n;
|
|
4009
|
-
const Jt = (v,
|
|
4009
|
+
const Jt = (v, C, T) => {
|
|
4010
4010
|
const A = Wt.current;
|
|
4011
4011
|
A && s.reportClientStreamError(A, {
|
|
4012
4012
|
...En(v),
|
|
4013
|
-
phase:
|
|
4013
|
+
phase: C,
|
|
4014
4014
|
recovered: T,
|
|
4015
4015
|
widget_version: Pn,
|
|
4016
4016
|
platform: typeof navigator < "u" && navigator.product === "ReactNative" ? "react-native" : "web"
|
|
@@ -4020,29 +4020,29 @@ function Vi({
|
|
|
4020
4020
|
le.error("agent chat stream error", v), En(v).kind === "empty_body" && le.error(
|
|
4021
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."
|
|
4022
4022
|
);
|
|
4023
|
-
const
|
|
4024
|
-
|
|
4023
|
+
const C = $.current === "in-flight" ? "send" : "resume", T = we.current;
|
|
4024
|
+
C === "send" && T ? Ae.current = {
|
|
4025
4025
|
kind: "send",
|
|
4026
4026
|
wireId: T.retryUuid ?? T.userMessage.id,
|
|
4027
4027
|
bubbleId: T.userMessage.id
|
|
4028
|
-
} :
|
|
4028
|
+
} : C === "resume" && Ae.current === null && (Ae.current = { kind: "resume" }), Jt(v, C, !1);
|
|
4029
4029
|
};
|
|
4030
4030
|
const Ht = R(!1);
|
|
4031
|
-
i.current = (v,
|
|
4031
|
+
i.current = (v, C) => {
|
|
4032
4032
|
Ht.current || (Ht.current = !0, le.warn(
|
|
4033
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."
|
|
4034
|
-
)), Jt(
|
|
4034
|
+
)), Jt(C, v, !0);
|
|
4035
4035
|
};
|
|
4036
|
-
const qe = R(m), Ke =
|
|
4036
|
+
const qe = R(m), Ke = S.current === n, Et = R(null), Ct = R(null), Yt = R(I), xe = R(m);
|
|
4037
4037
|
xe.current = m;
|
|
4038
|
-
const tt = z((v,
|
|
4038
|
+
const tt = z((v, C) => {
|
|
4039
4039
|
const T = In(v.parts);
|
|
4040
4040
|
if (!T || T.rowIds.length === 0) return;
|
|
4041
4041
|
const A = pt(v.parts);
|
|
4042
4042
|
A.length !== 0 && U(
|
|
4043
4043
|
(j) => j.some((Y) => Y.turnId === T.turnId) ? j : [
|
|
4044
4044
|
...j,
|
|
4045
|
-
{ key:
|
|
4045
|
+
{ key: C, turnId: T.turnId, rowIds: T.rowIds, items: A }
|
|
4046
4046
|
]
|
|
4047
4047
|
);
|
|
4048
4048
|
}, []), Kt = z(
|
|
@@ -4059,18 +4059,18 @@ function Vi({
|
|
|
4059
4059
|
);
|
|
4060
4060
|
F(() => {
|
|
4061
4061
|
const v = Yt.current;
|
|
4062
|
-
Yt.current =
|
|
4063
|
-
const
|
|
4064
|
-
if (
|
|
4065
|
-
if (
|
|
4062
|
+
Yt.current = I;
|
|
4063
|
+
const C = S.current;
|
|
4064
|
+
if (C === n) return;
|
|
4065
|
+
if (S.current = n, C === null) {
|
|
4066
4066
|
U([]);
|
|
4067
4067
|
return;
|
|
4068
4068
|
}
|
|
4069
4069
|
const T = xe.current === "submitted" || xe.current === "streaming" || qe.current === "submitted" || qe.current === "streaming" || $.current === "in-flight";
|
|
4070
|
-
|
|
4070
|
+
w.current += 1, x.current = 0, N.current = Promise.resolve(), k.current = new gn(Cn), $.current = "idle", Ie(!1), we.current = null, Ae.current = null, Ue.current = null, b(null), O.current = !1, Ct.current = null, Et.current = m === "submitted" || m === "streaming" ? m : null, qe.current = "ready", xe.current = "ready", L(), ae((A) => A + 1), de(!1), U([]), Re(null), T && Promise.resolve().then(() => v()).catch((A) => {
|
|
4071
4071
|
le.error("agent chat client stream cancel failed", A);
|
|
4072
4072
|
});
|
|
4073
|
-
}, [n, m,
|
|
4073
|
+
}, [n, m, I, L, Re]), F(() => {
|
|
4074
4074
|
var j, Y;
|
|
4075
4075
|
const v = Et.current;
|
|
4076
4076
|
if (v !== null && m === v) {
|
|
@@ -4078,14 +4078,14 @@ function Vi({
|
|
|
4078
4078
|
return;
|
|
4079
4079
|
}
|
|
4080
4080
|
Et.current = null;
|
|
4081
|
-
const
|
|
4082
|
-
if (qe.current = m, (m === "submitted" || m === "streaming") && (
|
|
4081
|
+
const C = qe.current;
|
|
4082
|
+
if (qe.current = m, (m === "submitted" || m === "streaming") && (C !== "submitted" && C !== "streaming" && Ye.current === null && Re(`turn-resumed-${Rt()}`), de(!0)), m === "streaming") {
|
|
4083
4083
|
const Z = (j = we.current) == null ? void 0 : j.userMessage.id;
|
|
4084
4084
|
Z && o.markUserMessageDelivered(Z);
|
|
4085
4085
|
return;
|
|
4086
4086
|
}
|
|
4087
4087
|
if (m !== "ready" && m !== "error") return;
|
|
4088
|
-
if (
|
|
4088
|
+
if (C === "streaming" || C === "submitted" || // An empty response can finish before React observes an active status.
|
|
4089
4089
|
$.current === "in-flight" && (p == null ? void 0 : p.messages) === W.current) {
|
|
4090
4090
|
de(!0);
|
|
4091
4091
|
const Z = $.current === "in-flight";
|
|
@@ -4094,7 +4094,7 @@ function Vi({
|
|
|
4094
4094
|
if (Ue.current = be, be !== null && re && re.role === "assistant" && tt(re, be), m === "ready") {
|
|
4095
4095
|
const Pe = (Y = we.current) == null ? void 0 : Y.userMessage.id;
|
|
4096
4096
|
Pe && o.markUserMessageDelivered(Pe);
|
|
4097
|
-
} else Z &&
|
|
4097
|
+
} else Z && C !== "streaming" && we.current && o.releaseUnsentOptionPick(we.current.input);
|
|
4098
4098
|
$.current === "stopping" || (n ? ($.current = "reconciling", t.reconcileAfterStream(n).catch((Pe) => {
|
|
4099
4099
|
le.error("agent chat post-turn reconcile failed", Pe);
|
|
4100
4100
|
}).finally(() => {
|
|
@@ -4103,7 +4103,7 @@ function Vi({
|
|
|
4103
4103
|
}
|
|
4104
4104
|
if ($.current !== "idle" || !n || fe.current && m !== "error") return;
|
|
4105
4105
|
const A = k.current.dequeueNext();
|
|
4106
|
-
A && ($.current = "in-flight", Ie(!1), we.current = A, Ae.current = null, b(null),
|
|
4106
|
+
A && ($.current = "in-flight", Ie(!1), we.current = A, Ae.current = null, b(null), O.current = !1, Re(`turn-${A.userMessage.id}`), o.appendUserMessageIfAbsent(A.userMessage), ae((Z) => Z + 1), h(
|
|
4107
4107
|
{ text: A.userMessage.content },
|
|
4108
4108
|
{ body: Kt(A) }
|
|
4109
4109
|
));
|
|
@@ -4111,7 +4111,7 @@ function Vi({
|
|
|
4111
4111
|
m,
|
|
4112
4112
|
n,
|
|
4113
4113
|
ve,
|
|
4114
|
-
|
|
4114
|
+
h,
|
|
4115
4115
|
o,
|
|
4116
4116
|
t,
|
|
4117
4117
|
Kt,
|
|
@@ -4121,13 +4121,13 @@ function Vi({
|
|
|
4121
4121
|
]);
|
|
4122
4122
|
const Gt = z(
|
|
4123
4123
|
(v) => {
|
|
4124
|
-
const
|
|
4124
|
+
const C = w.current;
|
|
4125
4125
|
x.current++;
|
|
4126
|
-
const A =
|
|
4126
|
+
const A = N.current.then(
|
|
4127
4127
|
async () => {
|
|
4128
|
-
if (
|
|
4128
|
+
if (C !== w.current) return;
|
|
4129
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 ||
|
|
4130
|
+
if (!Z || C !== w.current) return;
|
|
4131
4131
|
const re = { ...Z, input: v };
|
|
4132
4132
|
if (!k.current.enqueue(re)) {
|
|
4133
4133
|
le.warn("agent chat queue full; rejecting newest send", {
|
|
@@ -4138,9 +4138,9 @@ function Vi({
|
|
|
4138
4138
|
ae((be) => be + 1), o.notifySendAccepted(v);
|
|
4139
4139
|
}
|
|
4140
4140
|
).finally(() => {
|
|
4141
|
-
|
|
4141
|
+
C === w.current && x.current--;
|
|
4142
4142
|
});
|
|
4143
|
-
return
|
|
4143
|
+
return N.current = A.then(
|
|
4144
4144
|
() => {
|
|
4145
4145
|
},
|
|
4146
4146
|
() => {
|
|
@@ -4152,8 +4152,8 @@ function Vi({
|
|
|
4152
4152
|
var Y;
|
|
4153
4153
|
const v = we.current;
|
|
4154
4154
|
if (!v) return;
|
|
4155
|
-
const
|
|
4156
|
-
if (
|
|
4155
|
+
const C = v.input.optionReply, T = C ? r.find((Z) => Z.id === C.messageId) : void 0, A = T && Ur(T) ? (Y = T.messageOptions) == null ? void 0 : Y.pickedOptionId : null;
|
|
4156
|
+
if (C && A && A !== C.optionId) return;
|
|
4157
4157
|
if (!k.current.enqueue({
|
|
4158
4158
|
...v,
|
|
4159
4159
|
retryUuid: Rt()
|
|
@@ -4161,36 +4161,36 @@ function Vi({
|
|
|
4161
4161
|
le.warn("agent chat queue full; retry not enqueued");
|
|
4162
4162
|
return;
|
|
4163
4163
|
}
|
|
4164
|
-
|
|
4164
|
+
C && o.setMessageOptionPick(C.messageId, C.optionId), L(), ae((Z) => Z + 1);
|
|
4165
4165
|
}, [L, o, r]), Ar = z(
|
|
4166
4166
|
(v) => {
|
|
4167
|
-
const
|
|
4167
|
+
const C = k.current.removeWhere(
|
|
4168
4168
|
(T) => T.userMessage.id === v
|
|
4169
4169
|
);
|
|
4170
|
-
|
|
4170
|
+
C && (o.releaseUnsentOptionPick(C.input), ae((T) => T + 1));
|
|
4171
4171
|
},
|
|
4172
4172
|
[o]
|
|
4173
4173
|
), xr = z(() => {
|
|
4174
|
-
$.current = "stopping", Ie(!0),
|
|
4175
|
-
const v =
|
|
4176
|
-
Fi({ api: s, sessionId: n, chatStop:
|
|
4177
|
-
v ===
|
|
4178
|
-
}).catch((
|
|
4179
|
-
le.error("agent chat stop failed",
|
|
4174
|
+
$.current = "stopping", Ie(!0), O.current = !1;
|
|
4175
|
+
const v = w.current;
|
|
4176
|
+
Fi({ api: s, sessionId: n, chatStop: I }).then(() => {
|
|
4177
|
+
v === w.current && (O.current = !0);
|
|
4178
|
+
}).catch((C) => {
|
|
4179
|
+
le.error("agent chat stop failed", C);
|
|
4180
4180
|
}).then(() => {
|
|
4181
|
-
if (v ===
|
|
4181
|
+
if (v === w.current) {
|
|
4182
4182
|
if (!n) {
|
|
4183
4183
|
de(!1);
|
|
4184
4184
|
return;
|
|
4185
4185
|
}
|
|
4186
|
-
return t.reconcileAfterStream(n).catch((
|
|
4187
|
-
le.error("agent chat post-stop reconcile failed",
|
|
4186
|
+
return t.reconcileAfterStream(n).catch((C) => {
|
|
4187
|
+
le.error("agent chat post-stop reconcile failed", C);
|
|
4188
4188
|
});
|
|
4189
4189
|
}
|
|
4190
4190
|
}).finally(() => {
|
|
4191
|
-
v ===
|
|
4191
|
+
v === w.current && ($.current = "idle", ae((C) => C + 1));
|
|
4192
4192
|
});
|
|
4193
|
-
}, [s, n,
|
|
4193
|
+
}, [s, n, I, t]);
|
|
4194
4194
|
F(() => {
|
|
4195
4195
|
const v = {
|
|
4196
4196
|
send: Gt,
|
|
@@ -4202,7 +4202,7 @@ function Vi({
|
|
|
4202
4202
|
F(() => Ce([]), [n]), F(() => {
|
|
4203
4203
|
var j, Y;
|
|
4204
4204
|
if (!n) return;
|
|
4205
|
-
const v = nt === void 0 && rt === void 0 ? void 0 : { toolActivity: nt, reasoning: rt },
|
|
4205
|
+
const v = nt === void 0 && rt === void 0 ? void 0 : { toolActivity: nt, reasoning: rt }, C = Ct.current, T = (C == null ? void 0 : C.sessionId) === n && (((j = C.presentation) == null ? void 0 : j.toolActivity) !== nt || ((Y = C.presentation) == null ? void 0 : Y.reasoning) !== rt);
|
|
4206
4206
|
Ct.current = { sessionId: n, presentation: v };
|
|
4207
4207
|
let A = !1;
|
|
4208
4208
|
return (async () => {
|
|
@@ -4224,31 +4224,31 @@ function Vi({
|
|
|
4224
4224
|
return [];
|
|
4225
4225
|
const v = f.at(-1);
|
|
4226
4226
|
if (!v || v.role !== "assistant") return [];
|
|
4227
|
-
const
|
|
4227
|
+
const C = [];
|
|
4228
4228
|
for (const T of v.parts) {
|
|
4229
4229
|
if (!pe(T)) continue;
|
|
4230
4230
|
const A = Ka(T), j = A === zi ? "highlight-element" : A === Zi ? "act-on-page" : null;
|
|
4231
|
-
j && T.state === "input-available" &&
|
|
4231
|
+
j && T.state === "input-available" && C.push({
|
|
4232
4232
|
key: `${n ?? "pending"}:${T.toolCallId}`,
|
|
4233
4233
|
type: j,
|
|
4234
4234
|
input: T.input,
|
|
4235
4235
|
callId: T.toolCallId
|
|
4236
4236
|
});
|
|
4237
4237
|
}
|
|
4238
|
-
return
|
|
4238
|
+
return C;
|
|
4239
4239
|
}, [f, n, m, Se]), Mr = X(
|
|
4240
4240
|
() => at.filter(
|
|
4241
|
-
(v) => u &&
|
|
4241
|
+
(v) => u && y && (v.type !== "act-on-page" || g) && !wt.has(v.key)
|
|
4242
4242
|
),
|
|
4243
4243
|
[
|
|
4244
4244
|
at,
|
|
4245
4245
|
u,
|
|
4246
|
-
|
|
4246
|
+
y,
|
|
4247
4247
|
g,
|
|
4248
4248
|
wt
|
|
4249
4249
|
]
|
|
4250
4250
|
), xt = z(
|
|
4251
|
-
(v,
|
|
4251
|
+
(v, C, T, A) => {
|
|
4252
4252
|
if (!n) return;
|
|
4253
4253
|
const j = `${n}:${v}`;
|
|
4254
4254
|
if (st.current.has(j)) return;
|
|
@@ -4260,7 +4260,7 @@ function Vi({
|
|
|
4260
4260
|
}
|
|
4261
4261
|
st.current = Y, Tr(Y), s.sendPageReply(n, {
|
|
4262
4262
|
callId: v,
|
|
4263
|
-
outcome:
|
|
4263
|
+
outcome: C,
|
|
4264
4264
|
...T ? { detail: T } : {},
|
|
4265
4265
|
// The page as it is after the action. Without it a flow that
|
|
4266
4266
|
// crosses screens stops dead: the agent is holding refs to the
|
|
@@ -4272,28 +4272,28 @@ function Vi({
|
|
|
4272
4272
|
), [_r, Tt] = J(null), Te = R(
|
|
4273
4273
|
/* @__PURE__ */ new Map()
|
|
4274
4274
|
), Rr = z(
|
|
4275
|
-
(v) => new Promise((
|
|
4275
|
+
(v) => new Promise((C) => {
|
|
4276
4276
|
const T = `${n ?? "pending"}:${v.callId}`;
|
|
4277
4277
|
if (st.current.has(T)) {
|
|
4278
|
-
|
|
4278
|
+
C(!1);
|
|
4279
4279
|
return;
|
|
4280
4280
|
}
|
|
4281
|
-
At.current.add(T), Te.current.forEach((A) => A(!1)), Te.current.clear(), Te.current.set(v.callId,
|
|
4281
|
+
At.current.add(T), Te.current.forEach((A) => A(!1)), Te.current.clear(), Te.current.set(v.callId, C), Tt(v);
|
|
4282
4282
|
}),
|
|
4283
4283
|
[n]
|
|
4284
|
-
), Mt = z((v,
|
|
4284
|
+
), Mt = z((v, C) => {
|
|
4285
4285
|
const T = Te.current.get(v);
|
|
4286
4286
|
Te.current.delete(v), Tt(
|
|
4287
4287
|
(A) => (A == null ? void 0 : A.callId) === v ? null : A
|
|
4288
|
-
), T == null || T(
|
|
4288
|
+
), T == null || T(C);
|
|
4289
4289
|
}, []);
|
|
4290
4290
|
F(() => {
|
|
4291
4291
|
for (const v of at)
|
|
4292
|
-
u &&
|
|
4292
|
+
u && y && (v.type !== "act-on-page" || g) || (Mt(v.callId, !1), At.current.has(v.key) || xt(v.callId, "declined"));
|
|
4293
4293
|
}, [
|
|
4294
4294
|
at,
|
|
4295
4295
|
u,
|
|
4296
|
-
|
|
4296
|
+
y,
|
|
4297
4297
|
g,
|
|
4298
4298
|
Mt,
|
|
4299
4299
|
xt
|
|
@@ -4302,11 +4302,11 @@ function Vi({
|
|
|
4302
4302
|
F(() => {
|
|
4303
4303
|
var Z;
|
|
4304
4304
|
const v = Ae.current;
|
|
4305
|
-
if (
|
|
4306
|
-
const
|
|
4305
|
+
if (P === void 0 || oe || !v || !n) return;
|
|
4306
|
+
const C = v.kind === "send" ? v.wireId : (Z = r.findLast(
|
|
4307
4307
|
(re) => re.type === "USER" && !re.pending
|
|
4308
4308
|
)) == null ? void 0 : Z.id;
|
|
4309
|
-
if (
|
|
4309
|
+
if (C === void 0) return;
|
|
4310
4310
|
const T = new Set(r.map((re) => re.id));
|
|
4311
4311
|
let A = !1, j;
|
|
4312
4312
|
const Y = async (re) => {
|
|
@@ -4319,7 +4319,7 @@ function Vi({
|
|
|
4319
4319
|
}
|
|
4320
4320
|
if (A || Ae.current !== v) return;
|
|
4321
4321
|
if (be == null ? void 0 : be.turns.some(
|
|
4322
|
-
(lt) => (lt.input_message_uuids ?? []).includes(
|
|
4322
|
+
(lt) => (lt.input_message_uuids ?? []).includes(C) && lt.message_uuids.some((Dr) => T.has(Dr))
|
|
4323
4323
|
)) {
|
|
4324
4324
|
Ae.current = null, v.kind === "send" && o.markUserMessageDelivered(v.bubbleId), L();
|
|
4325
4325
|
return;
|
|
@@ -4331,7 +4331,7 @@ function Vi({
|
|
|
4331
4331
|
A = !0, j !== void 0 && clearTimeout(j);
|
|
4332
4332
|
};
|
|
4333
4333
|
}, [
|
|
4334
|
-
|
|
4334
|
+
P,
|
|
4335
4335
|
oe,
|
|
4336
4336
|
r,
|
|
4337
4337
|
n,
|
|
@@ -4346,17 +4346,17 @@ function Vi({
|
|
|
4346
4346
|
), F(() => {
|
|
4347
4347
|
if (oe && !Se) return;
|
|
4348
4348
|
const v = Te.current;
|
|
4349
|
-
v.size !== 0 && (v.forEach((
|
|
4349
|
+
v.size !== 0 && (v.forEach((C) => C(!1)), v.clear(), Tt(null));
|
|
4350
4350
|
}, [oe, Se]), F(() => {
|
|
4351
4351
|
if (oe) return;
|
|
4352
4352
|
const v = Ue.current;
|
|
4353
4353
|
if (v === null) return;
|
|
4354
|
-
const
|
|
4355
|
-
|
|
4354
|
+
const C = f.at(-1);
|
|
4355
|
+
C && C.role === "assistant" && tt(C, v);
|
|
4356
4356
|
}, [f, oe, tt]);
|
|
4357
4357
|
const _t = z(() => {
|
|
4358
|
-
n && (oe ||
|
|
4359
|
-
}, [n, oe, G,
|
|
4358
|
+
n && (oe || P === void 0 && !G || B());
|
|
4359
|
+
}, [n, oe, G, P, B]);
|
|
4360
4360
|
F(
|
|
4361
4361
|
() => $i(_t),
|
|
4362
4362
|
[_t]
|
|
@@ -4365,7 +4365,7 @@ function Vi({
|
|
|
4365
4365
|
const v = () => {
|
|
4366
4366
|
de(!1), ae((A) => A + 1), Ye.current === Ue.current && Re(null), Ue.current = null;
|
|
4367
4367
|
};
|
|
4368
|
-
if (Ye.current === Ue.current && (p == null ? void 0 : p.messages) === f && !p.isError && !p.isDisconnect && (!p.isAbort ||
|
|
4368
|
+
if (Ye.current === Ue.current && (p == null ? void 0 : p.messages) === f && !p.isError && !p.isDisconnect && (!p.isAbort || O.current) && !pt(p.message.parts).some(
|
|
4369
4369
|
(A) => A.kind !== "steps"
|
|
4370
4370
|
)) {
|
|
4371
4371
|
const A = r.findLast((j) => j.type === "USER");
|
|
@@ -4373,7 +4373,7 @@ function Vi({
|
|
|
4373
4373
|
return;
|
|
4374
4374
|
}
|
|
4375
4375
|
if (p && p.messages !== f) return;
|
|
4376
|
-
const
|
|
4376
|
+
const C = f.at(-1), T = (C == null ? void 0 : C.role) === "assistant" ? In(C.parts) : null;
|
|
4377
4377
|
if (T && T.rowIds.length > 0) {
|
|
4378
4378
|
const A = new Set(r.map((j) => j.id));
|
|
4379
4379
|
T.rowIds.every((j) => A.has(j)) && v();
|
|
@@ -4421,11 +4421,11 @@ function Vi({
|
|
|
4421
4421
|
me
|
|
4422
4422
|
]), Or = X(
|
|
4423
4423
|
() => Ke ? Ee.flatMap((v) => {
|
|
4424
|
-
const
|
|
4424
|
+
const C = hn(v.items, {
|
|
4425
4425
|
toolActivity: it,
|
|
4426
4426
|
reasoning: ot
|
|
4427
4427
|
});
|
|
4428
|
-
return
|
|
4428
|
+
return C.length === 0 ? [] : [C === v.items ? v : { ...v, items: C }];
|
|
4429
4429
|
}) : [],
|
|
4430
4430
|
[Ee, it, ot, Ke]
|
|
4431
4431
|
), Nr = X(
|
|
@@ -4441,7 +4441,7 @@ function Vi({
|
|
|
4441
4441
|
/** The live turn's node key (stable through the retained promotion). */
|
|
4442
4442
|
liveTurnKey: me,
|
|
4443
4443
|
/** The last turn failed — the transcript renders a visible error row. */
|
|
4444
|
-
turnFailed:
|
|
4444
|
+
turnFailed: P !== void 0,
|
|
4445
4445
|
retryFailedTurn: wr,
|
|
4446
4446
|
resumeInterruptedTurn: _t,
|
|
4447
4447
|
queuedUserMessages: Nr,
|
|
@@ -4481,23 +4481,23 @@ function Hi({
|
|
|
4481
4481
|
widgetCtx: n,
|
|
4482
4482
|
onHandled: r
|
|
4483
4483
|
}) {
|
|
4484
|
-
const [s, o] = J("idle"), [l, u] = J(null), [
|
|
4484
|
+
const [s, o] = J("idle"), [l, u] = J(null), [y, g] = J(
|
|
4485
4485
|
null
|
|
4486
|
-
), [i, d] = J(null), p = R(new AbortController()), b = R(null),
|
|
4487
|
-
|
|
4488
|
-
const
|
|
4486
|
+
), [i, d] = J(null), p = R(new AbortController()), b = R(null), O = R(/* @__PURE__ */ new Set()), M = R(null), N = R(null), x = R(null), w = R(!0), S = R((e == null ? void 0 : e.request_id) ?? null);
|
|
4487
|
+
S.current = (e == null ? void 0 : e.request_id) ?? null;
|
|
4488
|
+
const E = z(() => {
|
|
4489
4489
|
var L;
|
|
4490
4490
|
p.current.abort(), (L = b.current) == null || L.close(), b.current = null;
|
|
4491
4491
|
}, []);
|
|
4492
|
-
F(() => (
|
|
4493
|
-
|
|
4494
|
-
}), [
|
|
4492
|
+
F(() => (E(), x.current = null, N.current = null, M.current = null, o("idle"), u(null), g(null), d(null), E), [E, e == null ? void 0 : e.request_id, e == null ? void 0 : e.server_id, n]), F(() => (w.current = !0, () => {
|
|
4493
|
+
w.current = !1, E();
|
|
4494
|
+
}), [E]);
|
|
4495
4495
|
const c = z(
|
|
4496
4496
|
async (L) => {
|
|
4497
4497
|
if (!e) return;
|
|
4498
4498
|
const B = e.request_id;
|
|
4499
|
-
if (
|
|
4500
|
-
|
|
4499
|
+
if (O.current.has(B)) return;
|
|
4500
|
+
O.current.add(B), M.current = L, g(L), d(null);
|
|
4501
4501
|
let W = !1;
|
|
4502
4502
|
try {
|
|
4503
4503
|
await n.messageCtx.sendMessage({
|
|
@@ -4505,22 +4505,22 @@ function Hi({
|
|
|
4505
4505
|
onAccepted: () => {
|
|
4506
4506
|
W = !0, r(e.request_id);
|
|
4507
4507
|
}
|
|
4508
|
-
}),
|
|
4508
|
+
}), w.current && S.current === B && !W && d(
|
|
4509
4509
|
L === "renew" ? "Could not request a new connection. Try again." : "Could not continue your request. Try again."
|
|
4510
4510
|
);
|
|
4511
4511
|
} catch {
|
|
4512
|
-
|
|
4512
|
+
w.current && S.current === B && d(
|
|
4513
4513
|
L === "renew" ? "Could not request a new connection. Try again." : "Could not continue your request. Try again."
|
|
4514
4514
|
);
|
|
4515
4515
|
} finally {
|
|
4516
|
-
|
|
4516
|
+
O.current.delete(B), w.current && S.current === B && g(null);
|
|
4517
4517
|
}
|
|
4518
4518
|
},
|
|
4519
4519
|
[r, e, n]
|
|
4520
4520
|
), m = z(async () => {
|
|
4521
4521
|
var B, W;
|
|
4522
4522
|
if (!e) return;
|
|
4523
|
-
|
|
4523
|
+
E(), x.current = e.request_id, p.current = new AbortController();
|
|
4524
4524
|
const { signal: L } = p.current;
|
|
4525
4525
|
o("loading"), M.current = null, u(null), d(null);
|
|
4526
4526
|
try {
|
|
@@ -4539,7 +4539,7 @@ function Hi({
|
|
|
4539
4539
|
host: $.host,
|
|
4540
4540
|
completion: k.completion,
|
|
4541
4541
|
...k.completion === "oauth" ? { attemptId: k.attempt_id } : {}
|
|
4542
|
-
}),
|
|
4542
|
+
}), N.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
4543
|
} catch (k) {
|
|
4544
4544
|
if (L.aborted) return;
|
|
4545
4545
|
if ((W = b.current) == null || W.close(), b.current = null, u(null), o("idle"), k instanceof zr) {
|
|
@@ -4550,14 +4550,14 @@ function Hi({
|
|
|
4550
4550
|
k instanceof Error ? k.message : "Could not start the connection."
|
|
4551
4551
|
);
|
|
4552
4552
|
}
|
|
4553
|
-
}, [
|
|
4553
|
+
}, [E, e, c, n]);
|
|
4554
4554
|
F(() => {
|
|
4555
4555
|
if (s !== "waiting" && s !== "ready" || !l || !e)
|
|
4556
4556
|
return;
|
|
4557
4557
|
const L = new AbortController();
|
|
4558
4558
|
let B;
|
|
4559
|
-
const W =
|
|
4560
|
-
|
|
4559
|
+
const W = N.current ?? Date.now() + An;
|
|
4560
|
+
N.current = W;
|
|
4561
4561
|
let k = 0, $ = document.hidden || !document.hasFocus(), Se = !1;
|
|
4562
4562
|
const Ie = () => {
|
|
4563
4563
|
$ = !0;
|
|
@@ -4635,43 +4635,43 @@ function Hi({
|
|
|
4635
4635
|
}, [l, s, e, n]), F(() => {
|
|
4636
4636
|
s !== "connected" && s !== "external" || x.current !== (e == null ? void 0 : e.request_id) || c(s === "external" ? "external" : "resume");
|
|
4637
4637
|
}, [s, e == null ? void 0 : e.request_id, c]);
|
|
4638
|
-
const f = z(() => o("waiting"), []),
|
|
4639
|
-
|
|
4640
|
-
}, [
|
|
4638
|
+
const f = z(() => o("waiting"), []), h = z(async () => {
|
|
4639
|
+
E(), u(null), o("idle"), await c("dismiss");
|
|
4640
|
+
}, [E, c]), I = z(async () => {
|
|
4641
4641
|
const L = M.current;
|
|
4642
4642
|
if (L) {
|
|
4643
4643
|
await c(L);
|
|
4644
4644
|
return;
|
|
4645
4645
|
}
|
|
4646
4646
|
await m();
|
|
4647
|
-
}, [c, m]),
|
|
4647
|
+
}, [c, m]), P = X(
|
|
4648
4648
|
() => e ? {
|
|
4649
4649
|
request: e,
|
|
4650
4650
|
phase: s,
|
|
4651
4651
|
authorization: l,
|
|
4652
|
-
continuation:
|
|
4652
|
+
continuation: y,
|
|
4653
4653
|
error: i,
|
|
4654
4654
|
start: m,
|
|
4655
4655
|
opened: f,
|
|
4656
|
-
cancel:
|
|
4657
|
-
retryContinuation:
|
|
4656
|
+
cancel: h,
|
|
4657
|
+
retryContinuation: I
|
|
4658
4658
|
} : null,
|
|
4659
4659
|
[
|
|
4660
4660
|
l,
|
|
4661
|
-
y,
|
|
4662
4661
|
h,
|
|
4662
|
+
y,
|
|
4663
4663
|
i,
|
|
4664
4664
|
f,
|
|
4665
4665
|
s,
|
|
4666
4666
|
e,
|
|
4667
|
-
|
|
4667
|
+
I,
|
|
4668
4668
|
m
|
|
4669
4669
|
]
|
|
4670
4670
|
);
|
|
4671
4671
|
return H.createElement(
|
|
4672
4672
|
bt.Provider,
|
|
4673
4673
|
{
|
|
4674
|
-
value:
|
|
4674
|
+
value: P
|
|
4675
4675
|
},
|
|
4676
4676
|
t
|
|
4677
4677
|
);
|
|
@@ -4735,45 +4735,45 @@ function Gi({
|
|
|
4735
4735
|
isStreaming: o,
|
|
4736
4736
|
liveItems: l,
|
|
4737
4737
|
turnSources: u,
|
|
4738
|
-
liveTurnKey:
|
|
4738
|
+
liveTurnKey: y,
|
|
4739
4739
|
turnFailed: g,
|
|
4740
4740
|
retryFailedTurn: i,
|
|
4741
4741
|
resumeInterruptedTurn: d,
|
|
4742
4742
|
queuedUserMessages: p,
|
|
4743
4743
|
removeQueued: b,
|
|
4744
|
-
stop:
|
|
4744
|
+
stop: O,
|
|
4745
4745
|
pageEffects: M,
|
|
4746
|
-
replyToPageCall:
|
|
4746
|
+
replyToPageCall: N,
|
|
4747
4747
|
pendingPageAction: x,
|
|
4748
|
-
requestPageActionConsent:
|
|
4749
|
-
resolvePageAction:
|
|
4750
|
-
handledConnectionRequestIds:
|
|
4748
|
+
requestPageActionConsent: w,
|
|
4749
|
+
resolvePageAction: S,
|
|
4750
|
+
handledConnectionRequestIds: E,
|
|
4751
4751
|
sourceSessionId: c
|
|
4752
4752
|
} = Vi({
|
|
4753
4753
|
widgetCtx: e,
|
|
4754
4754
|
config: n,
|
|
4755
4755
|
sessionId: ((ve = r.session) == null ? void 0 : ve.id) ?? null,
|
|
4756
4756
|
persistedMessages: s.messages
|
|
4757
|
-
}), m = ((ae = s.messages.at(-1)) == null ? void 0 : ae.type) === "USER", f = R(/* @__PURE__ */ new Set()),
|
|
4758
|
-
|
|
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), I = ((de = r.session) == null ? void 0 : de.id) ?? null;
|
|
4758
|
+
h.current !== I && (h.current = I, f.current.clear()), E.forEach(
|
|
4759
4759
|
(U) => f.current.add(U)
|
|
4760
4760
|
);
|
|
4761
|
-
const
|
|
4761
|
+
const P = (fe = [
|
|
4762
4762
|
...u.flatMap((U) => U.items),
|
|
4763
4763
|
...l
|
|
4764
4764
|
].findLast(
|
|
4765
4765
|
(U) => U.kind === "connection" && !f.current.has(U.request.request_id)
|
|
4766
|
-
)) == null ? void 0 : fe.request, [L, B] = J({ sessionId:
|
|
4766
|
+
)) == null ? void 0 : fe.request, [L, B] = J({ sessionId: I, request: null }), W = ((Ee = n.capabilities) == null ? void 0 : Ee.connections) === !0, k = W && I !== null && L.sessionId === I ? L.request : null;
|
|
4767
4767
|
F(() => {
|
|
4768
|
-
!W ||
|
|
4769
|
-
const ie = U.sessionId ===
|
|
4770
|
-
return U.sessionId ===
|
|
4768
|
+
!W || I === null || c !== I || B((U) => {
|
|
4769
|
+
const ie = U.sessionId === I && U.request && !f.current.has(U.request.request_id) ? U.request : P ?? null;
|
|
4770
|
+
return U.sessionId === I && U.request === ie ? U : { sessionId: I, request: ie };
|
|
4771
4771
|
});
|
|
4772
4772
|
}, [
|
|
4773
|
-
|
|
4773
|
+
I,
|
|
4774
4774
|
c,
|
|
4775
|
-
|
|
4776
|
-
|
|
4775
|
+
P,
|
|
4776
|
+
E,
|
|
4777
4777
|
W,
|
|
4778
4778
|
k
|
|
4779
4779
|
]);
|
|
@@ -4789,18 +4789,18 @@ function Gi({
|
|
|
4789
4789
|
isStreaming: o,
|
|
4790
4790
|
liveItems: l,
|
|
4791
4791
|
turnSources: u,
|
|
4792
|
-
liveTurnKey:
|
|
4792
|
+
liveTurnKey: y,
|
|
4793
4793
|
turnFailed: g,
|
|
4794
4794
|
retryFailedTurn: i,
|
|
4795
4795
|
resumeInterruptedTurn: d,
|
|
4796
4796
|
queuedUserMessages: p,
|
|
4797
4797
|
removeQueued: b,
|
|
4798
|
-
stop:
|
|
4798
|
+
stop: O,
|
|
4799
4799
|
pageEffects: M,
|
|
4800
|
-
replyToPageCall:
|
|
4800
|
+
replyToPageCall: N,
|
|
4801
4801
|
pendingPageAction: x,
|
|
4802
|
-
requestPageActionConsent:
|
|
4803
|
-
resolvePageAction:
|
|
4802
|
+
requestPageActionConsent: w,
|
|
4803
|
+
resolvePageAction: S,
|
|
4804
4804
|
pendingConnection: k,
|
|
4805
4805
|
pendingClarification: ms({
|
|
4806
4806
|
turnSources: u,
|
|
@@ -4813,18 +4813,18 @@ function Gi({
|
|
|
4813
4813
|
o,
|
|
4814
4814
|
l,
|
|
4815
4815
|
u,
|
|
4816
|
-
|
|
4816
|
+
y,
|
|
4817
4817
|
g,
|
|
4818
4818
|
i,
|
|
4819
4819
|
d,
|
|
4820
4820
|
p,
|
|
4821
4821
|
b,
|
|
4822
|
-
P,
|
|
4823
|
-
M,
|
|
4824
4822
|
O,
|
|
4823
|
+
M,
|
|
4824
|
+
N,
|
|
4825
4825
|
x,
|
|
4826
|
-
|
|
4827
|
-
|
|
4826
|
+
w,
|
|
4827
|
+
S,
|
|
4828
4828
|
m,
|
|
4829
4829
|
k
|
|
4830
4830
|
]
|
|
@@ -4879,14 +4879,14 @@ class Qi {
|
|
|
4879
4879
|
if (this.disposed) return;
|
|
4880
4880
|
const { chats: s, activeId: o } = this.state.get(), l = s.findIndex((d) => d.id === r && !d.closed), u = s[l];
|
|
4881
4881
|
if (!u) return;
|
|
4882
|
-
const
|
|
4882
|
+
const y = this.isWorking(u), g = y ? s.map((d) => d.id === r ? { ...d, closed: !0 } : d) : s.filter((d) => d.id !== r);
|
|
4883
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);
|
|
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 }),
|
|
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);
|
|
4885
4885
|
}, this.canCreateChat = () => !this.disposed && (!this.root.config.oneOpenSessionAllowed || !this.state.get().chats.some(({ ctx: r }) => {
|
|
4886
4886
|
const { session: s, isCreatingSession: o } = r.sessionCtx.sessionState.get();
|
|
4887
4887
|
return (s == null ? void 0 : s.isOpened) || o;
|
|
4888
4888
|
}) && !this.root.sessionCtx.sessionsState.get().data.some((r) => r.isOpened)), this.open = (r) => {
|
|
4889
|
-
var
|
|
4889
|
+
var y, g, i, d;
|
|
4890
4890
|
if (this.disposed) return;
|
|
4891
4891
|
const { chats: s } = this.state.get();
|
|
4892
4892
|
if (!r && !this.canCreateChat()) return;
|
|
@@ -4897,7 +4897,7 @@ class Qi {
|
|
|
4897
4897
|
}
|
|
4898
4898
|
) : s.find((p) => this.isEmpty(p));
|
|
4899
4899
|
if (o)
|
|
4900
|
-
return this.select(o.id), (g = (
|
|
4900
|
+
return this.select(o.id), (g = (y = this.root.config.hooks) == null ? void 0 : y.onNavigateToChat) == null || g.call(y, {
|
|
4901
4901
|
session: o.ctx.sessionCtx.sessionState.get().session ?? void 0
|
|
4902
4902
|
}), o.ctx;
|
|
4903
4903
|
const l = r ? this.root.sessionCtx.sessionsState.get().data.find((p) => p.id === r) : void 0;
|
|
@@ -4967,9 +4967,9 @@ function eo({
|
|
|
4967
4967
|
ctx: e,
|
|
4968
4968
|
workspace: n
|
|
4969
4969
|
}) {
|
|
4970
|
-
const r = pr(), s = Ki(), o = K(e.messageCtx.state), l = K(e.sessionCtx.sessionState), u = K(e.messageCtx.draftState),
|
|
4971
|
-
(
|
|
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 ||
|
|
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(
|
|
4971
|
+
(O) => O.type === "USER"
|
|
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;
|
|
4973
4973
|
return F(
|
|
4974
4974
|
() => n.update(t, {
|
|
4975
4975
|
title: i,
|
|
@@ -5000,13 +5000,13 @@ function no({
|
|
|
5000
5000
|
[t]
|
|
5001
5001
|
);
|
|
5002
5002
|
F(() => r.mount(), [r]);
|
|
5003
|
-
const { chats: s, activeId: o } = K(r.state), l = s.find((
|
|
5004
|
-
() => s.map((
|
|
5003
|
+
const { chats: s, activeId: o } = K(r.state), l = s.find((y) => y.id === o), u = X(
|
|
5004
|
+
() => s.map((y) => /* @__PURE__ */ H.createElement(
|
|
5005
5005
|
to,
|
|
5006
5006
|
{
|
|
5007
|
-
key:
|
|
5008
|
-
chatId:
|
|
5009
|
-
ctx:
|
|
5007
|
+
key: y.id,
|
|
5008
|
+
chatId: y.id,
|
|
5009
|
+
ctx: y.ctx,
|
|
5010
5010
|
config: e,
|
|
5011
5011
|
workspace: r
|
|
5012
5012
|
}
|
|
@@ -5105,28 +5105,28 @@ function _o({
|
|
|
5105
5105
|
loadingComponent: s,
|
|
5106
5106
|
errorComponent: o
|
|
5107
5107
|
}) {
|
|
5108
|
-
var
|
|
5108
|
+
var w;
|
|
5109
5109
|
const l = R(Promise.resolve()), u = R(t);
|
|
5110
5110
|
u.current = t;
|
|
5111
|
-
const
|
|
5111
|
+
const y = io(t), g = R(null), i = R(null), d = R(null), [p, b] = J({ status: "loading" }), O = X(
|
|
5112
5112
|
() => new ro({
|
|
5113
5113
|
components: n
|
|
5114
5114
|
}),
|
|
5115
5115
|
[n]
|
|
5116
5116
|
);
|
|
5117
|
-
|
|
5118
|
-
var
|
|
5119
|
-
if (((
|
|
5120
|
-
const
|
|
5117
|
+
F(() => {
|
|
5118
|
+
var c, m, f;
|
|
5119
|
+
if (((c = d.current) == null ? void 0 : c.identity) !== y) {
|
|
5120
|
+
const h = (m = d.current) == null ? void 0 : m.widgetCtx.dispose({
|
|
5121
5121
|
clearActiveSession: !0
|
|
5122
5122
|
});
|
|
5123
|
-
l.current = Promise.all([l.current,
|
|
5123
|
+
l.current = Promise.all([l.current, h]).then(
|
|
5124
5124
|
() => {
|
|
5125
5125
|
}
|
|
5126
5126
|
), d.current = null;
|
|
5127
5127
|
}
|
|
5128
|
-
((
|
|
5129
|
-
identity:
|
|
5128
|
+
((f = i.current) == null ? void 0 : f.identity) !== y && (b({ status: "loading" }), i.current = {
|
|
5129
|
+
identity: y,
|
|
5130
5130
|
request: l.current.then(
|
|
5131
5131
|
() => Vr.initialize({
|
|
5132
5132
|
config: t,
|
|
@@ -5136,68 +5136,77 @@ function _o({
|
|
|
5136
5136
|
})
|
|
5137
5137
|
)
|
|
5138
5138
|
});
|
|
5139
|
-
const
|
|
5140
|
-
|
|
5141
|
-
(
|
|
5142
|
-
var
|
|
5143
|
-
if (((
|
|
5144
|
-
|
|
5139
|
+
const S = i.current.request, E = i.current.identity;
|
|
5140
|
+
S.then(
|
|
5141
|
+
(h) => {
|
|
5142
|
+
var I;
|
|
5143
|
+
if (((I = i.current) == null ? void 0 : I.request) !== S) {
|
|
5144
|
+
h.dispose();
|
|
5145
5145
|
return;
|
|
5146
5146
|
}
|
|
5147
|
-
d.current = { identity:
|
|
5147
|
+
d.current = { identity: E, widgetCtx: h }, b({
|
|
5148
5148
|
status: "ready",
|
|
5149
|
-
identity:
|
|
5150
|
-
widgetCtx:
|
|
5149
|
+
identity: E,
|
|
5150
|
+
widgetCtx: h
|
|
5151
5151
|
});
|
|
5152
5152
|
},
|
|
5153
|
-
(
|
|
5154
|
-
var
|
|
5155
|
-
if (((
|
|
5156
|
-
const
|
|
5157
|
-
le.error("widget initialization failed",
|
|
5153
|
+
(h) => {
|
|
5154
|
+
var P;
|
|
5155
|
+
if (((P = i.current) == null ? void 0 : P.request) !== S) return;
|
|
5156
|
+
const I = h instanceof Error ? h : new Error("Widget initialization failed", { cause: h });
|
|
5157
|
+
le.error("widget initialization failed", I), b({
|
|
5158
5158
|
status: "error",
|
|
5159
|
-
identity:
|
|
5160
|
-
error:
|
|
5159
|
+
identity: E,
|
|
5160
|
+
error: I
|
|
5161
5161
|
});
|
|
5162
5162
|
}
|
|
5163
5163
|
);
|
|
5164
|
-
}, [
|
|
5164
|
+
}, [y, t, r]), F(
|
|
5165
5165
|
() => () => {
|
|
5166
|
-
var
|
|
5167
|
-
i.current = null, (
|
|
5166
|
+
var S;
|
|
5167
|
+
i.current = null, (S = d.current) == null || S.widgetCtx.dispose(), d.current = null;
|
|
5168
5168
|
},
|
|
5169
5169
|
[]
|
|
5170
|
-
)
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5170
|
+
);
|
|
5171
|
+
const M = R(
|
|
5172
|
+
null
|
|
5173
|
+
);
|
|
5174
|
+
if (jr(() => {
|
|
5175
|
+
var c, m;
|
|
5176
|
+
if (p.status !== "ready" || p.identity !== y)
|
|
5177
|
+
return;
|
|
5178
|
+
const S = (c = t.user) == null ? void 0 : c.token;
|
|
5179
|
+
if (!S) return;
|
|
5180
|
+
const { widgetCtx: E } = p;
|
|
5181
|
+
((m = M.current) == null ? void 0 : m.widgetCtx) === E && M.current.token === S || (M.current = { widgetCtx: E, token: S }, E.api.setAuthToken(S), E.tokenRenewalCtx.track(S));
|
|
5182
|
+
}, [(w = t.user) == null ? void 0 : w.token, y, p]), F(() => {
|
|
5174
5183
|
if (p.status !== "ready" || typeof document > "u")
|
|
5175
5184
|
return;
|
|
5176
|
-
const
|
|
5177
|
-
document.visibilityState === "visible" &&
|
|
5185
|
+
const S = p.widgetCtx.tokenRenewalCtx, E = () => {
|
|
5186
|
+
document.visibilityState === "visible" && S.onVisible();
|
|
5178
5187
|
};
|
|
5179
|
-
return document.addEventListener("visibilitychange",
|
|
5180
|
-
}, [p]), p.status === "loading" || "identity" in p && p.identity !==
|
|
5188
|
+
return document.addEventListener("visibilitychange", E), () => document.removeEventListener("visibilitychange", E);
|
|
5189
|
+
}, [p]), p.status === "loading" || "identity" in p && p.identity !== y)
|
|
5181
5190
|
return s ? /* @__PURE__ */ H.createElement(H.Fragment, null, s) : null;
|
|
5182
5191
|
if (p.status === "error")
|
|
5183
5192
|
return o ? /* @__PURE__ */ H.createElement(H.Fragment, null, o(p.error)) : null;
|
|
5184
|
-
const { widgetCtx:
|
|
5193
|
+
const { widgetCtx: N } = p, x = (S, E) => /* @__PURE__ */ H.createElement(
|
|
5185
5194
|
hr.Provider,
|
|
5186
5195
|
{
|
|
5187
5196
|
value: {
|
|
5188
|
-
widgetCtx:
|
|
5197
|
+
widgetCtx: S,
|
|
5189
5198
|
config: t,
|
|
5190
5199
|
components: n,
|
|
5191
|
-
componentStore:
|
|
5200
|
+
componentStore: O,
|
|
5192
5201
|
version: Pn,
|
|
5193
5202
|
contentIframeRef: g
|
|
5194
5203
|
}
|
|
5195
5204
|
},
|
|
5196
|
-
|
|
5205
|
+
E
|
|
5197
5206
|
);
|
|
5198
|
-
return t.displayMode === "companion" && !t.inline ? /* @__PURE__ */ H.createElement(no, { widgetCtx:
|
|
5199
|
-
|
|
5200
|
-
/* @__PURE__ */ H.createElement(fr, { key:
|
|
5207
|
+
return t.displayMode === "companion" && !t.inline ? /* @__PURE__ */ H.createElement(no, { widgetCtx: N, config: t }, (S) => x(S, e)) : x(
|
|
5208
|
+
N,
|
|
5209
|
+
/* @__PURE__ */ H.createElement(fr, { key: y, widgetCtx: N, config: t }, e)
|
|
5201
5210
|
);
|
|
5202
5211
|
}
|
|
5203
5212
|
function ne() {
|
|
@@ -5250,7 +5259,10 @@ function No() {
|
|
|
5250
5259
|
}
|
|
5251
5260
|
function Lo() {
|
|
5252
5261
|
const { widgetCtx: t } = ne(), { ended: e } = K(t.tokenRenewalCtx.state);
|
|
5253
|
-
return {
|
|
5262
|
+
return {
|
|
5263
|
+
sessionEnded: e,
|
|
5264
|
+
renewUserToken: t.tokenRenewalCtx.renewUserToken
|
|
5265
|
+
};
|
|
5254
5266
|
}
|
|
5255
5267
|
function oo() {
|
|
5256
5268
|
const [t, e] = J("ltr");
|
|
@@ -5316,11 +5328,11 @@ function br() {
|
|
|
5316
5328
|
};
|
|
5317
5329
|
}
|
|
5318
5330
|
function Sr() {
|
|
5319
|
-
var
|
|
5331
|
+
var y;
|
|
5320
5332
|
const { widgetCtx: t } = ne(), { oneOpenSessionAllowed: e } = It(), n = K(t.sessionCtx.sessionState), r = K(t.sessionCtx.sessionsState), { openSessions: s, closedSessions: o } = X(() => ({
|
|
5321
5333
|
openSessions: r.data.filter((g) => g.isOpened === !0),
|
|
5322
5334
|
closedSessions: r.data.filter((g) => g.isOpened === !1)
|
|
5323
|
-
}), [r.data]), { workspace: l } = gr(), u = l ? l.canCreateChat() : !e || s.length === 0 && !n.isCreatingSession && !((
|
|
5335
|
+
}), [r.data]), { workspace: l } = gr(), u = l ? l.canCreateChat() : !e || s.length === 0 && !n.isCreatingSession && !((y = n.session) != null && y.isOpened);
|
|
5324
5336
|
return {
|
|
5325
5337
|
sessionState: n,
|
|
5326
5338
|
sessionsState: r,
|
|
@@ -5451,53 +5463,53 @@ function yo({
|
|
|
5451
5463
|
const l = Jr(e), u = Hr(
|
|
5452
5464
|
t,
|
|
5453
5465
|
l
|
|
5454
|
-
),
|
|
5466
|
+
), y = l.join("|"), [g, i] = J(u), [d, p] = J({
|
|
5455
5467
|
defaultLayout: u,
|
|
5456
|
-
allowedLayoutsKey:
|
|
5468
|
+
allowedLayoutsKey: y
|
|
5457
5469
|
});
|
|
5458
|
-
(d.defaultLayout !== u || d.allowedLayoutsKey !==
|
|
5459
|
-
const b = (
|
|
5460
|
-
i((
|
|
5461
|
-
const
|
|
5462
|
-
return l.includes(
|
|
5470
|
+
(d.defaultLayout !== u || d.allowedLayoutsKey !== y) && (p({ defaultLayout: u, allowedLayoutsKey: y }), (d.defaultLayout !== u || !l.includes(g)) && i(u));
|
|
5471
|
+
const b = (h) => {
|
|
5472
|
+
i((I) => {
|
|
5473
|
+
const P = typeof h == "function" ? h(I) : h;
|
|
5474
|
+
return l.includes(P) ? P : I;
|
|
5463
5475
|
});
|
|
5464
|
-
},
|
|
5465
|
-
|
|
5466
|
-
const M = (
|
|
5467
|
-
b(
|
|
5476
|
+
}, O = R(l);
|
|
5477
|
+
O.current = l;
|
|
5478
|
+
const M = (h) => {
|
|
5479
|
+
b(h), O.current.includes(h) && ho(h) && (s == null || s.setCompanionLayout(h).catch(() => {
|
|
5468
5480
|
}));
|
|
5469
|
-
}, [
|
|
5481
|
+
}, [N, x] = J(n), [w, S] = J(r), [E, c] = J({
|
|
5470
5482
|
side: n,
|
|
5471
5483
|
mode: r
|
|
5472
5484
|
});
|
|
5473
|
-
(
|
|
5485
|
+
(E.side !== n || E.mode !== r) && (c({
|
|
5474
5486
|
side: n,
|
|
5475
5487
|
mode: r
|
|
5476
|
-
}),
|
|
5488
|
+
}), E.side !== n && x(n), E.mode !== r && S(r)), F(() => {
|
|
5477
5489
|
if (!s) return;
|
|
5478
|
-
let
|
|
5479
|
-
return s.getCompanionLayout().then((
|
|
5480
|
-
|
|
5490
|
+
let h = !1;
|
|
5491
|
+
return s.getCompanionLayout().then((I) => {
|
|
5492
|
+
h || !I || O.current.includes(I) && i(I);
|
|
5481
5493
|
}).catch(() => {
|
|
5482
|
-
}), s.getCompanionSidebarSide().then((
|
|
5483
|
-
!
|
|
5494
|
+
}), s.getCompanionSidebarSide().then((I) => {
|
|
5495
|
+
!h && I && x(I);
|
|
5484
5496
|
}).catch(() => {
|
|
5485
|
-
}), s.getCompanionSidebarMode().then((
|
|
5486
|
-
!
|
|
5497
|
+
}), s.getCompanionSidebarMode().then((I) => {
|
|
5498
|
+
!h && I && S(I);
|
|
5487
5499
|
}).catch(() => {
|
|
5488
5500
|
}), () => {
|
|
5489
|
-
|
|
5501
|
+
h = !0;
|
|
5490
5502
|
};
|
|
5491
5503
|
}, [s]);
|
|
5492
5504
|
const m = z(
|
|
5493
|
-
(
|
|
5494
|
-
x(
|
|
5505
|
+
(h) => {
|
|
5506
|
+
x(h), s == null || s.setCompanionSidebarSide(h).catch(() => {
|
|
5495
5507
|
});
|
|
5496
5508
|
},
|
|
5497
5509
|
[s]
|
|
5498
5510
|
), f = z(
|
|
5499
|
-
(
|
|
5500
|
-
|
|
5511
|
+
(h) => {
|
|
5512
|
+
S(h), s == null || s.setCompanionSidebarMode(h).catch(() => {
|
|
5501
5513
|
});
|
|
5502
5514
|
},
|
|
5503
5515
|
[s]
|
|
@@ -5511,9 +5523,9 @@ function yo({
|
|
|
5511
5523
|
setLayoutPreference: M,
|
|
5512
5524
|
allowedLayouts: l,
|
|
5513
5525
|
defaultLayout: u,
|
|
5514
|
-
sidebarSide:
|
|
5526
|
+
sidebarSide: N,
|
|
5515
5527
|
setSidebarSide: m,
|
|
5516
|
-
sidebarMode:
|
|
5528
|
+
sidebarMode: w,
|
|
5517
5529
|
setSidebarMode: f
|
|
5518
5530
|
}
|
|
5519
5531
|
},
|
|
@@ -5529,8 +5541,8 @@ function zo() {
|
|
|
5529
5541
|
return t;
|
|
5530
5542
|
}
|
|
5531
5543
|
function Zo() {
|
|
5532
|
-
var u,
|
|
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 = (
|
|
5544
|
+
var u, y;
|
|
5545
|
+
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(
|
|
5534
5546
|
(g) => {
|
|
5535
5547
|
var i, d;
|
|
5536
5548
|
return [
|
|
@@ -5539,7 +5551,7 @@ function Zo() {
|
|
|
5539
5551
|
((d = o == null ? void 0 : o.slug) == null ? void 0 : d.toLowerCase()) || ""
|
|
5540
5552
|
].includes(g.key.toLowerCase());
|
|
5541
5553
|
}
|
|
5542
|
-
)) == null ? void 0 :
|
|
5554
|
+
)) == null ? void 0 : y.component;
|
|
5543
5555
|
return {
|
|
5544
5556
|
modes: r,
|
|
5545
5557
|
modesComponents: e,
|
|
@@ -5556,9 +5568,9 @@ function Vo(t = "csat") {
|
|
|
5556
5568
|
...X(() => {
|
|
5557
5569
|
var u;
|
|
5558
5570
|
const s = n.findLast(
|
|
5559
|
-
(
|
|
5571
|
+
(y) => y.type === "SYSTEM" && y.subtype === `${t}_requested`
|
|
5560
5572
|
), o = n.findLast(
|
|
5561
|
-
(
|
|
5573
|
+
(y) => y.type === "SYSTEM" && y.subtype === `${t}_submitted`
|
|
5562
5574
|
), l = !!s && (!o || n.indexOf(s) > n.indexOf(o));
|
|
5563
5575
|
return {
|
|
5564
5576
|
csatRequestedMessage: s,
|
|
@@ -5581,8 +5593,8 @@ function Bo(t) {
|
|
|
5581
5593
|
getValue: () => s.current.getValue(),
|
|
5582
5594
|
setValue: (u) => s.current.setValue(u),
|
|
5583
5595
|
onSend: () => {
|
|
5584
|
-
var u,
|
|
5585
|
-
return (
|
|
5596
|
+
var u, y;
|
|
5597
|
+
return (y = (u = s.current).onSend) == null ? void 0 : y.call(u);
|
|
5586
5598
|
}
|
|
5587
5599
|
});
|
|
5588
5600
|
}, [n]), l = z(() => {
|