@aintela/chat 0.14.1 → 0.14.3
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/components.js +6535 -6521
- package/dist/components.js.map +1 -1
- package/dist/{detachedRunActivity-C_TBbcmB.js → detachedRunActivity-B85--SdS.js} +314 -250
- package/dist/detachedRunActivity-B85--SdS.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/services.js +1 -1
- package/dist/src/components/AiChat/AiChatTypes.d.ts +2 -0
- package/dist/src/components/AiChat/aiChatEngine.d.ts +11 -0
- package/dist/src/components/AiChat/stateConfiguration.d.ts +1 -1
- package/dist/src/components/Library/markdownExtended.streaming.test.d.ts +1 -0
- package/dist/src/components/v2/TriggerDropdown.d.ts +1 -1
- package/dist/src/models/Notification.d.ts +3 -1
- package/dist/src/services/interaction/reduceInteraction.d.ts +16 -0
- package/dist/src/services/servers/AgentGatewayWSAsync.d.ts +12 -0
- package/dist/src/services/servers/connectionSupervisor.credentials.test.d.ts +1 -0
- package/dist/src/services/servers/connectionSupervisor.d.ts +14 -1
- package/dist/src/services/servers/gatewayCredentials.wire.test.d.ts +0 -0
- package/dist/src/utils/jwtExpiry.d.ts +6 -0
- package/dist/src/utils/jwtExpiry.test.d.ts +1 -0
- package/dist/tests/bench/markdownRender.bench.d.ts +1 -0
- package/dist/tests/bench/textSplit.bench.d.ts +1 -0
- package/dist/tests/fakes/fakeJwt.d.ts +4 -0
- package/package.json +1 -1
- package/dist/detachedRunActivity-C_TBbcmB.js.map +0 -1
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var h = (i, e) =>
|
|
4
|
-
var a = (i, e, t) =>
|
|
5
|
-
import { i as
|
|
6
|
-
import { format as
|
|
7
|
-
import
|
|
8
|
-
import { C as E, P as
|
|
9
|
-
import { d as
|
|
10
|
-
import { r as
|
|
1
|
+
var Ie = Object.defineProperty;
|
|
2
|
+
var Fe = (i, e, t) => e in i ? Ie(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
|
+
var h = (i, e) => Ie(i, "name", { value: e, configurable: !0 });
|
|
4
|
+
var a = (i, e, t) => Fe(i, typeof e != "symbol" ? e + "" : e, t);
|
|
5
|
+
import { i as _, E as I, S as U, z as Te, C as L, j as xe, L as Ne, P as z, n as _e, q as Ue, T as qe, o as Be, s as ne, B as We } from "./serializer-CdIQS0hy.js";
|
|
6
|
+
import { format as Ge } from "date-fns";
|
|
7
|
+
import ze from "lodash";
|
|
8
|
+
import { C as E, P as He } from "./Prompt-DZb7OaPp.js";
|
|
9
|
+
import { d as Qe } from "./environmentUtils-VZNTCzEE.js";
|
|
10
|
+
import { r as je } from "./httpSessionService-B2wgAfly.js";
|
|
11
11
|
const K = {
|
|
12
12
|
PROMPTS: "envision-prompts"
|
|
13
|
-
},
|
|
13
|
+
}, Je = 50, re = class re {
|
|
14
14
|
getPrompts() {
|
|
15
15
|
try {
|
|
16
16
|
const e = localStorage.getItem(K.PROMPTS);
|
|
@@ -40,7 +40,7 @@ const K = {
|
|
|
40
40
|
storePrompt(e) {
|
|
41
41
|
try {
|
|
42
42
|
const t = this.getPrompts().filter((s) => s.promptText !== e.promptText);
|
|
43
|
-
t.unshift(e), localStorage.setItem(K.PROMPTS, JSON.stringify(t.slice(0,
|
|
43
|
+
t.unshift(e), localStorage.setItem(K.PROMPTS, JSON.stringify(t.slice(0, Je)));
|
|
44
44
|
} catch (t) {
|
|
45
45
|
console.error("Error storing prompt:", t);
|
|
46
46
|
}
|
|
@@ -53,16 +53,16 @@ const K = {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
|
-
h(
|
|
57
|
-
let
|
|
58
|
-
const
|
|
56
|
+
h(re, "LocalStorageService");
|
|
57
|
+
let ye = re;
|
|
58
|
+
const xt = /* @__PURE__ */ h((i) => {
|
|
59
59
|
const e = i.getPrompts(), t = e.length;
|
|
60
60
|
if (t > 0) {
|
|
61
61
|
const s = e[0].promptText, n = e[e.length - 1].promptText, r = e[0].created;
|
|
62
62
|
return { promptState: t + "_" + s + "_" + n + "_" + r };
|
|
63
63
|
} else
|
|
64
64
|
return { promptState: "0" };
|
|
65
|
-
}, "usePromptState"),
|
|
65
|
+
}, "usePromptState"), oe = class oe {
|
|
66
66
|
constructor() {
|
|
67
67
|
a(this, "artifactGenerated", "artifactGenerated");
|
|
68
68
|
a(this, "artifactSelected", "artifactSelected");
|
|
@@ -80,9 +80,9 @@ const Rt = /* @__PURE__ */ h((i) => {
|
|
|
80
80
|
a(this, "gatewayFirstToken", "gatewayFirstToken");
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
|
-
h(
|
|
84
|
-
let
|
|
85
|
-
const d = new
|
|
83
|
+
h(oe, "EventTypes");
|
|
84
|
+
let V = oe;
|
|
85
|
+
const d = new V(), ae = class ae {
|
|
86
86
|
constructor() {
|
|
87
87
|
a(this, "listeners", {});
|
|
88
88
|
}
|
|
@@ -236,24 +236,52 @@ const d = new X(), re = class re {
|
|
|
236
236
|
this.removeListener(d.gatewayFirstToken, e);
|
|
237
237
|
}
|
|
238
238
|
};
|
|
239
|
-
h(
|
|
240
|
-
let
|
|
241
|
-
const
|
|
242
|
-
function
|
|
239
|
+
h(ae, "EventBusService");
|
|
240
|
+
let ve = ae;
|
|
241
|
+
const Z = 2e3;
|
|
242
|
+
function q(i) {
|
|
243
243
|
i.parts === i.prev.parts && (i.parts = i.prev.parts.slice());
|
|
244
244
|
}
|
|
245
|
-
h(
|
|
245
|
+
h(q, "ownParts");
|
|
246
246
|
function Q(i) {
|
|
247
247
|
i.functionMap === i.prev.functionMap && (i.functionMap = new Map(i.functionMap));
|
|
248
248
|
}
|
|
249
249
|
h(Q, "ownFunctionMap");
|
|
250
|
-
const
|
|
251
|
-
function
|
|
250
|
+
const Ke = /* @__PURE__ */ h((i) => i == I.FunctionCall || i == I.PartialFunctionCall, "isFunctionCall"), Ye = /* @__PURE__ */ h((i) => i == I.FunctionResponse, "isFunctionResponse"), $e = /* @__PURE__ */ h((i) => i.parts.length + 1 + "-" + i.prev.interactionId, "nextPartId");
|
|
251
|
+
function Xe(i, e) {
|
|
252
252
|
var t, s, n, r, o;
|
|
253
|
-
return !!(!e || i.mustPush || i.mustPush === !1 && (i.eventType !== e.eventType || ((t = i.functionDetails) == null ? void 0 : t.id) !== ((s = e.functionDetails) == null ? void 0 : s.id)) || i.textAppendable && (((r = (n = e.thoughtDetails) == null ? void 0 : n.text) == null ? void 0 : r.length) ?? ((o = e.text) == null ? void 0 : o.length) ?? 0) >
|
|
253
|
+
return !!(!e || i.mustPush || i.mustPush === !1 && (i.eventType !== e.eventType || ((t = i.functionDetails) == null ? void 0 : t.id) !== ((s = e.functionDetails) == null ? void 0 : s.id)) || i.textAppendable && i.eventType !== I.Text && (((r = (n = e.thoughtDetails) == null ? void 0 : n.text) == null ? void 0 : r.length) ?? ((o = e.text) == null ? void 0 : o.length) ?? 0) > Z);
|
|
254
254
|
}
|
|
255
|
-
h(
|
|
256
|
-
|
|
255
|
+
h(Xe, "opensNewPart");
|
|
256
|
+
const Ve = /* @__PURE__ */ h((i) => i === " " || i === " " || i === `
|
|
257
|
+
` || i === "\r", "isBlank");
|
|
258
|
+
function Ze(i) {
|
|
259
|
+
let e = 0;
|
|
260
|
+
for (const t of i.split(`
|
|
261
|
+
`)) {
|
|
262
|
+
const s = t.trimStart();
|
|
263
|
+
(s.startsWith("```") || s.startsWith("~~~")) && e++;
|
|
264
|
+
}
|
|
265
|
+
return e;
|
|
266
|
+
}
|
|
267
|
+
h(Ze, "fenceLines");
|
|
268
|
+
function et(i, e) {
|
|
269
|
+
if (i.length + e.length <= Z) return -1;
|
|
270
|
+
const t = /* @__PURE__ */ h((s) => (s >= 0 ? e[s] : i[i.length + s]) ?? "", "at");
|
|
271
|
+
for (let s = e.length - 1; s >= 0; s--) {
|
|
272
|
+
if (Ve(e[s]) || t(s - 1) !== `
|
|
273
|
+
`) continue;
|
|
274
|
+
let n = s - 2;
|
|
275
|
+
if (t(n) === "\r" && n--, t(n) === `
|
|
276
|
+
`) {
|
|
277
|
+
if (i.length + s <= Z) return -1;
|
|
278
|
+
if (Ze(i + e.slice(0, s)) % 2 === 0) return s;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return -1;
|
|
282
|
+
}
|
|
283
|
+
h(et, "splitAtBlockBoundary");
|
|
284
|
+
function tt(i, e) {
|
|
257
285
|
const t = e.functionDetails.id, s = e.functionDetails.clientOutput, n = i.parts.findIndex((r) => {
|
|
258
286
|
var o;
|
|
259
287
|
return ((o = r.functionDetails) == null ? void 0 : o.id) === t;
|
|
@@ -268,18 +296,18 @@ function Ye(i, e) {
|
|
|
268
296
|
parked: e.functionDetails.parked === !0 || r.functionDetails.parked === !0
|
|
269
297
|
}
|
|
270
298
|
};
|
|
271
|
-
|
|
299
|
+
q(i), i.parts[n] = o, Q(i), i.functionMap.set(t, o);
|
|
272
300
|
} else {
|
|
273
301
|
const r = {
|
|
274
302
|
...e,
|
|
275
|
-
id:
|
|
303
|
+
id: $e(i),
|
|
276
304
|
functionDetails: { ...e.functionDetails, silent: !0 }
|
|
277
305
|
};
|
|
278
|
-
|
|
306
|
+
q(i), i.parts.push(r), Q(i), i.functionMap.set(t, r);
|
|
279
307
|
}
|
|
280
308
|
}
|
|
281
|
-
h(
|
|
282
|
-
function
|
|
309
|
+
h(tt, "foldClientOutput");
|
|
310
|
+
function st(i, e, t, s, n) {
|
|
283
311
|
var g;
|
|
284
312
|
const r = i.parts.findIndex((m) => {
|
|
285
313
|
var u;
|
|
@@ -312,22 +340,22 @@ function Xe(i, e, t, s, n) {
|
|
|
312
340
|
parked: c.parked === !0 || l.parked === !0
|
|
313
341
|
}
|
|
314
342
|
};
|
|
315
|
-
Q(i), i.functionMap.set(s, f), f.eventType === I.FunctionResponse && ((g = n == null ? void 0 : n.onFunctionResponse) == null || g.call(n, f.functionDetails)), r > -1 && (
|
|
343
|
+
Q(i), i.functionMap.set(s, f), f.eventType === I.FunctionResponse && ((g = n == null ? void 0 : n.onFunctionResponse) == null || g.call(n, f.functionDetails)), r > -1 && (q(i), i.parts[r] = f);
|
|
316
344
|
}
|
|
317
|
-
h(
|
|
318
|
-
function
|
|
345
|
+
h(st, "foldFunctionEvent");
|
|
346
|
+
function Ee(i, e, t, s) {
|
|
319
347
|
s && e.functionDetails && (Q(i), i.functionMap.set(s, e));
|
|
320
|
-
const n = i.
|
|
321
|
-
n && n.textAppendable && (
|
|
348
|
+
const n = i.parts[i.parts.length - 1] ?? null;
|
|
349
|
+
n && n.textAppendable && (q(i), i.parts[i.parts.length - 1] = { ...n, ended: /* @__PURE__ */ new Date() });
|
|
322
350
|
const r = {
|
|
323
351
|
...e,
|
|
324
|
-
id:
|
|
352
|
+
id: $e(i),
|
|
325
353
|
partial: t.partial
|
|
326
354
|
};
|
|
327
355
|
i.parts = [...i.parts, r];
|
|
328
356
|
}
|
|
329
|
-
h(
|
|
330
|
-
function
|
|
357
|
+
h(Ee, "openPart");
|
|
358
|
+
function Y(i, e, t, s) {
|
|
331
359
|
const n = i.parts[i.parts.length - 1] ?? null;
|
|
332
360
|
if (!n) return;
|
|
333
361
|
const r = {
|
|
@@ -342,10 +370,10 @@ function Ze(i, e, t, s) {
|
|
|
342
370
|
}
|
|
343
371
|
} else
|
|
344
372
|
r.text = e.text ?? "", r.textDetails.version++, e.thoughtDetails && (r.thoughtDetails = { ...e.thoughtDetails, text: e.thoughtDetails.text.trim() });
|
|
345
|
-
|
|
373
|
+
q(i), i.parts[i.parts.length - 1] = r;
|
|
346
374
|
}
|
|
347
|
-
h(
|
|
348
|
-
function
|
|
375
|
+
h(Y, "appendText");
|
|
376
|
+
function nt(i, e) {
|
|
349
377
|
if (!e || e.length === 0) return i;
|
|
350
378
|
const t = i.slice();
|
|
351
379
|
for (const s of e) {
|
|
@@ -354,10 +382,10 @@ function et(i, e) {
|
|
|
354
382
|
}
|
|
355
383
|
return t;
|
|
356
384
|
}
|
|
357
|
-
h(
|
|
358
|
-
function
|
|
385
|
+
h(nt, "mergeArtifacts");
|
|
386
|
+
function it(i, e, t) {
|
|
359
387
|
var c, l;
|
|
360
|
-
const s =
|
|
388
|
+
const s = _.FlatParts(e == null ? void 0 : e.parts), n = i.parts[i.parts.length - 1] ?? null, r = {
|
|
361
389
|
prev: i,
|
|
362
390
|
parts: i.parts,
|
|
363
391
|
functionMap: i.functionMap ?? /* @__PURE__ */ new Map()
|
|
@@ -365,20 +393,28 @@ function tt(i, e, t) {
|
|
|
365
393
|
let o = !1;
|
|
366
394
|
if (s) {
|
|
367
395
|
if (s.eventType === I.FunctionClientOutput && !!((c = s.functionDetails) != null && c.id))
|
|
368
|
-
|
|
369
|
-
else if (
|
|
370
|
-
const g =
|
|
396
|
+
tt(r, s);
|
|
397
|
+
else if (Xe(s, n)) {
|
|
398
|
+
const g = Ke(s.eventType) || Ye(s.eventType), m = g ? (l = s.functionDetails) == null ? void 0 : l.id : void 0;
|
|
371
399
|
g && !m && console.error("Got isCall or isResponse without a callId", s);
|
|
372
400
|
const u = m ? r.functionMap.get(m) : void 0;
|
|
373
|
-
u && m && s.functionDetails ?
|
|
401
|
+
u && m && s.functionDetails ? st(r, s, u, m, t) : (Ee(r, s, e, m), o = !0);
|
|
402
|
+
}
|
|
403
|
+
if (s.textAppendable) {
|
|
404
|
+
const g = r.parts[r.parts.length - 1], m = !o && e.partial && s.eventType === I.Text && (g == null ? void 0 : g.eventType) === I.Text && s.text ? et(g.text ?? "", s.text) : -1;
|
|
405
|
+
if (m >= 0) {
|
|
406
|
+
m > 0 && Y(r, { ...s, text: s.text.slice(0, m) }, e, !1);
|
|
407
|
+
const u = { ...s, text: s.text.slice(m) };
|
|
408
|
+
Ee(r, u, e, void 0), Y(r, u, e, !0);
|
|
409
|
+
} else
|
|
410
|
+
Y(r, s, e, o);
|
|
374
411
|
}
|
|
375
|
-
s.textAppendable && Ze(r, s, e, o);
|
|
376
412
|
}
|
|
377
413
|
return {
|
|
378
414
|
...i,
|
|
379
415
|
version: i.version + 1,
|
|
380
416
|
parts: r.parts,
|
|
381
|
-
artifactData:
|
|
417
|
+
artifactData: nt(i.artifactData ?? [], e.llmArtifacts),
|
|
382
418
|
functionMap: r.functionMap,
|
|
383
419
|
turn_complete: e.turn_complete,
|
|
384
420
|
partial: e.partial,
|
|
@@ -386,8 +422,8 @@ function tt(i, e, t) {
|
|
|
386
422
|
agent: e.agent ?? i.agent
|
|
387
423
|
};
|
|
388
424
|
}
|
|
389
|
-
h(
|
|
390
|
-
const
|
|
425
|
+
h(it, "reduceInteraction");
|
|
426
|
+
const ce = class ce {
|
|
391
427
|
constructor(e, t) {
|
|
392
428
|
a(this, "interaction");
|
|
393
429
|
a(this, "eventBusService");
|
|
@@ -399,15 +435,15 @@ const oe = class oe {
|
|
|
399
435
|
* throttled subscribers cannot diverge from live state.
|
|
400
436
|
*/
|
|
401
437
|
merge(e) {
|
|
402
|
-
const t =
|
|
438
|
+
const t = it(this.interaction, e, {
|
|
403
439
|
onFunctionResponse: /* @__PURE__ */ h((s) => this.eventBusService.gatewayEmitFunctionResponse(s), "onFunctionResponse")
|
|
404
440
|
});
|
|
405
441
|
return this.interaction = t, t;
|
|
406
442
|
}
|
|
407
443
|
};
|
|
408
|
-
h(
|
|
409
|
-
let j =
|
|
410
|
-
const
|
|
444
|
+
h(ce, "InteractionService");
|
|
445
|
+
let j = ce;
|
|
446
|
+
const Re = 4001, rt = 4002, be = 4004, ot = 4100, H = 500, at = 2e4, ct = 1e3, lt = 0.2, N = 300 * 1e3, ht = 0.75, ut = 2e3, w = "[Connection]", le = class le {
|
|
411
447
|
constructor(e) {
|
|
412
448
|
a(this, "ports");
|
|
413
449
|
a(this, "state");
|
|
@@ -464,7 +500,7 @@ const ke = 4001, st = 4002, De = 4004, nt = 4100, H = 500, it = 2e4, rt = 1e3, o
|
|
|
464
500
|
if (this.inflight) return this.inflight;
|
|
465
501
|
if (this.isUp && this.target.sessionId && !this.halted)
|
|
466
502
|
return Promise.resolve(this.target.sessionId);
|
|
467
|
-
} else this.target && (console.log(`${
|
|
503
|
+
} else this.target && (console.log(`${w} switching from session ${this.target.sessionId ?? "(new)"} to ${e ?? "(new)"}.`), this.close());
|
|
468
504
|
return this.halted = null, this.cancelRetry(), this.target = { sessionId: e, resume: (t == null ? void 0 : t.resume) === !0, prepare: t == null ? void 0 : t.prepare }, this.startIdleTick(), this.dial();
|
|
469
505
|
}
|
|
470
506
|
/**
|
|
@@ -474,9 +510,11 @@ const ke = 4001, st = 4002, De = 4004, nt = 4100, H = 500, it = 2e4, rt = 1e3, o
|
|
|
474
510
|
*/
|
|
475
511
|
async ensure(e) {
|
|
476
512
|
var t;
|
|
513
|
+
if (this.halted === "credentials-expired" && this.target)
|
|
514
|
+
return console.warn(`${w} send guard: halted on an expired credential — checking it again before the send.`), this.halted = null, this.target.resume = !0, this.dial();
|
|
477
515
|
if (this.halted)
|
|
478
516
|
throw new Error(`The connection was halted (${this.halted}); session ${((t = this.target) == null ? void 0 : t.sessionId) ?? e ?? "none"} cannot be redialled.`);
|
|
479
|
-
return this.target ? this.inflight ? this.inflight : this.isUp && this.target.sessionId ? this.target.sessionId : (console.warn(`${
|
|
517
|
+
return this.target ? this.inflight ? this.inflight : this.isUp && this.target.sessionId ? this.target.sessionId : (console.warn(`${w} send guard: socket is DOWN at send time (session ${this.target.sessionId ?? "(new)"}, status ${this.state.connectionStatus}) — redialling now instead of in ${this.wait}ms.`), this.cancelRetry(), this.target.resume = !0, this.dial()) : (console.warn(`${w} send guard: nothing supervised yet — opening session ${e ?? "(new)"} with the replay cursor.`), this.open(e, { resume: !0 }));
|
|
480
518
|
}
|
|
481
519
|
/** Stop supervising: hang up, cancel any retry, stop the idle tick. Never throws. */
|
|
482
520
|
close() {
|
|
@@ -485,7 +523,7 @@ const ke = 4001, st = 4002, De = 4004, nt = 4100, H = 500, it = 2e4, rt = 1e3, o
|
|
|
485
523
|
try {
|
|
486
524
|
this.ports.hangUp();
|
|
487
525
|
} catch (t) {
|
|
488
|
-
console.error(`${
|
|
526
|
+
console.error(`${w} hangUp threw`, t);
|
|
489
527
|
}
|
|
490
528
|
e && this.state.setConnectionStatus(E.Disconnected);
|
|
491
529
|
}
|
|
@@ -501,12 +539,12 @@ const ke = 4001, st = 4002, De = 4004, nt = 4100, H = 500, it = 2e4, rt = 1e3, o
|
|
|
501
539
|
* A close that lands while a dial is in flight is remembered and judged when that dial fails.
|
|
502
540
|
*/
|
|
503
541
|
transportClosed(e, t) {
|
|
504
|
-
if (e !==
|
|
542
|
+
if (e !== Re && (this.lastCloseCode = e, !!this.target)) {
|
|
505
543
|
if (this.inflight) {
|
|
506
|
-
console.log(`${
|
|
544
|
+
console.log(`${w} socket closed (code=${e}) while a dial is in flight — judged when it settles.`);
|
|
507
545
|
return;
|
|
508
546
|
}
|
|
509
|
-
this.state.connectionStatus === E.Connected && (console.warn(`${
|
|
547
|
+
this.state.connectionStatus === E.Connected && (console.warn(`${w} socket closed: code=${e} reason="${t}" (session ${this.target.sessionId ?? "(new)"}).`), this.state.setConnectionStatus(E.Disconnected), this.judge(e));
|
|
510
548
|
}
|
|
511
549
|
}
|
|
512
550
|
// ─── The dial ───────────────────────────────────────────────────────────
|
|
@@ -514,11 +552,15 @@ const ke = 4001, st = 4002, De = 4004, nt = 4100, H = 500, it = 2e4, rt = 1e3, o
|
|
|
514
552
|
const e = this.target;
|
|
515
553
|
this.lastCloseCode = null, this.state.setConnectionStatus(E.Connecting);
|
|
516
554
|
const t = this.now();
|
|
517
|
-
console.log(`${
|
|
518
|
-
const n = (async () =>
|
|
555
|
+
console.log(`${w} dialling session ${e.sessionId ?? "(new)"}${e.resume ? " with the replay cursor" : ""}${this.everConnected ? " (reconnect)" : ""}.`);
|
|
556
|
+
const n = (async () => {
|
|
557
|
+
if (this.ports.ensureCredentials && !await this.ports.ensureCredentials())
|
|
558
|
+
throw this.target === e && !this.halted && (this.state.setConnectionStatus(E.Disconnected), this.halt("credentials-expired", { sessionId: e.sessionId })), new Error("The access token has expired and could not be renewed — not dialling.");
|
|
559
|
+
return e.prepare && await e.prepare(), this.ports.dial(e.sessionId, { resume: e.resume });
|
|
560
|
+
})().then((r) => {
|
|
519
561
|
var c, l;
|
|
520
562
|
if (this.target !== e) {
|
|
521
|
-
console.log(`${
|
|
563
|
+
console.log(`${w} a dial for ${e.sessionId ?? "(new)"} resolved after it was abandoned — hanging up.`);
|
|
522
564
|
try {
|
|
523
565
|
this.ports.hangUp();
|
|
524
566
|
} catch {
|
|
@@ -526,7 +568,7 @@ const ke = 4001, st = 4002, De = 4004, nt = 4100, H = 500, it = 2e4, rt = 1e3, o
|
|
|
526
568
|
throw new Error("Connection attempt abandoned");
|
|
527
569
|
}
|
|
528
570
|
if (e.sessionId && r !== e.sessionId) {
|
|
529
|
-
console.error(`${
|
|
571
|
+
console.error(`${w} asked for session ${e.sessionId}, the server answered with ${r} — refusing the swap and halting.`);
|
|
530
572
|
try {
|
|
531
573
|
this.ports.hangUp();
|
|
532
574
|
} catch {
|
|
@@ -534,11 +576,11 @@ const ke = 4001, st = 4002, De = 4004, nt = 4100, H = 500, it = 2e4, rt = 1e3, o
|
|
|
534
576
|
throw this.state.setConnectionStatus(E.Disconnected), this.halt("session-gone", { sessionId: e.sessionId, actualSessionId: r }), new Error(`Session ${e.sessionId} no longer exists on the server (it answered with ${r}).`);
|
|
535
577
|
}
|
|
536
578
|
const o = this.everConnected;
|
|
537
|
-
return this.everConnected = !0, e.sessionId = r, e.resume = !0, e.prepare = void 0, this.wait = H, this.attempt = 0, this.state.setConnectionStatus(E.Connected), console.log(`${
|
|
579
|
+
return this.everConnected = !0, e.sessionId = r, e.resume = !0, e.prepare = void 0, this.wait = H, this.attempt = 0, this.state.setConnectionStatus(E.Connected), console.log(`${w} ${o ? "reconnected to" : "connected to"} session ${r} in ${this.now() - t}ms.`), (l = (c = this.ports).onConnected) == null || l.call(c, r, { reconnect: o }), r;
|
|
538
580
|
}).catch((r) => {
|
|
539
581
|
if (this.target === e && !this.halted) {
|
|
540
582
|
const o = this.lastCloseCode;
|
|
541
|
-
console.error(`${
|
|
583
|
+
console.error(`${w} dial of session ${e.sessionId ?? "(new)"} failed after ${this.now() - t}ms${o !== null ? ` (socket closed with ${o})` : ""}:`, r), this.state.setConnectionStatus(E.Disconnected), this.inflight === n && (this.inflight = null), this.judge(o);
|
|
542
584
|
}
|
|
543
585
|
throw r;
|
|
544
586
|
}).finally(() => {
|
|
@@ -550,33 +592,33 @@ const ke = 4001, st = 4002, De = 4004, nt = 4100, H = 500, it = 2e4, rt = 1e3, o
|
|
|
550
592
|
judge(e) {
|
|
551
593
|
var s;
|
|
552
594
|
const t = (s = this.target) == null ? void 0 : s.sessionId;
|
|
553
|
-
if (e ===
|
|
554
|
-
if (e ===
|
|
595
|
+
if (e === rt) return this.halt("attached-elsewhere", { sessionId: t, code: e });
|
|
596
|
+
if (e === be) return this.halt("session-gone", { sessionId: t, code: e });
|
|
555
597
|
if (e === 1e3 || e === 1008) return this.halt("closed-by-server", { sessionId: t, code: e });
|
|
556
598
|
this.scheduleRetry();
|
|
557
599
|
}
|
|
558
600
|
halt(e, t) {
|
|
559
601
|
var s, n;
|
|
560
|
-
this.halted = e, this.cancelRetry(), console.warn(`${
|
|
602
|
+
this.halted = e, this.cancelRetry(), console.warn(`${w} halted (${e}) on session ${t.sessionId ?? "(new)"}${t.code !== void 0 ? `, close code ${t.code}` : ""} — no automatic redial; an explicit open() may try again.`);
|
|
561
603
|
try {
|
|
562
604
|
(n = (s = this.ports).onHalt) == null || n.call(s, e, t);
|
|
563
605
|
} catch (r) {
|
|
564
|
-
console.error(`${
|
|
606
|
+
console.error(`${w} onHalt threw`, r);
|
|
565
607
|
}
|
|
566
608
|
}
|
|
567
609
|
scheduleRetry() {
|
|
568
610
|
var t, s;
|
|
569
611
|
if (!this.target || this.retryTimer || this.inflight) return;
|
|
570
612
|
if (!this.state.sessionActive) {
|
|
571
|
-
console.log(`${
|
|
613
|
+
console.log(`${w} session idle — not redialling until activity resumes.`);
|
|
572
614
|
return;
|
|
573
615
|
}
|
|
574
616
|
const e = this.jittered(this.wait);
|
|
575
|
-
this.wait = Math.min(Math.floor(this.wait + this.wait * this.wait /
|
|
617
|
+
this.wait = Math.min(Math.floor(this.wait + this.wait * this.wait / ct), at), this.attempt += 1, console.warn(`${w} redialling session ${this.target.sessionId ?? "(new)"} in ${e}ms (then ${this.wait}ms, attempt ${this.attempt}).`);
|
|
576
618
|
try {
|
|
577
619
|
(s = (t = this.ports).onRetryScheduled) == null || s.call(t, { sessionId: this.target.sessionId, delayMs: e, attempt: this.attempt });
|
|
578
620
|
} catch (n) {
|
|
579
|
-
console.error(`${
|
|
621
|
+
console.error(`${w} onRetryScheduled threw`, n);
|
|
580
622
|
}
|
|
581
623
|
this.retryTimer = setTimeout(() => {
|
|
582
624
|
this.retryTimer = null, !(!this.target || this.halted) && (this.target.resume = !0, this.dial().catch(() => {
|
|
@@ -587,7 +629,7 @@ const ke = 4001, st = 4002, De = 4004, nt = 4100, H = 500, it = 2e4, rt = 1e3, o
|
|
|
587
629
|
this.retryTimer && (clearTimeout(this.retryTimer), this.retryTimer = null);
|
|
588
630
|
}
|
|
589
631
|
jittered(e) {
|
|
590
|
-
return Math.max(0, Math.round(e + e *
|
|
632
|
+
return Math.max(0, Math.round(e + e * lt * (Math.random() * 2 - 1)));
|
|
591
633
|
}
|
|
592
634
|
sameTarget(e) {
|
|
593
635
|
var t;
|
|
@@ -595,7 +637,7 @@ const ke = 4001, st = 4002, De = 4004, nt = 4100, H = 500, it = 2e4, rt = 1e3, o
|
|
|
595
637
|
}
|
|
596
638
|
// ─── Idle ───────────────────────────────────────────────────────────────
|
|
597
639
|
startIdleTick() {
|
|
598
|
-
this.idleTimer || (this.idleTimer = setInterval(() => this.tick(),
|
|
640
|
+
this.idleTimer || (this.idleTimer = setInterval(() => this.tick(), ut));
|
|
599
641
|
}
|
|
600
642
|
stopIdleTick() {
|
|
601
643
|
this.idleTimer && (clearInterval(this.idleTimer), this.idleTimer = null);
|
|
@@ -612,25 +654,37 @@ const ke = 4001, st = 4002, De = 4004, nt = 4100, H = 500, it = 2e4, rt = 1e3, o
|
|
|
612
654
|
if (!this.target) return;
|
|
613
655
|
this.state.turnOpen && this.state.setLastActivity();
|
|
614
656
|
const e = this.now() - this.state.lastActivity;
|
|
615
|
-
if (e >
|
|
657
|
+
if (e > N) {
|
|
616
658
|
if (this.state.sessionActive && this.state.setIsSessionActive(!1), this.cancelRetry(), this.state.connectionStatus === E.Connected) {
|
|
617
|
-
console.warn(`${
|
|
659
|
+
console.warn(`${w} idle for ${Math.round(e / 1e3)}s (limit ${N / 1e3}s) — closing the socket (session ${this.target.sessionId ?? "(new)"}). Activity, or a send, redials it.`);
|
|
618
660
|
try {
|
|
619
661
|
this.ports.hangUp();
|
|
620
662
|
} catch (t) {
|
|
621
|
-
console.error(`${
|
|
663
|
+
console.error(`${w} hangUp threw`, t);
|
|
622
664
|
}
|
|
623
665
|
this.state.setConnectionStatus(E.Disconnected);
|
|
624
666
|
}
|
|
625
667
|
return;
|
|
626
668
|
}
|
|
627
|
-
this.state.sessionActive || (console.log(`${
|
|
628
|
-
}))), e >
|
|
669
|
+
this.state.sessionActive || (console.log(`${w} activity resumed — the session is active again.`), this.state.setIsSessionActive(!0), this.wait = H, this.state.connectionStatus === E.Disconnected && !this.halted && !this.inflight && (this.target.resume = !0, this.dial().catch(() => {
|
|
670
|
+
}))), e > N * ht ? this.idleWarningLogged || (this.idleWarningLogged = !0, console.warn(`${w} idle ${Math.round(e / 1e3)}s of ${N / 1e3}s — the socket closes in about ${Math.round((N - e) / 1e3)}s unless something happens.`)) : this.idleWarningLogged = !1;
|
|
629
671
|
}
|
|
630
672
|
};
|
|
631
|
-
h(
|
|
632
|
-
let
|
|
633
|
-
|
|
673
|
+
h(le, "ConnectionSupervisor");
|
|
674
|
+
let ee = le;
|
|
675
|
+
function dt(i, e = Date.now()) {
|
|
676
|
+
if (!i) return null;
|
|
677
|
+
const t = i.split(".")[1];
|
|
678
|
+
if (!t) return null;
|
|
679
|
+
try {
|
|
680
|
+
const s = t.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(t.length / 4) * 4, "="), n = JSON.parse(atob(s)).exp;
|
|
681
|
+
return typeof n == "number" ? n - e / 1e3 : null;
|
|
682
|
+
} catch {
|
|
683
|
+
return null;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
h(dt, "secondsUntilJwtExpiry");
|
|
687
|
+
const he = class he {
|
|
634
688
|
constructor(e) {
|
|
635
689
|
a(this, "pending", null);
|
|
636
690
|
a(this, "lastPublishedAt", 0);
|
|
@@ -662,8 +716,15 @@ const ce = class ce {
|
|
|
662
716
|
this.trailing && (clearTimeout(this.trailing), this.trailing = null);
|
|
663
717
|
}
|
|
664
718
|
};
|
|
665
|
-
h(
|
|
666
|
-
let
|
|
719
|
+
h(he, "ThrottledEmitter");
|
|
720
|
+
let te = he;
|
|
721
|
+
function ft(i) {
|
|
722
|
+
return async () => {
|
|
723
|
+
const e = dt(i());
|
|
724
|
+
return e === null || e > 0 ? !0 : (console.warn(`[AgentGateway] the access token expired ${Math.round(-e)}s ago and the host gave no way to renew it — not dialling.`), !1);
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
h(ft, "builtInCredentialCheck");
|
|
667
728
|
const y = class y {
|
|
668
729
|
constructor(e, t, s, n, r, o, c, l, f, g, m) {
|
|
669
730
|
a(this, "base_url");
|
|
@@ -714,7 +775,7 @@ const y = class y {
|
|
|
714
775
|
*/
|
|
715
776
|
a(this, "everConnected", !1);
|
|
716
777
|
/** Publishes the live message to the store; see ThrottledEmitter for the cadence rules. */
|
|
717
|
-
a(this, "liveMessage", new
|
|
778
|
+
a(this, "liveMessage", new te({
|
|
718
779
|
windowMs: y.CURRENT_MSG_THROTTLE_MS,
|
|
719
780
|
publish: /* @__PURE__ */ h((e) => {
|
|
720
781
|
this.sessionState.setCurrentMessage(e), this.eventBusService.gatewayEmitMessage(e);
|
|
@@ -730,8 +791,9 @@ const y = class y {
|
|
|
730
791
|
a(this, "runningRequests", /* @__PURE__ */ new Map());
|
|
731
792
|
this.options = m ?? {}, this.user = e, this.config = r, this.rawJwt = e.access_token, this.base_url = n, this.eventBusService = t, this.sessionId = g, this.artifactService = s, this.sessionState = o.getState(), this.notificationPort = c, this.storageService = f, o.subscribe((u, p) => {
|
|
732
793
|
this.sessionState = u, p.turnOpen && !u.turnOpen && this.flushAnnouncements();
|
|
733
|
-
}), this.wsService = l, this.connection = new
|
|
794
|
+
}), this.wsService = l, this.connection = new ee({
|
|
734
795
|
store: o,
|
|
796
|
+
ensureCredentials: this.options.ensureDialableToken ?? (this.options.getToken ? ft(this.options.getToken) : void 0),
|
|
735
797
|
// A redial while a turn is open carries the turn's id: the server tells us if it cannot continue it.
|
|
736
798
|
dial: /* @__PURE__ */ h((u, p) => this.wsService.connect(u, {
|
|
737
799
|
...p,
|
|
@@ -744,12 +806,12 @@ const y = class y {
|
|
|
744
806
|
}, "onConnected"),
|
|
745
807
|
onRetryScheduled: /* @__PURE__ */ h(({ delayMs: u, attempt: p }) => {
|
|
746
808
|
var D;
|
|
747
|
-
const
|
|
748
|
-
this.sessionState.setConnectionOutage({ since: C, retryAt:
|
|
809
|
+
const S = Date.now(), C = ((D = this.sessionState.connectionOutage) == null ? void 0 : D.since) ?? S;
|
|
810
|
+
this.sessionState.setConnectionOutage({ since: C, retryAt: S + u, attempt: p, halted: null }), S - C >= y.OUTAGE_CLOSES_TURN_AFTER_MS && this.closeOpenTurnWith(y.OUTAGE_TURN_MESSAGE);
|
|
749
811
|
}, "onRetryScheduled"),
|
|
750
812
|
onHalt: /* @__PURE__ */ h((u, p) => {
|
|
751
|
-
const
|
|
752
|
-
this.sessionState.setConnectionOutage({ since: (
|
|
813
|
+
const S = this.sessionState.connectionOutage;
|
|
814
|
+
this.sessionState.setConnectionOutage({ since: (S == null ? void 0 : S.since) ?? Date.now(), retryAt: null, attempt: (S == null ? void 0 : S.attempt) ?? 0, halted: u }), this.notifyHalt(u, p), this.closeOpenTurnWith(y.HALT_TURN_MESSAGE[u]);
|
|
753
815
|
}, "onHalt")
|
|
754
816
|
}), this.wsService.onEvent = async (u) => {
|
|
755
817
|
await this.Message(u);
|
|
@@ -789,14 +851,15 @@ const y = class y {
|
|
|
789
851
|
if (!this.sessionState.turnOpen) return;
|
|
790
852
|
const t = this.getCurrentInteractionId(), s = this.openTurns.size > 0 ? [...this.openTurns] : t ? [t] : [];
|
|
791
853
|
for (const n of s)
|
|
792
|
-
console.warn(`[AgentGateway] closing interaction ${n} from the client side: ${e}`), this.Message(
|
|
854
|
+
console.warn(`[AgentGateway] closing interaction ${n} from the client side: ${e}`), this.Message(U.createErrorEvent(e, n));
|
|
793
855
|
}
|
|
794
856
|
/** The supervisor gave up on its own (another tab holds the session, the session is gone, …): tell the user. */
|
|
795
857
|
notifyHalt(e, t) {
|
|
796
858
|
const s = {
|
|
797
859
|
"attached-elsewhere": { message: "Esta sessão já está aberta em outra janela", kind: "session-attached-elsewhere" },
|
|
798
860
|
"session-gone": { message: "A sessão não existe mais no servidor", kind: "session-gone" },
|
|
799
|
-
"closed-by-server": { message: "O servidor encerrou a conexão", kind: "connection-closed" }
|
|
861
|
+
"closed-by-server": { message: "O servidor encerrou a conexão", kind: "connection-closed" },
|
|
862
|
+
"credentials-expired": { message: "Sua sessão expirou. Entre novamente para continuar", kind: "credentials-expired" }
|
|
800
863
|
}, { message: n, kind: r } = s[e];
|
|
801
864
|
try {
|
|
802
865
|
this.notificationPort.pushNotification({
|
|
@@ -920,10 +983,10 @@ const y = class y {
|
|
|
920
983
|
const n = this.interactionsServiceMap.get(t);
|
|
921
984
|
if (n) {
|
|
922
985
|
const o = n.interaction;
|
|
923
|
-
o.interactionQuestion || (o.interactionQuestion = e.content ?? ""), o.origin ?? (o.origin =
|
|
986
|
+
o.interactionQuestion || (o.interactionQuestion = e.content ?? ""), o.origin ?? (o.origin = Te(e.origin));
|
|
924
987
|
return;
|
|
925
988
|
}
|
|
926
|
-
this.openRemoteInteraction(t, e.content ?? "",
|
|
989
|
+
this.openRemoteInteraction(t, e.content ?? "", Te(e.origin), !0);
|
|
927
990
|
}
|
|
928
991
|
/**
|
|
929
992
|
* The server delivered messages this tab queued (AIA Issue 1651). Injected into the running turn — the frame lists
|
|
@@ -965,7 +1028,7 @@ const y = class y {
|
|
|
965
1028
|
return t || (t = this.openRemoteInteraction(e.interactionId, "", void 0, !1)), t.merge(e);
|
|
966
1029
|
}
|
|
967
1030
|
getNewInteractionId() {
|
|
968
|
-
const t =
|
|
1031
|
+
const t = Ge(/* @__PURE__ */ new Date(), "MMM_dd_HH_mm_ss");
|
|
969
1032
|
return `${this.msg_order}_${t}`;
|
|
970
1033
|
}
|
|
971
1034
|
// ─── Inbound: server events ─────────────────────────────────────────────
|
|
@@ -1008,7 +1071,7 @@ const y = class y {
|
|
|
1008
1071
|
});
|
|
1009
1072
|
} catch (t) {
|
|
1010
1073
|
if (this.getCurrentInteractionId()) {
|
|
1011
|
-
const s =
|
|
1074
|
+
const s = U.createErrorEvent("OnMessage error: " + t.toString(), this.getCurrentInteractionId() ?? "Empty Current"), n = this.updateMap(s);
|
|
1012
1075
|
if (console.error("Error event: ", JSON.stringify(s, void 0, 4)), !n) {
|
|
1013
1076
|
console.error("Error event, could not update interaction: ", JSON.stringify(s, void 0, 4));
|
|
1014
1077
|
return;
|
|
@@ -1145,14 +1208,14 @@ const y = class y {
|
|
|
1145
1208
|
}
|
|
1146
1209
|
// ─── Outbound: the user's turns ─────────────────────────────────────────
|
|
1147
1210
|
async sendMessage(e, t) {
|
|
1148
|
-
let s = this.getInteractions().length, n =
|
|
1211
|
+
let s = this.getInteractions().length, n = _.createWaiting(!0, !0, "Overall", /* @__PURE__ */ new Date());
|
|
1149
1212
|
this.sendStatusMessage(e.data, [n], s.toString() + "1");
|
|
1150
1213
|
try {
|
|
1151
1214
|
const { promptAsString: r, json: o } = this.sessionState.onRenderPrompt ? this.sessionState.onRenderPrompt(e.data) : { promptAsString: e.data, json: void 0 };
|
|
1152
1215
|
this.sessionState.onRenderPrompt && (e.data = o, e.friendlyMessage = r);
|
|
1153
|
-
const c = await this.sendMessageInternal(e, t), l =
|
|
1216
|
+
const c = await this.sendMessageInternal(e, t), l = He.createPrompt(r ?? "", (o == null ? void 0 : o.toString()) ?? {});
|
|
1154
1217
|
this.storageService.storePrompt(l);
|
|
1155
|
-
const f =
|
|
1218
|
+
const f = _.fromText("Planejando próximos passos");
|
|
1156
1219
|
return this.sendStatusMessage(e.data, [n, f], s.toString() + "1"), c != null && c.success ? this.eventBusService.ChatEmitMessageSent(e.data, c.interaction) : this.eventBusService.ChatEmitMessageError((c == null ? void 0 : c.error) ?? ""), c;
|
|
1157
1220
|
} catch (r) {
|
|
1158
1221
|
const o = r instanceof Error ? r.message : String(r ?? "");
|
|
@@ -1164,7 +1227,7 @@ const y = class y {
|
|
|
1164
1227
|
created: /* @__PURE__ */ new Date(),
|
|
1165
1228
|
interactionId: "",
|
|
1166
1229
|
partial: !1,
|
|
1167
|
-
parts: [
|
|
1230
|
+
parts: [_.fromError(o)],
|
|
1168
1231
|
version: 0
|
|
1169
1232
|
}
|
|
1170
1233
|
};
|
|
@@ -1176,7 +1239,7 @@ const y = class y {
|
|
|
1176
1239
|
const s = this.suspendState;
|
|
1177
1240
|
this.suspendState = !1;
|
|
1178
1241
|
const n = this.startInteraction(e.friendlyMessage ?? e.data, s);
|
|
1179
|
-
if (this.localInteractionIds.add(n.interactionId), this.registerInteractionCallId(n.interactionId, t), (r = e.userUi) != null && r.name && n.parts.push(
|
|
1242
|
+
if (this.localInteractionIds.add(n.interactionId), this.registerInteractionCallId(n.interactionId, t), (r = e.userUi) != null && r.name && n.parts.push(_.fromUserUi(e.userUi.name, e.userUi.args)), !this.wsService)
|
|
1180
1243
|
throw "no wsService created";
|
|
1181
1244
|
if (!((o = this.config.agentConfig) != null && o.id))
|
|
1182
1245
|
throw "Agent not selected";
|
|
@@ -1249,7 +1312,7 @@ const y = class y {
|
|
|
1249
1312
|
sendStatusMessage(e, t, s) {
|
|
1250
1313
|
var r, o;
|
|
1251
1314
|
let n;
|
|
1252
|
-
((o = (r = this.currentIS) == null ? void 0 : r.interaction) == null ? void 0 : o.turn_complete) === !1 && !this.currentIS.interaction.remote ? (n =
|
|
1315
|
+
((o = (r = this.currentIS) == null ? void 0 : r.interaction) == null ? void 0 : o.turn_complete) === !1 && !this.currentIS.interaction.remote ? (n = ze.cloneDeep(this.currentIS.interaction), n.parts.push(...t)) : n = {
|
|
1253
1316
|
interactionId: "tmp" + s,
|
|
1254
1317
|
created: /* @__PURE__ */ new Date(),
|
|
1255
1318
|
partial: !0,
|
|
@@ -1396,61 +1459,62 @@ a(y, "OUTAGE_CLOSES_TURN_AFTER_MS", 6e4), a(y, "OUTAGE_TURN_MESSAGE", "Sem conex
|
|
|
1396
1459
|
a(y, "NO_CONNECTION_MESSAGE", "Não foi possível obter conexão com o servidor"), a(y, "HALT_TURN_MESSAGE", {
|
|
1397
1460
|
"attached-elsewhere": "Esta sessão está aberta em outra janela. A resposta foi interrompida.",
|
|
1398
1461
|
"session-gone": "A sessão não existe mais no servidor. A resposta foi interrompida.",
|
|
1399
|
-
"closed-by-server": "O servidor encerrou a conexão. A resposta foi interrompida."
|
|
1462
|
+
"closed-by-server": "O servidor encerrou a conexão. A resposta foi interrompida.",
|
|
1463
|
+
"credentials-expired": "Sua sessão expirou. Entre novamente para continuar. A resposta foi interrompida."
|
|
1400
1464
|
});
|
|
1401
|
-
let
|
|
1402
|
-
function
|
|
1403
|
-
const e = new
|
|
1465
|
+
let Me = y;
|
|
1466
|
+
function gt(i) {
|
|
1467
|
+
const e = new Ne();
|
|
1404
1468
|
e.author = "main", e.streamingParts = i.streamingParts, i.partialEventType ? e.eventType = i.partialEventType : e.eventType = i.functionName ? { fullName: z.StreamingFunctionCallUpdateContent, type: I.PartialFunctionCall } : i.partialReasoning ? { fullName: z.StreamingReasoningContent, type: I.Thought } : { fullName: z.StreamingTextContent, type: I.Text }, e.interactionId = i.iteractionId ?? "", e.mimeType = "text/plain", e.partial = !0, e.role = { label: "Assistant" }, e.timestamp = i.timeStamp ?? (/* @__PURE__ */ new Date()).getTime(), e.turnComplete = !1;
|
|
1405
1469
|
const t = e.eventType.type;
|
|
1406
1470
|
if (t == I.PartialFunctionCall) {
|
|
1407
|
-
const s = new
|
|
1471
|
+
const s = new _e();
|
|
1408
1472
|
s.choiceIndex = 0, s.callId = i.functionCallId, s.arguments = i.partialText, s.name = i.functionName, e.content = { items: [s], role: { label: "Assistant" } };
|
|
1409
1473
|
} else if (t == I.Text)
|
|
1410
1474
|
if (e.eventType.fullName == z.StreamingTextContent) {
|
|
1411
|
-
const s = new
|
|
1475
|
+
const s = new Ue();
|
|
1412
1476
|
s.text = i.partialText, e.content = { items: [s], role: { label: "Assistant" } };
|
|
1413
1477
|
} else {
|
|
1414
|
-
const s = new
|
|
1478
|
+
const s = new qe();
|
|
1415
1479
|
s.text = i.partialText, e.content = { items: [s], role: { label: "Assistant" } };
|
|
1416
1480
|
}
|
|
1417
1481
|
else if (t == I.Thought) {
|
|
1418
|
-
const s = new
|
|
1482
|
+
const s = new Be();
|
|
1419
1483
|
s.text = i.partialReasoning, e.content = { items: [s], role: { label: "Assistant" } };
|
|
1420
1484
|
}
|
|
1421
1485
|
return e;
|
|
1422
1486
|
}
|
|
1423
|
-
h(
|
|
1424
|
-
function
|
|
1425
|
-
const e = i.partialEvent ?
|
|
1487
|
+
h(gt, "llmEventFromPartial");
|
|
1488
|
+
function ie(i) {
|
|
1489
|
+
const e = i.partialEvent ? gt(i.partialEvent) : i.event;
|
|
1426
1490
|
if (e)
|
|
1427
1491
|
return i.detachedRunId && (e.detachedRunId = i.detachedRunId, e.detachedRunName = i.detachedRunName), e;
|
|
1428
1492
|
}
|
|
1429
|
-
h(
|
|
1430
|
-
function
|
|
1493
|
+
h(ie, "llmEventFromFrame");
|
|
1494
|
+
function Le(i) {
|
|
1431
1495
|
var e, t, s;
|
|
1432
1496
|
return (((t = (e = i.content) == null ? void 0 : e.items) == null ? void 0 : t.length) ?? 0) > 0 || (((s = i.streamingParts) == null ? void 0 : s.length) ?? 0) > 0;
|
|
1433
1497
|
}
|
|
1434
|
-
h(
|
|
1435
|
-
function
|
|
1498
|
+
h(Le, "carriesContent");
|
|
1499
|
+
function Pe(i) {
|
|
1436
1500
|
var t;
|
|
1437
1501
|
if (i.type !== "InteractionStarted" || !((t = i.interaction) != null && t.interactionId)) return;
|
|
1438
1502
|
if (i.interaction.detachedRunId || !i.detachedRunId) return i.interaction;
|
|
1439
|
-
const e = Object.assign(new
|
|
1503
|
+
const e = Object.assign(new xe(), i.interaction);
|
|
1440
1504
|
return e.detachedRunId = i.detachedRunId, e;
|
|
1441
1505
|
}
|
|
1442
|
-
h(
|
|
1443
|
-
const
|
|
1444
|
-
function
|
|
1506
|
+
h(Pe, "interactionStartFromFrame");
|
|
1507
|
+
const pt = 0.02;
|
|
1508
|
+
function mt(i, e) {
|
|
1445
1509
|
if (!e) return null;
|
|
1446
1510
|
const t = (e.interactionsCompressed ?? 0) > 0 || (e.compressionRatio ?? 0) > 0;
|
|
1447
1511
|
if (!i)
|
|
1448
|
-
return t ?
|
|
1449
|
-
const s = i.size - e.size, n = e.maxSize || i.maxSize || 0, r = n > 0 ? s / n >=
|
|
1450
|
-
return !t && !r ? null :
|
|
1512
|
+
return t ? Ce(e, e.size, e.size) : null;
|
|
1513
|
+
const s = i.size - e.size, n = e.maxSize || i.maxSize || 0, r = n > 0 ? s / n >= pt : i.size > 0 && s / i.size >= 0.1;
|
|
1514
|
+
return !t && !r ? null : Ce(e, i.size, e.size, i.ratio);
|
|
1451
1515
|
}
|
|
1452
|
-
h(
|
|
1453
|
-
function
|
|
1516
|
+
h(mt, "detectCompaction");
|
|
1517
|
+
function Ce(i, e, t, s) {
|
|
1454
1518
|
return {
|
|
1455
1519
|
at: Date.now(),
|
|
1456
1520
|
// Where the bar stood when it happened — the marker's position. The ratio
|
|
@@ -1462,8 +1526,8 @@ function ve(i, e, t, s) {
|
|
|
1462
1526
|
interactionsCompressed: i.interactionsCompressed
|
|
1463
1527
|
};
|
|
1464
1528
|
}
|
|
1465
|
-
h(
|
|
1466
|
-
const
|
|
1529
|
+
h(Ce, "entry");
|
|
1530
|
+
const Ae = 4, wt = 3, St = 20, F = class F {
|
|
1467
1531
|
constructor() {
|
|
1468
1532
|
a(this, "stats");
|
|
1469
1533
|
a(this, "onFlush");
|
|
@@ -1499,14 +1563,14 @@ const Ee = 4, dt = 3, ft = 20, F = class F {
|
|
|
1499
1563
|
record(e) {
|
|
1500
1564
|
const t = Date.now();
|
|
1501
1565
|
if (this.events.push([t, e.textLength]), this.stats.eventCount += 1, this.stats.totalTransfered += e.rawLength, e.sessionInformation && !e.fromDetachedRun) {
|
|
1502
|
-
const r =
|
|
1503
|
-
r && (this.sessionCompactions.push(r), this.sessionCompactions.length >
|
|
1566
|
+
const r = mt(this.previousSessionInformation, e.sessionInformation);
|
|
1567
|
+
r && (this.sessionCompactions.push(r), this.sessionCompactions.length > St && this.sessionCompactions.shift()), this.previousSessionInformation = e.sessionInformation, this.stats.sessionInformation = e.sessionInformation, this.stats.sessionCompactions = this.sessionCompactions;
|
|
1504
1568
|
}
|
|
1505
1569
|
this.stats.elapsed = (t - this.stats.startTime.getTime()) / 1e3;
|
|
1506
|
-
const s = t -
|
|
1570
|
+
const s = t - Ae * 1e3;
|
|
1507
1571
|
for (; this.events.length > 0 && this.events[0][0] <= s; ) this.events.shift();
|
|
1508
1572
|
const n = this.events.reduce((r, o) => r + o[1], 0);
|
|
1509
|
-
this.stats.tokensPerSecond = n /
|
|
1573
|
+
this.stats.tokensPerSecond = n / wt / Ae, this.flushCoalesced();
|
|
1510
1574
|
}
|
|
1511
1575
|
flushCoalesced() {
|
|
1512
1576
|
if (!this.onFlush) return;
|
|
@@ -1522,12 +1586,12 @@ const Ee = 4, dt = 3, ft = 20, F = class F {
|
|
|
1522
1586
|
}
|
|
1523
1587
|
};
|
|
1524
1588
|
h(F, "StreamStatsTracker"), a(F, "STATS_FLUSH_MS", 120);
|
|
1525
|
-
let
|
|
1526
|
-
const
|
|
1589
|
+
let se = F;
|
|
1590
|
+
const It = 5e3, Tt = 3e4, X = 1e4, ue = class ue {
|
|
1527
1591
|
constructor(e = "ws://localhost:8000", t) {
|
|
1528
1592
|
a(this, "ws", null);
|
|
1529
1593
|
/** Frame counts, byte totals, the token-rate estimate and the compaction history — see StreamStatsTracker. */
|
|
1530
|
-
a(this, "statsTracker", new
|
|
1594
|
+
a(this, "statsTracker", new se());
|
|
1531
1595
|
a(this, "baseUrl");
|
|
1532
1596
|
/**
|
|
1533
1597
|
* Optional callback that returns the current JWT. We re-evaluate it on every connect/reconnect
|
|
@@ -1575,7 +1639,7 @@ const gt = 5e3, pt = 3e4, Y = 1e4, le = class le {
|
|
|
1575
1639
|
* the single-attach policy makes it undeliverable from here anyway.
|
|
1576
1640
|
*/
|
|
1577
1641
|
a(this, "pendingAnswers", []);
|
|
1578
|
-
this.baseUrl = e, this.getToken = t, this.firstTokenInteractions = /* @__PURE__ */ new Set(), this.streamingResponseSerializer =
|
|
1642
|
+
this.baseUrl = e, this.getToken = t, this.firstTokenInteractions = /* @__PURE__ */ new Set(), this.streamingResponseSerializer = ne(), console.log("SOCKET INSTACE", Qe()), this.lastActivity = (/* @__PURE__ */ new Date()).getTime();
|
|
1579
1643
|
}
|
|
1580
1644
|
get stats() {
|
|
1581
1645
|
return this.statsTracker.stats;
|
|
@@ -1598,7 +1662,7 @@ const gt = 5e3, pt = 3e4, Y = 1e4, le = class le {
|
|
|
1598
1662
|
*/
|
|
1599
1663
|
connect(e, t) {
|
|
1600
1664
|
return new Promise(async (s, n) => {
|
|
1601
|
-
var D,
|
|
1665
|
+
var D, x;
|
|
1602
1666
|
t != null && t.resume || (this.lastSeq = -1);
|
|
1603
1667
|
const r = (D = this.getToken) == null ? void 0 : D.call(this), o = [];
|
|
1604
1668
|
r && o.push(`access_token=${encodeURIComponent(r)}`), e && this.lastSeq >= 0 && o.push(`lastSeq=${this.lastSeq}`), e && (t != null && t.resume) && t.openInteractionId && o.push(`openInteraction=${encodeURIComponent(t.openInteractionId)}`);
|
|
@@ -1623,7 +1687,7 @@ const gt = 5e3, pt = 3e4, Y = 1e4, le = class le {
|
|
|
1623
1687
|
};
|
|
1624
1688
|
const g = 200, m = 3e4, u = 8e3, p = this.ws;
|
|
1625
1689
|
this.sessionId = void 0;
|
|
1626
|
-
let
|
|
1690
|
+
let S = 0, C = 0;
|
|
1627
1691
|
for (; ; ) {
|
|
1628
1692
|
if (this.ws !== p) {
|
|
1629
1693
|
n("Connection attempt superseded by a newer connect()");
|
|
@@ -1634,7 +1698,7 @@ const gt = 5e3, pt = 3e4, Y = 1e4, le = class le {
|
|
|
1634
1698
|
n("Connection closed before a session id was received");
|
|
1635
1699
|
return;
|
|
1636
1700
|
}
|
|
1637
|
-
if (p.readyState === WebSocket.CONNECTING &&
|
|
1701
|
+
if (p.readyState === WebSocket.CONNECTING && S >= m) {
|
|
1638
1702
|
try {
|
|
1639
1703
|
p.close();
|
|
1640
1704
|
} catch {
|
|
@@ -1646,9 +1710,9 @@ const gt = 5e3, pt = 3e4, Y = 1e4, le = class le {
|
|
|
1646
1710
|
n(`Connected but no session id arrived within ${u / 1e3}s`);
|
|
1647
1711
|
return;
|
|
1648
1712
|
}
|
|
1649
|
-
|
|
1713
|
+
S % 2e3 === 0 && console.log("Aguardando session Id"), await this.sleep(g), S += g, p.readyState === WebSocket.OPEN && (C += g);
|
|
1650
1714
|
}
|
|
1651
|
-
console.log(`[WebSocket] Session ${this.sessionId} proven${this.lastSeq >= 0 ? ` (replaying from lastSeq=${this.lastSeq})` : ""}.`), this.lastKnownSessionId = this.sessionId, (
|
|
1715
|
+
console.log(`[WebSocket] Session ${this.sessionId} proven${this.lastSeq >= 0 ? ` (replaying from lastSeq=${this.lastSeq})` : ""}.`), this.lastKnownSessionId = this.sessionId, (x = this.onOpen) == null || x.call(this), this.flushPendingAnswers(this.sessionId), s(this.sessionId);
|
|
1652
1716
|
});
|
|
1653
1717
|
}
|
|
1654
1718
|
/** Drop the current socket without reporting it: handlers off, then close. */
|
|
@@ -1688,7 +1752,7 @@ const gt = 5e3, pt = 3e4, Y = 1e4, le = class le {
|
|
|
1688
1752
|
case "Event":
|
|
1689
1753
|
break;
|
|
1690
1754
|
case "InteractionStarted": {
|
|
1691
|
-
const r =
|
|
1755
|
+
const r = Pe(e);
|
|
1692
1756
|
r ? (n = this.onInteractionStarted) == null || n.call(this, r) : console.warn("[WebSocket] InteractionStarted frame without an interaction id");
|
|
1693
1757
|
break;
|
|
1694
1758
|
}
|
|
@@ -1700,8 +1764,8 @@ const gt = 5e3, pt = 3e4, Y = 1e4, le = class le {
|
|
|
1700
1764
|
default:
|
|
1701
1765
|
console.warn("[WebSocket] Unknown message type:", e.type);
|
|
1702
1766
|
}
|
|
1703
|
-
const s =
|
|
1704
|
-
return s ? (
|
|
1767
|
+
const s = ie(e);
|
|
1768
|
+
return s ? (Le(s) && this.emitFirstToken(s.interactionId), this.handleEvent(s, t), s) : null;
|
|
1705
1769
|
}
|
|
1706
1770
|
emitFirstToken(e) {
|
|
1707
1771
|
var t;
|
|
@@ -1820,21 +1884,21 @@ const gt = 5e3, pt = 3e4, Y = 1e4, le = class le {
|
|
|
1820
1884
|
const e = Date.now();
|
|
1821
1885
|
if (this.pingSentAt !== null) {
|
|
1822
1886
|
const t = e - this.pingSentAt;
|
|
1823
|
-
if (t >=
|
|
1887
|
+
if (t >= X) {
|
|
1824
1888
|
this.failSocket(
|
|
1825
|
-
|
|
1889
|
+
ot,
|
|
1826
1890
|
`No frame received for ${Math.round(t / 1e3)}s after a Ping`
|
|
1827
1891
|
);
|
|
1828
1892
|
return;
|
|
1829
1893
|
}
|
|
1830
|
-
console.warn(`[WebSocket] Still no reply ${t}ms after the Ping (budget ${
|
|
1894
|
+
console.warn(`[WebSocket] Still no reply ${t}ms after the Ping (budget ${X}ms, session ${this.sessionLabel}) — the peer may be gone.`);
|
|
1831
1895
|
return;
|
|
1832
1896
|
}
|
|
1833
|
-
e - this.lastActivity >=
|
|
1897
|
+
e - this.lastActivity >= Tt && this.ping();
|
|
1834
1898
|
} catch (e) {
|
|
1835
1899
|
console.error("Error on monitor", e);
|
|
1836
1900
|
}
|
|
1837
|
-
},
|
|
1901
|
+
}, It);
|
|
1838
1902
|
}
|
|
1839
1903
|
/**
|
|
1840
1904
|
* Send a heartbeat ping and start the reply clock (unless one is already running).
|
|
@@ -1845,7 +1909,7 @@ const gt = 5e3, pt = 3e4, Y = 1e4, le = class le {
|
|
|
1845
1909
|
AgentId: "",
|
|
1846
1910
|
InteractionId: "",
|
|
1847
1911
|
ModelId: ""
|
|
1848
|
-
}), this.pingSentAt === null && (this.pingSentAt = Date.now(), console.log(`[WebSocket] Ping sent after ${Date.now() - this.lastActivity}ms of silence (session ${this.sessionLabel}); any frame within ${
|
|
1912
|
+
}), this.pingSentAt === null && (this.pingSentAt = Date.now(), console.log(`[WebSocket] Ping sent after ${Date.now() - this.lastActivity}ms of silence (session ${this.sessionLabel}); any frame within ${X}ms answers it.`));
|
|
1849
1913
|
}
|
|
1850
1914
|
/**
|
|
1851
1915
|
* Behave as if the peer vanished: the socket is closed and reported as an abnormal close (1006),
|
|
@@ -1880,7 +1944,7 @@ const gt = 5e3, pt = 3e4, Y = 1e4, le = class le {
|
|
|
1880
1944
|
* Disconnect the WebSocket
|
|
1881
1945
|
*/
|
|
1882
1946
|
disconnect() {
|
|
1883
|
-
console.log(`[WebSocket] disconnect() (session ${this.sessionLabel})`), this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingSentAt = null, this.firstTokenInteractions.clear(), this.lastKnownSessionId = void 0, this.lastSeq = -1, this.ws && (this.ws.close(
|
|
1947
|
+
console.log(`[WebSocket] disconnect() (session ${this.sessionLabel})`), this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingSentAt = null, this.firstTokenInteractions.clear(), this.lastKnownSessionId = void 0, this.lastSeq = -1, this.ws && (this.ws.close(Re, "Intentional disconnect"), this.ws = null);
|
|
1884
1948
|
}
|
|
1885
1949
|
/**
|
|
1886
1950
|
* Check if connected
|
|
@@ -1890,7 +1954,7 @@ const gt = 5e3, pt = 3e4, Y = 1e4, le = class le {
|
|
|
1890
1954
|
}
|
|
1891
1955
|
async handleEvent(e, t) {
|
|
1892
1956
|
var n, r, o, c;
|
|
1893
|
-
const s = (r = (n = e.content) == null ? void 0 : n.items) == null ? void 0 : r.find((l) => l instanceof
|
|
1957
|
+
const s = (r = (n = e.content) == null ? void 0 : n.items) == null ? void 0 : r.find((l) => l instanceof We);
|
|
1894
1958
|
if (s) {
|
|
1895
1959
|
(o = this.onBillingLimit) == null || o.call(this, {
|
|
1896
1960
|
plan: s.plan ?? "team",
|
|
@@ -1907,7 +1971,7 @@ const gt = 5e3, pt = 3e4, Y = 1e4, le = class le {
|
|
|
1907
1971
|
return;
|
|
1908
1972
|
}
|
|
1909
1973
|
try {
|
|
1910
|
-
const l =
|
|
1974
|
+
const l = U.parseFromTypedEvent(e);
|
|
1911
1975
|
if (!l)
|
|
1912
1976
|
throw "Server event was null";
|
|
1913
1977
|
this.statsTracker.record({
|
|
@@ -1923,9 +1987,9 @@ const gt = 5e3, pt = 3e4, Y = 1e4, le = class le {
|
|
|
1923
1987
|
}
|
|
1924
1988
|
}
|
|
1925
1989
|
};
|
|
1926
|
-
h(
|
|
1927
|
-
let
|
|
1928
|
-
const
|
|
1990
|
+
h(ue, "WebSocketConnecionV2");
|
|
1991
|
+
let ke = ue;
|
|
1992
|
+
const de = class de {
|
|
1929
1993
|
constructor(e, t) {
|
|
1930
1994
|
a(this, "cache", /* @__PURE__ */ new Map());
|
|
1931
1995
|
a(this, "serverBaseUrl");
|
|
@@ -1933,7 +1997,7 @@ const he = class he {
|
|
|
1933
1997
|
this.serverBaseUrl = e.replace(/\/$/, ""), this.accessToken = t;
|
|
1934
1998
|
}
|
|
1935
1999
|
get headers() {
|
|
1936
|
-
return { Authorization: `Bearer ${
|
|
2000
|
+
return { Authorization: `Bearer ${je(this.accessToken)}` };
|
|
1937
2001
|
}
|
|
1938
2002
|
async init() {
|
|
1939
2003
|
}
|
|
@@ -1980,24 +2044,24 @@ const he = class he {
|
|
|
1980
2044
|
}
|
|
1981
2045
|
}
|
|
1982
2046
|
};
|
|
1983
|
-
h(
|
|
1984
|
-
let
|
|
1985
|
-
const
|
|
2047
|
+
h(de, "HttpArtifactService");
|
|
2048
|
+
let Oe = de;
|
|
2049
|
+
const fe = class fe extends Error {
|
|
1986
2050
|
constructor(e, t) {
|
|
1987
2051
|
super(t ?? `GET detached-run frames answered ${e}`), this.status = e, this.name = "DetachedRunFramesHttpError";
|
|
1988
2052
|
}
|
|
1989
2053
|
};
|
|
1990
|
-
h(
|
|
1991
|
-
let P =
|
|
1992
|
-
function
|
|
2054
|
+
h(fe, "DetachedRunFramesHttpError");
|
|
2055
|
+
let P = fe;
|
|
2056
|
+
function yt(i) {
|
|
1993
2057
|
if (i instanceof P) {
|
|
1994
2058
|
const { status: e } = i;
|
|
1995
2059
|
return { kind: e === 401 ? "unauthorized" : e === 403 ? "forbidden" : e === 404 || e === 410 ? "notFound" : "gaveUp", status: e, cause: i };
|
|
1996
2060
|
}
|
|
1997
2061
|
return { kind: "gaveUp", cause: i };
|
|
1998
2062
|
}
|
|
1999
|
-
h(
|
|
2000
|
-
function
|
|
2063
|
+
h(yt, "toDetachedRunFollowError");
|
|
2064
|
+
function vt(i) {
|
|
2001
2065
|
let e = "", t = [], s, n;
|
|
2002
2066
|
const r = /* @__PURE__ */ h(() => {
|
|
2003
2067
|
(t.length > 0 || s !== void 0) && i({ event: s, data: t.join(`
|
|
@@ -2028,12 +2092,12 @@ function wt(i) {
|
|
|
2028
2092
|
}
|
|
2029
2093
|
};
|
|
2030
2094
|
}
|
|
2031
|
-
h(
|
|
2032
|
-
function
|
|
2095
|
+
h(vt, "createSseParser");
|
|
2096
|
+
function Et(i) {
|
|
2033
2097
|
return i >= 500 || i === 408 || i === 429;
|
|
2034
2098
|
}
|
|
2035
|
-
h(
|
|
2036
|
-
function
|
|
2099
|
+
h(Et, "retryable");
|
|
2100
|
+
function Mt(i, e) {
|
|
2037
2101
|
return new Promise((t) => {
|
|
2038
2102
|
if (e != null && e.aborted) return t();
|
|
2039
2103
|
const s = setTimeout(n, i);
|
|
@@ -2043,22 +2107,22 @@ function It(i, e) {
|
|
|
2043
2107
|
h(n, "done"), e == null || e.addEventListener("abort", n, { once: !0 });
|
|
2044
2108
|
});
|
|
2045
2109
|
}
|
|
2046
|
-
h(
|
|
2047
|
-
function
|
|
2110
|
+
h(Mt, "sleep");
|
|
2111
|
+
function Ct(i, e, t, s) {
|
|
2048
2112
|
const n = e === "session" ? "sessions" : "detached-runs";
|
|
2049
2113
|
return `${i.replace(/\/+$/, "")}/${n}/${encodeURIComponent(t)}/frames?afterSeq=${s}`;
|
|
2050
2114
|
}
|
|
2051
|
-
h(
|
|
2052
|
-
async function
|
|
2053
|
-
var
|
|
2054
|
-
const { baseUrl: e, runId: t, signal: s, onFrame: n, onEnd: r, onOpen: o, onRetry: c } = i, l = i.resource ?? "detachedRun", f = i.fetchImpl ?? ((A, $) => fetch(A, $)), g = ((
|
|
2055
|
-
let p = i.afterSeq ?? 0,
|
|
2115
|
+
h(Ct, "framesUrl");
|
|
2116
|
+
async function At(i) {
|
|
2117
|
+
var x, v, M, pe, me;
|
|
2118
|
+
const { baseUrl: e, runId: t, signal: s, onFrame: n, onEnd: r, onOpen: o, onRetry: c } = i, l = i.resource ?? "detachedRun", f = i.fetchImpl ?? ((A, $) => fetch(A, $)), g = ((x = i.retry) == null ? void 0 : x.initialMs) ?? 500, m = ((v = i.retry) == null ? void 0 : v.maxMs) ?? 15e3, u = ((M = i.retry) == null ? void 0 : M.maxAttempts) ?? Number.POSITIVE_INFINITY;
|
|
2119
|
+
let p = i.afterSeq ?? 0, S = 0, C = !1;
|
|
2056
2120
|
async function D(A) {
|
|
2057
2121
|
if (i.onUnauthorized)
|
|
2058
2122
|
try {
|
|
2059
2123
|
if (await i.onUnauthorized()) return !0;
|
|
2060
|
-
} catch (
|
|
2061
|
-
console.warn(`[DetachedRunFrames] run ${t}: onUnauthorized threw`,
|
|
2124
|
+
} catch (k) {
|
|
2125
|
+
console.warn(`[DetachedRunFrames] run ${t}: onUnauthorized threw`, k);
|
|
2062
2126
|
}
|
|
2063
2127
|
if (!i.getToken) return !1;
|
|
2064
2128
|
const $ = await i.getToken() ?? void 0;
|
|
@@ -2067,25 +2131,25 @@ async function yt(i) {
|
|
|
2067
2131
|
for (h(D, "secondChance"); !(s != null && s.aborted); ) {
|
|
2068
2132
|
let A;
|
|
2069
2133
|
try {
|
|
2070
|
-
const
|
|
2071
|
-
J && (
|
|
2072
|
-
const
|
|
2073
|
-
if (
|
|
2134
|
+
const k = { Accept: "text/event-stream" }, J = await ((pe = i.getToken) == null ? void 0 : pe.call(i)) ?? void 0;
|
|
2135
|
+
J && (k.Authorization = `Bearer ${J}`);
|
|
2136
|
+
const O = await f(Ct(e, l, t, p), { method: "GET", headers: k, signal: s, cache: "no-store" });
|
|
2137
|
+
if (O.status === 401) {
|
|
2074
2138
|
if (!C && await D(J)) {
|
|
2075
2139
|
C = !0;
|
|
2076
2140
|
continue;
|
|
2077
2141
|
}
|
|
2078
2142
|
throw new P(401);
|
|
2079
2143
|
}
|
|
2080
|
-
if (C = !1, !
|
|
2081
|
-
throw
|
|
2082
|
-
if (!
|
|
2144
|
+
if (C = !1, !O.ok)
|
|
2145
|
+
throw Et(O.status) ? new Error(`GET detached-run frames answered ${O.status}`) : new P(O.status);
|
|
2146
|
+
if (!O.body) throw new P(O.status, "The frames response has no readable body");
|
|
2083
2147
|
o == null || o();
|
|
2084
|
-
let
|
|
2085
|
-
const
|
|
2148
|
+
let B = !1;
|
|
2149
|
+
const W = vt((T) => {
|
|
2086
2150
|
if (T.event === "end") {
|
|
2087
2151
|
const b = Number(T.data);
|
|
2088
|
-
T.data !== "" && Number.isFinite(b) && b > p && (p = b),
|
|
2152
|
+
T.data !== "" && Number.isFinite(b) && b > p && (p = b), B = !0;
|
|
2089
2153
|
return;
|
|
2090
2154
|
}
|
|
2091
2155
|
if (T.event !== void 0 && T.event !== "message" || T.data === "") return;
|
|
@@ -2094,51 +2158,51 @@ async function yt(i) {
|
|
|
2094
2158
|
if (R <= p) return;
|
|
2095
2159
|
p = R;
|
|
2096
2160
|
}
|
|
2097
|
-
|
|
2098
|
-
let
|
|
2161
|
+
B = !1;
|
|
2162
|
+
let Se;
|
|
2099
2163
|
try {
|
|
2100
|
-
|
|
2164
|
+
Se = JSON.parse(T.data);
|
|
2101
2165
|
} catch (b) {
|
|
2102
2166
|
console.warn(`[DetachedRunFrames] run ${t}: a frame that is not JSON was skipped (seq ${T.id ?? "?"})`, b);
|
|
2103
2167
|
return;
|
|
2104
2168
|
}
|
|
2105
|
-
|
|
2169
|
+
S = 0;
|
|
2106
2170
|
try {
|
|
2107
|
-
n(
|
|
2171
|
+
n(Se, R);
|
|
2108
2172
|
} catch (b) {
|
|
2109
2173
|
console.error(`[DetachedRunFrames] run ${t}: onFrame threw on seq ${T.id ?? "?"}`, b);
|
|
2110
2174
|
}
|
|
2111
|
-
}), G =
|
|
2175
|
+
}), G = O.body.getReader(), we = new TextDecoder();
|
|
2112
2176
|
try {
|
|
2113
2177
|
for (; ; ) {
|
|
2114
2178
|
const { done: T, value: R } = await G.read();
|
|
2115
2179
|
if (T) break;
|
|
2116
|
-
|
|
2180
|
+
W.push(we.decode(R, { stream: !0 }));
|
|
2117
2181
|
}
|
|
2118
|
-
|
|
2182
|
+
W.push(we.decode()), W.idle() || (B = !1), W.flush();
|
|
2119
2183
|
} finally {
|
|
2120
|
-
(
|
|
2184
|
+
(me = G.releaseLock) == null || me.call(G);
|
|
2121
2185
|
}
|
|
2122
|
-
if (
|
|
2186
|
+
if (B && l !== "session")
|
|
2123
2187
|
return r == null || r(p), { reason: "end", lastSeq: p };
|
|
2124
2188
|
A = new Error(l === "session" ? "The session frames stream closed" : "The frames stream closed before its end event");
|
|
2125
|
-
} catch (
|
|
2189
|
+
} catch (k) {
|
|
2126
2190
|
if (s != null && s.aborted) break;
|
|
2127
|
-
if (
|
|
2128
|
-
A =
|
|
2191
|
+
if (k instanceof P) throw k;
|
|
2192
|
+
A = k;
|
|
2129
2193
|
}
|
|
2130
|
-
if (
|
|
2131
|
-
const $ = Math.min(g * 2 ** (
|
|
2194
|
+
if (S += 1, S >= u) throw A;
|
|
2195
|
+
const $ = Math.min(g * 2 ** (S - 1), m);
|
|
2132
2196
|
try {
|
|
2133
|
-
c == null || c(A,
|
|
2197
|
+
c == null || c(A, S, $);
|
|
2134
2198
|
} catch {
|
|
2135
2199
|
}
|
|
2136
|
-
await
|
|
2200
|
+
await Mt($, s);
|
|
2137
2201
|
}
|
|
2138
2202
|
return { reason: "aborted", lastSeq: p };
|
|
2139
2203
|
}
|
|
2140
|
-
h(
|
|
2141
|
-
const
|
|
2204
|
+
h(At, "streamDetachedRunFrames");
|
|
2205
|
+
const ge = class ge {
|
|
2142
2206
|
constructor(e) {
|
|
2143
2207
|
a(this, "onEvent");
|
|
2144
2208
|
a(this, "onError");
|
|
@@ -2153,7 +2217,7 @@ const de = class de {
|
|
|
2153
2217
|
/** Following stopped for good — the run is gone, forbidden, the credentials failed twice, or retries ran out. */
|
|
2154
2218
|
a(this, "onFollowError");
|
|
2155
2219
|
a(this, "options");
|
|
2156
|
-
a(this, "serializer",
|
|
2220
|
+
a(this, "serializer", ne());
|
|
2157
2221
|
a(this, "firstTokens", /* @__PURE__ */ new Set());
|
|
2158
2222
|
a(this, "runId");
|
|
2159
2223
|
a(this, "controller", null);
|
|
@@ -2186,7 +2250,7 @@ const de = class de {
|
|
|
2186
2250
|
const t = new AbortController();
|
|
2187
2251
|
return this.controller = t, this.following = !0, new Promise((n, r) => {
|
|
2188
2252
|
let o = !1;
|
|
2189
|
-
|
|
2253
|
+
At({
|
|
2190
2254
|
...this.options,
|
|
2191
2255
|
runId: e,
|
|
2192
2256
|
afterSeq: this.lastSeq,
|
|
@@ -2209,7 +2273,7 @@ const de = class de {
|
|
|
2209
2273
|
o || r(new Error("The frames stream stopped before it opened"));
|
|
2210
2274
|
}).catch((c) => {
|
|
2211
2275
|
var g, m, u;
|
|
2212
|
-
const l =
|
|
2276
|
+
const l = yt(c), f = l.kind === "notFound" ? be : l.kind === "forbidden" || l.kind === "unauthorized" ? 1008 : 1011;
|
|
2213
2277
|
console.error(`[DetachedRunFrames] run ${e}: following stopped (${l.kind})`, c);
|
|
2214
2278
|
try {
|
|
2215
2279
|
(g = this.onFollowError) == null || g.call(this, l);
|
|
@@ -2233,16 +2297,16 @@ const de = class de {
|
|
|
2233
2297
|
return;
|
|
2234
2298
|
}
|
|
2235
2299
|
if (!t) return;
|
|
2236
|
-
const s =
|
|
2300
|
+
const s = Pe(t);
|
|
2237
2301
|
if (s) {
|
|
2238
2302
|
(r = this.onInteractionStarted) == null || r.call(this, s);
|
|
2239
2303
|
return;
|
|
2240
2304
|
}
|
|
2241
|
-
const n =
|
|
2305
|
+
const n = ie(t);
|
|
2242
2306
|
if (n) {
|
|
2243
|
-
|
|
2307
|
+
Le(n) && n.interactionId && !this.firstTokens.has(n.interactionId) && (this.firstTokens.add(n.interactionId), (o = this.onFirstToken) == null || o.call(this, n.interactionId));
|
|
2244
2308
|
try {
|
|
2245
|
-
const l =
|
|
2309
|
+
const l = U.parseFromTypedEvent(n);
|
|
2246
2310
|
(c = this.onEvent) == null || c.call(this, l).catch((f) => console.error("[DetachedRunFrames] onEvent failed", f));
|
|
2247
2311
|
} catch (l) {
|
|
2248
2312
|
console.error("[DetachedRunFrames] a frame could not be mapped to a server event", l);
|
|
@@ -2262,29 +2326,29 @@ const de = class de {
|
|
|
2262
2326
|
return this.controller !== null;
|
|
2263
2327
|
}
|
|
2264
2328
|
};
|
|
2265
|
-
h(
|
|
2266
|
-
let
|
|
2267
|
-
const
|
|
2268
|
-
function
|
|
2329
|
+
h(ge, "DetachedRunFramesTransport");
|
|
2330
|
+
let De = ge;
|
|
2331
|
+
const kt = "todolistUpdated";
|
|
2332
|
+
function Nt(i, e = ne()) {
|
|
2269
2333
|
var n, r;
|
|
2270
2334
|
let t;
|
|
2271
2335
|
try {
|
|
2272
|
-
const o = e.parse(i), c = o ?
|
|
2273
|
-
t = c ?
|
|
2336
|
+
const o = e.parse(i), c = o ? ie(o) : void 0;
|
|
2337
|
+
t = c ? U.parseFromTypedEvent(c) : void 0;
|
|
2274
2338
|
} catch {
|
|
2275
2339
|
return [];
|
|
2276
2340
|
}
|
|
2277
2341
|
if (!t) return [];
|
|
2278
2342
|
const s = [];
|
|
2279
2343
|
for (const o of t.parts ?? [])
|
|
2280
|
-
if (o.eventType === I.ToolEvent && ((n = o.toolDetails) == null ? void 0 : n.eventName) ===
|
|
2281
|
-
const c =
|
|
2344
|
+
if (o.eventType === I.ToolEvent && ((n = o.toolDetails) == null ? void 0 : n.eventName) === kt) {
|
|
2345
|
+
const c = Ot(o.toolDetails.eventData);
|
|
2282
2346
|
c && s.push({ kind: "todo", todoList: c });
|
|
2283
2347
|
} else (o.eventType === I.FunctionCall || o.eventType === I.PartialFunctionCall) && ((r = o.functionDetails) != null && r.name) ? s.push({ kind: "tool", name: o.functionDetails.name, interactionId: t.interactionId }) : o.eventType === I.Text && o.text && s.push({ kind: "text", text: o.text, partial: !!t.partial, interactionId: t.interactionId });
|
|
2284
2348
|
return s;
|
|
2285
2349
|
}
|
|
2286
|
-
h(
|
|
2287
|
-
function
|
|
2350
|
+
h(Nt, "readDetachedRunActivity");
|
|
2351
|
+
function Ot(i) {
|
|
2288
2352
|
if (!i) return null;
|
|
2289
2353
|
try {
|
|
2290
2354
|
const e = JSON.parse(i);
|
|
@@ -2293,26 +2357,26 @@ function Et(i) {
|
|
|
2293
2357
|
return null;
|
|
2294
2358
|
}
|
|
2295
2359
|
}
|
|
2296
|
-
h(
|
|
2360
|
+
h(Ot, "parseTodoList");
|
|
2297
2361
|
export {
|
|
2298
|
-
|
|
2299
|
-
|
|
2362
|
+
Me as A,
|
|
2363
|
+
ee as C,
|
|
2300
2364
|
P as D,
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2365
|
+
ve as E,
|
|
2366
|
+
Oe as H,
|
|
2367
|
+
N as I,
|
|
2368
|
+
ye as L,
|
|
2369
|
+
Z as M,
|
|
2370
|
+
kt as T,
|
|
2371
|
+
ht as W,
|
|
2372
|
+
De as a,
|
|
2309
2373
|
j as b,
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2374
|
+
ke as c,
|
|
2375
|
+
vt as d,
|
|
2376
|
+
it as e,
|
|
2377
|
+
Nt as r,
|
|
2378
|
+
At as s,
|
|
2379
|
+
yt as t,
|
|
2380
|
+
xt as u
|
|
2317
2381
|
};
|
|
2318
|
-
//# sourceMappingURL=detachedRunActivity-
|
|
2382
|
+
//# sourceMappingURL=detachedRunActivity-B85--SdS.js.map
|