@aintela/chat 0.4.37 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components.js +7213 -6950
- package/dist/components.js.map +1 -1
- package/dist/hooks.js +1 -1
- package/dist/httpArtifactService-EEhF_mp9.js +1744 -0
- package/dist/httpArtifactService-EEhF_mp9.js.map +1 -0
- package/dist/{httpSessionService-CUujaUo6.js → httpSessionService-wBby4ggl.js} +51 -53
- package/dist/httpSessionService-wBby4ggl.js.map +1 -0
- package/dist/index.js +248 -240
- package/dist/models.js +1 -1
- package/dist/{serializer-DX-yGa_k.js → serializer-CC-nM3ig.js} +497 -498
- package/dist/serializer-CC-nM3ig.js.map +1 -0
- package/dist/services.js +12 -10
- package/dist/src/components/AiChat/AiChatContext.d.ts +4 -0
- package/dist/src/components/AiChat/AiChatTypes.d.ts +8 -0
- package/dist/src/components/AiChat/ChatPane/CrossfadeSlot.d.ts +24 -0
- package/dist/src/components/AiChat/ChatPane/CurrentMessage.d.ts +9 -9
- package/dist/src/components/AiChat/ChatPane/Message.d.ts +1 -3
- package/dist/src/components/AiChat/ChatPane/MessageAgent.d.ts +9 -8
- package/dist/src/components/AiChat/ChatPane/MessageScope.d.ts +32 -0
- package/dist/src/components/AiChat/ChatPane/MessageUser.d.ts +0 -1
- package/dist/src/components/AiChat/ChatPane/StickyQuestionHeader.d.ts +0 -1
- package/dist/src/components/AiChat/ChatPane/groupParts.d.ts +34 -0
- package/dist/src/components/AiChat/ChatPane/messageAgentVerbosity.test.d.ts +1 -0
- package/dist/src/components/AiChat/ChatPane/parts/ActivityLine.d.ts +9 -0
- package/dist/src/components/AiChat/ChatPane/parts/ConnectionOutagePart.d.ts +9 -0
- package/dist/src/components/AiChat/ChatPane/parts/connectionOutagePart.test.d.ts +1 -0
- package/dist/src/components/AiChat/ChatPane/parts/index.d.ts +4 -1
- package/dist/src/components/AiChat/ChatPane/parts/types.d.ts +25 -5
- package/dist/src/components/AiChat/ChatPane/reasoningHeadlines.d.ts +4 -9
- package/dist/src/components/AiChat/ChatPane/verbosity.d.ts +57 -0
- package/dist/src/components/AiChat/sessionStateManagerService.d.ts +36 -35
- package/dist/src/components/AiChat/stateConfiguration.d.ts +18 -0
- package/dist/src/components/index.d.ts +10 -4
- package/dist/src/components/v2/VerbositySlider.d.ts +12 -0
- package/dist/src/interfaces/index.d.ts +0 -1
- package/dist/src/models/Interaction.d.ts +0 -9
- package/dist/src/models/InteractionPart.d.ts +4 -3
- package/dist/src/models/Notification.d.ts +7 -1
- package/dist/src/models/ServerEvent.d.ts +4 -0
- package/dist/src/models/index.d.ts +1 -1
- package/dist/src/services/WebSocketConnection/WebSocketConnectionV2.d.ts +28 -108
- package/dist/src/services/WebSocketConnection/closeCodes.d.ts +24 -0
- package/dist/src/services/WebSocketConnection/streamStats.d.ts +41 -0
- package/dist/src/services/WebSocketConnection/streamStats.test.d.ts +1 -0
- package/dist/src/services/WebSocketConnection/webSocketConnection.d.ts +15 -12
- package/dist/src/services/eventBusService.d.ts +28 -67
- package/dist/src/services/index.d.ts +2 -1
- package/dist/src/services/interaction/reduceInteraction.d.ts +28 -0
- package/dist/src/services/interactionService.d.ts +15 -32
- package/dist/src/services/interactionService.invariants.test.d.ts +1 -0
- package/dist/src/services/servers/AgentGatewayService.d.ts +3 -182
- package/dist/src/services/servers/AgentGatewayWSAsync.d.ts +145 -46
- package/dist/src/services/servers/connectionSupervisor.d.ts +173 -0
- package/dist/src/services/servers/connectionSupervisor.test.d.ts +1 -0
- package/dist/src/services/servers/connectionSupervisor.wire.test.d.ts +0 -0
- package/dist/src/services/servers/gatewayErrorClosesTurn.test.d.ts +1 -0
- package/dist/src/services/servers/gatewayFixes.test.d.ts +1 -0
- package/dist/src/services/servers/throttledEmit.test.d.ts +1 -0
- package/dist/src/services/servers/throttledEmitter.d.ts +38 -0
- package/dist/src/services/streamPipeline.characterization.test.d.ts +1 -0
- package/dist/src/services/wire/decodeFrame.d.ts +21 -0
- package/dist/src/services/wire/decodeFrame.test.d.ts +1 -0
- package/dist/tests/bench/streamPipeline.bench.d.ts +1 -0
- package/dist/tests/fakes/fakeRawWebSocket.d.ts +2 -0
- package/dist/tests/fakes/fakeWebSocket.d.ts +4 -3
- package/dist/tests/fakes/makeGateway.d.ts +7 -0
- package/dist/tests/wire/journey.d.ts +47 -0
- package/dist/{useChatSessions-BXYvvd4S.js → useChatSessions-C6sYF4U6.js} +2 -2
- package/dist/{useChatSessions-BXYvvd4S.js.map → useChatSessions-C6sYF4U6.js.map} +1 -1
- package/package.json +2 -1
- package/dist/httpArtifactService-GdGsaFKS.js +0 -1979
- package/dist/httpArtifactService-GdGsaFKS.js.map +0 -1
- package/dist/httpSessionService-CUujaUo6.js.map +0 -1
- package/dist/serializer-DX-yGa_k.js.map +0 -1
- package/dist/src/interfaces/IHeartbeatPort.d.ts +0 -4
- /package/dist/src/components/AiChat/{sessionStateManagerService.idle.test.d.ts → ChatPane/crossfadeSlot.test.d.ts} +0 -0
- /package/dist/src/{services/interactionServiceGrouping.test.d.ts → components/AiChat/ChatPane/groupParts.test.d.ts} +0 -0
|
@@ -0,0 +1,1744 @@
|
|
|
1
|
+
var X = Object.defineProperty;
|
|
2
|
+
var at = (i, t, e) => t in i ? X(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
|
|
3
|
+
var d = (i, t) => X(i, "name", { value: t, configurable: !0 });
|
|
4
|
+
var o = (i, t, e) => at(i, typeof t != "symbol" ? t + "" : t, e);
|
|
5
|
+
import { I as O, E as I, S as N, C as b, L as ct, P as $, l as lt, o as ht, T as ut, m as dt, q as gt } from "./serializer-CC-nM3ig.js";
|
|
6
|
+
import { format as ft } from "date-fns";
|
|
7
|
+
import pt from "lodash";
|
|
8
|
+
import { C as T, P as mt } from "./Prompt-DZb7OaPp.js";
|
|
9
|
+
import { d as wt } from "./environmentUtils-VZNTCzEE.js";
|
|
10
|
+
import { r as St } from "./httpSessionService-wBby4ggl.js";
|
|
11
|
+
const _ = {
|
|
12
|
+
PROMPTS: "envision-prompts"
|
|
13
|
+
}, It = 50, q = class q {
|
|
14
|
+
getPrompts() {
|
|
15
|
+
try {
|
|
16
|
+
const t = localStorage.getItem(_.PROMPTS);
|
|
17
|
+
return t ? JSON.parse(t).sort((s, n) => new Date(n.created).getTime() - new Date(s.created).getTime()) : [];
|
|
18
|
+
} catch (t) {
|
|
19
|
+
return console.error("Error loading prompts:", t), [];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Record a sent prompt, most recent first, de-duplicated by text.
|
|
24
|
+
*
|
|
25
|
+
* Asking the same thing again MOVES that entry to the top rather than adding
|
|
26
|
+
* a second copy — the history is a list of distinct things you have asked,
|
|
27
|
+
* and a repeated question spending two of the twelve visible rows costs a
|
|
28
|
+
* suggestion for nothing. The repeat's own `id` and `created` win, because
|
|
29
|
+
* what the list orders by is when you last asked.
|
|
30
|
+
*
|
|
31
|
+
* The dedupe used to look only at `prompts[0]`, and then unshifted anyway:
|
|
32
|
+
* a consecutive repeat overwrote the older copy's id and timestamp AND
|
|
33
|
+
* appended a new row, so the same text appeared twice with the same id.
|
|
34
|
+
*
|
|
35
|
+
* Matching is exact on `promptText` (`PromptUtils.createPrompt` has already
|
|
36
|
+
* trimmed it). Two prompts differing only in case or inner whitespace stay
|
|
37
|
+
* separate entries — that is deliberate, not an oversight: normalising them
|
|
38
|
+
* would mean re-surfacing text the user never typed.
|
|
39
|
+
*/
|
|
40
|
+
storePrompt(t) {
|
|
41
|
+
try {
|
|
42
|
+
const e = this.getPrompts().filter((s) => s.promptText !== t.promptText);
|
|
43
|
+
e.unshift(t), localStorage.setItem(_.PROMPTS, JSON.stringify(e.slice(0, It)));
|
|
44
|
+
} catch (e) {
|
|
45
|
+
console.error("Error storing prompt:", e);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
clearAllPrompts() {
|
|
49
|
+
try {
|
|
50
|
+
localStorage.removeItem(_.PROMPTS);
|
|
51
|
+
} catch (t) {
|
|
52
|
+
console.error("Error clearing prompts:", t);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
d(q, "LocalStorageService");
|
|
57
|
+
let V = q;
|
|
58
|
+
const te = /* @__PURE__ */ d((i) => {
|
|
59
|
+
const t = i.getPrompts(), e = t.length;
|
|
60
|
+
if (e > 0) {
|
|
61
|
+
const s = t[0].promptText, n = t[t.length - 1].promptText, r = t[0].created;
|
|
62
|
+
return { promptState: e + "_" + s + "_" + n + "_" + r };
|
|
63
|
+
} else
|
|
64
|
+
return { promptState: "0" };
|
|
65
|
+
}, "usePromptState"), G = class G {
|
|
66
|
+
constructor() {
|
|
67
|
+
o(this, "artifactGenerated", "artifactGenerated");
|
|
68
|
+
o(this, "artifactSelected", "artifactSelected");
|
|
69
|
+
o(this, "gatewayMessage", "gatewayMessage");
|
|
70
|
+
o(this, "gatewayTurnComplete", "gatewayTurnComplete");
|
|
71
|
+
o(this, "gatewayStreamError", "gatewayStreamError");
|
|
72
|
+
o(this, "gatewayConnected", "gatewayConnected");
|
|
73
|
+
o(this, "gatewayTurnOpen", "gatewayTurnOpen");
|
|
74
|
+
o(this, "gatewayFunctionResponse", "gatewayFunctionResponse");
|
|
75
|
+
o(this, "uiAskQuestion", "uiAskQuestion");
|
|
76
|
+
o(this, "gatewayEndMessageData", "gatewayEndMessageData");
|
|
77
|
+
o(this, "onMessageSent", "onMessageSent");
|
|
78
|
+
o(this, "onMessageError", "onMessageError");
|
|
79
|
+
o(this, "onToolEvent", "onToolEvent");
|
|
80
|
+
o(this, "gatewayFirstToken", "gatewayFirstToken");
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
d(G, "EventTypes");
|
|
84
|
+
let U = G;
|
|
85
|
+
const l = new U(), B = class B {
|
|
86
|
+
constructor() {
|
|
87
|
+
o(this, "listeners", {});
|
|
88
|
+
}
|
|
89
|
+
callListeners(t, ...e) {
|
|
90
|
+
const s = this.listeners[t];
|
|
91
|
+
if (s) {
|
|
92
|
+
const n = s.map((r) => r(...e));
|
|
93
|
+
Promise.all(n).catch((r) => {
|
|
94
|
+
console.error(`Lost error in one of the listeners of the event: ${t}, listeners: ${s.length}, error: ${r}`, s);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
addListener(t, e) {
|
|
99
|
+
this.listeners[t] || (this.listeners[t] = []), this.listeners[t].push(e);
|
|
100
|
+
}
|
|
101
|
+
removeListener(t, e) {
|
|
102
|
+
this.listeners[t] && (this.listeners[t] = this.listeners[t].filter((s) => s !== e));
|
|
103
|
+
}
|
|
104
|
+
/* typed artifact listeners */
|
|
105
|
+
artifactOnGenerated(t) {
|
|
106
|
+
this.addListener(l.artifactGenerated, t);
|
|
107
|
+
}
|
|
108
|
+
artifactEmitGenerated(t) {
|
|
109
|
+
this.callListeners(l.artifactGenerated, t);
|
|
110
|
+
}
|
|
111
|
+
artifactOffGenerated(t) {
|
|
112
|
+
this.removeListener(l.artifactGenerated, t);
|
|
113
|
+
}
|
|
114
|
+
artifactOnSelected(t) {
|
|
115
|
+
this.addListener(l.artifactSelected, t);
|
|
116
|
+
}
|
|
117
|
+
artifactEmitSelected(t) {
|
|
118
|
+
this.callListeners(l.artifactSelected, t);
|
|
119
|
+
}
|
|
120
|
+
artifactOffSelected(t) {
|
|
121
|
+
this.removeListener(l.artifactSelected, t);
|
|
122
|
+
}
|
|
123
|
+
gatewayOnMessage(t) {
|
|
124
|
+
this.addListener(l.gatewayMessage, t);
|
|
125
|
+
}
|
|
126
|
+
gatewayEmitMessage(t) {
|
|
127
|
+
this.callListeners(l.gatewayMessage, t);
|
|
128
|
+
}
|
|
129
|
+
gatewayOffMessage(t) {
|
|
130
|
+
this.removeListener(l.gatewayMessage, t);
|
|
131
|
+
}
|
|
132
|
+
gatewayOnTurnComplete(t) {
|
|
133
|
+
this.addListener(l.gatewayTurnComplete, t);
|
|
134
|
+
}
|
|
135
|
+
gatewayEmitTurnComplete(t, e) {
|
|
136
|
+
this.callListeners(l.gatewayTurnComplete, t, e);
|
|
137
|
+
}
|
|
138
|
+
gatewayOffTurnComplete(t) {
|
|
139
|
+
this.removeListener(l.gatewayTurnComplete, t);
|
|
140
|
+
}
|
|
141
|
+
gatewayOnTurnOpen(t) {
|
|
142
|
+
this.addListener(l.gatewayTurnOpen, t);
|
|
143
|
+
}
|
|
144
|
+
gatewayEmitTurnOpen(t) {
|
|
145
|
+
this.callListeners(l.gatewayTurnOpen, t);
|
|
146
|
+
}
|
|
147
|
+
gatewayOffTurnOpen(t) {
|
|
148
|
+
this.removeListener(l.gatewayTurnOpen, t);
|
|
149
|
+
}
|
|
150
|
+
gatewayOnStreamError(t) {
|
|
151
|
+
this.addListener(l.gatewayStreamError, t);
|
|
152
|
+
}
|
|
153
|
+
gatewayEmitStreamError(t) {
|
|
154
|
+
this.callListeners(l.gatewayStreamError, t);
|
|
155
|
+
}
|
|
156
|
+
gatewayOffStreamError(t) {
|
|
157
|
+
this.removeListener(l.gatewayStreamError, t);
|
|
158
|
+
}
|
|
159
|
+
/** The live socket is up and the session proven — on the first open and on every reconnect (`info.reconnect`). */
|
|
160
|
+
gatewayOnConnected(t) {
|
|
161
|
+
this.addListener(l.gatewayConnected, t);
|
|
162
|
+
}
|
|
163
|
+
gatewayEmitConnected(t, e) {
|
|
164
|
+
this.callListeners(l.gatewayConnected, t, e);
|
|
165
|
+
}
|
|
166
|
+
gatewayOffConnected(t) {
|
|
167
|
+
this.removeListener(l.gatewayConnected, t);
|
|
168
|
+
}
|
|
169
|
+
chatOnMessageSent(t) {
|
|
170
|
+
this.addListener(l.onMessageSent, t);
|
|
171
|
+
}
|
|
172
|
+
chatOffMessageSent(t) {
|
|
173
|
+
this.removeListener(l.onMessageSent, t);
|
|
174
|
+
}
|
|
175
|
+
ChatEmitMessageSent(t, e) {
|
|
176
|
+
this.callListeners(l.onMessageSent, t, e);
|
|
177
|
+
}
|
|
178
|
+
chatOnMessageError(t) {
|
|
179
|
+
this.addListener(l.onMessageError, t);
|
|
180
|
+
}
|
|
181
|
+
chatOffMessageError(t) {
|
|
182
|
+
this.removeListener(l.onMessageError, t);
|
|
183
|
+
}
|
|
184
|
+
ChatEmitMessageError(t) {
|
|
185
|
+
this.callListeners(l.onMessageError, t);
|
|
186
|
+
}
|
|
187
|
+
gatewayOnFunctionResponse(t) {
|
|
188
|
+
this.addListener(l.gatewayFunctionResponse, t);
|
|
189
|
+
}
|
|
190
|
+
gatewayEmitFunctionResponse(t) {
|
|
191
|
+
this.callListeners(l.gatewayFunctionResponse, t);
|
|
192
|
+
}
|
|
193
|
+
gatewayOffFunctionResponse(t) {
|
|
194
|
+
this.removeListener(l.gatewayFunctionResponse, t);
|
|
195
|
+
}
|
|
196
|
+
// "Re-ask this" — a `#ask-…` link in the transcript, carrying the link's TEXT as the question.
|
|
197
|
+
// An event rather than component state because the prompt that must send it is not always
|
|
198
|
+
// ChatPane's own: a host that passes `hidePromptInput` mounts its own `PromptV2` elsewhere in
|
|
199
|
+
// its tree, and that instance cannot see ChatPane's `useState`. Whichever prompt is mounted
|
|
200
|
+
// listens; ChatPane publishes only when its internal one is suppressed, so the question is
|
|
201
|
+
// never sent twice.
|
|
202
|
+
uiOnAskQuestion(t) {
|
|
203
|
+
this.addListener(l.uiAskQuestion, t);
|
|
204
|
+
}
|
|
205
|
+
uiEmitAskQuestion(t) {
|
|
206
|
+
this.callListeners(l.uiAskQuestion, t);
|
|
207
|
+
}
|
|
208
|
+
uiOffAskQuestion(t) {
|
|
209
|
+
this.removeListener(l.uiAskQuestion, t);
|
|
210
|
+
}
|
|
211
|
+
gatewayOnEndMessageData(t) {
|
|
212
|
+
this.addListener(l.gatewayEndMessageData, t);
|
|
213
|
+
}
|
|
214
|
+
gatewayEmitEndMessageData(t) {
|
|
215
|
+
this.callListeners(l.gatewayEndMessageData, t);
|
|
216
|
+
}
|
|
217
|
+
gatewayOffEndMessageData(t) {
|
|
218
|
+
this.removeListener(l.gatewayEndMessageData, t);
|
|
219
|
+
}
|
|
220
|
+
gatewayOnToolEvent(t) {
|
|
221
|
+
this.addListener(l.onToolEvent, t);
|
|
222
|
+
}
|
|
223
|
+
gatewayEmitToolEvent(t, e, s) {
|
|
224
|
+
this.callListeners(l.onToolEvent, t, e, s);
|
|
225
|
+
}
|
|
226
|
+
gatewayOffToolEvent(t) {
|
|
227
|
+
this.removeListener(l.onToolEvent, t);
|
|
228
|
+
}
|
|
229
|
+
gatewayOnFirstToken(t) {
|
|
230
|
+
this.addListener(l.gatewayFirstToken, t);
|
|
231
|
+
}
|
|
232
|
+
gatewayEmitFirstToken(t) {
|
|
233
|
+
this.callListeners(l.gatewayFirstToken, t);
|
|
234
|
+
}
|
|
235
|
+
gatewayOffFirstToken(t) {
|
|
236
|
+
this.removeListener(l.gatewayFirstToken, t);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
d(B, "EventBusService");
|
|
240
|
+
let Z = B;
|
|
241
|
+
const Tt = 2e3;
|
|
242
|
+
function k(i) {
|
|
243
|
+
i.parts === i.prev.parts && (i.parts = i.prev.parts.slice());
|
|
244
|
+
}
|
|
245
|
+
d(k, "ownParts");
|
|
246
|
+
function L(i) {
|
|
247
|
+
i.functionMap === i.prev.functionMap && (i.functionMap = new Map(i.functionMap));
|
|
248
|
+
}
|
|
249
|
+
d(L, "ownFunctionMap");
|
|
250
|
+
const yt = /* @__PURE__ */ d((i) => i == I.FunctionCall || i == I.PartialFunctionCall, "isFunctionCall"), vt = /* @__PURE__ */ d((i) => i == I.FunctionResponse, "isFunctionResponse"), rt = /* @__PURE__ */ d((i) => i.parts.length + 1 + "-" + i.prev.interactionId, "nextPartId");
|
|
251
|
+
function Ct(i, t) {
|
|
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) > Tt);
|
|
254
|
+
}
|
|
255
|
+
d(Ct, "opensNewPart");
|
|
256
|
+
function Et(i, t) {
|
|
257
|
+
const e = t.functionDetails.id, s = t.functionDetails.clientOutput, n = i.parts.findIndex((r) => {
|
|
258
|
+
var a;
|
|
259
|
+
return ((a = r.functionDetails) == null ? void 0 : a.id) === e;
|
|
260
|
+
});
|
|
261
|
+
if (n > -1) {
|
|
262
|
+
const r = i.parts[n], a = {
|
|
263
|
+
...r,
|
|
264
|
+
functionDetails: {
|
|
265
|
+
...r.functionDetails,
|
|
266
|
+
clientOutput: s ?? r.functionDetails.clientOutput,
|
|
267
|
+
// Sticky true-wins: this event IS the park, and a later merge must not clear it.
|
|
268
|
+
parked: t.functionDetails.parked === !0 || r.functionDetails.parked === !0
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
k(i), i.parts[n] = a, L(i), i.functionMap.set(e, a);
|
|
272
|
+
} else {
|
|
273
|
+
const r = {
|
|
274
|
+
...t,
|
|
275
|
+
id: rt(i),
|
|
276
|
+
functionDetails: { ...t.functionDetails, silent: !0 }
|
|
277
|
+
};
|
|
278
|
+
k(i), i.parts.push(r), L(i), i.functionMap.set(e, r);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
d(Et, "foldClientOutput");
|
|
282
|
+
function At(i, t, e, s, n) {
|
|
283
|
+
var w;
|
|
284
|
+
const r = i.parts.findIndex((u) => {
|
|
285
|
+
var g;
|
|
286
|
+
return ((g = u.functionDetails) == null ? void 0 : g.id) === s;
|
|
287
|
+
}), a = r > -1 ? i.parts[r] : e, c = t.functionDetails, h = a.functionDetails, f = {
|
|
288
|
+
...a,
|
|
289
|
+
eventType: t.eventType,
|
|
290
|
+
functionDetails: {
|
|
291
|
+
id: h.id,
|
|
292
|
+
name: c.name ?? h.name,
|
|
293
|
+
// The settled FunctionCall carries the parsed args; the PartialFunctionCall stream it
|
|
294
|
+
// folds onto only accumulated raw JSON in `.text`.
|
|
295
|
+
args: c.args ?? h.args,
|
|
296
|
+
response: c.response,
|
|
297
|
+
status: c.status ?? "Composing",
|
|
298
|
+
start: c.start ?? h.start,
|
|
299
|
+
end: c.end ?? h.end,
|
|
300
|
+
isUi: c.isUi === !0 || h.isUi === !0,
|
|
301
|
+
// Keep the call's friendly args summary when the result event (which has none) folds in.
|
|
302
|
+
argsDescription: c.argsDescription ?? h.argsDescription,
|
|
303
|
+
// The tool's client-only payload rides the RESULT event; sticky so a later rep without
|
|
304
|
+
// one can't clobber it. This is what a uiTool renderer reads.
|
|
305
|
+
clientOutput: c.clientOutput ?? h.clientOutput,
|
|
306
|
+
// Ask-user component ([KernelUIComponent]) — sticky like isUi/clientOutput. The streaming
|
|
307
|
+
// final CALL carries it, the PartialFunctionCall it folds onto may not (issue #60).
|
|
308
|
+
askUserComponent: c.askUserComponent ?? h.askUserComponent,
|
|
309
|
+
isAskUser: c.isAskUser || h.isAskUser || !!(c.askUserComponent ?? h.askUserComponent),
|
|
310
|
+
// Runtime "don't render" override rides the RESULT; sticky so it survives the fold.
|
|
311
|
+
cancelUi: c.cancelUi === !0 || h.cancelUi === !0,
|
|
312
|
+
parked: c.parked === !0 || h.parked === !0
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
L(i), i.functionMap.set(s, f), f.eventType === I.FunctionResponse && ((w = n == null ? void 0 : n.onFunctionResponse) == null || w.call(n, f.functionDetails)), r > -1 && (k(i), i.parts[r] = f);
|
|
316
|
+
}
|
|
317
|
+
d(At, "foldFunctionEvent");
|
|
318
|
+
function Mt(i, t, e, s) {
|
|
319
|
+
s && t.functionDetails && (L(i), i.functionMap.set(s, t));
|
|
320
|
+
const n = i.prev.parts[i.prev.parts.length - 1] ?? null;
|
|
321
|
+
n && n.textAppendable && (k(i), i.parts[i.parts.length - 1] = { ...n, ended: /* @__PURE__ */ new Date() });
|
|
322
|
+
const r = {
|
|
323
|
+
...t,
|
|
324
|
+
id: rt(i),
|
|
325
|
+
partial: e.partial
|
|
326
|
+
};
|
|
327
|
+
i.parts = [...i.parts, r];
|
|
328
|
+
}
|
|
329
|
+
d(Mt, "openPart");
|
|
330
|
+
function Ot(i, t, e, s) {
|
|
331
|
+
const n = i.parts[i.parts.length - 1] ?? null;
|
|
332
|
+
if (!n) return;
|
|
333
|
+
const r = {
|
|
334
|
+
...n,
|
|
335
|
+
partial: e.partial,
|
|
336
|
+
textDetails: n.textDetails ? { ...n.textDetails } : { version: 0 }
|
|
337
|
+
};
|
|
338
|
+
if (e.partial) {
|
|
339
|
+
if (r.textDetails.version++, s || (r.text = (n.text ?? "") + (t.text ?? "")), !s && t.thoughtDetails && r.thoughtDetails) {
|
|
340
|
+
const a = t.thoughtDetails.text;
|
|
341
|
+
(a.length >= 50 || a.length < 50 && a !== r.thoughtDetails.text) && (r.thoughtDetails = { ...r.thoughtDetails, text: r.thoughtDetails.text + a });
|
|
342
|
+
}
|
|
343
|
+
} else
|
|
344
|
+
r.text = t.text ?? "", r.textDetails.version++, t.thoughtDetails && (r.thoughtDetails = { ...t.thoughtDetails, text: t.thoughtDetails.text.trim() });
|
|
345
|
+
k(i), i.parts[i.parts.length - 1] = r;
|
|
346
|
+
}
|
|
347
|
+
d(Ot, "appendText");
|
|
348
|
+
function kt(i, t) {
|
|
349
|
+
if (!t || t.length === 0) return i;
|
|
350
|
+
const e = i.slice();
|
|
351
|
+
for (const s of t) {
|
|
352
|
+
const n = s.toArtifact(), r = e.findIndex((a) => a.id === n.id);
|
|
353
|
+
r === -1 ? e.push(n) : e[r] = n;
|
|
354
|
+
}
|
|
355
|
+
return e;
|
|
356
|
+
}
|
|
357
|
+
d(kt, "mergeArtifacts");
|
|
358
|
+
function $t(i, t, e) {
|
|
359
|
+
var c, h;
|
|
360
|
+
const s = O.FlatParts(t == null ? void 0 : t.parts), n = i.parts[i.parts.length - 1] ?? null, r = {
|
|
361
|
+
prev: i,
|
|
362
|
+
parts: i.parts,
|
|
363
|
+
functionMap: i.functionMap ?? /* @__PURE__ */ new Map()
|
|
364
|
+
};
|
|
365
|
+
let a = !1;
|
|
366
|
+
if (s) {
|
|
367
|
+
if (s.eventType === I.FunctionClientOutput && !!((c = s.functionDetails) != null && c.id))
|
|
368
|
+
Et(r, s);
|
|
369
|
+
else if (Ct(s, n)) {
|
|
370
|
+
const w = yt(s.eventType) || vt(s.eventType), u = w ? (h = s.functionDetails) == null ? void 0 : h.id : void 0;
|
|
371
|
+
w && !u && console.error("Got isCall or isResponse without a callId", s);
|
|
372
|
+
const g = u ? r.functionMap.get(u) : void 0;
|
|
373
|
+
g && u && s.functionDetails ? At(r, s, g, u, e) : (Mt(r, s, t, u), a = !0);
|
|
374
|
+
}
|
|
375
|
+
s.textAppendable && Ot(r, s, t, a);
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
...i,
|
|
379
|
+
version: i.version + 1,
|
|
380
|
+
parts: r.parts,
|
|
381
|
+
artifactData: kt(i.artifactData ?? [], t.llmArtifacts),
|
|
382
|
+
functionMap: r.functionMap,
|
|
383
|
+
turn_complete: t.turn_complete,
|
|
384
|
+
partial: t.partial,
|
|
385
|
+
asyncFinalResponse: t.asyncFinalResponse
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
d($t, "reduceInteraction");
|
|
389
|
+
const H = class H {
|
|
390
|
+
constructor(t, e) {
|
|
391
|
+
o(this, "interaction");
|
|
392
|
+
o(this, "eventBusService");
|
|
393
|
+
this.interaction = t, this.eventBusService = e;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Computes the next interaction from a server event and makes it current.
|
|
397
|
+
* Pure with respect to the previous tree: snapshots already handed out to
|
|
398
|
+
* throttled subscribers cannot diverge from live state.
|
|
399
|
+
*/
|
|
400
|
+
merge(t) {
|
|
401
|
+
const e = $t(this.interaction, t, {
|
|
402
|
+
onFunctionResponse: /* @__PURE__ */ d((s) => this.eventBusService.gatewayEmitFunctionResponse(s), "onFunctionResponse")
|
|
403
|
+
});
|
|
404
|
+
return this.interaction = e, e;
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
d(H, "InteractionService");
|
|
408
|
+
let P = H;
|
|
409
|
+
const ot = 4001, Dt = 4002, bt = 4004, Lt = 4100, D = 500, Pt = 2e4, _t = 1e3, Rt = 0.2, M = 300 * 1e3, Nt = 0.75, Ut = 2e3, m = "[Connection]", z = class z {
|
|
410
|
+
constructor(t) {
|
|
411
|
+
o(this, "ports");
|
|
412
|
+
o(this, "state");
|
|
413
|
+
o(this, "now");
|
|
414
|
+
o(this, "target", null);
|
|
415
|
+
o(this, "inflight", null);
|
|
416
|
+
o(this, "retryTimer", null);
|
|
417
|
+
o(this, "idleTimer", null);
|
|
418
|
+
o(this, "wait", D);
|
|
419
|
+
/** Consecutive failed attempts since the last proven connection. */
|
|
420
|
+
o(this, "attempt", 0);
|
|
421
|
+
o(this, "halted", null);
|
|
422
|
+
/** The code of the last close the transport reported, consumed by the next dial failure. */
|
|
423
|
+
o(this, "lastCloseCode", null);
|
|
424
|
+
o(this, "everConnected", !1);
|
|
425
|
+
o(this, "idleWarningLogged", !1);
|
|
426
|
+
this.ports = t, this.now = t.now ?? (() => Date.now()), this.state = t.store.getState(), t.store.subscribe((e) => {
|
|
427
|
+
this.state = e;
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
// ─── Queries ────────────────────────────────────────────────────────────
|
|
431
|
+
get sessionId() {
|
|
432
|
+
var t;
|
|
433
|
+
return (t = this.target) == null ? void 0 : t.sessionId;
|
|
434
|
+
}
|
|
435
|
+
get isSupervising() {
|
|
436
|
+
return this.target !== null;
|
|
437
|
+
}
|
|
438
|
+
get haltReason() {
|
|
439
|
+
return this.halted;
|
|
440
|
+
}
|
|
441
|
+
/** The delay the NEXT failure would wait. Exposed for tests and the console. */
|
|
442
|
+
get nextWaitMs() {
|
|
443
|
+
return this.wait;
|
|
444
|
+
}
|
|
445
|
+
get retryScheduled() {
|
|
446
|
+
return this.retryTimer !== null;
|
|
447
|
+
}
|
|
448
|
+
/** Connected by the store AND by the transport. */
|
|
449
|
+
get isUp() {
|
|
450
|
+
var t, e;
|
|
451
|
+
return this.state.connectionStatus === T.Connected && (((e = (t = this.ports).isConnected) == null ? void 0 : e.call(t)) ?? !0);
|
|
452
|
+
}
|
|
453
|
+
// ─── Commands ───────────────────────────────────────────────────────────
|
|
454
|
+
/**
|
|
455
|
+
* Be on `sessionId` (or on a fresh session when undefined). Resolves with the session id once
|
|
456
|
+
* the first attempt succeeds, rejects when it fails — and keeps retrying in the background
|
|
457
|
+
* either way, until {@link close} or a halt. Calling it for the session already targeted
|
|
458
|
+
* joins the dial in flight or returns the open socket's id; calling it for a different session
|
|
459
|
+
* hangs up the current one first.
|
|
460
|
+
*/
|
|
461
|
+
open(t, e) {
|
|
462
|
+
if (this.target && this.sameTarget(t)) {
|
|
463
|
+
if (this.inflight) return this.inflight;
|
|
464
|
+
if (this.isUp && this.target.sessionId && !this.halted)
|
|
465
|
+
return Promise.resolve(this.target.sessionId);
|
|
466
|
+
} else this.target && (console.log(`${m} switching from session ${this.target.sessionId ?? "(new)"} to ${t ?? "(new)"}.`), this.close());
|
|
467
|
+
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();
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* The send guard: make sure the socket is up before a frame goes out, dialling NOW (not at
|
|
471
|
+
* the next scheduled retry) when it is not. `fallbackSessionId` is what to dial when nothing
|
|
472
|
+
* was ever opened through here (a host that set the session on the gateway directly).
|
|
473
|
+
*/
|
|
474
|
+
async ensure(t) {
|
|
475
|
+
var e;
|
|
476
|
+
if (this.halted)
|
|
477
|
+
throw new Error(`The connection was halted (${this.halted}); session ${((e = this.target) == null ? void 0 : e.sessionId) ?? t ?? "none"} cannot be redialled.`);
|
|
478
|
+
return this.target ? this.inflight ? this.inflight : this.isUp && this.target.sessionId ? this.target.sessionId : (console.warn(`${m} 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(`${m} send guard: nothing supervised yet — opening session ${t ?? "(new)"} with the replay cursor.`), this.open(t, { resume: !0 }));
|
|
479
|
+
}
|
|
480
|
+
/** Stop supervising: hang up, cancel any retry, stop the idle tick. Never throws. */
|
|
481
|
+
close() {
|
|
482
|
+
const t = this.target;
|
|
483
|
+
this.target = null, this.halted = null, this.cancelRetry(), this.stopIdleTick(), this.wait = D, this.attempt = 0;
|
|
484
|
+
try {
|
|
485
|
+
this.ports.hangUp();
|
|
486
|
+
} catch (e) {
|
|
487
|
+
console.error(`${m} hangUp threw`, e);
|
|
488
|
+
}
|
|
489
|
+
t && this.state.setConnectionStatus(T.Disconnected);
|
|
490
|
+
}
|
|
491
|
+
// ─── Transport reports ──────────────────────────────────────────────────
|
|
492
|
+
/**
|
|
493
|
+
* The transport's socket closed. The code is the policy input:
|
|
494
|
+
* - 4001: our own hang-up, nothing to do.
|
|
495
|
+
* - 4002: attached elsewhere — halt, never bounce the other tab.
|
|
496
|
+
* - 4004: the server no longer has the session — halt, the host tells the user.
|
|
497
|
+
* - 1000 / 1008: closed on purpose / credentials rejected — halt.
|
|
498
|
+
* - anything else (1001 going away, 1006 abnormal, 1011–1013 server trouble, 4003 the server's
|
|
499
|
+
* idle close, 4100 our heartbeat's dead-peer verdict): retry on the curve, cursor kept.
|
|
500
|
+
* A close that lands while a dial is in flight is remembered and judged when that dial fails.
|
|
501
|
+
*/
|
|
502
|
+
transportClosed(t, e) {
|
|
503
|
+
if (t !== ot && (this.lastCloseCode = t, !!this.target)) {
|
|
504
|
+
if (this.inflight) {
|
|
505
|
+
console.log(`${m} socket closed (code=${t}) while a dial is in flight — judged when it settles.`);
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
this.state.connectionStatus === T.Connected && (console.warn(`${m} socket closed: code=${t} reason="${e}" (session ${this.target.sessionId ?? "(new)"}).`), this.state.setConnectionStatus(T.Disconnected), this.judge(t));
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
// ─── The dial ───────────────────────────────────────────────────────────
|
|
512
|
+
dial() {
|
|
513
|
+
const t = this.target;
|
|
514
|
+
this.lastCloseCode = null, this.state.setConnectionStatus(T.Connecting);
|
|
515
|
+
const e = this.now();
|
|
516
|
+
console.log(`${m} dialling session ${t.sessionId ?? "(new)"}${t.resume ? " with the replay cursor" : ""}${this.everConnected ? " (reconnect)" : ""}.`);
|
|
517
|
+
const n = (async () => (t.prepare && await t.prepare(), this.ports.dial(t.sessionId, { resume: t.resume })))().then((r) => {
|
|
518
|
+
var c, h;
|
|
519
|
+
if (this.target !== t) {
|
|
520
|
+
console.log(`${m} a dial for ${t.sessionId ?? "(new)"} resolved after it was abandoned — hanging up.`);
|
|
521
|
+
try {
|
|
522
|
+
this.ports.hangUp();
|
|
523
|
+
} catch {
|
|
524
|
+
}
|
|
525
|
+
throw new Error("Connection attempt abandoned");
|
|
526
|
+
}
|
|
527
|
+
if (t.sessionId && r !== t.sessionId) {
|
|
528
|
+
console.error(`${m} asked for session ${t.sessionId}, the server answered with ${r} — refusing the swap and halting.`);
|
|
529
|
+
try {
|
|
530
|
+
this.ports.hangUp();
|
|
531
|
+
} catch {
|
|
532
|
+
}
|
|
533
|
+
throw this.state.setConnectionStatus(T.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}).`);
|
|
534
|
+
}
|
|
535
|
+
const a = this.everConnected;
|
|
536
|
+
return this.everConnected = !0, t.sessionId = r, t.resume = !0, t.prepare = void 0, this.wait = D, this.attempt = 0, this.state.setConnectionStatus(T.Connected), console.log(`${m} ${a ? "reconnected to" : "connected to"} session ${r} in ${this.now() - e}ms.`), (h = (c = this.ports).onConnected) == null || h.call(c, r, { reconnect: a }), r;
|
|
537
|
+
}).catch((r) => {
|
|
538
|
+
if (this.target === t && !this.halted) {
|
|
539
|
+
const a = this.lastCloseCode;
|
|
540
|
+
console.error(`${m} dial of session ${t.sessionId ?? "(new)"} failed after ${this.now() - e}ms${a !== null ? ` (socket closed with ${a})` : ""}:`, r), this.state.setConnectionStatus(T.Disconnected), this.inflight === n && (this.inflight = null), this.judge(a);
|
|
541
|
+
}
|
|
542
|
+
throw r;
|
|
543
|
+
}).finally(() => {
|
|
544
|
+
this.inflight === n && (this.inflight = null);
|
|
545
|
+
});
|
|
546
|
+
return this.inflight = n, n;
|
|
547
|
+
}
|
|
548
|
+
/** Apply the close-code policy to a failure: halt, or schedule the next attempt. */
|
|
549
|
+
judge(t) {
|
|
550
|
+
var s;
|
|
551
|
+
const e = (s = this.target) == null ? void 0 : s.sessionId;
|
|
552
|
+
if (t === Dt) return this.halt("attached-elsewhere", { sessionId: e, code: t });
|
|
553
|
+
if (t === bt) return this.halt("session-gone", { sessionId: e, code: t });
|
|
554
|
+
if (t === 1e3 || t === 1008) return this.halt("closed-by-server", { sessionId: e, code: t });
|
|
555
|
+
this.scheduleRetry();
|
|
556
|
+
}
|
|
557
|
+
halt(t, e) {
|
|
558
|
+
var s, n;
|
|
559
|
+
this.halted = t, this.cancelRetry(), console.warn(`${m} halted (${t}) on session ${e.sessionId ?? "(new)"}${e.code !== void 0 ? `, close code ${e.code}` : ""} — no automatic redial; an explicit open() may try again.`);
|
|
560
|
+
try {
|
|
561
|
+
(n = (s = this.ports).onHalt) == null || n.call(s, t, e);
|
|
562
|
+
} catch (r) {
|
|
563
|
+
console.error(`${m} onHalt threw`, r);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
scheduleRetry() {
|
|
567
|
+
var e, s;
|
|
568
|
+
if (!this.target || this.retryTimer || this.inflight) return;
|
|
569
|
+
if (!this.state.sessionActive) {
|
|
570
|
+
console.log(`${m} session idle — not redialling until activity resumes.`);
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
const t = this.jittered(this.wait);
|
|
574
|
+
this.wait = Math.min(Math.floor(this.wait + this.wait * this.wait / _t), Pt), this.attempt += 1, console.warn(`${m} redialling session ${this.target.sessionId ?? "(new)"} in ${t}ms (then ${this.wait}ms, attempt ${this.attempt}).`);
|
|
575
|
+
try {
|
|
576
|
+
(s = (e = this.ports).onRetryScheduled) == null || s.call(e, { sessionId: this.target.sessionId, delayMs: t, attempt: this.attempt });
|
|
577
|
+
} catch (n) {
|
|
578
|
+
console.error(`${m} onRetryScheduled threw`, n);
|
|
579
|
+
}
|
|
580
|
+
this.retryTimer = setTimeout(() => {
|
|
581
|
+
this.retryTimer = null, !(!this.target || this.halted) && (this.target.resume = !0, this.dial().catch(() => {
|
|
582
|
+
}));
|
|
583
|
+
}, t);
|
|
584
|
+
}
|
|
585
|
+
cancelRetry() {
|
|
586
|
+
this.retryTimer && (clearTimeout(this.retryTimer), this.retryTimer = null);
|
|
587
|
+
}
|
|
588
|
+
jittered(t) {
|
|
589
|
+
return Math.max(0, Math.round(t + t * Rt * (Math.random() * 2 - 1)));
|
|
590
|
+
}
|
|
591
|
+
sameTarget(t) {
|
|
592
|
+
var e;
|
|
593
|
+
return ((e = this.target) == null ? void 0 : e.sessionId) === t;
|
|
594
|
+
}
|
|
595
|
+
// ─── Idle ───────────────────────────────────────────────────────────────
|
|
596
|
+
startIdleTick() {
|
|
597
|
+
this.idleTimer || (this.idleTimer = setInterval(() => this.tick(), Ut));
|
|
598
|
+
}
|
|
599
|
+
stopIdleTick() {
|
|
600
|
+
this.idleTimer && (clearInterval(this.idleTimer), this.idleTimer = null);
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* One idle check. Public so a test can drive it without the interval.
|
|
604
|
+
*
|
|
605
|
+
* A STREAMING TURN IS ACTIVITY: `lastActivity` is otherwise fed only by human input and sends,
|
|
606
|
+
* and surfaces without a ChatPane never register the listeners, so a long agent turn used to
|
|
607
|
+
* cross the window mid-stream and get its socket closed under it. Refreshing the clock while
|
|
608
|
+
* the turn is open mirrors the server's own live-activity exemption.
|
|
609
|
+
*/
|
|
610
|
+
tick() {
|
|
611
|
+
if (!this.target) return;
|
|
612
|
+
this.state.turnOpen && this.state.setLastActivity();
|
|
613
|
+
const t = this.now() - this.state.lastActivity;
|
|
614
|
+
if (t > M) {
|
|
615
|
+
if (this.state.sessionActive && this.state.setIsSessionActive(!1), this.cancelRetry(), this.state.connectionStatus === T.Connected) {
|
|
616
|
+
console.warn(`${m} idle for ${Math.round(t / 1e3)}s (limit ${M / 1e3}s) — closing the socket (session ${this.target.sessionId ?? "(new)"}). Activity, or a send, redials it.`);
|
|
617
|
+
try {
|
|
618
|
+
this.ports.hangUp();
|
|
619
|
+
} catch (e) {
|
|
620
|
+
console.error(`${m} hangUp threw`, e);
|
|
621
|
+
}
|
|
622
|
+
this.state.setConnectionStatus(T.Disconnected);
|
|
623
|
+
}
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
this.state.sessionActive || (console.log(`${m} activity resumed — the session is active again.`), this.state.setIsSessionActive(!0), this.wait = D, this.state.connectionStatus === T.Disconnected && !this.halted && !this.inflight && (this.target.resume = !0, this.dial().catch(() => {
|
|
627
|
+
}))), t > M * Nt ? this.idleWarningLogged || (this.idleWarningLogged = !0, console.warn(`${m} idle ${Math.round(t / 1e3)}s of ${M / 1e3}s — the socket closes in about ${Math.round((M - t) / 1e3)}s unless something happens.`)) : this.idleWarningLogged = !1;
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
d(z, "ConnectionSupervisor");
|
|
631
|
+
let F = z;
|
|
632
|
+
const K = class K {
|
|
633
|
+
constructor(t) {
|
|
634
|
+
o(this, "pending", null);
|
|
635
|
+
o(this, "lastPublishedAt", 0);
|
|
636
|
+
o(this, "trailing", null);
|
|
637
|
+
this.options = t;
|
|
638
|
+
}
|
|
639
|
+
emit(t) {
|
|
640
|
+
const e = Date.now(), s = e - this.lastPublishedAt;
|
|
641
|
+
if (t.partial === !1 || s >= this.options.windowMs) {
|
|
642
|
+
this.clearTrailing(), this.publish(t, e);
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
this.pending = t, this.clearTrailing(), this.trailing = setTimeout(() => {
|
|
646
|
+
this.trailing = null, this.pending && this.pending.version > this.options.publishedVersion() && this.publish(this.pending, e);
|
|
647
|
+
}, this.options.windowMs * 2);
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Drop a trailing publish still queued. Call on turn commit: once the store
|
|
651
|
+
* has moved the interaction into history and nulled the live message, a late
|
|
652
|
+
* trailing publish would set it live again — the duplicated-bubble bug.
|
|
653
|
+
*/
|
|
654
|
+
cancelPending() {
|
|
655
|
+
this.clearTrailing(), this.pending = null;
|
|
656
|
+
}
|
|
657
|
+
publish(t, e) {
|
|
658
|
+
this.lastPublishedAt = e, this.pending = null, this.options.publish(t);
|
|
659
|
+
}
|
|
660
|
+
clearTrailing() {
|
|
661
|
+
this.trailing && (clearTimeout(this.trailing), this.trailing = null);
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
d(K, "ThrottledEmitter");
|
|
665
|
+
let x = K;
|
|
666
|
+
const S = class S {
|
|
667
|
+
constructor(t, e, s, n, r, a, c, h, f, w) {
|
|
668
|
+
o(this, "base_url");
|
|
669
|
+
o(this, "msg_order", 0);
|
|
670
|
+
o(this, "interactionsMap", /* @__PURE__ */ new Map());
|
|
671
|
+
o(this, "interactionsServiceMap", /* @__PURE__ */ new Map());
|
|
672
|
+
o(this, "user");
|
|
673
|
+
o(this, "config");
|
|
674
|
+
o(this, "currentIS", null);
|
|
675
|
+
o(this, "sessionState");
|
|
676
|
+
o(this, "storageService");
|
|
677
|
+
o(this, "notificationPort");
|
|
678
|
+
o(this, "interactionCallIds", /* @__PURE__ */ new Map());
|
|
679
|
+
/** Interactions whose turn was committed (turn-complete or a server error); a second close is ignored. */
|
|
680
|
+
o(this, "committedTurns", /* @__PURE__ */ new Set());
|
|
681
|
+
o(this, "rawJwt");
|
|
682
|
+
o(this, "sessionId");
|
|
683
|
+
o(this, "eventBusService");
|
|
684
|
+
o(this, "artifactService");
|
|
685
|
+
o(this, "wsService");
|
|
686
|
+
/** The one owner of dial / redial / idle close / connection status. See ConnectionSupervisor. */
|
|
687
|
+
o(this, "connection");
|
|
688
|
+
o(this, "suspendState", !1);
|
|
689
|
+
/**
|
|
690
|
+
* True once a WS has successfully opened at least once in this gateway's
|
|
691
|
+
* lifetime. Gates the "Reiniciando a conexão" toast: a drop of a working
|
|
692
|
+
* connection is worth telling the user about, a failed initial dial is not
|
|
693
|
+
* (the Connecting state already covers it).
|
|
694
|
+
*/
|
|
695
|
+
o(this, "everConnected", !1);
|
|
696
|
+
/** Publishes the live message to the store; see ThrottledEmitter for the cadence rules. */
|
|
697
|
+
o(this, "liveMessage", new x({
|
|
698
|
+
windowMs: S.CURRENT_MSG_THROTTLE_MS,
|
|
699
|
+
publish: /* @__PURE__ */ d((t) => {
|
|
700
|
+
this.sessionState.setCurrentMessage(t), this.eventBusService.gatewayEmitMessage(t);
|
|
701
|
+
}, "publish"),
|
|
702
|
+
publishedVersion: /* @__PURE__ */ d(() => {
|
|
703
|
+
var t;
|
|
704
|
+
return ((t = this.sessionState.currentMessage) == null ? void 0 : t.version) ?? 0;
|
|
705
|
+
}, "publishedVersion")
|
|
706
|
+
}));
|
|
707
|
+
o(this, "subAgentInteractions", /* @__PURE__ */ new Map());
|
|
708
|
+
o(this, "subAgentInteractionServices", /* @__PURE__ */ new Map());
|
|
709
|
+
// ─── Artifacts ──────────────────────────────────────────────────────────
|
|
710
|
+
o(this, "runningRequests", /* @__PURE__ */ new Map());
|
|
711
|
+
this.user = t, this.config = r, this.rawJwt = t.access_token, this.base_url = n, this.eventBusService = e, this.sessionId = w, this.artifactService = s, this.sessionState = a.getState(), this.notificationPort = c, this.storageService = f, a.subscribe((u, g) => {
|
|
712
|
+
this.sessionState = u;
|
|
713
|
+
}), this.wsService = h, this.connection = new F({
|
|
714
|
+
store: a,
|
|
715
|
+
// A redial while a turn is open carries the turn's id: the server tells us if it cannot continue it.
|
|
716
|
+
dial: /* @__PURE__ */ d((u, g) => this.wsService.connect(u, {
|
|
717
|
+
...g,
|
|
718
|
+
openInteractionId: g.resume && this.sessionState.turnOpen ? this.getCurrentInteractionId() ?? void 0 : void 0
|
|
719
|
+
}), "dial"),
|
|
720
|
+
hangUp: /* @__PURE__ */ d(() => this.wsService.closeStream(), "hangUp"),
|
|
721
|
+
isConnected: /* @__PURE__ */ d(() => this.wsService.isConnected(), "isConnected"),
|
|
722
|
+
onConnected: /* @__PURE__ */ d((u, g) => {
|
|
723
|
+
this.sessionId = u, this.sessionState.setConnectionOutage(null), this.eventBusService.gatewayEmitConnected(u, g);
|
|
724
|
+
}, "onConnected"),
|
|
725
|
+
onRetryScheduled: /* @__PURE__ */ d(({ delayMs: u, attempt: g }) => {
|
|
726
|
+
var A;
|
|
727
|
+
const p = Date.now(), C = ((A = this.sessionState.connectionOutage) == null ? void 0 : A.since) ?? p;
|
|
728
|
+
this.sessionState.setConnectionOutage({ since: C, retryAt: p + u, attempt: g, halted: null }), p - C >= S.OUTAGE_CLOSES_TURN_AFTER_MS && this.closeOpenTurnWith(S.OUTAGE_TURN_MESSAGE);
|
|
729
|
+
}, "onRetryScheduled"),
|
|
730
|
+
onHalt: /* @__PURE__ */ d((u, g) => {
|
|
731
|
+
const p = this.sessionState.connectionOutage;
|
|
732
|
+
this.sessionState.setConnectionOutage({ since: (p == null ? void 0 : p.since) ?? Date.now(), retryAt: null, attempt: (p == null ? void 0 : p.attempt) ?? 0, halted: u }), this.notifyHalt(u, g), this.closeOpenTurnWith(S.HALT_TURN_MESSAGE[u]);
|
|
733
|
+
}, "onHalt")
|
|
734
|
+
}), this.wsService.onEvent = async (u) => {
|
|
735
|
+
await this.Message(u);
|
|
736
|
+
}, this.wsService.onNewPacket = (u) => {
|
|
737
|
+
this.sessionState.setStatistics(u);
|
|
738
|
+
}, this.wsService.onError = (u) => {
|
|
739
|
+
if (console.error("Stream error:", u), this.everConnected)
|
|
740
|
+
try {
|
|
741
|
+
this.notificationPort.pushNotification({
|
|
742
|
+
message: "Reiniciando a conexão com o servidor",
|
|
743
|
+
type: "info",
|
|
744
|
+
// Tagged so a host can recognise this one and draw its own affordance (a progress bar glued
|
|
745
|
+
// to the page, say) instead of a toast, without matching on the copy.
|
|
746
|
+
kind: "connection-restarting"
|
|
747
|
+
});
|
|
748
|
+
} catch (g) {
|
|
749
|
+
console.error("[AgentGateway] notification port threw on connection-restarting", g);
|
|
750
|
+
}
|
|
751
|
+
this.eventBusService.gatewayEmitStreamError(u);
|
|
752
|
+
}, this.wsService.onOpen = () => {
|
|
753
|
+
this.everConnected = !0;
|
|
754
|
+
}, this.wsService.onFirstToken = (u) => {
|
|
755
|
+
this.localEmitFirstToken(u);
|
|
756
|
+
}, this.wsService.onClose = (u, g) => {
|
|
757
|
+
this.connection.transportClosed(u, g);
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* The turn the user is waiting on will not continue: close it from the client side with an error
|
|
762
|
+
* part, the same way a server error would. No-op when no turn is open.
|
|
763
|
+
*/
|
|
764
|
+
closeOpenTurnWith(t) {
|
|
765
|
+
if (!this.sessionState.turnOpen) return;
|
|
766
|
+
const e = this.getCurrentInteractionId();
|
|
767
|
+
e && (console.warn(`[AgentGateway] closing interaction ${e} from the client side: ${t}`), this.Message(N.createErrorEvent(t, e)));
|
|
768
|
+
}
|
|
769
|
+
/** The supervisor gave up on its own (another tab holds the session, the session is gone, …): tell the user. */
|
|
770
|
+
notifyHalt(t, e) {
|
|
771
|
+
const s = {
|
|
772
|
+
"attached-elsewhere": { message: "Esta sessão já está aberta em outra janela", kind: "session-attached-elsewhere" },
|
|
773
|
+
"session-gone": { message: "A sessão não existe mais no servidor", kind: "session-gone" },
|
|
774
|
+
"closed-by-server": { message: "O servidor encerrou a conexão", kind: "connection-closed" }
|
|
775
|
+
}, { message: n, kind: r } = s[t];
|
|
776
|
+
try {
|
|
777
|
+
this.notificationPort.pushNotification({
|
|
778
|
+
message: n,
|
|
779
|
+
type: "warning",
|
|
780
|
+
kind: r,
|
|
781
|
+
details: `session ${e.sessionId ?? "none"}${e.code !== void 0 ? `, close code ${e.code}` : ""}${e.actualSessionId ? `, server answered with ${e.actualSessionId}` : ""}`
|
|
782
|
+
});
|
|
783
|
+
} catch (a) {
|
|
784
|
+
console.error(`[AgentGateway] notification port threw on ${r}`, a);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
// ─── Agent context ──────────────────────────────────────────────────────
|
|
788
|
+
/**
|
|
789
|
+
* The agent this gateway speaks to — the ONE truth for the conversation.
|
|
790
|
+
* `sendMessageInternal` stamps every outbound frame's `AgentId` from it,
|
|
791
|
+
* and the session manager binds/rebinds against it. Fixed at construction;
|
|
792
|
+
* see {@link forceAgentContext} for the single exception (issue #59).
|
|
793
|
+
*/
|
|
794
|
+
getAgentContext() {
|
|
795
|
+
return this.config;
|
|
796
|
+
}
|
|
797
|
+
getModel() {
|
|
798
|
+
return this.config.model;
|
|
799
|
+
}
|
|
800
|
+
setModel(t) {
|
|
801
|
+
this.config = { ...this.config, model: t };
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Live update for the ordinary, non-identity slice of the context — the
|
|
805
|
+
* dataset/customer the same agent works over. No "force" needed: swapping
|
|
806
|
+
* datasets mid-conversation is routine and changes nothing about who is
|
|
807
|
+
* answering.
|
|
808
|
+
*/
|
|
809
|
+
setCustomer(t) {
|
|
810
|
+
this.config = { ...this.config, customer: t };
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Replace the AGENT mid-conversation. The escape hatch for an agent picker,
|
|
814
|
+
* and nothing else: the session already holds another agent's history, and
|
|
815
|
+
* the server stamps `Session.AgentId` on the first turn only — so the
|
|
816
|
+
* conversation keeps reporting the agent it STARTED as, however many times
|
|
817
|
+
* this is called. Prefer a new engine (new key, see `engineKeyFor`) per
|
|
818
|
+
* agent.
|
|
819
|
+
*
|
|
820
|
+
* Callers pass the FULL replacement context (the same shape the gateway was
|
|
821
|
+
* constructed with). The `model` slice is preserved when the incoming
|
|
822
|
+
* context omits it — the model is owned separately by {@link setModel} and
|
|
823
|
+
* must not be clobbered by an agent-only change.
|
|
824
|
+
*/
|
|
825
|
+
forceAgentContext(t) {
|
|
826
|
+
this.config = {
|
|
827
|
+
...t,
|
|
828
|
+
model: t.model ?? this.config.model
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
// ─── Session and interactions ───────────────────────────────────────────
|
|
832
|
+
getSessionId() {
|
|
833
|
+
return this.sessionId;
|
|
834
|
+
}
|
|
835
|
+
setSession(t, e) {
|
|
836
|
+
(this.sessionId === void 0 || this.sessionId != t) && (this.sessionId = t, this.msg_order = this.sessionState.messages.length);
|
|
837
|
+
}
|
|
838
|
+
startInteraction(t, e, s) {
|
|
839
|
+
if (e && this.currentIS)
|
|
840
|
+
return this.currentIS.interaction.isSuspended = !1, this.currentIS.interaction.interactionQuestion += " + " + t, this.currentIS.interaction;
|
|
841
|
+
this.msg_order += 1;
|
|
842
|
+
let n = this.getNewInteractionId();
|
|
843
|
+
s && (n = s);
|
|
844
|
+
let r = {
|
|
845
|
+
created: /* @__PURE__ */ new Date(),
|
|
846
|
+
interactionId: n,
|
|
847
|
+
artifactData: [],
|
|
848
|
+
partial: !0,
|
|
849
|
+
sessionId: this.sessionId,
|
|
850
|
+
turn_complete: !1,
|
|
851
|
+
parts: [],
|
|
852
|
+
version: 0,
|
|
853
|
+
functionMap: /* @__PURE__ */ new Map(),
|
|
854
|
+
interactionQuestion: t
|
|
855
|
+
};
|
|
856
|
+
return this.interactionsMap.set(r.interactionId, r), this.currentIS = new P(r, this.eventBusService), this.interactionsServiceMap.set(r.interactionId, this.currentIS), r;
|
|
857
|
+
}
|
|
858
|
+
getInteractions() {
|
|
859
|
+
return Array.from(this.interactionsMap.values());
|
|
860
|
+
}
|
|
861
|
+
getCurrentInteractionId() {
|
|
862
|
+
return this.currentIS ? this.currentIS.interaction.interactionId : null;
|
|
863
|
+
}
|
|
864
|
+
getCurrentInteraction() {
|
|
865
|
+
var t;
|
|
866
|
+
return ((t = this.currentIS) == null ? void 0 : t.interaction) ?? null;
|
|
867
|
+
}
|
|
868
|
+
updateMap(t) {
|
|
869
|
+
let e = this.interactionsServiceMap.get(t.interactionId);
|
|
870
|
+
if (!e) {
|
|
871
|
+
var s = this.startInteraction("Unknown", !1, t.interactionId);
|
|
872
|
+
e = this.interactionsServiceMap.get(s.interactionId);
|
|
873
|
+
}
|
|
874
|
+
return e.merge(t);
|
|
875
|
+
}
|
|
876
|
+
getNewInteractionId() {
|
|
877
|
+
const e = ft(/* @__PURE__ */ new Date(), "MMM_dd_HH_mm_ss");
|
|
878
|
+
return `${this.msg_order}_${e}`;
|
|
879
|
+
}
|
|
880
|
+
// ─── Inbound: server events ─────────────────────────────────────────────
|
|
881
|
+
async Message(t) {
|
|
882
|
+
try {
|
|
883
|
+
let e;
|
|
884
|
+
if (typeof t == "object" && Object.keys(t).includes("mimeType"))
|
|
885
|
+
e = t;
|
|
886
|
+
else {
|
|
887
|
+
console.error("Uknown message type", t);
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
if (e.subAgentId) {
|
|
891
|
+
this.handleSubAgentEvent(e);
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
if (e.serverError && console.error("Stream error: ", e.serverError), e.endMessageData && this.eventBusService.gatewayEmitEndMessageData(e.endMessageData), e.llmArtifacts && e.llmArtifacts.length > 0)
|
|
895
|
+
for (const a of e.llmArtifacts) {
|
|
896
|
+
const c = a.toArtifact();
|
|
897
|
+
this.artifactService.addToCache(c), this.eventBusService.artifactEmitGenerated(c);
|
|
898
|
+
}
|
|
899
|
+
for (const a of e.parts ?? [])
|
|
900
|
+
a.toolDetails && this.localEmitToolEvent(a.toolDetails);
|
|
901
|
+
const s = (e.parts ?? []).some((a) => a.eventType === I.ServerError);
|
|
902
|
+
if (s && !e.interactionId) {
|
|
903
|
+
const a = this.getCurrentInteractionId();
|
|
904
|
+
a && (e.interactionId = a);
|
|
905
|
+
}
|
|
906
|
+
const n = this.updateMap(e);
|
|
907
|
+
if (!n) {
|
|
908
|
+
console.error("No updated interaction");
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
911
|
+
this.localEmitMessage(n), (e.turn_complete || e.asyncFinalResponse || s) && (this.committedTurns.has(e.interactionId) || (this.committedTurns.add(e.interactionId), this.turnComplete(e.interactionId, n, e.author, e.subAgentId)));
|
|
912
|
+
const r = e.artifactsDelta;
|
|
913
|
+
r && r.forEach((a) => {
|
|
914
|
+
const c = n.artifactData.filter((f) => f.id == a);
|
|
915
|
+
let h = null;
|
|
916
|
+
c && c.length > 0 && (h = c[0], h.loadingPromise = this.asyncLoadArtifact(a).then((f) => (f === null ? console.error("Error trying to load artifact id:", h == null ? void 0 : h.id, "Artifact is null") : this.eventBusService.artifactEmitGenerated(f), f)).catch((f) => (console.error("Error trying to load artifact id:", h == null ? void 0 : h.id, f.toString()), null)));
|
|
917
|
+
});
|
|
918
|
+
} catch (e) {
|
|
919
|
+
if (this.getCurrentInteractionId()) {
|
|
920
|
+
const s = N.createErrorEvent("OnMessage error: " + e.toString(), this.getCurrentInteractionId() ?? "Empty Current"), n = this.updateMap(s);
|
|
921
|
+
if (console.error("Error event: ", JSON.stringify(s, void 0, 4)), !n) {
|
|
922
|
+
console.error("Error event, could not update interaction: ", JSON.stringify(s, void 0, 4));
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
this.localEmitMessage(n);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
getOrCreateSubAgentInteraction(t, e, s) {
|
|
930
|
+
let n = this.subAgentInteractions.get(t), r = this.subAgentInteractionServices.get(t);
|
|
931
|
+
return (!n || !r) && (n = {
|
|
932
|
+
created: /* @__PURE__ */ new Date(),
|
|
933
|
+
interactionId: e,
|
|
934
|
+
artifactData: [],
|
|
935
|
+
partial: !0,
|
|
936
|
+
turn_complete: !1,
|
|
937
|
+
parts: [],
|
|
938
|
+
version: 0,
|
|
939
|
+
functionMap: /* @__PURE__ */ new Map(),
|
|
940
|
+
interactionQuestion: s ?? t
|
|
941
|
+
}, r = new P(n, this.eventBusService), this.subAgentInteractions.set(t, n), this.subAgentInteractionServices.set(t, r)), { interaction: n, service: r };
|
|
942
|
+
}
|
|
943
|
+
handleSubAgentEvent(t) {
|
|
944
|
+
const e = t.subAgentId, { service: s } = this.getOrCreateSubAgentInteraction(e, t.interactionId, t.subAgentName);
|
|
945
|
+
for (const r of t.parts ?? [])
|
|
946
|
+
r.toolDetails && this.localEmitToolEvent({ ...r.toolDetails, subAgentId: e });
|
|
947
|
+
const n = s.merge(t);
|
|
948
|
+
n && (this.sessionState.setSubAgentMessage(e, n, t.subAgentName), (t.turn_complete ?? !1) && this.sessionState.completeSubAgent(e));
|
|
949
|
+
}
|
|
950
|
+
localEmitToolEvent(t) {
|
|
951
|
+
this.sessionState.setLastToolEvent(t), this.eventBusService.gatewayEmitToolEvent(t.eventName, t.eventData, t.sessionId);
|
|
952
|
+
}
|
|
953
|
+
registerInteractionCallId(t, e) {
|
|
954
|
+
e != null && e.callId && this.interactionCallIds.set(t, e.callId);
|
|
955
|
+
}
|
|
956
|
+
localEmitFirstToken(t) {
|
|
957
|
+
this.eventBusService.gatewayEmitFirstToken({
|
|
958
|
+
interactionId: t,
|
|
959
|
+
callId: this.interactionCallIds.get(t)
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
localEmitMessage(t) {
|
|
963
|
+
this.liveMessage.emit(t);
|
|
964
|
+
}
|
|
965
|
+
localOpen(t, e) {
|
|
966
|
+
this.sessionState.setTurnOpen(!0), this.eventBusService.gatewayEmitTurnOpen(t ?? "");
|
|
967
|
+
}
|
|
968
|
+
async turnComplete(t, e, s, n) {
|
|
969
|
+
this.liveMessage.cancelPending(), this.sessionState.setNewMessage(e), this.eventBusService.gatewayEmitTurnComplete(t, e), this.interactionCallIds.delete(t), this.sessionState.setLastToolEvent(null), this.localEmitToolEvent({
|
|
970
|
+
eventName: "todolistUpdated",
|
|
971
|
+
eventData: "",
|
|
972
|
+
subAgentId: n
|
|
973
|
+
}), this.sessionState.setTurnOpen(!1);
|
|
974
|
+
}
|
|
975
|
+
async asyncLoadArtifact(t) {
|
|
976
|
+
let e = null;
|
|
977
|
+
const s = this.runningRequests.get(t);
|
|
978
|
+
s ? (console.warn("GOT A running promise", t), e = s) : (e = this.artifactService.getArtifact(t), this.runningRequests.set(t, e));
|
|
979
|
+
try {
|
|
980
|
+
return await e;
|
|
981
|
+
} catch (n) {
|
|
982
|
+
return console.error("Error awating on HTML promise", n.toString()), null;
|
|
983
|
+
} finally {
|
|
984
|
+
this.runningRequests.delete(t);
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
// ─── Connection ─────────────────────────────────────────────────────────
|
|
988
|
+
/**
|
|
989
|
+
* Be on `sessionId` (a fresh session when undefined). Resolves with the session id once the
|
|
990
|
+
* first dial succeeds and rejects when it fails; the supervisor keeps redialling in the
|
|
991
|
+
* background either way, with the replay cursor, until {@link closeConnection}. Concurrent
|
|
992
|
+
* callers for the same session share the dial in flight. See ConnectionSupervisor for the
|
|
993
|
+
* backoff, the idle close and the close-code policy — and for the rule that a requested
|
|
994
|
+
* session is never swapped for another.
|
|
995
|
+
*/
|
|
996
|
+
async openConnection(t, e) {
|
|
997
|
+
return this.connection.open(t, e);
|
|
998
|
+
}
|
|
999
|
+
async closeConnection(t = !0) {
|
|
1000
|
+
try {
|
|
1001
|
+
return this.stopStream(t), {
|
|
1002
|
+
success: !0,
|
|
1003
|
+
interaction: this.getCurrentInteraction()
|
|
1004
|
+
};
|
|
1005
|
+
} catch {
|
|
1006
|
+
return {
|
|
1007
|
+
success: !1,
|
|
1008
|
+
interaction: this.getCurrentInteraction()
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
/** Hang up and stop supervising the connection. `closeTurn` also closes an open turn in the store. */
|
|
1013
|
+
stopStream(t = !0) {
|
|
1014
|
+
t && this.sessionState.setTurnOpen(!1), this.sessionState.setConnectionOutage(null), this.connection.close();
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Make sure the socket is OPEN before a send, redialling the SAME session when it is not.
|
|
1018
|
+
*
|
|
1019
|
+
* The socket can be down at send time for reasons the composer cannot see: the client's own
|
|
1020
|
+
* idle close (5 min without input), the server's (6 min without a message, code 4003), a dead
|
|
1021
|
+
* peer the heartbeat just detected, or a dial still in flight. Until this existed the send
|
|
1022
|
+
* threw `WebSocket is not connected` AFTER the user's turn was already on the transcript — or
|
|
1023
|
+
* the composer refused it outright. A send IS the activity that reconnect was waiting for, so
|
|
1024
|
+
* the supervisor dials now rather than at its next scheduled retry, replay cursor kept.
|
|
1025
|
+
*/
|
|
1026
|
+
async ensureConnected() {
|
|
1027
|
+
const t = this.sessionId;
|
|
1028
|
+
if (this.wsService.isConnected()) {
|
|
1029
|
+
console.log(`[AgentGateway] send guard: socket is open (session ${t ?? "none"}, status ${this.sessionState.connectionStatus}) — sending straight away.`);
|
|
1030
|
+
return;
|
|
1031
|
+
}
|
|
1032
|
+
const e = Date.now();
|
|
1033
|
+
try {
|
|
1034
|
+
const s = await this.connection.ensure(t);
|
|
1035
|
+
console.log(`[AgentGateway] send guard: reconnected to ${s} in ${Date.now() - e}ms — sending now.`);
|
|
1036
|
+
} catch (s) {
|
|
1037
|
+
throw console.error(`[AgentGateway] send guard: redial FAILED after ${Date.now() - e}ms — the message was not sent.`, s), new Error(S.NO_CONNECTION_MESSAGE, { cause: s });
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
// ─── Outbound: the user's turns ─────────────────────────────────────────
|
|
1041
|
+
async sendMessage(t, e) {
|
|
1042
|
+
let s = this.getInteractions().length, n = O.createWaiting(!0, !0, "Overall", /* @__PURE__ */ new Date());
|
|
1043
|
+
this.sendStatusMessage(t.data, [n], s.toString() + "1");
|
|
1044
|
+
try {
|
|
1045
|
+
const { promptAsString: r, json: a } = this.sessionState.onRenderPrompt ? this.sessionState.onRenderPrompt(t.data) : { promptAsString: t.data, json: void 0 };
|
|
1046
|
+
this.sessionState.onRenderPrompt && (t.data = a, t.friendlyMessage = r);
|
|
1047
|
+
const c = await this.sendMessageInternal(t, e), h = mt.createPrompt(r ?? "", (a == null ? void 0 : a.toString()) ?? {});
|
|
1048
|
+
this.storageService.storePrompt(h);
|
|
1049
|
+
const f = O.fromText("Planejando próximos passos");
|
|
1050
|
+
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;
|
|
1051
|
+
} catch (r) {
|
|
1052
|
+
const a = r instanceof Error ? r.message : String(r ?? "");
|
|
1053
|
+
return this.liveMessage.cancelPending(), this.sessionState.setCurrentMessage(null), this.sessionState.setTurnOpen(!1), this.eventBusService.ChatEmitMessageError(a), {
|
|
1054
|
+
success: !1,
|
|
1055
|
+
error: a,
|
|
1056
|
+
interaction: {
|
|
1057
|
+
artifactData: [],
|
|
1058
|
+
created: /* @__PURE__ */ new Date(),
|
|
1059
|
+
interactionId: "",
|
|
1060
|
+
partial: !1,
|
|
1061
|
+
parts: [O.fromError(a)],
|
|
1062
|
+
version: 0
|
|
1063
|
+
}
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
// Send a message to the server over the socket
|
|
1068
|
+
async sendMessageInternal(t, e) {
|
|
1069
|
+
var r, a, c, h, f, w, u, g;
|
|
1070
|
+
const s = this.suspendState;
|
|
1071
|
+
this.suspendState = !1;
|
|
1072
|
+
const n = this.startInteraction(t.friendlyMessage ?? t.data, s);
|
|
1073
|
+
if (this.registerInteractionCallId(n.interactionId, e), (r = t.userUi) != null && r.name && n.parts.push(O.fromUserUi(t.userUi.name, t.userUi.args)), !this.wsService)
|
|
1074
|
+
throw "no wsService created";
|
|
1075
|
+
if (!((a = this.config.agentConfig) != null && a.id))
|
|
1076
|
+
throw "Agent not selected";
|
|
1077
|
+
return this.sessionState.setLastActivity(), await this.ensureConnected(), this.wsService.sendMessage({
|
|
1078
|
+
Content: t.data,
|
|
1079
|
+
SessionId: this.sessionId,
|
|
1080
|
+
Action: b.SendMessage,
|
|
1081
|
+
ModelId: this.config.model,
|
|
1082
|
+
InteractionId: n.interactionId,
|
|
1083
|
+
AgentId: (c = this.config.agentConfig) == null ? void 0 : c.id,
|
|
1084
|
+
// Optional explicit C# class name on the server (e.g. "LlmAgentSessionReplay").
|
|
1085
|
+
// When set, AgentBootStrapService.GetAgent dispatches to that class directly
|
|
1086
|
+
// instead of looking up an Agent metadata row by AgentId. Plumbed through
|
|
1087
|
+
// `agentContext.agentConfig.agentImplementation` so a host can run a turn
|
|
1088
|
+
// against any registered LlmAgent variant without seeding a Mongo record.
|
|
1089
|
+
AgentImplementation: (h = this.config.agentConfig) == null ? void 0 : h.agentImplementation,
|
|
1090
|
+
Parameters: {
|
|
1091
|
+
CustomerName: ((f = this.config.customer) == null ? void 0 : f.name) ?? "",
|
|
1092
|
+
DataSet: ((w = this.config.customer) == null ? void 0 : w.dataSetId) ?? ""
|
|
1093
|
+
},
|
|
1094
|
+
// Forward image attachments as a structured payload (PascalCase
|
|
1095
|
+
// keys to match the C# `Message.Images` / `MessageImage` model).
|
|
1096
|
+
Images: (u = t.images) != null && u.length ? t.images.map((p) => ({ MimeType: p.mimeType, Data: p.data })) : void 0,
|
|
1097
|
+
// Client-only UI representation for this turn (PascalCase to match the C# `Message.UserUi`
|
|
1098
|
+
// model). The server persists it as a UserUiContent sibling and strips it from the model
|
|
1099
|
+
// request; Content remains the only model-facing text.
|
|
1100
|
+
UserUi: (g = t.userUi) != null && g.name ? { Name: t.userUi.name, Args: t.userUi.args } : void 0
|
|
1101
|
+
}), this.localOpen(n.interactionId, "system"), {
|
|
1102
|
+
interaction: n,
|
|
1103
|
+
success: !0
|
|
1104
|
+
};
|
|
1105
|
+
}
|
|
1106
|
+
sendStatusMessage(t, e, s) {
|
|
1107
|
+
var r, a;
|
|
1108
|
+
let n;
|
|
1109
|
+
((a = (r = this.currentIS) == null ? void 0 : r.interaction) == null ? void 0 : a.turn_complete) === !1 ? (n = pt.cloneDeep(this.currentIS.interaction), n.parts.push(...e)) : n = {
|
|
1110
|
+
interactionId: "tmp" + s,
|
|
1111
|
+
created: /* @__PURE__ */ new Date(),
|
|
1112
|
+
partial: !0,
|
|
1113
|
+
turn_complete: !1,
|
|
1114
|
+
version: 0,
|
|
1115
|
+
parts: e,
|
|
1116
|
+
interactionQuestion: t,
|
|
1117
|
+
artifactData: []
|
|
1118
|
+
}, this.localEmitMessage(n);
|
|
1119
|
+
}
|
|
1120
|
+
/**
|
|
1121
|
+
* Send the user's answer to a parked `ask_user` tool call back to the agent, as a
|
|
1122
|
+
* ChatAction.AnswerHumanTool frame. 'sent' when it went out immediately, 'queued' when the
|
|
1123
|
+
* socket was down and the answer will flush on reconnect.
|
|
1124
|
+
*
|
|
1125
|
+
* Feature-detected rather than cast: a host may supply any `IWebSocketConnection` (the demo's fake
|
|
1126
|
+
* gateway does), and a hard cast turned "this transport doesn't deliver answers" into a TypeError
|
|
1127
|
+
* thrown from a click handler — with the answer lost either way.
|
|
1128
|
+
*/
|
|
1129
|
+
answerHumanTool(t, e) {
|
|
1130
|
+
var n;
|
|
1131
|
+
const s = (n = this.wsService.answerHumanTool) == null ? void 0 : n.bind(this.wsService);
|
|
1132
|
+
return s ? s(t, e) : (console.warn("[AgentGateway] transport cannot deliver parked-tool answers", t), "queued");
|
|
1133
|
+
}
|
|
1134
|
+
// ─── Suspend ────────────────────────────────────────────────────────────
|
|
1135
|
+
async suspend() {
|
|
1136
|
+
const t = this.wsService;
|
|
1137
|
+
return new Promise(async (e, s) => {
|
|
1138
|
+
let n = !1;
|
|
1139
|
+
t.onSuspended = () => {
|
|
1140
|
+
n = !0;
|
|
1141
|
+
}, t.suspendStream();
|
|
1142
|
+
const r = 100, a = 5e3;
|
|
1143
|
+
let c = 0;
|
|
1144
|
+
for (; !n && c < a; )
|
|
1145
|
+
await this.sleep(r), c += r;
|
|
1146
|
+
if (!n) {
|
|
1147
|
+
s("Timeout awaiting for suspension");
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
if (!this.currentIS) {
|
|
1151
|
+
console.error("CurrentIS is null"), s("CurrentIS is null");
|
|
1152
|
+
return;
|
|
1153
|
+
}
|
|
1154
|
+
const h = this.currentIS.interaction;
|
|
1155
|
+
h.isSuspended = !0, this.sessionState.setCurrentMessage(h), this.sessionState.setTurnOpen(!1), this.suspendState = !0, e(!0);
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
async sleep(t) {
|
|
1159
|
+
return new Promise((e) => setTimeout(e, t));
|
|
1160
|
+
}
|
|
1161
|
+
};
|
|
1162
|
+
d(S, "AgentGatewayWSAsync"), // How often the streaming message re-renders. 150 ms made a reasoning highlight, or a burst of them, visibly lag the
|
|
1163
|
+
// server (Ciro, 2026-10-07). The server already merges deltas over a 50 ms window (the SDK's DeltaCoalescer), so
|
|
1164
|
+
// frames arrive at ~20/s per kind and 20 ms here costs little: it mostly stops adding a second delay on top.
|
|
1165
|
+
o(S, "CURRENT_MSG_THROTTLE_MS", 20), /**
|
|
1166
|
+
* How long an open turn survives a connection outage. While the supervisor is redialling the
|
|
1167
|
+
* turn stays open — a short blip resumes it from the replay cursor, and a server that comes back
|
|
1168
|
+
* (or another instance) closes it with an error if its run is gone. Past this, nobody can tell
|
|
1169
|
+
* us anything, and a turn that is still open is a composer that is still locked: the client
|
|
1170
|
+
* closes it itself, with an error part, so the user can go on.
|
|
1171
|
+
*/
|
|
1172
|
+
o(S, "OUTAGE_CLOSES_TURN_AFTER_MS", 6e4), o(S, "OUTAGE_TURN_MESSAGE", "Sem conexão com o servidor há mais de um minuto. A resposta foi interrompida."), /** What a send reports when the socket could not be brought up for it. */
|
|
1173
|
+
o(S, "NO_CONNECTION_MESSAGE", "Não foi possível obter conexão com o servidor"), o(S, "HALT_TURN_MESSAGE", {
|
|
1174
|
+
"attached-elsewhere": "Esta sessão está aberta em outra janela. A resposta foi interrompida.",
|
|
1175
|
+
"session-gone": "A sessão não existe mais no servidor. A resposta foi interrompida.",
|
|
1176
|
+
"closed-by-server": "O servidor encerrou a conexão. A resposta foi interrompida."
|
|
1177
|
+
});
|
|
1178
|
+
let tt = S;
|
|
1179
|
+
function Ft(i) {
|
|
1180
|
+
const t = new ct();
|
|
1181
|
+
t.author = "main", t.streamingParts = i.streamingParts, i.partialEventType ? t.eventType = i.partialEventType : t.eventType = i.functionName ? { fullName: $.StreamingFunctionCallUpdateContent, type: I.PartialFunctionCall } : i.partialReasoning ? { fullName: $.StreamingReasoningContent, type: I.Thought } : { fullName: $.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;
|
|
1182
|
+
const e = t.eventType.type;
|
|
1183
|
+
if (e == I.PartialFunctionCall) {
|
|
1184
|
+
const s = new lt();
|
|
1185
|
+
s.choiceIndex = 0, s.callId = i.functionCallId, s.arguments = i.partialText, s.name = i.functionName, t.content = { items: [s], role: { label: "Assistant" } };
|
|
1186
|
+
} else if (e == I.Text)
|
|
1187
|
+
if (t.eventType.fullName == $.StreamingTextContent) {
|
|
1188
|
+
const s = new ht();
|
|
1189
|
+
s.text = i.partialText, t.content = { items: [s], role: { label: "Assistant" } };
|
|
1190
|
+
} else {
|
|
1191
|
+
const s = new ut();
|
|
1192
|
+
s.text = i.partialText, t.content = { items: [s], role: { label: "Assistant" } };
|
|
1193
|
+
}
|
|
1194
|
+
else if (e == I.Thought) {
|
|
1195
|
+
const s = new dt();
|
|
1196
|
+
s.text = i.partialReasoning, t.content = { items: [s], role: { label: "Assistant" } };
|
|
1197
|
+
}
|
|
1198
|
+
return t;
|
|
1199
|
+
}
|
|
1200
|
+
d(Ft, "llmEventFromPartial");
|
|
1201
|
+
function xt(i) {
|
|
1202
|
+
const t = i.partialEvent ? Ft(i.partialEvent) : i.event;
|
|
1203
|
+
if (t)
|
|
1204
|
+
return i.subAgentId && (t.subAgentId = i.subAgentId, t.subAgentName = i.subAgentName), t;
|
|
1205
|
+
}
|
|
1206
|
+
d(xt, "llmEventFromFrame");
|
|
1207
|
+
function Wt(i) {
|
|
1208
|
+
var t, e, s;
|
|
1209
|
+
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;
|
|
1210
|
+
}
|
|
1211
|
+
d(Wt, "carriesContent");
|
|
1212
|
+
const qt = 0.02;
|
|
1213
|
+
function Gt(i, t) {
|
|
1214
|
+
if (!t) return null;
|
|
1215
|
+
const e = (t.interactionsCompressed ?? 0) > 0 || (t.compressionRatio ?? 0) > 0;
|
|
1216
|
+
if (!i)
|
|
1217
|
+
return e ? et(t, t.size, t.size) : null;
|
|
1218
|
+
const s = i.size - t.size, n = t.maxSize || i.maxSize || 0, r = n > 0 ? s / n >= qt : i.size > 0 && s / i.size >= 0.1;
|
|
1219
|
+
return !e && !r ? null : et(t, i.size, t.size, i.ratio);
|
|
1220
|
+
}
|
|
1221
|
+
d(Gt, "detectCompaction");
|
|
1222
|
+
function et(i, t, e, s) {
|
|
1223
|
+
return {
|
|
1224
|
+
at: Date.now(),
|
|
1225
|
+
// Where the bar stood when it happened — the marker's position. The ratio
|
|
1226
|
+
// BEFORE the pass is the meaningful one: it is the fill the compaction
|
|
1227
|
+
// reacted to, and it is also the only one that does not move afterwards.
|
|
1228
|
+
ratio: s ?? i.ratio,
|
|
1229
|
+
sizeBefore: t,
|
|
1230
|
+
sizeAfter: e,
|
|
1231
|
+
interactionsCompressed: i.interactionsCompressed
|
|
1232
|
+
};
|
|
1233
|
+
}
|
|
1234
|
+
d(et, "entry");
|
|
1235
|
+
const st = 4, Bt = 3, Ht = 20, E = class E {
|
|
1236
|
+
constructor() {
|
|
1237
|
+
o(this, "stats");
|
|
1238
|
+
o(this, "onFlush");
|
|
1239
|
+
o(this, "sessionCompactions", []);
|
|
1240
|
+
o(this, "previousSessionInformation");
|
|
1241
|
+
/** [timestamp, text length] per frame, for the sliding-window rate. */
|
|
1242
|
+
o(this, "events", []);
|
|
1243
|
+
o(this, "flushTimer", null);
|
|
1244
|
+
o(this, "lastFlushed", 0);
|
|
1245
|
+
this.stats = this.fresh();
|
|
1246
|
+
}
|
|
1247
|
+
fresh() {
|
|
1248
|
+
return {
|
|
1249
|
+
eventCount: 0,
|
|
1250
|
+
unknonwCount: 0,
|
|
1251
|
+
buffer: [],
|
|
1252
|
+
startTime: /* @__PURE__ */ new Date(),
|
|
1253
|
+
elapsed: 0,
|
|
1254
|
+
unparsedCount: 0,
|
|
1255
|
+
totalTransfered: 0,
|
|
1256
|
+
tokensPerSecond: 0,
|
|
1257
|
+
sessionCompactions: this.sessionCompactions
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1260
|
+
/** A new interaction started streaming: counters restart, the compaction history does not. */
|
|
1261
|
+
resetForInteraction() {
|
|
1262
|
+
this.stats = this.fresh();
|
|
1263
|
+
}
|
|
1264
|
+
/**
|
|
1265
|
+
* Account for one decoded frame. `sessionInformation` is only read off main-agent
|
|
1266
|
+
* frames — a sub-agent's reading describes a different session.
|
|
1267
|
+
*/
|
|
1268
|
+
record(t) {
|
|
1269
|
+
const e = Date.now();
|
|
1270
|
+
if (this.events.push([e, t.textLength]), this.stats.eventCount += 1, this.stats.totalTransfered += t.rawLength, t.sessionInformation && !t.fromSubAgent) {
|
|
1271
|
+
const r = Gt(this.previousSessionInformation, t.sessionInformation);
|
|
1272
|
+
r && (this.sessionCompactions.push(r), this.sessionCompactions.length > Ht && this.sessionCompactions.shift()), this.previousSessionInformation = t.sessionInformation, this.stats.sessionInformation = t.sessionInformation, this.stats.sessionCompactions = this.sessionCompactions;
|
|
1273
|
+
}
|
|
1274
|
+
this.stats.elapsed = (e - this.stats.startTime.getTime()) / 1e3;
|
|
1275
|
+
const s = e - st * 1e3;
|
|
1276
|
+
for (; this.events.length > 0 && this.events[0][0] <= s; ) this.events.shift();
|
|
1277
|
+
const n = this.events.reduce((r, a) => r + a[1], 0);
|
|
1278
|
+
this.stats.tokensPerSecond = n / Bt / st, this.flushCoalesced();
|
|
1279
|
+
}
|
|
1280
|
+
flushCoalesced() {
|
|
1281
|
+
if (!this.onFlush) return;
|
|
1282
|
+
const t = Date.now(), e = t - this.lastFlushed;
|
|
1283
|
+
if (e >= E.STATS_FLUSH_MS) {
|
|
1284
|
+
this.flushTimer && (clearTimeout(this.flushTimer), this.flushTimer = null), this.lastFlushed = t, this.onFlush({ ...this.stats });
|
|
1285
|
+
return;
|
|
1286
|
+
}
|
|
1287
|
+
this.flushTimer || (this.flushTimer = setTimeout(() => {
|
|
1288
|
+
var s;
|
|
1289
|
+
this.flushTimer = null, this.lastFlushed = Date.now(), (s = this.onFlush) == null || s.call(this, { ...this.stats });
|
|
1290
|
+
}, E.STATS_FLUSH_MS - e));
|
|
1291
|
+
}
|
|
1292
|
+
};
|
|
1293
|
+
d(E, "StreamStatsTracker"), o(E, "STATS_FLUSH_MS", 120);
|
|
1294
|
+
let W = E;
|
|
1295
|
+
const zt = 5e3, Kt = 3e4, R = 1e4, J = class J {
|
|
1296
|
+
constructor(t = "ws://localhost:8000", e) {
|
|
1297
|
+
o(this, "ws", null);
|
|
1298
|
+
/** Frame counts, byte totals, the token-rate estimate and the compaction history — see StreamStatsTracker. */
|
|
1299
|
+
o(this, "statsTracker", new W());
|
|
1300
|
+
o(this, "baseUrl");
|
|
1301
|
+
/**
|
|
1302
|
+
* Optional callback that returns the current JWT. We re-evaluate it on every connect/reconnect
|
|
1303
|
+
* so that a refreshed token is picked up automatically. Browsers can't set the Authorization
|
|
1304
|
+
* header on the WebSocket handshake, so we pass the JWT via the ?access_token= query string,
|
|
1305
|
+
* which the .NET JwtBearer events handler reads in Program.cs.
|
|
1306
|
+
*/
|
|
1307
|
+
o(this, "getToken");
|
|
1308
|
+
o(this, "onEvent");
|
|
1309
|
+
o(this, "onError");
|
|
1310
|
+
o(this, "onOpen");
|
|
1311
|
+
o(this, "onFirstToken");
|
|
1312
|
+
o(this, "onSuspended");
|
|
1313
|
+
o(this, "onClose");
|
|
1314
|
+
/**
|
|
1315
|
+
* Fired when the server signals that we lost streaming events on resume — our
|
|
1316
|
+
* `lastSeq` fell off the end of the in-memory replay buffer. Consumers should
|
|
1317
|
+
* reset partial-streaming UI for this session and rely on persisted history.
|
|
1318
|
+
*/
|
|
1319
|
+
o(this, "onRewindLost");
|
|
1320
|
+
o(this, "sessionId");
|
|
1321
|
+
o(this, "monitorInterval", null);
|
|
1322
|
+
o(this, "streamingResponseSerializer");
|
|
1323
|
+
o(this, "lastActivity");
|
|
1324
|
+
/** When the outstanding heartbeat Ping went out; null while no reply is pending. */
|
|
1325
|
+
o(this, "pingSentAt", null);
|
|
1326
|
+
o(this, "firstTokenInteractions");
|
|
1327
|
+
/** Last sessionId we successfully had — stamps parked answers, labels log lines. */
|
|
1328
|
+
o(this, "lastKnownSessionId");
|
|
1329
|
+
/**
|
|
1330
|
+
* Highest server-assigned `seq` we have observed and processed. The next
|
|
1331
|
+
* reconnect appends `?lastSeq={lastSeq}` so the server can replay anything
|
|
1332
|
+
* we missed from the InteractionRun's in-memory buffer. -1 means "haven't
|
|
1333
|
+
* seen any sequenced events yet" (fresh connection).
|
|
1334
|
+
*/
|
|
1335
|
+
o(this, "lastSeq", -1);
|
|
1336
|
+
/**
|
|
1337
|
+
* Parked-tool answers that could not be sent because the socket was not OPEN
|
|
1338
|
+
* (e.g. the connection idled out while the user was in an IdP sign-in popup).
|
|
1339
|
+
* Keyed per tool call (last answer wins) and stamped with the session they
|
|
1340
|
+
* belong to; flushed by `onopen` when the socket resumes THAT session. An
|
|
1341
|
+
* answer for a session this instance is no longer attached to is dropped —
|
|
1342
|
+
* the single-attach policy makes it undeliverable from here anyway.
|
|
1343
|
+
*/
|
|
1344
|
+
o(this, "pendingAnswers", []);
|
|
1345
|
+
this.baseUrl = t, this.getToken = e, this.firstTokenInteractions = /* @__PURE__ */ new Set(), this.streamingResponseSerializer = gt(), console.log("SOCKET INSTACE", wt()), this.lastActivity = (/* @__PURE__ */ new Date()).getTime();
|
|
1346
|
+
}
|
|
1347
|
+
get stats() {
|
|
1348
|
+
return this.statsTracker.stats;
|
|
1349
|
+
}
|
|
1350
|
+
/** Coalesced stats updates (see StreamStatsTracker.STATS_FLUSH_MS). */
|
|
1351
|
+
set onNewPacket(t) {
|
|
1352
|
+
this.statsTracker.onFlush = t;
|
|
1353
|
+
}
|
|
1354
|
+
get onNewPacket() {
|
|
1355
|
+
return this.statsTracker.onFlush;
|
|
1356
|
+
}
|
|
1357
|
+
/**
|
|
1358
|
+
* Dial the endpoint once. Resolves with the session id the server's first Pong carries;
|
|
1359
|
+
* rejects when the socket closes, or times out, before that. A close AFTER the Pong is
|
|
1360
|
+
* reported through `onClose` only.
|
|
1361
|
+
*
|
|
1362
|
+
* `options.resume` keeps the replay cursor so the server can send back everything emitted
|
|
1363
|
+
* while we were away (`?lastSeq=N`). Without it the dial is fresh and the cursor is dropped:
|
|
1364
|
+
* a cursor from one conversation must never be presented to another.
|
|
1365
|
+
*/
|
|
1366
|
+
connect(t, e) {
|
|
1367
|
+
return new Promise(async (s, n) => {
|
|
1368
|
+
var Q, Y;
|
|
1369
|
+
e != null && e.resume || (this.lastSeq = -1);
|
|
1370
|
+
const r = (Q = this.getToken) == null ? void 0 : Q.call(this), a = [];
|
|
1371
|
+
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)}`);
|
|
1372
|
+
const c = a.length > 0 ? `?${a.join("&")}` : "", h = this.baseUrl.replace(/^http:\/\//, "ws://").replace(/^https:\/\//, "wss://"), f = `${h}/ws/connect/${t ?? ""}${c}`;
|
|
1373
|
+
console.log("[WebSocket] Connecting to", `${h}/ws/connect/${t ?? ""}` + (t && this.lastSeq >= 0 ? ` (resume lastSeq=${this.lastSeq})` : "")), this.detachSocket(), this.ws = new WebSocket(f), this.ws.onopen = () => {
|
|
1374
|
+
console.log("[WebSocket] Socket open — waiting for the session id"), this.ping(), this.monitor();
|
|
1375
|
+
}, this.ws.onmessage = (y) => {
|
|
1376
|
+
try {
|
|
1377
|
+
this.lastActivity = (/* @__PURE__ */ new Date()).getTime(), this.pingSentAt = null;
|
|
1378
|
+
const v = this.streamingResponseSerializer.parse(y.data);
|
|
1379
|
+
if (!v)
|
|
1380
|
+
throw "Error parsing event JSON";
|
|
1381
|
+
this.handleMessage(v, y.data);
|
|
1382
|
+
} catch (v) {
|
|
1383
|
+
console.error("[WebSocket] Error parsing message:", v);
|
|
1384
|
+
}
|
|
1385
|
+
}, this.ws.onerror = (y) => {
|
|
1386
|
+
console.error("[WebSocket] Error:", y), this.onError && this.onError("WebSocket error");
|
|
1387
|
+
}, this.ws.onclose = (y) => {
|
|
1388
|
+
var v;
|
|
1389
|
+
console.log(`[WebSocket] Closed: code=${y.code} reason="${y.reason}" (session ${this.sessionLabel}, lastSeq=${this.lastSeq})`), this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingSentAt = null, this.sessionId = void 0, (v = this.onClose) == null || v.call(this, y.code, y.reason);
|
|
1390
|
+
};
|
|
1391
|
+
const w = 200, u = 3e4, g = 8e3, p = this.ws;
|
|
1392
|
+
this.sessionId = void 0;
|
|
1393
|
+
let C = 0, A = 0;
|
|
1394
|
+
for (; ; ) {
|
|
1395
|
+
if (this.ws !== p) {
|
|
1396
|
+
n("Connection attempt superseded by a newer connect()");
|
|
1397
|
+
return;
|
|
1398
|
+
}
|
|
1399
|
+
if (this.sessionId) break;
|
|
1400
|
+
if (p.readyState === WebSocket.CLOSING || p.readyState === WebSocket.CLOSED) {
|
|
1401
|
+
n("Connection closed before a session id was received");
|
|
1402
|
+
return;
|
|
1403
|
+
}
|
|
1404
|
+
if (p.readyState === WebSocket.CONNECTING && C >= u) {
|
|
1405
|
+
try {
|
|
1406
|
+
p.close();
|
|
1407
|
+
} catch {
|
|
1408
|
+
}
|
|
1409
|
+
n(`Server did not accept the connection within ${u / 1e3}s`);
|
|
1410
|
+
return;
|
|
1411
|
+
}
|
|
1412
|
+
if (p.readyState === WebSocket.OPEN && A >= g) {
|
|
1413
|
+
n(`Connected but no session id arrived within ${g / 1e3}s`);
|
|
1414
|
+
return;
|
|
1415
|
+
}
|
|
1416
|
+
C % 2e3 === 0 && console.log("Aguardando session Id"), await this.sleep(w), C += w, p.readyState === WebSocket.OPEN && (A += w);
|
|
1417
|
+
}
|
|
1418
|
+
console.log(`[WebSocket] Session ${this.sessionId} proven${this.lastSeq >= 0 ? ` (replaying from lastSeq=${this.lastSeq})` : ""}.`), this.lastKnownSessionId = this.sessionId, (Y = this.onOpen) == null || Y.call(this), this.flushPendingAnswers(this.sessionId), s(this.sessionId);
|
|
1419
|
+
});
|
|
1420
|
+
}
|
|
1421
|
+
/** Drop the current socket without reporting it: handlers off, then close. */
|
|
1422
|
+
detachSocket() {
|
|
1423
|
+
if (this.ws) {
|
|
1424
|
+
this.ws.onopen = null, this.ws.onmessage = null, this.ws.onerror = null, this.ws.onclose = null;
|
|
1425
|
+
try {
|
|
1426
|
+
this.ws.close();
|
|
1427
|
+
} catch {
|
|
1428
|
+
}
|
|
1429
|
+
this.ws = null;
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
async sleep(t) {
|
|
1433
|
+
return new Promise((e) => setTimeout(e, t));
|
|
1434
|
+
}
|
|
1435
|
+
/** The session this instance believes it is on — for log lines, never for logic. */
|
|
1436
|
+
get sessionLabel() {
|
|
1437
|
+
return this.sessionId ?? this.lastKnownSessionId ?? "none";
|
|
1438
|
+
}
|
|
1439
|
+
/**
|
|
1440
|
+
* Handle incoming messages from server
|
|
1441
|
+
*/
|
|
1442
|
+
handleMessage(t, e) {
|
|
1443
|
+
switch (typeof t.seq == "number" && t.seq > this.lastSeq && (this.lastSeq = t.seq), t.type) {
|
|
1444
|
+
case "Pong":
|
|
1445
|
+
if (this.sessionId = t.sessionId, this.lastKnownSessionId = t.sessionId ?? this.lastKnownSessionId, !t.sessionId) {
|
|
1446
|
+
console.error("Pong response has no SESSION ID");
|
|
1447
|
+
return;
|
|
1448
|
+
}
|
|
1449
|
+
t.accessToken && this.persistRefreshedAccessToken(t.accessToken);
|
|
1450
|
+
break;
|
|
1451
|
+
case "Suspended":
|
|
1452
|
+
this.onSuspended && this.onSuspended();
|
|
1453
|
+
break;
|
|
1454
|
+
case "Event":
|
|
1455
|
+
break;
|
|
1456
|
+
case "RewindLost":
|
|
1457
|
+
console.warn(
|
|
1458
|
+
`[WebSocket] RewindLost: lost events on resume, resuming from seq=${t.seq}`
|
|
1459
|
+
), typeof t.seq == "number" && (this.lastSeq = t.seq - 1), this.onRewindLost && t.sessionId && this.onRewindLost(t.sessionId, t.seq ?? -1);
|
|
1460
|
+
break;
|
|
1461
|
+
default:
|
|
1462
|
+
console.warn("[WebSocket] Unknown message type:", t.type);
|
|
1463
|
+
}
|
|
1464
|
+
const s = xt(t);
|
|
1465
|
+
return s ? (Wt(s) && this.emitFirstToken(s.interactionId), this.handleEvent(s, e), s) : null;
|
|
1466
|
+
}
|
|
1467
|
+
emitFirstToken(t) {
|
|
1468
|
+
var e;
|
|
1469
|
+
!t || this.firstTokenInteractions.has(t) || (this.statsTracker.resetForInteraction(), this.firstTokenInteractions.add(t), (e = this.onFirstToken) == null || e.call(this, t));
|
|
1470
|
+
}
|
|
1471
|
+
/**
|
|
1472
|
+
* Mirror a server-side-refreshed JWT into the stored user record so the global
|
|
1473
|
+
* fetch interceptor (packages/dashboard-app/.../EnvisionAuthProvider.tsx) picks
|
|
1474
|
+
* it up on the next HTTP call. Idempotent — the same token is delivered on
|
|
1475
|
+
* multiple consecutive Pong frames for listener-readiness, and we only write
|
|
1476
|
+
* when it actually changed.
|
|
1477
|
+
*
|
|
1478
|
+
* Uses the same localStorage key the auth provider reads (`envision_user`).
|
|
1479
|
+
* Done here in the WS layer rather than via a callback so consumers don't need
|
|
1480
|
+
* to wire up token-handling boilerplate; React contexts that hold the user in
|
|
1481
|
+
* memory will pick up the new token on the next refresh/render or via their
|
|
1482
|
+
* own storage listeners.
|
|
1483
|
+
*/
|
|
1484
|
+
persistRefreshedAccessToken(t) {
|
|
1485
|
+
const e = "envision_user";
|
|
1486
|
+
try {
|
|
1487
|
+
const s = localStorage.getItem(e);
|
|
1488
|
+
if (!s) {
|
|
1489
|
+
console.warn("[WebSocket] WS-refreshed token received but no stored user — dropping");
|
|
1490
|
+
return;
|
|
1491
|
+
}
|
|
1492
|
+
const n = JSON.parse(s);
|
|
1493
|
+
if ((n == null ? void 0 : n.access_token) === t) return;
|
|
1494
|
+
n.access_token = t, localStorage.setItem(e, JSON.stringify(n)), console.info("[WebSocket] Mirrored WS-refreshed JWT into stored user");
|
|
1495
|
+
} catch (s) {
|
|
1496
|
+
console.error("[WebSocket] Failed to persist WS-refreshed token", s);
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
closeStream() {
|
|
1500
|
+
this.disconnect();
|
|
1501
|
+
}
|
|
1502
|
+
suspendStream() {
|
|
1503
|
+
this.sendBaseMessage({
|
|
1504
|
+
Action: b.Suspend,
|
|
1505
|
+
AgentId: "",
|
|
1506
|
+
InteractionId: "",
|
|
1507
|
+
ModelId: ""
|
|
1508
|
+
});
|
|
1509
|
+
}
|
|
1510
|
+
/**
|
|
1511
|
+
* Send the user's answer to a parked ask_user tool call (ChatAction.AnswerHumanTool).
|
|
1512
|
+
*
|
|
1513
|
+
* Never throws on a dead socket: the parked tool answer is the one message whose loss
|
|
1514
|
+
* strands the whole turn (the askauth popup case — the socket idles out while the user
|
|
1515
|
+
* is at the IdP, the token comes back, and a plain send would throw into an unhandled
|
|
1516
|
+
* rejection with the answer gone). When the socket is not OPEN the answer is queued and
|
|
1517
|
+
* flushed by `onopen` on the next (re)connect of the same session.
|
|
1518
|
+
*
|
|
1519
|
+
* Returns 'sent' when it went out now, 'queued' when it will go out on reconnect.
|
|
1520
|
+
*/
|
|
1521
|
+
answerHumanTool(t, e) {
|
|
1522
|
+
const s = {
|
|
1523
|
+
Action: b.AnswerHumanTool,
|
|
1524
|
+
AgentId: "",
|
|
1525
|
+
InteractionId: "",
|
|
1526
|
+
ToolCallId: t,
|
|
1527
|
+
Answer: e
|
|
1528
|
+
};
|
|
1529
|
+
if (this.ws && this.ws.readyState === WebSocket.OPEN)
|
|
1530
|
+
try {
|
|
1531
|
+
return this.sendBaseMessage(s), "sent";
|
|
1532
|
+
} catch {
|
|
1533
|
+
}
|
|
1534
|
+
return this.queueAnswer(t, e), "queued";
|
|
1535
|
+
}
|
|
1536
|
+
queueAnswer(t, e) {
|
|
1537
|
+
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.`);
|
|
1538
|
+
}
|
|
1539
|
+
flushPendingAnswers(t) {
|
|
1540
|
+
if (this.pendingAnswers.length === 0) return;
|
|
1541
|
+
const e = this.pendingAnswers;
|
|
1542
|
+
this.pendingAnswers = [];
|
|
1543
|
+
for (const s of e) {
|
|
1544
|
+
if (s.sessionId && t && s.sessionId !== t) {
|
|
1545
|
+
console.warn(`[WebSocket] Dropping queued answer for tool call ${s.toolCallId} — it belongs to session ${s.sessionId}, reconnected to ${t}.`);
|
|
1546
|
+
continue;
|
|
1547
|
+
}
|
|
1548
|
+
try {
|
|
1549
|
+
this.sendBaseMessage({
|
|
1550
|
+
Action: b.AnswerHumanTool,
|
|
1551
|
+
AgentId: "",
|
|
1552
|
+
InteractionId: "",
|
|
1553
|
+
ToolCallId: s.toolCallId,
|
|
1554
|
+
Answer: s.answer
|
|
1555
|
+
}), console.info(`[WebSocket] Flushed queued answer for tool call ${s.toolCallId}.`);
|
|
1556
|
+
} catch {
|
|
1557
|
+
this.pendingAnswers.push(s);
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
/**
|
|
1562
|
+
* Send a message to the agent
|
|
1563
|
+
*/
|
|
1564
|
+
sendMessage(t) {
|
|
1565
|
+
this.sendBaseMessage(t);
|
|
1566
|
+
}
|
|
1567
|
+
sendBaseMessage(t) {
|
|
1568
|
+
if (this.lastActivity = (/* @__PURE__ */ new Date()).getTime(), !this.ws || this.ws.readyState !== WebSocket.OPEN)
|
|
1569
|
+
throw new Error("WebSocket is not connected");
|
|
1570
|
+
this.ws.send(JSON.stringify(t));
|
|
1571
|
+
}
|
|
1572
|
+
/**
|
|
1573
|
+
* Heartbeat: keep a quiet socket alive with a Ping every PING_INTERVAL_MS, and
|
|
1574
|
+
* declare it dead when a Ping goes PONG_TIMEOUT_MS without ANY inbound frame.
|
|
1575
|
+
* Started by `onopen`, stopped by `onclose`/`disconnect()`.
|
|
1576
|
+
*/
|
|
1577
|
+
monitor() {
|
|
1578
|
+
this.monitorInterval && clearInterval(this.monitorInterval), this.monitorInterval = setInterval(() => {
|
|
1579
|
+
try {
|
|
1580
|
+
if (!this.isConnected()) return;
|
|
1581
|
+
const t = Date.now();
|
|
1582
|
+
if (this.pingSentAt !== null) {
|
|
1583
|
+
const e = t - this.pingSentAt;
|
|
1584
|
+
if (e >= R) {
|
|
1585
|
+
this.failSocket(
|
|
1586
|
+
Lt,
|
|
1587
|
+
`No frame received for ${Math.round(e / 1e3)}s after a Ping`
|
|
1588
|
+
);
|
|
1589
|
+
return;
|
|
1590
|
+
}
|
|
1591
|
+
console.warn(`[WebSocket] Still no reply ${e}ms after the Ping (budget ${R}ms, session ${this.sessionLabel}) — the peer may be gone.`);
|
|
1592
|
+
return;
|
|
1593
|
+
}
|
|
1594
|
+
t - this.lastActivity >= Kt && this.ping();
|
|
1595
|
+
} catch (t) {
|
|
1596
|
+
console.error("Error on monitor", t);
|
|
1597
|
+
}
|
|
1598
|
+
}, zt);
|
|
1599
|
+
}
|
|
1600
|
+
/**
|
|
1601
|
+
* Send a heartbeat ping and start the reply clock (unless one is already running).
|
|
1602
|
+
*/
|
|
1603
|
+
ping() {
|
|
1604
|
+
this.sendBaseMessage({
|
|
1605
|
+
Action: "Ping",
|
|
1606
|
+
AgentId: "",
|
|
1607
|
+
InteractionId: "",
|
|
1608
|
+
ModelId: ""
|
|
1609
|
+
}), this.pingSentAt === null && (this.pingSentAt = Date.now(), console.log(`[WebSocket] Ping sent after ${Date.now() - this.lastActivity}ms of silence (session ${this.sessionLabel}); any frame within ${R}ms answers it.`));
|
|
1610
|
+
}
|
|
1611
|
+
/**
|
|
1612
|
+
* Behave as if the peer vanished: the socket is closed and reported as an abnormal close (1006),
|
|
1613
|
+
* exactly the path the heartbeat's dead-peer verdict takes. For demos and tests of the resume —
|
|
1614
|
+
* the supervisor redials with the replay cursor and the server replays what it buffered — on a
|
|
1615
|
+
* server that is still running; a real drop needs a cable pulled.
|
|
1616
|
+
*/
|
|
1617
|
+
simulateDrop() {
|
|
1618
|
+
this.failSocket(1006, "Simulated drop");
|
|
1619
|
+
}
|
|
1620
|
+
/**
|
|
1621
|
+
* Declare the current socket dead and run the close path NOW, without waiting
|
|
1622
|
+
* for the browser: for a half-open peer `onclose` can lag by minutes or never
|
|
1623
|
+
* come, and the decision has already been made. The dead socket's own onclose
|
|
1624
|
+
* handler is invoked with a client-local code, so the consumer sees exactly
|
|
1625
|
+
* what a server close would have produced. Handlers are detached first so a
|
|
1626
|
+
* late real close event cannot run it a second time.
|
|
1627
|
+
*/
|
|
1628
|
+
failSocket(t, e) {
|
|
1629
|
+
const s = this.ws;
|
|
1630
|
+
if (!s) return;
|
|
1631
|
+
console.warn(`[WebSocket] ${e} — treating the socket as dead (code=${t}, session ${this.sessionLabel}). readyState was ${s.readyState} (OPEN=${WebSocket.OPEN}), which is why nothing else noticed. Running the close path now.`);
|
|
1632
|
+
const n = s.onclose;
|
|
1633
|
+
s.onopen = null, s.onmessage = null, s.onerror = null, s.onclose = null;
|
|
1634
|
+
try {
|
|
1635
|
+
s.close();
|
|
1636
|
+
} catch {
|
|
1637
|
+
}
|
|
1638
|
+
n == null || n.call(s, { code: t, reason: e });
|
|
1639
|
+
}
|
|
1640
|
+
/**
|
|
1641
|
+
* Disconnect the WebSocket
|
|
1642
|
+
*/
|
|
1643
|
+
disconnect() {
|
|
1644
|
+
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(ot, "Intentional disconnect"), this.ws = null);
|
|
1645
|
+
}
|
|
1646
|
+
/**
|
|
1647
|
+
* Check if connected
|
|
1648
|
+
*/
|
|
1649
|
+
isConnected() {
|
|
1650
|
+
return this.ws !== null && this.ws.readyState === WebSocket.OPEN;
|
|
1651
|
+
}
|
|
1652
|
+
async handleEvent(t, e) {
|
|
1653
|
+
var s;
|
|
1654
|
+
try {
|
|
1655
|
+
const n = N.parseFromTypedEvent(t);
|
|
1656
|
+
if (!n)
|
|
1657
|
+
throw "Server event was null";
|
|
1658
|
+
this.statsTracker.record({
|
|
1659
|
+
rawLength: e.length,
|
|
1660
|
+
textLength: ((s = t.text) == null ? void 0 : s.length) ?? 0,
|
|
1661
|
+
sessionInformation: n.session_information,
|
|
1662
|
+
fromSubAgent: !!n.subAgentId
|
|
1663
|
+
}), this.onEvent && this.onEvent(n).catch((r) => {
|
|
1664
|
+
console.error("Lost error on on-event", r);
|
|
1665
|
+
});
|
|
1666
|
+
} catch (n) {
|
|
1667
|
+
console.error("handleEvent error", n);
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
};
|
|
1671
|
+
d(J, "WebSocketConnecionV2");
|
|
1672
|
+
let nt = J;
|
|
1673
|
+
const j = class j {
|
|
1674
|
+
constructor(t, e) {
|
|
1675
|
+
o(this, "cache", /* @__PURE__ */ new Map());
|
|
1676
|
+
o(this, "serverBaseUrl");
|
|
1677
|
+
o(this, "accessToken");
|
|
1678
|
+
this.serverBaseUrl = t.replace(/\/$/, ""), this.accessToken = e;
|
|
1679
|
+
}
|
|
1680
|
+
get headers() {
|
|
1681
|
+
return { Authorization: `Bearer ${St(this.accessToken)}` };
|
|
1682
|
+
}
|
|
1683
|
+
async init() {
|
|
1684
|
+
}
|
|
1685
|
+
getArtifacts() {
|
|
1686
|
+
return Array.from(this.cache.values());
|
|
1687
|
+
}
|
|
1688
|
+
async saveArtifact(t) {
|
|
1689
|
+
this.cache.set(t.id, t);
|
|
1690
|
+
}
|
|
1691
|
+
saveArtifactToCache(t) {
|
|
1692
|
+
this.cache.set(t.id, t);
|
|
1693
|
+
}
|
|
1694
|
+
async deleteArtifact(t) {
|
|
1695
|
+
this.cache.delete(t);
|
|
1696
|
+
}
|
|
1697
|
+
addToCache(t) {
|
|
1698
|
+
this.cache.set(t.id, t);
|
|
1699
|
+
}
|
|
1700
|
+
getArtifactWithCache(t) {
|
|
1701
|
+
return this.cache.get(t) ?? null;
|
|
1702
|
+
}
|
|
1703
|
+
async getArtifact(t, e) {
|
|
1704
|
+
if (this.cache.has(t)) return this.cache.get(t) ?? null;
|
|
1705
|
+
try {
|
|
1706
|
+
const s = await fetch(`${this.serverBaseUrl}/AdminArtifact/${t}`, {
|
|
1707
|
+
headers: this.headers
|
|
1708
|
+
});
|
|
1709
|
+
if (!s.ok) return null;
|
|
1710
|
+
const n = await s.json();
|
|
1711
|
+
return this.cache.set(n.id, n), n;
|
|
1712
|
+
} catch {
|
|
1713
|
+
return null;
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
async clearAllArtifacts() {
|
|
1717
|
+
this.cache.clear();
|
|
1718
|
+
}
|
|
1719
|
+
async getFileContent(t) {
|
|
1720
|
+
try {
|
|
1721
|
+
const e = await fetch(t, { headers: this.headers });
|
|
1722
|
+
return e.ok ? await e.text() : null;
|
|
1723
|
+
} catch {
|
|
1724
|
+
return null;
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
};
|
|
1728
|
+
d(j, "HttpArtifactService");
|
|
1729
|
+
let it = j;
|
|
1730
|
+
export {
|
|
1731
|
+
tt as A,
|
|
1732
|
+
F as C,
|
|
1733
|
+
Z as E,
|
|
1734
|
+
it as H,
|
|
1735
|
+
M as I,
|
|
1736
|
+
V as L,
|
|
1737
|
+
Tt as M,
|
|
1738
|
+
Nt as W,
|
|
1739
|
+
P as a,
|
|
1740
|
+
nt as b,
|
|
1741
|
+
$t as r,
|
|
1742
|
+
te as u
|
|
1743
|
+
};
|
|
1744
|
+
//# sourceMappingURL=httpArtifactService-EEhF_mp9.js.map
|