Rename the internal tool registry to capability registry
This commit is contained in:
1 parent
f8b2b2ecde
commit
bc9256a9d9
41 files changed
+470
-452
No files matched your search
@@ -7,9 +7,9 @@ import { join } from "node:path";
|
||||
import { CorpConfig } from "../../core/config/types.js";
|
||||
import { CliError } from "../../core/errors.js";
|
||||
import { saveRuleMappingSnapshot } from "./rule-mapping.js";
|
||||
import { buildRulePushPlan, findSealTool, sealTools } from "./tools.js";
|
||||
import { buildRulePushPlan, findSealCapability, sealCapabilities } from "./capabilities.js";
|
||||
|
||||
type ToolHandler = (
|
||||
type CapabilityHandler = (
|
||||
client: KyInstance,
|
||||
params: Record<string, unknown>,
|
||||
context: { corp: CorpConfig }
|
||||
@@ -30,9 +30,9 @@ afterEach(() => {
|
||||
}
|
||||
});
|
||||
|
||||
describe("sealTools", () => {
|
||||
describe("sealCapabilities", () => {
|
||||
test("exposes concrete JSON schemas for parameterized tools", () => {
|
||||
const createRule = sealTools.find((tool) => tool.name === "seal_approval_rule_create");
|
||||
const createRule = sealCapabilities.find((tool) => tool.name === "seal_approval_rule_create");
|
||||
expect(createRule).toBeDefined();
|
||||
|
||||
const schema = z.toJSONSchema(createRule!.parameters) as {
|
||||
@@ -49,35 +49,35 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("includes the approval context aggregation tool", () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_context_get");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_context_get");
|
||||
expect(tool).toBeDefined();
|
||||
});
|
||||
|
||||
test("includes the session diagnostic tool", () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_session_get");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_session_get");
|
||||
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");
|
||||
const listTool = sealCapabilities.find((item) => item.name === "seal_delegation_list");
|
||||
const createCapability = sealCapabilities.find((item) => item.name === "seal_delegation_create");
|
||||
const revokeTool = sealCapabilities.find((item) => item.name === "seal_delegation_revoke");
|
||||
|
||||
expect(listTool).toBeDefined();
|
||||
expect(createTool).toBeDefined();
|
||||
expect(createCapability).toBeDefined();
|
||||
expect(revokeTool).toBeDefined();
|
||||
});
|
||||
|
||||
test("includes user management tools", () => {
|
||||
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");
|
||||
const createCapability = sealCapabilities.find((item) => item.name === "seal_user_create");
|
||||
const resetTool = sealCapabilities.find((item) => item.name === "seal_user_reset_password");
|
||||
const getTool = sealCapabilities.find((item) => item.name === "seal_user_get");
|
||||
const searchTool = sealCapabilities.find((item) => item.name === "seal_user_search");
|
||||
const deleteTool = sealCapabilities.find((item) => item.name === "seal_user_delete");
|
||||
const activateTool = sealCapabilities.find((item) => item.name === "seal_user_activate");
|
||||
const userDelegationTool = sealCapabilities.find((item) => item.name === "seal_user_delegation_create");
|
||||
|
||||
expect(createTool).toBeDefined();
|
||||
expect(createCapability).toBeDefined();
|
||||
expect(resetTool).toBeDefined();
|
||||
expect(getTool).toBeDefined();
|
||||
expect(searchTool).toBeDefined();
|
||||
@@ -87,105 +87,105 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("includes read-only contacts directory tools", () => {
|
||||
expect(sealTools.find((item) => item.name === "seal_contacts_departments_root_list")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_contacts_department_get")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_contacts_department_children_list")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_contacts_department_users_list")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_contacts_last_sync_time_get")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_contacts_departments_root_list")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_contacts_department_get")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_contacts_department_children_list")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_contacts_department_users_list")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_contacts_last_sync_time_get")).toBeDefined();
|
||||
});
|
||||
|
||||
test("includes the read-only insight stats and analytics tools", () => {
|
||||
expect(sealTools.find((item) => item.name === "seal_insight_stats_get")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_insight_risks_by_tag_get")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_insight_performance_get")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_insight_record_analyze")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_insight_export")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_insight_stats_get")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_insight_risks_by_tag_get")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_insight_performance_get")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_insight_record_analyze")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_insight_export")).toBeDefined();
|
||||
});
|
||||
|
||||
test("includes read-only financial data tools", () => {
|
||||
expect(sealTools.find((item) => item.name === "seal_expenses_list")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_invoices_list")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_expenses_list")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_invoices_list")).toBeDefined();
|
||||
});
|
||||
|
||||
test("includes the Feishu simulation approval definition tool", () => {
|
||||
expect(sealTools.find((item) => item.name === "seal_simulation_feishu_approval_definitions_list")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_simulation_feishu_approval_definitions_list")).toBeDefined();
|
||||
});
|
||||
|
||||
test("includes system configuration tools", () => {
|
||||
expect(sealTools.find((item) => item.name === "seal_llm_config_get")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_llm_providers_list")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_permissions_available_list")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_permissions_configs_list")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_billing_status_get")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_billing_plans_list")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_billing_features_list")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_llm_config_get")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_llm_providers_list")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_permissions_available_list")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_permissions_configs_list")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_billing_status_get")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_billing_plans_list")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_billing_features_list")).toBeDefined();
|
||||
});
|
||||
|
||||
test("includes Webhook management tools", () => {
|
||||
expect(sealTools.find((item) => item.name === "seal_webhook_list")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_webhook_get")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_webhook_add")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_webhook_update")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_webhook_delete")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_webhook_replay")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_webhook_list")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_webhook_get")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_webhook_add")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_webhook_update")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_webhook_delete")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_webhook_replay")).toBeDefined();
|
||||
});
|
||||
|
||||
test("includes deploy hosecloud tools", () => {
|
||||
expect(sealTools.find((item) => item.name === "seal_deploy_hosecloud_requirements")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_deploy_hosecloud_list")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_deploy_hosecloud_get")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_deploy_hosecloud_status")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_deploy_hosecloud_configure")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_deploy_hosecloud_sync")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_deploy_hosecloud_requirements")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_deploy_hosecloud_list")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_deploy_hosecloud_get")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_deploy_hosecloud_status")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_deploy_hosecloud_configure")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_deploy_hosecloud_sync")).toBeDefined();
|
||||
});
|
||||
|
||||
test("includes preference and thinking-depth tools", () => {
|
||||
expect(sealTools.find((item) => item.name === "seal_preference_get")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_preference_decision_update")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_preference_thinking_depth_set")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_preference_thinking_depth_policies_list")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_preference_thinking_depth_policies_upsert")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_preference_thinking_depth_policies_remove")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_preference_get")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_preference_decision_update")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_preference_thinking_depth_set")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_preference_thinking_depth_policies_list")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_preference_thinking_depth_policies_upsert")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_preference_thinking_depth_policies_remove")).toBeDefined();
|
||||
});
|
||||
|
||||
test("includes simulation wait, clean, specifications tools and approval run stats/count", () => {
|
||||
expect(sealTools.find((item) => item.name === "seal_simulation_batch_wait")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_simulation_batch_clean")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_simulation_specifications_list")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_approval_runs_stats")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_approval_runs_count")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_simulation_batch_wait")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_simulation_batch_clean")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_simulation_specifications_list")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_approval_runs_stats")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_approval_runs_count")).toBeDefined();
|
||||
});
|
||||
|
||||
test("includes the approval search tool", () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_search");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_search");
|
||||
expect(tool).toBeDefined();
|
||||
});
|
||||
|
||||
test("approval rules list can return count only", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_rules_list");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_rules_list");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(fakeRulesClient(), { countOnly: true }, fakeContext());
|
||||
|
||||
expect(result).toEqual({ count: 2 });
|
||||
});
|
||||
|
||||
test("approval rules list treats limit zero as count only", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_rules_list");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_rules_list");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(fakeRulesClient(), { fields: ["id"], limit: 0 }, fakeContext());
|
||||
|
||||
expect(result).toEqual({ count: 2 });
|
||||
});
|
||||
|
||||
test("approval rules list can project lightweight fields", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_rules_list");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_rules_list");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(
|
||||
fakeRulesClient(),
|
||||
{ fields: ["id", "code", "status", "strictness", "scope"], limit: 1 },
|
||||
@@ -206,10 +206,10 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval rules list renders timestamps in standard Beijing ISO format", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_rules_list");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_rules_list");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
|
||||
const full = await handler(fakeRulesClient(), {}, fakeContext()) as {
|
||||
rules: Array<Record<string, unknown>>;
|
||||
@@ -255,9 +255,9 @@ describe("sealTools", () => {
|
||||
}]
|
||||
});
|
||||
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_rule_get");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_rule_get");
|
||||
expect(tool).toBeDefined();
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const context = { corp: { ...fakeContext().corp, testCorpId: "t-corp-1" } };
|
||||
|
||||
const draft = await handler(fakeRulesClient(), { code: "29" }, context) as Record<string, unknown>;
|
||||
@@ -274,9 +274,9 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval rule update without --if-unchanged leaves concurrency check absent", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_rule_update");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_rule_update");
|
||||
expect(tool).toBeDefined();
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(
|
||||
fakeRuleUpdateClient(1780898164536),
|
||||
{ ruleId: "29", description: "当单据金额超过 5000 元时必须提供发票原件与行程证明。" },
|
||||
@@ -286,8 +286,8 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval rule update --if-unchanged rejects when the draft moved on (exit 13)", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_rule_update");
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_rule_update");
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
try {
|
||||
await handler(
|
||||
fakeRuleUpdateClient(1780898164536),
|
||||
@@ -302,8 +302,8 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval rule update --if-unchanged proceeds when the draft is unchanged", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_rule_update");
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_rule_update");
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(
|
||||
fakeRuleUpdateClient(1780898164536),
|
||||
{ ruleId: "29", description: "当单据金额超过 5000 元时必须提供发票原件与行程证明。", ifUnchanged: "2026-06-08T13:56:04+08:00" },
|
||||
@@ -313,9 +313,9 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("seal_approval_run_diagnose aggregates document, result, cited rules, and version snapshot", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_run_diagnose");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_run_diagnose");
|
||||
expect(tool).toBeDefined();
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
|
||||
const byRecord = await handler(fakeDiagnoseClient(), { recordId: "run-1" }, fakeContext()) as Record<string, any>;
|
||||
expect(byRecord.recordId).toBe("run-1");
|
||||
@@ -339,11 +339,11 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval rules clear can dry run without deleting", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_rules_clear");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_rules_clear");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const client = fakeClearRulesClient();
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(client, { dryRun: true }, fakeContext()) as {
|
||||
dryRun: boolean;
|
||||
beforeCount: number;
|
||||
@@ -361,11 +361,11 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval rules clear deletes all draft rules", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_rules_clear");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_rules_clear");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const client = fakeClearRulesClient();
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(client, {}, fakeContext()) as {
|
||||
dryRun: boolean;
|
||||
beforeCount: number;
|
||||
@@ -385,7 +385,7 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("preference dry run reads config without patching it", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_preference_decision_update");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_preference_decision_update");
|
||||
expect(tool).toBeDefined();
|
||||
let patched = false;
|
||||
const client = {
|
||||
@@ -408,7 +408,7 @@ describe("sealTools", () => {
|
||||
}
|
||||
} as unknown as KyInstance;
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(client, { explicitApprove: "new", dryRun: true }, fakeContext()) as {
|
||||
preview: boolean;
|
||||
targetUrl: string;
|
||||
@@ -503,22 +503,22 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("includes approval run Langfuse bridge tools", () => {
|
||||
expect(sealTools.find((item) => item.name === "seal_approval_runs_search")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_approval_runs_summary")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_simulation_batch_records_get")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_approval_run_langfuse_bridge_get")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_approval_runs_search")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_approval_runs_summary")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_simulation_batch_records_get")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_approval_run_langfuse_bridge_get")).toBeDefined();
|
||||
});
|
||||
|
||||
test("can find tools by name in sealTools", () => {
|
||||
expect(findSealTool("seal_approval_rule_create")).toBeDefined();
|
||||
expect(findSealTool("non_existent_tool")).toBeUndefined();
|
||||
test("can find tools by name in sealCapabilities", () => {
|
||||
expect(findSealCapability("seal_approval_rule_create")).toBeDefined();
|
||||
expect(findSealCapability("non_existent_tool")).toBeUndefined();
|
||||
});
|
||||
|
||||
test("approval run search omits bridge unless requested", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_runs_search");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_runs_search");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(fakeApprovalRunsClient(), { limit: 1 }, fakeContext());
|
||||
|
||||
expect(result).not.toHaveProperty("bridge");
|
||||
@@ -526,10 +526,10 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval run search can filter by extracted human result", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_runs_search");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_runs_search");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(
|
||||
fakeApprovalRunsClient(),
|
||||
{ humanResult: "驳回", limit: 10 },
|
||||
@@ -551,11 +551,11 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval run search maps rejected human result to manual approval status", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_runs_search");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_runs_search");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const requests: string[] = [];
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
await handler(
|
||||
fakeApprovalRunsClient(requests),
|
||||
{
|
||||
@@ -573,11 +573,11 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval run search forwards query as API search parameter", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_runs_search");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_runs_search");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const requests: string[] = [];
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
await handler(
|
||||
fakeApprovalRunsClient(requests),
|
||||
{
|
||||
@@ -595,10 +595,10 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval run get returns stable aliases for document concepts", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_run_get");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_run_get");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(
|
||||
fakeApprovalRunsClient(),
|
||||
{ recordId: "run-1" },
|
||||
@@ -627,10 +627,10 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval run get can return selected fields only", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_run_get");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_run_get");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(
|
||||
fakeApprovalRunsClient(),
|
||||
{ recordId: "run-1", fields: "metadata,document.fields,result.summary" },
|
||||
@@ -650,10 +650,10 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval run get can return summary preset", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_run_get");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_run_get");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(
|
||||
fakeApprovalRunsClient(),
|
||||
{ recordId: "run-1", summary: true },
|
||||
@@ -666,11 +666,11 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval run pick supports sn latest and compact candidate fields", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_run_pick");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_run_pick");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const requests: string[] = [];
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(
|
||||
fakeApprovalRunsClient(requests),
|
||||
{ sn: "B26001965", latest: true },
|
||||
@@ -687,10 +687,10 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval run attachments extracts compact attachment metadata", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_run_attachments_get");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_run_attachments_get");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(
|
||||
fakeApprovalRunsClient(),
|
||||
{ recordId: "run-1" },
|
||||
@@ -713,10 +713,10 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval run cited rules extracts rule application details", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_run_cited_rules_get");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_run_cited_rules_get");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(
|
||||
fakeApprovalRunsClient(),
|
||||
{ recordId: "run-1" },
|
||||
@@ -736,10 +736,10 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval run document summary returns key fields without raw payload", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_run_document_summary_get");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_run_document_summary_get");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(
|
||||
fakeApprovalRunsClient(),
|
||||
{ recordId: "run-1" },
|
||||
@@ -756,10 +756,10 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval run result can return summary only", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_run_result_get");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_run_result_get");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(
|
||||
fakeApprovalRunsClient(),
|
||||
{ recordId: "run-1", summary: true },
|
||||
@@ -782,10 +782,10 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval run url returns Seal result and Hose document links by recordId", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_run_url_get");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_run_url_get");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(
|
||||
fakeApprovalRunsClient(),
|
||||
{ recordId: "run-1" },
|
||||
@@ -822,10 +822,10 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval run url supports type=hose-document", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_run_url_get");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_run_url_get");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(
|
||||
fakeApprovalRunsClient(),
|
||||
{ recordId: "run-1", type: "hose-document" },
|
||||
@@ -846,11 +846,11 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval run url throws error without a document lookup", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_run_url_get");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_run_url_get");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const requests: string[] = [];
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
await expect(
|
||||
handler(
|
||||
fakeApprovalRunsClient(requests),
|
||||
@@ -862,12 +862,12 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval run url can resolve by sourceDocumentSN", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_run_url_get");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_run_url_get");
|
||||
expect(tool).toBeDefined();
|
||||
primeHoseEnterpriseUrl("corp-a", "https://app.ekuaibao.com/web/home.html?accessToken=close-token");
|
||||
|
||||
const requests: string[] = [];
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(
|
||||
fakeApprovalRunsClient(requests),
|
||||
{ sourceDocumentSN: "B26001965" },
|
||||
@@ -883,11 +883,11 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval run url returns auto_login link with identity, expiration, and warning when autoLogin=true", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_run_url_get");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_run_url_get");
|
||||
expect(tool).toBeDefined();
|
||||
primeHoseEnterpriseUrl("corp-a", "https://app.ekuaibao.com/web/home.html?accessToken=close-token");
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = (await handler(
|
||||
fakeApprovalRunsClient(),
|
||||
{ recordId: "run-1", autoLogin: true, expiresIn: 3600 },
|
||||
@@ -912,11 +912,11 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval run url supports legacy hoseSso=true with explicit hose attribute naming", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_run_url_get");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_run_url_get");
|
||||
expect(tool).toBeDefined();
|
||||
primeHoseEnterpriseUrl("corp-a", "https://app.ekuaibao.com/web/home.html?accessToken=close-token");
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = (await handler(
|
||||
fakeApprovalRunsClient(),
|
||||
{ recordId: "run-1", hoseSso: true },
|
||||
@@ -937,10 +937,10 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval run url throws clear error when sso=true is used on non-hose enterprise", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_run_url_get");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_run_url_get");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
await expect(
|
||||
handler(
|
||||
fakeApprovalRunsClient(),
|
||||
@@ -951,10 +951,10 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval run summary filters by local date and returns compact aggregates", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_runs_summary");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_runs_summary");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(
|
||||
fakeApprovalRunsClient(),
|
||||
{ date: "2026-06-08", timezone: "Asia/Shanghai", limit: 100 },
|
||||
@@ -977,10 +977,10 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval rule get resolves one rule by version and code", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_rule_get");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_rule_get");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(
|
||||
fakeRulesClient(),
|
||||
{ versionNumber: 16, code: "44" },
|
||||
@@ -998,9 +998,9 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval rule get defaults to current draft and handles 0-based codes without +1 offset", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_rule_get");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_rule_get");
|
||||
expect(tool).toBeDefined();
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const client = fakeZeroBasedRulesClient();
|
||||
|
||||
// Draft lookup for code 0
|
||||
@@ -1049,9 +1049,9 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("approval run cited-rules extracts and merges result.rulesResult and result.hitRules", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_run_cited_rules_get");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_run_cited_rules_get");
|
||||
expect(tool).toBeDefined();
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
|
||||
const mockClient = {
|
||||
get: () => ({
|
||||
@@ -1124,10 +1124,10 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("deploy hosecloud configure saves integration and rejects missing customApiUrl", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_deploy_hosecloud_configure");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_deploy_hosecloud_configure");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const client = fakeDeployClient();
|
||||
|
||||
// 1. Rejects custom environment without customApiUrl
|
||||
@@ -1165,10 +1165,10 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("deploy hosecloud status masks signKey alongside apiKey/apiSecret", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_deploy_hosecloud_status");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_deploy_hosecloud_status");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const client = {
|
||||
get: (url: string) => {
|
||||
if (url === "api/v1/simulation/integration-status") {
|
||||
@@ -1208,7 +1208,7 @@ describe("sealTools", () => {
|
||||
});
|
||||
|
||||
test("seal_approval_runs_count supports startDate and endDate and normalizes them", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_approval_runs_count");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_approval_runs_count");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const schema = z.toJSONSchema(tool!.parameters) as {
|
||||
@@ -1220,7 +1220,7 @@ describe("sealTools", () => {
|
||||
|
||||
const requests: string[] = [];
|
||||
const client = fakeApprovalRunsClient(requests);
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
|
||||
const res = await handler(
|
||||
client,
|
||||
@@ -0,0 +1,3 @@
|
||||
// Re-export from modular capabilities/ directory.
|
||||
// capabilities.ts was split into domain-specific modules under src/domains/seal/capabilities/.
|
||||
export * from "./capabilities/index.js";
|
||||
+7
-7
@@ -14,7 +14,7 @@ import {
|
||||
type ApprovalRun
|
||||
} from "../types.js";
|
||||
import type {
|
||||
ToolContext
|
||||
CapabilityContext
|
||||
} from "./helpers.js";
|
||||
import * as helpers from "./helpers.js";
|
||||
|
||||
@@ -45,7 +45,7 @@ const {
|
||||
summarizeRuleVersion
|
||||
} = helpers;
|
||||
|
||||
export const approvalRunsTools = [
|
||||
export const approvalRunsCapabilities = [
|
||||
{
|
||||
name: "seal_approval_runs_search",
|
||||
description: "查询 Seal 审批/审核运行记录总表,并整理合思单据到 Langfuse trace/session 的桥接字段",
|
||||
@@ -194,7 +194,7 @@ export const approvalRunsTools = [
|
||||
outputFile?: string;
|
||||
toDownloads?: boolean;
|
||||
},
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => exportApprovalRunsToExcel(client, context.corp, params)
|
||||
},
|
||||
{
|
||||
@@ -231,7 +231,7 @@ export const approvalRunsTools = [
|
||||
handler: async (
|
||||
client: KyInstance,
|
||||
params: { target?: string; recordId?: string; sourceDocumentSN?: string },
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => {
|
||||
const corp = context.corp;
|
||||
if (corp.source.type !== "hose") {
|
||||
@@ -456,7 +456,7 @@ export const approvalRunsTools = [
|
||||
hoseSso?: boolean;
|
||||
expiresIn?: number;
|
||||
},
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => {
|
||||
const hasDocumentLookup = Boolean(params.recordId || params.sourceDocumentSN || params.sourceDocumentId);
|
||||
if (!hasDocumentLookup) {
|
||||
@@ -579,7 +579,7 @@ export const approvalRunsTools = [
|
||||
maxScan?: number;
|
||||
includeBridge?: boolean;
|
||||
},
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => {
|
||||
const query = params.sn ?? params.query;
|
||||
if (!query) throw new Error("query or sn is required");
|
||||
@@ -629,7 +629,7 @@ export const approvalRunsTools = [
|
||||
handler: async (
|
||||
client: KyInstance,
|
||||
params: { sn?: string; recordId?: string; full?: boolean },
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => {
|
||||
if (!params.sn && !params.recordId) {
|
||||
throw new Error("sn or recordId is required for approval run diagnosis");
|
||||
@@ -2,7 +2,7 @@ import { z } from "zod";
|
||||
import type { KyInstance } from "ky";
|
||||
import * as api from "../api.js";
|
||||
|
||||
export const billingTools = [
|
||||
export const billingCapabilities = [
|
||||
{
|
||||
name: "seal_llm_config_get",
|
||||
description: "查询当前 Seal 租户的大模型 (LLM) 配置",
|
||||
@@ -2,7 +2,7 @@ import { z } from "zod";
|
||||
import type { KyInstance } from "ky";
|
||||
import * as api from "../api.js";
|
||||
|
||||
export const contactsTools = [
|
||||
export const contactsCapabilities = [
|
||||
{
|
||||
name: "seal_contacts_departments_root_list",
|
||||
description: "列出当前 Seal 租户通讯录的顶级部门",
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
type HosecloudConfigInput
|
||||
} from "../types.js";
|
||||
import type {
|
||||
ToolContext
|
||||
CapabilityContext
|
||||
} from "./helpers.js";
|
||||
import * as helpers from "./helpers.js";
|
||||
|
||||
@@ -16,7 +16,7 @@ const {
|
||||
mutationPreview
|
||||
} = helpers;
|
||||
|
||||
export const deployTools = [
|
||||
export const deployCapabilities = [
|
||||
{
|
||||
name: "seal_deploy_hosecloud_requirements",
|
||||
description: "获取 Seal AI 审批发布到合思费控所需配置字段与说明",
|
||||
@@ -107,7 +107,7 @@ export const deployTools = [
|
||||
customApiUrl: z.string().optional(),
|
||||
dryRun: z.boolean().optional().describe("只返回前后配置 Diff,不执行写入")
|
||||
}),
|
||||
handler: async (client: KyInstance, rawParams: HosecloudConfigInput, context: ToolContext) => {
|
||||
handler: async (client: KyInstance, rawParams: HosecloudConfigInput, context: CapabilityContext) => {
|
||||
const { dryRun, ...inputParams } = rawParams;
|
||||
const apiKey = inputParams.apiKey ?? (inputParams as any).appKey;
|
||||
const apiSecret = inputParams.apiSecret ?? (inputParams as any).appSecurity;
|
||||
@@ -190,7 +190,7 @@ export const deployTools = [
|
||||
parameters: z.object({
|
||||
signKey: z.string().describe("合思集成 sign-key")
|
||||
}),
|
||||
handler: async (client: KyInstance, params: { signKey: string }, context: ToolContext) => {
|
||||
handler: async (client: KyInstance, params: { signKey: string }, context: CapabilityContext) => {
|
||||
const config = await api.getApprovalStylePreferences(client);
|
||||
const integration = (config.integrations ?? []).find(
|
||||
(item: any) => item.type === "hosecloud" && item.signKey === params.signKey
|
||||
@@ -15,15 +15,15 @@ import type { LocalRuleItem } from "../rules-local.js";
|
||||
import { loadRuleMappingSnapshot } from "../rule-mapping.js";
|
||||
import { formatBeijingIso, normalizeBeijingIso } from "../../../core/config/timestamps.js";
|
||||
|
||||
export type ToolContext = {
|
||||
export type CapabilityContext = {
|
||||
corp: CorpConfig;
|
||||
};
|
||||
|
||||
export type SealToolDefinition = {
|
||||
export type SealCapabilityDefinition = {
|
||||
name: string;
|
||||
description: string;
|
||||
parameters: z.ZodType;
|
||||
handler: (client: KyInstance, params: never, context: ToolContext) => Promise<unknown>;
|
||||
handler: (client: KyInstance, params: never, context: CapabilityContext) => Promise<unknown>;
|
||||
};
|
||||
|
||||
export function presentWebhookIntegration(
|
||||
@@ -285,7 +285,7 @@ export function redactIntegrationSecrets(integration: Record<string, unknown>) {
|
||||
}
|
||||
|
||||
export function mutationPreview(
|
||||
context: ToolContext,
|
||||
context: CapabilityContext,
|
||||
endpoint: string,
|
||||
before: unknown,
|
||||
after: unknown,
|
||||
@@ -3,10 +3,10 @@ import type { KyInstance } from "ky";
|
||||
import * as api from "../api.js";
|
||||
import { createSealClientForToken } from "../../../core/http/factory.js";
|
||||
import type {
|
||||
ToolContext
|
||||
CapabilityContext
|
||||
} from "./helpers.js";
|
||||
|
||||
export const identityTools = [
|
||||
export const identityCapabilities = [
|
||||
{
|
||||
name: "seal_whoami",
|
||||
description: "查询当前 Seal 用户身份及租户信息",
|
||||
@@ -112,7 +112,7 @@ export const identityTools = [
|
||||
handler: async (
|
||||
client: KyInstance,
|
||||
params: { userIdOrPhone: string; note?: string },
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) =>
|
||||
api.createDelegationForUser(
|
||||
client,
|
||||
@@ -1,38 +1,44 @@
|
||||
import { identityTools } from "./identity.js";
|
||||
import { contactsTools } from "./contacts.js";
|
||||
import { insightTools } from "./insight.js";
|
||||
import { billingTools } from "./billing.js";
|
||||
import { rulesTools } from "./rules.js";
|
||||
import { webhookTools } from "./webhook.js";
|
||||
import { approvalRunsTools } from "./approval-runs.js";
|
||||
import { simulationTools } from "./simulation.js";
|
||||
import { deployTools } from "./deploy.js";
|
||||
import { preferenceTools } from "./preference.js";
|
||||
import { identityCapabilities } from "./identity.js";
|
||||
import { contactsCapabilities } from "./contacts.js";
|
||||
import { insightCapabilities } from "./insight.js";
|
||||
import { billingCapabilities } from "./billing.js";
|
||||
import { rulesCapabilities } from "./rules.js";
|
||||
import { webhookCapabilities } from "./webhook.js";
|
||||
import { approvalRunsCapabilities } from "./approval-runs.js";
|
||||
import { simulationCapabilities } from "./simulation.js";
|
||||
import { deployCapabilities } from "./deploy.js";
|
||||
import { preferenceCapabilities } from "./preference.js";
|
||||
|
||||
export * from "./helpers.js";
|
||||
export * from "./validate.js";
|
||||
|
||||
export const sealTools = [
|
||||
...identityTools,
|
||||
...contactsTools,
|
||||
...insightTools,
|
||||
...billingTools,
|
||||
...rulesTools,
|
||||
...webhookTools,
|
||||
...approvalRunsTools,
|
||||
...simulationTools,
|
||||
...deployTools,
|
||||
...preferenceTools
|
||||
export const sealCapabilities = [
|
||||
...identityCapabilities,
|
||||
...contactsCapabilities,
|
||||
...insightCapabilities,
|
||||
...billingCapabilities,
|
||||
...rulesCapabilities,
|
||||
...webhookCapabilities,
|
||||
...approvalRunsCapabilities,
|
||||
...simulationCapabilities,
|
||||
...deployCapabilities,
|
||||
...preferenceCapabilities
|
||||
];
|
||||
|
||||
export type SealTool = (typeof sealTools)[number];
|
||||
export type SealCapability = (typeof sealCapabilities)[number];
|
||||
|
||||
/**
|
||||
* MCP read/write classification for the tool registry.
|
||||
* Registry naming boundary: these entries are INTERNAL domain capability handlers, NOT MCP tools.
|
||||
* The `seal_*` strings are identifiers for internal dispatch (`runCapability`), the HTTP adapter
|
||||
* (`POST /api/tool/:name`), and the MCP gateway allow-lists below — the MCP server itself only ever
|
||||
* exposes the `seal_cli` / `seal_cli_write` gateway pair and never these names. CLI verbs such as
|
||||
* `seal-use context` are the only human-facing names (see README "One registry, three doors").
|
||||
*
|
||||
* The two sets are exhaustive by construction: `tools.test.ts` asserts they partition `sealTools`
|
||||
* exactly, so a newly added tool fails the suite until it is classified here. The read-only MCP tool
|
||||
* (`seal_cli`) may only invoke names in {@link SEAL_READ_ONLY_TOOLS}; everything else is reachable
|
||||
* MCP read/write classification for the capability registry.
|
||||
*
|
||||
* The two sets are exhaustive by construction: `capabilities.test.ts` asserts they partition `sealCapabilities`
|
||||
* exactly, so a newly added capability fails the suite until it is classified here. The read-only MCP tool
|
||||
* (`seal_cli`) may only invoke names in {@link SEAL_READ_ONLY_CAPABILITIES}; everything else is reachable
|
||||
* solely through `seal_cli_write`.
|
||||
*
|
||||
* Read-only means it reads tenant state, or writes only a local file. Anything that creates, updates,
|
||||
@@ -40,7 +46,7 @@ export type SealTool = (typeof sealTools)[number];
|
||||
* including when it reads like a query. `seal_insight_record_analyze` is the instructive case: it
|
||||
* sounds like a read but issues a POST that starts an analysis server-side.
|
||||
*/
|
||||
export const SEAL_READ_ONLY_TOOLS: ReadonlySet<string> = new Set([
|
||||
export const SEAL_READ_ONLY_CAPABILITIES: ReadonlySet<string> = new Set([
|
||||
"seal_approval_context_get",
|
||||
"seal_approval_document_get",
|
||||
"seal_approval_documents_list",
|
||||
@@ -111,7 +117,7 @@ export const SEAL_READ_ONLY_TOOLS: ReadonlySet<string> = new Set([
|
||||
"seal_whoami"
|
||||
]);
|
||||
|
||||
export const SEAL_MUTATING_TOOLS: ReadonlySet<string> = new Set([
|
||||
export const SEAL_MUTATING_CAPABILITIES: ReadonlySet<string> = new Set([
|
||||
"seal_approval_delete_document",
|
||||
"seal_approval_document_create",
|
||||
"seal_approval_document_update",
|
||||
@@ -146,14 +152,14 @@ export const SEAL_MUTATING_TOOLS: ReadonlySet<string> = new Set([
|
||||
"seal_webhook_update"
|
||||
]);
|
||||
|
||||
export function isReadOnlySealTool(name: string): boolean {
|
||||
return SEAL_READ_ONLY_TOOLS.has(name);
|
||||
export function isReadOnlySealCapability(name: string): boolean {
|
||||
return SEAL_READ_ONLY_CAPABILITIES.has(name);
|
||||
}
|
||||
|
||||
const sealToolByName = new Map<string, SealTool>(
|
||||
sealTools.map((tool) => [tool.name, tool])
|
||||
const sealCapabilityByName = new Map<string, SealCapability>(
|
||||
sealCapabilities.map((tool) => [tool.name, tool])
|
||||
);
|
||||
|
||||
export function findSealTool(name: string): SealTool | undefined {
|
||||
return sealToolByName.get(name);
|
||||
export function findSealCapability(name: string): SealCapability | undefined {
|
||||
return sealCapabilityByName.get(name);
|
||||
}
|
||||
@@ -3,10 +3,10 @@ import type { KyInstance } from "ky";
|
||||
import * as api from "../api.js";
|
||||
import { exportInsightReportToExcel, type InsightExportOptions } from "../insight-export.js";
|
||||
import type {
|
||||
ToolContext
|
||||
CapabilityContext
|
||||
} from "./helpers.js";
|
||||
|
||||
export const insightTools = [
|
||||
export const insightCapabilities = [
|
||||
{
|
||||
name: "seal_insight_stats_get",
|
||||
description: "查询智能洞察风险标签统计及分析状态",
|
||||
@@ -70,7 +70,7 @@ export const insightTools = [
|
||||
handler: async (
|
||||
client: KyInstance,
|
||||
params: InsightExportOptions,
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => exportInsightReportToExcel(client, context.corp, params)
|
||||
},
|
||||
{
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
type DecisionPreferences
|
||||
} from "../types.js";
|
||||
import type {
|
||||
ToolContext
|
||||
CapabilityContext
|
||||
} from "./helpers.js";
|
||||
import * as helpers from "./helpers.js";
|
||||
|
||||
@@ -15,7 +15,7 @@ const {
|
||||
mutationPreview
|
||||
} = helpers;
|
||||
|
||||
export const preferenceTools = [
|
||||
export const preferenceCapabilities = [
|
||||
{
|
||||
name: "seal_preference_get",
|
||||
description: "获取当前决策偏好、思考深度偏好与绑定的规则版本",
|
||||
@@ -39,7 +39,7 @@ export const preferenceTools = [
|
||||
review: z.string().optional(),
|
||||
dryRun: z.boolean().optional().describe("只返回前后配置 Diff,不执行写入")
|
||||
}),
|
||||
handler: async (client: KyInstance, params: Partial<DecisionPreferences> & { dryRun?: boolean }, context: ToolContext) => {
|
||||
handler: async (client: KyInstance, params: Partial<DecisionPreferences> & { dryRun?: boolean }, context: CapabilityContext) => {
|
||||
const config = (await api.getApprovalStylePreferences(client, context.corp.seal.endpoints.approvalStylePreferences)) as any;
|
||||
const { dryRun, ...changes } = params;
|
||||
const updated = {
|
||||
@@ -63,7 +63,7 @@ export const preferenceTools = [
|
||||
defaultLevel: z.enum(["medium", "high"]).describe("默认思考深度"),
|
||||
dryRun: z.boolean().optional().describe("只返回前后配置 Diff,不执行写入")
|
||||
}),
|
||||
handler: async (client: KyInstance, params: { defaultLevel: "medium" | "high"; dryRun?: boolean }, context: ToolContext) => {
|
||||
handler: async (client: KyInstance, params: { defaultLevel: "medium" | "high"; dryRun?: boolean }, context: CapabilityContext) => {
|
||||
const config = (await api.getApprovalStylePreferences(client, context.corp.seal.endpoints.approvalStylePreferences)) as any;
|
||||
const updated = {
|
||||
...config,
|
||||
@@ -96,7 +96,7 @@ export const preferenceTools = [
|
||||
parameters: ThinkingPolicySchema.extend({
|
||||
dryRun: z.boolean().optional().describe("只返回前后配置 Diff,不执行写入")
|
||||
}),
|
||||
handler: async (client: KyInstance, policy: ThinkingPolicy & { dryRun?: boolean }, context: ToolContext) => {
|
||||
handler: async (client: KyInstance, policy: ThinkingPolicy & { dryRun?: boolean }, context: CapabilityContext) => {
|
||||
const config = (await api.getApprovalStylePreferences(client, context.corp.seal.endpoints.approvalStylePreferences)) as any;
|
||||
const { dryRun, ...cleanPolicy } = policy;
|
||||
const existing: ThinkingPolicy[] = config.thinkingDepthPreference?.routingPolicies ?? [];
|
||||
@@ -124,7 +124,7 @@ export const preferenceTools = [
|
||||
policyId: z.string().describe("路由策略 ID"),
|
||||
dryRun: z.boolean().optional().describe("只返回前后配置 Diff,不执行写入")
|
||||
}),
|
||||
handler: async (client: KyInstance, params: { policyId: string; dryRun?: boolean }, context: ToolContext) => {
|
||||
handler: async (client: KyInstance, params: { policyId: string; dryRun?: boolean }, context: CapabilityContext) => {
|
||||
const config = (await api.getApprovalStylePreferences(client, context.corp.seal.endpoints.approvalStylePreferences)) as any;
|
||||
const existing: ThinkingPolicy[] = config.thinkingDepthPreference?.routingPolicies ?? [];
|
||||
const next = existing.filter((item) => item.id !== params.policyId);
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
type RuleSetVersion
|
||||
} from "../types.js";
|
||||
import type {
|
||||
ToolContext,
|
||||
CapabilityContext,
|
||||
RuleField
|
||||
} from "./helpers.js";
|
||||
import * as helpers from "./helpers.js";
|
||||
@@ -42,12 +42,12 @@ const {
|
||||
resolveCrossEnvRuleMapping
|
||||
} = helpers;
|
||||
|
||||
function attachCrossEnvRule(context: ToolContext, rule: Record<string, unknown>) {
|
||||
function attachCrossEnvRule(context: CapabilityContext, rule: Record<string, unknown>) {
|
||||
const crossEnv = resolveCrossEnvRuleMapping(context.corp, rule);
|
||||
return crossEnv ? { ...rule, crossEnv } : rule;
|
||||
}
|
||||
|
||||
export const rulesTools = [
|
||||
export const rulesCapabilities = [
|
||||
{
|
||||
name: "seal_approval_rules_list",
|
||||
description: "列出 Seal 审批规则(默认当前草稿,传 version='latest' 或版本号则列出对应已发布版本);支持 countOnly、fields、limit",
|
||||
@@ -112,7 +112,7 @@ export const rulesTools = [
|
||||
handler: async (
|
||||
client: KyInstance,
|
||||
params: { dryRun?: boolean; recode?: boolean },
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => {
|
||||
const before = await api.listApprovalRules(client);
|
||||
if (params.dryRun) {
|
||||
@@ -207,7 +207,7 @@ export const rulesTools = [
|
||||
strictness?: string;
|
||||
ifUnchanged?: string | number;
|
||||
},
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => {
|
||||
let resolvedRuleId = params.ruleId.trim();
|
||||
const targetCodeNum = parseRuleCodeNumber(resolvedRuleId);
|
||||
@@ -362,7 +362,7 @@ export const rulesTools = [
|
||||
full?: boolean;
|
||||
format?: "unified" | "json";
|
||||
},
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => {
|
||||
const fromVersion = hydrateRuleVersionStableIds(context.corp.id, await resolveRuleVersionSelector(client, params.from));
|
||||
const toVersion = hydrateRuleVersionStableIds(context.corp.id, await resolveRuleVersionSelector(client, params.to));
|
||||
@@ -393,7 +393,7 @@ export const rulesTools = [
|
||||
parameters: z.object({
|
||||
versionName: z.string().describe("版本名称")
|
||||
}),
|
||||
handler: async (client: KyInstance, params: { versionName: string }, context: ToolContext) => {
|
||||
handler: async (client: KyInstance, params: { versionName: string }, context: CapabilityContext) => {
|
||||
const draft = await api.listApprovalRules(client).catch(() => undefined);
|
||||
const published = await api.publishApprovalRuleVersion(client, params.versionName);
|
||||
if (draft) {
|
||||
@@ -425,7 +425,7 @@ export const rulesTools = [
|
||||
ruleId?: string;
|
||||
recordId?: string;
|
||||
},
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => {
|
||||
const selector = {
|
||||
code: params.code,
|
||||
@@ -490,7 +490,7 @@ export const rulesTools = [
|
||||
level?: "all" | "error" | "warning";
|
||||
summary?: boolean;
|
||||
},
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => {
|
||||
let targets: RuleLintTarget[] = [];
|
||||
let versionNumber: number | undefined;
|
||||
@@ -578,7 +578,7 @@ export const rulesTools = [
|
||||
version?: string;
|
||||
out?: string;
|
||||
},
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => {
|
||||
const outPath = params.out ?? "./rules.local.json";
|
||||
let rules: LocalRuleItem[] = [];
|
||||
@@ -657,7 +657,7 @@ export const rulesTools = [
|
||||
publish?: boolean;
|
||||
versionName?: string;
|
||||
},
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => {
|
||||
const filePath = params.file ?? "./rules.local.json";
|
||||
let local: ReturnType<typeof loadLocalRulesFile>;
|
||||
@@ -890,7 +890,7 @@ export const rulesTools = [
|
||||
maxChars?: number;
|
||||
fields?: string[];
|
||||
},
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => searchApprovalContent(client, context.corp, params)
|
||||
},
|
||||
{
|
||||
@@ -910,7 +910,7 @@ export const rulesTools = [
|
||||
ruleVersionNumber?: number;
|
||||
latestRuleVersion?: boolean;
|
||||
},
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => {
|
||||
const currentContext = await api.getApprovalContext(client, {
|
||||
documentLimit: params.documentLimit,
|
||||
@@ -935,7 +935,7 @@ export const rulesTools = [
|
||||
name: "seal_approval_style_preferences_get",
|
||||
description: "获取 Seal 审批风格偏好配置",
|
||||
parameters: z.object({}),
|
||||
handler: async (client: KyInstance, _params: unknown, context: ToolContext) =>
|
||||
handler: async (client: KyInstance, _params: unknown, context: CapabilityContext) =>
|
||||
api.getApprovalStylePreferences(
|
||||
client,
|
||||
context.corp.seal.endpoints.approvalStylePreferences
|
||||
@@ -956,7 +956,7 @@ export const rulesTools = [
|
||||
handler: async (
|
||||
client: KyInstance,
|
||||
params: Record<string, unknown>,
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) =>
|
||||
api.updateApprovalStylePreferences(
|
||||
client,
|
||||
@@ -18,7 +18,7 @@ const {
|
||||
filterRuns
|
||||
} = helpers;
|
||||
|
||||
export const simulationTools = [
|
||||
export const simulationCapabilities = [
|
||||
{
|
||||
name: "seal_simulation_feishu_approval_definitions_list",
|
||||
description: "列出飞书模拟测试可用的审批定义,便于选择 approvalCode",
|
||||
+10
-10
@@ -1,9 +1,9 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { CliError } from "../../../core/errors.js";
|
||||
import { findSealTool, parseToolParams, type SealTool } from "./index.js";
|
||||
import { findSealCapability, parseCapabilityParams, type SealCapability } from "./index.js";
|
||||
|
||||
function tool(name: string): SealTool {
|
||||
const found = findSealTool(name);
|
||||
function tool(name: string): SealCapability {
|
||||
const found = findSealCapability(name);
|
||||
if (!found) throw new Error(`test fixture missing tool: ${name}`);
|
||||
return found;
|
||||
}
|
||||
@@ -11,7 +11,7 @@ function tool(name: string): SealTool {
|
||||
/** Asserts rejection and returns the message so tests can check its wording. */
|
||||
function rejectsWith(toolName: string, params: Record<string, unknown>): string {
|
||||
try {
|
||||
parseToolParams(tool(toolName), params);
|
||||
parseCapabilityParams(tool(toolName), params);
|
||||
} catch (error) {
|
||||
expect(error).toBeInstanceOf(CliError);
|
||||
expect((error as CliError).exitCode).toBe(13);
|
||||
@@ -20,14 +20,14 @@ function rejectsWith(toolName: string, params: Record<string, unknown>): string
|
||||
throw new Error(`expected ${toolName} to reject ${JSON.stringify(params)}`);
|
||||
}
|
||||
|
||||
describe("parseToolParams", () => {
|
||||
describe("parseCapabilityParams", () => {
|
||||
test("accepts valid params and returns the exact object it was given", () => {
|
||||
const target = tool("seal_user_create");
|
||||
const params = { name: "张三", phone: "13800001111", departmentIds: ["d1"] };
|
||||
|
||||
// Identity matters: handlers read keys the schema does not declare, so the
|
||||
// gate must pass its input through, never zod's (stripped) parse output.
|
||||
expect(parseToolParams(target, params)).toBe(params);
|
||||
expect(parseCapabilityParams(target, params)).toBe(params);
|
||||
});
|
||||
|
||||
test("names the missing required field instead of letting the handler crash on undefined", () => {
|
||||
@@ -49,7 +49,7 @@ describe("parseToolParams", () => {
|
||||
// /v1/* passes url.searchParams through: everything arrives as a string,
|
||||
// but the schema declares z.number() / z.boolean(). Without coercion every
|
||||
// REST route would 400 on its own documented query params.
|
||||
expect(parseToolParams(target, params)).toBe(params);
|
||||
expect(parseCapabilityParams(target, params)).toBe(params);
|
||||
expect(params.limit).toBe("50");
|
||||
expect(params.includeBridge).toBe("true");
|
||||
});
|
||||
@@ -63,7 +63,7 @@ describe("parseToolParams", () => {
|
||||
// `?fields=id,code` on /v1/approval/rules: today the handler receives a
|
||||
// string and pickRuleFields iterates its characters, returning empty
|
||||
// objects. Validation splits it so the documented form actually works.
|
||||
expect(parseToolParams(tool("seal_approval_rules_list"), { fields: "id,code" })).toEqual({
|
||||
expect(parseCapabilityParams(tool("seal_approval_rules_list"), { fields: "id,code" })).toEqual({
|
||||
fields: "id,code"
|
||||
});
|
||||
expect(rejectsWith("seal_approval_rules_list", { fields: "id,not-a-field" })).toContain("fields");
|
||||
@@ -73,7 +73,7 @@ describe("parseToolParams", () => {
|
||||
// z.object is non-strict: an extra HTTP body key is a compatibility
|
||||
// non-event, not an error. This gate checks declared params only.
|
||||
const target = tool("seal_approval_runs_search");
|
||||
expect(parseToolParams(target, { status: "TERMINATED", corp: "corp-a", stray: 1 })).toBeTypeOf("object");
|
||||
expect(parseCapabilityParams(target, { status: "TERMINATED", corp: "corp-a", stray: 1 })).toBeTypeOf("object");
|
||||
});
|
||||
|
||||
test("lets the legacy credential aliases through to the handler that supports them", () => {
|
||||
@@ -81,7 +81,7 @@ describe("parseToolParams", () => {
|
||||
// alongside apiKey/apiSecret; a schema that declared only apiKey as
|
||||
// required would have blocked that documented path.
|
||||
expect(() =>
|
||||
parseToolParams(tool("seal_deploy_hosecloud_configure"), {
|
||||
parseCapabilityParams(tool("seal_deploy_hosecloud_configure"), {
|
||||
appKey: "key-1",
|
||||
appSecurity: "secret-1",
|
||||
mode: "assisted"
|
||||
@@ -1,13 +1,13 @@
|
||||
import { z } from "zod";
|
||||
import { validationError } from "../../../core/errors.js";
|
||||
import type { SealTool } from "./index.js";
|
||||
import type { SealCapability } from "./index.js";
|
||||
|
||||
/**
|
||||
* Checks one invocation's params against the schema its tool declares, then
|
||||
* returns the params unchanged.
|
||||
*
|
||||
* Both dispatch paths — `runToolResult` (every CLI command) and
|
||||
* `executeSealTool` (`POST /api/tool/:name`, every `/v1/*` route) — used to
|
||||
* Both dispatch paths — `runCapabilityResult` (every CLI command) and
|
||||
* `executeSealCapability` (`POST /api/tool/:name`, every `/v1/*` route) — used to
|
||||
* hand `params` straight to `handler`, so a required field could be missing, a
|
||||
* limit could be `999999`, or a typo'd HTTP body key could sail through and
|
||||
* surface later as an opaque upstream error or a `Cannot read properties of
|
||||
@@ -29,7 +29,7 @@ import type { SealTool } from "./index.js";
|
||||
* declares (see {@link coerceWireTypes}) because `/v1/*` query strings arrive
|
||||
* entirely as strings while the schema says `z.number()`.
|
||||
*/
|
||||
export function parseToolParams(tool: SealTool, params: Record<string, unknown>): Record<string, unknown> {
|
||||
export function parseCapabilityParams(tool: SealCapability, params: Record<string, unknown>): Record<string, unknown> {
|
||||
const result = tool.parameters.safeParse(coerceWireTypes(tool.parameters, params));
|
||||
if (result.success) return params;
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
type WebhookMode
|
||||
} from "../types.js";
|
||||
import type {
|
||||
ToolContext
|
||||
CapabilityContext
|
||||
} from "./helpers.js";
|
||||
import * as helpers from "./helpers.js";
|
||||
|
||||
@@ -29,7 +29,7 @@ const {
|
||||
mutationPreview
|
||||
} = helpers;
|
||||
|
||||
export const webhookTools = [
|
||||
export const webhookCapabilities = [
|
||||
{
|
||||
name: "seal_webhook_list",
|
||||
description: "列出当前 Seal 租户的 Webhook 集成,可按 ID、名称或 URL 查找",
|
||||
@@ -40,7 +40,7 @@ export const webhookTools = [
|
||||
handler: async (
|
||||
client: KyInstance,
|
||||
params: { query?: string; includeSecret?: boolean },
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => {
|
||||
const integrations = api.filterWebhookIntegrations(
|
||||
await api.listWebhookIntegrations(
|
||||
@@ -65,7 +65,7 @@ export const webhookTools = [
|
||||
handler: async (
|
||||
client: KyInstance,
|
||||
params: { selector: string; includeSecret?: boolean },
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => {
|
||||
const integration = api.findWebhookIntegration(
|
||||
await api.listWebhookIntegrations(
|
||||
@@ -100,7 +100,7 @@ export const webhookTools = [
|
||||
materialPackFilePolicy?: Partial<z.infer<typeof MaterialPackFilePolicySchema>>;
|
||||
dryRun?: boolean;
|
||||
},
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => {
|
||||
const baseUrl = getConfiguredSealBaseUrl(context.corp);
|
||||
const preview = params.dryRun
|
||||
@@ -154,7 +154,7 @@ export const webhookTools = [
|
||||
materialPackFilePolicy?: Partial<z.infer<typeof MaterialPackFilePolicySchema>>;
|
||||
dryRun?: boolean;
|
||||
},
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => {
|
||||
if (params.secret !== undefined && params.rotateSecret) {
|
||||
throw new Error("Webhook secret and rotateSecret cannot be used together");
|
||||
@@ -197,7 +197,7 @@ export const webhookTools = [
|
||||
handler: async (
|
||||
client: KyInstance,
|
||||
params: { selector: string; confirm?: boolean; dryRun?: boolean },
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => {
|
||||
if (!params.confirm && !params.dryRun) {
|
||||
throw new Error("Refusing to delete Webhook integration without confirm=true");
|
||||
@@ -256,7 +256,7 @@ export const webhookTools = [
|
||||
dryRun?: boolean;
|
||||
force?: boolean;
|
||||
},
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => {
|
||||
const selectCorpFn = (id?: string) => {
|
||||
const corps = loadCorpConfigs();
|
||||
@@ -312,7 +312,7 @@ export const webhookTools = [
|
||||
handler: async (
|
||||
client: KyInstance,
|
||||
params: { filePath?: string },
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => {
|
||||
return checkWebhookReadiness(client, context.corp, { filePath: params.filePath });
|
||||
}
|
||||
@@ -328,7 +328,7 @@ export const webhookTools = [
|
||||
handler: async (
|
||||
client: KyInstance,
|
||||
params: { filePath: string; mode?: "preview" | "push"; webhook?: string },
|
||||
context: ToolContext
|
||||
context: CapabilityContext
|
||||
) => {
|
||||
const input = readMaterialPackFile(params.filePath);
|
||||
if (params.mode !== "push") return previewMaterialPack(input.fileBuffer, input.fileName);
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
saveLocalRulesFile,
|
||||
localRulesToLintTargets
|
||||
} from "./rules-local.js";
|
||||
import { findSealTool } from "./tools.js";
|
||||
import { findSealCapability } from "./capabilities.js";
|
||||
|
||||
const tempDirs: string[] = [];
|
||||
|
||||
@@ -109,10 +109,10 @@ describe("rules-local offline lint tool integration", () => {
|
||||
]
|
||||
});
|
||||
|
||||
const lintTool = findSealTool("seal_approval_rules_lint")!;
|
||||
expect(lintTool).toBeDefined();
|
||||
const lintCapability = findSealCapability("seal_approval_rules_lint")!;
|
||||
expect(lintCapability).toBeDefined();
|
||||
|
||||
const result = await lintTool.handler(
|
||||
const result = await lintCapability.handler(
|
||||
null as any,
|
||||
{ file: filePath } as any,
|
||||
{ corp: { id: "test-corp" } } as any
|
||||
@@ -139,9 +139,9 @@ describe("rules-local offline lint tool integration", () => {
|
||||
]
|
||||
});
|
||||
|
||||
const lintTool = findSealTool("seal_approval_rules_lint")!;
|
||||
const lintCapability = findSealCapability("seal_approval_rules_lint")!;
|
||||
|
||||
const result = await lintTool.handler(
|
||||
const result = await lintCapability.handler(
|
||||
null as any,
|
||||
{ file: filePath } as any,
|
||||
{ corp: { id: "test-corp" } } as any
|
||||
@@ -153,7 +153,7 @@ describe("rules-local offline lint tool integration", () => {
|
||||
|
||||
// minScore enforcement
|
||||
await expect(
|
||||
lintTool.handler(
|
||||
lintCapability.handler(
|
||||
null as any,
|
||||
{ file: filePath, minScore: 95 } as any,
|
||||
{ corp: { id: "test-corp" } } as any
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
listSimulationTemplates,
|
||||
uploadMaterialPackage
|
||||
} from "./api.js";
|
||||
import { buildSimulationBatchParams, findReusableSimulationBatch, sealTools } from "./tools.js";
|
||||
import { buildSimulationBatchParams, findReusableSimulationBatch, sealCapabilities } from "./capabilities.js";
|
||||
import {
|
||||
MaterialPackageSchema,
|
||||
SimulationBatch,
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
SimulationTemplateSchema
|
||||
} from "./types.js";
|
||||
|
||||
type ToolHandler = (
|
||||
type CapabilityHandler = (
|
||||
client: KyInstance,
|
||||
params: Record<string, unknown>,
|
||||
context: { corp: CorpConfig }
|
||||
@@ -529,7 +529,7 @@ describe("findReusableSimulationBatch", () => {
|
||||
|
||||
describe("simulation tool handlers", () => {
|
||||
test("create tool resolves signKey automatically and posts the payload", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_simulation_batch_create");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_simulation_batch_create");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
let postedBody: Record<string, unknown> | undefined;
|
||||
@@ -555,7 +555,7 @@ describe("simulation tool handlers", () => {
|
||||
}
|
||||
} as unknown as KyInstance;
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(client, {
|
||||
mode: "hosecloud",
|
||||
flowIds: ["B26017701"],
|
||||
@@ -579,7 +579,7 @@ describe("simulation tool handlers", () => {
|
||||
});
|
||||
|
||||
test("create tool reuses a recent identical batch instead of creating a new one", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_simulation_batch_create");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_simulation_batch_create");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
let postCalls = 0;
|
||||
@@ -608,7 +608,7 @@ describe("simulation tool handlers", () => {
|
||||
}
|
||||
} as unknown as KyInstance;
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(client, {
|
||||
mode: "hosecloud",
|
||||
flowIds: ["B26017701"]
|
||||
@@ -625,7 +625,7 @@ describe("simulation tool handlers", () => {
|
||||
});
|
||||
|
||||
test("create tool force bypasses the reuse check", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_simulation_batch_create");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_simulation_batch_create");
|
||||
let posted = false;
|
||||
const client = {
|
||||
get: (url: string) => {
|
||||
@@ -652,7 +652,7 @@ describe("simulation tool handlers", () => {
|
||||
}
|
||||
} as unknown as KyInstance;
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(client, {
|
||||
mode: "hosecloud",
|
||||
flowIds: ["B26017701"],
|
||||
@@ -665,7 +665,7 @@ describe("simulation tool handlers", () => {
|
||||
});
|
||||
|
||||
test("create tool creates a new batch when the identical batch is outside the reuse window", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_simulation_batch_create");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_simulation_batch_create");
|
||||
let posted = false;
|
||||
const client = {
|
||||
get: (url: string) => {
|
||||
@@ -692,7 +692,7 @@ describe("simulation tool handlers", () => {
|
||||
}
|
||||
} as unknown as KyInstance;
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(client, {
|
||||
mode: "hosecloud",
|
||||
flowIds: ["B26017701"]
|
||||
@@ -703,7 +703,7 @@ describe("simulation tool handlers", () => {
|
||||
});
|
||||
|
||||
test("create tool surface exposes mode, flowIds, and rawParams", () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_simulation_batch_create");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_simulation_batch_create");
|
||||
const { z } = require("zod") as typeof import("zod");
|
||||
const schema = z.toJSONSchema(tool!.parameters) as { properties?: Record<string, unknown> };
|
||||
expect(Object.keys(schema.properties ?? {})).toEqual(
|
||||
@@ -712,17 +712,17 @@ describe("simulation tool handlers", () => {
|
||||
});
|
||||
|
||||
test("includes the simulation management tool set", () => {
|
||||
expect(sealTools.find((item) => item.name === "seal_simulation_batches_list")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_simulation_batch_get")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_simulation_batch_status")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_simulation_templates_get")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_simulation_integrations_get")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_simulation_batch_records_get")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_simulation_material_package_upload")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_simulation_batches_list")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_simulation_batch_get")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_simulation_batch_status")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_simulation_templates_get")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_simulation_integrations_get")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_simulation_batch_records_get")).toBeDefined();
|
||||
expect(sealCapabilities.find((item) => item.name === "seal_simulation_material_package_upload")).toBeDefined();
|
||||
});
|
||||
|
||||
test("status tool performs one non-blocking check and exposes the next action", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_simulation_batch_status");
|
||||
const tool = sealCapabilities.find((item) => item.name === "seal_simulation_batch_status");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const client = {
|
||||
@@ -732,7 +732,7 @@ describe("simulation tool handlers", () => {
|
||||
}
|
||||
} as unknown as KyInstance;
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const handler = tool!.handler as CapabilityHandler;
|
||||
const result = await handler(client, { batchId: "batch-1" }, fakeContext()) as Record<string, unknown>;
|
||||
|
||||
expect(result).toMatchObject({
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
// Re-export from modular tools/ directory.
|
||||
// tools.ts was split into domain-specific modules under src/domains/seal/tools/.
|
||||
export * from "./tools/index.js";
|
||||
Reference in new issue
Block a user