feat(assist-platform): add assist platform automation and tenant onboarding
- Add SSO QR status poller and assist platform HTTP client - Add assist-platform session store with 0600 secure permissions - Implement domains/assist-platform (api, services, types) for corporation search, detail, tickets, staff query and passwordless token generation - Implement cli/commands/assist-platform with aliases assist-center and ap - Support seamless --save --switch --elevate pipeline to import tenant and extract persistent OpenAPI credentials - Update embedded skill documentation, reference guide, and test suites
This commit is contained in:
1 parent
d839fcbe2b
commit
ed9fa979e0
25 files changed
+1811
-2
No files matched your search
@@ -0,0 +1,145 @@
|
||||
import {
|
||||
generateAssistSession,
|
||||
importAssistSessionToLocal,
|
||||
} from "../../../domains/assist-platform/services.js";
|
||||
import { isDryRun, mutationPreview, requireMutationConfirmation } from "../../mutation.js";
|
||||
import { booleanOption, stringOption } from "../../parser.js";
|
||||
import { printJson, printKeyValue } from "../../printer.js";
|
||||
import type { CliParsedArgs, CliResult, CliRuntime } from "../../types.js";
|
||||
import { resolveAssistClient } from "./common.js";
|
||||
|
||||
export async function handleEnter(
|
||||
parsed: CliParsedArgs,
|
||||
runtime: CliRuntime
|
||||
): Promise<CliResult> {
|
||||
const client = resolveAssistClient(parsed, runtime);
|
||||
const corpId =
|
||||
parsed.args[0] ||
|
||||
stringOption(parsed.options, ["corp", "corpid", "id"]) ||
|
||||
runtime.selectedCorp?.id;
|
||||
|
||||
if (!corpId) {
|
||||
return {
|
||||
stdout: "",
|
||||
stderr: "用法: hose-use assist-platform enter <企业ID> [--admin] [--staff <姓名>] [--save] [--switch]\n示例: hose-use assist-platform enter Cxa3oOtQi2eS$g --staff 李志财 --save --yes\n",
|
||||
exitCode: 1,
|
||||
};
|
||||
}
|
||||
|
||||
const ticketId = stringOption(parsed.options, ["ticket", "ticket-id", "auth-code"]);
|
||||
const staffName = stringOption(parsed.options, ["staff", "user", "name"]);
|
||||
const forceAdmin = booleanOption(parsed.options, ["admin"]);
|
||||
// 如果显式指定了 staffName 且未显式指定 --admin,则为用户模式;否则默认为管理员模式
|
||||
const isAdmin = forceAdmin || !staffName;
|
||||
|
||||
const shouldSave = booleanOption(parsed.options, ["save", "import", "persist"]);
|
||||
const shouldSwitch = booleanOption(parsed.options, ["switch", "current"]);
|
||||
const overwrite = booleanOption(parsed.options, ["overwrite"]);
|
||||
const saveName = stringOption(parsed.options, ["alias", "corp-name"]);
|
||||
|
||||
// 1. 若不要求保存落盘,仅生成直通免密链接输出
|
||||
if (!shouldSave && !shouldSwitch) {
|
||||
const sessionRes = await generateAssistSession(client, {
|
||||
corpId,
|
||||
ticketId,
|
||||
isAdmin,
|
||||
staffName,
|
||||
});
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson(sessionRes, runtime.outputOptions),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const pairs: Record<string, string> = {
|
||||
企业ID: sessionRes.corporationId,
|
||||
授权模式: sessionRes.isAdmin ? "👑 企业管理员 (Admin)" : `👤 普通员工 (${sessionRes.staffName || "-"})`,
|
||||
授权工单: sessionRes.ticketId,
|
||||
会话Token: sessionRes.token,
|
||||
免密直通链接: sessionRes.loginUrl,
|
||||
};
|
||||
|
||||
return {
|
||||
stdout: `====== 协助平台免密会话生成成功 ======\n${printKeyValue(pairs)}\n\n操作提示:\n - 在浏览器中打开以上链接可直接进入协助调试工作台\n - 若要一键落盘到本地企业配置: hose-use assist-platform enter ${corpId} ${sessionRes.isAdmin ? "--admin" : `--staff "${sessionRes.staffName}"`} --save --yes\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// 2. 要求持久化落盘 / 切换为工作企业
|
||||
if (isDryRun(parsed, runtime)) {
|
||||
return mutationPreview(
|
||||
parsed,
|
||||
runtime,
|
||||
"从协助平台换取免密凭证并落盘为本地企业配置",
|
||||
saveName || `企业 [${corpId}]`,
|
||||
{
|
||||
corpId,
|
||||
isAdmin,
|
||||
staffName: staffName || null,
|
||||
ticketId: ticketId || "自动选择最新有效工单",
|
||||
switchCurrent: shouldSwitch,
|
||||
overwrite,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const nextConfirmCmd = `hose-use assist-platform enter ${corpId} ${isAdmin ? "--admin" : `--staff "${staffName}"`} --save ${shouldSwitch ? "--switch " : ""}--yes`;
|
||||
requireMutationConfirmation(
|
||||
parsed,
|
||||
runtime,
|
||||
`从协助平台换取凭证并导入企业 [${corpId}]`,
|
||||
nextConfirmCmd
|
||||
);
|
||||
|
||||
const { sessionResult, corpConfig } = await importAssistSessionToLocal(client, {
|
||||
corpId,
|
||||
ticketId,
|
||||
isAdmin,
|
||||
staffName,
|
||||
saveName,
|
||||
overwrite: overwrite ?? true,
|
||||
});
|
||||
|
||||
// 若指定了 --switch,切换当前激活企业
|
||||
if (shouldSwitch) {
|
||||
runtime.corpContext.switchCorp(corpConfig.id, true);
|
||||
}
|
||||
|
||||
if (runtime.jsonMode) {
|
||||
return {
|
||||
stdout: printJson({
|
||||
success: true,
|
||||
sessionResult,
|
||||
enterprise: {
|
||||
id: corpConfig.id,
|
||||
name: corpConfig.name,
|
||||
staffId: corpConfig.credentials.staffId,
|
||||
hasOpenApi: Boolean(corpConfig.credentials.appKey),
|
||||
switched: shouldSwitch,
|
||||
},
|
||||
}, runtime.outputOptions),
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const successPairs: Record<string, string> = {
|
||||
企业标识: corpConfig.id,
|
||||
企业名称: corpConfig.name,
|
||||
执行身份: sessionResult.isAdmin ? "👑 企业管理员" : `👤 ${sessionResult.staffName || "员工"} (${corpConfig.credentials.staffId})`,
|
||||
授权工单: sessionResult.ticketId,
|
||||
凭证状态: corpConfig.credentials.appKey ? `✅ 已提取 OpenAPI 持久化密钥 (${corpConfig.credentials.appKey})` : "⚪ 临时协助会话",
|
||||
配置文件: `enterprises/${corpConfig.id}.json`,
|
||||
激活状态: shouldSwitch ? "🎯 已设为当前激活工作企业" : "可随时运行 hose-use corps switch 进行切换",
|
||||
};
|
||||
|
||||
return {
|
||||
stdout: `[SUCCESS] 协助企业凭证获取并落盘成功!\n${printKeyValue(successPairs)}\n`,
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user