@dsmm/dsmm 0.3.2 → 0.3.3
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 +2 -2
- package/cordis.patch.yml +0 -9
- package/docs/agent-presets.md +5 -5
- package/docs/compatibility.md +2 -6
- package/docs/migration-from-ocmm.md +1 -1
- package/docs/roadmap.md +5 -12
- package/docs/settings-status.md +1 -1
- package/lib/client/ChildrenPanel.d.ts +1 -4
- package/lib/client/ChildrenPanel.js +3 -3
- package/lib/client/DeploymentPage.d.ts +1 -3
- package/lib/client/DeploymentPage.js +2 -2
- package/lib/client/PermissionsPanel.d.ts +1 -3
- package/lib/client/PermissionsPanel.js +2 -3
- package/lib/client/children-locales.d.ts +4 -4
- package/lib/client/controller.js +4 -1
- package/lib/client/deployment-locales.js +0 -1
- package/lib/client/deployment-modules.js +1 -1
- package/lib/client/index.js +2 -7
- package/lib/client/locales.js +131 -119
- package/lib/client/permission-locales.d.ts +0 -26
- package/lib/client/permission-locales.js +0 -20
- package/lib/client.js +1837 -3634
- package/lib/index.d.ts +0 -2
- package/lib/index.js +9 -22
- package/lib/native-admission.d.ts +0 -3
- package/lib/native-admission.js +12 -45
- package/lib/permission-fs-search.js +1 -2
- package/lib/permission-fs.js +1 -2
- package/lib/permission-web.js +1 -2
- package/lib/preset-materializer.js +3 -3
- package/lib/preset-registry.d.ts +20 -2
- package/lib/preset-registry.js +46 -17
- package/lib/profile-diagnostics.js +1 -1
- package/lib/profile-remote.js +1 -3
- package/lib/role-policy.js +2 -2
- package/lib/role-subagents.js +2 -1
- package/lib/roles.d.ts +2 -0
- package/lib/roles.js +2 -0
- package/lib/settings.d.ts +1 -3
- package/lib/settings.js +4 -9
- package/package.json +1 -5
- package/lib/client/ChildPermissions.d.ts +0 -43
- package/lib/client/ChildPermissions.js +0 -100
- package/lib/client/HistoryContinuation.d.ts +0 -7
- package/lib/client/HistoryContinuation.js +0 -22
- package/lib/client/PermissionPanelEntry.d.ts +0 -8
- package/lib/client/PermissionPanelEntry.js +0 -11
- package/lib/client/TemporaryPermissions.d.ts +0 -21
- package/lib/client/TemporaryPermissions.js +0 -94
- package/lib/client/history-controller.d.ts +0 -29
- package/lib/client/history-controller.js +0 -111
- package/lib/client/history-entry.d.ts +0 -11
- package/lib/client/history-entry.js +0 -106
- package/lib/client/history-locales.d.ts +0 -95
- package/lib/client/history-locales.js +0 -41
- package/lib/client/temporary-permission-client.d.ts +0 -20
- package/lib/client/temporary-permission-client.js +0 -52
- package/lib/client/temporary-permission-entry.d.ts +0 -6
- package/lib/client/temporary-permission-entry.js +0 -56
- package/lib/history-candidates.d.ts +0 -30
- package/lib/history-candidates.js +0 -176
- package/lib/history-codec.d.ts +0 -11
- package/lib/history-codec.js +0 -102
- package/lib/history-contract.d.ts +0 -44
- package/lib/history-contract.js +0 -2
- package/lib/history-controller.d.ts +0 -42
- package/lib/history-controller.js +0 -329
- package/lib/history-policy.d.ts +0 -4
- package/lib/history-policy.js +0 -8
- package/lib/history-remote.d.ts +0 -28
- package/lib/history-remote.js +0 -17
- package/lib/history-rpc.d.ts +0 -24
- package/lib/history-rpc.js +0 -136
- package/lib/history-support.d.ts +0 -15
- package/lib/history-support.js +0 -21
- package/lib/history-types.d.ts +0 -67
- package/lib/history-types.js +0 -2
- package/lib/permission-child-control.d.ts +0 -36
- package/lib/permission-child-control.js +0 -164
- package/lib/permission-exec-argv.d.ts +0 -32
- package/lib/permission-exec-argv.js +0 -171
- package/lib/permission-temporary-files.d.ts +0 -19
- package/lib/permission-temporary-files.js +0 -248
- package/lib/permission-temporary-grants.d.ts +0 -106
- package/lib/permission-temporary-grants.js +0 -198
- package/lib/permission-temporary-install.d.ts +0 -25
- package/lib/permission-temporary-install.js +0 -86
- package/lib/permission-temporary-remote.d.ts +0 -19
- package/lib/permission-temporary-remote.js +0 -75
- package/lib/permission-temporary-rpc.d.ts +0 -37
- package/lib/permission-temporary-rpc.js +0 -154
- package/lib/permission-temporary-types.d.ts +0 -47
- package/lib/permission-temporary-types.js +0 -2
- package/lib/permission-temporary-web.d.ts +0 -11
- package/lib/permission-temporary-web.js +0 -154
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-gateway@0.2.1-rc.2.patch +0 -13291
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-remotes@0.2.1-rc.2.patch +0 -9133
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-client-ui-approval@0.2.1-rc.2.patch +0 -156
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-subagent@0.2.1-rc.2.patch +0 -3546
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-user-approval@0.2.1-rc.2.patch +0 -431
- package/patches/dsh-approval-settlement/@deepseek-ai__dsh-web@0.2.1-rc.2.patch +0 -119
- package/patches/dsh-approval-settlement/README.md +0 -41
- package/patches/dsh-approval-settlement/metadata.json +0 -10
- package/patches/dsh-session-activation/@deepseek-ai__dsh-agent-loop@0.2.1-rc.2.patch +0 -383
- package/patches/dsh-session-activation/@deepseek-ai__dsh-agent-preset-registry@0.2.1-rc.2.patch +0 -55
- package/patches/dsh-session-activation/@deepseek-ai__dsh-api-session-controller@0.2.1-rc.2.patch +0 -16673
- package/patches/dsh-session-activation/@deepseek-ai__dsh-client-ui-subagent@0.2.1-rc.2.patch +0 -29
- package/patches/dsh-session-activation/@deepseek-ai__dsh-client-ui-workspace@0.2.1-rc.2.patch +0 -196
- package/patches/dsh-session-activation/@deepseek-ai__dsh-session-persistence-jsonl@0.2.1-rc.2.patch +0 -35
- package/patches/dsh-session-activation/@deepseek-ai__dsh-session-persistence@0.2.1-rc.2.patch +0 -40
|
@@ -1,431 +0,0 @@
|
|
|
1
|
-
diff --git a/lib/index.js b/lib/index.js
|
|
2
|
-
index d48f06f95967c12a191dcc297ae5918e5c5e5aef..d9dbf1e97a9532dc2a96f0f8ddd019540c5d281b 100644
|
|
3
|
-
--- a/lib/index.js
|
|
4
|
-
+++ b/lib/index.js
|
|
5
|
-
@@ -1,192 +1 @@
|
|
6
|
-
-import { randomUUID } from "node:crypto";
|
|
7
|
-
-import { Service } from "@deepseek-ai/cordis";
|
|
8
|
-
-import z from "@deepseek-ai/schemastery";
|
|
9
|
-
-import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
10
|
-
-import { scopeTarget } from "@deepseek-ai/dsh-scope";
|
|
11
|
-
-import { SessionSeq } from "@deepseek-ai/dsh-session";
|
|
12
|
-
-//#region lib/types/types.js
|
|
13
|
-
-/**
|
|
14
|
-
-* Wire-safe approval identifiers and outcome vocabulary, free of
|
|
15
|
-
-* cordis/service imports so browser type chains can
|
|
16
|
-
-* consume them without loading this package's Context augmentation.
|
|
17
|
-
-* @module @deepseek-ai/dsh-user-approval/types
|
|
18
|
-
-*/
|
|
19
|
-
-/**
|
|
20
|
-
-* Brand a string as an {@link ApprovalRequestId}.
|
|
21
|
-
-* @param id - the raw id string to brand.
|
|
22
|
-
-* @returns the same string carrying the brand.
|
|
23
|
-
-*/
|
|
24
|
-
-function ApprovalRequestId(id) {
|
|
25
|
-
- return id;
|
|
26
|
-
-}
|
|
27
|
-
-//#endregion
|
|
28
|
-
-//#region lib/types/index.js
|
|
29
|
-
-/**
|
|
30
|
-
-* Service Definition for the approval capability seam, covering requests, cancellation, audit, and per-session policy. Missing
|
|
31
|
-
-* answerers fail closed; grants apply only to the requested action.
|
|
32
|
-
-* @module @deepseek-ai/dsh-user-approval
|
|
33
|
-
-*/
|
|
34
|
-
-/** Every {@link ApprovalOutcome}, for runtime normalization of answerer returns. */
|
|
35
|
-
-const OUTCOMES = [
|
|
36
|
-
- "allowed-once",
|
|
37
|
-
- "rejected",
|
|
38
|
-
- "cancelled",
|
|
39
|
-
- "unavailable"
|
|
40
|
-
-];
|
|
41
|
-
-/** Every {@link ApprovalPolicy}, for option advertisement and runtime validation of untrusted policy strings. */
|
|
42
|
-
-const APPROVAL_POLICIES = ["ask", "never"];
|
|
43
|
-
-/** Model-facing statement for the deterministic `'never'` policy. */
|
|
44
|
-
-const NEVER_SENTENCE = "Approval prompts are disabled in this session: actions that require approval are rejected automatically — do not request sandbox escalation (do not set `sandbox_permissions`).";
|
|
45
|
-
-/** Model-facing statement for an interactive policy that may still fail closed. */
|
|
46
|
-
-const ASK_SENTENCE = "Approval policy: ask. Operations that require approval may ask through the configured answerers; without an available answerer, the request fails closed.";
|
|
47
|
-
-/**
|
|
48
|
-
-* Whether the log currently sits inside an open turn (a `turn/start` not yet
|
|
49
|
-
-* closed by a `turn/end`) — the {@link ApprovalService.request} precondition.
|
|
50
|
-
-* The audit pair must be turn-enclosed: the turn is the durable log's
|
|
51
|
-
-* commit/replay boundary, so a bare event appended between turns is
|
|
52
|
-
-* indistinguishable from a crash tail and silently dropped on reload.
|
|
53
|
-
-*/
|
|
54
|
-
-function hasOpenTurn(session) {
|
|
55
|
-
- for (let seq = session.seq - 1; seq >= 0; seq -= 1) {
|
|
56
|
-
- const type = session.eventAt(SessionSeq(seq))?.type;
|
|
57
|
-
- if (type === "turn/start") return true;
|
|
58
|
-
- if (type === "turn/end") return false;
|
|
59
|
-
- }
|
|
60
|
-
- return false;
|
|
61
|
-
-}
|
|
62
|
-
-/**
|
|
63
|
-
-* Append the sole durable representation of a session policy override. Invalid
|
|
64
|
-
-* values throw before the log changes; consumers fold the new value on each read.
|
|
65
|
-
-* @param session - the session the override belongs to.
|
|
66
|
-
-* @param policy - the policy in effect until the next switch.
|
|
67
|
-
-*/
|
|
68
|
-
-function setApprovalPolicy(session, policy) {
|
|
69
|
-
- if (!APPROVAL_POLICIES.includes(policy)) throw new TypeError("approval policy must be one of \"ask\" or \"never\"");
|
|
70
|
-
- session.append("approval/policy", { policy });
|
|
71
|
-
-}
|
|
72
|
-
-/**
|
|
73
|
-
-* Approval service that applies session policy before answerers and logs every
|
|
74
|
-
-* ask/outcome pair to the requesting session. It exposes deterministic policy
|
|
75
|
-
-* changes to the model through the runtime-context snapshot and switch notices.
|
|
76
|
-
-*/
|
|
77
|
-
-var ApprovalService = class extends Service {
|
|
78
|
-
- config;
|
|
79
|
-
- static Config = z.object({ policy: z.union(["ask", "never"]).default("ask") });
|
|
80
|
-
- constructor(ctx, config) {
|
|
81
|
-
- super(ctx, "approval");
|
|
82
|
-
- this.config = config;
|
|
83
|
-
- const effective = (agent) => this.effectivePolicy(agent.session);
|
|
84
|
-
- ctx.inject(["systemPrompt"], (scope) => {
|
|
85
|
-
- scope.systemPrompt.context({
|
|
86
|
-
- name: "approval:policy",
|
|
87
|
-
- order: scope.systemPrompt.getContextOrder("APPROVAL_POLICY"),
|
|
88
|
-
- text: (context) => {
|
|
89
|
-
- const agent = context.agent;
|
|
90
|
-
- if (agent === void 0) return "";
|
|
91
|
-
- return effective(agent) === "never" ? NEVER_SENTENCE : ASK_SENTENCE;
|
|
92
|
-
- }
|
|
93
|
-
- });
|
|
94
|
-
- });
|
|
95
|
-
- }
|
|
96
|
-
- /**
|
|
97
|
-
- * Switch one live agent's policy and queue the transition for its next model
|
|
98
|
-
- * step. Session initialization uses {@link setApprovalPolicy} directly
|
|
99
|
-
- * because there is no previously visible policy to change.
|
|
100
|
-
- * @param agent - the live agent whose policy is changing.
|
|
101
|
-
- * @param policy - the new effective policy.
|
|
102
|
-
- */
|
|
103
|
-
- setPolicy(agent, policy) {
|
|
104
|
-
- const previous = this.effectivePolicy(agent.session);
|
|
105
|
-
- if (previous === policy) return;
|
|
106
|
-
- setApprovalPolicy(agent.session, policy);
|
|
107
|
-
- agent.inject(createUserMessage({
|
|
108
|
-
- content: [{
|
|
109
|
-
- type: "text",
|
|
110
|
-
- text: `The approval policy changed from "${previous}" to "${policy}" (changed by the user).`
|
|
111
|
-
- }],
|
|
112
|
-
- source: { kind: "user-approval" }
|
|
113
|
-
- }));
|
|
114
|
-
- }
|
|
115
|
-
- /**
|
|
116
|
-
- * Ask the composed answerers to decide one readonly same-process request.
|
|
117
|
-
- * The service borrows the request, agent, session, and live signal directly.
|
|
118
|
-
- * The request requires an open turn because the audit pair must be enclosed
|
|
119
|
-
- * by the durable log's commit/replay boundary; an idle ask rejects before
|
|
120
|
-
- * appending anything. The answerer phase always produces an outcome: an
|
|
121
|
-
- * aborted signal yields `'cancelled'`, a missing or throwing answerer yields
|
|
122
|
-
- * `'unavailable'` (fail closed), and a rogue non-vocabulary return value is
|
|
123
|
-
- * normalized to `'unavailable'`. A failure that prevents either audit append
|
|
124
|
-
- * from committing still rejects because returning an unlogged decision would
|
|
125
|
-
- * violate the pair. Session contains post-commit observer failures, so an
|
|
126
|
-
- * authoritative append cannot reject the request or suppress its matching
|
|
127
|
-
- * audit event.
|
|
128
|
-
- * @param req - the pending decision (agent, tool identity, reason, signal).
|
|
129
|
-
- * @returns the closed outcome; `'allowed-once'` is the only grant.
|
|
130
|
-
- * @throws when no turn is open or either audit event fails before the session
|
|
131
|
-
- * append commit point.
|
|
132
|
-
- */
|
|
133
|
-
- async request(req) {
|
|
134
|
-
- const session = req.agent.session;
|
|
135
|
-
- if (!hasOpenTurn(session)) throw new Error("approval.request() outside an open turn: the approval/asked + approval/decided audit pair must be turn-enclosed (a bare event between turns is crash-tail garbage on reload). Ask from inside the turn that needs the decision.");
|
|
136
|
-
- const id = ApprovalRequestId(randomUUID());
|
|
137
|
-
- session.append("approval/asked", {
|
|
138
|
-
- id,
|
|
139
|
-
- toolName: req.toolName,
|
|
140
|
-
- ...req.callId !== void 0 ? { callId: req.callId } : {},
|
|
141
|
-
- ...req.reason !== void 0 ? { reason: req.reason } : {}
|
|
142
|
-
- });
|
|
143
|
-
- const outcome = await this.decide(req, session);
|
|
144
|
-
- session.append("approval/decided", {
|
|
145
|
-
- id,
|
|
146
|
-
- outcome
|
|
147
|
-
- });
|
|
148
|
-
- return outcome;
|
|
149
|
-
- }
|
|
150
|
-
- /**
|
|
151
|
-
- * The session's effective policy: its own `approval/policy` fold, else the
|
|
152
|
-
- * configured default (the schema already defaulted an omitted policy to
|
|
153
|
-
- * `'ask'`; the `??` only narrows the optional-input TYPE).
|
|
154
|
-
- * @param session - the exact accepted session whose policy applies.
|
|
155
|
-
- * @returns the policy every ask for this session resolves under right now.
|
|
156
|
-
- */
|
|
157
|
-
- effectivePolicy(session) {
|
|
158
|
-
- return this.overrideOf(session) ?? this.config.policy ?? "ask";
|
|
159
|
-
- }
|
|
160
|
-
- /**
|
|
161
|
-
- * Read the session override without applying the configured default.
|
|
162
|
-
- * @param session - session whose log supplies the override.
|
|
163
|
-
- * @returns the last logged policy, or `undefined` without one.
|
|
164
|
-
- */
|
|
165
|
-
- overrideOf(session) {
|
|
166
|
-
- for (let seq = session.seq - 1; seq >= 0; seq -= 1) {
|
|
167
|
-
- const event = session.eventAt(SessionSeq(seq));
|
|
168
|
-
- if (event?.type === "approval/policy") return event.data.policy;
|
|
169
|
-
- }
|
|
170
|
-
- }
|
|
171
|
-
- /**
|
|
172
|
-
- * Dispatch the waterfall, contained and raced against the request signal.
|
|
173
|
-
- * @param req - the borrowed public request.
|
|
174
|
-
- * @param session - the request agent's session used for policy lookup.
|
|
175
|
-
- * @returns the normalized closed outcome.
|
|
176
|
-
- */
|
|
177
|
-
- async decide(req, session) {
|
|
178
|
-
- const signal = req.signal;
|
|
179
|
-
- if (signal?.aborted) return "cancelled";
|
|
180
|
-
- if (this.effectivePolicy(session) === "never") return "rejected";
|
|
181
|
-
- const answer = Promise.resolve().then(() => this.ctx.waterfall(scopeTarget(req.agent, req.agent), "approval/request", req, () => Promise.resolve("unavailable"))).then((outcome) => OUTCOMES.includes(outcome) ? outcome : "unavailable", () => "unavailable");
|
|
182
|
-
- if (signal === void 0) return answer;
|
|
183
|
-
- return await new Promise((resolve) => {
|
|
184
|
-
- const onAbort = () => {
|
|
185
|
-
- signal.removeEventListener("abort", onAbort);
|
|
186
|
-
- resolve("cancelled");
|
|
187
|
-
- };
|
|
188
|
-
- signal.addEventListener("abort", onAbort, { once: true });
|
|
189
|
-
- answer.then((outcome) => {
|
|
190
|
-
- signal.removeEventListener("abort", onAbort);
|
|
191
|
-
- resolve(outcome);
|
|
192
|
-
- });
|
|
193
|
-
- });
|
|
194
|
-
- }
|
|
195
|
-
-};
|
|
196
|
-
-//#endregion
|
|
197
|
-
-export { APPROVAL_POLICIES, ApprovalRequestId, ApprovalService, ApprovalService as default, setApprovalPolicy };
|
|
198
|
-
+import{randomUUID as randomUUID2}from"node:crypto";import{Service}from"@deepseek-ai/cordis";import z from"@deepseek-ai/schemastery";import{createUserMessage}from"@deepseek-ai/dsh-llm";import{scopeTarget}from"@deepseek-ai/dsh-scope";import{SessionSeq}from"@deepseek-ai/dsh-session";function ApprovalRequestId(id){return id}import{randomUUID}from"node:crypto";var adapters=new WeakMap;function approvalAdapter(callback){const listener=function(...args){return callback.apply(this,args)};Object.defineProperty(listener,"bind",{value(receiver){const bound=Function.prototype.bind.call(this,receiver);adapters.set(bound,true);return bound}});return listener}var ApprovalSettlements=class{generation=randomUUID();active=new WeakMap;receipts=new Map;observers=new Set;open(request,id){const state={request,id,closed:false,source:"unknown",winner:void 0};const group=this.active.get(request)??new Set;group.add(state);this.active.set(request,group);return state}identity(request){const states=this.active.get(request);return states?.size===1?states.values().next().value.id:void 0}close(state,outcome,auditSeq){state.closed=true;const states=this.active.get(state.request);states?.delete(state);if(!states?.size)this.active.delete(state.request);if(auditSeq===void 0)return;const receipt=Object.freeze({requestId:state.id,generation:this.generation,outcome,auditSeq,source:state.source,winner:state.winner});this.receipts.set(state.id,receipt);while(this.receipts.size>1024)this.receipts.delete(this.receipts.keys().next().value);for(const observer of this.observers){try{Promise.resolve(observer(receipt)).catch(()=>{})}catch{}}return receipt}async dispatch(ctx,target,request,state){const args=[target,"approval/request",request];const callbacks=ctx.events.dispatch("waterfall",args);let cursor=0;const invoke=()=>{const callback=callbacks[cursor++];if(callback===void 0)return Promise.resolve({value:"unavailable",source:"unknown"});const adapter=adapters.get(callback);let calls=0,child,completed=false,evidence;const next=()=>{calls++;const work=invoke();return work.then(result3=>{child=result3;completed=true;return result3.value})};const link=adapter===void 0?void 0:Object.freeze({requestId:state.id,accept(winner){if(state.closed||evidence!==void 0)return;evidence=winner;state.winner=winner}});let result2;try{result2=callback(request,next,link)}catch(error){return Promise.reject(error)}return Promise.resolve(result2).then(value=>{let source="unknown";if(adapter!==void 0){if(calls===0&&evidence?.candidate===value)source=evidence.source;else if(calls===1&&completed&&child?.value===value&&evidence===void 0)source=child.source}return{value,source}})};const result=await invoke();if(!state.closed)state.source=result.source;return result.value}};var OUTCOMES=["allowed-once","rejected","cancelled","unavailable"];var APPROVAL_POLICIES=["ask","never"];var NEVER_SENTENCE="Approval prompts are disabled in this session: actions that require approval are rejected automatically \u2014 do not request sandbox escalation (do not set `sandbox_permissions`).";var ASK_SENTENCE="Approval policy: ask. Operations that require approval may ask through the configured answerers; without an available answerer, the request fails closed.";function hasOpenTurn(session){for(let seq=session.seq-1;seq>=0;seq-=1){const type=session.eventAt(SessionSeq(seq))?.type;if(type==="turn/start")return true;if(type==="turn/end")return false}return false}function setApprovalPolicy(session,policy){if(!APPROVAL_POLICIES.includes(policy)){throw new TypeError('approval policy must be one of "ask" or "never"')}session.append("approval/policy",{policy})}var ApprovalService=class extends Service{settlements=new ApprovalSettlements;requestIdentity(request){return this.settlements.identity(request)}settlement(id){return this.settlements.receipts.get(id)}forgetSettlement(id){this.settlements.receipts.delete(id)}onSettlement(observer){this.settlements.observers.add(observer);return()=>this.settlements.observers.delete(observer)}createForwarder(callback){return approvalAdapter(callback)}config;static Config=z.object({policy:z.union(["ask","never"]).default("ask")});constructor(ctx,config){super(ctx,"approval");this.config=config;const effective=agent=>this.effectivePolicy(agent.session);ctx.inject(["systemPrompt"],scope=>{scope.systemPrompt.context({name:"approval:policy",order:scope.systemPrompt.getContextOrder("APPROVAL_POLICY"),text:context=>{const agent=context.agent;if(agent===void 0)return"";const policy=effective(agent);return policy==="never"?NEVER_SENTENCE:ASK_SENTENCE}})})}setPolicy(agent,policy){const previous=this.effectivePolicy(agent.session);if(previous===policy)return;setApprovalPolicy(agent.session,policy);agent.inject(createUserMessage({content:[{type:"text",text:`The approval policy changed from "${previous}" to "${policy}" (changed by the user).`}],source:{kind:"user-approval"}}))}async request(req,options){const session=req.agent.session;if(!hasOpenTurn(session)){throw new Error("approval.request() outside an open turn: the approval/asked + approval/decided audit pair must be turn-enclosed (a bare event between turns is crash-tail garbage on reload). Ask from inside the turn that needs the decision.")}const id=ApprovalRequestId(randomUUID2());const state=this.settlements.open(req,id);try{options?.opened?.(id);session.append("approval/asked",{id,toolName:req.toolName,...req.callId!==void 0?{callId:req.callId}:{},...req.reason!==void 0?{reason:req.reason}:{}});const outcome=await this.decide(req,session,state);session.append("approval/decided",{id,outcome});this.settlements.close(state,outcome,session.seq-1);return outcome}finally{if(!state.closed)this.settlements.close(state)}}effectivePolicy(session){return this.overrideOf(session)??this.config.policy??"ask"}overrideOf(session){for(let seq=session.seq-1;seq>=0;seq-=1){const event=session.eventAt(SessionSeq(seq));if(event?.type==="approval/policy")return event.data.policy}return void 0}async decide(req,session,state){const signal=req.signal;if(signal?.aborted)return"cancelled";if(this.effectivePolicy(session)==="never")return"rejected";const answer=Promise.resolve().then(()=>this.settlements.dispatch(this.ctx,scopeTarget(req.agent,req.agent),req,state)).then(outcome=>OUTCOMES.includes(outcome)?outcome:"unavailable",()=>"unavailable");if(signal===void 0)return answer;return await new Promise(resolve=>{const onAbort=()=>{signal.removeEventListener("abort",onAbort);resolve("cancelled")};signal.addEventListener("abort",onAbort,{once:true});void answer.then(outcome=>{signal.removeEventListener("abort",onAbort);resolve(outcome)})})}};var index_default=ApprovalService;export{APPROVAL_POLICIES,ApprovalRequestId,ApprovalService,index_default as default,setApprovalPolicy};
|
|
199
|
-
diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts
|
|
200
|
-
index ceac86ed47bb929a66367789eaea5420e9bcc055..3e735b0f718b7e2292898d37d18e01f44e87310b 100644
|
|
201
|
-
--- a/lib/types/index.d.ts
|
|
202
|
-
+++ b/lib/types/index.d.ts
|
|
203
|
-
@@ -39,6 +39,9 @@ declare module '@deepseek-ai/dsh-session/types' {
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
import type { ApprovalOutcome, ApprovalRequestEvent } from './types.ts';
|
|
207
|
-
+import type { ApprovalRequestId } from './types.ts';
|
|
208
|
-
+import type { ApprovalSettlement, ApprovalForwarding } from './settlement.js';
|
|
209
|
-
+export type { ApprovalSettlement, ApprovalWinner, ApprovalForwarding } from './settlement.js';
|
|
210
|
-
export { ApprovalRequestId } from './types.ts';
|
|
211
|
-
export type { ApprovalOutcome } from './types.ts';
|
|
212
|
-
/**
|
|
213
|
-
@@ -103,6 +106,12 @@ export interface Config {
|
|
214
|
-
* changes to the model through the runtime-context snapshot and switch notices.
|
|
215
|
-
*/
|
|
216
|
-
export declare class ApprovalService extends Service {
|
|
217
|
-
+ requestIdentity(request: ApprovalRequest): ApprovalRequestId | undefined;
|
|
218
|
-
+ settlement(id: ApprovalRequestId): ApprovalSettlement | undefined;
|
|
219
|
-
+ forgetSettlement(id: ApprovalRequestId): void;
|
|
220
|
-
+ onSettlement(observer: (receipt: ApprovalSettlement) => void): () => void;
|
|
221
|
-
+ /** Trusted Host adapter registration; never use this for an unreviewed listener. */
|
|
222
|
-
+ createForwarder(callback: (this: unknown, request: ApprovalRequest, next: () => Promise<ApprovalOutcome>, link: ApprovalForwarding) => Promise<ApprovalOutcome>): (request: ApprovalRequest, next: () => Promise<ApprovalOutcome>) => Promise<ApprovalOutcome>;
|
|
223
|
-
config: Config;
|
|
224
|
-
static Config: z<Config>;
|
|
225
|
-
constructor(ctx: Context, config: Config);
|
|
226
|
-
@@ -132,7 +141,7 @@ export declare class ApprovalService extends Service {
|
|
227
|
-
* @throws when no turn is open or either audit event fails before the session
|
|
228
|
-
* append commit point.
|
|
229
|
-
*/
|
|
230
|
-
- request(req: ApprovalRequest): Promise<ApprovalOutcome>;
|
|
231
|
-
+ request(req: ApprovalRequest, options?: { opened(id: ApprovalRequestId): void }): Promise<ApprovalOutcome>;
|
|
232
|
-
/**
|
|
233
|
-
* The session's effective policy: its own `approval/policy` fold, else the
|
|
234
|
-
* configured default (the schema already defaulted an omitted policy to
|
|
235
|
-
diff --git a/lib/types/index.js b/lib/types/index.js
|
|
236
|
-
index 7e3b95ecfeeb1b0f063a7806fac06ab48af392fc..09b4e6718e46df3865782d54690e880dbe0b96e9 100644
|
|
237
|
-
--- a/lib/types/index.js
|
|
238
|
-
+++ b/lib/types/index.js
|
|
239
|
-
@@ -10,6 +10,7 @@ import { createUserMessage } from '@deepseek-ai/dsh-llm';
|
|
240
|
-
import { scopeTarget } from '@deepseek-ai/dsh-scope';
|
|
241
|
-
import { SessionSeq } from '@deepseek-ai/dsh-session';
|
|
242
|
-
import { ApprovalRequestId } from "./types.js";
|
|
243
|
-
+import { ApprovalSettlements, approvalAdapter } from './settlement.js';
|
|
244
|
-
export { ApprovalRequestId } from "./types.js";
|
|
245
|
-
/** Every {@link ApprovalOutcome}, for runtime normalization of answerer returns. */
|
|
246
|
-
const OUTCOMES = ['allowed-once', 'rejected', 'cancelled', 'unavailable'];
|
|
247
|
-
@@ -55,6 +56,15 @@ export function setApprovalPolicy(session, policy) {
|
|
248
|
-
* changes to the model through the runtime-context snapshot and switch notices.
|
|
249
|
-
*/
|
|
250
|
-
export class ApprovalService extends Service {
|
|
251
|
-
+ settlements = new ApprovalSettlements();
|
|
252
|
-
+ requestIdentity(request) { return this.settlements.identity(request); }
|
|
253
|
-
+ settlement(id) { return this.settlements.receipts.get(id); }
|
|
254
|
-
+ forgetSettlement(id) { this.settlements.receipts.delete(id); }
|
|
255
|
-
+ onSettlement(observer) {
|
|
256
|
-
+ this.settlements.observers.add(observer);
|
|
257
|
-
+ return () => this.settlements.observers.delete(observer);
|
|
258
|
-
+ }
|
|
259
|
-
+ createForwarder(callback) { return approvalAdapter(callback); }
|
|
260
|
-
config;
|
|
261
|
-
static Config = z.object({
|
|
262
|
-
policy: z.union(['ask', 'never']).default('ask'),
|
|
263
|
-
@@ -118,7 +128,7 @@ export class ApprovalService extends Service {
|
|
264
|
-
* @throws when no turn is open or either audit event fails before the session
|
|
265
|
-
* append commit point.
|
|
266
|
-
*/
|
|
267
|
-
- async request(req) {
|
|
268
|
-
+ async request(req, options) {
|
|
269
|
-
const session = req.agent.session;
|
|
270
|
-
if (!hasOpenTurn(session)) {
|
|
271
|
-
throw new Error('approval.request() outside an open turn: the approval/asked + approval/decided audit pair '
|
|
272
|
-
@@ -126,15 +136,22 @@ export class ApprovalService extends Service {
|
|
273
|
-
+ 'Ask from inside the turn that needs the decision.');
|
|
274
|
-
}
|
|
275
|
-
const id = ApprovalRequestId(randomUUID());
|
|
276
|
-
+ const state = this.settlements.open(req, id);
|
|
277
|
-
+ try {
|
|
278
|
-
+ options?.opened?.(id);
|
|
279
|
-
session.append('approval/asked', {
|
|
280
|
-
id,
|
|
281
|
-
toolName: req.toolName,
|
|
282
|
-
...req.callId !== undefined ? { callId: req.callId } : {},
|
|
283
|
-
...req.reason !== undefined ? { reason: req.reason } : {},
|
|
284
|
-
});
|
|
285
|
-
- const outcome = await this.decide(req, session);
|
|
286
|
-
+ const outcome = await this.decide(req, session, state);
|
|
287
|
-
session.append('approval/decided', { id, outcome });
|
|
288
|
-
+ this.settlements.close(state, outcome, session.seq - 1);
|
|
289
|
-
return outcome;
|
|
290
|
-
+ } finally {
|
|
291
|
-
+ if (!state.closed) this.settlements.close(state);
|
|
292
|
-
+ }
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* The session's effective policy: its own `approval/policy` fold, else the
|
|
296
|
-
@@ -166,7 +183,7 @@ export class ApprovalService extends Service {
|
|
297
|
-
* @param session - the request agent's session used for policy lookup.
|
|
298
|
-
* @returns the normalized closed outcome.
|
|
299
|
-
*/
|
|
300
|
-
- async decide(req, session) {
|
|
301
|
-
+ async decide(req, session, state) {
|
|
302
|
-
const signal = req.signal;
|
|
303
|
-
if (signal?.aborted)
|
|
304
|
-
return 'cancelled';
|
|
305
|
-
@@ -181,7 +198,7 @@ export class ApprovalService extends Service {
|
|
306
|
-
// SYNCHRONOUSLY (before its first await) must land in the same rejection
|
|
307
|
-
// path as an async one — `Promise.resolve(call())` would let it escape
|
|
308
|
-
// the containment into the caller.
|
|
309
|
-
- const answer = Promise.resolve().then(() => this.ctx.waterfall(scopeTarget(req.agent, req.agent), 'approval/request', req, () => Promise.resolve('unavailable'))).then(
|
|
310
|
-
+ const answer = Promise.resolve().then(() => this.settlements.dispatch(this.ctx, scopeTarget(req.agent, req.agent), req, state)).then(
|
|
311
|
-
// Normalize a rogue (non-vocabulary) answerer return to the fail-closed
|
|
312
|
-
// outcome instead of leaking it into callers' closed-union switches.
|
|
313
|
-
outcome => OUTCOMES.includes(outcome) ? outcome : 'unavailable',
|
|
314
|
-
diff --git a/lib/types/settlement.d.ts b/lib/types/settlement.d.ts
|
|
315
|
-
new file mode 100644
|
|
316
|
-
index 0000000000000000000000000000000000000000..82ebaf2da4ff38d055f88cc1acf5bccfe56318e3
|
|
317
|
-
--- /dev/null
|
|
318
|
-
+++ b/lib/types/settlement.d.ts
|
|
319
|
-
@@ -0,0 +1,23 @@
|
|
320
|
-
+import type { ApprovalOutcome, ApprovalRequestId } from './types.js';
|
|
321
|
-
+export interface ApprovalWinner {
|
|
322
|
-
+ readonly requestId: ApprovalRequestId;
|
|
323
|
-
+ readonly deliveryId?: string;
|
|
324
|
-
+ readonly answerId?: string;
|
|
325
|
-
+ readonly source: 'operator' | 'temporary' | 'unknown';
|
|
326
|
-
+ readonly automatic: boolean;
|
|
327
|
-
+ readonly permit?: string;
|
|
328
|
-
+ readonly retention?: string;
|
|
329
|
-
+ readonly candidate: ApprovalOutcome;
|
|
330
|
-
+}
|
|
331
|
-
+export interface ApprovalSettlement {
|
|
332
|
-
+ readonly requestId: ApprovalRequestId;
|
|
333
|
-
+ readonly generation: string;
|
|
334
|
-
+ readonly outcome: ApprovalOutcome;
|
|
335
|
-
+ readonly auditSeq: number;
|
|
336
|
-
+ readonly source: ApprovalWinner['source'];
|
|
337
|
-
+ readonly winner?: ApprovalWinner;
|
|
338
|
-
+}
|
|
339
|
-
+export interface ApprovalForwarding {
|
|
340
|
-
+ readonly requestId: ApprovalRequestId;
|
|
341
|
-
+ accept(winner: ApprovalWinner): void;
|
|
342
|
-
+}
|
|
343
|
-
diff --git a/lib/types/settlement.js b/lib/types/settlement.js
|
|
344
|
-
new file mode 100644
|
|
345
|
-
index 0000000000000000000000000000000000000000..a62101e261dca5ee706a050514fb245e927331a4
|
|
346
|
-
--- /dev/null
|
|
347
|
-
+++ b/lib/types/settlement.js
|
|
348
|
-
@@ -0,0 +1,83 @@
|
|
349
|
-
+import { randomUUID } from 'node:crypto';
|
|
350
|
-
+
|
|
351
|
-
+const adapters = new WeakMap();
|
|
352
|
-
+/** Only explicitly installed approval adapters participate in source continuity. */
|
|
353
|
-
+export function approvalAdapter(callback) {
|
|
354
|
-
+ const listener = function (...args) { return callback.apply(this, args); };
|
|
355
|
-
+ Object.defineProperty(listener, 'bind', { value(receiver) {
|
|
356
|
-
+ const bound = Function.prototype.bind.call(this, receiver);
|
|
357
|
-
+ adapters.set(bound, true);
|
|
358
|
-
+ return bound;
|
|
359
|
-
+ } });
|
|
360
|
-
+ return listener;
|
|
361
|
-
+}
|
|
362
|
-
+
|
|
363
|
-
+export class ApprovalSettlements {
|
|
364
|
-
+ generation = randomUUID();
|
|
365
|
-
+ active = new WeakMap();
|
|
366
|
-
+ receipts = new Map();
|
|
367
|
-
+ observers = new Set();
|
|
368
|
-
+ open(request, id) {
|
|
369
|
-
+ const state = { request, id, closed: false, source: 'unknown', winner: undefined };
|
|
370
|
-
+ const group = this.active.get(request) ?? new Set();
|
|
371
|
-
+ group.add(state); this.active.set(request, group);
|
|
372
|
-
+ return state;
|
|
373
|
-
+ }
|
|
374
|
-
+ identity(request) {
|
|
375
|
-
+ const states = this.active.get(request);
|
|
376
|
-
+ return states?.size === 1 ? states.values().next().value.id : undefined;
|
|
377
|
-
+ }
|
|
378
|
-
+ close(state, outcome, auditSeq) {
|
|
379
|
-
+ state.closed = true;
|
|
380
|
-
+ const states = this.active.get(state.request);
|
|
381
|
-
+ states?.delete(state);
|
|
382
|
-
+ if (!states?.size) this.active.delete(state.request);
|
|
383
|
-
+ if (auditSeq === undefined) return;
|
|
384
|
-
+ const receipt = Object.freeze({ requestId: state.id, generation: this.generation,
|
|
385
|
-
+ outcome, auditSeq, source: state.source, winner: state.winner });
|
|
386
|
-
+ this.receipts.set(state.id, receipt);
|
|
387
|
-
+ while (this.receipts.size > 1024) this.receipts.delete(this.receipts.keys().next().value);
|
|
388
|
-
+ for (const observer of this.observers) {
|
|
389
|
-
+ try { Promise.resolve(observer(receipt)).catch(() => {}); } catch { /* Observers cannot undo an audit commit. */ }
|
|
390
|
-
+ }
|
|
391
|
-
+ return receipt;
|
|
392
|
-
+ }
|
|
393
|
-
+ async dispatch(ctx, target, request, state) {
|
|
394
|
-
+ const args = [target, 'approval/request', request];
|
|
395
|
-
+ const callbacks = ctx.events.dispatch('waterfall', args);
|
|
396
|
-
+ let cursor = 0;
|
|
397
|
-
+ const invoke = () => {
|
|
398
|
-
+ const callback = callbacks[cursor++];
|
|
399
|
-
+ if (callback === undefined) return Promise.resolve({ value: 'unavailable', source: 'unknown' });
|
|
400
|
-
+ const adapter = adapters.get(callback);
|
|
401
|
-
+ let calls = 0, child, completed = false, evidence;
|
|
402
|
-
+ const next = () => {
|
|
403
|
-
+ calls++;
|
|
404
|
-
+ const work = invoke();
|
|
405
|
-
+ return work.then(result => { child = result; completed = true; return result.value; });
|
|
406
|
-
+ };
|
|
407
|
-
+ const link = adapter === undefined ? undefined : Object.freeze({
|
|
408
|
-
+ requestId: state.id,
|
|
409
|
-
+ accept(winner) {
|
|
410
|
-
+ if (state.closed || evidence !== undefined) return;
|
|
411
|
-
+ evidence = winner;
|
|
412
|
-
+ state.winner = winner;
|
|
413
|
-
+ },
|
|
414
|
-
+ });
|
|
415
|
-
+ let result;
|
|
416
|
-
+ try { result = callback(request, next, link); }
|
|
417
|
-
+ catch (error) { return Promise.reject(error); }
|
|
418
|
-
+ return Promise.resolve(result).then(value => {
|
|
419
|
-
+ let source = 'unknown';
|
|
420
|
-
+ if (adapter !== undefined) {
|
|
421
|
-
+ if (calls === 0 && evidence?.candidate === value) source = evidence.source;
|
|
422
|
-
+ else if (calls === 1 && completed && child?.value === value && evidence === undefined) source = child.source;
|
|
423
|
-
+ }
|
|
424
|
-
+ return { value, source };
|
|
425
|
-
+ });
|
|
426
|
-
+ };
|
|
427
|
-
+ const result = await invoke();
|
|
428
|
-
+ if (!state.closed) state.source = result.source;
|
|
429
|
-
+ return result.value;
|
|
430
|
-
+ }
|
|
431
|
-
+}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
diff --git a/lib/index.js b/lib/index.js
|
|
2
|
-
index c70ab83154ee2a69f0c44507f1dd161ce8b7e38f..4c6da3afa0a31986713bb8e6992388def61d0a82 100644
|
|
3
|
-
--- a/lib/index.js
|
|
4
|
-
+++ b/lib/index.js
|
|
5
|
-
@@ -1,4 +1,4 @@
|
|
6
|
-
-import { Service } from "@deepseek-ai/cordis";
|
|
7
|
-
+import { Service, symbols } from "@deepseek-ai/cordis";
|
|
8
|
-
import z from "@deepseek-ai/schemastery";
|
|
9
|
-
import { HarnessError } from "@deepseek-ai/dsh-llm";
|
|
10
|
-
//#region lib/types/types.js
|
|
11
|
-
@@ -17,6 +17,8 @@ import { HarnessError } from "@deepseek-ai/dsh-llm";
|
|
12
|
-
* structured error metadata.
|
|
13
|
-
*/
|
|
14
|
-
var WebError = class extends HarnessError {};
|
|
15
|
-
+const preparedFetches = new WeakMap();
|
|
16
|
-
+const serviceOwner = value => value?.[symbols.original] ?? value;
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region lib/types/index.js
|
|
19
|
-
/**
|
|
20
|
-
@@ -51,6 +53,8 @@ var WebRuntime = class extends Service {
|
|
21
|
-
});
|
|
22
|
-
searchProviders = /* @__PURE__ */ new Map();
|
|
23
|
-
fetchProviders = /* @__PURE__ */ new Map();
|
|
24
|
-
+ fetchRegistrations = new Map();
|
|
25
|
-
+ fetchRegistryState = { revision: {} };
|
|
26
|
-
searchProviderEnv;
|
|
27
|
-
fetchProviderEnv;
|
|
28
|
-
constructor(ctx, config) {
|
|
29
|
-
@@ -81,9 +85,13 @@ var WebRuntime = class extends Service {
|
|
30
|
-
}
|
|
31
|
-
registerProvider(store, provider) {
|
|
32
|
-
if (store.has(provider.id)) throw new WebError(`a web provider with id "${provider.id}" is already registered`, "WEB_DUPLICATE_PROVIDER");
|
|
33
|
-
+ const registrations = store === this.fetchProviders ? this.fetchRegistrations : undefined;
|
|
34
|
-
+ const registryState = registrations && this.fetchRegistryState;
|
|
35
|
-
const dispose = this.ctx.effect(function* () {
|
|
36
|
-
store.set(provider.id, provider);
|
|
37
|
-
- yield () => store.delete(provider.id);
|
|
38
|
-
+ registrations?.set(provider.id, Object.freeze({}));
|
|
39
|
-
+ if (registryState) registryState.revision = {};
|
|
40
|
-
+ yield () => { store.delete(provider.id); registrations?.delete(provider.id); if (registryState) registryState.revision = {}; };
|
|
41
|
-
}, "web.registerProvider()");
|
|
42
|
-
return () => void dispose();
|
|
43
|
-
}
|
|
44
|
-
@@ -118,6 +126,48 @@ var WebRuntime = class extends Service {
|
|
45
|
-
...configuredId !== void 0 ? { configuredId } : {}
|
|
46
|
-
}).fetch(request, signal);
|
|
47
|
-
}
|
|
48
|
-
+ /** Prepare a detached request without invoking fetch or resolving its URL. */
|
|
49
|
-
+ prepareFetch(request) {
|
|
50
|
-
+ const cloned = Object.freeze(structuredClone(request));
|
|
51
|
-
+ const revision = this.fetchRegistryState.revision;
|
|
52
|
-
+ const configuredId = this.config.fetchProvider.get() ?? this.fetchProviderEnv;
|
|
53
|
-
+ const provider = resolveProvider({ providers: this.fetchProviders, configuredId });
|
|
54
|
-
+ const registration = this.fetchRegistrations.get(provider.id);
|
|
55
|
-
+ if (!registration || this.fetchProviders.get(provider.id) !== provider || revision !== this.fetchRegistryState.revision) throw new WebError("fetch provider registration changed", "WEB_PREPARED_STALE");
|
|
56
|
-
+ const prepared = Object.freeze({ request: cloned, provider, registration });
|
|
57
|
-
+ preparedFetches.set(prepared, { owner: serviceOwner(this), configuredId, provider, registration, revision, fetch: provider.fetch, request: cloned });
|
|
58
|
-
+ return prepared;
|
|
59
|
-
+ }
|
|
60
|
-
+ /** One attempt, including failures. The final callback and provider handoff are synchronous. */
|
|
61
|
-
+ async fetchPrepared(prepared, { signal, beforeDispatch } = {}) {
|
|
62
|
-
+ const entry = preparedFetches.get(prepared);
|
|
63
|
-
+ if (!entry) throw new WebError("invalid or consumed fetch preparation", "WEB_PREPARED_STALE");
|
|
64
|
-
+ preparedFetches.delete(prepared);
|
|
65
|
-
+ const check = () => {
|
|
66
|
-
+ if (signal?.aborted) throw new WebError("web fetch aborted", "WEB_ABORTED");
|
|
67
|
-
+ if (serviceOwner(this) !== entry.owner || serviceOwner(this.ctx.get("web")) !== entry.owner
|
|
68
|
-
+ || this.fetchRegistryState.revision !== entry.revision
|
|
69
|
-
+ || this.fetchProviders.get(entry.provider.id) !== entry.provider
|
|
70
|
-
+ || this.fetchRegistrations.get(entry.provider.id) !== entry.registration || entry.provider.fetch !== entry.fetch)
|
|
71
|
-
+ throw new WebError("fetch preparation is no longer current", "WEB_PREPARED_STALE");
|
|
72
|
-
+ };
|
|
73
|
-
+ check();
|
|
74
|
-
+ const selected = () => {
|
|
75
|
-
+ const configuredId = this.config.fetchProvider.get() ?? this.fetchProviderEnv;
|
|
76
|
-
+ if (configuredId !== entry.configuredId || resolveProvider({ providers: this.fetchProviders, configuredId }) !== entry.provider)
|
|
77
|
-
+ throw new WebError("fetch provider selection changed", "WEB_PREPARED_STALE");
|
|
78
|
-
+ check();
|
|
79
|
-
+ };
|
|
80
|
-
+ selected();
|
|
81
|
-
+ const result = beforeDispatch?.();
|
|
82
|
-
+ if (result !== null && (typeof result === "object" || typeof result === "function") && typeof result.then === "function") {
|
|
83
|
-
+ Promise.resolve(result).catch(() => {});
|
|
84
|
-
+ throw new WebError("beforeDispatch must be synchronous", "WEB_PREPARED_ASYNC_CALLBACK");
|
|
85
|
-
+ }
|
|
86
|
-
+ if ((this.config.fetchProvider.get() ?? this.fetchProviderEnv) !== entry.configuredId) throw new WebError("fetch provider selection changed", "WEB_PREPARED_STALE");
|
|
87
|
-
+ check();
|
|
88
|
-
+ return Reflect.apply(entry.fetch, entry.provider, [entry.request, signal]);
|
|
89
|
-
+ }
|
|
90
|
-
};
|
|
91
|
-
/** Resolve the selected provider or throw the matching {@link WebError}. */
|
|
92
|
-
function resolveProvider(selection) {
|
|
93
|
-
diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts
|
|
94
|
-
index 4c8f6bde391e4961748b123b7f1717ffb1ec45f6..f84e434c1c7d68db6f879f82585c6cb0225028c8 100644
|
|
95
|
-
--- a/lib/types/index.d.ts
|
|
96
|
-
+++ b/lib/types/index.d.ts
|
|
97
|
-
@@ -41,6 +41,11 @@ export interface WebRuntimeConfig {
|
|
98
|
-
* - No id configured, multiple usable providers → `WEB_PROVIDER_AMBIGUOUS`.
|
|
99
|
-
* - No id configured, no usable provider → `WEB_PROVIDER_UNAVAILABLE`.
|
|
100
|
-
*/
|
|
101
|
-
+export interface PreparedWebFetch {
|
|
102
|
-
+ readonly request: Readonly<WebFetchRequest>;
|
|
103
|
-
+ readonly provider: WebFetchProvider;
|
|
104
|
-
+ readonly registration: object;
|
|
105
|
-
+}
|
|
106
|
-
export declare class WebRuntime extends Service {
|
|
107
|
-
private readonly config;
|
|
108
|
-
/**
|
|
109
|
-
@@ -96,6 +101,10 @@ export declare class WebRuntime extends Service {
|
|
110
|
-
* @returns the retrieval outcome; non-2xx responses resolve descriptively.
|
|
111
|
-
*/
|
|
112
|
-
fetch(request: WebFetchRequest, signal?: AbortSignal): Promise<WebFetchResult>;
|
|
113
|
-
+ /** No fetch/DNS dispatch. Capability is bound to this live service and registration. */
|
|
114
|
-
+ prepareFetch(request: WebFetchRequest): PreparedWebFetch;
|
|
115
|
-
+ /** One dispatch attempt, with a synchronous final check. Failures consume the capability. */
|
|
116
|
-
+ fetchPrepared(prepared: PreparedWebFetch, options?: { signal?: AbortSignal; beforeDispatch?: () => unknown }): Promise<WebFetchResult>;
|
|
117
|
-
}
|
|
118
|
-
export default WebRuntime;
|
|
119
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# Native approval settlement support
|
|
2
|
-
|
|
3
|
-
These four pnpm patches target DSH `0.2.1-rc.2`. Apply all four to the Host and Client package graph. `metadata.json` supplies the workspace patch entries and the existing SDK package that DSMM must directly declare for its public Client types. pnpm owns patch integrity and lockfile generation. Installing the DSMM plugin alone does not patch an embedded Desktop Host.
|
|
4
|
-
|
|
5
|
-
## SDK contracts
|
|
6
|
-
|
|
7
|
-
- `ApprovalService.request(req, { opened(requestId) })` supplies the service-generated identity for that exact borrowed request. `requestIdentity(req)` is available only for an unambiguous active request. `settlement(requestId)` returns a bounded, live-only final-audit receipt; `forgetSettlement` releases it. Historical events never recreate receipts.
|
|
8
|
-
- `onSettlement` observes committed receipts. Receipt `source` describes proven continuity through the Host waterfall. `winner.automatic` independently records an actually accepted permit answer, including when a later layer destroys source continuity.
|
|
9
|
-
- `TypertGateway.approvalDelivery(peer, requestId, deliveryId)` returns the actual live delivery or `undefined`. `registerApprovalPermits` installs one synchronous Host verifier. Issuance does not claim the native winner or consume a grant.
|
|
10
|
-
- Client Gateway negotiates the `approval-settlement-1` capability before adding protocol fields. Old peers keep the original manual answer path without reusable provenance.
|
|
11
|
-
- `PendingApproval` is a **type-only export from `@deepseek-ai/dsh-client-ui-approval/client`**, not a class exported by the package root. Its readonly `requestId`/`deliveryId` identify a negotiated delivery. `answer(outcome, { permit })` or `answer(outcome, { retention })` fixes sideband in the same first-wins critical section as the outcome. The Host-issued retention token binds the chosen duration to the actual winning answer; a competing native once-only answer cannot inherit an earlier retention intent.
|
|
12
|
-
- Native UI owns the optional `conversation.approval.permissions` child slot. Its owner passes the exact public `pending` object. The existing detail slot and native answer/reject controls remain intact.
|
|
13
|
-
|
|
14
|
-
Only the native Remote/UI producers and explicitly audited approval adapters can carry source. Unknown listeners always produce unknown source, even when returning an equal outcome or calling `next()` once. The approval-specific adapters preserve Cordis selection, filtering, callback tracing, order and `this`; they do not modify Cordis. Never register an unreviewed listener with `createForwarder` or `$approvalAnswerer`.
|
|
15
|
-
|
|
16
|
-
## DSMM integration hooks
|
|
17
|
-
|
|
18
|
-
The parent composition owns `src/index.ts`, `src/native-admission.ts` and `src/client/index.ts`.
|
|
19
|
-
|
|
20
|
-
1. When permission rules are startup-mounted and patched `approval`/`typertGateway` and the Core/rules owners are live, call `installTemporaryPermissions(ctx, { core, roles, rules, argv })` from `permission-temporary-install.ts`. Pass the existing `createCorePermissionAuthority()` result, actual `DsmmRolePolicy`, and actual `PermissionRulesRuntimeSync`, not serialized policy or ownership booleans. This factory installs one grant store, native file adapters, authenticated RPC, and optional explicit argv tool. It refreshes the actual rule owner before capturing controlled calls. Do not separately install duplicate stores or RPC owners.
|
|
21
|
-
2. The returned `grants` is revoked on native `agent/disposed`. The parent's admission lifecycle must also call `grants.revokeAgent(exactAgent)` when replacing or releasing that Agent's owner/generation. This clears reusable grants without cancelling a native manual pending. The RPC remains root-only until trusted explicit child authorization and a visible native route are available.
|
|
22
|
-
3. Supply `argv` only in an authorized execution composition and before its role/tool ceiling is captured. `temporaryPermissionCapture()` uses the real Core physical-lifetime checks and calls `DsmmRolePolicy.assertToolExecution()` and `toolDenial()` for the actual registered tool. Automatic reuse additionally checks the captured Core generation and synchronized rules. `programKind()` is trusted Host classification: unknown programs and interpreters are once-only. Do not add `dsmm_exec_argv` to readonly role allowlists. Approval service shadows that differ from the factory's actual native service are refused.
|
|
23
|
-
4. The argv tool requires canonical absolute executable/cwd paths, the verified native local subprocess provider and current sandbox policy. It never changes native mode. Confining modes require `sandbox.confine`; missing support refuses execution. Environment is controlled overrides/tombstones over `scrubbedParentEnv`, not a replacement snapshot. Canonical paths are rechecked after asynchronous confinement, then provider handoff follows the final synchronous check without an await. This is not an atomic OS-release revocation guarantee, final-inode guarantee or binary-content pin.
|
|
24
|
-
5. Existing DSMM permission answerers use the explicitly audited `permissionApprovalAdapter` when the patch is available. Mount them after the patched ApprovalService; otherwise their source remains unknown and no scoped grant is created or consumed.
|
|
25
|
-
6. On the Client, register the existing permission dictionaries, then call `registerTemporaryPermissionSlots(ctx, connection)`. For the existing permissions panel, pass a generation-scoped `temporaryPermissionClient(connection, signal)` in its optional `temporary` prop. Recreate it for a new connection generation. No new question queue or answer RPC is introduced.
|
|
26
|
-
|
|
27
|
-
`permission-fs.ts` and `permission-fs-search.ts` wrap the actual native registration and body. Their reusable file adapter supports the exact native `LocalFileSystem`; search additionally requires the exact native `LocalSubprocessRuntime` in Node, the packaged ripgrep helper and its complete native argv template. Unknown providers and native sandbox-escalation requests retain native once-only behavior; they do not advertise reusable scopes. Native bash/pwsh remain once-only.
|
|
28
|
-
|
|
29
|
-
File requests expose exact targets and explicit directory-tree choices. Read and write grants, and distinct native tool registrations, remain separate. The Host resolves every target through the real filesystem, uses its `contains()` relation for trees, and rechecks the canonical target/type after asynchronous preparation. File operations are fenced again at the actual provider call; search performs a synchronous canonical-path/type, argv, cwd, effective-environment, provider and lease check immediately before spawn. The native working-directory metadata check is preserved without granting content access to that directory. Revocation/TTL stop subsequent handoffs, including a write delayed inside native `fs/write-intent`.
|
|
30
|
-
|
|
31
|
-
File grants never widen standing mode: read-only mutations and workspace-write mutations outside the resolved workspace are refused. There is no final-inode, Windows hardlink, binary-content, kernel filesystem or process-network guarantee. Website reuse and explicit child ask remain unsupported until their actual SDK provenance/selection boundaries are available; these four settlement patches do not provide them.
|
|
32
|
-
|
|
33
|
-
## Isolated verification
|
|
34
|
-
|
|
35
|
-
The SDK test supports task-owned editable package copies or an isolated pnpm-applied installation. Set `DSMM_APPROVAL_SDK_DIR` to the isolated project and `DSMM_APPROVAL_INSTALLED=1` to use its actual installed patched exports:
|
|
36
|
-
|
|
37
|
-
```powershell
|
|
38
|
-
node --import ./test/approval-settlement-sdk-loader.mjs --test ./test/approval-settlement-sdk.test.mjs
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
Run from `dsmm/`. The tests use in-memory Agents, native Gateway/Remote dispatch, native PendingApproval, synthetic operator Peers, actual local filesystem/ripgrep effects and a Go-built disposable argv program. They never use Desktop profiles, credentials, session files or model providers. The Go toolchain must already exist; no tool is installed. Tests remove their owned file/program/cache directories. The package-isolation directory is owned by the invoking verification run. `--test-name-pattern "temporary files|grants are created|operator Client RPC"` selects file and affected store/RPC coverage without rebuilding or rerunning the argv program.
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"patchedDependencies": {
|
|
3
|
-
"@deepseek-ai/dsh-user-approval@0.2.1-rc.2": "dsmm/patches/dsh-approval-settlement/@deepseek-ai__dsh-user-approval@0.2.1-rc.2.patch",
|
|
4
|
-
"@deepseek-ai/dsh-api-gateway@0.2.1-rc.2": "dsmm/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-gateway@0.2.1-rc.2.patch",
|
|
5
|
-
"@deepseek-ai/dsh-api-remotes@0.2.1-rc.2": "dsmm/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-remotes@0.2.1-rc.2.patch",
|
|
6
|
-
"@deepseek-ai/dsh-client-ui-approval@0.2.1-rc.2": "dsmm/patches/dsh-approval-settlement/@deepseek-ai__dsh-client-ui-approval@0.2.1-rc.2.patch"
|
|
7
|
-
},
|
|
8
|
-
"dsmmPeerDependencies": { "@deepseek-ai/dsh-client-ui-approval": "0.2.1-rc.2" },
|
|
9
|
-
"dsmmDevDependencies": { "@deepseek-ai/dsh-client-ui-approval": "0.2.1-rc.2" }
|
|
10
|
-
}
|