feat(shared): add Section concept and toolSection() partition

This commit is contained in:
SnapOtter
2026-06-20 10:55:56 +08:00
parent 0acc8ca751
commit 790747188a
3 changed files with 81 additions and 0 deletions
+1
View File
@@ -7,4 +7,5 @@ export * from "./features.js";
export * from "./i18n/index.js";
export * from "./modality.js";
export * from "./permissions.js";
export * from "./section.js";
export * from "./types.js";
+43
View File
@@ -0,0 +1,43 @@
import { MODALITIES, type Modality } from "./modality.js";
import type { Tool } from "./types.js";
export type Section = "image" | "video" | "audio" | "pdf" | "files";
export interface SectionInfo {
id: Section;
name: string;
icon: string;
color: string;
order: number;
}
// Reuse the existing modality visuals so icon/color have one source of truth.
function visualOf(modality: Modality): { icon: string; color: string } {
const m = MODALITIES.find((x) => x.id === modality);
return { icon: m?.icon ?? "File", color: m?.color ?? "#6B7280" };
}
export const SECTIONS: SectionInfo[] = [
{ id: "image", name: "Image", order: 0, ...visualOf("image") },
{ id: "video", name: "Video", order: 1, ...visualOf("video") },
{ id: "audio", name: "Audio", order: 2, ...visualOf("audio") },
{ id: "pdf", name: "PDF", order: 3, ...visualOf("document") },
{ id: "files", name: "Files", order: 4, ...visualOf("file") },
];
// A tool's presentation section. The backend Modality enum is unchanged;
// the "document" modality splits by whether the tool ingests PDFs.
export function toolSection(tool: Pick<Tool, "modality" | "acceptedInputs">): Section {
switch (tool.modality) {
case "image":
return "image";
case "video":
return "video";
case "audio":
return "audio";
case "file":
return "files";
case "document":
return tool.acceptedInputs.includes(".pdf") ? "pdf" : "files";
}
}