dsh-model-switch 0.4.66 → 0.4.68

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.
@@ -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-BgLqMl2z.js";
2
+ export { ModelSwitchSubagentRuntime, StartupIncompatibilityError, profileSubagentRuntime as default, profileSubagentRuntime, installSubagentDiscoveryHint, installSubagentRouteWrappers, mountWithStartupFallback, routeSubagentRequest, routedRuntimeUnavailableNotice, routedSubagentRequest, subagentDiscoveryFooter, subagentDiscoveryHintStatus, subagentRuntimeInject, subagentSurfaceOf };
@@ -32,8 +32,6 @@ export interface ModelSwitchSettingsFace {
32
32
  enabled: boolean;
33
33
  tools: readonly string[];
34
34
  }) => Promise<void>;
35
- /** Persist the reviewer stream idle timeout; undefined restores provider default. */
36
- saveReviewTimeout: (value: number | undefined) => Promise<void>;
37
35
  /** The Host's live tool catalog; absent on a Host without the `tools` RPC endpoint. */
38
36
  scanTools?: () => Promise<{
39
37
  rows: readonly ToolCatalogRow[];
@@ -78,16 +78,6 @@ export declare const zh: {
78
78
  readonly reviewAllowlistAvailable: "本机存在但未放行的工具:";
79
79
  readonly reviewAllowlistRepo: "仓库";
80
80
  readonly reviewAllowlistSkipped: "本 Host 进程已为纯读调用跳过 {count} 次审查。";
81
- readonly reviewTimeout: "审查超时";
82
- readonly reviewTimeoutDefault: "跟随 Provider 默认(300 秒)";
83
- readonly reviewTimeoutHelp: "设置自动审查请求的流式空闲超时。留空恢复 Provider 默认值;勾选「取消超时」写入上游上限(约 24.8 天),审查将不会因空闲而超时。保存后会立即重挂审查模型所在的 Provider 使其生效,重挂会中断该 Provider 的在途调用;重挂不了时回落到下次启动生效。";
84
- readonly reviewTimeoutScope: "注意:该值写入审查模型所在 Provider 的 streamIdleTimeoutMs,对该 Provider 的所有调用(含主对话)生效,不只影响审查请求。";
85
- readonly reviewTimeoutSeconds: "超时秒数";
86
- readonly reviewTimeoutPlaceholder: "300(默认)";
87
- readonly reviewTimeoutCancelLabel: "取消超时";
88
- readonly reviewTimeoutCancelHint: "审查调用不再因空闲超时(写入约 24.8 天上限)";
89
- readonly reviewTimeoutSave: "保存超时设置";
90
- readonly reviewTimeoutCancelled: "已取消超时";
91
81
  readonly reviewAutomodeLinked: "Auto mode 已接入:审查路由 {route},直通 +{added} 个纯读工具({skipped} 条通配未同步)。";
92
82
  readonly reviewAutomodeRouteOwn: "沿用其自身配置";
93
83
  readonly reviewAutomodeRouteUnset: "未配置(沿用会话模型)";
@@ -16,11 +16,6 @@ export interface ModelSwitchSettingsView {
16
16
  autoReviewSkipReadOnly?: boolean;
17
17
  /** Exact tool names, or trailing-`*` patterns, that skip the reviewer when enabled. */
18
18
  autoReviewAllowlist?: readonly string[];
19
- /**
20
- * Reviewer stream idle timeout in ms; `0` = cancelled (written as the upstream
21
- * ceiling); absent = follow the provider default.
22
- */
23
- autoReviewTimeoutMs?: number;
24
19
  compactProvider?: string;
25
20
  compactModel?: string;
26
21
  titleProvider?: string;
@@ -67,12 +62,8 @@ export declare const AUTO_REVIEW_ALLOWLIST_FIELDS: Readonly<{
67
62
  readonly enabled: "autoReviewSkipReadOnly";
68
63
  readonly tools: "autoReviewAllowlist";
69
64
  }>;
70
- /** Auto-reviewer stream idle timeout: one stored value; absent keeps the provider default. */
71
- export declare const AUTO_REVIEW_TIMEOUT_FIELD: "autoReviewTimeoutMs";
72
65
  /** Upstream ceiling enforced by `@deepseek-ai/dsh-timeout` (MAX_TIMER_DELAY_MS). */
73
66
  export declare const UPSTREAM_MAX_IDLE_TIMEOUT_MS = 2147483647;
74
- /** Upstream default (300 s) when the provider profile leaves the field unset. */
75
- export declare const UPSTREAM_DEFAULT_IDLE_TIMEOUT_MS = 300000;
76
67
  /** One allowlist editor snapshot (switch + entries). */
77
68
  export interface AutoReviewAllowlistView {
78
69
  enabled: boolean;
@@ -1,6 +1,10 @@
1
1
  /**
2
2
  * Configurable Auto-reviewer stream idle timeout.
3
3
  *
4
+ * @deprecated 2026-11-19 冻结:审查超时功能已移除,`model-switch-review-timeout`
5
+ * 行已从 `cordis.patch.yml` 移除,本模块不再被挂载。保留源码仅为可回退,下个大
6
+ * 版本删除;不再修 bug、不再适配新版本。
7
+ *
4
8
  * The reviewer call is a normal llm stream, so its idle watchdog is the one
5
9
  * `@deepseek-ai/dsh-llm-pi-ai` puts on the **provider profile**:
6
10
  * `providers.<id>.streamIdleTimeoutMs` (default 300 000 ms). There is no
@@ -46,6 +46,40 @@ export declare function routedSubagentRequest<T extends RoutableSubagentRequest>
46
46
  * either order. Unsupported or sealed surfaces leave the official route usable.
47
47
  */
48
48
  export declare function installSubagentRouteWrappers(ctx: Context): () => void;
49
+ /**
50
+ * Live state of the discovery-hint adapter, surfaced through the capabilities
51
+ * RPC next to the other adapter states.
52
+ */
53
+ export declare const subagentDiscoveryHintStatus: {
54
+ /** The tools registry was reachable and the adapter installed. */
55
+ installed: boolean;
56
+ /** The discovery tool was found and its execute wrapped. */
57
+ toolWrapped: boolean;
58
+ };
59
+ /**
60
+ * Compose the route footer appended to the discovery tool's text output.
61
+ *
62
+ * Pure so the copy and the source attribution stay unit-testable.
63
+ *
64
+ * @param route - the route an unnamed spawn from this session would use.
65
+ * @param pinnedByGroup - whether a provider group (not the flat card) pinned it.
66
+ * @returns the footer line; undefined routes are stated as official inherit.
67
+ */
68
+ export declare function subagentDiscoveryFooter(route: SubagentRoute | undefined, pinnedByGroup: boolean): string;
69
+ /**
70
+ * Wrap the official discovery tool's execute so its text output also states the
71
+ * route an unnamed spawn would actually take — the one piece the
72
+ * authorized-route listing cannot know.
73
+ *
74
+ * The wrap is in place on the registered definition (the registry resolves
75
+ * tools per call), idempotent across re-sweeps, and re-applied when the
76
+ * registry changes so a re-registered tool is covered too. Unknown result
77
+ * shapes pass through untouched; unload restores the official execute.
78
+ *
79
+ * @param ctx - this row's context.
80
+ * @returns a disposer that detaches the listener and restores the execute.
81
+ */
82
+ export declare function installSubagentDiscoveryHint(ctx: Context): () => void;
49
83
  /**
50
84
  * Wait for the official service without replacing it or copying its dependency
51
85
  * list. Model Switch is read optionally per call, so its absence cannot hold a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-model-switch",
3
- "version": "0.4.66",
3
+ "version": "0.4.68",
4
4
  "description": "Explicit model routing plus composer/Plan picker for DeepSeek Harness",
5
5
  "repository": {
6
6
  "type": "git",
@@ -78,7 +78,7 @@
78
78
  "cordis.patch.yml",
79
79
  "CHANGELOG.md",
80
80
  "README.md",
81
- "README.zh.md",
81
+ "README.en.md",
82
82
  "docs/screenshots/*.png",
83
83
  "PRODUCT.md",
84
84
  "IMPLEMENTATION_PLAN.md"