@aintela/chat 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components.js +8370 -8215
- package/dist/components.js.map +1 -1
- package/dist/{detachedRunActivity-RNg1JDDW.js → detachedRunActivity-jHa9SDv1.js} +194 -192
- package/dist/{detachedRunActivity-RNg1JDDW.js.map → detachedRunActivity-jHa9SDv1.js.map} +1 -1
- package/dist/hooks.js +1 -1
- package/dist/{httpSessionService-DLdoBZRW.js → httpSessionService-BIkDesYB.js} +32 -31
- package/dist/{httpSessionService-DLdoBZRW.js.map → httpSessionService-BIkDesYB.js.map} +1 -1
- package/dist/index.js +182 -177
- package/dist/services.js +2 -2
- package/dist/src/components/AiChat/AiChatContext.d.ts +9 -0
- package/dist/src/components/AiChat/AiChatTypes.d.ts +6 -0
- package/dist/src/components/AiChat/ChatPane/ChatTurn.d.ts +33 -0
- package/dist/src/components/AiChat/ChatPane/CurrentMessage.d.ts +6 -4
- package/dist/src/components/AiChat/ChatPane/parts/ReadOnlyGuard.d.ts +9 -0
- package/dist/src/components/AiChat/ChatPane/parts/uiPartStage.d.ts +15 -10
- package/dist/src/components/AiChat/ChatPane/parts/uiToolRegistry.d.ts +6 -0
- package/dist/src/components/AiChat/ChatPane/turnCommitKeepsUiTools.test.d.ts +1 -0
- package/dist/src/components/LlmResponseRender/EnvironmentContext.d.ts +7 -0
- package/dist/src/components/index.d.ts +1 -1
- package/dist/src/components/v2/SharedSessionTranscript.d.ts +76 -0
- package/dist/src/components/v2/index.d.ts +2 -0
- package/dist/src/models/ChatSession.d.ts +6 -0
- package/dist/src/services/detachedRun/DetachedRunFramesTransport.d.ts +11 -0
- package/dist/src/services/detachedRun/streamDetachedRunFrames.d.ts +7 -0
- package/dist/{useChatSessions-DwqgYo79.js → useChatSessions-CyFKVtkk.js} +2 -2
- package/dist/{useChatSessions-DwqgYo79.js.map → useChatSessions-CyFKVtkk.js.map} +1 -1
- package/package.json +1 -1
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var h = (i, t) =>
|
|
4
|
-
var o = (i, t, e) =>
|
|
5
|
-
import { i as N, E as I, S as x, z as
|
|
6
|
-
import { format as
|
|
7
|
-
import
|
|
8
|
-
import { C as E, P as
|
|
9
|
-
import { d as
|
|
10
|
-
import { r as
|
|
1
|
+
var wt = Object.defineProperty;
|
|
2
|
+
var bt = (i, t, e) => t in i ? wt(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
|
|
3
|
+
var h = (i, t) => wt(i, "name", { value: t, configurable: !0 });
|
|
4
|
+
var o = (i, t, e) => bt(i, typeof t != "symbol" ? t + "" : t, e);
|
|
5
|
+
import { i as N, E as I, S as x, z as St, C as U, j as Lt, L as Pt, P as z, n as Ft, q as _t, T as Nt, o as Ut, s as et, B as xt } from "./serializer-DvR3nOcf.js";
|
|
6
|
+
import { format as qt } from "date-fns";
|
|
7
|
+
import Wt from "lodash";
|
|
8
|
+
import { C as E, P as Bt } from "./Prompt-DZb7OaPp.js";
|
|
9
|
+
import { d as Gt } from "./environmentUtils-VZNTCzEE.js";
|
|
10
|
+
import { r as zt } from "./httpSessionService-BIkDesYB.js";
|
|
11
11
|
const Q = {
|
|
12
12
|
PROMPTS: "envision-prompts"
|
|
13
|
-
},
|
|
13
|
+
}, Ht = 50, nt = class nt {
|
|
14
14
|
getPrompts() {
|
|
15
15
|
try {
|
|
16
16
|
const t = localStorage.getItem(Q.PROMPTS);
|
|
@@ -40,7 +40,7 @@ const Q = {
|
|
|
40
40
|
storePrompt(t) {
|
|
41
41
|
try {
|
|
42
42
|
const e = this.getPrompts().filter((s) => s.promptText !== t.promptText);
|
|
43
|
-
e.unshift(t), localStorage.setItem(Q.PROMPTS, JSON.stringify(e.slice(0,
|
|
43
|
+
e.unshift(t), localStorage.setItem(Q.PROMPTS, JSON.stringify(e.slice(0, Ht)));
|
|
44
44
|
} catch (e) {
|
|
45
45
|
console.error("Error storing prompt:", e);
|
|
46
46
|
}
|
|
@@ -54,8 +54,8 @@ const Q = {
|
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
h(nt, "LocalStorageService");
|
|
57
|
-
let
|
|
58
|
-
const
|
|
57
|
+
let It = nt;
|
|
58
|
+
const Re = /* @__PURE__ */ h((i) => {
|
|
59
59
|
const t = i.getPrompts(), e = t.length;
|
|
60
60
|
if (e > 0) {
|
|
61
61
|
const s = t[0].promptText, n = t[t.length - 1].promptText, r = t[0].created;
|
|
@@ -237,8 +237,8 @@ const d = new X(), rt = class rt {
|
|
|
237
237
|
}
|
|
238
238
|
};
|
|
239
239
|
h(rt, "EventBusService");
|
|
240
|
-
let
|
|
241
|
-
const
|
|
240
|
+
let Tt = rt;
|
|
241
|
+
const Jt = 2e3;
|
|
242
242
|
function q(i) {
|
|
243
243
|
i.parts === i.prev.parts && (i.parts = i.prev.parts.slice());
|
|
244
244
|
}
|
|
@@ -247,13 +247,13 @@ function J(i) {
|
|
|
247
247
|
i.functionMap === i.prev.functionMap && (i.functionMap = new Map(i.functionMap));
|
|
248
248
|
}
|
|
249
249
|
h(J, "ownFunctionMap");
|
|
250
|
-
const
|
|
251
|
-
function
|
|
250
|
+
const jt = /* @__PURE__ */ h((i) => i == I.FunctionCall || i == I.PartialFunctionCall, "isFunctionCall"), Kt = /* @__PURE__ */ h((i) => i == I.FunctionResponse, "isFunctionResponse"), Ot = /* @__PURE__ */ h((i) => i.parts.length + 1 + "-" + i.prev.interactionId, "nextPartId");
|
|
251
|
+
function Qt(i, t) {
|
|
252
252
|
var e, s, n, r, a;
|
|
253
|
-
return !!(!t || i.mustPush || i.mustPush === !1 && (i.eventType !== t.eventType || ((e = i.functionDetails) == null ? void 0 : e.id) !== ((s = t.functionDetails) == null ? void 0 : s.id)) || i.textAppendable && (((r = (n = t.thoughtDetails) == null ? void 0 : n.text) == null ? void 0 : r.length) ?? ((a = t.text) == null ? void 0 : a.length) ?? 0) >
|
|
253
|
+
return !!(!t || i.mustPush || i.mustPush === !1 && (i.eventType !== t.eventType || ((e = i.functionDetails) == null ? void 0 : e.id) !== ((s = t.functionDetails) == null ? void 0 : s.id)) || i.textAppendable && (((r = (n = t.thoughtDetails) == null ? void 0 : n.text) == null ? void 0 : r.length) ?? ((a = t.text) == null ? void 0 : a.length) ?? 0) > Jt);
|
|
254
254
|
}
|
|
255
|
-
h(
|
|
256
|
-
function
|
|
255
|
+
h(Qt, "opensNewPart");
|
|
256
|
+
function Yt(i, t) {
|
|
257
257
|
const e = t.functionDetails.id, s = t.functionDetails.clientOutput, n = i.parts.findIndex((r) => {
|
|
258
258
|
var a;
|
|
259
259
|
return ((a = r.functionDetails) == null ? void 0 : a.id) === e;
|
|
@@ -272,14 +272,14 @@ function Qt(i, t) {
|
|
|
272
272
|
} else {
|
|
273
273
|
const r = {
|
|
274
274
|
...t,
|
|
275
|
-
id:
|
|
275
|
+
id: Ot(i),
|
|
276
276
|
functionDetails: { ...t.functionDetails, silent: !0 }
|
|
277
277
|
};
|
|
278
278
|
q(i), i.parts.push(r), J(i), i.functionMap.set(e, r);
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
|
-
h(
|
|
282
|
-
function
|
|
281
|
+
h(Yt, "foldClientOutput");
|
|
282
|
+
function Xt(i, t, e, s, n) {
|
|
283
283
|
var p;
|
|
284
284
|
const r = i.parts.findIndex((m) => {
|
|
285
285
|
var u;
|
|
@@ -314,20 +314,20 @@ function Yt(i, t, e, s, n) {
|
|
|
314
314
|
};
|
|
315
315
|
J(i), i.functionMap.set(s, f), f.eventType === I.FunctionResponse && ((p = n == null ? void 0 : n.onFunctionResponse) == null || p.call(n, f.functionDetails)), r > -1 && (q(i), i.parts[r] = f);
|
|
316
316
|
}
|
|
317
|
-
h(
|
|
318
|
-
function
|
|
317
|
+
h(Xt, "foldFunctionEvent");
|
|
318
|
+
function Vt(i, t, e, s) {
|
|
319
319
|
s && t.functionDetails && (J(i), i.functionMap.set(s, t));
|
|
320
320
|
const n = i.prev.parts[i.prev.parts.length - 1] ?? null;
|
|
321
321
|
n && n.textAppendable && (q(i), i.parts[i.parts.length - 1] = { ...n, ended: /* @__PURE__ */ new Date() });
|
|
322
322
|
const r = {
|
|
323
323
|
...t,
|
|
324
|
-
id:
|
|
324
|
+
id: Ot(i),
|
|
325
325
|
partial: e.partial
|
|
326
326
|
};
|
|
327
327
|
i.parts = [...i.parts, r];
|
|
328
328
|
}
|
|
329
|
-
h(
|
|
330
|
-
function
|
|
329
|
+
h(Vt, "openPart");
|
|
330
|
+
function Zt(i, t, e, s) {
|
|
331
331
|
const n = i.parts[i.parts.length - 1] ?? null;
|
|
332
332
|
if (!n) return;
|
|
333
333
|
const r = {
|
|
@@ -344,8 +344,8 @@ function Vt(i, t, e, s) {
|
|
|
344
344
|
r.text = t.text ?? "", r.textDetails.version++, t.thoughtDetails && (r.thoughtDetails = { ...t.thoughtDetails, text: t.thoughtDetails.text.trim() });
|
|
345
345
|
q(i), i.parts[i.parts.length - 1] = r;
|
|
346
346
|
}
|
|
347
|
-
h(
|
|
348
|
-
function
|
|
347
|
+
h(Zt, "appendText");
|
|
348
|
+
function te(i, t) {
|
|
349
349
|
if (!t || t.length === 0) return i;
|
|
350
350
|
const e = i.slice();
|
|
351
351
|
for (const s of t) {
|
|
@@ -354,8 +354,8 @@ function Zt(i, t) {
|
|
|
354
354
|
}
|
|
355
355
|
return e;
|
|
356
356
|
}
|
|
357
|
-
h(
|
|
358
|
-
function
|
|
357
|
+
h(te, "mergeArtifacts");
|
|
358
|
+
function ee(i, t, e) {
|
|
359
359
|
var c, l;
|
|
360
360
|
const s = N.FlatParts(t == null ? void 0 : t.parts), n = i.parts[i.parts.length - 1] ?? null, r = {
|
|
361
361
|
prev: i,
|
|
@@ -365,20 +365,20 @@ function te(i, t, e) {
|
|
|
365
365
|
let a = !1;
|
|
366
366
|
if (s) {
|
|
367
367
|
if (s.eventType === I.FunctionClientOutput && !!((c = s.functionDetails) != null && c.id))
|
|
368
|
-
|
|
369
|
-
else if (
|
|
370
|
-
const p =
|
|
368
|
+
Yt(r, s);
|
|
369
|
+
else if (Qt(s, n)) {
|
|
370
|
+
const p = jt(s.eventType) || Kt(s.eventType), m = p ? (l = s.functionDetails) == null ? void 0 : l.id : void 0;
|
|
371
371
|
p && !m && console.error("Got isCall or isResponse without a callId", s);
|
|
372
372
|
const u = m ? r.functionMap.get(m) : void 0;
|
|
373
|
-
u && m && s.functionDetails ?
|
|
373
|
+
u && m && s.functionDetails ? Xt(r, s, u, m, e) : (Vt(r, s, t, m), a = !0);
|
|
374
374
|
}
|
|
375
|
-
s.textAppendable &&
|
|
375
|
+
s.textAppendable && Zt(r, s, t, a);
|
|
376
376
|
}
|
|
377
377
|
return {
|
|
378
378
|
...i,
|
|
379
379
|
version: i.version + 1,
|
|
380
380
|
parts: r.parts,
|
|
381
|
-
artifactData:
|
|
381
|
+
artifactData: te(i.artifactData ?? [], t.llmArtifacts),
|
|
382
382
|
functionMap: r.functionMap,
|
|
383
383
|
turn_complete: t.turn_complete,
|
|
384
384
|
partial: t.partial,
|
|
@@ -386,7 +386,7 @@ function te(i, t, e) {
|
|
|
386
386
|
agent: t.agent ?? i.agent
|
|
387
387
|
};
|
|
388
388
|
}
|
|
389
|
-
h(
|
|
389
|
+
h(ee, "reduceInteraction");
|
|
390
390
|
const ot = class ot {
|
|
391
391
|
constructor(t, e) {
|
|
392
392
|
o(this, "interaction");
|
|
@@ -399,7 +399,7 @@ const ot = class ot {
|
|
|
399
399
|
* throttled subscribers cannot diverge from live state.
|
|
400
400
|
*/
|
|
401
401
|
merge(t) {
|
|
402
|
-
const e =
|
|
402
|
+
const e = ee(this.interaction, t, {
|
|
403
403
|
onFunctionResponse: /* @__PURE__ */ h((s) => this.eventBusService.gatewayEmitFunctionResponse(s), "onFunctionResponse")
|
|
404
404
|
});
|
|
405
405
|
return this.interaction = e, e;
|
|
@@ -407,7 +407,7 @@ const ot = class ot {
|
|
|
407
407
|
};
|
|
408
408
|
h(ot, "InteractionService");
|
|
409
409
|
let j = ot;
|
|
410
|
-
const
|
|
410
|
+
const kt = 4001, se = 4002, Dt = 4004, ne = 4100, H = 500, ie = 2e4, re = 1e3, oe = 0.2, _ = 300 * 1e3, ae = 0.75, ce = 2e3, S = "[Connection]", at = class at {
|
|
411
411
|
constructor(t) {
|
|
412
412
|
o(this, "ports");
|
|
413
413
|
o(this, "state");
|
|
@@ -464,7 +464,7 @@ const Ot = 4001, ee = 4002, kt = 4004, se = 4100, H = 500, ne = 2e4, ie = 1e3, r
|
|
|
464
464
|
if (this.inflight) return this.inflight;
|
|
465
465
|
if (this.isUp && this.target.sessionId && !this.halted)
|
|
466
466
|
return Promise.resolve(this.target.sessionId);
|
|
467
|
-
} else this.target && (console.log(`${
|
|
467
|
+
} else this.target && (console.log(`${S} switching from session ${this.target.sessionId ?? "(new)"} to ${t ?? "(new)"}.`), this.close());
|
|
468
468
|
return this.halted = null, this.cancelRetry(), this.target = { sessionId: t, resume: (e == null ? void 0 : e.resume) === !0, prepare: e == null ? void 0 : e.prepare }, this.startIdleTick(), this.dial();
|
|
469
469
|
}
|
|
470
470
|
/**
|
|
@@ -476,7 +476,7 @@ const Ot = 4001, ee = 4002, kt = 4004, se = 4100, H = 500, ne = 2e4, ie = 1e3, r
|
|
|
476
476
|
var e;
|
|
477
477
|
if (this.halted)
|
|
478
478
|
throw new Error(`The connection was halted (${this.halted}); session ${((e = this.target) == null ? void 0 : e.sessionId) ?? t ?? "none"} cannot be redialled.`);
|
|
479
|
-
return this.target ? this.inflight ? this.inflight : this.isUp && this.target.sessionId ? this.target.sessionId : (console.warn(`${
|
|
479
|
+
return this.target ? this.inflight ? this.inflight : this.isUp && this.target.sessionId ? this.target.sessionId : (console.warn(`${S} 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(`${S} send guard: nothing supervised yet — opening session ${t ?? "(new)"} with the replay cursor.`), this.open(t, { resume: !0 }));
|
|
480
480
|
}
|
|
481
481
|
/** Stop supervising: hang up, cancel any retry, stop the idle tick. Never throws. */
|
|
482
482
|
close() {
|
|
@@ -485,7 +485,7 @@ const Ot = 4001, ee = 4002, kt = 4004, se = 4100, H = 500, ne = 2e4, ie = 1e3, r
|
|
|
485
485
|
try {
|
|
486
486
|
this.ports.hangUp();
|
|
487
487
|
} catch (e) {
|
|
488
|
-
console.error(`${
|
|
488
|
+
console.error(`${S} hangUp threw`, e);
|
|
489
489
|
}
|
|
490
490
|
t && this.state.setConnectionStatus(E.Disconnected);
|
|
491
491
|
}
|
|
@@ -501,12 +501,12 @@ const Ot = 4001, ee = 4002, kt = 4004, se = 4100, H = 500, ne = 2e4, ie = 1e3, r
|
|
|
501
501
|
* A close that lands while a dial is in flight is remembered and judged when that dial fails.
|
|
502
502
|
*/
|
|
503
503
|
transportClosed(t, e) {
|
|
504
|
-
if (t !==
|
|
504
|
+
if (t !== kt && (this.lastCloseCode = t, !!this.target)) {
|
|
505
505
|
if (this.inflight) {
|
|
506
|
-
console.log(`${
|
|
506
|
+
console.log(`${S} socket closed (code=${t}) while a dial is in flight — judged when it settles.`);
|
|
507
507
|
return;
|
|
508
508
|
}
|
|
509
|
-
this.state.connectionStatus === E.Connected && (console.warn(`${
|
|
509
|
+
this.state.connectionStatus === E.Connected && (console.warn(`${S} socket closed: code=${t} reason="${e}" (session ${this.target.sessionId ?? "(new)"}).`), this.state.setConnectionStatus(E.Disconnected), this.judge(t));
|
|
510
510
|
}
|
|
511
511
|
}
|
|
512
512
|
// ─── The dial ───────────────────────────────────────────────────────────
|
|
@@ -514,11 +514,11 @@ const Ot = 4001, ee = 4002, kt = 4004, se = 4100, H = 500, ne = 2e4, ie = 1e3, r
|
|
|
514
514
|
const t = this.target;
|
|
515
515
|
this.lastCloseCode = null, this.state.setConnectionStatus(E.Connecting);
|
|
516
516
|
const e = this.now();
|
|
517
|
-
console.log(`${
|
|
517
|
+
console.log(`${S} dialling session ${t.sessionId ?? "(new)"}${t.resume ? " with the replay cursor" : ""}${this.everConnected ? " (reconnect)" : ""}.`);
|
|
518
518
|
const n = (async () => (t.prepare && await t.prepare(), this.ports.dial(t.sessionId, { resume: t.resume })))().then((r) => {
|
|
519
519
|
var c, l;
|
|
520
520
|
if (this.target !== t) {
|
|
521
|
-
console.log(`${
|
|
521
|
+
console.log(`${S} a dial for ${t.sessionId ?? "(new)"} resolved after it was abandoned — hanging up.`);
|
|
522
522
|
try {
|
|
523
523
|
this.ports.hangUp();
|
|
524
524
|
} catch {
|
|
@@ -526,7 +526,7 @@ const Ot = 4001, ee = 4002, kt = 4004, se = 4100, H = 500, ne = 2e4, ie = 1e3, r
|
|
|
526
526
|
throw new Error("Connection attempt abandoned");
|
|
527
527
|
}
|
|
528
528
|
if (t.sessionId && r !== t.sessionId) {
|
|
529
|
-
console.error(`${
|
|
529
|
+
console.error(`${S} asked for session ${t.sessionId}, the server answered with ${r} — refusing the swap and halting.`);
|
|
530
530
|
try {
|
|
531
531
|
this.ports.hangUp();
|
|
532
532
|
} catch {
|
|
@@ -534,11 +534,11 @@ const Ot = 4001, ee = 4002, kt = 4004, se = 4100, H = 500, ne = 2e4, ie = 1e3, r
|
|
|
534
534
|
throw this.state.setConnectionStatus(E.Disconnected), this.halt("session-gone", { sessionId: t.sessionId, actualSessionId: r }), new Error(`Session ${t.sessionId} no longer exists on the server (it answered with ${r}).`);
|
|
535
535
|
}
|
|
536
536
|
const a = this.everConnected;
|
|
537
|
-
return this.everConnected = !0, t.sessionId = r, t.resume = !0, t.prepare = void 0, this.wait = H, this.attempt = 0, this.state.setConnectionStatus(E.Connected), console.log(`${
|
|
537
|
+
return this.everConnected = !0, t.sessionId = r, t.resume = !0, t.prepare = void 0, this.wait = H, this.attempt = 0, this.state.setConnectionStatus(E.Connected), console.log(`${S} ${a ? "reconnected to" : "connected to"} session ${r} in ${this.now() - e}ms.`), (l = (c = this.ports).onConnected) == null || l.call(c, r, { reconnect: a }), r;
|
|
538
538
|
}).catch((r) => {
|
|
539
539
|
if (this.target === t && !this.halted) {
|
|
540
540
|
const a = this.lastCloseCode;
|
|
541
|
-
console.error(`${
|
|
541
|
+
console.error(`${S} dial of session ${t.sessionId ?? "(new)"} failed after ${this.now() - e}ms${a !== null ? ` (socket closed with ${a})` : ""}:`, r), this.state.setConnectionStatus(E.Disconnected), this.inflight === n && (this.inflight = null), this.judge(a);
|
|
542
542
|
}
|
|
543
543
|
throw r;
|
|
544
544
|
}).finally(() => {
|
|
@@ -550,33 +550,33 @@ const Ot = 4001, ee = 4002, kt = 4004, se = 4100, H = 500, ne = 2e4, ie = 1e3, r
|
|
|
550
550
|
judge(t) {
|
|
551
551
|
var s;
|
|
552
552
|
const e = (s = this.target) == null ? void 0 : s.sessionId;
|
|
553
|
-
if (t ===
|
|
554
|
-
if (t ===
|
|
553
|
+
if (t === se) return this.halt("attached-elsewhere", { sessionId: e, code: t });
|
|
554
|
+
if (t === Dt) return this.halt("session-gone", { sessionId: e, code: t });
|
|
555
555
|
if (t === 1e3 || t === 1008) return this.halt("closed-by-server", { sessionId: e, code: t });
|
|
556
556
|
this.scheduleRetry();
|
|
557
557
|
}
|
|
558
558
|
halt(t, e) {
|
|
559
559
|
var s, n;
|
|
560
|
-
this.halted = t, this.cancelRetry(), console.warn(`${
|
|
560
|
+
this.halted = t, this.cancelRetry(), console.warn(`${S} halted (${t}) on session ${e.sessionId ?? "(new)"}${e.code !== void 0 ? `, close code ${e.code}` : ""} — no automatic redial; an explicit open() may try again.`);
|
|
561
561
|
try {
|
|
562
562
|
(n = (s = this.ports).onHalt) == null || n.call(s, t, e);
|
|
563
563
|
} catch (r) {
|
|
564
|
-
console.error(`${
|
|
564
|
+
console.error(`${S} onHalt threw`, r);
|
|
565
565
|
}
|
|
566
566
|
}
|
|
567
567
|
scheduleRetry() {
|
|
568
568
|
var e, s;
|
|
569
569
|
if (!this.target || this.retryTimer || this.inflight) return;
|
|
570
570
|
if (!this.state.sessionActive) {
|
|
571
|
-
console.log(`${
|
|
571
|
+
console.log(`${S} session idle — not redialling until activity resumes.`);
|
|
572
572
|
return;
|
|
573
573
|
}
|
|
574
574
|
const t = this.jittered(this.wait);
|
|
575
|
-
this.wait = Math.min(Math.floor(this.wait + this.wait * this.wait /
|
|
575
|
+
this.wait = Math.min(Math.floor(this.wait + this.wait * this.wait / re), ie), this.attempt += 1, console.warn(`${S} redialling session ${this.target.sessionId ?? "(new)"} in ${t}ms (then ${this.wait}ms, attempt ${this.attempt}).`);
|
|
576
576
|
try {
|
|
577
577
|
(s = (e = this.ports).onRetryScheduled) == null || s.call(e, { sessionId: this.target.sessionId, delayMs: t, attempt: this.attempt });
|
|
578
578
|
} catch (n) {
|
|
579
|
-
console.error(`${
|
|
579
|
+
console.error(`${S} onRetryScheduled threw`, n);
|
|
580
580
|
}
|
|
581
581
|
this.retryTimer = setTimeout(() => {
|
|
582
582
|
this.retryTimer = null, !(!this.target || this.halted) && (this.target.resume = !0, this.dial().catch(() => {
|
|
@@ -587,7 +587,7 @@ const Ot = 4001, ee = 4002, kt = 4004, se = 4100, H = 500, ne = 2e4, ie = 1e3, r
|
|
|
587
587
|
this.retryTimer && (clearTimeout(this.retryTimer), this.retryTimer = null);
|
|
588
588
|
}
|
|
589
589
|
jittered(t) {
|
|
590
|
-
return Math.max(0, Math.round(t + t *
|
|
590
|
+
return Math.max(0, Math.round(t + t * oe * (Math.random() * 2 - 1)));
|
|
591
591
|
}
|
|
592
592
|
sameTarget(t) {
|
|
593
593
|
var e;
|
|
@@ -595,7 +595,7 @@ const Ot = 4001, ee = 4002, kt = 4004, se = 4100, H = 500, ne = 2e4, ie = 1e3, r
|
|
|
595
595
|
}
|
|
596
596
|
// ─── Idle ───────────────────────────────────────────────────────────────
|
|
597
597
|
startIdleTick() {
|
|
598
|
-
this.idleTimer || (this.idleTimer = setInterval(() => this.tick(),
|
|
598
|
+
this.idleTimer || (this.idleTimer = setInterval(() => this.tick(), ce));
|
|
599
599
|
}
|
|
600
600
|
stopIdleTick() {
|
|
601
601
|
this.idleTimer && (clearInterval(this.idleTimer), this.idleTimer = null);
|
|
@@ -614,18 +614,18 @@ const Ot = 4001, ee = 4002, kt = 4004, se = 4100, H = 500, ne = 2e4, ie = 1e3, r
|
|
|
614
614
|
const t = this.now() - this.state.lastActivity;
|
|
615
615
|
if (t > _) {
|
|
616
616
|
if (this.state.sessionActive && this.state.setIsSessionActive(!1), this.cancelRetry(), this.state.connectionStatus === E.Connected) {
|
|
617
|
-
console.warn(`${
|
|
617
|
+
console.warn(`${S} idle for ${Math.round(t / 1e3)}s (limit ${_ / 1e3}s) — closing the socket (session ${this.target.sessionId ?? "(new)"}). Activity, or a send, redials it.`);
|
|
618
618
|
try {
|
|
619
619
|
this.ports.hangUp();
|
|
620
620
|
} catch (e) {
|
|
621
|
-
console.error(`${
|
|
621
|
+
console.error(`${S} hangUp threw`, e);
|
|
622
622
|
}
|
|
623
623
|
this.state.setConnectionStatus(E.Disconnected);
|
|
624
624
|
}
|
|
625
625
|
return;
|
|
626
626
|
}
|
|
627
|
-
this.state.sessionActive || (console.log(`${
|
|
628
|
-
}))), t > _ *
|
|
627
|
+
this.state.sessionActive || (console.log(`${S} 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(() => {
|
|
628
|
+
}))), t > _ * ae ? this.idleWarningLogged || (this.idleWarningLogged = !0, console.warn(`${S} idle ${Math.round(t / 1e3)}s of ${_ / 1e3}s — the socket closes in about ${Math.round((_ - t) / 1e3)}s unless something happens.`)) : this.idleWarningLogged = !1;
|
|
629
629
|
}
|
|
630
630
|
};
|
|
631
631
|
h(at, "ConnectionSupervisor");
|
|
@@ -737,13 +737,13 @@ const y = class y {
|
|
|
737
737
|
this.sessionId = u, this.sessionState.setConnectionOutage(null), this.eventBusService.gatewayEmitConnected(u, g), this.flushAnnouncements();
|
|
738
738
|
}, "onConnected"),
|
|
739
739
|
onRetryScheduled: /* @__PURE__ */ h(({ delayMs: u, attempt: g }) => {
|
|
740
|
-
var
|
|
741
|
-
const
|
|
742
|
-
this.sessionState.setConnectionOutage({ since:
|
|
740
|
+
var D;
|
|
741
|
+
const w = Date.now(), M = ((D = this.sessionState.connectionOutage) == null ? void 0 : D.since) ?? w;
|
|
742
|
+
this.sessionState.setConnectionOutage({ since: M, retryAt: w + u, attempt: g, halted: null }), w - M >= y.OUTAGE_CLOSES_TURN_AFTER_MS && this.closeOpenTurnWith(y.OUTAGE_TURN_MESSAGE);
|
|
743
743
|
}, "onRetryScheduled"),
|
|
744
744
|
onHalt: /* @__PURE__ */ h((u, g) => {
|
|
745
|
-
const
|
|
746
|
-
this.sessionState.setConnectionOutage({ since: (
|
|
745
|
+
const w = this.sessionState.connectionOutage;
|
|
746
|
+
this.sessionState.setConnectionOutage({ since: (w == null ? void 0 : w.since) ?? Date.now(), retryAt: null, attempt: (w == null ? void 0 : w.attempt) ?? 0, halted: u }), this.notifyHalt(u, g), this.closeOpenTurnWith(y.HALT_TURN_MESSAGE[u]);
|
|
747
747
|
}, "onHalt")
|
|
748
748
|
}), this.wsService.onEvent = async (u) => {
|
|
749
749
|
await this.Message(u);
|
|
@@ -907,10 +907,10 @@ const y = class y {
|
|
|
907
907
|
const s = this.interactionsServiceMap.get(e);
|
|
908
908
|
if (s) {
|
|
909
909
|
const n = s.interaction;
|
|
910
|
-
n.interactionQuestion || (n.interactionQuestion = t.content ?? ""), n.origin ?? (n.origin =
|
|
910
|
+
n.interactionQuestion || (n.interactionQuestion = t.content ?? ""), n.origin ?? (n.origin = St(t.origin));
|
|
911
911
|
return;
|
|
912
912
|
}
|
|
913
|
-
this.openRemoteInteraction(e, t.content ?? "",
|
|
913
|
+
this.openRemoteInteraction(e, t.content ?? "", St(t.origin), !0);
|
|
914
914
|
}
|
|
915
915
|
getInteractions() {
|
|
916
916
|
return Array.from(this.interactionsMap.values());
|
|
@@ -927,7 +927,7 @@ const y = class y {
|
|
|
927
927
|
return e || (e = this.openRemoteInteraction(t.interactionId, "", void 0, !1)), e.merge(t);
|
|
928
928
|
}
|
|
929
929
|
getNewInteractionId() {
|
|
930
|
-
const e =
|
|
930
|
+
const e = qt(/* @__PURE__ */ new Date(), "MMM_dd_HH_mm_ss");
|
|
931
931
|
return `${this.msg_order}_${e}`;
|
|
932
932
|
}
|
|
933
933
|
// ─── Inbound: server events ─────────────────────────────────────────────
|
|
@@ -1112,7 +1112,7 @@ const y = class y {
|
|
|
1112
1112
|
try {
|
|
1113
1113
|
const { promptAsString: r, json: a } = this.sessionState.onRenderPrompt ? this.sessionState.onRenderPrompt(t.data) : { promptAsString: t.data, json: void 0 };
|
|
1114
1114
|
this.sessionState.onRenderPrompt && (t.data = a, t.friendlyMessage = r);
|
|
1115
|
-
const c = await this.sendMessageInternal(t, e), l =
|
|
1115
|
+
const c = await this.sendMessageInternal(t, e), l = Bt.createPrompt(r ?? "", (a == null ? void 0 : a.toString()) ?? {});
|
|
1116
1116
|
this.storageService.storePrompt(l);
|
|
1117
1117
|
const f = N.fromText("Planejando próximos passos");
|
|
1118
1118
|
return this.sendStatusMessage(t.data, [n, f], s.toString() + "1"), c != null && c.success ? this.eventBusService.ChatEmitMessageSent(t.data, c.interaction) : this.eventBusService.ChatEmitMessageError((c == null ? void 0 : c.error) ?? ""), c;
|
|
@@ -1174,7 +1174,7 @@ const y = class y {
|
|
|
1174
1174
|
sendStatusMessage(t, e, s) {
|
|
1175
1175
|
var r, a;
|
|
1176
1176
|
let n;
|
|
1177
|
-
((a = (r = this.currentIS) == null ? void 0 : r.interaction) == null ? void 0 : a.turn_complete) === !1 && !this.currentIS.interaction.remote ? (n =
|
|
1177
|
+
((a = (r = this.currentIS) == null ? void 0 : r.interaction) == null ? void 0 : a.turn_complete) === !1 && !this.currentIS.interaction.remote ? (n = Wt.cloneDeep(this.currentIS.interaction), n.parts.push(...e)) : n = {
|
|
1178
1178
|
interactionId: "tmp" + s,
|
|
1179
1179
|
created: /* @__PURE__ */ new Date(),
|
|
1180
1180
|
partial: !0,
|
|
@@ -1291,59 +1291,59 @@ o(y, "NO_CONNECTION_MESSAGE", "Não foi possível obter conexão com o servidor"
|
|
|
1291
1291
|
"session-gone": "A sessão não existe mais no servidor. A resposta foi interrompida.",
|
|
1292
1292
|
"closed-by-server": "O servidor encerrou a conexão. A resposta foi interrompida."
|
|
1293
1293
|
});
|
|
1294
|
-
let
|
|
1295
|
-
function
|
|
1296
|
-
const t = new
|
|
1294
|
+
let yt = y;
|
|
1295
|
+
function le(i) {
|
|
1296
|
+
const t = new Pt();
|
|
1297
1297
|
t.author = "main", t.streamingParts = i.streamingParts, i.partialEventType ? t.eventType = i.partialEventType : t.eventType = i.functionName ? { fullName: z.StreamingFunctionCallUpdateContent, type: I.PartialFunctionCall } : i.partialReasoning ? { fullName: z.StreamingReasoningContent, type: I.Thought } : { fullName: z.StreamingTextContent, type: I.Text }, t.interactionId = i.iteractionId ?? "", t.mimeType = "text/plain", t.partial = !0, t.role = { label: "Assistant" }, t.timestamp = i.timeStamp ?? (/* @__PURE__ */ new Date()).getTime(), t.turnComplete = !1;
|
|
1298
1298
|
const e = t.eventType.type;
|
|
1299
1299
|
if (e == I.PartialFunctionCall) {
|
|
1300
|
-
const s = new
|
|
1300
|
+
const s = new Ft();
|
|
1301
1301
|
s.choiceIndex = 0, s.callId = i.functionCallId, s.arguments = i.partialText, s.name = i.functionName, t.content = { items: [s], role: { label: "Assistant" } };
|
|
1302
1302
|
} else if (e == I.Text)
|
|
1303
1303
|
if (t.eventType.fullName == z.StreamingTextContent) {
|
|
1304
|
-
const s = new
|
|
1304
|
+
const s = new _t();
|
|
1305
1305
|
s.text = i.partialText, t.content = { items: [s], role: { label: "Assistant" } };
|
|
1306
1306
|
} else {
|
|
1307
|
-
const s = new
|
|
1307
|
+
const s = new Nt();
|
|
1308
1308
|
s.text = i.partialText, t.content = { items: [s], role: { label: "Assistant" } };
|
|
1309
1309
|
}
|
|
1310
1310
|
else if (e == I.Thought) {
|
|
1311
|
-
const s = new
|
|
1311
|
+
const s = new Ut();
|
|
1312
1312
|
s.text = i.partialReasoning, t.content = { items: [s], role: { label: "Assistant" } };
|
|
1313
1313
|
}
|
|
1314
1314
|
return t;
|
|
1315
1315
|
}
|
|
1316
|
-
h(
|
|
1316
|
+
h(le, "llmEventFromPartial");
|
|
1317
1317
|
function st(i) {
|
|
1318
|
-
const t = i.partialEvent ?
|
|
1318
|
+
const t = i.partialEvent ? le(i.partialEvent) : i.event;
|
|
1319
1319
|
if (t)
|
|
1320
1320
|
return i.detachedRunId && (t.detachedRunId = i.detachedRunId, t.detachedRunName = i.detachedRunName), t;
|
|
1321
1321
|
}
|
|
1322
1322
|
h(st, "llmEventFromFrame");
|
|
1323
|
-
function
|
|
1323
|
+
function $t(i) {
|
|
1324
1324
|
var t, e, s;
|
|
1325
1325
|
return (((e = (t = i.content) == null ? void 0 : t.items) == null ? void 0 : e.length) ?? 0) > 0 || (((s = i.streamingParts) == null ? void 0 : s.length) ?? 0) > 0;
|
|
1326
1326
|
}
|
|
1327
|
-
h(
|
|
1328
|
-
function
|
|
1327
|
+
h($t, "carriesContent");
|
|
1328
|
+
function Rt(i) {
|
|
1329
1329
|
var e;
|
|
1330
1330
|
if (i.type !== "InteractionStarted" || !((e = i.interaction) != null && e.interactionId)) return;
|
|
1331
1331
|
if (i.interaction.detachedRunId || !i.detachedRunId) return i.interaction;
|
|
1332
|
-
const t = Object.assign(new
|
|
1332
|
+
const t = Object.assign(new Lt(), i.interaction);
|
|
1333
1333
|
return t.detachedRunId = i.detachedRunId, t;
|
|
1334
1334
|
}
|
|
1335
|
-
h(
|
|
1336
|
-
const
|
|
1337
|
-
function
|
|
1335
|
+
h(Rt, "interactionStartFromFrame");
|
|
1336
|
+
const he = 0.02;
|
|
1337
|
+
function ue(i, t) {
|
|
1338
1338
|
if (!t) return null;
|
|
1339
1339
|
const e = (t.interactionsCompressed ?? 0) > 0 || (t.compressionRatio ?? 0) > 0;
|
|
1340
1340
|
if (!i)
|
|
1341
|
-
return e ?
|
|
1342
|
-
const s = i.size - t.size, n = t.maxSize || i.maxSize || 0, r = n > 0 ? s / n >=
|
|
1343
|
-
return !e && !r ? null :
|
|
1341
|
+
return e ? vt(t, t.size, t.size) : null;
|
|
1342
|
+
const s = i.size - t.size, n = t.maxSize || i.maxSize || 0, r = n > 0 ? s / n >= he : i.size > 0 && s / i.size >= 0.1;
|
|
1343
|
+
return !e && !r ? null : vt(t, i.size, t.size, i.ratio);
|
|
1344
1344
|
}
|
|
1345
|
-
h(
|
|
1346
|
-
function
|
|
1345
|
+
h(ue, "detectCompaction");
|
|
1346
|
+
function vt(i, t, e, s) {
|
|
1347
1347
|
return {
|
|
1348
1348
|
at: Date.now(),
|
|
1349
1349
|
// Where the bar stood when it happened — the marker's position. The ratio
|
|
@@ -1355,8 +1355,8 @@ function yt(i, t, e, s) {
|
|
|
1355
1355
|
interactionsCompressed: i.interactionsCompressed
|
|
1356
1356
|
};
|
|
1357
1357
|
}
|
|
1358
|
-
h(
|
|
1359
|
-
const
|
|
1358
|
+
h(vt, "entry");
|
|
1359
|
+
const Et = 4, de = 3, fe = 20, P = class P {
|
|
1360
1360
|
constructor() {
|
|
1361
1361
|
o(this, "stats");
|
|
1362
1362
|
o(this, "onFlush");
|
|
@@ -1392,14 +1392,14 @@ const vt = 4, ue = 3, de = 20, P = class P {
|
|
|
1392
1392
|
record(t) {
|
|
1393
1393
|
const e = Date.now();
|
|
1394
1394
|
if (this.events.push([e, t.textLength]), this.stats.eventCount += 1, this.stats.totalTransfered += t.rawLength, t.sessionInformation && !t.fromDetachedRun) {
|
|
1395
|
-
const r =
|
|
1396
|
-
r && (this.sessionCompactions.push(r), this.sessionCompactions.length >
|
|
1395
|
+
const r = ue(this.previousSessionInformation, t.sessionInformation);
|
|
1396
|
+
r && (this.sessionCompactions.push(r), this.sessionCompactions.length > fe && this.sessionCompactions.shift()), this.previousSessionInformation = t.sessionInformation, this.stats.sessionInformation = t.sessionInformation, this.stats.sessionCompactions = this.sessionCompactions;
|
|
1397
1397
|
}
|
|
1398
1398
|
this.stats.elapsed = (e - this.stats.startTime.getTime()) / 1e3;
|
|
1399
|
-
const s = e -
|
|
1399
|
+
const s = e - Et * 1e3;
|
|
1400
1400
|
for (; this.events.length > 0 && this.events[0][0] <= s; ) this.events.shift();
|
|
1401
1401
|
const n = this.events.reduce((r, a) => r + a[1], 0);
|
|
1402
|
-
this.stats.tokensPerSecond = n /
|
|
1402
|
+
this.stats.tokensPerSecond = n / de / Et, this.flushCoalesced();
|
|
1403
1403
|
}
|
|
1404
1404
|
flushCoalesced() {
|
|
1405
1405
|
if (!this.onFlush) return;
|
|
@@ -1416,7 +1416,7 @@ const vt = 4, ue = 3, de = 20, P = class P {
|
|
|
1416
1416
|
};
|
|
1417
1417
|
h(P, "StreamStatsTracker"), o(P, "STATS_FLUSH_MS", 120);
|
|
1418
1418
|
let tt = P;
|
|
1419
|
-
const
|
|
1419
|
+
const ge = 5e3, pe = 3e4, Y = 1e4, lt = class lt {
|
|
1420
1420
|
constructor(t = "ws://localhost:8000", e) {
|
|
1421
1421
|
o(this, "ws", null);
|
|
1422
1422
|
/** Frame counts, byte totals, the token-rate estimate and the compaction history — see StreamStatsTracker. */
|
|
@@ -1468,7 +1468,7 @@ const fe = 5e3, ge = 3e4, Y = 1e4, lt = class lt {
|
|
|
1468
1468
|
* the single-attach policy makes it undeliverable from here anyway.
|
|
1469
1469
|
*/
|
|
1470
1470
|
o(this, "pendingAnswers", []);
|
|
1471
|
-
this.baseUrl = t, this.getToken = e, this.firstTokenInteractions = /* @__PURE__ */ new Set(), this.streamingResponseSerializer = et(), console.log("SOCKET INSTACE",
|
|
1471
|
+
this.baseUrl = t, this.getToken = e, this.firstTokenInteractions = /* @__PURE__ */ new Set(), this.streamingResponseSerializer = et(), console.log("SOCKET INSTACE", Gt()), this.lastActivity = (/* @__PURE__ */ new Date()).getTime();
|
|
1472
1472
|
}
|
|
1473
1473
|
get stats() {
|
|
1474
1474
|
return this.statsTracker.stats;
|
|
@@ -1491,9 +1491,9 @@ const fe = 5e3, ge = 3e4, Y = 1e4, lt = class lt {
|
|
|
1491
1491
|
*/
|
|
1492
1492
|
connect(t, e) {
|
|
1493
1493
|
return new Promise(async (s, n) => {
|
|
1494
|
-
var
|
|
1494
|
+
var D, F;
|
|
1495
1495
|
e != null && e.resume || (this.lastSeq = -1);
|
|
1496
|
-
const r = (
|
|
1496
|
+
const r = (D = this.getToken) == null ? void 0 : D.call(this), a = [];
|
|
1497
1497
|
r && a.push(`access_token=${encodeURIComponent(r)}`), t && this.lastSeq >= 0 && a.push(`lastSeq=${this.lastSeq}`), t && (e != null && e.resume) && e.openInteractionId && a.push(`openInteraction=${encodeURIComponent(e.openInteractionId)}`);
|
|
1498
1498
|
const c = a.length > 0 ? `?${a.join("&")}` : "", l = this.baseUrl.replace(/^http:\/\//, "ws://").replace(/^https:\/\//, "wss://"), f = `${l}/ws/connect/${t ?? ""}${c}`;
|
|
1499
1499
|
console.log("[WebSocket] Connecting to", `${l}/ws/connect/${t ?? ""}` + (t && this.lastSeq >= 0 ? ` (resume lastSeq=${this.lastSeq})` : "")), this.detachSocket(), this.ws = new WebSocket(f), this.ws.onopen = () => {
|
|
@@ -1516,7 +1516,7 @@ const fe = 5e3, ge = 3e4, Y = 1e4, lt = class lt {
|
|
|
1516
1516
|
};
|
|
1517
1517
|
const p = 200, m = 3e4, u = 8e3, g = this.ws;
|
|
1518
1518
|
this.sessionId = void 0;
|
|
1519
|
-
let
|
|
1519
|
+
let w = 0, M = 0;
|
|
1520
1520
|
for (; ; ) {
|
|
1521
1521
|
if (this.ws !== g) {
|
|
1522
1522
|
n("Connection attempt superseded by a newer connect()");
|
|
@@ -1527,7 +1527,7 @@ const fe = 5e3, ge = 3e4, Y = 1e4, lt = class lt {
|
|
|
1527
1527
|
n("Connection closed before a session id was received");
|
|
1528
1528
|
return;
|
|
1529
1529
|
}
|
|
1530
|
-
if (g.readyState === WebSocket.CONNECTING &&
|
|
1530
|
+
if (g.readyState === WebSocket.CONNECTING && w >= m) {
|
|
1531
1531
|
try {
|
|
1532
1532
|
g.close();
|
|
1533
1533
|
} catch {
|
|
@@ -1535,11 +1535,11 @@ const fe = 5e3, ge = 3e4, Y = 1e4, lt = class lt {
|
|
|
1535
1535
|
n(`Server did not accept the connection within ${m / 1e3}s`);
|
|
1536
1536
|
return;
|
|
1537
1537
|
}
|
|
1538
|
-
if (g.readyState === WebSocket.OPEN &&
|
|
1538
|
+
if (g.readyState === WebSocket.OPEN && M >= u) {
|
|
1539
1539
|
n(`Connected but no session id arrived within ${u / 1e3}s`);
|
|
1540
1540
|
return;
|
|
1541
1541
|
}
|
|
1542
|
-
|
|
1542
|
+
w % 2e3 === 0 && console.log("Aguardando session Id"), await this.sleep(p), w += p, g.readyState === WebSocket.OPEN && (M += p);
|
|
1543
1543
|
}
|
|
1544
1544
|
console.log(`[WebSocket] Session ${this.sessionId} proven${this.lastSeq >= 0 ? ` (replaying from lastSeq=${this.lastSeq})` : ""}.`), this.lastKnownSessionId = this.sessionId, (F = this.onOpen) == null || F.call(this), this.flushPendingAnswers(this.sessionId), s(this.sessionId);
|
|
1545
1545
|
});
|
|
@@ -1581,7 +1581,7 @@ const fe = 5e3, ge = 3e4, Y = 1e4, lt = class lt {
|
|
|
1581
1581
|
case "Event":
|
|
1582
1582
|
break;
|
|
1583
1583
|
case "InteractionStarted": {
|
|
1584
|
-
const r =
|
|
1584
|
+
const r = Rt(t);
|
|
1585
1585
|
r ? (n = this.onInteractionStarted) == null || n.call(this, r) : console.warn("[WebSocket] InteractionStarted frame without an interaction id");
|
|
1586
1586
|
break;
|
|
1587
1587
|
}
|
|
@@ -1594,7 +1594,7 @@ const fe = 5e3, ge = 3e4, Y = 1e4, lt = class lt {
|
|
|
1594
1594
|
console.warn("[WebSocket] Unknown message type:", t.type);
|
|
1595
1595
|
}
|
|
1596
1596
|
const s = st(t);
|
|
1597
|
-
return s ? (
|
|
1597
|
+
return s ? ($t(s) && this.emitFirstToken(s.interactionId), this.handleEvent(s, e), s) : null;
|
|
1598
1598
|
}
|
|
1599
1599
|
emitFirstToken(t) {
|
|
1600
1600
|
var e;
|
|
@@ -1715,7 +1715,7 @@ const fe = 5e3, ge = 3e4, Y = 1e4, lt = class lt {
|
|
|
1715
1715
|
const e = t - this.pingSentAt;
|
|
1716
1716
|
if (e >= Y) {
|
|
1717
1717
|
this.failSocket(
|
|
1718
|
-
|
|
1718
|
+
ne,
|
|
1719
1719
|
`No frame received for ${Math.round(e / 1e3)}s after a Ping`
|
|
1720
1720
|
);
|
|
1721
1721
|
return;
|
|
@@ -1723,11 +1723,11 @@ const fe = 5e3, ge = 3e4, Y = 1e4, lt = class lt {
|
|
|
1723
1723
|
console.warn(`[WebSocket] Still no reply ${e}ms after the Ping (budget ${Y}ms, session ${this.sessionLabel}) — the peer may be gone.`);
|
|
1724
1724
|
return;
|
|
1725
1725
|
}
|
|
1726
|
-
t - this.lastActivity >=
|
|
1726
|
+
t - this.lastActivity >= pe && this.ping();
|
|
1727
1727
|
} catch (t) {
|
|
1728
1728
|
console.error("Error on monitor", t);
|
|
1729
1729
|
}
|
|
1730
|
-
},
|
|
1730
|
+
}, ge);
|
|
1731
1731
|
}
|
|
1732
1732
|
/**
|
|
1733
1733
|
* Send a heartbeat ping and start the reply clock (unless one is already running).
|
|
@@ -1773,7 +1773,7 @@ const fe = 5e3, ge = 3e4, Y = 1e4, lt = class lt {
|
|
|
1773
1773
|
* Disconnect the WebSocket
|
|
1774
1774
|
*/
|
|
1775
1775
|
disconnect() {
|
|
1776
|
-
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(
|
|
1776
|
+
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(kt, "Intentional disconnect"), this.ws = null);
|
|
1777
1777
|
}
|
|
1778
1778
|
/**
|
|
1779
1779
|
* Check if connected
|
|
@@ -1783,7 +1783,7 @@ const fe = 5e3, ge = 3e4, Y = 1e4, lt = class lt {
|
|
|
1783
1783
|
}
|
|
1784
1784
|
async handleEvent(t, e) {
|
|
1785
1785
|
var n, r, a, c;
|
|
1786
|
-
const s = (r = (n = t.content) == null ? void 0 : n.items) == null ? void 0 : r.find((l) => l instanceof
|
|
1786
|
+
const s = (r = (n = t.content) == null ? void 0 : n.items) == null ? void 0 : r.find((l) => l instanceof xt);
|
|
1787
1787
|
if (s) {
|
|
1788
1788
|
(a = this.onBillingLimit) == null || a.call(this, {
|
|
1789
1789
|
plan: s.plan ?? "team",
|
|
@@ -1817,7 +1817,7 @@ const fe = 5e3, ge = 3e4, Y = 1e4, lt = class lt {
|
|
|
1817
1817
|
}
|
|
1818
1818
|
};
|
|
1819
1819
|
h(lt, "WebSocketConnecionV2");
|
|
1820
|
-
let
|
|
1820
|
+
let Ct = lt;
|
|
1821
1821
|
const ht = class ht {
|
|
1822
1822
|
constructor(t, e) {
|
|
1823
1823
|
o(this, "cache", /* @__PURE__ */ new Map());
|
|
@@ -1826,7 +1826,7 @@ const ht = class ht {
|
|
|
1826
1826
|
this.serverBaseUrl = t.replace(/\/$/, ""), this.accessToken = e;
|
|
1827
1827
|
}
|
|
1828
1828
|
get headers() {
|
|
1829
|
-
return { Authorization: `Bearer ${
|
|
1829
|
+
return { Authorization: `Bearer ${zt(this.accessToken)}` };
|
|
1830
1830
|
}
|
|
1831
1831
|
async init() {
|
|
1832
1832
|
}
|
|
@@ -1874,7 +1874,7 @@ const ht = class ht {
|
|
|
1874
1874
|
}
|
|
1875
1875
|
};
|
|
1876
1876
|
h(ht, "HttpArtifactService");
|
|
1877
|
-
let
|
|
1877
|
+
let Mt = ht;
|
|
1878
1878
|
const ut = class ut extends Error {
|
|
1879
1879
|
constructor(t, e) {
|
|
1880
1880
|
super(e ?? `GET detached-run frames answered ${t}`), this.status = t, this.name = "DetachedRunFramesHttpError";
|
|
@@ -1882,15 +1882,15 @@ const ut = class ut extends Error {
|
|
|
1882
1882
|
};
|
|
1883
1883
|
h(ut, "DetachedRunFramesHttpError");
|
|
1884
1884
|
let L = ut;
|
|
1885
|
-
function
|
|
1885
|
+
function me(i) {
|
|
1886
1886
|
if (i instanceof L) {
|
|
1887
1887
|
const { status: t } = i;
|
|
1888
1888
|
return { kind: t === 401 ? "unauthorized" : t === 403 ? "forbidden" : t === 404 || t === 410 ? "notFound" : "gaveUp", status: t, cause: i };
|
|
1889
1889
|
}
|
|
1890
1890
|
return { kind: "gaveUp", cause: i };
|
|
1891
1891
|
}
|
|
1892
|
-
h(
|
|
1893
|
-
function
|
|
1892
|
+
h(me, "toDetachedRunFollowError");
|
|
1893
|
+
function we(i) {
|
|
1894
1894
|
let t = "", e = [], s, n;
|
|
1895
1895
|
const r = /* @__PURE__ */ h(() => {
|
|
1896
1896
|
(e.length > 0 || s !== void 0) && i({ event: s, data: e.join(`
|
|
@@ -1921,12 +1921,12 @@ function me(i) {
|
|
|
1921
1921
|
}
|
|
1922
1922
|
};
|
|
1923
1923
|
}
|
|
1924
|
-
h(
|
|
1925
|
-
function
|
|
1924
|
+
h(we, "createSseParser");
|
|
1925
|
+
function Se(i) {
|
|
1926
1926
|
return i >= 500 || i === 408 || i === 429;
|
|
1927
1927
|
}
|
|
1928
|
-
h(
|
|
1929
|
-
function
|
|
1928
|
+
h(Se, "retryable");
|
|
1929
|
+
function Ie(i, t) {
|
|
1930
1930
|
return new Promise((e) => {
|
|
1931
1931
|
if (t != null && t.aborted) return e();
|
|
1932
1932
|
const s = setTimeout(n, i);
|
|
@@ -1936,15 +1936,16 @@ function Se(i, t) {
|
|
|
1936
1936
|
h(n, "done"), t == null || t.addEventListener("abort", n, { once: !0 });
|
|
1937
1937
|
});
|
|
1938
1938
|
}
|
|
1939
|
-
h(
|
|
1940
|
-
function
|
|
1941
|
-
|
|
1939
|
+
h(Ie, "sleep");
|
|
1940
|
+
function Te(i, t, e, s) {
|
|
1941
|
+
const n = t === "session" ? "sessions" : "detached-runs";
|
|
1942
|
+
return `${i.replace(/\/+$/, "")}/${n}/${encodeURIComponent(e)}/frames?afterSeq=${s}`;
|
|
1942
1943
|
}
|
|
1943
|
-
h(
|
|
1944
|
-
async function
|
|
1945
|
-
var
|
|
1946
|
-
const { baseUrl: t, runId: e, signal: s, onFrame: n, onEnd: r, onOpen: a, onRetry: c } = i, l = i.fetchImpl ?? ((A, $) => fetch(A, $)),
|
|
1947
|
-
let
|
|
1944
|
+
h(Te, "framesUrl");
|
|
1945
|
+
async function ye(i) {
|
|
1946
|
+
var F, v, C, ft, gt;
|
|
1947
|
+
const { baseUrl: t, runId: e, signal: s, onFrame: n, onEnd: r, onOpen: a, onRetry: c } = i, l = i.resource ?? "detachedRun", f = i.fetchImpl ?? ((A, $) => fetch(A, $)), p = ((F = i.retry) == null ? void 0 : F.initialMs) ?? 500, m = ((v = i.retry) == null ? void 0 : v.maxMs) ?? 15e3, u = ((C = i.retry) == null ? void 0 : C.maxAttempts) ?? Number.POSITIVE_INFINITY;
|
|
1948
|
+
let g = i.afterSeq ?? 0, w = 0, M = !1;
|
|
1948
1949
|
async function D(A) {
|
|
1949
1950
|
if (i.onUnauthorized)
|
|
1950
1951
|
try {
|
|
@@ -1959,77 +1960,77 @@ async function Te(i) {
|
|
|
1959
1960
|
for (h(D, "secondChance"); !(s != null && s.aborted); ) {
|
|
1960
1961
|
let A;
|
|
1961
1962
|
try {
|
|
1962
|
-
const O = { Accept: "text/event-stream" }, K = await ((
|
|
1963
|
+
const O = { Accept: "text/event-stream" }, K = await ((ft = i.getToken) == null ? void 0 : ft.call(i)) ?? void 0;
|
|
1963
1964
|
K && (O.Authorization = `Bearer ${K}`);
|
|
1964
|
-
const k = await
|
|
1965
|
+
const k = await f(Te(t, l, e, g), { method: "GET", headers: O, signal: s, cache: "no-store" });
|
|
1965
1966
|
if (k.status === 401) {
|
|
1966
|
-
if (!
|
|
1967
|
-
|
|
1967
|
+
if (!M && await D(K)) {
|
|
1968
|
+
M = !0;
|
|
1968
1969
|
continue;
|
|
1969
1970
|
}
|
|
1970
1971
|
throw new L(401);
|
|
1971
1972
|
}
|
|
1972
|
-
if (
|
|
1973
|
-
throw
|
|
1973
|
+
if (M = !1, !k.ok)
|
|
1974
|
+
throw Se(k.status) ? new Error(`GET detached-run frames answered ${k.status}`) : new L(k.status);
|
|
1974
1975
|
if (!k.body) throw new L(k.status, "The frames response has no readable body");
|
|
1975
1976
|
a == null || a();
|
|
1976
1977
|
let W = !1;
|
|
1977
|
-
const B =
|
|
1978
|
+
const B = we((T) => {
|
|
1978
1979
|
if (T.event === "end") {
|
|
1979
1980
|
const b = Number(T.data);
|
|
1980
|
-
T.data !== "" && Number.isFinite(b) && b >
|
|
1981
|
+
T.data !== "" && Number.isFinite(b) && b > g && (g = b), W = !0;
|
|
1981
1982
|
return;
|
|
1982
1983
|
}
|
|
1983
1984
|
if (T.event !== void 0 && T.event !== "message" || T.data === "") return;
|
|
1984
1985
|
const R = T.id !== void 0 && T.id !== "" ? Number(T.id) : void 0;
|
|
1985
1986
|
if (R !== void 0 && Number.isFinite(R)) {
|
|
1986
|
-
if (R <=
|
|
1987
|
-
|
|
1987
|
+
if (R <= g) return;
|
|
1988
|
+
g = R;
|
|
1988
1989
|
}
|
|
1989
1990
|
W = !1;
|
|
1990
|
-
let
|
|
1991
|
+
let mt;
|
|
1991
1992
|
try {
|
|
1992
|
-
|
|
1993
|
+
mt = JSON.parse(T.data);
|
|
1993
1994
|
} catch (b) {
|
|
1994
1995
|
console.warn(`[DetachedRunFrames] run ${e}: a frame that is not JSON was skipped (seq ${T.id ?? "?"})`, b);
|
|
1995
1996
|
return;
|
|
1996
1997
|
}
|
|
1997
|
-
|
|
1998
|
+
w = 0;
|
|
1998
1999
|
try {
|
|
1999
|
-
n(
|
|
2000
|
+
n(mt, R);
|
|
2000
2001
|
} catch (b) {
|
|
2001
2002
|
console.error(`[DetachedRunFrames] run ${e}: onFrame threw on seq ${T.id ?? "?"}`, b);
|
|
2002
2003
|
}
|
|
2003
|
-
}), G = k.body.getReader(),
|
|
2004
|
+
}), G = k.body.getReader(), pt = new TextDecoder();
|
|
2004
2005
|
try {
|
|
2005
2006
|
for (; ; ) {
|
|
2006
2007
|
const { done: T, value: R } = await G.read();
|
|
2007
2008
|
if (T) break;
|
|
2008
|
-
B.push(
|
|
2009
|
+
B.push(pt.decode(R, { stream: !0 }));
|
|
2009
2010
|
}
|
|
2010
|
-
B.push(
|
|
2011
|
+
B.push(pt.decode()), B.idle() || (W = !1), B.flush();
|
|
2011
2012
|
} finally {
|
|
2012
|
-
(
|
|
2013
|
+
(gt = G.releaseLock) == null || gt.call(G);
|
|
2013
2014
|
}
|
|
2014
|
-
if (W)
|
|
2015
|
-
return r == null || r(
|
|
2016
|
-
A = new Error("The frames stream closed before its end event");
|
|
2015
|
+
if (W && l !== "session")
|
|
2016
|
+
return r == null || r(g), { reason: "end", lastSeq: g };
|
|
2017
|
+
A = new Error(l === "session" ? "The session frames stream closed" : "The frames stream closed before its end event");
|
|
2017
2018
|
} catch (O) {
|
|
2018
2019
|
if (s != null && s.aborted) break;
|
|
2019
2020
|
if (O instanceof L) throw O;
|
|
2020
2021
|
A = O;
|
|
2021
2022
|
}
|
|
2022
|
-
if (
|
|
2023
|
-
const $ = Math.min(
|
|
2023
|
+
if (w += 1, w >= u) throw A;
|
|
2024
|
+
const $ = Math.min(p * 2 ** (w - 1), m);
|
|
2024
2025
|
try {
|
|
2025
|
-
c == null || c(A,
|
|
2026
|
+
c == null || c(A, w, $);
|
|
2026
2027
|
} catch {
|
|
2027
2028
|
}
|
|
2028
|
-
await
|
|
2029
|
+
await Ie($, s);
|
|
2029
2030
|
}
|
|
2030
|
-
return { reason: "aborted", lastSeq:
|
|
2031
|
+
return { reason: "aborted", lastSeq: g };
|
|
2031
2032
|
}
|
|
2032
|
-
h(
|
|
2033
|
+
h(ye, "streamDetachedRunFrames");
|
|
2033
2034
|
const dt = class dt {
|
|
2034
2035
|
constructor(t) {
|
|
2035
2036
|
o(this, "onEvent");
|
|
@@ -2062,7 +2063,8 @@ const dt = class dt {
|
|
|
2062
2063
|
return this.following;
|
|
2063
2064
|
}
|
|
2064
2065
|
connect(t, e) {
|
|
2065
|
-
|
|
2066
|
+
var s, n;
|
|
2067
|
+
return t ? ((t !== this.runId || !(e != null && e.resume)) && (this.lastSeq = ((n = (s = this.options).initialAfterSeq) == null ? void 0 : n.call(s)) ?? 0, this.firstTokens.clear()), this.runId = t, this.start(t)) : Promise.reject(new Error("DetachedRunFramesTransport: connect() needs the run id"));
|
|
2066
2068
|
}
|
|
2067
2069
|
/**
|
|
2068
2070
|
* Follow again from the last seq — after the stream ended and the run was resumed (answered). A no-op while a
|
|
@@ -2077,7 +2079,7 @@ const dt = class dt {
|
|
|
2077
2079
|
const e = new AbortController();
|
|
2078
2080
|
return this.controller = e, this.following = !0, new Promise((n, r) => {
|
|
2079
2081
|
let a = !1;
|
|
2080
|
-
|
|
2082
|
+
ye({
|
|
2081
2083
|
...this.options,
|
|
2082
2084
|
runId: t,
|
|
2083
2085
|
afterSeq: this.lastSeq,
|
|
@@ -2100,7 +2102,7 @@ const dt = class dt {
|
|
|
2100
2102
|
a || r(new Error("The frames stream stopped before it opened"));
|
|
2101
2103
|
}).catch((c) => {
|
|
2102
2104
|
var p, m, u;
|
|
2103
|
-
const l =
|
|
2105
|
+
const l = me(c), f = l.kind === "notFound" ? Dt : l.kind === "forbidden" || l.kind === "unauthorized" ? 1008 : 1011;
|
|
2104
2106
|
console.error(`[DetachedRunFrames] run ${t}: following stopped (${l.kind})`, c);
|
|
2105
2107
|
try {
|
|
2106
2108
|
(p = this.onFollowError) == null || p.call(this, l);
|
|
@@ -2124,14 +2126,14 @@ const dt = class dt {
|
|
|
2124
2126
|
return;
|
|
2125
2127
|
}
|
|
2126
2128
|
if (!e) return;
|
|
2127
|
-
const s =
|
|
2129
|
+
const s = Rt(e);
|
|
2128
2130
|
if (s) {
|
|
2129
2131
|
(r = this.onInteractionStarted) == null || r.call(this, s);
|
|
2130
2132
|
return;
|
|
2131
2133
|
}
|
|
2132
2134
|
const n = st(e);
|
|
2133
2135
|
if (n) {
|
|
2134
|
-
|
|
2136
|
+
$t(n) && n.interactionId && !this.firstTokens.has(n.interactionId) && (this.firstTokens.add(n.interactionId), (a = this.onFirstToken) == null || a.call(this, n.interactionId));
|
|
2135
2137
|
try {
|
|
2136
2138
|
const l = x.parseFromTypedEvent(n);
|
|
2137
2139
|
(c = this.onEvent) == null || c.call(this, l).catch((f) => console.error("[DetachedRunFrames] onEvent failed", f));
|
|
@@ -2154,9 +2156,9 @@ const dt = class dt {
|
|
|
2154
2156
|
}
|
|
2155
2157
|
};
|
|
2156
2158
|
h(dt, "DetachedRunFramesTransport");
|
|
2157
|
-
let
|
|
2158
|
-
const
|
|
2159
|
-
function
|
|
2159
|
+
let At = dt;
|
|
2160
|
+
const ve = "todolistUpdated";
|
|
2161
|
+
function be(i, t = et()) {
|
|
2160
2162
|
var n, r;
|
|
2161
2163
|
let e;
|
|
2162
2164
|
try {
|
|
@@ -2168,14 +2170,14 @@ function Re(i, t = et()) {
|
|
|
2168
2170
|
if (!e) return [];
|
|
2169
2171
|
const s = [];
|
|
2170
2172
|
for (const a of e.parts ?? [])
|
|
2171
|
-
if (a.eventType === I.ToolEvent && ((n = a.toolDetails) == null ? void 0 : n.eventName) ===
|
|
2172
|
-
const c =
|
|
2173
|
+
if (a.eventType === I.ToolEvent && ((n = a.toolDetails) == null ? void 0 : n.eventName) === ve) {
|
|
2174
|
+
const c = Ee(a.toolDetails.eventData);
|
|
2173
2175
|
c && s.push({ kind: "todo", todoList: c });
|
|
2174
2176
|
} else (a.eventType === I.FunctionCall || a.eventType === I.PartialFunctionCall) && ((r = a.functionDetails) != null && r.name) ? s.push({ kind: "tool", name: a.functionDetails.name, interactionId: e.interactionId }) : a.eventType === I.Text && a.text && s.push({ kind: "text", text: a.text, partial: !!e.partial, interactionId: e.interactionId });
|
|
2175
2177
|
return s;
|
|
2176
2178
|
}
|
|
2177
|
-
h(
|
|
2178
|
-
function
|
|
2179
|
+
h(be, "readDetachedRunActivity");
|
|
2180
|
+
function Ee(i) {
|
|
2179
2181
|
if (!i) return null;
|
|
2180
2182
|
try {
|
|
2181
2183
|
const t = JSON.parse(i);
|
|
@@ -2184,26 +2186,26 @@ function ve(i) {
|
|
|
2184
2186
|
return null;
|
|
2185
2187
|
}
|
|
2186
2188
|
}
|
|
2187
|
-
h(
|
|
2189
|
+
h(Ee, "parseTodoList");
|
|
2188
2190
|
export {
|
|
2189
|
-
|
|
2191
|
+
yt as A,
|
|
2190
2192
|
V as C,
|
|
2191
2193
|
L as D,
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
+
Tt as E,
|
|
2195
|
+
Mt as H,
|
|
2194
2196
|
_ as I,
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2197
|
+
It as L,
|
|
2198
|
+
Jt as M,
|
|
2199
|
+
ve as T,
|
|
2200
|
+
ae as W,
|
|
2201
|
+
At as a,
|
|
2200
2202
|
j as b,
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2203
|
+
Ct as c,
|
|
2204
|
+
we as d,
|
|
2205
|
+
ee as e,
|
|
2206
|
+
be as r,
|
|
2207
|
+
ye as s,
|
|
2208
|
+
me as t,
|
|
2209
|
+
Re as u
|
|
2208
2210
|
};
|
|
2209
|
-
//# sourceMappingURL=detachedRunActivity-
|
|
2211
|
+
//# sourceMappingURL=detachedRunActivity-jHa9SDv1.js.map
|