dsh-thinking-levels 4.1.0-beta.9 → 4.2.0-beta.26

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/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, TAKEOVER_NAMESPACE, takeoverProvidersOf, withOfficialCompatFixes, } from "./takeover-sync.js";
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
- models: z.dict(z.object({
20
- // schemastery fields are optional unless marked `.required()`.
21
- vision: z.boolean(),
22
- thinking: z.boolean(),
23
- efforts: z.union([z.const(false), z.array(effortId)]),
24
- contextWindow: z.number().step(1).min(CONTEXT_WINDOW_MIN).max(CONTEXT_WINDOW_MAX),
25
- })).default({}),
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
- * The providers currently taken over by dsh-llm-openai-completions, read
140
- * lazily from the live `llm-openai-completions` namespace. `null` when the
141
- * namespace is unregistered (adapter plugin absent). Toggle folding and effort
142
- * injection apply only to routes inside this list; everything else keeps
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 takeoverOf(ctx) {
146
- const settings = ctx.get('settings');
147
- const section = settings?.get?.(TAKEOVER_NAMESPACE);
148
- return takeoverProvidersOf(section);
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, read from the live settings namespace
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 adapter (it is in the `llm-openai-completions` list).
159
- * A route OUTSIDE the takeover list is served by pi-ai with its native
160
- * reasoning semantics — off/high stay visible and pi-ai validates the effort —
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(ctx, provider, model, takeover) {
164
- const settings = ctx.get('settings');
165
- const section = settings?.get?.('llm-pi-ai');
166
- const entry = section?.providers?.[provider]?.models?.find(candidate => candidate['id'] === model);
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-list concern: only the openai-completions
175
- // adapter's routes get the Off/On treatment. pi-ai-served routes keep their
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 posture = piAiPosture(ctx, provider, model, takeoverOf(ctx));
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,20 @@ 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: the `.volatile()` fields arrive as live
229
- // refs (DSH 0.1.7+) and are re-read per request, so a committed settings
230
- // change needs no re-registration; `loader/volatile-update` re-validates the
231
- // committed level eagerly instead of failing on the next model request.
232
- const current = () => resolveLiveConfig(config);
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
+ scope.sessionProjections?.register(buildBillingDefinition());
317
+ });
318
+ const current = () => resolveLiveConfig(source());
233
319
  ctx.on('loader/volatile-update', () => {
234
320
  assertEffortId(resolveLiveConfig(config).level, 'dsh-thinking-levels config.level');
321
+ // A flipped takeover switch mirrors immediately (identity-gated).
322
+ syncTakeover();
235
323
  });
236
324
  // Official-compat bridge (check branch): write the OFFICIAL compat surface
237
325
  // into the llm-pi-ai namespace for every provider that targets a custom
@@ -253,7 +341,9 @@ export function apply(ctx, config = DEFAULT_CONFIG) {
253
341
  const syncDeveloperRole = () => {
254
342
  syncTail = syncTail.then(async () => {
255
343
  const settings = ctx.get('settings');
256
- const piAi = settings?.get?.(PI_AI_NAMESPACE);
344
+ // describe() is the only read channel on 0.1.7+ (SettingsForms has no
345
+ // `get`); the section value is the schema-projected live config.
346
+ const piAi = readSection(ctx, PI_AI_NAMESPACE)?.value;
257
347
  const next = withOfficialCompatFixes(piAi);
258
348
  if (next === undefined || next === piAi)
259
349
  return;
@@ -263,16 +353,46 @@ export function apply(ctx, config = DEFAULT_CONFIG) {
263
353
  ctx.logger?.warn?.('[thinking-levels] developer-role compat sync rejected (schema gate); kept previous section', error);
264
354
  });
265
355
  };
356
+ // Takeover mirror: this plugin's `takeover` switch (settings UI) is the
357
+ // control-layer master; the write lands in the transport's OWN section
358
+ // (`llm-openai-completions.enabled`), whose judgment stays single-source.
359
+ // Cross-plugin writes are schema-gated at the write site (the transport's
360
+ // `enabled` is volatile) and never touch its other fields. Writes fire only
361
+ // on divergence (transport absent = nothing to drive), so a manual edit of
362
+ // the transport section survives until the switch is actually flipped again.
363
+ const syncTakeover = () => {
364
+ syncTail = syncTail.then(async () => {
365
+ // Resolve the transport's LIVE namespace from the describe document
366
+ // (the entry id changed shape across its packaging history) — the read
367
+ // and the mirror write land on the same settled id.
368
+ const transport = resolveNamespaceOf(describeSettings(ctx), TAKEOVER_NAMESPACE_CANDIDATES);
369
+ const patch = takeoverPatch(transport?.value, current().takeover);
370
+ if (patch === undefined || transport === undefined)
371
+ return;
372
+ const settings = ctx.get('settings');
373
+ await settings?.update?.(transport.ns, patch);
374
+ ctx.logger?.info?.('[thinking-levels] takeover switch %s written to %s.enabled', String(current().takeover), transport.ns);
375
+ }).catch((error) => {
376
+ ctx.logger?.warn?.('[thinking-levels] takeover mirror write rejected (schema gate); kept previous section', error);
377
+ });
378
+ };
266
379
  // Initial sync (adapters may register later; re-run on every adapters update
267
380
  // and every llm-pi-ai settings update so a Settings → Models edit propagates.
268
381
  // The write is identity-gated, so the re-entry triggered by our own update
269
382
  // settles immediately).
270
383
  syncDeveloperRole();
384
+ syncTakeover();
271
385
  const onSyncAny = ctx.on;
272
- onSyncAny('llm/adapters-updated', () => syncDeveloperRole());
386
+ onSyncAny('llm/adapters-updated', () => {
387
+ syncDeveloperRole();
388
+ syncTakeover();
389
+ });
273
390
  onSyncAny('settings/document-updated', (ns) => {
274
391
  if (ns === PI_AI_NAMESPACE)
275
392
  syncDeveloperRole();
393
+ // Any settings commit re-checks the mirror (identity-gated); the write we
394
+ // just made re-enters here and settles without a second write.
395
+ syncTakeover();
276
396
  });
277
397
  // Inject the level decision into every model request of a step.
278
398
  // The 'agent/request' event key is augmented onto cordis Events by the
@@ -331,13 +451,22 @@ export function apply(ctx, config = DEFAULT_CONFIG) {
331
451
  // Read the live llm-pi-ai config for the thinking/effort posture the card
332
452
  // wrote there: a model with `reasoningEfforts` but without effort support
333
453
  // (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 adapter. A pi-ai-served
454
+ // the route is taken over by the openai-completions transport. A pi-ai-served
335
455
  // route (e.g. mimo via xiaomi) keeps its native off/high levels.
336
- const piAiFor = (provider, model) => piAiPosture(ctx, provider, model, takeoverOf(ctx));
456
+ const piAiFor = (provider, model) => {
457
+ const readout = takeoverReadout(ctx);
458
+ return piAiPosture(readout.piAi, provider, model, readout.routes);
459
+ };
337
460
  advertiseModelCapability(llm, overrideFor, piAiFor);
338
461
  const onAny = ctx.on;
339
462
  onAny('llm/adapters-updated', () => {
340
463
  capability.clear();
341
464
  advertiseModelCapability(ctx.get('llm'), overrideFor, piAiFor);
342
465
  });
466
+ // A settings commit can flip the takeover judgment (the transport's enabled
467
+ // flag or the llm-pi-ai routes): drop the cached capability snapshots so
468
+ // toggle folding follows the new posture on the next request.
469
+ onAny('settings/document-updated', () => {
470
+ capability.clear();
471
+ });
343
472
  }
@@ -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
+ }
@@ -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
- /** The settings namespace of the retired short-circuit adapter, still READ to gate posture. */
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 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).
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 takeoverProvidersOf(section: {
146
+ export declare function takeoverRoutesOf(section: {
121
147
  enabled?: unknown;
122
148
  providers?: unknown;
123
149
  } | undefined): string[] | null;
@@ -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
- /** The settings namespace of the retired short-circuit adapter, still READ to gate posture. */
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 providers the openai-completions adapter is currently set up to take
220
- * over, from the live `llm-openai-completions` settings namespace. Used to
221
- * gate thinking-levels' own behavior: a route OUTSIDE the takeover list is
222
- * served by pi-ai with its native reasoning semantics (off/high visible,
223
- * pi-ai validates and serializes the effort) and must not be folded into an
224
- * Off/On toggle or have efforts injected by this plugin.
225
- * @param section - the live llm-openai-completions section, if registered.
226
- * @returns the provider ids the adapter will serve, or `null` when the
227
- * namespace is unregistered (adapter plugin absent).
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 takeoverProvidersOf(section) {
259
+ export function takeoverRoutesOf(section) {
230
260
  if (section === undefined)
231
261
  return null;
232
262
  if (section.enabled !== true)