dsh-thinking-levels 3.4.4 → 3.4.5-beta.2

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.
@@ -150,3 +150,30 @@ export declare function clampToEfforts(level: EffortId, efforts: readonly string
150
150
  export declare function resolveEffortInjection(input: EffortInjectionInput): EffortInjectionDecision;
151
151
  /** Wall-clock delta of one tool call, for the timing telemetry. */
152
152
  export declare function toolDurationMs(startedAt: number, finishedAt: number): number;
153
+ /**
154
+ * Display rank of the effort slider stops: `auto` is the scheduler sentinel and
155
+ * sits LEFTMOST regardless of whether the model allows disabling thinking;
156
+ * `off` / `on` follow, then the strength gradient. Ids outside the standard set
157
+ * (custom gateway wire values such as `ultra`) rank last, in arrival order.
158
+ */
159
+ export declare const EFFORT_SLIDER_RANK: Readonly<Record<string, number>>;
160
+ /**
161
+ * Order a model's advertised efforts for the slider track (left → right).
162
+ * Stable sort: unknown ids keep their relative arrival order after the known
163
+ * ranks, so a gateway's custom wire values are never dropped or reordered
164
+ * against each other.
165
+ */
166
+ export declare function orderEffortsForSlider<T extends {
167
+ id: string;
168
+ }>(efforts: readonly T[]): T[];
169
+ /**
170
+ * Map the line's effective effort to a stop index of the ordered track: exact
171
+ * id match wins; an unmatched id (e.g. a defaultEffort the track does not
172
+ * advertise) parks on the nearest stop by display rank, ties resolving to the
173
+ * stronger level (higher index); an absent value parks on stop 0 (the neutral
174
+ * left end — `auto` when advertised) and an empty track always yields 0, so the
175
+ * caller never faces an out-of-range thumb.
176
+ */
177
+ export declare function nearestEffortStopIndex(stops: readonly {
178
+ id: string;
179
+ }[], value: string | undefined): number;
@@ -201,3 +201,58 @@ export function resolveEffortInjection(input) {
201
201
  export function toolDurationMs(startedAt, finishedAt) {
202
202
  return Math.max(0, finishedAt - startedAt);
203
203
  }
204
+ /* ── effort slider ordering & placement (client face, kept pure for tests) ── */
205
+ /**
206
+ * Display rank of the effort slider stops: `auto` is the scheduler sentinel and
207
+ * sits LEFTMOST regardless of whether the model allows disabling thinking;
208
+ * `off` / `on` follow, then the strength gradient. Ids outside the standard set
209
+ * (custom gateway wire values such as `ultra`) rank last, in arrival order.
210
+ */
211
+ export const EFFORT_SLIDER_RANK = {
212
+ auto: 0, off: 1, on: 2, minimal: 3, low: 4, medium: 5, high: 6, xhigh: 7, max: 8,
213
+ };
214
+ /** Fallback rank for ids outside the standard table. */
215
+ const EFFORT_SLIDER_RANK_TAIL = 100;
216
+ /**
217
+ * Order a model's advertised efforts for the slider track (left → right).
218
+ * Stable sort: unknown ids keep their relative arrival order after the known
219
+ * ranks, so a gateway's custom wire values are never dropped or reordered
220
+ * against each other.
221
+ */
222
+ export function orderEffortsForSlider(efforts) {
223
+ return [...efforts].sort((a, b) => {
224
+ const rankA = EFFORT_SLIDER_RANK[a.id] ?? EFFORT_SLIDER_RANK_TAIL;
225
+ const rankB = EFFORT_SLIDER_RANK[b.id] ?? EFFORT_SLIDER_RANK_TAIL;
226
+ return rankA - rankB;
227
+ });
228
+ }
229
+ /**
230
+ * Map the line's effective effort to a stop index of the ordered track: exact
231
+ * id match wins; an unmatched id (e.g. a defaultEffort the track does not
232
+ * advertise) parks on the nearest stop by display rank, ties resolving to the
233
+ * stronger level (higher index); an absent value parks on stop 0 (the neutral
234
+ * left end — `auto` when advertised) and an empty track always yields 0, so the
235
+ * caller never faces an out-of-range thumb.
236
+ */
237
+ export function nearestEffortStopIndex(stops, value) {
238
+ if (stops.length === 0)
239
+ return 0;
240
+ if (value === undefined)
241
+ return 0;
242
+ const exact = stops.findIndex(stop => stop.id === value);
243
+ if (exact >= 0)
244
+ return exact;
245
+ const rank = EFFORT_SLIDER_RANK[value] ?? EFFORT_SLIDER_RANK_TAIL;
246
+ let best = 0;
247
+ let bestDistance = Number.POSITIVE_INFINITY;
248
+ stops.forEach((stop, index) => {
249
+ const stopRank = EFFORT_SLIDER_RANK[stop.id] ?? EFFORT_SLIDER_RANK_TAIL;
250
+ const distance = Math.abs(stopRank - rank);
251
+ // `<=` resolves ties toward the stronger (right-most) level.
252
+ if (distance <= bestDistance) {
253
+ bestDistance = distance;
254
+ best = index;
255
+ }
256
+ });
257
+ return best;
258
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-thinking-levels",
3
- "version": "3.4.4",
3
+ "version": "3.4.5-beta.2",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org",
6
6
  "access": "public",