Skip to content

🤖 Open-source, local-first alternative to Grok Bot, OpenAI dots and Claude Duet. Your own AI bots on any model: GPT, Claude, Gemini, Grok, DeepSeek, Kimi, GLM and 70+ more through one Modelflare key. Reach them in the app, WeChat or Feishu; they remember you, work in the background, run commands and use your computer. Pay per use.

feat(ui): 模型选择器按模型族分组,可展开收起

dyk98d06c2c9cfcb2
diff --git a/test/model-family.unit.test.ts b/test/model-family.unit.test.ts
new file mode 100644
index 0000000..a89a479
--- /dev/null
+++ b/test/model-family.unit.test.ts
@@ -0,0 +1,38 @@
+/** 模型选择器的模型族分组:Modelflare 的 ID 不带厂商前缀,按名字归族,族内版本新的在前。 */
+import { describe, it, expect } from "vitest";
+// @ts-expect-error 界面代码是不经构建的 JS
+import { groupModels, modelFamily } from "../ui/lib/models.js";
+
+// Modelflare 2026-10-30 公开的对话模型(节选)
+const LIST = [
+ "claude-fable-5", "claude-fable-5-1", "claude-haiku-4-5", "claude-opus-5", "claude-opus-5-5", "claude-sonnet-5-5",
+ "codex-auto-review", "deepseek-v4-flash", "deepseek-v4.1-flash", "gemini-3.1-pro-preview", "gemini-3.8-flash",
+ "glm-5.3", "gpt-5.4", "gpt-5.6-sol", "gpt-6-sol", "gpt-6.1-sol", "grok-4.5", "grok-4.7", "kimi-k3", "muse-spark-1.3", "qwen3.8-max",
+];
+
+describe("模型族", () => {
+ it("按名字认族;认不出的归「其他」,带 modelflare/ 前缀也一样", () => {
+ expect(modelFamily("gpt-6-sol")).toBe("GPT");
+ expect(modelFamily("o3-mini")).toBe("GPT");
+ expect(modelFamily("codex-auto-review")).toBe("GPT");
+ expect(modelFamily("modelflare/claude-opus-5-5")).toBe("Claude");
+ expect(modelFamily("qwen3.8-max")).toBe("Qwen");
+ expect(modelFamily("kimi-k3")).toBe("Kimi");
+ expect(modelFamily("muse-spark-1.3")).toBe("其他");
+ });
+
+ it("族按固定顺序,「其他」最后;族内版本新的在前,同版本按名字", () => {
+ const g = groupModels(LIST);
+ expect(g.map(([f]: [string]) => f)).toEqual(["GPT", "Claude", "Gemini", "Grok", "DeepSeek", "Qwen", "Kimi", "GLM", "其他"]);
+ const of = (f: string) => g.find(([x]: [string]) => x === f)[1].map(([, label]: [string, string]) => label);
+ expect(of("GPT")).toEqual(["gpt-6.1-sol", "gpt-6-sol", "gpt-5.6-sol", "gpt-5.4", "codex-auto-review"]);
+ expect(of("Claude")).toEqual(["claude-opus-5-5", "claude-sonnet-5-5", "claude-fable-5-1", "claude-fable-5", "claude-opus-5", "claude-haiku-4-5"]);
+ expect(of("DeepSeek")).toEqual(["deepseek-v4.1-flash", "deepseek-v4-flash"]);
+ });
+
+ it("日期后缀不当版本号;筛选只留匹配的族", () => {
+ const g = groupModels(["claude-sonnet-4-20250514", "claude-3-5-sonnet-20241022", "claude-opus-4-1"]);
+ expect(g[0][1].map(([m]: [string]) => m)).toEqual(["claude-opus-4-1", "claude-sonnet-4-20250514", "claude-3-5-sonnet-20241022"]);
+ expect(groupModels(LIST, "flash").map(([f]: [string]) => f)).toEqual(["Gemini", "DeepSeek"]);
+ });
+});
diff --git a/ui/components/model-picker.js b/ui/components/model-picker.js
index 9e24171..39f0dbb 100644
--- a/ui/components/model-picker.js
+++ b/ui/components/model-picker.js
@@ -1,14 +1,12 @@
-// 模型选择器(magpie picker 的样式;数据来自 Modelflare 的 /v1/models)。
+// 模型选择器(magpie picker 的样式;数据来自 Modelflare 的 /v1/models)。按模型族分组,组头可以展开收起。
// 不做厂商图标栏:各厂商 logo 是第三方商标,未取得授权前不用。
import { useEffect, useMemo, useRef, useState } from "preact/hooks";
import { html, Popover, Icon } from "./ui.js";
import { api } from "../lib/api.js";
import { createStore, useStore } from "../lib/store.js";
+import { groupModels, modelFamily, normModel, sameModel } from "../lib/models.js";
-/** 内置网关列出的模型带 "modelflare/" 前缀,Modelflare 直接列出的不带;两种写法都能调用,显示与比较时去掉它 */
-export const normModel = (m) => (m && m.startsWith("modelflare/") ? m.slice("modelflare/".length) : m || "");
-export const sameModel = (a, b) => !!a && !!b && normModel(a) === normModel(b);
-export const shortModel = (m) => (m && m.includes("/") ? m.slice(m.lastIndexOf("/") + 1) : m);
+export { groupModels, normModel, sameModel, shortModel } from "../lib/models.js";
// —— 模型能力与参考价(/models/info,后端缓存一小时;界面第一次打开选择器时取一次)——
const infoStore = createStore(null);
@@ -41,23 +39,28 @@ export function modelNote(info, id) {
}
const NOTE_TITLE = "上下文 · 能力 · 每百万 tokens 输入/输出的起步参考价(美元,以账单为准)";
-/** 按 "厂商/模型" 的前缀分组(没有前缀的放在最后);返回 [厂商, [[原始 id, 显示名]]] */
-export function groupModels(models, q = "") {
- const needle = q.trim().toLowerCase();
- const groups = new Map();
- for (const m of models) {
- const n = normModel(m);
- if (needle && !n.toLowerCase().includes(needle)) continue;
- const k = n.includes("/") ? n.slice(0, n.indexOf("/")) : "";
- if (!groups.has(k)) groups.set(k, []);
- groups.get(k).push([m, k ? n.slice(k.length + 1) : n]);
- }
- return [...groups.entries()].sort((a, b) => (a[0] === "" ? 1 : b[0] === "" ? -1 : a[0].localeCompare(b[0])));
+// —— 模型族的开合:当前模型所在的族默认展开(没有当前模型时展开第一个);用户点过的按点的算,本次运行内记住 ——
+const famOpen = new Map();
+export function useFamilies(groups, current) {
+ const [, redraw] = useState(0);
+ const curFam = current ? modelFamily(current) : groups[0]?.[0];
+ const isOpen = (g) => famOpen.get(g) ?? g === curFam;
+ const toggle = (g) => {
+ famOpen.set(g, !isOpen(g));
+ redraw((n) => n + 1);
+ };
+ return { isOpen, toggle };
+}
+
+/** 组头的内容:族名、收起时里面的当前模型、数量、箭头(展开时转向下) */
+export function FamilyHead({ name, count, current }) {
+ return html`<span class="v">${name}</span><span class="n">${current || ""}</span><span class="cnt">${count}</span><${Icon} name="chevRight" size=${12} class="chev" />`;
}
/**
* models: string[] | null(加载中);error: 加载失败时的说明。
* reset: { label, note, onSelect } 顶部"恢复默认"项;foot: { label, onClick, disabled } 底部操作。
+ * 不筛选时按模型族折叠(只有一个族时不出组头);筛选时全部展开,组名只作标签。
*/
export function ModelPicker({ anchor, models, error, current, onPick, onClose, reset, foot, onRetry, prefer = "down", align = "left" }) {
const [q, setQ] = useState("");
@@ -65,23 +68,51 @@ export function ModelPicker({ anchor, models, error, current, onPick, onClose, r
const listRef = useRef(null);
const info = useModelInfo();
const groups = useMemo(() => groupModels(models || [], q), [models, q]);
+ const { isOpen, toggle } = useFamilies(groups, current);
+ const folding = !q.trim() && groups.length > 1;
const custom = q.trim() && !(models || []).some((m) => sameModel(m, q.trim())) ? q.trim() : "";
- const flat = [...(reset && !q ? [{ reset: true }] : []), ...groups.flatMap(([, ms]) => ms.map(([m]) => ({ m }))), ...(custom ? [{ m: custom, custom: true }] : [])];
+ const flat = [
+ ...(reset && !q ? [{ reset: true }] : []),
+ ...groups.flatMap(([g, ms]) => {
+ const rows = ms.map(([m]) => ({ m, g }));
+ return folding ? [{ fam: g }, ...(isOpen(g) ? rows : [])] : rows;
+ }),
+ ...(custom ? [{ m: custom, custom: true }] : []),
+ ];
+ // 列表到了以后,指向并滚到当前模型
+ const placed = useRef(false);
+ useEffect(() => {
+ if (placed.current || !models?.length) return;
+ placed.current = true;
+ const i = flat.findIndex((it) => it.m && sameModel(it.m, current));
+ if (i < 0) return;
+ setSel(i);
+ requestAnimationFrame(() => listRef.current?.querySelector("li.cur")?.scrollIntoView({ block: "nearest" }));
+ }, [models]);
const choose = (it) => {
onClose();
if (it.reset) reset.onSelect();
else onPick(it.m);
};
const onKey = (e) => {
+ const it = flat[sel];
if (e.key === "ArrowDown") {
e.preventDefault();
setSel((s) => Math.min(flat.length - 1, s + 1));
} else if (e.key === "ArrowUp") {
e.preventDefault();
setSel((s) => Math.max(0, s - 1));
- } else if (e.key === "Enter" && flat[sel]) {
+ } else if (e.key === "Enter" && it) {
+ e.preventDefault();
+ if (it.fam) toggle(it.fam);
+ else choose(it);
+ } else if (folding && it && (e.key === "ArrowRight" || e.key === "ArrowLeft")) {
+ // 输入框是空的(folding 时 q 为空),左右键不会挪光标:→ 展开,← 收起;在模型上按 ← 收起它所在的族
e.preventDefault();
- choose(flat[sel]);
+ const g = it.fam || it.g;
+ if (!g || (it.m && e.key === "ArrowRight")) return;
+ if (isOpen(g) !== (e.key === "ArrowRight")) toggle(g);
+ if (it.m) setSel(flat.findIndex((x) => x.fam === g));
}
requestAnimationFrame(() => listRef.current?.querySelector("li.sel")?.scrollIntoView({ block: "nearest" }));
};
@@ -95,6 +126,16 @@ export function ModelPicker({ anchor, models, error, current, onPick, onClose, r
<span class="check"><${Icon} name="check" size=${14} /></span>
</li>`;
};
+ const head = (g, ms) => {
+ idx++;
+ const i = idx;
+ const open = isOpen(g);
+ const cur = open ? undefined : ms.find(([m]) => sameModel(m, current));
+ return html`<li class=${`fam ${sel === i ? "sel" : ""}`} aria-expanded=${open} onPointerMove=${() => setSel(i)} onClick=${() => toggle(g)}>
+ <${FamilyHead} name=${g} count=${ms.length} current=${cur?.[1]} />
+ </li>`;
+ };
+ const rows = (ms) => ms.map(([m, label]) => item({ m }, label, modelNote(info, m)));
return html`<${Popover} anchor=${anchor} onClose=${onClose} class="model-picker" width=${340} maxHeight=${420} prefer=${prefer} align=${align} label="选择模型">
<div class="search"><${Icon} name="search" size=${14} />
<input placeholder="筛选,或输入任意模型 ID" value=${q} onInput=${(e) => { setQ(e.target.value); setSel(0); }} onKeyDown=${onKey} aria-label="筛选模型" />
@@ -104,7 +145,9 @@ export function ModelPicker({ anchor, models, error, current, onPick, onClose, r
${error && html`<li class="explained" style="pointer-events:auto"><span class="v" style="white-space:normal;color:var(--red)">获取模型列表失败:${error}</span>
${onRetry && html`<button type="button" class="text" onClick=${onRetry}>重试</button>`}</li>`}
${reset && !q && item({ reset: true }, reset.label, reset.note)}
- ${groups.map(([g, ms]) => html`${g && html`<li class="group">${g}</li>`}${ms.map(([m, label]) => item({ m }, label, modelNote(info, m)))}`)}
+ ${groups.map(([g, ms]) =>
+ folding ? html`${head(g, ms)}${isOpen(g) && rows(ms)}` : html`${groups.length > 1 && html`<li class="group">${g}</li>`}${rows(ms)}`,
+ )}
${custom && item({ m: custom, custom: true }, `使用「${custom}」`, "自定义模型 ID")}
${models && !models.length && !q && html`<li class="explained"><span class="v" style="white-space:normal">没有可用模型:这个 Key 所在的分组还没有开放模型</span></li>`}
</ul>
diff --git a/ui/design/README.md b/ui/design/README.md
index 45df251..bc191f3 100644
--- a/ui/design/README.md
+++ b/ui/design/README.md
@@ -19,7 +19,7 @@ ui/design/
motion.css 关键帧库 + .anim-* 工具类 + 减少动态效果
typography.css 文字角色 .t-*(在 utilities 层)
utilities.css .stack .cluster .grow .truncate .tone-* .sr-only
- components/ 一个组件一个文件:glass button field badge list seg switch popover sheet toast notice feedback avatar
+ components/ 一个组件一个文件:glass button field badge list seg switch popover model-family sheet toast notice feedback avatar
motion.js ms("--dur-base")、usePresence()、reducedMotion()
index.html / gallery.* 样例页
ui/css/ 页面样式(shell / chat / settings),放在 app 层
diff --git a/ui/design/components/model-family.css b/ui/design/components/model-family.css
new file mode 100644
index 0000000..44fac3d
--- /dev/null
+++ b/ui/design/components/model-family.css
@@ -0,0 +1,9 @@
+/* 模型族组头 .fam(模型选择器 .model-picker、引导页的 .picklist):点一下展开或收起这一族。
+ 族名和模型名落在同一条文字线上(不缩进),靠字重、数量和箭头区分;收起时把里面的当前模型名带出来。 */
+.fam .v { font-weight: var(--fw-semibold); color: var(--fg); }
+.fam .n { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-xs); color: var(--muted); }
+.fam .cnt { flex: none; margin-left: auto; font-size: var(--fs-2xs); color: var(--muted); font-variant-numeric: tabular-nums; }
+.fam .chev { flex: none; color: var(--muted); transition: transform var(--t-base); }
+.fam[aria-expanded="true"] .chev { transform: rotate(90deg); }
+/* 展开的一族结束后、下一个组头前空一点 */
+:is(.pop, .picklist) :not(.fam) + .fam { margin-top: var(--space-1); }
diff --git a/ui/design/index.css b/ui/design/index.css
index a438be9..0a63d84 100644
--- a/ui/design/index.css
+++ b/ui/design/index.css
@@ -19,6 +19,7 @@
@import url("components/seg.css") layer(components);
@import url("components/switch.css") layer(components);
@import url("components/popover.css") layer(components);
+@import url("components/model-family.css") layer(components);
@import url("components/sheet.css") layer(components);
@import url("components/toast.css") layer(components);
@import url("components/notice.css") layer(components);
diff --git a/ui/lib/models.js b/ui/lib/models.js
new file mode 100644
index 0000000..66fa681
--- /dev/null
+++ b/ui/lib/models.js
@@ -0,0 +1,66 @@
+// 模型 ID 的显示与分组(不依赖界面,单元测试直接引入)。
+
+/** 内置网关列出的模型带 "modelflare/" 前缀,Modelflare 直接列出的不带;两种写法都能调用,显示与比较时去掉它 */
+export const normModel = (m) => (m && m.startsWith("modelflare/") ? m.slice("modelflare/".length) : m || "");
+export const sameModel = (a, b) => !!a && !!b && normModel(a) === normModel(b);
+export const shortModel = (m) => (m && m.includes("/") ? m.slice(m.lastIndexOf("/") + 1) : m);
+
+// —— 模型族:按名字认(Modelflare 的 ID 不带厂商前缀,如 gpt-6-sol、claude-opus-5-5)。数组顺序就是显示顺序,认不出的归「其他」放最后 ——
+const FAMILIES = [
+ ["GPT", /^(gpt|chatgpt|codex|o\d)/],
+ ["Claude", /^claude/],
+ ["Gemini", /^gemini/],
+ ["Grok", /^grok/],
+ ["DeepSeek", /^deepseek/],
+ ["Qwen", /^(qwen|qwq)/],
+ ["Kimi", /^(kimi|moonshot)/],
+ ["GLM", /^(glm|chatglm)/],
+ ["MiniMax", /^(minimax|abab)/],
+ ["Doubao", /^(doubao|seed)/],
+ ["Llama", /^llama/],
+ ["Mistral", /^(mistral|mixtral|magistral|codestral|devstral|ministral)/],
+];
+export const OTHER_FAMILY = "其他";
+const ORDER = [...FAMILIES.map(([f]) => f), OTHER_FAMILY];
+
+export function modelFamily(id) {
+ const n = (shortModel(normModel(id)) || "").toLowerCase();
+ return FAMILIES.find(([, re]) => re.test(n))?.[0] ?? OTHER_FAMILY;
+}
+
+/** 名字里第一个版本号(5-5、6.1、v4.1、qwen3.8)读成数字数组;4 位以上的数字是日期之类,到此为止 */
+function version(id) {
+ const m = id.match(/\d+(?:[.-]\d+)*/);
+ const out = [];
+ for (const p of m ? m[0].split(/[.-]/) : []) {
+ if (p.length > 3) break;
+ out.push(Number(p));
+ }
+ return out;
+}
+
+/** 族内排序:版本新的在前(6.1 > 6 > 5.6),同版本按名字 */
+function newerFirst(a, b) {
+ const x = version(a);
+ const y = version(b);
+ for (let i = 0; i < Math.max(x.length, y.length); i++) {
+ const d = (y[i] ?? -1) - (x[i] ?? -1);
+ if (d) return d;
+ }
+ return a.localeCompare(b);
+}
+
+/** 按模型族分组并按 q 筛选;返回 [族名, [[原始 id, 显示名]]],族按固定顺序 */
+export function groupModels(models, q = "") {
+ const needle = q.trim().toLowerCase();
+ const groups = new Map();
+ for (const m of models) {
+ const n = normModel(m);
+ if (needle && !n.toLowerCase().includes(needle)) continue;
+ const f = modelFamily(m);
+ if (!groups.has(f)) groups.set(f, []);
+ groups.get(f).push([m, n.includes("/") ? n.slice(n.indexOf("/") + 1) : n]);
+ }
+ for (const ms of groups.values()) ms.sort((a, b) => newerFirst(a[1], b[1]));
+ return [...groups.entries()].sort((a, b) => ORDER.indexOf(a[0]) - ORDER.indexOf(b[0]));
+}
diff --git a/ui/screens/onboarding.js b/ui/screens/onboarding.js
index a315792..73ee74c 100644
--- a/ui/screens/onboarding.js
+++ b/ui/screens/onboarding.js
@@ -4,7 +4,7 @@
import { useEffect, useMemo, useRef, useState } from "preact/hooks";
import { html, Icon, Notice, Seg, Spinner, CopyButton } from "../components/ui.js";
import { BotAvatar, MAIN_CHAR } from "../components/avatar.js";
-import { groupModels } from "../components/model-picker.js";
+import { FamilyHead, groupModels, useFamilies } from "../components/model-picker.js";
import { api } from "../lib/api.js";
import { MF_CONSOLE, MF_DOCS, MF_KEYS } from "../lib/links.js";
@@ -171,6 +171,8 @@ function ModelStep({ models, initial, onDone }) {
const [busy, setBusy] = useState(false);
const [err, setErr] = useState("");
const groups = useMemo(() => groupModels(models, q), [models, q]);
+ const { isOpen, toggle } = useFamilies(groups, cur);
+ const folding = !q.trim() && groups.length > 1;
const start = async () => {
setBusy(true);
try {
@@ -187,10 +189,15 @@ function ModelStep({ models, initial, onDone }) {
? html`<p class="hint">选一个默认模型,之后随时可在对话里切换。</p>
<input class="field" placeholder="筛选模型" value=${q} onInput=${(e) => setQ(e.target.value)} aria-label="筛选模型" />
<div class="picklist" role="listbox" aria-label="默认模型">
- ${groups.map(([g, ms]) => html`${g && html`<div class="group">${g}</div>`}
- ${ms.map(([m, label]) => html`<button type="button" role="option" aria-selected=${m === cur} class=${m === cur ? "cur" : ""} onClick=${() => setCur(m)} onDblClick=${start}>
+ ${groups.map(([g, ms]) => {
+ const rows = ms.map(([m, label]) => html`<button type="button" role="option" aria-selected=${m === cur} class=${m === cur ? "cur" : ""} onClick=${() => setCur(m)} onDblClick=${start}>
<span class="v">${label}</span>${m === cur && html`<span class="check"><${Icon} name="check" size=${14} /></span>`}
- </button>`)}`)}
+ </button>`);
+ if (!folding) return html`${groups.length > 1 && html`<div class="group">${g}</div>`}${rows}`;
+ const open = isOpen(g);
+ const hit = open ? undefined : ms.find(([m]) => m === cur);
+ return html`<button type="button" class="fam" aria-expanded=${open} onClick=${() => toggle(g)}><${FamilyHead} name=${g} count=${ms.length} current=${hit?.[1]} /></button>${open && rows}`;
+ })}
${!groups.length && html`<p class="hint">没有匹配的模型</p>`}
</div>`
: html`<${Notice} tone="amber" action=${html`<a class="btn" href=${MF_CONSOLE} target="_blank" rel="noopener noreferrer">去控制台 ↗</a>`}>这个 Key 所在的分组暂无可用模型。可以在控制台给分组开放模型后再回来刷新。<//>`}