Add user search, activation, and automated delegation flow and bump version to 0.4.0
Binaries / Verify (push) Has been cancelled
Binaries / Build linux-x64 (push) Has been cancelled
Binaries / Build macos-arm64 (push) Has been cancelled
Binaries / Build windows-x64 (push) Has been cancelled
Binaries / Publish release assets (push) Has been cancelled

This commit is contained in:
gitea committed 2026-07-29 17:24:22 +08:00
1 parent 957cd2f70e
commit c0318df70b
8 files changed
+193 -7

No files matched your search

+6 -6
View File
@@ -1,13 +1,13 @@
---
name: seal-home
version: 0.3.8
description: "v0.3.8: Use when working with Seal Home approval automation: 合思/易快报企业认证, Hose authorization links, approval run lookup, LLM config, permissions, billing status, users & password reset, delegation links, approval rules, documents, search, and Langfuse hints."
version: 0.4.0
description: "v0.4.0: Use when working with Seal Home approval automation: 合思/易快报企业认证, Hose authorization links, approval run lookup, LLM config, permissions, billing status, user search, user activation, admin delegation link generation, delegation links, approval rules, documents, search, and Langfuse hints."
metadata:
version: 0.3.8
short-description: Seal approval automation tools (v0.3.8)
version: 0.4.0
short-description: Seal approval automation tools (v0.4.0)
---
# Seal Home (v0.3.8)
# Seal Home (v0.4.0)
Use the global `seal-home` CLI. This skill is a routing layer for agents: keep this file short, choose the right command, and read a focused reference only when the task needs detail.
@@ -30,7 +30,7 @@ seal-home tools list
## Route By Intent
- Delegation links (授权链接): `seal-home delegation list`, `create [--note ...]`, `revoke <tokenId>`.
- User & Contacts Management (用户与重置默认密码): `seal-home users create --name ... --phone ...`, `reset-password <userId>`, `get <userId>`, `delete <userId>`.
- User & Contacts Management (用户搜索、激活与一键代生成授权): `seal-home users search [keyword]`, `users delegation <userIdOrPhone>`, `users activate <userId>`, `users create --name ... --phone ...`, `reset-password <userId>`, `get <userId>`, `delete <userId>`.
- LLM Model Config & Providers: `seal-home llm config`, `seal-home llm providers`.
- System Permissions Config: `seal-home permissions available`, `seal-home permissions configs`.
- Billing & Feature Quotas: `seal-home billing status`, `seal-home billing plans`, `seal-home billing features`.
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "seal-home",
"version": "0.3.8",
"version": "0.4.0",
"type": "module",
"module": "src/server.ts",
"bin": {
+21
View File
@@ -177,6 +177,12 @@ async function main() {
return;
}
if (area === "users" && (action === "search" || action === "list")) {
const keyword = maybeName ?? stringOption(args.options.keyword) ?? stringOption(args.options.query) ?? "";
await runTool("seal_user_search", client, corp, { keyword }, outputOptions(args.options));
return;
}
if (area === "users" && action === "get") {
const userId = maybeName ?? stringOption(args.options.userId);
if (!userId) throw new Error("Usage: seal-home users get <userId>");
@@ -191,6 +197,21 @@ async function main() {
return;
}
if (area === "users" && action === "activate") {
const userId = maybeName ?? stringOption(args.options.userId);
if (!userId) throw new Error("Usage: seal-home users activate <userId>");
await runTool("seal_user_activate", client, corp, { userId }, outputOptions(args.options));
return;
}
if (area === "users" && (action === "delegation" || action === "impersonate")) {
const userIdOrPhone = maybeName ?? stringOption(args.options.userId) ?? stringOption(args.options.phone);
if (!userIdOrPhone) throw new Error("Usage: seal-home users delegation <userIdOrPhone> [--note <note>]");
const note = stringOption(args.options.note);
await runTool("seal_user_delegation_create", client, corp, { userIdOrPhone, note }, outputOptions(args.options));
return;
}
if (area === "llm" && (action === "config" || action === "get")) {
await runTool("seal_llm_config_get", client, corp, {}, outputOptions(args.options));
return;
+24
View File
@@ -28,3 +28,27 @@ export async function createSealClient(corp: CorpConfig): Promise<KyInstance> {
}
});
}
export async function createSealClientForToken(corp: CorpConfig, token: string): Promise<KyInstance> {
const session = await getSealSessionForCorp(corp);
return ky.create({
prefix: session.enterprise.sealUrl,
timeout: 30000,
headers: {
Authorization: `Bearer ${token}`
},
hooks: {
beforeError: [
async ({ error }) => {
const body =
error instanceof HTTPError
? await error.response.text().catch(() => "")
: "";
error.message = `${error.message}${body ? `: ${body}` : ""}`;
return error;
}
]
}
});
}
+94
View File
@@ -31,6 +31,8 @@ import {
SealUserResetPasswordResultSchema,
SealUserDetail,
SealUserDetailSchema,
SealContactSearchResult,
SealContactSearchResultSchema,
LlmConfig,
LlmConfigSchema,
LlmProvider,
@@ -396,6 +398,16 @@ export async function getUserDetail(
);
}
export async function searchUsers(
client: KyInstance,
keyword = ""
): Promise<SealContactSearchResult> {
return unwrap(
await client.get("api/v1/contacts/search", { searchParams: { keyword } }),
SealContactSearchResultSchema
);
}
export async function deleteLocalUser(
client: KyInstance,
userId: string
@@ -405,6 +417,88 @@ export async function deleteLocalUser(
return json.data?.success ?? response.ok;
}
export async function activateLocalUser(
client: KyInstance,
userId: string
): Promise<boolean> {
const response = await client.post(`api/v1/contacts/local/users/${userId}/activate`, { json: {} });
const json = (await response.json()) as { data?: { success?: boolean } };
return json.data?.success ?? response.ok;
}
export async function loginWithPhonePassword(
client: KyInstance,
params: { phone: string; password: string }
): Promise<{ token: string; user: unknown }> {
const response = await client.post("api/auth/sms-otp/sign-in-password", {
json: params
});
const setAuthToken = response.headers.get("set-auth-token");
const json = (await response.json()) as { user?: unknown; session?: { token?: string } };
const token = setAuthToken ?? json.session?.token;
if (!token) {
throw new Error("Failed to retrieve authentication token from login response");
}
return { token, user: json.user };
}
export async function createDelegationForUser(
client: KyInstance,
params: { userIdOrPhone: string; note?: string },
createClientForToken: (token: string) => Promise<KyInstance>
): Promise<{
targetUser: SealUserDetail;
delegation: SealDelegationCreateResult;
temporaryPassword: string;
}> {
let user: SealUserDetail;
if (params.userIdOrPhone.startsWith("+") || /^\d{11}$/.test(params.userIdOrPhone)) {
const search = await searchUsers(client, params.userIdOrPhone);
const found = search.users.find(
(u) => u.mobile?.includes(params.userIdOrPhone) || u._id === params.userIdOrPhone
) ?? search.users[0];
if (!found) {
throw new Error(`User not found with phone/ID: ${params.userIdOrPhone}`);
}
user = found;
} else {
user = await getUserDetail(client, params.userIdOrPhone).catch(async () => {
const search = await searchUsers(client, params.userIdOrPhone);
const found = search.users[0];
if (!found) throw new Error(`User not found: ${params.userIdOrPhone}`);
return found;
});
}
if (user.status === "resigned") {
await activateLocalUser(client, user._id);
user = await getUserDetail(client, user._id);
}
const resetRes = await resetUserPassword(client, user._id);
const rawPhone = user.mobile || (user as unknown as { identities?: Array<{ providerId?: string }> }).identities?.[0]?.providerId || "";
const cleanPhone = rawPhone.replace(/^\+86/, "");
if (!cleanPhone) {
throw new Error(`User ${user.name} has no associated phone number for password login`);
}
const { token } = await loginWithPhonePassword(client, {
phone: cleanPhone,
password: resetRes.password
});
const userClient = await createClientForToken(token);
const delegation = await createDelegation(userClient, {
note: params.note ?? `Delegation generated by admin for ${user.name}`
});
return {
targetUser: user,
delegation,
temporaryPassword: resetRes.password
};
}
export async function getLlmConfig(client: KyInstance): Promise<LlmConfig> {
return unwrap(await client.get("api/v1/llm/config"), LlmConfigSchema);
}
+6
View File
@@ -70,12 +70,18 @@ describe("sealTools", () => {
const createTool = sealTools.find((item) => item.name === "seal_user_create");
const resetTool = sealTools.find((item) => item.name === "seal_user_reset_password");
const getTool = sealTools.find((item) => item.name === "seal_user_get");
const searchTool = sealTools.find((item) => item.name === "seal_user_search");
const deleteTool = sealTools.find((item) => item.name === "seal_user_delete");
const activateTool = sealTools.find((item) => item.name === "seal_user_activate");
const userDelegationTool = sealTools.find((item) => item.name === "seal_user_delegation_create");
expect(createTool).toBeDefined();
expect(resetTool).toBeDefined();
expect(getTool).toBeDefined();
expect(searchTool).toBeDefined();
expect(deleteTool).toBeDefined();
expect(activateTool).toBeDefined();
expect(userDelegationTool).toBeDefined();
});
test("includes system configuration tools", () => {
+35
View File
@@ -3,6 +3,7 @@ import { KyInstance } from "ky";
import * as api from "./api.js";
import { getHoseEnterpriseUrl } from "../../core/auth/hose.js";
import { CorpConfig } from "../../core/config/types.js";
import { createSealClientForToken } from "../../core/http/factory.js";
import { searchApprovalContent } from "./search.js";
import type { ApprovalRule, ApprovalRun, RuleSetVersion } from "./types.js";
@@ -86,6 +87,15 @@ export const sealTools = [
handler: async (client: KyInstance, params: { userId: string }) =>
api.getUserDetail(client, params.userId)
},
{
name: "seal_user_search",
description: "按姓名、手机号或邮箱搜索 Seal 成员用户列表",
parameters: z.object({
keyword: z.string().optional().describe("搜索关键词(姓名、手机号、邮箱等),不传或传空字符串可列出租户成员")
}),
handler: async (client: KyInstance, params: { keyword?: string }) =>
api.searchUsers(client, params.keyword ?? "")
},
{
name: "seal_user_delete",
description: "删除指定 Seal 本地用户",
@@ -95,6 +105,31 @@ export const sealTools = [
handler: async (client: KyInstance, params: { userId: string }) =>
api.deleteLocalUser(client, params.userId)
},
{
name: "seal_user_activate",
description: "启用/激活已离职的 Seal 用户账号",
parameters: z.object({
userId: z.string().describe("用户 ID (_id)")
}),
handler: async (client: KyInstance, params: { userId: string }) =>
api.activateLocalUser(client, params.userId)
},
{
name: "seal_user_delegation_create",
description: "为指定 Seal 用户(按用户ID、手机号或姓名)重置密码登录并生成其专属授权链接 (Delegation)",
parameters: z.object({
userIdOrPhone: z.string().describe("目标用户 ID、手机号或姓名"),
note: z.string().optional().describe("授权链接备注信息")
}),
handler: async (
client: KyInstance,
params: { userIdOrPhone: string; note?: string },
context: ToolContext
) =>
api.createDelegationForUser(client, params, (token) =>
createSealClientForToken(context.corp, token)
)
},
{
name: "seal_llm_config_get",
description: "查询当前 Seal 租户的大模型 (LLM) 配置",
+6
View File
@@ -256,6 +256,11 @@ export const SealUserDetailSchema = z.object({
updatedAt: z.string().optional()
}).passthrough();
export const SealContactSearchResultSchema = z.object({
departments: z.array(z.record(z.string(), z.unknown())).default([]),
users: z.array(SealUserDetailSchema).default([])
}).passthrough();
export const LlmConfigSchema = z.object({
provider: z.string(),
config: z.record(z.string(), z.unknown()).default({})
@@ -303,6 +308,7 @@ export type SealDelegationCreateResult = z.infer<typeof SealDelegationCreateResu
export type SealUserCreateResult = z.infer<typeof SealUserCreateResultSchema>;
export type SealUserResetPasswordResult = z.infer<typeof SealUserResetPasswordResultSchema>;
export type SealUserDetail = z.infer<typeof SealUserDetailSchema>;
export type SealContactSearchResult = z.infer<typeof SealContactSearchResultSchema>;
export type LlmConfig = z.infer<typeof LlmConfigSchema>;
export type LlmProvider = z.infer<typeof LlmProviderSchema>;
export type AvailablePermissionsData = z.infer<typeof AvailablePermissionsDataSchema>;