Merge pull request #83 from yunyingk/refactor/complete-semantic-cleanup

refactor(core): 全量语义化客户端迁移并移除历史兼容桥接层
This commit is contained in:
yunyingk authored and GitHub committed 2026-09-17 15:44:45 +08:00
commit 7e16a6a312
34 files changed
+89 -141

No files matched your search

+3 -3
View File
@@ -2,7 +2,7 @@
import { parseArgs, stringOption, booleanOption, numberOption } from "./cli/parser.js";
import { printJson, printTable, redactSensitiveText, formatExpiresAt } from "./cli/printer.js";
import { initCorpRuntime } from "./cli/helpers.js";
import { createEkbClient } from "./core/auth/ekb.js";
import { createSessionClient } from "./core/http/session-client.js";
import {
ApprovalService,
ApprovalRepository,
@@ -29,7 +29,7 @@ export async function runAiProCli(rawArgs: string[]): Promise<{ stdout: string;
const corp = runtime.selectedCorp;
const repo = new ApprovalRepository();
const service = new ApprovalService(repo);
let client: Awaited<ReturnType<typeof createEkbClient>> | undefined;
let client: Awaited<ReturnType<typeof createSessionClient>> | undefined;
const positional: string[] = [];
for (let i = 0; i < rawArgs.length; i++) {
@@ -69,7 +69,7 @@ export async function runAiProCli(rawArgs: string[]): Promise<{ stdout: string;
const getClient = async () => {
const activeCorpId = requireCorpId();
if (!corp) throw new Error("未找到当前企业配置");
client ??= await createEkbClient(corp);
client ??= await createSessionClient(corp);
return { client, corpId: activeCorpId };
};
+2 -2
View File
@@ -1,7 +1,7 @@
import { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
import { printJson, printTable } from "../printer.js";
import { stringOption, booleanOption, numberOption } from "../parser.js";
import { createEkbClient } from "../../core/auth/ekb.js";
import { createSessionClient } from "../../core/http/session-client.js";
import {
ApprovalService,
ApprovalGatewayBlockedError,
@@ -19,7 +19,7 @@ export async function handleApprovalCommand(
);
}
const client = await createEkbClient(corp);
const client = await createSessionClient(corp);
const corpId = corp.corpId || corp.id;
const service = new ApprovalService();
+2 -2
View File
@@ -14,7 +14,7 @@ import {
getActiveAccount,
setActiveAccount,
} from "../../core/auth/account-store.js";
import { createEkbClient } from "../../core/auth/ekb.js";
import { createSessionClient } from "../../core/http/session-client.js";
import { stringOption, booleanOption } from "../parser.js";
import { printJson, printKeyValue, printTable, formatSourceLabel, formatExpiresAt } from "../printer.js";
import { prompt } from "../helpers.js";
@@ -166,7 +166,7 @@ async function handleStatus(parsed: CliParsedArgs, runtime: CliRuntime): Promise
if (currentCorp) {
try {
const client = await createEkbClient(currentCorp);
const client = await createSessionClient(currentCorp);
const res = await client.get("api/account/v2/session").json<{ value?: unknown }>();
sessionValid = !!res.value;
sessionData = res.value;
+3 -3
View File
@@ -1,7 +1,7 @@
import { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
import { printJson, printTable } from "../printer.js";
import { booleanOption, stringOption, numberOption } from "../parser.js";
import { createEkbClient } from "../../core/auth/ekb.js";
import { createSessionClient } from "../../core/http/session-client.js";
import {
searchAndFormatBills,
getBillByCodeOrId,
@@ -35,9 +35,9 @@ export async function handleBillCommand(
const action = parsed.action?.toLowerCase();
const corpId = corp.corpId || corp.id;
let client: Awaited<ReturnType<typeof createEkbClient>> | undefined;
let client: Awaited<ReturnType<typeof createSessionClient>> | undefined;
const getClient = async () => {
client ??= await createEkbClient(corp);
client ??= await createSessionClient(corp);
return client;
};
+2 -2
View File
@@ -1,6 +1,6 @@
import { describe, it, expect } from "bun:test";
import { parseHeadersOrCurl } from "../../core/auth/login.js";
import { resolveCorpCluster } from "../../core/auth/easo.js";
import { resolveCorpCluster } from "../../core/http/unity-client.js";
import { handleCorpsCommand } from "./corps.js";
import type { CliRuntime } from "../types.js";
@@ -34,7 +34,7 @@ describe("core/auth/login > parseHeadersOrCurl & URL link parsing", () => {
});
});
describe("core/auth/easo > resolveCorpCluster", () => {
describe("core/http/unity-client > resolveCorpCluster", () => {
it("prioritizes explicit cluster config", () => {
expect(resolveCorpCluster({ cluster: "wx2", baseUrl: "https://app.ekuaibao.com" })).toBe("wx2");
});
+2 -2
View File
@@ -1,13 +1,13 @@
import { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
import { printJson, printTable } from "../printer.js";
import { numberOption, stringOption } from "../parser.js";
import { createEkbClient } from "../../core/auth/ekb.js";
import { createSessionClient } from "../../core/http/session-client.js";
import { searchDimensions, resolveDimension } from "../../domains/dimension/tools.js";
export async function handleDimensionCommand(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
const corp = runtime.selectedCorp;
if (!corp) throw new Error("未指定或未找到有效企业。请通过 --corp=<id> 指定企业,或运行 hose-use auth login 登录。");
const client = await createEkbClient(corp);
const client = await createSessionClient(corp);
const corpId = corp.corpId || corp.id;
const action = parsed.action?.toLowerCase() || "list";
if (["list", "search", "catalogs", undefined].includes(action)) {
+3 -3
View File
@@ -1,7 +1,7 @@
import { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
import { printJson, printTable } from "../printer.js";
import { booleanOption, stringOption } from "../parser.js";
import { createEkbClient } from "../../core/auth/ekb.js";
import { createSessionClient } from "../../core/http/session-client.js";
import {
createFeeType,
disableFeeTypeItem,
@@ -68,9 +68,9 @@ export async function handleFeeTypeCommand(
const corpId = corp.corpId || corp.id;
const action = (parsed.action?.toLowerCase() || "list").trim();
let client: Awaited<ReturnType<typeof createEkbClient>> | undefined;
let client: Awaited<ReturnType<typeof createSessionClient>> | undefined;
const getClient = async () => {
client ??= await createEkbClient(corp);
client ??= await createSessionClient(corp);
return client;
};
+5 -5
View File
@@ -1,7 +1,7 @@
import { booleanOption, numberOption, stringOption } from "../parser.js";
import { printJson, printTable } from "../printer.js";
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
import { createEkbClient } from "../../core/auth/ekb.js";
import { createSessionClient } from "../../core/http/session-client.js";
import { filterMessages, listMessages, mergeMessages, readMessage } from "../../domains/message/tools.js";
import type { MessageItem } from "../../domains/message/types.js";
import { isDryRun, mutationPreview, requireMutationConfirmation } from "../mutation.js";
@@ -30,7 +30,7 @@ export async function handleMessageCommand(parsed: CliParsedArgs, runtime: CliRu
const corpId = corp.corpId || corp.id;
if (action === "count" || action === "unread") {
const client = await createEkbClient(corp);
const client = await createSessionClient(corp);
const result = await listMessages(client, corpId, { start: 0, count: 1, read: false });
if (runtime.jsonMode) return { stdout: printJson({ corpId, unread: result.total }, runtime.outputOptions), stderr: "", exitCode: 0 };
return { stdout: `未读消息: ${result.total}\n`, stderr: "", exitCode: 0 };
@@ -43,7 +43,7 @@ export async function handleMessageCommand(parsed: CliParsedArgs, runtime: CliRu
return mutationPreview(parsed, runtime, "标记消息为已读", messageId, { read: true });
}
requireMutationConfirmation(parsed, runtime, "标记消息为已读", `hose-use message read ${messageId} --yes`);
const client = await createEkbClient(corp);
const client = await createSessionClient(corp);
await readMessage(client, corpId, messageId);
if (runtime.jsonMode) return { stdout: printJson({ corpId, id: messageId, read: true }, runtime.outputOptions), stderr: "", exitCode: 0 };
return { stdout: `已标记消息为已读: ${messageId}\n`, stderr: "", exitCode: 0 };
@@ -54,7 +54,7 @@ export async function handleMessageCommand(parsed: CliParsedArgs, runtime: CliRu
return mutationPreview(parsed, runtime, "批量标记未读消息为已读", `corp:${corpId}`, { read: true, allUnread: true });
}
requireMutationConfirmation(parsed, runtime, "批量标记未读消息为已读", "hose-use message read-all --yes");
const client = await createEkbClient(corp);
const client = await createSessionClient(corp);
const ids: string[] = [];
let start = 0;
let total = 0;
@@ -74,7 +74,7 @@ export async function handleMessageCommand(parsed: CliParsedArgs, runtime: CliRu
return { stdout: "", stderr: `未知消息子命令: ${action}。支持: list, count, read <messageId>, read-all\n`, exitCode: 1 };
}
const client = await createEkbClient(corp);
const client = await createSessionClient(corp);
const read = booleanOption(parsed.options, ["read"]);
const unread = booleanOption(parsed.options, ["unread"]);
+2 -2
View File
@@ -1,6 +1,6 @@
import { printJson, printTable } from "../printer.js";
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
import { createEkbClient } from "../../core/auth/ekb.js";
import { createSessionClient } from "../../core/http/session-client.js";
import { getPermissions } from "../../domains/permission/tools.js";
export async function handlePermissionCommand(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
@@ -8,7 +8,7 @@ export async function handlePermissionCommand(parsed: CliParsedArgs, runtime: Cl
if (!corp) throw new Error("未指定或未找到有效企业。请通过 --corp=<id> 指定企业,或运行 hose-use auth login 登录。");
const action = parsed.action?.toLowerCase() || "get";
if (!["get", "list", "show"].includes(action)) throw new Error(`未知 permission 子命令: ${action}。支持: get`);
const client = await createEkbClient(corp);
const client = await createSessionClient(corp);
const report = await getPermissions(client, corp.corpId || corp.id);
if (runtime.jsonMode) return { stdout: printJson({ corpId: corp.corpId || corp.id, corpName: corp.name, ...report }, runtime.outputOptions), stderr: "", exitCode: 0 };
const rows = report.permissions.map((item) => [item.name, item.auth ? "启用" : "停用"]);
+6 -7
View File
@@ -1,5 +1,4 @@
import { createEkbClient } from "../../core/auth/ekb.js";
import { getEasoClient } from "../../core/auth/easo.js";
import { createSessionClient, getEasoClient } from "../../core/http/index.js";
import * as api from "../../domains/platform/api.js";
import { printJson, printKeyValue, formatSourceLabel, formatExpiresAt } from "../printer.js";
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
@@ -32,10 +31,10 @@ export async function handleProbeCommand(
};
// 1. 独立测试 EKB 主站 Session
let ekbClient: Awaited<ReturnType<typeof createEkbClient>> | null = null;
let sessionClient: Awaited<ReturnType<typeof createSessionClient>> | null = null;
try {
ekbClient = await createEkbClient(currentCorp);
const sessionRes = await ekbClient
sessionClient = await createSessionClient(currentCorp);
const sessionRes = await sessionClient
.get("api/account/v2/session")
.json<{ value?: { userId?: string; loginStaffId?: string; expTime?: number } }>();
@@ -54,9 +53,9 @@ export async function handleProbeCommand(
// 2. 独立测试自建应用列表访问
let platforms: any[] = [];
if (ekbClient) {
if (sessionClient) {
try {
platforms = await api.listPlatforms(ekbClient, currentCorp.credentials.corpId);
platforms = await api.listPlatforms(sessionClient, currentCorp.credentials.corpId);
results.platformAccess = {
status: "ok",
totalPlatforms: platforms.length,
+2 -2
View File
@@ -1,13 +1,13 @@
import { numberOption, stringOption } from "../parser.js";
import { printJson, printTable } from "../printer.js";
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
import { createEkbClient } from "../../core/auth/ekb.js";
import { createSessionClient } from "../../core/http/session-client.js";
import { getRoleGroups, getRoleMembers, searchRoles } from "../../domains/role/tools.js";
export async function handleRoleCommand(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
const corp = runtime.selectedCorp;
if (!corp) throw new Error("未指定或未找到有效企业。请通过 --corp=<id> 指定企业,或运行 hose-use auth login 登录。");
const client = await createEkbClient(corp), corpId = corp.corpId || corp.id;
const client = await createSessionClient(corp), corpId = corp.corpId || corp.id;
const action = parsed.action?.toLowerCase() || "list";
if (["list", "search"].includes(action)) {
const keyword = stringOption(parsed.options, ["keyword", "q", "query"]) || parsed.args[0];
+2 -2
View File
@@ -5,7 +5,7 @@ import { runServiceCommand, ServiceConfig, getPidFile, getLogFile } from "../ser
import { printJson, printKeyValue } from "../printer.js";
import { numberOption, stringOption } from "../parser.js";
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
import { createEkbClient } from "../../core/auth/ekb.js";
import { createSessionClient } from "../../core/http/session-client.js";
import { EventStore } from "../../domains/events/store.js";
import { pollEvents } from "../../domains/events/poller.js";
@@ -23,7 +23,7 @@ export async function handleServiceCommand(
const corp = runtime.selectedCorp;
if (!corp) throw new Error("事件轮询需要企业上下文,请通过 --corp=<id> 指定企业。");
const corpId = corp.corpId || corp.id;
const client = await createEkbClient(corp);
const client = await createSessionClient(corp);
const limit = numberOption(parsed.options, ["limit", "count", "n"], 50) || 50;
const store = new EventStore(join(SERVICE_STATE_DIR, `events-${corpId}.json`));
const result = await pollEvents(client, corpId, store, limit);
+2 -2
View File
@@ -1,7 +1,7 @@
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
import { booleanOption, numberOption, stringOption } from "../parser.js";
import { printJson, printTable } from "../printer.js";
import { createEkbClient } from "../../core/auth/ekb.js";
import { createSessionClient } from "../../core/http/session-client.js";
import { listTasks } from "../../domains/task/tools.js";
import type { TaskView } from "../../domains/task/types.js";
@@ -40,7 +40,7 @@ export async function handleTaskCommand(parsed: CliParsedArgs, runtime: CliRunti
const unread = booleanOption(parsed.options, ["unread"]);
// Carbon copy defaults to unread, while the other views do not use this flag.
const readFilter = view === "cc" ? read && !unread : undefined;
const result = await listTasks(await createEkbClient(corp), corp.corpId || corp.id, view, { start, count, staffId, from, to, read: readFilter });
const result = await listTasks(await createSessionClient(corp), corp.corpId || corp.id, view, { start, count, staffId, from, to, read: readFilter });
if (runtime.jsonMode) {
return { stdout: printJson({ corpId: corp.corpId || corp.id, corpName: corp.name, ...result }, runtime.outputOptions), stderr: "", exitCode: 0 };
+15 -9
View File
@@ -2,9 +2,11 @@ import readline from "readline";
import { loadCorpConfigs, loadGlobalConfig, getEnterprisesDirCandidates } from "../core/config/loader.js";
import { CorpContext, resolveCorpConfig } from "../core/config/manager.js";
import { CorpConfig } from "../core/config/types.js";
import { createEkbClient } from "../core/auth/ekb.js";
import { getEasoClient } from "../core/auth/easo.js";
import { getPiperClient } from "../core/auth/piper.js";
import {
createSessionClient,
getUnityClient,
getScriptEngineClient,
} from "../core/http/index.js";
import { CliRuntime, OutputOptions } from "./types.js";
export function initCorpRuntime(
@@ -60,19 +62,23 @@ export function initCorpRuntime(
}
export async function createClientsForCorp(corp: CorpConfig) {
const ekbClient = await createEkbClient(corp);
const { client: easoClient } = await getEasoClient(corp);
const sessionClient = await createSessionClient(corp);
const { client: unityClient } = await getUnityClient(corp);
return {
corp,
ekbClient,
easoClient,
sessionClient,
ekbClient: sessionClient,
unityClient,
easoClient: unityClient,
};
}
export async function createPiperClientForCorp(corp: CorpConfig, platformId: string) {
return getPiperClient(corp, platformId);
export async function createScriptEngineClientForCorp(corp: CorpConfig, platformId: string) {
return getScriptEngineClient(corp, platformId);
}
export const createPiperClientForCorp = createScriptEngineClientForCorp;
export function prompt(question: string): Promise<string> {
const rl = readline.createInterface({
input: process.stdin,
+1 -4
View File
@@ -11,10 +11,7 @@ src/core/
│ ├── account-store.ts # 多账号持久化存储 (~/.cache/ekb-mcp/accounts.json)
│ ├── tools.ts # MCP Auth Tools 注册与调度
│ ├── token-store.ts # 动态 Token 缓存(兼容 ~/.config/hose-use/tokens.json 与历史路径)
│ ├── types.ts
│ ├── ekb.ts # 【向后兼容桥接】re-export http/session-client.js
│ ├── easo.ts # 【向后兼容桥接】re-export http/unity-client.js
│ └── piper.ts # 【向后兼容桥接】re-export http/script-engine-client.js
│ └── types.ts
├── http/ # 统一 HTTP 客户端装配与网络传输(语义化客户端)
│ ├── factory.ts # Ky 底层客户端工厂(超时、重试、错误钩子)
│ ├── fingerprint.ts # 统一浏览器指纹、User-Agent、Cookie 与 WAF 策略头
-14
View File
@@ -1,14 +0,0 @@
/**
* @deprecated 兼容历史导出。请优先从 "src/core/http/index.js" 导入 getUnityClient 与 getEasoClient
*/
export {
resolveCorpCluster,
fetchUnityJwt,
fetchHoseToken,
fetchEasoRealmToken,
getEasoClient,
getUnityClient,
EASO_BASE_URL,
BUSINESS_CENTER_URL,
EKB_BASE_URL,
} from "../http/unity-client.js";
-10
View File
@@ -1,10 +0,0 @@
/**
* @deprecated 兼容历史导出。请优先从 "src/core/http/index.js" 导入 createSessionClient 与 getSessionHeaders
*/
export {
createSessionClient,
getSessionHeaders,
createEkbClient,
getEkbHeaders,
type CreateSessionClientOptions,
} from "../http/session-client.js";
+1 -1
View File
@@ -5,7 +5,7 @@ import { join } from "node:path";
import { AuthenticationError } from "../errors.js";
import { CorpConfig } from "../config/types.js";
import { saveCorpConfig, saveMultipleCorpConfigs, resolveWritableEnterprisesDir } from "../config/loader.js";
import { resolveCorpCluster } from "./easo.js";
import { resolveCorpCluster } from "../http/unity-client.js";
import {
saveAccount,
getAccount,
-10
View File
@@ -1,10 +0,0 @@
/**
* @deprecated 兼容历史导出。请优先从 "src/core/http/index.js" 导入 getScriptEngineClient 与 getPiperClient
*/
export {
getScriptEngineClient,
getPiperClient,
fetchEasoJwt,
SCRIPT_ENGINE_BASE_URL,
PIPER_BASE_URL,
} from "../http/script-engine-client.js";
+2 -2
View File
@@ -1,6 +1,6 @@
import { z } from "zod";
import { CorpContext } from "../config/manager.js";
import { createEkbClient } from "./ekb.js";
import { createSessionClient } from "../http/session-client.js";
// ── 精简 MCP Auth Tools (其余复杂登录/刷新均由 CLI 直接提供) ───────────────────
@@ -54,7 +54,7 @@ export const authTools = [
let sessionValid = false;
let sessionData: unknown = null;
try {
const client = await createEkbClient(current);
const client = await createSessionClient(current);
const res = await client.get("api/account/v2/session").json<{ value?: unknown }>();
sessionData = res.value;
sessionValid = !!res.value;
+6 -10
View File
@@ -8,14 +8,13 @@ import {
import {
getSessionHeaders,
createSessionClient,
createEkbClient,
} from "./session-client.js";
import {
createOpenApiClient,
getOpenApiHeaders,
} from "./openapi-client.js";
import { resolveCorpCluster } from "./unity-client.js";
import { getScriptEngineClient, getPiperClient } from "./script-engine-client.js";
import { getScriptEngineClient } from "./script-engine-client.js";
import type { CorpConfig } from "../config/types.js";
function mockCorp(overrides: Partial<CorpConfig> = {}): CorpConfig {
@@ -69,13 +68,10 @@ describe("core/http/session-client", () => {
expect(headers["Origin"]).toBe(DEFAULT_ORIGIN);
});
it("createSessionClient and createEkbClient alias produce valid clients", async () => {
it("createSessionClient produces valid client", async () => {
const corp = mockCorp();
const client1 = await createSessionClient(corp);
const client2 = await createEkbClient(corp);
expect(client1).toBeDefined();
expect(client2).toBeDefined();
const client = await createSessionClient(corp);
expect(client).toBeDefined();
});
});
@@ -110,7 +106,7 @@ describe("core/http/unity-client & script-engine-client", () => {
expect(resolveCorpCluster({})).toBe("app");
});
it("getPiperClient alias points to getScriptEngineClient", () => {
expect(getPiperClient).toBe(getScriptEngineClient);
it("getScriptEngineClient is defined and callable", () => {
expect(getScriptEngineClient).toBeDefined();
});
});
-3
View File
@@ -24,8 +24,6 @@ export {
export {
createSessionClient,
getSessionHeaders,
createEkbClient,
getEkbHeaders,
type CreateSessionClientOptions,
} from "./session-client.js";
@@ -50,6 +48,5 @@ export {
// 6. 工作流脚本调试引擎客户端 (Script Engine Client)
export {
getScriptEngineClient,
getPiperClient,
fetchEasoJwt,
} from "./script-engine-client.js";
-4
View File
@@ -110,7 +110,3 @@ export async function getScriptEngineClient(
},
});
}
// ── 向后兼容别名 ─────────────────────────────────────────────────────────────
/** @deprecated 推荐使用 getScriptEngineClient */
export const getPiperClient = getScriptEngineClient;
@@ -1,6 +1,6 @@
import { describe, expect, it } from "bun:test";
import { canRefreshCorpAccessToken, resolveLinkExpiresAt } from "./login.js";
import { createEkbClient } from "./ekb.js";
import { canRefreshCorpAccessToken, resolveLinkExpiresAt } from "../auth/login.js";
import { createSessionClient } from "./session-client.js";
import type { CorpConfig } from "../config/types.js";
function corp(overrides: Partial<CorpConfig> = {}): CorpConfig {
@@ -14,7 +14,7 @@ function corp(overrides: Partial<CorpConfig> = {}): CorpConfig {
};
}
describe("core/auth/ekb refresh policy", () => {
describe("core/http/session-client refresh policy", () => {
it("only allows account credentials with an explicit account binding to refresh", () => {
expect(canRefreshCorpAccessToken(corp())).toBe(false);
expect(canRefreshCorpAccessToken(corp({ source: "browser", accountId: "86-1" }))).toBe(false);
@@ -32,7 +32,7 @@ describe("core/auth/ekb refresh policy", () => {
}) as unknown as typeof fetch;
try {
const client = await createEkbClient(corp());
const client = await createSessionClient(corp());
await expect(client.get("api/test")).rejects.toThrow("临时凭证已过期,请使用 hose-use corps add-link 重新导入");
expect(calls).toBe(1);
} finally {
-7
View File
@@ -70,10 +70,3 @@ export async function createSessionClient(
}),
});
}
// ── 向后兼容别名 ─────────────────────────────────────────────────────────────
/** @deprecated 推荐使用 getSessionHeaders */
export const getEkbHeaders = getSessionHeaders;
/** @deprecated 推荐使用 createSessionClient */
export const createEkbClient = createSessionClient;
+4 -4
View File
@@ -50,7 +50,7 @@ import {
type BillAttachmentReport,
} from "./types.js";
import { CorpContext } from "../../core/config/manager.js";
import { createEkbClient } from "../../core/auth/ekb.js";
import { createSessionClient } from "../../core/http/session-client.js";
import { resolveDimension } from "../dimension/tools.js";
// ── 通用内置字段中文 Label 字典 ───────────────────────────────────────────────
@@ -1349,7 +1349,7 @@ export const billTools = [
if (!corp) {
throw new Error("未配置活跃企业上下文");
}
const client = await createEkbClient(corp);
const client = await createSessionClient(corp);
const result = await searchAndFormatBills(client, corp.corpId || corp.id, params);
return {
corpId: corp.corpId || corp.id,
@@ -1372,7 +1372,7 @@ export const billTools = [
if (!corp) {
throw new Error("未配置活跃企业上下文");
}
const client = await createEkbClient(corp);
const client = await createSessionClient(corp);
const bills = await getBillByCodeOrId(client, corp.corpId || corp.id, params.code);
if (bills.length === 0) {
return {
@@ -1397,7 +1397,7 @@ export const billTools = [
if (!corp) {
throw new Error("未配置活跃企业上下文");
}
const client = await createEkbClient(corp);
const client = await createSessionClient(corp);
const { entities } = await getFieldDictionary(client, corp.corpId || corp.id, true);
return {
corpId: corp.corpId || corp.id,
+1 -1
View File
@@ -1,5 +1,5 @@
import { z } from "zod";
import { getEasoClient } from "../../core/auth/easo.js";
import { getEasoClient } from "../../core/http/unity-client.js";
import type { CorpConfig } from "../../core/config/types.js";
import { fetchStaffs } from "./api.js";
import type { ContactListResult, ContactSearchOptions, Staff } from "./types.js";
+1 -1
View File
@@ -63,7 +63,7 @@ export const dimensionTools = [
const corp = corpContext.getCurrent();
if (!corp) throw new Error("未配置活跃企业上下文");
const items = await searchDimensions(
await import("../../core/auth/ekb.js").then((m) => m.createEkbClient(corp)),
await import("../../core/http/session-client.js").then((m) => m.createSessionClient(corp)),
corp.corpId || corp.id,
{ name: params.keyword }
);
+1 -1
View File
@@ -17,7 +17,7 @@ domains/feetype/tools.ts (业务编排:树展开、路径计算、字段规
domains/feetype/api.ts (HTTP 传输层:直连 /api/v1/form/feeTypes 与 /api/form/v2/specifications)
│
▼
core/auth/ekb.ts (企业身份认证与凭证管理)
core/http/session-client.ts (企业会话客户端与凭证注入)
```
## 接口路由映射
+4 -4
View File
@@ -1,4 +1,4 @@
import { createEkbClient } from "../../core/auth/ekb.js";
import { createSessionClient } from "../../core/http/session-client.js";
import type { CorpConfig } from "../../core/config/types.js";
import {
fetchDesktopMenuTree,
@@ -11,7 +11,7 @@ import type { MenuItem, WorkbenchApp } from "./types.js";
export async function fetchWorkbenchAppsList(
corp: CorpConfig
): Promise<WorkbenchApp[]> {
const client = await createEkbClient(corp);
const client = await createSessionClient(corp);
const corpId = corp.corpId || corp.credentials.corpId;
return fetchWorkbenchApps(client, corpId);
}
@@ -20,7 +20,7 @@ export async function fetchWorkbenchAppsList(
export async function fetchDesktopMenus(
corp: CorpConfig
): Promise<MenuItem[]> {
const client = await createEkbClient(corp);
const client = await createSessionClient(corp);
const corpId = corp.corpId || corp.credentials.corpId;
return fetchDesktopMenuTree(client, corpId);
}
@@ -29,7 +29,7 @@ export async function fetchDesktopMenus(
export async function fetchAppCenterSubMenus(
corp: CorpConfig
): Promise<MenuItem[]> {
const client = await createEkbClient(corp);
const client = await createSessionClient(corp);
const corpId = corp.corpId || corp.credentials.corpId;
return fetchAppCenterMenus(client, corpId);
}
+1 -1
View File
@@ -10,7 +10,7 @@ export const permissionTools = [{
parameters: z.object({}),
handler: async ({ corpContext }: any) => {
const corp = corpContext.getCurrent(); if (!corp) throw new Error("未配置活跃企业上下文");
const client = await import("../../core/auth/ekb.js").then((m) => m.createEkbClient(corp));
const client = await import("../../core/http/session-client.js").then((m) => m.createSessionClient(corp));
return getPermissions(client, corp.corpId || corp.id);
},
}];
+1 -1
View File
@@ -73,7 +73,7 @@ export const roleTools = [
handler: async ({ corpContext }: any, params: { keyword?: string; count?: number }) => {
const corp = corpContext.getCurrent();
if (!corp) throw new Error("未配置活跃企业上下文");
const client = await import("../../core/auth/ekb.js").then((m) => m.createEkbClient(corp));
const client = await import("../../core/http/session-client.js").then((m) => m.createSessionClient(corp));
const roles = await searchRoles(client, corp.corpId || corp.id, { keyword: params.keyword });
return { count: roles.length, roles: roles.slice(0, params.count ?? 100) };
},
+5 -6
View File
@@ -1,5 +1,4 @@
import { createEkbClient } from "../../core/auth/ekb.js";
import { getUnityClient } from "../../core/auth/easo.js";
import { createSessionClient, getUnityClient } from "../../core/http/index.js";
import type { CorpConfig } from "../../core/config/types.js";
import {
listOpenApiKeys,
@@ -17,15 +16,15 @@ import type {
} from "./types.js";
export async function fetchOpenApiKeys(corp: CorpConfig): Promise<OpenApiKey[]> {
const ekbClient = await createEkbClient(corp);
const sessionClient = await createSessionClient(corp);
const corpId = corp.corpId || corp.credentials.corpId;
return listOpenApiKeys(ekbClient, corpId);
return listOpenApiKeys(sessionClient, corpId);
}
export async function fetchOpenConfig(corp: CorpConfig): Promise<OpenConfig> {
const ekbClient = await createEkbClient(corp);
const sessionClient = await createSessionClient(corp);
const corpId = corp.corpId || corp.credentials.corpId;
return getOpenConfig(ekbClient, corpId);
return getOpenConfig(sessionClient, corpId);
}
export async function fetchClientGoods(
+6 -7
View File
@@ -5,8 +5,7 @@ import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
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 { createSessionClient, getUnityClient } from "./core/http/index.js";
import { AuthenticationError, EkbError, NotLoggedInError } from "./core/errors.js";
import { authTools } from "./core/auth/tools.js";
import { platformTools } from "./domains/platform/tools.js";
@@ -344,10 +343,10 @@ export function createServer(options: { mode?: HoseMcpMode; enabled?: boolean }
isError: true,
};
}
const ekbClient = await createEkbClient(currentCorp);
const { client: easoClient } = await getEasoClient(currentCorp);
const sessionClient = await createSessionClient(currentCorp);
const { client: unityClient } = await getUnityClient(currentCorp);
const result = await platformTool.handler(
{ corp: currentCorp, ekbClient, easoClient },
{ corp: currentCorp, ekbClient: sessionClient, easoClient: unityClient },
parsed.data as never
);
return {
@@ -370,9 +369,9 @@ export function createServer(options: { mode?: HoseMcpMode; enabled?: boolean }
isError: true,
};
}
const ekbClient = await createEkbClient(currentCorp);
const sessionClient = await createSessionClient(currentCorp);
const result = await datalinkTool.handler(
{ corp: currentCorp, ekbClient },
{ corp: currentCorp, ekbClient: sessionClient },
parsed.data as never
);
return {