@aintela/chat 0.2.59 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.md +77 -0
  2. package/dist/{ClientMessage-EKgfuTp8.js → ClientMessage-DUby3KyC.js} +16 -22
  3. package/dist/{ClientMessage-EKgfuTp8.js.map → ClientMessage-DUby3KyC.js.map} +1 -1
  4. package/dist/Memory-CjrYSkzB.js +47 -0
  5. package/dist/Memory-CjrYSkzB.js.map +1 -0
  6. package/dist/atMentions-CnHuJKhX.js +959 -0
  7. package/dist/atMentions-CnHuJKhX.js.map +1 -0
  8. package/dist/components.js +10161 -11344
  9. package/dist/components.js.map +1 -1
  10. package/dist/environmentUtils-VZNTCzEE.js +88 -0
  11. package/dist/environmentUtils-VZNTCzEE.js.map +1 -0
  12. package/dist/hooks.js +4 -5
  13. package/dist/{httpArtifactService-CpbRpTHb.js → httpArtifactService-Ba9xFy1E.js} +537 -646
  14. package/dist/httpArtifactService-Ba9xFy1E.js.map +1 -0
  15. package/dist/{httpSessionService-BEQMIKfv.js → httpSessionService-DXlT2vxT.js} +34 -24
  16. package/dist/httpSessionService-DXlT2vxT.js.map +1 -0
  17. package/dist/index.js +242 -243
  18. package/dist/models.js +48 -51
  19. package/dist/models.js.map +1 -1
  20. package/dist/serializer-D2W42bdT.js +1730 -0
  21. package/dist/serializer-D2W42bdT.js.map +1 -0
  22. package/dist/services.js +2 -2
  23. package/dist/src/components/AiChat/AiChatContext.d.ts +0 -3
  24. package/dist/src/components/AiChat/AiChatProvider.agent.test.d.ts +1 -0
  25. package/dist/src/components/AiChat/AiChatProvider.d.ts +2 -2
  26. package/dist/src/components/AiChat/AiChatTypes.d.ts +45 -27
  27. package/dist/src/components/AiChat/ChatPane/ChatPane.test.d.ts +1 -0
  28. package/dist/src/components/AiChat/ChatPane/MessageAgent.d.ts +0 -1
  29. package/dist/src/components/AiChat/ChatPane/MessagePart.d.ts +5 -3
  30. package/dist/src/components/AiChat/ChatPane/MessagePart.test.d.ts +1 -0
  31. package/dist/src/components/AiChat/ChatPane/friendlyToolConfig.test.d.ts +1 -0
  32. package/dist/src/components/AiChat/ChatPane/messageAgentThoughts.test.d.ts +1 -0
  33. package/dist/src/components/AiChat/ChatPane/parts/ThoughtRun.d.ts +28 -0
  34. package/dist/src/components/AiChat/ChatPane/parts/ThoughtRunContext.d.ts +18 -0
  35. package/dist/src/components/AiChat/ChatPane/parts/index.d.ts +5 -1
  36. package/dist/src/components/AiChat/ChatPane/parts/thoughtRun.test.d.ts +1 -0
  37. package/dist/src/components/AiChat/ChatPane/parts/uiToolDispatcher.test.d.ts +1 -0
  38. package/dist/src/components/AiChat/ChatPane/parts/uiToolRegistry.test.d.ts +1 -0
  39. package/dist/src/components/AiChat/aiChatEngine.d.ts +24 -5
  40. package/dist/src/components/AiChat/index.d.ts +1 -3
  41. package/dist/src/components/AiChat/sessionStateManagerService.bind.test.d.ts +1 -0
  42. package/dist/src/components/AiChat/sessionStateManagerService.d.ts +22 -10
  43. package/dist/src/components/AiChat/useAgentEngine.d.ts +69 -0
  44. package/dist/src/components/AiChat/useAgentEngine.test.d.ts +1 -0
  45. package/dist/src/components/index.d.ts +4 -7
  46. package/dist/src/components/v2/AiChatFloating.d.ts +3 -0
  47. package/dist/src/components/v2/PromptV2.d.ts +21 -6
  48. package/dist/src/components/v2/PromptV2.test.d.ts +1 -0
  49. package/dist/src/components/v2/icons.d.ts +1 -0
  50. package/dist/src/components/v2/index.d.ts +25 -25
  51. package/dist/src/hooks/index.d.ts +1 -1
  52. package/dist/src/hooks/useContainerWidth.d.ts +0 -1
  53. package/dist/src/models/ArtifactData.d.ts +0 -7
  54. package/dist/src/models/ChatSession.d.ts +0 -32
  55. package/dist/src/models/ClientMessage.d.ts +0 -4
  56. package/dist/src/models/ServerEvent.d.ts +0 -36
  57. package/dist/src/models/enums.d.ts +0 -1
  58. package/dist/src/models/index.d.ts +1 -2
  59. package/dist/src/models/interactionPartUtils.test.d.ts +1 -0
  60. package/dist/src/models/semanticKernelModel/sanitizeJsonString.test.d.ts +0 -0
  61. package/dist/src/models/serverEventDecode.test.d.ts +0 -0
  62. package/dist/src/services/WebSocketConnection/webSocketConnectionV2.reconnect.test.d.ts +0 -0
  63. package/dist/src/services/interactionService.d.ts +11 -0
  64. package/dist/src/services/interactionServiceGrouping.test.d.ts +1 -0
  65. package/dist/src/services/servers/AgentGatewayService.d.ts +25 -18
  66. package/dist/src/services/servers/AgentGatewayWSAsync.d.ts +0 -1
  67. package/dist/src/services/servers/agentGatewayAgentContext.test.d.ts +1 -0
  68. package/dist/src/services/storageService.d.ts +34 -59
  69. package/dist/src/services/storageService.test.d.ts +1 -0
  70. package/dist/src/utils/index.d.ts +2 -6
  71. package/dist/src/utils/urlParser.d.ts +0 -1
  72. package/dist/src/utils/urlParser.test.d.ts +1 -0
  73. package/dist/tests/fakes/fakeChatServices.d.ts +42 -0
  74. package/dist/tests/fakes/fakeRawWebSocket.d.ts +51 -0
  75. package/dist/tests/fakes/fakeStorage.d.ts +7 -0
  76. package/dist/tests/fakes/makeGateway.d.ts +24 -1
  77. package/dist/{useChatSessions-BQP7DhY1.js → useChatSessions-1AAvAdPW.js} +2 -2
  78. package/dist/{useChatSessions-BQP7DhY1.js.map → useChatSessions-1AAvAdPW.js.map} +1 -1
  79. package/dist/useContainerWidth-B40_i-NW.js +295 -0
  80. package/dist/{useContainerWidth-B3t1ZTlo.js.map → useContainerWidth-B40_i-NW.js.map} +1 -1
  81. package/dist/utils.js +340 -57
  82. package/dist/utils.js.map +1 -1
  83. package/package.json +1 -1
  84. package/dist/Memory-DjLZqgbF.js +0 -84
  85. package/dist/Memory-DjLZqgbF.js.map +0 -1
  86. package/dist/atMentions-C0dza8DD.js +0 -1000
  87. package/dist/atMentions-C0dza8DD.js.map +0 -1
  88. package/dist/auth-lluJZyQO.js +0 -524
  89. package/dist/auth-lluJZyQO.js.map +0 -1
  90. package/dist/environmentUtils-CUVZ6Dq1.js +0 -478
  91. package/dist/environmentUtils-CUVZ6Dq1.js.map +0 -1
  92. package/dist/httpArtifactService-CpbRpTHb.js.map +0 -1
  93. package/dist/httpSessionService-BEQMIKfv.js.map +0 -1
  94. package/dist/serializer-BXSH9aYQ.js +0 -1360
  95. package/dist/serializer-BXSH9aYQ.js.map +0 -1
  96. package/dist/src/components/AiChat/AiChatFloating.d.ts +0 -3
  97. package/dist/src/components/AiChat/ChatPane/LastPrompts.d.ts +0 -9
  98. package/dist/src/components/AiChat/ChatPane/Prompt.d.ts +0 -9
  99. package/dist/src/components/AiChat/ChatPane/SubAgentBox.d.ts +0 -9
  100. package/dist/src/components/AiChat/ChatPane/TaskList.d.ts +0 -6
  101. package/dist/src/components/AiChat/useLiveSession.d.ts +0 -52
  102. package/dist/src/components/v2/AiChatFloatingV2.d.ts +0 -3
  103. package/dist/src/utils/jsonDetector.d.ts +0 -50
  104. package/dist/src/utils/jsonUtils.d.ts +0 -1
  105. package/dist/src/utils/materialIconsSvg.d.ts +0 -51
  106. package/dist/src/utils/objectUtils.d.ts +0 -31
  107. package/dist/src/utils/parseArtifact.d.ts +0 -3
  108. package/dist/src/utils/uriUtils.d.ts +0 -39
  109. package/dist/useContainerWidth-B3t1ZTlo.js +0 -309
@@ -1,248 +1,107 @@
1
- var rt = Object.defineProperty;
2
- var St = (D, t, e) => t in D ? rt(D, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : D[t] = e;
3
- var g = (D, t) => rt(D, "name", { value: t, configurable: !0 });
4
- var a = (D, t, e) => St(D, typeof t != "symbol" ? t + "" : t, e);
5
- import { d as x, t as wt, E as I, k as yt, j as Tt, q as It, C as W } from "./environmentUtils-CUVZ6Dq1.js";
6
- import { I as _, S as gt, g as Ct, L as vt, P as B, b as Et, e as Mt, T as Dt, c as Ot } from "./serializer-BXSH9aYQ.js";
7
- import { unified as At } from "unified";
8
- import kt from "remark-parse";
9
- import { toMarkdown as Nt } from "mdast-util-to-markdown";
10
- import { format as Pt } from "date-fns";
11
- import _t from "lodash";
12
- import { P as bt, C as U } from "./Prompt-DZb7OaPp.js";
13
- import { r as Ft } from "./httpSessionService-BEQMIKfv.js";
14
- const w = {
15
- ARTIFACTS: "envision-artifacts",
16
- SECTIONS: "envision-sections",
1
+ var it = Object.defineProperty;
2
+ var pt = (D, t, e) => t in D ? it(D, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : D[t] = e;
3
+ var f = (D, t) => it(D, "name", { value: t, configurable: !0 });
4
+ var i = (D, t, e) => pt(D, typeof t != "symbol" ? t + "" : t, e);
5
+ import { i as mt, a as St, d as wt } from "./environmentUtils-VZNTCzEE.js";
6
+ import { I as N, E as T, j as Tt, S as dt, q as yt, L as vt, P as L, l as Ct, o as It, T as Et, m as Mt, C as U } from "./serializer-D2W42bdT.js";
7
+ import { unified as Dt } from "unified";
8
+ import Ot from "remark-parse";
9
+ import { toMarkdown as kt } from "mdast-util-to-markdown";
10
+ import { format as At } from "date-fns";
11
+ import Pt from "lodash";
12
+ import { P as Nt, C as F } from "./Prompt-DZb7OaPp.js";
13
+ import { r as _t } from "./httpSessionService-DXlT2vxT.js";
14
+ const W = {
17
15
  PROMPTS: "envision-prompts"
18
- }, L = [
19
- {
20
- id: "dashboards",
21
- name: "Dashboards",
22
- isDefault: !0,
23
- created: (/* @__PURE__ */ new Date()).toISOString(),
24
- iconType: "dashboard"
25
- },
26
- {
27
- id: "charts",
28
- name: "Chart",
29
- isDefault: !0,
30
- created: (/* @__PURE__ */ new Date()).toISOString(),
31
- iconType: "chart"
32
- },
33
- {
34
- id: "data-analytics",
35
- name: "Data Analytics",
36
- isDefault: !0,
37
- created: (/* @__PURE__ */ new Date()).toISOString(),
38
- iconType: "folder"
39
- }
40
- ], z = class z {
41
- constructor() {
42
- a(this, "onPromptCreated", /* @__PURE__ */ g(() => {
43
- }, "onPromptCreated"));
44
- }
45
- getItem(t) {
46
- return localStorage.getItem(t);
47
- }
48
- setItem(t, e) {
49
- localStorage.setItem(t, e);
50
- }
51
- removeItem(t) {
52
- localStorage.removeItem(t);
53
- }
54
- initializeStorage() {
55
- try {
56
- const t = localStorage.getItem(w.SECTIONS);
57
- if (!t)
58
- localStorage.setItem(w.SECTIONS, JSON.stringify(L));
59
- else {
60
- const s = JSON.parse(t);
61
- if (L.some(
62
- (n) => !s.find((r) => r.id === n.id)
63
- )) {
64
- const n = [...s];
65
- L.forEach((r) => {
66
- s.find((l) => l.id === r.id) || n.push(r);
67
- }), localStorage.setItem(w.SECTIONS, JSON.stringify(n));
68
- }
69
- }
70
- const e = localStorage.getItem(w.ARTIFACTS);
71
- if (e) {
72
- const s = JSON.parse(e);
73
- let i = !1;
74
- const n = s.map((r) => {
75
- if (!r.sectionId) {
76
- i = !0;
77
- let l = "data-analytics";
78
- return r.type === x.Dashboard ? l = "dashboards" : r.type === x.Chart && (l = "charts"), {
79
- ...r,
80
- sectionId: l
81
- };
82
- }
83
- return r;
84
- });
85
- i && localStorage.setItem(w.ARTIFACTS, JSON.stringify(n));
86
- }
87
- } catch (t) {
88
- console.error("Error initializing storage:", t);
89
- }
90
- }
91
- getSections() {
92
- try {
93
- const t = localStorage.getItem(w.SECTIONS);
94
- return t ? JSON.parse(t) : L;
95
- } catch (t) {
96
- return console.error("Error loading sections:", t), L;
97
- }
98
- }
99
- getArtifacts() {
100
- try {
101
- const t = localStorage.getItem(w.ARTIFACTS);
102
- return t ? JSON.parse(t) : [];
103
- } catch (t) {
104
- return console.error("Error loading artifacts:", t), [];
105
- }
106
- }
107
- createSection(t, e = "folder") {
108
- const s = {
109
- id: crypto.randomUUID(),
110
- name: t,
111
- isDefault: !1,
112
- created: (/* @__PURE__ */ new Date()).toISOString(),
113
- iconType: e
114
- }, i = this.getSections();
115
- return i.push(s), localStorage.setItem(w.SECTIONS, JSON.stringify(i)), s;
116
- }
117
- updateSection(t, e) {
118
- const s = this.getSections(), i = s.findIndex((n) => n.id === t);
119
- i >= 0 && (s[i] = { ...s[i], ...e }, localStorage.setItem(w.SECTIONS, JSON.stringify(s)));
120
- }
121
- deleteSection(t) {
122
- const e = this.getSections(), s = e.find((i) => i.id === t);
123
- if (s && !s.isDefault) {
124
- 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);
125
- localStorage.setItem(w.ARTIFACTS, JSON.stringify(r));
126
- const l = e.filter((o) => o.id !== t);
127
- localStorage.setItem(w.SECTIONS, JSON.stringify(l));
128
- }
129
- }
130
- storeArtifact(t) {
131
- try {
132
- const e = this.getArtifacts(), s = e.findIndex((i) => i.id === t.id);
133
- if (s >= 0)
134
- e[s] = t;
135
- else {
136
- let i = "data-analytics";
137
- t.type === x.Dashboard ? i = "dashboards" : t.type === x.Chart && (i = "charts");
138
- const n = {
139
- ...t,
140
- created: t.created || (/* @__PURE__ */ new Date()).toISOString(),
141
- sectionId: t.sectionId || i
142
- };
143
- e.push(n);
144
- }
145
- localStorage.setItem(w.ARTIFACTS, JSON.stringify(e));
146
- } catch (e) {
147
- console.error("Error storing artifact:", e);
148
- }
149
- }
150
- moveArtifact(t, e) {
151
- const s = this.getArtifacts(), i = s.findIndex((n) => n.id === t);
152
- i >= 0 && (s[i] = { ...s[i], sectionId: e }, localStorage.setItem(w.ARTIFACTS, JSON.stringify(s)));
153
- }
154
- deleteArtifact(t) {
155
- const s = this.getArtifacts().filter((i) => i.id !== t);
156
- localStorage.setItem(w.ARTIFACTS, JSON.stringify(s));
157
- }
158
- updateArtifact(t, e) {
159
- const s = this.getArtifacts(), i = s.findIndex((n) => n.id === t);
160
- i >= 0 && (s[i] = { ...s[i], ...e }, localStorage.setItem(w.ARTIFACTS, JSON.stringify(s)));
161
- }
162
- getArtifactsBySection(t) {
163
- return this.getArtifacts().filter((s) => s.sectionId === t);
164
- }
165
- // Prompt management methods
16
+ }, bt = 50, K = class K {
166
17
  getPrompts() {
167
18
  try {
168
- const t = localStorage.getItem(w.PROMPTS);
169
- return t ? JSON.parse(t).sort((s, i) => new Date(i.created).getTime() - new Date(s.created).getTime()) : [];
19
+ const t = localStorage.getItem(W.PROMPTS);
20
+ return t ? JSON.parse(t).sort((s, a) => new Date(a.created).getTime() - new Date(s.created).getTime()) : [];
170
21
  } catch (t) {
171
22
  return console.error("Error loading prompts:", t), [];
172
23
  }
173
24
  }
25
+ /**
26
+ * Record a sent prompt, most recent first, de-duplicated by text.
27
+ *
28
+ * Asking the same thing again MOVES that entry to the top rather than adding
29
+ * a second copy — the history is a list of distinct things you have asked,
30
+ * and a repeated question spending two of the twelve visible rows costs a
31
+ * suggestion for nothing. The repeat's own `id` and `created` win, because
32
+ * what the list orders by is when you last asked.
33
+ *
34
+ * The dedupe used to look only at `prompts[0]`, and then unshifted anyway:
35
+ * a consecutive repeat overwrote the older copy's id and timestamp AND
36
+ * appended a new row, so the same text appeared twice with the same id.
37
+ *
38
+ * Matching is exact on `promptText` (`PromptUtils.createPrompt` has already
39
+ * trimmed it). Two prompts differing only in case or inner whitespace stay
40
+ * separate entries — that is deliberate, not an oversight: normalising them
41
+ * would mean re-surfacing text the user never typed.
42
+ */
174
43
  storePrompt(t) {
175
44
  try {
176
- const e = this.getPrompts();
177
- e.length > 0 && e[0].promptText === t.promptText && (e[0].created = t.created, e[0].id = t.id), e.unshift(t);
178
- const s = e.slice(0, 50);
179
- localStorage.setItem(w.PROMPTS, JSON.stringify(s));
45
+ const e = this.getPrompts().filter((s) => s.promptText !== t.promptText);
46
+ e.unshift(t), localStorage.setItem(W.PROMPTS, JSON.stringify(e.slice(0, bt)));
180
47
  } catch (e) {
181
48
  console.error("Error storing prompt:", e);
182
49
  }
183
50
  }
184
- deletePrompt(t) {
185
- try {
186
- const s = this.getPrompts().filter((i) => i.id !== t);
187
- localStorage.setItem(w.PROMPTS, JSON.stringify(s));
188
- } catch (e) {
189
- console.error("Error deleting prompt:", e);
190
- }
191
- }
192
51
  clearAllPrompts() {
193
52
  try {
194
- localStorage.removeItem(w.PROMPTS);
53
+ localStorage.removeItem(W.PROMPTS);
195
54
  } catch (t) {
196
55
  console.error("Error clearing prompts:", t);
197
56
  }
198
57
  }
199
58
  };
200
- g(z, "LocalStorageService");
201
- let ot = z;
202
- const te = /* @__PURE__ */ g((D) => {
59
+ f(K, "LocalStorageService");
60
+ let at = K;
61
+ const Vt = /* @__PURE__ */ f((D) => {
203
62
  const t = D.getPrompts(), e = t.length;
204
63
  if (e > 0) {
205
- const s = t[0].promptText, i = t[t.length - 1].promptText, n = t[0].created;
206
- return { promptState: e + "_" + s + "_" + i + "_" + n };
64
+ const s = t[0].promptText, a = t[t.length - 1].promptText, n = t[0].created;
65
+ return { promptState: e + "_" + s + "_" + a + "_" + n };
207
66
  } else
208
67
  return { promptState: "0" };
209
- }, "usePromptState"), Y = class Y {
68
+ }, "usePromptState"), J = class J {
210
69
  constructor() {
211
- a(this, "activityLost", "activityLost");
212
- a(this, "artifactGenerated", "artifactGenerated");
213
- a(this, "artifactSelected", "artifactSelected");
214
- a(this, "artifactDeleted", "artifactDeleted");
215
- a(this, "gatewayMessage", "gatewayMessage");
216
- a(this, "gatewayTurnComplete", "gatewayTurnComplete");
217
- a(this, "gatewayStreamError", "gatewayStreamError");
218
- a(this, "gatewayTurnOpen", "gatewayTurnOpen");
219
- a(this, "sessionCreated", "sessionCreated");
220
- a(this, "sessionUpdated", "sessionUpdated");
221
- a(this, "gatewayFunctionResponse", "gatewayFunctionResponse");
222
- a(this, "uiUnsavedPopoverToggle", "uiUnsavedPopoverToggle");
223
- a(this, "artifactsStorageUpdated", "artifactsStorageUpdated");
224
- a(this, "gatewayStreamEnded", "gatewayStreamEnded");
225
- a(this, "streamNewChunk", "streamNewChunk");
226
- a(this, "gatewayEndMessageData", "gatewayEndMessageData");
227
- a(this, "connectionStateChange", "connectionStateChange");
228
- a(this, "onMessageSent", "onMessageSent");
229
- a(this, "onMessageError", "onMessageError");
230
- a(this, "onToolEvent", "onToolEvent");
231
- a(this, "gatewayFirstToken", "gatewayFirstToken");
70
+ i(this, "activityLost", "activityLost");
71
+ i(this, "artifactGenerated", "artifactGenerated");
72
+ i(this, "artifactSelected", "artifactSelected");
73
+ i(this, "artifactDeleted", "artifactDeleted");
74
+ i(this, "gatewayMessage", "gatewayMessage");
75
+ i(this, "gatewayTurnComplete", "gatewayTurnComplete");
76
+ i(this, "gatewayStreamError", "gatewayStreamError");
77
+ i(this, "gatewayTurnOpen", "gatewayTurnOpen");
78
+ i(this, "sessionCreated", "sessionCreated");
79
+ i(this, "sessionUpdated", "sessionUpdated");
80
+ i(this, "gatewayFunctionResponse", "gatewayFunctionResponse");
81
+ i(this, "uiUnsavedPopoverToggle", "uiUnsavedPopoverToggle");
82
+ i(this, "artifactsStorageUpdated", "artifactsStorageUpdated");
83
+ i(this, "gatewayStreamEnded", "gatewayStreamEnded");
84
+ i(this, "streamNewChunk", "streamNewChunk");
85
+ i(this, "gatewayEndMessageData", "gatewayEndMessageData");
86
+ i(this, "connectionStateChange", "connectionStateChange");
87
+ i(this, "onMessageSent", "onMessageSent");
88
+ i(this, "onMessageError", "onMessageError");
89
+ i(this, "onToolEvent", "onToolEvent");
90
+ i(this, "gatewayFirstToken", "gatewayFirstToken");
232
91
  }
233
92
  };
234
- g(Y, "EventTypes");
235
- let J = Y;
236
- const c = new J(), j = class j {
93
+ f(J, "EventTypes");
94
+ let $ = J;
95
+ const o = new $(), z = class z {
237
96
  constructor() {
238
- a(this, "listeners", {});
239
- a(this, "listenersCount", {});
97
+ i(this, "listeners", {});
98
+ i(this, "listenersCount", {});
240
99
  }
241
100
  callListeners(t, ...e) {
242
101
  const s = this.listeners[t];
243
102
  if (this.listenersCount[t] = this.listenersCount[t] + 1, s) {
244
- const i = s.map((n) => n(...e));
245
- Promise.all(i).catch((n) => {
103
+ const a = s.map((n) => n(...e));
104
+ Promise.all(a).catch((n) => {
246
105
  console.error(`Lost error in one of the listeners of the event: ${t}, listeners: ${s.length}, error: ${n}`, s);
247
106
  });
248
107
  }
@@ -254,239 +113,239 @@ const c = new J(), j = class j {
254
113
  return this.listenersCount[t];
255
114
  }
256
115
  activityOnLost(t) {
257
- const e = c.activityLost;
116
+ const e = o.activityLost;
258
117
  this.addListener(e, t);
259
118
  }
260
119
  activityEmitLost() {
261
- this.callListeners(c.activityLost);
120
+ this.callListeners(o.activityLost);
262
121
  }
263
122
  /* typed artifact listeners */
264
123
  artifactOnGenerated(t) {
265
- const e = c.artifactGenerated;
124
+ const e = o.artifactGenerated;
266
125
  this.addListener(e, t);
267
126
  }
268
127
  artifactEmitGenerated(t) {
269
- this.callListeners(c.artifactGenerated, t);
128
+ this.callListeners(o.artifactGenerated, t);
270
129
  }
271
130
  artifactOffGenerated(t) {
272
- const e = c.artifactGenerated;
131
+ const e = o.artifactGenerated;
273
132
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
274
133
  }
275
134
  artifactOnSelected(t) {
276
- const e = c.artifactSelected;
135
+ const e = o.artifactSelected;
277
136
  this.addListener(e, t);
278
137
  }
279
138
  artifactEmitSelected(t) {
280
- this.callListeners(c.artifactSelected, t);
139
+ this.callListeners(o.artifactSelected, t);
281
140
  }
282
141
  artifactOffSelected(t) {
283
- const e = c.artifactSelected;
142
+ const e = o.artifactSelected;
284
143
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
285
144
  }
286
145
  artifactOnDeleted(t) {
287
- const e = c.artifactDeleted;
146
+ const e = o.artifactDeleted;
288
147
  this.addListener(e, t);
289
148
  }
290
149
  artifactEmitDeleted(t) {
291
- this.callListeners(c.artifactDeleted, t);
150
+ this.callListeners(o.artifactDeleted, t);
292
151
  }
293
152
  artifactOffDeleted(t) {
294
- const e = c.artifactDeleted;
153
+ const e = o.artifactDeleted;
295
154
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
296
155
  }
297
156
  gatewayOnMessage(t) {
298
- const e = c.gatewayMessage;
157
+ const e = o.gatewayMessage;
299
158
  this.addListener(e, t);
300
159
  }
301
160
  gatewayOnTurnComplete(t) {
302
- const e = c.gatewayTurnComplete;
161
+ const e = o.gatewayTurnComplete;
303
162
  this.addListener(e, t);
304
163
  }
305
164
  gatewayOnTurnOpen(t) {
306
- const e = c.gatewayTurnOpen;
165
+ const e = o.gatewayTurnOpen;
307
166
  this.addListener(e, t);
308
167
  }
309
168
  gatewayOnStreamError(t) {
310
- const e = c.gatewayStreamError;
169
+ const e = o.gatewayStreamError;
311
170
  this.addListener(e, t);
312
171
  }
313
172
  gatewayOnStreamEnded(t) {
314
- const e = c.gatewayStreamEnded;
173
+ const e = o.gatewayStreamEnded;
315
174
  this.addListener(e, t);
316
175
  }
317
176
  gatewayOffStreamEnded(t) {
318
- const e = c.gatewayStreamEnded;
177
+ const e = o.gatewayStreamEnded;
319
178
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
320
179
  }
321
180
  gatewayEmitStreamEnded(t, e) {
322
- this.callListeners(c.gatewayStreamEnded, t, e);
181
+ this.callListeners(o.gatewayStreamEnded, t, e);
323
182
  }
324
183
  gatewayEmitMessage(t, e = null) {
325
- this.callListeners(c.gatewayMessage, t, e);
184
+ this.callListeners(o.gatewayMessage, t, e);
326
185
  }
327
186
  gatewayEmitTurnComplete(t, e) {
328
- this.callListeners(c.gatewayTurnComplete, t, e);
187
+ this.callListeners(o.gatewayTurnComplete, t, e);
329
188
  }
330
189
  gatewayEmitStreamError(t) {
331
- this.callListeners(c.gatewayStreamError, t);
190
+ this.callListeners(o.gatewayStreamError, t);
332
191
  }
333
192
  gatewayEmitTurnOpen(t) {
334
- this.callListeners(c.gatewayTurnOpen, t);
193
+ this.callListeners(o.gatewayTurnOpen, t);
335
194
  }
336
195
  gatewayOffMessage(t) {
337
- const e = c.gatewayMessage;
196
+ const e = o.gatewayMessage;
338
197
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
339
198
  }
340
199
  gatewayOffTurnComplete(t) {
341
- const e = c.gatewayTurnComplete;
200
+ const e = o.gatewayTurnComplete;
342
201
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
343
202
  }
344
203
  gatewayOffTurnOpen(t) {
345
- const e = c.gatewayTurnOpen;
204
+ const e = o.gatewayTurnOpen;
346
205
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
347
206
  }
348
207
  gatewayOffStreamError(t) {
349
- const e = c.gatewayStreamError;
208
+ const e = o.gatewayStreamError;
350
209
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
351
210
  }
352
211
  sessionOnCreated(t) {
353
- const e = c.sessionCreated;
212
+ const e = o.sessionCreated;
354
213
  this.addListener(e, t);
355
214
  }
356
215
  chatOnMessageSent(t) {
357
- const e = c.onMessageSent;
216
+ const e = o.onMessageSent;
358
217
  this.addListener(e, t);
359
218
  }
360
219
  chatOffMessageSent(t) {
361
- const e = c.onMessageSent;
220
+ const e = o.onMessageSent;
362
221
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
363
222
  }
364
223
  ChatEmitMessageSent(t, e) {
365
- this.callListeners(c.onMessageSent, t, e);
224
+ this.callListeners(o.onMessageSent, t, e);
366
225
  }
367
226
  chatOnMessageError(t) {
368
- const e = c.onMessageError;
227
+ const e = o.onMessageError;
369
228
  this.addListener(e, t);
370
229
  }
371
230
  chatOffMessageError(t) {
372
- const e = c.onMessageError;
231
+ const e = o.onMessageError;
373
232
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
374
233
  }
375
234
  ChatEmitMessageError(t) {
376
- this.callListeners(c.onMessageError, t);
235
+ this.callListeners(o.onMessageError, t);
377
236
  }
378
237
  sessionOnUpdated(t) {
379
- const e = c.sessionUpdated;
238
+ const e = o.sessionUpdated;
380
239
  this.addListener(e, t);
381
240
  }
382
241
  sessionEmitCreated(t) {
383
- this.callListeners(c.sessionCreated, t);
242
+ this.callListeners(o.sessionCreated, t);
384
243
  }
385
244
  sessionEmitUpdated(t) {
386
- this.callListeners(c.sessionUpdated, t);
245
+ this.callListeners(o.sessionUpdated, t);
387
246
  }
388
247
  sessionOffCreated(t) {
389
- const e = c.sessionCreated;
248
+ const e = o.sessionCreated;
390
249
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
391
250
  }
392
251
  sessionOffUpdated(t) {
393
- const e = c.sessionUpdated;
252
+ const e = o.sessionUpdated;
394
253
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
395
254
  }
396
255
  gatewayEmitFunctionResponse(t) {
397
- this.callListeners(c.gatewayFunctionResponse, t);
256
+ this.callListeners(o.gatewayFunctionResponse, t);
398
257
  }
399
258
  gatewayOffFunctionResponse(t) {
400
- const e = c.gatewayFunctionResponse;
259
+ const e = o.gatewayFunctionResponse;
401
260
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
402
261
  }
403
262
  gatewayOnFunctionResponse(t) {
404
- const e = c.gatewayFunctionResponse;
263
+ const e = o.gatewayFunctionResponse;
405
264
  this.addListener(e, t);
406
265
  }
407
266
  // UI events
408
267
  uiOnUnsavedPopoverToggle(t) {
409
- const e = c.uiUnsavedPopoverToggle;
268
+ const e = o.uiUnsavedPopoverToggle;
410
269
  this.addListener(e, t);
411
270
  }
412
271
  uiEmitUnsavedPopoverToggle(t) {
413
- this.callListeners(c.uiUnsavedPopoverToggle, t);
272
+ this.callListeners(o.uiUnsavedPopoverToggle, t);
414
273
  }
415
274
  uiOffUnsavedPopoverToggle(t) {
416
- const e = c.uiUnsavedPopoverToggle;
275
+ const e = o.uiUnsavedPopoverToggle;
417
276
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
418
277
  }
419
278
  // Artifacts storage update events
420
279
  artifactsOnStorageUpdated(t) {
421
- const e = c.artifactsStorageUpdated;
280
+ const e = o.artifactsStorageUpdated;
422
281
  this.addListener(e, t);
423
282
  }
424
283
  artifactsEmitStorageUpdated() {
425
- this.callListeners(c.artifactsStorageUpdated);
284
+ this.callListeners(o.artifactsStorageUpdated);
426
285
  }
427
286
  artifactsOffStorageUpdated(t) {
428
- const e = c.artifactsStorageUpdated;
287
+ const e = o.artifactsStorageUpdated;
429
288
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
430
289
  }
431
290
  streamOnNewChunk(t) {
432
- const e = c.streamNewChunk;
291
+ const e = o.streamNewChunk;
433
292
  this.addListener(e, t);
434
293
  }
435
294
  streamEmitNewChunk(t) {
436
- this.callListeners(c.streamNewChunk, t);
295
+ this.callListeners(o.streamNewChunk, t);
437
296
  }
438
297
  streamOffNewChunk(t) {
439
- const e = c.streamNewChunk;
298
+ const e = o.streamNewChunk;
440
299
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
441
300
  }
442
301
  gatewayOnEndMessageData(t) {
443
- const e = c.gatewayEndMessageData;
302
+ const e = o.gatewayEndMessageData;
444
303
  this.addListener(e, t);
445
304
  }
446
305
  gatewayEmitEndMessageData(t) {
447
- this.callListeners(c.gatewayEndMessageData, t);
306
+ this.callListeners(o.gatewayEndMessageData, t);
448
307
  }
449
308
  gatewayOffEndMessageData(t) {
450
- const e = c.gatewayEndMessageData;
309
+ const e = o.gatewayEndMessageData;
451
310
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
452
311
  }
453
312
  gatewayOnConnectionStateChange(t) {
454
- const e = c.connectionStateChange;
313
+ const e = o.connectionStateChange;
455
314
  this.addListener(e, t);
456
315
  }
457
316
  gatewayEmitConnectionStateChange(t) {
458
- this.callListeners(c.connectionStateChange, t);
317
+ this.callListeners(o.connectionStateChange, t);
459
318
  }
460
319
  gatewayOffConnectionStateChange(t) {
461
- const e = c.connectionStateChange;
320
+ const e = o.connectionStateChange;
462
321
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
463
322
  }
464
323
  gatewayOnToolEvent(t) {
465
- const e = c.onToolEvent;
324
+ const e = o.onToolEvent;
466
325
  this.addListener(e, t);
467
326
  }
468
327
  gatewayEmitToolEvent(t, e, s) {
469
- this.callListeners(c.onToolEvent, t, e, s);
328
+ this.callListeners(o.onToolEvent, t, e, s);
470
329
  }
471
330
  gatewayOffToolEvent(t) {
472
- const e = c.onToolEvent;
331
+ const e = o.onToolEvent;
473
332
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
474
333
  }
475
334
  gatewayOnFirstToken(t) {
476
- const e = c.gatewayFirstToken;
335
+ const e = o.gatewayFirstToken;
477
336
  this.addListener(e, t);
478
337
  }
479
338
  gatewayEmitFirstToken(t) {
480
- this.callListeners(c.gatewayFirstToken, t);
339
+ this.callListeners(o.gatewayFirstToken, t);
481
340
  }
482
341
  gatewayOffFirstToken(t) {
483
- const e = c.gatewayFirstToken;
342
+ const e = o.gatewayFirstToken;
484
343
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
485
344
  }
486
345
  };
487
- g(j, "EventBusService");
488
- let G = j;
489
- const X = class X extends G {
346
+ f(z, "EventBusService");
347
+ let q = z;
348
+ const Y = class Y extends q {
490
349
  constructor() {
491
350
  super();
492
351
  }
@@ -494,7 +353,7 @@ const X = class X extends G {
494
353
  console.log("MockEventBusService.gatewayEmitConnectionStateChange");
495
354
  }
496
355
  gatewayEmitMessage(t, e) {
497
- wt() ? process.stdout.write(`M${t.version}, `) : console.log("MockEventBusService.gatewayEmitMessage");
356
+ mt() ? process.stdout.write(`M${t.version}, `) : console.log("MockEventBusService.gatewayEmitMessage");
498
357
  }
499
358
  gatewayEmitTurnComplete(t, e) {
500
359
  console.log("MockEventBusService.gatewayEmitTurnComplete");
@@ -512,73 +371,96 @@ const X = class X extends G {
512
371
  console.log("MockEventBusService.gatewayOffFunctionResponse", t);
513
372
  }
514
373
  };
515
- g(X, "MockEventBusService");
516
- let ct = X;
517
- const Rt = 2e3, pt = {
374
+ f(Y, "MockEventBusService");
375
+ let rt = Y;
376
+ const Rt = 2e3, gt = {
518
377
  inline: "inline",
519
378
  block: "block"
520
- }, Q = class Q {
379
+ }, X = class X {
521
380
  constructor() {
522
- a(this, "parts", []);
523
- a(this, "isLastGroup", !1);
524
- a(this, "hasThoughts", !1);
525
- a(this, "lastWithThoughts", !1);
526
- a(this, "type", pt.inline);
381
+ i(this, "parts", []);
382
+ i(this, "isLastGroup", !1);
383
+ i(this, "hasThoughts", !1);
384
+ i(this, "lastWithThoughts", !1);
385
+ /**
386
+ * A run of CONSECUTIVE thought parts — one continuous piece of reasoning
387
+ * that `merge` split at {@link MAX_CHAR_PER_TEXT_PART} to keep a very long
388
+ * prose from dragging the browser down.
389
+ *
390
+ * The split is a rendering optimisation and must not be legible as one: the
391
+ * reader gets a single "Pensando…" block whatever the chunk count, drawn by
392
+ * the run's chrome, while each chunk stays its own memoized MessagePart —
393
+ * which is where the CPU saving actually comes from.
394
+ */
395
+ i(this, "isThoughtRun", !1);
396
+ i(this, "type", gt.inline);
527
397
  }
528
398
  };
529
- g(Q, "InteractionPartGroup");
530
- let $ = Q;
531
- const Z = class Z {
399
+ f(X, "InteractionPartGroup");
400
+ let x = X;
401
+ const j = class j {
532
402
  constructor(t, e) {
533
- a(this, "interaction");
534
- a(this, "eventBusService");
535
- a(this, "parseTextIntoParts", /* @__PURE__ */ g((t) => {
403
+ i(this, "interaction");
404
+ i(this, "eventBusService");
405
+ i(this, "parseTextIntoParts", /* @__PURE__ */ f((t) => {
536
406
  if (!t || t.trim().length == 0) return [];
537
- const e = At().use(kt).parse(t), s = [];
538
- let i = null;
407
+ const e = Dt().use(Ot).parse(t), s = [];
408
+ let a = null;
539
409
  for (const n of e.children)
540
- n.type === "code" ? (i && (s.push(i), i = null), n.lang === "htmlCanvas" && s.push(`
410
+ n.type === "code" ? (a && (s.push(a), a = null), n.lang === "htmlCanvas" && s.push(`
541
411
  \`\`\`liveTsx
542
412
  ${n.value}
543
413
  \`\`\`
544
- `)) : (i || (i = ""), i += Nt(n));
545
- return i && s.push(i), s;
414
+ `)) : (a || (a = ""), a += kt(n));
415
+ return a && s.push(a), s;
546
416
  }, "parseTextIntoParts"));
547
417
  this.interaction = t, this.eventBusService = e;
548
418
  }
549
419
  expandSubParts(t, e) {
550
- const s = this.parseTextIntoParts(t), i = [];
420
+ const s = this.parseTextIntoParts(t), a = [];
551
421
  let n = 0;
552
422
  for (const r of s) {
553
- const l = _.fromText(r);
554
- l.id = n + "_" + e, i.push(l), n++;
423
+ const l = N.fromText(r);
424
+ l.id = n + "_" + e, a.push(l), n++;
555
425
  }
556
- return i;
426
+ return a;
557
427
  }
558
428
  groupPartsByDisplayType(t, e = !0, s = !1) {
559
- var l, o, d;
560
- const i = [];
561
- let n = new $();
429
+ var l, c, d;
430
+ const a = [];
431
+ let n = new x();
562
432
  for (let u = 0; u < t.length; u++) {
563
433
  const h = t[u];
564
- let p = !((((l = h.functionDetails) == null ? void 0 : l.isUi) ?? !1) || ((o = h.functionDetails) == null ? void 0 : o.cancelUi) !== !0 && (((d = h.functionDetails) == null ? void 0 : d.isAskUser) ?? !1)) && h.eventType !== I.Text && h.eventType !== I.Thought && (h.eventType === I.FunctionCall || h.eventType === I.PartialFunctionCall || h.eventType === I.FunctionResponse) && u < t.length - 1;
565
- !e && p && !s || (p ? (h.eventType == I.Thought && (n.hasThoughts = !0), n.parts.push(h), n.isLastGroup = u === t.length - 1) : (n.parts.length > 0 && (i.push(n), n = new $()), i.push({
566
- type: pt.block,
567
- parts: [h],
568
- isLastGroup: u === t.length - 1,
569
- hasThoughts: !1,
570
- lastWithThoughts: !1
571
- })));
434
+ let p = !((((l = h.functionDetails) == null ? void 0 : l.isUi) ?? !1) || ((c = h.functionDetails) == null ? void 0 : c.cancelUi) !== !0 && (((d = h.functionDetails) == null ? void 0 : d.isAskUser) ?? !1)) && h.eventType !== T.Text && h.eventType !== T.Thought && (h.eventType === T.FunctionCall || h.eventType === T.PartialFunctionCall || h.eventType === T.FunctionResponse) && u < t.length - 1;
435
+ if (!(!e && p && !s))
436
+ if (p)
437
+ h.eventType == T.Thought && (n.hasThoughts = !0), n.parts.push(h), n.isLastGroup = u === t.length - 1;
438
+ else {
439
+ n.parts.length > 0 && (a.push(n), n = new x());
440
+ const M = h.eventType === T.Thought, w = a[a.length - 1];
441
+ if (M && (w != null && w.isThoughtRun)) {
442
+ w.parts.push(h), w.isLastGroup = u === t.length - 1;
443
+ continue;
444
+ }
445
+ a.push({
446
+ type: gt.block,
447
+ parts: [h],
448
+ isLastGroup: u === t.length - 1,
449
+ hasThoughts: !1,
450
+ lastWithThoughts: !1,
451
+ isThoughtRun: M
452
+ });
453
+ }
572
454
  }
573
- n.parts.length > 0 && i.push(n);
574
- const r = i.filter((u) => u.hasThoughts);
575
- return r.length > 0 && (r[r.length - 1].lastWithThoughts = !0), i;
455
+ n.parts.length > 0 && a.push(n);
456
+ const r = a.filter((u) => u.hasThoughts);
457
+ return r.length > 0 && (r[r.length - 1].lastWithThoughts = !0), a;
576
458
  }
577
459
  isFunctionCall(t) {
578
- return t == I.FunctionCall || t == I.PartialFunctionCall;
460
+ return t == T.FunctionCall || t == T.PartialFunctionCall;
579
461
  }
580
462
  isFunctionResponse(t) {
581
- return t == I.FunctionResponse;
463
+ return t == T.FunctionResponse;
582
464
  }
583
465
  // Computes the next interaction from a server event. Pure with respect to
584
466
  // `prev` — no part or array on the prior tree is mutated; modified entities
@@ -586,54 +468,54 @@ ${n.value}
586
468
  // new tree as the last step, so snapshots already handed out to throttled
587
469
  // subscribers can't diverge from the live state.
588
470
  merge(t) {
589
- var b, F, y, A, N, st, nt, it;
590
- const e = this.interaction, s = [], i = [], n = _.FlatParts(t == null ? void 0 : t.parts), r = e.parts[e.parts.length - 1] ?? null;
471
+ var _, b, y, O, A, tt, et, st;
472
+ const e = this.interaction, s = [], a = [], n = N.FlatParts(t == null ? void 0 : t.parts), r = e.parts[e.parts.length - 1] ?? null;
591
473
  let l = !1;
592
- n && (l = !r || n.mustPush || n.mustPush === !1 && (n.eventType !== (r == null ? void 0 : r.eventType) || ((b = n == null ? void 0 : n.functionDetails) == null ? void 0 : b.id) !== ((F = r.functionDetails) == null ? void 0 : F.id)));
593
- let o = e.parts, d = e.functionMap ?? /* @__PURE__ */ new Map(), u = !e.functionMap;
594
- const h = /* @__PURE__ */ g(() => {
474
+ n && (l = !r || n.mustPush || n.mustPush === !1 && (n.eventType !== (r == null ? void 0 : r.eventType) || ((_ = n == null ? void 0 : n.functionDetails) == null ? void 0 : _.id) !== ((b = r.functionDetails) == null ? void 0 : b.id)));
475
+ let c = e.parts, d = e.functionMap ?? /* @__PURE__ */ new Map(), u = !e.functionMap;
476
+ const h = /* @__PURE__ */ f(() => {
595
477
  u || (d = new Map(d), u = !0);
596
- }, "cloneFunctionMap"), C = /* @__PURE__ */ g(() => {
597
- o === e.parts && (o = e.parts.slice());
478
+ }, "cloneFunctionMap"), C = /* @__PURE__ */ f(() => {
479
+ c === e.parts && (c = e.parts.slice());
598
480
  }, "clonePartsIfShared");
599
- if (!l && (o == null ? void 0 : o.length) > 0 && (n != null && n.textAppendable)) {
600
- const f = o[o.length - 1];
601
- (((A = (y = f.thoughtDetails) == null ? void 0 : y.text) == null ? void 0 : A.length) ?? ((N = f.text) == null ? void 0 : N.length) ?? 0) > Rt && (l = !0);
481
+ if (!l && (c == null ? void 0 : c.length) > 0 && (n != null && n.textAppendable)) {
482
+ const g = c[c.length - 1];
483
+ (((O = (y = g.thoughtDetails) == null ? void 0 : y.text) == null ? void 0 : O.length) ?? ((A = g.text) == null ? void 0 : A.length) ?? 0) > Rt && (l = !0);
602
484
  }
603
485
  let p = !1;
604
- if ((n == null ? void 0 : n.eventType) === I.FunctionClientOutput && !!((st = n.functionDetails) != null && st.id) && n) {
605
- const f = n.functionDetails.id, T = n.functionDetails.clientOutput, E = o.findIndex((S) => {
486
+ if ((n == null ? void 0 : n.eventType) === T.FunctionClientOutput && !!((tt = n.functionDetails) != null && tt.id) && n) {
487
+ const g = n.functionDetails.id, v = n.functionDetails.clientOutput, E = c.findIndex((S) => {
606
488
  var m;
607
- return ((m = S.functionDetails) == null ? void 0 : m.id) === f;
489
+ return ((m = S.functionDetails) == null ? void 0 : m.id) === g;
608
490
  });
609
491
  if (E > -1) {
610
- const S = o[E], m = {
492
+ const S = c[E], m = {
611
493
  ...S,
612
494
  functionDetails: {
613
495
  ...S.functionDetails,
614
- clientOutput: T ?? S.functionDetails.clientOutput,
496
+ clientOutput: v ?? S.functionDetails.clientOutput,
615
497
  // Sticky true-wins: this event IS the park, and a later merge must not clear it.
616
498
  parked: n.functionDetails.parked === !0 || S.functionDetails.parked === !0
617
499
  }
618
500
  };
619
- C(), o[E] = m, h(), d.set(f, m), s.push(m);
501
+ C(), c[E] = m, h(), d.set(g, m), s.push(m);
620
502
  } else {
621
503
  const S = {
622
504
  ...n,
623
- id: o.length + 1 + "-" + e.interactionId,
505
+ id: c.length + 1 + "-" + e.interactionId,
624
506
  functionDetails: { ...n.functionDetails, silent: !0 }
625
507
  };
626
- C(), o = o === e.parts ? e.parts.slice() : o, o.push(S), h(), d.set(f, S);
508
+ C(), c = c === e.parts ? e.parts.slice() : c, c.push(S), h(), d.set(g, S);
627
509
  }
628
510
  } else if (l && n) {
629
- const f = this.isFunctionCall(n.eventType) || this.isFunctionResponse(n.eventType), T = f ? (nt = n.functionDetails) == null ? void 0 : nt.id : void 0;
630
- f && !T && console.error("Got isCall or isResponse without a callId", n);
631
- const E = T ? d.get(T) : void 0;
632
- if (E && T && n.functionDetails) {
633
- const S = o.findIndex((mt) => {
634
- var at;
635
- return ((at = mt.functionDetails) == null ? void 0 : at.id) === T;
636
- }), m = S > -1 ? o[S] : E, R = {
511
+ const g = this.isFunctionCall(n.eventType) || this.isFunctionResponse(n.eventType), v = g ? (et = n.functionDetails) == null ? void 0 : et.id : void 0;
512
+ g && !v && console.error("Got isCall or isResponse without a callId", n);
513
+ const E = v ? d.get(v) : void 0;
514
+ if (E && v && n.functionDetails) {
515
+ const S = c.findIndex((ft) => {
516
+ var nt;
517
+ return ((nt = ft.functionDetails) == null ? void 0 : nt.id) === v;
518
+ }), m = S > -1 ? c[S] : E, R = {
637
519
  ...m,
638
520
  eventType: n.eventType,
639
521
  functionDetails: {
@@ -674,65 +556,65 @@ ${n.value}
674
556
  parked: n.functionDetails.parked === !0 || m.functionDetails.parked === !0
675
557
  }
676
558
  };
677
- h(), d.set(T, R), R.eventType === I.FunctionResponse && this.eventBusService.gatewayEmitFunctionResponse(R.functionDetails), s.push(R), S > -1 && (C(), o[S] = R);
559
+ h(), d.set(v, R), R.eventType === T.FunctionResponse && this.eventBusService.gatewayEmitFunctionResponse(R.functionDetails), s.push(R), S > -1 && (C(), c[S] = R);
678
560
  } else {
679
- if (T && n.functionDetails && !E && (h(), d.set(T, n)), r && r.textAppendable) {
561
+ if (v && n.functionDetails && !E && (h(), d.set(v, n)), r && r.textAppendable) {
680
562
  const m = {
681
563
  ...r,
682
564
  ended: /* @__PURE__ */ new Date(),
683
565
  isStillWriting: !1
684
566
  };
685
- C(), o[o.length - 1] = m, s.push(m);
567
+ C(), c[c.length - 1] = m, s.push(m);
686
568
  }
687
569
  const S = {
688
570
  ...n,
689
- id: o.length + 1 + "-" + e.interactionId,
571
+ id: c.length + 1 + "-" + e.interactionId,
690
572
  isStillWriting: n.textAppendable,
691
573
  partial: t.partial
692
574
  };
693
- (it = S.functionDetails) != null && it.silent || s.push(S), o = [...o, S], p = !0;
575
+ (st = S.functionDetails) != null && st.silent || s.push(S), c = [...c, S], p = !0;
694
576
  }
695
577
  }
696
- let M = o[o.length - 1] ?? null;
697
- if (M && n && n.textAppendable) {
698
- const f = {
699
- ...M,
578
+ let w = c[c.length - 1] ?? null;
579
+ if (w && n && n.textAppendable) {
580
+ const g = {
581
+ ...w,
700
582
  partial: t.partial,
701
- textDetails: M.textDetails ? { ...M.textDetails } : { version: 0 }
583
+ textDetails: w.textDetails ? { ...w.textDetails } : { version: 0 }
702
584
  };
703
- let T = !1;
585
+ let v = !1;
704
586
  if (t.partial) {
705
587
  try {
706
- f.textDetails.version++, p || (f.text = (M.text ?? "") + (n.text ?? ""));
588
+ g.textDetails.version++, p || (g.text = (w.text ?? "") + (n.text ?? ""));
707
589
  } catch (E) {
708
590
  console.error("Error here", E.toString());
709
591
  }
710
- f.textLastChunk = n.text ?? "", f.isStillWriting = !0, T = !0, n.thoughtDetails && f.thoughtDetails && (n.thoughtDetails.text.length >= 50 || n.thoughtDetails.text.length < 50 && n.thoughtDetails.text !== f.thoughtDetails.text) && (f.thoughtDetails = {
711
- ...f.thoughtDetails,
712
- text: f.thoughtDetails.text + n.thoughtDetails.text
713
- }, f.thoughtLastChunk = n.thoughtDetails.text);
592
+ g.textLastChunk = n.text ?? "", g.isStillWriting = !0, v = !0, !p && n.thoughtDetails && g.thoughtDetails && (n.thoughtDetails.text.length >= 50 || n.thoughtDetails.text.length < 50 && n.thoughtDetails.text !== g.thoughtDetails.text) && (g.thoughtDetails = {
593
+ ...g.thoughtDetails,
594
+ text: g.thoughtDetails.text + n.thoughtDetails.text
595
+ }, g.thoughtLastChunk = n.thoughtDetails.text);
714
596
  } else
715
- f.isStillWriting = !1, f.text = n.text ?? "", f.textDetails.version++, n.thoughtDetails && (f.thoughtDetails = {
597
+ g.isStillWriting = !1, g.text = n.text ?? "", g.textDetails.version++, n.thoughtDetails && (g.thoughtDetails = {
716
598
  ...n.thoughtDetails,
717
599
  text: n.thoughtDetails.text.trim()
718
- }), T = !l;
719
- C(), o[o.length - 1] = f, M = f, T && s.push(f);
600
+ }), v = !l;
601
+ C(), c[c.length - 1] = g, w = g, v && s.push(g);
720
602
  }
721
- let v = e.artifactData ?? [];
603
+ let I = e.artifactData ?? [];
722
604
  if (t.llmArtifacts && t.llmArtifacts.length > 0) {
723
- let f = !1;
724
- for (const T of t.llmArtifacts) {
725
- const E = T.toArtifact();
726
- f || (v = v.slice(), f = !0);
727
- const S = v.findIndex((m) => m.id === E.id);
728
- S === -1 ? v.push(E) : v[S] = E;
605
+ let g = !1;
606
+ for (const v of t.llmArtifacts) {
607
+ const E = v.toArtifact();
608
+ g || (I = I.slice(), g = !0);
609
+ const S = I.findIndex((m) => m.id === E.id);
610
+ S === -1 ? I.push(E) : I[S] = E;
729
611
  }
730
612
  }
731
613
  const k = {
732
614
  ...e,
733
615
  version: e.version + 1,
734
- parts: o,
735
- artifactData: v,
616
+ parts: c,
617
+ artifactData: I,
736
618
  functionMap: d,
737
619
  turn_complete: t.turn_complete,
738
620
  partial: t.partial,
@@ -741,7 +623,7 @@ ${n.value}
741
623
  return this.interaction = k, {
742
624
  updatedInteraction: k,
743
625
  updatedParts: s,
744
- newArtifacts: i,
626
+ newArtifacts: a,
745
627
  mainBranch: k,
746
628
  analyticsBranch: null,
747
629
  analyticsBranchPartsChanged: null,
@@ -749,86 +631,86 @@ ${n.value}
749
631
  };
750
632
  }
751
633
  };
752
- g(Z, "InteractionService");
753
- let q = Z;
754
- const Ut = 1200 * 1e3, P = class P {
755
- constructor(t, e, s, i, n, r, l, o, d, u = Tt.Interactive) {
756
- a(this, "base_production_url", yt() ?? "https://agent.tripapi.com.br");
757
- a(this, "base_url_local", "http://localagent:8000");
758
- a(this, "base_url");
759
- a(this, "isLocal", !1);
760
- a(this, "msg_order", 0);
761
- a(this, "lastPing", /* @__PURE__ */ new Date());
762
- a(this, "interactionsMap", /* @__PURE__ */ new Map());
763
- a(this, "interactionsServiceMap", /* @__PURE__ */ new Map());
764
- a(this, "user");
765
- a(this, "config");
766
- a(this, "currentIS", null);
767
- a(this, "server_session_id");
768
- a(this, "model_session_id");
769
- a(this, "runMode");
770
- a(this, "sessionState");
771
- a(this, "storageService");
772
- a(this, "notificationPort");
773
- a(this, "interactionCallIds", /* @__PURE__ */ new Map());
774
- a(this, "rawJwt");
775
- a(this, "sessionId");
776
- a(this, "isInited", !1);
634
+ f(j, "InteractionService");
635
+ let B = j;
636
+ const Ft = 1200 * 1e3, P = class P {
637
+ constructor(t, e, s, a, n, r, l, c, d, u = Tt.Interactive) {
638
+ i(this, "base_production_url", St() ?? "https://agent.tripapi.com.br");
639
+ i(this, "base_url_local", "http://localagent:8000");
640
+ i(this, "base_url");
641
+ i(this, "isLocal", !1);
642
+ i(this, "msg_order", 0);
643
+ i(this, "lastPing", /* @__PURE__ */ new Date());
644
+ i(this, "interactionsMap", /* @__PURE__ */ new Map());
645
+ i(this, "interactionsServiceMap", /* @__PURE__ */ new Map());
646
+ i(this, "user");
647
+ i(this, "config");
648
+ i(this, "currentIS", null);
649
+ i(this, "server_session_id");
650
+ i(this, "model_session_id");
651
+ i(this, "runMode");
652
+ i(this, "sessionState");
653
+ i(this, "storageService");
654
+ i(this, "notificationPort");
655
+ i(this, "interactionCallIds", /* @__PURE__ */ new Map());
656
+ i(this, "rawJwt");
657
+ i(this, "sessionId");
658
+ i(this, "isInited", !1);
777
659
  //Define all SSEServer methods here, use from SSEServer.ts
778
- a(this, "eventBusService");
779
- a(this, "artifactService");
780
- a(this, "onTurnOpen", /* @__PURE__ */ g((t) => {
660
+ i(this, "eventBusService");
661
+ i(this, "artifactService");
662
+ i(this, "onTurnOpen", /* @__PURE__ */ f((t) => {
781
663
  this.eventBusService.gatewayOnTurnOpen(t);
782
664
  }, "onTurnOpen"));
783
- a(this, "offTurnOpen", /* @__PURE__ */ g((t) => {
665
+ i(this, "offTurnOpen", /* @__PURE__ */ f((t) => {
784
666
  this.eventBusService.gatewayOffTurnOpen(t);
785
667
  }, "offTurnOpen"));
786
- a(this, "onTurnComplete", /* @__PURE__ */ g((t) => {
668
+ i(this, "onTurnComplete", /* @__PURE__ */ f((t) => {
787
669
  this.eventBusService.gatewayOnTurnComplete(t);
788
670
  }, "onTurnComplete"));
789
- a(this, "offTurnComplete", /* @__PURE__ */ g((t) => {
671
+ i(this, "offTurnComplete", /* @__PURE__ */ f((t) => {
790
672
  this.eventBusService.gatewayOffTurnComplete(t);
791
673
  }, "offTurnComplete"));
792
- a(this, "onStreamError", /* @__PURE__ */ g((t) => {
674
+ i(this, "onStreamError", /* @__PURE__ */ f((t) => {
793
675
  this.eventBusService.gatewayOnStreamError(t);
794
676
  }, "onStreamError"));
795
- a(this, "offStreamError", /* @__PURE__ */ g((t) => {
677
+ i(this, "offStreamError", /* @__PURE__ */ f((t) => {
796
678
  this.eventBusService.gatewayOffStreamError(t);
797
679
  }, "offStreamError"));
798
- a(this, "onStreamEnded", /* @__PURE__ */ g((t) => {
680
+ i(this, "onStreamEnded", /* @__PURE__ */ f((t) => {
799
681
  this.eventBusService.gatewayOnStreamEnded(t);
800
682
  }, "onStreamEnded"));
801
- a(this, "offStreamEnded", /* @__PURE__ */ g((t) => {
683
+ i(this, "offStreamEnded", /* @__PURE__ */ f((t) => {
802
684
  this.eventBusService.gatewayOffStreamEnded(t);
803
685
  }, "offStreamEnded"));
804
- a(this, "onMessage", /* @__PURE__ */ g((t) => {
686
+ i(this, "onMessage", /* @__PURE__ */ f((t) => {
805
687
  this.eventBusService.gatewayOnMessage(t);
806
688
  }, "onMessage"));
807
- a(this, "offMessage", /* @__PURE__ */ g((t) => {
689
+ i(this, "offMessage", /* @__PURE__ */ f((t) => {
808
690
  this.eventBusService.gatewayOffMessage(t);
809
691
  }, "offMessage"));
810
- a(this, "onFirstToken", /* @__PURE__ */ g((t) => {
692
+ i(this, "onFirstToken", /* @__PURE__ */ f((t) => {
811
693
  this.eventBusService.gatewayOnFirstToken(t);
812
694
  }, "onFirstToken"));
813
- a(this, "offFirstToken", /* @__PURE__ */ g((t) => {
695
+ i(this, "offFirstToken", /* @__PURE__ */ f((t) => {
814
696
  this.eventBusService.gatewayOffFirstToken(t);
815
697
  }, "offFirstToken"));
816
- a(this, "onFunctionResponse", /* @__PURE__ */ g((t) => {
698
+ i(this, "onFunctionResponse", /* @__PURE__ */ f((t) => {
817
699
  this.eventBusService.gatewayOnFunctionResponse(t);
818
700
  }, "onFunctionResponse"));
819
- a(this, "offFunctionResponse", /* @__PURE__ */ g((t) => {
701
+ i(this, "offFunctionResponse", /* @__PURE__ */ f((t) => {
820
702
  this.eventBusService.gatewayOffFunctionResponse(t);
821
703
  }, "offFunctionResponse"));
822
- a(this, "toolSessionId", null);
823
- a(this, "pendingCurrentMessage", null);
824
- a(this, "lastCurrentMessageUpdate", 0);
825
- a(this, "runningRequests", /* @__PURE__ */ new Map());
826
- a(this, "lastToolInteraction", "");
827
- a(this, "subAgentInteractions", /* @__PURE__ */ new Map());
828
- a(this, "subAgentInteractionServices", /* @__PURE__ */ new Map());
829
- a(this, "lastThorttledTimeout", null);
830
- a(this, "lastPingStatus", !1);
831
- this.user = t, this.config = n, this.rawJwt = t.access_token, this.base_url = i, this.eventBusService = e, this.sessionId = d, this.runMode = u, this.artifactService = s, this.sessionState = r.getState(), this.notificationPort = l, this.storageService = o, r.subscribe((h, C) => {
704
+ i(this, "toolSessionId", null);
705
+ i(this, "pendingCurrentMessage", null);
706
+ i(this, "lastCurrentMessageUpdate", 0);
707
+ i(this, "runningRequests", /* @__PURE__ */ new Map());
708
+ i(this, "lastToolInteraction", "");
709
+ i(this, "subAgentInteractions", /* @__PURE__ */ new Map());
710
+ i(this, "subAgentInteractionServices", /* @__PURE__ */ new Map());
711
+ i(this, "lastThorttledTimeout", null);
712
+ i(this, "lastPingStatus", !1);
713
+ this.user = t, this.config = n, this.rawJwt = t.access_token, this.base_url = a, this.eventBusService = e, this.sessionId = d, this.runMode = u, this.artifactService = s, this.sessionState = r.getState(), this.notificationPort = l, this.storageService = c, r.subscribe((h, C) => {
832
714
  this.sessionState = h;
833
715
  });
834
716
  }
@@ -847,6 +729,12 @@ const Ut = 1200 * 1e3, P = class P {
847
729
  answerHumanTool(t, e) {
848
730
  return console.warn("answerHumanTool: not supported by this gateway", t, e), "queued";
849
731
  }
732
+ /**
733
+ * The agent this gateway speaks to — the ONE truth for the conversation.
734
+ * `sendMessageInternal` stamps every outbound frame's `AgentId` from it,
735
+ * and the session manager binds/rebinds against it. Fixed at construction;
736
+ * see {@link forceAgentContext} for the single exception (issue #59).
737
+ */
850
738
  getAgentContext() {
851
739
  return this.config;
852
740
  }
@@ -857,25 +745,28 @@ const Ut = 1200 * 1e3, P = class P {
857
745
  this.config = { ...this.config, model: t };
858
746
  }
859
747
  /**
860
- * Live update for the agent / customer slice of the gateway's
861
- * config. Mirrors {@link setModel}'s in-place pattern so the
862
- * next outgoing message — `sendMessageInternal` reads
863
- * `this.config.agentConfig?.id` directly at send time, see
864
- * `AgentGatewayWSAsync.sendMessageInternal` — picks up the new
865
- * id without rebuilding the gateway or tearing down the
866
- * WebSocket. This is what the host calls from the agent picker
867
- * so switching agents preserves the current session's
868
- * connection, chat history, and any in-flight stream state
869
- * instead of remounting `AiChatProvider` and losing them.
748
+ * Live update for the ordinary, non-identity slice of the context — the
749
+ * dataset/customer the same agent works over. No "force" needed: swapping
750
+ * datasets mid-conversation is routine and changes nothing about who is
751
+ * answering.
752
+ */
753
+ setCustomer(t) {
754
+ this.config = { ...this.config, customer: t };
755
+ }
756
+ /**
757
+ * Replace the AGENT mid-conversation. The escape hatch for an agent picker,
758
+ * and nothing else: the session already holds another agent's history, and
759
+ * the server stamps `Session.AgentId` on the first turn only — so the
760
+ * conversation keeps reporting the agent it STARTED as, however many times
761
+ * this is called. Prefer a new engine (new key, see `engineKeyFor`) per
762
+ * agent.
870
763
  *
871
- * Callers should pass the FULL replacement context (the same
872
- * shape they originally constructed the gateway with). The
873
- * gateway preserves the `model` slice from its current config
874
- * if the incoming context omits it — the model is owned
875
- * separately by `setModel` and shouldn't get clobbered by an
876
- * agent-only change.
764
+ * Callers pass the FULL replacement context (the same shape the gateway was
765
+ * constructed with). The `model` slice is preserved when the incoming
766
+ * context omits it — the model is owned separately by {@link setModel} and
767
+ * must not be clobbered by an agent-only change.
877
768
  */
878
- setAgentContext(t) {
769
+ forceAgentContext(t) {
879
770
  this.config = {
880
771
  ...t,
881
772
  model: t.model ?? this.config.model
@@ -900,11 +791,11 @@ const Ut = 1200 * 1e3, P = class P {
900
791
  if (e && this.currentIS)
901
792
  return this.currentIS.interaction.isSuspended = !1, this.currentIS.interaction.interactionQuestion += " + " + t, this.currentIS.interaction;
902
793
  this.msg_order += 1;
903
- let i = this.getNewInteractionId();
904
- s && (i = s);
794
+ let a = this.getNewInteractionId();
795
+ s && (a = s);
905
796
  let n = {
906
797
  created: /* @__PURE__ */ new Date(),
907
- interactionId: i,
798
+ interactionId: a,
908
799
  artifactData: [],
909
800
  partial: !0,
910
801
  sessionId: this.sessionId,
@@ -914,7 +805,7 @@ const Ut = 1200 * 1e3, P = class P {
914
805
  functionMap: /* @__PURE__ */ new Map(),
915
806
  interactionQuestion: t
916
807
  };
917
- return this.interactionsMap.set(n.interactionId, n), this.currentIS = new q(n, this.eventBusService), this.interactionsServiceMap.set(n.interactionId, this.currentIS), n;
808
+ return this.interactionsMap.set(n.interactionId, n), this.currentIS = new B(n, this.eventBusService), this.interactionsServiceMap.set(n.interactionId, this.currentIS), n;
918
809
  }
919
810
  getInteractions() {
920
811
  return Array.from(this.interactionsMap.values());
@@ -967,8 +858,8 @@ const Ut = 1200 * 1e3, P = class P {
967
858
  s ? (console.warn("GOT A running promise", t), e = s) : (e = this.artifactService.getArtifact(t), this.runningRequests.set(t, e));
968
859
  try {
969
860
  return await e;
970
- } catch (i) {
971
- return console.error("Error awating on HTML promise", i.toString()), null;
861
+ } catch (a) {
862
+ return console.error("Error awating on HTML promise", a.toString()), null;
972
863
  } finally {
973
864
  this.runningRequests.delete(t);
974
865
  }
@@ -984,8 +875,8 @@ const Ut = 1200 * 1e3, P = class P {
984
875
  return !1;
985
876
  }
986
877
  getOrCreateSubAgentInteraction(t, e, s) {
987
- let i = this.subAgentInteractions.get(t), n = this.subAgentInteractionServices.get(t);
988
- return (!i || !n) && (i = {
878
+ let a = this.subAgentInteractions.get(t), n = this.subAgentInteractionServices.get(t);
879
+ return (!a || !n) && (a = {
989
880
  created: /* @__PURE__ */ new Date(),
990
881
  interactionId: e,
991
882
  artifactData: [],
@@ -995,7 +886,7 @@ const Ut = 1200 * 1e3, P = class P {
995
886
  version: 0,
996
887
  functionMap: /* @__PURE__ */ new Map(),
997
888
  interactionQuestion: s ?? t
998
- }, n = new q(i, this.eventBusService), this.subAgentInteractions.set(t, i), this.subAgentInteractionServices.set(t, n)), { interaction: i, service: n };
889
+ }, n = new B(a, this.eventBusService), this.subAgentInteractions.set(t, a), this.subAgentInteractionServices.set(t, n)), { interaction: a, service: n };
999
890
  }
1000
891
  handleSubAgentEvent(t) {
1001
892
  const e = t.subAgentId, { service: s } = this.getOrCreateSubAgentInteraction(e, t.interactionId, t.subAgentName);
@@ -1006,10 +897,10 @@ const Ut = 1200 * 1e3, P = class P {
1006
897
  continue;
1007
898
  }
1008
899
  }
1009
- const i = s.merge(t);
1010
- if (!i) return;
900
+ const a = s.merge(t);
901
+ if (!a) return;
1011
902
  const n = t.turn_complete ?? !1;
1012
- this.sessionState.setSubAgentMessage(e, i.updatedInteraction, t.subAgentName), n && this.sessionState.completeSubAgent(e);
903
+ this.sessionState.setSubAgentMessage(e, a.updatedInteraction, t.subAgentName), n && this.sessionState.completeSubAgent(e);
1013
904
  }
1014
905
  async Message(t) {
1015
906
  try {
@@ -1046,21 +937,21 @@ const Ut = 1200 * 1e3, P = class P {
1046
937
  return;
1047
938
  }
1048
939
  this.localEmitMessage(s.updatedInteraction, s), e.turn_complete && this.turnComplete(e.interactionId, s.updatedInteraction, e.author, e.subAgentId), e.asyncFinalResponse && (e.turn_complete = !0, s.updatedInteraction.turn_complete == !0, this.finalResponse(e.interactionId, s.updatedInteraction, e.author, e.subAgentId));
1049
- const i = e.artifactsDelta;
1050
- i && i.forEach((n) => {
1051
- const r = s.updatedInteraction.artifactData.filter((o) => o.id == n);
940
+ const a = e.artifactsDelta;
941
+ a && a.forEach((n) => {
942
+ const r = s.updatedInteraction.artifactData.filter((c) => c.id == n);
1052
943
  let l = null;
1053
- 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)));
944
+ r && r.length > 0 && (l = r[0], l.loadingPromise = this.asyncLoadArtifact(n).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)));
1054
945
  });
1055
946
  }
1056
947
  } catch (e) {
1057
948
  if (this.getCurrentInteractionId()) {
1058
- const s = gt.createErrorEvent("OnMessage error: " + e.toString(), this.getCurrentInteractionId() ?? "Empty Current"), i = this.updateMap(s);
1059
- if (console.error("Error event: ", JSON.stringify(s, void 0, 4)), !i) {
949
+ const s = dt.createErrorEvent("OnMessage error: " + e.toString(), this.getCurrentInteractionId() ?? "Empty Current"), a = this.updateMap(s);
950
+ if (console.error("Error event: ", JSON.stringify(s, void 0, 4)), !a) {
1060
951
  console.error("Error event, could not update interaction: ", JSON.stringify(s, void 0, 4));
1061
952
  return;
1062
953
  }
1063
- this.localEmitMessage(i.updatedInteraction);
954
+ this.localEmitMessage(a.updatedInteraction);
1064
955
  }
1065
956
  }
1066
957
  }
@@ -1084,8 +975,8 @@ const Ut = 1200 * 1e3, P = class P {
1084
975
  this.sessionState.setCurrentMessage(t), this.lastCurrentMessageUpdate = e, this.pendingCurrentMessage = null, this.eventBusService.gatewayEmitMessage(t, s);
1085
976
  }
1086
977
  localEmitMessage(t, e) {
1087
- const s = (/* @__PURE__ */ new Date()).getTime(), i = s - this.lastCurrentMessageUpdate;
1088
- t.partial === !1 || i >= P.CURRENT_MSG_THROTTLE_MS ? (this.lastThorttledTimeout && (clearTimeout(this.lastThorttledTimeout), this.lastThorttledTimeout = null), this.doEmitMessage(t, s, e), this.pendingCurrentMessage = null) : (this.pendingCurrentMessage = t, this.lastThorttledTimeout && clearTimeout(this.lastThorttledTimeout), this.lastThorttledTimeout = setTimeout(() => {
978
+ const s = (/* @__PURE__ */ new Date()).getTime(), a = s - this.lastCurrentMessageUpdate;
979
+ t.partial === !1 || a >= P.CURRENT_MSG_THROTTLE_MS ? (this.lastThorttledTimeout && (clearTimeout(this.lastThorttledTimeout), this.lastThorttledTimeout = null), this.doEmitMessage(t, s, e), this.pendingCurrentMessage = null) : (this.pendingCurrentMessage = t, this.lastThorttledTimeout && clearTimeout(this.lastThorttledTimeout), this.lastThorttledTimeout = setTimeout(() => {
1089
980
  var r, l;
1090
981
  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);
1091
982
  }, P.CURRENT_MSG_THROTTLE_MS * 2));
@@ -1108,26 +999,26 @@ const Ut = 1200 * 1e3, P = class P {
1108
999
  cancelPendingCurrentMessage() {
1109
1000
  this.lastThorttledTimeout && (clearTimeout(this.lastThorttledTimeout), this.lastThorttledTimeout = null), this.pendingCurrentMessage = null;
1110
1001
  }
1111
- async turnComplete(t, e, s, i) {
1002
+ async turnComplete(t, e, s, a) {
1112
1003
  this.cancelPendingCurrentMessage(), this.sessionState.setNewMessage(e), this.eventBusService.gatewayEmitTurnComplete(t, e), this.interactionCallIds.delete(t), this.sessionState.setLastToolEvent(null), this.localEmitToolEvent({
1113
1004
  eventName: "todolistUpdated",
1114
1005
  eventData: "",
1115
- subAgentId: i
1006
+ subAgentId: a
1116
1007
  }), this.sessionState.setTurnOpen(!1);
1117
1008
  }
1118
1009
  async handlePing() {
1119
- return Date.now() - this.lastPing.getTime() > Ut ? await this.ping() ? (this.lastPing = /* @__PURE__ */ new Date(), this.lastPingStatus = !0, !0) : (this.lastPingStatus = !1, !1) : (this.lastPingStatus = !0, !0);
1010
+ return Date.now() - this.lastPing.getTime() > Ft ? await this.ping() ? (this.lastPing = /* @__PURE__ */ new Date(), this.lastPingStatus = !0, !0) : (this.lastPingStatus = !1, !1) : (this.lastPingStatus = !0, !0);
1120
1011
  }
1121
1012
  async sendMessage(t, e) {
1122
- let s = this.getInteractions().length, i = _.createWaiting(!0, !0, "Overall", /* @__PURE__ */ new Date());
1123
- this.sendStatusMessage(t.data, [i], s.toString() + "1");
1013
+ let s = this.getInteractions().length, a = N.createWaiting(!0, !0, "Overall", /* @__PURE__ */ new Date());
1014
+ this.sendStatusMessage(t.data, [a], s.toString() + "1");
1124
1015
  try {
1125
1016
  const { promptAsString: n, json: r } = this.sessionState.onRenderPrompt ? this.sessionState.onRenderPrompt(t.data) : { promptAsString: t.data, json: void 0 };
1126
1017
  this.sessionState.onRenderPrompt && (t.data = r, t.friendlyMessage = n);
1127
- const l = await this.sendMessageInternal(t, e), o = bt.createPrompt(n ?? "", (r == null ? void 0 : r.toString()) ?? {});
1128
- this.storageService.storePrompt(o);
1129
- const d = _.fromText("Planejando próximos passos");
1130
- return this.sendStatusMessage(t.data, [i, d], s.toString() + "1"), l != null && l.success ? this.eventBusService.ChatEmitMessageSent(t.data, l.interaction) : this.eventBusService.ChatEmitMessageError((l == null ? void 0 : l.error) ?? ""), l;
1018
+ const l = await this.sendMessageInternal(t, e), c = Nt.createPrompt(n ?? "", (r == null ? void 0 : r.toString()) ?? {});
1019
+ this.storageService.storePrompt(c);
1020
+ const d = N.fromText("Planejando próximos passos");
1021
+ return this.sendStatusMessage(t.data, [a, d], s.toString() + "1"), l != null && l.success ? this.eventBusService.ChatEmitMessageSent(t.data, l.interaction) : this.eventBusService.ChatEmitMessageError((l == null ? void 0 : l.error) ?? ""), l;
1131
1022
  } catch (n) {
1132
1023
  return this.eventBusService.ChatEmitMessageError((n == null ? void 0 : n.toString()) ?? ""), {
1133
1024
  success: !1,
@@ -1136,7 +1027,7 @@ const Ut = 1200 * 1e3, P = class P {
1136
1027
  created: /* @__PURE__ */ new Date(),
1137
1028
  interactionId: "",
1138
1029
  partial: !1,
1139
- parts: [_.fromError((n == null ? void 0 : n.toString()) ?? "")],
1030
+ parts: [N.fromError((n == null ? void 0 : n.toString()) ?? "")],
1140
1031
  version: 0
1141
1032
  }
1142
1033
  };
@@ -1144,6 +1035,9 @@ const Ut = 1200 * 1e3, P = class P {
1144
1035
  this.clearStatus();
1145
1036
  }
1146
1037
  }
1038
+ // `reset(user, config?)` is gone (issue #59): a fourth public door that took an
1039
+ // AgentContext, with one implementation that only ever threw. Rebuild the engine
1040
+ // instead — that is what "reset this conversation" means now.
1147
1041
  async check() {
1148
1042
  return !0;
1149
1043
  }
@@ -1154,8 +1048,8 @@ const Ut = 1200 * 1e3, P = class P {
1154
1048
  }
1155
1049
  sendStatusMessage(t, e, s) {
1156
1050
  var n, r;
1157
- let i;
1158
- ((r = (n = this.currentIS) == null ? void 0 : n.interaction) == null ? void 0 : r.turn_complete) === !1 ? (i = _t.cloneDeep(this.currentIS.interaction), i.parts.push(...e)) : i = {
1051
+ let a;
1052
+ ((r = (n = this.currentIS) == null ? void 0 : n.interaction) == null ? void 0 : r.turn_complete) === !1 ? (a = Pt.cloneDeep(this.currentIS.interaction), a.parts.push(...e)) : a = {
1159
1053
  interactionId: "tmp" + s,
1160
1054
  created: /* @__PURE__ */ new Date(),
1161
1055
  partial: !0,
@@ -1164,7 +1058,7 @@ const Ut = 1200 * 1e3, P = class P {
1164
1058
  parts: e,
1165
1059
  interactionQuestion: t,
1166
1060
  artifactData: []
1167
- }, this.localEmitMessage(i);
1061
+ }, this.localEmitMessage(a);
1168
1062
  }
1169
1063
  clearStatus() {
1170
1064
  }
@@ -1178,43 +1072,43 @@ const Ut = 1200 * 1e3, P = class P {
1178
1072
  }
1179
1073
  }
1180
1074
  getNewInteractionId() {
1181
- const e = Pt(/* @__PURE__ */ new Date(), "MMM_dd_HH_mm_ss");
1075
+ const e = At(/* @__PURE__ */ new Date(), "MMM_dd_HH_mm_ss");
1182
1076
  return `${this.msg_order}_${e}`;
1183
1077
  }
1184
1078
  };
1185
- g(P, "AgentGatewayService"), a(P, "SUSPENSION_MSG", "SUSPEND"), a(P, "CURRENT_MSG_THROTTLE_MS", 20);
1186
- let H = P;
1187
- const K = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2, ht = 2, V = class V {
1079
+ f(P, "AgentGatewayService"), i(P, "SUSPENSION_MSG", "SUSPEND"), i(P, "CURRENT_MSG_THROTTLE_MS", 150);
1080
+ let G = P;
1081
+ const H = 4001, Lt = 4002, ot = 4, Ut = 3, xt = 500, Bt = 3e4, Wt = 2, $t = 0.2, ct = 2, Q = class Q {
1188
1082
  constructor(t = "ws://localhost:8000", e) {
1189
- a(this, "ws", null);
1190
- a(this, "stats");
1191
- a(this, "baseUrl");
1083
+ i(this, "ws", null);
1084
+ i(this, "stats");
1085
+ i(this, "baseUrl");
1192
1086
  /**
1193
1087
  * Optional callback that returns the current JWT. We re-evaluate it on every connect/reconnect
1194
1088
  * so that a refreshed token is picked up automatically. Browsers can't set the Authorization
1195
1089
  * header on the WebSocket handshake, so we pass the JWT via the ?access_token= query string,
1196
1090
  * which the .NET JwtBearer events handler reads in Program.cs.
1197
1091
  */
1198
- a(this, "getToken");
1199
- a(this, "onEvent");
1200
- a(this, "onError");
1201
- a(this, "onOpen");
1202
- a(this, "onFirstToken");
1203
- a(this, "onSuspended");
1204
- a(this, "onPong");
1205
- a(this, "onClose");
1092
+ i(this, "getToken");
1093
+ i(this, "onEvent");
1094
+ i(this, "onError");
1095
+ i(this, "onOpen");
1096
+ i(this, "onFirstToken");
1097
+ i(this, "onSuspended");
1098
+ i(this, "onPong");
1099
+ i(this, "onClose");
1206
1100
  /** Fired when an unexpected close triggers a reconnect attempt. */
1207
- a(this, "onReconnecting");
1101
+ i(this, "onReconnecting");
1208
1102
  /** Fired the first time the socket reopens after an unexpected close. */
1209
- a(this, "onReconnected");
1103
+ i(this, "onReconnected");
1210
1104
  /**
1211
1105
  * Fired when the server signals that we lost streaming events on resume — our
1212
1106
  * `lastSeq` fell off the end of the in-memory replay buffer. Consumers should
1213
1107
  * reset partial-streaming UI for this session and rely on persisted history.
1214
1108
  */
1215
- a(this, "onRewindLost");
1216
- a(this, "sessionId");
1217
- a(this, "onNewPacket");
1109
+ i(this, "onRewindLost");
1110
+ i(this, "sessionId");
1111
+ i(this, "onNewPacket");
1218
1112
  /**
1219
1113
  * Stats can fire dozens of times per second during streaming. We
1220
1114
  * coalesce to a fixed cadence so subscribers see steady,
@@ -1225,33 +1119,33 @@ const K = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
1225
1119
  * on every packet, with their useEffect-driven setStates pushing
1226
1120
  * React's nested-update counter past its threshold).
1227
1121
  */
1228
- a(this, "statsFlushTimer", null);
1229
- a(this, "statsLastFlushed", 0);
1230
- a(this, "STATS_FLUSH_MS", 120);
1231
- a(this, "monitorInterval", null);
1232
- a(this, "streamingResponseSerializer");
1233
- a(this, "events");
1234
- a(this, "lastActivity");
1235
- a(this, "pingPongStack");
1236
- a(this, "firstTokenInteractions");
1122
+ i(this, "statsFlushTimer", null);
1123
+ i(this, "statsLastFlushed", 0);
1124
+ i(this, "STATS_FLUSH_MS", 120);
1125
+ i(this, "monitorInterval", null);
1126
+ i(this, "streamingResponseSerializer");
1127
+ i(this, "events");
1128
+ i(this, "lastActivity");
1129
+ i(this, "pingPongStack");
1130
+ i(this, "firstTokenInteractions");
1237
1131
  /** Last sessionId we successfully had — used to resume on reconnect. */
1238
- a(this, "lastKnownSessionId");
1132
+ i(this, "lastKnownSessionId");
1239
1133
  /** True when the consumer called `disconnect()` — suppresses auto-reconnect. */
1240
- a(this, "intentionalDisconnect", !1);
1134
+ i(this, "intentionalDisconnect", !1);
1241
1135
  /** Number of reconnect attempts since the last clean open. */
1242
- a(this, "reconnectAttempts", 0);
1243
- a(this, "reconnectTimer", null);
1136
+ i(this, "reconnectAttempts", 0);
1137
+ i(this, "reconnectTimer", null);
1244
1138
  /** True while we are in the middle of an unexpected-close → reconnect cycle. */
1245
- a(this, "isReconnecting", !1);
1139
+ i(this, "isReconnecting", !1);
1246
1140
  /** Internal flag set by `scheduleReconnect` so `connect()` does not reset the backoff state. */
1247
- a(this, "_internalReconnect", !1);
1141
+ i(this, "_internalReconnect", !1);
1248
1142
  /**
1249
1143
  * Highest server-assigned `seq` we have observed and processed. The next
1250
1144
  * reconnect appends `?lastSeq={lastSeq}` so the server can replay anything
1251
1145
  * we missed from the InteractionRun's in-memory buffer. -1 means "haven't
1252
1146
  * seen any sequenced events yet" (fresh connection).
1253
1147
  */
1254
- a(this, "lastSeq", -1);
1148
+ i(this, "lastSeq", -1);
1255
1149
  /**
1256
1150
  * Parked-tool answers that could not be sent because the socket was not OPEN
1257
1151
  * (e.g. the connection idled out while the user was in an IdP sign-in popup).
@@ -1260,7 +1154,7 @@ const K = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
1260
1154
  * answer for a session this instance is no longer attached to is dropped —
1261
1155
  * the single-attach policy makes it undeliverable from here anyway.
1262
1156
  */
1263
- a(this, "pendingAnswers", []);
1157
+ i(this, "pendingAnswers", []);
1264
1158
  /**
1265
1159
  * True once *any* socket on this instance has received at least one packet.
1266
1160
  * Used by `onclose` to distinguish a real mid-stream drop (we had a working
@@ -1273,8 +1167,8 @@ const K = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
1273
1167
  * when a replacement socket fails before delivering its first message.
1274
1168
  * Cleared by `disconnect()`.
1275
1169
  */
1276
- a(this, "hasEverReceivedPacket", !1);
1277
- this.baseUrl = t, this.getToken = e, this.pingPongStack = [], this.events = [], this.firstTokenInteractions = /* @__PURE__ */ new Set(), this.streamingResponseSerializer = Ct(), console.log("SOCKET INSTACE", It()), this.stats = {
1170
+ i(this, "hasEverReceivedPacket", !1);
1171
+ this.baseUrl = t, this.getToken = e, this.pingPongStack = [], this.events = [], this.firstTokenInteractions = /* @__PURE__ */ new Set(), this.streamingResponseSerializer = yt(), console.log("SOCKET INSTACE", wt()), this.stats = {
1278
1172
  eventCount: 0,
1279
1173
  unknonwCount: 0,
1280
1174
  buffer: [],
@@ -1296,14 +1190,14 @@ const K = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
1296
1190
  * silently, because the transcript looked intact right up to the gap.
1297
1191
  */
1298
1192
  connect(t, e) {
1299
- return new Promise(async (s, i) => {
1300
- var F;
1193
+ return new Promise(async (s, a) => {
1194
+ var b;
1301
1195
  this.intentionalDisconnect = !1;
1302
1196
  const n = this._internalReconnect || (e == null ? void 0 : e.resume) === !0;
1303
1197
  n || (this.cancelPendingReconnect(), this.isReconnecting = !1, this.reconnectAttempts = 0, this.lastSeq = -1), this._internalReconnect = !1;
1304
- const r = (F = this.getToken) == null ? void 0 : F.call(this), l = [];
1198
+ const r = (b = this.getToken) == null ? void 0 : b.call(this), l = [];
1305
1199
  r && l.push(`access_token=${encodeURIComponent(r)}`), t && this.lastSeq >= 0 && l.push(`lastSeq=${this.lastSeq}`);
1306
- const o = l.length > 0 ? `?${l.join("&")}` : "", d = this.baseUrl.replace(/^http:\/\//, "ws://").replace(/^https:\/\//, "wss://"), u = `${d}/ws/connect/${t ?? ""}${o}`, h = `${d}/ws/connect/${t ?? ""}` + (n && t && this.lastSeq >= 0 ? ` (resume lastSeq=${this.lastSeq})` : "");
1200
+ const c = l.length > 0 ? `?${l.join("&")}` : "", d = this.baseUrl.replace(/^http:\/\//, "ws://").replace(/^https:\/\//, "wss://"), u = `${d}/ws/connect/${t ?? ""}${c}`, h = `${d}/ws/connect/${t ?? ""}` + (n && t && this.lastSeq >= 0 ? ` (resume lastSeq=${this.lastSeq})` : "");
1307
1201
  if (console.log("Connecting to ", h), this.ws) {
1308
1202
  this.ws.onopen = null, this.ws.onmessage = null, this.ws.onerror = null, this.ws.onclose = null;
1309
1203
  try {
@@ -1321,50 +1215,50 @@ const K = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
1321
1215
  }, this.ws.onmessage = (y) => {
1322
1216
  try {
1323
1217
  this.lastActivity = (/* @__PURE__ */ new Date()).getTime();
1324
- const A = this.streamingResponseSerializer.parse(y.data);
1325
- if (!A)
1218
+ const O = this.streamingResponseSerializer.parse(y.data);
1219
+ if (!O)
1326
1220
  throw "Error parsing event JSON";
1327
- const N = this.handleMessage(A, y.data);
1328
- !C && (N != null && N.timestamp) && (C = !0, this.hasEverReceivedPacket = !0);
1329
- } catch (A) {
1330
- console.error("[WebSocket] Error parsing message:", A);
1221
+ const A = this.handleMessage(O, y.data);
1222
+ !C && (A != null && A.timestamp) && (C = !0, this.hasEverReceivedPacket = !0);
1223
+ } catch (O) {
1224
+ console.error("[WebSocket] Error parsing message:", O);
1331
1225
  }
1332
1226
  }, this.ws.onerror = (y) => {
1333
1227
  console.error("[WebSocket] Error:", y), this.onError && this.onError("WebSocket error");
1334
1228
  }, this.ws.onclose = (y) => {
1335
1229
  console.log("[WebSocket] Closed:", y.code, y.reason), this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingPongStack = [];
1336
- const A = this.sessionId ?? this.lastKnownSessionId;
1230
+ const O = this.sessionId ?? this.lastKnownSessionId;
1337
1231
  if (this.sessionId = void 0, (C || this.hasEverReceivedPacket) && this.shouldAttemptReconnect(y.code)) {
1338
- this.scheduleReconnect(A, y.code, y.reason);
1232
+ this.scheduleReconnect(O, y.code, y.reason);
1339
1233
  return;
1340
1234
  }
1341
1235
  this.isReconnecting = !1, this.reconnectAttempts = 0, this.onClose && this.onClose(y.code, y.reason);
1342
1236
  };
1343
- const p = 200, O = 3e4, M = 8e3, v = this.ws;
1237
+ const p = 200, M = 3e4, w = 8e3, I = this.ws;
1344
1238
  this.sessionId = void 0;
1345
- let k = 0, b = 0;
1239
+ let k = 0, _ = 0;
1346
1240
  for (; !this.sessionId; ) {
1347
- if (this.ws !== v) {
1348
- i("Connection attempt superseded by a newer connect()");
1241
+ if (this.ws !== I) {
1242
+ a("Connection attempt superseded by a newer connect()");
1349
1243
  return;
1350
1244
  }
1351
- if (v.readyState === WebSocket.CLOSING || v.readyState === WebSocket.CLOSED) {
1352
- i("Connection closed before a session id was received");
1245
+ if (I.readyState === WebSocket.CLOSING || I.readyState === WebSocket.CLOSED) {
1246
+ a("Connection closed before a session id was received");
1353
1247
  return;
1354
1248
  }
1355
- if (v.readyState === WebSocket.CONNECTING && k >= O) {
1249
+ if (I.readyState === WebSocket.CONNECTING && k >= M) {
1356
1250
  try {
1357
- v.close();
1251
+ I.close();
1358
1252
  } catch {
1359
1253
  }
1360
- i(`Server did not accept the connection within ${O / 1e3}s`);
1254
+ a(`Server did not accept the connection within ${M / 1e3}s`);
1361
1255
  return;
1362
1256
  }
1363
- if (v.readyState === WebSocket.OPEN && b >= M) {
1364
- i(`Connected but no session id arrived within ${M / 1e3}s`);
1257
+ if (I.readyState === WebSocket.OPEN && _ >= w) {
1258
+ a(`Connected but no session id arrived within ${w / 1e3}s`);
1365
1259
  return;
1366
1260
  }
1367
- k % 2e3 === 0 && console.log("Aguardando session Id"), await this.sleep(p), k += p, v.readyState === WebSocket.OPEN && (b += p);
1261
+ k % 2e3 === 0 && console.log("Aguardando session Id"), await this.sleep(p), k += p, I.readyState === WebSocket.OPEN && (_ += p);
1368
1262
  }
1369
1263
  console.log("SUCCESS - GOT SESSION ID", this.sessionId), this.lastKnownSessionId = this.sessionId, s(this.sessionId);
1370
1264
  });
@@ -1379,36 +1273,36 @@ const K = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
1379
1273
  * - 4000-4099 reserved for app-level fatal codes from the server
1380
1274
  */
1381
1275
  shouldAttemptReconnect(t) {
1382
- return !(this.intentionalDisconnect || t === K || t === Lt || t === 1e3 || t === 1008);
1276
+ return !(this.intentionalDisconnect || t === H || t === Lt || t === 1e3 || t === 1008);
1383
1277
  }
1384
1278
  cancelPendingReconnect() {
1385
1279
  this.reconnectTimer && (clearTimeout(this.reconnectTimer), this.reconnectTimer = null);
1386
1280
  }
1387
1281
  computeBackoffDelay() {
1388
- const t = Bt * Math.pow($t, this.reconnectAttempts), e = Math.min(t, Wt), s = e * qt * (Math.random() * 2 - 1);
1282
+ const t = xt * Math.pow(Wt, this.reconnectAttempts), e = Math.min(t, Bt), s = e * $t * (Math.random() * 2 - 1);
1389
1283
  return Math.max(0, Math.round(e + s));
1390
1284
  }
1391
1285
  scheduleReconnect(t, e, s) {
1392
1286
  var n, r;
1393
1287
  if (this.intentionalDisconnect) return;
1394
- if (this.reconnectAttempts >= ht) {
1288
+ if (this.reconnectAttempts >= ct) {
1395
1289
  console.warn(
1396
1290
  `[WebSocket] Reconnect exhausted after ${this.reconnectAttempts} attempts (last code=${e}, reason="${s}"). Handing off to outer state manager.`
1397
1291
  ), this.isReconnecting = !1, this.reconnectAttempts = 0, this.cancelPendingReconnect(), (n = this.onClose) == null || n.call(this, e, s);
1398
1292
  return;
1399
1293
  }
1400
1294
  this.isReconnecting = !0, this.reconnectAttempts += 1;
1401
- const i = this.computeBackoffDelay();
1295
+ const a = this.computeBackoffDelay();
1402
1296
  console.warn(
1403
- `[WebSocket] Unexpected close (code=${e}, reason="${s}"). Reconnect attempt #${this.reconnectAttempts}/${ht} in ${i}ms (resume sessionId=${t ?? "none"}).`
1404
- ), (r = this.onReconnecting) == null || r.call(this, this.reconnectAttempts, i), this.cancelPendingReconnect(), this.reconnectTimer = setTimeout(async () => {
1297
+ `[WebSocket] Unexpected close (code=${e}, reason="${s}"). Reconnect attempt #${this.reconnectAttempts}/${ct} in ${a}ms (resume sessionId=${t ?? "none"}).`
1298
+ ), (r = this.onReconnecting) == null || r.call(this, this.reconnectAttempts, a), this.cancelPendingReconnect(), this.reconnectTimer = setTimeout(async () => {
1405
1299
  if (this.reconnectTimer = null, !this.intentionalDisconnect)
1406
1300
  try {
1407
1301
  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);
1408
1302
  } catch (l) {
1409
1303
  console.error("[WebSocket] Reconnect attempt failed:", l);
1410
1304
  }
1411
- }, i);
1305
+ }, a);
1412
1306
  }
1413
1307
  async sleep(t) {
1414
1308
  return new Promise((e) => setTimeout(e, t));
@@ -1417,7 +1311,7 @@ const K = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
1417
1311
  * Handle incoming messages from server
1418
1312
  */
1419
1313
  handleMessage(t, e) {
1420
- var l, o, d;
1314
+ var l, c, d;
1421
1315
  switch (typeof t.seq == "number" && t.seq > this.lastSeq && (this.lastSeq = t.seq), t.type) {
1422
1316
  case "Pong":
1423
1317
  if (this.sessionId = t.sessionId, this.lastKnownSessionId = t.sessionId ?? this.lastKnownSessionId, !t.sessionId) {
@@ -1444,33 +1338,33 @@ const K = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
1444
1338
  this.emitFirstToken(u == null ? void 0 : u.iteractionId);
1445
1339
  const h = new vt();
1446
1340
  if (h.author = "main", h.streamingParts = t.partialEvent.streamingParts, t.partialEvent.partialEventType ? h.eventType = t.partialEvent.partialEventType : h.eventType = u.functionName ? {
1447
- fullName: B.StreamingFunctionCallUpdateContent,
1448
- type: I.PartialFunctionCall
1341
+ fullName: L.StreamingFunctionCallUpdateContent,
1342
+ type: T.PartialFunctionCall
1449
1343
  } : u.partialReasoning ? {
1450
- fullName: B.StreamingReasoningContent,
1451
- type: I.Thought
1344
+ fullName: L.StreamingReasoningContent,
1345
+ type: T.Thought
1452
1346
  } : {
1453
- fullName: B.StreamingTextContent,
1454
- type: I.Text
1455
- }, h.interactionId = (u == null ? void 0 : u.iteractionId) ?? "", h.mimeType = "text/plain", h.partial = !0, h.eventType.type == I.PartialFunctionCall) {
1456
- var s = new Et();
1347
+ fullName: L.StreamingTextContent,
1348
+ type: T.Text
1349
+ }, h.interactionId = (u == null ? void 0 : u.iteractionId) ?? "", h.mimeType = "text/plain", h.partial = !0, h.eventType.type == T.PartialFunctionCall) {
1350
+ var s = new Ct();
1457
1351
  s.choiceIndex = 0, s.callId = u.functionCallId, s.arguments = u.partialText, s.name = u.functionName, h.content = {
1458
1352
  items: [s],
1459
1353
  role: {
1460
1354
  label: "Assistant"
1461
1355
  }
1462
1356
  };
1463
- } else if (h.eventType.type == I.Text)
1464
- if (h.eventType.fullName == B.StreamingTextContent) {
1465
- var i = new Mt();
1466
- i.text = u.partialText, h.content = {
1467
- items: [i],
1357
+ } else if (h.eventType.type == T.Text)
1358
+ if (h.eventType.fullName == L.StreamingTextContent) {
1359
+ var a = new It();
1360
+ a.text = u.partialText, h.content = {
1361
+ items: [a],
1468
1362
  role: {
1469
1363
  label: "Assistant"
1470
1364
  }
1471
1365
  };
1472
1366
  } else {
1473
- var n = new Dt();
1367
+ var n = new Et();
1474
1368
  n.text = u.partialText, h.content = {
1475
1369
  items: [n],
1476
1370
  role: {
@@ -1478,8 +1372,8 @@ const K = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
1478
1372
  }
1479
1373
  };
1480
1374
  }
1481
- else if (h.eventType.type == I.Thought) {
1482
- var r = new Ot();
1375
+ else if (h.eventType.type == T.Thought) {
1376
+ var r = new Mt();
1483
1377
  r.text = u.partialReasoning, h.content = {
1484
1378
  items: [r],
1485
1379
  role: {
@@ -1492,7 +1386,7 @@ const K = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
1492
1386
  label: "Assistant"
1493
1387
  }, h.timestamp = (u == null ? void 0 : u.timeStamp) ?? (/* @__PURE__ */ new Date()).getTime(), h.turnComplete = !1, t.event = h, t.partialEvent = void 0;
1494
1388
  }
1495
- 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 || (((d = t.event.streamingParts) == null ? void 0 : d.length) ?? 0) > 0) && this.emitFirstToken(t.event.interactionId), this.handleEvent(t.event, e), t.event) : null;
1389
+ 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 || (((d = t.event.streamingParts) == null ? void 0 : d.length) ?? 0) > 0) && this.emitFirstToken(t.event.interactionId), this.handleEvent(t.event, e), t.event) : null;
1496
1390
  }
1497
1391
  emitFirstToken(t) {
1498
1392
  var e;
@@ -1528,9 +1422,9 @@ const K = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
1528
1422
  console.warn("[WebSocket] WS-refreshed token received but no stored user — dropping");
1529
1423
  return;
1530
1424
  }
1531
- const i = JSON.parse(s);
1532
- if ((i == null ? void 0 : i.access_token) === t) return;
1533
- i.access_token = t, localStorage.setItem(e, JSON.stringify(i)), console.info("[WebSocket] Mirrored WS-refreshed JWT into stored user");
1425
+ const a = JSON.parse(s);
1426
+ if ((a == null ? void 0 : a.access_token) === t) return;
1427
+ a.access_token = t, localStorage.setItem(e, JSON.stringify(a)), console.info("[WebSocket] Mirrored WS-refreshed JWT into stored user");
1534
1428
  } catch (s) {
1535
1429
  console.error("[WebSocket] Failed to persist WS-refreshed token", s);
1536
1430
  }
@@ -1540,7 +1434,7 @@ const K = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
1540
1434
  }
1541
1435
  suspendStream() {
1542
1436
  this.sendBaseMessage({
1543
- Action: W.Suspend,
1437
+ Action: U.Suspend,
1544
1438
  AgentId: "",
1545
1439
  InteractionId: "",
1546
1440
  ModelId: ""
@@ -1559,7 +1453,7 @@ const K = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
1559
1453
  */
1560
1454
  answerHumanTool(t, e) {
1561
1455
  const s = {
1562
- Action: W.AnswerHumanTool,
1456
+ Action: U.AnswerHumanTool,
1563
1457
  AgentId: "",
1564
1458
  InteractionId: "",
1565
1459
  ToolCallId: t,
@@ -1586,7 +1480,7 @@ const K = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
1586
1480
  }
1587
1481
  try {
1588
1482
  this.sendBaseMessage({
1589
- Action: W.AnswerHumanTool,
1483
+ Action: U.AnswerHumanTool,
1590
1484
  AgentId: "",
1591
1485
  InteractionId: "",
1592
1486
  ToolCallId: s.toolCallId,
@@ -1615,10 +1509,10 @@ const K = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
1615
1509
  const t = this, e = this.pingPongStack, s = 3e4;
1616
1510
  this.monitorInterval = setInterval(() => {
1617
1511
  try {
1618
- const i = (/* @__PURE__ */ new Date()).getTime() - this.lastActivity;
1619
- 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());
1620
- } catch (i) {
1621
- console.error("Error on monitor", i);
1512
+ const a = (/* @__PURE__ */ new Date()).getTime() - this.lastActivity;
1513
+ t.isConnected() && a >= s - 200 && (e.length > 0 && console.warn("Ping pong stack broke here, on pinging"), e.push((/* @__PURE__ */ new Date()).getTime()), t.ping());
1514
+ } catch (a) {
1515
+ console.error("Error on monitor", a);
1622
1516
  }
1623
1517
  }, s);
1624
1518
  }
@@ -1637,7 +1531,7 @@ const K = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
1637
1531
  * Disconnect the WebSocket
1638
1532
  */
1639
1533
  disconnect() {
1640
- 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(K, "Intentional disconnect"), this.ws = null);
1534
+ 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(H, "Intentional disconnect"), this.ws = null);
1641
1535
  }
1642
1536
  /**
1643
1537
  * Check if connected
@@ -1666,40 +1560,40 @@ const K = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2,
1666
1560
  async handleEvent(t, e) {
1667
1561
  var s;
1668
1562
  try {
1669
- const i = gt.parseFromTypedEvent(t);
1670
- if (!i)
1563
+ const a = dt.parseFromTypedEvent(t);
1564
+ if (!a)
1671
1565
  throw "Server event was null";
1672
- 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;
1673
- const n = Date.now() - lt * 1e3, l = this.events.filter((o) => o[0] > n).reduce((o, d) => o += d[1], 0) / xt;
1674
- this.stats.tokensPerSecond = l / lt, this.flushStatsCoalesced(), this.onEvent && this.onEvent(i).catch((o) => {
1675
- console.error("Lost error on on-event", o);
1566
+ this.events.push([(/* @__PURE__ */ new Date()).getTime(), ((s = t.text) == null ? void 0 : s.length) ?? 0]), this.stats.eventCount += 1, this.stats.totalTransfered += e.length, a.session_information && !a.subAgentId && (this.stats.sessionInformation = a.session_information), this.stats.elapsed = (Date.now() - this.stats.startTime.getTime()) / 1e3;
1567
+ const n = Date.now() - ot * 1e3, l = this.events.filter((c) => c[0] > n).reduce((c, d) => c += d[1], 0) / Ut;
1568
+ this.stats.tokensPerSecond = l / ot, this.flushStatsCoalesced(), this.onEvent && this.onEvent(a).catch((c) => {
1569
+ console.error("Lost error on on-event", c);
1676
1570
  });
1677
- } catch (i) {
1678
- console.error("handleEvent error", i);
1571
+ } catch (a) {
1572
+ console.error("handleEvent error", a);
1679
1573
  }
1680
1574
  }
1681
1575
  };
1682
- g(V, "WebSocketConnecionV2");
1683
- let ut = V;
1684
- const Jt = "envision_agent_sessionId", tt = class tt extends H {
1685
- constructor(e, s, i, n, r, l, o, d, u, h, C) {
1686
- super(e, s, i, n, r, l, o, u, C);
1687
- a(this, "suspendState", !1);
1688
- a(this, "wsService");
1689
- a(this, "root_url", "");
1690
- a(this, "hearBeatPort");
1691
- a(this, "connectionAttempts", 0);
1576
+ f(Q, "WebSocketConnecionV2");
1577
+ let lt = Q;
1578
+ const qt = "envision_agent_sessionId", Z = class Z extends G {
1579
+ constructor(e, s, a, n, r, l, c, d, u, h, C) {
1580
+ super(e, s, a, n, r, l, c, u, C);
1581
+ i(this, "suspendState", !1);
1582
+ i(this, "wsService");
1583
+ i(this, "root_url", "");
1584
+ i(this, "hearBeatPort");
1585
+ i(this, "connectionAttempts", 0);
1692
1586
  /**
1693
1587
  * True once a WS has successfully opened at least once in this gateway's
1694
1588
  * lifetime. Gates the "Reiniciando a conexão" toast: a drop of a working
1695
1589
  * connection is worth telling the user about, a failed initial dial is not
1696
1590
  * (the Connecting state already covers it).
1697
1591
  */
1698
- a(this, "everConnected", !1);
1699
- a(this, "statuses", ["CONNECTING", "OPEN", "CLOSED", "UNKNOWN"]);
1700
- a(this, "lastConnectionPromise", null);
1701
- a(this, "socketState", U.Disconnected);
1702
- a(this, "streamOpened", !1);
1592
+ i(this, "everConnected", !1);
1593
+ i(this, "statuses", ["CONNECTING", "OPEN", "CLOSED", "UNKNOWN"]);
1594
+ i(this, "lastConnectionPromise", null);
1595
+ i(this, "socketState", F.Disconnected);
1596
+ i(this, "streamOpened", !1);
1703
1597
  this.hearBeatPort = h, this.root_url = this.base_url, this.wsService = d, this.wsService.onEvent = async (p) => {
1704
1598
  await super.Message(p);
1705
1599
  }, this.wsService.onNewPacket = (p) => {
@@ -1707,7 +1601,7 @@ const Jt = "envision_agent_sessionId", tt = class tt extends H {
1707
1601
  }, this.wsService.onPong = (p) => {
1708
1602
  }, this.wsService.onError = (p) => {
1709
1603
  this.streamOpened = !1;
1710
- const O = {
1604
+ const M = {
1711
1605
  data: this.getErrorEvent(p),
1712
1606
  lastEventId: (/* @__PURE__ */ new Date()).getTime().toString(),
1713
1607
  origin: "gatewayService"
@@ -1715,20 +1609,17 @@ const Jt = "envision_agent_sessionId", tt = class tt extends H {
1715
1609
  console.error("Stream error:", p), this.everConnected && this.notificationPort.pushNotification({
1716
1610
  message: "Reiniciando a conexão com o servidor",
1717
1611
  type: "info"
1718
- }), super.Message(O);
1612
+ }), super.Message(M);
1719
1613
  }, this.wsService.onOpen = () => {
1720
- this.everConnected = !0, this.sessionState.setConnectionStatus(U.Connected);
1614
+ this.everConnected = !0, this.sessionState.setConnectionStatus(F.Connected);
1721
1615
  }, this.wsService.onReconnected = (p) => {
1722
- this.sessionState.setConnectionStatus(U.Connected);
1616
+ this.sessionState.setConnectionStatus(F.Connected);
1723
1617
  }, this.wsService.onFirstToken = (p) => {
1724
1618
  this.localEmitFirstToken(p);
1725
- }, this.wsService.onClose = (p, O) => {
1726
- p != K && this.sessionState.setConnectionStatus(U.Disconnected);
1619
+ }, this.wsService.onClose = (p, M) => {
1620
+ p != H && this.sessionState.setConnectionStatus(F.Disconnected);
1727
1621
  };
1728
1622
  }
1729
- reset(e, s) {
1730
- throw new Error("Method not implemented.");
1731
- }
1732
1623
  startStream(e) {
1733
1624
  throw new Error("Method not implemented.");
1734
1625
  }
@@ -1736,7 +1627,7 @@ const Jt = "envision_agent_sessionId", tt = class tt extends H {
1736
1627
  return this.suspendState;
1737
1628
  }
1738
1629
  getStoredSessionId() {
1739
- const e = localStorage.getItem(Jt);
1630
+ const e = localStorage.getItem(qt);
1740
1631
  if (e)
1741
1632
  return e;
1742
1633
  }
@@ -1748,15 +1639,15 @@ const Jt = "envision_agent_sessionId", tt = class tt extends H {
1748
1639
  const s = this.interactionsMap.get(e);
1749
1640
  return s == null ? void 0 : s.turn_complete;
1750
1641
  }
1751
- async finalResponse(e, s, i) {
1752
- super.turnComplete(e, s, i);
1642
+ async finalResponse(e, s, a) {
1643
+ super.turnComplete(e, s, a);
1753
1644
  }
1754
1645
  stopStream(e = !0) {
1755
1646
  e && this.sessionState.setTurnOpen(!1), this.wsService && this.wsService.closeStream();
1756
1647
  }
1757
1648
  async suspend() {
1758
1649
  const e = this.wsService;
1759
- return new Promise(async (i, n) => {
1650
+ return new Promise(async (a, n) => {
1760
1651
  let r = !1;
1761
1652
  e.onSuspended = () => {
1762
1653
  r = !0;
@@ -1768,7 +1659,7 @@ const Jt = "envision_agent_sessionId", tt = class tt extends H {
1768
1659
  if (r)
1769
1660
  if (this.currentIS) {
1770
1661
  const u = this.currentIS.interaction;
1771
- u.isSuspended = !0, this.sessionState.setCurrentMessage(u), this.sessionState.setTurnOpen(!1), i(!0);
1662
+ u.isSuspended = !0, this.sessionState.setCurrentMessage(u), this.sessionState.setTurnOpen(!1), a(!0);
1772
1663
  } else
1773
1664
  console.error("CurrentIS is null"), n("CurrentIS is null");
1774
1665
  else
@@ -1787,8 +1678,8 @@ const Jt = "envision_agent_sessionId", tt = class tt extends H {
1787
1678
  */
1788
1679
  answerHumanTool(e, s) {
1789
1680
  var n;
1790
- const i = (n = this.wsService.answerHumanTool) == null ? void 0 : n.bind(this.wsService);
1791
- return i ? i(e, s) : (console.warn("[AgentGateway] transport cannot deliver parked-tool answers", e), "queued");
1681
+ const a = (n = this.wsService.answerHumanTool) == null ? void 0 : n.bind(this.wsService);
1682
+ return a ? a(e, s) : (console.warn("[AgentGateway] transport cannot deliver parked-tool answers", e), "queued");
1792
1683
  }
1793
1684
  async cancelSuspend() {
1794
1685
  var s;
@@ -1799,9 +1690,9 @@ const Jt = "envision_agent_sessionId", tt = class tt extends H {
1799
1690
  return !0;
1800
1691
  }
1801
1692
  async openConnection(e, s) {
1802
- return this.lastConnectionPromise ? this.lastConnectionPromise : this.socketState == U.Disconnected ? (this.lastConnectionPromise = new Promise((i, n) => {
1693
+ return this.lastConnectionPromise ? this.lastConnectionPromise : this.socketState == F.Disconnected ? (this.lastConnectionPromise = new Promise((a, n) => {
1803
1694
  this.wsService.connect(e, s).then((r) => {
1804
- this.sessionId = r, i(r);
1695
+ this.sessionId = r, a(r);
1805
1696
  }).catch((r) => {
1806
1697
  n(r);
1807
1698
  }).finally(() => {
@@ -1823,28 +1714,28 @@ const Jt = "envision_agent_sessionId", tt = class tt extends H {
1823
1714
  }
1824
1715
  }
1825
1716
  simulateDisconnect(e = 4500, s = "Debug simulated disconnect") {
1826
- const i = this.wsService;
1827
- i != null && i.ws && i.ws.close(e, s);
1717
+ const a = this.wsService;
1718
+ a != null && a.ws && a.ws.close(e, s);
1828
1719
  }
1829
1720
  async sleep(e) {
1830
1721
  return new Promise((s) => setTimeout(s, e));
1831
1722
  }
1832
1723
  // Send a message to the server via HTTP POST
1833
- async sendMessageInternal(e, s, i) {
1834
- var l, o, d, u, h, C, p, O;
1724
+ async sendMessageInternal(e, s, a) {
1725
+ var l, c, d, u, h, C, p, M;
1835
1726
  const n = this.suspendState;
1836
1727
  this.suspendState = !1;
1837
1728
  const r = this.startInteraction(e.friendlyMessage ?? e.data, n);
1838
- if (this.registerInteractionCallId(r.interactionId, s), (l = e.userUi) != null && l.name && r.parts.push(_.fromUserUi(e.userUi.name, e.userUi.args)), !this.wsService)
1729
+ if (this.registerInteractionCallId(r.interactionId, s), (l = e.userUi) != null && l.name && r.parts.push(N.fromUserUi(e.userUi.name, e.userUi.args)), !this.wsService)
1839
1730
  throw "no wsService created";
1840
1731
  if (!this.sessionId)
1841
1732
  throw "no session id set";
1842
- if (!((o = this.config.agentConfig) != null && o.id))
1733
+ if (!((c = this.config.agentConfig) != null && c.id))
1843
1734
  throw "Agent not selected";
1844
1735
  return this.wsService.sendMessage({
1845
1736
  Content: e.data,
1846
1737
  SessionId: this.sessionId,
1847
- Action: W.SendMessage,
1738
+ Action: U.SendMessage,
1848
1739
  ModelId: this.config.model,
1849
1740
  InteractionId: r.interactionId,
1850
1741
  AgentId: (d = this.config.agentConfig) == null ? void 0 : d.id,
@@ -1860,28 +1751,28 @@ const Jt = "envision_agent_sessionId", tt = class tt extends H {
1860
1751
  },
1861
1752
  // Forward image attachments as a structured payload (PascalCase
1862
1753
  // keys to match the C# `Message.Images` / `MessageImage` model).
1863
- Images: (p = e.images) != null && p.length ? e.images.map((M) => ({ MimeType: M.mimeType, Data: M.data })) : void 0,
1754
+ Images: (p = e.images) != null && p.length ? e.images.map((w) => ({ MimeType: w.mimeType, Data: w.data })) : void 0,
1864
1755
  // Client-only UI representation for this turn (PascalCase to match the C# `Message.UserUi`
1865
1756
  // model). The server persists it as a UserUiContent sibling and strips it from the model
1866
1757
  // request; Content remains the only model-facing text.
1867
- UserUi: (O = e.userUi) != null && O.name ? { Name: e.userUi.name, Args: e.userUi.args } : void 0
1758
+ UserUi: (M = e.userUi) != null && M.name ? { Name: e.userUi.name, Args: e.userUi.args } : void 0
1868
1759
  }), this.localOpen(r.interactionId, "system"), Promise.resolve({
1869
1760
  interaction: r,
1870
1761
  success: !0
1871
1762
  });
1872
1763
  }
1873
1764
  };
1874
- g(tt, "AgentGatewayWSAsync");
1875
- let dt = tt;
1876
- const et = class et {
1765
+ f(Z, "AgentGatewayWSAsync");
1766
+ let ht = Z;
1767
+ const V = class V {
1877
1768
  constructor(t, e) {
1878
- a(this, "cache", /* @__PURE__ */ new Map());
1879
- a(this, "serverBaseUrl");
1880
- a(this, "accessToken");
1769
+ i(this, "cache", /* @__PURE__ */ new Map());
1770
+ i(this, "serverBaseUrl");
1771
+ i(this, "accessToken");
1881
1772
  this.serverBaseUrl = t.replace(/\/$/, ""), this.accessToken = e;
1882
1773
  }
1883
1774
  get headers() {
1884
- return { Authorization: `Bearer ${Ft(this.accessToken)}` };
1775
+ return { Authorization: `Bearer ${_t(this.accessToken)}` };
1885
1776
  }
1886
1777
  async init() {
1887
1778
  }
@@ -1910,8 +1801,8 @@ const et = class et {
1910
1801
  headers: this.headers
1911
1802
  });
1912
1803
  if (!s.ok) return null;
1913
- const i = await s.json();
1914
- return this.cache.set(i.id, i), i;
1804
+ const a = await s.json();
1805
+ return this.cache.set(a.id, a), a;
1915
1806
  } catch {
1916
1807
  return null;
1917
1808
  }
@@ -1928,17 +1819,17 @@ const et = class et {
1928
1819
  }
1929
1820
  }
1930
1821
  };
1931
- g(et, "HttpArtifactService");
1932
- let ft = et;
1822
+ f(V, "HttpArtifactService");
1823
+ let ut = V;
1933
1824
  export {
1934
- H as A,
1935
- G as E,
1936
- ft as H,
1937
- q as I,
1938
- ot as L,
1939
- ct as M,
1940
- ut as W,
1941
- dt as a,
1942
- te as u
1825
+ G as A,
1826
+ q as E,
1827
+ ut as H,
1828
+ B as I,
1829
+ at as L,
1830
+ rt as M,
1831
+ lt as W,
1832
+ ht as a,
1833
+ Vt as u
1943
1834
  };
1944
- //# sourceMappingURL=httpArtifactService-CpbRpTHb.js.map
1835
+ //# sourceMappingURL=httpArtifactService-Ba9xFy1E.js.map