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