happy-imou-cloud 2.0.9 → 2.0.11
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/BaseReasoningProcessor-5ACv9gKu.mjs +320 -0
- package/dist/BaseReasoningProcessor-COrRWyn0.cjs +323 -0
- package/dist/ProviderSelectionHandler-BljOLMQn.mjs +261 -0
- package/dist/ProviderSelectionHandler-DBGobhGZ.cjs +265 -0
- package/dist/{api-CnvyGas2.mjs → api-BcWf5v4i.mjs} +174 -46
- package/dist/{api-CUTdFiFP.cjs → api-Ye-rPX6s.cjs} +215 -87
- package/dist/{command-DLAJZsKX.cjs → command-BK93nizl.cjs} +6 -6
- package/dist/{command-BGA3qCKR.mjs → command-nOI80Mnm.mjs} +6 -6
- package/dist/{index-BpZL4RcT.mjs → index-DnsqY6I_.mjs} +871 -148
- package/dist/{index-D4OdFq68.cjs → index-J7QKJ8lc.cjs} +955 -228
- package/dist/index.cjs +8 -8
- package/dist/index.mjs +8 -8
- package/dist/lib.cjs +2 -3
- package/dist/lib.d.cts +2 -0
- package/dist/lib.d.mts +2 -0
- package/dist/lib.mjs +2 -3
- package/dist/{persistence-BPV3AmJL.mjs → persistence-BMa6cyw9.mjs} +2 -3
- package/dist/{persistence-CxvL0cwp.cjs → persistence-xK5CKhbn.cjs} +30 -31
- package/dist/registerKillSessionHandler-CH6yN0eG.cjs +1198 -0
- package/dist/registerKillSessionHandler-Dxwg4L4J.mjs +1179 -0
- package/dist/{runClaude-KwIVwFp1.cjs → runClaude-BMHlBny_.cjs} +904 -427
- package/dist/{runClaude-8inO7C5p.mjs → runClaude-cQ-UT0Ke.mjs} +883 -406
- package/dist/{runCodex-BQ-fN5E6.mjs → runCodex-AnJUPIhX.mjs} +160 -584
- package/dist/{runCodex-Ba8COxZe.cjs → runCodex-roOSOWWL.cjs} +163 -589
- package/dist/{runGemini-BE0FizuV.mjs → runGemini-BGo_0mzA.mjs} +142 -396
- package/dist/{runGemini-DtdLLX9o.cjs → runGemini-Cg6Zbqlz.cjs} +145 -399
- package/package.json +9 -8
- package/scripts/e2e/fake-codex-acp-agent.mjs +139 -0
- package/scripts/e2e/local-server-session-roundtrip.mjs +1063 -0
- package/scripts/release-smoke.mjs +23 -6
- package/dist/names-C9iJODqA.mjs +0 -625
- package/dist/names-YEhZwVT0.cjs +0 -636
- package/dist/registerKillSessionHandler-C2O8b5wH.mjs +0 -454
- package/dist/registerKillSessionHandler-rqd7duc9.cjs +0 -459
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { l as logger } from './api-BcWf5v4i.mjs';
|
|
2
|
+
import { g as getPendingInteractionTimeoutMs, I as INTERACTION_SUPERSEDED_ERROR, a as INTERACTION_TIMED_OUT_ERROR } from './registerKillSessionHandler-Dxwg4L4J.mjs';
|
|
3
|
+
|
|
4
|
+
async function runModeLoop(opts) {
|
|
5
|
+
let currentMode = opts.startingMode;
|
|
6
|
+
if (opts.notifyInitialMode) {
|
|
7
|
+
await opts.onModeChange?.(currentMode);
|
|
8
|
+
}
|
|
9
|
+
while (true) {
|
|
10
|
+
opts.onIteration?.(currentMode);
|
|
11
|
+
const result = await opts.launchers[currentMode]();
|
|
12
|
+
if (result.type === "exit") {
|
|
13
|
+
return result.value;
|
|
14
|
+
}
|
|
15
|
+
currentMode = result.mode;
|
|
16
|
+
await opts.onModeChange?.(currentMode);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function createKeepAliveController(opts) {
|
|
21
|
+
let thinking = opts.initialThinking ?? false;
|
|
22
|
+
let mode = opts.initialMode;
|
|
23
|
+
let disposed = false;
|
|
24
|
+
const sync = () => {
|
|
25
|
+
if (disposed) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
opts.send(thinking, mode);
|
|
29
|
+
};
|
|
30
|
+
sync();
|
|
31
|
+
const intervalId = setInterval(sync, opts.intervalMs ?? 2e3);
|
|
32
|
+
return {
|
|
33
|
+
dispose: () => {
|
|
34
|
+
if (disposed) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
disposed = true;
|
|
38
|
+
clearInterval(intervalId);
|
|
39
|
+
},
|
|
40
|
+
getMode: () => mode,
|
|
41
|
+
getThinking: () => thinking,
|
|
42
|
+
setMode: (nextMode) => {
|
|
43
|
+
mode = nextMode;
|
|
44
|
+
sync();
|
|
45
|
+
},
|
|
46
|
+
setThinking: (nextThinking) => {
|
|
47
|
+
thinking = nextThinking;
|
|
48
|
+
sync();
|
|
49
|
+
},
|
|
50
|
+
sync
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
class ProviderSelectionHandler {
|
|
55
|
+
pendingRequests = /* @__PURE__ */ new Map();
|
|
56
|
+
session;
|
|
57
|
+
providerLabel;
|
|
58
|
+
constructor(session, providerLabel) {
|
|
59
|
+
this.session = session;
|
|
60
|
+
this.providerLabel = providerLabel;
|
|
61
|
+
this.setupRpcHandler();
|
|
62
|
+
}
|
|
63
|
+
updateSession(newSession) {
|
|
64
|
+
this.session = newSession;
|
|
65
|
+
this.setupRpcHandler();
|
|
66
|
+
}
|
|
67
|
+
async requestSelection(request) {
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
const pending = {
|
|
70
|
+
resolve,
|
|
71
|
+
reject,
|
|
72
|
+
request
|
|
73
|
+
};
|
|
74
|
+
pending.timeoutHandle = setTimeout(() => {
|
|
75
|
+
this.handleSelectionTimeout(request.id, pending);
|
|
76
|
+
}, getPendingInteractionTimeoutMs());
|
|
77
|
+
this.pendingRequests.set(request.id, pending);
|
|
78
|
+
this.session.updateAgentState((currentState) => ({
|
|
79
|
+
...currentState,
|
|
80
|
+
requests: {
|
|
81
|
+
...currentState.requests,
|
|
82
|
+
[request.id]: {
|
|
83
|
+
tool: "AskUserQuestion",
|
|
84
|
+
arguments: {
|
|
85
|
+
requestKind: "selection",
|
|
86
|
+
questions: [
|
|
87
|
+
{
|
|
88
|
+
header: this.providerLabel,
|
|
89
|
+
question: request.message,
|
|
90
|
+
multiSelect: false,
|
|
91
|
+
options: request.options.map((option) => ({
|
|
92
|
+
label: option.label,
|
|
93
|
+
description: option.description || option.optionId,
|
|
94
|
+
optionId: option.optionId
|
|
95
|
+
}))
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
},
|
|
99
|
+
createdAt: Date.now(),
|
|
100
|
+
requestKind: "selection",
|
|
101
|
+
options: request.options,
|
|
102
|
+
defaultOptionId: request.defaultOptionId
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}));
|
|
106
|
+
logger.debug(`[${this.providerLabel}] Selection request sent (${request.id}) with ${request.options.length} options`);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
hasPendingRequests() {
|
|
110
|
+
return this.pendingRequests.size > 0;
|
|
111
|
+
}
|
|
112
|
+
supersedePendingRequests(reason = INTERACTION_SUPERSEDED_ERROR) {
|
|
113
|
+
const pendingSnapshot = Array.from(this.pendingRequests.entries());
|
|
114
|
+
if (pendingSnapshot.length === 0) {
|
|
115
|
+
return 0;
|
|
116
|
+
}
|
|
117
|
+
this.pendingRequests.clear();
|
|
118
|
+
const completedAt = Date.now();
|
|
119
|
+
for (const [, pending] of pendingSnapshot) {
|
|
120
|
+
this.clearPendingRequestTimeout(pending);
|
|
121
|
+
pending.reject(new Error(reason));
|
|
122
|
+
}
|
|
123
|
+
this.session.updateAgentState((currentState) => {
|
|
124
|
+
const requests = { ...currentState.requests || {} };
|
|
125
|
+
const completedRequests = { ...currentState.completedRequests || {} };
|
|
126
|
+
for (const [id, request] of Object.entries(requests)) {
|
|
127
|
+
if (request.requestKind !== "selection") {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
completedRequests[id] = {
|
|
131
|
+
...request,
|
|
132
|
+
completedAt,
|
|
133
|
+
status: "canceled",
|
|
134
|
+
reason,
|
|
135
|
+
requestKind: "selection"
|
|
136
|
+
};
|
|
137
|
+
delete requests[id];
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
...currentState,
|
|
141
|
+
requests,
|
|
142
|
+
completedRequests
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
logger.debug(`[${this.providerLabel}] Superseded ${pendingSnapshot.length} pending selection request(s)`);
|
|
146
|
+
return pendingSnapshot.length;
|
|
147
|
+
}
|
|
148
|
+
reset(reason = "Session reset") {
|
|
149
|
+
const pendingSnapshot = Array.from(this.pendingRequests.entries());
|
|
150
|
+
this.pendingRequests.clear();
|
|
151
|
+
for (const [, pending] of pendingSnapshot) {
|
|
152
|
+
this.clearPendingRequestTimeout(pending);
|
|
153
|
+
pending.reject(new Error(reason));
|
|
154
|
+
}
|
|
155
|
+
this.session.updateAgentState((currentState) => {
|
|
156
|
+
const requests = { ...currentState.requests || {} };
|
|
157
|
+
const completedRequests = { ...currentState.completedRequests || {} };
|
|
158
|
+
for (const [id, request] of Object.entries(requests)) {
|
|
159
|
+
if (request.requestKind !== "selection") {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
completedRequests[id] = {
|
|
163
|
+
...request,
|
|
164
|
+
completedAt: Date.now(),
|
|
165
|
+
status: "canceled",
|
|
166
|
+
reason,
|
|
167
|
+
requestKind: "selection"
|
|
168
|
+
};
|
|
169
|
+
delete requests[id];
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
...currentState,
|
|
173
|
+
requests,
|
|
174
|
+
completedRequests
|
|
175
|
+
};
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
setupRpcHandler() {
|
|
179
|
+
this.session.rpcHandlerManager.registerHandler("selection", async (response) => {
|
|
180
|
+
const pending = this.pendingRequests.get(response.id);
|
|
181
|
+
if (!pending) {
|
|
182
|
+
logger.debug(`[${this.providerLabel}] Selection request not found or already resolved`);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
this.pendingRequests.delete(response.id);
|
|
186
|
+
this.clearPendingRequestTimeout(pending);
|
|
187
|
+
pending.resolve(response);
|
|
188
|
+
this.session.updateAgentState((currentState) => {
|
|
189
|
+
const request = currentState.requests?.[response.id];
|
|
190
|
+
if (!request) {
|
|
191
|
+
return currentState;
|
|
192
|
+
}
|
|
193
|
+
const { [response.id]: _, ...remainingRequests } = currentState.requests || {};
|
|
194
|
+
return {
|
|
195
|
+
...currentState,
|
|
196
|
+
requests: remainingRequests,
|
|
197
|
+
completedRequests: {
|
|
198
|
+
...currentState.completedRequests,
|
|
199
|
+
[response.id]: {
|
|
200
|
+
...request,
|
|
201
|
+
completedAt: Date.now(),
|
|
202
|
+
status: "approved",
|
|
203
|
+
requestKind: "selection",
|
|
204
|
+
selectedOptionId: response.optionId
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
clearPendingRequestTimeout(pending) {
|
|
212
|
+
if (pending?.timeoutHandle) {
|
|
213
|
+
clearTimeout(pending.timeoutHandle);
|
|
214
|
+
pending.timeoutHandle = void 0;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
handleSelectionTimeout(requestId, pending) {
|
|
218
|
+
const active = this.pendingRequests.get(requestId);
|
|
219
|
+
if (!active || active !== pending) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
this.pendingRequests.delete(requestId);
|
|
223
|
+
this.clearPendingRequestTimeout(active);
|
|
224
|
+
active.reject(new Error(INTERACTION_TIMED_OUT_ERROR));
|
|
225
|
+
this.session.updateAgentState((currentState) => {
|
|
226
|
+
const request = currentState.requests?.[requestId] || {
|
|
227
|
+
tool: "AskUserQuestion",
|
|
228
|
+
arguments: {
|
|
229
|
+
requestKind: "selection",
|
|
230
|
+
questions: []
|
|
231
|
+
},
|
|
232
|
+
createdAt: Date.now(),
|
|
233
|
+
requestKind: "selection",
|
|
234
|
+
options: active.request.options,
|
|
235
|
+
defaultOptionId: active.request.defaultOptionId
|
|
236
|
+
};
|
|
237
|
+
const { [requestId]: _, ...remainingRequests } = currentState.requests || {};
|
|
238
|
+
return {
|
|
239
|
+
...currentState,
|
|
240
|
+
requests: remainingRequests,
|
|
241
|
+
completedRequests: {
|
|
242
|
+
...currentState.completedRequests,
|
|
243
|
+
[requestId]: {
|
|
244
|
+
...request,
|
|
245
|
+
completedAt: Date.now(),
|
|
246
|
+
status: "canceled",
|
|
247
|
+
reason: INTERACTION_TIMED_OUT_ERROR,
|
|
248
|
+
requestKind: "selection"
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
});
|
|
253
|
+
this.session.sendSessionEvent({
|
|
254
|
+
type: "message",
|
|
255
|
+
message: "Pending interaction timed out waiting for a response. Send a new message to continue."
|
|
256
|
+
});
|
|
257
|
+
logger.debug(`[${this.providerLabel}] Selection request timed out (${requestId})`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export { ProviderSelectionHandler as P, createKeepAliveController as c, runModeLoop as r };
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var api = require('./api-Ye-rPX6s.cjs');
|
|
4
|
+
var registerKillSessionHandler = require('./registerKillSessionHandler-CH6yN0eG.cjs');
|
|
5
|
+
|
|
6
|
+
async function runModeLoop(opts) {
|
|
7
|
+
let currentMode = opts.startingMode;
|
|
8
|
+
if (opts.notifyInitialMode) {
|
|
9
|
+
await opts.onModeChange?.(currentMode);
|
|
10
|
+
}
|
|
11
|
+
while (true) {
|
|
12
|
+
opts.onIteration?.(currentMode);
|
|
13
|
+
const result = await opts.launchers[currentMode]();
|
|
14
|
+
if (result.type === "exit") {
|
|
15
|
+
return result.value;
|
|
16
|
+
}
|
|
17
|
+
currentMode = result.mode;
|
|
18
|
+
await opts.onModeChange?.(currentMode);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function createKeepAliveController(opts) {
|
|
23
|
+
let thinking = opts.initialThinking ?? false;
|
|
24
|
+
let mode = opts.initialMode;
|
|
25
|
+
let disposed = false;
|
|
26
|
+
const sync = () => {
|
|
27
|
+
if (disposed) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
opts.send(thinking, mode);
|
|
31
|
+
};
|
|
32
|
+
sync();
|
|
33
|
+
const intervalId = setInterval(sync, opts.intervalMs ?? 2e3);
|
|
34
|
+
return {
|
|
35
|
+
dispose: () => {
|
|
36
|
+
if (disposed) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
disposed = true;
|
|
40
|
+
clearInterval(intervalId);
|
|
41
|
+
},
|
|
42
|
+
getMode: () => mode,
|
|
43
|
+
getThinking: () => thinking,
|
|
44
|
+
setMode: (nextMode) => {
|
|
45
|
+
mode = nextMode;
|
|
46
|
+
sync();
|
|
47
|
+
},
|
|
48
|
+
setThinking: (nextThinking) => {
|
|
49
|
+
thinking = nextThinking;
|
|
50
|
+
sync();
|
|
51
|
+
},
|
|
52
|
+
sync
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
class ProviderSelectionHandler {
|
|
57
|
+
pendingRequests = /* @__PURE__ */ new Map();
|
|
58
|
+
session;
|
|
59
|
+
providerLabel;
|
|
60
|
+
constructor(session, providerLabel) {
|
|
61
|
+
this.session = session;
|
|
62
|
+
this.providerLabel = providerLabel;
|
|
63
|
+
this.setupRpcHandler();
|
|
64
|
+
}
|
|
65
|
+
updateSession(newSession) {
|
|
66
|
+
this.session = newSession;
|
|
67
|
+
this.setupRpcHandler();
|
|
68
|
+
}
|
|
69
|
+
async requestSelection(request) {
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
const pending = {
|
|
72
|
+
resolve,
|
|
73
|
+
reject,
|
|
74
|
+
request
|
|
75
|
+
};
|
|
76
|
+
pending.timeoutHandle = setTimeout(() => {
|
|
77
|
+
this.handleSelectionTimeout(request.id, pending);
|
|
78
|
+
}, registerKillSessionHandler.getPendingInteractionTimeoutMs());
|
|
79
|
+
this.pendingRequests.set(request.id, pending);
|
|
80
|
+
this.session.updateAgentState((currentState) => ({
|
|
81
|
+
...currentState,
|
|
82
|
+
requests: {
|
|
83
|
+
...currentState.requests,
|
|
84
|
+
[request.id]: {
|
|
85
|
+
tool: "AskUserQuestion",
|
|
86
|
+
arguments: {
|
|
87
|
+
requestKind: "selection",
|
|
88
|
+
questions: [
|
|
89
|
+
{
|
|
90
|
+
header: this.providerLabel,
|
|
91
|
+
question: request.message,
|
|
92
|
+
multiSelect: false,
|
|
93
|
+
options: request.options.map((option) => ({
|
|
94
|
+
label: option.label,
|
|
95
|
+
description: option.description || option.optionId,
|
|
96
|
+
optionId: option.optionId
|
|
97
|
+
}))
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
},
|
|
101
|
+
createdAt: Date.now(),
|
|
102
|
+
requestKind: "selection",
|
|
103
|
+
options: request.options,
|
|
104
|
+
defaultOptionId: request.defaultOptionId
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}));
|
|
108
|
+
api.logger.debug(`[${this.providerLabel}] Selection request sent (${request.id}) with ${request.options.length} options`);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
hasPendingRequests() {
|
|
112
|
+
return this.pendingRequests.size > 0;
|
|
113
|
+
}
|
|
114
|
+
supersedePendingRequests(reason = registerKillSessionHandler.INTERACTION_SUPERSEDED_ERROR) {
|
|
115
|
+
const pendingSnapshot = Array.from(this.pendingRequests.entries());
|
|
116
|
+
if (pendingSnapshot.length === 0) {
|
|
117
|
+
return 0;
|
|
118
|
+
}
|
|
119
|
+
this.pendingRequests.clear();
|
|
120
|
+
const completedAt = Date.now();
|
|
121
|
+
for (const [, pending] of pendingSnapshot) {
|
|
122
|
+
this.clearPendingRequestTimeout(pending);
|
|
123
|
+
pending.reject(new Error(reason));
|
|
124
|
+
}
|
|
125
|
+
this.session.updateAgentState((currentState) => {
|
|
126
|
+
const requests = { ...currentState.requests || {} };
|
|
127
|
+
const completedRequests = { ...currentState.completedRequests || {} };
|
|
128
|
+
for (const [id, request] of Object.entries(requests)) {
|
|
129
|
+
if (request.requestKind !== "selection") {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
completedRequests[id] = {
|
|
133
|
+
...request,
|
|
134
|
+
completedAt,
|
|
135
|
+
status: "canceled",
|
|
136
|
+
reason,
|
|
137
|
+
requestKind: "selection"
|
|
138
|
+
};
|
|
139
|
+
delete requests[id];
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
...currentState,
|
|
143
|
+
requests,
|
|
144
|
+
completedRequests
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
api.logger.debug(`[${this.providerLabel}] Superseded ${pendingSnapshot.length} pending selection request(s)`);
|
|
148
|
+
return pendingSnapshot.length;
|
|
149
|
+
}
|
|
150
|
+
reset(reason = "Session reset") {
|
|
151
|
+
const pendingSnapshot = Array.from(this.pendingRequests.entries());
|
|
152
|
+
this.pendingRequests.clear();
|
|
153
|
+
for (const [, pending] of pendingSnapshot) {
|
|
154
|
+
this.clearPendingRequestTimeout(pending);
|
|
155
|
+
pending.reject(new Error(reason));
|
|
156
|
+
}
|
|
157
|
+
this.session.updateAgentState((currentState) => {
|
|
158
|
+
const requests = { ...currentState.requests || {} };
|
|
159
|
+
const completedRequests = { ...currentState.completedRequests || {} };
|
|
160
|
+
for (const [id, request] of Object.entries(requests)) {
|
|
161
|
+
if (request.requestKind !== "selection") {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
completedRequests[id] = {
|
|
165
|
+
...request,
|
|
166
|
+
completedAt: Date.now(),
|
|
167
|
+
status: "canceled",
|
|
168
|
+
reason,
|
|
169
|
+
requestKind: "selection"
|
|
170
|
+
};
|
|
171
|
+
delete requests[id];
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
...currentState,
|
|
175
|
+
requests,
|
|
176
|
+
completedRequests
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
setupRpcHandler() {
|
|
181
|
+
this.session.rpcHandlerManager.registerHandler("selection", async (response) => {
|
|
182
|
+
const pending = this.pendingRequests.get(response.id);
|
|
183
|
+
if (!pending) {
|
|
184
|
+
api.logger.debug(`[${this.providerLabel}] Selection request not found or already resolved`);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
this.pendingRequests.delete(response.id);
|
|
188
|
+
this.clearPendingRequestTimeout(pending);
|
|
189
|
+
pending.resolve(response);
|
|
190
|
+
this.session.updateAgentState((currentState) => {
|
|
191
|
+
const request = currentState.requests?.[response.id];
|
|
192
|
+
if (!request) {
|
|
193
|
+
return currentState;
|
|
194
|
+
}
|
|
195
|
+
const { [response.id]: _, ...remainingRequests } = currentState.requests || {};
|
|
196
|
+
return {
|
|
197
|
+
...currentState,
|
|
198
|
+
requests: remainingRequests,
|
|
199
|
+
completedRequests: {
|
|
200
|
+
...currentState.completedRequests,
|
|
201
|
+
[response.id]: {
|
|
202
|
+
...request,
|
|
203
|
+
completedAt: Date.now(),
|
|
204
|
+
status: "approved",
|
|
205
|
+
requestKind: "selection",
|
|
206
|
+
selectedOptionId: response.optionId
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
clearPendingRequestTimeout(pending) {
|
|
214
|
+
if (pending?.timeoutHandle) {
|
|
215
|
+
clearTimeout(pending.timeoutHandle);
|
|
216
|
+
pending.timeoutHandle = void 0;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
handleSelectionTimeout(requestId, pending) {
|
|
220
|
+
const active = this.pendingRequests.get(requestId);
|
|
221
|
+
if (!active || active !== pending) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
this.pendingRequests.delete(requestId);
|
|
225
|
+
this.clearPendingRequestTimeout(active);
|
|
226
|
+
active.reject(new Error(registerKillSessionHandler.INTERACTION_TIMED_OUT_ERROR));
|
|
227
|
+
this.session.updateAgentState((currentState) => {
|
|
228
|
+
const request = currentState.requests?.[requestId] || {
|
|
229
|
+
tool: "AskUserQuestion",
|
|
230
|
+
arguments: {
|
|
231
|
+
requestKind: "selection",
|
|
232
|
+
questions: []
|
|
233
|
+
},
|
|
234
|
+
createdAt: Date.now(),
|
|
235
|
+
requestKind: "selection",
|
|
236
|
+
options: active.request.options,
|
|
237
|
+
defaultOptionId: active.request.defaultOptionId
|
|
238
|
+
};
|
|
239
|
+
const { [requestId]: _, ...remainingRequests } = currentState.requests || {};
|
|
240
|
+
return {
|
|
241
|
+
...currentState,
|
|
242
|
+
requests: remainingRequests,
|
|
243
|
+
completedRequests: {
|
|
244
|
+
...currentState.completedRequests,
|
|
245
|
+
[requestId]: {
|
|
246
|
+
...request,
|
|
247
|
+
completedAt: Date.now(),
|
|
248
|
+
status: "canceled",
|
|
249
|
+
reason: registerKillSessionHandler.INTERACTION_TIMED_OUT_ERROR,
|
|
250
|
+
requestKind: "selection"
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
});
|
|
255
|
+
this.session.sendSessionEvent({
|
|
256
|
+
type: "message",
|
|
257
|
+
message: "Pending interaction timed out waiting for a response. Send a new message to continue."
|
|
258
|
+
});
|
|
259
|
+
api.logger.debug(`[${this.providerLabel}] Selection request timed out (${requestId})`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
exports.ProviderSelectionHandler = ProviderSelectionHandler;
|
|
264
|
+
exports.createKeepAliveController = createKeepAliveController;
|
|
265
|
+
exports.runModeLoop = runModeLoop;
|