@ai-workbench/remote-agent 0.9.0-toolbridge.29 → 0.9.0-toolbridge.30
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 +2 -4
- package/dist/cold-recovery.d.ts +4 -5
- package/dist/cold-recovery.js +17 -18
- package/dist/cold-store.d.ts +1 -1
- package/dist/employee-provider.d.ts +0 -2
- package/dist/employee-provider.js +4 -4
- package/dist/index.js +20 -27
- package/dist/provider.d.ts +0 -1
- package/dist/provider.js +31 -63
- package/dist/toolbridge-table.d.ts +1 -1
- package/dist/toolbridge-table.js +2 -2
- package/dist/toolbridge.js +1 -20
- package/package.json +1 -1
- package/dist/employee-startup.d.ts +0 -18
- package/dist/employee-startup.js +0 -95
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# AI Workbench 远程助手 · @ai-workbench/remote-agent@0.9.0-toolbridge.
|
|
1
|
+
# AI Workbench 远程助手 · @ai-workbench/remote-agent@0.9.0-toolbridge.30 · 插件 → 添加插件
|
|
2
2
|
|
|
3
3
|
## 办公依赖与开工计时(O1,2026-11-15)
|
|
4
4
|
|
|
@@ -87,6 +87,4 @@ Codex 员工端只使用随包提供的原生组件,通道等待本次组件
|
|
|
87
87
|
|
|
88
88
|
模型目录在官方启动读取时获取,并在连接变为 connected 时经官方注册刷新;官方菜单打开或重试读取缓存是 DSH 官方限制,本插件不改官方菜单或核心。真正不支持的推理档位由 DSH 预检,其英文提示保留为观察项。
|
|
89
89
|
|
|
90
|
-
I3(0.9.0-toolbridge.27):同一 DSH 对话的系统规则更新后,续接原 Codex native 线程并在实际模型请求应用新版规则;需要主机含桥 Codex ACP aw.15。规则未变不重复追加历史;每次恢复仍带当前配置以支持压缩重建。用量说明已由 U1(0.9.0-toolbridge.
|
|
91
|
-
|
|
92
|
-
T3(0.9.0-toolbridge.29):在已连接、当前员工目录已接纳的 Codex 路径,同轮登录核验与端点准备重叠;两项均成功并再次核对目标、连接代次与物理目录后才开工,每轮核验与正常完成后结束 broker 的做法保留。当前输入已完整列出同一技能目录时,skill 工具省去重复名字数组;目录不完整或只有历史目录时保留原快照。未改变首轮工具可见性,没有新增设置、限制或错误码。本机受控时延与工具字节测量不代表远机实测速率或实际 API token 节省;DSH 原生本轮因缺独立登录未测。
|
|
90
|
+
I3(0.9.0-toolbridge.27):同一 DSH 对话的系统规则更新后,续接原 Codex native 线程并在实际模型请求应用新版规则;需要主机含桥 Codex ACP aw.15。规则未变不重复追加历史;每次恢复仍带当前配置以支持压缩重建。用量说明已由 U1(0.9.0-toolbridge.30)更正:Codex aw.15 和 Claude 0.94.0 的 ACP 回执均按本次 prompt 统计,逐轮全额结算一次,不减历史基线;旧累计快照不再参与计算。冷接回只减同一 prompt 已在 DSH 落盘的部分,可靠终态先持久化,原 broker 回收后仍可补记其未落盘用量。订阅额度卡仍读取官方额度窗口,不能由 token 数推算百分比。Claude 的规则传递保持。无新增设置、限制或错误码。
|
package/dist/cold-recovery.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { type HostModel } from './model-catalog.ts';
|
|
2
1
|
import type { Context } from '@deepseek-ai/cordis';
|
|
3
2
|
import { type SessionEvent, type SessionHeader } from '@deepseek-ai/dsh-session';
|
|
4
|
-
import { type GenerateOptions, type StreamChunk } from '@deepseek-ai/dsh-llm';
|
|
3
|
+
import { type LlmResolvedModelInfo, type GenerateOptions, type StreamChunk } from '@deepseek-ai/dsh-llm';
|
|
5
4
|
import { type ColdRound, type ColdStore } from './cold-store.ts';
|
|
6
5
|
import { type Runtime, type ConnectApi } from './provider.ts';
|
|
7
6
|
import { type BrokerIo, type SshArgv } from './broker.ts';
|
|
@@ -53,9 +52,9 @@ export declare class ColdRecovery {
|
|
|
53
52
|
projectCancelledInputs(options: GenerateOptions): Promise<GenerateOptions>;
|
|
54
53
|
previousPointer(options: GenerateOptions): Promise<any>;
|
|
55
54
|
release(sessionId: string, id: string): void;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
/** This handle only replays an existing round. Its envelope follows this
|
|
56
|
+
* step's choice; it neither selects nor advertises capabilities for a new model. */
|
|
57
|
+
recoveryModel(provider: string, model: string, signal?: AbortSignal): LlmResolvedModelInfo | undefined;
|
|
59
58
|
canRecover(options: GenerateOptions): boolean;
|
|
60
59
|
private connection;
|
|
61
60
|
stream(options: GenerateOptions, lifetime?: AbortSignal): AsyncGenerator<StreamChunk>;
|
package/dist/cold-recovery.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { watch } from 'node:fs';
|
|
2
2
|
import { dirname } from 'node:path';
|
|
3
3
|
import { lstat, realpath } from 'node:fs/promises';
|
|
4
|
-
import { modelInfo } from "./model-catalog.js";
|
|
5
4
|
import { SessionId } from '@deepseek-ai/dsh-session';
|
|
6
|
-
import { expandAssistantStream, createUserMessage } from '@deepseek-ai/dsh-llm';
|
|
5
|
+
import { expandAssistantStream, createUserMessage, ReasoningEffortId } from '@deepseek-ai/dsh-llm';
|
|
7
6
|
import { isDeepStrictEqual } from 'node:util';
|
|
8
7
|
import { createHash } from 'node:crypto';
|
|
9
8
|
import { createColdStore, coldNeed } from "./cold-store.js";
|
|
@@ -114,8 +113,7 @@ export class ColdRecovery {
|
|
|
114
113
|
const inputDigests = Object.fromEntries(inputs.map(m => [m.id, digest(m)]));
|
|
115
114
|
if (!inputs.length)
|
|
116
115
|
throw coldNeed();
|
|
117
|
-
|
|
118
|
-
await runtime.cold.prepare(nativeId, { ...meta, header, inputDigests, callConfig: { provider, model, reasoningEffort, temperature, maxTokens, stop } });
|
|
116
|
+
await runtime.cold.prepare(nativeId, { ...meta, header, inputDigests });
|
|
119
117
|
await this.store.update(options.sessionId, options.provider, runtime.cold.id, row => { row.originTurn = turn; row.originStep = step; });
|
|
120
118
|
this.live.set(options.sessionId, runtime.cold.id);
|
|
121
119
|
}
|
|
@@ -245,6 +243,7 @@ export class ColdRecovery {
|
|
|
245
243
|
await this.schedule(agent); });
|
|
246
244
|
this.ctx.on('agent/inbox/inserted', ({ agent }) => { this.queueSnapshot(agent); });
|
|
247
245
|
this.ctx.on('agent/pre-step', async (payload, next) => {
|
|
246
|
+
const selection = structuredClone(payload.modelSelection ?? { provider: payload.agent.options.provider, model: payload.agent.options.model, reasoningEffort: payload.agent.options.reasoningEffort });
|
|
248
247
|
const cancellation = this.watchCancellation(payload);
|
|
249
248
|
try {
|
|
250
249
|
const decision = await next();
|
|
@@ -276,7 +275,7 @@ export class ColdRecovery {
|
|
|
276
275
|
if (!row || markers.some(m => recoveryMarker(m) !== row.id) || !['running', 'terminal'].includes(row.phase))
|
|
277
276
|
throw coldNeed('SESSION_CONTEXT_MISMATCH');
|
|
278
277
|
restoreHumans();
|
|
279
|
-
this.steps.set(payload.agent, { turn: payload.turn, step: payload.step, signal: payload.signal, row, markerId: markers[0].id });
|
|
278
|
+
this.steps.set(payload.agent, { turn: payload.turn, step: payload.step, signal: payload.signal, row, markerId: markers[0].id, selection });
|
|
280
279
|
return { ...decision, messages: [...markers, ...decision.messages.filter(m => !claimed.has(m.id) && !recoveryMarker(m))] };
|
|
281
280
|
}
|
|
282
281
|
catch (error) {
|
|
@@ -288,11 +287,10 @@ export class ColdRecovery {
|
|
|
288
287
|
await cancellation?.pending;
|
|
289
288
|
}
|
|
290
289
|
});
|
|
290
|
+
// DSH captures provider/model/effort before pre-step. Recovery reads the old
|
|
291
|
+
// native round privately and must not replace that prepared request envelope.
|
|
291
292
|
this.ctx.on('agent/request', async (payload, next) => { try {
|
|
292
|
-
|
|
293
|
-
if (step && step.turn === payload.turn && step.step === payload.step && step.signal === payload.signal)
|
|
294
|
-
return structuredClone(step.row.meta.callConfig ?? { provider: step.row.provider, model: step.row.meta.model, reasoningEffort: step.row.meta.modelConfiguration?.selected?.effort });
|
|
295
|
-
return config;
|
|
293
|
+
return await next();
|
|
296
294
|
}
|
|
297
295
|
finally {
|
|
298
296
|
await this.cancellationWatches.get(payload.agent)?.pending;
|
|
@@ -357,15 +355,16 @@ export class ColdRecovery {
|
|
|
357
355
|
}
|
|
358
356
|
release(sessionId, id) { if (this.live.get(sessionId) === id)
|
|
359
357
|
this.live.delete(sessionId); }
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
358
|
+
/** This handle only replays an existing round. Its envelope follows this
|
|
359
|
+
* step's choice; it neither selects nor advertises capabilities for a new model. */
|
|
360
|
+
recoveryModel(provider, model, signal) {
|
|
361
|
+
for (const step of this.steps.values())
|
|
362
|
+
if (step.signal === signal && step.row.provider === provider && (step.selection?.model ?? step.row.meta?.model) === model) {
|
|
363
|
+
const effort = step.selection?.reasoningEffort;
|
|
364
|
+
return { provider, id: model, name: '接回原轮结果', ...(effort === undefined ? {} : { reasoning: { efforts: [{ id: ReasoningEffortId(effort), name: effort }] } }) };
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
canRecover(options) { return !options.purpose && [...this.steps].some(([agent, step]) => agent.session.id === options.sessionId && step.row.provider === options.provider && (step.selection?.model ?? 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)); }
|
|
369
368
|
async connection(signal, binding) {
|
|
370
369
|
for (;;) {
|
|
371
370
|
signal?.throwIfAborted();
|
package/dist/cold-store.d.ts
CHANGED
|
@@ -46,7 +46,7 @@ export interface ColdRound {
|
|
|
46
46
|
baseline?: unknown;
|
|
47
47
|
modelConfiguration?: unknown;
|
|
48
48
|
header: unknown;
|
|
49
|
-
model: string;
|
|
49
|
+
model: string; /** 只读旧版字段;不再覆盖DSH已冻结的本步配置。 */
|
|
50
50
|
callConfig?: import('@deepseek-ai/dsh-llm').LlmCallConfig;
|
|
51
51
|
prelude?: string;
|
|
52
52
|
inputDigests?: Record<string, string>;
|
|
@@ -4,7 +4,6 @@ import type { ConnectApi, ConnectTarget, ConnectionState, Project, Runtime, Runt
|
|
|
4
4
|
import { type BrokerIo, type SshArgv } from './broker.ts';
|
|
5
5
|
import type { DetailChannel } from './remote-details.ts';
|
|
6
6
|
import type { LocalWorkspaceContext } from '@ai-workbench/connect/api';
|
|
7
|
-
import type { EmployeeStartup } from './employee-startup.ts';
|
|
8
7
|
export interface EmployeeProviderOptions {
|
|
9
8
|
getNetwork(): NetworkApi | undefined;
|
|
10
9
|
workspace(request: RuntimeRequest): Promise<{
|
|
@@ -27,7 +26,6 @@ interface Admission {
|
|
|
27
26
|
target: ConnectTarget;
|
|
28
27
|
connection: ConnectionState;
|
|
29
28
|
request: RuntimeRequest;
|
|
30
|
-
preparation?: EmployeeStartup;
|
|
31
29
|
}
|
|
32
30
|
/** Inspect the current local workspace once at turn start, before host readiness. */
|
|
33
31
|
export declare function inspectEmployeeWorkspace(get: () => ConnectApi | undefined, employee: EmployeeProviderOptions, agent: AgentDefinition, api: ConnectApi, request: RuntimeRequest): Promise<Readonly<LocalWorkspaceContext> | undefined>;
|
|
@@ -134,13 +134,13 @@ export function createEmployeeProvider(get, options, agent) {
|
|
|
134
134
|
throw fail('EMPLOYEE_OPERATION_UNSUPPORTED');
|
|
135
135
|
if (!Number.isSafeInteger(request.acpMaxMessageBytes) || request.acpMaxMessageBytes < 1)
|
|
136
136
|
throw fail('SETTINGS_REQUIRED');
|
|
137
|
-
const prepareLocation = () =>
|
|
138
|
-
const resolveNative = () =>
|
|
137
|
+
const prepareLocation = () => admitEmployeeLocation({ api: api, network, workspace, connection, expectedLocal: { instanceId: context.instanceId, epoch: context.epoch, workspaceId: context.workspaceId, bindingId: context.bindingId, directory: { ...context.directory } }, settingsPath: target.session.settingsPath, signal: roundSignal });
|
|
138
|
+
const resolveNative = () => employee.native();
|
|
139
139
|
// 仅把无授权、无目标的静态包路径解析与本轮N准备重叠。两项都收敛后,
|
|
140
140
|
// 按原顺序处理错误;每轮N准备、事件撤销、执行目标绑定仍完整执行。
|
|
141
141
|
const [locationResult, nativeResult] = await Promise.allSettled([
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
request.startupTiming?.run('endpoint-prepare', prepareLocation) ?? prepareLocation(),
|
|
143
|
+
request.startupTiming?.run('native-metadata', resolveNative) ?? resolveNative(),
|
|
144
144
|
]);
|
|
145
145
|
if (locationResult.status === 'rejected')
|
|
146
146
|
throw locationResult.reason;
|
package/dist/index.js
CHANGED
|
@@ -150,7 +150,6 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
150
150
|
if (old && old.outcome !== 'deferred') {
|
|
151
151
|
if (old.outcome !== 'injected' || old.nativeSessionId !== nativeSessionId) {
|
|
152
152
|
const error = new NeedError('INPUT_DELIVERY_UNCONFIRMED', '这条中途消息已有未确认的送达记录,没有再次发送。', '原轮中途消息回执');
|
|
153
|
-
live.steerFailure ??= error;
|
|
154
153
|
throw error;
|
|
155
154
|
}
|
|
156
155
|
(this.injectedInputs.get(sessionId) ?? this.injectedInputs.set(sessionId, new Map()).get(sessionId)).set(message.id, digest);
|
|
@@ -180,7 +179,6 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
180
179
|
await store.put({ ...receipt, outcome: dispatched ? 'unknown' : 'deferred' });
|
|
181
180
|
if (dispatched) {
|
|
182
181
|
const failure = new NeedError('INPUT_DELIVERY_UNCONFIRMED', '中途消息可能已交给原轮,送达结果未知,没有自动重复发送。', '原轮中途消息回执');
|
|
183
|
-
live.steerFailure ??= failure;
|
|
184
182
|
throw failure;
|
|
185
183
|
}
|
|
186
184
|
live.runtime.details?.record({ kind: 'need', severity: 'warning', code: error instanceof NeedError ? error.code : 'INPUT_DELIVERY_UNCONFIRMED', summary: '中途消息未发出,仍由官方队列后续处理。' });
|
|
@@ -188,10 +186,9 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
188
186
|
});
|
|
189
187
|
const observed = work.catch(error => {
|
|
190
188
|
live.runtime.details?.record({ kind: 'need', severity: 'warning', code: error instanceof NeedError ? error.code : 'INPUT_DELIVERY_UNCONFIRMED', summary: '中途消息未确认,原消息没有丢弃或自动重发。' });
|
|
191
|
-
//
|
|
192
|
-
//
|
|
193
|
-
|
|
194
|
-
throw error;
|
|
189
|
+
// A steering receipt describes this input, not the running prompt's result.
|
|
190
|
+
// Keep its uncertainty durable; the official next step records the input
|
|
191
|
+
// and explains why it was not sent again without failing the original turn.
|
|
195
192
|
});
|
|
196
193
|
live.steerTail = observed;
|
|
197
194
|
void observed.catch(() => { });
|
|
@@ -426,17 +423,26 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
426
423
|
checkpointIndex = readPointer(options, this.agent)?.index ?? -1;
|
|
427
424
|
const receipts = this.steeringReceipts && options.sessionId ? await this.steeringReceipts.read(options.sessionId, options.provider, humanIds) : new Map();
|
|
428
425
|
const matching = [...receipts.values()].filter(r => tail.some(m => m.role === 'user' && 'source' in m && m.source?.kind === 'user' && m.id === r.messageId && steeringMessageDigest(m) === r.messageSha256));
|
|
429
|
-
|
|
430
|
-
if (
|
|
431
|
-
throw new NeedError('
|
|
426
|
+
const uncertain = new Set(matching.filter(r => r.outcome === 'prepared' || r.outcome === 'unknown').map(r => {
|
|
427
|
+
if (!previous || r.nativeSessionId !== previous.sessionId)
|
|
428
|
+
throw new NeedError('SESSION_CONTEXT_MISMATCH', '中途消息属于另一原生轮,未重复提交。', '原会话的中途消息回执与检查点');
|
|
429
|
+
return r.messageId;
|
|
430
|
+
}));
|
|
431
|
+
const receiptNotice = uncertain.size ? '\n中途消息送达未确认,已保留记录,没有重复发送。原轮结果已保留;请核对原轮输出,之后可在原会话继续。\n' : undefined;
|
|
432
432
|
const injected = new Set(matching.filter(r => r.outcome === 'injected').map(r => { if (!previous || r.nativeSessionId !== previous.sessionId)
|
|
433
433
|
throw new NeedError('SESSION_CONTEXT_MISMATCH', '中途消息属于另一原生轮,未重复提交。', '原会话的注入回执与检查点'); return r.messageId; }));
|
|
434
|
-
|
|
434
|
+
const withheld = new Set([...injected, ...uncertain]);
|
|
435
|
+
if (humanIds.length && humanIds.every(id => withheld.has(id))) {
|
|
436
|
+
if (receiptNotice) {
|
|
437
|
+
const notice = new StreamMapper();
|
|
438
|
+
yield* notice.text(receiptNotice);
|
|
439
|
+
yield* notice.flush();
|
|
440
|
+
}
|
|
435
441
|
yield { type: 'finish', reason: { kind: 'stop' }, replayState: { response: previous } };
|
|
436
442
|
succeeded = true;
|
|
437
443
|
return;
|
|
438
444
|
}
|
|
439
|
-
const projected = { ...options, messages: options.messages.filter((m, index) => index <= checkpointIndex || !('id' in m) || typeof m.id !== 'string' || !
|
|
445
|
+
const projected = { ...options, messages: options.messages.filter((m, index) => index <= checkpointIndex || !('id' in m) || typeof m.id !== 'string' || !withheld.has(m.id)) };
|
|
440
446
|
earlyStage = 'input-prepare';
|
|
441
447
|
let input = await startupTiming.run('input-prepare', () => prepareInput(projected, this.readImage));
|
|
442
448
|
const contextSha256 = createHash('sha256').update(input.systemPrompt ?? '').digest('hex');
|
|
@@ -519,6 +525,8 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
519
525
|
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?.(); }); };
|
|
520
526
|
const renderNotice = (text) => render(async () => { if (runtime.cold)
|
|
521
527
|
await runtime.cold.store.update(options.sessionId, options.provider, runtime.cold.id, row => { (row.localNotices ??= []).push({ beforeUpdate: nativeUpdates, text }); }); push(mapper.text(text)); });
|
|
528
|
+
if (receiptNotice)
|
|
529
|
+
renderNotice(receiptNotice);
|
|
522
530
|
let promptPermit;
|
|
523
531
|
let confirmedNativeMode;
|
|
524
532
|
let endDispatch = () => { };
|
|
@@ -680,13 +688,10 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
680
688
|
bridge.replayState = { response: makePointer(session.id) };
|
|
681
689
|
bridge?.begin(modelSignal);
|
|
682
690
|
id = session.id;
|
|
683
|
-
let promptFailed = false;
|
|
684
691
|
try {
|
|
685
692
|
const result = await dispatchPrompt();
|
|
686
693
|
live.acceptingSteer = false;
|
|
687
694
|
await live.steerTail;
|
|
688
|
-
if (live.steerFailure)
|
|
689
|
-
throw live.steerFailure;
|
|
690
695
|
if (bridge?.unsettled)
|
|
691
696
|
bridge.abandon('HOST_PROMPT_ENDED_WITH_PENDING_CALL');
|
|
692
697
|
permissionOff?.();
|
|
@@ -696,21 +701,11 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
696
701
|
}
|
|
697
702
|
catch (error) {
|
|
698
703
|
endDispatch('failed');
|
|
699
|
-
promptFailed = true;
|
|
700
704
|
throw error;
|
|
701
705
|
}
|
|
702
706
|
finally {
|
|
703
707
|
live.acceptingSteer = false;
|
|
704
|
-
|
|
705
|
-
await live.steerTail;
|
|
706
|
-
if (live.steerFailure)
|
|
707
|
-
throw live.steerFailure;
|
|
708
|
-
}
|
|
709
|
-
catch (error) {
|
|
710
|
-
if (!promptFailed)
|
|
711
|
-
throw error;
|
|
712
|
-
details.record({ kind: 'need', severity: 'warning', code: 'INPUT_DELIVERY_UNCONFIRMED', summary: '原轮失败且有中途消息未获送达确认,没有重发。' });
|
|
713
|
-
}
|
|
708
|
+
await live.steerTail;
|
|
714
709
|
permissionOff?.();
|
|
715
710
|
permissionOff = undefined;
|
|
716
711
|
bridge?.end();
|
|
@@ -772,8 +767,6 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
772
767
|
throw withFirstFailureEvidence(error, runtime?.closeDiagnostics?.first?.reason, failureCode);
|
|
773
768
|
}
|
|
774
769
|
finally {
|
|
775
|
-
if (request)
|
|
776
|
-
this.resolveRuntime.releasePreparation?.(request);
|
|
777
770
|
permissionOff?.();
|
|
778
771
|
permissionOff = undefined;
|
|
779
772
|
permissionEpoch.abort();
|
package/dist/provider.d.ts
CHANGED
|
@@ -113,7 +113,6 @@ export interface RuntimeRequest extends Invocation {
|
|
|
113
113
|
}
|
|
114
114
|
export type RuntimeProvider = ((request: RuntimeRequest) => Promise<Runtime>) & {
|
|
115
115
|
preflight?: (request: RuntimeRequest) => Promise<void>;
|
|
116
|
-
releasePreparation?: (request: RuntimeRequest) => void;
|
|
117
116
|
};
|
|
118
117
|
export interface ConnectTarget {
|
|
119
118
|
host: string;
|
package/dist/provider.js
CHANGED
|
@@ -149,16 +149,6 @@ export function connectProvider(get, options = {}) {
|
|
|
149
149
|
// Cache the initialization promise so concurrent sessions share this provider's binding lifetimes.
|
|
150
150
|
let employee;
|
|
151
151
|
const admissions = new WeakMap();
|
|
152
|
-
const preparations = new WeakMap();
|
|
153
|
-
const releasePreparation = (request) => { const owned = preparations.get(request); preparations.delete(request); admissions.delete(request); owned?.restore(); owned?.preparation.cancel(); };
|
|
154
|
-
const ownPreparation = (request, preparation) => {
|
|
155
|
-
const original = request.recordEarlyFailure;
|
|
156
|
-
const wrapped = async (error, stage) => { releasePreparation(request); if (original)
|
|
157
|
-
await original(error, stage); };
|
|
158
|
-
preparations.set(request, { preparation, restore: () => { if (request.recordEarlyFailure === wrapped)
|
|
159
|
-
request.recordEarlyFailure = original; } });
|
|
160
|
-
request.recordEarlyFailure = wrapped;
|
|
161
|
-
};
|
|
162
152
|
const preflight = async (request) => {
|
|
163
153
|
request.signal?.throwIfAborted();
|
|
164
154
|
const api = get();
|
|
@@ -167,7 +157,6 @@ export function connectProvider(get, options = {}) {
|
|
|
167
157
|
requireNativeWorkspace(api);
|
|
168
158
|
requireLoginCoordinator(api);
|
|
169
159
|
let sourceStage = 'input-acceptance';
|
|
170
|
-
let preparation;
|
|
171
160
|
try {
|
|
172
161
|
request.workspaceSource = options.source ? await options.source(request, api) : request.hostSource;
|
|
173
162
|
if (!options.source && !request.workspaceSource && options.workspace && request.sessionId && api.getContractInfo().workspaceLocations === 1) {
|
|
@@ -180,12 +169,6 @@ export function connectProvider(get, options = {}) {
|
|
|
180
169
|
request.localContext = await module.inspectEmployeeWorkspace(get, options.employee, agent, api, request);
|
|
181
170
|
}
|
|
182
171
|
sourceStage = 'login-readiness';
|
|
183
|
-
if (!host && agent.loginProvider === 'codex' && options.employee && request.localContext) {
|
|
184
|
-
const module = await import("./employee-startup.js");
|
|
185
|
-
preparation = module.beginEmployeeStartup(get, options.employee, api, request);
|
|
186
|
-
if (preparation)
|
|
187
|
-
ownPreparation(request, preparation);
|
|
188
|
-
}
|
|
189
172
|
const loginReady = async () => {
|
|
190
173
|
request.localAdmissionCheck?.();
|
|
191
174
|
const before = api.getConnectionState();
|
|
@@ -208,13 +191,8 @@ export function connectProvider(get, options = {}) {
|
|
|
208
191
|
throw connectNeedError(locations.need);
|
|
209
192
|
if (!host)
|
|
210
193
|
await options.local?.admit?.(request, api, connection, target);
|
|
211
|
-
if (preparation) {
|
|
212
|
-
await preparation.ready;
|
|
213
|
-
preparation.confirm(target, connection);
|
|
214
|
-
}
|
|
215
194
|
}
|
|
216
195
|
catch (error) {
|
|
217
|
-
preparation?.cancel();
|
|
218
196
|
admissions.delete(request);
|
|
219
197
|
const record = request.recordEarlyFailure;
|
|
220
198
|
request.recordEarlyFailure = undefined;
|
|
@@ -229,51 +207,41 @@ export function connectProvider(get, options = {}) {
|
|
|
229
207
|
const admitted = admissions.get(request);
|
|
230
208
|
admissions.delete(request);
|
|
231
209
|
const { api, target, connection } = admitted;
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
employee ??= import("./employee-provider.js").then(module => module.createEmployeeProvider(get, options, agent));
|
|
242
|
-
const local = await (await employee)({ api, target, connection, request, preparation });
|
|
243
|
-
if (local) {
|
|
244
|
-
local.loginRequired = () => offerLogin(api, request, get, agent);
|
|
245
|
-
return local;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
if (!host && agent.loginProvider === 'claude' && options.local) {
|
|
249
|
-
const runtime = await options.local(request, api, connection, target);
|
|
250
|
-
if (runtime)
|
|
251
|
-
return runtime;
|
|
210
|
+
if (!request.sessionId)
|
|
211
|
+
throw new NeedError('PROJECT_BINDING_REQUIRED', '我需要当前会话和已选择的工作区,请使用原生工作区入口', 'DSH会话与原生工作区');
|
|
212
|
+
const host = request.workspaceSource?.source === 'host';
|
|
213
|
+
if (!host && options.employee) {
|
|
214
|
+
employee ??= import("./employee-provider.js").then(module => module.createEmployeeProvider(get, options, agent));
|
|
215
|
+
const local = await (await employee)({ api, target, connection, request });
|
|
216
|
+
if (local) {
|
|
217
|
+
local.loginRequired = () => offerLogin(api, request, get, agent);
|
|
218
|
+
return local;
|
|
252
219
|
}
|
|
253
|
-
// A local source must have been handled by its employee provider above.
|
|
254
|
-
// Host execution requires an explicit host location; no name-based resolver.
|
|
255
|
-
if (!host)
|
|
256
|
-
throw new NeedError('WORKSPACE_LOCATION_REQUIRED', '请选择文件夹来源;改变来源后请新建会话。', '已选择的本机或主机文件夹');
|
|
257
|
-
const resolved = await resolveHostWorkspace(api, request, agent.loginProvider);
|
|
258
|
-
const project = resolved.project;
|
|
259
|
-
const details = await options.details?.(request, api, connection, target);
|
|
260
|
-
if (!options.open)
|
|
261
|
-
throw new NeedError('RUNTIME_REQUIRED', '我需要主机运行适配器', '主机broker适配');
|
|
262
|
-
const runtime = await options.open(resolved.target, project, { ...request, agent, bindingId: undefined, workspaceId: undefined, bindingRevision: undefined, detailChannel: details });
|
|
263
|
-
runtime.hostSource = Object.freeze({ ...request.workspaceSource });
|
|
264
|
-
runtime.hostWorkspace = Object.freeze({ cwd: project.path });
|
|
265
|
-
// The transport can outlive a turn; presentation belongs only to this invocation.
|
|
266
|
-
runtime.details = details ?? runtime.details;
|
|
267
|
-
runtime.binding = undefined;
|
|
268
|
-
runtime.connection = { ...connection };
|
|
269
|
-
runtime.loginRequired = () => offerLogin(api, request, get, agent);
|
|
270
|
-
return runtime;
|
|
271
220
|
}
|
|
272
|
-
|
|
273
|
-
|
|
221
|
+
if (!host && agent.loginProvider === 'claude' && options.local) {
|
|
222
|
+
const runtime = await options.local(request, api, connection, target);
|
|
223
|
+
if (runtime)
|
|
224
|
+
return runtime;
|
|
274
225
|
}
|
|
226
|
+
// A local source must have been handled by its employee provider above.
|
|
227
|
+
// Host execution requires an explicit host location; no name-based resolver.
|
|
228
|
+
if (!host)
|
|
229
|
+
throw new NeedError('WORKSPACE_LOCATION_REQUIRED', '请选择文件夹来源;改变来源后请新建会话。', '已选择的本机或主机文件夹');
|
|
230
|
+
const resolved = await resolveHostWorkspace(api, request, agent.loginProvider);
|
|
231
|
+
const project = resolved.project;
|
|
232
|
+
const details = await options.details?.(request, api, connection, target);
|
|
233
|
+
if (!options.open)
|
|
234
|
+
throw new NeedError('RUNTIME_REQUIRED', '我需要主机运行适配器', '主机broker适配');
|
|
235
|
+
const runtime = await options.open(resolved.target, project, { ...request, agent, bindingId: undefined, workspaceId: undefined, bindingRevision: undefined, detailChannel: details });
|
|
236
|
+
runtime.hostSource = Object.freeze({ ...request.workspaceSource });
|
|
237
|
+
runtime.hostWorkspace = Object.freeze({ cwd: project.path });
|
|
238
|
+
// The transport can outlive a turn; presentation belongs only to this invocation.
|
|
239
|
+
runtime.details = details ?? runtime.details;
|
|
240
|
+
runtime.binding = undefined;
|
|
241
|
+
runtime.connection = { ...connection };
|
|
242
|
+
runtime.loginRequired = () => offerLogin(api, request, get, agent);
|
|
243
|
+
return runtime;
|
|
275
244
|
};
|
|
276
245
|
resolve.preflight = preflight;
|
|
277
|
-
resolve.releasePreparation = releasePreparation;
|
|
278
246
|
return resolve;
|
|
279
247
|
}
|
|
@@ -8,4 +8,4 @@ export interface BridgeTool {
|
|
|
8
8
|
wire: Tool;
|
|
9
9
|
}
|
|
10
10
|
export declare function dshSkillCatalog(messages?: GenerateOptions['messages']): readonly string[] | undefined;
|
|
11
|
-
export declare function bridgeTable(tools?: readonly ToolSchema[], catalog?: readonly string[]
|
|
11
|
+
export declare function bridgeTable(tools?: readonly ToolSchema[], catalog?: readonly string[]): ReadonlyMap<string, BridgeTool>;
|
package/dist/toolbridge-table.js
CHANGED
|
@@ -17,7 +17,7 @@ export function dshSkillCatalog(messages = []) {
|
|
|
17
17
|
return source.entries.map(entry => entry.name);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
export function bridgeTable(tools = [], catalog
|
|
20
|
+
export function bridgeTable(tools = [], catalog) {
|
|
21
21
|
const table = new Map(), names = new Set();
|
|
22
22
|
for (const tool of tools) {
|
|
23
23
|
if (excluded.has(tool.name))
|
|
@@ -29,7 +29,7 @@ export function bridgeTable(tools = [], catalog, catalogInCurrentPrompt = false)
|
|
|
29
29
|
if (table.has(alias))
|
|
30
30
|
throw new NeedError('TOOLBRIDGE_NAME_COLLISION', '工具桥名称冲突,未执行。', '唯一工具桥名称');
|
|
31
31
|
const schema = structuredClone(tool);
|
|
32
|
-
const skill = schema.name === 'skill' ? ' 这是DSH技能加载器,名字取自DSH的<available_skills>目录;主机Claude/Codex的原生技能按各自原生技能指令加载。' + (
|
|
32
|
+
const skill = schema.name === 'skill' ? ' 这是DSH技能加载器,名字取自DSH的<available_skills>目录;主机Claude/Codex的原生技能按各自原生技能指令加载。' + (catalog === undefined ? '请以当前DSH技能目录为准。' : '本次DSH公布的目录快照:' + JSON.stringify(catalog) + ';实际可用性由DSH调用时确认。') + '技能资源按返回的<skill_resources>基址读取。' : '';
|
|
33
33
|
table.set(alias, { alias, schema, wire: { name: alias, description: 'DSH工具 ' + schema.name + ':' + schema.description + skill, inputSchema: structuredClone(schema.parameters) } });
|
|
34
34
|
}
|
|
35
35
|
return table;
|
package/dist/toolbridge.js
CHANGED
|
@@ -16,26 +16,7 @@ export class ToolBridge {
|
|
|
16
16
|
readImage;
|
|
17
17
|
controller = new AbortController();
|
|
18
18
|
snapshot;
|
|
19
|
-
get table() {
|
|
20
|
-
if (this.snapshot)
|
|
21
|
-
return this.snapshot;
|
|
22
|
-
const messages = this.options.messages, catalog = dshSkillCatalog(messages);
|
|
23
|
-
// prepareInput只转发最后assistant之后的user内容;历史目录不能代替当前prompt。
|
|
24
|
-
// 正文不含目录全部名字时仍保留原schema快照,避免分支/切模型时丢发现入口。
|
|
25
|
-
const current = messages.slice(messages.findLastIndex(message => message.role === 'assistant') + 1);
|
|
26
|
-
const forwarded = catalog !== undefined && catalog.length > 0 && current.some(message => {
|
|
27
|
-
const names = dshSkillCatalog([message]);
|
|
28
|
-
if (names === undefined || JSON.stringify(names) !== JSON.stringify(catalog))
|
|
29
|
-
return false;
|
|
30
|
-
const text = message.content.filter(block => block.type === 'text').map(block => block.text).join('\n');
|
|
31
|
-
// 只认官方目录中明确声明的完整名字;子串命中不能证明office也已随office-xlsx送达。
|
|
32
|
-
// 未识别的格式继续携带原名字快照,不推测目录内容。
|
|
33
|
-
const declared = new Set([...text.matchAll(/<available_skills>([\s\S]*?)<\/available_skills>/g)]
|
|
34
|
-
.flatMap(section => [...section[1].matchAll(/^[ \t]*-[ \t]+`([^`\r\n]+)`[ \t]*:/gm)].map(item => item[1])));
|
|
35
|
-
return catalog.every(name => declared.has(name));
|
|
36
|
-
});
|
|
37
|
-
return this.snapshot = bridgeTable(this.options.tools, catalog, forwarded);
|
|
38
|
-
}
|
|
19
|
+
get table() { return this.snapshot ??= bridgeTable(this.options.tools, dshSkillCatalog(this.options.messages)); }
|
|
39
20
|
calls = new Map();
|
|
40
21
|
enabled = false;
|
|
41
22
|
ended = false;
|
package/package.json
CHANGED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { NetworkApi } from '@ai-workbench/network/api';
|
|
2
|
-
import type { LocalWorkspaceContext } from '@ai-workbench/connect/api';
|
|
3
|
-
import type { EmployeeProviderOptions } from './employee-provider.ts';
|
|
4
|
-
import { type ConnectApi, type ConnectTarget, type ConnectionState, type RuntimeRequest } from './provider.ts';
|
|
5
|
-
import { admitEmployeeLocation } from './employee-location.ts';
|
|
6
|
-
type Location = Awaited<ReturnType<typeof admitEmployeeLocation>>;
|
|
7
|
-
/** 只拥有本次请求的等待和围栏,不拥有、关闭或缓存N的共享设备服务。 */
|
|
8
|
-
export interface EmployeeStartup {
|
|
9
|
-
ready: Promise<void>;
|
|
10
|
-
confirm(target: ConnectTarget, connection: ConnectionState): void;
|
|
11
|
-
location(network: NetworkApi, context: Readonly<LocalWorkspaceContext>): Promise<Location>;
|
|
12
|
-
native(): Promise<{
|
|
13
|
-
path: string;
|
|
14
|
-
}>;
|
|
15
|
-
cancel(): void;
|
|
16
|
-
}
|
|
17
|
-
export declare function beginEmployeeStartup(get: () => ConnectApi | undefined, employee: EmployeeProviderOptions, api: ConnectApi, request: RuntimeRequest): EmployeeStartup | undefined;
|
|
18
|
-
export {};
|
package/dist/employee-startup.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
-
import { awaitL, sameTarget, validateTarget } from "./provider.js";
|
|
3
|
-
import { admitEmployeeLocation } from "./employee-location.js";
|
|
4
|
-
import { connectNeedError } from "./connect-need.js";
|
|
5
|
-
import { NeedError } from "./remote.js";
|
|
6
|
-
const failure = (code) => new NeedError(code, '员工电脑的工作区或执行连接已变化,本轮没有继续执行。', '当前工作区绑定与员工端执行器');
|
|
7
|
-
export function beginEmployeeStartup(get, employee, api, request) {
|
|
8
|
-
const context = request.localContext ? structuredClone(request.localContext) : undefined, connection = api.getConnectionState();
|
|
9
|
-
// 只在原context已接纳且已有执行用途可信target的路径重叠;首次未连接仍按原顺序开通。
|
|
10
|
-
if (!context || connection.phase !== 'connected' || typeof api.getSshTarget !== 'function')
|
|
11
|
-
return;
|
|
12
|
-
const network = employee.getNetwork(), lifetime = new AbortController(), offs = [];
|
|
13
|
-
const signal = AbortSignal.any([lifetime.signal, ...request.signal ? [request.signal] : []]);
|
|
14
|
-
let closed = false, target, location, native;
|
|
15
|
-
const nativeMetadata = () => native ??= (request.startupTiming?.run('native-metadata', () => employee.native()) ?? Promise.resolve().then(() => employee.native()));
|
|
16
|
-
const close = () => { if (closed)
|
|
17
|
-
return; closed = true; for (const off of offs.splice(0))
|
|
18
|
-
off(); };
|
|
19
|
-
const cancel = () => { lifetime.abort(failure('ABORTED')); close(); };
|
|
20
|
-
const check = () => {
|
|
21
|
-
signal.throwIfAborted();
|
|
22
|
-
request.localAdmissionCheck?.();
|
|
23
|
-
if (get() !== api || employee.getNetwork() !== network)
|
|
24
|
-
throw failure('EMPLOYEE_CONTEXT_CHANGED');
|
|
25
|
-
const now = api.getConnectionState();
|
|
26
|
-
if (now.phase !== 'connected' || now.instanceId !== connection.instanceId || now.epoch !== connection.epoch)
|
|
27
|
-
throw failure('CONNECTION_LOST');
|
|
28
|
-
if (!network || network.getState().phase !== 'online')
|
|
29
|
-
throw failure('CONNECTION_LOST');
|
|
30
|
-
};
|
|
31
|
-
const changed = () => { try {
|
|
32
|
-
check();
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
lifetime.abort(error);
|
|
36
|
-
close();
|
|
37
|
-
} };
|
|
38
|
-
const revokeNetwork = (event) => { if (event.kind === 'lost') {
|
|
39
|
-
lifetime.abort(failure('CONNECTION_LOST'));
|
|
40
|
-
close();
|
|
41
|
-
}
|
|
42
|
-
else
|
|
43
|
-
changed(); };
|
|
44
|
-
const aborted = () => close();
|
|
45
|
-
signal.addEventListener('abort', aborted, { once: true });
|
|
46
|
-
offs.push(() => signal.removeEventListener('abort', aborted));
|
|
47
|
-
const pending = (async () => {
|
|
48
|
-
if (typeof api.onConnectionState !== 'function' || typeof api.onWorkspaceLocationState !== 'function' || !network || typeof network.onState !== 'function' || typeof network.prepareEmployeeEndpoint !== 'function')
|
|
49
|
-
throw failure('DEPENDENCY_REQUIRED');
|
|
50
|
-
const watch = (off) => { if (closed)
|
|
51
|
-
off();
|
|
52
|
-
else
|
|
53
|
-
offs.push(off); };
|
|
54
|
-
watch(api.onConnectionState(changed));
|
|
55
|
-
watch(api.onWorkspaceLocationState(changed));
|
|
56
|
-
watch(network.onState(revokeNetwork));
|
|
57
|
-
if (network.getState().phase !== 'online')
|
|
58
|
-
throw failure('EMPLOYEE_ENDPOINT_UNAVAILABLE');
|
|
59
|
-
check();
|
|
60
|
-
const current = await awaitL(() => api.getSshTarget(), signal);
|
|
61
|
-
if (!current.ok)
|
|
62
|
-
throw connectNeedError(current.error);
|
|
63
|
-
target = structuredClone(current.value);
|
|
64
|
-
validateTarget(target);
|
|
65
|
-
check();
|
|
66
|
-
// 保留O1既有的纯静态解析重叠;实际执行与broker仍须等待两道门及静态结果。
|
|
67
|
-
void nativeMetadata().catch(() => { });
|
|
68
|
-
const prepare = () => admitEmployeeLocation({ api: api, network, workspace: { id: context.workspaceId, path: context.directory.path }, connection, expectedLocal: { instanceId: context.instanceId, epoch: context.epoch, workspaceId: context.workspaceId, bindingId: context.bindingId, directory: { ...context.directory } }, settingsPath: target.session.settingsPath, signal });
|
|
69
|
-
location = await awaitL(() => request.startupTiming?.run('endpoint-prepare', prepare) ?? prepare(), signal);
|
|
70
|
-
check();
|
|
71
|
-
})();
|
|
72
|
-
// 登录失败始终优先;端点提前失败也先被观察,不能产生未处理拒绝或抢先改变失败语义。
|
|
73
|
-
void pending.catch(() => { });
|
|
74
|
-
const confirm = (current, ready) => { check(); if (!target || !sameTarget(target, current) || ready.instanceId !== connection.instanceId || ready.epoch !== connection.epoch)
|
|
75
|
-
throw failure('EMPLOYEE_CONTEXT_CHANGED'); };
|
|
76
|
-
return { ready: pending, confirm, cancel, native: nativeMetadata, async location(currentNetwork, currentContext) {
|
|
77
|
-
await pending;
|
|
78
|
-
check();
|
|
79
|
-
if (currentNetwork !== network || !isDeepStrictEqual(currentContext, context))
|
|
80
|
-
throw failure('EMPLOYEE_CONTEXT_CHANGED');
|
|
81
|
-
// 准备完成至登录结束之间仍可能替换物理目录;只重读L的只读context,不再prepare第二次。
|
|
82
|
-
const [current, physical] = await Promise.all([
|
|
83
|
-
awaitL(() => api.getSshTarget(), signal),
|
|
84
|
-
awaitL(() => api.getLocalWorkspaceContext({ instanceId: context.instanceId, epoch: context.epoch, workspaceId: context.workspaceId, expectedBindingId: context.bindingId }), signal),
|
|
85
|
-
]);
|
|
86
|
-
check();
|
|
87
|
-
if (!current.ok)
|
|
88
|
-
throw connectNeedError(current.error);
|
|
89
|
-
if (!physical.ok)
|
|
90
|
-
throw connectNeedError(physical.error);
|
|
91
|
-
if (!target || !sameTarget(target, current.value) || !isDeepStrictEqual(physical.value, context))
|
|
92
|
-
throw failure('EMPLOYEE_CONTEXT_CHANGED');
|
|
93
|
-
return location;
|
|
94
|
-
} };
|
|
95
|
-
}
|