refactor: 移除 SealAI 相关业务域、认证与文档
This commit is contained in:
1 parent
31c2a112de
commit
2085a97e34
13 files changed
-785
No files matched your search
@@ -30,10 +30,6 @@
|
||||
- `enterprises/*.json` — 企业级静态配置
|
||||
- `~/.cache/ekb-mcp/tokens.json` — 动态 Token 缓存(自动刷新)
|
||||
|
||||
SealAI 子域使用独立 Bearer JWT,详细流程不要写在这里,见:
|
||||
|
||||
- [src/domains/sealai/README.sealai.md](./src/domains/sealai/README.sealai.md)
|
||||
|
||||
Platform 子域使用 EASO / Piper 独立认证,详细流程见:
|
||||
|
||||
- [src/domains/platform/README.platform.md](./src/domains/platform/README.platform.md)
|
||||
@@ -50,7 +46,6 @@ server.ts ──→ domains/ ──→ core/
|
||||
│ │ ├── config/ 企业配置管理
|
||||
│ │ └── http/ HTTP 客户端工厂
|
||||
│ │
|
||||
│ ├── sealai/ SealAI 域
|
||||
│ └── platform/ Platform 域
|
||||
│
|
||||
└── core/errors.ts 统一异常语义
|
||||
@@ -74,7 +69,6 @@ server.ts ──→ domains/ ──→ core/
|
||||
|
||||
常用子域入口:
|
||||
|
||||
- SealAI 说明:[src/domains/sealai/README.sealai.md](./src/domains/sealai/README.sealai.md)
|
||||
- Platform 说明:[src/domains/platform/README.platform.md](./src/domains/platform/README.platform.md)
|
||||
|
||||
## 开发与修改规则
|
||||
|
||||
@@ -43,15 +43,10 @@ src/
|
||||
├── core/ # 基础设施
|
||||
│ ├── config/ # 企业配置管理
|
||||
│ ├── auth/ # 认证(Token 缓存/刷新)
|
||||
│ │ ├── sealai.ts # SealAI SSO → JWT
|
||||
│ │ ├── easo.ts # EASO 四步认证
|
||||
│ │ └── piper.ts # Piper 三步认证
|
||||
│ └── http/ # HTTP 客户端工厂
|
||||
├── domains/ # 业务域
|
||||
│ ├── sealai/ # SealAI 域
|
||||
│ │ ├── types.ts
|
||||
│ │ ├── api.ts
|
||||
│ │ └── tools.ts
|
||||
│ └── platform/ # 自建应用/工作流域
|
||||
│ ├── types.ts
|
||||
│ ├── api.ts
|
||||
@@ -61,14 +56,6 @@ src/
|
||||
|
||||
## 已迁移功能
|
||||
|
||||
### SealAI
|
||||
- [x] 认证(SSO → JWT,内存+持久化缓存)
|
||||
- [x] 用户身份查询
|
||||
- [x] 计费/订阅查询
|
||||
- [x] 审核规则 CRUD
|
||||
- [x] 规则版本发布
|
||||
- [x] 知识文档 CRUD
|
||||
|
||||
### Platform
|
||||
- [x] 自建应用列表 (`platform_list`)
|
||||
- [x] EASO 四步认证
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
# SealAI 模块
|
||||
|
||||
## 概述
|
||||
|
||||
SealAI(`{corpId.lower()}.sealai.cc`)是独立于快报主站的 AI 填单/审批平台,
|
||||
采用 Next.js App Router + Kubernetes/Istio 后端,认证体系与快报 HAB 完全独立。
|
||||
|
||||
本模块已集成进 `ekb-mcp` MCP Server,代码位于:
|
||||
|
||||
```text
|
||||
src/domains/sealai/
|
||||
├── types.ts # Zod schema 与类型定义
|
||||
├── api.ts # HTTP 传输层(SealAI API 封装)
|
||||
└── tools.ts # MCP tool 注册
|
||||
```
|
||||
|
||||
## 认证机制
|
||||
|
||||
SealAI 使用独立的 Bearer JWT,通过快报 accesstoken SSO 换取:
|
||||
|
||||
```
|
||||
快报 accesstoken
|
||||
→ GET https://{corpId.lower()}.sealai.cc/api/auth/oauth2/session/oem-hosecloud
|
||||
?token={accesstoken}&returnToken=1
|
||||
→ Bearer JWT
|
||||
→ 缓存到 ~/.cache/ekb-mcp/tokens.json(TTL 1小时)
|
||||
→ SealAI HTTP client
|
||||
```
|
||||
|
||||
**关键细节:**
|
||||
- corpId 全小写作为子域名:`ID01Jdq2yIDnMr` → `id01jdq2yidnmr.sealai.cc`
|
||||
- token 自动缓存,内存 + 持久化,TTL 1 小时,到期自动重新换取
|
||||
- 遇到 401 调用 `clearSealaiToken(corpId)` 清除缓存后重试
|
||||
|
||||
## MCP Tools
|
||||
|
||||
| Tool | 说明 |
|
||||
|---|---|
|
||||
| `sealai_whoami` | 当前用户身份(user + tenant) |
|
||||
| `sealai_billing` | 订阅状态 + 各功能配额 |
|
||||
| `sealai_rules_list` | 草稿区审核规则列表 |
|
||||
| `sealai_rule_create` | 新建草稿审核规则 |
|
||||
| `sealai_rule_update` | 更新草稿审核规则(partial) |
|
||||
| `sealai_rule_delete` | 删除草稿审核规则 |
|
||||
| `sealai_versions_list` | 已发布规则集版本历史 |
|
||||
| `sealai_version_publish` | 发布草稿规则为新版本 |
|
||||
| `sealai_knowledge_list` | 知识文档列表 |
|
||||
| `sealai_knowledge_get` | 知识文档详情 |
|
||||
| `sealai_knowledge_create` | 新建知识文档 |
|
||||
| `sealai_knowledge_update` | 更新知识文档 |
|
||||
|
||||
## 数据模型
|
||||
|
||||
### DraftRule(草稿规则)
|
||||
|
||||
```typescript
|
||||
{
|
||||
id: string;
|
||||
description: string; // 规则描述
|
||||
scope: string; // 适用场景(自由文本)
|
||||
strictness: string; // MUST_FOLLOW | SHOULD_FOLLOW | SUGGESTION
|
||||
status: string; // 固定为 "DRAFT"
|
||||
createdAt: number; // 毫秒时间戳
|
||||
updatedAt: number;
|
||||
}
|
||||
```
|
||||
|
||||
### RuleSetVersion(已发布版本)
|
||||
|
||||
```typescript
|
||||
{
|
||||
id: string;
|
||||
versionNumber: number;
|
||||
versionName: string; // 如 "审核规则 版本4"
|
||||
publishedByName: string;
|
||||
publishedAt: number; // 毫秒时间戳
|
||||
rules: PublishedRuleSnapshot[]; // 快照,不可变
|
||||
}
|
||||
```
|
||||
|
||||
### strictness 枚举
|
||||
|
||||
| 值 | 含义 |
|
||||
|----|----|
|
||||
| `MUST_FOLLOW` | 必须遵守 |
|
||||
| `SHOULD_FOLLOW` | 应当遵守 |
|
||||
| `SUGGESTION` | 建议 |
|
||||
|
||||
### Feature(功能配额)三种形态
|
||||
|
||||
| 形态 | 字段 | 示例 code |
|
||||
|------|------|-----------|
|
||||
| 余额型 | `balance / totalQuota / totalUsed` | `ai-approval` |
|
||||
| 配额型 | `quota / used / remaining` | `approval-rules` |
|
||||
| 开关型 | `enabled` | `ai-fill`, `webhook` |
|
||||
@@ -10,7 +10,6 @@ src/core/
|
||||
│ ├── ekb.ts # 快报主站三 Header 认证
|
||||
│ ├── easo.ts # EASO(unity.ekuaibao.com)四步认证
|
||||
│ ├── piper.ts # Piper(piper.ekuaibao.com)三步认证
|
||||
│ ├── sealai.ts # SealAI SSO → JWT
|
||||
│ ├── token-store.ts # 持久化 Token 缓存(~/.cache/ekb-mcp/tokens.json)
|
||||
│ └── types.ts
|
||||
├── config/ # 企业配置管理
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
import ky from "ky";
|
||||
import { CorpConfig } from "../config/types.js";
|
||||
import { createAuthClient } from "../http/factory.js";
|
||||
import { TokenEntry } from "./types.js";
|
||||
import { getCorpTokens, setCorpTokens, clearCorpTokens } from "./token-store.js";
|
||||
import { AuthenticationError } from "../errors.js";
|
||||
|
||||
// 内存缓存
|
||||
const memoryCache = new Map<string, TokenEntry>();
|
||||
|
||||
function isExpired(entry: TokenEntry, refreshTtl: number): boolean {
|
||||
return Date.now() >= entry.expiresAt - refreshTtl * 1000;
|
||||
}
|
||||
|
||||
export async function getSealaiToken(corp: CorpConfig): Promise<string> {
|
||||
const refreshTtl = corp.auth?.refreshTtl ?? 300;
|
||||
const cacheKey = `${corp.id}:sealai`;
|
||||
|
||||
// 1. 检查内存缓存
|
||||
const mem = memoryCache.get(cacheKey);
|
||||
if (mem && !isExpired(mem, refreshTtl)) {
|
||||
return mem.token;
|
||||
}
|
||||
|
||||
// 2. 检查持久化缓存
|
||||
const stored = getCorpTokens(corp.id);
|
||||
if (stored?.sealai && !isExpired(stored.sealai, refreshTtl)) {
|
||||
memoryCache.set(cacheKey, stored.sealai);
|
||||
return stored.sealai.token;
|
||||
}
|
||||
|
||||
// 3. 重新换取
|
||||
const sealaiUrl =
|
||||
corp.sealaiUrl || `https://${corp.credentials.corpId.toLowerCase()}.sealai.cc`;
|
||||
|
||||
const response = await ky
|
||||
.get(`${sealaiUrl}/api/auth/oauth2/session/oem-hosecloud`, {
|
||||
searchParams: {
|
||||
token: corp.credentials.accessToken,
|
||||
returnToken: "1",
|
||||
},
|
||||
})
|
||||
.json<{ token: string; expiresIn: number }>();
|
||||
|
||||
if (!response.token) {
|
||||
throw new AuthenticationError("Failed to exchange SealAI token");
|
||||
}
|
||||
|
||||
const entry: TokenEntry = {
|
||||
token: response.token,
|
||||
expiresAt: Date.now() + response.expiresIn * 1000,
|
||||
};
|
||||
|
||||
// 4. 更新内存 + 持久化
|
||||
memoryCache.set(cacheKey, entry);
|
||||
setCorpTokens(corp.id, {
|
||||
...stored,
|
||||
sealai: entry,
|
||||
});
|
||||
|
||||
return entry.token;
|
||||
}
|
||||
|
||||
export function clearSealaiToken(corpId: string): void {
|
||||
const cacheKey = `${corpId}:sealai`;
|
||||
memoryCache.delete(cacheKey);
|
||||
clearCorpTokens(corpId);
|
||||
}
|
||||
|
||||
export async function createSealaiClient(corp: CorpConfig) {
|
||||
const sealaiUrl =
|
||||
corp.sealaiUrl || `https://${corp.credentials.corpId.toLowerCase()}.sealai.cc`;
|
||||
|
||||
return createAuthClient({
|
||||
prefixUrl: sealaiUrl,
|
||||
getHeaders: async () => ({
|
||||
Authorization: `Bearer ${await getSealaiToken(corp)}`,
|
||||
}),
|
||||
onUnauthorized: () => {
|
||||
clearSealaiToken(corp.id);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -6,7 +6,6 @@ export const TokenEntrySchema = z.object({
|
||||
});
|
||||
|
||||
export const CorpTokensSchema = z.object({
|
||||
sealai: TokenEntrySchema.optional(),
|
||||
eas: z.object({
|
||||
hoseToken: z.string(),
|
||||
unityJwt: z.string(),
|
||||
|
||||
@@ -14,7 +14,6 @@ export const CorpConfigSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
baseUrl: z.string().url().optional(), // 默认 https://app.ekuaibao.com
|
||||
sealaiUrl: z.string().optional(), // 默认 https://{corpId}.sealai.cc
|
||||
credentials: CorpCredentialsSchema,
|
||||
auth: CorpAuthConfigSchema.optional(),
|
||||
});
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
| 域 | 说明 | 详细文档 |
|
||||
|---|---|---|
|
||||
| `platform/` | 自建应用(DataLink Platform)与工作流(EASO/Piper) | [README.platform.md](./platform/README.platform.md) |
|
||||
| `sealai/` | SealAI 独立子域(AI 填单/审批) | [README.sealai.md](./sealai/README.sealai.md) |
|
||||
|
||||
## 分层规则
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
# SealAI 域说明
|
||||
|
||||
SealAI 域负责 `{corpId.lower()}.sealai.cc` 独立子站的 AI 填单/审批能力。
|
||||
|
||||
## 代码结构
|
||||
|
||||
```text
|
||||
src/domains/sealai/
|
||||
├── types.ts # Zod schema 与类型定义
|
||||
├── api.ts # HTTP 传输层
|
||||
└── tools.ts # MCP tool 注册
|
||||
```
|
||||
|
||||
## 详细文档
|
||||
|
||||
完整认证说明、MCP tool 列表、数据模型见:
|
||||
|
||||
[docs/modules/sealai.md](../../../docs/modules/sealai.md)
|
||||
@@ -1,182 +0,0 @@
|
||||
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);
|
||||
}
|
||||
@@ -1,196 +0,0 @@
|
||||
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];
|
||||
@@ -1,159 +0,0 @@
|
||||
import { z } from "zod";
|
||||
|
||||
// ── 认证 ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
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>;
|
||||
@@ -9,9 +9,7 @@ import { loadCorpConfigs } from "./core/config/loader.js";
|
||||
import { CorpContext } from "./core/config/manager.js";
|
||||
import { createEkbClient } from "./core/auth/ekb.js";
|
||||
import { getEasoClient } from "./core/auth/easo.js";
|
||||
import { createSealaiClient } from "./core/auth/sealai.js";
|
||||
import { AuthenticationError, EkbError, NotLoggedInError } from "./core/errors.js";
|
||||
import { sealaiTools } from "./domains/sealai/tools.js";
|
||||
import { platformTools } from "./domains/platform/tools.js";
|
||||
|
||||
const SwitchCorpSchema = z.object({
|
||||
@@ -84,12 +82,6 @@ async function main() {
|
||||
description: "切换到指定企业",
|
||||
inputSchema: (SwitchCorpSchema as any).toJSONSchema(),
|
||||
},
|
||||
// SealAI 工具
|
||||
...sealaiTools.map((t) => ({
|
||||
name: t.name,
|
||||
description: t.description,
|
||||
inputSchema: (t.parameters as any).toJSONSchema(),
|
||||
})),
|
||||
// Platform 工具
|
||||
...platformTools.map((t) => ({
|
||||
name: t.name,
|
||||
@@ -147,27 +139,6 @@ async function main() {
|
||||
}
|
||||
|
||||
try {
|
||||
// SealAI 工具
|
||||
const sealaiTool = sealaiTools.find((t) => t.name === name);
|
||||
if (sealaiTool) {
|
||||
const parsed = sealaiTool.parameters.safeParse(args);
|
||||
if (!parsed.success) {
|
||||
return {
|
||||
content: [{ type: "text", text: `参数错误: ${parsed.error.message}` }],
|
||||
isError: true,
|
||||
};
|
||||
}
|
||||
const client = await createSealaiClient(currentCorp);
|
||||
const result = await sealaiTool.handler(client, parsed.data as never);
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: JSON.stringify(result, null, 2),
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
// Platform 工具
|
||||
const platformTool = platformTools.find((t) => t.name === name);
|
||||
|
||||
Reference in new issue
Block a user