dsh-thinking-levels 4.3.3 → 4.4.0

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
@@ -75,6 +75,14 @@ export interface ThinkingLevelsConfig {
75
75
  * flag is the control-layer UI for it.
76
76
  */
77
77
  takeover: boolean | Volatile<boolean>;
78
+ /**
79
+ * UI takeover switch (issues #3/#4): false (default) keeps the official
80
+ * composer model popup — the `auto` mask still arrives through the adapter
81
+ * advertisement below, and the official popup keeps its native search.
82
+ * true seats the plugin's ModelPanel (which carries its own search box and
83
+ * the intent/resolved effort chip).
84
+ */
85
+ takeoverUi: boolean | Volatile<boolean>;
78
86
  /** Configurer-confirmed capability overrides, keyed `provider/model`. */
79
87
  models: Record<string, ModelCapabilityOverride>;
80
88
  /**
@@ -97,6 +105,7 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
97
105
  allowDowngrade: z<boolean, boolean, "volatile-defined">;
98
106
  allowUpgrade: z<boolean, boolean, "volatile-defined">;
99
107
  takeover: z<boolean, boolean, "volatile-defined">;
108
+ takeoverUi: z<boolean, boolean, "volatile-defined">;
100
109
  defaultPricing: z<"estimate" | "cn" | "global" | "custom" | "off", "estimate" | "cn" | "global" | "custom" | "off", "volatile-defined">;
101
110
  models: z<import("@deepseek-ai/cosmokit").Dict<{
102
111
  vision?: boolean | null | undefined;
@@ -115,6 +124,7 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
115
124
  allowDowngrade: z<boolean, boolean, "volatile-defined">;
116
125
  allowUpgrade: z<boolean, boolean, "volatile-defined">;
117
126
  takeover: z<boolean, boolean, "volatile-defined">;
127
+ takeoverUi: z<boolean, boolean, "volatile-defined">;
118
128
  defaultPricing: z<"estimate" | "cn" | "global" | "custom" | "off", "estimate" | "cn" | "global" | "custom" | "off", "volatile-defined">;
119
129
  models: z<import("@deepseek-ai/cosmokit").Dict<{
120
130
  vision?: boolean | null | undefined;
@@ -141,6 +151,7 @@ export declare const LegacyConfig: z<Schemastery.ObjectS<NoInfer<{
141
151
  allowDowngrade: z<boolean, boolean, "defined">;
142
152
  allowUpgrade: z<boolean, boolean, "defined">;
143
153
  takeover: z<boolean, boolean, "defined">;
154
+ takeoverUi: z<boolean, boolean, "defined">;
144
155
  defaultPricing: z<"estimate" | "cn" | "global" | "custom" | "off", "estimate" | "cn" | "global" | "custom" | "off", "defined">;
145
156
  models: z<import("@deepseek-ai/cosmokit").Dict<{
146
157
  vision?: boolean | null | undefined;
@@ -159,6 +170,7 @@ export declare const LegacyConfig: z<Schemastery.ObjectS<NoInfer<{
159
170
  allowDowngrade: z<boolean, boolean, "defined">;
160
171
  allowUpgrade: z<boolean, boolean, "defined">;
161
172
  takeover: z<boolean, boolean, "defined">;
173
+ takeoverUi: z<boolean, boolean, "defined">;
162
174
  defaultPricing: z<"estimate" | "cn" | "global" | "custom" | "off", "estimate" | "cn" | "global" | "custom" | "off", "defined">;
163
175
  models: z<import("@deepseek-ai/cosmokit").Dict<{
164
176
  vision?: boolean | null | undefined;
@@ -191,6 +203,45 @@ declare module '@deepseek-ai/cordis' {
191
203
  * the schema default is the fallback.
192
204
  */
193
205
  export declare function readVolatile<T>(value: T | Volatile<T> | undefined, fallback: T): T;
206
+ /** Minimal face of the llm service's adapter registrations (typed locally to avoid a host-package value import). */
207
+ interface LlmRegistration {
208
+ adapter: {
209
+ resolveModel: (provider: string, model: string, signal?: unknown) => Promise<{
210
+ reasoning?: {
211
+ efforts?: {
212
+ id: string;
213
+ name: string;
214
+ }[];
215
+ };
216
+ }>;
217
+ };
218
+ }
219
+ /**
220
+ * Advertise `auto` (and, for configurer-confirmed rc.6-era models, `low`) in
221
+ * the model directory: wrap every registered adapter's `resolveModel` so the
222
+ * returned `reasoning.efforts` include the extra levels. Idempotent per
223
+ * adapter. `auto` is a mask the plugin resolves per request; `low` is only
224
+ * added when the model override confirms the level, so rc.7+ models (which
225
+ * already advertise low) and unconfirmed models stay untouched.
226
+ *
227
+ * A thinking model WITHOUT effort support (Qwen3.6-style, per the llm-pi-ai
228
+ * config: `reasoningEfforts` present but `compat.supportsReasoningEffort` not
229
+ * true) gets its selector collapsed to a plain On/Off toggle: `off` disables
230
+ * thinking, `on` maps to the `high` level, which pi-ai serializes as
231
+ * `enable_thinking: true` under `thinkingFormat: qwen`. No auto/low masks are
232
+ * offered for these — there is nothing to schedule.
233
+ * @param llm - the resolved `llm` service, when present.
234
+ * @param overrideFor - model override lookup, keyed `provider/model`.
235
+ * @param piAiFor - llm-pi-ai config capability lookup, keyed `provider/model`.
236
+ * (exported for the idempotence regression test, issue #4 — same precedent as
237
+ * `installLegacySection`)
238
+ */
239
+ export declare function advertiseModelCapability(llm: {
240
+ adapters?: Map<string, LlmRegistration>;
241
+ } | undefined, overrideFor: (provider: string, model: string) => ModelCapabilityOverride | undefined, piAiFor: (provider: string, model: string) => {
242
+ thinkingOn: boolean;
243
+ supportsEffort: boolean;
244
+ } | undefined): void;
194
245
  /**
195
246
  * Legacy (≤0.1.6) settings registration: on hosts whose settings service
196
247
  * carries the imperative face (`register` present, `describe` absent), install
@@ -208,3 +259,4 @@ export declare function installLegacySection(ctx: Context, config: ThinkingLevel
208
259
  * @param config - resolved plugin configuration.
209
260
  */
210
261
  export declare function apply(ctx: Context, config?: ThinkingLevelsConfig): void;
262
+ export {};
package/lib/index.js CHANGED
@@ -30,6 +30,7 @@ export const Config = z.object({
30
30
  allowDowngrade: z.boolean().default(true).volatile(),
31
31
  allowUpgrade: z.boolean().default(false).volatile(),
32
32
  takeover: z.boolean().default(false).volatile(),
33
+ takeoverUi: z.boolean().default(false).volatile(),
33
34
  defaultPricing: defaultPricingSchema.volatile(),
34
35
  models: modelsSchema,
35
36
  });
@@ -46,6 +47,7 @@ export const LegacyConfig = z.object({
46
47
  allowDowngrade: z.boolean().default(true),
47
48
  allowUpgrade: z.boolean().default(false),
48
49
  takeover: z.boolean().default(false),
50
+ takeoverUi: z.boolean().default(false),
49
51
  defaultPricing: defaultPricingSchema,
50
52
  models: modelsSchema,
51
53
  });
@@ -56,6 +58,7 @@ export const DEFAULT_CONFIG = {
56
58
  allowDowngrade: true,
57
59
  allowUpgrade: false,
58
60
  takeover: false,
61
+ takeoverUi: false,
59
62
  defaultPricing: 'estimate',
60
63
  models: {},
61
64
  };
@@ -84,6 +87,7 @@ function resolveLiveConfig(config) {
84
87
  allowDowngrade: readVolatile(config.allowDowngrade, true),
85
88
  allowUpgrade: readVolatile(config.allowUpgrade, false),
86
89
  takeover: readVolatile(config.takeover, false),
90
+ takeoverUi: readVolatile(config.takeoverUi, false),
87
91
  defaultPricing: readVolatile(config.defaultPricing, 'estimate'),
88
92
  models: config.models,
89
93
  };
@@ -104,6 +108,15 @@ const AUTO_EFFORT = { id: 'auto', name: 'Auto' };
104
108
  * e.g. via `thinkingFormat: qwen` → enable_thinking + thinking_budget).
105
109
  */
106
110
  const LOW_EFFORT = { id: 'low', name: 'Low' };
111
+ /**
112
+ * Adapters whose `resolveModel` is already wrapped — the per-adapter
113
+ * idempotence issue #4 proves was missing: re-running the advertisement on
114
+ * every `llm/adapters-updated` stacked a new wrapper per pass, and every
115
+ * stacked layer re-ran the post-processing on each resolveModel call.
116
+ * Keyed on the adapter object itself, so a genuinely new adapter is wrapped
117
+ * once and retired ones need no cleanup.
118
+ */
119
+ const advertisedAdapters = new WeakSet();
107
120
  /**
108
121
  * Advertise `auto` (and, for configurer-confirmed rc.6-era models, `low`) in
109
122
  * the model directory: wrap every registered adapter's `resolveModel` so the
@@ -121,10 +134,19 @@ const LOW_EFFORT = { id: 'low', name: 'Low' };
121
134
  * @param llm - the resolved `llm` service, when present.
122
135
  * @param overrideFor - model override lookup, keyed `provider/model`.
123
136
  * @param piAiFor - llm-pi-ai config capability lookup, keyed `provider/model`.
137
+ * (exported for the idempotence regression test, issue #4 — same precedent as
138
+ * `installLegacySection`)
124
139
  */
125
- function advertiseModelCapability(llm, overrideFor, piAiFor) {
140
+ export function advertiseModelCapability(llm, overrideFor, piAiFor) {
126
141
  for (const registration of llm?.adapters?.values() ?? []) {
127
142
  const adapter = registration.adapter;
143
+ // Issue #4: the re-run on every `llm/adapters-updated` must NOT stack
144
+ // wrappers — each stacked layer re-ran the post-processing (and a full
145
+ // describeSettings) on every resolveModel call. This WeakSet is the
146
+ // idempotence the JSDoc has always promised.
147
+ if (advertisedAdapters.has(adapter))
148
+ continue;
149
+ advertisedAdapters.add(adapter);
128
150
  const original = adapter.resolveModel.bind(adapter);
129
151
  adapter.resolveModel = async (provider, model, signal) => {
130
152
  const info = await original(provider, model, signal);
@@ -250,6 +272,19 @@ function capabilityResolver(ctx) {
250
272
  }
251
273
  /** The registered settings namespace of the ≤0.1.6 era. */
252
274
  const THINKING_LEVELS_SETTINGS_NAMESPACE = 'thinking-levels';
275
+ /**
276
+ * The settings namespaces whose commits can move the takeover judgment
277
+ * (issue #4): the transport's `enabled` mirror must not be re-synced through
278
+ * a full describeSettings on EVERY unrelated commit — boot fires many.
279
+ * Includes both transport packaging ids and both own namespaces, so the
280
+ * mirror still re-checks whenever its own inputs move.
281
+ */
282
+ const TAKEOVER_SYNC_NAMESPACES = [
283
+ PI_AI_NAMESPACE,
284
+ ...TAKEOVER_NAMESPACE_CANDIDATES,
285
+ 'dsh-thinking-levels',
286
+ THINKING_LEVELS_SETTINGS_NAMESPACE,
287
+ ];
253
288
  /**
254
289
  * Legacy (≤0.1.6) settings registration: on hosts whose settings service
255
290
  * carries the imperative face (`register` present, `describe` absent), install
@@ -287,6 +322,7 @@ export function installLegacySection(ctx, config, hooks) {
287
322
  allowDowngrade: readVolatile(config.allowDowngrade, true),
288
323
  allowUpgrade: readVolatile(config.allowUpgrade, false),
289
324
  takeover: readVolatile(config.takeover, false),
325
+ takeoverUi: readVolatile(config.takeoverUi, false),
290
326
  models: config.models,
291
327
  };
292
328
  const scope = settings.register(THINKING_LEVELS_SETTINGS_NAMESPACE, LegacyConfig, { base: plainBase });
@@ -413,9 +449,11 @@ export function apply(ctx, config = DEFAULT_CONFIG) {
413
449
  onSyncAny('settings/document-updated', (ns) => {
414
450
  if (ns === PI_AI_NAMESPACE)
415
451
  syncDeveloperRole();
416
- // Any settings commit re-checks the mirror (identity-gated); the write we
417
- // just made re-enters here and settles without a second write.
418
- syncTakeover();
452
+ // The mirror re-checks only where a commit can move the takeover
453
+ // judgment (issue #4); the write it just made re-enters here and
454
+ // settles (identity-gated) without a second write.
455
+ if (TAKEOVER_SYNC_NAMESPACES.includes(ns))
456
+ syncTakeover();
419
457
  });
420
458
  // Inject the level decision into every model request of a step.
421
459
  // The 'agent/request' event key is augmented onto cordis Events by the
@@ -476,8 +514,18 @@ export function apply(ctx, config = DEFAULT_CONFIG) {
476
514
  // (Qwen3.6) is collapsed to an On/Off toggle in the selector — but ONLY when
477
515
  // the route is taken over by the openai-completions transport. A pi-ai-served
478
516
  // route (e.g. mimo via xiaomi) keeps its native off/high levels.
517
+ // Readout cache (issue #4): the resolveModel wrapper runs piAiFor on EVERY
518
+ // model resolution, and a full describeSettings per call made the model
519
+ // page cost O(models × adapters). One readout per generation, invalidated
520
+ // with the capability cache on every settings commit below.
521
+ let readoutCache;
522
+ const cachedReadout = () => {
523
+ if (readoutCache === undefined)
524
+ readoutCache = takeoverReadout(ctx);
525
+ return readoutCache;
526
+ };
479
527
  const piAiFor = (provider, model) => {
480
- const readout = takeoverReadout(ctx);
528
+ const readout = cachedReadout();
481
529
  return piAiPosture(readout.piAi, provider, model, readout.routes);
482
530
  };
483
531
  advertiseModelCapability(llm, overrideFor, piAiFor);
@@ -491,5 +539,6 @@ export function apply(ctx, config = DEFAULT_CONFIG) {
491
539
  // toggle folding follows the new posture on the next request.
492
540
  onAny('settings/document-updated', () => {
493
541
  capability.clear();
542
+ readoutCache = undefined;
494
543
  });
495
544
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-thinking-levels",
3
- "version": "4.3.3",
3
+ "version": "4.4.0",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org",
6
6
  "access": "public",