@dsmm/dsmm 0.2.0 → 0.2.2
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 +38 -66
- package/agent-presets/dsmm-builder/agent.cordis.yml +10 -2015
- package/agent-presets/dsmm-clarifier/agent.cordis.yml +24 -343
- package/agent-presets/dsmm-code-search/agent.cordis.yml +19 -6
- package/agent-presets/dsmm-coding/agent.cordis.yml +19 -438
- package/agent-presets/dsmm-complex/agent.cordis.yml +23 -1009
- package/agent-presets/dsmm-creative/agent.cordis.yml +25 -442
- package/agent-presets/dsmm-cross-cutting/agent.cordis.yml +29 -1013
- package/agent-presets/dsmm-deep/agent.cordis.yml +24 -1008
- package/agent-presets/dsmm-doc-search/agent.cordis.yml +19 -6
- package/agent-presets/dsmm-documenting/agent.cordis.yml +26 -439
- package/agent-presets/dsmm-frontend/agent.cordis.yml +21 -440
- package/agent-presets/dsmm-hard-reasoning/agent.cordis.yml +22 -441
- package/agent-presets/dsmm-media-reader/agent.cordis.yml +19 -6
- package/agent-presets/dsmm-normal-task/agent.cordis.yml +19 -438
- package/agent-presets/dsmm-oracle/agent.cordis.yml +25 -340
- package/agent-presets/dsmm-oracle-2nd/agent.cordis.yml +25 -340
- package/agent-presets/dsmm-orchestrator/agent.cordis.yml +29 -2025
- package/agent-presets/dsmm-plan-critic/agent.cordis.yml +24 -341
- package/agent-presets/dsmm-planner/agent.cordis.yml +14 -344
- package/agent-presets/dsmm-quick/agent.cordis.yml +19 -6
- package/agent-presets/dsmm-research/agent.cordis.yml +23 -8
- package/agent-presets/dsmm-reviewer/agent.cordis.yml +25 -340
- package/docs/agent-presets.md +36 -52
- package/docs/compatibility.md +50 -108
- package/docs/deferred-native-approval-risk.md +19 -0
- package/docs/design.md +2 -2
- package/docs/lsp.md +11 -21
- package/docs/migration-from-ocmm.md +2 -2
- package/docs/model-routing.md +84 -59
- package/docs/native-permissions.md +35 -0
- package/docs/profiles.md +40 -87
- package/docs/releasing.md +83 -2
- package/docs/roadmap.md +71 -17
- package/docs/settings-status.md +34 -169
- package/docs/skill-sync.md +52 -15
- package/lib/child-admission-contract.d.ts +37 -0
- package/lib/child-admission-contract.js +2 -0
- package/lib/child-admission.d.ts +42 -0
- package/lib/child-admission.js +162 -0
- package/lib/child-capture.d.ts +81 -0
- package/lib/child-capture.js +203 -0
- package/lib/child-evidence.d.ts +17 -0
- package/lib/child-evidence.js +43 -0
- package/lib/client/ChildrenPanel.d.ts +43 -0
- package/lib/client/ChildrenPanel.js +82 -0
- package/lib/client/DeploymentPage.js +15 -8
- package/lib/client/EditableChoice.d.ts +17 -0
- package/lib/client/EditableChoice.js +49 -0
- package/lib/client/PermissionsPanel.d.ts +14 -0
- package/lib/client/PermissionsPanel.js +46 -0
- package/lib/client/ProfilesSection.js +30 -15
- package/lib/client/RoleAvailability.d.ts +7 -0
- package/lib/client/RoleAvailability.js +19 -0
- package/lib/client/SessionProfiles.js +27 -9
- package/lib/client/StructuredEditor.js +15 -7
- package/lib/client/children-controller.d.ts +98 -0
- package/lib/client/children-controller.js +296 -0
- package/lib/client/children-locales.d.ts +367 -0
- package/lib/client/children-locales.js +69 -0
- package/lib/client/controller.d.ts +6 -1
- package/lib/client/controller.js +14 -8
- package/lib/client/deployment-data.d.ts +2 -1
- package/lib/client/deployment-data.js +34 -5
- package/lib/client/deployment-locales.d.ts +4 -0
- package/lib/client/deployment-locales.js +11 -2
- package/lib/client/diagnostics.d.ts +14 -0
- package/lib/client/diagnostics.js +53 -0
- package/lib/client/index.d.ts +4 -0
- package/lib/client/index.js +96 -2
- package/lib/client/locales.d.ts +54 -0
- package/lib/client/locales.js +34 -16
- package/lib/client/permission-client.d.ts +16 -0
- package/lib/client/permission-client.js +38 -0
- package/lib/client/permission-controller.d.ts +62 -0
- package/lib/client/permission-controller.js +149 -0
- package/lib/client/permission-locales.d.ts +114 -0
- package/lib/client/permission-locales.js +75 -0
- package/lib/client/session-labels.js +4 -4
- package/lib/client/structured.js +19 -5
- package/lib/client/styles.d.ts +1 -1
- package/lib/client/styles.js +20 -0
- package/lib/client.js +5780 -1679
- package/lib/core-permission-authority.d.ts +18 -0
- package/lib/core-permission-authority.js +255 -0
- package/lib/core-permissions.d.ts +8 -0
- package/lib/core-permissions.js +33 -0
- package/lib/delivery-authority.d.ts +68 -0
- package/lib/delivery-authority.js +260 -0
- package/lib/deployment-config.d.ts +23 -0
- package/lib/deployment-config.js +61 -40
- package/lib/deployment-permission-rules.d.ts +55 -0
- package/lib/deployment-permission-rules.js +306 -0
- package/lib/dsh-types.d.ts +10 -4
- package/lib/guards.d.ts +1 -1
- package/lib/guards.js +29 -8
- package/lib/host-llm-startup.d.ts +41 -0
- package/lib/host-llm-startup.js +65 -0
- package/lib/host-llm.d.ts +92 -0
- package/lib/host-llm.js +325 -0
- package/lib/index.d.ts +15 -4
- package/lib/index.js +300 -47
- package/lib/legacy-child-policy.d.ts +51 -0
- package/lib/legacy-child-policy.js +123 -0
- package/lib/legacy-read-composition.d.ts +20 -0
- package/lib/legacy-read-composition.js +144 -0
- package/lib/legacy-read-contracts.d.ts +157 -0
- package/lib/legacy-read-contracts.js +39 -0
- package/lib/legacy-read-host.d.ts +19 -0
- package/lib/legacy-read-host.js +67 -0
- package/lib/legacy-read-integration.d.ts +121 -0
- package/lib/legacy-read-integration.js +522 -0
- package/lib/legacy-read-proxy.d.ts +26 -0
- package/lib/legacy-read-proxy.js +237 -0
- package/lib/live-pi-ai-owner.d.ts +18 -0
- package/lib/live-pi-ai-owner.js +144 -0
- package/lib/llm-runtime.d.ts +11 -0
- package/lib/llm-runtime.js +21 -0
- package/lib/managed-settings.d.ts +5 -0
- package/lib/managed-settings.js +14 -0
- package/lib/model-parameter-policy.d.ts +11 -0
- package/lib/model-parameter-policy.js +27 -0
- package/lib/model-routing.js +28 -17
- package/lib/modules.d.ts +13 -5
- package/lib/modules.js +17 -1
- package/lib/native-child-evidence.d.ts +42 -0
- package/lib/native-child-evidence.js +133 -0
- package/lib/native-pi-ai-wire.d.ts +37 -0
- package/lib/native-pi-ai-wire.js +261 -0
- package/lib/native-scope.js +1 -1
- package/lib/permission-bash.d.ts +6 -0
- package/lib/permission-bash.js +7 -0
- package/lib/permission-control.d.ts +73 -0
- package/lib/permission-control.js +205 -0
- package/lib/permission-controller.d.ts +68 -0
- package/lib/permission-controller.js +317 -0
- package/lib/permission-errors.d.ts +7 -0
- package/lib/permission-errors.js +21 -0
- package/lib/permission-fs-search.d.ts +5 -0
- package/lib/permission-fs-search.js +7 -0
- package/lib/permission-fs.d.ts +5 -0
- package/lib/permission-fs.js +7 -0
- package/lib/permission-native-access.d.ts +11 -0
- package/lib/permission-native-access.js +6 -0
- package/lib/permission-native-command.d.ts +10 -0
- package/lib/permission-native-command.js +93 -0
- package/lib/permission-native-rules.d.ts +75 -0
- package/lib/permission-native-rules.js +278 -0
- package/lib/permission-pwsh.d.ts +6 -0
- package/lib/permission-pwsh.js +7 -0
- package/lib/permission-remote.d.ts +26 -0
- package/lib/permission-remote.js +53 -0
- package/lib/permission-rpc.d.ts +29 -0
- package/lib/permission-rpc.js +152 -0
- package/lib/permission-rules.d.ts +115 -0
- package/lib/permission-rules.js +256 -0
- package/lib/permission-settings.d.ts +45 -0
- package/lib/permission-settings.js +48 -0
- package/lib/permission-shell.d.ts +38 -0
- package/lib/permission-shell.js +150 -0
- package/lib/permission-web.d.ts +5 -0
- package/lib/permission-web.js +7 -0
- package/lib/preset-registry.js +36 -25
- package/lib/profile-diagnostics.d.ts +45 -0
- package/lib/profile-diagnostics.js +148 -0
- package/lib/profile-locale.d.ts +3 -0
- package/lib/profile-locale.js +2 -0
- package/lib/profile-remote.d.ts +8 -0
- package/lib/profile-remote.js +163 -39
- package/lib/profile-rpc.d.ts +4 -3
- package/lib/profile-rpc.js +14 -12
- package/lib/profile-runtime.d.ts +40 -1
- package/lib/profile-runtime.js +368 -93
- package/lib/profile-store.d.ts +11 -0
- package/lib/profile-store.js +143 -11
- package/lib/profile-types.d.ts +70 -1
- package/lib/profile-types.js +1 -0
- package/lib/profiles.d.ts +16 -2
- package/lib/profiles.js +156 -79
- package/lib/prompt-content.js +1 -1
- package/lib/prompts.d.ts +37 -2
- package/lib/prompts.js +111 -9
- package/lib/recovery-policy.js +20 -7
- package/lib/role-control-remote.d.ts +38 -0
- package/lib/role-control-remote.js +211 -0
- package/lib/role-control-rpc.d.ts +51 -0
- package/lib/role-control-rpc.js +377 -0
- package/lib/role-control-types.d.ts +92 -0
- package/lib/role-control-types.js +8 -0
- package/lib/role-invocation.d.ts +47 -0
- package/lib/role-invocation.js +135 -0
- package/lib/role-llm-runtime.d.ts +17 -0
- package/lib/role-llm-runtime.js +62 -0
- package/lib/role-llm.d.ts +31 -0
- package/lib/role-llm.js +66 -0
- package/lib/role-policy.d.ts +49 -8
- package/lib/role-policy.js +437 -60
- package/lib/role-providers.d.ts +1 -1
- package/lib/role-providers.js +30 -35
- package/lib/role-routing.d.ts +11 -2
- package/lib/role-routing.js +42 -25
- package/lib/role-runs.d.ts +135 -0
- package/lib/role-runs.js +304 -0
- package/lib/role-subagents.d.ts +58 -3
- package/lib/role-subagents.js +169 -56
- package/lib/roles.d.ts +5 -6
- package/lib/roles.js +10 -39
- package/lib/route-json.d.ts +19 -0
- package/lib/route-json.js +129 -0
- package/lib/routing-policy.d.ts +2 -0
- package/lib/routing-policy.js +12 -2
- package/lib/runtime-integration.d.ts +112 -0
- package/lib/runtime-integration.js +784 -0
- package/lib/runtime-recovery.js +18 -8
- package/lib/settings.d.ts +47 -13
- package/lib/settings.js +217 -82
- package/lib/skills.js +2 -2
- package/lib/status.d.ts +10 -1
- package/lib/status.js +11 -8
- package/lib/subagent-runtime.d.ts +45 -0
- package/lib/subagent-runtime.js +131 -0
- package/package.json +106 -56
- package/patches/subagent-runtime.yml +15 -0
- package/prompts/deepseek-flash.md +1 -1
- package/prompts/deepseek-v4-pro.md +2 -2
- package/prompts/deepwork.md +27 -18
- package/prompts/source/agents/clarifier.md +5 -3
- package/prompts/source/agents/orchestrator.md +18 -9
- package/prompts/source/agents/plan-critic.md +5 -1
- package/prompts/source/agents/planner.md +4 -2
- package/prompts/source/agents/reviewer.md +6 -0
- package/prompts/source/category/complex.md +4 -4
- package/prompts/source/category/creative.md +6 -4
- package/prompts/source/category/cross-cutting.md +10 -8
- package/prompts/source/category/deep.md +5 -3
- package/prompts/source/category/documenting.md +7 -1
- package/prompts/source/category/frontend.md +2 -2
- package/prompts/source/category/hard-reasoning.md +3 -3
- package/prompts/source/category/research.md +4 -2
- package/prompts/source/deepwork/claude-opus-5.md +2 -2
- package/prompts/source/deepwork/codex.md +1 -1
- package/prompts/source/deepwork/default.md +22 -15
- package/prompts/source/deepwork/gemini.md +23 -16
- package/prompts/source/deepwork/glm.md +21 -14
- package/prompts/source/deepwork/gpt.md +12 -6
- package/prompts/source/deepwork/planner.md +8 -5
- package/prompts/source/manifest.json +178 -63
- package/prompts/source/shared/dsh-host-contract.md +5 -3
- package/prompts/source/shared/locale.md +2 -2
- package/prompts/source/terminal/orchestrator.md +1 -1
- package/scripts/cold-profile-composition.mjs +329 -0
- package/scripts/cold-profile-sources.mjs +238 -0
- package/scripts/migrate-cold-profile.mjs +315 -0
- package/skills/ast-grep/SKILL.md +7 -4
- package/skills/brainstorming/SKILL.md +43 -22
- package/skills/coding-agent-sessions/SKILL.md +7 -4
- package/skills/coding-agent-sessions/scripts/agent_sessions/pi_family.py +46 -46
- package/skills/coding-agent-sessions/scripts/tests/test_pi_family_scanners.py +130 -130
- package/skills/debugging/SKILL.md +14 -9
- package/skills/debugging/references/methodology/00-setup.md +14 -62
- package/skills/debugging/references/methodology/02-investigate.md +4 -4
- package/skills/debugging/references/methodology/03-flaky-triage.md +3 -3
- package/skills/debugging/references/methodology/04-hard-reasoning-escalation.md +2 -14
- package/skills/debugging/references/methodology/06-fix.md +6 -6
- package/skills/debugging/references/methodology/08-qa.md +5 -5
- package/skills/debugging/references/methodology/09-cleanup.md +15 -153
- package/skills/debugging/references/methodology/partial-runtime-evidence.md +3 -16
- package/skills/debugging/references/runtimes/bundled-js-binary.md +1 -16
- package/skills/debugging/references/runtimes/native-binary.md +9 -54
- package/skills/debugging/references/runtimes/node.md +4 -15
- package/skills/debugging/references/runtimes/python.md +3 -15
- package/skills/debugging/references/runtimes/rust.md +2 -18
- package/skills/debugging/references/tools/dap.md +1 -1
- package/skills/debugging/references/tools/ghidra.md +4 -15
- package/skills/debugging/references/tools/playwright-cli.md +3 -15
- package/skills/debugging/references/tools/pwntools.md +4 -16
- package/skills/dispatching-parallel-agents/SKILL.md +18 -16
- package/skills/frontend/SKILL.md +7 -4
- package/skills/frontend/references/design/react-dev-tooling-skill.md +1 -1
- package/skills/git-master/SKILL.md +7 -4
- package/skills/init-deep/SKILL.md +7 -4
- package/skills/receiving-code-review/SKILL.md +17 -12
- package/skills/remove-ai-slops/SKILL.md +39 -38
- package/skills/requesting-code-review/SKILL.md +19 -17
- package/skills/requesting-code-review/code-reviewer.md +13 -1
- package/skills/subagent-driven-development/SKILL.md +29 -26
- package/skills/subagent-driven-development/implementer-prompt.md +29 -11
- package/skills/subagent-driven-development/spec-reviewer-prompt.md +6 -1
- package/skills/using-git-worktrees/SKILL.md +7 -4
- package/skills/writing-plans/SKILL.md +29 -24
- package/skills/writing-plans/plan-document-reviewer-prompt.md +10 -1
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { isAbsolute } from "node:path";
|
|
3
|
+
import { isDeepStrictEqual } from "node:util";
|
|
4
|
+
import { HarnessError, ToolCallId } from "@deepseek-ai/dsh-llm";
|
|
5
|
+
import { createScope } from "@deepseek-ai/dsh-scope";
|
|
6
|
+
import { assertLegacyReadBindings } from "./legacy-read-composition.js";
|
|
7
|
+
import { isLegacyReadCallLease, LegacyReadUnavailable } from "./legacy-read-contracts.js";
|
|
8
|
+
export function installLegacyReadProxy(composition, parent, child, evidence, nativeDefinition) {
|
|
9
|
+
if (["ready", "disposed"].includes(composition.view().state) || composition.view().activeCalls)
|
|
10
|
+
throw new LegacyReadUnavailable("composition-unavailable");
|
|
11
|
+
if (nativeDefinition.name !== "read" || parent.ctx.tools.get("read", parent) !== nativeDefinition)
|
|
12
|
+
throw new LegacyReadUnavailable("provenance-unavailable");
|
|
13
|
+
const standingScope = createScope(child.ctx, child);
|
|
14
|
+
const proxyScope = createScope(child.ctx, child);
|
|
15
|
+
const calls = new Map();
|
|
16
|
+
let removed = false;
|
|
17
|
+
const openTurnStart = (agent) => agent.ctx.get("sessionProjections")?.stateOf(agent.session, "turnBoundary")?.openTurnStartSeq;
|
|
18
|
+
const assertContext = (call) => {
|
|
19
|
+
const context = call.context;
|
|
20
|
+
if (context === undefined)
|
|
21
|
+
throw new LegacyReadUnavailable("audit-unavailable");
|
|
22
|
+
context.assertAvailable();
|
|
23
|
+
if (context.approval.kind !== call.lease.approval)
|
|
24
|
+
throw new LegacyReadUnavailable("approval-unavailable");
|
|
25
|
+
if (context.approval.kind === "coordinated-turn") {
|
|
26
|
+
const approval = context.approval;
|
|
27
|
+
if (approval.turn.parent !== parent || openTurnStart(parent) == null || approval.turn.openTurnStartSeq !== openTurnStart(parent)
|
|
28
|
+
|| approval.signal.aborted)
|
|
29
|
+
throw new LegacyReadUnavailable("approval-unavailable");
|
|
30
|
+
if (approval.childTurn !== undefined && (approval.childTurn.child !== child || openTurnStart(child) == null
|
|
31
|
+
|| approval.childTurn.openTurnStartSeq !== openTurnStart(child) || approval.childTurn.signal.aborted))
|
|
32
|
+
throw new LegacyReadUnavailable("approval-unavailable");
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const callSignal = (exec, call) => AbortSignal.any([exec.signal, call.lease.signal,
|
|
36
|
+
...(call.context === undefined ? [] : [call.context.signal]),
|
|
37
|
+
...(call.context?.approval.kind === "coordinated-turn" ? [call.context.approval.signal,
|
|
38
|
+
...(call.context.approval.childTurn === undefined ? [] : [call.context.approval.childTurn.signal])] : [])]);
|
|
39
|
+
const definition = {
|
|
40
|
+
name: "read", description: nativeDefinition.description, parameters: nativeDefinition.parameters,
|
|
41
|
+
output: { schema: nativeDefinition.output.schema, render: (args, value) => nativeDefinition.output.render(args, value) },
|
|
42
|
+
isConcurrencySafe: () => true,
|
|
43
|
+
async execute(args, exec) {
|
|
44
|
+
const call = calls.get(exec.token);
|
|
45
|
+
if (call === undefined || call.invoked || removed)
|
|
46
|
+
throw new LegacyReadUnavailable("lifetime-unavailable");
|
|
47
|
+
call.invoked = true;
|
|
48
|
+
const { lease } = call;
|
|
49
|
+
lease.assertActive();
|
|
50
|
+
assertContext(call);
|
|
51
|
+
const signal = callSignal(exec, call);
|
|
52
|
+
signal.throwIfAborted();
|
|
53
|
+
const binding = composition.owner.resolveReadBindings(parent, child, lease);
|
|
54
|
+
assertLegacyReadBindings(lease, binding);
|
|
55
|
+
if (args === null || typeof args !== "object" || Array.isArray(args))
|
|
56
|
+
throw new LegacyReadUnavailable("arguments-unavailable");
|
|
57
|
+
const row = args;
|
|
58
|
+
if (Reflect.ownKeys(row).some(key => !["file_path", "offset", "limit"].includes(String(key)))
|
|
59
|
+
|| typeof row.file_path !== "string" || !row.file_path.trim() || row.file_path.includes("\0")
|
|
60
|
+
|| [row.offset, row.limit].some(value => value !== undefined && (typeof value !== "number" || !Number.isSafeInteger(value) || value < 1))
|
|
61
|
+
|| (typeof row.limit === "number" && row.limit > binding.caps.limit))
|
|
62
|
+
throw new LegacyReadUnavailable("arguments-unavailable");
|
|
63
|
+
const target = await binding.childFs.resolve(row.file_path, { cwd: child.session.header.cwd, signal });
|
|
64
|
+
lease.assertActive();
|
|
65
|
+
signal.throwIfAborted();
|
|
66
|
+
const hostPath = binding.childFs.processPath(target);
|
|
67
|
+
const mapped = binding.parentFs.processPathFromHostPath(hostPath);
|
|
68
|
+
if (!isAbsolute(hostPath) || mapped === undefined || !isAbsolute(mapped))
|
|
69
|
+
throw new LegacyReadUnavailable("target-unavailable");
|
|
70
|
+
const parentTarget = await binding.parentFs.resolve(mapped, { cwd: parent.session.header.cwd, signal });
|
|
71
|
+
lease.assertActive();
|
|
72
|
+
signal.throwIfAborted();
|
|
73
|
+
if (target.targetKey === undefined || target.targetKey !== parentTarget.targetKey)
|
|
74
|
+
throw new LegacyReadUnavailable("target-unavailable");
|
|
75
|
+
assertLegacyReadBindings(lease, composition.owner.resolveReadBindings(parent, child, lease));
|
|
76
|
+
assertContext(call);
|
|
77
|
+
signal.throwIfAborted();
|
|
78
|
+
const callId = ToolCallId(`legacy-read:${randomUUID()}`);
|
|
79
|
+
call.parentExecution = { callId, rootCallId: exec.rootCallId, parent: exec.token };
|
|
80
|
+
const result = await parent.ctx.tools.execute({ agent: parent, name: "read", arguments: { ...row, file_path: mapped },
|
|
81
|
+
parent: exec.token, rootCallId: exec.rootCallId, callId, signal });
|
|
82
|
+
call.parentResult = result;
|
|
83
|
+
// Native execution has already settled. Never reclassify it using a newer epoch.
|
|
84
|
+
if (result.isError) {
|
|
85
|
+
const error = new HarnessError(result.error.message, result.error.info?.code ?? "LEGACY_READ_FAILED");
|
|
86
|
+
if (result.error.info !== undefined)
|
|
87
|
+
error.name = result.error.info.name;
|
|
88
|
+
call.transport = { isError: true, error: { message: error.message, info: { name: error.name, code: error.code } },
|
|
89
|
+
content: [{ type: "text", text: `Error: ${error.message}` }] };
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
if (result.concludesTurn)
|
|
93
|
+
exec.concludeTurn();
|
|
94
|
+
call.transport = { isError: false, value: result.value, content: definition.output.render(args, result.value),
|
|
95
|
+
...(result.concludesTurn ? { concludesTurn: true } : {}) };
|
|
96
|
+
return result.value;
|
|
97
|
+
},
|
|
98
|
+
projectContent(exec, result) {
|
|
99
|
+
const call = calls.get(exec.token);
|
|
100
|
+
// This runs BEFORE child post policy, and never replaces a later transformation.
|
|
101
|
+
return call?.projectionOutcome !== undefined && call.parentResult !== undefined && isDeepStrictEqual(result, call.projectionOutcome)
|
|
102
|
+
? call.parentResult.content : undefined;
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
const standingGuard = exec => exec.name !== "read" || exec.agent !== child ? undefined
|
|
106
|
+
: removed || !calls.has(exec.token) || child.ctx.tools.get("read", child) !== definition
|
|
107
|
+
|| calls.get(exec.token).lease.signal.aborted ? "Legacy read requires an active child-local operation lease" : undefined;
|
|
108
|
+
standingScope.ctx.tools.guard(standingGuard);
|
|
109
|
+
// The standing listener outlives the proxy so native completion always retires acquired leases.
|
|
110
|
+
const onResult = (exec, childResult) => {
|
|
111
|
+
const call = calls.get(exec.token);
|
|
112
|
+
if (call === undefined)
|
|
113
|
+
return;
|
|
114
|
+
calls.delete(exec.token);
|
|
115
|
+
const outcomes = { childExecution: exec, childResult,
|
|
116
|
+
...(call.parentExecution === undefined ? {} : { parentExecution: call.parentExecution }),
|
|
117
|
+
...(call.parentResult === undefined ? {} : { parentResult: call.parentResult }) };
|
|
118
|
+
const reportFault = (error) => {
|
|
119
|
+
void composition.closeForChange("audit-fault");
|
|
120
|
+
try {
|
|
121
|
+
composition.owner.reportAuditFault(error, outcomes);
|
|
122
|
+
}
|
|
123
|
+
catch (reportError) {
|
|
124
|
+
standingScope.ctx.logger.warn("Legacy read audit fault reporter failed", reportError);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
void (async () => {
|
|
128
|
+
try {
|
|
129
|
+
if (call.context !== undefined)
|
|
130
|
+
await call.context.finish(outcomes);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
reportFault(error);
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
try {
|
|
137
|
+
call.context?.release();
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
reportFault(error);
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
call.lease.release();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
})();
|
|
147
|
+
};
|
|
148
|
+
standingScope.ctx.on("tools/result", onResult);
|
|
149
|
+
const preExecute = async (exec, next) => {
|
|
150
|
+
if (exec.agent !== child || exec.name !== "read")
|
|
151
|
+
return next();
|
|
152
|
+
let signal = exec.signal;
|
|
153
|
+
const unavailable = (error) => signal.aborted ? { kind: "cancel" }
|
|
154
|
+
: { kind: "deny", reason: "Legacy read operation unavailable", info: { name: "LegacyReadUnavailable",
|
|
155
|
+
code: error instanceof LegacyReadUnavailable ? error.code : "lifetime-unavailable" } };
|
|
156
|
+
let call;
|
|
157
|
+
try {
|
|
158
|
+
const lease = composition.acquireLease(parent, child, evidence, exec.signal);
|
|
159
|
+
call = { lease, invoked: false };
|
|
160
|
+
calls.set(exec.token, call);
|
|
161
|
+
signal = callSignal(exec, call);
|
|
162
|
+
const context = await composition.owner.acquireCallContext(parent, child, exec, lease);
|
|
163
|
+
if (!isLegacyReadCallLease(context))
|
|
164
|
+
throw new LegacyReadUnavailable("audit-unavailable");
|
|
165
|
+
call.context = context;
|
|
166
|
+
signal = callSignal(exec, call);
|
|
167
|
+
lease.assertActive();
|
|
168
|
+
assertContext(call);
|
|
169
|
+
signal.throwIfAborted();
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
return unavailable(error);
|
|
173
|
+
}
|
|
174
|
+
// Downstream exceptions remain native final-errors, and terminal decisions remain authoritative.
|
|
175
|
+
const decision = await next();
|
|
176
|
+
if (decision.kind === "deny" || decision.kind === "cancel")
|
|
177
|
+
return decision;
|
|
178
|
+
try {
|
|
179
|
+
signal = callSignal(exec, call);
|
|
180
|
+
call.lease.assertActive();
|
|
181
|
+
assertContext(call);
|
|
182
|
+
signal.throwIfAborted();
|
|
183
|
+
// This pre-only adapter cannot prove the original child caller includes these lifetimes.
|
|
184
|
+
// Parent approval instead receives a merged public execute input from the proxy body.
|
|
185
|
+
if (decision.kind === "ask")
|
|
186
|
+
throw new LegacyReadUnavailable("approval-unavailable");
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
return unavailable(error);
|
|
190
|
+
}
|
|
191
|
+
return decision;
|
|
192
|
+
};
|
|
193
|
+
proxyScope.ctx.on("tools/pre-execute", preExecute, { prepend: true });
|
|
194
|
+
const complete = async (exec, next) => {
|
|
195
|
+
const call = calls.get(exec.token);
|
|
196
|
+
if (call === undefined)
|
|
197
|
+
return next();
|
|
198
|
+
const originalSignal = exec.signal;
|
|
199
|
+
exec.signal = callSignal(exec, call);
|
|
200
|
+
try {
|
|
201
|
+
const downstream = await next();
|
|
202
|
+
if (call.transport !== undefined && call.parentResult !== undefined && isDeepStrictEqual(downstream, call.transport)) {
|
|
203
|
+
call.projectionOutcome = call.parentResult.isError ? call.parentResult : { ...call.transport,
|
|
204
|
+
...(call.parentResult.additionalContexts === undefined ? {} : { additionalContexts: call.parentResult.additionalContexts }) };
|
|
205
|
+
return call.parentResult;
|
|
206
|
+
}
|
|
207
|
+
return downstream;
|
|
208
|
+
}
|
|
209
|
+
finally {
|
|
210
|
+
exec.signal = originalSignal;
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
proxyScope.ctx.on("tools/execute", complete, { prepend: true });
|
|
214
|
+
proxyScope.ctx.tools.register(definition);
|
|
215
|
+
return { parent, child, definition, nativeDefinition, proxyScope, standingScope,
|
|
216
|
+
contributions: Object.freeze([
|
|
217
|
+
{ stage: "pre", scope: proxyScope, reference: preExecute, order: 0 },
|
|
218
|
+
{ stage: "guard", scope: standingScope, reference: standingGuard, order: 0 },
|
|
219
|
+
{ stage: "around", scope: proxyScope, reference: complete, order: 0 },
|
|
220
|
+
{ stage: "project", scope: proxyScope, reference: definition.projectContent, order: 0 },
|
|
221
|
+
{ stage: "finalization", scope: standingScope, reference: onResult, order: 0 },
|
|
222
|
+
]),
|
|
223
|
+
async removeProxy() {
|
|
224
|
+
if (composition.view().state === "ready" || composition.view().activeCalls)
|
|
225
|
+
throw new LegacyReadUnavailable("composition-unavailable");
|
|
226
|
+
removed = true;
|
|
227
|
+
await proxyScope.dispose();
|
|
228
|
+
},
|
|
229
|
+
async releaseAfterChildDispose() {
|
|
230
|
+
if (child.ctx.get("agents")?.get(child.id) === child || composition.view().activeCalls)
|
|
231
|
+
throw new LegacyReadUnavailable("lifetime-unavailable");
|
|
232
|
+
removed = true;
|
|
233
|
+
await proxyScope.dispose();
|
|
234
|
+
await standingScope.dispose();
|
|
235
|
+
}, };
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=legacy-read-proxy.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { LlmAdapter, LlmRuntime } from "@deepseek-ai/dsh-llm";
|
|
3
|
+
import type { DsmmLlmGeneration, DsmmLlmCallConfig } from "./host-llm.js";
|
|
4
|
+
import type { DsmmLlmRouteResolver } from "./role-llm.js";
|
|
5
|
+
type RegistrationHandle = ReturnType<LlmRuntime["registerAdapter"]>;
|
|
6
|
+
/** Captures public registering-fiber provenance; the native runtime remains the sole registry. */
|
|
7
|
+
export declare class LivePiAiOwner implements DsmmLlmRouteResolver {
|
|
8
|
+
private readonly ctx;
|
|
9
|
+
private readonly native;
|
|
10
|
+
private readonly registrations;
|
|
11
|
+
constructor(ctx: Context, native: LlmRuntime);
|
|
12
|
+
requiresRaw(config: DsmmLlmCallConfig): boolean;
|
|
13
|
+
register(scope: Context, providers: readonly string[], adapter: LlmAdapter, handle: RegistrationHandle): RegistrationHandle;
|
|
14
|
+
generation(provider: string): DsmmLlmGeneration;
|
|
15
|
+
resolveRoute(input: Parameters<DsmmLlmRouteResolver["resolveRoute"]>[0], signal?: AbortSignal): Promise<import("./route-json.js").ModelRouteJson>;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=live-pi-ai-owner.d.ts.map
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { symbols } from "@deepseek-ai/cordis";
|
|
2
|
+
import { LlmError } from "@deepseek-ai/dsh-llm";
|
|
3
|
+
import { Config } from "@deepseek-ai/dsh-llm-pi-ai";
|
|
4
|
+
import { InMemoryCredentialStore } from "@earendil-works/pi-ai";
|
|
5
|
+
import { brandString } from "@deepseek-ai/dsh-brand";
|
|
6
|
+
import { isDeepStrictEqual } from "node:util";
|
|
7
|
+
import { createDsmmPiAiProviderOwner } from "./native-pi-ai-wire.js";
|
|
8
|
+
import { snapshotDsmmCall } from "./host-llm.js";
|
|
9
|
+
import { DsmmMissingProviderError, modelRouteToCall } from "./role-llm.js";
|
|
10
|
+
import { normalizeModelRouteJson } from "./route-json.js";
|
|
11
|
+
const original = (value) => Reflect.get(value, symbols.original) ?? value;
|
|
12
|
+
/** Captures public registering-fiber provenance; the native runtime remains the sole registry. */
|
|
13
|
+
export class LivePiAiOwner {
|
|
14
|
+
ctx;
|
|
15
|
+
native;
|
|
16
|
+
registrations = new Map();
|
|
17
|
+
constructor(ctx, native) {
|
|
18
|
+
this.ctx = ctx;
|
|
19
|
+
this.native = native;
|
|
20
|
+
}
|
|
21
|
+
requiresRaw(config) {
|
|
22
|
+
return config.customParameters !== undefined || config.stop !== undefined
|
|
23
|
+
&& this.registrations.get(config.provider)?.scope.fiber.entry?.options.name === "@deepseek-ai/dsh-llm-pi-ai";
|
|
24
|
+
}
|
|
25
|
+
register(scope, providers, adapter, handle) {
|
|
26
|
+
const record = { scope, adapter, life: new AbortController(), generations: new Map(), providers: [...providers] };
|
|
27
|
+
const retire = () => {
|
|
28
|
+
for (const generation of record.generations.values())
|
|
29
|
+
generation.retire.abort(new LlmError("Provider generation retired", "INVALID_PREPARED_CALL"));
|
|
30
|
+
record.generations.clear();
|
|
31
|
+
};
|
|
32
|
+
const remove = () => {
|
|
33
|
+
retire();
|
|
34
|
+
record.life.abort();
|
|
35
|
+
for (const provider of record.providers)
|
|
36
|
+
if (this.registrations.get(provider) === record)
|
|
37
|
+
this.registrations.delete(provider);
|
|
38
|
+
};
|
|
39
|
+
for (const provider of providers)
|
|
40
|
+
this.registrations.set(provider, record);
|
|
41
|
+
scope.effect(() => remove);
|
|
42
|
+
scope.on("loader/volatile-update", retire, { prepend: true });
|
|
43
|
+
scope.on("loader/partial-dispose", entry => { if (entry === scope.fiber.entry)
|
|
44
|
+
retire(); }, { prepend: true, global: true });
|
|
45
|
+
scope.on("credentials/reference-updated", retire, { prepend: true, global: true });
|
|
46
|
+
const wrapped = Object.assign(() => { remove(); handle(); }, {
|
|
47
|
+
replace: (next) => {
|
|
48
|
+
// Native validation is atomic: a rejected replacement leaves the old routes registered.
|
|
49
|
+
retire();
|
|
50
|
+
handle.replace(next);
|
|
51
|
+
for (const provider of record.providers)
|
|
52
|
+
if (this.registrations.get(provider) === record)
|
|
53
|
+
this.registrations.delete(provider);
|
|
54
|
+
record.providers = [...next];
|
|
55
|
+
for (const provider of next)
|
|
56
|
+
this.registrations.set(provider, record);
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
return wrapped;
|
|
60
|
+
}
|
|
61
|
+
generation(provider) {
|
|
62
|
+
const record = this.registrations.get(provider);
|
|
63
|
+
if (record === undefined)
|
|
64
|
+
throw new LlmError("Provider registration is not ready", "DSMM_PROVIDER_NOT_READY");
|
|
65
|
+
const { scope, adapter } = record;
|
|
66
|
+
if (scope.fiber.entry?.options.name !== "@deepseek-ai/dsh-llm-pi-ai")
|
|
67
|
+
throw new LlmError("This provider has no raw executor", "UNSUPPORTED_ROUTE_PARAMETERS");
|
|
68
|
+
const config = scope.fiber.config;
|
|
69
|
+
if (config === null || typeof config !== "object" || !("providers" in config) || config.providers === null || typeof config.providers !== "object"
|
|
70
|
+
|| !("get" in config.providers) || typeof config.providers.get !== "function")
|
|
71
|
+
throw new LlmError("Pi-AI live configuration is unavailable", "DSMM_PROVIDER_NOT_READY");
|
|
72
|
+
const ref = config.providers;
|
|
73
|
+
const current = ref.get()[provider];
|
|
74
|
+
if (current === undefined)
|
|
75
|
+
throw new LlmError("Pi-AI no longer declares this route", "DSMM_PROVIDER_NOT_READY");
|
|
76
|
+
const profile = structuredClone(current);
|
|
77
|
+
const cached = record.generations.get(provider);
|
|
78
|
+
if (cached !== undefined) {
|
|
79
|
+
try {
|
|
80
|
+
cached.value.assertCurrent();
|
|
81
|
+
return cached.value;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
cached.retire.abort();
|
|
85
|
+
record.generations.delete(provider);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const retire = new AbortController();
|
|
89
|
+
const credentials = scope.get("credentials");
|
|
90
|
+
const signal = AbortSignal.any([record.life.signal, retire.signal]);
|
|
91
|
+
const assertCurrent = () => {
|
|
92
|
+
signal.throwIfAborted();
|
|
93
|
+
if (this.registrations.get(provider) !== record || scope.fiber.state !== 2 || scope.fiber.entry?.fiber !== scope.fiber
|
|
94
|
+
|| scope.fiber.config !== config || !isDeepStrictEqual(ref.get()[provider], profile)
|
|
95
|
+
|| (credentials === undefined ? scope.get("credentials") !== undefined : scope.get("credentials") === undefined || original(scope.get("credentials")) !== original(credentials))) {
|
|
96
|
+
retire.abort(new LlmError("Provider configuration or owner changed", "INVALID_PREPARED_CALL"));
|
|
97
|
+
signal.throwIfAborted();
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
assertCurrent();
|
|
101
|
+
const owner = createDsmmPiAiProviderOwner(this.ctx, {
|
|
102
|
+
config: { providers: { [provider]: structuredClone(profile) } },
|
|
103
|
+
settingsNamespace: scope.fiber.entry.options.id,
|
|
104
|
+
auth: { credentials: new InMemoryCredentialStore(), authContext: {
|
|
105
|
+
env: async () => { throw new LlmError("Raw requests require named credentials", "MISSING_CREDENTIAL"); }, fileExists: async () => false,
|
|
106
|
+
} },
|
|
107
|
+
async resolveApiKey(_provider, reference, requestSignal) {
|
|
108
|
+
assertCurrent();
|
|
109
|
+
requestSignal?.throwIfAborted();
|
|
110
|
+
if (credentials === undefined)
|
|
111
|
+
throw new LlmError("The credential service is unavailable", "MISSING_CREDENTIAL");
|
|
112
|
+
const key = await credentials.resolve(brandString(reference));
|
|
113
|
+
assertCurrent();
|
|
114
|
+
requestSignal?.throwIfAborted();
|
|
115
|
+
return key?.value;
|
|
116
|
+
},
|
|
117
|
+
}, { signal, adapter, assertCurrent });
|
|
118
|
+
const value = owner.generation(provider);
|
|
119
|
+
record.generations.set(provider, { value, retire });
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
async resolveRoute(input, signal) {
|
|
123
|
+
const route = normalizeModelRouteJson(input), call = snapshotDsmmCall(modelRouteToCall(route));
|
|
124
|
+
signal?.throwIfAborted();
|
|
125
|
+
if (!this.native.listProviders().some(row => row.id === route.provider))
|
|
126
|
+
throw new DsmmMissingProviderError();
|
|
127
|
+
if (!this.requiresRaw(call)) {
|
|
128
|
+
try {
|
|
129
|
+
await this.native.resolveCallConfig(call, signal);
|
|
130
|
+
return route;
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
if (!(error instanceof LlmError) || !["UNSUPPORTED_REASONING_EFFORT", "UNSUPPORTED_OPTION"].includes(error.code))
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const generation = this.generation(route.provider);
|
|
138
|
+
await generation.prepareCall(route.provider, route.model, signal ?? generation.signal);
|
|
139
|
+
generation.assertCurrent();
|
|
140
|
+
signal?.throwIfAborted();
|
|
141
|
+
return route;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=live-pi-ai-owner.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { LlmRuntime } from "@deepseek-ai/dsh-llm";
|
|
3
|
+
import { DsmmAwareLlmRuntime } from "./host-llm.js";
|
|
4
|
+
/** The selected profile's sole native LLM registry, installed by cold source migration. */
|
|
5
|
+
export declare class DsmmNativeLlmRuntime extends DsmmAwareLlmRuntime {
|
|
6
|
+
private readonly providerOwner;
|
|
7
|
+
constructor(ctx: Context);
|
|
8
|
+
registerAdapter(...args: Parameters<LlmRuntime["registerAdapter"]>): import("@deepseek-ai/dsh-llm").AdapterRegistrationHandle;
|
|
9
|
+
}
|
|
10
|
+
export default DsmmNativeLlmRuntime;
|
|
11
|
+
//# sourceMappingURL=llm-runtime.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DsmmAwareLlmRuntime } from "./host-llm.js";
|
|
2
|
+
import { LivePiAiOwner } from "./live-pi-ai-owner.js";
|
|
3
|
+
import { createDsmmRoleLlmOwner } from "./role-llm-runtime.js";
|
|
4
|
+
/** The selected profile's sole native LLM registry, installed by cold source migration. */
|
|
5
|
+
export class DsmmNativeLlmRuntime extends DsmmAwareLlmRuntime {
|
|
6
|
+
providerOwner;
|
|
7
|
+
constructor(ctx) {
|
|
8
|
+
let owner;
|
|
9
|
+
super(ctx, undefined, { preflight: (frame, proposal) => owner.preflight(frame, proposal) });
|
|
10
|
+
this.providerOwner = new LivePiAiOwner(ctx, this);
|
|
11
|
+
owner = createDsmmRoleLlmOwner(ctx, this.providerOwner);
|
|
12
|
+
ctx.provide("dsmmLlmRoutes", this.providerOwner);
|
|
13
|
+
ctx.inject(["dsmmCoreLlmOwner"], scope => this.bindRequestOwner(scope));
|
|
14
|
+
}
|
|
15
|
+
registerAdapter(...args) {
|
|
16
|
+
const handle = super.registerAdapter(...args);
|
|
17
|
+
return this.providerOwner.register(this.ctx, args[0], args[1], handle);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export default DsmmNativeLlmRuntime;
|
|
21
|
+
//# sourceMappingURL=llm-runtime.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
export declare const inject: string[];
|
|
3
|
+
/** Ordinary native settings service, with the caller-scoped editor transaction boundary. */
|
|
4
|
+
export declare function apply(ctx: Context): void;
|
|
5
|
+
//# sourceMappingURL=managed-settings.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SettingsForms } from "@deepseek-ai/dsh-settings";
|
|
2
|
+
import { permissionConfigEditorFacade } from "./deployment-permission-rules.js";
|
|
3
|
+
export const inject = SettingsForms.inject;
|
|
4
|
+
function isEditor(value) {
|
|
5
|
+
return value !== null && typeof value === "object" && "edit" in value && typeof value.edit === "function";
|
|
6
|
+
}
|
|
7
|
+
/** Ordinary native settings service, with the caller-scoped editor transaction boundary. */
|
|
8
|
+
export function apply(ctx) {
|
|
9
|
+
const editor = Reflect.get(ctx, "configEditor");
|
|
10
|
+
if (!isEditor(editor))
|
|
11
|
+
throw new Error("The native configuration editor is unavailable.");
|
|
12
|
+
new SettingsForms(ctx.extend({ configEditor: permissionConfigEditorFacade(editor) }));
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=managed-settings.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DsmmProfileAdmission, DsmmSettings } from "./settings.js";
|
|
2
|
+
/** Execution semantics, not an admission or executor capability. */
|
|
3
|
+
export type ResolvedModelParameterPolicy = Readonly<{
|
|
4
|
+
mode: "passthrough" | "native-defaults" | "legacy-native-v1";
|
|
5
|
+
}>;
|
|
6
|
+
/** Call with the exact immutable Agent admission; never substitute current parent settings. */
|
|
7
|
+
export declare function resolvedModelParameterPolicy(admission: DsmmProfileAdmission): ResolvedModelParameterPolicy;
|
|
8
|
+
/** Cold Core composition may resolve its startup snapshot without waiting for DW. */
|
|
9
|
+
export declare function configuredModelParameterPolicy(settings: DsmmSettings): ResolvedModelParameterPolicy;
|
|
10
|
+
export declare function parseModelParameterPolicy(value: unknown): ResolvedModelParameterPolicy;
|
|
11
|
+
//# sourceMappingURL=model-parameter-policy.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const passthrough = Object.freeze({ mode: "passthrough" });
|
|
2
|
+
const nativeDefaults = Object.freeze({ mode: "native-defaults" });
|
|
3
|
+
const legacy = Object.freeze({ mode: "legacy-native-v1" });
|
|
4
|
+
/** Call with the exact immutable Agent admission; never substitute current parent settings. */
|
|
5
|
+
export function resolvedModelParameterPolicy(admission) {
|
|
6
|
+
const capture = admission.childCapture;
|
|
7
|
+
if (capture !== undefined)
|
|
8
|
+
return capture.version === 1 ? legacy : capture.modelParameterPolicy;
|
|
9
|
+
if (admission.childEvidence?.mode === "legacy-conservative")
|
|
10
|
+
return legacy;
|
|
11
|
+
return configuredModelParameterPolicy(admission.settings);
|
|
12
|
+
}
|
|
13
|
+
/** Cold Core composition may resolve its startup snapshot without waiting for DW. */
|
|
14
|
+
export function configuredModelParameterPolicy(settings) {
|
|
15
|
+
return settings.modelParameters.passthrough ? passthrough : nativeDefaults;
|
|
16
|
+
}
|
|
17
|
+
export function parseModelParameterPolicy(value) {
|
|
18
|
+
if (value === null || typeof value !== "object" || Array.isArray(value) || Object.keys(value).length !== 1 || !("mode" in value))
|
|
19
|
+
throw new TypeError("Invalid model parameter policy");
|
|
20
|
+
switch (value.mode) {
|
|
21
|
+
case "passthrough": return passthrough;
|
|
22
|
+
case "native-defaults": return nativeDefaults;
|
|
23
|
+
case "legacy-native-v1": return legacy;
|
|
24
|
+
default: throw new TypeError("Invalid model parameter policy");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=model-parameter-policy.js.map
|
package/lib/model-routing.js
CHANGED
|
@@ -4,6 +4,9 @@ import { resolveSelectedAgentPreset } from "./session-scope.js";
|
|
|
4
4
|
import { resolveAdmittedDsmmRole as resolveEffectiveDsmmRole } from "./role-policy.js";
|
|
5
5
|
import { childOwnedSessionEvents, sessionEvents } from "./session-scope.js";
|
|
6
6
|
import { isCurrentRecoveryStep } from "./recovery-policy.js";
|
|
7
|
+
import { capturedRoleInvocation } from "./role-invocation.js";
|
|
8
|
+
import { modelRouteFromCall } from "./role-llm.js";
|
|
9
|
+
import { configuredModelParameterPolicy, resolvedModelParameterPolicy } from "./model-parameter-policy.js";
|
|
7
10
|
export function isDeepseekV4ProRoute(config) {
|
|
8
11
|
return config.provider.toLowerCase() === "deepseek-official" && config.model.toLowerCase() === "deepseek-v4-pro";
|
|
9
12
|
}
|
|
@@ -12,10 +15,7 @@ export function isDeepseekFlashRoute(config) {
|
|
|
12
15
|
&& config.model.toLowerCase() === "deepseek-flash";
|
|
13
16
|
}
|
|
14
17
|
export function desiredDeepseekEffort(settings, preset, route = "v4-pro") {
|
|
15
|
-
|
|
16
|
-
return preset !== undefined && maxPresets.some((configuredPreset) => configuredPreset === preset)
|
|
17
|
-
? "max"
|
|
18
|
-
: route === "flash" ? settings.deepseekFlashDefaultReasoningEffort : settings.deepseekV4ProDefaultReasoningEffort;
|
|
18
|
+
return route === "flash" ? settings.deepseekFlashDefaultReasoningEffort : settings.deepseekV4ProDefaultReasoningEffort;
|
|
19
19
|
}
|
|
20
20
|
export function selectAdvertisedEffort(desired, reasoning) {
|
|
21
21
|
if (!reasoning)
|
|
@@ -59,6 +59,8 @@ export function registerModelRouting(ctx, controller, getSettings) {
|
|
|
59
59
|
if (frame.signal.aborted)
|
|
60
60
|
return downstream;
|
|
61
61
|
const settings = getSettings(frame.agent);
|
|
62
|
+
const admission = getSettings.admission?.(frame.agent);
|
|
63
|
+
const parameterPolicy = admission === undefined ? configuredModelParameterPolicy(settings) : resolvedModelParameterPolicy(admission);
|
|
62
64
|
if (!settings.modules.deepwork.enabled)
|
|
63
65
|
return downstream;
|
|
64
66
|
const ordinaryRoot = frame.agent.session.header?.origin !== "subagent";
|
|
@@ -66,7 +68,8 @@ export function registerModelRouting(ctx, controller, getSettings) {
|
|
|
66
68
|
const active = controller.active(frame.agent, settings.defaultActive);
|
|
67
69
|
const role = resolveEffectiveDsmmRole(frame.agent, settings, active);
|
|
68
70
|
const policy = role === undefined ? undefined : settings.roleRouting[role];
|
|
69
|
-
const
|
|
71
|
+
const invocation = capturedRoleInvocation(frame.agent);
|
|
72
|
+
const primary = invocation?.initialRoute ?? policy?.primary;
|
|
70
73
|
const epoch = getSettings.admission?.(frame.agent).epoch;
|
|
71
74
|
const identity = await establishRolePolicy(frame, settings, role, readyCtx, epoch);
|
|
72
75
|
const fallbacks = effectiveRoleFallbackRoutes(settings, role);
|
|
@@ -76,12 +79,15 @@ export function registerModelRouting(ctx, controller, getSettings) {
|
|
|
76
79
|
const currentStep = isCurrentRecoveryStep(frame.agent.session.header?.origin === "subagent" ? childOwnedSessionEvents(frame.agent.session) : sessionEvents(frame.agent.session), frame.turn, frame.step);
|
|
77
80
|
if (role !== undefined && identity !== undefined && currentStep) {
|
|
78
81
|
let lock = roleRouteLock(frame.agent, identity);
|
|
79
|
-
const exactPolicy = primary !== undefined || policy?.fallbackRoutes !== undefined || fallbacks.length > 0
|
|
82
|
+
const exactPolicy = invocation === undefined ? primary !== undefined || policy?.fallbackRoutes !== undefined || fallbacks.length > 0
|
|
83
|
+
: invocation.routeSource !== "inherited" || invocation.exactEffort || fallbacks.length > 0;
|
|
80
84
|
const captured = assembledSelections.get(frame.agent);
|
|
81
85
|
const manual = captured?.signal === frame.signal ? captured.intent : undefined;
|
|
82
86
|
if (ordinaryRoot) {
|
|
83
|
-
|
|
84
|
-
|
|
87
|
+
if (manual !== undefined && lock?.manualSelectionSeq !== manual.seq
|
|
88
|
+
&& !nativeModelSelectionWasAccepted(frame.agent, manual))
|
|
89
|
+
downstream = applyModelRoute(downstream, manual.route);
|
|
90
|
+
const selected = modelRouteFromCall(downstream);
|
|
85
91
|
if (lock === undefined || !sameExactModelRoute(lock.route, selected) || lock.manualSelectionSeq !== manual?.seq) {
|
|
86
92
|
const generation = (lock?.generation ?? -1) + 1;
|
|
87
93
|
lock = pinRoleRoute(frame.agent, identity, selected, [selected]);
|
|
@@ -92,7 +98,7 @@ export function registerModelRouting(ctx, controller, getSettings) {
|
|
|
92
98
|
return downstream;
|
|
93
99
|
}
|
|
94
100
|
if (manual !== undefined && lock?.manualSelectionSeq !== manual.seq
|
|
95
|
-
&& (
|
|
101
|
+
&& (sameModelRoute(downstream, manual.route) && downstream.reasoningEffort === manual.route.reasoningEffort || nativeModelSelectionWasAccepted(frame.agent, manual))) {
|
|
96
102
|
const llm = frame.agent.ctx?.get?.("llm")
|
|
97
103
|
?? (readyCtx.get !== undefined ? readyCtx.get("llm") : readyCtx.llm);
|
|
98
104
|
if (llm?.resolveCallConfig === undefined)
|
|
@@ -100,7 +106,7 @@ export function registerModelRouting(ctx, controller, getSettings) {
|
|
|
100
106
|
await llm.resolveCallConfig(applyModelRoute(downstream, manual.route), frame.signal);
|
|
101
107
|
frame.signal.throwIfAborted();
|
|
102
108
|
const generation = (lock?.generation ?? -1) + 1;
|
|
103
|
-
lock = pinRoleRoute(frame.agent, identity, manual.route, [manual.route, ...fallbacks]);
|
|
109
|
+
lock = pinRoleRoute(frame.agent, identity, manual.route, [manual.route, ...fallbacks], { preserveCandidates: parameterPolicy.mode === "native-defaults" });
|
|
104
110
|
lock.manualSelectionSeq = manual.seq;
|
|
105
111
|
lock.generation = generation;
|
|
106
112
|
lockedAgents.add(frame.agent);
|
|
@@ -113,36 +119,41 @@ export function registerModelRouting(ctx, controller, getSettings) {
|
|
|
113
119
|
if (admitted !== undefined)
|
|
114
120
|
return applyModelRoute(downstream, admitted);
|
|
115
121
|
const accepted = persistedRoleRoute(frame, liveAlias ? undefined : primary, fallbacks, identity);
|
|
116
|
-
if (lock !== undefined && accepted !== undefined && !
|
|
122
|
+
if (lock !== undefined && accepted !== undefined && !sameExactModelRoute(accepted, lock.route)) {
|
|
117
123
|
// An explicit already-committed native route change remains host-owned;
|
|
118
124
|
// DSMM's pending current-frame route still has precedence above.
|
|
119
125
|
lock.route = { ...accepted };
|
|
126
|
+
lock.candidateIndex = lock.candidates.findIndex(candidate => sameExactModelRoute(candidate, accepted));
|
|
120
127
|
lock.generation += 1;
|
|
121
128
|
lock.startupSettled = true;
|
|
122
129
|
lock.retries = 0;
|
|
123
130
|
lock.rateLimits = 0;
|
|
124
131
|
}
|
|
125
132
|
if (lock === undefined) {
|
|
126
|
-
const inherited =
|
|
127
|
-
|
|
128
|
-
const candidates = orderedModelRoutes([liveAlias ? inherited : primary ?? inherited, ...fallbacks]);
|
|
133
|
+
const inherited = modelRouteFromCall(downstream);
|
|
134
|
+
const candidates = invocation?.candidates ?? orderedModelRoutes([liveAlias ? inherited : primary ?? inherited, ...fallbacks]);
|
|
129
135
|
const persisted = accepted;
|
|
130
136
|
const llm = frame.agent.ctx?.get?.("llm")
|
|
131
137
|
?? (readyCtx.get !== undefined ? readyCtx.get("llm") : readyCtx.llm);
|
|
132
|
-
const selected = persisted ?? (exactPolicy ? await selectInitialModelRoute(llm ?? {}, candidates, frame.signal) : inherited);
|
|
138
|
+
const selected = persisted ?? invocation?.initialRoute ?? (exactPolicy ? await selectInitialModelRoute(llm ?? {}, candidates, frame.signal, parameterPolicy.mode === "passthrough" ? readyCtx.get?.("dsmmLlmRoutes") : undefined) : inherited);
|
|
133
139
|
frame.signal.throwIfAborted();
|
|
134
|
-
lock = pinRoleRoute(frame.agent, identity, selected, candidates
|
|
140
|
+
lock = pinRoleRoute(frame.agent, identity, selected, candidates, { preserveCandidates: parameterPolicy.mode === "native-defaults",
|
|
141
|
+
initialCandidate: persisted ?? invocation?.selectedCandidate });
|
|
135
142
|
if (persisted !== undefined)
|
|
136
143
|
lock.startupSettled = true;
|
|
137
144
|
lockedAgents.add(frame.agent);
|
|
138
145
|
}
|
|
139
146
|
downstream = applyModelRoute(downstream, lock.route);
|
|
140
|
-
|
|
147
|
+
const newRouteWithoutEffort = invocation !== undefined && !invocation.exactEffort
|
|
148
|
+
&& (invocation.routeSource === "level" || invocation.routeSource === "invocation-route");
|
|
149
|
+
if ((exactPolicy || lock.attempts > 0) && !newRouteWithoutEffort)
|
|
141
150
|
return downstream;
|
|
142
151
|
}
|
|
143
152
|
// Ordinary roots belong to the native model tab, including its exact effort.
|
|
144
153
|
if (ordinaryRoot)
|
|
145
154
|
return downstream;
|
|
155
|
+
if (parameterPolicy.mode === "native-defaults")
|
|
156
|
+
return downstream;
|
|
146
157
|
// Named fallback efforts are native policy IDs, never legacy calibration inputs.
|
|
147
158
|
if (fallbacks.some((fallback) => fallback.reasoningEffort !== undefined
|
|
148
159
|
&& sameModelRoute(fallback, downstream) && fallback.reasoningEffort === downstream.reasoningEffort))
|