dsh-thinking-slider 0.3.4 → 0.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.
Files changed (3) hide show
  1. package/README.md +17 -20
  2. package/lib/client.js +2 -300
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -51,27 +51,19 @@
51
51
  | --- | --- |
52
52
  | ![能量充能 · 深色](docs/energy-mode.png) | ![能量充能 · 浅色](docs/energy-mode-light.png) |
53
53
 
54
- ## 让没有等级的模型真的能选等级
54
+ ## 与 DSH 原生能力的关系
55
55
 
56
- **先说原因**:等级要能真正生效,必须由 `reasoningEfforts` 给每个模型声明
57
- 「等级 → 发给网关的原始值」的映射。而 DSH 的「设置 → 模型」页面**没有这个字段**,
58
- 所以**任何通过 GUI 添加的代理商,模型都永远不会有等级**。
56
+ 从 **DSH 0.2.2** 起,这两件事已经由内核自己做了,**本插件不再重复**:
59
57
 
60
- 注意这不是"显示问题":DSH 会**直接拒绝**一个没有映射的等级(
61
- `UNSUPPORTED_REASONING_EFFORT`,不是静默忽略)。它的注释写明了设计意图 ——
62
- 它宁可**不报告**任何等级,也不愿意提供一个"做不到自己所说事情"的控件。
63
- (本插件早期版本试图在界面上补四档,结果每次点选都报错,已回退。)
58
+ - **声明等级**:**设置 → 模型** 添加自定义代理商时,每个模型都能选推理等级
59
+ (内核按协议校验,例如 Gemini 只接受 `minimal`/`low`/`medium`/`high`)
60
+ - **选择等级**:模型菜单里已有等级子菜单(含「供应商默认」)
64
61
 
65
- **插件补上了这个缺口**:**设置 → 通用 → 模型推理等级** 会列出「有模型没声明等级的
66
- 代理商」,逐个点「补四档」即可。
62
+ 所以 0.4.0 起本插件**只做外观**:三种视觉模式和卡片排版。等级本身仍走官方接口,
63
+ 插件不改动 `reasoningEfforts` 配置,也不会替你写任何模型设置 —— 缺等级请去
64
+ **设置 → 模型** 补。
67
65
 
68
- - 写入的是 `llm-pi-ai` 的**真实配置**(与「设置 → 模型」同一份),所以等级**真的生效**
69
- - 适配器每个请求都重读配置,**不需要重启**
70
- - 只补**没有声明**的模型;已经声明过的原样保留
71
- - **逐代理商确认,不做全自动**:若某个网关不接受 `reasoning_effort`,会让那个代理商
72
- 的请求全部失败。`none / low / high / max` 是实测可用的拼写,但**换网关要先试一个模型**
73
-
74
- ![设置 → 通用 → 模型推理等级:逐代理商「补四档」](docs/shot-settings.png)
66
+ 如果你更想要官方那套控件,把模式切成「官方」即可,插件随即完全不注册座位。
75
67
 
76
68
  ## 要求
77
69
 
@@ -131,8 +123,10 @@ dsh plugin --profile desktop add github:MuFeng262/dsh-thinking-slider
131
123
 
132
124
  ## 让自定义模型也有推理等级
133
125
 
134
- **档位不在插件里。** 插件是通用的,但 `Off / Low / High / Max` 来自你自己的 profile 配置。
135
- DSH 的 Models 设置页**刻意不提供**这个字段,只能手写进 profile 的 `cordis.patch.yml`:
126
+ **档位不在插件里。** 插件是通用的,档位来自模型自己声明的能力。
127
+
128
+ **DSH 0.2.2 起**,直接去 **设置 → 模型** 给自定义代理商的每个模型选等级即可,
129
+ 内核会按协议校验可用档位。下面的手写方式只在**旧版 DSH**、或者你想一次性批量改配置时还有用:
136
130
 
137
131
  ```yaml
138
132
  - id: llm-pi-ai
@@ -178,13 +172,16 @@ dsh plugin --profile desktop remove dsh-thinking-slider
178
172
  ```bash
179
173
  git clone https://github.com/MuFeng262/dsh-thinking-slider
180
174
  cd dsh-thinking-slider
181
- node test/smoke.mjs # 66 项行为测试,零依赖,不需要 DSH
175
+ node test/smoke.mjs # 106 项行为测试,零依赖,不需要 DSH
182
176
  ```
183
177
 
184
178
  `test/smoke.mjs` 自带一个迷你 React 运行时(hooks 槽位、类组件与错误边界、
185
179
  跨渲染的 DOM 节点身份、真实执行的 effect 与 cleanup),所以
186
180
  「节点重挂后动画有没有重新绑定」这类问题是可以断言的,不需要开浏览器。
187
181
 
182
+ 发布新版本见 [RELEASING.md](RELEASING.md):Release 说明**必须中英双语**,
183
+ release 附件与 npm 包用同一个 tarball(保证字节一致)。
184
+
188
185
  ## 许可
189
186
 
190
187
  MIT
package/lib/client.js CHANGED
@@ -81,114 +81,6 @@ window.__ModuleLoader__.load({
81
81
  /** React hook over the mode store. */
82
82
  const useMode = () => react.useSyncExternalStore(subscribeMode, getMode, getMode)
83
83
 
84
- // ---------------------------------------------------------------------
85
- // Filling in reasoning levels for models that declare none.
86
- //
87
- // The Host keeps the wire mapping per model in `reasoningEfforts`, and a model
88
- // without one resolves to `reasoning: false`: DSH reports no selectable level
89
- // and REFUSES an explicit one (UNSUPPORTED_REASONING_EFFORT), on purpose --
90
- // it will not ship "a control that cannot do what it says". So a level can
91
- // only be offered by putting the mapping into the config the Host reads.
92
- //
93
- // The Models settings page has no field for it, which is why every provider
94
- // added through the GUI offers no levels. A plugin may edit a namespace
95
- // another plugin owns, so the fix is to write the mapping into `llm-pi-ai`'s
96
- // own config -- the same place the Models page writes -- which the adapter
97
- // re-reads on the next request, no restart needed.
98
- //
99
- // Applied per provider, on request: a gateway that rejects `reasoning_effort`
100
- // would 400 every request, so this must never happen behind the user's back.
101
- // ---------------------------------------------------------------------
102
- const LLM_NAMESPACE = 'llm-pi-ai'
103
- /** The levels this plugin offers, in the wire spellings verified to work. */
104
- const DEFAULT_EFFORTS = { off: 'none', low: 'low', high: 'high', max: 'max' }
105
-
106
- /** Providers with at least one model that declares no levels. */
107
- const providersMissingLevels = (configValue) => {
108
- const providers = configValue?.providers
109
- if (providers === null || typeof providers !== 'object') return []
110
- const missing = []
111
- for (const [route, entry] of Object.entries(providers)) {
112
- const models = Array.isArray(entry?.models) ? entry.models : []
113
- const count = models.filter((model) => model?.reasoningEfforts === undefined).length
114
- if (count > 0) missing.push({ route, count, total: models.length })
115
- }
116
- return missing.sort((left, right) => left.route.localeCompare(right.route))
117
- }
118
-
119
- /** The provider map with one provider's level-less models filled in. */
120
- const withFilledLevels = (configValue, route) => {
121
- const entry = configValue?.providers?.[route]
122
- if (entry === undefined || entry === null) return undefined
123
- const models = (Array.isArray(entry.models) ? entry.models : []).map((model) =>
124
- model?.reasoningEfforts === undefined
125
- ? { ...model, reasoningEfforts: { ...DEFAULT_EFFORTS } }
126
- : model)
127
- return { ...configValue.providers, [route]: { ...entry, models } }
128
- }
129
-
130
- /**
131
- * Write the default levels for one provider's level-less models.
132
- *
133
- * Shared by the settings row and the card's empty state, because the empty
134
- * state is exactly where a user looks when a model offers no levels.
135
- *
136
- * `target` resolves the config form lazily: the namespace the Host serves is
137
- * discovered at runtime (`include:llm-pi-ai` for a bundle-inserted row, not
138
- * the patch id), so it cannot be hardcoded here.
139
- *
140
- * @returns `{ ok: true, count, pending? }` or `{ ok: false, message }`, with
141
- * the message naming what was actually found so a mismatch is diagnosable.
142
- */
143
- const fillProviderLevels = (target, route) => {
144
- let resolved = null
145
- try {
146
- resolved = target.resolve()
147
- } catch (error) {
148
- return { ok: false, message: String(error?.message ?? error) }
149
- }
150
- if (resolved === null) {
151
- return {
152
- ok: false,
153
- message: `找不到承载 providers 的设置命名空间(试过:${target.tried().join(', ') || '无'})`,
154
- }
155
- }
156
- const { namespace, form } = resolved
157
- const value = form.getSnapshot()?.value
158
- const providers = value?.providers
159
- if (providers === null || typeof providers !== 'object' || Array.isArray(providers)) {
160
- const keys = value !== null && value !== undefined && typeof value === 'object'
161
- ? Object.keys(value).join(', ')
162
- : String(value)
163
- return { ok: false, message: `读不到 providers(命名空间 ${namespace}:拿到 ${keys || '空'})` }
164
- }
165
- const entry = providers[route]
166
- if (entry === undefined || entry === null) {
167
- return { ok: false, message: `配置里没有代理商 "${route}"(现有:${Object.keys(providers).join(', ') || '空'})` }
168
- }
169
- const models = Array.isArray(entry.models) ? entry.models : []
170
- const count = models.filter((model) => model?.reasoningEfforts === undefined).length
171
- if (count === 0) return { ok: true, count: 0 }
172
- const next = withFilledLevels(value, route)
173
- if (next === undefined) return { ok: false, message: `配置里没有代理商 "${route}"` }
174
- try {
175
- const result = form.set('providers', next)
176
- if (result !== undefined && result !== null && typeof result.then === 'function') {
177
- return {
178
- ok: true,
179
- count,
180
- pending: result.then(
181
- () => ({ ok: true, count }),
182
- (error) => ({ ok: false, message: String(error?.message ?? error) }),
183
- ),
184
- }
185
- }
186
- return { ok: true, count }
187
- } catch (error) {
188
- return { ok: false, message: String(error?.message ?? error) }
189
- }
190
- }
191
-
192
84
  // ---------------------------------------------------------------------
193
85
  // Colour scheme.
194
86
  //
@@ -268,13 +160,7 @@ window.__ModuleLoader__.load({
268
160
  .tsl-fallbackBadge{font-size:11px;color:var(--dsw-alias-state-warn-primary,#b7791f)}
269
161
  .tsl-fallbackRetry{border:0;padding:0;background:0 0;color:inherit;font:inherit;font-size:11px;text-decoration:underline;cursor:pointer;opacity:.85}
270
162
  .tsl-fallbackRetry:hover{opacity:1}
271
- .tsl-settings{display:flex;flex-direction:column}
272
163
  .tsl-setting{display:flex;align-items:center;gap:12px;padding:12px 0;min-width:0}
273
- .tsl-fills{flex:none;display:flex;flex-wrap:wrap;justify-content:flex-end;gap:6px;max-width:58%}
274
- .tsl-fillChip{display:inline-flex;align-items:center;gap:6px;padding:2px 4px 2px 10px;border-radius:999px;background:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-2,rgba(127,127,127,.16)));color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px;white-space:nowrap}
275
- .tsl-fillApply{border:0;background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.2));color:var(--dsw-alias-label-primary);font:inherit;font-size:12px;line-height:18px;padding:2px 8px;border-radius:999px;cursor:pointer;white-space:nowrap}
276
- .tsl-fillApply:hover{background:var(--dsw-alias-brand-primary,#4d6bfe);color:#fff}
277
- .tsl-fillApply:focus-visible{box-shadow:0 0 0 2px var(--dsw-focus-ring-color,var(--dsw-alias-brand-primary,#4d6bfe))}
278
164
  .tsl-settingText{display:flex;flex-direction:column;gap:2px;min-width:0;flex:1 1 auto}
279
165
  .tsl-settingTitle{font-size:13px;line-height:20px;color:var(--dsw-alias-label-primary)}
280
166
  .tsl-settingHint{font-size:11px;line-height:16px;color:var(--dsw-alias-label-caption)}
@@ -792,7 +678,7 @@ window.__ModuleLoader__.load({
792
678
  }
793
679
 
794
680
  function Seat(props) {
795
- const { locked, available, directory, load, select, fillLevels } = props
681
+ const { locked, available, directory, load, select } = props
796
682
 
797
683
  const state = react.useSyncExternalStore(
798
684
  (subscribe) => directory.subscribe(subscribe),
@@ -1159,22 +1045,6 @@ window.__ModuleLoader__.load({
1159
1045
  ],
1160
1046
  })
1161
1047
 
1162
- // The card's empty state is exactly where someone looks when a model offers
1163
- // no levels, so the fix belongs here too, not only in Settings.
1164
- const fillable = typeof fillLevels === 'function' && current !== null
1165
- const fillHere = () => {
1166
- if (!fillable) return
1167
- const outcome = fillLevels(current.provider)
1168
- if (outcome?.ok === false) setNotice(outcome.message)
1169
- else if (outcome?.count === 0) setNotice('这个代理商已经声明过等级了,重开卡片即可看到')
1170
- else setNotice('已写入等级的映射,关掉卡片重开即可看到(若该网关不接受 reasoning_effort,会让它的请求失败)')
1171
- if (outcome?.ok && outcome.pending !== undefined) {
1172
- outcome.pending.then((settled) => {
1173
- if (!settled.ok) setNotice(settled.message)
1174
- })
1175
- }
1176
- }
1177
-
1178
1048
  const effortPane = jsxs('div', {
1179
1049
  children: [
1180
1050
  jsxs('div', {
@@ -1222,23 +1092,7 @@ window.__ModuleLoader__.load({
1222
1092
  }),
1223
1093
  ],
1224
1094
  }),
1225
- supported
1226
- ? track
1227
- : jsxs('div', {
1228
- className: 'tsl-empty',
1229
- children: [
1230
- jsx('span', { children: '这个模型没有提供推理等级' }),
1231
- fillable
1232
- ? jsx('button', {
1233
- type: 'button',
1234
- className: 'tsl-fillApply',
1235
- title: LEVELS_HINT_LONG,
1236
- onClick: fillHere,
1237
- children: `给 ${current.provider} 补四档`,
1238
- })
1239
- : null,
1240
- ],
1241
- }),
1095
+ supported ? track : jsx('div', { className: 'tsl-empty', children: '这个模型没有提供推理等级' }),
1242
1096
  supported ? scale : null,
1243
1097
  notice !== null ? jsx('div', { className: 'tsl-failure', children: notice }) : null,
1244
1098
  ],
@@ -1464,86 +1318,8 @@ window.__ModuleLoader__.load({
1464
1318
  })
1465
1319
  }
1466
1320
 
1467
- /** Tooltip for the per-provider fill buttons. */
1468
- const LEVELS_HINT_LONG = '给这个代理商里没有声明推理等级的模型补上 Off/Low/High/Max,'
1469
- + '写入 llm-pi-ai 配置(与「设置 → 模型」同一份),宿主下一个请求即生效,不用重启。'
1470
- + '若该网关不接受 reasoning_effort,会让它的请求失败 —— 所以逐个确认,不要一次全补。'
1471
-
1472
- /**
1473
- * The Settings → General row that fills reasoning levels in per provider.
1474
- *
1475
- * Reads and writes `llm-pi-ai`'s config through the settings transport, so the
1476
- * change lands in the same document the Models page edits.
1477
- */
1478
- function LevelsRow(props) {
1479
- const target = props.target
1480
- const form = target.form()
1481
- const snapshot = react.useSyncExternalStore(
1482
- (listener) => target.form().subscribe(listener),
1483
- () => target.form().getSnapshot(),
1484
- )
1485
- const [failure, setFailure] = react.useState(null)
1486
- const missing = providersMissingLevels(snapshot?.value)
1487
- const total = missing.reduce((sum, entry) => sum + entry.count, 0)
1488
-
1489
- const apply = (route) => {
1490
- const outcome = fillProviderLevels(target, route)
1491
- setFailure(outcome.ok ? null : outcome.message)
1492
- if (outcome.ok && outcome.pending !== undefined) {
1493
- outcome.pending.then((settled) => {
1494
- if (!settled.ok) setFailure(settled.message)
1495
- })
1496
- }
1497
- }
1498
-
1499
- return jsxs('div', {
1500
- className: 'tsl-setting',
1501
- children: [
1502
- jsxs('div', {
1503
- className: 'tsl-settingText',
1504
- children: [
1505
- jsx('span', { className: 'tsl-settingTitle', children: '模型推理等级' }),
1506
- jsx('span', {
1507
- className: 'tsl-settingHint',
1508
- children: failure !== null
1509
- ? `写入失败:${failure}`
1510
- : missing.length === 0
1511
- ? '所有模型都已声明等级'
1512
- : `${missing.length} 个代理商共 ${total} 个模型没有等级`,
1513
- }),
1514
- ],
1515
- }),
1516
- jsx('div', {
1517
- className: 'tsl-fills',
1518
- children: missing.map(({ route, count }) => jsxs('span', {
1519
- className: 'tsl-fillChip',
1520
- children: [
1521
- jsx('span', { children: `${route} · ${count}` }),
1522
- jsx('button', {
1523
- type: 'button',
1524
- className: 'tsl-fillApply',
1525
- title: LEVELS_HINT_LONG,
1526
- onClick: () => apply(route),
1527
- children: '补四档',
1528
- }),
1529
- ],
1530
- }, route)),
1531
- }),
1532
- ],
1533
- })
1534
- }
1535
-
1536
1321
  function apply(ctx) {
1537
1322
  try {
1538
- /**
1539
- * The `llm-pi-ai` config form, once the settings transport provides it.
1540
- *
1541
- * Declared here, in `apply`'s scope: both the settings row and the card's
1542
- * fill button read it, and a nested declaration would leave the card
1543
- * looking at a different variable that never gets assigned.
1544
- */
1545
- let levelsForm = null
1546
-
1547
1323
  // The mode row lives in Settings → General, independent of whether the
1548
1324
  // composer seat has a place to mount.
1549
1325
  try {
@@ -1557,77 +1333,6 @@ window.__ModuleLoader__.load({
1557
1333
  record('settings-row', error)
1558
1334
  }
1559
1335
 
1560
- // The level-filling row needs the settings transport to read and write
1561
- // `llm-pi-ai`'s config. Declared as a derived scope so a composition
1562
- // without it loses only this row (and the card's fill button), not the
1563
- // whole plugin.
1564
- try {
1565
- ctx.inject(['configForms'], (scope) => {
1566
- const forms = scope.configForms
1567
- /**
1568
- * Namespaces worth asking for, best guess first.
1569
- *
1570
- * The settings namespace of a bundle-inserted row is its entry id, and
1571
- * the Config inspector reports those as `include:<patchId>` (it does
1572
- * for ui-theme), so the profile's patch id may not be the namespace the
1573
- * transport serves. Which one it is cannot be hardcoded -- and the
1574
- * describe mirror is empty until something populates it -- so every
1575
- * candidate is probed and the one whose value actually carries
1576
- * `providers` wins.
1577
- */
1578
- const candidates = () => {
1579
- let served = []
1580
- try {
1581
- const view = forms.describe().getSnapshot().view
1582
- served = (view?.namespaces ?? [])
1583
- .map((entry) => entry?.ns)
1584
- .filter((ns) => typeof ns === 'string')
1585
- } catch {}
1586
- return [...new Set([
1587
- LLM_NAMESPACE,
1588
- `include:${LLM_NAMESPACE}`,
1589
- ...served,
1590
- ...served.map((ns) => `include:${ns}`),
1591
- ])]
1592
- }
1593
- let cached = null
1594
- const target = {
1595
- tried: () => candidates(),
1596
- resolve: () => {
1597
- if (cached !== null) return cached
1598
- for (const namespace of candidates()) {
1599
- let form = null
1600
- try {
1601
- form = forms.get(namespace)
1602
- } catch {}
1603
- const value = form?.getSnapshot?.()?.value
1604
- if (value !== null && value !== undefined && typeof value === 'object' && value.providers !== undefined) {
1605
- cached = { namespace, form }
1606
- return cached
1607
- }
1608
- }
1609
- return null
1610
- },
1611
- /** Convenience for the row's render, which needs both halves. */
1612
- form: () => target.resolve()?.form ?? forms.get(LLM_NAMESPACE),
1613
- }
1614
- levelsForm = target
1615
- return ctx.slots.inject('settings.general.item', () =>
1616
- ctx.slots.register(
1617
- {
1618
- name: 'settings.general.item',
1619
- id: 'thinking-slider-levels',
1620
- order: 13,
1621
- inject: () => ({ target }),
1622
- },
1623
- LevelsRow,
1624
- ),
1625
- )
1626
- })
1627
- } catch (error) {
1628
- record('settings-levels', error)
1629
- }
1630
-
1631
1336
  ctx.inject(['slots', 'modelDirectories'], (scope) => {
1632
1337
  const slots = scope.slots
1633
1338
  const sessions = scope.sessions
@@ -1667,9 +1372,6 @@ window.__ModuleLoader__.load({
1667
1372
  if (available) directory.load().catch(() => {})
1668
1373
  },
1669
1374
  select: (selection) => (available ? directory.select(selection) : Promise.resolve(undefined)),
1670
- // Lets the card off the missing levels right where the user is
1671
- // looking, instead of only from Settings.
1672
- fillLevels: levelsForm === null ? undefined : (route) => fillProviderLevels(levelsForm, route),
1673
1375
  }
1674
1376
  } catch (error) {
1675
1377
  record('inject', error)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-thinking-slider",
3
- "version": "0.3.4",
4
- "description": "Codex-style reasoning-effort slider for the DeepSeek Harness composer: pick a model, then drag its thinking level on a gradient particle rail.",
3
+ "version": "0.4.0",
4
+ "description": "Three visual modes for picking a model's reasoning level in the DeepSeek Harness composer: hand back to the native selector, a gradient particle rail, or an energy-charging track. The levels themselves come from DSH.",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": "MuFeng262",