diff --git a/skills/seal-use/SKILL.md b/skills/seal-use/SKILL.md index 97b179e..c2f5f29 100644 --- a/skills/seal-use/SKILL.md +++ b/skills/seal-use/SKILL.md @@ -84,13 +84,15 @@ bun run dev:override # 编译本机二进制、打版本号并原子覆盖 2. 读取 `references/first-time-user.md`,只渲染与当前路径对应的截图;不能只给纯文字步骤。 3. 接收材料后由 Agent 自动发现企业、域名和管理员。除非自动发现失败,不要要求用户先填写 `corpId`、`staffId` 或域名。 -## `corps` 主线 +## `corps` 主线与规则演进 企业接入、发现、维护与测试配对的具体语法见 `seal-use help corps`;材料选择与操作流程按下方 reference 路由。 Hose 专属命令应从命令名或选项中明确可见:`auth hose-*`、`approval-runs hose-flow`、`deploy hosecloud`、`simulation --mode hosecloud`。跨来源入口只有在明确使用 `--elevate-hose`、`--with-flow` 或 `--type hose-document` 时才启用对应 Hose 能力。 -生产规则变更遵循:生产改草稿 → 同步测试 → 模拟/回归验证 → 用户确认 → 生产发布。`sync-test`、`replay-test`、规则发布和清空等高风险操作优先 `--dry-run`,正式执行必须显式 `--yes` 或 `--confirm`。 +规则变更与验证闭环: +- **单租户快照测试(首选,无需双企业组)**:`simulation create` 原生支持 `ruleSource`(默认以当前线上生效规则运行;加 `--draft` 显式对未发布草稿拍摄不可变快照;`--rule-version` 挂载指定历史版本),单个企业租户内执行 `seal-use simulation create --corp --flow-ids --draft --wait` 即可原地完成草稿快照测试,不再需要双企业组与 `sync-test` 预发版造快照。 +- **双租户物理隔离(可选)**:仅在需严格物理隔离外部审批流出站、跨租户出站仿真重放或执行全量自动化回归矩阵(`test regression` 阻断生产环境)时,才使用 `corps bind-test` 与 `corps sync-test`。`sync-test`、`replay-test`、规则发布和清空等高风险操作优先 `--dry-run`,正式执行必须显式 `--yes` 或 `--confirm`。 ## 规则编号重排:两次调用 diff --git a/skills/seal-use/references/cli.md b/skills/seal-use/references/cli.md index 1d70341..e6450aa 100644 --- a/skills/seal-use/references/cli.md +++ b/skills/seal-use/references/cli.md @@ -136,8 +136,9 @@ seal-use report review dismiss [--hours ] [--corp ] seal-use report review list [--corp ] seal-use report review import <台账.xlsx|csv> --corp seal-use simulation batch-records [--corp ] -seal-use simulation create --mode hosecloud --flow-ids "B26017701,B26022501" [--wait] [--timeout 10m] [--poll-interval 2s] [--reject-node 财务] [--thinking-depth default|medium|high] [--skip-extract|--extract] [--skip-invoice-generation] [--no-wait] [--force] [--reuse-window 5m] [--corp ] -seal-use simulation create --mode material_pack --package-ids [--template-id conference_reimbursement_v1] [--schema-config file.json] [--corp ] +seal-use simulation create --mode hosecloud --flow-ids "B26017701,B26022501" [--wait] [--timeout 10m] [--poll-interval 2s] [--reject-node 财务] [--thinking-depth default|medium|high] [--skip-extract|--extract] [--skip-invoice-generation] [--no-wait] [--force] [--reuse-window 5m] [--draft] [--rule-version ] [--corp ] +seal-use simulation create --mode material_pack --package-ids [--template-id conference_reimbursement_v1] [--schema-config file.json] [--draft] [--rule-version ] [--corp ] +seal-use simulation create --mode maycur --form-codes "MC001,MC002" [--draft] [--corp ] seal-use simulation create --source-system weaver --request-ids "req-01,req-02" [--corp ] seal-use simulation status [--corp ] seal-use simulation wait [--timeout 10m] [--poll-interval 2s] [--corp ] diff --git a/skills/seal-use/references/staging-simulation-workflow.md b/skills/seal-use/references/staging-simulation-workflow.md index 803430a..f6c95fb 100644 --- a/skills/seal-use/references/staging-simulation-workflow.md +++ b/skills/seal-use/references/staging-simulation-workflow.md @@ -13,17 +13,46 @@ # 国内镜像源秒级自愈与升级 curl -fsSL https://git.ying-qing.cn/gitea/seal-use/raw/branch/main/scripts/install.sh | bash ``` -2. **测试先行,优先草稿隔离 (Staging-First Recommendation)**: - - 强烈建议生产环境的规则修改优先以草稿态(`draft`)保存,并通过 `seal-use corps sync-test` 自动同步到绑定的测试企业进行模拟验证。 - - Agent 应主动向用户建议该安全演进闭环,但**绝不替用户做决定**。最终的操作权在用户手中;若用户明确指示直接在生产企业发布,Agent 必须尊重并遵照用户意图执行。 -3. **合思集成安全隔离 (Hosecloud Zero-Impact Sync)**: - - 测试环境进行合思模拟测试,必须在测试企业中保存合思凭证。 - - `corps sync-test` 会自动读取本地生产 source 凭证并为测试环境配置 `assisted`(辅助)模式的合思集成,名称格式为 `{企业名前缀}(Seal测)`。 +2. **单租户原生快照测试(首选,不再强求双企业组)**: + - 过去平台模拟测试因无法指定规则版本,必须通过双企业组(生产 + 测试)与 `corps sync-test` 在测试企业预发版来固化快照。 + - 现在 Seal 后端原生支持 `ruleSource`:创建模拟时默认以当前线上生效的正式规则运行;若要测试刚刚修改的未发布规则草稿,显式传递 `--draft` 即可自动对当前草稿拍摄不可变快照(`ruleSource: { type: "current" }`);亦可通过 `--rule-version ` 挂载指定历史发布版本。 + - **单企业租户即可原生闭环草稿快照测试与多版本对比**,无需强行开通或绑定第二个测试企业。 +3. **双企业租户物理隔离场景(保留边界)**: + - 双企业组(`corps bind-test` + `corps sync-test`)不再是为了“制造快照”,而是为了: + 1. 物理隔离外部费控审批流出站(测试端合思集成设为 `assisted`,防止外部推送副作用); + 2. 执行全自动大样本回归测试矩阵(`seal-use test regression` 硬阻断生产企业执行); + 3. 跨租户 Webhook 与出站仿真重放。 - **严禁向合思执行同步 (`deploy hosecloud sync`)**:测试环境的合思配置只保存在 Seal 端,绝不向合思生产系统推送 EBot 节点或创建真实出站消息,保障生产费控审批流的绝对安全。 --- -## 端到端标准演进闭环 (The 5-Stage Lifecycle) +## 端到端标准演进闭环 (Evolution Lifecycles) + +### 路径 A:单企业租户原生快照演进闭环(优先首选) + +```mermaid +flowchart TD + A["Stage 1: 规则草稿修改 (rules update)"] --> B["Stage 2: 单租户原生快照模拟 (simulation create --draft --wait)"] + B --> C{"快照模拟与版本比对是否通过?"} + C -- 存在偏差/翻转误伤 --> A + C -- 验证通过 --> D["Stage 3: 生产正式发布 (rules publish)"] +``` + +1. **修改草稿**:`seal-use rules update --corp `。 +2. **原地快照模拟验证**: + ```bash + # 显式使用 --draft 为当前未发布草稿拍摄不可变快照 + seal-use simulation create --corp --flow-ids "<单号>" --draft --wait + + # 或与线上当前生效规则基线、历史已发布版本回溯比对 + seal-use simulation create --corp --flow-ids "<单号>" --wait + seal-use simulation create --corp --flow-ids "<单号>" --rule-version "" --wait + ``` +3. **正式发布**:用户确认后执行 `seal-use rules publish "<变更说明>" --corp `。 + +--- + +### 路径 B:双企业租户物理隔离演进闭环(特定场景选) ```mermaid flowchart TD @@ -163,12 +192,26 @@ flowchart TD ``` > **红线保障**:系统硬性规定回归测试严禁在生产环境发起;且前置计算点数余额,余额不足直接拒绝执行;基于出站 HTTPS 轮询,客户端无公网 IP 亦可稳定工作。 - - **方式 B:合思原生模拟任务 (Simulation Create,单据与附件测试首选)**: - 针对目标真实单据号(或客诉单据)在测试环境发起模拟。**强烈建议单据及附件审核优先采用本方式**,因为平台原生模拟通道会调用合思官方 OpenAPI 完整抓取单据正文与全部发票、合同等二进制附件,完整度最高;且支持 `--wait` 自动挂起轮询直至出结果: + - **方式 B:平台原生模拟任务 (Simulation Create,单据与附件测试首选)**: + 针对目标真实单据号(或客诉单据)在测试环境发起模拟。**强烈建议单据及附件审核优先采用本方式**,因为平台原生模拟通道会调用上游官方 API 完整抓取单据正文与全部发票、合同等二进制附件,完整度最高;且支持 `--wait` 自动挂起轮询直至出结果: ```bash - # 异步创建后自动轮询等待结果(推荐) + # 异步创建后自动轮询等待结果(默认使用当前规则草稿快照) seal-use simulation create --corp --mode hosecloud --flow-ids "<单号1>,<单号2>" --wait + + # 指定已发布历史规则版本进行回溯比对(例如比对修复前后的版本差异) + seal-use simulation create --corp --mode hosecloud --flow-ids "<单号>" --rule-version "" --wait + + # 深度推理与附件无缓存全量重跑(深度思考模式下生效) + seal-use simulation create --corp --mode hosecloud --flow-ids "<单号>" --thinking-depth high --disable-attachment-cache --wait + + # 每刻报销原生单据模拟测试 + seal-use simulation create --corp --mode maycur --form-codes "<单号1>,<单号2>" --wait ``` + > **规则源与版本快照(`ruleSource`)**: + > - 默认或显式传 `--rule-source current` 时,系统自动为当前草稿拍摄规则快照(`type: "snapshot"`),界面与批次详情显示 `当前规则快照(未发布)· 拍摄时间`。 + > - 指定 `--rule-version ` 时,锁定使用已发布的历史版本(`type: "published"`),用于精准评估特定版本的判定准确度。 + > - 审核记录中同步包含 `ruleSetSnapshotCreatedAt` 与思考深度(`thinkingDepthLevel`)。 + > > **打断/重发防重复扣费**:批次创建默认幂等——复用窗口(默认 5 分钟,`--reuse-window` 可调)内对同一组 `--flow-ids`/`--package-ids` 再次执行 `simulation create` 会直接返回既有批次(`reused: true`),不会重复扣费。若 `--wait` 挂起期间命令被用户消息打断或后台 task 被 kill,**先执行 `seal-use simulation list --limit 3` 查最近批次**(同单批次可能已在服务端跑完),拿到批次 ID 后用 `status`/`batch-records` 取结果;确认无在途同单批次再决定重发。确需立刻重跑同组单号时显式加 `--force`。 > > **按界面名称找历史批次**:模拟测试服务端没有名称/关键词检索,批次也没有 `name` 字段(界面的「任务 fe1993e4」是 UUID 末 8 位)。用 `seal-use simulation search "任务 fe1993e4" --since 7d` 或 `seal-use simulation list --query <关键词> --since <时间>`;这是 **CLI 本地聚合检索**(先按 `limit`/`offset` 拉取再过滤,响应带 `retrieval.serverSideSearch: false`),命中范围以 `scanned` 为准,需要覆盖更早批次时加 `--all`(可用 `--max-scan` 控上限)。 diff --git a/src/cli/commands/simulation.ts b/src/cli/commands/simulation.ts index 053e7c0..69e4350 100644 --- a/src/cli/commands/simulation.ts +++ b/src/cli/commands/simulation.ts @@ -87,6 +87,31 @@ export async function handleSimulationCommand( ); } + const isDraft = + booleanOption(args.options.draft) || + booleanOption(args.options.current) || + booleanOption(args.options["current-rules"]) || + booleanOption(args.options.currentRules) || + stringOption(args.options.ruleSource) === "current" || + stringOption(args.options["rule-source"]) === "current"; + + const ruleVersion = + stringOption(args.options.ruleVersion) ?? + stringOption(args.options["rule-version"]) ?? + stringOption(args.options["rule-version-id"]) ?? + stringOption(args.options.ruleVersionId); + + let ruleSource: { type: "current" } | { type: "published"; versionId: string } | undefined; + if (isDraft) { + ruleSource = { type: "current" }; + } else if (ruleVersion) { + ruleSource = { type: "published", versionId: ruleVersion }; + } + + const formCodes = + splitOption(args.options.formCodes) ?? + splitOption(args.options["form-codes"]); + const result = await runCapabilityResult( "sealSimulationBatchCreate", client, @@ -96,11 +121,14 @@ export async function handleSimulationCommand( sourceSystem: mode, flowIds, documentSn: flowIds, + formCodes, 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, disableAttachmentCache: booleanOption(args.options.disableAttachmentCache) ?? booleanOption(args.options["disable-attachment-cache"]), + ruleSource, + ruleVersion, signKey, packageIds, packageId, diff --git a/src/cli/help.ts b/src/cli/help.ts index 38c6829..cfaecb8 100644 --- a/src/cli/help.ts +++ b/src/cli/help.ts @@ -849,10 +849,11 @@ export const HELP_REGISTRY: AreaHelp[] = [ }, { name: "create", - summary: "Trigger a simulation batch (reuses an identical batch within the reuse window; defaults to skipping background expense DB extraction)", + summary: "Trigger a simulation batch (reuses an identical batch within the reuse window; defaults to skipping background expense DB extraction; defaults to latest published rules; pass --draft for unreleased draft snapshot)", usage: [ - "seal-use simulation create --mode hosecloud --flow-ids \"B26017701,B26022501\" [--wait] [--timeout 10m] [--poll-interval 2s] [--reject-node 财务] [--thinking-depth default|medium|high] [--skip-extract|--extract] [--skip-invoice-generation] [--no-wait] [--force] [--reuse-window 5m] [--corp ]", - "seal-use simulation create --mode material_pack --package-ids [--template-id conference_reimbursement_v1] [--schema-config file.json] [--corp ]", + "seal-use simulation create --mode hosecloud --flow-ids \"B26017701,B26022501\" [--wait] [--timeout 10m] [--poll-interval 2s] [--reject-node 财务] [--thinking-depth default|medium|high] [--skip-extract|--extract] [--skip-invoice-generation] [--no-wait] [--force] [--reuse-window 5m] [--draft] [--rule-version ] [--corp ]", + "seal-use simulation create --mode material_pack --package-ids [--template-id conference_reimbursement_v1] [--schema-config file.json] [--draft] [--rule-version ] [--corp ]", + "seal-use simulation create --mode maycur --form-codes \"MC001,MC002\" [--draft] [--corp ]", "seal-use simulation create --source-system weaver --request-ids \"req-01,req-02\" [--corp ]" ] }, diff --git a/src/cli/parser.ts b/src/cli/parser.ts index 3c26bd0..2e849da 100644 --- a/src/cli/parser.ts +++ b/src/cli/parser.ts @@ -27,7 +27,7 @@ export const BOOLEAN_FLAGS = new Set([ "V", "add", "all", "allow-unreviewed", "allowUnreviewed", "as-hose", "attachments", "auto", "auto-login", "autoLogin", "bg-save", "changelog", "check", "check-only", "completed-only", "completedOnly", "confirm", "count", "disable-attachment-cache", "disableAttachmentCache", - "download", "downloads", "dry-run", "dryRun", "elevate-hose", "enabled", + "download", "downloads", "draft", "current", "dry-run", "dryRun", "elevate-hose", "enabled", "exclude-deleted", "extract", "extract-expenses", "extractExpenses", "fail-on-flips", "flow", "force", "full", "glossary", "has-input", "has-output", "help", "has-extra-risk", "hasExtraRisk", "hose", "hose-outbound", "hose-sso", "hoseOutbound", "hoseSso", "include-deleted", "include-io-preview", "include-simulation", "include-unchanged", "include-bridge", "includeBridge", "includeSimulation", "includeUnchanged", "local", "no-attachments", "no-flow", "no-glossary", @@ -54,7 +54,7 @@ export const VALUE_FLAGS = new Set([ "documentId", "document-limit", "documentLimit", "documentSn", "documentType", "domain", "enable", "end", "end-date", "end-time", "endDate", "endTime", "env", "environment", "expire", "expires-in", "expiresIn", "fields", "file", "file-id", "file-name", "flow-concurrency", - "flow-id", "flow-ids", "flow-status-list", "flowId", "flowIds", "flowStatusList", "format", "from", + "flow-id", "flow-ids", "flow-status-list", "flowId", "flowIds", "flowStatusList", "form-codes", "formCodes", "format", "from", "from-link", "host", "hours", "human", "human-accuracy", "humanAccuracy", "human-result", "humanResult", "id", "input", "integration", "json", "json-path", "key-id", "keyId", "keyword", "ledger", "level", "limit", "lines", "link", "linter", "manual-approval-status", "manual-status", "manualApprovalStatus", "manualStatus", @@ -70,7 +70,7 @@ export const VALUE_FLAGS = new Set([ "reviewed-by", "reviewedBy", "report-id", "repo", "request-ids", "requestIds", "resubmit-method", "resubmitMethod", "result-url", "resultUrl", "reuse-window", - "reuseWindow", "rule", "rule-hints", "rule-id", "ruleId", "rule-version", "ruleVersion", "runtime-id", + "reuseWindow", "rule", "rule-hints", "rule-id", "ruleId", "rule-source", "ruleSource", "rule-version", "ruleVersion", "rule-version-id", "ruleVersionId", "runtime-id", "runtimeId", "samples", "scenarios", "schema-config", "schemaConfig", "scope", "sealUrl", "search", "secret", "selector", "session-id", "sign-key", "signKey", "simulation-batch-id", "simulationBatchId", "since", "sn", "sn-prefix", "sn-suffix", "snPrefix", diff --git a/src/domains/seal/api.ts b/src/domains/seal/api.ts index 281acea..3a40e51 100644 --- a/src/domains/seal/api.ts +++ b/src/domains/seal/api.ts @@ -88,6 +88,8 @@ import { SimulationIntegrationStatusSchema, SimulationHosecloudIntegration, SimulationHosecloudIntegrationSchema, + SimulationMaycurIntegration, + SimulationMaycurIntegrationSchema, MaterialPackage, MaterialPackageSchema, SimulationSpecification, @@ -824,6 +826,22 @@ export async function listSimulationHosecloudIntegrations( return z.array(SimulationHosecloudIntegrationSchema).parse(data); } +export async function listSimulationMaycurPrivateIntegrations( + client: KyInstance +): Promise { + const json = (await client.get("api/v1/simulation/maycur-private-integrations").json()) as { data?: unknown }; + const data = json.data ?? json; + return z.array(SimulationMaycurIntegrationSchema).parse(data); +} + +export async function listSimulationMaycurStandardIntegrations( + client: KyInstance +): Promise { + const json = (await client.get("api/v1/simulation/maycur-standard-integrations").json()) as { data?: unknown }; + const data = json.data ?? json; + return z.array(SimulationMaycurIntegrationSchema).parse(data); +} + export async function cleanSimulationBatch( client: KyInstance, batchId: string diff --git a/src/domains/seal/capabilities/helpers.ts b/src/domains/seal/capabilities/helpers.ts index d0509e8..7debfea 100644 --- a/src/domains/seal/capabilities/helpers.ts +++ b/src/domains/seal/capabilities/helpers.ts @@ -21,6 +21,7 @@ import type { ApprovalRun, RuleSetVersion, SimulationBatch, + SimulationRuleSourceInput, WebhookIntegration } from "../types.js"; import { extractApprovalRunAttachments } from "../approval-runs/attachments.js"; @@ -230,39 +231,18 @@ export function normalizeRuleStrictness(value?: string): string { } export type SimulationBatchCreateInput = { - mode?: string; - sourceSystem?: string; - flowIds?: string[]; - documentSn?: string | string[]; + mode?: string; sourceSystem?: string; signKey?: string; + flowIds?: string[]; documentSn?: string | string[]; formCodes?: string[]; rejectNodeName?: string | null; thinkingDepthOverride?: "default" | "medium" | "high"; - skipInvoiceGeneration?: boolean; - skipExpenseExtraction?: boolean; - disableAttachmentCache?: boolean; - signKey?: string; - packageIds?: string[]; - packageId?: string; - templateId?: string; - schemaConfig?: Record; - approvalCode?: string; - nodeId?: string; - runMode?: string; - requestIds?: string[]; - workflowTypeId?: string; - flowStatusList?: number[]; - businessCodes?: string[]; - documentType?: string; - formCodes?: string[]; - formSubTypeBizCode?: string; - formStatus?: string; - pageNo?: number; - pageSize?: number; - startTime?: number; - endTime?: number; - status?: string[]; - limit?: number; - // 预留:其他取数模式(如合思时间范围)透传参数,覆盖构建结果 - rawParams?: Record; + skipInvoiceGeneration?: boolean; skipExpenseExtraction?: boolean; disableAttachmentCache?: boolean; + ruleSource?: SimulationRuleSourceInput; ruleVersion?: string; + packageIds?: string[]; packageId?: string; templateId?: string; + schemaConfig?: Record; approvalCode?: string; nodeId?: string; runMode?: string; + requestIds?: string[]; workflowTypeId?: string; flowStatusList?: number[]; businessCodes?: string[]; + documentType?: string; formSubTypeBizCode?: string; formStatus?: string; + pageNo?: number; pageSize?: number; startTime?: number; endTime?: number; + status?: string[]; limit?: number; rawParams?: Record; }; export function redactIntegrationSecrets(integration: Record) { @@ -320,6 +300,12 @@ export function buildSimulationBatchParams(input: SimulationBatchCreateInput): R thinkingDepthOverride: input.thinkingDepthOverride ?? "default", disableAttachmentCache: input.disableAttachmentCache ?? false }; + const resolvedRuleSource = + input.ruleSource ?? + (input.ruleVersion ? { type: "published", versionId: input.ruleVersion } : undefined); + if (resolvedRuleSource) { + params.ruleSource = resolvedRuleSource; + } const docSns = input.flowIds ?? (typeof input.documentSn === "string" ? input.documentSn.split(",").map((s) => s.trim()).filter(Boolean) : input.documentSn); @@ -376,17 +362,21 @@ export function buildSimulationBatchParams(input: SimulationBatchCreateInput): R rejectNodeName: input.rejectNodeName ?? null }); } else if (sourceSystem === "maycur" || sourceSystem === "maycur-standard") { - Object.assign(params, { - sourceSystem, - formCodes: input.formCodes ?? docSns, - createdAtStart: input.startTime, - createdAtEnd: input.endTime, - formSubTypeBizCode: input.formSubTypeBizCode, - formStatus: input.formStatus, - pageNo: input.pageNo ?? 1, - pageSize: input.pageSize ?? 100, - signKey: input.signKey - }); + const formCodes = input.formCodes ?? docSns; + if (formCodes?.length) { + Object.assign(params, { sourceSystem, formCodes, ...(input.signKey ? { signKey: input.signKey } : {}) }); + } else { + Object.assign(params, { + sourceSystem, + createdAtStart: input.startTime, + createdAtEnd: input.endTime, + formSubTypeBizCode: input.formSubTypeBizCode, + formStatus: input.formStatus, + pageNo: input.pageNo ?? 1, + pageSize: input.pageSize ?? 100, + signKey: input.signKey + }); + } } else if (sourceSystem === "feishu") { Object.assign(params, { sourceSystem: "feishu", @@ -418,6 +408,7 @@ export function summarizeSimulationBatch(batch: SimulationBatch) { failedCount: batch.failedCount, createdCount: batch.createdCount, createFailedCount: batch.createFailedCount, + ruleSource: batch.ruleSource, requestSummary: batch.requestSummary, resultSummary: batch.resultSummary, createdAt: batch.createdAt diff --git a/src/domains/seal/capabilities/simulation.test.ts b/src/domains/seal/capabilities/simulation.test.ts index 98051f5..4c7ae74 100644 --- a/src/domains/seal/capabilities/simulation.test.ts +++ b/src/domains/seal/capabilities/simulation.test.ts @@ -324,6 +324,29 @@ describe("buildSimulationBatchParams", () => { }); }); + test("builds request payload with specified ruleVersion", () => { + const params = buildSimulationBatchParams({ + mode: "hosecloud", + flowIds: ["B26017701"], + signKey: SIGN_KEY, + ruleVersion: "01a123bd-ef1c-7579-8ebc-3c02058c9c72" + }); + expect(params.ruleSource).toEqual({ + type: "published", + versionId: "01a123bd-ef1c-7579-8ebc-3c02058c9c72" + }); + }); + + test("builds request payload with explicit ruleSource", () => { + const params = buildSimulationBatchParams({ + mode: "hosecloud", + flowIds: ["B26017701"], + signKey: SIGN_KEY, + ruleSource: { type: "current" } + }); + expect(params.ruleSource).toEqual({ type: "current" }); + }); + test("rejects hosecloud mode without flowIds", () => { expect(() => buildSimulationBatchParams({ mode: "hosecloud", signKey: SIGN_KEY })) .toThrow("hosecloud 模式需要提供 flowIds"); diff --git a/src/domains/seal/capabilities/simulation.ts b/src/domains/seal/capabilities/simulation.ts index 92b672c..3ce1a2c 100644 --- a/src/domains/seal/capabilities/simulation.ts +++ b/src/domains/seal/capabilities/simulation.ts @@ -5,7 +5,9 @@ import { readFileSync } from "node:fs"; import { formatBeijingIso } from "../../../core/config/timestamps.js"; import * as api from "../api.js"; import { - type SimulationBatch + type SimulationBatch, + SimulationRuleSourceInputSchema, + type SimulationRuleSourceInput } from "../types.js"; import * as helpers from "./helpers.js"; import { parseDurationMs } from "../../../core/duration.js"; @@ -85,16 +87,21 @@ export const simulationCapabilities = [ }, { name: "sealSimulationBatchCreate", - description: "创建 Seal 模拟测试批次。支持合思指定单号(hosecloud)与材料包导入(material_pack)两种模式;默认幂等:复用窗口内同 flow-ids/packageIds 的既有批次直接返回不重复扣费(--force 跳过);其他取数模式通过 rawParams 预留透传。", + description: "创建 Seal 模拟测试批次。支持合思指定单号(hosecloud)、每刻报销(maycur/maycur-standard)、泛微(weaver)、汇联易(helios)与材料包导入(material_pack)模式;默认以线上生效规则运行,支持 ruleSource.type=current 或 --draft 显式拍摄未发布草稿快照,或指定 ruleVersion 回溯已发布版本;默认幂等:复用窗口内同 flow-ids/packageIds 的既有批次直接返回不重复扣费(--force 跳过);其他取数模式通过 rawParams 预留透传。", parameters: z.object({ - mode: z.enum(["hosecloud", "material_pack"]).default("hosecloud").describe("来源模式: hosecloud=合思指定单号; material_pack=材料包导入"), - flowIds: z.array(z.string()).max(100).optional().describe("合思模式: 单据流水号列表"), + mode: z.enum(["hosecloud", "material_pack", "weaver", "helios", "maycur", "maycur-standard"]).default("hosecloud").describe("来源模式: hosecloud=合思指定单号; material_pack=材料包导入; weaver=泛微OA; helios=汇联易; maycur=每刻报销私有版; maycur-standard=每刻报销标准版"), + sourceSystem: z.string().optional().describe("来源系统,缺省同 mode"), + flowIds: z.array(z.string()).max(100).optional().describe("合思/通用单据流水号列表"), + documentSn: z.union([z.string(), z.array(z.string())]).optional().describe("单据编号(别名)"), + formCodes: z.array(z.string()).max(100).optional().describe("每刻报销单号列表"), rejectNodeName: z.string().nullable().optional().describe("仅关注特定节点: 节点名称, 不设为 null 表示不限制"), thinkingDepthOverride: z.enum(["default", "medium", "high"]).optional().describe("思考深度: default=按偏好设置, medium=标准, high=深度推理"), skipInvoiceGeneration: z.boolean().optional().describe("跳过发票生成, 默认 true"), skipExpenseExtraction: z.boolean().optional().describe("跳过后台历史费用明细库提取(防重报检索用), 默认 true"), disableAttachmentCache: z.boolean().optional().describe("不使用附件缓存, 默认 false"), - signKey: z.string().optional().describe("合思集成标识; 缺省时自动取第一个合思集成"), + ruleSource: SimulationRuleSourceInputSchema.optional().describe("规则来源: { type: 'current' } 或 { type: 'published', versionId: '...' }"), + ruleVersion: z.string().optional().describe("指定已发布规则版本 ID (等同于 ruleSource.type=published)"), + signKey: z.string().optional().describe("合思/每刻集成标识; 缺省时自动取对应集成"), packageIds: z.array(z.string()).optional().describe("材料包模式: 材料包 id 列表(来自 material-packages upload 响应)"), templateId: z.string().optional().describe("材料包模板 id, 例如 conference_reimbursement_v1; 缺省取 schemaConfig.id"), schemaConfig: z.record(z.string(), z.unknown()).optional().describe("材料包字段映射(确认参数), 建议使用 material-packages upload 返回的 schemaConfig"), @@ -106,13 +113,18 @@ export const simulationCapabilities = [ handler: async ( client: KyInstance, params: { - mode?: "hosecloud" | "material_pack"; + mode?: "hosecloud" | "material_pack" | "weaver" | "helios" | "maycur" | "maycur-standard"; + sourceSystem?: string; flowIds?: string[]; + documentSn?: string | string[]; + formCodes?: string[]; rejectNodeName?: string | null; thinkingDepthOverride?: "default" | "medium" | "high"; skipInvoiceGeneration?: boolean; skipExpenseExtraction?: boolean; disableAttachmentCache?: boolean; + ruleSource?: SimulationRuleSourceInput; + ruleVersion?: string; signKey?: string; packageIds?: string[]; templateId?: string; @@ -123,7 +135,7 @@ export const simulationCapabilities = [ rawParams?: Record; } ) => { - const mode = params.mode ?? "hosecloud"; + const mode = params.mode ?? (params.sourceSystem as typeof params.mode) ?? "hosecloud"; let signKey = params.signKey; if (mode === "hosecloud" && !signKey) { const integrations = await api.listSimulationHosecloudIntegrations(client); @@ -131,16 +143,27 @@ export const simulationCapabilities = [ if (!signKey) { throw validationError("未找到合思集成 signKey, 请通过 signKey 参数提供"); } + } else if (mode === "maycur" && !signKey) { + const integrations = await api.listSimulationMaycurPrivateIntegrations(client).catch(() => []); + signKey = integrations.find((item) => item.signKey)?.signKey; + } else if (mode === "maycur-standard" && !signKey) { + const integrations = await api.listSimulationMaycurStandardIntegrations(client).catch(() => []); + signKey = integrations.find((item) => item.signKey)?.signKey; } const payload = buildSimulationBatchParams({ mode, + sourceSystem: params.sourceSystem ?? mode, flowIds: params.flowIds, + documentSn: params.documentSn, + formCodes: params.formCodes, rejectNodeName: params.rejectNodeName, thinkingDepthOverride: params.thinkingDepthOverride, skipInvoiceGeneration: params.skipInvoiceGeneration, skipExpenseExtraction: params.skipExpenseExtraction, disableAttachmentCache: params.disableAttachmentCache, + ruleSource: params.ruleSource, + ruleVersion: params.ruleVersion, signKey, packageIds: params.packageIds, templateId: params.templateId, @@ -361,14 +384,16 @@ export const simulationCapabilities = [ }, { name: "sealSimulationIntegrationsGet", - description: "查询模拟测试可用的来源集成状态与合思集成选项(signKey 等)", + description: "查询模拟测试可用的来源集成状态与合思/每刻集成选项(signKey 等)", parameters: z.object({}), handler: async (client: KyInstance) => { - const [status, hosecloudIntegrations] = await Promise.all([ + const [status, hosecloudIntegrations, maycurPrivateIntegrations, maycurStandardIntegrations] = await Promise.all([ api.getSimulationIntegrationStatus(client), - api.listSimulationHosecloudIntegrations(client) + api.listSimulationHosecloudIntegrations(client).catch(() => []), + api.listSimulationMaycurPrivateIntegrations(client).catch(() => []), + api.listSimulationMaycurStandardIntegrations(client).catch(() => []) ]); - return { status, hosecloudIntegrations }; + return { status, hosecloudIntegrations, maycurPrivateIntegrations, maycurStandardIntegrations }; } }, { diff --git a/src/domains/seal/types.ts b/src/domains/seal/types.ts index d39a5c3..d509fc5 100644 --- a/src/domains/seal/types.ts +++ b/src/domains/seal/types.ts @@ -238,6 +238,9 @@ export const ApprovalRunSchema = z.object({ ruleSetVersionNumber: z.number().optional(), ruleSetPublishedAt: z.number().optional(), ruleSetPublishedByName: z.string().optional(), + ruleSetSnapshotCreatedAt: z.number().optional(), + thinkingDepthLevel: z.string().optional(), + durationMs: z.number().optional(), createdAt: z.union([z.string(), z.number()]).optional(), updatedAt: z.union([z.string(), z.number()]).optional() }).passthrough(); @@ -480,7 +483,9 @@ export const SimulationBatchParamsSchema = z.object({ packageIds: z.array(z.string()).optional(), packageLabel: z.string().optional(), runMode: z.string().optional(), - schemaConfig: SimulationSchemaConfigSchema.optional() + schemaConfig: SimulationSchemaConfigSchema.optional(), + ruleSource: z.unknown().optional(), + formCodes: z.array(z.string()).optional() }).passthrough(); export const SimulationRequestSummarySchema = z.object({ @@ -498,6 +503,34 @@ export const SimulationResultSummarySchema = z.object({ message: z.string().optional() }).passthrough(); +export const SimulationRuleSourceSchema = z.discriminatedUnion("type", [ + z.object({ + type: z.literal("snapshot"), + snapshotId: z.string(), + createdAt: z.number().optional() + }), + z.object({ + type: z.literal("published"), + versionId: z.string(), + versionNumber: z.number().optional() + }), + z.object({ + type: z.literal("current") + }) +]); +export type SimulationRuleSource = z.infer; + +export const SimulationRuleSourceInputSchema = z.discriminatedUnion("type", [ + z.object({ + type: z.literal("current") + }), + z.object({ + type: z.literal("published"), + versionId: z.string().min(1) + }) +]); +export type SimulationRuleSourceInput = z.infer; + export const SimulationBatchSchema = z.object({ id: z.string(), tenantId: z.string().optional(), @@ -514,6 +547,7 @@ export const SimulationBatchSchema = z.object({ params: SimulationBatchParamsSchema.optional(), requestSummary: SimulationRequestSummarySchema.nullable().optional(), resultSummary: SimulationResultSummarySchema.nullable().optional(), + ruleSource: SimulationRuleSourceSchema.optional(), createdAt: z.union([z.string(), z.number()]).optional(), updatedAt: z.union([z.string(), z.number()]).optional() }).passthrough(); @@ -556,6 +590,13 @@ export const SimulationHosecloudIntegrationSchema = z.object({ corporationId: z.string().optional() }).passthrough(); +export const SimulationMaycurIntegrationSchema = z.object({ + signKey: z.string(), + displayName: z.string(), + sourceSystem: z.enum(["maycur", "maycur-standard"]).optional() +}).passthrough(); +export type SimulationMaycurIntegration = z.infer; + export const MaterialPackageSchema = z.object({ id: z.string(), tenantId: z.string().optional(),