dsh-model-switch 0.4.48 → 0.4.51
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 +38 -0
- package/cordis.patch.yml +7 -0
- package/lib/auto-review-uu9lvAIZ.js +1068 -0
- package/lib/auto-review.js +1 -1
- package/lib/client.js +289 -153
- package/lib/index.js +5 -1
- package/lib/prime-memory-compat.js +46 -8
- package/lib/review-timeout.js +238 -0
- package/lib/types/client/ModelSwitchSettings.d.ts +2 -0
- package/lib/types/client/locales.d.ts +10 -0
- package/lib/types/client-contract.d.ts +11 -0
- package/lib/types/host-settings.d.ts +15 -0
- package/lib/types/prime-memory-compat.d.ts +29 -0
- package/lib/types/review-timeout.d.ts +104 -0
- package/package.json +5 -1
|
@@ -0,0 +1,238 @@
|
|
|
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 };
|
|
@@ -32,6 +32,8 @@ export interface ModelSwitchSettingsFace {
|
|
|
32
32
|
enabled: boolean;
|
|
33
33
|
tools: readonly string[];
|
|
34
34
|
}) => Promise<void>;
|
|
35
|
+
/** Persist the reviewer stream idle timeout; undefined restores provider default. */
|
|
36
|
+
saveReviewTimeout: (value: number | undefined) => Promise<void>;
|
|
35
37
|
/** The Host's live tool catalog; absent on a Host without the `tools` RPC endpoint. */
|
|
36
38
|
scanTools?: () => Promise<{
|
|
37
39
|
rows: readonly ToolCatalogRow[];
|
|
@@ -75,6 +75,16 @@ export declare const zh: {
|
|
|
75
75
|
readonly reviewAllowlistAvailable: "本机存在但未放行的工具:";
|
|
76
76
|
readonly reviewAllowlistRepo: "仓库";
|
|
77
77
|
readonly reviewAllowlistSkipped: "本 Host 进程已为纯读调用跳过 {count} 次审查。";
|
|
78
|
+
readonly reviewTimeout: "审查超时";
|
|
79
|
+
readonly reviewTimeoutDefault: "跟随 Provider 默认(300 秒)";
|
|
80
|
+
readonly reviewTimeoutHelp: "设置自动审查请求的流式空闲超时。留空恢复 Provider 默认值;勾选「取消超时」写入上游上限(约 24.8 天),审查将不会因空闲而超时。该值写在 Provider 配置里,改完需重启一次 DSH 才生效。";
|
|
81
|
+
readonly reviewTimeoutScope: "注意:该值写入审查模型所在 Provider 的 streamIdleTimeoutMs,对该 Provider 的所有调用(含主对话)生效,不只影响审查请求。";
|
|
82
|
+
readonly reviewTimeoutSeconds: "超时秒数";
|
|
83
|
+
readonly reviewTimeoutPlaceholder: "300(默认)";
|
|
84
|
+
readonly reviewTimeoutCancelLabel: "取消超时";
|
|
85
|
+
readonly reviewTimeoutCancelHint: "审查调用不再因空闲超时(写入约 24.8 天上限)";
|
|
86
|
+
readonly reviewTimeoutSave: "保存超时设置";
|
|
87
|
+
readonly reviewTimeoutCancelled: "已取消超时";
|
|
78
88
|
readonly reviewAutomodeLinked: "Auto mode 已接入:审查路由 {route},直通 +{added} 个纯读工具({skipped} 条通配未同步)。";
|
|
79
89
|
readonly reviewAutomodeRouteOwn: "沿用其自身配置";
|
|
80
90
|
readonly reviewAutomodeRouteUnset: "未配置(沿用会话模型)";
|
|
@@ -16,6 +16,11 @@ export interface ModelSwitchSettingsView {
|
|
|
16
16
|
autoReviewSkipReadOnly?: boolean;
|
|
17
17
|
/** Exact tool names, or trailing-`*` patterns, that skip the reviewer when enabled. */
|
|
18
18
|
autoReviewAllowlist?: readonly string[];
|
|
19
|
+
/**
|
|
20
|
+
* Reviewer stream idle timeout in ms; `0` = cancelled (written as the upstream
|
|
21
|
+
* ceiling); absent = follow the provider default.
|
|
22
|
+
*/
|
|
23
|
+
autoReviewTimeoutMs?: number;
|
|
19
24
|
compactProvider?: string;
|
|
20
25
|
compactModel?: string;
|
|
21
26
|
titleProvider?: string;
|
|
@@ -62,6 +67,12 @@ export declare const AUTO_REVIEW_ALLOWLIST_FIELDS: Readonly<{
|
|
|
62
67
|
readonly enabled: "autoReviewSkipReadOnly";
|
|
63
68
|
readonly tools: "autoReviewAllowlist";
|
|
64
69
|
}>;
|
|
70
|
+
/** Auto-reviewer stream idle timeout: one stored value; absent keeps the provider default. */
|
|
71
|
+
export declare const AUTO_REVIEW_TIMEOUT_FIELD: "autoReviewTimeoutMs";
|
|
72
|
+
/** Upstream ceiling enforced by `@deepseek-ai/dsh-timeout` (MAX_TIMER_DELAY_MS). */
|
|
73
|
+
export declare const UPSTREAM_MAX_IDLE_TIMEOUT_MS = 2147483647;
|
|
74
|
+
/** Upstream default (300 s) when the provider profile leaves the field unset. */
|
|
75
|
+
export declare const UPSTREAM_DEFAULT_IDLE_TIMEOUT_MS = 300000;
|
|
65
76
|
/** One allowlist editor snapshot (switch + entries). */
|
|
66
77
|
export interface AutoReviewAllowlistView {
|
|
67
78
|
enabled: boolean;
|
|
@@ -29,6 +29,19 @@ export interface ModelSwitchSettings {
|
|
|
29
29
|
* name). A bare `*` is rejected by the settings editor and never matches.
|
|
30
30
|
*/
|
|
31
31
|
autoReviewAllowlist?: readonly string[];
|
|
32
|
+
/**
|
|
33
|
+
* Reviewer stream idle timeout, in milliseconds, written to the reviewer
|
|
34
|
+
* routes' pi-ai provider profiles (`streamIdleTimeoutMs`).
|
|
35
|
+
*
|
|
36
|
+
* - absent: follow the provider default (300 s) — the upstream behaviour.
|
|
37
|
+
* - `0`: "cancel the timeout" — written as the upstream hard maximum
|
|
38
|
+
* (2147483647 ms ≈ 24.86 days), the closest legal value to "no timeout".
|
|
39
|
+
* - otherwise: a positive finite integer, clamped to the upstream ceiling.
|
|
40
|
+
*
|
|
41
|
+
* The key lives on the provider profile, so it applies to every call through
|
|
42
|
+
* that provider (reviewer, main chat, …), not only the reviewer.
|
|
43
|
+
*/
|
|
44
|
+
autoReviewTimeoutMs?: number;
|
|
32
45
|
/** Summarization provider for `/compact` and automatic compaction; both fields unset = official default (the conversation target). */
|
|
33
46
|
compactProvider?: string;
|
|
34
47
|
/** Summarization model for `/compact` and automatic compaction; set together with `compactProvider`. */
|
|
@@ -60,6 +73,8 @@ export interface Config {
|
|
|
60
73
|
autoReviewSkipReadOnly: Volatile<boolean>;
|
|
61
74
|
/** Tool names (exact, or a trailing `*` pattern) that skip the Auto reviewer. */
|
|
62
75
|
autoReviewAllowlist: Volatile<readonly string[]>;
|
|
76
|
+
/** Reviewer stream idle timeout in ms; 0 = cancel (upstream ceiling); absent = provider default. */
|
|
77
|
+
autoReviewTimeoutMs: Volatile<number | undefined>;
|
|
63
78
|
compactProvider: Volatile<string | undefined>;
|
|
64
79
|
compactModel: Volatile<string | undefined>;
|
|
65
80
|
titleProvider: Volatile<string | undefined>;
|
|
@@ -79,6 +79,35 @@ export declare function planPrimeMemoryRoute(config: unknown, route: CapabilityR
|
|
|
79
79
|
interface Loader {
|
|
80
80
|
entries?(): Iterable<Entry>;
|
|
81
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Whether the memory row's live section already carries exactly our route.
|
|
84
|
+
*
|
|
85
|
+
* The RPC write path persists the live section to the profile document on every
|
|
86
|
+
* call, and a document change reloads the composition — so pushing an unchanged
|
|
87
|
+
* route re-triggers this adapter forever (a ~6 s recompose loop, observed with
|
|
88
|
+
* `dsh-prime-memory@0.26.10`). Comparing first is what makes the push idempotent
|
|
89
|
+
* across reloads.
|
|
90
|
+
*
|
|
91
|
+
* @param value - the memory row's live settings object, as the forms describe it.
|
|
92
|
+
* @param provider - route provider to compare against.
|
|
93
|
+
* @param model - route model to compare against.
|
|
94
|
+
* @returns true when a push would change nothing.
|
|
95
|
+
*/
|
|
96
|
+
export declare function memoryLiveMatchesRoute(value: unknown, provider: string, model: string): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Hand the route to the memory plugin through the RPC it registers for its own
|
|
99
|
+
* settings page.
|
|
100
|
+
*
|
|
101
|
+
* Writing the config document (what `settings.update` does) only changes what the
|
|
102
|
+
* next start reads; the plugin resolves its route from the runtime settings object
|
|
103
|
+
* it built at `apply`. This endpoint is the documented runtime write path — the
|
|
104
|
+
* same one its own "distillation parameters" panel posts to — so it takes effect
|
|
105
|
+
* without a restart, which is exactly what a provider switch needs.
|
|
106
|
+
*/
|
|
107
|
+
export declare function pushMemoryRoute(ctx: Context, route: {
|
|
108
|
+
provider: string;
|
|
109
|
+
model: string;
|
|
110
|
+
}): Promise<'pushed' | 'absent' | 'rejected'>;
|
|
82
111
|
/**
|
|
83
112
|
* Install the adapter for the whole profile.
|
|
84
113
|
*
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configurable Auto-reviewer stream idle timeout.
|
|
3
|
+
*
|
|
4
|
+
* The reviewer call is a normal llm stream, so its idle watchdog is the one
|
|
5
|
+
* `@deepseek-ai/dsh-llm-pi-ai` puts on the **provider profile**:
|
|
6
|
+
* `providers.<id>.streamIdleTimeoutMs` (default 300 000 ms). There is no
|
|
7
|
+
* per-request override — `GenerateOptions` carries no timeout fields and the
|
|
8
|
+
* adapter reads the profile per call — so the only way to change the reviewer's
|
|
9
|
+
* timeout is to write that provider-profile key.
|
|
10
|
+
*
|
|
11
|
+
* Consequences, all surfaced in the UI copy:
|
|
12
|
+
*
|
|
13
|
+
* - The key lives on the provider, so it applies to **every** call through that
|
|
14
|
+
* provider (reviewer, main chat, other routes), not only the reviewer.
|
|
15
|
+
* - "Cancel the timeout" is legal only as the upstream ceiling
|
|
16
|
+
* (`MAX_TIMER_DELAY_MS` = 2147483647 ms ≈ 24.86 days); upstream rejects 0,
|
|
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**.
|
|
20
|
+
*
|
|
21
|
+
* Restoring is symmetric: the value a provider carried before the first
|
|
22
|
+
* overwrite is recorded in this plugin's own settings
|
|
23
|
+
* (`autoReviewTimeoutPrevious`) and written back when the setting returns to
|
|
24
|
+
* "follow the provider default", so clearing the setting never leaves an
|
|
25
|
+
* adapter-written value behind.
|
|
26
|
+
*
|
|
27
|
+
* @module
|
|
28
|
+
*/
|
|
29
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
30
|
+
import type { ModelSwitchSettings } from './host-settings.js';
|
|
31
|
+
/** Cordis plugin identity; matches the `cordis.patch.yml` insert row id. */
|
|
32
|
+
export declare const name = "model-switch-review-timeout";
|
|
33
|
+
/** This row needs the Host's settings service (for `documentPath` and our ns). */
|
|
34
|
+
export declare const inject: string[];
|
|
35
|
+
/** The pi-ai row whose provider profiles carry `streamIdleTimeoutMs`. */
|
|
36
|
+
export declare const PI_AI_ROW = "llm-pi-ai";
|
|
37
|
+
/** Live state surfaced next to the reviewer card through the capabilities RPC. */
|
|
38
|
+
export declare const reviewTimeoutStatus: {
|
|
39
|
+
configuredMs: number | undefined;
|
|
40
|
+
applied: string[];
|
|
41
|
+
skipped: string[];
|
|
42
|
+
};
|
|
43
|
+
/** One resolved write decision. */
|
|
44
|
+
export interface ReviewTimeoutPlan {
|
|
45
|
+
/** Milliseconds to write per provider; undefined means "restore / follow default". */
|
|
46
|
+
readonly timeoutMs: number | undefined;
|
|
47
|
+
/** Reviewer provider ids collected from the global route and every group. */
|
|
48
|
+
readonly providers: readonly string[];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Resolve the stored setting into concrete write values.
|
|
52
|
+
*
|
|
53
|
+
* Stored values are user intent: absent = follow the provider default, `0` =
|
|
54
|
+
* cancelled (written as the upstream ceiling), anything else is clamped into
|
|
55
|
+
* the upstream-legal range so a hand-edited profile cannot produce a rejected
|
|
56
|
+
* value.
|
|
57
|
+
*
|
|
58
|
+
* @param settings - the plugin's current settings.
|
|
59
|
+
* @returns the write value and the reviewer providers to apply it to.
|
|
60
|
+
*/
|
|
61
|
+
export declare function planReviewTimeout(settings: ModelSwitchSettings): ReviewTimeoutPlan;
|
|
62
|
+
/** Why a provider was left untouched. */
|
|
63
|
+
export type ReviewTimeoutSkip = 'missing-row' | 'missing-provider' | 'unrecorded';
|
|
64
|
+
/** Result of one document patch attempt. */
|
|
65
|
+
export interface ReviewTimeoutPatch {
|
|
66
|
+
readonly text: string;
|
|
67
|
+
readonly outcome: 'written' | 'unchanged' | ReviewTimeoutSkip;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Set or remove one pi-ai provider's `streamIdleTimeoutMs` in the profile
|
|
71
|
+
* document, touching only that provider's block.
|
|
72
|
+
*
|
|
73
|
+
* The pi-ai row's layout is fixed by its schema: the provider sits at six
|
|
74
|
+
* spaces under `providers:`, its fields at eight. The patch inserts the key at
|
|
75
|
+
* the top of the provider block, replaces it in place, or removes it, and never
|
|
76
|
+
* touches another provider or row.
|
|
77
|
+
*
|
|
78
|
+
* @param text - the full profile document.
|
|
79
|
+
* @param provider - the pi-ai provider id.
|
|
80
|
+
* @param timeoutMs - the value to write, or undefined to remove the key.
|
|
81
|
+
* @returns the patched text and what happened.
|
|
82
|
+
*/
|
|
83
|
+
export declare function patchProviderIdleTimeout(text: string, provider: string, timeoutMs: number | undefined): ReviewTimeoutPatch;
|
|
84
|
+
/**
|
|
85
|
+
* Read a provider's current `streamIdleTimeoutMs` from the document.
|
|
86
|
+
*
|
|
87
|
+
* Used to record the pre-overwrite value so a later reset restores it.
|
|
88
|
+
*
|
|
89
|
+
* @param text - the full profile document.
|
|
90
|
+
* @param provider - the pi-ai provider id.
|
|
91
|
+
* @returns the value, or null when the key is absent.
|
|
92
|
+
*/
|
|
93
|
+
export declare function readProviderIdleTimeout(text: string, provider: string): number | null;
|
|
94
|
+
/**
|
|
95
|
+
* Row entry point: apply the configured timeout to the reviewer providers'
|
|
96
|
+
* pi-ai profiles in the profile document.
|
|
97
|
+
*
|
|
98
|
+
* Every failure is contained and logged; a broken document must never take the
|
|
99
|
+
* Host down. The write is idempotent: replays find the value already in place
|
|
100
|
+
* and do nothing.
|
|
101
|
+
*
|
|
102
|
+
* @param ctx - this row's context.
|
|
103
|
+
*/
|
|
104
|
+
export declare function apply(ctx: Context): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-model-switch",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.51",
|
|
4
4
|
"description": "Explicit model routing plus composer/Plan picker for DeepSeek Harness",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -66,6 +66,10 @@
|
|
|
66
66
|
"types": "./lib/types/prime-memory-compat.d.ts",
|
|
67
67
|
"default": "./lib/prime-memory-compat.js"
|
|
68
68
|
},
|
|
69
|
+
"./review-timeout": {
|
|
70
|
+
"types": "./lib/types/review-timeout.d.ts",
|
|
71
|
+
"default": "./lib/review-timeout.js"
|
|
72
|
+
},
|
|
69
73
|
"./package.json": "./package.json"
|
|
70
74
|
},
|
|
71
75
|
"files": [
|