dsh-model-select-plus 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/lib/client.cjs +137 -13
- package/package.json +4 -4
- package/src/client.js +144 -12
package/README.md
CHANGED
|
@@ -8,7 +8,10 @@
|
|
|
8
8
|
2. **推理等级一键切换**:行内点等级 chip 即切换模型+推理等级,无需二级钻取。
|
|
9
9
|
3. **搜索**:按模型名 / 描述 / provider 过滤,带放大镜图标与清除按钮。
|
|
10
10
|
4. **收藏置顶**:行首星标收藏,收藏项置顶为独立分组(插件生命周期内的浏览器内存保存)。
|
|
11
|
-
5.
|
|
11
|
+
5. **分组折叠**:非当前模型选中组默认折叠,仅当前模型所在组默认展开;点击分组标题即可折叠 / 展开,行尾带数量指示;手动折叠状态在菜单开合间保留,切换模型后自动展开新组;搜索时自动展开全部,避免匹配项被隐藏。
|
|
12
|
+
6. **模型组快捷 Tag 导航**:搜索栏下方展示所有模型组(含“★ 收藏”)标签,超出宽度自动换行,Tag 名后带组内模型数量 `(x)`;当前模型所在组高亮指示;点击任意 Tag 只展开该组并折叠其余组,同时平滑滚动定位,搜索状态下点击直达目标组。
|
|
13
|
+
7. **供应商/模型显示**:composer 触发按钮显示当前选择为 `供应商/模型` 格式,供应商取组显示名(缺失时回退 provider id)。
|
|
14
|
+
8. **视觉打磨**:`--dsw-alias-*` 主题令牌,浅/深色自适应;面板入场动画、quiet 触发按钮、细滚动条、居中的 SVG 星标、折叠箭头与圆角 Tag 徽章。
|
|
12
15
|
|
|
13
16
|
## 安装
|
|
14
17
|
|
package/lib/client.cjs
CHANGED
|
@@ -45,6 +45,7 @@ var module = { exports: {} };
|
|
|
45
45
|
var inject = ["slots"];
|
|
46
46
|
var API = "/plugins/dsh-model-select-plus/api";
|
|
47
47
|
var STYLE_TAG = "dsh-model-select-plus/style";
|
|
48
|
+
var FAVS_KEY = "__favorites__";
|
|
48
49
|
var CSS = `
|
|
49
50
|
.mdsl-root { position: relative; }
|
|
50
51
|
.mdsl-backdrop { position: fixed; inset: 0; z-index: 35; }
|
|
@@ -72,12 +73,25 @@ var module = { exports: {} };
|
|
|
72
73
|
.mdsl-search:focus { border-color: var(--dsw-alias-brand-primary); box-shadow: 0 0 0 3px var(--dsw-alias-interactive-bg-active); }
|
|
73
74
|
.mdsl-search-clear { position: absolute; right: 7px; border: none; background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-secondary); border-radius: 50%; width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; cursor: pointer; font-family: inherit; font-size: 12px; line-height: 1; }
|
|
74
75
|
.mdsl-search-clear:hover { background: var(--dsw-alias-interactive-bg-active); color: var(--dsw-alias-label-primary); }
|
|
75
|
-
.mdsl-
|
|
76
|
+
.mdsl-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-top: 8px; }
|
|
77
|
+
.mdsl-tag { flex: none; display: inline-flex; align-items: center; gap: 4px; font-family: inherit; font-size: 11px; line-height: 1.3; border: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-secondary); border-radius: 999px; padding: 2px 8px; cursor: pointer; user-select: none; transition: border-color .12s, color .12s, background .12s; }
|
|
78
|
+
.mdsl-tag:hover { border-color: var(--dsw-alias-border-l2); color: var(--dsw-alias-label-primary); background: var(--dsw-alias-interactive-bg-hover); }
|
|
79
|
+
.mdsl-tag:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-brand-primary); }
|
|
80
|
+
.mdsl-tag-current { border-color: var(--dsw-alias-brand-primary); color: var(--dsw-alias-brand-primary); background: var(--dsw-alias-interactive-bg-active); font-weight: 550; }
|
|
81
|
+
.mdsl-tag-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--dsw-alias-brand-primary); flex: none; }
|
|
82
|
+
.mdsl-tag-count { color: var(--dsw-alias-label-tertiary); font-weight: 500; }
|
|
83
|
+
.mdsl-body { flex: 1; min-height: 0; overflow-y: auto; padding: 5px; scrollbar-width: thin; scrollbar-color: var(--dsw-alias-scrollbar-bg-l1) transparent; }
|
|
76
84
|
.mdsl-body::-webkit-scrollbar { width: 7px; }
|
|
77
85
|
.mdsl-body::-webkit-scrollbar-thumb { background: var(--dsw-alias-scrollbar-bg-l1); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
|
|
78
86
|
.mdsl-body::-webkit-scrollbar-thumb:hover { background: var(--dsw-alias-scrollbar-hover-l1); }
|
|
79
87
|
.mdsl-group { display: flex; flex-direction: column; gap: 3px; margin-bottom: 4px; }
|
|
80
|
-
.mdsl-group-
|
|
88
|
+
.mdsl-group-collapsed { gap: 0; margin-bottom: 2px; }
|
|
89
|
+
.mdsl-group-title { display: flex; align-items: center; gap: 5px; font-size: 10px; font-weight: 600; color: var(--dsw-alias-label-tertiary); letter-spacing: .06em; text-transform: uppercase; padding: 5px 6px 3px; margin: 2px 2px 0; border-radius: 6px; cursor: pointer; user-select: none; transition: background .12s ease, color .12s ease; }
|
|
90
|
+
.mdsl-group-title:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-secondary); }
|
|
91
|
+
.mdsl-group-title:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-brand-primary); }
|
|
92
|
+
.mdsl-group-chevron { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 10px; height: 10px; color: currentColor; transform: rotate(90deg); transition: transform .14s ease; }
|
|
93
|
+
.mdsl-group-collapsed .mdsl-group-chevron { transform: none; }
|
|
94
|
+
.mdsl-group-count { margin-left: auto; font-weight: 500; letter-spacing: 0; opacity: .85; }
|
|
81
95
|
.mdsl-row { display: flex; align-items: flex-start; gap: 6px; padding: 6px 8px; border-radius: 10px; cursor: pointer; transition: background .12s ease; }
|
|
82
96
|
.mdsl-row:hover { background: var(--dsw-alias-interactive-bg-hover); }
|
|
83
97
|
.mdsl-row-current, .mdsl-row-current:hover { background: var(--dsw-alias-interactive-bg-active); }
|
|
@@ -116,6 +130,11 @@ var module = { exports: {} };
|
|
|
116
130
|
{ width: 14, height: 14, viewBox: "0 0 24 24", fill: filled ? "currentColor" : "none", xmlns: "http://www.w3.org/2000/svg" },
|
|
117
131
|
import_react.default.createElement("path", { d: "M12 2.6l2.86 5.8 6.4.94-4.63 4.5 1.1 6.37L12 17.02 6.27 20.2l1.1-6.37-4.63-4.5 6.4-.94L12 2.6z", stroke: "currentColor", strokeWidth: 1.5, strokeLinejoin: "round" })
|
|
118
132
|
);
|
|
133
|
+
var chevron = () => import_react.default.createElement(
|
|
134
|
+
"svg",
|
|
135
|
+
{ width: 9, height: 9, viewBox: "0 0 8 8", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
|
|
136
|
+
import_react.default.createElement("path", { d: "M2.2 1.6L5.4 4 2.2 6.4", stroke: "currentColor", strokeWidth: 1.3, strokeLinecap: "round", strokeLinejoin: "round" })
|
|
137
|
+
);
|
|
119
138
|
var searchIcon = () => import_react.default.createElement(
|
|
120
139
|
"span",
|
|
121
140
|
{ className: "mdsl-search-icon" },
|
|
@@ -129,11 +148,13 @@ var module = { exports: {} };
|
|
|
129
148
|
function ModelSelectLite(props) {
|
|
130
149
|
const sessionId = props.sessionId;
|
|
131
150
|
const locked = props.locked === true;
|
|
151
|
+
const bodyRef = import_react.default.useRef(null);
|
|
132
152
|
const [open, setOpen] = import_react.default.useState(false);
|
|
133
153
|
const [data, setData] = import_react.default.useState({ status: "idle", groups: [], failures: [], current: null, error: null });
|
|
134
154
|
const [query, setQuery] = import_react.default.useState("");
|
|
135
155
|
const [busy, setBusy] = import_react.default.useState(false);
|
|
136
156
|
const [, bump] = import_react.default.useState(0);
|
|
157
|
+
const [userToggled, setUserToggled] = import_react.default.useState(() => /* @__PURE__ */ new Map());
|
|
137
158
|
const load = () => {
|
|
138
159
|
setData((d) => ({ ...d, status: "loading", error: null }));
|
|
139
160
|
const url = `${API}/catalog?sessionId=${encodeURIComponent(sessionId)}`;
|
|
@@ -148,7 +169,10 @@ var module = { exports: {} };
|
|
|
148
169
|
});
|
|
149
170
|
};
|
|
150
171
|
import_react.default.useEffect(() => {
|
|
151
|
-
if (sessionId !== void 0)
|
|
172
|
+
if (sessionId !== void 0) {
|
|
173
|
+
setUserToggled(/* @__PURE__ */ new Map());
|
|
174
|
+
load();
|
|
175
|
+
}
|
|
152
176
|
}, [sessionId]);
|
|
153
177
|
const openMenu = () => {
|
|
154
178
|
setOpen(true);
|
|
@@ -174,6 +198,7 @@ var module = { exports: {} };
|
|
|
174
198
|
setBusy(false);
|
|
175
199
|
if (res && res.ok === true) {
|
|
176
200
|
setData((d) => ({ ...d, current: res.selected, error: null }));
|
|
201
|
+
setUserToggled(/* @__PURE__ */ new Map());
|
|
177
202
|
closeMenu();
|
|
178
203
|
} else {
|
|
179
204
|
setData((d) => ({ ...d, error: res && res.message || "\u9009\u62E9\u5931\u8D25" }));
|
|
@@ -192,10 +217,49 @@ var module = { exports: {} };
|
|
|
192
217
|
favorites = next;
|
|
193
218
|
bump((x) => x + 1);
|
|
194
219
|
};
|
|
220
|
+
const isGroupCollapsed = (gid) => {
|
|
221
|
+
if (query.trim() !== "") return false;
|
|
222
|
+
if (userToggled.has(gid)) return userToggled.get(gid);
|
|
223
|
+
const cur = data.current;
|
|
224
|
+
const isCurrentGroup = gid === FAVS_KEY ? cur !== null && favorites.has(cur.provider + "/" + cur.model) : cur !== null && cur.provider === gid;
|
|
225
|
+
return !isCurrentGroup;
|
|
226
|
+
};
|
|
227
|
+
const toggleCollapse = (gid) => {
|
|
228
|
+
const nextState = !isGroupCollapsed(gid);
|
|
229
|
+
setUserToggled((prev) => {
|
|
230
|
+
const next = new Map(prev);
|
|
231
|
+
next.set(gid, nextState);
|
|
232
|
+
return next;
|
|
233
|
+
});
|
|
234
|
+
};
|
|
235
|
+
const scrollToGroup = (gid) => {
|
|
236
|
+
if (query !== "") setQuery("");
|
|
237
|
+
setUserToggled((prev) => {
|
|
238
|
+
const next = /* @__PURE__ */ new Map();
|
|
239
|
+
if (data.groups) {
|
|
240
|
+
for (const g of data.groups) next.set(g.id, true);
|
|
241
|
+
}
|
|
242
|
+
next.set(FAVS_KEY, true);
|
|
243
|
+
next.set(gid, false);
|
|
244
|
+
return next;
|
|
245
|
+
});
|
|
246
|
+
setTimeout(() => {
|
|
247
|
+
if (!bodyRef.current) return;
|
|
248
|
+
const el = bodyRef.current.querySelector('[data-group-id="' + gid + '"]');
|
|
249
|
+
if (el) {
|
|
250
|
+
const bodyRect = bodyRef.current.getBoundingClientRect();
|
|
251
|
+
const elRect = el.getBoundingClientRect();
|
|
252
|
+
const targetScrollTop = bodyRef.current.scrollTop + (elRect.top - bodyRect.top);
|
|
253
|
+
bodyRef.current.scrollTo({ top: Math.max(0, targetScrollTop - 4), behavior: "smooth" });
|
|
254
|
+
}
|
|
255
|
+
}, 40);
|
|
256
|
+
};
|
|
195
257
|
const current = data.current;
|
|
196
258
|
const curGroup = current ? data.groups.find((g) => g.id === current.provider) : void 0;
|
|
197
259
|
const curModel = curGroup ? curGroup.models.find((mm) => mm.id === current.model) : void 0;
|
|
260
|
+
const providerName = curGroup ? curGroup.name : current ? current.provider : "";
|
|
198
261
|
const modelName = curModel && curModel.name || (current ? current.model : "\u9009\u62E9\u6A21\u578B");
|
|
262
|
+
const triggerLabel = current ? providerName + "/" + modelName : "\u9009\u62E9\u6A21\u578B";
|
|
199
263
|
const effEffort = current ? current.reasoningEffort !== void 0 ? current.reasoningEffort : curModel && curModel.reasoning ? curModel.reasoning.defaultEffort : void 0 : void 0;
|
|
200
264
|
const effMatch = effEffort && curModel && curModel.reasoning ? curModel.reasoning.efforts.find((e) => e.id === effEffort) : void 0;
|
|
201
265
|
const effLabel = effMatch ? effMatch.name : effEffort ? effEffort : curModel && curModel.reasoning ? "\u9ED8\u8BA4" : void 0;
|
|
@@ -211,6 +275,40 @@ var module = { exports: {} };
|
|
|
211
275
|
const filtered = q === "" ? allChoices : allChoices.filter((c) => (c.m.name + " " + (c.m.description || "") + " " + c.g.name).toLowerCase().includes(q));
|
|
212
276
|
const favs = filtered.filter((c) => favorites.has(`${c.g.id}/${c.m.id}`));
|
|
213
277
|
const nonFavs = filtered.filter((c) => !favorites.has(`${c.g.id}/${c.m.id}`));
|
|
278
|
+
const favsCollapsed = isGroupCollapsed(FAVS_KEY);
|
|
279
|
+
const tagList = [];
|
|
280
|
+
if (favorites.size > 0) {
|
|
281
|
+
const isCurrent = current !== null && favorites.has(current.provider + "/" + current.model);
|
|
282
|
+
tagList.push({ id: FAVS_KEY, name: "\u2605 \u6536\u85CF", isCurrent, count: favorites.size });
|
|
283
|
+
}
|
|
284
|
+
if (data.groups) {
|
|
285
|
+
for (const g of data.groups) {
|
|
286
|
+
if (g.models && g.models.length > 0) {
|
|
287
|
+
const isCurrent = current !== null && current.provider === g.id;
|
|
288
|
+
tagList.push({ id: g.id, name: g.name, isCurrent, count: g.models.length });
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
const groupTitle = (gid, name2, count, isCollapsed, interactive) => import_react.default.createElement(
|
|
293
|
+
"div",
|
|
294
|
+
{
|
|
295
|
+
className: "mdsl-group-title",
|
|
296
|
+
role: "button",
|
|
297
|
+
tabIndex: 0,
|
|
298
|
+
"aria-expanded": isCollapsed ? false : true,
|
|
299
|
+
title: (isCollapsed ? "\u5C55\u5F00\uFF1A" : "\u6298\u53E0\uFF1A") + name2,
|
|
300
|
+
onClick: interactive ? () => toggleCollapse(gid) : void 0,
|
|
301
|
+
onKeyDown: interactive ? (ev) => {
|
|
302
|
+
if (ev.key === "Enter" || ev.key === " ") {
|
|
303
|
+
ev.preventDefault();
|
|
304
|
+
toggleCollapse(gid);
|
|
305
|
+
}
|
|
306
|
+
} : void 0
|
|
307
|
+
},
|
|
308
|
+
import_react.default.createElement("span", { className: "mdsl-group-chevron" }, chevron()),
|
|
309
|
+
import_react.default.createElement("span", null, name2),
|
|
310
|
+
import_react.default.createElement("span", { className: "mdsl-group-count" }, count)
|
|
311
|
+
);
|
|
214
312
|
const renderRow = (c) => {
|
|
215
313
|
const hasEfforts = c.m.reasoning && c.m.reasoning.efforts && c.m.reasoning.efforts.length;
|
|
216
314
|
const effEff = current !== null && current.provider === c.g.id && current.model === c.m.id ? effEffort : hasEfforts ? c.m.reasoning.defaultEffort : void 0;
|
|
@@ -253,11 +351,16 @@ var module = { exports: {} };
|
|
|
253
351
|
const renderGroup = (g) => {
|
|
254
352
|
const items = nonFavs.filter((c) => c.g.id === g.id);
|
|
255
353
|
if (items.length === 0) return null;
|
|
354
|
+
const isCollapsed = isGroupCollapsed(g.id);
|
|
256
355
|
return import_react.default.createElement(
|
|
257
356
|
"div",
|
|
258
|
-
{
|
|
259
|
-
|
|
260
|
-
|
|
357
|
+
{
|
|
358
|
+
className: "mdsl-group" + (isCollapsed ? " mdsl-group-collapsed" : ""),
|
|
359
|
+
key: g.id,
|
|
360
|
+
"data-group-id": g.id
|
|
361
|
+
},
|
|
362
|
+
groupTitle(g.id, g.name, items.length, isCollapsed, q === ""),
|
|
363
|
+
isCollapsed ? null : items.map(renderRow)
|
|
261
364
|
);
|
|
262
365
|
};
|
|
263
366
|
return import_react.default.createElement(
|
|
@@ -272,9 +375,9 @@ var module = { exports: {} };
|
|
|
272
375
|
else openMenu();
|
|
273
376
|
},
|
|
274
377
|
disabled: locked,
|
|
275
|
-
title:
|
|
378
|
+
title: triggerLabel + (effLabel ? " \xB7 " + effLabel : "")
|
|
276
379
|
},
|
|
277
|
-
import_react.default.createElement("span", { className: "mdsl-label" },
|
|
380
|
+
import_react.default.createElement("span", { className: "mdsl-label" }, triggerLabel),
|
|
278
381
|
effLabel ? [import_react.default.createElement("span", { className: "mdsl-sep" }, "\xB7"), import_react.default.createElement("span", { className: "mdsl-effort" }, effLabel)] : null,
|
|
279
382
|
import_react.default.createElement("span", { className: "mdsl-chevron" + (open ? " mdsl-chevron-open" : "") }, "\u25BE")
|
|
280
383
|
),
|
|
@@ -299,20 +402,41 @@ var module = { exports: {} };
|
|
|
299
402
|
if (ev.key === "Escape") closeMenu();
|
|
300
403
|
} }),
|
|
301
404
|
query !== "" ? import_react.default.createElement("button", { className: "mdsl-search-clear", onClick: () => setQuery("") }, "\xD7") : null
|
|
302
|
-
)
|
|
405
|
+
),
|
|
406
|
+
tagList.length > 0 ? import_react.default.createElement(
|
|
407
|
+
"div",
|
|
408
|
+
{ className: "mdsl-tags" },
|
|
409
|
+
tagList.map((tag) => import_react.default.createElement(
|
|
410
|
+
"button",
|
|
411
|
+
{
|
|
412
|
+
key: tag.id,
|
|
413
|
+
type: "button",
|
|
414
|
+
className: "mdsl-tag" + (tag.isCurrent ? " mdsl-tag-current" : ""),
|
|
415
|
+
title: "\u8DF3\u8F6C\u81F3 " + tag.name,
|
|
416
|
+
onClick: () => scrollToGroup(tag.id)
|
|
417
|
+
},
|
|
418
|
+
tag.isCurrent ? import_react.default.createElement("span", { className: "mdsl-tag-dot" }) : null,
|
|
419
|
+
import_react.default.createElement("span", null, tag.name),
|
|
420
|
+
import_react.default.createElement("span", { className: "mdsl-tag-count" }, "(" + tag.count + ")")
|
|
421
|
+
))
|
|
422
|
+
) : null
|
|
303
423
|
),
|
|
304
424
|
data.status === "error" ? import_react.default.createElement("div", { className: "mdsl-error" }, data.error || "\u52A0\u8F7D\u5931\u8D25") : null,
|
|
305
425
|
data.failures && data.failures.length ? import_react.default.createElement("div", { className: "mdsl-error" }, data.failures.map((f) => f.name + ": " + f.message).join("\uFF1B")) : null,
|
|
306
426
|
import_react.default.createElement(
|
|
307
427
|
"div",
|
|
308
|
-
{ className: "mdsl-body" },
|
|
428
|
+
{ className: "mdsl-body", ref: bodyRef },
|
|
309
429
|
data.status === "loading" ? import_react.default.createElement("div", { className: "mdsl-empty" }, "\u52A0\u8F7D\u4E2D\u2026") : null,
|
|
310
430
|
data.status === "ready" && allChoices.length === 0 ? import_react.default.createElement("div", { className: "mdsl-empty" }, "\u6682\u65E0\u53EF\u7528\u6A21\u578B") : null,
|
|
311
431
|
favs.length ? import_react.default.createElement(
|
|
312
432
|
"div",
|
|
313
|
-
{
|
|
314
|
-
|
|
315
|
-
|
|
433
|
+
{
|
|
434
|
+
className: "mdsl-group" + (favsCollapsed ? " mdsl-group-collapsed" : ""),
|
|
435
|
+
key: FAVS_KEY,
|
|
436
|
+
"data-group-id": FAVS_KEY
|
|
437
|
+
},
|
|
438
|
+
groupTitle(FAVS_KEY, "\u6536\u85CF", favs.length, favsCollapsed, q === ""),
|
|
439
|
+
favsCollapsed ? null : favs.map(renderRow)
|
|
316
440
|
) : null,
|
|
317
441
|
(data.groups || []).map(renderGroup)
|
|
318
442
|
),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-model-select-plus",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "A richer model-selection popup for DeepSeek Harness: provider-grouped models with descriptions, inline reasoning-effort chips, search and pinned favorites — replaces the composer's default ModelSelect.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/host.js",
|
|
@@ -60,9 +60,9 @@
|
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"@deepseek-ai/cordis": "^4.0.2",
|
|
63
|
-
"@deepseek-ai/dsh-host-webserver": "^0.1.
|
|
64
|
-
"@deepseek-ai/dsh-client-ui-renderer": "^0.1.
|
|
65
|
-
"@deepseek-ai/dsh-client-ui-slots": "^0.1.
|
|
63
|
+
"@deepseek-ai/dsh-host-webserver": "^0.1.5-alpha.1",
|
|
64
|
+
"@deepseek-ai/dsh-client-ui-renderer": "^0.1.5-alpha.1",
|
|
65
|
+
"@deepseek-ai/dsh-client-ui-slots": "^0.1.5-alpha.1",
|
|
66
66
|
"react": "^18.3.1"
|
|
67
67
|
},
|
|
68
68
|
"peerDependenciesMeta": {
|
package/src/client.js
CHANGED
|
@@ -29,6 +29,7 @@ export const inject = ["slots"];
|
|
|
29
29
|
|
|
30
30
|
const API = "/plugins/dsh-model-select-plus/api";
|
|
31
31
|
const STYLE_TAG = "dsh-model-select-plus/style";
|
|
32
|
+
const FAVS_KEY = "__favorites__";
|
|
32
33
|
|
|
33
34
|
const CSS = `
|
|
34
35
|
.mdsl-root { position: relative; }
|
|
@@ -57,12 +58,25 @@ const CSS = `
|
|
|
57
58
|
.mdsl-search:focus { border-color: var(--dsw-alias-brand-primary); box-shadow: 0 0 0 3px var(--dsw-alias-interactive-bg-active); }
|
|
58
59
|
.mdsl-search-clear { position: absolute; right: 7px; border: none; background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-secondary); border-radius: 50%; width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; cursor: pointer; font-family: inherit; font-size: 12px; line-height: 1; }
|
|
59
60
|
.mdsl-search-clear:hover { background: var(--dsw-alias-interactive-bg-active); color: var(--dsw-alias-label-primary); }
|
|
60
|
-
.mdsl-
|
|
61
|
+
.mdsl-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-top: 8px; }
|
|
62
|
+
.mdsl-tag { flex: none; display: inline-flex; align-items: center; gap: 4px; font-family: inherit; font-size: 11px; line-height: 1.3; border: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-secondary); border-radius: 999px; padding: 2px 8px; cursor: pointer; user-select: none; transition: border-color .12s, color .12s, background .12s; }
|
|
63
|
+
.mdsl-tag:hover { border-color: var(--dsw-alias-border-l2); color: var(--dsw-alias-label-primary); background: var(--dsw-alias-interactive-bg-hover); }
|
|
64
|
+
.mdsl-tag:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-brand-primary); }
|
|
65
|
+
.mdsl-tag-current { border-color: var(--dsw-alias-brand-primary); color: var(--dsw-alias-brand-primary); background: var(--dsw-alias-interactive-bg-active); font-weight: 550; }
|
|
66
|
+
.mdsl-tag-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--dsw-alias-brand-primary); flex: none; }
|
|
67
|
+
.mdsl-tag-count { color: var(--dsw-alias-label-tertiary); font-weight: 500; }
|
|
68
|
+
.mdsl-body { flex: 1; min-height: 0; overflow-y: auto; padding: 5px; scrollbar-width: thin; scrollbar-color: var(--dsw-alias-scrollbar-bg-l1) transparent; }
|
|
61
69
|
.mdsl-body::-webkit-scrollbar { width: 7px; }
|
|
62
70
|
.mdsl-body::-webkit-scrollbar-thumb { background: var(--dsw-alias-scrollbar-bg-l1); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
|
|
63
71
|
.mdsl-body::-webkit-scrollbar-thumb:hover { background: var(--dsw-alias-scrollbar-hover-l1); }
|
|
64
72
|
.mdsl-group { display: flex; flex-direction: column; gap: 3px; margin-bottom: 4px; }
|
|
65
|
-
.mdsl-group-
|
|
73
|
+
.mdsl-group-collapsed { gap: 0; margin-bottom: 2px; }
|
|
74
|
+
.mdsl-group-title { display: flex; align-items: center; gap: 5px; font-size: 10px; font-weight: 600; color: var(--dsw-alias-label-tertiary); letter-spacing: .06em; text-transform: uppercase; padding: 5px 6px 3px; margin: 2px 2px 0; border-radius: 6px; cursor: pointer; user-select: none; transition: background .12s ease, color .12s ease; }
|
|
75
|
+
.mdsl-group-title:hover { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-secondary); }
|
|
76
|
+
.mdsl-group-title:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--dsw-alias-brand-primary); }
|
|
77
|
+
.mdsl-group-chevron { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 10px; height: 10px; color: currentColor; transform: rotate(90deg); transition: transform .14s ease; }
|
|
78
|
+
.mdsl-group-collapsed .mdsl-group-chevron { transform: none; }
|
|
79
|
+
.mdsl-group-count { margin-left: auto; font-weight: 500; letter-spacing: 0; opacity: .85; }
|
|
66
80
|
.mdsl-row { display: flex; align-items: flex-start; gap: 6px; padding: 6px 8px; border-radius: 10px; cursor: pointer; transition: background .12s ease; }
|
|
67
81
|
.mdsl-row:hover { background: var(--dsw-alias-interactive-bg-hover); }
|
|
68
82
|
.mdsl-row-current, .mdsl-row-current:hover { background: var(--dsw-alias-interactive-bg-active); }
|
|
@@ -100,6 +114,12 @@ const star = (filled) => React.createElement(
|
|
|
100
114
|
React.createElement("path", { d: "M12 2.6l2.86 5.8 6.4.94-4.63 4.5 1.1 6.37L12 17.02 6.27 20.2l1.1-6.37-4.63-4.5 6.4-.94L12 2.6z", stroke: "currentColor", strokeWidth: 1.5, strokeLinejoin: "round" }),
|
|
101
115
|
);
|
|
102
116
|
|
|
117
|
+
const chevron = () => React.createElement(
|
|
118
|
+
"svg",
|
|
119
|
+
{ width: 9, height: 9, viewBox: "0 0 8 8", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
|
|
120
|
+
React.createElement("path", { d: "M2.2 1.6L5.4 4 2.2 6.4", stroke: "currentColor", strokeWidth: 1.3, strokeLinecap: "round", strokeLinejoin: "round" }),
|
|
121
|
+
);
|
|
122
|
+
|
|
103
123
|
const searchIcon = () => React.createElement(
|
|
104
124
|
"span",
|
|
105
125
|
{ className: "mdsl-search-icon" },
|
|
@@ -114,11 +134,16 @@ const searchIcon = () => React.createElement(
|
|
|
114
134
|
function ModelSelectLite(props) {
|
|
115
135
|
const sessionId = props.sessionId;
|
|
116
136
|
const locked = props.locked === true;
|
|
137
|
+
const bodyRef = React.useRef(null);
|
|
117
138
|
const [open, setOpen] = React.useState(false);
|
|
118
139
|
const [data, setData] = React.useState({ status: "idle", groups: [], failures: [], current: null, error: null });
|
|
119
140
|
const [query, setQuery] = React.useState("");
|
|
120
141
|
const [busy, setBusy] = React.useState(false);
|
|
121
142
|
const [, bump] = React.useState(0);
|
|
143
|
+
// Manual overrides for group fold state (id -> boolean). By default, only
|
|
144
|
+
// the group containing the currently selected model is expanded; all other
|
|
145
|
+
// groups default to collapsed. Searching force-expands every group.
|
|
146
|
+
const [userToggled, setUserToggled] = React.useState(() => new Map());
|
|
122
147
|
|
|
123
148
|
const load = () => {
|
|
124
149
|
setData((d) => ({ ...d, status: "loading", error: null }));
|
|
@@ -139,7 +164,12 @@ function ModelSelectLite(props) {
|
|
|
139
164
|
|
|
140
165
|
// Load on mount (and when the session changes) so the trigger shows the
|
|
141
166
|
// current model immediately instead of the "选择模型" placeholder.
|
|
142
|
-
React.useEffect(() => {
|
|
167
|
+
React.useEffect(() => {
|
|
168
|
+
if (sessionId !== undefined) {
|
|
169
|
+
setUserToggled(new Map());
|
|
170
|
+
load();
|
|
171
|
+
}
|
|
172
|
+
}, [sessionId]);
|
|
143
173
|
|
|
144
174
|
const openMenu = () => { setOpen(true); load(); };
|
|
145
175
|
const closeMenu = () => { setOpen(false); setQuery(""); };
|
|
@@ -162,6 +192,7 @@ function ModelSelectLite(props) {
|
|
|
162
192
|
setBusy(false);
|
|
163
193
|
if (res && res.ok === true) {
|
|
164
194
|
setData((d) => ({ ...d, current: res.selected, error: null }));
|
|
195
|
+
setUserToggled(new Map());
|
|
165
196
|
closeMenu();
|
|
166
197
|
} else {
|
|
167
198
|
setData((d) => ({ ...d, error: (res && res.message) || "选择失败" }));
|
|
@@ -182,10 +213,56 @@ function ModelSelectLite(props) {
|
|
|
182
213
|
bump((x) => x + 1);
|
|
183
214
|
};
|
|
184
215
|
|
|
216
|
+
const isGroupCollapsed = (gid) => {
|
|
217
|
+
if (query.trim() !== "") return false;
|
|
218
|
+
if (userToggled.has(gid)) return userToggled.get(gid);
|
|
219
|
+
const cur = data.current;
|
|
220
|
+
const isCurrentGroup = gid === FAVS_KEY
|
|
221
|
+
? (cur !== null && favorites.has(cur.provider + "/" + cur.model))
|
|
222
|
+
: (cur !== null && cur.provider === gid);
|
|
223
|
+
return !isCurrentGroup;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const toggleCollapse = (gid) => {
|
|
227
|
+
const nextState = !isGroupCollapsed(gid);
|
|
228
|
+
setUserToggled((prev) => {
|
|
229
|
+
const next = new Map(prev);
|
|
230
|
+
next.set(gid, nextState);
|
|
231
|
+
return next;
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const scrollToGroup = (gid) => {
|
|
236
|
+
if (query !== "") setQuery("");
|
|
237
|
+
setUserToggled((prev) => {
|
|
238
|
+
// 点击 Tag:只展开目标组,收藏组与其余模型组全部折叠
|
|
239
|
+
const next = new Map();
|
|
240
|
+
if (data.groups) {
|
|
241
|
+
for (const g of data.groups) next.set(g.id, true);
|
|
242
|
+
}
|
|
243
|
+
next.set(FAVS_KEY, true);
|
|
244
|
+
next.set(gid, false);
|
|
245
|
+
return next;
|
|
246
|
+
});
|
|
247
|
+
setTimeout(() => {
|
|
248
|
+
if (!bodyRef.current) return;
|
|
249
|
+
const el = bodyRef.current.querySelector('[data-group-id="' + gid + '"]');
|
|
250
|
+
if (el) {
|
|
251
|
+
const bodyRect = bodyRef.current.getBoundingClientRect();
|
|
252
|
+
const elRect = el.getBoundingClientRect();
|
|
253
|
+
const targetScrollTop = bodyRef.current.scrollTop + (elRect.top - bodyRect.top);
|
|
254
|
+
bodyRef.current.scrollTo({ top: Math.max(0, targetScrollTop - 4), behavior: "smooth" });
|
|
255
|
+
}
|
|
256
|
+
}, 40);
|
|
257
|
+
};
|
|
258
|
+
|
|
185
259
|
const current = data.current;
|
|
186
260
|
const curGroup = current ? data.groups.find((g) => g.id === current.provider) : undefined;
|
|
187
261
|
const curModel = curGroup ? curGroup.models.find((mm) => mm.id === current.model) : undefined;
|
|
262
|
+
// trigger 按钮显示“供应商/模型”,供应商取组的显示名,找不到组时回退 provider id。
|
|
263
|
+
const providerName = curGroup ? curGroup.name : (current ? current.provider : "");
|
|
188
264
|
const modelName = (curModel && curModel.name) || (current ? current.model : "选择模型");
|
|
265
|
+
const triggerLabel = current ? (providerName + "/" + modelName) : "选择模型";
|
|
189
266
|
const effEffort = current
|
|
190
267
|
? (current.reasoningEffort !== undefined ? current.reasoningEffort : (curModel && curModel.reasoning ? curModel.reasoning.defaultEffort : undefined))
|
|
191
268
|
: undefined;
|
|
@@ -205,6 +282,39 @@ function ModelSelectLite(props) {
|
|
|
205
282
|
const filtered = q === "" ? allChoices : allChoices.filter((c) => (c.m.name + " " + (c.m.description || "") + " " + c.g.name).toLowerCase().includes(q));
|
|
206
283
|
const favs = filtered.filter((c) => favorites.has(`${c.g.id}/${c.m.id}`));
|
|
207
284
|
const nonFavs = filtered.filter((c) => !favorites.has(`${c.g.id}/${c.m.id}`));
|
|
285
|
+
const favsCollapsed = isGroupCollapsed(FAVS_KEY);
|
|
286
|
+
|
|
287
|
+
const tagList = [];
|
|
288
|
+
if (favorites.size > 0) {
|
|
289
|
+
const isCurrent = current !== null && favorites.has(current.provider + "/" + current.model);
|
|
290
|
+
tagList.push({ id: FAVS_KEY, name: "★ 收藏", isCurrent, count: favorites.size });
|
|
291
|
+
}
|
|
292
|
+
if (data.groups) {
|
|
293
|
+
for (const g of data.groups) {
|
|
294
|
+
if (g.models && g.models.length > 0) {
|
|
295
|
+
const isCurrent = current !== null && current.provider === g.id;
|
|
296
|
+
tagList.push({ id: g.id, name: g.name, isCurrent, count: g.models.length });
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// Group header doubles as a collapse toggle (Enter/Space work too); while
|
|
302
|
+
// searching it is inert and every group renders expanded.
|
|
303
|
+
const groupTitle = (gid, name, count, isCollapsed, interactive) => React.createElement(
|
|
304
|
+
"div",
|
|
305
|
+
{
|
|
306
|
+
className: "mdsl-group-title",
|
|
307
|
+
role: "button",
|
|
308
|
+
tabIndex: 0,
|
|
309
|
+
"aria-expanded": isCollapsed ? false : true,
|
|
310
|
+
title: (isCollapsed ? "展开:" : "折叠:") + name,
|
|
311
|
+
onClick: interactive ? () => toggleCollapse(gid) : undefined,
|
|
312
|
+
onKeyDown: interactive ? (ev) => { if (ev.key === "Enter" || ev.key === " ") { ev.preventDefault(); toggleCollapse(gid); } } : undefined,
|
|
313
|
+
},
|
|
314
|
+
React.createElement("span", { className: "mdsl-group-chevron" }, chevron()),
|
|
315
|
+
React.createElement("span", null, name),
|
|
316
|
+
React.createElement("span", { className: "mdsl-group-count" }, count),
|
|
317
|
+
);
|
|
208
318
|
|
|
209
319
|
const renderRow = (c) => {
|
|
210
320
|
const hasEfforts = c.m.reasoning && c.m.reasoning.efforts && c.m.reasoning.efforts.length;
|
|
@@ -237,9 +347,14 @@ function ModelSelectLite(props) {
|
|
|
237
347
|
const renderGroup = (g) => {
|
|
238
348
|
const items = nonFavs.filter((c) => c.g.id === g.id);
|
|
239
349
|
if (items.length === 0) return null;
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
350
|
+
const isCollapsed = isGroupCollapsed(g.id);
|
|
351
|
+
return React.createElement("div", {
|
|
352
|
+
className: "mdsl-group" + (isCollapsed ? " mdsl-group-collapsed" : ""),
|
|
353
|
+
key: g.id,
|
|
354
|
+
"data-group-id": g.id,
|
|
355
|
+
},
|
|
356
|
+
groupTitle(g.id, g.name, items.length, isCollapsed, q === ""),
|
|
357
|
+
isCollapsed ? null : items.map(renderRow),
|
|
243
358
|
);
|
|
244
359
|
};
|
|
245
360
|
|
|
@@ -248,9 +363,9 @@ function ModelSelectLite(props) {
|
|
|
248
363
|
className: "mdsl-trigger",
|
|
249
364
|
onClick: () => { if (open) closeMenu(); else openMenu(); },
|
|
250
365
|
disabled: locked,
|
|
251
|
-
title:
|
|
366
|
+
title: triggerLabel + (effLabel ? " · " + effLabel : ""),
|
|
252
367
|
},
|
|
253
|
-
React.createElement("span", { className: "mdsl-label" },
|
|
368
|
+
React.createElement("span", { className: "mdsl-label" }, triggerLabel),
|
|
254
369
|
effLabel ? [React.createElement("span", { className: "mdsl-sep" }, "·"), React.createElement("span", { className: "mdsl-effort" }, effLabel)] : null,
|
|
255
370
|
React.createElement("span", { className: "mdsl-chevron" + (open ? " mdsl-chevron-open" : "") }, "▾"),
|
|
256
371
|
),
|
|
@@ -268,15 +383,32 @@ function ModelSelectLite(props) {
|
|
|
268
383
|
React.createElement("input", { className: "mdsl-search", placeholder: "搜索模型 / 描述 / 提供商…", value: query, onChange: (ev) => setQuery(ev.target.value), onKeyDown: (ev) => { if (ev.key === "Escape") closeMenu(); } }),
|
|
269
384
|
query !== "" ? React.createElement("button", { className: "mdsl-search-clear", onClick: () => setQuery("") }, "×") : null,
|
|
270
385
|
),
|
|
386
|
+
tagList.length > 0 ? React.createElement("div", { className: "mdsl-tags" },
|
|
387
|
+
tagList.map((tag) => React.createElement("button", {
|
|
388
|
+
key: tag.id,
|
|
389
|
+
type: "button",
|
|
390
|
+
className: "mdsl-tag" + (tag.isCurrent ? " mdsl-tag-current" : ""),
|
|
391
|
+
title: "跳转至 " + tag.name,
|
|
392
|
+
onClick: () => scrollToGroup(tag.id),
|
|
393
|
+
},
|
|
394
|
+
tag.isCurrent ? React.createElement("span", { className: "mdsl-tag-dot" }) : null,
|
|
395
|
+
React.createElement("span", null, tag.name),
|
|
396
|
+
React.createElement("span", { className: "mdsl-tag-count" }, "(" + tag.count + ")"),
|
|
397
|
+
)),
|
|
398
|
+
) : null,
|
|
271
399
|
),
|
|
272
400
|
data.status === "error" ? React.createElement("div", { className: "mdsl-error" }, data.error || "加载失败") : null,
|
|
273
401
|
data.failures && data.failures.length ? React.createElement("div", { className: "mdsl-error" }, data.failures.map((f) => f.name + ": " + f.message).join(";")) : null,
|
|
274
|
-
React.createElement("div", { className: "mdsl-body" },
|
|
402
|
+
React.createElement("div", { className: "mdsl-body", ref: bodyRef },
|
|
275
403
|
data.status === "loading" ? React.createElement("div", { className: "mdsl-empty" }, "加载中…") : null,
|
|
276
404
|
data.status === "ready" && allChoices.length === 0 ? React.createElement("div", { className: "mdsl-empty" }, "暂无可用模型") : null,
|
|
277
|
-
favs.length ? React.createElement("div", {
|
|
278
|
-
|
|
279
|
-
|
|
405
|
+
favs.length ? React.createElement("div", {
|
|
406
|
+
className: "mdsl-group" + (favsCollapsed ? " mdsl-group-collapsed" : ""),
|
|
407
|
+
key: FAVS_KEY,
|
|
408
|
+
"data-group-id": FAVS_KEY,
|
|
409
|
+
},
|
|
410
|
+
groupTitle(FAVS_KEY, "收藏", favs.length, favsCollapsed, q === ""),
|
|
411
|
+
favsCollapsed ? null : favs.map(renderRow),
|
|
280
412
|
) : null,
|
|
281
413
|
(data.groups || []).map(renderGroup),
|
|
282
414
|
),
|