weaver-work-cli 0.1.63 → 0.1.64
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/dist/chunks/{archive-BLDYBZDX.js → archive-WUZKAEZ6.js} +2 -2
- package/dist/chunks/{archive-oa-3GJ3TWXR.js → archive-oa-PN46RTI2.js} +2 -2
- package/dist/chunks/{asset-AFXJN4CK.js → asset-ZPC5VWZM.js} +2 -2
- package/dist/chunks/{asset-idle-VUJXWGWJ.js → asset-idle-DHGP3NYY.js} +2 -2
- package/dist/chunks/{attachment-content-VMJA7NSQ.js → attachment-content-JQDW3BIB.js} +3 -3
- package/dist/chunks/{blog-EREB35VU.js → blog-JC47AIXK.js} +2 -2
- package/dist/chunks/{caizhilian-ATM2JO5S.js → caizhilian-IKIHM77A.js} +4 -4
- package/dist/chunks/{calendar-E26ZIH7S.js → calendar-GZTSJ57Y.js} +2 -2
- package/dist/chunks/{chunk-OMAGCLUE.js → chunk-26FCCU5O.js} +2 -2
- package/dist/chunks/{chunk-BY3WDJO5.js → chunk-3PCXBG4H.js} +1 -1
- package/dist/chunks/{chunk-EOZHSNND.js → chunk-3W5NMGDS.js} +2 -2
- package/dist/chunks/{chunk-TNFIUZ4H.js → chunk-4AFWOGOV.js} +1 -1
- package/dist/chunks/{chunk-QAMIIFP6.js → chunk-5QQKLR6H.js} +11 -11
- package/dist/chunks/{chunk-C5PIGPGX.js → chunk-6T5X6YWX.js} +2 -2
- package/dist/chunks/{chunk-WPBZQVLS.js → chunk-AFZTMYGC.js} +1 -1
- package/dist/chunks/{chunk-IGICM3WJ.js → chunk-AGSO3PIK.js} +2 -2
- package/dist/chunks/{chunk-6VCQLZXE.js → chunk-FDBAFANU.js} +1 -0
- package/dist/chunks/{chunk-RV2JAA5I.js → chunk-FJUOUSV3.js} +1 -1
- package/dist/chunks/{chunk-6G2JARDK.js → chunk-HLT6B26P.js} +1 -1
- package/dist/chunks/{chunk-THMBDCRA.js → chunk-HWA2A25Y.js} +2 -2
- package/dist/chunks/{chunk-SHBDXEUE.js → chunk-I3MOFD6Q.js} +4 -4
- package/dist/chunks/{chunk-5CY37VLS.js → chunk-INVYKG4I.js} +45 -43
- package/dist/chunks/{chunk-QZYKZ7MQ.js → chunk-K7QKQRSL.js} +155 -57
- package/dist/chunks/{chunk-HEJPVXD3.js → chunk-KDFEHDIB.js} +4 -4
- package/dist/chunks/{chunk-I4C2KR2G.js → chunk-KYDXWYFB.js} +1 -1
- package/dist/chunks/{chunk-RR45ELVE.js → chunk-Q6D6PSMH.js} +2 -2
- package/dist/chunks/{chunk-G3ZM57PD.js → chunk-RMOH2GMF.js} +2 -2
- package/dist/chunks/{chunk-LOVAIGM2.js → chunk-SCMHG23G.js} +50 -50
- package/dist/chunks/{chunk-GQK6WLOS.js → chunk-VLY5RTVO.js} +2 -2
- package/dist/chunks/{chunk-SDPC7BG2.js → chunk-WSHIOSGM.js} +2 -2
- package/dist/chunks/{chunk-4OB22YKE.js → chunk-XHSEK2VM.js} +6 -6
- package/dist/chunks/{chunk-GOBNIGWS.js → chunk-YTFNMQO4.js} +1 -1
- package/dist/chunks/{conflict-AMNTM3FV.js → conflict-UUC7AFUI.js} +2 -2
- package/dist/chunks/{contract-PLO2V2NO.js → contract-INMS7SYQ.js} +846 -199
- package/dist/chunks/{cowork-FZAXE6FO.js → cowork-34CBYVQP.js} +2 -2
- package/dist/chunks/{create-flow-2DAUN7HU.js → create-flow-YOR4QTAJ.js} +8 -6
- package/dist/chunks/{data-7NXMWET4.js → data-QKWI5325.js} +13 -2
- package/dist/chunks/{ebuilder-form-DEYHX6M7.js → ebuilder-form-ZONRROK4.js} +3 -3
- package/dist/chunks/{ehr-QQH2DYYA.js → ehr-2CONM7R6.js} +2 -2
- package/dist/chunks/{entry-mode-2JTVEKMP.js → entry-mode-S2ENJ6GZ.js} +3 -3
- package/dist/chunks/{env-2JZMXC6I.js → env-ZSAXU5PJ.js} +2 -2
- package/dist/chunks/{esb-I5ZFHJUK.js → esb-FQASCY2H.js} +4 -4
- package/dist/chunks/{factory-XIATYHU6.js → factory-N76QQA53.js} +1 -1
- package/dist/chunks/{fna-3V2TL6B2.js → fna-FCLVIWAS.js} +2 -2
- package/dist/chunks/{group-chat-CVYUZCOQ.js → group-chat-UM665WDZ.js} +3 -3
- package/dist/chunks/{host-CBONEAZS.js → host-2ED2KC4X.js} +3 -3
- package/dist/chunks/{host-4DP7C7YQ.js → host-2UYZEY2V.js} +3 -3
- package/dist/chunks/{host-4KQCAEWA.js → host-46NYKDQP.js} +3 -3
- package/dist/chunks/{host-BD7NAM33.js → host-7IPZKIM4.js} +3 -3
- package/dist/chunks/{host-L37QVNIV.js → host-P7G22WNM.js} +3 -3
- package/dist/chunks/{host-4X2F3JPQ.js → host-XLCBLNJD.js} +3 -3
- package/dist/chunks/{hrm-OL3IKN7C.js → hrm-XKL27NX2.js} +3 -3
- package/dist/chunks/{im-YXQWUF3R.js → im-NDYIMASG.js} +3 -3
- package/dist/chunks/{invoice-4WY32PR2.js → invoice-MOGNB6HN.js} +3 -3
- package/dist/chunks/{jiuchuanhui-L6SHLONH.js → jiuchuanhui-3T5X7SB7.js} +2 -2
- package/dist/chunks/{lazy-dispatch-OYE6QV24.js → lazy-dispatch-4WOIL3ZQ.js} +4 -4
- package/dist/chunks/{mail-PZV2KNRU.js → mail-P7VMUKQW.js} +2 -2
- package/dist/chunks/{meeting-6SOBCC6N.js → meeting-MMTYDHXA.js} +13 -13
- package/dist/chunks/{minute-doc-KSJSJNOH.js → minute-doc-LCSBWGJ3.js} +4 -4
- package/dist/chunks/{okr-B76FW5M2.js → okr-VZXRQGS4.js} +2 -2
- package/dist/chunks/{operations-YOMEGFLV.js → operations-MI2BSKZX.js} +4 -4
- package/dist/chunks/{performance-4VBKUPFO.js → performance-OPEQNW7Y.js} +870 -15
- package/dist/chunks/{plan-HBNZRQTI.js → plan-TJAS4N5X.js} +2 -2
- package/dist/chunks/{project-IV6FWK74.js → project-CYBGU6K6.js} +2 -2
- package/dist/chunks/{reception-BR5YURT6.js → reception-3FT2F66K.js} +2 -2
- package/dist/chunks/{recruit-stage-4HQ6OGXT.js → recruit-stage-WPGB5BDJ.js} +2 -2
- package/dist/chunks/{registry-JFQEFC7E.js → registry-BAWCWV4D.js} +2 -2
- package/dist/chunks/{registry-7LICMV5J.js → registry-FNI5E76J.js} +12 -12
- package/dist/chunks/{registry-MZJQX65Q.js → registry-QRMXRSCT.js} +4 -4
- package/dist/chunks/{room-recommend-43GLLE7Y.js → room-recommend-I7QQRHEL.js} +4 -4
- package/dist/chunks/{schedule-ZQ42BEW6.js → schedule-3P7EWGNZ.js} +4 -4
- package/dist/chunks/{smart-extract-QKAEAZGM.js → smart-extract-FOBSVNYW.js} +2 -2
- package/dist/chunks/{workflow-6HV7H5PC.js → workflow-U2KKTVQY.js} +4 -4
- package/dist/index.js +33 -33
- package/dist/internal/e10/auth/commands.js +182 -43
- package/dist/shortcuts/contract/error-actions.js +112 -0
- package/dist/shortcuts/contract/errors.js +9 -1
- package/dist/shortcuts/contract/manifest.js +18 -7
- package/dist/shortcuts/contract/operations/docx-slots.js +112 -5
- package/dist/shortcuts/contract/operations/docx-verify.js +2 -70
- package/dist/shortcuts/contract/operations/elements-build.js +82 -56
- package/dist/shortcuts/contract/operations/elements-spec.js +140 -3
- package/dist/shortcuts/contract/operations/ledger-card.js +25 -2
- package/dist/shortcuts/contract/operations/ledger.js +33 -5
- package/dist/shortcuts/contract/operations/money.js +90 -0
- package/dist/shortcuts/contract/operations/placeholder-scan.js +104 -0
- package/dist/shortcuts/contract/operations/quote-recognize.js +54 -17
- package/dist/shortcuts/contract/operations/quote-ref.js +179 -0
- package/dist/shortcuts/contract/operations/quote-submit.js +20 -3
- package/dist/shortcuts/contract/operations/quote.js +66 -12
- package/dist/shortcuts/contract/operations/solutions-spec.js +79 -0
- package/dist/shortcuts/contract/operations/triage.js +55 -9
- package/dist/shortcuts/data/operations/shared.js +14 -1
- package/dist/shortcuts/meeting/operations/eb/create-flow.js +25 -11
- package/dist/shortcuts/performance/flow-utils.js +363 -0
- package/dist/shortcuts/performance/manifest.js +2 -2
- package/dist/shortcuts/performance/operations/flow-detail.js +85 -0
- package/dist/shortcuts/performance/operations/flow-list.js +213 -0
- package/dist/shortcuts/performance/operations/flow-score.js +241 -0
- package/dist/shortcuts/performance/operations/registry.js +6 -0
- package/docs/e10-auth.md +27 -2
- package/package.json +1 -1
- package/skills/weaver-e10-jinchengda/SKILL.md +87 -39
- package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +29 -29
- package/skills/weaver-e10-jinchengda/references/contract-clause-insert.md +2 -2
- package/skills/weaver-e10-jinchengda/references/contract-clause-library-crud.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-command-index.md +29 -7
- package/skills/weaver-e10-jinchengda/references/contract-compare-report.md +3 -3
- package/skills/weaver-e10-jinchengda/references/contract-credit-page.md +5 -5
- package/skills/weaver-e10-jinchengda/references/contract-disabled-capabilities.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-doc-compare.md +22 -25
- package/skills/weaver-e10-jinchengda/references/contract-doc-triage.md +53 -314
- package/skills/weaver-e10-jinchengda/references/contract-element-extract.md +6 -5
- package/skills/weaver-e10-jinchengda/references/contract-element-save-record.md +19 -11
- package/skills/weaver-e10-jinchengda/references/contract-execution-rules.md +3 -3
- package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +43 -25
- package/skills/weaver-e10-jinchengda/references/contract-field-extract-other-flows.md +103 -212
- package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +7 -7
- package/skills/weaver-e10-jinchengda/references/contract-ledger-catalog.md +7 -6
- package/skills/weaver-e10-jinchengda/references/contract-ledger-query-playbook.md +34 -21
- package/skills/weaver-e10-jinchengda/references/contract-ledger-rules.md +6 -6
- package/skills/weaver-e10-jinchengda/references/contract-modeltext-library.md +3 -3
- package/skills/weaver-e10-jinchengda/references/contract-multi-file.md +6 -6
- package/skills/weaver-e10-jinchengda/references/contract-object-detect.md +22 -22
- package/skills/weaver-e10-jinchengda/references/contract-open-web-pages.md +21 -19
- package/skills/weaver-e10-jinchengda/references/contract-performance-query.md +6 -5
- package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +132 -95
- package/skills/weaver-e10-jinchengda/references/contract-request-status.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-request-write.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-template-recommend.md +1 -1
- package/skills/weaver-e10-jinchengda/references/contract-type-fingerprints.md +12 -12
- package/skills/weaver-e10-jinchengda/references/contract-workflow-discovery.md +1 -1
- package/skills/weaver-e10-jinchengda/references/orchestration.md +5 -5
- package/skills/weaver-e10-meeting/SKILL.md +8 -7
- package/skills/weaver-e10-meeting/references/create-commands.md +2 -2
- package/skills/weaver-e10-meeting/references/create-flow.md +6 -6
- package/skills/weaver-e10-meeting/references/create-guardrails.md +10 -10
- package/skills/weaver-e10-meeting/references/invitation.md +1 -1
- package/skills/weaver-e10-meeting/references/meeting-eb.md +26 -26
- package/skills/weaver-e10-meeting/references/meeting-invitation.md +2 -2
- package/skills/weaver-e10-meeting/references/meeting-minute-file.md +2 -2
- package/skills/weaver-e10-meeting/references/meeting-verification.md +1 -1
- package/skills/weaver-e10-performance/SKILL.md +45 -5
- package/skills/weaver-e10-performance/agents/openai.yaml +26 -2
- package/skills/weaver-e10-performance/references/flow-api.md +128 -0
- package/skills/weaver-e10-performance/references/flow-assess.md +149 -0
- package/skills/weaver-e10-yimiaoban/SKILL.md +8 -5
- package/skills/weaver-e10-yimiaoban/references/source-manifest.json +3 -3
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
2
|
import { randomBytes } from 'node:crypto';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
3
4
|
import { createServer } from 'node:http';
|
|
5
|
+
import { isConnectorMode } from '../../../core/connector.js';
|
|
4
6
|
import { CliError, ExitCode } from '../../../core/errors.js';
|
|
5
7
|
import { clearInvoiceTokenForSession } from '../../../shortcuts/invoice/host.js';
|
|
6
8
|
import { buildE10CookieHeader, E10AuthSession, clearProfileAuthFile, extractRawSetCookie, extractSessionTicket, findAuthFile, getActiveProfile, getProfileAuthPath, getProfileDir, listProfiles, profileNameFromUrl, readProfileConfig, readTeamsCheckUserInfo, resolveActiveProfileForHost, saveAuthFile, saveProfileConfig, setActiveProfile, switchActiveProfile, } from './session.js';
|
|
@@ -160,7 +162,19 @@ function validateAgentReturnUrl(value) {
|
|
|
160
162
|
}
|
|
161
163
|
return value;
|
|
162
164
|
}
|
|
163
|
-
|
|
165
|
+
/**
|
|
166
|
+
* 是否处于「机器模式」认证:连接器/宿主代跑,或 stdout 不是终端。
|
|
167
|
+
*
|
|
168
|
+
* 机器模式下没有人在浏览器前点「是否打开 XX?」弹层,若仍走桌面回跳,CLI 会一直
|
|
169
|
+
* 阻塞到 `AGENT_RETURN_TIMEOUT_MS`(15 分钟),而按「进程退出 + stdout」判定授权
|
|
170
|
+
* 结果的宿主只会看到超时失败——凭证其实早在回调那一刻就落盘了。
|
|
171
|
+
*/
|
|
172
|
+
export function isMachineAuthMode(stdout = process.stdout, connectorMode = isConnectorMode()) {
|
|
173
|
+
if (connectorMode)
|
|
174
|
+
return true;
|
|
175
|
+
return stdout.isTTY !== true;
|
|
176
|
+
}
|
|
177
|
+
export function resolveAgentReturnTarget(options = {}, env = process.env, agentType = resolveAgentType(options, env), mode = {}) {
|
|
164
178
|
const builtInTarget = builtInAgentReturnTarget(agentType);
|
|
165
179
|
const explicitUrl = optionString(options, 'agentReturnUrl') || envString(env, AGENT_RETURN_URL_ENV_KEY);
|
|
166
180
|
if (explicitUrl) {
|
|
@@ -169,6 +183,9 @@ export function resolveAgentReturnTarget(options = {}, env = process.env, agentT
|
|
|
169
183
|
url: validateAgentReturnUrl(explicitUrl),
|
|
170
184
|
};
|
|
171
185
|
}
|
|
186
|
+
// 机器模式只认显式指定的返回地址;内置映射与 `<agent_type>://` 猜测都会挂住进程。
|
|
187
|
+
if (mode.machine)
|
|
188
|
+
return null;
|
|
172
189
|
if (builtInTarget)
|
|
173
190
|
return builtInTarget;
|
|
174
191
|
const conventionalUrl = conventionalAgentReturnUrl(agentType);
|
|
@@ -300,19 +317,101 @@ export function renderE10LoginSuccessPage(userId, returnTarget = null, launchTok
|
|
|
300
317
|
: '';
|
|
301
318
|
return `<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>weaver-work-cli 登录成功</title><style>:root{color-scheme:light}*{box-sizing:border-box}body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Arial,sans-serif;background:radial-gradient(circle at 50% 18%,#eefbf8 0,#f6f7f9 42%,#eef1f5 100%);color:#20242a;display:grid;place-items:center;min-height:100vh;margin:0}.card{background:rgba(255,255,255,.88);border:1px solid #e6e8ec;border-radius:18px;padding:34px 38px;box-shadow:0 18px 55px rgba(18,24,40,.09);width:min(560px,calc(100vw - 40px));text-align:center}.title{font-size:24px;font-weight:700;margin-bottom:10px}.desc{color:#667085;font-size:15px;line-height:24px}.user{color:#98a2b3;font-size:12px;margin-top:18px}.overlay{position:fixed;inset:0;z-index:10;display:grid;place-items:center;padding:20px;background:rgba(28,34,41,.36);backdrop-filter:blur(5px)}.overlay[hidden]{display:none}.prompt{width:min(410px,calc(100vw - 32px));padding:32px 28px 26px;border:1px solid rgba(255,255,255,.75);border-radius:24px;background:rgba(250,250,251,.97);box-shadow:0 24px 70px rgba(15,23,42,.28);text-align:center}.app-icon{width:74px;height:74px;margin:0 auto 24px;filter:drop-shadow(0 8px 14px rgba(8,170,130,.22))}.app-icon svg{display:block;width:100%;height:100%}.prompt h1{margin:0;font-size:20px;line-height:30px;font-weight:700;letter-spacing:-.2px}.prompt p{margin:10px 0 24px;color:#667085;font-size:14px;line-height:22px}.prompt button{display:block;width:100%;min-height:40px;border:0;border-radius:12px;font:600 16px/22px inherit;cursor:pointer;transition:transform .12s ease,filter .12s ease}.prompt button+button{margin-top:10px}.prompt button:hover{filter:brightness(.98)}.prompt button:active{transform:scale(.99)}.prompt button:disabled{cursor:wait;opacity:.62}.primary{background:linear-gradient(180deg,#2f91ff,#0b74e5);color:#fff;box-shadow:0 8px 18px rgba(11,116,229,.2)}.secondary{background:#e9eaec;color:#22252a}.status{min-height:18px;margin-top:14px;color:#667085;font-size:12px;line-height:18px}</style></head><body><main class="card"><div class="title">登录授权成功</div><div class="desc">你可以关闭此页面,返回智能体或终端继续使用。</div><div class="user">${esc(userId)}</div></main>${returnAction}${returnScript}</body></html>`;
|
|
302
319
|
}
|
|
303
|
-
|
|
320
|
+
function defaultFileExists(file) {
|
|
321
|
+
try {
|
|
322
|
+
return existsSync(file);
|
|
323
|
+
}
|
|
324
|
+
catch {
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function firstExisting(candidates, exists) {
|
|
329
|
+
return candidates.find((candidate) => exists(candidate)) ?? null;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* 解析 Windows 上 `rundll32.exe` 的绝对路径。
|
|
333
|
+
*
|
|
334
|
+
* 必须用绝对路径:`execFile` 只走 PATH 解析(不经过 CreateProcess 的系统目录搜索),
|
|
335
|
+
* 而连接器/沙箱宿主的 PATH 常被整体重建、不含 `%SystemRoot%\System32`,
|
|
336
|
+
* 裸命令名会直接 `spawn rundll32.exe ENOENT`,表现为授权页「打开应用」返回 500。
|
|
337
|
+
* 系统盘不一定是 C,所以用 `SystemRoot`/`windir` 拼,不硬编码 `C:\Windows`。
|
|
338
|
+
*/
|
|
339
|
+
export function resolveWindowsRundll32Path(env = process.env, exists = defaultFileExists) {
|
|
340
|
+
const systemRoot = (env.SystemRoot || env.windir || env.WINDIR || 'C:\\Windows')
|
|
341
|
+
.replace(/[\\/]+$/, '');
|
|
342
|
+
return firstExisting([
|
|
343
|
+
// 常规路径;32 位进程下会被 WOW64 重定向到 SysWOW64,同样可正常 ShellExecute。
|
|
344
|
+
`${systemRoot}\\System32\\rundll32.exe`,
|
|
345
|
+
// 仅 32 位进程可见的虚拟目录,作为兜底;64 位进程探测会返回 false。
|
|
346
|
+
`${systemRoot}\\Sysnative\\rundll32.exe`,
|
|
347
|
+
], exists) ?? 'rundll32.exe';
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* 关闭本地回调服务,并保证 `onClosed` 一定被调用。
|
|
351
|
+
*
|
|
352
|
+
* 浏览器/HTTP 客户端会保持 keep-alive 连接,`server.close()` 的回调要等这些连接
|
|
353
|
+
* 自然断开才触发,Promise 就一直不 resolve、`{"status":"authorized"}` 也就永远不
|
|
354
|
+
* 输出——宿主(如豆包)以「进程退出」判定授权成功时,会误报鉴权失败。
|
|
355
|
+
* 这里先关空闲连接,再在 `graceMs` 后强制关闭残留连接并兜底回调。
|
|
356
|
+
*/
|
|
357
|
+
export function closeHttpServer(server, onClosed, graceMs = 500) {
|
|
358
|
+
let closed = false;
|
|
359
|
+
let timer = null;
|
|
360
|
+
const done = () => {
|
|
361
|
+
if (closed)
|
|
362
|
+
return;
|
|
363
|
+
closed = true;
|
|
364
|
+
if (timer)
|
|
365
|
+
clearTimeout(timer);
|
|
366
|
+
onClosed();
|
|
367
|
+
};
|
|
368
|
+
try {
|
|
369
|
+
server.close(done);
|
|
370
|
+
server.closeIdleConnections?.();
|
|
371
|
+
timer = setTimeout(() => {
|
|
372
|
+
try {
|
|
373
|
+
server.closeAllConnections?.();
|
|
374
|
+
}
|
|
375
|
+
catch {
|
|
376
|
+
/* ignore: 连接已关闭 */
|
|
377
|
+
}
|
|
378
|
+
done();
|
|
379
|
+
}, graceMs);
|
|
380
|
+
timer.unref?.();
|
|
381
|
+
}
|
|
382
|
+
catch {
|
|
383
|
+
done();
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* 解析「用系统默认处理器打开 URL」的命令。
|
|
388
|
+
*
|
|
389
|
+
* 三个平台都用绝对路径优先、裸命令名兜底:宿主清空 PATH 时裸名会 ENOENT,
|
|
390
|
+
* 但正常桌面环境里绝对路径也一定存在,因此回退不会改变既有行为。
|
|
391
|
+
*/
|
|
392
|
+
export function resolveBrowserOpenCommand(url, platform = process.platform, options = {}) {
|
|
393
|
+
const exists = options.exists ?? defaultFileExists;
|
|
394
|
+
const env = options.env ?? process.env;
|
|
304
395
|
if (platform === 'win32') {
|
|
305
|
-
return { file:
|
|
396
|
+
return { file: resolveWindowsRundll32Path(env, exists), args: ['url.dll,FileProtocolHandler', url] };
|
|
397
|
+
}
|
|
398
|
+
if (platform === 'darwin') {
|
|
399
|
+
return { file: firstExisting(['/usr/bin/open'], exists) ?? 'open', args: [url] };
|
|
400
|
+
}
|
|
401
|
+
return { file: firstExisting(['/usr/bin/xdg-open', '/bin/xdg-open'], exists) ?? 'xdg-open', args: [url] };
|
|
402
|
+
}
|
|
403
|
+
function describeOpenFailure(error) {
|
|
404
|
+
if (error instanceof Error) {
|
|
405
|
+
const code = error.code;
|
|
406
|
+
return code ? `${code}: ${error.message}` : error.message;
|
|
306
407
|
}
|
|
307
|
-
|
|
308
|
-
return { file: 'open', args: [url] };
|
|
309
|
-
return { file: 'xdg-open', args: [url] };
|
|
408
|
+
return String(error);
|
|
310
409
|
}
|
|
311
410
|
function openUrlInBrowser(url, ctx) {
|
|
312
411
|
const command = resolveBrowserOpenCommand(url);
|
|
313
412
|
execFile(command.file, command.args, (error) => {
|
|
314
413
|
if (error) {
|
|
315
|
-
ctx.logger.warn(
|
|
414
|
+
ctx.logger.warn(`Could not open browser automatically (${command.file}: ${describeOpenFailure(error)}). Copy the login URL manually.`);
|
|
316
415
|
}
|
|
317
416
|
});
|
|
318
417
|
}
|
|
@@ -501,9 +600,15 @@ async function oidcExchange(code, redirectUri, baseUrl, tenantKeyFallback, agent
|
|
|
501
600
|
redirect: 'manual',
|
|
502
601
|
});
|
|
503
602
|
const tokenData = await readJsonObject(tokenResp);
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
603
|
+
// E10 的业务失败是 HTTP 200 + `{"status":400,"code":"1010"}`,只看 HTTP 状态码会把
|
|
604
|
+
// 失败当成功继续往下走,最终以「无法解析 ETEAMSID」这种误导性错误收场。
|
|
605
|
+
const businessStatus = Number(tokenData.status);
|
|
606
|
+
const businessFailed = Number.isFinite(businessStatus) && businessStatus >= 400;
|
|
607
|
+
if (tokenResp.status >= 400 || businessFailed) {
|
|
608
|
+
const message = readString(tokenData, 'message', 'msg', 'error_description', 'error')
|
|
609
|
+
|| `OAuth token exchange failed: ${businessFailed ? businessStatus : tokenResp.status}`;
|
|
610
|
+
const code = readString(tokenData, 'code');
|
|
611
|
+
throw new CliError(code ? `${message} (code ${code})` : message, ExitCode.AuthError);
|
|
507
612
|
}
|
|
508
613
|
let eteamsId = readString(tokenData, 'eteamsId', 'eteamsid');
|
|
509
614
|
let userId = readString(tokenData, 'id', 'userId', 'employeeId');
|
|
@@ -677,7 +782,7 @@ async function runXiaoELogin(ctx, options) {
|
|
|
677
782
|
}).catch((logError) => ctx.logger.debug(`Could not persist XiaoE auth error log: ${logError instanceof Error ? logError.message : String(logError)}`));
|
|
678
783
|
throw error;
|
|
679
784
|
}
|
|
680
|
-
async function runBrowserLogin(ctx, options) {
|
|
785
|
+
async function runBrowserLogin(ctx, options, loginMode = {}) {
|
|
681
786
|
const commandOpts = asOptions(options);
|
|
682
787
|
const globalOptions = ctx.getGlobalOptions();
|
|
683
788
|
const profileFromGlobal = globalOptions.profile;
|
|
@@ -692,40 +797,54 @@ async function runBrowserLogin(ctx, options) {
|
|
|
692
797
|
const hostKey = target.hostKey;
|
|
693
798
|
const baseUrl = normalizeUrl(explicitBaseUrl || target.cfg.baseUrl || resolveDefaultE10BaseUrl(ctx.env));
|
|
694
799
|
const tenantKey = optionString(commandOpts, 'tenantKey');
|
|
695
|
-
const
|
|
696
|
-
const
|
|
697
|
-
|
|
800
|
+
const explicitPort = optionString(commandOpts, 'port');
|
|
801
|
+
const portText = explicitPort || '19800';
|
|
802
|
+
let port = Number(portText);
|
|
803
|
+
if (!/^\d+$/u.test(portText) || !Number.isInteger(port) || port < 0 || port > 65535) {
|
|
698
804
|
throw new CliError('Invalid --port value', ExitCode.UsageError);
|
|
699
805
|
}
|
|
700
|
-
|
|
806
|
+
// `auth init` 必须在回调后完成平台契约,显式返回地址也不能拖住其 stdout 和退出。
|
|
807
|
+
const machineMode = loginMode.machine === true || isMachineAuthMode();
|
|
808
|
+
const agentReturnTarget = loginMode.machine === true ? null
|
|
809
|
+
: resolveAgentReturnTarget(commandOpts, ctx.env, agentType, { machine: machineMode });
|
|
701
810
|
const agentReturnToken = agentReturnTarget ? randomBytes(24).toString('base64url') : '';
|
|
702
|
-
const
|
|
703
|
-
|
|
704
|
-
|
|
811
|
+
const successHeaders = {
|
|
812
|
+
'cache-control': 'no-store',
|
|
813
|
+
'content-security-policy': agentReturnTarget
|
|
814
|
+
? `default-src 'none'; style-src 'unsafe-inline'; script-src 'nonce-${agentReturnToken}'; connect-src 'self'`
|
|
815
|
+
: `default-src 'none'; style-src 'unsafe-inline'`,
|
|
816
|
+
'content-type': 'text/html; charset=utf-8',
|
|
817
|
+
'referrer-policy': 'no-referrer',
|
|
818
|
+
'x-content-type-options': 'nosniff',
|
|
819
|
+
'x-frame-options': 'DENY',
|
|
820
|
+
};
|
|
821
|
+
let redirectUri = '';
|
|
822
|
+
if (machineMode && !agentReturnTarget) {
|
|
823
|
+
// 连接器/非交互宿主:回调成功即收口,不等弹层,避免宿主按「进程退出」判定时超时失败。
|
|
824
|
+
ctx.logger.info('Machine mode: closing the callback server right after authorization.');
|
|
825
|
+
}
|
|
705
826
|
ctx.logger.info('Waiting for E10 authorization callback...');
|
|
706
827
|
return await new Promise((resolve, reject) => {
|
|
707
828
|
let settled = false;
|
|
708
829
|
let timer = null;
|
|
709
830
|
let pendingLoginResult = null;
|
|
710
831
|
let tlsCallbackDetected = false;
|
|
832
|
+
let exchanging = false;
|
|
833
|
+
let retriedPort = false;
|
|
711
834
|
const finish = (error, result) => {
|
|
712
835
|
if (settled)
|
|
713
836
|
return;
|
|
714
837
|
settled = true;
|
|
715
838
|
if (timer)
|
|
716
839
|
clearTimeout(timer);
|
|
717
|
-
|
|
840
|
+
// keep-alive 连接会拖住 server.close() 的回调,必须强制释放,
|
|
841
|
+
// 否则依赖「进程退出」判定授权结果的宿主会一直等不到 stdout。
|
|
842
|
+
closeHttpServer(server, () => {
|
|
718
843
|
if (error)
|
|
719
844
|
reject(error);
|
|
720
845
|
else
|
|
721
846
|
resolve(result);
|
|
722
|
-
};
|
|
723
|
-
try {
|
|
724
|
-
server.close(complete);
|
|
725
|
-
}
|
|
726
|
-
catch {
|
|
727
|
-
complete();
|
|
728
|
-
}
|
|
847
|
+
});
|
|
729
848
|
};
|
|
730
849
|
const server = createServer(async (req, res) => {
|
|
731
850
|
const callbackUrl = new URL(req.url || '/', `http://127.0.0.1:${port}`);
|
|
@@ -759,8 +878,10 @@ async function runBrowserLogin(ctx, options) {
|
|
|
759
878
|
res.end('{"ok":true}');
|
|
760
879
|
finish(null, result);
|
|
761
880
|
}
|
|
762
|
-
catch {
|
|
763
|
-
|
|
881
|
+
catch (openError) {
|
|
882
|
+
// 把真实的 spawn 失败原因(如 ENOENT)打到日志,否则只剩「请确认应用已安装」,
|
|
883
|
+
// 排查时无法区分「没装应用」和「找不到 rundll32 / PATH 被清空」。
|
|
884
|
+
ctx.logger.warn(`Could not open ${agentReturnTarget.label} automatically (${describeOpenFailure(openError)}).`);
|
|
764
885
|
res.writeHead(500, { 'cache-control': 'no-store', 'content-type': 'text/plain; charset=utf-8' });
|
|
765
886
|
res.end(`无法打开 ${agentReturnTarget.label},请确认应用已安装。`);
|
|
766
887
|
}
|
|
@@ -771,6 +892,17 @@ async function runBrowserLogin(ctx, options) {
|
|
|
771
892
|
res.end('Not found');
|
|
772
893
|
return;
|
|
773
894
|
}
|
|
895
|
+
// 授权码只能换票一次,刷新或并发回调不能重放换票并把已成功的登录变成失败。
|
|
896
|
+
if (pendingLoginResult) {
|
|
897
|
+
res.writeHead(200, successHeaders);
|
|
898
|
+
res.end(renderE10LoginSuccessPage(pendingLoginResult.userId, agentReturnTarget, agentReturnToken));
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
901
|
+
if (exchanging || settled) {
|
|
902
|
+
res.writeHead(409, { 'cache-control': 'no-store', 'content-type': 'text/plain; charset=utf-8' });
|
|
903
|
+
res.end('Authorization callback already received.');
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
774
906
|
const error = callbackUrl.searchParams.get('error');
|
|
775
907
|
const code = callbackUrl.searchParams.get('code');
|
|
776
908
|
const redirectAgentType = explicitAgentType
|
|
@@ -799,24 +931,15 @@ async function runBrowserLogin(ctx, options) {
|
|
|
799
931
|
timer = null;
|
|
800
932
|
}
|
|
801
933
|
try {
|
|
934
|
+
exchanging = true;
|
|
802
935
|
const result = await oidcExchange(code, redirectUri, baseUrl, tenantKey, redirectAgentType, profileFromGlobal, hostKey);
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
'content-security-policy': agentReturnTarget
|
|
806
|
-
? `default-src 'none'; style-src 'unsafe-inline'; script-src 'nonce-${agentReturnToken}'; connect-src 'self'`
|
|
807
|
-
: `default-src 'none'; style-src 'unsafe-inline'`,
|
|
808
|
-
'content-type': 'text/html; charset=utf-8',
|
|
809
|
-
'referrer-policy': 'no-referrer',
|
|
810
|
-
'x-content-type-options': 'nosniff',
|
|
811
|
-
'x-frame-options': 'DENY',
|
|
812
|
-
};
|
|
813
|
-
res.writeHead(200, responseHeaders);
|
|
936
|
+
pendingLoginResult = result;
|
|
937
|
+
res.writeHead(200, successHeaders);
|
|
814
938
|
res.end(renderE10LoginSuccessPage(result.userId, agentReturnTarget, agentReturnToken));
|
|
815
939
|
if (!agentReturnTarget) {
|
|
816
940
|
finish(null, result);
|
|
817
941
|
return;
|
|
818
942
|
}
|
|
819
|
-
pendingLoginResult = result;
|
|
820
943
|
if (timer)
|
|
821
944
|
clearTimeout(timer);
|
|
822
945
|
timer = setTimeout(() => finish(null, result), AGENT_RETURN_TIMEOUT_MS);
|
|
@@ -829,6 +952,12 @@ async function runBrowserLogin(ctx, options) {
|
|
|
829
952
|
}
|
|
830
953
|
});
|
|
831
954
|
server.on('error', (error) => {
|
|
955
|
+
if (error.code === 'EADDRINUSE' && !explicitPort && !retriedPort) {
|
|
956
|
+
retriedPort = true;
|
|
957
|
+
ctx.logger.warn(`Port ${port} is already in use. Using an available callback port.`);
|
|
958
|
+
server.listen(0, '127.0.0.1');
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
832
961
|
const message = error.code === 'EADDRINUSE'
|
|
833
962
|
? `Port ${port} is already in use. Retry with --port ${port + 1}.`
|
|
834
963
|
: error.code === 'EACCES'
|
|
@@ -856,10 +985,20 @@ async function runBrowserLogin(ctx, options) {
|
|
|
856
985
|
}
|
|
857
986
|
socket.destroy();
|
|
858
987
|
});
|
|
859
|
-
server.
|
|
988
|
+
server.once('listening', () => {
|
|
989
|
+
const address = server.address();
|
|
990
|
+
if (!address || typeof address === 'string') {
|
|
991
|
+
finish(new CliError('Could not resolve local OAuth callback port.', ExitCode.UsageError));
|
|
992
|
+
return;
|
|
993
|
+
}
|
|
994
|
+
port = address.port;
|
|
995
|
+
redirectUri = `http://127.0.0.1:${port}/callback`;
|
|
996
|
+
const loginUrl = buildE10AuthorizeUrl(baseUrl, redirectUri, agentType);
|
|
997
|
+
ctx.logger.info('Open browser login: ' + loginUrl);
|
|
860
998
|
ctx.logger.info('Local callback server: ' + redirectUri);
|
|
861
999
|
openUrlInBrowser(loginUrl, ctx);
|
|
862
1000
|
});
|
|
1001
|
+
server.listen(port, '127.0.0.1');
|
|
863
1002
|
timer = setTimeout(() => {
|
|
864
1003
|
finish(new CliError('Login timed out after 5 minutes.', ExitCode.AuthError));
|
|
865
1004
|
}, 300_000);
|
|
@@ -1007,7 +1146,7 @@ function registerBrowserLoginCommand(auth, action, name, description, machine =
|
|
|
1007
1146
|
.description(description)
|
|
1008
1147
|
.option('--base-url <url>', 'E10 base URL (defaults to https://weapp.eteams.cn)')
|
|
1009
1148
|
.option('--tenant-key <key>', 'Tenant key fallback after login')
|
|
1010
|
-
.option('--port <n>', 'Local OAuth callback port
|
|
1149
|
+
.option('--port <n>', 'Local OAuth callback port (default: 19800 with automatic fallback; 0 selects an available port)')
|
|
1011
1150
|
.option('--agent_type <value>', 'Agent type sent to E10 authorize endpoint')
|
|
1012
1151
|
.option('--agent-type <value>', 'Alias of --agent_type')
|
|
1013
1152
|
.option('--agent-return-url <url>', 'Desktop application URL linked by the login success page');
|
|
@@ -1020,7 +1159,7 @@ function registerBrowserLoginCommand(auth, action, name, description, machine =
|
|
|
1020
1159
|
// 平台型连接器契约:stdout 只出严格 JSON,进度与授权链接走 stderr。
|
|
1021
1160
|
ctx.logger.machineMode = true;
|
|
1022
1161
|
try {
|
|
1023
|
-
const result = await runBrowserLogin(ctx, options);
|
|
1162
|
+
const result = await runBrowserLogin(ctx, options, { machine: true });
|
|
1024
1163
|
ctx.output.raw(JSON.stringify({
|
|
1025
1164
|
status: 'authorized',
|
|
1026
1165
|
employeeId: result.userId || '',
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 合同链路错误动作目录(2026-11-20 P2)。
|
|
3
|
+
*
|
|
4
|
+
* ## 解决什么问题
|
|
5
|
+
*
|
|
6
|
+
* 2026-11-20 事故的第一轮输出是:
|
|
7
|
+
*
|
|
8
|
+
* > 「上传接口要求合同总金额必须是大于 0 的真实数值,而报价书里的金额在我这边显示为脱敏
|
|
9
|
+
* > 占位符,无法直接作为数值传入。因此合同暂时没能上传进系统……」
|
|
10
|
+
*
|
|
11
|
+
* 工具当时只报了一句 `total_amount_required`(**形态非法**),模型把它翻译成了**业务结论**
|
|
12
|
+
* (**数据不可得**),于是链路在第一步就停了——而真值一直在本地。
|
|
13
|
+
*
|
|
14
|
+
* 根因不是模型判断力,而是**错误载荷里没有动作**:错误只说明「哪一步没过」,没有说明
|
|
15
|
+
* 「下一步做什么、不许下什么结论」。本目录把这件事变成机器判据——每个错误码都带
|
|
16
|
+
* `details.action`:
|
|
17
|
+
*
|
|
18
|
+
* ```json
|
|
19
|
+
* "details": {
|
|
20
|
+
* "action": {
|
|
21
|
+
* "action": "fix-input",
|
|
22
|
+
* "requiredAction": "把 totalAmount 改成 $quote 引用或纯数值后重跑……",
|
|
23
|
+
* "forbiddenClaims": ["金额不可得", "需要用户提供金额", "无法生成合同"]
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* 注入点在 `contractValidationError()`:所有合同校验错误自动携带,无遗漏、无重复实现。
|
|
29
|
+
*/
|
|
30
|
+
/** 报价单转合同链路的错误码 → 动作。新增错误码时一并登记,避免又出现「只有报错没有动作」。 */
|
|
31
|
+
export const CONTRACT_ERROR_ACTIONS = {
|
|
32
|
+
// ── 金额形态(2026-11-20 P0 守卫)
|
|
33
|
+
total_amount_required: {
|
|
34
|
+
action: 'fix-input',
|
|
35
|
+
requiredAction: '补传 totalAmount;优先用 {"$quote":"<报价书解析结果.json 绝对路径>#totals.final_total"},真值由 CLI 本地读取,重跑本步',
|
|
36
|
+
forbiddenClaims: ['金额不可得', '需要用户提供金额', '无法生成合同'],
|
|
37
|
+
},
|
|
38
|
+
total_amount_placeholder: {
|
|
39
|
+
action: 'fix-input',
|
|
40
|
+
requiredAction: '把 totalAmount 改成 {"$quote":"<解析结果.json>#totals.final_total"} 或纯数值后重跑;不要再传 [[MONEY_*]]',
|
|
41
|
+
forbiddenClaims: ['金额不可得', '需要用户提供金额', '无法上传合同'],
|
|
42
|
+
},
|
|
43
|
+
sections_amount_placeholder: {
|
|
44
|
+
action: 'fix-input',
|
|
45
|
+
requiredAction: '把 sections 改成 {"$quote":"<解析结果.json>#sections"},或不传 sections(背景说明会退化为不含费用构成)后重跑',
|
|
46
|
+
forbiddenClaims: ['金额不可得', '需要用户提供金额'],
|
|
47
|
+
},
|
|
48
|
+
plan_value_placeholder: {
|
|
49
|
+
action: 'fix-input',
|
|
50
|
+
requiredAction: '把 plan 里写成占位符的金额位点改成 $quote 引用或纯数值后重跑 contract.docx.slots.fill',
|
|
51
|
+
forbiddenClaims: ['金额不可得', '需要用户提供金额', '无法生成合同'],
|
|
52
|
+
},
|
|
53
|
+
plan_value_display_text: {
|
|
54
|
+
action: 'fix-input',
|
|
55
|
+
requiredAction: '金额位点去掉货币符号,改传 $quote 引用或纯数值后重跑 slots.fill',
|
|
56
|
+
forbiddenClaims: ['金额不可得', '需要用户提供金额'],
|
|
57
|
+
},
|
|
58
|
+
// ── 值引用通道(2026-11-20 P1)
|
|
59
|
+
quote_ref_unresolved: {
|
|
60
|
+
action: 'fix-path',
|
|
61
|
+
requiredAction: '按 details.errors 里给出的位置与「该文件顶层可用字段」修正 $quote 的文件路径或字段路径后重跑;'
|
|
62
|
+
+ '解析结果需先用 contract.quote.parse / contract.quote.normalize 的 out 参数落盘',
|
|
63
|
+
forbiddenClaims: ['报价书有问题', '需要用户重新提供报价书'],
|
|
64
|
+
},
|
|
65
|
+
quote_placeholder_in_model_json: {
|
|
66
|
+
action: 'obtain-source',
|
|
67
|
+
requiredAction: '占位符不是金额、本地也无法还原:① 有该报价书的 .xlsx 原件时改走 contract.quote.parse(真值由代码在本地算出)并用 out 落盘;'
|
|
68
|
+
+ '② 只有 .docx 原件时,先确认本地确无 .xlsx 或已算好的解析结果,再说明缺的是哪一个文件',
|
|
69
|
+
forbiddenClaims: ['报价书未填写金额', '金额不可得'],
|
|
70
|
+
},
|
|
71
|
+
// ── 文件与路径
|
|
72
|
+
quote_normalize_invalid: { action: 'fix-input', requiredAction: '按报错修正模型产出的报价 JSON 后重跑 normalize' },
|
|
73
|
+
quote_normalize_source_missing: { action: 'fix-input', requiredAction: '补传模型产出的报价 JSON 文件路径(data)后重跑' },
|
|
74
|
+
plan_not_found: { action: 'fix-path', requiredAction: '核对 plan 文件路径后重跑 slots.fill' },
|
|
75
|
+
plan_required: { action: 'fix-path', requiredAction: '补传 plan(填充方案对象或其 JSON 文件路径)后重跑 slots.fill' },
|
|
76
|
+
template_required: { action: 'fix-path', requiredAction: '补传模板 docx 绝对路径后重跑' },
|
|
77
|
+
template_not_found: { action: 'obtain-source', requiredAction: '确认模板文件已下载到本地(contract file download)后重跑' },
|
|
78
|
+
contract_path_required: { action: 'fix-path', requiredAction: '补传生成的合同 docx 绝对路径后重跑' },
|
|
79
|
+
contract_path_not_found: { action: 'fix-path', requiredAction: '核对合同 docx 路径(应先跑 slots.fill 生成)后重跑' },
|
|
80
|
+
file_type_unsupported: { action: 'obtain-source', requiredAction: '把 .xls / .doc 另存为 .xlsx / .docx 后重跑' },
|
|
81
|
+
// ── 业务参数
|
|
82
|
+
customer_required: { action: 'fix-input', requiredAction: '补传 customerName(报价单客户全称)后重跑' },
|
|
83
|
+
customer_not_found: { action: 'fix-input', requiredAction: '按报价单判读客户全称后重跑' },
|
|
84
|
+
flow_required: { action: 'fix-input', requiredAction: '按报价单类型标识确认 flow(契约锁 / 新客户 / 常规二次销售 / 老客户增值)后传入重跑' },
|
|
85
|
+
flow_not_builtin: { action: 'fix-input', requiredAction: '改用四个内置流程之一后重跑' },
|
|
86
|
+
tab_invalid: { action: 'fix-input', requiredAction: '改用合法 tab 后重跑' },
|
|
87
|
+
file_id_required: { action: 'fix-path', requiredAction: '先跑 contract.flow.launch 拿到 workflow fileId,再传入重跑' },
|
|
88
|
+
recognize_result_invalid: {
|
|
89
|
+
action: 'fix-input',
|
|
90
|
+
requiredAction: 'recognizeResult 必须内联为 JSON 对象(不能传文件路径字符串)后重跑',
|
|
91
|
+
},
|
|
92
|
+
input_invalid: { action: 'fix-input', requiredAction: '按报错修正入参后重跑' },
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* 把动作挂到错误 `details` 上。
|
|
96
|
+
*
|
|
97
|
+
* 只在目录命中时生效;`details` 是对象就合并,是标量/数组就放进 `value`,避免覆盖原有信息。
|
|
98
|
+
*/
|
|
99
|
+
export function withRequiredAction(subtype, details) {
|
|
100
|
+
const entry = CONTRACT_ERROR_ACTIONS[subtype];
|
|
101
|
+
if (!entry)
|
|
102
|
+
return details;
|
|
103
|
+
const action = { action: entry.action, requiredAction: entry.requiredAction };
|
|
104
|
+
if (entry.forbiddenClaims?.length)
|
|
105
|
+
action.forbiddenClaims = entry.forbiddenClaims;
|
|
106
|
+
if (details === undefined || details === null)
|
|
107
|
+
return { action };
|
|
108
|
+
if (typeof details === 'object' && !Array.isArray(details)) {
|
|
109
|
+
return { ...details, action };
|
|
110
|
+
}
|
|
111
|
+
return { value: details, action };
|
|
112
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CliError, ExitCode } from '../../core/errors.js';
|
|
2
|
+
import { withRequiredAction } from './error-actions.js';
|
|
2
3
|
export class ContractCliError extends CliError {
|
|
3
4
|
type;
|
|
4
5
|
subtype;
|
|
@@ -19,9 +20,16 @@ export class ContractCliError extends CliError {
|
|
|
19
20
|
this.partialData = options.partialData;
|
|
20
21
|
}
|
|
21
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* 合同链路校验错误。
|
|
25
|
+
*
|
|
26
|
+
* 2026-11-20 P2:错误码命中 `error-actions.ts` 目录时,自动把「下一步动作 + 不许下的结论」
|
|
27
|
+
* 挂到 `details.action` 上。事故复盘见该文件开头——当时只有 `total_amount_required`
|
|
28
|
+
* 一句形态描述,模型把它读成了「金额不可得」并停止链路。
|
|
29
|
+
*/
|
|
22
30
|
export function contractValidationError(subtype, message, details) {
|
|
23
31
|
return new ContractCliError('validation', subtype, message, {
|
|
24
|
-
details,
|
|
32
|
+
details: withRequiredAction(subtype, details),
|
|
25
33
|
exitCode: ExitCode.UsageError,
|
|
26
34
|
});
|
|
27
35
|
}
|
|
@@ -458,7 +458,7 @@ const quoteContracts = [
|
|
|
458
458
|
out: { type: 'string', minLength: 1, maxLength: 4096, description: '输出 docx 绝对路径' },
|
|
459
459
|
plan: {
|
|
460
460
|
anyOf: [{ type: 'object' }, { type: 'string' }],
|
|
461
|
-
description: '填充方案:{ slots:[{slotId,value}], details:[{slotId,items,subtotal}], unsupported:[], totals:{grandTotal,installments} };也可传 JSON
|
|
461
|
+
description: '填充方案:{ slots:[{slotId,value}], details:[{slotId,items,subtotal}], unsupported:[], totals:{grandTotal,installments} };也可传 JSON 文件路径。金额一律不要手写数值,用值引用 {"$quote":"<报价书解析结果.json 绝对路径>#totals.final_total"}(明细可用 #sections.0.items、小计用 #sections.0.total),真值由本进程读;写 [[MONEY_*]] 报 plan_value_placeholder、写 ¥144,000.00 报 plan_value_display_text,均拒绝写入',
|
|
462
462
|
},
|
|
463
463
|
strict: { type: 'boolean', description: '默认 true:必填位点未覆盖即判不通过' },
|
|
464
464
|
allowRowInsert: { type: 'boolean', description: '默认 true:明细行不足时克隆已有行补足(不改网格)' },
|
|
@@ -470,7 +470,7 @@ const quoteContracts = [
|
|
|
470
470
|
fixed: { local: true, kind: 'docx-verify' },
|
|
471
471
|
inputSchema: readSchema({
|
|
472
472
|
path: { type: 'string', minLength: 1, maxLength: 4096, description: 'docx 绝对路径' },
|
|
473
|
-
patterns: { type: 'array', items: { type: 'string' }, description: '需要检查残留的占位文本;缺省用内置集合(xxx
|
|
473
|
+
patterns: { type: 'array', items: { type: 'string' }, description: '需要检查残留的占位文本;缺省用内置集合([[MONEY / MONEY_ / xxx公司 / ***有限公司 / 年 月 日 / 【】 / ____ / {{ 等)' },
|
|
474
474
|
title: { type: 'string', description: '应出现的合同名称,用于校验标题替换是否完整' },
|
|
475
475
|
titleCount: { type: 'integer', minimum: 0, description: '标题期望出现次数;传了就要求精确相等,不传只要求至少 1 次' },
|
|
476
476
|
out: { type: 'string', maxLength: 4096, description: '可选:校验报告 JSON 输出路径' },
|
|
@@ -486,9 +486,15 @@ const quoteContracts = [
|
|
|
486
486
|
customerName: { type: 'string', minLength: 1, description: '报价单客户全称(即最终用户)' },
|
|
487
487
|
contractTitle: { type: 'string', maxLength: 400, description: '合同名称;缺省按「客户全称 + 合同管理系统软件产品及实施服务购买合同」生成' },
|
|
488
488
|
contractFileName: { type: 'string', maxLength: 400, description: '合同文件落盘名;缺省与 contractTitle 同名,通用名(如「合同」)会被纠正为合同名称' },
|
|
489
|
-
totalAmount: {
|
|
489
|
+
totalAmount: {
|
|
490
|
+
anyOf: [{ type: 'number' }, { type: 'string' }, { type: 'object' }],
|
|
491
|
+
description: '报价单最终优惠报价(不是标准价合计)。三选一:① 纯数值(如 809166.76);② 可唯一归一的字符串(如 "¥809,166.76");③ **推荐**值引用 {"$quote":"<解析结果.json 绝对路径>#totals.final_total"},真值由本进程读、金额不经过模型上下文。传脱敏占位符 [[MONEY_*]] 会被 total_amount_placeholder 拒收',
|
|
492
|
+
},
|
|
490
493
|
ourCompany: { type: 'string', description: '我方签约主体,默认「泛微网络科技股份有限公司」' },
|
|
491
|
-
sections: {
|
|
494
|
+
sections: {
|
|
495
|
+
anyOf: [{ type: 'array', items: { type: 'object' }, }, { type: 'object' }],
|
|
496
|
+
description: '报价单费用分节,用于归纳合同背景说明。可传数组,也可传值引用 {"$quote":"<解析结果.json>#sections"}(解析结果的 sections 已含 title/total,能被直接消费)',
|
|
497
|
+
},
|
|
492
498
|
background: { type: 'string', maxLength: 2000, description: '合同背景说明;不传按报价单分节自动归纳' },
|
|
493
499
|
quoteTitle: { type: 'string', description: '报价单标题,供合同类型识别' },
|
|
494
500
|
quoteFileName: { type: 'string', description: '报价单文件名,供合同类型识别' },
|
|
@@ -504,7 +510,10 @@ const quoteContracts = [
|
|
|
504
510
|
contractPath: { type: 'string', minLength: 1, maxLength: 4096, description: '生成的合同 docx 绝对路径(quotescreen.tocontract 的 contract.path)' },
|
|
505
511
|
flow: { type: 'string', enum: ['契约锁', '新客户', '常规二次销售', '老客户增值'], description: '合同类型;须由编排层按报价单标识确认后传入' },
|
|
506
512
|
customerName: { type: 'string', minLength: 1, description: '报价单客户全称(即最终用户)' },
|
|
507
|
-
totalAmount: {
|
|
513
|
+
totalAmount: {
|
|
514
|
+
anyOf: [{ type: 'number' }, { type: 'string' }, { type: 'object' }],
|
|
515
|
+
description: '报价单最终优惠报价(不是标准价合计)。三选一:① 纯数值(如 809166.76);② 可唯一归一的字符串(如 "¥809,166.76");③ **推荐**值引用 {"$quote":"<解析结果.json 绝对路径>#totals.final_total"}。传脱敏占位符 [[MONEY_*]] 会被 total_amount_placeholder 拒收',
|
|
516
|
+
},
|
|
508
517
|
contractTitle: { type: 'string', maxLength: 400, description: '合同名称;缺省按「客户全称 + 合同管理系统软件产品及实施服务购买合同」生成' },
|
|
509
518
|
fileName: { type: 'string', maxLength: 400, description: '合同文件名;缺省取 contractPath 的文件名,通用名(如「合同」)会被纠正为合同名称' },
|
|
510
519
|
ourCompany: { type: 'string', description: '我方签约主体,默认「泛微网络科技股份有限公司」' },
|
|
@@ -613,7 +622,7 @@ const quoteContracts = [
|
|
|
613
622
|
title: { type: 'string', description: '卡片标题,默认取菜单名' },
|
|
614
623
|
callId: { type: 'string', description: '默认 ledger-<菜单>-<YYYYMMDDHHmm>-01;列表卡为 ebdf-list-<菜单>-<YYYYMMDDHHmm>-01' },
|
|
615
624
|
comParamPairs: { type: 'array', items: { type: 'string' }, description: '台账页:形如 khmc=泛微 的台账键(日期/金额区间请用 comParamsJson);列表卡:形如 field_<字段id>=<值>;与 comParamsJson 互斥' },
|
|
616
|
-
comParamsJson: { type: 'string', description: '筛选对象的 JSON
|
|
625
|
+
comParamsJson: { type: 'string', description: '筛选对象的 JSON 字符串(必须序列化成字符串传,不能直接传对象):台账页传 { "khmc": "泛微", "qdrq": ["2024-01-01", "2024-12-31"] };列表卡传 comParams 对象;与 comParamPairs 互斥' },
|
|
617
626
|
out: { type: 'string', maxLength: 4096, description: '可选:卡片 JSON 输出路径' },
|
|
618
627
|
}),
|
|
619
628
|
},
|
|
@@ -702,6 +711,7 @@ const quoteContracts = [
|
|
|
702
711
|
sheet: { type: 'string' },
|
|
703
712
|
keepRemark: { type: 'boolean' },
|
|
704
713
|
includeZero: { type: 'boolean' },
|
|
714
|
+
out: { type: 'string', maxLength: 4096, description: '可选:把解析结果写成 JSON。落盘后后续可用 {"$quote":"<该文件>#totals.final_total"} 引用真值,金额不经过模型上下文' },
|
|
705
715
|
}, ['path']),
|
|
706
716
|
},
|
|
707
717
|
{
|
|
@@ -717,7 +727,8 @@ const quoteContracts = [
|
|
|
717
727
|
risk: 'read',
|
|
718
728
|
fixed: { local: true, kind: 'quote-normalize' },
|
|
719
729
|
inputSchema: readSchema({
|
|
720
|
-
data: { type: 'string', minLength: 1 },
|
|
730
|
+
data: { type: 'string', minLength: 1, description: '模型产出的报价 JSON 文件路径' },
|
|
731
|
+
out: { type: 'string', maxLength: 4096, description: '可选:把归一化后的解析结果写成 JSON。落盘后后续可用 {"$quote":"<该文件>#totals.final_total"} 引用真值' },
|
|
721
732
|
}, ['data']),
|
|
722
733
|
},
|
|
723
734
|
];
|