dsh-thinking-levels 4.4.4 → 4.4.7

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
@@ -23,12 +23,14 @@
23
23
  * - `agent/request` waterfall (packages/core/agent-loop/src/agent.ts
24
24
  * buildRequest): each listener may return a modified GenerateOptions for
25
25
  * the next listener — the sanctioned way to adjust request config.
26
- * - `session.events` (agent.session) carries the step's tool/call records; the
27
- * auto scheduler PULLS the recent calls from there at request time
28
- * (`recentToolCalls`). There is no `agent/tool` push event in DSH — the
29
- * scope-event registry (`packages/core/scope/src/scoped-events.generated.ts`)
30
- * lists no such name in 0.1.1-rc.2 or 0.1.2-rc.1, so tool recognition must
31
- * stay a pull from `session.events`.
26
+ * - `session.events` (agent.session) carried the step's tool/call records up to
27
+ * host 0.1.0-rc.8 only; from 0.1.2-rc.1 on the log is read through the
28
+ * projection registry instead (`tlAutoSchedule`, issue #6). The deprecated
29
+ * synchronous readers (`eventAt/snapshotEvents/ownEvents`) are prohibited for
30
+ * new production calls by `packages/core/session/README.md:62`.
31
+ * - The session's EXPLICIT effort pick is folded from `model/selection` events:
32
+ * the host seeds `reasoningEffort` from the previous request header (this
33
+ * plugin's own output), so the seed must never be read as a manual pick.
32
34
  * - declarative settings (DSH 0.1.7+): the runtime-adjustable `Config` fields
33
35
  * are marked `.volatile()`, the host generates the settings form from the
34
36
  * schema alone, and the plugin reads the live values per request.
@@ -38,6 +40,7 @@ import type { Volatile } from '@deepseek-ai/cosmokit';
38
40
  import z from '@deepseek-ai/schemastery';
39
41
  import { type EffortId } from './thinking-level.ts';
40
42
  import { type PricingPolicy } from './billing-projection.ts';
43
+ import { type PiAiSection } from './takeover-sync.ts';
41
44
  /** One configurer-confirmed capability override for a `provider/model` key. */
42
45
  export interface ModelCapabilityOverride {
43
46
  /** Manual override of the vision-model classification (auto: inputModalities). */
@@ -106,7 +109,7 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
106
109
  allowUpgrade: z<boolean, boolean, "volatile-defined">;
107
110
  takeover: z<boolean, boolean, "volatile-defined">;
108
111
  takeoverUi: z<boolean, boolean, "volatile-defined">;
109
- defaultPricing: z<"estimate" | "cn" | "global" | "custom" | "off", "estimate" | "cn" | "global" | "custom" | "off", "volatile-defined">;
112
+ defaultPricing: z<"off" | "custom" | "estimate" | "cn" | "global", "off" | "custom" | "estimate" | "cn" | "global", "volatile-defined">;
110
113
  models: z<import("@deepseek-ai/cosmokit").Dict<{
111
114
  vision?: boolean | null | undefined;
112
115
  thinking?: boolean | null | undefined;
@@ -125,7 +128,7 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
125
128
  allowUpgrade: z<boolean, boolean, "volatile-defined">;
126
129
  takeover: z<boolean, boolean, "volatile-defined">;
127
130
  takeoverUi: z<boolean, boolean, "volatile-defined">;
128
- defaultPricing: z<"estimate" | "cn" | "global" | "custom" | "off", "estimate" | "cn" | "global" | "custom" | "off", "volatile-defined">;
131
+ defaultPricing: z<"off" | "custom" | "estimate" | "cn" | "global", "off" | "custom" | "estimate" | "cn" | "global", "volatile-defined">;
129
132
  models: z<import("@deepseek-ai/cosmokit").Dict<{
130
133
  vision?: boolean | null | undefined;
131
134
  thinking?: boolean | null | undefined;
@@ -152,7 +155,7 @@ export declare const LegacyConfig: z<Schemastery.ObjectS<NoInfer<{
152
155
  allowUpgrade: z<boolean, boolean, "defined">;
153
156
  takeover: z<boolean, boolean, "defined">;
154
157
  takeoverUi: z<boolean, boolean, "defined">;
155
- defaultPricing: z<"estimate" | "cn" | "global" | "custom" | "off", "estimate" | "cn" | "global" | "custom" | "off", "defined">;
158
+ defaultPricing: z<"off" | "custom" | "estimate" | "cn" | "global", "off" | "custom" | "estimate" | "cn" | "global", "defined">;
156
159
  models: z<import("@deepseek-ai/cosmokit").Dict<{
157
160
  vision?: boolean | null | undefined;
158
161
  thinking?: boolean | null | undefined;
@@ -171,7 +174,7 @@ export declare const LegacyConfig: z<Schemastery.ObjectS<NoInfer<{
171
174
  allowUpgrade: z<boolean, boolean, "defined">;
172
175
  takeover: z<boolean, boolean, "defined">;
173
176
  takeoverUi: z<boolean, boolean, "defined">;
174
- defaultPricing: z<"estimate" | "cn" | "global" | "custom" | "off", "estimate" | "cn" | "global" | "custom" | "off", "defined">;
177
+ defaultPricing: z<"off" | "custom" | "estimate" | "cn" | "global", "off" | "custom" | "estimate" | "cn" | "global", "defined">;
175
178
  models: z<import("@deepseek-ai/cosmokit").Dict<{
176
179
  vision?: boolean | null | undefined;
177
180
  thinking?: boolean | null | undefined;
@@ -242,6 +245,30 @@ export declare function advertiseModelCapability(llm: {
242
245
  thinkingOn: boolean;
243
246
  supportsEffort: boolean;
244
247
  } | undefined): void;
248
+ /**
249
+ * The llm-pi-ai posture of one model, from the live llm-pi-ai section
250
+ * (the capability card writes `reasoningEfforts` and `compat` there). Absent
251
+ * when the route/model is not configured.
252
+ *
253
+ * A model is toggle-only (Off/On, no effort levels) only when ALL THREE hold:
254
+ * the model declares a thinking toggle (reasoningEfforts table, no
255
+ * supportsReasoningEffort), the route is taken over by the transport (it is in
256
+ * the takeover judgment), AND the route speaks the openai-completions wire
257
+ * protocol. The Off/On fold exists because a completions toggle model rejects
258
+ * any `reasoning_effort` string pi-ai does not resolve to its fixed seven
259
+ * levels; that physical reason does NOT apply to a Responses/Anthropic route,
260
+ * whose levels pi-ai maps natively (thinking budget / reasoning-effort enum)
261
+ * and whose `supportsReasoningEffort` compat field the host refuses to write
262
+ * at all (4.4.4). Folding such a route would silently strip the configured
263
+ * level set down to Off/On. A route OUTSIDE the takeover judgment is likewise
264
+ * served by pi-ai with its native reasoning semantics and is NOT folded here.
265
+ * (exported for the protocol-gate regression, issue #9 — same precedent as
266
+ * `advertiseModelCapability`)
267
+ */
268
+ export declare function piAiPosture(piAi: PiAiSection | undefined, provider: string, model: string, takeover: string[] | null): {
269
+ thinkingOn: boolean;
270
+ supportsEffort: boolean;
271
+ } | undefined;
245
272
  /**
246
273
  * Legacy (≤0.1.6) settings registration: on hosts whose settings service
247
274
  * carries the imperative face (`register` present, `describe` absent), install
package/lib/index.js CHANGED
@@ -2,6 +2,7 @@ import z from '@deepseek-ai/schemastery';
2
2
  import { assertEffortId, reasoningEffortSupported, resolveEffortInjection } from "./thinking-level.js";
3
3
  import { buildBillingDefinition } from "./billing-projection.js";
4
4
  import { recentToolCalls } from "./session-events.js";
5
+ import { buildAutoScheduleDefinition, readAutoSchedule, requestedEffortOf } from "./auto-schedule-projection.js";
5
6
  import { CONTEXT_WINDOW_MAX, CONTEXT_WINDOW_MIN } from "./context-window.js";
6
7
  import { PI_AI_NAMESPACE, TAKEOVER_NAMESPACE_CANDIDATES, takeoverPatch, takeoverRoutesOf, withOfficialCompatFixes, } from "./takeover-sync.js";
7
8
  import { describeSettings, readSection, readSectionOf, resolveNamespaceOf } from "./settings-read.js";
@@ -205,17 +206,25 @@ function takeoverReadout(ctx) {
205
206
  * (the capability card writes `reasoningEfforts` and `compat` there). Absent
206
207
  * when the route/model is not configured.
207
208
  *
208
- * A model is toggle-only (Off/On, no effort levels) only when BOTH the model
209
- * declares a thinking toggle (reasoningEfforts table, no
210
- * supportsReasoningEffort) AND the route is taken over by the
211
- * openai-completions transport (it is in the takeover judgment). A route
212
- * OUTSIDE the takeover judgment is served by pi-ai with its native
213
- * reasoning semantics — off/high stay visible and pi-ai validates the
214
- * effort — so it is NOT folded into a toggle here.
209
+ * A model is toggle-only (Off/On, no effort levels) only when ALL THREE hold:
210
+ * the model declares a thinking toggle (reasoningEfforts table, no
211
+ * supportsReasoningEffort), the route is taken over by the transport (it is in
212
+ * the takeover judgment), AND the route speaks the openai-completions wire
213
+ * protocol. The Off/On fold exists because a completions toggle model rejects
214
+ * any `reasoning_effort` string pi-ai does not resolve to its fixed seven
215
+ * levels; that physical reason does NOT apply to a Responses/Anthropic route,
216
+ * whose levels pi-ai maps natively (thinking budget / reasoning-effort enum)
217
+ * and whose `supportsReasoningEffort` compat field the host refuses to write
218
+ * at all (4.4.4). Folding such a route would silently strip the configured
219
+ * level set down to Off/On. A route OUTSIDE the takeover judgment is likewise
220
+ * served by pi-ai with its native reasoning semantics and is NOT folded here.
221
+ * (exported for the protocol-gate regression, issue #9 — same precedent as
222
+ * `advertiseModelCapability`)
215
223
  */
216
- function piAiPosture(piAi, provider, model, takeover) {
217
- const rows = Array.isArray(piAi?.providers?.[provider]?.models)
218
- ? piAi.providers[provider].models
224
+ export function piAiPosture(piAi, provider, model, takeover) {
225
+ const profile = piAi?.providers?.[provider];
226
+ const rows = Array.isArray(profile?.models)
227
+ ? profile.models
219
228
  : [];
220
229
  const entry = rows.find(candidate => candidate['id'] === model);
221
230
  if (entry === undefined)
@@ -225,11 +234,17 @@ function piAiPosture(piAi, provider, model, takeover) {
225
234
  const thinkingOn = typeof efforts === 'object' && efforts !== null && !Array.isArray(efforts);
226
235
  const supportsEffort = typeof compat === 'object' && compat !== null
227
236
  && compat['supportsReasoningEffort'] === true;
228
- // Toggle folding is a takeover-judgment concern: only the openai-completions
229
- // transport's routes get the Off/On treatment. pi-ai-served routes keep their
230
- // native effort levels (off/high visible).
237
+ // Toggle folding is a takeover-judgment concern AND an openai-completions
238
+ // concern: only a taken-over completions route gets the Off/On treatment.
239
+ // The transport is named `dsh-llm-openai-completions` but since the 4.4.x
240
+ // line fronts three protocols; a Responses/Anthropic route keeps its native
241
+ // effort levels (the table drives pi-ai's thinkingLevelMap). An absent `api`
242
+ // keeps pi-ai's openai-completions default, so it stays foldable — the same
243
+ // predicate as the card's `completionsCompatConfigurable`.
244
+ const api = profile?.api;
245
+ const isCompletions = typeof api !== 'string' || api === 'openai-completions';
231
246
  const toggled = takeover !== null && takeover.includes(provider);
232
- return { thinkingOn: thinkingOn && toggled, supportsEffort };
247
+ return { thinkingOn: thinkingOn && toggled && isCompletions, supportsEffort };
233
248
  }
234
249
  const CAPABILITY_CACHE_KEY_SEPARATOR = '\u0000';
235
250
  /** A model that cannot be resolved is treated as non-reasoning: never inject. */
@@ -375,6 +390,17 @@ export function apply(ctx, config = DEFAULT_CONFIG) {
375
390
  }
376
391
  });
377
392
  const current = () => resolveLiveConfig(source());
393
+ ctx.inject?.(['sessionProjections'], (scope) => {
394
+ const registry = scope.sessionProjections;
395
+ if (typeof registry?.stateOf !== 'function' || typeof registry.register !== 'function')
396
+ return;
397
+ try {
398
+ registry.register(buildAutoScheduleDefinition());
399
+ }
400
+ catch (error) {
401
+ console.warn(`[dsh-thinking-levels] tlAutoSchedule register failed (auto falls back to the legacy read): ${error instanceof Error ? error.message : String(error)}`);
402
+ }
403
+ });
378
404
  ctx.on('loader/volatile-update', () => {
379
405
  assertEffortId(resolveLiveConfig(config).level, 'dsh-thinking-levels config.level');
380
406
  // A flipped takeover switch mirrors immediately (identity-gated).
@@ -478,11 +504,18 @@ export function apply(ctx, config = DEFAULT_CONFIG) {
478
504
  // Unsupported fields are stripped, not sent; a resolved low/auto schedule
479
505
  // only ever reaches models whose metadata admits the level.
480
506
  const capabilityFor = await capability.resolve(seed.provider, seed.model);
481
- const calls = recentToolCalls(payload.agent);
507
+ // Folded projection state (issue #6): recent tool samples + the session's
508
+ // explicit pick. `undefined` on registries without `stateOf` (0.1.0-rc.8).
509
+ const session = payload.agent?.session;
510
+ const autoSchedule = readAutoSchedule(ctx, session);
511
+ const calls = autoSchedule?.samples ?? recentToolCalls(payload.agent);
512
+ // Intent comes from the session/config, never from the seed: the host
513
+ // echoes this plugin's own last injection back through the header.
514
+ const requested = requestedEffortOf(autoSchedule, cfg.level);
482
515
  const decision = resolveEffortInjection({
483
516
  supportsReasoning: capabilityFor.supportsReasoning,
517
+ requested,
484
518
  seedEffort: seed.reasoningEffort,
485
- selected: cfg.level,
486
519
  recentCalls: calls,
487
520
  allowDowngrade: cfg.allowDowngrade,
488
521
  allowUpgrade: cfg.allowUpgrade,
@@ -498,8 +531,11 @@ export function apply(ctx, config = DEFAULT_CONFIG) {
498
531
  return stripped;
499
532
  }
500
533
  // Summary-only log: individual tool names/arg sizes are workflow metadata
501
- // that need not land in the host log; count and decision suffice.
502
- 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);
534
+ // that need not land in the host log; count and decision suffice. `user=`
535
+ // and `src=` make the runtime proof for issue #6 readable: a healthy
536
+ // session shows `src=projection`, `calls>0` after tool activity, and
537
+ // `user=auto` on every request after the first.
538
+ ctx.logger?.info?.('[thinking-levels] agent/request: model=%s/%s user=%s seed=%s calls=%d => level=%s src=%s', String(seed.provider), String(seed.model), String(requested), String(seed.reasoningEffort), calls.length, decision.level, autoSchedule === undefined ? 'legacy' : 'projection');
503
539
  return { ...seed, reasoningEffort: decision.level };
504
540
  }, { prepend: true });
505
541
  // Advertise the `auto` mask (and, for configurer-confirmed rc.6-era models,
@@ -1,19 +1,36 @@
1
1
  /**
2
2
  * Session tool-call sampling for dsh-thinking-levels.
3
3
  *
4
- * Pulled out of the plugin body so the extraction logic — the part most
5
- * exposed to dsh event-shape drift — is unit-testable in isolation, with
6
- * explicit guards instead of naked type assertions. If a future dsh version
7
- * reshapes `session.events`, the failure shows up in the tests, not as a
8
- * silently wrong effort decision.
4
+ * Two readers, one extraction:
5
+ * - {@link toolSampleOf} normalizes a single raw Session event and is shared
6
+ * with the `tlAutoSchedule` projection (`auto-schedule-projection.ts`), so
7
+ * the `tool/call` wire shape lives in exactly one place.
8
+ * - {@link recentToolCalls} is the LEGACY pull path. `session.events` only
9
+ * ever existed on hosts up to 0.1.0-rc.8 (verified: `get events()` present at
10
+ * `dsh-v0.1.0-rc.8`, zero hits from `dsh-v0.1.2-rc.1` on), so on every newer
11
+ * line it returns `[]` — which is exactly the issue #6 defect. It survives
12
+ * only as the 0.1.0-rc.8 fallback for hosts whose projection registry
13
+ * predates `stateOf`.
9
14
  */
10
15
  import type { ToolCallSample } from './thinking-level.ts';
11
16
  /** How many recent tool calls to sample for one decision. */
12
17
  export declare const TOOL_SAMPLE_WINDOW = 8;
18
+ /** Approximate argument size in characters (payload heft); unknown shapes read as 0. */
19
+ export declare function argsSizeOf(argumentsValue: unknown): number;
13
20
  /**
14
- * Recent tool calls of a session's current step, oldest first.
15
- * Non-tool events and malformed records are skipped; at most
16
- * {@link TOOL_SAMPLE_WINDOW} samples are returned.
21
+ * Normalize one raw Session event into a tool-call sample.
22
+ *
23
+ * @param event - any committed Session event.
24
+ * @returns the sample, or undefined for any other event / malformed record.
25
+ */
26
+ export declare function toolSampleOf(event: unknown): ToolCallSample | undefined;
27
+ /**
28
+ * LEGACY: recent tool calls off `agent.session.events`, oldest first.
29
+ *
30
+ * Only 0.1.0-rc.8 carries that array property; every host from 0.1.2-rc.1 on
31
+ * drops it in favour of `eventAt()/snapshotEvents()/ownEvents()`, so this
32
+ * returns `[]` there. Callers must treat `[]` as "no samples available" and
33
+ * prefer the projection read.
17
34
  *
18
35
  * @param agent - the `payload.agent` value from the `agent/request` waterfall.
19
36
  * @returns the sampled tool calls, or `[]` for a fresh prompt / unknown shape.
@@ -1,11 +1,16 @@
1
1
  /**
2
2
  * Session tool-call sampling for dsh-thinking-levels.
3
3
  *
4
- * Pulled out of the plugin body so the extraction logic — the part most
5
- * exposed to dsh event-shape drift — is unit-testable in isolation, with
6
- * explicit guards instead of naked type assertions. If a future dsh version
7
- * reshapes `session.events`, the failure shows up in the tests, not as a
8
- * silently wrong effort decision.
4
+ * Two readers, one extraction:
5
+ * - {@link toolSampleOf} normalizes a single raw Session event and is shared
6
+ * with the `tlAutoSchedule` projection (`auto-schedule-projection.ts`), so
7
+ * the `tool/call` wire shape lives in exactly one place.
8
+ * - {@link recentToolCalls} is the LEGACY pull path. `session.events` only
9
+ * ever existed on hosts up to 0.1.0-rc.8 (verified: `get events()` present at
10
+ * `dsh-v0.1.0-rc.8`, zero hits from `dsh-v0.1.2-rc.1` on), so on every newer
11
+ * line it returns `[]` — which is exactly the issue #6 defect. It survives
12
+ * only as the 0.1.0-rc.8 fallback for hosts whose projection registry
13
+ * predates `stateOf`.
9
14
  */
10
15
  /** How many recent tool calls to sample for one decision. */
11
16
  export const TOOL_SAMPLE_WINDOW = 8;
@@ -19,13 +24,29 @@ function isToolCallEvent(event) {
19
24
  return isRecord(event.data);
20
25
  }
21
26
  /** Approximate argument size in characters (payload heft); unknown shapes read as 0. */
22
- function argsSizeOf(argumentsValue) {
27
+ export function argsSizeOf(argumentsValue) {
23
28
  return typeof argumentsValue === 'string' ? argumentsValue.length : 0;
24
29
  }
25
30
  /**
26
- * Recent tool calls of a session's current step, oldest first.
27
- * Non-tool events and malformed records are skipped; at most
28
- * {@link TOOL_SAMPLE_WINDOW} samples are returned.
31
+ * Normalize one raw Session event into a tool-call sample.
32
+ *
33
+ * @param event - any committed Session event.
34
+ * @returns the sample, or undefined for any other event / malformed record.
35
+ */
36
+ export function toolSampleOf(event) {
37
+ if (!isToolCallEvent(event))
38
+ return undefined;
39
+ const data = event.data;
40
+ const name = typeof data.name === 'string' && data.name.length > 0 ? data.name : 'tool';
41
+ return { name, argsSize: argsSizeOf(data.arguments) };
42
+ }
43
+ /**
44
+ * LEGACY: recent tool calls off `agent.session.events`, oldest first.
45
+ *
46
+ * Only 0.1.0-rc.8 carries that array property; every host from 0.1.2-rc.1 on
47
+ * drops it in favour of `eventAt()/snapshotEvents()/ownEvents()`, so this
48
+ * returns `[]` there. Callers must treat `[]` as "no samples available" and
49
+ * prefer the projection read.
29
50
  *
30
51
  * @param agent - the `payload.agent` value from the `agent/request` waterfall.
31
52
  * @returns the sampled tool calls, or `[]` for a fresh prompt / unknown shape.
@@ -38,12 +59,9 @@ export function recentToolCalls(agent) {
38
59
  return [];
39
60
  const samples = [];
40
61
  for (let index = session.events.length - 1; index >= 0 && samples.length < TOOL_SAMPLE_WINDOW; index -= 1) {
41
- const event = session.events[index];
42
- if (!isToolCallEvent(event))
43
- continue;
44
- const data = event.data;
45
- const name = typeof data.name === 'string' && data.name.length > 0 ? data.name : 'tool';
46
- samples.push({ name, argsSize: argsSizeOf(data.arguments) });
62
+ const sample = toolSampleOf(session.events[index]);
63
+ if (sample !== undefined)
64
+ samples.push(sample);
47
65
  }
48
66
  return samples.reverse();
49
67
  }
@@ -88,10 +88,24 @@ export declare function reasoningEffortSupported(reasoning: unknown): boolean;
88
88
  export interface EffortInjectionInput {
89
89
  /** Whether the target model advertises reasoning-effort support. */
90
90
  supportsReasoning: boolean;
91
- /** The `reasoningEffort` already present on the request seed, if any. */
91
+ /**
92
+ * The level this request was ASKED for: the session's explicit pick (folded
93
+ * from `model/selection`) when present, else the plugin-configured default.
94
+ *
95
+ * Never derive this from the request seed. From dsh 0.1.2-rc.1 on, the host
96
+ * seeds `reasoningEffort` from the previous `request/header` — which is this
97
+ * plugin's own output (`core/agent-loop/src/agent.ts:573-581`). Reading it as
98
+ * a manual pick made `auto` resolve once and then stay frozen for the rest of
99
+ * the session (issue #6, bug 2).
100
+ */
101
+ requested: EffortId;
102
+ /**
103
+ * The `reasoningEffort` already present on the request seed (host echo of a
104
+ * previous header, or route inheritance). Used ONLY to recognise the `on`
105
+ * toggle and to strip an inherited effort from a model that cannot take one —
106
+ * never as a manual-pick signal.
107
+ */
92
108
  seedEffort: unknown;
93
- /** Plugin-configured default level when the seed carries none. */
94
- selected: EffortId;
95
109
  /** Recent tool calls of the step, for the auto scheduler. */
96
110
  recentCalls: readonly ToolCallSample[];
97
111
  /** Scheduler preference: allow the scheduler to drop below `high`. */
@@ -133,18 +147,21 @@ export declare function clampToEfforts(level: EffortId, efforts: readonly string
133
147
  * - A model without reasoning support never receives the field: dsh would
134
148
  * throw UNSUPPORTED_REASONING_EFFORT, so the seed's inherited effort (from a
135
149
  * previous route or session header) is stripped.
136
- * - A manual wire selection passes through unchanged when the model advertises
137
- * it; an unsupported manual pick is stripped rather than clamped (the user
138
- * asked for that exact level).
150
+ * - A manual wire selection (`requested`) passes through unchanged when the
151
+ * model advertises it; an unsupported manual pick is stripped rather than
152
+ * clamped (the user asked for that exact level).
139
153
  * - `on` is the enable-thinking toggle, never a wire level: on a toggle-only
140
154
  * model it injects the advertised thinking level (`high`), which the wire
141
155
  * serializes as enable_thinking without a reasoning_effort; an
142
156
  * effort-capable model does not advertise `on`, so it is stripped.
143
- * - `auto` (or no selection) resolves through the scheduler; the result is
144
- * clamped to the model's advertised levels, so a scheduled `low` on a model
145
- * that only takes off/high (Qwen3.6) becomes `high` instead of an error.
157
+ * - `auto` resolves through the scheduler; the result is clamped to the
158
+ * model's advertised levels, so a scheduled `low` on a model that only takes
159
+ * off/high (Qwen3.6) becomes `high` instead of an error.
160
+ *
161
+ * The manual/auto branch reads `requested` only. The seed no longer influences
162
+ * it, so a header echoed back by the host cannot masquerade as a user pick.
146
163
  *
147
- * @param input - model capability plus the seed's current effort.
164
+ * @param input - model capability plus the requested level and the seed's effort.
148
165
  * @returns whether to inject and the level to set.
149
166
  */
150
167
  export declare function resolveEffortInjection(input: EffortInjectionInput): EffortInjectionDecision;
@@ -147,50 +147,53 @@ export function clampToEfforts(level, efforts) {
147
147
  * - A model without reasoning support never receives the field: dsh would
148
148
  * throw UNSUPPORTED_REASONING_EFFORT, so the seed's inherited effort (from a
149
149
  * previous route or session header) is stripped.
150
- * - A manual wire selection passes through unchanged when the model advertises
151
- * it; an unsupported manual pick is stripped rather than clamped (the user
152
- * asked for that exact level).
150
+ * - A manual wire selection (`requested`) passes through unchanged when the
151
+ * model advertises it; an unsupported manual pick is stripped rather than
152
+ * clamped (the user asked for that exact level).
153
153
  * - `on` is the enable-thinking toggle, never a wire level: on a toggle-only
154
154
  * model it injects the advertised thinking level (`high`), which the wire
155
155
  * serializes as enable_thinking without a reasoning_effort; an
156
156
  * effort-capable model does not advertise `on`, so it is stripped.
157
- * - `auto` (or no selection) resolves through the scheduler; the result is
158
- * clamped to the model's advertised levels, so a scheduled `low` on a model
159
- * that only takes off/high (Qwen3.6) becomes `high` instead of an error.
157
+ * - `auto` resolves through the scheduler; the result is clamped to the
158
+ * model's advertised levels, so a scheduled `low` on a model that only takes
159
+ * off/high (Qwen3.6) becomes `high` instead of an error.
160
160
  *
161
- * @param input - model capability plus the seed's current effort.
161
+ * The manual/auto branch reads `requested` only. The seed no longer influences
162
+ * it, so a header echoed back by the host cannot masquerade as a user pick.
163
+ *
164
+ * @param input - model capability plus the requested level and the seed's effort.
162
165
  * @returns whether to inject and the level to set.
163
166
  */
164
167
  export function resolveEffortInjection(input) {
165
- const { supportsReasoning, seedEffort, selected, efforts, toggleOnly } = input;
168
+ const { supportsReasoning, requested, efforts, toggleOnly } = input;
166
169
  if (!supportsReasoning)
167
170
  return { inject: false };
168
171
  if (toggleOnly) {
169
172
  // Toggle-only model (Qwen3.6 / mimo-v2.5 style): thinking is an on/off
170
173
  // switch expressed through the provider's enable_thinking semantics.
171
174
  // - Off → inject `off`: the provider maps it to thinking disabled.
172
- // - On / any other seed → inject `high` (the advertised toggle level): the
173
- // short-circuit adapter serializes a non-off effort as enable_thinking
174
- // true — an explicit "thinking on" signal the wire needs. (A request
175
- // with NO effort at all is the ambiguous case: leaving it absent relies
176
- // on the provider default, which some gateways treat as off.)
177
- return { inject: true, level: seedEffort === 'off' ? 'off' : 'high' };
175
+ // - On / any other request → inject `high` (the advertised toggle level):
176
+ // the short-circuit adapter serializes a non-off effort as
177
+ // enable_thinking true — an explicit "thinking on" signal the wire needs.
178
+ // (A request with NO effort at all is the ambiguous case: leaving it
179
+ // absent relies on the provider default, which some gateways read as off.)
180
+ return { inject: true, level: requested === 'off' ? 'off' : 'high' };
178
181
  }
179
- if (seedEffort === 'on') {
182
+ if (requested === 'on' || input.seedEffort === 'on') {
180
183
  // A stray On on an effort-capable model: never a wire level, stripped.
181
184
  return { inject: false };
182
185
  }
183
- if (isEffortId(seedEffort) && seedEffort !== 'auto') {
186
+ if (requested !== 'auto') {
184
187
  // A manual pick is the user asking for that exact level: pass it through
185
188
  // only when the model advertises it, strip it otherwise (no clamping of an
186
189
  // explicit choice).
187
- return efforts.includes(seedEffort)
188
- ? { inject: true, level: seedEffort }
190
+ return efforts.includes(requested)
191
+ ? { inject: true, level: requested }
189
192
  : { inject: false };
190
193
  }
191
194
  const level = decideEffort({
192
195
  recentCalls: input.recentCalls,
193
- selected: seedEffort === 'auto' ? 'auto' : selected,
196
+ selected: 'auto',
194
197
  allowDowngrade: input.allowDowngrade,
195
198
  allowUpgrade: input.allowUpgrade,
196
199
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-thinking-levels",
3
- "version": "4.4.4",
3
+ "version": "4.4.7",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org",
6
6
  "access": "public",
@@ -61,17 +61,17 @@
61
61
  },
62
62
  "engines": {
63
63
  "node": ">=22.19.0 || >=24.0.0",
64
- "dsh": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2"
64
+ "dsh": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3"
65
65
  },
66
66
  "peerDependencies": {
67
67
  "@deepseek-ai/cordis": "^4.0.1",
68
- "@deepseek-ai/dsh-api-remotes": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2",
69
- "@deepseek-ai/dsh-api-session-controller": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2",
70
- "@deepseek-ai/dsh-client-locale": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2",
71
- "@deepseek-ai/dsh-client-ui-model-selection": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2",
72
- "@deepseek-ai/dsh-client-ui-renderer": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2",
73
- "@deepseek-ai/dsh-client-ui-settings": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2",
74
- "@deepseek-ai/dsh-client-ui-slots": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2"
68
+ "@deepseek-ai/dsh-api-remotes": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3",
69
+ "@deepseek-ai/dsh-api-session-controller": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3",
70
+ "@deepseek-ai/dsh-client-locale": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3",
71
+ "@deepseek-ai/dsh-client-ui-model-selection": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3",
72
+ "@deepseek-ai/dsh-client-ui-renderer": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3",
73
+ "@deepseek-ai/dsh-client-ui-settings": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3",
74
+ "@deepseek-ai/dsh-client-ui-slots": "0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3"
75
75
  },
76
76
  "peerDependenciesMeta": {
77
77
  "@deepseek-ai/dsh-api-remotes": {
@@ -103,11 +103,11 @@
103
103
  "devDependencies": {
104
104
  "@deepseek-ai/cordis": "^4.0.4",
105
105
  "@deepseek-ai/cosmokit": "^1.8.5",
106
- "@deepseek-ai/dsh-client-locale": "0.2.1-rc.1",
107
- "@deepseek-ai/dsh-client-store": "0.2.1-rc.1",
108
- "@deepseek-ai/dsh-client-ui-renderer": "0.2.1-rc.1",
109
- "@deepseek-ai/dsh-client-ui-settings": "0.2.1-rc.1",
110
- "@deepseek-ai/dsh-client-ui-slots": "0.2.1-rc.1",
106
+ "@deepseek-ai/dsh-client-locale": "0.2.1-rc.3",
107
+ "@deepseek-ai/dsh-client-store": "0.2.1-rc.3",
108
+ "@deepseek-ai/dsh-client-ui-renderer": "0.2.1-rc.3",
109
+ "@deepseek-ai/dsh-client-ui-settings": "0.2.1-rc.3",
110
+ "@deepseek-ai/dsh-client-ui-slots": "0.2.1-rc.3",
111
111
  "@deepseek-ai/schemastery": "^3.18.4",
112
112
  "@eslint/js": "^10.0.1",
113
113
  "@types/node": "^24.0.0",