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>;
|
||||
@@ -0,0 +1,182 @@
|
||||
import { z } from "zod";
|
||||
import { KyInstance } from "ky";
|
||||
import {
|
||||
MeDataSchema,
|
||||
BillingStatusDataSchema,
|
||||
DraftRulesDataSchema,
|
||||
DraftRuleSchema,
|
||||
RuleSetVersionSchema,
|
||||
PublishVersionDataSchema,
|
||||
KnowledgeArticleListDataSchema,
|
||||
KnowledgeArticleSchema,
|
||||
} 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 getMe(client: KyInstance): Promise<import("./types").MeData> {
|
||||
const response = await client.get("api/v1/auth/me");
|
||||
return unwrap(response, MeDataSchema);
|
||||
}
|
||||
|
||||
// ── 计费 ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
export async function getBillingStatus(
|
||||
client: KyInstance
|
||||
): Promise<import("./types").BillingStatusData> {
|
||||
const response = await client.get("api/v1/billing/status");
|
||||
return unwrap(response, BillingStatusDataSchema);
|
||||
}
|
||||
|
||||
// ── 审核规则 ──────────────────────────────────────────────────────────────────
|
||||
|
||||
export async function listRules(
|
||||
client: KyInstance
|
||||
): Promise<import("./types").DraftRulesData> {
|
||||
const response = await client.get("api/v1/rules");
|
||||
return unwrap(response, DraftRulesDataSchema);
|
||||
}
|
||||
|
||||
export async function createRule(
|
||||
client: KyInstance,
|
||||
params: {
|
||||
description: string;
|
||||
scope: string;
|
||||
strictness: string;
|
||||
}
|
||||
): Promise<import("./types").DraftRule> {
|
||||
const response = await client.post("api/v1/rules", {
|
||||
json: params,
|
||||
});
|
||||
return unwrap(response, DraftRuleSchema);
|
||||
}
|
||||
|
||||
export async function updateRule(
|
||||
client: KyInstance,
|
||||
ruleId: string,
|
||||
params: {
|
||||
description?: string;
|
||||
scope?: string;
|
||||
strictness?: string;
|
||||
}
|
||||
): Promise<import("./types").DraftRule> {
|
||||
const response = await client.put(`api/v1/rules/${ruleId}`, {
|
||||
json: params,
|
||||
});
|
||||
return unwrap(response, DraftRuleSchema);
|
||||
}
|
||||
|
||||
export async function deleteRule(client: KyInstance, ruleId: string): Promise<void> {
|
||||
await client.delete(`api/v1/rules/${ruleId}`);
|
||||
}
|
||||
|
||||
export async function listRuleSetVersions(
|
||||
client: KyInstance
|
||||
): Promise<import("./types").RuleSetVersion[]> {
|
||||
const response = await client.get("api/v1/rule-set-versions");
|
||||
return unwrap(response, z.array(RuleSetVersionSchema));
|
||||
}
|
||||
|
||||
export async function publishRuleSetVersion(
|
||||
client: KyInstance,
|
||||
versionName: string
|
||||
): Promise<import("./types").PublishVersionData> {
|
||||
const response = await client.post("api/v1/rule-set-versions/publish", {
|
||||
json: { versionName },
|
||||
});
|
||||
return unwrap(response, PublishVersionDataSchema);
|
||||
}
|
||||
|
||||
// ── 知识文档 ──────────────────────────────────────────────────────────────────
|
||||
|
||||
export async function listArticles(
|
||||
client: KyInstance,
|
||||
params: {
|
||||
scenarios?: string[];
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
sortBy?: string;
|
||||
sortOrder?: string;
|
||||
} = {}
|
||||
): Promise<import("./types").KnowledgeArticleListData> {
|
||||
const searchParams = new URLSearchParams();
|
||||
searchParams.set("offset", String(params.offset ?? 0));
|
||||
searchParams.set("limit", String(params.limit ?? 20));
|
||||
searchParams.set("sortBy", params.sortBy ?? "createdAt");
|
||||
searchParams.set("sortOrder", params.sortOrder ?? "desc");
|
||||
|
||||
if (params.scenarios) {
|
||||
for (let i = 0; i < params.scenarios.length; i++) {
|
||||
searchParams.set(`filter[scenarios][${i}]`, params.scenarios[i]);
|
||||
}
|
||||
}
|
||||
|
||||
const response = await client.get("api/v1/knowledge/articles", {
|
||||
searchParams,
|
||||
});
|
||||
return unwrap(response, KnowledgeArticleListDataSchema);
|
||||
}
|
||||
|
||||
export async function getArticle(
|
||||
client: KyInstance,
|
||||
articleId: string
|
||||
): Promise<import("./types").KnowledgeArticle> {
|
||||
const response = await client.get(`api/v1/knowledge/articles/${articleId}`);
|
||||
return unwrap(response, KnowledgeArticleSchema);
|
||||
}
|
||||
|
||||
export async function createArticle(
|
||||
client: KyInstance,
|
||||
params: {
|
||||
title: string;
|
||||
purpose: string;
|
||||
content: string;
|
||||
contentType?: string;
|
||||
status?: string;
|
||||
scenarios?: string[];
|
||||
tags?: string[];
|
||||
}
|
||||
): Promise<import("./types").KnowledgeArticle> {
|
||||
const response = await client.post("api/v1/knowledge/articles", {
|
||||
json: {
|
||||
...params,
|
||||
contentType: params.contentType ?? "policy",
|
||||
status: params.status ?? "published",
|
||||
scenarios: params.scenarios ?? [],
|
||||
tags: params.tags ?? [],
|
||||
},
|
||||
});
|
||||
return unwrap(response, KnowledgeArticleSchema);
|
||||
}
|
||||
|
||||
export async function patchArticle(
|
||||
client: KyInstance,
|
||||
articleId: string,
|
||||
params: {
|
||||
title?: string;
|
||||
purpose?: string;
|
||||
content?: string;
|
||||
contentType?: string;
|
||||
status?: string;
|
||||
enabled?: boolean;
|
||||
scenarios?: string[];
|
||||
tags?: string[];
|
||||
}
|
||||
): Promise<import("./types").KnowledgeArticle> {
|
||||
const attributes: Record<string, unknown> = {};
|
||||
for (const [key, value] of Object.entries(params)) {
|
||||
if (value !== undefined) {
|
||||
attributes[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
const response = await client.patch(`api/v1/knowledge/articles/${articleId}`, {
|
||||
json: { attributes },
|
||||
});
|
||||
return unwrap(response, KnowledgeArticleSchema);
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
import { z } from "zod";
|
||||
import { KyInstance } from "ky";
|
||||
import * as api from "./api";
|
||||
|
||||
// ── Tool 定义 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export const sealaiTools = [
|
||||
{
|
||||
name: "sealai_whoami",
|
||||
description: "查询当前 SealAI 用户身份及租户信息",
|
||||
parameters: z.object({}),
|
||||
handler: async (client: KyInstance) => {
|
||||
return await api.getMe(client);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sealai_billing",
|
||||
description: "查询 SealAI 订阅状态及功能配额",
|
||||
parameters: z.object({}),
|
||||
handler: async (client: KyInstance) => {
|
||||
return await api.getBillingStatus(client);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sealai_rules_list",
|
||||
description: "列出 SealAI 草稿区审核规则",
|
||||
parameters: z.object({}),
|
||||
handler: async (client: KyInstance) => {
|
||||
return await api.listRules(client);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sealai_rule_create",
|
||||
description: "新建 SealAI 草稿审核规则",
|
||||
parameters: z.object({
|
||||
description: z.string().describe("规则描述"),
|
||||
scope: z.string().describe("适用场景"),
|
||||
strictness: z
|
||||
.enum(["MUST_FOLLOW", "SHOULD_FOLLOW", "SUGGESTION"])
|
||||
.describe("严格程度"),
|
||||
}),
|
||||
handler: async (
|
||||
client: KyInstance,
|
||||
params: { description: string; scope: string; strictness: string }
|
||||
) => {
|
||||
return await api.createRule(client, params);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sealai_rule_update",
|
||||
description: "更新 SealAI 草稿审核规则",
|
||||
parameters: z.object({
|
||||
ruleId: z.string().describe("规则 ID"),
|
||||
description: z.string().optional().describe("规则描述"),
|
||||
scope: z.string().optional().describe("适用场景"),
|
||||
strictness: z
|
||||
.enum(["MUST_FOLLOW", "SHOULD_FOLLOW", "SUGGESTION"])
|
||||
.optional()
|
||||
.describe("严格程度"),
|
||||
}),
|
||||
handler: async (
|
||||
client: KyInstance,
|
||||
params: {
|
||||
ruleId: string;
|
||||
description?: string;
|
||||
scope?: string;
|
||||
strictness?: string;
|
||||
}
|
||||
) => {
|
||||
const { ruleId, ...rest } = params;
|
||||
return await api.updateRule(client, ruleId, rest);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sealai_rule_delete",
|
||||
description: "删除 SealAI 草稿审核规则",
|
||||
parameters: z.object({
|
||||
ruleId: z.string().describe("规则 ID"),
|
||||
}),
|
||||
handler: async (client: KyInstance, params: { ruleId: string }) => {
|
||||
await api.deleteRule(client, params.ruleId);
|
||||
return { success: true };
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sealai_versions_list",
|
||||
description: "列出 SealAI 已发布规则集版本历史",
|
||||
parameters: z.object({}),
|
||||
handler: async (client: KyInstance) => {
|
||||
return await api.listRuleSetVersions(client);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sealai_version_publish",
|
||||
description: "发布 SealAI 草稿规则为新版本",
|
||||
parameters: z.object({
|
||||
versionName: z.string().describe("版本名称"),
|
||||
}),
|
||||
handler: async (client: KyInstance, params: { versionName: string }) => {
|
||||
return await api.publishRuleSetVersion(client, params.versionName);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sealai_knowledge_list",
|
||||
description: "列出 SealAI 知识文档",
|
||||
parameters: z.object({
|
||||
scenarios: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe("场景过滤,如 [\"audit\", \"fill\"]"),
|
||||
offset: z.number().optional().describe("分页偏移量"),
|
||||
limit: z.number().optional().describe("每页数量"),
|
||||
}),
|
||||
handler: async (
|
||||
client: KyInstance,
|
||||
params: {
|
||||
scenarios?: string[];
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
}
|
||||
) => {
|
||||
return await api.listArticles(client, params);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sealai_knowledge_get",
|
||||
description: "获取 SealAI 知识文档详情",
|
||||
parameters: z.object({
|
||||
articleId: z.string().describe("文档 ID"),
|
||||
}),
|
||||
handler: async (client: KyInstance, params: { articleId: string }) => {
|
||||
return await api.getArticle(client, params.articleId);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sealai_knowledge_create",
|
||||
description: "新建 SealAI 知识文档",
|
||||
parameters: z.object({
|
||||
title: z.string().describe("文档标题"),
|
||||
purpose: z.string().describe("适用说明"),
|
||||
content: z.string().describe("正文内容(Markdown)"),
|
||||
contentType: z.string().optional().describe("内容类型,默认 policy"),
|
||||
status: z.string().optional().describe("published 或 draft"),
|
||||
scenarios: z.array(z.string()).optional().describe("适用场景"),
|
||||
tags: z.array(z.string()).optional().describe("标签"),
|
||||
}),
|
||||
handler: async (
|
||||
client: KyInstance,
|
||||
params: {
|
||||
title: string;
|
||||
purpose: string;
|
||||
content: string;
|
||||
contentType?: string;
|
||||
status?: string;
|
||||
scenarios?: string[];
|
||||
tags?: string[];
|
||||
}
|
||||
) => {
|
||||
return await api.createArticle(client, params);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sealai_knowledge_update",
|
||||
description: "更新 SealAI 知识文档",
|
||||
parameters: z.object({
|
||||
articleId: z.string().describe("文档 ID"),
|
||||
title: z.string().optional(),
|
||||
purpose: z.string().optional(),
|
||||
content: z.string().optional(),
|
||||
contentType: z.string().optional(),
|
||||
status: z.string().optional(),
|
||||
enabled: z.boolean().optional(),
|
||||
scenarios: z.array(z.string()).optional(),
|
||||
tags: z.array(z.string()).optional(),
|
||||
}),
|
||||
handler: async (
|
||||
client: KyInstance,
|
||||
params: {
|
||||
articleId: string;
|
||||
title?: string;
|
||||
purpose?: string;
|
||||
content?: string;
|
||||
contentType?: string;
|
||||
status?: string;
|
||||
enabled?: boolean;
|
||||
scenarios?: string[];
|
||||
tags?: string[];
|
||||
}
|
||||
) => {
|
||||
const { articleId, ...rest } = params;
|
||||
return await api.patchArticle(client, articleId, rest);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export type SealAiTool = (typeof sealaiTools)[number];
|
||||
@@ -0,0 +1,166 @@
|
||||
import { z } from "zod";
|
||||
|
||||
// ── 通用包装 ──────────────────────────────────────────────────────────────────
|
||||
|
||||
export const SealAiResponseSchema = <T extends z.ZodType>(dataSchema: T) =>
|
||||
z.object({
|
||||
data: dataSchema,
|
||||
});
|
||||
|
||||
// ── 认证 ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
export const HosecloudStaffSchema = z.object({
|
||||
staffId: z.string(),
|
||||
name: z.string(),
|
||||
code: z.string().default(""),
|
||||
bindTime: z.number(),
|
||||
});
|
||||
|
||||
export const SealAiUserSchema = z.object({
|
||||
id: z.string(),
|
||||
tenantId: z.string(),
|
||||
name: z.string(),
|
||||
isAdmin: z.boolean(),
|
||||
permissions: z.array(z.string()),
|
||||
providerUserId: z.string(),
|
||||
hosecloudStaff: HosecloudStaffSchema.optional(),
|
||||
});
|
||||
|
||||
export const HoseCorpConfigSchema = z.object({
|
||||
apiKey: z.string(),
|
||||
corporationId: z.string(),
|
||||
corporationName: z.string(),
|
||||
});
|
||||
|
||||
export const SealAiTenantSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
tenantSlug: z.string(),
|
||||
isDemo: z.boolean(),
|
||||
logoUrl: z.string().optional(),
|
||||
hoseCorpConfig: HoseCorpConfigSchema,
|
||||
});
|
||||
|
||||
export const MeDataSchema = z.object({
|
||||
user: SealAiUserSchema,
|
||||
tenant: SealAiTenantSchema,
|
||||
});
|
||||
|
||||
// ── 计费 ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
export const SubscriptionSchema = z.object({
|
||||
id: z.string(),
|
||||
tenantId: z.string(),
|
||||
planId: z.string(),
|
||||
status: z.string(), // "active" | "expired"
|
||||
startDate: z.string(),
|
||||
createdAt: z.string(),
|
||||
updatedAt: z.string(),
|
||||
});
|
||||
|
||||
export const FeatureSchema = z.object({
|
||||
code: z.string(),
|
||||
name: z.string(),
|
||||
enabled: z.boolean().optional(),
|
||||
quota: z.number().optional(),
|
||||
used: z.number().optional(),
|
||||
remaining: z.number().optional(),
|
||||
balance: z.number().optional(),
|
||||
totalQuota: z.number().optional(),
|
||||
totalUsed: z.number().optional(),
|
||||
nextResetDate: z.string().optional(),
|
||||
});
|
||||
|
||||
export const BillingStatusDataSchema = z.object({
|
||||
subscriptions: z.array(SubscriptionSchema),
|
||||
features: z.array(FeatureSchema),
|
||||
});
|
||||
|
||||
// ── 审核规则草稿 ──────────────────────────────────────────────────────────────
|
||||
|
||||
export const DraftRuleSchema = z.object({
|
||||
id: z.string(),
|
||||
tenantId: z.string(),
|
||||
description: z.string(),
|
||||
scope: z.string(),
|
||||
strictness: z.string(), // MUST_FOLLOW / SHOULD_FOLLOW / SUGGESTION
|
||||
status: z.string(), // DRAFT
|
||||
createdAt: z.number(),
|
||||
updatedAt: z.number(),
|
||||
});
|
||||
|
||||
export const DraftRulesDataSchema = z.object({
|
||||
rules: z.array(DraftRuleSchema),
|
||||
hasPendingDeletes: z.boolean().default(false),
|
||||
});
|
||||
|
||||
// ── 已发布版本 ────────────────────────────────────────────────────────────────
|
||||
|
||||
export const PublishedRuleSnapshotSchema = z.object({
|
||||
description: z.string(),
|
||||
scope: z.string(),
|
||||
strictness: z.string(),
|
||||
});
|
||||
|
||||
export const RuleSetVersionSchema = z.object({
|
||||
id: z.string(),
|
||||
tenantId: z.string(),
|
||||
versionNumber: z.number(),
|
||||
versionName: z.string(),
|
||||
publishedBy: z.string(),
|
||||
publishedByName: z.string(),
|
||||
rules: z.array(PublishedRuleSnapshotSchema),
|
||||
publishedAt: z.number(),
|
||||
createdAt: z.number(),
|
||||
});
|
||||
|
||||
export const PublishVersionDataSchema = z.object({
|
||||
version: RuleSetVersionSchema,
|
||||
rulesCount: z.number(),
|
||||
});
|
||||
|
||||
// ── 知识文档 ──────────────────────────────────────────────────────────────────
|
||||
|
||||
export const KnowledgeArticleSchema = z.object({
|
||||
id: z.string(),
|
||||
tenantId: z.string(),
|
||||
title: z.string(),
|
||||
purpose: z.string(),
|
||||
contentType: z.string(),
|
||||
content: z.string(),
|
||||
status: z.string(), // "published" | "draft"
|
||||
enabled: z.boolean().default(true),
|
||||
scenarios: z.array(z.string()).default([]),
|
||||
tags: z.array(z.string()).default([]),
|
||||
category: z.string().optional(),
|
||||
categoryTags: z.array(z.string()).default([]),
|
||||
createdBy: z.string().optional(),
|
||||
createdByName: z.string().optional(),
|
||||
createdAt: z.number().optional(),
|
||||
updatedAt: z.number().optional(),
|
||||
updatedBy: z.string().optional(),
|
||||
updatedByName: z.string().optional(),
|
||||
isDeleted: z.boolean().default(false),
|
||||
});
|
||||
|
||||
export const KnowledgeArticleListDataSchema = z.object({
|
||||
articles: z.array(KnowledgeArticleSchema),
|
||||
total: z.number().optional(),
|
||||
});
|
||||
|
||||
// ── 类型导出 ──────────────────────────────────────────────────────────────────
|
||||
|
||||
export type HosecloudStaff = z.infer<typeof HosecloudStaffSchema>;
|
||||
export type SealAiUser = z.infer<typeof SealAiUserSchema>;
|
||||
export type SealAiTenant = z.infer<typeof SealAiTenantSchema>;
|
||||
export type MeData = z.infer<typeof MeDataSchema>;
|
||||
export type Subscription = z.infer<typeof SubscriptionSchema>;
|
||||
export type Feature = z.infer<typeof FeatureSchema>;
|
||||
export type BillingStatusData = z.infer<typeof BillingStatusDataSchema>;
|
||||
export type DraftRule = z.infer<typeof DraftRuleSchema>;
|
||||
export type DraftRulesData = z.infer<typeof DraftRulesDataSchema>;
|
||||
export type PublishedRuleSnapshot = z.infer<typeof PublishedRuleSnapshotSchema>;
|
||||
export type RuleSetVersion = z.infer<typeof RuleSetVersionSchema>;
|
||||
export type PublishVersionData = z.infer<typeof PublishVersionDataSchema>;
|
||||
export type KnowledgeArticle = z.infer<typeof KnowledgeArticleSchema>;
|
||||
export type KnowledgeArticleListData = z.infer<typeof KnowledgeArticleListDataSchema>;
|
||||
Reference in new issue
Block a user