import type { SearchAction } from "@umt/contracts"; // 页面与操作跳转(命令面板静态清单),按 IA-2 导航:概览 / 获取 / 整理 / 系统(任务归系统;RSS 在站点详情里)。 // href 是控制台内路径;action 类带查询参数,由前端页面识别后打开对应表单。 const page = (id: string, group: string, title: string, href: string, keywords: string[] = []): SearchAction => ({ id: `page.${id}`, kind: "page", group, title, href, keywords, }); const action = (id: string, group: string, title: string, href: string, keywords: string[] = []): SearchAction => ({ id: `action.${id}`, kind: "action", group, title, href, keywords, }); export const SEARCH_ACTIONS: readonly SearchAction[] = [ page("home", "概览", "首页", "/console", ["home", "dashboard", "概览"]), page("agent", "概览", "智能体会话", "/console/agent", ["agent", "会话"]), page("schedules", "概览", "计划", "/console/schedules", ["schedule", "cron", "巡检", "计划", "定时任务"]), page("sites", "获取", "站点", "/console/sites", ["site", "pt", "站点账号", "rss", "feed", "bt"]), page("subscriptions", "获取", "订阅", "/console/subscriptions", ["subscription", "追剧"]), page("rules", "获取", "规则", "/console/rules", ["rules", "收录策略", "policy"]), page("downloads", "整理", "下载面板", "/console/downloads", ["download", "qb", "下载任务"]), page("organize", "整理", "整理记录", "/console/organize", ["organize", "入库", "历史"]), page("organize-attention", "整理", "需要处理的整理记录", "/console/organize?tab=records&attention=1", [ "inbox", "待处理", "识别不到", "decision", ]), page("files", "整理", "文件管理", "/console/files", ["files", "文件"]), page("trash", "整理", "回收站", "/console/files/trash", ["trash", "删除"]), page("library", "整理", "媒体库", "/console/library", ["library", "媒体库", "作品"]), page("tasks", "系统", "任务", "/console/tasks", ["task", "运行", "历史"]), page("settings", "系统", "设置", "/console/settings", ["settings", "配置", "tmdb", "下载器"]), page("audit", "系统", "审计", "/console/audit", ["audit", "日志"]), page("preferences", "系统", "偏好", "/console/preferences", ["preferences", "主题"]), action("new-subscription", "获取", "新建订阅", "/console/subscriptions?new=1", ["subscribe", "订阅"]), action("new-agent-run", "概览", "新建智能体会话", "/console/agent?new=1", ["agent", "委托"]), action("add-site", "获取", "添加站点", "/console/sites?new=1", ["site", "站点", "rss", "feed", "bt"]), // RSS 属于站点(IA-2):添加 RSS 源 = 添加「自定义 RSS 源」类型的站点 action("add-feed", "获取", "添加自定义 RSS 源", "/console/sites?new=rss_feed", ["rss", "feed"]), action("new-schedule", "概览", "新建巡检", "/console/schedules?new=1", ["巡检", "agent_check"]), ]; /** 标题 / 关键词 / 路径包含查询词(不区分大小写);标题前缀命中排前 */ export function matchActions(q: string, limit: number): SearchAction[] { const needle = q.trim().toLowerCase(); if (!needle) return []; const scored: { a: SearchAction; score: number }[] = []; for (const a of SEARCH_ACTIONS) { const title = a.title.toLowerCase(); let score = 0; if (title.startsWith(needle)) score = 3; else if (title.includes(needle)) score = 2; else if (a.keywords.some((k) => k.toLowerCase().includes(needle)) || a.href.toLowerCase().includes(needle)) score = 1; if (score) scored.push({ a, score }); } return scored .sort((x, y) => y.score - x.score) .slice(0, limit) .map((x) => x.a); }