@aintela/chat 0.2.34 → 0.2.37
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 +2292 -2274
- package/dist/components.js.map +1 -1
- package/dist/hooks.js +1 -1
- package/dist/{httpArtifactService-3J9rNvgw.js → httpArtifactService-BpRwcTJp.js} +134 -82
- package/dist/httpArtifactService-BpRwcTJp.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/services.js +1 -1
- package/dist/src/services/WebSocketConnection/WebSocketConnectionV2.d.ts +23 -2
- package/dist/src/services/WebSocketConnection/webSocketConnectionV2.test.d.ts +1 -0
- package/dist/src/services/servers/AgentGatewayService.d.ts +3 -2
- package/dist/src/services/servers/AgentGatewayWSAsync.d.ts +2 -1
- package/dist/useContainerWidth-CDv8UQyZ.js +309 -0
- package/dist/useContainerWidth-CDv8UQyZ.js.map +1 -0
- package/package.json +1 -1
- package/dist/httpArtifactService-3J9rNvgw.js.map +0 -1
- package/dist/useContainerWidth-Cs50UcTK.js +0 -309
- package/dist/useContainerWidth-Cs50UcTK.js.map +0 -1
package/dist/hooks.js
CHANGED
|
@@ -2,14 +2,14 @@ var nt = Object.defineProperty;
|
|
|
2
2
|
var gt = (O, t, e) => t in O ? nt(O, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : O[t] = e;
|
|
3
3
|
var f = (O, t) => nt(O, "name", { value: t, configurable: !0 });
|
|
4
4
|
var a = (O, t, e) => gt(O, typeof t != "symbol" ? t + "" : t, e);
|
|
5
|
-
import { d as L, t as
|
|
5
|
+
import { d as L, t as pt, E as I, k as mt, j as St, q as wt, C as B } from "./environmentUtils-CUVZ6Dq1.js";
|
|
6
6
|
import { I as _, S as ut, g as yt, L as Tt, P as x, b as It, e as Ct, T as vt, c as Et } from "./serializer-uea8YsIP.js";
|
|
7
7
|
import { unified as Mt } from "unified";
|
|
8
8
|
import Ot from "remark-parse";
|
|
9
9
|
import { toMarkdown as Dt } from "mdast-util-to-markdown";
|
|
10
10
|
import { format as At } from "date-fns";
|
|
11
11
|
import Nt from "lodash";
|
|
12
|
-
import { P as
|
|
12
|
+
import { P as kt, C as R } from "./Prompt-DZb7OaPp.js";
|
|
13
13
|
const w = {
|
|
14
14
|
ARTIFACTS: "envision-artifacts",
|
|
15
15
|
SECTIONS: "envision-sections",
|
|
@@ -231,8 +231,8 @@ const Yt = /* @__PURE__ */ f((O) => {
|
|
|
231
231
|
}
|
|
232
232
|
};
|
|
233
233
|
f(z, "EventTypes");
|
|
234
|
-
let
|
|
235
|
-
const c = new
|
|
234
|
+
let q = z;
|
|
235
|
+
const c = new q(), Y = class Y {
|
|
236
236
|
constructor() {
|
|
237
237
|
a(this, "listeners", {});
|
|
238
238
|
a(this, "listenersCount", {});
|
|
@@ -484,8 +484,8 @@ const c = new J(), Y = class Y {
|
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
486
|
f(Y, "EventBusService");
|
|
487
|
-
let
|
|
488
|
-
const j = class j extends
|
|
487
|
+
let J = Y;
|
|
488
|
+
const j = class j extends J {
|
|
489
489
|
constructor() {
|
|
490
490
|
super();
|
|
491
491
|
}
|
|
@@ -493,7 +493,7 @@ const j = class j extends q {
|
|
|
493
493
|
console.log("MockEventBusService.gatewayEmitConnectionStateChange");
|
|
494
494
|
}
|
|
495
495
|
gatewayEmitMessage(t, e) {
|
|
496
|
-
|
|
496
|
+
pt() ? process.stdout.write(`M${t.version}, `) : console.log("MockEventBusService.gatewayEmitMessage");
|
|
497
497
|
}
|
|
498
498
|
gatewayEmitTurnComplete(t, e) {
|
|
499
499
|
console.log("MockEventBusService.gatewayEmitTurnComplete");
|
|
@@ -526,7 +526,7 @@ const dt = {
|
|
|
526
526
|
}
|
|
527
527
|
};
|
|
528
528
|
f(Q, "InteractionPartGroup");
|
|
529
|
-
let
|
|
529
|
+
let W = Q;
|
|
530
530
|
const X = class X {
|
|
531
531
|
constructor(t, e) {
|
|
532
532
|
a(this, "interaction");
|
|
@@ -557,11 +557,11 @@ ${n.value}
|
|
|
557
557
|
groupPartsByDisplayType(t, e = !0, s = !1) {
|
|
558
558
|
var l;
|
|
559
559
|
const i = [];
|
|
560
|
-
let n = new
|
|
560
|
+
let n = new W();
|
|
561
561
|
for (let o = 0; o < t.length; o++) {
|
|
562
562
|
const u = t[o];
|
|
563
563
|
let h = !(((l = u.functionDetails) == null ? void 0 : l.isUi) ?? !1) && u.eventType !== I.Text && u.eventType !== I.Thought && (u.eventType === I.FunctionCall || u.eventType === I.PartialFunctionCall || u.eventType === I.FunctionResponse) && o < t.length - 1;
|
|
564
|
-
!e && h && !s || (h ? (u.eventType == I.Thought && (n.hasThoughts = !0), n.parts.push(u), n.isLastGroup = o === t.length - 1) : (n.parts.length > 0 && (i.push(n), n = new
|
|
564
|
+
!e && h && !s || (h ? (u.eventType == I.Thought && (n.hasThoughts = !0), n.parts.push(u), n.isLastGroup = o === t.length - 1) : (n.parts.length > 0 && (i.push(n), n = new W()), i.push({
|
|
565
565
|
type: dt.block,
|
|
566
566
|
parts: [u],
|
|
567
567
|
isLastGroup: o === t.length - 1,
|
|
@@ -595,21 +595,21 @@ ${n.value}
|
|
|
595
595
|
}, "cloneFunctionMap"), v = /* @__PURE__ */ f(() => {
|
|
596
596
|
o === e.parts && (o = e.parts.slice());
|
|
597
597
|
}, "clonePartsIfShared");
|
|
598
|
-
let
|
|
598
|
+
let m = !1;
|
|
599
599
|
if ((n == null ? void 0 : n.eventType) === I.FunctionClientOutput && !!((A = n.functionDetails) != null && A.id) && n) {
|
|
600
600
|
const g = n.functionDetails.id, C = n.functionDetails.clientOutput, E = o.findIndex((S) => {
|
|
601
|
-
var
|
|
602
|
-
return ((
|
|
601
|
+
var p;
|
|
602
|
+
return ((p = S.functionDetails) == null ? void 0 : p.id) === g;
|
|
603
603
|
});
|
|
604
604
|
if (E > -1) {
|
|
605
|
-
const S = o[E],
|
|
605
|
+
const S = o[E], p = {
|
|
606
606
|
...S,
|
|
607
607
|
functionDetails: {
|
|
608
608
|
...S.functionDetails,
|
|
609
609
|
clientOutput: C ?? S.functionDetails.clientOutput
|
|
610
610
|
}
|
|
611
611
|
};
|
|
612
|
-
v(), o[E] =
|
|
612
|
+
v(), o[E] = p, h(), u.set(g, p), s.push(p);
|
|
613
613
|
} else {
|
|
614
614
|
const S = {
|
|
615
615
|
...n,
|
|
@@ -626,12 +626,12 @@ ${n.value}
|
|
|
626
626
|
const S = o.findIndex((ft) => {
|
|
627
627
|
var st;
|
|
628
628
|
return ((st = ft.functionDetails) == null ? void 0 : st.id) === C;
|
|
629
|
-
}),
|
|
630
|
-
...
|
|
629
|
+
}), p = S > -1 ? o[S] : E, F = {
|
|
630
|
+
...p,
|
|
631
631
|
eventType: n.eventType,
|
|
632
632
|
functionDetails: {
|
|
633
|
-
id:
|
|
634
|
-
name: n.functionDetails.name ??
|
|
633
|
+
id: p.functionDetails.id,
|
|
634
|
+
name: n.functionDetails.name ?? p.functionDetails.name,
|
|
635
635
|
// Take the parsed args from the incoming event when
|
|
636
636
|
// present (the full FunctionCall carries them), fall
|
|
637
637
|
// back to what was already on the part. Previously
|
|
@@ -640,41 +640,41 @@ ${n.value}
|
|
|
640
640
|
// args off every full FunctionCall fold because the
|
|
641
641
|
// PartialFunctionCall stream only accumulates raw
|
|
642
642
|
// JSON in `.text` — `.args` stayed undefined.
|
|
643
|
-
args: n.functionDetails.args ??
|
|
643
|
+
args: n.functionDetails.args ?? p.functionDetails.args,
|
|
644
644
|
response: n.functionDetails.response,
|
|
645
645
|
status: n.functionDetails.status ?? "Composing",
|
|
646
|
-
start: n.functionDetails.start ??
|
|
647
|
-
end: n.functionDetails.end ??
|
|
646
|
+
start: n.functionDetails.start ?? p.functionDetails.start,
|
|
647
|
+
end: n.functionDetails.end ?? p.functionDetails.end,
|
|
648
648
|
// true-wins: a UI call has multiple reps (streaming part with isUi, the
|
|
649
649
|
// persisted FunctionCall, the result) and they interleave. `??` let a later
|
|
650
650
|
// `false`/`undefined` rep clobber an earlier `true`; OR-ing keeps it sticky.
|
|
651
|
-
isUi: n.functionDetails.isUi === !0 ||
|
|
651
|
+
isUi: n.functionDetails.isUi === !0 || p.functionDetails.isUi === !0,
|
|
652
652
|
// Keep the call's friendly args summary when the result event (which has none) folds in.
|
|
653
|
-
argsDescription: n.functionDetails.argsDescription ??
|
|
653
|
+
argsDescription: n.functionDetails.argsDescription ?? p.functionDetails.argsDescription,
|
|
654
654
|
// The tool's client-only payload rides the RESULT event; keep it sticky so a
|
|
655
655
|
// later rep without one can't clobber it. This is what a uiTool renderer reads.
|
|
656
|
-
clientOutput: n.functionDetails.clientOutput ??
|
|
656
|
+
clientOutput: n.functionDetails.clientOutput ?? p.functionDetails.clientOutput,
|
|
657
657
|
// Ask-user component ([KernelUIComponent]) — sticky like isUi/clientOutput. The
|
|
658
658
|
// streaming final CALL carries it, but the PartialFunctionCall it folds onto (and a
|
|
659
659
|
// later result rep) may not; dropping it strips the part's askUser classification so
|
|
660
660
|
// the docked drawer never surfaces (issue #60 — esp. a no-arg tool like update_profile,
|
|
661
661
|
// which has no name match to fall back on the way ask_user/askauth do).
|
|
662
|
-
askUserComponent: n.functionDetails.askUserComponent ??
|
|
663
|
-
isAskUser: n.functionDetails.isAskUser ||
|
|
662
|
+
askUserComponent: n.functionDetails.askUserComponent ?? p.functionDetails.askUserComponent,
|
|
663
|
+
isAskUser: n.functionDetails.isAskUser || p.functionDetails.isAskUser || !!(n.functionDetails.askUserComponent ?? p.functionDetails.askUserComponent),
|
|
664
664
|
// Runtime "don't render" override rides the RESULT; true-wins sticky like isUi so it
|
|
665
665
|
// survives folding onto the earlier call rep and suppresses drawer/uiTool classification.
|
|
666
|
-
cancelUi: n.functionDetails.cancelUi === !0 ||
|
|
666
|
+
cancelUi: n.functionDetails.cancelUi === !0 || p.functionDetails.cancelUi === !0
|
|
667
667
|
}
|
|
668
668
|
};
|
|
669
669
|
h(), u.set(C, F), F.eventType === I.FunctionResponse && this.eventBusService.gatewayEmitFunctionResponse(F.functionDetails), s.push(F), S > -1 && (v(), o[S] = F);
|
|
670
670
|
} else {
|
|
671
671
|
if (C && n.functionDetails && !E && (h(), u.set(C, n)), r && r.textAppendable) {
|
|
672
|
-
const
|
|
672
|
+
const p = {
|
|
673
673
|
...r,
|
|
674
674
|
ended: /* @__PURE__ */ new Date(),
|
|
675
675
|
isStillWriting: !1
|
|
676
676
|
};
|
|
677
|
-
v(), o[o.length - 1] =
|
|
677
|
+
v(), o[o.length - 1] = p, s.push(p);
|
|
678
678
|
}
|
|
679
679
|
const S = {
|
|
680
680
|
...n,
|
|
@@ -682,7 +682,7 @@ ${n.value}
|
|
|
682
682
|
isStillWriting: n.textAppendable,
|
|
683
683
|
partial: t.partial
|
|
684
684
|
};
|
|
685
|
-
(et = S.functionDetails) != null && et.silent || s.push(S), o = [...o, S],
|
|
685
|
+
(et = S.functionDetails) != null && et.silent || s.push(S), o = [...o, S], m = !0;
|
|
686
686
|
}
|
|
687
687
|
}
|
|
688
688
|
let y = o[o.length - 1] ?? null;
|
|
@@ -695,7 +695,7 @@ ${n.value}
|
|
|
695
695
|
let C = !1;
|
|
696
696
|
if (t.partial) {
|
|
697
697
|
try {
|
|
698
|
-
g.textDetails.version++,
|
|
698
|
+
g.textDetails.version++, m || (g.text = (y.text ?? "") + (n.text ?? ""));
|
|
699
699
|
} catch (E) {
|
|
700
700
|
console.error("Error here", E.toString());
|
|
701
701
|
}
|
|
@@ -716,11 +716,11 @@ ${n.value}
|
|
|
716
716
|
for (const C of t.llmArtifacts) {
|
|
717
717
|
const E = C.toArtifact();
|
|
718
718
|
g || (M = M.slice(), g = !0);
|
|
719
|
-
const S = M.findIndex((
|
|
719
|
+
const S = M.findIndex((p) => p.id === E.id);
|
|
720
720
|
S === -1 ? M.push(E) : M[S] = E;
|
|
721
721
|
}
|
|
722
722
|
}
|
|
723
|
-
const
|
|
723
|
+
const P = {
|
|
724
724
|
...e,
|
|
725
725
|
version: e.version + 1,
|
|
726
726
|
parts: o,
|
|
@@ -730,11 +730,11 @@ ${n.value}
|
|
|
730
730
|
partial: t.partial,
|
|
731
731
|
asyncFinalResponse: t.asyncFinalResponse
|
|
732
732
|
};
|
|
733
|
-
return this.interaction =
|
|
734
|
-
updatedInteraction:
|
|
733
|
+
return this.interaction = P, {
|
|
734
|
+
updatedInteraction: P,
|
|
735
735
|
updatedParts: s,
|
|
736
736
|
newArtifacts: i,
|
|
737
|
-
mainBranch:
|
|
737
|
+
mainBranch: P,
|
|
738
738
|
analyticsBranch: null,
|
|
739
739
|
analyticsBranchPartsChanged: null,
|
|
740
740
|
mainBranchPartsChanged: s
|
|
@@ -742,10 +742,10 @@ ${n.value}
|
|
|
742
742
|
}
|
|
743
743
|
};
|
|
744
744
|
f(X, "InteractionService");
|
|
745
|
-
let
|
|
746
|
-
const
|
|
745
|
+
let $ = X;
|
|
746
|
+
const Pt = 1200 * 1e3, k = class k {
|
|
747
747
|
constructor(t, e, s, i, n, r, l, o, u, d = St.Interactive) {
|
|
748
|
-
a(this, "base_production_url",
|
|
748
|
+
a(this, "base_production_url", mt() ?? "https://agent.tripapi.com.br");
|
|
749
749
|
a(this, "base_url_local", "http://localagent:8000");
|
|
750
750
|
a(this, "base_url");
|
|
751
751
|
a(this, "isLocal", !1);
|
|
@@ -833,10 +833,11 @@ const kt = 1200 * 1e3, P = class P {
|
|
|
833
833
|
/**
|
|
834
834
|
* Send the user's answer to a parked `ask_user` tool call back to the agent.
|
|
835
835
|
* Default no-op; the WebSocket gateway (AgentGatewayWSAsync) overrides it to emit
|
|
836
|
-
* a ChatAction.AnswerHumanTool frame.
|
|
836
|
+
* a ChatAction.AnswerHumanTool frame. Returns 'sent' when it went out immediately,
|
|
837
|
+
* 'queued' when the socket was down and the answer will flush on reconnect.
|
|
837
838
|
*/
|
|
838
839
|
answerHumanTool(t, e) {
|
|
839
|
-
console.warn("answerHumanTool: not supported by this gateway", t, e);
|
|
840
|
+
return console.warn("answerHumanTool: not supported by this gateway", t, e), "queued";
|
|
840
841
|
}
|
|
841
842
|
getAgentContext() {
|
|
842
843
|
return this.config;
|
|
@@ -905,7 +906,7 @@ const kt = 1200 * 1e3, P = class P {
|
|
|
905
906
|
functionMap: /* @__PURE__ */ new Map(),
|
|
906
907
|
interactionQuestion: t
|
|
907
908
|
};
|
|
908
|
-
return this.interactionsMap.set(n.interactionId, n), this.currentIS = new
|
|
909
|
+
return this.interactionsMap.set(n.interactionId, n), this.currentIS = new $(n, this.eventBusService), this.interactionsServiceMap.set(n.interactionId, this.currentIS), n;
|
|
909
910
|
}
|
|
910
911
|
getInteractions() {
|
|
911
912
|
return Array.from(this.interactionsMap.values());
|
|
@@ -981,7 +982,7 @@ const kt = 1200 * 1e3, P = class P {
|
|
|
981
982
|
version: 0,
|
|
982
983
|
functionMap: /* @__PURE__ */ new Map(),
|
|
983
984
|
interactionQuestion: s ?? t
|
|
984
|
-
}, n = new
|
|
985
|
+
}, n = new $(i, this.eventBusService), this.subAgentInteractions.set(t, i), this.subAgentInteractionServices.set(t, n)), { interaction: i, service: n };
|
|
985
986
|
}
|
|
986
987
|
handleSubAgentEvent(t) {
|
|
987
988
|
const e = t.subAgentId, { service: s } = this.getOrCreateSubAgentInteraction(e, t.interactionId, t.subAgentName);
|
|
@@ -1071,10 +1072,10 @@ const kt = 1200 * 1e3, P = class P {
|
|
|
1071
1072
|
}
|
|
1072
1073
|
localEmitMessage(t, e) {
|
|
1073
1074
|
const s = (/* @__PURE__ */ new Date()).getTime(), i = s - this.lastCurrentMessageUpdate;
|
|
1074
|
-
t.partial === !1 || i >=
|
|
1075
|
+
t.partial === !1 || i >= k.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(() => {
|
|
1075
1076
|
var r, l;
|
|
1076
1077
|
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);
|
|
1077
|
-
},
|
|
1078
|
+
}, k.CURRENT_MSG_THROTTLE_MS * 2));
|
|
1078
1079
|
}
|
|
1079
1080
|
localOpen(t, e) {
|
|
1080
1081
|
this.sessionState.setTurnOpen(!0), this.eventBusService.gatewayEmitTurnOpen(t ?? "");
|
|
@@ -1102,7 +1103,7 @@ const kt = 1200 * 1e3, P = class P {
|
|
|
1102
1103
|
}), this.sessionState.setTurnOpen(!1);
|
|
1103
1104
|
}
|
|
1104
1105
|
async handlePing() {
|
|
1105
|
-
return Date.now() - this.lastPing.getTime() >
|
|
1106
|
+
return Date.now() - this.lastPing.getTime() > Pt ? await this.ping() ? (this.lastPing = /* @__PURE__ */ new Date(), this.lastPingStatus = !0, !0) : (this.lastPingStatus = !1, !1) : (this.lastPingStatus = !0, !0);
|
|
1106
1107
|
}
|
|
1107
1108
|
async sendMessage(t, e) {
|
|
1108
1109
|
let s = this.getInteractions().length, i = _.createWaiting(!0, !0, "Overall", /* @__PURE__ */ new Date());
|
|
@@ -1110,7 +1111,7 @@ const kt = 1200 * 1e3, P = class P {
|
|
|
1110
1111
|
try {
|
|
1111
1112
|
const { promptAsString: n, json: r } = this.sessionState.onRenderPrompt ? this.sessionState.onRenderPrompt(t.data) : { promptAsString: t.data, json: void 0 };
|
|
1112
1113
|
this.sessionState.onRenderPrompt && (t.data = r, t.friendlyMessage = n);
|
|
1113
|
-
const l = await this.sendMessageInternal(t, e), o =
|
|
1114
|
+
const l = await this.sendMessageInternal(t, e), o = kt.createPrompt(n ?? "", (r == null ? void 0 : r.toString()) ?? {});
|
|
1114
1115
|
this.storageService.storePrompt(o);
|
|
1115
1116
|
const u = _.fromText("Planejando próximos passos");
|
|
1116
1117
|
return this.sendStatusMessage(t.data, [i, u], s.toString() + "1"), l != null && l.success ? this.eventBusService.ChatEmitMessageSent(t.data, l.interaction) : this.eventBusService.ChatEmitMessageError((l == null ? void 0 : l.error) ?? ""), l;
|
|
@@ -1168,8 +1169,8 @@ const kt = 1200 * 1e3, P = class P {
|
|
|
1168
1169
|
return `${this.msg_order}_${e}`;
|
|
1169
1170
|
}
|
|
1170
1171
|
};
|
|
1171
|
-
f(
|
|
1172
|
-
let G =
|
|
1172
|
+
f(k, "AgentGatewayService"), a(k, "SUSPENSION_MSG", "SUSPEND"), a(k, "CURRENT_MSG_THROTTLE_MS", 20);
|
|
1173
|
+
let G = k;
|
|
1173
1174
|
const H = 4001, _t = 4002, rt = 4, bt = 3, Ft = 500, Rt = 3e4, Ut = 2, Lt = 0.2, ot = 2, Z = class Z {
|
|
1174
1175
|
constructor(t = "ws://localhost:8000", e) {
|
|
1175
1176
|
a(this, "ws", null);
|
|
@@ -1238,6 +1239,15 @@ const H = 4001, _t = 4002, rt = 4, bt = 3, Ft = 500, Rt = 3e4, Ut = 2, Lt = 0.2,
|
|
|
1238
1239
|
* seen any sequenced events yet" (fresh connection).
|
|
1239
1240
|
*/
|
|
1240
1241
|
a(this, "lastSeq", -1);
|
|
1242
|
+
/**
|
|
1243
|
+
* Parked-tool answers that could not be sent because the socket was not OPEN
|
|
1244
|
+
* (e.g. the connection idled out while the user was in an IdP sign-in popup).
|
|
1245
|
+
* Keyed per tool call (last answer wins) and stamped with the session they
|
|
1246
|
+
* belong to; flushed by `onopen` when the socket resumes THAT session. An
|
|
1247
|
+
* answer for a session this instance is no longer attached to is dropped —
|
|
1248
|
+
* the single-attach policy makes it undeliverable from here anyway.
|
|
1249
|
+
*/
|
|
1250
|
+
a(this, "pendingAnswers", []);
|
|
1241
1251
|
/**
|
|
1242
1252
|
* True once *any* socket on this instance has received at least one packet.
|
|
1243
1253
|
* Used by `onclose` to distinguish a real mid-stream drop (we had a working
|
|
@@ -1287,7 +1297,7 @@ const H = 4001, _t = 4002, rt = 4, bt = 3, Ft = 500, Rt = 3e4, Ut = 2, Lt = 0.2,
|
|
|
1287
1297
|
this.ws.onopen = () => {
|
|
1288
1298
|
console.log("[WebSocket] Connected");
|
|
1289
1299
|
const T = this.isReconnecting;
|
|
1290
|
-
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 ?? "");
|
|
1300
|
+
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);
|
|
1291
1301
|
}, this.ws.onmessage = (T) => {
|
|
1292
1302
|
try {
|
|
1293
1303
|
this.lastActivity = (/* @__PURE__ */ new Date()).getTime();
|
|
@@ -1310,9 +1320,9 @@ const H = 4001, _t = 4002, rt = 4, bt = 3, Ft = 500, Rt = 3e4, Ut = 2, Lt = 0.2,
|
|
|
1310
1320
|
}
|
|
1311
1321
|
this.isReconnecting = !1, this.reconnectAttempts = 0, this.onClose && this.onClose(T.code, T.reason);
|
|
1312
1322
|
};
|
|
1313
|
-
const v = 200,
|
|
1323
|
+
const v = 200, m = 3e4, D = 8e3, y = this.ws;
|
|
1314
1324
|
this.sessionId = void 0;
|
|
1315
|
-
let M = 0,
|
|
1325
|
+
let M = 0, P = 0;
|
|
1316
1326
|
for (; !this.sessionId; ) {
|
|
1317
1327
|
if (this.ws !== y) {
|
|
1318
1328
|
s("Connection attempt superseded by a newer connect()");
|
|
@@ -1322,19 +1332,19 @@ const H = 4001, _t = 4002, rt = 4, bt = 3, Ft = 500, Rt = 3e4, Ut = 2, Lt = 0.2,
|
|
|
1322
1332
|
s("Connection closed before a session id was received");
|
|
1323
1333
|
return;
|
|
1324
1334
|
}
|
|
1325
|
-
if (y.readyState === WebSocket.CONNECTING && M >=
|
|
1335
|
+
if (y.readyState === WebSocket.CONNECTING && M >= m) {
|
|
1326
1336
|
try {
|
|
1327
1337
|
y.close();
|
|
1328
1338
|
} catch {
|
|
1329
1339
|
}
|
|
1330
|
-
s(`Server did not accept the connection within ${
|
|
1340
|
+
s(`Server did not accept the connection within ${m / 1e3}s`);
|
|
1331
1341
|
return;
|
|
1332
1342
|
}
|
|
1333
|
-
if (y.readyState === WebSocket.OPEN &&
|
|
1343
|
+
if (y.readyState === WebSocket.OPEN && P >= D) {
|
|
1334
1344
|
s(`Connected but no session id arrived within ${D / 1e3}s`);
|
|
1335
1345
|
return;
|
|
1336
1346
|
}
|
|
1337
|
-
M % 2e3 === 0 && console.log("Aguardando session Id"), await this.sleep(v), M += v, y.readyState === WebSocket.OPEN && (
|
|
1347
|
+
M % 2e3 === 0 && console.log("Aguardando session Id"), await this.sleep(v), M += v, y.readyState === WebSocket.OPEN && (P += v);
|
|
1338
1348
|
}
|
|
1339
1349
|
console.log("SUCCESS - GOT SESSION ID", this.sessionId), this.lastKnownSessionId = this.sessionId, e(this.sessionId);
|
|
1340
1350
|
});
|
|
@@ -1510,21 +1520,62 @@ const H = 4001, _t = 4002, rt = 4, bt = 3, Ft = 500, Rt = 3e4, Ut = 2, Lt = 0.2,
|
|
|
1510
1520
|
}
|
|
1511
1521
|
suspendStream() {
|
|
1512
1522
|
this.sendBaseMessage({
|
|
1513
|
-
Action:
|
|
1523
|
+
Action: B.Suspend,
|
|
1514
1524
|
AgentId: "",
|
|
1515
1525
|
InteractionId: "",
|
|
1516
1526
|
ModelId: ""
|
|
1517
1527
|
});
|
|
1518
1528
|
}
|
|
1519
|
-
/**
|
|
1529
|
+
/**
|
|
1530
|
+
* Send the user's answer to a parked ask_user tool call (ChatAction.AnswerHumanTool).
|
|
1531
|
+
*
|
|
1532
|
+
* Never throws on a dead socket: the parked tool answer is the one message whose loss
|
|
1533
|
+
* strands the whole turn (the askauth popup case — the socket idles out while the user
|
|
1534
|
+
* is at the IdP, the token comes back, and a plain send would throw into an unhandled
|
|
1535
|
+
* rejection with the answer gone). When the socket is not OPEN the answer is queued and
|
|
1536
|
+
* flushed by `onopen` on the next (re)connect of the same session.
|
|
1537
|
+
*
|
|
1538
|
+
* Returns 'sent' when it went out now, 'queued' when it will go out on reconnect.
|
|
1539
|
+
*/
|
|
1520
1540
|
answerHumanTool(t, e) {
|
|
1521
|
-
|
|
1522
|
-
Action:
|
|
1541
|
+
const s = {
|
|
1542
|
+
Action: B.AnswerHumanTool,
|
|
1523
1543
|
AgentId: "",
|
|
1524
1544
|
InteractionId: "",
|
|
1525
1545
|
ToolCallId: t,
|
|
1526
1546
|
Answer: e
|
|
1527
|
-
}
|
|
1547
|
+
};
|
|
1548
|
+
if (this.ws && this.ws.readyState === WebSocket.OPEN)
|
|
1549
|
+
try {
|
|
1550
|
+
return this.sendBaseMessage(s), "sent";
|
|
1551
|
+
} catch {
|
|
1552
|
+
}
|
|
1553
|
+
return this.queueAnswer(t, e), "queued";
|
|
1554
|
+
}
|
|
1555
|
+
queueAnswer(t, e) {
|
|
1556
|
+
this.pendingAnswers = this.pendingAnswers.filter((s) => s.toolCallId !== t), this.pendingAnswers.push({ sessionId: this.sessionId ?? this.lastKnownSessionId, toolCallId: t, answer: e }), console.warn(`[WebSocket] Socket not open — queued answer for tool call ${t}; will flush on reconnect.`);
|
|
1557
|
+
}
|
|
1558
|
+
flushPendingAnswers(t) {
|
|
1559
|
+
if (this.pendingAnswers.length === 0) return;
|
|
1560
|
+
const e = this.pendingAnswers;
|
|
1561
|
+
this.pendingAnswers = [];
|
|
1562
|
+
for (const s of e) {
|
|
1563
|
+
if (s.sessionId && t && s.sessionId !== t) {
|
|
1564
|
+
console.warn(`[WebSocket] Dropping queued answer for tool call ${s.toolCallId} — it belongs to session ${s.sessionId}, reconnected to ${t}.`);
|
|
1565
|
+
continue;
|
|
1566
|
+
}
|
|
1567
|
+
try {
|
|
1568
|
+
this.sendBaseMessage({
|
|
1569
|
+
Action: B.AnswerHumanTool,
|
|
1570
|
+
AgentId: "",
|
|
1571
|
+
InteractionId: "",
|
|
1572
|
+
ToolCallId: s.toolCallId,
|
|
1573
|
+
Answer: s.answer
|
|
1574
|
+
}), console.info(`[WebSocket] Flushed queued answer for tool call ${s.toolCallId}.`);
|
|
1575
|
+
} catch {
|
|
1576
|
+
this.pendingAnswers.push(s);
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1528
1579
|
}
|
|
1529
1580
|
/**
|
|
1530
1581
|
* Send a message to the agent
|
|
@@ -1629,30 +1680,30 @@ const xt = "envision_agent_sessionId", V = class V extends G {
|
|
|
1629
1680
|
a(this, "lastConnectionPromise", null);
|
|
1630
1681
|
a(this, "socketState", R.Disconnected);
|
|
1631
1682
|
a(this, "streamOpened", !1);
|
|
1632
|
-
this.hearBeatPort = h, this.root_url = this.base_url, this.wsService = u, this.wsService.onEvent = async (
|
|
1633
|
-
await super.Message(
|
|
1634
|
-
}, this.wsService.onNewPacket = (
|
|
1635
|
-
this.sessionState.setStatistics(
|
|
1636
|
-
}, this.wsService.onPong = (
|
|
1637
|
-
}, this.wsService.onError = (
|
|
1683
|
+
this.hearBeatPort = h, this.root_url = this.base_url, this.wsService = u, this.wsService.onEvent = async (m) => {
|
|
1684
|
+
await super.Message(m);
|
|
1685
|
+
}, this.wsService.onNewPacket = (m) => {
|
|
1686
|
+
this.sessionState.setStatistics(m), this.eventBusService.streamEmitNewChunk(m);
|
|
1687
|
+
}, this.wsService.onPong = (m) => {
|
|
1688
|
+
}, this.wsService.onError = (m) => {
|
|
1638
1689
|
this.streamOpened = !1;
|
|
1639
1690
|
const D = {
|
|
1640
|
-
data: this.getErrorEvent(
|
|
1691
|
+
data: this.getErrorEvent(m),
|
|
1641
1692
|
lastEventId: (/* @__PURE__ */ new Date()).getTime().toString(),
|
|
1642
1693
|
origin: "gatewayService"
|
|
1643
1694
|
};
|
|
1644
|
-
console.error("Stream error:",
|
|
1695
|
+
console.error("Stream error:", m), this.everConnected && this.notificationPort.pushNotification({
|
|
1645
1696
|
message: "Reiniciando a conexão com o servidor",
|
|
1646
1697
|
type: "info"
|
|
1647
1698
|
}), super.Message(D);
|
|
1648
1699
|
}, this.wsService.onOpen = () => {
|
|
1649
1700
|
this.everConnected = !0, this.sessionState.setConnectionStatus(R.Connected);
|
|
1650
|
-
}, this.wsService.onReconnected = (
|
|
1701
|
+
}, this.wsService.onReconnected = (m) => {
|
|
1651
1702
|
this.sessionState.setConnectionStatus(R.Connected);
|
|
1652
|
-
}, this.wsService.onFirstToken = (
|
|
1653
|
-
this.localEmitFirstToken(
|
|
1654
|
-
}, this.wsService.onClose = (
|
|
1655
|
-
|
|
1703
|
+
}, this.wsService.onFirstToken = (m) => {
|
|
1704
|
+
this.localEmitFirstToken(m);
|
|
1705
|
+
}, this.wsService.onClose = (m, D) => {
|
|
1706
|
+
m != H && this.sessionState.setConnectionStatus(R.Disconnected);
|
|
1656
1707
|
};
|
|
1657
1708
|
}
|
|
1658
1709
|
reset(e, s) {
|
|
@@ -1707,8 +1758,9 @@ const xt = "envision_agent_sessionId", V = class V extends G {
|
|
|
1707
1758
|
}
|
|
1708
1759
|
});
|
|
1709
1760
|
}
|
|
1761
|
+
/** Forwards a parked-tool answer; 'queued' means the socket was down and it will flush on reconnect. */
|
|
1710
1762
|
answerHumanTool(e, s) {
|
|
1711
|
-
this.wsService.answerHumanTool(e, s);
|
|
1763
|
+
return this.wsService.answerHumanTool(e, s);
|
|
1712
1764
|
}
|
|
1713
1765
|
async cancelSuspend() {
|
|
1714
1766
|
var s;
|
|
@@ -1751,7 +1803,7 @@ const xt = "envision_agent_sessionId", V = class V extends G {
|
|
|
1751
1803
|
}
|
|
1752
1804
|
// Send a message to the server via HTTP POST
|
|
1753
1805
|
async sendMessageInternal(e, s, i) {
|
|
1754
|
-
var l, o, u, d, h, v,
|
|
1806
|
+
var l, o, u, d, h, v, m, D;
|
|
1755
1807
|
const n = this.suspendState;
|
|
1756
1808
|
this.suspendState = !1;
|
|
1757
1809
|
const r = this.startInteraction(e.friendlyMessage ?? e.data, n);
|
|
@@ -1764,7 +1816,7 @@ const xt = "envision_agent_sessionId", V = class V extends G {
|
|
|
1764
1816
|
return this.wsService.sendMessage({
|
|
1765
1817
|
Content: e.data,
|
|
1766
1818
|
SessionId: this.sessionId,
|
|
1767
|
-
Action:
|
|
1819
|
+
Action: B.SendMessage,
|
|
1768
1820
|
ModelId: this.config.model,
|
|
1769
1821
|
InteractionId: r.interactionId,
|
|
1770
1822
|
AgentId: (u = this.config.agentConfig) == null ? void 0 : u.id,
|
|
@@ -1780,7 +1832,7 @@ const xt = "envision_agent_sessionId", V = class V extends G {
|
|
|
1780
1832
|
},
|
|
1781
1833
|
// Forward image attachments as a structured payload (PascalCase
|
|
1782
1834
|
// keys to match the C# `Message.Images` / `MessageImage` model).
|
|
1783
|
-
Images: (
|
|
1835
|
+
Images: (m = e.images) != null && m.length ? e.images.map((y) => ({ MimeType: y.mimeType, Data: y.data })) : void 0,
|
|
1784
1836
|
// Client-only UI representation for this turn (PascalCase to match the C# `Message.UserUi`
|
|
1785
1837
|
// model). The server persists it as a UserUiContent sibling and strips it from the model
|
|
1786
1838
|
// request; Content remains the only model-facing text.
|
|
@@ -1852,13 +1904,13 @@ f(tt, "HttpArtifactService");
|
|
|
1852
1904
|
let ht = tt;
|
|
1853
1905
|
export {
|
|
1854
1906
|
G as A,
|
|
1855
|
-
|
|
1907
|
+
J as E,
|
|
1856
1908
|
ht as H,
|
|
1857
|
-
|
|
1909
|
+
$ as I,
|
|
1858
1910
|
it as L,
|
|
1859
1911
|
at as M,
|
|
1860
1912
|
ct as W,
|
|
1861
1913
|
lt as a,
|
|
1862
1914
|
Yt as u
|
|
1863
1915
|
};
|
|
1864
|
-
//# sourceMappingURL=httpArtifactService-
|
|
1916
|
+
//# sourceMappingURL=httpArtifactService-BpRwcTJp.js.map
|