diff --git a/src/aipro-cli.ts b/src/aipro-cli.ts index 164ad7b..1b55a71 100644 --- a/src/aipro-cli.ts +++ b/src/aipro-cli.ts @@ -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> | undefined; + let client: Awaited> | 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 }; }; diff --git a/src/cli/commands/approval.ts b/src/cli/commands/approval.ts index 7c2ce1b..94dbbba 100644 --- a/src/cli/commands/approval.ts +++ b/src/cli/commands/approval.ts @@ -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(); diff --git a/src/cli/commands/auth.ts b/src/cli/commands/auth.ts index 21a7590..5b74c2d 100644 --- a/src/cli/commands/auth.ts +++ b/src/cli/commands/auth.ts @@ -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; diff --git a/src/cli/commands/bill.ts b/src/cli/commands/bill.ts index 453ed89..ddc132a 100644 --- a/src/cli/commands/bill.ts +++ b/src/cli/commands/bill.ts @@ -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> | undefined; + let client: Awaited> | undefined; const getClient = async () => { - client ??= await createEkbClient(corp); + client ??= await createSessionClient(corp); return client; }; diff --git a/src/cli/commands/corps.test.ts b/src/cli/commands/corps.test.ts index 12146c0..eaf4a40 100644 --- a/src/cli/commands/corps.test.ts +++ b/src/cli/commands/corps.test.ts @@ -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"); }); diff --git a/src/cli/commands/dimension.ts b/src/cli/commands/dimension.ts index 004c6d2..93ade11 100644 --- a/src/cli/commands/dimension.ts +++ b/src/cli/commands/dimension.ts @@ -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 { const corp = runtime.selectedCorp; if (!corp) throw new Error("未指定或未找到有效企业。请通过 --corp= 指定企业,或运行 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)) { diff --git a/src/cli/commands/feetype.ts b/src/cli/commands/feetype.ts index a2f8115..70ad54f 100644 --- a/src/cli/commands/feetype.ts +++ b/src/cli/commands/feetype.ts @@ -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> | undefined; + let client: Awaited> | undefined; const getClient = async () => { - client ??= await createEkbClient(corp); + client ??= await createSessionClient(corp); return client; }; diff --git a/src/cli/commands/message.ts b/src/cli/commands/message.ts index 8f15bd4..58c70b5 100644 --- a/src/cli/commands/message.ts +++ b/src/cli/commands/message.ts @@ -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 , 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"]); diff --git a/src/cli/commands/permission.ts b/src/cli/commands/permission.ts index 991adb3..5518ff9 100644 --- a/src/cli/commands/permission.ts +++ b/src/cli/commands/permission.ts @@ -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 { @@ -8,7 +8,7 @@ export async function handlePermissionCommand(parsed: CliParsedArgs, runtime: Cl if (!corp) throw new Error("未指定或未找到有效企业。请通过 --corp= 指定企业,或运行 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 ? "启用" : "停用"]); diff --git a/src/cli/commands/probe.ts b/src/cli/commands/probe.ts index c779403..d0528e8 100644 --- a/src/cli/commands/probe.ts +++ b/src/cli/commands/probe.ts @@ -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> | null = null; + let sessionClient: Awaited> | 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, diff --git a/src/cli/commands/role.ts b/src/cli/commands/role.ts index 643c13e..dfbf800 100644 --- a/src/cli/commands/role.ts +++ b/src/cli/commands/role.ts @@ -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 { const corp = runtime.selectedCorp; if (!corp) throw new Error("未指定或未找到有效企业。请通过 --corp= 指定企业,或运行 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]; diff --git a/src/cli/commands/service.ts b/src/cli/commands/service.ts index dad68b2..7e73e69 100644 --- a/src/cli/commands/service.ts +++ b/src/cli/commands/service.ts @@ -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= 指定企业。"); 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); diff --git a/src/cli/commands/task.ts b/src/cli/commands/task.ts index aaac18f..aa4870c 100644 --- a/src/cli/commands/task.ts +++ b/src/cli/commands/task.ts @@ -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 }; diff --git a/src/cli/helpers.ts b/src/cli/helpers.ts index e83ccba..8232eb6 100644 --- a/src/cli/helpers.ts +++ b/src/cli/helpers.ts @@ -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 { const rl = readline.createInterface({ input: process.stdin, diff --git a/src/core/README.core.md b/src/core/README.core.md index e766e62..9bb8954 100644 --- a/src/core/README.core.md +++ b/src/core/README.core.md @@ -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 策略头 diff --git a/src/core/auth/easo.ts b/src/core/auth/easo.ts deleted file mode 100644 index f37abf0..0000000 --- a/src/core/auth/easo.ts +++ /dev/null @@ -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"; diff --git a/src/core/auth/ekb.ts b/src/core/auth/ekb.ts deleted file mode 100644 index fb87407..0000000 --- a/src/core/auth/ekb.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * @deprecated 兼容历史导出。请优先从 "src/core/http/index.js" 导入 createSessionClient 与 getSessionHeaders - */ -export { - createSessionClient, - getSessionHeaders, - createEkbClient, - getEkbHeaders, - type CreateSessionClientOptions, -} from "../http/session-client.js"; diff --git a/src/core/auth/login.ts b/src/core/auth/login.ts index 4e27168..8c996bd 100644 --- a/src/core/auth/login.ts +++ b/src/core/auth/login.ts @@ -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, diff --git a/src/core/auth/piper.ts b/src/core/auth/piper.ts deleted file mode 100644 index 7b3435f..0000000 --- a/src/core/auth/piper.ts +++ /dev/null @@ -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"; diff --git a/src/core/auth/tools.ts b/src/core/auth/tools.ts index 8d1d236..21aa7a8 100644 --- a/src/core/auth/tools.ts +++ b/src/core/auth/tools.ts @@ -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; diff --git a/src/core/http/clients.test.ts b/src/core/http/clients.test.ts index 8424a36..cfeeedc 100644 --- a/src/core/http/clients.test.ts +++ b/src/core/http/clients.test.ts @@ -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 { @@ -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(); }); }); diff --git a/src/core/http/index.ts b/src/core/http/index.ts index 983a546..299a819 100644 --- a/src/core/http/index.ts +++ b/src/core/http/index.ts @@ -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"; diff --git a/src/core/http/script-engine-client.ts b/src/core/http/script-engine-client.ts index 43702dc..c2a4380 100644 --- a/src/core/http/script-engine-client.ts +++ b/src/core/http/script-engine-client.ts @@ -110,7 +110,3 @@ export async function getScriptEngineClient( }, }); } - -// ── 向后兼容别名 ───────────────────────────────────────────────────────────── -/** @deprecated 推荐使用 getScriptEngineClient */ -export const getPiperClient = getScriptEngineClient; diff --git a/src/core/auth/ekb.test.ts b/src/core/http/session-client.test.ts similarity index 91% rename from src/core/auth/ekb.test.ts rename to src/core/http/session-client.test.ts index a3d3e80..e154420 100644 --- a/src/core/auth/ekb.test.ts +++ b/src/core/http/session-client.test.ts @@ -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 { @@ -14,7 +14,7 @@ function corp(overrides: Partial = {}): 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 { diff --git a/src/core/http/session-client.ts b/src/core/http/session-client.ts index 113026c..73e4740 100644 --- a/src/core/http/session-client.ts +++ b/src/core/http/session-client.ts @@ -70,10 +70,3 @@ export async function createSessionClient( }), }); } - -// ── 向后兼容别名 ───────────────────────────────────────────────────────────── -/** @deprecated 推荐使用 getSessionHeaders */ -export const getEkbHeaders = getSessionHeaders; - -/** @deprecated 推荐使用 createSessionClient */ -export const createEkbClient = createSessionClient; diff --git a/src/domains/bill/tools.ts b/src/domains/bill/tools.ts index 3664e82..994979f 100644 --- a/src/domains/bill/tools.ts +++ b/src/domains/bill/tools.ts @@ -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, diff --git a/src/domains/contact/tools.ts b/src/domains/contact/tools.ts index d3eb5fe..2ace27c 100644 --- a/src/domains/contact/tools.ts +++ b/src/domains/contact/tools.ts @@ -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"; diff --git a/src/domains/dimension/tools.ts b/src/domains/dimension/tools.ts index c5b4fa8..7030380 100644 --- a/src/domains/dimension/tools.ts +++ b/src/domains/dimension/tools.ts @@ -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 } ); diff --git a/src/domains/feetype/README.feetype.md b/src/domains/feetype/README.feetype.md index df1c36e..45a6373 100644 --- a/src/domains/feetype/README.feetype.md +++ b/src/domains/feetype/README.feetype.md @@ -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 (企业会话客户端与凭证注入) ``` ## 接口路由映射 diff --git a/src/domains/menu/tools.ts b/src/domains/menu/tools.ts index a5acff2..4d10643 100644 --- a/src/domains/menu/tools.ts +++ b/src/domains/menu/tools.ts @@ -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 { - 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 { - 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 { - const client = await createEkbClient(corp); + const client = await createSessionClient(corp); const corpId = corp.corpId || corp.credentials.corpId; return fetchAppCenterMenus(client, corpId); } diff --git a/src/domains/permission/tools.ts b/src/domains/permission/tools.ts index 43c47a2..4f6673a 100644 --- a/src/domains/permission/tools.ts +++ b/src/domains/permission/tools.ts @@ -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); }, }]; diff --git a/src/domains/role/tools.ts b/src/domains/role/tools.ts index 3626a14..608feba 100644 --- a/src/domains/role/tools.ts +++ b/src/domains/role/tools.ts @@ -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) }; }, diff --git a/src/domains/store/tools.ts b/src/domains/store/tools.ts index 1e6002c..54770b5 100644 --- a/src/domains/store/tools.ts +++ b/src/domains/store/tools.ts @@ -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 { - 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 { - 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( diff --git a/src/server.ts b/src/server.ts index a74b160..48d1da2 100644 --- a/src/server.ts +++ b/src/server.ts @@ -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 {