@dsmm/dsmm 0.3.1 → 0.3.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/cordis.patch.yml +9 -0
- package/docs/compatibility.md +10 -0
- package/docs/releasing.md +25 -65
- package/docs/roadmap.md +44 -2
- package/lib/client/ChildPermissions.d.ts +43 -0
- package/lib/client/ChildPermissions.js +100 -0
- package/lib/client/ChildrenPanel.d.ts +4 -1
- package/lib/client/ChildrenPanel.js +3 -3
- package/lib/client/DeploymentFields.d.ts +6 -2
- package/lib/client/DeploymentFields.js +8 -6
- package/lib/client/DeploymentPage.d.ts +4 -1
- package/lib/client/DeploymentPage.js +5 -4
- package/lib/client/HistoryContinuation.d.ts +7 -0
- package/lib/client/HistoryContinuation.js +22 -0
- package/lib/client/PermissionPanelEntry.d.ts +8 -0
- package/lib/client/PermissionPanelEntry.js +11 -0
- package/lib/client/PermissionsPanel.d.ts +3 -1
- package/lib/client/PermissionsPanel.js +3 -2
- package/lib/client/ProfilesSection.js +3 -3
- package/lib/client/RoleAvailability.js +1 -1
- package/lib/client/SessionProfiles.js +21 -18
- package/lib/client/TemporaryPermissions.d.ts +21 -0
- package/lib/client/TemporaryPermissions.js +94 -0
- package/lib/client/children-locales.d.ts +4 -4
- package/lib/client/controller.d.ts +17 -0
- package/lib/client/controller.js +101 -18
- package/lib/client/deployment-locales.js +26 -26
- package/lib/client/history-controller.d.ts +29 -0
- package/lib/client/history-controller.js +111 -0
- package/lib/client/history-entry.d.ts +11 -0
- package/lib/client/history-entry.js +106 -0
- package/lib/client/history-locales.d.ts +95 -0
- package/lib/client/history-locales.js +41 -0
- package/lib/client/index.js +16 -3
- package/lib/client/locales.d.ts +6 -0
- package/lib/client/locales.js +104 -92
- package/lib/client/permission-locales.d.ts +26 -0
- package/lib/client/permission-locales.js +55 -35
- package/lib/client/temporary-permission-client.d.ts +20 -0
- package/lib/client/temporary-permission-client.js +52 -0
- package/lib/client/temporary-permission-entry.d.ts +6 -0
- package/lib/client/temporary-permission-entry.js +56 -0
- package/lib/client.js +3881 -1981
- package/lib/history-candidates.d.ts +30 -0
- package/lib/history-candidates.js +176 -0
- package/lib/history-codec.d.ts +11 -0
- package/lib/history-codec.js +102 -0
- package/lib/history-contract.d.ts +44 -0
- package/lib/history-contract.js +2 -0
- package/lib/history-controller.d.ts +42 -0
- package/lib/history-controller.js +329 -0
- package/lib/history-policy.d.ts +4 -0
- package/lib/history-policy.js +8 -0
- package/lib/history-remote.d.ts +28 -0
- package/lib/history-remote.js +17 -0
- package/lib/history-rpc.d.ts +24 -0
- package/lib/history-rpc.js +136 -0
- package/lib/history-support.d.ts +15 -0
- package/lib/history-support.js +21 -0
- package/lib/history-types.d.ts +67 -0
- package/lib/history-types.js +2 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +24 -6
- package/lib/native-admission.d.ts +21 -0
- package/lib/native-admission.js +206 -16
- package/lib/permission-child-control.d.ts +36 -0
- package/lib/permission-child-control.js +164 -0
- package/lib/permission-control.d.ts +2 -0
- package/lib/permission-control.js +7 -0
- package/lib/permission-controller.js +2 -2
- package/lib/permission-exec-argv.d.ts +32 -0
- package/lib/permission-exec-argv.js +171 -0
- package/lib/permission-fs-search.js +2 -1
- package/lib/permission-fs.js +2 -1
- package/lib/permission-native-rules.js +3 -3
- package/lib/permission-temporary-files.d.ts +19 -0
- package/lib/permission-temporary-files.js +248 -0
- package/lib/permission-temporary-grants.d.ts +106 -0
- package/lib/permission-temporary-grants.js +198 -0
- package/lib/permission-temporary-install.d.ts +25 -0
- package/lib/permission-temporary-install.js +86 -0
- package/lib/permission-temporary-remote.d.ts +19 -0
- package/lib/permission-temporary-remote.js +75 -0
- package/lib/permission-temporary-rpc.d.ts +37 -0
- package/lib/permission-temporary-rpc.js +154 -0
- package/lib/permission-temporary-types.d.ts +47 -0
- package/lib/permission-temporary-types.js +2 -0
- package/lib/permission-temporary-web.d.ts +11 -0
- package/lib/permission-temporary-web.js +154 -0
- package/lib/permission-web.js +2 -1
- package/lib/preset-skills.d.ts +1 -1
- package/lib/preset-skills.js +2 -2
- package/lib/profile-rpc.js +2 -0
- package/lib/profile-runtime.d.ts +12 -1
- package/lib/profile-runtime.js +122 -10
- package/lib/profile-store.d.ts +2 -2
- package/lib/profile-store.js +8 -1
- package/lib/profile-types.d.ts +1 -0
- package/lib/role-invocation.d.ts +1 -1
- package/lib/role-invocation.js +2 -2
- package/lib/role-subagents.js +16 -3
- package/lib/skills.d.ts +1 -0
- package/lib/skills.js +5 -1
- package/package.json +41 -33
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-gateway@0.2.1-rc.2.patch +13291 -0
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-remotes@0.2.1-rc.2.patch +9133 -0
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-client-ui-approval@0.2.1-rc.2.patch +156 -0
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-subagent@0.2.1-rc.2.patch +3546 -0
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-user-approval@0.2.1-rc.2.patch +431 -0
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-web@0.2.1-rc.2.patch +119 -0
- package/patches/dsh-approval-settlement/README.md +41 -0
- package/patches/dsh-approval-settlement/metadata.json +10 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-agent-loop@0.2.1-rc.2.patch +383 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-agent-preset-registry@0.2.1-rc.2.patch +55 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-api-session-controller@0.2.1-rc.2.patch +16673 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-client-ui-subagent@0.2.1-rc.2.patch +29 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-client-ui-workspace@0.2.1-rc.2.patch +196 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-session-persistence-jsonl@0.2.1-rc.2.patch +35 -0
- package/patches/dsh-session-activation/@deepseek-ai__dsh-session-persistence@0.2.1-rc.2.patch +40 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { SessionInspection } from "@deepseek-ai/dsh-session-persistence";
|
|
3
|
+
import type { NativeAdmission } from "./native-admission.js";
|
|
4
|
+
import type { DsmmProfileRuntime } from "./profile-runtime.js";
|
|
5
|
+
import type { DsmmDeploymentConfig } from "./deployment-config.js";
|
|
6
|
+
import type { HistoryCandidate, HistoryCandidates } from "./history-contract.js";
|
|
7
|
+
import type { HistoryPreviewRequest } from "./history-types.js";
|
|
8
|
+
/** Current deployment/profile and native composition only; history supplies content and restrictive ceilings. */
|
|
9
|
+
export declare class DsmmHistoryCandidates implements HistoryCandidates {
|
|
10
|
+
private readonly ctx;
|
|
11
|
+
private readonly profiles;
|
|
12
|
+
private readonly deployment;
|
|
13
|
+
private readonly admission;
|
|
14
|
+
readonly signal: AbortSignal;
|
|
15
|
+
private modelGeneration;
|
|
16
|
+
constructor(ctx: Context, profiles: DsmmProfileRuntime, deployment: DsmmDeploymentConfig, admission: NativeAdmission);
|
|
17
|
+
checkCompatibility(): Promise<void>;
|
|
18
|
+
choices(signal: AbortSignal): Promise<{
|
|
19
|
+
presets: {
|
|
20
|
+
id: string;
|
|
21
|
+
label: string;
|
|
22
|
+
}[];
|
|
23
|
+
profiles: {
|
|
24
|
+
id: string;
|
|
25
|
+
label: string;
|
|
26
|
+
}[];
|
|
27
|
+
}>;
|
|
28
|
+
prepare(request: HistoryPreviewRequest, inspection: SessionInspection, signal: AbortSignal): Promise<HistoryCandidate>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=history-candidates.d.ts.map
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { isDeepStrictEqual } from "node:util";
|
|
3
|
+
import { symbols } from "@deepseek-ai/cordis";
|
|
4
|
+
import { ReasoningEffortId } from "@deepseek-ai/dsh-llm";
|
|
5
|
+
import { setSandboxMode } from "@deepseek-ai/dsh-sandbox-policy";
|
|
6
|
+
import { setApprovalPolicy } from "@deepseek-ai/dsh-user-approval";
|
|
7
|
+
import { HistoryRefusal } from "./history-controller.js";
|
|
8
|
+
import { DSMM_ROLES, isDsmmRoleId } from "./roles.js";
|
|
9
|
+
import { isRootRoleEnabled } from "./settings.js";
|
|
10
|
+
import { appendModeRecord } from "./session-metadata.js";
|
|
11
|
+
import { effectiveHistoryGitWriteGuard } from "./history-policy.js";
|
|
12
|
+
const require = createRequire(import.meta.url), sdk = createRequire(require.resolve("@deepseek-ai/dsh-agent-preset-registry"));
|
|
13
|
+
const { createScope, scopeParentOf } = sdk("@deepseek-ai/dsh-scope");
|
|
14
|
+
const original = (value) => Reflect.get(value, symbols.original) ?? value;
|
|
15
|
+
const services = ["llm", "tools", "systemPrompt", "skills", "sandboxPolicy", "approval"];
|
|
16
|
+
function requireCurrentLease(lease) {
|
|
17
|
+
if (!("assertCurrent" in lease) || typeof lease.assertCurrent !== "function")
|
|
18
|
+
throw new HistoryRefusal("unsupported-host");
|
|
19
|
+
}
|
|
20
|
+
/** Current deployment/profile and native composition only; history supplies content and restrictive ceilings. */
|
|
21
|
+
export class DsmmHistoryCandidates {
|
|
22
|
+
ctx;
|
|
23
|
+
profiles;
|
|
24
|
+
deployment;
|
|
25
|
+
admission;
|
|
26
|
+
signal;
|
|
27
|
+
modelGeneration = 0;
|
|
28
|
+
constructor(ctx, profiles, deployment, admission) {
|
|
29
|
+
this.ctx = ctx;
|
|
30
|
+
this.profiles = profiles;
|
|
31
|
+
this.deployment = deployment;
|
|
32
|
+
this.admission = admission;
|
|
33
|
+
this.signal = admission.lifetime.signal;
|
|
34
|
+
ctx.on("llm/adapters-updated", () => { this.modelGeneration++; }, { global: true });
|
|
35
|
+
}
|
|
36
|
+
async checkCompatibility() {
|
|
37
|
+
this.signal.throwIfAborted();
|
|
38
|
+
const registry = this.ctx.agentPresets, preset = (await registry.list()).find(row => !row.broken);
|
|
39
|
+
if (!preset)
|
|
40
|
+
throw new HistoryRefusal("unavailable");
|
|
41
|
+
const lease = await registry.acquireScope(preset.id);
|
|
42
|
+
try {
|
|
43
|
+
requireCurrentLease(lease);
|
|
44
|
+
lease.assertCurrent();
|
|
45
|
+
this.signal.throwIfAborted();
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
await lease[Symbol.asyncDispose]();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async choices(signal) {
|
|
52
|
+
signal.throwIfAborted();
|
|
53
|
+
this.signal.throwIfAborted();
|
|
54
|
+
const desired = await this.deployment.readDesired(), rows = await this.ctx.agentPresets.list(), profiles = await this.profiles.describe();
|
|
55
|
+
signal.throwIfAborted();
|
|
56
|
+
this.signal.throwIfAborted();
|
|
57
|
+
return { presets: rows.filter(row => !row.broken && (!row.id.startsWith("dsmm-") || isDsmmRoleId(row.id) && isRootRoleEnabled(desired.settings, row.id)))
|
|
58
|
+
.map(row => ({ id: row.id, label: (row.name ?? row.id).slice(0, 120) })),
|
|
59
|
+
profiles: profiles.profiles.filter(row => row.revision !== null && row.error === undefined).map(row => ({ id: row.id, label: (row.label ?? row.id).slice(0, 120) })) };
|
|
60
|
+
}
|
|
61
|
+
async prepare(request, inspection, signal) {
|
|
62
|
+
signal.throwIfAborted();
|
|
63
|
+
this.signal.throwIfAborted();
|
|
64
|
+
if (inspection.meta.origin === "subagent")
|
|
65
|
+
throw new HistoryRefusal("child-owner-required");
|
|
66
|
+
const profile = await this.profiles.prepareHistory(request.profileId, this.signal), settings = profile.admission.settings;
|
|
67
|
+
if (request.preset.startsWith("dsmm-") && (!isDsmmRoleId(request.preset) || !isRootRoleEnabled(settings, request.preset)))
|
|
68
|
+
throw new HistoryRefusal("unavailable");
|
|
69
|
+
const registry = this.ctx.agentPresets, metadata = await registry.resolve(request.preset);
|
|
70
|
+
if (metadata.broken)
|
|
71
|
+
throw new HistoryRefusal("unavailable");
|
|
72
|
+
const lease = await registry.acquireScope(request.preset);
|
|
73
|
+
try {
|
|
74
|
+
requireCurrentLease(lease);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
await lease[Symbol.asyncDispose]();
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
const scope = createScope(this.ctx, {}, { parent: lease.key });
|
|
81
|
+
const dispose = async () => { try {
|
|
82
|
+
await scope.dispose();
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
await lease[Symbol.asyncDispose]();
|
|
86
|
+
} };
|
|
87
|
+
try {
|
|
88
|
+
const get = (name) => registry.serviceFor({ ctx: scope.ctx }, name) ?? this.ctx.get(name);
|
|
89
|
+
const captured = services.map(name => get(name));
|
|
90
|
+
if (captured.some(value => value === undefined))
|
|
91
|
+
throw new HistoryRefusal("unavailable");
|
|
92
|
+
const llm = get("llm"), sandbox = get("sandboxPolicy"), approval = get("approval");
|
|
93
|
+
const permissions = this.ctx.get("dsmmPermissionController");
|
|
94
|
+
if (!permissions)
|
|
95
|
+
throw new HistoryRefusal("unavailable");
|
|
96
|
+
await permissions.rules.refresh();
|
|
97
|
+
const rules = permissions.rules.getPolicy(), permissionSignal = permissions.rules.signal;
|
|
98
|
+
const source = this.deployment.permissionSource();
|
|
99
|
+
if (source.globalRevision !== profile.admission.deployment?.globalRevision || source.nativeRevision !== profile.admission.deployment?.nativeRevision)
|
|
100
|
+
throw new HistoryRefusal("stale");
|
|
101
|
+
const generation = this.modelGeneration;
|
|
102
|
+
const active = settings.modules.deepwork.enabled && (isDsmmRoleId(request.preset) || request.preset !== "minimal" && settings.defaultActive);
|
|
103
|
+
const role = isDsmmRoleId(request.preset) ? request.preset : active ? "dsmm-orchestrator" : undefined;
|
|
104
|
+
const route = role === undefined ? undefined : settings.roleRouting[role]?.primary;
|
|
105
|
+
const defaultModel = this.ctx.get?.("agentDefaultModel");
|
|
106
|
+
if (!route && !defaultModel)
|
|
107
|
+
throw new HistoryRefusal("unavailable");
|
|
108
|
+
const model = route === undefined ? structuredClone(defaultModel.currentSelection()) : { provider: route.provider, model: route.model,
|
|
109
|
+
...(route.reasoningEffort === undefined ? {} : { reasoningEffort: ReasoningEffortId(route.reasoningEffort) }) };
|
|
110
|
+
await llm.resolveCallConfig(model, signal);
|
|
111
|
+
const oldSandbox = inspection.events.filter(event => event.type === "sandbox/mode").at(-1);
|
|
112
|
+
const oldApproval = inspection.events.filter(event => event.type === "approval/policy").at(-1);
|
|
113
|
+
const oldPreset = inspection.events.filter(event => event.type === "agent-preset/selected").at(-1)?.data.agentPreset ?? inspection.meta.agentPreset;
|
|
114
|
+
const readOnlyHistory = oldSandbox?.data.mode === "read-only" || DSMM_ROLES.some(role => role.id === oldPreset && role.access === "read-only");
|
|
115
|
+
const defaultMode = sandbox.defaultMode, defaultApproval = approval.config.policy ?? "ask";
|
|
116
|
+
const mode = readOnlyHistory ? "read-only" : defaultMode;
|
|
117
|
+
const approvalPolicy = oldApproval?.data.policy === "never" ? "never" : defaultApproval;
|
|
118
|
+
const check = () => {
|
|
119
|
+
this.signal.throwIfAborted();
|
|
120
|
+
permissionSignal.throwIfAborted();
|
|
121
|
+
try {
|
|
122
|
+
lease.assertCurrent();
|
|
123
|
+
profile.assertCurrent();
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
throw new HistoryRefusal("stale");
|
|
127
|
+
}
|
|
128
|
+
const current = this.ctx.get("dsmmPermissionController");
|
|
129
|
+
const currentDefault = this.ctx.get?.("agentDefaultModel");
|
|
130
|
+
if (!this.admission.isReady || original(this.ctx.agentPresets) !== original(registry) || this.modelGeneration !== generation
|
|
131
|
+
|| current === undefined || original(current) !== original(permissions) || current.rules.signal !== permissionSignal
|
|
132
|
+
|| current.rules.getPolicy().revision !== rules.revision || this.deployment.permissionSource().revision !== source.revision
|
|
133
|
+
|| captured.some((value, index) => { const now = get(services[index]); return value === undefined || now === undefined || original(value) !== original(now); })
|
|
134
|
+
|| route === undefined && (currentDefault === undefined || original(currentDefault) !== original(defaultModel) || !isDeepStrictEqual(currentDefault.currentSelection(), model))
|
|
135
|
+
|| sandbox.defaultMode !== defaultMode || (approval.config.policy ?? "ask") !== defaultApproval)
|
|
136
|
+
throw new HistoryRefusal("stale");
|
|
137
|
+
};
|
|
138
|
+
check();
|
|
139
|
+
signal.throwIfAborted();
|
|
140
|
+
return { admission: profile.admission, model, signal: AbortSignal.any([this.signal, permissionSignal]),
|
|
141
|
+
view: { preset: { id: request.preset, label: (metadata.name ?? metadata.id).slice(0, 120) }, profile: request.profileId === null ? null : { id: request.profileId, label: (profile.label ?? request.profileId).slice(0, 120) }, model,
|
|
142
|
+
roles: DSMM_ROLES.filter(role => active && settings.roles[role.id]).map(role => ({ id: role.id, label: role.name })),
|
|
143
|
+
restrictions: [`sandbox: ${mode}`, `approval: ${approvalPolicy}`, `Deepwork: ${active ? "on" : "off"}`, `DSMM Git-write guard: ${effectiveHistoryGitWriteGuard(settings, mode === "danger-full-access", active)}`],
|
|
144
|
+
differences: ["Current preset, saved configuration and current native permissions replace historical execution settings. Historical approval outcomes and temporary grants are not reused."] },
|
|
145
|
+
assertCurrent: check,
|
|
146
|
+
revalidate: async (currentSignal) => {
|
|
147
|
+
check();
|
|
148
|
+
await profile.revalidate(currentSignal);
|
|
149
|
+
await llm.resolveCallConfig(model, currentSignal);
|
|
150
|
+
check();
|
|
151
|
+
currentSignal.throwIfAborted();
|
|
152
|
+
},
|
|
153
|
+
install: async (agent, currentSignal) => {
|
|
154
|
+
check();
|
|
155
|
+
currentSignal.throwIfAborted();
|
|
156
|
+
if (scopeParentOf(agent) !== lease.key || registry.composedPreset(agent.ctx) !== request.preset
|
|
157
|
+
|| captured.some((value, index) => { const actual = registry.serviceFor(agent, services[index]) ?? agent.ctx.get(services[index]); return value === undefined || actual === undefined || original(value) !== original(actual); }))
|
|
158
|
+
throw new HistoryRefusal("stale");
|
|
159
|
+
setSandboxMode(agent.session, mode);
|
|
160
|
+
check();
|
|
161
|
+
setApprovalPolicy(agent.session, approvalPolicy);
|
|
162
|
+
check();
|
|
163
|
+
appendModeRecord(agent.session, active);
|
|
164
|
+
check();
|
|
165
|
+
await this.admission.prepareHistory(agent, profile.admission, currentSignal);
|
|
166
|
+
check();
|
|
167
|
+
currentSignal.throwIfAborted();
|
|
168
|
+
}, dispose };
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
await dispose();
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=history-candidates.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HistoryChoices, HistoryConfirmRequest, HistoryContinuationResult, HistoryFailure, HistoryJson, HistoryPreview, HistoryPreviewRequest, HistoryStatus } from "./history-types.js";
|
|
2
|
+
export declare function historySessionId(input: unknown): string;
|
|
3
|
+
export declare function historyJson(input: unknown, depth?: number, active?: Set<object>): HistoryJson;
|
|
4
|
+
export declare function parseHistoryFailure(input: unknown): HistoryFailure;
|
|
5
|
+
export declare function parseHistoryStatus(input: unknown): HistoryStatus;
|
|
6
|
+
export declare function parseHistoryChoices(input: unknown): HistoryChoices;
|
|
7
|
+
export declare function parseHistoryPreviewRequest(input: unknown): HistoryPreviewRequest;
|
|
8
|
+
export declare function parseHistoryConfirmRequest(input: unknown): HistoryConfirmRequest;
|
|
9
|
+
export declare function parseHistoryPreview(input: unknown): HistoryPreview;
|
|
10
|
+
export declare function parseHistoryResult(input: unknown): HistoryContinuationResult;
|
|
11
|
+
//# sourceMappingURL=history-codec.d.ts.map
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { isNativeSessionId, isProfileId } from "./profile-remote.js";
|
|
2
|
+
const codes = ["validation", "not-owned", "not-found", "unsupported-host", "unsupported-backend", "unavailable", "busy", "stale", "cancelled", "authorization-required", "child-owner-required", "format-unavailable", "initialization-failed"];
|
|
3
|
+
function invalid() { throw new TypeError("Invalid history continuation request or response"); }
|
|
4
|
+
function object(input, required, optional = []) {
|
|
5
|
+
if (!input || typeof input !== "object" || Array.isArray(input)
|
|
6
|
+
|| ![Object.prototype, null].includes(Object.getPrototypeOf(input)) || Object.getOwnPropertySymbols(input).length
|
|
7
|
+
|| Object.values(Object.getOwnPropertyDescriptors(input)).some(row => !Object.hasOwn(row, "value") || !row.enumerable))
|
|
8
|
+
invalid();
|
|
9
|
+
const row = input;
|
|
10
|
+
if (required.some(key => !Object.hasOwn(row, key)) || Object.keys(row).some(key => !required.includes(key) && !optional.includes(key)))
|
|
11
|
+
invalid();
|
|
12
|
+
return row;
|
|
13
|
+
}
|
|
14
|
+
function text(input, maximum = 4096) { if (typeof input !== "string" || input.length > maximum)
|
|
15
|
+
invalid(); return input; }
|
|
16
|
+
function bool(input) { if (typeof input !== "boolean")
|
|
17
|
+
invalid(); return input; }
|
|
18
|
+
function list(input, parse) { if (!Array.isArray(input))
|
|
19
|
+
invalid(); return input.map(value => parse(value)); }
|
|
20
|
+
function code(input) { if (!codes.includes(input))
|
|
21
|
+
invalid(); return input; }
|
|
22
|
+
export function historySessionId(input) { if (!isNativeSessionId(input))
|
|
23
|
+
invalid(); return input; }
|
|
24
|
+
function intentId(input) { const id = text(input, 36); if (!/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u.test(id))
|
|
25
|
+
invalid(); return id; }
|
|
26
|
+
function profileId(input) { if (input === null)
|
|
27
|
+
return null; if (!isProfileId(input))
|
|
28
|
+
invalid(); return input; }
|
|
29
|
+
function presetId(input) { return historySessionId(input); }
|
|
30
|
+
function choice(input) { const row = object(input, ["id", "label"]); return { id: text(row.id, 256), label: text(row.label, 120) }; }
|
|
31
|
+
export function historyJson(input, depth = 0, active = new Set()) {
|
|
32
|
+
if (depth > 32)
|
|
33
|
+
invalid();
|
|
34
|
+
if (input === null || typeof input === "boolean" || typeof input === "string")
|
|
35
|
+
return input;
|
|
36
|
+
if (typeof input === "number") {
|
|
37
|
+
if (!Number.isFinite(input))
|
|
38
|
+
invalid();
|
|
39
|
+
return input;
|
|
40
|
+
}
|
|
41
|
+
if (!input || typeof input !== "object")
|
|
42
|
+
invalid();
|
|
43
|
+
if (active.has(input))
|
|
44
|
+
invalid();
|
|
45
|
+
active.add(input);
|
|
46
|
+
try {
|
|
47
|
+
if (Array.isArray(input)) {
|
|
48
|
+
if (Object.getOwnPropertySymbols(input).length || Object.entries(Object.getOwnPropertyDescriptors(input)).some(([key, property]) => key !== "length" && (!/^(0|[1-9][0-9]*)$/u.test(key) || !Object.hasOwn(property, "value") || !property.enumerable)))
|
|
49
|
+
invalid();
|
|
50
|
+
return input.map(value => historyJson(value, depth + 1, active));
|
|
51
|
+
}
|
|
52
|
+
const row = object(input, Object.keys(input));
|
|
53
|
+
return Object.fromEntries(Object.entries(row).map(([key, value]) => [key, historyJson(value, depth + 1, active)]));
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
active.delete(input);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export function parseHistoryFailure(input) {
|
|
60
|
+
const row = object(input, ["code", "storageEffects"]);
|
|
61
|
+
if (row.storageEffects !== "none" && row.storageEffects !== "may-have-committed")
|
|
62
|
+
invalid();
|
|
63
|
+
return { code: code(row.code), storageEffects: row.storageEffects };
|
|
64
|
+
}
|
|
65
|
+
export function parseHistoryStatus(input) {
|
|
66
|
+
const row = object(input, ["sessionId", "readable", "execution", "compatibleHost"], ["reason"]);
|
|
67
|
+
if (row.readable !== "readable" && row.readable !== "unavailable")
|
|
68
|
+
invalid();
|
|
69
|
+
if (!["authorization-required", "activating", "active", "unavailable"].includes(String(row.execution)))
|
|
70
|
+
invalid();
|
|
71
|
+
return { sessionId: historySessionId(row.sessionId), readable: row.readable, execution: row.execution, compatibleHost: bool(row.compatibleHost), ...(row.reason === undefined ? {} : { reason: code(row.reason) }) };
|
|
72
|
+
}
|
|
73
|
+
export function parseHistoryChoices(input) {
|
|
74
|
+
const row = object(input, ["presets", "profiles"]);
|
|
75
|
+
return { presets: list(row.presets, value => { const result = choice(value); presetId(result.id); return result; }), profiles: list(row.profiles, value => { const result = choice(value); profileId(result.id); return result; }) };
|
|
76
|
+
}
|
|
77
|
+
export function parseHistoryPreviewRequest(input) {
|
|
78
|
+
const row = object(input, ["sessionId", "preset", "profileId"]);
|
|
79
|
+
return { sessionId: historySessionId(row.sessionId), preset: presetId(row.preset), profileId: profileId(row.profileId) };
|
|
80
|
+
}
|
|
81
|
+
export function parseHistoryConfirmRequest(input) {
|
|
82
|
+
const row = object(input, ["sessionId", "intentId", "processPending", "acceptMigration"]);
|
|
83
|
+
return { sessionId: historySessionId(row.sessionId), intentId: intentId(row.intentId), processPending: bool(row.processPending), acceptMigration: bool(row.acceptMigration) };
|
|
84
|
+
}
|
|
85
|
+
function candidate(input) {
|
|
86
|
+
const row = object(input, ["preset", "profile", "model", "roles", "restrictions", "differences"]);
|
|
87
|
+
const model = object(row.model, ["provider", "model"], ["reasoningEffort"]);
|
|
88
|
+
return { preset: choice(row.preset), profile: row.profile === null ? null : choice(row.profile),
|
|
89
|
+
model: { provider: text(model.provider, 256), model: text(model.model, 256), ...(model.reasoningEffort === undefined ? {} : { reasoningEffort: text(model.reasoningEffort, 128) }) },
|
|
90
|
+
roles: list(row.roles, choice), restrictions: list(row.restrictions, value => text(value)), differences: list(row.differences, value => text(value)) };
|
|
91
|
+
}
|
|
92
|
+
export function parseHistoryPreview(input) {
|
|
93
|
+
const row = object(input, ["sessionId", "intentId", "cwd", "candidate", "migrationRequired", "pending"]), pending = object(row.pending, ["nextTurn", "nextStep"]);
|
|
94
|
+
return { sessionId: historySessionId(row.sessionId), intentId: intentId(row.intentId), cwd: text(row.cwd), candidate: candidate(row.candidate), migrationRequired: bool(row.migrationRequired), pending: { nextTurn: list(pending.nextTurn, historyJson), nextStep: list(pending.nextStep, historyJson) } };
|
|
95
|
+
}
|
|
96
|
+
export function parseHistoryResult(input) {
|
|
97
|
+
const row = object(input, ["sessionId", "execution"]);
|
|
98
|
+
if (row.execution !== "active")
|
|
99
|
+
invalid();
|
|
100
|
+
return { sessionId: historySessionId(row.sessionId), execution: "active" };
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=history-codec.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Agent, ModelSelection } from "@deepseek-ai/dsh-agent";
|
|
2
|
+
import type { SessionInspection } from "@deepseek-ai/dsh-session-persistence";
|
|
3
|
+
import type { DsmmProfileAdmission } from "./settings.js";
|
|
4
|
+
import type { HistoryCandidateView, HistoryChoices, HistoryPreviewRequest } from "./history-types.js";
|
|
5
|
+
/** A current profile/preset/policy preparation, never reconstructed from old epochs or approvals. */
|
|
6
|
+
export interface HistoryCandidate {
|
|
7
|
+
readonly admission: DsmmProfileAdmission;
|
|
8
|
+
readonly view: HistoryCandidateView;
|
|
9
|
+
readonly model: ModelSelection;
|
|
10
|
+
readonly signal: AbortSignal;
|
|
11
|
+
/** Re-read current configuration and availability without touching the historical log. */
|
|
12
|
+
revalidate(signal: AbortSignal): Promise<void>;
|
|
13
|
+
/** Synchronous revision/owner/policy fence, including across native created notifications. */
|
|
14
|
+
assertCurrent(): undefined;
|
|
15
|
+
/** Install current native restrictions in the unpublished Agent; registrations belong to that Agent. */
|
|
16
|
+
install(agent: Agent, signal: AbortSignal): Promise<void>;
|
|
17
|
+
/** Release preparation resources, not successfully installed Agent policy. */
|
|
18
|
+
dispose(): void | Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export interface HistoryCandidates {
|
|
21
|
+
readonly signal: AbortSignal;
|
|
22
|
+
checkCompatibility?(): Promise<void>;
|
|
23
|
+
choices(signal: AbortSignal): Promise<HistoryChoices>;
|
|
24
|
+
prepare(request: HistoryPreviewRequest, inspection: SessionInspection, signal: AbortSignal): Promise<HistoryCandidate>;
|
|
25
|
+
}
|
|
26
|
+
/** Existing NativeAdmission surface; the bridge adds no second admission owner. */
|
|
27
|
+
export interface HistoryNativeAdmission {
|
|
28
|
+
readonly lifetime: AbortController;
|
|
29
|
+
readonly isReady: boolean;
|
|
30
|
+
get(agent: Agent): DsmmProfileAdmission | undefined;
|
|
31
|
+
assert(agent: Agent): DsmmProfileAdmission;
|
|
32
|
+
}
|
|
33
|
+
/** Host-created identity. None of these fields is accepted from the wire. */
|
|
34
|
+
export interface HistoryOperator {
|
|
35
|
+
readonly peer: object;
|
|
36
|
+
readonly connection: object;
|
|
37
|
+
readonly peerSignal: AbortSignal;
|
|
38
|
+
readonly signal: AbortSignal;
|
|
39
|
+
assertCurrent(): void;
|
|
40
|
+
/** Does not retain a completed preview RPC's cancellation signal. */
|
|
41
|
+
assertOwner(): void;
|
|
42
|
+
assertVisible(sessionId: string): void;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=history-contract.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Service } from "@deepseek-ai/cordis";
|
|
2
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
3
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
4
|
+
import type { DsmmProfileAdmission } from "./settings.js";
|
|
5
|
+
import type { HistoryCandidates, HistoryNativeAdmission, HistoryOperator } from "./history-contract.js";
|
|
6
|
+
import type { HistoryChoices, HistoryConfirmRequest, HistoryContinuationResult, HistoryFailure, HistoryFailureCode, HistoryPreview, HistoryPreviewRequest, HistoryStatus } from "./history-types.js";
|
|
7
|
+
export declare class HistoryRefusal extends Error {
|
|
8
|
+
readonly code: HistoryFailureCode;
|
|
9
|
+
readonly storageEffects: HistoryFailure["storageEffects"];
|
|
10
|
+
constructor(code: HistoryFailureCode, storageEffects?: HistoryFailure["storageEffects"]);
|
|
11
|
+
}
|
|
12
|
+
/** Host-only one-operation intents around the native history and activation APIs. */
|
|
13
|
+
export declare class HistoryContinuations extends Service {
|
|
14
|
+
private readonly candidates;
|
|
15
|
+
private readonly admission;
|
|
16
|
+
readonly lifetime: AbortController;
|
|
17
|
+
private readonly intents;
|
|
18
|
+
private readonly prepared;
|
|
19
|
+
private guardedLoop;
|
|
20
|
+
private readonly cleanups;
|
|
21
|
+
constructor(ctx: Context, candidates: HistoryCandidates, admission: HistoryNativeAdmission);
|
|
22
|
+
private compatibility;
|
|
23
|
+
private visible;
|
|
24
|
+
private ready;
|
|
25
|
+
private compatible;
|
|
26
|
+
describe(input: string, operator: HistoryOperator): Promise<HistoryStatus>;
|
|
27
|
+
choices(operator: HistoryOperator): Promise<HistoryChoices>;
|
|
28
|
+
preview(input: HistoryPreviewRequest, operator: HistoryOperator): Promise<HistoryPreview>;
|
|
29
|
+
private check;
|
|
30
|
+
/** Called only by NativeAdmission.created for the exact unpublished continuation candidate. */
|
|
31
|
+
admissionForCreated(agent: Agent): DsmmProfileAdmission | undefined;
|
|
32
|
+
private authorize;
|
|
33
|
+
confirm(input: HistoryConfirmRequest, operator: HistoryOperator): Promise<HistoryContinuationResult>;
|
|
34
|
+
private release;
|
|
35
|
+
}
|
|
36
|
+
declare module "@deepseek-ai/cordis" {
|
|
37
|
+
interface Context {
|
|
38
|
+
dsmmHistoryContinuation: HistoryContinuations;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export declare function historyFailure(error: unknown): HistoryFailure;
|
|
42
|
+
//# sourceMappingURL=history-controller.d.ts.map
|