From 298e114420fc60c3c9ee9abb04d57141446ee0ba Mon Sep 17 00:00:00 2001 From: yunyingk Date: Mon, 18 May 2026 22:10:44 +0800 Subject: [PATCH] =?UTF-8?q?feat(platform):=20=E6=96=B0=E5=A2=9E=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E6=B5=81=E6=8E=A7=E5=88=B6=E5=8F=8A=E8=BE=85=E5=8A=A9?= =?UTF-8?q?=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 认证调用 --- src/domains/platform/api.ts | 76 +++++++++++++++++++++++++++++++++++ src/domains/platform/tools.ts | 70 ++++++++++++++++++++++++++++++++ src/domains/platform/types.ts | 56 ++++++++++++++++++++++---- 3 files changed, 195 insertions(+), 7 deletions(-) diff --git a/src/domains/platform/api.ts b/src/domains/platform/api.ts index 884621d..70751ad 100644 --- a/src/domains/platform/api.ts +++ b/src/domains/platform/api.ts @@ -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(response: Response, schema: z.ZodType): Promise { 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 { + 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 { + 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 { + 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 { + const response = await client.get(`api/webhook/${pipelineId}`); + return unwrap(response, WebhookInfoSchema); +} + +// ── 测试/采样数据(Piper)───────────────────────────────────────────────────── + +export async function sampleWorkflowData( + client: KyInstance, + pipelineId: string +): Promise { + const response = await client.post(`api/easo/pipelines/${pipelineId}/sampleData`); + return response.json(); +} diff --git a/src/domains/platform/tools.ts b/src/domains/platform/tools.ts index 503bfb6..7f4a6e7 100644 --- a/src/domains/platform/tools.ts +++ b/src/domains/platform/tools.ts @@ -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]; diff --git a/src/domains/platform/types.ts b/src/domains/platform/types.ts index 3db9a85..5e3cdcd 100644 --- a/src/domains/platform/types.ts +++ b/src/domains/platform/types.ts @@ -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; @@ -124,3 +162,7 @@ export type WorkflowStats = z.infer; export type WorkflowAlarm = z.infer; export type WorkflowDetail = z.infer; export type WorkflowCharge = z.infer; +export type WorkflowJob = z.infer; +export type WorkflowDsl = z.infer; +export type Staff = z.infer; +export type WebhookInfo = z.infer;