fix(*): 模型选择 - 修复系统渠道 Logo 搜索与前台模型模式误判
This commit is contained in:
@@ -10,7 +10,7 @@ type LobeIconComponent = ComponentType<SVGProps<SVGSVGElement> & { size?: number
|
||||
|
||||
// 只允许按需加载 Mono 组件。这里不能使用 eager glob:模型 Logo 目录有数百个 provider 模块,
|
||||
// eager 会让每次进入工作区都发起数百个开发模块请求,即使用户从未打开 Logo 选择器。
|
||||
const iconModules = import.meta.glob?.("../../node_modules/@lobehub/icons/es/*/components/Mono.js", { import: "default" }) || {};
|
||||
const iconModules = import.meta.glob("../../node_modules/@lobehub/icons/es/*/components/Mono.js", { import: "default" });
|
||||
const iconLoaders = Object.fromEntries(
|
||||
Object.entries(iconModules)
|
||||
.map(([path, loader]) => [path.match(/\/([^/]+)\/components\/Mono\.js$/)?.[1], loader])
|
||||
@@ -19,7 +19,7 @@ const iconLoaders = Object.fromEntries(
|
||||
const iconRegistry = new Map<string, LobeIconComponent>();
|
||||
const iconLoadPromises = new Map<string, Promise<LobeIconComponent | undefined>>();
|
||||
const iconOptions = toc
|
||||
.filter((item) => item.group === "model" || item.group === "provider")
|
||||
.filter((item) => item.group === "model" || item.group === "provider" || item.group === "application")
|
||||
.map((item) => ({ id: item.id, title: item.fullTitle || item.title }))
|
||||
.filter((item) => Boolean(iconLoaders[item.id]));
|
||||
|
||||
|
||||
19
web/test/model-logo.test.ts
Normal file
19
web/test/model-logo.test.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
|
||||
describe("模型 Logo 选择器", () => {
|
||||
test("使用 Vite 可识别的直接 glob 并包含前台模型 Logo 数据源", () => {
|
||||
const source = readFileSync(resolve(import.meta.dir, "../src/components/model-logo.tsx"), "utf8");
|
||||
const toc = JSON.parse(readFileSync(resolve(import.meta.dir, "../node_modules/@lobehub/icons/es/toc.json"), "utf8")) as Array<{ group: string; id: string }>;
|
||||
const options = toc.filter((item) => item.group === "model" || item.group === "provider" || item.group === "application");
|
||||
|
||||
expect(source).toContain('import.meta.glob("../../node_modules/@lobehub/icons/es/*/components/Mono.js"');
|
||||
expect(source).not.toContain("import.meta.glob?.(");
|
||||
expect(options.length).toBeGreaterThan(300);
|
||||
expect(options.some((item) => item.id === "OpenAI")).toBe(true);
|
||||
expect(options.some((item) => item.id === "AgnesAI")).toBe(true);
|
||||
expect(existsSync(resolve(import.meta.dir, "../node_modules/@lobehub/icons/es/OpenAI/components/Mono.js"))).toBe(true);
|
||||
expect(existsSync(resolve(import.meta.dir, "../node_modules/@lobehub/icons/es/AgnesAI/components/Mono.js"))).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user