@aintela/chat 0.3.7 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components.js +5392 -5305
- package/dist/components.js.map +1 -1
- package/dist/hooks.js +1 -1
- package/dist/{httpArtifactService-qcYDyDh_.js → httpArtifactService-CqEs3x-Q.js} +308 -271
- package/dist/httpArtifactService-CqEs3x-Q.js.map +1 -0
- package/dist/{httpSessionService-DXlT2vxT.js → httpSessionService-BnNVSRID.js} +2 -2
- package/dist/{httpSessionService-DXlT2vxT.js.map → httpSessionService-BnNVSRID.js.map} +1 -1
- package/dist/index.js +129 -127
- package/dist/models.js +1 -1
- package/dist/{serializer-D2W42bdT.js → serializer-CdUT_OO2.js} +424 -408
- package/dist/serializer-CdUT_OO2.js.map +1 -0
- package/dist/services.js +2 -2
- package/dist/src/components/Library/SessionUsagePanel.d.ts +14 -0
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/components/v2/PromptV2.d.ts +16 -0
- package/dist/src/models/semanticKernelModel/models.d.ts +22 -0
- package/dist/src/services/WebSocketConnection/WebSocketConnectionV2.d.ts +8 -0
- package/dist/src/utils/sessionCompaction.d.ts +15 -0
- package/dist/src/utils/sessionCompaction.test.d.ts +1 -0
- package/dist/{useChatSessions-1AAvAdPW.js → useChatSessions-eMttJ-qI.js} +2 -2
- package/dist/{useChatSessions-1AAvAdPW.js.map → useChatSessions-eMttJ-qI.js.map} +1 -1
- package/package.json +1 -1
- package/dist/httpArtifactService-qcYDyDh_.js.map +0 -1
- package/dist/serializer-D2W42bdT.js.map +0 -1
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
var it = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var f = (
|
|
4
|
-
var i = (
|
|
5
|
-
import { i as
|
|
6
|
-
import { I as N, E as
|
|
7
|
-
import { unified as
|
|
8
|
-
import
|
|
9
|
-
import { toMarkdown as
|
|
10
|
-
import { format as
|
|
11
|
-
import
|
|
12
|
-
import { P as
|
|
13
|
-
import { r as
|
|
2
|
+
var mt = (w, t, e) => t in w ? it(w, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : w[t] = e;
|
|
3
|
+
var f = (w, t) => it(w, "name", { value: t, configurable: !0 });
|
|
4
|
+
var i = (w, t, e) => mt(w, typeof t != "symbol" ? t + "" : t, e);
|
|
5
|
+
import { i as St, a as wt, d as Tt } from "./environmentUtils-VZNTCzEE.js";
|
|
6
|
+
import { I as N, E as y, j as yt, S as ft, q as Ct, L as It, P as L, l as vt, o as Et, T as Mt, m as Dt, C as U } from "./serializer-CdUT_OO2.js";
|
|
7
|
+
import { unified as Ot } from "unified";
|
|
8
|
+
import kt from "remark-parse";
|
|
9
|
+
import { toMarkdown as At } from "mdast-util-to-markdown";
|
|
10
|
+
import { format as Pt } from "date-fns";
|
|
11
|
+
import Nt from "lodash";
|
|
12
|
+
import { P as _t, C as F } from "./Prompt-DZb7OaPp.js";
|
|
13
|
+
import { r as bt } from "./httpSessionService-BnNVSRID.js";
|
|
14
14
|
const W = {
|
|
15
15
|
PROMPTS: "envision-prompts"
|
|
16
|
-
},
|
|
16
|
+
}, Rt = 50, z = class z {
|
|
17
17
|
getPrompts() {
|
|
18
18
|
try {
|
|
19
19
|
const t = localStorage.getItem(W.PROMPTS);
|
|
@@ -43,7 +43,7 @@ const W = {
|
|
|
43
43
|
storePrompt(t) {
|
|
44
44
|
try {
|
|
45
45
|
const e = this.getPrompts().filter((s) => s.promptText !== t.promptText);
|
|
46
|
-
e.unshift(t), localStorage.setItem(W.PROMPTS, JSON.stringify(e.slice(0,
|
|
46
|
+
e.unshift(t), localStorage.setItem(W.PROMPTS, JSON.stringify(e.slice(0, Rt)));
|
|
47
47
|
} catch (e) {
|
|
48
48
|
console.error("Error storing prompt:", e);
|
|
49
49
|
}
|
|
@@ -56,16 +56,16 @@ const W = {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
|
-
f(
|
|
60
|
-
let at =
|
|
61
|
-
const
|
|
62
|
-
const t =
|
|
59
|
+
f(z, "LocalStorageService");
|
|
60
|
+
let at = z;
|
|
61
|
+
const ne = /* @__PURE__ */ f((w) => {
|
|
62
|
+
const t = w.getPrompts(), e = t.length;
|
|
63
63
|
if (e > 0) {
|
|
64
64
|
const s = t[0].promptText, a = t[t.length - 1].promptText, n = t[0].created;
|
|
65
65
|
return { promptState: e + "_" + s + "_" + a + "_" + n };
|
|
66
66
|
} else
|
|
67
67
|
return { promptState: "0" };
|
|
68
|
-
}, "usePromptState"),
|
|
68
|
+
}, "usePromptState"), K = class K {
|
|
69
69
|
constructor() {
|
|
70
70
|
i(this, "activityLost", "activityLost");
|
|
71
71
|
i(this, "artifactGenerated", "artifactGenerated");
|
|
@@ -90,9 +90,9 @@ const Vt = /* @__PURE__ */ f((D) => {
|
|
|
90
90
|
i(this, "gatewayFirstToken", "gatewayFirstToken");
|
|
91
91
|
}
|
|
92
92
|
};
|
|
93
|
-
f(
|
|
94
|
-
let $ =
|
|
95
|
-
const
|
|
93
|
+
f(K, "EventTypes");
|
|
94
|
+
let $ = K;
|
|
95
|
+
const c = new $(), J = class J {
|
|
96
96
|
constructor() {
|
|
97
97
|
i(this, "listeners", {});
|
|
98
98
|
i(this, "listenersCount", {});
|
|
@@ -113,239 +113,239 @@ const o = new $(), z = class z {
|
|
|
113
113
|
return this.listenersCount[t];
|
|
114
114
|
}
|
|
115
115
|
activityOnLost(t) {
|
|
116
|
-
const e =
|
|
116
|
+
const e = c.activityLost;
|
|
117
117
|
this.addListener(e, t);
|
|
118
118
|
}
|
|
119
119
|
activityEmitLost() {
|
|
120
|
-
this.callListeners(
|
|
120
|
+
this.callListeners(c.activityLost);
|
|
121
121
|
}
|
|
122
122
|
/* typed artifact listeners */
|
|
123
123
|
artifactOnGenerated(t) {
|
|
124
|
-
const e =
|
|
124
|
+
const e = c.artifactGenerated;
|
|
125
125
|
this.addListener(e, t);
|
|
126
126
|
}
|
|
127
127
|
artifactEmitGenerated(t) {
|
|
128
|
-
this.callListeners(
|
|
128
|
+
this.callListeners(c.artifactGenerated, t);
|
|
129
129
|
}
|
|
130
130
|
artifactOffGenerated(t) {
|
|
131
|
-
const e =
|
|
131
|
+
const e = c.artifactGenerated;
|
|
132
132
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
133
133
|
}
|
|
134
134
|
artifactOnSelected(t) {
|
|
135
|
-
const e =
|
|
135
|
+
const e = c.artifactSelected;
|
|
136
136
|
this.addListener(e, t);
|
|
137
137
|
}
|
|
138
138
|
artifactEmitSelected(t) {
|
|
139
|
-
this.callListeners(
|
|
139
|
+
this.callListeners(c.artifactSelected, t);
|
|
140
140
|
}
|
|
141
141
|
artifactOffSelected(t) {
|
|
142
|
-
const e =
|
|
142
|
+
const e = c.artifactSelected;
|
|
143
143
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
144
144
|
}
|
|
145
145
|
artifactOnDeleted(t) {
|
|
146
|
-
const e =
|
|
146
|
+
const e = c.artifactDeleted;
|
|
147
147
|
this.addListener(e, t);
|
|
148
148
|
}
|
|
149
149
|
artifactEmitDeleted(t) {
|
|
150
|
-
this.callListeners(
|
|
150
|
+
this.callListeners(c.artifactDeleted, t);
|
|
151
151
|
}
|
|
152
152
|
artifactOffDeleted(t) {
|
|
153
|
-
const e =
|
|
153
|
+
const e = c.artifactDeleted;
|
|
154
154
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
155
155
|
}
|
|
156
156
|
gatewayOnMessage(t) {
|
|
157
|
-
const e =
|
|
157
|
+
const e = c.gatewayMessage;
|
|
158
158
|
this.addListener(e, t);
|
|
159
159
|
}
|
|
160
160
|
gatewayOnTurnComplete(t) {
|
|
161
|
-
const e =
|
|
161
|
+
const e = c.gatewayTurnComplete;
|
|
162
162
|
this.addListener(e, t);
|
|
163
163
|
}
|
|
164
164
|
gatewayOnTurnOpen(t) {
|
|
165
|
-
const e =
|
|
165
|
+
const e = c.gatewayTurnOpen;
|
|
166
166
|
this.addListener(e, t);
|
|
167
167
|
}
|
|
168
168
|
gatewayOnStreamError(t) {
|
|
169
|
-
const e =
|
|
169
|
+
const e = c.gatewayStreamError;
|
|
170
170
|
this.addListener(e, t);
|
|
171
171
|
}
|
|
172
172
|
gatewayOnStreamEnded(t) {
|
|
173
|
-
const e =
|
|
173
|
+
const e = c.gatewayStreamEnded;
|
|
174
174
|
this.addListener(e, t);
|
|
175
175
|
}
|
|
176
176
|
gatewayOffStreamEnded(t) {
|
|
177
|
-
const e =
|
|
177
|
+
const e = c.gatewayStreamEnded;
|
|
178
178
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
179
179
|
}
|
|
180
180
|
gatewayEmitStreamEnded(t, e) {
|
|
181
|
-
this.callListeners(
|
|
181
|
+
this.callListeners(c.gatewayStreamEnded, t, e);
|
|
182
182
|
}
|
|
183
183
|
gatewayEmitMessage(t, e = null) {
|
|
184
|
-
this.callListeners(
|
|
184
|
+
this.callListeners(c.gatewayMessage, t, e);
|
|
185
185
|
}
|
|
186
186
|
gatewayEmitTurnComplete(t, e) {
|
|
187
|
-
this.callListeners(
|
|
187
|
+
this.callListeners(c.gatewayTurnComplete, t, e);
|
|
188
188
|
}
|
|
189
189
|
gatewayEmitStreamError(t) {
|
|
190
|
-
this.callListeners(
|
|
190
|
+
this.callListeners(c.gatewayStreamError, t);
|
|
191
191
|
}
|
|
192
192
|
gatewayEmitTurnOpen(t) {
|
|
193
|
-
this.callListeners(
|
|
193
|
+
this.callListeners(c.gatewayTurnOpen, t);
|
|
194
194
|
}
|
|
195
195
|
gatewayOffMessage(t) {
|
|
196
|
-
const e =
|
|
196
|
+
const e = c.gatewayMessage;
|
|
197
197
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
198
198
|
}
|
|
199
199
|
gatewayOffTurnComplete(t) {
|
|
200
|
-
const e =
|
|
200
|
+
const e = c.gatewayTurnComplete;
|
|
201
201
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
202
202
|
}
|
|
203
203
|
gatewayOffTurnOpen(t) {
|
|
204
|
-
const e =
|
|
204
|
+
const e = c.gatewayTurnOpen;
|
|
205
205
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
206
206
|
}
|
|
207
207
|
gatewayOffStreamError(t) {
|
|
208
|
-
const e =
|
|
208
|
+
const e = c.gatewayStreamError;
|
|
209
209
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
210
210
|
}
|
|
211
211
|
sessionOnCreated(t) {
|
|
212
|
-
const e =
|
|
212
|
+
const e = c.sessionCreated;
|
|
213
213
|
this.addListener(e, t);
|
|
214
214
|
}
|
|
215
215
|
chatOnMessageSent(t) {
|
|
216
|
-
const e =
|
|
216
|
+
const e = c.onMessageSent;
|
|
217
217
|
this.addListener(e, t);
|
|
218
218
|
}
|
|
219
219
|
chatOffMessageSent(t) {
|
|
220
|
-
const e =
|
|
220
|
+
const e = c.onMessageSent;
|
|
221
221
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
222
222
|
}
|
|
223
223
|
ChatEmitMessageSent(t, e) {
|
|
224
|
-
this.callListeners(
|
|
224
|
+
this.callListeners(c.onMessageSent, t, e);
|
|
225
225
|
}
|
|
226
226
|
chatOnMessageError(t) {
|
|
227
|
-
const e =
|
|
227
|
+
const e = c.onMessageError;
|
|
228
228
|
this.addListener(e, t);
|
|
229
229
|
}
|
|
230
230
|
chatOffMessageError(t) {
|
|
231
|
-
const e =
|
|
231
|
+
const e = c.onMessageError;
|
|
232
232
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
233
233
|
}
|
|
234
234
|
ChatEmitMessageError(t) {
|
|
235
|
-
this.callListeners(
|
|
235
|
+
this.callListeners(c.onMessageError, t);
|
|
236
236
|
}
|
|
237
237
|
sessionOnUpdated(t) {
|
|
238
|
-
const e =
|
|
238
|
+
const e = c.sessionUpdated;
|
|
239
239
|
this.addListener(e, t);
|
|
240
240
|
}
|
|
241
241
|
sessionEmitCreated(t) {
|
|
242
|
-
this.callListeners(
|
|
242
|
+
this.callListeners(c.sessionCreated, t);
|
|
243
243
|
}
|
|
244
244
|
sessionEmitUpdated(t) {
|
|
245
|
-
this.callListeners(
|
|
245
|
+
this.callListeners(c.sessionUpdated, t);
|
|
246
246
|
}
|
|
247
247
|
sessionOffCreated(t) {
|
|
248
|
-
const e =
|
|
248
|
+
const e = c.sessionCreated;
|
|
249
249
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
250
250
|
}
|
|
251
251
|
sessionOffUpdated(t) {
|
|
252
|
-
const e =
|
|
252
|
+
const e = c.sessionUpdated;
|
|
253
253
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
254
254
|
}
|
|
255
255
|
gatewayEmitFunctionResponse(t) {
|
|
256
|
-
this.callListeners(
|
|
256
|
+
this.callListeners(c.gatewayFunctionResponse, t);
|
|
257
257
|
}
|
|
258
258
|
gatewayOffFunctionResponse(t) {
|
|
259
|
-
const e =
|
|
259
|
+
const e = c.gatewayFunctionResponse;
|
|
260
260
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
261
261
|
}
|
|
262
262
|
gatewayOnFunctionResponse(t) {
|
|
263
|
-
const e =
|
|
263
|
+
const e = c.gatewayFunctionResponse;
|
|
264
264
|
this.addListener(e, t);
|
|
265
265
|
}
|
|
266
266
|
// UI events
|
|
267
267
|
uiOnUnsavedPopoverToggle(t) {
|
|
268
|
-
const e =
|
|
268
|
+
const e = c.uiUnsavedPopoverToggle;
|
|
269
269
|
this.addListener(e, t);
|
|
270
270
|
}
|
|
271
271
|
uiEmitUnsavedPopoverToggle(t) {
|
|
272
|
-
this.callListeners(
|
|
272
|
+
this.callListeners(c.uiUnsavedPopoverToggle, t);
|
|
273
273
|
}
|
|
274
274
|
uiOffUnsavedPopoverToggle(t) {
|
|
275
|
-
const e =
|
|
275
|
+
const e = c.uiUnsavedPopoverToggle;
|
|
276
276
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
277
277
|
}
|
|
278
278
|
// Artifacts storage update events
|
|
279
279
|
artifactsOnStorageUpdated(t) {
|
|
280
|
-
const e =
|
|
280
|
+
const e = c.artifactsStorageUpdated;
|
|
281
281
|
this.addListener(e, t);
|
|
282
282
|
}
|
|
283
283
|
artifactsEmitStorageUpdated() {
|
|
284
|
-
this.callListeners(
|
|
284
|
+
this.callListeners(c.artifactsStorageUpdated);
|
|
285
285
|
}
|
|
286
286
|
artifactsOffStorageUpdated(t) {
|
|
287
|
-
const e =
|
|
287
|
+
const e = c.artifactsStorageUpdated;
|
|
288
288
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
289
289
|
}
|
|
290
290
|
streamOnNewChunk(t) {
|
|
291
|
-
const e =
|
|
291
|
+
const e = c.streamNewChunk;
|
|
292
292
|
this.addListener(e, t);
|
|
293
293
|
}
|
|
294
294
|
streamEmitNewChunk(t) {
|
|
295
|
-
this.callListeners(
|
|
295
|
+
this.callListeners(c.streamNewChunk, t);
|
|
296
296
|
}
|
|
297
297
|
streamOffNewChunk(t) {
|
|
298
|
-
const e =
|
|
298
|
+
const e = c.streamNewChunk;
|
|
299
299
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
300
300
|
}
|
|
301
301
|
gatewayOnEndMessageData(t) {
|
|
302
|
-
const e =
|
|
302
|
+
const e = c.gatewayEndMessageData;
|
|
303
303
|
this.addListener(e, t);
|
|
304
304
|
}
|
|
305
305
|
gatewayEmitEndMessageData(t) {
|
|
306
|
-
this.callListeners(
|
|
306
|
+
this.callListeners(c.gatewayEndMessageData, t);
|
|
307
307
|
}
|
|
308
308
|
gatewayOffEndMessageData(t) {
|
|
309
|
-
const e =
|
|
309
|
+
const e = c.gatewayEndMessageData;
|
|
310
310
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
311
311
|
}
|
|
312
312
|
gatewayOnConnectionStateChange(t) {
|
|
313
|
-
const e =
|
|
313
|
+
const e = c.connectionStateChange;
|
|
314
314
|
this.addListener(e, t);
|
|
315
315
|
}
|
|
316
316
|
gatewayEmitConnectionStateChange(t) {
|
|
317
|
-
this.callListeners(
|
|
317
|
+
this.callListeners(c.connectionStateChange, t);
|
|
318
318
|
}
|
|
319
319
|
gatewayOffConnectionStateChange(t) {
|
|
320
|
-
const e =
|
|
320
|
+
const e = c.connectionStateChange;
|
|
321
321
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
322
322
|
}
|
|
323
323
|
gatewayOnToolEvent(t) {
|
|
324
|
-
const e =
|
|
324
|
+
const e = c.onToolEvent;
|
|
325
325
|
this.addListener(e, t);
|
|
326
326
|
}
|
|
327
327
|
gatewayEmitToolEvent(t, e, s) {
|
|
328
|
-
this.callListeners(
|
|
328
|
+
this.callListeners(c.onToolEvent, t, e, s);
|
|
329
329
|
}
|
|
330
330
|
gatewayOffToolEvent(t) {
|
|
331
|
-
const e =
|
|
331
|
+
const e = c.onToolEvent;
|
|
332
332
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
333
333
|
}
|
|
334
334
|
gatewayOnFirstToken(t) {
|
|
335
|
-
const e =
|
|
335
|
+
const e = c.gatewayFirstToken;
|
|
336
336
|
this.addListener(e, t);
|
|
337
337
|
}
|
|
338
338
|
gatewayEmitFirstToken(t) {
|
|
339
|
-
this.callListeners(
|
|
339
|
+
this.callListeners(c.gatewayFirstToken, t);
|
|
340
340
|
}
|
|
341
341
|
gatewayOffFirstToken(t) {
|
|
342
|
-
const e =
|
|
342
|
+
const e = c.gatewayFirstToken;
|
|
343
343
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
344
344
|
}
|
|
345
345
|
};
|
|
346
|
-
f(
|
|
347
|
-
let q =
|
|
348
|
-
const
|
|
346
|
+
f(J, "EventBusService");
|
|
347
|
+
let q = J;
|
|
348
|
+
const X = class X extends q {
|
|
349
349
|
constructor() {
|
|
350
350
|
super();
|
|
351
351
|
}
|
|
@@ -353,7 +353,7 @@ const Y = class Y extends q {
|
|
|
353
353
|
console.log("MockEventBusService.gatewayEmitConnectionStateChange");
|
|
354
354
|
}
|
|
355
355
|
gatewayEmitMessage(t, e) {
|
|
356
|
-
|
|
356
|
+
St() ? process.stdout.write(`M${t.version}, `) : console.log("MockEventBusService.gatewayEmitMessage");
|
|
357
357
|
}
|
|
358
358
|
gatewayEmitTurnComplete(t, e) {
|
|
359
359
|
console.log("MockEventBusService.gatewayEmitTurnComplete");
|
|
@@ -371,12 +371,12 @@ const Y = class Y extends q {
|
|
|
371
371
|
console.log("MockEventBusService.gatewayOffFunctionResponse", t);
|
|
372
372
|
}
|
|
373
373
|
};
|
|
374
|
-
f(
|
|
375
|
-
let
|
|
376
|
-
const
|
|
374
|
+
f(X, "MockEventBusService");
|
|
375
|
+
let ot = X;
|
|
376
|
+
const Ft = 2e3, gt = {
|
|
377
377
|
inline: "inline",
|
|
378
378
|
block: "block"
|
|
379
|
-
},
|
|
379
|
+
}, Y = class Y {
|
|
380
380
|
constructor() {
|
|
381
381
|
i(this, "parts", []);
|
|
382
382
|
i(this, "isLastGroup", !1);
|
|
@@ -396,22 +396,22 @@ const Rt = 2e3, gt = {
|
|
|
396
396
|
i(this, "type", gt.inline);
|
|
397
397
|
}
|
|
398
398
|
};
|
|
399
|
-
f(
|
|
400
|
-
let x =
|
|
399
|
+
f(Y, "InteractionPartGroup");
|
|
400
|
+
let x = Y;
|
|
401
401
|
const j = class j {
|
|
402
402
|
constructor(t, e) {
|
|
403
403
|
i(this, "interaction");
|
|
404
404
|
i(this, "eventBusService");
|
|
405
405
|
i(this, "parseTextIntoParts", /* @__PURE__ */ f((t) => {
|
|
406
406
|
if (!t || t.trim().length == 0) return [];
|
|
407
|
-
const e =
|
|
407
|
+
const e = Ot().use(kt).parse(t), s = [];
|
|
408
408
|
let a = null;
|
|
409
409
|
for (const n of e.children)
|
|
410
410
|
n.type === "code" ? (a && (s.push(a), a = null), n.lang === "htmlCanvas" && s.push(`
|
|
411
411
|
\`\`\`liveTsx
|
|
412
412
|
${n.value}
|
|
413
413
|
\`\`\`
|
|
414
|
-
`)) : (a || (a = ""), a +=
|
|
414
|
+
`)) : (a || (a = ""), a += At(n));
|
|
415
415
|
return a && s.push(a), s;
|
|
416
416
|
}, "parseTextIntoParts"));
|
|
417
417
|
this.interaction = t, this.eventBusService = e;
|
|
@@ -419,27 +419,27 @@ ${n.value}
|
|
|
419
419
|
expandSubParts(t, e) {
|
|
420
420
|
const s = this.parseTextIntoParts(t), a = [];
|
|
421
421
|
let n = 0;
|
|
422
|
-
for (const
|
|
423
|
-
const l = N.fromText(
|
|
422
|
+
for (const o of s) {
|
|
423
|
+
const l = N.fromText(o);
|
|
424
424
|
l.id = n + "_" + e, a.push(l), n++;
|
|
425
425
|
}
|
|
426
426
|
return a;
|
|
427
427
|
}
|
|
428
428
|
groupPartsByDisplayType(t, e = !0, s = !1) {
|
|
429
|
-
var l,
|
|
429
|
+
var l, r, d;
|
|
430
430
|
const a = [];
|
|
431
431
|
let n = new x();
|
|
432
432
|
for (let u = 0; u < t.length; u++) {
|
|
433
433
|
const h = t[u];
|
|
434
|
-
let p = !((((l = h.functionDetails) == null ? void 0 : l.isUi) ?? !1) || ((
|
|
434
|
+
let p = !((((l = h.functionDetails) == null ? void 0 : l.isUi) ?? !1) || ((r = h.functionDetails) == null ? void 0 : r.cancelUi) !== !0 && (((d = h.functionDetails) == null ? void 0 : d.isAskUser) ?? !1)) && h.eventType !== y.Text && h.eventType !== y.Thought && (h.eventType === y.FunctionCall || h.eventType === y.PartialFunctionCall || h.eventType === y.FunctionResponse) && u < t.length - 1;
|
|
435
435
|
if (!(!e && p && !s))
|
|
436
436
|
if (p)
|
|
437
|
-
h.eventType ==
|
|
437
|
+
h.eventType == y.Thought && (n.hasThoughts = !0), n.parts.push(h), n.isLastGroup = u === t.length - 1;
|
|
438
438
|
else {
|
|
439
439
|
n.parts.length > 0 && (a.push(n), n = new x());
|
|
440
|
-
const
|
|
441
|
-
if (
|
|
442
|
-
|
|
440
|
+
const D = h.eventType === y.Thought, T = a[a.length - 1];
|
|
441
|
+
if (D && (T != null && T.isThoughtRun)) {
|
|
442
|
+
T.parts.push(h), T.isLastGroup = u === t.length - 1;
|
|
443
443
|
continue;
|
|
444
444
|
}
|
|
445
445
|
a.push({
|
|
@@ -448,19 +448,19 @@ ${n.value}
|
|
|
448
448
|
isLastGroup: u === t.length - 1,
|
|
449
449
|
hasThoughts: !1,
|
|
450
450
|
lastWithThoughts: !1,
|
|
451
|
-
isThoughtRun:
|
|
451
|
+
isThoughtRun: D
|
|
452
452
|
});
|
|
453
453
|
}
|
|
454
454
|
}
|
|
455
455
|
n.parts.length > 0 && a.push(n);
|
|
456
|
-
const
|
|
457
|
-
return
|
|
456
|
+
const o = a.filter((u) => u.hasThoughts);
|
|
457
|
+
return o.length > 0 && (o[o.length - 1].lastWithThoughts = !0), a;
|
|
458
458
|
}
|
|
459
459
|
isFunctionCall(t) {
|
|
460
|
-
return t ==
|
|
460
|
+
return t == y.FunctionCall || t == y.PartialFunctionCall;
|
|
461
461
|
}
|
|
462
462
|
isFunctionResponse(t) {
|
|
463
|
-
return t ==
|
|
463
|
+
return t == y.FunctionResponse;
|
|
464
464
|
}
|
|
465
465
|
// Computes the next interaction from a server event. Pure with respect to
|
|
466
466
|
// `prev` — no part or array on the prior tree is mutated; modified entities
|
|
@@ -468,54 +468,54 @@ ${n.value}
|
|
|
468
468
|
// new tree as the last step, so snapshots already handed out to throttled
|
|
469
469
|
// subscribers can't diverge from the live state.
|
|
470
470
|
merge(t) {
|
|
471
|
-
var _, b,
|
|
472
|
-
const e = this.interaction, s = [], a = [], n = N.FlatParts(t == null ? void 0 : t.parts),
|
|
471
|
+
var _, b, C, O, A, tt, et, st;
|
|
472
|
+
const e = this.interaction, s = [], a = [], n = N.FlatParts(t == null ? void 0 : t.parts), o = e.parts[e.parts.length - 1] ?? null;
|
|
473
473
|
let l = !1;
|
|
474
|
-
n && (l = !
|
|
475
|
-
let
|
|
474
|
+
n && (l = !o || n.mustPush || n.mustPush === !1 && (n.eventType !== (o == null ? void 0 : o.eventType) || ((_ = n == null ? void 0 : n.functionDetails) == null ? void 0 : _.id) !== ((b = o.functionDetails) == null ? void 0 : b.id)));
|
|
475
|
+
let r = e.parts, d = e.functionMap ?? /* @__PURE__ */ new Map(), u = !e.functionMap;
|
|
476
476
|
const h = /* @__PURE__ */ f(() => {
|
|
477
477
|
u || (d = new Map(d), u = !0);
|
|
478
|
-
}, "cloneFunctionMap"),
|
|
479
|
-
|
|
478
|
+
}, "cloneFunctionMap"), v = /* @__PURE__ */ f(() => {
|
|
479
|
+
r === e.parts && (r = e.parts.slice());
|
|
480
480
|
}, "clonePartsIfShared");
|
|
481
|
-
if (!l && (
|
|
482
|
-
const g =
|
|
483
|
-
(((O = (
|
|
481
|
+
if (!l && (r == null ? void 0 : r.length) > 0 && (n != null && n.textAppendable)) {
|
|
482
|
+
const g = r[r.length - 1];
|
|
483
|
+
(((O = (C = g.thoughtDetails) == null ? void 0 : C.text) == null ? void 0 : O.length) ?? ((A = g.text) == null ? void 0 : A.length) ?? 0) > Ft && (l = !0);
|
|
484
484
|
}
|
|
485
485
|
let p = !1;
|
|
486
|
-
if ((n == null ? void 0 : n.eventType) ===
|
|
487
|
-
const g = n.functionDetails.id,
|
|
486
|
+
if ((n == null ? void 0 : n.eventType) === y.FunctionClientOutput && !!((tt = n.functionDetails) != null && tt.id) && n) {
|
|
487
|
+
const g = n.functionDetails.id, I = n.functionDetails.clientOutput, M = r.findIndex((S) => {
|
|
488
488
|
var m;
|
|
489
489
|
return ((m = S.functionDetails) == null ? void 0 : m.id) === g;
|
|
490
490
|
});
|
|
491
|
-
if (
|
|
492
|
-
const S =
|
|
491
|
+
if (M > -1) {
|
|
492
|
+
const S = r[M], m = {
|
|
493
493
|
...S,
|
|
494
494
|
functionDetails: {
|
|
495
495
|
...S.functionDetails,
|
|
496
|
-
clientOutput:
|
|
496
|
+
clientOutput: I ?? S.functionDetails.clientOutput,
|
|
497
497
|
// Sticky true-wins: this event IS the park, and a later merge must not clear it.
|
|
498
498
|
parked: n.functionDetails.parked === !0 || S.functionDetails.parked === !0
|
|
499
499
|
}
|
|
500
500
|
};
|
|
501
|
-
|
|
501
|
+
v(), r[M] = m, h(), d.set(g, m), s.push(m);
|
|
502
502
|
} else {
|
|
503
503
|
const S = {
|
|
504
504
|
...n,
|
|
505
|
-
id:
|
|
505
|
+
id: r.length + 1 + "-" + e.interactionId,
|
|
506
506
|
functionDetails: { ...n.functionDetails, silent: !0 }
|
|
507
507
|
};
|
|
508
|
-
|
|
508
|
+
v(), r = r === e.parts ? e.parts.slice() : r, r.push(S), h(), d.set(g, S);
|
|
509
509
|
}
|
|
510
510
|
} else if (l && n) {
|
|
511
|
-
const g = this.isFunctionCall(n.eventType) || this.isFunctionResponse(n.eventType),
|
|
512
|
-
g && !
|
|
513
|
-
const
|
|
514
|
-
if (
|
|
515
|
-
const S =
|
|
511
|
+
const g = this.isFunctionCall(n.eventType) || this.isFunctionResponse(n.eventType), I = g ? (et = n.functionDetails) == null ? void 0 : et.id : void 0;
|
|
512
|
+
g && !I && console.error("Got isCall or isResponse without a callId", n);
|
|
513
|
+
const M = I ? d.get(I) : void 0;
|
|
514
|
+
if (M && I && n.functionDetails) {
|
|
515
|
+
const S = r.findIndex((pt) => {
|
|
516
516
|
var nt;
|
|
517
|
-
return ((nt =
|
|
518
|
-
}), m = S > -1 ?
|
|
517
|
+
return ((nt = pt.functionDetails) == null ? void 0 : nt.id) === I;
|
|
518
|
+
}), m = S > -1 ? r[S] : M, R = {
|
|
519
519
|
...m,
|
|
520
520
|
eventType: n.eventType,
|
|
521
521
|
functionDetails: {
|
|
@@ -556,40 +556,40 @@ ${n.value}
|
|
|
556
556
|
parked: n.functionDetails.parked === !0 || m.functionDetails.parked === !0
|
|
557
557
|
}
|
|
558
558
|
};
|
|
559
|
-
h(), d.set(
|
|
559
|
+
h(), d.set(I, R), R.eventType === y.FunctionResponse && this.eventBusService.gatewayEmitFunctionResponse(R.functionDetails), s.push(R), S > -1 && (v(), r[S] = R);
|
|
560
560
|
} else {
|
|
561
|
-
if (
|
|
561
|
+
if (I && n.functionDetails && !M && (h(), d.set(I, n)), o && o.textAppendable) {
|
|
562
562
|
const m = {
|
|
563
|
-
...
|
|
563
|
+
...o,
|
|
564
564
|
ended: /* @__PURE__ */ new Date(),
|
|
565
565
|
isStillWriting: !1
|
|
566
566
|
};
|
|
567
|
-
|
|
567
|
+
v(), r[r.length - 1] = m, s.push(m);
|
|
568
568
|
}
|
|
569
569
|
const S = {
|
|
570
570
|
...n,
|
|
571
|
-
id:
|
|
571
|
+
id: r.length + 1 + "-" + e.interactionId,
|
|
572
572
|
isStillWriting: n.textAppendable,
|
|
573
573
|
partial: t.partial
|
|
574
574
|
};
|
|
575
|
-
(st = S.functionDetails) != null && st.silent || s.push(S),
|
|
575
|
+
(st = S.functionDetails) != null && st.silent || s.push(S), r = [...r, S], p = !0;
|
|
576
576
|
}
|
|
577
577
|
}
|
|
578
|
-
let
|
|
579
|
-
if (
|
|
578
|
+
let T = r[r.length - 1] ?? null;
|
|
579
|
+
if (T && n && n.textAppendable) {
|
|
580
580
|
const g = {
|
|
581
|
-
...
|
|
581
|
+
...T,
|
|
582
582
|
partial: t.partial,
|
|
583
|
-
textDetails:
|
|
583
|
+
textDetails: T.textDetails ? { ...T.textDetails } : { version: 0 }
|
|
584
584
|
};
|
|
585
|
-
let
|
|
585
|
+
let I = !1;
|
|
586
586
|
if (t.partial) {
|
|
587
587
|
try {
|
|
588
|
-
g.textDetails.version++, p || (g.text = (
|
|
589
|
-
} catch (
|
|
590
|
-
console.error("Error here",
|
|
588
|
+
g.textDetails.version++, p || (g.text = (T.text ?? "") + (n.text ?? ""));
|
|
589
|
+
} catch (M) {
|
|
590
|
+
console.error("Error here", M.toString());
|
|
591
591
|
}
|
|
592
|
-
g.textLastChunk = n.text ?? "", g.isStillWriting = !0,
|
|
592
|
+
g.textLastChunk = n.text ?? "", g.isStillWriting = !0, I = !0, !p && n.thoughtDetails && g.thoughtDetails && (n.thoughtDetails.text.length >= 50 || n.thoughtDetails.text.length < 50 && n.thoughtDetails.text !== g.thoughtDetails.text) && (g.thoughtDetails = {
|
|
593
593
|
...g.thoughtDetails,
|
|
594
594
|
text: g.thoughtDetails.text + n.thoughtDetails.text
|
|
595
595
|
}, g.thoughtLastChunk = n.thoughtDetails.text);
|
|
@@ -597,24 +597,24 @@ ${n.value}
|
|
|
597
597
|
g.isStillWriting = !1, g.text = n.text ?? "", g.textDetails.version++, n.thoughtDetails && (g.thoughtDetails = {
|
|
598
598
|
...n.thoughtDetails,
|
|
599
599
|
text: n.thoughtDetails.text.trim()
|
|
600
|
-
}),
|
|
601
|
-
|
|
600
|
+
}), I = !l;
|
|
601
|
+
v(), r[r.length - 1] = g, T = g, I && s.push(g);
|
|
602
602
|
}
|
|
603
|
-
let
|
|
603
|
+
let E = e.artifactData ?? [];
|
|
604
604
|
if (t.llmArtifacts && t.llmArtifacts.length > 0) {
|
|
605
605
|
let g = !1;
|
|
606
|
-
for (const
|
|
607
|
-
const
|
|
608
|
-
g || (
|
|
609
|
-
const S =
|
|
610
|
-
S === -1 ?
|
|
606
|
+
for (const I of t.llmArtifacts) {
|
|
607
|
+
const M = I.toArtifact();
|
|
608
|
+
g || (E = E.slice(), g = !0);
|
|
609
|
+
const S = E.findIndex((m) => m.id === M.id);
|
|
610
|
+
S === -1 ? E.push(M) : E[S] = M;
|
|
611
611
|
}
|
|
612
612
|
}
|
|
613
613
|
const k = {
|
|
614
614
|
...e,
|
|
615
615
|
version: e.version + 1,
|
|
616
|
-
parts:
|
|
617
|
-
artifactData:
|
|
616
|
+
parts: r,
|
|
617
|
+
artifactData: E,
|
|
618
618
|
functionMap: d,
|
|
619
619
|
turn_complete: t.turn_complete,
|
|
620
620
|
partial: t.partial,
|
|
@@ -633,9 +633,9 @@ ${n.value}
|
|
|
633
633
|
};
|
|
634
634
|
f(j, "InteractionService");
|
|
635
635
|
let B = j;
|
|
636
|
-
const
|
|
637
|
-
constructor(t, e, s, a, n,
|
|
638
|
-
i(this, "base_production_url",
|
|
636
|
+
const Lt = 1200 * 1e3, P = class P {
|
|
637
|
+
constructor(t, e, s, a, n, o, l, r, d, u = yt.Interactive) {
|
|
638
|
+
i(this, "base_production_url", wt() ?? "https://agent.tripapi.com.br");
|
|
639
639
|
i(this, "base_url_local", "http://localagent:8000");
|
|
640
640
|
i(this, "base_url");
|
|
641
641
|
i(this, "isLocal", !1);
|
|
@@ -710,7 +710,7 @@ const Ft = 1200 * 1e3, P = class P {
|
|
|
710
710
|
i(this, "subAgentInteractionServices", /* @__PURE__ */ new Map());
|
|
711
711
|
i(this, "lastThorttledTimeout", null);
|
|
712
712
|
i(this, "lastPingStatus", !1);
|
|
713
|
-
this.user = t, this.config = n, this.rawJwt = t.access_token, this.base_url = a, this.eventBusService = e, this.sessionId = d, this.runMode = u, this.artifactService = s, this.sessionState =
|
|
713
|
+
this.user = t, this.config = n, this.rawJwt = t.access_token, this.base_url = a, this.eventBusService = e, this.sessionId = d, this.runMode = u, this.artifactService = s, this.sessionState = o.getState(), this.notificationPort = l, this.storageService = r, o.subscribe((h, v) => {
|
|
714
714
|
this.sessionState = h;
|
|
715
715
|
});
|
|
716
716
|
}
|
|
@@ -891,9 +891,9 @@ const Ft = 1200 * 1e3, P = class P {
|
|
|
891
891
|
handleSubAgentEvent(t) {
|
|
892
892
|
const e = t.subAgentId, { service: s } = this.getOrCreateSubAgentInteraction(e, t.interactionId, t.subAgentName);
|
|
893
893
|
if (t.parts && t.parts.length > 0) {
|
|
894
|
-
for (const
|
|
895
|
-
if (
|
|
896
|
-
this.localEmitToolEvent({ ...
|
|
894
|
+
for (const o of t.parts)
|
|
895
|
+
if (o.toolDetails) {
|
|
896
|
+
this.localEmitToolEvent({ ...o.toolDetails, subAgentId: e });
|
|
897
897
|
continue;
|
|
898
898
|
}
|
|
899
899
|
}
|
|
@@ -918,8 +918,8 @@ const Ft = 1200 * 1e3, P = class P {
|
|
|
918
918
|
if (e.serverError && console.error("Stream error: ", e.serverError), e.endMessageData && this.eventBusService.gatewayEmitEndMessageData(e.endMessageData), e) {
|
|
919
919
|
if (e.llmArtifacts && e.llmArtifacts.length > 0)
|
|
920
920
|
for (const n of e.llmArtifacts) {
|
|
921
|
-
const
|
|
922
|
-
this.artifactService.addToCache(
|
|
921
|
+
const o = n.toArtifact();
|
|
922
|
+
this.artifactService.addToCache(o), this.eventBusService.artifactEmitGenerated(o);
|
|
923
923
|
}
|
|
924
924
|
if (e.parts && e.parts.length > 0) {
|
|
925
925
|
for (const n of e.parts)
|
|
@@ -939,14 +939,14 @@ const Ft = 1200 * 1e3, P = class P {
|
|
|
939
939
|
this.localEmitMessage(s.updatedInteraction, s), e.turn_complete && this.turnComplete(e.interactionId, s.updatedInteraction, e.author, e.subAgentId), e.asyncFinalResponse && (e.turn_complete = !0, s.updatedInteraction.turn_complete == !0, this.finalResponse(e.interactionId, s.updatedInteraction, e.author, e.subAgentId));
|
|
940
940
|
const a = e.artifactsDelta;
|
|
941
941
|
a && a.forEach((n) => {
|
|
942
|
-
const
|
|
942
|
+
const o = s.updatedInteraction.artifactData.filter((r) => r.id == n);
|
|
943
943
|
let l = null;
|
|
944
|
-
|
|
944
|
+
o && o.length > 0 && (l = o[0], l.loadingPromise = this.asyncLoadArtifact(n).then((r) => (r === null ? console.error("Error trying to load artifact id:", l == null ? void 0 : l.id, "Artifact is null") : this.eventBusService.artifactEmitGenerated(r), r)).catch((r) => (console.error("Error trying to load artifact id:", l == null ? void 0 : l.id, r.toString()), null)));
|
|
945
945
|
});
|
|
946
946
|
}
|
|
947
947
|
} catch (e) {
|
|
948
948
|
if (this.getCurrentInteractionId()) {
|
|
949
|
-
const s =
|
|
949
|
+
const s = ft.createErrorEvent("OnMessage error: " + e.toString(), this.getCurrentInteractionId() ?? "Empty Current"), a = this.updateMap(s);
|
|
950
950
|
if (console.error("Error event: ", JSON.stringify(s, void 0, 4)), !a) {
|
|
951
951
|
console.error("Error event, could not update interaction: ", JSON.stringify(s, void 0, 4));
|
|
952
952
|
return;
|
|
@@ -977,8 +977,8 @@ const Ft = 1200 * 1e3, P = class P {
|
|
|
977
977
|
localEmitMessage(t, e) {
|
|
978
978
|
const s = (/* @__PURE__ */ new Date()).getTime(), a = s - this.lastCurrentMessageUpdate;
|
|
979
979
|
t.partial === !1 || a >= P.CURRENT_MSG_THROTTLE_MS ? (this.lastThorttledTimeout && (clearTimeout(this.lastThorttledTimeout), this.lastThorttledTimeout = null), this.doEmitMessage(t, s, e), this.pendingCurrentMessage = null) : (this.pendingCurrentMessage = t, this.lastThorttledTimeout && clearTimeout(this.lastThorttledTimeout), this.lastThorttledTimeout = setTimeout(() => {
|
|
980
|
-
var
|
|
981
|
-
this.pendingCurrentMessage && (((
|
|
980
|
+
var o, l;
|
|
981
|
+
this.pendingCurrentMessage && (((o = this.pendingCurrentMessage) == null ? void 0 : o.version) ?? 0) > (((l = this.sessionState.currentMessage) == null ? void 0 : l.version) ?? 0) && (this.doEmitMessage(this.pendingCurrentMessage, s, e), this.lastThorttledTimeout = null);
|
|
982
982
|
}, P.CURRENT_MSG_THROTTLE_MS * 2));
|
|
983
983
|
}
|
|
984
984
|
localOpen(t, e) {
|
|
@@ -1007,16 +1007,16 @@ const Ft = 1200 * 1e3, P = class P {
|
|
|
1007
1007
|
}), this.sessionState.setTurnOpen(!1);
|
|
1008
1008
|
}
|
|
1009
1009
|
async handlePing() {
|
|
1010
|
-
return Date.now() - this.lastPing.getTime() >
|
|
1010
|
+
return Date.now() - this.lastPing.getTime() > Lt ? await this.ping() ? (this.lastPing = /* @__PURE__ */ new Date(), this.lastPingStatus = !0, !0) : (this.lastPingStatus = !1, !1) : (this.lastPingStatus = !0, !0);
|
|
1011
1011
|
}
|
|
1012
1012
|
async sendMessage(t, e) {
|
|
1013
1013
|
let s = this.getInteractions().length, a = N.createWaiting(!0, !0, "Overall", /* @__PURE__ */ new Date());
|
|
1014
1014
|
this.sendStatusMessage(t.data, [a], s.toString() + "1");
|
|
1015
1015
|
try {
|
|
1016
|
-
const { promptAsString: n, json:
|
|
1017
|
-
this.sessionState.onRenderPrompt && (t.data =
|
|
1018
|
-
const l = await this.sendMessageInternal(t, e),
|
|
1019
|
-
this.storageService.storePrompt(
|
|
1016
|
+
const { promptAsString: n, json: o } = this.sessionState.onRenderPrompt ? this.sessionState.onRenderPrompt(t.data) : { promptAsString: t.data, json: void 0 };
|
|
1017
|
+
this.sessionState.onRenderPrompt && (t.data = o, t.friendlyMessage = n);
|
|
1018
|
+
const l = await this.sendMessageInternal(t, e), r = _t.createPrompt(n ?? "", (o == null ? void 0 : o.toString()) ?? {});
|
|
1019
|
+
this.storageService.storePrompt(r);
|
|
1020
1020
|
const d = N.fromText("Planejando próximos passos");
|
|
1021
1021
|
return this.sendStatusMessage(t.data, [a, d], s.toString() + "1"), l != null && l.success ? this.eventBusService.ChatEmitMessageSent(t.data, l.interaction) : this.eventBusService.ChatEmitMessageError((l == null ? void 0 : l.error) ?? ""), l;
|
|
1022
1022
|
} catch (n) {
|
|
@@ -1047,9 +1047,9 @@ const Ft = 1200 * 1e3, P = class P {
|
|
|
1047
1047
|
t.partial = !0, t.turn_complete = !1, t.asyncFinalResponse = !1, t.interactionId = t.interactionId, this.eventBusService.gatewayEmitTurnOpen(t.interactionId), this.Message(t);
|
|
1048
1048
|
}
|
|
1049
1049
|
sendStatusMessage(t, e, s) {
|
|
1050
|
-
var n,
|
|
1050
|
+
var n, o;
|
|
1051
1051
|
let a;
|
|
1052
|
-
((
|
|
1052
|
+
((o = (n = this.currentIS) == null ? void 0 : n.interaction) == null ? void 0 : o.turn_complete) === !1 ? (a = Nt.cloneDeep(this.currentIS.interaction), a.parts.push(...e)) : a = {
|
|
1053
1053
|
interactionId: "tmp" + s,
|
|
1054
1054
|
created: /* @__PURE__ */ new Date(),
|
|
1055
1055
|
partial: !0,
|
|
@@ -1072,16 +1072,47 @@ const Ft = 1200 * 1e3, P = class P {
|
|
|
1072
1072
|
}
|
|
1073
1073
|
}
|
|
1074
1074
|
getNewInteractionId() {
|
|
1075
|
-
const e =
|
|
1075
|
+
const e = Pt(/* @__PURE__ */ new Date(), "MMM_dd_HH_mm_ss");
|
|
1076
1076
|
return `${this.msg_order}_${e}`;
|
|
1077
1077
|
}
|
|
1078
1078
|
};
|
|
1079
1079
|
f(P, "AgentGatewayService"), i(P, "SUSPENSION_MSG", "SUSPEND"), i(P, "CURRENT_MSG_THROTTLE_MS", 150);
|
|
1080
1080
|
let G = P;
|
|
1081
|
-
const
|
|
1081
|
+
const Ut = 0.02;
|
|
1082
|
+
function xt(w, t) {
|
|
1083
|
+
if (!t) return null;
|
|
1084
|
+
const e = (t.interactionsCompressed ?? 0) > 0 || (t.compressionRatio ?? 0) > 0;
|
|
1085
|
+
if (!w)
|
|
1086
|
+
return e ? rt(t, t.size, t.size) : null;
|
|
1087
|
+
const s = w.size - t.size, a = t.maxSize || w.maxSize || 0, n = a > 0 ? s / a >= Ut : w.size > 0 && s / w.size >= 0.1;
|
|
1088
|
+
return !e && !n ? null : rt(t, w.size, t.size, w.ratio);
|
|
1089
|
+
}
|
|
1090
|
+
f(xt, "detectCompaction");
|
|
1091
|
+
function rt(w, t, e, s) {
|
|
1092
|
+
return {
|
|
1093
|
+
at: Date.now(),
|
|
1094
|
+
// Where the bar stood when it happened — the marker's position. The ratio
|
|
1095
|
+
// BEFORE the pass is the meaningful one: it is the fill the compaction
|
|
1096
|
+
// reacted to, and it is also the only one that does not move afterwards.
|
|
1097
|
+
ratio: s ?? w.ratio,
|
|
1098
|
+
sizeBefore: t,
|
|
1099
|
+
sizeAfter: e,
|
|
1100
|
+
interactionsCompressed: w.interactionsCompressed
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
f(rt, "entry");
|
|
1104
|
+
const H = 4001, Bt = 4002, ct = 4, Wt = 3, $t = 20, qt = 500, Gt = 3e4, Ht = 2, zt = 0.2, lt = 2, Q = class Q {
|
|
1082
1105
|
constructor(t = "ws://localhost:8000", e) {
|
|
1083
1106
|
i(this, "ws", null);
|
|
1084
1107
|
i(this, "stats");
|
|
1108
|
+
/**
|
|
1109
|
+
* Compaction history for the whole CONNECTION, and the previous size reading it
|
|
1110
|
+
* is derived from. Deliberately not inside `stats`: those are rebuilt on every
|
|
1111
|
+
* interaction (see emitFirstToken), and a session's compaction history outlives
|
|
1112
|
+
* any one turn — it is the thing the usage panel plots.
|
|
1113
|
+
*/
|
|
1114
|
+
i(this, "sessionCompactions", []);
|
|
1115
|
+
i(this, "previousSessionInformation");
|
|
1085
1116
|
i(this, "baseUrl");
|
|
1086
1117
|
/**
|
|
1087
1118
|
* Optional callback that returns the current JWT. We re-evaluate it on every connect/reconnect
|
|
@@ -1168,7 +1199,7 @@ const H = 4001, Lt = 4002, ot = 4, Ut = 3, xt = 500, Bt = 3e4, Wt = 2, $t = 0.2,
|
|
|
1168
1199
|
* Cleared by `disconnect()`.
|
|
1169
1200
|
*/
|
|
1170
1201
|
i(this, "hasEverReceivedPacket", !1);
|
|
1171
|
-
this.baseUrl = t, this.getToken = e, this.pingPongStack = [], this.events = [], this.firstTokenInteractions = /* @__PURE__ */ new Set(), this.streamingResponseSerializer =
|
|
1202
|
+
this.baseUrl = t, this.getToken = e, this.pingPongStack = [], this.events = [], this.firstTokenInteractions = /* @__PURE__ */ new Set(), this.streamingResponseSerializer = Ct(), console.log("SOCKET INSTACE", Tt()), this.stats = {
|
|
1172
1203
|
eventCount: 0,
|
|
1173
1204
|
unknonwCount: 0,
|
|
1174
1205
|
buffer: [],
|
|
@@ -1176,7 +1207,8 @@ const H = 4001, Lt = 4002, ot = 4, Ut = 3, xt = 500, Bt = 3e4, Wt = 2, $t = 0.2,
|
|
|
1176
1207
|
elapsed: 0,
|
|
1177
1208
|
unparsedCount: 0,
|
|
1178
1209
|
totalTransfered: 0,
|
|
1179
|
-
tokensPerSecond: 0
|
|
1210
|
+
tokensPerSecond: 0,
|
|
1211
|
+
sessionCompactions: this.sessionCompactions
|
|
1180
1212
|
}, this.lastActivity = (/* @__PURE__ */ new Date()).getTime();
|
|
1181
1213
|
}
|
|
1182
1214
|
/**
|
|
@@ -1195,9 +1227,9 @@ const H = 4001, Lt = 4002, ot = 4, Ut = 3, xt = 500, Bt = 3e4, Wt = 2, $t = 0.2,
|
|
|
1195
1227
|
this.intentionalDisconnect = !1;
|
|
1196
1228
|
const n = this._internalReconnect || (e == null ? void 0 : e.resume) === !0;
|
|
1197
1229
|
n || (this.cancelPendingReconnect(), this.isReconnecting = !1, this.reconnectAttempts = 0, this.lastSeq = -1), this._internalReconnect = !1;
|
|
1198
|
-
const
|
|
1199
|
-
|
|
1200
|
-
const
|
|
1230
|
+
const o = (b = this.getToken) == null ? void 0 : b.call(this), l = [];
|
|
1231
|
+
o && l.push(`access_token=${encodeURIComponent(o)}`), t && this.lastSeq >= 0 && l.push(`lastSeq=${this.lastSeq}`);
|
|
1232
|
+
const r = l.length > 0 ? `?${l.join("&")}` : "", d = this.baseUrl.replace(/^http:\/\//, "ws://").replace(/^https:\/\//, "wss://"), u = `${d}/ws/connect/${t ?? ""}${r}`, h = `${d}/ws/connect/${t ?? ""}` + (n && t && this.lastSeq >= 0 ? ` (resume lastSeq=${this.lastSeq})` : "");
|
|
1201
1233
|
if (console.log("Connecting to ", h), this.ws) {
|
|
1202
1234
|
this.ws.onopen = null, this.ws.onmessage = null, this.ws.onerror = null, this.ws.onclose = null;
|
|
1203
1235
|
try {
|
|
@@ -1207,58 +1239,58 @@ const H = 4001, Lt = 4002, ot = 4, Ut = 3, xt = 500, Bt = 3e4, Wt = 2, $t = 0.2,
|
|
|
1207
1239
|
this.ws = null;
|
|
1208
1240
|
}
|
|
1209
1241
|
this.ws = new WebSocket(u), console.log("[WebSocket] Connecting to:", `${d}/ws/connect/${t ?? ""}`);
|
|
1210
|
-
let
|
|
1242
|
+
let v = !1;
|
|
1211
1243
|
this.ws.onopen = () => {
|
|
1212
1244
|
console.log("[WebSocket] Connected");
|
|
1213
|
-
const
|
|
1214
|
-
this.isReconnecting = !1, this.reconnectAttempts = 0, this.pingPongStack.push((/* @__PURE__ */ new Date()).getTime()), this.ping(), this.monitor(), this.onOpen && this.onOpen(),
|
|
1215
|
-
}, this.ws.onmessage = (
|
|
1245
|
+
const C = this.isReconnecting;
|
|
1246
|
+
this.isReconnecting = !1, this.reconnectAttempts = 0, this.pingPongStack.push((/* @__PURE__ */ new Date()).getTime()), this.ping(), this.monitor(), this.onOpen && this.onOpen(), C && this.onReconnected && this.onReconnected(t ?? this.lastKnownSessionId ?? ""), this.flushPendingAnswers(t ?? this.lastKnownSessionId);
|
|
1247
|
+
}, this.ws.onmessage = (C) => {
|
|
1216
1248
|
try {
|
|
1217
1249
|
this.lastActivity = (/* @__PURE__ */ new Date()).getTime();
|
|
1218
|
-
const O = this.streamingResponseSerializer.parse(
|
|
1250
|
+
const O = this.streamingResponseSerializer.parse(C.data);
|
|
1219
1251
|
if (!O)
|
|
1220
1252
|
throw "Error parsing event JSON";
|
|
1221
|
-
const A = this.handleMessage(O,
|
|
1222
|
-
!
|
|
1253
|
+
const A = this.handleMessage(O, C.data);
|
|
1254
|
+
!v && (A != null && A.timestamp) && (v = !0, this.hasEverReceivedPacket = !0);
|
|
1223
1255
|
} catch (O) {
|
|
1224
1256
|
console.error("[WebSocket] Error parsing message:", O);
|
|
1225
1257
|
}
|
|
1226
|
-
}, this.ws.onerror = (
|
|
1227
|
-
console.error("[WebSocket] Error:",
|
|
1228
|
-
}, this.ws.onclose = (
|
|
1229
|
-
console.log("[WebSocket] Closed:",
|
|
1258
|
+
}, this.ws.onerror = (C) => {
|
|
1259
|
+
console.error("[WebSocket] Error:", C), this.onError && this.onError("WebSocket error");
|
|
1260
|
+
}, this.ws.onclose = (C) => {
|
|
1261
|
+
console.log("[WebSocket] Closed:", C.code, C.reason), this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingPongStack = [];
|
|
1230
1262
|
const O = this.sessionId ?? this.lastKnownSessionId;
|
|
1231
|
-
if (this.sessionId = void 0, (
|
|
1232
|
-
this.scheduleReconnect(O,
|
|
1263
|
+
if (this.sessionId = void 0, (v || this.hasEverReceivedPacket) && this.shouldAttemptReconnect(C.code)) {
|
|
1264
|
+
this.scheduleReconnect(O, C.code, C.reason);
|
|
1233
1265
|
return;
|
|
1234
1266
|
}
|
|
1235
|
-
this.isReconnecting = !1, this.reconnectAttempts = 0, this.onClose && this.onClose(
|
|
1267
|
+
this.isReconnecting = !1, this.reconnectAttempts = 0, this.onClose && this.onClose(C.code, C.reason);
|
|
1236
1268
|
};
|
|
1237
|
-
const p = 200,
|
|
1269
|
+
const p = 200, D = 3e4, T = 8e3, E = this.ws;
|
|
1238
1270
|
this.sessionId = void 0;
|
|
1239
1271
|
let k = 0, _ = 0;
|
|
1240
1272
|
for (; !this.sessionId; ) {
|
|
1241
|
-
if (this.ws !==
|
|
1273
|
+
if (this.ws !== E) {
|
|
1242
1274
|
a("Connection attempt superseded by a newer connect()");
|
|
1243
1275
|
return;
|
|
1244
1276
|
}
|
|
1245
|
-
if (
|
|
1277
|
+
if (E.readyState === WebSocket.CLOSING || E.readyState === WebSocket.CLOSED) {
|
|
1246
1278
|
a("Connection closed before a session id was received");
|
|
1247
1279
|
return;
|
|
1248
1280
|
}
|
|
1249
|
-
if (
|
|
1281
|
+
if (E.readyState === WebSocket.CONNECTING && k >= D) {
|
|
1250
1282
|
try {
|
|
1251
|
-
|
|
1283
|
+
E.close();
|
|
1252
1284
|
} catch {
|
|
1253
1285
|
}
|
|
1254
|
-
a(`Server did not accept the connection within ${
|
|
1286
|
+
a(`Server did not accept the connection within ${D / 1e3}s`);
|
|
1255
1287
|
return;
|
|
1256
1288
|
}
|
|
1257
|
-
if (
|
|
1258
|
-
a(`Connected but no session id arrived within ${
|
|
1289
|
+
if (E.readyState === WebSocket.OPEN && _ >= T) {
|
|
1290
|
+
a(`Connected but no session id arrived within ${T / 1e3}s`);
|
|
1259
1291
|
return;
|
|
1260
1292
|
}
|
|
1261
|
-
k % 2e3 === 0 && console.log("Aguardando session Id"), await this.sleep(p), k += p,
|
|
1293
|
+
k % 2e3 === 0 && console.log("Aguardando session Id"), await this.sleep(p), k += p, E.readyState === WebSocket.OPEN && (_ += p);
|
|
1262
1294
|
}
|
|
1263
1295
|
console.log("SUCCESS - GOT SESSION ID", this.sessionId), this.lastKnownSessionId = this.sessionId, s(this.sessionId);
|
|
1264
1296
|
});
|
|
@@ -1273,19 +1305,19 @@ const H = 4001, Lt = 4002, ot = 4, Ut = 3, xt = 500, Bt = 3e4, Wt = 2, $t = 0.2,
|
|
|
1273
1305
|
* - 4000-4099 reserved for app-level fatal codes from the server
|
|
1274
1306
|
*/
|
|
1275
1307
|
shouldAttemptReconnect(t) {
|
|
1276
|
-
return !(this.intentionalDisconnect || t === H || t ===
|
|
1308
|
+
return !(this.intentionalDisconnect || t === H || t === Bt || t === 1e3 || t === 1008);
|
|
1277
1309
|
}
|
|
1278
1310
|
cancelPendingReconnect() {
|
|
1279
1311
|
this.reconnectTimer && (clearTimeout(this.reconnectTimer), this.reconnectTimer = null);
|
|
1280
1312
|
}
|
|
1281
1313
|
computeBackoffDelay() {
|
|
1282
|
-
const t =
|
|
1314
|
+
const t = qt * Math.pow(Ht, this.reconnectAttempts), e = Math.min(t, Gt), s = e * zt * (Math.random() * 2 - 1);
|
|
1283
1315
|
return Math.max(0, Math.round(e + s));
|
|
1284
1316
|
}
|
|
1285
1317
|
scheduleReconnect(t, e, s) {
|
|
1286
|
-
var n,
|
|
1318
|
+
var n, o;
|
|
1287
1319
|
if (this.intentionalDisconnect) return;
|
|
1288
|
-
if (this.reconnectAttempts >=
|
|
1320
|
+
if (this.reconnectAttempts >= lt) {
|
|
1289
1321
|
console.warn(
|
|
1290
1322
|
`[WebSocket] Reconnect exhausted after ${this.reconnectAttempts} attempts (last code=${e}, reason="${s}"). Handing off to outer state manager.`
|
|
1291
1323
|
), this.isReconnecting = !1, this.reconnectAttempts = 0, this.cancelPendingReconnect(), (n = this.onClose) == null || n.call(this, e, s);
|
|
@@ -1294,8 +1326,8 @@ const H = 4001, Lt = 4002, ot = 4, Ut = 3, xt = 500, Bt = 3e4, Wt = 2, $t = 0.2,
|
|
|
1294
1326
|
this.isReconnecting = !0, this.reconnectAttempts += 1;
|
|
1295
1327
|
const a = this.computeBackoffDelay();
|
|
1296
1328
|
console.warn(
|
|
1297
|
-
`[WebSocket] Unexpected close (code=${e}, reason="${s}"). Reconnect attempt #${this.reconnectAttempts}/${
|
|
1298
|
-
), (
|
|
1329
|
+
`[WebSocket] Unexpected close (code=${e}, reason="${s}"). Reconnect attempt #${this.reconnectAttempts}/${lt} in ${a}ms (resume sessionId=${t ?? "none"}).`
|
|
1330
|
+
), (o = this.onReconnecting) == null || o.call(this, this.reconnectAttempts, a), this.cancelPendingReconnect(), this.reconnectTimer = setTimeout(async () => {
|
|
1299
1331
|
if (this.reconnectTimer = null, !this.intentionalDisconnect)
|
|
1300
1332
|
try {
|
|
1301
1333
|
this.ws && (this.ws.onopen = null, this.ws.onmessage = null, this.ws.onerror = null, this.ws.onclose = null, this.ws = null), this._internalReconnect = !0, await this.connect(t);
|
|
@@ -1311,7 +1343,7 @@ const H = 4001, Lt = 4002, ot = 4, Ut = 3, xt = 500, Bt = 3e4, Wt = 2, $t = 0.2,
|
|
|
1311
1343
|
* Handle incoming messages from server
|
|
1312
1344
|
*/
|
|
1313
1345
|
handleMessage(t, e) {
|
|
1314
|
-
var l,
|
|
1346
|
+
var l, r, d;
|
|
1315
1347
|
switch (typeof t.seq == "number" && t.seq > this.lastSeq && (this.lastSeq = t.seq), t.type) {
|
|
1316
1348
|
case "Pong":
|
|
1317
1349
|
if (this.sessionId = t.sessionId, this.lastKnownSessionId = t.sessionId ?? this.lastKnownSessionId, !t.sessionId) {
|
|
@@ -1336,27 +1368,27 @@ const H = 4001, Lt = 4002, ot = 4, Ut = 3, xt = 500, Bt = 3e4, Wt = 2, $t = 0.2,
|
|
|
1336
1368
|
if (t.partialEvent) {
|
|
1337
1369
|
const u = t.partialEvent;
|
|
1338
1370
|
this.emitFirstToken(u == null ? void 0 : u.iteractionId);
|
|
1339
|
-
const h = new
|
|
1371
|
+
const h = new It();
|
|
1340
1372
|
if (h.author = "main", h.streamingParts = t.partialEvent.streamingParts, t.partialEvent.partialEventType ? h.eventType = t.partialEvent.partialEventType : h.eventType = u.functionName ? {
|
|
1341
1373
|
fullName: L.StreamingFunctionCallUpdateContent,
|
|
1342
|
-
type:
|
|
1374
|
+
type: y.PartialFunctionCall
|
|
1343
1375
|
} : u.partialReasoning ? {
|
|
1344
1376
|
fullName: L.StreamingReasoningContent,
|
|
1345
|
-
type:
|
|
1377
|
+
type: y.Thought
|
|
1346
1378
|
} : {
|
|
1347
1379
|
fullName: L.StreamingTextContent,
|
|
1348
|
-
type:
|
|
1349
|
-
}, h.interactionId = (u == null ? void 0 : u.iteractionId) ?? "", h.mimeType = "text/plain", h.partial = !0, h.eventType.type ==
|
|
1350
|
-
var s = new
|
|
1380
|
+
type: y.Text
|
|
1381
|
+
}, h.interactionId = (u == null ? void 0 : u.iteractionId) ?? "", h.mimeType = "text/plain", h.partial = !0, h.eventType.type == y.PartialFunctionCall) {
|
|
1382
|
+
var s = new vt();
|
|
1351
1383
|
s.choiceIndex = 0, s.callId = u.functionCallId, s.arguments = u.partialText, s.name = u.functionName, h.content = {
|
|
1352
1384
|
items: [s],
|
|
1353
1385
|
role: {
|
|
1354
1386
|
label: "Assistant"
|
|
1355
1387
|
}
|
|
1356
1388
|
};
|
|
1357
|
-
} else if (h.eventType.type ==
|
|
1389
|
+
} else if (h.eventType.type == y.Text)
|
|
1358
1390
|
if (h.eventType.fullName == L.StreamingTextContent) {
|
|
1359
|
-
var a = new
|
|
1391
|
+
var a = new Et();
|
|
1360
1392
|
a.text = u.partialText, h.content = {
|
|
1361
1393
|
items: [a],
|
|
1362
1394
|
role: {
|
|
@@ -1364,7 +1396,7 @@ const H = 4001, Lt = 4002, ot = 4, Ut = 3, xt = 500, Bt = 3e4, Wt = 2, $t = 0.2,
|
|
|
1364
1396
|
}
|
|
1365
1397
|
};
|
|
1366
1398
|
} else {
|
|
1367
|
-
var n = new
|
|
1399
|
+
var n = new Mt();
|
|
1368
1400
|
n.text = u.partialText, h.content = {
|
|
1369
1401
|
items: [n],
|
|
1370
1402
|
role: {
|
|
@@ -1372,10 +1404,10 @@ const H = 4001, Lt = 4002, ot = 4, Ut = 3, xt = 500, Bt = 3e4, Wt = 2, $t = 0.2,
|
|
|
1372
1404
|
}
|
|
1373
1405
|
};
|
|
1374
1406
|
}
|
|
1375
|
-
else if (h.eventType.type ==
|
|
1376
|
-
var
|
|
1377
|
-
|
|
1378
|
-
items: [
|
|
1407
|
+
else if (h.eventType.type == y.Thought) {
|
|
1408
|
+
var o = new Dt();
|
|
1409
|
+
o.text = u.partialReasoning, h.content = {
|
|
1410
|
+
items: [o],
|
|
1379
1411
|
role: {
|
|
1380
1412
|
label: "Assistant"
|
|
1381
1413
|
}
|
|
@@ -1386,7 +1418,7 @@ const H = 4001, Lt = 4002, ot = 4, Ut = 3, xt = 500, Bt = 3e4, Wt = 2, $t = 0.2,
|
|
|
1386
1418
|
label: "Assistant"
|
|
1387
1419
|
}, h.timestamp = (u == null ? void 0 : u.timeStamp) ?? (/* @__PURE__ */ new Date()).getTime(), h.turnComplete = !1, t.event = h, t.partialEvent = void 0;
|
|
1388
1420
|
}
|
|
1389
|
-
return t.event ? (t.subAgentId && (t.event.subAgentId = t.subAgentId, t.event.subAgentName = t.subAgentName), ((((
|
|
1421
|
+
return t.event ? (t.subAgentId && (t.event.subAgentId = t.subAgentId, t.event.subAgentName = t.subAgentName), ((((r = (l = t.event.content) == null ? void 0 : l.items) == null ? void 0 : r.length) ?? 0) > 0 || (((d = t.event.streamingParts) == null ? void 0 : d.length) ?? 0) > 0) && this.emitFirstToken(t.event.interactionId), this.handleEvent(t.event, e), t.event) : null;
|
|
1390
1422
|
}
|
|
1391
1423
|
emitFirstToken(t) {
|
|
1392
1424
|
var e;
|
|
@@ -1398,7 +1430,8 @@ const H = 4001, Lt = 4002, ot = 4, Ut = 3, xt = 500, Bt = 3e4, Wt = 2, $t = 0.2,
|
|
|
1398
1430
|
elapsed: 0,
|
|
1399
1431
|
unparsedCount: 0,
|
|
1400
1432
|
totalTransfered: 0,
|
|
1401
|
-
tokensPerSecond: 0
|
|
1433
|
+
tokensPerSecond: 0,
|
|
1434
|
+
sessionCompactions: this.sessionCompactions
|
|
1402
1435
|
}, this.firstTokenInteractions.add(t), (e = this.onFirstToken) == null || e.call(this, t));
|
|
1403
1436
|
}
|
|
1404
1437
|
/**
|
|
@@ -1560,13 +1593,17 @@ const H = 4001, Lt = 4002, ot = 4, Ut = 3, xt = 500, Bt = 3e4, Wt = 2, $t = 0.2,
|
|
|
1560
1593
|
async handleEvent(t, e) {
|
|
1561
1594
|
var s;
|
|
1562
1595
|
try {
|
|
1563
|
-
const a =
|
|
1596
|
+
const a = ft.parseFromTypedEvent(t);
|
|
1564
1597
|
if (!a)
|
|
1565
1598
|
throw "Server event was null";
|
|
1566
|
-
this.events.push([(/* @__PURE__ */ new Date()).getTime(), ((s = t.text) == null ? void 0 : s.length) ?? 0]), this.stats.eventCount += 1, this.stats.totalTransfered += e.length, a.session_information && !a.subAgentId
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1599
|
+
if (this.events.push([(/* @__PURE__ */ new Date()).getTime(), ((s = t.text) == null ? void 0 : s.length) ?? 0]), this.stats.eventCount += 1, this.stats.totalTransfered += e.length, a.session_information && !a.subAgentId) {
|
|
1600
|
+
const r = xt(this.previousSessionInformation, a.session_information);
|
|
1601
|
+
r && (this.sessionCompactions.push(r), this.sessionCompactions.length > $t && this.sessionCompactions.shift()), this.previousSessionInformation = a.session_information, this.stats.sessionInformation = a.session_information, this.stats.sessionCompactions = this.sessionCompactions;
|
|
1602
|
+
}
|
|
1603
|
+
this.stats.elapsed = (Date.now() - this.stats.startTime.getTime()) / 1e3;
|
|
1604
|
+
const n = Date.now() - ct * 1e3, l = this.events.filter((r) => r[0] > n).reduce((r, d) => r += d[1], 0) / Wt;
|
|
1605
|
+
this.stats.tokensPerSecond = l / ct, this.flushStatsCoalesced(), this.onEvent && this.onEvent(a).catch((r) => {
|
|
1606
|
+
console.error("Lost error on on-event", r);
|
|
1570
1607
|
});
|
|
1571
1608
|
} catch (a) {
|
|
1572
1609
|
console.error("handleEvent error", a);
|
|
@@ -1574,10 +1611,10 @@ const H = 4001, Lt = 4002, ot = 4, Ut = 3, xt = 500, Bt = 3e4, Wt = 2, $t = 0.2,
|
|
|
1574
1611
|
}
|
|
1575
1612
|
};
|
|
1576
1613
|
f(Q, "WebSocketConnecionV2");
|
|
1577
|
-
let
|
|
1578
|
-
const
|
|
1579
|
-
constructor(e, s, a, n,
|
|
1580
|
-
super(e, s, a, n,
|
|
1614
|
+
let ht = Q;
|
|
1615
|
+
const Kt = "envision_agent_sessionId", Z = class Z extends G {
|
|
1616
|
+
constructor(e, s, a, n, o, l, r, d, u, h, v) {
|
|
1617
|
+
super(e, s, a, n, o, l, r, u, v);
|
|
1581
1618
|
i(this, "suspendState", !1);
|
|
1582
1619
|
i(this, "wsService");
|
|
1583
1620
|
i(this, "root_url", "");
|
|
@@ -1601,7 +1638,7 @@ const qt = "envision_agent_sessionId", Z = class Z extends G {
|
|
|
1601
1638
|
}, this.wsService.onPong = (p) => {
|
|
1602
1639
|
}, this.wsService.onError = (p) => {
|
|
1603
1640
|
this.streamOpened = !1;
|
|
1604
|
-
const
|
|
1641
|
+
const D = {
|
|
1605
1642
|
data: this.getErrorEvent(p),
|
|
1606
1643
|
lastEventId: (/* @__PURE__ */ new Date()).getTime().toString(),
|
|
1607
1644
|
origin: "gatewayService"
|
|
@@ -1612,14 +1649,14 @@ const qt = "envision_agent_sessionId", Z = class Z extends G {
|
|
|
1612
1649
|
// Tagged so a host can recognise this one and draw its own affordance (a progress bar glued
|
|
1613
1650
|
// to the page, say) instead of a toast, without matching on the copy.
|
|
1614
1651
|
kind: "connection-restarting"
|
|
1615
|
-
}), super.Message(
|
|
1652
|
+
}), super.Message(D);
|
|
1616
1653
|
}, this.wsService.onOpen = () => {
|
|
1617
1654
|
this.everConnected = !0, this.sessionState.setConnectionStatus(F.Connected);
|
|
1618
1655
|
}, this.wsService.onReconnected = (p) => {
|
|
1619
1656
|
this.sessionState.setConnectionStatus(F.Connected);
|
|
1620
1657
|
}, this.wsService.onFirstToken = (p) => {
|
|
1621
1658
|
this.localEmitFirstToken(p);
|
|
1622
|
-
}, this.wsService.onClose = (p,
|
|
1659
|
+
}, this.wsService.onClose = (p, D) => {
|
|
1623
1660
|
p != H && this.sessionState.setConnectionStatus(F.Disconnected);
|
|
1624
1661
|
};
|
|
1625
1662
|
}
|
|
@@ -1630,7 +1667,7 @@ const qt = "envision_agent_sessionId", Z = class Z extends G {
|
|
|
1630
1667
|
return this.suspendState;
|
|
1631
1668
|
}
|
|
1632
1669
|
getStoredSessionId() {
|
|
1633
|
-
const e = localStorage.getItem(
|
|
1670
|
+
const e = localStorage.getItem(Kt);
|
|
1634
1671
|
if (e)
|
|
1635
1672
|
return e;
|
|
1636
1673
|
}
|
|
@@ -1651,15 +1688,15 @@ const qt = "envision_agent_sessionId", Z = class Z extends G {
|
|
|
1651
1688
|
async suspend() {
|
|
1652
1689
|
const e = this.wsService;
|
|
1653
1690
|
return new Promise(async (a, n) => {
|
|
1654
|
-
let
|
|
1691
|
+
let o = !1;
|
|
1655
1692
|
e.onSuspended = () => {
|
|
1656
|
-
|
|
1693
|
+
o = !0;
|
|
1657
1694
|
}, e.suspendStream();
|
|
1658
1695
|
try {
|
|
1659
1696
|
let d = 0;
|
|
1660
|
-
for (; !
|
|
1697
|
+
for (; !o && d < 5e3; )
|
|
1661
1698
|
await this.sleep(100), d += 100;
|
|
1662
|
-
if (
|
|
1699
|
+
if (o)
|
|
1663
1700
|
if (this.currentIS) {
|
|
1664
1701
|
const u = this.currentIS.interaction;
|
|
1665
1702
|
u.isSuspended = !0, this.sessionState.setCurrentMessage(u), this.sessionState.setTurnOpen(!1), a(!0);
|
|
@@ -1694,10 +1731,10 @@ const qt = "envision_agent_sessionId", Z = class Z extends G {
|
|
|
1694
1731
|
}
|
|
1695
1732
|
async openConnection(e, s) {
|
|
1696
1733
|
return this.lastConnectionPromise ? this.lastConnectionPromise : this.socketState == F.Disconnected ? (this.lastConnectionPromise = new Promise((a, n) => {
|
|
1697
|
-
this.wsService.connect(e, s).then((
|
|
1698
|
-
this.sessionId =
|
|
1699
|
-
}).catch((
|
|
1700
|
-
n(
|
|
1734
|
+
this.wsService.connect(e, s).then((o) => {
|
|
1735
|
+
this.sessionId = o, a(o);
|
|
1736
|
+
}).catch((o) => {
|
|
1737
|
+
n(o);
|
|
1701
1738
|
}).finally(() => {
|
|
1702
1739
|
this.lastConnectionPromise = null;
|
|
1703
1740
|
});
|
|
@@ -1725,22 +1762,22 @@ const qt = "envision_agent_sessionId", Z = class Z extends G {
|
|
|
1725
1762
|
}
|
|
1726
1763
|
// Send a message to the server via HTTP POST
|
|
1727
1764
|
async sendMessageInternal(e, s, a) {
|
|
1728
|
-
var l,
|
|
1765
|
+
var l, r, d, u, h, v, p, D;
|
|
1729
1766
|
const n = this.suspendState;
|
|
1730
1767
|
this.suspendState = !1;
|
|
1731
|
-
const
|
|
1732
|
-
if (this.registerInteractionCallId(
|
|
1768
|
+
const o = this.startInteraction(e.friendlyMessage ?? e.data, n);
|
|
1769
|
+
if (this.registerInteractionCallId(o.interactionId, s), (l = e.userUi) != null && l.name && o.parts.push(N.fromUserUi(e.userUi.name, e.userUi.args)), !this.wsService)
|
|
1733
1770
|
throw "no wsService created";
|
|
1734
1771
|
if (!this.sessionId)
|
|
1735
1772
|
throw "no session id set";
|
|
1736
|
-
if (!((
|
|
1773
|
+
if (!((r = this.config.agentConfig) != null && r.id))
|
|
1737
1774
|
throw "Agent not selected";
|
|
1738
1775
|
return this.wsService.sendMessage({
|
|
1739
1776
|
Content: e.data,
|
|
1740
1777
|
SessionId: this.sessionId,
|
|
1741
1778
|
Action: U.SendMessage,
|
|
1742
1779
|
ModelId: this.config.model,
|
|
1743
|
-
InteractionId:
|
|
1780
|
+
InteractionId: o.interactionId,
|
|
1744
1781
|
AgentId: (d = this.config.agentConfig) == null ? void 0 : d.id,
|
|
1745
1782
|
// Optional explicit C# class name on the server (e.g. "LlmAgentSessionReplay").
|
|
1746
1783
|
// When set, AgentBootStrapService.GetAgent dispatches to that class directly
|
|
@@ -1750,23 +1787,23 @@ const qt = "envision_agent_sessionId", Z = class Z extends G {
|
|
|
1750
1787
|
AgentImplementation: (u = this.config.agentConfig) == null ? void 0 : u.agentImplementation,
|
|
1751
1788
|
Parameters: {
|
|
1752
1789
|
CustomerName: ((h = this.config.customer) == null ? void 0 : h.name) ?? "",
|
|
1753
|
-
DataSet: ((
|
|
1790
|
+
DataSet: ((v = this.config.customer) == null ? void 0 : v.dataSetId) ?? ""
|
|
1754
1791
|
},
|
|
1755
1792
|
// Forward image attachments as a structured payload (PascalCase
|
|
1756
1793
|
// keys to match the C# `Message.Images` / `MessageImage` model).
|
|
1757
|
-
Images: (p = e.images) != null && p.length ? e.images.map((
|
|
1794
|
+
Images: (p = e.images) != null && p.length ? e.images.map((T) => ({ MimeType: T.mimeType, Data: T.data })) : void 0,
|
|
1758
1795
|
// Client-only UI representation for this turn (PascalCase to match the C# `Message.UserUi`
|
|
1759
1796
|
// model). The server persists it as a UserUiContent sibling and strips it from the model
|
|
1760
1797
|
// request; Content remains the only model-facing text.
|
|
1761
|
-
UserUi: (
|
|
1762
|
-
}), this.localOpen(
|
|
1763
|
-
interaction:
|
|
1798
|
+
UserUi: (D = e.userUi) != null && D.name ? { Name: e.userUi.name, Args: e.userUi.args } : void 0
|
|
1799
|
+
}), this.localOpen(o.interactionId, "system"), Promise.resolve({
|
|
1800
|
+
interaction: o,
|
|
1764
1801
|
success: !0
|
|
1765
1802
|
});
|
|
1766
1803
|
}
|
|
1767
1804
|
};
|
|
1768
1805
|
f(Z, "AgentGatewayWSAsync");
|
|
1769
|
-
let
|
|
1806
|
+
let ut = Z;
|
|
1770
1807
|
const V = class V {
|
|
1771
1808
|
constructor(t, e) {
|
|
1772
1809
|
i(this, "cache", /* @__PURE__ */ new Map());
|
|
@@ -1775,7 +1812,7 @@ const V = class V {
|
|
|
1775
1812
|
this.serverBaseUrl = t.replace(/\/$/, ""), this.accessToken = e;
|
|
1776
1813
|
}
|
|
1777
1814
|
get headers() {
|
|
1778
|
-
return { Authorization: `Bearer ${
|
|
1815
|
+
return { Authorization: `Bearer ${bt(this.accessToken)}` };
|
|
1779
1816
|
}
|
|
1780
1817
|
async init() {
|
|
1781
1818
|
}
|
|
@@ -1823,16 +1860,16 @@ const V = class V {
|
|
|
1823
1860
|
}
|
|
1824
1861
|
};
|
|
1825
1862
|
f(V, "HttpArtifactService");
|
|
1826
|
-
let
|
|
1863
|
+
let dt = V;
|
|
1827
1864
|
export {
|
|
1828
1865
|
G as A,
|
|
1829
1866
|
q as E,
|
|
1830
|
-
|
|
1867
|
+
dt as H,
|
|
1831
1868
|
B as I,
|
|
1832
1869
|
at as L,
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1870
|
+
ot as M,
|
|
1871
|
+
ht as W,
|
|
1872
|
+
ut as a,
|
|
1873
|
+
ne as u
|
|
1837
1874
|
};
|
|
1838
|
-
//# sourceMappingURL=httpArtifactService-
|
|
1875
|
+
//# sourceMappingURL=httpArtifactService-CqEs3x-Q.js.map
|