refactor: 拆分工作流命令和循环诊断职责

拆出节点目录与执行上下文补全,复用客户端选择逻辑并整理循环规则。
This commit is contained in:
gitea committed 2026-10-30 17:40:04 +08:00
1 parent 7af7e7db35
commit e185c84b4e
11 files changed
+383 -372

No files matched your search

+2 -86
View File
@@ -1,94 +1,10 @@
import { extractFailureExecutions, findExecutionNode, flattenExecutionTree, getExecutionLogs, getJob, getJobExecutionLevel, getJobExecutionTree, getJobFailedExecutions, getWorkflowDetail, isTaskExecutionFailed, explainConditionBranches } from "../../../domains/platform/workflow/services.js";
import { listBasicPlatforms as listPlatforms } from "../../../domains/platform/applications/services.js";
import type { WorkflowTaskExecution } from "../../../domains/platform/workflow/types.js";
import { stringOption, numberOption, booleanOption } from "../../parser.js";
import { createClientsForCorp, createPiperClientForCorp } from "../../helpers.js";
import { printJson, printTable, printKeyValue } from "../../printer.js";
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
import { PLATFORM_ID_OPTION_KEYS, extractCodeNodeSummaries, formatCodeNodeSummariesCard } from "./shared.js";
async function createJobPiperClient(
parsed: CliParsedArgs,
runtime: CliRuntime
): Promise<Awaited<ReturnType<typeof createPiperClientForCorp>>> {
const corp = runtime.selectedCorp!;
const explicit = stringOption(parsed.options, PLATFORM_ID_OPTION_KEYS);
if (explicit) {
return createPiperClientForCorp(corp, explicit);
}
const clients = await createClientsForCorp(corp);
try {
const corpId = corp.corpId || corp.id;
const platforms = await listPlatforms(clients.ekbClient, corpId);
const firstActive = platforms.find((p) => p.active) ?? platforms[0];
if (firstActive?.id) {
return await createPiperClientForCorp(corp, firstActive.id);
}
} catch {
// Fall back to default easoClient
}
return clients.easoClient;
}
async function enrichFailedExecutions(
client: Awaited<ReturnType<typeof createPiperClientForCorp>>,
jobId: string,
items: WorkflowTaskExecution[]
): Promise<WorkflowTaskExecution[]> {
const parentCache = new Map<string, WorkflowTaskExecution[]>();
const enriched: WorkflowTaskExecution[] = [];
for (const item of items) {
if (item.parentId && (!item.currentLoopPath || !item.name || !item.form)) {
let siblings = parentCache.get(item.parentId);
if (!siblings) {
try {
const level = await getJobExecutionLevel(client, jobId, {
parentId: item.parentId,
page: 1,
pageSize: 100,
});
siblings = level.items;
} catch {
siblings = [];
}
parentCache.set(item.parentId, siblings);
}
const matched = siblings.find((s) => s.id === item.id);
if (matched) {
const itemInputs = item.inputs;
const matchedInputs = matched.inputs;
const hasItemInputs = Array.isArray(itemInputs)
? itemInputs.length > 0
: Boolean(itemInputs && typeof itemInputs === "object" && Object.keys(itemInputs as Record<string, unknown>).length > 0);
const itemOutputs = item.outputs;
const matchedOutputs = matched.outputs;
const hasItemOutputs = Boolean(
itemOutputs && typeof itemOutputs === "object" && Object.keys(itemOutputs as Record<string, unknown>).length > 0
);
enriched.push({
...matched,
...item,
name: item.name || matched.name,
label: item.label || matched.label,
displayName: item.displayName || matched.displayName,
type: item.type || matched.type,
status: item.status || matched.status,
currentLoopPath: item.currentLoopPath || matched.currentLoopPath,
levelIndex: item.levelIndex?.length ? item.levelIndex : matched.levelIndex,
form: item.form ?? matched.form,
details: item.details ?? matched.details,
inputs: hasItemInputs ? itemInputs : matchedInputs,
outputs: hasItemOutputs ? itemOutputs : matchedOutputs,
error: item.error ?? matched.error,
});
continue;
}
}
enriched.push(item);
}
return enriched;
}
import { createJobPiperClient, extractCodeNodeSummaries, formatCodeNodeSummariesCard } from "./shared.js";
import { enrichFailedExecutions } from "./job-execution.js";
export async function handleJob(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
const jobId = parsed.args[0] || stringOption(parsed.options, ["id", "job-id", "jobId"]);