dsh-thinking-levels 4.1.0 → 4.2.0-beta.29
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.ja.md +35 -0
- package/CHANGELOG.ko.md +35 -0
- package/CHANGELOG.md +56 -1
- package/dsh.plugin.json +16 -16
- package/lib/billing-projection.d.ts +578 -0
- package/lib/billing-projection.js +393 -0
- package/lib/client.js +1457 -359
- package/lib/client.js.map +1 -1
- package/lib/index.d.ts +62 -0
- package/lib/index.js +178 -38
- package/lib/settings-read.d.ts +53 -0
- package/lib/settings-read.js +36 -0
- package/lib/takeover-sync.d.ts +37 -11
- package/lib/takeover-sync.js +41 -11
- package/package.json +134 -132
package/lib/index.d.ts
CHANGED
|
@@ -67,6 +67,13 @@ export interface ThinkingLevelsConfig {
|
|
|
67
67
|
allowDowngrade: boolean | Volatile<boolean>;
|
|
68
68
|
/** Scheduler preference: allow lifting above the `high` hub to `max`. */
|
|
69
69
|
allowUpgrade: boolean | Volatile<boolean>;
|
|
70
|
+
/**
|
|
71
|
+
* Master takeover switch: mirrored into the openai-completions transport's
|
|
72
|
+
* own section (`llm-openai-completions.enabled`) when it flips. The
|
|
73
|
+
* transport's dispatch judgment stays single-source in ITS section; this
|
|
74
|
+
* flag is the control-layer UI for it.
|
|
75
|
+
*/
|
|
76
|
+
takeover: boolean | Volatile<boolean>;
|
|
70
77
|
/** Configurer-confirmed capability overrides, keyed `provider/model`. */
|
|
71
78
|
models: Record<string, ModelCapabilityOverride>;
|
|
72
79
|
}
|
|
@@ -82,6 +89,7 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
|
82
89
|
level: z<"off" | "on" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "auto", "off" | "on" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "auto", "volatile-defined">;
|
|
83
90
|
allowDowngrade: z<boolean, boolean, "volatile-defined">;
|
|
84
91
|
allowUpgrade: z<boolean, boolean, "volatile-defined">;
|
|
92
|
+
takeover: z<boolean, boolean, "volatile-defined">;
|
|
85
93
|
models: z<import("@deepseek-ai/cosmokit").Dict<{
|
|
86
94
|
vision?: boolean | null | undefined;
|
|
87
95
|
thinking?: boolean | null | undefined;
|
|
@@ -98,6 +106,49 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
|
98
106
|
level: z<"off" | "on" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "auto", "off" | "on" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "auto", "volatile-defined">;
|
|
99
107
|
allowDowngrade: z<boolean, boolean, "volatile-defined">;
|
|
100
108
|
allowUpgrade: z<boolean, boolean, "volatile-defined">;
|
|
109
|
+
takeover: z<boolean, boolean, "volatile-defined">;
|
|
110
|
+
models: z<import("@deepseek-ai/cosmokit").Dict<{
|
|
111
|
+
vision?: boolean | null | undefined;
|
|
112
|
+
thinking?: boolean | null | undefined;
|
|
113
|
+
efforts?: false | ("off" | "on" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max")[] | null | undefined;
|
|
114
|
+
contextWindow?: number | null | undefined;
|
|
115
|
+
} & import("@deepseek-ai/cosmokit").Dict, string>, import("@deepseek-ai/cosmokit").Dict<Schemastery.ObjectT<NoInfer<{
|
|
116
|
+
vision: z<boolean, boolean, "plain">;
|
|
117
|
+
thinking: z<boolean, boolean, "plain">;
|
|
118
|
+
efforts: z<false | ("off" | "on" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max")[], false | ("off" | "on" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max")[], "plain">;
|
|
119
|
+
contextWindow: z<number, number, "plain">;
|
|
120
|
+
}>>, string>, "defined">;
|
|
121
|
+
}>>, "plain">;
|
|
122
|
+
/**
|
|
123
|
+
* Legacy (≤0.1.6) settings schema: the same fields WITHOUT the `.volatile()`
|
|
124
|
+
* ref wrappers. The imperative `settings.register` resolver reads schemas
|
|
125
|
+
* literally and rejects the 0.1.7 ref descriptors ("$.enabled expected
|
|
126
|
+
* boolean but got [object Object]", live on cell 0.1.5) — the 3.x compat
|
|
127
|
+
* branches shipped exactly this plain shape.
|
|
128
|
+
*/
|
|
129
|
+
export declare const LegacyConfig: z<Schemastery.ObjectS<NoInfer<{
|
|
130
|
+
enabled: z<boolean, boolean, "defined">;
|
|
131
|
+
level: z<"off" | "on" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "auto", "off" | "on" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "auto", "defined">;
|
|
132
|
+
allowDowngrade: z<boolean, boolean, "defined">;
|
|
133
|
+
allowUpgrade: z<boolean, boolean, "defined">;
|
|
134
|
+
takeover: z<boolean, boolean, "defined">;
|
|
135
|
+
models: z<import("@deepseek-ai/cosmokit").Dict<{
|
|
136
|
+
vision?: boolean | null | undefined;
|
|
137
|
+
thinking?: boolean | null | undefined;
|
|
138
|
+
efforts?: false | ("off" | "on" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max")[] | null | undefined;
|
|
139
|
+
contextWindow?: number | null | undefined;
|
|
140
|
+
} & import("@deepseek-ai/cosmokit").Dict, string>, import("@deepseek-ai/cosmokit").Dict<Schemastery.ObjectT<NoInfer<{
|
|
141
|
+
vision: z<boolean, boolean, "plain">;
|
|
142
|
+
thinking: z<boolean, boolean, "plain">;
|
|
143
|
+
efforts: z<false | ("off" | "on" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max")[], false | ("off" | "on" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max")[], "plain">;
|
|
144
|
+
contextWindow: z<number, number, "plain">;
|
|
145
|
+
}>>, string>, "defined">;
|
|
146
|
+
}>>, Schemastery.ObjectT<NoInfer<{
|
|
147
|
+
enabled: z<boolean, boolean, "defined">;
|
|
148
|
+
level: z<"off" | "on" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "auto", "off" | "on" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "auto", "defined">;
|
|
149
|
+
allowDowngrade: z<boolean, boolean, "defined">;
|
|
150
|
+
allowUpgrade: z<boolean, boolean, "defined">;
|
|
151
|
+
takeover: z<boolean, boolean, "defined">;
|
|
101
152
|
models: z<import("@deepseek-ai/cosmokit").Dict<{
|
|
102
153
|
vision?: boolean | null | undefined;
|
|
103
154
|
thinking?: boolean | null | undefined;
|
|
@@ -129,6 +180,17 @@ declare module '@deepseek-ai/cordis' {
|
|
|
129
180
|
* the schema default is the fallback.
|
|
130
181
|
*/
|
|
131
182
|
export declare function readVolatile<T>(value: T | Volatile<T> | undefined, fallback: T): T;
|
|
183
|
+
/**
|
|
184
|
+
* Legacy (≤0.1.6) settings registration: on hosts whose settings service
|
|
185
|
+
* carries the imperative face (`register` present, `describe` absent), install
|
|
186
|
+
* this plugin's section so its config is runtime-editable and the live values
|
|
187
|
+
* feed `current()`. On 0.1.7+ the composition entry IS the section (the
|
|
188
|
+
* `.volatile()` fields arrive as live refs) and `register` no longer exists —
|
|
189
|
+
* the install is a no-op there. Shape-detected, never version-guessed.
|
|
190
|
+
*/
|
|
191
|
+
export declare function installLegacySection(ctx: Context, config: ThinkingLevelsConfig, hooks: {
|
|
192
|
+
setSource: (source: () => ThinkingLevelsConfig) => void;
|
|
193
|
+
}): void;
|
|
132
194
|
/**
|
|
133
195
|
* Plugin body.
|
|
134
196
|
* @param ctx - host context carrying the agent-event dispatch.
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import z from '@deepseek-ai/schemastery';
|
|
2
2
|
import { assertEffortId, reasoningEffortSupported, resolveEffortInjection } from "./thinking-level.js";
|
|
3
|
+
import { buildBillingDefinition } from "./billing-projection.js";
|
|
3
4
|
import { recentToolCalls } from "./session-events.js";
|
|
4
5
|
import { CONTEXT_WINDOW_MAX, CONTEXT_WINDOW_MIN } from "./context-window.js";
|
|
5
|
-
import { PI_AI_NAMESPACE,
|
|
6
|
+
import { PI_AI_NAMESPACE, TAKEOVER_NAMESPACE_CANDIDATES, takeoverPatch, takeoverRoutesOf, withOfficialCompatFixes, } from "./takeover-sync.js";
|
|
7
|
+
import { describeSettings, readSection, readSectionOf, resolveNamespaceOf } from "./settings-read.js";
|
|
6
8
|
const effortId = z.union(['off', 'on', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max']);
|
|
9
|
+
/** Per-model capability overrides — shared verbatim by both schema faces
|
|
10
|
+
* below (the two must never drift). */
|
|
11
|
+
const modelsSchema = z.dict(z.object({
|
|
12
|
+
// schemastery fields are optional unless marked `.required()`.
|
|
13
|
+
vision: z.boolean(),
|
|
14
|
+
thinking: z.boolean(),
|
|
15
|
+
efforts: z.union([z.const(false), z.array(effortId)]),
|
|
16
|
+
contextWindow: z.number().step(1).min(CONTEXT_WINDOW_MIN).max(CONTEXT_WINDOW_MAX),
|
|
17
|
+
})).default({});
|
|
7
18
|
/**
|
|
8
19
|
* Composition-entry schema: what a dsh profile may configure at assembly
|
|
9
20
|
* time (cordis.yml `config:` of the plugin row). The same schema doubles as
|
|
@@ -16,13 +27,23 @@ export const Config = z.object({
|
|
|
16
27
|
level: z.union(['off', 'on', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max', 'auto']).default('auto').volatile(),
|
|
17
28
|
allowDowngrade: z.boolean().default(true).volatile(),
|
|
18
29
|
allowUpgrade: z.boolean().default(false).volatile(),
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
takeover: z.boolean().default(false).volatile(),
|
|
31
|
+
models: modelsSchema,
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* Legacy (≤0.1.6) settings schema: the same fields WITHOUT the `.volatile()`
|
|
35
|
+
* ref wrappers. The imperative `settings.register` resolver reads schemas
|
|
36
|
+
* literally and rejects the 0.1.7 ref descriptors ("$.enabled expected
|
|
37
|
+
* boolean but got [object Object]", live on cell 0.1.5) — the 3.x compat
|
|
38
|
+
* branches shipped exactly this plain shape.
|
|
39
|
+
*/
|
|
40
|
+
export const LegacyConfig = z.object({
|
|
41
|
+
enabled: z.boolean().default(true),
|
|
42
|
+
level: z.union(['off', 'on', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max', 'auto']).default('auto'),
|
|
43
|
+
allowDowngrade: z.boolean().default(true),
|
|
44
|
+
allowUpgrade: z.boolean().default(false),
|
|
45
|
+
takeover: z.boolean().default(false),
|
|
46
|
+
models: modelsSchema,
|
|
26
47
|
});
|
|
27
48
|
/** Settings defaults, kept in lockstep with the schema defaults above. */
|
|
28
49
|
export const DEFAULT_CONFIG = {
|
|
@@ -30,6 +51,7 @@ export const DEFAULT_CONFIG = {
|
|
|
30
51
|
level: 'auto',
|
|
31
52
|
allowDowngrade: true,
|
|
32
53
|
allowUpgrade: false,
|
|
54
|
+
takeover: false,
|
|
33
55
|
models: {},
|
|
34
56
|
};
|
|
35
57
|
/**
|
|
@@ -56,6 +78,7 @@ function resolveLiveConfig(config) {
|
|
|
56
78
|
level: readVolatile(config.level, 'auto'),
|
|
57
79
|
allowDowngrade: readVolatile(config.allowDowngrade, true),
|
|
58
80
|
allowUpgrade: readVolatile(config.allowUpgrade, false),
|
|
81
|
+
takeover: readVolatile(config.takeover, false),
|
|
59
82
|
models: config.models,
|
|
60
83
|
};
|
|
61
84
|
}
|
|
@@ -136,34 +159,37 @@ function advertiseModelCapability(llm, overrideFor, piAiFor) {
|
|
|
136
159
|
}
|
|
137
160
|
}
|
|
138
161
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
* pi-ai's native reasoning semantics.
|
|
162
|
+
* One `describe()` pass, two namespaces: the taken-over routes (transport
|
|
163
|
+
* section judgment) and the llm-pi-ai section for the posture lookup.
|
|
164
|
+
* `describe()` replaces the dead `settings?.get?.()` soft reads —
|
|
165
|
+
* `SettingsForms` has no `get`.
|
|
144
166
|
*/
|
|
145
|
-
function
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
167
|
+
function takeoverReadout(ctx) {
|
|
168
|
+
const descriptors = describeSettings(ctx);
|
|
169
|
+
// The transport's composition entry id changed shape across its packaging
|
|
170
|
+
// history — settle on whichever namespace the describe document carries.
|
|
171
|
+
const section = resolveNamespaceOf(descriptors, TAKEOVER_NAMESPACE_CANDIDATES)?.value;
|
|
172
|
+
const piAi = readSectionOf(descriptors, PI_AI_NAMESPACE)?.value;
|
|
173
|
+
return { routes: takeoverRoutesOf(section), piAi };
|
|
149
174
|
}
|
|
150
175
|
/**
|
|
151
|
-
* The llm-pi-ai posture of one model,
|
|
176
|
+
* The llm-pi-ai posture of one model, from the live llm-pi-ai section
|
|
152
177
|
* (the capability card writes `reasoningEfforts` and `compat` there). Absent
|
|
153
178
|
* when the route/model is not configured.
|
|
154
179
|
*
|
|
155
180
|
* A model is toggle-only (Off/On, no effort levels) only when BOTH the model
|
|
156
181
|
* declares a thinking toggle (reasoningEfforts table, no
|
|
157
182
|
* supportsReasoningEffort) AND the route is taken over by the
|
|
158
|
-
* openai-completions
|
|
159
|
-
*
|
|
160
|
-
* reasoning semantics — off/high stay visible and pi-ai validates the
|
|
161
|
-
* so it is NOT folded into a toggle here.
|
|
183
|
+
* openai-completions transport (it is in the takeover judgment). A route
|
|
184
|
+
* OUTSIDE the takeover judgment is served by pi-ai with its native
|
|
185
|
+
* reasoning semantics — off/high stay visible and pi-ai validates the
|
|
186
|
+
* effort — so it is NOT folded into a toggle here.
|
|
162
187
|
*/
|
|
163
|
-
function piAiPosture(
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
188
|
+
function piAiPosture(piAi, provider, model, takeover) {
|
|
189
|
+
const rows = Array.isArray(piAi?.providers?.[provider]?.models)
|
|
190
|
+
? piAi.providers[provider].models
|
|
191
|
+
: [];
|
|
192
|
+
const entry = rows.find(candidate => candidate['id'] === model);
|
|
167
193
|
if (entry === undefined)
|
|
168
194
|
return undefined;
|
|
169
195
|
const efforts = entry['reasoningEfforts'];
|
|
@@ -171,8 +197,8 @@ function piAiPosture(ctx, provider, model, takeover) {
|
|
|
171
197
|
const thinkingOn = typeof efforts === 'object' && efforts !== null && !Array.isArray(efforts);
|
|
172
198
|
const supportsEffort = typeof compat === 'object' && compat !== null
|
|
173
199
|
&& compat['supportsReasoningEffort'] === true;
|
|
174
|
-
// Toggle folding is a takeover-
|
|
175
|
-
//
|
|
200
|
+
// Toggle folding is a takeover-judgment concern: only the openai-completions
|
|
201
|
+
// transport's routes get the Off/On treatment. pi-ai-served routes keep their
|
|
176
202
|
// native effort levels (off/high visible).
|
|
177
203
|
const toggled = takeover !== null && takeover.includes(provider);
|
|
178
204
|
return { thinkingOn: thinkingOn && toggled, supportsEffort };
|
|
@@ -196,7 +222,8 @@ function capabilityResolver(ctx) {
|
|
|
196
222
|
try {
|
|
197
223
|
const info = await llm?.resolveModelInfo?.(provider, model);
|
|
198
224
|
const efforts = info?.reasoning?.efforts?.map(effort => effort.id) ?? [];
|
|
199
|
-
const
|
|
225
|
+
const readout = takeoverReadout(ctx);
|
|
226
|
+
const posture = piAiPosture(readout.piAi, provider, model, readout.routes);
|
|
200
227
|
capability = {
|
|
201
228
|
supportsReasoning: reasoningEffortSupported(info?.reasoning),
|
|
202
229
|
efforts,
|
|
@@ -215,6 +242,60 @@ function capabilityResolver(ctx) {
|
|
|
215
242
|
},
|
|
216
243
|
};
|
|
217
244
|
}
|
|
245
|
+
/** The registered settings namespace of the ≤0.1.6 era. */
|
|
246
|
+
const THINKING_LEVELS_SETTINGS_NAMESPACE = 'thinking-levels';
|
|
247
|
+
/**
|
|
248
|
+
* Legacy (≤0.1.6) settings registration: on hosts whose settings service
|
|
249
|
+
* carries the imperative face (`register` present, `describe` absent), install
|
|
250
|
+
* this plugin's section so its config is runtime-editable and the live values
|
|
251
|
+
* feed `current()`. On 0.1.7+ the composition entry IS the section (the
|
|
252
|
+
* `.volatile()` fields arrive as live refs) and `register` no longer exists —
|
|
253
|
+
* the install is a no-op there. Shape-detected, never version-guessed.
|
|
254
|
+
*/
|
|
255
|
+
export function installLegacySection(ctx, config, hooks) {
|
|
256
|
+
const inject = ctx.inject;
|
|
257
|
+
if (typeof inject !== 'function')
|
|
258
|
+
return;
|
|
259
|
+
inject.call(ctx, ['settings'], (sctx) => {
|
|
260
|
+
const settings = sctx.settings;
|
|
261
|
+
console.log(`[dsh-thinking-levels] settings service face: register=${typeof settings?.register} installSection=${typeof settings?.installSection} describe=${typeof settings?.describe}`);
|
|
262
|
+
// `register`'s presence IS the imperative face (≤0.1.6). `describe` must
|
|
263
|
+
// NOT be read as a declarative-generation marker: the webServer mirror
|
|
264
|
+
// carries describe/mutate on EVERY generation (三代腰 finding —
|
|
265
|
+
// mutate/describe 四代全在), so the old `describe → skip` clause silently
|
|
266
|
+
// disabled this install on 0.1.2/0.1.5 too, leaving the namespace
|
|
267
|
+
// unregistered and every settingsScope.bind('thinking-levels') read
|
|
268
|
+
// `unavailable` forever.
|
|
269
|
+
if (typeof settings?.register !== 'function')
|
|
270
|
+
return;
|
|
271
|
+
try {
|
|
272
|
+
// The loader hands `apply` its config through the entry schema — the
|
|
273
|
+
// volatile-shaped `Config` on EVERY generation — so the runtime values
|
|
274
|
+
// sit behind live refs even on hosts taking the imperative register
|
|
275
|
+
// path. Flatten to plain values for the legacy resolver's base layer
|
|
276
|
+
// ("$.enabled expected boolean but got [object Object]", live on cell
|
|
277
|
+
// 0.1.5, was the ref riding in as the base).
|
|
278
|
+
const plainBase = {
|
|
279
|
+
enabled: readVolatile(config.enabled, true),
|
|
280
|
+
level: readVolatile(config.level, 'auto'),
|
|
281
|
+
allowDowngrade: readVolatile(config.allowDowngrade, true),
|
|
282
|
+
allowUpgrade: readVolatile(config.allowUpgrade, false),
|
|
283
|
+
takeover: readVolatile(config.takeover, false),
|
|
284
|
+
models: config.models,
|
|
285
|
+
};
|
|
286
|
+
const scope = settings.register(THINKING_LEVELS_SETTINGS_NAMESPACE, LegacyConfig, { base: plainBase });
|
|
287
|
+
console.log('[dsh-thinking-levels] settings via settings.register (≤0.1.6 imperative face)');
|
|
288
|
+
hooks.setSource(() => scope.get());
|
|
289
|
+
sctx.effect(() => () => {
|
|
290
|
+
hooks.setSource(() => config);
|
|
291
|
+
});
|
|
292
|
+
scope.watch?.(() => { });
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
console.log(`[dsh-thinking-levels] settings.register FAILED: ${error instanceof Error ? error.message : String(error)}`);
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
}
|
|
218
299
|
/**
|
|
219
300
|
* Plugin body.
|
|
220
301
|
* @param ctx - host context carrying the agent-event dispatch.
|
|
@@ -225,13 +306,31 @@ export function apply(ctx, config = DEFAULT_CONFIG) {
|
|
|
225
306
|
// not ride through into the model request, where dsh throws
|
|
226
307
|
// UNSUPPORTED_REASONING_EFFORT per request.
|
|
227
308
|
assertEffortId(resolveLiveConfig(config).level, 'dsh-thinking-levels config.level');
|
|
228
|
-
// Runtime-adjustable configuration:
|
|
229
|
-
//
|
|
230
|
-
// change needs no re-registration
|
|
231
|
-
//
|
|
232
|
-
|
|
309
|
+
// Runtime-adjustable configuration: volatile refs on 0.1.7+, the registered
|
|
310
|
+
// section before that — both re-read per request, so a committed settings
|
|
311
|
+
// change needs no re-registration. The ≤0.1.6 registered section (user edits
|
|
312
|
+
// layered over the entry base) wins when installed.
|
|
313
|
+
let source = () => config;
|
|
314
|
+
installLegacySection(ctx, config, { setSource: (next) => { source = next; } });
|
|
315
|
+
ctx.inject?.(['sessionProjections'], (scope) => {
|
|
316
|
+
const def = buildBillingDefinition();
|
|
317
|
+
// 0.1.0-rc.8 是唯一的旧平面契约 registry(snapshot 走 def.schema.parse(def.view(state)),
|
|
318
|
+
// 0.1.1+ 全线是 stateSchema/wire 新契约)。旧 registry 对缺 schema 的单元直接
|
|
319
|
+
// 「Cannot read properties of undefined (reading 'parse')」——一颗单元毒化全部
|
|
320
|
+
// 冷会话历史加载(2026-10-08 五格实证)。镜像 wire 形状为平面键,两代 registry
|
|
321
|
+
// 各取所需;新契约线多出的两个键无人消费,行为不变。
|
|
322
|
+
const wire = def.wire;
|
|
323
|
+
if (wire && def.schema === undefined) {
|
|
324
|
+
def.schema = wire.viewSchema;
|
|
325
|
+
def.view = wire.view;
|
|
326
|
+
}
|
|
327
|
+
scope.sessionProjections?.register(def);
|
|
328
|
+
});
|
|
329
|
+
const current = () => resolveLiveConfig(source());
|
|
233
330
|
ctx.on('loader/volatile-update', () => {
|
|
234
331
|
assertEffortId(resolveLiveConfig(config).level, 'dsh-thinking-levels config.level');
|
|
332
|
+
// A flipped takeover switch mirrors immediately (identity-gated).
|
|
333
|
+
syncTakeover();
|
|
235
334
|
});
|
|
236
335
|
// Official-compat bridge (check branch): write the OFFICIAL compat surface
|
|
237
336
|
// into the llm-pi-ai namespace for every provider that targets a custom
|
|
@@ -253,7 +352,9 @@ export function apply(ctx, config = DEFAULT_CONFIG) {
|
|
|
253
352
|
const syncDeveloperRole = () => {
|
|
254
353
|
syncTail = syncTail.then(async () => {
|
|
255
354
|
const settings = ctx.get('settings');
|
|
256
|
-
|
|
355
|
+
// describe() is the only read channel on 0.1.7+ (SettingsForms has no
|
|
356
|
+
// `get`); the section value is the schema-projected live config.
|
|
357
|
+
const piAi = readSection(ctx, PI_AI_NAMESPACE)?.value;
|
|
257
358
|
const next = withOfficialCompatFixes(piAi);
|
|
258
359
|
if (next === undefined || next === piAi)
|
|
259
360
|
return;
|
|
@@ -263,16 +364,46 @@ export function apply(ctx, config = DEFAULT_CONFIG) {
|
|
|
263
364
|
ctx.logger?.warn?.('[thinking-levels] developer-role compat sync rejected (schema gate); kept previous section', error);
|
|
264
365
|
});
|
|
265
366
|
};
|
|
367
|
+
// Takeover mirror: this plugin's `takeover` switch (settings UI) is the
|
|
368
|
+
// control-layer master; the write lands in the transport's OWN section
|
|
369
|
+
// (`llm-openai-completions.enabled`), whose judgment stays single-source.
|
|
370
|
+
// Cross-plugin writes are schema-gated at the write site (the transport's
|
|
371
|
+
// `enabled` is volatile) and never touch its other fields. Writes fire only
|
|
372
|
+
// on divergence (transport absent = nothing to drive), so a manual edit of
|
|
373
|
+
// the transport section survives until the switch is actually flipped again.
|
|
374
|
+
const syncTakeover = () => {
|
|
375
|
+
syncTail = syncTail.then(async () => {
|
|
376
|
+
// Resolve the transport's LIVE namespace from the describe document
|
|
377
|
+
// (the entry id changed shape across its packaging history) — the read
|
|
378
|
+
// and the mirror write land on the same settled id.
|
|
379
|
+
const transport = resolveNamespaceOf(describeSettings(ctx), TAKEOVER_NAMESPACE_CANDIDATES);
|
|
380
|
+
const patch = takeoverPatch(transport?.value, current().takeover);
|
|
381
|
+
if (patch === undefined || transport === undefined)
|
|
382
|
+
return;
|
|
383
|
+
const settings = ctx.get('settings');
|
|
384
|
+
await settings?.update?.(transport.ns, patch);
|
|
385
|
+
ctx.logger?.info?.('[thinking-levels] takeover switch %s written to %s.enabled', String(current().takeover), transport.ns);
|
|
386
|
+
}).catch((error) => {
|
|
387
|
+
ctx.logger?.warn?.('[thinking-levels] takeover mirror write rejected (schema gate); kept previous section', error);
|
|
388
|
+
});
|
|
389
|
+
};
|
|
266
390
|
// Initial sync (adapters may register later; re-run on every adapters update
|
|
267
391
|
// and every llm-pi-ai settings update so a Settings → Models edit propagates.
|
|
268
392
|
// The write is identity-gated, so the re-entry triggered by our own update
|
|
269
393
|
// settles immediately).
|
|
270
394
|
syncDeveloperRole();
|
|
395
|
+
syncTakeover();
|
|
271
396
|
const onSyncAny = ctx.on;
|
|
272
|
-
onSyncAny('llm/adapters-updated', () =>
|
|
397
|
+
onSyncAny('llm/adapters-updated', () => {
|
|
398
|
+
syncDeveloperRole();
|
|
399
|
+
syncTakeover();
|
|
400
|
+
});
|
|
273
401
|
onSyncAny('settings/document-updated', (ns) => {
|
|
274
402
|
if (ns === PI_AI_NAMESPACE)
|
|
275
403
|
syncDeveloperRole();
|
|
404
|
+
// Any settings commit re-checks the mirror (identity-gated); the write we
|
|
405
|
+
// just made re-enters here and settles without a second write.
|
|
406
|
+
syncTakeover();
|
|
276
407
|
});
|
|
277
408
|
// Inject the level decision into every model request of a step.
|
|
278
409
|
// The 'agent/request' event key is augmented onto cordis Events by the
|
|
@@ -331,13 +462,22 @@ export function apply(ctx, config = DEFAULT_CONFIG) {
|
|
|
331
462
|
// Read the live llm-pi-ai config for the thinking/effort posture the card
|
|
332
463
|
// wrote there: a model with `reasoningEfforts` but without effort support
|
|
333
464
|
// (Qwen3.6) is collapsed to an On/Off toggle in the selector — but ONLY when
|
|
334
|
-
// the route is taken over by the openai-completions
|
|
465
|
+
// the route is taken over by the openai-completions transport. A pi-ai-served
|
|
335
466
|
// route (e.g. mimo via xiaomi) keeps its native off/high levels.
|
|
336
|
-
const piAiFor = (provider, model) =>
|
|
467
|
+
const piAiFor = (provider, model) => {
|
|
468
|
+
const readout = takeoverReadout(ctx);
|
|
469
|
+
return piAiPosture(readout.piAi, provider, model, readout.routes);
|
|
470
|
+
};
|
|
337
471
|
advertiseModelCapability(llm, overrideFor, piAiFor);
|
|
338
472
|
const onAny = ctx.on;
|
|
339
473
|
onAny('llm/adapters-updated', () => {
|
|
340
474
|
capability.clear();
|
|
341
475
|
advertiseModelCapability(ctx.get('llm'), overrideFor, piAiFor);
|
|
342
476
|
});
|
|
477
|
+
// A settings commit can flip the takeover judgment (the transport's enabled
|
|
478
|
+
// flag or the llm-pi-ai routes): drop the cached capability snapshots so
|
|
479
|
+
// toggle folding follows the new posture on the next request.
|
|
480
|
+
onAny('settings/document-updated', () => {
|
|
481
|
+
capability.clear();
|
|
482
|
+
});
|
|
343
483
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-namespace reads over the DSH 0.1.7+ settings service.
|
|
3
|
+
*
|
|
4
|
+
* `SettingsForms` (the service registered as `settings`) has no `get(ns)`:
|
|
5
|
+
* the read channel is `describe()`, which returns every active profile
|
|
6
|
+
* entry's live Config value with its schema projection and revision. The
|
|
7
|
+
* `settings?.get?.(ns)` soft reads this plugin carried since the 0.1.7
|
|
8
|
+
* migration were therefore silently dead on every supported host — this
|
|
9
|
+
* module replaces them.
|
|
10
|
+
*
|
|
11
|
+
* Values are schema-projected by the host (`projectForm`), so only fields
|
|
12
|
+
* the owning plugin's Config schema declares survive the round trip; the
|
|
13
|
+
* `revision` is the write fence `settings.update(ns, patch, expectedRevision)`
|
|
14
|
+
* accepts.
|
|
15
|
+
* @module dsh-thinking-levels/settings-read
|
|
16
|
+
*/
|
|
17
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
18
|
+
/** Minimal face of the settings service this module reads. */
|
|
19
|
+
export interface SettingsServiceLike {
|
|
20
|
+
describe?: () => SettingsDescriptorLike[];
|
|
21
|
+
}
|
|
22
|
+
/** One active profile entry as `describe()` reports it (minimal face). */
|
|
23
|
+
export interface SettingsDescriptorLike {
|
|
24
|
+
ns: string;
|
|
25
|
+
value: unknown;
|
|
26
|
+
revision: number;
|
|
27
|
+
}
|
|
28
|
+
/** One namespace's live section value with its write fence. */
|
|
29
|
+
export interface SectionReadout<T = unknown> {
|
|
30
|
+
value: T;
|
|
31
|
+
revision: number;
|
|
32
|
+
}
|
|
33
|
+
/** One `describe()` pass over the live settings, or `undefined` when the service is absent. */
|
|
34
|
+
export declare function describeSettings(ctx: Context): SettingsDescriptorLike[] | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Read one namespace's live section. `undefined` when the settings service is
|
|
37
|
+
* absent or the namespace is not an active profile entry (owning plugin not
|
|
38
|
+
* installed / not composed).
|
|
39
|
+
*/
|
|
40
|
+
export declare function readSection<T = unknown>(ctx: Context, ns: string): SectionReadout<T> | undefined;
|
|
41
|
+
/** Pick one namespace out of a `describe()` pass (undefined when absent). */
|
|
42
|
+
export declare function readSectionOf<T = unknown>(descriptors: SettingsDescriptorLike[] | undefined, ns: string): SectionReadout<T> | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Pick the first candidate namespace a `describe()` pass actually carries.
|
|
45
|
+
* Composition entry ids shifted shape across a plugin's own packaging history
|
|
46
|
+
* (e.g. the openai-completions transport's `dsh-llm-openai-completions` since
|
|
47
|
+
* its 0.4.0 fragment vs the short form earlier manual installs used), so
|
|
48
|
+
* cross-plugin readers resolve the LIVE id instead of hardcoding one — the
|
|
49
|
+
* winner is shape-detected from the document, never version-guessed.
|
|
50
|
+
*/
|
|
51
|
+
export declare function resolveNamespaceOf<T = unknown>(descriptors: SettingsDescriptorLike[] | undefined, candidates: readonly string[]): (SectionReadout<T> & {
|
|
52
|
+
ns: string;
|
|
53
|
+
}) | undefined;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** One `describe()` pass over the live settings, or `undefined` when the service is absent. */
|
|
2
|
+
export function describeSettings(ctx) {
|
|
3
|
+
const settings = ctx.get('settings');
|
|
4
|
+
return settings?.describe?.();
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Read one namespace's live section. `undefined` when the settings service is
|
|
8
|
+
* absent or the namespace is not an active profile entry (owning plugin not
|
|
9
|
+
* installed / not composed).
|
|
10
|
+
*/
|
|
11
|
+
export function readSection(ctx, ns) {
|
|
12
|
+
return readSectionOf(describeSettings(ctx), ns);
|
|
13
|
+
}
|
|
14
|
+
/** Pick one namespace out of a `describe()` pass (undefined when absent). */
|
|
15
|
+
export function readSectionOf(descriptors, ns) {
|
|
16
|
+
const found = descriptors?.find((descriptor) => descriptor.ns === ns);
|
|
17
|
+
if (found === undefined)
|
|
18
|
+
return undefined;
|
|
19
|
+
return { value: found.value, revision: found.revision };
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Pick the first candidate namespace a `describe()` pass actually carries.
|
|
23
|
+
* Composition entry ids shifted shape across a plugin's own packaging history
|
|
24
|
+
* (e.g. the openai-completions transport's `dsh-llm-openai-completions` since
|
|
25
|
+
* its 0.4.0 fragment vs the short form earlier manual installs used), so
|
|
26
|
+
* cross-plugin readers resolve the LIVE id instead of hardcoding one — the
|
|
27
|
+
* winner is shape-detected from the document, never version-guessed.
|
|
28
|
+
*/
|
|
29
|
+
export function resolveNamespaceOf(descriptors, candidates) {
|
|
30
|
+
for (const ns of candidates) {
|
|
31
|
+
const read = readSectionOf(descriptors, ns);
|
|
32
|
+
if (read !== undefined)
|
|
33
|
+
return { ...read, ns };
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
package/lib/takeover-sync.d.ts
CHANGED
|
@@ -32,7 +32,15 @@
|
|
|
32
32
|
*/
|
|
33
33
|
/** The settings namespace holding the provider/model configs (llm-pi-ai). */
|
|
34
34
|
export declare const PI_AI_NAMESPACE = "llm-pi-ai";
|
|
35
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* The transport's composition entry id changed shape across its packaging
|
|
37
|
+
* history: the shipped cordis.patch.yml inserts `dsh-llm-openai-completions`
|
|
38
|
+
* since the 0.4.0 fragment, while earlier manual installs used the short form.
|
|
39
|
+
* Readers settle on whichever namespace the host's describe document carries —
|
|
40
|
+
* never version-guessed, always shape-detected.
|
|
41
|
+
*/
|
|
42
|
+
export declare const TAKEOVER_NAMESPACE_CANDIDATES: readonly ["dsh-llm-openai-completions", "llm-openai-completions"];
|
|
43
|
+
/** @deprecated short-form candidate kept for takeovers of legacy installs; prefer {@link TAKEOVER_NAMESPACE_CANDIDATES}. */
|
|
36
44
|
export declare const TAKEOVER_NAMESPACE = "llm-openai-completions";
|
|
37
45
|
/** One model row of the llm-pi-ai section (minimal face). */
|
|
38
46
|
export interface PiAiModelRow {
|
|
@@ -107,17 +115,35 @@ export declare function identifyTakeoverProviders(section: PiAiSection | undefin
|
|
|
107
115
|
*/
|
|
108
116
|
export declare function withOfficialCompatFixes(section: PiAiSection | undefined): PiAiSection | undefined;
|
|
109
117
|
/**
|
|
110
|
-
* The
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
118
|
+
* The settings patch to sync this plugin's takeover switch into the
|
|
119
|
+
* transport's own section, or `undefined` when nothing may be written:
|
|
120
|
+
* the transport is not composed (no section to drive — its `enabled` simply
|
|
121
|
+
* does not exist), or the section already agrees (identity). Cross-plugin
|
|
122
|
+
* writes are schema-gated at the WRITE site (the target field must be
|
|
123
|
+
* volatile in the owning plugin's Config — `enabled` is), not
|
|
124
|
+
* caller-gated; this plugin never writes anything but `enabled` there, so
|
|
125
|
+
* the user's manual `providers` list and every other field are untouched.
|
|
126
|
+
* @param section - the live llm-openai-completions section, if composed.
|
|
127
|
+
* @param flag - this plugin's takeover switch.
|
|
128
|
+
* @returns the minimal patch, or `undefined` when no write is due.
|
|
129
|
+
*/
|
|
130
|
+
export declare function takeoverPatch(section: {
|
|
131
|
+
enabled?: unknown;
|
|
132
|
+
providers?: unknown;
|
|
133
|
+
} | undefined, flag: boolean): {
|
|
134
|
+
enabled: boolean;
|
|
135
|
+
} | undefined;
|
|
136
|
+
/**
|
|
137
|
+
* The routes the openai-completions transport currently takes over: pure
|
|
138
|
+
* manual membership (`enabled && route ∈ providers`). The capability card's
|
|
139
|
+
* per-route takeover checkbox is the single per-route truth and dispatch uses
|
|
140
|
+
* the same set, so this gating reads exactly what the transport serves.
|
|
141
|
+
* @param section - the live llm-openai-completions section, if composed.
|
|
142
|
+
* @returns the taken-over route ids, `[]` when the transport is disabled, or
|
|
143
|
+
* `null` when the transport is not composed (namespace absent — every route
|
|
144
|
+
* keeps pi-ai's native reasoning semantics).
|
|
119
145
|
*/
|
|
120
|
-
export declare function
|
|
146
|
+
export declare function takeoverRoutesOf(section: {
|
|
121
147
|
enabled?: unknown;
|
|
122
148
|
providers?: unknown;
|
|
123
149
|
} | undefined): string[] | null;
|
package/lib/takeover-sync.js
CHANGED
|
@@ -32,7 +32,18 @@
|
|
|
32
32
|
*/
|
|
33
33
|
/** The settings namespace holding the provider/model configs (llm-pi-ai). */
|
|
34
34
|
export const PI_AI_NAMESPACE = 'llm-pi-ai';
|
|
35
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* The transport's composition entry id changed shape across its packaging
|
|
37
|
+
* history: the shipped cordis.patch.yml inserts `dsh-llm-openai-completions`
|
|
38
|
+
* since the 0.4.0 fragment, while earlier manual installs used the short form.
|
|
39
|
+
* Readers settle on whichever namespace the host's describe document carries —
|
|
40
|
+
* never version-guessed, always shape-detected.
|
|
41
|
+
*/
|
|
42
|
+
export const TAKEOVER_NAMESPACE_CANDIDATES = [
|
|
43
|
+
'dsh-llm-openai-completions',
|
|
44
|
+
'llm-openai-completions',
|
|
45
|
+
];
|
|
46
|
+
/** @deprecated short-form candidate kept for takeovers of legacy installs; prefer {@link TAKEOVER_NAMESPACE_CANDIDATES}. */
|
|
36
47
|
export const TAKEOVER_NAMESPACE = 'llm-openai-completions';
|
|
37
48
|
/** Hosts that are NOT a custom gateway (official OpenAI-compatible endpoints). */
|
|
38
49
|
const OFFICIAL_HOST_RE = /(?:^|\.)(?:deepseek\.com|openai\.com|openrouter\.ai|anthropic\.com|googleapis\.com|ai\.google\.dev|mistral\.ai|x\.ai)$/i;
|
|
@@ -216,17 +227,36 @@ export function withOfficialCompatFixes(section) {
|
|
|
216
227
|
return nextProviders === undefined ? section : { ...section, providers: nextProviders };
|
|
217
228
|
}
|
|
218
229
|
/**
|
|
219
|
-
* The
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
230
|
+
* The settings patch to sync this plugin's takeover switch into the
|
|
231
|
+
* transport's own section, or `undefined` when nothing may be written:
|
|
232
|
+
* the transport is not composed (no section to drive — its `enabled` simply
|
|
233
|
+
* does not exist), or the section already agrees (identity). Cross-plugin
|
|
234
|
+
* writes are schema-gated at the WRITE site (the target field must be
|
|
235
|
+
* volatile in the owning plugin's Config — `enabled` is), not
|
|
236
|
+
* caller-gated; this plugin never writes anything but `enabled` there, so
|
|
237
|
+
* the user's manual `providers` list and every other field are untouched.
|
|
238
|
+
* @param section - the live llm-openai-completions section, if composed.
|
|
239
|
+
* @param flag - this plugin's takeover switch.
|
|
240
|
+
* @returns the minimal patch, or `undefined` when no write is due.
|
|
241
|
+
*/
|
|
242
|
+
export function takeoverPatch(section, flag) {
|
|
243
|
+
if (section === undefined)
|
|
244
|
+
return undefined;
|
|
245
|
+
if (section.enabled === flag)
|
|
246
|
+
return undefined;
|
|
247
|
+
return { enabled: flag };
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* The routes the openai-completions transport currently takes over: pure
|
|
251
|
+
* manual membership (`enabled && route ∈ providers`). The capability card's
|
|
252
|
+
* per-route takeover checkbox is the single per-route truth and dispatch uses
|
|
253
|
+
* the same set, so this gating reads exactly what the transport serves.
|
|
254
|
+
* @param section - the live llm-openai-completions section, if composed.
|
|
255
|
+
* @returns the taken-over route ids, `[]` when the transport is disabled, or
|
|
256
|
+
* `null` when the transport is not composed (namespace absent — every route
|
|
257
|
+
* keeps pi-ai's native reasoning semantics).
|
|
228
258
|
*/
|
|
229
|
-
export function
|
|
259
|
+
export function takeoverRoutesOf(section) {
|
|
230
260
|
if (section === undefined)
|
|
231
261
|
return null;
|
|
232
262
|
if (section.enabled !== true)
|