dsh-thinking-levels 4.4.18 → 4.4.19

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.4.19
4
+
5
+ - **修复 issue #11:选中 auto 时界面看不到实际生效档位。** 报告人观察到「选 Auto 后请求仍以 high 发出,`lastUsed` 一直是 high、`pending` 一直是 auto」。核实结论:auto 不上送**是设计**(它是 scheduler sentinel,请求期由 `decideEffort` 按工具采样窗口解析成具体档位,有降档行为),`lastUsed`/`pending` 是宿主 `modelSelection` 投影的固有语义(`lastUsed` 每次 `request/header` 被重写、`pending` 匹配 header 提交后清空,二者都不承载用户意图 —— 见 `auto-schedule-projection.ts` 模块注释)。**真正的缺陷是显示**:`tlAutoSchedule` 投影新增 `lastEffective` 字段,折叠已提交的 `request/header` 中的 effective effort(宿主在 `dsh-llm` 里把解析结果写进该事件),选择器 chip 据此显示 `Auto → high`。
6
+ - 为什么不能复用 `directory.current.reasoningEffort`:宿主从 `modelSelection.next`(**下一步**要用的选择,即用户意图)派生它(`dsh-client-ui-model-selection/src/client/directory.ts:178`),选中 auto 时它永远是 `'auto'`,所以旧的 `→ level` 提示永远不显示。
7
+ - 投影 `stateVersion` 1 → 2(形状变更);历史会话不受影响 —— 投影是日志的折叠视图,冷读会重新折叠出 `samples`/`userEffort`/`lastEffective`。
8
+ - 降级:投影通道缺失(旧宿主、冷会话)时 `lastEffectiveEffort` 为 `undefined`,chip 退回只显示意图标签,不报错(抛错的 inject 会让整个座位让回官方选择器)。
9
+ - 新增 7 个用例:`request/header` 折叠(正常/缺失/非字符串)、引用稳定性(`Object.is` 门控)、冷读重建、注入面降级。
10
+
3
11
  ## 4.4.18
4
12
 
5
13
  - **修复 issue #10(同时覆盖 #9 的形态):与第三方 adapter 包装器同开时 `resolveModel` 互递归爆栈 / 改写报错。**
package/dsh.plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "dsh-external/dsh-thinking-levels",
3
- "version": "4.4.18",
3
+ "version": "4.4.19",
4
4
  "main": "./lib/index.js",
5
5
  "description": "thinking-level (reasoning_effort) control — auto-adjust per tool round, with optional manual lock and per-tool timing telemetry.",
6
6
  "engines": {
@@ -44,6 +44,20 @@ export interface AutoScheduleState {
44
44
  samples: readonly ToolCallSample[];
45
45
  /** Effort explicitly picked in this session, or null when never picked. */
46
46
  userEffort: string | null;
47
+ /**
48
+ * The effort the last request ACTUALLY carried, folded from the committed
49
+ * `request/header` (the host writes the effective value there —
50
+ * `dsh-llm/lib/index.js:2298-2308`).
51
+ *
52
+ * Issue #11: with `auto` selected the UI showed "Auto" while every request
53
+ * went out as a concrete level, so the user could not tell what was really
54
+ * sent. The host's `modelSelection.lastUsed` cannot answer that either (it is
55
+ * rewritten on every header, i.e. it holds our own output — see the module
56
+ * doc), so the answer has to come from this projection.
57
+ *
58
+ * `null` until the session's first committed request.
59
+ */
60
+ lastEffective: string | null;
47
61
  }
48
62
  /**
49
63
  * Fold one committed Session event into the auto-schedule state.
@@ -72,6 +86,7 @@ export declare function buildAutoScheduleDefinition(): {
72
86
  argsSize: z.ZodNumber;
73
87
  }, z.core.$strip>>;
74
88
  userEffort: z.ZodNullable<z.ZodString>;
89
+ lastEffective: z.ZodNullable<z.ZodString>;
75
90
  }, z.core.$strip>;
76
91
  init: () => AutoScheduleState;
77
92
  apply: typeof applyAutoSchedule;
@@ -42,9 +42,10 @@ export const AUTO_SCHEDULE_KEY = 'tlAutoSchedule';
42
42
  const stateSchema = z.object({
43
43
  samples: z.array(z.object({ name: z.string(), argsSize: z.number() })),
44
44
  userEffort: z.string().nullable(),
45
+ lastEffective: z.string().nullable(),
45
46
  });
46
47
  /** Initial folded state (also the shape every cold read starts from). */
47
- const initAutoSchedule = () => ({ samples: [], userEffort: null });
48
+ const initAutoSchedule = () => ({ samples: [], userEffort: null, lastEffective: null });
48
49
  /**
49
50
  * Fold one committed Session event into the auto-schedule state.
50
51
  *
@@ -78,6 +79,23 @@ export function applyAutoSchedule(state, event) {
78
79
  const userEffort = typeof raw === 'string' && raw.length > 0 ? raw : null;
79
80
  return userEffort === state.userEffort ? state : { ...state, userEffort };
80
81
  }
82
+ if (type === 'request/header') {
83
+ // Issue #11: the header carries the effort this request actually went out
84
+ // with — the host resolves and commits the effective value here, so it is
85
+ // the only durable record of what `auto` turned into.
86
+ const data = event.data;
87
+ const header = typeof data === 'object' && data !== null
88
+ ? data.header
89
+ : undefined;
90
+ const config = typeof header === 'object' && header !== null
91
+ ? header.config
92
+ : undefined;
93
+ const raw = typeof config === 'object' && config !== null
94
+ ? config.reasoningEffort
95
+ : undefined;
96
+ const lastEffective = typeof raw === 'string' && raw.length > 0 ? raw : null;
97
+ return lastEffective === state.lastEffective ? state : { ...state, lastEffective };
98
+ }
81
99
  return state;
82
100
  }
83
101
  /**
@@ -89,7 +107,11 @@ export function applyAutoSchedule(state, event) {
89
107
  export function buildAutoScheduleDefinition() {
90
108
  return {
91
109
  key: AUTO_SCHEDULE_KEY,
92
- stateVersion: 1,
110
+ // Bumped 1 → 2 when `lastEffective` joined the state (issue #11): the host
111
+ // validates against `stateSchema` per version, so a shape change must raise
112
+ // it. Historical sessions are not lost — the state is a fold over the log,
113
+ // so a cold read rebuilds samples/userEffort/lastEffective from the events.
114
+ stateVersion: 2,
93
115
  stateSchema,
94
116
  init: initAutoSchedule,
95
117
  apply: applyAutoSchedule,
package/lib/client.js CHANGED
@@ -2770,7 +2770,7 @@ body:not([data-ds-dark-theme]) .${ZONE_CLASS}[data-top="1"] .${TRACK_CLASS} { an
2770
2770
  * (the "max context window" editor moved into each line).
2771
2771
  * @param props - injected directory + config forms, session seat, copy.
2772
2772
  */
2773
- function ModelPanel({ directory, piAiScope, deepseekScope, tlScope, sessionId, t }) {
2773
+ function ModelPanel({ directory, piAiScope, deepseekScope, tlScope, sessionId, lastEffectiveEffort, t }) {
2774
2774
  const state = (0, react.useSyncExternalStore)((listener) => directory?.store.subscribe(listener) ?? (() => {}), () => directory?.store.getSnapshot() ?? UNAVAILABLE_STATE);
2775
2775
  const piSnapshot = (0, react.useSyncExternalStore)((listener) => piAiScope.subscribe(listener), () => piAiScope.getSnapshot());
2776
2776
  const dsSnapshot = (0, react.useSyncExternalStore)((listener) => deepseekScope.subscribe(listener), () => deepseekScope.getSnapshot());
@@ -2977,11 +2977,21 @@ body:not([data-ds-dark-theme]) .${ZONE_CLASS}[data-top="1"] .${TRACK_CLASS} { an
2977
2977
  const triggerLabel = current?.name ?? state.current?.model ?? t("model.panel.choose");
2978
2978
  const currentReasoning = current?.model.reasoning;
2979
2979
  const resolvedEffort = state.current?.reasoningEffort;
2980
+ /**
2981
+ * Issue #11: what the last request ACTUALLY carried.
2982
+ *
2983
+ * `resolvedEffort` above is the host's `modelSelection.next` — the user's
2984
+ * intent — so with `auto` picked it stays `'auto'` and the `→ level` hint
2985
+ * could never appear. The projection's `lastEffective` is the committed
2986
+ * header's resolved level. Fall back to `resolvedEffort` for hosts without the
2987
+ * projection so a non-auto pick keeps its previous hint behaviour.
2988
+ */
2989
+ const actualEffort = lastEffectiveEffort ?? resolvedEffort;
2980
2990
  const autoAdvertised = currentReasoning?.efforts.some((effort) => effort.id === "auto") === true;
2981
2991
  const intentEffort = selectedEffortRef.current ?? (resolvedEffort === "auto" || autoAdvertised && configLevel === "auto" ? "auto" : resolvedEffort ?? currentReasoning?.defaultEffort);
2982
2992
  const effortName = (id) => currentReasoning?.efforts.find((level) => level.id === id)?.name ?? id;
2983
2993
  const effortLabel = currentReasoning === void 0 ? void 0 : intentEffort === void 0 ? t("input.effort.default") : effortName(intentEffort);
2984
- const resolvedHint = currentReasoning !== void 0 && intentEffort === "auto" && resolvedEffort !== void 0 && resolvedEffort !== "auto" ? `→ ${effortName(resolvedEffort)}` : void 0;
2994
+ const resolvedHint = currentReasoning !== void 0 && intentEffort === "auto" && actualEffort !== void 0 && actualEffort !== "auto" ? `→ ${effortName(actualEffort)}` : void 0;
2985
2995
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2986
2996
  ref: rootRef,
2987
2997
  style: rootStyle,
@@ -5458,6 +5468,8 @@ body:not([data-ds-dark-theme]) .${ZONE_CLASS}[data-top="1"] .${TRACK_CLASS} { an
5458
5468
  * the switch and the panel seats (or abdicates) immediately, no reload.
5459
5469
  */
5460
5470
  let seatDirectories;
5471
+ /** The `sessions` face, kept for the chip's projection read (issue #11). */
5472
+ let sessionsRef;
5461
5473
  let seatDeclared = false;
5462
5474
  let seatWatched = false;
5463
5475
  let seatClaimed;
@@ -5467,6 +5479,35 @@ body:not([data-ds-dark-theme]) .${ZONE_CLASS}[data-top="1"] .${TRACK_CLASS} { an
5467
5479
  if (seatHandleMemo === void 0 && scopeOf !== void 0) seatHandleMemo = tlSettingsScopeOf(scopeOf);
5468
5480
  return seatHandleMemo;
5469
5481
  };
5482
+ /**
5483
+ * The level the session's last committed request actually carried, read from
5484
+ * this plugin's own `tlAutoSchedule` projection (issue #11).
5485
+ *
5486
+ * Why not the directory's `current.reasoningEffort`: the host derives it from
5487
+ * `modelSelection.next` — the selection the NEXT step uses, i.e. the user's
5488
+ * intent (`dsh-client-ui-model-selection/src/client/directory.ts:178`). With
5489
+ * `auto` picked, `next.reasoningEffort` stays `'auto'` for the whole session,
5490
+ * so the chip had no way to show what was really sent. The projection folds
5491
+ * the committed `request/header`, which carries the resolved level.
5492
+ *
5493
+ * Returns `undefined` — never throws — when the projection channel or the
5494
+ * projection itself is absent (older hosts, cold sessions). The chip then
5495
+ * degrades to the plain intent label.
5496
+ * @param sessions - the sessions face captured from the scope inject.
5497
+ * @param sessionId - the owning session.
5498
+ * @returns the last effective effort id, or undefined.
5499
+ */
5500
+ const lastEffectiveOf = (sessions, sessionId) => {
5501
+ try {
5502
+ const face = sessions?.binding(sessionId)?.session?.projections?.faceOf?.("tlAutoSchedule");
5503
+ const snapshot = typeof face?.getSnapshot === "function" ? face.getSnapshot() : void 0;
5504
+ const value = typeof snapshot === "object" && snapshot !== null ? snapshot.value : void 0;
5505
+ const raw = typeof value === "object" && value !== null ? value.lastEffective : void 0;
5506
+ return typeof raw === "string" && raw.length > 0 ? raw : void 0;
5507
+ } catch {
5508
+ return;
5509
+ }
5510
+ };
5470
5511
  const takeoverUiOn = () => {
5471
5512
  const snap = typeof seatHandle()?.getSnapshot === "function" ? seatHandle().getSnapshot() : void 0;
5472
5513
  return snap?.status === "ready" && snap.value?.takeoverUi === true;
@@ -5487,7 +5528,8 @@ body:not([data-ds-dark-theme]) .${ZONE_CLASS}[data-top="1"] .${TRACK_CLASS} { an
5487
5528
  directory,
5488
5529
  piAiScope: scopeOf?.("llm-pi-ai"),
5489
5530
  deepseekScope: scopeOf?.("llm-deepseek"),
5490
- tlScope: scopeOf === void 0 ? void 0 : tlSettingsScopeOf(scopeOf)
5531
+ tlScope: scopeOf === void 0 ? void 0 : tlSettingsScopeOf(scopeOf),
5532
+ lastEffectiveEffort: lastEffectiveOf(sessionsRef, sessionId)
5491
5533
  };
5492
5534
  }
5493
5535
  });
@@ -5525,6 +5567,7 @@ body:not([data-ds-dark-theme]) .${ZONE_CLASS}[data-top="1"] .${TRACK_CLASS} { an
5525
5567
  const directories = scope.modelDirectories;
5526
5568
  if (directories === void 0) return;
5527
5569
  seatDirectories = directories;
5570
+ sessionsRef = scope.sessions;
5528
5571
  ctx.slots.inject("conversation.input.model", function* () {
5529
5572
  seatDeclared = true;
5530
5573
  startSeatWatch();