Release v0.10.9: Purge legacy MCP code, decouple CLI commands, and clean unused exports
This commit is contained in:
1 parent
d525087b97
commit
edafe033dc
20 files changed
+256
-594
No files matched your search
@@ -1,5 +1,10 @@
|
||||
import type { CorpConfig } from "../../core/config/types.js";
|
||||
import type { createSealClient } from "../../core/http/factory.js";
|
||||
import * as api from "../../domains/seal/api.js";
|
||||
import {
|
||||
downloadApprovalRunAttachments,
|
||||
extractApprovalRunAttachments
|
||||
} from "../../domains/seal/attachments.js";
|
||||
import { runTool, runToolResult } from "../helpers.js";
|
||||
import { booleanOption, numberOption, stringOption } from "../parser.js";
|
||||
import { outputOptions, printJson } from "../printer.js";
|
||||
@@ -176,23 +181,19 @@ export async function handleApprovalRunsCommand(
|
||||
"Usage: seal-use approval-runs attachments download <recordId> [--all] [--name <name>] [--out-dir <dir>]"
|
||||
);
|
||||
}
|
||||
const downloadResult = (await runToolResult(
|
||||
"seal_approval_run_attachments_download",
|
||||
client,
|
||||
corp,
|
||||
{
|
||||
recordId,
|
||||
all: booleanOption(args.options.all),
|
||||
name: stringOption(args.options.name),
|
||||
outDir:
|
||||
stringOption(args.options["out-dir"]) ??
|
||||
stringOption(args.options.outDir) ??
|
||||
stringOption(args.options.dir)
|
||||
}
|
||||
)) as any;
|
||||
const record = await api.getApprovalRun(client, recordId);
|
||||
const downloadResult = await downloadApprovalRunAttachments({
|
||||
record,
|
||||
all: booleanOption(args.options.all),
|
||||
name: stringOption(args.options.name),
|
||||
outDir:
|
||||
stringOption(args.options["out-dir"]) ??
|
||||
stringOption(args.options.outDir) ??
|
||||
stringOption(args.options.dir)
|
||||
});
|
||||
|
||||
printJson(downloadResult, outputOptions(args.options));
|
||||
if (downloadResult?.total > 0 && downloadResult?.downloaded === 0) {
|
||||
if (downloadResult.total > 0 && downloadResult.downloaded === 0) {
|
||||
throw new Error(`所有 ${downloadResult.total} 个附件下载均失败。`);
|
||||
}
|
||||
return;
|
||||
@@ -202,38 +203,29 @@ export async function handleApprovalRunsCommand(
|
||||
if (!recordId) throw new Error("Usage: seal-use approval-runs attachments <recordId> | seal-use approval-runs attachments download <recordId>");
|
||||
|
||||
if (booleanOption(args.options.download)) {
|
||||
const downloadResult = (await runToolResult(
|
||||
"seal_approval_run_attachments_download",
|
||||
client,
|
||||
corp,
|
||||
{
|
||||
recordId,
|
||||
all: booleanOption(args.options.all) ?? true,
|
||||
name: stringOption(args.options.name),
|
||||
outDir:
|
||||
stringOption(args.options["out-dir"]) ??
|
||||
stringOption(args.options.outDir) ??
|
||||
stringOption(args.options.dir)
|
||||
}
|
||||
)) as any;
|
||||
const record = await api.getApprovalRun(client, recordId);
|
||||
const downloadResult = await downloadApprovalRunAttachments({
|
||||
record,
|
||||
all: booleanOption(args.options.all) ?? true,
|
||||
name: stringOption(args.options.name),
|
||||
outDir:
|
||||
stringOption(args.options["out-dir"]) ??
|
||||
stringOption(args.options.outDir) ??
|
||||
stringOption(args.options.dir)
|
||||
});
|
||||
|
||||
printJson(downloadResult, outputOptions(args.options));
|
||||
if (downloadResult?.total > 0 && downloadResult?.downloaded === 0) {
|
||||
if (downloadResult.total > 0 && downloadResult.downloaded === 0) {
|
||||
throw new Error(`所有 ${downloadResult.total} 个附件下载均失败。`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
await runTool(
|
||||
"seal_approval_run_attachments_get",
|
||||
client,
|
||||
corp,
|
||||
{
|
||||
recordId,
|
||||
summary: booleanOption(args.options.summary)
|
||||
},
|
||||
outputOptions(args.options)
|
||||
);
|
||||
const record = await api.getApprovalRun(client, recordId);
|
||||
const result = extractApprovalRunAttachments(record, {
|
||||
summary: booleanOption(args.options.summary)
|
||||
});
|
||||
printJson(result, outputOptions(args.options));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -244,23 +236,19 @@ export async function handleApprovalRunsCommand(
|
||||
"Usage: seal-use approval-runs download <recordId> [--all] [--name <name>] [--out-dir <dir>]"
|
||||
);
|
||||
}
|
||||
const downloadResult = (await runToolResult(
|
||||
"seal_approval_run_attachments_download",
|
||||
client,
|
||||
corp,
|
||||
{
|
||||
recordId,
|
||||
all: booleanOption(args.options.all),
|
||||
name: stringOption(args.options.name),
|
||||
outDir:
|
||||
stringOption(args.options["out-dir"]) ??
|
||||
stringOption(args.options.outDir) ??
|
||||
stringOption(args.options.dir)
|
||||
}
|
||||
)) as any;
|
||||
const record = await api.getApprovalRun(client, recordId);
|
||||
const downloadResult = await downloadApprovalRunAttachments({
|
||||
record,
|
||||
all: booleanOption(args.options.all),
|
||||
name: stringOption(args.options.name),
|
||||
outDir:
|
||||
stringOption(args.options["out-dir"]) ??
|
||||
stringOption(args.options.outDir) ??
|
||||
stringOption(args.options.dir)
|
||||
});
|
||||
|
||||
printJson(downloadResult, outputOptions(args.options));
|
||||
if (downloadResult?.total > 0 && downloadResult?.downloaded === 0) {
|
||||
if (downloadResult.total > 0 && downloadResult.downloaded === 0) {
|
||||
throw new Error(`所有 ${downloadResult.total} 个附件下载均失败。`);
|
||||
}
|
||||
return;
|
||||
|
||||
@@ -22,7 +22,7 @@ export async function handleAuthCommand(action: string | undefined, corp: CorpCo
|
||||
throw new Error(`Unknown auth command: ${action ?? ""}. Run 'seal-use help' for available commands.`);
|
||||
}
|
||||
|
||||
export async function diagnoseAuth(corp: CorpConfig) {
|
||||
async function diagnoseAuth(corp: CorpConfig) {
|
||||
if (corp.source.type !== "hose") {
|
||||
const client = await createSealClient(corp);
|
||||
const me = await getMe(client);
|
||||
|
||||
+4
-4
@@ -2,10 +2,10 @@ import { writeFileSync } from "node:fs";
|
||||
import { booleanOption, stringOption } from "./parser.js";
|
||||
import type { OutputOptions } from "./types.js";
|
||||
|
||||
export const RULE_LIST_FULL_COUNT_LIMIT = 100;
|
||||
export const RULE_LIST_FULL_BYTES_LIMIT = 120_000;
|
||||
const RULE_LIST_FULL_COUNT_LIMIT = 100;
|
||||
const RULE_LIST_FULL_BYTES_LIMIT = 120_000;
|
||||
export const RULE_SUMMARY_FIELDS = ["id", "code", "status", "strictness", "scope", "createdAt", "updatedAt"];
|
||||
export const DEFAULT_OUTPUT_BYTES_LIMIT = 200_000;
|
||||
const DEFAULT_OUTPUT_BYTES_LIMIT = 200_000;
|
||||
|
||||
export function formatConsoleOutput(values: unknown[]): string {
|
||||
return values.map((value) => (typeof value === "string" ? value : String(value))).join(" ");
|
||||
@@ -33,7 +33,7 @@ export function printJson(value: unknown, options: OutputOptions = {}) {
|
||||
console.log(json.trimEnd());
|
||||
}
|
||||
|
||||
export function protectLargeOutput(result: unknown, options: OutputOptions = {}) {
|
||||
function protectLargeOutput(result: unknown, options: OutputOptions = {}) {
|
||||
if (options.allowFull || options.outputFile) return;
|
||||
const bodyBytes = Buffer.byteLength(JSON.stringify(result), "utf-8");
|
||||
if (bodyBytes > DEFAULT_OUTPUT_BYTES_LIMIT) {
|
||||
|
||||
@@ -39,10 +39,6 @@ export async function getSealSessionForCorp(corp: CorpConfig): Promise<SealSessi
|
||||
return next;
|
||||
}
|
||||
|
||||
export async function getSealToken(corp: CorpConfig): Promise<string> {
|
||||
return (await getSealSessionForCorp(corp)).token;
|
||||
}
|
||||
|
||||
export async function resolveSealEnterpriseConfig(
|
||||
corp: CorpConfig
|
||||
): Promise<SealEnterpriseConfig> {
|
||||
|
||||
@@ -13,7 +13,6 @@ const LEGACY_GLOBAL_CONFIG_ENV = "SEAL_HOME_CONFIG_FILE";
|
||||
|
||||
export const PRIMARY_USER_ENTERPRISES_DIR = join(homedir(), ".config", "seal-use", "enterprises");
|
||||
export const LEGACY_USER_ENTERPRISES_DIR = join(homedir(), ".config", "seal-home", "enterprises");
|
||||
export const USER_ENTERPRISES_DIR = PRIMARY_USER_ENTERPRISES_DIR;
|
||||
|
||||
const PRIMARY_GLOBAL_CONFIG_FILE = join(homedir(), ".config", "seal-use", "config.json");
|
||||
const LEGACY_GLOBAL_CONFIG_FILE = join(homedir(), ".config", "seal-home", "config.json");
|
||||
@@ -39,7 +38,7 @@ export function resolveEnterprisesDir(): string | undefined {
|
||||
return resolveEnterprisesDirs()[0];
|
||||
}
|
||||
|
||||
export function resolveEnterprisesDirs(): string[] {
|
||||
function resolveEnterprisesDirs(): string[] {
|
||||
const configured = (process.env[CONFIG_ENV] ?? process.env[LEGACY_CONFIG_ENV])?.trim();
|
||||
if (configured) return existsSync(configured) ? [configured] : [];
|
||||
|
||||
@@ -58,15 +57,6 @@ export function resolveEnterprisesDirs(): string[] {
|
||||
return uniqueExisting;
|
||||
}
|
||||
|
||||
export function resolvePrimaryEnterprisesDir(): string | undefined {
|
||||
const configured = (process.env[CONFIG_ENV] ?? process.env[LEGACY_CONFIG_ENV])?.trim();
|
||||
if (configured) return existsSync(configured) ? configured : undefined;
|
||||
if (existsSync(ENTERPRISES_DIR)) return ENTERPRISES_DIR;
|
||||
if (existsSync(PRIMARY_USER_ENTERPRISES_DIR)) return PRIMARY_USER_ENTERPRISES_DIR;
|
||||
if (existsSync(LEGACY_USER_ENTERPRISES_DIR)) return LEGACY_USER_ENTERPRISES_DIR;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function resolveWritableEnterprisesDir(): string {
|
||||
const configured = (process.env[CONFIG_ENV] ?? process.env[LEGACY_CONFIG_ENV])?.trim();
|
||||
if (configured) return configured;
|
||||
|
||||
@@ -36,11 +36,11 @@ export function getDefaultGlobalSkillDir(): string {
|
||||
return join(homedir(), ".agents", "skills", "seal-use");
|
||||
}
|
||||
|
||||
export function getLegacyGlobalSkillDir(): string {
|
||||
function getLegacyGlobalSkillDir(): string {
|
||||
return join(homedir(), ".agents", "skills", "seal-home");
|
||||
}
|
||||
|
||||
export function cleanLegacySkillDir(): boolean {
|
||||
function cleanLegacySkillDir(): boolean {
|
||||
const legacyDir = getLegacyGlobalSkillDir();
|
||||
if (existsSync(legacyDir)) {
|
||||
try {
|
||||
|
||||
@@ -46,7 +46,7 @@ export function listAvailableLinters(): Array<{ name: string; type: "builtin" |
|
||||
return list;
|
||||
}
|
||||
|
||||
export function resolveLinterPath(nameOrPath: string): string | undefined {
|
||||
function resolveLinterPath(nameOrPath: string): string | undefined {
|
||||
if (!nameOrPath || nameOrPath === "builtin") {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ function decodeZipEntryName(entry: any): string {
|
||||
return utf8;
|
||||
}
|
||||
|
||||
export function isJunk(name: string): boolean {
|
||||
function isJunk(name: string): boolean {
|
||||
const base = name.split("/").pop() ?? "";
|
||||
return name.split("/").includes("__MACOSX") || base === ".DS_Store" || base.startsWith("._") || base.startsWith(".~") || base.startsWith("~$");
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { CorpConfig } from "../../core/config/types.js";
|
||||
import { findSealMcpTool, findSealTool, sealMcpTools, sealTools } from "./tools.js";
|
||||
import { findSealTool, sealTools } from "./tools.js";
|
||||
|
||||
type ToolHandler = (
|
||||
client: KyInstance,
|
||||
@@ -230,51 +230,9 @@ describe("sealTools", () => {
|
||||
expect(sealTools.find((item) => item.name === "seal_approval_run_langfuse_bridge_get")).toBeDefined();
|
||||
});
|
||||
|
||||
test("keeps the MCP exposed tool surface narrow", () => {
|
||||
expect(sealMcpTools.map((tool) => tool.name)).toEqual([
|
||||
"seal_whoami",
|
||||
"seal_approval_search",
|
||||
"seal_approval_context_get",
|
||||
"seal_webhook_material_pack",
|
||||
"seal_runs_search",
|
||||
"seal_action"
|
||||
]);
|
||||
});
|
||||
|
||||
test("routes low-frequency management tools through seal_action", async () => {
|
||||
const tool = sealMcpTools.find((item) => item.name === "seal_action");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const result = await handler(
|
||||
fakeApprovalRunsClient(),
|
||||
{ action: "runs.summary", payload: { date: "2026-06-08", timezone: "Asia/Shanghai" } },
|
||||
fakeContext()
|
||||
) as { matched: number };
|
||||
|
||||
expect(result.matched).toBe(2);
|
||||
});
|
||||
|
||||
test("routes lightweight approval run actions through seal_action", async () => {
|
||||
const tool = sealMcpTools.find((item) => item.name === "seal_action");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const result = await handler(
|
||||
fakeApprovalRunsClient(),
|
||||
{ action: "runs.citedRules", payload: { recordId: "run-1" } },
|
||||
fakeContext()
|
||||
) as { count: number };
|
||||
|
||||
expect(result.count).toBe(1);
|
||||
});
|
||||
|
||||
test("keeps old fine-grained tools available to compatibility callers but hidden from MCP list", () => {
|
||||
expect(sealMcpTools.find((item) => item.name === "seal_approval_rule_create")).toBeUndefined();
|
||||
expect(findSealMcpTool("seal_approval_rule_create")).toBeUndefined();
|
||||
test("can find tools by name in sealTools", () => {
|
||||
expect(findSealTool("seal_approval_rule_create")).toBeDefined();
|
||||
expect(findSealMcpTool("seal_action")).toBeDefined();
|
||||
expect(findSealMcpTool("seal_runs_search")?.name).toBe("seal_runs_search");
|
||||
expect(findSealTool("non_existent_tool")).toBeUndefined();
|
||||
});
|
||||
|
||||
test("approval run search omits bridge unless requested", async () => {
|
||||
|
||||
+4
-242
@@ -17,10 +17,7 @@ import {
|
||||
} from "./rules-local.js";
|
||||
import { previewMaterialPack, pushMaterialPack, readMaterialPackFile } from "./material-pack/index.js";
|
||||
import {
|
||||
extractApprovalRunAttachments,
|
||||
downloadApprovalRunAttachments,
|
||||
type ApprovalRunAttachment,
|
||||
type DownloadAttachmentsResult
|
||||
extractApprovalRunAttachments
|
||||
} from "./attachments.js";
|
||||
import {
|
||||
ThinkingPolicySchema,
|
||||
@@ -1233,28 +1230,6 @@ export const sealTools = [
|
||||
return extractApprovalRunAttachments(record, { summary: params.summary });
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "seal_approval_run_attachments_download",
|
||||
description: "下载审批运行记录中的附件到本地目录;优先使用记录内 ossSignedUrl 直链",
|
||||
parameters: z.object({
|
||||
recordId: z.string().describe("Seal approval run record ID"),
|
||||
all: z.boolean().optional().describe("下载所有附件"),
|
||||
name: z.string().optional().describe("按文件名、fileId 或 tokenKey 过滤"),
|
||||
outDir: z.string().optional().describe("本地保存目录,默认 ./attachments")
|
||||
}),
|
||||
handler: async (
|
||||
client: KyInstance,
|
||||
params: { recordId: string; all?: boolean; name?: string; outDir?: string }
|
||||
) => {
|
||||
const record = await api.getApprovalRun(client, params.recordId);
|
||||
return downloadApprovalRunAttachments({
|
||||
record,
|
||||
all: params.all,
|
||||
name: params.name,
|
||||
outDir: params.outDir
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "seal_approval_run_result_get",
|
||||
description: "返回审批运行结果摘要;summary=true 时只返回 decision、summary、风险点数量、命中规则数量、traceId 等",
|
||||
@@ -2057,221 +2032,10 @@ const sealToolByName = new Map<string, SealTool>(
|
||||
sealTools.map((tool) => [tool.name, tool])
|
||||
);
|
||||
|
||||
const mcpDirectToolNames = [
|
||||
"seal_whoami",
|
||||
"seal_approval_search",
|
||||
"seal_approval_context_get",
|
||||
"seal_webhook_material_pack"
|
||||
] as const;
|
||||
|
||||
const sealActionNames = [
|
||||
"seal_session_get",
|
||||
"seal_approval_rules_list",
|
||||
"seal_approval_rules_clear",
|
||||
"seal_approval_rule_create",
|
||||
"seal_approval_rule_update",
|
||||
"seal_approval_rule_delete",
|
||||
"seal_approval_rule_versions_list",
|
||||
"seal_approval_rule_version_get",
|
||||
"seal_approval_rule_get",
|
||||
"seal_approval_rules_lint",
|
||||
"seal_approval_rules_pull",
|
||||
"seal_approval_rules_push",
|
||||
"seal_approval_rule_version_publish",
|
||||
"seal_approval_documents_list",
|
||||
"seal_approval_document_get",
|
||||
"seal_approval_document_create",
|
||||
"seal_approval_document_update",
|
||||
"seal_approval_style_preferences_get",
|
||||
"seal_approval_style_preferences_update",
|
||||
"seal_webhook_list",
|
||||
"seal_webhook_get",
|
||||
"seal_webhook_add",
|
||||
"seal_webhook_update",
|
||||
"seal_webhook_delete",
|
||||
"seal_approval_runs_summary",
|
||||
"seal_approval_runs_stats",
|
||||
"seal_approval_runs_count",
|
||||
"seal_approval_run_get",
|
||||
"seal_approval_run_cited_rules_get",
|
||||
"seal_approval_run_document_summary_get",
|
||||
"seal_approval_run_attachments_get",
|
||||
"seal_approval_run_attachments_download",
|
||||
"seal_approval_run_result_get",
|
||||
"seal_approval_run_url_get",
|
||||
"seal_approval_run_pick",
|
||||
"seal_simulation_batch_records_get",
|
||||
"seal_simulation_batch_create",
|
||||
"seal_simulation_batch_wait",
|
||||
"seal_simulation_batch_clean",
|
||||
"seal_simulation_batches_list",
|
||||
"seal_simulation_batch_get",
|
||||
"seal_simulation_templates_get",
|
||||
"seal_simulation_integrations_get",
|
||||
"seal_simulation_specifications_list",
|
||||
"seal_simulation_material_package_upload",
|
||||
"seal_deploy_hosecloud_requirements",
|
||||
"seal_deploy_hosecloud_list",
|
||||
"seal_deploy_hosecloud_get",
|
||||
"seal_deploy_hosecloud_status",
|
||||
"seal_deploy_hosecloud_configure",
|
||||
"seal_deploy_hosecloud_sync",
|
||||
"seal_preference_get",
|
||||
"seal_preference_decision_update",
|
||||
"seal_preference_thinking_depth_set",
|
||||
"seal_preference_thinking_depth_policies_list",
|
||||
"seal_preference_thinking_depth_policies_upsert",
|
||||
"seal_preference_thinking_depth_policies_remove",
|
||||
"seal_approval_run_langfuse_bridge_get"
|
||||
] as const;
|
||||
|
||||
const sealActionAliases: Record<string, (typeof sealActionNames)[number]> = {
|
||||
"session.get": "seal_session_get",
|
||||
"rule.list": "seal_approval_rules_list",
|
||||
"rule.clear": "seal_approval_rules_clear",
|
||||
"rule.create": "seal_approval_rule_create",
|
||||
"rule.update": "seal_approval_rule_update",
|
||||
"rule.delete": "seal_approval_rule_delete",
|
||||
"rule.versions.list": "seal_approval_rule_versions_list",
|
||||
"rule.version.get": "seal_approval_rule_version_get",
|
||||
"rule.get": "seal_approval_rule_get",
|
||||
"rule.lint": "seal_approval_rules_lint",
|
||||
"rule.pull": "seal_approval_rules_pull",
|
||||
"rule.push": "seal_approval_rules_push",
|
||||
"rule.publish": "seal_approval_rule_version_publish",
|
||||
"doc.list": "seal_approval_documents_list",
|
||||
"doc.get": "seal_approval_document_get",
|
||||
"doc.create": "seal_approval_document_create",
|
||||
"doc.update": "seal_approval_document_update",
|
||||
"style.get": "seal_approval_style_preferences_get",
|
||||
"style.update": "seal_approval_style_preferences_update",
|
||||
"webhook.list": "seal_webhook_list",
|
||||
"webhook.get": "seal_webhook_get",
|
||||
"webhook.add": "seal_webhook_add",
|
||||
"webhook.update": "seal_webhook_update",
|
||||
"webhook.delete": "seal_webhook_delete",
|
||||
"runs.summary": "seal_approval_runs_summary",
|
||||
"runs.stats": "seal_approval_runs_stats",
|
||||
"runs.count": "seal_approval_runs_count",
|
||||
"runs.get": "seal_approval_run_get",
|
||||
"runs.citedRules": "seal_approval_run_cited_rules_get",
|
||||
"runs.documentSummary": "seal_approval_run_document_summary_get",
|
||||
"runs.attachments": "seal_approval_run_attachments_get",
|
||||
"runs.attachments.download": "seal_approval_run_attachments_download",
|
||||
"runs.result": "seal_approval_run_result_get",
|
||||
"runs.url": "seal_approval_run_url_get",
|
||||
"runs.pick": "seal_approval_run_pick",
|
||||
"batch.records.get": "seal_simulation_batch_records_get",
|
||||
"batch.create": "seal_simulation_batch_create",
|
||||
"batch.wait": "seal_simulation_batch_wait",
|
||||
"batch.clean": "seal_simulation_batch_clean",
|
||||
"batch.list": "seal_simulation_batches_list",
|
||||
"batch.get": "seal_simulation_batch_get",
|
||||
"batch.templates.list": "seal_simulation_templates_get",
|
||||
"batch.integrations.get": "seal_simulation_integrations_get",
|
||||
"batch.specifications.list": "seal_simulation_specifications_list",
|
||||
"batch.materialPackageUpload": "seal_simulation_material_package_upload",
|
||||
"deploy.hosecloud.requirements": "seal_deploy_hosecloud_requirements",
|
||||
"deploy.hosecloud.list": "seal_deploy_hosecloud_list",
|
||||
"deploy.hosecloud.get": "seal_deploy_hosecloud_get",
|
||||
"deploy.hosecloud.status": "seal_deploy_hosecloud_status",
|
||||
"deploy.hosecloud.configure": "seal_deploy_hosecloud_configure",
|
||||
"deploy.hosecloud.sync": "seal_deploy_hosecloud_sync",
|
||||
"preference.get": "seal_preference_get",
|
||||
"preference.decision.update": "seal_preference_decision_update",
|
||||
"preference.thinkingDepth.set": "seal_preference_thinking_depth_set",
|
||||
"preference.thinkingDepth.policies.list": "seal_preference_thinking_depth_policies_list",
|
||||
"preference.thinkingDepth.policies.upsert": "seal_preference_thinking_depth_policies_upsert",
|
||||
"preference.thinkingDepth.policies.remove": "seal_preference_thinking_depth_policies_remove",
|
||||
"langfuse.bridge.get": "seal_approval_run_langfuse_bridge_get"
|
||||
};
|
||||
|
||||
export const sealMcpTools: SealToolDefinition[] = [
|
||||
...mcpDirectToolNames.map((name) => requiredTool(name)),
|
||||
{
|
||||
...requiredTool("seal_approval_runs_search"),
|
||||
name: "seal_runs_search",
|
||||
description: "查询 Seal 审批/审核运行记录,返回精简记录并按需提供 Langfuse trace/session 关联"
|
||||
},
|
||||
{
|
||||
name: "seal_action",
|
||||
description: "Seal 低频管理操作统一入口。传 action=help 查看可用动作;支持 rule/doc/style/webhook/runs/batch/langfuse 等管理与诊断操作。",
|
||||
parameters: z.object({
|
||||
action: z.string().describe("动作名,如 help、rule.create、doc.update、webhook.list、runs.summary、langfuse.bridge.get;也兼容旧 tool 名"),
|
||||
payload: z.record(z.string(), z.unknown()).optional().describe("动作参数对象")
|
||||
}),
|
||||
handler: async (
|
||||
client: KyInstance,
|
||||
params: { action: string; payload?: Record<string, unknown> },
|
||||
context: ToolContext
|
||||
) => runSealAction(client, params, context)
|
||||
}
|
||||
];
|
||||
|
||||
export function findSealTool(name: string, options: { includeMcpAliases?: boolean } = {}) {
|
||||
if (options.includeMcpAliases && name === "seal_runs_search") {
|
||||
return requiredTool("seal_approval_runs_search");
|
||||
}
|
||||
export function findSealTool(name: string): SealTool | undefined {
|
||||
return sealToolByName.get(name);
|
||||
}
|
||||
|
||||
export function findSealMcpTool(name: string) {
|
||||
return sealMcpTools.find((tool) => tool.name === name);
|
||||
}
|
||||
|
||||
async function runSealAction(
|
||||
client: KyInstance,
|
||||
params: { action: string; payload?: Record<string, unknown> },
|
||||
context: ToolContext
|
||||
) {
|
||||
const action = params.action?.trim();
|
||||
if (!action || action === "help") {
|
||||
return sealActionHelp(params.payload?.topic);
|
||||
}
|
||||
|
||||
const toolName = sealActionAliases[action] ?? action;
|
||||
if (!isSealActionToolName(toolName)) {
|
||||
return {
|
||||
error: `Unsupported seal_action action: ${action}`,
|
||||
help: sealActionHelp(params.payload?.topic)
|
||||
};
|
||||
}
|
||||
|
||||
const tool = requiredTool(toolName);
|
||||
const payload = params.payload ?? {};
|
||||
return tool.handler(client, payload as never, context);
|
||||
}
|
||||
|
||||
function sealActionHelp(topic: unknown) {
|
||||
const normalizedTopic = typeof topic === "string" ? topic.trim() : undefined;
|
||||
const actions = Object.entries(sealActionAliases)
|
||||
.filter(([action]) => !normalizedTopic || action.startsWith(`${normalizedTopic}.`))
|
||||
.map(([action, toolName]) => {
|
||||
const tool = requiredTool(toolName);
|
||||
return {
|
||||
action,
|
||||
toolName,
|
||||
description: tool.description
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
usage: "seal_action({ action, payload })",
|
||||
topics: ["session", "rule", "doc", "style", "webhook", "runs", "batch", "langfuse"],
|
||||
actions
|
||||
};
|
||||
}
|
||||
|
||||
function requiredTool(name: string): SealTool {
|
||||
const tool = sealToolByName.get(name);
|
||||
if (!tool) throw new Error(`Missing Seal tool: ${name}`);
|
||||
return tool;
|
||||
}
|
||||
|
||||
function isSealActionToolName(name: string): name is (typeof sealActionNames)[number] {
|
||||
return sealActionNames.includes(name as (typeof sealActionNames)[number]);
|
||||
}
|
||||
|
||||
function presentWebhookIntegration(
|
||||
integration: WebhookIntegration,
|
||||
includeSecret: boolean
|
||||
@@ -2392,7 +2156,7 @@ export type SimulationBatchCreateInput = {
|
||||
rawParams?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export function parseDurationMs(duration: string): number {
|
||||
function parseDurationMs(duration: string): number {
|
||||
const match = duration.match(/^(\d+(?:\.\d+)?)\s*(ms|s|m|h|d)?$/i);
|
||||
if (!match || !match[1]) return 600000;
|
||||
const val = parseFloat(match[1]);
|
||||
@@ -2407,7 +2171,7 @@ export function parseDurationMs(duration: string): number {
|
||||
}
|
||||
}
|
||||
|
||||
export function redactIntegrationSecrets(integration: Record<string, unknown>) {
|
||||
function redactIntegrationSecrets(integration: Record<string, unknown>) {
|
||||
return Object.fromEntries(
|
||||
Object.entries(integration).map(([key, value]) => [
|
||||
key,
|
||||
@@ -3447,5 +3211,3 @@ function localParts(date: Date, timezone: string): Record<string, string> {
|
||||
.map((part) => [part.type, part.value])
|
||||
);
|
||||
}
|
||||
|
||||
export { extractApprovalRunAttachments, downloadApprovalRunAttachments };
|
||||
+1
-1
@@ -124,7 +124,7 @@ export async function handleHttpRequest(req: IncomingMessage, res: ServerRespons
|
||||
// 5. Generic Tool Invocation endpoint (POST /api/tool/:name)
|
||||
if (method === "POST" && pathname.startsWith("/api/tool/")) {
|
||||
const toolName = pathname.slice("/api/tool/".length).trim();
|
||||
const tool = findSealTool(toolName, { includeMcpAliases: true });
|
||||
const tool = findSealTool(toolName);
|
||||
if (!tool) {
|
||||
sendError(res, 404, `Tool not found: '${toolName}'`);
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user