Add Hose auth diagnostic command
This commit is contained in:
1 parent
97315a3c92
commit
2478a7f12f
4 files changed
+325
-13
No files matched your search
@@ -34,16 +34,17 @@ bun link
|
||||
seal-home version
|
||||
```
|
||||
|
||||
Create a user-level enterprise config that works from any directory:
|
||||
Create a user-level Hose enterprise config that works from any directory:
|
||||
|
||||
```bash
|
||||
mkdir -p ~/.config/seal-home/enterprises
|
||||
cp enterprises/example.hose.json ~/.config/seal-home/enterprises/local.json
|
||||
# Edit ~/.config/seal-home/enterprises/local.json with your own Hose/Seal credentials.
|
||||
seal-home source config
|
||||
seal-home corps add-hose --json '{"name":"企业名称","domain":"https://app.ekuaibao.com","appKey":"...","appSecurity":"...","proxyStaffBizId":"corpId:staffId"}'
|
||||
seal-home auth diagnose
|
||||
seal-home tools list
|
||||
```
|
||||
|
||||
`corps add-hose` verifies by default before writing the config. It uses the Hose OpenAPI credential response to derive the corporation ID, then checks provisional auth, Seal SSO, and Seal `whoami`. Pass `"force":true` or `"verify":false` only when you intentionally want to write a config that may fail later.
|
||||
|
||||
For custom config locations, set `SEAL_HOME_ENTERPRISES_DIR` to a directory containing non-example `*.json` enterprise config files.
|
||||
|
||||
Update an existing checkout:
|
||||
@@ -72,17 +73,20 @@ seal-home version
|
||||
seal-home config paths
|
||||
seal-home tools list
|
||||
seal-home corps list
|
||||
seal-home auth diagnose
|
||||
seal-home approval-runs summary --date 2026-06-08 --timezone Asia/Shanghai
|
||||
seal-home tool seal_approval_runs_summary --json '{"date":"2026-06-08","timezone":"Asia/Shanghai"}'
|
||||
```
|
||||
|
||||
CLI output is JSON on stdout. Errors are written to stderr.
|
||||
|
||||
Enterprise config lookup order:
|
||||
Enterprise config lookup:
|
||||
|
||||
1. `SEAL_HOME_ENTERPRISES_DIR`
|
||||
2. `./enterprises` in the current working directory
|
||||
3. `~/.config/seal-home/enterprises`
|
||||
- If `SEAL_HOME_ENTERPRISES_DIR` is set, only that directory is loaded.
|
||||
- Otherwise `./enterprises` and `~/.config/seal-home/enterprises` are merged.
|
||||
- User-level configs override same-ID configs from `./enterprises`.
|
||||
|
||||
Use `seal-home auth diagnose [--corp <corpId>]` when login fails. It reports four stages without printing tokens: `hose.openapi`, `hose.provisional`, `seal.sso`, and `seal.whoami`. A failed stage points to whether the problem is Hose app credentials, staff authorization, Seal SSO/tenant reachability, or Seal user/session access.
|
||||
|
||||
## Local Service
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ seal-home tools list
|
||||
|
||||
Use CLI for broad or detailed operations. The CLI intentionally exposes the full fine-grained tool list and is the primary interface for shared/public use.
|
||||
|
||||
Enterprise configs are loaded from `SEAL_HOME_ENTERPRISES_DIR`, `./enterprises`, or `~/.config/seal-home/enterprises`, in that order. Prefer user-level config for shared/public installs so commands do not depend on the repository working directory.
|
||||
Enterprise configs are loaded from `SEAL_HOME_ENTERPRISES_DIR` when it is set. Otherwise `./enterprises` and `~/.config/seal-home/enterprises` are merged, with user-level configs overriding same-ID local configs. Prefer user-level config for shared/public installs so commands do not depend on the repository working directory.
|
||||
|
||||
Optional local service commands:
|
||||
|
||||
@@ -35,6 +35,7 @@ Use `seal-home update` after pulling new versions; it restarts the service if it
|
||||
|
||||
- For current identity or tenant: use `seal-home tool seal_whoami`.
|
||||
- For configured enterprises: use `seal-home corps list`.
|
||||
- For Hose login, SSO, or "Unable to connect" authentication failures: use `seal-home auth diagnose [--corp <corpId>]`.
|
||||
- For source-derived enterprise config: use `seal-home source config`.
|
||||
- For daily approval run questions: use `seal-home approval-runs summary --date YYYY-MM-DD --timezone Asia/Shanghai`.
|
||||
- For approval run lookup by document SN, ID, status, mode, or trace: use `seal-home approval-runs search`.
|
||||
@@ -44,6 +45,23 @@ Use `seal-home update` after pulling new versions; it restarts the service if it
|
||||
|
||||
## Task Playbooks
|
||||
|
||||
### Diagnose Hose authentication
|
||||
|
||||
Use when a Hose/合思 sourced enterprise cannot log in, `seal_whoami` fails, or an agent needs to verify a newly added enterprise config.
|
||||
|
||||
```bash
|
||||
seal-home auth diagnose --corp <corpId>
|
||||
```
|
||||
|
||||
Read the JSON `stages` in order:
|
||||
|
||||
- `hose.openapi`: appKey/appSecurity can get a Hose OpenAPI token and corporation ID.
|
||||
- `hose.provisional`: `proxyStaffBizId`/staff ID can get a provisional auth URL.
|
||||
- `seal.sso`: Seal accepts the Hose provisional token and returns a bearer session.
|
||||
- `seal.whoami`: the Seal bearer can read current user and tenant.
|
||||
|
||||
Do not expect tokens in the output; the command intentionally redacts or omits them. If a stage fails, report that stage and its error, then stop assuming later stages worked.
|
||||
|
||||
### Diagnose one approval document
|
||||
|
||||
Use when the user gives a 合思/易快报单号, Seal source document SN, source document ID, or asks why one approval did or did not pass.
|
||||
|
||||
@@ -6,11 +6,11 @@ Run from any directory after installing the global CLI:
|
||||
seal-home <command>
|
||||
```
|
||||
|
||||
Enterprise config lookup order:
|
||||
Enterprise config lookup:
|
||||
|
||||
1. `SEAL_HOME_ENTERPRISES_DIR`
|
||||
2. `./enterprises` in the current working directory
|
||||
3. `~/.config/seal-home/enterprises`
|
||||
- If `SEAL_HOME_ENTERPRISES_DIR` is set, only that directory is loaded.
|
||||
- Otherwise `./enterprises` and `~/.config/seal-home/enterprises` are merged.
|
||||
- User-level configs override same-ID local configs.
|
||||
|
||||
## Top-Level Commands
|
||||
|
||||
@@ -21,6 +21,10 @@ seal-home service <start|stop|restart|status>
|
||||
seal-home update
|
||||
seal-home tools list
|
||||
seal-home corps list [--corp <corpId>]
|
||||
seal-home corps current
|
||||
seal-home corps switch <corpId>
|
||||
seal-home corps add-hose --json '{"name":"企业名称","domain":"https://app.ekuaibao.com","appKey":"...","appSecurity":"...","proxyStaffBizId":"corpId:staffId"}'
|
||||
seal-home auth diagnose [--corp <corpId>]
|
||||
seal-home source config [--corp <corpId>]
|
||||
seal-home tool <toolName> [--corp <corpId>] [--json '{"key":"value"}']
|
||||
seal-home approval-runs summary [--date YYYY-MM-DD] [--timezone Asia/Shanghai]
|
||||
@@ -46,6 +50,7 @@ seal-home simulation batch-records <batchId>
|
||||
|
||||
Identity and session:
|
||||
|
||||
- `seal-home auth diagnose [--corp <corpId>]`
|
||||
- `seal_whoami`
|
||||
- `seal_session_get`
|
||||
|
||||
@@ -84,6 +89,27 @@ Approval runs, simulations, and Langfuse bridge:
|
||||
|
||||
## Common Examples
|
||||
|
||||
Add and verify a Hose enterprise:
|
||||
|
||||
```bash
|
||||
seal-home corps add-hose --json '{"name":"企业名称","domain":"https://app.ekuaibao.com","appKey":"...","appSecurity":"...","proxyStaffBizId":"corpId:staffId"}'
|
||||
seal-home auth diagnose --corp <corpId>
|
||||
```
|
||||
|
||||
Force-write a Hose config without verification:
|
||||
|
||||
```bash
|
||||
seal-home corps add-hose --json '{"name":"企业名称","domain":"https://app.ekuaibao.com","appKey":"...","appSecurity":"...","proxyStaffBizId":"corpId:staffId","force":true}'
|
||||
```
|
||||
|
||||
Diagnose auth failures:
|
||||
|
||||
```bash
|
||||
seal-home auth diagnose --corp <corpId>
|
||||
```
|
||||
|
||||
The diagnostic stages are `hose.openapi`, `hose.provisional`, `seal.sso`, and `seal.whoami`. Tokens are omitted from output.
|
||||
|
||||
Search approval content:
|
||||
|
||||
```bash
|
||||
|
||||
+264
@@ -8,6 +8,7 @@ import { fileURLToPath } from "node:url";
|
||||
import { getEnterprisesDirCandidates, loadCorpConfigs, resolveWritableEnterprisesDir } from "./core/config/loader.js";
|
||||
import { createSealClient } from "./core/http/factory.js";
|
||||
import { resolveLiveSealEnterpriseConfig } from "./domains/seal/source.js";
|
||||
import { getMe } from "./domains/seal/api.js";
|
||||
import { sealTools, type SealTool } from "./domains/seal/tools.js";
|
||||
import { CorpConfig } from "./core/config/types.js";
|
||||
import { clearCorpTokenCache } from "./core/auth/token-store.js";
|
||||
@@ -113,6 +114,11 @@ async function main() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "auth" && action === "diagnose") {
|
||||
printJson(await diagnoseAuth(corp));
|
||||
return;
|
||||
}
|
||||
|
||||
const client = await createSealClient(corp);
|
||||
|
||||
if (area === "context") {
|
||||
@@ -475,6 +481,263 @@ async function addHoseCorp(input: Record<string, unknown>) {
|
||||
});
|
||||
}
|
||||
|
||||
async function diagnoseAuth(corp: CorpConfig) {
|
||||
if (corp.source.type !== "hose") {
|
||||
const client = await createSealClient(corp);
|
||||
const me = await getMe(client);
|
||||
return {
|
||||
corp: {
|
||||
id: corp.id,
|
||||
name: corp.name,
|
||||
sourceType: corp.source.type
|
||||
},
|
||||
ok: true,
|
||||
stages: [
|
||||
{
|
||||
name: "seal.whoami",
|
||||
ok: true,
|
||||
user: me.user,
|
||||
tenant: me.tenant
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
clearCorpTokenCache(corp.id);
|
||||
const source = corp.source;
|
||||
const appKey = source.appKey ?? source.key;
|
||||
const appSecurity = source.appSecurity ?? source.password;
|
||||
const sealUrl = (corp.seal.url ?? source.sealUrl ?? `https://${source.corpId.toLowerCase()}.sealai.cc`).replace(/\/+$/, "");
|
||||
const uid = source.staffId.includes(":") ? source.staffId : `${source.corpId}:${source.staffId}`;
|
||||
const stages: Array<Record<string, unknown>> = [];
|
||||
|
||||
if (!appKey || !appSecurity) {
|
||||
return {
|
||||
corp: {
|
||||
id: corp.id,
|
||||
name: corp.name,
|
||||
sourceType: corp.source.type
|
||||
},
|
||||
ok: false,
|
||||
stages: [
|
||||
{
|
||||
name: "hose.openapi",
|
||||
ok: false,
|
||||
error: "Hose source requires appKey/key and appSecurity/password"
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
const openapi = await runDiagnoseStage("hose.openapi", async () => {
|
||||
const json = await postJson(`${source.domain.replace(/\/+$/, "")}/api/openapi/v1/auth/getAccessToken`, {
|
||||
appKey,
|
||||
appSecurity
|
||||
});
|
||||
const value = objectValue(json.value);
|
||||
const token = stringValue(value.accessToken) ?? stringValue(json.accessToken) ?? stringValue(json.token);
|
||||
if (!token) throw new Error("Hose login did not return an access token");
|
||||
return {
|
||||
token,
|
||||
public: {
|
||||
corporationId: stringValue(value.corporationId) ?? stringValue(objectValue(value.corporation).id),
|
||||
expireTime: numberValue(value.expireTime)
|
||||
}
|
||||
};
|
||||
});
|
||||
stages.push(openapi.public);
|
||||
|
||||
const openapiToken = openapi.private?.token;
|
||||
const provisional = openapiToken
|
||||
? await runDiagnoseStage("hose.provisional", async () => {
|
||||
const json = await postJson(
|
||||
`${source.domain.replace(/\/+$/, "")}/api/openapi/v1.1/provisional/getProvisionalAuth?accessToken=${encodeURIComponent(openapiToken)}`,
|
||||
{
|
||||
uid,
|
||||
pageType: "home",
|
||||
expireDate: 7200
|
||||
}
|
||||
);
|
||||
const url = stringValue(objectValue(json.value).message);
|
||||
if (!url) throw new Error("Hose CloseAPI did not return a provisional auth URL");
|
||||
const token = new URL(url).searchParams.get("accessToken");
|
||||
if (!token) throw new Error("Hose provisional auth URL did not include accessToken");
|
||||
return {
|
||||
token,
|
||||
public: {
|
||||
uid,
|
||||
hasProvisionalUrl: true
|
||||
}
|
||||
};
|
||||
})
|
||||
: skippedStage("hose.provisional");
|
||||
stages.push(provisional.public);
|
||||
|
||||
const provisionalToken = provisional.private?.token;
|
||||
const sealSession = provisionalToken
|
||||
? await runDiagnoseStage("seal.sso", async () => {
|
||||
const json = await getJson(
|
||||
`${sealUrl}/api/auth/oauth2/session/oem-hosecloud?token=${encodeURIComponent(provisionalToken)}&returnToken=1`
|
||||
);
|
||||
const data = objectValue(json.data);
|
||||
const token =
|
||||
stringValue(json.token) ??
|
||||
stringValue(json.accessToken) ??
|
||||
stringValue(data.token) ??
|
||||
stringValue(data.accessToken);
|
||||
if (!token) throw new Error("Seal SSO did not return a bearer token");
|
||||
return {
|
||||
token,
|
||||
public: {
|
||||
sealUrl,
|
||||
expiresIn: numberValue(json.expiresIn) ?? numberValue(json.expires_in) ?? numberValue(data.expiresIn) ?? numberValue(data.expires_in)
|
||||
}
|
||||
};
|
||||
})
|
||||
: skippedStage("seal.sso");
|
||||
stages.push(sealSession.public);
|
||||
|
||||
const sealToken = sealSession.private?.token;
|
||||
const whoami = sealToken
|
||||
? await runDiagnoseStage("seal.whoami", async () => {
|
||||
const json = await getJson(`${sealUrl}/api/v1/auth/me`, {
|
||||
authorization: `Bearer ${sealToken}`
|
||||
});
|
||||
const data = objectValue(json.data);
|
||||
const user = objectValue(data.user ?? json.user);
|
||||
const tenant = objectValue(data.tenant ?? json.tenant);
|
||||
return {
|
||||
public: {
|
||||
user: {
|
||||
id: stringValue(user.id),
|
||||
name: stringValue(user.name),
|
||||
isAdmin: booleanValue(user.isAdmin),
|
||||
providerUserId: stringValue(user.providerUserId)
|
||||
},
|
||||
tenant: {
|
||||
id: stringValue(tenant.id),
|
||||
name: stringValue(tenant.name),
|
||||
tenantSlug: stringValue(tenant.tenantSlug),
|
||||
hoseCorpConfig: summarizeHoseCorpConfig(tenant.hoseCorpConfig)
|
||||
}
|
||||
}
|
||||
};
|
||||
})
|
||||
: skippedStage("seal.whoami");
|
||||
stages.push(whoami.public);
|
||||
|
||||
return {
|
||||
corp: {
|
||||
id: corp.id,
|
||||
name: corp.name,
|
||||
sourceType: corp.source.type
|
||||
},
|
||||
ok: stages.every((stage) => stage.ok === true),
|
||||
stages
|
||||
};
|
||||
}
|
||||
|
||||
type DiagnoseStageResult = {
|
||||
public: Record<string, unknown>;
|
||||
private?: {
|
||||
token?: string;
|
||||
};
|
||||
};
|
||||
|
||||
async function runDiagnoseStage(
|
||||
name: string,
|
||||
action: () => Promise<{ public: Record<string, unknown>; token?: string }>
|
||||
): Promise<DiagnoseStageResult> {
|
||||
try {
|
||||
const result = await action();
|
||||
return {
|
||||
public: {
|
||||
name,
|
||||
ok: true,
|
||||
...compactObject(result.public)
|
||||
},
|
||||
private: result.token ? { token: result.token } : undefined
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
public: {
|
||||
name,
|
||||
ok: false,
|
||||
error: redactSensitiveText(error instanceof Error ? error.message : String(error))
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function skippedStage(name: string): DiagnoseStageResult {
|
||||
return {
|
||||
public: {
|
||||
name,
|
||||
ok: false,
|
||||
skipped: true
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async function postJson(url: string, body: Record<string, unknown>): Promise<Record<string, unknown>> {
|
||||
const response = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"content-type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
return parseJsonResponse(response);
|
||||
}
|
||||
|
||||
async function getJson(url: string, headers: Record<string, string> = {}): Promise<Record<string, unknown>> {
|
||||
const response = await fetch(url, {
|
||||
headers
|
||||
});
|
||||
return parseJsonResponse(response);
|
||||
}
|
||||
|
||||
async function parseJsonResponse(response: Response): Promise<Record<string, unknown>> {
|
||||
const body = await response.text();
|
||||
if (!response.ok) {
|
||||
throw new Error(`${response.status} ${body}`);
|
||||
}
|
||||
const json = JSON.parse(body) as unknown;
|
||||
return objectValue(json);
|
||||
}
|
||||
|
||||
function objectValue(value: unknown): Record<string, unknown> {
|
||||
return value && typeof value === "object" && !Array.isArray(value)
|
||||
? value as Record<string, unknown>
|
||||
: {};
|
||||
}
|
||||
|
||||
function stringValue(value: unknown): string | undefined {
|
||||
return typeof value === "string" && value ? value : undefined;
|
||||
}
|
||||
|
||||
function numberValue(value: unknown): number | undefined {
|
||||
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
||||
}
|
||||
|
||||
function booleanValue(value: unknown): boolean | undefined {
|
||||
return typeof value === "boolean" ? value : undefined;
|
||||
}
|
||||
|
||||
function summarizeHoseCorpConfig(value: unknown) {
|
||||
const config = objectValue(value);
|
||||
return compactObject({
|
||||
corporationId: stringValue(config.corporationId),
|
||||
corporationName: stringValue(config.corporationName)
|
||||
});
|
||||
}
|
||||
|
||||
function compactObject<T extends Record<string, unknown>>(value: T): T {
|
||||
return Object.fromEntries(
|
||||
Object.entries(value).filter(([, item]) => item !== undefined)
|
||||
) as T;
|
||||
}
|
||||
|
||||
function requiredString(input: Record<string, unknown>, key: string): string {
|
||||
const value = optionalString(input, key);
|
||||
if (!value) throw new Error(`Missing required JSON field: ${key}`);
|
||||
@@ -683,6 +946,7 @@ Usage:
|
||||
seal-home corps current
|
||||
seal-home corps switch <corpId>
|
||||
seal-home corps add-hose --json '{"name":"企业名称","domain":"https://app.ekuaibao.com","appKey":"...","appSecurity":"...","proxyStaffBizId":"corpId:staffId"}'
|
||||
seal-home auth diagnose [--corp <corpId>]
|
||||
seal-home source config [--corp <corpId>]
|
||||
seal-home tool <toolName> [--corp <corpId>] [--json '{"key":"value"}']
|
||||
seal-home rules versions [--corp <corpId>]
|
||||
|
||||
Reference in new issue
Block a user