feat(platform): 新增工作流控制及辅助工具
- platform_workflow_toggle: 启用/停用工作流(state=1/0) - platform_workflow_jobs: 查询运行中的任务 - platform_workflow_dsl: 获取 DSL 配置列表 - platform_workflow_staffs: 获取企业员工列表 - platform_workflow_webhook: 获取 Webhook 信息 - platform_workflow_sample: 获取测试/采样数据 - 修复类型定义兼容 null 值(department, email 等) - 所有工具通过 Piper/EASO 认证调用
This commit is contained in:
1 parent
b7bdb39f56
commit
298e114420
3 files changed
+195
-7
No files matched your search
@@ -6,6 +6,10 @@ import {
|
||||
WorkflowStatsSchema,
|
||||
WorkflowChargeSchema,
|
||||
WorkflowDetailSchema,
|
||||
WorkflowJobSchema,
|
||||
WorkflowDslSchema,
|
||||
StaffSchema,
|
||||
WebhookInfoSchema,
|
||||
} from "./types";
|
||||
|
||||
// Helper to unwrap { data: T } response
|
||||
@@ -14,6 +18,11 @@ async function unwrap<T>(response: Response, schema: z.ZodType<T>): Promise<T> {
|
||||
return schema.parse(json.data);
|
||||
}
|
||||
|
||||
// Helper for simple success responses
|
||||
async function ok(response: Response): Promise<{ success: boolean }> {
|
||||
return { success: response.status === 200 };
|
||||
}
|
||||
|
||||
// ── 自建应用 ──────────────────────────────────────────────────────────────────
|
||||
|
||||
export async function listPlatforms(
|
||||
@@ -72,3 +81,70 @@ export async function getWorkflowDetail(
|
||||
const response = await client.get(`api/easo/pipelines/${pipelineId}`);
|
||||
return unwrap(response, WorkflowDetailSchema);
|
||||
}
|
||||
|
||||
// ── 工作流启停(Piper)────────────────────────────────────────────────────────
|
||||
|
||||
export async function toggleWorkflow(
|
||||
client: KyInstance,
|
||||
pipelineId: string,
|
||||
state: 0 | 1
|
||||
): Promise<{ success: boolean }> {
|
||||
const response = await client.put(`api/easo/pipelines/state/${pipelineId}`, {
|
||||
searchParams: { state: String(state) },
|
||||
});
|
||||
return ok(response);
|
||||
}
|
||||
|
||||
// ── 运行中的任务(Piper)──────────────────────────────────────────────────────
|
||||
|
||||
export async function listRunningJobs(
|
||||
client: KyInstance,
|
||||
pipelineId: string,
|
||||
runType: "DEBUG" | "PROD" = "DEBUG"
|
||||
): Promise<import("./types").WorkflowJob[]> {
|
||||
const response = await client.get("api/easo/jobs/running", {
|
||||
searchParams: { pipelineId, runType },
|
||||
});
|
||||
return unwrap(response, z.array(WorkflowJobSchema));
|
||||
}
|
||||
|
||||
// ── DSL 配置(Piper)──────────────────────────────────────────────────────────
|
||||
|
||||
export async function listDsl(
|
||||
client: KyInstance
|
||||
): Promise<import("./types").WorkflowDsl[]> {
|
||||
const response = await client.get("api/easo/dsl/all");
|
||||
return unwrap(response, z.array(WorkflowDslSchema));
|
||||
}
|
||||
|
||||
// ── 员工列表(Piper)──────────────────────────────────────────────────────────
|
||||
|
||||
export async function listStaffs(
|
||||
client: KyInstance,
|
||||
external: boolean = false
|
||||
): Promise<import("./types").Staff[]> {
|
||||
const response = await client.get("api/easo/common/staffs", {
|
||||
searchParams: { external: String(external) },
|
||||
});
|
||||
return unwrap(response, z.array(StaffSchema));
|
||||
}
|
||||
|
||||
// ── Webhook 信息(Piper)──────────────────────────────────────────────────────
|
||||
|
||||
export async function getWebhookInfo(
|
||||
client: KyInstance,
|
||||
pipelineId: string
|
||||
): Promise<import("./types").WebhookInfo> {
|
||||
const response = await client.get(`api/webhook/${pipelineId}`);
|
||||
return unwrap(response, WebhookInfoSchema);
|
||||
}
|
||||
|
||||
// ── 测试/采样数据(Piper)─────────────────────────────────────────────────────
|
||||
|
||||
export async function sampleWorkflowData(
|
||||
client: KyInstance,
|
||||
pipelineId: string
|
||||
): Promise<unknown> {
|
||||
const response = await client.post(`api/easo/pipelines/${pipelineId}/sampleData`);
|
||||
return response.json();
|
||||
}
|
||||
@@ -54,6 +54,76 @@ export const platformTools = [
|
||||
return await api.getWorkflowDetail(client, params.pipelineId);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "platform_workflow_toggle",
|
||||
description: "启用或停用工作流(Piper)。state=1 启用,state=0 停用",
|
||||
parameters: z.object({
|
||||
pipelineId: z.string().describe("工作流 ID"),
|
||||
state: z.number().describe("状态:1 启用,0 停用"),
|
||||
}),
|
||||
handler: async (
|
||||
client: KyInstance,
|
||||
params: { pipelineId: string; state: number }
|
||||
) => {
|
||||
return await api.toggleWorkflow(
|
||||
client,
|
||||
params.pipelineId,
|
||||
params.state as 0 | 1
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "platform_workflow_jobs",
|
||||
description: "查询工作流运行中的任务(Piper)",
|
||||
parameters: z.object({
|
||||
pipelineId: z.string().describe("工作流 ID"),
|
||||
runType: z.enum(["DEBUG", "PROD"]).optional().describe("运行类型,默认 DEBUG"),
|
||||
}),
|
||||
handler: async (
|
||||
client: KyInstance,
|
||||
params: { pipelineId: string; runType?: "DEBUG" | "PROD" }
|
||||
) => {
|
||||
return await api.listRunningJobs(client, params.pipelineId, params.runType);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "platform_workflow_dsl",
|
||||
description: "获取工作流 DSL 配置列表(Piper)",
|
||||
parameters: z.object({}),
|
||||
handler: async (client: KyInstance) => {
|
||||
return await api.listDsl(client);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "platform_workflow_staffs",
|
||||
description: "获取企业员工列表(Piper)",
|
||||
parameters: z.object({
|
||||
external: z.boolean().optional().describe("是否包含外部人员,默认 false"),
|
||||
}),
|
||||
handler: async (client: KyInstance, params: { external?: boolean }) => {
|
||||
return await api.listStaffs(client, params.external);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "platform_workflow_webhook",
|
||||
description: "获取工作流 Webhook 信息(Piper)",
|
||||
parameters: z.object({
|
||||
pipelineId: z.string().describe("工作流 ID"),
|
||||
}),
|
||||
handler: async (client: KyInstance, params: { pipelineId: string }) => {
|
||||
return await api.getWebhookInfo(client, params.pipelineId);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "platform_workflow_sample",
|
||||
description: "获取工作流测试/采样数据(Piper)",
|
||||
parameters: z.object({
|
||||
pipelineId: z.string().describe("工作流 ID"),
|
||||
}),
|
||||
handler: async (client: KyInstance, params: { pipelineId: string }) => {
|
||||
return await api.sampleWorkflowData(client, params.pipelineId);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export type PlatformTool = (typeof platformTools)[number];
|
||||
@@ -49,10 +49,10 @@ export const WorkflowSchema = z.object({
|
||||
runningCount: z.number().default(0),
|
||||
errorCount: z.number().default(0),
|
||||
updateTime: z.string().default(""),
|
||||
updateUser: z.string().optional(),
|
||||
updateUser: z.string().nullable().optional(),
|
||||
tasks: z.array(z.any()).default([]),
|
||||
desc: z.string().optional(),
|
||||
customDesc: z.string().optional(),
|
||||
desc: z.string().nullable().optional(),
|
||||
customDesc: z.string().nullable().optional(),
|
||||
});
|
||||
|
||||
export const WorkflowPageSchema = z.object({
|
||||
@@ -87,15 +87,15 @@ export const WorkflowAlarmSchema = z.object({
|
||||
export const WorkflowDetailSchema = z.object({
|
||||
id: z.string(),
|
||||
label: z.string().default(""),
|
||||
desc: z.string().optional(),
|
||||
customDesc: z.string().optional(),
|
||||
desc: z.string().nullable().optional(),
|
||||
customDesc: z.string().nullable().optional(),
|
||||
state: z.number().default(0),
|
||||
debugState: z.number().default(0),
|
||||
runTimes: z.number().default(0),
|
||||
errorTimes: z.number().default(0),
|
||||
updateTime: z.string().default(""),
|
||||
updateUser: z.string().optional(),
|
||||
staffName: z.string().optional(),
|
||||
updateUser: z.string().nullable().optional(),
|
||||
staffName: z.string().nullable().optional(),
|
||||
version: z.string().default(""),
|
||||
dataLimit: z.number().default(20),
|
||||
source: z.number().default(0),
|
||||
@@ -114,6 +114,44 @@ export const WorkflowChargeSchema = z.object({
|
||||
remaining: z.number().default(0),
|
||||
});
|
||||
|
||||
// ── 运行中的任务 ──────────────────────────────────────────────────────────────
|
||||
|
||||
export const WorkflowJobSchema = z.object({
|
||||
id: z.string(),
|
||||
pipelineId: z.string(),
|
||||
status: z.string().default(""),
|
||||
startTime: z.string().optional(),
|
||||
endTime: z.string().optional(),
|
||||
triggerType: z.string().default(""),
|
||||
});
|
||||
|
||||
// ── DSL 配置 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export const WorkflowDslSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string().default(""),
|
||||
type: z.string().default(""),
|
||||
config: z.record(z.string(), z.any()).default({}),
|
||||
});
|
||||
|
||||
// ── 员工 ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
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 type Platform = z.infer<typeof PlatformSchema>;
|
||||
@@ -124,3 +162,7 @@ export type WorkflowStats = z.infer<typeof WorkflowStatsSchema>;
|
||||
export type WorkflowAlarm = z.infer<typeof WorkflowAlarmSchema>;
|
||||
export type WorkflowDetail = z.infer<typeof WorkflowDetailSchema>;
|
||||
export type WorkflowCharge = z.infer<typeof WorkflowChargeSchema>;
|
||||
export type WorkflowJob = z.infer<typeof WorkflowJobSchema>;
|
||||
export type WorkflowDsl = z.infer<typeof WorkflowDslSchema>;
|
||||
export type Staff = z.infer<typeof StaffSchema>;
|
||||
export type WebhookInfo = z.infer<typeof WebhookInfoSchema>;
|
||||
Reference in new issue
Block a user