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

+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>;