@aintela/chat 0.2.25 → 0.2.27

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.
Files changed (30) hide show
  1. package/dist/{auth-DbmLacBc.js → auth-GFZAFz7L.js} +2 -2
  2. package/dist/{auth-DbmLacBc.js.map → auth-GFZAFz7L.js.map} +1 -1
  3. package/dist/components.js +2626 -2589
  4. package/dist/components.js.map +1 -1
  5. package/dist/{environmentUtils-BaKw5_VD.js → environmentUtils-CUVZ6Dq1.js} +44 -28
  6. package/dist/environmentUtils-CUVZ6Dq1.js.map +1 -0
  7. package/dist/hooks.js +1 -1
  8. package/dist/{httpArtifactService-Dh9LGQ9a.js → httpArtifactService-B668XBHO.js} +465 -436
  9. package/dist/httpArtifactService-B668XBHO.js.map +1 -0
  10. package/dist/{httpSessionService-5Kr__oQL.js → httpSessionService-BuT5FlDc.js} +3 -3
  11. package/dist/{httpSessionService-5Kr__oQL.js.map → httpSessionService-BuT5FlDc.js.map} +1 -1
  12. package/dist/index.js +6 -6
  13. package/dist/models.js +2 -2
  14. package/dist/serializer-BPina6fX.js +1337 -0
  15. package/dist/serializer-BPina6fX.js.map +1 -0
  16. package/dist/services.js +2 -2
  17. package/dist/src/components/AiChat/ChatPane/parts/AskUserDispatcher.d.ts +22 -0
  18. package/dist/src/components/AiChat/ChatPane/parts/types.d.ts +17 -0
  19. package/dist/src/components/AiChat/ChatPane/parts/uiToolRegistry.d.ts +47 -2
  20. package/dist/src/models/InteractionPart.test.d.ts +1 -0
  21. package/dist/src/models/ServerEvent.d.ts +11 -0
  22. package/dist/src/models/semanticKernelModel/models.d.ts +14 -4
  23. package/dist/{useChatSessions-DttlifVk.js → useChatSessions-DsHPo0GV.js} +2 -2
  24. package/dist/{useChatSessions-DttlifVk.js.map → useChatSessions-DsHPo0GV.js.map} +1 -1
  25. package/dist/utils.js +2 -2
  26. package/package.json +1 -1
  27. package/dist/environmentUtils-BaKw5_VD.js.map +0 -1
  28. package/dist/httpArtifactService-Dh9LGQ9a.js.map +0 -1
  29. package/dist/serializer-DyHZxlAG.js +0 -1276
  30. package/dist/serializer-DyHZxlAG.js.map +0 -1
@@ -1,16 +1,16 @@
1
- var et = Object.defineProperty;
2
- var dt = (E, t, e) => t in E ? et(E, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : E[t] = e;
3
- var g = (E, t) => et(E, "name", { value: t, configurable: !0 });
4
- var a = (E, t, e) => dt(E, typeof t != "symbol" ? t + "" : t, e);
5
- import { d as _, t as gt, E as T, k as ft, j as mt, q as pt, C as L } from "./environmentUtils-BaKw5_VD.js";
6
- import { I as A, S as lt, g as St, L as wt, P as F, b as Tt, e as yt, T as It, c as Ct } from "./serializer-DyHZxlAG.js";
7
- import { unified as vt } from "unified";
8
- import Et from "remark-parse";
9
- import { toMarkdown as Mt } from "mdast-util-to-markdown";
10
- import { format as Ot } from "date-fns";
11
- import Dt from "lodash";
12
- import { P as At, C as P } from "./Prompt-DZb7OaPp.js";
13
- const S = {
1
+ var nt = Object.defineProperty;
2
+ var gt = (O, t, e) => t in O ? nt(O, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : O[t] = e;
3
+ var f = (O, t) => nt(O, "name", { value: t, configurable: !0 });
4
+ var a = (O, t, e) => gt(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 L } from "./environmentUtils-CUVZ6Dq1.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-BPina6fX.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,9 +36,9 @@ const S = {
36
36
  created: (/* @__PURE__ */ new Date()).toISOString(),
37
37
  iconType: "folder"
38
38
  }
39
- ], W = class W {
39
+ ], J = class J {
40
40
  constructor() {
41
- a(this, "onPromptCreated", /* @__PURE__ */ g(() => {
41
+ a(this, "onPromptCreated", /* @__PURE__ */ f(() => {
42
42
  }, "onPromptCreated"));
43
43
  }
44
44
  getItem(t) {
@@ -52,27 +52,27 @@ const S = {
52
52
  }
53
53
  initializeStorage() {
54
54
  try {
55
- const t = localStorage.getItem(S.SECTIONS);
55
+ const t = localStorage.getItem(T.SECTIONS);
56
56
  if (!t)
57
- localStorage.setItem(S.SECTIONS, JSON.stringify(k));
57
+ localStorage.setItem(T.SECTIONS, JSON.stringify(k));
58
58
  else {
59
59
  const s = JSON.parse(t);
60
60
  if (k.some(
61
- (i) => !s.find((r) => r.id === i.id)
61
+ (n) => !s.find((r) => r.id === n.id)
62
62
  )) {
63
- const i = [...s];
63
+ const n = [...s];
64
64
  k.forEach((r) => {
65
- s.find((l) => l.id === r.id) || i.push(r);
66
- }), localStorage.setItem(S.SECTIONS, JSON.stringify(i));
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(S.ARTIFACTS);
69
+ const e = localStorage.getItem(T.ARTIFACTS);
70
70
  if (e) {
71
71
  const s = JSON.parse(e);
72
- let n = !1;
73
- const i = s.map((r) => {
72
+ let i = !1;
73
+ const n = s.map((r) => {
74
74
  if (!r.sectionId) {
75
- n = !0;
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
- n && localStorage.setItem(S.ARTIFACTS, JSON.stringify(i));
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(S.SECTIONS);
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(S.ARTIFACTS);
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
- }, n = this.getSections();
114
- return n.push(s), localStorage.setItem(S.SECTIONS, JSON.stringify(n)), s;
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(), n = s.findIndex((i) => i.id === t);
118
- n >= 0 && (s[n] = { ...s[n], ...e }, localStorage.setItem(S.SECTIONS, JSON.stringify(s)));
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((n) => n.id === t);
121
+ const e = this.getSections(), s = e.find((i) => i.id === t);
122
122
  if (s && !s.isDefault) {
123
- const n = this.getArtifacts(), i = s.iconType === "dashboard" ? "dashboards" : s.iconType === "chart" ? "charts" : "data-analytics", r = n.map((c) => c.sectionId === t ? { ...c, sectionId: i } : c);
124
- localStorage.setItem(S.ARTIFACTS, JSON.stringify(r));
125
- const l = e.filter((c) => c.id !== t);
126
- localStorage.setItem(S.SECTIONS, JSON.stringify(l));
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((n) => n.id === t.id);
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 n = "data-analytics";
136
- t.type === _.Dashboard ? n = "dashboards" : t.type === _.Chart && (n = "charts");
137
- const i = {
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 || n
140
+ sectionId: t.sectionId || i
141
141
  };
142
- e.push(i);
142
+ e.push(n);
143
143
  }
144
- localStorage.setItem(S.ARTIFACTS, JSON.stringify(e));
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(), n = s.findIndex((i) => i.id === t);
151
- n >= 0 && (s[n] = { ...s[n], sectionId: e }, localStorage.setItem(S.ARTIFACTS, JSON.stringify(s)));
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((n) => n.id !== t);
155
- localStorage.setItem(S.ARTIFACTS, JSON.stringify(s));
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(), n = s.findIndex((i) => i.id === t);
159
- n >= 0 && (s[n] = { ...s[n], ...e }, localStorage.setItem(S.ARTIFACTS, JSON.stringify(s)));
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(S.PROMPTS);
168
- return t ? JSON.parse(t).sort((s, n) => new Date(n.created).getTime() - new Date(s.created).getTime()) : [];
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(S.PROMPTS, JSON.stringify(s));
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((n) => n.id !== t);
186
- localStorage.setItem(S.PROMPTS, JSON.stringify(s));
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(S.PROMPTS);
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(W, "LocalStorageService");
200
- let st = W;
201
- const Kt = /* @__PURE__ */ g((E) => {
202
- const t = E.getPrompts(), e = t.length;
199
+ f(J, "LocalStorageService");
200
+ let it = J;
201
+ const jt = /* @__PURE__ */ f((O) => {
202
+ const t = O.getPrompts(), e = t.length;
203
203
  if (e > 0) {
204
- const s = t[0].promptText, n = t[t.length - 1].promptText, i = t[0].created;
205
- return { promptState: e + "_" + s + "_" + n + "_" + i };
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"), J = class J {
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(J, "EventTypes");
234
- let U = J;
235
- const o = new U(), q = class q {
233
+ f(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 n = s.map((i) => i(...e));
244
- Promise.all(n).catch((i) => {
245
- console.error(`Lost error in one of the listeners of the event: ${t}, listeners: ${s.length}, error: ${i}`, s);
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 = o.activityLost;
256
+ const e = c.activityLost;
257
257
  this.addListener(e, t);
258
258
  }
259
259
  activityEmitLost() {
260
- this.callListeners(o.activityLost);
260
+ this.callListeners(c.activityLost);
261
261
  }
262
262
  /* typed artifact listeners */
263
263
  artifactOnGenerated(t) {
264
- const e = o.artifactGenerated;
264
+ const e = c.artifactGenerated;
265
265
  this.addListener(e, t);
266
266
  }
267
267
  artifactEmitGenerated(t) {
268
- this.callListeners(o.artifactGenerated, t);
268
+ this.callListeners(c.artifactGenerated, t);
269
269
  }
270
270
  artifactOffGenerated(t) {
271
- const e = o.artifactGenerated;
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 = o.artifactSelected;
275
+ const e = c.artifactSelected;
276
276
  this.addListener(e, t);
277
277
  }
278
278
  artifactEmitSelected(t) {
279
- this.callListeners(o.artifactSelected, t);
279
+ this.callListeners(c.artifactSelected, t);
280
280
  }
281
281
  artifactOffSelected(t) {
282
- const e = o.artifactSelected;
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 = o.artifactDeleted;
286
+ const e = c.artifactDeleted;
287
287
  this.addListener(e, t);
288
288
  }
289
289
  artifactEmitDeleted(t) {
290
- this.callListeners(o.artifactDeleted, t);
290
+ this.callListeners(c.artifactDeleted, t);
291
291
  }
292
292
  artifactOffDeleted(t) {
293
- const e = o.artifactDeleted;
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 = o.gatewayMessage;
297
+ const e = c.gatewayMessage;
298
298
  this.addListener(e, t);
299
299
  }
300
300
  gatewayOnTurnComplete(t) {
301
- const e = o.gatewayTurnComplete;
301
+ const e = c.gatewayTurnComplete;
302
302
  this.addListener(e, t);
303
303
  }
304
304
  gatewayOnTurnOpen(t) {
305
- const e = o.gatewayTurnOpen;
305
+ const e = c.gatewayTurnOpen;
306
306
  this.addListener(e, t);
307
307
  }
308
308
  gatewayOnStreamError(t) {
309
- const e = o.gatewayStreamError;
309
+ const e = c.gatewayStreamError;
310
310
  this.addListener(e, t);
311
311
  }
312
312
  gatewayOnStreamEnded(t) {
313
- const e = o.gatewayStreamEnded;
313
+ const e = c.gatewayStreamEnded;
314
314
  this.addListener(e, t);
315
315
  }
316
316
  gatewayOffStreamEnded(t) {
317
- const e = o.gatewayStreamEnded;
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(o.gatewayStreamEnded, t, e);
321
+ this.callListeners(c.gatewayStreamEnded, t, e);
322
322
  }
323
323
  gatewayEmitMessage(t, e = null) {
324
- this.callListeners(o.gatewayMessage, t, e);
324
+ this.callListeners(c.gatewayMessage, t, e);
325
325
  }
326
326
  gatewayEmitTurnComplete(t, e) {
327
- this.callListeners(o.gatewayTurnComplete, t, e);
327
+ this.callListeners(c.gatewayTurnComplete, t, e);
328
328
  }
329
329
  gatewayEmitStreamError(t) {
330
- this.callListeners(o.gatewayStreamError, t);
330
+ this.callListeners(c.gatewayStreamError, t);
331
331
  }
332
332
  gatewayEmitTurnOpen(t) {
333
- this.callListeners(o.gatewayTurnOpen, t);
333
+ this.callListeners(c.gatewayTurnOpen, t);
334
334
  }
335
335
  gatewayOffMessage(t) {
336
- const e = o.gatewayMessage;
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 = o.gatewayTurnComplete;
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 = o.gatewayTurnOpen;
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 = o.gatewayStreamError;
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 = o.sessionCreated;
352
+ const e = c.sessionCreated;
353
353
  this.addListener(e, t);
354
354
  }
355
355
  chatOnMessageSent(t) {
356
- const e = o.onMessageSent;
356
+ const e = c.onMessageSent;
357
357
  this.addListener(e, t);
358
358
  }
359
359
  chatOffMessageSent(t) {
360
- const e = o.onMessageSent;
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(o.onMessageSent, t, e);
364
+ this.callListeners(c.onMessageSent, t, e);
365
365
  }
366
366
  chatOnMessageError(t) {
367
- const e = o.onMessageError;
367
+ const e = c.onMessageError;
368
368
  this.addListener(e, t);
369
369
  }
370
370
  chatOffMessageError(t) {
371
- const e = o.onMessageError;
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(o.onMessageError, t);
375
+ this.callListeners(c.onMessageError, t);
376
376
  }
377
377
  sessionOnUpdated(t) {
378
- const e = o.sessionUpdated;
378
+ const e = c.sessionUpdated;
379
379
  this.addListener(e, t);
380
380
  }
381
381
  sessionEmitCreated(t) {
382
- this.callListeners(o.sessionCreated, t);
382
+ this.callListeners(c.sessionCreated, t);
383
383
  }
384
384
  sessionEmitUpdated(t) {
385
- this.callListeners(o.sessionUpdated, t);
385
+ this.callListeners(c.sessionUpdated, t);
386
386
  }
387
387
  sessionOffCreated(t) {
388
- const e = o.sessionCreated;
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 = o.sessionUpdated;
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(o.gatewayFunctionResponse, t);
396
+ this.callListeners(c.gatewayFunctionResponse, t);
397
397
  }
398
398
  gatewayOffFunctionResponse(t) {
399
- const e = o.gatewayFunctionResponse;
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 = o.gatewayFunctionResponse;
403
+ const e = c.gatewayFunctionResponse;
404
404
  this.addListener(e, t);
405
405
  }
406
406
  // UI events
407
407
  uiOnUnsavedPopoverToggle(t) {
408
- const e = o.uiUnsavedPopoverToggle;
408
+ const e = c.uiUnsavedPopoverToggle;
409
409
  this.addListener(e, t);
410
410
  }
411
411
  uiEmitUnsavedPopoverToggle(t) {
412
- this.callListeners(o.uiUnsavedPopoverToggle, t);
412
+ this.callListeners(c.uiUnsavedPopoverToggle, t);
413
413
  }
414
414
  uiOffUnsavedPopoverToggle(t) {
415
- const e = o.uiUnsavedPopoverToggle;
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 = o.artifactsStorageUpdated;
420
+ const e = c.artifactsStorageUpdated;
421
421
  this.addListener(e, t);
422
422
  }
423
423
  artifactsEmitStorageUpdated() {
424
- this.callListeners(o.artifactsStorageUpdated);
424
+ this.callListeners(c.artifactsStorageUpdated);
425
425
  }
426
426
  artifactsOffStorageUpdated(t) {
427
- const e = o.artifactsStorageUpdated;
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 = o.streamNewChunk;
431
+ const e = c.streamNewChunk;
432
432
  this.addListener(e, t);
433
433
  }
434
434
  streamEmitNewChunk(t) {
435
- this.callListeners(o.streamNewChunk, t);
435
+ this.callListeners(c.streamNewChunk, t);
436
436
  }
437
437
  streamOffNewChunk(t) {
438
- const e = o.streamNewChunk;
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 = o.gatewayEndMessageData;
442
+ const e = c.gatewayEndMessageData;
443
443
  this.addListener(e, t);
444
444
  }
445
445
  gatewayEmitEndMessageData(t) {
446
- this.callListeners(o.gatewayEndMessageData, t);
446
+ this.callListeners(c.gatewayEndMessageData, t);
447
447
  }
448
448
  gatewayOffEndMessageData(t) {
449
- const e = o.gatewayEndMessageData;
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 = o.connectionStateChange;
453
+ const e = c.connectionStateChange;
454
454
  this.addListener(e, t);
455
455
  }
456
456
  gatewayEmitConnectionStateChange(t) {
457
- this.callListeners(o.connectionStateChange, t);
457
+ this.callListeners(c.connectionStateChange, t);
458
458
  }
459
459
  gatewayOffConnectionStateChange(t) {
460
- const e = o.connectionStateChange;
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 = o.onToolEvent;
464
+ const e = c.onToolEvent;
465
465
  this.addListener(e, t);
466
466
  }
467
467
  gatewayEmitToolEvent(t, e, s) {
468
- this.callListeners(o.onToolEvent, t, e, s);
468
+ this.callListeners(c.onToolEvent, t, e, s);
469
469
  }
470
470
  gatewayOffToolEvent(t) {
471
- const e = o.onToolEvent;
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 = o.gatewayFirstToken;
475
+ const e = c.gatewayFirstToken;
476
476
  this.addListener(e, t);
477
477
  }
478
478
  gatewayEmitFirstToken(t) {
479
- this.callListeners(o.gatewayFirstToken, t);
479
+ this.callListeners(c.gatewayFirstToken, t);
480
480
  }
481
481
  gatewayOffFirstToken(t) {
482
- const e = o.gatewayFirstToken;
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(q, "EventBusService");
487
- let x = q;
488
- const G = class G extends x {
486
+ f(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
- gt() ? process.stdout.write(`M${t.version}, `) : console.log("MockEventBusService.gatewayEmitMessage");
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(G, "MockEventBusService");
515
- let nt = G;
516
- const ht = {
514
+ f(H, "MockEventBusService");
515
+ let at = H;
516
+ const dt = {
517
517
  inline: "inline",
518
518
  block: "block"
519
- }, H = class H {
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", ht.inline);
525
+ a(this, "type", dt.inline);
526
526
  }
527
527
  };
528
- g(H, "InteractionPartGroup");
529
- let R = H;
530
- const K = class K {
528
+ f(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
- a(this, "parseTextIntoParts", /* @__PURE__ */ g((t) => {
534
+ a(this, "parseTextIntoParts", /* @__PURE__ */ f((t) => {
535
535
  if (!t || t.trim().length == 0) return [];
536
- const e = vt().use(Et).parse(t), s = [];
537
- let n = null;
538
- for (const i of e.children)
539
- i.type === "code" ? (n && (s.push(n), n = null), i.lang === "htmlCanvas" && s.push(`
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
- ${i.value}
541
+ ${n.value}
542
542
  \`\`\`
543
- `)) : (n || (n = ""), n += Mt(i));
544
- return n && s.push(n), s;
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), n = [];
550
- let i = 0;
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 = i + "_" + e, n.push(l), i++;
553
+ l.id = n + "_" + e, i.push(l), n++;
554
554
  }
555
- return n;
555
+ return i;
556
556
  }
557
557
  groupPartsByDisplayType(t, e = !0, s = !1) {
558
558
  var l;
559
- const n = [];
560
- let i = new R();
561
- for (let c = 0; c < t.length; c++) {
562
- const u = t[c];
563
- let h = !(((l = u.functionDetails) == null ? void 0 : l.isUi) ?? !1) && u.eventType !== T.Text && u.eventType !== T.Thought && (u.eventType === T.FunctionCall || u.eventType === T.PartialFunctionCall || u.eventType === T.FunctionResponse) && c < t.length - 1;
564
- !e && h && !s || (h ? (u.eventType == T.Thought && (i.hasThoughts = !0), i.parts.push(u), i.isLastGroup = c === t.length - 1) : (i.parts.length > 0 && (n.push(i), i = new R()), n.push({
565
- type: ht.block,
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: c === t.length - 1,
567
+ isLastGroup: o === t.length - 1,
568
568
  hasThoughts: !1,
569
569
  lastWithThoughts: !1
570
570
  })));
571
571
  }
572
- i.parts.length > 0 && n.push(i);
573
- const r = n.filter((c) => c.hasThoughts);
574
- return r.length > 0 && (r[r.length - 1].lastWithThoughts = !0), n;
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 == T.FunctionCall || t == T.PartialFunctionCall;
577
+ return t == y.FunctionCall || t == y.PartialFunctionCall;
578
578
  }
579
579
  isFunctionResponse(t) {
580
- return t == T.FunctionResponse;
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 Q, X, Z, V;
589
- const e = this.interaction, s = [], n = [], i = A.FlatParts(t == null ? void 0 : t.parts), r = e.parts[e.parts.length - 1] ?? null;
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
- i && (l = !r || i.mustPush || i.mustPush === !1 && (i.eventType !== (r == null ? void 0 : r.eventType) || ((Q = i == null ? void 0 : i.functionDetails) == null ? void 0 : Q.id) !== ((X = r.functionDetails) == null ? void 0 : X.id)));
592
- let c = e.parts, u = e.functionMap ?? /* @__PURE__ */ new Map(), d = !e.functionMap;
593
- const h = /* @__PURE__ */ g(() => {
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
+ const h = /* @__PURE__ */ f(() => {
594
594
  d || (u = new Map(u), d = !0);
595
- }, "cloneFunctionMap"), C = /* @__PURE__ */ g(() => {
596
- c === e.parts && (c = e.parts.slice());
595
+ }, "cloneFunctionMap"), v = /* @__PURE__ */ f(() => {
596
+ o === e.parts && (o = e.parts.slice());
597
597
  }, "clonePartsIfShared");
598
- let m = !1;
599
- if (l && i) {
600
- const p = this.isFunctionCall(i.eventType) || this.isFunctionResponse(i.eventType), y = p ? (Z = i.functionDetails) == null ? void 0 : Z.id : void 0;
601
- p && !y && console.error("Got isCall or isResponse without a callId", i);
602
- const M = y ? u.get(y) : void 0;
603
- if (M && y && i.functionDetails) {
604
- const v = c.findIndex((ut) => {
605
- var tt;
606
- return ((tt = ut.functionDetails) == null ? void 0 : tt.id) === y;
607
- }), I = v > -1 ? c[v] : M, N = {
608
- ...I,
609
- eventType: i.eventType,
598
+ let p = !1;
599
+ if ((n == null ? void 0 : n.eventType) === y.FunctionClientOutput && !!((V = n.functionDetails) != null && V.id) && n) {
600
+ const g = n.functionDetails.id, C = n.functionDetails.clientOutput, E = o.findIndex((w) => {
601
+ var m;
602
+ return ((m = w.functionDetails) == null ? void 0 : m.id) === g;
603
+ });
604
+ if (E > -1) {
605
+ const w = o[E], m = {
606
+ ...w,
607
+ functionDetails: {
608
+ ...w.functionDetails,
609
+ clientOutput: C ?? w.functionDetails.clientOutput
610
+ }
611
+ };
612
+ v(), o[E] = m, h(), u.set(g, m), s.push(m);
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(g, w);
620
+ }
621
+ } else if (l && n) {
622
+ const g = this.isFunctionCall(n.eventType) || this.isFunctionResponse(n.eventType), C = g ? (tt = n.functionDetails) == null ? void 0 : tt.id : void 0;
623
+ g && !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((ft) => {
627
+ var st;
628
+ return ((st = ft.functionDetails) == null ? void 0 : st.id) === C;
629
+ }), m = w > -1 ? o[w] : E, N = {
630
+ ...m,
631
+ eventType: n.eventType,
610
632
  functionDetails: {
611
- id: I.functionDetails.id,
612
- name: i.functionDetails.name ?? I.functionDetails.name,
633
+ id: m.functionDetails.id,
634
+ name: n.functionDetails.name ?? m.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,109 @@ ${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: i.functionDetails.args ?? I.functionDetails.args,
622
- response: i.functionDetails.response,
623
- status: i.functionDetails.status ?? "Composing",
624
- start: i.functionDetails.start ?? I.functionDetails.start,
625
- end: i.functionDetails.end ?? I.functionDetails.end,
643
+ args: n.functionDetails.args ?? m.functionDetails.args,
644
+ response: n.functionDetails.response,
645
+ status: n.functionDetails.status ?? "Composing",
646
+ start: n.functionDetails.start ?? m.functionDetails.start,
647
+ end: n.functionDetails.end ?? m.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: i.functionDetails.isUi === !0 || I.functionDetails.isUi === !0,
651
+ isUi: n.functionDetails.isUi === !0 || m.functionDetails.isUi === !0,
630
652
  // Keep the call's friendly args summary when the result event (which has none) folds in.
631
- argsDescription: i.functionDetails.argsDescription ?? I.functionDetails.argsDescription,
653
+ argsDescription: n.functionDetails.argsDescription ?? m.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: i.functionDetails.clientOutput ?? I.functionDetails.clientOutput
656
+ clientOutput: n.functionDetails.clientOutput ?? m.functionDetails.clientOutput,
657
+ // Ask-user component ([KernelUIComponent]) — sticky like isUi/clientOutput. The
658
+ // streaming final CALL carries it, but the PartialFunctionCall it folds onto (and a
659
+ // later result rep) may not; dropping it strips the part's askUser classification so
660
+ // the docked drawer never surfaces (issue #60 — esp. a no-arg tool like update_profile,
661
+ // which has no name match to fall back on the way ask_user/askauth do).
662
+ askUserComponent: n.functionDetails.askUserComponent ?? m.functionDetails.askUserComponent,
663
+ isAskUser: n.functionDetails.isAskUser || m.functionDetails.isAskUser || !!(n.functionDetails.askUserComponent ?? m.functionDetails.askUserComponent)
635
664
  }
636
665
  };
637
- h(), u.set(y, N), N.eventType === T.FunctionResponse && this.eventBusService.gatewayEmitFunctionResponse(N.functionDetails), s.push(N), v > -1 && (C(), c[v] = N);
666
+ h(), u.set(C, N), N.eventType === y.FunctionResponse && this.eventBusService.gatewayEmitFunctionResponse(N.functionDetails), s.push(N), w > -1 && (v(), o[w] = N);
638
667
  } else {
639
- if (y && i.functionDetails && !M && (h(), u.set(y, i)), r && r.textAppendable) {
640
- const I = {
668
+ if (C && n.functionDetails && !E && (h(), u.set(C, n)), r && r.textAppendable) {
669
+ const m = {
641
670
  ...r,
642
671
  ended: /* @__PURE__ */ new Date(),
643
672
  isStillWriting: !1
644
673
  };
645
- C(), c[c.length - 1] = I, s.push(I);
674
+ v(), o[o.length - 1] = m, s.push(m);
646
675
  }
647
- const v = {
648
- ...i,
649
- id: c.length + 1 + "-" + e.interactionId,
650
- isStillWriting: i.textAppendable,
676
+ const w = {
677
+ ...n,
678
+ id: o.length + 1 + "-" + e.interactionId,
679
+ isStillWriting: n.textAppendable,
651
680
  partial: t.partial
652
681
  };
653
- (V = v.functionDetails) != null && V.silent || s.push(v), c = [...c, v], m = !0;
682
+ (et = w.functionDetails) != null && et.silent || s.push(w), o = [...o, w], p = !0;
654
683
  }
655
684
  }
656
- let f = c[c.length - 1] ?? null;
657
- if (f && i && i.textAppendable) {
658
- const p = {
659
- ...f,
685
+ let I = o[o.length - 1] ?? null;
686
+ if (I && n && n.textAppendable) {
687
+ const g = {
688
+ ...I,
660
689
  partial: t.partial,
661
- textDetails: f.textDetails ? { ...f.textDetails } : { version: 0 }
690
+ textDetails: I.textDetails ? { ...I.textDetails } : { version: 0 }
662
691
  };
663
- let y = !1;
692
+ let C = !1;
664
693
  if (t.partial) {
665
694
  try {
666
- p.textDetails.version++, m || (p.text = (f.text ?? "") + (i.text ?? ""));
667
- } catch (M) {
668
- console.error("Error here", M.toString());
695
+ g.textDetails.version++, p || (g.text = (I.text ?? "") + (n.text ?? ""));
696
+ } catch (E) {
697
+ console.error("Error here", E.toString());
669
698
  }
670
- p.textLastChunk = i.text ?? "", p.isStillWriting = !0, y = !0, i.thoughtDetails && p.thoughtDetails && i.thoughtDetails.text !== p.thoughtDetails.text && (p.thoughtDetails = {
671
- ...p.thoughtDetails,
672
- text: p.thoughtDetails.text + i.thoughtDetails.text
673
- }, p.thoughtLastChunk = i.thoughtDetails.text);
699
+ g.textLastChunk = n.text ?? "", g.isStillWriting = !0, C = !0, n.thoughtDetails && g.thoughtDetails && n.thoughtDetails.text !== g.thoughtDetails.text && (g.thoughtDetails = {
700
+ ...g.thoughtDetails,
701
+ text: g.thoughtDetails.text + n.thoughtDetails.text
702
+ }, g.thoughtLastChunk = n.thoughtDetails.text);
674
703
  } else
675
- p.isStillWriting = !1, p.text = i.text ?? "", p.textDetails.version++, i.thoughtDetails && (p.thoughtDetails = {
676
- ...i.thoughtDetails,
677
- text: i.thoughtDetails.text.trim()
678
- }), y = !l;
679
- C(), c[c.length - 1] = p, f = p, y && s.push(p);
704
+ g.isStillWriting = !1, g.text = n.text ?? "", g.textDetails.version++, n.thoughtDetails && (g.thoughtDetails = {
705
+ ...n.thoughtDetails,
706
+ text: n.thoughtDetails.text.trim()
707
+ }), C = !l;
708
+ v(), o[o.length - 1] = g, I = g, C && s.push(g);
680
709
  }
681
- let w = e.artifactData ?? [];
710
+ let M = e.artifactData ?? [];
682
711
  if (t.llmArtifacts && t.llmArtifacts.length > 0) {
683
- let p = !1;
684
- for (const y of t.llmArtifacts) {
685
- const M = y.toArtifact();
686
- p || (w = w.slice(), p = !0);
687
- const v = w.findIndex((I) => I.id === M.id);
688
- v === -1 ? w.push(M) : w[v] = M;
712
+ let g = !1;
713
+ for (const C of t.llmArtifacts) {
714
+ const E = C.toArtifact();
715
+ g || (M = M.slice(), g = !0);
716
+ const w = M.findIndex((m) => m.id === E.id);
717
+ w === -1 ? M.push(E) : M[w] = E;
689
718
  }
690
719
  }
691
- const O = {
720
+ const U = {
692
721
  ...e,
693
722
  version: e.version + 1,
694
- parts: c,
695
- artifactData: w,
723
+ parts: o,
724
+ artifactData: M,
696
725
  functionMap: u,
697
726
  turn_complete: t.turn_complete,
698
727
  partial: t.partial,
699
728
  asyncFinalResponse: t.asyncFinalResponse
700
729
  };
701
- return this.interaction = O, {
702
- updatedInteraction: O,
730
+ return this.interaction = U, {
731
+ updatedInteraction: U,
703
732
  updatedParts: s,
704
- newArtifacts: n,
705
- mainBranch: O,
733
+ newArtifacts: i,
734
+ mainBranch: U,
706
735
  analyticsBranch: null,
707
736
  analyticsBranchPartsChanged: null,
708
737
  mainBranchPartsChanged: s
709
738
  };
710
739
  }
711
740
  };
712
- g(K, "InteractionService");
713
- let b = K;
714
- const Nt = 1200 * 1e3, D = class D {
715
- constructor(t, e, s, n, i, r, l, c, u, d = mt.Interactive) {
716
- a(this, "base_production_url", ft() ?? "https://agent.tripapi.com.br");
741
+ f(z, "InteractionService");
742
+ let b = z;
743
+ const kt = 1200 * 1e3, D = class D {
744
+ constructor(t, e, s, i, n, r, l, o, u, d = St.Interactive) {
745
+ a(this, "base_production_url", pt() ?? "https://agent.tripapi.com.br");
717
746
  a(this, "base_url_local", "http://localagent:8000");
718
747
  a(this, "base_url");
719
748
  a(this, "isLocal", !1);
@@ -737,46 +766,46 @@ const Nt = 1200 * 1e3, D = class D {
737
766
  //Define all SSEServer methods here, use from SSEServer.ts
738
767
  a(this, "eventBusService");
739
768
  a(this, "artifactService");
740
- a(this, "onTurnOpen", /* @__PURE__ */ g((t) => {
769
+ a(this, "onTurnOpen", /* @__PURE__ */ f((t) => {
741
770
  this.eventBusService.gatewayOnTurnOpen(t);
742
771
  }, "onTurnOpen"));
743
- a(this, "offTurnOpen", /* @__PURE__ */ g((t) => {
772
+ a(this, "offTurnOpen", /* @__PURE__ */ f((t) => {
744
773
  this.eventBusService.gatewayOffTurnOpen(t);
745
774
  }, "offTurnOpen"));
746
- a(this, "onTurnComplete", /* @__PURE__ */ g((t) => {
775
+ a(this, "onTurnComplete", /* @__PURE__ */ f((t) => {
747
776
  this.eventBusService.gatewayOnTurnComplete(t);
748
777
  }, "onTurnComplete"));
749
- a(this, "offTurnComplete", /* @__PURE__ */ g((t) => {
778
+ a(this, "offTurnComplete", /* @__PURE__ */ f((t) => {
750
779
  this.eventBusService.gatewayOffTurnComplete(t);
751
780
  }, "offTurnComplete"));
752
- a(this, "onStreamError", /* @__PURE__ */ g((t) => {
781
+ a(this, "onStreamError", /* @__PURE__ */ f((t) => {
753
782
  this.eventBusService.gatewayOnStreamError(t);
754
783
  }, "onStreamError"));
755
- a(this, "offStreamError", /* @__PURE__ */ g((t) => {
784
+ a(this, "offStreamError", /* @__PURE__ */ f((t) => {
756
785
  this.eventBusService.gatewayOffStreamError(t);
757
786
  }, "offStreamError"));
758
- a(this, "onStreamEnded", /* @__PURE__ */ g((t) => {
787
+ a(this, "onStreamEnded", /* @__PURE__ */ f((t) => {
759
788
  this.eventBusService.gatewayOnStreamEnded(t);
760
789
  }, "onStreamEnded"));
761
- a(this, "offStreamEnded", /* @__PURE__ */ g((t) => {
790
+ a(this, "offStreamEnded", /* @__PURE__ */ f((t) => {
762
791
  this.eventBusService.gatewayOffStreamEnded(t);
763
792
  }, "offStreamEnded"));
764
- a(this, "onMessage", /* @__PURE__ */ g((t) => {
793
+ a(this, "onMessage", /* @__PURE__ */ f((t) => {
765
794
  this.eventBusService.gatewayOnMessage(t);
766
795
  }, "onMessage"));
767
- a(this, "offMessage", /* @__PURE__ */ g((t) => {
796
+ a(this, "offMessage", /* @__PURE__ */ f((t) => {
768
797
  this.eventBusService.gatewayOffMessage(t);
769
798
  }, "offMessage"));
770
- a(this, "onFirstToken", /* @__PURE__ */ g((t) => {
799
+ a(this, "onFirstToken", /* @__PURE__ */ f((t) => {
771
800
  this.eventBusService.gatewayOnFirstToken(t);
772
801
  }, "onFirstToken"));
773
- a(this, "offFirstToken", /* @__PURE__ */ g((t) => {
802
+ a(this, "offFirstToken", /* @__PURE__ */ f((t) => {
774
803
  this.eventBusService.gatewayOffFirstToken(t);
775
804
  }, "offFirstToken"));
776
- a(this, "onFunctionResponse", /* @__PURE__ */ g((t) => {
805
+ a(this, "onFunctionResponse", /* @__PURE__ */ f((t) => {
777
806
  this.eventBusService.gatewayOnFunctionResponse(t);
778
807
  }, "onFunctionResponse"));
779
- a(this, "offFunctionResponse", /* @__PURE__ */ g((t) => {
808
+ a(this, "offFunctionResponse", /* @__PURE__ */ f((t) => {
780
809
  this.eventBusService.gatewayOffFunctionResponse(t);
781
810
  }, "offFunctionResponse"));
782
811
  a(this, "toolSessionId", null);
@@ -788,7 +817,7 @@ const Nt = 1200 * 1e3, D = class D {
788
817
  a(this, "subAgentInteractionServices", /* @__PURE__ */ new Map());
789
818
  a(this, "lastThorttledTimeout", null);
790
819
  a(this, "lastPingStatus", !1);
791
- this.user = t, this.config = i, this.rawJwt = t.access_token, this.base_url = n, this.eventBusService = e, this.sessionId = u, this.runMode = d, this.artifactService = s, this.sessionState = r.getState(), this.notificationPort = l, this.storageService = c, r.subscribe((h, C) => {
820
+ 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
821
  this.sessionState = h;
793
822
  });
794
823
  }
@@ -859,11 +888,11 @@ const Nt = 1200 * 1e3, D = class D {
859
888
  if (e && this.currentIS)
860
889
  return this.currentIS.interaction.isSuspended = !1, this.currentIS.interaction.interactionQuestion += " + " + t, this.currentIS.interaction;
861
890
  this.msg_order += 1;
862
- let n = this.getNewInteractionId();
863
- s && (n = s);
864
- let i = {
891
+ let i = this.getNewInteractionId();
892
+ s && (i = s);
893
+ let n = {
865
894
  created: /* @__PURE__ */ new Date(),
866
- interactionId: n,
895
+ interactionId: i,
867
896
  artifactData: [],
868
897
  partial: !0,
869
898
  sessionId: this.sessionId,
@@ -873,7 +902,7 @@ const Nt = 1200 * 1e3, D = class D {
873
902
  functionMap: /* @__PURE__ */ new Map(),
874
903
  interactionQuestion: t
875
904
  };
876
- return this.interactionsMap.set(i.interactionId, i), this.currentIS = new b(i, this.eventBusService), this.interactionsServiceMap.set(i.interactionId, this.currentIS), i;
905
+ return this.interactionsMap.set(n.interactionId, n), this.currentIS = new b(n, this.eventBusService), this.interactionsServiceMap.set(n.interactionId, this.currentIS), n;
877
906
  }
878
907
  getInteractions() {
879
908
  return Array.from(this.interactionsMap.values());
@@ -921,8 +950,8 @@ const Nt = 1200 * 1e3, D = class D {
921
950
  s ? (console.warn("GOT A running promise", t), e = s) : (e = this.artifactService.getArtifact(t), this.runningRequests.set(t, e));
922
951
  try {
923
952
  return await e;
924
- } catch (n) {
925
- return console.error("Error awating on HTML promise", n.toString()), null;
953
+ } catch (i) {
954
+ return console.error("Error awating on HTML promise", i.toString()), null;
926
955
  } finally {
927
956
  this.runningRequests.delete(t);
928
957
  }
@@ -938,8 +967,8 @@ const Nt = 1200 * 1e3, D = class D {
938
967
  return !1;
939
968
  }
940
969
  getOrCreateSubAgentInteraction(t, e, s) {
941
- let n = this.subAgentInteractions.get(t), i = this.subAgentInteractionServices.get(t);
942
- return (!n || !i) && (n = {
970
+ let i = this.subAgentInteractions.get(t), n = this.subAgentInteractionServices.get(t);
971
+ return (!i || !n) && (i = {
943
972
  created: /* @__PURE__ */ new Date(),
944
973
  interactionId: e,
945
974
  artifactData: [],
@@ -949,7 +978,7 @@ const Nt = 1200 * 1e3, D = class D {
949
978
  version: 0,
950
979
  functionMap: /* @__PURE__ */ new Map(),
951
980
  interactionQuestion: s ?? t
952
- }, i = new b(n, this.eventBusService), this.subAgentInteractions.set(t, n), this.subAgentInteractionServices.set(t, i)), { interaction: n, service: i };
981
+ }, n = new b(i, this.eventBusService), this.subAgentInteractions.set(t, i), this.subAgentInteractionServices.set(t, n)), { interaction: i, service: n };
953
982
  }
954
983
  handleSubAgentEvent(t) {
955
984
  const e = t.subAgentId, { service: s } = this.getOrCreateSubAgentInteraction(e, t.interactionId, t.subAgentName);
@@ -960,10 +989,10 @@ const Nt = 1200 * 1e3, D = class D {
960
989
  continue;
961
990
  }
962
991
  }
963
- const n = s.merge(t);
964
- if (!n) return;
965
- const i = t.turn_complete ?? !1;
966
- this.sessionState.setSubAgentMessage(e, n.updatedInteraction, t.subAgentName), i && this.sessionState.completeSubAgent(e);
992
+ const i = s.merge(t);
993
+ if (!i) return;
994
+ const n = t.turn_complete ?? !1;
995
+ this.sessionState.setSubAgentMessage(e, i.updatedInteraction, t.subAgentName), n && this.sessionState.completeSubAgent(e);
967
996
  }
968
997
  async Message(t) {
969
998
  try {
@@ -980,14 +1009,14 @@ const Nt = 1200 * 1e3, D = class D {
980
1009
  }
981
1010
  if (e.serverError && console.error("Stream error: ", e.serverError), e.endMessageData && this.eventBusService.gatewayEmitEndMessageData(e.endMessageData), e) {
982
1011
  if (e.llmArtifacts && e.llmArtifacts.length > 0)
983
- for (const i of e.llmArtifacts) {
984
- const r = i.toArtifact();
1012
+ for (const n of e.llmArtifacts) {
1013
+ const r = n.toArtifact();
985
1014
  this.artifactService.addToCache(r), this.eventBusService.artifactEmitGenerated(r);
986
1015
  }
987
1016
  if (e.parts && e.parts.length > 0) {
988
- for (const i of e.parts)
989
- if (i.toolDetails) {
990
- this.localEmitToolEvent(i.toolDetails);
1017
+ for (const n of e.parts)
1018
+ if (n.toolDetails) {
1019
+ this.localEmitToolEvent(n.toolDetails);
991
1020
  continue;
992
1021
  }
993
1022
  }
@@ -1000,21 +1029,21 @@ const Nt = 1200 * 1e3, D = class D {
1000
1029
  return;
1001
1030
  }
1002
1031
  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 n = e.artifactsDelta;
1004
- n && n.forEach((i) => {
1005
- const r = s.updatedInteraction.artifactData.filter((c) => c.id == i);
1032
+ const i = e.artifactsDelta;
1033
+ i && i.forEach((n) => {
1034
+ const r = s.updatedInteraction.artifactData.filter((o) => o.id == n);
1006
1035
  let l = null;
1007
- r && r.length > 0 && (l = r[0], l.loadingPromise = this.asyncLoadArtifact(i).then((c) => (c === null ? console.error("Error trying to load artifact id:", l == null ? void 0 : l.id, "Artifact is null") : this.eventBusService.artifactEmitGenerated(c), c)).catch((c) => (console.error("Error trying to load artifact id:", l == null ? void 0 : l.id, c.toString()), null)));
1036
+ 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
1037
  });
1009
1038
  }
1010
1039
  } catch (e) {
1011
1040
  if (this.getCurrentInteractionId()) {
1012
- const s = lt.createErrorEvent("OnMessage error: " + e.toString(), this.getCurrentInteractionId() ?? "Empty Current"), n = this.updateMap(s);
1013
- if (console.error("Error event: ", JSON.stringify(s, void 0, 4)), !n) {
1041
+ const s = ut.createErrorEvent("OnMessage error: " + e.toString(), this.getCurrentInteractionId() ?? "Empty Current"), i = this.updateMap(s);
1042
+ if (console.error("Error event: ", JSON.stringify(s, void 0, 4)), !i) {
1014
1043
  console.error("Error event, could not update interaction: ", JSON.stringify(s, void 0, 4));
1015
1044
  return;
1016
1045
  }
1017
- this.localEmitMessage(n.updatedInteraction);
1046
+ this.localEmitMessage(i.updatedInteraction);
1018
1047
  }
1019
1048
  }
1020
1049
  }
@@ -1038,8 +1067,8 @@ const Nt = 1200 * 1e3, D = class D {
1038
1067
  this.sessionState.setCurrentMessage(t), this.lastCurrentMessageUpdate = e, this.pendingCurrentMessage = null, this.eventBusService.gatewayEmitMessage(t, s);
1039
1068
  }
1040
1069
  localEmitMessage(t, e) {
1041
- const s = (/* @__PURE__ */ new Date()).getTime(), n = s - this.lastCurrentMessageUpdate;
1042
- t.partial === !1 || n >= 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(() => {
1070
+ const s = (/* @__PURE__ */ new Date()).getTime(), i = s - this.lastCurrentMessageUpdate;
1071
+ 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
1072
  var r, l;
1044
1073
  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
1074
  }, D.CURRENT_MSG_THROTTLE_MS * 2));
@@ -1062,35 +1091,35 @@ const Nt = 1200 * 1e3, D = class D {
1062
1091
  cancelPendingCurrentMessage() {
1063
1092
  this.lastThorttledTimeout && (clearTimeout(this.lastThorttledTimeout), this.lastThorttledTimeout = null), this.pendingCurrentMessage = null;
1064
1093
  }
1065
- async turnComplete(t, e, s, n) {
1094
+ async turnComplete(t, e, s, i) {
1066
1095
  this.cancelPendingCurrentMessage(), this.sessionState.setNewMessage(e), this.eventBusService.gatewayEmitTurnComplete(t, e), this.interactionCallIds.delete(t), this.sessionState.setLastToolEvent(null), this.localEmitToolEvent({
1067
1096
  eventName: "todolistUpdated",
1068
1097
  eventData: "",
1069
- subAgentId: n
1098
+ subAgentId: i
1070
1099
  }), this.sessionState.setTurnOpen(!1);
1071
1100
  }
1072
1101
  async handlePing() {
1073
- return Date.now() - this.lastPing.getTime() > Nt ? await this.ping() ? (this.lastPing = /* @__PURE__ */ new Date(), this.lastPingStatus = !0, !0) : (this.lastPingStatus = !1, !1) : (this.lastPingStatus = !0, !0);
1102
+ 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
1103
  }
1075
1104
  async sendMessage(t, e) {
1076
- let s = this.getInteractions().length, n = A.createWaiting(!0, !0, "Overall", /* @__PURE__ */ new Date());
1077
- this.sendStatusMessage(t.data, [n], s.toString() + "1");
1105
+ let s = this.getInteractions().length, i = A.createWaiting(!0, !0, "Overall", /* @__PURE__ */ new Date());
1106
+ this.sendStatusMessage(t.data, [i], s.toString() + "1");
1078
1107
  try {
1079
- const { promptAsString: i, json: r } = this.sessionState.onRenderPrompt ? this.sessionState.onRenderPrompt(t.data) : { promptAsString: t.data, json: void 0 };
1080
- this.sessionState.onRenderPrompt && (t.data = r, t.friendlyMessage = i);
1081
- const l = await this.sendMessageInternal(t, e), c = At.createPrompt(i ?? "", (r == null ? void 0 : r.toString()) ?? {});
1082
- this.storageService.storePrompt(c);
1108
+ const { promptAsString: n, json: r } = this.sessionState.onRenderPrompt ? this.sessionState.onRenderPrompt(t.data) : { promptAsString: t.data, json: void 0 };
1109
+ this.sessionState.onRenderPrompt && (t.data = r, t.friendlyMessage = n);
1110
+ const l = await this.sendMessageInternal(t, e), o = Pt.createPrompt(n ?? "", (r == null ? void 0 : r.toString()) ?? {});
1111
+ this.storageService.storePrompt(o);
1083
1112
  const u = A.fromText("Planejando próximos passos");
1084
- return this.sendStatusMessage(t.data, [n, 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;
1085
- } catch (i) {
1086
- return this.eventBusService.ChatEmitMessageError((i == null ? void 0 : i.toString()) ?? ""), {
1113
+ 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;
1114
+ } catch (n) {
1115
+ return this.eventBusService.ChatEmitMessageError((n == null ? void 0 : n.toString()) ?? ""), {
1087
1116
  success: !1,
1088
1117
  interaction: {
1089
1118
  artifactData: [],
1090
1119
  created: /* @__PURE__ */ new Date(),
1091
1120
  interactionId: "",
1092
1121
  partial: !1,
1093
- parts: [A.fromError((i == null ? void 0 : i.toString()) ?? "")],
1122
+ parts: [A.fromError((n == null ? void 0 : n.toString()) ?? "")],
1094
1123
  version: 0
1095
1124
  }
1096
1125
  };
@@ -1107,9 +1136,9 @@ const Nt = 1200 * 1e3, D = class D {
1107
1136
  t.partial = !0, t.turn_complete = !1, t.asyncFinalResponse = !1, t.interactionId = t.interactionId, this.eventBusService.gatewayEmitTurnOpen(t.interactionId), this.Message(t);
1108
1137
  }
1109
1138
  sendStatusMessage(t, e, s) {
1110
- var i, r;
1111
- let n;
1112
- ((r = (i = this.currentIS) == null ? void 0 : i.interaction) == null ? void 0 : r.turn_complete) === !1 ? (n = Dt.cloneDeep(this.currentIS.interaction), n.parts.push(...e)) : n = {
1139
+ var n, r;
1140
+ let i;
1141
+ ((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
1142
  interactionId: "tmp" + s,
1114
1143
  created: /* @__PURE__ */ new Date(),
1115
1144
  partial: !0,
@@ -1118,7 +1147,7 @@ const Nt = 1200 * 1e3, D = class D {
1118
1147
  parts: e,
1119
1148
  interactionQuestion: t,
1120
1149
  artifactData: []
1121
- }, this.localEmitMessage(n);
1150
+ }, this.localEmitMessage(i);
1122
1151
  }
1123
1152
  clearStatus() {
1124
1153
  }
@@ -1132,13 +1161,13 @@ const Nt = 1200 * 1e3, D = class D {
1132
1161
  }
1133
1162
  }
1134
1163
  getNewInteractionId() {
1135
- const e = Ot(/* @__PURE__ */ new Date(), "MMM_dd_HH_mm_ss");
1164
+ const e = At(/* @__PURE__ */ new Date(), "MMM_dd_HH_mm_ss");
1136
1165
  return `${this.msg_order}_${e}`;
1137
1166
  }
1138
1167
  };
1139
- g(D, "AgentGatewayService"), a(D, "SUSPENSION_MSG", "SUSPEND"), a(D, "CURRENT_MSG_THROTTLE_MS", 20);
1140
- let B = D;
1141
- const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2, at = 2, z = class z {
1168
+ f(D, "AgentGatewayService"), a(D, "SUSPENSION_MSG", "SUSPEND"), a(D, "CURRENT_MSG_THROTTLE_MS", 20);
1169
+ let $ = D;
1170
+ const W = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, bt = 3e4, Ut = 2, Lt = 0.2, ot = 2, j = class j {
1142
1171
  constructor(t = "ws://localhost:8000", e) {
1143
1172
  a(this, "ws", null);
1144
1173
  a(this, "stats");
@@ -1219,7 +1248,7 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
1219
1248
  * Cleared by `disconnect()`.
1220
1249
  */
1221
1250
  a(this, "hasEverReceivedPacket", !1);
1222
- this.baseUrl = t, this.getToken = e, this.pingPongStack = [], this.events = [], this.firstTokenInteractions = /* @__PURE__ */ new Set(), this.streamingResponseSerializer = St(), console.log("SOCKET INSTACE", pt()), this.stats = {
1251
+ 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
1252
  eventCount: 0,
1224
1253
  unknonwCount: 0,
1225
1254
  buffer: [],
@@ -1235,13 +1264,13 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
1235
1264
  */
1236
1265
  connect(t) {
1237
1266
  return new Promise(async (e, s) => {
1238
- var m;
1267
+ var p;
1239
1268
  this.intentionalDisconnect = !1;
1240
- const n = this._internalReconnect;
1241
- n || (this.cancelPendingReconnect(), this.isReconnecting = !1, this.reconnectAttempts = 0, this.lastSeq = -1), this._internalReconnect = !1;
1242
- const i = (m = this.getToken) == null ? void 0 : m.call(this), r = [];
1243
- i && r.push(`access_token=${encodeURIComponent(i)}`), t && this.lastSeq >= 0 && r.push(`lastSeq=${this.lastSeq}`);
1244
- const l = r.length > 0 ? `?${r.join("&")}` : "", c = this.baseUrl.replace(/^http:\/\//, "ws://").replace(/^https:\/\//, "wss://"), u = `${c}/ws/connect/${t ?? ""}${l}`, d = `${c}/ws/connect/${t ?? ""}` + (n && t && this.lastSeq >= 0 ? ` (resume lastSeq=${this.lastSeq})` : "");
1269
+ const i = this._internalReconnect;
1270
+ i || (this.cancelPendingReconnect(), this.isReconnecting = !1, this.reconnectAttempts = 0, this.lastSeq = -1), this._internalReconnect = !1;
1271
+ const n = (p = this.getToken) == null ? void 0 : p.call(this), r = [];
1272
+ n && r.push(`access_token=${encodeURIComponent(n)}`), t && this.lastSeq >= 0 && r.push(`lastSeq=${this.lastSeq}`);
1273
+ 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
1274
  if (console.log("Connecting to ", d), this.ws) {
1246
1275
  this.ws.onopen = null, this.ws.onmessage = null, this.ws.onerror = null, this.ws.onclose = null;
1247
1276
  try {
@@ -1250,37 +1279,37 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
1250
1279
  }
1251
1280
  this.ws = null;
1252
1281
  }
1253
- this.ws = new WebSocket(u), console.log("[WebSocket] Connecting to:", `${c}/ws/connect/${t ?? ""}`);
1282
+ this.ws = new WebSocket(u), console.log("[WebSocket] Connecting to:", `${o}/ws/connect/${t ?? ""}`);
1254
1283
  let h = !1;
1255
1284
  this.ws.onopen = () => {
1256
1285
  console.log("[WebSocket] Connected");
1257
- const f = this.isReconnecting;
1258
- this.isReconnecting = !1, this.reconnectAttempts = 0, this.pingPongStack.push((/* @__PURE__ */ new Date()).getTime()), this.ping(), this.monitor(), this.onOpen && this.onOpen(), f && this.onReconnected && this.onReconnected(t ?? this.lastKnownSessionId ?? "");
1259
- }, this.ws.onmessage = (f) => {
1286
+ const S = this.isReconnecting;
1287
+ this.isReconnecting = !1, this.reconnectAttempts = 0, this.pingPongStack.push((/* @__PURE__ */ new Date()).getTime()), this.ping(), this.monitor(), this.onOpen && this.onOpen(), S && this.onReconnected && this.onReconnected(t ?? this.lastKnownSessionId ?? "");
1288
+ }, this.ws.onmessage = (S) => {
1260
1289
  try {
1261
1290
  this.lastActivity = (/* @__PURE__ */ new Date()).getTime();
1262
- const w = this.streamingResponseSerializer.parse(f.data);
1263
- if (!w)
1291
+ const I = this.streamingResponseSerializer.parse(S.data);
1292
+ if (!I)
1264
1293
  throw "Error parsing event JSON";
1265
- const O = this.handleMessage(w, f.data);
1266
- !h && (O != null && O.timestamp) && (h = !0, this.hasEverReceivedPacket = !0);
1267
- } catch (w) {
1268
- console.error("[WebSocket] Error parsing message:", w);
1294
+ const M = this.handleMessage(I, S.data);
1295
+ !h && (M != null && M.timestamp) && (h = !0, this.hasEverReceivedPacket = !0);
1296
+ } catch (I) {
1297
+ console.error("[WebSocket] Error parsing message:", I);
1269
1298
  }
1270
- }, this.ws.onerror = (f) => {
1271
- console.error("[WebSocket] Error:", f), this.onError && this.onError("WebSocket error");
1272
- }, this.ws.onclose = (f) => {
1273
- console.log("[WebSocket] Closed:", f.code, f.reason), this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingPongStack = [];
1274
- const w = this.sessionId ?? this.lastKnownSessionId;
1275
- if (this.sessionId = void 0, (h || this.hasEverReceivedPacket) && this.shouldAttemptReconnect(f.code)) {
1276
- this.scheduleReconnect(w, f.code, f.reason);
1299
+ }, this.ws.onerror = (S) => {
1300
+ console.error("[WebSocket] Error:", S), this.onError && this.onError("WebSocket error");
1301
+ }, this.ws.onclose = (S) => {
1302
+ console.log("[WebSocket] Closed:", S.code, S.reason), this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingPongStack = [];
1303
+ const I = this.sessionId ?? this.lastKnownSessionId;
1304
+ if (this.sessionId = void 0, (h || this.hasEverReceivedPacket) && this.shouldAttemptReconnect(S.code)) {
1305
+ this.scheduleReconnect(I, S.code, S.reason);
1277
1306
  return;
1278
1307
  }
1279
- this.isReconnecting = !1, this.reconnectAttempts = 0, this.onClose && this.onClose(f.code, f.reason);
1308
+ this.isReconnecting = !1, this.reconnectAttempts = 0, this.onClose && this.onClose(S.code, S.reason);
1280
1309
  };
1281
- let C = 0;
1282
- for (this.sessionId = void 0; !this.sessionId && C < 30; )
1283
- console.log("Aguardando session Id"), await this.sleep(400), C++;
1310
+ let v = 0;
1311
+ for (this.sessionId = void 0; !this.sessionId && v < 30; )
1312
+ console.log("Aguardando session Id"), await this.sleep(400), v++;
1284
1313
  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
1314
  });
1286
1315
  }
@@ -1294,36 +1323,36 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
1294
1323
  * - 4000-4099 reserved for app-level fatal codes from the server
1295
1324
  */
1296
1325
  shouldAttemptReconnect(t) {
1297
- return !(this.intentionalDisconnect || t === $ || t === Pt || t === 1e3 || t === 1008);
1326
+ return !(this.intentionalDisconnect || t === W || t === _t || t === 1e3 || t === 1008);
1298
1327
  }
1299
1328
  cancelPendingReconnect() {
1300
1329
  this.reconnectTimer && (clearTimeout(this.reconnectTimer), this.reconnectTimer = null);
1301
1330
  }
1302
1331
  computeBackoffDelay() {
1303
- const t = _t * Math.pow(Rt, this.reconnectAttempts), e = Math.min(t, Ft), s = e * bt * (Math.random() * 2 - 1);
1332
+ const t = Rt * Math.pow(Ut, this.reconnectAttempts), e = Math.min(t, bt), s = e * Lt * (Math.random() * 2 - 1);
1304
1333
  return Math.max(0, Math.round(e + s));
1305
1334
  }
1306
1335
  scheduleReconnect(t, e, s) {
1307
- var i, r;
1336
+ var n, r;
1308
1337
  if (this.intentionalDisconnect) return;
1309
- if (this.reconnectAttempts >= at) {
1338
+ if (this.reconnectAttempts >= ot) {
1310
1339
  console.warn(
1311
1340
  `[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(), (i = this.onClose) == null || i.call(this, e, s);
1341
+ ), this.isReconnecting = !1, this.reconnectAttempts = 0, this.cancelPendingReconnect(), (n = this.onClose) == null || n.call(this, e, s);
1313
1342
  return;
1314
1343
  }
1315
1344
  this.isReconnecting = !0, this.reconnectAttempts += 1;
1316
- const n = this.computeBackoffDelay();
1345
+ const i = this.computeBackoffDelay();
1317
1346
  console.warn(
1318
- `[WebSocket] Unexpected close (code=${e}, reason="${s}"). Reconnect attempt #${this.reconnectAttempts}/${at} in ${n}ms (resume sessionId=${t ?? "none"}).`
1319
- ), (r = this.onReconnecting) == null || r.call(this, this.reconnectAttempts, n), this.cancelPendingReconnect(), this.reconnectTimer = setTimeout(async () => {
1347
+ `[WebSocket] Unexpected close (code=${e}, reason="${s}"). Reconnect attempt #${this.reconnectAttempts}/${ot} in ${i}ms (resume sessionId=${t ?? "none"}).`
1348
+ ), (r = this.onReconnecting) == null || r.call(this, this.reconnectAttempts, i), this.cancelPendingReconnect(), this.reconnectTimer = setTimeout(async () => {
1320
1349
  if (this.reconnectTimer = null, !this.intentionalDisconnect)
1321
1350
  try {
1322
1351
  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
1352
  } catch (l) {
1324
1353
  console.error("[WebSocket] Reconnect attempt failed:", l);
1325
1354
  }
1326
- }, n);
1355
+ }, i);
1327
1356
  }
1328
1357
  async sleep(t) {
1329
1358
  return new Promise((e) => setTimeout(e, t));
@@ -1332,7 +1361,7 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
1332
1361
  * Handle incoming messages from server
1333
1362
  */
1334
1363
  handleMessage(t, e) {
1335
- var l, c, u;
1364
+ var l, o, u;
1336
1365
  switch (typeof t.seq == "number" && t.seq > this.lastSeq && (this.lastSeq = t.seq), t.type) {
1337
1366
  case "Pong":
1338
1367
  if (this.sessionId = t.sessionId, this.lastKnownSessionId = t.sessionId ?? this.lastKnownSessionId, !t.sessionId) {
@@ -1357,44 +1386,44 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
1357
1386
  if (t.partialEvent) {
1358
1387
  const d = t.partialEvent;
1359
1388
  this.emitFirstToken(d == null ? void 0 : d.iteractionId);
1360
- const h = new wt();
1389
+ const h = new yt();
1361
1390
  if (h.author = "main", h.streamingParts = t.partialEvent.streamingParts, t.partialEvent.partialEventType ? h.eventType = t.partialEvent.partialEventType : h.eventType = d.functionName ? {
1362
1391
  fullName: F.StreamingFunctionCallUpdateContent,
1363
- type: T.PartialFunctionCall
1392
+ type: y.PartialFunctionCall
1364
1393
  } : d.partialReasoning ? {
1365
1394
  fullName: F.StreamingReasoningContent,
1366
- type: T.Thought
1395
+ type: y.Thought
1367
1396
  } : {
1368
1397
  fullName: F.StreamingTextContent,
1369
- type: T.Text
1370
- }, h.interactionId = (d == null ? void 0 : d.iteractionId) ?? "", h.mimeType = "text/plain", h.partial = !0, h.eventType.type == T.PartialFunctionCall) {
1371
- var s = new Tt();
1398
+ type: y.Text
1399
+ }, h.interactionId = (d == null ? void 0 : d.iteractionId) ?? "", h.mimeType = "text/plain", h.partial = !0, h.eventType.type == y.PartialFunctionCall) {
1400
+ var s = new It();
1372
1401
  s.choiceIndex = 0, s.callId = d.functionCallId, s.arguments = d.partialText, s.name = d.functionName, h.content = {
1373
1402
  items: [s],
1374
1403
  role: {
1375
1404
  label: "Assistant"
1376
1405
  }
1377
1406
  };
1378
- } else if (h.eventType.type == T.Text)
1407
+ } else if (h.eventType.type == y.Text)
1379
1408
  if (h.eventType.fullName == F.StreamingTextContent) {
1380
- var n = new yt();
1381
- n.text = d.partialText, h.content = {
1382
- items: [n],
1409
+ var i = new Ct();
1410
+ i.text = d.partialText, h.content = {
1411
+ items: [i],
1383
1412
  role: {
1384
1413
  label: "Assistant"
1385
1414
  }
1386
1415
  };
1387
1416
  } else {
1388
- var i = new It();
1389
- i.text = d.partialText, h.content = {
1390
- items: [i],
1417
+ var n = new vt();
1418
+ n.text = d.partialText, h.content = {
1419
+ items: [n],
1391
1420
  role: {
1392
1421
  label: "Assistant"
1393
1422
  }
1394
1423
  };
1395
1424
  }
1396
- else if (h.eventType.type == T.Thought) {
1397
- var r = new Ct();
1425
+ else if (h.eventType.type == y.Thought) {
1426
+ var r = new Et();
1398
1427
  r.text = d.partialReasoning, h.content = {
1399
1428
  items: [r],
1400
1429
  role: {
@@ -1407,7 +1436,7 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
1407
1436
  label: "Assistant"
1408
1437
  }, h.timestamp = (d == null ? void 0 : d.timeStamp) ?? (/* @__PURE__ */ new Date()).getTime(), h.turnComplete = !1, t.event = h, t.partialEvent = void 0;
1409
1438
  }
1410
- return t.event ? (t.subAgentId && (t.event.subAgentId = t.subAgentId, t.event.subAgentName = t.subAgentName), ((((c = (l = t.event.content) == null ? void 0 : l.items) == null ? void 0 : c.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;
1439
+ 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
1440
  }
1412
1441
  emitFirstToken(t) {
1413
1442
  var e;
@@ -1443,9 +1472,9 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
1443
1472
  console.warn("[WebSocket] WS-refreshed token received but no stored user — dropping");
1444
1473
  return;
1445
1474
  }
1446
- const n = JSON.parse(s);
1447
- if ((n == null ? void 0 : n.access_token) === t) return;
1448
- n.access_token = t, localStorage.setItem(e, JSON.stringify(n)), console.info("[WebSocket] Mirrored WS-refreshed JWT into stored user");
1475
+ const i = JSON.parse(s);
1476
+ if ((i == null ? void 0 : i.access_token) === t) return;
1477
+ i.access_token = t, localStorage.setItem(e, JSON.stringify(i)), console.info("[WebSocket] Mirrored WS-refreshed JWT into stored user");
1449
1478
  } catch (s) {
1450
1479
  console.error("[WebSocket] Failed to persist WS-refreshed token", s);
1451
1480
  }
@@ -1489,10 +1518,10 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
1489
1518
  const t = this, e = this.pingPongStack, s = 3e4;
1490
1519
  this.monitorInterval = setInterval(() => {
1491
1520
  try {
1492
- const n = (/* @__PURE__ */ new Date()).getTime() - this.lastActivity;
1493
- t.isConnected() && n >= s - 200 && (e.length > 0 && console.warn("Ping pong stack broke here, on pinging"), e.push((/* @__PURE__ */ new Date()).getTime()), t.ping());
1494
- } catch (n) {
1495
- console.error("Error on monitor", n);
1521
+ const i = (/* @__PURE__ */ new Date()).getTime() - this.lastActivity;
1522
+ 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());
1523
+ } catch (i) {
1524
+ console.error("Error on monitor", i);
1496
1525
  }
1497
1526
  }, s);
1498
1527
  }
@@ -1511,7 +1540,7 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
1511
1540
  * Disconnect the WebSocket
1512
1541
  */
1513
1542
  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($, "Intentional disconnect"), this.ws = null);
1543
+ 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
1544
  }
1516
1545
  /**
1517
1546
  * Check if connected
@@ -1540,24 +1569,24 @@ const $ = 4001, Pt = 4002, it = 4, kt = 3, _t = 500, Ft = 3e4, Rt = 2, bt = 0.2,
1540
1569
  async handleEvent(t, e) {
1541
1570
  var s;
1542
1571
  try {
1543
- const n = lt.parseFromTypedEvent(t);
1544
- if (!n)
1572
+ const i = ut.parseFromTypedEvent(t);
1573
+ if (!i)
1545
1574
  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, n.session_information && !n.subAgentId && (this.stats.sessionInformation = n.session_information), this.stats.elapsed = (Date.now() - this.stats.startTime.getTime()) / 1e3;
1547
- const i = Date.now() - it * 1e3, l = this.events.filter((c) => c[0] > i).reduce((c, u) => c += u[1], 0) / kt;
1548
- this.stats.tokensPerSecond = l / it, this.flushStatsCoalesced(), this.onEvent && this.onEvent(n).catch((c) => {
1549
- console.error("Lost error on on-event", c);
1575
+ 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;
1576
+ const n = Date.now() - rt * 1e3, l = this.events.filter((o) => o[0] > n).reduce((o, u) => o += u[1], 0) / Ft;
1577
+ this.stats.tokensPerSecond = l / rt, this.flushStatsCoalesced(), this.onEvent && this.onEvent(i).catch((o) => {
1578
+ console.error("Lost error on on-event", o);
1550
1579
  });
1551
- } catch (n) {
1552
- console.error("handleEvent error", n);
1580
+ } catch (i) {
1581
+ console.error("handleEvent error", i);
1553
1582
  }
1554
1583
  }
1555
1584
  };
1556
- g(z, "WebSocketConnecionV2");
1557
- let rt = z;
1558
- const Lt = "envision_agent_sessionId", j = class j extends B {
1559
- constructor(e, s, n, i, r, l, c, u, d, h, C) {
1560
- super(e, s, n, i, r, l, c, d, C);
1585
+ f(j, "WebSocketConnecionV2");
1586
+ let ct = j;
1587
+ const xt = "envision_agent_sessionId", Y = class Y extends $ {
1588
+ constructor(e, s, i, n, r, l, o, u, d, h, v) {
1589
+ super(e, s, i, n, r, l, o, d, v);
1561
1590
  a(this, "suspendState", !1);
1562
1591
  a(this, "wsService");
1563
1592
  a(this, "root_url", "");
@@ -1567,30 +1596,30 @@ const Lt = "envision_agent_sessionId", j = class j extends B {
1567
1596
  a(this, "lastConnectionPromise", null);
1568
1597
  a(this, "socketState", P.Disconnected);
1569
1598
  a(this, "streamOpened", !1);
1570
- this.hearBeatPort = h, this.root_url = this.base_url, this.wsService = u, this.wsService.onEvent = async (m) => {
1571
- await super.Message(m);
1572
- }, this.wsService.onNewPacket = (m) => {
1573
- this.sessionState.setStatistics(m), this.eventBusService.streamEmitNewChunk(m);
1574
- }, this.wsService.onPong = (m) => {
1575
- }, this.wsService.onError = (m) => {
1599
+ this.hearBeatPort = h, this.root_url = this.base_url, this.wsService = u, this.wsService.onEvent = async (p) => {
1600
+ await super.Message(p);
1601
+ }, this.wsService.onNewPacket = (p) => {
1602
+ this.sessionState.setStatistics(p), this.eventBusService.streamEmitNewChunk(p);
1603
+ }, this.wsService.onPong = (p) => {
1604
+ }, this.wsService.onError = (p) => {
1576
1605
  this.streamOpened = !1;
1577
- const f = {
1578
- data: this.getErrorEvent(m),
1606
+ const S = {
1607
+ data: this.getErrorEvent(p),
1579
1608
  lastEventId: (/* @__PURE__ */ new Date()).getTime().toString(),
1580
1609
  origin: "gatewayService"
1581
1610
  };
1582
- console.error("Stream error:", m), this.notificationPort.pushNotification({
1583
- message: "Stream error" + m,
1611
+ console.error("Stream error:", p), this.notificationPort.pushNotification({
1612
+ message: "Stream error" + p,
1584
1613
  type: "warning"
1585
- }), super.Message(f);
1614
+ }), super.Message(S);
1586
1615
  }, this.wsService.onOpen = () => {
1587
1616
  this.sessionState.setConnectionStatus(P.Connected);
1588
- }, this.wsService.onReconnected = (m) => {
1617
+ }, this.wsService.onReconnected = (p) => {
1589
1618
  this.sessionState.setConnectionStatus(P.Connected);
1590
- }, this.wsService.onFirstToken = (m) => {
1591
- this.localEmitFirstToken(m);
1592
- }, this.wsService.onClose = (m, f) => {
1593
- m != $ && this.sessionState.setConnectionStatus(P.Disconnected);
1619
+ }, this.wsService.onFirstToken = (p) => {
1620
+ this.localEmitFirstToken(p);
1621
+ }, this.wsService.onClose = (p, S) => {
1622
+ p != W && this.sessionState.setConnectionStatus(P.Disconnected);
1594
1623
  };
1595
1624
  }
1596
1625
  reset(e, s) {
@@ -1603,7 +1632,7 @@ const Lt = "envision_agent_sessionId", j = class j extends B {
1603
1632
  return this.suspendState;
1604
1633
  }
1605
1634
  getStoredSessionId() {
1606
- const e = localStorage.getItem(Lt);
1635
+ const e = localStorage.getItem(xt);
1607
1636
  if (e)
1608
1637
  return e;
1609
1638
  }
@@ -1615,15 +1644,15 @@ const Lt = "envision_agent_sessionId", j = class j extends B {
1615
1644
  const s = this.interactionsMap.get(e);
1616
1645
  return s == null ? void 0 : s.turn_complete;
1617
1646
  }
1618
- async finalResponse(e, s, n) {
1619
- super.turnComplete(e, s, n);
1647
+ async finalResponse(e, s, i) {
1648
+ super.turnComplete(e, s, i);
1620
1649
  }
1621
1650
  stopStream(e = !0) {
1622
1651
  e && this.sessionState.setTurnOpen(!1), this.wsService && this.wsService.closeStream();
1623
1652
  }
1624
1653
  async suspend() {
1625
1654
  const e = this.wsService;
1626
- return new Promise(async (n, i) => {
1655
+ return new Promise(async (i, n) => {
1627
1656
  let r = !1;
1628
1657
  e.onSuspended = () => {
1629
1658
  r = !0;
@@ -1635,11 +1664,11 @@ const Lt = "envision_agent_sessionId", j = class j extends B {
1635
1664
  if (r)
1636
1665
  if (this.currentIS) {
1637
1666
  const d = this.currentIS.interaction;
1638
- d.isSuspended = !0, this.sessionState.setCurrentMessage(d), this.sessionState.setTurnOpen(!1), n(!0);
1667
+ d.isSuspended = !0, this.sessionState.setCurrentMessage(d), this.sessionState.setTurnOpen(!1), i(!0);
1639
1668
  } else
1640
- console.error("CurrentIS is null"), i("CurrentIS is null");
1669
+ console.error("CurrentIS is null"), n("CurrentIS is null");
1641
1670
  else
1642
- i("Timeout awaiting for suspension");
1671
+ n("Timeout awaiting for suspension");
1643
1672
  } finally {
1644
1673
  this.suspendState = !0;
1645
1674
  }
@@ -1657,11 +1686,11 @@ const Lt = "envision_agent_sessionId", j = class j extends B {
1657
1686
  return !0;
1658
1687
  }
1659
1688
  async openConnection(e) {
1660
- return this.lastConnectionPromise ? this.lastConnectionPromise : this.socketState == P.Disconnected ? (this.lastConnectionPromise = new Promise((s, n) => {
1661
- this.wsService.connect(e).then((i) => {
1662
- this.sessionId = i, s(i);
1663
- }).catch((i) => {
1664
- n(i);
1689
+ return this.lastConnectionPromise ? this.lastConnectionPromise : this.socketState == P.Disconnected ? (this.lastConnectionPromise = new Promise((s, i) => {
1690
+ this.wsService.connect(e).then((n) => {
1691
+ this.sessionId = n, s(n);
1692
+ }).catch((n) => {
1693
+ i(n);
1665
1694
  }).finally(() => {
1666
1695
  this.lastConnectionPromise = null;
1667
1696
  });
@@ -1681,23 +1710,23 @@ const Lt = "envision_agent_sessionId", j = class j extends B {
1681
1710
  }
1682
1711
  }
1683
1712
  simulateDisconnect(e = 4500, s = "Debug simulated disconnect") {
1684
- const n = this.wsService;
1685
- n != null && n.ws && n.ws.close(e, s);
1713
+ const i = this.wsService;
1714
+ i != null && i.ws && i.ws.close(e, s);
1686
1715
  }
1687
1716
  async sleep(e) {
1688
1717
  return new Promise((s) => setTimeout(s, e));
1689
1718
  }
1690
1719
  // Send a message to the server via HTTP POST
1691
- async sendMessageInternal(e, s, n) {
1692
- var l, c, u, d, h, C, m, f;
1693
- const i = this.suspendState;
1720
+ async sendMessageInternal(e, s, i) {
1721
+ var l, o, u, d, h, v, p, S;
1722
+ const n = this.suspendState;
1694
1723
  this.suspendState = !1;
1695
- const r = this.startInteraction(e.friendlyMessage ?? e.data, i);
1724
+ const r = this.startInteraction(e.friendlyMessage ?? e.data, n);
1696
1725
  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
1726
  throw "no wsService created";
1698
1727
  if (!this.sessionId)
1699
1728
  throw "no session id set";
1700
- if (!((c = this.config.agentConfig) != null && c.id))
1729
+ if (!((o = this.config.agentConfig) != null && o.id))
1701
1730
  throw "Agent not selected";
1702
1731
  return this.wsService.sendMessage({
1703
1732
  Content: e.data,
@@ -1714,24 +1743,24 @@ const Lt = "envision_agent_sessionId", j = class j extends B {
1714
1743
  AgentImplementation: (d = this.config.agentConfig) == null ? void 0 : d.agentImplementation,
1715
1744
  Parameters: {
1716
1745
  CustomerName: ((h = this.config.customer) == null ? void 0 : h.name) ?? "",
1717
- DataSet: ((C = this.config.customer) == null ? void 0 : C.dataSetId) ?? ""
1746
+ DataSet: ((v = this.config.customer) == null ? void 0 : v.dataSetId) ?? ""
1718
1747
  },
1719
1748
  // Forward image attachments as a structured payload (PascalCase
1720
1749
  // keys to match the C# `Message.Images` / `MessageImage` model).
1721
- Images: (m = e.images) != null && m.length ? e.images.map((w) => ({ MimeType: w.mimeType, Data: w.data })) : void 0,
1750
+ Images: (p = e.images) != null && p.length ? e.images.map((I) => ({ MimeType: I.mimeType, Data: I.data })) : void 0,
1722
1751
  // Client-only UI representation for this turn (PascalCase to match the C# `Message.UserUi`
1723
1752
  // model). The server persists it as a UserUiContent sibling and strips it from the model
1724
1753
  // request; Content remains the only model-facing text.
1725
- UserUi: (f = e.userUi) != null && f.name ? { Name: e.userUi.name, Args: e.userUi.args } : void 0
1754
+ UserUi: (S = e.userUi) != null && S.name ? { Name: e.userUi.name, Args: e.userUi.args } : void 0
1726
1755
  }), this.localOpen(r.interactionId, "system"), Promise.resolve({
1727
1756
  interaction: r,
1728
1757
  success: !0
1729
1758
  });
1730
1759
  }
1731
1760
  };
1732
- g(j, "AgentGatewayWSAsync");
1733
- let ot = j;
1734
- const Y = class Y {
1761
+ f(Y, "AgentGatewayWSAsync");
1762
+ let lt = Y;
1763
+ const Q = class Q {
1735
1764
  constructor(t, e) {
1736
1765
  a(this, "cache", /* @__PURE__ */ new Map());
1737
1766
  a(this, "serverBaseUrl");
@@ -1768,8 +1797,8 @@ const Y = class Y {
1768
1797
  headers: this.headers
1769
1798
  });
1770
1799
  if (!s.ok) return null;
1771
- const n = await s.json();
1772
- return this.cache.set(n.id, n), n;
1800
+ const i = await s.json();
1801
+ return this.cache.set(i.id, i), i;
1773
1802
  } catch {
1774
1803
  return null;
1775
1804
  }
@@ -1786,17 +1815,17 @@ const Y = class Y {
1786
1815
  }
1787
1816
  }
1788
1817
  };
1789
- g(Y, "HttpArtifactService");
1790
- let ct = Y;
1818
+ f(Q, "HttpArtifactService");
1819
+ let ht = Q;
1791
1820
  export {
1792
- B as A,
1793
- x as E,
1794
- ct as H,
1821
+ $ as A,
1822
+ B as E,
1823
+ ht as H,
1795
1824
  b as I,
1796
- st as L,
1797
- nt as M,
1798
- rt as W,
1799
- ot as a,
1800
- Kt as u
1825
+ it as L,
1826
+ at as M,
1827
+ ct as W,
1828
+ lt as a,
1829
+ jt as u
1801
1830
  };
1802
- //# sourceMappingURL=httpArtifactService-Dh9LGQ9a.js.map
1831
+ //# sourceMappingURL=httpArtifactService-B668XBHO.js.map