dsh-monkeyai-sessions 0.1.16 → 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 +34 -14
package/package.json
CHANGED
|
@@ -792,8 +792,12 @@ export class MonkeyAIRemoteService extends TypertRemoteService {
|
|
|
792
792
|
newReplayKeysThisConnection = 0
|
|
793
793
|
const unsubscribeThis = acp.subscribe(event => {
|
|
794
794
|
if (currentAcp !== acp) return
|
|
795
|
-
if (event.params?.sessionId !== selectedSession) return
|
|
796
795
|
if (event.kind === 'request') {
|
|
796
|
+
const requestSessionId = event.params?.sessionId
|
|
797
|
+
const sessionlessQuestion = requestSessionId === undefined && event.method === 'elicitation/create'
|
|
798
|
+
// elicitation/create follows the MCP request shape and may omit the
|
|
799
|
+
// ACP session id. This socket is already bound to selectedSession.
|
|
800
|
+
if (requestSessionId !== selectedSession && !sessionlessQuestion) return
|
|
797
801
|
if (pendingRequests.size >= 64) {
|
|
798
802
|
const reason = new Error('Remote session has too many pending requests')
|
|
799
803
|
controller.abort(reason)
|
|
@@ -809,6 +813,7 @@ export class MonkeyAIRemoteService extends TypertRemoteService {
|
|
|
809
813
|
data: event.params,
|
|
810
814
|
})
|
|
811
815
|
} else {
|
|
816
|
+
if (event.params?.sessionId !== selectedSession) return
|
|
812
817
|
if (event.method === '_monkeyai/session/history_changed' && httpHistoryComplete && ticketHttpBase) {
|
|
813
818
|
// Large live message bodies are persisted instead of streamed as
|
|
814
819
|
// chunks. Match the desktop client: refresh the newest HTTP pages
|
|
@@ -1113,6 +1118,7 @@ export class MonkeyAIRemoteService extends TypertRemoteService {
|
|
|
1113
1118
|
const uplink = this.ctx.invocation?.uplink()
|
|
1114
1119
|
if (!uplink) throw new Error('Remote session command channel is unavailable')
|
|
1115
1120
|
uplinkIterator = uplink[Symbol.asyncIterator]()
|
|
1121
|
+
let promptInFlight = false
|
|
1116
1122
|
|
|
1117
1123
|
commandPump = (async () => {
|
|
1118
1124
|
while (!signal.aborted) {
|
|
@@ -1167,24 +1173,38 @@ export class MonkeyAIRemoteService extends TypertRemoteService {
|
|
|
1167
1173
|
}
|
|
1168
1174
|
|
|
1169
1175
|
if (command.type === 'prompt') {
|
|
1170
|
-
|
|
1171
|
-
// session/prompt resolves only when the whole turn finishes;
|
|
1172
|
-
// long turns on big sessions can take many minutes. Streamed
|
|
1173
|
-
// session/update frames reach the panel while it runs.
|
|
1174
|
-
const result = await currentAcp.request('session/prompt', {
|
|
1175
|
-
sessionId: selectedSession,
|
|
1176
|
-
prompt: [{ type: 'text', text: command.text }],
|
|
1177
|
-
}, { signal, timeoutMs: 1_800_000 })
|
|
1178
|
-
emit({ type: 'delivery', sessionId: selectedSession, data: { accepted: true, result } })
|
|
1179
|
-
} catch (promptError) {
|
|
1180
|
-
if (signal.aborted) return
|
|
1176
|
+
if (promptInFlight) {
|
|
1181
1177
|
emit({
|
|
1182
1178
|
type: 'delivery',
|
|
1183
1179
|
sessionId: selectedSession,
|
|
1184
|
-
data: { accepted: false, code: '
|
|
1185
|
-
message:
|
|
1180
|
+
data: { accepted: false, code: 'turn_in_progress' },
|
|
1181
|
+
message: '当前回合仍在执行,请等待完成后再下发新指令',
|
|
1186
1182
|
})
|
|
1183
|
+
continue
|
|
1187
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
|
+
})()
|
|
1188
1208
|
continue
|
|
1189
1209
|
}
|
|
1190
1210
|
|