weaver-work-cli 0.1.60 → 0.1.62
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-4SQAVTIB.js → archive-S2VKZWQ3.js} +2 -2
- package/dist/chunks/{archive-oa-W2UEJ67L.js → archive-oa-HEDSIUUY.js} +2 -2
- package/dist/chunks/{asset-EGZEABBI.js → asset-HYH4W357.js} +2 -2
- package/dist/chunks/{asset-idle-EBUZBB6M.js → asset-idle-N7REBNGL.js} +2 -2
- package/dist/chunks/{attachment-content-I6WHKGR2.js → attachment-content-VYYA75FR.js} +3 -3
- package/dist/chunks/{blog-2YKMWOWI.js → blog-SLMZZICV.js} +2 -2
- package/dist/chunks/{caizhilian-5NM4X5HG.js → caizhilian-RV43KKBT.js} +4 -4
- package/dist/chunks/{calendar-H4QTJCUY.js → calendar-DMVZ4OLY.js} +2 -2
- package/dist/chunks/{chunk-VLL6JOB4.js → chunk-6XSSAUNW.js} +4 -4
- package/dist/chunks/{chunk-VQWPQTEY.js → chunk-BIA2NKUG.js} +4 -4
- package/dist/chunks/{chunk-VMCCRWFO.js → chunk-BQYX2UX5.js} +2 -2
- package/dist/chunks/{chunk-XF7S6FQW.js → chunk-DTCQFTHW.js} +1 -1
- package/dist/chunks/{chunk-CPG6NLN4.js → chunk-E5YD5JWR.js} +1 -1
- package/dist/chunks/{chunk-PH7N4UFT.js → chunk-EGANE35F.js} +1 -1
- package/dist/chunks/{chunk-Z4IPY5GV.js → chunk-H6YOMI3U.js} +2 -2
- package/dist/chunks/{chunk-HHH4K3YY.js → chunk-ILALC2N6.js} +1 -1
- package/dist/chunks/{chunk-WINR2Q6K.js → chunk-KXJA42EA.js} +86 -19
- package/dist/chunks/{chunk-CQ4OVCKG.js → chunk-KY3R42RS.js} +2 -2
- package/dist/chunks/{chunk-WVH5ESDA.js → chunk-NRYDJN4J.js} +1 -1
- package/dist/chunks/{chunk-TGM7BWEH.js → chunk-P6TXQK75.js} +2 -2
- package/dist/chunks/{chunk-6YWHRXEQ.js → chunk-QBDXJS2W.js} +119 -9
- package/dist/chunks/{chunk-2IGZUMNG.js → chunk-SHX7XBYR.js} +180 -18
- package/dist/chunks/{chunk-P7RXQDCA.js → chunk-T2KVJFWJ.js} +4 -4
- package/dist/chunks/{chunk-FMNCSYIG.js → chunk-TEZHIB6T.js} +2 -2
- package/dist/chunks/{chunk-HMIIVM2L.js → chunk-UBGWIXU3.js} +97 -45
- package/dist/chunks/{chunk-5N222HK6.js → chunk-UBRWONP4.js} +2 -2
- package/dist/chunks/{chunk-7U5YHCW7.js → chunk-UQFPF4EX.js} +2 -2
- package/dist/chunks/{chunk-4GG72JAT.js → chunk-V2LASYKO.js} +2 -2
- package/dist/chunks/{chunk-BDBTZVYA.js → chunk-VBFBMM7G.js} +55 -55
- package/dist/chunks/{chunk-YHSOCGKO.js → chunk-VNYOUAWV.js} +11 -11
- package/dist/chunks/{chunk-SFM3M2L3.js → chunk-WIWDVETN.js} +19 -3
- package/dist/chunks/{chunk-44KJ7WFA.js → chunk-XT77MP54.js} +2 -2
- package/dist/chunks/{chunk-JFKMPRZB.js → chunk-YI2YMW5N.js} +50 -3
- package/dist/chunks/{conflict-QMDLS2EW.js → conflict-GFJRS6I7.js} +2 -2
- package/dist/chunks/{contract-LLRKMLQQ.js → contract-U3ZGNRWB.js} +2 -2
- package/dist/chunks/{cowork-2RDFBZWB.js → cowork-EX7PKIDK.js} +2 -2
- package/dist/chunks/{create-flow-5ODJ7WJO.js → create-flow-EJZD434E.js} +6 -6
- package/dist/chunks/{data-LVDFIRNG.js → data-FOODGAMF.js} +278 -121
- package/dist/chunks/{ebuilder-form-7WA6X6ZI.js → ebuilder-form-I2EOKODG.js} +3 -3
- package/dist/chunks/{ehr-52GBKNJR.js → ehr-TE4RFNID.js} +2 -2
- package/dist/chunks/{entry-mode-73BJML22.js → entry-mode-ZOLSXEGX.js} +9 -5
- package/dist/chunks/{env-OHFS76HV.js → env-TID5NFR6.js} +2 -2
- package/dist/chunks/{esb-HJSXCEOM.js → esb-7L6MHYLB.js} +4 -4
- package/dist/chunks/{factory-FRTA2LP4.js → factory-OG7BPMH5.js} +1 -1
- package/dist/chunks/{fna-OBACRT3J.js → fna-6V2ENR3Y.js} +2 -2
- package/dist/chunks/{group-chat-KBFRPCR2.js → group-chat-5DKPWIHL.js} +3 -3
- package/dist/chunks/{host-TTSGY5NZ.js → host-3DLYA54R.js} +3 -3
- package/dist/chunks/{host-KJT3G5D2.js → host-GOJHHTPY.js} +3 -3
- package/dist/chunks/{host-KOWUMNAY.js → host-OGBHL75G.js} +3 -3
- package/dist/chunks/{host-MFXRA2MY.js → host-ONZC6AE7.js} +3 -3
- package/dist/chunks/{host-W4JCNRFS.js → host-TJ5VVHM7.js} +3 -3
- package/dist/chunks/{host-2BKMPWDH.js → host-VTPAWDZV.js} +3 -3
- package/dist/chunks/{hrm-AK3WGBMN.js → hrm-2N7NFQDZ.js} +3 -3
- package/dist/chunks/{im-JZSBPO4Z.js → im-XCH47ZBN.js} +3 -3
- package/dist/chunks/{invoice-6XDMPCWB.js → invoice-5KJ7T774.js} +198 -331
- package/dist/chunks/{jiuchuanhui-K4EQU6GK.js → jiuchuanhui-PL6DRPBM.js} +2 -2
- package/dist/chunks/{lazy-dispatch-GCA6HDOB.js → lazy-dispatch-UATEN7H7.js} +5 -5
- package/dist/chunks/{mail-IKVCQCVZ.js → mail-Q7Z4CQ4D.js} +2 -2
- package/dist/chunks/{meeting-ARHVWK7G.js → meeting-5E3BNARL.js} +13 -13
- package/dist/chunks/{minute-doc-547KSYKR.js → minute-doc-NXRE5C77.js} +4 -4
- package/dist/chunks/{okr-KV43FPPX.js → okr-3O3XNYOK.js} +2 -2
- package/dist/chunks/{operations-6NXJ7RTE.js → operations-EZWG72FH.js} +4 -4
- package/dist/chunks/performance-Y7CPNSOR.js +1295 -0
- package/dist/chunks/{plan-WOYR4WEG.js → plan-BLGPZF5M.js} +2 -2
- package/dist/chunks/{project-CQJKBUIL.js → project-6MZMLJMP.js} +2 -2
- package/dist/chunks/{reception-MPBU3JXC.js → reception-F2VT2X52.js} +2 -2
- package/dist/chunks/{recruit-stage-USTTRHOX.js → recruit-stage-4ETIBMIW.js} +2 -2
- package/dist/chunks/{registry-GURQG4ZV.js → registry-3FYSWV3U.js} +3 -3
- package/dist/chunks/{registry-SS5J2FZQ.js → registry-7RS74TCK.js} +4 -4
- package/dist/chunks/{registry-H5HQ5QNH.js → registry-I4DVPDMU.js} +11 -11
- package/dist/chunks/{room-recommend-3UBROMZE.js → room-recommend-GWCVKCXW.js} +4 -4
- package/dist/chunks/{schedule-FTUQML6O.js → schedule-6AN63MJQ.js} +4 -4
- package/dist/chunks/{smart-extract-APX2PNIN.js → smart-extract-SR4SJJKN.js} +3 -3
- package/dist/chunks/{workflow-WMPW3WSB.js → workflow-KF7FA2UQ.js} +7 -7
- package/dist/cmd/refs/index.js +124 -4
- package/dist/core/output.js +199 -26
- package/dist/core/refs.js +36 -0
- package/dist/index.js +38 -33
- package/dist/internal/e10/auth/xiaoe.js +25 -3
- package/dist/shortcuts/caizhilian/operations/files.js +86 -15
- package/dist/shortcuts/data/index.js +12 -2
- package/dist/shortcuts/data/manifest.js +4 -2
- package/dist/shortcuts/data/operations/attribution.js +229 -0
- package/dist/shortcuts/data/operations/ds.js +87 -90
- package/dist/shortcuts/data/operations/index.js +3 -1
- package/dist/shortcuts/index.js +5 -0
- package/dist/shortcuts/invoice/manifest.js +30 -62
- package/dist/shortcuts/invoice/operations/registry.js +2 -2
- package/dist/shortcuts/invoice/operations/reim-customer.js +111 -0
- package/dist/shortcuts/invoice/operations/shared.js +0 -204
- package/dist/shortcuts/meeting/operations/eb/create-flow.js +84 -16
- package/dist/shortcuts/meeting/operations/eb/entry-mode.js +61 -7
- package/dist/shortcuts/performance/continuation.js +74 -0
- package/dist/shortcuts/performance/errors.js +65 -0
- package/dist/shortcuts/performance/host.js +105 -0
- package/dist/shortcuts/performance/index.js +109 -0
- package/dist/shortcuts/performance/manifest.js +30 -0
- package/dist/shortcuts/performance/operations/hrm-resolve.js +114 -0
- package/dist/shortcuts/performance/operations/registry.js +44 -0
- package/dist/shortcuts/performance/operations/scheme-detail.js +70 -0
- package/dist/shortcuts/performance/operations/scheme-draft.js +116 -0
- package/dist/shortcuts/performance/operations/scheme-publish.js +158 -0
- package/dist/shortcuts/performance/operations/types.js +32 -0
- package/dist/shortcuts/performance/scheme-validate.js +307 -0
- package/dist/shortcuts/performance/shared.js +158 -0
- package/docs/agent-invoice.md +1 -1
- package/docs/agent-io-channel-design.md +67 -3
- package/docs/data.md +2 -1
- package/docs/invoice.md +0 -2
- package/package.json +1 -1
- package/scripts/xiaoe_env.py +6 -1
- package/skill-template/business-info.json +19 -0
- package/skill-template/domains/performance.md +18 -0
- package/skill-template/domains/yepiaotong.md +0 -1
- package/skills/weaver-e10-caizhilian/SKILL.md +1 -1
- package/skills/weaver-e10-data/references/datasource.md +2 -1
- package/skills/weaver-e10-meeting/SKILL.md +5 -3
- package/skills/weaver-e10-performance/SKILL.md +202 -0
- package/skills/weaver-e10-performance/agents/openai.yaml +74 -0
- package/skills/weaver-e10-performance/references/default-assembly.md +108 -0
- package/skills/weaver-e10-performance/references/entity-resolution.md +69 -0
- package/skills/weaver-e10-performance/references/enums-and-normalization.md +80 -0
- package/skills/weaver-e10-performance/references/examples.md +146 -0
- package/skills/weaver-e10-performance/references/extraction-guide.md +144 -0
- package/skills/weaver-e10-performance/references/scheme-edit-req-fields.md +185 -0
- package/skills/weaver-e10-performance/references/scheme-setting-page.md +62 -0
- package/skills/weaver-e10-performance/scripts/parse_appraisal_doc.py +483 -0
- package/skills/weaver-e10-shared/references/json-output-contract.md +5 -0
- package/skills/weaver-e10-yepiaotong/SKILL.md +16 -9
- package/skills/weaver-e10-yepiaotong/references/invoice-reim-relation.md +9 -7
- package/skills/weaver-e10-yepiaotong/references/invoice-reim.md +15 -11
- package/skills/weaver-e10-yepiaotong/references/reim-api-reference.md +29 -25
- package/skills/weaver-e10-yepiaotong/references/reim-customer-search.md +89 -0
- package/skills/weaver-e10-yepiaotong/references/reim-examples.md +35 -37
- package/skills/weaver-e10-yepiaotong/references/reim-form-fill-rules.md +66 -63
- package/skills/weaver-e10-yepiaotong/references/reim-workflow.md +50 -71
- package/skills/weaver-e10-yepiaotong/references/source-manifest.json +34 -95
- package/dist/shortcuts/invoice/operations/browse-field.js +0 -17
- package/skills/weaver-e10-yepiaotong/references/invoice-browse-field-data.md +0 -204
|
@@ -83,58 +83,6 @@ const UPDATE_FIELDS = new Map([
|
|
|
83
83
|
['currency', 'string'],
|
|
84
84
|
['currencyName', 'string'],
|
|
85
85
|
]);
|
|
86
|
-
const BROWSE_TYPE_NAMES = new Map([
|
|
87
|
-
[1, '增值税专用发票'],
|
|
88
|
-
[2, '增值税普通发票'],
|
|
89
|
-
[3, '增值税电子普通发票'],
|
|
90
|
-
[4, '卷式发票'],
|
|
91
|
-
[5, '通行费增值税电子普通发票'],
|
|
92
|
-
[6, '机动车销售统一发票'],
|
|
93
|
-
[7, '定额发票'],
|
|
94
|
-
[8, '客运汽车票'],
|
|
95
|
-
[9, '航空运输电子客票行程单'],
|
|
96
|
-
[10, '火车票'],
|
|
97
|
-
[11, '出租车票'],
|
|
98
|
-
[12, '其他'],
|
|
99
|
-
[13, '汽车通行费发票'],
|
|
100
|
-
[14, '船票'],
|
|
101
|
-
[22, '二手车销售统一发票'],
|
|
102
|
-
[28, '增值税电子专用发票'],
|
|
103
|
-
[32, '电子发票(增值税专用发票)'],
|
|
104
|
-
[33, '电子发票(普通发票)'],
|
|
105
|
-
[47, '医疗收费票据'],
|
|
106
|
-
[48, '财政非税收入统一票据'],
|
|
107
|
-
[49, '海关进口增值税专用缴款书'],
|
|
108
|
-
[50, '电子发票服务平台纸质普票'],
|
|
109
|
-
[52, '完税凭证'],
|
|
110
|
-
[53, '国际小票'],
|
|
111
|
-
[54, '银行回单'],
|
|
112
|
-
[56, '代扣代缴税收缴款凭证'],
|
|
113
|
-
]);
|
|
114
|
-
const VALID_STATUS_NAMES = new Map([
|
|
115
|
-
[0, '未查验'],
|
|
116
|
-
[1, '有效已查验'],
|
|
117
|
-
[2, '有效未查验'],
|
|
118
|
-
[3, '查验失败'],
|
|
119
|
-
[4, '发票无效'],
|
|
120
|
-
[5, '票面校验不一致'],
|
|
121
|
-
]);
|
|
122
|
-
const SOURCE_NAMES = new Map([
|
|
123
|
-
[1, '微信'],
|
|
124
|
-
[2, '支付宝'],
|
|
125
|
-
[4, '邮箱'],
|
|
126
|
-
[5, '拍照'],
|
|
127
|
-
[6, '扫码'],
|
|
128
|
-
[7, '手动'],
|
|
129
|
-
[9, '查验录入'],
|
|
130
|
-
[10, '企业微信'],
|
|
131
|
-
[11, '公众号'],
|
|
132
|
-
[12, '企业台账'],
|
|
133
|
-
[13, '文件'],
|
|
134
|
-
[14, 'Excel'],
|
|
135
|
-
[15, '短信'],
|
|
136
|
-
[16, '链接录入'],
|
|
137
|
-
]);
|
|
138
86
|
export function asObject(value, name = '业务输入') {
|
|
139
87
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
140
88
|
throw invoiceValidationError('input_invalid', `${name}必须是 JSON 对象`);
|
|
@@ -307,13 +255,6 @@ export async function getDetail(input, host) {
|
|
|
307
255
|
body: { ...body, userFlag: '1', isDelFlag: '1', req_base: reqBase() },
|
|
308
256
|
});
|
|
309
257
|
}
|
|
310
|
-
export async function getDetailsByFids(fids, host) {
|
|
311
|
-
return host.invoiceRequest({
|
|
312
|
-
path: '/api/inc/get',
|
|
313
|
-
method: 'POST',
|
|
314
|
-
body: { ids: fids, mask: 0, userFlag: '1', isDelFlag: '1', req_base: reqBase() },
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
258
|
export function invoiceDetailUrl(baseUrl, fid) {
|
|
318
259
|
return `${baseUrl.replace(/\/+$/, '')}/sp/inc/incDetail?fid=${fid}`;
|
|
319
260
|
}
|
|
@@ -339,155 +280,10 @@ export function preview(info, baseUrl) {
|
|
|
339
280
|
export function workflow(name, state) {
|
|
340
281
|
return { workflow: name, version: 1, state };
|
|
341
282
|
}
|
|
342
|
-
function stringOrEmpty(value) {
|
|
343
|
-
return value === undefined || value === null ? '' : String(value);
|
|
344
|
-
}
|
|
345
283
|
export function numberOrZero(value) {
|
|
346
284
|
const parsed = Number(value);
|
|
347
285
|
return Number.isFinite(parsed) ? parsed : 0;
|
|
348
286
|
}
|
|
349
|
-
function enumName(names, value) {
|
|
350
|
-
if (value === undefined || value === null || value === '')
|
|
351
|
-
return '';
|
|
352
|
-
return names.get(numberOrZero(value)) || '';
|
|
353
|
-
}
|
|
354
|
-
function parseExt(extRaw) {
|
|
355
|
-
if (typeof extRaw !== 'string' || !extRaw.trim())
|
|
356
|
-
return {};
|
|
357
|
-
try {
|
|
358
|
-
const parsed = JSON.parse(extRaw);
|
|
359
|
-
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
|
|
360
|
-
}
|
|
361
|
-
catch {
|
|
362
|
-
return {};
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
function dateToTimestampMs(date) {
|
|
366
|
-
if (typeof date !== 'string' || !/^\d{4}-\d{2}-\d{2}$/u.test(date))
|
|
367
|
-
return 0;
|
|
368
|
-
const timestamp = Date.parse(`${date}T00:00:00+08:00`);
|
|
369
|
-
return Number.isFinite(timestamp) ? timestamp : 0;
|
|
370
|
-
}
|
|
371
|
-
function contentFor(typeName, number) {
|
|
372
|
-
if (typeName && number)
|
|
373
|
-
return `${typeName}-${number}`;
|
|
374
|
-
return typeName || number || '';
|
|
375
|
-
}
|
|
376
|
-
function cents(value) {
|
|
377
|
-
if (value === undefined || value === null || value === '')
|
|
378
|
-
return 0;
|
|
379
|
-
const text = String(value);
|
|
380
|
-
const match = /^(-?\d+)(?:\.(\d{1,2}))?$/u.exec(text);
|
|
381
|
-
if (!match)
|
|
382
|
-
return null;
|
|
383
|
-
const whole = Number(match[1]);
|
|
384
|
-
const fraction = Number((match[2] || '').padEnd(2, '0'));
|
|
385
|
-
return whole * 100 + (whole < 0 ? -fraction : fraction);
|
|
386
|
-
}
|
|
387
|
-
function moneyMinus(total, reiming, reimed) {
|
|
388
|
-
if ((reiming === undefined || reiming === null || reiming === '') && (reimed === undefined || reimed === null || reimed === '')) {
|
|
389
|
-
return stringOrEmpty(total);
|
|
390
|
-
}
|
|
391
|
-
const totalCents = cents(total);
|
|
392
|
-
const reimingCents = cents(reiming);
|
|
393
|
-
const reimedCents = cents(reimed);
|
|
394
|
-
if (totalCents === null || reimingCents === null || reimedCents === null)
|
|
395
|
-
return stringOrEmpty(total);
|
|
396
|
-
const value = totalCents - reimingCents - reimedCents;
|
|
397
|
-
const sign = value < 0 ? '-' : '';
|
|
398
|
-
const absolute = Math.abs(value);
|
|
399
|
-
const whole = Math.floor(absolute / 100);
|
|
400
|
-
const fraction = absolute % 100;
|
|
401
|
-
return fraction === 0 ? `${sign}${whole}` : `${sign}${whole}.${String(fraction).padStart(2, '0')}`;
|
|
402
|
-
}
|
|
403
|
-
function extProductNames(products) {
|
|
404
|
-
if (!Array.isArray(products))
|
|
405
|
-
return '';
|
|
406
|
-
return products
|
|
407
|
-
.map((item) => item && typeof item === 'object' ? stringOrEmpty(item.productName || item.name) : '')
|
|
408
|
-
.filter(Boolean)
|
|
409
|
-
.join('、');
|
|
410
|
-
}
|
|
411
|
-
export function browseFieldItem(info) {
|
|
412
|
-
const comm = info.comm_info || {};
|
|
413
|
-
const pro = comm.pro || {};
|
|
414
|
-
const price = comm.price || {};
|
|
415
|
-
const buyer = comm.buyer || {};
|
|
416
|
-
const payer = comm.payer || {};
|
|
417
|
-
const modify = info.modify_info || {};
|
|
418
|
-
const ext = parseExt(info.ext);
|
|
419
|
-
const products = Array.isArray(ext.products) ? ext.products : [];
|
|
420
|
-
const fid = stringOrEmpty(info.fid || info.id);
|
|
421
|
-
const type = numberOrZero(pro.type);
|
|
422
|
-
const typeName = stringOrEmpty(pro.cname) || BROWSE_TYPE_NAMES.get(type) || '未知票种';
|
|
423
|
-
const number = stringOrEmpty(info.number);
|
|
424
|
-
const content = contentFor(typeName, number);
|
|
425
|
-
const total = stringOrEmpty(price.total);
|
|
426
|
-
const reimingMoney = typeof price.reimingMoney === 'string' ? price.reimingMoney : '';
|
|
427
|
-
const reimedMoney = typeof price.reimedMoney === 'string' ? price.reimedMoney : '';
|
|
428
|
-
const firstProduct = products.find((item) => item && typeof item === 'object');
|
|
429
|
-
return {
|
|
430
|
-
optionId: fid,
|
|
431
|
-
id: fid,
|
|
432
|
-
fid,
|
|
433
|
-
type,
|
|
434
|
-
typeName,
|
|
435
|
-
number,
|
|
436
|
-
code: stringOrEmpty(info.code),
|
|
437
|
-
content,
|
|
438
|
-
name: content,
|
|
439
|
-
total,
|
|
440
|
-
ttax: stringOrEmpty(ext.ttax),
|
|
441
|
-
seller: stringOrEmpty(payer.company),
|
|
442
|
-
sellerId: stringOrEmpty(payer.tcode),
|
|
443
|
-
buyer: stringOrEmpty(buyer.company),
|
|
444
|
-
buyerId: stringOrEmpty(buyer.tcode),
|
|
445
|
-
incDate: stringOrEmpty(pro.date),
|
|
446
|
-
incDateTimestamp: dateToTimestampMs(pro.date),
|
|
447
|
-
validStatus: enumName(VALID_STATUS_NAMES, pro.valid),
|
|
448
|
-
source: enumName(SOURCE_NAMES, modify.source),
|
|
449
|
-
invoiceStatus: numberOrZero(pro.status),
|
|
450
|
-
del: numberOrZero(modify.del),
|
|
451
|
-
currency: stringOrEmpty(info.currency) || 'CNY',
|
|
452
|
-
currencyName: stringOrEmpty(info.currencyName) || '人民币',
|
|
453
|
-
taxRate: stringOrEmpty(ext.taxRate || ext.trate || firstProduct?.taxRate || firstProduct?.trate),
|
|
454
|
-
consumeContent: stringOrEmpty(ext.content) || extProductNames(products),
|
|
455
|
-
fylx: stringOrEmpty(info.fylx) || '0',
|
|
456
|
-
inputDate: stringOrEmpty(modify.createDate || modify.modifyDate),
|
|
457
|
-
incTotal: 0,
|
|
458
|
-
reimingMoney,
|
|
459
|
-
reimedMoney,
|
|
460
|
-
notReimMoney: moneyMinus(total, reimingMoney, reimedMoney),
|
|
461
|
-
reimDate: '',
|
|
462
|
-
reimProcess: '',
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
export function browseFieldData(response) {
|
|
466
|
-
const ret = response.res_base?.ret;
|
|
467
|
-
if (ret !== undefined && ret !== 0) {
|
|
468
|
-
throw new InvoiceCliError('api', 'detail_failed', response.res_base?.message || '详情接口整体失败', {
|
|
469
|
-
code: ret,
|
|
470
|
-
details: { res_base: response.res_base },
|
|
471
|
-
exitCode: 1,
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
const items = [];
|
|
475
|
-
const errors = [];
|
|
476
|
-
for (const entry of Array.isArray(response.infos) ? response.infos : []) {
|
|
477
|
-
const itemRet = entry?.ret?.ret;
|
|
478
|
-
if (itemRet !== 0) {
|
|
479
|
-
errors.push({
|
|
480
|
-
fid: stringOrEmpty(entry?.info?.fid || entry?.info?.id),
|
|
481
|
-
ret: itemRet,
|
|
482
|
-
message: entry?.ret?.message || '查询失败',
|
|
483
|
-
});
|
|
484
|
-
continue;
|
|
485
|
-
}
|
|
486
|
-
if (entry?.info && typeof entry.info === 'object')
|
|
487
|
-
items.push(browseFieldItem(entry.info));
|
|
488
|
-
}
|
|
489
|
-
return { items, errors };
|
|
490
|
-
}
|
|
491
287
|
export function assertBusinessSuccess(value, subtype, fallbackMessage) {
|
|
492
288
|
const result = value && typeof value === 'object' ? value : {};
|
|
493
289
|
const code = result.code ?? result.res_base?.ret;
|
|
@@ -280,7 +280,7 @@ async function resolveRoomValue(env, input) {
|
|
|
280
280
|
* getRelateData 里匹配,匹配不到就返回 NEEDS_CONFIRMATION("无法唯一解析的选项")——
|
|
281
281
|
* 看起来像"流程建会走不通",其实是值格式不对。这里统一补成对象。
|
|
282
282
|
*/
|
|
283
|
-
export async function shapeBrowserValues(env, values) {
|
|
283
|
+
export async function shapeBrowserValues(env, values, options = {}) {
|
|
284
284
|
const notes = [];
|
|
285
285
|
const shaped = { ...values };
|
|
286
286
|
const readable = {};
|
|
@@ -420,11 +420,21 @@ export async function shapeBrowserValues(env, values) {
|
|
|
420
420
|
}
|
|
421
421
|
}
|
|
422
422
|
const unresolved = rows.filter((row) => row.id === '');
|
|
423
|
-
if (unresolved.length > 0) {
|
|
423
|
+
if (unresolved.length > 0 && options.crmAutoPick === true) {
|
|
424
|
+
// 直接发起流程:客户查不到就不带,不阻断、不追问。
|
|
425
|
+
notes.push(`客户未建档,已跳过:${unresolved.map((row) => row.name).join('、')}`);
|
|
426
|
+
for (let i = rows.length - 1; i >= 0; i -= 1)
|
|
427
|
+
if (rows[i].id === '')
|
|
428
|
+
rows.splice(i, 1);
|
|
429
|
+
}
|
|
430
|
+
else if (unresolved.length > 0) {
|
|
424
431
|
throw meetingValidationError('crm_not_found', `参会客户有 ${unresolved.length} 个在 CRM 里查不到:${unresolved.map((row) => row.name).join('、')}。`
|
|
425
432
|
+ '请确认客户名称,或先到客户表建档;也可以改用「客户名(客户id)」或 `[{id,name}]` 传 crm_members。');
|
|
426
433
|
}
|
|
427
|
-
|
|
434
|
+
if (rows.length > 0)
|
|
435
|
+
shaped.crm_members = rows;
|
|
436
|
+
else
|
|
437
|
+
delete shaped.crm_members;
|
|
428
438
|
readable.crm_members = rows.map((row) => row.name || row.id).join('、');
|
|
429
439
|
notes.push(`参会客户按客户浏览按钮格式提交:${rows.length} 个客户`);
|
|
430
440
|
/**
|
|
@@ -436,7 +446,13 @@ export async function shapeBrowserValues(env, values) {
|
|
|
436
446
|
* ⇒ 这里直接拒绝,并给出可用写法;客户名可从 `meeting.eb.crm.search` 的 `items[].name` 拿。
|
|
437
447
|
*/
|
|
438
448
|
const missingNames = rows.filter((row) => row.name === '');
|
|
439
|
-
if (missingNames.length > 0) {
|
|
449
|
+
if (missingNames.length > 0 && options.crmAutoPick === true) {
|
|
450
|
+
notes.push('有客户只给了 id 没有名称,已跳过,避免写成空值');
|
|
451
|
+
for (let i = rows.length - 1; i >= 0; i -= 1)
|
|
452
|
+
if (rows[i].name === '')
|
|
453
|
+
rows.splice(i, 1);
|
|
454
|
+
}
|
|
455
|
+
else if (missingNames.length > 0) {
|
|
440
456
|
throw meetingValidationError('crm_name_required', `参会客户有 ${missingNames.length} 个只给了 id、没有客户名称:${missingNames.map((row) => row.id).join('、')}。`
|
|
441
457
|
+ '客户浏览按钮必须带名称才能写入(只给 id 会被服务端静默存成空值)。'
|
|
442
458
|
+ '请先用 `meeting.eb.crm.search` 按客户名查到 `{ customerId, name }`,'
|
|
@@ -1312,13 +1328,22 @@ const ebMeetingCreateFlowPrepare = {
|
|
|
1312
1328
|
handler: async (args, env) => {
|
|
1313
1329
|
// 预检各阶段耗时(debugTimings:true 时随结果返回)
|
|
1314
1330
|
// 发起流程优先:明确要"发起/创建流程"时不做预检与推荐,只填单。
|
|
1315
|
-
|
|
1331
|
+
let skipPreflight = args.skipPreflight === true;
|
|
1316
1332
|
// 上游流程工具已让用户选过「直接发起表单」时,模型会带 entryMode=direct_form,等价于 skipPreflight。
|
|
1317
1333
|
if (args.entryMode === 'direct_form') {
|
|
1318
1334
|
args = { ...args, skipPreflight: true };
|
|
1335
|
+
skipPreflight = true;
|
|
1319
1336
|
}
|
|
1320
1337
|
// 会话内入口标记:流程工具已问过时,这里不再弹入口选项。
|
|
1321
|
-
|
|
1338
|
+
// entryMode 必须带本轮令牌(由下面的选项 value 下发),否则视为模型自填,无效。
|
|
1339
|
+
let entryResolved = '';
|
|
1340
|
+
const rawEntry = String(args.entryMode ?? '').trim();
|
|
1341
|
+
if (rawEntry === 'assist' || rawEntry === 'direct_form') {
|
|
1342
|
+
const { verifyEntryToken } = await import('./entry-mode.js');
|
|
1343
|
+
if (await verifyEntryToken(env, String(args.entryToken ?? ''), rawEntry).catch(() => false)) {
|
|
1344
|
+
entryResolved = rawEntry;
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1322
1347
|
if (!entryResolved) {
|
|
1323
1348
|
const { readEntryChoice } = await import('./entry-mode.js');
|
|
1324
1349
|
const mark = await readEntryChoice(env).catch(() => null);
|
|
@@ -1328,16 +1353,48 @@ const ebMeetingCreateFlowPrepare = {
|
|
|
1328
1353
|
if (entryResolved)
|
|
1329
1354
|
args = { ...args, entryMode: entryResolved };
|
|
1330
1355
|
env.__entryResolved = entryResolved || undefined;
|
|
1331
|
-
if (entryResolved === 'direct_form')
|
|
1356
|
+
if (entryResolved === 'direct_form') {
|
|
1357
|
+
args = { ...args, skipPreflight: true };
|
|
1358
|
+
skipPreflight = true;
|
|
1359
|
+
}
|
|
1360
|
+
// 四要素已齐(人 + 时间含上午/下午/晚上 + 地点)⇒ 直接发起,不预检、不问入口。
|
|
1361
|
+
const beginRaw = String(args.begin_datetime ?? '').trim();
|
|
1362
|
+
const timeReady = /^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}/.test(beginRaw)
|
|
1363
|
+
|| (String(args.time_slot ?? '').trim() !== ''
|
|
1364
|
+
&& (String(args.dateFrom ?? '').trim() !== '' || /^\d{4}-\d{2}-\d{2}/.test(beginRaw)));
|
|
1365
|
+
const placeReady = String(args.address ?? args.customize_address ?? '').trim() !== '';
|
|
1366
|
+
const peopleReady = String(args.hrm_members ?? '').trim() !== '';
|
|
1367
|
+
const autoDirect = timeReady && placeReady && peopleReady;
|
|
1368
|
+
if (autoDirect) {
|
|
1332
1369
|
args = { ...args, skipPreflight: true };
|
|
1370
|
+
skipPreflight = true;
|
|
1371
|
+
}
|
|
1372
|
+
// 入口确认:没有 entryMode、没有会话标记、也不是直接发起 → 必须先让用户选一次。
|
|
1373
|
+
if (!entryResolved && args.skipPreflight !== true) {
|
|
1374
|
+
const { createEntryToken } = await import('./entry-mode.js');
|
|
1375
|
+
const tokenDirect = await createEntryToken(env, 'direct_form');
|
|
1376
|
+
const tokenAssist = await createEntryToken(env, 'assist');
|
|
1377
|
+
return meetingSuccess('meeting.eb.meeting.create.flow.prepare', {
|
|
1378
|
+
status: 'NEEDS_SELECTION',
|
|
1379
|
+
selectionType: 'entry',
|
|
1380
|
+
ui: { component: 'choice', multiple: false, recommendedKey: 'A' },
|
|
1381
|
+
message: '预定会议有两种方式:直接发起流程表单,或由我先推荐会议室、检测冲突。请让用户选一个。',
|
|
1382
|
+
options: [
|
|
1383
|
+
{ key: 'A', label: '直接发起流程', reason: '打开会议申请表单,只回填已知信息', value: { entryMode: 'direct_form', entryToken: tokenDirect } },
|
|
1384
|
+
{ key: 'B', label: '推荐会议室/检测冲突', reason: '先确认时间地点,再提交', value: { entryMode: 'assist', entryToken: tokenAssist } },
|
|
1385
|
+
],
|
|
1386
|
+
hint: '用户点选后把 value 原样带回(含 entryMode),不要自己替用户选。',
|
|
1387
|
+
}, { meta: { notes: ['入口确认:用户未表态时必须先问一次'] } });
|
|
1388
|
+
}
|
|
1333
1389
|
if (args.skipPreflight === true) {
|
|
1334
1390
|
// 直接发起流程:仍要推荐会议室(自动选最优),但不弹时段/房间候选、不等待确认。
|
|
1391
|
+
// 四要素已齐(人+时间+地点)时地点由用户给定,跳过推荐与冲突查询,只填单。
|
|
1335
1392
|
const hasAddress = String(args.address ?? args.customize_address ?? '').trim() !== '';
|
|
1336
1393
|
args = {
|
|
1337
1394
|
...args,
|
|
1338
1395
|
timeConfirmed: true,
|
|
1339
|
-
autoRoom: true,
|
|
1340
|
-
enrich: true,
|
|
1396
|
+
autoRoom: autoDirect !== true,
|
|
1397
|
+
enrich: autoDirect !== true,
|
|
1341
1398
|
...(hasAddress ? { roomConfirmed: true } : {}),
|
|
1342
1399
|
};
|
|
1343
1400
|
}
|
|
@@ -1355,6 +1412,8 @@ const ebMeetingCreateFlowPrepare = {
|
|
|
1355
1412
|
// enrich=false:只做"建会必需"的事(载入表单 + 填字段 + 提交),跳过会议室推荐/冲突检测/空闲时段。
|
|
1356
1413
|
// 适用场景:人、时间、房间都已经确定,只想尽快把会建出来(可省掉 3 组额外请求与一次 ESB 调用)。
|
|
1357
1414
|
const enrich = args.enrich !== false;
|
|
1415
|
+
// 直接发起且指定了房间:只查该房间占用(用于被占时自动换房),不做推荐/人员冲突。
|
|
1416
|
+
const roomCheckOnly = args.skipPreflight === true && String(args.address ?? '').trim() !== '';
|
|
1358
1417
|
let beginText = String(args.begin_datetime ?? '').trim();
|
|
1359
1418
|
let endText = String(args.end_datetime ?? '').trim();
|
|
1360
1419
|
/**
|
|
@@ -1669,7 +1728,7 @@ const ebMeetingCreateFlowPrepare = {
|
|
|
1669
1728
|
const floorHint = floorArg ?? (/楼|层|\d+\s*F/iu.test(String(args.address ?? ''))
|
|
1670
1729
|
? inferRoomFloor(String(args.address ?? ''))
|
|
1671
1730
|
: null);
|
|
1672
|
-
const roomTask = (enrich && beginText && endText)
|
|
1731
|
+
const roomTask = ((enrich || roomCheckOnly) && beginText && endText)
|
|
1673
1732
|
? (async () => {
|
|
1674
1733
|
const usageData = await dayUsagesTask;
|
|
1675
1734
|
return recommendRooms(env, {
|
|
@@ -1739,13 +1798,13 @@ const ebMeetingCreateFlowPrepare = {
|
|
|
1739
1798
|
checkNotices.push(`空闲校验沿用 ${Math.round((Date.now() - cachedChecks.checkedAt) / 1000)} 秒前的结论`
|
|
1740
1799
|
+ '(时间/参会人/会议室都没变,未重复查询)。');
|
|
1741
1800
|
}
|
|
1742
|
-
const roomConflictTask = cachedChecks
|
|
1801
|
+
const roomConflictTask = (cachedChecks && !roomCheckOnly && !roomConfirmed)
|
|
1743
1802
|
? Promise.resolve({
|
|
1744
1803
|
room: cachedChecks.roomRecord,
|
|
1745
1804
|
hasConflict: cachedChecks.roomHasConflict === true,
|
|
1746
1805
|
conflicts: (cachedChecks.roomConflicts ?? []),
|
|
1747
1806
|
})
|
|
1748
|
-
: (enrich && beginText && endText && addressId !== '')
|
|
1807
|
+
: ((enrich || roomCheckOnly) && beginText && endText && addressId !== '')
|
|
1749
1808
|
? (async () => {
|
|
1750
1809
|
const room = await resolveAddressRoom(env, addressId);
|
|
1751
1810
|
// 名称对不上任何房间 → 直接判"没这间房",别把一串文本丢进表单等提交时才报错
|
|
@@ -1849,8 +1908,8 @@ const ebMeetingCreateFlowPrepare = {
|
|
|
1849
1908
|
// ① 指定的会议室该时段已被占用 → 不替用户改,但必须拦下来并给替代候选。
|
|
1850
1909
|
const roomConflictData = roomConflict;
|
|
1851
1910
|
const resolvedAddress = roomConflictData?.room ?? null;
|
|
1852
|
-
|
|
1853
|
-
|
|
1911
|
+
let resolvedAddressId = resolvedAddress?.id || addressId;
|
|
1912
|
+
let addressDisplay = resolvedAddress?.name || addressId;
|
|
1854
1913
|
// ①-a 名称对不上任何房间。
|
|
1855
1914
|
// ⛔ 2026-10-31 真机:以前这种会一路走到 AWAITING_CONFIRMATION,地点按纯文本塞进表单,
|
|
1856
1915
|
// 用户到流程页面提交时才被工作流打回「请按名称选择」—— 报错位置离真实原因太远。
|
|
@@ -1910,7 +1969,16 @@ const ebMeetingCreateFlowPrepare = {
|
|
|
1910
1969
|
});
|
|
1911
1970
|
}
|
|
1912
1971
|
// 只有"用户已确认这间房"时才按占用拦截;未确认的只是候选,交给下面的选房分支处理。
|
|
1913
|
-
|
|
1972
|
+
// 直接发起流程:指定房被占时自动改用首选空闲房,不追问(普通链路仍走选项)。
|
|
1973
|
+
if (skipPreflight && addressInput && roomConfirmed && roomConflictData?.hasConflict === true && roomOptions.length > 0) {
|
|
1974
|
+
const fallback = roomOptions[0].value ?? {};
|
|
1975
|
+
const from = { id: resolvedAddressId, name: addressDisplay };
|
|
1976
|
+
resolvedAddressId = String(fallback.id ?? '');
|
|
1977
|
+
addressDisplay = String(fallback.name ?? addressDisplay);
|
|
1978
|
+
addressInput = resolvedAddressId;
|
|
1979
|
+
decisions.roomAutoSwitched = { reason: '指定房被占,自动改用首选空闲房', from, to: { id: resolvedAddressId, name: addressDisplay } };
|
|
1980
|
+
}
|
|
1981
|
+
if (addressInput && roomConfirmed && roomConflictData?.hasConflict === true && !(skipPreflight && roomOptions.length > 0)) {
|
|
1914
1982
|
const busy = Array.isArray(roomConflictData.conflicts) ? roomConflictData.conflicts : [];
|
|
1915
1983
|
decisions.roomConflict = {
|
|
1916
1984
|
address: resolvedAddressId,
|
|
@@ -2281,7 +2349,7 @@ const ebMeetingCreateFlowPrepare = {
|
|
|
2281
2349
|
...(args.extraFields && typeof args.extraFields === 'object' && !Array.isArray(args.extraFields)
|
|
2282
2350
|
? args.extraFields
|
|
2283
2351
|
: {}),
|
|
2284
|
-
});
|
|
2352
|
+
}, { crmAutoPick: skipPreflight });
|
|
2285
2353
|
// datakey 固化:上次解析出的「语义键 → fieldId」直接复用(表单字段改名也不影响),
|
|
2286
2354
|
// 本次解析结果再写回,形成"猜一次、之后一直用 datakey"的效果。
|
|
2287
2355
|
const preferredFields = await readFlowFieldMap(env, workflowId);
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 建会入口选择:解决"流程工具已经问过、会议 skill 又问一遍"的重复询问,
|
|
3
|
+
* 并给"用户选择"加一次性令牌,防止模型自己填 entryMode 绕过入口询问。
|
|
3
4
|
*
|
|
4
|
-
* 谁先问谁落标记(按租户 + 登录人,10
|
|
5
|
-
* - 流程工具返回 choice 后:meeting.entry.record {choice:"assist"}
|
|
6
|
-
* - 会议 skill 收到 assist 时先读标记:命中就不再弹入口选项
|
|
7
|
-
* 直接调用会议 skill(没经过工具)时没有标记,仍由 skill 问一次。
|
|
5
|
+
* 谁先问谁落标记(按租户 + 登录人,10 分钟过期)。
|
|
8
6
|
*/
|
|
9
7
|
import { join, dirname } from 'node:path';
|
|
10
8
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
9
|
+
import { createHmac, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
11
10
|
import { meetingSuccess } from '../types.js';
|
|
12
11
|
import { meetingValidationError } from '../../errors.js';
|
|
13
12
|
import { meetingStateDir } from '../env.js';
|
|
@@ -15,9 +14,9 @@ const TTL_MS = 10 * 60 * 1000;
|
|
|
15
14
|
async function entryFile(env) {
|
|
16
15
|
const session = await env.host.getSession();
|
|
17
16
|
const scope = String(session?.tenantKey || session?.baseUrl || 'default').replace(/[^\w.-]+/g, '_');
|
|
18
|
-
return join(meetingStateDir(env.ctx),
|
|
17
|
+
return join(meetingStateDir(env.ctx), 'entry-' + scope + '.json');
|
|
19
18
|
}
|
|
20
|
-
/**
|
|
19
|
+
/** 读当前会话的入口选择;过期或无记录返回 null。 */
|
|
21
20
|
export async function readEntryChoice(env) {
|
|
22
21
|
try {
|
|
23
22
|
const raw = JSON.parse(readFileSync(await entryFile(env), 'utf8'));
|
|
@@ -30,6 +29,61 @@ export async function readEntryChoice(env) {
|
|
|
30
29
|
return null;
|
|
31
30
|
}
|
|
32
31
|
}
|
|
32
|
+
/** 令牌密钥:本机一次性生成,落 state 目录。 */
|
|
33
|
+
async function tokenSecret(env) {
|
|
34
|
+
const file = join(meetingStateDir(env.ctx), 'entry-secret');
|
|
35
|
+
try {
|
|
36
|
+
const value = readFileSync(file, 'utf8').trim();
|
|
37
|
+
if (value.length >= 32)
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// 首次:生成并落盘
|
|
42
|
+
}
|
|
43
|
+
const secret = randomBytes(32).toString('hex');
|
|
44
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
45
|
+
writeFileSync(file, secret, 'utf8');
|
|
46
|
+
return secret;
|
|
47
|
+
}
|
|
48
|
+
async function tokenUser(env) {
|
|
49
|
+
try {
|
|
50
|
+
const session = await env.host.getSession();
|
|
51
|
+
return String(session?.userId ?? '');
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return '';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async function signToken(env, choice, ts) {
|
|
58
|
+
const secret = await tokenSecret(env);
|
|
59
|
+
const user = await tokenUser(env);
|
|
60
|
+
const payload = choice + '.' + ts + '.' + user;
|
|
61
|
+
return createHmac('sha256', secret).update(payload).digest('hex').slice(0, 32);
|
|
62
|
+
}
|
|
63
|
+
/** 生成入口令牌(随选项 value 下发,下一轮原样回传才有效)。 */
|
|
64
|
+
export async function createEntryToken(env, choice) {
|
|
65
|
+
const ts = Date.now();
|
|
66
|
+
return choice + '.' + ts + '.' + (await signToken(env, choice, ts));
|
|
67
|
+
}
|
|
68
|
+
/** 校验入口令牌:选择项一致、未过期、签名匹配。 */
|
|
69
|
+
export async function verifyEntryToken(env, token, choice) {
|
|
70
|
+
const parts = String(token ?? '').split('.');
|
|
71
|
+
if (parts.length !== 3)
|
|
72
|
+
return false;
|
|
73
|
+
const [tokenChoice, tsRaw, sig] = parts;
|
|
74
|
+
if (tokenChoice !== choice)
|
|
75
|
+
return false;
|
|
76
|
+
const ts = Number(tsRaw);
|
|
77
|
+
if (!Number.isFinite(ts) || Date.now() - ts > TTL_MS)
|
|
78
|
+
return false;
|
|
79
|
+
const expected = await signToken(env, choice, ts);
|
|
80
|
+
try {
|
|
81
|
+
return timingSafeEqual(Buffer.from(sig), Buffer.from(expected));
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
33
87
|
const record = {
|
|
34
88
|
name: 'meeting.entry.record',
|
|
35
89
|
resource: 'eb',
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { CONTINUATION_TTL_MS } from '../../core/continuation-ttl.js';
|
|
2
|
+
import { createHmac, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
import { chmod, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
5
|
+
import { homedir } from 'node:os';
|
|
6
|
+
import { resolve } from 'node:path';
|
|
7
|
+
import { pfValidationError } from './errors.js';
|
|
8
|
+
function stateRoot(ctx) {
|
|
9
|
+
const configured = ctx?.config?.path();
|
|
10
|
+
if (configured)
|
|
11
|
+
return resolve(configured, '..');
|
|
12
|
+
return process.env.WEAVER_WORK_CLI_HOME || process.env.WORK_CLI_HOME || resolve(homedir(), '.weaver-work-cli');
|
|
13
|
+
}
|
|
14
|
+
async function loadKey(ctx) {
|
|
15
|
+
const keysDir = resolve(stateRoot(ctx), 'keys');
|
|
16
|
+
const filename = resolve(keysDir, 'performance-continuation.key');
|
|
17
|
+
await mkdir(keysDir, { recursive: true, mode: 0o700 });
|
|
18
|
+
if (existsSync(filename))
|
|
19
|
+
return readFile(filename);
|
|
20
|
+
const key = randomBytes(32);
|
|
21
|
+
try {
|
|
22
|
+
await writeFile(filename, key, { flag: 'wx', mode: 0o600 });
|
|
23
|
+
if (process.platform !== 'win32')
|
|
24
|
+
await chmod(filename, 0o600).catch(() => undefined);
|
|
25
|
+
return key;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return readFile(filename);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function encode(value) {
|
|
32
|
+
return Buffer.from(JSON.stringify(value)).toString('base64url');
|
|
33
|
+
}
|
|
34
|
+
function signature(payload, key) {
|
|
35
|
+
return createHmac('sha256', key).update(payload).digest('base64url');
|
|
36
|
+
}
|
|
37
|
+
export function createPerformanceContinuationSigner(ctx) {
|
|
38
|
+
return {
|
|
39
|
+
async issue(payload, ttlMs = CONTINUATION_TTL_MS) {
|
|
40
|
+
const issuedAt = Date.now();
|
|
41
|
+
const body = encode({ ...payload, issuedAt, expiresAt: issuedAt + ttlMs });
|
|
42
|
+
const sig = signature(body, await loadKey(ctx));
|
|
43
|
+
return `${body}.${sig}`;
|
|
44
|
+
},
|
|
45
|
+
async verify(token, expectedOperation) {
|
|
46
|
+
if (typeof token !== 'string' || !token.includes('.')) {
|
|
47
|
+
throw pfValidationError('continuation_invalid', 'continuation 无效');
|
|
48
|
+
}
|
|
49
|
+
const [body, provided] = token.split('.');
|
|
50
|
+
const expected = signature(body, await loadKey(ctx));
|
|
51
|
+
const valid = provided.length === expected.length
|
|
52
|
+
&& timingSafeEqual(Buffer.from(provided), Buffer.from(expected));
|
|
53
|
+
if (!valid)
|
|
54
|
+
throw pfValidationError('continuation_invalid', 'continuation 签名校验失败');
|
|
55
|
+
let payload;
|
|
56
|
+
try {
|
|
57
|
+
payload = JSON.parse(Buffer.from(body, 'base64url').toString('utf8'));
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
throw pfValidationError('continuation_invalid', 'continuation 载荷解析失败');
|
|
61
|
+
}
|
|
62
|
+
if (!payload || typeof payload !== 'object') {
|
|
63
|
+
throw pfValidationError('continuation_invalid', 'continuation 载荷必须是对象');
|
|
64
|
+
}
|
|
65
|
+
if (typeof payload.expiresAt === 'number' && Date.now() > payload.expiresAt) {
|
|
66
|
+
throw pfValidationError('continuation_expired', 'continuation 已过期,请重新 prepare');
|
|
67
|
+
}
|
|
68
|
+
if (payload.operation && String(payload.operation) !== String(expectedOperation)) {
|
|
69
|
+
throw pfValidationError('continuation_operation_mismatch', `continuation 属于操作 ${String(payload.operation)},不能用于 ${expectedOperation}`);
|
|
70
|
+
}
|
|
71
|
+
return payload;
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { CliError, ExitCode } from '../../core/errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* performance 模块错误类型。
|
|
4
|
+
* 形态与 recruit-stage 模块一致(type/subtype/details/partialData),
|
|
5
|
+
* 前缀 pf 避免与其他模块的错误类型混淆。
|
|
6
|
+
*/
|
|
7
|
+
export class PerformanceCliError extends CliError {
|
|
8
|
+
type;
|
|
9
|
+
subtype;
|
|
10
|
+
code;
|
|
11
|
+
retryable;
|
|
12
|
+
stage;
|
|
13
|
+
details;
|
|
14
|
+
partialData;
|
|
15
|
+
constructor(type, subtype, message, options = {}) {
|
|
16
|
+
super(message, options.exitCode ?? ExitCode.InternalError);
|
|
17
|
+
this.name = 'PerformanceCliError';
|
|
18
|
+
this.type = type;
|
|
19
|
+
this.subtype = subtype;
|
|
20
|
+
this.code = options.code;
|
|
21
|
+
this.retryable = options.retryable ?? false;
|
|
22
|
+
this.stage = options.stage;
|
|
23
|
+
this.details = options.details;
|
|
24
|
+
this.partialData = options.partialData;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function pfValidationError(subtype, message, details) {
|
|
28
|
+
return new PerformanceCliError('validation', subtype, message, {
|
|
29
|
+
details,
|
|
30
|
+
exitCode: ExitCode.UsageError,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export function pfAuthError(subtype, message, details) {
|
|
34
|
+
return new PerformanceCliError('authentication', subtype, message, {
|
|
35
|
+
details,
|
|
36
|
+
exitCode: ExitCode.AuthError,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
export function pfNetworkError(subtype, message, options = {}) {
|
|
40
|
+
return new PerformanceCliError('network', subtype, message, {
|
|
41
|
+
...options,
|
|
42
|
+
retryable: options.retryable ?? true,
|
|
43
|
+
exitCode: ExitCode.NetworkError,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export function pfConfirmationError(action, details) {
|
|
47
|
+
return new PerformanceCliError('confirmation', 'required', '该操作需要明确确认', {
|
|
48
|
+
details: { action, ...details },
|
|
49
|
+
exitCode: ExitCode.ConfirmationRequired,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/** 业务失败(接口 status/fail/code 判定失败的主通道)。 */
|
|
53
|
+
export function pfFail(message, details) {
|
|
54
|
+
return new PerformanceCliError('api', 'business_error', message, {
|
|
55
|
+
details,
|
|
56
|
+
exitCode: ExitCode.GeneralError,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
export function pfPartialError(message, partialData, details) {
|
|
60
|
+
return new PerformanceCliError('partial', 'write_uncertain', message, {
|
|
61
|
+
details,
|
|
62
|
+
partialData,
|
|
63
|
+
exitCode: ExitCode.Partial,
|
|
64
|
+
});
|
|
65
|
+
}
|