// 技能库纯逻辑:按 scope 分组、档位文案。 // 对齐 C3 扩(GET /skills,只读注册表视图)。纯逻辑,便于 node 环境单测。 import type { SkillView } from "@/lib/api/types"; export type SkillScope = "builtin" | "custom" | "community"; export const SCOPE_LABELS: Record = { builtin: "内置", custom: "自定义", community: "社区", }; export const TIER_LABELS: Record = { writer: "写手", analyst: "分析", light: "轻量", }; export function scopeLabel(scope: string): string { return SCOPE_LABELS[scope] ?? scope; } export function tierLabel(tier: string): string { return TIER_LABELS[tier] ?? tier; } export type SkillGroups = { scope: string; skills: SkillView[] }[]; // 按 scope 分组(保持服务端 name 升序);scope 顺序按首次出现。 export function groupByScope( skills: readonly SkillView[] | undefined, ): SkillGroups { const order: string[] = []; const map = new Map(); for (const skill of skills ?? []) { if (!map.has(skill.scope)) { order.push(skill.scope); map.set(skill.scope, []); } map.get(skill.scope)?.push(skill); } return order.map((scope) => ({ scope, skills: map.get(scope) ?? [] })); }