dsh-pin-default-model 1.2.0 → 1.3.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.js CHANGED
@@ -11,6 +11,12 @@
11
11
  * refuses to overwrite the pinned selection. The pin itself is changed only
12
12
  * through this plugin's own host route, so a session switch can never move it.
13
13
  *
14
+ * The pin carries a routing triple: provider, model, and an optional
15
+ * reasoning effort. When the effort is omitted the plugin does not interfere
16
+ * with the effort at all and the provider default applies — that is the safe
17
+ * default, because DSH rejects a request whose effort the model does not
18
+ * support (`UNSUPPORTED_REASONING_EFFORT`).
19
+ *
14
20
  * The browser half uses plain fetch against those routes, which avoids any
15
21
  * dependency on the settings-client services and keeps loading order simple.
16
22
  */
@@ -21,7 +27,10 @@ export const name = 'dsh-pin-default-model';
21
27
  /** Services this plugin uses on the host side. */
22
28
  export const inject = ['agentDefaultModel', 'webServer', 'sessionController'];
23
29
 
24
- /** Pin used when the live service has no selection yet. */
30
+ /**
31
+ * Pin used when the live service has no selection yet.
32
+ * No reasoning effort: the provider default applies until the user locks one.
33
+ */
25
34
  const FALLBACK_PIN = { provider: 'magpie', model: 'group/x-call' };
26
35
 
27
36
  /** How long to wait before the first drift check, letting the profile settle. */
@@ -30,20 +39,6 @@ const FIRST_CHECK_MS = 1500;
30
39
  /** How often the live default is compared against the pin. */
31
40
  const WATCH_INTERVAL_MS = 2000;
32
41
 
33
- /**
34
- * Compare two selections by their routing triple.
35
- * @param selection - a `{ provider, model, reasoningEffort? }` value.
36
- * @returns a stable key that is equal for equivalent selections.
37
- */
38
- function keyOf(selection) {
39
- const effort = selection?.reasoningEffort;
40
- return [
41
- String(selection?.provider ?? ''),
42
- String(selection?.model ?? ''),
43
- effort === undefined || effort === null ? '' : String(effort),
44
- ].join('\u0000');
45
- }
46
-
47
42
  /**
48
43
  * Build a clean selection value.
49
44
  * @param value - a candidate selection from a request or the service.
@@ -61,6 +56,37 @@ function cleanSelection(value) {
61
56
  };
62
57
  }
63
58
 
59
+ /**
60
+ * Decide whether a live selection satisfies the pin.
61
+ *
62
+ * The effort only participates when the pin locks one. A pin without an effort
63
+ * means "follow the provider default", so a session that changes only its
64
+ * effort is left alone while a session that changes the route is still refused.
65
+ * @param pin - the pinned selection.
66
+ * @param live - the selection to test.
67
+ * @returns true when the live selection already satisfies the pin.
68
+ */
69
+ function satisfies(pin, live) {
70
+ if (pin === undefined || live === undefined) return false;
71
+ if (pin.provider !== live.provider || pin.model !== live.model) return false;
72
+ if (pin.reasoningEffort === undefined) return true;
73
+ return pin.reasoningEffort === live.reasoningEffort;
74
+ }
75
+
76
+ /**
77
+ * Find one model in a provider-grouped catalog.
78
+ * @param groups - provider groups from the model catalog.
79
+ * @param provider - provider id.
80
+ * @param model - model id.
81
+ * @returns the catalog entry, or undefined when the route is not listed.
82
+ */
83
+ function findModel(groups, provider, model) {
84
+ const group = (groups ?? []).find((candidate) => candidate?.id === provider);
85
+ if (group === undefined) return undefined;
86
+ return (group.models ?? []).find((candidate) => candidate?.id === model);
87
+ }
88
+
89
+
64
90
  /** Send a JSON response with a no-store cache policy. */
65
91
  function sendJson(response, status, body) {
66
92
  const payload = JSON.stringify(body);
@@ -146,18 +172,20 @@ export function apply(ctx, config) {
146
172
  model: config?.model?.get?.(),
147
173
  reasoningEffort: config?.reasoningEffort?.get?.(),
148
174
  }) ?? cleanSelection(service.currentSelection?.()) ?? { ...FALLBACK_PIN };
149
- let pinKey = keyOf(currentPin);
150
175
  let restoring = false;
151
176
  let settingFromRoute = false;
152
177
 
153
178
  const pinnedSave = function pinnedSaveSelection(next) {
154
179
  // A write issued by our own route or by the restore path is allowed.
155
- if (settingFromRoute || restoring || keyOf(next) === pinKey) {
180
+ if (settingFromRoute || restoring || satisfies(currentPin, next)) {
156
181
  return Promise.resolve(originalSave.call(service, next));
157
182
  }
158
183
  log(
159
184
  'info',
160
- `pin-default-model: ignored a default-model change to ${String(next?.provider)}/${String(next?.model)}; the default stays ${currentPin.provider}/${currentPin.model}`,
185
+ `pin-default-model: ignored a default-model change to ${String(next?.provider)}/${String(next?.model)}`
186
+ + `${next?.reasoningEffort === undefined ? '' : ` (${String(next.reasoningEffort)})`};`
187
+ + ` the default stays ${currentPin.provider}/${currentPin.model}`
188
+ + `${currentPin.reasoningEffort === undefined ? '' : ` (${currentPin.reasoningEffort})`}`,
161
189
  );
162
190
  queueMicrotask(() => { void hold(); });
163
191
  return Promise.resolve();
@@ -181,8 +209,14 @@ export function apply(ctx, config) {
181
209
  log('warn', `pin-default-model: cannot read the default selection: ${String(error)}`);
182
210
  return;
183
211
  }
184
- if (keyOf(live) === pinKey) return;
185
- log('info', `pin-default-model: default drifted; restoring ${currentPin.provider}/${currentPin.model}`);
212
+ if (satisfies(currentPin, live)) return;
213
+ log(
214
+ 'info',
215
+ `pin-default-model: default drifted to ${String(live?.provider)}/${String(live?.model)}`
216
+ + `${live?.reasoningEffort === undefined ? '' : ` (${String(live.reasoningEffort)})`};`
217
+ + ` restoring ${currentPin.provider}/${currentPin.model}`
218
+ + `${currentPin.reasoningEffort === undefined ? '' : ` (${currentPin.reasoningEffort})`}`,
219
+ );
186
220
  restoring = true;
187
221
  try {
188
222
  await originalSave.call(service, currentPin);
@@ -250,8 +284,30 @@ export function apply(ctx, config) {
250
284
  sendJson(response, 400, { ok: false, error: 'provider and model are required' });
251
285
  return;
252
286
  }
287
+ // DSH rejects a call whose effort the model does not support, so a
288
+ // pin that could never be used must not be stored. The route is
289
+ // checked here rather than left to fail at session creation.
290
+ if (next.reasoningEffort !== undefined) {
291
+ const groups = (await catalog()).groups;
292
+ const entry = findModel(groups, next.provider, next.model);
293
+ if (entry === undefined) {
294
+ sendJson(response, 400, {
295
+ ok: false,
296
+ error: `model "${next.provider}/${next.model}" is not in the catalog; cannot verify the reasoning effort`,
297
+ });
298
+ return;
299
+ }
300
+ const supported = (entry.reasoning?.efforts ?? []).map((effort) => effort.id);
301
+ if (!supported.includes(next.reasoningEffort)) {
302
+ sendJson(response, 400, {
303
+ ok: false,
304
+ error: `model "${next.provider}/${next.model}" does not support reasoning effort "${next.reasoningEffort}"`
305
+ + `${supported.length === 0 ? ' (it offers no reasoning effort)' : ` (supported: ${supported.join(', ')})`}`,
306
+ });
307
+ return;
308
+ }
309
+ }
253
310
  currentPin = next;
254
- pinKey = keyOf(next);
255
311
  settingFromRoute = true;
256
312
  try {
257
313
  await originalSave.call(service, next);
@@ -259,7 +315,11 @@ export function apply(ctx, config) {
259
315
  finally {
260
316
  settingFromRoute = false;
261
317
  }
262
- log('info', `pin-default-model: pin changed to ${next.provider}/${next.model}`);
318
+ log(
319
+ 'info',
320
+ `pin-default-model: pin changed to ${next.provider}/${next.model}`
321
+ + `${next.reasoningEffort === undefined ? '' : ` (${next.reasoningEffort})`}`,
322
+ );
263
323
  sendJson(response, 200, { ok: true, selection: currentPin });
264
324
  }
265
325
  catch (error) {
@@ -278,7 +338,11 @@ export function apply(ctx, config) {
278
338
  const first = setTimeout(() => { void hold(); }, FIRST_CHECK_MS);
279
339
  if (typeof first?.unref === 'function') first.unref();
280
340
 
281
- log('info', `pin-default-model: holding the default at ${currentPin.provider}/${currentPin.model}`);
341
+ log(
342
+ 'info',
343
+ `pin-default-model: holding the default at ${currentPin.provider}/${currentPin.model}`
344
+ + `${currentPin.reasoningEffort === undefined ? ' (reasoning effort follows the provider default)' : ` (${currentPin.reasoningEffort})`}`,
345
+ );
282
346
 
283
347
  return () => {
284
348
  clearInterval(timer);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-pin-default-model",
3
- "version": "1.2.0",
4
- "description": "Pins the DeepSeek Harness default model so switching models inside a session never changes what new sessions start with.",
3
+ "version": "1.3.0",
4
+ "description": "Pins the DeepSeek Harness default model and reasoning effort so switching either inside a session never changes what new sessions start with.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "license": "MIT",