refactor: 归整工作流管理和目录字典

This commit is contained in:
gitea committed 2026-10-30 17:47:34 +08:00
1 parent 5f96cc2c88
commit f4f34a83b4
16 files changed
+57 -45

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
import { readFileSync, writeFileSync } from "node:fs";
import { EkbError } from "../../../core/errors.js";
import { getWorkflowDetail, listAllWorkflows, refreshWorkflowChooses, updateWorkflow } from "../../../domains/platform/workflow/services.js";
import { WorkflowSavePartialError } from "../../../domains/platform/workflow/save-error.js";
import { WorkflowSavePartialError } from "../../../domains/platform/workflow/management/save-error.js";
import { WorkflowDetailSchema } from "../../../domains/platform/workflow/types.js";
import {
applyWorkflowPathPatch,
@@ -9,7 +9,7 @@ import { cliErrorResult } from "../../runner.js";
import { normalizeCliArgs, tokenizeCommand } from "../../../server.js";
import { handleWorkflowCommand } from "./index.js";
import { WorkflowDetailSchema } from "../../../domains/platform/workflow/types.js";
import { WorkflowSavePartialError } from "../../../domains/platform/workflow/save-error.js";
import { WorkflowSavePartialError } from "../../../domains/platform/workflow/management/save-error.js";
import type { CliRuntime } from "../../types.js";
const spies: Array<{ mockRestore(): void }> = [];
@@ -207,17 +207,16 @@ MVEL 本地仿真支持的是转译子集:零参 `HashMap` / `ArrayList` 及 `
|---|---|
| [api.ts](./api.ts)、[types.ts](./types.ts) | HTTP 请求/响应校验与工作流 Zod 模型 |
| [services.ts](./services.ts) | 显式业务出口及既有能力目录的统一导出 |
| [queries.ts](./queries.ts) | 列表、历史、执行读取和跨应用工作流检索 |
| [configuration.ts](./configuration.ts) | 创建、复制、保存、启停、快照清洗与部分成功恢复 |
| [execution.ts](./execution.ts)、[execution-context.ts](./execution-context.ts) | 执行树展开、失败节点提取及执行实例上下文 |
| [diff.ts](./diff.ts) | 配置快照与执行结果差异 |
| [debug.ts](./debug.ts) | 调试、输入采样和结果汇总 |
| [catalog.ts](./catalog.ts) | DSL、节点权限、枚举字典与回退 |
### 子目录
| 目录 | 职责 |
|---|---|
| [management](./management/README.management.md) | 工作流列表、查询、创建、复制、保存及启停 |
| [catalog](./catalog/README.catalog.md) | DSL、节点权限与业务枚举字典 |
| [triggers](./triggers/README.triggers.md) | 触发器分类、初始节点构建及 Webhook 地址与复制规则;实际调度由合思服务端负责 |
| [nodes](./nodes/README.nodes.md) | 节点树遍历、定位、增删改和重排,以及灰度节点目录 |
| [analysis](./analysis/README.analysis.md) | 工作流结构、引用依赖和配置的静态分析与诊断 |
@@ -0,0 +1,6 @@
# 工作流目录与字典
- [catalog.ts](./catalog.ts):DSL、员工、可用节点、灰度开通与枚举查询。
- [enums.ts](./enums.ts):内置工作流动作枚举和匹配。
灰度节点静态清单位于同级 [nodes](../nodes/README.nodes.md);HTTP 传输由上级 `api.ts` 负责。
@@ -1,7 +1,7 @@
import { KyInstance } from "ky";
import { CorpConfig } from "../../../core/config/types.js";
import * as api from "./api.js";
import { PermissionError, ValidationError } from "../../../core/errors.js";
import { CorpConfig } from "../../../../core/config/types.js";
import * as api from "../api.js";
import { PermissionError, ValidationError } from "../../../../core/errors.js";
export function listDsl(...args: Parameters<typeof api.listDsl>) {
@@ -57,7 +57,7 @@ export async function resolveWorkflowEnumOptions(
export async function getWorkflowAvailableNodes(
client: KyInstance
): Promise<import("./types.js").AvailableWorkflowNodes> {
): Promise<import("../types.js").AvailableWorkflowNodes> {
const catalog = await api.listDslCatalog(client);
const allTypes = new Set<string>();
@@ -82,8 +82,8 @@ export async function getWorkflowAvailableNodes(
export async function grantWorkflowNodes(
corp: CorpConfig,
options: import("./types.js").GrantWorkflowNodesOptions
): Promise<import("./types.js").GrantWorkflowNodesResult> {
options: import("../types.js").GrantWorkflowNodesOptions
): Promise<import("../types.js").GrantWorkflowNodesResult> {
if (!options.nodes || options.nodes.length === 0) {
throw new ValidationError("必须指定至少一个需要开通的节点名称或类型");
}
@@ -99,7 +99,7 @@ export async function grantWorkflowNodes(
}
// 2. 节点清洗与归一化(将可能传入的中文名映射为标准的 node type)
const { findGrayNode } = await import("./nodes/gray-nodes-catalog.js");
const { findGrayNode } = await import("../nodes/gray-nodes-catalog.js");
const normalizedNodes = options.nodes.map((node) => {
const matched = findGrayNode(node);
return matched ? matched.type : node.trim();
@@ -5,8 +5,8 @@ import {
isWorkflowActionCode,
matchWorkflowAction,
resolveWorkflowEnumOptions,
} from "./services.js";
import { analyzeWorkflow } from "./analysis/index.js";
} from "../services.js";
import { analyzeWorkflow } from "../analysis/index.js";
describe("Workflow Action Enums & Diagnostics", () => {
it("contains 18 standard system notification action enums", () => {
+1 -1
View File
@@ -5,4 +5,4 @@ export * from "./branch/index.js";
export * from "./analysis/index.js";
export * from "./state/index.js";
export * from "./alert/index.js";
export * from "./enums.js";
export * from "./catalog/enums.js";
@@ -0,0 +1,7 @@
# 工作流管理
- [configuration.ts](./configuration.ts):创建、复制、保存、启停和元数据刷新。
- [queries.ts](./queries.ts):工作流列表与跨应用查询,以及 Job、日志等读取服务出口。
- [save-error.ts](./save-error.ts):主保存成功而元数据刷新失败时的部分成功异常。
HTTP 传输和共享模型仍位于上级 `api.ts`、`types.ts`,对外业务出口为上级 `services.ts`。
@@ -1,14 +1,14 @@
import { KyInstance } from "ky";
import { WorkflowSavePartialError } from "./save-error.js";
import * as api from "./api.js";
import { buildInitialTriggerTask, resetCopiedWebhookTrigger, ensureWebhookTriggerPath } from "./triggers/index.js";
export { buildInitialTriggerTask } from "./triggers/index.js";
import * as api from "../api.js";
import { buildInitialTriggerTask, resetCopiedWebhookTrigger, ensureWebhookTriggerPath } from "../triggers/index.js";
export { buildInitialTriggerTask } from "../triggers/index.js";
export function sanitizeWorkflowSnapshot(
detail: import("./types.js").WorkflowDetail
): import("./types.js").WorkflowDetail {
const cloned = JSON.parse(JSON.stringify(detail)) as import("./types.js").WorkflowDetail;
detail: import("../types.js").WorkflowDetail
): import("../types.js").WorkflowDetail {
const cloned = JSON.parse(JSON.stringify(detail)) as import("../types.js").WorkflowDetail;
if (Array.isArray(cloned.$snapshot)) {
cloned.$snapshot = cloned.$snapshot.map((entry) => {
if (typeof entry.value === "string" && entry.value.includes("docs.ekuaibao.com")) {
@@ -26,11 +26,11 @@ export function sanitizeWorkflowSnapshot(
export async function updateWorkflow(
client: KyInstance,
workflow: import("./types.js").WorkflowDetail,
workflow: import("../types.js").WorkflowDetail,
platformId?: string
) {
// 前端保存时会带上触发输入 $platformId;缺少它会导致平台把内置节点 desc 重置为「」。
const payload: import("./types.js").WorkflowDetail = platformId && !workflow.inputs?.length
const payload: import("../types.js").WorkflowDetail = platformId && !workflow.inputs?.length
? { ...workflow, inputs: [{ key: "$platformId", value: platformId }] }
: workflow;
const sanitized = sanitizeWorkflowSnapshot(payload);
@@ -55,9 +55,9 @@ export async function copyWorkflow(
client: import("ky").KyInstance,
pipelineId: string,
options: { label?: string; platformId?: string } = {}
): Promise<import("./types.js").WorkflowDetail> {
): Promise<import("../types.js").WorkflowDetail> {
const detail = await api.getWorkflowDetail(client, pipelineId);
const cloned = JSON.parse(JSON.stringify(detail)) as import("./types.js").WorkflowDetail;
const cloned = JSON.parse(JSON.stringify(detail)) as import("../types.js").WorkflowDetail;
if (options.label) {
cloned.label = options.label;
} else if (!cloned.label.includes("副本")) {
@@ -93,7 +93,7 @@ export interface CreateWorkflowOptions {
export async function createWorkflow(
client: import("ky").KyInstance,
options: CreateWorkflowOptions = {}
): Promise<import("./types.js").WorkflowDetail> {
): Promise<import("../types.js").WorkflowDetail> {
let base: Record<string, any> = {};
if (options.file) {
const fs = await import("fs/promises");
@@ -1,6 +1,6 @@
import { expect, it, spyOn } from "bun:test";
import * as applications from "../applications/services.js";
import * as api from "./api.js";
import * as applications from "../../applications/services.js";
import * as api from "../api.js";
import { listAllWorkflows } from "./queries.js";
it("reports whether cross-application results cover all pages and applications", async () => {
@@ -1,8 +1,8 @@
import { listBasicPlatforms } from "../applications/services.js";
import { listBasicPlatforms } from "../../applications/services.js";
import { KyInstance } from "ky";
import { CorpConfig } from "../../../core/config/types.js";
import * as api from "./api.js";
import { WorkflowSummary, WorkflowListAllError, WorkflowTask, WorkflowWithMatches, TaskMatch } from "./types.js";
import { CorpConfig } from "../../../../core/config/types.js";
import * as api from "../api.js";
import { WorkflowSummary, WorkflowListAllError, WorkflowTask, WorkflowWithMatches, TaskMatch } from "../types.js";
export interface WorkflowClients {
@@ -1,5 +1,5 @@
import { EkbError } from "../../../core/errors.js";
import type { WorkflowDetail } from "./types.js";
import { EkbError } from "../../../../core/errors.js";
import type { WorkflowDetail } from "../types.js";
/** 主保存已经提交,后续元数据刷新失败。调用方必须保留已保存版本。 */
export class WorkflowSavePartialError extends EkbError {
@@ -1,10 +1,10 @@
import { expect, test } from "bun:test";
import ky from "ky";
import { deleteWorkflow, updateWorkflowChooses } from "./api.js";
import { refreshWorkflowChooses, updateWorkflow } from "./services.js";
import { WorkflowDetailSchema } from "./types.js";
import { deleteWorkflow, updateWorkflowChooses } from "../api.js";
import { refreshWorkflowChooses, updateWorkflow } from "../services.js";
import { WorkflowDetailSchema } from "../types.js";
import { WorkflowSavePartialError } from "./save-error.js";
import { AuthenticationError } from "../../../core/errors.js";
import { AuthenticationError } from "../../../../core/errors.js";
test("Piper 无返回值写操作兼容空成功,拒绝业务失败与无效 JSON", async () => {
for (const action of [deleteWorkflow, updateWorkflowChooses]) {
+5 -5
View File
@@ -15,14 +15,14 @@ export {
getExecutionLogs,
listAllWorkflows,
findWorkflowsByTaskType,
} from "./queries.js";
} from "./management/queries.js";
export type {
WorkflowClients,
ListAllWorkflowsOptions,
ListAllWorkflowsResult,
FindWorkflowsByTaskTypeOptions,
FindWorkflowsByTaskTypeResult,
} from "./queries.js";
} from "./management/queries.js";
export {
sanitizeWorkflowSnapshot,
updateWorkflow,
@@ -32,10 +32,10 @@ export {
createWorkflow,
deleteWorkflow,
toggleWorkflow,
} from "./configuration.js";
} from "./management/configuration.js";
export type {
CreateWorkflowOptions,
} from "./configuration.js";
} from "./management/configuration.js";
export {
listDsl,
listStaffs,
@@ -43,7 +43,7 @@ export {
resolveWorkflowEnumOptions,
getWorkflowAvailableNodes,
grantWorkflowNodes,
} from "./catalog.js";
} from "./catalog/catalog.js";
export {
getWebhookInfo,
sampleWorkflowData,