@dsmm/dsmm 0.2.2 → 0.3.1
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 +26 -42
- package/cordis.patch.yml +1 -0
- package/docs/agent-presets.md +26 -14
- package/docs/compatibility.md +20 -79
- package/docs/deferred-native-approval-risk.md +8 -12
- package/docs/design.md +25 -254
- package/docs/lsp.md +2 -2
- package/docs/migration-from-ocmm.md +38 -51
- package/docs/model-routing.md +21 -21
- package/docs/native-permissions.md +17 -7
- package/docs/profiles.md +13 -9
- package/docs/releasing.md +34 -240
- package/docs/roadmap.md +23 -254
- package/docs/runtime-recovery.md +29 -91
- package/docs/safety-guards.md +19 -16
- package/docs/settings-status.md +23 -11
- package/docs/skill-sync.md +17 -17
- package/docs/web-fetch-fakeip.md +82 -0
- package/lib/child-capture.d.ts +16 -2
- package/lib/child-capture.js +29 -10
- package/lib/client/ChildrenPanel.d.ts +1 -4
- package/lib/client/ChildrenPanel.js +4 -16
- package/lib/client/DeploymentFields.d.ts +28 -0
- package/lib/client/DeploymentFields.js +68 -0
- package/lib/client/DeploymentPage.d.ts +17 -5
- package/lib/client/DeploymentPage.js +79 -112
- package/lib/client/NativeCommandEntries.d.ts +17 -0
- package/lib/client/NativeCommandEntries.js +68 -0
- package/lib/client/PermissionsPanel.d.ts +1 -1
- package/lib/client/PermissionsPanel.js +8 -8
- package/lib/client/ProfilesSection.js +7 -5
- package/lib/client/RoleToolView-data.d.ts +35 -0
- package/lib/client/RoleToolView-data.js +52 -0
- package/lib/client/RoleToolView-locales.d.ts +36 -0
- package/lib/client/RoleToolView-locales.js +20 -0
- package/lib/client/RoleToolView.d.ts +10 -0
- package/lib/client/RoleToolView.js +47 -0
- package/lib/client/SessionProfiles.js +39 -15
- package/lib/client/children-controller.d.ts +2 -8
- package/lib/client/children-controller.js +1 -26
- package/lib/client/children-locales.d.ts +26 -51
- package/lib/client/children-locales.js +8 -12
- package/lib/client/configuration-display.d.ts +5 -0
- package/lib/client/configuration-display.js +11 -0
- package/lib/client/controller.d.ts +1 -0
- package/lib/client/controller.js +20 -13
- package/lib/client/deployment-controller.d.ts +13 -1
- package/lib/client/deployment-controller.js +85 -25
- package/lib/client/deployment-data.d.ts +1 -0
- package/lib/client/deployment-data.js +4 -1
- package/lib/client/deployment-locales.d.ts +43 -0
- package/lib/client/deployment-locales.js +35 -9
- package/lib/client/deployment-modules.d.ts +9 -0
- package/lib/client/deployment-modules.js +24 -0
- package/lib/client/deployment-workspace.d.ts +48 -0
- package/lib/client/deployment-workspace.js +123 -0
- package/lib/client/index.js +11 -74
- package/lib/client/locales.d.ts +7 -0
- package/lib/client/locales.js +12 -6
- package/lib/client/permission-controller.d.ts +1 -0
- package/lib/client/permission-controller.js +3 -2
- package/lib/client/permission-locales.d.ts +25 -0
- package/lib/client/permission-locales.js +24 -4
- package/lib/client/session-labels.js +4 -3
- package/lib/client/styles.d.ts +1 -1
- package/lib/client/styles.js +9 -8
- package/lib/client.js +2716 -2364
- package/lib/commands.js +2 -0
- package/lib/config-file-store.d.ts +3 -0
- package/lib/config-file-store.js +4 -2
- package/lib/config-revision.d.ts +5 -0
- package/lib/config-revision.js +11 -0
- package/lib/core-permission-authority.js +11 -41
- package/lib/deployment-config.d.ts +9 -2
- package/lib/deployment-config.js +35 -8
- package/lib/deployment-permission-rules.js +19 -7
- package/lib/dsh-types.d.ts +1 -1
- package/lib/host-llm-startup.js +3 -3
- package/lib/host-llm.d.ts +9 -3
- package/lib/host-llm.js +48 -8
- package/lib/index.d.ts +17 -21
- package/lib/index.js +131 -430
- package/lib/lifetime.d.ts +4 -0
- package/lib/lifetime.js +22 -0
- package/lib/live-pi-ai-owner.d.ts +1 -0
- package/lib/live-pi-ai-owner.js +8 -4
- package/lib/mode.d.ts +3 -2
- package/lib/mode.js +28 -41
- package/lib/model-routing.d.ts +2 -8
- package/lib/model-routing.js +59 -175
- package/lib/native-admission.d.ts +56 -0
- package/lib/native-admission.js +313 -0
- package/lib/native-pi-ai-wire.d.ts +3 -1
- package/lib/native-pi-ai-wire.js +47 -13
- package/lib/permission-control.d.ts +0 -3
- package/lib/permission-rpc.js +3 -3
- package/lib/preset-registry.js +3 -2
- package/lib/preset-skills.d.ts +3 -12
- package/lib/preset-skills.js +28 -58
- package/lib/profile-diagnostics.d.ts +1 -1
- package/lib/profile-diagnostics.js +2 -2
- package/lib/profile-remote.js +61 -22
- package/lib/profile-rpc.d.ts +4 -3
- package/lib/profile-rpc.js +39 -41
- package/lib/profile-runtime.d.ts +31 -74
- package/lib/profile-runtime.js +224 -639
- package/lib/profile-store.d.ts +18 -6
- package/lib/profile-store.js +106 -64
- package/lib/profile-types.d.ts +18 -4
- package/lib/profiles.d.ts +3 -1
- package/lib/profiles.js +9 -7
- package/lib/prompt-content.d.ts +1 -0
- package/lib/prompt-content.js +4 -1
- package/lib/prompts.d.ts +2 -12
- package/lib/prompts.js +11 -66
- package/lib/role-control-remote.d.ts +1 -4
- package/lib/role-control-remote.js +8 -36
- package/lib/role-control-rpc.d.ts +10 -36
- package/lib/role-control-rpc.js +112 -265
- package/lib/role-control-types.d.ts +3 -26
- package/lib/role-control-types.js +3 -4
- package/lib/role-identity.d.ts +5 -0
- package/lib/role-identity.js +10 -0
- package/lib/role-invocation.d.ts +2 -2
- package/lib/role-llm-runtime.js +5 -11
- package/lib/role-policy.d.ts +19 -53
- package/lib/role-policy.js +136 -525
- package/lib/role-providers.d.ts +5 -8
- package/lib/role-providers.js +20 -126
- package/lib/role-routing.d.ts +1 -3
- package/lib/role-routing.js +24 -34
- package/lib/role-subagents.d.ts +5 -14
- package/lib/role-subagents.js +149 -97
- package/lib/runtime-integration.d.ts +5 -109
- package/lib/runtime-integration.js +11 -779
- package/lib/session-metadata.d.ts +13 -12
- package/lib/session-metadata.js +6 -31
- package/lib/session-scope.js +6 -2
- package/lib/settings.d.ts +5 -18
- package/lib/settings.js +19 -43
- package/lib/state.d.ts +3 -2
- package/lib/state.js +26 -10
- package/lib/status.d.ts +1 -9
- package/lib/status.js +3 -55
- package/lib/web-fetch-address-policy.d.ts +24 -0
- package/lib/web-fetch-address-policy.js +189 -0
- package/lib/web-fetch-fakeip.d.ts +25 -0
- package/lib/web-fetch-fakeip.js +107 -0
- package/package.json +133 -113
- package/docs/research/deepseek-v4-pro.md +0 -74
- package/docs/research/oh-dsh.md +0 -96
- package/lib/child-admission.d.ts +0 -42
- package/lib/child-admission.js +0 -162
- package/lib/delivery-authority.d.ts +0 -68
- package/lib/delivery-authority.js +0 -260
- package/lib/legacy-child-policy.d.ts +0 -51
- package/lib/legacy-child-policy.js +0 -123
- package/lib/legacy-read-composition.d.ts +0 -20
- package/lib/legacy-read-composition.js +0 -144
- package/lib/legacy-read-contracts.d.ts +0 -157
- package/lib/legacy-read-contracts.js +0 -39
- package/lib/legacy-read-host.d.ts +0 -19
- package/lib/legacy-read-host.js +0 -67
- package/lib/legacy-read-integration.d.ts +0 -121
- package/lib/legacy-read-integration.js +0 -522
- package/lib/legacy-read-proxy.d.ts +0 -26
- package/lib/legacy-read-proxy.js +0 -237
- package/lib/native-child-evidence.d.ts +0 -42
- package/lib/native-child-evidence.js +0 -133
- package/lib/role-runs.d.ts +0 -135
- package/lib/role-runs.js +0 -304
- package/lib/session-persistence.d.ts +0 -35
- package/lib/session-persistence.js +0 -304
- package/lib/subagent-runtime.d.ts +0 -45
- package/lib/subagent-runtime.js +0 -131
- package/prompts/deepseek-flash.md +0 -11
- package/prompts/deepseek-v4-pro.md +0 -14
- package/scripts/cold-profile-composition.mjs +0 -329
- package/scripts/cold-profile-sources.mjs +0 -238
- package/scripts/migrate-cold-profile.mjs +0 -315
- package/scripts/repair-session-log.mjs +0 -476
- package/scripts/session-repair-native-verifier.mjs +0 -367
package/lib/lifetime.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Revoke synchronously when an owning scope begins unloading, before async cleanup. */
|
|
2
|
+
export function scopeLifetime(scope, label, revoke, install = () => { }) {
|
|
3
|
+
return scope.effect(() => {
|
|
4
|
+
const owners = new Map();
|
|
5
|
+
for (let fiber = scope.fiber; !owners.has(fiber.ctx); fiber = fiber.parent.fiber)
|
|
6
|
+
owners.set(fiber.ctx, fiber);
|
|
7
|
+
const retired = () => [...owners.values()].some(fiber => fiber.uid === null || fiber.state === 4 || fiber.state === 5);
|
|
8
|
+
const plugin = scope.on("internal/plugin", fiber => { if (owners.has(fiber.ctx) && retired())
|
|
9
|
+
revoke(); }, { global: true, prepend: true });
|
|
10
|
+
const status = scope.on("internal/status", fiber => { if (owners.has(fiber.ctx) && retired())
|
|
11
|
+
revoke(); }, { global: true, prepend: true });
|
|
12
|
+
if (retired()) {
|
|
13
|
+
plugin();
|
|
14
|
+
status();
|
|
15
|
+
revoke();
|
|
16
|
+
throw new Error("DSMM owner is retired");
|
|
17
|
+
}
|
|
18
|
+
install();
|
|
19
|
+
return () => { plugin(); status(); revoke(); };
|
|
20
|
+
}, label);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=lifetime.js.map
|
|
@@ -9,6 +9,7 @@ export declare class LivePiAiOwner implements DsmmLlmRouteResolver {
|
|
|
9
9
|
private readonly native;
|
|
10
10
|
private readonly registrations;
|
|
11
11
|
constructor(ctx: Context, native: LlmRuntime);
|
|
12
|
+
supportsNativeStop(provider: string): boolean;
|
|
12
13
|
requiresRaw(config: DsmmLlmCallConfig): boolean;
|
|
13
14
|
register(scope: Context, providers: readonly string[], adapter: LlmAdapter, handle: RegistrationHandle): RegistrationHandle;
|
|
14
15
|
generation(provider: string): DsmmLlmGeneration;
|
package/lib/live-pi-ai-owner.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { symbols } from "@deepseek-ai/cordis";
|
|
2
2
|
import { LlmError } from "@deepseek-ai/dsh-llm";
|
|
3
|
-
import { Config } from "@deepseek-ai/dsh-llm-pi-ai";
|
|
3
|
+
import { Config, PiAiAdapter } from "@deepseek-ai/dsh-llm-pi-ai";
|
|
4
4
|
import { InMemoryCredentialStore } from "@earendil-works/pi-ai";
|
|
5
5
|
import { brandString } from "@deepseek-ai/dsh-brand";
|
|
6
6
|
import { isDeepStrictEqual } from "node:util";
|
|
@@ -18,9 +18,12 @@ export class LivePiAiOwner {
|
|
|
18
18
|
this.ctx = ctx;
|
|
19
19
|
this.native = native;
|
|
20
20
|
}
|
|
21
|
+
supportsNativeStop(provider) {
|
|
22
|
+
const registration = this.registrations.get(provider);
|
|
23
|
+
return registration !== undefined && !(registration.adapter instanceof PiAiAdapter);
|
|
24
|
+
}
|
|
21
25
|
requiresRaw(config) {
|
|
22
|
-
return config.customParameters !== undefined || config.stop !== undefined
|
|
23
|
-
&& this.registrations.get(config.provider)?.scope.fiber.entry?.options.name === "@deepseek-ai/dsh-llm-pi-ai";
|
|
26
|
+
return config.customParameters !== undefined || config.stop !== undefined && !this.supportsNativeStop(config.provider);
|
|
24
27
|
}
|
|
25
28
|
register(scope, providers, adapter, handle) {
|
|
26
29
|
const record = { scope, adapter, life: new AbortController(), generations: new Map(), providers: [...providers] };
|
|
@@ -63,7 +66,7 @@ export class LivePiAiOwner {
|
|
|
63
66
|
if (record === undefined)
|
|
64
67
|
throw new LlmError("Provider registration is not ready", "DSMM_PROVIDER_NOT_READY");
|
|
65
68
|
const { scope, adapter } = record;
|
|
66
|
-
if (scope.fiber.entry?.options.name !== "@deepseek-ai/dsh-llm-pi-ai")
|
|
69
|
+
if (!(adapter instanceof PiAiAdapter) || scope.fiber.entry?.options.name !== "@deepseek-ai/dsh-llm-pi-ai")
|
|
67
70
|
throw new LlmError("This provider has no raw executor", "UNSUPPORTED_ROUTE_PARAMETERS");
|
|
68
71
|
const config = scope.fiber.config;
|
|
69
72
|
if (config === null || typeof config !== "object" || !("providers" in config) || config.providers === null || typeof config.providers !== "object"
|
|
@@ -127,6 +130,7 @@ export class LivePiAiOwner {
|
|
|
127
130
|
if (!this.requiresRaw(call)) {
|
|
128
131
|
try {
|
|
129
132
|
await this.native.resolveCallConfig(call, signal);
|
|
133
|
+
signal?.throwIfAborted();
|
|
130
134
|
return route;
|
|
131
135
|
}
|
|
132
136
|
catch (error) {
|
package/lib/mode.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { DshContext } from "./dsh-types.js";
|
|
1
|
+
import type { DshAgent, DshContext } from "./dsh-types.js";
|
|
2
2
|
import type { Config } from "./index.js";
|
|
3
3
|
import type { DsmmSettingsGetter } from "./settings.js";
|
|
4
4
|
import type { DeepworkModeController } from "./state.js";
|
|
5
|
-
|
|
5
|
+
/** The admission installer owns scope selection; assembly reads the immutable Agent configuration. */
|
|
6
|
+
export declare function registerDeepworkPrompt(readyCtx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter, config: Config, agent: DshAgent, lifetime: AbortSignal): void;
|
|
6
7
|
//# sourceMappingURL=mode.d.ts.map
|
package/lib/mode.js
CHANGED
|
@@ -1,57 +1,44 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getTraceable } from "@deepseek-ai/cordis";
|
|
2
2
|
import { agentForScope, nativeAgentContext } from "./native-scope.js";
|
|
3
3
|
import { buildDeepworkPrompt } from "./prompts.js";
|
|
4
4
|
import { resolveEffectiveDsmmRole, resolveSelectedAgentPreset } from "./session-scope.js";
|
|
5
|
+
const bindings = new WeakMap();
|
|
5
6
|
function routeFromAgent(agent) {
|
|
6
7
|
const header = agent.session.requestHeader?.();
|
|
7
8
|
const { provider, model } = (header === undefined ? agent.options : header.config) ?? {};
|
|
8
9
|
return typeof provider === "string" && typeof model === "string" ? { provider, model } : undefined;
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
/** The admission installer owns scope selection; assembly reads the immutable Agent configuration. */
|
|
12
|
+
export function registerDeepworkPrompt(readyCtx, controller, getSettings, config, agent, lifetime) {
|
|
13
|
+
const refresh = bindings.get(agent);
|
|
14
|
+
if (refresh) {
|
|
15
|
+
refresh();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const ctx = nativeAgentContext(agent);
|
|
19
|
+
let dispose;
|
|
20
|
+
const reconcile = () => {
|
|
21
|
+
dispose?.();
|
|
22
|
+
const registry = ctx.get("agentPresets")?.serviceFor(agent, "systemPrompt") ?? ctx.get("systemPrompt");
|
|
23
|
+
if (!registry)
|
|
24
|
+
throw new Error("Deepwork requires the native system prompt service");
|
|
25
|
+
dispose = getTraceable(ctx, registry).section({ name: "dsmm:deepwork", order: getSettings(agent).promptOrder, interpolate: false,
|
|
17
26
|
text(context) {
|
|
18
|
-
if (context.signal?.aborted)
|
|
27
|
+
if (context.signal?.aborted || getSettings.subagentRuntime !== undefined && !getSettings.subagentRuntime().deliveryFenceReady)
|
|
19
28
|
return "";
|
|
20
|
-
|
|
21
|
-
if (subject === undefined)
|
|
29
|
+
if (context.scope !== agent && agentForScope(readyCtx, context.scope) !== agent)
|
|
22
30
|
return "";
|
|
23
|
-
const settings = getSettings(
|
|
24
|
-
if (!settings.modules.deepwork.enabled || !controller.active(
|
|
31
|
+
const settings = getSettings(agent);
|
|
32
|
+
if (!settings.modules.deepwork.enabled || !controller.active(agent, settings.defaultActive))
|
|
25
33
|
return "";
|
|
26
|
-
return buildDeepworkPrompt(settings, { route: routeFromAgent(
|
|
34
|
+
return buildDeepworkPrompt(settings, { route: routeFromAgent(agent), selectedPreset: resolveSelectedAgentPreset(agent.session), roleId: resolveEffectiveDsmmRole(agent, settings, true) ?? null, overrideSection: config.section });
|
|
27
35
|
}
|
|
28
|
-
};
|
|
29
|
-
// Keep the caller's registration scope even when a primitive service is supplied.
|
|
30
|
-
const service = ctx instanceof Context ? getTraceable(ctx, registry) : registry;
|
|
31
|
-
return service.section(section);
|
|
36
|
+
});
|
|
32
37
|
};
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const presets = readyCtx.get?.("agentPresets");
|
|
39
|
-
const dispose = install(ctx, presets?.serviceFor(agent, "systemPrompt") ?? ctx.get("systemPrompt"), agent);
|
|
40
|
-
if (dispose !== undefined)
|
|
41
|
-
agents.set(agent, dispose);
|
|
42
|
-
};
|
|
43
|
-
readyCtx.on?.("agent/created", ({ agent }) => installForAgent(agent), { global: true });
|
|
44
|
-
readyCtx.on?.("agent-preset/selected", (id) => {
|
|
45
|
-
const agent = readyCtx.get?.("agents")?.get(id);
|
|
46
|
-
if (agent !== undefined)
|
|
47
|
-
installForAgent(agent);
|
|
48
|
-
}, { global: true });
|
|
49
|
-
readyCtx.on?.("agent/disposed", ({ agent }) => { agents.get(agent)?.(); agents.delete(agent); }, { global: true });
|
|
50
|
-
// Native fibers own each section. DSMM also releases the Agent-owned ones
|
|
51
|
-
// when its own plugin is unloaded while those Agents remain alive.
|
|
52
|
-
readyCtx.effect?.(() => () => { for (const dispose of agents.values())
|
|
53
|
-
dispose(); agents.clear(); });
|
|
54
|
-
for (const agent of readyCtx.get?.("agents")?.list() ?? [])
|
|
55
|
-
installForAgent(agent);
|
|
38
|
+
bindings.set(agent, reconcile);
|
|
39
|
+
const retire = () => { dispose?.(); bindings.delete(agent); lifetime.removeEventListener("abort", retire); };
|
|
40
|
+
lifetime.addEventListener("abort", retire, { once: true });
|
|
41
|
+
ctx.effect(() => retire);
|
|
42
|
+
reconcile();
|
|
56
43
|
}
|
|
57
44
|
//# sourceMappingURL=mode.js.map
|
package/lib/model-routing.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import type { DshContext
|
|
2
|
-
import type {
|
|
1
|
+
import type { DshContext } from "./dsh-types.js";
|
|
2
|
+
import type { DsmmSettingsGetter } from "./settings.js";
|
|
3
3
|
import type { DeepworkModeController } from "./state.js";
|
|
4
|
-
export type DeepseekReasoningEffort = DeepseekDefaultReasoningEffort | "max";
|
|
5
|
-
export type DeepseekModelRoute = "v4-pro" | "flash";
|
|
6
|
-
export declare function isDeepseekV4ProRoute(config: Pick<DshLlmCallConfig, "provider" | "model">): boolean;
|
|
7
|
-
export declare function isDeepseekFlashRoute(config: Pick<DshLlmCallConfig, "provider" | "model">): boolean;
|
|
8
|
-
export declare function desiredDeepseekEffort(settings: DsmmSettings, preset?: string, route?: DeepseekModelRoute): DeepseekReasoningEffort;
|
|
9
|
-
export declare function selectAdvertisedEffort(desired: DeepseekReasoningEffort, reasoning: DshModelReasoningInfo | undefined): string | undefined;
|
|
10
4
|
export declare function registerModelRouting(ctx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter): void;
|
|
11
5
|
//# sourceMappingURL=model-routing.d.ts.map
|
package/lib/model-routing.js
CHANGED
|
@@ -1,41 +1,11 @@
|
|
|
1
|
-
import { isDsmmRoleId } from "./roles.js";
|
|
2
1
|
import { applyModelRoute, clearRoleRouteLock, effectiveRoleFallbackRoutes, establishRolePolicy, latestNativeModelSelection, nativeModelSelectionWasAccepted, orderedModelRoutes, persistedRoleRoute, pinRoleRoute, roleRouteLock, selectInitialModelRoute, sameExactModelRoute, sameModelRoute, takeAdmittedRecoveryRoute } from "./role-routing.js";
|
|
3
|
-
import {
|
|
4
|
-
import { resolveAdmittedDsmmRole as resolveEffectiveDsmmRole } from "./role-policy.js";
|
|
2
|
+
import { resolveAdmittedDsmmRole } from "./role-policy.js";
|
|
5
3
|
import { childOwnedSessionEvents, sessionEvents } from "./session-scope.js";
|
|
6
4
|
import { isCurrentRecoveryStep } from "./recovery-policy.js";
|
|
7
5
|
import { capturedRoleInvocation } from "./role-invocation.js";
|
|
8
6
|
import { modelRouteFromCall } from "./role-llm.js";
|
|
9
7
|
import { configuredModelParameterPolicy, resolvedModelParameterPolicy } from "./model-parameter-policy.js";
|
|
10
|
-
|
|
11
|
-
return config.provider.toLowerCase() === "deepseek-official" && config.model.toLowerCase() === "deepseek-v4-pro";
|
|
12
|
-
}
|
|
13
|
-
export function isDeepseekFlashRoute(config) {
|
|
14
|
-
return ["deepseek-official", "deepseek-account"].includes(config.provider.toLowerCase())
|
|
15
|
-
&& config.model.toLowerCase() === "deepseek-flash";
|
|
16
|
-
}
|
|
17
|
-
export function desiredDeepseekEffort(settings, preset, route = "v4-pro") {
|
|
18
|
-
return route === "flash" ? settings.deepseekFlashDefaultReasoningEffort : settings.deepseekV4ProDefaultReasoningEffort;
|
|
19
|
-
}
|
|
20
|
-
export function selectAdvertisedEffort(desired, reasoning) {
|
|
21
|
-
if (!reasoning)
|
|
22
|
-
return undefined;
|
|
23
|
-
const advertised = new Set(reasoning.efforts.map((effort) => effort.id));
|
|
24
|
-
const fallback = reasoning.defaultEffort !== undefined && advertised.has(reasoning.defaultEffort) ? reasoning.defaultEffort : undefined;
|
|
25
|
-
if (desired === "max") {
|
|
26
|
-
if (advertised.has("max"))
|
|
27
|
-
return "max";
|
|
28
|
-
if (advertised.has("high"))
|
|
29
|
-
return "high";
|
|
30
|
-
return fallback;
|
|
31
|
-
}
|
|
32
|
-
return advertised.has(desired) ? desired : fallback;
|
|
33
|
-
}
|
|
34
|
-
function hasLiveRuntimeOwner(ctx, agent) {
|
|
35
|
-
const agents = ctx.get?.("agents");
|
|
36
|
-
return agent.id !== undefined && agents !== undefined
|
|
37
|
-
&& agents.list().some((parent) => parent !== agent && agents.isOwnedBy(agent.id, parent));
|
|
38
|
-
}
|
|
8
|
+
import { registerRuntimeRecovery } from "./runtime-recovery.js";
|
|
39
9
|
export function registerModelRouting(ctx, controller, getSettings) {
|
|
40
10
|
const installedContexts = new WeakSet();
|
|
41
11
|
const install = (readyCtx) => {
|
|
@@ -44,160 +14,87 @@ export function registerModelRouting(ctx, controller, getSettings) {
|
|
|
44
14
|
installedContexts.add(readyCtx);
|
|
45
15
|
const lockedAgents = new Set();
|
|
46
16
|
const assembledSelections = new WeakMap();
|
|
47
|
-
let dispose;
|
|
48
|
-
let disposeAgent;
|
|
49
|
-
let disposeAssembly;
|
|
17
|
+
let dispose, disposeAgent, disposeAssembly;
|
|
50
18
|
try {
|
|
19
|
+
registerRuntimeRecovery(readyCtx, controller, getSettings);
|
|
51
20
|
disposeAssembly = readyCtx.on("system-prompt/assemble", async (_assembly, context, next) => {
|
|
52
|
-
if (context.agent !== undefined && context.signal !== undefined)
|
|
21
|
+
if (context.agent !== undefined && context.signal !== undefined)
|
|
53
22
|
assembledSelections.set(context.agent, { signal: context.signal, intent: latestNativeModelSelection(context.agent) });
|
|
54
|
-
}
|
|
55
23
|
return next();
|
|
56
24
|
}, { prepend: true });
|
|
57
25
|
dispose = readyCtx.on("agent/request", async (frame, next) => {
|
|
58
|
-
|
|
26
|
+
const downstream = await next();
|
|
59
27
|
if (frame.signal.aborted)
|
|
60
28
|
return downstream;
|
|
61
|
-
const settings = getSettings(frame.agent);
|
|
62
|
-
const admission = getSettings.admission?.(frame.agent);
|
|
29
|
+
const settings = getSettings(frame.agent), admission = getSettings.admission?.(frame.agent);
|
|
63
30
|
const parameterPolicy = admission === undefined ? configuredModelParameterPolicy(settings) : resolvedModelParameterPolicy(admission);
|
|
64
31
|
if (!settings.modules.deepwork.enabled)
|
|
65
32
|
return downstream;
|
|
66
33
|
const ordinaryRoot = frame.agent.session.header?.origin !== "subagent";
|
|
67
34
|
const admitted = takeAdmittedRecoveryRoute(frame);
|
|
68
|
-
const
|
|
69
|
-
const role = resolveEffectiveDsmmRole(frame.agent, settings, active);
|
|
35
|
+
const role = resolveAdmittedDsmmRole(frame.agent, settings, controller.active(frame.agent, settings.defaultActive));
|
|
70
36
|
const policy = role === undefined ? undefined : settings.roleRouting[role];
|
|
71
37
|
const invocation = capturedRoleInvocation(frame.agent);
|
|
72
38
|
const primary = invocation?.initialRoute ?? policy?.primary;
|
|
73
|
-
const
|
|
74
|
-
|
|
39
|
+
const identity = await establishRolePolicy(frame, settings, role, readyCtx, admission?.epoch);
|
|
40
|
+
frame.signal.throwIfAborted();
|
|
75
41
|
const fallbacks = effectiveRoleFallbackRoutes(settings, role);
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
if (
|
|
87
|
-
if (manual !== undefined && lock?.manualSelectionSeq !== manual.seq
|
|
88
|
-
&& !nativeModelSelectionWasAccepted(frame.agent, manual))
|
|
89
|
-
downstream = applyModelRoute(downstream, manual.route);
|
|
90
|
-
const selected = modelRouteFromCall(downstream);
|
|
91
|
-
if (lock === undefined || !sameExactModelRoute(lock.route, selected) || lock.manualSelectionSeq !== manual?.seq) {
|
|
92
|
-
const generation = (lock?.generation ?? -1) + 1;
|
|
93
|
-
lock = pinRoleRoute(frame.agent, identity, selected, [selected]);
|
|
94
|
-
lock.manualSelectionSeq = manual?.seq;
|
|
95
|
-
lock.generation = generation;
|
|
96
|
-
lockedAgents.add(frame.agent);
|
|
97
|
-
}
|
|
98
|
-
return downstream;
|
|
99
|
-
}
|
|
100
|
-
if (manual !== undefined && lock?.manualSelectionSeq !== manual.seq
|
|
101
|
-
&& (sameModelRoute(downstream, manual.route) && downstream.reasoningEffort === manual.route.reasoningEffort || nativeModelSelectionWasAccepted(frame.agent, manual))) {
|
|
102
|
-
const llm = frame.agent.ctx?.get?.("llm")
|
|
103
|
-
?? (readyCtx.get !== undefined ? readyCtx.get("llm") : readyCtx.llm);
|
|
104
|
-
if (llm?.resolveCallConfig === undefined)
|
|
105
|
-
throw new Error("dsmm explicit model selection requires the native LLM service");
|
|
106
|
-
await llm.resolveCallConfig(applyModelRoute(downstream, manual.route), frame.signal);
|
|
107
|
-
frame.signal.throwIfAborted();
|
|
42
|
+
const currentStep = isCurrentRecoveryStep(ordinaryRoot ? sessionEvents(frame.agent.session) : childOwnedSessionEvents(frame.agent.session), frame.turn, frame.step);
|
|
43
|
+
if (role === undefined || identity === undefined || !currentStep)
|
|
44
|
+
return downstream;
|
|
45
|
+
let lock = roleRouteLock(frame.agent, identity);
|
|
46
|
+
const exactPolicy = invocation === undefined ? primary !== undefined || policy?.fallbackRoutes !== undefined || fallbacks.length > 0
|
|
47
|
+
: invocation.routeSource !== "inherited" || invocation.exactEffort || fallbacks.length > 0;
|
|
48
|
+
const captured = assembledSelections.get(frame.agent);
|
|
49
|
+
const manual = captured?.signal === frame.signal ? captured.intent : undefined;
|
|
50
|
+
if (ordinaryRoot) {
|
|
51
|
+
const selected = modelRouteFromCall(downstream);
|
|
52
|
+
if (lock === undefined || !sameExactModelRoute(lock.route, selected) || lock.manualSelectionSeq !== manual?.seq) {
|
|
108
53
|
const generation = (lock?.generation ?? -1) + 1;
|
|
109
|
-
lock = pinRoleRoute(frame.agent, identity,
|
|
110
|
-
lock.manualSelectionSeq = manual
|
|
54
|
+
lock = pinRoleRoute(frame.agent, identity, selected, [selected]);
|
|
55
|
+
lock.manualSelectionSeq = manual?.seq;
|
|
111
56
|
lock.generation = generation;
|
|
112
57
|
lockedAgents.add(frame.agent);
|
|
113
58
|
}
|
|
114
|
-
if (lock?.manualSelectionSeq !== undefined) {
|
|
115
|
-
// An unchanged explicit intent must not undo a policy-authorized
|
|
116
|
-
// fallback; a fresh native selection event re-admits above.
|
|
117
|
-
return applyModelRoute(downstream, lock.route);
|
|
118
|
-
}
|
|
119
|
-
if (admitted !== undefined)
|
|
120
|
-
return applyModelRoute(downstream, admitted);
|
|
121
|
-
const accepted = persistedRoleRoute(frame, liveAlias ? undefined : primary, fallbacks, identity);
|
|
122
|
-
if (lock !== undefined && accepted !== undefined && !sameExactModelRoute(accepted, lock.route)) {
|
|
123
|
-
// An explicit already-committed native route change remains host-owned;
|
|
124
|
-
// DSMM's pending current-frame route still has precedence above.
|
|
125
|
-
lock.route = { ...accepted };
|
|
126
|
-
lock.candidateIndex = lock.candidates.findIndex(candidate => sameExactModelRoute(candidate, accepted));
|
|
127
|
-
lock.generation += 1;
|
|
128
|
-
lock.startupSettled = true;
|
|
129
|
-
lock.retries = 0;
|
|
130
|
-
lock.rateLimits = 0;
|
|
131
|
-
}
|
|
132
|
-
if (lock === undefined) {
|
|
133
|
-
const inherited = modelRouteFromCall(downstream);
|
|
134
|
-
const candidates = invocation?.candidates ?? orderedModelRoutes([liveAlias ? inherited : primary ?? inherited, ...fallbacks]);
|
|
135
|
-
const persisted = accepted;
|
|
136
|
-
const llm = frame.agent.ctx?.get?.("llm")
|
|
137
|
-
?? (readyCtx.get !== undefined ? readyCtx.get("llm") : readyCtx.llm);
|
|
138
|
-
const selected = persisted ?? invocation?.initialRoute ?? (exactPolicy ? await selectInitialModelRoute(llm ?? {}, candidates, frame.signal, parameterPolicy.mode === "passthrough" ? readyCtx.get?.("dsmmLlmRoutes") : undefined) : inherited);
|
|
139
|
-
frame.signal.throwIfAborted();
|
|
140
|
-
lock = pinRoleRoute(frame.agent, identity, selected, candidates, { preserveCandidates: parameterPolicy.mode === "native-defaults",
|
|
141
|
-
initialCandidate: persisted ?? invocation?.selectedCandidate });
|
|
142
|
-
if (persisted !== undefined)
|
|
143
|
-
lock.startupSettled = true;
|
|
144
|
-
lockedAgents.add(frame.agent);
|
|
145
|
-
}
|
|
146
|
-
downstream = applyModelRoute(downstream, lock.route);
|
|
147
|
-
const newRouteWithoutEffort = invocation !== undefined && !invocation.exactEffort
|
|
148
|
-
&& (invocation.routeSource === "level" || invocation.routeSource === "invocation-route");
|
|
149
|
-
if ((exactPolicy || lock.attempts > 0) && !newRouteWithoutEffort)
|
|
150
|
-
return downstream;
|
|
151
|
-
}
|
|
152
|
-
// Ordinary roots belong to the native model tab, including its exact effort.
|
|
153
|
-
if (ordinaryRoot)
|
|
154
|
-
return downstream;
|
|
155
|
-
if (parameterPolicy.mode === "native-defaults")
|
|
156
|
-
return downstream;
|
|
157
|
-
// Named fallback efforts are native policy IDs, never legacy calibration inputs.
|
|
158
|
-
if (fallbacks.some((fallback) => fallback.reasoningEffort !== undefined
|
|
159
|
-
&& sameModelRoute(fallback, downstream) && fallback.reasoningEffort === downstream.reasoningEffort))
|
|
160
|
-
return downstream;
|
|
161
|
-
const route = isDeepseekV4ProRoute(downstream) ? "v4-pro" : isDeepseekFlashRoute(downstream) ? "flash" : undefined;
|
|
162
|
-
if (route === undefined)
|
|
163
|
-
return downstream;
|
|
164
|
-
const calibration = route === "flash" ? settings.deepseekFlashCalibration : settings.deepseekV4ProCalibration;
|
|
165
|
-
if (calibration === "off")
|
|
166
|
-
return downstream;
|
|
167
|
-
const preset = role ?? resolveSelectedAgentPreset(frame.agent?.session);
|
|
168
|
-
const inScope = active || isDsmmRoleId(preset);
|
|
169
|
-
if (!inScope)
|
|
170
59
|
return downstream;
|
|
171
|
-
if (calibration === "auto" && downstream.reasoningEffort !== undefined)
|
|
172
|
-
return downstream;
|
|
173
|
-
const desired = desiredDeepseekEffort(settings, preset, route);
|
|
174
|
-
let selected;
|
|
175
|
-
try {
|
|
176
|
-
const agentContext = frame.agent.ctx;
|
|
177
|
-
const llm = agentContext?.get?.("llm")
|
|
178
|
-
?? (readyCtx.get !== undefined ? readyCtx.get("llm") : readyCtx.llm);
|
|
179
|
-
const modelInfo = await llm?.resolveModelInfo(downstream.provider, downstream.model, frame.signal);
|
|
180
|
-
selected = selectAdvertisedEffort(desired, modelInfo?.reasoning);
|
|
181
60
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
61
|
+
const llm = frame.agent.ctx?.get?.("llm") ?? readyCtx.get?.("llm") ?? readyCtx.llm;
|
|
62
|
+
if (manual !== undefined && lock?.manualSelectionSeq !== manual.seq
|
|
63
|
+
&& (sameModelRoute(downstream, manual.route) && downstream.reasoningEffort === manual.route.reasoningEffort || nativeModelSelectionWasAccepted(frame.agent, manual))) {
|
|
64
|
+
const selected = modelRouteFromCall(downstream);
|
|
65
|
+
const generation = (lock?.generation ?? -1) + 1;
|
|
66
|
+
lock = pinRoleRoute(frame.agent, identity, selected, [selected, ...fallbacks], { preserveCandidates: parameterPolicy.mode === "native-defaults" });
|
|
67
|
+
lock.manualSelectionSeq = manual.seq;
|
|
68
|
+
lock.generation = generation;
|
|
69
|
+
lockedAgents.add(frame.agent);
|
|
185
70
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
return downstream;
|
|
71
|
+
// A consumed explicit selection must not undo an admitted fallback.
|
|
72
|
+
if (lock?.manualSelectionSeq !== undefined)
|
|
73
|
+
return applyModelRoute(downstream, lock.route);
|
|
74
|
+
if (admitted !== undefined)
|
|
75
|
+
return applyModelRoute(downstream, admitted);
|
|
76
|
+
const accepted = persistedRoleRoute(frame, primary, fallbacks, identity);
|
|
77
|
+
if (lock !== undefined && accepted !== undefined && !sameExactModelRoute(accepted, lock.route)) {
|
|
78
|
+
lock.route = { ...accepted };
|
|
79
|
+
lock.candidateIndex = lock.candidates.findIndex(candidate => sameExactModelRoute(candidate, accepted));
|
|
80
|
+
lock.generation += 1;
|
|
81
|
+
lock.startupSettled = true;
|
|
82
|
+
lock.retries = 0;
|
|
83
|
+
lock.rateLimits = 0;
|
|
189
84
|
}
|
|
190
|
-
if (
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
85
|
+
if (lock === undefined) {
|
|
86
|
+
const inherited = modelRouteFromCall(downstream);
|
|
87
|
+
const candidates = invocation?.candidates ?? orderedModelRoutes([primary ?? inherited, ...fallbacks]);
|
|
88
|
+
const selected = accepted ?? invocation?.initialRoute ?? (exactPolicy ? await selectInitialModelRoute(llm ?? {}, candidates, frame.signal, parameterPolicy.mode === "passthrough" ? readyCtx.get?.("dsmmLlmRoutes") : undefined) : inherited);
|
|
89
|
+
frame.signal.throwIfAborted();
|
|
90
|
+
lock = pinRoleRoute(frame.agent, identity, selected, candidates, { preserveCandidates: parameterPolicy.mode === "native-defaults", initialCandidate: accepted ?? invocation?.selectedCandidate });
|
|
91
|
+
if (accepted !== undefined)
|
|
92
|
+
lock.startupSettled = true;
|
|
93
|
+
lockedAgents.add(frame.agent);
|
|
194
94
|
}
|
|
195
|
-
return
|
|
95
|
+
return applyModelRoute(downstream, lock.route);
|
|
196
96
|
}, { prepend: true });
|
|
197
|
-
disposeAgent = readyCtx.on("agent/disposed", ({ agent }) => {
|
|
198
|
-
lockedAgents.delete(agent);
|
|
199
|
-
clearRoleRouteLock(agent);
|
|
200
|
-
}, { global: true });
|
|
97
|
+
disposeAgent = readyCtx.on("agent/disposed", ({ agent }) => { lockedAgents.delete(agent); clearRoleRouteLock(agent); }, { global: true });
|
|
201
98
|
}
|
|
202
99
|
catch (error) {
|
|
203
100
|
installedContexts.delete(readyCtx);
|
|
@@ -220,24 +117,11 @@ export function registerModelRouting(ctx, controller, getSettings) {
|
|
|
220
117
|
dispose();
|
|
221
118
|
});
|
|
222
119
|
};
|
|
223
|
-
|
|
224
|
-
if (ctx.get !== undefined) {
|
|
120
|
+
if (ctx.get !== undefined)
|
|
225
121
|
install(ctx);
|
|
226
|
-
|
|
227
|
-
}
|
|
228
|
-
if (ctx.inject !== undefined) {
|
|
122
|
+
else if (ctx.inject !== undefined)
|
|
229
123
|
ctx.inject(["llm"], install);
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
if (Object.prototype.hasOwnProperty.call(ctx, "llm") && Object.prototype.hasOwnProperty.call(ctx, "on"))
|
|
124
|
+
else if (Object.prototype.hasOwnProperty.call(ctx, "llm") && Object.prototype.hasOwnProperty.call(ctx, "on"))
|
|
233
125
|
install(ctx);
|
|
234
126
|
}
|
|
235
|
-
function warnUnavailable(readyCtx, rootCtx, desired, modelRoute) {
|
|
236
|
-
try {
|
|
237
|
-
(readyCtx.logger ?? rootCtx.logger)?.warn(`dsmm could not select advertised reasoning effort for ${modelRoute}; desired ${desired}`);
|
|
238
|
-
}
|
|
239
|
-
catch {
|
|
240
|
-
// Warning emission is diagnostic-only and must not alter routing fail-open behavior.
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
127
|
//# sourceMappingURL=model-routing.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
3
|
+
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
4
|
+
import type { SubagentProvider, SubagentActivation, ContinuableCreateRequest } from "@deepseek-ai/dsh-subagent";
|
|
5
|
+
import type { ToolExecution } from "@deepseek-ai/dsh-tools";
|
|
6
|
+
import type { DsmmProfileRuntime } from "./profile-runtime.js";
|
|
7
|
+
import type { DsmmProfileAdmission } from "./settings.js";
|
|
8
|
+
import type { ResolvedRoleInvocation } from "./role-invocation.js";
|
|
9
|
+
import type { DsmmRolePolicy } from "./role-policy.js";
|
|
10
|
+
declare module "@deepseek-ai/cordis" {
|
|
11
|
+
interface Context {
|
|
12
|
+
dsmmNativeAdmission: NativeAdmission;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** Short-lived creation correlations and exact live bindings, never an execution queue. */
|
|
16
|
+
export declare class NativeAdmission {
|
|
17
|
+
readonly ctx: Context;
|
|
18
|
+
readonly profiles: DsmmProfileRuntime;
|
|
19
|
+
readonly policy: DsmmRolePolicy;
|
|
20
|
+
readonly lifetime: AbortController;
|
|
21
|
+
private readonly pending;
|
|
22
|
+
private readonly live;
|
|
23
|
+
private readonly candidates;
|
|
24
|
+
private readonly agents;
|
|
25
|
+
private readonly activations;
|
|
26
|
+
private readonly activities;
|
|
27
|
+
private readonly calls;
|
|
28
|
+
private readonly rebindings;
|
|
29
|
+
private readonly guardedTools;
|
|
30
|
+
private readonly agentLifetimes;
|
|
31
|
+
private readonly retirements;
|
|
32
|
+
private ready;
|
|
33
|
+
private install?;
|
|
34
|
+
constructor(ctx: Context, profiles: DsmmProfileRuntime, policy: DsmmRolePolicy);
|
|
35
|
+
activate(install: NonNullable<NativeAdmission["install"]>): void;
|
|
36
|
+
get isReady(): boolean;
|
|
37
|
+
get(agent: Agent): DsmmProfileAdmission | undefined;
|
|
38
|
+
configuration(agent: Agent): DsmmProfileAdmission;
|
|
39
|
+
invocation(agent: Agent): ResolvedRoleInvocation | undefined;
|
|
40
|
+
ensure(agent: Agent): Promise<DsmmProfileAdmission>;
|
|
41
|
+
assert(agent: Agent): DsmmProfileAdmission;
|
|
42
|
+
reserve(exec: Readonly<ToolExecution>, invocation: ResolvedRoleInvocation, provider: SubagentProvider, maxDepth?: number): Promise<{
|
|
43
|
+
childId: SessionId;
|
|
44
|
+
release(): Promise<void>;
|
|
45
|
+
signal: AbortSignal;
|
|
46
|
+
}>;
|
|
47
|
+
duringCall<T>(agent: Agent, signal: AbortSignal, operation: (signal: AbortSignal) => Promise<T>): Promise<T>;
|
|
48
|
+
prepare(request: ContinuableCreateRequest, provider: SubagentProvider): void;
|
|
49
|
+
private check;
|
|
50
|
+
track(activation: SubagentActivation): void;
|
|
51
|
+
private guardTools;
|
|
52
|
+
private retireAgent;
|
|
53
|
+
private rebindBlank;
|
|
54
|
+
private created;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=native-admission.d.ts.map
|