@aintela/chat 0.2.22 → 0.2.26
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 +4518 -4442
- package/dist/components.js.map +1 -1
- package/dist/hooks.js +2 -2
- package/dist/{httpArtifactService-Dh9LGQ9a.js → httpArtifactService-DFlQzSgN.js} +429 -407
- package/dist/httpArtifactService-DFlQzSgN.js.map +1 -0
- package/dist/{httpSessionService-5Kr__oQL.js → httpSessionService-D9JXx3JD.js} +2 -2
- package/dist/{httpSessionService-5Kr__oQL.js.map → httpSessionService-D9JXx3JD.js.map} +1 -1
- package/dist/index.js +5 -5
- package/dist/models.js +1 -1
- package/dist/{serializer-DyHZxlAG.js → serializer-C1uBjgTd.js} +499 -457
- package/dist/serializer-C1uBjgTd.js.map +1 -0
- package/dist/services.js +2 -2
- package/dist/src/components/AiChat/ChatPane/parts/AskUserDispatcher.d.ts +22 -0
- package/dist/src/components/AiChat/ChatPane/parts/types.d.ts +17 -0
- package/dist/src/components/AiChat/ChatPane/parts/uiToolRegistry.d.ts +47 -2
- package/dist/src/components/v2/PromptV2.d.ts +8 -1
- package/dist/src/hooks/usePromptAssist.d.ts +7 -1
- package/dist/src/models/ServerEvent.d.ts +11 -0
- package/dist/src/models/semanticKernelModel/models.d.ts +8 -1
- package/dist/src/services/httpPromptAssistService.d.ts +19 -0
- package/dist/{useChatSessions-DttlifVk.js → useChatSessions-C1rHmRuS.js} +2 -2
- package/dist/{useChatSessions-DttlifVk.js.map → useChatSessions-C1rHmRuS.js.map} +1 -1
- package/dist/useContainerWidth-0EA-kdzl.js +260 -0
- package/dist/useContainerWidth-0EA-kdzl.js.map +1 -0
- package/package.json +1 -1
- package/dist/httpArtifactService-Dh9LGQ9a.js.map +0 -1
- package/dist/serializer-DyHZxlAG.js.map +0 -1
- package/dist/useContainerWidth-DsNHNR-z.js +0 -187
- package/dist/useContainerWidth-DsNHNR-z.js.map +0 -1
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var g = (
|
|
4
|
-
var a = (
|
|
5
|
-
import { d as _, t as
|
|
6
|
-
import { I as A, S as
|
|
7
|
-
import { unified as
|
|
8
|
-
import
|
|
9
|
-
import { toMarkdown as
|
|
10
|
-
import { format as
|
|
11
|
-
import
|
|
12
|
-
import { P as
|
|
13
|
-
const
|
|
1
|
+
var nt = Object.defineProperty;
|
|
2
|
+
var ft = (O, t, e) => t in O ? nt(O, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : O[t] = e;
|
|
3
|
+
var g = (O, t) => nt(O, "name", { value: t, configurable: !0 });
|
|
4
|
+
var a = (O, t, e) => ft(O, typeof t != "symbol" ? t + "" : t, e);
|
|
5
|
+
import { d as _, t as mt, E as y, k as pt, j as St, q as wt, C as U } from "./environmentUtils-BaKw5_VD.js";
|
|
6
|
+
import { I as A, S as ut, g as Tt, L as yt, P as F, b as It, e as Ct, T as vt, c as Et } from "./serializer-C1uBjgTd.js";
|
|
7
|
+
import { unified as Mt } from "unified";
|
|
8
|
+
import Ot from "remark-parse";
|
|
9
|
+
import { toMarkdown as Dt } from "mdast-util-to-markdown";
|
|
10
|
+
import { format as At } from "date-fns";
|
|
11
|
+
import Nt from "lodash";
|
|
12
|
+
import { P as Pt, C as P } from "./Prompt-DZb7OaPp.js";
|
|
13
|
+
const T = {
|
|
14
14
|
ARTIFACTS: "envision-artifacts",
|
|
15
15
|
SECTIONS: "envision-sections",
|
|
16
16
|
PROMPTS: "envision-prompts"
|
|
@@ -36,7 +36,7 @@ const S = {
|
|
|
36
36
|
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
37
37
|
iconType: "folder"
|
|
38
38
|
}
|
|
39
|
-
],
|
|
39
|
+
], J = class J {
|
|
40
40
|
constructor() {
|
|
41
41
|
a(this, "onPromptCreated", /* @__PURE__ */ g(() => {
|
|
42
42
|
}, "onPromptCreated"));
|
|
@@ -52,27 +52,27 @@ const S = {
|
|
|
52
52
|
}
|
|
53
53
|
initializeStorage() {
|
|
54
54
|
try {
|
|
55
|
-
const t = localStorage.getItem(
|
|
55
|
+
const t = localStorage.getItem(T.SECTIONS);
|
|
56
56
|
if (!t)
|
|
57
|
-
localStorage.setItem(
|
|
57
|
+
localStorage.setItem(T.SECTIONS, JSON.stringify(k));
|
|
58
58
|
else {
|
|
59
59
|
const s = JSON.parse(t);
|
|
60
60
|
if (k.some(
|
|
61
|
-
(
|
|
61
|
+
(n) => !s.find((r) => r.id === n.id)
|
|
62
62
|
)) {
|
|
63
|
-
const
|
|
63
|
+
const n = [...s];
|
|
64
64
|
k.forEach((r) => {
|
|
65
|
-
s.find((l) => l.id === r.id) ||
|
|
66
|
-
}), localStorage.setItem(
|
|
65
|
+
s.find((l) => l.id === r.id) || n.push(r);
|
|
66
|
+
}), localStorage.setItem(T.SECTIONS, JSON.stringify(n));
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
const e = localStorage.getItem(
|
|
69
|
+
const e = localStorage.getItem(T.ARTIFACTS);
|
|
70
70
|
if (e) {
|
|
71
71
|
const s = JSON.parse(e);
|
|
72
|
-
let
|
|
73
|
-
const
|
|
72
|
+
let i = !1;
|
|
73
|
+
const n = s.map((r) => {
|
|
74
74
|
if (!r.sectionId) {
|
|
75
|
-
|
|
75
|
+
i = !0;
|
|
76
76
|
let l = "data-analytics";
|
|
77
77
|
return r.type === _.Dashboard ? l = "dashboards" : r.type === _.Chart && (l = "charts"), {
|
|
78
78
|
...r,
|
|
@@ -81,7 +81,7 @@ const S = {
|
|
|
81
81
|
}
|
|
82
82
|
return r;
|
|
83
83
|
});
|
|
84
|
-
|
|
84
|
+
i && localStorage.setItem(T.ARTIFACTS, JSON.stringify(n));
|
|
85
85
|
}
|
|
86
86
|
} catch (t) {
|
|
87
87
|
console.error("Error initializing storage:", t);
|
|
@@ -89,7 +89,7 @@ const S = {
|
|
|
89
89
|
}
|
|
90
90
|
getSections() {
|
|
91
91
|
try {
|
|
92
|
-
const t = localStorage.getItem(
|
|
92
|
+
const t = localStorage.getItem(T.SECTIONS);
|
|
93
93
|
return t ? JSON.parse(t) : k;
|
|
94
94
|
} catch (t) {
|
|
95
95
|
return console.error("Error loading sections:", t), k;
|
|
@@ -97,7 +97,7 @@ const S = {
|
|
|
97
97
|
}
|
|
98
98
|
getArtifacts() {
|
|
99
99
|
try {
|
|
100
|
-
const t = localStorage.getItem(
|
|
100
|
+
const t = localStorage.getItem(T.ARTIFACTS);
|
|
101
101
|
return t ? JSON.parse(t) : [];
|
|
102
102
|
} catch (t) {
|
|
103
103
|
return console.error("Error loading artifacts:", t), [];
|
|
@@ -110,53 +110,53 @@ const S = {
|
|
|
110
110
|
isDefault: !1,
|
|
111
111
|
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
112
112
|
iconType: e
|
|
113
|
-
},
|
|
114
|
-
return
|
|
113
|
+
}, i = this.getSections();
|
|
114
|
+
return i.push(s), localStorage.setItem(T.SECTIONS, JSON.stringify(i)), s;
|
|
115
115
|
}
|
|
116
116
|
updateSection(t, e) {
|
|
117
|
-
const s = this.getSections(),
|
|
118
|
-
|
|
117
|
+
const s = this.getSections(), i = s.findIndex((n) => n.id === t);
|
|
118
|
+
i >= 0 && (s[i] = { ...s[i], ...e }, localStorage.setItem(T.SECTIONS, JSON.stringify(s)));
|
|
119
119
|
}
|
|
120
120
|
deleteSection(t) {
|
|
121
|
-
const e = this.getSections(), s = e.find((
|
|
121
|
+
const e = this.getSections(), s = e.find((i) => i.id === t);
|
|
122
122
|
if (s && !s.isDefault) {
|
|
123
|
-
const
|
|
124
|
-
localStorage.setItem(
|
|
125
|
-
const l = e.filter((
|
|
126
|
-
localStorage.setItem(
|
|
123
|
+
const i = this.getArtifacts(), n = s.iconType === "dashboard" ? "dashboards" : s.iconType === "chart" ? "charts" : "data-analytics", r = i.map((o) => o.sectionId === t ? { ...o, sectionId: n } : o);
|
|
124
|
+
localStorage.setItem(T.ARTIFACTS, JSON.stringify(r));
|
|
125
|
+
const l = e.filter((o) => o.id !== t);
|
|
126
|
+
localStorage.setItem(T.SECTIONS, JSON.stringify(l));
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
storeArtifact(t) {
|
|
130
130
|
try {
|
|
131
|
-
const e = this.getArtifacts(), s = e.findIndex((
|
|
131
|
+
const e = this.getArtifacts(), s = e.findIndex((i) => i.id === t.id);
|
|
132
132
|
if (s >= 0)
|
|
133
133
|
e[s] = t;
|
|
134
134
|
else {
|
|
135
|
-
let
|
|
136
|
-
t.type === _.Dashboard ?
|
|
137
|
-
const
|
|
135
|
+
let i = "data-analytics";
|
|
136
|
+
t.type === _.Dashboard ? i = "dashboards" : t.type === _.Chart && (i = "charts");
|
|
137
|
+
const n = {
|
|
138
138
|
...t,
|
|
139
139
|
created: t.created || (/* @__PURE__ */ new Date()).toISOString(),
|
|
140
|
-
sectionId: t.sectionId ||
|
|
140
|
+
sectionId: t.sectionId || i
|
|
141
141
|
};
|
|
142
|
-
e.push(
|
|
142
|
+
e.push(n);
|
|
143
143
|
}
|
|
144
|
-
localStorage.setItem(
|
|
144
|
+
localStorage.setItem(T.ARTIFACTS, JSON.stringify(e));
|
|
145
145
|
} catch (e) {
|
|
146
146
|
console.error("Error storing artifact:", e);
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
moveArtifact(t, e) {
|
|
150
|
-
const s = this.getArtifacts(),
|
|
151
|
-
|
|
150
|
+
const s = this.getArtifacts(), i = s.findIndex((n) => n.id === t);
|
|
151
|
+
i >= 0 && (s[i] = { ...s[i], sectionId: e }, localStorage.setItem(T.ARTIFACTS, JSON.stringify(s)));
|
|
152
152
|
}
|
|
153
153
|
deleteArtifact(t) {
|
|
154
|
-
const s = this.getArtifacts().filter((
|
|
155
|
-
localStorage.setItem(
|
|
154
|
+
const s = this.getArtifacts().filter((i) => i.id !== t);
|
|
155
|
+
localStorage.setItem(T.ARTIFACTS, JSON.stringify(s));
|
|
156
156
|
}
|
|
157
157
|
updateArtifact(t, e) {
|
|
158
|
-
const s = this.getArtifacts(),
|
|
159
|
-
|
|
158
|
+
const s = this.getArtifacts(), i = s.findIndex((n) => n.id === t);
|
|
159
|
+
i >= 0 && (s[i] = { ...s[i], ...e }, localStorage.setItem(T.ARTIFACTS, JSON.stringify(s)));
|
|
160
160
|
}
|
|
161
161
|
getArtifactsBySection(t) {
|
|
162
162
|
return this.getArtifacts().filter((s) => s.sectionId === t);
|
|
@@ -164,8 +164,8 @@ const S = {
|
|
|
164
164
|
// Prompt management methods
|
|
165
165
|
getPrompts() {
|
|
166
166
|
try {
|
|
167
|
-
const t = localStorage.getItem(
|
|
168
|
-
return t ? JSON.parse(t).sort((s,
|
|
167
|
+
const t = localStorage.getItem(T.PROMPTS);
|
|
168
|
+
return t ? JSON.parse(t).sort((s, i) => new Date(i.created).getTime() - new Date(s.created).getTime()) : [];
|
|
169
169
|
} catch (t) {
|
|
170
170
|
return console.error("Error loading prompts:", t), [];
|
|
171
171
|
}
|
|
@@ -175,37 +175,37 @@ const S = {
|
|
|
175
175
|
const e = this.getPrompts();
|
|
176
176
|
e.length > 0 && e[0].promptText === t.promptText && (e[0].created = t.created, e[0].id = t.id), e.unshift(t);
|
|
177
177
|
const s = e.slice(0, 50);
|
|
178
|
-
localStorage.setItem(
|
|
178
|
+
localStorage.setItem(T.PROMPTS, JSON.stringify(s));
|
|
179
179
|
} catch (e) {
|
|
180
180
|
console.error("Error storing prompt:", e);
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
deletePrompt(t) {
|
|
184
184
|
try {
|
|
185
|
-
const s = this.getPrompts().filter((
|
|
186
|
-
localStorage.setItem(
|
|
185
|
+
const s = this.getPrompts().filter((i) => i.id !== t);
|
|
186
|
+
localStorage.setItem(T.PROMPTS, JSON.stringify(s));
|
|
187
187
|
} catch (e) {
|
|
188
188
|
console.error("Error deleting prompt:", e);
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
clearAllPrompts() {
|
|
192
192
|
try {
|
|
193
|
-
localStorage.removeItem(
|
|
193
|
+
localStorage.removeItem(T.PROMPTS);
|
|
194
194
|
} catch (t) {
|
|
195
195
|
console.error("Error clearing prompts:", t);
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
};
|
|
199
|
-
g(
|
|
200
|
-
let
|
|
201
|
-
const
|
|
202
|
-
const t =
|
|
199
|
+
g(J, "LocalStorageService");
|
|
200
|
+
let it = J;
|
|
201
|
+
const jt = /* @__PURE__ */ g((O) => {
|
|
202
|
+
const t = O.getPrompts(), e = t.length;
|
|
203
203
|
if (e > 0) {
|
|
204
|
-
const s = t[0].promptText,
|
|
205
|
-
return { promptState: e + "_" + s + "_" +
|
|
204
|
+
const s = t[0].promptText, i = t[t.length - 1].promptText, n = t[0].created;
|
|
205
|
+
return { promptState: e + "_" + s + "_" + i + "_" + n };
|
|
206
206
|
} else
|
|
207
207
|
return { promptState: "0" };
|
|
208
|
-
}, "usePromptState"),
|
|
208
|
+
}, "usePromptState"), q = class q {
|
|
209
209
|
constructor() {
|
|
210
210
|
a(this, "activityLost", "activityLost");
|
|
211
211
|
a(this, "artifactGenerated", "artifactGenerated");
|
|
@@ -230,9 +230,9 @@ const Kt = /* @__PURE__ */ g((E) => {
|
|
|
230
230
|
a(this, "gatewayFirstToken", "gatewayFirstToken");
|
|
231
231
|
}
|
|
232
232
|
};
|
|
233
|
-
g(
|
|
234
|
-
let
|
|
235
|
-
const
|
|
233
|
+
g(q, "EventTypes");
|
|
234
|
+
let x = q;
|
|
235
|
+
const c = new x(), G = class G {
|
|
236
236
|
constructor() {
|
|
237
237
|
a(this, "listeners", {});
|
|
238
238
|
a(this, "listenersCount", {});
|
|
@@ -240,9 +240,9 @@ const o = new U(), q = class q {
|
|
|
240
240
|
callListeners(t, ...e) {
|
|
241
241
|
const s = this.listeners[t];
|
|
242
242
|
if (this.listenersCount[t] = this.listenersCount[t] + 1, s) {
|
|
243
|
-
const
|
|
244
|
-
Promise.all(
|
|
245
|
-
console.error(`Lost error in one of the listeners of the event: ${t}, listeners: ${s.length}, error: ${
|
|
243
|
+
const i = s.map((n) => n(...e));
|
|
244
|
+
Promise.all(i).catch((n) => {
|
|
245
|
+
console.error(`Lost error in one of the listeners of the event: ${t}, listeners: ${s.length}, error: ${n}`, s);
|
|
246
246
|
});
|
|
247
247
|
}
|
|
248
248
|
}
|
|
@@ -253,239 +253,239 @@ const o = new U(), q = class q {
|
|
|
253
253
|
return this.listenersCount[t];
|
|
254
254
|
}
|
|
255
255
|
activityOnLost(t) {
|
|
256
|
-
const e =
|
|
256
|
+
const e = c.activityLost;
|
|
257
257
|
this.addListener(e, t);
|
|
258
258
|
}
|
|
259
259
|
activityEmitLost() {
|
|
260
|
-
this.callListeners(
|
|
260
|
+
this.callListeners(c.activityLost);
|
|
261
261
|
}
|
|
262
262
|
/* typed artifact listeners */
|
|
263
263
|
artifactOnGenerated(t) {
|
|
264
|
-
const e =
|
|
264
|
+
const e = c.artifactGenerated;
|
|
265
265
|
this.addListener(e, t);
|
|
266
266
|
}
|
|
267
267
|
artifactEmitGenerated(t) {
|
|
268
|
-
this.callListeners(
|
|
268
|
+
this.callListeners(c.artifactGenerated, t);
|
|
269
269
|
}
|
|
270
270
|
artifactOffGenerated(t) {
|
|
271
|
-
const e =
|
|
271
|
+
const e = c.artifactGenerated;
|
|
272
272
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
273
273
|
}
|
|
274
274
|
artifactOnSelected(t) {
|
|
275
|
-
const e =
|
|
275
|
+
const e = c.artifactSelected;
|
|
276
276
|
this.addListener(e, t);
|
|
277
277
|
}
|
|
278
278
|
artifactEmitSelected(t) {
|
|
279
|
-
this.callListeners(
|
|
279
|
+
this.callListeners(c.artifactSelected, t);
|
|
280
280
|
}
|
|
281
281
|
artifactOffSelected(t) {
|
|
282
|
-
const e =
|
|
282
|
+
const e = c.artifactSelected;
|
|
283
283
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
284
284
|
}
|
|
285
285
|
artifactOnDeleted(t) {
|
|
286
|
-
const e =
|
|
286
|
+
const e = c.artifactDeleted;
|
|
287
287
|
this.addListener(e, t);
|
|
288
288
|
}
|
|
289
289
|
artifactEmitDeleted(t) {
|
|
290
|
-
this.callListeners(
|
|
290
|
+
this.callListeners(c.artifactDeleted, t);
|
|
291
291
|
}
|
|
292
292
|
artifactOffDeleted(t) {
|
|
293
|
-
const e =
|
|
293
|
+
const e = c.artifactDeleted;
|
|
294
294
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
295
295
|
}
|
|
296
296
|
gatewayOnMessage(t) {
|
|
297
|
-
const e =
|
|
297
|
+
const e = c.gatewayMessage;
|
|
298
298
|
this.addListener(e, t);
|
|
299
299
|
}
|
|
300
300
|
gatewayOnTurnComplete(t) {
|
|
301
|
-
const e =
|
|
301
|
+
const e = c.gatewayTurnComplete;
|
|
302
302
|
this.addListener(e, t);
|
|
303
303
|
}
|
|
304
304
|
gatewayOnTurnOpen(t) {
|
|
305
|
-
const e =
|
|
305
|
+
const e = c.gatewayTurnOpen;
|
|
306
306
|
this.addListener(e, t);
|
|
307
307
|
}
|
|
308
308
|
gatewayOnStreamError(t) {
|
|
309
|
-
const e =
|
|
309
|
+
const e = c.gatewayStreamError;
|
|
310
310
|
this.addListener(e, t);
|
|
311
311
|
}
|
|
312
312
|
gatewayOnStreamEnded(t) {
|
|
313
|
-
const e =
|
|
313
|
+
const e = c.gatewayStreamEnded;
|
|
314
314
|
this.addListener(e, t);
|
|
315
315
|
}
|
|
316
316
|
gatewayOffStreamEnded(t) {
|
|
317
|
-
const e =
|
|
317
|
+
const e = c.gatewayStreamEnded;
|
|
318
318
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
319
319
|
}
|
|
320
320
|
gatewayEmitStreamEnded(t, e) {
|
|
321
|
-
this.callListeners(
|
|
321
|
+
this.callListeners(c.gatewayStreamEnded, t, e);
|
|
322
322
|
}
|
|
323
323
|
gatewayEmitMessage(t, e = null) {
|
|
324
|
-
this.callListeners(
|
|
324
|
+
this.callListeners(c.gatewayMessage, t, e);
|
|
325
325
|
}
|
|
326
326
|
gatewayEmitTurnComplete(t, e) {
|
|
327
|
-
this.callListeners(
|
|
327
|
+
this.callListeners(c.gatewayTurnComplete, t, e);
|
|
328
328
|
}
|
|
329
329
|
gatewayEmitStreamError(t) {
|
|
330
|
-
this.callListeners(
|
|
330
|
+
this.callListeners(c.gatewayStreamError, t);
|
|
331
331
|
}
|
|
332
332
|
gatewayEmitTurnOpen(t) {
|
|
333
|
-
this.callListeners(
|
|
333
|
+
this.callListeners(c.gatewayTurnOpen, t);
|
|
334
334
|
}
|
|
335
335
|
gatewayOffMessage(t) {
|
|
336
|
-
const e =
|
|
336
|
+
const e = c.gatewayMessage;
|
|
337
337
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
338
338
|
}
|
|
339
339
|
gatewayOffTurnComplete(t) {
|
|
340
|
-
const e =
|
|
340
|
+
const e = c.gatewayTurnComplete;
|
|
341
341
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
342
342
|
}
|
|
343
343
|
gatewayOffTurnOpen(t) {
|
|
344
|
-
const e =
|
|
344
|
+
const e = c.gatewayTurnOpen;
|
|
345
345
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
346
346
|
}
|
|
347
347
|
gatewayOffStreamError(t) {
|
|
348
|
-
const e =
|
|
348
|
+
const e = c.gatewayStreamError;
|
|
349
349
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
350
350
|
}
|
|
351
351
|
sessionOnCreated(t) {
|
|
352
|
-
const e =
|
|
352
|
+
const e = c.sessionCreated;
|
|
353
353
|
this.addListener(e, t);
|
|
354
354
|
}
|
|
355
355
|
chatOnMessageSent(t) {
|
|
356
|
-
const e =
|
|
356
|
+
const e = c.onMessageSent;
|
|
357
357
|
this.addListener(e, t);
|
|
358
358
|
}
|
|
359
359
|
chatOffMessageSent(t) {
|
|
360
|
-
const e =
|
|
360
|
+
const e = c.onMessageSent;
|
|
361
361
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
362
362
|
}
|
|
363
363
|
ChatEmitMessageSent(t, e) {
|
|
364
|
-
this.callListeners(
|
|
364
|
+
this.callListeners(c.onMessageSent, t, e);
|
|
365
365
|
}
|
|
366
366
|
chatOnMessageError(t) {
|
|
367
|
-
const e =
|
|
367
|
+
const e = c.onMessageError;
|
|
368
368
|
this.addListener(e, t);
|
|
369
369
|
}
|
|
370
370
|
chatOffMessageError(t) {
|
|
371
|
-
const e =
|
|
371
|
+
const e = c.onMessageError;
|
|
372
372
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
373
373
|
}
|
|
374
374
|
ChatEmitMessageError(t) {
|
|
375
|
-
this.callListeners(
|
|
375
|
+
this.callListeners(c.onMessageError, t);
|
|
376
376
|
}
|
|
377
377
|
sessionOnUpdated(t) {
|
|
378
|
-
const e =
|
|
378
|
+
const e = c.sessionUpdated;
|
|
379
379
|
this.addListener(e, t);
|
|
380
380
|
}
|
|
381
381
|
sessionEmitCreated(t) {
|
|
382
|
-
this.callListeners(
|
|
382
|
+
this.callListeners(c.sessionCreated, t);
|
|
383
383
|
}
|
|
384
384
|
sessionEmitUpdated(t) {
|
|
385
|
-
this.callListeners(
|
|
385
|
+
this.callListeners(c.sessionUpdated, t);
|
|
386
386
|
}
|
|
387
387
|
sessionOffCreated(t) {
|
|
388
|
-
const e =
|
|
388
|
+
const e = c.sessionCreated;
|
|
389
389
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
390
390
|
}
|
|
391
391
|
sessionOffUpdated(t) {
|
|
392
|
-
const e =
|
|
392
|
+
const e = c.sessionUpdated;
|
|
393
393
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
394
394
|
}
|
|
395
395
|
gatewayEmitFunctionResponse(t) {
|
|
396
|
-
this.callListeners(
|
|
396
|
+
this.callListeners(c.gatewayFunctionResponse, t);
|
|
397
397
|
}
|
|
398
398
|
gatewayOffFunctionResponse(t) {
|
|
399
|
-
const e =
|
|
399
|
+
const e = c.gatewayFunctionResponse;
|
|
400
400
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
401
401
|
}
|
|
402
402
|
gatewayOnFunctionResponse(t) {
|
|
403
|
-
const e =
|
|
403
|
+
const e = c.gatewayFunctionResponse;
|
|
404
404
|
this.addListener(e, t);
|
|
405
405
|
}
|
|
406
406
|
// UI events
|
|
407
407
|
uiOnUnsavedPopoverToggle(t) {
|
|
408
|
-
const e =
|
|
408
|
+
const e = c.uiUnsavedPopoverToggle;
|
|
409
409
|
this.addListener(e, t);
|
|
410
410
|
}
|
|
411
411
|
uiEmitUnsavedPopoverToggle(t) {
|
|
412
|
-
this.callListeners(
|
|
412
|
+
this.callListeners(c.uiUnsavedPopoverToggle, t);
|
|
413
413
|
}
|
|
414
414
|
uiOffUnsavedPopoverToggle(t) {
|
|
415
|
-
const e =
|
|
415
|
+
const e = c.uiUnsavedPopoverToggle;
|
|
416
416
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
417
417
|
}
|
|
418
418
|
// Artifacts storage update events
|
|
419
419
|
artifactsOnStorageUpdated(t) {
|
|
420
|
-
const e =
|
|
420
|
+
const e = c.artifactsStorageUpdated;
|
|
421
421
|
this.addListener(e, t);
|
|
422
422
|
}
|
|
423
423
|
artifactsEmitStorageUpdated() {
|
|
424
|
-
this.callListeners(
|
|
424
|
+
this.callListeners(c.artifactsStorageUpdated);
|
|
425
425
|
}
|
|
426
426
|
artifactsOffStorageUpdated(t) {
|
|
427
|
-
const e =
|
|
427
|
+
const e = c.artifactsStorageUpdated;
|
|
428
428
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
429
429
|
}
|
|
430
430
|
streamOnNewChunk(t) {
|
|
431
|
-
const e =
|
|
431
|
+
const e = c.streamNewChunk;
|
|
432
432
|
this.addListener(e, t);
|
|
433
433
|
}
|
|
434
434
|
streamEmitNewChunk(t) {
|
|
435
|
-
this.callListeners(
|
|
435
|
+
this.callListeners(c.streamNewChunk, t);
|
|
436
436
|
}
|
|
437
437
|
streamOffNewChunk(t) {
|
|
438
|
-
const e =
|
|
438
|
+
const e = c.streamNewChunk;
|
|
439
439
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
440
440
|
}
|
|
441
441
|
gatewayOnEndMessageData(t) {
|
|
442
|
-
const e =
|
|
442
|
+
const e = c.gatewayEndMessageData;
|
|
443
443
|
this.addListener(e, t);
|
|
444
444
|
}
|
|
445
445
|
gatewayEmitEndMessageData(t) {
|
|
446
|
-
this.callListeners(
|
|
446
|
+
this.callListeners(c.gatewayEndMessageData, t);
|
|
447
447
|
}
|
|
448
448
|
gatewayOffEndMessageData(t) {
|
|
449
|
-
const e =
|
|
449
|
+
const e = c.gatewayEndMessageData;
|
|
450
450
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
451
451
|
}
|
|
452
452
|
gatewayOnConnectionStateChange(t) {
|
|
453
|
-
const e =
|
|
453
|
+
const e = c.connectionStateChange;
|
|
454
454
|
this.addListener(e, t);
|
|
455
455
|
}
|
|
456
456
|
gatewayEmitConnectionStateChange(t) {
|
|
457
|
-
this.callListeners(
|
|
457
|
+
this.callListeners(c.connectionStateChange, t);
|
|
458
458
|
}
|
|
459
459
|
gatewayOffConnectionStateChange(t) {
|
|
460
|
-
const e =
|
|
460
|
+
const e = c.connectionStateChange;
|
|
461
461
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
462
462
|
}
|
|
463
463
|
gatewayOnToolEvent(t) {
|
|
464
|
-
const e =
|
|
464
|
+
const e = c.onToolEvent;
|
|
465
465
|
this.addListener(e, t);
|
|
466
466
|
}
|
|
467
467
|
gatewayEmitToolEvent(t, e, s) {
|
|
468
|
-
this.callListeners(
|
|
468
|
+
this.callListeners(c.onToolEvent, t, e, s);
|
|
469
469
|
}
|
|
470
470
|
gatewayOffToolEvent(t) {
|
|
471
|
-
const e =
|
|
471
|
+
const e = c.onToolEvent;
|
|
472
472
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
473
473
|
}
|
|
474
474
|
gatewayOnFirstToken(t) {
|
|
475
|
-
const e =
|
|
475
|
+
const e = c.gatewayFirstToken;
|
|
476
476
|
this.addListener(e, t);
|
|
477
477
|
}
|
|
478
478
|
gatewayEmitFirstToken(t) {
|
|
479
|
-
this.callListeners(
|
|
479
|
+
this.callListeners(c.gatewayFirstToken, t);
|
|
480
480
|
}
|
|
481
481
|
gatewayOffFirstToken(t) {
|
|
482
|
-
const e =
|
|
482
|
+
const e = c.gatewayFirstToken;
|
|
483
483
|
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
|
-
g(
|
|
487
|
-
let
|
|
488
|
-
const
|
|
486
|
+
g(G, "EventBusService");
|
|
487
|
+
let B = G;
|
|
488
|
+
const H = class H extends B {
|
|
489
489
|
constructor() {
|
|
490
490
|
super();
|
|
491
491
|
}
|
|
@@ -493,7 +493,7 @@ const G = class G extends x {
|
|
|
493
493
|
console.log("MockEventBusService.gatewayEmitConnectionStateChange");
|
|
494
494
|
}
|
|
495
495
|
gatewayEmitMessage(t, e) {
|
|
496
|
-
|
|
496
|
+
mt() ? process.stdout.write(`M${t.version}, `) : console.log("MockEventBusService.gatewayEmitMessage");
|
|
497
497
|
}
|
|
498
498
|
gatewayEmitTurnComplete(t, e) {
|
|
499
499
|
console.log("MockEventBusService.gatewayEmitTurnComplete");
|
|
@@ -511,73 +511,73 @@ const G = class G extends x {
|
|
|
511
511
|
console.log("MockEventBusService.gatewayOffFunctionResponse", t);
|
|
512
512
|
}
|
|
513
513
|
};
|
|
514
|
-
g(
|
|
515
|
-
let
|
|
516
|
-
const
|
|
514
|
+
g(H, "MockEventBusService");
|
|
515
|
+
let at = H;
|
|
516
|
+
const dt = {
|
|
517
517
|
inline: "inline",
|
|
518
518
|
block: "block"
|
|
519
|
-
},
|
|
519
|
+
}, K = class K {
|
|
520
520
|
constructor() {
|
|
521
521
|
a(this, "parts", []);
|
|
522
522
|
a(this, "isLastGroup", !1);
|
|
523
523
|
a(this, "hasThoughts", !1);
|
|
524
524
|
a(this, "lastWithThoughts", !1);
|
|
525
|
-
a(this, "type",
|
|
525
|
+
a(this, "type", dt.inline);
|
|
526
526
|
}
|
|
527
527
|
};
|
|
528
|
-
g(
|
|
529
|
-
let R =
|
|
530
|
-
const
|
|
528
|
+
g(K, "InteractionPartGroup");
|
|
529
|
+
let R = K;
|
|
530
|
+
const z = class z {
|
|
531
531
|
constructor(t, e) {
|
|
532
532
|
a(this, "interaction");
|
|
533
533
|
a(this, "eventBusService");
|
|
534
534
|
a(this, "parseTextIntoParts", /* @__PURE__ */ g((t) => {
|
|
535
535
|
if (!t || t.trim().length == 0) return [];
|
|
536
|
-
const e =
|
|
537
|
-
let
|
|
538
|
-
for (const
|
|
539
|
-
|
|
536
|
+
const e = Mt().use(Ot).parse(t), s = [];
|
|
537
|
+
let i = null;
|
|
538
|
+
for (const n of e.children)
|
|
539
|
+
n.type === "code" ? (i && (s.push(i), i = null), n.lang === "htmlCanvas" && s.push(`
|
|
540
540
|
\`\`\`liveTsx
|
|
541
|
-
${
|
|
541
|
+
${n.value}
|
|
542
542
|
\`\`\`
|
|
543
|
-
`)) : (
|
|
544
|
-
return
|
|
543
|
+
`)) : (i || (i = ""), i += Dt(n));
|
|
544
|
+
return i && s.push(i), s;
|
|
545
545
|
}, "parseTextIntoParts"));
|
|
546
546
|
this.interaction = t, this.eventBusService = e;
|
|
547
547
|
}
|
|
548
548
|
expandSubParts(t, e) {
|
|
549
|
-
const s = this.parseTextIntoParts(t),
|
|
550
|
-
let
|
|
549
|
+
const s = this.parseTextIntoParts(t), i = [];
|
|
550
|
+
let n = 0;
|
|
551
551
|
for (const r of s) {
|
|
552
552
|
const l = A.fromText(r);
|
|
553
|
-
l.id =
|
|
553
|
+
l.id = n + "_" + e, i.push(l), n++;
|
|
554
554
|
}
|
|
555
|
-
return
|
|
555
|
+
return i;
|
|
556
556
|
}
|
|
557
557
|
groupPartsByDisplayType(t, e = !0, s = !1) {
|
|
558
558
|
var l;
|
|
559
|
-
const
|
|
560
|
-
let
|
|
561
|
-
for (let
|
|
562
|
-
const u = t[
|
|
563
|
-
let h = !(((l = u.functionDetails) == null ? void 0 : l.isUi) ?? !1) && u.eventType !==
|
|
564
|
-
!e && h && !s || (h ? (u.eventType ==
|
|
565
|
-
type:
|
|
559
|
+
const i = [];
|
|
560
|
+
let n = new R();
|
|
561
|
+
for (let o = 0; o < t.length; o++) {
|
|
562
|
+
const u = t[o];
|
|
563
|
+
let h = !(((l = u.functionDetails) == null ? void 0 : l.isUi) ?? !1) && u.eventType !== y.Text && u.eventType !== y.Thought && (u.eventType === y.FunctionCall || u.eventType === y.PartialFunctionCall || u.eventType === y.FunctionResponse) && o < t.length - 1;
|
|
564
|
+
!e && h && !s || (h ? (u.eventType == y.Thought && (n.hasThoughts = !0), n.parts.push(u), n.isLastGroup = o === t.length - 1) : (n.parts.length > 0 && (i.push(n), n = new R()), i.push({
|
|
565
|
+
type: dt.block,
|
|
566
566
|
parts: [u],
|
|
567
|
-
isLastGroup:
|
|
567
|
+
isLastGroup: o === t.length - 1,
|
|
568
568
|
hasThoughts: !1,
|
|
569
569
|
lastWithThoughts: !1
|
|
570
570
|
})));
|
|
571
571
|
}
|
|
572
|
-
|
|
573
|
-
const r =
|
|
574
|
-
return r.length > 0 && (r[r.length - 1].lastWithThoughts = !0),
|
|
572
|
+
n.parts.length > 0 && i.push(n);
|
|
573
|
+
const r = i.filter((o) => o.hasThoughts);
|
|
574
|
+
return r.length > 0 && (r[r.length - 1].lastWithThoughts = !0), i;
|
|
575
575
|
}
|
|
576
576
|
isFunctionCall(t) {
|
|
577
|
-
return t ==
|
|
577
|
+
return t == y.FunctionCall || t == y.PartialFunctionCall;
|
|
578
578
|
}
|
|
579
579
|
isFunctionResponse(t) {
|
|
580
|
-
return t ==
|
|
580
|
+
return t == y.FunctionResponse;
|
|
581
581
|
}
|
|
582
582
|
// Computes the next interaction from a server event. Pure with respect to
|
|
583
583
|
// `prev` — no part or array on the prior tree is mutated; modified entities
|
|
@@ -585,31 +585,53 @@ ${i.value}
|
|
|
585
585
|
// new tree as the last step, so snapshots already handed out to throttled
|
|
586
586
|
// subscribers can't diverge from the live state.
|
|
587
587
|
merge(t) {
|
|
588
|
-
var
|
|
589
|
-
const e = this.interaction, s = [],
|
|
588
|
+
var X, Z, V, tt, et;
|
|
589
|
+
const e = this.interaction, s = [], i = [], n = A.FlatParts(t == null ? void 0 : t.parts), r = e.parts[e.parts.length - 1] ?? null;
|
|
590
590
|
let l = !1;
|
|
591
|
-
|
|
592
|
-
let
|
|
591
|
+
n && (l = !r || n.mustPush || n.mustPush === !1 && (n.eventType !== (r == null ? void 0 : r.eventType) || ((X = n == null ? void 0 : n.functionDetails) == null ? void 0 : X.id) !== ((Z = r.functionDetails) == null ? void 0 : Z.id)));
|
|
592
|
+
let o = e.parts, u = e.functionMap ?? /* @__PURE__ */ new Map(), d = !e.functionMap;
|
|
593
593
|
const h = /* @__PURE__ */ g(() => {
|
|
594
594
|
d || (u = new Map(u), d = !0);
|
|
595
|
-
}, "cloneFunctionMap"),
|
|
596
|
-
|
|
595
|
+
}, "cloneFunctionMap"), v = /* @__PURE__ */ g(() => {
|
|
596
|
+
o === e.parts && (o = e.parts.slice());
|
|
597
597
|
}, "clonePartsIfShared");
|
|
598
598
|
let m = !1;
|
|
599
|
-
if (
|
|
600
|
-
const
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
599
|
+
if ((n == null ? void 0 : n.eventType) === y.FunctionClientOutput && !!((V = n.functionDetails) != null && V.id) && n) {
|
|
600
|
+
const f = n.functionDetails.id, C = n.functionDetails.clientOutput, E = o.findIndex((w) => {
|
|
601
|
+
var S;
|
|
602
|
+
return ((S = w.functionDetails) == null ? void 0 : S.id) === f;
|
|
603
|
+
});
|
|
604
|
+
if (E > -1) {
|
|
605
|
+
const w = o[E], S = {
|
|
606
|
+
...w,
|
|
607
|
+
functionDetails: {
|
|
608
|
+
...w.functionDetails,
|
|
609
|
+
clientOutput: C ?? w.functionDetails.clientOutput
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
v(), o[E] = S, h(), u.set(f, S), s.push(S);
|
|
613
|
+
} else {
|
|
614
|
+
const w = {
|
|
615
|
+
...n,
|
|
616
|
+
id: o.length + 1 + "-" + e.interactionId,
|
|
617
|
+
functionDetails: { ...n.functionDetails, silent: !0 }
|
|
618
|
+
};
|
|
619
|
+
v(), o = o === e.parts ? e.parts.slice() : o, o.push(w), h(), u.set(f, w);
|
|
620
|
+
}
|
|
621
|
+
} else if (l && n) {
|
|
622
|
+
const f = this.isFunctionCall(n.eventType) || this.isFunctionResponse(n.eventType), C = f ? (tt = n.functionDetails) == null ? void 0 : tt.id : void 0;
|
|
623
|
+
f && !C && console.error("Got isCall or isResponse without a callId", n);
|
|
624
|
+
const E = C ? u.get(C) : void 0;
|
|
625
|
+
if (E && C && n.functionDetails) {
|
|
626
|
+
const w = o.findIndex((gt) => {
|
|
627
|
+
var st;
|
|
628
|
+
return ((st = gt.functionDetails) == null ? void 0 : st.id) === C;
|
|
629
|
+
}), S = w > -1 ? o[w] : E, N = {
|
|
630
|
+
...S,
|
|
631
|
+
eventType: n.eventType,
|
|
610
632
|
functionDetails: {
|
|
611
|
-
id:
|
|
612
|
-
name:
|
|
633
|
+
id: S.functionDetails.id,
|
|
634
|
+
name: n.functionDetails.name ?? S.functionDetails.name,
|
|
613
635
|
// Take the parsed args from the incoming event when
|
|
614
636
|
// present (the full FunctionCall carries them), fall
|
|
615
637
|
// back to what was already on the part. Previously
|
|
@@ -618,102 +640,102 @@ ${i.value}
|
|
|
618
640
|
// args off every full FunctionCall fold because the
|
|
619
641
|
// PartialFunctionCall stream only accumulates raw
|
|
620
642
|
// JSON in `.text` — `.args` stayed undefined.
|
|
621
|
-
args:
|
|
622
|
-
response:
|
|
623
|
-
status:
|
|
624
|
-
start:
|
|
625
|
-
end:
|
|
643
|
+
args: n.functionDetails.args ?? S.functionDetails.args,
|
|
644
|
+
response: n.functionDetails.response,
|
|
645
|
+
status: n.functionDetails.status ?? "Composing",
|
|
646
|
+
start: n.functionDetails.start ?? S.functionDetails.start,
|
|
647
|
+
end: n.functionDetails.end ?? S.functionDetails.end,
|
|
626
648
|
// true-wins: a UI call has multiple reps (streaming part with isUi, the
|
|
627
649
|
// persisted FunctionCall, the result) and they interleave. `??` let a later
|
|
628
650
|
// `false`/`undefined` rep clobber an earlier `true`; OR-ing keeps it sticky.
|
|
629
|
-
isUi:
|
|
651
|
+
isUi: n.functionDetails.isUi === !0 || S.functionDetails.isUi === !0,
|
|
630
652
|
// Keep the call's friendly args summary when the result event (which has none) folds in.
|
|
631
|
-
argsDescription:
|
|
653
|
+
argsDescription: n.functionDetails.argsDescription ?? S.functionDetails.argsDescription,
|
|
632
654
|
// The tool's client-only payload rides the RESULT event; keep it sticky so a
|
|
633
655
|
// later rep without one can't clobber it. This is what a uiTool renderer reads.
|
|
634
|
-
clientOutput:
|
|
656
|
+
clientOutput: n.functionDetails.clientOutput ?? S.functionDetails.clientOutput
|
|
635
657
|
}
|
|
636
658
|
};
|
|
637
|
-
h(), u.set(
|
|
659
|
+
h(), u.set(C, N), N.eventType === y.FunctionResponse && this.eventBusService.gatewayEmitFunctionResponse(N.functionDetails), s.push(N), w > -1 && (v(), o[w] = N);
|
|
638
660
|
} else {
|
|
639
|
-
if (
|
|
640
|
-
const
|
|
661
|
+
if (C && n.functionDetails && !E && (h(), u.set(C, n)), r && r.textAppendable) {
|
|
662
|
+
const S = {
|
|
641
663
|
...r,
|
|
642
664
|
ended: /* @__PURE__ */ new Date(),
|
|
643
665
|
isStillWriting: !1
|
|
644
666
|
};
|
|
645
|
-
|
|
667
|
+
v(), o[o.length - 1] = S, s.push(S);
|
|
646
668
|
}
|
|
647
|
-
const
|
|
648
|
-
...
|
|
649
|
-
id:
|
|
650
|
-
isStillWriting:
|
|
669
|
+
const w = {
|
|
670
|
+
...n,
|
|
671
|
+
id: o.length + 1 + "-" + e.interactionId,
|
|
672
|
+
isStillWriting: n.textAppendable,
|
|
651
673
|
partial: t.partial
|
|
652
674
|
};
|
|
653
|
-
(
|
|
675
|
+
(et = w.functionDetails) != null && et.silent || s.push(w), o = [...o, w], m = !0;
|
|
654
676
|
}
|
|
655
677
|
}
|
|
656
|
-
let
|
|
657
|
-
if (
|
|
658
|
-
const
|
|
659
|
-
...
|
|
678
|
+
let I = o[o.length - 1] ?? null;
|
|
679
|
+
if (I && n && n.textAppendable) {
|
|
680
|
+
const f = {
|
|
681
|
+
...I,
|
|
660
682
|
partial: t.partial,
|
|
661
|
-
textDetails:
|
|
683
|
+
textDetails: I.textDetails ? { ...I.textDetails } : { version: 0 }
|
|
662
684
|
};
|
|
663
|
-
let
|
|
685
|
+
let C = !1;
|
|
664
686
|
if (t.partial) {
|
|
665
687
|
try {
|
|
666
|
-
|
|
667
|
-
} catch (
|
|
668
|
-
console.error("Error here",
|
|
688
|
+
f.textDetails.version++, m || (f.text = (I.text ?? "") + (n.text ?? ""));
|
|
689
|
+
} catch (E) {
|
|
690
|
+
console.error("Error here", E.toString());
|
|
669
691
|
}
|
|
670
|
-
|
|
671
|
-
...
|
|
672
|
-
text:
|
|
673
|
-
},
|
|
692
|
+
f.textLastChunk = n.text ?? "", f.isStillWriting = !0, C = !0, n.thoughtDetails && f.thoughtDetails && n.thoughtDetails.text !== f.thoughtDetails.text && (f.thoughtDetails = {
|
|
693
|
+
...f.thoughtDetails,
|
|
694
|
+
text: f.thoughtDetails.text + n.thoughtDetails.text
|
|
695
|
+
}, f.thoughtLastChunk = n.thoughtDetails.text);
|
|
674
696
|
} else
|
|
675
|
-
|
|
676
|
-
...
|
|
677
|
-
text:
|
|
678
|
-
}),
|
|
679
|
-
|
|
697
|
+
f.isStillWriting = !1, f.text = n.text ?? "", f.textDetails.version++, n.thoughtDetails && (f.thoughtDetails = {
|
|
698
|
+
...n.thoughtDetails,
|
|
699
|
+
text: n.thoughtDetails.text.trim()
|
|
700
|
+
}), C = !l;
|
|
701
|
+
v(), o[o.length - 1] = f, I = f, C && s.push(f);
|
|
680
702
|
}
|
|
681
|
-
let
|
|
703
|
+
let M = e.artifactData ?? [];
|
|
682
704
|
if (t.llmArtifacts && t.llmArtifacts.length > 0) {
|
|
683
|
-
let
|
|
684
|
-
for (const
|
|
685
|
-
const
|
|
686
|
-
|
|
687
|
-
const
|
|
688
|
-
|
|
705
|
+
let f = !1;
|
|
706
|
+
for (const C of t.llmArtifacts) {
|
|
707
|
+
const E = C.toArtifact();
|
|
708
|
+
f || (M = M.slice(), f = !0);
|
|
709
|
+
const w = M.findIndex((S) => S.id === E.id);
|
|
710
|
+
w === -1 ? M.push(E) : M[w] = E;
|
|
689
711
|
}
|
|
690
712
|
}
|
|
691
|
-
const
|
|
713
|
+
const L = {
|
|
692
714
|
...e,
|
|
693
715
|
version: e.version + 1,
|
|
694
|
-
parts:
|
|
695
|
-
artifactData:
|
|
716
|
+
parts: o,
|
|
717
|
+
artifactData: M,
|
|
696
718
|
functionMap: u,
|
|
697
719
|
turn_complete: t.turn_complete,
|
|
698
720
|
partial: t.partial,
|
|
699
721
|
asyncFinalResponse: t.asyncFinalResponse
|
|
700
722
|
};
|
|
701
|
-
return this.interaction =
|
|
702
|
-
updatedInteraction:
|
|
723
|
+
return this.interaction = L, {
|
|
724
|
+
updatedInteraction: L,
|
|
703
725
|
updatedParts: s,
|
|
704
|
-
newArtifacts:
|
|
705
|
-
mainBranch:
|
|
726
|
+
newArtifacts: i,
|
|
727
|
+
mainBranch: L,
|
|
706
728
|
analyticsBranch: null,
|
|
707
729
|
analyticsBranchPartsChanged: null,
|
|
708
730
|
mainBranchPartsChanged: s
|
|
709
731
|
};
|
|
710
732
|
}
|
|
711
733
|
};
|
|
712
|
-
g(
|
|
713
|
-
let b =
|
|
714
|
-
const
|
|
715
|
-
constructor(t, e, s,
|
|
716
|
-
a(this, "base_production_url",
|
|
734
|
+
g(z, "InteractionService");
|
|
735
|
+
let b = z;
|
|
736
|
+
const kt = 1200 * 1e3, D = class D {
|
|
737
|
+
constructor(t, e, s, i, n, r, l, o, u, d = St.Interactive) {
|
|
738
|
+
a(this, "base_production_url", pt() ?? "https://agent.tripapi.com.br");
|
|
717
739
|
a(this, "base_url_local", "http://localagent:8000");
|
|
718
740
|
a(this, "base_url");
|
|
719
741
|
a(this, "isLocal", !1);
|
|
@@ -788,7 +810,7 @@ const Nt = 1200 * 1e3, D = class D {
|
|
|
788
810
|
a(this, "subAgentInteractionServices", /* @__PURE__ */ new Map());
|
|
789
811
|
a(this, "lastThorttledTimeout", null);
|
|
790
812
|
a(this, "lastPingStatus", !1);
|
|
791
|
-
this.user = t, this.config =
|
|
813
|
+
this.user = t, this.config = n, this.rawJwt = t.access_token, this.base_url = i, this.eventBusService = e, this.sessionId = u, this.runMode = d, this.artifactService = s, this.sessionState = r.getState(), this.notificationPort = l, this.storageService = o, r.subscribe((h, v) => {
|
|
792
814
|
this.sessionState = h;
|
|
793
815
|
});
|
|
794
816
|
}
|
|
@@ -859,11 +881,11 @@ const Nt = 1200 * 1e3, D = class D {
|
|
|
859
881
|
if (e && this.currentIS)
|
|
860
882
|
return this.currentIS.interaction.isSuspended = !1, this.currentIS.interaction.interactionQuestion += " + " + t, this.currentIS.interaction;
|
|
861
883
|
this.msg_order += 1;
|
|
862
|
-
let
|
|
863
|
-
s && (
|
|
864
|
-
let
|
|
884
|
+
let i = this.getNewInteractionId();
|
|
885
|
+
s && (i = s);
|
|
886
|
+
let n = {
|
|
865
887
|
created: /* @__PURE__ */ new Date(),
|
|
866
|
-
interactionId:
|
|
888
|
+
interactionId: i,
|
|
867
889
|
artifactData: [],
|
|
868
890
|
partial: !0,
|
|
869
891
|
sessionId: this.sessionId,
|
|
@@ -873,7 +895,7 @@ const Nt = 1200 * 1e3, D = class D {
|
|
|
873
895
|
functionMap: /* @__PURE__ */ new Map(),
|
|
874
896
|
interactionQuestion: t
|
|
875
897
|
};
|
|
876
|
-
return this.interactionsMap.set(
|
|
898
|
+
return this.interactionsMap.set(n.interactionId, n), this.currentIS = new b(n, this.eventBusService), this.interactionsServiceMap.set(n.interactionId, this.currentIS), n;
|
|
877
899
|
}
|
|
878
900
|
getInteractions() {
|
|
879
901
|
return Array.from(this.interactionsMap.values());
|
|
@@ -921,8 +943,8 @@ const Nt = 1200 * 1e3, D = class D {
|
|
|
921
943
|
s ? (console.warn("GOT A running promise", t), e = s) : (e = this.artifactService.getArtifact(t), this.runningRequests.set(t, e));
|
|
922
944
|
try {
|
|
923
945
|
return await e;
|
|
924
|
-
} catch (
|
|
925
|
-
return console.error("Error awating on HTML promise",
|
|
946
|
+
} catch (i) {
|
|
947
|
+
return console.error("Error awating on HTML promise", i.toString()), null;
|
|
926
948
|
} finally {
|
|
927
949
|
this.runningRequests.delete(t);
|
|
928
950
|
}
|
|
@@ -938,8 +960,8 @@ const Nt = 1200 * 1e3, D = class D {
|
|
|
938
960
|
return !1;
|
|
939
961
|
}
|
|
940
962
|
getOrCreateSubAgentInteraction(t, e, s) {
|
|
941
|
-
let
|
|
942
|
-
return (!
|
|
963
|
+
let i = this.subAgentInteractions.get(t), n = this.subAgentInteractionServices.get(t);
|
|
964
|
+
return (!i || !n) && (i = {
|
|
943
965
|
created: /* @__PURE__ */ new Date(),
|
|
944
966
|
interactionId: e,
|
|
945
967
|
artifactData: [],
|
|
@@ -949,7 +971,7 @@ const Nt = 1200 * 1e3, D = class D {
|
|
|
949
971
|
version: 0,
|
|
950
972
|
functionMap: /* @__PURE__ */ new Map(),
|
|
951
973
|
interactionQuestion: s ?? t
|
|
952
|
-
},
|
|
974
|
+
}, n = new b(i, this.eventBusService), this.subAgentInteractions.set(t, i), this.subAgentInteractionServices.set(t, n)), { interaction: i, service: n };
|
|
953
975
|
}
|
|
954
976
|
handleSubAgentEvent(t) {
|
|
955
977
|
const e = t.subAgentId, { service: s } = this.getOrCreateSubAgentInteraction(e, t.interactionId, t.subAgentName);
|
|
@@ -960,10 +982,10 @@ const Nt = 1200 * 1e3, D = class D {
|
|
|
960
982
|
continue;
|
|
961
983
|
}
|
|
962
984
|
}
|
|
963
|
-
const
|
|
964
|
-
if (!
|
|
965
|
-
const
|
|
966
|
-
this.sessionState.setSubAgentMessage(e,
|
|
985
|
+
const i = s.merge(t);
|
|
986
|
+
if (!i) return;
|
|
987
|
+
const n = t.turn_complete ?? !1;
|
|
988
|
+
this.sessionState.setSubAgentMessage(e, i.updatedInteraction, t.subAgentName), n && this.sessionState.completeSubAgent(e);
|
|
967
989
|
}
|
|
968
990
|
async Message(t) {
|
|
969
991
|
try {
|
|
@@ -980,14 +1002,14 @@ const Nt = 1200 * 1e3, D = class D {
|
|
|
980
1002
|
}
|
|
981
1003
|
if (e.serverError && console.error("Stream error: ", e.serverError), e.endMessageData && this.eventBusService.gatewayEmitEndMessageData(e.endMessageData), e) {
|
|
982
1004
|
if (e.llmArtifacts && e.llmArtifacts.length > 0)
|
|
983
|
-
for (const
|
|
984
|
-
const r =
|
|
1005
|
+
for (const n of e.llmArtifacts) {
|
|
1006
|
+
const r = n.toArtifact();
|
|
985
1007
|
this.artifactService.addToCache(r), this.eventBusService.artifactEmitGenerated(r);
|
|
986
1008
|
}
|
|
987
1009
|
if (e.parts && e.parts.length > 0) {
|
|
988
|
-
for (const
|
|
989
|
-
if (
|
|
990
|
-
this.localEmitToolEvent(
|
|
1010
|
+
for (const n of e.parts)
|
|
1011
|
+
if (n.toolDetails) {
|
|
1012
|
+
this.localEmitToolEvent(n.toolDetails);
|
|
991
1013
|
continue;
|
|
992
1014
|
}
|
|
993
1015
|
}
|
|
@@ -1000,21 +1022,21 @@ const Nt = 1200 * 1e3, D = class D {
|
|
|
1000
1022
|
return;
|
|
1001
1023
|
}
|
|
1002
1024
|
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));
|
|
1003
|
-
const
|
|
1004
|
-
|
|
1005
|
-
const r = s.updatedInteraction.artifactData.filter((
|
|
1025
|
+
const i = e.artifactsDelta;
|
|
1026
|
+
i && i.forEach((n) => {
|
|
1027
|
+
const r = s.updatedInteraction.artifactData.filter((o) => o.id == n);
|
|
1006
1028
|
let l = null;
|
|
1007
|
-
r && r.length > 0 && (l = r[0], l.loadingPromise = this.asyncLoadArtifact(
|
|
1029
|
+
r && r.length > 0 && (l = r[0], l.loadingPromise = this.asyncLoadArtifact(n).then((o) => (o === null ? console.error("Error trying to load artifact id:", l == null ? void 0 : l.id, "Artifact is null") : this.eventBusService.artifactEmitGenerated(o), o)).catch((o) => (console.error("Error trying to load artifact id:", l == null ? void 0 : l.id, o.toString()), null)));
|
|
1008
1030
|
});
|
|
1009
1031
|
}
|
|
1010
1032
|
} catch (e) {
|
|
1011
1033
|
if (this.getCurrentInteractionId()) {
|
|
1012
|
-
const s =
|
|
1013
|
-
if (console.error("Error event: ", JSON.stringify(s, void 0, 4)), !
|
|
1034
|
+
const s = ut.createErrorEvent("OnMessage error: " + e.toString(), this.getCurrentInteractionId() ?? "Empty Current"), i = this.updateMap(s);
|
|
1035
|
+
if (console.error("Error event: ", JSON.stringify(s, void 0, 4)), !i) {
|
|
1014
1036
|
console.error("Error event, could not update interaction: ", JSON.stringify(s, void 0, 4));
|
|
1015
1037
|
return;
|
|
1016
1038
|
}
|
|
1017
|
-
this.localEmitMessage(
|
|
1039
|
+
this.localEmitMessage(i.updatedInteraction);
|
|
1018
1040
|
}
|
|
1019
1041
|
}
|
|
1020
1042
|
}
|
|
@@ -1038,8 +1060,8 @@ const Nt = 1200 * 1e3, D = class D {
|
|
|
1038
1060
|
this.sessionState.setCurrentMessage(t), this.lastCurrentMessageUpdate = e, this.pendingCurrentMessage = null, this.eventBusService.gatewayEmitMessage(t, s);
|
|
1039
1061
|
}
|
|
1040
1062
|
localEmitMessage(t, e) {
|
|
1041
|
-
const s = (/* @__PURE__ */ new Date()).getTime(),
|
|
1042
|
-
t.partial === !1 ||
|
|
1063
|
+
const s = (/* @__PURE__ */ new Date()).getTime(), i = s - this.lastCurrentMessageUpdate;
|
|
1064
|
+
t.partial === !1 || i >= D.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(() => {
|
|
1043
1065
|
var r, l;
|
|
1044
1066
|
this.pendingCurrentMessage && (((r = this.pendingCurrentMessage) == null ? void 0 : r.version) ?? 0) > (((l = this.sessionState.currentMessage) == null ? void 0 : l.version) ?? 0) && (this.doEmitMessage(this.pendingCurrentMessage, s, e), this.lastThorttledTimeout = null);
|
|
1045
1067
|
}, D.CURRENT_MSG_THROTTLE_MS * 2));
|
|
@@ -1062,35 +1084,35 @@ const Nt = 1200 * 1e3, D = class D {
|
|
|
1062
1084
|
cancelPendingCurrentMessage() {
|
|
1063
1085
|
this.lastThorttledTimeout && (clearTimeout(this.lastThorttledTimeout), this.lastThorttledTimeout = null), this.pendingCurrentMessage = null;
|
|
1064
1086
|
}
|
|
1065
|
-
async turnComplete(t, e, s,
|
|
1087
|
+
async turnComplete(t, e, s, i) {
|
|
1066
1088
|
this.cancelPendingCurrentMessage(), this.sessionState.setNewMessage(e), this.eventBusService.gatewayEmitTurnComplete(t, e), this.interactionCallIds.delete(t), this.sessionState.setLastToolEvent(null), this.localEmitToolEvent({
|
|
1067
1089
|
eventName: "todolistUpdated",
|
|
1068
1090
|
eventData: "",
|
|
1069
|
-
subAgentId:
|
|
1091
|
+
subAgentId: i
|
|
1070
1092
|
}), this.sessionState.setTurnOpen(!1);
|
|
1071
1093
|
}
|
|
1072
1094
|
async handlePing() {
|
|
1073
|
-
return Date.now() - this.lastPing.getTime() >
|
|
1095
|
+
return Date.now() - this.lastPing.getTime() > kt ? await this.ping() ? (this.lastPing = /* @__PURE__ */ new Date(), this.lastPingStatus = !0, !0) : (this.lastPingStatus = !1, !1) : (this.lastPingStatus = !0, !0);
|
|
1074
1096
|
}
|
|
1075
1097
|
async sendMessage(t, e) {
|
|
1076
|
-
let s = this.getInteractions().length,
|
|
1077
|
-
this.sendStatusMessage(t.data, [
|
|
1098
|
+
let s = this.getInteractions().length, i = A.createWaiting(!0, !0, "Overall", /* @__PURE__ */ new Date());
|
|
1099
|
+
this.sendStatusMessage(t.data, [i], s.toString() + "1");
|
|
1078
1100
|
try {
|
|
1079
|
-
const { promptAsString:
|
|
1080
|
-
this.sessionState.onRenderPrompt && (t.data = r, t.friendlyMessage =
|
|
1081
|
-
const l = await this.sendMessageInternal(t, e),
|
|
1082
|
-
this.storageService.storePrompt(
|
|
1101
|
+
const { promptAsString: n, json: r } = this.sessionState.onRenderPrompt ? this.sessionState.onRenderPrompt(t.data) : { promptAsString: t.data, json: void 0 };
|
|
1102
|
+
this.sessionState.onRenderPrompt && (t.data = r, t.friendlyMessage = n);
|
|
1103
|
+
const l = await this.sendMessageInternal(t, e), o = Pt.createPrompt(n ?? "", (r == null ? void 0 : r.toString()) ?? {});
|
|
1104
|
+
this.storageService.storePrompt(o);
|
|
1083
1105
|
const u = A.fromText("Planejando próximos passos");
|
|
1084
|
-
return this.sendStatusMessage(t.data, [
|
|
1085
|
-
} catch (
|
|
1086
|
-
return this.eventBusService.ChatEmitMessageError((
|
|
1106
|
+
return this.sendStatusMessage(t.data, [i, u], s.toString() + "1"), l != null && l.success ? this.eventBusService.ChatEmitMessageSent(t.data, l.interaction) : this.eventBusService.ChatEmitMessageError((l == null ? void 0 : l.error) ?? ""), l;
|
|
1107
|
+
} catch (n) {
|
|
1108
|
+
return this.eventBusService.ChatEmitMessageError((n == null ? void 0 : n.toString()) ?? ""), {
|
|
1087
1109
|
success: !1,
|
|
1088
1110
|
interaction: {
|
|
1089
1111
|
artifactData: [],
|
|
1090
1112
|
created: /* @__PURE__ */ new Date(),
|
|
1091
1113
|
interactionId: "",
|
|
1092
1114
|
partial: !1,
|
|
1093
|
-
parts: [A.fromError((
|
|
1115
|
+
parts: [A.fromError((n == null ? void 0 : n.toString()) ?? "")],
|
|
1094
1116
|
version: 0
|
|
1095
1117
|
}
|
|
1096
1118
|
};
|
|
@@ -1107,9 +1129,9 @@ const Nt = 1200 * 1e3, D = class D {
|
|
|
1107
1129
|
t.partial = !0, t.turn_complete = !1, t.asyncFinalResponse = !1, t.interactionId = t.interactionId, this.eventBusService.gatewayEmitTurnOpen(t.interactionId), this.Message(t);
|
|
1108
1130
|
}
|
|
1109
1131
|
sendStatusMessage(t, e, s) {
|
|
1110
|
-
var
|
|
1111
|
-
let
|
|
1112
|
-
((r = (
|
|
1132
|
+
var n, r;
|
|
1133
|
+
let i;
|
|
1134
|
+
((r = (n = this.currentIS) == null ? void 0 : n.interaction) == null ? void 0 : r.turn_complete) === !1 ? (i = Nt.cloneDeep(this.currentIS.interaction), i.parts.push(...e)) : i = {
|
|
1113
1135
|
interactionId: "tmp" + s,
|
|
1114
1136
|
created: /* @__PURE__ */ new Date(),
|
|
1115
1137
|
partial: !0,
|
|
@@ -1118,7 +1140,7 @@ const Nt = 1200 * 1e3, D = class D {
|
|
|
1118
1140
|
parts: e,
|
|
1119
1141
|
interactionQuestion: t,
|
|
1120
1142
|
artifactData: []
|
|
1121
|
-
}, this.localEmitMessage(
|
|
1143
|
+
}, this.localEmitMessage(i);
|
|
1122
1144
|
}
|
|
1123
1145
|
clearStatus() {
|
|
1124
1146
|
}
|
|
@@ -1132,13 +1154,13 @@ const Nt = 1200 * 1e3, D = class D {
|
|
|
1132
1154
|
}
|
|
1133
1155
|
}
|
|
1134
1156
|
getNewInteractionId() {
|
|
1135
|
-
const e =
|
|
1157
|
+
const e = At(/* @__PURE__ */ new Date(), "MMM_dd_HH_mm_ss");
|
|
1136
1158
|
return `${this.msg_order}_${e}`;
|
|
1137
1159
|
}
|
|
1138
1160
|
};
|
|
1139
1161
|
g(D, "AgentGatewayService"), a(D, "SUSPENSION_MSG", "SUSPEND"), a(D, "CURRENT_MSG_THROTTLE_MS", 20);
|
|
1140
|
-
let
|
|
1141
|
-
const
|
|
1162
|
+
let $ = D;
|
|
1163
|
+
const W = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, bt = 3e4, Lt = 2, Ut = 0.2, ot = 2, j = class j {
|
|
1142
1164
|
constructor(t = "ws://localhost:8000", e) {
|
|
1143
1165
|
a(this, "ws", null);
|
|
1144
1166
|
a(this, "stats");
|
|
@@ -1219,7 +1241,7 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
|
|
|
1219
1241
|
* Cleared by `disconnect()`.
|
|
1220
1242
|
*/
|
|
1221
1243
|
a(this, "hasEverReceivedPacket", !1);
|
|
1222
|
-
this.baseUrl = t, this.getToken = e, this.pingPongStack = [], this.events = [], this.firstTokenInteractions = /* @__PURE__ */ new Set(), this.streamingResponseSerializer =
|
|
1244
|
+
this.baseUrl = t, this.getToken = e, this.pingPongStack = [], this.events = [], this.firstTokenInteractions = /* @__PURE__ */ new Set(), this.streamingResponseSerializer = Tt(), console.log("SOCKET INSTACE", wt()), this.stats = {
|
|
1223
1245
|
eventCount: 0,
|
|
1224
1246
|
unknonwCount: 0,
|
|
1225
1247
|
buffer: [],
|
|
@@ -1237,11 +1259,11 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
|
|
|
1237
1259
|
return new Promise(async (e, s) => {
|
|
1238
1260
|
var m;
|
|
1239
1261
|
this.intentionalDisconnect = !1;
|
|
1240
|
-
const
|
|
1241
|
-
|
|
1242
|
-
const
|
|
1243
|
-
|
|
1244
|
-
const l = r.length > 0 ? `?${r.join("&")}` : "",
|
|
1262
|
+
const i = this._internalReconnect;
|
|
1263
|
+
i || (this.cancelPendingReconnect(), this.isReconnecting = !1, this.reconnectAttempts = 0, this.lastSeq = -1), this._internalReconnect = !1;
|
|
1264
|
+
const n = (m = this.getToken) == null ? void 0 : m.call(this), r = [];
|
|
1265
|
+
n && r.push(`access_token=${encodeURIComponent(n)}`), t && this.lastSeq >= 0 && r.push(`lastSeq=${this.lastSeq}`);
|
|
1266
|
+
const l = r.length > 0 ? `?${r.join("&")}` : "", o = this.baseUrl.replace(/^http:\/\//, "ws://").replace(/^https:\/\//, "wss://"), u = `${o}/ws/connect/${t ?? ""}${l}`, d = `${o}/ws/connect/${t ?? ""}` + (i && t && this.lastSeq >= 0 ? ` (resume lastSeq=${this.lastSeq})` : "");
|
|
1245
1267
|
if (console.log("Connecting to ", d), this.ws) {
|
|
1246
1268
|
this.ws.onopen = null, this.ws.onmessage = null, this.ws.onerror = null, this.ws.onclose = null;
|
|
1247
1269
|
try {
|
|
@@ -1250,37 +1272,37 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
|
|
|
1250
1272
|
}
|
|
1251
1273
|
this.ws = null;
|
|
1252
1274
|
}
|
|
1253
|
-
this.ws = new WebSocket(u), console.log("[WebSocket] Connecting to:", `${
|
|
1275
|
+
this.ws = new WebSocket(u), console.log("[WebSocket] Connecting to:", `${o}/ws/connect/${t ?? ""}`);
|
|
1254
1276
|
let h = !1;
|
|
1255
1277
|
this.ws.onopen = () => {
|
|
1256
1278
|
console.log("[WebSocket] Connected");
|
|
1257
|
-
const
|
|
1258
|
-
this.isReconnecting = !1, this.reconnectAttempts = 0, this.pingPongStack.push((/* @__PURE__ */ new Date()).getTime()), this.ping(), this.monitor(), this.onOpen && this.onOpen(),
|
|
1259
|
-
}, this.ws.onmessage = (
|
|
1279
|
+
const p = this.isReconnecting;
|
|
1280
|
+
this.isReconnecting = !1, this.reconnectAttempts = 0, this.pingPongStack.push((/* @__PURE__ */ new Date()).getTime()), this.ping(), this.monitor(), this.onOpen && this.onOpen(), p && this.onReconnected && this.onReconnected(t ?? this.lastKnownSessionId ?? "");
|
|
1281
|
+
}, this.ws.onmessage = (p) => {
|
|
1260
1282
|
try {
|
|
1261
1283
|
this.lastActivity = (/* @__PURE__ */ new Date()).getTime();
|
|
1262
|
-
const
|
|
1263
|
-
if (!
|
|
1284
|
+
const I = this.streamingResponseSerializer.parse(p.data);
|
|
1285
|
+
if (!I)
|
|
1264
1286
|
throw "Error parsing event JSON";
|
|
1265
|
-
const
|
|
1266
|
-
!h && (
|
|
1267
|
-
} catch (
|
|
1268
|
-
console.error("[WebSocket] Error parsing message:",
|
|
1287
|
+
const M = this.handleMessage(I, p.data);
|
|
1288
|
+
!h && (M != null && M.timestamp) && (h = !0, this.hasEverReceivedPacket = !0);
|
|
1289
|
+
} catch (I) {
|
|
1290
|
+
console.error("[WebSocket] Error parsing message:", I);
|
|
1269
1291
|
}
|
|
1270
|
-
}, this.ws.onerror = (
|
|
1271
|
-
console.error("[WebSocket] Error:",
|
|
1272
|
-
}, this.ws.onclose = (
|
|
1273
|
-
console.log("[WebSocket] Closed:",
|
|
1274
|
-
const
|
|
1275
|
-
if (this.sessionId = void 0, (h || this.hasEverReceivedPacket) && this.shouldAttemptReconnect(
|
|
1276
|
-
this.scheduleReconnect(
|
|
1292
|
+
}, this.ws.onerror = (p) => {
|
|
1293
|
+
console.error("[WebSocket] Error:", p), this.onError && this.onError("WebSocket error");
|
|
1294
|
+
}, this.ws.onclose = (p) => {
|
|
1295
|
+
console.log("[WebSocket] Closed:", p.code, p.reason), this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingPongStack = [];
|
|
1296
|
+
const I = this.sessionId ?? this.lastKnownSessionId;
|
|
1297
|
+
if (this.sessionId = void 0, (h || this.hasEverReceivedPacket) && this.shouldAttemptReconnect(p.code)) {
|
|
1298
|
+
this.scheduleReconnect(I, p.code, p.reason);
|
|
1277
1299
|
return;
|
|
1278
1300
|
}
|
|
1279
|
-
this.isReconnecting = !1, this.reconnectAttempts = 0, this.onClose && this.onClose(
|
|
1301
|
+
this.isReconnecting = !1, this.reconnectAttempts = 0, this.onClose && this.onClose(p.code, p.reason);
|
|
1280
1302
|
};
|
|
1281
|
-
let
|
|
1282
|
-
for (this.sessionId = void 0; !this.sessionId &&
|
|
1283
|
-
console.log("Aguardando session Id"), await this.sleep(400),
|
|
1303
|
+
let v = 0;
|
|
1304
|
+
for (this.sessionId = void 0; !this.sessionId && v < 30; )
|
|
1305
|
+
console.log("Aguardando session Id"), await this.sleep(400), v++;
|
|
1284
1306
|
this.sessionId ? (console.log("SUCCESS - GOT SESSION ID", this.sessionId), this.lastKnownSessionId = this.sessionId, e(this.sessionId)) : s("After 12 seconds no session id was generated");
|
|
1285
1307
|
});
|
|
1286
1308
|
}
|
|
@@ -1294,36 +1316,36 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
|
|
|
1294
1316
|
* - 4000-4099 reserved for app-level fatal codes from the server
|
|
1295
1317
|
*/
|
|
1296
1318
|
shouldAttemptReconnect(t) {
|
|
1297
|
-
return !(this.intentionalDisconnect || t ===
|
|
1319
|
+
return !(this.intentionalDisconnect || t === W || t === _t || t === 1e3 || t === 1008);
|
|
1298
1320
|
}
|
|
1299
1321
|
cancelPendingReconnect() {
|
|
1300
1322
|
this.reconnectTimer && (clearTimeout(this.reconnectTimer), this.reconnectTimer = null);
|
|
1301
1323
|
}
|
|
1302
1324
|
computeBackoffDelay() {
|
|
1303
|
-
const t =
|
|
1325
|
+
const t = Rt * Math.pow(Lt, this.reconnectAttempts), e = Math.min(t, bt), s = e * Ut * (Math.random() * 2 - 1);
|
|
1304
1326
|
return Math.max(0, Math.round(e + s));
|
|
1305
1327
|
}
|
|
1306
1328
|
scheduleReconnect(t, e, s) {
|
|
1307
|
-
var
|
|
1329
|
+
var n, r;
|
|
1308
1330
|
if (this.intentionalDisconnect) return;
|
|
1309
|
-
if (this.reconnectAttempts >=
|
|
1331
|
+
if (this.reconnectAttempts >= ot) {
|
|
1310
1332
|
console.warn(
|
|
1311
1333
|
`[WebSocket] Reconnect exhausted after ${this.reconnectAttempts} attempts (last code=${e}, reason="${s}"). Handing off to outer state manager.`
|
|
1312
|
-
), this.isReconnecting = !1, this.reconnectAttempts = 0, this.cancelPendingReconnect(), (
|
|
1334
|
+
), this.isReconnecting = !1, this.reconnectAttempts = 0, this.cancelPendingReconnect(), (n = this.onClose) == null || n.call(this, e, s);
|
|
1313
1335
|
return;
|
|
1314
1336
|
}
|
|
1315
1337
|
this.isReconnecting = !0, this.reconnectAttempts += 1;
|
|
1316
|
-
const
|
|
1338
|
+
const i = this.computeBackoffDelay();
|
|
1317
1339
|
console.warn(
|
|
1318
|
-
`[WebSocket] Unexpected close (code=${e}, reason="${s}"). Reconnect attempt #${this.reconnectAttempts}/${
|
|
1319
|
-
), (r = this.onReconnecting) == null || r.call(this, this.reconnectAttempts,
|
|
1340
|
+
`[WebSocket] Unexpected close (code=${e}, reason="${s}"). Reconnect attempt #${this.reconnectAttempts}/${ot} in ${i}ms (resume sessionId=${t ?? "none"}).`
|
|
1341
|
+
), (r = this.onReconnecting) == null || r.call(this, this.reconnectAttempts, i), this.cancelPendingReconnect(), this.reconnectTimer = setTimeout(async () => {
|
|
1320
1342
|
if (this.reconnectTimer = null, !this.intentionalDisconnect)
|
|
1321
1343
|
try {
|
|
1322
1344
|
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);
|
|
1323
1345
|
} catch (l) {
|
|
1324
1346
|
console.error("[WebSocket] Reconnect attempt failed:", l);
|
|
1325
1347
|
}
|
|
1326
|
-
},
|
|
1348
|
+
}, i);
|
|
1327
1349
|
}
|
|
1328
1350
|
async sleep(t) {
|
|
1329
1351
|
return new Promise((e) => setTimeout(e, t));
|
|
@@ -1332,7 +1354,7 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
|
|
|
1332
1354
|
* Handle incoming messages from server
|
|
1333
1355
|
*/
|
|
1334
1356
|
handleMessage(t, e) {
|
|
1335
|
-
var l,
|
|
1357
|
+
var l, o, u;
|
|
1336
1358
|
switch (typeof t.seq == "number" && t.seq > this.lastSeq && (this.lastSeq = t.seq), t.type) {
|
|
1337
1359
|
case "Pong":
|
|
1338
1360
|
if (this.sessionId = t.sessionId, this.lastKnownSessionId = t.sessionId ?? this.lastKnownSessionId, !t.sessionId) {
|
|
@@ -1357,44 +1379,44 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
|
|
|
1357
1379
|
if (t.partialEvent) {
|
|
1358
1380
|
const d = t.partialEvent;
|
|
1359
1381
|
this.emitFirstToken(d == null ? void 0 : d.iteractionId);
|
|
1360
|
-
const h = new
|
|
1382
|
+
const h = new yt();
|
|
1361
1383
|
if (h.author = "main", h.streamingParts = t.partialEvent.streamingParts, t.partialEvent.partialEventType ? h.eventType = t.partialEvent.partialEventType : h.eventType = d.functionName ? {
|
|
1362
1384
|
fullName: F.StreamingFunctionCallUpdateContent,
|
|
1363
|
-
type:
|
|
1385
|
+
type: y.PartialFunctionCall
|
|
1364
1386
|
} : d.partialReasoning ? {
|
|
1365
1387
|
fullName: F.StreamingReasoningContent,
|
|
1366
|
-
type:
|
|
1388
|
+
type: y.Thought
|
|
1367
1389
|
} : {
|
|
1368
1390
|
fullName: F.StreamingTextContent,
|
|
1369
|
-
type:
|
|
1370
|
-
}, h.interactionId = (d == null ? void 0 : d.iteractionId) ?? "", h.mimeType = "text/plain", h.partial = !0, h.eventType.type ==
|
|
1371
|
-
var s = new
|
|
1391
|
+
type: y.Text
|
|
1392
|
+
}, h.interactionId = (d == null ? void 0 : d.iteractionId) ?? "", h.mimeType = "text/plain", h.partial = !0, h.eventType.type == y.PartialFunctionCall) {
|
|
1393
|
+
var s = new It();
|
|
1372
1394
|
s.choiceIndex = 0, s.callId = d.functionCallId, s.arguments = d.partialText, s.name = d.functionName, h.content = {
|
|
1373
1395
|
items: [s],
|
|
1374
1396
|
role: {
|
|
1375
1397
|
label: "Assistant"
|
|
1376
1398
|
}
|
|
1377
1399
|
};
|
|
1378
|
-
} else if (h.eventType.type ==
|
|
1400
|
+
} else if (h.eventType.type == y.Text)
|
|
1379
1401
|
if (h.eventType.fullName == F.StreamingTextContent) {
|
|
1380
|
-
var
|
|
1381
|
-
|
|
1382
|
-
items: [
|
|
1402
|
+
var i = new Ct();
|
|
1403
|
+
i.text = d.partialText, h.content = {
|
|
1404
|
+
items: [i],
|
|
1383
1405
|
role: {
|
|
1384
1406
|
label: "Assistant"
|
|
1385
1407
|
}
|
|
1386
1408
|
};
|
|
1387
1409
|
} else {
|
|
1388
|
-
var
|
|
1389
|
-
|
|
1390
|
-
items: [
|
|
1410
|
+
var n = new vt();
|
|
1411
|
+
n.text = d.partialText, h.content = {
|
|
1412
|
+
items: [n],
|
|
1391
1413
|
role: {
|
|
1392
1414
|
label: "Assistant"
|
|
1393
1415
|
}
|
|
1394
1416
|
};
|
|
1395
1417
|
}
|
|
1396
|
-
else if (h.eventType.type ==
|
|
1397
|
-
var r = new
|
|
1418
|
+
else if (h.eventType.type == y.Thought) {
|
|
1419
|
+
var r = new Et();
|
|
1398
1420
|
r.text = d.partialReasoning, h.content = {
|
|
1399
1421
|
items: [r],
|
|
1400
1422
|
role: {
|
|
@@ -1407,7 +1429,7 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
|
|
|
1407
1429
|
label: "Assistant"
|
|
1408
1430
|
}, h.timestamp = (d == null ? void 0 : d.timeStamp) ?? (/* @__PURE__ */ new Date()).getTime(), h.turnComplete = !1, t.event = h, t.partialEvent = void 0;
|
|
1409
1431
|
}
|
|
1410
|
-
return t.event ? (t.subAgentId && (t.event.subAgentId = t.subAgentId, t.event.subAgentName = t.subAgentName), ((((
|
|
1432
|
+
return t.event ? (t.subAgentId && (t.event.subAgentId = t.subAgentId, t.event.subAgentName = t.subAgentName), ((((o = (l = t.event.content) == null ? void 0 : l.items) == null ? void 0 : o.length) ?? 0) > 0 || (((u = t.event.streamingParts) == null ? void 0 : u.length) ?? 0) > 0) && this.emitFirstToken(t.event.interactionId), this.handleEvent(t.event, e), t.event) : null;
|
|
1411
1433
|
}
|
|
1412
1434
|
emitFirstToken(t) {
|
|
1413
1435
|
var e;
|
|
@@ -1443,9 +1465,9 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
|
|
|
1443
1465
|
console.warn("[WebSocket] WS-refreshed token received but no stored user — dropping");
|
|
1444
1466
|
return;
|
|
1445
1467
|
}
|
|
1446
|
-
const
|
|
1447
|
-
if ((
|
|
1448
|
-
|
|
1468
|
+
const i = JSON.parse(s);
|
|
1469
|
+
if ((i == null ? void 0 : i.access_token) === t) return;
|
|
1470
|
+
i.access_token = t, localStorage.setItem(e, JSON.stringify(i)), console.info("[WebSocket] Mirrored WS-refreshed JWT into stored user");
|
|
1449
1471
|
} catch (s) {
|
|
1450
1472
|
console.error("[WebSocket] Failed to persist WS-refreshed token", s);
|
|
1451
1473
|
}
|
|
@@ -1455,7 +1477,7 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
|
|
|
1455
1477
|
}
|
|
1456
1478
|
suspendStream() {
|
|
1457
1479
|
this.sendBaseMessage({
|
|
1458
|
-
Action:
|
|
1480
|
+
Action: U.Suspend,
|
|
1459
1481
|
AgentId: "",
|
|
1460
1482
|
InteractionId: "",
|
|
1461
1483
|
ModelId: ""
|
|
@@ -1464,7 +1486,7 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
|
|
|
1464
1486
|
/** Send the user's answer to a parked ask_user tool call (ChatAction.AnswerHumanTool). */
|
|
1465
1487
|
answerHumanTool(t, e) {
|
|
1466
1488
|
this.sendBaseMessage({
|
|
1467
|
-
Action:
|
|
1489
|
+
Action: U.AnswerHumanTool,
|
|
1468
1490
|
AgentId: "",
|
|
1469
1491
|
InteractionId: "",
|
|
1470
1492
|
ToolCallId: t,
|
|
@@ -1489,10 +1511,10 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
|
|
|
1489
1511
|
const t = this, e = this.pingPongStack, s = 3e4;
|
|
1490
1512
|
this.monitorInterval = setInterval(() => {
|
|
1491
1513
|
try {
|
|
1492
|
-
const
|
|
1493
|
-
t.isConnected() &&
|
|
1494
|
-
} catch (
|
|
1495
|
-
console.error("Error on monitor",
|
|
1514
|
+
const i = (/* @__PURE__ */ new Date()).getTime() - this.lastActivity;
|
|
1515
|
+
t.isConnected() && i >= s - 200 && (e.length > 0 && console.warn("Ping pong stack broke here, on pinging"), e.push((/* @__PURE__ */ new Date()).getTime()), t.ping());
|
|
1516
|
+
} catch (i) {
|
|
1517
|
+
console.error("Error on monitor", i);
|
|
1496
1518
|
}
|
|
1497
1519
|
}, s);
|
|
1498
1520
|
}
|
|
@@ -1511,7 +1533,7 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
|
|
|
1511
1533
|
* Disconnect the WebSocket
|
|
1512
1534
|
*/
|
|
1513
1535
|
disconnect() {
|
|
1514
|
-
console.warn("Chamou DISCONNECT!!!"), this.intentionalDisconnect = !0, this.cancelPendingReconnect(), this.isReconnecting = !1, this.reconnectAttempts = 0, this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingPongStack = [], this.firstTokenInteractions.clear(), this.lastKnownSessionId = void 0, this.lastSeq = -1, this.hasEverReceivedPacket = !1, this.ws && (this.ws.close(
|
|
1536
|
+
console.warn("Chamou DISCONNECT!!!"), this.intentionalDisconnect = !0, this.cancelPendingReconnect(), this.isReconnecting = !1, this.reconnectAttempts = 0, this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingPongStack = [], this.firstTokenInteractions.clear(), this.lastKnownSessionId = void 0, this.lastSeq = -1, this.hasEverReceivedPacket = !1, this.ws && (this.ws.close(W, "Intentional disconnect"), this.ws = null);
|
|
1515
1537
|
}
|
|
1516
1538
|
/**
|
|
1517
1539
|
* Check if connected
|
|
@@ -1540,24 +1562,24 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
|
|
|
1540
1562
|
async handleEvent(t, e) {
|
|
1541
1563
|
var s;
|
|
1542
1564
|
try {
|
|
1543
|
-
const
|
|
1544
|
-
if (!
|
|
1565
|
+
const i = ut.parseFromTypedEvent(t);
|
|
1566
|
+
if (!i)
|
|
1545
1567
|
throw "Server event was null";
|
|
1546
|
-
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,
|
|
1547
|
-
const
|
|
1548
|
-
this.stats.tokensPerSecond = l /
|
|
1549
|
-
console.error("Lost error on on-event",
|
|
1568
|
+
this.events.push([(/* @__PURE__ */ new Date()).getTime(), ((s = t.text) == null ? void 0 : s.length) ?? 0]), this.stats.eventCount += 1, this.stats.totalTransfered += e.length, i.session_information && !i.subAgentId && (this.stats.sessionInformation = i.session_information), this.stats.elapsed = (Date.now() - this.stats.startTime.getTime()) / 1e3;
|
|
1569
|
+
const n = Date.now() - rt * 1e3, l = this.events.filter((o) => o[0] > n).reduce((o, u) => o += u[1], 0) / Ft;
|
|
1570
|
+
this.stats.tokensPerSecond = l / rt, this.flushStatsCoalesced(), this.onEvent && this.onEvent(i).catch((o) => {
|
|
1571
|
+
console.error("Lost error on on-event", o);
|
|
1550
1572
|
});
|
|
1551
|
-
} catch (
|
|
1552
|
-
console.error("handleEvent error",
|
|
1573
|
+
} catch (i) {
|
|
1574
|
+
console.error("handleEvent error", i);
|
|
1553
1575
|
}
|
|
1554
1576
|
}
|
|
1555
1577
|
};
|
|
1556
|
-
g(
|
|
1557
|
-
let
|
|
1558
|
-
const
|
|
1559
|
-
constructor(e, s,
|
|
1560
|
-
super(e, s,
|
|
1578
|
+
g(j, "WebSocketConnecionV2");
|
|
1579
|
+
let ct = j;
|
|
1580
|
+
const xt = "envision_agent_sessionId", Y = class Y extends $ {
|
|
1581
|
+
constructor(e, s, i, n, r, l, o, u, d, h, v) {
|
|
1582
|
+
super(e, s, i, n, r, l, o, d, v);
|
|
1561
1583
|
a(this, "suspendState", !1);
|
|
1562
1584
|
a(this, "wsService");
|
|
1563
1585
|
a(this, "root_url", "");
|
|
@@ -1574,7 +1596,7 @@ const Lt = "envision_agent_sessionId", j = class j extends B {
|
|
|
1574
1596
|
}, this.wsService.onPong = (m) => {
|
|
1575
1597
|
}, this.wsService.onError = (m) => {
|
|
1576
1598
|
this.streamOpened = !1;
|
|
1577
|
-
const
|
|
1599
|
+
const p = {
|
|
1578
1600
|
data: this.getErrorEvent(m),
|
|
1579
1601
|
lastEventId: (/* @__PURE__ */ new Date()).getTime().toString(),
|
|
1580
1602
|
origin: "gatewayService"
|
|
@@ -1582,15 +1604,15 @@ const Lt = "envision_agent_sessionId", j = class j extends B {
|
|
|
1582
1604
|
console.error("Stream error:", m), this.notificationPort.pushNotification({
|
|
1583
1605
|
message: "Stream error" + m,
|
|
1584
1606
|
type: "warning"
|
|
1585
|
-
}), super.Message(
|
|
1607
|
+
}), super.Message(p);
|
|
1586
1608
|
}, this.wsService.onOpen = () => {
|
|
1587
1609
|
this.sessionState.setConnectionStatus(P.Connected);
|
|
1588
1610
|
}, this.wsService.onReconnected = (m) => {
|
|
1589
1611
|
this.sessionState.setConnectionStatus(P.Connected);
|
|
1590
1612
|
}, this.wsService.onFirstToken = (m) => {
|
|
1591
1613
|
this.localEmitFirstToken(m);
|
|
1592
|
-
}, this.wsService.onClose = (m,
|
|
1593
|
-
m !=
|
|
1614
|
+
}, this.wsService.onClose = (m, p) => {
|
|
1615
|
+
m != W && this.sessionState.setConnectionStatus(P.Disconnected);
|
|
1594
1616
|
};
|
|
1595
1617
|
}
|
|
1596
1618
|
reset(e, s) {
|
|
@@ -1603,7 +1625,7 @@ const Lt = "envision_agent_sessionId", j = class j extends B {
|
|
|
1603
1625
|
return this.suspendState;
|
|
1604
1626
|
}
|
|
1605
1627
|
getStoredSessionId() {
|
|
1606
|
-
const e = localStorage.getItem(
|
|
1628
|
+
const e = localStorage.getItem(xt);
|
|
1607
1629
|
if (e)
|
|
1608
1630
|
return e;
|
|
1609
1631
|
}
|
|
@@ -1615,15 +1637,15 @@ const Lt = "envision_agent_sessionId", j = class j extends B {
|
|
|
1615
1637
|
const s = this.interactionsMap.get(e);
|
|
1616
1638
|
return s == null ? void 0 : s.turn_complete;
|
|
1617
1639
|
}
|
|
1618
|
-
async finalResponse(e, s,
|
|
1619
|
-
super.turnComplete(e, s,
|
|
1640
|
+
async finalResponse(e, s, i) {
|
|
1641
|
+
super.turnComplete(e, s, i);
|
|
1620
1642
|
}
|
|
1621
1643
|
stopStream(e = !0) {
|
|
1622
1644
|
e && this.sessionState.setTurnOpen(!1), this.wsService && this.wsService.closeStream();
|
|
1623
1645
|
}
|
|
1624
1646
|
async suspend() {
|
|
1625
1647
|
const e = this.wsService;
|
|
1626
|
-
return new Promise(async (
|
|
1648
|
+
return new Promise(async (i, n) => {
|
|
1627
1649
|
let r = !1;
|
|
1628
1650
|
e.onSuspended = () => {
|
|
1629
1651
|
r = !0;
|
|
@@ -1635,11 +1657,11 @@ const Lt = "envision_agent_sessionId", j = class j extends B {
|
|
|
1635
1657
|
if (r)
|
|
1636
1658
|
if (this.currentIS) {
|
|
1637
1659
|
const d = this.currentIS.interaction;
|
|
1638
|
-
d.isSuspended = !0, this.sessionState.setCurrentMessage(d), this.sessionState.setTurnOpen(!1),
|
|
1660
|
+
d.isSuspended = !0, this.sessionState.setCurrentMessage(d), this.sessionState.setTurnOpen(!1), i(!0);
|
|
1639
1661
|
} else
|
|
1640
|
-
console.error("CurrentIS is null"),
|
|
1662
|
+
console.error("CurrentIS is null"), n("CurrentIS is null");
|
|
1641
1663
|
else
|
|
1642
|
-
|
|
1664
|
+
n("Timeout awaiting for suspension");
|
|
1643
1665
|
} finally {
|
|
1644
1666
|
this.suspendState = !0;
|
|
1645
1667
|
}
|
|
@@ -1657,11 +1679,11 @@ const Lt = "envision_agent_sessionId", j = class j extends B {
|
|
|
1657
1679
|
return !0;
|
|
1658
1680
|
}
|
|
1659
1681
|
async openConnection(e) {
|
|
1660
|
-
return this.lastConnectionPromise ? this.lastConnectionPromise : this.socketState == P.Disconnected ? (this.lastConnectionPromise = new Promise((s,
|
|
1661
|
-
this.wsService.connect(e).then((
|
|
1662
|
-
this.sessionId =
|
|
1663
|
-
}).catch((
|
|
1664
|
-
n
|
|
1682
|
+
return this.lastConnectionPromise ? this.lastConnectionPromise : this.socketState == P.Disconnected ? (this.lastConnectionPromise = new Promise((s, i) => {
|
|
1683
|
+
this.wsService.connect(e).then((n) => {
|
|
1684
|
+
this.sessionId = n, s(n);
|
|
1685
|
+
}).catch((n) => {
|
|
1686
|
+
i(n);
|
|
1665
1687
|
}).finally(() => {
|
|
1666
1688
|
this.lastConnectionPromise = null;
|
|
1667
1689
|
});
|
|
@@ -1681,28 +1703,28 @@ const Lt = "envision_agent_sessionId", j = class j extends B {
|
|
|
1681
1703
|
}
|
|
1682
1704
|
}
|
|
1683
1705
|
simulateDisconnect(e = 4500, s = "Debug simulated disconnect") {
|
|
1684
|
-
const
|
|
1685
|
-
|
|
1706
|
+
const i = this.wsService;
|
|
1707
|
+
i != null && i.ws && i.ws.close(e, s);
|
|
1686
1708
|
}
|
|
1687
1709
|
async sleep(e) {
|
|
1688
1710
|
return new Promise((s) => setTimeout(s, e));
|
|
1689
1711
|
}
|
|
1690
1712
|
// Send a message to the server via HTTP POST
|
|
1691
|
-
async sendMessageInternal(e, s,
|
|
1692
|
-
var l,
|
|
1693
|
-
const
|
|
1713
|
+
async sendMessageInternal(e, s, i) {
|
|
1714
|
+
var l, o, u, d, h, v, m, p;
|
|
1715
|
+
const n = this.suspendState;
|
|
1694
1716
|
this.suspendState = !1;
|
|
1695
|
-
const r = this.startInteraction(e.friendlyMessage ?? e.data,
|
|
1717
|
+
const r = this.startInteraction(e.friendlyMessage ?? e.data, n);
|
|
1696
1718
|
if (this.registerInteractionCallId(r.interactionId, s), (l = e.userUi) != null && l.name && r.parts.push(A.fromUserUi(e.userUi.name, e.userUi.args)), !this.wsService)
|
|
1697
1719
|
throw "no wsService created";
|
|
1698
1720
|
if (!this.sessionId)
|
|
1699
1721
|
throw "no session id set";
|
|
1700
|
-
if (!((
|
|
1722
|
+
if (!((o = this.config.agentConfig) != null && o.id))
|
|
1701
1723
|
throw "Agent not selected";
|
|
1702
1724
|
return this.wsService.sendMessage({
|
|
1703
1725
|
Content: e.data,
|
|
1704
1726
|
SessionId: this.sessionId,
|
|
1705
|
-
Action:
|
|
1727
|
+
Action: U.SendMessage,
|
|
1706
1728
|
ModelId: this.config.model,
|
|
1707
1729
|
InteractionId: r.interactionId,
|
|
1708
1730
|
AgentId: (u = this.config.agentConfig) == null ? void 0 : u.id,
|
|
@@ -1714,24 +1736,24 @@ const Lt = "envision_agent_sessionId", j = class j extends B {
|
|
|
1714
1736
|
AgentImplementation: (d = this.config.agentConfig) == null ? void 0 : d.agentImplementation,
|
|
1715
1737
|
Parameters: {
|
|
1716
1738
|
CustomerName: ((h = this.config.customer) == null ? void 0 : h.name) ?? "",
|
|
1717
|
-
DataSet: ((
|
|
1739
|
+
DataSet: ((v = this.config.customer) == null ? void 0 : v.dataSetId) ?? ""
|
|
1718
1740
|
},
|
|
1719
1741
|
// Forward image attachments as a structured payload (PascalCase
|
|
1720
1742
|
// keys to match the C# `Message.Images` / `MessageImage` model).
|
|
1721
|
-
Images: (m = e.images) != null && m.length ? e.images.map((
|
|
1743
|
+
Images: (m = e.images) != null && m.length ? e.images.map((I) => ({ MimeType: I.mimeType, Data: I.data })) : void 0,
|
|
1722
1744
|
// Client-only UI representation for this turn (PascalCase to match the C# `Message.UserUi`
|
|
1723
1745
|
// model). The server persists it as a UserUiContent sibling and strips it from the model
|
|
1724
1746
|
// request; Content remains the only model-facing text.
|
|
1725
|
-
UserUi: (
|
|
1747
|
+
UserUi: (p = e.userUi) != null && p.name ? { Name: e.userUi.name, Args: e.userUi.args } : void 0
|
|
1726
1748
|
}), this.localOpen(r.interactionId, "system"), Promise.resolve({
|
|
1727
1749
|
interaction: r,
|
|
1728
1750
|
success: !0
|
|
1729
1751
|
});
|
|
1730
1752
|
}
|
|
1731
1753
|
};
|
|
1732
|
-
g(
|
|
1733
|
-
let
|
|
1734
|
-
const
|
|
1754
|
+
g(Y, "AgentGatewayWSAsync");
|
|
1755
|
+
let lt = Y;
|
|
1756
|
+
const Q = class Q {
|
|
1735
1757
|
constructor(t, e) {
|
|
1736
1758
|
a(this, "cache", /* @__PURE__ */ new Map());
|
|
1737
1759
|
a(this, "serverBaseUrl");
|
|
@@ -1768,8 +1790,8 @@ const Y = class Y {
|
|
|
1768
1790
|
headers: this.headers
|
|
1769
1791
|
});
|
|
1770
1792
|
if (!s.ok) return null;
|
|
1771
|
-
const
|
|
1772
|
-
return this.cache.set(
|
|
1793
|
+
const i = await s.json();
|
|
1794
|
+
return this.cache.set(i.id, i), i;
|
|
1773
1795
|
} catch {
|
|
1774
1796
|
return null;
|
|
1775
1797
|
}
|
|
@@ -1786,17 +1808,17 @@ const Y = class Y {
|
|
|
1786
1808
|
}
|
|
1787
1809
|
}
|
|
1788
1810
|
};
|
|
1789
|
-
g(
|
|
1790
|
-
let
|
|
1811
|
+
g(Q, "HttpArtifactService");
|
|
1812
|
+
let ht = Q;
|
|
1791
1813
|
export {
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1814
|
+
$ as A,
|
|
1815
|
+
B as E,
|
|
1816
|
+
ht as H,
|
|
1795
1817
|
b as I,
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1818
|
+
it as L,
|
|
1819
|
+
at as M,
|
|
1820
|
+
ct as W,
|
|
1821
|
+
lt as a,
|
|
1822
|
+
jt as u
|
|
1801
1823
|
};
|
|
1802
|
-
//# sourceMappingURL=httpArtifactService-
|
|
1824
|
+
//# sourceMappingURL=httpArtifactService-DFlQzSgN.js.map
|