dsh-model-switch 0.4.52 → 0.4.54

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.
@@ -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(默认)";