weaver-work-cli 0.1.59 → 0.1.61

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.
Files changed (124) hide show
  1. package/dist/chunks/{archive-4SQAVTIB.js → archive-S2VKZWQ3.js} +2 -2
  2. package/dist/chunks/{archive-oa-W2UEJ67L.js → archive-oa-HEDSIUUY.js} +2 -2
  3. package/dist/chunks/{asset-EGZEABBI.js → asset-HYH4W357.js} +2 -2
  4. package/dist/chunks/{asset-idle-EBUZBB6M.js → asset-idle-N7REBNGL.js} +2 -2
  5. package/dist/chunks/{attachment-content-TP6WDNC6.js → attachment-content-VYYA75FR.js} +3 -3
  6. package/dist/chunks/{blog-2YKMWOWI.js → blog-SLMZZICV.js} +2 -2
  7. package/dist/chunks/{caizhilian-5NM4X5HG.js → caizhilian-RV43KKBT.js} +4 -4
  8. package/dist/chunks/{calendar-H4QTJCUY.js → calendar-DMVZ4OLY.js} +2 -2
  9. package/dist/chunks/{chunk-QNPIY5R6.js → chunk-6XSSAUNW.js} +4 -4
  10. package/dist/chunks/{chunk-AQOPPNTR.js → chunk-BIA2NKUG.js} +4 -4
  11. package/dist/chunks/{chunk-VMCCRWFO.js → chunk-BQYX2UX5.js} +2 -2
  12. package/dist/chunks/{chunk-CI2RF3AJ.js → chunk-DTCQFTHW.js} +1 -1
  13. package/dist/chunks/{chunk-I3BFBBP2.js → chunk-E5YD5JWR.js} +1 -1
  14. package/dist/chunks/{chunk-PH7N4UFT.js → chunk-EGANE35F.js} +1 -1
  15. package/dist/chunks/{chunk-Z4IPY5GV.js → chunk-H6YOMI3U.js} +2 -2
  16. package/dist/chunks/{chunk-U2DWV6JC.js → chunk-ILALC2N6.js} +1 -1
  17. package/dist/chunks/{chunk-WINR2Q6K.js → chunk-KXJA42EA.js} +86 -19
  18. package/dist/chunks/{chunk-CQ4OVCKG.js → chunk-KY3R42RS.js} +2 -2
  19. package/dist/chunks/{chunk-WVH5ESDA.js → chunk-NRYDJN4J.js} +1 -1
  20. package/dist/chunks/{chunk-TGM7BWEH.js → chunk-P6TXQK75.js} +2 -2
  21. package/dist/chunks/{chunk-6YWHRXEQ.js → chunk-QBDXJS2W.js} +119 -9
  22. package/dist/chunks/{chunk-2IGZUMNG.js → chunk-SHX7XBYR.js} +180 -18
  23. package/dist/chunks/{chunk-XR5BGFNT.js → chunk-T2KVJFWJ.js} +10 -4
  24. package/dist/chunks/{chunk-FMNCSYIG.js → chunk-TEZHIB6T.js} +2 -2
  25. package/dist/chunks/{chunk-2FHP4PYS.js → chunk-UBGWIXU3.js} +116 -40
  26. package/dist/chunks/{chunk-5N222HK6.js → chunk-UBRWONP4.js} +2 -2
  27. package/dist/chunks/{chunk-MQBMMJUV.js → chunk-UQFPF4EX.js} +2 -2
  28. package/dist/chunks/{chunk-4GG72JAT.js → chunk-V2LASYKO.js} +2 -2
  29. package/dist/chunks/{chunk-FM7B5BIR.js → chunk-VBFBMM7G.js} +61 -53
  30. package/dist/chunks/{chunk-ZHPCNM2S.js → chunk-VNYOUAWV.js} +11 -11
  31. package/dist/chunks/{chunk-SFM3M2L3.js → chunk-WIWDVETN.js} +19 -3
  32. package/dist/chunks/{chunk-44KJ7WFA.js → chunk-XT77MP54.js} +2 -2
  33. package/dist/chunks/chunk-YI2YMW5N.js +111 -0
  34. package/dist/chunks/{conflict-Y3ESXYIA.js → conflict-GFJRS6I7.js} +2 -2
  35. package/dist/chunks/{contract-LLRKMLQQ.js → contract-U3ZGNRWB.js} +2 -2
  36. package/dist/chunks/{cowork-2RDFBZWB.js → cowork-EX7PKIDK.js} +2 -2
  37. package/dist/chunks/{create-flow-JHQSA6JF.js → create-flow-EJZD434E.js} +6 -6
  38. package/dist/chunks/{data-ZVS3BWPT.js → data-FOODGAMF.js} +278 -123
  39. package/dist/chunks/{ebuilder-form-TWSXS5NA.js → ebuilder-form-I2EOKODG.js} +5 -5
  40. package/dist/chunks/{ehr-52GBKNJR.js → ehr-TE4RFNID.js} +2 -2
  41. package/dist/chunks/entry-mode-ZOLSXEGX.js +19 -0
  42. package/dist/chunks/{env-LQBLL3MZ.js → env-TID5NFR6.js} +2 -2
  43. package/dist/chunks/{esb-HJSXCEOM.js → esb-7L6MHYLB.js} +4 -4
  44. package/dist/chunks/{factory-X7PN6B3B.js → factory-OG7BPMH5.js} +1 -1
  45. package/dist/chunks/{fna-OBACRT3J.js → fna-6V2ENR3Y.js} +2 -2
  46. package/dist/chunks/{group-chat-PPFY7SPV.js → group-chat-5DKPWIHL.js} +3 -3
  47. package/dist/chunks/{host-TTSGY5NZ.js → host-3DLYA54R.js} +3 -3
  48. package/dist/chunks/{host-KJT3G5D2.js → host-GOJHHTPY.js} +3 -3
  49. package/dist/chunks/{host-KOWUMNAY.js → host-OGBHL75G.js} +3 -3
  50. package/dist/chunks/{host-MFXRA2MY.js → host-ONZC6AE7.js} +3 -3
  51. package/dist/chunks/{host-W4JCNRFS.js → host-TJ5VVHM7.js} +3 -3
  52. package/dist/chunks/{host-2BKMPWDH.js → host-VTPAWDZV.js} +3 -3
  53. package/dist/chunks/{hrm-AK3WGBMN.js → hrm-2N7NFQDZ.js} +3 -3
  54. package/dist/chunks/{im-JZSBPO4Z.js → im-XCH47ZBN.js} +3 -3
  55. package/dist/chunks/{invoice-6XDMPCWB.js → invoice-XQRKMGNY.js} +3 -3
  56. package/dist/chunks/{jiuchuanhui-K4EQU6GK.js → jiuchuanhui-PL6DRPBM.js} +2 -2
  57. package/dist/chunks/{lazy-dispatch-GCA6HDOB.js → lazy-dispatch-UATEN7H7.js} +5 -5
  58. package/dist/chunks/{mail-IKVCQCVZ.js → mail-Q7Z4CQ4D.js} +2 -2
  59. package/dist/chunks/{meeting-GMRQZFJP.js → meeting-5E3BNARL.js} +13 -12
  60. package/dist/chunks/{minute-doc-JXH3MNC7.js → minute-doc-NXRE5C77.js} +4 -4
  61. package/dist/chunks/{okr-KV43FPPX.js → okr-3O3XNYOK.js} +2 -2
  62. package/dist/chunks/{operations-6NXJ7RTE.js → operations-EZWG72FH.js} +4 -4
  63. package/dist/chunks/performance-Y7CPNSOR.js +1295 -0
  64. package/dist/chunks/{plan-WOYR4WEG.js → plan-BLGPZF5M.js} +2 -2
  65. package/dist/chunks/{project-CQJKBUIL.js → project-6MZMLJMP.js} +2 -2
  66. package/dist/chunks/{reception-MPBU3JXC.js → reception-F2VT2X52.js} +2 -2
  67. package/dist/chunks/{recruit-stage-USTTRHOX.js → recruit-stage-4ETIBMIW.js} +2 -2
  68. package/dist/chunks/{registry-GURQG4ZV.js → registry-3FYSWV3U.js} +3 -3
  69. package/dist/chunks/{registry-SS5J2FZQ.js → registry-7RS74TCK.js} +4 -4
  70. package/dist/chunks/{registry-WZCCBI5L.js → registry-I4DVPDMU.js} +11 -10
  71. package/dist/chunks/{room-recommend-CKU5NF2E.js → room-recommend-GWCVKCXW.js} +4 -4
  72. package/dist/chunks/{schedule-DEFAO2RY.js → schedule-6AN63MJQ.js} +4 -4
  73. package/dist/chunks/{smart-extract-APX2PNIN.js → smart-extract-SR4SJJKN.js} +3 -3
  74. package/dist/chunks/{workflow-WMPW3WSB.js → workflow-KF7FA2UQ.js} +7 -7
  75. package/dist/cmd/refs/index.js +124 -4
  76. package/dist/core/output.js +199 -26
  77. package/dist/core/refs.js +36 -0
  78. package/dist/index.js +38 -33
  79. package/dist/internal/e10/auth/xiaoe.js +25 -3
  80. package/dist/shortcuts/caizhilian/operations/files.js +86 -15
  81. package/dist/shortcuts/data/index.js +12 -2
  82. package/dist/shortcuts/data/manifest.js +4 -2
  83. package/dist/shortcuts/data/operations/attribution.js +229 -0
  84. package/dist/shortcuts/data/operations/ds.js +87 -92
  85. package/dist/shortcuts/data/operations/index.js +3 -1
  86. package/dist/shortcuts/index.js +5 -0
  87. package/dist/shortcuts/meeting/operations/eb/create-flow.js +111 -12
  88. package/dist/shortcuts/meeting/operations/eb/entry-mode.js +116 -0
  89. package/dist/shortcuts/meeting/operations/eb/index.js +2 -0
  90. package/dist/shortcuts/meeting/operations/eb/room-recommend.js +11 -0
  91. package/dist/shortcuts/meeting/operations/registry.js +4 -0
  92. package/dist/shortcuts/performance/continuation.js +74 -0
  93. package/dist/shortcuts/performance/errors.js +65 -0
  94. package/dist/shortcuts/performance/host.js +105 -0
  95. package/dist/shortcuts/performance/index.js +109 -0
  96. package/dist/shortcuts/performance/manifest.js +30 -0
  97. package/dist/shortcuts/performance/operations/hrm-resolve.js +114 -0
  98. package/dist/shortcuts/performance/operations/registry.js +44 -0
  99. package/dist/shortcuts/performance/operations/scheme-detail.js +70 -0
  100. package/dist/shortcuts/performance/operations/scheme-draft.js +116 -0
  101. package/dist/shortcuts/performance/operations/scheme-publish.js +158 -0
  102. package/dist/shortcuts/performance/operations/types.js +32 -0
  103. package/dist/shortcuts/performance/scheme-validate.js +307 -0
  104. package/dist/shortcuts/performance/shared.js +158 -0
  105. package/docs/agent-io-channel-design.md +67 -3
  106. package/docs/data.md +2 -1
  107. package/package.json +1 -1
  108. package/scripts/xiaoe_env.py +6 -1
  109. package/skill-template/business-info.json +19 -0
  110. package/skill-template/domains/performance.md +18 -0
  111. package/skills/weaver-e10-caizhilian/SKILL.md +1 -1
  112. package/skills/weaver-e10-data/references/datasource.md +2 -1
  113. package/skills/weaver-e10-meeting/SKILL.md +16 -3
  114. package/skills/weaver-e10-performance/SKILL.md +202 -0
  115. package/skills/weaver-e10-performance/agents/openai.yaml +74 -0
  116. package/skills/weaver-e10-performance/references/default-assembly.md +108 -0
  117. package/skills/weaver-e10-performance/references/entity-resolution.md +69 -0
  118. package/skills/weaver-e10-performance/references/enums-and-normalization.md +80 -0
  119. package/skills/weaver-e10-performance/references/examples.md +146 -0
  120. package/skills/weaver-e10-performance/references/extraction-guide.md +144 -0
  121. package/skills/weaver-e10-performance/references/scheme-edit-req-fields.md +185 -0
  122. package/skills/weaver-e10-performance/references/scheme-setting-page.md +62 -0
  123. package/skills/weaver-e10-performance/scripts/parse_appraisal_doc.py +483 -0
  124. package/skills/weaver-e10-shared/references/json-output-contract.md +5 -0
@@ -0,0 +1,44 @@
1
+ import { PerformanceCliError } from '../errors.js';
2
+ import { schemeDraftOperations } from './scheme-draft.js';
3
+ import { schemePublishOperations } from './scheme-publish.js';
4
+ import { schemeDetailOperations } from './scheme-detail.js';
5
+ import { hrmResolveOperations } from './hrm-resolve.js';
6
+ const definitions = [
7
+ ...hrmResolveOperations,
8
+ ...schemeDetailOperations,
9
+ ...schemeDraftOperations,
10
+ ...schemePublishOperations,
11
+ ];
12
+ const registry = new Map();
13
+ for (const definition of definitions) {
14
+ if (registry.has(definition.name)) {
15
+ throw new Error(`duplicate performance operation: ${definition.name}`);
16
+ }
17
+ registry.set(definition.name, definition);
18
+ }
19
+ export function performanceOperationDefinitions() {
20
+ return [...registry.values()];
21
+ }
22
+ export function getPerformanceOperation(operation) {
23
+ const definition = registry.get(operation);
24
+ if (!definition) {
25
+ throw new PerformanceCliError('validation', 'operation_unknown', `绩效方案模块不支持操作:${operation}`, {
26
+ exitCode: 1,
27
+ });
28
+ }
29
+ return definition;
30
+ }
31
+ export async function executePerformanceOperation(operation, input, env) {
32
+ const definition = getPerformanceOperation(operation);
33
+ // 拒绝未声明参数:防「参数名写错被静默忽略」(与 recruit-stage 标准入口一致)。
34
+ const schema = definition.inputSchema;
35
+ if (schema && schema.additionalProperties === false) {
36
+ const known = Object.keys((schema.properties || {}));
37
+ const unknown = Object.keys(input || {}).filter((key) => !known.includes(key));
38
+ if (unknown.length > 0) {
39
+ throw new PerformanceCliError('validation', 'unknown_argument', `未知参数:${unknown.join('、')}。本操作支持的参数:${known.length ? known.join('、') : '(无)'}。`
40
+ + '参数名写错会被静默忽略并返回看似正常的结果,请按上面的参数名重传。', { exitCode: 1 });
41
+ }
42
+ }
43
+ return definition.handler(input, env);
44
+ }
@@ -0,0 +1,70 @@
1
+ import { pfValidationError } from '../errors.js';
2
+ import { assertWeaResult, normalizeId } from '../shared.js';
3
+ import { buildBonusPenaltyRows, buildIndicatorRows, describeTargets, summarizeScheme, TARGET_TYPE_LABELS } from '../scheme-validate.js';
4
+ import { pfSuccess, schemaOf } from './types.js';
5
+ const DETAIL_PATH = '/api/workrelate/performance/scheme/detail';
6
+ /**
7
+ * detail:回读方案(草稿态正常)。
8
+ * 返回精简核对视图(基本信息摘要 + 指标行数/权重合计 + 评分审批序列 + 缺失项提示 + detailId),
9
+ * 以及完整 data 原文(供 publish.prepare 组参或 Agent 深查;超大输出由全局 refs 机制接管)。
10
+ */
11
+ async function detail(args, env) {
12
+ if (args.id === undefined || args.id === null || args.id === '') {
13
+ throw pfValidationError('id_missing', '缺少方案 id');
14
+ }
15
+ const id = normalizeId(args.id, 'id');
16
+ const response = await env.host.request({
17
+ path: `${DETAIL_PATH}/${encodeURIComponent(id)}`,
18
+ method: 'GET',
19
+ operation: 'performance.scheme.detail',
20
+ });
21
+ const data = assertWeaResult(response, '读取方案详情');
22
+ if (!data || typeof data !== 'object') {
23
+ throw pfValidationError('detail_not_object', '方案详情返回 data 不是对象', { id });
24
+ }
25
+ const summary = summarizeScheme(data);
26
+ // 缺失项提示(服务端缺失项口径:常规指标/加减分项/评分人/审批人/生效日期是最常缺的五类)。
27
+ const missing = [];
28
+ if (!summary.indicatorCount)
29
+ missing.push('常规指标');
30
+ if (!summary.plusCount)
31
+ missing.push('加分项');
32
+ if (!summary.minusCount)
33
+ missing.push('减分项');
34
+ if (!summary.steps.length)
35
+ missing.push('评分/审批节点');
36
+ if (!summary.teffectTime)
37
+ missing.push('生效日期');
38
+ if (!data.detailId)
39
+ missing.push('detailId(异常:发布前必须先修复,见 publish.prepare)');
40
+ return pfSuccess('performance.scheme.detail', {
41
+ schemeId: String(id),
42
+ status: data.status ?? null,
43
+ applyStatus: data.applyStatus ?? null,
44
+ detailId: data.detailId === undefined || data.detailId === null ? null : String(data.detailId),
45
+ summary,
46
+ targets: describeTargets(data),
47
+ // 业务行:Agent 直接按此渲染表格,禁止只报计数
48
+ indicatorRows: buildIndicatorRows(data),
49
+ plusRows: buildBonusPenaltyRows(data, 'plus'),
50
+ minusRows: buildBonusPenaltyRows(data, 'minus'),
51
+ missing,
52
+ targetTypeLegend: TARGET_TYPE_LABELS,
53
+ data,
54
+ });
55
+ }
56
+ export const schemeDetailOperations = [
57
+ {
58
+ name: 'performance.scheme.detail',
59
+ resource: 'performance.scheme',
60
+ method: 'query',
61
+ action: 'scheme.detail',
62
+ summary: '回读方案详情(草稿态正常),返回精简核对视图 + 缺失项提示 + 完整原文',
63
+ capability: 'performance.scheme.detail',
64
+ risk: 'read',
65
+ inputSchema: schemaOf({
66
+ id: { type: 'string', description: '方案 id,字符串形式(18 位 Long 用数字会丢精度)' },
67
+ }, { required: ['id'] }),
68
+ handler: detail,
69
+ },
70
+ ];
@@ -0,0 +1,116 @@
1
+ import { pfConfirmationError, pfValidationError } from '../errors.js';
2
+ import { assertWeaResult, ensureDetailIdForUpdate, normalizeId, schemeEditReqSchema } from '../shared.js';
3
+ import { assertNoErrors, buildBonusPenaltyRows, buildIndicatorRows, describeTargets, normalizeSchemeBody, schemeFingerprint, summarizeScheme, validateScheme } from '../scheme-validate.js';
4
+ import { pfSuccess, schemaOf } from './types.js';
5
+ const EDIT_PATH = '/api/workrelate/performance/scheme/edit';
6
+ /** 入参只收 SchemeEditReq 顶层已知字段(剔除 apply 专用的 confirm/continuation 后整体透传)。 */
7
+ const REQ_FIELDS = [...Object.keys(schemeEditReqSchema)];
8
+ function pickRequestBody(args) {
9
+ const body = {};
10
+ for (const field of REQ_FIELDS) {
11
+ if (args[field] !== undefined)
12
+ body[field] = args[field];
13
+ }
14
+ // 考核对象 id 一律字符串:18 位 Long 用 JSON 数字会丢精度
15
+ if (Array.isArray(body.schemeLinkList)) {
16
+ body.schemeLinkList = body.schemeLinkList.map((link, index) => {
17
+ if (!link || typeof link !== 'object')
18
+ return link;
19
+ if (Number(link.targetType) === 11)
20
+ return { ...link, id: '0' };
21
+ return { ...link, id: normalizeId(link.id, `schemeLinkList[${index}].id`) };
22
+ });
23
+ }
24
+ return body;
25
+ }
26
+ /**
27
+ * draft.prepare:校验 + 摘要(不落库)。
28
+ * 返回给用户确认的摘要(方案名/考核对象/指标行数/权重合计/评分审批序列 + 校验 WARN),
29
+ * 以及 continuation(含提交指纹),apply 验签比对指纹,防「确认摘要与实际提交不一致」。
30
+ */
31
+ async function prepare(args, env) {
32
+ const normalized = normalizeSchemeBody(pickRequestBody(args));
33
+ const body = await ensureDetailIdForUpdate(env.host, normalized.body, 'performance.scheme.draft.prepare');
34
+ const issues = assertNoErrors([...normalized.issues, ...validateScheme(body)]);
35
+ const summary = summarizeScheme(body);
36
+ const fingerprint = schemeFingerprint(body);
37
+ const continuation = await env.continuation.issue({
38
+ operation: 'performance.scheme.draft.apply',
39
+ fingerprint,
40
+ });
41
+ const preview = {
42
+ action: '暂存草稿(POST /scheme/edit;覆盖式全量重建指标/流程/加减分项,不触发发布动作)',
43
+ scheme: summary,
44
+ targets: describeTargets(body),
45
+ indicatorRows: buildIndicatorRows(body),
46
+ plusRows: buildBonusPenaltyRows(body, 'plus'),
47
+ minusRows: buildBonusPenaltyRows(body, 'minus'),
48
+ issues: issues.map((issue) => `[${issue.level === 'warn' ? 'WARN' : 'ERROR'}] ${issue.message}`),
49
+ };
50
+ return pfSuccess('performance.scheme.draft.prepare', { continuation, fingerprint, preview }, {
51
+ continuation,
52
+ fingerprint,
53
+ confirmHint: '向用户展示 preview 摘要并确认后,携带 confirm=true 与本 continuation 调用 performance.scheme.draft.apply',
54
+ });
55
+ }
56
+ /** draft.apply:确认后落草稿(覆盖式暂存),返回方案 id。 */
57
+ async function apply(args, env) {
58
+ if (args.confirm !== true) {
59
+ throw pfConfirmationError('performance.scheme.draft.apply', { hint: '必须先向用户展示 prepare 摘要并获得明确确认' });
60
+ }
61
+ if (typeof args.continuation !== 'string' || !args.continuation) {
62
+ throw pfValidationError('continuation_missing', '缺少 continuation(先运行 performance.scheme.draft.prepare)');
63
+ }
64
+ const verified = await env.continuation.verify(args.continuation, 'performance.scheme.draft.apply');
65
+ const normalized = normalizeSchemeBody(pickRequestBody(args));
66
+ const body = await ensureDetailIdForUpdate(env.host, normalized.body, 'performance.scheme.draft.apply');
67
+ assertNoErrors([...normalized.issues, ...validateScheme(body)]);
68
+ const fingerprint = schemeFingerprint(body);
69
+ if (String(verified.fingerprint) !== fingerprint) {
70
+ throw pfValidationError('fingerprint_mismatch', '提交内容与确认摘要不一致(参数在 prepare 之后被修改),请重新 prepare 并再次确认', {
71
+ expected: verified.fingerprint,
72
+ actual: fingerprint,
73
+ });
74
+ }
75
+ const response = await env.host.request({
76
+ path: EDIT_PATH,
77
+ body,
78
+ operation: 'performance.scheme.draft.apply',
79
+ });
80
+ const schemeId = assertWeaResult(response, '暂存草稿');
81
+ return pfSuccess('performance.scheme.draft.apply', {
82
+ schemeId,
83
+ status: args.id ? 'draft-updated' : 'draft-created',
84
+ next: '用 performance.scheme.detail 回读核对;发布须用户明确同意后走 performance.scheme.publish.prepare',
85
+ });
86
+ }
87
+ export const schemeDraftOperations = [
88
+ {
89
+ name: 'performance.scheme.draft.prepare',
90
+ resource: 'performance.scheme',
91
+ method: 'prepare',
92
+ action: 'scheme.draft',
93
+ summary: '暂存草稿前校验并生成确认摘要(不落库);返回 continuation 与提交指纹',
94
+ capability: 'performance.scheme.draft',
95
+ risk: 'write',
96
+ requiresConfirmation: true,
97
+ inputSchema: schemaOf(schemeEditReqSchema, { required: ['name', 'schemeLinkList'] }),
98
+ handler: prepare,
99
+ },
100
+ {
101
+ name: 'performance.scheme.draft.apply',
102
+ resource: 'performance.scheme',
103
+ method: 'apply',
104
+ action: 'scheme.draft',
105
+ summary: '确认后暂存草稿(POST /scheme/edit,覆盖式全量暂存,不触发发布)',
106
+ capability: 'performance.scheme.draft',
107
+ risk: 'write',
108
+ requiresConfirmation: true,
109
+ inputSchema: schemaOf({
110
+ ...schemeEditReqSchema,
111
+ confirm: { type: 'boolean', description: '必须 true(用户已确认 prepare 摘要)' },
112
+ continuation: { type: 'string', description: 'prepare 返回的 continuation' },
113
+ }, { required: ['name', 'schemeLinkList', 'confirm', 'continuation'] }),
114
+ handler: apply,
115
+ },
116
+ ];
@@ -0,0 +1,158 @@
1
+ import { pfConfirmationError, pfFail, pfValidationError } from '../errors.js';
2
+ import { assertWeaResult, normalizeId, schemeEditReqSchema } from '../shared.js';
3
+ import { assertNoErrors, describeTargets, schemeFingerprint, summarizeScheme, validateScheme } from '../scheme-validate.js';
4
+ import { pfSuccess, schemaOf } from './types.js';
5
+ const APPLY_PATH = '/api/workrelate/performance/scheme/applyScheme';
6
+ const DETAIL_PATH = '/api/workrelate/performance/scheme/detail';
7
+ const REQ_FIELDS = [...Object.keys(schemeEditReqSchema)];
8
+ function pickRequestBody(args) {
9
+ const body = {};
10
+ for (const field of REQ_FIELDS) {
11
+ if (args[field] !== undefined)
12
+ body[field] = args[field];
13
+ }
14
+ return body;
15
+ }
16
+ function requireId(args) {
17
+ if (args.id === undefined || args.id === null || args.id === '') {
18
+ throw pfValidationError('id_missing', '发布已有方案必须传 id(不带 id 会直接创建并发布新方案)');
19
+ }
20
+ return normalizeId(args.id, 'id');
21
+ }
22
+ /** detail 回读中属于 SchemeEditReq 的字段(发布参数基于 detail 回读组装)。 */
23
+ const DETAIL_REQ_FIELDS = REQ_FIELDS;
24
+ function readBackScheme(detailData) {
25
+ const body = {};
26
+ for (const field of DETAIL_REQ_FIELDS) {
27
+ if (detailData[field] !== undefined && detailData[field] !== null)
28
+ body[field] = detailData[field];
29
+ }
30
+ // id / detailId 必须保留(detailId 丢失 = hr_kpi_details 重复插入,detail 永久 500,无法自愈)。
31
+ body.id = normalizeId(detailData.id, 'detail.id');
32
+ body.detailId = normalizeId(detailData.detailId, 'detail.detailId');
33
+ return body;
34
+ }
35
+ /**
36
+ * publish.prepare:发布前组装与确认(不落库)。
37
+ * 两种入参形态:
38
+ * A. 只传 id —— 自动 detail 回读组装完整发布参数(推荐,detailId 不会丢);
39
+ * B. 传完整 SchemeEditReq(可覆盖个别字段)—— 以入参为准,但 id/detailId 仍强制回读对齐。
40
+ * 返回发布摘要(含方案当前状态、发布语义提示)+ continuation。
41
+ */
42
+ async function prepare(args, env) {
43
+ const id = requireId(args);
44
+ const detailResponse = await env.host.request({
45
+ path: `${DETAIL_PATH}/${encodeURIComponent(String(id))}`,
46
+ method: 'GET',
47
+ operation: 'performance.scheme.publish.prepare',
48
+ });
49
+ const detailData = assertWeaResult(detailResponse, '读取方案详情');
50
+ if (!detailData || typeof detailData !== 'object') {
51
+ throw pfFail('读取方案详情:返回 data 不是对象', { id });
52
+ }
53
+ if (detailData.detailId === undefined || detailData.detailId === null || detailData.detailId === '') {
54
+ // 已知故障特征:发布不带 detailId 会导致 hr_kpi_details 重复插入、detail 永久 500。
55
+ throw pfValidationError('detail_id_missing', '方案详情回读不到 detailId——为防重复明细事故,禁止发布;请在方案编辑页核对该方案', { id });
56
+ }
57
+ // 以 detail 回读为底,叠加调用方显式传入的覆盖字段(不含 confirm/continuation)。
58
+ const overrides = pickRequestBody(args);
59
+ delete overrides.confirm;
60
+ const detailId = normalizeId(detailData.detailId, 'detail.detailId');
61
+ const body = { ...readBackScheme(detailData), ...overrides, id: String(id), detailId };
62
+ const issues = assertNoErrors(validateScheme(body));
63
+ const summary = summarizeScheme(body);
64
+ const fingerprint = schemeFingerprint(body);
65
+ const continuation = await env.continuation.issue({
66
+ operation: 'performance.scheme.publish.apply',
67
+ fingerprint,
68
+ });
69
+ const preview = {
70
+ action: '发布方案(POST /scheme/applyScheme)——正式动作:触发版本管理、ESB 动作流、提醒,方案立即生效',
71
+ currentStatus: detailData.status ?? null,
72
+ scheme: summary,
73
+ targets: describeTargets(body),
74
+ issues: issues.map((issue) => `[${issue.level === 'warn' ? 'WARN' : 'ERROR'}] ${issue.message}`),
75
+ fatalNote: 'id 与 detailId 已从 detail 回读并强制带上(detailId 丢失会导致方案数据损坏,禁止剔除)',
76
+ };
77
+ return pfSuccess('performance.scheme.publish.prepare', { continuation, fingerprint, preview }, {
78
+ continuation,
79
+ fingerprint,
80
+ confirmHint: '发布必须用户明确同意。展示 preview(含发布语义提示)确认后,携带 confirm=true 与 continuation 调用 performance.scheme.publish.apply',
81
+ });
82
+ }
83
+ /** publish.apply:确认后发布,返回方案 id。 */
84
+ async function apply(args, env) {
85
+ if (args.confirm !== true) {
86
+ throw pfConfirmationError('performance.scheme.publish.apply', { hint: '发布是正式动作,必须用户明确同意' });
87
+ }
88
+ if (typeof args.continuation !== 'string' || !args.continuation) {
89
+ throw pfValidationError('continuation_missing', '缺少 continuation(先运行 performance.scheme.publish.prepare)');
90
+ }
91
+ const verified = await env.continuation.verify(args.continuation, 'performance.scheme.publish.apply');
92
+ const id = requireId(args);
93
+ const detailResponse = await env.host.request({
94
+ path: `${DETAIL_PATH}/${encodeURIComponent(String(id))}`,
95
+ method: 'GET',
96
+ operation: 'performance.scheme.publish.apply',
97
+ });
98
+ const detailData = assertWeaResult(detailResponse, '读取方案详情');
99
+ if (detailData?.detailId === undefined || detailData?.detailId === null || detailData?.detailId === '') {
100
+ throw pfValidationError('detail_id_missing', '方案详情回读不到 detailId——为防重复明细事故,禁止发布', { id });
101
+ }
102
+ const overrides = pickRequestBody(args);
103
+ delete overrides.confirm;
104
+ const detailId = normalizeId(detailData.detailId, 'detail.detailId');
105
+ const body = { ...readBackScheme(detailData), ...overrides, id: String(id), detailId };
106
+ assertNoErrors(validateScheme(body));
107
+ const fingerprint = schemeFingerprint(body);
108
+ if (String(verified.fingerprint) !== fingerprint) {
109
+ throw pfValidationError('fingerprint_mismatch', '提交内容与确认摘要不一致(方案数据或参数在 prepare 之后发生变化),请重新 prepare 并再次确认', {
110
+ expected: verified.fingerprint,
111
+ actual: fingerprint,
112
+ });
113
+ }
114
+ const response = await env.host.request({
115
+ path: APPLY_PATH,
116
+ body,
117
+ operation: 'performance.scheme.publish.apply',
118
+ });
119
+ const schemeId = assertWeaResult(response, '发布方案');
120
+ return pfSuccess('performance.scheme.publish.apply', {
121
+ schemeId,
122
+ status: 'published',
123
+ next: '用 performance.scheme.detail 核对 status=finished / applyStatus;方案设置页可在 E10 前端继续完善',
124
+ });
125
+ }
126
+ export const schemePublishOperations = [
127
+ {
128
+ name: 'performance.scheme.publish.prepare',
129
+ resource: 'performance.scheme',
130
+ method: 'prepare',
131
+ action: 'scheme.publish',
132
+ summary: '发布前自动 detail 回读组装完整参数(强制带 id+detailId)并生成确认摘要;不落库',
133
+ capability: 'performance.scheme.publish',
134
+ risk: 'write',
135
+ requiresConfirmation: true,
136
+ inputSchema: schemaOf({
137
+ ...schemeEditReqSchema,
138
+ // 发布推荐只传 id(其余参数自动回读);显式传入的字段会覆盖回读值。
139
+ }, { required: ['id'], description: '推荐只传 id:参数自动从 detail 回读组装(detailId 防丢);也可显式覆盖个别字段' }),
140
+ handler: prepare,
141
+ },
142
+ {
143
+ name: 'performance.scheme.publish.apply',
144
+ resource: 'performance.scheme',
145
+ method: 'apply',
146
+ action: 'scheme.publish',
147
+ summary: '确认后发布方案(POST /scheme/applyScheme;正式动作,触发版本/ESB/提醒)',
148
+ capability: 'performance.scheme.publish',
149
+ risk: 'write',
150
+ requiresConfirmation: true,
151
+ inputSchema: schemaOf({
152
+ ...schemeEditReqSchema,
153
+ confirm: { type: 'boolean', description: '必须 true(用户已明确同意发布)' },
154
+ continuation: { type: 'string', description: 'prepare 返回的 continuation' },
155
+ }, { required: ['id', 'confirm', 'continuation'] }),
156
+ handler: apply,
157
+ },
158
+ ];
@@ -0,0 +1,32 @@
1
+ import { pfValidationError } from '../errors.js';
2
+ export const READ = 'read';
3
+ export const WRITE = 'write';
4
+ export function pfSuccess(action, data, meta) {
5
+ const payload = { ok: true, action, data };
6
+ if (meta && Object.keys(meta).length > 0)
7
+ payload.meta = meta;
8
+ // 把 meta.continuation 镜像到 data,使「读 data.continuation」与「读 meta.continuation」都能取到同一个值。
9
+ const cont = meta?.continuation;
10
+ if (typeof cont === 'string' && data && typeof data === 'object' && !Array.isArray(data)) {
11
+ const obj = data;
12
+ if (!(typeof obj.continuation === 'string' && obj.continuation))
13
+ obj.continuation = cont;
14
+ }
15
+ return payload;
16
+ }
17
+ /** 构造「对象类型 + 严格禁止额外字段」的 JSON Schema。 */
18
+ export function schemaOf(properties, options = {}) {
19
+ return {
20
+ type: 'object',
21
+ additionalProperties: false,
22
+ properties,
23
+ ...(options.required?.length ? { required: options.required } : {}),
24
+ ...(options.description ? { description: options.description } : {}),
25
+ };
26
+ }
27
+ export function asObject(value) {
28
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
29
+ throw pfValidationError('input_not_object', '输入必须是 JSON 对象');
30
+ }
31
+ return value;
32
+ }