@ai-workbench/remote-agent 0.9.0-toolbridge.13 → 0.9.0-toolbridge.15
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 +8 -3
- package/dist/acp.d.ts +5 -0
- package/dist/acp.js +52 -3
- package/dist/broker-runtime.d.ts +2 -0
- package/dist/broker-runtime.js +46 -3
- package/dist/broker.d.ts +41 -1
- package/dist/broker.js +237 -9
- package/dist/claude-local.js +26 -5
- package/dist/cold-protocol.d.ts +14 -0
- package/dist/cold-protocol.js +285 -0
- package/dist/cold-recovery.d.ts +53 -0
- package/dist/cold-recovery.js +427 -0
- package/dist/cold-store.d.ts +91 -0
- package/dist/cold-store.js +29 -0
- package/dist/employee-endpoint.js +15 -1
- package/dist/employee-provider.js +26 -6
- package/dist/index.d.ts +11 -2
- package/dist/index.js +178 -30
- package/dist/live-steering.d.ts +46 -0
- package/dist/live-steering.js +45 -0
- package/dist/provider.d.ts +11 -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/package.json +11 -10
package/README.md
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
# AI Workbench 远程助手 · @ai-workbench/remote-agent@0.9.0-toolbridge.
|
|
1
|
+
# AI Workbench 远程助手 · @ai-workbench/remote-agent@0.9.0-toolbridge.15 · 插件 → 添加插件
|
|
2
2
|
|
|
3
3
|
## 含工具桥预发布线
|
|
4
4
|
|
|
5
|
-
本包为 `0.9.0-toolbridge.
|
|
5
|
+
本包为 `0.9.0-toolbridge.15`,从 `v0.9.0-toolbridge.14` 派生,使用 `host-toolbridge` 发布渠道。员工安装由连接组件提供的「AI 写作工作台(含工具桥)」总包 `@ai-workbench/workbench-toolbridge@0.1.12`,与不含工具桥的版本二选一。
|
|
6
|
+
|
|
7
|
+
本轮增加两家运行中插话(DSH 原生 nextStep),保留官方队列和原话;明确 followup 仍排下一轮。Codex 含桥组件需 `2.2.2-aw.12`,Claude 仍为官方 `0.94.0`。插件确定消息未发出时保留排队资格;送达未确认时明确报错且不重放。已注入旧正文不能撤回,编辑版下一步骤交付。
|
|
8
|
+
|
|
9
|
+
host `0.8.10` 的新 broker 支持同一客户端/SDK 在切网后按输出游标和输入 ACK 水位接回原 prompt、结果及用量,不重新发送原 prompt;旧本机执行端失效仍为 UNKNOWN,不用新进程替换或重放旧操作。客户端完全退出、崩溃后,重新打开同一 DSH 会话会自动接回已持久登记的原 prompt,显示未落盘输出并取回原结果、增量用量。原 prompt 只执行一次;旧审批仅取消,不复活未知本机执行。旧运行 broker 和 X.14 在途轮不会被安装自动补造冷恢复记录。无新增设置;512,000,000 字节默认保留,实际协议头计入同一容量。
|
|
10
|
+
|
|
6
11
|
|
|
7
12
|
选择本机文件夹后,Claude 和 Codex 可以把 DSH 已启用的 MCP、web、skill、ask_user、todo/present/goal 等工具交给 DSH 原生执行和审批。内置文件/命令、子代理/agent-team、run_code 不在桥接表;原有文件和命令执行方式保留。plan 不自动放行桥接权限;default 下 Claude 的桥接原生权限由插件单次应答,员工只在 DSH 审批实际工具。主机文件夹不开放工具桥。
|
|
8
13
|
|
|
@@ -26,7 +31,7 @@ Claude 本机 Bash 会单独消费员工桥代理的控制诊断,不把它交
|
|
|
26
31
|
|
|
27
32
|
## 会话行为
|
|
28
33
|
|
|
29
|
-
|
|
34
|
+
新的用户轮启动一个新助手进程,按原生会话编号恢复上下文;退出前尚未结算的原轮则附着原进程,仅取回该轮输出、结果和用量,不重发原输入。主机会话始终使用创建时保存的主机和目录;工作区之后的选择只影响新会话。
|
|
30
35
|
|
|
31
36
|
同一 DSH 会话切换 Claude/Codex 时,切回会接本品牌最近的远端会话,并补充它尚未见过的可见对话;首次使用某品牌则带入全部可见历史。工具内部状态、推理和技术详情不转交。历史超出既有 `acpMaxMessageBytes` 容量时,只带能容纳的最近完整轮,并在技术详情说明省略数量;当前输入保持完整,超限仍明确失败。没有新增设置、重试或时限。
|
|
32
37
|
|
package/dist/acp.d.ts
CHANGED
|
@@ -53,6 +53,10 @@ export declare class AcpSession {
|
|
|
53
53
|
private turnSignal?;
|
|
54
54
|
private turnToken?;
|
|
55
55
|
private busy;
|
|
56
|
+
private steeringSupported;
|
|
57
|
+
private dispatchedSteers;
|
|
58
|
+
get canSteer(): boolean;
|
|
59
|
+
get steerDispatchCount(): number;
|
|
56
60
|
private startAttempted;
|
|
57
61
|
private negotiated;
|
|
58
62
|
private method?;
|
|
@@ -118,6 +122,7 @@ export declare class AcpSession {
|
|
|
118
122
|
start(cwd: string, resumeId?: string, signal?: AbortSignal, context?: AcpStartContext, prompt?: acp.ContentBlock[]): Promise<string>;
|
|
119
123
|
/** Codex context is immutable after creation; keep the old remote session intact. */
|
|
120
124
|
prompt(input: string | acp.ContentBlock[], signal?: AbortSignal): Promise<acp.StopReason>;
|
|
125
|
+
steer(prompt: acp.ContentBlock[], signal?: AbortSignal, isCurrent?: () => boolean, maxBytes?: number): Promise<'injected' | 'promptRequired'>;
|
|
121
126
|
close(cause?: CloseCause, error?: Error): void;
|
|
122
127
|
}
|
|
123
128
|
export declare function acpNeed(error: unknown): NeedError;
|
package/dist/acp.js
CHANGED
|
@@ -18,6 +18,10 @@ export class AcpSession {
|
|
|
18
18
|
turnSignal;
|
|
19
19
|
turnToken;
|
|
20
20
|
busy = false;
|
|
21
|
+
steeringSupported = false;
|
|
22
|
+
dispatchedSteers = 0;
|
|
23
|
+
get canSteer() { return this.steeringSupported && this.busy && !this.closeRequested; }
|
|
24
|
+
get steerDispatchCount() { return this.dispatchedSteers; }
|
|
21
25
|
startAttempted = false;
|
|
22
26
|
negotiated = {};
|
|
23
27
|
method;
|
|
@@ -430,6 +434,10 @@ export class AcpSession {
|
|
|
430
434
|
throw new acp.RequestError(-32601, '不支持此扩展交互');
|
|
431
435
|
})
|
|
432
436
|
.onNotification('*', ({ method, params }) => {
|
|
437
|
+
if (method === '_aw/broker-replay-complete') {
|
|
438
|
+
this.hooks.broker?.confirmReplay(record(params)?.generation);
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
433
441
|
this.detail({ kind: 'extension', severity: 'warning', code: 'ACP_UNKNOWN_NOTIFICATION', summary: '收到未知远端扩展通知,已保留技术记录', method, payload: params });
|
|
434
442
|
});
|
|
435
443
|
if ('readable' in transport && 'writable' in transport)
|
|
@@ -449,7 +457,8 @@ export class AcpSession {
|
|
|
449
457
|
/** A rejected request on an already-closed SDK never reaches this write.
|
|
450
458
|
* Once a transport write starts, failure remains delivery-unknown. */
|
|
451
459
|
observeDispatch(message) {
|
|
452
|
-
|
|
460
|
+
const method = record(message)?.method;
|
|
461
|
+
if (!['session/prompt', '_session/steering'].includes(String(method)) || !Object.hasOwn(message, 'id'))
|
|
453
462
|
return;
|
|
454
463
|
const params = record(record(message)?.params), current = params ? this.promptPermissions.get(params) : undefined;
|
|
455
464
|
if (params)
|
|
@@ -458,6 +467,8 @@ export class AcpSession {
|
|
|
458
467
|
this.closeDiagnostics.record({ layer: 'acp', initiator: 'acp.permission-dispatch-gate', reason: 'PERMISSION_POLICY_CHANGED', operation: 'session/prompt', action: 'failure' });
|
|
459
468
|
throw new NeedError('PERMISSION_POLICY_CHANGED', '当前权限已变化或无法核对,这次派发已停止;原输入没有重放。', '当前权限代次与远端同值回执');
|
|
460
469
|
}
|
|
470
|
+
if (current.maxBytes !== undefined && Buffer.byteLength(JSON.stringify(message)) + 1 > current.maxBytes)
|
|
471
|
+
throw new NeedError('ACP_MESSAGE_TOO_LARGE', '中途消息超过已设置的会话消息容量,未发送。', '管理员调整acpMaxMessageBytes');
|
|
461
472
|
current.native();
|
|
462
473
|
this.hooks.broker?.authorizePrompt(() => { try {
|
|
463
474
|
if (!current.current())
|
|
@@ -468,7 +479,10 @@ export class AcpSession {
|
|
|
468
479
|
catch {
|
|
469
480
|
return false;
|
|
470
481
|
} });
|
|
471
|
-
|
|
482
|
+
if (method === 'session/prompt')
|
|
483
|
+
this.dispatchedPrompts++;
|
|
484
|
+
else
|
|
485
|
+
this.dispatchedSteers++;
|
|
472
486
|
}
|
|
473
487
|
observe(stream) {
|
|
474
488
|
// Observe already-parsed public Stream messages: no NDJSON parsing, second
|
|
@@ -520,6 +534,8 @@ export class AcpSession {
|
|
|
520
534
|
if (hello.protocolVersion !== acp.PROTOCOL_VERSION)
|
|
521
535
|
throw new NeedError('ACP_VERSION_MISMATCH', 'ACP 协议版本不兼容', '支持 ACP v1 的远端 agent');
|
|
522
536
|
this.negotiated = hello.agentCapabilities ?? {};
|
|
537
|
+
const steering = record(hello._meta?.steering);
|
|
538
|
+
this.steeringSupported = steering?.supported === true && (!context?.codexNewSessionOnly || steering.idleBehavior === 'promptRequired');
|
|
523
539
|
if (this.employeeMeta) {
|
|
524
540
|
const policy = record(hello._meta?.awEmployeeExecution);
|
|
525
541
|
if (!this.hooks.employeeExecution || !policy || Object.keys(policy).length !== (context?.toolBridgeServers ? 6 : 5) || context?.toolBridgeServers && policy.mcpBridge !== 1 || policy.version !== 1 || policy.nativeCliVersion !== '0.160.1' || policy.native !== true || policy.perRpcGate !== true || policy.noHostFallback !== true)
|
|
@@ -625,7 +641,18 @@ export class AcpSession {
|
|
|
625
641
|
this.turnToken = Symbol('turn');
|
|
626
642
|
let rejectAbort;
|
|
627
643
|
const interrupted = new Promise((_resolve, reject) => { rejectAbort = reject; });
|
|
644
|
+
const requestAbort = new AbortController();
|
|
628
645
|
const cancel = () => {
|
|
646
|
+
if (signal?.reason?.kind === 'disposed') {
|
|
647
|
+
this.close({ layer: 'acp', initiator: 'acp.owner-disposed', reason: 'SESSION_DETACHED', action: 'detach' });
|
|
648
|
+
rejectAbort?.(new NeedError('ABORTED', '客户端已退出,主机原轮保留,未发送取消', '原轮冷恢复'));
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
if (this.closeRequested) {
|
|
652
|
+
rejectAbort?.(new NeedError('ABORTED', '客户端已分离,未重发或取消主机原轮', '原轮恢复状态'));
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
requestAbort.abort(signal?.reason);
|
|
629
656
|
this.closeDiagnostics.record({ layer: 'acp', initiator: 'acp.prompt-cancel', reason: 'ABORTED', operation: 'session/prompt', action: 'abort' });
|
|
630
657
|
rejectAbort?.(new NeedError('ABORTED', '已请求取消本轮,远端状态需确认', '确认主机取消状态'));
|
|
631
658
|
void this.connection.agent.notify(acp.methods.agent.session.cancel, { sessionId: this.sessionId }).catch(() => {
|
|
@@ -637,7 +664,7 @@ export class AcpSession {
|
|
|
637
664
|
this.flushBridgeStartupNotice();
|
|
638
665
|
const result = await this.stage('acp-prompt', () => {
|
|
639
666
|
this.promptPermissions.set(params, { current, native });
|
|
640
|
-
const request = this.connection.agent.request(acp.methods.agent.session.prompt, params, { cancellationSignal: signal });
|
|
667
|
+
const request = this.connection.agent.request(acp.methods.agent.session.prompt, params, { cancellationSignal: requestAbort.signal });
|
|
641
668
|
return signal ? Promise.race([request, interrupted]) : request;
|
|
642
669
|
});
|
|
643
670
|
signal?.throwIfAborted();
|
|
@@ -656,12 +683,34 @@ export class AcpSession {
|
|
|
656
683
|
this.turnToken = undefined;
|
|
657
684
|
}
|
|
658
685
|
}
|
|
686
|
+
async steer(prompt, signal, isCurrent, maxBytes) {
|
|
687
|
+
if (!this.canSteer || !this.sessionId || isCurrent && !isCurrent())
|
|
688
|
+
return 'promptRequired';
|
|
689
|
+
this.validatePrompt(prompt);
|
|
690
|
+
signal?.throwIfAborted();
|
|
691
|
+
const token = this.turnToken, permit = this.hooks.promptGuard?.(), expected = this.selectedPermission, reported = new Set();
|
|
692
|
+
const current = () => this.canSteer && (!isCurrent || isCurrent()) && this.turnToken === token && !signal?.aborted && (!permit || !permit.signal.aborted && permit.isCurrent());
|
|
693
|
+
const params = { sessionId: this.sessionId, prompt, _meta: { steering: { idleBehavior: 'promptRequired' } } };
|
|
694
|
+
this.promptPermissions.set(params, { current, native: () => this.validateNativePermission(expected, reported), maxBytes });
|
|
695
|
+
try {
|
|
696
|
+
const result = await this.connection.agent.request('_session/steering', params, { cancellationSignal: signal });
|
|
697
|
+
if (result.outcome === 'injected' || result.outcome === 'promptRequired')
|
|
698
|
+
return result.outcome;
|
|
699
|
+
throw new NeedError('INPUT_DELIVERY_UNCONFIRMED', '中途消息未获得同一轮的注入回执,没有重复提交。', '原轮injected或promptRequired回执');
|
|
700
|
+
}
|
|
701
|
+
catch (error) {
|
|
702
|
+
throw acpNeed(error);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
659
705
|
close(cause = { layer: 'acp', initiator: 'acp.close', reason: 'ACP_CLOSE_REQUESTED', action: 'close' }, error) { this.closeDiagnostics.record({ ...cause, changes: cause.changes ?? [{ field: 'acp.close-requested', before: this.closeRequested, after: true }] }); this.closeRequested = true; this.connection?.close(error); }
|
|
660
706
|
}
|
|
661
707
|
export function acpNeed(error) {
|
|
662
708
|
if (error instanceof NeedError)
|
|
663
709
|
return error;
|
|
664
710
|
if (error instanceof acp.RequestError) {
|
|
711
|
+
const localCode = record(error.data)?.localDispatchCode;
|
|
712
|
+
if (error.message === 'ACP_LOCAL_REQUEST_REJECTED' && (localCode === 'ACP_MESSAGE_TOO_LARGE' || localCode === 'PERMISSION_POLICY_CHANGED'))
|
|
713
|
+
return new NeedError(localCode, '中途消息在实际派发前被拒绝,仍在官方队列中,未发送。', '当前消息、权限与acpMaxMessageBytes');
|
|
665
714
|
if (record(error.data)?.reason === 'thread_active_writer')
|
|
666
715
|
return new NeedError('REMOTE_SESSION_BUSY', employeeFailure('REMOTE_SESSION_BUSY'), '原远端线程仍被占用;需要按同一DSH会话和远端线程定位已断开的旧broker并确认释放;RPC 错误码 ' + error.code);
|
|
667
716
|
// Host SDK1.9 uses Internal error + data.details for thrown adapter errors.
|
package/dist/broker-runtime.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ColdStore } from './cold-store.ts';
|
|
1
2
|
import { type SshArgv, type BrokerIo, type BrokerSettings } from './broker.ts';
|
|
2
3
|
import { type ConnectApi, type ConnectTarget, type Project, type Runtime, type RuntimeRequest } from './provider.ts';
|
|
3
4
|
import type { Interaction } from './interaction.ts';
|
|
@@ -5,4 +6,5 @@ import type { Interaction } from './interaction.ts';
|
|
|
5
6
|
export declare function brokerFactory(_get: () => ConnectApi | undefined, _ask: Interaction | undefined, configuration: BrokerSettings | (() => BrokerSettings), provided?: {
|
|
6
7
|
argv?: SshArgv;
|
|
7
8
|
io?: (target: ConnectTarget) => BrokerIo;
|
|
9
|
+
coldStore?: ColdStore;
|
|
8
10
|
}): (target: ConnectTarget, project: Project, request: RuntimeRequest) => Promise<Runtime>;
|
package/dist/broker-runtime.js
CHANGED
|
@@ -6,6 +6,7 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
6
6
|
}
|
|
7
7
|
return path;
|
|
8
8
|
};
|
|
9
|
+
import { newColdId } from "./cold-store.js";
|
|
9
10
|
import { randomUUID } from 'node:crypto';
|
|
10
11
|
import { CloseDiagnostics } from "./close-diagnostics.js";
|
|
11
12
|
import { BrokerTransport, brokerCommand, brokerId, sshIo, controlJson } from "./broker.js";
|
|
@@ -36,14 +37,56 @@ export function brokerFactory(_get, _ask, configuration, provided) {
|
|
|
36
37
|
throw new NeedError(started.code, '主机的环境配置会覆盖本机执行位置,本轮已停止;请由管理员移开该配置后在原会话重试。', '主机 CODEX_HOME/environments.toml 不存在');
|
|
37
38
|
if (started.protocolVersion !== 1 || started.id !== id || !started.instanceId)
|
|
38
39
|
throw new NeedError('BROKER_PROTOCOL_INVALID', '主机会话未能启动,请恢复连接后再试。', '有效的主机会话启动回应');
|
|
39
|
-
const
|
|
40
|
+
const coldStore = started.messageInputProtocolVersion === 1 ? provided?.coldStore : undefined, roundId = newColdId();
|
|
41
|
+
if (coldStore)
|
|
42
|
+
await coldStore.put({ version: 1, id: roundId, sessionId: request.sessionId, provider: agent.id, brand: agent.loginProvider, phase: 'opening', target: structuredClone(target), brokerId: id, instanceId: started.instanceId, controlMaxBytes: started.controlMaxBytes, heartbeatIntervalMs: started.lifecycle.heartbeatIntervalMs, rpcIds: [], answered: [], inputSequence: 0, outputAfter: 0 });
|
|
43
|
+
const beforeMessage = coldStore ? async (bytes, message) => {
|
|
44
|
+
const rpc = JSON.parse(Buffer.from(bytes).toString('utf8'));
|
|
45
|
+
let record = await coldStore.update(request.sessionId, agent.id, roundId, row => {
|
|
46
|
+
if (rpc.method && Object.hasOwn(rpc, 'id') && !row.rpcIds.includes(rpc.id))
|
|
47
|
+
row.rpcIds.push(rpc.id);
|
|
48
|
+
row.pending = { id: message.id, sha256: message.sha256, wire: Buffer.from(bytes).toString('base64'), baseSequence: message.baseSequence, chunkBytes: message.chunkBytes, chunks: Math.ceil(bytes.length / message.chunkBytes), ...(rpc.method ? { method: rpc.method } : {}), ...(Object.hasOwn(rpc, 'id') ? { rpcId: rpc.id } : {}) };
|
|
49
|
+
if (rpc.method === 'session/prompt') {
|
|
50
|
+
if (!row.meta || row.nativeId !== rpc.params?.sessionId || row.promptId)
|
|
51
|
+
throw new NeedError('INPUT_DELIVERY_UNCONFIRMED', '原轮归属未完成持久登记,未发送输入', '完整冷恢复快照');
|
|
52
|
+
row.promptId = String(rpc.id);
|
|
53
|
+
row.promptSha256 = message.sha256;
|
|
54
|
+
row.promptBytes = bytes.length;
|
|
55
|
+
row.phase = 'running';
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
if (rpc.method === 'session/prompt') {
|
|
59
|
+
const bound = controlJson(await io.run(command(['bind-round', id, '--if-instance', started.instanceId, '--dsh-session-id', request.sessionId, '--provider', agent.loginProvider, '--remote-session-id', record.nativeId, '--round-id', roundId, '--prompt-id', record.promptId, '--prompt-sha256', record.promptSha256, '--prompt-bytes', String(record.promptBytes)])));
|
|
60
|
+
if (!Number.isSafeInteger(bound.round?.outputStartSequence))
|
|
61
|
+
throw new NeedError('BROKER_PROTOCOL_INVALID', '原轮输出起点未确认', '原轮绑定回执');
|
|
62
|
+
await coldStore.update(request.sessionId, agent.id, roundId, row => { row.outputStart = bound.round.outputStartSequence; });
|
|
63
|
+
}
|
|
64
|
+
} : undefined;
|
|
65
|
+
const afterMessage = coldStore ? async (sequence) => { await coldStore.update(request.sessionId, agent.id, roundId, row => { if (row.pending && !row.pending.method && row.pending.rpcId !== undefined && !row.answered.includes(row.pending.rpcId))
|
|
66
|
+
row.answered.push(row.pending.rpcId); row.inputSequence = sequence; delete row.pending; }); } : undefined;
|
|
67
|
+
const channel = new BrokerTransport({ observeClose: diagnostics.capture(), maxFrameBytes: settings.brokerMaxFrameBytes, instanceId: started.instanceId, leased: true, controlMaxBytes: started.controlMaxBytes, ...(started.inputProtocolVersion === 2 ? { inputProtocolVersion: 2, recoverDisconnect: true } : {}), ...(coldStore ? { messageInput: true, beforeMessage, afterMessage } : {}), attach: (after = 0) => io.attach(command(['attach', id, '--after', String(after), '--framed', '--leased', ...(started.inputProtocolVersion === 2 ? ['--input-protocol', '2'] : []), ...(coldStore ? ['--message-input'] : []), '--if-instance', started.instanceId])) });
|
|
68
|
+
const reconnectOff = started.inputProtocolVersion === 2 ? _get()?.onConnectionState?.(state => { if (state.phase === 'connected' && !channel.online)
|
|
69
|
+
void channel.connect().catch(() => { }); }) : undefined;
|
|
40
70
|
let ended = false;
|
|
41
|
-
const
|
|
71
|
+
const detach = async (cause = { layer: 'broker', initiator: 'broker.detach', reason: 'SESSION_DETACHED', action: 'detach' }) => {
|
|
42
72
|
if (ended)
|
|
43
73
|
return;
|
|
44
74
|
ended = true;
|
|
75
|
+
reconnectOff?.();
|
|
45
76
|
diagnostics.record(cause);
|
|
46
77
|
channel.close(cause);
|
|
78
|
+
};
|
|
79
|
+
const dispose = async (cause = { layer: 'broker', initiator: 'broker.dispose', reason: 'BROKER_DISPOSE', action: 'dispose' }) => {
|
|
80
|
+
if (ended)
|
|
81
|
+
return;
|
|
82
|
+
if (channel.supportsRecovery) {
|
|
83
|
+
const attachmentId = channel.attachmentId;
|
|
84
|
+
await detach(cause);
|
|
85
|
+
if (attachmentId)
|
|
86
|
+
void io.run(command(['kill', id, '--if-instance', started.instanceId, '--if-attachment', attachmentId])).catch(() => console.warn('[remote-agent] 原写者已分离或更换,主机按既有生命周期保留原轮'));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
await detach(cause);
|
|
47
90
|
void io.run(command(['kill', id, '--if-instance', started.instanceId])).catch(() => console.warn('[remote-agent] 旧主机会话暂未清理,将由主机自动回收'));
|
|
48
91
|
};
|
|
49
92
|
const aborted = () => channel.fail(new NeedError('ABORTED', '本轮已取消。', '确认主机状态'), { layer: 'broker', initiator: 'broker.open-signal', reason: 'ABORTED', action: 'abort' });
|
|
@@ -61,6 +104,6 @@ export function brokerFactory(_get, _ask, configuration, provided) {
|
|
|
61
104
|
finally {
|
|
62
105
|
request.signal?.removeEventListener('abort', aborted);
|
|
63
106
|
}
|
|
64
|
-
return { identity: identity(target), cwd: project.path, closeDiagnostics: diagnostics, broker: channel, sessionOwnership, acpTransport: channel, dispose, detach: dispose };
|
|
107
|
+
return { ...(coldStore ? { cold: { id: roundId, store: coldStore, prepare: async (nativeId, meta) => { await coldStore.update(request.sessionId, agent.id, roundId, row => { row.nativeId = nativeId; row.meta = structuredClone(meta); }); } } } : {}), identity: identity(target), cwd: project.path, closeDiagnostics: diagnostics, broker: channel, sessionOwnership, acpTransport: channel, dispose, detach: channel.supportsRecovery ? detach : dispose };
|
|
65
108
|
};
|
|
66
109
|
}
|
package/dist/broker.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ColdWrite } from './cold-store.ts';
|
|
1
2
|
import { type CloseCause, type CloseObserver } from './close-diagnostics.ts';
|
|
2
3
|
import { type ChildProcessWithoutNullStreams } from 'node:child_process';
|
|
3
4
|
import { NeedError, type Need } from './remote.ts';
|
|
@@ -9,7 +10,22 @@ export interface BrokerOptions {
|
|
|
9
10
|
instanceId?: string;
|
|
10
11
|
leased?: boolean;
|
|
11
12
|
controlMaxBytes?: number;
|
|
12
|
-
attach: () => Promise<Attachment>;
|
|
13
|
+
attach: (after?: number) => Promise<Attachment>;
|
|
14
|
+
inputProtocolVersion?: 2;
|
|
15
|
+
recoverDisconnect?: boolean;
|
|
16
|
+
messageInput?: boolean;
|
|
17
|
+
initialSequence?: number;
|
|
18
|
+
restoreInput?: {
|
|
19
|
+
sequence: number;
|
|
20
|
+
pending?: ColdWrite;
|
|
21
|
+
};
|
|
22
|
+
beforeMessage?: (bytes: Uint8Array, message: {
|
|
23
|
+
id: string;
|
|
24
|
+
sha256: string;
|
|
25
|
+
chunkBytes: number;
|
|
26
|
+
baseSequence: number;
|
|
27
|
+
}) => Promise<void>;
|
|
28
|
+
afterMessage?: (sequence: number) => Promise<void>;
|
|
13
29
|
onNeed?: (need: Need) => void;
|
|
14
30
|
}
|
|
15
31
|
/** One byte stream / SDK app over one SSH attachment of a new agent. Input is never replayed. */
|
|
@@ -20,6 +36,30 @@ export declare class BrokerTransport {
|
|
|
20
36
|
private output;
|
|
21
37
|
private attachment?;
|
|
22
38
|
private cursor;
|
|
39
|
+
get lastSequence(): number;
|
|
40
|
+
private receipt;
|
|
41
|
+
get inputReceipt(): any;
|
|
42
|
+
private controlWait?;
|
|
43
|
+
private resendControl;
|
|
44
|
+
private controlMessage;
|
|
45
|
+
completeRestoredInput(): void;
|
|
46
|
+
discardMessage(id: string): Promise<any>;
|
|
47
|
+
observeMessage(id: string): Promise<any>;
|
|
48
|
+
resumeMessage(write: ColdWrite): Promise<void>;
|
|
49
|
+
private attachedId?;
|
|
50
|
+
get attachmentId(): string | undefined;
|
|
51
|
+
private inputSequence;
|
|
52
|
+
private inputReady;
|
|
53
|
+
private pendingInput?;
|
|
54
|
+
private recoveryTimer?;
|
|
55
|
+
private recoveryIntervalMs?;
|
|
56
|
+
private everReady;
|
|
57
|
+
get recovering(): boolean;
|
|
58
|
+
get supportsRecovery(): boolean;
|
|
59
|
+
confirmReplay(generation: unknown): void;
|
|
60
|
+
private recover;
|
|
61
|
+
private waitInput;
|
|
62
|
+
private acknowledge;
|
|
23
63
|
private epoch;
|
|
24
64
|
private attached;
|
|
25
65
|
private ended;
|