- 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
74 lines
2.3 KiB
TypeScript
74 lines
2.3 KiB
TypeScript
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
import { join, dirname } from "node:path";
|
|
import { homedir } from "node:os";
|
|
import { z } from "zod";
|
|
|
|
export const ASSIST_PLATFORM_STORE_PATH = join(
|
|
homedir(),
|
|
".config",
|
|
"hose-use",
|
|
"assist-platform.json"
|
|
);
|
|
|
|
export function resolveAssistPlatformStorePath(): string {
|
|
const envFile = process.env.HOSE_ASSIST_PLATFORM_FILE?.trim();
|
|
if (envFile) return envFile;
|
|
const stateDir = process.env.HOSE_STATE_DIR?.trim();
|
|
if (stateDir) return join(stateDir, "assist-platform.json");
|
|
return ASSIST_PLATFORM_STORE_PATH;
|
|
}
|
|
|
|
export const AssistPlatformSessionSchema = z.object({
|
|
token: z.string().describe("协助平台 API 会话 Token"),
|
|
hoseAccessToken: z.string().optional().describe("统一认证 Access Token (JWT)"),
|
|
userName: z.string().optional().describe("登录运维/客服员工姓名"),
|
|
userId: z.string().optional().describe("登录用户 ID"),
|
|
baseUrl: z.string().default("https://unity.ekuaibao.com").describe("协助平台基础服务地址"),
|
|
updatedAt: z.number().default(() => Date.now()),
|
|
});
|
|
|
|
export type AssistPlatformSession = z.infer<typeof AssistPlatformSessionSchema>;
|
|
|
|
function ensureDir(path: string): void {
|
|
const dir = dirname(path);
|
|
if (!existsSync(dir)) {
|
|
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
}
|
|
try {
|
|
chmodSync(dir, 0o700);
|
|
} catch {}
|
|
}
|
|
|
|
export function loadAssistPlatformSession(): AssistPlatformSession | null {
|
|
const filePath = resolveAssistPlatformStorePath();
|
|
try {
|
|
if (!existsSync(filePath)) return null;
|
|
const content = readFileSync(filePath, "utf-8");
|
|
const parsed = JSON.parse(content);
|
|
return AssistPlatformSessionSchema.parse(parsed);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function saveAssistPlatformSession(session: AssistPlatformSession): void {
|
|
const filePath = resolveAssistPlatformStorePath();
|
|
ensureDir(filePath);
|
|
writeFileSync(filePath, JSON.stringify(session, null, 2), {
|
|
encoding: "utf-8",
|
|
mode: 0o600,
|
|
});
|
|
try {
|
|
chmodSync(filePath, 0o600);
|
|
} catch {}
|
|
}
|
|
|
|
export function clearAssistPlatformSession(): void {
|
|
const filePath = resolveAssistPlatformStorePath();
|
|
try {
|
|
if (existsSync(filePath)) {
|
|
writeFileSync(filePath, "{}", { encoding: "utf-8", mode: 0o600 });
|
|
}
|
|
} catch {}
|
|
}
|