@ai-workbench/remote-agent 0.9.0-toolbridge.2 → 0.9.0-toolbridge.20
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/README.md +23 -8
- package/dist/acp.d.ts +13 -1
- package/dist/acp.js +101 -16
- package/dist/broker-runtime.d.ts +2 -0
- package/dist/broker-runtime.js +52 -3
- package/dist/broker.d.ts +56 -1
- package/dist/broker.js +300 -10
- package/dist/claude-local.js +26 -5
- package/dist/client.js +1 -1
- package/dist/close-diagnostics.d.ts +1 -1
- package/dist/close-diagnostics.js +1 -1
- package/dist/cold-protocol.d.ts +17 -0
- package/dist/cold-protocol.js +358 -0
- package/dist/cold-recovery.d.ts +63 -0
- package/dist/cold-recovery.js +598 -0
- package/dist/cold-store.d.ts +100 -0
- package/dist/cold-store.js +29 -0
- package/dist/employee-endpoint.js +15 -1
- package/dist/employee-mcp.js +1 -1
- package/dist/employee-provider.js +26 -6
- package/dist/employee-relay.js +148 -1
- package/dist/employee-shell.d.ts +2 -0
- package/dist/employee-shell.js +22 -19
- package/dist/employee-tools.js +2 -2
- package/dist/employee-workspace.d.ts +20 -4
- package/dist/employee-workspace.js +26 -5
- package/dist/index.d.ts +12 -3
- package/dist/index.js +205 -40
- package/dist/input.js +4 -1
- package/dist/live-steering.d.ts +46 -0
- package/dist/live-steering.js +45 -0
- package/dist/model-catalog.d.ts +2 -0
- package/dist/model-catalog.js +5 -1
- package/dist/preflight-diagnostic.js +1 -1
- package/dist/presentation.js +1 -0
- package/dist/provider.d.ts +13 -0
- package/dist/rpc-namespace.js +16 -2
- package/dist/session-source.d.ts +3 -1
- package/dist/session-source.js +2 -1
- package/dist/toolbridge-loop.d.ts +3 -2
- package/dist/toolbridge-loop.js +4 -2
- package/dist/toolbridge-table.d.ts +4 -3
- package/dist/toolbridge-table.js +15 -5
- package/dist/toolbridge.d.ts +1 -1
- package/dist/toolbridge.js +4 -4
- package/package.json +23 -16
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
import { watch } from 'node:fs';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { lstat, realpath } from 'node:fs/promises';
|
|
4
|
+
import { modelInfo } from "./model-catalog.js";
|
|
5
|
+
import { SessionId } from '@deepseek-ai/dsh-session';
|
|
6
|
+
import { expandAssistantStream, createUserMessage } from '@deepseek-ai/dsh-llm';
|
|
7
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
8
|
+
import { createHash } from 'node:crypto';
|
|
9
|
+
import { createColdStore, coldNeed } from "./cold-store.js";
|
|
10
|
+
import { recoverColdProtocol, recoverLocalCancellation } from "./cold-protocol.js";
|
|
11
|
+
import { sameStoredSessionHeader } from "./session-header.js";
|
|
12
|
+
import { awaitL, identity, unwrap } from "./provider.js";
|
|
13
|
+
import { sshIo } from "./broker.js";
|
|
14
|
+
const sourceKind = 'ai-workbench-cold-recovery';
|
|
15
|
+
export const recoveryMarker = (message) => message?.role === 'user' && message.source?.kind === sourceKind && typeof message.source?.roundId === 'string' ? message.source.roundId : undefined;
|
|
16
|
+
// Reconstruct only official, exact claims. A turn may stop after inbox.claim
|
|
17
|
+
// and before either step/start or user/message has been appended.
|
|
18
|
+
function inputClaims(events) {
|
|
19
|
+
const queues = { 'next-step': [], 'next-turn': [] }, claims = new Map();
|
|
20
|
+
let turn;
|
|
21
|
+
const add = (owner, message) => { const items = claims.get(owner) ?? new Map(); items.set(message.id, message); claims.set(owner, items); };
|
|
22
|
+
for (const event of events) {
|
|
23
|
+
if (event.type === 'turn/start')
|
|
24
|
+
turn = event.data.turn;
|
|
25
|
+
else if (event.type === 'turn/end')
|
|
26
|
+
turn = undefined;
|
|
27
|
+
else if (event.type === 'user/message' && turn !== undefined)
|
|
28
|
+
add(turn, event.data);
|
|
29
|
+
else if (event.type === 'agent/inbox/spliced') {
|
|
30
|
+
const { target, start, removedCount = 0, inserted, outcome } = event.data, queue = queues[target];
|
|
31
|
+
if (!queue || !Number.isSafeInteger(start) || start < 0 || start > queue.length || !Number.isSafeInteger(removedCount) || removedCount < 0 || start + removedCount > queue.length)
|
|
32
|
+
throw coldNeed('SESSION_CONTEXT_MISMATCH');
|
|
33
|
+
const removed = queue.splice(start, removedCount, ...inserted);
|
|
34
|
+
if (turn !== undefined && outcome !== 'canceled')
|
|
35
|
+
for (const message of removed)
|
|
36
|
+
add(turn, message);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return claims;
|
|
40
|
+
}
|
|
41
|
+
const digest = (message) => createHash('sha256').update(JSON.stringify(message)).digest('hex');
|
|
42
|
+
export class ColdRecovery {
|
|
43
|
+
ctx;
|
|
44
|
+
getConnect;
|
|
45
|
+
config;
|
|
46
|
+
provided;
|
|
47
|
+
store;
|
|
48
|
+
queues = new WeakMap();
|
|
49
|
+
scheduled = new WeakMap();
|
|
50
|
+
live = new Map();
|
|
51
|
+
lifetime = new AbortController();
|
|
52
|
+
cancellationWatches = new Map();
|
|
53
|
+
steps = new Map();
|
|
54
|
+
constructor(ctx, getConnect, config, provided) {
|
|
55
|
+
this.ctx = ctx;
|
|
56
|
+
this.getConnect = getConnect;
|
|
57
|
+
this.config = config;
|
|
58
|
+
this.provided = provided;
|
|
59
|
+
this.store = provided?.store ?? createColdStore(ctx);
|
|
60
|
+
ctx.effect?.(() => () => this.dispose());
|
|
61
|
+
}
|
|
62
|
+
dispose() { this.lifetime.abort(Object.assign(new DOMException('原轮恢复已分离', 'AbortError'), { kind: 'disposed' })); for (const watch of this.cancellationWatches.values())
|
|
63
|
+
watch.off(); this.cancellationWatches.clear(); }
|
|
64
|
+
async events(sessionId, header) {
|
|
65
|
+
const sessions = this.ctx.get('sessions'), session = sessions?.get(SessionId(sessionId)), persistence = this.ctx.get('sessionPersistence');
|
|
66
|
+
if (!session || !persistence?.identity || !await sessions.flush(session))
|
|
67
|
+
throw coldNeed();
|
|
68
|
+
const handle = await persistence.open(session.id, 'read');
|
|
69
|
+
try {
|
|
70
|
+
if (handle.id !== session.id || handle.access !== 'read' || !sameStoredSessionHeader(handle.header, session.header) || header && !sameStoredSessionHeader(handle.header, header))
|
|
71
|
+
throw coldNeed('SESSION_CONTEXT_MISMATCH');
|
|
72
|
+
const result = await handle.read();
|
|
73
|
+
return result.events;
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
await handle.close();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async capture(runtime, options, nativeId, meta) {
|
|
80
|
+
if (!runtime.cold || !options.sessionId)
|
|
81
|
+
return;
|
|
82
|
+
const session = this.ctx.get('sessions')?.get(SessionId(options.sessionId));
|
|
83
|
+
if (!session)
|
|
84
|
+
throw coldNeed();
|
|
85
|
+
if (this.provided?.readSource && !isDeepStrictEqual(meta.hostSource ?? { source: 'local' }, await this.provided.readSource(options.sessionId)))
|
|
86
|
+
throw coldNeed('SESSION_CONTEXT_MISMATCH');
|
|
87
|
+
const events = await this.events(options.sessionId), header = structuredClone(session.header);
|
|
88
|
+
let turn, step;
|
|
89
|
+
for (const e of events) {
|
|
90
|
+
if (e.type === 'turn/start') {
|
|
91
|
+
turn = e.data.turn;
|
|
92
|
+
step = undefined;
|
|
93
|
+
}
|
|
94
|
+
else if (e.type === 'step/start') {
|
|
95
|
+
step = e.data.step;
|
|
96
|
+
}
|
|
97
|
+
else if (e.type === 'turn/end') {
|
|
98
|
+
turn = undefined;
|
|
99
|
+
step = undefined;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (turn === undefined || step === undefined)
|
|
103
|
+
throw coldNeed();
|
|
104
|
+
let t, s;
|
|
105
|
+
const inputs = [];
|
|
106
|
+
for (const e of events) {
|
|
107
|
+
if (e.type === 'turn/start')
|
|
108
|
+
t = e.data.turn;
|
|
109
|
+
else if (e.type === 'step/start')
|
|
110
|
+
s = e.data.step;
|
|
111
|
+
else if (e.type === 'user/message' && t === turn && s === step)
|
|
112
|
+
inputs.push(e.data);
|
|
113
|
+
}
|
|
114
|
+
const inputDigests = Object.fromEntries(inputs.map(m => [m.id, digest(m)]));
|
|
115
|
+
if (!inputs.length)
|
|
116
|
+
throw coldNeed();
|
|
117
|
+
const { provider, model, reasoningEffort, temperature, maxTokens, stop } = options;
|
|
118
|
+
await runtime.cold.prepare(nativeId, { ...meta, header, inputDigests, callConfig: { provider, model, reasoningEffort, temperature, maxTokens, stop } });
|
|
119
|
+
await this.store.update(options.sessionId, options.provider, runtime.cold.id, row => { row.originTurn = turn; row.originStep = step; });
|
|
120
|
+
this.live.set(options.sessionId, runtime.cold.id);
|
|
121
|
+
}
|
|
122
|
+
async recordUserCancellation(runtime, options, nativeId, fallback) {
|
|
123
|
+
if (!runtime.cold || !options.sessionId)
|
|
124
|
+
return;
|
|
125
|
+
const before = await this.store.read(options.sessionId, options.provider);
|
|
126
|
+
if (!before || before.id !== runtime.cold.id)
|
|
127
|
+
return;
|
|
128
|
+
if (!before.meta)
|
|
129
|
+
await this.capture(runtime, options, nativeId, fallback);
|
|
130
|
+
await this.store.update(options.sessionId, options.provider, runtime.cold.id, row => { row.cancelIntent ??= { source: 'user-signal' }; if (!row.promptId) {
|
|
131
|
+
row.cancelCheckpoint = { inputNotDelivered: true, receipt: { kind: 'no-prompt-wire' } };
|
|
132
|
+
row.terminal = { kind: 'local-cancel', value: { inputNotDelivered: true } };
|
|
133
|
+
row.finalUsage = row.meta.baseline;
|
|
134
|
+
row.phase = 'terminal';
|
|
135
|
+
} });
|
|
136
|
+
}
|
|
137
|
+
async adoptUserCancellation(row, events) {
|
|
138
|
+
if (row.cancelIntent || row.phase === 'committed')
|
|
139
|
+
return row;
|
|
140
|
+
const turns = new Set();
|
|
141
|
+
if (row.originTurn !== undefined)
|
|
142
|
+
turns.add(row.originTurn);
|
|
143
|
+
for (const [turn, messages] of inputClaims(events))
|
|
144
|
+
if ([...messages.values()].some(message => recoveryMarker(message) === row.id))
|
|
145
|
+
turns.add(turn);
|
|
146
|
+
if (!events.some(event => event.type === 'turn/end' && turns.has(event.data.turn) && event.data.reason.kind === 'aborted' && event.data.reason.reason.kind === 'user'))
|
|
147
|
+
return row;
|
|
148
|
+
return this.store.update(row.sessionId, row.provider, row.id, r => { r.cancelIntent = { source: 'official-user' }; if (!r.promptId) {
|
|
149
|
+
r.cancelCheckpoint = { inputNotDelivered: true, receipt: { kind: 'no-prompt-wire' } };
|
|
150
|
+
r.terminal = { kind: 'local-cancel', value: { inputNotDelivered: true } };
|
|
151
|
+
r.finalUsage = r.meta.baseline;
|
|
152
|
+
r.phase = 'terminal';
|
|
153
|
+
} });
|
|
154
|
+
}
|
|
155
|
+
async reconcile(row, events) {
|
|
156
|
+
const owns = (pointer) => pointer?.coldRoundId === row.id && pointer.coldRoundTerminal === true && pointer.sessionId === row.nativeId && pointer.dshSessionId === row.sessionId && pointer.agent === row.provider && pointer.coldPromptId === row.promptId;
|
|
157
|
+
let settled = events.find(e => e.type === 'assistant/message' && e.data.message.source.provider === row.provider && owns(e.data.message.source.replayState?.response));
|
|
158
|
+
if (!settled)
|
|
159
|
+
settled = events.find(e => e.type === 'assistant/attempt' && expandAssistantStream(e.data.stream).some(item => { const chunk = item.chunk; if (chunk.type !== 'finish' || !['stop', 'max-tokens'].includes(chunk.reason.kind))
|
|
160
|
+
return false; const response = chunk.replayState?.response; return owns(response); }));
|
|
161
|
+
if (!settled && (row.terminal?.kind === 'local-cancel' && row.cancelCheckpoint?.inputNotDelivered && row.cancelIntent || row.terminal?.kind === 'error' || row.terminal?.kind === 'result' && row.terminal.value?.stopReason === 'cancelled') && row.errorDelivery && row.errorDelivery.promptId === row.promptId) {
|
|
162
|
+
const delivery = row.errorDelivery;
|
|
163
|
+
let turn, step, ours = false;
|
|
164
|
+
for (const e of events) {
|
|
165
|
+
if (e.type === 'turn/start') {
|
|
166
|
+
turn = e.data.turn;
|
|
167
|
+
ours = false;
|
|
168
|
+
}
|
|
169
|
+
else if (e.type === 'step/start') {
|
|
170
|
+
step = e.data.step;
|
|
171
|
+
ours = false;
|
|
172
|
+
}
|
|
173
|
+
else if (e.type === 'user/message' && e.data.id === delivery.markerId && recoveryMarker(e.data) === row.id)
|
|
174
|
+
ours = true;
|
|
175
|
+
else if (e.type === 'assistant/attempt' && ours && e.data.turn === turn && e.data.step === step && expandAssistantStream(e.data.stream).some(item => item.chunk.type === 'finish' && (item.chunk.reason.kind === 'error' || item.chunk.reason.kind === 'aborted') && item.chunk.reason.failure?.code === delivery.code && item.chunk.reason.failure?.message === delivery.message))
|
|
176
|
+
settled = e;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (!settled)
|
|
180
|
+
return false;
|
|
181
|
+
await this.store.update(row.sessionId, row.provider, row.id, r => { r.phase = 'committed'; r.officialSeq = settled.seq; r.outputAfter = (settled.type === 'assistant/message' ? settled.data.message.source.replayState?.response?.coldOutputAfter : undefined) ?? r.terminalAfter ?? 0; delete r.pending; });
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
queueSnapshot(agent) { const q = this.queues.get(agent) ?? new Map(); for (const m of agent.inbox.nextStep)
|
|
185
|
+
q.set(m.id, 'next-step'); for (const m of agent.inbox.nextTurn)
|
|
186
|
+
q.set(m.id, 'next-turn'); this.queues.set(agent, q); return q; }
|
|
187
|
+
async schedule(agent) {
|
|
188
|
+
const provider = agent.options.provider;
|
|
189
|
+
if (typeof provider !== 'string')
|
|
190
|
+
return;
|
|
191
|
+
let row = await this.store.read(agent.session.id, provider);
|
|
192
|
+
if (!row || !['running', 'terminal'].includes(row.phase) || !row.promptId && row.terminal?.kind !== 'local-cancel' || this.live.get(row.sessionId) === row.id || this.scheduled.get(agent) === row.id)
|
|
193
|
+
return;
|
|
194
|
+
if (!row.meta || !sameStoredSessionHeader(row.meta.header, agent.session.header))
|
|
195
|
+
throw coldNeed('SESSION_CONTEXT_MISMATCH');
|
|
196
|
+
const events = await this.events(row.sessionId, row.meta.header);
|
|
197
|
+
row = await this.adoptUserCancellation(row, events);
|
|
198
|
+
if (await this.reconcile(row, events))
|
|
199
|
+
return;
|
|
200
|
+
this.queueSnapshot(agent);
|
|
201
|
+
this.scheduled.set(agent, row.id);
|
|
202
|
+
const existing = [...agent.inbox.nextStep, ...agent.inbox.nextTurn].find(m => recoveryMarker(m) === row.id);
|
|
203
|
+
for (const target of ['next-step', 'next-turn']) {
|
|
204
|
+
const queue = target === 'next-step' ? agent.inbox.nextStep : agent.inbox.nextTurn;
|
|
205
|
+
for (let index = queue.length - 1; index >= 0; index--)
|
|
206
|
+
if (recoveryMarker(queue[index]) === row.id)
|
|
207
|
+
agent.inbox.splice(target, index, 1, []);
|
|
208
|
+
}
|
|
209
|
+
agent.send(existing ?? createUserMessage({ source: { kind: sourceKind, roundId: row.id, form: 'notice', summary: '接回退出前原轮结果' }, content: [{ type: 'text', text: '正在接回退出前的原轮结果;没有重新发送原任务。' }] }), 'next-step', true);
|
|
210
|
+
}
|
|
211
|
+
async settleUserCancellation(row, parentLifetime) {
|
|
212
|
+
const lifetime = parentLifetime ? AbortSignal.any([this.lifetime.signal, parentLifetime]) : this.lifetime.signal;
|
|
213
|
+
if (lifetime.aborted || row.phase === 'committed' || !row.promptId || !row.meta || row.cancelIntent?.delivered || row.cancelCheckpoint?.inputNotDelivered)
|
|
214
|
+
return;
|
|
215
|
+
const api = this.getConnect(), connection = api?.getConnectionState?.();
|
|
216
|
+
if (!api || connection && connection.phase !== 'connected')
|
|
217
|
+
return;
|
|
218
|
+
const target = unwrap(await awaitL(() => api.getSshTarget(), lifetime));
|
|
219
|
+
if (identity(target) !== row.meta.identity || !isDeepStrictEqual(target, row.target))
|
|
220
|
+
throw coldNeed('SESSION_CONTEXT_MISMATCH');
|
|
221
|
+
const io = this.provided?.io?.(row) ?? sshIo(target, this.provided?.argv ?? (await import('@ai-workbench/connect')).sshArgs, this.config().brokerControlMaxBytes);
|
|
222
|
+
for await (const _chunk of recoverColdProtocol(row, this.store, { blocks: [] }, { io, maxFrameBytes: this.config().brokerMaxFrameBytes, maxMessageBytes: this.config().acpMaxMessageBytes, signal: lifetime, cancelOnly: true })) { }
|
|
223
|
+
}
|
|
224
|
+
watchCancellation(payload) {
|
|
225
|
+
const { agent, turn, step, signal } = payload, provider = String(agent.options.provider);
|
|
226
|
+
if (!['codex-remote', 'claude-code-workbench'].includes(provider) || !this.provided?.store && !this.ctx.get('storageDomain'))
|
|
227
|
+
return;
|
|
228
|
+
this.cancellationWatches.get(agent)?.off();
|
|
229
|
+
// Take the snapshot before pre-step/prepareCall can create a new runtime.
|
|
230
|
+
// A live normal producer already owns its own adapter cancellation listener.
|
|
231
|
+
const snapshot = this.store.read(agent.session.id, provider).then(row => ({ row, live: row && this.live.get(row.sessionId) === row.id }));
|
|
232
|
+
void snapshot.catch(() => { });
|
|
233
|
+
const watch = { turn, step, signal, started: false, pending: undefined, off: () => signal.removeEventListener('abort', note) };
|
|
234
|
+
const note = () => { if (signal.reason?.kind !== 'user')
|
|
235
|
+
return; watch.pending = (async () => { const { row, live } = await snapshot; if (!row || live || !['running', 'terminal'].includes(row.phase))
|
|
236
|
+
return; if (!row.meta || !sameStoredSessionHeader(row.meta.header, agent.session.header))
|
|
237
|
+
throw coldNeed('SESSION_CONTEXT_MISMATCH'); const cancelled = await this.store.update(row.sessionId, row.provider, row.id, r => { r.cancelIntent ??= { source: 'user-signal' }; }); if (!watch.started)
|
|
238
|
+
await this.settleUserCancellation(cancelled); })(); void watch.pending.catch(() => { }); };
|
|
239
|
+
this.cancellationWatches.set(agent, watch);
|
|
240
|
+
signal.addEventListener('abort', note, { once: true });
|
|
241
|
+
if (signal.aborted)
|
|
242
|
+
note();
|
|
243
|
+
return watch;
|
|
244
|
+
}
|
|
245
|
+
install() {
|
|
246
|
+
this.ctx.on('agent/created', async ({ agent, source }) => { if (source === 'resume')
|
|
247
|
+
await this.schedule(agent); });
|
|
248
|
+
this.ctx.on('agent/inbox/inserted', ({ agent }) => { this.queueSnapshot(agent); });
|
|
249
|
+
this.ctx.on('agent/pre-step', async (payload, next) => {
|
|
250
|
+
const cancellation = this.watchCancellation(payload);
|
|
251
|
+
try {
|
|
252
|
+
const decision = await next();
|
|
253
|
+
if (decision.kind !== 'enter')
|
|
254
|
+
return decision;
|
|
255
|
+
this.steps.delete(payload.agent);
|
|
256
|
+
let markers = decision.messages.filter(m => recoveryMarker(m));
|
|
257
|
+
if (!markers.length && !this.scheduled.has(payload.agent) && (!['codex-remote', 'claude-code-workbench'].includes(String(payload.agent.options.provider)) || !this.provided?.store && !this.ctx.get('storageDomain')))
|
|
258
|
+
return decision;
|
|
259
|
+
const claimed = new Set(payload.messages.map(m => m.id)), q = this.queues.get(payload.agent);
|
|
260
|
+
let restored = false;
|
|
261
|
+
const restoreHumans = () => { if (restored)
|
|
262
|
+
return; restored = true; for (const target of ['next-step', 'next-turn']) {
|
|
263
|
+
const messages = decision.messages.filter(m => claimed.has(m.id) && !recoveryMarker(m) && (q?.get(m.id) ?? 'next-step') === target);
|
|
264
|
+
if (messages.length)
|
|
265
|
+
payload.agent.inbox.splice(target, 0, 0, messages);
|
|
266
|
+
} };
|
|
267
|
+
try {
|
|
268
|
+
let row = await this.store.read(payload.agent.session.id, String(payload.agent.options.provider));
|
|
269
|
+
if (row?.meta)
|
|
270
|
+
row = await this.adoptUserCancellation(row, await this.events(row.sessionId, row.meta.header));
|
|
271
|
+
if (!markers.length && row && ['running', 'terminal'].includes(row.phase) && (row.promptId || row.terminal?.kind === 'local-cancel') && this.live.get(row.sessionId) !== row.id) {
|
|
272
|
+
if (await this.reconcile(row, await this.events(row.sessionId, row.meta?.header)))
|
|
273
|
+
return decision;
|
|
274
|
+
markers = [createUserMessage({ source: { kind: sourceKind, roundId: row.id, form: 'notice', summary: '接回退出前原轮结果' }, content: [{ type: 'text', text: '正在接回退出前的原轮结果;没有重新发送原任务。' }] })];
|
|
275
|
+
}
|
|
276
|
+
if (!markers.length)
|
|
277
|
+
return decision;
|
|
278
|
+
if (!row || markers.some(m => recoveryMarker(m) !== row.id) || !['running', 'terminal'].includes(row.phase))
|
|
279
|
+
throw coldNeed('SESSION_CONTEXT_MISMATCH');
|
|
280
|
+
restoreHumans();
|
|
281
|
+
this.steps.set(payload.agent, { turn: payload.turn, step: payload.step, signal: payload.signal, row, markerId: markers[0].id });
|
|
282
|
+
return { ...decision, messages: [...markers, ...decision.messages.filter(m => !claimed.has(m.id) && !recoveryMarker(m))] };
|
|
283
|
+
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
restoreHumans();
|
|
286
|
+
throw error;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
finally {
|
|
290
|
+
await cancellation?.pending;
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
this.ctx.on('agent/request', async (payload, next) => { try {
|
|
294
|
+
const config = await next(), step = this.steps.get(payload.agent);
|
|
295
|
+
if (step && step.turn === payload.turn && step.step === payload.step && step.signal === payload.signal)
|
|
296
|
+
return structuredClone(step.row.meta.callConfig ?? { provider: step.row.provider, model: step.row.meta.model, reasoningEffort: step.row.meta.modelConfiguration?.selected?.effort });
|
|
297
|
+
return config;
|
|
298
|
+
}
|
|
299
|
+
finally {
|
|
300
|
+
await this.cancellationWatches.get(payload.agent)?.pending;
|
|
301
|
+
} });
|
|
302
|
+
this.ctx.on('agent/disposed', ({ agent }) => { this.cancellationWatches.get(agent)?.off(); this.cancellationWatches.delete(agent); this.steps.delete(agent); this.scheduled.delete(agent); this.live.delete(agent.session.id); });
|
|
303
|
+
this.ctx.on('session/event', (session, event) => { if (event.type === 'step/end' || event.type === 'turn/end') {
|
|
304
|
+
for (const [agent, watch] of this.cancellationWatches) {
|
|
305
|
+
if (agent.session.id === session.id && watch.turn === event.data.turn && (event.type === 'turn/end' || watch.step === event.data.step)) {
|
|
306
|
+
watch.off();
|
|
307
|
+
this.cancellationWatches.delete(agent);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
for (const [agent, step] of this.steps)
|
|
311
|
+
if (agent.session.id === session.id && step.turn === event.data.turn && (event.type === 'turn/end' || step.step === event.data.step))
|
|
312
|
+
this.steps.delete(agent);
|
|
313
|
+
} if (event.type === 'turn/end') {
|
|
314
|
+
void (async () => { for (const provider of ['codex-remote', 'claude-code-workbench']) {
|
|
315
|
+
const row = await this.store.read(session.id, provider);
|
|
316
|
+
if (row?.terminal && row.phase !== 'committed')
|
|
317
|
+
await this.reconcile(row, await this.events(session.id, row.meta?.header));
|
|
318
|
+
} })().catch(() => this.ctx.logger('remote-agent').warn('INPUT_DELIVERY_UNCONFIRMED:原轮终态落盘未确认'));
|
|
319
|
+
} if (event.type === 'assistant/message') {
|
|
320
|
+
const pointer = event.data.message.source.replayState?.response;
|
|
321
|
+
if (pointer?.coldRoundTerminal && pointer?.coldRoundId)
|
|
322
|
+
void (async () => { const row = await this.store.read(session.id, event.data.message.source.provider); if (row && row.id === pointer.coldRoundId)
|
|
323
|
+
await this.reconcile(row, await this.events(session.id, row.meta?.header)); })().catch(() => this.ctx.logger('remote-agent').warn('INPUT_DELIVERY_UNCONFIRMED:原轮结果已返回,持久提交暂未确认'));
|
|
324
|
+
} });
|
|
325
|
+
for (const agent of this.ctx.get('agents')?.list?.() ?? [])
|
|
326
|
+
void (async () => { await agent.whenIdle(); if (this.ctx.get('agents')?.get(agent.session.id) !== agent)
|
|
327
|
+
return; await agent.runMaintenance(async () => { await this.schedule(agent); }); })().catch(() => this.ctx.logger('remote-agent').warn('INPUT_DELIVERY_UNCONFIRMED:冷恢复初始化未确认'));
|
|
328
|
+
}
|
|
329
|
+
/** Official user cancellation is an input disposition even before a remote runtime exists. */
|
|
330
|
+
async projectCancelledInputs(options) {
|
|
331
|
+
if (!options.sessionId || !this.ctx.get('sessions')?.get(SessionId(options.sessionId)))
|
|
332
|
+
return options;
|
|
333
|
+
const events = await this.events(options.sessionId), claims = inputClaims(events), cancelled = new Set();
|
|
334
|
+
for (const event of events)
|
|
335
|
+
if (event.type === 'turn/end' && event.data.reason.kind === 'aborted' && event.data.reason.reason.kind === 'user')
|
|
336
|
+
for (const id of claims.get(event.data.turn)?.keys() ?? [])
|
|
337
|
+
cancelled.add(id);
|
|
338
|
+
return cancelled.size ? { ...options, messages: options.messages.filter(message => message.role !== 'user' || (!message.id || !cancelled.has(message.id))) } : options;
|
|
339
|
+
}
|
|
340
|
+
async previousPointer(options) {
|
|
341
|
+
if (!options.sessionId || !this.provided?.store && !this.ctx.get('storageDomain'))
|
|
342
|
+
return;
|
|
343
|
+
let row = await this.store.read(options.sessionId, options.provider);
|
|
344
|
+
if (!row || !row.meta || !row.terminal)
|
|
345
|
+
return;
|
|
346
|
+
if (row.phase !== 'committed') {
|
|
347
|
+
if (!await this.reconcile(row, await this.events(row.sessionId, row.meta.header)))
|
|
348
|
+
throw coldNeed();
|
|
349
|
+
row = (await this.store.read(options.sessionId, options.provider));
|
|
350
|
+
}
|
|
351
|
+
const index = options.messages.findLastIndex(m => recoveryMarker(m) === row.id);
|
|
352
|
+
if (index < 0)
|
|
353
|
+
return;
|
|
354
|
+
await this.events(row.sessionId, row.meta.header);
|
|
355
|
+
const m = row.meta, usage = row.finalUsage ?? null;
|
|
356
|
+
if (!row.nativeId)
|
|
357
|
+
return { index, pointer: undefined };
|
|
358
|
+
return { index, pointer: { version: 2, agent: row.provider, dshSessionId: row.sessionId, identity: m.identity, cwd: m.cwd, sessionId: row.nativeId, contextSha256: m.contextSha256, usageSnapshot: usage, ...(m.binding ? { bindingId: m.binding.bindingId, workspaceId: m.binding.workspaceId } : {}), ...(m.hostSource ? { hostSource: m.hostSource } : {}), ...(m.modelConfiguration ? { modelConfiguration: m.modelConfiguration } : {}) } };
|
|
359
|
+
}
|
|
360
|
+
release(sessionId, id) { if (this.live.get(sessionId) === id)
|
|
361
|
+
this.live.delete(sessionId); }
|
|
362
|
+
recoveryModel(provider, model, signal) { for (const step of this.steps.values()) {
|
|
363
|
+
if (step.signal === signal && step.row.provider === provider && step.row.meta?.model === model) {
|
|
364
|
+
const selected = step.row.meta.modelConfiguration?.selected;
|
|
365
|
+
if (!selected)
|
|
366
|
+
throw coldNeed();
|
|
367
|
+
return modelInfo(provider, selected);
|
|
368
|
+
}
|
|
369
|
+
} }
|
|
370
|
+
canRecover(options) { return !options.purpose && [...this.steps].some(([agent, step]) => agent.session.id === options.sessionId && step.row.provider === options.provider && step.row.meta?.model === options.model && step.signal === options.signal && (!step.signal.aborted || step.signal.reason?.kind === 'user') && options.messages.some(m => m.id === step.markerId && recoveryMarker(m) === step.row.id)); }
|
|
371
|
+
async connection(signal, binding) {
|
|
372
|
+
for (;;) {
|
|
373
|
+
signal?.throwIfAborted();
|
|
374
|
+
const api = this.getConnect(), stamp = api ? JSON.stringify([api.getConnectionState?.(), binding?.binding ? api.getWorkspaceLocationState?.() : undefined]) : '';
|
|
375
|
+
if (api) {
|
|
376
|
+
if (binding?.binding && (!api.getWorkspaceLocationState || !api.onWorkspaceLocationState || !api.onConnectionState))
|
|
377
|
+
throw coldNeed('DEPENDENCY_REQUIRED');
|
|
378
|
+
const location = binding?.binding ? api.getWorkspaceLocationState?.() : undefined;
|
|
379
|
+
if (binding?.binding && (location?.phase === 'disposed' || location?.phase === 'failed' && location.need && !['HOST_OFFLINE', 'SSH_FAILED', 'CONNECTION_LOST'].includes(location.need.code)))
|
|
380
|
+
throw coldNeed(location?.need?.code ?? 'SESSION_CONTEXT_MISMATCH');
|
|
381
|
+
const state = api.getConnectionState?.();
|
|
382
|
+
if (!state || state.phase === 'connected') {
|
|
383
|
+
const result = await awaitL(() => api.getSshTarget(), signal);
|
|
384
|
+
if (result.ok) {
|
|
385
|
+
if (!binding?.binding || api.getWorkspaceLocationState?.().phase === 'ready')
|
|
386
|
+
return { api, target: result.value, connection: state };
|
|
387
|
+
}
|
|
388
|
+
else if (!['HOST_OFFLINE', 'SSH_FAILED', 'CONNECTION_LOST'].includes(result.error.code))
|
|
389
|
+
unwrap(result);
|
|
390
|
+
}
|
|
391
|
+
else if (state.phase === 'disposed' || state.need && !['HOST_OFFLINE', 'SSH_FAILED', 'CONNECTION_LOST'].includes(state.need.code))
|
|
392
|
+
throw coldNeed(state.need?.code ?? 'CONNECTION_REQUIRED');
|
|
393
|
+
}
|
|
394
|
+
await new Promise((resolve, reject) => { const offs = []; const clear = () => { for (const off of offs)
|
|
395
|
+
off(); signal?.removeEventListener('abort', abort); }; const wake = () => { clear(); resolve(); }; const abort = () => { clear(); reject(signal?.reason); }; offs.push(this.ctx.on('internal/service', name => { if (name === 'aiWorkbenchConnect')
|
|
396
|
+
wake(); })); if (api?.onConnectionState)
|
|
397
|
+
offs.push(api.onConnectionState(wake)); if (api?.onWorkspaceLocationState)
|
|
398
|
+
offs.push(api.onWorkspaceLocationState(wake)); signal?.addEventListener('abort', abort, { once: true }); if (signal?.aborted)
|
|
399
|
+
abort();
|
|
400
|
+
else if (this.getConnect() !== api || api && JSON.stringify([api.getConnectionState?.(), binding?.binding ? api.getWorkspaceLocationState?.() : undefined]) !== stamp)
|
|
401
|
+
wake(); });
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
async *stream(options, lifetime) {
|
|
405
|
+
if (!this.canRecover(options) || !options.sessionId)
|
|
406
|
+
throw coldNeed();
|
|
407
|
+
const selected = [...this.steps.values()].find(step => step.signal === options.signal && step.row.sessionId === options.sessionId && step.row.provider === options.provider);
|
|
408
|
+
let inheritedCancellation;
|
|
409
|
+
for (const [agent, step] of this.steps)
|
|
410
|
+
if (step === selected) {
|
|
411
|
+
const watch = this.cancellationWatches.get(agent);
|
|
412
|
+
if (watch) {
|
|
413
|
+
watch.started = true;
|
|
414
|
+
inheritedCancellation = watch.pending;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
let cancellation;
|
|
418
|
+
const note = () => { if (options.signal?.reason?.kind === 'user')
|
|
419
|
+
cancellation = this.store.update(selected.row.sessionId, selected.row.provider, selected.row.id, row => { row.cancelIntent ??= { source: 'user-signal' }; }); void cancellation?.catch(() => { }); };
|
|
420
|
+
options.signal?.addEventListener('abort', note, { once: true });
|
|
421
|
+
if (options.signal?.aborted)
|
|
422
|
+
note();
|
|
423
|
+
try {
|
|
424
|
+
await inheritedCancellation;
|
|
425
|
+
yield* this.streamRound(options, lifetime);
|
|
426
|
+
}
|
|
427
|
+
finally {
|
|
428
|
+
options.signal?.removeEventListener('abort', note);
|
|
429
|
+
await cancellation;
|
|
430
|
+
if (cancellation && !lifetime?.aborted) {
|
|
431
|
+
const row = await this.store.read(selected.row.sessionId, selected.row.provider);
|
|
432
|
+
if (row && row.id === selected.row.id)
|
|
433
|
+
await this.settleUserCancellation(row, lifetime);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
async *streamRound(options, lifetime) {
|
|
438
|
+
if (!this.canRecover(options) || !options.sessionId)
|
|
439
|
+
throw coldNeed();
|
|
440
|
+
const markers = options.messages.filter(m => recoveryMarker(m)), id = recoveryMarker(markers.at(-1));
|
|
441
|
+
const selected = [...this.steps.values()].find(step => step.signal === options.signal && step.row.id === id);
|
|
442
|
+
const row = await this.store.read(options.sessionId, options.provider);
|
|
443
|
+
if (!selected || !row || row.id !== id || !row.meta || !row.nativeId && row.terminal?.kind !== 'local-cancel' || !['running', 'terminal'].includes(row.phase))
|
|
444
|
+
throw coldNeed();
|
|
445
|
+
const events = await this.events(row.sessionId, row.meta.header);
|
|
446
|
+
if (this.provided?.readSource && !isDeepStrictEqual(row.meta.hostSource ?? { source: 'local' }, await this.provided.readSource(row.sessionId)))
|
|
447
|
+
throw coldNeed('SESSION_CONTEXT_MISMATCH');
|
|
448
|
+
for (const [inputId, expected] of Object.entries(row.meta.inputDigests ?? {})) {
|
|
449
|
+
const e = events.find(e => e.type === 'user/message' && e.data.id === inputId);
|
|
450
|
+
if (!e || digest(e.data) !== expected)
|
|
451
|
+
throw coldNeed('SESSION_CONTEXT_MISMATCH');
|
|
452
|
+
}
|
|
453
|
+
if (row.terminal?.kind === 'local-cancel') {
|
|
454
|
+
yield* recoverLocalCancellation(row, this.store, selected.markerId);
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
const operationSignal = lifetime ? AbortSignal.any([lifetime, ...options.signal ? [options.signal] : []]) : options.signal;
|
|
458
|
+
const { api, target, connection: initialConnection } = await this.connection(operationSignal, row.meta);
|
|
459
|
+
if (identity(target) !== row.meta.identity || !isDeepStrictEqual(target, row.target))
|
|
460
|
+
throw coldNeed('SESSION_CONTEXT_MISMATCH');
|
|
461
|
+
if (row.meta.binding) {
|
|
462
|
+
if (typeof api.onWorkspaceLocationState !== 'function' || typeof api.onConnectionState !== 'function')
|
|
463
|
+
throw coldNeed('DEPENDENCY_REQUIRED');
|
|
464
|
+
const state = api.getWorkspaceLocationState?.(), matches = state?.items.filter(x => x.workspaceId === row.meta.binding.workspaceId);
|
|
465
|
+
if (state?.phase !== 'ready' || matches?.length !== 1 || matches[0].bindingId !== row.meta.binding.bindingId || matches[0].status !== 'selected' || matches[0].source !== (row.meta.hostSource ? 'host' : 'local'))
|
|
466
|
+
throw coldNeed('SESSION_CONTEXT_MISMATCH');
|
|
467
|
+
}
|
|
468
|
+
if (row.meta.localDirectory) {
|
|
469
|
+
try {
|
|
470
|
+
const expected = row.meta.localDirectory, current = await lstat(expected.path), canonical = await realpath(expected.path);
|
|
471
|
+
if (!current.isDirectory() || current.isSymbolicLink() || canonical !== expected.path || current.dev !== expected.device || current.ino !== expected.inode)
|
|
472
|
+
throw coldNeed('EMPLOYEE_CONTEXT_CHANGED');
|
|
473
|
+
}
|
|
474
|
+
catch {
|
|
475
|
+
throw coldNeed('EMPLOYEE_CONTEXT_CHANGED');
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
const attempts = new Set([JSON.stringify([row.originTurn, row.originStep])]);
|
|
479
|
+
let turn, step;
|
|
480
|
+
for (const e of events) {
|
|
481
|
+
if (e.type === 'turn/start')
|
|
482
|
+
turn = e.data.turn;
|
|
483
|
+
else if (e.type === 'step/start')
|
|
484
|
+
step = e.data.step;
|
|
485
|
+
else if (e.type === 'user/message' && recoveryMarker(e.data) === row.id)
|
|
486
|
+
attempts.add(JSON.stringify([turn, step]));
|
|
487
|
+
}
|
|
488
|
+
const blocks = [], usage = { inputTokens: 0, outputTokens: 0 };
|
|
489
|
+
for (const e of events) {
|
|
490
|
+
if (!['assistant/message', 'assistant/attempt'].includes(e.type))
|
|
491
|
+
continue;
|
|
492
|
+
const d = e.data;
|
|
493
|
+
const pointer = d.message?.source?.replayState?.response;
|
|
494
|
+
if (!attempts.has(JSON.stringify([d.turn, d.step])) && pointer?.coldRoundId !== row.id && !(d.turn === row.originTurn && d.step >= row.originStep))
|
|
495
|
+
continue;
|
|
496
|
+
if (e.type === 'assistant/message' && d.message.source.provider !== row.provider)
|
|
497
|
+
continue;
|
|
498
|
+
const data = e.data;
|
|
499
|
+
if (e.type === 'assistant/message')
|
|
500
|
+
blocks.push(...data.message.content);
|
|
501
|
+
else {
|
|
502
|
+
const llm = await import('@deepseek-ai/dsh-llm');
|
|
503
|
+
const assembler = new llm.BlockAssembler();
|
|
504
|
+
for (const item of llm.expandAssistantStream(data.stream ?? [])) {
|
|
505
|
+
assembler.push(item.chunk);
|
|
506
|
+
if (item.chunk.type === 'usage')
|
|
507
|
+
for (const [key, value] of Object.entries(item.chunk.usage))
|
|
508
|
+
if (typeof value === 'number')
|
|
509
|
+
usage[key] = (usage[key] ?? 0) + value;
|
|
510
|
+
}
|
|
511
|
+
blocks.push(...assembler.blocks());
|
|
512
|
+
}
|
|
513
|
+
for (const [key, value] of Object.entries(data.usage ?? {}))
|
|
514
|
+
if (typeof value === 'number')
|
|
515
|
+
usage[key] = (usage[key] ?? 0) + value;
|
|
516
|
+
}
|
|
517
|
+
let io = this.provided?.io?.(row);
|
|
518
|
+
if (!io) {
|
|
519
|
+
const argv = this.provided?.argv ?? (await import('@ai-workbench/connect')).sshArgs;
|
|
520
|
+
io = sshIo(target, argv, this.config().brokerControlMaxBytes);
|
|
521
|
+
}
|
|
522
|
+
const guard = new AbortController(), disposers = [];
|
|
523
|
+
let revoked;
|
|
524
|
+
const revoke = (code = 'SESSION_CONTEXT_MISMATCH') => { revoked = coldNeed(code); guard.abort({ kind: 'disposed' }); };
|
|
525
|
+
const connection = initialConnection;
|
|
526
|
+
const checkLocation = () => { if (this.getConnect() !== api) {
|
|
527
|
+
revoke();
|
|
528
|
+
return;
|
|
529
|
+
} if (!row.meta.binding)
|
|
530
|
+
return; const state = api.getWorkspaceLocationState?.(); if (!state) {
|
|
531
|
+
revoke();
|
|
532
|
+
return;
|
|
533
|
+
} if (state.phase !== 'ready') {
|
|
534
|
+
if (state.phase === 'disposed' || state.phase === 'failed' && (!state.need || !['HOST_OFFLINE', 'SSH_FAILED', 'CONNECTION_LOST'].includes(state.need.code)))
|
|
535
|
+
revoke();
|
|
536
|
+
return;
|
|
537
|
+
} const matches = state.items.filter(x => x.workspaceId === row.meta.binding.workspaceId); if (matches.length !== 1 || matches[0].bindingId !== row.meta.binding.bindingId || matches[0].source !== (row.meta.hostSource ? 'host' : 'local') || matches[0].status !== 'selected')
|
|
538
|
+
revoke(); };
|
|
539
|
+
try {
|
|
540
|
+
disposers.push(this.ctx.on('domain/changed', event => { if (event.domain === 'ai_workbench_remote_sources' && event.table === 'sessions' && event.key === row.sessionId && (event.operation === 'deleted' || !isDeepStrictEqual(event.value, row.meta.hostSource ?? { source: 'local' })))
|
|
541
|
+
revoke(); }));
|
|
542
|
+
disposers.push(this.ctx.on('internal/service', name => { if (name === 'aiWorkbenchConnect' && this.getConnect() !== api)
|
|
543
|
+
revoke(); }));
|
|
544
|
+
if (api.onWorkspaceLocationState)
|
|
545
|
+
disposers.push(api.onWorkspaceLocationState(checkLocation));
|
|
546
|
+
if (api.onConnectionState)
|
|
547
|
+
disposers.push(api.onConnectionState(next => { if (this.getConnect() !== api || next.instanceId !== connection?.instanceId || next.phase === 'disposed' || next.phase === 'unavailable' && (!next.need || !['HOST_OFFLINE', 'SSH_FAILED', 'CONNECTION_LOST'].includes(next.need.code)))
|
|
548
|
+
revoke();
|
|
549
|
+
else if (next.phase === 'connected') {
|
|
550
|
+
void api.getSshTarget().then(result => { if (result.ok) {
|
|
551
|
+
if (identity(result.value) !== row.meta.identity || !isDeepStrictEqual(result.value, row.target))
|
|
552
|
+
revoke();
|
|
553
|
+
}
|
|
554
|
+
else if (!['HOST_OFFLINE', 'SSH_FAILED', 'CONNECTION_LOST'].includes(result.error.code))
|
|
555
|
+
revoke(); }, () => revoke());
|
|
556
|
+
checkLocation();
|
|
557
|
+
} }));
|
|
558
|
+
if (row.meta.localDirectory) {
|
|
559
|
+
const expected = row.meta.localDirectory;
|
|
560
|
+
const check = async () => { try {
|
|
561
|
+
const stat = await lstat(expected.path);
|
|
562
|
+
if (!stat.isDirectory() || stat.isSymbolicLink() || await realpath(expected.path) !== expected.path || stat.dev !== expected.device || stat.ino !== expected.inode)
|
|
563
|
+
revoke('EMPLOYEE_CONTEXT_CHANGED');
|
|
564
|
+
}
|
|
565
|
+
catch {
|
|
566
|
+
revoke('EMPLOYEE_CONTEXT_CHANGED');
|
|
567
|
+
} };
|
|
568
|
+
const watcher = watch(dirname(expected.path), () => { void check(); });
|
|
569
|
+
watcher.on('error', () => revoke('EMPLOYEE_CONTEXT_CHANGED'));
|
|
570
|
+
disposers.push(() => watcher.close());
|
|
571
|
+
await check();
|
|
572
|
+
}
|
|
573
|
+
checkLocation();
|
|
574
|
+
const signal = AbortSignal.any([guard.signal, ...operationSignal ? [operationSignal] : []]);
|
|
575
|
+
if (!isDeepStrictEqual(api.getConnectionState?.(), initialConnection)) {
|
|
576
|
+
const checked = await this.connection(signal, row.meta);
|
|
577
|
+
if (checked.api !== api || !isDeepStrictEqual(checked.target, row.target))
|
|
578
|
+
revoke();
|
|
579
|
+
}
|
|
580
|
+
if (this.provided?.readSource && !isDeepStrictEqual(row.meta.hostSource ?? { source: 'local' }, await this.provided.readSource(row.sessionId)))
|
|
581
|
+
revoke();
|
|
582
|
+
signal.throwIfAborted();
|
|
583
|
+
this.live.set(row.sessionId, row.id);
|
|
584
|
+
yield* recoverColdProtocol(row, this.store, { blocks, usage }, { io, maxFrameBytes: this.config().brokerMaxFrameBytes, maxMessageBytes: this.config().acpMaxMessageBytes, signal, markerId: selected.markerId });
|
|
585
|
+
if (revoked)
|
|
586
|
+
throw revoked;
|
|
587
|
+
}
|
|
588
|
+
catch (error) {
|
|
589
|
+
throw revoked ?? error;
|
|
590
|
+
}
|
|
591
|
+
finally {
|
|
592
|
+
for (const off of disposers)
|
|
593
|
+
off();
|
|
594
|
+
if (this.live.get(row.sessionId) === row.id)
|
|
595
|
+
this.live.delete(row.sessionId);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|