dsh-model-switch 0.4.70 → 0.4.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import { a as bindAutoReviewSessionCorrelation, c as installToolCallSafetyNet, d as resolveSessionAutoReviewRoute, f as reviewLlm, i as autoReviewStatus, l as isReviewerInfrastructureFailure, n as autoReviewGate, o as defensivePermissionPresets, p as reviewScope, r as autoReviewRouteOf, s as inject, t as apply, u as name } from "./auto-review-CYvvootQ.js";
1
+ import { a as bindAutoReviewSessionCorrelation, c as installToolCallSafetyNet, d as resolveSessionAutoReviewRoute, f as reviewLlm, i as autoReviewStatus, l as isReviewerInfrastructureFailure, n as autoReviewGate, o as defensivePermissionPresets, p as reviewScope, r as autoReviewRouteOf, s as inject, t as apply, u as name } from "./auto-review-B4L59yj4.js";
2
2
  export { apply, autoReviewGate, autoReviewRouteOf, autoReviewStatus, bindAutoReviewSessionCorrelation, defensivePermissionPresets, inject, installToolCallSafetyNet, isReviewerInfrastructureFailure, name, resolveSessionAutoReviewRoute, reviewLlm, reviewScope };
@@ -1,4 +1,4 @@
1
- import { t as DEFAULT_READ_ONLY_TOOLS } from "./tool-allowlist-cN9Z1XKn.js";
1
+ import { t as DEFAULT_READ_ONLY_TOOLS } from "./tool-allowlist-Ddb8jfNx.js";
2
2
  import { t as applyFiberConfig } from "./fiber-hot-update-DrZANcwD.js";
3
3
  //#region lib/types/automode-compat.js
4
4
  /** Cordis plugin identity; matches the `cordis.patch.yml` insert row id. */
package/lib/client.js CHANGED
@@ -64,6 +64,42 @@ window.__ModuleLoader__.load({
64
64
  label: "插件 · dsh-embedded-browser",
65
65
  repo: "https://github.com/imroc/dsh-embedded-browser"
66
66
  },
67
+ {
68
+ id: "dsh-bilibili-summary",
69
+ kind: "plugin",
70
+ label: "插件 · dsh-bilibili-summary",
71
+ repo: "https://github.com/Adamaik/dsh-zcode-plugins"
72
+ },
73
+ {
74
+ id: "dsh-media-lens",
75
+ kind: "plugin",
76
+ label: "插件 · dsh-media-lens",
77
+ repo: "https://github.com/drscrewdriver/dsh-media-lens"
78
+ },
79
+ {
80
+ id: "dsh-video-storyboard",
81
+ kind: "plugin",
82
+ label: "插件 · dsh-video-storyboard",
83
+ repo: "https://github.com/SAOS-3624/dsh-video-storyboard"
84
+ },
85
+ {
86
+ id: "dsh-video-studio",
87
+ kind: "plugin",
88
+ label: "插件 · dsh-video-studio",
89
+ repo: "https://github.com/vandoor7-droid/dsh-video-studio"
90
+ },
91
+ {
92
+ id: "dsh-meme-radar",
93
+ kind: "plugin",
94
+ label: "插件 · dsh-meme-radar",
95
+ repo: "https://github.com/vandoor7-droid/dsh-meme-radar"
96
+ },
97
+ {
98
+ id: "dsh-windows-mcp",
99
+ kind: "plugin",
100
+ label: "插件 · dsh-windows-mcp",
101
+ repo: "https://github.com/helloHub1212/dsh-windows-mcp"
102
+ },
67
103
  {
68
104
  id: "mcp:wincu",
69
105
  kind: "mcp",
@@ -145,6 +181,8 @@ window.__ModuleLoader__.load({
145
181
  "terminal_signal",
146
182
  "todo_write",
147
183
  "update_goal",
184
+ "user_terminal_list",
185
+ "user_terminal_read",
148
186
  "wait_agent",
149
187
  "web_fetch",
150
188
  "web_search",
@@ -162,7 +200,12 @@ window.__ModuleLoader__.load({
162
200
  ["browser_embedded_", "dsh-embedded-browser"],
163
201
  ["ops_", "dsh-ops"],
164
202
  ["vision_", "dsh-vision-router"],
165
- ["univer_", "dsh-univer-office"]
203
+ ["univer_", "dsh-univer-office"],
204
+ ["bilibili_", "dsh-bilibili-summary"],
205
+ ["media_read_", "dsh-media-lens"],
206
+ ["video_", "dsh-video-storyboard"],
207
+ ["studio_", "dsh-video-studio"],
208
+ ["meme_", "dsh-meme-radar"]
166
209
  ];
167
210
  /**
168
211
  * Single plugin tools that carry no usable prefix.
@@ -203,7 +246,9 @@ window.__ModuleLoader__.load({
203
246
  ["memory_list", "dsh-auto-memory"],
204
247
  ["memory_prune", "dsh-auto-memory"],
205
248
  ["memory_read", "dsh-auto-memory"],
206
- ["memory_write", "dsh-auto-memory"]
249
+ ["memory_write", "dsh-auto-memory"],
250
+ ["hotlist_scan", "dsh-meme-radar"],
251
+ ["windows_mcp_doctor", "dsh-windows-mcp"]
207
252
  ]);
208
253
  /** `<base>__<owner>` — the extension-tool naming the QQ bot framework uses. */
209
254
  const EXTENSION_TOOL = /^([A-Za-z0-9_-]+)__(.+)$/;
@@ -227,7 +272,8 @@ window.__ModuleLoader__.load({
227
272
  * Beyond that rule sit the entries the user explicitly released (2026-10-24:
228
273
  * goal/schedule/terminal creation; 2026-11-20: the vision model calls, the
229
274
  * mineru document_parse task, todo/goal updates, and the prime-memory write
230
- * tools). These do have side effects — vision calls spend the configured
275
+ * tools; 2026-11-22: the media-lens file reads and the video storyboard
276
+ * search/decode tools). These do have side effects — vision calls spend the configured
231
277
  * backend's quota and send image content to it, document_parse spawns a parse
232
278
  * task, the memory tools mutate the memory store — but everything they enable
233
279
  * stays inside the same session and auto preset. Releasing them only skips the
@@ -236,7 +282,11 @@ window.__ModuleLoader__.load({
236
282
  * from the parent's in-flight bypass answer, so releasing them would strip the
237
283
  * child of the auto preset entirely (see DELEGATION_SPAWNS in the tests).
238
284
  * schedule_edit was reviewed on 2026-11-20 and deliberately kept OUT: it can
239
- * modify or delete tasks other sessions created.
285
+ * modify or delete tasks other sessions created. bilibili_login (writes the
286
+ * stored sign-in session), bilibili_transcribe (its first run builds a private
287
+ * virtualenv, downloads a whisper model and the audio) and meme_add (writes
288
+ * the meme library) were reviewed on 2026-11-22 and stay OUT for the same
289
+ * reason.
240
290
  */
241
291
  const DEFAULT_READ_ONLY_TOOLS = [
242
292
  "read",
@@ -337,6 +387,19 @@ window.__ModuleLoader__.load({
337
387
  "mcp__mineru-mcp__get_task_progress",
338
388
  "mcp__mineru-mcp__get_recent_logs",
339
389
  "mcp__mineru-mcp__wait_for_task",
390
+ "user_terminal_list",
391
+ "user_terminal_read",
392
+ "windows_mcp_doctor",
393
+ "meme_query",
394
+ "hotlist_scan",
395
+ "bilibili_video_info",
396
+ "bilibili_series",
397
+ "bilibili_subtitles",
398
+ "video_help",
399
+ "video_probe",
400
+ "video_storyboard_settings",
401
+ "studio_status",
402
+ "studio_open",
340
403
  "vision_describe",
341
404
  "vision_bootstrap",
342
405
  "vision_ground",
@@ -363,6 +426,14 @@ window.__ModuleLoader__.load({
363
426
  "memory_migrate_relation",
364
427
  "memory_reproject",
365
428
  "memory_ruminate_cancel",
429
+ "media_read_image",
430
+ "media_read_audio",
431
+ "media_read_pdf",
432
+ "media_read_video",
433
+ "video_locate",
434
+ "video_storyboard",
435
+ "video_subtitles",
436
+ "video_zoom",
366
437
  "sessions_list__*",
367
438
  "bing_search__*"
368
439
  ];
@@ -1259,15 +1330,21 @@ window.__ModuleLoader__.load({
1259
1330
  }
1260
1331
  function deriveRouteChoices(groups, route, allowedProviders) {
1261
1332
  const allowed = allowedProviders === void 0 ? void 0 : new Set(allowedProviders);
1262
- const providers = groups.filter((group) => allowed === void 0 || allowed.has(group.id)).map((group) => ({
1333
+ const listed = groups.filter((group) => allowed === void 0 || allowed.has(group.id)).map((group) => ({
1263
1334
  id: group.id,
1264
1335
  name: group.name
1265
1336
  }));
1266
- if (route?.provider !== void 0 && !providers.some((option) => option.id === route.provider)) providers.push({
1337
+ if (route?.provider !== void 0 && !listed.some((option) => option.id === route.provider)) listed.push({
1267
1338
  id: route.provider,
1268
1339
  name: route.provider,
1269
1340
  unavailable: true
1270
1341
  });
1342
+ const ids = new Set(listed.map((choice) => choice.id));
1343
+ const providers = listed.filter((choice) => {
1344
+ if (choice.id === route?.provider) return true;
1345
+ const base = canonicalGroupProvider(choice.id);
1346
+ return base === choice.id || !ids.has(base);
1347
+ });
1271
1348
  const models = (groups.find((item) => item.id === route?.provider)?.models ?? []).map((model) => ({
1272
1349
  id: model.id,
1273
1350
  name: model.name
@@ -1298,13 +1375,7 @@ window.__ModuleLoader__.load({
1298
1375
  * @returns catalog choices first (original order), then the missing providers.
1299
1376
  */
1300
1377
  function groupProviderChoices(groups, configured, current) {
1301
- const listed = deriveRouteChoices(groups, current === void 0 || current.trim() === "" ? void 0 : { provider: current }).providers;
1302
- const ids = new Set(listed.map((choice) => choice.id));
1303
- const choices = listed.filter((choice) => {
1304
- if (choice.id === current) return true;
1305
- const base = canonicalGroupProvider(choice.id);
1306
- return base === choice.id || !ids.has(base);
1307
- });
1378
+ const choices = deriveRouteChoices(groups, current === void 0 || current.trim() === "" ? void 0 : { provider: current }).providers;
1308
1379
  const seen = new Set(choices.map((choice) => choice.id));
1309
1380
  for (const provider of configured) {
1310
1381
  if (provider.trim() === "" || seen.has(provider)) continue;
package/lib/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { l as normalizeProviderGroups } from "./session-route-CRfpxarI.js";
2
- import { r as resolveToolSource, t as DEFAULT_READ_ONLY_TOOLS } from "./tool-allowlist-cN9Z1XKn.js";
3
- import { i as autoReviewStatus } from "./auto-review-CYvvootQ.js";
2
+ import { r as resolveToolSource, t as DEFAULT_READ_ONLY_TOOLS } from "./tool-allowlist-Ddb8jfNx.js";
3
+ import { i as autoReviewStatus } from "./auto-review-B4L59yj4.js";
4
4
  import { ModelSwitchAdapterRegistry } from "./adapter-registry.js";
5
5
  import { automodeCompatView } from "./automode-compat.js";
6
6
  import { s as subagentDiscoveryHintStatus } from "./subagent-runtime-eNKrdb2H.js";
7
- import { u as reviewTimeoutStatus } from "./review-timeout-FB32BcnO.js";
7
+ import { u as reviewTimeoutStatus } from "./review-timeout-CAlD65wl.js";
8
8
  import { primeMemoryCompatStatus } from "./prime-memory-compat.js";
9
9
  import { a as visionRouterCompatStatus } from "./vision-router-compat-DP81VMLW.js";
10
10
  import { createRequire } from "node:module";
@@ -0,0 +1,339 @@
1
+ import "./tool-allowlist-Ddb8jfNx.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
+ reasoningEffort: "memoryReasoningEffort"
39
+ });
40
+ Object.freeze({
41
+ provider: "visionProvider",
42
+ model: "visionModel"
43
+ });
44
+ //#endregion
45
+ //#region lib/types/review-timeout.js
46
+ /** Cordis plugin identity; matches the `cordis.patch.yml` insert row id. */
47
+ const name = "model-switch-review-timeout";
48
+ /** This row needs the Host's settings service (for `documentPath` and our ns). */
49
+ const inject = ["settings"];
50
+ /** The pi-ai row whose provider profiles carry `streamIdleTimeoutMs`. */
51
+ const PI_AI_ROW = "llm-pi-ai";
52
+ /** The package the pi-ai row loads; matching by name survives a profile id rename. */
53
+ const PI_AI_PACKAGE = "@deepseek-ai/dsh-llm-pi-ai";
54
+ /** Live state surfaced next to the reviewer card through the capabilities RPC. */
55
+ const reviewTimeoutStatus = {
56
+ configuredMs: void 0,
57
+ applied: [],
58
+ skipped: [],
59
+ /** Providers whose running row was reloaded with the new timeout. */
60
+ hotApplied: [],
61
+ /** Whether the running row took the value, or the next start has to. */
62
+ hot: void 0,
63
+ /** Why the running row did not take the value, when it did not. */
64
+ hotReason: void 0
65
+ };
66
+ /**
67
+ * Resolve the stored setting into concrete write values.
68
+ *
69
+ * Stored values are user intent: absent = follow the provider default, `0` =
70
+ * cancelled (written as the upstream ceiling), anything else is clamped into
71
+ * the upstream-legal range so a hand-edited profile cannot produce a rejected
72
+ * value.
73
+ *
74
+ * @param settings - the plugin's current settings.
75
+ * @returns the write value and the reviewer providers to apply it to.
76
+ */
77
+ function planReviewTimeout(settings) {
78
+ const raw = settings.autoReviewTimeoutMs;
79
+ const timeoutMs = raw === void 0 ? void 0 : raw <= 0 ? UPSTREAM_MAX_IDLE_TIMEOUT_MS : Math.min(Math.floor(raw), UPSTREAM_MAX_IDLE_TIMEOUT_MS);
80
+ const providers = /* @__PURE__ */ new Set();
81
+ const add = (value) => {
82
+ const trimmed = (value ?? "").trim();
83
+ if (trimmed !== "") providers.add(trimmed);
84
+ };
85
+ add(settings.autoReviewProvider);
86
+ for (const group of Object.values(settings.providerGroups ?? {})) add(group.autoReviewProvider);
87
+ return {
88
+ timeoutMs,
89
+ providers: [...providers]
90
+ };
91
+ }
92
+ /** Escape a provider id for use inside a regular expression. */
93
+ function escapeRegExp(value) {
94
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
95
+ }
96
+ /**
97
+ * Set or remove one pi-ai provider's `streamIdleTimeoutMs` in the profile
98
+ * document, touching only that provider's block.
99
+ *
100
+ * The pi-ai row's layout is fixed by its schema: the provider sits at six
101
+ * spaces under `providers:`, its fields at eight. The patch inserts the key at
102
+ * the top of the provider block, replaces it in place, or removes it, and never
103
+ * touches another provider or row.
104
+ *
105
+ * @param text - the full profile document.
106
+ * @param provider - the pi-ai provider id.
107
+ * @param timeoutMs - the value to write, or undefined to remove the key.
108
+ * @returns the patched text and what happened.
109
+ */
110
+ function patchProviderIdleTimeout(text, provider, timeoutMs) {
111
+ const rows = text.split(/(?=^- id: )/m);
112
+ const index = rows.findIndex((row) => new RegExp(`^- id: ${escapeRegExp(PI_AI_ROW)}\\r?$`, "m").test(row.split("\n", 1)[0] ?? ""));
113
+ if (index < 0) return {
114
+ text,
115
+ outcome: "missing-row"
116
+ };
117
+ const row = rows[index];
118
+ const match = new RegExp(`^( {6})(${escapeRegExp(provider)}):(\\r?)$`, "m").exec(row);
119
+ if (match === null) return {
120
+ text,
121
+ outcome: "missing-provider"
122
+ };
123
+ const blockStart = match.index + match[0].length;
124
+ const bodyRe = /\r?\n {0,6}\S/g;
125
+ bodyRe.lastIndex = blockStart;
126
+ const bodyEnd = bodyRe.exec(row)?.index ?? row.length;
127
+ const block = row.slice(blockStart, bodyEnd);
128
+ const idleRe = /^( {8})streamIdleTimeoutMs: *(\d+)(\r?)$/m;
129
+ const idleMatch = idleRe.exec(block);
130
+ if (timeoutMs !== void 0) {
131
+ if (idleMatch !== null) {
132
+ if (Number(idleMatch[2]) === timeoutMs) return {
133
+ text,
134
+ outcome: "unchanged"
135
+ };
136
+ const nextBlock = block.replace(idleRe, `${idleMatch[1]}streamIdleTimeoutMs: ${timeoutMs}${idleMatch[3]}`);
137
+ rows[index] = row.slice(0, blockStart) + nextBlock + row.slice(bodyEnd);
138
+ return {
139
+ text: rows.join(""),
140
+ outcome: "written"
141
+ };
142
+ }
143
+ const nextBlock = `\n streamIdleTimeoutMs: ${timeoutMs}${match[3] === "\r" ? "\r\n" : "\n"}${block.slice(1)}`;
144
+ rows[index] = row.slice(0, blockStart) + nextBlock + row.slice(bodyEnd);
145
+ return {
146
+ text: rows.join(""),
147
+ outcome: "written"
148
+ };
149
+ }
150
+ if (idleMatch === null) return {
151
+ text,
152
+ outcome: "unchanged"
153
+ };
154
+ const removeRe = /^ {8}streamIdleTimeoutMs: *\d+\r?\n/m;
155
+ const withoutLine = removeRe.test(block) ? block.replace(removeRe, "") : block.replace(idleRe, "");
156
+ rows[index] = row.slice(0, blockStart) + withoutLine + row.slice(bodyEnd);
157
+ return {
158
+ text: rows.join(""),
159
+ outcome: "written"
160
+ };
161
+ }
162
+ /**
163
+ * Read a provider's current `streamIdleTimeoutMs` from the document.
164
+ *
165
+ * Used to record the pre-overwrite value so a later reset restores it.
166
+ *
167
+ * @param text - the full profile document.
168
+ * @param provider - the pi-ai provider id.
169
+ * @returns the value, or null when the key is absent.
170
+ */
171
+ function readProviderIdleTimeout(text, provider) {
172
+ const row = text.split(/(?=^- id: )/m).find((candidate) => candidate.startsWith(`- id: llm-pi-ai\n`) || candidate.startsWith(`- id: llm-pi-ai\r\n`));
173
+ if (row === void 0) return null;
174
+ const match = new RegExp(`^ {6}${escapeRegExp(provider)}:\\r?\\n((?: {8}.*\\r?\\n)*)`, "m").exec(row);
175
+ if (match === null) return null;
176
+ const idle = /^ {8}streamIdleTimeoutMs: *(\d+)/m.exec(match[1] ?? "");
177
+ return idle === null ? null : Number(idle[1]);
178
+ }
179
+ /**
180
+ * Build the pi-ai row config with one provider's idle timeout set or removed.
181
+ *
182
+ * Pure: the caller decides whether to hand the result to the loader, and a shape
183
+ * this function does not recognize returns `undefined` instead of a guess.
184
+ *
185
+ * @param config - the row's current config object.
186
+ * @param provider - the pi-ai provider id inside `providers`.
187
+ * @param timeoutMs - the value to set, or undefined to remove the key.
188
+ * @returns the next config, or undefined when the current one is not an object.
189
+ */
190
+ function planProviderConfig(config, provider, timeoutMs) {
191
+ if (config === null || typeof config !== "object" || Array.isArray(config)) return void 0;
192
+ const base = config;
193
+ const providers = base.providers === null || typeof base.providers !== "object" || Array.isArray(base.providers) ? {} : base.providers;
194
+ const nextProvider = { ...providers[provider] === null || typeof providers[provider] !== "object" || Array.isArray(providers[provider]) ? {} : providers[provider] };
195
+ if (timeoutMs === void 0) delete nextProvider.streamIdleTimeoutMs;
196
+ else nextProvider.streamIdleTimeoutMs = timeoutMs;
197
+ return {
198
+ ...base,
199
+ providers: {
200
+ ...providers,
201
+ [provider]: nextProvider
202
+ }
203
+ };
204
+ }
205
+ /**
206
+ * Find the loader row that owns the pi-ai provider profiles.
207
+ *
208
+ * @param loader - the Host loader service, when present.
209
+ * @returns the row entry, or undefined when the profile does not load it.
210
+ */
211
+ function findPiAiEntry(loader) {
212
+ if (loader === void 0 || typeof loader.entries !== "function") return void 0;
213
+ for (const entry of loader.entries()) if (entry.options?.name === PI_AI_PACKAGE || entry.id === "llm-pi-ai") return entry;
214
+ }
215
+ /**
216
+ * Reload the pi-ai row so a changed timeout applies without a Host restart.
217
+ *
218
+ * The document write already happened; this is the runtime half. One reload
219
+ * carries every provider that changed. A reload aborts the provider's in-flight
220
+ * calls, which is why it only runs on an actual value change.
221
+ *
222
+ * @param loader - the Host loader service.
223
+ * @param log - row logger for the one-line report.
224
+ * @param providers - providers whose `streamIdleTimeoutMs` the document write changed.
225
+ * @param timeoutMs - the value the document now carries, or undefined for a reset.
226
+ */
227
+ async function pushHotTimeout(loader, log, providers, timeoutMs) {
228
+ const entry = findPiAiEntry(loader);
229
+ if (entry === void 0) {
230
+ reviewTimeoutStatus.hot = "restart-required";
231
+ reviewTimeoutStatus.hotReason = "the pi-ai row is not loaded";
232
+ return;
233
+ }
234
+ let config = entry.options?.config;
235
+ for (const provider of providers) {
236
+ const next = planProviderConfig(config, provider, timeoutMs);
237
+ if (next === void 0) {
238
+ reviewTimeoutStatus.hot = "restart-required";
239
+ reviewTimeoutStatus.hotReason = "the pi-ai row config is not an object";
240
+ return;
241
+ }
242
+ config = next;
243
+ }
244
+ const result = await applyFiberConfig(entry, config);
245
+ const label = timeoutMs === void 0 ? "reset (provider defaults restored)" : `${timeoutMs}ms`;
246
+ if (result.outcome === "updated") {
247
+ reviewTimeoutStatus.hot = "applied";
248
+ reviewTimeoutStatus.hotReason = void 0;
249
+ for (const provider of providers) if (!reviewTimeoutStatus.hotApplied.includes(provider)) reviewTimeoutStatus.hotApplied.push(provider);
250
+ log.info(`model-switch: reloaded ${PI_AI_ROW} so the review timeout (${label}) applies now to [${providers.join(", ")}]; its in-flight calls were dropped`);
251
+ return;
252
+ }
253
+ reviewTimeoutStatus.hot = "restart-required";
254
+ 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";
255
+ 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`);
256
+ }
257
+ /**
258
+ * Row entry point: apply the configured timeout to the reviewer providers'
259
+ * pi-ai profiles in the profile document.
260
+ *
261
+ * Every failure is contained and logged; a broken document must never take the
262
+ * Host down. The write is idempotent: replays find the value already in place
263
+ * and do nothing.
264
+ *
265
+ * @param ctx - this row's context.
266
+ */
267
+ function apply(outer) {
268
+ outer.inject(["modelSwitch"], (ctx) => {
269
+ const runtime = ctx.modelSwitch;
270
+ const log = ctx.logger;
271
+ const execute = async () => {
272
+ reviewTimeoutStatus.configuredMs = void 0;
273
+ reviewTimeoutStatus.applied = [];
274
+ reviewTimeoutStatus.skipped = [];
275
+ reviewTimeoutStatus.hotApplied = [];
276
+ reviewTimeoutStatus.hot = void 0;
277
+ reviewTimeoutStatus.hotReason = void 0;
278
+ const settings = runtime.currentSettings();
279
+ const plan = planReviewTimeout(settings);
280
+ reviewTimeoutStatus.configuredMs = settings.autoReviewTimeoutMs;
281
+ if (plan.providers.length === 0) return;
282
+ const forms = ctx.get("settings", true);
283
+ const documentPath = forms?.documentPath;
284
+ if (forms === void 0 || typeof documentPath !== "string" || documentPath === "") {
285
+ reviewTimeoutStatus.skipped.push(...plan.providers);
286
+ log.warn("model-switch: no profile document is reachable; the review timeout write is skipped");
287
+ return;
288
+ }
289
+ try {
290
+ const { readFile, writeFile } = await import("node:fs/promises");
291
+ let text = await readFile(documentPath, "utf8");
292
+ let changed = false;
293
+ const changedProviders = [];
294
+ for (const provider of plan.providers) {
295
+ const patched = patchProviderIdleTimeout(text, provider, plan.timeoutMs);
296
+ if (patched.outcome === "written") {
297
+ text = patched.text;
298
+ changed = true;
299
+ changedProviders.push(provider);
300
+ }
301
+ if (patched.outcome === "written" || patched.outcome === "unchanged") reviewTimeoutStatus.applied.push(provider);
302
+ else reviewTimeoutStatus.skipped.push(provider);
303
+ }
304
+ if (changed) await writeFile(documentPath, text, "utf8");
305
+ 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(", ")}]`);
306
+ if (changedProviders.length > 0) pushHotTimeout(ctx.get("loader", false), log, changedProviders, plan.timeoutMs);
307
+ } catch (cause) {
308
+ log.warn(`model-switch: the review timeout write failed (${String(cause)})`);
309
+ }
310
+ };
311
+ let pending;
312
+ const run = () => {
313
+ if (pending !== void 0) return pending;
314
+ const next = execute().finally(() => {
315
+ if (pending === next) pending = void 0;
316
+ });
317
+ pending = next;
318
+ return next;
319
+ };
320
+ run();
321
+ const lateSweep = setTimeout(() => {
322
+ run();
323
+ }, 1500);
324
+ const offService = ctx.on("internal/service", (name) => {
325
+ if (name === "settings") run();
326
+ });
327
+ ctx.effect(function* () {
328
+ yield () => {
329
+ offService();
330
+ clearTimeout(lateSweep);
331
+ };
332
+ yield ctx.on("model-switch/settings-update", () => {
333
+ run();
334
+ });
335
+ }, "model-switch: keep the review timeout write aligned with the settings");
336
+ });
337
+ }
338
+ //#endregion
339
+ 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,2 +1,2 @@
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-FB32BcnO.js";
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-CAlD65wl.js";
2
2
  export { PI_AI_ROW, apply, findPiAiEntry, inject, name, patchProviderIdleTimeout, planProviderConfig, planReviewTimeout, readProviderIdleTimeout, reviewTimeoutStatus };