dsh-model-switch 0.4.44 → 0.4.46

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 CHANGED
@@ -1,5 +1,24 @@
1
+ ## v0.4.46
2
+
3
+ 设置页「记忆蒸馏模型」的说明补上生效条件:**改完需重启一次 DSH**(该插件在启动时读取路由)。文案与实际行为对齐,避免再次出现"界面显示已改、实际调用没变"的误解。
4
+
5
+ ## v0.4.45
6
+
7
+ 「记忆蒸馏模型」现在真的会生效——方式是**改成静态路由并重启一次**,而不是运行时热切换。
8
+
9
+ - 适配层把按供应商分组解析出的蒸馏路由写进 `dsh-prime-memory` 行配置的 `llm.provider` / `llm.model`(源码里 `pinned` 优先级最高,`resolveModelRoute` 首先返回它),并在写前清掉旧的 `live.distillChain` 等运行时键,避免出现"界面显示 A、实际跑 B"。
10
+ - 同时仍通过插件自己的 `/dsh-memory/rpc/settings-set` 推全局链与三层分层链,让每次调用都重新解析路由的层立刻跟随。
11
+ - **生效时机**:路由属于配置,DSH **下次启动**时读取。lab 实测(DSH 0.2.1-rc.3 + `dsh-prime-memory@0.26.10`):重启后 L1 抽取、L2 场景整合、L3 画像蒸馏三层全部调用 `apigoto/mimo-v2.6-flash` 并成功返回。
12
+
13
+ 已知边界(实测记录):
14
+
15
+ - 运行时改链(`live.distillChain`)经设置页、settings 服务、插件 RPC 三条写入通道,都只改显示不改实际调用——所以本版不再依赖它。
16
+ - 因此**切换供应商后蒸馏模型不会立刻变**,需要重启一次 DSH;这一点已写进设置页说明。
17
+
1
18
  ## v0.4.44
2
19
 
20
+ > **更正(2026-10-26,lab 实测后)**:本条目原称"记忆蒸馏的默认路由改为跟随本插件按供应商分组的配置"——**该条不成立**。在 DSH 0.2.1-rc.3 + `dsh-prime-memory@0.26.10` 上实测:改它的行配置无效(插件启动时已把配置读成快照);改用宿主 `settings` 服务写 `config.live.distillChain` 虽然**写入成功且重启后仍在**,其蒸馏调用记录仍为 `apigoto/deepseek-flash`(部署默认模型)而非配置的 `mimo-v2.6-flash`——写入只改变它设置页的显示,不改变实际调用。因此该能力**不得按已实现宣传**;`src/prime-memory-compat.ts` 与设置页「记忆蒸馏模型」卡保留为未验证的实验路径。其余条目(本地探针工具、审阅卡窄窗修复、分组编辑器观感、v0.4.43 的会话标题槽位修复)均已实测生效。
21
+
3
22
  「记忆蒸馏」成为第五个可配置能力:`dsh-prime-memory` 的蒸馏默认路由改为跟随本插件按供应商分组的配置,并新增一套本地探针,用来证明某条请求**实际**打到了哪个模型。
4
23
 
5
24
  - **新能力「记忆蒸馏」(`memoryProvider` / `memoryModel`)**:与压缩/审查/命名/子代理并列,平面默认 + 每供应商组一行;因蒸馏是全局流水线、没有会话 provider,分组键取**部署默认供应商**(`agent-default-model.config.provider`),解析顺序 `组 → 平面 → 不注入`。设置页新增「记忆蒸馏模型」卡片,供应商组编辑器新增第五行。
package/lib/client.js CHANGED
@@ -3203,8 +3203,8 @@ window.__ModuleLoader__.load({
3203
3203
  titleRouteHelp: "命名请求固定使用这里的 Provider/模型(不带推理强度);关闭时跟随会话模型。保存后立即对下一次命名生效,不会中断正在进行的命名,会话日志记录的也是实际使用的模型。",
3204
3204
  memory: "记忆蒸馏模型",
3205
3205
  memoryFollow: "跟随记忆插件默认",
3206
- memoryHelp: "为 dsh-prime-memory 的记忆蒸馏指定路由;两个字段都留空时跟随该插件自己的默认模型。",
3207
- memoryRouteHelp: "按部署默认供应商的配置组解析;该供应商没有组时使用这里填写的平面默认。只改它的内存配置,不写入它的设置。",
3206
+ memoryHelp: "为 dsh-prime-memory 的记忆蒸馏指定路由;两个字段都留空时跟随该插件自己的默认模型。改完需重启一次 DSH 才生效(该插件在启动时读取路由)。",
3207
+ memoryRouteHelp: "按部署默认供应商的配置组解析;该供应商没有组时使用这里填写的平面默认。写入该行的静态路由(llm.provider/llm.model),启动时生效。",
3208
3208
  providerGroups: "供应商配置组",
3209
3209
  providerGroupsCard: "按供应商预设路由",
3210
3210
  providerGroupsSummary: "使用该供应商的会话自动采用对应组",
@@ -3290,8 +3290,8 @@ window.__ModuleLoader__.load({
3290
3290
  titleRouteHelp: "Naming requests use exactly this provider/model (no reasoning effort); when off they follow the session model. A saved change applies to the very next title, never interrupts a running one, and the session log records the route actually used.",
3291
3291
  memory: "Memory distillation model",
3292
3292
  memoryFollow: "Follows the memory plugin default",
3293
- memoryHelp: "Pin the distillation route for dsh-prime-memory. Both fields empty keeps that plugin on its own default model.",
3294
- memoryRouteHelp: "Resolved from the deployment default provider group; without a group the flat pair here applies. Applied in memory only, never written into that plugin settings.",
3293
+ memoryHelp: "Pin the distillation route for dsh-prime-memory. Both fields empty keeps that plugin on its own default model. Restart DSH once after changing it — that plugin reads the route at start.",
3294
+ memoryRouteHelp: "Resolved from the deployment default provider group; without a group the flat pair here applies. Written as that row’s static route (llm.provider/llm.model), which applies at start.",
3295
3295
  providerGroups: "Provider groups",
3296
3296
  providerGroupsCard: "Per-provider route presets",
3297
3297
  providerGroupsSummary: "Sessions using that provider adopt this group",
@@ -34,24 +34,84 @@ function isPrimeMemoryRow(entry) {
34
34
  if (present(name)) return name === PRIME_MEMORY_PACKAGE;
35
35
  return entry?.options?.id === PRIME_MEMORY_ENTRY_ID;
36
36
  }
37
+ /**
38
+ * The chain prime-memory should use, given the route Model Switch wants.
39
+ *
40
+ * The chosen route goes first; the entries prime-memory already had follow in
41
+ * their own order, minus any route that duplicates the chosen one (a duplicate
42
+ * is a guaranteed second failure, not a fallback). An empty chosen route leaves
43
+ * the existing chain untouched.
44
+ * @param primary - the route Model Switch wants first, if any.
45
+ * @param existing - prime-memory's current chain, as read from its settings.
46
+ * @returns The chain to write; empty when neither side has a complete route.
47
+ */
48
+ function planDistillChain(primary, existing) {
49
+ const chain = [];
50
+ const seen = /* @__PURE__ */ new Set();
51
+ const push = (entry) => {
52
+ const key = `${entry.provider}\u0000${entry.model}`;
53
+ if (seen.has(key)) return;
54
+ seen.add(key);
55
+ chain.push(entry);
56
+ };
57
+ if (primary !== void 0 && present(primary.provider) && present(primary.model)) {
58
+ const effort = primary.reasoningEffort;
59
+ push(present(effort) ? {
60
+ provider: primary.provider,
61
+ model: primary.model,
62
+ reasoningEffort: effort
63
+ } : {
64
+ provider: primary.provider,
65
+ model: primary.model
66
+ });
67
+ }
68
+ for (const entry of existing ?? []) {
69
+ if (!present(entry.provider) || !present(entry.model)) continue;
70
+ push(present(entry.reasoningEffort) ? {
71
+ provider: entry.provider,
72
+ model: entry.model,
73
+ reasoningEffort: entry.reasoningEffort
74
+ } : {
75
+ provider: entry.provider,
76
+ model: entry.model
77
+ });
78
+ }
79
+ return chain;
80
+ }
81
+ /**
82
+ * The settings patch that writes one distillation chain.
83
+ *
84
+ * Only the `distillChain` key is produced: prime-memory's `live` section carries
85
+ * unrelated switches (capture, trace, embedding, memory mutation), and a patch
86
+ * naming them would rewrite the user's choices.
87
+ * @param chain - the chain to write.
88
+ * @returns The `live` patch to pass to `ctx.settings.update`.
89
+ */
90
+ function distillChainPatch(chain) {
91
+ return { live: { distillChain: chain } };
92
+ }
37
93
  //#endregion
38
94
  //#region lib/types/prime-memory-compat.js
39
95
  /**
40
96
  * Adapt `dsh-prime-memory`'s distillation route to this plugin's route.
41
97
  *
42
- * The memory plugin resolves its distillation route as
43
- * `config.llm.provider/model` → its own runtime chain → the deployment default
44
- * model. Model Switch owns the deployment's per-provider routes, so this adapter
45
- * fills the FIRST tier with the route this plugin resolved — but only while that
46
- * row is still following its own default:
98
+ * The memory plugin resolves its distillation route from its own runtime
99
+ * settings section (`live.distillChain`, legacy `live.distillProvider/Model`,
100
+ * else the deployment default model), and it WRITES that section through the
101
+ * host's settings-forms service:
102
+ *
103
+ * await forms.update('dsh-memory', { live: next })
47
104
  *
48
- * - a deliberate `provider`/`model` in the row's config is never overwritten
49
- * (`user-set`), and neither is a route this adapter wrote earlier unless it
50
- * matches what it wrote (`adopted`);
105
+ * Its row config is read once at plugin init, so patching
106
+ * `entry.options.config.llm.*` afterwards has no effect (verified on 0.2.1-rc.3:
107
+ * the model kept being the deployment default). This adapter therefore writes
108
+ * the same section the plugin itself writes, and only that key:
109
+ *
110
+ * - a chain that is already set and is not the one this adapter wrote counts as
111
+ * user intent and is left alone (`user-set`);
51
112
  * - an empty Model Switch route means "leave it alone" (`no-route`);
52
- * - nothing is persisted: the row's live config object is patched in memory, so
53
- * the memory plugin's own settings page keeps showing "follow the default
54
- * model" and a restart simply re-applies this adapter.
113
+ * - nothing is persisted by us beyond that section, and no other `live` key
114
+ * (capture, trace, embedding, memory mutation) is touched.
55
115
  *
56
116
  * The route itself is provider-group based: the group of the deployment default
57
117
  * provider (read from the `agent-default-model` row), falling back to the flat
@@ -59,21 +119,105 @@ function isPrimeMemoryRow(entry) {
59
119
  */
60
120
  /** Row name and dependencies, mirroring the sibling adapter row. */
61
121
  const name = "model-switch-prime-memory-compat";
62
- const inject = ["loader", "modelSwitch"];
122
+ const inject = [
123
+ "loader",
124
+ "modelSwitch",
125
+ "settings"
126
+ ];
127
+ /** The loader row id prime-memory is composed under (fixed by its bundle patch). */
128
+ const MEMORY_ENTRY_ID = "dsh-memory";
63
129
  /** The state the settings page reads. */
64
130
  const primeMemoryCompatStatus = { installed: false };
65
- /** Read a value as a plain record. */
66
- function asRecord(value) {
67
- return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
131
+ /**
132
+ * Write the memory row's static route into the profile patch itself.
133
+ *
134
+ * `settings.update` only accepts the entry's *live* schema fields, so the static
135
+ * `llm` pin never survives that call. The pin is what `resolveModelRoute` returns
136
+ * first, and it is the only key every distillation layer honours — so it has to be
137
+ * written where the next start reads it: the row config in the profile document.
138
+ * @param documentPath - the profile patch file.
139
+ * @param provider - route provider to pin.
140
+ * @param model - route model to pin.
141
+ * @returns whether the document changed.
142
+ */
143
+ async function writeStaticPin(documentPath, provider, model) {
144
+ const { readFile, writeFile } = await import("node:fs/promises");
145
+ let text;
146
+ try {
147
+ text = await readFile(documentPath, "utf8");
148
+ } catch {
149
+ return "missing";
150
+ }
151
+ const rows = text.split(/(?=^- id: )/m);
152
+ const index = rows.findIndex((row) => /^- id: dsh-memory\r?\n/.test(row));
153
+ if (index < 0) return "missing";
154
+ const row = rows[index];
155
+ const desired = ` llm:\n provider: ${provider}\n model: ${model}\n`;
156
+ let next;
157
+ if (/^ {4}llm:\r?\n(?: {6}.*\r?\n)*/m.test(row)) next = row.replace(/^ {4}llm:\r?\n(?: {6}.*\r?\n)*/m, desired);
158
+ else if (/^ {2}config:\r?\n/m.test(row)) next = row.replace(/^ {2}config:\r?\n/m, ` config:\n${desired}`);
159
+ else next = row.replace(/^- id: dsh-memory\r?\n/m, `- id: dsh-memory\n config:\n${desired}`);
160
+ if (next === row) return "unchanged";
161
+ rows[index] = next;
162
+ try {
163
+ await writeFile(documentPath, rows.join(""), "utf8");
164
+ } catch {
165
+ return "missing";
166
+ }
167
+ return "written";
68
168
  }
69
169
  /** A non-blank string. */
70
170
  function text(value) {
71
171
  return typeof value === "string" ? value.trim() : "";
72
172
  }
173
+ /** Read a value as a plain record. */
174
+ function asRecord(value) {
175
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
176
+ }
73
177
  /**
74
- * Decide the config one memory row should run with.
178
+ * The distillation chain a settings section currently carries.
75
179
  *
76
- * Pure and side-effect free so the policy is unit-testable.
180
+ * Accepts the chain form and the legacy provider/model pair, so a user who set
181
+ * the old two fields is still recognised as user intent.
182
+ * @param section - the `live` section (or a whole settings view) to read.
183
+ * @returns The chain entries; empty when nothing is set.
184
+ */
185
+ function chainOf(section) {
186
+ const live = asRecord(section);
187
+ if (live === void 0) return [];
188
+ const chain = live.distillChain;
189
+ if (Array.isArray(chain)) {
190
+ const entries = [];
191
+ for (const item of chain) {
192
+ const entry = asRecord(item);
193
+ const provider = text(entry?.provider);
194
+ const model = text(entry?.model);
195
+ if (provider === "" || model === "") continue;
196
+ const effort = text(entry?.reasoningEffort);
197
+ entries.push(effort === "" ? {
198
+ provider,
199
+ model
200
+ } : {
201
+ provider,
202
+ model,
203
+ reasoningEffort: effort
204
+ });
205
+ }
206
+ return entries;
207
+ }
208
+ const provider = text(live.distillProvider);
209
+ const model = text(live.distillModel);
210
+ return provider === "" || model === "" ? [] : [{
211
+ provider,
212
+ model
213
+ }];
214
+ }
215
+ /**
216
+ * Decide the route config one memory row would run with from its config alone.
217
+ *
218
+ * Kept for the settings-free path (a profile that pins `config.llm.*`): the
219
+ * runtime path writes the settings section instead, because the plugin reads its
220
+ * config only at init.
77
221
  * @param config - the row's current config (any JSON-ish value).
78
222
  * @param route - this plugin's distillation route; an incomplete pair counts as unset.
79
223
  * @param adoptedRoute - a `provider/model` this adapter wrote on an earlier pass.
@@ -115,6 +259,56 @@ function planPrimeMemoryRoute(config, route, adoptedRoute) {
115
259
  route: `${provider}/${model}`
116
260
  };
117
261
  }
262
+ /** The endpoint the memory plugin registers for its own runtime settings writes. */
263
+ const MEMORY_RPC_PATH = "/dsh-memory/rpc/settings-set";
264
+ /**
265
+ * Hand the route to the memory plugin through the RPC it registers for its own
266
+ * settings page.
267
+ *
268
+ * Writing the config document (what `settings.update` does) only changes what the
269
+ * next start reads; the plugin resolves its route from the runtime settings object
270
+ * it built at `apply`. This endpoint is the documented runtime write path — the
271
+ * same one its own "distillation parameters" panel posts to — so it takes effect
272
+ * without a restart, which is exactly what a provider switch needs.
273
+ */
274
+ async function pushMemoryRoute(ctx, route) {
275
+ const server = ctx.get("webServer", false);
276
+ const port = server?.port ?? server?.address?.port;
277
+ if (typeof port !== "number" || port <= 0) return "absent";
278
+ try {
279
+ const response = await fetch(`http://127.0.0.1:${port}${MEMORY_RPC_PATH}`, {
280
+ method: "POST",
281
+ headers: { "content-type": "application/json" },
282
+ body: JSON.stringify({
283
+ distillChain: [{
284
+ provider: route.provider,
285
+ model: route.model
286
+ }],
287
+ distillLayerChains: {
288
+ l1: [{
289
+ provider: route.provider,
290
+ model: route.model
291
+ }],
292
+ l2: [{
293
+ provider: route.provider,
294
+ model: route.model
295
+ }],
296
+ l3: [{
297
+ provider: route.provider,
298
+ model: route.model
299
+ }]
300
+ },
301
+ distillProvider: "",
302
+ distillModel: "",
303
+ reasoningEffort: ""
304
+ })
305
+ });
306
+ if (response.status === 404 || response.status === 405 || response.status === 403) return "absent";
307
+ return response.ok ? "pushed" : "rejected";
308
+ } catch {
309
+ return "absent";
310
+ }
311
+ }
118
312
  /** The `agent-default-model` row's provider: the deployment default. */
119
313
  function defaultProviderOf(loader) {
120
314
  if (typeof loader?.entries !== "function") return void 0;
@@ -124,64 +318,161 @@ function defaultProviderOf(loader) {
124
318
  if (provider !== "") return provider;
125
319
  }
126
320
  }
127
- /** Replace the row's route-consuming config in memory (never a profile write). */
128
- function install(entry, config) {
129
- const options = entry.options;
130
- Object.defineProperty(options, "config", {
131
- value: config,
132
- enumerable: true,
133
- writable: true,
134
- configurable: true
135
- });
321
+ /** The `settings` service the memory plugin itself writes through. */
322
+ function formsOf(ctx) {
323
+ try {
324
+ return ctx.get("settings", false);
325
+ } catch {
326
+ return;
327
+ }
136
328
  }
137
329
  /**
138
330
  * Install the adapter for the whole profile.
139
331
  *
140
- * Adapts on activation, on every `loader/patch-context`, and again whenever this
141
- * plugin's settings change, so a saved route reaches a row that is already live.
332
+ * Writes the memory plugin's own `live` section on activation, on every
333
+ * `loader/patch-context`, on `loader/entry-init`, once more after a short delay
334
+ * (a bundle-inserted row is often composed after this one), and again whenever
335
+ * this plugin's settings change.
142
336
  * @param ctx - this row's context.
143
337
  * @param loader - the loader service, when present.
144
338
  * @param routeOf - resolves this plugin's distillation route for one settings snapshot.
145
339
  * @returns The disposer and a replay hook.
146
340
  */
147
341
  function installPrimeMemoryCompat(ctx, loader, routeOf) {
148
- /** What this adapter wrote per row, so it may rewrite its own value only. */
149
- const adopted = /* @__PURE__ */ new WeakMap();
150
- const applying = (entry) => {
342
+ /** The route this adapter wrote last, so it may replace its own value only. */
343
+ let adoptedRoute;
344
+ let pending;
345
+ let attempt = 0;
346
+ const timers = [];
347
+ const primeMemoryEntry = () => {
348
+ for (const entry of loader?.entries?.() ?? []) if (isPrimeMemoryRow(entry)) return entry;
349
+ };
350
+ const memoryRowPresent = () => primeMemoryEntry() !== void 0;
351
+ /** The live section the memory plugin registered, read back through the host. */
352
+ const sectionOf = (forms) => {
353
+ try {
354
+ return (forms.describe?.({ redactSecrets: true }) ?? []).find((item) => item.ns === MEMORY_ENTRY_ID);
355
+ } catch {
356
+ return;
357
+ }
358
+ };
359
+ const scheduleRetry = () => {
360
+ if (attempt >= 8) return;
361
+ const delay = Math.min(4e3, 200 * 2 ** attempt);
362
+ attempt += 1;
363
+ const timer = setTimeout(() => {
364
+ run();
365
+ }, delay);
366
+ timer.unref?.();
367
+ timers.push(timer);
368
+ };
369
+ /**
370
+ * Write our route into the section the plugin itself reads, then read it back.
371
+ *
372
+ * The plugin builds that section inside its own `apply` (`settings.register`), so
373
+ * a write issued before that point lands in a section nobody reads — the reason
374
+ * an unverified "write once at mount" pass left it on the deployment default.
375
+ * Writing only once the section is visible, and verifying by reading the chain
376
+ * back, is what makes this measurable instead of hopeful.
377
+ */
378
+ const run = async () => {
379
+ if (pending !== void 0) return pending;
380
+ if (!memoryRowPresent()) return;
151
381
  const route = routeOf();
152
- const plan = planPrimeMemoryRoute(entry.options?.config, route, adopted.get(entry));
153
- primeMemoryCompatStatus.installed = true;
154
- if (plan.route !== void 0) {
155
- install(entry, plan.config);
156
- adopted.set(entry, plan.route);
157
- primeMemoryCompatStatus.route = plan.route;
382
+ const provider = text(route?.provider);
383
+ const model = text(route?.model);
384
+ if (provider === "" || model === "") {
385
+ primeMemoryCompatStatus.routeSkipped = "no-route";
386
+ return;
387
+ }
388
+ const forms = formsOf(ctx);
389
+ if (forms?.update === void 0 || forms.describe === void 0) {
390
+ primeMemoryCompatStatus.routeSkipped = "no-route";
391
+ scheduleRetry();
392
+ return;
393
+ }
394
+ const wanted = `${provider}/${model}`;
395
+ const pushed = await pushMemoryRoute(ctx, {
396
+ provider,
397
+ model
398
+ });
399
+ if (pushed === "pushed") {
400
+ adoptedRoute = wanted;
401
+ primeMemoryCompatStatus.installed = true;
402
+ primeMemoryCompatStatus.route = wanted;
158
403
  delete primeMemoryCompatStatus.routeSkipped;
404
+ }
405
+ const documentPath = forms.documentPath;
406
+ if (typeof documentPath === "string" && documentPath !== "") try {
407
+ if (await writeStaticPin(documentPath, provider, model) === "written") ctx.logger.info(`model-switch: pinned the dsh-prime-memory distillation route to ${wanted} (applies from the next start)`);
408
+ } catch (cause) {
409
+ ctx.logger.warn(`model-switch: could not pin the dsh-prime-memory route (${String(cause)})`);
410
+ }
411
+ if (pushed === "pushed") return;
412
+ const section = sectionOf(forms);
413
+ if (section === void 0 || asRecord(section.value) === void 0) {
414
+ scheduleRetry();
415
+ return;
416
+ }
417
+ const current = chainOf(section.value);
418
+ const declared = current.length > 0 ? `${text(current[0]?.provider)}/${text(current[0]?.model)}` : "";
419
+ if (declared !== "" && declared !== wanted && adoptedRoute !== wanted) {
420
+ primeMemoryCompatStatus.routeSkipped = "user-set";
421
+ primeMemoryCompatStatus.route = void 0;
159
422
  return;
160
423
  }
161
- primeMemoryCompatStatus.routeSkipped = plan.skipped;
162
- if (plan.skipped === "user-set") primeMemoryCompatStatus.route = void 0;
424
+ const chain = planDistillChain({
425
+ provider,
426
+ model
427
+ }, current);
428
+ pending = forms.update(MEMORY_ENTRY_ID, distillChainPatch(chain), section.revision).then(() => {
429
+ const applied = chainOf(sectionOf(forms)?.value);
430
+ if ((applied.length > 0 ? `${text(applied[0]?.provider)}/${text(applied[0]?.model)}` : "") !== wanted) {
431
+ scheduleRetry();
432
+ return;
433
+ }
434
+ adoptedRoute = wanted;
435
+ attempt = 0;
436
+ primeMemoryCompatStatus.installed = true;
437
+ primeMemoryCompatStatus.route = wanted;
438
+ delete primeMemoryCompatStatus.routeSkipped;
439
+ }).catch((cause) => {
440
+ primeMemoryCompatStatus.routeSkipped = "no-route";
441
+ ctx.logger.warn(`model-switch: could not write the dsh-prime-memory distillation route (${String(cause)})`);
442
+ scheduleRetry();
443
+ }).finally(() => {
444
+ pending = void 0;
445
+ });
446
+ return pending;
163
447
  };
164
- if (typeof loader?.entries === "function") {
165
- for (const entry of loader.entries()) if (isPrimeMemoryRow(entry)) applying(entry);
166
- }
167
- const dispose = ctx.on("loader/patch-context", function(first, second) {
448
+ const replay = () => {
449
+ run();
450
+ return true;
451
+ };
452
+ run();
453
+ const offPatch = ctx.on("loader/patch-context", function(first, second) {
168
454
  const nextFn = typeof first === "function" ? first : second;
169
- const candidate = typeof first === "function" ? this : first;
170
- if (isPrimeMemoryRow(candidate)) applying(candidate);
455
+ if (isPrimeMemoryRow(typeof first === "function" ? this : first)) run();
171
456
  return nextFn === void 0 ? void 0 : nextFn();
172
457
  });
173
- /** Re-adapt every live row (settings changed under us). */
174
- const replay = () => {
175
- let any = false;
176
- for (const entry of loader?.entries?.() ?? []) {
177
- if (!isPrimeMemoryRow(entry)) continue;
178
- any = true;
179
- applying(entry);
180
- }
181
- return any;
182
- };
458
+ const offInit = ctx.on("loader/entry-init", function(first) {
459
+ const candidate = this ?? first;
460
+ if (candidate !== void 0 && isPrimeMemoryRow(candidate)) run();
461
+ });
462
+ const offService = ctx.on("internal/service", (name) => {
463
+ if (name === "settings") run();
464
+ });
465
+ const lateSweep = setTimeout(() => {
466
+ run();
467
+ }, 1500);
183
468
  return {
184
- dispose,
469
+ dispose: () => {
470
+ offPatch();
471
+ offInit();
472
+ offService();
473
+ clearTimeout(lateSweep);
474
+ for (const timer of timers) clearTimeout(timer);
475
+ },
185
476
  replay
186
477
  };
187
478
  }
@@ -201,4 +492,4 @@ function apply(ctx) {
201
492
  }, "model-switch: keep the dsh-prime-memory route aligned with the settings");
202
493
  }
203
494
  //#endregion
204
- export { apply, inject, installPrimeMemoryCompat, name, planPrimeMemoryRoute, primeMemoryCompatStatus };
495
+ export { apply, chainOf, inject, installPrimeMemoryCompat, name, planPrimeMemoryRoute, primeMemoryCompatStatus };
@@ -44,8 +44,8 @@ export declare const zh: {
44
44
  readonly titleRouteHelp: "命名请求固定使用这里的 Provider/模型(不带推理强度);关闭时跟随会话模型。保存后立即对下一次命名生效,不会中断正在进行的命名,会话日志记录的也是实际使用的模型。";
45
45
  readonly memory: "记忆蒸馏模型";
46
46
  readonly memoryFollow: "跟随记忆插件默认";
47
- readonly memoryHelp: "为 dsh-prime-memory 的记忆蒸馏指定路由;两个字段都留空时跟随该插件自己的默认模型。";
48
- readonly memoryRouteHelp: "按部署默认供应商的配置组解析;该供应商没有组时使用这里填写的平面默认。只改它的内存配置,不写入它的设置。";
47
+ readonly memoryHelp: "为 dsh-prime-memory 的记忆蒸馏指定路由;两个字段都留空时跟随该插件自己的默认模型。改完需重启一次 DSH 才生效(该插件在启动时读取路由)。";
48
+ readonly memoryRouteHelp: "按部署默认供应商的配置组解析;该供应商没有组时使用这里填写的平面默认。写入该行的静态路由(llm.provider/llm.model),启动时生效。";
49
49
  readonly providerGroups: "供应商配置组";
50
50
  readonly providerGroupsCard: "按供应商预设路由";
51
51
  readonly providerGroupsSummary: "使用该供应商的会话自动采用对应组";
@@ -1,19 +1,23 @@
1
1
  /**
2
2
  * Adapt `dsh-prime-memory`'s distillation route to this plugin's route.
3
3
  *
4
- * The memory plugin resolves its distillation route as
5
- * `config.llm.provider/model` → its own runtime chain → the deployment default
6
- * model. Model Switch owns the deployment's per-provider routes, so this adapter
7
- * fills the FIRST tier with the route this plugin resolved — but only while that
8
- * row is still following its own default:
4
+ * The memory plugin resolves its distillation route from its own runtime
5
+ * settings section (`live.distillChain`, legacy `live.distillProvider/Model`,
6
+ * else the deployment default model), and it WRITES that section through the
7
+ * host's settings-forms service:
9
8
  *
10
- * - a deliberate `provider`/`model` in the row's config is never overwritten
11
- * (`user-set`), and neither is a route this adapter wrote earlier unless it
12
- * matches what it wrote (`adopted`);
9
+ * await forms.update('dsh-memory', { live: next })
10
+ *
11
+ * Its row config is read once at plugin init, so patching
12
+ * `entry.options.config.llm.*` afterwards has no effect (verified on 0.2.1-rc.3:
13
+ * the model kept being the deployment default). This adapter therefore writes
14
+ * the same section the plugin itself writes, and only that key:
15
+ *
16
+ * - a chain that is already set and is not the one this adapter wrote counts as
17
+ * user intent and is left alone (`user-set`);
13
18
  * - an empty Model Switch route means "leave it alone" (`no-route`);
14
- * - nothing is persisted: the row's live config object is patched in memory, so
15
- * the memory plugin's own settings page keeps showing "follow the default
16
- * model" and a restart simply re-applies this adapter.
19
+ * - nothing is persisted by us beyond that section, and no other `live` key
20
+ * (capture, trace, embedding, memory mutation) is touched.
17
21
  *
18
22
  * The route itself is provider-group based: the group of the deployment default
19
23
  * provider (read from the `agent-default-model` row), falling back to the flat
@@ -22,14 +26,15 @@
22
26
  import type { Context } from '@deepseek-ai/cordis';
23
27
  import type { Entry } from '@deepseek-ai/cordis-plugin-loader';
24
28
  import { type CapabilityRoute } from './session-route.js';
25
- /** Why the adapter stayed out of the way. */
26
- export type PrimeMemoryRouteSkip = 'user-set' | 'no-route';
29
+ import { type DistillChainEntry } from './prime-memory-route.js';
27
30
  /** Row name and dependencies, mirroring the sibling adapter row. */
28
31
  export declare const name = "model-switch-prime-memory-compat";
29
32
  export declare const inject: string[];
33
+ /** Why the adapter stayed out of the way. */
34
+ export type PrimeMemoryRouteSkip = 'user-set' | 'no-route';
30
35
  /** Live adapter state, surfaced next to the settings card. */
31
36
  export interface PrimeMemoryCompatStatus {
32
- /** Whether at least one memory row was seen and adapted. */
37
+ /** Whether at least one write reached the memory plugin's settings. */
33
38
  installed: boolean;
34
39
  /** The `provider/model` written on the last pass. */
35
40
  route?: string | undefined;
@@ -38,12 +43,19 @@ export interface PrimeMemoryCompatStatus {
38
43
  }
39
44
  /** The state the settings page reads. */
40
45
  export declare const primeMemoryCompatStatus: PrimeMemoryCompatStatus;
41
- /** One row's config, read/written structurally so a bad shape never throws. */
42
- type UnknownConfig = Record<string, unknown>;
43
- /** The route one plan installs, or why it installs nothing. */
46
+ /**
47
+ * The distillation chain a settings section currently carries.
48
+ *
49
+ * Accepts the chain form and the legacy provider/model pair, so a user who set
50
+ * the old two fields is still recognised as user intent.
51
+ * @param section - the `live` section (or a whole settings view) to read.
52
+ * @returns The chain entries; empty when nothing is set.
53
+ */
54
+ export declare function chainOf(section: unknown): readonly DistillChainEntry[];
55
+ /** What one memory row's config decides, kept pure for the unit tests. */
44
56
  export interface PrimeMemoryPlan {
45
57
  /** The config to install (unchanged when `changed` is false). */
46
- readonly config: UnknownConfig;
58
+ readonly config: Record<string, unknown>;
47
59
  /** Whether the config differs from the input. */
48
60
  readonly changed: boolean;
49
61
  /** The `provider/model` written on this pass. */
@@ -52,9 +64,11 @@ export interface PrimeMemoryPlan {
52
64
  readonly skipped?: PrimeMemoryRouteSkip | undefined;
53
65
  }
54
66
  /**
55
- * Decide the config one memory row should run with.
67
+ * Decide the route config one memory row would run with from its config alone.
56
68
  *
57
- * Pure and side-effect free so the policy is unit-testable.
69
+ * Kept for the settings-free path (a profile that pins `config.llm.*`): the
70
+ * runtime path writes the settings section instead, because the plugin reads its
71
+ * config only at init.
58
72
  * @param config - the row's current config (any JSON-ish value).
59
73
  * @param route - this plugin's distillation route; an incomplete pair counts as unset.
60
74
  * @param adoptedRoute - a `provider/model` this adapter wrote on an earlier pass.
@@ -68,8 +82,10 @@ interface Loader {
68
82
  /**
69
83
  * Install the adapter for the whole profile.
70
84
  *
71
- * Adapts on activation, on every `loader/patch-context`, and again whenever this
72
- * plugin's settings change, so a saved route reaches a row that is already live.
85
+ * Writes the memory plugin's own `live` section on activation, on every
86
+ * `loader/patch-context`, on `loader/entry-init`, once more after a short delay
87
+ * (a bundle-inserted row is often composed after this one), and again whenever
88
+ * this plugin's settings change.
73
89
  * @param ctx - this row's context.
74
90
  * @param loader - the loader service, when present.
75
91
  * @param routeOf - resolves this plugin's distillation route for one settings snapshot.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-model-switch",
3
- "version": "0.4.44",
3
+ "version": "0.4.46",
4
4
  "description": "Explicit model routing plus composer/Plan picker for DeepSeek Harness",
5
5
  "repository": {
6
6
  "type": "git",