@ai-workbench/remote-agent 0.9.0-toolbridge.14 → 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 +4 -4
- package/dist/acp.js +8 -1
- package/dist/broker-runtime.d.ts +2 -0
- package/dist/broker-runtime.js +30 -2
- package/dist/broker.d.ts +24 -0
- package/dist/broker.js +66 -10
- package/dist/claude-local.js +1 -1
- 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-provider.js +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +59 -25
- package/dist/provider.d.ts +11 -0
- package/dist/session-source.d.ts +3 -1
- package/dist/session-source.js +2 -1
- package/package.json +11 -10
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ColdRecovery } from "./cold-recovery.js";
|
|
1
2
|
import { createSteeringReceipts, installLiveSteering, steeringMessageDigest } from "./live-steering.js";
|
|
2
3
|
import { ToolBridgeLoop } from "./toolbridge-loop.js";
|
|
3
4
|
import { openToolBridgeMcp, TOOLBRIDGE_NOTICE } from "./toolbridge.js";
|
|
@@ -96,6 +97,7 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
96
97
|
preflightDiagnostics;
|
|
97
98
|
permissions;
|
|
98
99
|
steeringReceipts;
|
|
100
|
+
coldRecovery;
|
|
99
101
|
bridgeLoop;
|
|
100
102
|
config;
|
|
101
103
|
sessions = new Map();
|
|
@@ -107,7 +109,7 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
107
109
|
modelPresentation = new ModelPresentation();
|
|
108
110
|
employeeNoticeSessions = new Set();
|
|
109
111
|
pendingEmployeeNotices = new Set();
|
|
110
|
-
constructor(config, resolveRuntime, approve, providerName = () => CODEX_AGENT.name.zh, agent = CODEX_AGENT, readImage, reportLoginFailure, directory, preflightDiagnostics, permissions, bridgeStopped, steeringReceipts) {
|
|
112
|
+
constructor(config, resolveRuntime, approve, providerName = () => CODEX_AGENT.name.zh, agent = CODEX_AGENT, readImage, reportLoginFailure, directory, preflightDiagnostics, permissions, bridgeStopped, steeringReceipts, coldRecovery) {
|
|
111
113
|
super();
|
|
112
114
|
this.resolveRuntime = resolveRuntime;
|
|
113
115
|
this.approve = approve;
|
|
@@ -119,6 +121,7 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
119
121
|
this.preflightDiagnostics = preflightDiagnostics;
|
|
120
122
|
this.permissions = permissions;
|
|
121
123
|
this.steeringReceipts = steeringReceipts;
|
|
124
|
+
this.coldRecovery = coldRecovery;
|
|
122
125
|
this.bridgeLoop = new ToolBridgeLoop(readImage, bridgeStopped, (id, message) => this.injectedInputs.get(id)?.get(message.id) === steeringMessageDigest(message));
|
|
123
126
|
this.config = typeof config === 'function' ? config : () => config;
|
|
124
127
|
}
|
|
@@ -204,6 +207,9 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
204
207
|
catalog.release();
|
|
205
208
|
} }
|
|
206
209
|
async resolveModel(provider, id, signal) {
|
|
210
|
+
const recovered = this.coldRecovery?.recoveryModel(provider, id, signal);
|
|
211
|
+
if (recovered)
|
|
212
|
+
return recovered;
|
|
207
213
|
const displayed = this.modelPresentation.resolve(provider, id);
|
|
208
214
|
if (displayed)
|
|
209
215
|
return displayed;
|
|
@@ -285,6 +291,17 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
285
291
|
throw failure.reason;
|
|
286
292
|
}
|
|
287
293
|
async *stream(options) {
|
|
294
|
+
if (this.coldRecovery?.canRecover(options)) {
|
|
295
|
+
try {
|
|
296
|
+
yield* this.coldRecovery.stream(options);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
if (error instanceof NeedError)
|
|
301
|
+
throw new LlmError(error.message, error.code, { cause: error });
|
|
302
|
+
throw error;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
288
305
|
// Before the tool bridge: a parked turn must not take a background request for its own continuation.
|
|
289
306
|
if (options.purpose)
|
|
290
307
|
throw new LlmError(employeeFailure('PURPOSE_UNSUPPORTED', this.agent.loginProvider, false), 'PURPOSE_UNSUPPORTED');
|
|
@@ -335,7 +352,7 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
335
352
|
if (key)
|
|
336
353
|
this.turns.set(key, turn);
|
|
337
354
|
const signal = AbortSignal.any([this.lifetime.signal, turn.signal, ...(original.signal ? [original.signal] : [])]);
|
|
338
|
-
|
|
355
|
+
let options = { ...original, signal };
|
|
339
356
|
const abortOffs = [];
|
|
340
357
|
let bridgeMcp;
|
|
341
358
|
let request;
|
|
@@ -352,6 +369,7 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
352
369
|
let selected;
|
|
353
370
|
let modelConfiguration;
|
|
354
371
|
let turnFailure;
|
|
372
|
+
let coldPrelude = '';
|
|
355
373
|
let employeeNoticeShown = false;
|
|
356
374
|
let permissionOff;
|
|
357
375
|
let permissionEpoch = new AbortController();
|
|
@@ -373,7 +391,12 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
373
391
|
try {
|
|
374
392
|
if (!Number.isSafeInteger(config.acpMaxMessageBytes) || config.acpMaxMessageBytes < 1)
|
|
375
393
|
throw new NeedError('SETTINGS_REQUIRED', '远程模型连接设置无效,请联系管理员检查', '有效的acpMaxMessageBytes');
|
|
376
|
-
const
|
|
394
|
+
const standardCheckpoint = readPointer(options, this.agent), recoveredCheckpoint = await this.coldRecovery?.previousPointer(options);
|
|
395
|
+
const checkpoint = recoveredCheckpoint && (!standardCheckpoint || recoveredCheckpoint.index > standardCheckpoint.index) ? recoveredCheckpoint : standardCheckpoint, previous = checkpoint?.pointer;
|
|
396
|
+
const usedColdCheckpoint = !!recoveredCheckpoint && checkpoint === recoveredCheckpoint;
|
|
397
|
+
const checkpointIndex = usedColdCheckpoint ? -1 : checkpoint?.index ?? -1;
|
|
398
|
+
if (usedColdCheckpoint)
|
|
399
|
+
options = { ...options, messages: options.messages.filter((m, index) => index > checkpoint.index || m.role === 'system' || m.role === 'developer') };
|
|
377
400
|
employeeNoticeShown = !!key && this.employeeNoticeSessions.has(key) || false;
|
|
378
401
|
if (employeeNoticeShown && key)
|
|
379
402
|
this.employeeNoticeSessions.add(key);
|
|
@@ -408,7 +431,7 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
408
431
|
succeeded = true;
|
|
409
432
|
return;
|
|
410
433
|
}
|
|
411
|
-
const projected = { ...options, messages: options.messages.filter((m, index) => index <=
|
|
434
|
+
const projected = { ...options, messages: options.messages.filter((m, index) => index <= checkpointIndex || !('id' in m) || typeof m.id !== 'string' || !injected.has(m.id)) };
|
|
412
435
|
earlyStage = 'input-prepare';
|
|
413
436
|
let input = await prepareInput(projected, this.readImage);
|
|
414
437
|
const contextSha256 = createHash('sha256').update(input.systemPrompt ?? '').digest('hex');
|
|
@@ -438,7 +461,7 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
438
461
|
}
|
|
439
462
|
if (previous && !runtime.hostSource && (previous.identity !== runtime.identity || previous.cwd !== runtime.cwd || previous.bindingId && previous.bindingId !== runtime.binding?.bindingId || previous.workspaceId && previous.workspaceId !== runtime.binding?.workspaceId))
|
|
440
463
|
throw new NeedError('SESSION_CONTEXT_MISMATCH', '原会话的员工主机或工作区已改变,请新建会话', '原会话的可信目标和工作区');
|
|
441
|
-
input = await prepareContinuation({ ...options, messages: projected.messages.slice(
|
|
464
|
+
input = await prepareContinuation({ ...options, messages: projected.messages.slice(checkpointIndex + 1) }, input, this.readImage, { maxBytes: config.acpMaxMessageBytes, host: runtime.hostWorkspace });
|
|
442
465
|
if (runtime.hostWorkspace && mode === 'session' && Buffer.byteLength(JSON.stringify({ prompt: input.prompt, systemPrompt: input.systemPrompt }), 'utf8') > config.acpMaxMessageBytes)
|
|
443
466
|
throw new NeedError('ACP_MESSAGE_TOO_LARGE', '本轮输入超过已设置的会话消息容量,未截断或发送', '管理员调整acpMaxMessageBytes');
|
|
444
467
|
const details = runtime.details ?? await createRemoteDetails({ warn: line => console.warn(line) }).open({ sessionId: options.sessionId ?? 'unscoped', provider: this.agent.loginProvider, identity: runtime.identity, connection: runtime.connection });
|
|
@@ -457,13 +480,14 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
457
480
|
let id;
|
|
458
481
|
let stop;
|
|
459
482
|
const pointerRuntime = runtime;
|
|
460
|
-
const makePointer = (nativeId) => ({ ...(pointerRuntime.hostSource ? { hostSource: pointerRuntime.hostSource } : {}), ...(modelConfiguration ? { modelConfiguration } : {}), version: 2, agent: this.agent.id, contextSha256, ...(mode === 'session' ? { usageSnapshot: mapper.usageSnapshot } : {}), ...(options.sessionId ? { dshSessionId: options.sessionId } : {}), identity: pointerRuntime.identity, cwd: pointerRuntime.cwd, sessionId: nativeId, ...(pointerRuntime.binding ? { bindingId: pointerRuntime.binding.bindingId, workspaceId: pointerRuntime.binding.workspaceId } : {}) });
|
|
483
|
+
const makePointer = (nativeId) => ({ ...(pointerRuntime.cold ? { coldRoundId: pointerRuntime.cold.id } : {}), ...(pointerRuntime.hostSource ? { hostSource: pointerRuntime.hostSource } : {}), ...(modelConfiguration ? { modelConfiguration } : {}), version: 2, agent: this.agent.id, contextSha256, ...(mode === 'session' ? { usageSnapshot: mapper.usageSnapshot } : {}), ...(options.sessionId ? { dshSessionId: options.sessionId } : {}), identity: pointerRuntime.identity, cwd: pointerRuntime.cwd, sessionId: nativeId, ...(pointerRuntime.binding ? { bindingId: pointerRuntime.binding.bindingId, workspaceId: pointerRuntime.binding.workspaceId } : {}) });
|
|
461
484
|
if (runtime.employeePresentation)
|
|
462
485
|
details.record({ kind: 'session', severity: 'warning', code: 'EMPLOYEE_EXECUTION_SCOPE', summary: runtime.employeePresentation, payload: { source: 'local' } });
|
|
463
486
|
if (runtime.execution)
|
|
464
487
|
details.record({ kind: 'session', severity: 'warning', code: 'CLAUDE_EMPLOYEE_SCOPE', summary: runtime.execution.notice, payload: runtime.execution.scope });
|
|
465
488
|
if ((runtime.employeePresentation || runtime.execution) && !employeeNoticeShown) {
|
|
466
|
-
|
|
489
|
+
coldPrelude = EMPLOYEE_EXECUTION_NOTICE + (bridge?.enabled ? '\n\n' + TOOLBRIDGE_NOTICE : '') + '\n\n';
|
|
490
|
+
for (const chunk of mapper.text(coldPrelude)) {
|
|
467
491
|
if (chunk.type === 'text-delta') {
|
|
468
492
|
employeeNoticeShown = true;
|
|
469
493
|
if (key) {
|
|
@@ -485,6 +509,10 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
485
509
|
let done = false;
|
|
486
510
|
let failure;
|
|
487
511
|
const push = (chunks) => { queue.push(...chunks); wake?.(); wake = undefined; };
|
|
512
|
+
let renderTail = Promise.resolve(), nativeUpdates = 0, coldPromptStarted = false;
|
|
513
|
+
const render = (work) => { renderTail = renderTail.then(work); void renderTail.catch(error => { failure ??= error; session?.close({ layer: 'adapter', initiator: 'adapter.render-failure', reason: closeCode(error, 'MAPPING_FAILED'), action: 'close' }); wake?.(); }); };
|
|
514
|
+
const renderNotice = (text) => render(async () => { if (runtime.cold)
|
|
515
|
+
await runtime.cold.store.update(options.sessionId, options.provider, runtime.cold.id, row => { (row.localNotices ??= []).push({ beforeUpdate: nativeUpdates, text }); }); push(mapper.text(text)); });
|
|
488
516
|
let promptPermit;
|
|
489
517
|
let confirmedNativeMode;
|
|
490
518
|
const hooks = { closeDiagnostics: runtime.closeDiagnostics, broker: runtime.broker, sessionOwnership: runtime.sessionOwnership, employeeExecution: runtime.employeeExecution, ...this.permissions ? { promptGuard: () => {
|
|
@@ -511,23 +539,17 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
511
539
|
if (execution) {
|
|
512
540
|
if (toolName && ['Agent', 'Task', 'TaskOutput', 'TaskStop', 'Read', 'Write', 'Edit', 'Glob', 'Grep', 'Bash'].includes(toolName)) {
|
|
513
541
|
details.record({ kind: 'need', severity: 'warning', code: 'CLAUDE_HOST_TOOL_UNSUPPORTED', summary: '这类原生调用没有经过员工端别名,本机来源不支持;本次审批已取消', payload: { operation: toolName } });
|
|
514
|
-
|
|
542
|
+
renderNotice('\n这类操作尚不支持在本机执行,已取消本次审批,没有在主机代跑。\n');
|
|
515
543
|
return 'cancelled';
|
|
516
544
|
}
|
|
517
545
|
}
|
|
518
546
|
const answer = await this.approve?.(permission, approvalSignal, options, execution && toolName?.startsWith('mcp__employee__') ? 'employee-local' : undefined, runtime.hostWorkspace) ?? 'unavailable';
|
|
519
547
|
return answer;
|
|
520
|
-
}, onEmployeeNotice: notice =>
|
|
521
|
-
|
|
522
|
-
push(mapper.acp(notification.update));
|
|
523
|
-
}
|
|
524
|
-
catch (error) {
|
|
525
|
-
failure = error;
|
|
526
|
-
session?.close({ layer: 'adapter', initiator: 'adapter.mapper-failure', reason: closeCode(error, 'MAPPING_FAILED'), action: 'close' });
|
|
527
|
-
} }, onResponse: response => push(mapper.acpResponse(response)), onDetail: detail => details.record(detail) };
|
|
548
|
+
}, onEmployeeNotice: notice => renderNotice(notice + '\n\n'), onUpdate: notification => { const fromPrompt = coldPromptStarted; render(() => { bridge?.observe(notification.update); push(mapper.acp(notification.update)); if (fromPrompt)
|
|
549
|
+
nativeUpdates++; }); }, onResponse: response => render(() => { push(mapper.acpResponse(response)); }), onDetail: detail => details.record(detail) };
|
|
528
550
|
const transport = runtime.acpTransport instanceof acp.AgentApp || runtime.acpTransport instanceof unstable.AgentApp ? runtime.acpTransport : acp.ndJsonStream(runtime.acpTransport.writable, runtime.acpTransport.readable, { maxMessageBytes: config.acpMaxMessageBytes });
|
|
529
551
|
session = new AcpSession(transport, hooks);
|
|
530
|
-
live = { session, runtime, configuration, contextSha256, usageSnapshot: mapper.usageSnapshot, options, acceptingSteer: true, turnId: randomUUID(), steerIds: new Map(), steerTail: Promise.resolve(), maxBytes: config.acpMaxMessageBytes, notice:
|
|
552
|
+
live = { session, runtime, configuration, contextSha256, usageSnapshot: mapper.usageSnapshot, options, acceptingSteer: true, turnId: randomUUID(), steerIds: new Map(), steerTail: Promise.resolve(), maxBytes: config.acpMaxMessageBytes, notice: renderNotice };
|
|
531
553
|
if (key)
|
|
532
554
|
this.sessions.set(key, live);
|
|
533
555
|
promptBaseline = session.promptDispatchCount;
|
|
@@ -624,6 +646,10 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
624
646
|
}
|
|
625
647
|
recordInformation();
|
|
626
648
|
details.beginTurn(runtime.detailContext?.() ?? { turn: null, step: null });
|
|
649
|
+
await renderTail;
|
|
650
|
+
if (runtime.cold && this.coldRecovery)
|
|
651
|
+
await this.coldRecovery.capture(runtime, options, session.id, { identity: runtime.identity, cwd: runtime.cwd, binding: runtime.binding, hostSource: runtime.hostSource, contextSha256, baseline: mapper.usageSnapshot, modelConfiguration, model: options.model, prelude: coldPrelude, localDirectory: runtime.localDirectory });
|
|
652
|
+
coldPromptStarted = true;
|
|
627
653
|
await runtime.execution?.beginTurn(modelSignal);
|
|
628
654
|
if (bridge?.enabled)
|
|
629
655
|
bridge.replayState = { response: makePointer(session.id) };
|
|
@@ -666,7 +692,7 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
666
692
|
details.endTurn();
|
|
667
693
|
}
|
|
668
694
|
})();
|
|
669
|
-
void task.then(value => { stop = value; }, error => { failure ??= runtime.broker?.error ?? error; }).finally(() => { done = true; wake?.(); wake = undefined; });
|
|
695
|
+
void task.then(value => { stop = value; }, error => { failure ??= runtime.broker?.error ?? error; }).then(async () => { await renderTail; }, error => { failure ??= error; }).catch(error => { failure ??= error; }).finally(() => { done = true; wake?.(); wake = undefined; });
|
|
670
696
|
while (!done || queue.length) {
|
|
671
697
|
if (queue.length)
|
|
672
698
|
yield queue.shift();
|
|
@@ -696,7 +722,8 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
696
722
|
}
|
|
697
723
|
}
|
|
698
724
|
yield* mapper.flush();
|
|
699
|
-
const
|
|
725
|
+
const finalCold = runtime.cold ? await runtime.cold.store.update(options.sessionId, options.provider, runtime.cold.id, row => { row.finalUsage = mapper.usageSnapshot; row.terminal = { kind: 'result', value: { stopReason: stop } }; row.phase = 'terminal'; row.terminalAfter = runtime.broker?.lastSequence; }) : undefined;
|
|
726
|
+
const pointer = { ...makePointer(id), ...(finalCold ? { coldRoundTerminal: true, coldPromptId: finalCold.promptId, coldOutputAfter: runtime.broker?.lastSequence } : {}) };
|
|
700
727
|
succeeded = true;
|
|
701
728
|
yield { type: 'finish', reason: { kind: stop === 'max_tokens' || stop === 'max_turn_requests' ? 'max-tokens' : 'stop' }, replayState: { response: pointer } };
|
|
702
729
|
}
|
|
@@ -727,10 +754,15 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
727
754
|
if (bridgeMcp)
|
|
728
755
|
await bridgeMcp.close();
|
|
729
756
|
if (runtime) {
|
|
757
|
+
if (runtime.cold && key)
|
|
758
|
+
this.coldRecovery?.release(key, runtime.cold.id);
|
|
730
759
|
session?.close({ layer: 'adapter', initiator: 'adapter.turn-finally', reason: succeeded ? 'TURN_FINISHED' : 'TURN_FAILED', action: 'close' });
|
|
731
760
|
if (key && this.sessions.get(key) === live)
|
|
732
761
|
this.sessions.delete(key);
|
|
733
|
-
|
|
762
|
+
if (session && session.promptDispatchCount > promptBaseline && (runtime.cold || this.shuttingDown || key && this.detached.has(key) || original.signal?.reason?.kind === 'disposed'))
|
|
763
|
+
void runtime.detach?.({ layer: 'adapter', initiator: 'adapter.preserve-original', reason: 'SESSION_DETACHED', action: 'detach' });
|
|
764
|
+
else
|
|
765
|
+
void this.cleanupRuntime(runtime);
|
|
734
766
|
}
|
|
735
767
|
if (key && this.turns.get(key) === turn)
|
|
736
768
|
this.turns.delete(key);
|
|
@@ -743,8 +775,8 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
743
775
|
/** One official registration owns both routes, preserving opaque replay ownership. */
|
|
744
776
|
export class RemoteAgentsAdapter extends LlmAdapter {
|
|
745
777
|
adapters = new Map();
|
|
746
|
-
constructor(config, makeRuntime, approve, nameFor, readImage, reportLoginFailure, directory, preflightDiagnostics, permissions, bridgeStopped, steeringReceipts) { super(); for (const agent of AGENTS)
|
|
747
|
-
this.adapters.set(agent.id, new CodexRemoteAdapter(config, makeRuntime(agent), approve, () => nameFor(agent), agent, readImage, reportLoginFailure, directory, preflightDiagnostics, permissions, bridgeStopped, steeringReceipts)); }
|
|
778
|
+
constructor(config, makeRuntime, approve, nameFor, readImage, reportLoginFailure, directory, preflightDiagnostics, permissions, bridgeStopped, steeringReceipts, coldRecovery) { super(); for (const agent of AGENTS)
|
|
779
|
+
this.adapters.set(agent.id, new CodexRemoteAdapter(config, makeRuntime(agent), approve, () => nameFor(agent), agent, readImage, reportLoginFailure, directory, preflightDiagnostics, permissions, bridgeStopped, steeringReceipts, coldRecovery)); }
|
|
748
780
|
adapter(provider) { const adapter = this.adapters.get(provider); if (!adapter)
|
|
749
781
|
throw new LlmError('远程模型未注册', 'PROVIDER_NOT_FOUND'); return adapter; }
|
|
750
782
|
providerInfo(provider) { return this.adapter(provider).providerInfo(provider); }
|
|
@@ -778,7 +810,9 @@ export function apply(ctx, live) {
|
|
|
778
810
|
throw new NeedError('ATTACHMENT_REQUIRED', '我需要官方附件组件读取这张图片', '官方attachments.readImage');
|
|
779
811
|
return attachments.readImage(ref, signal);
|
|
780
812
|
};
|
|
781
|
-
const
|
|
813
|
+
const sessionSources = createSessionSources(ctx, get);
|
|
814
|
+
const coldRecovery = new ColdRecovery(ctx, get, config, { readSource: sessionSources.read });
|
|
815
|
+
const openByAgent = new Map(AGENTS.map(agent => [agent.id, brokerFactory(get, undefined, config, { coldStore: coldRecovery.store })]));
|
|
782
816
|
const detailManagers = new Map();
|
|
783
817
|
const managerForProfile = () => {
|
|
784
818
|
const profile = ctx.get('profileContext');
|
|
@@ -791,7 +825,6 @@ export function apply(ctx, live) {
|
|
|
791
825
|
return manager;
|
|
792
826
|
};
|
|
793
827
|
ctx.provide('aiWorkbenchRemoteDiagnostics', { read: (query) => managerForProfile().read(query) });
|
|
794
|
-
const sessionSources = createSessionSources(ctx, get);
|
|
795
828
|
const preflightDiagnostics = createPreflightDiagnostics({ ctx, getApi: get, manager: managerForProfile });
|
|
796
829
|
const diagnostics = new Map();
|
|
797
830
|
const diagnostic = (scope, provider, message) => {
|
|
@@ -890,7 +923,8 @@ export function apply(ctx, live) {
|
|
|
890
923
|
if (turn !== null && step !== null)
|
|
891
924
|
agent.session.append('assistant/message', { turn, step, message: createAssistantMessage({ content: [{ type: 'text', text: notice }], source: { provider: 'ai-workbench-toolbridge', model: 'notice' } }), stream: [] }, { surfaceOp: 'append' });
|
|
892
925
|
agent.cancel({ kind: 'hook', reason: 'DSH_BRIDGE_CALL_ABANDONED_BY_HOST' }, { keepInbox: true });
|
|
893
|
-
}, steeringReceipts);
|
|
926
|
+
}, steeringReceipts, coldRecovery);
|
|
927
|
+
coldRecovery.install();
|
|
894
928
|
installLiveSteering(ctx, adapter);
|
|
895
929
|
ctx.on('session/event', (session, event) => { if (event.type === 'turn/end') {
|
|
896
930
|
const operation = event.data.reason.kind === 'completed' ? adapter.completeDshTurn(session.id, session.deriveMessages()) : adapter.disposeSession(session.id);
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ColdRound, ColdStore } from './cold-store.ts';
|
|
1
2
|
import type { ToolBridge } from './toolbridge.ts';
|
|
2
3
|
import { type SessionSource } from './host-workspace.ts';
|
|
3
4
|
import type { CloseCause, CloseDiagnostics } from './close-diagnostics.ts';
|
|
@@ -27,6 +28,16 @@ export interface EmployeeExecution {
|
|
|
27
28
|
validate(signal?: AbortSignal): Promise<void>;
|
|
28
29
|
}
|
|
29
30
|
export interface Runtime {
|
|
31
|
+
localDirectory?: {
|
|
32
|
+
path: string;
|
|
33
|
+
device: number;
|
|
34
|
+
inode: number;
|
|
35
|
+
};
|
|
36
|
+
cold?: {
|
|
37
|
+
id: string;
|
|
38
|
+
store: ColdStore;
|
|
39
|
+
prepare: (nativeId: string, meta: NonNullable<ColdRound['meta']>) => Promise<void>;
|
|
40
|
+
};
|
|
30
41
|
identity: string;
|
|
31
42
|
cwd: string;
|
|
32
43
|
hostWorkspace?: Readonly<HostWorkspacePresentation>;
|
package/dist/session-source.d.ts
CHANGED
|
@@ -15,4 +15,6 @@ export declare const sessionSourceSpec: {
|
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
17
|
/** Official domain metadata, keyed by native session ID. No L files, local path probes or host identity hashes. */
|
|
18
|
-
export declare function createSessionSources(ctx: Context, getApi: () => ConnectApi | undefined): (request: RuntimeRequest, api: ConnectApi) => Promise<SessionSource | undefined
|
|
18
|
+
export declare function createSessionSources(ctx: Context, getApi: () => ConnectApi | undefined): ((request: RuntimeRequest, api: ConnectApi) => Promise<SessionSource | undefined>) & {
|
|
19
|
+
read: (sessionId: string) => Promise<SessionSource | undefined>;
|
|
20
|
+
};
|
package/dist/session-source.js
CHANGED
|
@@ -79,7 +79,7 @@ export function createSessionSources(ctx, getApi) {
|
|
|
79
79
|
return;
|
|
80
80
|
void save(session, api).catch(() => ctx.logger('remote-agent').warn('会话文件来源暂未保存;发送时将重试'));
|
|
81
81
|
});
|
|
82
|
-
|
|
82
|
+
const resolve = async (request, api) => {
|
|
83
83
|
if (!request.sessionId || api.getContractInfo?.().workspaceLocations !== 1 && !request.hostSource)
|
|
84
84
|
return;
|
|
85
85
|
const session = ctx.get('sessions')?.get(SessionId(request.sessionId));
|
|
@@ -87,4 +87,5 @@ export function createSessionSources(ctx, getApi) {
|
|
|
87
87
|
throw storageNeed();
|
|
88
88
|
return save(session, api, request);
|
|
89
89
|
};
|
|
90
|
+
return Object.assign(resolve, { read: async (sessionId) => { const source = (await open()).table('sessions').get(sessionId); return source ? Object.freeze({ ...source }) : undefined; } });
|
|
90
91
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-workbench/remote-agent",
|
|
3
|
-
"version": "0.9.0-toolbridge.
|
|
3
|
+
"version": "0.9.0-toolbridge.15",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -53,8 +53,14 @@
|
|
|
53
53
|
"@deepseek-ai/dsh-client-ui-settings": "0.2.0-rc.2",
|
|
54
54
|
"@deepseek-ai/dsh-compaction-basic": "0.2.0-rc.2",
|
|
55
55
|
"@deepseek-ai/dsh-llm": "0.2.0-rc.2",
|
|
56
|
+
"@deepseek-ai/dsh-sandbox-policy": "0.2.0-rc.2",
|
|
56
57
|
"@deepseek-ai/dsh-session": "0.2.0-rc.2",
|
|
58
|
+
"@deepseek-ai/dsh-session-persistence-jsonl": "0.2.0-rc.2",
|
|
59
|
+
"@deepseek-ai/dsh-session-projection": "0.2.0-rc.2",
|
|
60
|
+
"@deepseek-ai/dsh-storage-domain": "0.2.0-rc.2",
|
|
61
|
+
"@deepseek-ai/dsh-system-prompt": "0.2.0-rc.2",
|
|
57
62
|
"@deepseek-ai/dsh-token-meter": "0.2.0-rc.2",
|
|
63
|
+
"@deepseek-ai/dsh-tools": "0.2.0-rc.2",
|
|
58
64
|
"@deepseek-ai/dsh-typert-protocol": "0.2.0-rc.2",
|
|
59
65
|
"@deepseek-ai/dsh-typert-registry": "0.2.0-rc.2",
|
|
60
66
|
"@deepseek-ai/dsh-user-approval": "0.2.0-rc.2",
|
|
@@ -65,12 +71,7 @@
|
|
|
65
71
|
"react": "18.3.1",
|
|
66
72
|
"react-dom": "18.3.1",
|
|
67
73
|
"typescript": "5.9.3",
|
|
68
|
-
"zustand": "4.4.7"
|
|
69
|
-
"@deepseek-ai/dsh-sandbox-policy": "0.2.0-rc.2",
|
|
70
|
-
"@deepseek-ai/dsh-storage-domain": "0.2.0-rc.2",
|
|
71
|
-
"@deepseek-ai/dsh-session-projection": "0.2.0-rc.2",
|
|
72
|
-
"@deepseek-ai/dsh-system-prompt": "0.2.0-rc.2",
|
|
73
|
-
"@deepseek-ai/dsh-tools": "0.2.0-rc.2"
|
|
74
|
+
"zustand": "4.4.7"
|
|
74
75
|
},
|
|
75
76
|
"peerDependencies": {
|
|
76
77
|
"@ai-workbench/connect": "~0.7.37",
|
|
@@ -79,12 +80,12 @@
|
|
|
79
80
|
"@deepseek-ai/dsh-agent": ">=0.2.0-rc.2 <0.3.0-0",
|
|
80
81
|
"@deepseek-ai/dsh-attachment": ">=0.2.0-rc.2 <0.3.0-0",
|
|
81
82
|
"@deepseek-ai/dsh-llm": ">=0.2.0-rc.2 <0.3.0-0",
|
|
83
|
+
"@deepseek-ai/dsh-sandbox-policy": ">=0.2.0-rc.2 <0.3.0-0",
|
|
82
84
|
"@deepseek-ai/dsh-session": ">=0.2.0-rc.2 <0.3.0-0",
|
|
85
|
+
"@deepseek-ai/dsh-storage-domain": ">=0.2.0-rc.2 <0.3.0-0",
|
|
83
86
|
"@deepseek-ai/dsh-typert-protocol": ">=0.2.0-rc.2 <0.3.0-0",
|
|
84
87
|
"@deepseek-ai/dsh-user-approval": ">=0.2.0-rc.2 <0.3.0-0",
|
|
85
|
-
"@deepseek-ai/schemastery": "^3.18.4"
|
|
86
|
-
"@deepseek-ai/dsh-sandbox-policy": ">=0.2.0-rc.2 <0.3.0-0",
|
|
87
|
-
"@deepseek-ai/dsh-storage-domain": ">=0.2.0-rc.2 <0.3.0-0"
|
|
88
|
+
"@deepseek-ai/schemastery": "^3.18.4"
|
|
88
89
|
},
|
|
89
90
|
"dsh": {
|
|
90
91
|
"bundle": {
|