154 lines
7.9 KiB
TypeScript
154 lines
7.9 KiB
TypeScript
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;
|
|
export const RULE_SUMMARY_FIELDS = ["id", "code", "status", "strictness", "scope", "createdAt", "updatedAt"];
|
|
export const DEFAULT_OUTPUT_BYTES_LIMIT = 200_000;
|
|
|
|
export function formatConsoleOutput(values: unknown[]): string {
|
|
return values.map((value) => (typeof value === "string" ? value : String(value))).join(" ");
|
|
}
|
|
|
|
export function joinOutput(lines: string[]): string {
|
|
if (!lines.length) return "";
|
|
return `${lines.join("\n")}\n`;
|
|
}
|
|
|
|
export function redactSensitiveText(value: string): string {
|
|
return value
|
|
.replace(/([?&](?:accessToken|token|returnToken)=)[^&\s]+/gi, "$1<redacted>")
|
|
.replace(/(Bearer\s+)[A-Za-z0-9._~+/=-]+/gi, "$1<redacted>");
|
|
}
|
|
|
|
export function printJson(value: unknown, options: OutputOptions = {}) {
|
|
protectLargeOutput(value, options);
|
|
const json = `${JSON.stringify(value, null, 2)}\n`;
|
|
if (options.outputFile) {
|
|
writeFileSync(options.outputFile, json);
|
|
console.log(JSON.stringify({ outputFile: options.outputFile, bytes: Buffer.byteLength(json, "utf-8") }, null, 2));
|
|
return;
|
|
}
|
|
console.log(json.trimEnd());
|
|
}
|
|
|
|
export 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) {
|
|
throw new Error(
|
|
`Output is large (${bodyBytes} bytes). Use --summary, --fields, --count, or --output-file; pass --full only when you really need the full response.`
|
|
);
|
|
}
|
|
}
|
|
|
|
export function protectLargeRuleListOutput(result: unknown, allowFull: boolean) {
|
|
if (allowFull) return;
|
|
|
|
const data = result && typeof result === "object" ? (result as {
|
|
count?: unknown;
|
|
rules?: unknown;
|
|
}) : {};
|
|
const count = typeof data.count === "number" ? data.count : undefined;
|
|
const rulesCount = Array.isArray(data.rules) ? data.rules.length : undefined;
|
|
const bodyBytes = Buffer.byteLength(JSON.stringify(result), "utf-8");
|
|
const effectiveCount = count ?? rulesCount ?? 0;
|
|
|
|
if (effectiveCount > RULE_LIST_FULL_COUNT_LIMIT || bodyBytes > RULE_LIST_FULL_BYTES_LIMIT) {
|
|
throw new Error(
|
|
`Rule list is large (${effectiveCount} rules, ${bodyBytes} bytes). Use "seal-home rules list --summary" or "seal-home rules count"; pass --full only when you really need full descriptions.`
|
|
);
|
|
}
|
|
}
|
|
|
|
export function outputOptions(options: Record<string, string | boolean>): OutputOptions {
|
|
return {
|
|
allowFull: booleanOption(options.full) === true,
|
|
outputFile: stringOption(options.outputFile) ?? stringOption(options["output-file"])
|
|
};
|
|
}
|
|
|
|
export function printHelp() {
|
|
console.log(`seal-home CLI
|
|
|
|
Usage:
|
|
seal-home version
|
|
seal-home mcp
|
|
seal-home mcp config
|
|
seal-home mcp-config
|
|
seal-home skill dump
|
|
seal-home skill install [--dir <path>|--local]
|
|
seal-home skill status
|
|
seal-home openapi
|
|
seal-home probe [<corpId>]
|
|
seal-home config paths
|
|
seal-home config get
|
|
seal-home config mode <stateful|stateless> [--corp <corpId>]
|
|
seal-home update [--check] [--force] [--version <v>]
|
|
seal-home update check
|
|
seal-home update changelog [--limit <n>]
|
|
seal-home changelog [--limit <n>]
|
|
seal-home tools list
|
|
seal-home corps list [--corp <corpId>]
|
|
seal-home corps current [--corp <corpId>]
|
|
seal-home corps switch <corpId>
|
|
seal-home corps add-hose --json '{"name":"企业名称","domain":"https://app.ekuaibao.com","appKey":"...","appSecurity":"...","proxyStaffBizId":"corpId:staffId"}'
|
|
seal-home corps add-seal --json '{"sealUrl":"https://tenant.sealai.cc","token":"seal-bearer-token"}'
|
|
seal-home auth diagnose [--corp <corpId>]
|
|
seal-home auth hose-link [--corp <corpId>] [--expire 7200]
|
|
seal-home delegation list [--corp <corpId>]
|
|
seal-home delegation create [--note <note>] [--corp <corpId>]
|
|
seal-home delegation revoke <tokenId> [--corp <corpId>]
|
|
seal-home users create --name <name> --phone <phone> [--dept <deptId>] [--corp <corpId>]
|
|
seal-home users search <keyword> [--corp <corpId>]
|
|
seal-home users delegation <userIdOrPhone|name> [--note <note>] [--corp <corpId>]
|
|
seal-home users reset-password <userId> [--corp <corpId>]
|
|
seal-home users get <userId> [--corp <corpId>]
|
|
seal-home users delete <userId> [--corp <corpId>]
|
|
seal-home llm config [--corp <corpId>]
|
|
seal-home llm providers [--corp <corpId>]
|
|
seal-home permissions available [--corp <corpId>]
|
|
seal-home permissions configs [--corp <corpId>]
|
|
seal-home billing status [--corp <corpId>]
|
|
seal-home billing plans [--corp <corpId>]
|
|
seal-home billing features [--corp <corpId>]
|
|
seal-home webhook list [--query <text>] [--show-secret] [--corp <corpId>]
|
|
seal-home webhook get|find <idOrName> [--show-secret] [--corp <corpId>]
|
|
seal-home webhook add --name <name> --result-url <url> [--mode assisted|semi_automatic|fully_automatic] [--auto-approval-rate 60] [--secret <secret>] [--corp <corpId>]
|
|
seal-home webhook update <idOrName> [--name <name>] [--result-url <url>] [--mode assisted|semi_automatic|fully_automatic] [--auto-approval-rate 60] [--secret <secret>|--rotate-secret] [--corp <corpId>]
|
|
seal-home webhook delete <idOrName> --yes [--corp <corpId>]
|
|
seal-home source config [--corp <corpId>]
|
|
seal-home tool <toolName> [--corp <corpId>] [--json '{"key":"value"}']
|
|
seal-home rules count [--corp <corpId>]
|
|
seal-home rules list [--summary] [--count] [--limit 20] [--offset 0] [--corp <corpId>]
|
|
seal-home rules clear [--corp <corpId>] [--dry-run|--yes]
|
|
seal-home rules versions [--corp <corpId>]
|
|
seal-home rules version <versionId|versionNumber|latest> [--corp <corpId>]
|
|
seal-home rules get --corp <corpId> --version <number|latest> --code '#0038'
|
|
seal-home rules get --corp <corpId> --record-id <recordId> --runtime-id rule-205
|
|
seal-home rules search <keyword> [--version <versionId|versionNumber|latest>] [--maxResults 20] [--corp <corpId>]
|
|
seal-home context [--ruleVersion <versionId|versionNumber|latest>] [--documentLimit 50] [--corp <corpId>]
|
|
seal-home approval-runs summary [--date YYYY-MM-DD] [--timezone Asia/Shanghai] [--corp <corpId>]
|
|
seal-home approval-runs list|search [--query text] [--humanResult 驳回] [--manualApprovalStatus TERMINATED] [--startDate ms] [--endDate ms] [--limit 20] [--includeBridge true] [--corp <corpId>]
|
|
seal-home approval-runs pick --sn <documentSN> [--batch <batchId>] [--latest] [--fields recordId,status,aiDecision] [--corp <corpId>]
|
|
seal-home approval-runs get <recordId> [--summary] [--fields metadata|document.fields,result.summary] [--full] [--output-file file.json] [--corp <corpId>]
|
|
seal-home approval-runs cited-rules <recordId> [--corp <corpId>]
|
|
seal-home approval-runs document-summary <recordId> [--corp <corpId>]
|
|
seal-home approval-runs attachments <recordId> [--summary] [--corp <corpId>]
|
|
seal-home approval-runs result <recordId> [--summary] [--corp <corpId>]
|
|
seal-home approval-runs url [--corp <corpId>]
|
|
seal-home approval-runs url <recordId> [--corp <corpId>]
|
|
seal-home approval-runs url --sourceDocumentSN B26022501 [--corp <corpId>]
|
|
seal-home approval-runs bridge [--sourceDocumentSN B26001887] [--corp <corpId>]
|
|
seal-home simulation batch-records <batchId> [--corp <corpId>]
|
|
seal-home simulation create --mode hosecloud --flow-ids "B26017701,B26022501" [--reject-node 财务] [--thinking-depth default|medium|high] [--skip-invoice-generation|--skip-invoice-generation false] [--corp <corpId>]
|
|
seal-home simulation create --mode material_pack --package-ids <materialPackageId> [--template-id conference_reimbursement_v1] [--schema-config file.json] [--corp <corpId>]
|
|
seal-home simulation list [--limit 50] [--corp <corpId>]
|
|
seal-home simulation get <batchId> [--corp <corpId>]
|
|
seal-home simulation templates [--corp <corpId>]
|
|
seal-home simulation integrations [--corp <corpId>]
|
|
seal-home simulation package-upload <材料包.zip> [--corp <corpId>]
|
|
`);
|
|
}
|