feat(workflow): 企业可用节点探针、灰度开通收敛与DataLink公式硬规则校验
This commit is contained in:
1 parent
4f0eea5725
commit
0768b94d65
14 files changed
+974
-22
No files matched your search
@@ -6,20 +6,50 @@ import {
|
||||
addWorkflowTask,
|
||||
editWorkflowTask,
|
||||
removeWorkflowTask,
|
||||
getWorkflowAvailableNodes,
|
||||
grantWorkflowNodes,
|
||||
} from "../../../domains/platform/services.js";
|
||||
import {
|
||||
GRAY_NODES_CATALOG,
|
||||
findGrayNode,
|
||||
} from "../../../domains/platform/workflow/nodes/gray-nodes-catalog.js";
|
||||
import { stringOption } from "../../parser.js";
|
||||
import { printJson, printTable, printKeyValue } from "../../printer.js";
|
||||
import { isDryRun, mutationPreview, requireMutationConfirmation } from "../../mutation.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
||||
import { createPiperClientForCorp } from "../../helpers.js";
|
||||
import { createWorkflowDetailClient } from "./shared.js";
|
||||
|
||||
const SUB_ACTIONS = new Set(["list", "ls", "get", "show", "info", "add", "append", "insert", "edit", "update", "set", "rm", "remove", "delete", "del"]);
|
||||
const CORP_LEVEL_ACTIONS = new Set(["available", "list-available", "catalog", "probe", "grant", "open"]);
|
||||
|
||||
export async function handleNodeCommand(
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime
|
||||
): Promise<CliResult> {
|
||||
const isPluralNodes = parsed.action === "nodes";
|
||||
const firstArg = parsed.args[0]?.toLowerCase();
|
||||
|
||||
// 1. 企业级节点字典与灰度开通快捷分支
|
||||
if (firstArg === "grant" || firstArg === "open") {
|
||||
return handleGrantNodes(parsed, runtime);
|
||||
}
|
||||
if (
|
||||
firstArg === "available" ||
|
||||
firstArg === "list-available" ||
|
||||
firstArg === "catalog" ||
|
||||
firstArg === "probe"
|
||||
) {
|
||||
return handleListAvailableNodes(parsed, runtime);
|
||||
}
|
||||
|
||||
// 2. 如果是 `hose-use workflow nodes`(复数)且没有指定具体的 pipelineId
|
||||
const secondArg = parsed.args[1];
|
||||
const isSecondArgPipelineId = secondArg && /^\d{10,}$/.test(secondArg.trim());
|
||||
if (isPluralNodes && (!firstArg || ((firstArg === "list" || firstArg === "ls") && !isSecondArgPipelineId && !parsed.options.id && !parsed.options.pipelineId))) {
|
||||
return handleListAvailableNodes(parsed, runtime);
|
||||
}
|
||||
|
||||
let subAction = "list";
|
||||
let pipelineId = "";
|
||||
let nodeTarget = "";
|
||||
@@ -43,19 +73,22 @@ export async function handleNodeCommand(
|
||||
stderr: [
|
||||
"用法: hose-use workflow node <子命令> <pipelineId> [选项]",
|
||||
"",
|
||||
"子命令:",
|
||||
"子命令 (工作流级别):",
|
||||
" list <pipelineId> 列出工作流所有任务节点 (别名: ls, 默认)",
|
||||
" get <pipelineId> <节点标识> 查看指定节点的完整配置 (别名: show, info)",
|
||||
" add <pipelineId> [选项] 声明式追加或插入新任务节点 (别名: append, insert)",
|
||||
" edit <pipelineId> <节点标识> 定向修改指定节点配置 (别名: update, set)",
|
||||
" rm <pipelineId> <节点标识> 安全移除指定任务节点 (别名: remove, delete)",
|
||||
"",
|
||||
"子命令 (企业灰度节点级别):",
|
||||
" nodes [list] [--all] 列出当前企业已开通的节点字典 (别名: probe, catalog)",
|
||||
" nodes grant <type...> 为当前企业开通灰度节点",
|
||||
"",
|
||||
"示例:",
|
||||
" hose-use workflow nodes",
|
||||
" hose-use workflow nodes --all",
|
||||
" hose-use workflow nodes grant code-js2",
|
||||
" hose-use workflow node list 896398895352487950",
|
||||
" hose-use workflow node get 896398895352487950 action_dx9cci",
|
||||
" hose-use workflow node add 896398895352487950 --type=code-js2 --label='数据清洗' --code='return items;' --yes",
|
||||
" hose-use workflow node edit 896398895352487950 action_dx9cci --label='新清洗逻辑' --yes",
|
||||
" hose-use workflow node rm 896398895352487950 action_dx9cci --yes",
|
||||
].join("\n") + "\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
@@ -426,3 +459,164 @@ async function handleRemoveNode(
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// ── 企业可用节点字典与灰度开通 ──────────────────────────────────────────────
|
||||
|
||||
async function handleListAvailableNodes(
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime
|
||||
): Promise<CliResult> {
|
||||
const corp = runtime.selectedCorp!;
|
||||
const platformId = stringOption(parsed.options, ["platform-id", "platformId", "app-id", "appId"]) || corp.id;
|
||||
const piperClient = await createPiperClientForCorp(corp, platformId);
|
||||
const available = await getWorkflowAvailableNodes(piperClient);
|
||||
|
||||
const showAll = Boolean(parsed.options.all || parsed.options.compare || parsed.options.diff);
|
||||
const filterKw = (
|
||||
parsed.args[1] ||
|
||||
stringOption(parsed.options, ["keyword", "query", "filter"]) ||
|
||||
""
|
||||
).toLowerCase();
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
const output = {
|
||||
corpId: corp.corpId || corp.id,
|
||||
corpName: corp.name,
|
||||
totalGranted: available.allTypes.size,
|
||||
actionNodesCount: available.actionNodes.length,
|
||||
controlNodesCount: available.controlNodes.length,
|
||||
triggerNodesCount: available.triggerNodes.length,
|
||||
grantedTypes: Array.from(available.allTypes).sort(),
|
||||
catalog: {
|
||||
action: available.actionNodes.map((n) => ({ name: n.name, type: n.type })),
|
||||
control: available.controlNodes.map((n) => ({ name: n.name, type: n.type })),
|
||||
trigger: available.triggerNodes.map((n) => ({ name: n.name, type: n.type })),
|
||||
},
|
||||
};
|
||||
return {
|
||||
stdout: printJson(output, runtime.outputOptions),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// 渲染人类友好视图
|
||||
if (showAll) {
|
||||
// 对照全量 108 个灰度节点
|
||||
const rows = GRAY_NODES_CATALOG.filter((item) => {
|
||||
if (!filterKw) return true;
|
||||
return (
|
||||
item.displayName.toLowerCase().includes(filterKw) ||
|
||||
item.type.toLowerCase().includes(filterKw)
|
||||
);
|
||||
}).map((item) => {
|
||||
const isGranted = available.allTypes.has(item.type.toLowerCase());
|
||||
const statusText = isGranted ? "✅ 已开通" : "🔒 未开通";
|
||||
return [item.displayName, item.type, item.category || "action", statusText];
|
||||
});
|
||||
|
||||
const output = [
|
||||
`====== 工作流节点字典与灰度开通对照 [${corp.name}] ======`,
|
||||
printKeyValue({
|
||||
"当前企业": `${corp.name} (${corp.corpId || corp.id})`,
|
||||
"已开通节点总数": `${available.allTypes.size} 个`,
|
||||
"灰度对照清单": `${GRAY_NODES_CATALOG.length} 个`,
|
||||
}),
|
||||
"",
|
||||
printTable(["显示名称", "节点类型 (type)", "分组", "开通状态"], rows),
|
||||
"",
|
||||
"提示:",
|
||||
" - 使用 hose-use workflow nodes grant <type> 开通灰度节点 (如: hose-use workflow nodes grant code-js2)",
|
||||
].join("\n");
|
||||
|
||||
return { stdout: output, stderr: "", exitCode: 0 };
|
||||
}
|
||||
|
||||
// 简要分组视图
|
||||
const actionList = available.actionNodes.map((n) => `${n.name} (${n.type})`).join("、");
|
||||
const controlList = available.controlNodes.map((n) => `${n.name} (${n.type})`).join("、");
|
||||
const triggerList = available.triggerNodes.map((n) => `${n.name} (${n.type})`).join("、");
|
||||
|
||||
const output = [
|
||||
`====== 当前企业已开通工作流节点字典 [${corp.name}] ======`,
|
||||
printKeyValue({
|
||||
"当前企业": `${corp.name} (${corp.corpId || corp.id})`,
|
||||
"已开通节点数": `${available.allTypes.size} 个 (动作 ${available.actionNodes.length}, 控制 ${available.controlNodes.length}, 触发 ${available.triggerNodes.length})`,
|
||||
}),
|
||||
"",
|
||||
`⚡ 触发器节点 (${available.triggerNodes.length}):`,
|
||||
triggerList || "无",
|
||||
"",
|
||||
`⚙️ 动作节点 (${available.actionNodes.length}):`,
|
||||
actionList || "无",
|
||||
"",
|
||||
`🔀 控制流程节点 (${available.controlNodes.length}):`,
|
||||
controlList || "无",
|
||||
"",
|
||||
"提示:",
|
||||
" - 添加 --all 参数可查看与官方 108 个灰度节点清单的完整开通对照表",
|
||||
" - 使用 hose-use workflow nodes grant <type...> 开通新灰度节点 (如: hose-use workflow nodes grant code-js2)",
|
||||
].join("\n");
|
||||
|
||||
return { stdout: output, stderr: "", exitCode: 0 };
|
||||
}
|
||||
|
||||
async function handleGrantNodes(
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime
|
||||
): Promise<CliResult> {
|
||||
const corp = runtime.selectedCorp!;
|
||||
const rawNodes = parsed.args.slice(1);
|
||||
const optionNodes = stringOption(parsed.options, ["nodes", "node", "type", "types"]);
|
||||
const targetNodes: string[] = [];
|
||||
|
||||
if (optionNodes) {
|
||||
targetNodes.push(...optionNodes.split(/[,,\s]+/).map((s) => s.trim()).filter(Boolean));
|
||||
}
|
||||
for (const arg of rawNodes) {
|
||||
if (arg && !arg.startsWith("-")) {
|
||||
targetNodes.push(...arg.split(/[,,\s]+/).map((s) => s.trim()).filter(Boolean));
|
||||
}
|
||||
}
|
||||
|
||||
if (targetNodes.length === 0) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "错误: 请指定要开通的节点类型 (如: hose-use workflow nodes grant code-js2 或 dify)\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
const password = stringOption(parsed.options, ["password", "pwd", "admin-key"]);
|
||||
|
||||
const result = await grantWorkflowNodes(corp, {
|
||||
nodes: targetNodes,
|
||||
password,
|
||||
});
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson(result, runtime.outputOptions),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const lines = [
|
||||
`====== 灰度节点开通结果 [${corp.name}] ======`,
|
||||
printKeyValue({
|
||||
"申请开通节点": targetNodes.join(", "),
|
||||
"新开通成功": result.saved.length ? result.saved.join(", ") : "无 (已处于开通状态)",
|
||||
"跳过(已开通)": result.skipped.length ? result.skipped.join(", ") : "无",
|
||||
"网关反馈": result.rawMessage || "处理成功",
|
||||
}),
|
||||
"",
|
||||
"✅ 节点权限已生效!工作流设计器与 hose-use workflow analyze 将立即支持该节点。",
|
||||
];
|
||||
|
||||
return {
|
||||
stdout: lines.join("\n"),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user