refactor: 将 ekb-mcp 上移到根目录
项目结构重构: - 将 ekb-mcp/ 子目录内容上移到项目根目录 - 更新 AGENTS.md 反映新的 TS + MCP 架构 - 更新 README.md 为 ekb-mcp 项目说明 - 保留 docs/ 文档目录 新的项目结构: - src/core/ - 基础设施(auth, config, http) - src/domains/ - 业务域(sealai, platform) - src/server.ts - MCP Server 入口 - enterprises/ - 企业配置
This commit is contained in:
1 parent
955f56114f
commit
f9eb6a4844
30 files changed
+384
-422
No files matched your search
@@ -0,0 +1,79 @@
|
||||
import { z } from "zod";
|
||||
import { KyInstance } from "ky";
|
||||
import {
|
||||
PlatformSchema,
|
||||
WorkflowPageSchema,
|
||||
WorkflowStatsSchema,
|
||||
WorkflowChargeSchema,
|
||||
WorkflowDetailSchema,
|
||||
} from "./types";
|
||||
|
||||
// Helper to unwrap { data: T } response
|
||||
async function unwrap<T>(response: Response, schema: z.ZodType<T>): Promise<T> {
|
||||
const json = await response.json() as { data: unknown };
|
||||
return schema.parse(json.data);
|
||||
}
|
||||
|
||||
// ── 自建应用 ──────────────────────────────────────────────────────────────────
|
||||
|
||||
export async function listPlatforms(
|
||||
client: KyInstance,
|
||||
corpId: string
|
||||
): Promise<import("./types").Platform[]> {
|
||||
const response = await client.get("api/v2/datalink/platform/search", {
|
||||
searchParams: { scope: "enable", corpId },
|
||||
});
|
||||
const json = (await response.json()) as { items: unknown[] };
|
||||
return z.array(PlatformSchema).parse(json.items);
|
||||
}
|
||||
|
||||
// ── 工作流(EASO)─────────────────────────────────────────────────────────────
|
||||
|
||||
export async function listWorkflows(
|
||||
client: KyInstance,
|
||||
corpId: string,
|
||||
platformId: string,
|
||||
page: number = 1,
|
||||
pageSize: number = 20
|
||||
): Promise<import("./types").WorkflowPage> {
|
||||
const response = await client.get("api/easo/pipelines/logs", {
|
||||
searchParams: {
|
||||
corpId,
|
||||
platformId,
|
||||
number: String(page),
|
||||
pageSize: String(pageSize),
|
||||
},
|
||||
});
|
||||
return unwrap(response, WorkflowPageSchema);
|
||||
}
|
||||
|
||||
export async function getWorkflowStats(
|
||||
client: KyInstance,
|
||||
corpId: string,
|
||||
platformId: string
|
||||
): Promise<import("./types").WorkflowStats> {
|
||||
const response = await client.get("api/easo/stats", {
|
||||
searchParams: { corpId, platformId },
|
||||
});
|
||||
return unwrap(response, WorkflowStatsSchema);
|
||||
}
|
||||
|
||||
export async function getWorkflowCharge(
|
||||
client: KyInstance,
|
||||
corpId: string
|
||||
): Promise<import("./types").WorkflowCharge> {
|
||||
const response = await client.get("api/easo/charge", {
|
||||
searchParams: { corpId },
|
||||
});
|
||||
return unwrap(response, WorkflowChargeSchema);
|
||||
}
|
||||
|
||||
// ── 工作流详情(Piper)────────────────────────────────────────────────────────
|
||||
|
||||
export async function getWorkflowDetail(
|
||||
client: KyInstance,
|
||||
pipelineId: string
|
||||
): Promise<import("./types").WorkflowDetail> {
|
||||
const response = await client.get(`api/easo/pipelines/${pipelineId}`);
|
||||
return unwrap(response, WorkflowDetailSchema);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { z } from "zod";
|
||||
import { KyInstance } from "ky";
|
||||
import * as api from "./api";
|
||||
|
||||
export const platformTools = [
|
||||
{
|
||||
name: "platform_list",
|
||||
description: "列出企业下所有启用的自建应用",
|
||||
parameters: z.object({}),
|
||||
handler: async (_client: KyInstance, _args: Record<string, unknown>) => {
|
||||
return { message: "platform_list 在 server.ts 中直接处理" };
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "platform_workflow_list",
|
||||
description: "列出指定自建应用下的工作流",
|
||||
parameters: z.object({
|
||||
platformId: z.string().describe("自建应用 ID"),
|
||||
page: z.number().optional().describe("页码,默认 1"),
|
||||
pageSize: z.number().optional().describe("每页数量,默认 20"),
|
||||
}),
|
||||
handler: async (
|
||||
client: KyInstance,
|
||||
params: { platformId: string; page?: number; pageSize?: number }
|
||||
) => {
|
||||
// 需要从 corp 获取 corpId,这里简化处理
|
||||
return { message: "需要使用 EASO 客户端" };
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export type PlatformTool = (typeof platformTools)[number];
|
||||
@@ -0,0 +1,126 @@
|
||||
import { z } from "zod";
|
||||
|
||||
// ── 通用响应包装 ──────────────────────────────────────────────────────────────
|
||||
|
||||
export const EkbResponseSchema = <T extends z.ZodType>(dataSchema: T) =>
|
||||
z.object({
|
||||
code: z.number(),
|
||||
msg: z.string().default(""),
|
||||
data: dataSchema.optional(),
|
||||
});
|
||||
|
||||
// ── 自建应用(DataLink Platform)─────────────────────────────
|
||||
|
||||
export const PlatformSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
nameSpell: z.string().default(""),
|
||||
enName: z.string().nullable().optional(),
|
||||
code: z.string().default(""),
|
||||
corporationId: z.string(),
|
||||
active: z.boolean().default(true),
|
||||
type: z.string().default(""),
|
||||
groupType: z.string().default(""),
|
||||
platformType: z.string().default(""),
|
||||
source: z.string().default(""),
|
||||
adminIds: z.array(z.string()).default([]),
|
||||
desc: z.string().nullable().optional(),
|
||||
importMethod: z.array(z.string()).default([]),
|
||||
createTime: z.number().default(0),
|
||||
updateTime: z.number().default(0),
|
||||
});
|
||||
|
||||
// ── 工作流(EASO Pipeline)───────────────────────────────────
|
||||
|
||||
export const WorkflowTaskSchema = z.object({
|
||||
name: z.string().default(""),
|
||||
type: z.string().default(""),
|
||||
label: z.string().default(""),
|
||||
desc: z.string().optional(),
|
||||
groupName: z.string().default(""),
|
||||
orderIndex: z.number().default(0),
|
||||
status: z.string().default(""),
|
||||
});
|
||||
|
||||
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().optional(),
|
||||
tasks: z.array(z.any()).default([]),
|
||||
desc: z.string().optional(),
|
||||
customDesc: z.string().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().optional(),
|
||||
customDesc: z.string().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(),
|
||||
version: z.string().default(""),
|
||||
dataLimit: z.number().default(20),
|
||||
source: z.number().default(0),
|
||||
queueJobs: z.boolean().default(false),
|
||||
tasksVersion: z.number().default(0),
|
||||
tasks: z.array(WorkflowTaskSchema).default([]),
|
||||
alarm: WorkflowAlarmSchema.optional(),
|
||||
});
|
||||
|
||||
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 type Platform = z.infer<typeof PlatformSchema>;
|
||||
export type WorkflowTask = z.infer<typeof WorkflowTaskSchema>;
|
||||
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 WorkflowCharge = z.infer<typeof WorkflowChargeSchema>;
|
||||
Reference in new issue
Block a user