diff --git a/package.json b/package.json index 19851c2..49d24b1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "seal-home", - "version": "0.3.5", + "version": "0.3.6", "type": "module", "module": "src/server.ts", "bin": { diff --git a/skills/seal-home/SKILL.md b/skills/seal-home/SKILL.md index 55f6f15..5fe6dd5 100644 --- a/skills/seal-home/SKILL.md +++ b/skills/seal-home/SKILL.md @@ -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 `. -- User-facing 合思 authorization link: `seal-home auth hose-link --corp --expire 7200`; read `references/hose-enterprise-auth.md`. +- User-facing 合思 authorization link: `seal-home auth hose-link --corp --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 --summary` or `--fields ...`; read `references/approval-run-lightweight.md`. - AI used which rules: use `approval-runs cited-rules `; read `references/approval-run-lightweight.md`. diff --git a/skills/seal-home/references/hose-enterprise-auth.md b/skills/seal-home/references/hose-enterprise-auth.md index a8b95d5..8d2bf05 100644 --- a/skills/seal-home/references/hose-enterprise-auth.md +++ b/skills/seal-home/references/hose-enterprise-auth.md @@ -57,4 +57,5 @@ Important: - Do not return the Seal tenant URL such as `https://.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. diff --git a/src/cli.ts b/src/cli.ts index 7b0684a..713e763 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -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 "); + 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 ] seal-home auth hose-link [--corp ] [--expire 7200] + seal-home delegation list [--corp ] + seal-home delegation create [--note ] [--corp ] + seal-home delegation revoke [--corp ] seal-home source config [--corp ] seal-home tool [--corp ] [--json '{"key":"value"}'] seal-home rules count [--corp ] diff --git a/src/domains/seal/api.ts b/src/domains/seal/api.ts index 526c842..f973183 100644 --- a/src/domains/seal/api.ts +++ b/src/domains/seal/api.ts @@ -20,7 +20,11 @@ import { SealSessionData, SealSessionDataSchema, RuleSetVersion, - RuleSetVersionSchema + RuleSetVersionSchema, + SealDelegationItem, + SealDelegationItemSchema, + SealDelegationCreateResult, + SealDelegationCreateResultSchema } from "./types.js"; async function unwrap(response: Response, schema: z.ZodType): Promise { @@ -308,3 +312,24 @@ function setArrayOptional( searchParams.set(`${key}[${index}]`, item); }); } + +export async function listDelegations(client: KyInstance): Promise { + return unwrap(await client.get("api/v1/delegation/list"), z.array(SealDelegationItemSchema)); +} + +export async function createDelegation( + client: KyInstance, + params?: { note?: string } +): Promise { + return unwrap( + await client.post("api/v1/delegation/create", { json: params ?? {} }), + SealDelegationCreateResultSchema + ); +} + +export async function revokeDelegation(client: KyInstance, tokenId: string): Promise { + 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; +} + diff --git a/src/domains/seal/tools.test.ts b/src/domains/seal/tools.test.ts index 584ba54..5e5eebb 100644 --- a/src/domains/seal/tools.test.ts +++ b/src/domains/seal/tools.test.ts @@ -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(); diff --git a/src/domains/seal/tools.ts b/src/domains/seal/tools.ts index 630935f..a99a8fc 100644 --- a/src/domains/seal/tools.ts +++ b/src/domains/seal/tools.ts @@ -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 以避免返回规则正文", diff --git a/src/domains/seal/types.ts b/src/domains/seal/types.ts index 6432769..3d2d257 100644 --- a/src/domains/seal/types.ts +++ b/src/domains/seal/types.ts @@ -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; export type SealSessionData = z.infer; export type ApprovalRule = z.infer; @@ -229,3 +246,6 @@ export type ApprovalIntegration = z.infer; export type ApprovalStylePreferences = z.infer; export type ApprovalRun = z.infer; export type ApprovalRunListData = z.infer; +export type SealDelegationItem = z.infer; +export type SealDelegationCreateResult = z.infer; +