dsh-monkeyai-sessions 0.1.17 → 0.1.18
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/package.json +1 -1
- package/src/host/monkeyai-remote.js +28 -13
package/package.json
CHANGED
|
@@ -1118,6 +1118,7 @@ export class MonkeyAIRemoteService extends TypertRemoteService {
|
|
|
1118
1118
|
const uplink = this.ctx.invocation?.uplink()
|
|
1119
1119
|
if (!uplink) throw new Error('Remote session command channel is unavailable')
|
|
1120
1120
|
uplinkIterator = uplink[Symbol.asyncIterator]()
|
|
1121
|
+
let promptInFlight = false
|
|
1121
1122
|
|
|
1122
1123
|
commandPump = (async () => {
|
|
1123
1124
|
while (!signal.aborted) {
|
|
@@ -1172,24 +1173,38 @@ export class MonkeyAIRemoteService extends TypertRemoteService {
|
|
|
1172
1173
|
}
|
|
1173
1174
|
|
|
1174
1175
|
if (command.type === 'prompt') {
|
|
1175
|
-
|
|
1176
|
-
// session/prompt resolves only when the whole turn finishes;
|
|
1177
|
-
// long turns on big sessions can take many minutes. Streamed
|
|
1178
|
-
// session/update frames reach the panel while it runs.
|
|
1179
|
-
const result = await currentAcp.request('session/prompt', {
|
|
1180
|
-
sessionId: selectedSession,
|
|
1181
|
-
prompt: [{ type: 'text', text: command.text }],
|
|
1182
|
-
}, { signal, timeoutMs: 1_800_000 })
|
|
1183
|
-
emit({ type: 'delivery', sessionId: selectedSession, data: { accepted: true, result } })
|
|
1184
|
-
} catch (promptError) {
|
|
1185
|
-
if (signal.aborted) return
|
|
1176
|
+
if (promptInFlight) {
|
|
1186
1177
|
emit({
|
|
1187
1178
|
type: 'delivery',
|
|
1188
1179
|
sessionId: selectedSession,
|
|
1189
|
-
data: { accepted: false, code: '
|
|
1190
|
-
message:
|
|
1180
|
+
data: { accepted: false, code: 'turn_in_progress' },
|
|
1181
|
+
message: '当前回合仍在执行,请等待完成后再下发新指令',
|
|
1191
1182
|
})
|
|
1183
|
+
continue
|
|
1192
1184
|
}
|
|
1185
|
+
promptInFlight = true
|
|
1186
|
+
const promptAcp = currentAcp
|
|
1187
|
+
void (async () => {
|
|
1188
|
+
try {
|
|
1189
|
+
// Let the command pump process answers and cancellation while
|
|
1190
|
+
// session/prompt waits for the remote turn to finish.
|
|
1191
|
+
const result = await promptAcp.request('session/prompt', {
|
|
1192
|
+
sessionId: selectedSession,
|
|
1193
|
+
prompt: [{ type: 'text', text: command.text }],
|
|
1194
|
+
}, { signal, timeoutMs: 1_800_000 })
|
|
1195
|
+
emit({ type: 'delivery', sessionId: selectedSession, data: { accepted: true, result } })
|
|
1196
|
+
} catch (promptError) {
|
|
1197
|
+
if (signal.aborted) return
|
|
1198
|
+
emit({
|
|
1199
|
+
type: 'delivery',
|
|
1200
|
+
sessionId: selectedSession,
|
|
1201
|
+
data: { accepted: false, code: 'remote_rejected' },
|
|
1202
|
+
message: promptError instanceof Error ? promptError.message : '远程 runtime 拒绝了该指令',
|
|
1203
|
+
})
|
|
1204
|
+
} finally {
|
|
1205
|
+
promptInFlight = false
|
|
1206
|
+
}
|
|
1207
|
+
})()
|
|
1193
1208
|
continue
|
|
1194
1209
|
}
|
|
1195
1210
|
|