@aintela/chat 0.2.41 → 0.2.43
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/{atMentions-C5Fs9Yab.js → atMentions-CJUmkOh9.js} +9 -9
- package/dist/{atMentions-C5Fs9Yab.js.map → atMentions-CJUmkOh9.js.map} +1 -1
- package/dist/{auth-ffNUief3.js → auth-xpQrzSI2.js} +2 -2
- package/dist/{auth-ffNUief3.js.map → auth-xpQrzSI2.js.map} +1 -1
- package/dist/components.js +6338 -6131
- package/dist/components.js.map +1 -1
- package/dist/{httpArtifactService-DBKIvfSD.js → httpArtifactService--6WV2FDW.js} +133 -125
- package/dist/{httpArtifactService-DBKIvfSD.js.map → httpArtifactService--6WV2FDW.js.map} +1 -1
- package/dist/index.js +178 -175
- package/dist/services.js +1 -1
- package/dist/src/components/AiChat/ChatPane/AskUserDialog.d.ts +36 -0
- package/dist/src/components/AiChat/ChatPane/AskUserSheet.d.ts +4 -0
- package/dist/src/components/AiChat/ChatPane/parts/uiPartStage.d.ts +67 -0
- package/dist/src/components/AiChat/ChatPane/useParkedAskUser.d.ts +39 -0
- package/dist/src/components/LlmResponseRender/parseBlocks.test.d.ts +1 -0
- package/dist/src/components/index.d.ts +5 -0
- package/dist/src/services/WebSocketConnection/webSocketConnection.d.ts +7 -0
- package/dist/src/services/servers/AgentGatewayWSAsync.d.ts +7 -1
- package/dist/utils.js +2 -2
- package/package.json +1 -1
|
@@ -2,11 +2,11 @@ var rt = Object.defineProperty;
|
|
|
2
2
|
var St = (O, t, e) => t in O ? rt(O, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : O[t] = e;
|
|
3
3
|
var g = (O, t) => rt(O, "name", { value: t, configurable: !0 });
|
|
4
4
|
var a = (O, t, e) => St(O, typeof t != "symbol" ? t + "" : t, e);
|
|
5
|
-
import { d as L, t as wt, E as C, k as
|
|
5
|
+
import { d as L, t as wt, E as C, k as yt, j as Tt, q as It, C as B } from "./environmentUtils-CUVZ6Dq1.js";
|
|
6
6
|
import { I as _, S as gt, g as Ct, L as vt, P as x, b as Et, e as Mt, T as Ot, c as Dt } from "./serializer-uea8YsIP.js";
|
|
7
7
|
import { unified as At } from "unified";
|
|
8
|
-
import
|
|
9
|
-
import { toMarkdown as
|
|
8
|
+
import kt from "remark-parse";
|
|
9
|
+
import { toMarkdown as Nt } from "mdast-util-to-markdown";
|
|
10
10
|
import { format as Pt } from "date-fns";
|
|
11
11
|
import _t from "lodash";
|
|
12
12
|
import { P as bt, C as R } from "./Prompt-DZb7OaPp.js";
|
|
@@ -534,14 +534,14 @@ const Q = class Q {
|
|
|
534
534
|
a(this, "eventBusService");
|
|
535
535
|
a(this, "parseTextIntoParts", /* @__PURE__ */ g((t) => {
|
|
536
536
|
if (!t || t.trim().length == 0) return [];
|
|
537
|
-
const e = At().use(
|
|
537
|
+
const e = At().use(kt).parse(t), s = [];
|
|
538
538
|
let i = null;
|
|
539
539
|
for (const n of e.children)
|
|
540
540
|
n.type === "code" ? (i && (s.push(i), i = null), n.lang === "htmlCanvas" && s.push(`
|
|
541
541
|
\`\`\`liveTsx
|
|
542
542
|
${n.value}
|
|
543
543
|
\`\`\`
|
|
544
|
-
`)) : (i || (i = ""), i +=
|
|
544
|
+
`)) : (i || (i = ""), i += Nt(n));
|
|
545
545
|
return i && s.push(i), s;
|
|
546
546
|
}, "parseTextIntoParts"));
|
|
547
547
|
this.interaction = t, this.eventBusService = e;
|
|
@@ -556,22 +556,22 @@ ${n.value}
|
|
|
556
556
|
return i;
|
|
557
557
|
}
|
|
558
558
|
groupPartsByDisplayType(t, e = !0, s = !1) {
|
|
559
|
-
var l;
|
|
559
|
+
var l, o, d;
|
|
560
560
|
const i = [];
|
|
561
561
|
let n = new W();
|
|
562
|
-
for (let
|
|
563
|
-
const
|
|
564
|
-
let
|
|
565
|
-
!e &&
|
|
562
|
+
for (let u = 0; u < t.length; u++) {
|
|
563
|
+
const h = t[u];
|
|
564
|
+
let p = !((((l = h.functionDetails) == null ? void 0 : l.isUi) ?? !1) || ((o = h.functionDetails) == null ? void 0 : o.cancelUi) !== !0 && (((d = h.functionDetails) == null ? void 0 : d.isAskUser) ?? !1)) && h.eventType !== C.Text && h.eventType !== C.Thought && (h.eventType === C.FunctionCall || h.eventType === C.PartialFunctionCall || h.eventType === C.FunctionResponse) && u < t.length - 1;
|
|
565
|
+
!e && p && !s || (p ? (h.eventType == C.Thought && (n.hasThoughts = !0), n.parts.push(h), n.isLastGroup = u === t.length - 1) : (n.parts.length > 0 && (i.push(n), n = new W()), i.push({
|
|
566
566
|
type: pt.block,
|
|
567
|
-
parts: [
|
|
568
|
-
isLastGroup:
|
|
567
|
+
parts: [h],
|
|
568
|
+
isLastGroup: u === t.length - 1,
|
|
569
569
|
hasThoughts: !1,
|
|
570
570
|
lastWithThoughts: !1
|
|
571
571
|
})));
|
|
572
572
|
}
|
|
573
573
|
n.parts.length > 0 && i.push(n);
|
|
574
|
-
const r = i.filter((
|
|
574
|
+
const r = i.filter((u) => u.hasThoughts);
|
|
575
575
|
return r.length > 0 && (r[r.length - 1].lastWithThoughts = !0), i;
|
|
576
576
|
}
|
|
577
577
|
isFunctionCall(t) {
|
|
@@ -586,57 +586,57 @@ ${n.value}
|
|
|
586
586
|
// new tree as the last step, so snapshots already handed out to throttled
|
|
587
587
|
// subscribers can't diverge from the live state.
|
|
588
588
|
merge(t) {
|
|
589
|
-
var b,
|
|
589
|
+
var b, T, A, k, et, st, nt, it;
|
|
590
590
|
const e = this.interaction, s = [], i = [], n = _.FlatParts(t == null ? void 0 : t.parts), r = e.parts[e.parts.length - 1] ?? null;
|
|
591
591
|
let l = !1;
|
|
592
|
-
n && (l = !r || n.mustPush || n.mustPush === !1 && (n.eventType !== (r == null ? void 0 : r.eventType) || ((b = n == null ? void 0 : n.functionDetails) == null ? void 0 : b.id) !== ((
|
|
593
|
-
let o = e.parts,
|
|
592
|
+
n && (l = !r || n.mustPush || n.mustPush === !1 && (n.eventType !== (r == null ? void 0 : r.eventType) || ((b = n == null ? void 0 : n.functionDetails) == null ? void 0 : b.id) !== ((T = r.functionDetails) == null ? void 0 : T.id)));
|
|
593
|
+
let o = e.parts, d = e.functionMap ?? /* @__PURE__ */ new Map(), u = !e.functionMap;
|
|
594
594
|
const h = /* @__PURE__ */ g(() => {
|
|
595
|
-
|
|
595
|
+
u || (d = new Map(d), u = !0);
|
|
596
596
|
}, "cloneFunctionMap"), v = /* @__PURE__ */ g(() => {
|
|
597
597
|
o === e.parts && (o = e.parts.slice());
|
|
598
598
|
}, "clonePartsIfShared");
|
|
599
599
|
if (!l && (o == null ? void 0 : o.length) > 0 && (n != null && n.textAppendable)) {
|
|
600
600
|
const f = o[o.length - 1];
|
|
601
|
-
(((
|
|
601
|
+
(((k = (A = f.thoughtDetails) == null ? void 0 : A.text) == null ? void 0 : k.length) ?? ((et = f.text) == null ? void 0 : et.length) ?? 0) > Rt && (l = !0);
|
|
602
602
|
}
|
|
603
|
-
let
|
|
603
|
+
let p = !1;
|
|
604
604
|
if ((n == null ? void 0 : n.eventType) === C.FunctionClientOutput && !!((st = n.functionDetails) != null && st.id) && n) {
|
|
605
605
|
const f = n.functionDetails.id, I = n.functionDetails.clientOutput, E = o.findIndex((S) => {
|
|
606
|
-
var
|
|
607
|
-
return ((
|
|
606
|
+
var m;
|
|
607
|
+
return ((m = S.functionDetails) == null ? void 0 : m.id) === f;
|
|
608
608
|
});
|
|
609
609
|
if (E > -1) {
|
|
610
|
-
const S = o[E],
|
|
610
|
+
const S = o[E], m = {
|
|
611
611
|
...S,
|
|
612
612
|
functionDetails: {
|
|
613
613
|
...S.functionDetails,
|
|
614
614
|
clientOutput: I ?? S.functionDetails.clientOutput
|
|
615
615
|
}
|
|
616
616
|
};
|
|
617
|
-
v(), o[E] =
|
|
617
|
+
v(), o[E] = m, h(), d.set(f, m), s.push(m);
|
|
618
618
|
} else {
|
|
619
619
|
const S = {
|
|
620
620
|
...n,
|
|
621
621
|
id: o.length + 1 + "-" + e.interactionId,
|
|
622
622
|
functionDetails: { ...n.functionDetails, silent: !0 }
|
|
623
623
|
};
|
|
624
|
-
v(), o = o === e.parts ? e.parts.slice() : o, o.push(S), h(),
|
|
624
|
+
v(), o = o === e.parts ? e.parts.slice() : o, o.push(S), h(), d.set(f, S);
|
|
625
625
|
}
|
|
626
626
|
} else if (l && n) {
|
|
627
627
|
const f = this.isFunctionCall(n.eventType) || this.isFunctionResponse(n.eventType), I = f ? (nt = n.functionDetails) == null ? void 0 : nt.id : void 0;
|
|
628
628
|
f && !I && console.error("Got isCall or isResponse without a callId", n);
|
|
629
|
-
const E = I ?
|
|
629
|
+
const E = I ? d.get(I) : void 0;
|
|
630
630
|
if (E && I && n.functionDetails) {
|
|
631
631
|
const S = o.findIndex((mt) => {
|
|
632
632
|
var at;
|
|
633
633
|
return ((at = mt.functionDetails) == null ? void 0 : at.id) === I;
|
|
634
|
-
}),
|
|
635
|
-
...
|
|
634
|
+
}), m = S > -1 ? o[S] : E, F = {
|
|
635
|
+
...m,
|
|
636
636
|
eventType: n.eventType,
|
|
637
637
|
functionDetails: {
|
|
638
|
-
id:
|
|
639
|
-
name: n.functionDetails.name ??
|
|
638
|
+
id: m.functionDetails.id,
|
|
639
|
+
name: n.functionDetails.name ?? m.functionDetails.name,
|
|
640
640
|
// Take the parsed args from the incoming event when
|
|
641
641
|
// present (the full FunctionCall carries them), fall
|
|
642
642
|
// back to what was already on the part. Previously
|
|
@@ -645,41 +645,41 @@ ${n.value}
|
|
|
645
645
|
// args off every full FunctionCall fold because the
|
|
646
646
|
// PartialFunctionCall stream only accumulates raw
|
|
647
647
|
// JSON in `.text` — `.args` stayed undefined.
|
|
648
|
-
args: n.functionDetails.args ??
|
|
648
|
+
args: n.functionDetails.args ?? m.functionDetails.args,
|
|
649
649
|
response: n.functionDetails.response,
|
|
650
650
|
status: n.functionDetails.status ?? "Composing",
|
|
651
|
-
start: n.functionDetails.start ??
|
|
652
|
-
end: n.functionDetails.end ??
|
|
651
|
+
start: n.functionDetails.start ?? m.functionDetails.start,
|
|
652
|
+
end: n.functionDetails.end ?? m.functionDetails.end,
|
|
653
653
|
// true-wins: a UI call has multiple reps (streaming part with isUi, the
|
|
654
654
|
// persisted FunctionCall, the result) and they interleave. `??` let a later
|
|
655
655
|
// `false`/`undefined` rep clobber an earlier `true`; OR-ing keeps it sticky.
|
|
656
|
-
isUi: n.functionDetails.isUi === !0 ||
|
|
656
|
+
isUi: n.functionDetails.isUi === !0 || m.functionDetails.isUi === !0,
|
|
657
657
|
// Keep the call's friendly args summary when the result event (which has none) folds in.
|
|
658
|
-
argsDescription: n.functionDetails.argsDescription ??
|
|
658
|
+
argsDescription: n.functionDetails.argsDescription ?? m.functionDetails.argsDescription,
|
|
659
659
|
// The tool's client-only payload rides the RESULT event; keep it sticky so a
|
|
660
660
|
// later rep without one can't clobber it. This is what a uiTool renderer reads.
|
|
661
|
-
clientOutput: n.functionDetails.clientOutput ??
|
|
661
|
+
clientOutput: n.functionDetails.clientOutput ?? m.functionDetails.clientOutput,
|
|
662
662
|
// Ask-user component ([KernelUIComponent]) — sticky like isUi/clientOutput. The
|
|
663
663
|
// streaming final CALL carries it, but the PartialFunctionCall it folds onto (and a
|
|
664
664
|
// later result rep) may not; dropping it strips the part's askUser classification so
|
|
665
665
|
// the docked drawer never surfaces (issue #60 — esp. a no-arg tool like update_profile,
|
|
666
666
|
// which has no name match to fall back on the way ask_user/askauth do).
|
|
667
|
-
askUserComponent: n.functionDetails.askUserComponent ??
|
|
668
|
-
isAskUser: n.functionDetails.isAskUser ||
|
|
667
|
+
askUserComponent: n.functionDetails.askUserComponent ?? m.functionDetails.askUserComponent,
|
|
668
|
+
isAskUser: n.functionDetails.isAskUser || m.functionDetails.isAskUser || !!(n.functionDetails.askUserComponent ?? m.functionDetails.askUserComponent),
|
|
669
669
|
// Runtime "don't render" override rides the RESULT; true-wins sticky like isUi so it
|
|
670
670
|
// survives folding onto the earlier call rep and suppresses drawer/uiTool classification.
|
|
671
|
-
cancelUi: n.functionDetails.cancelUi === !0 ||
|
|
671
|
+
cancelUi: n.functionDetails.cancelUi === !0 || m.functionDetails.cancelUi === !0
|
|
672
672
|
}
|
|
673
673
|
};
|
|
674
|
-
h(),
|
|
674
|
+
h(), d.set(I, F), F.eventType === C.FunctionResponse && this.eventBusService.gatewayEmitFunctionResponse(F.functionDetails), s.push(F), S > -1 && (v(), o[S] = F);
|
|
675
675
|
} else {
|
|
676
|
-
if (I && n.functionDetails && !E && (h(),
|
|
677
|
-
const
|
|
676
|
+
if (I && n.functionDetails && !E && (h(), d.set(I, n)), r && r.textAppendable) {
|
|
677
|
+
const m = {
|
|
678
678
|
...r,
|
|
679
679
|
ended: /* @__PURE__ */ new Date(),
|
|
680
680
|
isStillWriting: !1
|
|
681
681
|
};
|
|
682
|
-
v(), o[o.length - 1] =
|
|
682
|
+
v(), o[o.length - 1] = m, s.push(m);
|
|
683
683
|
}
|
|
684
684
|
const S = {
|
|
685
685
|
...n,
|
|
@@ -687,20 +687,20 @@ ${n.value}
|
|
|
687
687
|
isStillWriting: n.textAppendable,
|
|
688
688
|
partial: t.partial
|
|
689
689
|
};
|
|
690
|
-
(it = S.functionDetails) != null && it.silent || s.push(S), o = [...o, S],
|
|
690
|
+
(it = S.functionDetails) != null && it.silent || s.push(S), o = [...o, S], p = !0;
|
|
691
691
|
}
|
|
692
692
|
}
|
|
693
|
-
let
|
|
694
|
-
if (
|
|
693
|
+
let y = o[o.length - 1] ?? null;
|
|
694
|
+
if (y && n && n.textAppendable) {
|
|
695
695
|
const f = {
|
|
696
|
-
...
|
|
696
|
+
...y,
|
|
697
697
|
partial: t.partial,
|
|
698
|
-
textDetails:
|
|
698
|
+
textDetails: y.textDetails ? { ...y.textDetails } : { version: 0 }
|
|
699
699
|
};
|
|
700
700
|
let I = !1;
|
|
701
701
|
if (t.partial) {
|
|
702
702
|
try {
|
|
703
|
-
f.textDetails.version++,
|
|
703
|
+
f.textDetails.version++, p || (f.text = (y.text ?? "") + (n.text ?? ""));
|
|
704
704
|
} catch (E) {
|
|
705
705
|
console.error("Error here", E.toString());
|
|
706
706
|
}
|
|
@@ -713,7 +713,7 @@ ${n.value}
|
|
|
713
713
|
...n.thoughtDetails,
|
|
714
714
|
text: n.thoughtDetails.text.trim()
|
|
715
715
|
}), I = !l;
|
|
716
|
-
v(), o[o.length - 1] = f,
|
|
716
|
+
v(), o[o.length - 1] = f, y = f, I && s.push(f);
|
|
717
717
|
}
|
|
718
718
|
let M = e.artifactData ?? [];
|
|
719
719
|
if (t.llmArtifacts && t.llmArtifacts.length > 0) {
|
|
@@ -721,7 +721,7 @@ ${n.value}
|
|
|
721
721
|
for (const I of t.llmArtifacts) {
|
|
722
722
|
const E = I.toArtifact();
|
|
723
723
|
f || (M = M.slice(), f = !0);
|
|
724
|
-
const S = M.findIndex((
|
|
724
|
+
const S = M.findIndex((m) => m.id === E.id);
|
|
725
725
|
S === -1 ? M.push(E) : M[S] = E;
|
|
726
726
|
}
|
|
727
727
|
}
|
|
@@ -730,7 +730,7 @@ ${n.value}
|
|
|
730
730
|
version: e.version + 1,
|
|
731
731
|
parts: o,
|
|
732
732
|
artifactData: M,
|
|
733
|
-
functionMap:
|
|
733
|
+
functionMap: d,
|
|
734
734
|
turn_complete: t.turn_complete,
|
|
735
735
|
partial: t.partial,
|
|
736
736
|
asyncFinalResponse: t.asyncFinalResponse
|
|
@@ -748,9 +748,9 @@ ${n.value}
|
|
|
748
748
|
};
|
|
749
749
|
g(Q, "InteractionService");
|
|
750
750
|
let $ = Q;
|
|
751
|
-
const Ut = 1200 * 1e3,
|
|
752
|
-
constructor(t, e, s, i, n, r, l, o,
|
|
753
|
-
a(this, "base_production_url",
|
|
751
|
+
const Ut = 1200 * 1e3, N = class N {
|
|
752
|
+
constructor(t, e, s, i, n, r, l, o, d, u = Tt.Interactive) {
|
|
753
|
+
a(this, "base_production_url", yt() ?? "https://agent.tripapi.com.br");
|
|
754
754
|
a(this, "base_url_local", "http://localagent:8000");
|
|
755
755
|
a(this, "base_url");
|
|
756
756
|
a(this, "isLocal", !1);
|
|
@@ -825,7 +825,7 @@ const Ut = 1200 * 1e3, k = class k {
|
|
|
825
825
|
a(this, "subAgentInteractionServices", /* @__PURE__ */ new Map());
|
|
826
826
|
a(this, "lastThorttledTimeout", null);
|
|
827
827
|
a(this, "lastPingStatus", !1);
|
|
828
|
-
this.user = t, this.config = n, this.rawJwt = t.access_token, this.base_url = i, this.eventBusService = e, this.sessionId =
|
|
828
|
+
this.user = t, this.config = n, this.rawJwt = t.access_token, this.base_url = i, this.eventBusService = e, this.sessionId = d, this.runMode = u, this.artifactService = s, this.sessionState = r.getState(), this.notificationPort = l, this.storageService = o, r.subscribe((h, v) => {
|
|
829
829
|
this.sessionState = h;
|
|
830
830
|
});
|
|
831
831
|
}
|
|
@@ -1077,10 +1077,10 @@ const Ut = 1200 * 1e3, k = class k {
|
|
|
1077
1077
|
}
|
|
1078
1078
|
localEmitMessage(t, e) {
|
|
1079
1079
|
const s = (/* @__PURE__ */ new Date()).getTime(), i = s - this.lastCurrentMessageUpdate;
|
|
1080
|
-
t.partial === !1 || i >=
|
|
1080
|
+
t.partial === !1 || i >= N.CURRENT_MSG_THROTTLE_MS ? (this.lastThorttledTimeout && (clearTimeout(this.lastThorttledTimeout), this.lastThorttledTimeout = null), this.doEmitMessage(t, s, e), this.pendingCurrentMessage = null) : (this.pendingCurrentMessage = t, this.lastThorttledTimeout && clearTimeout(this.lastThorttledTimeout), this.lastThorttledTimeout = setTimeout(() => {
|
|
1081
1081
|
var r, l;
|
|
1082
1082
|
this.pendingCurrentMessage && (((r = this.pendingCurrentMessage) == null ? void 0 : r.version) ?? 0) > (((l = this.sessionState.currentMessage) == null ? void 0 : l.version) ?? 0) && (this.doEmitMessage(this.pendingCurrentMessage, s, e), this.lastThorttledTimeout = null);
|
|
1083
|
-
},
|
|
1083
|
+
}, N.CURRENT_MSG_THROTTLE_MS * 2));
|
|
1084
1084
|
}
|
|
1085
1085
|
localOpen(t, e) {
|
|
1086
1086
|
this.sessionState.setTurnOpen(!0), this.eventBusService.gatewayEmitTurnOpen(t ?? "");
|
|
@@ -1118,8 +1118,8 @@ const Ut = 1200 * 1e3, k = class k {
|
|
|
1118
1118
|
this.sessionState.onRenderPrompt && (t.data = r, t.friendlyMessage = n);
|
|
1119
1119
|
const l = await this.sendMessageInternal(t, e), o = bt.createPrompt(n ?? "", (r == null ? void 0 : r.toString()) ?? {});
|
|
1120
1120
|
this.storageService.storePrompt(o);
|
|
1121
|
-
const
|
|
1122
|
-
return this.sendStatusMessage(t.data, [i,
|
|
1121
|
+
const d = _.fromText("Planejando próximos passos");
|
|
1122
|
+
return this.sendStatusMessage(t.data, [i, d], s.toString() + "1"), l != null && l.success ? this.eventBusService.ChatEmitMessageSent(t.data, l.interaction) : this.eventBusService.ChatEmitMessageError((l == null ? void 0 : l.error) ?? ""), l;
|
|
1123
1123
|
} catch (n) {
|
|
1124
1124
|
return this.eventBusService.ChatEmitMessageError((n == null ? void 0 : n.toString()) ?? ""), {
|
|
1125
1125
|
success: !1,
|
|
@@ -1174,8 +1174,8 @@ const Ut = 1200 * 1e3, k = class k {
|
|
|
1174
1174
|
return `${this.msg_order}_${e}`;
|
|
1175
1175
|
}
|
|
1176
1176
|
};
|
|
1177
|
-
g(
|
|
1178
|
-
let G =
|
|
1177
|
+
g(N, "AgentGatewayService"), a(N, "SUSPENSION_MSG", "SUSPEND"), a(N, "CURRENT_MSG_THROTTLE_MS", 20);
|
|
1178
|
+
let G = N;
|
|
1179
1179
|
const H = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2, ht = 2, Z = class Z {
|
|
1180
1180
|
constructor(t = "ws://localhost:8000", e) {
|
|
1181
1181
|
a(this, "ws", null);
|
|
@@ -1288,8 +1288,8 @@ const H = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
|
|
|
1288
1288
|
i || (this.cancelPendingReconnect(), this.isReconnecting = !1, this.reconnectAttempts = 0, this.lastSeq = -1), this._internalReconnect = !1;
|
|
1289
1289
|
const n = (b = this.getToken) == null ? void 0 : b.call(this), r = [];
|
|
1290
1290
|
n && r.push(`access_token=${encodeURIComponent(n)}`), t && this.lastSeq >= 0 && r.push(`lastSeq=${this.lastSeq}`);
|
|
1291
|
-
const l = r.length > 0 ? `?${r.join("&")}` : "", o = this.baseUrl.replace(/^http:\/\//, "ws://").replace(/^https:\/\//, "wss://"),
|
|
1292
|
-
if (console.log("Connecting to ",
|
|
1291
|
+
const l = r.length > 0 ? `?${r.join("&")}` : "", o = this.baseUrl.replace(/^http:\/\//, "ws://").replace(/^https:\/\//, "wss://"), d = `${o}/ws/connect/${t ?? ""}${l}`, u = `${o}/ws/connect/${t ?? ""}` + (i && t && this.lastSeq >= 0 ? ` (resume lastSeq=${this.lastSeq})` : "");
|
|
1292
|
+
if (console.log("Connecting to ", u), this.ws) {
|
|
1293
1293
|
this.ws.onopen = null, this.ws.onmessage = null, this.ws.onerror = null, this.ws.onclose = null;
|
|
1294
1294
|
try {
|
|
1295
1295
|
this.ws.close();
|
|
@@ -1297,59 +1297,59 @@ const H = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
|
|
|
1297
1297
|
}
|
|
1298
1298
|
this.ws = null;
|
|
1299
1299
|
}
|
|
1300
|
-
this.ws = new WebSocket(
|
|
1300
|
+
this.ws = new WebSocket(d), console.log("[WebSocket] Connecting to:", `${o}/ws/connect/${t ?? ""}`);
|
|
1301
1301
|
let h = !1;
|
|
1302
1302
|
this.ws.onopen = () => {
|
|
1303
1303
|
console.log("[WebSocket] Connected");
|
|
1304
|
-
const
|
|
1305
|
-
this.isReconnecting = !1, this.reconnectAttempts = 0, this.pingPongStack.push((/* @__PURE__ */ new Date()).getTime()), this.ping(), this.monitor(), this.onOpen && this.onOpen(),
|
|
1306
|
-
}, this.ws.onmessage = (
|
|
1304
|
+
const T = this.isReconnecting;
|
|
1305
|
+
this.isReconnecting = !1, this.reconnectAttempts = 0, this.pingPongStack.push((/* @__PURE__ */ new Date()).getTime()), this.ping(), this.monitor(), this.onOpen && this.onOpen(), T && this.onReconnected && this.onReconnected(t ?? this.lastKnownSessionId ?? ""), this.flushPendingAnswers(t ?? this.lastKnownSessionId);
|
|
1306
|
+
}, this.ws.onmessage = (T) => {
|
|
1307
1307
|
try {
|
|
1308
1308
|
this.lastActivity = (/* @__PURE__ */ new Date()).getTime();
|
|
1309
|
-
const A = this.streamingResponseSerializer.parse(
|
|
1309
|
+
const A = this.streamingResponseSerializer.parse(T.data);
|
|
1310
1310
|
if (!A)
|
|
1311
1311
|
throw "Error parsing event JSON";
|
|
1312
|
-
const
|
|
1313
|
-
!h && (
|
|
1312
|
+
const k = this.handleMessage(A, T.data);
|
|
1313
|
+
!h && (k != null && k.timestamp) && (h = !0, this.hasEverReceivedPacket = !0);
|
|
1314
1314
|
} catch (A) {
|
|
1315
1315
|
console.error("[WebSocket] Error parsing message:", A);
|
|
1316
1316
|
}
|
|
1317
|
-
}, this.ws.onerror = (
|
|
1318
|
-
console.error("[WebSocket] Error:",
|
|
1319
|
-
}, this.ws.onclose = (
|
|
1320
|
-
console.log("[WebSocket] Closed:",
|
|
1317
|
+
}, this.ws.onerror = (T) => {
|
|
1318
|
+
console.error("[WebSocket] Error:", T), this.onError && this.onError("WebSocket error");
|
|
1319
|
+
}, this.ws.onclose = (T) => {
|
|
1320
|
+
console.log("[WebSocket] Closed:", T.code, T.reason), this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingPongStack = [];
|
|
1321
1321
|
const A = this.sessionId ?? this.lastKnownSessionId;
|
|
1322
|
-
if (this.sessionId = void 0, (h || this.hasEverReceivedPacket) && this.shouldAttemptReconnect(
|
|
1323
|
-
this.scheduleReconnect(A,
|
|
1322
|
+
if (this.sessionId = void 0, (h || this.hasEverReceivedPacket) && this.shouldAttemptReconnect(T.code)) {
|
|
1323
|
+
this.scheduleReconnect(A, T.code, T.reason);
|
|
1324
1324
|
return;
|
|
1325
1325
|
}
|
|
1326
|
-
this.isReconnecting = !1, this.reconnectAttempts = 0, this.onClose && this.onClose(
|
|
1326
|
+
this.isReconnecting = !1, this.reconnectAttempts = 0, this.onClose && this.onClose(T.code, T.reason);
|
|
1327
1327
|
};
|
|
1328
|
-
const v = 200,
|
|
1328
|
+
const v = 200, p = 3e4, D = 8e3, y = this.ws;
|
|
1329
1329
|
this.sessionId = void 0;
|
|
1330
1330
|
let M = 0, P = 0;
|
|
1331
1331
|
for (; !this.sessionId; ) {
|
|
1332
|
-
if (this.ws !==
|
|
1332
|
+
if (this.ws !== y) {
|
|
1333
1333
|
s("Connection attempt superseded by a newer connect()");
|
|
1334
1334
|
return;
|
|
1335
1335
|
}
|
|
1336
|
-
if (
|
|
1336
|
+
if (y.readyState === WebSocket.CLOSING || y.readyState === WebSocket.CLOSED) {
|
|
1337
1337
|
s("Connection closed before a session id was received");
|
|
1338
1338
|
return;
|
|
1339
1339
|
}
|
|
1340
|
-
if (
|
|
1340
|
+
if (y.readyState === WebSocket.CONNECTING && M >= p) {
|
|
1341
1341
|
try {
|
|
1342
|
-
|
|
1342
|
+
y.close();
|
|
1343
1343
|
} catch {
|
|
1344
1344
|
}
|
|
1345
|
-
s(`Server did not accept the connection within ${
|
|
1345
|
+
s(`Server did not accept the connection within ${p / 1e3}s`);
|
|
1346
1346
|
return;
|
|
1347
1347
|
}
|
|
1348
|
-
if (
|
|
1348
|
+
if (y.readyState === WebSocket.OPEN && P >= D) {
|
|
1349
1349
|
s(`Connected but no session id arrived within ${D / 1e3}s`);
|
|
1350
1350
|
return;
|
|
1351
1351
|
}
|
|
1352
|
-
M % 2e3 === 0 && console.log("Aguardando session Id"), await this.sleep(v), M += v,
|
|
1352
|
+
M % 2e3 === 0 && console.log("Aguardando session Id"), await this.sleep(v), M += v, y.readyState === WebSocket.OPEN && (P += v);
|
|
1353
1353
|
}
|
|
1354
1354
|
console.log("SUCCESS - GOT SESSION ID", this.sessionId), this.lastKnownSessionId = this.sessionId, e(this.sessionId);
|
|
1355
1355
|
});
|
|
@@ -1402,7 +1402,7 @@ const H = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
|
|
|
1402
1402
|
* Handle incoming messages from server
|
|
1403
1403
|
*/
|
|
1404
1404
|
handleMessage(t, e) {
|
|
1405
|
-
var l, o,
|
|
1405
|
+
var l, o, d;
|
|
1406
1406
|
switch (typeof t.seq == "number" && t.seq > this.lastSeq && (this.lastSeq = t.seq), t.type) {
|
|
1407
1407
|
case "Pong":
|
|
1408
1408
|
if (this.sessionId = t.sessionId, this.lastKnownSessionId = t.sessionId ?? this.lastKnownSessionId, !t.sessionId) {
|
|
@@ -1425,21 +1425,21 @@ const H = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
|
|
|
1425
1425
|
console.warn("[WebSocket] Unknown message type:", t.type);
|
|
1426
1426
|
}
|
|
1427
1427
|
if (t.partialEvent) {
|
|
1428
|
-
const
|
|
1429
|
-
this.emitFirstToken(
|
|
1428
|
+
const u = t.partialEvent;
|
|
1429
|
+
this.emitFirstToken(u == null ? void 0 : u.iteractionId);
|
|
1430
1430
|
const h = new vt();
|
|
1431
|
-
if (h.author = "main", h.streamingParts = t.partialEvent.streamingParts, t.partialEvent.partialEventType ? h.eventType = t.partialEvent.partialEventType : h.eventType =
|
|
1431
|
+
if (h.author = "main", h.streamingParts = t.partialEvent.streamingParts, t.partialEvent.partialEventType ? h.eventType = t.partialEvent.partialEventType : h.eventType = u.functionName ? {
|
|
1432
1432
|
fullName: x.StreamingFunctionCallUpdateContent,
|
|
1433
1433
|
type: C.PartialFunctionCall
|
|
1434
|
-
} :
|
|
1434
|
+
} : u.partialReasoning ? {
|
|
1435
1435
|
fullName: x.StreamingReasoningContent,
|
|
1436
1436
|
type: C.Thought
|
|
1437
1437
|
} : {
|
|
1438
1438
|
fullName: x.StreamingTextContent,
|
|
1439
1439
|
type: C.Text
|
|
1440
|
-
}, h.interactionId = (
|
|
1440
|
+
}, h.interactionId = (u == null ? void 0 : u.iteractionId) ?? "", h.mimeType = "text/plain", h.partial = !0, h.eventType.type == C.PartialFunctionCall) {
|
|
1441
1441
|
var s = new Et();
|
|
1442
|
-
s.choiceIndex = 0, s.callId =
|
|
1442
|
+
s.choiceIndex = 0, s.callId = u.functionCallId, s.arguments = u.partialText, s.name = u.functionName, h.content = {
|
|
1443
1443
|
items: [s],
|
|
1444
1444
|
role: {
|
|
1445
1445
|
label: "Assistant"
|
|
@@ -1448,7 +1448,7 @@ const H = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
|
|
|
1448
1448
|
} else if (h.eventType.type == C.Text)
|
|
1449
1449
|
if (h.eventType.fullName == x.StreamingTextContent) {
|
|
1450
1450
|
var i = new Mt();
|
|
1451
|
-
i.text =
|
|
1451
|
+
i.text = u.partialText, h.content = {
|
|
1452
1452
|
items: [i],
|
|
1453
1453
|
role: {
|
|
1454
1454
|
label: "Assistant"
|
|
@@ -1456,7 +1456,7 @@ const H = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
|
|
|
1456
1456
|
};
|
|
1457
1457
|
} else {
|
|
1458
1458
|
var n = new Ot();
|
|
1459
|
-
n.text =
|
|
1459
|
+
n.text = u.partialText, h.content = {
|
|
1460
1460
|
items: [n],
|
|
1461
1461
|
role: {
|
|
1462
1462
|
label: "Assistant"
|
|
@@ -1465,7 +1465,7 @@ const H = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
|
|
|
1465
1465
|
}
|
|
1466
1466
|
else if (h.eventType.type == C.Thought) {
|
|
1467
1467
|
var r = new Dt();
|
|
1468
|
-
r.text =
|
|
1468
|
+
r.text = u.partialReasoning, h.content = {
|
|
1469
1469
|
items: [r],
|
|
1470
1470
|
role: {
|
|
1471
1471
|
label: "Assistant"
|
|
@@ -1475,9 +1475,9 @@ const H = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
|
|
|
1475
1475
|
t.event = void 0;
|
|
1476
1476
|
h.role = {
|
|
1477
1477
|
label: "Assistant"
|
|
1478
|
-
}, h.timestamp = (
|
|
1478
|
+
}, h.timestamp = (u == null ? void 0 : u.timeStamp) ?? (/* @__PURE__ */ new Date()).getTime(), h.turnComplete = !1, t.event = h, t.partialEvent = void 0;
|
|
1479
1479
|
}
|
|
1480
|
-
return t.event ? (t.subAgentId && (t.event.subAgentId = t.subAgentId, t.event.subAgentName = t.subAgentName), ((((o = (l = t.event.content) == null ? void 0 : l.items) == null ? void 0 : o.length) ?? 0) > 0 || (((
|
|
1480
|
+
return t.event ? (t.subAgentId && (t.event.subAgentId = t.subAgentId, t.event.subAgentName = t.subAgentName), ((((o = (l = t.event.content) == null ? void 0 : l.items) == null ? void 0 : o.length) ?? 0) > 0 || (((d = t.event.streamingParts) == null ? void 0 : d.length) ?? 0) > 0) && this.emitFirstToken(t.event.interactionId), this.handleEvent(t.event, e), t.event) : null;
|
|
1481
1481
|
}
|
|
1482
1482
|
emitFirstToken(t) {
|
|
1483
1483
|
var e;
|
|
@@ -1655,7 +1655,7 @@ const H = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
|
|
|
1655
1655
|
if (!i)
|
|
1656
1656
|
throw "Server event was null";
|
|
1657
1657
|
this.events.push([(/* @__PURE__ */ new Date()).getTime(), ((s = t.text) == null ? void 0 : s.length) ?? 0]), this.stats.eventCount += 1, this.stats.totalTransfered += e.length, i.session_information && !i.subAgentId && (this.stats.sessionInformation = i.session_information), this.stats.elapsed = (Date.now() - this.stats.startTime.getTime()) / 1e3;
|
|
1658
|
-
const n = Date.now() - lt * 1e3, l = this.events.filter((o) => o[0] > n).reduce((o,
|
|
1658
|
+
const n = Date.now() - lt * 1e3, l = this.events.filter((o) => o[0] > n).reduce((o, d) => o += d[1], 0) / xt;
|
|
1659
1659
|
this.stats.tokensPerSecond = l / lt, this.flushStatsCoalesced(), this.onEvent && this.onEvent(i).catch((o) => {
|
|
1660
1660
|
console.error("Lost error on on-event", o);
|
|
1661
1661
|
});
|
|
@@ -1667,8 +1667,8 @@ const H = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
|
|
|
1667
1667
|
g(Z, "WebSocketConnecionV2");
|
|
1668
1668
|
let ut = Z;
|
|
1669
1669
|
const Jt = "envision_agent_sessionId", V = class V extends G {
|
|
1670
|
-
constructor(e, s, i, n, r, l, o,
|
|
1671
|
-
super(e, s, i, n, r, l, o,
|
|
1670
|
+
constructor(e, s, i, n, r, l, o, d, u, h, v) {
|
|
1671
|
+
super(e, s, i, n, r, l, o, u, v);
|
|
1672
1672
|
a(this, "suspendState", !1);
|
|
1673
1673
|
a(this, "wsService");
|
|
1674
1674
|
a(this, "root_url", "");
|
|
@@ -1685,30 +1685,30 @@ const Jt = "envision_agent_sessionId", V = class V extends G {
|
|
|
1685
1685
|
a(this, "lastConnectionPromise", null);
|
|
1686
1686
|
a(this, "socketState", R.Disconnected);
|
|
1687
1687
|
a(this, "streamOpened", !1);
|
|
1688
|
-
this.hearBeatPort = h, this.root_url = this.base_url, this.wsService =
|
|
1689
|
-
await super.Message(
|
|
1690
|
-
}, this.wsService.onNewPacket = (
|
|
1691
|
-
this.sessionState.setStatistics(
|
|
1692
|
-
}, this.wsService.onPong = (
|
|
1693
|
-
}, this.wsService.onError = (
|
|
1688
|
+
this.hearBeatPort = h, this.root_url = this.base_url, this.wsService = d, this.wsService.onEvent = async (p) => {
|
|
1689
|
+
await super.Message(p);
|
|
1690
|
+
}, this.wsService.onNewPacket = (p) => {
|
|
1691
|
+
this.sessionState.setStatistics(p), this.eventBusService.streamEmitNewChunk(p);
|
|
1692
|
+
}, this.wsService.onPong = (p) => {
|
|
1693
|
+
}, this.wsService.onError = (p) => {
|
|
1694
1694
|
this.streamOpened = !1;
|
|
1695
1695
|
const D = {
|
|
1696
|
-
data: this.getErrorEvent(
|
|
1696
|
+
data: this.getErrorEvent(p),
|
|
1697
1697
|
lastEventId: (/* @__PURE__ */ new Date()).getTime().toString(),
|
|
1698
1698
|
origin: "gatewayService"
|
|
1699
1699
|
};
|
|
1700
|
-
console.error("Stream error:",
|
|
1700
|
+
console.error("Stream error:", p), this.everConnected && this.notificationPort.pushNotification({
|
|
1701
1701
|
message: "Reiniciando a conexão com o servidor",
|
|
1702
1702
|
type: "info"
|
|
1703
1703
|
}), super.Message(D);
|
|
1704
1704
|
}, this.wsService.onOpen = () => {
|
|
1705
1705
|
this.everConnected = !0, this.sessionState.setConnectionStatus(R.Connected);
|
|
1706
|
-
}, this.wsService.onReconnected = (
|
|
1706
|
+
}, this.wsService.onReconnected = (p) => {
|
|
1707
1707
|
this.sessionState.setConnectionStatus(R.Connected);
|
|
1708
|
-
}, this.wsService.onFirstToken = (
|
|
1709
|
-
this.localEmitFirstToken(
|
|
1710
|
-
}, this.wsService.onClose = (
|
|
1711
|
-
|
|
1708
|
+
}, this.wsService.onFirstToken = (p) => {
|
|
1709
|
+
this.localEmitFirstToken(p);
|
|
1710
|
+
}, this.wsService.onClose = (p, D) => {
|
|
1711
|
+
p != H && this.sessionState.setConnectionStatus(R.Disconnected);
|
|
1712
1712
|
};
|
|
1713
1713
|
}
|
|
1714
1714
|
reset(e, s) {
|
|
@@ -1747,13 +1747,13 @@ const Jt = "envision_agent_sessionId", V = class V extends G {
|
|
|
1747
1747
|
r = !0;
|
|
1748
1748
|
}, e.suspendStream();
|
|
1749
1749
|
try {
|
|
1750
|
-
let
|
|
1751
|
-
for (; !r &&
|
|
1752
|
-
await this.sleep(100),
|
|
1750
|
+
let d = 0;
|
|
1751
|
+
for (; !r && d < 5e3; )
|
|
1752
|
+
await this.sleep(100), d += 100;
|
|
1753
1753
|
if (r)
|
|
1754
1754
|
if (this.currentIS) {
|
|
1755
|
-
const
|
|
1756
|
-
|
|
1755
|
+
const u = this.currentIS.interaction;
|
|
1756
|
+
u.isSuspended = !0, this.sessionState.setCurrentMessage(u), this.sessionState.setTurnOpen(!1), i(!0);
|
|
1757
1757
|
} else
|
|
1758
1758
|
console.error("CurrentIS is null"), n("CurrentIS is null");
|
|
1759
1759
|
else
|
|
@@ -1763,9 +1763,17 @@ const Jt = "envision_agent_sessionId", V = class V extends G {
|
|
|
1763
1763
|
}
|
|
1764
1764
|
});
|
|
1765
1765
|
}
|
|
1766
|
-
/**
|
|
1766
|
+
/**
|
|
1767
|
+
* Forwards a parked-tool answer; 'queued' means the socket was down and it will flush on reconnect.
|
|
1768
|
+
*
|
|
1769
|
+
* Feature-detected rather than cast: a host may supply any `IWebSocketConnection` (the demo's fake
|
|
1770
|
+
* gateway does), and a hard cast turned "this transport doesn't deliver answers" into a TypeError
|
|
1771
|
+
* thrown from a click handler — with the answer lost either way.
|
|
1772
|
+
*/
|
|
1767
1773
|
answerHumanTool(e, s) {
|
|
1768
|
-
|
|
1774
|
+
var n;
|
|
1775
|
+
const i = (n = this.wsService.answerHumanTool) == null ? void 0 : n.bind(this.wsService);
|
|
1776
|
+
return i ? i(e, s) : (console.warn("[AgentGateway] transport cannot deliver parked-tool answers", e), "queued");
|
|
1769
1777
|
}
|
|
1770
1778
|
async cancelSuspend() {
|
|
1771
1779
|
var s;
|
|
@@ -1808,7 +1816,7 @@ const Jt = "envision_agent_sessionId", V = class V extends G {
|
|
|
1808
1816
|
}
|
|
1809
1817
|
// Send a message to the server via HTTP POST
|
|
1810
1818
|
async sendMessageInternal(e, s, i) {
|
|
1811
|
-
var l, o,
|
|
1819
|
+
var l, o, d, u, h, v, p, D;
|
|
1812
1820
|
const n = this.suspendState;
|
|
1813
1821
|
this.suspendState = !1;
|
|
1814
1822
|
const r = this.startInteraction(e.friendlyMessage ?? e.data, n);
|
|
@@ -1824,20 +1832,20 @@ const Jt = "envision_agent_sessionId", V = class V extends G {
|
|
|
1824
1832
|
Action: B.SendMessage,
|
|
1825
1833
|
ModelId: this.config.model,
|
|
1826
1834
|
InteractionId: r.interactionId,
|
|
1827
|
-
AgentId: (
|
|
1835
|
+
AgentId: (d = this.config.agentConfig) == null ? void 0 : d.id,
|
|
1828
1836
|
// Optional explicit C# class name on the server (e.g. "LlmAgentSessionReplay").
|
|
1829
1837
|
// When set, AgentBootStrapService.GetAgent dispatches to that class directly
|
|
1830
1838
|
// instead of looking up an Agent metadata row by AgentId. Plumbed through
|
|
1831
1839
|
// `agentContext.agentConfig.agentImplementation` so a host can run a turn
|
|
1832
1840
|
// against any registered LlmAgent variant without seeding a Mongo record.
|
|
1833
|
-
AgentImplementation: (
|
|
1841
|
+
AgentImplementation: (u = this.config.agentConfig) == null ? void 0 : u.agentImplementation,
|
|
1834
1842
|
Parameters: {
|
|
1835
1843
|
CustomerName: ((h = this.config.customer) == null ? void 0 : h.name) ?? "",
|
|
1836
1844
|
DataSet: ((v = this.config.customer) == null ? void 0 : v.dataSetId) ?? ""
|
|
1837
1845
|
},
|
|
1838
1846
|
// Forward image attachments as a structured payload (PascalCase
|
|
1839
1847
|
// keys to match the C# `Message.Images` / `MessageImage` model).
|
|
1840
|
-
Images: (
|
|
1848
|
+
Images: (p = e.images) != null && p.length ? e.images.map((y) => ({ MimeType: y.mimeType, Data: y.data })) : void 0,
|
|
1841
1849
|
// Client-only UI representation for this turn (PascalCase to match the C# `Message.UserUi`
|
|
1842
1850
|
// model). The server persists it as a UserUiContent sibling and strips it from the model
|
|
1843
1851
|
// request; Content remains the only model-facing text.
|
|
@@ -1918,4 +1926,4 @@ export {
|
|
|
1918
1926
|
dt as a,
|
|
1919
1927
|
te as u
|
|
1920
1928
|
};
|
|
1921
|
-
//# sourceMappingURL=httpArtifactService
|
|
1929
|
+
//# sourceMappingURL=httpArtifactService--6WV2FDW.js.map
|