@aintela/chat 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -0
- package/dist/components.js +7528 -7182
- package/dist/components.js.map +1 -1
- package/dist/{httpArtifactService-DYQDPVVH.js → detachedRunActivity-CjyFTKSw.js} +769 -324
- package/dist/detachedRunActivity-CjyFTKSw.js.map +1 -0
- package/dist/detachedRunModel-X59Pb5V-.js +67 -0
- package/dist/{detachedRunModel-1ii9qGTW.js.map → detachedRunModel-X59Pb5V-.js.map} +1 -1
- package/dist/hooks.js +1 -1
- package/dist/httpSessionService-Ckb9Cxia.js +320 -0
- package/dist/httpSessionService-Ckb9Cxia.js.map +1 -0
- package/dist/index.js +296 -274
- package/dist/models.js +47 -41
- package/dist/{serializer-BNsp8xs2.js → serializer-DNUH6kgE.js} +567 -507
- package/dist/serializer-DNUH6kgE.js.map +1 -0
- package/dist/services.js +22 -15
- package/dist/src/components/AiChat/AiChatContext.d.ts +3 -1
- package/dist/src/components/AiChat/AiChatTypes.d.ts +7 -1
- package/dist/src/components/AiChat/ChatPane/InteractionOriginBadge.d.ts +15 -0
- package/dist/src/components/AiChat/ChatPane/messageUserOrigin.test.d.ts +1 -0
- package/dist/src/components/AiChat/aiChatEngine.d.ts +13 -1
- package/dist/src/components/index.d.ts +2 -0
- package/dist/src/components/v2/DetachedRunTaskBox.d.ts +30 -5
- package/dist/src/components/v2/DetachedRunTaskBox.live.test.d.ts +1 -0
- package/dist/src/components/v2/DetachedRunTranscript.d.ts +89 -0
- package/dist/src/components/v2/DetachedRunTranscript.test.d.ts +1 -0
- package/dist/src/components/v2/index.d.ts +5 -0
- package/dist/src/components/v2/useDetachedRunLiveActivity.d.ts +30 -0
- package/dist/src/components/v2/useDetachedRunResumeKey.d.ts +15 -0
- package/dist/src/components/v2/useDetachedRunResumeKey.test.d.ts +1 -0
- package/dist/src/models/Interaction.d.ts +15 -0
- package/dist/src/models/detachedRunModel.d.ts +11 -0
- package/dist/src/models/enums.d.ts +3 -1
- package/dist/src/models/index.d.ts +4 -3
- package/dist/src/models/semanticKernelModel/models.d.ts +22 -1
- package/dist/src/services/WebSocketConnection/WebSocketConnectionV2.d.ts +2 -1
- package/dist/src/services/WebSocketConnection/webSocketConnection.d.ts +15 -2
- package/dist/src/services/detachedRun/DetachedRunFramesTransport.d.ts +68 -0
- package/dist/src/services/detachedRun/DetachedRunFramesTransport.test.d.ts +1 -0
- package/dist/src/services/detachedRun/detachedRunActivity.d.ts +25 -0
- package/dist/src/services/detachedRun/streamDetachedRunFrames.d.ts +110 -0
- package/dist/src/services/detachedRun/streamDetachedRunFrames.test.d.ts +1 -0
- package/dist/src/services/index.d.ts +7 -0
- package/dist/src/services/servers/AgentGatewayService.d.ts +1 -1
- package/dist/src/services/servers/AgentGatewayWSAsync.d.ts +67 -1
- package/dist/src/services/servers/gatewayAnnounceDetachedRun.test.d.ts +1 -0
- package/dist/src/services/servers/gatewayInteractionStarted.test.d.ts +1 -0
- package/dist/src/services/wire/decodeFrame.d.ts +6 -1
- package/dist/tests/fakes/fakeWebSocket.d.ts +8 -2
- package/dist/tests/fakes/makeGateway.d.ts +3 -1
- package/dist/{useChatSessions-Q41Jmr6P.js → useChatSessions-aTjNcj8q.js} +2 -2
- package/dist/{useChatSessions-Q41Jmr6P.js.map → useChatSessions-aTjNcj8q.js.map} +1 -1
- package/package.json +1 -1
- package/dist/detachedRunModel-1ii9qGTW.js +0 -50
- package/dist/httpArtifactService-DYQDPVVH.js.map +0 -1
- package/dist/httpSessionService-BY7JeW8d.js +0 -309
- package/dist/httpSessionService-BY7JeW8d.js.map +0 -1
- package/dist/serializer-BNsp8xs2.js.map +0 -1
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var o = (i, t, e) =>
|
|
5
|
-
import {
|
|
6
|
-
import { format as
|
|
7
|
-
import
|
|
8
|
-
import { C as
|
|
9
|
-
import { d as
|
|
10
|
-
import { r as
|
|
11
|
-
const
|
|
1
|
+
var mt = Object.defineProperty;
|
|
2
|
+
var Rt = (i, t, e) => t in i ? mt(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
|
|
3
|
+
var h = (i, t) => mt(i, "name", { value: t, configurable: !0 });
|
|
4
|
+
var o = (i, t, e) => Rt(i, typeof t != "symbol" ? t + "" : t, e);
|
|
5
|
+
import { i as N, E as I, S as x, z as wt, C as U, j as bt, L as Lt, P as z, n as Pt, q as Ft, T as _t, o as Nt, s as et } from "./serializer-DNUH6kgE.js";
|
|
6
|
+
import { format as Ut } from "date-fns";
|
|
7
|
+
import xt from "lodash";
|
|
8
|
+
import { C as E, P as qt } from "./Prompt-DZb7OaPp.js";
|
|
9
|
+
import { d as Wt } from "./environmentUtils-VZNTCzEE.js";
|
|
10
|
+
import { r as Gt } from "./httpSessionService-Ckb9Cxia.js";
|
|
11
|
+
const Q = {
|
|
12
12
|
PROMPTS: "envision-prompts"
|
|
13
|
-
},
|
|
13
|
+
}, Bt = 50, nt = class nt {
|
|
14
14
|
getPrompts() {
|
|
15
15
|
try {
|
|
16
|
-
const t = localStorage.getItem(
|
|
16
|
+
const t = localStorage.getItem(Q.PROMPTS);
|
|
17
17
|
return t ? JSON.parse(t).sort((s, n) => new Date(n.created).getTime() - new Date(s.created).getTime()) : [];
|
|
18
18
|
} catch (t) {
|
|
19
19
|
return console.error("Error loading prompts:", t), [];
|
|
@@ -40,29 +40,29 @@ const b = {
|
|
|
40
40
|
storePrompt(t) {
|
|
41
41
|
try {
|
|
42
42
|
const e = this.getPrompts().filter((s) => s.promptText !== t.promptText);
|
|
43
|
-
e.unshift(t), localStorage.setItem(
|
|
43
|
+
e.unshift(t), localStorage.setItem(Q.PROMPTS, JSON.stringify(e.slice(0, Bt)));
|
|
44
44
|
} catch (e) {
|
|
45
45
|
console.error("Error storing prompt:", e);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
clearAllPrompts() {
|
|
49
49
|
try {
|
|
50
|
-
localStorage.removeItem(
|
|
50
|
+
localStorage.removeItem(Q.PROMPTS);
|
|
51
51
|
} catch (t) {
|
|
52
52
|
console.error("Error clearing prompts:", t);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
|
-
|
|
57
|
-
let
|
|
58
|
-
const
|
|
56
|
+
h(nt, "LocalStorageService");
|
|
57
|
+
let St = nt;
|
|
58
|
+
const De = /* @__PURE__ */ h((i) => {
|
|
59
59
|
const t = i.getPrompts(), e = t.length;
|
|
60
60
|
if (e > 0) {
|
|
61
61
|
const s = t[0].promptText, n = t[t.length - 1].promptText, r = t[0].created;
|
|
62
62
|
return { promptState: e + "_" + s + "_" + n + "_" + r };
|
|
63
63
|
} else
|
|
64
64
|
return { promptState: "0" };
|
|
65
|
-
}, "usePromptState"),
|
|
65
|
+
}, "usePromptState"), it = class it {
|
|
66
66
|
constructor() {
|
|
67
67
|
o(this, "artifactGenerated", "artifactGenerated");
|
|
68
68
|
o(this, "artifactSelected", "artifactSelected");
|
|
@@ -80,9 +80,9 @@ const te = /* @__PURE__ */ d((i) => {
|
|
|
80
80
|
o(this, "gatewayFirstToken", "gatewayFirstToken");
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
|
-
|
|
84
|
-
let
|
|
85
|
-
const
|
|
83
|
+
h(it, "EventTypes");
|
|
84
|
+
let X = it;
|
|
85
|
+
const d = new X(), rt = class rt {
|
|
86
86
|
constructor() {
|
|
87
87
|
o(this, "listeners", {});
|
|
88
88
|
}
|
|
@@ -103,95 +103,95 @@ const l = new U(), B = class B {
|
|
|
103
103
|
}
|
|
104
104
|
/* typed artifact listeners */
|
|
105
105
|
artifactOnGenerated(t) {
|
|
106
|
-
this.addListener(
|
|
106
|
+
this.addListener(d.artifactGenerated, t);
|
|
107
107
|
}
|
|
108
108
|
artifactEmitGenerated(t) {
|
|
109
|
-
this.callListeners(
|
|
109
|
+
this.callListeners(d.artifactGenerated, t);
|
|
110
110
|
}
|
|
111
111
|
artifactOffGenerated(t) {
|
|
112
|
-
this.removeListener(
|
|
112
|
+
this.removeListener(d.artifactGenerated, t);
|
|
113
113
|
}
|
|
114
114
|
artifactOnSelected(t) {
|
|
115
|
-
this.addListener(
|
|
115
|
+
this.addListener(d.artifactSelected, t);
|
|
116
116
|
}
|
|
117
117
|
artifactEmitSelected(t) {
|
|
118
|
-
this.callListeners(
|
|
118
|
+
this.callListeners(d.artifactSelected, t);
|
|
119
119
|
}
|
|
120
120
|
artifactOffSelected(t) {
|
|
121
|
-
this.removeListener(
|
|
121
|
+
this.removeListener(d.artifactSelected, t);
|
|
122
122
|
}
|
|
123
123
|
gatewayOnMessage(t) {
|
|
124
|
-
this.addListener(
|
|
124
|
+
this.addListener(d.gatewayMessage, t);
|
|
125
125
|
}
|
|
126
126
|
gatewayEmitMessage(t) {
|
|
127
|
-
this.callListeners(
|
|
127
|
+
this.callListeners(d.gatewayMessage, t);
|
|
128
128
|
}
|
|
129
129
|
gatewayOffMessage(t) {
|
|
130
|
-
this.removeListener(
|
|
130
|
+
this.removeListener(d.gatewayMessage, t);
|
|
131
131
|
}
|
|
132
132
|
gatewayOnTurnComplete(t) {
|
|
133
|
-
this.addListener(
|
|
133
|
+
this.addListener(d.gatewayTurnComplete, t);
|
|
134
134
|
}
|
|
135
135
|
gatewayEmitTurnComplete(t, e) {
|
|
136
|
-
this.callListeners(
|
|
136
|
+
this.callListeners(d.gatewayTurnComplete, t, e);
|
|
137
137
|
}
|
|
138
138
|
gatewayOffTurnComplete(t) {
|
|
139
|
-
this.removeListener(
|
|
139
|
+
this.removeListener(d.gatewayTurnComplete, t);
|
|
140
140
|
}
|
|
141
141
|
gatewayOnTurnOpen(t) {
|
|
142
|
-
this.addListener(
|
|
142
|
+
this.addListener(d.gatewayTurnOpen, t);
|
|
143
143
|
}
|
|
144
144
|
gatewayEmitTurnOpen(t) {
|
|
145
|
-
this.callListeners(
|
|
145
|
+
this.callListeners(d.gatewayTurnOpen, t);
|
|
146
146
|
}
|
|
147
147
|
gatewayOffTurnOpen(t) {
|
|
148
|
-
this.removeListener(
|
|
148
|
+
this.removeListener(d.gatewayTurnOpen, t);
|
|
149
149
|
}
|
|
150
150
|
gatewayOnStreamError(t) {
|
|
151
|
-
this.addListener(
|
|
151
|
+
this.addListener(d.gatewayStreamError, t);
|
|
152
152
|
}
|
|
153
153
|
gatewayEmitStreamError(t) {
|
|
154
|
-
this.callListeners(
|
|
154
|
+
this.callListeners(d.gatewayStreamError, t);
|
|
155
155
|
}
|
|
156
156
|
gatewayOffStreamError(t) {
|
|
157
|
-
this.removeListener(
|
|
157
|
+
this.removeListener(d.gatewayStreamError, t);
|
|
158
158
|
}
|
|
159
159
|
/** The live socket is up and the session proven — on the first open and on every reconnect (`info.reconnect`). */
|
|
160
160
|
gatewayOnConnected(t) {
|
|
161
|
-
this.addListener(
|
|
161
|
+
this.addListener(d.gatewayConnected, t);
|
|
162
162
|
}
|
|
163
163
|
gatewayEmitConnected(t, e) {
|
|
164
|
-
this.callListeners(
|
|
164
|
+
this.callListeners(d.gatewayConnected, t, e);
|
|
165
165
|
}
|
|
166
166
|
gatewayOffConnected(t) {
|
|
167
|
-
this.removeListener(
|
|
167
|
+
this.removeListener(d.gatewayConnected, t);
|
|
168
168
|
}
|
|
169
169
|
chatOnMessageSent(t) {
|
|
170
|
-
this.addListener(
|
|
170
|
+
this.addListener(d.onMessageSent, t);
|
|
171
171
|
}
|
|
172
172
|
chatOffMessageSent(t) {
|
|
173
|
-
this.removeListener(
|
|
173
|
+
this.removeListener(d.onMessageSent, t);
|
|
174
174
|
}
|
|
175
175
|
ChatEmitMessageSent(t, e) {
|
|
176
|
-
this.callListeners(
|
|
176
|
+
this.callListeners(d.onMessageSent, t, e);
|
|
177
177
|
}
|
|
178
178
|
chatOnMessageError(t) {
|
|
179
|
-
this.addListener(
|
|
179
|
+
this.addListener(d.onMessageError, t);
|
|
180
180
|
}
|
|
181
181
|
chatOffMessageError(t) {
|
|
182
|
-
this.removeListener(
|
|
182
|
+
this.removeListener(d.onMessageError, t);
|
|
183
183
|
}
|
|
184
184
|
ChatEmitMessageError(t) {
|
|
185
|
-
this.callListeners(
|
|
185
|
+
this.callListeners(d.onMessageError, t);
|
|
186
186
|
}
|
|
187
187
|
gatewayOnFunctionResponse(t) {
|
|
188
|
-
this.addListener(
|
|
188
|
+
this.addListener(d.gatewayFunctionResponse, t);
|
|
189
189
|
}
|
|
190
190
|
gatewayEmitFunctionResponse(t) {
|
|
191
|
-
this.callListeners(
|
|
191
|
+
this.callListeners(d.gatewayFunctionResponse, t);
|
|
192
192
|
}
|
|
193
193
|
gatewayOffFunctionResponse(t) {
|
|
194
|
-
this.removeListener(
|
|
194
|
+
this.removeListener(d.gatewayFunctionResponse, t);
|
|
195
195
|
}
|
|
196
196
|
// "Re-ask this" — a `#ask-…` link in the transcript, carrying the link's TEXT as the question.
|
|
197
197
|
// An event rather than component state because the prompt that must send it is not always
|
|
@@ -200,60 +200,60 @@ const l = new U(), B = class B {
|
|
|
200
200
|
// listens; ChatPane publishes only when its internal one is suppressed, so the question is
|
|
201
201
|
// never sent twice.
|
|
202
202
|
uiOnAskQuestion(t) {
|
|
203
|
-
this.addListener(
|
|
203
|
+
this.addListener(d.uiAskQuestion, t);
|
|
204
204
|
}
|
|
205
205
|
uiEmitAskQuestion(t) {
|
|
206
|
-
this.callListeners(
|
|
206
|
+
this.callListeners(d.uiAskQuestion, t);
|
|
207
207
|
}
|
|
208
208
|
uiOffAskQuestion(t) {
|
|
209
|
-
this.removeListener(
|
|
209
|
+
this.removeListener(d.uiAskQuestion, t);
|
|
210
210
|
}
|
|
211
211
|
gatewayOnEndMessageData(t) {
|
|
212
|
-
this.addListener(
|
|
212
|
+
this.addListener(d.gatewayEndMessageData, t);
|
|
213
213
|
}
|
|
214
214
|
gatewayEmitEndMessageData(t) {
|
|
215
|
-
this.callListeners(
|
|
215
|
+
this.callListeners(d.gatewayEndMessageData, t);
|
|
216
216
|
}
|
|
217
217
|
gatewayOffEndMessageData(t) {
|
|
218
|
-
this.removeListener(
|
|
218
|
+
this.removeListener(d.gatewayEndMessageData, t);
|
|
219
219
|
}
|
|
220
220
|
gatewayOnToolEvent(t) {
|
|
221
|
-
this.addListener(
|
|
221
|
+
this.addListener(d.onToolEvent, t);
|
|
222
222
|
}
|
|
223
223
|
gatewayEmitToolEvent(t, e, s) {
|
|
224
|
-
this.callListeners(
|
|
224
|
+
this.callListeners(d.onToolEvent, t, e, s);
|
|
225
225
|
}
|
|
226
226
|
gatewayOffToolEvent(t) {
|
|
227
|
-
this.removeListener(
|
|
227
|
+
this.removeListener(d.onToolEvent, t);
|
|
228
228
|
}
|
|
229
229
|
gatewayOnFirstToken(t) {
|
|
230
|
-
this.addListener(
|
|
230
|
+
this.addListener(d.gatewayFirstToken, t);
|
|
231
231
|
}
|
|
232
232
|
gatewayEmitFirstToken(t) {
|
|
233
|
-
this.callListeners(
|
|
233
|
+
this.callListeners(d.gatewayFirstToken, t);
|
|
234
234
|
}
|
|
235
235
|
gatewayOffFirstToken(t) {
|
|
236
|
-
this.removeListener(
|
|
236
|
+
this.removeListener(d.gatewayFirstToken, t);
|
|
237
237
|
}
|
|
238
238
|
};
|
|
239
|
-
|
|
240
|
-
let
|
|
241
|
-
const
|
|
242
|
-
function
|
|
239
|
+
h(rt, "EventBusService");
|
|
240
|
+
let It = rt;
|
|
241
|
+
const zt = 2e3;
|
|
242
|
+
function q(i) {
|
|
243
243
|
i.parts === i.prev.parts && (i.parts = i.prev.parts.slice());
|
|
244
244
|
}
|
|
245
|
-
|
|
246
|
-
function
|
|
245
|
+
h(q, "ownParts");
|
|
246
|
+
function J(i) {
|
|
247
247
|
i.functionMap === i.prev.functionMap && (i.functionMap = new Map(i.functionMap));
|
|
248
248
|
}
|
|
249
|
-
|
|
250
|
-
const
|
|
251
|
-
function
|
|
249
|
+
h(J, "ownFunctionMap");
|
|
250
|
+
const Ht = /* @__PURE__ */ h((i) => i == I.FunctionCall || i == I.PartialFunctionCall, "isFunctionCall"), Jt = /* @__PURE__ */ h((i) => i == I.FunctionResponse, "isFunctionResponse"), At = /* @__PURE__ */ h((i) => i.parts.length + 1 + "-" + i.prev.interactionId, "nextPartId");
|
|
251
|
+
function jt(i, t) {
|
|
252
252
|
var e, s, n, r, a;
|
|
253
|
-
return !!(!t || i.mustPush || i.mustPush === !1 && (i.eventType !== t.eventType || ((e = i.functionDetails) == null ? void 0 : e.id) !== ((s = t.functionDetails) == null ? void 0 : s.id)) || i.textAppendable && (((r = (n = t.thoughtDetails) == null ? void 0 : n.text) == null ? void 0 : r.length) ?? ((a = t.text) == null ? void 0 : a.length) ?? 0) >
|
|
253
|
+
return !!(!t || i.mustPush || i.mustPush === !1 && (i.eventType !== t.eventType || ((e = i.functionDetails) == null ? void 0 : e.id) !== ((s = t.functionDetails) == null ? void 0 : s.id)) || i.textAppendable && (((r = (n = t.thoughtDetails) == null ? void 0 : n.text) == null ? void 0 : r.length) ?? ((a = t.text) == null ? void 0 : a.length) ?? 0) > zt);
|
|
254
254
|
}
|
|
255
|
-
|
|
256
|
-
function
|
|
255
|
+
h(jt, "opensNewPart");
|
|
256
|
+
function Kt(i, t) {
|
|
257
257
|
const e = t.functionDetails.id, s = t.functionDetails.clientOutput, n = i.parts.findIndex((r) => {
|
|
258
258
|
var a;
|
|
259
259
|
return ((a = r.functionDetails) == null ? void 0 : a.id) === e;
|
|
@@ -268,66 +268,66 @@ function Et(i, t) {
|
|
|
268
268
|
parked: t.functionDetails.parked === !0 || r.functionDetails.parked === !0
|
|
269
269
|
}
|
|
270
270
|
};
|
|
271
|
-
|
|
271
|
+
q(i), i.parts[n] = a, J(i), i.functionMap.set(e, a);
|
|
272
272
|
} else {
|
|
273
273
|
const r = {
|
|
274
274
|
...t,
|
|
275
|
-
id:
|
|
275
|
+
id: At(i),
|
|
276
276
|
functionDetails: { ...t.functionDetails, silent: !0 }
|
|
277
277
|
};
|
|
278
|
-
|
|
278
|
+
q(i), i.parts.push(r), J(i), i.functionMap.set(e, r);
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
|
-
|
|
282
|
-
function
|
|
283
|
-
var
|
|
284
|
-
const r = i.parts.findIndex((
|
|
285
|
-
var
|
|
286
|
-
return ((
|
|
287
|
-
}), a = r > -1 ? i.parts[r] : e, c = t.functionDetails,
|
|
281
|
+
h(Kt, "foldClientOutput");
|
|
282
|
+
function Qt(i, t, e, s, n) {
|
|
283
|
+
var p;
|
|
284
|
+
const r = i.parts.findIndex((m) => {
|
|
285
|
+
var u;
|
|
286
|
+
return ((u = m.functionDetails) == null ? void 0 : u.id) === s;
|
|
287
|
+
}), a = r > -1 ? i.parts[r] : e, c = t.functionDetails, l = a.functionDetails, f = {
|
|
288
288
|
...a,
|
|
289
289
|
eventType: t.eventType,
|
|
290
290
|
functionDetails: {
|
|
291
|
-
id:
|
|
292
|
-
name: c.name ??
|
|
291
|
+
id: l.id,
|
|
292
|
+
name: c.name ?? l.name,
|
|
293
293
|
// The settled FunctionCall carries the parsed args; the PartialFunctionCall stream it
|
|
294
294
|
// folds onto only accumulated raw JSON in `.text`.
|
|
295
|
-
args: c.args ??
|
|
295
|
+
args: c.args ?? l.args,
|
|
296
296
|
response: c.response,
|
|
297
297
|
status: c.status ?? "Composing",
|
|
298
|
-
start: c.start ??
|
|
299
|
-
end: c.end ??
|
|
300
|
-
isUi: c.isUi === !0 ||
|
|
298
|
+
start: c.start ?? l.start,
|
|
299
|
+
end: c.end ?? l.end,
|
|
300
|
+
isUi: c.isUi === !0 || l.isUi === !0,
|
|
301
301
|
// Keep the call's friendly args summary when the result event (which has none) folds in.
|
|
302
|
-
argsDescription: c.argsDescription ??
|
|
302
|
+
argsDescription: c.argsDescription ?? l.argsDescription,
|
|
303
303
|
// The tool's client-only payload rides the RESULT event; sticky so a later rep without
|
|
304
304
|
// one can't clobber it. This is what a uiTool renderer reads.
|
|
305
|
-
clientOutput: c.clientOutput ??
|
|
305
|
+
clientOutput: c.clientOutput ?? l.clientOutput,
|
|
306
306
|
// Ask-user component ([KernelUIComponent]) — sticky like isUi/clientOutput. The streaming
|
|
307
307
|
// final CALL carries it, the PartialFunctionCall it folds onto may not (issue #60).
|
|
308
|
-
askUserComponent: c.askUserComponent ??
|
|
309
|
-
isAskUser: c.isAskUser ||
|
|
308
|
+
askUserComponent: c.askUserComponent ?? l.askUserComponent,
|
|
309
|
+
isAskUser: c.isAskUser || l.isAskUser || !!(c.askUserComponent ?? l.askUserComponent),
|
|
310
310
|
// Runtime "don't render" override rides the RESULT; sticky so it survives the fold.
|
|
311
|
-
cancelUi: c.cancelUi === !0 ||
|
|
312
|
-
parked: c.parked === !0 ||
|
|
311
|
+
cancelUi: c.cancelUi === !0 || l.cancelUi === !0,
|
|
312
|
+
parked: c.parked === !0 || l.parked === !0
|
|
313
313
|
}
|
|
314
314
|
};
|
|
315
|
-
|
|
315
|
+
J(i), i.functionMap.set(s, f), f.eventType === I.FunctionResponse && ((p = n == null ? void 0 : n.onFunctionResponse) == null || p.call(n, f.functionDetails)), r > -1 && (q(i), i.parts[r] = f);
|
|
316
316
|
}
|
|
317
|
-
|
|
318
|
-
function
|
|
319
|
-
s && t.functionDetails && (
|
|
317
|
+
h(Qt, "foldFunctionEvent");
|
|
318
|
+
function Yt(i, t, e, s) {
|
|
319
|
+
s && t.functionDetails && (J(i), i.functionMap.set(s, t));
|
|
320
320
|
const n = i.prev.parts[i.prev.parts.length - 1] ?? null;
|
|
321
|
-
n && n.textAppendable && (
|
|
321
|
+
n && n.textAppendable && (q(i), i.parts[i.parts.length - 1] = { ...n, ended: /* @__PURE__ */ new Date() });
|
|
322
322
|
const r = {
|
|
323
323
|
...t,
|
|
324
|
-
id:
|
|
324
|
+
id: At(i),
|
|
325
325
|
partial: e.partial
|
|
326
326
|
};
|
|
327
327
|
i.parts = [...i.parts, r];
|
|
328
328
|
}
|
|
329
|
-
|
|
330
|
-
function
|
|
329
|
+
h(Yt, "openPart");
|
|
330
|
+
function Xt(i, t, e, s) {
|
|
331
331
|
const n = i.parts[i.parts.length - 1] ?? null;
|
|
332
332
|
if (!n) return;
|
|
333
333
|
const r = {
|
|
@@ -342,10 +342,10 @@ function Ot(i, t, e, s) {
|
|
|
342
342
|
}
|
|
343
343
|
} else
|
|
344
344
|
r.text = t.text ?? "", r.textDetails.version++, t.thoughtDetails && (r.thoughtDetails = { ...t.thoughtDetails, text: t.thoughtDetails.text.trim() });
|
|
345
|
-
|
|
345
|
+
q(i), i.parts[i.parts.length - 1] = r;
|
|
346
346
|
}
|
|
347
|
-
|
|
348
|
-
function
|
|
347
|
+
h(Xt, "appendText");
|
|
348
|
+
function Vt(i, t) {
|
|
349
349
|
if (!t || t.length === 0) return i;
|
|
350
350
|
const e = i.slice();
|
|
351
351
|
for (const s of t) {
|
|
@@ -354,10 +354,10 @@ function kt(i, t) {
|
|
|
354
354
|
}
|
|
355
355
|
return e;
|
|
356
356
|
}
|
|
357
|
-
|
|
358
|
-
function
|
|
359
|
-
var c,
|
|
360
|
-
const s =
|
|
357
|
+
h(Vt, "mergeArtifacts");
|
|
358
|
+
function Zt(i, t, e) {
|
|
359
|
+
var c, l;
|
|
360
|
+
const s = N.FlatParts(t == null ? void 0 : t.parts), n = i.parts[i.parts.length - 1] ?? null, r = {
|
|
361
361
|
prev: i,
|
|
362
362
|
parts: i.parts,
|
|
363
363
|
functionMap: i.functionMap ?? /* @__PURE__ */ new Map()
|
|
@@ -365,28 +365,28 @@ function Dt(i, t, e) {
|
|
|
365
365
|
let a = !1;
|
|
366
366
|
if (s) {
|
|
367
367
|
if (s.eventType === I.FunctionClientOutput && !!((c = s.functionDetails) != null && c.id))
|
|
368
|
-
|
|
369
|
-
else if (
|
|
370
|
-
const
|
|
371
|
-
|
|
372
|
-
const
|
|
373
|
-
|
|
368
|
+
Kt(r, s);
|
|
369
|
+
else if (jt(s, n)) {
|
|
370
|
+
const p = Ht(s.eventType) || Jt(s.eventType), m = p ? (l = s.functionDetails) == null ? void 0 : l.id : void 0;
|
|
371
|
+
p && !m && console.error("Got isCall or isResponse without a callId", s);
|
|
372
|
+
const u = m ? r.functionMap.get(m) : void 0;
|
|
373
|
+
u && m && s.functionDetails ? Qt(r, s, u, m, e) : (Yt(r, s, t, m), a = !0);
|
|
374
374
|
}
|
|
375
|
-
s.textAppendable &&
|
|
375
|
+
s.textAppendable && Xt(r, s, t, a);
|
|
376
376
|
}
|
|
377
377
|
return {
|
|
378
378
|
...i,
|
|
379
379
|
version: i.version + 1,
|
|
380
380
|
parts: r.parts,
|
|
381
|
-
artifactData:
|
|
381
|
+
artifactData: Vt(i.artifactData ?? [], t.llmArtifacts),
|
|
382
382
|
functionMap: r.functionMap,
|
|
383
383
|
turn_complete: t.turn_complete,
|
|
384
384
|
partial: t.partial,
|
|
385
385
|
asyncFinalResponse: t.asyncFinalResponse
|
|
386
386
|
};
|
|
387
387
|
}
|
|
388
|
-
|
|
389
|
-
const
|
|
388
|
+
h(Zt, "reduceInteraction");
|
|
389
|
+
const ot = class ot {
|
|
390
390
|
constructor(t, e) {
|
|
391
391
|
o(this, "interaction");
|
|
392
392
|
o(this, "eventBusService");
|
|
@@ -398,15 +398,15 @@ const H = class H {
|
|
|
398
398
|
* throttled subscribers cannot diverge from live state.
|
|
399
399
|
*/
|
|
400
400
|
merge(t) {
|
|
401
|
-
const e =
|
|
402
|
-
onFunctionResponse: /* @__PURE__ */
|
|
401
|
+
const e = Zt(this.interaction, t, {
|
|
402
|
+
onFunctionResponse: /* @__PURE__ */ h((s) => this.eventBusService.gatewayEmitFunctionResponse(s), "onFunctionResponse")
|
|
403
403
|
});
|
|
404
404
|
return this.interaction = e, e;
|
|
405
405
|
}
|
|
406
406
|
};
|
|
407
|
-
|
|
408
|
-
let
|
|
409
|
-
const
|
|
407
|
+
h(ot, "InteractionService");
|
|
408
|
+
let j = ot;
|
|
409
|
+
const Ot = 4001, te = 4002, kt = 4004, ee = 4100, H = 500, se = 2e4, ne = 1e3, ie = 0.2, _ = 300 * 1e3, re = 0.75, oe = 2e3, w = "[Connection]", at = class at {
|
|
410
410
|
constructor(t) {
|
|
411
411
|
o(this, "ports");
|
|
412
412
|
o(this, "state");
|
|
@@ -415,7 +415,7 @@ const ot = 4001, $t = 4002, Rt = 4004, Lt = 4100, $ = 500, Pt = 2e4, bt = 1e3, _
|
|
|
415
415
|
o(this, "inflight", null);
|
|
416
416
|
o(this, "retryTimer", null);
|
|
417
417
|
o(this, "idleTimer", null);
|
|
418
|
-
o(this, "wait",
|
|
418
|
+
o(this, "wait", H);
|
|
419
419
|
/** Consecutive failed attempts since the last proven connection. */
|
|
420
420
|
o(this, "attempt", 0);
|
|
421
421
|
o(this, "halted", null);
|
|
@@ -448,7 +448,7 @@ const ot = 4001, $t = 4002, Rt = 4004, Lt = 4100, $ = 500, Pt = 2e4, bt = 1e3, _
|
|
|
448
448
|
/** Connected by the store AND by the transport. */
|
|
449
449
|
get isUp() {
|
|
450
450
|
var t, e;
|
|
451
|
-
return this.state.connectionStatus ===
|
|
451
|
+
return this.state.connectionStatus === E.Connected && (((e = (t = this.ports).isConnected) == null ? void 0 : e.call(t)) ?? !0);
|
|
452
452
|
}
|
|
453
453
|
// ─── Commands ───────────────────────────────────────────────────────────
|
|
454
454
|
/**
|
|
@@ -463,7 +463,7 @@ const ot = 4001, $t = 4002, Rt = 4004, Lt = 4100, $ = 500, Pt = 2e4, bt = 1e3, _
|
|
|
463
463
|
if (this.inflight) return this.inflight;
|
|
464
464
|
if (this.isUp && this.target.sessionId && !this.halted)
|
|
465
465
|
return Promise.resolve(this.target.sessionId);
|
|
466
|
-
} else this.target && (console.log(`${
|
|
466
|
+
} else this.target && (console.log(`${w} switching from session ${this.target.sessionId ?? "(new)"} to ${t ?? "(new)"}.`), this.close());
|
|
467
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
468
|
}
|
|
469
469
|
/**
|
|
@@ -475,18 +475,18 @@ const ot = 4001, $t = 4002, Rt = 4004, Lt = 4100, $ = 500, Pt = 2e4, bt = 1e3, _
|
|
|
475
475
|
var e;
|
|
476
476
|
if (this.halted)
|
|
477
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(`${
|
|
478
|
+
return this.target ? this.inflight ? this.inflight : this.isUp && this.target.sessionId ? this.target.sessionId : (console.warn(`${w} send guard: socket is DOWN at send time (session ${this.target.sessionId ?? "(new)"}, status ${this.state.connectionStatus}) — redialling now instead of in ${this.wait}ms.`), this.cancelRetry(), this.target.resume = !0, this.dial()) : (console.warn(`${w} send guard: nothing supervised yet — opening session ${t ?? "(new)"} with the replay cursor.`), this.open(t, { resume: !0 }));
|
|
479
479
|
}
|
|
480
480
|
/** Stop supervising: hang up, cancel any retry, stop the idle tick. Never throws. */
|
|
481
481
|
close() {
|
|
482
482
|
const t = this.target;
|
|
483
|
-
this.target = null, this.halted = null, this.cancelRetry(), this.stopIdleTick(), this.wait =
|
|
483
|
+
this.target = null, this.halted = null, this.cancelRetry(), this.stopIdleTick(), this.wait = H, this.attempt = 0;
|
|
484
484
|
try {
|
|
485
485
|
this.ports.hangUp();
|
|
486
486
|
} catch (e) {
|
|
487
|
-
console.error(`${
|
|
487
|
+
console.error(`${w} hangUp threw`, e);
|
|
488
488
|
}
|
|
489
|
-
t && this.state.setConnectionStatus(
|
|
489
|
+
t && this.state.setConnectionStatus(E.Disconnected);
|
|
490
490
|
}
|
|
491
491
|
// ─── Transport reports ──────────────────────────────────────────────────
|
|
492
492
|
/**
|
|
@@ -500,24 +500,24 @@ const ot = 4001, $t = 4002, Rt = 4004, Lt = 4100, $ = 500, Pt = 2e4, bt = 1e3, _
|
|
|
500
500
|
* A close that lands while a dial is in flight is remembered and judged when that dial fails.
|
|
501
501
|
*/
|
|
502
502
|
transportClosed(t, e) {
|
|
503
|
-
if (t !==
|
|
503
|
+
if (t !== Ot && (this.lastCloseCode = t, !!this.target)) {
|
|
504
504
|
if (this.inflight) {
|
|
505
|
-
console.log(`${
|
|
505
|
+
console.log(`${w} socket closed (code=${t}) while a dial is in flight — judged when it settles.`);
|
|
506
506
|
return;
|
|
507
507
|
}
|
|
508
|
-
this.state.connectionStatus ===
|
|
508
|
+
this.state.connectionStatus === E.Connected && (console.warn(`${w} socket closed: code=${t} reason="${e}" (session ${this.target.sessionId ?? "(new)"}).`), this.state.setConnectionStatus(E.Disconnected), this.judge(t));
|
|
509
509
|
}
|
|
510
510
|
}
|
|
511
511
|
// ─── The dial ───────────────────────────────────────────────────────────
|
|
512
512
|
dial() {
|
|
513
513
|
const t = this.target;
|
|
514
|
-
this.lastCloseCode = null, this.state.setConnectionStatus(
|
|
514
|
+
this.lastCloseCode = null, this.state.setConnectionStatus(E.Connecting);
|
|
515
515
|
const e = this.now();
|
|
516
|
-
console.log(`${
|
|
516
|
+
console.log(`${w} dialling session ${t.sessionId ?? "(new)"}${t.resume ? " with the replay cursor" : ""}${this.everConnected ? " (reconnect)" : ""}.`);
|
|
517
517
|
const n = (async () => (t.prepare && await t.prepare(), this.ports.dial(t.sessionId, { resume: t.resume })))().then((r) => {
|
|
518
|
-
var c,
|
|
518
|
+
var c, l;
|
|
519
519
|
if (this.target !== t) {
|
|
520
|
-
console.log(`${
|
|
520
|
+
console.log(`${w} a dial for ${t.sessionId ?? "(new)"} resolved after it was abandoned — hanging up.`);
|
|
521
521
|
try {
|
|
522
522
|
this.ports.hangUp();
|
|
523
523
|
} catch {
|
|
@@ -525,19 +525,19 @@ const ot = 4001, $t = 4002, Rt = 4004, Lt = 4100, $ = 500, Pt = 2e4, bt = 1e3, _
|
|
|
525
525
|
throw new Error("Connection attempt abandoned");
|
|
526
526
|
}
|
|
527
527
|
if (t.sessionId && r !== t.sessionId) {
|
|
528
|
-
console.error(`${
|
|
528
|
+
console.error(`${w} asked for session ${t.sessionId}, the server answered with ${r} — refusing the swap and halting.`);
|
|
529
529
|
try {
|
|
530
530
|
this.ports.hangUp();
|
|
531
531
|
} catch {
|
|
532
532
|
}
|
|
533
|
-
throw this.state.setConnectionStatus(
|
|
533
|
+
throw this.state.setConnectionStatus(E.Disconnected), this.halt("session-gone", { sessionId: t.sessionId, actualSessionId: r }), new Error(`Session ${t.sessionId} no longer exists on the server (it answered with ${r}).`);
|
|
534
534
|
}
|
|
535
535
|
const a = this.everConnected;
|
|
536
|
-
return this.everConnected = !0, t.sessionId = r, t.resume = !0, t.prepare = void 0, this.wait =
|
|
536
|
+
return this.everConnected = !0, t.sessionId = r, t.resume = !0, t.prepare = void 0, this.wait = H, this.attempt = 0, this.state.setConnectionStatus(E.Connected), console.log(`${w} ${a ? "reconnected to" : "connected to"} session ${r} in ${this.now() - e}ms.`), (l = (c = this.ports).onConnected) == null || l.call(c, r, { reconnect: a }), r;
|
|
537
537
|
}).catch((r) => {
|
|
538
538
|
if (this.target === t && !this.halted) {
|
|
539
539
|
const a = this.lastCloseCode;
|
|
540
|
-
console.error(`${
|
|
540
|
+
console.error(`${w} dial of session ${t.sessionId ?? "(new)"} failed after ${this.now() - e}ms${a !== null ? ` (socket closed with ${a})` : ""}:`, r), this.state.setConnectionStatus(E.Disconnected), this.inflight === n && (this.inflight = null), this.judge(a);
|
|
541
541
|
}
|
|
542
542
|
throw r;
|
|
543
543
|
}).finally(() => {
|
|
@@ -549,33 +549,33 @@ const ot = 4001, $t = 4002, Rt = 4004, Lt = 4100, $ = 500, Pt = 2e4, bt = 1e3, _
|
|
|
549
549
|
judge(t) {
|
|
550
550
|
var s;
|
|
551
551
|
const e = (s = this.target) == null ? void 0 : s.sessionId;
|
|
552
|
-
if (t ===
|
|
553
|
-
if (t ===
|
|
552
|
+
if (t === te) return this.halt("attached-elsewhere", { sessionId: e, code: t });
|
|
553
|
+
if (t === kt) return this.halt("session-gone", { sessionId: e, code: t });
|
|
554
554
|
if (t === 1e3 || t === 1008) return this.halt("closed-by-server", { sessionId: e, code: t });
|
|
555
555
|
this.scheduleRetry();
|
|
556
556
|
}
|
|
557
557
|
halt(t, e) {
|
|
558
558
|
var s, n;
|
|
559
|
-
this.halted = t, this.cancelRetry(), console.warn(`${
|
|
559
|
+
this.halted = t, this.cancelRetry(), console.warn(`${w} 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
560
|
try {
|
|
561
561
|
(n = (s = this.ports).onHalt) == null || n.call(s, t, e);
|
|
562
562
|
} catch (r) {
|
|
563
|
-
console.error(`${
|
|
563
|
+
console.error(`${w} onHalt threw`, r);
|
|
564
564
|
}
|
|
565
565
|
}
|
|
566
566
|
scheduleRetry() {
|
|
567
567
|
var e, s;
|
|
568
568
|
if (!this.target || this.retryTimer || this.inflight) return;
|
|
569
569
|
if (!this.state.sessionActive) {
|
|
570
|
-
console.log(`${
|
|
570
|
+
console.log(`${w} session idle — not redialling until activity resumes.`);
|
|
571
571
|
return;
|
|
572
572
|
}
|
|
573
573
|
const t = this.jittered(this.wait);
|
|
574
|
-
this.wait = Math.min(Math.floor(this.wait + this.wait * this.wait /
|
|
574
|
+
this.wait = Math.min(Math.floor(this.wait + this.wait * this.wait / ne), se), this.attempt += 1, console.warn(`${w} redialling session ${this.target.sessionId ?? "(new)"} in ${t}ms (then ${this.wait}ms, attempt ${this.attempt}).`);
|
|
575
575
|
try {
|
|
576
576
|
(s = (e = this.ports).onRetryScheduled) == null || s.call(e, { sessionId: this.target.sessionId, delayMs: t, attempt: this.attempt });
|
|
577
577
|
} catch (n) {
|
|
578
|
-
console.error(`${
|
|
578
|
+
console.error(`${w} onRetryScheduled threw`, n);
|
|
579
579
|
}
|
|
580
580
|
this.retryTimer = setTimeout(() => {
|
|
581
581
|
this.retryTimer = null, !(!this.target || this.halted) && (this.target.resume = !0, this.dial().catch(() => {
|
|
@@ -586,7 +586,7 @@ const ot = 4001, $t = 4002, Rt = 4004, Lt = 4100, $ = 500, Pt = 2e4, bt = 1e3, _
|
|
|
586
586
|
this.retryTimer && (clearTimeout(this.retryTimer), this.retryTimer = null);
|
|
587
587
|
}
|
|
588
588
|
jittered(t) {
|
|
589
|
-
return Math.max(0, Math.round(t + t *
|
|
589
|
+
return Math.max(0, Math.round(t + t * ie * (Math.random() * 2 - 1)));
|
|
590
590
|
}
|
|
591
591
|
sameTarget(t) {
|
|
592
592
|
var e;
|
|
@@ -594,7 +594,7 @@ const ot = 4001, $t = 4002, Rt = 4004, Lt = 4100, $ = 500, Pt = 2e4, bt = 1e3, _
|
|
|
594
594
|
}
|
|
595
595
|
// ─── Idle ───────────────────────────────────────────────────────────────
|
|
596
596
|
startIdleTick() {
|
|
597
|
-
this.idleTimer || (this.idleTimer = setInterval(() => this.tick(),
|
|
597
|
+
this.idleTimer || (this.idleTimer = setInterval(() => this.tick(), oe));
|
|
598
598
|
}
|
|
599
599
|
stopIdleTick() {
|
|
600
600
|
this.idleTimer && (clearInterval(this.idleTimer), this.idleTimer = null);
|
|
@@ -611,25 +611,25 @@ const ot = 4001, $t = 4002, Rt = 4004, Lt = 4100, $ = 500, Pt = 2e4, bt = 1e3, _
|
|
|
611
611
|
if (!this.target) return;
|
|
612
612
|
this.state.turnOpen && this.state.setLastActivity();
|
|
613
613
|
const t = this.now() - this.state.lastActivity;
|
|
614
|
-
if (t >
|
|
615
|
-
if (this.state.sessionActive && this.state.setIsSessionActive(!1), this.cancelRetry(), this.state.connectionStatus ===
|
|
616
|
-
console.warn(`${
|
|
614
|
+
if (t > _) {
|
|
615
|
+
if (this.state.sessionActive && this.state.setIsSessionActive(!1), this.cancelRetry(), this.state.connectionStatus === E.Connected) {
|
|
616
|
+
console.warn(`${w} idle for ${Math.round(t / 1e3)}s (limit ${_ / 1e3}s) — closing the socket (session ${this.target.sessionId ?? "(new)"}). Activity, or a send, redials it.`);
|
|
617
617
|
try {
|
|
618
618
|
this.ports.hangUp();
|
|
619
619
|
} catch (e) {
|
|
620
|
-
console.error(`${
|
|
620
|
+
console.error(`${w} hangUp threw`, e);
|
|
621
621
|
}
|
|
622
|
-
this.state.setConnectionStatus(
|
|
622
|
+
this.state.setConnectionStatus(E.Disconnected);
|
|
623
623
|
}
|
|
624
624
|
return;
|
|
625
625
|
}
|
|
626
|
-
this.state.sessionActive || (console.log(`${
|
|
627
|
-
}))), t >
|
|
626
|
+
this.state.sessionActive || (console.log(`${w} activity resumed — the session is active again.`), this.state.setIsSessionActive(!0), this.wait = H, this.state.connectionStatus === E.Disconnected && !this.halted && !this.inflight && (this.target.resume = !0, this.dial().catch(() => {
|
|
627
|
+
}))), t > _ * re ? this.idleWarningLogged || (this.idleWarningLogged = !0, console.warn(`${w} idle ${Math.round(t / 1e3)}s of ${_ / 1e3}s — the socket closes in about ${Math.round((_ - t) / 1e3)}s unless something happens.`)) : this.idleWarningLogged = !1;
|
|
628
628
|
}
|
|
629
629
|
};
|
|
630
|
-
|
|
631
|
-
let
|
|
632
|
-
const
|
|
630
|
+
h(at, "ConnectionSupervisor");
|
|
631
|
+
let V = at;
|
|
632
|
+
const ct = class ct {
|
|
633
633
|
constructor(t) {
|
|
634
634
|
o(this, "pending", null);
|
|
635
635
|
o(this, "lastPublishedAt", 0);
|
|
@@ -661,10 +661,10 @@ const K = class K {
|
|
|
661
661
|
this.trailing && (clearTimeout(this.trailing), this.trailing = null);
|
|
662
662
|
}
|
|
663
663
|
};
|
|
664
|
-
|
|
665
|
-
let
|
|
666
|
-
const
|
|
667
|
-
constructor(t, e, s, n, r, a, c,
|
|
664
|
+
h(ct, "ThrottledEmitter");
|
|
665
|
+
let Z = ct;
|
|
666
|
+
const y = class y {
|
|
667
|
+
constructor(t, e, s, n, r, a, c, l, f, p, m) {
|
|
668
668
|
o(this, "base_url");
|
|
669
669
|
o(this, "msg_order", 0);
|
|
670
670
|
o(this, "interactionsMap", /* @__PURE__ */ new Map());
|
|
@@ -678,6 +678,19 @@ const S = class S {
|
|
|
678
678
|
o(this, "interactionCallIds", /* @__PURE__ */ new Map());
|
|
679
679
|
/** Interactions whose turn was committed (turn-complete or a server error); a second close is ignored. */
|
|
680
680
|
o(this, "committedTurns", /* @__PURE__ */ new Set());
|
|
681
|
+
/** Interactions this tab sent. An `InteractionStarted` for one of them announces what is already here. */
|
|
682
|
+
o(this, "localInteractionIds", /* @__PURE__ */ new Set());
|
|
683
|
+
/**
|
|
684
|
+
* Turns open right now, local and remote. `turnOpen` in the store is "any of these": a remote turn finishing
|
|
685
|
+
* must not unlock the composer under a local turn still streaming, nor the other way round.
|
|
686
|
+
*/
|
|
687
|
+
o(this, "openTurns", /* @__PURE__ */ new Set());
|
|
688
|
+
o(this, "options");
|
|
689
|
+
/** Announcements asked for in this tab, by `runId|settleKey` — a second request for the same settle is a no-op. */
|
|
690
|
+
o(this, "announceRequested", /* @__PURE__ */ new Set());
|
|
691
|
+
/** Announcements waiting for the chat to be idle (no open turn) and connected, in request order. */
|
|
692
|
+
o(this, "pendingAnnouncements", []);
|
|
693
|
+
o(this, "flushingAnnouncements", !1);
|
|
681
694
|
o(this, "rawJwt");
|
|
682
695
|
o(this, "sessionId");
|
|
683
696
|
o(this, "eventBusService");
|
|
@@ -694,12 +707,12 @@ const S = class S {
|
|
|
694
707
|
*/
|
|
695
708
|
o(this, "everConnected", !1);
|
|
696
709
|
/** Publishes the live message to the store; see ThrottledEmitter for the cadence rules. */
|
|
697
|
-
o(this, "liveMessage", new
|
|
698
|
-
windowMs:
|
|
699
|
-
publish: /* @__PURE__ */
|
|
710
|
+
o(this, "liveMessage", new Z({
|
|
711
|
+
windowMs: y.CURRENT_MSG_THROTTLE_MS,
|
|
712
|
+
publish: /* @__PURE__ */ h((t) => {
|
|
700
713
|
this.sessionState.setCurrentMessage(t), this.eventBusService.gatewayEmitMessage(t);
|
|
701
714
|
}, "publish"),
|
|
702
|
-
publishedVersion: /* @__PURE__ */
|
|
715
|
+
publishedVersion: /* @__PURE__ */ h(() => {
|
|
703
716
|
var t;
|
|
704
717
|
return ((t = this.sessionState.currentMessage) == null ? void 0 : t.version) ?? 0;
|
|
705
718
|
}, "publishedVersion")
|
|
@@ -708,31 +721,33 @@ const S = class S {
|
|
|
708
721
|
o(this, "detachedRunInteractionServices", /* @__PURE__ */ new Map());
|
|
709
722
|
// ─── Artifacts ──────────────────────────────────────────────────────────
|
|
710
723
|
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 =
|
|
712
|
-
this.sessionState = u;
|
|
713
|
-
}), this.wsService =
|
|
724
|
+
this.options = m ?? {}, this.user = t, this.config = r, this.rawJwt = t.access_token, this.base_url = n, this.eventBusService = e, this.sessionId = p, this.artifactService = s, this.sessionState = a.getState(), this.notificationPort = c, this.storageService = f, a.subscribe((u, g) => {
|
|
725
|
+
this.sessionState = u, g.turnOpen && !u.turnOpen && this.flushAnnouncements();
|
|
726
|
+
}), this.wsService = l, this.connection = new V({
|
|
714
727
|
store: a,
|
|
715
728
|
// A redial while a turn is open carries the turn's id: the server tells us if it cannot continue it.
|
|
716
|
-
dial: /* @__PURE__ */
|
|
729
|
+
dial: /* @__PURE__ */ h((u, g) => this.wsService.connect(u, {
|
|
717
730
|
...g,
|
|
718
731
|
openInteractionId: g.resume && this.sessionState.turnOpen ? this.getCurrentInteractionId() ?? void 0 : void 0
|
|
719
732
|
}), "dial"),
|
|
720
|
-
hangUp: /* @__PURE__ */
|
|
721
|
-
isConnected: /* @__PURE__ */
|
|
722
|
-
onConnected: /* @__PURE__ */
|
|
723
|
-
this.sessionId = u, this.sessionState.setConnectionOutage(null), this.eventBusService.gatewayEmitConnected(u, g);
|
|
733
|
+
hangUp: /* @__PURE__ */ h(() => this.wsService.closeStream(), "hangUp"),
|
|
734
|
+
isConnected: /* @__PURE__ */ h(() => this.wsService.isConnected(), "isConnected"),
|
|
735
|
+
onConnected: /* @__PURE__ */ h((u, g) => {
|
|
736
|
+
this.sessionId = u, this.sessionState.setConnectionOutage(null), this.eventBusService.gatewayEmitConnected(u, g), this.flushAnnouncements();
|
|
724
737
|
}, "onConnected"),
|
|
725
|
-
onRetryScheduled: /* @__PURE__ */
|
|
738
|
+
onRetryScheduled: /* @__PURE__ */ h(({ delayMs: u, attempt: g }) => {
|
|
726
739
|
var M;
|
|
727
|
-
const
|
|
728
|
-
this.sessionState.setConnectionOutage({ since:
|
|
740
|
+
const S = Date.now(), D = ((M = this.sessionState.connectionOutage) == null ? void 0 : M.since) ?? S;
|
|
741
|
+
this.sessionState.setConnectionOutage({ since: D, retryAt: S + u, attempt: g, halted: null }), S - D >= y.OUTAGE_CLOSES_TURN_AFTER_MS && this.closeOpenTurnWith(y.OUTAGE_TURN_MESSAGE);
|
|
729
742
|
}, "onRetryScheduled"),
|
|
730
|
-
onHalt: /* @__PURE__ */
|
|
731
|
-
const
|
|
732
|
-
this.sessionState.setConnectionOutage({ since: (
|
|
743
|
+
onHalt: /* @__PURE__ */ h((u, g) => {
|
|
744
|
+
const S = this.sessionState.connectionOutage;
|
|
745
|
+
this.sessionState.setConnectionOutage({ since: (S == null ? void 0 : S.since) ?? Date.now(), retryAt: null, attempt: (S == null ? void 0 : S.attempt) ?? 0, halted: u }), this.notifyHalt(u, g), this.closeOpenTurnWith(y.HALT_TURN_MESSAGE[u]);
|
|
733
746
|
}, "onHalt")
|
|
734
747
|
}), this.wsService.onEvent = async (u) => {
|
|
735
748
|
await this.Message(u);
|
|
749
|
+
}, this.wsService.onInteractionStarted = (u) => {
|
|
750
|
+
this.interactionStarted(u);
|
|
736
751
|
}, this.wsService.onNewPacket = (u) => {
|
|
737
752
|
this.sessionState.setStatistics(u);
|
|
738
753
|
}, this.wsService.onError = (u) => {
|
|
@@ -763,8 +778,9 @@ const S = class S {
|
|
|
763
778
|
*/
|
|
764
779
|
closeOpenTurnWith(t) {
|
|
765
780
|
if (!this.sessionState.turnOpen) return;
|
|
766
|
-
const e = this.getCurrentInteractionId();
|
|
767
|
-
|
|
781
|
+
const e = this.getCurrentInteractionId(), s = this.openTurns.size > 0 ? [...this.openTurns] : e ? [e] : [];
|
|
782
|
+
for (const n of s)
|
|
783
|
+
console.warn(`[AgentGateway] closing interaction ${n} from the client side: ${t}`), this.Message(x.createErrorEvent(t, n));
|
|
768
784
|
}
|
|
769
785
|
/** The supervisor gave up on its own (another tab holds the session, the session is gone, …): tell the user. */
|
|
770
786
|
notifyHalt(t, e) {
|
|
@@ -840,10 +856,13 @@ const S = class S {
|
|
|
840
856
|
return this.currentIS.interaction.isSuspended = !1, this.currentIS.interaction.interactionQuestion += " + " + t, this.currentIS.interaction;
|
|
841
857
|
this.msg_order += 1;
|
|
842
858
|
let n = this.getNewInteractionId();
|
|
843
|
-
s && (n = s);
|
|
844
|
-
|
|
859
|
+
return s && (n = s), this.currentIS = this.registerInteraction(n, t), this.currentIS.interaction;
|
|
860
|
+
}
|
|
861
|
+
/** A new interaction and its merge service, in the maps. Who becomes current is the caller's decision. */
|
|
862
|
+
registerInteraction(t, e, s) {
|
|
863
|
+
const n = {
|
|
845
864
|
created: /* @__PURE__ */ new Date(),
|
|
846
|
-
interactionId:
|
|
865
|
+
interactionId: t,
|
|
847
866
|
artifactData: [],
|
|
848
867
|
partial: !0,
|
|
849
868
|
sessionId: this.sessionId,
|
|
@@ -851,9 +870,44 @@ const S = class S {
|
|
|
851
870
|
parts: [],
|
|
852
871
|
version: 0,
|
|
853
872
|
functionMap: /* @__PURE__ */ new Map(),
|
|
854
|
-
interactionQuestion:
|
|
873
|
+
interactionQuestion: e,
|
|
874
|
+
...s
|
|
855
875
|
};
|
|
856
|
-
|
|
876
|
+
this.interactionsMap.set(t, n);
|
|
877
|
+
const r = new j(n, this.eventBusService);
|
|
878
|
+
return this.interactionsServiceMap.set(t, r), r;
|
|
879
|
+
}
|
|
880
|
+
/** The current interaction's turn is still open — it owns the live message, and must stay current. */
|
|
881
|
+
currentTurnIsOpen() {
|
|
882
|
+
const t = this.getCurrentInteractionId();
|
|
883
|
+
return !!t && this.openTurns.has(t);
|
|
884
|
+
}
|
|
885
|
+
/**
|
|
886
|
+
* A turn this tab did not send (AIA Issue 1548): a WhatsApp message, a platform wake turn, another tab's turn, a
|
|
887
|
+
* detached run's briefing. It becomes the current interaction only when no open turn holds that place — a local
|
|
888
|
+
* turn mid-stream keeps it, and with it the resume cursor, suspend and the client-side close; the remote turn
|
|
889
|
+
* streams into its own interaction and takes over the live message when that turn ends.
|
|
890
|
+
*/
|
|
891
|
+
openRemoteInteraction(t, e, s, n) {
|
|
892
|
+
const r = this.registerInteraction(t, e, { remote: !0, ...s && { origin: s } });
|
|
893
|
+
return this.currentTurnIsOpen() || (this.currentIS = r), n && (this.openTurns.add(t), this.sessionState.setTurnOpen(!0), this.eventBusService.gatewayEmitTurnOpen(t), this.currentIS === r && this.localEmitMessage(r.interaction)), r;
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* An `InteractionStarted` frame. Opens a turn this tab did not send, with the text that started it as its
|
|
897
|
+
* question; ignores one this tab sent (its interaction already exists) and one already known or committed.
|
|
898
|
+
* Outside {@link AgentGatewayOptions.transcriptOfDetachedRun}, a detached run's turn is ignored too: it runs on
|
|
899
|
+
* the run's own session, and its box — not this transcript — shows it.
|
|
900
|
+
*/
|
|
901
|
+
interactionStarted(t) {
|
|
902
|
+
const e = t.interactionId;
|
|
903
|
+
if (!e || t.detachedRunId && !this.options.transcriptOfDetachedRun || this.localInteractionIds.has(e) || this.committedTurns.has(e)) return;
|
|
904
|
+
const s = this.interactionsServiceMap.get(e);
|
|
905
|
+
if (s) {
|
|
906
|
+
const n = s.interaction;
|
|
907
|
+
n.interactionQuestion || (n.interactionQuestion = t.content ?? ""), n.origin ?? (n.origin = wt(t.origin));
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
this.openRemoteInteraction(e, t.content ?? "", wt(t.origin), !0);
|
|
857
911
|
}
|
|
858
912
|
getInteractions() {
|
|
859
913
|
return Array.from(this.interactionsMap.values());
|
|
@@ -867,14 +921,10 @@ const S = class S {
|
|
|
867
921
|
}
|
|
868
922
|
updateMap(t) {
|
|
869
923
|
let e = this.interactionsServiceMap.get(t.interactionId);
|
|
870
|
-
|
|
871
|
-
var s = this.startInteraction("Unknown", !1, t.interactionId);
|
|
872
|
-
e = this.interactionsServiceMap.get(s.interactionId);
|
|
873
|
-
}
|
|
874
|
-
return e.merge(t);
|
|
924
|
+
return e || (e = this.openRemoteInteraction(t.interactionId, "", void 0, !1)), e.merge(t);
|
|
875
925
|
}
|
|
876
926
|
getNewInteractionId() {
|
|
877
|
-
const e =
|
|
927
|
+
const e = Ut(/* @__PURE__ */ new Date(), "MMM_dd_HH_mm_ss");
|
|
878
928
|
return `${this.msg_order}_${e}`;
|
|
879
929
|
}
|
|
880
930
|
// ─── Inbound: server events ─────────────────────────────────────────────
|
|
@@ -887,7 +937,7 @@ const S = class S {
|
|
|
887
937
|
console.error("Uknown message type", t);
|
|
888
938
|
return;
|
|
889
939
|
}
|
|
890
|
-
if (e.detachedRunId) {
|
|
940
|
+
if (e.detachedRunId && !this.options.transcriptOfDetachedRun) {
|
|
891
941
|
this.handleDetachedRunEvent(e);
|
|
892
942
|
return;
|
|
893
943
|
}
|
|
@@ -908,16 +958,16 @@ const S = class S {
|
|
|
908
958
|
console.error("No updated interaction");
|
|
909
959
|
return;
|
|
910
960
|
}
|
|
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.detachedRunId)));
|
|
961
|
+
(n.interactionId === this.getCurrentInteractionId() || !this.currentTurnIsOpen()) && 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.detachedRunId)));
|
|
912
962
|
const r = e.artifactsDelta;
|
|
913
963
|
r && r.forEach((a) => {
|
|
914
964
|
const c = n.artifactData.filter((f) => f.id == a);
|
|
915
|
-
let
|
|
916
|
-
c && c.length > 0 && (
|
|
965
|
+
let l = null;
|
|
966
|
+
c && c.length > 0 && (l = c[0], l.loadingPromise = this.asyncLoadArtifact(a).then((f) => (f === null ? console.error("Error trying to load artifact id:", l == null ? void 0 : l.id, "Artifact is null") : this.eventBusService.artifactEmitGenerated(f), f)).catch((f) => (console.error("Error trying to load artifact id:", l == null ? void 0 : l.id, f.toString()), null)));
|
|
917
967
|
});
|
|
918
968
|
} catch (e) {
|
|
919
969
|
if (this.getCurrentInteractionId()) {
|
|
920
|
-
const s =
|
|
970
|
+
const s = x.createErrorEvent("OnMessage error: " + e.toString(), this.getCurrentInteractionId() ?? "Empty Current"), n = this.updateMap(s);
|
|
921
971
|
if (console.error("Error event: ", JSON.stringify(s, void 0, 4)), !n) {
|
|
922
972
|
console.error("Error event, could not update interaction: ", JSON.stringify(s, void 0, 4));
|
|
923
973
|
return;
|
|
@@ -938,7 +988,7 @@ const S = class S {
|
|
|
938
988
|
version: 0,
|
|
939
989
|
functionMap: /* @__PURE__ */ new Map(),
|
|
940
990
|
interactionQuestion: s ?? t
|
|
941
|
-
}, r = new
|
|
991
|
+
}, r = new j(n, this.eventBusService), this.detachedRunInteractions.set(t, n), this.detachedRunInteractionServices.set(t, r)), { interaction: n, service: r };
|
|
942
992
|
}
|
|
943
993
|
handleDetachedRunEvent(t) {
|
|
944
994
|
const e = t.detachedRunId, { service: s } = this.getOrCreateDetachedRunInteraction(e, t.interactionId, t.detachedRunName);
|
|
@@ -963,14 +1013,29 @@ const S = class S {
|
|
|
963
1013
|
this.liveMessage.emit(t);
|
|
964
1014
|
}
|
|
965
1015
|
localOpen(t, e) {
|
|
966
|
-
this.sessionState.setTurnOpen(!0), this.eventBusService.gatewayEmitTurnOpen(t ?? "");
|
|
1016
|
+
t && this.openTurns.add(t), this.sessionState.setTurnOpen(!0), this.eventBusService.gatewayEmitTurnOpen(t ?? "");
|
|
967
1017
|
}
|
|
968
1018
|
async turnComplete(t, e, s, n) {
|
|
969
|
-
this.
|
|
1019
|
+
this.openTurns.delete(t);
|
|
1020
|
+
const r = t === this.getCurrentInteractionId(), a = r ? null : this.sessionState.currentMessage;
|
|
1021
|
+
r && this.liveMessage.cancelPending(), this.sessionState.setNewMessage(e), a && a.interactionId !== t ? this.sessionState.setCurrentMessage(a) : r && this.handOverLiveMessage(), this.eventBusService.gatewayEmitTurnComplete(t, e), this.interactionCallIds.delete(t), this.sessionState.setLastToolEvent(null), this.localEmitToolEvent({
|
|
970
1022
|
eventName: "todolistUpdated",
|
|
971
1023
|
eventData: "",
|
|
972
1024
|
detachedRunId: n
|
|
973
|
-
}), this.sessionState.setTurnOpen(
|
|
1025
|
+
}), this.sessionState.setTurnOpen(this.openTurns.size > 0);
|
|
1026
|
+
}
|
|
1027
|
+
/**
|
|
1028
|
+
* The current turn ended while another is still open (a remote turn that started under it): that one becomes
|
|
1029
|
+
* current and its progress so far goes live at once.
|
|
1030
|
+
*/
|
|
1031
|
+
handOverLiveMessage() {
|
|
1032
|
+
for (const t of this.openTurns) {
|
|
1033
|
+
const e = this.interactionsServiceMap.get(t);
|
|
1034
|
+
if (e) {
|
|
1035
|
+
this.currentIS = e, this.sessionState.setCurrentMessage(e.interaction), this.eventBusService.gatewayEmitMessage(e.interaction);
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
974
1039
|
}
|
|
975
1040
|
async asyncLoadArtifact(t) {
|
|
976
1041
|
let e = null;
|
|
@@ -1011,7 +1076,7 @@ const S = class S {
|
|
|
1011
1076
|
}
|
|
1012
1077
|
/** Hang up and stop supervising the connection. `closeTurn` also closes an open turn in the store. */
|
|
1013
1078
|
stopStream(t = !0) {
|
|
1014
|
-
t && this.sessionState.setTurnOpen(!1), this.sessionState.setConnectionOutage(null), this.connection.close();
|
|
1079
|
+
t && (this.openTurns.clear(), this.sessionState.setTurnOpen(!1)), this.sessionState.setConnectionOutage(null), this.connection.close();
|
|
1015
1080
|
}
|
|
1016
1081
|
/**
|
|
1017
1082
|
* Make sure the socket is OPEN before a send, redialling the SAME session when it is not.
|
|
@@ -1034,23 +1099,23 @@ const S = class S {
|
|
|
1034
1099
|
const s = await this.connection.ensure(t);
|
|
1035
1100
|
console.log(`[AgentGateway] send guard: reconnected to ${s} in ${Date.now() - e}ms — sending now.`);
|
|
1036
1101
|
} catch (s) {
|
|
1037
|
-
throw console.error(`[AgentGateway] send guard: redial FAILED after ${Date.now() - e}ms — the message was not sent.`, s), new Error(
|
|
1102
|
+
throw console.error(`[AgentGateway] send guard: redial FAILED after ${Date.now() - e}ms — the message was not sent.`, s), new Error(y.NO_CONNECTION_MESSAGE, { cause: s });
|
|
1038
1103
|
}
|
|
1039
1104
|
}
|
|
1040
1105
|
// ─── Outbound: the user's turns ─────────────────────────────────────────
|
|
1041
1106
|
async sendMessage(t, e) {
|
|
1042
|
-
let s = this.getInteractions().length, n =
|
|
1107
|
+
let s = this.getInteractions().length, n = N.createWaiting(!0, !0, "Overall", /* @__PURE__ */ new Date());
|
|
1043
1108
|
this.sendStatusMessage(t.data, [n], s.toString() + "1");
|
|
1044
1109
|
try {
|
|
1045
1110
|
const { promptAsString: r, json: a } = this.sessionState.onRenderPrompt ? this.sessionState.onRenderPrompt(t.data) : { promptAsString: t.data, json: void 0 };
|
|
1046
1111
|
this.sessionState.onRenderPrompt && (t.data = a, t.friendlyMessage = r);
|
|
1047
|
-
const c = await this.sendMessageInternal(t, e),
|
|
1048
|
-
this.storageService.storePrompt(
|
|
1049
|
-
const f =
|
|
1112
|
+
const c = await this.sendMessageInternal(t, e), l = qt.createPrompt(r ?? "", (a == null ? void 0 : a.toString()) ?? {});
|
|
1113
|
+
this.storageService.storePrompt(l);
|
|
1114
|
+
const f = N.fromText("Planejando próximos passos");
|
|
1050
1115
|
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
1116
|
} catch (r) {
|
|
1052
1117
|
const a = r instanceof Error ? r.message : String(r ?? "");
|
|
1053
|
-
return this.liveMessage.cancelPending(), this.sessionState.setCurrentMessage(null), this.sessionState.setTurnOpen(
|
|
1118
|
+
return this.liveMessage.cancelPending(), this.sessionState.setCurrentMessage(null), this.sessionState.setTurnOpen(this.openTurns.size > 0), this.eventBusService.ChatEmitMessageError(a), {
|
|
1054
1119
|
success: !1,
|
|
1055
1120
|
error: a,
|
|
1056
1121
|
interaction: {
|
|
@@ -1058,7 +1123,7 @@ const S = class S {
|
|
|
1058
1123
|
created: /* @__PURE__ */ new Date(),
|
|
1059
1124
|
interactionId: "",
|
|
1060
1125
|
partial: !1,
|
|
1061
|
-
parts: [
|
|
1126
|
+
parts: [N.fromError(a)],
|
|
1062
1127
|
version: 0
|
|
1063
1128
|
}
|
|
1064
1129
|
};
|
|
@@ -1066,18 +1131,18 @@ const S = class S {
|
|
|
1066
1131
|
}
|
|
1067
1132
|
// Send a message to the server over the socket
|
|
1068
1133
|
async sendMessageInternal(t, e) {
|
|
1069
|
-
var r, a, c,
|
|
1134
|
+
var r, a, c, l, f, p, m, u;
|
|
1070
1135
|
const s = this.suspendState;
|
|
1071
1136
|
this.suspendState = !1;
|
|
1072
1137
|
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(
|
|
1138
|
+
if (this.localInteractionIds.add(n.interactionId), this.registerInteractionCallId(n.interactionId, e), (r = t.userUi) != null && r.name && n.parts.push(N.fromUserUi(t.userUi.name, t.userUi.args)), !this.wsService)
|
|
1074
1139
|
throw "no wsService created";
|
|
1075
1140
|
if (!((a = this.config.agentConfig) != null && a.id))
|
|
1076
1141
|
throw "Agent not selected";
|
|
1077
1142
|
return this.sessionState.setLastActivity(), await this.ensureConnected(), this.wsService.sendMessage({
|
|
1078
1143
|
Content: t.data,
|
|
1079
1144
|
SessionId: this.sessionId,
|
|
1080
|
-
Action:
|
|
1145
|
+
Action: U.SendMessage,
|
|
1081
1146
|
ModelId: this.config.model,
|
|
1082
1147
|
InteractionId: n.interactionId,
|
|
1083
1148
|
AgentId: (c = this.config.agentConfig) == null ? void 0 : c.id,
|
|
@@ -1086,18 +1151,18 @@ const S = class S {
|
|
|
1086
1151
|
// instead of looking up an Agent metadata row by AgentId. Plumbed through
|
|
1087
1152
|
// `agentContext.agentConfig.agentImplementation` so a host can run a turn
|
|
1088
1153
|
// against any registered LlmAgent variant without seeding a Mongo record.
|
|
1089
|
-
AgentImplementation: (
|
|
1154
|
+
AgentImplementation: (l = this.config.agentConfig) == null ? void 0 : l.agentImplementation,
|
|
1090
1155
|
Parameters: {
|
|
1091
1156
|
CustomerName: ((f = this.config.customer) == null ? void 0 : f.name) ?? "",
|
|
1092
|
-
DataSet: ((
|
|
1157
|
+
DataSet: ((p = this.config.customer) == null ? void 0 : p.dataSetId) ?? ""
|
|
1093
1158
|
},
|
|
1094
1159
|
// Forward image attachments as a structured payload (PascalCase
|
|
1095
1160
|
// keys to match the C# `Message.Images` / `MessageImage` model).
|
|
1096
|
-
Images: (
|
|
1161
|
+
Images: (m = t.images) != null && m.length ? t.images.map((g) => ({ MimeType: g.mimeType, Data: g.data })) : void 0,
|
|
1097
1162
|
// Client-only UI representation for this turn (PascalCase to match the C# `Message.UserUi`
|
|
1098
1163
|
// model). The server persists it as a UserUiContent sibling and strips it from the model
|
|
1099
1164
|
// request; Content remains the only model-facing text.
|
|
1100
|
-
UserUi: (
|
|
1165
|
+
UserUi: (u = t.userUi) != null && u.name ? { Name: t.userUi.name, Args: t.userUi.args } : void 0
|
|
1101
1166
|
}), this.localOpen(n.interactionId, "system"), {
|
|
1102
1167
|
interaction: n,
|
|
1103
1168
|
success: !0
|
|
@@ -1106,7 +1171,7 @@ const S = class S {
|
|
|
1106
1171
|
sendStatusMessage(t, e, s) {
|
|
1107
1172
|
var r, a;
|
|
1108
1173
|
let n;
|
|
1109
|
-
((a = (r = this.currentIS) == null ? void 0 : r.interaction) == null ? void 0 : a.turn_complete) === !1 ? (n =
|
|
1174
|
+
((a = (r = this.currentIS) == null ? void 0 : r.interaction) == null ? void 0 : a.turn_complete) === !1 && !this.currentIS.interaction.remote ? (n = xt.cloneDeep(this.currentIS.interaction), n.parts.push(...e)) : n = {
|
|
1110
1175
|
interactionId: "tmp" + s,
|
|
1111
1176
|
created: /* @__PURE__ */ new Date(),
|
|
1112
1177
|
partial: !0,
|
|
@@ -1131,6 +1196,54 @@ const S = class S {
|
|
|
1131
1196
|
const s = (n = this.wsService.answerHumanTool) == null ? void 0 : n.bind(this.wsService);
|
|
1132
1197
|
return s ? s(t, e) : (console.warn("[AgentGateway] transport cannot deliver parked-tool answers", t), "queued");
|
|
1133
1198
|
}
|
|
1199
|
+
// ─── Detached-run announcements ─────────────────────────────────────────
|
|
1200
|
+
/**
|
|
1201
|
+
* Ask the server to tell this conversation about a detached run of it that settled (AIA Issue 1548 §5): the
|
|
1202
|
+
* `AnnounceDetachedRun` socket action. The server claims every settled-and-unannounced run of the session at once
|
|
1203
|
+
* (two tabs asking, one wins) and starts an ordinary turn on this socket, `origin: platform`, in the host's words —
|
|
1204
|
+
* which arrives as any remote turn does (`InteractionStarted`).
|
|
1205
|
+
*
|
|
1206
|
+
* <p>Never over a turn: while one is open in this tab the request waits, and goes out when the chat is idle (and
|
|
1207
|
+
* the socket up). `settleKey` — the run's `settledAt` — scopes the dedupe: a repeated request for the same settle
|
|
1208
|
+
* is a no-op, a resumed run that settles anew is announced again.</p>
|
|
1209
|
+
*/
|
|
1210
|
+
async announceDetachedRun(t, e) {
|
|
1211
|
+
const s = `${t}|${e ?? ""}`;
|
|
1212
|
+
return this.announceRequested.has(s) ? "duplicate" : (this.announceRequested.add(s), this.pendingAnnouncements.push(t), await this.flushAnnouncements(), this.pendingAnnouncements.includes(t) ? "queued" : "sent");
|
|
1213
|
+
}
|
|
1214
|
+
/** Send the queued announcements, oldest first, while the chat is idle and the socket is open. */
|
|
1215
|
+
async flushAnnouncements() {
|
|
1216
|
+
var t, e;
|
|
1217
|
+
if (!this.flushingAnnouncements) {
|
|
1218
|
+
this.flushingAnnouncements = !0;
|
|
1219
|
+
try {
|
|
1220
|
+
for (; this.pendingAnnouncements.length > 0 && !this.sessionState.turnOpen; ) {
|
|
1221
|
+
const s = (t = this.wsService.sendBaseMessage) == null ? void 0 : t.bind(this.wsService);
|
|
1222
|
+
if (!s) {
|
|
1223
|
+
console.warn("[AgentGateway] transport cannot send an AnnounceDetachedRun; the request stays queued");
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
1226
|
+
if (!this.wsService.isConnected() || !this.sessionId) return;
|
|
1227
|
+
const n = this.pendingAnnouncements[0];
|
|
1228
|
+
try {
|
|
1229
|
+
s({
|
|
1230
|
+
Action: U.AnnounceDetachedRun,
|
|
1231
|
+
AgentId: ((e = this.config.agentConfig) == null ? void 0 : e.id) ?? "",
|
|
1232
|
+
InteractionId: `announce_${n}_${Date.now()}`,
|
|
1233
|
+
SessionId: this.sessionId,
|
|
1234
|
+
DetachedRunId: n
|
|
1235
|
+
});
|
|
1236
|
+
} catch (r) {
|
|
1237
|
+
console.warn(`[AgentGateway] AnnounceDetachedRun for run ${n} could not be sent; it stays queued`, r);
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1240
|
+
this.pendingAnnouncements.shift(), console.log(`[AgentGateway] asked for the announcement of run ${n} (session ${this.sessionId}).`);
|
|
1241
|
+
}
|
|
1242
|
+
} finally {
|
|
1243
|
+
this.flushingAnnouncements = !1;
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1134
1247
|
// ─── Suspend ────────────────────────────────────────────────────────────
|
|
1135
1248
|
async suspend() {
|
|
1136
1249
|
const t = this.wsService;
|
|
@@ -1151,75 +1264,83 @@ const S = class S {
|
|
|
1151
1264
|
console.error("CurrentIS is null"), s("CurrentIS is null");
|
|
1152
1265
|
return;
|
|
1153
1266
|
}
|
|
1154
|
-
const
|
|
1155
|
-
|
|
1267
|
+
const l = this.currentIS.interaction;
|
|
1268
|
+
l.isSuspended = !0, this.openTurns.delete(l.interactionId), this.sessionState.setCurrentMessage(l), this.sessionState.setTurnOpen(this.openTurns.size > 0), this.suspendState = !0, e(!0);
|
|
1156
1269
|
});
|
|
1157
1270
|
}
|
|
1158
1271
|
async sleep(t) {
|
|
1159
1272
|
return new Promise((e) => setTimeout(e, t));
|
|
1160
1273
|
}
|
|
1161
1274
|
};
|
|
1162
|
-
|
|
1275
|
+
h(y, "AgentGatewayWSAsync"), // How often the streaming message re-renders. 150 ms made a reasoning highlight, or a burst of them, visibly lag the
|
|
1163
1276
|
// server (Ciro, 2026-10-07). The server already merges deltas over a 50 ms window (the SDK's DeltaCoalescer), so
|
|
1164
1277
|
// frames arrive at ~20/s per kind and 20 ms here costs little: it mostly stops adding a second delay on top.
|
|
1165
|
-
o(
|
|
1278
|
+
o(y, "CURRENT_MSG_THROTTLE_MS", 20), /**
|
|
1166
1279
|
* How long an open turn survives a connection outage. While the supervisor is redialling the
|
|
1167
1280
|
* turn stays open — a short blip resumes it from the replay cursor, and a server that comes back
|
|
1168
1281
|
* (or another instance) closes it with an error if its run is gone. Past this, nobody can tell
|
|
1169
1282
|
* us anything, and a turn that is still open is a composer that is still locked: the client
|
|
1170
1283
|
* closes it itself, with an error part, so the user can go on.
|
|
1171
1284
|
*/
|
|
1172
|
-
o(
|
|
1173
|
-
o(
|
|
1285
|
+
o(y, "OUTAGE_CLOSES_TURN_AFTER_MS", 6e4), o(y, "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. */
|
|
1286
|
+
o(y, "NO_CONNECTION_MESSAGE", "Não foi possível obter conexão com o servidor"), o(y, "HALT_TURN_MESSAGE", {
|
|
1174
1287
|
"attached-elsewhere": "Esta sessão está aberta em outra janela. A resposta foi interrompida.",
|
|
1175
1288
|
"session-gone": "A sessão não existe mais no servidor. A resposta foi interrompida.",
|
|
1176
1289
|
"closed-by-server": "O servidor encerrou a conexão. A resposta foi interrompida."
|
|
1177
1290
|
});
|
|
1178
|
-
let
|
|
1179
|
-
function
|
|
1180
|
-
const t = new
|
|
1181
|
-
t.author = "main", t.streamingParts = i.streamingParts, i.partialEventType ? t.eventType = i.partialEventType : t.eventType = i.functionName ? { fullName:
|
|
1291
|
+
let Tt = y;
|
|
1292
|
+
function ae(i) {
|
|
1293
|
+
const t = new Lt();
|
|
1294
|
+
t.author = "main", t.streamingParts = i.streamingParts, i.partialEventType ? t.eventType = i.partialEventType : t.eventType = i.functionName ? { fullName: z.StreamingFunctionCallUpdateContent, type: I.PartialFunctionCall } : i.partialReasoning ? { fullName: z.StreamingReasoningContent, type: I.Thought } : { fullName: z.StreamingTextContent, type: I.Text }, t.interactionId = i.iteractionId ?? "", t.mimeType = "text/plain", t.partial = !0, t.role = { label: "Assistant" }, t.timestamp = i.timeStamp ?? (/* @__PURE__ */ new Date()).getTime(), t.turnComplete = !1;
|
|
1182
1295
|
const e = t.eventType.type;
|
|
1183
1296
|
if (e == I.PartialFunctionCall) {
|
|
1184
|
-
const s = new
|
|
1297
|
+
const s = new Pt();
|
|
1185
1298
|
s.choiceIndex = 0, s.callId = i.functionCallId, s.arguments = i.partialText, s.name = i.functionName, t.content = { items: [s], role: { label: "Assistant" } };
|
|
1186
1299
|
} else if (e == I.Text)
|
|
1187
|
-
if (t.eventType.fullName ==
|
|
1188
|
-
const s = new
|
|
1300
|
+
if (t.eventType.fullName == z.StreamingTextContent) {
|
|
1301
|
+
const s = new Ft();
|
|
1189
1302
|
s.text = i.partialText, t.content = { items: [s], role: { label: "Assistant" } };
|
|
1190
1303
|
} else {
|
|
1191
|
-
const s = new
|
|
1304
|
+
const s = new _t();
|
|
1192
1305
|
s.text = i.partialText, t.content = { items: [s], role: { label: "Assistant" } };
|
|
1193
1306
|
}
|
|
1194
1307
|
else if (e == I.Thought) {
|
|
1195
|
-
const s = new
|
|
1308
|
+
const s = new Nt();
|
|
1196
1309
|
s.text = i.partialReasoning, t.content = { items: [s], role: { label: "Assistant" } };
|
|
1197
1310
|
}
|
|
1198
1311
|
return t;
|
|
1199
1312
|
}
|
|
1200
|
-
|
|
1201
|
-
function
|
|
1202
|
-
const t = i.partialEvent ?
|
|
1313
|
+
h(ae, "llmEventFromPartial");
|
|
1314
|
+
function st(i) {
|
|
1315
|
+
const t = i.partialEvent ? ae(i.partialEvent) : i.event;
|
|
1203
1316
|
if (t)
|
|
1204
1317
|
return i.detachedRunId && (t.detachedRunId = i.detachedRunId, t.detachedRunName = i.detachedRunName), t;
|
|
1205
1318
|
}
|
|
1206
|
-
|
|
1207
|
-
function
|
|
1319
|
+
h(st, "llmEventFromFrame");
|
|
1320
|
+
function Dt(i) {
|
|
1208
1321
|
var t, e, s;
|
|
1209
1322
|
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
1323
|
}
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1324
|
+
h(Dt, "carriesContent");
|
|
1325
|
+
function $t(i) {
|
|
1326
|
+
var e;
|
|
1327
|
+
if (i.type !== "InteractionStarted" || !((e = i.interaction) != null && e.interactionId)) return;
|
|
1328
|
+
if (i.interaction.detachedRunId || !i.detachedRunId) return i.interaction;
|
|
1329
|
+
const t = Object.assign(new bt(), i.interaction);
|
|
1330
|
+
return t.detachedRunId = i.detachedRunId, t;
|
|
1331
|
+
}
|
|
1332
|
+
h($t, "interactionStartFromFrame");
|
|
1333
|
+
const ce = 0.02;
|
|
1334
|
+
function le(i, t) {
|
|
1214
1335
|
if (!t) return null;
|
|
1215
1336
|
const e = (t.interactionsCompressed ?? 0) > 0 || (t.compressionRatio ?? 0) > 0;
|
|
1216
1337
|
if (!i)
|
|
1217
|
-
return e ?
|
|
1218
|
-
const s = i.size - t.size, n = t.maxSize || i.maxSize || 0, r = n > 0 ? s / n >=
|
|
1219
|
-
return !e && !r ? null :
|
|
1338
|
+
return e ? yt(t, t.size, t.size) : null;
|
|
1339
|
+
const s = i.size - t.size, n = t.maxSize || i.maxSize || 0, r = n > 0 ? s / n >= ce : i.size > 0 && s / i.size >= 0.1;
|
|
1340
|
+
return !e && !r ? null : yt(t, i.size, t.size, i.ratio);
|
|
1220
1341
|
}
|
|
1221
|
-
|
|
1222
|
-
function
|
|
1342
|
+
h(le, "detectCompaction");
|
|
1343
|
+
function yt(i, t, e, s) {
|
|
1223
1344
|
return {
|
|
1224
1345
|
at: Date.now(),
|
|
1225
1346
|
// Where the bar stood when it happened — the marker's position. The ratio
|
|
@@ -1231,8 +1352,8 @@ function et(i, t, e, s) {
|
|
|
1231
1352
|
interactionsCompressed: i.interactionsCompressed
|
|
1232
1353
|
};
|
|
1233
1354
|
}
|
|
1234
|
-
|
|
1235
|
-
const
|
|
1355
|
+
h(yt, "entry");
|
|
1356
|
+
const vt = 4, he = 3, ue = 20, P = class P {
|
|
1236
1357
|
constructor() {
|
|
1237
1358
|
o(this, "stats");
|
|
1238
1359
|
o(this, "onFlush");
|
|
@@ -1268,35 +1389,35 @@ const st = 4, Bt = 3, Ht = 20, E = class E {
|
|
|
1268
1389
|
record(t) {
|
|
1269
1390
|
const e = Date.now();
|
|
1270
1391
|
if (this.events.push([e, t.textLength]), this.stats.eventCount += 1, this.stats.totalTransfered += t.rawLength, t.sessionInformation && !t.fromDetachedRun) {
|
|
1271
|
-
const r =
|
|
1272
|
-
r && (this.sessionCompactions.push(r), this.sessionCompactions.length >
|
|
1392
|
+
const r = le(this.previousSessionInformation, t.sessionInformation);
|
|
1393
|
+
r && (this.sessionCompactions.push(r), this.sessionCompactions.length > ue && this.sessionCompactions.shift()), this.previousSessionInformation = t.sessionInformation, this.stats.sessionInformation = t.sessionInformation, this.stats.sessionCompactions = this.sessionCompactions;
|
|
1273
1394
|
}
|
|
1274
1395
|
this.stats.elapsed = (e - this.stats.startTime.getTime()) / 1e3;
|
|
1275
|
-
const s = e -
|
|
1396
|
+
const s = e - vt * 1e3;
|
|
1276
1397
|
for (; this.events.length > 0 && this.events[0][0] <= s; ) this.events.shift();
|
|
1277
1398
|
const n = this.events.reduce((r, a) => r + a[1], 0);
|
|
1278
|
-
this.stats.tokensPerSecond = n /
|
|
1399
|
+
this.stats.tokensPerSecond = n / he / vt, this.flushCoalesced();
|
|
1279
1400
|
}
|
|
1280
1401
|
flushCoalesced() {
|
|
1281
1402
|
if (!this.onFlush) return;
|
|
1282
1403
|
const t = Date.now(), e = t - this.lastFlushed;
|
|
1283
|
-
if (e >=
|
|
1404
|
+
if (e >= P.STATS_FLUSH_MS) {
|
|
1284
1405
|
this.flushTimer && (clearTimeout(this.flushTimer), this.flushTimer = null), this.lastFlushed = t, this.onFlush({ ...this.stats });
|
|
1285
1406
|
return;
|
|
1286
1407
|
}
|
|
1287
1408
|
this.flushTimer || (this.flushTimer = setTimeout(() => {
|
|
1288
1409
|
var s;
|
|
1289
1410
|
this.flushTimer = null, this.lastFlushed = Date.now(), (s = this.onFlush) == null || s.call(this, { ...this.stats });
|
|
1290
|
-
},
|
|
1411
|
+
}, P.STATS_FLUSH_MS - e));
|
|
1291
1412
|
}
|
|
1292
1413
|
};
|
|
1293
|
-
|
|
1294
|
-
let
|
|
1295
|
-
const
|
|
1414
|
+
h(P, "StreamStatsTracker"), o(P, "STATS_FLUSH_MS", 120);
|
|
1415
|
+
let tt = P;
|
|
1416
|
+
const de = 5e3, fe = 3e4, Y = 1e4, lt = class lt {
|
|
1296
1417
|
constructor(t = "ws://localhost:8000", e) {
|
|
1297
1418
|
o(this, "ws", null);
|
|
1298
1419
|
/** Frame counts, byte totals, the token-rate estimate and the compaction history — see StreamStatsTracker. */
|
|
1299
|
-
o(this, "statsTracker", new
|
|
1420
|
+
o(this, "statsTracker", new tt());
|
|
1300
1421
|
o(this, "baseUrl");
|
|
1301
1422
|
/**
|
|
1302
1423
|
* Optional callback that returns the current JWT. We re-evaluate it on every connect/reconnect
|
|
@@ -1317,6 +1438,7 @@ const zt = 5e3, Kt = 3e4, _ = 1e4, J = class J {
|
|
|
1317
1438
|
* reset partial-streaming UI for this session and rely on persisted history.
|
|
1318
1439
|
*/
|
|
1319
1440
|
o(this, "onRewindLost");
|
|
1441
|
+
o(this, "onInteractionStarted");
|
|
1320
1442
|
o(this, "sessionId");
|
|
1321
1443
|
o(this, "monitorInterval", null);
|
|
1322
1444
|
o(this, "streamingResponseSerializer");
|
|
@@ -1342,7 +1464,7 @@ const zt = 5e3, Kt = 3e4, _ = 1e4, J = class J {
|
|
|
1342
1464
|
* the single-attach policy makes it undeliverable from here anyway.
|
|
1343
1465
|
*/
|
|
1344
1466
|
o(this, "pendingAnswers", []);
|
|
1345
|
-
this.baseUrl = t, this.getToken = e, this.firstTokenInteractions = /* @__PURE__ */ new Set(), this.streamingResponseSerializer =
|
|
1467
|
+
this.baseUrl = t, this.getToken = e, this.firstTokenInteractions = /* @__PURE__ */ new Set(), this.streamingResponseSerializer = et(), console.log("SOCKET INSTACE", Wt()), this.lastActivity = (/* @__PURE__ */ new Date()).getTime();
|
|
1346
1468
|
}
|
|
1347
1469
|
get stats() {
|
|
1348
1470
|
return this.statsTracker.stats;
|
|
@@ -1365,57 +1487,57 @@ const zt = 5e3, Kt = 3e4, _ = 1e4, J = class J {
|
|
|
1365
1487
|
*/
|
|
1366
1488
|
connect(t, e) {
|
|
1367
1489
|
return new Promise(async (s, n) => {
|
|
1368
|
-
var
|
|
1490
|
+
var M, F;
|
|
1369
1491
|
e != null && e.resume || (this.lastSeq = -1);
|
|
1370
|
-
const r = (
|
|
1492
|
+
const r = (M = this.getToken) == null ? void 0 : M.call(this), a = [];
|
|
1371
1493
|
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("&")}` : "",
|
|
1373
|
-
console.log("[WebSocket] Connecting to", `${
|
|
1494
|
+
const c = a.length > 0 ? `?${a.join("&")}` : "", l = this.baseUrl.replace(/^http:\/\//, "ws://").replace(/^https:\/\//, "wss://"), f = `${l}/ws/connect/${t ?? ""}${c}`;
|
|
1495
|
+
console.log("[WebSocket] Connecting to", `${l}/ws/connect/${t ?? ""}` + (t && this.lastSeq >= 0 ? ` (resume lastSeq=${this.lastSeq})` : "")), this.detachSocket(), this.ws = new WebSocket(f), this.ws.onopen = () => {
|
|
1374
1496
|
console.log("[WebSocket] Socket open — waiting for the session id"), this.ping(), this.monitor();
|
|
1375
|
-
}, this.ws.onmessage = (
|
|
1497
|
+
}, this.ws.onmessage = (v) => {
|
|
1376
1498
|
try {
|
|
1377
1499
|
this.lastActivity = (/* @__PURE__ */ new Date()).getTime(), this.pingSentAt = null;
|
|
1378
|
-
const
|
|
1379
|
-
if (!
|
|
1500
|
+
const C = this.streamingResponseSerializer.parse(v.data);
|
|
1501
|
+
if (!C)
|
|
1380
1502
|
throw "Error parsing event JSON";
|
|
1381
|
-
this.handleMessage(
|
|
1382
|
-
} catch (
|
|
1383
|
-
console.error("[WebSocket] Error parsing message:",
|
|
1503
|
+
this.handleMessage(C, v.data);
|
|
1504
|
+
} catch (C) {
|
|
1505
|
+
console.error("[WebSocket] Error parsing message:", C);
|
|
1384
1506
|
}
|
|
1385
|
-
}, this.ws.onerror = (
|
|
1386
|
-
console.error("[WebSocket] Error:",
|
|
1387
|
-
}, this.ws.onclose = (
|
|
1388
|
-
var
|
|
1389
|
-
console.log(`[WebSocket] Closed: code=${
|
|
1507
|
+
}, this.ws.onerror = (v) => {
|
|
1508
|
+
console.error("[WebSocket] Error:", v), this.onError && this.onError("WebSocket error");
|
|
1509
|
+
}, this.ws.onclose = (v) => {
|
|
1510
|
+
var C;
|
|
1511
|
+
console.log(`[WebSocket] Closed: code=${v.code} reason="${v.reason}" (session ${this.sessionLabel}, lastSeq=${this.lastSeq})`), this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingSentAt = null, this.sessionId = void 0, (C = this.onClose) == null || C.call(this, v.code, v.reason);
|
|
1390
1512
|
};
|
|
1391
|
-
const
|
|
1513
|
+
const p = 200, m = 3e4, u = 8e3, g = this.ws;
|
|
1392
1514
|
this.sessionId = void 0;
|
|
1393
|
-
let
|
|
1515
|
+
let S = 0, D = 0;
|
|
1394
1516
|
for (; ; ) {
|
|
1395
|
-
if (this.ws !==
|
|
1517
|
+
if (this.ws !== g) {
|
|
1396
1518
|
n("Connection attempt superseded by a newer connect()");
|
|
1397
1519
|
return;
|
|
1398
1520
|
}
|
|
1399
1521
|
if (this.sessionId) break;
|
|
1400
|
-
if (
|
|
1522
|
+
if (g.readyState === WebSocket.CLOSING || g.readyState === WebSocket.CLOSED) {
|
|
1401
1523
|
n("Connection closed before a session id was received");
|
|
1402
1524
|
return;
|
|
1403
1525
|
}
|
|
1404
|
-
if (
|
|
1526
|
+
if (g.readyState === WebSocket.CONNECTING && S >= m) {
|
|
1405
1527
|
try {
|
|
1406
|
-
|
|
1528
|
+
g.close();
|
|
1407
1529
|
} catch {
|
|
1408
1530
|
}
|
|
1409
|
-
n(`Server did not accept the connection within ${
|
|
1531
|
+
n(`Server did not accept the connection within ${m / 1e3}s`);
|
|
1410
1532
|
return;
|
|
1411
1533
|
}
|
|
1412
|
-
if (
|
|
1413
|
-
n(`Connected but no session id arrived within ${
|
|
1534
|
+
if (g.readyState === WebSocket.OPEN && D >= u) {
|
|
1535
|
+
n(`Connected but no session id arrived within ${u / 1e3}s`);
|
|
1414
1536
|
return;
|
|
1415
1537
|
}
|
|
1416
|
-
|
|
1538
|
+
S % 2e3 === 0 && console.log("Aguardando session Id"), await this.sleep(p), S += p, g.readyState === WebSocket.OPEN && (D += p);
|
|
1417
1539
|
}
|
|
1418
|
-
console.log(`[WebSocket] Session ${this.sessionId} proven${this.lastSeq >= 0 ? ` (replaying from lastSeq=${this.lastSeq})` : ""}.`), this.lastKnownSessionId = this.sessionId, (
|
|
1540
|
+
console.log(`[WebSocket] Session ${this.sessionId} proven${this.lastSeq >= 0 ? ` (replaying from lastSeq=${this.lastSeq})` : ""}.`), this.lastKnownSessionId = this.sessionId, (F = this.onOpen) == null || F.call(this), this.flushPendingAnswers(this.sessionId), s(this.sessionId);
|
|
1419
1541
|
});
|
|
1420
1542
|
}
|
|
1421
1543
|
/** Drop the current socket without reporting it: handlers off, then close. */
|
|
@@ -1440,6 +1562,7 @@ const zt = 5e3, Kt = 3e4, _ = 1e4, J = class J {
|
|
|
1440
1562
|
* Handle incoming messages from server
|
|
1441
1563
|
*/
|
|
1442
1564
|
handleMessage(t, e) {
|
|
1565
|
+
var n;
|
|
1443
1566
|
switch (typeof t.seq == "number" && t.seq > this.lastSeq && (this.lastSeq = t.seq), t.type) {
|
|
1444
1567
|
case "Pong":
|
|
1445
1568
|
if (this.sessionId = t.sessionId, this.lastKnownSessionId = t.sessionId ?? this.lastKnownSessionId, !t.sessionId) {
|
|
@@ -1453,6 +1576,11 @@ const zt = 5e3, Kt = 3e4, _ = 1e4, J = class J {
|
|
|
1453
1576
|
break;
|
|
1454
1577
|
case "Event":
|
|
1455
1578
|
break;
|
|
1579
|
+
case "InteractionStarted": {
|
|
1580
|
+
const r = $t(t);
|
|
1581
|
+
r ? (n = this.onInteractionStarted) == null || n.call(this, r) : console.warn("[WebSocket] InteractionStarted frame without an interaction id");
|
|
1582
|
+
break;
|
|
1583
|
+
}
|
|
1456
1584
|
case "RewindLost":
|
|
1457
1585
|
console.warn(
|
|
1458
1586
|
`[WebSocket] RewindLost: lost events on resume, resuming from seq=${t.seq}`
|
|
@@ -1461,8 +1589,8 @@ const zt = 5e3, Kt = 3e4, _ = 1e4, J = class J {
|
|
|
1461
1589
|
default:
|
|
1462
1590
|
console.warn("[WebSocket] Unknown message type:", t.type);
|
|
1463
1591
|
}
|
|
1464
|
-
const s =
|
|
1465
|
-
return s ? (
|
|
1592
|
+
const s = st(t);
|
|
1593
|
+
return s ? (Dt(s) && this.emitFirstToken(s.interactionId), this.handleEvent(s, e), s) : null;
|
|
1466
1594
|
}
|
|
1467
1595
|
emitFirstToken(t) {
|
|
1468
1596
|
var e;
|
|
@@ -1501,7 +1629,7 @@ const zt = 5e3, Kt = 3e4, _ = 1e4, J = class J {
|
|
|
1501
1629
|
}
|
|
1502
1630
|
suspendStream() {
|
|
1503
1631
|
this.sendBaseMessage({
|
|
1504
|
-
Action:
|
|
1632
|
+
Action: U.Suspend,
|
|
1505
1633
|
AgentId: "",
|
|
1506
1634
|
InteractionId: "",
|
|
1507
1635
|
ModelId: ""
|
|
@@ -1520,7 +1648,7 @@ const zt = 5e3, Kt = 3e4, _ = 1e4, J = class J {
|
|
|
1520
1648
|
*/
|
|
1521
1649
|
answerHumanTool(t, e) {
|
|
1522
1650
|
const s = {
|
|
1523
|
-
Action:
|
|
1651
|
+
Action: U.AnswerHumanTool,
|
|
1524
1652
|
AgentId: "",
|
|
1525
1653
|
InteractionId: "",
|
|
1526
1654
|
ToolCallId: t,
|
|
@@ -1547,7 +1675,7 @@ const zt = 5e3, Kt = 3e4, _ = 1e4, J = class J {
|
|
|
1547
1675
|
}
|
|
1548
1676
|
try {
|
|
1549
1677
|
this.sendBaseMessage({
|
|
1550
|
-
Action:
|
|
1678
|
+
Action: U.AnswerHumanTool,
|
|
1551
1679
|
AgentId: "",
|
|
1552
1680
|
InteractionId: "",
|
|
1553
1681
|
ToolCallId: s.toolCallId,
|
|
@@ -1581,21 +1709,21 @@ const zt = 5e3, Kt = 3e4, _ = 1e4, J = class J {
|
|
|
1581
1709
|
const t = Date.now();
|
|
1582
1710
|
if (this.pingSentAt !== null) {
|
|
1583
1711
|
const e = t - this.pingSentAt;
|
|
1584
|
-
if (e >=
|
|
1712
|
+
if (e >= Y) {
|
|
1585
1713
|
this.failSocket(
|
|
1586
|
-
|
|
1714
|
+
ee,
|
|
1587
1715
|
`No frame received for ${Math.round(e / 1e3)}s after a Ping`
|
|
1588
1716
|
);
|
|
1589
1717
|
return;
|
|
1590
1718
|
}
|
|
1591
|
-
console.warn(`[WebSocket] Still no reply ${e}ms after the Ping (budget ${
|
|
1719
|
+
console.warn(`[WebSocket] Still no reply ${e}ms after the Ping (budget ${Y}ms, session ${this.sessionLabel}) — the peer may be gone.`);
|
|
1592
1720
|
return;
|
|
1593
1721
|
}
|
|
1594
|
-
t - this.lastActivity >=
|
|
1722
|
+
t - this.lastActivity >= fe && this.ping();
|
|
1595
1723
|
} catch (t) {
|
|
1596
1724
|
console.error("Error on monitor", t);
|
|
1597
1725
|
}
|
|
1598
|
-
},
|
|
1726
|
+
}, de);
|
|
1599
1727
|
}
|
|
1600
1728
|
/**
|
|
1601
1729
|
* Send a heartbeat ping and start the reply clock (unless one is already running).
|
|
@@ -1606,7 +1734,7 @@ const zt = 5e3, Kt = 3e4, _ = 1e4, J = class J {
|
|
|
1606
1734
|
AgentId: "",
|
|
1607
1735
|
InteractionId: "",
|
|
1608
1736
|
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 ${
|
|
1737
|
+
}), 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 ${Y}ms answers it.`));
|
|
1610
1738
|
}
|
|
1611
1739
|
/**
|
|
1612
1740
|
* Behave as if the peer vanished: the socket is closed and reported as an abnormal close (1006),
|
|
@@ -1641,7 +1769,7 @@ const zt = 5e3, Kt = 3e4, _ = 1e4, J = class J {
|
|
|
1641
1769
|
* Disconnect the WebSocket
|
|
1642
1770
|
*/
|
|
1643
1771
|
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(
|
|
1772
|
+
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
1773
|
}
|
|
1646
1774
|
/**
|
|
1647
1775
|
* Check if connected
|
|
@@ -1652,7 +1780,7 @@ const zt = 5e3, Kt = 3e4, _ = 1e4, J = class J {
|
|
|
1652
1780
|
async handleEvent(t, e) {
|
|
1653
1781
|
var s;
|
|
1654
1782
|
try {
|
|
1655
|
-
const n =
|
|
1783
|
+
const n = x.parseFromTypedEvent(t);
|
|
1656
1784
|
if (!n)
|
|
1657
1785
|
throw "Server event was null";
|
|
1658
1786
|
this.statsTracker.record({
|
|
@@ -1668,9 +1796,9 @@ const zt = 5e3, Kt = 3e4, _ = 1e4, J = class J {
|
|
|
1668
1796
|
}
|
|
1669
1797
|
}
|
|
1670
1798
|
};
|
|
1671
|
-
|
|
1672
|
-
let
|
|
1673
|
-
const
|
|
1799
|
+
h(lt, "WebSocketConnecionV2");
|
|
1800
|
+
let Et = lt;
|
|
1801
|
+
const ht = class ht {
|
|
1674
1802
|
constructor(t, e) {
|
|
1675
1803
|
o(this, "cache", /* @__PURE__ */ new Map());
|
|
1676
1804
|
o(this, "serverBaseUrl");
|
|
@@ -1678,7 +1806,7 @@ const j = class j {
|
|
|
1678
1806
|
this.serverBaseUrl = t.replace(/\/$/, ""), this.accessToken = e;
|
|
1679
1807
|
}
|
|
1680
1808
|
get headers() {
|
|
1681
|
-
return { Authorization: `Bearer ${
|
|
1809
|
+
return { Authorization: `Bearer ${Gt(this.accessToken)}` };
|
|
1682
1810
|
}
|
|
1683
1811
|
async init() {
|
|
1684
1812
|
}
|
|
@@ -1725,20 +1853,337 @@ const j = class j {
|
|
|
1725
1853
|
}
|
|
1726
1854
|
}
|
|
1727
1855
|
};
|
|
1728
|
-
|
|
1729
|
-
let
|
|
1856
|
+
h(ht, "HttpArtifactService");
|
|
1857
|
+
let Ct = ht;
|
|
1858
|
+
const ut = class ut extends Error {
|
|
1859
|
+
constructor(t, e) {
|
|
1860
|
+
super(e ?? `GET detached-run frames answered ${t}`), this.status = t, this.name = "DetachedRunFramesHttpError";
|
|
1861
|
+
}
|
|
1862
|
+
};
|
|
1863
|
+
h(ut, "DetachedRunFramesHttpError");
|
|
1864
|
+
let L = ut;
|
|
1865
|
+
function ge(i) {
|
|
1866
|
+
if (i instanceof L) {
|
|
1867
|
+
const { status: t } = i;
|
|
1868
|
+
return { kind: t === 401 ? "unauthorized" : t === 403 ? "forbidden" : t === 404 || t === 410 ? "notFound" : "gaveUp", status: t, cause: i };
|
|
1869
|
+
}
|
|
1870
|
+
return { kind: "gaveUp", cause: i };
|
|
1871
|
+
}
|
|
1872
|
+
h(ge, "toDetachedRunFollowError");
|
|
1873
|
+
function pe(i) {
|
|
1874
|
+
let t = "", e = [], s, n;
|
|
1875
|
+
const r = /* @__PURE__ */ h(() => {
|
|
1876
|
+
(e.length > 0 || s !== void 0) && i({ event: s, data: e.join(`
|
|
1877
|
+
`), id: n }), e = [], s = void 0, n = void 0;
|
|
1878
|
+
}, "dispatch"), a = /* @__PURE__ */ h((c) => {
|
|
1879
|
+
if (c === "") return r();
|
|
1880
|
+
if (c.startsWith(":")) return;
|
|
1881
|
+
const l = c.indexOf(":"), f = l === -1 ? c : c.slice(0, l);
|
|
1882
|
+
let p = l === -1 ? "" : c.slice(l + 1);
|
|
1883
|
+
p.startsWith(" ") && (p = p.slice(1)), f === "data" ? e.push(p) : f === "event" ? s = p : f === "id" && (n = p);
|
|
1884
|
+
}, "line");
|
|
1885
|
+
return {
|
|
1886
|
+
push(c) {
|
|
1887
|
+
for (t += c; ; ) {
|
|
1888
|
+
const l = t.search(/\r\n|\r|\n/);
|
|
1889
|
+
if (l === -1 || t[l] === "\r" && l === t.length - 1) return;
|
|
1890
|
+
const f = t.startsWith(`\r
|
|
1891
|
+
`, l) ? 2 : 1;
|
|
1892
|
+
a(t.slice(0, l)), t = t.slice(l + f);
|
|
1893
|
+
}
|
|
1894
|
+
},
|
|
1895
|
+
/** Nothing half-received: no partial line buffered, no event begun and not yet dispatched. */
|
|
1896
|
+
idle() {
|
|
1897
|
+
return t === "" && e.length === 0 && s === void 0 && n === void 0;
|
|
1898
|
+
},
|
|
1899
|
+
flush() {
|
|
1900
|
+
t !== "" && a(t.replace(/\r$/, "")), t = "";
|
|
1901
|
+
}
|
|
1902
|
+
};
|
|
1903
|
+
}
|
|
1904
|
+
h(pe, "createSseParser");
|
|
1905
|
+
function me(i) {
|
|
1906
|
+
return i >= 500 || i === 408 || i === 429;
|
|
1907
|
+
}
|
|
1908
|
+
h(me, "retryable");
|
|
1909
|
+
function we(i, t) {
|
|
1910
|
+
return new Promise((e) => {
|
|
1911
|
+
if (t != null && t.aborted) return e();
|
|
1912
|
+
const s = setTimeout(n, i);
|
|
1913
|
+
function n() {
|
|
1914
|
+
clearTimeout(s), t == null || t.removeEventListener("abort", n), e();
|
|
1915
|
+
}
|
|
1916
|
+
h(n, "done"), t == null || t.addEventListener("abort", n, { once: !0 });
|
|
1917
|
+
});
|
|
1918
|
+
}
|
|
1919
|
+
h(we, "sleep");
|
|
1920
|
+
function Se(i, t, e) {
|
|
1921
|
+
return `${i.replace(/\/+$/, "")}/detached-runs/${encodeURIComponent(t)}/frames?afterSeq=${e}`;
|
|
1922
|
+
}
|
|
1923
|
+
h(Se, "framesUrl");
|
|
1924
|
+
async function Ie(i) {
|
|
1925
|
+
var M, F, v, C, ft;
|
|
1926
|
+
const { baseUrl: t, runId: e, signal: s, onFrame: n, onEnd: r, onOpen: a, onRetry: c } = i, l = i.fetchImpl ?? ((A, $) => fetch(A, $)), f = ((M = i.retry) == null ? void 0 : M.initialMs) ?? 500, p = ((F = i.retry) == null ? void 0 : F.maxMs) ?? 15e3, m = ((v = i.retry) == null ? void 0 : v.maxAttempts) ?? Number.POSITIVE_INFINITY;
|
|
1927
|
+
let u = i.afterSeq ?? 0, g = 0, S = !1;
|
|
1928
|
+
async function D(A) {
|
|
1929
|
+
if (i.onUnauthorized)
|
|
1930
|
+
try {
|
|
1931
|
+
if (await i.onUnauthorized()) return !0;
|
|
1932
|
+
} catch (O) {
|
|
1933
|
+
console.warn(`[DetachedRunFrames] run ${e}: onUnauthorized threw`, O);
|
|
1934
|
+
}
|
|
1935
|
+
if (!i.getToken) return !1;
|
|
1936
|
+
const $ = await i.getToken() ?? void 0;
|
|
1937
|
+
return !!$ && $ !== A;
|
|
1938
|
+
}
|
|
1939
|
+
for (h(D, "secondChance"); !(s != null && s.aborted); ) {
|
|
1940
|
+
let A;
|
|
1941
|
+
try {
|
|
1942
|
+
const O = { Accept: "text/event-stream" }, K = await ((C = i.getToken) == null ? void 0 : C.call(i)) ?? void 0;
|
|
1943
|
+
K && (O.Authorization = `Bearer ${K}`);
|
|
1944
|
+
const k = await l(Se(t, e, u), { method: "GET", headers: O, signal: s, cache: "no-store" });
|
|
1945
|
+
if (k.status === 401) {
|
|
1946
|
+
if (!S && await D(K)) {
|
|
1947
|
+
S = !0;
|
|
1948
|
+
continue;
|
|
1949
|
+
}
|
|
1950
|
+
throw new L(401);
|
|
1951
|
+
}
|
|
1952
|
+
if (S = !1, !k.ok)
|
|
1953
|
+
throw me(k.status) ? new Error(`GET detached-run frames answered ${k.status}`) : new L(k.status);
|
|
1954
|
+
if (!k.body) throw new L(k.status, "The frames response has no readable body");
|
|
1955
|
+
a == null || a();
|
|
1956
|
+
let W = !1;
|
|
1957
|
+
const G = pe((T) => {
|
|
1958
|
+
if (T.event === "end") {
|
|
1959
|
+
const b = Number(T.data);
|
|
1960
|
+
T.data !== "" && Number.isFinite(b) && b > u && (u = b), W = !0;
|
|
1961
|
+
return;
|
|
1962
|
+
}
|
|
1963
|
+
if (T.event !== void 0 && T.event !== "message" || T.data === "") return;
|
|
1964
|
+
const R = T.id !== void 0 && T.id !== "" ? Number(T.id) : void 0;
|
|
1965
|
+
if (R !== void 0 && Number.isFinite(R)) {
|
|
1966
|
+
if (R <= u) return;
|
|
1967
|
+
u = R;
|
|
1968
|
+
}
|
|
1969
|
+
W = !1;
|
|
1970
|
+
let pt;
|
|
1971
|
+
try {
|
|
1972
|
+
pt = JSON.parse(T.data);
|
|
1973
|
+
} catch (b) {
|
|
1974
|
+
console.warn(`[DetachedRunFrames] run ${e}: a frame that is not JSON was skipped (seq ${T.id ?? "?"})`, b);
|
|
1975
|
+
return;
|
|
1976
|
+
}
|
|
1977
|
+
g = 0;
|
|
1978
|
+
try {
|
|
1979
|
+
n(pt, R);
|
|
1980
|
+
} catch (b) {
|
|
1981
|
+
console.error(`[DetachedRunFrames] run ${e}: onFrame threw on seq ${T.id ?? "?"}`, b);
|
|
1982
|
+
}
|
|
1983
|
+
}), B = k.body.getReader(), gt = new TextDecoder();
|
|
1984
|
+
try {
|
|
1985
|
+
for (; ; ) {
|
|
1986
|
+
const { done: T, value: R } = await B.read();
|
|
1987
|
+
if (T) break;
|
|
1988
|
+
G.push(gt.decode(R, { stream: !0 }));
|
|
1989
|
+
}
|
|
1990
|
+
G.push(gt.decode()), G.idle() || (W = !1), G.flush();
|
|
1991
|
+
} finally {
|
|
1992
|
+
(ft = B.releaseLock) == null || ft.call(B);
|
|
1993
|
+
}
|
|
1994
|
+
if (W)
|
|
1995
|
+
return r == null || r(u), { reason: "end", lastSeq: u };
|
|
1996
|
+
A = new Error("The frames stream closed before its end event");
|
|
1997
|
+
} catch (O) {
|
|
1998
|
+
if (s != null && s.aborted) break;
|
|
1999
|
+
if (O instanceof L) throw O;
|
|
2000
|
+
A = O;
|
|
2001
|
+
}
|
|
2002
|
+
if (g += 1, g >= m) throw A;
|
|
2003
|
+
const $ = Math.min(f * 2 ** (g - 1), p);
|
|
2004
|
+
try {
|
|
2005
|
+
c == null || c(A, g, $);
|
|
2006
|
+
} catch {
|
|
2007
|
+
}
|
|
2008
|
+
await we($, s);
|
|
2009
|
+
}
|
|
2010
|
+
return { reason: "aborted", lastSeq: u };
|
|
2011
|
+
}
|
|
2012
|
+
h(Ie, "streamDetachedRunFrames");
|
|
2013
|
+
const dt = class dt {
|
|
2014
|
+
constructor(t) {
|
|
2015
|
+
o(this, "onEvent");
|
|
2016
|
+
o(this, "onError");
|
|
2017
|
+
o(this, "onOpen");
|
|
2018
|
+
o(this, "onFirstToken");
|
|
2019
|
+
o(this, "onSuspended");
|
|
2020
|
+
o(this, "onClose");
|
|
2021
|
+
o(this, "onNewPacket");
|
|
2022
|
+
o(this, "onInteractionStarted");
|
|
2023
|
+
/** The stream of the current follow is over: the server closed it right after an `event: end`. */
|
|
2024
|
+
o(this, "onEnd");
|
|
2025
|
+
/** Following stopped for good — the run is gone, forbidden, the credentials failed twice, or retries ran out. */
|
|
2026
|
+
o(this, "onFollowError");
|
|
2027
|
+
o(this, "options");
|
|
2028
|
+
o(this, "serializer", et());
|
|
2029
|
+
o(this, "firstTokens", /* @__PURE__ */ new Set());
|
|
2030
|
+
o(this, "runId");
|
|
2031
|
+
o(this, "controller", null);
|
|
2032
|
+
o(this, "following", !1);
|
|
2033
|
+
o(this, "lastSeq", 0);
|
|
2034
|
+
this.options = t;
|
|
2035
|
+
}
|
|
2036
|
+
/** The highest seq delivered so far — where the next follow resumes. */
|
|
2037
|
+
get cursor() {
|
|
2038
|
+
return this.lastSeq;
|
|
2039
|
+
}
|
|
2040
|
+
/** Whether a follow is running (false after `end`, an abort or a fatal answer). */
|
|
2041
|
+
get isFollowing() {
|
|
2042
|
+
return this.following;
|
|
2043
|
+
}
|
|
2044
|
+
connect(t, e) {
|
|
2045
|
+
return t ? ((t !== this.runId || !(e != null && e.resume)) && (this.lastSeq = 0, this.firstTokens.clear()), this.runId = t, this.start(t)) : Promise.reject(new Error("DetachedRunFramesTransport: connect() needs the run id"));
|
|
2046
|
+
}
|
|
2047
|
+
/**
|
|
2048
|
+
* Follow again from the last seq — after the stream ended and the run was resumed (answered). A no-op while a
|
|
2049
|
+
* follow is running. Resolves once the server answers with the stream.
|
|
2050
|
+
*/
|
|
2051
|
+
follow() {
|
|
2052
|
+
return this.runId ? this.following ? Promise.resolve(this.runId) : this.start(this.runId) : Promise.reject(new Error("DetachedRunFramesTransport: follow() before connect()"));
|
|
2053
|
+
}
|
|
2054
|
+
start(t) {
|
|
2055
|
+
var s;
|
|
2056
|
+
(s = this.controller) == null || s.abort();
|
|
2057
|
+
const e = new AbortController();
|
|
2058
|
+
return this.controller = e, this.following = !0, new Promise((n, r) => {
|
|
2059
|
+
let a = !1;
|
|
2060
|
+
Ie({
|
|
2061
|
+
...this.options,
|
|
2062
|
+
runId: t,
|
|
2063
|
+
afterSeq: this.lastSeq,
|
|
2064
|
+
signal: e.signal,
|
|
2065
|
+
onOpen: /* @__PURE__ */ h(() => {
|
|
2066
|
+
var c;
|
|
2067
|
+
a || (a = !0, (c = this.onOpen) == null || c.call(this), n(t));
|
|
2068
|
+
}, "onOpen"),
|
|
2069
|
+
onFrame: /* @__PURE__ */ h((c, l) => {
|
|
2070
|
+
typeof l == "number" && l > this.lastSeq && (this.lastSeq = l), this.dispatch(c);
|
|
2071
|
+
}, "onFrame"),
|
|
2072
|
+
onEnd: /* @__PURE__ */ h((c) => {
|
|
2073
|
+
var l;
|
|
2074
|
+
this.lastSeq = Math.max(this.lastSeq, c), (l = this.onEnd) == null || l.call(this, this.lastSeq);
|
|
2075
|
+
}, "onEnd"),
|
|
2076
|
+
onRetry: /* @__PURE__ */ h((c, l, f) => {
|
|
2077
|
+
console.warn(`[DetachedRunFrames] run ${t}: the stream failed (attempt ${l}); following again from seq ${this.lastSeq} in ${f}ms.`, c);
|
|
2078
|
+
}, "onRetry")
|
|
2079
|
+
}).then(() => {
|
|
2080
|
+
a || r(new Error("The frames stream stopped before it opened"));
|
|
2081
|
+
}).catch((c) => {
|
|
2082
|
+
var p, m, u;
|
|
2083
|
+
const l = ge(c), f = l.kind === "notFound" ? kt : l.kind === "forbidden" || l.kind === "unauthorized" ? 1008 : 1011;
|
|
2084
|
+
console.error(`[DetachedRunFrames] run ${t}: following stopped (${l.kind})`, c);
|
|
2085
|
+
try {
|
|
2086
|
+
(p = this.onFollowError) == null || p.call(this, l);
|
|
2087
|
+
} catch (g) {
|
|
2088
|
+
console.error("[DetachedRunFrames] onFollowError threw", g);
|
|
2089
|
+
}
|
|
2090
|
+
(m = this.onError) == null || m.call(this, String((c == null ? void 0 : c.message) ?? c)), (u = this.onClose) == null || u.call(this, f, String((c == null ? void 0 : c.message) ?? "")), a || r(c);
|
|
2091
|
+
}).finally(() => {
|
|
2092
|
+
this.controller === e && (this.following = !1);
|
|
2093
|
+
});
|
|
2094
|
+
});
|
|
2095
|
+
}
|
|
2096
|
+
/** One frame, decoded exactly as the chat socket decodes it. A frame that fails to decode is skipped. */
|
|
2097
|
+
dispatch(t) {
|
|
2098
|
+
var r, a, c;
|
|
2099
|
+
let e;
|
|
2100
|
+
try {
|
|
2101
|
+
e = this.serializer.parse(t);
|
|
2102
|
+
} catch (l) {
|
|
2103
|
+
console.warn("[DetachedRunFrames] a frame failed to decode", l);
|
|
2104
|
+
return;
|
|
2105
|
+
}
|
|
2106
|
+
if (!e) return;
|
|
2107
|
+
const s = $t(e);
|
|
2108
|
+
if (s) {
|
|
2109
|
+
(r = this.onInteractionStarted) == null || r.call(this, s);
|
|
2110
|
+
return;
|
|
2111
|
+
}
|
|
2112
|
+
const n = st(e);
|
|
2113
|
+
if (n) {
|
|
2114
|
+
Dt(n) && n.interactionId && !this.firstTokens.has(n.interactionId) && (this.firstTokens.add(n.interactionId), (a = this.onFirstToken) == null || a.call(this, n.interactionId));
|
|
2115
|
+
try {
|
|
2116
|
+
const l = x.parseFromTypedEvent(n);
|
|
2117
|
+
(c = this.onEvent) == null || c.call(this, l).catch((f) => console.error("[DetachedRunFrames] onEvent failed", f));
|
|
2118
|
+
} catch (l) {
|
|
2119
|
+
console.error("[DetachedRunFrames] a frame could not be mapped to a server event", l);
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
sendMessage(t) {
|
|
2124
|
+
throw new Error("A detached-run transcript is read-only: answer the run through its own endpoint.");
|
|
2125
|
+
}
|
|
2126
|
+
suspendStream() {
|
|
2127
|
+
}
|
|
2128
|
+
closeStream() {
|
|
2129
|
+
var t;
|
|
2130
|
+
(t = this.controller) == null || t.abort(), this.controller = null, this.following = !1;
|
|
2131
|
+
}
|
|
2132
|
+
isConnected() {
|
|
2133
|
+
return this.controller !== null;
|
|
2134
|
+
}
|
|
2135
|
+
};
|
|
2136
|
+
h(dt, "DetachedRunFramesTransport");
|
|
2137
|
+
let Mt = dt;
|
|
2138
|
+
const Te = "todolistUpdated";
|
|
2139
|
+
function $e(i, t = et()) {
|
|
2140
|
+
var n, r;
|
|
2141
|
+
let e;
|
|
2142
|
+
try {
|
|
2143
|
+
const a = t.parse(i), c = a ? st(a) : void 0;
|
|
2144
|
+
e = c ? x.parseFromTypedEvent(c) : void 0;
|
|
2145
|
+
} catch {
|
|
2146
|
+
return [];
|
|
2147
|
+
}
|
|
2148
|
+
if (!e) return [];
|
|
2149
|
+
const s = [];
|
|
2150
|
+
for (const a of e.parts ?? [])
|
|
2151
|
+
if (a.eventType === I.ToolEvent && ((n = a.toolDetails) == null ? void 0 : n.eventName) === Te) {
|
|
2152
|
+
const c = ye(a.toolDetails.eventData);
|
|
2153
|
+
c && s.push({ kind: "todo", todoList: c });
|
|
2154
|
+
} else (a.eventType === I.FunctionCall || a.eventType === I.PartialFunctionCall) && ((r = a.functionDetails) != null && r.name) ? s.push({ kind: "tool", name: a.functionDetails.name, interactionId: e.interactionId }) : a.eventType === I.Text && a.text && s.push({ kind: "text", text: a.text, partial: !!e.partial, interactionId: e.interactionId });
|
|
2155
|
+
return s;
|
|
2156
|
+
}
|
|
2157
|
+
h($e, "readDetachedRunActivity");
|
|
2158
|
+
function ye(i) {
|
|
2159
|
+
if (!i) return null;
|
|
2160
|
+
try {
|
|
2161
|
+
const t = JSON.parse(i);
|
|
2162
|
+
return t && Array.isArray(t.items) ? t : null;
|
|
2163
|
+
} catch {
|
|
2164
|
+
return null;
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
h(ye, "parseTodoList");
|
|
1730
2168
|
export {
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
2169
|
+
Tt as A,
|
|
2170
|
+
V as C,
|
|
2171
|
+
L as D,
|
|
2172
|
+
It as E,
|
|
2173
|
+
Ct as H,
|
|
2174
|
+
_ as I,
|
|
2175
|
+
St as L,
|
|
2176
|
+
zt as M,
|
|
2177
|
+
Te as T,
|
|
2178
|
+
re as W,
|
|
2179
|
+
Mt as a,
|
|
2180
|
+
j as b,
|
|
2181
|
+
Et as c,
|
|
2182
|
+
pe as d,
|
|
2183
|
+
Zt as e,
|
|
2184
|
+
$e as r,
|
|
2185
|
+
Ie as s,
|
|
2186
|
+
ge as t,
|
|
2187
|
+
De as u
|
|
1743
2188
|
};
|
|
1744
|
-
//# sourceMappingURL=
|
|
2189
|
+
//# sourceMappingURL=detachedRunActivity-CjyFTKSw.js.map
|