dsh-model-switch 0.4.67 → 0.4.69

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/IMPLEMENTATION_PLAN.md +12 -1
  3. package/PRODUCT.md +3 -3
  4. package/README.en.md +17 -19
  5. package/README.md +17 -19
  6. package/cordis.patch.yml +9 -0
  7. package/lib/auto-review-CYvvootQ.js +1079 -0
  8. package/lib/auto-review.js +1 -1
  9. package/lib/automode-compat.js +1 -1
  10. package/lib/client.js +473 -47
  11. package/lib/compaction.js +1 -1
  12. package/lib/index.js +30 -6
  13. package/lib/prime-memory-compat.js +568 -1
  14. package/lib/prime-memory-route-DGUVfogE.js +117 -0
  15. package/lib/review-timeout-FB32BcnO.js +339 -0
  16. package/lib/review-timeout.js +1 -1
  17. package/lib/session-route-CRfpxarI.js +357 -0
  18. package/lib/session-title.js +1 -1
  19. package/lib/subagent-runtime-BgLqMl2z.js +424 -0
  20. package/lib/subagent-runtime-CluWLZio.js +412 -0
  21. package/lib/subagent-runtime-eNKrdb2H.js +424 -0
  22. package/lib/subagent-runtime.js +2 -289
  23. package/lib/tool-allowlist-cN9Z1XKn.js +489 -0
  24. package/lib/types/capabilities-rpc.d.ts +7 -0
  25. package/lib/types/client/ModelSwitchSettings.d.ts +6 -3
  26. package/lib/types/client/locales.d.ts +12 -2
  27. package/lib/types/client-contract.d.ts +33 -1
  28. package/lib/types/host-settings.d.ts +11 -0
  29. package/lib/types/prime-memory-compat.d.ts +7 -4
  30. package/lib/types/prime-memory-route.d.ts +22 -0
  31. package/lib/types/provider-group.d.ts +31 -3
  32. package/lib/types/session-route.d.ts +24 -3
  33. package/lib/types/subagent-runtime.d.ts +34 -0
  34. package/lib/types/tool-allowlist.d.ts +13 -0
  35. package/lib/types/vision-router-compat.d.ts +62 -0
  36. package/lib/types/vision-router-route.d.ts +94 -0
  37. package/lib/vision-router-compat-B9bkgJmh.js +312 -0
  38. package/lib/vision-router-compat.js +2 -0
  39. package/package.json +5 -1
@@ -1,289 +1,2 @@
1
- import { o as sessionSubagentRouteOf } from "./session-route-D8izd8Zd.js";
2
- import { symbols } from "@deepseek-ai/cordis";
3
- import { ReasoningEffortId } from "@deepseek-ai/dsh-llm";
4
- import OfficialSubagentRuntime from "@deepseek-ai/dsh-subagent";
5
- //#region lib/types/subagent-runtime-legacy.js
6
- /** Previously published startup error; retained for consumers of this module. */
7
- var StartupIncompatibilityError = class extends Error {
8
- name = "StartupIncompatibilityError";
9
- surface;
10
- constructor(surfaceOrMessage, message) {
11
- super(message ?? surfaceOrMessage);
12
- this.surface = message === void 0 ? "startup" : surfaceOrMessage;
13
- }
14
- };
15
- /** Classify the two published start API generations without version guessing. */
16
- function subagentSurfaceOf(value) {
17
- if (value === null || typeof value !== "object" && typeof value !== "function") return void 0;
18
- if (typeof Reflect.get(value, "startActivation") === "function") return "activation";
19
- return typeof Reflect.get(value, "start") === "function" && typeof Reflect.get(value, "startContinuable") === "function" ? "start" : void 0;
20
- }
21
- function once(dispose) {
22
- let pending;
23
- return () => {
24
- pending ??= Promise.resolve().then(() => dispose()).then(() => void 0);
25
- return pending;
26
- };
27
- }
28
- var CleanupLedger = class {
29
- attempts = [];
30
- add(dispose) {
31
- this.attempts.push(once(dispose));
32
- }
33
- async disposeAll() {
34
- const failures = [];
35
- for (const dispose of [...this.attempts].reverse()) try {
36
- await dispose();
37
- } catch (error) {
38
- failures.push(error);
39
- }
40
- return failures;
41
- }
42
- };
43
- function startupFailure(error, failures) {
44
- if (failures.length === 0) throw error;
45
- throw new AggregateError([error, ...failures], "Subagent runtime startup and cleanup failed", { cause: error });
46
- }
47
- function cleanupDisposer(ledger) {
48
- return async () => {
49
- const failures = await ledger.disposeAll();
50
- if (failures.length > 0) throw new AggregateError(failures, "Subagent runtime cleanup failed");
51
- };
52
- }
53
- /** Retain the typed-only startup fallback and reverse, idempotent cleanup contract. */
54
- async function mountWithStartupFallback(candidate, fallback) {
55
- const ledger = new CleanupLedger();
56
- try {
57
- return {
58
- value: await candidate((dispose) => ledger.add(dispose)),
59
- dispose: cleanupDisposer(ledger)
60
- };
61
- } catch (error) {
62
- const failures = await ledger.disposeAll();
63
- if (!(error instanceof StartupIncompatibilityError) || failures.length > 0) startupFailure(error, failures);
64
- }
65
- try {
66
- return {
67
- value: await fallback((dispose) => ledger.add(dispose)),
68
- dispose: cleanupDisposer(ledger)
69
- };
70
- } catch (error) {
71
- startupFailure(error, await ledger.disposeAll());
72
- }
73
- }
74
- function routedRuntimeUnavailableNotice(error) {
75
- return `model-switch: the routed Subagent runtime is unavailable on this DSH Host (${error.message}); delegation follows the official route instead`;
76
- }
77
- /** @deprecated Only the legacy subclass needs a mirrored dependency list. */
78
- function subagentRuntimeInject(officialInject) {
79
- return [.../* @__PURE__ */ new Set([...officialInject ?? [], "modelSwitch"])];
80
- }
81
- function publicMethod(method) {
82
- const value = Reflect.get(OfficialSubagentRuntime.prototype, method);
83
- if (typeof value !== "function") throw new StartupIncompatibilityError("OfficialSubagentRuntime", `OfficialSubagentRuntime must expose public ${method}()`);
84
- return value;
85
- }
86
- /**
87
- * @deprecated Kept importable for existing consumers, not mounted by the bundle.
88
- * Install profileSubagentRuntime around the official service instead: the
89
- * official Loader row must remain enabled to own its strict Typert definitions.
90
- */
91
- var ModelSwitchSubagentRuntime = class extends OfficialSubagentRuntime {
92
- static inject = subagentRuntimeInject(OfficialSubagentRuntime.inject);
93
- routed(name, request) {
94
- const provider = this.ctx.subagents.getProvider(name);
95
- if (provider !== void 0 && provider.capabilities.agentOptions !== true) return request;
96
- return routeSubagentRequest(request, sessionSubagentRouteOf(this.ctx, request.parent.session, this.ctx.modelSwitch.currentSettings()));
97
- }
98
- start(name, request) {
99
- return Reflect.apply(publicMethod("start"), this, [name, this.routed(name, request)]);
100
- }
101
- startContinuable(spec) {
102
- return Reflect.apply(publicMethod("startContinuable"), this, [{
103
- ...spec,
104
- request: this.routed(spec.provider, spec.request)
105
- }]);
106
- }
107
- startActivation(spec) {
108
- const request = spec.request ?? spec;
109
- return Reflect.apply(publicMethod("startActivation"), this, [{
110
- ...spec,
111
- request: this.routed(spec.provider, request)
112
- }]);
113
- }
114
- };
115
- //#endregion
116
- //#region lib/types/subagent-runtime.js
117
- function present(value) {
118
- return typeof value === "string" && value.trim() !== "";
119
- }
120
- function spawnHasAnyRouteField(options) {
121
- return present(options?.provider) || present(options?.model) || options?.reasoningEffort !== void 0;
122
- }
123
- /**
124
- * Inject a parent-session route only when the caller named no provider, model,
125
- * or reasoning effort. All other request and Agent options pass through.
126
- */
127
- function routeSubagentRequest(request, route) {
128
- if (spawnHasAnyRouteField(request.agentOptions) || route === void 0) return request;
129
- return {
130
- ...request,
131
- agentOptions: {
132
- ...request.agentOptions,
133
- provider: route.provider,
134
- model: route.model,
135
- ...route.reasoningEffort === void 0 ? {} : { reasoningEffort: ReasoningEffortId(route.reasoningEffort) }
136
- }
137
- };
138
- }
139
- /** Resolve the current public route surface, never retaining a disposed service. */
140
- function routedSubagentRequest(ctx, runtime, providerName, request) {
141
- if (spawnHasAnyRouteField(request.agentOptions)) return request;
142
- const provider = runtime.getProvider?.(providerName);
143
- if (provider !== void 0 && provider.capabilities?.agentOptions !== true) return request;
144
- let modelSwitch;
145
- try {
146
- modelSwitch = ctx.get("modelSwitch");
147
- } catch {
148
- return request;
149
- }
150
- if (typeof modelSwitch?.currentSettings !== "function") return request;
151
- return routeSubagentRequest(request, sessionSubagentRouteOf(ctx, request.parent.session, modelSwitch.currentSettings()));
152
- }
153
- /** A tracing proxy is for calls, not method ownership or descriptor restoration. */
154
- function originalService(value) {
155
- const original = Reflect.get(value, symbols.original);
156
- return original !== null && (typeof original === "object" || typeof original === "function") ? original : value;
157
- }
158
- function isRequest(value) {
159
- if (typeof value !== "object" || value === null) return false;
160
- const parent = Reflect.get(value, "parent");
161
- return typeof parent === "object" && parent !== null && Reflect.get(parent, "session") !== void 0;
162
- }
163
- /**
164
- * Route one activation spec under either released shape. 0.2.1 through
165
- * 0.2.2-rc.1 nest the SubagentStartRequest under spec.request; 0.2.2-rc.2
166
- * flattens those fields onto the spec itself. Unknown shapes pass through
167
- * untouched, so an unanticipated future shape keeps the official route.
168
- */
169
- function routedSpecOf(spec, provider, state) {
170
- const nested = Reflect.get(spec, "request");
171
- if (typeof nested === "object" && nested !== null && isRequest(nested)) {
172
- const request = routeFor(state, provider, nested);
173
- return request === nested ? spec : {
174
- ...spec,
175
- request
176
- };
177
- }
178
- if (isRequest(spec)) {
179
- const request = routeFor(state, provider, spec);
180
- if (request === spec) return spec;
181
- return {
182
- ...spec,
183
- agentOptions: request.agentOptions
184
- };
185
- }
186
- return spec;
187
- }
188
- function warn(ctx, message) {
189
- try {
190
- ctx.logger.warn(message);
191
- } catch {}
192
- }
193
- const wrappers = /* @__PURE__ */ new WeakMap();
194
- function routeFor(state, provider, request) {
195
- const ctx = [...state.leases].at(-1)?.ctx;
196
- return ctx === void 0 ? request : routedSubagentRequest(ctx, state.runtime, provider, request);
197
- }
198
- function wrapMethod(target, key, factory) {
199
- const original = Reflect.get(target, key);
200
- if (typeof original !== "function") return void 0;
201
- const previous = Object.getOwnPropertyDescriptor(target, key);
202
- const wrapped = factory(original);
203
- Object.defineProperty(target, key, {
204
- configurable: true,
205
- enumerable: previous?.enumerable ?? false,
206
- writable: true,
207
- value: wrapped
208
- });
209
- return () => {
210
- if (Object.getOwnPropertyDescriptor(target, key)?.value !== wrapped) return;
211
- if (previous === void 0) Reflect.deleteProperty(target, key);
212
- else Object.defineProperty(target, key, previous);
213
- };
214
- }
215
- /**
216
- * Wrap the official service's start entries only. Its identity, prototype,
217
- * registry, manager, Typert binding and prompt/interrupt methods are untouched.
218
- * Disposers are idempotent and safe when overlapping adapter fibers unload in
219
- * either order. Unsupported or sealed surfaces leave the official route usable.
220
- */
221
- function installSubagentRouteWrappers(ctx) {
222
- const service = ctx.get("subagents");
223
- if (service === void 0) {
224
- warn(ctx, "model-switch: subagents service is unavailable; delegation keeps the official route");
225
- return () => {};
226
- }
227
- const runtime = originalService(service);
228
- let state = wrappers.get(runtime);
229
- if (state === void 0) {
230
- state = {
231
- runtime,
232
- leases: /* @__PURE__ */ new Set(),
233
- restores: []
234
- };
235
- const current = state;
236
- const wrap = (key, factory) => {
237
- const restore = wrapMethod(runtime, key, factory);
238
- if (restore !== void 0) current.restores.push(restore);
239
- };
240
- try {
241
- for (const key of ["startActivation", "startContinuable"]) wrap(key, (original) => function(...args) {
242
- const rawSpec = args[0];
243
- if (typeof rawSpec !== "object" || rawSpec === null) return Reflect.apply(original, this, args);
244
- const spec = rawSpec;
245
- if (typeof spec.provider !== "string") return Reflect.apply(original, this, args);
246
- return Reflect.apply(original, this, [routedSpecOf(spec, spec.provider, current), ...args.slice(1)]);
247
- });
248
- wrap("start", (original) => function(...args) {
249
- const [provider, request] = args;
250
- if (typeof provider !== "string" || !isRequest(request)) return Reflect.apply(original, this, args);
251
- return Reflect.apply(original, this, [
252
- provider,
253
- routeFor(current, provider, request),
254
- ...args.slice(2)
255
- ]);
256
- });
257
- } catch (error) {
258
- for (const restore of current.restores.reverse()) restore();
259
- warn(ctx, `model-switch: Subagent starts cannot be wrapped (${String(error)}); delegation keeps the official route`);
260
- return () => {};
261
- }
262
- if (current.restores.length === 0) {
263
- warn(ctx, "model-switch: no supported public Subagent start entry; delegation keeps the official route");
264
- return () => {};
265
- }
266
- wrappers.set(runtime, state);
267
- }
268
- const lease = { ctx };
269
- state.leases.add(lease);
270
- const owned = state;
271
- return () => {
272
- if (!owned.leases.delete(lease) || owned.leases.size > 0) return;
273
- for (const restore of [...owned.restores].reverse()) restore();
274
- wrappers.delete(runtime);
275
- };
276
- }
277
- /**
278
- * Wait for the official service without replacing it or copying its dependency
279
- * list. Model Switch is read optionally per call, so its absence cannot hold a
280
- * startup fiber or retain a stale settings service. Cordis rebinds this effect
281
- * when the official service is recreated.
282
- */
283
- function profileSubagentRuntime(ctx) {
284
- ctx.inject(["subagents"], (scope) => {
285
- scope.effect(() => installSubagentRouteWrappers(scope), "Model Switch: route official Subagent starts");
286
- });
287
- }
288
- //#endregion
289
- export { ModelSwitchSubagentRuntime, StartupIncompatibilityError, profileSubagentRuntime as default, profileSubagentRuntime, installSubagentRouteWrappers, mountWithStartupFallback, routeSubagentRequest, routedRuntimeUnavailableNotice, routedSubagentRequest, subagentRuntimeInject, subagentSurfaceOf };
1
+ import { a as routedSubagentRequest, c as ModelSwitchSubagentRuntime, d as routedRuntimeUnavailableNotice, f as subagentRuntimeInject, i as routeSubagentRequest, l as StartupIncompatibilityError, n as installSubagentRouteWrappers, o as subagentDiscoveryFooter, p as subagentSurfaceOf, r as profileSubagentRuntime, s as subagentDiscoveryHintStatus, t as installSubagentDiscoveryHint, u as mountWithStartupFallback } from "./subagent-runtime-eNKrdb2H.js";
2
+ export { ModelSwitchSubagentRuntime, StartupIncompatibilityError, profileSubagentRuntime as default, profileSubagentRuntime, installSubagentDiscoveryHint, installSubagentRouteWrappers, mountWithStartupFallback, routeSubagentRequest, routedRuntimeUnavailableNotice, routedSubagentRequest, subagentDiscoveryFooter, subagentDiscoveryHintStatus, subagentRuntimeInject, subagentSurfaceOf };