@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
package/lib/guards.js
CHANGED
|
@@ -3,6 +3,9 @@ import { resolveSelectedAgentPreset } from "./session-scope.js";
|
|
|
3
3
|
import { validatePlanMutation } from "./plan-validation.js";
|
|
4
4
|
import { classifyKnownGitWrite, classifyShellDialectViolation } from "./shell-command.js";
|
|
5
5
|
import { resolveAdmittedDsmmRole } from "./role-policy.js";
|
|
6
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
7
|
+
import { nativeStandingFullAccess } from "./permission-native-access.js";
|
|
8
|
+
import { DsmmProfileError } from "./profiles.js";
|
|
6
9
|
export const DSMM_GUARD_PREFIX = "[dsmm safety]";
|
|
7
10
|
const STRUCTURED_TODO_PATTERN = /^\[[^\]]+\]\s+\[[^\]]+\]\s+to\s+.+\s+-\s+expect\s+.+/u;
|
|
8
11
|
function asRecord(value) {
|
|
@@ -198,9 +201,11 @@ function todoDisciplineDecision(exec, settings) {
|
|
|
198
201
|
reason: `${DSMM_GUARD_PREFIX} todo content must use "[WHERE] [HOW] to [WHY] - expect [RESULT]": ${malformed.content}`
|
|
199
202
|
};
|
|
200
203
|
}
|
|
201
|
-
export function decidePreToolExecution(exec, settings, controller) {
|
|
204
|
+
export function decidePreToolExecution(exec, settings, controller, nativeFullAccess = false) {
|
|
202
205
|
if (!isSafetyScopeActive(exec, settings, controller))
|
|
203
206
|
return undefined;
|
|
207
|
+
if (nativeFullAccess)
|
|
208
|
+
return settings.guards.gitWriteGuard === "deny" ? gitWriteDecision(exec, settings) : undefined;
|
|
204
209
|
if (settings.guards.shellCommandSafety) {
|
|
205
210
|
const shell = shellSafetyDecision(exec);
|
|
206
211
|
if (shell !== undefined)
|
|
@@ -242,18 +247,31 @@ export function decidePostToolExecution(exec, result, decision, settings, contro
|
|
|
242
247
|
};
|
|
243
248
|
}
|
|
244
249
|
export function registerSafetyGuards(ctx, controller, getSettings, rolePolicy) {
|
|
250
|
+
const truncationLimits = new WeakMap();
|
|
245
251
|
const tools = ctx.get?.("tools");
|
|
246
252
|
if (rolePolicy !== undefined && tools !== undefined) {
|
|
247
|
-
const guard = tools.guard((execution) => execution.agent === undefined ? undefined : rolePolicy.toolDenial(execution.agent, execution.name, tools));
|
|
253
|
+
const guard = tools.guard((execution) => execution.agent === undefined ? undefined : rolePolicy.toolDenial(execution.agent, execution.name, tools, execution));
|
|
248
254
|
ctx.effect?.(() => guard);
|
|
249
255
|
}
|
|
250
256
|
ctx.on?.("tools/pre-execute", async (exec, next) => {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
257
|
+
const execution = exec;
|
|
258
|
+
const full = Context.is(ctx) && nativeStandingFullAccess(ctx, exec.agent);
|
|
259
|
+
rolePolicy?.captureToolExecution(execution, full);
|
|
260
|
+
const denied = exec.agent === undefined ? undefined : full ? rolePolicy?.toolBlacklistDenial(exec.agent, exec.name, execution) : rolePolicy?.preToolDenial(exec.agent, exec.name, undefined, execution);
|
|
254
261
|
if (denied !== undefined)
|
|
255
262
|
return { kind: "deny", reason: denied };
|
|
256
|
-
|
|
263
|
+
let settings;
|
|
264
|
+
try {
|
|
265
|
+
settings = getSettings(exec.agent);
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
if (full && error instanceof DsmmProfileError && !["disposed", "not-owned", "cancelled"].includes(error.code))
|
|
269
|
+
return next();
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
const decision = decidePreToolExecution(exec, settings, controller, full);
|
|
273
|
+
if (!full && settings.modules.deepwork.enabled && settings.guards.toolOutputTruncation.enabled && isSafetyScopeActive(exec, settings, controller))
|
|
274
|
+
truncationLimits.set(exec, settings.guards.toolOutputTruncation.maxInlineBytes);
|
|
257
275
|
if (decision === undefined)
|
|
258
276
|
return next();
|
|
259
277
|
if (decision.kind === "deny")
|
|
@@ -262,9 +280,12 @@ export function registerSafetyGuards(ctx, controller, getSettings, rolePolicy) {
|
|
|
262
280
|
return downstream.kind === "allow" ? decision : downstream;
|
|
263
281
|
}, { prepend: true });
|
|
264
282
|
ctx.on?.("tools/post-execute", async (exec, result, next) => {
|
|
265
|
-
const settings = getSettings(exec.agent);
|
|
266
283
|
const decision = await next();
|
|
267
|
-
|
|
284
|
+
const limit = truncationLimits.get(exec);
|
|
285
|
+
if (limit === undefined || result.isError || decision.kind !== "accept" || "value" in decision)
|
|
286
|
+
return decision;
|
|
287
|
+
const text = allText(decision.content ?? result.content);
|
|
288
|
+
return text === undefined || utf8Bytes(text) <= limit ? decision : { ...decision, content: [{ type: "text", text: truncateTextMiddle(text, limit, exec.name) }] };
|
|
268
289
|
}, { prepend: true });
|
|
269
290
|
}
|
|
270
291
|
//# sourceMappingURL=guards.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import { AgentLoop } from "@deepseek-ai/dsh-agent-loop";
|
|
3
|
+
import type { Config as AgentLoopConfig } from "@deepseek-ai/dsh-agent-loop";
|
|
4
|
+
import { DsmmAwareLlmRuntime } from "./host-llm.js";
|
|
5
|
+
import type { DsmmLlmHostOwner } from "./host-llm.js";
|
|
6
|
+
import type { DsmmPiAiOwnerOptions, DsmmPiAiProviderOwner } from "./native-pi-ai-wire.js";
|
|
7
|
+
export interface DsmmLlmColdStartupOptions {
|
|
8
|
+
/** Original validated declarative AgentLoop config, including all configured Agents. */
|
|
9
|
+
readonly agentLoop: AgentLoopConfig;
|
|
10
|
+
readonly provider: DsmmPiAiOwnerOptions;
|
|
11
|
+
/** Install routing/admission guards and return their exact live request owner before constructing the loop. */
|
|
12
|
+
readonly establish?: (ctx: Context, providers: DsmmPiAiProviderOwner) => Promise<DsmmLlmHostOwner>;
|
|
13
|
+
}
|
|
14
|
+
export interface DsmmLlmColdStartup {
|
|
15
|
+
/** Append to profileContext.overlays before readProfilePatches; Settings recomposition must see this same layer. Provider handoff remains explicit in the stock provider row. */
|
|
16
|
+
readonly patches: readonly [{
|
|
17
|
+
readonly id: "agent-loop";
|
|
18
|
+
readonly disabled: true;
|
|
19
|
+
}, {
|
|
20
|
+
readonly insert: readonly [{
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly config: DsmmPiAiOwnerOptions["config"];
|
|
24
|
+
}];
|
|
25
|
+
}];
|
|
26
|
+
/** Pass to the public dsh-app-boot prepare callback, before the standard profile entries mount. */
|
|
27
|
+
prepare(ctx: Context): Promise<void>;
|
|
28
|
+
/** Call after boot settlement. Missing dependencies are a startup refusal, never an implicit stock fallback. */
|
|
29
|
+
assertReady(): {
|
|
30
|
+
readonly loop: AgentLoop;
|
|
31
|
+
readonly llm: DsmmAwareLlmRuntime;
|
|
32
|
+
readonly provider: DsmmPiAiProviderOwner;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Host-only cold composition. The profile must disable its original agent-loop
|
|
37
|
+
* row and remove only this owner's routes from llm-pi-ai before mounting entries.
|
|
38
|
+
* The standard MAIN, registries, persistence and other provider owners remain mounted.
|
|
39
|
+
*/
|
|
40
|
+
export declare function createDsmmLlmColdStartup(options: DsmmLlmColdStartupOptions): DsmmLlmColdStartup;
|
|
41
|
+
//# sourceMappingURL=host-llm-startup.d.ts.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Context, symbols } from "@deepseek-ai/cordis";
|
|
2
|
+
import { AgentLoop } from "@deepseek-ai/dsh-agent-loop";
|
|
3
|
+
import { DsmmAwareLlmRuntime } from "./host-llm.js";
|
|
4
|
+
import { createDsmmRoleLlmOwner } from "./role-llm-runtime.js";
|
|
5
|
+
/**
|
|
6
|
+
* Host-only cold composition. The profile must disable its original agent-loop
|
|
7
|
+
* row and remove only this owner's routes from llm-pi-ai before mounting entries.
|
|
8
|
+
* The standard MAIN, registries, persistence and other provider owners remain mounted.
|
|
9
|
+
*/
|
|
10
|
+
export function createDsmmLlmColdStartup(options) {
|
|
11
|
+
let host;
|
|
12
|
+
let failure;
|
|
13
|
+
let mounted;
|
|
14
|
+
let provider;
|
|
15
|
+
const dependencies = [...AgentLoop.inject, "dsmmProfileRuntime", "dsmmRuntimeIntegration", "sessionPersistence", "dsmmLlmProviderOwner"];
|
|
16
|
+
const builtin = "dsmm-llm-provider-owner";
|
|
17
|
+
return {
|
|
18
|
+
patches: [{ id: "agent-loop", disabled: true }, { insert: [{ id: options.provider.settingsNamespace, name: `cordis:${builtin}`, config: options.provider.config }] }],
|
|
19
|
+
async prepare(ctx) {
|
|
20
|
+
const loader = ctx.get("loader");
|
|
21
|
+
if (host !== undefined || ctx.get("agentLoop") !== undefined || loader === undefined || ctx.fiber.entry !== undefined || [...ctx.loader.entries()].length > 0)
|
|
22
|
+
throw new Error("DSMM LLM composition must be installed exactly once before the Loader tree mounts");
|
|
23
|
+
const profile = ctx.get("profileContext");
|
|
24
|
+
if (profile === null || typeof profile !== "object" || !("overlays" in profile) || !Array.isArray(profile.overlays)
|
|
25
|
+
|| !profile.overlays.some((patch) => patch !== null && typeof patch === "object" && "insert" in patch && Array.isArray(patch.insert)
|
|
26
|
+
&& patch.insert.some((entry) => entry !== null && typeof entry === "object" && "id" in entry && "name" in entry && entry.id === options.provider.settingsNamespace && entry.name === `cordis:${builtin}`))) {
|
|
27
|
+
throw new Error("DSMM LLM startup patches must be included in the authoritative profileContext.overlays before readProfilePatches");
|
|
28
|
+
}
|
|
29
|
+
host = ctx;
|
|
30
|
+
const { createDsmmPiAiProviderPlugin } = await import("./native-pi-ai-wire.js");
|
|
31
|
+
ctx.loader.builtins[builtin] = { default: createDsmmPiAiProviderPlugin(options.provider, owner => { provider = owner; }) };
|
|
32
|
+
ctx.inject(dependencies, async (scope) => {
|
|
33
|
+
try {
|
|
34
|
+
if (scope.get("agentLoop") !== undefined || provider === undefined)
|
|
35
|
+
throw new Error("DSMM LLM cold ownership was not established before AgentLoop");
|
|
36
|
+
const integration = scope.get("dsmmRuntimeIntegration");
|
|
37
|
+
if (integration?.runtime.authority.view().deliveryFenceReady !== true)
|
|
38
|
+
throw new Error("DSMM admission guards are not ready");
|
|
39
|
+
const original = scope.llm;
|
|
40
|
+
const stock = Reflect.get(original, symbols.original) ?? original;
|
|
41
|
+
const isolated = scope.isolate("llm");
|
|
42
|
+
const owner = await (options.establish ?? createDsmmRoleLlmOwner)(isolated, provider);
|
|
43
|
+
const llm = new DsmmAwareLlmRuntime(isolated, stock, owner);
|
|
44
|
+
const loop = new AgentLoop(isolated, options.agentLoop);
|
|
45
|
+
mounted = Object.freeze({ loop, llm, provider });
|
|
46
|
+
scope.effect(() => () => { mounted = undefined; });
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
failure = error;
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
assertReady() {
|
|
55
|
+
if (failure !== undefined)
|
|
56
|
+
throw failure;
|
|
57
|
+
if (mounted === undefined) {
|
|
58
|
+
const missing = dependencies.filter(key => host?.get(key) === undefined);
|
|
59
|
+
throw new Error(`DSMM LLM cold startup is not ready; missing dependencies: ${missing.join(", ") || "provider or admission establishment"}`);
|
|
60
|
+
}
|
|
61
|
+
return mounted;
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=host-llm-startup.js.map
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Events } from "@deepseek-ai/cordis";
|
|
3
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
4
|
+
import { LlmRuntime } from "@deepseek-ai/dsh-llm";
|
|
5
|
+
import type { GenerateOptions, LlmCallConfig, PreparedLlmCall, PreparedAdapterCall, ResolvedRetryPolicy, StreamChunk } from "@deepseek-ai/dsh-llm";
|
|
6
|
+
export type DsmmJson = null | boolean | number | string | readonly DsmmJson[] | {
|
|
7
|
+
readonly [key: string]: DsmmJson;
|
|
8
|
+
};
|
|
9
|
+
export type DsmmLlmRequestFrame = Parameters<Events["agent/request"]>[0];
|
|
10
|
+
export interface DsmmLlmCallConfig extends LlmCallConfig {
|
|
11
|
+
readonly customParameters?: Readonly<Record<string, DsmmJson>>;
|
|
12
|
+
}
|
|
13
|
+
export interface DsmmLlmCallClassifier {
|
|
14
|
+
requiresRaw?(config: DsmmLlmCallConfig): boolean;
|
|
15
|
+
}
|
|
16
|
+
/** Use the live provider owner and this call's complete frozen parameters, not envelope presence alone. */
|
|
17
|
+
export declare function requiresDsmmCallAdmission(config: DsmmLlmCallConfig, classifier?: DsmmLlmCallClassifier, uncapturedAgent?: Agent): boolean;
|
|
18
|
+
/** A Host-held admission, not a credential or a value accepted from serialized configuration. */
|
|
19
|
+
export interface DsmmLlmAdmission {
|
|
20
|
+
readonly agent: Agent;
|
|
21
|
+
readonly admission: object;
|
|
22
|
+
readonly capture: object;
|
|
23
|
+
readonly epoch: string;
|
|
24
|
+
readonly signal: AbortSignal;
|
|
25
|
+
assertCurrent(): void;
|
|
26
|
+
}
|
|
27
|
+
export interface DsmmLlmGeneration {
|
|
28
|
+
readonly identity: object;
|
|
29
|
+
readonly signal: AbortSignal;
|
|
30
|
+
readonly retryPolicy: ResolvedRetryPolicy;
|
|
31
|
+
readonly defaultReasoningEffort?: LlmCallConfig["reasoningEffort"];
|
|
32
|
+
assertCurrent(): void;
|
|
33
|
+
prepareCall(provider: string, model: string, signal: AbortSignal, assertAdmission?: () => void): Promise<PreparedAdapterCall>;
|
|
34
|
+
}
|
|
35
|
+
export interface DsmmLlmHostOwner {
|
|
36
|
+
/** Classification must reject lost DSMM evidence instead of returning native. */
|
|
37
|
+
preflight(frame: DsmmLlmRequestFrame, proposal: LlmCallConfig): Promise<{
|
|
38
|
+
readonly kind: "native";
|
|
39
|
+
} | {
|
|
40
|
+
readonly kind: "stock";
|
|
41
|
+
readonly admission: DsmmLlmAdmission;
|
|
42
|
+
readonly config: LlmCallConfig;
|
|
43
|
+
} | {
|
|
44
|
+
readonly kind: "dsmm";
|
|
45
|
+
readonly admission: DsmmLlmAdmission;
|
|
46
|
+
readonly generation: DsmmLlmGeneration;
|
|
47
|
+
readonly config: DsmmLlmCallConfig;
|
|
48
|
+
}>;
|
|
49
|
+
}
|
|
50
|
+
export declare function freezeDsmmJson<T>(value: T): T;
|
|
51
|
+
export declare function snapshotDsmmCall(config: DsmmLlmCallConfig): DsmmLlmCallConfig;
|
|
52
|
+
export declare function preparedConfigMatches(request: GenerateOptions, config: DsmmLlmCallConfig): boolean;
|
|
53
|
+
/** Consumption is synchronous, including rejected dispatches and streams never iterated. */
|
|
54
|
+
export declare function singleUsePreparedStream(dispatch: PreparedLlmCall["stream"]): PreparedLlmCall["stream"];
|
|
55
|
+
/** Native execution service; an optional stock collaborator supports explicit isolated hosts. */
|
|
56
|
+
export declare class DsmmAwareLlmRuntime extends LlmRuntime {
|
|
57
|
+
readonly stock: LlmRuntime | undefined;
|
|
58
|
+
private readonly requestOwner;
|
|
59
|
+
private readonly calls;
|
|
60
|
+
private readonly admitted;
|
|
61
|
+
private readonly preparedRequests;
|
|
62
|
+
private readonly pending;
|
|
63
|
+
private readonly active;
|
|
64
|
+
private readonly nativeClassifications;
|
|
65
|
+
private readonly lifetime;
|
|
66
|
+
private detachRequestOwner?;
|
|
67
|
+
constructor(ctx: Context, stock: LlmRuntime | undefined, requestOwner: DsmmLlmHostOwner);
|
|
68
|
+
/** The Core entry installs its final binder after its request-routing collaborators. */
|
|
69
|
+
protected bindRequestOwner(ctx: Context): void;
|
|
70
|
+
private ownsScope;
|
|
71
|
+
private assertCaptured;
|
|
72
|
+
private finishCaptured;
|
|
73
|
+
private uncapturedNativeConfig;
|
|
74
|
+
prepareCall(proposal: LlmCallConfig, signal?: AbortSignal): Promise<PreparedLlmCall>;
|
|
75
|
+
private prepareAdmittedCall;
|
|
76
|
+
private bindPrepared;
|
|
77
|
+
private adapterStreamFor;
|
|
78
|
+
stream(options: GenerateOptions): AsyncIterable<StreamChunk>;
|
|
79
|
+
registerAdapter(...args: Parameters<LlmRuntime["registerAdapter"]>): import("@deepseek-ai/dsh-llm").AdapterRegistrationHandle;
|
|
80
|
+
registerConfigurableProviders(...args: Parameters<LlmRuntime["registerConfigurableProviders"]>): import("@deepseek-ai/dsh-llm").DirectoryRegistrationHandle;
|
|
81
|
+
registerModelDiscovery(...args: Parameters<LlmRuntime["registerModelDiscovery"]>): () => void;
|
|
82
|
+
resolveCallConfig(...args: Parameters<LlmRuntime["resolveCallConfig"]>): Promise<LlmCallConfig>;
|
|
83
|
+
resolveModelInfo(...args: Parameters<LlmRuntime["resolveModelInfo"]>): Promise<import("@deepseek-ai/dsh-llm").LlmResolvedModelInfo>;
|
|
84
|
+
listModels(...args: Parameters<LlmRuntime["listModels"]>): Promise<import("@deepseek-ai/dsh-llm").LlmModelInfo[]>;
|
|
85
|
+
listProviders(): import("@deepseek-ai/dsh-llm").LlmProviderInfo[];
|
|
86
|
+
listConfigurableProviders(): import("@deepseek-ai/dsh-llm").LlmConfigurableProvider[];
|
|
87
|
+
discoverModels(...args: Parameters<LlmRuntime["discoverModels"]>): Promise<import("@deepseek-ai/dsh-llm").LlmDiscoveredModel[]>;
|
|
88
|
+
providerRetryPolicy(...args: Parameters<LlmRuntime["providerRetryPolicy"]>): ResolvedRetryPolicy;
|
|
89
|
+
imageRequestPricing(...args: Parameters<LlmRuntime["imageRequestPricing"]>): import("@deepseek-ai/dsh-llm").LlmImageRequestPricing | undefined;
|
|
90
|
+
fileRequestText(...args: Parameters<LlmRuntime["fileRequestText"]>): string;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=host-llm.d.ts.map
|
package/lib/host-llm.js
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { Context, symbols } from "@deepseek-ai/cordis";
|
|
2
|
+
import { LlmRuntime, LlmError, errorChain, isAgentLoopRequest, projectFilesToText, projectImagesForTextModel, projectToolUpdates } from "@deepseek-ai/dsh-llm";
|
|
3
|
+
import { canonicalHeader } from "@deepseek-ai/dsh-session";
|
|
4
|
+
import { isDeepStrictEqual } from "node:util";
|
|
5
|
+
import { copyRouteJson } from "./route-json.js";
|
|
6
|
+
import { modelRouteFromCall } from "./role-llm.js";
|
|
7
|
+
import { classifyDsmmAgent } from "./runtime-integration.js";
|
|
8
|
+
/** Use the live provider owner and this call's complete frozen parameters, not envelope presence alone. */
|
|
9
|
+
export function requiresDsmmCallAdmission(config, classifier, uncapturedAgent) {
|
|
10
|
+
return uncapturedAgent !== undefined && classifyDsmmAgent(uncapturedAgent) === "dsmm"
|
|
11
|
+
|| (classifier?.requiresRaw?.(config) ?? config.customParameters !== undefined);
|
|
12
|
+
}
|
|
13
|
+
const envelopeFields = new Set(["messages", "tools", "toolHistory", "sessionId", "signal"]);
|
|
14
|
+
export function freezeDsmmJson(value) {
|
|
15
|
+
let detached;
|
|
16
|
+
try {
|
|
17
|
+
detached = copyRouteJson(value);
|
|
18
|
+
}
|
|
19
|
+
catch (cause) {
|
|
20
|
+
throw new LlmError("LLM parameters must be bounded lossless JSON", "INVALID_CONFIG", { cause });
|
|
21
|
+
}
|
|
22
|
+
const freeze = (item) => {
|
|
23
|
+
if (item !== null && typeof item === "object") {
|
|
24
|
+
for (const child of Object.values(item))
|
|
25
|
+
freeze(child);
|
|
26
|
+
Object.freeze(item);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
freeze(detached);
|
|
30
|
+
return detached;
|
|
31
|
+
}
|
|
32
|
+
export function snapshotDsmmCall(config) {
|
|
33
|
+
const copy = freezeDsmmJson(config);
|
|
34
|
+
for (const key of Object.keys(copy))
|
|
35
|
+
if (!["provider", "model", "reasoningEffort", "temperature", "maxTokens", "stop", "customParameters"].includes(key))
|
|
36
|
+
throw new LlmError(`Unknown call field: ${key}`, "INVALID_CONFIG");
|
|
37
|
+
try {
|
|
38
|
+
modelRouteFromCall(copy);
|
|
39
|
+
}
|
|
40
|
+
catch (cause) {
|
|
41
|
+
throw new LlmError("LLM route fields conflict or contain invalid values", "INVALID_CONFIG", { cause });
|
|
42
|
+
}
|
|
43
|
+
return copy;
|
|
44
|
+
}
|
|
45
|
+
export function preparedConfigMatches(request, config) {
|
|
46
|
+
return isDeepStrictEqual(Object.fromEntries(Object.entries(request).filter(([key]) => !envelopeFields.has(key))), config);
|
|
47
|
+
}
|
|
48
|
+
/** Consumption is synchronous, including rejected dispatches and streams never iterated. */
|
|
49
|
+
export function singleUsePreparedStream(dispatch) {
|
|
50
|
+
let consumed = false;
|
|
51
|
+
return request => {
|
|
52
|
+
if (consumed)
|
|
53
|
+
throw new LlmError("Prepared LLM call was consumed", "INVALID_PREPARED_CALL");
|
|
54
|
+
consumed = true;
|
|
55
|
+
return dispatch(request);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Native execution service; an optional stock collaborator supports explicit isolated hosts. */
|
|
59
|
+
export class DsmmAwareLlmRuntime extends LlmRuntime {
|
|
60
|
+
stock;
|
|
61
|
+
requestOwner;
|
|
62
|
+
calls = new WeakMap();
|
|
63
|
+
admitted = new WeakSet();
|
|
64
|
+
preparedRequests = new WeakSet();
|
|
65
|
+
pending = new WeakMap();
|
|
66
|
+
active = new WeakMap();
|
|
67
|
+
nativeClassifications = new WeakMap();
|
|
68
|
+
lifetime = new AbortController();
|
|
69
|
+
detachRequestOwner;
|
|
70
|
+
constructor(ctx, stock, requestOwner) {
|
|
71
|
+
super(ctx);
|
|
72
|
+
this.stock = stock;
|
|
73
|
+
this.requestOwner = requestOwner;
|
|
74
|
+
ctx.effect(() => () => this.lifetime.abort(new LlmError("LLM Host retired", "INVALID_PREPARED_CALL")));
|
|
75
|
+
ctx.on("session/event", (session, event) => {
|
|
76
|
+
if (event.type !== "step/end" && event.type !== "turn/end")
|
|
77
|
+
return;
|
|
78
|
+
const agent = ctx.get("agents")?.get(session.id);
|
|
79
|
+
if (agent === undefined)
|
|
80
|
+
return;
|
|
81
|
+
this.active.get(agent)?.revocation.abort();
|
|
82
|
+
this.active.delete(agent);
|
|
83
|
+
this.pending.delete(agent);
|
|
84
|
+
this.nativeClassifications.delete(agent);
|
|
85
|
+
}, { global: true });
|
|
86
|
+
this.bindRequestOwner(ctx);
|
|
87
|
+
}
|
|
88
|
+
/** The Core entry installs its final binder after its request-routing collaborators. */
|
|
89
|
+
bindRequestOwner(ctx) {
|
|
90
|
+
this.detachRequestOwner?.();
|
|
91
|
+
this.detachRequestOwner = ctx.on("agent/request", async (frame, next) => {
|
|
92
|
+
const proposal = await next();
|
|
93
|
+
frame.signal.throwIfAborted();
|
|
94
|
+
if (this.stock === undefined && !this.ownsScope(frame)) {
|
|
95
|
+
if (proposal.customParameters !== undefined)
|
|
96
|
+
throw new LlmError("Raw request scope has another LLM owner", "INVALID_PREPARED_CALL");
|
|
97
|
+
return proposal;
|
|
98
|
+
}
|
|
99
|
+
const result = await this.requestOwner.preflight(frame, proposal);
|
|
100
|
+
frame.signal.throwIfAborted();
|
|
101
|
+
if (result.kind === "native") {
|
|
102
|
+
const config = snapshotDsmmCall(proposal);
|
|
103
|
+
this.nativeClassifications.set(frame.agent, { frame: Object.freeze({ ...frame }), config });
|
|
104
|
+
return config;
|
|
105
|
+
}
|
|
106
|
+
this.nativeClassifications.delete(frame.agent);
|
|
107
|
+
if (result.admission.agent !== frame.agent)
|
|
108
|
+
throw new LlmError("LLM admission belongs to another Agent", "INVALID_PREPARED_CALL");
|
|
109
|
+
this.active.get(frame.agent)?.revocation.abort();
|
|
110
|
+
const captured = { frame: Object.freeze({ ...frame }), admission: result.admission,
|
|
111
|
+
...(result.kind === "dsmm" ? { generation: result.generation } : {}), revocation: new AbortController() };
|
|
112
|
+
this.active.set(frame.agent, captured);
|
|
113
|
+
const retire = () => {
|
|
114
|
+
if (this.active.get(frame.agent) === captured && frame.agent.status === "running" && !frame.signal.aborted)
|
|
115
|
+
frame.agent.cancel({ kind: "hook", reason: "DSMM LLM admission retired" }, { keepInbox: true });
|
|
116
|
+
};
|
|
117
|
+
const externalSignals = [captured.admission.signal, ...captured.generation === undefined ? [] : [captured.generation.signal], this.lifetime.signal];
|
|
118
|
+
for (const signal of externalSignals)
|
|
119
|
+
signal.addEventListener("abort", retire, { once: true });
|
|
120
|
+
captured.revocation.signal.addEventListener("abort", () => { for (const signal of externalSignals)
|
|
121
|
+
signal.removeEventListener("abort", retire); }, { once: true });
|
|
122
|
+
if (externalSignals.some(signal => signal.aborted))
|
|
123
|
+
retire();
|
|
124
|
+
this.assertCaptured(captured);
|
|
125
|
+
const prior = frame.agent.session.requestHeader();
|
|
126
|
+
if (prior !== undefined)
|
|
127
|
+
snapshotDsmmCall(prior.config);
|
|
128
|
+
const config = snapshotDsmmCall(result.config);
|
|
129
|
+
this.calls.set(config, captured);
|
|
130
|
+
this.admitted.add(config);
|
|
131
|
+
this.pending.set(frame.agent, config);
|
|
132
|
+
return config;
|
|
133
|
+
}, { prepend: true, global: true });
|
|
134
|
+
}
|
|
135
|
+
ownsScope(frame) {
|
|
136
|
+
const current = frame.agent.ctx.get("llm");
|
|
137
|
+
return current !== undefined && (Reflect.get(current, symbols.original) ?? current) === (Reflect.get(this, symbols.original) ?? this);
|
|
138
|
+
}
|
|
139
|
+
assertCaptured(call) {
|
|
140
|
+
this.lifetime.signal.throwIfAborted();
|
|
141
|
+
call.frame.signal.throwIfAborted();
|
|
142
|
+
call.admission.signal.throwIfAborted();
|
|
143
|
+
call.generation?.signal.throwIfAborted();
|
|
144
|
+
call.generation?.assertCurrent();
|
|
145
|
+
call.revocation.signal.throwIfAborted();
|
|
146
|
+
call.admission.assertCurrent();
|
|
147
|
+
if (this.stock === undefined && !this.ownsScope(call.frame))
|
|
148
|
+
throw new LlmError("Request scope no longer resolves this native LLM owner", "INVALID_PREPARED_CALL");
|
|
149
|
+
if (this.ctx.get("agents")?.get(call.frame.agent.id) !== call.frame.agent || call.frame.agent.status !== "running" || this.active.get(call.frame.agent) !== call)
|
|
150
|
+
throw new LlmError("LLM Agent lifecycle is no longer current", "INVALID_PREPARED_CALL");
|
|
151
|
+
}
|
|
152
|
+
finishCaptured(call) {
|
|
153
|
+
call.revocation.abort();
|
|
154
|
+
if (this.active.get(call.frame.agent) === call)
|
|
155
|
+
this.active.delete(call.frame.agent);
|
|
156
|
+
}
|
|
157
|
+
uncapturedNativeConfig(proposal, agent, signal, fallback = false) {
|
|
158
|
+
this.lifetime.signal.throwIfAborted();
|
|
159
|
+
const config = snapshotDsmmCall(proposal);
|
|
160
|
+
const classifier = this.ctx.get("dsmmLlmRoutes");
|
|
161
|
+
const native = agent === undefined ? undefined : this.nativeClassifications.get(agent);
|
|
162
|
+
const classified = native !== undefined && native.frame.signal === signal && !native.frame.signal.aborted
|
|
163
|
+
&& agent?.status === "running" && this.ctx.get("agents")?.get(agent.id) === agent
|
|
164
|
+
&& (this.stock !== undefined || this.ownsScope(native.frame))
|
|
165
|
+
&& (fallback ? isDeepStrictEqual(config, native.config) : proposal === native.config);
|
|
166
|
+
if (requiresDsmmCallAdmission(config, classifier, classified ? undefined : agent))
|
|
167
|
+
throw new LlmError("Enhanced requests require their exact Host proposal", "INVALID_PREPARED_CALL");
|
|
168
|
+
return config;
|
|
169
|
+
}
|
|
170
|
+
async prepareCall(proposal, signal) {
|
|
171
|
+
const initiator = this.ctx.get("agents")?.currentInitiator();
|
|
172
|
+
if (initiator !== undefined && this.pending.has(initiator) && this.pending.get(initiator) !== proposal)
|
|
173
|
+
throw new LlmError("DSMM request lost its exact proposal identity", "INVALID_PREPARED_CALL");
|
|
174
|
+
const captured = this.calls.get(proposal);
|
|
175
|
+
if (captured === undefined) {
|
|
176
|
+
if (this.admitted.has(proposal))
|
|
177
|
+
throw new LlmError("DSMM proposal was already consumed", "INVALID_PREPARED_CALL");
|
|
178
|
+
const config = this.uncapturedNativeConfig(proposal, initiator, signal);
|
|
179
|
+
return this.stock === undefined ? super.prepareCall(config, signal) : this.stock.prepareCall(config, signal);
|
|
180
|
+
}
|
|
181
|
+
this.calls.delete(proposal);
|
|
182
|
+
this.pending.delete(captured.frame.agent);
|
|
183
|
+
try {
|
|
184
|
+
if (signal !== captured.frame.signal)
|
|
185
|
+
throw new LlmError("LLM request signal does not match admission", "INVALID_PREPARED_CALL");
|
|
186
|
+
return await this.prepareAdmittedCall(proposal, signal, captured);
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
// NO_ADAPTER is the official loop's signal to dispatch without a prepared call.
|
|
190
|
+
if (error instanceof LlmError && error.code === "NO_ADAPTER")
|
|
191
|
+
throw new LlmError("Admitted DSMM generation could not prepare the request", "DSMM_PREPARATION_FAILED", { cause: error });
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async prepareAdmittedCall(proposal, signal, captured) {
|
|
196
|
+
this.assertCaptured(captured);
|
|
197
|
+
if (captured.generation === undefined) {
|
|
198
|
+
const preparationSignal = AbortSignal.any([signal, captured.admission.signal, captured.revocation.signal, this.lifetime.signal]);
|
|
199
|
+
const prepared = await (this.stock === undefined ? super.prepareCall(proposal, preparationSignal) : this.stock.prepareCall(proposal, preparationSignal));
|
|
200
|
+
this.assertCaptured(captured);
|
|
201
|
+
return this.bindPrepared(captured, signal, prepared, request => prepared.stream(request));
|
|
202
|
+
}
|
|
203
|
+
const bound = await captured.generation.prepareCall(proposal.provider, proposal.model, signal, () => this.assertCaptured(captured));
|
|
204
|
+
this.assertCaptured(captured);
|
|
205
|
+
if (bound.model.provider !== proposal.provider || bound.model.id !== proposal.model)
|
|
206
|
+
throw new LlmError("Provider resolved another model", "INVALID_ADAPTER");
|
|
207
|
+
const customParameters = proposal.customParameters;
|
|
208
|
+
const defaultReasoningEffort = captured.generation.defaultReasoningEffort ?? bound.model.reasoning?.defaultEffort;
|
|
209
|
+
const adapterDefaults = Object.freeze({
|
|
210
|
+
...(proposal.maxTokens === undefined && !["max_tokens", "max_completion_tokens", "max_output_tokens"].some(key => Object.hasOwn(customParameters ?? {}, key)) && bound.model.defaultMaxTokens !== undefined ? { maxTokens: true } : {}),
|
|
211
|
+
...(proposal.reasoningEffort === undefined && !Object.hasOwn(customParameters ?? {}, "reasoning_effort") && defaultReasoningEffort !== undefined ? { reasoningEffort: true } : {}),
|
|
212
|
+
});
|
|
213
|
+
const config = snapshotDsmmCall({ ...proposal, ...(adapterDefaults.maxTokens ? { maxTokens: bound.model.defaultMaxTokens } : {}),
|
|
214
|
+
...(adapterDefaults.reasoningEffort ? { reasoningEffort: defaultReasoningEffort } : {}) });
|
|
215
|
+
return this.bindPrepared(captured, signal, {
|
|
216
|
+
config, adapterDefaults, retryPolicy: freezeDsmmJson(captured.generation.retryPolicy),
|
|
217
|
+
...(bound.model.context === undefined ? {} : { context: freezeDsmmJson(bound.model.context) }),
|
|
218
|
+
...(bound.model.inputModalities === undefined ? {} : { inputModalities: freezeDsmmJson(bound.model.inputModalities) }),
|
|
219
|
+
...(bound.model.systemPromptUpdate === undefined ? {} : { systemPromptUpdate: bound.model.systemPromptUpdate }),
|
|
220
|
+
...(bound.model.toolUpdate === undefined ? {} : { toolUpdate: bound.model.toolUpdate }),
|
|
221
|
+
stream: bound.stream,
|
|
222
|
+
}, (request, providerSignal) => this.ctx.waterfall(this, "llm/stream", request, () => this.adapterStreamFor(bound, request, providerSignal)));
|
|
223
|
+
}
|
|
224
|
+
bindPrepared(captured, signal, prepared, dispatchPrepared) {
|
|
225
|
+
const { stream: _stream, ...metadata } = prepared;
|
|
226
|
+
const { config, adapterDefaults } = metadata;
|
|
227
|
+
return Object.freeze({ ...freezeDsmmJson(metadata),
|
|
228
|
+
stream: singleUsePreparedStream((request) => {
|
|
229
|
+
this.assertCaptured(captured);
|
|
230
|
+
if (!isAgentLoopRequest(request) || !Object.isFrozen(request) || request.signal !== signal || request.sessionId !== captured.frame.agent.id
|
|
231
|
+
|| !preparedConfigMatches(request, config))
|
|
232
|
+
throw new LlmError("Prepared LLM request changed", "INVALID_PREPARED_CALL");
|
|
233
|
+
this.preparedRequests.add(request);
|
|
234
|
+
const session = captured.frame.agent.session;
|
|
235
|
+
const header = canonicalHeader({ config, adapterDefaults, ...(request.tools === undefined ? {} : { tools: [...request.tools] }) });
|
|
236
|
+
if (!isDeepStrictEqual(session.requestHeader(), header))
|
|
237
|
+
session.append("request/header", { header, reason: "change" });
|
|
238
|
+
const dispatch = async function* (runtime) {
|
|
239
|
+
try {
|
|
240
|
+
runtime.assertCaptured(captured);
|
|
241
|
+
if (await runtime.ctx.get("sessions")?.flush(session) !== true)
|
|
242
|
+
throw new LlmError("Native request header has no persistence listener", "PERSISTENCE_UNAVAILABLE");
|
|
243
|
+
runtime.assertCaptured(captured);
|
|
244
|
+
const providerSignal = AbortSignal.any([captured.frame.signal, captured.admission.signal,
|
|
245
|
+
...captured.generation === undefined ? [] : [captured.generation.signal], captured.revocation.signal, runtime.lifetime.signal]);
|
|
246
|
+
yield* dispatchPrepared(request, providerSignal);
|
|
247
|
+
}
|
|
248
|
+
finally {
|
|
249
|
+
runtime.finishCaptured(captured);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
return dispatch(this);
|
|
253
|
+
}),
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
async *adapterStreamFor(bound, request, signal) {
|
|
257
|
+
let iterator;
|
|
258
|
+
const failure = (error) => ({ type: "finish", reason: { kind: signal.aborted ? "aborted" : "error",
|
|
259
|
+
failure: error instanceof LlmError ? error.failure : { code: "UNKNOWN", message: errorChain(error) } } });
|
|
260
|
+
let messages = projectFilesToText(request.messages, ref => {
|
|
261
|
+
const path = this.ctx.get("attachments")?.fileHostPath(ref);
|
|
262
|
+
return path === undefined ? undefined : this.ctx.get("fs")?.processPathFromHostPath(path);
|
|
263
|
+
});
|
|
264
|
+
if (bound.model.inputModalities !== undefined && !bound.model.inputModalities.includes("image"))
|
|
265
|
+
messages = projectImagesForTextModel(messages);
|
|
266
|
+
const projected = projectToolUpdates(messages, request.tools, bound.model.toolUpdate, request.toolHistory);
|
|
267
|
+
const projectedMessages = [...projected.messages];
|
|
268
|
+
Object.freeze(projectedMessages);
|
|
269
|
+
signal.throwIfAborted();
|
|
270
|
+
const options = Object.freeze({ ...request, signal, messages: projectedMessages, ...(projected.tools === undefined ? {} : { tools: [...projected.tools] }) });
|
|
271
|
+
try {
|
|
272
|
+
iterator = bound.stream(options)[Symbol.asyncIterator]();
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
yield failure(error);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
let completed = false;
|
|
279
|
+
try {
|
|
280
|
+
while (true) {
|
|
281
|
+
let next;
|
|
282
|
+
try {
|
|
283
|
+
next = await iterator.next();
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
286
|
+
completed = true;
|
|
287
|
+
yield failure(error);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (next.done) {
|
|
291
|
+
completed = true;
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
yield next.value;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
finally {
|
|
298
|
+
if (!completed)
|
|
299
|
+
await iterator.return?.();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
stream(options) {
|
|
303
|
+
const agent = options.sessionId === undefined ? undefined : this.ctx.get("agents")?.get(options.sessionId);
|
|
304
|
+
const captured = agent === undefined ? undefined : this.active.get(agent);
|
|
305
|
+
if (this.preparedRequests.has(options) || captured !== undefined && (options.signal === captured.frame.signal || isAgentLoopRequest(options))) {
|
|
306
|
+
throw new LlmError("Admitted DSMM requests require their prepared call", "INVALID_PREPARED_CALL");
|
|
307
|
+
}
|
|
308
|
+
const config = this.uncapturedNativeConfig(Object.fromEntries(Object.entries(options).filter(([key]) => !envelopeFields.has(key))), agent, options.signal, true);
|
|
309
|
+
const request = Object.isFrozen(options) ? options : { ...options, ...config };
|
|
310
|
+
return this.stock === undefined ? super.stream(request) : this.stock.stream(request);
|
|
311
|
+
}
|
|
312
|
+
registerAdapter(...args) { return this.stock === undefined ? super.registerAdapter(...args) : this.stock.registerAdapter(...args); }
|
|
313
|
+
registerConfigurableProviders(...args) { return this.stock === undefined ? super.registerConfigurableProviders(...args) : this.stock.registerConfigurableProviders(...args); }
|
|
314
|
+
registerModelDiscovery(...args) { return this.stock === undefined ? super.registerModelDiscovery(...args) : this.stock.registerModelDiscovery(...args); }
|
|
315
|
+
resolveCallConfig(...args) { return this.stock === undefined ? super.resolveCallConfig(...args) : this.stock.resolveCallConfig(...args); }
|
|
316
|
+
resolveModelInfo(...args) { return this.stock === undefined ? super.resolveModelInfo(...args) : this.stock.resolveModelInfo(...args); }
|
|
317
|
+
listModels(...args) { return this.stock === undefined ? super.listModels(...args) : this.stock.listModels(...args); }
|
|
318
|
+
listProviders() { return this.stock === undefined ? super.listProviders() : this.stock.listProviders(); }
|
|
319
|
+
listConfigurableProviders() { return this.stock === undefined ? super.listConfigurableProviders() : this.stock.listConfigurableProviders(); }
|
|
320
|
+
discoverModels(...args) { return this.stock === undefined ? super.discoverModels(...args) : this.stock.discoverModels(...args); }
|
|
321
|
+
providerRetryPolicy(...args) { return this.stock === undefined ? super.providerRetryPolicy(...args) : this.stock.providerRetryPolicy(...args); }
|
|
322
|
+
imageRequestPricing(...args) { return this.stock === undefined ? super.imageRequestPricing(...args) : this.stock.imageRequestPricing(...args); }
|
|
323
|
+
fileRequestText(...args) { return this.stock === undefined ? super.fileRequestText(...args) : this.stock.fileRequestText(...args); }
|
|
324
|
+
}
|
|
325
|
+
//# sourceMappingURL=host-llm.js.map
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { DshContext } from "./dsh-types.js";
|
|
2
2
|
import type { DsmmPluginConfig } from "./settings.js";
|
|
3
|
+
import type { DsmmHostStartupOptions } from "./runtime-integration.js";
|
|
3
4
|
export declare const name = "dsmm";
|
|
4
|
-
export declare const inject: readonly ["profileContext"];
|
|
5
|
+
export declare const inject: readonly ["profileContext", "agents"];
|
|
5
6
|
export type Config = DsmmPluginConfig;
|
|
6
7
|
export declare const Config: import("@deepseek-ai/schemastery").default<DsmmPluginConfig>;
|
|
7
8
|
export type { DeepworkSessionEventMap } from "./dsh-events.js";
|
|
@@ -37,12 +38,22 @@ export { DSMM_MODULE_DESCRIPTORS, deepworkEnabled, projectDeepworkModule } from
|
|
|
37
38
|
export type { DsmmModuleState } from "./modules.js";
|
|
38
39
|
export type { DsmmProfileRuntimeStore, DsmmProfileRuntimeOptions } from "./profile-runtime.js";
|
|
39
40
|
export { DEEPWORK_MODE_EVENT, DeepworkModeController, hasOpenTurn, isDeepworkActive } from "./state.js";
|
|
40
|
-
export
|
|
41
|
+
export type { DsmmHostStartupOptions } from "./runtime-integration.js";
|
|
42
|
+
export { DsmmNativeLlmRuntime } from "./llm-runtime.js";
|
|
43
|
+
export type { DsmmLlmAdmission, DsmmLlmCallConfig, DsmmLlmHostOwner, DsmmLlmGeneration, DsmmJson } from "./host-llm.js";
|
|
44
|
+
/** Experimental Host collaborators are programmatic only; serialized settings cannot authenticate them. */
|
|
45
|
+
export declare function createDsmmHostPlugin(startup: DsmmHostStartupOptions): {
|
|
46
|
+
name: string;
|
|
47
|
+
Config: import("@deepseek-ai/schemastery").default<DsmmPluginConfig>;
|
|
48
|
+
inject: string[] | readonly ["profileContext", "agents"];
|
|
49
|
+
apply(ctx: DshContext, config?: Config): void | Promise<void>;
|
|
50
|
+
};
|
|
51
|
+
export declare function apply(ctx: DshContext, config?: Config, hostStartup?: DsmmHostStartupOptions): void | Promise<void>;
|
|
41
52
|
declare const _default: {
|
|
42
53
|
name: string;
|
|
43
|
-
inject: readonly ["profileContext"];
|
|
54
|
+
inject: readonly ["profileContext", "agents"];
|
|
44
55
|
Config: import("@deepseek-ai/schemastery").default<DsmmPluginConfig>;
|
|
45
|
-
apply:
|
|
56
|
+
apply(ctx: DshContext, config?: Config): void | Promise<void>;
|
|
46
57
|
};
|
|
47
58
|
export default _default;
|
|
48
59
|
//# sourceMappingURL=index.d.ts.map
|