dsh-codex-model-effort-ui 1.1.7 → 1.1.8
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 +18 -2
- package/client.effort.js +14 -94
- package/client.js +98 -901
- package/client.styles.js +918 -286
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* 面板包含两个页面:
|
|
6
|
-
*
|
|
7
|
-
* - `models` —— 按提供方分组的模型列表(Codex 列表样式)
|
|
8
|
-
* - `effort` —— 像素级复刻的推理强度滑杆
|
|
9
|
-
*/
|
|
1
|
+
// Codex 风格的模型/推理强度选择器,替换 DSH 输入框的 model 座位。
|
|
2
|
+
// chunk 结构:client.js(装配+主组件)、client.hooks.js(通用 Hook)、
|
|
3
|
+
// client.effort.js(强度纯函数)、client.styles.js(CSS)、client.views.js(渲染函数)
|
|
4
|
+
// chunk 之间不能静态 import,只能通过 props 传递模块对象(hooksApi / effortApi / viewsApi / metrics)。
|
|
10
5
|
|
|
11
6
|
window.__ModuleLoader__.load({
|
|
12
7
|
id: 'dsh-codex-model-effort-ui',
|
|
@@ -19,11 +14,8 @@ window.__ModuleLoader__.load({
|
|
|
19
14
|
const NS = 'dsh-codex-model-effort-ui';
|
|
20
15
|
const P = 'cmes'; // 类名前缀
|
|
21
16
|
|
|
22
|
-
/*
|
|
23
|
-
|
|
24
|
-
* ------------------------------------------------------------------ */
|
|
25
|
-
/* 两个词典必须携带完全相同的键集合。强度标签也放在这里
|
|
26
|
-
* 语言时强度阶梯会实时重新本地化——无需刷新,也无需重新挂载。 */
|
|
17
|
+
/* ------------------------------------------------------------ */
|
|
18
|
+
/* 两个词典必须携带完全相同的键集合 */
|
|
27
19
|
const zh = {
|
|
28
20
|
choose: '选择模型', effort: '推理强度', fast: '1.5 倍速',
|
|
29
21
|
usage: '用量更多', visual: '(仅视觉效果)', reset: '重置为默认',
|
|
@@ -83,14 +75,11 @@ window.__ModuleLoader__.load({
|
|
|
83
75
|
mo.observe(document.body, { attributes: true, attributeFilter: ['data-ds-dark-theme'] });
|
|
84
76
|
return () => mo.disconnect();
|
|
85
77
|
}
|
|
86
|
-
/** 组件树使用的响应式深色模式标志。 */
|
|
87
78
|
function useDarkTheme() {
|
|
88
79
|
return useSyncExternalStore(subscribeTheme, isDarkNow, () => false);
|
|
89
80
|
}
|
|
90
81
|
|
|
91
|
-
/*
|
|
92
|
-
* 图标(手绘路径;不含第三方资源)
|
|
93
|
-
* ------------------------------------------------------------------ */
|
|
82
|
+
/* ------------------------------------------------------------ */
|
|
94
83
|
const ICON = {
|
|
95
84
|
chevron: 'm9 18 6-6-6-6',
|
|
96
85
|
down: 'm6 9 6 6 6-6',
|
|
@@ -109,11 +98,7 @@ window.__ModuleLoader__.load({
|
|
|
109
98
|
}, h('path', { d: ICON[name] || ICON.chevron }));
|
|
110
99
|
}
|
|
111
100
|
|
|
112
|
-
/* 焦点陷阱:弹层是 role="dialog",Tab
|
|
113
|
-
* 在弹层打开期间拦下 Tab,在「首个 / 末个」可聚焦元素处掉头循环,
|
|
114
|
-
* 把焦点始终圈在弹层内。只处理 Tab,其余按键(方向键 / Enter /
|
|
115
|
-
* Escape)原样放行,不与滑轨、搜索框、模型列表的键盘逻辑抢事件。
|
|
116
|
-
* 宿主若注入了自己的陷阱,这里只是冗余兜底;未注入时补齐缺口。 */
|
|
101
|
+
/* 焦点陷阱:弹层是 role="dialog",Tab 不该走出它落到背景页上 */
|
|
117
102
|
const FOCUSABLE = 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])';
|
|
118
103
|
function trapFocus(section, event) {
|
|
119
104
|
if (event.key !== 'Tab') return;
|
|
@@ -129,404 +114,30 @@ window.__ModuleLoader__.load({
|
|
|
129
114
|
event.preventDefault(); first.focus({ preventScroll: true });
|
|
130
115
|
}
|
|
131
116
|
}
|
|
132
|
-
|
|
133
|
-
/* ------------------------------------------------------------------ *
|
|
134
|
-
* Fast 开关 —— 按会话持久化
|
|
135
|
-
* 本插件是 fail-open 的,因此每次存储访问都有保护:失败只损失重启后
|
|
136
|
-
* 的恢复,绝不会影响输入框。
|
|
137
|
-
* ------------------------------------------------------------------ */
|
|
138
|
-
const FAST_STORE_PREFIX = 'dsh.codex-effort-selector.fast.v1.';
|
|
139
|
-
const fastMemory = new Map();
|
|
140
|
-
function readFast(sessionId) {
|
|
141
|
-
if (!sessionId) return false;
|
|
142
|
-
if (fastMemory.has(sessionId)) return fastMemory.get(sessionId);
|
|
143
|
-
try {
|
|
144
|
-
if (typeof localStorage === 'undefined') return false;
|
|
145
|
-
return localStorage.getItem(FAST_STORE_PREFIX + sessionId) === '1';
|
|
146
|
-
} catch { return false; }
|
|
147
|
-
}
|
|
148
|
-
function writeFast(sessionId, on) {
|
|
149
|
-
if (!sessionId) return;
|
|
150
|
-
fastMemory.set(sessionId, on);
|
|
151
|
-
try {
|
|
152
|
-
if (typeof localStorage === 'undefined') return;
|
|
153
|
-
localStorage.setItem(FAST_STORE_PREFIX + sessionId, on ? '1' : '0');
|
|
154
|
-
} catch { /* 存储被禁用 —— 内存镜像仍然保留该值 */ }
|
|
155
|
-
}
|
|
156
|
-
|
|
157
117
|
function Selector(props) {
|
|
158
118
|
return typeof props.useProjection === 'function'
|
|
159
119
|
? h(TeamProjectionBridge, props)
|
|
160
120
|
: h(SelectorImpl, props);
|
|
161
121
|
}
|
|
162
122
|
|
|
163
|
-
/* 只在宿主提供 `useProjection`
|
|
123
|
+
/* 只在宿主提供 `useProjection` 时挂载:这里对它的调用是无条件的 */
|
|
164
124
|
function TeamProjectionBridge(props) {
|
|
165
125
|
const teamMode = props.useProjection('agentTeam');
|
|
166
126
|
return h(SelectorImpl, { ...props, teamMode });
|
|
167
127
|
}
|
|
168
128
|
|
|
169
|
-
/*
|
|
170
|
-
* 可复用的定位 / 状态 Hook
|
|
171
|
-
* ================================================================== */
|
|
129
|
+
/* ============================================================ */
|
|
172
130
|
|
|
173
|
-
/* 弹层与 tooltip 都通过 createPortal 渲染到 document.body(见 render 处
|
|
174
|
-
* 的说明),因此它们的 position:fixed 恒相对视口解析——不必再测量包含块,
|
|
175
|
-
* 直接写视口坐标即可。 */
|
|
176
|
-
function positionAbove(anchor, tip, fallbackW, fallbackH) {
|
|
177
|
-
if (!anchor || !tip) return;
|
|
178
|
-
const r = anchor.getBoundingClientRect();
|
|
179
|
-
const tw = tip.offsetWidth || fallbackW;
|
|
180
|
-
const th = tip.offsetHeight || fallbackH;
|
|
181
|
-
const left = Math.max(8, Math.min(r.left + r.width / 2 - tw / 2, window.innerWidth - tw - 8));
|
|
182
|
-
const top = Math.max(8, r.top - th - 7);
|
|
183
|
-
tip.style.left = `${left}px`;
|
|
184
|
-
tip.style.top = `${top}px`;
|
|
185
|
-
}
|
|
131
|
+
/* 弹层与 tooltip 都通过 createPortal 渲染到 document.body(见 render 处 */
|
|
186
132
|
|
|
187
|
-
|
|
188
|
-
useLayoutEffect(() => {
|
|
189
|
-
if (!shown) return;
|
|
190
|
-
const place = () => positionAbove(anchorRef.current, tipRef.current, fallbackW, fallbackH);
|
|
191
|
-
place();
|
|
192
|
-
window.addEventListener('resize', place);
|
|
193
|
-
document.addEventListener('scroll', place, true);
|
|
194
|
-
return () => {
|
|
195
|
-
window.removeEventListener('resize', place);
|
|
196
|
-
document.removeEventListener('scroll', place, true);
|
|
197
|
-
};
|
|
198
|
-
}, [shown, anchorRef, tipRef, fallbackW, fallbackH]);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/* 弹出面板的定位、高度余量与外部关闭 / Escape。
|
|
202
|
-
* 回调经 ref 读取,监听器只随 open 重绑一次,避免闭包过期。 */
|
|
203
|
-
function usePopoverLayout({ open, rootRef, popupRef, triggerRef, onOutside, onEscape }) {
|
|
204
|
-
const [room, setRoom] = useState(0);
|
|
205
|
-
const handlersRef = useRef({ onOutside, onEscape });
|
|
206
|
-
useLayoutEffect(() => { handlersRef.current = { onOutside, onEscape }; });
|
|
133
|
+
/* 弹出面板的定位、高度余量与外部关闭 / Escape */
|
|
207
134
|
|
|
208
|
-
|
|
209
|
-
* 只读 ref 与 window,因此是引用稳定的——既能被下面的 layout effect
|
|
210
|
-
* 绑定到事件上,也能被 `primeRoom` 在打开前直接调用,把首帧的
|
|
211
|
-
* top/left 一并预置(否则首帧会用 CSS 里的回退坐标画一帧再跳正)。 */
|
|
212
|
-
const align = React.useCallback(() => {
|
|
213
|
-
const trigger = triggerRef.current?.getBoundingClientRect();
|
|
214
|
-
const popup = popupRef.current;
|
|
215
|
-
if (!trigger || !popup || !popup.isConnected) return;
|
|
216
|
-
const width = Math.min(272, window.innerWidth - 24);
|
|
217
|
-
const left = Math.max(12, Math.min((trigger.left + trigger.right - width) / 2, window.innerWidth - width - 12));
|
|
218
|
-
/* 弹出面板 portal 到 body,position:fixed 恒相对视口,所以直接用
|
|
219
|
-
* 视口坐标:面板底边停在触发按钮上方 8px。 */
|
|
220
|
-
popup.style.setProperty(`--${P}-left`, `${left}px`);
|
|
221
|
-
popup.style.setProperty(`--${P}-top`, `${Math.max(12, trigger.top - popup.offsetHeight - 8)}px`);
|
|
222
|
-
/* 触发按钮上方的空间:驱动高度钳制,同时写回 state,让 render
|
|
223
|
-
* 不必自己读布局。 */
|
|
224
|
-
const roomAbove = Math.max(120, trigger.top - 20);
|
|
225
|
-
popup.style.setProperty(`--${P}-room`, `${roomAbove}px`);
|
|
226
|
-
setRoom(prev => (prev === roomAbove ? prev : roomAbove));
|
|
227
|
-
}, [popupRef, triggerRef]);
|
|
228
|
-
|
|
229
|
-
useLayoutEffect(() => {
|
|
230
|
-
if (!open) return;
|
|
231
|
-
let frame = 0;
|
|
232
|
-
function outside(event) {
|
|
233
|
-
/* 弹出面板 portal 到 body,已不在 `.cmes-root` 之内:外部点击判定
|
|
234
|
-
* 必须把面板与触发按钮一并视为「内部」,否则点面板自身会把它关掉。 */
|
|
235
|
-
const target = event.target;
|
|
236
|
-
if (rootRef.current?.contains(target)) return;
|
|
237
|
-
if (popupRef.current?.contains(target)) return;
|
|
238
|
-
if (target instanceof Node && triggerRef.current?.contains(target)) return;
|
|
239
|
-
handlersRef.current.onOutside(event);
|
|
240
|
-
}
|
|
241
|
-
function escape(event) {
|
|
242
|
-
if (event.key !== 'Escape') return;
|
|
243
|
-
handlersRef.current.onEscape(event);
|
|
244
|
-
}
|
|
245
|
-
function resized() {
|
|
246
|
-
cancelAnimationFrame(frame);
|
|
247
|
-
const until = performance.now() + 500;
|
|
248
|
-
const settle = () => { align(); if (performance.now() < until) frame = requestAnimationFrame(settle); };
|
|
249
|
-
frame = requestAnimationFrame(settle);
|
|
250
|
-
}
|
|
251
|
-
document.addEventListener('pointerdown', outside);
|
|
252
|
-
document.addEventListener('keydown', escape, true);
|
|
253
|
-
window.addEventListener('resize', resized);
|
|
254
|
-
document.addEventListener('scroll', align, true);
|
|
255
|
-
/* 输入区是多行的:换行 / 贴图 / 切会话会让触发按钮在**既不产生 window
|
|
256
|
-
* resize、也未必冒泡出 scroll 事件**的情况下移动,而弹层的 top 是
|
|
257
|
-
* 打开那一刻按 trigger.top 算死的——按钮一动弹层不跟,于是相对按钮
|
|
258
|
-
* 上浮或下沉。用一个观察器盯住触发按钮的定位祖先(`offsetParent`,
|
|
259
|
-
* 正是那条 overflow:auto/hidden 的输入区链)与触发按钮本身:它们的
|
|
260
|
-
* 盒子尺寸一变(输入区长高、滚动条出现/消失、外框平移)就重跑
|
|
261
|
-
* `align`,把弹层重新锚定到当前按钮位置。观察器回调在绘制前触发,
|
|
262
|
-
* 因此漂移不会先画出来再纠正。
|
|
263
|
-
*
|
|
264
|
-
* 已知残留缺口:ResizeObserver 只对「盒子尺寸变化」敏感。若按钮因
|
|
265
|
-
* 某祖先的 CSS transform / 主动画被整体平移,而所有被观察盒子尺寸
|
|
266
|
-
* 都没变,观察器不会响——这类纯位移只能靠 IntersectionObserver 或
|
|
267
|
-
* rAF 轮询兜底,但对一个 fail-open 插件而言过重,故刻意不引入。
|
|
268
|
-
* scroll(capture)与 window resize 监听仍覆盖绝大多数实际场景。 */
|
|
269
|
-
let observer = null;
|
|
270
|
-
if (typeof ResizeObserver === 'function') {
|
|
271
|
-
observer = new ResizeObserver(() => align());
|
|
272
|
-
const anchor = triggerRef.current?.offsetParent;
|
|
273
|
-
if (anchor) observer.observe(anchor);
|
|
274
|
-
if (triggerRef.current) observer.observe(triggerRef.current);
|
|
275
|
-
/* 弹层自身也要观察:面板高度带 `.2s` 过渡,切换 pane(强度 <-> 模型列表)
|
|
276
|
-
* 时高度会动画变化,而 top 是按当时的 offsetHeight 算死的。只盯触发按钮
|
|
277
|
-
* 的话,高度一长弹层底边就往下压过触发按钮(实测 gap 变 -32px)。观察
|
|
278
|
-
* 弹层后,动画每一帧高度一变就重算 top,底边始终钉在按钮上方 8px。 */
|
|
279
|
-
if (popupRef.current) observer.observe(popupRef.current);
|
|
280
|
-
}
|
|
281
|
-
align();
|
|
282
|
-
return () => {
|
|
283
|
-
document.removeEventListener('pointerdown', outside);
|
|
284
|
-
document.removeEventListener('keydown', escape, true);
|
|
285
|
-
window.removeEventListener('resize', resized);
|
|
286
|
-
document.removeEventListener('scroll', align, true);
|
|
287
|
-
if (observer) observer.disconnect();
|
|
288
|
-
cancelAnimationFrame(frame);
|
|
289
|
-
};
|
|
290
|
-
}, [open, align, rootRef, popupRef, triggerRef]);
|
|
291
|
-
|
|
292
|
-
/* 打开前先量一次:首帧就有正确的高度 **和位置**,不会先回退到 CSS 里的
|
|
293
|
-
* 回退坐标(left:12 / top:auto)再跳变。 */
|
|
294
|
-
function primeRoom() {
|
|
295
|
-
align();
|
|
296
|
-
}
|
|
297
|
-
return { room, primeRoom };
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/* Fast 开关的按会话持久化:内存镜像负责同一运行期,localStorage 负责
|
|
301
|
-
* 跨重启;每次存储访问都有保护(插件保持 fail-open)。 */
|
|
302
|
-
function useFastPreference(sessionId) {
|
|
303
|
-
const [fast, setFastState] = useState(() => readFast(sessionId));
|
|
304
|
-
const fastRef = useRef(fast);
|
|
305
|
-
const sessionRef = useRef(sessionId);
|
|
306
|
-
useLayoutEffect(() => { fastRef.current = fast; }, [fast]);
|
|
307
|
-
/* 宿主复用组件实例切换会话时,采纳新会话的偏好;真正的重新挂载已由
|
|
308
|
-
* useState 初始化器完成,此时观察不到变化。 */
|
|
309
|
-
useEffect(() => {
|
|
310
|
-
if (sessionRef.current === sessionId) return;
|
|
311
|
-
sessionRef.current = sessionId;
|
|
312
|
-
const stored = readFast(sessionId);
|
|
313
|
-
fastRef.current = stored;
|
|
314
|
-
setFastState(stored);
|
|
315
|
-
}, [sessionId]);
|
|
316
|
-
/* 写穿:接受值或更新函数,与它所包裹的 setState 行为一致。 */
|
|
317
|
-
function setFast(next) {
|
|
318
|
-
const value = typeof next === 'function' ? next(fastRef.current) : next;
|
|
319
|
-
if (value === fastRef.current) return;
|
|
320
|
-
fastRef.current = value;
|
|
321
|
-
setFastState(value);
|
|
322
|
-
writeFast(sessionId, value);
|
|
323
|
-
}
|
|
324
|
-
return [fast, setFast];
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/* 选择提交的串行化:同一时刻只发一次请求,后续选择合并为最新值。 */
|
|
328
|
-
function useSelectionCommit({ select, disabled, t, onError, onSettled, mountedRef }) {
|
|
329
|
-
const [busy, setBusy] = useState(false);
|
|
330
|
-
const pendingRef = useRef(null);
|
|
331
|
-
const busyRef = useRef(false);
|
|
332
|
-
|
|
333
|
-
async function commit(next) {
|
|
334
|
-
if (disabled || !next) return;
|
|
335
|
-
pendingRef.current = next;
|
|
336
|
-
if (busyRef.current) return;
|
|
337
|
-
busyRef.current = true;
|
|
338
|
-
setBusy(true);
|
|
339
|
-
onError('');
|
|
340
|
-
try {
|
|
341
|
-
while (pendingRef.current) {
|
|
342
|
-
const want = pendingRef.current;
|
|
343
|
-
pendingRef.current = null;
|
|
344
|
-
const result = await select(want);
|
|
345
|
-
if (result && !result.ok) throw new Error(result.error?.message || t('failed'));
|
|
346
|
-
if (result === undefined) throw new Error(t('unavailable'));
|
|
347
|
-
}
|
|
348
|
-
} catch (cause) {
|
|
349
|
-
pendingRef.current = null;
|
|
350
|
-
if (mountedRef.current) onError(cause?.message || t('failed'));
|
|
351
|
-
} finally {
|
|
352
|
-
busyRef.current = false;
|
|
353
|
-
if (mountedRef.current) {
|
|
354
|
-
setBusy(false);
|
|
355
|
-
onSettled();
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
return { busy, busyRef, commit };
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
/* Agent Teams 开关:能力门控 + 写入 + 失败上报。投影由桥接组件传入。 */
|
|
363
|
-
function useTeamToggle({ teamMode, setTeamMode, available, t, onError, mountedRef }) {
|
|
364
|
-
const [pending, setPending] = useState(false);
|
|
365
|
-
const supported = teamMode !== undefined
|
|
366
|
-
&& teamMode !== null
|
|
367
|
-
&& typeof setTeamMode === 'function'
|
|
368
|
-
&& available;
|
|
369
|
-
const enabled = supported && teamMode.enabled === true;
|
|
370
|
-
|
|
371
|
-
function toggle(next) {
|
|
372
|
-
if (!supported || pending) return;
|
|
373
|
-
setPending(true);
|
|
374
|
-
onError('');
|
|
375
|
-
Promise.resolve(setTeamMode(next)).then((result) => {
|
|
376
|
-
const failure = result && result.ok === false
|
|
377
|
-
? ((result.error && result.error.message) || t('teamFailed'))
|
|
378
|
-
: null;
|
|
379
|
-
if (failure) onError(failure);
|
|
380
|
-
}, (cause) => {
|
|
381
|
-
onError(cause instanceof Error ? cause.message : String(cause));
|
|
382
|
-
}).finally(() => { if (mountedRef.current) setPending(false); });
|
|
383
|
-
}
|
|
384
|
-
return { supported, enabled, pending, toggle };
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
function useRailDrag({ railRef, efforts, index, disabled, onMove, onPick, onCancel, U }) {
|
|
388
|
-
const [dragging, setDragging] = useState(false);
|
|
389
|
-
const [hovered, setHovered] = useState(-1);
|
|
390
|
-
const dragRef = useRef(false);
|
|
391
|
-
const pointerRef = useRef(null);
|
|
392
|
-
const liveRef = useRef(null);
|
|
393
|
-
const dragStartIndexRef = useRef(0);
|
|
394
|
-
const lastAppliedRef = useRef(null);
|
|
395
|
-
const apiRef = useRef({});
|
|
396
|
-
|
|
397
|
-
/* 指针映射与吸附比例都在 effort 分块里,用真实滑轨矩形调用,便于单测。 */
|
|
398
|
-
const railBox = () => railRef.current?.getBoundingClientRect();
|
|
399
|
-
function fractionAt(clientX) {
|
|
400
|
-
return U.fractionAt(clientX, railBox());
|
|
401
|
-
}
|
|
402
|
-
function nearestIndex(clientX) {
|
|
403
|
-
return U.nearestIndex(clientX, railBox(), efforts.length, index);
|
|
404
|
-
}
|
|
405
|
-
function paintLive(frac) {
|
|
406
|
-
railRef.current?.style.setProperty(`--${P}-pos`, String(frac));
|
|
407
|
-
}
|
|
408
|
-
function stopFraction(i) {
|
|
409
|
-
return U.stopFraction(i, efforts.length);
|
|
410
|
-
}
|
|
411
|
-
/* 强制把圆钮放到档位上,绕过 React 对相同状态的跳过渲染。 */
|
|
412
|
-
function snapLive(i) {
|
|
413
|
-
railRef.current?.style.setProperty(`--${P}-pos`, String(stopFraction(i)));
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
/* 只有一个地方把指针位置应用到滑轨:按压与文档级 move 都走这里。 */
|
|
417
|
-
function applyPointer(clientX) {
|
|
418
|
-
const frac = fractionAt(clientX);
|
|
419
|
-
liveRef.current = frac;
|
|
420
|
-
paintLive(frac);
|
|
421
|
-
const i = Math.round(frac * (efforts.length - 1));
|
|
422
|
-
const id = efforts[i]?.id;
|
|
423
|
-
if (id && id !== lastAppliedRef.current) {
|
|
424
|
-
lastAppliedRef.current = id;
|
|
425
|
-
onMove(id);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
function pointerDown(event) {
|
|
430
|
-
/* 刻意不受 busy 门控:进行中的提交绝不能让滑轨不可抓握;提交会合并,
|
|
431
|
-
* 因此期间开始的拖拽直接取代它。 */
|
|
432
|
-
if (disabled || efforts.length < 2) return;
|
|
433
|
-
/* 抑制原生拖放/文本选择,它们会触发 pointercancel 杀死手势。 */
|
|
434
|
-
event.preventDefault();
|
|
435
|
-
railRef.current?.focus({ preventScroll: true });
|
|
436
|
-
/* 指针捕获只是便利手段:手势由文档级监听器掌管。 */
|
|
437
|
-
try { event.currentTarget.setPointerCapture(event.pointerId); } catch { /* 非致命 */ }
|
|
438
|
-
dragRef.current = true;
|
|
439
|
-
pointerRef.current = event.pointerId;
|
|
440
|
-
dragStartIndexRef.current = index;
|
|
441
|
-
lastAppliedRef.current = null;
|
|
442
|
-
setDragging(true);
|
|
443
|
-
setHovered(-1);
|
|
444
|
-
applyPointer(event.clientX);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
/* 仅作悬停反馈;拖拽分支在文档级监听器里。 */
|
|
448
|
-
function pointerMove(event) {
|
|
449
|
-
if (dragRef.current) return;
|
|
450
|
-
const i = nearestIndex(event.clientX);
|
|
451
|
-
const box = railRef.current?.getBoundingClientRect();
|
|
452
|
-
if (!box) return;
|
|
453
|
-
const tickX = box.left + 15 + i / Math.max(1, efforts.length - 1) * (box.width - 30);
|
|
454
|
-
setHovered(Math.abs(event.clientX - tickX) < 10 && i !== index ? i : -1);
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
function finish(event) {
|
|
458
|
-
if (!dragRef.current) return;
|
|
459
|
-
dragRef.current = false;
|
|
460
|
-
pointerRef.current = null;
|
|
461
|
-
setDragging(false);
|
|
462
|
-
liveRef.current = null;
|
|
463
|
-
lastAppliedRef.current = null;
|
|
464
|
-
const known = event != null && Number.isFinite(event.clientX);
|
|
465
|
-
const i = known ? nearestIndex(event.clientX) : index;
|
|
466
|
-
snapLive(i);
|
|
467
|
-
const target = efforts[i] ?? efforts[index];
|
|
468
|
-
if (target) onPick(target.id);
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
/* 取消的拖拽回滚到按压时记录的档位(不提交)。 */
|
|
472
|
-
function cancelDrag() {
|
|
473
|
-
if (!dragRef.current) return;
|
|
474
|
-
dragRef.current = false;
|
|
475
|
-
pointerRef.current = null;
|
|
476
|
-
setDragging(false);
|
|
477
|
-
liveRef.current = null;
|
|
478
|
-
lastAppliedRef.current = null;
|
|
479
|
-
/* 展示层回滚(预览、峰值提示)由调用方负责,Hook 只管手势与吸附。 */
|
|
480
|
-
onCancel();
|
|
481
|
-
snapLive(dragStartIndexRef.current);
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
function keyDown(event) {
|
|
485
|
-
let next = index;
|
|
486
|
-
if (event.key === 'ArrowRight' || event.key === 'ArrowUp') next++;
|
|
487
|
-
else if (event.key === 'ArrowLeft' || event.key === 'ArrowDown') next--;
|
|
488
|
-
else if (event.key === 'Home') next = 0;
|
|
489
|
-
else if (event.key === 'End') next = efforts.length - 1;
|
|
490
|
-
else return;
|
|
491
|
-
event.preventDefault();
|
|
492
|
-
const i = Math.max(0, Math.min(efforts.length - 1, next));
|
|
493
|
-
/* 键盘移动本就落在档位上,仍显式吸附,避免同一次跳过渲染留下旧位置。 */
|
|
494
|
-
snapLive(i);
|
|
495
|
-
const target = efforts[i];
|
|
496
|
-
if (target) onPick(target.id);
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
useLayoutEffect(() => {
|
|
500
|
-
apiRef.current = { applyPointer, finish, cancelDrag };
|
|
501
|
-
});
|
|
502
|
-
useEffect(() => {
|
|
503
|
-
const owns = e => pointerRef.current === null || e.pointerId === pointerRef.current;
|
|
504
|
-
const move = e => { if (owns(e) && dragRef.current) apiRef.current.applyPointer(e.clientX); };
|
|
505
|
-
const up = e => { if (owns(e) && dragRef.current) apiRef.current.finish(e); };
|
|
506
|
-
const cancel = e => { if (owns(e) && dragRef.current) apiRef.current.cancelDrag(); };
|
|
507
|
-
/* 窗口外释放不会到达文档;焦点丢失是唯一信号,手势不能一直锁死。 */
|
|
508
|
-
const blur = () => { if (dragRef.current) apiRef.current.finish(); };
|
|
509
|
-
document.addEventListener('pointermove', move, true);
|
|
510
|
-
document.addEventListener('pointerup', up, true);
|
|
511
|
-
document.addEventListener('pointercancel', cancel, true);
|
|
512
|
-
window.addEventListener('blur', blur);
|
|
513
|
-
return () => {
|
|
514
|
-
document.removeEventListener('pointermove', move, true);
|
|
515
|
-
document.removeEventListener('pointerup', up, true);
|
|
516
|
-
document.removeEventListener('pointercancel', cancel, true);
|
|
517
|
-
window.removeEventListener('blur', blur);
|
|
518
|
-
};
|
|
519
|
-
}, []);
|
|
135
|
+
/* Fast 开关的按会话持久化:内存镜像负责同一运行期,localStorage 负责 */
|
|
520
136
|
|
|
521
|
-
|
|
522
|
-
* React 渲染滑轨 style 时若正在拖拽就读它,使两条 --pos 写入路径
|
|
523
|
-
* (paintLive 的 DOM 直写 与 React 的 style prop)写出同一个连续值——
|
|
524
|
-
* 否则越过档位阈值的那一帧 React 会把 --pos 改写回吸附位,圆钮偏离
|
|
525
|
-
* 指针半个档距再弹回(与「拖动期间无吸附跟随」的设计相矛盾)。 */
|
|
526
|
-
return { dragging, hovered, setHovered, pointerDown, pointerMove, finish, cancelDrag, keyDown, liveRef };
|
|
527
|
-
}
|
|
137
|
+
/* 选择提交的串行化:同一时刻只发一次请求,后续选择合并为最新值 */
|
|
528
138
|
|
|
529
|
-
|
|
139
|
+
/* Agent Teams 开关:能力门控 + 写入 + 失败上报 */
|
|
140
|
+
function SelectorImpl({ directory, load, select, available, locked, t, sessionId, setTeamMode, teamMode, css, metrics, effortApi, hooksApi, viewsApi }) {
|
|
530
141
|
const state = useSyncExternalStore(
|
|
531
142
|
fn => directory.subscribe(fn),
|
|
532
143
|
() => directory.getSnapshot()
|
|
@@ -539,9 +150,7 @@ window.__ModuleLoader__.load({
|
|
|
539
150
|
const [error, setError] = useState('');
|
|
540
151
|
const [query, setQuery] = useState('');
|
|
541
152
|
const [highlight, setHighlight] = useState(0);
|
|
542
|
-
/* tooltip 的可见性现在由状态驱动,而不再是 `:hover` CSS:tooltip
|
|
543
|
-
* 必须位于弹出面板之外,以逃出 backdrop-filter 的包含块,因此它不再
|
|
544
|
-
* 是 ⚡ 按钮的后代,任何后代选择器都无法选中它(完整诊断见 CSS 块)。 */
|
|
153
|
+
/* tooltip 的可见性现在由状态驱动,而不再是 `:hover` CSS:tooltip */
|
|
545
154
|
const [tipOn, setTipOn] = useState(false);
|
|
546
155
|
const [teamTipOn, setTeamTipOn] = useState(false);
|
|
547
156
|
const [resetTipOn, setResetTipOn] = useState(false);
|
|
@@ -570,12 +179,12 @@ window.__ModuleLoader__.load({
|
|
|
570
179
|
const groups = state.groups || [];
|
|
571
180
|
const group = groups.find(g => g.id === selection?.provider);
|
|
572
181
|
const model = group?.models.find(m => m.id === selection?.model);
|
|
573
|
-
const efforts =
|
|
182
|
+
const efforts = effortApi.sortEfforts(model?.reasoning?.efforts);
|
|
574
183
|
const savedEffort = selection?.reasoningEffort ?? model?.reasoning?.defaultEffort;
|
|
575
184
|
const displayed = preview ?? savedEffort;
|
|
576
185
|
const index = Math.max(0, efforts.findIndex(e => e.id === displayed));
|
|
577
186
|
const fraction = efforts.length > 1 ? index / (efforts.length - 1) : 0;
|
|
578
|
-
const peak =
|
|
187
|
+
const peak = effortApi.isPeakId(displayed);
|
|
579
188
|
const dark = useDarkTheme();
|
|
580
189
|
const modelName = model?.name || selection?.model || t('choose');
|
|
581
190
|
const disabled = Boolean(locked || !available);
|
|
@@ -583,250 +192,77 @@ window.__ModuleLoader__.load({
|
|
|
583
192
|
const teamTipShown = teamTipOn && open && pane === 'effort';
|
|
584
193
|
const resetTipShown = resetTipOn && open && pane === 'effort';
|
|
585
194
|
|
|
586
|
-
|
|
587
|
-
const
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
open,
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
195
|
+
/* 意图层 + 3 个内部 Hook(useSelectionCommit / useTeamToggle / useRai */
|
|
196
|
+
const controller = hooksApi.useEffortController({
|
|
197
|
+
state, selection, model, groups, load, available, disabled, error, setError,
|
|
198
|
+
sessionId, teamMode, setTeamMode, t, select,
|
|
199
|
+
open, setOpen, pane, setPane, preview, setPreview, message, setMessage,
|
|
200
|
+
query, setQuery, highlight, setHighlight, tipOn, setTipOn,
|
|
201
|
+
teamTipOn, setTeamTipOn, resetTipOn, setResetTipOn,
|
|
202
|
+
bloom, setBloom, view, setView, subProvider, setSubProvider,
|
|
203
|
+
efforts, savedEffort, displayed, index, fraction, peak, dark, modelName,
|
|
204
|
+
rootRef, popupRef, railRef, triggerRef, searchRef,
|
|
205
|
+
tipRef, fastBtnRef, resetRef, resetTipRef, teamTipRef, teamInfoBtnRef,
|
|
206
|
+
previewRef, mountedRef, timersRef, latest, seenIndexRef,
|
|
207
|
+
effortApi
|
|
598
208
|
});
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
useAnchoredTip(
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
const bloomMotes = useMemo(() => U.buildBloom(U.BLOOM_COUNT), [U]);
|
|
209
|
+
const {
|
|
210
|
+
fast, setFast, team, busy, rail, room, primeRoom,
|
|
211
|
+
activeProvider, providerModels, flatModels,
|
|
212
|
+
resetToDefault, chooseModel, close,
|
|
213
|
+
enterProvider, goBack, modelKeyDown
|
|
214
|
+
} = controller;
|
|
215
|
+
|
|
216
|
+
/* tooltip 定位:⚡ / ↻ / 团队 三个按钮各自的提示 */
|
|
217
|
+
hooksApi.useAnchoredTip(tipShown, fastBtnRef, tipRef, 120, 44);
|
|
218
|
+
hooksApi.useAnchoredTip(teamTipShown, teamInfoBtnRef, teamTipRef, 220, 60);
|
|
219
|
+
hooksApi.useAnchoredTip(resetTipShown, resetRef, resetTipRef, 140, 48);
|
|
611
220
|
|
|
612
|
-
/*
|
|
613
|
-
* effect 里同步:render 期间写 ref 会破坏渲染的纯粹性。刻意不放
|
|
614
|
-
* open——Escape 监听器只在弹层打开期间绑定,这里只保留 Escape 退层
|
|
615
|
-
* 真正需要的 pane/view 等即时状态,避免读到关闭动画窗口内的过期值。 */
|
|
221
|
+
/* 模型页打开时聚焦搜索框 */
|
|
616
222
|
useLayoutEffect(() => {
|
|
617
|
-
|
|
618
|
-
});
|
|
223
|
+
if (open && pane === 'models' && searchRef.current) searchRef.current.focus({ preventScroll: true });
|
|
224
|
+
}, [open, pane]);
|
|
225
|
+
|
|
226
|
+
/* 星尘 / 绽放粒子:一次生成本次会话使用的随机分布 */
|
|
227
|
+
const sparkles = useMemo(() => effortApi.buildSparkles(22), [effortApi]);
|
|
228
|
+
const bloomMotes = useMemo(() => effortApi.buildBloom(effortApi.BLOOM_COUNT), [effortApi]);
|
|
619
229
|
|
|
620
|
-
/* ----------
|
|
230
|
+
/* ---------- 加载副作用 ---------- */
|
|
621
231
|
useEffect(() => { if (available) load(); }, [available, load]);
|
|
622
232
|
|
|
623
233
|
useEffect(() => {
|
|
624
234
|
mountedRef.current = true;
|
|
235
|
+
const timers = timersRef.current;
|
|
625
236
|
return () => {
|
|
626
237
|
mountedRef.current = false;
|
|
627
|
-
|
|
238
|
+
timers.forEach(clearTimeout);
|
|
628
239
|
};
|
|
629
|
-
}, []);
|
|
630
|
-
|
|
631
|
-
/* tooltip 绝不能比锚定它的状态活得更久 */
|
|
632
|
-
useEffect(() => { if (!open) setTipOn(false); }, [open]);
|
|
633
|
-
useEffect(() => { if (pane !== 'effort') setTipOn(false); }, [pane]);
|
|
634
|
-
useEffect(() => { if (!open) setTeamTipOn(false); }, [open]);
|
|
635
|
-
useEffect(() => { if (pane !== 'effort') setTeamTipOn(false); }, [pane]);
|
|
636
|
-
useEffect(() => { if (!open) setResetTipOn(false); }, [open]);
|
|
637
|
-
useEffect(() => { if (pane !== 'effort') setResetTipOn(false); }, [pane]);
|
|
638
|
-
/* 重置出错/进入 busy 时按钮会变成 disabled,指针离开事件可能收不到;
|
|
639
|
-
* 这里主动收起,避免提示卡悬在不响应的按钮上。 */
|
|
640
|
-
useEffect(() => { if (busy || efforts.length === 0) setResetTipOn(false); }, [busy, efforts.length]);
|
|
641
|
-
useEffect(() => {
|
|
642
|
-
if (!open) { seenIndexRef.current = null; return; }
|
|
643
|
-
if (seenIndexRef.current === null) { seenIndexRef.current = index; return; }
|
|
644
|
-
const arrived = index === efforts.length - 1 && seenIndexRef.current !== index;
|
|
645
|
-
seenIndexRef.current = index;
|
|
646
|
-
if (arrived) setBloom(n => n + 1);
|
|
647
|
-
}, [index, open, efforts.length]);
|
|
240
|
+
}, [timersRef]);
|
|
648
241
|
|
|
649
|
-
/*
|
|
650
|
-
* 避免失效 id 无谓地累积(clearTimeout 对旧 id 是 no-op,但不整洁)。 */
|
|
651
|
-
function clearTimers() {
|
|
652
|
-
timersRef.current.forEach(clearTimeout);
|
|
653
|
-
timersRef.current = [];
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
/* 进入峰值时的特效:先显示警告,随后落定 */
|
|
657
|
-
function enterPeak() {
|
|
658
|
-
clearTimers();
|
|
659
|
-
setMessage(true);
|
|
660
|
-
timersRef.current = [setTimeout(() => { if (mountedRef.current) setMessage(false); }, 1800)];
|
|
661
|
-
}
|
|
662
|
-
function showEffort(id) {
|
|
663
|
-
const before = previewRef.current ?? savedEffort;
|
|
664
|
-
previewRef.current = id;
|
|
665
|
-
setPreview(id);
|
|
666
|
-
if (U.isPeakId(id) && !U.isPeakId(before)) enterPeak();
|
|
667
|
-
else if (!U.isPeakId(id)) {
|
|
668
|
-
timersRef.current.forEach(clearTimeout);
|
|
669
|
-
setMessage(false);
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
/* 清掉预览值:提交结束/取消后回到“已保存档位”的显示。 */
|
|
674
|
-
function clearPreview() {
|
|
675
|
-
previewRef.current = null;
|
|
676
|
-
setPreview(null);
|
|
677
|
-
}
|
|
678
|
-
/* 取消手势时连峰值提示一起回滚。 */
|
|
679
|
-
function cancelPreview() {
|
|
680
|
-
clearPreview();
|
|
681
|
-
timersRef.current.forEach(clearTimeout);
|
|
682
|
-
setMessage(false);
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
function chooseEffort(id) {
|
|
686
|
-
if (!selection || disabled || !efforts.some(e => e.id === id)) return;
|
|
687
|
-
showEffort(id);
|
|
688
|
-
if (id !== savedEffort) void commit({ ...selection, reasoningEffort: id });
|
|
689
|
-
else clearPreview();
|
|
690
|
-
}
|
|
691
|
-
function defaultStopId() {
|
|
692
|
-
if (!efforts.length) return undefined;
|
|
693
|
-
const declared = model?.reasoning?.defaultEffort;
|
|
694
|
-
if (declared !== undefined && efforts.some(e => e.id === declared)) return declared;
|
|
695
|
-
return efforts[Math.floor(efforts.length / 2)].id;
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
function resetToDefault() {
|
|
699
|
-
if (disabled) return;
|
|
700
|
-
setFast(false);
|
|
701
|
-
const id = defaultStopId();
|
|
702
|
-
if (id === undefined) return; // 无处可重置(没有任何档位)
|
|
703
|
-
chooseEffort(id);
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
function chooseModel(providerId, nextModel) {
|
|
707
|
-
if (disabled || busyRef.current) return;
|
|
708
|
-
const same = selection?.provider === providerId && selection?.model === nextModel.id;
|
|
709
|
-
/* 切换时取中间档(参考规则):floor(n/2)。没有声明档位的模型得到
|
|
710
|
-
* 的载荷完全不含 `reasoningEffort` 键——缺失表示“无意见”,这与
|
|
711
|
-
* 显式 null 不同。 */
|
|
712
|
-
const levels = U.sortEfforts(nextModel.reasoning?.efforts);
|
|
713
|
-
const mid = levels.length ? levels[Math.floor(levels.length / 2)].id : undefined;
|
|
714
|
-
const id = same ? savedEffort : mid;
|
|
715
|
-
setPane('effort');
|
|
716
|
-
setView(1);
|
|
717
|
-
setSubProvider(null);
|
|
718
|
-
setQuery('');
|
|
719
|
-
timersRef.current.forEach(clearTimeout);
|
|
720
|
-
setMessage(false);
|
|
721
|
-
setPreview(null);
|
|
722
|
-
previewRef.current = null;
|
|
723
|
-
void commit({
|
|
724
|
-
provider: providerId, model: nextModel.id,
|
|
725
|
-
...(id === undefined ? {} : { reasoningEffort: id })
|
|
726
|
-
});
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
function close() {
|
|
730
|
-
rail.cancelDrag();
|
|
731
|
-
setOpen(false);
|
|
732
|
-
setQuery('');
|
|
733
|
-
setPane('effort');
|
|
734
|
-
setView(1);
|
|
735
|
-
setSubProvider(null);
|
|
736
|
-
setHighlight(0);
|
|
737
|
-
triggerRef.current?.focus({ preventScroll: true });
|
|
738
|
-
}
|
|
242
|
+
/* ---------- 渲染 ---------- */
|
|
739
243
|
|
|
740
|
-
/*
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
}
|
|
744
|
-
function handleEscape(event) {
|
|
745
|
-
event.preventDefault();
|
|
746
|
-
event.stopPropagation();
|
|
747
|
-
/* Escape 每次退回一层,与参考实现一致:
|
|
748
|
-
* 第 2 页 -> 第 1 页 -> 强度面板 -> 关闭。 */
|
|
749
|
-
if (latest.current.pane === 'models') {
|
|
750
|
-
if (latest.current.view === 2) { goBack(); }
|
|
751
|
-
else { setPane('effort'); setQuery(''); }
|
|
752
|
-
} else close();
|
|
753
|
-
}
|
|
244
|
+
/* `latest` 供 Escape 处理器读取"最近一次提交"的面板状态 */
|
|
245
|
+
useLayoutEffect(() => {
|
|
246
|
+
latest.current = { fast, peak, pane, efforts, index, savedEffort, view };
|
|
247
|
+
});
|
|
754
248
|
|
|
755
249
|
/* 模型页打开时聚焦搜索框 */
|
|
756
250
|
useLayoutEffect(() => {
|
|
757
251
|
if (open && pane === 'models' && searchRef.current) searchRef.current.focus({ preventScroll: true });
|
|
758
252
|
}, [open, pane]);
|
|
759
253
|
|
|
760
|
-
/* 第 2 页当前展示的提供方(第 1 页为 null)。 */
|
|
761
|
-
const activeProvider = subProvider === null
|
|
762
|
-
? null
|
|
763
|
-
: groups.find(g => g.id === subProvider) ?? null;
|
|
764
|
-
|
|
765
|
-
/* 第 2 页的行,按查询过滤。匹配规则与出厂选择器使用的
|
|
766
|
-
* 大小写不敏感有序子序列规则相同。 */
|
|
767
|
-
const providerModels = useMemo(() => {
|
|
768
|
-
if (!activeProvider) return [];
|
|
769
|
-
const q = query.trim().toLowerCase();
|
|
770
|
-
if (!q) return activeProvider.models;
|
|
771
|
-
return activeProvider.models.filter(m => {
|
|
772
|
-
const name = (m.name || m.id).toLowerCase();
|
|
773
|
-
if (name.includes(q)) return true;
|
|
774
|
-
let i = 0;
|
|
775
|
-
for (const ch of name) if (ch === q[i]) i++;
|
|
776
|
-
return i === q.length;
|
|
777
|
-
});
|
|
778
|
-
}, [activeProvider, query]);
|
|
779
|
-
|
|
780
|
-
/* 第 1 页只是提供方列表;那里没有需要过滤的内容。 */
|
|
781
|
-
const flatModels = useMemo(
|
|
782
|
-
() => (activeProvider
|
|
783
|
-
? providerModels.map(m => ({ group: activeProvider, model: m }))
|
|
784
|
-
: []),
|
|
785
|
-
[activeProvider, providerModels]
|
|
786
|
-
);
|
|
787
|
-
|
|
788
|
-
function enterProvider(gid) {
|
|
789
|
-
setSubProvider(gid);
|
|
790
|
-
setQuery('');
|
|
791
|
-
setHighlight(0);
|
|
792
|
-
setView(2);
|
|
793
|
-
}
|
|
794
|
-
function goBack() {
|
|
795
|
-
setView(1);
|
|
796
|
-
setSubProvider(null);
|
|
797
|
-
setQuery('');
|
|
798
|
-
setHighlight(0);
|
|
799
|
-
}
|
|
800
|
-
|
|
801
254
|
useEffect(() => { setHighlight(0); }, [query, pane, view]);
|
|
802
255
|
|
|
803
|
-
function modelKeyDown(event) {
|
|
804
|
-
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
805
|
-
event.preventDefault();
|
|
806
|
-
if (!flatModels.length) return;
|
|
807
|
-
const delta = event.key === 'ArrowDown' ? 1 : -1;
|
|
808
|
-
setHighlight(prev => (prev + delta + flatModels.length) % flatModels.length);
|
|
809
|
-
} else if (event.key === 'Enter') {
|
|
810
|
-
event.preventDefault();
|
|
811
|
-
const entry = flatModels[highlight];
|
|
812
|
-
if (entry) chooseModel(entry.group.id, entry.model);
|
|
813
|
-
} else if (event.key === 'Home') {
|
|
814
|
-
event.preventDefault(); setHighlight(0);
|
|
815
|
-
} else if (event.key === 'End') {
|
|
816
|
-
event.preventDefault(); setHighlight(flatModels.length - 1);
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
|
|
820
256
|
/* ---------- 渲染 ---------- */
|
|
821
257
|
const currentLabel = efforts.length
|
|
822
|
-
? (
|
|
258
|
+
? (effortApi.effortLabel(efforts[index], t) || t('effort'))
|
|
823
259
|
: '';
|
|
824
|
-
const triggerLabel =
|
|
260
|
+
const triggerLabel = effortApi.effortLabel(efforts.find(e => e.id === savedEffort), t);
|
|
825
261
|
const status = error || (state.status === 'error' ? t('failed') : '');
|
|
826
|
-
/* N 档标签:单档时走单数模板,避免英文出现 “1 levels
|
|
827
|
-
const levelText = n => fill(t(n === 1 ? 'levelOne' : 'levels'), { count: n });
|
|
828
|
-
const ROW_H =
|
|
829
|
-
const HEAD_H =
|
|
262
|
+
/* N 档标签:单档时走单数模板,避免英文出现 “1 levels” */
|
|
263
|
+
// const levelText = n => fill(t(n === 1 ? 'levelOne' : 'levels'), { count: n });
|
|
264
|
+
const ROW_H = metrics.rowH, MODEL_H = metrics.modelH, LIST_MAX_H = metrics.listMaxH, LIST_PAD_B = metrics.listPadB;
|
|
265
|
+
const HEAD_H = metrics.headH, SEARCH_H = metrics.searchH, EMPTY_H = metrics.emptyH, SEC_H = metrics.secH, PAD = metrics.padH;
|
|
830
266
|
const noticeRows = (state.failures?.length ?? 0);
|
|
831
267
|
const noticeH = noticeRows > 0
|
|
832
268
|
? Math.min(noticeRows, 4) * 30 + (groups.length === 0 ? 8 : 4)
|
|
@@ -847,11 +283,7 @@ window.__ModuleLoader__.load({
|
|
|
847
283
|
: (typeof window === 'undefined' ? Infinity : Math.max(120, window.innerHeight - 52));
|
|
848
284
|
const cappedHeight = Math.min(menuHeight, roomAbove);
|
|
849
285
|
|
|
850
|
-
/* 错误提示行:原先用 bottom 锚定,会在「无推理档位」时压住
|
|
851
|
-
* .cmes-noeffort 文案(那块和滑轨同样占据 top:65 起、line-height 26
|
|
852
|
-
* 的带状区域,而 status 落在 bottom:6 正好与其重叠)。改为 top 锚定,
|
|
853
|
-
* 落在顶部 ⚡/重置 按钮之间的空档(y 8..50 的 modelLink 那一行),
|
|
854
|
-
* 那里无论有无档位、有无 team 行都恒为空,不会再与任何内容打架。 */
|
|
286
|
+
/* 错误提示行:原先用 bottom 锚定,会在「无推理档位」时压住 */
|
|
855
287
|
const statusTop = 8;
|
|
856
288
|
|
|
857
289
|
const classes = [
|
|
@@ -862,258 +294,27 @@ window.__ModuleLoader__.load({
|
|
|
862
294
|
message ? 'message' : ''
|
|
863
295
|
].filter(Boolean).join(' ');
|
|
864
296
|
|
|
865
|
-
/* ---
|
|
866
|
-
const
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
'aria-expanded': view === 2 && subProvider === g.id,
|
|
873
|
-
onClick: () => enterProvider(g.id)
|
|
874
|
-
},
|
|
875
|
-
h('span', { className: `${P}-rowName` }, g.name),
|
|
876
|
-
h('span', { className: `${P}-rowDot`, hidden: !isCurrent, 'aria-hidden': true }),
|
|
877
|
-
icon('chevron', `${P}-rowChev`));
|
|
297
|
+
/* --- 模型页:交给 client.views.js 的 renderModelsView 渲染 --- */
|
|
298
|
+
const modelsView = viewsApi.renderModelsView({
|
|
299
|
+
P, h, icon, t, fill, effortApi,
|
|
300
|
+
groups, state, providerModels, flatModels, activeProvider,
|
|
301
|
+
view, subProvider, selection, highlight, setHighlight,
|
|
302
|
+
enterProvider, goBack, modelKeyDown, searchRef, query, setQuery,
|
|
303
|
+
busy, noticeRows, chooseModel, pane
|
|
878
304
|
});
|
|
879
305
|
|
|
880
|
-
/*
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
});
|
|
890
|
-
} else if (groups.length === 0) {
|
|
891
|
-
noticeNodes.push(h('div', { key: 'empty', className: `${P}-empty` },
|
|
892
|
-
state.status === 'loading' ? t('loading') : t('empty')));
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
const modelNodes = providerModels.map(m => {
|
|
896
|
-
const entry = flatModels.findIndex(x => x.model.id === m.id);
|
|
897
|
-
const selected = selection?.provider === activeProvider?.id && selection?.model === m.id;
|
|
898
|
-
const levelCount = U.sortEfforts(m.reasoning?.efforts).length;
|
|
899
|
-
return h('button', {
|
|
900
|
-
key: `m-${m.id}`,
|
|
901
|
-
className: `${P}-model${selected ? ' sel' : ''}${levelCount ? '' : ' na'}${entry === highlight ? ' hovered' : ''}`,
|
|
902
|
-
type: 'button',
|
|
903
|
-
role: 'menuitemradio',
|
|
904
|
-
'aria-checked': selected,
|
|
905
|
-
disabled: busy,
|
|
906
|
-
title: levelCount ? levelText(levelCount) : t('noLevels'),
|
|
907
|
-
onMouseEnter: () => setHighlight(entry),
|
|
908
|
-
onClick: () => chooseModel(activeProvider.id, m)
|
|
909
|
-
},
|
|
910
|
-
h('span', { className: `${P}-modelName` },
|
|
911
|
-
h('span', null, m.name || m.id),
|
|
912
|
-
h('span', { className: `${P}-cnt` }, levelCount ? levelText(levelCount) : t('noLevelsShort'))),
|
|
913
|
-
icon('check', `${P}-ck`));
|
|
306
|
+
/* --- 强度面板:交给 client.views.js 的 renderEffortView 渲染 --- */
|
|
307
|
+
const effortView = viewsApi.renderEffortView({
|
|
308
|
+
P, h, icon, t, effortApi, metrics, ICON,
|
|
309
|
+
pane, fast, setFast, tipOn, setTipOn, resetTipOn, setResetTipOn,
|
|
310
|
+
teamTipOn, setTeamTipOn, fastBtnRef, resetRef, teamInfoBtnRef,
|
|
311
|
+
railRef, rail, setPane, team, busy, locked,
|
|
312
|
+
efforts, displayed, dark, index, fraction,
|
|
313
|
+
sparkles, bloomMotes, bloom, currentLabel, modelName,
|
|
314
|
+
disabled, resetToDefault
|
|
914
315
|
});
|
|
915
|
-
if (activeProvider && !modelNodes.length) {
|
|
916
|
-
modelNodes.push(h('div', { key: 'empty', className: `${P}-empty` }, t('noMatch')));
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
const modelsView = h('div', {
|
|
920
|
-
className: `${P}-pane ${P}-models${pane !== 'models' ? ' hidden' : ''}`,
|
|
921
|
-
role: 'menu', 'aria-label': t('model'),
|
|
922
|
-
inert: pane !== 'models' ? '' : undefined,
|
|
923
|
-
onKeyDown: modelKeyDown
|
|
924
|
-
},
|
|
925
|
-
h('div', {
|
|
926
|
-
className: `${P}-viewport${view === 2 ? ' view2' : ''}`
|
|
927
|
-
},
|
|
928
|
-
/* 第 1 页 —— 提供方(自有滚动容器,因此长列表可达) */
|
|
929
|
-
h('div', { className: `${P}-page slot1` },
|
|
930
|
-
h('div', { className: `${P}-sec` }, t('model')),
|
|
931
|
-
h('div', { className: `${P}-rows` }, ...providerNodes, ...noticeNodes)),
|
|
932
|
-
|
|
933
|
-
/* 第 2 页 —— 所选提供方的模型 */
|
|
934
|
-
h('div', {
|
|
935
|
-
className: `${P}-page slot2`,
|
|
936
|
-
inert: view !== 2 ? '' : undefined
|
|
937
|
-
},
|
|
938
|
-
h('div', { className: `${P}-head` },
|
|
939
|
-
h('button', {
|
|
940
|
-
type: 'button', className: `${P}-back`,
|
|
941
|
-
'aria-label': t('back'), title: t('back'),
|
|
942
|
-
onClick: goBack
|
|
943
|
-
}, icon('chevron', `${P}-iconSmall`)),
|
|
944
|
-
h('span', { className: `${P}-title` },
|
|
945
|
-
activeProvider ? activeProvider.name : '')),
|
|
946
|
-
h('label', { className: `${P}-search` },
|
|
947
|
-
icon('search', `${P}-iconSmall`),
|
|
948
|
-
h('input', {
|
|
949
|
-
ref: searchRef, type: 'text', value: query,
|
|
950
|
-
placeholder: t('search'), 'aria-label': t('search'),
|
|
951
|
-
spellCheck: false,
|
|
952
|
-
onChange: e => setQuery(e.target.value)
|
|
953
|
-
})),
|
|
954
|
-
h('div', { className: `${P}-list` }, ...modelNodes))));
|
|
955
|
-
|
|
956
|
-
/* --- 强度面板 --- */
|
|
957
|
-
const effortView = h('div', {
|
|
958
|
-
className: `${P}-pane ${P}-main${pane !== 'effort' ? ' hidden' : ''}`,
|
|
959
|
-
inert: pane !== 'effort' ? '' : undefined,
|
|
960
|
-
/* Agent Teams 行需要多一个行高;上面的弹出面板高度使用同一份
|
|
961
|
-
* 度量(M),因此两者一起增长 */
|
|
962
|
-
style: { [`--${P}-main-h`]: `${team.supported ? M.teamPaneH : M.effortPaneH}px` }
|
|
963
|
-
},
|
|
964
|
-
h('button', {
|
|
965
|
-
className: `${P}-tool ${P}-fast${fast ? ' active' : ''}`,
|
|
966
|
-
ref: fastBtnRef,
|
|
967
|
-
'aria-label': t('fast'), 'aria-pressed': fast,
|
|
968
|
-
'aria-describedby': `${P}-fast-tip`,
|
|
969
|
-
/* tooltip 绝不能作为此按钮的子节点:弹出面板的 backdrop-filter
|
|
970
|
-
* 会使它自身成为固定定位后代的包含块,从而裁掉该层。它在根节点
|
|
971
|
-
* 渲染(见返回值),并通过 `tipOn` 显示。 */
|
|
972
|
-
onPointerEnter: () => setTipOn(true),
|
|
973
|
-
onPointerLeave: () => setTipOn(false),
|
|
974
|
-
onFocus: () => setTipOn(true),
|
|
975
|
-
onBlur: () => setTipOn(false),
|
|
976
|
-
onClick: () => setFast(v => !v)
|
|
977
|
-
},
|
|
978
|
-
h('svg', { viewBox: '0 0 24 24', 'aria-hidden': true, style: { width: 15, height: 17, fill: fast ? 'currentColor' : 'none', stroke: 'currentColor', strokeWidth: fast ? 0.7 : 1.5, strokeLinejoin: 'round' } },
|
|
979
|
-
h('path', { d: ICON.bolt }))),
|
|
980
|
-
|
|
981
|
-
h('button', {
|
|
982
|
-
className: `${P}-modelLink`, onClick: () => setPane('models'),
|
|
983
|
-
'aria-label': t('model'), title: modelName
|
|
984
|
-
},
|
|
985
|
-
h('span', { className: `${P}-heading` }, currentLabel || t('choose'), icon('chevron', `${P}-iconSmall`)),
|
|
986
|
-
h('span', { className: `${P}-modelLinkName` }, modelName)),
|
|
987
|
-
|
|
988
|
-
h('div', { className: `${P}-warning` }, h('span', null, t('warning'))),
|
|
989
|
-
|
|
990
|
-
h('button', {
|
|
991
|
-
className: `${P}-tool ${P}-reset`,
|
|
992
|
-
ref: resetRef,
|
|
993
|
-
/* 只有在确实没有可重置内容时才禁用:旧的 `!model?.reasoning`
|
|
994
|
-
* 判断让按钮对常见的“有强度项但未声明默认值”提供方保持可用却
|
|
995
|
-
* 无效。 */
|
|
996
|
-
disabled: busy || efforts.length === 0,
|
|
997
|
-
'aria-label': t('reset'),
|
|
998
|
-
'aria-describedby': `${P}-reset-tip`,
|
|
999
|
-
/* 悬停提示改用与 ⚡ 相同的浮层卡片,而不是浏览器原生 title
|
|
1000
|
-
* (原生提示样式不可控,与面板的玻璃材质也不协调)。 */
|
|
1001
|
-
onPointerEnter: () => setResetTipOn(true),
|
|
1002
|
-
onPointerLeave: () => setResetTipOn(false),
|
|
1003
|
-
onFocus: () => setResetTipOn(true),
|
|
1004
|
-
onBlur: () => setResetTipOn(false),
|
|
1005
|
-
onClick: resetToDefault
|
|
1006
|
-
}, icon('reset')),
|
|
1007
|
-
|
|
1008
|
-
efforts.length
|
|
1009
|
-
? h('div', {
|
|
1010
|
-
className: `${P}-rail${rail.dragging ? ' dragging' : ''}`,
|
|
1011
|
-
ref: railRef,
|
|
1012
|
-
/* 逐档着色(问题 3):填充、未填充轨道色调、标题墨色和圆点
|
|
1013
|
-
* 都由当前档位派生,因此每个档位都呈现自己的颜色,而不是只有
|
|
1014
|
-
* Ultra 特殊。 */
|
|
1015
|
-
style: {
|
|
1016
|
-
[`--${P}-fill`]: U.fillFor(displayed, dark),
|
|
1017
|
-
[`--${P}-track`]: U.trackFor(U.fillFor(displayed, dark), dark),
|
|
1018
|
-
[`--${P}-ink`]: U.inkFor(displayed, dark),
|
|
1019
|
-
[`--${P}-dot`]: 'var(--dsw-alias-label-caption,#b6b6b8)',
|
|
1020
|
-
/* 绽放粒子是当前档位颜色向白色提亮——对 Ultra 而言正好落在
|
|
1021
|
-
* 测量得到的 #ceb0fa 左右紫色,无需第二张硬编码表 */
|
|
1022
|
-
[`--${P}-mote`]: U.mixHex(U.fillFor(displayed, dark), '#ffffff', dark ? 0.30 : 0.42),
|
|
1023
|
-
/* 一个无量纲比例同时驱动圆钮和填充。拖拽期间改读 liveRef 里的
|
|
1024
|
-
* 连续比例,与 paintLive 的 DOM 直写保持同一个值——若这里仍用
|
|
1025
|
-
* 吸附比例 fraction,越过档位阈值的那一帧 React 会把它写回
|
|
1026
|
-
* 吸附位,圆钮偏离指针半个档距再弹回。 */
|
|
1027
|
-
[`--${P}-pos`]: rail.dragging ? (rail.liveRef.current ?? fraction) : fraction
|
|
1028
|
-
},
|
|
1029
|
-
role: 'slider', tabIndex: 0,
|
|
1030
|
-
'aria-label': t('effort'),
|
|
1031
|
-
'aria-valuemin': 0, 'aria-valuemax': efforts.length - 1,
|
|
1032
|
-
'aria-valuenow': index, 'aria-valuetext': currentLabel,
|
|
1033
|
-
'aria-disabled': busy || disabled,
|
|
1034
|
-
onPointerDown: rail.pointerDown, onPointerMove: rail.pointerMove,
|
|
1035
|
-
onPointerUp: rail.finish, onPointerCancel: rail.cancelDrag,
|
|
1036
|
-
onLostPointerCapture: () => { /* 丢失捕获不算取消 */ },
|
|
1037
|
-
onPointerLeave: () => rail.setHovered(-1),
|
|
1038
|
-
onKeyDown: rail.keyDown
|
|
1039
|
-
},
|
|
1040
|
-
h('div', { className: `${P}-fill` }),
|
|
1041
|
-
...efforts.map((effort, i) => h('i', {
|
|
1042
|
-
key: effort.id,
|
|
1043
|
-
className: `${P}-dot${i <= index ? ' passed' : ''}${rail.hovered === i ? ' hovered' : ''}`,
|
|
1044
|
-
style: { [`--${P}-tick`]: efforts.length > 1 ? i / (efforts.length - 1) : 0 }
|
|
1045
|
-
})),
|
|
1046
|
-
h('div', { className: `${P}-sparks` },
|
|
1047
|
-
...sparkles.map(s => h('i', {
|
|
1048
|
-
key: s.key, className: `${P}-sp`,
|
|
1049
|
-
style: { top: s.top, [`--b`]: s.b, [`--dur`]: s.dur, [`--delay`]: s.delay }
|
|
1050
|
-
}))),
|
|
1051
|
-
/* 到达绽放:以到达计数器为 key,因此挂载新 key 会让每颗
|
|
1052
|
-
* 粒子的动画从 0% 重新开始 */
|
|
1053
|
-
bloom
|
|
1054
|
-
? h('div', {
|
|
1055
|
-
key: `bloom-${bloom}`, className: `${P}-bloom`, 'aria-hidden': true
|
|
1056
|
-
},
|
|
1057
|
-
h('i', { className: `${P}-halo` }),
|
|
1058
|
-
...bloomMotes.map(m => h('i', {
|
|
1059
|
-
key: m.key, className: `${P}-bp`,
|
|
1060
|
-
style: {
|
|
1061
|
-
[`--x0`]: m.x0, [`--y0`]: m.y0,
|
|
1062
|
-
[`--x1`]: m.x1, [`--y1`]: m.y1,
|
|
1063
|
-
[`--sz`]: m.sz, [`--bmax`]: m.bmax,
|
|
1064
|
-
[`--bd`]: m.bd, [`--bdel`]: m.bdel
|
|
1065
|
-
}
|
|
1066
|
-
})))
|
|
1067
|
-
: null,
|
|
1068
|
-
h('div', { className: `${P}-knob` }))
|
|
1069
|
-
: h('div', { className: `${P}-noeffort` }, t('unsupported')),
|
|
1070
|
-
|
|
1071
|
-
/* Agent Teams:DSH 放在模型菜单根面板里的开关,在滑杆下方重建。
|
|
1072
|
-
* 不具备该能力的宿主上完全隐藏,因此面板在那些宿主上保持原来的
|
|
1073
|
-
* 104px 形状。 */
|
|
1074
|
-
team.supported
|
|
1075
|
-
? h('div', { className: `${P}-team` },
|
|
1076
|
-
h('span', { className: `${P}-teamLabel` },
|
|
1077
|
-
h('span', null, t('team')),
|
|
1078
|
-
h('button', {
|
|
1079
|
-
type: 'button',
|
|
1080
|
-
className: `${P}-teamInfo`,
|
|
1081
|
-
ref: teamInfoBtnRef,
|
|
1082
|
-
/* 可访问名只用简短的「Agent Teams」;整句说明交给
|
|
1083
|
-
* aria-describedby 指向的提示卡,避免把长句塞进 label。 */
|
|
1084
|
-
'aria-label': t('team'),
|
|
1085
|
-
'aria-describedby': `${P}-team-tip`,
|
|
1086
|
-
onPointerEnter: () => setTeamTipOn(true),
|
|
1087
|
-
onPointerLeave: () => setTeamTipOn(false),
|
|
1088
|
-
onFocus: () => setTeamTipOn(true),
|
|
1089
|
-
onBlur: () => setTeamTipOn(false),
|
|
1090
|
-
/* 提示卡的显隐完全交给 hover / focus:这里若再切一刀,
|
|
1091
|
-
* 点击会把 hover 刚点亮的提示卡反过来关掉(指针还悬在上面,
|
|
1092
|
-
* 不会重新触发 enter),表现为提示卡在光标下凭空消失。
|
|
1093
|
-
* 点击只拦住冒泡,避免把整个弹层关掉。 */
|
|
1094
|
-
onClick: event => { event.preventDefault(); event.stopPropagation(); }
|
|
1095
|
-
}, icon('info', `${P}-teamInfoIcon`))),
|
|
1096
|
-
h('button', {
|
|
1097
|
-
type: 'button', role: 'switch',
|
|
1098
|
-
className: `${P}-teamSwitch`,
|
|
1099
|
-
'aria-checked': team.enabled ? 'true' : 'false',
|
|
1100
|
-
'aria-label': t('team'),
|
|
1101
|
-
disabled: Boolean(locked || team.pending),
|
|
1102
|
-
onClick: () => team.toggle(!team.enabled)
|
|
1103
|
-
}))
|
|
1104
|
-
: null);
|
|
1105
316
|
|
|
1106
|
-
/* 浮层(弹出面板 + tooltip)portal 到 document.body
|
|
1107
|
-
* 原因:宿主 DSH 给输入区座位 `.composerSeat` 无条件写了
|
|
1108
|
-
* `will-change: transform`(ConversationRoot.module.css),按规范这使
|
|
1109
|
-
* seat 成为它每个 `position:fixed` 后代的包含块。本插件的弹层 / tooltip
|
|
1110
|
-
* 过去作为 `.cmes-root` 的子节点留在 seat 里,于是 fixed 坐标被按 seat
|
|
1111
|
-
* 盒子而非视口解读——弹层相对触发按钮整体平移(探针 rect 变成座位原点,
|
|
1112
|
-
* Firefox 上实测中心 Δ≈277、间隙≈276),又被 seat 的 `z-index:9` 层叠
|
|
1113
|
-
* 上下文压在 DSH 元素之下而无法操作。portal 到 body 后浮层脱离 seat 的
|
|
1114
|
-
* 包含块与层叠上下文:fixed 重新相对视口解析,z-index 也在根上下文生效,
|
|
1115
|
-
* 同时不干扰 DSH 想从 `will-change` 得到的合成层。DSH 自家浮层
|
|
1116
|
-
* (StatsPills / TurnUsagePanel / ApprovalWarning 等)采用同一做法。 */
|
|
317
|
+
/* 浮层(弹出面板 + tooltip)portal 到 document.body */
|
|
1117
318
|
const overlay = h(React.Fragment, null,
|
|
1118
319
|
h('section', {
|
|
1119
320
|
className: classes, ref: popupRef, role: 'dialog',
|
|
@@ -1121,8 +322,8 @@ window.__ModuleLoader__.load({
|
|
|
1121
322
|
'aria-hidden': open ? undefined : 'true', inert: !open ? '' : undefined,
|
|
1122
323
|
onKeyDown: open ? event => trapFocus(popupRef.current, event) : undefined,
|
|
1123
324
|
style: {
|
|
1124
|
-
[`--${P}-height`]: `${pane === 'models' ? cappedHeight : (team.supported ?
|
|
1125
|
-
[`--${P}-ink`]:
|
|
325
|
+
[`--${P}-height`]: `${pane === 'models' ? cappedHeight : (team.supported ? metrics.teamPaneH : metrics.effortPaneH)}px`,
|
|
326
|
+
[`--${P}-ink`]: effortApi.inkFor(displayed, dark)
|
|
1126
327
|
}
|
|
1127
328
|
},
|
|
1128
329
|
modelsView,
|
|
@@ -1156,15 +357,15 @@ window.__ModuleLoader__.load({
|
|
|
1156
357
|
return h('div', { className: `${P}-root`, ref: rootRef },
|
|
1157
358
|
h('style', null, css),
|
|
1158
359
|
h('button', {
|
|
1159
|
-
className: `${P}-trigger${
|
|
360
|
+
className: `${P}-trigger${effortApi.isPeakId(savedEffort) ? ' peak' : ''}${fast ? ' fast' : ''}`,
|
|
1160
361
|
ref: triggerRef, disabled,
|
|
1161
362
|
'aria-label': `${modelName} ${triggerLabel}`.trim(),
|
|
1162
363
|
'aria-expanded': open, 'aria-haspopup': 'dialog', 'aria-busy': busy,
|
|
1163
|
-
style: { [`--${P}-ink`]:
|
|
364
|
+
style: { [`--${P}-ink`]: effortApi.inkFor(savedEffort, dark) },
|
|
1164
365
|
onClick: () => {
|
|
1165
366
|
if (open) close();
|
|
1166
367
|
else {
|
|
1167
|
-
/*
|
|
368
|
+
/* 打开前先量一次可用高度,首帧就是正确值,不会高度弹跳 */
|
|
1168
369
|
primeRoom();
|
|
1169
370
|
setPane(model ? 'effort' : 'models');
|
|
1170
371
|
setOpen(true);
|
|
@@ -1172,7 +373,8 @@ window.__ModuleLoader__.load({
|
|
|
1172
373
|
}
|
|
1173
374
|
}
|
|
1174
375
|
},
|
|
1175
|
-
|
|
376
|
+
/* ⚡ 图标常驻渲染(不再 `fast ? … : null` 条件挂载),仅用 CSS 切换 */
|
|
377
|
+
h('svg', { className: `${P}-bolt`, viewBox: '0 0 24 24', 'aria-hidden': true }, h('path', { d: ICON.bolt })),
|
|
1176
378
|
h('span', { className: `${P}-compact` }, icon('model')),
|
|
1177
379
|
h('span', { className: `${P}-caption` },
|
|
1178
380
|
modelName),
|
|
@@ -1181,26 +383,23 @@ window.__ModuleLoader__.load({
|
|
|
1181
383
|
: null,
|
|
1182
384
|
icon('down', `${P}-chev`)),
|
|
1183
385
|
|
|
1184
|
-
/* 浮层 portal 到 body:脱离 composerSeat 的 will-change 包含块与
|
|
1185
|
-
* z-index:9 层叠上下文(完整说明见上方 overlay 定义处)。 */
|
|
386
|
+
/* 浮层 portal 到 body:脱离 composerSeat 的 will-change 包含块与 */
|
|
1186
387
|
createPortal(overlay, document.body));
|
|
1187
388
|
}
|
|
1188
389
|
|
|
1189
|
-
/* 懒加载样式表分块(client.styles.js
|
|
1190
|
-
* 在 CSS 到达前不绘制,因此绝不会出现无样式渲染——与终端插件加载自有
|
|
1191
|
-
* 分块采用同一模式。 */
|
|
390
|
+
/* 懒加载样式表分块(client.styles.js) */
|
|
1192
391
|
const SelectorBody = lazy(async () => {
|
|
1193
|
-
/*
|
|
1194
|
-
* 阶梯/调色板/滑轨映射等纯函数(可脱离 React 单测)。
|
|
1195
|
-
* 分块加载失败时退回空组件,保持插件的 fail-open 约定:宁可不渲染,
|
|
1196
|
-
* 也不让输入框因一个懒加载错误而崩掉。 */
|
|
392
|
+
/* 四个分块按序加载: */
|
|
1197
393
|
try {
|
|
1198
394
|
const styles = await require.async('./client.styles.js');
|
|
1199
395
|
const effort = await require.async('./client.effort.js');
|
|
396
|
+
const hooks = await require.async('./client.hooks.js');
|
|
397
|
+
const views = await require.async('./client.views.js');
|
|
1200
398
|
const css = styles.css(P, styles.METRICS);
|
|
1201
399
|
return {
|
|
1202
400
|
default: props => h(Selector, {
|
|
1203
|
-
...props, css,
|
|
401
|
+
...props, css, metrics: styles.METRICS,
|
|
402
|
+
effortApi: effort, hooksApi: hooks, viewsApi: views
|
|
1204
403
|
})
|
|
1205
404
|
};
|
|
1206
405
|
} catch (cause) {
|
|
@@ -1212,9 +411,7 @@ window.__ModuleLoader__.load({
|
|
|
1212
411
|
return h(Suspense, { fallback: null }, h(SelectorBody, props));
|
|
1213
412
|
}
|
|
1214
413
|
|
|
1215
|
-
/*
|
|
1216
|
-
* 插件
|
|
1217
|
-
* ================================================================== */
|
|
414
|
+
/* ============================================================ */
|
|
1218
415
|
return {
|
|
1219
416
|
inject: ['slots', 'modelDirectories', 'sessions', 'locale', 'remote', 'remote.session'],
|
|
1220
417
|
apply(ctx) {
|