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.
- package/CHANGELOG.md +28 -0
- package/IMPLEMENTATION_PLAN.md +12 -1
- package/PRODUCT.md +3 -3
- package/README.en.md +17 -19
- package/README.md +17 -19
- package/cordis.patch.yml +9 -0
- package/lib/auto-review-CYvvootQ.js +1079 -0
- package/lib/auto-review.js +1 -1
- package/lib/automode-compat.js +1 -1
- package/lib/client.js +473 -47
- package/lib/compaction.js +1 -1
- package/lib/index.js +30 -6
- package/lib/prime-memory-compat.js +568 -1
- package/lib/prime-memory-route-DGUVfogE.js +117 -0
- package/lib/review-timeout-FB32BcnO.js +339 -0
- package/lib/review-timeout.js +1 -1
- package/lib/session-route-CRfpxarI.js +357 -0
- package/lib/session-title.js +1 -1
- package/lib/subagent-runtime-BgLqMl2z.js +424 -0
- package/lib/subagent-runtime-CluWLZio.js +412 -0
- package/lib/subagent-runtime-eNKrdb2H.js +424 -0
- package/lib/subagent-runtime.js +2 -289
- package/lib/tool-allowlist-cN9Z1XKn.js +489 -0
- package/lib/types/capabilities-rpc.d.ts +7 -0
- package/lib/types/client/ModelSwitchSettings.d.ts +6 -3
- package/lib/types/client/locales.d.ts +12 -2
- package/lib/types/client-contract.d.ts +33 -1
- package/lib/types/host-settings.d.ts +11 -0
- package/lib/types/prime-memory-compat.d.ts +7 -4
- package/lib/types/prime-memory-route.d.ts +22 -0
- package/lib/types/provider-group.d.ts +31 -3
- package/lib/types/session-route.d.ts +24 -3
- package/lib/types/subagent-runtime.d.ts +34 -0
- package/lib/types/tool-allowlist.d.ts +13 -0
- package/lib/types/vision-router-compat.d.ts +62 -0
- package/lib/types/vision-router-route.d.ts +94 -0
- package/lib/vision-router-compat-B9bkgJmh.js +312 -0
- package/lib/vision-router-compat.js +2 -0
- package/package.json +5 -1
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { s as visionRouteOf } from "./session-route-CRfpxarI.js";
|
|
2
|
+
import { t as deploymentDefaultProviderOf } from "./prime-memory-route-DGUVfogE.js";
|
|
3
|
+
//#region lib/types/vision-router-route.js
|
|
4
|
+
/**
|
|
5
|
+
* Model Switch's adapter to `dsh-vision-router`'s backend chain.
|
|
6
|
+
*
|
|
7
|
+
* dsh-vision-router owns the vision backend chain: an ordered `providers` list
|
|
8
|
+
* of `{ provider, model, fallbacks }` rows in its `vision-router` row config,
|
|
9
|
+
* each row a host llm provider/model the chain tries in order. This module only
|
|
10
|
+
* builds the chain Model Switch offers; it never runs a vision call, never
|
|
11
|
+
* rewrites another row, and never touches a route the user did not ask to
|
|
12
|
+
* change.
|
|
13
|
+
*
|
|
14
|
+
* Managed-head semantics: a configured route owns the chain's FIRST row (the
|
|
15
|
+
* primary backend); the rows the user already had stay below in their own order
|
|
16
|
+
* as fallbacks. Unlike the memory adapter there is no `user-set` skip: the
|
|
17
|
+
* chain is an ordered fallback table that is never empty (the built-in free
|
|
18
|
+
* endpoint is the runtime's last resort), so the head is the routing decision
|
|
19
|
+
* and a user-set head is exactly what a configured route replaces.
|
|
20
|
+
*
|
|
21
|
+
* All functions here are pure.
|
|
22
|
+
*/
|
|
23
|
+
/** The loader row id dsh-vision-router is composed under (fixed by its bundle patch). */
|
|
24
|
+
const VISION_ROUTER_ENTRY_ID = "vision-router";
|
|
25
|
+
/** The package name that identifies the row; the authoritative identity. */
|
|
26
|
+
const VISION_ROUTER_PACKAGE = "dsh-vision-router";
|
|
27
|
+
/** A non-blank string within dsh-vision-router's identifier budget. */
|
|
28
|
+
function validIdentifier(value) {
|
|
29
|
+
return typeof value === "string" && value.length > 0 && value.length <= 512;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Whether one loader entry is dsh-vision-router.
|
|
33
|
+
*
|
|
34
|
+
* The package name wins over the row id: a profile layer may rename the row,
|
|
35
|
+
* while an unrelated row could recycle the id.
|
|
36
|
+
* @param entry - the loader entry to test.
|
|
37
|
+
* @returns True for dsh-vision-router's row.
|
|
38
|
+
*/
|
|
39
|
+
function isVisionRouterRow(entry) {
|
|
40
|
+
const name = entry?.options?.name;
|
|
41
|
+
if (typeof name === "string" && name.trim() !== "") return name === VISION_ROUTER_PACKAGE;
|
|
42
|
+
return entry?.options?.id === VISION_ROUTER_ENTRY_ID;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Strip a raw providers value to well-formed chain rows.
|
|
46
|
+
*
|
|
47
|
+
* Mirrors dsh-vision-router's own runtime normalization: entries without a
|
|
48
|
+
* valid provider and model are dropped, fallbacks are kept as strings, and the
|
|
49
|
+
* chain is capped at the plugin's row limit.
|
|
50
|
+
* @param value - the raw `providers` config value, when present.
|
|
51
|
+
* @returns The valid rows, in stored order.
|
|
52
|
+
*/
|
|
53
|
+
function normalizeVisionProviderEntries(value) {
|
|
54
|
+
if (!Array.isArray(value)) return [];
|
|
55
|
+
const rows = [];
|
|
56
|
+
for (const entry of value) {
|
|
57
|
+
if (entry === null || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
58
|
+
const source = entry;
|
|
59
|
+
if (!validIdentifier(source.provider) || !validIdentifier(source.model)) continue;
|
|
60
|
+
const fallbacks = Array.isArray(source.fallbacks) ? source.fallbacks.filter((item) => validIdentifier(item)) : [];
|
|
61
|
+
rows.push({
|
|
62
|
+
provider: source.provider,
|
|
63
|
+
model: source.model,
|
|
64
|
+
fallbacks
|
|
65
|
+
});
|
|
66
|
+
if (rows.length >= 32) break;
|
|
67
|
+
}
|
|
68
|
+
return rows;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The backend chain dsh-vision-router should run, given the route Model Switch wants.
|
|
72
|
+
*
|
|
73
|
+
* The chosen route goes first; the entries the plugin already had follow in
|
|
74
|
+
* their own order, minus any duplicate of the chosen pair (a duplicate is a
|
|
75
|
+
* guaranteed second failure, not a fallback) and minus the entry this adapter
|
|
76
|
+
* wrote on an earlier pass (identified by `adopted`, so a route change
|
|
77
|
+
* replaces in place instead of accumulating). An empty chosen route leaves the
|
|
78
|
+
* existing chain untouched.
|
|
79
|
+
* @param existing - the raw `providers` config value as currently stored.
|
|
80
|
+
* @param route - the route Model Switch wants first, if any.
|
|
81
|
+
* @param adopted - the `provider/model` this adapter wrote on an earlier pass.
|
|
82
|
+
* @returns The chain to write, whether it changed, and what was applied.
|
|
83
|
+
*/
|
|
84
|
+
function planVisionProviders(existing, route, adopted) {
|
|
85
|
+
const chain = normalizeVisionProviderEntries(existing);
|
|
86
|
+
const provider = typeof route?.provider === "string" ? route.provider.trim() : "";
|
|
87
|
+
const model = typeof route?.model === "string" ? route.model.trim() : "";
|
|
88
|
+
if (provider === "" || model === "") return {
|
|
89
|
+
providers: chain,
|
|
90
|
+
changed: false,
|
|
91
|
+
skipped: "no-route"
|
|
92
|
+
};
|
|
93
|
+
const head = chain[0];
|
|
94
|
+
if (head !== void 0 && head.provider === provider && head.model === model) return {
|
|
95
|
+
providers: chain,
|
|
96
|
+
changed: false,
|
|
97
|
+
route: `${provider}/${model}`
|
|
98
|
+
};
|
|
99
|
+
const rest = chain.filter((entry) => {
|
|
100
|
+
if (entry.provider === provider && entry.model === model) return false;
|
|
101
|
+
if (adopted !== void 0 && `${entry.provider}/${entry.model}` === adopted) return false;
|
|
102
|
+
return true;
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
providers: [{
|
|
106
|
+
provider,
|
|
107
|
+
model,
|
|
108
|
+
fallbacks: []
|
|
109
|
+
}, ...rest].slice(0, 32),
|
|
110
|
+
changed: true,
|
|
111
|
+
route: `${provider}/${model}`
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region lib/types/vision-router-compat.js
|
|
116
|
+
/**
|
|
117
|
+
* Adapt `dsh-vision-router`'s backend chain to this plugin's vision route.
|
|
118
|
+
*
|
|
119
|
+
* The vision plugin owns an ordered `providers` chain in its `vision-router`
|
|
120
|
+
* row config and reads it live. The write crosses the same boundary the
|
|
121
|
+
* plugin's own settings facade uses: `ctx.configEditor.edit(entry, change)` —
|
|
122
|
+
* the released core ConfigEditor seam. The edit validates through the plugin's
|
|
123
|
+
* own Config schema (`providers` is declared there), persists into the profile
|
|
124
|
+
* patch row, and hot-reloads just that entry, so a provider switch applies
|
|
125
|
+
* without a Host restart. The plugin's HTTP local-settings transport stays
|
|
126
|
+
* unused: its BrowserAuth fence only admits an authenticated local browser,
|
|
127
|
+
* not a plugin fiber.
|
|
128
|
+
*
|
|
129
|
+
* The route itself is provider-group based: the group of the deployment
|
|
130
|
+
* default provider (canonicalized — a twin `${provider}-vision` default keys
|
|
131
|
+
* its base), falling back to the flat vision pair. Chain semantics are the
|
|
132
|
+
* managed head documented in `./vision-router-route.ts`: a configured route
|
|
133
|
+
* owns the first row, the user's own rows stay below as fallbacks, and an
|
|
134
|
+
* empty route leaves the chain untouched.
|
|
135
|
+
*/
|
|
136
|
+
/** Row name and dependencies, mirroring the sibling adapter rows. */
|
|
137
|
+
const name = "model-switch-vision-router-compat";
|
|
138
|
+
const inject = ["loader"];
|
|
139
|
+
/** The state the settings page reads. */
|
|
140
|
+
const visionRouterCompatStatus = {
|
|
141
|
+
installed: false,
|
|
142
|
+
replays: 0
|
|
143
|
+
};
|
|
144
|
+
/** A non-blank string. */
|
|
145
|
+
function text(value) {
|
|
146
|
+
return typeof value === "string" ? value.trim() : "";
|
|
147
|
+
}
|
|
148
|
+
/** Read a value as a plain record. */
|
|
149
|
+
function asRecord(value) {
|
|
150
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
151
|
+
}
|
|
152
|
+
/** The config one loader entry currently runs with. */
|
|
153
|
+
function configOf(entry) {
|
|
154
|
+
return asRecord(entry?.options?.config);
|
|
155
|
+
}
|
|
156
|
+
/** The ConfigEditor service, when this Host exposes the released seam. */
|
|
157
|
+
function editorOf(ctx) {
|
|
158
|
+
try {
|
|
159
|
+
return ctx.get("configEditor", false);
|
|
160
|
+
} catch {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/** The vision plugin's addressable row, as currently composed. */
|
|
165
|
+
function visionRouterEntryOf(editor) {
|
|
166
|
+
for (const candidate of editor.entries?.() ?? []) if (isVisionRouterRow(candidate)) return candidate;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Install the adapter for the whole profile.
|
|
170
|
+
*
|
|
171
|
+
* Runs on activation, on every `loader/patch-context` and `loader/entry-init`
|
|
172
|
+
* that concerns the vision plugin's row, once more after a short delay (the
|
|
173
|
+
* row is often composed after this one), when the `configEditor` service
|
|
174
|
+
* appears, and whenever this plugin's settings change. Every pass compares
|
|
175
|
+
* before writing: a ConfigEditor edit reconciles the profile and re-enters
|
|
176
|
+
* this adapter, so an unchanged head must not produce another write.
|
|
177
|
+
* @param ctx - this row's context.
|
|
178
|
+
* @param routeOf - resolves this plugin's vision route for one settings snapshot.
|
|
179
|
+
* @returns The disposer and a replay hook.
|
|
180
|
+
*/
|
|
181
|
+
function installVisionRouterCompat(ctx, routeOf) {
|
|
182
|
+
/** The route this adapter wrote last, so it may replace its own value only. */
|
|
183
|
+
let adoptedRoute;
|
|
184
|
+
let pending;
|
|
185
|
+
let attempt = 0;
|
|
186
|
+
const timers = [];
|
|
187
|
+
const scheduleRetry = () => {
|
|
188
|
+
if (attempt >= 8) return;
|
|
189
|
+
const delay = Math.min(4e3, 200 * 2 ** attempt);
|
|
190
|
+
attempt += 1;
|
|
191
|
+
const timer = setTimeout(() => {
|
|
192
|
+
run();
|
|
193
|
+
}, delay);
|
|
194
|
+
timer.unref?.();
|
|
195
|
+
timers.push(timer);
|
|
196
|
+
};
|
|
197
|
+
const run = async () => {
|
|
198
|
+
if (pending !== void 0) return pending;
|
|
199
|
+
const editor = editorOf(ctx);
|
|
200
|
+
if (editor === void 0 || typeof editor.entries !== "function" || typeof editor.edit !== "function") {
|
|
201
|
+
visionRouterCompatStatus.routeSkipped = "no-seam";
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const entry = visionRouterEntryOf(editor);
|
|
205
|
+
if (entry === void 0) {
|
|
206
|
+
visionRouterCompatStatus.routeSkipped = "no-row";
|
|
207
|
+
scheduleRetry();
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const editRow = editor.edit.bind(editor);
|
|
211
|
+
const route = routeOf();
|
|
212
|
+
const provider = text(route?.provider);
|
|
213
|
+
const model = text(route?.model);
|
|
214
|
+
if (provider === "" || model === "") {
|
|
215
|
+
visionRouterCompatStatus.routeSkipped = "no-route";
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const preview = planVisionProviders(configOf(entry)?.providers, route, adoptedRoute);
|
|
219
|
+
if (!preview.changed) {
|
|
220
|
+
adoptedRoute = preview.route ?? adoptedRoute;
|
|
221
|
+
if (preview.route !== void 0) {
|
|
222
|
+
visionRouterCompatStatus.installed = true;
|
|
223
|
+
visionRouterCompatStatus.route = preview.route;
|
|
224
|
+
delete visionRouterCompatStatus.routeSkipped;
|
|
225
|
+
}
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const wanted = `${provider}/${model}`;
|
|
229
|
+
pending = (async () => {
|
|
230
|
+
try {
|
|
231
|
+
await editRow(entry, (current) => {
|
|
232
|
+
const base = asRecord(current) ?? {};
|
|
233
|
+
const plan = planVisionProviders(base.providers, route, adoptedRoute);
|
|
234
|
+
return {
|
|
235
|
+
...base,
|
|
236
|
+
providers: plan.providers
|
|
237
|
+
};
|
|
238
|
+
});
|
|
239
|
+
const verify = planVisionProviders(configOf(visionRouterEntryOf(editor))?.providers, route, adoptedRoute);
|
|
240
|
+
if (!verify.changed) {
|
|
241
|
+
adoptedRoute = verify.route ?? wanted;
|
|
242
|
+
attempt = 0;
|
|
243
|
+
visionRouterCompatStatus.installed = true;
|
|
244
|
+
visionRouterCompatStatus.route = wanted;
|
|
245
|
+
delete visionRouterCompatStatus.routeSkipped;
|
|
246
|
+
} else visionRouterCompatStatus.routeSkipped = "rejected";
|
|
247
|
+
} catch (cause) {
|
|
248
|
+
visionRouterCompatStatus.routeSkipped = "rejected";
|
|
249
|
+
ctx.logger.warn(`model-switch: could not write the dsh-vision-router backend chain (${String(cause)})`);
|
|
250
|
+
scheduleRetry();
|
|
251
|
+
} finally {
|
|
252
|
+
pending = void 0;
|
|
253
|
+
}
|
|
254
|
+
})();
|
|
255
|
+
return pending;
|
|
256
|
+
};
|
|
257
|
+
const replay = () => {
|
|
258
|
+
visionRouterCompatStatus.replays += 1;
|
|
259
|
+
run();
|
|
260
|
+
return true;
|
|
261
|
+
};
|
|
262
|
+
run();
|
|
263
|
+
const offPatch = ctx.on("loader/patch-context", function(first, second) {
|
|
264
|
+
const nextFn = typeof first === "function" ? first : second;
|
|
265
|
+
if (isVisionRouterRow(typeof first === "function" ? this : first)) run();
|
|
266
|
+
return nextFn === void 0 ? void 0 : nextFn();
|
|
267
|
+
});
|
|
268
|
+
const offInit = ctx.on("loader/entry-init", function(first) {
|
|
269
|
+
const candidate = this ?? first;
|
|
270
|
+
if (candidate !== void 0 && isVisionRouterRow(candidate)) run();
|
|
271
|
+
});
|
|
272
|
+
const offService = ctx.on("internal/service", (name) => {
|
|
273
|
+
if (name === "configEditor") run();
|
|
274
|
+
});
|
|
275
|
+
const lateSweep = setTimeout(() => {
|
|
276
|
+
run();
|
|
277
|
+
}, 1500);
|
|
278
|
+
lateSweep.unref?.();
|
|
279
|
+
return {
|
|
280
|
+
dispose: () => {
|
|
281
|
+
offPatch();
|
|
282
|
+
offInit();
|
|
283
|
+
offService();
|
|
284
|
+
clearTimeout(lateSweep);
|
|
285
|
+
for (const timer of timers) clearTimeout(timer);
|
|
286
|
+
},
|
|
287
|
+
replay
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Row entry point: adapt the vision plugin on activation and on remount.
|
|
292
|
+
* @param ctx - this row's context.
|
|
293
|
+
*/
|
|
294
|
+
function apply(ctx) {
|
|
295
|
+
ctx.inject(["modelSwitch"], (withProvider) => {
|
|
296
|
+
withProvider.inject(["configEditor"], (scope) => scope.effect(() => {
|
|
297
|
+
const runtime = scope.modelSwitch;
|
|
298
|
+
const loader = scope.get("loader", false);
|
|
299
|
+
const routeOf = () => visionRouteOf(runtime.currentSettings(), deploymentDefaultProviderOf(loader));
|
|
300
|
+
const adapter = installVisionRouterCompat(scope, routeOf);
|
|
301
|
+
const off = scope.on("model-switch/settings-update", () => {
|
|
302
|
+
if (adapter.replay()) scope.logger.info("model-switch: re-applied the dsh-vision-router backend chain after a settings change");
|
|
303
|
+
});
|
|
304
|
+
return () => {
|
|
305
|
+
off();
|
|
306
|
+
adapter.dispose();
|
|
307
|
+
};
|
|
308
|
+
}, "model-switch: keep the dsh-vision-router route aligned with the settings"));
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
//#endregion
|
|
312
|
+
export { visionRouterCompatStatus as a, name as i, inject as n, installVisionRouterCompat as r, apply as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-model-switch",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.69",
|
|
4
4
|
"description": "Explicit model routing plus composer/Plan picker for DeepSeek Harness",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -66,6 +66,10 @@
|
|
|
66
66
|
"types": "./lib/types/prime-memory-compat.d.ts",
|
|
67
67
|
"default": "./lib/prime-memory-compat.js"
|
|
68
68
|
},
|
|
69
|
+
"./vision-router-compat": {
|
|
70
|
+
"types": "./lib/types/vision-router-compat.d.ts",
|
|
71
|
+
"default": "./lib/vision-router-compat.js"
|
|
72
|
+
},
|
|
69
73
|
"./review-timeout": {
|
|
70
74
|
"types": "./lib/types/review-timeout.d.ts",
|
|
71
75
|
"default": "./lib/review-timeout.js"
|