weaver-work-cli 0.1.73 → 0.1.75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -1
- package/dist/chunks/{archive-THZV4ND4.js → archive-OZJ6PYUR.js} +14 -9
- package/dist/chunks/{archive-oa-PQ23OLEV.js → archive-oa-BHL5RK2F.js} +10 -7
- package/dist/chunks/{asset-RGPROZYH.js → asset-HKRFRQR2.js} +10 -7
- package/dist/chunks/{asset-idle-Z2PDX7NA.js → asset-idle-GGIR4KE7.js} +7 -4
- package/dist/chunks/{attachment-content-R3RPVOYE.js → attachment-content-4OV65NK5.js} +3 -3
- package/dist/chunks/{blog-7U3QZPIF.js → blog-HYDP4DV3.js} +10 -7
- package/dist/chunks/{caizhilian-3AB42GCV.js → caizhilian-JS4RQZ6Z.js} +10 -7
- package/dist/chunks/{calendar-KINM64E4.js → calendar-SWRY4DIT.js} +10 -7
- package/dist/chunks/chunk-257JXJGD.js +30 -0
- package/dist/chunks/{chunk-LLCMOZ5L.js → chunk-2AUFKU2D.js} +11 -11
- package/dist/chunks/chunk-2BZ7TY4M.js +49 -0
- package/dist/chunks/{chunk-WM33BSIL.js → chunk-2QCCXPNU.js} +1 -1
- package/dist/chunks/{chunk-TV46Q4NY.js → chunk-4FCBEWNB.js} +74 -68
- package/dist/chunks/{chunk-NUP4RYZK.js → chunk-5D2V7ZAN.js} +2 -2
- package/dist/chunks/{chunk-DRUND2PJ.js → chunk-5QUTQHXF.js} +225 -152
- package/dist/chunks/{chunk-4BXR6CNB.js → chunk-5ZJGPEIB.js} +2 -2
- package/dist/chunks/chunk-7DE3VMZD.js +35 -0
- package/dist/chunks/chunk-BNKUHN4N.js +1346 -0
- package/dist/chunks/{chunk-2CHGUYMG.js → chunk-BSR5TM7U.js} +4 -4
- package/dist/chunks/{chunk-4I26YMBY.js → chunk-ERZY6GYL.js} +7 -3
- package/dist/chunks/{chunk-4YXAK6OA.js → chunk-FEZK536Z.js} +12 -7
- package/dist/chunks/{chunk-F4HM25K4.js → chunk-I6NOHKEK.js} +1 -1
- package/dist/chunks/{chunk-JMJBPP4B.js → chunk-J7FAAHWH.js} +2 -2
- package/dist/chunks/{chunk-54ST55IJ.js → chunk-JJONWB5N.js} +11 -1
- package/dist/chunks/chunk-JOY3HZXL.js +467 -0
- package/dist/chunks/{chunk-GWJLAF6B.js → chunk-JWF2R6EQ.js} +0 -462
- package/dist/chunks/{chunk-BWYVS62Z.js → chunk-KEA4XQPO.js} +4 -4
- package/dist/chunks/chunk-KINXYJXM.js +205 -0
- package/dist/chunks/{chunk-IBSJJGXL.js → chunk-KWJEICD4.js} +2 -2
- package/dist/chunks/{chunk-GAMGDNTF.js → chunk-LJI4N6FV.js} +1 -1
- package/dist/chunks/{chunk-IU6UB2TD.js → chunk-MXCRKXOP.js} +48 -6
- package/dist/chunks/{chunk-PAFOLIYQ.js → chunk-NWYHCZTY.js} +1 -1
- package/dist/chunks/chunk-OJ4JPD25.js +428 -0
- package/dist/chunks/{chunk-L7TYG5SN.js → chunk-OQCK5SAU.js} +2 -2
- package/dist/chunks/chunk-PG5YSNYY.js +1166 -0
- package/dist/chunks/{chunk-XZBYRYWX.js → chunk-QJWVYOOV.js} +2 -2
- package/dist/chunks/{chunk-AMAPQVBT.js → chunk-QVKRNL7L.js} +286 -305
- package/dist/chunks/chunk-SU6IJD6D.js +49 -0
- package/dist/chunks/{chunk-ZWLWXHJC.js → chunk-TA2RBUTH.js} +2 -2
- package/dist/chunks/{chunk-6HT73VOI.js → chunk-U6Y32KEV.js} +2 -2
- package/dist/chunks/chunk-UUJK76HV.js +209 -0
- package/dist/chunks/{chunk-R3MK2RBN.js → chunk-VOMDD2C5.js} +1 -1
- package/dist/chunks/chunk-Y3C6MDL7.js +28 -0
- package/dist/chunks/chunk-ZM7RN2IM.js +38 -0
- package/dist/chunks/{chunk-2XED2FKY.js → chunk-ZUB4M4N3.js} +38 -36
- package/dist/chunks/{chunk-7QFVXP2X.js → chunk-ZWIMLT6P.js} +8 -7
- package/dist/chunks/cli-FULPXIKJ.js +226 -0
- package/dist/chunks/commands-BNWFNTD3.js +70 -0
- package/dist/chunks/{conflict-VPAR7E6F.js → conflict-5BKCDV2F.js} +2 -2
- package/dist/chunks/{contract-DDXAO2DZ.js → contract-WI23OXVC.js} +12446 -5964
- package/dist/chunks/{cowork-34QCHMDD.js → cowork-DZBBVNMQ.js} +11 -8
- package/dist/chunks/{create-flow-52PU2OBI.js → create-flow-7ZRBRKX7.js} +6 -6
- package/dist/chunks/{data-CLQ62QGD.js → data-PAZVE6QE.js} +6 -3
- package/dist/chunks/{ebuilder-form-W5R7Q22S.js → ebuilder-form-5SQXIGXN.js} +9 -6
- package/dist/chunks/{ehr-LCNAVMK5.js → ehr-CX5F4ZAU.js} +23 -16
- package/dist/chunks/{entry-mode-6Z3ZV3DE.js → entry-mode-I2BYNONZ.js} +3 -3
- package/dist/chunks/{env-RDKWAARB.js → env-ZAQZ7EHN.js} +2 -2
- package/dist/chunks/{esb-ANKPUU65.js → esb-DQTXDIBF.js} +10 -7
- package/dist/chunks/{factory-434B7RAT.js → factory-XRI6KZ7H.js} +1 -1
- package/dist/chunks/{fna-AKBSG5HI.js → fna-FK6HQVJL.js} +13 -8
- package/dist/chunks/{group-chat-PROTW22R.js → group-chat-MLWNYM2P.js} +3 -3
- package/dist/chunks/{host-WO4L5G5I.js → host-3EPREGXS.js} +6 -3
- package/dist/chunks/{host-XIYG4F4B.js → host-J74JGYAW.js} +6 -3
- package/dist/chunks/{host-7FJW4E7R.js → host-KUMU3DDK.js} +6 -3
- package/dist/chunks/{host-5R2SNFWD.js → host-MEC4VQZA.js} +6 -3
- package/dist/chunks/{host-PDJAKCT7.js → host-T6NNQGVZ.js} +6 -3
- package/dist/chunks/{host-CGXUFQO4.js → host-VI7Q45PM.js} +6 -3
- package/dist/chunks/{hrm-WGODDTEH.js → hrm-KKVAW4P5.js} +8 -5
- package/dist/chunks/{im-YKTKAJU3.js → im-47CIWQNL.js} +7 -4
- package/dist/chunks/{invoice-PVYCCCVM.js → invoice-CDYRBNIG.js} +21 -16
- package/dist/chunks/{jiuchuanhui-RKOQW7BY.js → jiuchuanhui-M7QTRHZK.js} +17 -10
- package/dist/chunks/{lazy-dispatch-DW45AFQ5.js → lazy-dispatch-FKQJZFI5.js} +22 -8
- package/dist/chunks/{mail-BNB5S4NW.js → mail-NRBS5N6Y.js} +11 -8
- package/dist/chunks/{meeting-O2KDJH66.js → meeting-WC5LD3IO.js} +22 -18
- package/dist/chunks/{minute-doc-JUCG56GY.js → minute-doc-OQUMDTKG.js} +4 -4
- package/dist/chunks/{okr-LWFGWOE7.js → okr-EHKSKMPL.js} +10 -7
- package/dist/chunks/{operations-532PN5OB.js → operations-V5VM5MS2.js} +7 -4
- package/dist/chunks/{performance-7W5COCFU.js → performance-ZJADXJPN.js} +6 -3
- package/dist/chunks/{plan-ZVY3IYTL.js → plan-OTDNBDJ7.js} +10 -7
- package/dist/chunks/{project-SA62B7MH.js → project-4XVBQ3HX.js} +10 -7
- package/dist/chunks/{reception-NGIONPQ3.js → reception-3FAHOOH7.js} +8 -4
- package/dist/chunks/{recruit-stage-WOSN6MGP.js → recruit-stage-3WTVWW2K.js} +199 -74
- package/dist/chunks/register-SQOPIR2G.js +16 -0
- package/dist/chunks/{registry-R72GWXOG.js → registry-F4YFZLOD.js} +7 -3
- package/dist/chunks/registry-NBTBXR4L.js +30 -0
- package/dist/chunks/{registry-N7P3W2RD.js → registry-TJGCVRCW.js} +7 -4
- package/dist/chunks/{room-recommend-KCGIVUFR.js → room-recommend-KL62XB2Y.js} +4 -4
- package/dist/chunks/root-YZG2TS5W.js +16 -0
- package/dist/chunks/{schedule-6UP27HQ4.js → schedule-XOISYUPB.js} +4 -4
- package/dist/chunks/{smart-extract-DDOQSPRB.js → smart-extract-UYGNV3BM.js} +15 -7
- package/dist/chunks/update-AV5VOXGY.js +13 -0
- package/dist/chunks/{workflow-V5ALD6QZ.js → workflow-V54LJPXL.js} +15 -10
- package/dist/cli.js +40 -0
- package/dist/cmd/action.js +3 -1
- package/dist/cmd/doctor/index.js +1 -1
- package/dist/cmd/e10/index.js +1 -1
- package/dist/cmd/identity/index.js +5 -8
- package/dist/cmd/index.js +2 -0
- package/dist/cmd/setup/index.js +1 -1
- package/dist/cmd/update/index.js +38 -0
- package/dist/core/manifest-view.js +1 -1
- package/dist/core/output.js +8 -1
- package/dist/core/runtime-agent.js +13 -0
- package/dist/core/update-notice.js +23 -0
- package/dist/index.js +105 -198
- package/dist/internal/e10/auth/agent-host-key.js +16 -0
- package/dist/internal/e10/auth/agent-hosts.js +45 -9
- package/dist/internal/e10/auth/commands.js +66 -36
- package/dist/internal/e10/auth/session.js +30 -15
- package/dist/internal/e10/auth/xiaoe.js +4 -20
- package/dist/internal/e10/auth-recovery.js +44 -4
- package/dist/internal/e10/context.js +5 -2
- package/dist/internal/update/bootstrap.js +96 -0
- package/dist/internal/update/npm.js +78 -0
- package/dist/internal/update/service.js +252 -0
- package/dist/internal/update/store.js +135 -0
- package/dist/shortcuts/archive/index.js +2 -2
- package/dist/shortcuts/archive/manifest.js +1 -0
- package/dist/shortcuts/archive/operations/search.js +3 -1
- package/dist/shortcuts/archive-oa/index.js +1 -1
- package/dist/shortcuts/asset/index.js +1 -1
- package/dist/shortcuts/asset-idle/index.js +1 -1
- package/dist/shortcuts/blog/index.js +1 -1
- package/dist/shortcuts/caizhilian/index.js +1 -1
- package/dist/shortcuts/calendar/index.js +1 -1
- package/dist/shortcuts/contract/data/bi-config.js +156 -0
- package/dist/shortcuts/contract/data/collection-ledger-html.js +189 -0
- package/dist/shortcuts/contract/data/collection-node-catalog.js +226 -0
- package/dist/shortcuts/contract/data/metric-catalog.js +154 -20
- package/dist/shortcuts/contract/data/report-renderers.js +414 -0
- package/dist/shortcuts/contract/data/report-spec.js +132 -0
- package/dist/shortcuts/contract/error-actions.js +114 -0
- package/dist/shortcuts/contract/host.js +12 -3
- package/dist/shortcuts/contract/index.js +17 -1
- package/dist/shortcuts/contract/manifest.js +398 -3
- package/dist/shortcuts/contract/ooxml/docx-table.js +48 -0
- package/dist/shortcuts/contract/operations/bi-preview.js +131 -0
- package/dist/shortcuts/contract/operations/bizreview-report.js +496 -0
- package/dist/shortcuts/contract/operations/collection-node.js +229 -0
- package/dist/shortcuts/contract/operations/docx-slots.js +735 -16
- package/dist/shortcuts/contract/operations/draft-build.js +940 -0
- package/dist/shortcuts/contract/operations/draft-submit.js +229 -0
- package/dist/shortcuts/contract/operations/first-screen.js +3 -2
- package/dist/shortcuts/contract/operations/generated-submit.js +175 -0
- package/dist/shortcuts/contract/operations/ledger-report.js +233 -0
- package/dist/shortcuts/contract/operations/ledger-stat.js +1400 -0
- package/dist/shortcuts/contract/operations/ledger.js +4 -1
- package/dist/shortcuts/contract/operations/metrics.js +9 -3
- package/dist/shortcuts/contract/operations/ops-draft.js +527 -0
- package/dist/shortcuts/contract/operations/page.js +9 -0
- package/dist/shortcuts/contract/operations/quote-submit.js +55 -229
- package/dist/shortcuts/contract/operations/registry.js +20 -0
- package/dist/shortcuts/contract/operations/sign-launch.js +256 -0
- package/dist/shortcuts/contract/operations/viewlink.js +334 -0
- package/dist/shortcuts/cowork/index.js +2 -2
- package/dist/shortcuts/ebuilder-form/index.js +1 -1
- package/dist/shortcuts/ehr/index.js +2 -2
- package/dist/shortcuts/ehr/manifest.js +1 -1
- package/dist/shortcuts/ehr/operations/recruit-position.js +7 -2
- package/dist/shortcuts/ehr/operations/recruit-write.js +7 -6
- package/dist/shortcuts/ehr/operations/recruit.js +318 -248
- package/dist/shortcuts/ehr/operations/shared.js +22 -2
- package/dist/shortcuts/esb/index.js +1 -1
- package/dist/shortcuts/fna/index.js +1 -1
- package/dist/shortcuts/fna/manifest.js +1 -0
- package/dist/shortcuts/fna/operations/expense-chart.js +3 -1
- package/dist/shortcuts/hrm/index.js +1 -1
- package/dist/shortcuts/invoice/index.js +1 -1
- package/dist/shortcuts/jiuchuanhui/index.js +2 -2
- package/dist/shortcuts/jiuchuanhui/manifest.js +3 -0
- package/dist/shortcuts/mail/index.js +2 -2
- package/dist/shortcuts/meeting/index.js +1 -1
- package/dist/shortcuts/meeting/manifest.js +1 -0
- package/dist/shortcuts/meeting/operations/eb/catalog.js +5 -3
- package/dist/shortcuts/meeting/operations/eb/conflict.js +3 -1
- package/dist/shortcuts/meeting/operations/eb/create-flow.js +10 -9
- package/dist/shortcuts/meeting/operations/eb/factory.js +2 -0
- package/dist/shortcuts/meeting/operations/eb/member-expand.js +3 -2
- package/dist/shortcuts/meeting/operations/invitation-publish.js +3 -3
- package/dist/shortcuts/meeting/operations/invitation.js +4 -4
- package/dist/shortcuts/meeting/operations/link.js +3 -1
- package/dist/shortcuts/okr/index.js +1 -1
- package/dist/shortcuts/performance/index.js +1 -1
- package/dist/shortcuts/plan/index.js +1 -1
- package/dist/shortcuts/project/index.js +1 -1
- package/dist/shortcuts/reception/manifest.js +2 -2
- package/dist/shortcuts/recruit-stage/context.js +10 -2
- package/dist/shortcuts/recruit-stage/index.js +16 -3
- package/dist/shortcuts/recruit-stage/operations/interview-arrange.js +1 -1
- package/dist/shortcuts/recruit-stage/operations/interview-feedback.js +1 -1
- package/dist/shortcuts/recruit-stage/operations/jd-create.js +17 -8
- package/dist/shortcuts/recruit-stage/operations/list.js +1 -1
- package/dist/shortcuts/recruit-stage/operations/resume-import.js +178 -35
- package/dist/shortcuts/recruit-stage/operations/search.js +2 -2
- package/dist/shortcuts/recruit-stage/operations/shortlist.js +4 -2
- package/dist/shortcuts/recruit-stage/shared.js +27 -53
- package/dist/shortcuts/smart-extract/manifest.js +1 -0
- package/dist/shortcuts/smart-extract/operations/fill.js +7 -2
- package/dist/shortcuts/smart-extract/operations/validate.js +4 -1
- package/dist/shortcuts/workflow/index.js +2 -2
- package/dist/shortcuts/workflow/manifest.js +1 -0
- package/dist/shortcuts/workflow/operations/aiDeepRead/render.js +4 -1
- package/dist/shortcuts/workflow/operations/deepRead.js +23 -2
- package/dist/shortcuts/workflow/operations/form.js +8 -2
- package/docs/contract.md +6 -1
- package/docs/e10-auth.md +25 -7
- package/docs/operation-manual.md +15 -0
- package/package.json +2 -2
- package/scripts/pysite/__pycache__/sitecustomize.cpython-314.pyc +0 -0
- package/skill-template/business-info.json +28 -0
- package/skill-template/domains/jinchengda.md +13 -1
- package/skills/weaver-e10-archive-oa/references/source-manifest.json +3 -3
- package/skills/weaver-e10-caizhilian/references/auth-and-install.md +2 -1
- package/skills/weaver-e10-caizhilian/references/source-manifest.json +3 -3
- package/skills/weaver-e10-esb/references/source-manifest.json +3 -3
- package/skills/weaver-e10-jinchengda/SKILL.md +90 -32
- package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +45 -0
- package/skills/weaver-e10-jinchengda/references/contract-bizreview-report-template.html +68 -0
- package/skills/weaver-e10-jinchengda/references/contract-bizreview.md +216 -0
- package/skills/weaver-e10-jinchengda/references/contract-clause-negotiate.md +215 -0
- package/skills/weaver-e10-jinchengda/references/contract-collection-node.md +113 -0
- package/skills/weaver-e10-jinchengda/references/contract-command-index.md +19 -3
- package/skills/weaver-e10-jinchengda/references/contract-decisions.md +114 -0
- package/skills/weaver-e10-jinchengda/references/contract-doc-triage.md +53 -44
- package/skills/weaver-e10-jinchengda/references/contract-element-extract.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-field-extract-other-flows.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-firstscreen-guide.md +200 -0
- package/skills/weaver-e10-jinchengda/references/contract-ledger-catalog.md +18 -1
- package/skills/weaver-e10-jinchengda/references/contract-ledger-query-playbook.md +138 -3
- package/skills/weaver-e10-jinchengda/references/contract-ledger-report.md +158 -0
- package/skills/weaver-e10-jinchengda/references/contract-ledger-rules.md +3 -1
- package/skills/weaver-e10-jinchengda/references/contract-material-gap.md +139 -0
- package/skills/weaver-e10-jinchengda/references/contract-object-detect.md +2 -2
- package/skills/weaver-e10-jinchengda/references/contract-open-web-pages.md +10 -3
- package/skills/weaver-e10-jinchengda/references/contract-ops-draft.md +106 -0
- package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +176 -56
- package/skills/weaver-e10-jinchengda/references/contract-sign-launch.md +123 -0
- package/skills/weaver-e10-jinchengda/references/contract-smart-draft.md +410 -0
- package/skills/weaver-e10-jinchengda/references/contract-template-recommend.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-viewlink.md +110 -0
- package/skills/weaver-e10-jinchengda/references/orchestration.md +38 -24
- package/skills/weaver-e10-meeting/SKILL.md +13 -0
- package/skills/weaver-e10-okr/SKILL.md +11 -0
- package/skills/weaver-e10-okr/references/source-manifest.json +7 -6
- package/skills/weaver-e10-performance/SKILL.md +131 -39
- package/skills/weaver-e10-performance/agents/openai.yaml +48 -17
- package/skills/weaver-e10-performance/references/default-assembly.md +3 -0
- package/skills/weaver-e10-performance/references/extraction-guide.md +17 -3
- package/skills/weaver-e10-performance/references/flow-assess.md +38 -5
- package/skills/weaver-e10-performance/references/scheme-setting-page.md +20 -3
- package/skills/weaver-e10-performance/scripts/assemble_scheme.py +461 -0
- package/skills/weaver-e10-performance/scripts/parse_appraisal_doc.py +41 -0
- package/skills/weaver-e10-plan/SKILL.md +10 -0
- package/skills/weaver-e10-plan/references/source-manifest.json +13 -13
- package/skills/weaver-e10-qiyecheng/SKILL.md +2 -2
- package/skills/weaver-e10-qiyecheng/references/source-manifest.json +9 -9
- package/skills/weaver-e10-recruit-stage/SKILL.md +188 -169
- package/skills/weaver-e10-recruit-stage/agents/openai.yaml +55 -37
- package/skills/weaver-e10-recruit-stage/lib/interview-conflict.mjs +3 -0
- package/skills/weaver-e10-recruit-stage/lib/interview-summary.mjs +168 -35
- package/skills/weaver-e10-recruit-stage/lib/recruit-shortlist.mjs +175 -7
- package/skills/weaver-e10-recruit-stage/lib/recruit-write-helper.mjs +3 -0
- package/skills/weaver-e10-recruit-stage/lib/recruit-xiaoe-file.mjs +15 -1
- package/skills/weaver-e10-recruit-stage/lib/report-attachment.mjs +38 -0
- package/skills/weaver-e10-recruit-stage/lib/xiaoe-session.mjs +5 -1
- package/skills/weaver-e10-recruit-stage/references/env-fixed-values.md +4 -0
- package/skills/weaver-e10-recruit-stage/references/env-ziyong.md +4 -0
- package/skills/weaver-e10-recruit-stage/references/position-templates.md +12 -8
- package/skills/weaver-e10-recruit-stage/references/recruit-arrange-interview.md +16 -11
- package/skills/weaver-e10-recruit-stage/references/recruit-capability-check.md +10 -6
- package/skills/weaver-e10-recruit-stage/references/recruit-check-install.md +5 -1
- package/skills/weaver-e10-recruit-stage/references/recruit-detail-process.md +4 -0
- package/skills/weaver-e10-recruit-stage/references/recruit-edit-interview-feedback.md +7 -3
- package/skills/weaver-e10-recruit-stage/references/recruit-failure-fallback.md +6 -1
- package/skills/weaver-e10-recruit-stage/references/recruit-interview-not-attended.md +7 -3
- package/skills/weaver-e10-recruit-stage/references/recruit-jd-create.md +31 -23
- package/skills/weaver-e10-recruit-stage/references/recruit-jd-template.md +4 -0
- package/skills/weaver-e10-recruit-stage/references/recruit-list-candidate.md +4 -0
- package/skills/weaver-e10-recruit-stage/references/recruit-list-interview.md +5 -1
- package/skills/weaver-e10-recruit-stage/references/recruit-maint.md +4 -0
- package/skills/weaver-e10-recruit-stage/references/recruit-match-candidates.md +16 -10
- package/skills/weaver-e10-recruit-stage/references/recruit-my-positions.md +6 -2
- package/skills/weaver-e10-recruit-stage/references/recruit-output-links.md +147 -34
- package/skills/weaver-e10-recruit-stage/references/recruit-platform-compat.md +4 -0
- package/skills/weaver-e10-recruit-stage/references/recruit-report-templates.md +16 -4
- package/skills/weaver-e10-recruit-stage/references/recruit-resolve-creator.md +4 -0
- package/skills/weaver-e10-recruit-stage/references/recruit-resolve-metadata.md +8 -4
- package/skills/weaver-e10-recruit-stage/references/recruit-resume-import-batch.md +6 -2
- package/skills/weaver-e10-recruit-stage/references/recruit-resume-import.md +24 -15
- package/skills/weaver-e10-recruit-stage/references/recruit-resume-parse.md +7 -3
- package/skills/weaver-e10-recruit-stage/references/recruit-search-by-tag.md +7 -3
- package/skills/weaver-e10-recruit-stage/references/recruit-search-candidate.md +8 -4
- package/skills/weaver-e10-recruit-stage/references/recruit-tag-recommend.md +5 -1
- package/skills/weaver-e10-recruit-stage/references/recruit-urge-feedback.md +5 -1
- package/skills/weaver-e10-recruit-stage/references/recruit-utterance-glossary.md +5 -1
- package/skills/weaver-e10-recruit-stage/templates/candidate-evidence.html +41 -28
- package/skills/weaver-e10-recruit-stage/templates/interview-summary.html +23 -26
- package/skills/weaver-e10-recruit-stage/templates/match-report.html +32 -30
- package/skills/weaver-e10-shared/SKILL.md +40 -5
- package/skills/weaver-e10-shared/references/e10-auth-and-session.md +11 -1
- package/skills/weaver-e10-shared/references/json-output-contract.md +144 -8
- package/skills/weaver-e10-shared/references/weaver-e10-installation.md +11 -0
- package/skills/weaver-e10-shijingran/references/source-manifest.json +3 -3
- package/skills/weaver-e10-wenshuding/references/source-manifest.json +3 -3
- package/skills/weaver-e10-workflow/references/source-manifest.json +3 -3
- package/skills/weaver-e10-yepiaotong/references/source-manifest.json +5 -5
- package/dist/chunks/chunk-ICP53R52.js +0 -2849
- package/dist/chunks/registry-RIQ67ZT7.js +0 -27
|
@@ -0,0 +1,940 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { basename, dirname, resolve } from 'node:path';
|
|
3
|
+
import { contractValidationError } from '../errors.js';
|
|
4
|
+
import { encodeXml, parseTables } from '../ooxml/docx-table.js';
|
|
5
|
+
import { readZip, writeZip } from '../ooxml/zip.js';
|
|
6
|
+
import { validateXmlWellFormed } from './docx-slots.js';
|
|
7
|
+
import { findMoneyPlaceholder, hasCurrencySymbol, coerceAmount } from './money.js';
|
|
8
|
+
import { residueTextOfDocx, scanResidue, RESIDUE_PATTERNS } from './placeholder-scan.js';
|
|
9
|
+
import { rmbUpper } from './quote.js';
|
|
10
|
+
import { assertQuoteRefsResolved, resolveQuoteRefs } from './quote-ref.js';
|
|
11
|
+
/**
|
|
12
|
+
* ⑨ 智能起草(无模板):`contract.draft.build`。
|
|
13
|
+
*
|
|
14
|
+
* 与报价单链路的本质区别:
|
|
15
|
+
* - 报价单链路是「范文模板 + 位点回填」,**没有模板就不能生成**;
|
|
16
|
+
* - 起草链路没有模板,模型给出结构化合同大纲(当事人 / 条款 / 金额 / 付款 / 签署),
|
|
17
|
+
* 本文件直接用 OOXML 渲染 docx,并对产物做六类校验。两条链路互不复用。
|
|
18
|
+
*
|
|
19
|
+
* 交付判据:`data.ok === true` 且 `data.validate.fails` 为空。
|
|
20
|
+
* 校验口径与 `docx.slots.fill` 对齐(六类):结构完整 / 写入回读一致 / 金额勾稽 /
|
|
21
|
+
* 表格结构未变 / XML 良构 / 占位符残留为 0。
|
|
22
|
+
*
|
|
23
|
+
* 红线:
|
|
24
|
+
* 1. 不读任何模板、不跑 `recommend.doc`、不跑 `triage.extract`;
|
|
25
|
+
* 2. 金额只接受纯数值或可唯一归一的字符串;脱敏占位符与 `¥144,000.00` 这类展示文本
|
|
26
|
+
* 一律在写盘前拒收(`[[MONEY_*]]` 在本地没有还原环节,写进合同就是残次品);
|
|
27
|
+
* 3. 渲染失败如实报 `draft_docx_invalid` 并停止,不手工拼 XML 兜底。
|
|
28
|
+
*/
|
|
29
|
+
const DEFAULT_OUR_COMPANY = '泛微网络科技股份有限公司';
|
|
30
|
+
const GENERIC_TITLES = new Set(['合同', '合同文件', '未命名', 'document', 'new', '模板', 'temp', 'output']);
|
|
31
|
+
const TOTAL_TABLE_WIDTH = 9000;
|
|
32
|
+
// ---------------------------------------------------------------- 基础工具
|
|
33
|
+
function str(value) {
|
|
34
|
+
if (typeof value === 'string')
|
|
35
|
+
return value.trim();
|
|
36
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
37
|
+
return String(value);
|
|
38
|
+
return '';
|
|
39
|
+
}
|
|
40
|
+
function isRecord(value) {
|
|
41
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
42
|
+
}
|
|
43
|
+
function round2(value) {
|
|
44
|
+
return Math.round((value + Number.EPSILON) * 100) / 100;
|
|
45
|
+
}
|
|
46
|
+
function formatMoney(value) {
|
|
47
|
+
return value.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
48
|
+
}
|
|
49
|
+
function formatQty(value) {
|
|
50
|
+
return Number.isInteger(value) ? String(value) : String(value);
|
|
51
|
+
}
|
|
52
|
+
function formatPercent(value) {
|
|
53
|
+
return Number.isInteger(value) ? String(value) : String(round2(value));
|
|
54
|
+
}
|
|
55
|
+
function singleLine(text) {
|
|
56
|
+
return text.replace(/\r\n?/gu, '\n').replace(/\n+/gu, ' ').trim();
|
|
57
|
+
}
|
|
58
|
+
// ---------------------------------------------------------------- 入参守门
|
|
59
|
+
/** 文本字段:统一单行化,并在写盘前拦住脱敏金额占位符。 */
|
|
60
|
+
function textOf(value, field) {
|
|
61
|
+
const text = singleLine(str(value));
|
|
62
|
+
const token = findMoneyPlaceholder(text);
|
|
63
|
+
if (token) {
|
|
64
|
+
throw contractValidationError('draft_text_placeholder', `${field} 里含脱敏占位符「${token}」。本地进程没有任何还原环节,写进合同就是残次品;`
|
|
65
|
+
+ '请换成真实取值后重跑(金额一律走 amount 字段,不要写进正文)。', { field, placeholder: token });
|
|
66
|
+
}
|
|
67
|
+
return text;
|
|
68
|
+
}
|
|
69
|
+
function textList(value, field) {
|
|
70
|
+
if (!Array.isArray(value))
|
|
71
|
+
return [];
|
|
72
|
+
const out = [];
|
|
73
|
+
value.forEach((item, index) => {
|
|
74
|
+
const text = textOf(item, `${field}[${index}]`);
|
|
75
|
+
if (text)
|
|
76
|
+
out.push(text);
|
|
77
|
+
});
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 金额字段:只接受纯数值或能唯一归一的字符串。
|
|
82
|
+
*
|
|
83
|
+
* 三种拒收各有专用错误码,避免模型把「形态非法」读成「金额不可得」:
|
|
84
|
+
* - 脱敏占位符 → draft_amount_placeholder;
|
|
85
|
+
* - 带货币符号的展示文本 → draft_amount_display_text;
|
|
86
|
+
* - 其它非数值 → draft_amount_not_numeric。
|
|
87
|
+
*/
|
|
88
|
+
function amountOf(value, field, options = {}) {
|
|
89
|
+
if (value === undefined || value === null || value === '')
|
|
90
|
+
return null;
|
|
91
|
+
const raw = typeof value === 'string' ? value.trim() : String(value);
|
|
92
|
+
const placeholder = findMoneyPlaceholder(value);
|
|
93
|
+
if (placeholder) {
|
|
94
|
+
throw contractValidationError('draft_amount_placeholder', `${field} 是平台脱敏占位符「${placeholder}」。它在模型上下文里是真实金额的等价表示,`
|
|
95
|
+
+ '但本地进程收到的是字面量、没有还原环节,不能写进合同。正确动作:改传纯数值(如 809166.76)重跑。'
|
|
96
|
+
+ '⚠️ 这不是「金额拿不到」,不要据此向用户索要金额、也不要宣告链路失败。', { field, placeholder, raw });
|
|
97
|
+
}
|
|
98
|
+
if (hasCurrencySymbol(value)) {
|
|
99
|
+
throw contractValidationError('draft_amount_display_text', `${field} 带货币符号「${raw}」。金额字段只收纯数值,去掉 ¥ / $ 等符号后重跑。`, { field, raw });
|
|
100
|
+
}
|
|
101
|
+
const amount = coerceAmount(value);
|
|
102
|
+
if (amount === null) {
|
|
103
|
+
throw contractValidationError('draft_amount_not_numeric', `${field} 必须是数值或纯数字字符串,收到「${raw}」`, { field, raw });
|
|
104
|
+
}
|
|
105
|
+
if (options.positive && amount <= 0) {
|
|
106
|
+
throw contractValidationError('draft_amount_not_positive', `${field} 必须大于 0(收到 ${amount})。金额确实未定时整块不要传,不要用 0 或负数占位。`, { field, amount });
|
|
107
|
+
}
|
|
108
|
+
return amount;
|
|
109
|
+
}
|
|
110
|
+
/** 付款比例:接受 30、30%、"30 %";超出 0~100 视为非法。 */
|
|
111
|
+
function percentOf(value, field) {
|
|
112
|
+
if (value === undefined || value === null || value === '')
|
|
113
|
+
return null;
|
|
114
|
+
if (typeof value === 'number') {
|
|
115
|
+
if (!Number.isFinite(value) || value < 0 || value > 100) {
|
|
116
|
+
throw contractValidationError('draft_amount_not_numeric', `${field} 必须是 0~100 的比例,收到 ${value}`, { field });
|
|
117
|
+
}
|
|
118
|
+
return value;
|
|
119
|
+
}
|
|
120
|
+
const text = String(value).trim().replace(/%$/u, '').trim();
|
|
121
|
+
const num = coerceAmount(text);
|
|
122
|
+
if (num === null || num < 0 || num > 100) {
|
|
123
|
+
throw contractValidationError('draft_amount_not_numeric', `${field} 必须是 0~100 的比例(可写成 30 或 30%),收到「${String(value)}」`, { field });
|
|
124
|
+
}
|
|
125
|
+
return num;
|
|
126
|
+
}
|
|
127
|
+
function partyOf(value, field) {
|
|
128
|
+
const info = { name: '', address: '', contact: '', phone: '', email: '', bank: '', account: '' };
|
|
129
|
+
if (value === undefined || value === null || value === '')
|
|
130
|
+
return info;
|
|
131
|
+
if (typeof value === 'string') {
|
|
132
|
+
info.name = textOf(value, field);
|
|
133
|
+
return info;
|
|
134
|
+
}
|
|
135
|
+
if (!isRecord(value)) {
|
|
136
|
+
throw contractValidationError('draft_party_required', `${field} 必须是当事人全称或其信息对象`, { field });
|
|
137
|
+
}
|
|
138
|
+
info.name = textOf(value.name, `${field}.name`);
|
|
139
|
+
info.address = textOf(value.address, `${field}.address`);
|
|
140
|
+
info.contact = textOf(value.contact, `${field}.contact`);
|
|
141
|
+
info.phone = textOf(value.phone, `${field}.phone`);
|
|
142
|
+
info.email = textOf(value.email, `${field}.email`);
|
|
143
|
+
info.bank = textOf(value.bank, `${field}.bank`);
|
|
144
|
+
info.account = textOf(value.account, `${field}.account`);
|
|
145
|
+
return info;
|
|
146
|
+
}
|
|
147
|
+
function parseItem(value, articleIndex, itemIndex) {
|
|
148
|
+
const field = `articles[${articleIndex}].items[${itemIndex}]`;
|
|
149
|
+
if (!isRecord(value)) {
|
|
150
|
+
throw contractValidationError('draft_article_empty', `${field} 必须是明细行对象`, { field });
|
|
151
|
+
}
|
|
152
|
+
const item = {
|
|
153
|
+
name: textOf(value.name, `${field}.name`),
|
|
154
|
+
spec: textOf(value.spec, `${field}.spec`),
|
|
155
|
+
unit: textOf(value.unit, `${field}.unit`),
|
|
156
|
+
qty: amountOf(value.qty, `${field}.qty`),
|
|
157
|
+
price: amountOf(value.price, `${field}.price`),
|
|
158
|
+
amount: amountOf(value.amount, `${field}.amount`),
|
|
159
|
+
amountComputed: false,
|
|
160
|
+
};
|
|
161
|
+
if (item.amount === null && item.qty !== null && item.price !== null) {
|
|
162
|
+
item.amount = round2(item.qty * item.price);
|
|
163
|
+
item.amountComputed = true;
|
|
164
|
+
}
|
|
165
|
+
if (!item.name && !item.spec && item.amount === null)
|
|
166
|
+
return null;
|
|
167
|
+
return item;
|
|
168
|
+
}
|
|
169
|
+
function parseTable(value, field, warnings) {
|
|
170
|
+
if (value === undefined || value === null)
|
|
171
|
+
return null;
|
|
172
|
+
if (!isRecord(value)) {
|
|
173
|
+
warnings.push(`${field} 不是对象,已忽略`);
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
const headers = Array.isArray(value.headers)
|
|
177
|
+
? value.headers.map((header, index) => textOf(header, `${field}.headers[${index}]`)).filter(Boolean)
|
|
178
|
+
: [];
|
|
179
|
+
const rawRows = Array.isArray(value.rows) ? value.rows : [];
|
|
180
|
+
const rows = [];
|
|
181
|
+
rawRows.forEach((row, rowIndex) => {
|
|
182
|
+
if (!Array.isArray(row)) {
|
|
183
|
+
warnings.push(`${field}.rows[${rowIndex}] 不是数组,已忽略`);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
rows.push(row.map((cell, cellIndex) => textOf(cell, `${field}.rows[${rowIndex}][${cellIndex}]`)));
|
|
187
|
+
});
|
|
188
|
+
if (!headers.length && !rows.length)
|
|
189
|
+
return null;
|
|
190
|
+
const width = headers.length || Math.max(...rows.map((row) => row.length), 0);
|
|
191
|
+
const finalHeaders = headers.length
|
|
192
|
+
? headers
|
|
193
|
+
: Array.from({ length: width }, (_, index) => `列${index + 1}`);
|
|
194
|
+
const normalized = rows.map((row) => {
|
|
195
|
+
if (row.length === width)
|
|
196
|
+
return row;
|
|
197
|
+
warnings.push(`${field} 有一行列数 ${row.length} 与表头 ${width} 不一致,已按表头补齐/截断`);
|
|
198
|
+
return Array.from({ length: width }, (_, index) => row[index] ?? '');
|
|
199
|
+
});
|
|
200
|
+
return { headers: finalHeaders, rows: normalized };
|
|
201
|
+
}
|
|
202
|
+
function parseArticle(value, index, warnings) {
|
|
203
|
+
if (!isRecord(value)) {
|
|
204
|
+
throw contractValidationError('draft_articles_required', `articles[${index}] 必须是条款对象(含 heading)`, { index });
|
|
205
|
+
}
|
|
206
|
+
const heading = textOf(value.heading, `articles[${index}].heading`);
|
|
207
|
+
if (!heading) {
|
|
208
|
+
throw contractValidationError('draft_article_heading_required', `articles[${index}] 缺少 heading(如「第一条 合同标的」)`, { index });
|
|
209
|
+
}
|
|
210
|
+
const items = Array.isArray(value.items)
|
|
211
|
+
? value.items
|
|
212
|
+
.map((item, itemIndex) => parseItem(item, index, itemIndex))
|
|
213
|
+
.filter((item) => item !== null)
|
|
214
|
+
: [];
|
|
215
|
+
const table = parseTable(value.table, `articles[${index}].table`, warnings);
|
|
216
|
+
const paragraphs = textList(value.paragraphs, `articles[${index}].paragraphs`);
|
|
217
|
+
const notes = textList(value.notes, `articles[${index}].notes`);
|
|
218
|
+
if (!paragraphs.length && !items.length && !table && !notes.length) {
|
|
219
|
+
throw contractValidationError('draft_article_empty', `articles[${index}]「${heading}」没有任何内容:至少要有 paragraphs / items / table / notes 之一`, { index, heading });
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
heading,
|
|
223
|
+
paragraphs,
|
|
224
|
+
itemsTitle: textOf(value.itemsTitle, `articles[${index}].itemsTitle`),
|
|
225
|
+
items,
|
|
226
|
+
table,
|
|
227
|
+
notes,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
// ---------------------------------------------------------------- 目录模型
|
|
231
|
+
function buildModel(input) {
|
|
232
|
+
const warnings = [];
|
|
233
|
+
const title = textOf(input.title, 'title');
|
|
234
|
+
if (!title) {
|
|
235
|
+
throw contractValidationError('draft_title_required', '缺少 title(合同名称)。合同名称要能辨识对方主体与标的,不要用「合同」这类通用名。');
|
|
236
|
+
}
|
|
237
|
+
if (GENERIC_TITLES.has(title.toLowerCase())) {
|
|
238
|
+
warnings.push(`title「${title}」是通用名,上传到 E10 后无法辨识客户与标的;建议改成「{客户全称}{标的}购买合同」`);
|
|
239
|
+
}
|
|
240
|
+
const outInput = singleLine(str(input.out));
|
|
241
|
+
if (!outInput) {
|
|
242
|
+
throw contractValidationError('draft_out_required', '缺少 out(输出 docx 绝对路径)');
|
|
243
|
+
}
|
|
244
|
+
if (!/\.docx$/iu.test(outInput)) {
|
|
245
|
+
throw contractValidationError('draft_out_not_docx', `out 必须以 .docx 结尾,收到「${outInput}」`);
|
|
246
|
+
}
|
|
247
|
+
const outPath = resolve(outInput);
|
|
248
|
+
const ourParty = partyOf(input.ourParty, 'ourParty');
|
|
249
|
+
if (!ourParty.name)
|
|
250
|
+
ourParty.name = DEFAULT_OUR_COMPANY;
|
|
251
|
+
const counterParty = partyOf(input.counterParty, 'counterParty');
|
|
252
|
+
if (!counterParty.name) {
|
|
253
|
+
throw contractValidationError('draft_party_required', '缺少对方当事人全称(counterParty)。对方全称缺失时向用户问一次,不要编造。');
|
|
254
|
+
}
|
|
255
|
+
const metaInput = isRecord(input.meta) ? input.meta : {};
|
|
256
|
+
const meta = {
|
|
257
|
+
contractNo: textOf(metaInput.contractNo, 'meta.contractNo'),
|
|
258
|
+
signDate: textOf(metaInput.signDate, 'meta.signDate'),
|
|
259
|
+
signPlace: textOf(metaInput.signPlace, 'meta.signPlace'),
|
|
260
|
+
effectiveDate: textOf(metaInput.effectiveDate, 'meta.effectiveDate'),
|
|
261
|
+
};
|
|
262
|
+
const preamble = Array.isArray(input.preamble)
|
|
263
|
+
? input.preamble
|
|
264
|
+
.map((block, index) => textOf(block, `preamble[${index}]`))
|
|
265
|
+
.filter(Boolean)
|
|
266
|
+
: (() => {
|
|
267
|
+
const text = textOf(input.preamble, 'preamble');
|
|
268
|
+
return text ? text.split(/\n\s*\n/gu).map((block) => singleLine(block)).filter(Boolean) : [];
|
|
269
|
+
})();
|
|
270
|
+
const recitals = textList(input.recitals, 'recitals');
|
|
271
|
+
const rawArticles = Array.isArray(input.articles) ? input.articles : [];
|
|
272
|
+
if (!rawArticles.length) {
|
|
273
|
+
throw contractValidationError('draft_articles_required', '缺少 articles(至少一条条款)。条款内容由模型按用户需求起草,不要向用户索要模板。');
|
|
274
|
+
}
|
|
275
|
+
const articles = rawArticles.map((article, index) => parseArticle(article, index, warnings));
|
|
276
|
+
// ── 金额:sections 可推导 total;两者都无则不写金额章节
|
|
277
|
+
const amountInput = isRecord(input.amount) ? input.amount : {};
|
|
278
|
+
let total = amountOf(amountInput.total, 'amount.total', { positive: true });
|
|
279
|
+
const sections = [];
|
|
280
|
+
if (Array.isArray(amountInput.sections)) {
|
|
281
|
+
amountInput.sections.forEach((section, index) => {
|
|
282
|
+
if (!isRecord(section)) {
|
|
283
|
+
warnings.push(`amount.sections[${index}] 不是对象,已忽略`);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const name = textOf(section.name, `amount.sections[${index}].name`);
|
|
287
|
+
const amount = amountOf(section.amount, `amount.sections[${index}].amount`);
|
|
288
|
+
if (amount === null) {
|
|
289
|
+
warnings.push(`amount.sections[${index}] 缺少金额,已忽略`);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
sections.push({ name: name || `费用项目${index + 1}`, amount });
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
if (total === null && sections.length)
|
|
296
|
+
total = round2(sections.reduce((sum, section) => sum + section.amount, 0));
|
|
297
|
+
const inWords = textOf(amountInput.inWords, 'amount.inWords') || (total !== null ? rmbUpper(String(total)) : '');
|
|
298
|
+
const taxRate = textOf(amountInput.taxRate, 'amount.taxRate');
|
|
299
|
+
// ── 付款
|
|
300
|
+
const paymentInput = isRecord(input.payment) ? input.payment : {};
|
|
301
|
+
const paymentTerms = textList(paymentInput.terms, 'payment.terms');
|
|
302
|
+
const installments = [];
|
|
303
|
+
if (Array.isArray(paymentInput.installments)) {
|
|
304
|
+
paymentInput.installments.forEach((raw, index) => {
|
|
305
|
+
if (!isRecord(raw)) {
|
|
306
|
+
warnings.push(`payment.installments[${index}] 不是对象,已忽略`);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const installment = {
|
|
310
|
+
label: textOf(raw.label, `payment.installments[${index}].label`),
|
|
311
|
+
percent: percentOf(raw.percent, `payment.installments[${index}].percent`),
|
|
312
|
+
amount: amountOf(raw.amount, `payment.installments[${index}].amount`),
|
|
313
|
+
dueDate: textOf(raw.dueDate, `payment.installments[${index}].dueDate`),
|
|
314
|
+
};
|
|
315
|
+
// 只给比例时按总额折算金额;只给金额时按总额反算比例(均为展示值,不改变用户口径)
|
|
316
|
+
if (installment.amount === null && installment.percent !== null && total !== null) {
|
|
317
|
+
installment.amount = round2((total * installment.percent) / 100);
|
|
318
|
+
}
|
|
319
|
+
if (installment.percent === null && installment.amount !== null && total !== null && total > 0) {
|
|
320
|
+
installment.percent = round2((installment.amount / total) * 100);
|
|
321
|
+
}
|
|
322
|
+
if (installment.amount === null && installment.percent === null) {
|
|
323
|
+
warnings.push(`payment.installments[${index}] 既没有金额也没有比例,无法核对付款计划`);
|
|
324
|
+
}
|
|
325
|
+
installments.push(installment);
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
const signaturesInput = isRecord(input.signatures) ? input.signatures : {};
|
|
329
|
+
const signatures = {
|
|
330
|
+
ourSigner: textOf(signaturesInput.ourSigner, 'signatures.ourSigner'),
|
|
331
|
+
counterSigner: textOf(signaturesInput.counterSigner, 'signatures.counterSigner'),
|
|
332
|
+
datePlace: textOf(signaturesInput.datePlace, 'signatures.datePlace'),
|
|
333
|
+
};
|
|
334
|
+
return {
|
|
335
|
+
title,
|
|
336
|
+
outPath,
|
|
337
|
+
ourParty,
|
|
338
|
+
counterParty,
|
|
339
|
+
meta,
|
|
340
|
+
preamble,
|
|
341
|
+
recitals,
|
|
342
|
+
articles,
|
|
343
|
+
total,
|
|
344
|
+
inWords,
|
|
345
|
+
taxRate,
|
|
346
|
+
sections,
|
|
347
|
+
paymentTerms,
|
|
348
|
+
installments,
|
|
349
|
+
signatures,
|
|
350
|
+
attachments: textList(input.attachments, 'attachments'),
|
|
351
|
+
notes: textList(input.notes, 'notes'),
|
|
352
|
+
warnings,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function runXml(text, options = {}) {
|
|
356
|
+
const props = [];
|
|
357
|
+
if (options.bold)
|
|
358
|
+
props.push('<w:b/><w:bCs/>');
|
|
359
|
+
if (options.size)
|
|
360
|
+
props.push(`<w:sz w:val="${options.size}"/><w:szCs w:val="${options.size}"/>`);
|
|
361
|
+
const rPr = props.length ? `<w:rPr>${props.join('')}</w:rPr>` : '';
|
|
362
|
+
return `<w:r>${rPr}<w:t xml:space="preserve">${encodeXml(text)}</w:t></w:r>`;
|
|
363
|
+
}
|
|
364
|
+
function paraXml(text, options = {}) {
|
|
365
|
+
const pPr = [];
|
|
366
|
+
const spacing = [];
|
|
367
|
+
if (options.before !== undefined)
|
|
368
|
+
spacing.push(`w:before="${options.before}"`);
|
|
369
|
+
if (options.after !== undefined)
|
|
370
|
+
spacing.push(`w:after="${options.after}"`);
|
|
371
|
+
if (options.line)
|
|
372
|
+
spacing.push(`w:line="${options.line}" w:lineRule="auto"`);
|
|
373
|
+
if (spacing.length)
|
|
374
|
+
pPr.push(`<w:spacing ${spacing.join(' ')}/>`);
|
|
375
|
+
if (options.firstLine)
|
|
376
|
+
pPr.push('<w:ind w:firstLineChars="200" w:firstLine="420"/>');
|
|
377
|
+
if (options.align)
|
|
378
|
+
pPr.push(`<w:jc w:val="${options.align}"/>`);
|
|
379
|
+
if (options.keepNext)
|
|
380
|
+
pPr.push('<w:keepNext/>');
|
|
381
|
+
return `<w:p>${pPr.length ? `<w:pPr>${pPr.join('')}</w:pPr>` : ''}${runXml(text, options)}</w:p>`;
|
|
382
|
+
}
|
|
383
|
+
function emptyPara() {
|
|
384
|
+
return '<w:p/>';
|
|
385
|
+
}
|
|
386
|
+
function distribute(width, columns) {
|
|
387
|
+
if (columns <= 0)
|
|
388
|
+
return [];
|
|
389
|
+
const base = Math.floor(width / columns);
|
|
390
|
+
const remainder = width - base * columns;
|
|
391
|
+
return Array.from({ length: columns }, (_, index) => base + (index < remainder ? 1 : 0));
|
|
392
|
+
}
|
|
393
|
+
const BORDERED = '<w:tblBorders>'
|
|
394
|
+
+ '<w:top w:val="single" w:sz="4" w:space="0" w:color="000000"/>'
|
|
395
|
+
+ '<w:left w:val="single" w:sz="4" w:space="0" w:color="000000"/>'
|
|
396
|
+
+ '<w:bottom w:val="single" w:sz="4" w:space="0" w:color="000000"/>'
|
|
397
|
+
+ '<w:right w:val="single" w:sz="4" w:space="0" w:color="000000"/>'
|
|
398
|
+
+ '<w:insideH w:val="single" w:sz="4" w:space="0" w:color="000000"/>'
|
|
399
|
+
+ '<w:insideV w:val="single" w:sz="4" w:space="0" w:color="000000"/>'
|
|
400
|
+
+ '</w:tblBorders>';
|
|
401
|
+
const BORDERLESS = '<w:tblBorders>'
|
|
402
|
+
+ '<w:top w:val="none" w:sz="0" w:space="0" w:color="auto"/>'
|
|
403
|
+
+ '<w:left w:val="none" w:sz="0" w:space="0" w:color="auto"/>'
|
|
404
|
+
+ '<w:bottom w:val="none" w:sz="0" w:space="0" w:color="auto"/>'
|
|
405
|
+
+ '<w:right w:val="none" w:sz="0" w:space="0" w:color="auto"/>'
|
|
406
|
+
+ '<w:insideH w:val="none" w:sz="0" w:space="0" w:color="auto"/>'
|
|
407
|
+
+ '<w:insideV w:val="none" w:sz="0" w:space="0" w:color="auto"/>'
|
|
408
|
+
+ '</w:tblBorders>';
|
|
409
|
+
function cellXml(text, width, options = {}) {
|
|
410
|
+
const shade = options.header ? '<w:shd w:val="clear" w:color="auto" w:fill="F2F2F2"/>' : '';
|
|
411
|
+
return '<w:tc><w:tcPr>'
|
|
412
|
+
+ `<w:tcW w:w="${width}" w:type="dxa"/>${shade}<w:vAlign w:val="center"/>`
|
|
413
|
+
+ '</w:tcPr>'
|
|
414
|
+
+ paraXml(text, { size: options.fontSize ?? 18, after: 0, line: 240, bold: options.header })
|
|
415
|
+
+ '</w:tc>';
|
|
416
|
+
}
|
|
417
|
+
function tableXml(headers, rows, options = {}) {
|
|
418
|
+
const columns = headers.length;
|
|
419
|
+
const widths = options.widths && options.widths.length === columns
|
|
420
|
+
? options.widths
|
|
421
|
+
: distribute(TOTAL_TABLE_WIDTH, columns);
|
|
422
|
+
const grid = widths.map((width) => `<w:gridCol w:w="${width}"/>`).join('');
|
|
423
|
+
const borders = options.border === false ? BORDERLESS : BORDERED;
|
|
424
|
+
const headerRow = '<w:tr><w:trPr><w:tblHeader/></w:trPr>'
|
|
425
|
+
+ headers.map((header, index) => cellXml(header, widths[index], { ...options, header: true })).join('')
|
|
426
|
+
+ '</w:tr>';
|
|
427
|
+
const bodyRows = rows.map((row) => '<w:tr>'
|
|
428
|
+
+ widths
|
|
429
|
+
.map((width, index) => cellXml(row[index] ?? '', width, options))
|
|
430
|
+
.join('')
|
|
431
|
+
+ '</w:tr>').join('');
|
|
432
|
+
return '<w:tbl><w:tblPr>'
|
|
433
|
+
+ '<w:tblW w:w="0" w:type="auto"/>'
|
|
434
|
+
+ `<w:jc w:val="center"/>${borders}<w:tblLayout w:type="fixed"/>`
|
|
435
|
+
+ '</w:tblPr>'
|
|
436
|
+
+ `<w:tblGrid>${grid}</w:tblGrid>${headerRow}${bodyRows}</w:tbl>`;
|
|
437
|
+
}
|
|
438
|
+
const ARCHIVE_HEADERS = ['序号', '名称', '规格型号', '单位', '数量', '单价(元)', '金额(元)'];
|
|
439
|
+
const ARCHIVE_WIDTHS = [700, 2200, 1800, 700, 900, 1350, 1350];
|
|
440
|
+
function defaultPreamble(model) {
|
|
441
|
+
const raw = model.title.replace(/\.docx$/iu, '');
|
|
442
|
+
const withoutCustomer = raw.includes(model.counterParty.name) ? raw.split(model.counterParty.name).join('').trim() : raw;
|
|
443
|
+
const subject = withoutCustomer.replace(/(?:购买)?合同$/iu, '').trim() || '软件产品及实施服务';
|
|
444
|
+
return `${model.counterParty.name}(以下简称“甲方”)与${model.ourParty.name}(以下简称“乙方”)`
|
|
445
|
+
+ `经友好协商,就甲方向乙方采购${subject}事宜达成如下协议,以资共同遵守:`;
|
|
446
|
+
}
|
|
447
|
+
function partyLines(roleLabel, party) {
|
|
448
|
+
const lines = [`${roleLabel}:${party.name}`];
|
|
449
|
+
if (party.address)
|
|
450
|
+
lines.push(`地址:${party.address}`);
|
|
451
|
+
if (party.contact)
|
|
452
|
+
lines.push(`联系人:${party.contact}`);
|
|
453
|
+
if (party.phone)
|
|
454
|
+
lines.push(`电话:${party.phone}`);
|
|
455
|
+
if (party.email)
|
|
456
|
+
lines.push(`邮箱:${party.email}`);
|
|
457
|
+
if (party.bank)
|
|
458
|
+
lines.push(`开户银行:${party.bank}`);
|
|
459
|
+
if (party.account)
|
|
460
|
+
lines.push(`银行账号:${party.account}`);
|
|
461
|
+
return lines;
|
|
462
|
+
}
|
|
463
|
+
function renderDraft(model) {
|
|
464
|
+
const body = [];
|
|
465
|
+
const tables = [];
|
|
466
|
+
const required = [];
|
|
467
|
+
const written = [];
|
|
468
|
+
const itemAmounts = [];
|
|
469
|
+
const need = (value) => {
|
|
470
|
+
const text = singleLine(value);
|
|
471
|
+
if (text)
|
|
472
|
+
required.push(text);
|
|
473
|
+
};
|
|
474
|
+
const write = (value) => {
|
|
475
|
+
const text = singleLine(value);
|
|
476
|
+
if (text)
|
|
477
|
+
written.push(text);
|
|
478
|
+
};
|
|
479
|
+
// ── 标题与合同元信息
|
|
480
|
+
body.push(paraXml(model.title, { align: 'center', bold: true, size: 36, after: 240, line: 360 }));
|
|
481
|
+
need(model.title);
|
|
482
|
+
const metaLines = [];
|
|
483
|
+
if (model.meta.contractNo)
|
|
484
|
+
metaLines.push(`合同编号:${model.meta.contractNo}`);
|
|
485
|
+
if (model.meta.signPlace)
|
|
486
|
+
metaLines.push(`签订地点:${model.meta.signPlace}`);
|
|
487
|
+
if (model.meta.signDate)
|
|
488
|
+
metaLines.push(`签订日期:${model.meta.signDate}`);
|
|
489
|
+
if (model.meta.effectiveDate)
|
|
490
|
+
metaLines.push(`生效日期:${model.meta.effectiveDate}`);
|
|
491
|
+
if (metaLines.length) {
|
|
492
|
+
body.push(paraXml(metaLines.join(' '), { align: 'center', size: 21, after: 240 }));
|
|
493
|
+
metaLines.forEach((line) => { need(line); write(line); });
|
|
494
|
+
}
|
|
495
|
+
// ── 当事人
|
|
496
|
+
for (const line of partyLines('甲方(以下简称“甲方”)', model.counterParty)) {
|
|
497
|
+
body.push(paraXml(line, { after: 60 }));
|
|
498
|
+
need(line);
|
|
499
|
+
write(line);
|
|
500
|
+
}
|
|
501
|
+
body.push(emptyPara());
|
|
502
|
+
for (const line of partyLines('乙方(以下简称“乙方”)', model.ourParty)) {
|
|
503
|
+
body.push(paraXml(line, { after: 60 }));
|
|
504
|
+
need(line);
|
|
505
|
+
write(line);
|
|
506
|
+
}
|
|
507
|
+
body.push(emptyPara());
|
|
508
|
+
// ── 前言
|
|
509
|
+
const preamble = model.preamble.length ? model.preamble : [defaultPreamble(model)];
|
|
510
|
+
for (const block of preamble) {
|
|
511
|
+
body.push(paraXml(block, { firstLine: true, after: 120 }));
|
|
512
|
+
write(block);
|
|
513
|
+
}
|
|
514
|
+
// ── 鉴于条款
|
|
515
|
+
if (model.recitals.length) {
|
|
516
|
+
body.push(paraXml('鉴于:', { bold: true, after: 60, keepNext: true }));
|
|
517
|
+
model.recitals.forEach((recital, index) => {
|
|
518
|
+
const line = `${index + 1}. ${recital}`;
|
|
519
|
+
body.push(paraXml(line, { firstLine: true, after: 60 }));
|
|
520
|
+
write(line);
|
|
521
|
+
write(recital);
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
// ── 合同条款
|
|
525
|
+
model.articles.forEach((article) => {
|
|
526
|
+
body.push(paraXml(article.heading, {
|
|
527
|
+
bold: true,
|
|
528
|
+
size: 24,
|
|
529
|
+
before: 240,
|
|
530
|
+
after: 120,
|
|
531
|
+
keepNext: true,
|
|
532
|
+
}));
|
|
533
|
+
need(article.heading);
|
|
534
|
+
for (const paragraph of article.paragraphs) {
|
|
535
|
+
body.push(paraXml(paragraph, { firstLine: true, after: 120 }));
|
|
536
|
+
write(paragraph);
|
|
537
|
+
}
|
|
538
|
+
if (article.items.length) {
|
|
539
|
+
if (article.itemsTitle) {
|
|
540
|
+
body.push(paraXml(article.itemsTitle, { firstLine: true, after: 60 }));
|
|
541
|
+
write(article.itemsTitle);
|
|
542
|
+
}
|
|
543
|
+
const rows = article.items.map((item, index) => [
|
|
544
|
+
String(index + 1),
|
|
545
|
+
item.name,
|
|
546
|
+
item.spec,
|
|
547
|
+
item.unit,
|
|
548
|
+
item.qty !== null ? formatQty(item.qty) : '',
|
|
549
|
+
item.price !== null ? formatMoney(item.price) : '',
|
|
550
|
+
item.amount !== null ? formatMoney(item.amount) : '',
|
|
551
|
+
]);
|
|
552
|
+
body.push(tableXml(ARCHIVE_HEADERS, rows, { widths: ARCHIVE_WIDTHS }));
|
|
553
|
+
tables.push({ headers: ARCHIVE_HEADERS, rows });
|
|
554
|
+
article.items.forEach((item, index) => {
|
|
555
|
+
written.push(...rows[index].filter(Boolean));
|
|
556
|
+
itemAmounts.push({ field: `${article.heading}[${index + 1}]`, qty: item.qty, price: item.price, amount: item.amount });
|
|
557
|
+
});
|
|
558
|
+
body.push(emptyPara());
|
|
559
|
+
}
|
|
560
|
+
if (article.table) {
|
|
561
|
+
body.push(tableXml(article.table.headers, article.table.rows, {
|
|
562
|
+
widths: distribute(TOTAL_TABLE_WIDTH, article.table.headers.length),
|
|
563
|
+
}));
|
|
564
|
+
tables.push(article.table);
|
|
565
|
+
article.table.rows.forEach((row) => written.push(...row.filter(Boolean)));
|
|
566
|
+
}
|
|
567
|
+
if (article.notes.length) {
|
|
568
|
+
article.notes.forEach((note, index) => {
|
|
569
|
+
const line = `${index + 1}. ${note}`;
|
|
570
|
+
body.push(paraXml(line, { firstLine: true, after: 60 }));
|
|
571
|
+
write(line);
|
|
572
|
+
write(note);
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
body.push(paraXml('(以下无正文)', { align: 'center', before: 240, after: 240 }));
|
|
577
|
+
need('(以下无正文)');
|
|
578
|
+
// ── 合同金额
|
|
579
|
+
if (model.total !== null) {
|
|
580
|
+
body.push(paraXml('合同金额', { bold: true, size: 24, before: 240, after: 120, keepNext: true }));
|
|
581
|
+
const words = model.inWords || rmbUpper(String(model.total));
|
|
582
|
+
const upperLine = `合同总金额(大写):人民币${words}`;
|
|
583
|
+
const lowerLine = `合同总金额(小写):¥${formatMoney(model.total)}`;
|
|
584
|
+
body.push(paraXml(upperLine, { firstLine: true, after: 60 }));
|
|
585
|
+
body.push(paraXml(lowerLine, { firstLine: true, after: 60 }));
|
|
586
|
+
need('合同总金额');
|
|
587
|
+
write(upperLine);
|
|
588
|
+
write(lowerLine);
|
|
589
|
+
if (model.taxRate) {
|
|
590
|
+
const taxLine = `上述金额为含税金额,税率:${model.taxRate}。`;
|
|
591
|
+
body.push(paraXml(taxLine, { firstLine: true, after: 60 }));
|
|
592
|
+
write(taxLine);
|
|
593
|
+
}
|
|
594
|
+
if (model.sections.length) {
|
|
595
|
+
body.push(paraXml('合同金额构成如下:', { firstLine: true, after: 60 }));
|
|
596
|
+
const headers = ['序号', '费用项目', '金额(元)'];
|
|
597
|
+
const rows = model.sections.map((section, index) => [String(index + 1), section.name, formatMoney(section.amount)]);
|
|
598
|
+
rows.push(['', '合计', formatMoney(round2(model.sections.reduce((sum, section) => sum + section.amount, 0)))]);
|
|
599
|
+
body.push(tableXml(headers, rows, { widths: [900, 6100, 2000] }));
|
|
600
|
+
tables.push({ headers, rows });
|
|
601
|
+
model.sections.forEach((section) => {
|
|
602
|
+
write(section.name);
|
|
603
|
+
write(formatMoney(section.amount));
|
|
604
|
+
});
|
|
605
|
+
body.push(emptyPara());
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
// ── 付款方式
|
|
609
|
+
if (model.paymentTerms.length || model.installments.length) {
|
|
610
|
+
body.push(paraXml('付款方式', { bold: true, size: 24, before: 240, after: 120, keepNext: true }));
|
|
611
|
+
model.paymentTerms.forEach((term, index) => {
|
|
612
|
+
const line = `${index + 1}. ${term}`;
|
|
613
|
+
body.push(paraXml(line, { firstLine: true, after: 60 }));
|
|
614
|
+
write(line);
|
|
615
|
+
write(term);
|
|
616
|
+
});
|
|
617
|
+
if (model.installments.length) {
|
|
618
|
+
const headers = ['期次', '付款比例', '付款金额(元)', '约定付款时间'];
|
|
619
|
+
const rows = model.installments.map((installment, index) => [
|
|
620
|
+
installment.label || `第${index + 1}期`,
|
|
621
|
+
installment.percent !== null ? `${formatPercent(installment.percent)}%` : '',
|
|
622
|
+
installment.amount !== null ? formatMoney(installment.amount) : '',
|
|
623
|
+
installment.dueDate,
|
|
624
|
+
]);
|
|
625
|
+
body.push(tableXml(headers, rows, { widths: [1400, 1600, 2400, 3600] }));
|
|
626
|
+
tables.push({ headers, rows });
|
|
627
|
+
model.installments.forEach((installment, index) => {
|
|
628
|
+
written.push(...rows[index].filter(Boolean));
|
|
629
|
+
write(installment.amount !== null ? formatMoney(installment.amount) : '');
|
|
630
|
+
});
|
|
631
|
+
body.push(emptyPara());
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
// ── 签署页
|
|
635
|
+
body.push(paraXml('签署页', { bold: true, size: 24, before: 240, after: 120, keepNext: true }));
|
|
636
|
+
const signHeaders = ['甲方(盖章)', '乙方(盖章)'];
|
|
637
|
+
const signRows = [
|
|
638
|
+
[model.counterParty.name, model.ourParty.name],
|
|
639
|
+
[
|
|
640
|
+
`授权代表(签字):${model.signatures.counterSigner}`,
|
|
641
|
+
`授权代表(签字):${model.signatures.ourSigner}`,
|
|
642
|
+
],
|
|
643
|
+
];
|
|
644
|
+
body.push(tableXml(signHeaders, signRows, { border: false, widths: [4500, 4500], fontSize: 21 }));
|
|
645
|
+
tables.push({ headers: signHeaders, rows: signRows });
|
|
646
|
+
signRows.flat().forEach((line) => write(line));
|
|
647
|
+
const datePlace = model.signatures.datePlace || model.meta.signDate;
|
|
648
|
+
if (datePlace || model.meta.signPlace) {
|
|
649
|
+
const line = `签订日期/地点:${datePlace || ''}${datePlace && model.meta.signPlace ? ' ' : ''}${model.meta.signPlace || ''}`;
|
|
650
|
+
body.push(paraXml(line, { align: 'right', before: 120, after: 60 }));
|
|
651
|
+
write(line);
|
|
652
|
+
}
|
|
653
|
+
// ── 附件与其他约定
|
|
654
|
+
if (model.attachments.length) {
|
|
655
|
+
body.push(paraXml('附件', { bold: true, size: 24, before: 240, after: 120, keepNext: true }));
|
|
656
|
+
model.attachments.forEach((attachment, index) => {
|
|
657
|
+
const line = `${index + 1}. ${attachment}`;
|
|
658
|
+
body.push(paraXml(line, { after: 60 }));
|
|
659
|
+
write(line);
|
|
660
|
+
write(attachment);
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
if (model.notes.length) {
|
|
664
|
+
body.push(paraXml('其他约定', { bold: true, size: 24, before: 240, after: 120, keepNext: true }));
|
|
665
|
+
model.notes.forEach((note, index) => {
|
|
666
|
+
const line = `${index + 1}. ${note}`;
|
|
667
|
+
body.push(paraXml(line, { after: 60 }));
|
|
668
|
+
write(line);
|
|
669
|
+
write(note);
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
const documentXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
|
|
673
|
+
+ `<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">`
|
|
674
|
+
+ '<w:body>'
|
|
675
|
+
+ body.join('')
|
|
676
|
+
+ '<w:sectPr>'
|
|
677
|
+
+ '<w:pgSz w:w="11906" w:h="16838"/>'
|
|
678
|
+
+ '<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="851" w:footer="992" w:gutter="0"/>'
|
|
679
|
+
+ '<w:cols w:space="425"/>'
|
|
680
|
+
+ '<w:docGrid w:type="lines" w:linePitch="312"/>'
|
|
681
|
+
+ '</w:sectPr>'
|
|
682
|
+
+ '</w:body></w:document>';
|
|
683
|
+
return { documentXml, tables, required, written, itemAmounts };
|
|
684
|
+
}
|
|
685
|
+
const CONTENT_TYPES_XML = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
|
|
686
|
+
+ '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">'
|
|
687
|
+
+ '<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>'
|
|
688
|
+
+ '<Default Extension="xml" ContentType="application/xml"/>'
|
|
689
|
+
+ '<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>'
|
|
690
|
+
+ '<Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/>'
|
|
691
|
+
+ '<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>'
|
|
692
|
+
+ '<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>'
|
|
693
|
+
+ '</Types>';
|
|
694
|
+
const ROOT_RELS_XML = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
|
|
695
|
+
+ '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">'
|
|
696
|
+
+ '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>'
|
|
697
|
+
+ '<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>'
|
|
698
|
+
+ '<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>'
|
|
699
|
+
+ '</Relationships>';
|
|
700
|
+
const DOCUMENT_RELS_XML = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
|
|
701
|
+
+ '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">'
|
|
702
|
+
+ '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>'
|
|
703
|
+
+ '</Relationships>';
|
|
704
|
+
const STYLES_XML = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
|
|
705
|
+
+ '<w:styles xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">'
|
|
706
|
+
+ '<w:docDefaults>'
|
|
707
|
+
+ '<w:rPrDefault><w:rPr>'
|
|
708
|
+
+ '<w:rFonts w:ascii="宋体" w:eastAsia="宋体" w:hAnsi="宋体" w:cs="宋体"/>'
|
|
709
|
+
+ '<w:kern w:val="2"/><w:sz w:val="21"/><w:szCs w:val="21"/>'
|
|
710
|
+
+ '<w:lang w:val="en-US" w:eastAsia="zh-CN"/>'
|
|
711
|
+
+ '</w:rPr></w:rPrDefault>'
|
|
712
|
+
+ '<w:pPrDefault><w:pPr><w:spacing w:after="120" w:line="360" w:lineRule="auto"/></w:pPr></w:pPrDefault>'
|
|
713
|
+
+ '</w:docDefaults>'
|
|
714
|
+
+ '<w:style w:type="paragraph" w:default="1" w:styleId="Normal"><w:name w:val="Normal"/><w:qFormat/></w:style>'
|
|
715
|
+
+ '</w:styles>';
|
|
716
|
+
function coreXml(model, timestamp) {
|
|
717
|
+
return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
|
|
718
|
+
+ '<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" '
|
|
719
|
+
+ 'xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" '
|
|
720
|
+
+ 'xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
|
|
721
|
+
+ `<dc:title>${encodeXml(model.title)}</dc:title>`
|
|
722
|
+
+ '<dc:creator>contract.draft.build</dc:creator>'
|
|
723
|
+
+ `<dcterms:created xsi:type="dcterms:W3CDTF">${timestamp}</dcterms:created>`
|
|
724
|
+
+ `<dcterms:modified xsi:type="dcterms:W3CDTF">${timestamp}</dcterms:modified>`
|
|
725
|
+
+ '</cp:coreProperties>';
|
|
726
|
+
}
|
|
727
|
+
const APP_XML = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
|
|
728
|
+
+ '<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" '
|
|
729
|
+
+ 'xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">'
|
|
730
|
+
+ '<Application>weaver-work-cli</Application>'
|
|
731
|
+
+ '</Properties>';
|
|
732
|
+
function buildDocx(model, rendered) {
|
|
733
|
+
const timestamp = new Date().toISOString().replace(/\.\d{3}Z$/u, 'Z');
|
|
734
|
+
const entries = [
|
|
735
|
+
{ name: '[Content_Types].xml', data: Buffer.from(CONTENT_TYPES_XML, 'utf8') },
|
|
736
|
+
{ name: '_rels/.rels', data: Buffer.from(ROOT_RELS_XML, 'utf8') },
|
|
737
|
+
{ name: 'word/document.xml', data: Buffer.from(rendered.documentXml, 'utf8') },
|
|
738
|
+
{ name: 'word/_rels/document.xml.rels', data: Buffer.from(DOCUMENT_RELS_XML, 'utf8') },
|
|
739
|
+
{ name: 'word/styles.xml', data: Buffer.from(STYLES_XML, 'utf8') },
|
|
740
|
+
{ name: 'docProps/core.xml', data: Buffer.from(coreXml(model, timestamp), 'utf8') },
|
|
741
|
+
{ name: 'docProps/app.xml', data: Buffer.from(APP_XML, 'utf8') },
|
|
742
|
+
];
|
|
743
|
+
return writeZip(entries);
|
|
744
|
+
}
|
|
745
|
+
function validateDraft(model, rendered, entries, documentXml) {
|
|
746
|
+
const checks = [];
|
|
747
|
+
const fails = [];
|
|
748
|
+
const pass = (item, detail) => checks.push({ level: 'PASS', item, detail });
|
|
749
|
+
const warn = (item, detail) => checks.push({ level: 'WARN', item, detail });
|
|
750
|
+
const fail = (item, detail) => {
|
|
751
|
+
checks.push({ level: 'FAIL', item, detail });
|
|
752
|
+
fails.push(`${item}:${detail}`);
|
|
753
|
+
};
|
|
754
|
+
// ① 结构完整:标题、当事人、条款标题、正文结束标记必须在场
|
|
755
|
+
const missingRequired = rendered.required.filter((text) => !documentXml.includes(encodeXml(text)));
|
|
756
|
+
if (missingRequired.length) {
|
|
757
|
+
fail('结构完整', `缺少 ${missingRequired.slice(0, 5).join(';')}`);
|
|
758
|
+
}
|
|
759
|
+
else {
|
|
760
|
+
pass('结构完整', `标题 / 当事人 / ${model.articles.length} 条条款 / 结束标记齐全`);
|
|
761
|
+
}
|
|
762
|
+
// ② 写入回读一致:每个写入值都能在可见文本里逐字找到
|
|
763
|
+
const visible = residueTextOfDocx(entries);
|
|
764
|
+
const mismatched = rendered.written.filter((text) => text && !visible.includes(text));
|
|
765
|
+
if (mismatched.length) {
|
|
766
|
+
fail('写入回读一致', `${mismatched.length} 处不一致:${mismatched.slice(0, 5).join(';')}`);
|
|
767
|
+
}
|
|
768
|
+
else {
|
|
769
|
+
pass('写入回读一致', `${rendered.written.length} 个写入值全部回读命中`);
|
|
770
|
+
}
|
|
771
|
+
// ③ 金额勾稽:明细 = 单价×数量;分节合计 = 总额;分期累计 = 总额;比例合计 = 100%
|
|
772
|
+
const amountFails = [];
|
|
773
|
+
for (const item of rendered.itemAmounts) {
|
|
774
|
+
if (item.qty !== null && item.price !== null && item.amount !== null) {
|
|
775
|
+
const expect = round2(item.qty * item.price);
|
|
776
|
+
if (Math.abs(expect - item.amount) > 0.01) {
|
|
777
|
+
amountFails.push(`${item.field} 金额 ${item.amount} ≠ 单价×数量 ${expect}`);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
if (model.sections.length && model.total !== null) {
|
|
782
|
+
const sum = round2(model.sections.reduce((total, section) => total + section.amount, 0));
|
|
783
|
+
if (Math.abs(sum - model.total) > 0.01) {
|
|
784
|
+
amountFails.push(`费用分节合计 ${sum} ≠ 合同总金额 ${model.total}`);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
if (model.installments.length) {
|
|
788
|
+
if (model.total === null) {
|
|
789
|
+
amountFails.push('有付款计划但缺少合同总金额,无法核对分期');
|
|
790
|
+
}
|
|
791
|
+
else {
|
|
792
|
+
const sum = round2(model.installments.reduce((total, item) => total + (item.amount ?? 0), 0));
|
|
793
|
+
if (Math.abs(sum - model.total) > 0.01) {
|
|
794
|
+
amountFails.push(`分期累计 ${sum} ≠ 合同总金额 ${model.total}`);
|
|
795
|
+
}
|
|
796
|
+
const percents = model.installments.map((item) => item.percent);
|
|
797
|
+
if (percents.every((percent) => percent !== null)) {
|
|
798
|
+
const percentSum = round2(percents.reduce((total, percent) => total + percent, 0));
|
|
799
|
+
if (Math.abs(percentSum - 100) > 0.01) {
|
|
800
|
+
amountFails.push(`付款比例合计 ${percentSum}% ≠ 100%`);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
if (amountFails.length) {
|
|
806
|
+
fail('金额勾稽', amountFails.slice(0, 5).join(';'));
|
|
807
|
+
}
|
|
808
|
+
else {
|
|
809
|
+
pass('金额勾稽', model.total !== null ? `总额 ${formatMoney(model.total)} 与分节 / 分期 / 明细一致` : '未提供金额,跳过');
|
|
810
|
+
}
|
|
811
|
+
// ④ 表格结构未变:解析产物的顶层表格,逐张核对列数与行数
|
|
812
|
+
let parsed;
|
|
813
|
+
try {
|
|
814
|
+
parsed = parseTables(documentXml);
|
|
815
|
+
}
|
|
816
|
+
catch (error) {
|
|
817
|
+
parsed = [];
|
|
818
|
+
fail('表格结构未变', `表格解析失败:${error instanceof Error ? error.message : String(error)}`);
|
|
819
|
+
}
|
|
820
|
+
const tableFails = [];
|
|
821
|
+
if (parsed.length !== rendered.tables.length) {
|
|
822
|
+
tableFails.push(`表数 ${rendered.tables.length}→${parsed.length}`);
|
|
823
|
+
}
|
|
824
|
+
else {
|
|
825
|
+
rendered.tables.forEach((table, index) => {
|
|
826
|
+
const xmlTable = parsed[index];
|
|
827
|
+
if (!xmlTable)
|
|
828
|
+
return;
|
|
829
|
+
if (xmlTable.cols !== table.headers.length) {
|
|
830
|
+
tableFails.push(`T${index} 列数 ${table.headers.length}→${xmlTable.cols}`);
|
|
831
|
+
}
|
|
832
|
+
if (xmlTable.rows.length !== table.rows.length + 1) {
|
|
833
|
+
tableFails.push(`T${index} 行数 ${table.rows.length + 1}→${xmlTable.rows.length}`);
|
|
834
|
+
}
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
if (tableFails.length) {
|
|
838
|
+
fail('表格结构未变', tableFails.join(';'));
|
|
839
|
+
}
|
|
840
|
+
else {
|
|
841
|
+
pass('表格结构未变', `${rendered.tables.length} 张表,列数与行数一致`);
|
|
842
|
+
}
|
|
843
|
+
// ⑤ XML 良构
|
|
844
|
+
const wellFormed = validateXmlWellFormed(documentXml);
|
|
845
|
+
const requiredEntries = ['[Content_Types].xml', '_rels/.rels', 'word/document.xml', 'word/styles.xml'];
|
|
846
|
+
const missingEntries = requiredEntries.filter((name) => !entries.some((entry) => entry.name === name));
|
|
847
|
+
if (!wellFormed.ok || missingEntries.length) {
|
|
848
|
+
fail('XML 良构', wellFormed.ok ? `缺少包内条目:${missingEntries.join('、')}` : (wellFormed.error ?? '未知错误'));
|
|
849
|
+
}
|
|
850
|
+
else {
|
|
851
|
+
pass('XML 良构', '标签全部配对,包内条目齐全');
|
|
852
|
+
}
|
|
853
|
+
// ⑥ 占位符残留为 0
|
|
854
|
+
const residue = scanResidue(visible, RESIDUE_PATTERNS);
|
|
855
|
+
if (Object.keys(residue).length) {
|
|
856
|
+
fail('占位符残留', Object.entries(residue).map(([key, count]) => `${key}×${count}`).join('、'));
|
|
857
|
+
}
|
|
858
|
+
else {
|
|
859
|
+
pass('占位符残留', `0 处(清单 ${RESIDUE_PATTERNS.length} 项)`);
|
|
860
|
+
}
|
|
861
|
+
return { ok: fails.length === 0, checks, fails };
|
|
862
|
+
}
|
|
863
|
+
// ---------------------------------------------------------------- operation
|
|
864
|
+
export const contractDraftOperations = [
|
|
865
|
+
{
|
|
866
|
+
name: 'contract.draft.build',
|
|
867
|
+
async execute(input) {
|
|
868
|
+
// 金额值引用(与报价单链路同一通道):金额在模型上下文里可能被脱敏,
|
|
869
|
+
// 允许写成 {"$quote":"<解析结果.json>#totals.final_total"},真值由本进程读。
|
|
870
|
+
// 任何位置(amount.total / sections[].amount / items[].price / installments[].amount)都会被就地替换。
|
|
871
|
+
const refOutcome = resolveQuoteRefs(input);
|
|
872
|
+
assertQuoteRefsResolved(refOutcome, (errors) => `入参有 ${errors.length} 处 $quote 引用取不到值:`
|
|
873
|
+
+ errors.slice(0, 5).map((item) => `${item.at}(${item.ref}:${item.reason})`).join(';')
|
|
874
|
+
+ '。请核对文件路径与字段路径;解析结果需先用 contract.quote.parse / contract.quote.normalize 的 out 参数落盘。');
|
|
875
|
+
input = refOutcome.value;
|
|
876
|
+
const model = buildModel(input);
|
|
877
|
+
const warnings = [...model.warnings];
|
|
878
|
+
let rendered;
|
|
879
|
+
try {
|
|
880
|
+
rendered = renderDraft(model);
|
|
881
|
+
}
|
|
882
|
+
catch (error) {
|
|
883
|
+
throw contractValidationError('draft_docx_invalid', `合同 docx 渲染失败:${error instanceof Error ? error.message : String(error)}`);
|
|
884
|
+
}
|
|
885
|
+
let buffer;
|
|
886
|
+
try {
|
|
887
|
+
buffer = buildDocx(model, rendered);
|
|
888
|
+
}
|
|
889
|
+
catch (error) {
|
|
890
|
+
throw contractValidationError('draft_docx_invalid', `合同 docx 打包失败:${error instanceof Error ? error.message : String(error)}`);
|
|
891
|
+
}
|
|
892
|
+
try {
|
|
893
|
+
mkdirSync(dirname(model.outPath), { recursive: true });
|
|
894
|
+
writeFileSync(model.outPath, buffer);
|
|
895
|
+
}
|
|
896
|
+
catch (error) {
|
|
897
|
+
throw contractValidationError('draft_out_not_writable', `无法写入 ${model.outPath}:${error instanceof Error ? error.message : String(error)}`, { out: model.outPath });
|
|
898
|
+
}
|
|
899
|
+
// 回读产物做六类校验:不信任「刚写进去」的内存值,一律以磁盘文件为准
|
|
900
|
+
let entries;
|
|
901
|
+
try {
|
|
902
|
+
entries = readZip(readFileSync(model.outPath));
|
|
903
|
+
}
|
|
904
|
+
catch (error) {
|
|
905
|
+
throw contractValidationError('draft_docx_invalid', `产物不是有效的 docx:${error instanceof Error ? error.message : String(error)}`);
|
|
906
|
+
}
|
|
907
|
+
const documentEntry = entries.find((entry) => entry.name === 'word/document.xml');
|
|
908
|
+
if (!documentEntry) {
|
|
909
|
+
throw contractValidationError('draft_docx_invalid', '产物缺少 word/document.xml,不是有效的 Word 文档');
|
|
910
|
+
}
|
|
911
|
+
const documentXml = documentEntry.data.toString('utf8');
|
|
912
|
+
const validation = validateDraft(model, rendered, entries, documentXml);
|
|
913
|
+
if (!validation.ok)
|
|
914
|
+
warnings.push('校验未通过:见 validate.fails;未通过校验的产物不得交付');
|
|
915
|
+
return {
|
|
916
|
+
status: 'COMPLETE',
|
|
917
|
+
data: {
|
|
918
|
+
ok: validation.ok,
|
|
919
|
+
out: model.outPath,
|
|
920
|
+
contractPath: model.outPath,
|
|
921
|
+
fileName: basename(model.outPath),
|
|
922
|
+
expectedFileName: basename(model.outPath),
|
|
923
|
+
title: model.title,
|
|
924
|
+
amount: model.total,
|
|
925
|
+
totalAmount: model.total,
|
|
926
|
+
totalInWords: model.total !== null ? (model.inWords || rmbUpper(String(model.total))) : null,
|
|
927
|
+
articleCount: model.articles.length,
|
|
928
|
+
tableCount: rendered.tables.length,
|
|
929
|
+
validate: validation,
|
|
930
|
+
warnings,
|
|
931
|
+
note: validation.ok
|
|
932
|
+
? '已生成合同 docx 并通过六类校验,可交给 contract.draft.submit 收口'
|
|
933
|
+
: '不通过:见 validate.fails;未通过校验的产物不得交付,也不得上传',
|
|
934
|
+
},
|
|
935
|
+
};
|
|
936
|
+
},
|
|
937
|
+
},
|
|
938
|
+
];
|
|
939
|
+
/** 供其它模块(含测试)复用的渲染与校验入口。 */
|
|
940
|
+
export { buildModel, renderDraft, validateDraft };
|