@eddyskywalker/dsh-chatgpt-subscription 0.90.2 → 0.91.0
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/lib/client.js +536 -184
- package/lib/client.js.map +1 -1
- package/lib/codemode.js +353 -62
- package/lib/index.js +2379 -1503
- package/lib/{plan-mode-CoublSCJ.js → plan-mode-cY8pp0PZ.js} +1 -1
- package/lib/{plan-mode-pipeline-DvVmLaxR.js → plan-mode-pipeline-DQ8TM6mP.js} +21 -18
- package/lib/plan-mode-pipeline.js +1 -1
- package/lib/plan-mode.js +1 -1
- package/lib/{preset-sync-B9yKbQPc.js → preset-sync-gvhSzmlr.js} +44 -1
- package/lib/{progress-updates-DwpfBXOx.js → progress-updates-jiHnSAmz.js} +12 -1
- package/lib/progress-updates.js +1 -1
- package/lib/{tool-result-pruner-Dy6X17gv.js → tool-result-pruner-Baz9Lrov.js} +85 -41
- package/lib/tool-result-pruner.js +1 -1
- package/lib/types/client/features/subagent/SubagentCard.d.ts.map +1 -1
- package/lib/types/client/features/subagent/locales.d.ts +11 -2
- package/lib/types/client/features/subagent/locales.d.ts.map +1 -1
- package/lib/types/client/features/subagent/styles.d.ts +1 -1
- package/lib/types/client/features/subagent/styles.d.ts.map +1 -1
- package/lib/types/client/features/subagent/subagent-card-controller.d.ts +13 -0
- package/lib/types/client/features/subagent/subagent-card-controller.d.ts.map +1 -1
- package/lib/types/client/locales-ru/claude-api.d.ts.map +1 -1
- package/lib/types/client/locales-ru/claude.d.ts.map +1 -1
- package/lib/types/client/providers/claude/ClaudeSection.d.ts.map +1 -1
- package/lib/types/client/providers/claude/locales.d.ts +8 -2
- package/lib/types/client/providers/claude/locales.d.ts.map +1 -1
- package/lib/types/client/providers/claude/useClaudeSection.d.ts +1 -0
- package/lib/types/client/providers/claude/useClaudeSection.d.ts.map +1 -1
- package/lib/types/client/providers/claude-api/ClaudeApiSection.d.ts.map +1 -1
- package/lib/types/client/providers/claude-api/api.d.ts +4 -2
- package/lib/types/client/providers/claude-api/api.d.ts.map +1 -1
- package/lib/types/client/providers/claude-api/locales.d.ts +87 -5
- package/lib/types/client/providers/claude-api/locales.d.ts.map +1 -1
- package/lib/types/client/providers/claude-api/styles.d.ts.map +1 -1
- package/lib/types/client/providers/claude-api/useClaudeApiSection.d.ts +16 -7
- package/lib/types/client/providers/claude-api/useClaudeApiSection.d.ts.map +1 -1
- package/lib/types/compat.d.ts +1 -1
- package/lib/types/entries/codemode.d.ts.map +1 -1
- package/lib/types/entries/plan-mode-pipeline.d.ts.map +1 -1
- package/lib/types/host/common/llm-compat.d.ts +14 -0
- package/lib/types/host/common/llm-compat.d.ts.map +1 -1
- package/lib/types/host/providers/claude/routes.d.ts.map +1 -1
- package/lib/types/host/providers/claude/token-store.d.ts +3 -0
- package/lib/types/host/providers/claude/token-store.d.ts.map +1 -1
- package/lib/types/host/providers/claude-api/account-pool.d.ts +44 -0
- package/lib/types/host/providers/claude-api/account-pool.d.ts.map +1 -0
- package/lib/types/host/providers/claude-api/adapter.d.ts +10 -2
- package/lib/types/host/providers/claude-api/adapter.d.ts.map +1 -1
- package/lib/types/host/providers/claude-api/catalog-manager.d.ts +3 -2
- package/lib/types/host/providers/claude-api/catalog-manager.d.ts.map +1 -1
- package/lib/types/host/providers/claude-api/routes.d.ts +3 -7
- package/lib/types/host/providers/claude-api/routes.d.ts.map +1 -1
- package/lib/types/host/providers/claude-api/token-store.d.ts +4 -0
- package/lib/types/host/providers/claude-api/token-store.d.ts.map +1 -1
- package/lib/types/host/providers/cline-pass/adapter.d.ts.map +1 -1
- package/lib/types/host/providers/glm-coding-plan/adapter.d.ts.map +1 -1
- package/lib/types/host/providers/glm-coding-plan/mapper-anthropic.d.ts +1 -1
- package/lib/types/host/providers/glm-coding-plan/mapper-anthropic.d.ts.map +1 -1
- package/lib/types/host/providers/glm-coding-plan/mapper-openai.d.ts.map +1 -1
- package/lib/types/host/providers/glm-coding-plan/model-catalog.d.ts.map +1 -1
- package/lib/types/host/providers/minimax-code/adapter.d.ts.map +1 -1
- package/lib/types/host/providers/opendesign/adapter.d.ts.map +1 -1
- package/lib/types/host/providers/qianwen-token-plan/adapter.d.ts.map +1 -1
- package/lib/types/host/providers/step-code/adapter.d.ts.map +1 -1
- package/lib/types/host/runtime/cache-warmup/install.d.ts.map +1 -1
- package/lib/types/host/runtime/cache-warmup/retrieval-intent.d.ts.map +1 -1
- package/lib/types/host/runtime/codemode/executor.d.ts +50 -0
- package/lib/types/host/runtime/codemode/executor.d.ts.map +1 -1
- package/lib/types/host/runtime/codemode/transport.d.ts +6 -2
- package/lib/types/host/runtime/codemode/transport.d.ts.map +1 -1
- package/lib/types/host/runtime/compact-after-turn/index.d.ts +34 -3
- package/lib/types/host/runtime/compact-after-turn/index.d.ts.map +1 -1
- package/lib/types/host/runtime/deepseek-v41-flash/index.d.ts +2 -2
- package/lib/types/host/runtime/deepseek-v41-flash/index.d.ts.map +1 -1
- package/lib/types/host/runtime/deepseek-v41-flash/observation-tagger.d.ts.map +1 -1
- package/lib/types/host/runtime/deepseek-v41-flash/state-anchor.d.ts +17 -3
- package/lib/types/host/runtime/deepseek-v41-flash/state-anchor.d.ts.map +1 -1
- package/lib/types/host/runtime/guards/compaction-policy-guard.d.ts.map +1 -1
- package/lib/types/host/runtime/guards/plan-mode-cache-guard.d.ts.map +1 -1
- package/lib/types/host/runtime/guards/ptc-sdk-cache-guard.d.ts.map +1 -1
- package/lib/types/host/runtime/guards/subagent-model-authorization.d.ts +11 -3
- package/lib/types/host/runtime/guards/subagent-model-authorization.d.ts.map +1 -1
- package/lib/types/host/runtime/guards/subagent-route-audit.d.ts +0 -11
- package/lib/types/host/runtime/guards/subagent-route-audit.d.ts.map +1 -1
- package/lib/types/host/runtime/guards/team-policy-cache-guard.d.ts +2 -0
- package/lib/types/host/runtime/guards/team-policy-cache-guard.d.ts.map +1 -1
- package/lib/types/host/runtime/guards/timeline-cache-guard.d.ts.map +1 -1
- package/lib/types/host/runtime/open-models/index.d.ts +2 -2
- package/lib/types/host/runtime/open-models/index.d.ts.map +1 -1
- package/lib/types/host/runtime/open-models/observation-guard.d.ts.map +1 -1
- package/lib/types/host/runtime/open-models/profiles.d.ts +10 -2
- package/lib/types/host/runtime/open-models/profiles.d.ts.map +1 -1
- package/lib/types/host/runtime/open-models/state-anchor.d.ts +3 -0
- package/lib/types/host/runtime/open-models/state-anchor.d.ts.map +1 -1
- package/lib/types/host/runtime/presets/agent-preset.d.ts +12 -7
- package/lib/types/host/runtime/presets/agent-preset.d.ts.map +1 -1
- package/lib/types/host/runtime/progress-updates/index.d.ts.map +1 -1
- package/lib/types/index.d.ts +3 -2
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/shared/claude-api-contracts.d.ts +18 -0
- package/lib/types/shared/claude-api-contracts.d.ts.map +1 -1
- package/lib/types/shared/claude-contracts.d.ts +3 -0
- package/lib/types/shared/claude-contracts.d.ts.map +1 -1
- package/package.json +56 -52
- package/presets/dispatch/agent.cordis.yml +5 -4
package/lib/codemode.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { a as PLUGIN_MESSAGE_SOURCE_KIND, t as candidatePackageRoots } from "./preset-sync-
|
|
1
|
+
import { a as PLUGIN_MESSAGE_SOURCE_KIND, t as candidatePackageRoots } from "./preset-sync-gvhSzmlr.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import * as dshLlm from "@deepseek-ai/dsh-llm";
|
|
4
4
|
import { HarnessError, createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
5
5
|
import { dirname, join, resolve } from "node:path";
|
|
6
6
|
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
7
7
|
import { pathToFileURL } from "node:url";
|
|
8
|
-
import { NativeToolExecutor } from "@deepseek-ai/dsh-tool-executor-native";
|
|
9
8
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
10
9
|
//#region src/host/runtime/codemode/discovery.ts
|
|
11
10
|
/**
|
|
@@ -889,6 +888,120 @@ function sectionOrderOf(ctx) {
|
|
|
889
888
|
return 5e3;
|
|
890
889
|
}
|
|
891
890
|
}
|
|
891
|
+
/**
|
|
892
|
+
* 造一个面向 DSH 0.2.3-alpha.3+ `ctx.tools.setRoot()` 的 Code Mode 根注册表。
|
|
893
|
+
*
|
|
894
|
+
* - `include(registrations)` 接收 `ctx.tools` 自动注入的未遮蔽注册表视图;
|
|
895
|
+
* - `get()` / `getAll()` 仅暴露原生白名单与传输工具,模型直呼被遮蔽工具时由内核自动以
|
|
896
|
+
* `UNKNOWN_TOOL` 拒绝;
|
|
897
|
+
* - `bindings()` / `binding()` 向程序传输层暴露完整未遮蔽绑定,并按 `ToolStep` 钉死步骤视图。
|
|
898
|
+
*/
|
|
899
|
+
function createCodemodeRootRegistry(rules, hooks) {
|
|
900
|
+
const own = /* @__PURE__ */ new Map();
|
|
901
|
+
const sources = [];
|
|
902
|
+
const stepBindings = /* @__PURE__ */ new WeakMap();
|
|
903
|
+
const resolveRaw = (name, scope) => {
|
|
904
|
+
const direct = own.get(name);
|
|
905
|
+
if (direct !== void 0) return direct;
|
|
906
|
+
for (const source of sources) {
|
|
907
|
+
const found = source.get(name, scope);
|
|
908
|
+
if (found !== void 0) return found;
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
const resolveAllRaw = (scope) => {
|
|
912
|
+
const out = [...own.values()];
|
|
913
|
+
for (const source of sources) {
|
|
914
|
+
const entries = source.getAll(scope);
|
|
915
|
+
if (Array.isArray(entries)) for (const entry of entries) out.push(entry);
|
|
916
|
+
}
|
|
917
|
+
return out;
|
|
918
|
+
};
|
|
919
|
+
const dedupeBindings = (list) => {
|
|
920
|
+
const map = /* @__PURE__ */ new Map();
|
|
921
|
+
for (const entry of list) {
|
|
922
|
+
const name = nameOf(entry);
|
|
923
|
+
if (name === void 0 || map.has(name)) continue;
|
|
924
|
+
map.set(name, entry);
|
|
925
|
+
}
|
|
926
|
+
return map;
|
|
927
|
+
};
|
|
928
|
+
const ensureStepBindings = (toolStep, fallbackScope) => {
|
|
929
|
+
let declared = stepBindings.get(toolStep);
|
|
930
|
+
if (declared === void 0) {
|
|
931
|
+
const stepAgent = toolStep.agent;
|
|
932
|
+
declared = dedupeBindings(resolveAllRaw(typeof stepAgent === "object" && stepAgent !== null ? stepAgent : fallbackScope));
|
|
933
|
+
stepBindings.set(toolStep, declared);
|
|
934
|
+
}
|
|
935
|
+
return declared;
|
|
936
|
+
};
|
|
937
|
+
const sourceView = { get: (name, scope) => resolveRaw(name, scope) };
|
|
938
|
+
return {
|
|
939
|
+
sourceView,
|
|
940
|
+
register(tool) {
|
|
941
|
+
const toolName = nameOf(tool);
|
|
942
|
+
if (toolName === void 0) return () => {};
|
|
943
|
+
if (own.has(toolName)) throw new Error(`tool "${toolName}" is already registered in codemode root registry`);
|
|
944
|
+
own.set(toolName, tool);
|
|
945
|
+
return () => {
|
|
946
|
+
if (own.get(toolName) === tool) own.delete(toolName);
|
|
947
|
+
};
|
|
948
|
+
},
|
|
949
|
+
include(source) {
|
|
950
|
+
sources.push(source);
|
|
951
|
+
return () => {
|
|
952
|
+
const index = sources.indexOf(source);
|
|
953
|
+
if (index >= 0) sources.splice(index, 1);
|
|
954
|
+
};
|
|
955
|
+
},
|
|
956
|
+
get(name, scope) {
|
|
957
|
+
const raw = resolveRaw(name, scope);
|
|
958
|
+
if (raw === void 0) return void 0;
|
|
959
|
+
if (rules.options.guard && name !== rules.options.runToolName) {
|
|
960
|
+
if (isMaskedName(name, rules, hooks.viewForName(name, sourceView))) return void 0;
|
|
961
|
+
}
|
|
962
|
+
return raw;
|
|
963
|
+
},
|
|
964
|
+
getAll(scope) {
|
|
965
|
+
const all = resolveAllRaw(scope);
|
|
966
|
+
hooks.onCatalog?.(all);
|
|
967
|
+
const names = [];
|
|
968
|
+
for (const tool of all) {
|
|
969
|
+
const name = nameOf(tool);
|
|
970
|
+
if (name !== void 0) names.push(name);
|
|
971
|
+
}
|
|
972
|
+
const view = hooks.view(names, sourceView);
|
|
973
|
+
const visible = [];
|
|
974
|
+
const visibleNames = [];
|
|
975
|
+
const masked = [];
|
|
976
|
+
for (const tool of all) {
|
|
977
|
+
const name = nameOf(tool);
|
|
978
|
+
if (name === void 0) continue;
|
|
979
|
+
if (isMaskedName(name, rules, view)) masked.push(name);
|
|
980
|
+
else {
|
|
981
|
+
visible.push(tool);
|
|
982
|
+
visibleNames.push(name);
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
if (hooks.isProbing?.() !== true) hooks.onDescribe?.({
|
|
986
|
+
visible: visibleNames,
|
|
987
|
+
masked
|
|
988
|
+
});
|
|
989
|
+
return visible;
|
|
990
|
+
},
|
|
991
|
+
bindings(scope, toolStep) {
|
|
992
|
+
if (typeof toolStep === "object" && toolStep !== null) return [...ensureStepBindings(toolStep, scope).values()];
|
|
993
|
+
return [...dedupeBindings(resolveAllRaw(scope)).values()];
|
|
994
|
+
},
|
|
995
|
+
binding(name, scope, toolStep) {
|
|
996
|
+
const current = resolveRaw(name, scope);
|
|
997
|
+
if (current === void 0 || typeof toolStep !== "object" || toolStep === null) return current;
|
|
998
|
+
return ensureStepBindings(toolStep, scope).get(name) === current ? current : void 0;
|
|
999
|
+
},
|
|
1000
|
+
...typeof hooks.reset === "function" ? { async reset(agent) {
|
|
1001
|
+
await hooks.reset(agent);
|
|
1002
|
+
} } : {}
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
892
1005
|
//#endregion
|
|
893
1006
|
//#region src/host/runtime/codemode/transport.ts
|
|
894
1007
|
/**
|
|
@@ -1242,7 +1355,7 @@ function createTransportDefinition(host, rules) {
|
|
|
1242
1355
|
if (hasRawEscalation && isStrictSandboxUnsupported(runtime)) throw new CodemodeArgsError("sandbox_permissions and justification are not available for this PTC runtime");
|
|
1243
1356
|
const prevalidatedEscalation = hasRawEscalation && runtime.sandboxMode !== void 0 ? validateEscalationArgs(input.rawSandboxPermissions, input.rawJustification) : void 0;
|
|
1244
1357
|
await host.awaitPredecessors?.(exec.agent, exec.signal);
|
|
1245
|
-
const catalog = host.catalog(exec.agent, exec.toolSet);
|
|
1358
|
+
const catalog = host.catalog(exec.agent, exec.toolStep ?? exec.toolSet);
|
|
1246
1359
|
const runController = new AbortController();
|
|
1247
1360
|
const onOuterAbort = () => {
|
|
1248
1361
|
runController.abort(exec.signal.reason);
|
|
@@ -1289,7 +1402,8 @@ function createTransportDefinition(host, rules) {
|
|
|
1289
1402
|
callId,
|
|
1290
1403
|
signal: nestedSignal,
|
|
1291
1404
|
agent: exec.agent,
|
|
1292
|
-
toolSet: exec.toolSet
|
|
1405
|
+
toolSet: exec.toolSet,
|
|
1406
|
+
...exec.toolStep === void 0 ? {} : { toolStep: exec.toolStep }
|
|
1293
1407
|
}),
|
|
1294
1408
|
/**
|
|
1295
1409
|
* 提交阶段:按**提交顺序**逐条执行,落在会话里的副作用因此与提交顺序一致。
|
|
@@ -2089,7 +2203,8 @@ async function forwardNarration(host, narration, exec, signal) {
|
|
|
2089
2203
|
callId: String(exec.callId) + ":ptc:0",
|
|
2090
2204
|
signal,
|
|
2091
2205
|
agent: exec.agent,
|
|
2092
|
-
toolSet: exec.toolSet
|
|
2206
|
+
toolSet: exec.toolSet,
|
|
2207
|
+
...exec.toolStep === void 0 ? {} : { toolStep: exec.toolStep }
|
|
2093
2208
|
});
|
|
2094
2209
|
} catch {}
|
|
2095
2210
|
}
|
|
@@ -3033,6 +3148,99 @@ const inject = ["tools", "systemPrompt"];
|
|
|
3033
3148
|
const DEBUG_RING = 50;
|
|
3034
3149
|
const CORDIS_ORIGINAL_DESCRIPTION = "cordis.original";
|
|
3035
3150
|
const PTC_RUNTIME_PACKAGE = "@deepseek-ai/dsh-ptc-runtime";
|
|
3151
|
+
const LEGACY_NATIVE_EXECUTOR_PACKAGE = "@deepseek-ai/dsh-tool-executor-native";
|
|
3152
|
+
const TOOLS_PIPELINE_PACKAGE = "@deepseek-ai/dsh-tools/pipeline";
|
|
3153
|
+
let cachedToolsPipelinePromise;
|
|
3154
|
+
/** 从给定根目录解析包(或子路径)的真实入口 file:// URL(经过 realpathSync 归一化)。 */
|
|
3155
|
+
function resolvePackageModuleUrl(rootDir, specifier) {
|
|
3156
|
+
let req;
|
|
3157
|
+
try {
|
|
3158
|
+
req = createRequire(join(rootDir, "package.json"));
|
|
3159
|
+
} catch {
|
|
3160
|
+
return;
|
|
3161
|
+
}
|
|
3162
|
+
let entryPath;
|
|
3163
|
+
try {
|
|
3164
|
+
entryPath = req.resolve(specifier);
|
|
3165
|
+
} catch {
|
|
3166
|
+
const parts = specifier.split("/");
|
|
3167
|
+
const pkgName = specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
|
|
3168
|
+
const subpath = specifier.slice(pkgName.length);
|
|
3169
|
+
const exportKey = subpath === "" ? "." : `.${subpath}`;
|
|
3170
|
+
try {
|
|
3171
|
+
const manifestPath = req.resolve(`${pkgName}/package.json`);
|
|
3172
|
+
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
3173
|
+
const target = manifest.exports?.[exportKey];
|
|
3174
|
+
const rel = typeof target === "string" ? target : typeof target === "object" && target !== null ? target["import"] ?? target["default"] : exportKey === "." ? manifest.main : void 0;
|
|
3175
|
+
if (typeof rel === "string" && rel.length > 0) {
|
|
3176
|
+
const candidate = resolve(dirname(manifestPath), rel);
|
|
3177
|
+
if (existsSync(candidate)) entryPath = candidate;
|
|
3178
|
+
}
|
|
3179
|
+
} catch {
|
|
3180
|
+
return;
|
|
3181
|
+
}
|
|
3182
|
+
}
|
|
3183
|
+
if (entryPath === void 0) return void 0;
|
|
3184
|
+
try {
|
|
3185
|
+
return pathToFileURL(realpathSync(entryPath)).href;
|
|
3186
|
+
} catch {
|
|
3187
|
+
return pathToFileURL(entryPath).href;
|
|
3188
|
+
}
|
|
3189
|
+
}
|
|
3190
|
+
/** 同步加载旧代(0.2.2–0.2.3-alpha.2)的 `@deepseek-ai/dsh-tool-executor-native`。 */
|
|
3191
|
+
function loadLegacyNativeToolExecutor(ctx) {
|
|
3192
|
+
const roots = /* @__PURE__ */ new Set();
|
|
3193
|
+
contextBaseDirs(ctx, roots);
|
|
3194
|
+
for (const dir of candidatePackageRoots()) roots.add(dir);
|
|
3195
|
+
const tryRequire = (req) => {
|
|
3196
|
+
try {
|
|
3197
|
+
const mod = req(LEGACY_NATIVE_EXECUTOR_PACKAGE);
|
|
3198
|
+
return typeof mod?.NativeToolExecutor === "function" ? mod.NativeToolExecutor : void 0;
|
|
3199
|
+
} catch {
|
|
3200
|
+
return;
|
|
3201
|
+
}
|
|
3202
|
+
};
|
|
3203
|
+
for (const rootDir of roots) try {
|
|
3204
|
+
const found = tryRequire(createRequire(join(rootDir, "package.json")));
|
|
3205
|
+
if (found !== void 0) return found;
|
|
3206
|
+
} catch {}
|
|
3207
|
+
try {
|
|
3208
|
+
return tryRequire(createRequire(import.meta.url));
|
|
3209
|
+
} catch {
|
|
3210
|
+
return;
|
|
3211
|
+
}
|
|
3212
|
+
}
|
|
3213
|
+
/** 按需加载 DSH 0.2.3-alpha.3+ `@deepseek-ai/dsh-tools/pipeline`,供程序内子调用走完整策略管线。 */
|
|
3214
|
+
async function loadToolsPipeline(ctx) {
|
|
3215
|
+
if (cachedToolsPipelinePromise !== void 0) return cachedToolsPipelinePromise;
|
|
3216
|
+
cachedToolsPipelinePromise = (async () => {
|
|
3217
|
+
const roots = /* @__PURE__ */ new Set();
|
|
3218
|
+
contextBaseDirs(ctx, roots);
|
|
3219
|
+
for (const dir of candidatePackageRoots()) roots.add(dir);
|
|
3220
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3221
|
+
const tryImport = async (specifier) => {
|
|
3222
|
+
if (seen.has(specifier)) return void 0;
|
|
3223
|
+
seen.add(specifier);
|
|
3224
|
+
try {
|
|
3225
|
+
const mod = await import(specifier);
|
|
3226
|
+
if (typeof mod["ToolExecutionPipeline"] === "function" && typeof mod["executeToolBatch"] === "function") return {
|
|
3227
|
+
ToolExecutionPipeline: mod["ToolExecutionPipeline"],
|
|
3228
|
+
executeToolBatch: mod["executeToolBatch"]
|
|
3229
|
+
};
|
|
3230
|
+
} catch {}
|
|
3231
|
+
};
|
|
3232
|
+
for (const rootDir of roots) {
|
|
3233
|
+
const url = resolvePackageModuleUrl(rootDir, TOOLS_PIPELINE_PACKAGE);
|
|
3234
|
+
if (url === void 0) continue;
|
|
3235
|
+
const loaded = await tryImport(url);
|
|
3236
|
+
if (loaded !== void 0) return loaded;
|
|
3237
|
+
}
|
|
3238
|
+
return tryImport(TOOLS_PIPELINE_PACKAGE);
|
|
3239
|
+
})();
|
|
3240
|
+
const resolved = await cachedToolsPipelinePromise;
|
|
3241
|
+
if (resolved === void 0) cachedToolsPipelinePromise = void 0;
|
|
3242
|
+
return resolved;
|
|
3243
|
+
}
|
|
3036
3244
|
const resolvedPtcClassesByProto = /* @__PURE__ */ new WeakMap();
|
|
3037
3245
|
const pendingPtcClassesByProto = /* @__PURE__ */ new WeakMap();
|
|
3038
3246
|
/** 展开 Cordis 代理链,拿到最底层真实的 runtime 对象。 */
|
|
@@ -3292,20 +3500,32 @@ function apply(ctx, config = {}) {
|
|
|
3292
3500
|
};
|
|
3293
3501
|
const scopeKey = findScopeKey(ctx);
|
|
3294
3502
|
if (rules.options.nativeScope && scopeKey === void 0) log("warn", "[codemode] no registry scope tag on this context: masking falls back to name rules only (" + rules.options.hiddenPrefixes.join(", ") + "). Mount this row inside an agent preset to hide every tool the preset does not own.");
|
|
3295
|
-
/** 最近一次 describe
|
|
3503
|
+
/** 最近一次 describe / getAll 收到的完整定义集(含被遮蔽的),作为兜底快照。 */
|
|
3296
3504
|
let catalog = [];
|
|
3297
3505
|
const debugRing = [];
|
|
3298
3506
|
let firstDescribeLogged = false;
|
|
3507
|
+
let rootRegistry;
|
|
3508
|
+
let rootPipelineInstance;
|
|
3509
|
+
let rootPipelineModule;
|
|
3299
3510
|
/**
|
|
3300
|
-
* 解析当前调用方 agent
|
|
3511
|
+
* 解析当前调用方 agent 与步骤准入下的完整未遮蔽工具清单。
|
|
3301
3512
|
*
|
|
3302
|
-
*
|
|
3303
|
-
*
|
|
3304
|
-
* `
|
|
3513
|
+
* - DSH 0.2.3-alpha.3+(`setRoot` 模式):从 `rootRegistry.bindings(agent, toolStep)` 读取
|
|
3514
|
+
* `ctx.tools` 注入的未遮蔽注册表视图,并按 `toolStep` 钉死步骤绑定;
|
|
3515
|
+
* - DSH 0.2.2–0.2.3-alpha.2(`setExecutor` 模式):从 `ctx.tools.definitions(agent, toolSet)` 实时读取;
|
|
3516
|
+
* - 测试替身未提供上述接口时回退到最近一次 `catalog`。
|
|
3305
3517
|
*/
|
|
3306
|
-
const resolveCatalog = (agent,
|
|
3518
|
+
const resolveCatalog = (agent, stepOrToolSet) => {
|
|
3519
|
+
if (rootRegistry !== void 0) try {
|
|
3520
|
+
const scopeObj = typeof agent === "object" && agent !== null ? agent : void 0;
|
|
3521
|
+
const defs = rootRegistry.bindings(scopeObj, stepOrToolSet);
|
|
3522
|
+
if (Array.isArray(defs) && defs.length > 0) {
|
|
3523
|
+
const entries = defs.map(toCatalogEntry).filter((entry) => entry !== void 0);
|
|
3524
|
+
if (entries.length > 0) return entries;
|
|
3525
|
+
}
|
|
3526
|
+
} catch {}
|
|
3307
3527
|
if (agent !== void 0 && typeof tools.definitions === "function") try {
|
|
3308
|
-
const defs = tools.definitions(agent,
|
|
3528
|
+
const defs = tools.definitions(agent, stepOrToolSet);
|
|
3309
3529
|
if (Array.isArray(defs) && defs.length > 0) {
|
|
3310
3530
|
const entries = defs.map(toCatalogEntry).filter((entry) => entry !== void 0);
|
|
3311
3531
|
if (entries.length > 0) return entries;
|
|
@@ -3398,11 +3618,32 @@ function apply(ctx, config = {}) {
|
|
|
3398
3618
|
};
|
|
3399
3619
|
let batch;
|
|
3400
3620
|
try {
|
|
3401
|
-
|
|
3621
|
+
if (rootRegistry !== void 0 && typeof context.waterfall === "function" && typeof tools.checkGuards === "function") {
|
|
3622
|
+
const mod = rootPipelineModule ?? await loadToolsPipeline(ctx);
|
|
3623
|
+
if (mod !== void 0) {
|
|
3624
|
+
rootPipelineModule = mod;
|
|
3625
|
+
if (rootPipelineInstance === void 0) {
|
|
3626
|
+
const registry = rootRegistry;
|
|
3627
|
+
rootPipelineInstance = new mod.ToolExecutionPipeline(ctx, { get: (calledName, scope, toolStep) => registry.binding(calledName, typeof scope === "object" && scope !== null ? scope : void 0, toolStep) });
|
|
3628
|
+
}
|
|
3629
|
+
const step = request.toolStep ?? request.toolSet;
|
|
3630
|
+
batch = await mod.executeToolBatch({
|
|
3631
|
+
calls: [call],
|
|
3632
|
+
signal: request.signal,
|
|
3633
|
+
...request.agent === void 0 ? {} : { agent: request.agent },
|
|
3634
|
+
...step === void 0 ? {} : { toolStep: step }
|
|
3635
|
+
}, rootPipelineInstance);
|
|
3636
|
+
} else batch = await tools.execute({
|
|
3637
|
+
calls: [call],
|
|
3638
|
+
signal: request.signal,
|
|
3639
|
+
...request.agent === void 0 ? {} : { agent: request.agent },
|
|
3640
|
+
...request.toolStep !== void 0 ? { toolStep: request.toolStep } : request.toolSet === void 0 ? {} : { toolSet: request.toolSet }
|
|
3641
|
+
});
|
|
3642
|
+
} else batch = await tools.execute({
|
|
3402
3643
|
calls: [call],
|
|
3403
3644
|
signal: request.signal,
|
|
3404
3645
|
...request.agent === void 0 ? {} : { agent: request.agent },
|
|
3405
|
-
...request.toolSet === void 0 ? {} : { toolSet: request.toolSet }
|
|
3646
|
+
...request.toolStep !== void 0 ? { toolStep: request.toolStep } : request.toolSet === void 0 ? {} : { toolSet: request.toolSet }
|
|
3406
3647
|
});
|
|
3407
3648
|
} catch (error) {
|
|
3408
3649
|
return { error: messageOf(error) };
|
|
@@ -3428,65 +3669,115 @@ function apply(ctx, config = {}) {
|
|
|
3428
3669
|
}
|
|
3429
3670
|
};
|
|
3430
3671
|
for (const definition of createDiscoveryDefinitions(rules, () => currentCatalogSnapshot() ?? catalog, () => debugRing)) tools.register(definition);
|
|
3431
|
-
|
|
3672
|
+
const transportDef = createTransportDefinition(host, rules);
|
|
3673
|
+
tools.register(transportDef);
|
|
3674
|
+
const sectionText = () => {
|
|
3675
|
+
const runtime = runtimeOf();
|
|
3676
|
+
return buildCodemodeSectionText({
|
|
3677
|
+
runToolName: rules.options.runToolName,
|
|
3678
|
+
metaTools: rules.options.metaTools,
|
|
3679
|
+
language: runtime?.language,
|
|
3680
|
+
programFormat: runtime?.programFormat,
|
|
3681
|
+
nativeToolsOnly: rules.options.nativeToolsOnly,
|
|
3682
|
+
nativeTools: rules.options.nativeTools
|
|
3683
|
+
});
|
|
3684
|
+
};
|
|
3685
|
+
const resetEnvironment = async (agent) => {
|
|
3686
|
+
const runtime = runtimeOf();
|
|
3687
|
+
if (runtime === void 0) throw new Error("codemode: no PTC runtime is mounted (ctx.ptcRuntime); the program transport is unavailable");
|
|
3688
|
+
if (!runtime.retainsState) throw new CodeResetFailedError("The PTC runtime does not retain an environment");
|
|
3689
|
+
try {
|
|
3690
|
+
await retention.reset(agent, () => {
|
|
3691
|
+
const inject = typeof agent === "object" && agent !== null ? agent.inject : void 0;
|
|
3692
|
+
if (typeof inject === "function") inject.call(agent, createUserMessage({
|
|
3693
|
+
content: [{
|
|
3694
|
+
type: "text",
|
|
3695
|
+
text: "Program environment reset; retained variables cleared. Completed tool effects remain."
|
|
3696
|
+
}],
|
|
3697
|
+
source: { kind: PLUGIN_MESSAGE_SOURCE_KIND }
|
|
3698
|
+
}));
|
|
3699
|
+
});
|
|
3700
|
+
} catch (error) {
|
|
3701
|
+
throw new CodeResetFailedError("Program environment reset failed: " + messageOf(error) + ". State may not be cleared; retry the host reset before running more code.");
|
|
3702
|
+
}
|
|
3703
|
+
};
|
|
3704
|
+
const recordDescribe = (decision) => {
|
|
3705
|
+
const hidden = summarizeHidden(decision.masked);
|
|
3706
|
+
debugRing.push({
|
|
3707
|
+
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3708
|
+
visible: decision.visible,
|
|
3709
|
+
hidden
|
|
3710
|
+
});
|
|
3711
|
+
while (debugRing.length > DEBUG_RING) debugRing.shift();
|
|
3712
|
+
const namespaces = hidden.namespaces.map((entry) => entry.namespace + "=" + String(entry.count)).join(", ");
|
|
3713
|
+
const line = "[codemode] masked " + String(hidden.total) + " non-standard tool(s)" + (namespaces === "" ? "" : " (" + namespaces + ")") + "; request tools: " + decision.visible.join(", ");
|
|
3714
|
+
if (!firstDescribeLogged) {
|
|
3715
|
+
firstDescribeLogged = true;
|
|
3716
|
+
log("info", line);
|
|
3717
|
+
} else log("debug", line);
|
|
3718
|
+
};
|
|
3719
|
+
if (typeof tools.setRoot === "function") {
|
|
3720
|
+
loadToolsPipeline(ctx).then((mod) => {
|
|
3721
|
+
if (mod !== void 0) rootPipelineModule = mod;
|
|
3722
|
+
});
|
|
3723
|
+
let probingSetRoot = false;
|
|
3724
|
+
rootRegistry = createCodemodeRootRegistry(rules, {
|
|
3725
|
+
view: (names, sourceView) => resolveCatalogView(sourceView, scopeKey, names),
|
|
3726
|
+
viewForName: (toolName, sourceView) => resolveNameView(sourceView, scopeKey, toolName),
|
|
3727
|
+
onCatalog: (definitions) => {
|
|
3728
|
+
catalog = definitions.map(toCatalogEntry).filter((entry) => entry !== void 0);
|
|
3729
|
+
},
|
|
3730
|
+
onDescribe: recordDescribe,
|
|
3731
|
+
isProbing: () => probingSetRoot,
|
|
3732
|
+
reset: resetEnvironment
|
|
3733
|
+
});
|
|
3734
|
+
probingSetRoot = true;
|
|
3735
|
+
try {
|
|
3736
|
+
tools.setRoot(rootRegistry);
|
|
3737
|
+
} finally {
|
|
3738
|
+
probingSetRoot = false;
|
|
3739
|
+
}
|
|
3740
|
+
const systemPrompt = context.systemPrompt ?? serviceOf("systemPrompt");
|
|
3741
|
+
const registerSection = typeof systemPrompt === "object" && systemPrompt !== null ? systemPrompt.section : void 0;
|
|
3742
|
+
if (rules.options.sdkSection && typeof registerSection === "function") registerSection.call(systemPrompt, {
|
|
3743
|
+
name: "tools:sdk",
|
|
3744
|
+
order: sectionOrderOf(ctx),
|
|
3745
|
+
interpolate: false,
|
|
3746
|
+
text: (assembleCtx) => {
|
|
3747
|
+
const step = assembleCtx?.toolStep;
|
|
3748
|
+
if (step !== void 0 && typeof step.declares === "function") return step.declares(transportDef) ? sectionText() : "";
|
|
3749
|
+
try {
|
|
3750
|
+
return tools.get(rules.options.runToolName, assembleCtx?.scope) === transportDef ? sectionText() : "";
|
|
3751
|
+
} catch {
|
|
3752
|
+
return "";
|
|
3753
|
+
}
|
|
3754
|
+
}
|
|
3755
|
+
});
|
|
3756
|
+
const scopeNote = scopeKey === void 0 ? "" : ", everything outside this preset scope";
|
|
3757
|
+
log("info", "[codemode] active (root registry): transport [" + rules.options.runToolName + "], discovery [" + rules.options.metaTools.join(", ") + "], hiding [" + rules.options.hiddenPrefixes.join(", ") + "]" + scopeNote);
|
|
3758
|
+
return;
|
|
3759
|
+
}
|
|
3432
3760
|
if (typeof tools.setExecutor !== "function") {
|
|
3433
|
-
log("warn", "[codemode] this DSH build has
|
|
3761
|
+
log("warn", "[codemode] this DSH build has neither ctx.tools.setRoot() nor ctx.tools.setExecutor(); Code Mode requires DSH 0.2.2 or later. Switch this session to the built-in ptc preset.");
|
|
3762
|
+
return;
|
|
3763
|
+
}
|
|
3764
|
+
const LegacyNativeToolExecutor = loadLegacyNativeToolExecutor(ctx);
|
|
3765
|
+
if (LegacyNativeToolExecutor === void 0) {
|
|
3766
|
+
log("warn", "[codemode] could not resolve @deepseek-ai/dsh-tool-executor-native for legacy ctx.tools.setExecutor(); switch this session to the built-in ptc preset.");
|
|
3434
3767
|
return;
|
|
3435
3768
|
}
|
|
3436
|
-
const delegate = new
|
|
3769
|
+
const delegate = new LegacyNativeToolExecutor(ctx);
|
|
3437
3770
|
const view = () => resolveCatalogView(tools, scopeKey, catalog.map((entry) => entry.name));
|
|
3438
3771
|
const executor = createCodemodeExecutor(ctx, rules, {
|
|
3439
3772
|
delegate,
|
|
3440
3773
|
view,
|
|
3441
3774
|
viewForName: (toolName) => resolveNameView(tools, scopeKey, toolName),
|
|
3442
|
-
sectionText
|
|
3443
|
-
const runtime = runtimeOf();
|
|
3444
|
-
return buildCodemodeSectionText({
|
|
3445
|
-
runToolName: rules.options.runToolName,
|
|
3446
|
-
metaTools: rules.options.metaTools,
|
|
3447
|
-
language: runtime?.language,
|
|
3448
|
-
programFormat: runtime?.programFormat,
|
|
3449
|
-
nativeToolsOnly: rules.options.nativeToolsOnly,
|
|
3450
|
-
nativeTools: rules.options.nativeTools
|
|
3451
|
-
});
|
|
3452
|
-
},
|
|
3775
|
+
sectionText,
|
|
3453
3776
|
onCatalog: (definitions) => {
|
|
3454
3777
|
catalog = definitions.map(toCatalogEntry).filter((entry) => entry !== void 0);
|
|
3455
3778
|
},
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
if (runtime === void 0) throw new Error("codemode: no PTC runtime is mounted (ctx.ptcRuntime); the program transport is unavailable");
|
|
3459
|
-
if (!runtime.retainsState) throw new CodeResetFailedError("The PTC runtime does not retain an environment");
|
|
3460
|
-
try {
|
|
3461
|
-
await retention.reset(agent, () => {
|
|
3462
|
-
const inject = typeof agent === "object" && agent !== null ? agent.inject : void 0;
|
|
3463
|
-
if (typeof inject === "function") inject.call(agent, createUserMessage({
|
|
3464
|
-
content: [{
|
|
3465
|
-
type: "text",
|
|
3466
|
-
text: "Program environment reset; retained variables cleared. Completed tool effects remain."
|
|
3467
|
-
}],
|
|
3468
|
-
source: { kind: PLUGIN_MESSAGE_SOURCE_KIND }
|
|
3469
|
-
}));
|
|
3470
|
-
});
|
|
3471
|
-
} catch (error) {
|
|
3472
|
-
throw new CodeResetFailedError("Program environment reset failed: " + messageOf(error) + ". State may not be cleared; retry the host reset before running more code.");
|
|
3473
|
-
}
|
|
3474
|
-
},
|
|
3475
|
-
onDescribe: (decision) => {
|
|
3476
|
-
const hidden = summarizeHidden(decision.masked);
|
|
3477
|
-
debugRing.push({
|
|
3478
|
-
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3479
|
-
visible: decision.visible,
|
|
3480
|
-
hidden
|
|
3481
|
-
});
|
|
3482
|
-
while (debugRing.length > DEBUG_RING) debugRing.shift();
|
|
3483
|
-
const namespaces = hidden.namespaces.map((entry) => entry.namespace + "=" + String(entry.count)).join(", ");
|
|
3484
|
-
const line = "[codemode] masked " + String(hidden.total) + " non-standard tool(s)" + (namespaces === "" ? "" : " (" + namespaces + ")") + "; request tools: " + decision.visible.join(", ");
|
|
3485
|
-
if (!firstDescribeLogged) {
|
|
3486
|
-
firstDescribeLogged = true;
|
|
3487
|
-
log("info", line);
|
|
3488
|
-
} else log("debug", line);
|
|
3489
|
-
}
|
|
3779
|
+
reset: resetEnvironment,
|
|
3780
|
+
onDescribe: recordDescribe
|
|
3490
3781
|
});
|
|
3491
3782
|
tools.setExecutor(executor);
|
|
3492
3783
|
const scopeNote = scopeKey === void 0 ? "" : ", everything outside this preset scope";
|