建立 applications 的应用模型和查询出口,保留基础及详情投影差异。 下沉 DataLink,将工作流模型、API、编排及执行上下文归回 workflow。 同步 CLI、SDK、生成脚本、测试和活跃文档引用,公开命令与 SDK 名称保持兼容。 验证:943 项测试、类型和版本检查通过;三份生成规范字节一致,README 审计通过。
48 lines
1.8 KiB
TypeScript
48 lines
1.8 KiB
TypeScript
import type { WorkflowJobDetail, WorkflowTaskExecution } from "../types.js";
|
|
|
|
export const TERMINAL_STATES = new Set(["COMPLETED", "FAILED", "STOP", "STOPPED", "CANCELLED", "CANCELED"]);
|
|
|
|
export function normalizeJobStatus(job?: Partial<WorkflowJobDetail> | Record<string, unknown> | null): string {
|
|
if (!job) return "UNKNOWN";
|
|
const rawStatus = (job as any).status;
|
|
const rawState = (job as any).state;
|
|
if (typeof rawStatus === "string" && rawStatus.trim()) {
|
|
const s = rawStatus.trim().toUpperCase();
|
|
if (s === "STARTED") return "RUNNING";
|
|
return s;
|
|
}
|
|
if (rawState === 1 || rawState === "1") return "RUNNING";
|
|
if (rawState === 2 || rawState === "2") return "FAILED";
|
|
if (rawState === 0 || rawState === "0") return "COMPLETED";
|
|
if (rawState !== undefined && rawState !== null) return String(rawState).toUpperCase();
|
|
return "UNKNOWN";
|
|
}
|
|
|
|
export function isJobTerminal(status: string): boolean {
|
|
return TERMINAL_STATES.has(status.toUpperCase());
|
|
}
|
|
|
|
/**
|
|
* 提取节点执行失败或跳过时的具体错误原因
|
|
*/
|
|
export function extractTaskErrorMessage(node: WorkflowTaskExecution): string | undefined {
|
|
if (!node) return undefined;
|
|
const anyNode = node as any;
|
|
if (node.error?.message && String(node.error.message).trim()) {
|
|
return String(node.error.message).trim();
|
|
}
|
|
if (anyNode.errorMessage && String(anyNode.errorMessage).trim()) {
|
|
return String(anyNode.errorMessage).trim();
|
|
}
|
|
const outputs = anyNode.outputs ?? anyNode.output;
|
|
if (outputs && typeof outputs === "object") {
|
|
if (outputs.error) {
|
|
return typeof outputs.error === "string" ? outputs.error.trim() : JSON.stringify(outputs.error);
|
|
}
|
|
if (outputs.message && typeof outputs.message === "string") {
|
|
return outputs.message.trim();
|
|
}
|
|
}
|
|
return undefined;
|
|
}
|