dsh-model-switch 0.4.68 → 0.4.70
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 +30 -0
- package/IMPLEMENTATION_PLAN.md +12 -1
- package/PRODUCT.md +3 -3
- package/README.en.md +16 -3
- package/README.md +16 -3
- package/cordis.patch.yml +9 -0
- package/lib/auto-review-CYvvootQ.js +1079 -0
- package/lib/auto-review.js +1 -1
- package/lib/automode-compat.js +1 -1
- package/lib/client.js +503 -47
- package/lib/compaction.js +1 -1
- package/lib/index.js +26 -7
- package/lib/prime-memory-compat.js +573 -1
- package/lib/prime-memory-route-DGUVfogE.js +117 -0
- package/lib/review-timeout-FB32BcnO.js +339 -0
- package/lib/review-timeout.js +1 -1
- package/lib/session-route-CRfpxarI.js +357 -0
- package/lib/session-title.js +17 -3
- package/lib/subagent-runtime-eNKrdb2H.js +424 -0
- package/lib/subagent-runtime.js +1 -1
- package/lib/tool-allowlist-cN9Z1XKn.js +489 -0
- package/lib/types/capabilities-rpc.d.ts +7 -0
- package/lib/types/client/ModelSwitchSettings.d.ts +6 -3
- package/lib/types/client/locales.d.ts +18 -2
- package/lib/types/client-contract.d.ts +33 -1
- package/lib/types/host-settings.d.ts +11 -0
- package/lib/types/prime-memory-compat.d.ts +14 -6
- package/lib/types/prime-memory-route.d.ts +22 -0
- package/lib/types/provider-group.d.ts +31 -3
- package/lib/types/session-route.d.ts +24 -3
- package/lib/types/session-title.d.ts +12 -0
- package/lib/types/tool-allowlist.d.ts +13 -0
- package/lib/types/vision-router-compat.d.ts +62 -0
- package/lib/types/vision-router-route.d.ts +94 -0
- package/lib/vision-router-compat-B9bkgJmh.js +312 -0
- package/lib/vision-router-compat-DP81VMLW.js +312 -0
- package/lib/vision-router-compat.js +2 -0
- package/package.json +6 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { c as canonicalGroupProvider } from "./session-route-CRfpxarI.js";
|
|
2
|
+
//#region lib/types/prime-memory-route.js
|
|
3
|
+
/**
|
|
4
|
+
* Model Switch's adapter to `dsh-prime-memory`'s distillation route.
|
|
5
|
+
*
|
|
6
|
+
* prime-memory owns its distillation route: a `distillChain` in the volatile
|
|
7
|
+
* `live` settings section (`distillProvider`/`distillModel` before 0.x chains
|
|
8
|
+
* existed), read through its own settings handle and committed with
|
|
9
|
+
* `ctx.settings.update('dsh-memory', { live })` — a volatile-only commit that
|
|
10
|
+
* does not remount the plugin. This module only builds the write Model Switch
|
|
11
|
+
* offers; it never runs a distillation call, never rewrites the plugin, and
|
|
12
|
+
* never changes a route the user did not ask to change.
|
|
13
|
+
*
|
|
14
|
+
* All functions here are pure.
|
|
15
|
+
*/
|
|
16
|
+
/** The loader row id prime-memory is composed under (fixed by its bundle patch). */
|
|
17
|
+
const PRIME_MEMORY_ENTRY_ID = "dsh-memory";
|
|
18
|
+
/** The package name that identifies the row; the authoritative identity. */
|
|
19
|
+
const PRIME_MEMORY_PACKAGE = "dsh-prime-memory";
|
|
20
|
+
/** A non-blank string; blank values behave exactly like an absent field. */
|
|
21
|
+
function present(value) {
|
|
22
|
+
return typeof value === "string" && value.trim() !== "";
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Whether one loader entry is prime-memory.
|
|
26
|
+
*
|
|
27
|
+
* The package name wins over the row id: a profile layer may rename the row,
|
|
28
|
+
* while an unrelated row could recycle the id.
|
|
29
|
+
* @param entry - the loader entry to test.
|
|
30
|
+
* @returns True for prime-memory's row.
|
|
31
|
+
*/
|
|
32
|
+
function isPrimeMemoryRow(entry) {
|
|
33
|
+
const name = entry?.options?.name;
|
|
34
|
+
if (present(name)) return name === PRIME_MEMORY_PACKAGE;
|
|
35
|
+
return entry?.options?.id === PRIME_MEMORY_ENTRY_ID;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The chain prime-memory should use, given the route Model Switch wants.
|
|
39
|
+
*
|
|
40
|
+
* The chosen route goes first; the entries prime-memory already had follow in
|
|
41
|
+
* their own order, minus any route that duplicates the chosen one (a duplicate
|
|
42
|
+
* is a guaranteed second failure, not a fallback). An empty chosen route leaves
|
|
43
|
+
* the existing chain untouched.
|
|
44
|
+
* @param primary - the route Model Switch wants first, if any.
|
|
45
|
+
* @param existing - prime-memory's current chain, as read from its settings.
|
|
46
|
+
* @returns The chain to write; empty when neither side has a complete route.
|
|
47
|
+
*/
|
|
48
|
+
function planDistillChain(primary, existing) {
|
|
49
|
+
const chain = [];
|
|
50
|
+
const seen = /* @__PURE__ */ new Set();
|
|
51
|
+
const push = (entry) => {
|
|
52
|
+
const key = `${entry.provider}\u0000${entry.model}`;
|
|
53
|
+
if (seen.has(key)) return;
|
|
54
|
+
seen.add(key);
|
|
55
|
+
chain.push(entry);
|
|
56
|
+
};
|
|
57
|
+
if (primary !== void 0 && present(primary.provider) && present(primary.model)) {
|
|
58
|
+
const effort = primary.reasoningEffort;
|
|
59
|
+
push(present(effort) ? {
|
|
60
|
+
provider: primary.provider,
|
|
61
|
+
model: primary.model,
|
|
62
|
+
reasoningEffort: effort
|
|
63
|
+
} : {
|
|
64
|
+
provider: primary.provider,
|
|
65
|
+
model: primary.model
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
for (const entry of existing ?? []) {
|
|
69
|
+
if (!present(entry.provider) || !present(entry.model)) continue;
|
|
70
|
+
push(present(entry.reasoningEffort) ? {
|
|
71
|
+
provider: entry.provider,
|
|
72
|
+
model: entry.model,
|
|
73
|
+
reasoningEffort: entry.reasoningEffort
|
|
74
|
+
} : {
|
|
75
|
+
provider: entry.provider,
|
|
76
|
+
model: entry.model
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return chain;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The settings patch that writes one distillation chain.
|
|
83
|
+
*
|
|
84
|
+
* Only the `distillChain` key is produced: prime-memory's `live` section carries
|
|
85
|
+
* unrelated switches (capture, trace, embedding, memory mutation), and a patch
|
|
86
|
+
* naming them would rewrite the user's choices.
|
|
87
|
+
* @param chain - the chain to write.
|
|
88
|
+
* @returns The `live` patch to pass to `ctx.settings.update`.
|
|
89
|
+
*/
|
|
90
|
+
function distillChainPatch(chain) {
|
|
91
|
+
return { live: { distillChain: chain } };
|
|
92
|
+
}
|
|
93
|
+
/** A non-blank string. */
|
|
94
|
+
function nonBlank(value) {
|
|
95
|
+
return typeof value === "string" && value.trim() !== "";
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The deployment default provider, canonicalized for group keying.
|
|
99
|
+
*
|
|
100
|
+
* The `agent-default-model` row names the provider new sessions start on; a
|
|
101
|
+
* deployment whose default is a dsh-vision-router twin (`${provider}-vision`)
|
|
102
|
+
* keys its deployment-wide groups under the base provider, so the twin suffix
|
|
103
|
+
* is stripped here.
|
|
104
|
+
* @param loader - the loader service, when present.
|
|
105
|
+
* @returns The base provider id, or undefined when the row or its provider is absent.
|
|
106
|
+
*/
|
|
107
|
+
function deploymentDefaultProviderOf(loader) {
|
|
108
|
+
if (typeof loader?.entries !== "function") return void 0;
|
|
109
|
+
for (const entry of loader.entries()) {
|
|
110
|
+
if (entry?.options?.id !== "agent-default-model") continue;
|
|
111
|
+
const config = entry.options.config;
|
|
112
|
+
const provider = config !== null && typeof config === "object" && !Array.isArray(config) ? config.provider : void 0;
|
|
113
|
+
if (nonBlank(provider)) return canonicalGroupProvider(provider);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
export { planDistillChain as i, distillChainPatch as n, isPrimeMemoryRow as r, deploymentDefaultProviderOf as t };
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import "./tool-allowlist-cN9Z1XKn.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 };
|
package/lib/review-timeout.js
CHANGED
|
@@ -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-
|
|
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";
|
|
2
2
|
export { PI_AI_ROW, apply, findPiAiEntry, inject, name, patchProviderIdleTimeout, planProviderConfig, planReviewTimeout, readProviderIdleTimeout, reviewTimeoutStatus };
|