dsh-model-think-level 2.3.0 → 2.3.1
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/README.md +11 -1
- package/lib/client/ConfigPane.d.ts +16 -7
- package/lib/client/KeyManager.d.ts +3 -0
- package/lib/client/auto-continue-pref.d.ts +33 -0
- package/lib/client/auto-continue-rules.d.ts +96 -0
- package/lib/client/image-config-client.d.ts +10 -1
- package/lib/client/index.d.ts +1 -0
- package/lib/client/injection/auto-continue-run.d.ts +53 -0
- package/lib/client/injection/config-button-seat.d.ts +2 -2
- package/lib/client/injection/session-directory.d.ts +44 -0
- package/lib/client/locales.d.ts +17 -0
- package/lib/client/styles.d.ts +1 -1
- package/lib/client.js +150 -8
- package/lib/client.js.map +4 -4
- package/lib/image/config.d.ts +6 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +105 -27
- package/lib/index.js.map +2 -2
- package/package.json +5 -3
package/lib/image/config.d.ts
CHANGED
|
@@ -70,6 +70,12 @@ export interface ImageDefaults {
|
|
|
70
70
|
/** The whole config document, exactly as it sits on disk. */
|
|
71
71
|
export interface ImageConfig {
|
|
72
72
|
readonly version: 2;
|
|
73
|
+
/**
|
|
74
|
+
* Whether the image-generation service is on. Off means the native tool is
|
|
75
|
+
* not registered and every generation entry refuses; the models and image
|
|
76
|
+
* params stay in the file untouched, so switching back on costs one click.
|
|
77
|
+
*/
|
|
78
|
+
readonly enabled: boolean;
|
|
73
79
|
/** When `models[]` was last re-derived from the settings document. */
|
|
74
80
|
readonly syncedAt: string;
|
|
75
81
|
/** `"<route>/<modelId>"` of the default model, when the user picked one. */
|
package/lib/index.d.ts
CHANGED
|
@@ -44,6 +44,12 @@ export interface Config {
|
|
|
44
44
|
* "try exactly once" (default [1000, 2000, 4000, 8000, 16000, 30000]).
|
|
45
45
|
*/
|
|
46
46
|
bootRetryDelaysMs?: number[];
|
|
47
|
+
/**
|
|
48
|
+
* How long a key-index route must stay absent from the settings document
|
|
49
|
+
* before the vanish sweep deletes its residue, in milliseconds (default
|
|
50
|
+
* 30000). `0` sweeps on the first absent-reading pass.
|
|
51
|
+
*/
|
|
52
|
+
routeSweepGraceMs?: number;
|
|
47
53
|
/**
|
|
48
54
|
* Rewrite effort-less calls to forced-thinking ladders into the ladder's
|
|
49
55
|
* vendor default (default true). Only the request class that today becomes
|
package/lib/index.js
CHANGED
|
@@ -3984,6 +3984,7 @@ function imageConfigFilePath(home = harnessHome()) {
|
|
|
3984
3984
|
function emptyImageConfig(now = () => /* @__PURE__ */ new Date()) {
|
|
3985
3985
|
return {
|
|
3986
3986
|
version: 2,
|
|
3987
|
+
enabled: true,
|
|
3987
3988
|
syncedAt: now().toISOString(),
|
|
3988
3989
|
defaultModel: null,
|
|
3989
3990
|
defaults: { size: "1024x1024", quality: "high", n: 1, timeoutMs: 3e5 },
|
|
@@ -4039,6 +4040,9 @@ function parseImageConfig(raw, now = () => /* @__PURE__ */ new Date()) {
|
|
|
4039
4040
|
}
|
|
4040
4041
|
return {
|
|
4041
4042
|
version: 2,
|
|
4043
|
+
// A config written before the switch existed has no opinion on it: the
|
|
4044
|
+
// shipped behaviour was "on", so only an explicit false turns it off.
|
|
4045
|
+
enabled: raw["enabled"] !== false,
|
|
4042
4046
|
syncedAt: typeof raw["syncedAt"] === "string" ? raw["syncedAt"] : base.syncedAt,
|
|
4043
4047
|
defaultModel: typeof raw["defaultModel"] === "string" && raw["defaultModel"].length > 0 ? raw["defaultModel"] : null,
|
|
4044
4048
|
defaults,
|
|
@@ -4512,6 +4516,7 @@ async function generateImage(deps, request, sharedDeadline) {
|
|
|
4512
4516
|
}
|
|
4513
4517
|
}
|
|
4514
4518
|
async function generateWithinDeadline(deps, request, config, deadline) {
|
|
4519
|
+
if (!config.enabled) throw new GenerateError("config", "\u751F\u56FE\u670D\u52A1\u5DF2\u5173\u95ED\u2014\u2014\u53EF\u5728\u300C\u9AD8\u7EA7\u8BBE\u7F6E \u2192 \u751F\u56FE\u300D\u91CC\u91CD\u65B0\u5F00\u542F");
|
|
4515
4520
|
const prompt = request.prompt.trim();
|
|
4516
4521
|
if (prompt.length === 0) throw new GenerateError("param", "\u63D0\u793A\u8BCD\u4E3A\u7A7A");
|
|
4517
4522
|
const model = resolveImageModel(config, request.model);
|
|
@@ -4940,6 +4945,7 @@ function registerGenerateImageTool(ctx, deps) {
|
|
|
4940
4945
|
const parsed = parseArgs(rawArgs);
|
|
4941
4946
|
if (typeof parsed === "string") throw new Error(parsed);
|
|
4942
4947
|
const config = deps.generateDeps.config?.() ?? deps.readConfig();
|
|
4948
|
+
if (!config.enabled) throw new Error("\u751F\u56FE\u670D\u52A1\u5DF2\u5173\u95ED\u2014\u2014\u53EF\u5728\u300C\u9AD8\u7EA7\u8BBE\u7F6E \u2192 \u751F\u56FE\u300D\u91CC\u91CD\u65B0\u5F00\u542F");
|
|
4943
4949
|
const deadline = createGenerateDeadline(deps.generateDeps.timeoutMs ?? config.defaults.timeoutMs, exec.signal);
|
|
4944
4950
|
try {
|
|
4945
4951
|
deadline.check();
|
|
@@ -5029,6 +5035,7 @@ function registerGenerateImageTool(ctx, deps) {
|
|
|
5029
5035
|
};
|
|
5030
5036
|
}
|
|
5031
5037
|
function imageToolHint(config) {
|
|
5038
|
+
if (!config.enabled) return "";
|
|
5032
5039
|
if (config.models.length === 0) return "";
|
|
5033
5040
|
const defaults = `size ${config.defaults.size}\uFF0Cquality ${config.defaults.quality}\uFF0Cn ${config.defaults.n}`;
|
|
5034
5041
|
const resolved = resolveImageModel(config);
|
|
@@ -6112,6 +6119,7 @@ var name = PLUGIN_ID;
|
|
|
6112
6119
|
var inject = ["settings", "llm"];
|
|
6113
6120
|
var PI_NS = PI_AI_NS;
|
|
6114
6121
|
var BOOT_RETRY_DELAYS_MS = [1e3, 2e3, 4e3, 8e3, 16e3, 3e4];
|
|
6122
|
+
var ROUTE_SWEEP_GRACE_MS = 3e4;
|
|
6115
6123
|
var PROBE_TIMEOUT_MS = 15e3;
|
|
6116
6124
|
var BALANCE_TIMEOUT_MS = 8e3;
|
|
6117
6125
|
var CREDENTIAL_IPC_BUDGET_MS = 1e4;
|
|
@@ -6161,6 +6169,7 @@ var Config = Schema.object({
|
|
|
6161
6169
|
modalityAutofill: Schema.boolean().default(true),
|
|
6162
6170
|
probeTimeoutMs: Schema.natural().min(1).default(PROBE_TIMEOUT_MS),
|
|
6163
6171
|
bootRetryDelaysMs: Schema.array(Schema.natural().min(1)).default([...BOOT_RETRY_DELAYS_MS]),
|
|
6172
|
+
routeSweepGraceMs: Schema.natural().default(ROUTE_SWEEP_GRACE_MS),
|
|
6164
6173
|
defaultGuard: Schema.boolean().default(true),
|
|
6165
6174
|
uaOverride: Schema.boolean().default(true)
|
|
6166
6175
|
});
|
|
@@ -6534,6 +6543,7 @@ function apply(ctx, config = {}) {
|
|
|
6534
6543
|
modalityAutofill: config.modalityAutofill !== false,
|
|
6535
6544
|
probeTimeoutMs: config.probeTimeoutMs ?? PROBE_TIMEOUT_MS,
|
|
6536
6545
|
bootRetryDelaysMs: config.bootRetryDelaysMs ?? [...BOOT_RETRY_DELAYS_MS],
|
|
6546
|
+
routeSweepGraceMs: config.routeSweepGraceMs ?? ROUTE_SWEEP_GRACE_MS,
|
|
6537
6547
|
defaultGuard: config.defaultGuard !== false,
|
|
6538
6548
|
uaOverride: config.uaOverride !== false
|
|
6539
6549
|
};
|
|
@@ -6716,9 +6726,33 @@ function apply(ctx, config = {}) {
|
|
|
6716
6726
|
if (key.startsWith(prefix)) listingCache.delete(key);
|
|
6717
6727
|
}
|
|
6718
6728
|
};
|
|
6729
|
+
const vanishedSince = /* @__PURE__ */ new Map();
|
|
6730
|
+
const sweepTimers = /* @__PURE__ */ new Set();
|
|
6731
|
+
ctx.effect(() => () => {
|
|
6732
|
+
for (const timer of sweepTimers) clearTimeout(timer);
|
|
6733
|
+
sweepTimers.clear();
|
|
6734
|
+
}, "dsh-model-think-level: route-sweep timers");
|
|
6735
|
+
let recheckTimer;
|
|
6736
|
+
let recheckAt = 0;
|
|
6737
|
+
const scheduleSweep = (at) => {
|
|
6738
|
+
if (recheckTimer !== void 0) {
|
|
6739
|
+
if (recheckAt <= at) return;
|
|
6740
|
+
clearTimeout(recheckTimer);
|
|
6741
|
+
sweepTimers.delete(recheckTimer);
|
|
6742
|
+
}
|
|
6743
|
+
recheckAt = at;
|
|
6744
|
+
const timer = setTimeout(() => {
|
|
6745
|
+
sweepTimers.delete(timer);
|
|
6746
|
+
if (recheckTimer === timer) recheckTimer = void 0;
|
|
6747
|
+
void Promise.resolve().then(() => sweepVanishedRoutes());
|
|
6748
|
+
}, Math.max(0, at - Date.now()));
|
|
6749
|
+
recheckTimer = timer;
|
|
6750
|
+
sweepTimers.add(timer);
|
|
6751
|
+
};
|
|
6719
6752
|
const sweepVanishedRoutes = () => {
|
|
6720
|
-
|
|
6721
|
-
|
|
6753
|
+
const section = piSection();
|
|
6754
|
+
if (!isRecord(section) || !isRecord(section["providers"])) return false;
|
|
6755
|
+
const live = section["providers"];
|
|
6722
6756
|
const indexFile = keyIndexFilePath();
|
|
6723
6757
|
let index;
|
|
6724
6758
|
try {
|
|
@@ -6726,14 +6760,35 @@ function apply(ctx, config = {}) {
|
|
|
6726
6760
|
} catch {
|
|
6727
6761
|
return true;
|
|
6728
6762
|
}
|
|
6763
|
+
for (const route of vanishedSince.keys()) if (route in live) vanishedSince.delete(route);
|
|
6729
6764
|
const stale = /* @__PURE__ */ new Set();
|
|
6730
6765
|
for (const route of Object.keys(index.providers)) if (!(route in live)) stale.add(route);
|
|
6731
6766
|
for (const route of Object.keys(index.endpoints ?? {})) if (!(route in live)) stale.add(route);
|
|
6732
6767
|
for (const route of Object.keys(index.balances ?? {})) if (!(route in live)) stale.add(route);
|
|
6733
6768
|
if (stale.size === 0) return true;
|
|
6769
|
+
const graceMs = resolved.routeSweepGraceMs;
|
|
6770
|
+
const now = Date.now();
|
|
6771
|
+
const due = /* @__PURE__ */ new Set();
|
|
6772
|
+
for (const route of stale) {
|
|
6773
|
+
const since = vanishedSince.get(route);
|
|
6774
|
+
if (since === void 0) {
|
|
6775
|
+
if (graceMs <= 0) due.add(route);
|
|
6776
|
+
else vanishedSince.set(route, now);
|
|
6777
|
+
} else if (now - since >= graceMs) {
|
|
6778
|
+
due.add(route);
|
|
6779
|
+
}
|
|
6780
|
+
}
|
|
6781
|
+
let earliest = Infinity;
|
|
6782
|
+
for (const route of stale) {
|
|
6783
|
+
if (due.has(route)) continue;
|
|
6784
|
+
const since = vanishedSince.get(route);
|
|
6785
|
+
if (since !== void 0) earliest = Math.min(earliest, since + graceMs);
|
|
6786
|
+
}
|
|
6787
|
+
if (earliest !== Infinity) scheduleSweep(earliest);
|
|
6788
|
+
if (due.size === 0) return true;
|
|
6734
6789
|
const survivors = /* @__PURE__ */ new Set();
|
|
6735
6790
|
for (const [route, entries] of Object.entries(index.providers)) {
|
|
6736
|
-
if (
|
|
6791
|
+
if (due.has(route)) continue;
|
|
6737
6792
|
for (const entry of entries) survivors.add(entry.ref);
|
|
6738
6793
|
}
|
|
6739
6794
|
for (const profile of Object.values(live)) {
|
|
@@ -6743,15 +6798,19 @@ function apply(ctx, config = {}) {
|
|
|
6743
6798
|
}
|
|
6744
6799
|
const credentials = ctx.get("credentials");
|
|
6745
6800
|
let swept = false;
|
|
6746
|
-
for (const route of
|
|
6801
|
+
for (const route of due) {
|
|
6747
6802
|
const refs = keyEntriesOf(index, route).map((entry) => entry.ref);
|
|
6803
|
+
const hadEndpoints = index.endpoints?.[route] !== void 0;
|
|
6804
|
+
const hadBalance = index.balances?.[route] !== void 0;
|
|
6748
6805
|
try {
|
|
6749
6806
|
updateKeyIndex((current) => withoutRoute(current, route), indexFile);
|
|
6750
6807
|
} catch (error) {
|
|
6751
6808
|
console.error(`[dsh-model-think-level] key route cleanup for "${route}" failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
6752
6809
|
continue;
|
|
6753
6810
|
}
|
|
6811
|
+
vanishedSince.delete(route);
|
|
6754
6812
|
swept = true;
|
|
6813
|
+
console.info(`[dsh-model-think-level] provider "${route}" left the settings document past its grace window; swept key-index metadata (${refs.length} key(s)${hadEndpoints ? ", extra endpoints" : ""}${hadBalance ? ", balance URL" : ""})`);
|
|
6755
6814
|
for (const ref of refs) {
|
|
6756
6815
|
forgetServes(route, ref);
|
|
6757
6816
|
const here = `${route}\0${ref}`;
|
|
@@ -6919,11 +6978,6 @@ function apply(ctx, config = {}) {
|
|
|
6919
6978
|
}
|
|
6920
6979
|
});
|
|
6921
6980
|
{
|
|
6922
|
-
const sweepTimers = /* @__PURE__ */ new Set();
|
|
6923
|
-
ctx.effect(() => () => {
|
|
6924
|
-
for (const timer of sweepTimers) clearTimeout(timer);
|
|
6925
|
-
sweepTimers.clear();
|
|
6926
|
-
}, "dsh-model-think-level: route-sweep boot retries");
|
|
6927
6981
|
const bootRouteSweep = (attempt) => {
|
|
6928
6982
|
void Promise.resolve().then(() => sweepVanishedRoutes()).then((ready) => {
|
|
6929
6983
|
if (ready || attempt >= resolved.bootRetryDelaysMs.length) return;
|
|
@@ -7112,28 +7166,46 @@ function apply(ctx, config = {}) {
|
|
|
7112
7166
|
}
|
|
7113
7167
|
);
|
|
7114
7168
|
const imageToolState = { name: void 0, error: void 0 };
|
|
7169
|
+
let reconcileImageTool;
|
|
7115
7170
|
ctx.inject(["tools", "attachments"], (toolCtx) => {
|
|
7171
|
+
let registered;
|
|
7172
|
+
const release = () => {
|
|
7173
|
+
const current = registered;
|
|
7174
|
+
registered = void 0;
|
|
7175
|
+
imageToolState.name = void 0;
|
|
7176
|
+
if (current === void 0) return;
|
|
7177
|
+
try {
|
|
7178
|
+
current.dispose();
|
|
7179
|
+
} catch {
|
|
7180
|
+
}
|
|
7181
|
+
};
|
|
7182
|
+
const acquire = () => {
|
|
7183
|
+
if (registered !== void 0) return;
|
|
7184
|
+
try {
|
|
7185
|
+
registered = registerGenerateImageTool(toolCtx, {
|
|
7186
|
+
generateDeps: imageGenerateDeps,
|
|
7187
|
+
attachments: toolCtx.attachments,
|
|
7188
|
+
readConfig: () => readImageConfig()
|
|
7189
|
+
});
|
|
7190
|
+
imageToolState.name = registered.name;
|
|
7191
|
+
imageToolState.error = void 0;
|
|
7192
|
+
} catch (error) {
|
|
7193
|
+
imageToolState.name = void 0;
|
|
7194
|
+
imageToolState.error = error instanceof Error ? error.message : String(error);
|
|
7195
|
+
console.warn(`[dsh-model-think-level] \u5185\u5EFA\u751F\u56FE\u5DE5\u5177\u6CE8\u518C\u5931\u8D25\uFF08\u8BCA\u65AD\u8DEF\u7531 ${IMAGE_CONFIG_PATH} \u7684 tool.error \u4F1A\u5E26\u56DE\u8FD9\u6761\u539F\u56E0\uFF09\uFF1A${imageToolState.error}`);
|
|
7196
|
+
}
|
|
7197
|
+
};
|
|
7198
|
+
const reconcile = () => {
|
|
7199
|
+
if (readImageConfig().enabled) acquire();
|
|
7200
|
+
else release();
|
|
7201
|
+
};
|
|
7202
|
+
reconcileImageTool = reconcile;
|
|
7116
7203
|
toolCtx.effect(
|
|
7117
7204
|
() => {
|
|
7118
|
-
|
|
7119
|
-
try {
|
|
7120
|
-
registered = registerGenerateImageTool(toolCtx, {
|
|
7121
|
-
generateDeps: imageGenerateDeps,
|
|
7122
|
-
attachments: toolCtx.attachments,
|
|
7123
|
-
readConfig: () => readImageConfig()
|
|
7124
|
-
});
|
|
7125
|
-
} catch (error) {
|
|
7126
|
-
imageToolState.name = void 0;
|
|
7127
|
-
imageToolState.error = error instanceof Error ? error.message : String(error);
|
|
7128
|
-
console.warn(`[dsh-model-think-level] \u5185\u5EFA\u751F\u56FE\u5DE5\u5177\u6CE8\u518C\u5931\u8D25\uFF08\u8BCA\u65AD\u8DEF\u7531 ${IMAGE_CONFIG_PATH} \u7684 tool.error \u4F1A\u5E26\u56DE\u8FD9\u6761\u539F\u56E0\uFF09\uFF1A${imageToolState.error}`);
|
|
7129
|
-
throw error;
|
|
7130
|
-
}
|
|
7131
|
-
const { name: name2, dispose } = registered;
|
|
7132
|
-
imageToolState.name = name2;
|
|
7133
|
-
imageToolState.error = void 0;
|
|
7205
|
+
reconcile();
|
|
7134
7206
|
return () => {
|
|
7135
|
-
|
|
7136
|
-
|
|
7207
|
+
reconcileImageTool = void 0;
|
|
7208
|
+
release();
|
|
7137
7209
|
};
|
|
7138
7210
|
},
|
|
7139
7211
|
"dsh-model-think-level: generate_image tool"
|
|
@@ -8284,6 +8356,7 @@ function apply(ctx, config = {}) {
|
|
|
8284
8356
|
const config2 = readImageConfig();
|
|
8285
8357
|
sendJson(res, 200, {
|
|
8286
8358
|
ok: true,
|
|
8359
|
+
enabled: config2.enabled,
|
|
8287
8360
|
models: config2.models,
|
|
8288
8361
|
defaultModel: config2.defaultModel,
|
|
8289
8362
|
defaults: config2.defaults,
|
|
@@ -8307,6 +8380,7 @@ function apply(ctx, config = {}) {
|
|
|
8307
8380
|
try {
|
|
8308
8381
|
updateImageConfig((document) => {
|
|
8309
8382
|
let next = document;
|
|
8383
|
+
if (typeof body["enabled"] === "boolean") next = { ...next, enabled: body["enabled"] };
|
|
8310
8384
|
if (typeof body["defaultModel"] === "string" && body["defaultModel"].length > 0) {
|
|
8311
8385
|
next = { ...next, defaultModel: body["defaultModel"] };
|
|
8312
8386
|
}
|
|
@@ -8329,6 +8403,10 @@ function apply(ctx, config = {}) {
|
|
|
8329
8403
|
return next;
|
|
8330
8404
|
});
|
|
8331
8405
|
syncImageConfigNow();
|
|
8406
|
+
try {
|
|
8407
|
+
reconcileImageTool?.();
|
|
8408
|
+
} catch {
|
|
8409
|
+
}
|
|
8332
8410
|
sendJson(res, 200, { ok: true });
|
|
8333
8411
|
} catch (error) {
|
|
8334
8412
|
sendJson(res, 500, { ok: false, error: error instanceof Error ? error.message : String(error) });
|