refactor: 拆分工作流命令和循环诊断职责
拆出节点目录与执行上下文补全,复用客户端选择逻辑并整理循环规则。
This commit is contained in:
1 parent
7af7e7db35
commit
e185c84b4e
11 files changed
+383
-372
No files matched your search
@@ -10,7 +10,8 @@
|
||||
| [lifecycle.ts](./lifecycle.ts) | 启停与发布 |
|
||||
| [draft.ts](./draft.ts) | 本地 patch、版本校验、保存及定向刷新 chooses |
|
||||
| [create.ts](./create.ts)、[copy.ts](./copy.ts)、[delete.ts](./delete.ts) | 创建、复制与删除 |
|
||||
| [node.ts](./node.ts) | 节点操作和节点目录命令适配 |
|
||||
| [node.ts](./node.ts)、[node-catalog.ts](./node-catalog.ts) | 节点操作、节点目录及灰度开通命令适配 |
|
||||
| [job-execution.ts](./job-execution.ts) | 执行失败节点的上下文补全 |
|
||||
| [analyze.ts](./analyze.ts)、[check.ts](./check.ts)、[diff.ts](./diff.ts) | 静态分析、健康检查与配置/执行差异 |
|
||||
| [script.ts](./script.ts)、[test.ts](./test.ts) | 脚本校验、求值与工作流测试 |
|
||||
| [tail.ts](./tail.ts)、[webhook.ts](./webhook.ts)、[enum.ts](./enum.ts) | 执行监听、Webhook 与业务枚举 |
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { isClientGoodOpened } from "./analyze.js";
|
||||
import { afterEach, describe, expect, it, mock, spyOn } from "bun:test";
|
||||
import { handleAnalyze, isClientGoodOpened } from "./analyze.js";
|
||||
import * as services from "../../../domains/platform/workflow/services.js";
|
||||
import * as store from "../../../domains/store/tools.js";
|
||||
import * as shared from "./shared.js";
|
||||
import { parseArgs } from "../../parser.js";
|
||||
|
||||
afterEach(() => mock.restore());
|
||||
|
||||
describe("workflow analyze enterprise application status", () => {
|
||||
it("uses the enterprise opening status and ignores marketplace online status", () => {
|
||||
@@ -8,3 +14,18 @@ describe("workflow analyze enterprise application status", () => {
|
||||
expect(isClientGoodOpened({ status: "CLOSED", onLineStatus: "ONLINE" })).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
it("reports missing external evidence instead of claiming the workflow is safe to publish", async () => {
|
||||
spyOn(shared, "createWorkflowDetailClient").mockResolvedValue({ client: {}, clients: { ekbClient: {} } } as any);
|
||||
spyOn(services, "getWorkflowDetail").mockResolvedValue({ id: "wf", label: "test", state: 1, version: "1", tasks: [] } as any);
|
||||
spyOn(services, "getWorkflowAvailableNodes").mockRejectedValue(new Error("权限不足"));
|
||||
spyOn(store, "fetchClientGoods").mockRejectedValue(new Error("商店不可用"));
|
||||
const parsed = parseArgs(["workflow", "analyze", "wf", "--json"]);
|
||||
const runtime = { selectedCorp: { id: "corp" }, jsonMode: true } as any;
|
||||
const report = JSON.parse((await handleAnalyze(parsed, runtime)).stdout);
|
||||
expect(report.evidenceComplete).toBe(false);
|
||||
expect(report.evidenceErrors.map((item: { source: string }) => item.source)).toEqual(["availableNodeTypes", "openedPowerCodes"]);
|
||||
const text = await handleAnalyze(parsed, { ...runtime, jsonMode: false });
|
||||
expect(text.stdout).toContain("分析证据不完整");
|
||||
expect(text.stdout).not.toContain("可安全发布");
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import { createWorkflow } from "../../../domains/platform/workflow/services.js";
|
||||
import { createWorkflow, webhookTriggerUrl } from "../../../domains/platform/workflow/services.js";
|
||||
import { stringOption } from "../../parser.js";
|
||||
import { printJson, printKeyValue } from "../../printer.js";
|
||||
import { isDryRun, mutationPreview, requireMutationConfirmation } from "../../mutation.js";
|
||||
@@ -52,8 +52,8 @@ export async function handleCreate(
|
||||
|
||||
const triggerNode = result.tasks?.[0];
|
||||
const triggerSummary = triggerNode ? `${triggerNode.label || triggerNode.name} (${triggerNode.type})` : "无首节点 (需在设计器配置)";
|
||||
const webhookUrl = triggerNode?.type === "webhook" && (triggerNode as any).urlPath
|
||||
? `https://piper.ekuaibao.com/api/webhook/${(triggerNode as any).urlPath}`
|
||||
const webhookUrl = triggerNode?.type === "webhook" && triggerNode.urlPath
|
||||
? webhookTriggerUrl(triggerNode)
|
||||
: undefined;
|
||||
|
||||
const kvData: Record<string, string> = {
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import { getJobExecutionLevel } from "../../../domains/platform/workflow/services.js";
|
||||
import type { WorkflowTaskExecution } from "../../../domains/platform/workflow/types.js";
|
||||
import type { createPiperClientForCorp } from "../../helpers.js";
|
||||
|
||||
export 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;
|
||||
}
|
||||
|
||||
@@ -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"]);
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
import { getWorkflowAvailableNodes, grantWorkflowNodes } from "../../../domains/platform/workflow/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";
|
||||
|
||||
// ── 企业可用节点字典与灰度开通 ──────────────────────────────────────────────
|
||||
|
||||
export 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 };
|
||||
}
|
||||
|
||||
export 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,
|
||||
};
|
||||
}
|
||||
|
||||
requireMutationConfirmation(parsed, runtime, "开通企业工作流灰度节点", "hose-use workflow nodes grant <type...> --yes");
|
||||
if (isDryRun(parsed, runtime)) {
|
||||
return mutationPreview(parsed, runtime, "开通企业工作流灰度节点", corp.corpId || corp.credentials.corpId || corp.id, {
|
||||
nodes: targetNodes.map(node => findGrayNode(node)?.type || node.trim()),
|
||||
adminPasswordRequired: Boolean(process.env.HOSE_ADMIN_PASSWORD),
|
||||
});
|
||||
}
|
||||
|
||||
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: result.success ? 0 : 1,
|
||||
};
|
||||
}
|
||||
if (!result.success) {
|
||||
return { stdout: "", stderr: `灰度节点开通失败: ${result.rawMessage || "网关拒绝了开通请求"}\n`, exitCode: 1 };
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
}
|
||||
@@ -7,13 +7,7 @@ import {
|
||||
editWorkflowTask,
|
||||
removeWorkflowTask,
|
||||
applyNodeMapping,
|
||||
getWorkflowAvailableNodes,
|
||||
grantWorkflowNodes,
|
||||
} from "../../../domains/platform/workflow/services.js";
|
||||
import {
|
||||
GRAY_NODES_CATALOG,
|
||||
findGrayNode,
|
||||
} from "../../../domains/platform/workflow/nodes/gray-nodes-catalog.js";
|
||||
import { isServerManagedDescType } from "../../../domains/platform/workflow/nodes/mutations.js";
|
||||
import { ValidationError } from "../../../core/errors.js";
|
||||
import type { WorkflowDetail } from "../../../domains/platform/workflow/types.js";
|
||||
@@ -21,8 +15,8 @@ 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, formatWorkflowVersion } from "./shared.js";
|
||||
import { handleGrantNodes, handleListAvailableNodes } from "./node-catalog.js";
|
||||
|
||||
async function saveNodeChanges(client: Parameters<typeof getWorkflowDetail>[0], original: WorkflowDetail, updated: WorkflowDetail, platformId?: string) {
|
||||
const remote = await getWorkflowDetail(client, original.id);
|
||||
@@ -620,175 +614,3 @@ 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,
|
||||
};
|
||||
}
|
||||
|
||||
requireMutationConfirmation(parsed, runtime, "开通企业工作流灰度节点", "hose-use workflow nodes grant <type...> --yes");
|
||||
if (isDryRun(parsed, runtime)) {
|
||||
return mutationPreview(parsed, runtime, "开通企业工作流灰度节点", corp.corpId || corp.credentials.corpId || corp.id, {
|
||||
nodes: targetNodes.map(node => findGrayNode(node)?.type || node.trim()),
|
||||
adminPasswordRequired: Boolean(process.env.HOSE_ADMIN_PASSWORD),
|
||||
});
|
||||
}
|
||||
|
||||
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: result.success ? 0 : 1,
|
||||
};
|
||||
}
|
||||
if (!result.success) {
|
||||
return { stdout: "", stderr: `灰度节点开通失败: ${result.rawMessage || "网关拒绝了开通请求"}\n`, exitCode: 1 };
|
||||
}
|
||||
|
||||
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