@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/modules.d.ts
CHANGED
|
@@ -1,27 +1,35 @@
|
|
|
1
1
|
import type { DsmmDeploymentSnapshot, DsmmProfileAdmission, DsmmSettings } from "./settings.js";
|
|
2
2
|
/** Static first-party inventory, not a plugin/provider installation interface. */
|
|
3
|
-
export declare const DSMM_MODULE_DESCRIPTORS: readonly Readonly<{
|
|
3
|
+
export declare const DSMM_MODULE_DESCRIPTORS: readonly (Readonly<{
|
|
4
4
|
id: "deepwork";
|
|
5
5
|
label: "Deepwork";
|
|
6
6
|
key: "modules.deepwork.enabled";
|
|
7
|
-
}>
|
|
7
|
+
}> | Readonly<{
|
|
8
|
+
id: "permission-control";
|
|
9
|
+
label: "Permission control";
|
|
10
|
+
key: "permissionControl.enabled";
|
|
11
|
+
}>)[];
|
|
8
12
|
export interface DsmmModuleState {
|
|
9
13
|
descriptor: typeof DSMM_MODULE_DESCRIPTORS[number];
|
|
10
14
|
hostBundleEnabled: "unknown";
|
|
11
15
|
desired: {
|
|
12
16
|
enabled: boolean;
|
|
13
|
-
source: "defaults" | "global";
|
|
17
|
+
source: "defaults" | "global" | "profile";
|
|
14
18
|
capture: "current-global" | "admission" | "startup";
|
|
15
19
|
};
|
|
16
|
-
startupMounted: boolean;
|
|
20
|
+
startupMounted: boolean | null;
|
|
17
21
|
admitted: boolean | null;
|
|
18
22
|
nextRoot: {
|
|
19
|
-
admitted: boolean;
|
|
23
|
+
admitted: boolean | null;
|
|
20
24
|
reason: "global-disabled" | "restart-required" | null;
|
|
21
25
|
};
|
|
22
26
|
reason: "global-disabled" | "restart-required" | "captured-off" | null;
|
|
23
27
|
pending: boolean;
|
|
24
28
|
}
|
|
29
|
+
/** Trusted Host lifecycle observation; missing or retired owners return null, not readiness. */
|
|
30
|
+
export type DsmmMountedPermissionGetter = () => boolean | null;
|
|
25
31
|
export declare function deepworkEnabled(settings: DsmmSettings): boolean;
|
|
26
32
|
export declare function projectDeepworkModule(startup: DsmmSettings, desired?: DsmmDeploymentSnapshot, admission?: DsmmProfileAdmission, currentGlobal?: boolean): DsmmModuleState;
|
|
33
|
+
/** Both projections share the same captured deployment/admission; module state grants no authority. */
|
|
34
|
+
export declare function projectDsmmModules(startup: DsmmSettings, desired?: DsmmDeploymentSnapshot, admission?: DsmmProfileAdmission, currentGlobal?: boolean, getMountedPermission?: DsmmMountedPermissionGetter): DsmmModuleState[];
|
|
27
35
|
//# sourceMappingURL=modules.d.ts.map
|
package/lib/modules.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** Static first-party inventory, not a plugin/provider installation interface. */
|
|
2
2
|
export const DSMM_MODULE_DESCRIPTORS = Object.freeze([
|
|
3
|
-
Object.freeze({ id: "deepwork", label: "Deepwork", key: "modules.deepwork.enabled" })
|
|
3
|
+
Object.freeze({ id: "deepwork", label: "Deepwork", key: "modules.deepwork.enabled" }),
|
|
4
|
+
Object.freeze({ id: "permission-control", label: "Permission control", key: "permissionControl.enabled" })
|
|
4
5
|
]);
|
|
5
6
|
export function deepworkEnabled(settings) { return settings.modules.deepwork.enabled; }
|
|
6
7
|
export function projectDeepworkModule(startup, desired, admission, currentGlobal = false) {
|
|
@@ -18,4 +19,19 @@ export function projectDeepworkModule(startup, desired, admission, currentGlobal
|
|
|
18
19
|
pending: enabled !== mounted || admitted !== null && admitted !== next
|
|
19
20
|
};
|
|
20
21
|
}
|
|
22
|
+
/** Both projections share the same captured deployment/admission; module state grants no authority. */
|
|
23
|
+
export function projectDsmmModules(startup, desired, admission, currentGlobal = false, getMountedPermission) {
|
|
24
|
+
const enabled = desired?.settings.permissionControl.enabled ?? startup.permissionControl.enabled;
|
|
25
|
+
const mounted = getMountedPermission?.() ?? null;
|
|
26
|
+
const admitted = admission?.settings.permissionControl.enabled ?? null;
|
|
27
|
+
const restartRequired = enabled !== startup.permissionControl.enabled;
|
|
28
|
+
const reason = restartRequired ? "restart-required" : null;
|
|
29
|
+
return [projectDeepworkModule(startup, desired, admission, currentGlobal), {
|
|
30
|
+
descriptor: { ...DSMM_MODULE_DESCRIPTORS[1] }, hostBundleEnabled: "unknown",
|
|
31
|
+
desired: { enabled, source: desired?.sources["permissionControl.enabled"] ?? "defaults",
|
|
32
|
+
capture: currentGlobal ? "current-global" : admission === undefined ? "startup" : "admission" },
|
|
33
|
+
startupMounted: mounted, admitted, nextRoot: { admitted: mounted, reason }, reason,
|
|
34
|
+
pending: restartRequired || admitted !== null && mounted !== null && admitted !== mounted
|
|
35
|
+
}];
|
|
36
|
+
}
|
|
21
37
|
//# sourceMappingURL=modules.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { SessionEvent, SessionHeader, SessionId as NativeSessionId } from "@deepseek-ai/dsh-session";
|
|
3
|
+
import type { ContinuableSubagentDescriptorData } from "@deepseek-ai/dsh-subagent";
|
|
4
|
+
import type { ParentAdmissionTicket } from "./delivery-authority.js";
|
|
5
|
+
import type { ChildAdmissionCapture, LegacyChildEvidence } from "./child-capture.js";
|
|
6
|
+
import type { DsmmProfileAdmission } from "./settings.js";
|
|
7
|
+
import type { DsmmRoleId } from "./roles.js";
|
|
8
|
+
/** Host-only borrowed cut returned by the PUBLIC SessionQueryEngine.observeSession service. */
|
|
9
|
+
export interface NativeChildObservation extends Disposable {
|
|
10
|
+
readonly header: SessionHeader;
|
|
11
|
+
readonly inheritedEventCount: number;
|
|
12
|
+
readonly events: readonly SessionEvent[];
|
|
13
|
+
}
|
|
14
|
+
/** Injection avoids making the optional query provider a new DSMM package dependency. No wire caller supplies history. */
|
|
15
|
+
export interface NativeChildHistory {
|
|
16
|
+
observeSession(id: NativeSessionId, options: {
|
|
17
|
+
signal: AbortSignal;
|
|
18
|
+
projectionMode: "none";
|
|
19
|
+
}): Promise<NativeChildObservation>;
|
|
20
|
+
}
|
|
21
|
+
export interface NativeChildFacts {
|
|
22
|
+
readonly childSessionId: string;
|
|
23
|
+
readonly parentSessionId: string;
|
|
24
|
+
readonly depth: number;
|
|
25
|
+
readonly role: DsmmRoleId;
|
|
26
|
+
readonly descriptor: ContinuableSubagentDescriptorData;
|
|
27
|
+
readonly active?: boolean;
|
|
28
|
+
readonly requestBudgetObserved: boolean;
|
|
29
|
+
}
|
|
30
|
+
/** Exact public catalog and replay-validated physical cuts; never resumes an Agent. */
|
|
31
|
+
export declare class NativeChildEvidenceReader {
|
|
32
|
+
private readonly ctx;
|
|
33
|
+
private readonly assertTicket;
|
|
34
|
+
private readonly history;
|
|
35
|
+
constructor(ctx: Context, assertTicket: (ticket: ParentAdmissionTicket<DsmmProfileAdmission>) => void, history: NativeChildHistory);
|
|
36
|
+
read(ticket: ParentAdmissionTicket<DsmmProfileAdmission>, childId: string, callerSignal: AbortSignal): Promise<NativeChildFacts>;
|
|
37
|
+
legacy(ticket: ParentAdmissionTicket<DsmmProfileAdmission>, childId: string, signal: AbortSignal): Promise<LegacyChildEvidence>;
|
|
38
|
+
}
|
|
39
|
+
export declare function legacyEvidenceFromNativeFacts(facts: NativeChildFacts): LegacyChildEvidence;
|
|
40
|
+
/** Capture evidence must agree with the child's establishing descriptor, not current parent routing. */
|
|
41
|
+
export declare function assertNativeChildCapture(capture: ChildAdmissionCapture, facts: NativeChildFacts): void;
|
|
42
|
+
//# sourceMappingURL=native-child-evidence.d.ts.map
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { symbols } from "@deepseek-ai/cordis";
|
|
2
|
+
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
3
|
+
import { foldSubagentDescriptor, SubagentError } from "@deepseek-ai/dsh-subagent";
|
|
4
|
+
import { parseLegacyChildEvidence } from "./child-capture.js";
|
|
5
|
+
import { freezeSettings } from "./settings.js";
|
|
6
|
+
import { isDsmmRoleId } from "./roles.js";
|
|
7
|
+
function unauthorized() { throw new SubagentError("Child history does not prove its direct native identity", "UNAUTHORIZED"); }
|
|
8
|
+
/** Exact public catalog and replay-validated physical cuts; never resumes an Agent. */
|
|
9
|
+
export class NativeChildEvidenceReader {
|
|
10
|
+
ctx;
|
|
11
|
+
assertTicket;
|
|
12
|
+
history;
|
|
13
|
+
constructor(ctx, assertTicket, history) {
|
|
14
|
+
this.ctx = ctx;
|
|
15
|
+
this.assertTicket = assertTicket;
|
|
16
|
+
this.history = history;
|
|
17
|
+
}
|
|
18
|
+
async read(ticket, childId, callerSignal) {
|
|
19
|
+
const signal = AbortSignal.any([ticket.signal, callerSignal]);
|
|
20
|
+
const check = () => {
|
|
21
|
+
signal.throwIfAborted();
|
|
22
|
+
this.assertTicket(ticket);
|
|
23
|
+
const current = this.ctx.get("sessionQuery");
|
|
24
|
+
if (current === undefined || (Reflect.get(current, symbols.original) ?? current) !== (Reflect.get(this.history, symbols.original) ?? this.history))
|
|
25
|
+
unauthorized();
|
|
26
|
+
};
|
|
27
|
+
check();
|
|
28
|
+
if (this.ctx.agents.get(ticket.parent.id) !== ticket.parent || childId === ticket.parent.id)
|
|
29
|
+
unauthorized();
|
|
30
|
+
const rows = await this.ctx.subagents.listChildren(ticket.parent.id, signal);
|
|
31
|
+
check();
|
|
32
|
+
const matches = rows.filter(row => row.id === childId);
|
|
33
|
+
if (matches.length !== 1 || matches[0].mode !== "continuable")
|
|
34
|
+
unauthorized();
|
|
35
|
+
const observation = await this.history.observeSession(SessionId(childId), { signal, projectionMode: "none" });
|
|
36
|
+
try {
|
|
37
|
+
check();
|
|
38
|
+
const facts = readFacts(ticket.parent, childId, observation);
|
|
39
|
+
const catalog = matches[0];
|
|
40
|
+
if (catalog.createdAt !== observation.header.createdAt || catalog.mode !== facts.descriptor.mode || catalog.label !== facts.descriptor.label)
|
|
41
|
+
unauthorized();
|
|
42
|
+
check();
|
|
43
|
+
return facts;
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
observation[Symbol.dispose]();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async legacy(ticket, childId, signal) {
|
|
50
|
+
return legacyEvidenceFromNativeFacts(await this.read(ticket, childId, signal));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function readFacts(parent, childId, observation) {
|
|
54
|
+
const header = observation.header;
|
|
55
|
+
if (header.version !== 4 || header.id !== childId || header.parentSession !== parent.id || header.origin !== "subagent"
|
|
56
|
+
|| !Number.isSafeInteger(header.delegationDepth) || header.delegationDepth <= (parent.session.header.delegationDepth ?? 0)
|
|
57
|
+
|| typeof header.cwd !== "string")
|
|
58
|
+
unauthorized();
|
|
59
|
+
const inherited = observation.inheritedEventCount;
|
|
60
|
+
if (!Number.isSafeInteger(inherited) || inherited < 0 || inherited > observation.events.length)
|
|
61
|
+
unauthorized();
|
|
62
|
+
const own = observation.events.slice(inherited);
|
|
63
|
+
// The catalog projection is display data; a second descriptor cannot replace the establishing composition.
|
|
64
|
+
if (own.filter(event => event.type === "subagent/descriptor").length !== 1)
|
|
65
|
+
unauthorized();
|
|
66
|
+
const descriptor = foldSubagentDescriptor(own);
|
|
67
|
+
if (descriptor?.mode !== "continuable" || !descriptor.provider.startsWith("dsmm-role-"))
|
|
68
|
+
unauthorized();
|
|
69
|
+
const role = `dsmm-${descriptor.provider.slice("dsmm-role-".length)}`;
|
|
70
|
+
if (!isDsmmRoleId(role) || role === "dsmm-orchestrator" || descriptor.agentProvider === undefined || descriptor.agentModel === undefined)
|
|
71
|
+
unauthorized();
|
|
72
|
+
let active;
|
|
73
|
+
for (const event of own) {
|
|
74
|
+
if (event.type === "dsmm/role-policy") {
|
|
75
|
+
const data = event.data;
|
|
76
|
+
if (data === null || typeof data !== "object" || Array.isArray(data) || Object.keys(data).length !== 3
|
|
77
|
+
|| data.version !== 1 || data.role !== role || data.policy !== null && (typeof data.policy !== "string" || !/^[a-f0-9]{64}$/u.test(data.policy)))
|
|
78
|
+
unauthorized();
|
|
79
|
+
}
|
|
80
|
+
else if (event.type === "deepwork/mode") {
|
|
81
|
+
const data = event.data;
|
|
82
|
+
if (data === null || typeof data !== "object" || Array.isArray(data) || Object.keys(data).length !== 1 || typeof data.active !== "boolean")
|
|
83
|
+
unauthorized();
|
|
84
|
+
active = data.active;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return freezeSettings({ childSessionId: childId, parentSessionId: parent.id, depth: header.delegationDepth, role, descriptor,
|
|
88
|
+
...(active === undefined ? {} : { active }), requestBudgetObserved: own.some(hasRequestBudget) });
|
|
89
|
+
}
|
|
90
|
+
function hasRequestBudget(event) {
|
|
91
|
+
if (event.type !== "request/header")
|
|
92
|
+
return false;
|
|
93
|
+
return event.data.header.config.maxTokens !== undefined;
|
|
94
|
+
}
|
|
95
|
+
export function legacyEvidenceFromNativeFacts(facts) {
|
|
96
|
+
const provenFields = ["lineage", "role", "route"];
|
|
97
|
+
if (facts.descriptor.toolFilter !== undefined)
|
|
98
|
+
provenFields.push("tool-filter");
|
|
99
|
+
if (facts.active !== undefined)
|
|
100
|
+
provenFields.push("active-intent");
|
|
101
|
+
if (facts.requestBudgetObserved)
|
|
102
|
+
provenFields.push("max-tokens");
|
|
103
|
+
const limitations = [
|
|
104
|
+
...["profile-pin", "admission-epoch", "invocation-level", "locale", "tool-topology"].map(field => ({ field, code: "missing-evidence", effect: "display-only" })),
|
|
105
|
+
...["runtime-policy", "modules", "roles", "read-only", "route-override", "max-depth", "guards", "git-write", "shell", "delegation"].map(field => ({ field, code: "missing-evidence", effect: "capability-denied" })),
|
|
106
|
+
{ field: "max-tokens", code: "not-persisted", effect: "native-default" },
|
|
107
|
+
{ field: "output-schema", code: "unverified", effect: "capability-denied" },
|
|
108
|
+
];
|
|
109
|
+
if (facts.descriptor.toolFilter === undefined)
|
|
110
|
+
limitations.push({ field: "tool-filter", code: "missing-evidence", effect: "capability-denied" });
|
|
111
|
+
if (facts.active === undefined)
|
|
112
|
+
limitations.push({ field: "active-intent", code: "missing-evidence", effect: "display-only" });
|
|
113
|
+
return parseLegacyChildEvidence({ version: 1, mode: "legacy-conservative", childSessionId: facts.childSessionId,
|
|
114
|
+
parentSessionId: facts.parentSessionId, role: facts.role, depth: facts.depth,
|
|
115
|
+
route: { provider: facts.descriptor.agentProvider, model: facts.descriptor.agentModel,
|
|
116
|
+
...(facts.descriptor.agentReasoningEffort === undefined ? {} : { reasoningEffort: facts.descriptor.agentReasoningEffort }) },
|
|
117
|
+
...(facts.descriptor.toolFilter === undefined ? {} : { toolFilter: facts.descriptor.toolFilter }),
|
|
118
|
+
...(facts.active === undefined ? {} : { active: facts.active }), provenFields, limitations });
|
|
119
|
+
}
|
|
120
|
+
/** Capture evidence must agree with the child's establishing descriptor, not current parent routing. */
|
|
121
|
+
export function assertNativeChildCapture(capture, facts) {
|
|
122
|
+
const route = capture.invocation.initialRoute, descriptor = facts.descriptor;
|
|
123
|
+
if (capture.childSessionId !== facts.childSessionId || capture.parentSessionId !== facts.parentSessionId || capture.role !== facts.role
|
|
124
|
+
|| facts.depth > capture.authorityCeiling.maxDepth || descriptor.agentProvider !== route.provider || descriptor.agentModel !== route.model
|
|
125
|
+
|| descriptor.agentReasoningEffort !== route.reasoningEffort)
|
|
126
|
+
unauthorized();
|
|
127
|
+
const ceiling = capture.authorityCeiling.toolFilter, native = descriptor.toolFilter;
|
|
128
|
+
if (native?.allow !== undefined && (ceiling?.allow === undefined || ceiling.allow.some(name => !native.allow.includes(name))))
|
|
129
|
+
unauthorized();
|
|
130
|
+
if (native?.deny?.some(name => ceiling?.allow?.includes(name) || ceiling?.allow === undefined && !ceiling?.deny?.includes(name)))
|
|
131
|
+
unauthorized();
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=native-child-evidence.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import { PiAiAdapter, Config } from "@deepseek-ai/dsh-llm-pi-ai";
|
|
3
|
+
import type { Options, PiAiAdapterOptions } from "@deepseek-ai/dsh-llm-pi-ai";
|
|
4
|
+
import type { LlmAdapter } from "@deepseek-ai/dsh-llm";
|
|
5
|
+
import type { DsmmLlmGeneration } from "./host-llm.js";
|
|
6
|
+
import type { DsmmLlmRouteResolver } from "./role-llm.js";
|
|
7
|
+
export interface DsmmPiAiOwnerOptions {
|
|
8
|
+
readonly config: Options;
|
|
9
|
+
readonly settingsNamespace: string;
|
|
10
|
+
readonly auth: PiAiAdapterOptions["auth"];
|
|
11
|
+
/** Called only at dispatch. An absent named credential fails; no ambient lookup is used. */
|
|
12
|
+
readonly resolveApiKey: (provider: string, reference: string, signal?: AbortSignal) => Promise<string | undefined>;
|
|
13
|
+
}
|
|
14
|
+
export interface DsmmPiAiProviderOwner extends DsmmLlmRouteResolver {
|
|
15
|
+
readonly stockAdapter: PiAiAdapter;
|
|
16
|
+
readonly providers: readonly string[];
|
|
17
|
+
generation(provider: string): DsmmLlmGeneration;
|
|
18
|
+
}
|
|
19
|
+
declare module "@deepseek-ai/cordis" {
|
|
20
|
+
interface Context {
|
|
21
|
+
dsmmLlmProviderOwner: DsmmPiAiProviderOwner;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export interface DsmmPiAiProviderPlugin {
|
|
25
|
+
readonly name: "dsmm-llm-provider-owner";
|
|
26
|
+
readonly inject: string[];
|
|
27
|
+
readonly Config: typeof Config;
|
|
28
|
+
apply(ctx: Context, config: ReturnType<typeof Config>): void;
|
|
29
|
+
}
|
|
30
|
+
export declare function createDsmmPiAiProviderPlugin(options: DsmmPiAiOwnerOptions, ready: (owner: DsmmPiAiProviderOwner) => void): DsmmPiAiProviderPlugin;
|
|
31
|
+
/** Build the raw executor from declared profiles; borrowed registrations remain native-owned. */
|
|
32
|
+
export declare function createDsmmPiAiProviderOwner(ctx: Context, options: DsmmPiAiOwnerOptions, borrowed?: {
|
|
33
|
+
readonly signal: AbortSignal;
|
|
34
|
+
readonly adapter: LlmAdapter;
|
|
35
|
+
assertCurrent(): void;
|
|
36
|
+
}): DsmmPiAiProviderOwner;
|
|
37
|
+
//# sourceMappingURL=native-pi-ai-wire.d.ts.map
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
|
+
import { brandString } from "@deepseek-ai/dsh-brand";
|
|
3
|
+
import { PiAiAdapter, Config } from "@deepseek-ai/dsh-llm-pi-ai";
|
|
4
|
+
import { createModels, createProvider, envApiKeyAuth, hasApi } from "@earendil-works/pi-ai";
|
|
5
|
+
import { openAICompletionsApi } from "@earendil-works/pi-ai/api/openai-completions.lazy";
|
|
6
|
+
import { buildBaseOptions } from "@earendil-works/pi-ai/api/simple-options";
|
|
7
|
+
import { LlmError, ReasoningEffortId, assertUsableApiKey, attributionHeaders, freezeMessage, resolveImageAttachmentAccess, resolveRetryPolicy } from "@deepseek-ai/dsh-llm";
|
|
8
|
+
import { snapshotDsmmCall } from "./host-llm.js";
|
|
9
|
+
import { DsmmMissingProviderError, modelRouteToCall } from "./role-llm.js";
|
|
10
|
+
import { normalizeModelRouteJson } from "./route-json.js";
|
|
11
|
+
function normalizeDeclaredProfiles(config) {
|
|
12
|
+
const profiles = new Map();
|
|
13
|
+
for (const [provider, profile] of Object.entries(Config(config).providers.get())) {
|
|
14
|
+
if (profile.api !== "openai-completions" || !profile.baseURL || !profile.apiKeyEnv || !profile.models?.length
|
|
15
|
+
|| profile.modelOverrides !== undefined && Object.keys(profile.modelOverrides).length > 0) {
|
|
16
|
+
throw new LlmError("Raw execution requires an explicit completions endpoint, credential reference and finite model list without catalog overrides", "UNSUPPORTED_ROUTE_PARAMETERS");
|
|
17
|
+
}
|
|
18
|
+
const endpoint = new URL(profile.baseURL);
|
|
19
|
+
if (!["http:", "https:"].includes(endpoint.protocol) || endpoint.username || endpoint.password)
|
|
20
|
+
throw new LlmError("Invalid provider endpoint", "INVALID_CONFIG");
|
|
21
|
+
const seen = new Set();
|
|
22
|
+
const models = profile.models.map(entry => {
|
|
23
|
+
if (!entry.id || seen.has(entry.id))
|
|
24
|
+
throw new LlmError("Model identities must be nonempty and unique", "INVALID_CONFIG");
|
|
25
|
+
seen.add(entry.id);
|
|
26
|
+
const contextWindow = entry.contextWindow ?? profile.defaultContextWindow;
|
|
27
|
+
const maxTokens = entry.maxTokens ?? profile.defaultMaxTokens;
|
|
28
|
+
const input = [...(entry.input?.length ? entry.input : profile.defaultInput)];
|
|
29
|
+
if (input.length === 0)
|
|
30
|
+
throw new LlmError("Declared models must have input modalities", "INVALID_CONFIG");
|
|
31
|
+
if (!Number.isSafeInteger(contextWindow) || contextWindow <= 0 || !Number.isSafeInteger(maxTokens) || maxTokens <= 0)
|
|
32
|
+
throw new LlmError("Model capacities must be positive integers", "INVALID_CONFIG");
|
|
33
|
+
return { id: entry.id, name: entry.name ?? entry.id, provider, api: "openai-completions", baseUrl: profile.baseURL,
|
|
34
|
+
reasoning: false, input, contextWindow: contextWindow, maxTokens: maxTokens,
|
|
35
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
36
|
+
compat: { ...profile.compat, ...entry.compat } };
|
|
37
|
+
});
|
|
38
|
+
const piProvider = createProvider({ id: provider, name: profile.displayName ?? provider, baseUrl: profile.baseURL,
|
|
39
|
+
auth: { apiKey: envApiKeyAuth(provider, []) }, models, api: openAICompletionsApi() });
|
|
40
|
+
profiles.set(provider, {
|
|
41
|
+
provider, displayName: profile.displayName ?? provider, api: profile.api, baseURL: profile.baseURL,
|
|
42
|
+
...(profile.headers === undefined ? {} : { headers: { ...profile.headers } }),
|
|
43
|
+
...(profile.reasoning === undefined ? {} : { reasoning: profile.reasoning }),
|
|
44
|
+
...(profile.thinkingBudgets === undefined ? {} : { thinkingBudgets: { ...profile.thinkingBudgets } }),
|
|
45
|
+
...(profile.cacheRetention === undefined ? {} : { cacheRetention: profile.cacheRetention }),
|
|
46
|
+
...(profile.transport === undefined ? {} : { transport: profile.transport }),
|
|
47
|
+
...(profile.timeoutMs === undefined ? {} : { timeoutMs: profile.timeoutMs }),
|
|
48
|
+
...(profile.websocketConnectTimeoutMs === undefined ? {} : { websocketConnectTimeoutMs: profile.websocketConnectTimeoutMs }),
|
|
49
|
+
apiKeyEnv: brandString(profile.apiKeyEnv),
|
|
50
|
+
streamIdleTimeoutMs: profile.streamIdleTimeoutMs, maxRequestImageBytes: profile.maxRequestImageBytes,
|
|
51
|
+
requestImagePixelBudget: profile.requestImagePixelBudget, requestImageMaxBytes: profile.requestImageMaxBytes,
|
|
52
|
+
retryPolicy: resolveRetryPolicy(profile.retryPolicy?.mode === "normal" ? { ...profile.retryPolicy,
|
|
53
|
+
retryableCodes: profile.retryPolicy.retryableCodes === undefined ? undefined : [...profile.retryPolicy.retryableCodes] } : profile.retryPolicy, `dsmm.providers.${provider}.retryPolicy`), piProvider, modelErrors: new Map(),
|
|
54
|
+
configuredMaxTokens: new Map(profile.models.flatMap(model => model.maxTokens === undefined ? [] : [[model.id, model.maxTokens]])),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (profiles.size === 0)
|
|
58
|
+
throw new LlmError("DSMM provider owner must own at least one declared route", "INVALID_CONFIG");
|
|
59
|
+
return profiles;
|
|
60
|
+
}
|
|
61
|
+
function protectedHeaders(headers) {
|
|
62
|
+
const result = new Headers();
|
|
63
|
+
for (const [key, value] of Object.entries(headers))
|
|
64
|
+
if (value !== null)
|
|
65
|
+
result.set(key, value);
|
|
66
|
+
for (const [key, value] of Object.entries(attributionHeaders()))
|
|
67
|
+
result.set(key, value);
|
|
68
|
+
return Object.fromEntries(result);
|
|
69
|
+
}
|
|
70
|
+
/** Public provider composition preserves the SDK's native content/replay/stream translator. */
|
|
71
|
+
function rawProvider(provider, generation, request, assertCurrent) {
|
|
72
|
+
return {
|
|
73
|
+
...provider,
|
|
74
|
+
streamSimple(model, context, options) {
|
|
75
|
+
const exact = generation.getModel(model.provider, model.id);
|
|
76
|
+
if (exact === undefined || !hasApi(exact, "openai-completions"))
|
|
77
|
+
throw new LlmError("Raw generation has no exact completions model", "UNKNOWN_MODEL");
|
|
78
|
+
const tokenField = ["max_tokens", "max_completion_tokens", "max_output_tokens"].find(key => Object.hasOwn(request.customParameters ?? {}, key));
|
|
79
|
+
const rawBudget = tokenField === undefined ? undefined : request.customParameters?.[tokenField];
|
|
80
|
+
if (rawBudget !== undefined && (typeof rawBudget !== "number" || options?.maxTokens !== undefined && rawBudget > options.maxTokens))
|
|
81
|
+
throw new LlmError("Raw token budget conflicts with the Host request budget", "INVALID_REQUEST");
|
|
82
|
+
const baseOptions = buildBaseOptions(exact, context, { ...options, ...(typeof rawBudget === "number" ? { maxTokens: rawBudget } : {}) });
|
|
83
|
+
if (rawBudget !== undefined && baseOptions.maxTokens !== rawBudget)
|
|
84
|
+
throw new LlmError("Raw token budget exceeds the native context budget", "INVALID_REQUEST");
|
|
85
|
+
const wireOptions = {
|
|
86
|
+
...baseOptions,
|
|
87
|
+
onPayload(payload) {
|
|
88
|
+
assertCurrent();
|
|
89
|
+
request.signal?.throwIfAborted();
|
|
90
|
+
if (payload === null || typeof payload !== "object" || Array.isArray(payload))
|
|
91
|
+
throw new LlmError("Provider did not build an object payload", "INVALID_REQUEST");
|
|
92
|
+
if (tokenField !== undefined && !Object.hasOwn(payload, tokenField))
|
|
93
|
+
throw new LlmError("Raw token field does not match the declared model protocol", "INVALID_REQUEST");
|
|
94
|
+
const body = { ...payload, ...request.customParameters };
|
|
95
|
+
if (request.reasoningEffort !== undefined)
|
|
96
|
+
Reflect.set(body, "reasoning_effort", request.reasoningEffort);
|
|
97
|
+
if (request.stop !== undefined)
|
|
98
|
+
Reflect.set(body, "stop", [...request.stop]);
|
|
99
|
+
return body;
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
return generation.stream(exact, context, { ...wireOptions, transformHeaders: protectedHeaders });
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export function createDsmmPiAiProviderPlugin(options, ready) {
|
|
107
|
+
return { name: "dsmm-llm-provider-owner", inject: ["llm", "settings"], Config,
|
|
108
|
+
apply(ctx, config) {
|
|
109
|
+
const expected = Config(options.config).providers.get();
|
|
110
|
+
if (!isDeepStrictEqual(config.providers.get(), expected))
|
|
111
|
+
throw new LlmError("Cold provider entry differs from the Host-owned declaration", "INVALID_CONFIG");
|
|
112
|
+
ctx.effect(() => ctx.settings.configure({ auto: false }, ctx.fiber));
|
|
113
|
+
ctx.on("internal/config", function (_raw, next) {
|
|
114
|
+
const candidate = next();
|
|
115
|
+
if (this === ctx.fiber && !isDeepStrictEqual(Config(candidate).providers.get(), expected))
|
|
116
|
+
throw new LlmError("Provider ownership changes require a cold Host restart", "INVALID_CONFIG");
|
|
117
|
+
return candidate;
|
|
118
|
+
});
|
|
119
|
+
const owner = createDsmmPiAiProviderOwner(ctx, options);
|
|
120
|
+
ctx.provide("dsmmLlmRoutes", owner);
|
|
121
|
+
ready(owner);
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/** Build the raw executor from declared profiles; borrowed registrations remain native-owned. */
|
|
126
|
+
export function createDsmmPiAiProviderOwner(ctx, options, borrowed) {
|
|
127
|
+
const profiles = normalizeDeclaredProfiles(options.config);
|
|
128
|
+
const identity = Object.freeze({});
|
|
129
|
+
const life = new AbortController();
|
|
130
|
+
const assertCurrent = () => {
|
|
131
|
+
life.signal.throwIfAborted();
|
|
132
|
+
if (borrowed !== undefined) {
|
|
133
|
+
borrowed.signal.throwIfAborted();
|
|
134
|
+
borrowed.assertCurrent();
|
|
135
|
+
}
|
|
136
|
+
else if (ctx.get("dsmmLlmProviderOwner") !== owner)
|
|
137
|
+
throw new LlmError("Provider generation no longer owns its Host service", "INVALID_PREPARED_CALL");
|
|
138
|
+
};
|
|
139
|
+
if (borrowed === undefined)
|
|
140
|
+
ctx.effect(() => () => life.abort(new LlmError("Provider owner retired", "INVALID_PREPARED_CALL")));
|
|
141
|
+
const resolveNamedKey = async (provider, profile, signal) => {
|
|
142
|
+
signal.throwIfAborted();
|
|
143
|
+
assertCurrent();
|
|
144
|
+
if (profile.apiKeyEnv === undefined)
|
|
145
|
+
throw new LlmError("Provider credential reference is required", "MISSING_CREDENTIAL");
|
|
146
|
+
const key = await options.resolveApiKey(provider, profile.apiKeyEnv, signal);
|
|
147
|
+
signal.throwIfAborted();
|
|
148
|
+
assertCurrent();
|
|
149
|
+
if (key === undefined)
|
|
150
|
+
throw new LlmError("Provider credential is unavailable", "MISSING_CREDENTIAL");
|
|
151
|
+
return assertUsableApiKey(key, "dsmm", profile.apiKeyEnv);
|
|
152
|
+
};
|
|
153
|
+
const resolveApiKey = (provider, profile) => resolveNamedKey(provider, profile, life.signal);
|
|
154
|
+
const adapterOptions = { profiles: () => profiles, resolveApiKey, auth: options.auth,
|
|
155
|
+
resolveAttachments: () => ctx.get("attachments"),
|
|
156
|
+
resolveImageAccess: (attachments, ref) => resolveImageAttachmentAccess(attachments, path => ctx.get("fs")?.processPathFromHostPath(path), ref),
|
|
157
|
+
onReplayDegrade: () => ctx.logger.warn("DSMM provider replay degraded to native content"),
|
|
158
|
+
};
|
|
159
|
+
const stockStream = (request, preparationSignal) => {
|
|
160
|
+
assertCurrent();
|
|
161
|
+
const signal = AbortSignal.any([life.signal, ...request.signal === undefined ? [] : [request.signal], ...preparationSignal === undefined ? [] : [preparationSignal]]);
|
|
162
|
+
return new PiAiAdapter({ ...adapterOptions, resolveApiKey: (provider, profile) => resolveNamedKey(provider, profile, signal) }).stream(request);
|
|
163
|
+
};
|
|
164
|
+
const stockAdapter = new class extends PiAiAdapter {
|
|
165
|
+
stream(request) { return stockStream(request); }
|
|
166
|
+
async prepareCall(provider, model, signal) {
|
|
167
|
+
const prepared = await super.prepareCall(provider, model, signal);
|
|
168
|
+
signal?.throwIfAborted();
|
|
169
|
+
assertCurrent();
|
|
170
|
+
return { ...prepared, stream: request => stockStream(request, signal) };
|
|
171
|
+
}
|
|
172
|
+
}(adapterOptions);
|
|
173
|
+
const providers = Object.freeze([...profiles.keys()]);
|
|
174
|
+
if (borrowed === undefined) {
|
|
175
|
+
ctx.llm.registerAdapter([...providers], stockAdapter);
|
|
176
|
+
ctx.llm.registerConfigurableProviders([...profiles.values()].map(profile => ({ provider: profile.provider, displayName: profile.displayName,
|
|
177
|
+
settingsNs: options.settingsNamespace, settingsPath: ["providers", profile.provider], declared: true })));
|
|
178
|
+
ctx.llm.registerModelDiscovery(options.settingsNamespace, async (request, signal) => {
|
|
179
|
+
signal?.throwIfAborted();
|
|
180
|
+
if (request.provider === undefined || !profiles.has(request.provider))
|
|
181
|
+
throw new LlmError("Discovery requires a route owned by this Host", "NO_ADAPTER");
|
|
182
|
+
return (await stockAdapter.listModels(request.provider)).map(model => ({ id: model.id, name: model.name, inputModalities: model.inputModalities }));
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
const models = createModels(options.auth);
|
|
186
|
+
for (const profile of profiles.values())
|
|
187
|
+
models.setProvider(profile.piProvider);
|
|
188
|
+
const owner = Object.freeze({ stockAdapter, providers,
|
|
189
|
+
async resolveRoute(input, signal) {
|
|
190
|
+
const route = normalizeModelRouteJson(input);
|
|
191
|
+
signal?.throwIfAborted();
|
|
192
|
+
assertCurrent();
|
|
193
|
+
const call = snapshotDsmmCall(modelRouteToCall(route));
|
|
194
|
+
if (profiles.has(route.provider)) {
|
|
195
|
+
if (models.getModel(route.provider, route.model) === undefined)
|
|
196
|
+
throw new LlmError("Provider has no exact declared model", "UNKNOWN_MODEL");
|
|
197
|
+
await stockAdapter.resolveModel(route.provider, route.model, signal);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
if (!ctx.llm.listProviders().some(provider => provider.id === route.provider))
|
|
201
|
+
throw new DsmmMissingProviderError();
|
|
202
|
+
await ctx.llm.resolveCallConfig(call, signal);
|
|
203
|
+
if (call.customParameters !== undefined)
|
|
204
|
+
throw new LlmError("Raw route parameters require their declared Host provider owner", "UNSUPPORTED_ROUTE_PARAMETERS");
|
|
205
|
+
}
|
|
206
|
+
signal?.throwIfAborted();
|
|
207
|
+
assertCurrent();
|
|
208
|
+
return route;
|
|
209
|
+
},
|
|
210
|
+
generation(provider) {
|
|
211
|
+
const profile = profiles.get(provider);
|
|
212
|
+
if (profile === undefined)
|
|
213
|
+
throw new LlmError("Provider is not owned by this Host", "NO_ADAPTER");
|
|
214
|
+
return Object.freeze({ identity, signal: borrowed === undefined ? life.signal : AbortSignal.any([life.signal, borrowed.signal]), retryPolicy: profile.retryPolicy, assertCurrent,
|
|
215
|
+
...(profile.reasoning === undefined ? {} : { defaultReasoningEffort: ReasoningEffortId(profile.reasoning) }),
|
|
216
|
+
async prepareCall(selectedProvider, model, signal, assertAdmission) {
|
|
217
|
+
const assertCall = () => { signal.throwIfAborted(); assertCurrent(); assertAdmission?.(); };
|
|
218
|
+
assertCall();
|
|
219
|
+
if (selectedProvider !== provider || models.getModel(provider, model) === undefined)
|
|
220
|
+
throw new LlmError("Provider has no exact declared model", "UNKNOWN_MODEL");
|
|
221
|
+
const metadata = await (borrowed?.adapter ?? stockAdapter).resolveModel(provider, model, signal);
|
|
222
|
+
assertCall();
|
|
223
|
+
return { model: metadata, stream(request) {
|
|
224
|
+
assertCall();
|
|
225
|
+
request.signal?.throwIfAborted();
|
|
226
|
+
const extended = request;
|
|
227
|
+
const checked = snapshotDsmmCall({ provider: request.provider, model: request.model,
|
|
228
|
+
...(request.reasoningEffort === undefined ? {} : { reasoningEffort: request.reasoningEffort }),
|
|
229
|
+
...(request.temperature === undefined ? {} : { temperature: request.temperature }),
|
|
230
|
+
...(request.maxTokens === undefined ? {} : { maxTokens: request.maxTokens }),
|
|
231
|
+
...(request.stop === undefined ? {} : { stop: request.stop }),
|
|
232
|
+
...(extended.customParameters === undefined ? {} : { customParameters: extended.customParameters }),
|
|
233
|
+
});
|
|
234
|
+
const projectedProfiles = new Map([...profiles].map(([id, item]) => [id, { ...item, reasoning: undefined,
|
|
235
|
+
piProvider: rawProvider(item.piProvider, models, { ...request, ...checked }, assertCall) }]));
|
|
236
|
+
const credentialSignal = request.signal === undefined ? life.signal : AbortSignal.any([life.signal, request.signal]);
|
|
237
|
+
const rawAdapter = new PiAiAdapter({ ...adapterOptions, profiles: () => projectedProfiles,
|
|
238
|
+
resolveApiKey: async (selectedProvider, selectedProfile) => {
|
|
239
|
+
assertCall();
|
|
240
|
+
const key = await resolveNamedKey(selectedProvider, selectedProfile, credentialSignal);
|
|
241
|
+
assertCall();
|
|
242
|
+
return key;
|
|
243
|
+
} });
|
|
244
|
+
const { reasoningEffort: _effort, stop: _stop, ...native } = request;
|
|
245
|
+
const messages = native.messages.map(message => {
|
|
246
|
+
if (message.role !== "assistant" || message.source.replayState === undefined || profiles.has(message.source.provider))
|
|
247
|
+
return message;
|
|
248
|
+
const { replayState: _replay, ...source } = message.source;
|
|
249
|
+
return freezeMessage({ ...message, source });
|
|
250
|
+
});
|
|
251
|
+
return rawAdapter.stream({ ...native, messages });
|
|
252
|
+
} };
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
if (borrowed === undefined)
|
|
258
|
+
ctx.provide("dsmmLlmProviderOwner", owner);
|
|
259
|
+
return owner;
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=native-pi-ai-wire.js.map
|
package/lib/native-scope.js
CHANGED
|
@@ -6,7 +6,7 @@ const sdk = createRequire(require.resolve("@deepseek-ai/dsh-agent-preset-registr
|
|
|
6
6
|
const scope = sdk("@deepseek-ai/dsh-scope");
|
|
7
7
|
export const { scopeOf, scopeParentOf } = scope;
|
|
8
8
|
export function nativeAgentContext(agent) {
|
|
9
|
-
if (!(agent.ctx
|
|
9
|
+
if (!Context.is(agent.ctx) || scopeOf(agent.ctx) !== agent) {
|
|
10
10
|
throw new Error("dsmm skills require the exact native Agent scope, never a shared preset/global scope");
|
|
11
11
|
}
|
|
12
12
|
return agent.ctx;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import * as Native from "@deepseek-ai/dsh-tool-bash";
|
|
3
|
+
export { Config, name } from "@deepseek-ai/dsh-tool-bash";
|
|
4
|
+
export declare const inject: string[];
|
|
5
|
+
export declare function apply(ctx: Context, config: Native.Config): void;
|
|
6
|
+
//# sourceMappingURL=permission-bash.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as Native from "@deepseek-ai/dsh-tool-bash";
|
|
2
|
+
export { Config, name } from "@deepseek-ai/dsh-tool-bash";
|
|
3
|
+
export const inject = [...Native.inject, "dsmmPermissionController"];
|
|
4
|
+
export function apply(ctx, config) {
|
|
5
|
+
Native.apply(ctx.dsmmPermissionController.shellScope(ctx, "bash"), config);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=permission-bash.js.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
|
+
import type { PreToolDecision, ToolDefinition, ToolExecution, ToolRunContext } from "@deepseek-ai/dsh-tools";
|
|
4
|
+
import type { RoleRunHolder } from "./role-runs.js";
|
|
5
|
+
import type { NativeCommandEntry } from "./permission-settings.js";
|
|
6
|
+
import type { NativePermissionMode } from "./permission-native-access.js";
|
|
7
|
+
export { PermissionRefusal } from "./permission-errors.js";
|
|
8
|
+
export type PermissionRunHolder = Pick<RoleRunHolder, "state" | "owner" | "invocation" | "holderSignal" | "drained">;
|
|
9
|
+
export interface PermissionExecutionAuthority {
|
|
10
|
+
readonly agent: Agent;
|
|
11
|
+
readonly root: Agent;
|
|
12
|
+
readonly realm: object;
|
|
13
|
+
readonly admissionRevision: string;
|
|
14
|
+
readonly permissionRevision: string;
|
|
15
|
+
readonly owner: object;
|
|
16
|
+
readonly ownerGeneration: string | number;
|
|
17
|
+
readonly signal: AbortSignal;
|
|
18
|
+
readonly run?: PermissionRunHolder;
|
|
19
|
+
}
|
|
20
|
+
export type PermissionRootApprovalAuthority = Pick<PermissionExecutionAuthority, "root" | "realm" | "admissionRevision" | "permissionRevision" | "owner" | "ownerGeneration" | "signal">;
|
|
21
|
+
export interface PermissionExecutionIntegrity {
|
|
22
|
+
readonly signal?: AbortSignal;
|
|
23
|
+
assertCurrent(): void;
|
|
24
|
+
}
|
|
25
|
+
export interface PermissionControlCollaborators {
|
|
26
|
+
current(exec: Readonly<ToolExecution>): PermissionExecutionAuthority;
|
|
27
|
+
rootCurrent?(root: Agent, exec: Readonly<ToolExecution>): PermissionRootApprovalAuthority;
|
|
28
|
+
assertCurrent(authority: PermissionExecutionAuthority, exec: Readonly<ToolExecution>): void;
|
|
29
|
+
/** Physical ownership and real scope lifetime only; never permission/admission epochs. */
|
|
30
|
+
captureIntegrity?(exec: Readonly<ToolExecution>): PermissionExecutionIntegrity;
|
|
31
|
+
}
|
|
32
|
+
export interface PermissionRegistration {
|
|
33
|
+
readonly definition: ToolDefinition;
|
|
34
|
+
readonly registered: ToolDefinition;
|
|
35
|
+
readonly body: ToolDefinition["execute"];
|
|
36
|
+
readonly identity: object;
|
|
37
|
+
readonly signal?: AbortSignal;
|
|
38
|
+
assertCurrent?(execution: Readonly<ToolExecution>): void;
|
|
39
|
+
approval(): Context["approval"] | undefined;
|
|
40
|
+
standingMode(execution: Readonly<ToolExecution>): string | undefined;
|
|
41
|
+
unchanged(): boolean;
|
|
42
|
+
active: boolean;
|
|
43
|
+
}
|
|
44
|
+
export declare function permissionOriginal(value: object): object;
|
|
45
|
+
type Request = Parameters<Context["approval"]["request"]>[0];
|
|
46
|
+
type Outcome = Awaited<ReturnType<Context["approval"]["request"]>>;
|
|
47
|
+
export declare function isSandboxWidening(requested: NativeCommandEntry["sandboxMode"], standing: string | undefined): boolean;
|
|
48
|
+
/** Permission admission precedes native approval; subsequent checks enforce execution integrity only. */
|
|
49
|
+
export declare class PermissionControl {
|
|
50
|
+
private readonly ctx;
|
|
51
|
+
private readonly collaborators;
|
|
52
|
+
private readonly lifetime;
|
|
53
|
+
private readonly bindings;
|
|
54
|
+
private readonly requests;
|
|
55
|
+
private readonly execution;
|
|
56
|
+
constructor(ctx: Context, collaborators: PermissionControlCollaborators);
|
|
57
|
+
compose(exec: Readonly<ToolExecution>, registration: PermissionRegistration, entry: NativeCommandEntry | undefined, action: "inherit" | "allow" | "ask", next: () => Promise<PreToolDecision>, cwd: string): Promise<PreToolDecision>;
|
|
58
|
+
private checkIntegrity;
|
|
59
|
+
guard(exec: Readonly<ToolExecution>): string | undefined;
|
|
60
|
+
answerer(request: Request, next: () => Promise<Outcome>): Promise<Outcome>;
|
|
61
|
+
run<T>(exec: ToolRunContext, args: unknown, registration: PermissionRegistration, body: (signal: AbortSignal) => Promise<T>): Promise<T>;
|
|
62
|
+
private request;
|
|
63
|
+
/** Scoped original native body; a target fact is consumed only for its exact official request. */
|
|
64
|
+
nativeApproval(request: Request, service: Context["approval"]): Promise<Outcome>;
|
|
65
|
+
approvedTarget(exec: Readonly<ToolExecution>): NativePermissionMode | undefined;
|
|
66
|
+
sandboxMode(): NativePermissionMode | undefined;
|
|
67
|
+
finish(exec: Readonly<ToolExecution>): void;
|
|
68
|
+
revokePolicy(): void;
|
|
69
|
+
revokeRegistration(registration: PermissionRegistration): void;
|
|
70
|
+
revokeAgent(agent: Agent): void;
|
|
71
|
+
retire(): void;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=permission-control.d.ts.map
|