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,21 @@
|
||||
import { readFileSync, readdirSync } from "fs";
|
||||
import { join } from "path";
|
||||
import { CorpConfig, CorpConfigSchema } from "./types";
|
||||
|
||||
const ENTERPRISES_DIR = "./enterprises";
|
||||
|
||||
export function loadCorpConfigs(): CorpConfig[] {
|
||||
try {
|
||||
const files = readdirSync(ENTERPRISES_DIR).filter((f) =>
|
||||
f.endsWith(".json")
|
||||
);
|
||||
|
||||
return files.map((file) => {
|
||||
const content = readFileSync(join(ENTERPRISES_DIR, file), "utf-8");
|
||||
const parsed = JSON.parse(content);
|
||||
return CorpConfigSchema.parse(parsed);
|
||||
});
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { CorpConfig } from "./types";
|
||||
|
||||
export class CorpContext {
|
||||
private current: CorpConfig | null = null;
|
||||
private corps: Map<string, CorpConfig> = new Map();
|
||||
|
||||
constructor(corps: CorpConfig[]) {
|
||||
for (const corp of corps) {
|
||||
this.corps.set(corp.id, corp);
|
||||
}
|
||||
if (corps.length > 0) {
|
||||
this.current = corps[0];
|
||||
}
|
||||
}
|
||||
|
||||
getCurrent(): CorpConfig | null {
|
||||
return this.current;
|
||||
}
|
||||
|
||||
switchCorp(corpId: string): boolean {
|
||||
const corp = this.corps.get(corpId);
|
||||
if (!corp) return false;
|
||||
this.current = corp;
|
||||
return true;
|
||||
}
|
||||
|
||||
listCorps(): Array<{ id: string; name: string; current: boolean }> {
|
||||
return Array.from(this.corps.values()).map((corp) => ({
|
||||
id: corp.id,
|
||||
name: corp.name,
|
||||
current: corp.id === this.current?.id,
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const CorpCredentialsSchema = z.object({
|
||||
accessToken: z.string(),
|
||||
corpId: z.string(),
|
||||
staffId: z.string(),
|
||||
});
|
||||
|
||||
export const CorpAuthConfigSchema = z.object({
|
||||
refreshTtl: z.number().default(300), // 提前多少秒刷新,默认 5 分钟
|
||||
});
|
||||
|
||||
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(),
|
||||
});
|
||||
|
||||
export type CorpCredentials = z.infer<typeof CorpCredentialsSchema>;
|
||||
export type CorpAuthConfig = z.infer<typeof CorpAuthConfigSchema>;
|
||||
export type CorpConfig = z.infer<typeof CorpConfigSchema>;
|
||||
Reference in new issue
Block a user