108 lines
4.1 KiB
TypeScript
108 lines
4.1 KiB
TypeScript
import { existsSync, readFileSync } from "node:fs";
|
|
import type { CorpConfig } from "../../core/config/types.js";
|
|
import type { createSealClient } from "../../core/http/factory.js";
|
|
import { runTool } from "../helpers.js";
|
|
import {
|
|
booleanOption,
|
|
jsonObject,
|
|
numberOption,
|
|
splitOption,
|
|
stringOption
|
|
} from "../parser.js";
|
|
import { outputOptions } from "../printer.js";
|
|
import type { ParsedArgs } from "../types.js";
|
|
|
|
export async function handleSimulationCommand(
|
|
action: string | undefined,
|
|
maybeName: string | undefined,
|
|
client: Awaited<ReturnType<typeof createSealClient>>,
|
|
corp: CorpConfig,
|
|
args: ParsedArgs
|
|
) {
|
|
if (action === "batch-records") {
|
|
const batchId = maybeName ?? stringOption(args.options.batchId);
|
|
if (!batchId) throw new Error("Usage: seal-home simulation batch-records <batchId>");
|
|
await runTool(
|
|
"seal_simulation_batch_records_get",
|
|
client,
|
|
corp,
|
|
{
|
|
batchId,
|
|
query: stringOption(args.options.query)
|
|
},
|
|
outputOptions(args.options)
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (action === "create") {
|
|
const modeArg = stringOption(args.options.mode) ?? "hosecloud";
|
|
const mode = modeArg === "material-pack" ? "material_pack" : modeArg;
|
|
const schemaConfigPath = stringOption(args.options.schemaConfig) ?? stringOption(args.options["schema-config"]);
|
|
const schemaConfig = schemaConfigPath
|
|
? JSON.parse(readFileSync(schemaConfigPath, "utf8"))
|
|
: undefined;
|
|
await runTool(
|
|
"seal_simulation_batch_create",
|
|
client,
|
|
corp,
|
|
{
|
|
mode,
|
|
flowIds: splitOption(args.options.flowIds) ?? splitOption(args.options["flow-ids"]),
|
|
rejectNodeName: stringOption(args.options.rejectNode) ?? stringOption(args.options["reject-node"]) ?? null,
|
|
thinkingDepthOverride: stringOption(args.options.thinkingDepth) ?? stringOption(args.options["thinking-depth"]),
|
|
skipInvoiceGeneration: booleanOption(args.options.skipInvoiceGeneration) ?? booleanOption(args.options["skip-invoice-generation"]),
|
|
skipExpenseExtraction: booleanOption(args.options.skipExpenseExtraction) ?? booleanOption(args.options["skip-expense-extraction"]),
|
|
disableAttachmentCache: booleanOption(args.options.disableAttachmentCache) ?? booleanOption(args.options["disable-attachment-cache"]),
|
|
signKey: stringOption(args.options.signKey) ?? stringOption(args.options["sign-key"]),
|
|
packageIds: splitOption(args.options.packageIds) ?? splitOption(args.options["package-ids"]),
|
|
templateId: stringOption(args.options.templateId) ?? stringOption(args.options["template-id"]),
|
|
schemaConfig,
|
|
rawParams: jsonObject(args.json)
|
|
},
|
|
outputOptions(args.options)
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (action === "list") {
|
|
await runTool(
|
|
"seal_simulation_batches_list",
|
|
client,
|
|
corp,
|
|
{
|
|
limit: numberOption(args.options.limit)
|
|
},
|
|
outputOptions(args.options)
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (action === "get") {
|
|
const batchId = maybeName ?? stringOption(args.options.batchId) ?? stringOption(args.options["batch-id"]);
|
|
if (!batchId) throw new Error("Usage: seal-home simulation get <batchId>");
|
|
await runTool("seal_simulation_batch_get", client, corp, { batchId }, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "templates") {
|
|
await runTool("seal_simulation_templates_get", client, corp, {}, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "integrations") {
|
|
await runTool("seal_simulation_integrations_get", client, corp, {}, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
if (action === "package-upload") {
|
|
const filePath = maybeName ?? stringOption(args.options.file);
|
|
if (!filePath) throw new Error("Usage: seal-home simulation package-upload <材料包.zip>");
|
|
if (!existsSync(filePath)) throw new Error(`File not found: ${filePath}`);
|
|
await runTool("seal_simulation_material_package_upload", client, corp, { filePath }, outputOptions(args.options));
|
|
return;
|
|
}
|
|
|
|
throw new Error(`Unknown simulation command: ${action ?? ""}. Run 'seal-home help' for available commands.`);
|
|
}
|