219 lines
7.2 KiB
TypeScript
219 lines
7.2 KiB
TypeScript
import type { CorpConfig } from "../../core/config/types.js";
|
|
import type { createSealClient } from "../../core/http/factory.js";
|
|
import { runTool, runToolResult } from "../helpers.js";
|
|
import { booleanOption, numberOption, stringOption } from "../parser.js";
|
|
import { outputOptions, printJson } from "../printer.js";
|
|
import type { ParsedArgs } from "../types.js";
|
|
|
|
export async function handleApprovalRunsCommand(
|
|
action: string | undefined,
|
|
maybeName: string | undefined,
|
|
client: Awaited<ReturnType<typeof createSealClient>>,
|
|
corp: CorpConfig,
|
|
args: ParsedArgs
|
|
) {
|
|
if (action === "summary") {
|
|
const result = await runToolResult(
|
|
"seal_approval_runs_summary",
|
|
client,
|
|
corp,
|
|
{
|
|
date: stringOption(args.options.date),
|
|
timezone: stringOption(args.options.timezone),
|
|
limit: numberOption(args.options.limit),
|
|
startDate: stringOption(args.options.startDate),
|
|
endDate: stringOption(args.options.endDate),
|
|
status: stringOption(args.options.status),
|
|
taskMode: stringOption(args.options.taskMode),
|
|
manualApprovalStatus: stringOption(args.options.manualApprovalStatus),
|
|
sourceDocumentSN: stringOption(args.options.sourceDocumentSN),
|
|
sourceDocumentId: stringOption(args.options.sourceDocumentId),
|
|
humanResult: stringOption(args.options.humanResult),
|
|
query: stringOption(args.options.query)
|
|
}
|
|
);
|
|
if ((result as any)?.matched === 0 && (result as any)?.total > 0) {
|
|
console.error(
|
|
`提示:在 ${(result as any).date} 未匹配到记录(该企业共有 ${(result as any).total} 条历史记录)。可使用 --date YYYY-MM-DD 指定日期,或运行 seal-home approval-runs list --limit 10 查看最近记录。`
|
|
);
|
|
}
|
|
printJson(result, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "stats") {
|
|
await runTool(
|
|
"seal_approval_runs_stats",
|
|
client,
|
|
corp,
|
|
{
|
|
since: stringOption(args.options.since),
|
|
dedupeBy: (stringOption(args.options.dedupeBy) ?? stringOption(args.options["dedupe-by"])) as any,
|
|
status: stringOption(args.options.status),
|
|
sourceSystem: stringOption(args.options.sourceSystem) ?? stringOption(args.options["source-system"]),
|
|
taskMode: stringOption(args.options.taskMode) ?? stringOption(args.options["task-mode"])
|
|
},
|
|
outputOptions(args.options)
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (action === "count") {
|
|
await runTool(
|
|
"seal_approval_runs_count",
|
|
client,
|
|
corp,
|
|
{
|
|
status: stringOption(args.options.status),
|
|
sourceSystem: stringOption(args.options.sourceSystem) ?? stringOption(args.options["source-system"]),
|
|
taskMode: stringOption(args.options.taskMode) ?? stringOption(args.options["task-mode"]),
|
|
search: stringOption(args.options.search) ?? stringOption(args.options.query)
|
|
},
|
|
outputOptions(args.options)
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (action === "search" || action === "list") {
|
|
await runTool(
|
|
"seal_approval_runs_search",
|
|
client,
|
|
corp,
|
|
{
|
|
limit: numberOption(args.options.limit),
|
|
offset: numberOption(args.options.offset),
|
|
startDate: stringOption(args.options.startDate),
|
|
endDate: stringOption(args.options.endDate),
|
|
status: stringOption(args.options.status),
|
|
taskMode: stringOption(args.options.taskMode),
|
|
manualApprovalStatus: stringOption(args.options.manualApprovalStatus),
|
|
sourceDocumentSN: stringOption(args.options.sourceDocumentSN),
|
|
sourceDocumentId: stringOption(args.options.sourceDocumentId),
|
|
humanResult: stringOption(args.options.humanResult),
|
|
query: stringOption(args.options.query),
|
|
includeBridge: booleanOption(args.options.includeBridge)
|
|
},
|
|
outputOptions(args.options)
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (action === "bridge") {
|
|
await runTool(
|
|
"seal_approval_run_langfuse_bridge_get",
|
|
client,
|
|
corp,
|
|
{
|
|
recordId: stringOption(args.options.recordId),
|
|
sourceDocumentSN: stringOption(args.options.sourceDocumentSN),
|
|
sourceDocumentId: stringOption(args.options.sourceDocumentId),
|
|
simulationBatchId: stringOption(args.options.simulationBatchId),
|
|
limit: numberOption(args.options.limit)
|
|
},
|
|
outputOptions(args.options)
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (action === "pick") {
|
|
const query = maybeName ?? stringOption(args.options.query) ?? stringOption(args.options.sn);
|
|
if (!query) throw new Error("Usage: seal-home approval-runs pick --sn <documentSN>");
|
|
await runTool(
|
|
"seal_approval_run_pick",
|
|
client,
|
|
corp,
|
|
{
|
|
query,
|
|
sn: stringOption(args.options.sn),
|
|
batchId: stringOption(args.options.batch) ?? stringOption(args.options.batchId),
|
|
latest: booleanOption(args.options.latest),
|
|
fields: stringOption(args.options.fields),
|
|
limit: numberOption(args.options.limit),
|
|
includeBridge: booleanOption(args.options.includeBridge)
|
|
},
|
|
outputOptions(args.options)
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (action === "get") {
|
|
const recordId = args.command[2];
|
|
if (!recordId) throw new Error("Missing approval run recordId");
|
|
await runTool(
|
|
"seal_approval_run_get",
|
|
client,
|
|
corp,
|
|
{
|
|
recordId,
|
|
fields: stringOption(args.options.fields),
|
|
summary: booleanOption(args.options.summary)
|
|
},
|
|
outputOptions(args.options)
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (action === "cited-rules") {
|
|
const recordId = args.command[2];
|
|
if (!recordId) throw new Error("Usage: seal-home approval-runs cited-rules <recordId>");
|
|
await runTool("seal_approval_run_cited_rules_get", client, corp, { recordId }, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "document-summary") {
|
|
const recordId = args.command[2];
|
|
if (!recordId) throw new Error("Usage: seal-home approval-runs document-summary <recordId>");
|
|
await runTool("seal_approval_run_document_summary_get", client, corp, { recordId }, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "attachments") {
|
|
const recordId = args.command[2];
|
|
if (!recordId) throw new Error("Usage: seal-home approval-runs attachments <recordId>");
|
|
await runTool(
|
|
"seal_approval_run_attachments_get",
|
|
client,
|
|
corp,
|
|
{
|
|
recordId,
|
|
summary: booleanOption(args.options.summary)
|
|
},
|
|
outputOptions(args.options)
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (action === "result") {
|
|
const recordId = args.command[2];
|
|
if (!recordId) throw new Error("Usage: seal-home approval-runs result <recordId> [--summary]");
|
|
await runTool(
|
|
"seal_approval_run_result_get",
|
|
client,
|
|
corp,
|
|
{
|
|
recordId,
|
|
summary: booleanOption(args.options.summary)
|
|
},
|
|
outputOptions(args.options)
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (action === "url") {
|
|
await runTool(
|
|
"seal_approval_run_url_get",
|
|
client,
|
|
corp,
|
|
{
|
|
recordId: maybeName,
|
|
sourceDocumentSN: stringOption(args.options.sourceDocumentSN),
|
|
sourceDocumentId: stringOption(args.options.sourceDocumentId)
|
|
},
|
|
outputOptions(args.options)
|
|
);
|
|
return;
|
|
}
|
|
|
|
throw new Error(`Unknown approval-runs command: ${action ?? ""}. Run 'seal-home help' for available commands.`);
|
|
}
|