Add delegation link support and bump version to 0.3.6

This commit is contained in:
gitea committed 2026-07-29 16:31:10 +08:00
1 parent 997ece006a
commit 33ca5fcb4a
8 files changed
+108 -6

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "seal-home",
"version": "0.3.5",
"version": "0.3.6",
"type": "module",
"module": "src/server.ts",
"bin": {
+2 -1
View File
@@ -23,13 +23,14 @@ seal-home tools list
- Before write operations on rules, documents, style preferences, or publishing, fetch current state and confirm the intended mutation with the user. For repeat test-environment rule resets, prefer `rules clear --dry-run` followed by `rules clear --yes`.
- For date questions, use explicit dates and `--timezone Asia/Shanghai`.
- If output may be large, use `--summary`, `--fields`, `--count`, or `--output-file`; use `--full` only when the user really needs full payloads.
- When returning authorization/login links (e.g. 合思授权链接), ALWAYS provide BOTH a code block (` ```text ... ``` `) for easy copying without accidental default browser redirection, AND a clickable hyperlink.
## Route By Intent
- Current tenant or identity: `seal-home tool seal_whoami`.
- 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`.
- User-facing 合思 authorization link: `seal-home auth hose-link --corp <corpId> --expire 7200`; read `references/hose-enterprise-auth.md`. Always provide BOTH a code block (` ```text ... ``` `) for copy AND a hyperlink.
- One approval document by 单号/SN: use `seal-home approval-runs pick --sn <单号> --latest`; read `references/approval-run-lightweight.md`.
- One approval run detail: use `approval-runs get <recordId> --summary` or `--fields ...`; read `references/approval-run-lightweight.md`.
- AI used which rules: use `approval-runs cited-rules <recordId>`; read `references/approval-run-lightweight.md`.
@@ -57,4 +57,5 @@ Important:
- Do not return the Seal tenant URL such as `https://<tenant>.sealai.cc`; that is not the Hose authorization link.
- Do not manually assemble `thirdparty.html` with a global/OpenAPI token.
- `seal-home auth diagnose` proves this stage works but redacts the token, so it is not enough when the user needs the actual clickable Hose link.
- **Formatting Requirement**: When returning a Hose authorization link to the user, ALWAYS provide BOTH a code block (` ```text ... ``` `) for easy copying without accidental default browser redirection, AND a clickable hyperlink.
- If the CLI later provides a dedicated command for this, prefer that command.
+21
View File
@@ -142,6 +142,24 @@ async function main() {
const client = await createSealClient(corp);
if (area === "delegation" && action === "list") {
await runTool("seal_delegation_list", client, corp, {}, outputOptions(args.options));
return;
}
if (area === "delegation" && action === "create") {
const note = stringOption(args.options.note) ?? (maybeName ? [maybeName, ...args.command.slice(2)].join(" ") : undefined);
await runTool("seal_delegation_create", client, corp, { note }, outputOptions(args.options));
return;
}
if (area === "delegation" && action === "revoke") {
const tokenId = maybeName ?? stringOption(args.options.tokenId);
if (!tokenId) throw new Error("Usage: seal-home delegation revoke <tokenId>");
await runTool("seal_delegation_revoke", client, corp, { tokenId }, outputOptions(args.options));
return;
}
if (area === "context") {
await runTool("seal_approval_context_get", client, corp, {
documentLimit: numberOption(args.options.documentLimit),
@@ -1238,6 +1256,9 @@ Usage:
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 delegation list [--corp <corpId>]
seal-home delegation create [--note <note>] [--corp <corpId>]
seal-home delegation revoke <tokenId> [--corp <corpId>]
seal-home source config [--corp <corpId>]
seal-home tool <toolName> [--corp <corpId>] [--json '{"key":"value"}']
seal-home rules count [--corp <corpId>]
+26 -1
View File
@@ -20,7 +20,11 @@ import {
SealSessionData,
SealSessionDataSchema,
RuleSetVersion,
RuleSetVersionSchema
RuleSetVersionSchema,
SealDelegationItem,
SealDelegationItemSchema,
SealDelegationCreateResult,
SealDelegationCreateResultSchema
} from "./types.js";
async function unwrap<T>(response: Response, schema: z.ZodType<T>): Promise<T> {
@@ -308,3 +312,24 @@ function setArrayOptional(
searchParams.set(`${key}[${index}]`, item);
});
}
export async function listDelegations(client: KyInstance): Promise<SealDelegationItem[]> {
return unwrap(await client.get("api/v1/delegation/list"), z.array(SealDelegationItemSchema));
}
export async function createDelegation(
client: KyInstance,
params?: { note?: string }
): Promise<SealDelegationCreateResult> {
return unwrap(
await client.post("api/v1/delegation/create", { json: params ?? {} }),
SealDelegationCreateResultSchema
);
}
export async function revokeDelegation(client: KyInstance, tokenId: string): Promise<boolean> {
const response = await client.post("api/v1/delegation/revoke", { json: { tokenId } });
const json = (await response.json()) as { data?: { success?: boolean } };
return json.data?.success ?? response.ok;
}
+10
View File
@@ -56,6 +56,16 @@ describe("sealTools", () => {
expect(tool).toBeDefined();
});
test("includes the delegation management tools", () => {
const listTool = sealTools.find((item) => item.name === "seal_delegation_list");
const createTool = sealTools.find((item) => item.name === "seal_delegation_create");
const revokeTool = sealTools.find((item) => item.name === "seal_delegation_revoke");
expect(listTool).toBeDefined();
expect(createTool).toBeDefined();
expect(revokeTool).toBeDefined();
});
test("includes the approval search tool", () => {
const tool = sealTools.find((item) => item.name === "seal_approval_search");
expect(tool).toBeDefined();
+24
View File
@@ -30,6 +30,30 @@ export const sealTools = [
parameters: z.object({}),
handler: async (client: KyInstance) => api.getSession(client)
},
{
name: "seal_delegation_list",
description: "查询当前 Seal 租户下的授权链接 (Delegation) 列表",
parameters: z.object({}),
handler: async (client: KyInstance) => api.listDelegations(client)
},
{
name: "seal_delegation_create",
description: "创建新的 Seal 授权链接 (Delegation)",
parameters: z.object({
note: z.string().optional().describe("授权链接的备注或说明信息")
}),
handler: async (client: KyInstance, params: { note?: string }) =>
api.createDelegation(client, params)
},
{
name: "seal_delegation_revoke",
description: "撤销/废除指定的 Seal 授权链接 (Delegation)",
parameters: z.object({
tokenId: z.string().describe("授权链接 ID (delegation record ID)")
}),
handler: async (client: KyInstance, params: { tokenId: string }) =>
api.revokeDelegation(client, params.tokenId)
},
{
name: "seal_approval_rules_list",
description: "列出 Seal 当前草稿审批规则;支持 countOnly、fields、limit 以避免返回规则正文",
+23 -3
View File
@@ -96,9 +96,9 @@ export const RuleSetVersionSchema = z.object({
id: z.string(),
tenantId: z.string().optional(),
versionNumber: z.number(),
versionName: z.string(),
publishedBy: z.string().optional(),
publishedByName: z.string().optional(),
versionName: z.string().nullable().optional(),
publishedBy: z.string().nullable().optional(),
publishedByName: z.string().nullable().optional(),
rules: z.array(PublishedRuleSnapshotSchema).default([]),
publishedAt: z.number().optional(),
createdAt: z.number().optional()
@@ -217,6 +217,23 @@ export const ApprovalRunListDataSchema = z.object({
pageSize: z.number().optional()
}).passthrough();
export const SealDelegationItemSchema = z.object({
id: z.string(),
expiresAt: z.number().nullable().optional(),
revokedAt: z.number().nullable().optional(),
createdAt: z.number().nullable().optional(),
lastUsedAt: z.number().nullable().optional(),
useCount: z.number().default(0),
note: z.string().nullable().optional(),
link: z.string()
}).passthrough();
export const SealDelegationCreateResultSchema = z.object({
id: z.string(),
token: z.string(),
link: z.string()
}).passthrough();
export type MeData = z.infer<typeof MeDataSchema>;
export type SealSessionData = z.infer<typeof SealSessionDataSchema>;
export type ApprovalRule = z.infer<typeof ApprovalRuleSchema>;
@@ -229,3 +246,6 @@ export type ApprovalIntegration = z.infer<typeof ApprovalIntegrationSchema>;
export type ApprovalStylePreferences = z.infer<typeof ApprovalStylePreferencesSchema>;
export type ApprovalRun = z.infer<typeof ApprovalRunSchema>;
export type ApprovalRunListData = z.infer<typeof ApprovalRunListDataSchema>;
export type SealDelegationItem = z.infer<typeof SealDelegationItemSchema>;
export type SealDelegationCreateResult = z.infer<typeof SealDelegationCreateResultSchema>;