refactor: 按职责拆分工作流共享模型
This commit is contained in:
1 parent
22bd7a9995
commit
8a34ea8c85
14 files changed
+782
-751
No files matched your search
@@ -76,7 +76,7 @@ MCP 调用方式统一为 `hose_cli` 的 `command` 参数传入下列命令。
|
||||
|
||||
## 工作流 JSON Schema
|
||||
|
||||
`src/domains/platform/workflow/types.ts` 定义了递归、按节点类型区分的 Zod schema:
|
||||
`src/domains/platform/workflow/types.ts` 导出递归、按节点类型区分的 Zod schema,具体定义位于 `workflow/models/`:
|
||||
|
||||
- `WorkflowTaskSchema`:按节点类型区分并递归建模,覆盖 `webhook`、`condition`、`every`、`stop`、`http`、`flow-detail`、`code`、`code-js2`、`ekuaibao-datalink-filter`、`ekuaibao-datalink-create`、`data-convert`、`flow-create-task` 以及兜底 `unknown`。
|
||||
- 控制节点(`condition` / `every`)支持递归嵌套 `tasks`。
|
||||
|
||||
@@ -76,7 +76,7 @@ staffId, userId, sourceChannel?, baseUrl?, external?, needAuth?
|
||||
| P29 | POST | `PIPER /api/easo/dsl/condition/select/EKB_ENUM` | Query `{thirdId}`;body `{}` 或 `{$platformId}` | `{code,msg,data:[{label,code,name?}]}` | `src/domains/platform/workflow/api.ts:481` | 否 |
|
||||
| P30 | POST | `GW /hose-workflow-node` | `{token,corpId,nodes:"a,b,c",baseUrl?}` | `{success,saved:[],skipped:[],msg?}` | `src/domains/platform/workflow/api.ts:498` | 否 |
|
||||
|
||||
`Platform` 代码字段(`src/domains/platform/workflow/types.ts:5`):
|
||||
`Platform` 代码字段(`src/domains/platform/workflow/models/nodes.ts:5`):
|
||||
|
||||
```text
|
||||
id, name, nameSpell, enName?, code, corporationId, active, type, groupType,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"title": "Workflow detail (EASO/Piper pipeline)",
|
||||
"description": "工作流详情。GET /api/easo/pipelines/{id} 与 PUT /api/easo/pipelines/{id} 使用。PUT 请求体带 inputs,抓包中的响应 data 不返回 inputs。",
|
||||
"x-source": [
|
||||
"code-derived: src/domains/platform/workflow/types.ts:252 (WorkflowDetailSchema)",
|
||||
"code-derived: src/domains/platform/workflow/models/workflow.ts:49 (WorkflowDetailSchema)",
|
||||
"reference: _tmp-captured/raw/PUT-api-easo-pipelines-id.json"
|
||||
],
|
||||
"type": "object",
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"title": "Workflow job execution",
|
||||
"description": "Piper 任务实例与节点执行数据。/execution 与 /execution/level/failed 的 data 可能是数组,也可能是分页对象 {number,size,totalPages,totalItems,items}。",
|
||||
"x-source": [
|
||||
"code-derived: src/domains/platform/workflow/types.ts:339",
|
||||
"code-derived: src/domains/platform/workflow/models/execution.ts:5",
|
||||
"reference: _tmp-captured/raw/GET-api-easo-jobs-id-execution.json",
|
||||
"reference: _tmp-captured/raw/GET-api-easo-jobs-id-execution-completed.json"
|
||||
],
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"title": "Workflow snapshot",
|
||||
"description": "工作流快照。前端使用 GET /api/easo/pipelines/snapshot/{snapshotId};代码还兼容 /api/easo/snapshots/{id} 与 /api/easo/pipelines/{pipelineId}/snapshots/{id}。",
|
||||
"x-source": [
|
||||
"code-derived: src/domains/platform/workflow/types.ts:286 (WorkflowSnapshotSchema)",
|
||||
"code-derived: src/domains/platform/workflow/models/workflow.ts:83 (WorkflowSnapshotSchema)",
|
||||
"reference: _tmp-captured/raw/GET-api-easo-pipelines-snapshot-id.json"
|
||||
],
|
||||
"type": "object",
|
||||
|
||||
@@ -205,13 +205,14 @@ MVEL 本地仿真支持的是转译子集:零参 `HashMap` / `ArrayList` 及 `
|
||||
|
||||
| 文件 | 职责 |
|
||||
|---|---|
|
||||
| [api.ts](./api.ts)、[types.ts](./types.ts) | HTTP 请求/响应校验与工作流 Zod 模型 |
|
||||
| [api.ts](./api.ts)、[types.ts](./types.ts) | HTTP 请求/响应校验与工作流模型统一出口 |
|
||||
| [services.ts](./services.ts) | 显式业务出口及既有能力目录的统一导出 |
|
||||
|
||||
### 子目录
|
||||
|
||||
| 目录 | 职责 |
|
||||
|---|---|
|
||||
| [models](./models/README.models.md) | 工作流、节点、执行及其他共享 Zod 模型 |
|
||||
| [management](./management/README.management.md) | 工作流列表、查询、创建、复制、保存及启停 |
|
||||
| [catalog](./catalog/README.catalog.md) | DSL、节点权限与业务枚举字典 |
|
||||
| [execution](./execution/README.execution.md) | 执行树、实例上下文及调试结果汇总 |
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# 工作流共享模型
|
||||
|
||||
- [nodes.ts](./nodes.ts):递归任务节点及字段映射。
|
||||
- [workflow.ts](./workflow.ts):工作流配置、快照、状态和跨应用聚合结果。
|
||||
- [execution.ts](./execution.ts):Job 与执行记录。
|
||||
- [catalog.ts](./catalog.ts):DSL、节点、员工及枚举字典。
|
||||
- [debug.ts](./debug.ts):Webhook、调试数据源与样本。
|
||||
- [comparison.ts](./comparison.ts):配置和 Job 差异结果。
|
||||
|
||||
上级 [types.ts](../types.ts) 保留既有模型出口。节点递归 schema 放在同一文件,避免引入循环初始化。
|
||||
@@ -0,0 +1,78 @@
|
||||
import { z } from "zod";
|
||||
|
||||
// ── DSL 配置 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export const WorkflowDslSchema = z.object({
|
||||
id: z.string().optional(),
|
||||
name: z.string().default(""),
|
||||
type: z.string().default(""),
|
||||
config: z.record(z.string(), z.any()).default({}),
|
||||
});
|
||||
|
||||
export const WorkflowNodeDefinitionSchema = z
|
||||
.object({
|
||||
id: z.string().nullable().optional(),
|
||||
name: z.string().default(""),
|
||||
type: z.string().default(""),
|
||||
groupName: z.string().nullable().optional(),
|
||||
icon: z.string().nullable().optional(),
|
||||
iconColor: z.string().nullable().optional(),
|
||||
remark: z.string().nullable().optional(),
|
||||
platform: z.string().nullable().optional(),
|
||||
version: z.number().nullable().optional(),
|
||||
$json: z.string().nullable().optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export type WorkflowNodeDefinition = z.infer<typeof WorkflowNodeDefinitionSchema>;
|
||||
|
||||
export const WorkflowDslCatalogSchema = z
|
||||
.object({
|
||||
action: z.array(WorkflowNodeDefinitionSchema).default([]),
|
||||
control: z.array(WorkflowNodeDefinitionSchema).default([]),
|
||||
trigger: z.array(WorkflowNodeDefinitionSchema).default([]),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export type WorkflowDslCatalog = z.infer<typeof WorkflowDslCatalogSchema>;
|
||||
|
||||
export interface AvailableWorkflowNodes {
|
||||
allTypes: Set<string>;
|
||||
actionNodes: WorkflowNodeDefinition[];
|
||||
controlNodes: WorkflowNodeDefinition[];
|
||||
triggerNodes: WorkflowNodeDefinition[];
|
||||
}
|
||||
|
||||
export interface GrantWorkflowNodesOptions {
|
||||
nodes: string[];
|
||||
password?: string;
|
||||
}
|
||||
|
||||
export interface GrantWorkflowNodesResult {
|
||||
success: boolean;
|
||||
saved: string[];
|
||||
skipped: string[];
|
||||
rawMessage: string;
|
||||
}
|
||||
|
||||
// ── 员工 ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
export const StaffSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string().default(""),
|
||||
email: z.string().nullable().optional(),
|
||||
department: z.string().nullable().optional(),
|
||||
});
|
||||
|
||||
// ── 工作流/Piper 枚举选项 (EKB_ENUM) ──────────────────────────────────────────
|
||||
|
||||
export const WorkflowEnumItemSchema = z.object({
|
||||
label: z.string(),
|
||||
code: z.string(),
|
||||
name: z.string().optional().default(""),
|
||||
});
|
||||
|
||||
export type WorkflowEnumItem = z.infer<typeof WorkflowEnumItemSchema>;
|
||||
|
||||
export type WorkflowDsl = z.infer<typeof WorkflowDslSchema>;
|
||||
export type Staff = z.infer<typeof StaffSchema>;
|
||||
@@ -0,0 +1,99 @@
|
||||
// ── 工作流快照与 Job 差异比对模型 ──────────────────────────────────────────
|
||||
|
||||
export interface TaskConfigDiff {
|
||||
taskName: string;
|
||||
displayName?: string;
|
||||
type: string;
|
||||
changeType: "ADDED" | "REMOVED" | "MODIFIED";
|
||||
codeDiff?: {
|
||||
from?: string;
|
||||
to?: string;
|
||||
unifiedDiff?: string;
|
||||
};
|
||||
filterDiff?: {
|
||||
from?: unknown;
|
||||
to?: unknown;
|
||||
};
|
||||
configChanges: Array<{
|
||||
field: string;
|
||||
from?: unknown;
|
||||
to?: unknown;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface WorkflowSnapshotDiff {
|
||||
snapshotA: {
|
||||
id: string;
|
||||
version?: string;
|
||||
updateTime?: string;
|
||||
staffName?: string;
|
||||
};
|
||||
snapshotB: {
|
||||
id: string;
|
||||
version?: string;
|
||||
updateTime?: string;
|
||||
staffName?: string;
|
||||
};
|
||||
addedTasks: string[];
|
||||
removedTasks: string[];
|
||||
modifiedTasks: TaskConfigDiff[];
|
||||
summary: {
|
||||
totalA: number;
|
||||
totalB: number;
|
||||
changedCount: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface NodeExecutionDiff {
|
||||
taskName: string;
|
||||
instanceKey?: string;
|
||||
currentLoopPath?: string;
|
||||
displayName?: string;
|
||||
type?: string;
|
||||
statusA?: string;
|
||||
statusB?: string;
|
||||
durationMsA?: number;
|
||||
durationMsB?: number;
|
||||
errorA?: unknown;
|
||||
errorB?: unknown;
|
||||
inputsDiff?: Array<{
|
||||
field: string;
|
||||
from?: unknown;
|
||||
to?: unknown;
|
||||
}>;
|
||||
outputsDiff?: Array<{
|
||||
field: string;
|
||||
from?: unknown;
|
||||
to?: unknown;
|
||||
}>;
|
||||
diverged: boolean;
|
||||
}
|
||||
|
||||
export interface WorkflowJobDiff {
|
||||
jobA: {
|
||||
id: string;
|
||||
pipelineId?: string;
|
||||
state?: string | number;
|
||||
startTime?: string;
|
||||
durationTime?: number;
|
||||
hasError?: boolean;
|
||||
errorCount?: number;
|
||||
};
|
||||
jobB: {
|
||||
id: string;
|
||||
pipelineId?: string;
|
||||
state?: string | number;
|
||||
startTime?: string;
|
||||
durationTime?: number;
|
||||
hasError?: boolean;
|
||||
errorCount?: number;
|
||||
};
|
||||
nodes: NodeExecutionDiff[];
|
||||
summary: {
|
||||
totalNodesA: number;
|
||||
totalNodesB: number;
|
||||
divergedNodesCount: number;
|
||||
statusDiffCount: number;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import type { WorkflowTriggerCategory } from "../triggers/classification.js";
|
||||
import type { WorkflowTaskExecution } from "./execution.js";
|
||||
|
||||
// ── Webhook ──────────────────────────────────────────────────────────────────
|
||||
|
||||
export const WebhookInfoSchema = z.object({
|
||||
id: z.string(),
|
||||
pipelineId: z.string(),
|
||||
url: z.string().default(""),
|
||||
active: z.boolean().default(true),
|
||||
});
|
||||
|
||||
// ── 测试/采样数据 ─────────────────────────────────────────────────────────────
|
||||
|
||||
export const WorkflowSampleDataSchema = z.record(z.string(), z.any());
|
||||
|
||||
// ── 调试数据源与测试结果 ───────────────────────────────────────────────────────
|
||||
|
||||
export const WorkflowDebugSourceItemSchema = z
|
||||
.object({
|
||||
id: z.string(),
|
||||
title: z.string().default(""),
|
||||
flowState: z.string().default(""),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export const WorkflowDebugSourceResultSchema = z
|
||||
.object({
|
||||
type: z.string().default(""),
|
||||
total: z.number().default(0),
|
||||
items: z.array(WorkflowDebugSourceItemSchema).default([]),
|
||||
fields: z.array(z.object({ key: z.string(), label: z.string() })).default([]),
|
||||
label: z.string().default(""),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export type WorkflowDebugSourceItem = z.infer<typeof WorkflowDebugSourceItemSchema>;
|
||||
export type WorkflowDebugSourceResult = z.infer<typeof WorkflowDebugSourceResultSchema>;
|
||||
|
||||
export interface WorkflowTestReport {
|
||||
jobId: string;
|
||||
pipelineId: string;
|
||||
status: string;
|
||||
outcome: "completed" | "failed" | "timed_out" | "incomplete";
|
||||
timedOut: boolean;
|
||||
diagnosticsComplete: boolean;
|
||||
diagnosticsErrors: Array<{ source: string; message: string }>;
|
||||
runType: string;
|
||||
durationTime?: number;
|
||||
targetEntityId: string;
|
||||
triggerCategory?: WorkflowTriggerCategory;
|
||||
triggerType?: string;
|
||||
triggerLabel?: string;
|
||||
executionTree: WorkflowTaskExecution[];
|
||||
failedExecutions: WorkflowTaskExecution[];
|
||||
conditionDiagnoses: import("../branch/types.js").ConditionBranchExplanation[];
|
||||
}
|
||||
|
||||
// ── Webhook 数据样本 (Sample Data) ─────────────────────────────────────────────
|
||||
|
||||
export const WorkflowSampleRecordSchema = z.object({
|
||||
id: z.string(),
|
||||
corporationId: z.string().optional(),
|
||||
pipelineId: z.string().optional(),
|
||||
taskName: z.string().optional(),
|
||||
actived: z.number().optional(),
|
||||
dataJson: z.string(),
|
||||
createTime: z.number(),
|
||||
updateTime: z.number().optional(),
|
||||
});
|
||||
|
||||
export type WorkflowSampleRecord = z.infer<typeof WorkflowSampleRecordSchema>;
|
||||
|
||||
export const WorkflowSampleDataResultSchema = z.object({
|
||||
records: z.array(WorkflowSampleRecordSchema).default([]),
|
||||
total: z.number().optional(),
|
||||
size: z.number().optional(),
|
||||
current: z.number().optional(),
|
||||
});
|
||||
|
||||
export type WorkflowSampleDataResult = z.infer<typeof WorkflowSampleDataResultSchema>;
|
||||
|
||||
|
||||
export type WebhookInfo = z.infer<typeof WebhookInfoSchema>;
|
||||
export type WorkflowSampleData = z.infer<typeof WorkflowSampleDataSchema>;
|
||||
@@ -0,0 +1,109 @@
|
||||
import { z } from "zod";
|
||||
|
||||
// ── 运行中的任务与单次 Job 执行详情 ──────────────────────────────────────────
|
||||
|
||||
export const WorkflowJobSchema = z
|
||||
.object({
|
||||
id: z.string().optional(),
|
||||
jobId: z.string().optional(),
|
||||
pipelineId: z.string().nullish().default(""),
|
||||
jobName: z.string().nullish(),
|
||||
status: z.string().default(""),
|
||||
runType: z.string().default(""),
|
||||
executeTime: z.union([z.string(), z.number()]).nullish(),
|
||||
startTime: z.union([z.string(), z.number()]).nullish(),
|
||||
endTime: z.union([z.string(), z.number()]).nullish(),
|
||||
triggerType: z.string().default(""),
|
||||
successTaskCount: z.number().nullish().default(0),
|
||||
errorTaskCount: z.number().nullish().default(0),
|
||||
hasError: z.union([z.string(), z.boolean()]).nullish(),
|
||||
state: z.union([z.number(), z.string()]).nullish(),
|
||||
autoPublish: z.boolean().nullish(),
|
||||
version: z.string().nullish(),
|
||||
snapshotId: z.string().nullish(),
|
||||
})
|
||||
.passthrough()
|
||||
.transform((val) => ({
|
||||
...val,
|
||||
id: val.id || val.jobId || "",
|
||||
jobId: val.jobId || val.id || "",
|
||||
pipelineId: val.pipelineId || "",
|
||||
}));
|
||||
|
||||
export const WorkflowJobDetailSchema = z
|
||||
.object({
|
||||
id: z.string(),
|
||||
pipelineId: z.string().default(""),
|
||||
label: z.string().default(""),
|
||||
status: z.string().default(""),
|
||||
runType: z.string().default(""),
|
||||
startTime: z.union([z.number(), z.string()]).nullable().optional(),
|
||||
endTime: z.union([z.number(), z.string()]).nullable().optional(),
|
||||
createTime: z.union([z.number(), z.string()]).nullable().optional(),
|
||||
inputs: z.any().optional(),
|
||||
outputs: z.any().optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export const WorkflowExecutionErrorSchema = z
|
||||
.object({
|
||||
message: z.string().default(""),
|
||||
stackTrace: z.array(z.string()).nullish().transform((v) => v ?? []),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export const WorkflowExecutionLogSchema = z
|
||||
.object({
|
||||
id: z.union([z.string(), z.number()]).optional(),
|
||||
level: z.string().default("INFO"),
|
||||
message: z.string().default(""),
|
||||
createAt: z.union([z.string(), z.number()]).optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export const WorkflowTaskExecutionSchema = z
|
||||
.object({
|
||||
id: z.string(),
|
||||
parentId: z.string().nullable().optional(),
|
||||
jobId: z.string().optional(),
|
||||
pipelineId: z.string().optional(),
|
||||
name: z.string().optional(),
|
||||
displayName: z.string().nullable().optional(),
|
||||
label: z.string().nullable().optional(),
|
||||
type: z.string().default(""),
|
||||
orderIndex: z.number().optional(),
|
||||
levelIndex: z.array(z.number()).optional(),
|
||||
status: z.string().default(""),
|
||||
executionTime: z.number().optional(),
|
||||
startTime: z.union([z.number(), z.string()]).nullable().optional(),
|
||||
endTime: z.union([z.number(), z.string()]).nullable().optional(),
|
||||
createTime: z.union([z.number(), z.string()]).nullable().optional(),
|
||||
currentLoopPath: z.string().nullable().optional(),
|
||||
error: WorkflowExecutionErrorSchema.nullable().optional(),
|
||||
output: z.any().optional(),
|
||||
form: z.union([z.record(z.string(), z.any()), z.array(z.any())]).nullable().optional(),
|
||||
details: z.record(z.string(), z.any()).nullable().optional(),
|
||||
executionLogs: z.array(z.any()).optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export const WorkflowExecutionPageSchema = z
|
||||
.object({
|
||||
number: z.number().default(1),
|
||||
size: z.number().default(20),
|
||||
totalPages: z.number().default(0),
|
||||
totalItems: z.number().default(0),
|
||||
items: z
|
||||
.array(z.union([WorkflowTaskExecutionSchema, z.array(WorkflowTaskExecutionSchema)]))
|
||||
.default([])
|
||||
.transform((arr) => arr.flat()),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
|
||||
export type WorkflowJob = z.infer<typeof WorkflowJobSchema>;
|
||||
export type WorkflowJobDetail = z.infer<typeof WorkflowJobDetailSchema>;
|
||||
export type WorkflowExecutionError = z.infer<typeof WorkflowExecutionErrorSchema>;
|
||||
export type WorkflowExecutionLog = z.infer<typeof WorkflowExecutionLogSchema>;
|
||||
export type WorkflowTaskExecution = z.infer<typeof WorkflowTaskExecutionSchema>;
|
||||
export type WorkflowExecutionPage = z.infer<typeof WorkflowExecutionPageSchema>;
|
||||
@@ -0,0 +1,209 @@
|
||||
import { z } from "zod";
|
||||
|
||||
// ── 工作流任务节点(递归、按类型区分)─────────────────────────────────────────
|
||||
|
||||
export const BaseTaskSchema = z.object({
|
||||
name: z.string(),
|
||||
type: z.string(),
|
||||
label: z.string(),
|
||||
desc: z.string().optional(),
|
||||
groupName: z.string(),
|
||||
orderIndex: z.number(),
|
||||
levelIndex: z.array(z.number()),
|
||||
status: z.string(),
|
||||
displayName: z.string().optional(),
|
||||
});
|
||||
|
||||
// 任务节点运行时类型(用于递归结构中的类型标注)
|
||||
export interface WorkflowTask {
|
||||
name: string;
|
||||
type: string;
|
||||
label?: string;
|
||||
desc?: string;
|
||||
groupName: string;
|
||||
orderIndex: number;
|
||||
levelIndex: number[];
|
||||
status: string;
|
||||
displayName?: string;
|
||||
tasks?: WorkflowTask[];
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
// 条件/过滤的递归结构:condition / combineFilters
|
||||
export const FilterConditionSchema = z.object({
|
||||
key: z.string(),
|
||||
value: z.any().optional(),
|
||||
compare: z.string(),
|
||||
});
|
||||
|
||||
export const FilterGroupSchema: z.ZodType<any> = z.lazy(() =>
|
||||
z.object({
|
||||
filters: z.array(z.union([FilterConditionSchema, FilterGroupSchema])),
|
||||
condition: z.string(),
|
||||
})
|
||||
);
|
||||
|
||||
// 字段映射条目的两种形态:只读 key 或 key-value 映射(保留 value 及其余配置项)
|
||||
export const FieldMappingSchema = z.object({
|
||||
key: z.string(),
|
||||
value: z.any().optional(),
|
||||
}).passthrough();
|
||||
|
||||
// 错误处理配置
|
||||
export const OnErrorSchema = z.object({
|
||||
defaultAction: z.string(),
|
||||
});
|
||||
|
||||
// ── 控制节点 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export const ConditionTaskSchema: z.ZodType<WorkflowTask> = BaseTaskSchema.extend({
|
||||
type: z.literal("condition"),
|
||||
tasksMaxLevel: z.number(),
|
||||
combineFilters: FilterGroupSchema,
|
||||
tasks: z.lazy(() => z.array(WorkflowTaskSchema)),
|
||||
});
|
||||
|
||||
export const EveryTaskSchema: z.ZodType<WorkflowTask> = BaseTaskSchema.extend({
|
||||
type: z.literal("every"),
|
||||
batch: z.boolean(),
|
||||
batchSize: z.number().optional(),
|
||||
mode: z.string(),
|
||||
list: z.string(),
|
||||
filters: z.array(z.any()),
|
||||
tasksMaxLevel: z.number(),
|
||||
tasks: z.lazy(() => z.array(WorkflowTaskSchema)),
|
||||
});
|
||||
|
||||
// ── 触发器节点 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export const WebhookTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("webhook"),
|
||||
sampleId: z.string(),
|
||||
params: z.array(z.object({ key: z.string(), value: z.string() })),
|
||||
urlPath: z.string(),
|
||||
});
|
||||
|
||||
// ── 动作节点 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export const StopTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("stop"),
|
||||
});
|
||||
|
||||
export const HttpTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("http"),
|
||||
method: z.string(),
|
||||
url: z.string(),
|
||||
bodyType: z.string().optional(),
|
||||
bodyRaw: z.record(z.string(), z.any()).optional(),
|
||||
header: z.array(z.any()),
|
||||
params: z.array(z.object({ key: z.string(), value: z.string() })),
|
||||
successCode: z.array(z.string()),
|
||||
sampleData: z.record(z.string(), z.any()).optional(),
|
||||
});
|
||||
|
||||
export const FlowDetailTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("flow-detail"),
|
||||
specificationId: z.string(),
|
||||
mapping: z.union([
|
||||
z.boolean(),
|
||||
z.array(z.object({ key: z.string(), value: z.string() })),
|
||||
]),
|
||||
flowCode: z.string(),
|
||||
});
|
||||
|
||||
export const CodeTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("code"),
|
||||
code: z.string(),
|
||||
});
|
||||
|
||||
export const CodeJs2TaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("code-js2"),
|
||||
code: z.string(),
|
||||
mapping: z.array(z.object({ key: z.string(), value: z.string() })).optional(),
|
||||
onError: OnErrorSchema.optional(),
|
||||
});
|
||||
|
||||
export const EkuaibaoDatalinkFilterTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("ekuaibao-datalink-filter"),
|
||||
mode: z.string(),
|
||||
entityId: z.string(),
|
||||
fields: z.array(FieldMappingSchema),
|
||||
filters: z.array(z.any()),
|
||||
selectFields: z.array(z.any()),
|
||||
combineFilters: FilterGroupSchema,
|
||||
orderKey: z.string(),
|
||||
orderMode: z.string(),
|
||||
limitCount: z.string(),
|
||||
onError: OnErrorSchema.optional(),
|
||||
});
|
||||
|
||||
export const EkuaibaoDatalinkCreateTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("ekuaibao-datalink-create"),
|
||||
mode: z.string(),
|
||||
entityId: z.string(),
|
||||
fields: z.array(FieldMappingSchema),
|
||||
filters: z.array(z.any()),
|
||||
combineFilters: FilterGroupSchema,
|
||||
});
|
||||
|
||||
export const DataConvertTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("data-convert"),
|
||||
mode: z.string(),
|
||||
path: z.array(z.string()),
|
||||
fields: z.array(z.object({ key: z.string(), value: z.string() })),
|
||||
onError: OnErrorSchema.optional(),
|
||||
subType: z.string(),
|
||||
itemType: z.string(),
|
||||
targetType: z.string(),
|
||||
feeFormType: z.string(),
|
||||
});
|
||||
|
||||
export const FlowCreateTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("flow-create-task"),
|
||||
specificationId: z.string(),
|
||||
formState: z.string(),
|
||||
form: z.record(z.string(), z.string()),
|
||||
details: z.record(z.string(), z.any()),
|
||||
onError: OnErrorSchema.optional(),
|
||||
});
|
||||
|
||||
export const DynamicDelayTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("task-dynamic-delay"),
|
||||
sleepTime: z.union([z.number(), z.string()]).optional(),
|
||||
});
|
||||
|
||||
// 兜底节点:遇到未收录类型时仍保留全部字段
|
||||
export const UnknownTaskSchema = z
|
||||
.object({
|
||||
name: z.string().default("task"),
|
||||
type: z.string(),
|
||||
label: z.string().optional(),
|
||||
desc: z.string().optional(),
|
||||
groupName: z.string().default("trigger"),
|
||||
orderIndex: z.number().default(0),
|
||||
levelIndex: z.array(z.number()).default([0]),
|
||||
status: z.string().default("active"),
|
||||
displayName: z.string().optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
// 统一任务节点类型
|
||||
export const WorkflowTaskSchema: z.ZodType<WorkflowTask> = z.union([
|
||||
WebhookTaskSchema,
|
||||
ConditionTaskSchema,
|
||||
EveryTaskSchema,
|
||||
StopTaskSchema,
|
||||
HttpTaskSchema,
|
||||
FlowDetailTaskSchema,
|
||||
CodeTaskSchema,
|
||||
CodeJs2TaskSchema,
|
||||
EkuaibaoDatalinkFilterTaskSchema,
|
||||
EkuaibaoDatalinkCreateTaskSchema,
|
||||
DataConvertTaskSchema,
|
||||
FlowCreateTaskSchema,
|
||||
DynamicDelayTaskSchema,
|
||||
UnknownTaskSchema,
|
||||
]);
|
||||
|
||||
|
||||
export type FilterGroup = z.infer<typeof FilterGroupSchema>;
|
||||
@@ -0,0 +1,176 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { WorkflowTaskSchema } from "./nodes.js";
|
||||
|
||||
// ── 工作流(EASO Pipeline)───────────────────────────────────
|
||||
|
||||
export const WorkflowSchema = z.object({
|
||||
id: z.string(),
|
||||
pipelineName: z.string().default(""),
|
||||
state: z.number().default(0),
|
||||
runningCount: z.number().default(0),
|
||||
errorCount: z.number().default(0),
|
||||
updateTime: z.string().default(""),
|
||||
updateUser: z.string().nullable().optional(),
|
||||
tasks: z.array(WorkflowTaskSchema).default([]),
|
||||
desc: z.string().nullable().optional(),
|
||||
customDesc: z.string().nullable().optional(),
|
||||
});
|
||||
|
||||
export const WorkflowPageSchema = z.object({
|
||||
pipelineNum: z.number().default(0),
|
||||
runningNum: z.number().default(0),
|
||||
allRunCount: z.number().default(0),
|
||||
errorCount: z.number().default(0),
|
||||
number: z.number().default(1),
|
||||
size: z.number().default(20),
|
||||
totalPages: z.number().default(0),
|
||||
totalItems: z.number().default(0),
|
||||
pipelineList: z.array(WorkflowSchema).default([]),
|
||||
});
|
||||
|
||||
export const WorkflowStatsSchema = z.object({
|
||||
total: z.number().default(0),
|
||||
completed: z.number().default(0),
|
||||
failed: z.number().default(0),
|
||||
started: z.number().default(0),
|
||||
pipelineOpenCount: z.number().default(0),
|
||||
pipelineCloseCount: z.number().default(0),
|
||||
pipelineAllCount: z.number().default(0),
|
||||
});
|
||||
|
||||
export const WorkflowAlarmSchema = z.object({
|
||||
alarmUser: z.array(z.any()).default([]),
|
||||
alarmType: z.array(z.string()).default([]),
|
||||
active: z.boolean().default(true),
|
||||
alarmScope: z.string().default(""),
|
||||
});
|
||||
|
||||
export const WorkflowDetailSchema = z.object({
|
||||
id: z.string(),
|
||||
label: z.string().default(""),
|
||||
desc: z.string().nullable().optional(),
|
||||
customDesc: z.string().nullable().optional(),
|
||||
state: z.coerce.number().default(0),
|
||||
debugState: z.coerce.number().default(0),
|
||||
runTimes: z.coerce.number().default(0),
|
||||
errorTimes: z.coerce.number().default(0),
|
||||
updateTime: z.string().default(""),
|
||||
updateUser: z.string().nullable().optional(),
|
||||
staffName: z.string().nullable().optional(),
|
||||
version: z.string().default(""),
|
||||
dataLimit: z.coerce.number().default(20),
|
||||
source: z.coerce.number().default(0),
|
||||
queueJobs: z.boolean().default(false),
|
||||
tasksVersion: z.coerce.number().default(0),
|
||||
tasks: z.array(WorkflowTaskSchema).default([]),
|
||||
alarm: z.union([
|
||||
WorkflowAlarmSchema,
|
||||
z.string().transform((val) => {
|
||||
try {
|
||||
const parsed = JSON.parse(val);
|
||||
return WorkflowAlarmSchema.safeParse(parsed).data ?? undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}),
|
||||
z.null(),
|
||||
]).optional(),
|
||||
inputs: z.array(z.object({ key: z.string(), value: z.any() })).optional(),
|
||||
"$snapshot": z.array(z.object({ key: z.string(), value: z.string() })).optional(),
|
||||
}).passthrough();
|
||||
|
||||
export const WorkflowSnapshotSchema = z.object({
|
||||
id: z.string(),
|
||||
pipelineId: z.string(),
|
||||
corporationId: z.string().default(""),
|
||||
platformId: z.string().default(""),
|
||||
triggerKey: z.string().default(""),
|
||||
label: z.string().default(""),
|
||||
tasks: z.array(WorkflowTaskSchema).nullable().optional(),
|
||||
inputs: z.union([z.string(), z.array(z.any())]).default("[]"),
|
||||
outputs: z.union([z.string(), z.array(z.any())]).default("[]"),
|
||||
retry: z.number().default(0),
|
||||
state: z.number().default(0),
|
||||
debugState: z.number().default(0),
|
||||
staffId: z.string().nullable().optional(),
|
||||
staffName: z.string().nullable().optional(),
|
||||
createTime: z.string().default(""),
|
||||
updateTime: z.string().default(""),
|
||||
version: z.string().default(""),
|
||||
}).passthrough();
|
||||
|
||||
export const WorkflowSnapshotPageSchema = z.object({
|
||||
number: z.number().default(1),
|
||||
size: z.number().default(10),
|
||||
totalPages: z.number().default(0),
|
||||
totalItems: z.number().default(0),
|
||||
items: z.array(WorkflowSnapshotSchema).default([]),
|
||||
});
|
||||
|
||||
export const WorkflowLogItemSchema = z.record(z.string(), z.any());
|
||||
|
||||
export const WorkflowLogPageSchema = z.object({
|
||||
number: z.number().default(1),
|
||||
size: z.number().default(10),
|
||||
totalPages: z.number().default(0),
|
||||
totalItems: z.number().default(0),
|
||||
items: z.array(WorkflowLogItemSchema).default([]),
|
||||
executeCount: z.number().default(0),
|
||||
successCount: z.number().default(0),
|
||||
errorCount: z.number().default(0),
|
||||
jobList: z.array(WorkflowLogItemSchema).default([]),
|
||||
}).passthrough();
|
||||
|
||||
export const WorkflowChargeSchema = z.object({
|
||||
corporationId: z.string().default(""),
|
||||
status: z.string().default(""),
|
||||
orderType: z.string().default(""),
|
||||
total: z.number().default(0),
|
||||
used: z.number().default(0),
|
||||
remaining: z.number().default(0),
|
||||
});
|
||||
|
||||
// ── 工作流状态 ────────────────────────────────────────────────────────────────
|
||||
|
||||
export const WorkflowStateSchema = z.union([z.literal(0), z.literal(1)]);
|
||||
|
||||
// ── 跨应用聚合结果类型 ───────────────────────────────────────────────────────
|
||||
|
||||
export const WorkflowSummarySchema = WorkflowSchema.extend({
|
||||
platformId: z.string(),
|
||||
platformName: z.string(),
|
||||
});
|
||||
|
||||
export const WorkflowListAllErrorSchema = z.object({
|
||||
platformId: z.string(),
|
||||
platformName: z.string(),
|
||||
error: z.string(),
|
||||
});
|
||||
|
||||
export const TaskMatchSchema = z.object({
|
||||
taskName: z.string(),
|
||||
taskType: z.string(),
|
||||
levelIndex: z.array(z.number()),
|
||||
});
|
||||
|
||||
export const WorkflowWithMatchesSchema = WorkflowSummarySchema.extend({
|
||||
matchedTasks: z.array(TaskMatchSchema),
|
||||
});
|
||||
|
||||
|
||||
export type WorkflowState = z.infer<typeof WorkflowStateSchema>;
|
||||
export type Workflow = z.infer<typeof WorkflowSchema>;
|
||||
export type WorkflowPage = z.infer<typeof WorkflowPageSchema>;
|
||||
export type WorkflowStats = z.infer<typeof WorkflowStatsSchema>;
|
||||
export type WorkflowAlarm = z.infer<typeof WorkflowAlarmSchema>;
|
||||
export type WorkflowDetail = z.infer<typeof WorkflowDetailSchema>;
|
||||
export type WorkflowSnapshot = z.infer<typeof WorkflowSnapshotSchema>;
|
||||
export type WorkflowSnapshotPage = z.infer<typeof WorkflowSnapshotPageSchema>;
|
||||
export type WorkflowLogItem = z.infer<typeof WorkflowLogItemSchema>;
|
||||
export type WorkflowLogPage = z.infer<typeof WorkflowLogPageSchema>;
|
||||
export type WorkflowCharge = z.infer<typeof WorkflowChargeSchema>;
|
||||
export type WorkflowSummary = z.infer<typeof WorkflowSummarySchema>;
|
||||
export type WorkflowListAllError = z.infer<typeof WorkflowListAllErrorSchema>;
|
||||
export type TaskMatch = z.infer<typeof TaskMatchSchema>;
|
||||
export type WorkflowWithMatches = z.infer<typeof WorkflowWithMatchesSchema>;
|
||||
@@ -1,748 +1,10 @@
|
||||
import { z } from "zod";
|
||||
|
||||
// ── 工作流任务节点(递归、按类型区分)─────────────────────────────────────────
|
||||
|
||||
export const BaseTaskSchema = z.object({
|
||||
name: z.string(),
|
||||
type: z.string(),
|
||||
label: z.string(),
|
||||
desc: z.string().optional(),
|
||||
groupName: z.string(),
|
||||
orderIndex: z.number(),
|
||||
levelIndex: z.array(z.number()),
|
||||
status: z.string(),
|
||||
displayName: z.string().optional(),
|
||||
});
|
||||
|
||||
// 任务节点运行时类型(用于递归结构中的类型标注)
|
||||
export interface WorkflowTask {
|
||||
name: string;
|
||||
type: string;
|
||||
label?: string;
|
||||
desc?: string;
|
||||
groupName: string;
|
||||
orderIndex: number;
|
||||
levelIndex: number[];
|
||||
status: string;
|
||||
displayName?: string;
|
||||
tasks?: WorkflowTask[];
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
// 条件/过滤的递归结构:condition / combineFilters
|
||||
export const FilterConditionSchema = z.object({
|
||||
key: z.string(),
|
||||
value: z.any().optional(),
|
||||
compare: z.string(),
|
||||
});
|
||||
|
||||
export const FilterGroupSchema: z.ZodType<any> = z.lazy(() =>
|
||||
z.object({
|
||||
filters: z.array(z.union([FilterConditionSchema, FilterGroupSchema])),
|
||||
condition: z.string(),
|
||||
})
|
||||
);
|
||||
|
||||
// 字段映射条目的两种形态:只读 key 或 key-value 映射(保留 value 及其余配置项)
|
||||
export const FieldMappingSchema = z.object({
|
||||
key: z.string(),
|
||||
value: z.any().optional(),
|
||||
}).passthrough();
|
||||
|
||||
// 错误处理配置
|
||||
export const OnErrorSchema = z.object({
|
||||
defaultAction: z.string(),
|
||||
});
|
||||
|
||||
// ── 控制节点 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export const ConditionTaskSchema: z.ZodType<WorkflowTask> = BaseTaskSchema.extend({
|
||||
type: z.literal("condition"),
|
||||
tasksMaxLevel: z.number(),
|
||||
combineFilters: FilterGroupSchema,
|
||||
tasks: z.lazy(() => z.array(WorkflowTaskSchema)),
|
||||
});
|
||||
|
||||
export const EveryTaskSchema: z.ZodType<WorkflowTask> = BaseTaskSchema.extend({
|
||||
type: z.literal("every"),
|
||||
batch: z.boolean(),
|
||||
batchSize: z.number().optional(),
|
||||
mode: z.string(),
|
||||
list: z.string(),
|
||||
filters: z.array(z.any()),
|
||||
tasksMaxLevel: z.number(),
|
||||
tasks: z.lazy(() => z.array(WorkflowTaskSchema)),
|
||||
});
|
||||
|
||||
// ── 触发器节点 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export const WebhookTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("webhook"),
|
||||
sampleId: z.string(),
|
||||
params: z.array(z.object({ key: z.string(), value: z.string() })),
|
||||
urlPath: z.string(),
|
||||
});
|
||||
|
||||
// ── 动作节点 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export const StopTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("stop"),
|
||||
});
|
||||
|
||||
export const HttpTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("http"),
|
||||
method: z.string(),
|
||||
url: z.string(),
|
||||
bodyType: z.string().optional(),
|
||||
bodyRaw: z.record(z.string(), z.any()).optional(),
|
||||
header: z.array(z.any()),
|
||||
params: z.array(z.object({ key: z.string(), value: z.string() })),
|
||||
successCode: z.array(z.string()),
|
||||
sampleData: z.record(z.string(), z.any()).optional(),
|
||||
});
|
||||
|
||||
export const FlowDetailTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("flow-detail"),
|
||||
specificationId: z.string(),
|
||||
mapping: z.union([
|
||||
z.boolean(),
|
||||
z.array(z.object({ key: z.string(), value: z.string() })),
|
||||
]),
|
||||
flowCode: z.string(),
|
||||
});
|
||||
|
||||
export const CodeTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("code"),
|
||||
code: z.string(),
|
||||
});
|
||||
|
||||
export const CodeJs2TaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("code-js2"),
|
||||
code: z.string(),
|
||||
mapping: z.array(z.object({ key: z.string(), value: z.string() })).optional(),
|
||||
onError: OnErrorSchema.optional(),
|
||||
});
|
||||
|
||||
export const EkuaibaoDatalinkFilterTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("ekuaibao-datalink-filter"),
|
||||
mode: z.string(),
|
||||
entityId: z.string(),
|
||||
fields: z.array(FieldMappingSchema),
|
||||
filters: z.array(z.any()),
|
||||
selectFields: z.array(z.any()),
|
||||
combineFilters: FilterGroupSchema,
|
||||
orderKey: z.string(),
|
||||
orderMode: z.string(),
|
||||
limitCount: z.string(),
|
||||
onError: OnErrorSchema.optional(),
|
||||
});
|
||||
|
||||
export const EkuaibaoDatalinkCreateTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("ekuaibao-datalink-create"),
|
||||
mode: z.string(),
|
||||
entityId: z.string(),
|
||||
fields: z.array(FieldMappingSchema),
|
||||
filters: z.array(z.any()),
|
||||
combineFilters: FilterGroupSchema,
|
||||
});
|
||||
|
||||
export const DataConvertTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("data-convert"),
|
||||
mode: z.string(),
|
||||
path: z.array(z.string()),
|
||||
fields: z.array(z.object({ key: z.string(), value: z.string() })),
|
||||
onError: OnErrorSchema.optional(),
|
||||
subType: z.string(),
|
||||
itemType: z.string(),
|
||||
targetType: z.string(),
|
||||
feeFormType: z.string(),
|
||||
});
|
||||
|
||||
export const FlowCreateTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("flow-create-task"),
|
||||
specificationId: z.string(),
|
||||
formState: z.string(),
|
||||
form: z.record(z.string(), z.string()),
|
||||
details: z.record(z.string(), z.any()),
|
||||
onError: OnErrorSchema.optional(),
|
||||
});
|
||||
|
||||
export const DynamicDelayTaskSchema = BaseTaskSchema.extend({
|
||||
type: z.literal("task-dynamic-delay"),
|
||||
sleepTime: z.union([z.number(), z.string()]).optional(),
|
||||
});
|
||||
|
||||
// 兜底节点:遇到未收录类型时仍保留全部字段
|
||||
export const UnknownTaskSchema = z
|
||||
.object({
|
||||
name: z.string().default("task"),
|
||||
type: z.string(),
|
||||
label: z.string().optional(),
|
||||
desc: z.string().optional(),
|
||||
groupName: z.string().default("trigger"),
|
||||
orderIndex: z.number().default(0),
|
||||
levelIndex: z.array(z.number()).default([0]),
|
||||
status: z.string().default("active"),
|
||||
displayName: z.string().optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
// 统一任务节点类型
|
||||
export const WorkflowTaskSchema: z.ZodType<WorkflowTask> = z.union([
|
||||
WebhookTaskSchema,
|
||||
ConditionTaskSchema,
|
||||
EveryTaskSchema,
|
||||
StopTaskSchema,
|
||||
HttpTaskSchema,
|
||||
FlowDetailTaskSchema,
|
||||
CodeTaskSchema,
|
||||
CodeJs2TaskSchema,
|
||||
EkuaibaoDatalinkFilterTaskSchema,
|
||||
EkuaibaoDatalinkCreateTaskSchema,
|
||||
DataConvertTaskSchema,
|
||||
FlowCreateTaskSchema,
|
||||
DynamicDelayTaskSchema,
|
||||
UnknownTaskSchema,
|
||||
]);
|
||||
|
||||
// ── 工作流(EASO Pipeline)───────────────────────────────────
|
||||
|
||||
export const WorkflowSchema = z.object({
|
||||
id: z.string(),
|
||||
pipelineName: z.string().default(""),
|
||||
state: z.number().default(0),
|
||||
runningCount: z.number().default(0),
|
||||
errorCount: z.number().default(0),
|
||||
updateTime: z.string().default(""),
|
||||
updateUser: z.string().nullable().optional(),
|
||||
tasks: z.array(WorkflowTaskSchema).default([]),
|
||||
desc: z.string().nullable().optional(),
|
||||
customDesc: z.string().nullable().optional(),
|
||||
});
|
||||
|
||||
export const WorkflowPageSchema = z.object({
|
||||
pipelineNum: z.number().default(0),
|
||||
runningNum: z.number().default(0),
|
||||
allRunCount: z.number().default(0),
|
||||
errorCount: z.number().default(0),
|
||||
number: z.number().default(1),
|
||||
size: z.number().default(20),
|
||||
totalPages: z.number().default(0),
|
||||
totalItems: z.number().default(0),
|
||||
pipelineList: z.array(WorkflowSchema).default([]),
|
||||
});
|
||||
|
||||
export const WorkflowStatsSchema = z.object({
|
||||
total: z.number().default(0),
|
||||
completed: z.number().default(0),
|
||||
failed: z.number().default(0),
|
||||
started: z.number().default(0),
|
||||
pipelineOpenCount: z.number().default(0),
|
||||
pipelineCloseCount: z.number().default(0),
|
||||
pipelineAllCount: z.number().default(0),
|
||||
});
|
||||
|
||||
export const WorkflowAlarmSchema = z.object({
|
||||
alarmUser: z.array(z.any()).default([]),
|
||||
alarmType: z.array(z.string()).default([]),
|
||||
active: z.boolean().default(true),
|
||||
alarmScope: z.string().default(""),
|
||||
});
|
||||
|
||||
export const WorkflowDetailSchema = z.object({
|
||||
id: z.string(),
|
||||
label: z.string().default(""),
|
||||
desc: z.string().nullable().optional(),
|
||||
customDesc: z.string().nullable().optional(),
|
||||
state: z.coerce.number().default(0),
|
||||
debugState: z.coerce.number().default(0),
|
||||
runTimes: z.coerce.number().default(0),
|
||||
errorTimes: z.coerce.number().default(0),
|
||||
updateTime: z.string().default(""),
|
||||
updateUser: z.string().nullable().optional(),
|
||||
staffName: z.string().nullable().optional(),
|
||||
version: z.string().default(""),
|
||||
dataLimit: z.coerce.number().default(20),
|
||||
source: z.coerce.number().default(0),
|
||||
queueJobs: z.boolean().default(false),
|
||||
tasksVersion: z.coerce.number().default(0),
|
||||
tasks: z.array(WorkflowTaskSchema).default([]),
|
||||
alarm: z.union([
|
||||
WorkflowAlarmSchema,
|
||||
z.string().transform((val) => {
|
||||
try {
|
||||
const parsed = JSON.parse(val);
|
||||
return WorkflowAlarmSchema.safeParse(parsed).data ?? undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}),
|
||||
z.null(),
|
||||
]).optional(),
|
||||
inputs: z.array(z.object({ key: z.string(), value: z.any() })).optional(),
|
||||
"$snapshot": z.array(z.object({ key: z.string(), value: z.string() })).optional(),
|
||||
}).passthrough();
|
||||
|
||||
export const WorkflowSnapshotSchema = z.object({
|
||||
id: z.string(),
|
||||
pipelineId: z.string(),
|
||||
corporationId: z.string().default(""),
|
||||
platformId: z.string().default(""),
|
||||
triggerKey: z.string().default(""),
|
||||
label: z.string().default(""),
|
||||
tasks: z.array(WorkflowTaskSchema).nullable().optional(),
|
||||
inputs: z.union([z.string(), z.array(z.any())]).default("[]"),
|
||||
outputs: z.union([z.string(), z.array(z.any())]).default("[]"),
|
||||
retry: z.number().default(0),
|
||||
state: z.number().default(0),
|
||||
debugState: z.number().default(0),
|
||||
staffId: z.string().nullable().optional(),
|
||||
staffName: z.string().nullable().optional(),
|
||||
createTime: z.string().default(""),
|
||||
updateTime: z.string().default(""),
|
||||
version: z.string().default(""),
|
||||
}).passthrough();
|
||||
|
||||
export const WorkflowSnapshotPageSchema = z.object({
|
||||
number: z.number().default(1),
|
||||
size: z.number().default(10),
|
||||
totalPages: z.number().default(0),
|
||||
totalItems: z.number().default(0),
|
||||
items: z.array(WorkflowSnapshotSchema).default([]),
|
||||
});
|
||||
|
||||
export const WorkflowLogItemSchema = z.record(z.string(), z.any());
|
||||
|
||||
export const WorkflowLogPageSchema = z.object({
|
||||
number: z.number().default(1),
|
||||
size: z.number().default(10),
|
||||
totalPages: z.number().default(0),
|
||||
totalItems: z.number().default(0),
|
||||
items: z.array(WorkflowLogItemSchema).default([]),
|
||||
executeCount: z.number().default(0),
|
||||
successCount: z.number().default(0),
|
||||
errorCount: z.number().default(0),
|
||||
jobList: z.array(WorkflowLogItemSchema).default([]),
|
||||
}).passthrough();
|
||||
|
||||
export const WorkflowChargeSchema = z.object({
|
||||
corporationId: z.string().default(""),
|
||||
status: z.string().default(""),
|
||||
orderType: z.string().default(""),
|
||||
total: z.number().default(0),
|
||||
used: z.number().default(0),
|
||||
remaining: z.number().default(0),
|
||||
});
|
||||
|
||||
// ── 运行中的任务与单次 Job 执行详情 ──────────────────────────────────────────
|
||||
|
||||
export const WorkflowJobSchema = z
|
||||
.object({
|
||||
id: z.string().optional(),
|
||||
jobId: z.string().optional(),
|
||||
pipelineId: z.string().nullish().default(""),
|
||||
jobName: z.string().nullish(),
|
||||
status: z.string().default(""),
|
||||
runType: z.string().default(""),
|
||||
executeTime: z.union([z.string(), z.number()]).nullish(),
|
||||
startTime: z.union([z.string(), z.number()]).nullish(),
|
||||
endTime: z.union([z.string(), z.number()]).nullish(),
|
||||
triggerType: z.string().default(""),
|
||||
successTaskCount: z.number().nullish().default(0),
|
||||
errorTaskCount: z.number().nullish().default(0),
|
||||
hasError: z.union([z.string(), z.boolean()]).nullish(),
|
||||
state: z.union([z.number(), z.string()]).nullish(),
|
||||
autoPublish: z.boolean().nullish(),
|
||||
version: z.string().nullish(),
|
||||
snapshotId: z.string().nullish(),
|
||||
})
|
||||
.passthrough()
|
||||
.transform((val) => ({
|
||||
...val,
|
||||
id: val.id || val.jobId || "",
|
||||
jobId: val.jobId || val.id || "",
|
||||
pipelineId: val.pipelineId || "",
|
||||
}));
|
||||
|
||||
export const WorkflowJobDetailSchema = z
|
||||
.object({
|
||||
id: z.string(),
|
||||
pipelineId: z.string().default(""),
|
||||
label: z.string().default(""),
|
||||
status: z.string().default(""),
|
||||
runType: z.string().default(""),
|
||||
startTime: z.union([z.number(), z.string()]).nullable().optional(),
|
||||
endTime: z.union([z.number(), z.string()]).nullable().optional(),
|
||||
createTime: z.union([z.number(), z.string()]).nullable().optional(),
|
||||
inputs: z.any().optional(),
|
||||
outputs: z.any().optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export const WorkflowExecutionErrorSchema = z
|
||||
.object({
|
||||
message: z.string().default(""),
|
||||
stackTrace: z.array(z.string()).nullish().transform((v) => v ?? []),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export const WorkflowExecutionLogSchema = z
|
||||
.object({
|
||||
id: z.union([z.string(), z.number()]).optional(),
|
||||
level: z.string().default("INFO"),
|
||||
message: z.string().default(""),
|
||||
createAt: z.union([z.string(), z.number()]).optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export const WorkflowTaskExecutionSchema = z
|
||||
.object({
|
||||
id: z.string(),
|
||||
parentId: z.string().nullable().optional(),
|
||||
jobId: z.string().optional(),
|
||||
pipelineId: z.string().optional(),
|
||||
name: z.string().optional(),
|
||||
displayName: z.string().nullable().optional(),
|
||||
label: z.string().nullable().optional(),
|
||||
type: z.string().default(""),
|
||||
orderIndex: z.number().optional(),
|
||||
levelIndex: z.array(z.number()).optional(),
|
||||
status: z.string().default(""),
|
||||
executionTime: z.number().optional(),
|
||||
startTime: z.union([z.number(), z.string()]).nullable().optional(),
|
||||
endTime: z.union([z.number(), z.string()]).nullable().optional(),
|
||||
createTime: z.union([z.number(), z.string()]).nullable().optional(),
|
||||
currentLoopPath: z.string().nullable().optional(),
|
||||
error: WorkflowExecutionErrorSchema.nullable().optional(),
|
||||
output: z.any().optional(),
|
||||
form: z.union([z.record(z.string(), z.any()), z.array(z.any())]).nullable().optional(),
|
||||
details: z.record(z.string(), z.any()).nullable().optional(),
|
||||
executionLogs: z.array(z.any()).optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export const WorkflowExecutionPageSchema = z
|
||||
.object({
|
||||
number: z.number().default(1),
|
||||
size: z.number().default(20),
|
||||
totalPages: z.number().default(0),
|
||||
totalItems: z.number().default(0),
|
||||
items: z
|
||||
.array(z.union([WorkflowTaskExecutionSchema, z.array(WorkflowTaskExecutionSchema)]))
|
||||
.default([])
|
||||
.transform((arr) => arr.flat()),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
// ── DSL 配置 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export const WorkflowDslSchema = z.object({
|
||||
id: z.string().optional(),
|
||||
name: z.string().default(""),
|
||||
type: z.string().default(""),
|
||||
config: z.record(z.string(), z.any()).default({}),
|
||||
});
|
||||
|
||||
export const WorkflowNodeDefinitionSchema = z
|
||||
.object({
|
||||
id: z.string().nullable().optional(),
|
||||
name: z.string().default(""),
|
||||
type: z.string().default(""),
|
||||
groupName: z.string().nullable().optional(),
|
||||
icon: z.string().nullable().optional(),
|
||||
iconColor: z.string().nullable().optional(),
|
||||
remark: z.string().nullable().optional(),
|
||||
platform: z.string().nullable().optional(),
|
||||
version: z.number().nullable().optional(),
|
||||
$json: z.string().nullable().optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export type WorkflowNodeDefinition = z.infer<typeof WorkflowNodeDefinitionSchema>;
|
||||
|
||||
export const WorkflowDslCatalogSchema = z
|
||||
.object({
|
||||
action: z.array(WorkflowNodeDefinitionSchema).default([]),
|
||||
control: z.array(WorkflowNodeDefinitionSchema).default([]),
|
||||
trigger: z.array(WorkflowNodeDefinitionSchema).default([]),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export type WorkflowDslCatalog = z.infer<typeof WorkflowDslCatalogSchema>;
|
||||
|
||||
export interface AvailableWorkflowNodes {
|
||||
allTypes: Set<string>;
|
||||
actionNodes: WorkflowNodeDefinition[];
|
||||
controlNodes: WorkflowNodeDefinition[];
|
||||
triggerNodes: WorkflowNodeDefinition[];
|
||||
}
|
||||
|
||||
export interface GrantWorkflowNodesOptions {
|
||||
nodes: string[];
|
||||
password?: string;
|
||||
}
|
||||
|
||||
export interface GrantWorkflowNodesResult {
|
||||
success: boolean;
|
||||
saved: string[];
|
||||
skipped: string[];
|
||||
rawMessage: string;
|
||||
}
|
||||
|
||||
// ── 员工 ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
export const StaffSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string().default(""),
|
||||
email: z.string().nullable().optional(),
|
||||
department: z.string().nullable().optional(),
|
||||
});
|
||||
|
||||
// ── Webhook ──────────────────────────────────────────────────────────────────
|
||||
|
||||
export const WebhookInfoSchema = z.object({
|
||||
id: z.string(),
|
||||
pipelineId: z.string(),
|
||||
url: z.string().default(""),
|
||||
active: z.boolean().default(true),
|
||||
});
|
||||
|
||||
// ── 工作流状态 ────────────────────────────────────────────────────────────────
|
||||
|
||||
export const WorkflowStateSchema = z.union([z.literal(0), z.literal(1)]);
|
||||
|
||||
// ── 测试/采样数据 ─────────────────────────────────────────────────────────────
|
||||
|
||||
export const WorkflowSampleDataSchema = z.record(z.string(), z.any());
|
||||
|
||||
// ── 跨应用聚合结果类型 ───────────────────────────────────────────────────────
|
||||
|
||||
export const WorkflowSummarySchema = WorkflowSchema.extend({
|
||||
platformId: z.string(),
|
||||
platformName: z.string(),
|
||||
});
|
||||
|
||||
export const WorkflowListAllErrorSchema = z.object({
|
||||
platformId: z.string(),
|
||||
platformName: z.string(),
|
||||
error: z.string(),
|
||||
});
|
||||
|
||||
export const TaskMatchSchema = z.object({
|
||||
taskName: z.string(),
|
||||
taskType: z.string(),
|
||||
levelIndex: z.array(z.number()),
|
||||
});
|
||||
|
||||
export const WorkflowWithMatchesSchema = WorkflowSummarySchema.extend({
|
||||
matchedTasks: z.array(TaskMatchSchema),
|
||||
});
|
||||
|
||||
// 工作流共享模型出口;具体定义按职责拆分。
|
||||
// ── 类型导出 ──────────────────────────────────────────────────────────────────
|
||||
|
||||
export type FilterGroup = z.infer<typeof FilterGroupSchema>;
|
||||
export type WorkflowState = z.infer<typeof WorkflowStateSchema>;
|
||||
export type Workflow = z.infer<typeof WorkflowSchema>;
|
||||
export type WorkflowPage = z.infer<typeof WorkflowPageSchema>;
|
||||
export type WorkflowStats = z.infer<typeof WorkflowStatsSchema>;
|
||||
export type WorkflowAlarm = z.infer<typeof WorkflowAlarmSchema>;
|
||||
export type WorkflowDetail = z.infer<typeof WorkflowDetailSchema>;
|
||||
export type WorkflowSnapshot = z.infer<typeof WorkflowSnapshotSchema>;
|
||||
export type WorkflowSnapshotPage = z.infer<typeof WorkflowSnapshotPageSchema>;
|
||||
export type WorkflowLogItem = z.infer<typeof WorkflowLogItemSchema>;
|
||||
export type WorkflowLogPage = z.infer<typeof WorkflowLogPageSchema>;
|
||||
export type WorkflowCharge = z.infer<typeof WorkflowChargeSchema>;
|
||||
export type WorkflowJob = z.infer<typeof WorkflowJobSchema>;
|
||||
export type WorkflowJobDetail = z.infer<typeof WorkflowJobDetailSchema>;
|
||||
export type WorkflowExecutionError = z.infer<typeof WorkflowExecutionErrorSchema>;
|
||||
export type WorkflowExecutionLog = z.infer<typeof WorkflowExecutionLogSchema>;
|
||||
export type WorkflowTaskExecution = z.infer<typeof WorkflowTaskExecutionSchema>;
|
||||
export type WorkflowExecutionPage = z.infer<typeof WorkflowExecutionPageSchema>;
|
||||
export type WorkflowDsl = z.infer<typeof WorkflowDslSchema>;
|
||||
export type Staff = z.infer<typeof StaffSchema>;
|
||||
export type WebhookInfo = z.infer<typeof WebhookInfoSchema>;
|
||||
export type WorkflowSampleData = z.infer<typeof WorkflowSampleDataSchema>;
|
||||
export type WorkflowSummary = z.infer<typeof WorkflowSummarySchema>;
|
||||
export type WorkflowListAllError = z.infer<typeof WorkflowListAllErrorSchema>;
|
||||
export type TaskMatch = z.infer<typeof TaskMatchSchema>;
|
||||
export type WorkflowWithMatches = z.infer<typeof WorkflowWithMatchesSchema>;
|
||||
|
||||
// ── 工作流快照与 Job 差异比对模型 ──────────────────────────────────────────
|
||||
|
||||
export interface TaskConfigDiff {
|
||||
taskName: string;
|
||||
displayName?: string;
|
||||
type: string;
|
||||
changeType: "ADDED" | "REMOVED" | "MODIFIED";
|
||||
codeDiff?: {
|
||||
from?: string;
|
||||
to?: string;
|
||||
unifiedDiff?: string;
|
||||
};
|
||||
filterDiff?: {
|
||||
from?: unknown;
|
||||
to?: unknown;
|
||||
};
|
||||
configChanges: Array<{
|
||||
field: string;
|
||||
from?: unknown;
|
||||
to?: unknown;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface WorkflowSnapshotDiff {
|
||||
snapshotA: {
|
||||
id: string;
|
||||
version?: string;
|
||||
updateTime?: string;
|
||||
staffName?: string;
|
||||
};
|
||||
snapshotB: {
|
||||
id: string;
|
||||
version?: string;
|
||||
updateTime?: string;
|
||||
staffName?: string;
|
||||
};
|
||||
addedTasks: string[];
|
||||
removedTasks: string[];
|
||||
modifiedTasks: TaskConfigDiff[];
|
||||
summary: {
|
||||
totalA: number;
|
||||
totalB: number;
|
||||
changedCount: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface NodeExecutionDiff {
|
||||
taskName: string;
|
||||
instanceKey?: string;
|
||||
currentLoopPath?: string;
|
||||
displayName?: string;
|
||||
type?: string;
|
||||
statusA?: string;
|
||||
statusB?: string;
|
||||
durationMsA?: number;
|
||||
durationMsB?: number;
|
||||
errorA?: unknown;
|
||||
errorB?: unknown;
|
||||
inputsDiff?: Array<{
|
||||
field: string;
|
||||
from?: unknown;
|
||||
to?: unknown;
|
||||
}>;
|
||||
outputsDiff?: Array<{
|
||||
field: string;
|
||||
from?: unknown;
|
||||
to?: unknown;
|
||||
}>;
|
||||
diverged: boolean;
|
||||
}
|
||||
|
||||
export interface WorkflowJobDiff {
|
||||
jobA: {
|
||||
id: string;
|
||||
pipelineId?: string;
|
||||
state?: string | number;
|
||||
startTime?: string;
|
||||
durationTime?: number;
|
||||
hasError?: boolean;
|
||||
errorCount?: number;
|
||||
};
|
||||
jobB: {
|
||||
id: string;
|
||||
pipelineId?: string;
|
||||
state?: string | number;
|
||||
startTime?: string;
|
||||
durationTime?: number;
|
||||
hasError?: boolean;
|
||||
errorCount?: number;
|
||||
};
|
||||
nodes: NodeExecutionDiff[];
|
||||
summary: {
|
||||
totalNodesA: number;
|
||||
totalNodesB: number;
|
||||
divergedNodesCount: number;
|
||||
statusDiffCount: number;
|
||||
};
|
||||
}
|
||||
|
||||
// ── 调试数据源与测试结果 ───────────────────────────────────────────────────────
|
||||
|
||||
export const WorkflowDebugSourceItemSchema = z
|
||||
.object({
|
||||
id: z.string(),
|
||||
title: z.string().default(""),
|
||||
flowState: z.string().default(""),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export const WorkflowDebugSourceResultSchema = z
|
||||
.object({
|
||||
type: z.string().default(""),
|
||||
total: z.number().default(0),
|
||||
items: z.array(WorkflowDebugSourceItemSchema).default([]),
|
||||
fields: z.array(z.object({ key: z.string(), label: z.string() })).default([]),
|
||||
label: z.string().default(""),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export type WorkflowDebugSourceItem = z.infer<typeof WorkflowDebugSourceItemSchema>;
|
||||
export type WorkflowDebugSourceResult = z.infer<typeof WorkflowDebugSourceResultSchema>;
|
||||
|
||||
export interface WorkflowTestReport {
|
||||
jobId: string;
|
||||
pipelineId: string;
|
||||
status: string;
|
||||
outcome: "completed" | "failed" | "timed_out" | "incomplete";
|
||||
timedOut: boolean;
|
||||
diagnosticsComplete: boolean;
|
||||
diagnosticsErrors: Array<{ source: string; message: string }>;
|
||||
runType: string;
|
||||
durationTime?: number;
|
||||
targetEntityId: string;
|
||||
triggerCategory?: WorkflowTriggerCategory;
|
||||
triggerType?: string;
|
||||
triggerLabel?: string;
|
||||
executionTree: WorkflowTaskExecution[];
|
||||
failedExecutions: WorkflowTaskExecution[];
|
||||
conditionDiagnoses: import("./branch/types.js").ConditionBranchExplanation[];
|
||||
}
|
||||
|
||||
export * from "./models/nodes.js";
|
||||
export * from "./models/workflow.js";
|
||||
export * from "./models/execution.js";
|
||||
export * from "./models/catalog.js";
|
||||
export * from "./models/debug.js";
|
||||
export * from "./models/comparison.js";
|
||||
// ── 触发器元类型分类与智能路径路由 ───────────────────────────────────────────────
|
||||
|
||||
export { classifyWorkflowTrigger, type WorkflowTriggerCategory } from "./triggers/classification.js";
|
||||
import type { WorkflowTriggerCategory } from "./triggers/classification.js";
|
||||
|
||||
// ── Webhook 数据样本 (Sample Data) ─────────────────────────────────────────────
|
||||
|
||||
export const WorkflowSampleRecordSchema = z.object({
|
||||
id: z.string(),
|
||||
corporationId: z.string().optional(),
|
||||
pipelineId: z.string().optional(),
|
||||
taskName: z.string().optional(),
|
||||
actived: z.number().optional(),
|
||||
dataJson: z.string(),
|
||||
createTime: z.number(),
|
||||
updateTime: z.number().optional(),
|
||||
});
|
||||
|
||||
export type WorkflowSampleRecord = z.infer<typeof WorkflowSampleRecordSchema>;
|
||||
|
||||
export const WorkflowSampleDataResultSchema = z.object({
|
||||
records: z.array(WorkflowSampleRecordSchema).default([]),
|
||||
total: z.number().optional(),
|
||||
size: z.number().optional(),
|
||||
current: z.number().optional(),
|
||||
});
|
||||
|
||||
export type WorkflowSampleDataResult = z.infer<typeof WorkflowSampleDataResultSchema>;
|
||||
|
||||
// ── 工作流/Piper 枚举选项 (EKB_ENUM) ──────────────────────────────────────────
|
||||
|
||||
export const WorkflowEnumItemSchema = z.object({
|
||||
label: z.string(),
|
||||
code: z.string(),
|
||||
name: z.string().optional().default(""),
|
||||
});
|
||||
|
||||
export type WorkflowEnumItem = z.infer<typeof WorkflowEnumItemSchema>;
|
||||
Reference in new issue
Block a user