@aintela/chat 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Memory-BUnmYGNv.js.map +1 -1
- package/dist/PersonaAvatar-tKaWpDeQ.js +199 -0
- package/dist/PersonaAvatar-tKaWpDeQ.js.map +1 -0
- package/dist/agent-team.d.ts +2 -0
- package/dist/agent-team.js +27 -0
- package/dist/agent-team.js.map +1 -0
- package/dist/components.js +7107 -7601
- package/dist/components.js.map +1 -1
- package/dist/{detachedRunActivity-jHa9SDv1.js → detachedRunActivity-CCrlilHK.js} +988 -901
- package/dist/detachedRunActivity-CCrlilHK.js.map +1 -0
- package/dist/hooks.js +1 -1
- package/dist/{httpSessionService-BIkDesYB.js → httpSessionService-BLiZMoLb.js} +117 -106
- package/dist/httpSessionService-BLiZMoLb.js.map +1 -0
- package/dist/index.js +284 -278
- package/dist/index.js.map +1 -1
- package/dist/models.js +1 -1
- package/dist/{serializer-DvR3nOcf.js → serializer-DvfyE4_t.js} +488 -461
- package/dist/serializer-DvfyE4_t.js.map +1 -0
- package/dist/services.js +2 -2
- package/dist/src/agentTeam.d.ts +3 -0
- package/dist/src/components/AgentTeam/PersonaAvatar.d.ts +7 -1
- package/dist/src/components/AgentTeam/__tests__/personaFixtures.d.ts +3 -0
- package/dist/src/components/AgentTeam/agentRoles.d.ts +2 -2
- package/dist/src/components/AgentTeam/chatAgent.d.ts +1 -1
- package/dist/src/components/AgentTeam/personas.d.ts +65 -4
- package/dist/src/components/AiChat/ChatPane/chatTurnLiveQuestion.test.d.ts +1 -0
- package/dist/src/components/AiChat/stateConfiguration.d.ts +19 -0
- package/dist/src/components/v2/PromptV2.d.ts +6 -0
- package/dist/src/models/Interaction.d.ts +6 -1
- package/dist/src/models/contexts.d.ts +6 -0
- package/dist/src/models/enums.d.ts +6 -1
- package/dist/src/models/semanticKernelModel/models.d.ts +10 -1
- package/dist/src/services/servers/AgentGatewayWSAsync.d.ts +31 -0
- package/dist/src/services/servers/gatewayQueueMessage.test.d.ts +1 -0
- package/dist/{useChatSessions-CyFKVtkk.js → useChatSessions-BI3bHoOh.js} +2 -2
- package/dist/{useChatSessions-CyFKVtkk.js.map → useChatSessions-BI3bHoOh.js.map} +1 -1
- package/package.json +8 -1
- package/dist/detachedRunActivity-jHa9SDv1.js.map +0 -1
- package/dist/httpSessionService-BIkDesYB.js.map +0 -1
- package/dist/serializer-DvR3nOcf.js.map +0 -1
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var h = (i,
|
|
4
|
-
var
|
|
5
|
-
import { i as
|
|
6
|
-
import { format as
|
|
7
|
-
import
|
|
8
|
-
import { C as E, P as
|
|
9
|
-
import { d as
|
|
10
|
-
import { r as
|
|
11
|
-
const
|
|
1
|
+
var we = Object.defineProperty;
|
|
2
|
+
var be = (i, e, t) => e in i ? we(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
|
+
var h = (i, e) => we(i, "name", { value: e, configurable: !0 });
|
|
4
|
+
var a = (i, e, t) => be(i, typeof e != "symbol" ? e + "" : e, t);
|
|
5
|
+
import { i as U, E as I, S as q, z as Se, C as F, j as Le, L as Pe, P as z, n as Fe, q as Ne, T as _e, o as Ue, s as te, B as qe } from "./serializer-DvfyE4_t.js";
|
|
6
|
+
import { format as xe } from "date-fns";
|
|
7
|
+
import We from "lodash";
|
|
8
|
+
import { C as E, P as Be } from "./Prompt-DZb7OaPp.js";
|
|
9
|
+
import { d as Ge } from "./environmentUtils-VZNTCzEE.js";
|
|
10
|
+
import { r as ze } from "./httpSessionService-BLiZMoLb.js";
|
|
11
|
+
const K = {
|
|
12
12
|
PROMPTS: "envision-prompts"
|
|
13
|
-
},
|
|
13
|
+
}, He = 50, ne = class ne {
|
|
14
14
|
getPrompts() {
|
|
15
15
|
try {
|
|
16
|
-
const
|
|
17
|
-
return
|
|
18
|
-
} catch (
|
|
19
|
-
return console.error("Error loading prompts:",
|
|
16
|
+
const e = localStorage.getItem(K.PROMPTS);
|
|
17
|
+
return e ? JSON.parse(e).sort((s, n) => new Date(n.created).getTime() - new Date(s.created).getTime()) : [];
|
|
18
|
+
} catch (e) {
|
|
19
|
+
return console.error("Error loading prompts:", e), [];
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
@@ -37,161 +37,161 @@ const Q = {
|
|
|
37
37
|
* separate entries — that is deliberate, not an oversight: normalising them
|
|
38
38
|
* would mean re-surfacing text the user never typed.
|
|
39
39
|
*/
|
|
40
|
-
storePrompt(
|
|
40
|
+
storePrompt(e) {
|
|
41
41
|
try {
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
} catch (
|
|
45
|
-
console.error("Error storing prompt:",
|
|
42
|
+
const t = this.getPrompts().filter((s) => s.promptText !== e.promptText);
|
|
43
|
+
t.unshift(e), localStorage.setItem(K.PROMPTS, JSON.stringify(t.slice(0, He)));
|
|
44
|
+
} catch (t) {
|
|
45
|
+
console.error("Error storing prompt:", t);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
clearAllPrompts() {
|
|
49
49
|
try {
|
|
50
|
-
localStorage.removeItem(
|
|
51
|
-
} catch (
|
|
52
|
-
console.error("Error clearing prompts:",
|
|
50
|
+
localStorage.removeItem(K.PROMPTS);
|
|
51
|
+
} catch (e) {
|
|
52
|
+
console.error("Error clearing prompts:", e);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
|
-
h(
|
|
57
|
-
let
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
61
|
-
const s =
|
|
62
|
-
return { promptState:
|
|
56
|
+
h(ne, "LocalStorageService");
|
|
57
|
+
let Ie = ne;
|
|
58
|
+
const Rt = /* @__PURE__ */ h((i) => {
|
|
59
|
+
const e = i.getPrompts(), t = e.length;
|
|
60
|
+
if (t > 0) {
|
|
61
|
+
const s = e[0].promptText, n = e[e.length - 1].promptText, r = e[0].created;
|
|
62
|
+
return { promptState: t + "_" + s + "_" + n + "_" + r };
|
|
63
63
|
} else
|
|
64
64
|
return { promptState: "0" };
|
|
65
|
-
}, "usePromptState"),
|
|
65
|
+
}, "usePromptState"), ie = class ie {
|
|
66
66
|
constructor() {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
67
|
+
a(this, "artifactGenerated", "artifactGenerated");
|
|
68
|
+
a(this, "artifactSelected", "artifactSelected");
|
|
69
|
+
a(this, "gatewayMessage", "gatewayMessage");
|
|
70
|
+
a(this, "gatewayTurnComplete", "gatewayTurnComplete");
|
|
71
|
+
a(this, "gatewayStreamError", "gatewayStreamError");
|
|
72
|
+
a(this, "gatewayConnected", "gatewayConnected");
|
|
73
|
+
a(this, "gatewayTurnOpen", "gatewayTurnOpen");
|
|
74
|
+
a(this, "gatewayFunctionResponse", "gatewayFunctionResponse");
|
|
75
|
+
a(this, "uiAskQuestion", "uiAskQuestion");
|
|
76
|
+
a(this, "gatewayEndMessageData", "gatewayEndMessageData");
|
|
77
|
+
a(this, "onMessageSent", "onMessageSent");
|
|
78
|
+
a(this, "onMessageError", "onMessageError");
|
|
79
|
+
a(this, "onToolEvent", "onToolEvent");
|
|
80
|
+
a(this, "gatewayFirstToken", "gatewayFirstToken");
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
|
-
h(
|
|
84
|
-
let X =
|
|
85
|
-
const d = new X(),
|
|
83
|
+
h(ie, "EventTypes");
|
|
84
|
+
let X = ie;
|
|
85
|
+
const d = new X(), re = class re {
|
|
86
86
|
constructor() {
|
|
87
|
-
|
|
87
|
+
a(this, "listeners", {});
|
|
88
88
|
}
|
|
89
|
-
callListeners(
|
|
90
|
-
const s = this.listeners[
|
|
89
|
+
callListeners(e, ...t) {
|
|
90
|
+
const s = this.listeners[e];
|
|
91
91
|
if (s) {
|
|
92
|
-
const n = s.map((r) => r(...
|
|
92
|
+
const n = s.map((r) => r(...t));
|
|
93
93
|
Promise.all(n).catch((r) => {
|
|
94
|
-
console.error(`Lost error in one of the listeners of the event: ${
|
|
94
|
+
console.error(`Lost error in one of the listeners of the event: ${e}, listeners: ${s.length}, error: ${r}`, s);
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
addListener(
|
|
99
|
-
this.listeners[
|
|
98
|
+
addListener(e, t) {
|
|
99
|
+
this.listeners[e] || (this.listeners[e] = []), this.listeners[e].push(t);
|
|
100
100
|
}
|
|
101
|
-
removeListener(
|
|
102
|
-
this.listeners[
|
|
101
|
+
removeListener(e, t) {
|
|
102
|
+
this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
|
|
103
103
|
}
|
|
104
104
|
/* typed artifact listeners */
|
|
105
|
-
artifactOnGenerated(
|
|
106
|
-
this.addListener(d.artifactGenerated,
|
|
105
|
+
artifactOnGenerated(e) {
|
|
106
|
+
this.addListener(d.artifactGenerated, e);
|
|
107
107
|
}
|
|
108
|
-
artifactEmitGenerated(
|
|
109
|
-
this.callListeners(d.artifactGenerated,
|
|
108
|
+
artifactEmitGenerated(e) {
|
|
109
|
+
this.callListeners(d.artifactGenerated, e);
|
|
110
110
|
}
|
|
111
|
-
artifactOffGenerated(
|
|
112
|
-
this.removeListener(d.artifactGenerated,
|
|
111
|
+
artifactOffGenerated(e) {
|
|
112
|
+
this.removeListener(d.artifactGenerated, e);
|
|
113
113
|
}
|
|
114
|
-
artifactOnSelected(
|
|
115
|
-
this.addListener(d.artifactSelected,
|
|
114
|
+
artifactOnSelected(e) {
|
|
115
|
+
this.addListener(d.artifactSelected, e);
|
|
116
116
|
}
|
|
117
|
-
artifactEmitSelected(
|
|
118
|
-
this.callListeners(d.artifactSelected,
|
|
117
|
+
artifactEmitSelected(e) {
|
|
118
|
+
this.callListeners(d.artifactSelected, e);
|
|
119
119
|
}
|
|
120
|
-
artifactOffSelected(
|
|
121
|
-
this.removeListener(d.artifactSelected,
|
|
120
|
+
artifactOffSelected(e) {
|
|
121
|
+
this.removeListener(d.artifactSelected, e);
|
|
122
122
|
}
|
|
123
|
-
gatewayOnMessage(
|
|
124
|
-
this.addListener(d.gatewayMessage,
|
|
123
|
+
gatewayOnMessage(e) {
|
|
124
|
+
this.addListener(d.gatewayMessage, e);
|
|
125
125
|
}
|
|
126
|
-
gatewayEmitMessage(
|
|
127
|
-
this.callListeners(d.gatewayMessage,
|
|
126
|
+
gatewayEmitMessage(e) {
|
|
127
|
+
this.callListeners(d.gatewayMessage, e);
|
|
128
128
|
}
|
|
129
|
-
gatewayOffMessage(
|
|
130
|
-
this.removeListener(d.gatewayMessage,
|
|
129
|
+
gatewayOffMessage(e) {
|
|
130
|
+
this.removeListener(d.gatewayMessage, e);
|
|
131
131
|
}
|
|
132
|
-
gatewayOnTurnComplete(
|
|
133
|
-
this.addListener(d.gatewayTurnComplete,
|
|
132
|
+
gatewayOnTurnComplete(e) {
|
|
133
|
+
this.addListener(d.gatewayTurnComplete, e);
|
|
134
134
|
}
|
|
135
|
-
gatewayEmitTurnComplete(
|
|
136
|
-
this.callListeners(d.gatewayTurnComplete,
|
|
135
|
+
gatewayEmitTurnComplete(e, t) {
|
|
136
|
+
this.callListeners(d.gatewayTurnComplete, e, t);
|
|
137
137
|
}
|
|
138
|
-
gatewayOffTurnComplete(
|
|
139
|
-
this.removeListener(d.gatewayTurnComplete,
|
|
138
|
+
gatewayOffTurnComplete(e) {
|
|
139
|
+
this.removeListener(d.gatewayTurnComplete, e);
|
|
140
140
|
}
|
|
141
|
-
gatewayOnTurnOpen(
|
|
142
|
-
this.addListener(d.gatewayTurnOpen,
|
|
141
|
+
gatewayOnTurnOpen(e) {
|
|
142
|
+
this.addListener(d.gatewayTurnOpen, e);
|
|
143
143
|
}
|
|
144
|
-
gatewayEmitTurnOpen(
|
|
145
|
-
this.callListeners(d.gatewayTurnOpen,
|
|
144
|
+
gatewayEmitTurnOpen(e) {
|
|
145
|
+
this.callListeners(d.gatewayTurnOpen, e);
|
|
146
146
|
}
|
|
147
|
-
gatewayOffTurnOpen(
|
|
148
|
-
this.removeListener(d.gatewayTurnOpen,
|
|
147
|
+
gatewayOffTurnOpen(e) {
|
|
148
|
+
this.removeListener(d.gatewayTurnOpen, e);
|
|
149
149
|
}
|
|
150
|
-
gatewayOnStreamError(
|
|
151
|
-
this.addListener(d.gatewayStreamError,
|
|
150
|
+
gatewayOnStreamError(e) {
|
|
151
|
+
this.addListener(d.gatewayStreamError, e);
|
|
152
152
|
}
|
|
153
|
-
gatewayEmitStreamError(
|
|
154
|
-
this.callListeners(d.gatewayStreamError,
|
|
153
|
+
gatewayEmitStreamError(e) {
|
|
154
|
+
this.callListeners(d.gatewayStreamError, e);
|
|
155
155
|
}
|
|
156
|
-
gatewayOffStreamError(
|
|
157
|
-
this.removeListener(d.gatewayStreamError,
|
|
156
|
+
gatewayOffStreamError(e) {
|
|
157
|
+
this.removeListener(d.gatewayStreamError, e);
|
|
158
158
|
}
|
|
159
159
|
/** The live socket is up and the session proven — on the first open and on every reconnect (`info.reconnect`). */
|
|
160
|
-
gatewayOnConnected(
|
|
161
|
-
this.addListener(d.gatewayConnected,
|
|
160
|
+
gatewayOnConnected(e) {
|
|
161
|
+
this.addListener(d.gatewayConnected, e);
|
|
162
162
|
}
|
|
163
|
-
gatewayEmitConnected(
|
|
164
|
-
this.callListeners(d.gatewayConnected,
|
|
163
|
+
gatewayEmitConnected(e, t) {
|
|
164
|
+
this.callListeners(d.gatewayConnected, e, t);
|
|
165
165
|
}
|
|
166
|
-
gatewayOffConnected(
|
|
167
|
-
this.removeListener(d.gatewayConnected,
|
|
166
|
+
gatewayOffConnected(e) {
|
|
167
|
+
this.removeListener(d.gatewayConnected, e);
|
|
168
168
|
}
|
|
169
|
-
chatOnMessageSent(
|
|
170
|
-
this.addListener(d.onMessageSent,
|
|
169
|
+
chatOnMessageSent(e) {
|
|
170
|
+
this.addListener(d.onMessageSent, e);
|
|
171
171
|
}
|
|
172
|
-
chatOffMessageSent(
|
|
173
|
-
this.removeListener(d.onMessageSent,
|
|
172
|
+
chatOffMessageSent(e) {
|
|
173
|
+
this.removeListener(d.onMessageSent, e);
|
|
174
174
|
}
|
|
175
|
-
ChatEmitMessageSent(
|
|
176
|
-
this.callListeners(d.onMessageSent,
|
|
175
|
+
ChatEmitMessageSent(e, t) {
|
|
176
|
+
this.callListeners(d.onMessageSent, e, t);
|
|
177
177
|
}
|
|
178
|
-
chatOnMessageError(
|
|
179
|
-
this.addListener(d.onMessageError,
|
|
178
|
+
chatOnMessageError(e) {
|
|
179
|
+
this.addListener(d.onMessageError, e);
|
|
180
180
|
}
|
|
181
|
-
chatOffMessageError(
|
|
182
|
-
this.removeListener(d.onMessageError,
|
|
181
|
+
chatOffMessageError(e) {
|
|
182
|
+
this.removeListener(d.onMessageError, e);
|
|
183
183
|
}
|
|
184
|
-
ChatEmitMessageError(
|
|
185
|
-
this.callListeners(d.onMessageError,
|
|
184
|
+
ChatEmitMessageError(e) {
|
|
185
|
+
this.callListeners(d.onMessageError, e);
|
|
186
186
|
}
|
|
187
|
-
gatewayOnFunctionResponse(
|
|
188
|
-
this.addListener(d.gatewayFunctionResponse,
|
|
187
|
+
gatewayOnFunctionResponse(e) {
|
|
188
|
+
this.addListener(d.gatewayFunctionResponse, e);
|
|
189
189
|
}
|
|
190
|
-
gatewayEmitFunctionResponse(
|
|
191
|
-
this.callListeners(d.gatewayFunctionResponse,
|
|
190
|
+
gatewayEmitFunctionResponse(e) {
|
|
191
|
+
this.callListeners(d.gatewayFunctionResponse, e);
|
|
192
192
|
}
|
|
193
|
-
gatewayOffFunctionResponse(
|
|
194
|
-
this.removeListener(d.gatewayFunctionResponse,
|
|
193
|
+
gatewayOffFunctionResponse(e) {
|
|
194
|
+
this.removeListener(d.gatewayFunctionResponse, e);
|
|
195
195
|
}
|
|
196
196
|
// "Re-ask this" — a `#ask-…` link in the transcript, carrying the link's TEXT as the question.
|
|
197
197
|
// An event rather than component state because the prompt that must send it is not always
|
|
@@ -199,94 +199,94 @@ const d = new X(), rt = class rt {
|
|
|
199
199
|
// its tree, and that instance cannot see ChatPane's `useState`. Whichever prompt is mounted
|
|
200
200
|
// listens; ChatPane publishes only when its internal one is suppressed, so the question is
|
|
201
201
|
// never sent twice.
|
|
202
|
-
uiOnAskQuestion(
|
|
203
|
-
this.addListener(d.uiAskQuestion,
|
|
202
|
+
uiOnAskQuestion(e) {
|
|
203
|
+
this.addListener(d.uiAskQuestion, e);
|
|
204
204
|
}
|
|
205
|
-
uiEmitAskQuestion(
|
|
206
|
-
this.callListeners(d.uiAskQuestion,
|
|
205
|
+
uiEmitAskQuestion(e) {
|
|
206
|
+
this.callListeners(d.uiAskQuestion, e);
|
|
207
207
|
}
|
|
208
|
-
uiOffAskQuestion(
|
|
209
|
-
this.removeListener(d.uiAskQuestion,
|
|
208
|
+
uiOffAskQuestion(e) {
|
|
209
|
+
this.removeListener(d.uiAskQuestion, e);
|
|
210
210
|
}
|
|
211
|
-
gatewayOnEndMessageData(
|
|
212
|
-
this.addListener(d.gatewayEndMessageData,
|
|
211
|
+
gatewayOnEndMessageData(e) {
|
|
212
|
+
this.addListener(d.gatewayEndMessageData, e);
|
|
213
213
|
}
|
|
214
|
-
gatewayEmitEndMessageData(
|
|
215
|
-
this.callListeners(d.gatewayEndMessageData,
|
|
214
|
+
gatewayEmitEndMessageData(e) {
|
|
215
|
+
this.callListeners(d.gatewayEndMessageData, e);
|
|
216
216
|
}
|
|
217
|
-
gatewayOffEndMessageData(
|
|
218
|
-
this.removeListener(d.gatewayEndMessageData,
|
|
217
|
+
gatewayOffEndMessageData(e) {
|
|
218
|
+
this.removeListener(d.gatewayEndMessageData, e);
|
|
219
219
|
}
|
|
220
|
-
gatewayOnToolEvent(
|
|
221
|
-
this.addListener(d.onToolEvent,
|
|
220
|
+
gatewayOnToolEvent(e) {
|
|
221
|
+
this.addListener(d.onToolEvent, e);
|
|
222
222
|
}
|
|
223
|
-
gatewayEmitToolEvent(
|
|
224
|
-
this.callListeners(d.onToolEvent,
|
|
223
|
+
gatewayEmitToolEvent(e, t, s) {
|
|
224
|
+
this.callListeners(d.onToolEvent, e, t, s);
|
|
225
225
|
}
|
|
226
|
-
gatewayOffToolEvent(
|
|
227
|
-
this.removeListener(d.onToolEvent,
|
|
226
|
+
gatewayOffToolEvent(e) {
|
|
227
|
+
this.removeListener(d.onToolEvent, e);
|
|
228
228
|
}
|
|
229
|
-
gatewayOnFirstToken(
|
|
230
|
-
this.addListener(d.gatewayFirstToken,
|
|
229
|
+
gatewayOnFirstToken(e) {
|
|
230
|
+
this.addListener(d.gatewayFirstToken, e);
|
|
231
231
|
}
|
|
232
|
-
gatewayEmitFirstToken(
|
|
233
|
-
this.callListeners(d.gatewayFirstToken,
|
|
232
|
+
gatewayEmitFirstToken(e) {
|
|
233
|
+
this.callListeners(d.gatewayFirstToken, e);
|
|
234
234
|
}
|
|
235
|
-
gatewayOffFirstToken(
|
|
236
|
-
this.removeListener(d.gatewayFirstToken,
|
|
235
|
+
gatewayOffFirstToken(e) {
|
|
236
|
+
this.removeListener(d.gatewayFirstToken, e);
|
|
237
237
|
}
|
|
238
238
|
};
|
|
239
|
-
h(
|
|
240
|
-
let
|
|
241
|
-
const
|
|
242
|
-
function
|
|
239
|
+
h(re, "EventBusService");
|
|
240
|
+
let Te = re;
|
|
241
|
+
const Qe = 2e3;
|
|
242
|
+
function x(i) {
|
|
243
243
|
i.parts === i.prev.parts && (i.parts = i.prev.parts.slice());
|
|
244
244
|
}
|
|
245
|
-
h(
|
|
246
|
-
function
|
|
245
|
+
h(x, "ownParts");
|
|
246
|
+
function Q(i) {
|
|
247
247
|
i.functionMap === i.prev.functionMap && (i.functionMap = new Map(i.functionMap));
|
|
248
248
|
}
|
|
249
|
-
h(
|
|
250
|
-
const
|
|
251
|
-
function
|
|
252
|
-
var
|
|
253
|
-
return !!(!
|
|
249
|
+
h(Q, "ownFunctionMap");
|
|
250
|
+
const je = /* @__PURE__ */ h((i) => i == I.FunctionCall || i == I.PartialFunctionCall, "isFunctionCall"), Je = /* @__PURE__ */ h((i) => i == I.FunctionResponse, "isFunctionResponse"), Oe = /* @__PURE__ */ h((i) => i.parts.length + 1 + "-" + i.prev.interactionId, "nextPartId");
|
|
251
|
+
function Ke(i, e) {
|
|
252
|
+
var t, s, n, r, o;
|
|
253
|
+
return !!(!e || i.mustPush || i.mustPush === !1 && (i.eventType !== e.eventType || ((t = i.functionDetails) == null ? void 0 : t.id) !== ((s = e.functionDetails) == null ? void 0 : s.id)) || i.textAppendable && (((r = (n = e.thoughtDetails) == null ? void 0 : n.text) == null ? void 0 : r.length) ?? ((o = e.text) == null ? void 0 : o.length) ?? 0) > Qe);
|
|
254
254
|
}
|
|
255
|
-
h(
|
|
256
|
-
function
|
|
257
|
-
const
|
|
258
|
-
var
|
|
259
|
-
return ((
|
|
255
|
+
h(Ke, "opensNewPart");
|
|
256
|
+
function Ye(i, e) {
|
|
257
|
+
const t = e.functionDetails.id, s = e.functionDetails.clientOutput, n = i.parts.findIndex((r) => {
|
|
258
|
+
var o;
|
|
259
|
+
return ((o = r.functionDetails) == null ? void 0 : o.id) === t;
|
|
260
260
|
});
|
|
261
261
|
if (n > -1) {
|
|
262
|
-
const r = i.parts[n],
|
|
262
|
+
const r = i.parts[n], o = {
|
|
263
263
|
...r,
|
|
264
264
|
functionDetails: {
|
|
265
265
|
...r.functionDetails,
|
|
266
266
|
clientOutput: s ?? r.functionDetails.clientOutput,
|
|
267
267
|
// Sticky true-wins: this event IS the park, and a later merge must not clear it.
|
|
268
|
-
parked:
|
|
268
|
+
parked: e.functionDetails.parked === !0 || r.functionDetails.parked === !0
|
|
269
269
|
}
|
|
270
270
|
};
|
|
271
|
-
|
|
271
|
+
x(i), i.parts[n] = o, Q(i), i.functionMap.set(t, o);
|
|
272
272
|
} else {
|
|
273
273
|
const r = {
|
|
274
|
-
...
|
|
275
|
-
id:
|
|
276
|
-
functionDetails: { ...
|
|
274
|
+
...e,
|
|
275
|
+
id: Oe(i),
|
|
276
|
+
functionDetails: { ...e.functionDetails, silent: !0 }
|
|
277
277
|
};
|
|
278
|
-
|
|
278
|
+
x(i), i.parts.push(r), Q(i), i.functionMap.set(t, r);
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
|
-
h(
|
|
282
|
-
function
|
|
283
|
-
var
|
|
281
|
+
h(Ye, "foldClientOutput");
|
|
282
|
+
function Xe(i, e, t, s, n) {
|
|
283
|
+
var g;
|
|
284
284
|
const r = i.parts.findIndex((m) => {
|
|
285
285
|
var u;
|
|
286
286
|
return ((u = m.functionDetails) == null ? void 0 : u.id) === s;
|
|
287
|
-
}),
|
|
288
|
-
...
|
|
289
|
-
eventType:
|
|
287
|
+
}), o = r > -1 ? i.parts[r] : t, c = e.functionDetails, l = o.functionDetails, f = {
|
|
288
|
+
...o,
|
|
289
|
+
eventType: e.eventType,
|
|
290
290
|
functionDetails: {
|
|
291
291
|
id: l.id,
|
|
292
292
|
name: c.name ?? l.name,
|
|
@@ -312,126 +312,126 @@ function Xt(i, t, e, s, n) {
|
|
|
312
312
|
parked: c.parked === !0 || l.parked === !0
|
|
313
313
|
}
|
|
314
314
|
};
|
|
315
|
-
|
|
315
|
+
Q(i), i.functionMap.set(s, f), f.eventType === I.FunctionResponse && ((g = n == null ? void 0 : n.onFunctionResponse) == null || g.call(n, f.functionDetails)), r > -1 && (x(i), i.parts[r] = f);
|
|
316
316
|
}
|
|
317
|
-
h(
|
|
318
|
-
function
|
|
319
|
-
s &&
|
|
317
|
+
h(Xe, "foldFunctionEvent");
|
|
318
|
+
function Ve(i, e, t, s) {
|
|
319
|
+
s && e.functionDetails && (Q(i), i.functionMap.set(s, e));
|
|
320
320
|
const n = i.prev.parts[i.prev.parts.length - 1] ?? null;
|
|
321
|
-
n && n.textAppendable && (
|
|
321
|
+
n && n.textAppendable && (x(i), i.parts[i.parts.length - 1] = { ...n, ended: /* @__PURE__ */ new Date() });
|
|
322
322
|
const r = {
|
|
323
|
-
...
|
|
324
|
-
id:
|
|
325
|
-
partial:
|
|
323
|
+
...e,
|
|
324
|
+
id: Oe(i),
|
|
325
|
+
partial: t.partial
|
|
326
326
|
};
|
|
327
327
|
i.parts = [...i.parts, r];
|
|
328
328
|
}
|
|
329
|
-
h(
|
|
330
|
-
function
|
|
329
|
+
h(Ve, "openPart");
|
|
330
|
+
function Ze(i, e, t, s) {
|
|
331
331
|
const n = i.parts[i.parts.length - 1] ?? null;
|
|
332
332
|
if (!n) return;
|
|
333
333
|
const r = {
|
|
334
334
|
...n,
|
|
335
|
-
partial:
|
|
335
|
+
partial: t.partial,
|
|
336
336
|
textDetails: n.textDetails ? { ...n.textDetails } : { version: 0 }
|
|
337
337
|
};
|
|
338
|
-
if (
|
|
339
|
-
if (r.textDetails.version++, s || (r.text = (n.text ?? "") + (
|
|
340
|
-
const
|
|
341
|
-
(
|
|
338
|
+
if (t.partial) {
|
|
339
|
+
if (r.textDetails.version++, s || (r.text = (n.text ?? "") + (e.text ?? "")), !s && e.thoughtDetails && r.thoughtDetails) {
|
|
340
|
+
const o = e.thoughtDetails.text;
|
|
341
|
+
(o.length >= 50 || o.length < 50 && o !== r.thoughtDetails.text) && (r.thoughtDetails = { ...r.thoughtDetails, text: r.thoughtDetails.text + o });
|
|
342
342
|
}
|
|
343
343
|
} else
|
|
344
|
-
r.text =
|
|
345
|
-
|
|
344
|
+
r.text = e.text ?? "", r.textDetails.version++, e.thoughtDetails && (r.thoughtDetails = { ...e.thoughtDetails, text: e.thoughtDetails.text.trim() });
|
|
345
|
+
x(i), i.parts[i.parts.length - 1] = r;
|
|
346
346
|
}
|
|
347
|
-
h(
|
|
348
|
-
function
|
|
349
|
-
if (!
|
|
350
|
-
const
|
|
351
|
-
for (const s of
|
|
352
|
-
const n = s.toArtifact(), r =
|
|
353
|
-
r === -1 ?
|
|
347
|
+
h(Ze, "appendText");
|
|
348
|
+
function et(i, e) {
|
|
349
|
+
if (!e || e.length === 0) return i;
|
|
350
|
+
const t = i.slice();
|
|
351
|
+
for (const s of e) {
|
|
352
|
+
const n = s.toArtifact(), r = t.findIndex((o) => o.id === n.id);
|
|
353
|
+
r === -1 ? t.push(n) : t[r] = n;
|
|
354
354
|
}
|
|
355
|
-
return
|
|
355
|
+
return t;
|
|
356
356
|
}
|
|
357
|
-
h(
|
|
358
|
-
function
|
|
357
|
+
h(et, "mergeArtifacts");
|
|
358
|
+
function tt(i, e, t) {
|
|
359
359
|
var c, l;
|
|
360
|
-
const s =
|
|
360
|
+
const s = U.FlatParts(e == null ? void 0 : e.parts), n = i.parts[i.parts.length - 1] ?? null, r = {
|
|
361
361
|
prev: i,
|
|
362
362
|
parts: i.parts,
|
|
363
363
|
functionMap: i.functionMap ?? /* @__PURE__ */ new Map()
|
|
364
364
|
};
|
|
365
|
-
let
|
|
365
|
+
let o = !1;
|
|
366
366
|
if (s) {
|
|
367
367
|
if (s.eventType === I.FunctionClientOutput && !!((c = s.functionDetails) != null && c.id))
|
|
368
|
-
|
|
369
|
-
else if (
|
|
370
|
-
const
|
|
371
|
-
|
|
368
|
+
Ye(r, s);
|
|
369
|
+
else if (Ke(s, n)) {
|
|
370
|
+
const g = je(s.eventType) || Je(s.eventType), m = g ? (l = s.functionDetails) == null ? void 0 : l.id : void 0;
|
|
371
|
+
g && !m && console.error("Got isCall or isResponse without a callId", s);
|
|
372
372
|
const u = m ? r.functionMap.get(m) : void 0;
|
|
373
|
-
u && m && s.functionDetails ?
|
|
373
|
+
u && m && s.functionDetails ? Xe(r, s, u, m, t) : (Ve(r, s, e, m), o = !0);
|
|
374
374
|
}
|
|
375
|
-
s.textAppendable &&
|
|
375
|
+
s.textAppendable && Ze(r, s, e, o);
|
|
376
376
|
}
|
|
377
377
|
return {
|
|
378
378
|
...i,
|
|
379
379
|
version: i.version + 1,
|
|
380
380
|
parts: r.parts,
|
|
381
|
-
artifactData:
|
|
381
|
+
artifactData: et(i.artifactData ?? [], e.llmArtifacts),
|
|
382
382
|
functionMap: r.functionMap,
|
|
383
|
-
turn_complete:
|
|
384
|
-
partial:
|
|
385
|
-
asyncFinalResponse:
|
|
386
|
-
agent:
|
|
383
|
+
turn_complete: e.turn_complete,
|
|
384
|
+
partial: e.partial,
|
|
385
|
+
asyncFinalResponse: e.asyncFinalResponse,
|
|
386
|
+
agent: e.agent ?? i.agent
|
|
387
387
|
};
|
|
388
388
|
}
|
|
389
|
-
h(
|
|
390
|
-
const
|
|
391
|
-
constructor(
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
this.interaction =
|
|
389
|
+
h(tt, "reduceInteraction");
|
|
390
|
+
const oe = class oe {
|
|
391
|
+
constructor(e, t) {
|
|
392
|
+
a(this, "interaction");
|
|
393
|
+
a(this, "eventBusService");
|
|
394
|
+
this.interaction = e, this.eventBusService = t;
|
|
395
395
|
}
|
|
396
396
|
/**
|
|
397
397
|
* Computes the next interaction from a server event and makes it current.
|
|
398
398
|
* Pure with respect to the previous tree: snapshots already handed out to
|
|
399
399
|
* throttled subscribers cannot diverge from live state.
|
|
400
400
|
*/
|
|
401
|
-
merge(
|
|
402
|
-
const
|
|
401
|
+
merge(e) {
|
|
402
|
+
const t = tt(this.interaction, e, {
|
|
403
403
|
onFunctionResponse: /* @__PURE__ */ h((s) => this.eventBusService.gatewayEmitFunctionResponse(s), "onFunctionResponse")
|
|
404
404
|
});
|
|
405
|
-
return this.interaction =
|
|
405
|
+
return this.interaction = t, t;
|
|
406
406
|
}
|
|
407
407
|
};
|
|
408
|
-
h(
|
|
409
|
-
let j =
|
|
410
|
-
const
|
|
411
|
-
constructor(
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
408
|
+
h(oe, "InteractionService");
|
|
409
|
+
let j = oe;
|
|
410
|
+
const ke = 4001, st = 4002, De = 4004, nt = 4100, H = 500, it = 2e4, rt = 1e3, ot = 0.2, _ = 300 * 1e3, at = 0.75, ct = 2e3, S = "[Connection]", ae = class ae {
|
|
411
|
+
constructor(e) {
|
|
412
|
+
a(this, "ports");
|
|
413
|
+
a(this, "state");
|
|
414
|
+
a(this, "now");
|
|
415
|
+
a(this, "target", null);
|
|
416
|
+
a(this, "inflight", null);
|
|
417
|
+
a(this, "retryTimer", null);
|
|
418
|
+
a(this, "idleTimer", null);
|
|
419
|
+
a(this, "wait", H);
|
|
420
420
|
/** Consecutive failed attempts since the last proven connection. */
|
|
421
|
-
|
|
422
|
-
|
|
421
|
+
a(this, "attempt", 0);
|
|
422
|
+
a(this, "halted", null);
|
|
423
423
|
/** The code of the last close the transport reported, consumed by the next dial failure. */
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
this.ports =
|
|
428
|
-
this.state =
|
|
424
|
+
a(this, "lastCloseCode", null);
|
|
425
|
+
a(this, "everConnected", !1);
|
|
426
|
+
a(this, "idleWarningLogged", !1);
|
|
427
|
+
this.ports = e, this.now = e.now ?? (() => Date.now()), this.state = e.store.getState(), e.store.subscribe((t) => {
|
|
428
|
+
this.state = t;
|
|
429
429
|
});
|
|
430
430
|
}
|
|
431
431
|
// ─── Queries ────────────────────────────────────────────────────────────
|
|
432
432
|
get sessionId() {
|
|
433
|
-
var
|
|
434
|
-
return (
|
|
433
|
+
var e;
|
|
434
|
+
return (e = this.target) == null ? void 0 : e.sessionId;
|
|
435
435
|
}
|
|
436
436
|
get isSupervising() {
|
|
437
437
|
return this.target !== null;
|
|
@@ -448,8 +448,8 @@ const kt = 4001, se = 4002, Dt = 4004, ne = 4100, H = 500, ie = 2e4, re = 1e3, o
|
|
|
448
448
|
}
|
|
449
449
|
/** Connected by the store AND by the transport. */
|
|
450
450
|
get isUp() {
|
|
451
|
-
var
|
|
452
|
-
return this.state.connectionStatus === E.Connected && (((
|
|
451
|
+
var e, t;
|
|
452
|
+
return this.state.connectionStatus === E.Connected && (((t = (e = this.ports).isConnected) == null ? void 0 : t.call(e)) ?? !0);
|
|
453
453
|
}
|
|
454
454
|
// ─── Commands ───────────────────────────────────────────────────────────
|
|
455
455
|
/**
|
|
@@ -459,35 +459,35 @@ const kt = 4001, se = 4002, Dt = 4004, ne = 4100, H = 500, ie = 2e4, re = 1e3, o
|
|
|
459
459
|
* joins the dial in flight or returns the open socket's id; calling it for a different session
|
|
460
460
|
* hangs up the current one first.
|
|
461
461
|
*/
|
|
462
|
-
open(
|
|
463
|
-
if (this.target && this.sameTarget(
|
|
462
|
+
open(e, t) {
|
|
463
|
+
if (this.target && this.sameTarget(e)) {
|
|
464
464
|
if (this.inflight) return this.inflight;
|
|
465
465
|
if (this.isUp && this.target.sessionId && !this.halted)
|
|
466
466
|
return Promise.resolve(this.target.sessionId);
|
|
467
|
-
} else this.target && (console.log(`${S} switching from session ${this.target.sessionId ?? "(new)"} to ${
|
|
468
|
-
return this.halted = null, this.cancelRetry(), this.target = { sessionId:
|
|
467
|
+
} else this.target && (console.log(`${S} switching from session ${this.target.sessionId ?? "(new)"} to ${e ?? "(new)"}.`), this.close());
|
|
468
|
+
return this.halted = null, this.cancelRetry(), this.target = { sessionId: e, resume: (t == null ? void 0 : t.resume) === !0, prepare: t == null ? void 0 : t.prepare }, this.startIdleTick(), this.dial();
|
|
469
469
|
}
|
|
470
470
|
/**
|
|
471
471
|
* The send guard: make sure the socket is up before a frame goes out, dialling NOW (not at
|
|
472
472
|
* the next scheduled retry) when it is not. `fallbackSessionId` is what to dial when nothing
|
|
473
473
|
* was ever opened through here (a host that set the session on the gateway directly).
|
|
474
474
|
*/
|
|
475
|
-
async ensure(
|
|
476
|
-
var
|
|
475
|
+
async ensure(e) {
|
|
476
|
+
var t;
|
|
477
477
|
if (this.halted)
|
|
478
|
-
throw new Error(`The connection was halted (${this.halted}); session ${((
|
|
479
|
-
return this.target ? this.inflight ? this.inflight : this.isUp && this.target.sessionId ? this.target.sessionId : (console.warn(`${S} send guard: socket is DOWN at send time (session ${this.target.sessionId ?? "(new)"}, status ${this.state.connectionStatus}) — redialling now instead of in ${this.wait}ms.`), this.cancelRetry(), this.target.resume = !0, this.dial()) : (console.warn(`${S} send guard: nothing supervised yet — opening session ${
|
|
478
|
+
throw new Error(`The connection was halted (${this.halted}); session ${((t = this.target) == null ? void 0 : t.sessionId) ?? e ?? "none"} cannot be redialled.`);
|
|
479
|
+
return this.target ? this.inflight ? this.inflight : this.isUp && this.target.sessionId ? this.target.sessionId : (console.warn(`${S} send guard: socket is DOWN at send time (session ${this.target.sessionId ?? "(new)"}, status ${this.state.connectionStatus}) — redialling now instead of in ${this.wait}ms.`), this.cancelRetry(), this.target.resume = !0, this.dial()) : (console.warn(`${S} send guard: nothing supervised yet — opening session ${e ?? "(new)"} with the replay cursor.`), this.open(e, { resume: !0 }));
|
|
480
480
|
}
|
|
481
481
|
/** Stop supervising: hang up, cancel any retry, stop the idle tick. Never throws. */
|
|
482
482
|
close() {
|
|
483
|
-
const
|
|
483
|
+
const e = this.target;
|
|
484
484
|
this.target = null, this.halted = null, this.cancelRetry(), this.stopIdleTick(), this.wait = H, this.attempt = 0;
|
|
485
485
|
try {
|
|
486
486
|
this.ports.hangUp();
|
|
487
|
-
} catch (
|
|
488
|
-
console.error(`${S} hangUp threw`,
|
|
487
|
+
} catch (t) {
|
|
488
|
+
console.error(`${S} hangUp threw`, t);
|
|
489
489
|
}
|
|
490
|
-
|
|
490
|
+
e && this.state.setConnectionStatus(E.Disconnected);
|
|
491
491
|
}
|
|
492
492
|
// ─── Transport reports ──────────────────────────────────────────────────
|
|
493
493
|
/**
|
|
@@ -500,45 +500,45 @@ const kt = 4001, se = 4002, Dt = 4004, ne = 4100, H = 500, ie = 2e4, re = 1e3, o
|
|
|
500
500
|
* idle close, 4100 our heartbeat's dead-peer verdict): retry on the curve, cursor kept.
|
|
501
501
|
* A close that lands while a dial is in flight is remembered and judged when that dial fails.
|
|
502
502
|
*/
|
|
503
|
-
transportClosed(
|
|
504
|
-
if (
|
|
503
|
+
transportClosed(e, t) {
|
|
504
|
+
if (e !== ke && (this.lastCloseCode = e, !!this.target)) {
|
|
505
505
|
if (this.inflight) {
|
|
506
|
-
console.log(`${S} socket closed (code=${
|
|
506
|
+
console.log(`${S} socket closed (code=${e}) while a dial is in flight — judged when it settles.`);
|
|
507
507
|
return;
|
|
508
508
|
}
|
|
509
|
-
this.state.connectionStatus === E.Connected && (console.warn(`${S} socket closed: code=${
|
|
509
|
+
this.state.connectionStatus === E.Connected && (console.warn(`${S} socket closed: code=${e} reason="${t}" (session ${this.target.sessionId ?? "(new)"}).`), this.state.setConnectionStatus(E.Disconnected), this.judge(e));
|
|
510
510
|
}
|
|
511
511
|
}
|
|
512
512
|
// ─── The dial ───────────────────────────────────────────────────────────
|
|
513
513
|
dial() {
|
|
514
|
-
const
|
|
514
|
+
const e = this.target;
|
|
515
515
|
this.lastCloseCode = null, this.state.setConnectionStatus(E.Connecting);
|
|
516
|
-
const
|
|
517
|
-
console.log(`${S} dialling session ${
|
|
518
|
-
const n = (async () => (
|
|
516
|
+
const t = this.now();
|
|
517
|
+
console.log(`${S} dialling session ${e.sessionId ?? "(new)"}${e.resume ? " with the replay cursor" : ""}${this.everConnected ? " (reconnect)" : ""}.`);
|
|
518
|
+
const n = (async () => (e.prepare && await e.prepare(), this.ports.dial(e.sessionId, { resume: e.resume })))().then((r) => {
|
|
519
519
|
var c, l;
|
|
520
|
-
if (this.target !==
|
|
521
|
-
console.log(`${S} a dial for ${
|
|
520
|
+
if (this.target !== e) {
|
|
521
|
+
console.log(`${S} a dial for ${e.sessionId ?? "(new)"} resolved after it was abandoned — hanging up.`);
|
|
522
522
|
try {
|
|
523
523
|
this.ports.hangUp();
|
|
524
524
|
} catch {
|
|
525
525
|
}
|
|
526
526
|
throw new Error("Connection attempt abandoned");
|
|
527
527
|
}
|
|
528
|
-
if (
|
|
529
|
-
console.error(`${S} asked for session ${
|
|
528
|
+
if (e.sessionId && r !== e.sessionId) {
|
|
529
|
+
console.error(`${S} asked for session ${e.sessionId}, the server answered with ${r} — refusing the swap and halting.`);
|
|
530
530
|
try {
|
|
531
531
|
this.ports.hangUp();
|
|
532
532
|
} catch {
|
|
533
533
|
}
|
|
534
|
-
throw this.state.setConnectionStatus(E.Disconnected), this.halt("session-gone", { sessionId:
|
|
534
|
+
throw this.state.setConnectionStatus(E.Disconnected), this.halt("session-gone", { sessionId: e.sessionId, actualSessionId: r }), new Error(`Session ${e.sessionId} no longer exists on the server (it answered with ${r}).`);
|
|
535
535
|
}
|
|
536
|
-
const
|
|
537
|
-
return this.everConnected = !0,
|
|
536
|
+
const o = this.everConnected;
|
|
537
|
+
return this.everConnected = !0, e.sessionId = r, e.resume = !0, e.prepare = void 0, this.wait = H, this.attempt = 0, this.state.setConnectionStatus(E.Connected), console.log(`${S} ${o ? "reconnected to" : "connected to"} session ${r} in ${this.now() - t}ms.`), (l = (c = this.ports).onConnected) == null || l.call(c, r, { reconnect: o }), r;
|
|
538
538
|
}).catch((r) => {
|
|
539
|
-
if (this.target ===
|
|
540
|
-
const
|
|
541
|
-
console.error(`${S} dial of session ${
|
|
539
|
+
if (this.target === e && !this.halted) {
|
|
540
|
+
const o = this.lastCloseCode;
|
|
541
|
+
console.error(`${S} dial of session ${e.sessionId ?? "(new)"} failed after ${this.now() - t}ms${o !== null ? ` (socket closed with ${o})` : ""}:`, r), this.state.setConnectionStatus(E.Disconnected), this.inflight === n && (this.inflight = null), this.judge(o);
|
|
542
542
|
}
|
|
543
543
|
throw r;
|
|
544
544
|
}).finally(() => {
|
|
@@ -547,55 +547,55 @@ const kt = 4001, se = 4002, Dt = 4004, ne = 4100, H = 500, ie = 2e4, re = 1e3, o
|
|
|
547
547
|
return this.inflight = n, n;
|
|
548
548
|
}
|
|
549
549
|
/** Apply the close-code policy to a failure: halt, or schedule the next attempt. */
|
|
550
|
-
judge(
|
|
550
|
+
judge(e) {
|
|
551
551
|
var s;
|
|
552
|
-
const
|
|
553
|
-
if (
|
|
554
|
-
if (
|
|
555
|
-
if (
|
|
552
|
+
const t = (s = this.target) == null ? void 0 : s.sessionId;
|
|
553
|
+
if (e === st) return this.halt("attached-elsewhere", { sessionId: t, code: e });
|
|
554
|
+
if (e === De) return this.halt("session-gone", { sessionId: t, code: e });
|
|
555
|
+
if (e === 1e3 || e === 1008) return this.halt("closed-by-server", { sessionId: t, code: e });
|
|
556
556
|
this.scheduleRetry();
|
|
557
557
|
}
|
|
558
|
-
halt(
|
|
558
|
+
halt(e, t) {
|
|
559
559
|
var s, n;
|
|
560
|
-
this.halted =
|
|
560
|
+
this.halted = e, this.cancelRetry(), console.warn(`${S} halted (${e}) on session ${t.sessionId ?? "(new)"}${t.code !== void 0 ? `, close code ${t.code}` : ""} — no automatic redial; an explicit open() may try again.`);
|
|
561
561
|
try {
|
|
562
|
-
(n = (s = this.ports).onHalt) == null || n.call(s,
|
|
562
|
+
(n = (s = this.ports).onHalt) == null || n.call(s, e, t);
|
|
563
563
|
} catch (r) {
|
|
564
564
|
console.error(`${S} onHalt threw`, r);
|
|
565
565
|
}
|
|
566
566
|
}
|
|
567
567
|
scheduleRetry() {
|
|
568
|
-
var
|
|
568
|
+
var t, s;
|
|
569
569
|
if (!this.target || this.retryTimer || this.inflight) return;
|
|
570
570
|
if (!this.state.sessionActive) {
|
|
571
571
|
console.log(`${S} session idle — not redialling until activity resumes.`);
|
|
572
572
|
return;
|
|
573
573
|
}
|
|
574
|
-
const
|
|
575
|
-
this.wait = Math.min(Math.floor(this.wait + this.wait * this.wait /
|
|
574
|
+
const e = this.jittered(this.wait);
|
|
575
|
+
this.wait = Math.min(Math.floor(this.wait + this.wait * this.wait / rt), it), this.attempt += 1, console.warn(`${S} redialling session ${this.target.sessionId ?? "(new)"} in ${e}ms (then ${this.wait}ms, attempt ${this.attempt}).`);
|
|
576
576
|
try {
|
|
577
|
-
(s = (
|
|
577
|
+
(s = (t = this.ports).onRetryScheduled) == null || s.call(t, { sessionId: this.target.sessionId, delayMs: e, attempt: this.attempt });
|
|
578
578
|
} catch (n) {
|
|
579
579
|
console.error(`${S} onRetryScheduled threw`, n);
|
|
580
580
|
}
|
|
581
581
|
this.retryTimer = setTimeout(() => {
|
|
582
582
|
this.retryTimer = null, !(!this.target || this.halted) && (this.target.resume = !0, this.dial().catch(() => {
|
|
583
583
|
}));
|
|
584
|
-
},
|
|
584
|
+
}, e);
|
|
585
585
|
}
|
|
586
586
|
cancelRetry() {
|
|
587
587
|
this.retryTimer && (clearTimeout(this.retryTimer), this.retryTimer = null);
|
|
588
588
|
}
|
|
589
|
-
jittered(
|
|
590
|
-
return Math.max(0, Math.round(
|
|
589
|
+
jittered(e) {
|
|
590
|
+
return Math.max(0, Math.round(e + e * ot * (Math.random() * 2 - 1)));
|
|
591
591
|
}
|
|
592
|
-
sameTarget(
|
|
593
|
-
var
|
|
594
|
-
return ((
|
|
592
|
+
sameTarget(e) {
|
|
593
|
+
var t;
|
|
594
|
+
return ((t = this.target) == null ? void 0 : t.sessionId) === e;
|
|
595
595
|
}
|
|
596
596
|
// ─── Idle ───────────────────────────────────────────────────────────────
|
|
597
597
|
startIdleTick() {
|
|
598
|
-
this.idleTimer || (this.idleTimer = setInterval(() => this.tick(),
|
|
598
|
+
this.idleTimer || (this.idleTimer = setInterval(() => this.tick(), ct));
|
|
599
599
|
}
|
|
600
600
|
stopIdleTick() {
|
|
601
601
|
this.idleTimer && (clearInterval(this.idleTimer), this.idleTimer = null);
|
|
@@ -611,40 +611,40 @@ const kt = 4001, se = 4002, Dt = 4004, ne = 4100, H = 500, ie = 2e4, re = 1e3, o
|
|
|
611
611
|
tick() {
|
|
612
612
|
if (!this.target) return;
|
|
613
613
|
this.state.turnOpen && this.state.setLastActivity();
|
|
614
|
-
const
|
|
615
|
-
if (
|
|
614
|
+
const e = this.now() - this.state.lastActivity;
|
|
615
|
+
if (e > _) {
|
|
616
616
|
if (this.state.sessionActive && this.state.setIsSessionActive(!1), this.cancelRetry(), this.state.connectionStatus === E.Connected) {
|
|
617
|
-
console.warn(`${S} idle for ${Math.round(
|
|
617
|
+
console.warn(`${S} idle for ${Math.round(e / 1e3)}s (limit ${_ / 1e3}s) — closing the socket (session ${this.target.sessionId ?? "(new)"}). Activity, or a send, redials it.`);
|
|
618
618
|
try {
|
|
619
619
|
this.ports.hangUp();
|
|
620
|
-
} catch (
|
|
621
|
-
console.error(`${S} hangUp threw`,
|
|
620
|
+
} catch (t) {
|
|
621
|
+
console.error(`${S} hangUp threw`, t);
|
|
622
622
|
}
|
|
623
623
|
this.state.setConnectionStatus(E.Disconnected);
|
|
624
624
|
}
|
|
625
625
|
return;
|
|
626
626
|
}
|
|
627
627
|
this.state.sessionActive || (console.log(`${S} activity resumed — the session is active again.`), this.state.setIsSessionActive(!0), this.wait = H, this.state.connectionStatus === E.Disconnected && !this.halted && !this.inflight && (this.target.resume = !0, this.dial().catch(() => {
|
|
628
|
-
}))),
|
|
628
|
+
}))), e > _ * at ? this.idleWarningLogged || (this.idleWarningLogged = !0, console.warn(`${S} idle ${Math.round(e / 1e3)}s of ${_ / 1e3}s — the socket closes in about ${Math.round((_ - e) / 1e3)}s unless something happens.`)) : this.idleWarningLogged = !1;
|
|
629
629
|
}
|
|
630
630
|
};
|
|
631
|
-
h(
|
|
632
|
-
let V =
|
|
633
|
-
const
|
|
634
|
-
constructor(
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
this.options =
|
|
639
|
-
}
|
|
640
|
-
emit(
|
|
641
|
-
const
|
|
642
|
-
if (
|
|
643
|
-
this.clearTrailing(), this.publish(
|
|
631
|
+
h(ae, "ConnectionSupervisor");
|
|
632
|
+
let V = ae;
|
|
633
|
+
const ce = class ce {
|
|
634
|
+
constructor(e) {
|
|
635
|
+
a(this, "pending", null);
|
|
636
|
+
a(this, "lastPublishedAt", 0);
|
|
637
|
+
a(this, "trailing", null);
|
|
638
|
+
this.options = e;
|
|
639
|
+
}
|
|
640
|
+
emit(e) {
|
|
641
|
+
const t = Date.now(), s = t - this.lastPublishedAt;
|
|
642
|
+
if (e.partial === !1 || s >= this.options.windowMs) {
|
|
643
|
+
this.clearTrailing(), this.publish(e, t);
|
|
644
644
|
return;
|
|
645
645
|
}
|
|
646
|
-
this.pending =
|
|
647
|
-
this.trailing = null, this.pending && this.pending.version > this.options.publishedVersion() && this.publish(this.pending,
|
|
646
|
+
this.pending = e, this.clearTrailing(), this.trailing = setTimeout(() => {
|
|
647
|
+
this.trailing = null, this.pending && this.pending.version > this.options.publishedVersion() && this.publish(this.pending, t);
|
|
648
648
|
}, this.options.windowMs * 2);
|
|
649
649
|
}
|
|
650
650
|
/**
|
|
@@ -655,95 +655,101 @@ const ct = class ct {
|
|
|
655
655
|
cancelPending() {
|
|
656
656
|
this.clearTrailing(), this.pending = null;
|
|
657
657
|
}
|
|
658
|
-
publish(
|
|
659
|
-
this.lastPublishedAt =
|
|
658
|
+
publish(e, t) {
|
|
659
|
+
this.lastPublishedAt = t, this.pending = null, this.options.publish(e);
|
|
660
660
|
}
|
|
661
661
|
clearTrailing() {
|
|
662
662
|
this.trailing && (clearTimeout(this.trailing), this.trailing = null);
|
|
663
663
|
}
|
|
664
664
|
};
|
|
665
|
-
h(
|
|
666
|
-
let Z =
|
|
665
|
+
h(ce, "ThrottledEmitter");
|
|
666
|
+
let Z = ce;
|
|
667
667
|
const y = class y {
|
|
668
|
-
constructor(
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
668
|
+
constructor(e, t, s, n, r, o, c, l, f, g, m) {
|
|
669
|
+
a(this, "base_url");
|
|
670
|
+
a(this, "msg_order", 0);
|
|
671
|
+
a(this, "interactionsMap", /* @__PURE__ */ new Map());
|
|
672
|
+
a(this, "interactionsServiceMap", /* @__PURE__ */ new Map());
|
|
673
|
+
a(this, "user");
|
|
674
|
+
a(this, "config");
|
|
675
|
+
a(this, "currentIS", null);
|
|
676
|
+
a(this, "sessionState");
|
|
677
|
+
a(this, "storageService");
|
|
678
|
+
a(this, "notificationPort");
|
|
679
|
+
a(this, "interactionCallIds", /* @__PURE__ */ new Map());
|
|
680
680
|
/** Interactions whose turn was committed (turn-complete or a server error); a second close is ignored. */
|
|
681
|
-
|
|
681
|
+
a(this, "committedTurns", /* @__PURE__ */ new Set());
|
|
682
682
|
/** Interactions this tab sent. An `InteractionStarted` for one of them announces what is already here. */
|
|
683
|
-
|
|
683
|
+
a(this, "localInteractionIds", /* @__PURE__ */ new Set());
|
|
684
684
|
/**
|
|
685
685
|
* Turns open right now, local and remote. `turnOpen` in the store is "any of these": a remote turn finishing
|
|
686
686
|
* must not unlock the composer under a local turn still streaming, nor the other way round.
|
|
687
687
|
*/
|
|
688
|
-
|
|
689
|
-
|
|
688
|
+
a(this, "openTurns", /* @__PURE__ */ new Set());
|
|
689
|
+
/**
|
|
690
|
+
* Messages sent while a turn was open, by interaction id → the text the user typed, in send order (AIA Issue 1651).
|
|
691
|
+
* Mirrored to the store's `queuedMessages`. Leaves when the server announces the delivery, or when the turn ends
|
|
692
|
+
* without it (pause, error) and the text goes back to the composer.
|
|
693
|
+
*/
|
|
694
|
+
a(this, "queuedMessages", /* @__PURE__ */ new Map());
|
|
695
|
+
a(this, "options");
|
|
690
696
|
/** Announcements asked for in this tab, by `runId|settleKey` — a second request for the same settle is a no-op. */
|
|
691
|
-
|
|
697
|
+
a(this, "announceRequested", /* @__PURE__ */ new Set());
|
|
692
698
|
/** Announcements waiting for the chat to be idle (no open turn) and connected, in request order. */
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
699
|
+
a(this, "pendingAnnouncements", []);
|
|
700
|
+
a(this, "flushingAnnouncements", !1);
|
|
701
|
+
a(this, "rawJwt");
|
|
702
|
+
a(this, "sessionId");
|
|
703
|
+
a(this, "eventBusService");
|
|
704
|
+
a(this, "artifactService");
|
|
705
|
+
a(this, "wsService");
|
|
700
706
|
/** The one owner of dial / redial / idle close / connection status. See ConnectionSupervisor. */
|
|
701
|
-
|
|
702
|
-
|
|
707
|
+
a(this, "connection");
|
|
708
|
+
a(this, "suspendState", !1);
|
|
703
709
|
/**
|
|
704
710
|
* True once a WS has successfully opened at least once in this gateway's
|
|
705
711
|
* lifetime. Gates the "Reiniciando a conexão" toast: a drop of a working
|
|
706
712
|
* connection is worth telling the user about, a failed initial dial is not
|
|
707
713
|
* (the Connecting state already covers it).
|
|
708
714
|
*/
|
|
709
|
-
|
|
715
|
+
a(this, "everConnected", !1);
|
|
710
716
|
/** Publishes the live message to the store; see ThrottledEmitter for the cadence rules. */
|
|
711
|
-
|
|
717
|
+
a(this, "liveMessage", new Z({
|
|
712
718
|
windowMs: y.CURRENT_MSG_THROTTLE_MS,
|
|
713
|
-
publish: /* @__PURE__ */ h((
|
|
714
|
-
this.sessionState.setCurrentMessage(
|
|
719
|
+
publish: /* @__PURE__ */ h((e) => {
|
|
720
|
+
this.sessionState.setCurrentMessage(e), this.eventBusService.gatewayEmitMessage(e);
|
|
715
721
|
}, "publish"),
|
|
716
722
|
publishedVersion: /* @__PURE__ */ h(() => {
|
|
717
|
-
var
|
|
718
|
-
return ((
|
|
723
|
+
var e;
|
|
724
|
+
return ((e = this.sessionState.currentMessage) == null ? void 0 : e.version) ?? 0;
|
|
719
725
|
}, "publishedVersion")
|
|
720
726
|
}));
|
|
721
|
-
|
|
722
|
-
|
|
727
|
+
a(this, "detachedRunInteractions", /* @__PURE__ */ new Map());
|
|
728
|
+
a(this, "detachedRunInteractionServices", /* @__PURE__ */ new Map());
|
|
723
729
|
// ─── Artifacts ──────────────────────────────────────────────────────────
|
|
724
|
-
|
|
725
|
-
this.options = m ?? {}, this.user =
|
|
726
|
-
this.sessionState = u,
|
|
730
|
+
a(this, "runningRequests", /* @__PURE__ */ new Map());
|
|
731
|
+
this.options = m ?? {}, this.user = e, this.config = r, this.rawJwt = e.access_token, this.base_url = n, this.eventBusService = t, this.sessionId = g, this.artifactService = s, this.sessionState = o.getState(), this.notificationPort = c, this.storageService = f, o.subscribe((u, p) => {
|
|
732
|
+
this.sessionState = u, p.turnOpen && !u.turnOpen && this.flushAnnouncements();
|
|
727
733
|
}), this.wsService = l, this.connection = new V({
|
|
728
|
-
store:
|
|
734
|
+
store: o,
|
|
729
735
|
// A redial while a turn is open carries the turn's id: the server tells us if it cannot continue it.
|
|
730
|
-
dial: /* @__PURE__ */ h((u,
|
|
731
|
-
...
|
|
732
|
-
openInteractionId:
|
|
736
|
+
dial: /* @__PURE__ */ h((u, p) => this.wsService.connect(u, {
|
|
737
|
+
...p,
|
|
738
|
+
openInteractionId: p.resume && this.sessionState.turnOpen ? this.getCurrentInteractionId() ?? void 0 : void 0
|
|
733
739
|
}), "dial"),
|
|
734
740
|
hangUp: /* @__PURE__ */ h(() => this.wsService.closeStream(), "hangUp"),
|
|
735
741
|
isConnected: /* @__PURE__ */ h(() => this.wsService.isConnected(), "isConnected"),
|
|
736
|
-
onConnected: /* @__PURE__ */ h((u,
|
|
737
|
-
this.sessionId = u, this.sessionState.setConnectionOutage(null), this.eventBusService.gatewayEmitConnected(u,
|
|
742
|
+
onConnected: /* @__PURE__ */ h((u, p) => {
|
|
743
|
+
this.sessionId = u, this.sessionState.setConnectionOutage(null), this.eventBusService.gatewayEmitConnected(u, p), this.flushAnnouncements();
|
|
738
744
|
}, "onConnected"),
|
|
739
|
-
onRetryScheduled: /* @__PURE__ */ h(({ delayMs: u, attempt:
|
|
745
|
+
onRetryScheduled: /* @__PURE__ */ h(({ delayMs: u, attempt: p }) => {
|
|
740
746
|
var D;
|
|
741
|
-
const w = Date.now(),
|
|
742
|
-
this.sessionState.setConnectionOutage({ since:
|
|
747
|
+
const w = Date.now(), C = ((D = this.sessionState.connectionOutage) == null ? void 0 : D.since) ?? w;
|
|
748
|
+
this.sessionState.setConnectionOutage({ since: C, retryAt: w + u, attempt: p, halted: null }), w - C >= y.OUTAGE_CLOSES_TURN_AFTER_MS && this.closeOpenTurnWith(y.OUTAGE_TURN_MESSAGE);
|
|
743
749
|
}, "onRetryScheduled"),
|
|
744
|
-
onHalt: /* @__PURE__ */ h((u,
|
|
750
|
+
onHalt: /* @__PURE__ */ h((u, p) => {
|
|
745
751
|
const w = this.sessionState.connectionOutage;
|
|
746
|
-
this.sessionState.setConnectionOutage({ since: (w == null ? void 0 : w.since) ?? Date.now(), retryAt: null, attempt: (w == null ? void 0 : w.attempt) ?? 0, halted: u }), this.notifyHalt(u,
|
|
752
|
+
this.sessionState.setConnectionOutage({ since: (w == null ? void 0 : w.since) ?? Date.now(), retryAt: null, attempt: (w == null ? void 0 : w.attempt) ?? 0, halted: u }), this.notifyHalt(u, p), this.closeOpenTurnWith(y.HALT_TURN_MESSAGE[u]);
|
|
747
753
|
}, "onHalt")
|
|
748
754
|
}), this.wsService.onEvent = async (u) => {
|
|
749
755
|
await this.Message(u);
|
|
@@ -761,46 +767,46 @@ const y = class y {
|
|
|
761
767
|
// to the page, say) instead of a toast, without matching on the copy.
|
|
762
768
|
kind: "connection-restarting"
|
|
763
769
|
});
|
|
764
|
-
} catch (
|
|
765
|
-
console.error("[AgentGateway] notification port threw on connection-restarting",
|
|
770
|
+
} catch (p) {
|
|
771
|
+
console.error("[AgentGateway] notification port threw on connection-restarting", p);
|
|
766
772
|
}
|
|
767
773
|
this.eventBusService.gatewayEmitStreamError(u);
|
|
768
774
|
}, this.wsService.onOpen = () => {
|
|
769
775
|
this.everConnected = !0;
|
|
770
776
|
}, this.wsService.onBillingLimit = (u) => {
|
|
771
|
-
|
|
777
|
+
o.getState().setBillingLimit(u);
|
|
772
778
|
}, this.wsService.onFirstToken = (u) => {
|
|
773
779
|
this.localEmitFirstToken(u);
|
|
774
|
-
}, this.wsService.onClose = (u,
|
|
775
|
-
this.connection.transportClosed(u,
|
|
780
|
+
}, this.wsService.onClose = (u, p) => {
|
|
781
|
+
this.connection.transportClosed(u, p);
|
|
776
782
|
};
|
|
777
783
|
}
|
|
778
784
|
/**
|
|
779
785
|
* The turn the user is waiting on will not continue: close it from the client side with an error
|
|
780
786
|
* part, the same way a server error would. No-op when no turn is open.
|
|
781
787
|
*/
|
|
782
|
-
closeOpenTurnWith(
|
|
788
|
+
closeOpenTurnWith(e) {
|
|
783
789
|
if (!this.sessionState.turnOpen) return;
|
|
784
|
-
const
|
|
790
|
+
const t = this.getCurrentInteractionId(), s = this.openTurns.size > 0 ? [...this.openTurns] : t ? [t] : [];
|
|
785
791
|
for (const n of s)
|
|
786
|
-
console.warn(`[AgentGateway] closing interaction ${n} from the client side: ${
|
|
792
|
+
console.warn(`[AgentGateway] closing interaction ${n} from the client side: ${e}`), this.Message(q.createErrorEvent(e, n));
|
|
787
793
|
}
|
|
788
794
|
/** The supervisor gave up on its own (another tab holds the session, the session is gone, …): tell the user. */
|
|
789
|
-
notifyHalt(
|
|
795
|
+
notifyHalt(e, t) {
|
|
790
796
|
const s = {
|
|
791
797
|
"attached-elsewhere": { message: "Esta sessão já está aberta em outra janela", kind: "session-attached-elsewhere" },
|
|
792
798
|
"session-gone": { message: "A sessão não existe mais no servidor", kind: "session-gone" },
|
|
793
799
|
"closed-by-server": { message: "O servidor encerrou a conexão", kind: "connection-closed" }
|
|
794
|
-
}, { message: n, kind: r } = s[
|
|
800
|
+
}, { message: n, kind: r } = s[e];
|
|
795
801
|
try {
|
|
796
802
|
this.notificationPort.pushNotification({
|
|
797
803
|
message: n,
|
|
798
804
|
type: "warning",
|
|
799
805
|
kind: r,
|
|
800
|
-
details: `session ${
|
|
806
|
+
details: `session ${t.sessionId ?? "none"}${t.code !== void 0 ? `, close code ${t.code}` : ""}${t.actualSessionId ? `, server answered with ${t.actualSessionId}` : ""}`
|
|
801
807
|
});
|
|
802
|
-
} catch (
|
|
803
|
-
console.error(`[AgentGateway] notification port threw on ${r}`,
|
|
808
|
+
} catch (o) {
|
|
809
|
+
console.error(`[AgentGateway] notification port threw on ${r}`, o);
|
|
804
810
|
}
|
|
805
811
|
}
|
|
806
812
|
// ─── Agent context ──────────────────────────────────────────────────────
|
|
@@ -816,8 +822,8 @@ const y = class y {
|
|
|
816
822
|
getModel() {
|
|
817
823
|
return this.config.model;
|
|
818
824
|
}
|
|
819
|
-
setModel(
|
|
820
|
-
this.config = { ...this.config, model:
|
|
825
|
+
setModel(e) {
|
|
826
|
+
this.config = { ...this.config, model: e };
|
|
821
827
|
}
|
|
822
828
|
/**
|
|
823
829
|
* Live update for the ordinary, non-identity slice of the context — the
|
|
@@ -825,8 +831,8 @@ const y = class y {
|
|
|
825
831
|
* datasets mid-conversation is routine and changes nothing about who is
|
|
826
832
|
* answering.
|
|
827
833
|
*/
|
|
828
|
-
setCustomer(
|
|
829
|
-
this.config = { ...this.config, customer:
|
|
834
|
+
setCustomer(e) {
|
|
835
|
+
this.config = { ...this.config, customer: e };
|
|
830
836
|
}
|
|
831
837
|
/**
|
|
832
838
|
* Replace the AGENT mid-conversation. The escape hatch for an agent picker,
|
|
@@ -841,31 +847,31 @@ const y = class y {
|
|
|
841
847
|
* context omits it — the model is owned separately by {@link setModel} and
|
|
842
848
|
* must not be clobbered by an agent-only change.
|
|
843
849
|
*/
|
|
844
|
-
forceAgentContext(
|
|
850
|
+
forceAgentContext(e) {
|
|
845
851
|
this.config = {
|
|
846
|
-
...
|
|
847
|
-
model:
|
|
852
|
+
...e,
|
|
853
|
+
model: e.model ?? this.config.model
|
|
848
854
|
};
|
|
849
855
|
}
|
|
850
856
|
// ─── Session and interactions ───────────────────────────────────────────
|
|
851
857
|
getSessionId() {
|
|
852
858
|
return this.sessionId;
|
|
853
859
|
}
|
|
854
|
-
setSession(
|
|
855
|
-
(this.sessionId === void 0 || this.sessionId !=
|
|
860
|
+
setSession(e, t) {
|
|
861
|
+
(this.sessionId === void 0 || this.sessionId != e) && (this.sessionId = e, this.msg_order = this.sessionState.messages.length);
|
|
856
862
|
}
|
|
857
|
-
startInteraction(
|
|
858
|
-
if (
|
|
859
|
-
return this.currentIS.interaction.isSuspended = !1, this.currentIS.interaction.interactionQuestion += " + " +
|
|
863
|
+
startInteraction(e, t, s) {
|
|
864
|
+
if (t && this.currentIS)
|
|
865
|
+
return this.currentIS.interaction.isSuspended = !1, this.currentIS.interaction.interactionQuestion += " + " + e, this.currentIS.interaction;
|
|
860
866
|
this.msg_order += 1;
|
|
861
867
|
let n = this.getNewInteractionId();
|
|
862
|
-
return s && (n = s), this.currentIS = this.registerInteraction(n,
|
|
868
|
+
return s && (n = s), this.currentIS = this.registerInteraction(n, e), this.currentIS.interaction;
|
|
863
869
|
}
|
|
864
870
|
/** A new interaction and its merge service, in the maps. Who becomes current is the caller's decision. */
|
|
865
|
-
registerInteraction(
|
|
871
|
+
registerInteraction(e, t, s) {
|
|
866
872
|
const n = {
|
|
867
873
|
created: /* @__PURE__ */ new Date(),
|
|
868
|
-
interactionId:
|
|
874
|
+
interactionId: e,
|
|
869
875
|
artifactData: [],
|
|
870
876
|
partial: !0,
|
|
871
877
|
sessionId: this.sessionId,
|
|
@@ -873,17 +879,17 @@ const y = class y {
|
|
|
873
879
|
parts: [],
|
|
874
880
|
version: 0,
|
|
875
881
|
functionMap: /* @__PURE__ */ new Map(),
|
|
876
|
-
interactionQuestion:
|
|
882
|
+
interactionQuestion: t,
|
|
877
883
|
...s
|
|
878
884
|
};
|
|
879
|
-
this.interactionsMap.set(
|
|
885
|
+
this.interactionsMap.set(e, n);
|
|
880
886
|
const r = new j(n, this.eventBusService);
|
|
881
|
-
return this.interactionsServiceMap.set(
|
|
887
|
+
return this.interactionsServiceMap.set(e, r), r;
|
|
882
888
|
}
|
|
883
889
|
/** The current interaction's turn is still open — it owns the live message, and must stay current. */
|
|
884
890
|
currentTurnIsOpen() {
|
|
885
|
-
const
|
|
886
|
-
return !!
|
|
891
|
+
const e = this.getCurrentInteractionId();
|
|
892
|
+
return !!e && this.openTurns.has(e);
|
|
887
893
|
}
|
|
888
894
|
/**
|
|
889
895
|
* A turn this tab did not send (AIA Issue 1548): a WhatsApp message, a platform wake turn, another tab's turn, a
|
|
@@ -891,9 +897,9 @@ const y = class y {
|
|
|
891
897
|
* turn mid-stream keeps it, and with it the resume cursor, suspend and the client-side close; the remote turn
|
|
892
898
|
* streams into its own interaction and takes over the live message when that turn ends.
|
|
893
899
|
*/
|
|
894
|
-
openRemoteInteraction(
|
|
895
|
-
const r = this.registerInteraction(
|
|
896
|
-
return this.currentTurnIsOpen() || (this.currentIS = r), n && (this.openTurns.add(
|
|
900
|
+
openRemoteInteraction(e, t, s, n) {
|
|
901
|
+
const r = this.registerInteraction(e, t, { remote: !0, ...s && { origin: s } });
|
|
902
|
+
return this.currentTurnIsOpen() || (this.currentIS = r), n && (this.openTurns.add(e), this.sessionState.setTurnOpen(!0), this.eventBusService.gatewayEmitTurnOpen(e), this.currentIS === r && this.localEmitMessage(r.interaction)), r;
|
|
897
903
|
}
|
|
898
904
|
/**
|
|
899
905
|
* An `InteractionStarted` frame. Opens a turn this tab did not send, with the text that started it as its
|
|
@@ -901,16 +907,48 @@ const y = class y {
|
|
|
901
907
|
* Outside {@link AgentGatewayOptions.transcriptOfDetachedRun}, a detached run's turn is ignored too: it runs on
|
|
902
908
|
* the run's own session, and its box — not this transcript — shows it.
|
|
903
909
|
*/
|
|
904
|
-
interactionStarted(
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
910
|
+
interactionStarted(e) {
|
|
911
|
+
var r;
|
|
912
|
+
const t = e.interactionId;
|
|
913
|
+
if (!t || e.detachedRunId && !this.options.transcriptOfDetachedRun) return;
|
|
914
|
+
const s = ((r = e.queuedInteractionIds) != null && r.length ? e.queuedInteractionIds : [t]).filter((o) => this.queuedMessages.has(o));
|
|
915
|
+
if (s.length > 0) {
|
|
916
|
+
this.queuedMessageDelivered(e, s);
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
if (this.localInteractionIds.has(t) || this.committedTurns.has(t)) return;
|
|
920
|
+
const n = this.interactionsServiceMap.get(t);
|
|
921
|
+
if (n) {
|
|
922
|
+
const o = n.interaction;
|
|
923
|
+
o.interactionQuestion || (o.interactionQuestion = e.content ?? ""), o.origin ?? (o.origin = Se(e.origin));
|
|
911
924
|
return;
|
|
912
925
|
}
|
|
913
|
-
this.openRemoteInteraction(
|
|
926
|
+
this.openRemoteInteraction(t, e.content ?? "", Se(e.origin), !0);
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* The server delivered messages this tab queued (AIA Issue 1651). Injected into the running turn — the frame lists
|
|
930
|
+
* the ids it absorbed — the turn so far is committed as the previous message's answer and everything the server
|
|
931
|
+
* streams from here belongs to the new one, which shows the user's text as its question. Queued too late for the
|
|
932
|
+
* running turn, they start the next one — the previous turn is already committed, so it simply opens.
|
|
933
|
+
*/
|
|
934
|
+
queuedMessageDelivered(e, t) {
|
|
935
|
+
var l, f;
|
|
936
|
+
const s = e.interactionId, n = t.map((g) => this.queuedMessages.get(g)).join(`
|
|
937
|
+
`);
|
|
938
|
+
for (const g of t) this.queuedMessages.delete(g);
|
|
939
|
+
this.sessionState.removeQueuedMessages(t);
|
|
940
|
+
const r = (((l = e.queuedInteractionIds) == null ? void 0 : l.length) ?? 0) > 0, o = (f = this.currentIS) == null ? void 0 : f.interaction, c = this.registerInteraction(s, n);
|
|
941
|
+
if (this.localInteractionIds.add(s), r && o && this.openTurns.has(o.interactionId)) {
|
|
942
|
+
const g = o.interactionId;
|
|
943
|
+
this.openTurns.delete(g), this.committedTurns.add(g), this.liveMessage.cancelPending();
|
|
944
|
+
const m = { ...o, continuedBelow: !0 };
|
|
945
|
+
this.sessionState.setNewMessage(m), this.eventBusService.gatewayEmitTurnComplete(g, m), this.interactionCallIds.delete(g);
|
|
946
|
+
}
|
|
947
|
+
(r || !this.currentTurnIsOpen()) && (this.currentIS = c), this.openTurns.add(s), this.sessionState.setTurnOpen(!0), this.eventBusService.gatewayEmitTurnOpen(s), this.currentIS === c && (this.sessionState.setCurrentMessage(c.interaction), this.eventBusService.gatewayEmitMessage(c.interaction));
|
|
948
|
+
}
|
|
949
|
+
/** Hands every undelivered queued message back to the composer (the turn will not deliver them). */
|
|
950
|
+
restoreQueuedMessages() {
|
|
951
|
+
this.queuedMessages.size !== 0 && (this.queuedMessages.clear(), this.sessionState.restoreQueuedMessages());
|
|
914
952
|
}
|
|
915
953
|
getInteractions() {
|
|
916
954
|
return Array.from(this.interactionsMap.values());
|
|
@@ -919,58 +957,58 @@ const y = class y {
|
|
|
919
957
|
return this.currentIS ? this.currentIS.interaction.interactionId : null;
|
|
920
958
|
}
|
|
921
959
|
getCurrentInteraction() {
|
|
922
|
-
var
|
|
923
|
-
return ((
|
|
960
|
+
var e;
|
|
961
|
+
return ((e = this.currentIS) == null ? void 0 : e.interaction) ?? null;
|
|
924
962
|
}
|
|
925
|
-
updateMap(
|
|
926
|
-
let
|
|
927
|
-
return
|
|
963
|
+
updateMap(e) {
|
|
964
|
+
let t = this.interactionsServiceMap.get(e.interactionId);
|
|
965
|
+
return t || (t = this.openRemoteInteraction(e.interactionId, "", void 0, !1)), t.merge(e);
|
|
928
966
|
}
|
|
929
967
|
getNewInteractionId() {
|
|
930
|
-
const
|
|
931
|
-
return `${this.msg_order}_${
|
|
968
|
+
const t = xe(/* @__PURE__ */ new Date(), "MMM_dd_HH_mm_ss");
|
|
969
|
+
return `${this.msg_order}_${t}`;
|
|
932
970
|
}
|
|
933
971
|
// ─── Inbound: server events ─────────────────────────────────────────────
|
|
934
|
-
async Message(
|
|
972
|
+
async Message(e) {
|
|
935
973
|
try {
|
|
936
|
-
let
|
|
937
|
-
if (typeof
|
|
938
|
-
|
|
974
|
+
let t;
|
|
975
|
+
if (typeof e == "object" && Object.keys(e).includes("mimeType"))
|
|
976
|
+
t = e;
|
|
939
977
|
else {
|
|
940
|
-
console.error("Uknown message type",
|
|
978
|
+
console.error("Uknown message type", e);
|
|
941
979
|
return;
|
|
942
980
|
}
|
|
943
|
-
if (
|
|
944
|
-
this.handleDetachedRunEvent(
|
|
981
|
+
if (t.detachedRunId && !this.options.transcriptOfDetachedRun) {
|
|
982
|
+
this.handleDetachedRunEvent(t);
|
|
945
983
|
return;
|
|
946
984
|
}
|
|
947
|
-
if (
|
|
948
|
-
for (const
|
|
949
|
-
const c =
|
|
985
|
+
if (t.serverError && console.error("Stream error: ", t.serverError), t.endMessageData && this.eventBusService.gatewayEmitEndMessageData(t.endMessageData), t.llmArtifacts && t.llmArtifacts.length > 0)
|
|
986
|
+
for (const o of t.llmArtifacts) {
|
|
987
|
+
const c = o.toArtifact();
|
|
950
988
|
this.artifactService.addToCache(c), this.eventBusService.artifactEmitGenerated(c);
|
|
951
989
|
}
|
|
952
|
-
for (const
|
|
953
|
-
|
|
954
|
-
const s = (
|
|
955
|
-
if (s && !
|
|
956
|
-
const
|
|
957
|
-
|
|
990
|
+
for (const o of t.parts ?? [])
|
|
991
|
+
o.toolDetails && this.localEmitToolEvent(o.toolDetails);
|
|
992
|
+
const s = (t.parts ?? []).some((o) => o.eventType === I.ServerError);
|
|
993
|
+
if (s && !t.interactionId) {
|
|
994
|
+
const o = this.getCurrentInteractionId();
|
|
995
|
+
o && (t.interactionId = o);
|
|
958
996
|
}
|
|
959
|
-
const n = this.updateMap(
|
|
997
|
+
const n = this.updateMap(t);
|
|
960
998
|
if (!n) {
|
|
961
999
|
console.error("No updated interaction");
|
|
962
1000
|
return;
|
|
963
1001
|
}
|
|
964
|
-
(n.interactionId === this.getCurrentInteractionId() || !this.currentTurnIsOpen()) && this.localEmitMessage(n), (
|
|
965
|
-
const r =
|
|
966
|
-
r && r.forEach((
|
|
967
|
-
const c = n.artifactData.filter((f) => f.id ==
|
|
1002
|
+
(n.interactionId === this.getCurrentInteractionId() || !this.currentTurnIsOpen()) && this.localEmitMessage(n), (t.turn_complete || t.asyncFinalResponse || s) && (this.committedTurns.has(t.interactionId) || (this.committedTurns.add(t.interactionId), this.turnComplete(t.interactionId, n, t.author, t.detachedRunId), s && this.openTurns.size === 0 && this.restoreQueuedMessages()));
|
|
1003
|
+
const r = t.artifactsDelta;
|
|
1004
|
+
r && r.forEach((o) => {
|
|
1005
|
+
const c = n.artifactData.filter((f) => f.id == o);
|
|
968
1006
|
let l = null;
|
|
969
|
-
c && c.length > 0 && (l = c[0], l.loadingPromise = this.asyncLoadArtifact(
|
|
1007
|
+
c && c.length > 0 && (l = c[0], l.loadingPromise = this.asyncLoadArtifact(o).then((f) => (f === null ? console.error("Error trying to load artifact id:", l == null ? void 0 : l.id, "Artifact is null") : this.eventBusService.artifactEmitGenerated(f), f)).catch((f) => (console.error("Error trying to load artifact id:", l == null ? void 0 : l.id, f.toString()), null)));
|
|
970
1008
|
});
|
|
971
|
-
} catch (
|
|
1009
|
+
} catch (t) {
|
|
972
1010
|
if (this.getCurrentInteractionId()) {
|
|
973
|
-
const s =
|
|
1011
|
+
const s = q.createErrorEvent("OnMessage error: " + t.toString(), this.getCurrentInteractionId() ?? "Empty Current"), n = this.updateMap(s);
|
|
974
1012
|
if (console.error("Error event: ", JSON.stringify(s, void 0, 4)), !n) {
|
|
975
1013
|
console.error("Error event, could not update interaction: ", JSON.stringify(s, void 0, 4));
|
|
976
1014
|
return;
|
|
@@ -979,49 +1017,49 @@ const y = class y {
|
|
|
979
1017
|
}
|
|
980
1018
|
}
|
|
981
1019
|
}
|
|
982
|
-
getOrCreateDetachedRunInteraction(
|
|
983
|
-
let n = this.detachedRunInteractions.get(
|
|
1020
|
+
getOrCreateDetachedRunInteraction(e, t, s) {
|
|
1021
|
+
let n = this.detachedRunInteractions.get(e), r = this.detachedRunInteractionServices.get(e);
|
|
984
1022
|
return (!n || !r) && (n = {
|
|
985
1023
|
created: /* @__PURE__ */ new Date(),
|
|
986
|
-
interactionId:
|
|
1024
|
+
interactionId: t,
|
|
987
1025
|
artifactData: [],
|
|
988
1026
|
partial: !0,
|
|
989
1027
|
turn_complete: !1,
|
|
990
1028
|
parts: [],
|
|
991
1029
|
version: 0,
|
|
992
1030
|
functionMap: /* @__PURE__ */ new Map(),
|
|
993
|
-
interactionQuestion: s ??
|
|
994
|
-
}, r = new j(n, this.eventBusService), this.detachedRunInteractions.set(
|
|
1031
|
+
interactionQuestion: s ?? e
|
|
1032
|
+
}, r = new j(n, this.eventBusService), this.detachedRunInteractions.set(e, n), this.detachedRunInteractionServices.set(e, r)), { interaction: n, service: r };
|
|
995
1033
|
}
|
|
996
|
-
handleDetachedRunEvent(
|
|
997
|
-
const
|
|
998
|
-
for (const r of
|
|
999
|
-
r.toolDetails && this.localEmitToolEvent({ ...r.toolDetails, detachedRunId:
|
|
1000
|
-
const n = s.merge(
|
|
1001
|
-
n && (this.sessionState.setDetachedRunMessage(
|
|
1034
|
+
handleDetachedRunEvent(e) {
|
|
1035
|
+
const t = e.detachedRunId, { service: s } = this.getOrCreateDetachedRunInteraction(t, e.interactionId, e.detachedRunName);
|
|
1036
|
+
for (const r of e.parts ?? [])
|
|
1037
|
+
r.toolDetails && this.localEmitToolEvent({ ...r.toolDetails, detachedRunId: t });
|
|
1038
|
+
const n = s.merge(e);
|
|
1039
|
+
n && (this.sessionState.setDetachedRunMessage(t, n, e.detachedRunName), (e.turn_complete ?? !1) && this.sessionState.completeDetachedRun(t));
|
|
1002
1040
|
}
|
|
1003
|
-
localEmitToolEvent(
|
|
1004
|
-
this.sessionState.setLastToolEvent(
|
|
1041
|
+
localEmitToolEvent(e) {
|
|
1042
|
+
this.sessionState.setLastToolEvent(e), this.eventBusService.gatewayEmitToolEvent(e.eventName, e.eventData, e.sessionId);
|
|
1005
1043
|
}
|
|
1006
|
-
registerInteractionCallId(
|
|
1007
|
-
|
|
1044
|
+
registerInteractionCallId(e, t) {
|
|
1045
|
+
t != null && t.callId && this.interactionCallIds.set(e, t.callId);
|
|
1008
1046
|
}
|
|
1009
|
-
localEmitFirstToken(
|
|
1047
|
+
localEmitFirstToken(e) {
|
|
1010
1048
|
this.eventBusService.gatewayEmitFirstToken({
|
|
1011
|
-
interactionId:
|
|
1012
|
-
callId: this.interactionCallIds.get(
|
|
1049
|
+
interactionId: e,
|
|
1050
|
+
callId: this.interactionCallIds.get(e)
|
|
1013
1051
|
});
|
|
1014
1052
|
}
|
|
1015
|
-
localEmitMessage(
|
|
1016
|
-
this.liveMessage.emit(
|
|
1053
|
+
localEmitMessage(e) {
|
|
1054
|
+
this.liveMessage.emit(e);
|
|
1017
1055
|
}
|
|
1018
|
-
localOpen(
|
|
1019
|
-
|
|
1056
|
+
localOpen(e, t) {
|
|
1057
|
+
e && this.openTurns.add(e), this.sessionState.setTurnOpen(!0), this.eventBusService.gatewayEmitTurnOpen(e ?? "");
|
|
1020
1058
|
}
|
|
1021
|
-
async turnComplete(
|
|
1022
|
-
this.openTurns.delete(
|
|
1023
|
-
const r =
|
|
1024
|
-
r && this.liveMessage.cancelPending(), this.sessionState.setNewMessage(
|
|
1059
|
+
async turnComplete(e, t, s, n) {
|
|
1060
|
+
this.openTurns.delete(e);
|
|
1061
|
+
const r = e === this.getCurrentInteractionId(), o = r ? null : this.sessionState.currentMessage;
|
|
1062
|
+
r && this.liveMessage.cancelPending(), this.sessionState.setNewMessage(t), o && o.interactionId !== e ? this.sessionState.setCurrentMessage(o) : r && this.handOverLiveMessage(), this.eventBusService.gatewayEmitTurnComplete(e, t), this.interactionCallIds.delete(e), this.sessionState.setLastToolEvent(null), this.localEmitToolEvent({
|
|
1025
1063
|
eventName: "todolistUpdated",
|
|
1026
1064
|
eventData: "",
|
|
1027
1065
|
detachedRunId: n
|
|
@@ -1032,24 +1070,24 @@ const y = class y {
|
|
|
1032
1070
|
* current and its progress so far goes live at once.
|
|
1033
1071
|
*/
|
|
1034
1072
|
handOverLiveMessage() {
|
|
1035
|
-
for (const
|
|
1036
|
-
const
|
|
1037
|
-
if (
|
|
1038
|
-
this.currentIS =
|
|
1073
|
+
for (const e of this.openTurns) {
|
|
1074
|
+
const t = this.interactionsServiceMap.get(e);
|
|
1075
|
+
if (t) {
|
|
1076
|
+
this.currentIS = t, this.sessionState.setCurrentMessage(t.interaction), this.eventBusService.gatewayEmitMessage(t.interaction);
|
|
1039
1077
|
return;
|
|
1040
1078
|
}
|
|
1041
1079
|
}
|
|
1042
1080
|
}
|
|
1043
|
-
async asyncLoadArtifact(
|
|
1044
|
-
let
|
|
1045
|
-
const s = this.runningRequests.get(
|
|
1046
|
-
s ? (console.warn("GOT A running promise",
|
|
1081
|
+
async asyncLoadArtifact(e) {
|
|
1082
|
+
let t = null;
|
|
1083
|
+
const s = this.runningRequests.get(e);
|
|
1084
|
+
s ? (console.warn("GOT A running promise", e), t = s) : (t = this.artifactService.getArtifact(e), this.runningRequests.set(e, t));
|
|
1047
1085
|
try {
|
|
1048
|
-
return await
|
|
1086
|
+
return await t;
|
|
1049
1087
|
} catch (n) {
|
|
1050
1088
|
return console.error("Error awating on HTML promise", n.toString()), null;
|
|
1051
1089
|
} finally {
|
|
1052
|
-
this.runningRequests.delete(
|
|
1090
|
+
this.runningRequests.delete(e);
|
|
1053
1091
|
}
|
|
1054
1092
|
}
|
|
1055
1093
|
// ─── Connection ─────────────────────────────────────────────────────────
|
|
@@ -1061,12 +1099,12 @@ const y = class y {
|
|
|
1061
1099
|
* backoff, the idle close and the close-code policy — and for the rule that a requested
|
|
1062
1100
|
* session is never swapped for another.
|
|
1063
1101
|
*/
|
|
1064
|
-
async openConnection(
|
|
1065
|
-
return this.connection.open(
|
|
1102
|
+
async openConnection(e, t) {
|
|
1103
|
+
return this.connection.open(e, t);
|
|
1066
1104
|
}
|
|
1067
|
-
async closeConnection(
|
|
1105
|
+
async closeConnection(e = !0) {
|
|
1068
1106
|
try {
|
|
1069
|
-
return this.stopStream(
|
|
1107
|
+
return this.stopStream(e), {
|
|
1070
1108
|
success: !0,
|
|
1071
1109
|
interaction: this.getCurrentInteraction()
|
|
1072
1110
|
};
|
|
@@ -1078,8 +1116,8 @@ const y = class y {
|
|
|
1078
1116
|
}
|
|
1079
1117
|
}
|
|
1080
1118
|
/** Hang up and stop supervising the connection. `closeTurn` also closes an open turn in the store. */
|
|
1081
|
-
stopStream(
|
|
1082
|
-
|
|
1119
|
+
stopStream(e = !0) {
|
|
1120
|
+
e && (this.openTurns.clear(), this.sessionState.setTurnOpen(!1), this.restoreQueuedMessages()), this.sessionState.setConnectionOutage(null), this.connection.close();
|
|
1083
1121
|
}
|
|
1084
1122
|
/**
|
|
1085
1123
|
* Make sure the socket is OPEN before a send, redialling the SAME session when it is not.
|
|
@@ -1092,96 +1130,133 @@ const y = class y {
|
|
|
1092
1130
|
* the supervisor dials now rather than at its next scheduled retry, replay cursor kept.
|
|
1093
1131
|
*/
|
|
1094
1132
|
async ensureConnected() {
|
|
1095
|
-
const
|
|
1133
|
+
const e = this.sessionId;
|
|
1096
1134
|
if (this.wsService.isConnected()) {
|
|
1097
|
-
console.log(`[AgentGateway] send guard: socket is open (session ${
|
|
1135
|
+
console.log(`[AgentGateway] send guard: socket is open (session ${e ?? "none"}, status ${this.sessionState.connectionStatus}) — sending straight away.`);
|
|
1098
1136
|
return;
|
|
1099
1137
|
}
|
|
1100
|
-
const
|
|
1138
|
+
const t = Date.now();
|
|
1101
1139
|
try {
|
|
1102
|
-
const s = await this.connection.ensure(
|
|
1103
|
-
console.log(`[AgentGateway] send guard: reconnected to ${s} in ${Date.now() -
|
|
1140
|
+
const s = await this.connection.ensure(e);
|
|
1141
|
+
console.log(`[AgentGateway] send guard: reconnected to ${s} in ${Date.now() - t}ms — sending now.`);
|
|
1104
1142
|
} catch (s) {
|
|
1105
|
-
throw console.error(`[AgentGateway] send guard: redial FAILED after ${Date.now() -
|
|
1143
|
+
throw console.error(`[AgentGateway] send guard: redial FAILED after ${Date.now() - t}ms — the message was not sent.`, s), new Error(y.NO_CONNECTION_MESSAGE, { cause: s });
|
|
1106
1144
|
}
|
|
1107
1145
|
}
|
|
1108
1146
|
// ─── Outbound: the user's turns ─────────────────────────────────────────
|
|
1109
|
-
async sendMessage(
|
|
1110
|
-
let s = this.getInteractions().length, n =
|
|
1111
|
-
this.sendStatusMessage(
|
|
1147
|
+
async sendMessage(e, t) {
|
|
1148
|
+
let s = this.getInteractions().length, n = U.createWaiting(!0, !0, "Overall", /* @__PURE__ */ new Date());
|
|
1149
|
+
this.sendStatusMessage(e.data, [n], s.toString() + "1");
|
|
1112
1150
|
try {
|
|
1113
|
-
const { promptAsString: r, json:
|
|
1114
|
-
this.sessionState.onRenderPrompt && (
|
|
1115
|
-
const c = await this.sendMessageInternal(
|
|
1151
|
+
const { promptAsString: r, json: o } = this.sessionState.onRenderPrompt ? this.sessionState.onRenderPrompt(e.data) : { promptAsString: e.data, json: void 0 };
|
|
1152
|
+
this.sessionState.onRenderPrompt && (e.data = o, e.friendlyMessage = r);
|
|
1153
|
+
const c = await this.sendMessageInternal(e, t), l = Be.createPrompt(r ?? "", (o == null ? void 0 : o.toString()) ?? {});
|
|
1116
1154
|
this.storageService.storePrompt(l);
|
|
1117
|
-
const f =
|
|
1118
|
-
return this.sendStatusMessage(
|
|
1155
|
+
const f = U.fromText("Planejando próximos passos");
|
|
1156
|
+
return this.sendStatusMessage(e.data, [n, f], s.toString() + "1"), c != null && c.success ? this.eventBusService.ChatEmitMessageSent(e.data, c.interaction) : this.eventBusService.ChatEmitMessageError((c == null ? void 0 : c.error) ?? ""), c;
|
|
1119
1157
|
} catch (r) {
|
|
1120
|
-
const
|
|
1121
|
-
return this.liveMessage.cancelPending(), this.sessionState.setCurrentMessage(null), this.sessionState.setTurnOpen(this.openTurns.size > 0), this.eventBusService.ChatEmitMessageError(
|
|
1158
|
+
const o = r instanceof Error ? r.message : String(r ?? "");
|
|
1159
|
+
return this.liveMessage.cancelPending(), this.sessionState.setCurrentMessage(null), this.sessionState.setTurnOpen(this.openTurns.size > 0), this.eventBusService.ChatEmitMessageError(o), {
|
|
1122
1160
|
success: !1,
|
|
1123
|
-
error:
|
|
1161
|
+
error: o,
|
|
1124
1162
|
interaction: {
|
|
1125
1163
|
artifactData: [],
|
|
1126
1164
|
created: /* @__PURE__ */ new Date(),
|
|
1127
1165
|
interactionId: "",
|
|
1128
1166
|
partial: !1,
|
|
1129
|
-
parts: [
|
|
1167
|
+
parts: [U.fromError(o)],
|
|
1130
1168
|
version: 0
|
|
1131
1169
|
}
|
|
1132
1170
|
};
|
|
1133
1171
|
}
|
|
1134
1172
|
}
|
|
1135
1173
|
// Send a message to the server over the socket
|
|
1136
|
-
async sendMessageInternal(
|
|
1137
|
-
var r,
|
|
1174
|
+
async sendMessageInternal(e, t) {
|
|
1175
|
+
var r, o;
|
|
1138
1176
|
const s = this.suspendState;
|
|
1139
1177
|
this.suspendState = !1;
|
|
1140
|
-
const n = this.startInteraction(
|
|
1141
|
-
if (this.localInteractionIds.add(n.interactionId), this.registerInteractionCallId(n.interactionId,
|
|
1178
|
+
const n = this.startInteraction(e.friendlyMessage ?? e.data, s);
|
|
1179
|
+
if (this.localInteractionIds.add(n.interactionId), this.registerInteractionCallId(n.interactionId, t), (r = e.userUi) != null && r.name && n.parts.push(U.fromUserUi(e.userUi.name, e.userUi.args)), !this.wsService)
|
|
1142
1180
|
throw "no wsService created";
|
|
1143
|
-
if (!((
|
|
1181
|
+
if (!((o = this.config.agentConfig) != null && o.id))
|
|
1144
1182
|
throw "Agent not selected";
|
|
1145
|
-
return this.sessionState.setLastActivity(), await this.ensureConnected(), this.wsService.sendMessage({
|
|
1183
|
+
return this.sessionState.setLastActivity(), await this.ensureConnected(), this.wsService.sendMessage(this.messageFrame(F.SendMessage, e, n.interactionId)), this.localOpen(n.interactionId, "system"), {
|
|
1184
|
+
interaction: n,
|
|
1185
|
+
success: !0
|
|
1186
|
+
};
|
|
1187
|
+
}
|
|
1188
|
+
/**
|
|
1189
|
+
* Send a message while a turn is open (AIA Issue 1651): the `QueueMessage` action. The server queues it on the
|
|
1190
|
+
* running turn, which reads it after its next tool round — or right away, when the model would otherwise end the
|
|
1191
|
+
* turn — and announces the delivery with an `InteractionStarted`; {@link queuedMessageDelivered} then moves the
|
|
1192
|
+
* live message onto it. Until then it waits in the store's `queuedMessages`. With no turn open this is a plain
|
|
1193
|
+
* {@link sendMessage}. Text only: images ride a turn of their own.
|
|
1194
|
+
*/
|
|
1195
|
+
async queueMessage(e) {
|
|
1196
|
+
var r;
|
|
1197
|
+
if (this.openTurns.size === 0) return this.sendMessage(e);
|
|
1198
|
+
const t = e.friendlyMessage ?? e.data;
|
|
1199
|
+
this.msg_order += 1;
|
|
1200
|
+
const s = this.getNewInteractionId(), n = {
|
|
1201
|
+
interactionId: s,
|
|
1202
|
+
created: /* @__PURE__ */ new Date(),
|
|
1203
|
+
partial: !0,
|
|
1204
|
+
turn_complete: !1,
|
|
1205
|
+
version: 0,
|
|
1206
|
+
parts: [],
|
|
1207
|
+
interactionQuestion: t,
|
|
1208
|
+
artifactData: []
|
|
1209
|
+
};
|
|
1210
|
+
this.queuedMessages.set(s, t), this.sessionState.addQueuedMessage({ interactionId: s, text: t });
|
|
1211
|
+
try {
|
|
1212
|
+
if (!((r = this.config.agentConfig) != null && r.id)) throw new Error("Agent not selected");
|
|
1213
|
+
return this.sessionState.setLastActivity(), await this.ensureConnected(), this.wsService.sendMessage(this.messageFrame(F.QueueMessage, { ...e, images: void 0, userUi: void 0 }, s)), this.eventBusService.ChatEmitMessageSent(e.data, n), { success: !0, interaction: n };
|
|
1214
|
+
} catch (o) {
|
|
1215
|
+
const c = o instanceof Error ? o.message : String(o ?? "");
|
|
1216
|
+
return this.queuedMessages.delete(s), this.sessionState.removeQueuedMessages([s]), this.eventBusService.ChatEmitMessageError(c), { success: !1, error: c, interaction: n };
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
/** The socket frame for a user message — {@link sendMessageInternal}'s and {@link queueMessage}'s. */
|
|
1220
|
+
messageFrame(e, t, s) {
|
|
1221
|
+
var n, r, o, c, l, f, g, m;
|
|
1222
|
+
return {
|
|
1146
1223
|
Content: t.data,
|
|
1147
1224
|
SessionId: this.sessionId,
|
|
1148
|
-
Action:
|
|
1225
|
+
Action: e,
|
|
1149
1226
|
ModelId: this.config.model,
|
|
1150
|
-
InteractionId:
|
|
1151
|
-
AgentId: (
|
|
1227
|
+
InteractionId: s,
|
|
1228
|
+
AgentId: ((n = this.config.agentConfig) == null ? void 0 : n.id) ?? "",
|
|
1152
1229
|
// Optional explicit C# class name on the server (e.g. "LlmAgentSessionReplay").
|
|
1153
1230
|
// When set, AgentBootStrapService.GetAgent dispatches to that class directly
|
|
1154
1231
|
// instead of looking up an Agent metadata row by AgentId. Plumbed through
|
|
1155
1232
|
// `agentContext.agentConfig.agentImplementation` so a host can run a turn
|
|
1156
1233
|
// against any registered LlmAgent variant without seeding a Mongo record.
|
|
1157
|
-
AgentImplementation: (
|
|
1234
|
+
AgentImplementation: (r = this.config.agentConfig) == null ? void 0 : r.agentImplementation,
|
|
1158
1235
|
Parameters: {
|
|
1159
|
-
|
|
1160
|
-
|
|
1236
|
+
...((c = (o = this.config).parameters) == null ? void 0 : c.call(o)) ?? {},
|
|
1237
|
+
CustomerName: ((l = this.config.customer) == null ? void 0 : l.name) ?? "",
|
|
1238
|
+
DataSet: ((f = this.config.customer) == null ? void 0 : f.dataSetId) ?? ""
|
|
1161
1239
|
},
|
|
1162
1240
|
// Forward image attachments as a structured payload (PascalCase
|
|
1163
1241
|
// keys to match the C# `Message.Images` / `MessageImage` model).
|
|
1164
|
-
Images: (
|
|
1242
|
+
Images: (g = t.images) != null && g.length ? t.images.map((u) => ({ MimeType: u.mimeType, Data: u.data })) : void 0,
|
|
1165
1243
|
// Client-only UI representation for this turn (PascalCase to match the C# `Message.UserUi`
|
|
1166
1244
|
// model). The server persists it as a UserUiContent sibling and strips it from the model
|
|
1167
1245
|
// request; Content remains the only model-facing text.
|
|
1168
|
-
UserUi: (
|
|
1169
|
-
}), this.localOpen(n.interactionId, "system"), {
|
|
1170
|
-
interaction: n,
|
|
1171
|
-
success: !0
|
|
1246
|
+
UserUi: (m = t.userUi) != null && m.name ? { Name: t.userUi.name, Args: t.userUi.args } : void 0
|
|
1172
1247
|
};
|
|
1173
1248
|
}
|
|
1174
|
-
sendStatusMessage(
|
|
1175
|
-
var r,
|
|
1249
|
+
sendStatusMessage(e, t, s) {
|
|
1250
|
+
var r, o;
|
|
1176
1251
|
let n;
|
|
1177
|
-
((
|
|
1252
|
+
((o = (r = this.currentIS) == null ? void 0 : r.interaction) == null ? void 0 : o.turn_complete) === !1 && !this.currentIS.interaction.remote ? (n = We.cloneDeep(this.currentIS.interaction), n.parts.push(...t)) : n = {
|
|
1178
1253
|
interactionId: "tmp" + s,
|
|
1179
1254
|
created: /* @__PURE__ */ new Date(),
|
|
1180
1255
|
partial: !0,
|
|
1181
1256
|
turn_complete: !1,
|
|
1182
1257
|
version: 0,
|
|
1183
|
-
parts:
|
|
1184
|
-
interactionQuestion:
|
|
1258
|
+
parts: t,
|
|
1259
|
+
interactionQuestion: e,
|
|
1185
1260
|
artifactData: []
|
|
1186
1261
|
}, this.localEmitMessage(n);
|
|
1187
1262
|
}
|
|
@@ -1194,10 +1269,10 @@ const y = class y {
|
|
|
1194
1269
|
* gateway does), and a hard cast turned "this transport doesn't deliver answers" into a TypeError
|
|
1195
1270
|
* thrown from a click handler — with the answer lost either way.
|
|
1196
1271
|
*/
|
|
1197
|
-
answerHumanTool(
|
|
1272
|
+
answerHumanTool(e, t) {
|
|
1198
1273
|
var n;
|
|
1199
1274
|
const s = (n = this.wsService.answerHumanTool) == null ? void 0 : n.bind(this.wsService);
|
|
1200
|
-
return s ? s(
|
|
1275
|
+
return s ? s(e, t) : (console.warn("[AgentGateway] transport cannot deliver parked-tool answers", e), "queued");
|
|
1201
1276
|
}
|
|
1202
1277
|
// ─── Detached-run announcements ─────────────────────────────────────────
|
|
1203
1278
|
/**
|
|
@@ -1210,18 +1285,18 @@ const y = class y {
|
|
|
1210
1285
|
* the socket up). `settleKey` — the run's `settledAt` — scopes the dedupe: a repeated request for the same settle
|
|
1211
1286
|
* is a no-op, a resumed run that settles anew is announced again.</p>
|
|
1212
1287
|
*/
|
|
1213
|
-
async announceDetachedRun(
|
|
1214
|
-
const s = `${
|
|
1215
|
-
return this.announceRequested.has(s) ? "duplicate" : (this.announceRequested.add(s), this.pendingAnnouncements.push(
|
|
1288
|
+
async announceDetachedRun(e, t) {
|
|
1289
|
+
const s = `${e}|${t ?? ""}`;
|
|
1290
|
+
return this.announceRequested.has(s) ? "duplicate" : (this.announceRequested.add(s), this.pendingAnnouncements.push(e), await this.flushAnnouncements(), this.pendingAnnouncements.includes(e) ? "queued" : "sent");
|
|
1216
1291
|
}
|
|
1217
1292
|
/** Send the queued announcements, oldest first, while the chat is idle and the socket is open. */
|
|
1218
1293
|
async flushAnnouncements() {
|
|
1219
|
-
var
|
|
1294
|
+
var e, t;
|
|
1220
1295
|
if (!this.flushingAnnouncements) {
|
|
1221
1296
|
this.flushingAnnouncements = !0;
|
|
1222
1297
|
try {
|
|
1223
1298
|
for (; this.pendingAnnouncements.length > 0 && !this.sessionState.turnOpen; ) {
|
|
1224
|
-
const s = (
|
|
1299
|
+
const s = (e = this.wsService.sendBaseMessage) == null ? void 0 : e.bind(this.wsService);
|
|
1225
1300
|
if (!s) {
|
|
1226
1301
|
console.warn("[AgentGateway] transport cannot send an AnnounceDetachedRun; the request stays queued");
|
|
1227
1302
|
return;
|
|
@@ -1230,8 +1305,8 @@ const y = class y {
|
|
|
1230
1305
|
const n = this.pendingAnnouncements[0];
|
|
1231
1306
|
try {
|
|
1232
1307
|
s({
|
|
1233
|
-
Action:
|
|
1234
|
-
AgentId: ((
|
|
1308
|
+
Action: F.AnnounceDetachedRun,
|
|
1309
|
+
AgentId: ((t = this.config.agentConfig) == null ? void 0 : t.id) ?? "",
|
|
1235
1310
|
InteractionId: `announce_${n}_${Date.now()}`,
|
|
1236
1311
|
SessionId: this.sessionId,
|
|
1237
1312
|
DetachedRunId: n
|
|
@@ -1249,15 +1324,15 @@ const y = class y {
|
|
|
1249
1324
|
}
|
|
1250
1325
|
// ─── Suspend ────────────────────────────────────────────────────────────
|
|
1251
1326
|
async suspend() {
|
|
1252
|
-
const
|
|
1253
|
-
return new Promise(async (
|
|
1327
|
+
const e = this.wsService;
|
|
1328
|
+
return new Promise(async (t, s) => {
|
|
1254
1329
|
let n = !1;
|
|
1255
|
-
|
|
1330
|
+
e.onSuspended = () => {
|
|
1256
1331
|
n = !0;
|
|
1257
|
-
},
|
|
1258
|
-
const r = 100,
|
|
1332
|
+
}, e.suspendStream();
|
|
1333
|
+
const r = 100, o = 5e3;
|
|
1259
1334
|
let c = 0;
|
|
1260
|
-
for (; !n && c <
|
|
1335
|
+
for (; !n && c < o; )
|
|
1261
1336
|
await this.sleep(r), c += r;
|
|
1262
1337
|
if (!n) {
|
|
1263
1338
|
s("Timeout awaiting for suspension");
|
|
@@ -1268,104 +1343,116 @@ const y = class y {
|
|
|
1268
1343
|
return;
|
|
1269
1344
|
}
|
|
1270
1345
|
const l = this.currentIS.interaction;
|
|
1271
|
-
l.isSuspended = !0, this.openTurns.delete(l.interactionId), this.sessionState.setCurrentMessage(l), this.sessionState.setTurnOpen(this.openTurns.size > 0), this.suspendState = !0,
|
|
1346
|
+
l.isSuspended = !0, this.openTurns.delete(l.interactionId), this.sessionState.setCurrentMessage(l), this.sessionState.setTurnOpen(this.openTurns.size > 0), this.suspendState = !0, this.restoreQueuedMessages(), t(!0);
|
|
1272
1347
|
});
|
|
1273
1348
|
}
|
|
1274
|
-
|
|
1275
|
-
|
|
1349
|
+
/**
|
|
1350
|
+
* Stop the running turn for good: the server cancels the run (what was queued on it comes back to the composer, as
|
|
1351
|
+
* on a pause) and the turn closes with what it had streamed, instead of waiting suspended for a "Continue". The
|
|
1352
|
+
* next message starts a turn of its own. Rejects, like {@link suspend}, when the server did not confirm.
|
|
1353
|
+
*/
|
|
1354
|
+
async stop() {
|
|
1355
|
+
var s;
|
|
1356
|
+
const e = await this.suspend();
|
|
1357
|
+
this.suspendState = !1;
|
|
1358
|
+
const t = (s = this.currentIS) == null ? void 0 : s.interaction;
|
|
1359
|
+
return t && (t.isSuspended = !1), t && !this.committedTurns.has(t.interactionId) && (this.committedTurns.add(t.interactionId), this.liveMessage.cancelPending(), this.sessionState.setNewMessage(t), this.eventBusService.gatewayEmitTurnComplete(t.interactionId, t)), this.sessionState.setTurnOpen(this.openTurns.size > 0), e;
|
|
1360
|
+
}
|
|
1361
|
+
async sleep(e) {
|
|
1362
|
+
return new Promise((t) => setTimeout(t, e));
|
|
1276
1363
|
}
|
|
1277
1364
|
};
|
|
1278
1365
|
h(y, "AgentGatewayWSAsync"), // How often the streaming message re-renders. 150 ms made a reasoning highlight, or a burst of them, visibly lag the
|
|
1279
1366
|
// server (Ciro, 2026-10-07). The server already merges deltas over a 50 ms window (the SDK's DeltaCoalescer), so
|
|
1280
1367
|
// frames arrive at ~20/s per kind and 20 ms here costs little: it mostly stops adding a second delay on top.
|
|
1281
|
-
|
|
1368
|
+
a(y, "CURRENT_MSG_THROTTLE_MS", 20), /**
|
|
1282
1369
|
* How long an open turn survives a connection outage. While the supervisor is redialling the
|
|
1283
1370
|
* turn stays open — a short blip resumes it from the replay cursor, and a server that comes back
|
|
1284
1371
|
* (or another instance) closes it with an error if its run is gone. Past this, nobody can tell
|
|
1285
1372
|
* us anything, and a turn that is still open is a composer that is still locked: the client
|
|
1286
1373
|
* closes it itself, with an error part, so the user can go on.
|
|
1287
1374
|
*/
|
|
1288
|
-
|
|
1289
|
-
|
|
1375
|
+
a(y, "OUTAGE_CLOSES_TURN_AFTER_MS", 6e4), a(y, "OUTAGE_TURN_MESSAGE", "Sem conexão com o servidor há mais de um minuto. A resposta foi interrompida."), /** What a send reports when the socket could not be brought up for it. */
|
|
1376
|
+
a(y, "NO_CONNECTION_MESSAGE", "Não foi possível obter conexão com o servidor"), a(y, "HALT_TURN_MESSAGE", {
|
|
1290
1377
|
"attached-elsewhere": "Esta sessão está aberta em outra janela. A resposta foi interrompida.",
|
|
1291
1378
|
"session-gone": "A sessão não existe mais no servidor. A resposta foi interrompida.",
|
|
1292
1379
|
"closed-by-server": "O servidor encerrou a conexão. A resposta foi interrompida."
|
|
1293
1380
|
});
|
|
1294
|
-
let
|
|
1295
|
-
function
|
|
1296
|
-
const
|
|
1297
|
-
|
|
1298
|
-
const
|
|
1299
|
-
if (
|
|
1300
|
-
const s = new
|
|
1301
|
-
s.choiceIndex = 0, s.callId = i.functionCallId, s.arguments = i.partialText, s.name = i.functionName,
|
|
1302
|
-
} else if (
|
|
1303
|
-
if (
|
|
1304
|
-
const s = new
|
|
1305
|
-
s.text = i.partialText,
|
|
1381
|
+
let ye = y;
|
|
1382
|
+
function lt(i) {
|
|
1383
|
+
const e = new Pe();
|
|
1384
|
+
e.author = "main", e.streamingParts = i.streamingParts, i.partialEventType ? e.eventType = i.partialEventType : e.eventType = i.functionName ? { fullName: z.StreamingFunctionCallUpdateContent, type: I.PartialFunctionCall } : i.partialReasoning ? { fullName: z.StreamingReasoningContent, type: I.Thought } : { fullName: z.StreamingTextContent, type: I.Text }, e.interactionId = i.iteractionId ?? "", e.mimeType = "text/plain", e.partial = !0, e.role = { label: "Assistant" }, e.timestamp = i.timeStamp ?? (/* @__PURE__ */ new Date()).getTime(), e.turnComplete = !1;
|
|
1385
|
+
const t = e.eventType.type;
|
|
1386
|
+
if (t == I.PartialFunctionCall) {
|
|
1387
|
+
const s = new Fe();
|
|
1388
|
+
s.choiceIndex = 0, s.callId = i.functionCallId, s.arguments = i.partialText, s.name = i.functionName, e.content = { items: [s], role: { label: "Assistant" } };
|
|
1389
|
+
} else if (t == I.Text)
|
|
1390
|
+
if (e.eventType.fullName == z.StreamingTextContent) {
|
|
1391
|
+
const s = new Ne();
|
|
1392
|
+
s.text = i.partialText, e.content = { items: [s], role: { label: "Assistant" } };
|
|
1306
1393
|
} else {
|
|
1307
|
-
const s = new
|
|
1308
|
-
s.text = i.partialText,
|
|
1394
|
+
const s = new _e();
|
|
1395
|
+
s.text = i.partialText, e.content = { items: [s], role: { label: "Assistant" } };
|
|
1309
1396
|
}
|
|
1310
|
-
else if (
|
|
1311
|
-
const s = new
|
|
1312
|
-
s.text = i.partialReasoning,
|
|
1397
|
+
else if (t == I.Thought) {
|
|
1398
|
+
const s = new Ue();
|
|
1399
|
+
s.text = i.partialReasoning, e.content = { items: [s], role: { label: "Assistant" } };
|
|
1313
1400
|
}
|
|
1314
|
-
return
|
|
1401
|
+
return e;
|
|
1315
1402
|
}
|
|
1316
|
-
h(
|
|
1317
|
-
function
|
|
1318
|
-
const
|
|
1319
|
-
if (
|
|
1320
|
-
return i.detachedRunId && (
|
|
1403
|
+
h(lt, "llmEventFromPartial");
|
|
1404
|
+
function se(i) {
|
|
1405
|
+
const e = i.partialEvent ? lt(i.partialEvent) : i.event;
|
|
1406
|
+
if (e)
|
|
1407
|
+
return i.detachedRunId && (e.detachedRunId = i.detachedRunId, e.detachedRunName = i.detachedRunName), e;
|
|
1321
1408
|
}
|
|
1322
|
-
h(
|
|
1323
|
-
function $
|
|
1324
|
-
var
|
|
1325
|
-
return (((
|
|
1409
|
+
h(se, "llmEventFromFrame");
|
|
1410
|
+
function $e(i) {
|
|
1411
|
+
var e, t, s;
|
|
1412
|
+
return (((t = (e = i.content) == null ? void 0 : e.items) == null ? void 0 : t.length) ?? 0) > 0 || (((s = i.streamingParts) == null ? void 0 : s.length) ?? 0) > 0;
|
|
1326
1413
|
}
|
|
1327
|
-
h($
|
|
1328
|
-
function
|
|
1329
|
-
var
|
|
1330
|
-
if (i.type !== "InteractionStarted" || !((
|
|
1414
|
+
h($e, "carriesContent");
|
|
1415
|
+
function Re(i) {
|
|
1416
|
+
var t;
|
|
1417
|
+
if (i.type !== "InteractionStarted" || !((t = i.interaction) != null && t.interactionId)) return;
|
|
1331
1418
|
if (i.interaction.detachedRunId || !i.detachedRunId) return i.interaction;
|
|
1332
|
-
const
|
|
1333
|
-
return
|
|
1419
|
+
const e = Object.assign(new Le(), i.interaction);
|
|
1420
|
+
return e.detachedRunId = i.detachedRunId, e;
|
|
1334
1421
|
}
|
|
1335
|
-
h(
|
|
1336
|
-
const
|
|
1337
|
-
function
|
|
1338
|
-
if (!
|
|
1339
|
-
const
|
|
1422
|
+
h(Re, "interactionStartFromFrame");
|
|
1423
|
+
const ht = 0.02;
|
|
1424
|
+
function ut(i, e) {
|
|
1425
|
+
if (!e) return null;
|
|
1426
|
+
const t = (e.interactionsCompressed ?? 0) > 0 || (e.compressionRatio ?? 0) > 0;
|
|
1340
1427
|
if (!i)
|
|
1341
|
-
return
|
|
1342
|
-
const s = i.size -
|
|
1343
|
-
return !
|
|
1428
|
+
return t ? ve(e, e.size, e.size) : null;
|
|
1429
|
+
const s = i.size - e.size, n = e.maxSize || i.maxSize || 0, r = n > 0 ? s / n >= ht : i.size > 0 && s / i.size >= 0.1;
|
|
1430
|
+
return !t && !r ? null : ve(e, i.size, e.size, i.ratio);
|
|
1344
1431
|
}
|
|
1345
|
-
h(
|
|
1346
|
-
function
|
|
1432
|
+
h(ut, "detectCompaction");
|
|
1433
|
+
function ve(i, e, t, s) {
|
|
1347
1434
|
return {
|
|
1348
1435
|
at: Date.now(),
|
|
1349
1436
|
// Where the bar stood when it happened — the marker's position. The ratio
|
|
1350
1437
|
// BEFORE the pass is the meaningful one: it is the fill the compaction
|
|
1351
1438
|
// reacted to, and it is also the only one that does not move afterwards.
|
|
1352
1439
|
ratio: s ?? i.ratio,
|
|
1353
|
-
sizeBefore:
|
|
1354
|
-
sizeAfter:
|
|
1440
|
+
sizeBefore: e,
|
|
1441
|
+
sizeAfter: t,
|
|
1355
1442
|
interactionsCompressed: i.interactionsCompressed
|
|
1356
1443
|
};
|
|
1357
1444
|
}
|
|
1358
|
-
h(
|
|
1359
|
-
const
|
|
1445
|
+
h(ve, "entry");
|
|
1446
|
+
const Ee = 4, dt = 3, ft = 20, P = class P {
|
|
1360
1447
|
constructor() {
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1448
|
+
a(this, "stats");
|
|
1449
|
+
a(this, "onFlush");
|
|
1450
|
+
a(this, "sessionCompactions", []);
|
|
1451
|
+
a(this, "previousSessionInformation");
|
|
1365
1452
|
/** [timestamp, text length] per frame, for the sliding-window rate. */
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1453
|
+
a(this, "events", []);
|
|
1454
|
+
a(this, "flushTimer", null);
|
|
1455
|
+
a(this, "lastFlushed", 0);
|
|
1369
1456
|
this.stats = this.fresh();
|
|
1370
1457
|
}
|
|
1371
1458
|
fresh() {
|
|
@@ -1389,76 +1476,76 @@ const Et = 4, de = 3, fe = 20, P = class P {
|
|
|
1389
1476
|
* Account for one decoded frame. `sessionInformation` is only read off main-agent
|
|
1390
1477
|
* frames — a detached run's reading describes a different session.
|
|
1391
1478
|
*/
|
|
1392
|
-
record(
|
|
1393
|
-
const
|
|
1394
|
-
if (this.events.push([
|
|
1395
|
-
const r =
|
|
1396
|
-
r && (this.sessionCompactions.push(r), this.sessionCompactions.length >
|
|
1479
|
+
record(e) {
|
|
1480
|
+
const t = Date.now();
|
|
1481
|
+
if (this.events.push([t, e.textLength]), this.stats.eventCount += 1, this.stats.totalTransfered += e.rawLength, e.sessionInformation && !e.fromDetachedRun) {
|
|
1482
|
+
const r = ut(this.previousSessionInformation, e.sessionInformation);
|
|
1483
|
+
r && (this.sessionCompactions.push(r), this.sessionCompactions.length > ft && this.sessionCompactions.shift()), this.previousSessionInformation = e.sessionInformation, this.stats.sessionInformation = e.sessionInformation, this.stats.sessionCompactions = this.sessionCompactions;
|
|
1397
1484
|
}
|
|
1398
|
-
this.stats.elapsed = (
|
|
1399
|
-
const s =
|
|
1485
|
+
this.stats.elapsed = (t - this.stats.startTime.getTime()) / 1e3;
|
|
1486
|
+
const s = t - Ee * 1e3;
|
|
1400
1487
|
for (; this.events.length > 0 && this.events[0][0] <= s; ) this.events.shift();
|
|
1401
|
-
const n = this.events.reduce((r,
|
|
1402
|
-
this.stats.tokensPerSecond = n /
|
|
1488
|
+
const n = this.events.reduce((r, o) => r + o[1], 0);
|
|
1489
|
+
this.stats.tokensPerSecond = n / dt / Ee, this.flushCoalesced();
|
|
1403
1490
|
}
|
|
1404
1491
|
flushCoalesced() {
|
|
1405
1492
|
if (!this.onFlush) return;
|
|
1406
|
-
const
|
|
1407
|
-
if (
|
|
1408
|
-
this.flushTimer && (clearTimeout(this.flushTimer), this.flushTimer = null), this.lastFlushed =
|
|
1493
|
+
const e = Date.now(), t = e - this.lastFlushed;
|
|
1494
|
+
if (t >= P.STATS_FLUSH_MS) {
|
|
1495
|
+
this.flushTimer && (clearTimeout(this.flushTimer), this.flushTimer = null), this.lastFlushed = e, this.onFlush({ ...this.stats });
|
|
1409
1496
|
return;
|
|
1410
1497
|
}
|
|
1411
1498
|
this.flushTimer || (this.flushTimer = setTimeout(() => {
|
|
1412
1499
|
var s;
|
|
1413
1500
|
this.flushTimer = null, this.lastFlushed = Date.now(), (s = this.onFlush) == null || s.call(this, { ...this.stats });
|
|
1414
|
-
}, P.STATS_FLUSH_MS -
|
|
1501
|
+
}, P.STATS_FLUSH_MS - t));
|
|
1415
1502
|
}
|
|
1416
1503
|
};
|
|
1417
|
-
h(P, "StreamStatsTracker"),
|
|
1418
|
-
let
|
|
1419
|
-
const
|
|
1420
|
-
constructor(
|
|
1421
|
-
|
|
1504
|
+
h(P, "StreamStatsTracker"), a(P, "STATS_FLUSH_MS", 120);
|
|
1505
|
+
let ee = P;
|
|
1506
|
+
const gt = 5e3, pt = 3e4, Y = 1e4, le = class le {
|
|
1507
|
+
constructor(e = "ws://localhost:8000", t) {
|
|
1508
|
+
a(this, "ws", null);
|
|
1422
1509
|
/** Frame counts, byte totals, the token-rate estimate and the compaction history — see StreamStatsTracker. */
|
|
1423
|
-
|
|
1424
|
-
|
|
1510
|
+
a(this, "statsTracker", new ee());
|
|
1511
|
+
a(this, "baseUrl");
|
|
1425
1512
|
/**
|
|
1426
1513
|
* Optional callback that returns the current JWT. We re-evaluate it on every connect/reconnect
|
|
1427
1514
|
* so that a refreshed token is picked up automatically. Browsers can't set the Authorization
|
|
1428
1515
|
* header on the WebSocket handshake, so we pass the JWT via the ?access_token= query string,
|
|
1429
1516
|
* which the .NET JwtBearer events handler reads in Program.cs.
|
|
1430
1517
|
*/
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1518
|
+
a(this, "getToken");
|
|
1519
|
+
a(this, "onEvent");
|
|
1520
|
+
a(this, "onError");
|
|
1521
|
+
a(this, "onOpen");
|
|
1522
|
+
a(this, "onFirstToken");
|
|
1523
|
+
a(this, "onSuspended");
|
|
1524
|
+
a(this, "onBillingLimit");
|
|
1525
|
+
a(this, "onClose");
|
|
1439
1526
|
/**
|
|
1440
1527
|
* Fired when the server signals that we lost streaming events on resume — our
|
|
1441
1528
|
* `lastSeq` fell off the end of the in-memory replay buffer. Consumers should
|
|
1442
1529
|
* reset partial-streaming UI for this session and rely on persisted history.
|
|
1443
1530
|
*/
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1531
|
+
a(this, "onRewindLost");
|
|
1532
|
+
a(this, "onInteractionStarted");
|
|
1533
|
+
a(this, "sessionId");
|
|
1534
|
+
a(this, "monitorInterval", null);
|
|
1535
|
+
a(this, "streamingResponseSerializer");
|
|
1536
|
+
a(this, "lastActivity");
|
|
1450
1537
|
/** When the outstanding heartbeat Ping went out; null while no reply is pending. */
|
|
1451
|
-
|
|
1452
|
-
|
|
1538
|
+
a(this, "pingSentAt", null);
|
|
1539
|
+
a(this, "firstTokenInteractions");
|
|
1453
1540
|
/** Last sessionId we successfully had — stamps parked answers, labels log lines. */
|
|
1454
|
-
|
|
1541
|
+
a(this, "lastKnownSessionId");
|
|
1455
1542
|
/**
|
|
1456
1543
|
* Highest server-assigned `seq` we have observed and processed. The next
|
|
1457
1544
|
* reconnect appends `?lastSeq={lastSeq}` so the server can replay anything
|
|
1458
1545
|
* we missed from the InteractionRun's in-memory buffer. -1 means "haven't
|
|
1459
1546
|
* seen any sequenced events yet" (fresh connection).
|
|
1460
1547
|
*/
|
|
1461
|
-
|
|
1548
|
+
a(this, "lastSeq", -1);
|
|
1462
1549
|
/**
|
|
1463
1550
|
* Parked-tool answers that could not be sent because the socket was not OPEN
|
|
1464
1551
|
* (e.g. the connection idled out while the user was in an IdP sign-in popup).
|
|
@@ -1467,15 +1554,15 @@ const ge = 5e3, pe = 3e4, Y = 1e4, lt = class lt {
|
|
|
1467
1554
|
* answer for a session this instance is no longer attached to is dropped —
|
|
1468
1555
|
* the single-attach policy makes it undeliverable from here anyway.
|
|
1469
1556
|
*/
|
|
1470
|
-
|
|
1471
|
-
this.baseUrl =
|
|
1557
|
+
a(this, "pendingAnswers", []);
|
|
1558
|
+
this.baseUrl = e, this.getToken = t, this.firstTokenInteractions = /* @__PURE__ */ new Set(), this.streamingResponseSerializer = te(), console.log("SOCKET INSTACE", Ge()), this.lastActivity = (/* @__PURE__ */ new Date()).getTime();
|
|
1472
1559
|
}
|
|
1473
1560
|
get stats() {
|
|
1474
1561
|
return this.statsTracker.stats;
|
|
1475
1562
|
}
|
|
1476
1563
|
/** Coalesced stats updates (see StreamStatsTracker.STATS_FLUSH_MS). */
|
|
1477
|
-
set onNewPacket(
|
|
1478
|
-
this.statsTracker.onFlush =
|
|
1564
|
+
set onNewPacket(e) {
|
|
1565
|
+
this.statsTracker.onFlush = e;
|
|
1479
1566
|
}
|
|
1480
1567
|
get onNewPacket() {
|
|
1481
1568
|
return this.statsTracker.onFlush;
|
|
@@ -1489,59 +1576,59 @@ const ge = 5e3, pe = 3e4, Y = 1e4, lt = class lt {
|
|
|
1489
1576
|
* while we were away (`?lastSeq=N`). Without it the dial is fresh and the cursor is dropped:
|
|
1490
1577
|
* a cursor from one conversation must never be presented to another.
|
|
1491
1578
|
*/
|
|
1492
|
-
connect(
|
|
1579
|
+
connect(e, t) {
|
|
1493
1580
|
return new Promise(async (s, n) => {
|
|
1494
|
-
var D,
|
|
1495
|
-
|
|
1496
|
-
const r = (D = this.getToken) == null ? void 0 : D.call(this),
|
|
1497
|
-
r &&
|
|
1498
|
-
const c =
|
|
1499
|
-
console.log("[WebSocket] Connecting to", `${l}/ws/connect/${
|
|
1581
|
+
var D, N;
|
|
1582
|
+
t != null && t.resume || (this.lastSeq = -1);
|
|
1583
|
+
const r = (D = this.getToken) == null ? void 0 : D.call(this), o = [];
|
|
1584
|
+
r && o.push(`access_token=${encodeURIComponent(r)}`), e && this.lastSeq >= 0 && o.push(`lastSeq=${this.lastSeq}`), e && (t != null && t.resume) && t.openInteractionId && o.push(`openInteraction=${encodeURIComponent(t.openInteractionId)}`);
|
|
1585
|
+
const c = o.length > 0 ? `?${o.join("&")}` : "", l = this.baseUrl.replace(/^http:\/\//, "ws://").replace(/^https:\/\//, "wss://"), f = `${l}/ws/connect/${e ?? ""}${c}`;
|
|
1586
|
+
console.log("[WebSocket] Connecting to", `${l}/ws/connect/${e ?? ""}` + (e && this.lastSeq >= 0 ? ` (resume lastSeq=${this.lastSeq})` : "")), this.detachSocket(), this.ws = new WebSocket(f), this.ws.onopen = () => {
|
|
1500
1587
|
console.log("[WebSocket] Socket open — waiting for the session id"), this.ping(), this.monitor();
|
|
1501
1588
|
}, this.ws.onmessage = (v) => {
|
|
1502
1589
|
try {
|
|
1503
1590
|
this.lastActivity = (/* @__PURE__ */ new Date()).getTime(), this.pingSentAt = null;
|
|
1504
|
-
const
|
|
1505
|
-
if (!
|
|
1591
|
+
const M = this.streamingResponseSerializer.parse(v.data);
|
|
1592
|
+
if (!M)
|
|
1506
1593
|
throw "Error parsing event JSON";
|
|
1507
|
-
this.handleMessage(
|
|
1508
|
-
} catch (
|
|
1509
|
-
console.error("[WebSocket] Error parsing message:",
|
|
1594
|
+
this.handleMessage(M, v.data);
|
|
1595
|
+
} catch (M) {
|
|
1596
|
+
console.error("[WebSocket] Error parsing message:", M);
|
|
1510
1597
|
}
|
|
1511
1598
|
}, this.ws.onerror = (v) => {
|
|
1512
1599
|
console.error("[WebSocket] Error:", v), this.onError && this.onError("WebSocket error");
|
|
1513
1600
|
}, this.ws.onclose = (v) => {
|
|
1514
|
-
var
|
|
1515
|
-
console.log(`[WebSocket] Closed: code=${v.code} reason="${v.reason}" (session ${this.sessionLabel}, lastSeq=${this.lastSeq})`), this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingSentAt = null, this.sessionId = void 0, (
|
|
1601
|
+
var M;
|
|
1602
|
+
console.log(`[WebSocket] Closed: code=${v.code} reason="${v.reason}" (session ${this.sessionLabel}, lastSeq=${this.lastSeq})`), this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingSentAt = null, this.sessionId = void 0, (M = this.onClose) == null || M.call(this, v.code, v.reason);
|
|
1516
1603
|
};
|
|
1517
|
-
const
|
|
1604
|
+
const g = 200, m = 3e4, u = 8e3, p = this.ws;
|
|
1518
1605
|
this.sessionId = void 0;
|
|
1519
|
-
let w = 0,
|
|
1606
|
+
let w = 0, C = 0;
|
|
1520
1607
|
for (; ; ) {
|
|
1521
|
-
if (this.ws !==
|
|
1608
|
+
if (this.ws !== p) {
|
|
1522
1609
|
n("Connection attempt superseded by a newer connect()");
|
|
1523
1610
|
return;
|
|
1524
1611
|
}
|
|
1525
1612
|
if (this.sessionId) break;
|
|
1526
|
-
if (
|
|
1613
|
+
if (p.readyState === WebSocket.CLOSING || p.readyState === WebSocket.CLOSED) {
|
|
1527
1614
|
n("Connection closed before a session id was received");
|
|
1528
1615
|
return;
|
|
1529
1616
|
}
|
|
1530
|
-
if (
|
|
1617
|
+
if (p.readyState === WebSocket.CONNECTING && w >= m) {
|
|
1531
1618
|
try {
|
|
1532
|
-
|
|
1619
|
+
p.close();
|
|
1533
1620
|
} catch {
|
|
1534
1621
|
}
|
|
1535
1622
|
n(`Server did not accept the connection within ${m / 1e3}s`);
|
|
1536
1623
|
return;
|
|
1537
1624
|
}
|
|
1538
|
-
if (
|
|
1625
|
+
if (p.readyState === WebSocket.OPEN && C >= u) {
|
|
1539
1626
|
n(`Connected but no session id arrived within ${u / 1e3}s`);
|
|
1540
1627
|
return;
|
|
1541
1628
|
}
|
|
1542
|
-
w % 2e3 === 0 && console.log("Aguardando session Id"), await this.sleep(
|
|
1629
|
+
w % 2e3 === 0 && console.log("Aguardando session Id"), await this.sleep(g), w += g, p.readyState === WebSocket.OPEN && (C += g);
|
|
1543
1630
|
}
|
|
1544
|
-
console.log(`[WebSocket] Session ${this.sessionId} proven${this.lastSeq >= 0 ? ` (replaying from lastSeq=${this.lastSeq})` : ""}.`), this.lastKnownSessionId = this.sessionId, (
|
|
1631
|
+
console.log(`[WebSocket] Session ${this.sessionId} proven${this.lastSeq >= 0 ? ` (replaying from lastSeq=${this.lastSeq})` : ""}.`), this.lastKnownSessionId = this.sessionId, (N = this.onOpen) == null || N.call(this), this.flushPendingAnswers(this.sessionId), s(this.sessionId);
|
|
1545
1632
|
});
|
|
1546
1633
|
}
|
|
1547
1634
|
/** Drop the current socket without reporting it: handlers off, then close. */
|
|
@@ -1555,8 +1642,8 @@ const ge = 5e3, pe = 3e4, Y = 1e4, lt = class lt {
|
|
|
1555
1642
|
this.ws = null;
|
|
1556
1643
|
}
|
|
1557
1644
|
}
|
|
1558
|
-
async sleep(
|
|
1559
|
-
return new Promise((
|
|
1645
|
+
async sleep(e) {
|
|
1646
|
+
return new Promise((t) => setTimeout(t, e));
|
|
1560
1647
|
}
|
|
1561
1648
|
/** The session this instance believes it is on — for log lines, never for logic. */
|
|
1562
1649
|
get sessionLabel() {
|
|
@@ -1565,15 +1652,15 @@ const ge = 5e3, pe = 3e4, Y = 1e4, lt = class lt {
|
|
|
1565
1652
|
/**
|
|
1566
1653
|
* Handle incoming messages from server
|
|
1567
1654
|
*/
|
|
1568
|
-
handleMessage(
|
|
1655
|
+
handleMessage(e, t) {
|
|
1569
1656
|
var n;
|
|
1570
|
-
switch (typeof
|
|
1657
|
+
switch (typeof e.seq == "number" && e.seq > this.lastSeq && (this.lastSeq = e.seq), e.type) {
|
|
1571
1658
|
case "Pong":
|
|
1572
|
-
if (this.sessionId =
|
|
1659
|
+
if (this.sessionId = e.sessionId, this.lastKnownSessionId = e.sessionId ?? this.lastKnownSessionId, !e.sessionId) {
|
|
1573
1660
|
console.error("Pong response has no SESSION ID");
|
|
1574
1661
|
return;
|
|
1575
1662
|
}
|
|
1576
|
-
|
|
1663
|
+
e.accessToken && this.persistRefreshedAccessToken(e.accessToken);
|
|
1577
1664
|
break;
|
|
1578
1665
|
case "Suspended":
|
|
1579
1666
|
this.onSuspended && this.onSuspended();
|
|
@@ -1581,24 +1668,24 @@ const ge = 5e3, pe = 3e4, Y = 1e4, lt = class lt {
|
|
|
1581
1668
|
case "Event":
|
|
1582
1669
|
break;
|
|
1583
1670
|
case "InteractionStarted": {
|
|
1584
|
-
const r =
|
|
1671
|
+
const r = Re(e);
|
|
1585
1672
|
r ? (n = this.onInteractionStarted) == null || n.call(this, r) : console.warn("[WebSocket] InteractionStarted frame without an interaction id");
|
|
1586
1673
|
break;
|
|
1587
1674
|
}
|
|
1588
1675
|
case "RewindLost":
|
|
1589
1676
|
console.warn(
|
|
1590
|
-
`[WebSocket] RewindLost: lost events on resume, resuming from seq=${
|
|
1591
|
-
), typeof
|
|
1677
|
+
`[WebSocket] RewindLost: lost events on resume, resuming from seq=${e.seq}`
|
|
1678
|
+
), typeof e.seq == "number" && (this.lastSeq = e.seq - 1), this.onRewindLost && e.sessionId && this.onRewindLost(e.sessionId, e.seq ?? -1);
|
|
1592
1679
|
break;
|
|
1593
1680
|
default:
|
|
1594
|
-
console.warn("[WebSocket] Unknown message type:",
|
|
1681
|
+
console.warn("[WebSocket] Unknown message type:", e.type);
|
|
1595
1682
|
}
|
|
1596
|
-
const s =
|
|
1597
|
-
return s ? ($
|
|
1683
|
+
const s = se(e);
|
|
1684
|
+
return s ? ($e(s) && this.emitFirstToken(s.interactionId), this.handleEvent(s, t), s) : null;
|
|
1598
1685
|
}
|
|
1599
|
-
emitFirstToken(
|
|
1600
|
-
var
|
|
1601
|
-
!
|
|
1686
|
+
emitFirstToken(e) {
|
|
1687
|
+
var t;
|
|
1688
|
+
!e || this.firstTokenInteractions.has(e) || (this.statsTracker.resetForInteraction(), this.firstTokenInteractions.add(e), (t = this.onFirstToken) == null || t.call(this, e));
|
|
1602
1689
|
}
|
|
1603
1690
|
/**
|
|
1604
1691
|
* Mirror a server-side-refreshed JWT into the stored user record so the global
|
|
@@ -1613,17 +1700,17 @@ const ge = 5e3, pe = 3e4, Y = 1e4, lt = class lt {
|
|
|
1613
1700
|
* memory will pick up the new token on the next refresh/render or via their
|
|
1614
1701
|
* own storage listeners.
|
|
1615
1702
|
*/
|
|
1616
|
-
persistRefreshedAccessToken(
|
|
1617
|
-
const
|
|
1703
|
+
persistRefreshedAccessToken(e) {
|
|
1704
|
+
const t = "envision_user";
|
|
1618
1705
|
try {
|
|
1619
|
-
const s = localStorage.getItem(
|
|
1706
|
+
const s = localStorage.getItem(t);
|
|
1620
1707
|
if (!s) {
|
|
1621
1708
|
console.warn("[WebSocket] WS-refreshed token received but no stored user — dropping");
|
|
1622
1709
|
return;
|
|
1623
1710
|
}
|
|
1624
1711
|
const n = JSON.parse(s);
|
|
1625
|
-
if ((n == null ? void 0 : n.access_token) ===
|
|
1626
|
-
n.access_token =
|
|
1712
|
+
if ((n == null ? void 0 : n.access_token) === e) return;
|
|
1713
|
+
n.access_token = e, localStorage.setItem(t, JSON.stringify(n)), console.info("[WebSocket] Mirrored WS-refreshed JWT into stored user");
|
|
1627
1714
|
} catch (s) {
|
|
1628
1715
|
console.error("[WebSocket] Failed to persist WS-refreshed token", s);
|
|
1629
1716
|
}
|
|
@@ -1633,7 +1720,7 @@ const ge = 5e3, pe = 3e4, Y = 1e4, lt = class lt {
|
|
|
1633
1720
|
}
|
|
1634
1721
|
suspendStream() {
|
|
1635
1722
|
this.sendBaseMessage({
|
|
1636
|
-
Action:
|
|
1723
|
+
Action: F.Suspend,
|
|
1637
1724
|
AgentId: "",
|
|
1638
1725
|
InteractionId: "",
|
|
1639
1726
|
ModelId: ""
|
|
@@ -1650,36 +1737,36 @@ const ge = 5e3, pe = 3e4, Y = 1e4, lt = class lt {
|
|
|
1650
1737
|
*
|
|
1651
1738
|
* Returns 'sent' when it went out now, 'queued' when it will go out on reconnect.
|
|
1652
1739
|
*/
|
|
1653
|
-
answerHumanTool(
|
|
1740
|
+
answerHumanTool(e, t) {
|
|
1654
1741
|
const s = {
|
|
1655
|
-
Action:
|
|
1742
|
+
Action: F.AnswerHumanTool,
|
|
1656
1743
|
AgentId: "",
|
|
1657
1744
|
InteractionId: "",
|
|
1658
|
-
ToolCallId:
|
|
1659
|
-
Answer:
|
|
1745
|
+
ToolCallId: e,
|
|
1746
|
+
Answer: t
|
|
1660
1747
|
};
|
|
1661
1748
|
if (this.ws && this.ws.readyState === WebSocket.OPEN)
|
|
1662
1749
|
try {
|
|
1663
1750
|
return this.sendBaseMessage(s), "sent";
|
|
1664
1751
|
} catch {
|
|
1665
1752
|
}
|
|
1666
|
-
return this.queueAnswer(
|
|
1753
|
+
return this.queueAnswer(e, t), "queued";
|
|
1667
1754
|
}
|
|
1668
|
-
queueAnswer(
|
|
1669
|
-
this.pendingAnswers = this.pendingAnswers.filter((s) => s.toolCallId !==
|
|
1755
|
+
queueAnswer(e, t) {
|
|
1756
|
+
this.pendingAnswers = this.pendingAnswers.filter((s) => s.toolCallId !== e), this.pendingAnswers.push({ sessionId: this.sessionId ?? this.lastKnownSessionId, toolCallId: e, answer: t }), console.warn(`[WebSocket] Socket not open — queued answer for tool call ${e}; will flush on reconnect.`);
|
|
1670
1757
|
}
|
|
1671
|
-
flushPendingAnswers(
|
|
1758
|
+
flushPendingAnswers(e) {
|
|
1672
1759
|
if (this.pendingAnswers.length === 0) return;
|
|
1673
|
-
const
|
|
1760
|
+
const t = this.pendingAnswers;
|
|
1674
1761
|
this.pendingAnswers = [];
|
|
1675
|
-
for (const s of
|
|
1676
|
-
if (s.sessionId &&
|
|
1677
|
-
console.warn(`[WebSocket] Dropping queued answer for tool call ${s.toolCallId} — it belongs to session ${s.sessionId}, reconnected to ${
|
|
1762
|
+
for (const s of t) {
|
|
1763
|
+
if (s.sessionId && e && s.sessionId !== e) {
|
|
1764
|
+
console.warn(`[WebSocket] Dropping queued answer for tool call ${s.toolCallId} — it belongs to session ${s.sessionId}, reconnected to ${e}.`);
|
|
1678
1765
|
continue;
|
|
1679
1766
|
}
|
|
1680
1767
|
try {
|
|
1681
1768
|
this.sendBaseMessage({
|
|
1682
|
-
Action:
|
|
1769
|
+
Action: F.AnswerHumanTool,
|
|
1683
1770
|
AgentId: "",
|
|
1684
1771
|
InteractionId: "",
|
|
1685
1772
|
ToolCallId: s.toolCallId,
|
|
@@ -1693,13 +1780,13 @@ const ge = 5e3, pe = 3e4, Y = 1e4, lt = class lt {
|
|
|
1693
1780
|
/**
|
|
1694
1781
|
* Send a message to the agent
|
|
1695
1782
|
*/
|
|
1696
|
-
sendMessage(
|
|
1697
|
-
this.sendBaseMessage(
|
|
1783
|
+
sendMessage(e) {
|
|
1784
|
+
this.sendBaseMessage(e);
|
|
1698
1785
|
}
|
|
1699
|
-
sendBaseMessage(
|
|
1786
|
+
sendBaseMessage(e) {
|
|
1700
1787
|
if (this.lastActivity = (/* @__PURE__ */ new Date()).getTime(), !this.ws || this.ws.readyState !== WebSocket.OPEN)
|
|
1701
1788
|
throw new Error("WebSocket is not connected");
|
|
1702
|
-
this.ws.send(JSON.stringify(
|
|
1789
|
+
this.ws.send(JSON.stringify(e));
|
|
1703
1790
|
}
|
|
1704
1791
|
/**
|
|
1705
1792
|
* Heartbeat: keep a quiet socket alive with a Ping every PING_INTERVAL_MS, and
|
|
@@ -1710,24 +1797,24 @@ const ge = 5e3, pe = 3e4, Y = 1e4, lt = class lt {
|
|
|
1710
1797
|
this.monitorInterval && clearInterval(this.monitorInterval), this.monitorInterval = setInterval(() => {
|
|
1711
1798
|
try {
|
|
1712
1799
|
if (!this.isConnected()) return;
|
|
1713
|
-
const
|
|
1800
|
+
const e = Date.now();
|
|
1714
1801
|
if (this.pingSentAt !== null) {
|
|
1715
|
-
const
|
|
1716
|
-
if (
|
|
1802
|
+
const t = e - this.pingSentAt;
|
|
1803
|
+
if (t >= Y) {
|
|
1717
1804
|
this.failSocket(
|
|
1718
|
-
|
|
1719
|
-
`No frame received for ${Math.round(
|
|
1805
|
+
nt,
|
|
1806
|
+
`No frame received for ${Math.round(t / 1e3)}s after a Ping`
|
|
1720
1807
|
);
|
|
1721
1808
|
return;
|
|
1722
1809
|
}
|
|
1723
|
-
console.warn(`[WebSocket] Still no reply ${
|
|
1810
|
+
console.warn(`[WebSocket] Still no reply ${t}ms after the Ping (budget ${Y}ms, session ${this.sessionLabel}) — the peer may be gone.`);
|
|
1724
1811
|
return;
|
|
1725
1812
|
}
|
|
1726
|
-
|
|
1727
|
-
} catch (
|
|
1728
|
-
console.error("Error on monitor",
|
|
1813
|
+
e - this.lastActivity >= pt && this.ping();
|
|
1814
|
+
} catch (e) {
|
|
1815
|
+
console.error("Error on monitor", e);
|
|
1729
1816
|
}
|
|
1730
|
-
},
|
|
1817
|
+
}, gt);
|
|
1731
1818
|
}
|
|
1732
1819
|
/**
|
|
1733
1820
|
* Send a heartbeat ping and start the reply clock (unless one is already running).
|
|
@@ -1757,23 +1844,23 @@ const ge = 5e3, pe = 3e4, Y = 1e4, lt = class lt {
|
|
|
1757
1844
|
* what a server close would have produced. Handlers are detached first so a
|
|
1758
1845
|
* late real close event cannot run it a second time.
|
|
1759
1846
|
*/
|
|
1760
|
-
failSocket(
|
|
1847
|
+
failSocket(e, t) {
|
|
1761
1848
|
const s = this.ws;
|
|
1762
1849
|
if (!s) return;
|
|
1763
|
-
console.warn(`[WebSocket] ${
|
|
1850
|
+
console.warn(`[WebSocket] ${t} — treating the socket as dead (code=${e}, session ${this.sessionLabel}). readyState was ${s.readyState} (OPEN=${WebSocket.OPEN}), which is why nothing else noticed. Running the close path now.`);
|
|
1764
1851
|
const n = s.onclose;
|
|
1765
1852
|
s.onopen = null, s.onmessage = null, s.onerror = null, s.onclose = null;
|
|
1766
1853
|
try {
|
|
1767
1854
|
s.close();
|
|
1768
1855
|
} catch {
|
|
1769
1856
|
}
|
|
1770
|
-
n == null || n.call(s, { code:
|
|
1857
|
+
n == null || n.call(s, { code: e, reason: t });
|
|
1771
1858
|
}
|
|
1772
1859
|
/**
|
|
1773
1860
|
* Disconnect the WebSocket
|
|
1774
1861
|
*/
|
|
1775
1862
|
disconnect() {
|
|
1776
|
-
console.log(`[WebSocket] disconnect() (session ${this.sessionLabel})`), this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingSentAt = null, this.firstTokenInteractions.clear(), this.lastKnownSessionId = void 0, this.lastSeq = -1, this.ws && (this.ws.close(
|
|
1863
|
+
console.log(`[WebSocket] disconnect() (session ${this.sessionLabel})`), this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingSentAt = null, this.firstTokenInteractions.clear(), this.lastKnownSessionId = void 0, this.lastSeq = -1, this.ws && (this.ws.close(ke, "Intentional disconnect"), this.ws = null);
|
|
1777
1864
|
}
|
|
1778
1865
|
/**
|
|
1779
1866
|
* Check if connected
|
|
@@ -1781,11 +1868,11 @@ const ge = 5e3, pe = 3e4, Y = 1e4, lt = class lt {
|
|
|
1781
1868
|
isConnected() {
|
|
1782
1869
|
return this.ws !== null && this.ws.readyState === WebSocket.OPEN;
|
|
1783
1870
|
}
|
|
1784
|
-
async handleEvent(
|
|
1785
|
-
var n, r,
|
|
1786
|
-
const s = (r = (n =
|
|
1871
|
+
async handleEvent(e, t) {
|
|
1872
|
+
var n, r, o, c;
|
|
1873
|
+
const s = (r = (n = e.content) == null ? void 0 : n.items) == null ? void 0 : r.find((l) => l instanceof qe);
|
|
1787
1874
|
if (s) {
|
|
1788
|
-
(
|
|
1875
|
+
(o = this.onBillingLimit) == null || o.call(this, {
|
|
1789
1876
|
plan: s.plan ?? "team",
|
|
1790
1877
|
state: s.state ?? "ok",
|
|
1791
1878
|
used: s.used ?? 0,
|
|
@@ -1795,17 +1882,17 @@ const ge = 5e3, pe = 3e4, Y = 1e4, lt = class lt {
|
|
|
1795
1882
|
title: s.title,
|
|
1796
1883
|
message: s.message,
|
|
1797
1884
|
actionUrl: s.actionUrl,
|
|
1798
|
-
interactionId:
|
|
1885
|
+
interactionId: e.interactionId || void 0
|
|
1799
1886
|
});
|
|
1800
1887
|
return;
|
|
1801
1888
|
}
|
|
1802
1889
|
try {
|
|
1803
|
-
const l =
|
|
1890
|
+
const l = q.parseFromTypedEvent(e);
|
|
1804
1891
|
if (!l)
|
|
1805
1892
|
throw "Server event was null";
|
|
1806
1893
|
this.statsTracker.record({
|
|
1807
|
-
rawLength:
|
|
1808
|
-
textLength: ((c =
|
|
1894
|
+
rawLength: t.length,
|
|
1895
|
+
textLength: ((c = e.text) == null ? void 0 : c.length) ?? 0,
|
|
1809
1896
|
sessionInformation: l.session_information,
|
|
1810
1897
|
fromDetachedRun: !!l.detachedRunId
|
|
1811
1898
|
}), this.onEvent && this.onEvent(l).catch((f) => {
|
|
@@ -1816,42 +1903,42 @@ const ge = 5e3, pe = 3e4, Y = 1e4, lt = class lt {
|
|
|
1816
1903
|
}
|
|
1817
1904
|
}
|
|
1818
1905
|
};
|
|
1819
|
-
h(
|
|
1820
|
-
let
|
|
1821
|
-
const
|
|
1822
|
-
constructor(
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
this.serverBaseUrl =
|
|
1906
|
+
h(le, "WebSocketConnecionV2");
|
|
1907
|
+
let Me = le;
|
|
1908
|
+
const he = class he {
|
|
1909
|
+
constructor(e, t) {
|
|
1910
|
+
a(this, "cache", /* @__PURE__ */ new Map());
|
|
1911
|
+
a(this, "serverBaseUrl");
|
|
1912
|
+
a(this, "accessToken");
|
|
1913
|
+
this.serverBaseUrl = e.replace(/\/$/, ""), this.accessToken = t;
|
|
1827
1914
|
}
|
|
1828
1915
|
get headers() {
|
|
1829
|
-
return { Authorization: `Bearer ${
|
|
1916
|
+
return { Authorization: `Bearer ${ze(this.accessToken)}` };
|
|
1830
1917
|
}
|
|
1831
1918
|
async init() {
|
|
1832
1919
|
}
|
|
1833
1920
|
getArtifacts() {
|
|
1834
1921
|
return Array.from(this.cache.values());
|
|
1835
1922
|
}
|
|
1836
|
-
async saveArtifact(
|
|
1837
|
-
this.cache.set(
|
|
1923
|
+
async saveArtifact(e) {
|
|
1924
|
+
this.cache.set(e.id, e);
|
|
1838
1925
|
}
|
|
1839
|
-
saveArtifactToCache(
|
|
1840
|
-
this.cache.set(
|
|
1926
|
+
saveArtifactToCache(e) {
|
|
1927
|
+
this.cache.set(e.id, e);
|
|
1841
1928
|
}
|
|
1842
|
-
async deleteArtifact(
|
|
1843
|
-
this.cache.delete(
|
|
1929
|
+
async deleteArtifact(e) {
|
|
1930
|
+
this.cache.delete(e);
|
|
1844
1931
|
}
|
|
1845
|
-
addToCache(
|
|
1846
|
-
this.cache.set(
|
|
1932
|
+
addToCache(e) {
|
|
1933
|
+
this.cache.set(e.id, e);
|
|
1847
1934
|
}
|
|
1848
|
-
getArtifactWithCache(
|
|
1849
|
-
return this.cache.get(
|
|
1935
|
+
getArtifactWithCache(e) {
|
|
1936
|
+
return this.cache.get(e) ?? null;
|
|
1850
1937
|
}
|
|
1851
|
-
async getArtifact(
|
|
1852
|
-
if (this.cache.has(
|
|
1938
|
+
async getArtifact(e, t) {
|
|
1939
|
+
if (this.cache.has(e)) return this.cache.get(e) ?? null;
|
|
1853
1940
|
try {
|
|
1854
|
-
const s = await fetch(`${this.serverBaseUrl}/AdminArtifact/${
|
|
1941
|
+
const s = await fetch(`${this.serverBaseUrl}/AdminArtifact/${e}`, {
|
|
1855
1942
|
headers: this.headers
|
|
1856
1943
|
});
|
|
1857
1944
|
if (!s.ok) return null;
|
|
@@ -1864,94 +1951,94 @@ const ht = class ht {
|
|
|
1864
1951
|
async clearAllArtifacts() {
|
|
1865
1952
|
this.cache.clear();
|
|
1866
1953
|
}
|
|
1867
|
-
async getFileContent(
|
|
1954
|
+
async getFileContent(e) {
|
|
1868
1955
|
try {
|
|
1869
|
-
const
|
|
1870
|
-
return
|
|
1956
|
+
const t = await fetch(e, { headers: this.headers });
|
|
1957
|
+
return t.ok ? await t.text() : null;
|
|
1871
1958
|
} catch {
|
|
1872
1959
|
return null;
|
|
1873
1960
|
}
|
|
1874
1961
|
}
|
|
1875
1962
|
};
|
|
1876
|
-
h(
|
|
1877
|
-
let
|
|
1878
|
-
const
|
|
1879
|
-
constructor(
|
|
1880
|
-
super(
|
|
1963
|
+
h(he, "HttpArtifactService");
|
|
1964
|
+
let Ce = he;
|
|
1965
|
+
const ue = class ue extends Error {
|
|
1966
|
+
constructor(e, t) {
|
|
1967
|
+
super(t ?? `GET detached-run frames answered ${e}`), this.status = e, this.name = "DetachedRunFramesHttpError";
|
|
1881
1968
|
}
|
|
1882
1969
|
};
|
|
1883
|
-
h(
|
|
1884
|
-
let L =
|
|
1885
|
-
function
|
|
1970
|
+
h(ue, "DetachedRunFramesHttpError");
|
|
1971
|
+
let L = ue;
|
|
1972
|
+
function mt(i) {
|
|
1886
1973
|
if (i instanceof L) {
|
|
1887
|
-
const { status:
|
|
1888
|
-
return { kind:
|
|
1974
|
+
const { status: e } = i;
|
|
1975
|
+
return { kind: e === 401 ? "unauthorized" : e === 403 ? "forbidden" : e === 404 || e === 410 ? "notFound" : "gaveUp", status: e, cause: i };
|
|
1889
1976
|
}
|
|
1890
1977
|
return { kind: "gaveUp", cause: i };
|
|
1891
1978
|
}
|
|
1892
|
-
h(
|
|
1893
|
-
function
|
|
1894
|
-
let
|
|
1979
|
+
h(mt, "toDetachedRunFollowError");
|
|
1980
|
+
function wt(i) {
|
|
1981
|
+
let e = "", t = [], s, n;
|
|
1895
1982
|
const r = /* @__PURE__ */ h(() => {
|
|
1896
|
-
(
|
|
1897
|
-
`), id: n }),
|
|
1898
|
-
}, "dispatch"),
|
|
1983
|
+
(t.length > 0 || s !== void 0) && i({ event: s, data: t.join(`
|
|
1984
|
+
`), id: n }), t = [], s = void 0, n = void 0;
|
|
1985
|
+
}, "dispatch"), o = /* @__PURE__ */ h((c) => {
|
|
1899
1986
|
if (c === "") return r();
|
|
1900
1987
|
if (c.startsWith(":")) return;
|
|
1901
1988
|
const l = c.indexOf(":"), f = l === -1 ? c : c.slice(0, l);
|
|
1902
|
-
let
|
|
1903
|
-
|
|
1989
|
+
let g = l === -1 ? "" : c.slice(l + 1);
|
|
1990
|
+
g.startsWith(" ") && (g = g.slice(1)), f === "data" ? t.push(g) : f === "event" ? s = g : f === "id" && (n = g);
|
|
1904
1991
|
}, "line");
|
|
1905
1992
|
return {
|
|
1906
1993
|
push(c) {
|
|
1907
|
-
for (
|
|
1908
|
-
const l =
|
|
1909
|
-
if (l === -1 ||
|
|
1910
|
-
const f =
|
|
1994
|
+
for (e += c; ; ) {
|
|
1995
|
+
const l = e.search(/\r\n|\r|\n/);
|
|
1996
|
+
if (l === -1 || e[l] === "\r" && l === e.length - 1) return;
|
|
1997
|
+
const f = e.startsWith(`\r
|
|
1911
1998
|
`, l) ? 2 : 1;
|
|
1912
|
-
|
|
1999
|
+
o(e.slice(0, l)), e = e.slice(l + f);
|
|
1913
2000
|
}
|
|
1914
2001
|
},
|
|
1915
2002
|
/** Nothing half-received: no partial line buffered, no event begun and not yet dispatched. */
|
|
1916
2003
|
idle() {
|
|
1917
|
-
return
|
|
2004
|
+
return e === "" && t.length === 0 && s === void 0 && n === void 0;
|
|
1918
2005
|
},
|
|
1919
2006
|
flush() {
|
|
1920
|
-
|
|
2007
|
+
e !== "" && o(e.replace(/\r$/, "")), e = "";
|
|
1921
2008
|
}
|
|
1922
2009
|
};
|
|
1923
2010
|
}
|
|
1924
|
-
h(
|
|
1925
|
-
function
|
|
2011
|
+
h(wt, "createSseParser");
|
|
2012
|
+
function St(i) {
|
|
1926
2013
|
return i >= 500 || i === 408 || i === 429;
|
|
1927
2014
|
}
|
|
1928
|
-
h(
|
|
1929
|
-
function
|
|
1930
|
-
return new Promise((
|
|
1931
|
-
if (
|
|
2015
|
+
h(St, "retryable");
|
|
2016
|
+
function It(i, e) {
|
|
2017
|
+
return new Promise((t) => {
|
|
2018
|
+
if (e != null && e.aborted) return t();
|
|
1932
2019
|
const s = setTimeout(n, i);
|
|
1933
2020
|
function n() {
|
|
1934
|
-
clearTimeout(s),
|
|
2021
|
+
clearTimeout(s), e == null || e.removeEventListener("abort", n), t();
|
|
1935
2022
|
}
|
|
1936
|
-
h(n, "done"),
|
|
2023
|
+
h(n, "done"), e == null || e.addEventListener("abort", n, { once: !0 });
|
|
1937
2024
|
});
|
|
1938
2025
|
}
|
|
1939
|
-
h(
|
|
1940
|
-
function
|
|
1941
|
-
const n =
|
|
1942
|
-
return `${i.replace(/\/+$/, "")}/${n}/${encodeURIComponent(
|
|
2026
|
+
h(It, "sleep");
|
|
2027
|
+
function Tt(i, e, t, s) {
|
|
2028
|
+
const n = e === "session" ? "sessions" : "detached-runs";
|
|
2029
|
+
return `${i.replace(/\/+$/, "")}/${n}/${encodeURIComponent(t)}/frames?afterSeq=${s}`;
|
|
1943
2030
|
}
|
|
1944
|
-
h(
|
|
1945
|
-
async function
|
|
1946
|
-
var
|
|
1947
|
-
const { baseUrl:
|
|
1948
|
-
let
|
|
2031
|
+
h(Tt, "framesUrl");
|
|
2032
|
+
async function yt(i) {
|
|
2033
|
+
var N, v, M, fe, ge;
|
|
2034
|
+
const { baseUrl: e, runId: t, signal: s, onFrame: n, onEnd: r, onOpen: o, onRetry: c } = i, l = i.resource ?? "detachedRun", f = i.fetchImpl ?? ((A, $) => fetch(A, $)), g = ((N = i.retry) == null ? void 0 : N.initialMs) ?? 500, m = ((v = i.retry) == null ? void 0 : v.maxMs) ?? 15e3, u = ((M = i.retry) == null ? void 0 : M.maxAttempts) ?? Number.POSITIVE_INFINITY;
|
|
2035
|
+
let p = i.afterSeq ?? 0, w = 0, C = !1;
|
|
1949
2036
|
async function D(A) {
|
|
1950
2037
|
if (i.onUnauthorized)
|
|
1951
2038
|
try {
|
|
1952
2039
|
if (await i.onUnauthorized()) return !0;
|
|
1953
2040
|
} catch (O) {
|
|
1954
|
-
console.warn(`[DetachedRunFrames] run ${
|
|
2041
|
+
console.warn(`[DetachedRunFrames] run ${t}: onUnauthorized threw`, O);
|
|
1955
2042
|
}
|
|
1956
2043
|
if (!i.getToken) return !1;
|
|
1957
2044
|
const $ = await i.getToken() ?? void 0;
|
|
@@ -1960,60 +2047,60 @@ async function ye(i) {
|
|
|
1960
2047
|
for (h(D, "secondChance"); !(s != null && s.aborted); ) {
|
|
1961
2048
|
let A;
|
|
1962
2049
|
try {
|
|
1963
|
-
const O = { Accept: "text/event-stream" },
|
|
1964
|
-
|
|
1965
|
-
const k = await f(
|
|
2050
|
+
const O = { Accept: "text/event-stream" }, J = await ((fe = i.getToken) == null ? void 0 : fe.call(i)) ?? void 0;
|
|
2051
|
+
J && (O.Authorization = `Bearer ${J}`);
|
|
2052
|
+
const k = await f(Tt(e, l, t, p), { method: "GET", headers: O, signal: s, cache: "no-store" });
|
|
1966
2053
|
if (k.status === 401) {
|
|
1967
|
-
if (!
|
|
1968
|
-
|
|
2054
|
+
if (!C && await D(J)) {
|
|
2055
|
+
C = !0;
|
|
1969
2056
|
continue;
|
|
1970
2057
|
}
|
|
1971
2058
|
throw new L(401);
|
|
1972
2059
|
}
|
|
1973
|
-
if (
|
|
1974
|
-
throw
|
|
2060
|
+
if (C = !1, !k.ok)
|
|
2061
|
+
throw St(k.status) ? new Error(`GET detached-run frames answered ${k.status}`) : new L(k.status);
|
|
1975
2062
|
if (!k.body) throw new L(k.status, "The frames response has no readable body");
|
|
1976
|
-
|
|
2063
|
+
o == null || o();
|
|
1977
2064
|
let W = !1;
|
|
1978
|
-
const B =
|
|
2065
|
+
const B = wt((T) => {
|
|
1979
2066
|
if (T.event === "end") {
|
|
1980
2067
|
const b = Number(T.data);
|
|
1981
|
-
T.data !== "" && Number.isFinite(b) && b >
|
|
2068
|
+
T.data !== "" && Number.isFinite(b) && b > p && (p = b), W = !0;
|
|
1982
2069
|
return;
|
|
1983
2070
|
}
|
|
1984
2071
|
if (T.event !== void 0 && T.event !== "message" || T.data === "") return;
|
|
1985
2072
|
const R = T.id !== void 0 && T.id !== "" ? Number(T.id) : void 0;
|
|
1986
2073
|
if (R !== void 0 && Number.isFinite(R)) {
|
|
1987
|
-
if (R <=
|
|
1988
|
-
|
|
2074
|
+
if (R <= p) return;
|
|
2075
|
+
p = R;
|
|
1989
2076
|
}
|
|
1990
2077
|
W = !1;
|
|
1991
|
-
let
|
|
2078
|
+
let me;
|
|
1992
2079
|
try {
|
|
1993
|
-
|
|
2080
|
+
me = JSON.parse(T.data);
|
|
1994
2081
|
} catch (b) {
|
|
1995
|
-
console.warn(`[DetachedRunFrames] run ${
|
|
2082
|
+
console.warn(`[DetachedRunFrames] run ${t}: a frame that is not JSON was skipped (seq ${T.id ?? "?"})`, b);
|
|
1996
2083
|
return;
|
|
1997
2084
|
}
|
|
1998
2085
|
w = 0;
|
|
1999
2086
|
try {
|
|
2000
|
-
n(
|
|
2087
|
+
n(me, R);
|
|
2001
2088
|
} catch (b) {
|
|
2002
|
-
console.error(`[DetachedRunFrames] run ${
|
|
2089
|
+
console.error(`[DetachedRunFrames] run ${t}: onFrame threw on seq ${T.id ?? "?"}`, b);
|
|
2003
2090
|
}
|
|
2004
|
-
}), G = k.body.getReader(),
|
|
2091
|
+
}), G = k.body.getReader(), pe = new TextDecoder();
|
|
2005
2092
|
try {
|
|
2006
2093
|
for (; ; ) {
|
|
2007
2094
|
const { done: T, value: R } = await G.read();
|
|
2008
2095
|
if (T) break;
|
|
2009
|
-
B.push(
|
|
2096
|
+
B.push(pe.decode(R, { stream: !0 }));
|
|
2010
2097
|
}
|
|
2011
|
-
B.push(
|
|
2098
|
+
B.push(pe.decode()), B.idle() || (W = !1), B.flush();
|
|
2012
2099
|
} finally {
|
|
2013
|
-
(
|
|
2100
|
+
(ge = G.releaseLock) == null || ge.call(G);
|
|
2014
2101
|
}
|
|
2015
2102
|
if (W && l !== "session")
|
|
2016
|
-
return r == null || r(
|
|
2103
|
+
return r == null || r(p), { reason: "end", lastSeq: p };
|
|
2017
2104
|
A = new Error(l === "session" ? "The session frames stream closed" : "The frames stream closed before its end event");
|
|
2018
2105
|
} catch (O) {
|
|
2019
2106
|
if (s != null && s.aborted) break;
|
|
@@ -2021,38 +2108,38 @@ async function ye(i) {
|
|
|
2021
2108
|
A = O;
|
|
2022
2109
|
}
|
|
2023
2110
|
if (w += 1, w >= u) throw A;
|
|
2024
|
-
const $ = Math.min(
|
|
2111
|
+
const $ = Math.min(g * 2 ** (w - 1), m);
|
|
2025
2112
|
try {
|
|
2026
2113
|
c == null || c(A, w, $);
|
|
2027
2114
|
} catch {
|
|
2028
2115
|
}
|
|
2029
|
-
await
|
|
2116
|
+
await It($, s);
|
|
2030
2117
|
}
|
|
2031
|
-
return { reason: "aborted", lastSeq:
|
|
2118
|
+
return { reason: "aborted", lastSeq: p };
|
|
2032
2119
|
}
|
|
2033
|
-
h(
|
|
2034
|
-
const
|
|
2035
|
-
constructor(
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2120
|
+
h(yt, "streamDetachedRunFrames");
|
|
2121
|
+
const de = class de {
|
|
2122
|
+
constructor(e) {
|
|
2123
|
+
a(this, "onEvent");
|
|
2124
|
+
a(this, "onError");
|
|
2125
|
+
a(this, "onOpen");
|
|
2126
|
+
a(this, "onFirstToken");
|
|
2127
|
+
a(this, "onSuspended");
|
|
2128
|
+
a(this, "onClose");
|
|
2129
|
+
a(this, "onNewPacket");
|
|
2130
|
+
a(this, "onInteractionStarted");
|
|
2044
2131
|
/** The stream of the current follow is over: the server closed it right after an `event: end`. */
|
|
2045
|
-
|
|
2132
|
+
a(this, "onEnd");
|
|
2046
2133
|
/** Following stopped for good — the run is gone, forbidden, the credentials failed twice, or retries ran out. */
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
this.options =
|
|
2134
|
+
a(this, "onFollowError");
|
|
2135
|
+
a(this, "options");
|
|
2136
|
+
a(this, "serializer", te());
|
|
2137
|
+
a(this, "firstTokens", /* @__PURE__ */ new Set());
|
|
2138
|
+
a(this, "runId");
|
|
2139
|
+
a(this, "controller", null);
|
|
2140
|
+
a(this, "following", !1);
|
|
2141
|
+
a(this, "lastSeq", 0);
|
|
2142
|
+
this.options = e;
|
|
2056
2143
|
}
|
|
2057
2144
|
/** The highest seq delivered so far — where the next follow resumes. */
|
|
2058
2145
|
get cursor() {
|
|
@@ -2062,9 +2149,9 @@ const dt = class dt {
|
|
|
2062
2149
|
get isFollowing() {
|
|
2063
2150
|
return this.following;
|
|
2064
2151
|
}
|
|
2065
|
-
connect(
|
|
2152
|
+
connect(e, t) {
|
|
2066
2153
|
var s, n;
|
|
2067
|
-
return
|
|
2154
|
+
return e ? ((e !== this.runId || !(t != null && t.resume)) && (this.lastSeq = ((n = (s = this.options).initialAfterSeq) == null ? void 0 : n.call(s)) ?? 0, this.firstTokens.clear()), this.runId = e, this.start(e)) : Promise.reject(new Error("DetachedRunFramesTransport: connect() needs the run id"));
|
|
2068
2155
|
}
|
|
2069
2156
|
/**
|
|
2070
2157
|
* Follow again from the last seq — after the stream ended and the run was resumed (answered). A no-op while a
|
|
@@ -2073,20 +2160,20 @@ const dt = class dt {
|
|
|
2073
2160
|
follow() {
|
|
2074
2161
|
return this.runId ? this.following ? Promise.resolve(this.runId) : this.start(this.runId) : Promise.reject(new Error("DetachedRunFramesTransport: follow() before connect()"));
|
|
2075
2162
|
}
|
|
2076
|
-
start(
|
|
2163
|
+
start(e) {
|
|
2077
2164
|
var s;
|
|
2078
2165
|
(s = this.controller) == null || s.abort();
|
|
2079
|
-
const
|
|
2080
|
-
return this.controller =
|
|
2081
|
-
let
|
|
2082
|
-
|
|
2166
|
+
const t = new AbortController();
|
|
2167
|
+
return this.controller = t, this.following = !0, new Promise((n, r) => {
|
|
2168
|
+
let o = !1;
|
|
2169
|
+
yt({
|
|
2083
2170
|
...this.options,
|
|
2084
|
-
runId:
|
|
2171
|
+
runId: e,
|
|
2085
2172
|
afterSeq: this.lastSeq,
|
|
2086
|
-
signal:
|
|
2173
|
+
signal: t.signal,
|
|
2087
2174
|
onOpen: /* @__PURE__ */ h(() => {
|
|
2088
2175
|
var c;
|
|
2089
|
-
|
|
2176
|
+
o || (o = !0, (c = this.onOpen) == null || c.call(this), n(e));
|
|
2090
2177
|
}, "onOpen"),
|
|
2091
2178
|
onFrame: /* @__PURE__ */ h((c, l) => {
|
|
2092
2179
|
typeof l == "number" && l > this.lastSeq && (this.lastSeq = l), this.dispatch(c);
|
|
@@ -2096,116 +2183,116 @@ const dt = class dt {
|
|
|
2096
2183
|
this.lastSeq = Math.max(this.lastSeq, c), (l = this.onEnd) == null || l.call(this, this.lastSeq);
|
|
2097
2184
|
}, "onEnd"),
|
|
2098
2185
|
onRetry: /* @__PURE__ */ h((c, l, f) => {
|
|
2099
|
-
console.warn(`[DetachedRunFrames] run ${
|
|
2186
|
+
console.warn(`[DetachedRunFrames] run ${e}: the stream failed (attempt ${l}); following again from seq ${this.lastSeq} in ${f}ms.`, c);
|
|
2100
2187
|
}, "onRetry")
|
|
2101
2188
|
}).then(() => {
|
|
2102
|
-
|
|
2189
|
+
o || r(new Error("The frames stream stopped before it opened"));
|
|
2103
2190
|
}).catch((c) => {
|
|
2104
|
-
var
|
|
2105
|
-
const l =
|
|
2106
|
-
console.error(`[DetachedRunFrames] run ${
|
|
2191
|
+
var g, m, u;
|
|
2192
|
+
const l = mt(c), f = l.kind === "notFound" ? De : l.kind === "forbidden" || l.kind === "unauthorized" ? 1008 : 1011;
|
|
2193
|
+
console.error(`[DetachedRunFrames] run ${e}: following stopped (${l.kind})`, c);
|
|
2107
2194
|
try {
|
|
2108
|
-
(
|
|
2109
|
-
} catch (
|
|
2110
|
-
console.error("[DetachedRunFrames] onFollowError threw",
|
|
2195
|
+
(g = this.onFollowError) == null || g.call(this, l);
|
|
2196
|
+
} catch (p) {
|
|
2197
|
+
console.error("[DetachedRunFrames] onFollowError threw", p);
|
|
2111
2198
|
}
|
|
2112
|
-
(m = this.onError) == null || m.call(this, String((c == null ? void 0 : c.message) ?? c)), (u = this.onClose) == null || u.call(this, f, String((c == null ? void 0 : c.message) ?? "")),
|
|
2199
|
+
(m = this.onError) == null || m.call(this, String((c == null ? void 0 : c.message) ?? c)), (u = this.onClose) == null || u.call(this, f, String((c == null ? void 0 : c.message) ?? "")), o || r(c);
|
|
2113
2200
|
}).finally(() => {
|
|
2114
|
-
this.controller ===
|
|
2201
|
+
this.controller === t && (this.following = !1);
|
|
2115
2202
|
});
|
|
2116
2203
|
});
|
|
2117
2204
|
}
|
|
2118
2205
|
/** One frame, decoded exactly as the chat socket decodes it. A frame that fails to decode is skipped. */
|
|
2119
|
-
dispatch(
|
|
2120
|
-
var r,
|
|
2121
|
-
let
|
|
2206
|
+
dispatch(e) {
|
|
2207
|
+
var r, o, c;
|
|
2208
|
+
let t;
|
|
2122
2209
|
try {
|
|
2123
|
-
|
|
2210
|
+
t = this.serializer.parse(e);
|
|
2124
2211
|
} catch (l) {
|
|
2125
2212
|
console.warn("[DetachedRunFrames] a frame failed to decode", l);
|
|
2126
2213
|
return;
|
|
2127
2214
|
}
|
|
2128
|
-
if (!
|
|
2129
|
-
const s =
|
|
2215
|
+
if (!t) return;
|
|
2216
|
+
const s = Re(t);
|
|
2130
2217
|
if (s) {
|
|
2131
2218
|
(r = this.onInteractionStarted) == null || r.call(this, s);
|
|
2132
2219
|
return;
|
|
2133
2220
|
}
|
|
2134
|
-
const n =
|
|
2221
|
+
const n = se(t);
|
|
2135
2222
|
if (n) {
|
|
2136
|
-
$
|
|
2223
|
+
$e(n) && n.interactionId && !this.firstTokens.has(n.interactionId) && (this.firstTokens.add(n.interactionId), (o = this.onFirstToken) == null || o.call(this, n.interactionId));
|
|
2137
2224
|
try {
|
|
2138
|
-
const l =
|
|
2225
|
+
const l = q.parseFromTypedEvent(n);
|
|
2139
2226
|
(c = this.onEvent) == null || c.call(this, l).catch((f) => console.error("[DetachedRunFrames] onEvent failed", f));
|
|
2140
2227
|
} catch (l) {
|
|
2141
2228
|
console.error("[DetachedRunFrames] a frame could not be mapped to a server event", l);
|
|
2142
2229
|
}
|
|
2143
2230
|
}
|
|
2144
2231
|
}
|
|
2145
|
-
sendMessage(
|
|
2232
|
+
sendMessage(e) {
|
|
2146
2233
|
throw new Error("A detached-run transcript is read-only: answer the run through its own endpoint.");
|
|
2147
2234
|
}
|
|
2148
2235
|
suspendStream() {
|
|
2149
2236
|
}
|
|
2150
2237
|
closeStream() {
|
|
2151
|
-
var
|
|
2152
|
-
(
|
|
2238
|
+
var e;
|
|
2239
|
+
(e = this.controller) == null || e.abort(), this.controller = null, this.following = !1;
|
|
2153
2240
|
}
|
|
2154
2241
|
isConnected() {
|
|
2155
2242
|
return this.controller !== null;
|
|
2156
2243
|
}
|
|
2157
2244
|
};
|
|
2158
|
-
h(
|
|
2159
|
-
let
|
|
2160
|
-
const
|
|
2161
|
-
function
|
|
2245
|
+
h(de, "DetachedRunFramesTransport");
|
|
2246
|
+
let Ae = de;
|
|
2247
|
+
const vt = "todolistUpdated";
|
|
2248
|
+
function bt(i, e = te()) {
|
|
2162
2249
|
var n, r;
|
|
2163
|
-
let
|
|
2250
|
+
let t;
|
|
2164
2251
|
try {
|
|
2165
|
-
const
|
|
2166
|
-
|
|
2252
|
+
const o = e.parse(i), c = o ? se(o) : void 0;
|
|
2253
|
+
t = c ? q.parseFromTypedEvent(c) : void 0;
|
|
2167
2254
|
} catch {
|
|
2168
2255
|
return [];
|
|
2169
2256
|
}
|
|
2170
|
-
if (!
|
|
2257
|
+
if (!t) return [];
|
|
2171
2258
|
const s = [];
|
|
2172
|
-
for (const
|
|
2173
|
-
if (
|
|
2174
|
-
const c =
|
|
2259
|
+
for (const o of t.parts ?? [])
|
|
2260
|
+
if (o.eventType === I.ToolEvent && ((n = o.toolDetails) == null ? void 0 : n.eventName) === vt) {
|
|
2261
|
+
const c = Et(o.toolDetails.eventData);
|
|
2175
2262
|
c && s.push({ kind: "todo", todoList: c });
|
|
2176
|
-
} else (
|
|
2263
|
+
} else (o.eventType === I.FunctionCall || o.eventType === I.PartialFunctionCall) && ((r = o.functionDetails) != null && r.name) ? s.push({ kind: "tool", name: o.functionDetails.name, interactionId: t.interactionId }) : o.eventType === I.Text && o.text && s.push({ kind: "text", text: o.text, partial: !!t.partial, interactionId: t.interactionId });
|
|
2177
2264
|
return s;
|
|
2178
2265
|
}
|
|
2179
|
-
h(
|
|
2180
|
-
function
|
|
2266
|
+
h(bt, "readDetachedRunActivity");
|
|
2267
|
+
function Et(i) {
|
|
2181
2268
|
if (!i) return null;
|
|
2182
2269
|
try {
|
|
2183
|
-
const
|
|
2184
|
-
return
|
|
2270
|
+
const e = JSON.parse(i);
|
|
2271
|
+
return e && Array.isArray(e.items) ? e : null;
|
|
2185
2272
|
} catch {
|
|
2186
2273
|
return null;
|
|
2187
2274
|
}
|
|
2188
2275
|
}
|
|
2189
|
-
h(
|
|
2276
|
+
h(Et, "parseTodoList");
|
|
2190
2277
|
export {
|
|
2191
|
-
|
|
2278
|
+
ye as A,
|
|
2192
2279
|
V as C,
|
|
2193
2280
|
L as D,
|
|
2194
|
-
|
|
2195
|
-
|
|
2281
|
+
Te as E,
|
|
2282
|
+
Ce as H,
|
|
2196
2283
|
_ as I,
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2284
|
+
Ie as L,
|
|
2285
|
+
Qe as M,
|
|
2286
|
+
vt as T,
|
|
2287
|
+
at as W,
|
|
2288
|
+
Ae as a,
|
|
2202
2289
|
j as b,
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2290
|
+
Me as c,
|
|
2291
|
+
wt as d,
|
|
2292
|
+
tt as e,
|
|
2293
|
+
bt as r,
|
|
2294
|
+
yt as s,
|
|
2295
|
+
mt as t,
|
|
2296
|
+
Rt as u
|
|
2210
2297
|
};
|
|
2211
|
-
//# sourceMappingURL=detachedRunActivity-
|
|
2298
|
+
//# sourceMappingURL=detachedRunActivity-CCrlilHK.js.map
|