refactor: 全面转向 CLI 驱动架构与底层 SDK,裁撤繁杂 MCP 工具并参考 seal-home 规范

This commit is contained in:
gitea committed 2026-08-27 10:56:45 +08:00
1 parent 3d549e2e2f
commit e7aa8a86cc
19 files changed
+1228 -589

No files matched your search

+96
View File
@@ -0,0 +1,96 @@
import { createClientsForCorp } from "../helpers.js";
import * as api from "../../domains/platform/api.js";
import { printJson, printKeyValue } from "../printer.js";
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
export async function handleProbeCommand(
parsed: CliParsedArgs,
runtime: CliRuntime
): Promise<CliResult> {
const currentCorp = runtime.selectedCorp;
if (!currentCorp) {
return {
stdout: "",
stderr: "未配置任何企业,请先运行 hose auth login 或使用 --corp 指定\n",
exitCode: 1,
};
}
const results: Record<string, unknown> = {
enterprise: {
id: currentCorp.id,
name: currentCorp.name,
staffId: currentCorp.credentials.staffId,
baseUrl: currentCorp.baseUrl,
source: currentCorp.source,
accountId: currentCorp.accountId,
},
ekbSession: { status: "pending" },
easoToken: { status: "pending" },
platformAccess: { status: "pending" },
};
try {
const clients = await createClientsForCorp(currentCorp);
// 1. 测试 EKB 主站 Session
try {
const sessionRes = await clients.ekbClient
.get("api/account/v2/session")
.json<{ value?: { userId?: string; loginStaffId?: string; expTime?: number } }>();
results.ekbSession = {
status: "ok",
userId: sessionRes.value?.userId,
loginStaffId: sessionRes.value?.loginStaffId,
expTime: sessionRes.value?.expTime ? new Date(sessionRes.value.expTime).toLocaleString() : undefined,
};
} catch (e) {
results.ekbSession = {
status: "error",
error: e instanceof Error ? e.message : String(e),
};
}
// 2. 测试 EASO Token 换取
try {
const platforms = await api.listPlatforms(clients.ekbClient, currentCorp.credentials.corpId);
results.platformAccess = {
status: "ok",
totalPlatforms: platforms.length,
};
const stats = await api.getWorkflowStats(clients.easoClient, platforms[0]?.id || "platform");
results.easoToken = {
status: "ok",
message: "EASO 四步换票握手成功",
};
} catch (e) {
results.easoToken = {
status: "error",
error: e instanceof Error ? e.message : String(e),
};
}
} catch (error) {
results.error = error instanceof Error ? error.message : String(error);
}
if (runtime.jsonMode) {
return { stdout: printJson(results), stderr: "", exitCode: 0 };
}
const summary = printKeyValue({
"企业名称": currentCorp.name,
"企业 ID": currentCorp.id,
"员工工号": currentCorp.credentials.staffId,
"主站 Session 连通": (results.ekbSession as any).status === "ok" ? "🟢 正常" : "🔴 异常",
"EASO 引擎鉴权换票": (results.easoToken as any).status === "ok" ? "🟢 握手成功" : "🔴 失败",
"自建应用扫描": (results.platformAccess as any).status === "ok" ? `🟢 可访问 (${(results.platformAccess as any).totalPlatforms} 个自建应用)` : "🔴 失败",
});
return {
stdout: `====== 诊断结果 (Enterprise Probe) ======\n${summary}\n`,
stderr: "",
exitCode: 0,
};
}