refactor(corps): normalize credential categories and format workflow history logs

This commit is contained in:
gitea committed 2026-10-14 18:19:13 +08:00
1 parent f91a80f9dd
commit 0499ccb2cc
9 files changed
+161 -49

No files matched your search

+1 -1
View File
@@ -253,7 +253,7 @@ async function handleStatus(parsed: CliParsedArgs, runtime: CliRuntime): Promise
: "✅ 统一认证主账号自动换票"
: "⚪ 短期会话",
"Token 有效性": sessionValid ? "✅ 有效 (已通过 Session 验证)" : "❌ 无效或未连接",
"Token 过期时间": formatExpiresAt(currentCorp?.auth?.expiresAt || currentCorp?.session?.expTime, isPersistent),
"Token 过期时间": formatExpiresAt(currentCorp?.auth?.expiresAt || currentCorp?.session?.expTime, isPersistent, hasOpenApi ? "openapi" : currentCorp?.source),
};
if (currentCorp?.session) {
+1 -1
View File
@@ -135,7 +135,7 @@ export async function handleContextCommand(
` 当前操作员工 : ${corpStaffId}`,
` 员工真实姓名 : ${corpStaffName}`,
` 凭证来源类型 : ${currentCorp ? formatSourceLabel(currentCorp.source, hasOpenApiPersistentCredentials(currentCorp)) : "-"}`,
` 凭证有效状态 : ${currentCorp ? formatExpiresAt(corpExpiresAt, currentPersistent) : "-"}`,
` 凭证有效状态 : ${currentCorp ? formatExpiresAt(corpExpiresAt, currentPersistent, hasOpenApiPersistentCredentials(currentCorp) ? "openapi" : currentCorp.source) : "-"}`,
` 主站 BaseURL : ${currentCorp?.baseUrl || "-"}`,
` 已配置企业总数: ${allCorps.length} 家 (有效: ${validCorps.length} 家, 已过期: ${expiredCorps.length} 家)`,
` AI PRO 规约库 : ${scopesStr}`,
+1 -1
View File
@@ -55,7 +55,7 @@ export async function handleCurrent(parsed: CliParsedArgs, runtime: CliRuntime):
"员工姓名": current.staffName || current.session?.staffName || "-",
"凭证来源": formatSourceLabel(current.source, hasOpenApi),
"持久化状态": isPersistent ? (hasOpenApi ? `✅ 已配置 OpenAPI 持久化密钥 (${current.credentials.appKey})` : "✅ 已绑定统一认证主账号") : "⚪ 短期临时会话",
"Token 过期时间": formatExpiresAt(current.auth?.expiresAt || current.session?.expTime, isPersistent),
"Token 过期时间": formatExpiresAt(current.auth?.expiresAt || current.session?.expTime, isPersistent, hasOpenApi ? "openapi" : current.source),
"所属账号": current.accountId || "-",
"主站地址": current.baseUrl || "https://app.ekuaibao.com",
"适用上下文": "同时作为 hose-use 与 hose-aipro 的统一执行环境",
+25 -17
View File
@@ -1,6 +1,6 @@
import { canRefreshCorpAccessToken } from "../../../core/auth/login.js";
import { stringOption } from "../../parser.js";
import { printJson, printTable, formatExpiresAt } from "../../printer.js";
import { printJson, printTable, formatExpiresAt, formatSourceLabel } from "../../printer.js";
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
const FIELD_LABEL_MAP: Record<string, string> = {
@@ -30,19 +30,26 @@ export async function handleSearch(parsed: CliParsedArgs, runtime: CliRuntime):
: null;
const normalizedCorps = rawCorps
? rawCorps.map((c) => ({
id: c.id,
name: c.name,
corpId: c.corpId || c.credentials?.corpId || c.id,
staffId: c.staffId || c.credentials?.staffId || "",
staffName: c.staffName || c.session?.staffName || "",
accountId: c.accountId || "",
source: c.source || "manual",
baseUrl: c.baseUrl,
current: c.id === runtime.selectedCorp?.id,
expiresAt: c.auth?.expiresAt || (c.session?.expTime ?? undefined),
persistent: canRefreshCorpAccessToken(c),
}))
? rawCorps.map((c) => {
const hasOpenApi = Boolean(
(c.credentials?.appKey || c.auth?.appKey) &&
(c.credentials?.appSecurity || c.auth?.appSecurity)
);
return {
id: c.id,
name: c.name,
corpId: c.corpId || c.credentials?.corpId || c.id,
staffId: c.staffId || c.credentials?.staffId || "",
staffName: c.staffName || c.session?.staffName || "",
accountId: c.accountId || "",
source: c.source || "manual",
baseUrl: c.baseUrl,
current: c.id === runtime.selectedCorp?.id,
expiresAt: c.auth?.expiresAt || (c.session?.expTime ?? undefined),
persistent: canRefreshCorpAccessToken(c),
hasOpenApi,
};
})
: runtime.corpContext.listCorps().map((c) => ({
id: c.id,
name: c.name,
@@ -55,6 +62,7 @@ export async function handleSearch(parsed: CliParsedArgs, runtime: CliRuntime):
current: c.current || c.id === runtime.selectedCorp?.id,
expiresAt: c.expiresAt,
persistent: c.persistent,
hasOpenApi: c.hasOpenApi,
}));
const matches: Array<typeof normalizedCorps[number] & { matchedFields: string[] }> = [];
@@ -134,7 +142,7 @@ export async function handleSearch(parsed: CliParsedArgs, runtime: CliRuntime):
m.staffName ? (m.matchedFields.includes("staffName") ? `[${m.staffName}]` : m.staffName) : "-",
m.accountId ? (m.matchedFields.includes("accountId") ? `[${m.accountId}]` : m.accountId) : "-",
matchLabels.map((l) => `命中${l}`).join(", "),
formatExpiresAt(m.expiresAt, m.persistent),
formatExpiresAt(m.expiresAt, m.persistent, m.hasOpenApi ? "openapi" : m.source),
];
});
@@ -176,8 +184,8 @@ export async function handleList(parsed: CliParsedArgs, runtime: CliRuntime): Pr
c.id,
c.name,
c.staffId,
c.source || "manual",
formatExpiresAt(c.expiresAt, c.persistent),
formatSourceLabel(c.source, c.hasOpenApi),
formatExpiresAt(c.expiresAt, c.persistent, c.hasOpenApi ? "openapi" : c.source),
c.accountId || "-",
]);
+1 -1
View File
@@ -110,7 +110,7 @@ export async function handleProbeCommand(
? `✅ OpenAPI 持久化密钥 (${currentCorp.credentials.appKey})`
: "✅ 统一认证主账号自动换票"
: "⚪ 短期会话",
"Token 过期时间": formatExpiresAt(currentCorp.auth?.expiresAt || currentCorp.session?.expTime, isPersistent),
"Token 过期时间": formatExpiresAt(currentCorp.auth?.expiresAt || currentCorp.session?.expTime, isPersistent, hasOpenApi ? "openapi" : currentCorp.source),
"主站 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} 个自建应用)` : "🔴 失败",
+14 -10
View File
@@ -38,10 +38,14 @@ export async function handleLogs(parsed: CliParsedArgs, runtime: CliRuntime): Pr
endTime: stringOption(parsed.options, ["end-time", "endTime"]),
});
const hasErrorFilter = booleanOption(parsed.options, ["has-error", "hasError", "errors"]);
const isJobError = (job: any): boolean => {
if (job.hasError === true || job.hasError === "存在" || job.hasError === "true") return true;
if (typeof job.errorTaskCount === "number" && job.errorTaskCount > 0) return true;
if (job.state === "FAILED" || job.status === "FAILED") return true;
return false;
};
const filteredJobList = hasErrorFilter
? rawResult.jobList.filter(
(job) => job.hasError === true || job.errorTaskCount > 0 || job.state === "FAILED"
)
? rawResult.jobList.filter(isJobError)
: rawResult.jobList;
const result = hasErrorFilter
? { ...rawResult, jobList: filteredJobList }
@@ -49,15 +53,15 @@ export async function handleLogs(parsed: CliParsedArgs, runtime: CliRuntime): Pr
if (runtime.jsonMode) return { stdout: printJson(result, runtime.outputOptions), stderr: "", exitCode: 0 };
const rows = result.jobList.map((job, idx) => [
const rows = result.jobList.map((job: any, idx) => [
idx + 1,
job.id,
job.state,
job.successTaskCount,
job.errorTaskCount,
job.hasError || job.errorTaskCount > 0 ? "⚠️ 是 (true)" : "否 (false)",
job.jobId || job.id || "-",
job.status || (job.state === 0 ? "COMPLETED" : String(job.state ?? "-")),
job.successTaskCount ?? 0,
job.errorTaskCount ?? 0,
isJobError(job) ? "⚠️ 包含错误" : "正常",
job.durationTime ?? "-",
job.startTime || "-",
job.executeTime || job.startTime || "-",
]);
const tableStr = rows.length
? printTable(