dsh-thinking-slider 0.1.0 → 0.3.4
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/README.md +57 -2
- package/lib/client.js +754 -29
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,23 +1,78 @@
|
|
|
1
1
|
# dsh-thinking-slider
|
|
2
2
|
|
|
3
|
+
[](https://awesome-dsh-plugin.com)
|
|
4
|
+
|
|
3
5
|
把 DeepSeek Harness(DSH)composer 里的**模型选择器**换成「模型 + 推理强度」:
|
|
4
6
|
平时显示 `模型名 · 等级`,点开是一张卡片 —— 上面是模型列表入口,下面是带**渐变与粒子**的强度滑块。
|
|
5
7
|
|
|
6
8
|
*An opinionated model + reasoning-effort picker for the DSH composer, with a gradient particle rail.*
|
|
7
9
|
|
|
8
|
-

|
|
9
11
|
|
|
10
12
|
## 它做什么
|
|
11
13
|
|
|
12
14
|
- **关闭态**:正常的一行文字 `deepseek-flash · Max`,不占地方
|
|
13
15
|
- **点开**:卡片里大字显示当前等级,`模型名 ›` 可切模型,下面一条厚滑块
|
|
14
|
-
-
|
|
16
|
+
- **拖滑块**:即时切换推理强度;视觉随等级变化(见下方三种模式)
|
|
15
17
|
- **键盘**:`←/→`、`Home/End` 切换,`Esc` 关闭
|
|
16
18
|
- **降级**:模型没有推理等级时只显示模型名,不出现滑块(不会给你一个假的控件)
|
|
17
19
|
|
|
18
20
|
等级**不写死在插件里** —— 它读 DSH 上报的 `model.reasoning.efforts`,
|
|
19
21
|
所以任何在配置里声明了 `reasoningEfforts` 的供应商路由都会自动出现在滑块上。
|
|
20
22
|
|
|
23
|
+
## 三种模式
|
|
24
|
+
|
|
25
|
+
在 **设置 → 通用 → 推理滑块** 里切换。模式存在浏览器本地(localStorage),
|
|
26
|
+
切换即时生效,不需要重启。
|
|
27
|
+
|
|
28
|
+
| 模式 | 效果 |
|
|
29
|
+
| --- | --- |
|
|
30
|
+
| **官方** | 插件完全不注册座位,交还 DSH 官方的模型选择器原样 |
|
|
31
|
+
| **粒子** | 轨道渐变 + 内部漂浮粒子,等级越高越密 |
|
|
32
|
+
| **能量充能** | 深色轨道上的点阵充能场,前沿从左扫入旋钮,最高档持续燃烧 |
|
|
33
|
+
|
|
34
|
+
| 官方 | 粒子 | 能量充能 |
|
|
35
|
+
| --- | --- | --- |
|
|
36
|
+
|  |  |  |
|
|
37
|
+
|
|
38
|
+
设置行**独立于座位注册**,所以即使选了「官方」也随时能切回来 —— 不会把自己锁在外面。
|
|
39
|
+
|
|
40
|
+
能量模式是 canvas 2D 的逐格衰减模拟(不是 WebGL,也没有引入依赖):
|
|
41
|
+
每格有自己的随机相位与速度,前沿扫过时依次点亮,靠近旋钮的格子落定成
|
|
42
|
+
「热核 + 曳光」,最高档则保持长记忆让整条轨道持续燃烧;中间档落定后
|
|
43
|
+
**主动停掉渲染循环**,静止不烧 CPU。
|
|
44
|
+
|
|
45
|
+
**浅色 / 深色是两套分开的配色**:深色下格子越热越漂向白色(靠近旋钮白热),
|
|
46
|
+
浅色下**保持本色饱和度、靠对比度表达等级** —— 浅色轨道本身已接近白色,
|
|
47
|
+
再往白漂就等于把格子从视野里抹掉。配色跟随 `data-ds-dark-theme` 实时切换,
|
|
48
|
+
不用重开卡片。
|
|
49
|
+
|
|
50
|
+
| 深色 | 浅色 |
|
|
51
|
+
| --- | --- |
|
|
52
|
+
|  |  |
|
|
53
|
+
|
|
54
|
+
## 让没有等级的模型真的能选等级
|
|
55
|
+
|
|
56
|
+
**先说原因**:等级要能真正生效,必须由 `reasoningEfforts` 给每个模型声明
|
|
57
|
+
「等级 → 发给网关的原始值」的映射。而 DSH 的「设置 → 模型」页面**没有这个字段**,
|
|
58
|
+
所以**任何通过 GUI 添加的代理商,模型都永远不会有等级**。
|
|
59
|
+
|
|
60
|
+
注意这不是"显示问题":DSH 会**直接拒绝**一个没有映射的等级(
|
|
61
|
+
`UNSUPPORTED_REASONING_EFFORT`,不是静默忽略)。它的注释写明了设计意图 ——
|
|
62
|
+
它宁可**不报告**任何等级,也不愿意提供一个"做不到自己所说事情"的控件。
|
|
63
|
+
(本插件早期版本试图在界面上补四档,结果每次点选都报错,已回退。)
|
|
64
|
+
|
|
65
|
+
**插件补上了这个缺口**:**设置 → 通用 → 模型推理等级** 会列出「有模型没声明等级的
|
|
66
|
+
代理商」,逐个点「补四档」即可。
|
|
67
|
+
|
|
68
|
+
- 写入的是 `llm-pi-ai` 的**真实配置**(与「设置 → 模型」同一份),所以等级**真的生效**
|
|
69
|
+
- 适配器每个请求都重读配置,**不需要重启**
|
|
70
|
+
- 只补**没有声明**的模型;已经声明过的原样保留
|
|
71
|
+
- **逐代理商确认,不做全自动**:若某个网关不接受 `reasoning_effort`,会让那个代理商
|
|
72
|
+
的请求全部失败。`none / low / high / max` 是实测可用的拼写,但**换网关要先试一个模型**
|
|
73
|
+
|
|
74
|
+

|
|
75
|
+
|
|
21
76
|
## 要求
|
|
22
77
|
|
|
23
78
|
- DSH Desktop 或 `dsh web`,内核 **0.2.x**(开发时验证于 `0.2.0-rc.1` / `0.2.0-rc.2`)
|
package/lib/client.js
CHANGED
|
@@ -31,6 +31,188 @@ window.__ModuleLoader__.load({
|
|
|
31
31
|
|
|
32
32
|
const LOG = '[dsh-thinking-slider]'
|
|
33
33
|
|
|
34
|
+
// ---------------------------------------------------------------------
|
|
35
|
+
// Mode preference.
|
|
36
|
+
//
|
|
37
|
+
// Deliberately client-local (localStorage) rather than a Host Config
|
|
38
|
+
// schema: a schema would require `@deepseek-ai/schemastery`, which is NOT
|
|
39
|
+
// resolvable from a plugin that lives outside `<profile>/node_modules`
|
|
40
|
+
// (the junction dev layout). The settings row below is registered into
|
|
41
|
+
// `settings.general.item`, which the settings panel renders without any
|
|
42
|
+
// namespace filtering, so no Host plumbing is needed at all.
|
|
43
|
+
// ---------------------------------------------------------------------
|
|
44
|
+
/** Selectable rail modes, in settings order. */
|
|
45
|
+
const MODES = ['official', 'particle', 'energy']
|
|
46
|
+
const MODE_LABELS = { official: '官方', particle: '粒子', energy: '能量充能' }
|
|
47
|
+
const MODE_HINTS = {
|
|
48
|
+
official: '完全交还 DSH 官方模型选择器',
|
|
49
|
+
particle: '轨道内漂浮粒子,等级越高越密',
|
|
50
|
+
energy: '能量向旋钮汇聚,落档时爆发,最高档持续燃烧',
|
|
51
|
+
}
|
|
52
|
+
const MODE_KEY = 'dsh-thinking-slider:mode'
|
|
53
|
+
const DEFAULT_MODE = 'particle'
|
|
54
|
+
|
|
55
|
+
const readMode = () => {
|
|
56
|
+
try {
|
|
57
|
+
const stored = globalThis.localStorage?.getItem(MODE_KEY)
|
|
58
|
+
return MODES.includes(stored) ? stored : DEFAULT_MODE
|
|
59
|
+
} catch {
|
|
60
|
+
return DEFAULT_MODE
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
let currentMode = readMode()
|
|
64
|
+
const modeListeners = new Set()
|
|
65
|
+
/** Current rail mode. */
|
|
66
|
+
const getMode = () => currentMode
|
|
67
|
+
/** Subscribe to mode changes (for `useSyncExternalStore`). */
|
|
68
|
+
const subscribeMode = (listener) => {
|
|
69
|
+
modeListeners.add(listener)
|
|
70
|
+
return () => modeListeners.delete(listener)
|
|
71
|
+
}
|
|
72
|
+
/** Switch the rail mode and persist it. */
|
|
73
|
+
const setMode = (next) => {
|
|
74
|
+
if (!MODES.includes(next) || next === currentMode) return
|
|
75
|
+
currentMode = next
|
|
76
|
+
try {
|
|
77
|
+
globalThis.localStorage?.setItem(MODE_KEY, next)
|
|
78
|
+
} catch {}
|
|
79
|
+
for (const listener of [...modeListeners]) listener()
|
|
80
|
+
}
|
|
81
|
+
/** React hook over the mode store. */
|
|
82
|
+
const useMode = () => react.useSyncExternalStore(subscribeMode, getMode, getMode)
|
|
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
|
+
// ---------------------------------------------------------------------
|
|
193
|
+
// Colour scheme.
|
|
194
|
+
//
|
|
195
|
+
// The theme boot script puts `data-ds-dark-theme` on <body>, which is the
|
|
196
|
+
// only signal that reflects a FORCED light/dark preference (matchMedia only
|
|
197
|
+
// reports the OS setting). Watching the attribute also keeps the rail
|
|
198
|
+
// correct if the user flips the theme with the card already open.
|
|
199
|
+
// ---------------------------------------------------------------------
|
|
200
|
+
const readDarkTheme = () =>
|
|
201
|
+
typeof document !== 'undefined' && document.body?.hasAttribute?.('data-ds-dark-theme') === true
|
|
202
|
+
|
|
203
|
+
const useDarkTheme = () => {
|
|
204
|
+
const [dark, setDark] = react.useState(readDarkTheme)
|
|
205
|
+
react.useEffect(() => {
|
|
206
|
+
const body = typeof document === 'undefined' ? undefined : document.body
|
|
207
|
+
if (body === undefined || body === null || typeof MutationObserver !== 'function') return undefined
|
|
208
|
+
const observer = new MutationObserver(() => setDark(readDarkTheme()))
|
|
209
|
+
observer.observe(body, { attributes: true, attributeFilter: ['data-ds-dark-theme'] })
|
|
210
|
+
setDark(readDarkTheme())
|
|
211
|
+
return () => observer.disconnect()
|
|
212
|
+
}, [])
|
|
213
|
+
return dark
|
|
214
|
+
}
|
|
215
|
+
|
|
34
216
|
// ---------------------------------------------------------------------
|
|
35
217
|
// Styles. Only confirmed theme tokens are used, each with a literal
|
|
36
218
|
// fallback so a token rename degrades rather than breaks.
|
|
@@ -46,7 +228,7 @@ window.__ModuleLoader__.load({
|
|
|
46
228
|
.tsl-triggerLevel{flex:none;max-width:112px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--dsw-alias-label-caption)}
|
|
47
229
|
.tsl-triggerChevron{flex:none;color:var(--dsw-alias-label-caption);transition:transform .12s ease}
|
|
48
230
|
.tsl-triggerChevronOpen{transform:rotate(180deg)}
|
|
49
|
-
.tsl-card{position:fixed;z-index:1100;--tsl-knob:26px;width:320px;padding:18px 18px 16px
|
|
231
|
+
.tsl-card{position:fixed;z-index:1100;--tsl-knob:26px;width:320px;padding:18px 18px 16px;--dsw-elevation-stroke-color:var(--dsw-alias-border-l1,rgba(127,127,127,.18));border:0;border-radius:16px;background:var(--dsw-specific-menu,var(--dsw-alias-bg-layer-1,#fff));backdrop-filter:var(--dsw-menu-backdrop-filter,none);-webkit-backdrop-filter:var(--dsw-menu-backdrop-filter,none);color:var(--dsw-alias-label-primary);box-shadow:var(--dsw-elevation-prominent,0 12px 40px rgba(0,0,0,.28));animation:tsl-in .14s ease-out}
|
|
50
232
|
@keyframes tsl-in{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}
|
|
51
233
|
@media (prefers-reduced-motion: reduce){.tsl-card{animation:none}}
|
|
52
234
|
.tsl-head{display:flex;align-items:center;justify-content:center;position:relative;min-height:26px;margin-bottom:2px}
|
|
@@ -60,7 +242,7 @@ window.__ModuleLoader__.load({
|
|
|
60
242
|
.tsl-trackWrap{position:relative;height:30px;display:flex;align-items:center;outline:none;cursor:pointer;touch-action:none}
|
|
61
243
|
.tsl-trackWrap[data-inert=true]{cursor:default;opacity:.55}
|
|
62
244
|
.tsl-trackWrap:focus-visible .tsl-track{box-shadow:0 0 0 2px var(--dsw-focus-ring-color,var(--dsw-alias-brand-primary,#4d6bfe))}
|
|
63
|
-
.tsl-track{position:relative;width:100%;height:var(--tsl-knob);border-radius:999px;background:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.16));overflow:hidden;transition:box-shadow .2s ease}
|
|
245
|
+
.tsl-track{position:relative;width:100%;height:var(--tsl-knob);border-radius:999px;background:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-2,rgba(127,127,127,.16)));overflow:hidden;transition:box-shadow .2s ease}
|
|
64
246
|
.tsl-fill{position:absolute;left:0;top:0;bottom:0;border-radius:999px;transition:width .18s ease}
|
|
65
247
|
.tsl-canvas{position:absolute;inset:0;width:100%;height:100%;pointer-events:none}
|
|
66
248
|
.tsl-ticks{position:absolute;inset:0;pointer-events:none}
|
|
@@ -69,7 +251,7 @@ window.__ModuleLoader__.load({
|
|
|
69
251
|
.tsl-scale{position:relative;height:16px;margin-top:6px;font-size:11px;line-height:16px;color:var(--dsw-alias-label-caption)}
|
|
70
252
|
.tsl-scaleItem{position:absolute;top:0;white-space:nowrap;transform:translateX(-50%);transition:color .18s ease}
|
|
71
253
|
.tsl-scaleItem[data-active=true]{font-weight:500}
|
|
72
|
-
.tsl-empty{margin-top:10px;font-size:12px;line-height:18px;text-align:center;color:var(--dsw-alias-label-caption)}
|
|
254
|
+
.tsl-empty{margin-top:10px;font-size:12px;line-height:18px;text-align:center;color:var(--dsw-alias-label-caption);display:flex;flex-direction:column;align-items:center;gap:8px}
|
|
73
255
|
.tsl-list{max-height:min(320px,50vh);overflow:auto;margin:0 -6px;padding:0 6px;--dsh-scrollbar-thumb:var(--dsw-alias-scrollbar-bg-l2);--dsh-scrollbar-thumb-hover:var(--dsw-alias-scrollbar-hover-l2)}
|
|
74
256
|
.tsl-group{margin:2px 0 6px;font-size:11px;line-height:16px;letter-spacing:.04em;text-transform:uppercase;color:var(--dsw-alias-label-caption)}
|
|
75
257
|
.tsl-item{display:flex;align-items:center;gap:8px;width:100%;padding:7px 8px;border:0;border-radius:8px;background:0 0;color:inherit;font:inherit;font-size:13px;text-align:left;cursor:pointer}
|
|
@@ -86,6 +268,21 @@ window.__ModuleLoader__.load({
|
|
|
86
268
|
.tsl-fallbackBadge{font-size:11px;color:var(--dsw-alias-state-warn-primary,#b7791f)}
|
|
87
269
|
.tsl-fallbackRetry{border:0;padding:0;background:0 0;color:inherit;font:inherit;font-size:11px;text-decoration:underline;cursor:pointer;opacity:.85}
|
|
88
270
|
.tsl-fallbackRetry:hover{opacity:1}
|
|
271
|
+
.tsl-settings{display:flex;flex-direction:column}
|
|
272
|
+
.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
|
+
.tsl-settingText{display:flex;flex-direction:column;gap:2px;min-width:0;flex:1 1 auto}
|
|
279
|
+
.tsl-settingTitle{font-size:13px;line-height:20px;color:var(--dsw-alias-label-primary)}
|
|
280
|
+
.tsl-settingHint{font-size:11px;line-height:16px;color:var(--dsw-alias-label-caption)}
|
|
281
|
+
.tsl-seg{flex:none;display:inline-flex;align-items:center;gap:2px;padding:2px;border-radius:999px;background:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-2,rgba(127,127,127,.16)))}
|
|
282
|
+
.tsl-segChoice{border:0;background:0 0;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;line-height:18px;padding:3px 10px;border-radius:999px;cursor:pointer;white-space:nowrap}
|
|
283
|
+
.tsl-segChoice:hover:not([data-active=true]){background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.12))}
|
|
284
|
+
.tsl-segChoice[data-active=true]{background:var(--dsw-alias-interactive-bg-active,var(--dsw-alias-bg-layer-1,#fff));color:var(--dsw-alias-label-primary);box-shadow:0 1px 3px rgba(0,0,0,.18)}
|
|
285
|
+
.tsl-segChoice:focus-visible{box-shadow:0 0 0 2px var(--dsw-focus-ring-color,var(--dsw-alias-brand-primary,#4d6bfe))}
|
|
89
286
|
`
|
|
90
287
|
const TAG_ID = 'dsh-thinking-slider/styles.css'
|
|
91
288
|
const installStyles = () => {
|
|
@@ -107,6 +304,7 @@ window.__ModuleLoader__.load({
|
|
|
107
304
|
const OFF_LOOK = {
|
|
108
305
|
gradient: 'linear-gradient(90deg, rgb(100, 116, 139) 0%, rgb(148, 163, 184) 100%)',
|
|
109
306
|
accent: 'rgb(148, 163, 184)',
|
|
307
|
+
tint: [148, 163, 184],
|
|
110
308
|
glow: 'rgba(148, 163, 184, 0.18)',
|
|
111
309
|
energy: 0,
|
|
112
310
|
}
|
|
@@ -157,9 +355,12 @@ window.__ModuleLoader__.load({
|
|
|
157
355
|
const low = STOPS[index]
|
|
158
356
|
const high = STOPS[index + 1]
|
|
159
357
|
const energy = low.energy + (high.energy - low.energy) * local
|
|
358
|
+
const tint = mix(low.to, high.to, local)
|
|
160
359
|
return {
|
|
161
|
-
gradient: `linear-gradient(90deg, ${rgb(mix(low.from, high.from, local))} 0%, ${rgb(
|
|
162
|
-
accent: rgb(
|
|
360
|
+
gradient: `linear-gradient(90deg, ${rgb(mix(low.from, high.from, local))} 0%, ${rgb(tint)} 100%)`,
|
|
361
|
+
accent: rgb(tint),
|
|
362
|
+
// Numeric channels: the canvas renderers tint their cells with these.
|
|
363
|
+
tint,
|
|
163
364
|
glow: `${local < 0.5 ? low.glow : high.glow}${(0.18 + energy * 0.42).toFixed(2)})`,
|
|
164
365
|
energy,
|
|
165
366
|
}
|
|
@@ -302,6 +503,185 @@ window.__ModuleLoader__.load({
|
|
|
302
503
|
}, [canvas, lookRef, repaintRef, enabled])
|
|
303
504
|
}
|
|
304
505
|
|
|
506
|
+
/**
|
|
507
|
+
* "Energy" rail: a cellular field that charges from the left into the knob.
|
|
508
|
+
*
|
|
509
|
+
* Modelled on the cellular look this mode is meant to echo — a fine dot
|
|
510
|
+
* lattice over a dark rail, cells igniting as a charging front sweeps
|
|
511
|
+
* through, a warm tail settling behind the knob, and the top level burning
|
|
512
|
+
* continuously — but reimplemented on canvas 2D as a per-cell decay
|
|
513
|
+
* simulation, so the plugin keeps its zero dependencies and its single-file
|
|
514
|
+
* bundle.
|
|
515
|
+
*
|
|
516
|
+
* Calm by design: intermediate levels settle to a static lit field and the
|
|
517
|
+
* loop stops; only the model's highest level keeps burning. `repaintRef`
|
|
518
|
+
* stays bound after the loop stops so the seat restarts it on the next level
|
|
519
|
+
* change.
|
|
520
|
+
*
|
|
521
|
+
* @param canvas - the mounted canvas node, or null while unmounted.
|
|
522
|
+
* @param lookRef - current visual state (energy, tint, fill fraction).
|
|
523
|
+
* @param repaintRef - receives a nudge function the seat calls on change.
|
|
524
|
+
* @param burstRef - a timestamp the seat writes to force a fresh charge.
|
|
525
|
+
* @param enabled - whether the rail should animate at all.
|
|
526
|
+
*/
|
|
527
|
+
function useEnergyField(canvas, lookRef, repaintRef, burstRef, enabled, darkTheme) {
|
|
528
|
+
react.useEffect(() => {
|
|
529
|
+
if (!enabled || canvas === null || canvas === undefined) return undefined
|
|
530
|
+
let context = null
|
|
531
|
+
try {
|
|
532
|
+
context = canvas.getContext('2d')
|
|
533
|
+
} catch (error) {
|
|
534
|
+
console.warn(LOG, 'canvas 2d unavailable for the energy rail', error)
|
|
535
|
+
}
|
|
536
|
+
if (context === null) return undefined
|
|
537
|
+
|
|
538
|
+
const reduceMotion = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
539
|
+
let frame = 0
|
|
540
|
+
let width = 0
|
|
541
|
+
let height = 0
|
|
542
|
+
let last = 0
|
|
543
|
+
/** Milliseconds since the level last moved; drives the charging front. */
|
|
544
|
+
let elapsed = 0
|
|
545
|
+
/** Last seen knob position, so a level change replays the front. */
|
|
546
|
+
let settledLimit = -1
|
|
547
|
+
let cells = []
|
|
548
|
+
let cellW = 4
|
|
549
|
+
let cellH = 4
|
|
550
|
+
|
|
551
|
+
/** Deterministic per-cell noise, so a cell keeps its identity across frames. */
|
|
552
|
+
const hash = (a, b) => {
|
|
553
|
+
const value = Math.sin(a * 127.1 + b * 311.7) * 43758.5453
|
|
554
|
+
return value - Math.floor(value)
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
const measure = () => {
|
|
558
|
+
const rect = canvas.getBoundingClientRect()
|
|
559
|
+
const dpr = Math.min(2, window.devicePixelRatio || 1)
|
|
560
|
+
width = Math.max(1, Math.round(rect.width))
|
|
561
|
+
height = Math.max(1, Math.round(rect.height))
|
|
562
|
+
canvas.width = Math.round(width * dpr)
|
|
563
|
+
canvas.height = Math.round(height * dpr)
|
|
564
|
+
context.setTransform(dpr, 0, 0, dpr, 0, 0)
|
|
565
|
+
// A constant cell size in CSS pixels: the lattice must not reflow when
|
|
566
|
+
// the rail changes width, and the front keeps a pixel speed.
|
|
567
|
+
cellW = 4
|
|
568
|
+
cellH = Math.max(3, height / 6)
|
|
569
|
+
const columns = Math.max(1, Math.round(width / cellW))
|
|
570
|
+
const rows = Math.max(1, Math.round(height / cellH))
|
|
571
|
+
cells = []
|
|
572
|
+
for (let row = 0; row < rows; row += 1) {
|
|
573
|
+
for (let column = 0; column < columns; column += 1) {
|
|
574
|
+
cells.push({ column, row, random: hash(column + 1, row + 1), level: 0 })
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
measure()
|
|
579
|
+
|
|
580
|
+
let observer = null
|
|
581
|
+
if (typeof ResizeObserver === 'function') {
|
|
582
|
+
observer = new ResizeObserver(measure)
|
|
583
|
+
observer.observe(canvas)
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
const draw = (now) => {
|
|
587
|
+
frame = 0
|
|
588
|
+
const delta = last === 0 ? 16.7 : Math.min(48, now - last)
|
|
589
|
+
last = now
|
|
590
|
+
const look = lookRef.current
|
|
591
|
+
const energy = clamp01(look.energy ?? 0)
|
|
592
|
+
const tint = Array.isArray(look.tint) ? look.tint : [148, 163, 184]
|
|
593
|
+
const knob = Math.min(height, width)
|
|
594
|
+
const limit = limitOf(width, height, look.fillFraction)
|
|
595
|
+
|
|
596
|
+
if (burstRef.current) {
|
|
597
|
+
burstRef.current = 0
|
|
598
|
+
elapsed = 0
|
|
599
|
+
}
|
|
600
|
+
if (limit !== settledLimit) {
|
|
601
|
+
settledLimit = limit
|
|
602
|
+
elapsed = 0
|
|
603
|
+
} else if (!reduceMotion) {
|
|
604
|
+
elapsed += delta
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// Retention is the one dial the level turns: a short afterimage while
|
|
608
|
+
// the front passes, long trails that fuse into a sheet at the top.
|
|
609
|
+
const retention = reduceMotion ? 0.92 : 0.18 + energy * 0.72
|
|
610
|
+
const pulse = 0.84 + Math.sin(now / 227) * 0.16
|
|
611
|
+
const frameIndex = Math.floor(now / 125)
|
|
612
|
+
// The settled field reaches much further at the top level, which is what
|
|
613
|
+
// makes Max read as a sustained burn rather than a dot by the knob.
|
|
614
|
+
const tail = Math.max(8, width * (0.10 + 0.30 * energy))
|
|
615
|
+
const seconds = elapsed / 1000
|
|
616
|
+
|
|
617
|
+
context.clearRect(0, 0, width, height)
|
|
618
|
+
|
|
619
|
+
for (const cell of cells) {
|
|
620
|
+
const x = cell.column * cellW + cellW / 2
|
|
621
|
+
const y = cell.row * cellH + cellH / 2
|
|
622
|
+
let target = 0
|
|
623
|
+
|
|
624
|
+
if (x <= limit + 0.5) {
|
|
625
|
+
// The front: each cell starts its own travel when the level moves,
|
|
626
|
+
// so the charge reads as a sweep rather than a wipe.
|
|
627
|
+
const traveled = seconds * 210 * (0.85 + cell.random * 0.30)
|
|
628
|
+
const front = Math.max(limit - traveled, knob * 0.5)
|
|
629
|
+
if (seconds < 1.6 && x >= front) {
|
|
630
|
+
const behind = clamp01((limit - x) / Math.max(limit - front, 1))
|
|
631
|
+
target = Math.pow(1 - behind, 0.65) * Math.min(seconds, 1) * 0.8
|
|
632
|
+
}
|
|
633
|
+
// The settled field: a bright core at the knob plus a warm tail,
|
|
634
|
+
// thinning per frame so it glitters rather than glowing flat.
|
|
635
|
+
const distance = Math.max(limit - x, 0)
|
|
636
|
+
const aura = Math.exp(-Math.pow(distance / tail, 1.35))
|
|
637
|
+
const core = Math.exp(-Math.pow((x - (limit - knob * 0.14)) / Math.max(3, knob * 0.16), 2))
|
|
638
|
+
const glitter = hash(cell.column + frameIndex * 13, cell.row + frameIndex * 29) > 0.58 - energy * 0.22 ? 1 : 0
|
|
639
|
+
const settled = Math.max(core, aura * glitter * 0.72) * (0.58 + cell.random * 0.42) * pulse
|
|
640
|
+
target = Math.max(target, settled * (0.52 + energy * 0.78))
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
cell.level = Math.max(target, cell.level * retention)
|
|
644
|
+
if (cell.level <= 0.02) continue
|
|
645
|
+
|
|
646
|
+
// Dark scheme: hotter cells bleach toward white, which is what makes
|
|
647
|
+
// the knob end read as white-hot. Light scheme: bleaching would wash
|
|
648
|
+
// the cells out against an already near-white rail, so the tint stays
|
|
649
|
+
// saturated and contrast carries the level instead.
|
|
650
|
+
const heat = darkTheme ? Math.min(1, cell.level * 1.6) * 0.85 : 0
|
|
651
|
+
const contrast = darkTheme ? 1.15 : 1.55
|
|
652
|
+
const channel = (value) => Math.round(value + (255 - value) * heat)
|
|
653
|
+
context.fillStyle = `rgba(${channel(tint[0])},${channel(tint[1])},${channel(tint[2])},${Math.min(1, cell.level * contrast).toFixed(3)})`
|
|
654
|
+
context.fillRect(x - cellW * 0.34, y - cellH * 0.32, cellW * 0.68, cellH * 0.64)
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// Keep burning at the top level and while the front travels; otherwise
|
|
658
|
+
// settle and stop, leaving a static lit field.
|
|
659
|
+
if (!reduceMotion && (energy >= 0.98 || seconds < 1.6)) frame = requestAnimationFrame(draw)
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
const start = () => {
|
|
663
|
+
if (frame !== 0) return
|
|
664
|
+
last = 0
|
|
665
|
+
if (reduceMotion) {
|
|
666
|
+
draw(0)
|
|
667
|
+
return
|
|
668
|
+
}
|
|
669
|
+
frame = requestAnimationFrame(draw)
|
|
670
|
+
}
|
|
671
|
+
repaintRef.current = start
|
|
672
|
+
start()
|
|
673
|
+
|
|
674
|
+
return () => {
|
|
675
|
+
if (frame !== 0) cancelAnimationFrame(frame)
|
|
676
|
+
frame = 0
|
|
677
|
+
repaintRef.current = null
|
|
678
|
+
observer?.disconnect()
|
|
679
|
+
cells = []
|
|
680
|
+
context.clearRect(0, 0, width, height)
|
|
681
|
+
}
|
|
682
|
+
}, [canvas, lookRef, repaintRef, burstRef, enabled, darkTheme])
|
|
683
|
+
}
|
|
684
|
+
|
|
305
685
|
// ---------------------------------------------------------------------
|
|
306
686
|
// Error boundary: the seat must never throw, or the slot renderer retires
|
|
307
687
|
// it and the shipped selector silently takes the seat back.
|
|
@@ -412,7 +792,7 @@ window.__ModuleLoader__.load({
|
|
|
412
792
|
}
|
|
413
793
|
|
|
414
794
|
function Seat(props) {
|
|
415
|
-
const { locked, available, directory, load, select } = props
|
|
795
|
+
const { locked, available, directory, load, select, fillLevels } = props
|
|
416
796
|
|
|
417
797
|
const state = react.useSyncExternalStore(
|
|
418
798
|
(subscribe) => directory.subscribe(subscribe),
|
|
@@ -433,10 +813,26 @@ window.__ModuleLoader__.load({
|
|
|
433
813
|
const [canvasNode, setCanvasNode] = react.useState(null)
|
|
434
814
|
const lookRef = react.useRef(OFF_LOOK)
|
|
435
815
|
const repaintRef = react.useRef(null)
|
|
436
|
-
|
|
816
|
+
/** Non-zero once a commit asks the energy rail for a burst. */
|
|
817
|
+
const burstRef = react.useRef(0)
|
|
818
|
+
const mode = useMode()
|
|
819
|
+
const darkTheme = useDarkTheme()
|
|
820
|
+
|
|
821
|
+
/**
|
|
822
|
+
* Load the model directory once per session, not once per render.
|
|
823
|
+
*
|
|
824
|
+
* `load` arrives from the slot entry, which rebuilds it on every render, so
|
|
825
|
+
* depending on it directly made this effect fire on each pass and re-fetch
|
|
826
|
+
* the directory every time the composer re-rendered — invisible in-process,
|
|
827
|
+
* a visible stall on every reasoning-level change where the store is remote.
|
|
828
|
+
* `directory` is the stable per-session identity, so it is the honest
|
|
829
|
+
* dependency; the ref keeps the newest closure without re-triggering.
|
|
830
|
+
*/
|
|
831
|
+
const loadRef = react.useRef(load)
|
|
832
|
+
loadRef.current = load
|
|
437
833
|
react.useEffect(() => {
|
|
438
|
-
if (available === true)
|
|
439
|
-
}, [available,
|
|
834
|
+
if (available === true) loadRef.current()
|
|
835
|
+
}, [available, directory])
|
|
440
836
|
|
|
441
837
|
const groups = Array.isArray(state?.groups) ? state.groups : []
|
|
442
838
|
const failures = Array.isArray(state?.failures) ? state.failures : []
|
|
@@ -456,7 +852,24 @@ window.__ModuleLoader__.load({
|
|
|
456
852
|
const efforts = Array.isArray(currentModel?.reasoning?.efforts) ? currentModel.reasoning.efforts : []
|
|
457
853
|
const supported = efforts.length > 0
|
|
458
854
|
const activeEffort = current?.reasoningEffort ?? currentModel?.reasoning?.defaultEffort ?? null
|
|
459
|
-
|
|
855
|
+
/**
|
|
856
|
+
* The level the user just committed, shown before the store round-trip
|
|
857
|
+
* lands. Serving the level straight from `activeEffort` means the rail sits
|
|
858
|
+
* on the OLD level until the host answers, which reads as a stall where the
|
|
859
|
+
* store is remote (`dsh web`) even though it is imperceptible in-process.
|
|
860
|
+
*/
|
|
861
|
+
const [optimistic, setOptimistic] = react.useState(null)
|
|
862
|
+
react.useEffect(() => {
|
|
863
|
+
if (optimistic === null) return undefined
|
|
864
|
+
if (optimistic === activeEffort) {
|
|
865
|
+
setOptimistic(null)
|
|
866
|
+
return undefined
|
|
867
|
+
}
|
|
868
|
+
// Never mask the real level for long if the write never lands.
|
|
869
|
+
const timer = setTimeout(() => setOptimistic(null), 4000)
|
|
870
|
+
return () => clearTimeout(timer)
|
|
871
|
+
}, [optimistic, activeEffort])
|
|
872
|
+
const shownEffort = preview ?? optimistic ?? activeEffort
|
|
460
873
|
const busy = state?.pending !== null && state?.pending !== undefined
|
|
461
874
|
const inert = locked === true || available !== true || current === null || !supported
|
|
462
875
|
|
|
@@ -480,7 +893,9 @@ window.__ModuleLoader__.load({
|
|
|
480
893
|
repaintRef.current?.()
|
|
481
894
|
}, [look, fillFraction, lookRef, repaintRef])
|
|
482
895
|
|
|
483
|
-
|
|
896
|
+
const railLive = open && supported
|
|
897
|
+
useParticles(canvasNode, lookRef, repaintRef, railLive && mode === 'particle')
|
|
898
|
+
useEnergyField(canvasNode, lookRef, repaintRef, burstRef, railLive && mode === 'energy', darkTheme)
|
|
484
899
|
|
|
485
900
|
const activeLabel = !supported
|
|
486
901
|
? state?.retainedEffort ?? '推理等级'
|
|
@@ -491,7 +906,10 @@ window.__ModuleLoader__.load({
|
|
|
491
906
|
|
|
492
907
|
const commit = react.useCallback(
|
|
493
908
|
async (effort) => {
|
|
494
|
-
if (current === null || effort === activeEffort) return
|
|
909
|
+
if (current === null || effort === activeEffort || effort === optimistic) return
|
|
910
|
+
// Show the choice immediately; the effect above drops it once the
|
|
911
|
+
// session reports the new level (or after a timeout).
|
|
912
|
+
setOptimistic(effort)
|
|
495
913
|
try {
|
|
496
914
|
const result = await select({
|
|
497
915
|
provider: current.provider,
|
|
@@ -499,16 +917,21 @@ window.__ModuleLoader__.load({
|
|
|
499
917
|
...(effort === null || effort === undefined ? {} : { reasoningEffort: effort }),
|
|
500
918
|
})
|
|
501
919
|
if (result !== undefined && result !== null && result.ok === false) {
|
|
920
|
+
setOptimistic(null)
|
|
502
921
|
setNotice(`${result.error?.code ?? 'error'}: ${result.error?.message ?? '选择失败'}`)
|
|
503
922
|
} else {
|
|
504
923
|
setNotice(null)
|
|
924
|
+
// A committed level releases one burst on the energy rail.
|
|
925
|
+
burstRef.current = Date.now()
|
|
926
|
+
repaintRef.current?.()
|
|
505
927
|
}
|
|
506
928
|
} catch (error) {
|
|
507
929
|
console.error(LOG, 'selection failed', error)
|
|
930
|
+
setOptimistic(null)
|
|
508
931
|
setNotice(String(error?.message ?? error))
|
|
509
932
|
}
|
|
510
933
|
},
|
|
511
|
-
[activeEffort, current, select],
|
|
934
|
+
[activeEffort, current, optimistic, select],
|
|
512
935
|
)
|
|
513
936
|
|
|
514
937
|
const effortAt = react.useCallback(
|
|
@@ -710,7 +1133,9 @@ window.__ModuleLoader__.load({
|
|
|
710
1133
|
style: {
|
|
711
1134
|
width: centerOf(Math.max(0, index), Math.max(1, efforts.length)),
|
|
712
1135
|
background: look.gradient,
|
|
713
|
-
|
|
1136
|
+
// The energy rail is a dot lattice over a DARK track, so its
|
|
1137
|
+
// gradient fill is suppressed and the canvas carries the colour.
|
|
1138
|
+
opacity: mode === 'energy' ? 0 : isOff ? 0.45 : 1,
|
|
714
1139
|
},
|
|
715
1140
|
}),
|
|
716
1141
|
jsx('canvas', { ref: setCanvasNode, className: 'tsl-canvas' }),
|
|
@@ -734,6 +1159,22 @@ window.__ModuleLoader__.load({
|
|
|
734
1159
|
],
|
|
735
1160
|
})
|
|
736
1161
|
|
|
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
|
+
|
|
737
1178
|
const effortPane = jsxs('div', {
|
|
738
1179
|
children: [
|
|
739
1180
|
jsxs('div', {
|
|
@@ -781,7 +1222,23 @@ window.__ModuleLoader__.load({
|
|
|
781
1222
|
}),
|
|
782
1223
|
],
|
|
783
1224
|
}),
|
|
784
|
-
supported
|
|
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
|
+
}),
|
|
785
1242
|
supported ? scale : null,
|
|
786
1243
|
notice !== null ? jsx('div', { className: 'tsl-failure', children: notice }) : null,
|
|
787
1244
|
],
|
|
@@ -960,23 +1417,236 @@ window.__ModuleLoader__.load({
|
|
|
960
1417
|
'background:#3a1d1d', 'color:#ffd7d7', 'font:12px/18px ui-monospace,monospace',
|
|
961
1418
|
'box-shadow:0 10px 30px rgba(0,0,0,.45)', 'white-space:pre-wrap',
|
|
962
1419
|
].join(';')
|
|
963
|
-
box.textContent = `dsh-thinking-slider ${entry.phase} 失败:\n${entry.message}\n\n
|
|
1420
|
+
box.textContent = `dsh-thinking-slider ${entry.phase} 失败:\n${entry.message}\n\n`
|
|
1421
|
+
+ '每页只弹第一条错误;其余(含更早的)都在 __dshThinkingSlider.diagnostics 里,\n'
|
|
1422
|
+
+ 'Console 里跑 copy(JSON.stringify(__dshThinkingSlider, null, 2)) 即可取到。\n'
|
|
1423
|
+
+ '(截图给我即可定位;点此关闭)'
|
|
964
1424
|
box.addEventListener('click', () => box.remove())
|
|
965
1425
|
document.body.appendChild(box)
|
|
966
1426
|
} catch {}
|
|
967
1427
|
}
|
|
968
1428
|
|
|
1429
|
+
/**
|
|
1430
|
+
* The Settings → General row that picks the rail mode.
|
|
1431
|
+
*
|
|
1432
|
+
* Reads the module-level mode store directly, so it needs neither a Host
|
|
1433
|
+
* Config namespace nor a slot store: `settings.general.item` renders every
|
|
1434
|
+
* registration unconditionally.
|
|
1435
|
+
*/
|
|
1436
|
+
function ModeRow() {
|
|
1437
|
+
const mode = useMode()
|
|
1438
|
+
return jsxs('div', {
|
|
1439
|
+
className: 'tsl-setting',
|
|
1440
|
+
children: [
|
|
1441
|
+
jsxs('div', {
|
|
1442
|
+
className: 'tsl-settingText',
|
|
1443
|
+
children: [
|
|
1444
|
+
jsx('span', { className: 'tsl-settingTitle', children: '推理滑块' }),
|
|
1445
|
+
jsx('span', { className: 'tsl-settingHint', children: MODE_HINTS[mode] ?? MODE_HINTS.particle }),
|
|
1446
|
+
],
|
|
1447
|
+
}),
|
|
1448
|
+
jsx('div', {
|
|
1449
|
+
className: 'tsl-seg',
|
|
1450
|
+
role: 'radiogroup',
|
|
1451
|
+
'aria-label': '推理滑块模式',
|
|
1452
|
+
children: MODES.map((id) => jsx('button', {
|
|
1453
|
+
type: 'button',
|
|
1454
|
+
role: 'radio',
|
|
1455
|
+
'aria-checked': mode === id,
|
|
1456
|
+
'data-active': mode === id,
|
|
1457
|
+
className: 'tsl-segChoice',
|
|
1458
|
+
title: MODE_HINTS[id],
|
|
1459
|
+
onClick: () => setMode(id),
|
|
1460
|
+
children: MODE_LABELS[id],
|
|
1461
|
+
}, id)),
|
|
1462
|
+
}),
|
|
1463
|
+
],
|
|
1464
|
+
})
|
|
1465
|
+
}
|
|
1466
|
+
|
|
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
|
+
|
|
969
1536
|
function apply(ctx) {
|
|
970
1537
|
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
|
+
// The mode row lives in Settings → General, independent of whether the
|
|
1548
|
+
// composer seat has a place to mount.
|
|
1549
|
+
try {
|
|
1550
|
+
ctx.slots.inject('settings.general.item', () =>
|
|
1551
|
+
ctx.slots.register(
|
|
1552
|
+
{ name: 'settings.general.item', id: 'thinking-slider-mode', order: 12 },
|
|
1553
|
+
ModeRow,
|
|
1554
|
+
),
|
|
1555
|
+
)
|
|
1556
|
+
} catch (error) {
|
|
1557
|
+
record('settings-row', error)
|
|
1558
|
+
}
|
|
1559
|
+
|
|
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
|
+
|
|
971
1631
|
ctx.inject(['slots', 'modelDirectories'], (scope) => {
|
|
972
1632
|
const slots = scope.slots
|
|
973
1633
|
const sessions = scope.sessions
|
|
974
1634
|
const models = scope.modelDirectories
|
|
975
1635
|
|
|
976
|
-
let generation = 0
|
|
977
1636
|
let recoveries = 0
|
|
978
1637
|
let handle = null
|
|
979
1638
|
let stopped = false
|
|
1639
|
+
/**
|
|
1640
|
+
* Whether the seat's slot currently has a live declaration.
|
|
1641
|
+
*
|
|
1642
|
+
* `conversation.input.model` is declared by ui-conversation's composer
|
|
1643
|
+
* bar, NOT by this plugin, and the two plugins' `apply()` order is not
|
|
1644
|
+
* guaranteed. Registering while it is undeclared throws
|
|
1645
|
+
* `slot "..." is not declared`, so registration is gated on this flag
|
|
1646
|
+
* rather than merely on the mode: a profile that applies this plugin
|
|
1647
|
+
* first must not be able to reach `register()` at all.
|
|
1648
|
+
*/
|
|
1649
|
+
let declared = false
|
|
980
1650
|
|
|
981
1651
|
/**
|
|
982
1652
|
* The per-session face handed to the seat.
|
|
@@ -997,6 +1667,9 @@ window.__ModuleLoader__.load({
|
|
|
997
1667
|
if (available) directory.load().catch(() => {})
|
|
998
1668
|
},
|
|
999
1669
|
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),
|
|
1000
1673
|
}
|
|
1001
1674
|
} catch (error) {
|
|
1002
1675
|
record('inject', error)
|
|
@@ -1009,14 +1682,21 @@ window.__ModuleLoader__.load({
|
|
|
1009
1682
|
}
|
|
1010
1683
|
}
|
|
1011
1684
|
|
|
1012
|
-
/**
|
|
1685
|
+
/**
|
|
1686
|
+
* Claim the lowest free priority at or below the base.
|
|
1687
|
+
*
|
|
1688
|
+
* The walk restarts from the base on every call — deliberately NOT a
|
|
1689
|
+
* shared counter. Disposing our own registration frees its priority, so
|
|
1690
|
+
* a counter would march the seat down one step per remount (mode
|
|
1691
|
+
* switches, hot reloads) and eventually exhaust the budget, at which
|
|
1692
|
+
* point the seat would silently vanish. Only a priority still held by a
|
|
1693
|
+
* genuinely leaked predecessor makes the walk step down.
|
|
1694
|
+
*/
|
|
1013
1695
|
const register = () => {
|
|
1014
|
-
|
|
1015
|
-
const priority = BASE_PRIORITY - generation
|
|
1016
|
-
generation += 1
|
|
1696
|
+
for (let attempt = 0; attempt < MAX_GENERATIONS; attempt += 1) {
|
|
1017
1697
|
try {
|
|
1018
1698
|
handle = slots.register(
|
|
1019
|
-
{ name: SLOT, priority, inject: face },
|
|
1699
|
+
{ name: SLOT, priority: BASE_PRIORITY - attempt, inject: face },
|
|
1020
1700
|
(props) => jsx(SeatBoundary, { face: props }),
|
|
1021
1701
|
)
|
|
1022
1702
|
return handle
|
|
@@ -1028,35 +1708,80 @@ window.__ModuleLoader__.load({
|
|
|
1028
1708
|
// A predecessor leaked its registration; step down and retry.
|
|
1029
1709
|
}
|
|
1030
1710
|
}
|
|
1031
|
-
record('register', new Error(`no free priority after ${MAX_GENERATIONS}
|
|
1711
|
+
record('register', new Error(`no free priority after ${MAX_GENERATIONS} attempts`))
|
|
1032
1712
|
return null
|
|
1033
1713
|
}
|
|
1034
1714
|
|
|
1715
|
+
const mountSeat = () => {
|
|
1716
|
+
if (stopped || handle !== null || !declared) return handle
|
|
1717
|
+
if (getMode() === 'official') return null
|
|
1718
|
+
handle = register()
|
|
1719
|
+
return handle
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
const unmountSeat = () => {
|
|
1723
|
+
if (handle === null) return
|
|
1724
|
+
try {
|
|
1725
|
+
handle()
|
|
1726
|
+
} catch {}
|
|
1727
|
+
handle = null
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1035
1730
|
/** Put the seat back after the renderer retired it for a crash. */
|
|
1036
1731
|
const recover = (error) => {
|
|
1037
1732
|
record('entry-error', error)
|
|
1038
1733
|
if (stopped || recoveries >= MAX_RECOVERIES) return
|
|
1039
1734
|
recoveries += 1
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
} catch {}
|
|
1043
|
-
handle = null
|
|
1044
|
-
register()
|
|
1735
|
+
unmountSeat()
|
|
1736
|
+
mountSeat()
|
|
1045
1737
|
}
|
|
1046
1738
|
|
|
1047
1739
|
const stopErrors = typeof slots.onEntryError === 'function'
|
|
1048
1740
|
? slots.onEntryError((key, _entry, error, info) => {
|
|
1049
1741
|
if (key !== SLOT || info?.abdicated !== true) return
|
|
1742
|
+
if (getMode() === 'official') return
|
|
1050
1743
|
recover(error)
|
|
1051
1744
|
})
|
|
1052
1745
|
: undefined
|
|
1053
1746
|
|
|
1054
|
-
|
|
1747
|
+
/**
|
|
1748
|
+
* Mount or unmount the seat to match the current mode.
|
|
1749
|
+
*
|
|
1750
|
+
* `official` hands the composer back to the shipped selector by simply
|
|
1751
|
+
* not registering: an absent entry lets the lower-priority shipped one
|
|
1752
|
+
* render, which is why no placeholder is needed. Re-registering after
|
|
1753
|
+
* a mode switch reuses the freed base priority.
|
|
1754
|
+
*/
|
|
1755
|
+
const syncMode = () => {
|
|
1756
|
+
if (stopped) return
|
|
1757
|
+
if (getMode() === 'official') unmountSeat()
|
|
1758
|
+
else mountSeat()
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
const stopMode = subscribeMode(syncMode)
|
|
1762
|
+
|
|
1763
|
+
/**
|
|
1764
|
+
* The one path that can turn registration on.
|
|
1765
|
+
*
|
|
1766
|
+
* SlotService.inject runs its callback synchronously when the
|
|
1767
|
+
* declaration already exists, and again for every later declaration
|
|
1768
|
+
* lifetime (collapse disposes it first). Both the first arrival and a
|
|
1769
|
+
* re-declaration therefore land here, and both respect the mode.
|
|
1770
|
+
*/
|
|
1771
|
+
const stopInject = slots.inject(SLOT, () => {
|
|
1772
|
+
declared = true
|
|
1773
|
+
syncMode()
|
|
1774
|
+
return () => {
|
|
1775
|
+
declared = false
|
|
1776
|
+
unmountSeat()
|
|
1777
|
+
}
|
|
1778
|
+
})
|
|
1055
1779
|
|
|
1056
1780
|
// Owned by THIS plugin's fiber, so a hot reload disposes the seat
|
|
1057
1781
|
// instead of leaving a registration that blocks the next generation.
|
|
1058
1782
|
return () => {
|
|
1059
1783
|
stopped = true
|
|
1784
|
+
try { stopMode() } catch {}
|
|
1060
1785
|
try { stopInject?.() } catch {}
|
|
1061
1786
|
try { stopErrors?.() } catch {}
|
|
1062
1787
|
try { handle?.() } catch {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-thinking-slider",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.4",
|
|
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.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|