- 工作流节点描述增加服务端托管黑名单,仅代码节点保留自定义 desc - 工作流保存新增 --in-place,并改进版本冲突提示 - platform records 新增 --page 分页,--all 强制走 ndjson 文件流 - platform schema 展示 ownerId/submitterId 等系统字段 - 更新 Agent Skill 的代码节点 agent use 标记规范 - 补充对应测试与文档
174 lines
6.1 KiB
TypeScript
174 lines
6.1 KiB
TypeScript
import { flattenExecutionTree, listAllWorkflows } from "../../../domains/platform/services.js";
|
||
import { stringOption } from "../../parser.js";
|
||
import { createClientsForCorp, createPiperClientForCorp } from "../../helpers.js";
|
||
import type { CliParsedArgs, CliRuntime } from "../../types.js";
|
||
|
||
export const PLATFORM_ID_OPTION_KEYS = ["platform", "platform-id", "platformId", "app", "app-id", "appId"];
|
||
|
||
export function formatWorkflowVersion(workflow: {
|
||
version?: string | null;
|
||
tasksVersion?: number | null;
|
||
updateTime?: string | null;
|
||
}): string {
|
||
const version = workflow.version || "-";
|
||
const tasksVersion = workflow.tasksVersion ?? "-";
|
||
const updateTime = workflow.updateTime ? `,更新时间 ${workflow.updateTime}` : "";
|
||
return `版本 ${version}(tasksVersion ${tasksVersion})${updateTime}`;
|
||
}
|
||
|
||
export async function createWorkflowDetailClient(
|
||
parsed: CliParsedArgs,
|
||
runtime: CliRuntime,
|
||
pipelineId: string,
|
||
): Promise<{
|
||
client: Awaited<ReturnType<typeof createPiperClientForCorp>>;
|
||
clients: Awaited<ReturnType<typeof createClientsForCorp>>;
|
||
platformId?: string;
|
||
}> {
|
||
const clients = await createClientsForCorp(runtime.selectedCorp!);
|
||
const explicit = stringOption(parsed.options, PLATFORM_ID_OPTION_KEYS);
|
||
let platformId = explicit;
|
||
if (!platformId) {
|
||
try {
|
||
const corpId = runtime.selectedCorp!.corpId || runtime.selectedCorp!.id;
|
||
const { listPlatforms } = await import("../../../domains/platform/services.js");
|
||
const platforms = await listPlatforms(clients.ekbClient, corpId);
|
||
const firstActive = platforms.find((p) => p.active) ?? platforms[0];
|
||
platformId = firstActive?.id;
|
||
} catch {
|
||
// Fall back to easoClient
|
||
}
|
||
}
|
||
return {
|
||
client: platformId ? await createPiperClientForCorp(runtime.selectedCorp!, platformId) : clients.easoClient,
|
||
clients,
|
||
platformId,
|
||
};
|
||
}
|
||
|
||
export 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 { listPlatforms } = await import("../../../domains/platform/services.js");
|
||
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;
|
||
}
|
||
|
||
export interface CodeNodeSummary {
|
||
id: string;
|
||
name: string;
|
||
label: string;
|
||
type: string;
|
||
status: string;
|
||
rawOutput: unknown;
|
||
summaryLines: string[];
|
||
}
|
||
|
||
export function extractCodeNodeSummaries(
|
||
nodes: Array<any>,
|
||
flattenExecutionTreeFn?: (nodes: any[]) => any[]
|
||
): CodeNodeSummary[] {
|
||
const flattened = (flattenExecutionTreeFn ?? flattenExecutionTree)(nodes);
|
||
const summaries: CodeNodeSummary[] = [];
|
||
|
||
for (const node of flattened) {
|
||
if (!node) continue;
|
||
const type = String(node.type || "");
|
||
if (type !== "code" && type !== "code-js2") continue;
|
||
|
||
const rawOutput = node.output ?? node.outputs ?? node.details;
|
||
const summaryLines: string[] = [];
|
||
|
||
if (rawOutput === undefined || rawOutput === null) {
|
||
summaryLines.push(" 出参: (无返回值或 null)");
|
||
} else if (Array.isArray(rawOutput)) {
|
||
summaryLines.push(` 出参类型: Array (${rawOutput.length} 项)`);
|
||
if (rawOutput.length > 0) {
|
||
const first = rawOutput[0];
|
||
if (first && typeof first === "object") {
|
||
const keys = ["planCode", "code", "id", "name", "title", "totalAmount", "amount"];
|
||
const matchedKey = keys.find((k) => (first as Record<string, unknown>)[k] !== undefined);
|
||
if (matchedKey) {
|
||
summaryLines.push(` 首项 ${matchedKey}: ${String((first as Record<string, unknown>)[matchedKey])}`);
|
||
}
|
||
if ((first as any).amount !== undefined && matchedKey !== "amount") {
|
||
summaryLines.push(` 首项金额: ${String((first as any).amount)}`);
|
||
}
|
||
} else {
|
||
summaryLines.push(` 首项值: ${String(first)}`);
|
||
}
|
||
}
|
||
} else if (typeof rawOutput === "object") {
|
||
const obj = rawOutput as Record<string, unknown>;
|
||
summaryLines.push(" 出参类型: Object");
|
||
if (Array.isArray(obj.items)) {
|
||
summaryLines.push(` items.length: ${obj.items.length}`);
|
||
}
|
||
for (const k of ["planCode", "totalAmount", "count", "code", "total", "amount", "success"]) {
|
||
if (obj[k] !== undefined) {
|
||
summaryLines.push(` ${k}: ${String(obj[k])}`);
|
||
}
|
||
}
|
||
const allKeys = Object.keys(obj);
|
||
if (summaryLines.length === 1 && allKeys.length > 0) {
|
||
summaryLines.push(` 字段列表 (${allKeys.length} 个): ${allKeys.slice(0, 5).join(", ")}${allKeys.length > 5 ? "..." : ""}`);
|
||
}
|
||
} else {
|
||
summaryLines.push(` 出参值: ${String(rawOutput)}`);
|
||
}
|
||
|
||
summaries.push({
|
||
id: node.id || "-",
|
||
name: node.name || "-",
|
||
label: node.label || node.displayName || (type === "code" ? "MVEL代码节点" : "JS代码节点"),
|
||
type,
|
||
status: node.status || "UNKNOWN",
|
||
rawOutput,
|
||
summaryLines,
|
||
});
|
||
}
|
||
|
||
return summaries;
|
||
}
|
||
|
||
export function formatCodeNodeSummariesCard(
|
||
summaries: CodeNodeSummary[],
|
||
jobId?: string
|
||
): string[] {
|
||
if (summaries.length === 0) return [];
|
||
|
||
const lines: string[] = [
|
||
"",
|
||
"── 🧮 核心代码节点出参即时摘要 (Code Return Values) ──",
|
||
];
|
||
|
||
for (const s of summaries) {
|
||
const statusIcon = s.status === "COMPLETED" || s.status === "SUCCESS" ? "✅" : s.status === "FAILED" ? "❌" : "⏳";
|
||
lines.push(` ${statusIcon} [${s.name}] ${s.label} (${s.type}, 状态: ${s.status})`);
|
||
for (const l of s.summaryLines) {
|
||
lines.push(` ${l}`);
|
||
}
|
||
if (jobId) {
|
||
lines.push(` ↳ 完整出参查看: hose-use workflow job ${jobId} --node=${s.name} --full`);
|
||
}
|
||
}
|
||
|
||
return lines;
|
||
}
|