首页:顶部一行状态(自动化开关 + 只在异常时出现的服务 / 下载盘 / 站点账号 / 下载器问题), 下面只有「在忙什么」「要我处理」「最近入库」三块;去掉运行状态、计划、缓存、来源健康、 满足率与 0 值铺陈;0 订阅时写「还没有订阅。去搜索添加」。只读对账移出首页,设置里放进 自动化 →「高级」(与存储预算、流水保留、缓存有效期一起默认收起)。 计划页:「智能体巡检」移到最上面——巡检数量少、由用户自己建、每次会花钱,是这页最需要 看的;自动任务任务多、多数不用管,放在下面。自动任务按分类分组、每组可折叠:有失败或 运行中的组默认展开,其余收起为「N 个任务 · 下次 xx」一行,折叠状态记在 localStorage; 维护类整组叫「数据清理」,未接入调度的备份不列。巡检卡只留名称、开关、间隔、上次结果与 费用,目标 / 能力 / 预算 / 模型 / 最近会话收进「详情」。去掉顶部 6 个计数卡。定时任务说明 去掉表名、字段名与实现备注。 任务页:默认隐藏系统任务(无业务对象的引擎步骤、定时任务的成功运行),可一键显示; 标题不再用 ID;耗时移入技术信息;< 1 秒写「< 1 秒」;费用两位小数,不足一分写「< $0.01」。 下载盘相关文案改用「暂停线 / 恢复线」。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
135 lines
5.2 KiB
TypeScript
135 lines
5.2 KiB
TypeScript
import type { EngineBusinessKind, EngineRun, EngineTriggeredBy } from "@umt/contracts";
|
|
import { consolePath } from "~/components/console/nav.ts";
|
|
import type { StatusTone } from "~/components/console/status-badge.tsx";
|
|
|
|
// 统一任务流的标签:引擎 run + business(W9-I)。一条 run = 一条任务。
|
|
|
|
export const BUSINESS_KIND_LABEL: Record<EngineBusinessKind, string> = {
|
|
subscription: "订阅",
|
|
download: "下载",
|
|
organization: "整理",
|
|
agent: "智能体",
|
|
schedule: "定时任务",
|
|
feed: "RSS",
|
|
site: "站点",
|
|
decision: "待处理事项",
|
|
media: "作品",
|
|
};
|
|
export const BUSINESS_KINDS = Object.keys(BUSINESS_KIND_LABEL) as EngineBusinessKind[];
|
|
|
|
/** 来源:四类(定时/事件/手动/Agent);API Key 调用算手动 */
|
|
export type TaskSource = "schedule" | "event" | "manual" | "agent";
|
|
export const SOURCE_LABEL: Record<TaskSource, string> = {
|
|
schedule: "定时",
|
|
event: "事件",
|
|
manual: "手动",
|
|
agent: "智能体",
|
|
};
|
|
/** 来源 → 服务端 triggeredBy 筛选值(逗号分隔多值) */
|
|
export const SOURCE_TRIGGERED_BY: Record<TaskSource, string> = {
|
|
schedule: "schedule",
|
|
event: "event",
|
|
manual: "user,api_key",
|
|
agent: "agent",
|
|
};
|
|
export function sourceOf(t: EngineTriggeredBy | null | undefined): TaskSource | null {
|
|
if (!t) return null;
|
|
if (t === "user" || t === "api_key") return "manual";
|
|
return t;
|
|
}
|
|
|
|
/** 引擎工作流名 → 做什么 */
|
|
export const WORKFLOW_LABEL: Record<string, string> = {
|
|
ingestFeed: "抓取 Feed",
|
|
resolveObservation: "识别资源",
|
|
evaluateAcquisition: "评估候选",
|
|
submitDownload: "提交下载",
|
|
verifyAndImport: "核验入库",
|
|
refreshMetadata: "刷新元数据",
|
|
reconcileLibrary: "文件核对",
|
|
cleanupDownloadCache: "清理缓存",
|
|
resolveDecision: "处理待处理事项",
|
|
runAgent: "智能体会话",
|
|
snapshotSite: "站点抓取",
|
|
refreshSiteAccount: "刷新站点账号",
|
|
searchSubscription: "订阅搜索",
|
|
purgeTrash: "清理回收站",
|
|
refreshPiTokens: "刷新模型服务登录",
|
|
};
|
|
export const workflowLabel = (name: string) => WORKFLOW_LABEL[name] ?? name;
|
|
|
|
/** 引擎状态 → 任务状态 */
|
|
const RUN_STATUS: Record<string, { label: string; tone: StatusTone }> = {
|
|
pending: { label: "排队", tone: "neutral" },
|
|
running: { label: "进行中", tone: "neutral" },
|
|
sleeping: { label: "等待", tone: "neutral" },
|
|
completed: { label: "完成", tone: "success" },
|
|
succeeded: { label: "完成", tone: "success" },
|
|
failed: { label: "失败", tone: "destructive" },
|
|
canceled: { label: "已取消", tone: "warning" },
|
|
};
|
|
export const runStatus = (s: string) => RUN_STATUS[s] ?? { label: s, tone: "neutral" as StatusTone };
|
|
/**
|
|
* 任务行状态:引擎 run 正常结束但业务结果不是成功时以业务结果为准(Agent 会话超出预算 / 失败 / 已停止),
|
|
* 不把"引擎跑完"显示成「完成」
|
|
*/
|
|
const OUTCOME_STATUS: Record<string, { label: string; tone: StatusTone }> = {
|
|
budget_exceeded: { label: "超出预算", tone: "warning" },
|
|
failed: { label: "失败", tone: "destructive" },
|
|
cancelled: { label: "已停止", tone: "warning" },
|
|
waiting: { label: "等待", tone: "neutral" },
|
|
};
|
|
export function engineRunStatus(r: Pick<EngineRun, "status" | "business">) {
|
|
const outcome = r.business?.outcome;
|
|
if (outcome && (r.status === "completed" || r.status === "succeeded") && OUTCOME_STATUS[outcome])
|
|
return OUTCOME_STATUS[outcome];
|
|
return runStatus(r.status);
|
|
}
|
|
export const RUN_STATUS_OPTIONS = ["pending", "running", "completed", "failed", "canceled"].map((value) => ({
|
|
value,
|
|
label: runStatus(value).label,
|
|
}));
|
|
|
|
/** 行标题:业务对象名 > 业务类型 + 短 id > 工作流做什么 */
|
|
export function runTitle(r: Pick<EngineRun, "business" | "workflowName">): string {
|
|
const b = r.business;
|
|
if (b?.title) return b.title;
|
|
if (b) return BUSINESS_KIND_LABEL[b.kind];
|
|
return workflowLabel(r.workflowName);
|
|
}
|
|
|
|
/** 业务对象的"家"页面 */
|
|
export function businessLink(b: EngineRun["business"], input?: unknown): { to: string; label: string } | null {
|
|
if (!b) return null;
|
|
const id = encodeURIComponent(b.refId);
|
|
switch (b.kind) {
|
|
case "subscription":
|
|
return { to: consolePath("subscriptions"), label: "订阅" };
|
|
case "download": {
|
|
// 计划还没提交时 refId 是下载计划
|
|
const i = (input ?? {}) as { downloadTaskId?: unknown; acquisitionPlanId?: unknown };
|
|
if (!i.downloadTaskId && i.acquisitionPlanId === b.refId)
|
|
return { to: consolePath("downloads", "plans"), label: "下载计划" };
|
|
return { to: `/console/downloads/${id}`, label: "下载任务" };
|
|
}
|
|
case "organization":
|
|
return { to: `/console/organize/${id}`, label: "整理记录" };
|
|
case "agent":
|
|
return { to: `/console/agent/${id}`, label: "智能体会话" };
|
|
case "schedule":
|
|
return { to: `/console/schedules?job=${id}`, label: "定时任务" };
|
|
case "feed":
|
|
return { to: consolePath("sources"), label: "RSS" };
|
|
case "site":
|
|
return { to: `/console/sites/${id}`, label: "站点" };
|
|
case "decision":
|
|
return { to: consolePath("inbox"), label: "待处理" };
|
|
case "media":
|
|
return { to: `/console/library/${id}`, label: "作品" };
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export const ENGINE_ACTIVE = new Set(["pending", "running", "sleeping"]);
|