Add Seal-native enterprise support
This commit is contained in:
1 parent
2611ce4c85
commit
997ece006a
10 files changed
+176
-9
No files matched your search
@@ -4,7 +4,7 @@ Bun + TypeScript CLI and optional local service for pulling Seal enterprise appr
|
||||
|
||||
The first provider is Hose/合思: `key`, `password`, `corpId`, `staffId`, and an optional Hose domain. The provider exchanges those credentials for a Seal enterprise session, then the Seal domain tools can read and maintain approval rules, approval documents, and approval style preferences.
|
||||
|
||||
`direct` is also available for later sources that already provide a Seal Bearer token.
|
||||
Seal-native enterprise pages can be added with a Seal Bearer token. The older `direct` source remains available for existing configs that already provide a Seal Bearer token.
|
||||
|
||||
## Setup
|
||||
|
||||
@@ -16,7 +16,7 @@ bun run probe
|
||||
bun run start
|
||||
```
|
||||
|
||||
For an already-authenticated Seal source, copy `enterprises/example.direct.json` instead.
|
||||
For an already-authenticated Seal-native source, use `seal-home corps add-seal` or copy `enterprises/example.seal.json`. Existing `direct` configs remain supported via `enterprises/example.direct.json`.
|
||||
|
||||
## Public Usage
|
||||
|
||||
@@ -43,6 +43,15 @@ 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.
|
||||
|
||||
Create a user-level Seal-native enterprise config from an already signed-in Seal Home page:
|
||||
|
||||
```bash
|
||||
seal-home corps add-seal --json '{"sealUrl":"https://tenant.staging.sealai.cc","token":"seal-bearer-token"}'
|
||||
seal-home auth diagnose --corp tenant
|
||||
```
|
||||
|
||||
`corps add-seal` verifies `/api/v1/auth/me` by default and writes the tenant slug, tenant ID, tenant name, and provider user ID into local config metadata. Pass `"force":true` or `"verify":false` only when writing an offline config intentionally.
|
||||
|
||||
For custom config locations, set `SEAL_HOME_ENTERPRISES_DIR` to a directory containing non-example `*.json` enterprise config files.
|
||||
|
||||
Update an existing checkout:
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"id": "tenant-slug",
|
||||
"name": "Seal 原生企业",
|
||||
"seal": {
|
||||
"url": "https://tenant.sealai.cc",
|
||||
"tenantSlug": "tenant-slug",
|
||||
"endpoints": {
|
||||
"approvalStylePreferences": "api/v1/agent/ai-approval/config"
|
||||
}
|
||||
},
|
||||
"source": {
|
||||
"type": "seal",
|
||||
"token": "seal-bearer-token",
|
||||
"sealUrl": "https://tenant.sealai.cc",
|
||||
"expiresIn": 2592000,
|
||||
"staffId": "seal-user-id",
|
||||
"corpId": "tenant-slug",
|
||||
"tenantId": "seal-tenant-id",
|
||||
"tenantSlug": "tenant-slug",
|
||||
"tenantName": "Seal 原生企业",
|
||||
"providerUserId": "provider-user-id"
|
||||
},
|
||||
"auth": {
|
||||
"refreshTtl": 300
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "seal-home",
|
||||
"version": "0.3.3",
|
||||
"version": "0.3.5",
|
||||
"type": "module",
|
||||
"module": "src/server.ts",
|
||||
"bin": {
|
||||
|
||||
@@ -27,7 +27,7 @@ seal-home tools list
|
||||
## Route By Intent
|
||||
|
||||
- Current tenant or identity: `seal-home tool seal_whoami`.
|
||||
- Enterprise list/current/switch/add: `seal-home corps ...`; for Hose setup read `references/hose-enterprise-auth.md`.
|
||||
- Enterprise list/current/switch/add: `seal-home corps ...`; use `corps add-seal` for Seal-native tenants and `corps add-hose` for Hose setup; for Hose setup read `references/hose-enterprise-auth.md`.
|
||||
- Hose login/SSO/auth failures: `seal-home auth diagnose --corp <corpId>`.
|
||||
- User-facing 合思 authorization link: `seal-home auth hose-link --corp <corpId> --expire 7200`; read `references/hose-enterprise-auth.md`.
|
||||
- One approval document by 单号/SN: use `seal-home approval-runs pick --sn <单号> --latest`; read `references/approval-run-lightweight.md`.
|
||||
|
||||
@@ -24,6 +24,7 @@ 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 corps add-seal --json '{"sealUrl":"https://tenant.sealai.cc","token":"seal-bearer-token"}'
|
||||
seal-home auth diagnose [--corp <corpId>]
|
||||
seal-home auth hose-link [--corp <corpId>] [--expire 7200]
|
||||
seal-home source config [--corp <corpId>]
|
||||
|
||||
+91
@@ -117,6 +117,11 @@ async function main() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (area === "corps" && action === "add-seal") {
|
||||
await addSealCorp(jsonObject(args.json));
|
||||
return;
|
||||
}
|
||||
|
||||
const corp = selectCorp(String(args.options.corp ?? ""));
|
||||
|
||||
if (area === "source" && action === "config") {
|
||||
@@ -655,6 +660,75 @@ async function addHoseCorp(input: Record<string, unknown>) {
|
||||
});
|
||||
}
|
||||
|
||||
async function addSealCorp(input: Record<string, unknown>) {
|
||||
const token = requiredString(input, "token");
|
||||
const sealUrl = (optionalString(input, "sealUrl") ?? optionalString(input, "url") ?? "").replace(/\/+$/, "");
|
||||
if (!sealUrl) throw new Error("Missing required JSON field: sealUrl");
|
||||
|
||||
const expiresIn = optionalNumber(input, "expiresIn") ?? 30 * 24 * 60 * 60;
|
||||
const verify = input.force === true || input.verify === false ? false : true;
|
||||
const remote = verify ? await resolveSealWhoami(sealUrl, token) : undefined;
|
||||
const remoteUser = remote?.user;
|
||||
const remoteTenant = remote?.tenant;
|
||||
const tenantSlug = optionalString(input, "tenantSlug") ?? stringValue(remoteTenant?.tenantSlug);
|
||||
const tenantId = optionalString(input, "tenantId") ?? stringValue(remoteTenant?.id);
|
||||
const tenantName = optionalString(input, "tenantName") ??
|
||||
optionalString(input, "name") ??
|
||||
stringValue(remoteTenant?.name);
|
||||
const id = optionalString(input, "id") ?? tenantSlug ?? tenantId;
|
||||
if (!id) {
|
||||
throw new Error("Missing required JSON field: id. Seal whoami did not return tenantSlug or tenantId.");
|
||||
}
|
||||
const staffId = optionalString(input, "staffId") ??
|
||||
stringValue(remoteUser?.providerUserId) ??
|
||||
stringValue(remoteUser?.id) ??
|
||||
"seal";
|
||||
|
||||
const config: CorpConfig = {
|
||||
id,
|
||||
name: tenantName ?? id,
|
||||
seal: {
|
||||
url: sealUrl,
|
||||
tenantSlug,
|
||||
endpoints: {
|
||||
approvalStylePreferences: "api/v1/agent/ai-approval/config"
|
||||
}
|
||||
},
|
||||
source: {
|
||||
type: "seal",
|
||||
token,
|
||||
sealUrl,
|
||||
expiresIn,
|
||||
staffId,
|
||||
corpId: tenantSlug ?? tenantId ?? id,
|
||||
tenantId,
|
||||
tenantSlug,
|
||||
tenantName,
|
||||
providerUserId: stringValue(remoteUser?.providerUserId)
|
||||
},
|
||||
auth: {
|
||||
refreshTtl: 300
|
||||
}
|
||||
};
|
||||
|
||||
const enterprisesDir = resolveWritableEnterprisesDir();
|
||||
mkdirSync(enterprisesDir, { recursive: true, mode: 0o700 });
|
||||
const file = join(enterprisesDir, `${safeFileName(id)}.json`);
|
||||
if (existsSync(file) && input.overwrite !== true) {
|
||||
throw new Error(`Enterprise config already exists: ${file}. Pass "overwrite": true to replace it.`);
|
||||
}
|
||||
|
||||
writeFileSync(file, `${JSON.stringify(config, null, 2)}\n`, { mode: 0o600 });
|
||||
printJson({
|
||||
id,
|
||||
name: config.name,
|
||||
tenantId,
|
||||
tenantSlug,
|
||||
verified: verify,
|
||||
path: file
|
||||
});
|
||||
}
|
||||
|
||||
async function diagnoseAuth(corp: CorpConfig) {
|
||||
if (corp.source.type !== "hose") {
|
||||
const client = await createSealClient(corp);
|
||||
@@ -871,6 +945,17 @@ async function getJson(url: string, headers: Record<string, string> = {}): Promi
|
||||
return parseJsonResponse(response);
|
||||
}
|
||||
|
||||
async function resolveSealWhoami(sealUrl: string, token: string) {
|
||||
const json = await getJson(`${sealUrl}/api/v1/auth/me`, {
|
||||
authorization: `Bearer ${token}`
|
||||
});
|
||||
const data = objectValue(json.data);
|
||||
return {
|
||||
user: objectValue(data.user ?? json.user),
|
||||
tenant: objectValue(data.tenant ?? json.tenant)
|
||||
};
|
||||
}
|
||||
|
||||
async function parseJsonResponse(response: Response): Promise<Record<string, unknown>> {
|
||||
const body = await response.text();
|
||||
if (!response.ok) {
|
||||
@@ -931,6 +1016,11 @@ function optionalString(input: Record<string, unknown>, key: string): string | u
|
||||
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
||||
}
|
||||
|
||||
function optionalNumber(input: Record<string, unknown>, key: string): number | undefined {
|
||||
const value = input[key];
|
||||
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
||||
}
|
||||
|
||||
function inferCorpIdFromStaffId(staffId: string): string | undefined {
|
||||
const [corpId] = staffId.split(":", 1);
|
||||
return corpId || undefined;
|
||||
@@ -1145,6 +1235,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 corps add-seal --json '{"sealUrl":"https://tenant.sealai.cc","token":"seal-bearer-token"}'
|
||||
seal-home auth diagnose [--corp <corpId>]
|
||||
seal-home auth hose-link [--corp <corpId>] [--expire 7200]
|
||||
seal-home source config [--corp <corpId>]
|
||||
|
||||
@@ -2,23 +2,26 @@ import { CorpConfig } from "../config/types.js";
|
||||
import { SealSession } from "./types.js";
|
||||
|
||||
export async function getDirectSealSession(corp: CorpConfig): Promise<SealSession> {
|
||||
if (corp.source.type !== "direct") {
|
||||
if (corp.source.type !== "direct" && corp.source.type !== "seal") {
|
||||
throw new Error(`Unsupported Seal source: ${corp.source.type}`);
|
||||
}
|
||||
|
||||
const sealUrl = corp.seal.url ?? corp.source.sealUrl;
|
||||
const nativeSource = corp.source.type === "seal" ? corp.source : undefined;
|
||||
|
||||
return {
|
||||
token: corp.source.token,
|
||||
expiresAt: Date.now() + corp.source.expiresIn * 1000,
|
||||
enterprise: {
|
||||
provider: "direct",
|
||||
provider: nativeSource ? "seal" : "direct",
|
||||
corpId: corp.source.corpId ?? corp.id,
|
||||
staffId: corp.source.staffId,
|
||||
sealUrl,
|
||||
tenantSlug: corp.seal.tenantSlug,
|
||||
tenantId: nativeSource?.tenantId,
|
||||
tenantSlug: corp.seal.tenantSlug ?? nativeSource?.tenantSlug,
|
||||
tenantName: nativeSource?.tenantName,
|
||||
raw: {
|
||||
sourceType: "direct"
|
||||
sourceType: corp.source.type
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -15,6 +15,7 @@ async function refreshSealSession(corp: CorpConfig): Promise<SealSession> {
|
||||
case "hose":
|
||||
return getHoseSealSession(corp);
|
||||
case "direct":
|
||||
case "seal":
|
||||
return getDirectSealSession(corp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,4 +57,25 @@ describe("CorpConfigSchema", () => {
|
||||
}
|
||||
expect(config.source.expiresIn).toBe(3600);
|
||||
});
|
||||
|
||||
test("accepts native Seal bearer source", () => {
|
||||
const config = CorpConfigSchema.parse({
|
||||
id: "xiezihao",
|
||||
name: "谢子豪的测试环境",
|
||||
source: {
|
||||
type: "seal",
|
||||
token: "seal-token",
|
||||
sealUrl: "https://xiezihao.staging.sealai.cc",
|
||||
tenantSlug: "xiezihao",
|
||||
tenantId: "tenant-id"
|
||||
}
|
||||
});
|
||||
|
||||
expect(config.source.type).toBe("seal");
|
||||
if (config.source.type !== "seal") {
|
||||
throw new Error("expected seal source");
|
||||
}
|
||||
expect(config.source.staffId).toBe("seal");
|
||||
expect(config.source.tenantSlug).toBe("xiezihao");
|
||||
});
|
||||
});
|
||||
@@ -37,9 +37,23 @@ export const DirectSealSourceSchema = z.object({
|
||||
corpId: z.string().optional()
|
||||
});
|
||||
|
||||
export const NativeSealSourceSchema = z.object({
|
||||
type: z.literal("seal"),
|
||||
token: z.string(),
|
||||
sealUrl: z.string().url(),
|
||||
expiresIn: z.number().int().positive().default(3600),
|
||||
staffId: z.string().default("seal"),
|
||||
corpId: z.string().optional(),
|
||||
tenantId: z.string().optional(),
|
||||
tenantSlug: z.string().optional(),
|
||||
tenantName: z.string().optional(),
|
||||
providerUserId: z.string().optional()
|
||||
});
|
||||
|
||||
export const SealSourceSchema = z.discriminatedUnion("type", [
|
||||
HoseSealSourceSchema,
|
||||
DirectSealSourceSchema
|
||||
DirectSealSourceSchema,
|
||||
NativeSealSourceSchema
|
||||
]);
|
||||
|
||||
export const SealEndpointSchema = z.object({
|
||||
@@ -70,6 +84,7 @@ export const CorpConfigSchema = z.object({
|
||||
|
||||
export type HoseSealSource = z.infer<typeof HoseSealSourceSchema>;
|
||||
export type DirectSealSource = z.infer<typeof DirectSealSourceSchema>;
|
||||
export type NativeSealSource = z.infer<typeof NativeSealSourceSchema>;
|
||||
export type SealSource = z.infer<typeof SealSourceSchema>;
|
||||
export type CorpAuthConfig = z.infer<typeof CorpAuthConfigSchema>;
|
||||
export type CorpConfig = z.infer<typeof CorpConfigSchema>;
|
||||
Reference in new issue
Block a user