dsh-model-switch 0.4.51 → 0.4.53

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,3 +1,22 @@
1
+ ## v0.4.53
2
+
3
+ 「自动审查模型」与「审查超时」两项设置改为**热生效**,不再需要重启 DSH。
4
+
5
+ - **机制**:用 Cordis 已发布的 `Fiber.update(config, noSave)`(`cordis/lib/types/fiber.d.ts:187-199`:校验→`internal/update` 瀑布→重挂该行,`noSave` 提示不写回持久化)把新配置推给正在运行的行。新增 `src/fiber-hot-update.ts`:只对 `ACTIVE` 的 fiber 动作,返回 `updated` / `no-fiber` / `not-active` / `failed`,异常全部包住,自身不持久化任何东西。
6
+ - **automode 分类器路由**:设置变化且路由相对上次写入发生变化时才重挂。必须走重挂——该行的 `apply(ctx, rawConfig)` 用 zod `Config()` 解析出闭包副本,只替换 `entry.options.config` 触达不到运行中的实例。**副作用**:重挂会清空该行的判定缓存与每会话断路器计数。
7
+ - **审查超时**:文档写入成功后重挂 `llm-pi-ai` 行使新值立即生效;文档仍是持久副本,重挂不可用(无活实例 / 校验失败 / 被瀑布否决)时回落到下次启动,状态里标注 `restart-required`。**副作用**:重挂会中断该 provider 的在途调用,因此只在值真正变化时触发。
8
+ - **状态面**:capabilities RPC 的 `status` 新增 `automode.hot/hotReason` 与 `reviewTimeout{configuredMs,applied,hotApplied,hot,hotReason}`;设置页文案改为“立即生效 + 副作用 + 回落说明”。
9
+ - **lab 证据(virtual / 零真实额度,`D:\dsh-lab`)**:编辑 profile 触发 loader volatile-update 后**未重启**——automode 路由 `probe/gpt-6-luna` → `probe/deepseek-flash` 且 `hot: applied`;`autoReviewTimeoutMs` 设为 5 → 文档写入 `streamIdleTimeoutMs: 5`、`hotApplied: ["probe"]`、`hot: applied`;随后 30 秒 profile 哈希稳定(无重挂循环),profile 里没有 `classifier`(内存态未持久化)。
10
+ - **未验证(如实记录)**:热生效之后「下一次审查请求确实使用新路由/新超时」的请求级行为没有单独取证;重挂被上游否决时的回落只有单测覆盖。
11
+
12
+ ## v0.4.52
13
+
14
+ 修复一个自维持的 recompose 循环(lab 实测定位,DSH 0.2.1-rc.3 + dsh-prime-memory 0.26.10):
15
+
16
+ - **根因**:记忆蒸馏适配层的幂等守卫把 `forms.describe()` 返回的值当 live 段顶层读,而该值是整行配置(`{ llm, live }`)→ 守卫永不命中 → 每次激活都向 memory 的 settings-set RPC 重推路由;memory 插件每次 set 都会把 live 段重新落盘(键序与上一次不同)→ profile 文档变化触发 recompose → 适配层再次激活 → 再次重推。表现为 profile 文档 mtime 约每 5-6 秒一跳、automode 的 `boot` 决策记录约 1.5 条/秒,宿主进程并不重启。
17
+ - **修复**:`memoryLiveMatchesRoute` 同时接受 live 段与整行两种形态(嵌套时取 `live`);命中即跳过推送。新增嵌套形态单测。
18
+ - **证据**:修复前 40 秒窗口 3 次内容变化,相邻快照 diff 仅为 `mdExportMaxRecords` 键序位移(内容相同);修复后 40 秒窗口 **1 次**变化(首启创建 memory 行),之后稳定。二分另确认:移除本插件后 30 秒 0 跳。
19
+
1
20
  ## v0.4.51
2
21
 
3
22
  两处幂等加固,消除对 profile 文档的冗余写入:
@@ -1,4 +1,5 @@
1
1
  import { t as DEFAULT_READ_ONLY_TOOLS } from "./tool-allowlist-DlzB5GlQ.js";
2
+ import { t as applyFiberConfig } from "./fiber-hot-update-DrZANcwD.js";
2
3
  //#region lib/types/automode-compat.js
3
4
  /** Cordis plugin identity; matches the `cordis.patch.yml` insert row id. */
4
5
  const name = "model-switch-automode-compat";
@@ -19,7 +20,11 @@ const automodeCompatStatus = {
19
20
  /** Pattern-shaped entries that cannot transfer. */
20
21
  skipped: [],
21
22
  /** How many rows were rewritten (remounts included). */
22
- applied: 0
23
+ applied: 0,
24
+ /** Last hot-reload outcome, once a changed route was pushed into the live row. */
25
+ hot: void 0,
26
+ /** Why the last hot reload did not take, when it did not. */
27
+ hotReason: void 0
23
28
  };
24
29
  /** Plain-object guard: arrays and `null` are not config objects. */
25
30
  function asRecord(value) {
@@ -189,7 +194,9 @@ function automodeCompatView() {
189
194
  route: automodeCompatStatus.route,
190
195
  routeSkipped: automodeCompatStatus.routeSkipped,
191
196
  added: automodeCompatStatus.added.length,
192
- skipped: automodeCompatStatus.skipped.length
197
+ skipped: automodeCompatStatus.skipped.length,
198
+ hot: automodeCompatStatus.hot,
199
+ hotReason: automodeCompatStatus.hotReason
193
200
  };
194
201
  }
195
202
  /**
@@ -211,11 +218,45 @@ function installAutomodeCompat(ctx, loader, settings) {
211
218
  const applied = /* @__PURE__ */ new Map();
212
219
  /** Entry → the route this adapter wrote, so a replay may rewrite its own value. */
213
220
  const adopted = /* @__PURE__ */ new Map();
214
- const applying = (entry) => {
215
- const plan = adaptEntry(entry, settings, log, adopted.get(entry));
221
+ /** Entries whose fiber reload is in flight, so one change cannot restart twice. */
222
+ const reloading = /* @__PURE__ */ new Set();
223
+ /**
224
+ * Push a changed route into the row that is already running.
225
+ *
226
+ * `dsh-automode` passes its raw config through `Config(rawConfig)` (a zod
227
+ * schema) at activation, so the running instance holds a parsed copy: rewriting
228
+ * `entry.options.config` cannot reach it. Only a fiber reload re-runs `apply`
229
+ * with the adapted config. The reload disposes that instance, so its verdict
230
+ * cache and per-session breaker counters are gone afterwards.
231
+ *
232
+ * A reload that cannot run (`no-fiber` / `not-active`) is not an error: nothing
233
+ * is running that could be stale, and the next mount reads the adapted config.
234
+ */
235
+ const hotApply = (entry, plan, previous) => {
236
+ const route = plan.applied.route;
237
+ if (route === void 0 || route === previous || reloading.has(entry)) return;
238
+ reloading.add(entry);
239
+ applyFiberConfig(entry, plan.config).then((result) => {
240
+ reloading.delete(entry);
241
+ if (result.outcome === "updated") {
242
+ automodeCompatStatus.hot = "applied";
243
+ automodeCompatStatus.hotReason = void 0;
244
+ log.info(`model-switch: reloaded dsh-automode with ${route} (verdict cache and breaker counters were reset)`);
245
+ return;
246
+ }
247
+ if (result.outcome !== "failed") return;
248
+ automodeCompatStatus.hot = "restart-required";
249
+ automodeCompatStatus.hotReason = result.error ?? "reload failed";
250
+ log.warn(`model-switch: the dsh-automode reload with ${route} failed (${result.error ?? "unknown error"}); the new route applies after a Host restart`);
251
+ });
252
+ };
253
+ const applying = (entry, hot) => {
254
+ const previous = adopted.get(entry);
255
+ const plan = adaptEntry(entry, settings, log, previous);
216
256
  if (plan === void 0) return;
217
257
  if (plan.applied.route !== void 0) adopted.set(entry, plan.applied.route);
218
258
  else if (plan.applied.routeSkipped === "user-set") adopted.delete(entry);
259
+ if (hot) hotApply(entry, plan, previous);
219
260
  const summary = describeAutomodePlan(plan);
220
261
  lastSummary = summary;
221
262
  if (!plan.changed) return;
@@ -224,21 +265,21 @@ function installAutomodeCompat(ctx, loader, settings) {
224
265
  log.info(`model-switch: adapted dsh-automode (${summary})`);
225
266
  };
226
267
  if (loader !== void 0 && typeof loader.entries === "function") {
227
- for (const entry of loader.entries()) if (isAutomodeEntry(entry)) applying(entry);
268
+ for (const entry of loader.entries()) if (isAutomodeEntry(entry)) applying(entry, false);
228
269
  }
229
270
  const dispose = ctx.on("loader/patch-context", function(first, second) {
230
271
  const nextFn = typeof first === "function" ? first : second;
231
272
  const candidate = typeof first === "function" ? this : first;
232
- if (isAutomodeEntry(candidate)) applying(candidate);
273
+ if (isAutomodeEntry(candidate)) applying(candidate, false);
233
274
  return nextFn === void 0 ? void 0 : nextFn();
234
275
  });
235
- /** Re-adapt every live row (settings changed under us). */
276
+ /** Re-adapt every live row (settings changed under us) and reload the ones whose route moved. */
236
277
  const replay = () => {
237
278
  let any = false;
238
279
  for (const entry of loader?.entries?.() ?? []) {
239
280
  if (!isAutomodeEntry(entry)) continue;
240
281
  any = true;
241
- applying(entry);
282
+ applying(entry, true);
242
283
  }
243
284
  return any;
244
285
  };
package/lib/client.js CHANGED
@@ -3202,8 +3202,8 @@ window.__ModuleLoader__.load({
3202
3202
  titleRouteHelp: "命名请求固定使用这里的 Provider/模型(不带推理强度);关闭时跟随会话模型。保存后立即对下一次命名生效,不会中断正在进行的命名,会话日志记录的也是实际使用的模型。",
3203
3203
  memory: "记忆蒸馏模型",
3204
3204
  memoryFollow: "跟随记忆插件默认",
3205
- memoryHelp: "为 dsh-prime-memory 的记忆蒸馏指定路由;两个字段都留空时跟随该插件自己的默认模型。改完需重启一次 DSH 才生效(该插件在启动时读取路由)。",
3206
- memoryRouteHelp: "按部署默认供应商的配置组解析;该供应商没有组时使用这里填写的平面默认。写入该行的静态路由(llm.provider/llm.model),启动时生效。",
3205
+ memoryHelp: "为 dsh-prime-memory 的记忆蒸馏指定路由;两个字段都留空时跟随该插件自己的默认模型。保存后立即生效(写入该插件自己的 live 设置,运行中的实例会读到);它拒收时才回落到静态路由,下次启动生效。",
3206
+ memoryRouteHelp: "按部署默认供应商的配置组解析;该供应商没有组时使用这里填写的平面默认。优先写该行的 live 设置(立即生效),不可用时写静态路由(llm.provider/llm.model),启动时生效。",
3207
3207
  providerGroups: "供应商配置组",
3208
3208
  providerGroupsCard: "按供应商预设路由",
3209
3209
  providerGroupsSummary: "使用该供应商的会话自动采用对应组",
@@ -3235,7 +3235,7 @@ window.__ModuleLoader__.load({
3235
3235
  reviewAllowlistSkipped: "本 Host 进程已为纯读调用跳过 {count} 次审查。",
3236
3236
  reviewTimeout: "审查超时",
3237
3237
  reviewTimeoutDefault: "跟随 Provider 默认(300 秒)",
3238
- reviewTimeoutHelp: "设置自动审查请求的流式空闲超时。留空恢复 Provider 默认值;勾选「取消超时」写入上游上限(约 24.8 天),审查将不会因空闲而超时。该值写在 Provider 配置里,改完需重启一次 DSH 才生效。",
3238
+ reviewTimeoutHelp: "设置自动审查请求的流式空闲超时。留空恢复 Provider 默认值;勾选「取消超时」写入上游上限(约 24.8 天),审查将不会因空闲而超时。保存后会立即重挂审查模型所在的 Provider 使其生效,重挂会中断该 Provider 的在途调用;重挂不了时回落到下次启动生效。",
3239
3239
  reviewTimeoutScope: "注意:该值写入审查模型所在 Provider 的 streamIdleTimeoutMs,对该 Provider 的所有调用(含主对话)生效,不只影响审查请求。",
3240
3240
  reviewTimeoutSeconds: "超时秒数",
3241
3241
  reviewTimeoutPlaceholder: "300(默认)",
@@ -3299,8 +3299,8 @@ window.__ModuleLoader__.load({
3299
3299
  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.",
3300
3300
  memory: "Memory distillation model",
3301
3301
  memoryFollow: "Follows the memory plugin default",
3302
- 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.",
3303
- 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.",
3302
+ memoryHelp: "Pin the distillation route for dsh-prime-memory. Both fields empty keeps that plugin on its own default model. Saved changes apply immediately through that plugin’s own live settings; only when it refuses the write does the static route fall back to the next start.",
3303
+ memoryRouteHelp: "Resolved from the deployment default provider group; without a group the flat pair here applies. The live settings are preferred (immediate); the static route (llm.provider/llm.model) is the fallback that applies at start.",
3304
3304
  providerGroups: "Provider groups",
3305
3305
  providerGroupsCard: "Per-provider route presets",
3306
3306
  providerGroupsSummary: "Sessions using that provider adopt this group",
@@ -3332,7 +3332,7 @@ window.__ModuleLoader__.load({
3332
3332
  reviewAllowlistSkipped: "This Host process has skipped the reviewer {count} times.",
3333
3333
  reviewTimeout: "Review timeout",
3334
3334
  reviewTimeoutDefault: "Follows Provider default (300 s)",
3335
- reviewTimeoutHelp: "Set the streaming idle timeout for auto-review requests. Leave empty to restore the Provider default. Check \"Cancel timeout\" to write the upstream ceiling (~24.8 days) so reviews never time out on idle. The value is written into the Provider profile, so it applies after one DSH restart.",
3335
+ reviewTimeoutHelp: "Set the streaming idle timeout for auto-review requests. Leave empty to restore the Provider default. Check \"Cancel timeout\" to write the upstream ceiling (~24.8 days) so reviews never time out on idle. Saving reloads the Provider hosting the reviewer model so the value applies at once; that reload drops the Provider’s in-flight calls. When the reload cannot run, the value applies at the next start.",
3336
3336
  reviewTimeoutScope: "Note: this value is written to the streamIdleTimeoutMs of the Provider hosting the reviewer model and applies to every call through that Provider (main chat included), not only review requests.",
3337
3337
  reviewTimeoutSeconds: "Timeout (seconds)",
3338
3338
  reviewTimeoutPlaceholder: "300 (default)",
@@ -0,0 +1,74 @@
1
+ //#region lib/types/fiber-hot-update.js
2
+ /**
3
+ * Re-apply a plugin row's config in the running Host, without a Host restart.
4
+ *
5
+ * Cordis exposes this seam on the fiber that owns one loader row
6
+ * (`@deepseek-ai/cordis` `lib/types/fiber.d.ts`):
7
+ *
8
+ * update(config: any, noSave?: boolean): void
9
+ * // Validate and apply new config, then restart the plugin. Runs the
10
+ * // `internal/update` waterfall first, so update hooks (and HMR) can veto or
11
+ * // replace the restart. `noSave` — hint for persistence hooks not to write
12
+ * // the change back.
13
+ *
14
+ * So a row can be "remounted" with a config this plugin computed, while the
15
+ * profile document stays ours to write (or untouched, for rows this plugin only
16
+ * adapts in memory). Two consequences are deliberately the caller's business:
17
+ *
18
+ * - the remount disposes the running plugin instance, so whatever runtime state
19
+ * that instance held (a verdict cache, breaker counters, open streams) is
20
+ * gone afterwards;
21
+ * - `noSave` is a *hint*, not a guarantee — a loader with a persistence hook may
22
+ * still write the merged config back.
23
+ *
24
+ * This module only owns the mechanics: pick the fiber, refuse to touch a row
25
+ * that is not settled, contain every failure, and report what happened. It never
26
+ * throws and never persists anything itself.
27
+ *
28
+ * @module
29
+ */
30
+ /**
31
+ * `FiberState.ACTIVE`. The enum is a `const enum`, so the numeric value is what
32
+ * the running build carries; comparing it here keeps the check independent of
33
+ * an import that may be erased by the compiler.
34
+ */
35
+ const FIBER_ACTIVE = 2;
36
+ /** Render an unknown throwable for a log line. */
37
+ function messageOf(cause) {
38
+ return cause instanceof Error ? cause.message : String(cause);
39
+ }
40
+ /**
41
+ * Apply `config` to one live row by restarting its fiber with that config.
42
+ *
43
+ * The caller keeps responsibility for *when* this is safe (for example: only
44
+ * when the value actually changed, and only for rows whose restart cannot cut a
45
+ * call the user is waiting on). This function does not validate that policy.
46
+ *
47
+ * @param entry - the loader row to reload; `undefined` is reported, not thrown.
48
+ * @param config - the complete raw config the row should run with.
49
+ * @returns the outcome; never throws.
50
+ */
51
+ async function applyFiberConfig(entry, config) {
52
+ const fiber = entry?.fiber;
53
+ if (entry === void 0 || fiber === void 0) return { outcome: "no-fiber" };
54
+ if (fiber.state !== FIBER_ACTIVE) return { outcome: "not-active" };
55
+ try {
56
+ fiber.update(config, true);
57
+ } catch (cause) {
58
+ return {
59
+ outcome: "failed",
60
+ error: messageOf(cause)
61
+ };
62
+ }
63
+ try {
64
+ await fiber.await();
65
+ } catch (cause) {
66
+ return {
67
+ outcome: "failed",
68
+ error: messageOf(cause)
69
+ };
70
+ }
71
+ return { outcome: "updated" };
72
+ }
73
+ //#endregion
74
+ export { applyFiberConfig as t };
package/lib/index.js CHANGED
@@ -3,6 +3,7 @@ import { r as resolveToolSource, t as DEFAULT_READ_ONLY_TOOLS } from "./tool-all
3
3
  import { i as autoReviewStatus } from "./auto-review-uu9lvAIZ.js";
4
4
  import { ModelSwitchAdapterRegistry } from "./adapter-registry.js";
5
5
  import { automodeCompatView } from "./automode-compat.js";
6
+ import { u as reviewTimeoutStatus } from "./review-timeout-DXRFybFp.js";
6
7
  import { createRequire } from "node:module";
7
8
  import z from "@deepseek-ai/schemastery";
8
9
  import { Service } from "@deepseek-ai/cordis";
@@ -541,7 +542,14 @@ function installCapabilitiesRpc(ctx, registry, snapshot) {
541
542
  held: autoReviewStatus.held,
542
543
  allowedCalls: autoReviewStatus.allowedCalls,
543
544
  skippedReadOnly: autoReviewStatus.skippedReadOnly,
544
- automode: automodeCompatView()
545
+ automode: automodeCompatView(),
546
+ reviewTimeout: {
547
+ configuredMs: reviewTimeoutStatus.configuredMs,
548
+ applied: reviewTimeoutStatus.applied,
549
+ hotApplied: reviewTimeoutStatus.hotApplied,
550
+ hot: reviewTimeoutStatus.hot,
551
+ hotReason: reviewTimeoutStatus.hotReason
552
+ }
545
553
  }));
546
554
  const dispose = scope.connection.fetch.register({
547
555
  path: "/api/plugin-rpc/model-switch",
@@ -276,8 +276,10 @@ const MEMORY_RPC_PATH = "/dsh-memory/rpc/settings-set";
276
276
  * @returns true when a push would change nothing.
277
277
  */
278
278
  function memoryLiveMatchesRoute(value, provider, model) {
279
- if (value === null || typeof value !== "object") return false;
280
- const live = value;
279
+ const outer = value === null || typeof value !== "object" ? void 0 : value;
280
+ if (outer === void 0) return false;
281
+ const inner = outer.live;
282
+ const live = inner !== null && typeof inner === "object" ? inner : outer;
281
283
  if (live.distillProvider !== provider || live.distillModel !== model) return false;
282
284
  const chain = live.distillChain;
283
285
  if (Array.isArray(chain) && chain.length !== 0) return false;
@@ -0,0 +1,331 @@
1
+ import "./tool-allowlist-DlzB5GlQ.js";
2
+ import { t as applyFiberConfig } from "./fiber-hot-update-DrZANcwD.js";
3
+ Object.freeze({
4
+ mode: "subagentMode",
5
+ provider: "subagentProvider",
6
+ model: "subagentModel",
7
+ reasoningEffort: "subagentReasoningEffort"
8
+ });
9
+ Object.freeze({
10
+ provider: "searchProvider",
11
+ model: "searchModel"
12
+ });
13
+ Object.freeze({
14
+ provider: "imageProvider",
15
+ model: "imageModel"
16
+ });
17
+ Object.freeze({
18
+ provider: "autoReviewProvider",
19
+ model: "autoReviewModel"
20
+ });
21
+ Object.freeze({
22
+ enabled: "autoReviewSkipReadOnly",
23
+ tools: "autoReviewAllowlist"
24
+ });
25
+ /** Upstream ceiling enforced by `@deepseek-ai/dsh-timeout` (MAX_TIMER_DELAY_MS). */
26
+ const UPSTREAM_MAX_IDLE_TIMEOUT_MS = 2147483647;
27
+ Object.freeze({
28
+ provider: "compactProvider",
29
+ model: "compactModel"
30
+ });
31
+ Object.freeze({
32
+ provider: "titleProvider",
33
+ model: "titleModel"
34
+ });
35
+ Object.freeze({
36
+ provider: "memoryProvider",
37
+ model: "memoryModel"
38
+ });
39
+ //#endregion
40
+ //#region lib/types/review-timeout.js
41
+ /** Cordis plugin identity; matches the `cordis.patch.yml` insert row id. */
42
+ const name = "model-switch-review-timeout";
43
+ /** This row needs the Host's settings service (for `documentPath` and our ns). */
44
+ const inject = ["settings", "modelSwitch"];
45
+ /** The pi-ai row whose provider profiles carry `streamIdleTimeoutMs`. */
46
+ const PI_AI_ROW = "llm-pi-ai";
47
+ /** The package the pi-ai row loads; matching by name survives a profile id rename. */
48
+ const PI_AI_PACKAGE = "@deepseek-ai/dsh-llm-pi-ai";
49
+ /** Live state surfaced next to the reviewer card through the capabilities RPC. */
50
+ const reviewTimeoutStatus = {
51
+ configuredMs: void 0,
52
+ applied: [],
53
+ skipped: [],
54
+ /** Providers whose running row was reloaded with the new timeout. */
55
+ hotApplied: [],
56
+ /** Whether the running row took the value, or the next start has to. */
57
+ hot: void 0,
58
+ /** Why the running row did not take the value, when it did not. */
59
+ hotReason: void 0
60
+ };
61
+ /**
62
+ * Resolve the stored setting into concrete write values.
63
+ *
64
+ * Stored values are user intent: absent = follow the provider default, `0` =
65
+ * cancelled (written as the upstream ceiling), anything else is clamped into
66
+ * the upstream-legal range so a hand-edited profile cannot produce a rejected
67
+ * value.
68
+ *
69
+ * @param settings - the plugin's current settings.
70
+ * @returns the write value and the reviewer providers to apply it to.
71
+ */
72
+ function planReviewTimeout(settings) {
73
+ const raw = settings.autoReviewTimeoutMs;
74
+ const timeoutMs = raw === void 0 ? void 0 : raw <= 0 ? UPSTREAM_MAX_IDLE_TIMEOUT_MS : Math.min(Math.floor(raw), UPSTREAM_MAX_IDLE_TIMEOUT_MS);
75
+ const providers = /* @__PURE__ */ new Set();
76
+ const add = (value) => {
77
+ const trimmed = (value ?? "").trim();
78
+ if (trimmed !== "") providers.add(trimmed);
79
+ };
80
+ add(settings.autoReviewProvider);
81
+ for (const group of Object.values(settings.providerGroups ?? {})) add(group.autoReviewProvider);
82
+ return {
83
+ timeoutMs,
84
+ providers: [...providers]
85
+ };
86
+ }
87
+ /** Escape a provider id for use inside a regular expression. */
88
+ function escapeRegExp(value) {
89
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
90
+ }
91
+ /**
92
+ * Set or remove one pi-ai provider's `streamIdleTimeoutMs` in the profile
93
+ * document, touching only that provider's block.
94
+ *
95
+ * The pi-ai row's layout is fixed by its schema: the provider sits at six
96
+ * spaces under `providers:`, its fields at eight. The patch inserts the key at
97
+ * the top of the provider block, replaces it in place, or removes it, and never
98
+ * touches another provider or row.
99
+ *
100
+ * @param text - the full profile document.
101
+ * @param provider - the pi-ai provider id.
102
+ * @param timeoutMs - the value to write, or undefined to remove the key.
103
+ * @returns the patched text and what happened.
104
+ */
105
+ function patchProviderIdleTimeout(text, provider, timeoutMs) {
106
+ const rows = text.split(/(?=^- id: )/m);
107
+ const index = rows.findIndex((row) => new RegExp(`^- id: ${escapeRegExp(PI_AI_ROW)}\\r?$`, "m").test(row.split("\n", 1)[0] ?? ""));
108
+ if (index < 0) return {
109
+ text,
110
+ outcome: "missing-row"
111
+ };
112
+ const row = rows[index];
113
+ const match = new RegExp(`^( {6})(${escapeRegExp(provider)}):(\\r?)$`, "m").exec(row);
114
+ if (match === null) return {
115
+ text,
116
+ outcome: "missing-provider"
117
+ };
118
+ const blockStart = match.index + match[0].length;
119
+ const bodyRe = /\r?\n {0,6}\S/g;
120
+ bodyRe.lastIndex = blockStart;
121
+ const bodyEnd = bodyRe.exec(row)?.index ?? row.length;
122
+ const block = row.slice(blockStart, bodyEnd);
123
+ const idleRe = /^( {8})streamIdleTimeoutMs: *(\d+)(\r?)$/m;
124
+ const idleMatch = idleRe.exec(block);
125
+ if (timeoutMs !== void 0) {
126
+ if (idleMatch !== null) {
127
+ if (Number(idleMatch[2]) === timeoutMs) return {
128
+ text,
129
+ outcome: "unchanged"
130
+ };
131
+ const nextBlock = block.replace(idleRe, `${idleMatch[1]}streamIdleTimeoutMs: ${timeoutMs}${idleMatch[3]}`);
132
+ rows[index] = row.slice(0, blockStart) + nextBlock + row.slice(bodyEnd);
133
+ return {
134
+ text: rows.join(""),
135
+ outcome: "written"
136
+ };
137
+ }
138
+ const nextBlock = `\n streamIdleTimeoutMs: ${timeoutMs}${match[3] === "\r" ? "\r\n" : "\n"}${block.slice(1)}`;
139
+ rows[index] = row.slice(0, blockStart) + nextBlock + row.slice(bodyEnd);
140
+ return {
141
+ text: rows.join(""),
142
+ outcome: "written"
143
+ };
144
+ }
145
+ if (idleMatch === null) return {
146
+ text,
147
+ outcome: "unchanged"
148
+ };
149
+ const removeRe = /^ {8}streamIdleTimeoutMs: *\d+\r?\n/m;
150
+ const withoutLine = removeRe.test(block) ? block.replace(removeRe, "") : block.replace(idleRe, "");
151
+ rows[index] = row.slice(0, blockStart) + withoutLine + row.slice(bodyEnd);
152
+ return {
153
+ text: rows.join(""),
154
+ outcome: "written"
155
+ };
156
+ }
157
+ /**
158
+ * Read a provider's current `streamIdleTimeoutMs` from the document.
159
+ *
160
+ * Used to record the pre-overwrite value so a later reset restores it.
161
+ *
162
+ * @param text - the full profile document.
163
+ * @param provider - the pi-ai provider id.
164
+ * @returns the value, or null when the key is absent.
165
+ */
166
+ function readProviderIdleTimeout(text, provider) {
167
+ const row = text.split(/(?=^- id: )/m).find((candidate) => candidate.startsWith(`- id: llm-pi-ai\n`) || candidate.startsWith(`- id: llm-pi-ai\r\n`));
168
+ if (row === void 0) return null;
169
+ const match = new RegExp(`^ {6}${escapeRegExp(provider)}:\\r?\\n((?: {8}.*\\r?\\n)*)`, "m").exec(row);
170
+ if (match === null) return null;
171
+ const idle = /^ {8}streamIdleTimeoutMs: *(\d+)/m.exec(match[1] ?? "");
172
+ return idle === null ? null : Number(idle[1]);
173
+ }
174
+ /**
175
+ * Build the pi-ai row config with one provider's idle timeout set or removed.
176
+ *
177
+ * Pure: the caller decides whether to hand the result to the loader, and a shape
178
+ * this function does not recognize returns `undefined` instead of a guess.
179
+ *
180
+ * @param config - the row's current config object.
181
+ * @param provider - the pi-ai provider id inside `providers`.
182
+ * @param timeoutMs - the value to set, or undefined to remove the key.
183
+ * @returns the next config, or undefined when the current one is not an object.
184
+ */
185
+ function planProviderConfig(config, provider, timeoutMs) {
186
+ if (config === null || typeof config !== "object" || Array.isArray(config)) return void 0;
187
+ const base = config;
188
+ const providers = base.providers === null || typeof base.providers !== "object" || Array.isArray(base.providers) ? {} : base.providers;
189
+ const nextProvider = { ...providers[provider] === null || typeof providers[provider] !== "object" || Array.isArray(providers[provider]) ? {} : providers[provider] };
190
+ if (timeoutMs === void 0) delete nextProvider.streamIdleTimeoutMs;
191
+ else nextProvider.streamIdleTimeoutMs = timeoutMs;
192
+ return {
193
+ ...base,
194
+ providers: {
195
+ ...providers,
196
+ [provider]: nextProvider
197
+ }
198
+ };
199
+ }
200
+ /**
201
+ * Find the loader row that owns the pi-ai provider profiles.
202
+ *
203
+ * @param loader - the Host loader service, when present.
204
+ * @returns the row entry, or undefined when the profile does not load it.
205
+ */
206
+ function findPiAiEntry(loader) {
207
+ if (loader === void 0 || typeof loader.entries !== "function") return void 0;
208
+ for (const entry of loader.entries()) if (entry.options?.name === PI_AI_PACKAGE || entry.id === "llm-pi-ai") return entry;
209
+ }
210
+ /**
211
+ * Reload the pi-ai row so a changed timeout applies without a Host restart.
212
+ *
213
+ * The document write already happened; this is the runtime half. One reload
214
+ * carries every provider that changed. A reload aborts the provider's in-flight
215
+ * calls, which is why it only runs on an actual value change.
216
+ *
217
+ * @param loader - the Host loader service.
218
+ * @param log - row logger for the one-line report.
219
+ * @param providers - providers whose `streamIdleTimeoutMs` the document write changed.
220
+ * @param timeoutMs - the value the document now carries, or undefined for a reset.
221
+ */
222
+ async function pushHotTimeout(loader, log, providers, timeoutMs) {
223
+ const entry = findPiAiEntry(loader);
224
+ if (entry === void 0) {
225
+ reviewTimeoutStatus.hot = "restart-required";
226
+ reviewTimeoutStatus.hotReason = "the pi-ai row is not loaded";
227
+ return;
228
+ }
229
+ let config = entry.options?.config;
230
+ for (const provider of providers) {
231
+ const next = planProviderConfig(config, provider, timeoutMs);
232
+ if (next === void 0) {
233
+ reviewTimeoutStatus.hot = "restart-required";
234
+ reviewTimeoutStatus.hotReason = "the pi-ai row config is not an object";
235
+ return;
236
+ }
237
+ config = next;
238
+ }
239
+ const result = await applyFiberConfig(entry, config);
240
+ const label = timeoutMs === void 0 ? "reset (provider defaults restored)" : `${timeoutMs}ms`;
241
+ if (result.outcome === "updated") {
242
+ reviewTimeoutStatus.hot = "applied";
243
+ reviewTimeoutStatus.hotReason = void 0;
244
+ for (const provider of providers) if (!reviewTimeoutStatus.hotApplied.includes(provider)) reviewTimeoutStatus.hotApplied.push(provider);
245
+ log.info(`model-switch: reloaded ${PI_AI_ROW} so the review timeout (${label}) applies now to [${providers.join(", ")}]; its in-flight calls were dropped`);
246
+ return;
247
+ }
248
+ reviewTimeoutStatus.hot = "restart-required";
249
+ reviewTimeoutStatus.hotReason = result.outcome === "failed" ? result.error ?? "reload failed" : result.outcome === "no-fiber" ? "the pi-ai row has no live instance" : "the pi-ai row is mid-transition";
250
+ if (result.outcome === "failed") log.warn(`model-switch: the pi-ai reload for the review timeout failed (${reviewTimeoutStatus.hotReason}); the value applies after a Host restart`);
251
+ }
252
+ /**
253
+ * Row entry point: apply the configured timeout to the reviewer providers'
254
+ * pi-ai profiles in the profile document.
255
+ *
256
+ * Every failure is contained and logged; a broken document must never take the
257
+ * Host down. The write is idempotent: replays find the value already in place
258
+ * and do nothing.
259
+ *
260
+ * @param ctx - this row's context.
261
+ */
262
+ function apply(ctx) {
263
+ const log = ctx.logger;
264
+ const execute = async () => {
265
+ reviewTimeoutStatus.configuredMs = void 0;
266
+ reviewTimeoutStatus.applied = [];
267
+ reviewTimeoutStatus.skipped = [];
268
+ reviewTimeoutStatus.hotApplied = [];
269
+ reviewTimeoutStatus.hot = void 0;
270
+ reviewTimeoutStatus.hotReason = void 0;
271
+ const settings = ctx.modelSwitch.currentSettings();
272
+ const plan = planReviewTimeout(settings);
273
+ reviewTimeoutStatus.configuredMs = settings.autoReviewTimeoutMs;
274
+ if (plan.providers.length === 0) return;
275
+ const forms = ctx.get("settings", true);
276
+ const documentPath = forms?.documentPath;
277
+ if (forms === void 0 || typeof documentPath !== "string" || documentPath === "") {
278
+ reviewTimeoutStatus.skipped.push(...plan.providers);
279
+ log.warn("model-switch: no profile document is reachable; the review timeout write is skipped");
280
+ return;
281
+ }
282
+ try {
283
+ const { readFile, writeFile } = await import("node:fs/promises");
284
+ let text = await readFile(documentPath, "utf8");
285
+ let changed = false;
286
+ const changedProviders = [];
287
+ for (const provider of plan.providers) {
288
+ const patched = patchProviderIdleTimeout(text, provider, plan.timeoutMs);
289
+ if (patched.outcome === "written") {
290
+ text = patched.text;
291
+ changed = true;
292
+ changedProviders.push(provider);
293
+ }
294
+ if (patched.outcome === "written" || patched.outcome === "unchanged") reviewTimeoutStatus.applied.push(provider);
295
+ else reviewTimeoutStatus.skipped.push(provider);
296
+ }
297
+ if (changed) await writeFile(documentPath, text, "utf8");
298
+ log.info(`model-switch: review timeout ${plan.timeoutMs === void 0 ? "reset (provider defaults restored)" : `${plan.timeoutMs}ms`} applied to [${reviewTimeoutStatus.applied.join(", ")}]; skipped [${reviewTimeoutStatus.skipped.join(", ")}]`);
299
+ if (changedProviders.length > 0) pushHotTimeout(ctx.get("loader", false), log, changedProviders, plan.timeoutMs);
300
+ } catch (cause) {
301
+ log.warn(`model-switch: the review timeout write failed (${String(cause)})`);
302
+ }
303
+ };
304
+ let pending;
305
+ const run = () => {
306
+ if (pending !== void 0) return pending;
307
+ const next = execute().finally(() => {
308
+ if (pending === next) pending = void 0;
309
+ });
310
+ pending = next;
311
+ return next;
312
+ };
313
+ run();
314
+ const lateSweep = setTimeout(() => {
315
+ run();
316
+ }, 1500);
317
+ const offService = ctx.on("internal/service", (name) => {
318
+ if (name === "settings") run();
319
+ });
320
+ ctx.effect(function* () {
321
+ yield () => {
322
+ offService();
323
+ clearTimeout(lateSweep);
324
+ };
325
+ yield ctx.on("model-switch/settings-update", () => {
326
+ run();
327
+ });
328
+ }, "model-switch: keep the review timeout write aligned with the settings");
329
+ }
330
+ //#endregion
331
+ export { name as a, planReviewTimeout as c, inject as i, readProviderIdleTimeout as l, apply as n, patchProviderIdleTimeout as o, findPiAiEntry as r, planProviderConfig as s, PI_AI_ROW as t, reviewTimeoutStatus as u };
@@ -1,238 +1,2 @@
1
- import "./tool-allowlist-DlzB5GlQ.js";
2
- Object.freeze({
3
- mode: "subagentMode",
4
- provider: "subagentProvider",
5
- model: "subagentModel",
6
- reasoningEffort: "subagentReasoningEffort"
7
- });
8
- Object.freeze({
9
- provider: "searchProvider",
10
- model: "searchModel"
11
- });
12
- Object.freeze({
13
- provider: "imageProvider",
14
- model: "imageModel"
15
- });
16
- Object.freeze({
17
- provider: "autoReviewProvider",
18
- model: "autoReviewModel"
19
- });
20
- Object.freeze({
21
- enabled: "autoReviewSkipReadOnly",
22
- tools: "autoReviewAllowlist"
23
- });
24
- /** Upstream ceiling enforced by `@deepseek-ai/dsh-timeout` (MAX_TIMER_DELAY_MS). */
25
- const UPSTREAM_MAX_IDLE_TIMEOUT_MS = 2147483647;
26
- Object.freeze({
27
- provider: "compactProvider",
28
- model: "compactModel"
29
- });
30
- Object.freeze({
31
- provider: "titleProvider",
32
- model: "titleModel"
33
- });
34
- Object.freeze({
35
- provider: "memoryProvider",
36
- model: "memoryModel"
37
- });
38
- //#endregion
39
- //#region lib/types/review-timeout.js
40
- /** Cordis plugin identity; matches the `cordis.patch.yml` insert row id. */
41
- const name = "model-switch-review-timeout";
42
- /** This row needs the Host's settings service (for `documentPath` and our ns). */
43
- const inject = ["settings", "modelSwitch"];
44
- /** The pi-ai row whose provider profiles carry `streamIdleTimeoutMs`. */
45
- const PI_AI_ROW = "llm-pi-ai";
46
- /** Live state surfaced next to the reviewer card through the capabilities RPC. */
47
- const reviewTimeoutStatus = {
48
- configuredMs: void 0,
49
- applied: [],
50
- skipped: []
51
- };
52
- /**
53
- * Resolve the stored setting into concrete write values.
54
- *
55
- * Stored values are user intent: absent = follow the provider default, `0` =
56
- * cancelled (written as the upstream ceiling), anything else is clamped into
57
- * the upstream-legal range so a hand-edited profile cannot produce a rejected
58
- * value.
59
- *
60
- * @param settings - the plugin's current settings.
61
- * @returns the write value and the reviewer providers to apply it to.
62
- */
63
- function planReviewTimeout(settings) {
64
- const raw = settings.autoReviewTimeoutMs;
65
- const timeoutMs = raw === void 0 ? void 0 : raw <= 0 ? UPSTREAM_MAX_IDLE_TIMEOUT_MS : Math.min(Math.floor(raw), UPSTREAM_MAX_IDLE_TIMEOUT_MS);
66
- const providers = /* @__PURE__ */ new Set();
67
- const add = (value) => {
68
- const trimmed = (value ?? "").trim();
69
- if (trimmed !== "") providers.add(trimmed);
70
- };
71
- add(settings.autoReviewProvider);
72
- for (const group of Object.values(settings.providerGroups ?? {})) add(group.autoReviewProvider);
73
- return {
74
- timeoutMs,
75
- providers: [...providers]
76
- };
77
- }
78
- /** Escape a provider id for use inside a regular expression. */
79
- function escapeRegExp(value) {
80
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
81
- }
82
- /**
83
- * Set or remove one pi-ai provider's `streamIdleTimeoutMs` in the profile
84
- * document, touching only that provider's block.
85
- *
86
- * The pi-ai row's layout is fixed by its schema: the provider sits at six
87
- * spaces under `providers:`, its fields at eight. The patch inserts the key at
88
- * the top of the provider block, replaces it in place, or removes it, and never
89
- * touches another provider or row.
90
- *
91
- * @param text - the full profile document.
92
- * @param provider - the pi-ai provider id.
93
- * @param timeoutMs - the value to write, or undefined to remove the key.
94
- * @returns the patched text and what happened.
95
- */
96
- function patchProviderIdleTimeout(text, provider, timeoutMs) {
97
- const rows = text.split(/(?=^- id: )/m);
98
- const index = rows.findIndex((row) => new RegExp(`^- id: ${escapeRegExp(PI_AI_ROW)}\\r?$`, "m").test(row.split("\n", 1)[0] ?? ""));
99
- if (index < 0) return {
100
- text,
101
- outcome: "missing-row"
102
- };
103
- const row = rows[index];
104
- const match = new RegExp(`^( {6})(${escapeRegExp(provider)}):(\\r?)$`, "m").exec(row);
105
- if (match === null) return {
106
- text,
107
- outcome: "missing-provider"
108
- };
109
- const blockStart = match.index + match[0].length;
110
- const bodyRe = /\r?\n {0,6}\S/g;
111
- bodyRe.lastIndex = blockStart;
112
- const bodyEnd = bodyRe.exec(row)?.index ?? row.length;
113
- const block = row.slice(blockStart, bodyEnd);
114
- const idleRe = /^( {8})streamIdleTimeoutMs: *(\d+)(\r?)$/m;
115
- const idleMatch = idleRe.exec(block);
116
- if (timeoutMs !== void 0) {
117
- if (idleMatch !== null) {
118
- if (Number(idleMatch[2]) === timeoutMs) return {
119
- text,
120
- outcome: "unchanged"
121
- };
122
- const nextBlock = block.replace(idleRe, `${idleMatch[1]}streamIdleTimeoutMs: ${timeoutMs}${idleMatch[3]}`);
123
- rows[index] = row.slice(0, blockStart) + nextBlock + row.slice(bodyEnd);
124
- return {
125
- text: rows.join(""),
126
- outcome: "written"
127
- };
128
- }
129
- const nextBlock = `\n streamIdleTimeoutMs: ${timeoutMs}${match[3] === "\r" ? "\r\n" : "\n"}${block.slice(1)}`;
130
- rows[index] = row.slice(0, blockStart) + nextBlock + row.slice(bodyEnd);
131
- return {
132
- text: rows.join(""),
133
- outcome: "written"
134
- };
135
- }
136
- if (idleMatch === null) return {
137
- text,
138
- outcome: "unchanged"
139
- };
140
- const removeRe = /^ {8}streamIdleTimeoutMs: *\d+\r?\n/m;
141
- const withoutLine = removeRe.test(block) ? block.replace(removeRe, "") : block.replace(idleRe, "");
142
- rows[index] = row.slice(0, blockStart) + withoutLine + row.slice(bodyEnd);
143
- return {
144
- text: rows.join(""),
145
- outcome: "written"
146
- };
147
- }
148
- /**
149
- * Read a provider's current `streamIdleTimeoutMs` from the document.
150
- *
151
- * Used to record the pre-overwrite value so a later reset restores it.
152
- *
153
- * @param text - the full profile document.
154
- * @param provider - the pi-ai provider id.
155
- * @returns the value, or null when the key is absent.
156
- */
157
- function readProviderIdleTimeout(text, provider) {
158
- const row = text.split(/(?=^- id: )/m).find((candidate) => candidate.startsWith(`- id: llm-pi-ai\n`) || candidate.startsWith(`- id: llm-pi-ai\r\n`));
159
- if (row === void 0) return null;
160
- const match = new RegExp(`^ {6}${escapeRegExp(provider)}:\\r?\\n((?: {8}.*\\r?\\n)*)`, "m").exec(row);
161
- if (match === null) return null;
162
- const idle = /^ {8}streamIdleTimeoutMs: *(\d+)/m.exec(match[1] ?? "");
163
- return idle === null ? null : Number(idle[1]);
164
- }
165
- /**
166
- * Row entry point: apply the configured timeout to the reviewer providers'
167
- * pi-ai profiles in the profile document.
168
- *
169
- * Every failure is contained and logged; a broken document must never take the
170
- * Host down. The write is idempotent: replays find the value already in place
171
- * and do nothing.
172
- *
173
- * @param ctx - this row's context.
174
- */
175
- function apply(ctx) {
176
- const log = ctx.logger;
177
- const execute = async () => {
178
- reviewTimeoutStatus.configuredMs = void 0;
179
- reviewTimeoutStatus.applied = [];
180
- reviewTimeoutStatus.skipped = [];
181
- const settings = ctx.modelSwitch.currentSettings();
182
- const plan = planReviewTimeout(settings);
183
- reviewTimeoutStatus.configuredMs = settings.autoReviewTimeoutMs;
184
- if (plan.providers.length === 0) return;
185
- const forms = ctx.get("settings", true);
186
- const documentPath = forms?.documentPath;
187
- if (forms === void 0 || typeof documentPath !== "string" || documentPath === "") {
188
- reviewTimeoutStatus.skipped.push(...plan.providers);
189
- log.warn("model-switch: no profile document is reachable; the review timeout write is skipped");
190
- return;
191
- }
192
- try {
193
- const { readFile, writeFile } = await import("node:fs/promises");
194
- let text = await readFile(documentPath, "utf8");
195
- let changed = false;
196
- for (const provider of plan.providers) {
197
- const patched = patchProviderIdleTimeout(text, provider, plan.timeoutMs);
198
- if (patched.outcome === "written") {
199
- text = patched.text;
200
- changed = true;
201
- }
202
- if (patched.outcome === "written" || patched.outcome === "unchanged") reviewTimeoutStatus.applied.push(provider);
203
- else reviewTimeoutStatus.skipped.push(provider);
204
- }
205
- if (changed) await writeFile(documentPath, text, "utf8");
206
- log.info(`model-switch: review timeout ${plan.timeoutMs === void 0 ? "reset (provider defaults restored)" : `${plan.timeoutMs}ms`} applied to [${reviewTimeoutStatus.applied.join(", ")}]; skipped [${reviewTimeoutStatus.skipped.join(", ")}]; effective after restart`);
207
- } catch (cause) {
208
- log.warn(`model-switch: the review timeout write failed (${String(cause)})`);
209
- }
210
- };
211
- let pending;
212
- const run = () => {
213
- if (pending !== void 0) return pending;
214
- const next = execute().finally(() => {
215
- if (pending === next) pending = void 0;
216
- });
217
- pending = next;
218
- return next;
219
- };
220
- run();
221
- const lateSweep = setTimeout(() => {
222
- run();
223
- }, 1500);
224
- const offService = ctx.on("internal/service", (name) => {
225
- if (name === "settings") run();
226
- });
227
- ctx.effect(function* () {
228
- yield () => {
229
- offService();
230
- clearTimeout(lateSweep);
231
- };
232
- yield ctx.on("model-switch/settings-update", () => {
233
- run();
234
- });
235
- }, "model-switch: keep the review timeout write aligned with the settings");
236
- }
237
- //#endregion
238
- export { PI_AI_ROW, apply, inject, name, patchProviderIdleTimeout, planReviewTimeout, readProviderIdleTimeout, reviewTimeoutStatus };
1
+ import { a as name, c as planReviewTimeout, i as inject, l as readProviderIdleTimeout, n as apply, o as patchProviderIdleTimeout, r as findPiAiEntry, s as planProviderConfig, t as PI_AI_ROW, u as reviewTimeoutStatus } from "./review-timeout-DXRFybFp.js";
2
+ export { PI_AI_ROW, apply, findPiAiEntry, inject, name, patchProviderIdleTimeout, planProviderConfig, planReviewTimeout, readProviderIdleTimeout, reviewTimeoutStatus };
@@ -85,6 +85,10 @@ export declare const automodeCompatStatus: {
85
85
  skipped: string[];
86
86
  /** How many rows were rewritten (remounts included). */
87
87
  applied: number;
88
+ /** Last hot-reload outcome, once a changed route was pushed into the live row. */
89
+ hot: "applied" | "restart-required" | undefined;
90
+ /** Why the last hot reload did not take, when it did not. */
91
+ hotReason: string | undefined;
88
92
  };
89
93
  /**
90
94
  * Whether one loader entry is the third-party auto-mode row.
@@ -122,6 +126,10 @@ export interface AutomodeCompatView {
122
126
  readonly added: number;
123
127
  /** How many pattern-shaped entries could not transfer. */
124
128
  readonly skipped: number;
129
+ /** Last hot-reload outcome, when a changed route was pushed into the live row. */
130
+ readonly hot?: 'applied' | 'restart-required' | undefined;
131
+ /** Why the last hot reload did not take, when it did not. */
132
+ readonly hotReason?: string | undefined;
125
133
  }
126
134
  /**
127
135
  * Snapshot for the RPC/UI layer.
@@ -15,6 +15,16 @@ export interface ReviewStatus {
15
15
  readonly routeSkipped?: string | undefined;
16
16
  readonly added: number;
17
17
  readonly skipped: number;
18
+ readonly hot?: 'applied' | 'restart-required' | undefined;
19
+ readonly hotReason?: string | undefined;
20
+ } | undefined;
21
+ /** Review-timeout adapter state: the write and the runtime reload behind it. */
22
+ readonly reviewTimeout?: {
23
+ readonly configuredMs?: number | undefined;
24
+ readonly applied: readonly string[];
25
+ readonly hotApplied: readonly string[];
26
+ readonly hot?: 'applied' | 'restart-required' | undefined;
27
+ readonly hotReason?: string | undefined;
18
28
  } | undefined;
19
29
  }
20
30
  export declare const CAPABILITIES_RPC_METHOD = "plugin-rpc/model-switch";
@@ -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 的记忆蒸馏指定路由;两个字段都留空时跟随该插件自己的默认模型。改完需重启一次 DSH 才生效(该插件在启动时读取路由)。";
48
- readonly memoryRouteHelp: "按部署默认供应商的配置组解析;该供应商没有组时使用这里填写的平面默认。写入该行的静态路由(llm.provider/llm.model),启动时生效。";
47
+ readonly memoryHelp: "为 dsh-prime-memory 的记忆蒸馏指定路由;两个字段都留空时跟随该插件自己的默认模型。保存后立即生效(写入该插件自己的 live 设置,运行中的实例会读到);它拒收时才回落到静态路由,下次启动生效。";
48
+ readonly memoryRouteHelp: "按部署默认供应商的配置组解析;该供应商没有组时使用这里填写的平面默认。优先写该行的 live 设置(立即生效),不可用时写静态路由(llm.provider/llm.model),启动时生效。";
49
49
  readonly providerGroups: "供应商配置组";
50
50
  readonly providerGroupsCard: "按供应商预设路由";
51
51
  readonly providerGroupsSummary: "使用该供应商的会话自动采用对应组";
@@ -77,7 +77,7 @@ export declare const zh: {
77
77
  readonly reviewAllowlistSkipped: "本 Host 进程已为纯读调用跳过 {count} 次审查。";
78
78
  readonly reviewTimeout: "审查超时";
79
79
  readonly reviewTimeoutDefault: "跟随 Provider 默认(300 秒)";
80
- readonly reviewTimeoutHelp: "设置自动审查请求的流式空闲超时。留空恢复 Provider 默认值;勾选「取消超时」写入上游上限(约 24.8 天),审查将不会因空闲而超时。该值写在 Provider 配置里,改完需重启一次 DSH 才生效。";
80
+ readonly reviewTimeoutHelp: "设置自动审查请求的流式空闲超时。留空恢复 Provider 默认值;勾选「取消超时」写入上游上限(约 24.8 天),审查将不会因空闲而超时。保存后会立即重挂审查模型所在的 Provider 使其生效,重挂会中断该 Provider 的在途调用;重挂不了时回落到下次启动生效。";
81
81
  readonly reviewTimeoutScope: "注意:该值写入审查模型所在 Provider 的 streamIdleTimeoutMs,对该 Provider 的所有调用(含主对话)生效,不只影响审查请求。";
82
82
  readonly reviewTimeoutSeconds: "超时秒数";
83
83
  readonly reviewTimeoutPlaceholder: "300(默认)";
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Re-apply a plugin row's config in the running Host, without a Host restart.
3
+ *
4
+ * Cordis exposes this seam on the fiber that owns one loader row
5
+ * (`@deepseek-ai/cordis` `lib/types/fiber.d.ts`):
6
+ *
7
+ * update(config: any, noSave?: boolean): void
8
+ * // Validate and apply new config, then restart the plugin. Runs the
9
+ * // `internal/update` waterfall first, so update hooks (and HMR) can veto or
10
+ * // replace the restart. `noSave` — hint for persistence hooks not to write
11
+ * // the change back.
12
+ *
13
+ * So a row can be "remounted" with a config this plugin computed, while the
14
+ * profile document stays ours to write (or untouched, for rows this plugin only
15
+ * adapts in memory). Two consequences are deliberately the caller's business:
16
+ *
17
+ * - the remount disposes the running plugin instance, so whatever runtime state
18
+ * that instance held (a verdict cache, breaker counters, open streams) is
19
+ * gone afterwards;
20
+ * - `noSave` is a *hint*, not a guarantee — a loader with a persistence hook may
21
+ * still write the merged config back.
22
+ *
23
+ * This module only owns the mechanics: pick the fiber, refuse to touch a row
24
+ * that is not settled, contain every failure, and report what happened. It never
25
+ * throws and never persists anything itself.
26
+ *
27
+ * @module
28
+ */
29
+ import type { Entry } from '@deepseek-ai/cordis-plugin-loader';
30
+ /** How one hot config application ended. */
31
+ export type HotUpdateOutcome =
32
+ /** The row was reloaded with the new config. */
33
+ 'updated'
34
+ /** The row has no fiber (not mounted, or already torn down). */
35
+ | 'no-fiber'
36
+ /** The row is mid-transition; the change was skipped on purpose. */
37
+ | 'not-active'
38
+ /** The new config failed the plugin's own validation, or the reload threw. */
39
+ | 'failed';
40
+ /** Result of one hot config application. */
41
+ export interface HotUpdateResult {
42
+ /** What happened. */
43
+ readonly outcome: HotUpdateOutcome;
44
+ /** The failure text, when `outcome === 'failed'`. */
45
+ readonly error?: string | undefined;
46
+ }
47
+ /**
48
+ * Apply `config` to one live row by restarting its fiber with that config.
49
+ *
50
+ * The caller keeps responsibility for *when* this is safe (for example: only
51
+ * when the value actually changed, and only for rows whose restart cannot cut a
52
+ * call the user is waiting on). This function does not validate that policy.
53
+ *
54
+ * @param entry - the loader row to reload; `undefined` is reported, not thrown.
55
+ * @param config - the complete raw config the row should run with.
56
+ * @returns the outcome; never throws.
57
+ */
58
+ export declare function applyFiberConfig(entry: Entry | undefined, config: unknown): Promise<HotUpdateResult>;
@@ -15,8 +15,11 @@
15
15
  * - "Cancel the timeout" is legal only as the upstream ceiling
16
16
  * (`MAX_TIMER_DELAY_MS` = 2147483647 ms ≈ 24.86 days); upstream rejects 0,
17
17
  * negatives and Infinity, so the UI writes the ceiling and says so.
18
- * - The profile document is read at Host start (same channel as the memory
19
- * static pin), so a written value takes effect **after a restart**.
18
+ * - The profile document is the durable copy. After writing it, the running
19
+ * pi-ai row is reloaded through the loader fiber so the value applies without
20
+ * a Host restart; that reload drops the provider's in-flight calls. When the
21
+ * reload cannot run (no live row, a vetoed update, a failed validation) the
22
+ * value still lands at the next Host start, and the status line says so.
20
23
  *
21
24
  * Restoring is symmetric: the value a provider carried before the first
22
25
  * overwrite is recorded in this plugin's own settings
@@ -27,6 +30,7 @@
27
30
  * @module
28
31
  */
29
32
  import type { Context } from '@deepseek-ai/cordis';
33
+ import type { Entry, Loader } from '@deepseek-ai/cordis-plugin-loader';
30
34
  import type { ModelSwitchSettings } from './host-settings.js';
31
35
  /** Cordis plugin identity; matches the `cordis.patch.yml` insert row id. */
32
36
  export declare const name = "model-switch-review-timeout";
@@ -39,6 +43,12 @@ export declare const reviewTimeoutStatus: {
39
43
  configuredMs: number | undefined;
40
44
  applied: string[];
41
45
  skipped: string[];
46
+ /** Providers whose running row was reloaded with the new timeout. */
47
+ hotApplied: string[];
48
+ /** Whether the running row took the value, or the next start has to. */
49
+ hot: "applied" | "restart-required" | undefined;
50
+ /** Why the running row did not take the value, when it did not. */
51
+ hotReason: string | undefined;
42
52
  };
43
53
  /** One resolved write decision. */
44
54
  export interface ReviewTimeoutPlan {
@@ -91,6 +101,25 @@ export declare function patchProviderIdleTimeout(text: string, provider: string,
91
101
  * @returns the value, or null when the key is absent.
92
102
  */
93
103
  export declare function readProviderIdleTimeout(text: string, provider: string): number | null;
104
+ /**
105
+ * Build the pi-ai row config with one provider's idle timeout set or removed.
106
+ *
107
+ * Pure: the caller decides whether to hand the result to the loader, and a shape
108
+ * this function does not recognize returns `undefined` instead of a guess.
109
+ *
110
+ * @param config - the row's current config object.
111
+ * @param provider - the pi-ai provider id inside `providers`.
112
+ * @param timeoutMs - the value to set, or undefined to remove the key.
113
+ * @returns the next config, or undefined when the current one is not an object.
114
+ */
115
+ export declare function planProviderConfig(config: unknown, provider: string, timeoutMs: number | undefined): Record<string, unknown> | undefined;
116
+ /**
117
+ * Find the loader row that owns the pi-ai provider profiles.
118
+ *
119
+ * @param loader - the Host loader service, when present.
120
+ * @returns the row entry, or undefined when the profile does not load it.
121
+ */
122
+ export declare function findPiAiEntry(loader: Loader | undefined): Entry | undefined;
94
123
  /**
95
124
  * Row entry point: apply the configured timeout to the reviewer providers'
96
125
  * pi-ai profiles in the profile document.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-model-switch",
3
- "version": "0.4.51",
3
+ "version": "0.4.53",
4
4
  "description": "Explicit model routing plus composer/Plan picker for DeepSeek Harness",
5
5
  "repository": {
6
6
  "type": "git",