dsh-thinking-levels 0.4.1 → 0.7.0-beta.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/CHANGELOG.ja.md +117 -0
- package/CHANGELOG.ko.md +117 -0
- package/CHANGELOG.md +126 -0
- package/INSTALL.ja.md +163 -0
- package/INSTALL.ko.md +163 -0
- package/INSTALL.md +163 -0
- package/INSTALL.zh.md +163 -0
- package/LICENSE +21 -0
- package/README.ja.md +168 -0
- package/README.ko.md +168 -0
- package/README.md +222 -108
- package/README.zh.md +174 -108
- package/lib/client.js +1801 -94
- package/lib/client.js.map +1 -1
- package/lib/context-window.d.ts +41 -0
- package/lib/context-window.js +54 -0
- package/lib/index.d.ts +41 -3
- package/lib/index.js +227 -26
- package/lib/takeover-sync.d.ts +123 -0
- package/lib/takeover-sync.js +237 -0
- package/lib/thinking-level.d.ts +106 -16
- package/lib/thinking-level.js +126 -13
- package/package.json +88 -79
package/lib/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import z from '@deepseek-ai/schemastery';
|
|
2
|
-
import { assertEffortId,
|
|
2
|
+
import { assertEffortId, reasoningEffortSupported, resolveEffortInjection } from "./thinking-level.js";
|
|
3
3
|
import { recentToolCalls } from "./session-events.js";
|
|
4
|
+
import { CONTEXT_WINDOW_MAX, CONTEXT_WINDOW_MIN } from "./context-window.js";
|
|
5
|
+
import { PI_AI_NAMESPACE, TAKEOVER_NAMESPACE, takeoverProvidersOf, withOfficialCompatFixes, } from "./takeover-sync.js";
|
|
6
|
+
const effortId = z.union(['off', 'on', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max']);
|
|
4
7
|
/**
|
|
5
8
|
* Composition-entry schema: what a dsh profile may configure at assembly
|
|
6
9
|
* time (cordis.yml `config:` of the plugin row). The settings namespace
|
|
@@ -9,9 +12,16 @@ import { recentToolCalls } from "./session-events.js";
|
|
|
9
12
|
*/
|
|
10
13
|
export const Config = z.object({
|
|
11
14
|
enabled: z.boolean().default(true),
|
|
12
|
-
level: z.union(['off', 'low', 'high', 'max', 'auto']).default('auto'),
|
|
15
|
+
level: z.union(['off', 'on', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max', 'auto']).default('auto'),
|
|
13
16
|
allowDowngrade: z.boolean().default(true),
|
|
14
17
|
allowUpgrade: z.boolean().default(false),
|
|
18
|
+
models: z.dict(z.object({
|
|
19
|
+
// schemastery fields are optional unless marked `.required()`.
|
|
20
|
+
vision: z.boolean(),
|
|
21
|
+
thinking: z.boolean(),
|
|
22
|
+
efforts: z.union([z.const(false), z.array(effortId)]),
|
|
23
|
+
contextWindow: z.number().step(1).min(CONTEXT_WINDOW_MIN).max(CONTEXT_WINDOW_MAX),
|
|
24
|
+
})).default({}),
|
|
15
25
|
});
|
|
16
26
|
/** Settings defaults, kept in lockstep with the schema defaults above. */
|
|
17
27
|
export const DEFAULT_CONFIG = {
|
|
@@ -19,6 +29,7 @@ export const DEFAULT_CONFIG = {
|
|
|
19
29
|
level: 'auto',
|
|
20
30
|
allowDowngrade: true,
|
|
21
31
|
allowUpgrade: false,
|
|
32
|
+
models: {},
|
|
22
33
|
};
|
|
23
34
|
/** Runtime-adjustable settings namespace: level + scheduler toggles. */
|
|
24
35
|
export const THINKING_LEVELS_SETTINGS_NAMESPACE = 'thinking-levels';
|
|
@@ -58,25 +69,153 @@ const TOOL_AGE_LIMIT_MS = 10 * 60 * 1000;
|
|
|
58
69
|
*/
|
|
59
70
|
const AUTO_EFFORT = { id: 'auto', name: 'Auto' };
|
|
60
71
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
72
|
+
* The `low` level, advertised only for configurer-confirmed models whose
|
|
73
|
+
* adapter predates dsh rc.7 (efforts list without `low`). Advertising it makes
|
|
74
|
+
* the selector show Low and the harness request validation admit the
|
|
75
|
+
* passthrough; the adapter must serialize it (pi-ai openai-completions does,
|
|
76
|
+
* e.g. via `thinkingFormat: qwen` → enable_thinking + thinking_budget).
|
|
77
|
+
*/
|
|
78
|
+
const LOW_EFFORT = { id: 'low', name: 'Low' };
|
|
79
|
+
/**
|
|
80
|
+
* Advertise `auto` (and, for configurer-confirmed rc.6-era models, `low`) in
|
|
81
|
+
* the model directory: wrap every registered adapter's `resolveModel` so the
|
|
82
|
+
* returned `reasoning.efforts` include the extra levels. Idempotent per
|
|
83
|
+
* adapter. `auto` is a mask the plugin resolves per request; `low` is only
|
|
84
|
+
* added when the model override confirms the level, so rc.7+ models (which
|
|
85
|
+
* already advertise low) and unconfirmed models stay untouched.
|
|
86
|
+
*
|
|
87
|
+
* A thinking model WITHOUT effort support (Qwen3.6-style, per the llm-pi-ai
|
|
88
|
+
* config: `reasoningEfforts` present but `compat.supportsReasoningEffort` not
|
|
89
|
+
* true) gets its selector collapsed to a plain On/Off toggle: `off` disables
|
|
90
|
+
* thinking, `on` maps to the `high` level, which pi-ai serializes as
|
|
91
|
+
* `enable_thinking: true` under `thinkingFormat: qwen`. No auto/low masks are
|
|
92
|
+
* offered for these — there is nothing to schedule.
|
|
64
93
|
* @param llm - the resolved `llm` service, when present.
|
|
94
|
+
* @param overrideFor - model override lookup, keyed `provider/model`.
|
|
95
|
+
* @param piAiFor - llm-pi-ai config capability lookup, keyed `provider/model`.
|
|
65
96
|
*/
|
|
66
|
-
function
|
|
97
|
+
function advertiseModelCapability(llm, overrideFor, piAiFor) {
|
|
67
98
|
for (const registration of llm?.adapters?.values() ?? []) {
|
|
68
99
|
const adapter = registration.adapter;
|
|
69
100
|
const original = adapter.resolveModel.bind(adapter);
|
|
70
101
|
adapter.resolveModel = async (provider, model, signal) => {
|
|
71
102
|
const info = await original(provider, model, signal);
|
|
72
103
|
const reasoning = info.reasoning;
|
|
73
|
-
if (reasoning
|
|
74
|
-
info
|
|
104
|
+
if (reasoning === undefined)
|
|
105
|
+
return info;
|
|
106
|
+
const piCap = piAiFor(provider, model);
|
|
107
|
+
if (piCap?.thinkingOn === true && piCap.supportsEffort === false) {
|
|
108
|
+
// Toggle-only model (Qwen3.6 / mimo-v2.5 style): the selector shows
|
|
109
|
+
// Off/On. The On pick MUST be a level the provider's own request path
|
|
110
|
+
// accepts — pi-ai resolves only its fixed seven levels and rejects
|
|
111
|
+
// anything else per stream (`UNSUPPORTED_REASONING_EFFORT`). `high` is
|
|
112
|
+
// that level: because the model declares supportsReasoningEffort:
|
|
113
|
+
// false, pi-ai serializes a non-off effort as enable_thinking only —
|
|
114
|
+
// no reasoning_effort is sent, which is exactly the toggle semantics.
|
|
115
|
+
info.reasoning = {
|
|
116
|
+
...reasoning,
|
|
117
|
+
efforts: [
|
|
118
|
+
{ id: 'off', name: 'Off' },
|
|
119
|
+
{ id: 'high', name: 'On' },
|
|
120
|
+
],
|
|
121
|
+
};
|
|
122
|
+
return info;
|
|
123
|
+
}
|
|
124
|
+
const efforts = [...(reasoning.efforts ?? [])];
|
|
125
|
+
if (!efforts.some(effort => effort.id === 'auto'))
|
|
126
|
+
efforts.push(AUTO_EFFORT);
|
|
127
|
+
const override = overrideFor(provider, model);
|
|
128
|
+
if (override?.efforts !== undefined
|
|
129
|
+
&& override.efforts !== false
|
|
130
|
+
&& override.efforts.includes('low')
|
|
131
|
+
&& !efforts.some(effort => effort.id === 'low')) {
|
|
132
|
+
efforts.push(LOW_EFFORT);
|
|
75
133
|
}
|
|
134
|
+
info.reasoning = { ...reasoning, efforts };
|
|
76
135
|
return info;
|
|
77
136
|
};
|
|
78
137
|
}
|
|
79
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* The providers currently taken over by dsh-llm-openai-completions, read
|
|
141
|
+
* lazily from the live `llm-openai-completions` namespace. `null` when the
|
|
142
|
+
* namespace is unregistered (adapter plugin absent). Toggle folding and effort
|
|
143
|
+
* injection apply only to routes inside this list; everything else keeps
|
|
144
|
+
* pi-ai's native reasoning semantics.
|
|
145
|
+
*/
|
|
146
|
+
function takeoverOf(ctx) {
|
|
147
|
+
const settings = ctx.get('settings');
|
|
148
|
+
const section = settings?.get?.(TAKEOVER_NAMESPACE);
|
|
149
|
+
return takeoverProvidersOf(section);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The llm-pi-ai posture of one model, read from the live settings namespace
|
|
153
|
+
* (the capability card writes `reasoningEfforts` and `compat` there). Absent
|
|
154
|
+
* when the route/model is not configured.
|
|
155
|
+
*
|
|
156
|
+
* A model is toggle-only (Off/On, no effort levels) only when BOTH the model
|
|
157
|
+
* declares a thinking toggle (reasoningEfforts table, no
|
|
158
|
+
* supportsReasoningEffort) AND the route is taken over by the
|
|
159
|
+
* openai-completions adapter (it is in the `llm-openai-completions` list).
|
|
160
|
+
* A route OUTSIDE the takeover list is served by pi-ai with its native
|
|
161
|
+
* reasoning semantics — off/high stay visible and pi-ai validates the effort —
|
|
162
|
+
* so it is NOT folded into a toggle here.
|
|
163
|
+
*/
|
|
164
|
+
function piAiPosture(ctx, provider, model, takeover) {
|
|
165
|
+
const settings = ctx.get('settings');
|
|
166
|
+
const section = settings?.get?.('llm-pi-ai');
|
|
167
|
+
const entry = section?.providers?.[provider]?.models?.find(candidate => candidate['id'] === model);
|
|
168
|
+
if (entry === undefined)
|
|
169
|
+
return undefined;
|
|
170
|
+
const efforts = entry['reasoningEfforts'];
|
|
171
|
+
const compat = entry['compat'];
|
|
172
|
+
const thinkingOn = typeof efforts === 'object' && efforts !== null && !Array.isArray(efforts);
|
|
173
|
+
const supportsEffort = typeof compat === 'object' && compat !== null
|
|
174
|
+
&& compat['supportsReasoningEffort'] === true;
|
|
175
|
+
// Toggle folding is a takeover-list concern: only the openai-completions
|
|
176
|
+
// adapter's routes get the Off/On treatment. pi-ai-served routes keep their
|
|
177
|
+
// native effort levels (off/high visible).
|
|
178
|
+
const toggled = takeover !== null && takeover.includes(provider);
|
|
179
|
+
return { thinkingOn: thinkingOn && toggled, supportsEffort };
|
|
180
|
+
}
|
|
181
|
+
const CAPABILITY_CACHE_KEY_SEPARATOR = '\u0000';
|
|
182
|
+
/** A model that cannot be resolved is treated as non-reasoning: never inject. */
|
|
183
|
+
const UNRESOLVABLE_CAPABILITY = { supportsReasoning: false, efforts: [], vision: false, toggleOnly: false };
|
|
184
|
+
/** Runtime model-capability lookup with a per-route cache. */
|
|
185
|
+
function capabilityResolver(ctx) {
|
|
186
|
+
const cache = new Map();
|
|
187
|
+
return {
|
|
188
|
+
async resolve(provider, model) {
|
|
189
|
+
if (typeof provider !== 'string' || typeof model !== 'string')
|
|
190
|
+
return UNRESOLVABLE_CAPABILITY;
|
|
191
|
+
const key = `${provider}${CAPABILITY_CACHE_KEY_SEPARATOR}${model}`;
|
|
192
|
+
const cached = cache.get(key);
|
|
193
|
+
if (cached !== undefined)
|
|
194
|
+
return cached;
|
|
195
|
+
const llm = ctx.get('llm');
|
|
196
|
+
let capability;
|
|
197
|
+
try {
|
|
198
|
+
const info = await llm?.resolveModelInfo?.(provider, model);
|
|
199
|
+
const efforts = info?.reasoning?.efforts?.map(effort => effort.id) ?? [];
|
|
200
|
+
const posture = piAiPosture(ctx, provider, model, takeoverOf(ctx));
|
|
201
|
+
capability = {
|
|
202
|
+
supportsReasoning: reasoningEffortSupported(info?.reasoning),
|
|
203
|
+
efforts,
|
|
204
|
+
vision: Array.isArray(info?.inputModalities) && info.inputModalities.includes('image'),
|
|
205
|
+
toggleOnly: posture?.thinkingOn === true && posture.supportsEffort === false,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
capability = UNRESOLVABLE_CAPABILITY;
|
|
210
|
+
}
|
|
211
|
+
cache.set(key, capability);
|
|
212
|
+
return capability;
|
|
213
|
+
},
|
|
214
|
+
clear() {
|
|
215
|
+
cache.clear();
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
}
|
|
80
219
|
/**
|
|
81
220
|
* Plugin body.
|
|
82
221
|
* @param ctx - host context carrying the agent-event dispatch.
|
|
@@ -101,6 +240,47 @@ export function apply(ctx, config = DEFAULT_CONFIG) {
|
|
|
101
240
|
// re-registration.
|
|
102
241
|
onChange: () => { },
|
|
103
242
|
});
|
|
243
|
+
// Official-compat bridge (check branch): write the OFFICIAL compat surface
|
|
244
|
+
// into the llm-pi-ai namespace for every provider that targets a custom
|
|
245
|
+
// openai-completions gateway AND declares thinking (reasoningEfforts table):
|
|
246
|
+
// route-level `supportsDeveloperRole: false` plus model-level
|
|
247
|
+
// `thinkingFormat: qwen` on toggle-style thinking rows. This replaces the
|
|
248
|
+
// retired short-circuit route (maintaining the dsh-llm-openai-completions
|
|
249
|
+
// takeover list): since dsh v0.1.0-rc.8 the declarative compat fixes the
|
|
250
|
+
// developer-role 400 AND drives enable_thinking at the pi-ai adapter itself,
|
|
251
|
+
// so pi-ai keeps serving the route and no transport takeover is needed.
|
|
252
|
+
// Storage pattern follows
|
|
253
|
+
// hytime/dsh-thinking-effort's host side: read → pure transform (identity
|
|
254
|
+
// when nothing to change) → whole-section update, so dsh's llm-pi-ai schema
|
|
255
|
+
// validator gates the write where it is WRITTEN; an installed dsh predating
|
|
256
|
+
// rc.8 rejects the unknown field and we log and keep the previous section.
|
|
257
|
+
// The read is lazy and writes are queued by the service, so no race with a
|
|
258
|
+
// concurrent Settings → Models edit.
|
|
259
|
+
let syncTail = Promise.resolve();
|
|
260
|
+
const syncDeveloperRole = () => {
|
|
261
|
+
syncTail = syncTail.then(async () => {
|
|
262
|
+
const settings = ctx.get('settings');
|
|
263
|
+
const piAi = settings?.get?.(PI_AI_NAMESPACE);
|
|
264
|
+
const next = withOfficialCompatFixes(piAi);
|
|
265
|
+
if (next === undefined || next === piAi)
|
|
266
|
+
return;
|
|
267
|
+
await settings?.update?.(PI_AI_NAMESPACE, { providers: next.providers });
|
|
268
|
+
ctx.logger?.info?.('[thinking-levels] official-compat: supportsDeveloperRole=false (route) and thinkingFormat=qwen (toggle-style models) written to llm-pi-ai for custom thinking routes');
|
|
269
|
+
}).catch((error) => {
|
|
270
|
+
ctx.logger?.warn?.('[thinking-levels] developer-role compat sync rejected (schema gate); kept previous section', error);
|
|
271
|
+
});
|
|
272
|
+
};
|
|
273
|
+
// Initial sync (adapters may register later; re-run on every adapters update
|
|
274
|
+
// and every llm-pi-ai settings update so a Settings → Models edit propagates.
|
|
275
|
+
// The write is identity-gated, so the re-entry triggered by our own update
|
|
276
|
+
// settles immediately).
|
|
277
|
+
syncDeveloperRole();
|
|
278
|
+
const onSyncAny = ctx.on;
|
|
279
|
+
onSyncAny('llm/adapters-updated', () => syncDeveloperRole());
|
|
280
|
+
onSyncAny('settings/document-updated', (ns) => {
|
|
281
|
+
if (ns === PI_AI_NAMESPACE)
|
|
282
|
+
syncDeveloperRole();
|
|
283
|
+
});
|
|
104
284
|
// Inject the level decision into every model request of a step.
|
|
105
285
|
// The 'agent/request' event key is augmented onto cordis Events by the
|
|
106
286
|
// dsh-agent runtime's generated scope types; the npm package does not
|
|
@@ -110,41 +290,62 @@ export function apply(ctx, config = DEFAULT_CONFIG) {
|
|
|
110
290
|
// overwrites `reasoningEffort` with the session's selection after `next()`;
|
|
111
291
|
// registering first keeps this plugin's decision OUTERMOST so it runs last.
|
|
112
292
|
const on = ctx.on;
|
|
293
|
+
// Model capability snapshots, cached per provider/model and cleared whenever
|
|
294
|
+
// the adapter registry changes (a route's reasoning metadata can move).
|
|
295
|
+
const capability = capabilityResolver(ctx);
|
|
113
296
|
on('agent/request', async (payload, next) => {
|
|
114
297
|
const seed = await next();
|
|
115
298
|
const cfg = current();
|
|
116
299
|
// `enabled` may flip at runtime through the settings namespace.
|
|
117
300
|
if (!cfg.enabled)
|
|
118
301
|
return seed;
|
|
119
|
-
|
|
120
|
-
//
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
// `auto` mask (or an unset/unknown value): resolve through the plugin's
|
|
125
|
-
// scheduler, falling back to the configured default level.
|
|
126
|
-
const base = selected === 'auto' ? 'auto' : cfg.level;
|
|
302
|
+
// Model-aware guard: never send a reasoning effort to a model that does
|
|
303
|
+
// not advertise one (custom openai-completions routes such as Qwen3.6).
|
|
304
|
+
// Unsupported fields are stripped, not sent; a resolved low/auto schedule
|
|
305
|
+
// only ever reaches models whose metadata admits the level.
|
|
306
|
+
const capabilityFor = await capability.resolve(seed.provider, seed.model);
|
|
127
307
|
const calls = recentToolCalls(payload.agent);
|
|
128
|
-
const
|
|
308
|
+
const decision = resolveEffortInjection({
|
|
309
|
+
supportsReasoning: capabilityFor.supportsReasoning,
|
|
310
|
+
seedEffort: seed.reasoningEffort,
|
|
311
|
+
selected: cfg.level,
|
|
129
312
|
recentCalls: calls,
|
|
130
|
-
selected: base,
|
|
131
313
|
allowDowngrade: cfg.allowDowngrade,
|
|
132
314
|
allowUpgrade: cfg.allowUpgrade,
|
|
315
|
+
efforts: capabilityFor.efforts,
|
|
316
|
+
toggleOnly: capabilityFor.toggleOnly,
|
|
133
317
|
});
|
|
318
|
+
if (!decision.inject) {
|
|
319
|
+
// The model cannot take any effort: drop an inherited one so dsh does
|
|
320
|
+
// not reject the request (UNSUPPORTED_REASONING_EFFORT).
|
|
321
|
+
const stripped = { ...seed };
|
|
322
|
+
delete stripped.reasoningEffort;
|
|
323
|
+
ctx.logger?.info?.('[thinking-levels] agent/request: model=%s/%s has no reasoning effort; stripped', String(seed.provider), String(seed.model));
|
|
324
|
+
return stripped;
|
|
325
|
+
}
|
|
134
326
|
// Summary-only log: individual tool names/arg sizes are workflow metadata
|
|
135
327
|
// that need not land in the host log; count and decision suffice.
|
|
136
|
-
ctx.logger?.info?.('[thinking-levels] agent/request: selected=%s calls=%d => level=%s', String(
|
|
137
|
-
return { ...seed, reasoningEffort: level };
|
|
328
|
+
ctx.logger?.info?.('[thinking-levels] agent/request: model=%s/%s selected=%s calls=%d => level=%s', String(seed.provider), String(seed.model), String(seed.reasoningEffort), calls.length, decision.level);
|
|
329
|
+
return { ...seed, reasoningEffort: decision.level };
|
|
138
330
|
}, { prepend: true });
|
|
139
|
-
// Advertise the `auto` mask
|
|
140
|
-
//
|
|
141
|
-
//
|
|
142
|
-
//
|
|
331
|
+
// Advertise the `auto` mask (and, for configurer-confirmed rc.6-era models,
|
|
332
|
+
// `low`) in the model directory so the session model selector offers them
|
|
333
|
+
// alongside the adapter's native levels. Adapters may register after this
|
|
334
|
+
// plugin's apply (the load order differs between the CLI and DSH Desktop),
|
|
335
|
+
// so the wrapper also re-runs on every `llm/adapters-updated`.
|
|
143
336
|
const llm = ctx.get('llm');
|
|
144
|
-
|
|
337
|
+
const overrideFor = (provider, model) => current().models[`${provider}/${model}`];
|
|
338
|
+
// Read the live llm-pi-ai config for the thinking/effort posture the card
|
|
339
|
+
// wrote there: a model with `reasoningEfforts` but without effort support
|
|
340
|
+
// (Qwen3.6) is collapsed to an On/Off toggle in the selector — but ONLY when
|
|
341
|
+
// the route is taken over by the openai-completions adapter. A pi-ai-served
|
|
342
|
+
// route (e.g. mimo via xiaomi) keeps its native off/high levels.
|
|
343
|
+
const piAiFor = (provider, model) => piAiPosture(ctx, provider, model, takeoverOf(ctx));
|
|
344
|
+
advertiseModelCapability(llm, overrideFor, piAiFor);
|
|
145
345
|
const onAny = ctx.on;
|
|
146
346
|
onAny('llm/adapters-updated', () => {
|
|
147
|
-
|
|
347
|
+
capability.clear();
|
|
348
|
+
advertiseModelCapability(ctx.get('llm'), overrideFor, piAiFor);
|
|
148
349
|
});
|
|
149
350
|
// Per-tool wall-clock telemetry: log tool/call -> tool/result durations.
|
|
150
351
|
// Same boundary widening as above (agent/tool is a generated scope event).
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-flag sync (check branch): bridge from dsh-thinking-levels to the
|
|
3
|
+
* OFFICIAL llm-pi-ai compat surface.
|
|
4
|
+
*
|
|
5
|
+
* CHECK-BRANCH REPLACEMENT: the previous bridge maintained the
|
|
6
|
+
* `llm-openai-completions` takeover list of the dsh-llm-openai-completions
|
|
7
|
+
* adapter plugin (the short-circuit route). Since dsh v0.1.0-rc.8 the official
|
|
8
|
+
* `compat.supportsDeveloperRole` flag (commit 884f7b9c41) fixes the developer
|
|
9
|
+
* role 400 declaratively, so the short-circuit list is no longer needed: the
|
|
10
|
+
* sync now writes the flag into the OFFICIAL `llm-pi-ai` namespace instead.
|
|
11
|
+
*
|
|
12
|
+
* Storage pattern learned from hytime/dsh-thinking-effort's host side
|
|
13
|
+
* (src/host/settings.ts): read the live section → pure transform with
|
|
14
|
+
* immutable clones → `settings.update('llm-pi-ai', { providers })` whole-section
|
|
15
|
+
* writeback, so dsh's `llm-pi-ai` schema validator (assertServiceable) gates
|
|
16
|
+
* the write where it is WRITTEN (settings-rejected names route and model)
|
|
17
|
+
* instead of storing something the reader cannot serve. The flag is written at
|
|
18
|
+
* the ROUTE level (`providers.<route>.compat`) — the official inheritance chain
|
|
19
|
+
* (model → provider → catalog → protocol) means a model-level explicit value
|
|
20
|
+
* still wins, and explicit values are never clobbered by this sync.
|
|
21
|
+
*
|
|
22
|
+
* Identification is unchanged: a provider that (a) targets a custom
|
|
23
|
+
* openai-completions gateway and (b) declares thinking (a reasoningEfforts
|
|
24
|
+
* table) is exactly the route the short-circuit used to take over. Pure
|
|
25
|
+
* functions here are unit-tested; the host plugin wires them to the settings
|
|
26
|
+
* service.
|
|
27
|
+
*
|
|
28
|
+
* Deliberately soft-coupled: nothing here value-imports dsh-settings. If the
|
|
29
|
+
* installed dsh predates rc.8 the schema rejects the unknown field and the
|
|
30
|
+
* host catches and logs the rejection — no error, no log spam.
|
|
31
|
+
* @module dsh-thinking-levels/takeover-sync
|
|
32
|
+
*/
|
|
33
|
+
/** The settings namespace holding the provider/model configs (llm-pi-ai). */
|
|
34
|
+
export declare const PI_AI_NAMESPACE = "llm-pi-ai";
|
|
35
|
+
/** The settings namespace of the retired short-circuit adapter, still READ to gate posture. */
|
|
36
|
+
export declare const TAKEOVER_NAMESPACE = "llm-openai-completions";
|
|
37
|
+
/** One model row of the llm-pi-ai section (minimal face). */
|
|
38
|
+
export interface PiAiModelRow {
|
|
39
|
+
id?: unknown;
|
|
40
|
+
reasoningEfforts?: unknown;
|
|
41
|
+
compat?: unknown;
|
|
42
|
+
}
|
|
43
|
+
/** One provider profile of the llm-pi-ai section (minimal face). */
|
|
44
|
+
export interface PiAiProviderProfile {
|
|
45
|
+
api?: unknown;
|
|
46
|
+
baseURL?: unknown;
|
|
47
|
+
models?: unknown;
|
|
48
|
+
compat?: unknown;
|
|
49
|
+
/** Other profile fields (apiKeyEnv, displayName, …) exist but are unused. */
|
|
50
|
+
[key: string]: unknown;
|
|
51
|
+
}
|
|
52
|
+
/** The llm-pi-ai section slice this module reads and transforms. */
|
|
53
|
+
export interface PiAiSection {
|
|
54
|
+
providers?: Record<string, PiAiProviderProfile>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Whether a provider profile targets a CUSTOM openai-completions gateway:
|
|
58
|
+
* explicit `api: openai-completions`, or a baseURL that is not an official
|
|
59
|
+
* host. Catalog routes without either (e.g. xiaomi via pi-ai discovery) are
|
|
60
|
+
* not custom and are left alone.
|
|
61
|
+
* @param profile - the provider profile slice.
|
|
62
|
+
* @returns true when the route is a custom openai-completions gateway.
|
|
63
|
+
*/
|
|
64
|
+
export declare function isCustomOpenAiGateway(profile: PiAiProviderProfile | undefined): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Whether a provider declares thinking: at least one model row carries a
|
|
67
|
+
* reasoningEfforts table (thinking on). `false` (thinking off) and absent
|
|
68
|
+
* both mean no thinking.
|
|
69
|
+
* @param profile - the provider profile slice.
|
|
70
|
+
* @returns true when any model declares a reasoningEfforts table.
|
|
71
|
+
*/
|
|
72
|
+
export declare function declaresThinking(profile: PiAiProviderProfile | undefined): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Identify the providers that should be taken over by the openai-completions
|
|
75
|
+
* adapter: custom gateway AND thinking declared. Order is stable (the section's
|
|
76
|
+
* own provider order).
|
|
77
|
+
* @param section - the live llm-pi-ai section.
|
|
78
|
+
* @returns the provider ids to add to the takeover list.
|
|
79
|
+
*/
|
|
80
|
+
export declare function identifyTakeoverProviders(section: PiAiSection | undefined): string[];
|
|
81
|
+
/**
|
|
82
|
+
* Compute the llm-pi-ai section with the OFFICIAL compat fixes written for
|
|
83
|
+
* every identified provider (custom openai-completions gateway AND thinking
|
|
84
|
+
* declared):
|
|
85
|
+
*
|
|
86
|
+
* 1. ROUTE level: `compat.supportsDeveloperRole: false` when the route does
|
|
87
|
+
* not carry an explicit value — the system prompt goes out as `system`
|
|
88
|
+
* (fixes the Unexpected message role 400 on vLLM/SGLang gateways).
|
|
89
|
+
* 2. MODEL level: `compat.thinkingFormat: 'qwen-chat-template'` on TOGGLE-STYLE thinking
|
|
90
|
+
* model rows (a reasoningEfforts table, no row-level
|
|
91
|
+
* `supportsReasoningEffort: true`, no explicit thinkingFormat) — pi-ai
|
|
92
|
+
* then sends the `enable_thinking` flag these early vLLM thinking models
|
|
93
|
+
* need, instead of a reasoning_effort they do not support. Effort-capable
|
|
94
|
+
* rows are untouched (their reasoning_effort wire needs the default/openai
|
|
95
|
+
* or declared format), and the route level is deliberately NOT written —
|
|
96
|
+
* a route-wide thinkingFormat would flip effort models onto
|
|
97
|
+
* enable_thinking too.
|
|
98
|
+
*
|
|
99
|
+
* Semantics (learned from dsh-thinking-effort's storage handling):
|
|
100
|
+
* - An EXPLICIT value on any layer is respected and left alone; only ABSENT
|
|
101
|
+
* fields are filled. This keeps the sync idempotent and never overrides
|
|
102
|
+
* user intent.
|
|
103
|
+
* - Immutable: unchanged profiles/rows and the unchanged section are returned
|
|
104
|
+
* by reference, so the host can skip the write on identity.
|
|
105
|
+
* @param section - the live llm-pi-ai section.
|
|
106
|
+
* @returns the next section, or the previous value (identity) when no change.
|
|
107
|
+
*/
|
|
108
|
+
export declare function withOfficialCompatFixes(section: PiAiSection | undefined): PiAiSection | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* The providers the openai-completions adapter is currently set up to take
|
|
111
|
+
* over, from the live `llm-openai-completions` settings namespace. Used to
|
|
112
|
+
* gate thinking-levels' own behavior: a route OUTSIDE the takeover list is
|
|
113
|
+
* served by pi-ai with its native reasoning semantics (off/high visible,
|
|
114
|
+
* pi-ai validates and serializes the effort) and must not be folded into an
|
|
115
|
+
* Off/On toggle or have efforts injected by this plugin.
|
|
116
|
+
* @param section - the live llm-openai-completions section, if registered.
|
|
117
|
+
* @returns the provider ids the adapter will serve, or `null` when the
|
|
118
|
+
* namespace is unregistered (adapter plugin absent).
|
|
119
|
+
*/
|
|
120
|
+
export declare function takeoverProvidersOf(section: {
|
|
121
|
+
enabled?: unknown;
|
|
122
|
+
providers?: unknown;
|
|
123
|
+
} | undefined): string[] | null;
|