weaver-work-cli 0.1.60 → 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 (121) 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-I6WHKGR2.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-VLL6JOB4.js → chunk-6XSSAUNW.js} +4 -4
  10. package/dist/chunks/{chunk-VQWPQTEY.js → chunk-BIA2NKUG.js} +4 -4
  11. package/dist/chunks/{chunk-VMCCRWFO.js → chunk-BQYX2UX5.js} +2 -2
  12. package/dist/chunks/{chunk-XF7S6FQW.js → chunk-DTCQFTHW.js} +1 -1
  13. package/dist/chunks/{chunk-CPG6NLN4.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-HHH4K3YY.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-P7RXQDCA.js → chunk-T2KVJFWJ.js} +4 -4
  24. package/dist/chunks/{chunk-FMNCSYIG.js → chunk-TEZHIB6T.js} +2 -2
  25. package/dist/chunks/{chunk-HMIIVM2L.js → chunk-UBGWIXU3.js} +97 -45
  26. package/dist/chunks/{chunk-5N222HK6.js → chunk-UBRWONP4.js} +2 -2
  27. package/dist/chunks/{chunk-7U5YHCW7.js → chunk-UQFPF4EX.js} +2 -2
  28. package/dist/chunks/{chunk-4GG72JAT.js → chunk-V2LASYKO.js} +2 -2
  29. package/dist/chunks/{chunk-BDBTZVYA.js → chunk-VBFBMM7G.js} +55 -55
  30. package/dist/chunks/{chunk-YHSOCGKO.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-JFKMPRZB.js → chunk-YI2YMW5N.js} +50 -3
  34. package/dist/chunks/{conflict-QMDLS2EW.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-5ODJ7WJO.js → create-flow-EJZD434E.js} +6 -6
  38. package/dist/chunks/{data-LVDFIRNG.js → data-FOODGAMF.js} +278 -121
  39. package/dist/chunks/{ebuilder-form-7WA6X6ZI.js → ebuilder-form-I2EOKODG.js} +3 -3
  40. package/dist/chunks/{ehr-52GBKNJR.js → ehr-TE4RFNID.js} +2 -2
  41. package/dist/chunks/{entry-mode-73BJML22.js → entry-mode-ZOLSXEGX.js} +9 -5
  42. package/dist/chunks/{env-OHFS76HV.js → env-TID5NFR6.js} +2 -2
  43. package/dist/chunks/{esb-HJSXCEOM.js → esb-7L6MHYLB.js} +4 -4
  44. package/dist/chunks/{factory-FRTA2LP4.js → factory-OG7BPMH5.js} +1 -1
  45. package/dist/chunks/{fna-OBACRT3J.js → fna-6V2ENR3Y.js} +2 -2
  46. package/dist/chunks/{group-chat-KBFRPCR2.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-ARHVWK7G.js → meeting-5E3BNARL.js} +13 -13
  60. package/dist/chunks/{minute-doc-547KSYKR.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-H5HQ5QNH.js → registry-I4DVPDMU.js} +11 -11
  71. package/dist/chunks/{room-recommend-3UBROMZE.js → room-recommend-GWCVKCXW.js} +4 -4
  72. package/dist/chunks/{schedule-FTUQML6O.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 -90
  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 +84 -16
  88. package/dist/shortcuts/meeting/operations/eb/entry-mode.js +61 -7
  89. package/dist/shortcuts/performance/continuation.js +74 -0
  90. package/dist/shortcuts/performance/errors.js +65 -0
  91. package/dist/shortcuts/performance/host.js +105 -0
  92. package/dist/shortcuts/performance/index.js +109 -0
  93. package/dist/shortcuts/performance/manifest.js +30 -0
  94. package/dist/shortcuts/performance/operations/hrm-resolve.js +114 -0
  95. package/dist/shortcuts/performance/operations/registry.js +44 -0
  96. package/dist/shortcuts/performance/operations/scheme-detail.js +70 -0
  97. package/dist/shortcuts/performance/operations/scheme-draft.js +116 -0
  98. package/dist/shortcuts/performance/operations/scheme-publish.js +158 -0
  99. package/dist/shortcuts/performance/operations/types.js +32 -0
  100. package/dist/shortcuts/performance/scheme-validate.js +307 -0
  101. package/dist/shortcuts/performance/shared.js +158 -0
  102. package/docs/agent-io-channel-design.md +67 -3
  103. package/docs/data.md +2 -1
  104. package/package.json +1 -1
  105. package/scripts/xiaoe_env.py +6 -1
  106. package/skill-template/business-info.json +19 -0
  107. package/skill-template/domains/performance.md +18 -0
  108. package/skills/weaver-e10-caizhilian/SKILL.md +1 -1
  109. package/skills/weaver-e10-data/references/datasource.md +2 -1
  110. package/skills/weaver-e10-meeting/SKILL.md +5 -3
  111. package/skills/weaver-e10-performance/SKILL.md +202 -0
  112. package/skills/weaver-e10-performance/agents/openai.yaml +74 -0
  113. package/skills/weaver-e10-performance/references/default-assembly.md +108 -0
  114. package/skills/weaver-e10-performance/references/entity-resolution.md +69 -0
  115. package/skills/weaver-e10-performance/references/enums-and-normalization.md +80 -0
  116. package/skills/weaver-e10-performance/references/examples.md +146 -0
  117. package/skills/weaver-e10-performance/references/extraction-guide.md +144 -0
  118. package/skills/weaver-e10-performance/references/scheme-edit-req-fields.md +185 -0
  119. package/skills/weaver-e10-performance/references/scheme-setting-page.md +62 -0
  120. package/skills/weaver-e10-performance/scripts/parse_appraisal_doc.py +483 -0
  121. package/skills/weaver-e10-shared/references/json-output-contract.md +5 -0
@@ -1,69 +1,48 @@
1
1
  import { needArg } from '../host.js';
2
- import { dataValidationError } from '../errors.js';
2
+ import { dataApiError, dataValidationError } from '../errors.js';
3
3
  import { applyAppId, baseDto, parseOrder, parseStat, parseWhereArg, readListArg, renderTable, scanTips, tipsLines, } from './shared.js';
4
4
  // ---------------------------------------------------------------- 分组清单
5
5
  //
6
- // 这 58 个分组**仅作 `ds find` 的默认扫描候选集**,不参与任何取数参数推导。
7
- // 分组随环境模块安装情况增减,故支持 `--groups` 显式覆盖。
8
- const DS_GROUPS = [
9
- [1, '业务表单', 'weaver-formreport-service', 'form'],
10
- [2, '流程', 'weaver-workflow-report-serviceworkflowreport', 'workflow'],
11
- [3, '任务', 'weaver-project-servicetask', 'task'],
12
- [4, '日志', 'weaver-elog-service', 'elog'],
13
- [5, '会议', 'weaver-meeting-service', 'meeting'],
14
- [6, '日报', 'weaver-blog-service', 'blog'],
15
- [7, 'OKR', 'weaver-wr-goal-service', 'goal'],
16
- [8, '流程列表', 'weaver-workflow-list-service', 'workflow'],
17
- [9, '考勤', 'weaver-attend-service', 'attend'],
18
- [11, '组织画像', 'weaver-portrait-service', 'portrait'],
19
- [12, '工作流报告', 'weaver-workflow-report-serviceworkflow_report', 'workflow'],
20
- [13, '绩效', 'weaver-wr-performance-service', 'kpi'],
21
- [14, '项目', 'weaver-project-service', 'mainline'],
22
- [15, '基础定时模块', 'weaver-basic-schedule-service', 'escheduler'],
23
- [16, '知识画像', 'weaver-doc-service', 'document'],
24
- [17, 'HRM', 'weaver-hrm-service', 'hrm'],
25
- [18, 'e-builder报表', 'weaver-edcreportd-service', null],
26
- [19, 'e-builder应用', 'weaver-ebuilder-app-service', 'ebuilder'],
27
- [20, 'e-builder表单', 'weaver-ebuilder-form-service', 'ebuilder'],
28
- [21, '日程', 'weaver-calendar-service', 'calendar'],
29
- [22, '文档', 'weaver-doc-servicedocument', 'document'],
30
- [23, '文件', 'weaver-file-service', 'file'],
31
- [24, '公文管理', 'weaver-odoc-service', 'odoc'],
32
- [25, 'SCRM', 'weaver-crm-market-service', 'scrm'],
33
- [26, '协作区', 'weaver-cowork-service', 'cowork'],
34
- [27, '数据源', 'weaver-datasource-service', 'datasource'],
35
- [28, '计划报告', 'weaver-wr-plan-service', 'workreport'],
36
- [29, '电子签', 'weaver-signcenter-service', 'signcontract'],
37
- [30, '表单加密', 'weaver-datasecurity', 'datasecurity'],
38
- [31, '人事', 'weaver-hr-service', null],
39
- [32, '动作流', 'weaver-esb-setting-serviceesbCustom', 'esb'],
40
- [33, '发票云', 'weaver-inc-biz-service', 'inc'],
41
- [34, '绩效核算', 'weaver-ebuilder-contract-servicecmdatauFJXHS', 'ebuilder'],
42
- [35, 'EB合同管理', 'weaver-ebuilder-contract-service', null],
43
- [36, '待办事项', 'weaver-my-service', null],
44
- [37, '签名', 'weaver-signature-service', null],
45
- [38, '邮件', 'weaver-mail-base-service', 'email'],
46
- [39, '薪酬', 'weaver-hrm-salary', 'hrmsalary'],
47
- [40, '系统安全', 'weaver-security-framework-service', 'security'],
48
- [41, '公文交换中心', 'weaver-odocexchange-service', 'odocexchange'],
49
- [42, '招聘管理', 'weaver-recruit-service', 'recruit'],
50
- [43, '微搜', 'weaver-esearch-search-service', null],
51
- [44, '统一审批中心', 'weaver-intunifytodo-server-config-service', 'intunifytodos'],
52
- [45, '公共数据源', 'weaver-component-web-service', 'common'],
53
- [46, '数据分析', 'weaver-analyze-service', 'analyze'],
54
- [47, '财务模块', 'weaver-fna-expense-servicefexs', 'fna'],
55
- [48, 'ESB连接器', 'weaver-esb-setting-serviceesbConnect', 'esb'],
56
- [49, 'AI连接器', 'weaver-ai-application-service', 'ai'],
57
- [50, '外部流程', 'weaver-workflow-core-serviceworkflowCoreOuterwf', 'workflow'],
58
- [51, '绩效考核', 'weaver-wr-performance-eb-service', 'ebuilder'],
59
- [52, '问题定位平台', 'weaver-tissot-service', 'tissot'],
60
- [53, '工作流基础效率', 'weaver-workflow-report-serviceworkflowEffReport', 'workflow'],
61
- [54, '工作流操作者效率', 'weaver-workflow-report-serviceworkflowEffOperateReport', 'workflow'],
62
- [55, '工作流节点效率', 'weaver-workflow-report-serviceworkflowEffNodeReport', 'workflow'],
63
- [56, '规则引擎', 'weaver-logicflow-service', 'logicflow'],
64
- [57, '工作流表单', 'weaver-workflow-report-serviceworkflowFormReport', 'workflow'],
65
- [58, '统一认证中心', 'weaver-intunifyauth-server-base-service', null],
66
- ];
6
+ // 分组一律以 `/api/dw/ds/group` 的实时返回为准(sourceType 固定 LOGIC),
7
+ // 本文件不再内置任何分组常量:接口返回什么就是什么,随环境增减。
8
+ // `DS_CORE_GROUPS` / `DS_FIND_SEMANTIC_RULES` 只是「扫描优先级偏好」,
9
+ // 使用前必须与实时分组取交集,不得据此扩大扫描范围。
10
+ const DS_GROUPS_PATH = '/api/dw/ds/group';
11
+ /** 后端大小写敏感(传 `logic` ⇒ code=400),且不接受空串(⇒ code=500)。 */
12
+ const DS_GROUPS_SOURCE_TYPE = 'LOGIC';
13
+ /** 接口的 serviceMark 可能是 `""` 或直接缺字段 ⇒ 统一归一为 null。 */
14
+ function normalizeServiceMark(raw) {
15
+ return typeof raw === 'string' && raw.trim() !== '' ? raw : null;
16
+ }
17
+ function groupIndex(groups) {
18
+ return new Map(groups.map((group) => [group.groupId, group]));
19
+ }
20
+ /**
21
+ * 实时分组清单。单次命令内只取一次、由调用方把结果下传;不做模块级缓存
22
+ * (分组随环境变动,宁可贵一次也不留陈旧数据)。
23
+ */
24
+ async function fetchGroups(host) {
25
+ const response = await host.request({
26
+ method: 'GET',
27
+ path: DS_GROUPS_PATH,
28
+ query: { sourceType: DS_GROUPS_SOURCE_TYPE },
29
+ operation: 'ds.groups',
30
+ });
31
+ const rows = response?.data;
32
+ if (response?.code !== undefined && response.code !== 200) {
33
+ throw dataApiError('groups_failed', `分组清单接口返回失败:${response?.msg || `code=${response.code}`}`, { code: response.code, details: { sourceType: DS_GROUPS_SOURCE_TYPE } });
34
+ }
35
+ if (!Array.isArray(rows)) {
36
+ throw dataApiError('groups_failed', `分组清单接口异常:${response?.msg || '未返回 data 数组'}`, { code: response?.code, details: { sourceType: DS_GROUPS_SOURCE_TYPE } });
37
+ }
38
+ return rows
39
+ .filter((row) => row && typeof row.id === 'string' && row.id !== '')
40
+ .map((row) => ({
41
+ groupId: row.id,
42
+ label: String(row.name ?? ''),
43
+ serviceMark: normalizeServiceMark(row.serviceMark),
44
+ }));
45
+ }
67
46
  const DS_CORE_GROUPS = [
68
47
  'weaver-formreport-service',
69
48
  'weaver-ebuilder-form-service',
@@ -82,13 +61,11 @@ const DS_FIND_SEMANTIC_RULES = [
82
61
  { tag: '邮件/公文', re: /邮件|收件箱|公文|发文|档案|借阅/, groups: ['weaver-mail-base-service', 'weaver-odoc-service'] },
83
62
  { tag: '资产/日志', re: /资产|台账|日志|动作流|自动化/, groups: ['weaver-elog-service', 'weaver-esb-setting-serviceesbCustom'] },
84
63
  ];
85
- function groupLabel(groupId) {
86
- const hit = DS_GROUPS.find((item) => item[2] === groupId);
87
- return hit ? hit[1] : null;
64
+ function groupLabel(index, groupId) {
65
+ return index?.get(groupId)?.label ?? null;
88
66
  }
89
- function groupMark(groupId) {
90
- const hit = DS_GROUPS.find((item) => item[2] === groupId);
91
- return hit ? hit[3] : null;
67
+ function groupMark(index, groupId) {
68
+ return index?.get(groupId)?.serviceMark ?? null;
92
69
  }
93
70
  function explicitAppId(input) {
94
71
  const appId = input.app_id;
@@ -134,19 +111,28 @@ function renderFields(response) {
134
111
  return lines.length ? lines.join('\n') : '(空:未返回字段)';
135
112
  }
136
113
  // ---------------------------------------------------------------- 命令
137
- export async function dsGroups(input) {
114
+ export async function dsGroups(input, host) {
138
115
  const pattern = input.pattern ? String(input.pattern) : null;
139
- const groups = DS_GROUPS
140
- .filter((item) => !pattern || item[2].includes(pattern) || item[1].includes(pattern))
141
- .map((item) => ({ groupId: item[2], label: item[1], serviceMark: item[3] }));
116
+ const live = await fetchGroups(host);
117
+ const groups = live.filter((item) => !pattern
118
+ || item.groupId.includes(pattern)
119
+ || item.label.includes(pattern));
120
+ const liveIds = new Set(live.map((item) => item.groupId));
142
121
  const data = {
143
122
  count: groups.length,
144
123
  groups,
145
- coreGroups: DS_CORE_GROUPS,
146
- semanticRules: DS_FIND_SEMANTIC_RULES.map((rule) => ({ tag: rule.tag, groups: rule.groups })),
147
- note: '内置分组清单,仅用于 ds find 的默认扫描候选集;分组随环境变动时用 --groups 显式覆盖',
124
+ sourceType: DS_GROUPS_SOURCE_TYPE,
125
+ coreGroups: DS_CORE_GROUPS.filter((groupId) => liveIds.has(groupId)),
126
+ semanticRules: DS_FIND_SEMANTIC_RULES
127
+ .map((rule) => ({ tag: rule.tag, groups: rule.groups.filter((groupId) => liveIds.has(groupId)) }))
128
+ .filter((rule) => rule.groups.length > 0),
129
+ note: `分组清单来自 ${DS_GROUPS_PATH} 实时返回(sourceType=${DS_GROUPS_SOURCE_TYPE}),接口返回什么就是什么、随环境增减;`
130
+ + 'ds find 的默认扫描候选同样只取实时分组,需缩小范围时用 --groups 显式指定',
131
+ };
132
+ return {
133
+ data,
134
+ text: renderTable(`分组清单 ${groups.length} 个(实时)`, groups, ['groupId', 'label', 'serviceMark']),
148
135
  };
149
- return { data, text: renderTable(`内置分组清单 ${groups.length} 个`, groups, ['groupId', 'label', 'serviceMark']) };
150
136
  }
151
137
  export async function dsTables(input, host) {
152
138
  const groupId = needArg(input, 'group');
@@ -271,16 +257,17 @@ export async function dsCount(input, host) {
271
257
  };
272
258
  }
273
259
  // ---------------------------------------------------------------- find / describe
274
- function pickFindGroups(input, keyword) {
260
+ function pickFindGroups(input, keyword, live) {
275
261
  if (input.groups) {
276
262
  return { mode: 'explicit', groups: String(input.groups).split(',').map((item) => item.trim()).filter(Boolean) };
277
263
  }
278
264
  if (input.all_groups)
279
- return { mode: 'all', groups: DS_GROUPS.map((item) => item[2]) };
265
+ return { mode: 'all', groups: live.map((item) => item.groupId) };
280
266
  const max = Math.max(Number(input.max_groups || '6') || 6, DS_CORE_GROUPS.length);
267
+ const liveIds = new Set(live.map((item) => item.groupId));
281
268
  const picked = [];
282
269
  const push = (groupId) => {
283
- if (groupId && !picked.includes(groupId))
270
+ if (groupId && liveIds.has(groupId) && !picked.includes(groupId))
284
271
  picked.push(groupId);
285
272
  };
286
273
  for (const groupId of DS_CORE_GROUPS)
@@ -306,12 +293,12 @@ async function mapLimit(items, limit, fn) {
306
293
  await Promise.all(workers);
307
294
  return out;
308
295
  }
309
- async function scanGroups(host, groupIds, keyword, sourceType, pageSize, concurrency, appId, pages) {
296
+ async function scanGroups(host, index, groupIds, keyword, sourceType, pageSize, concurrency, appId, pages) {
310
297
  return mapLimit(groupIds, concurrency, async (groupId) => {
311
298
  const result = {
312
299
  groupId,
313
- label: groupLabel(groupId),
314
- serviceMark: groupMark(groupId),
300
+ label: groupLabel(index, groupId),
301
+ serviceMark: groupMark(index, groupId),
315
302
  records: [],
316
303
  error: null,
317
304
  total: null,
@@ -415,7 +402,7 @@ function routeHint(candidates) {
415
402
  return { channel: 'BLOG_DAILY', desc: 'BLOG_DAILY 模块配置通道(日报)', reason: '命中日报分组' };
416
403
  if (has((c) => c.serviceMark === 'document'))
417
404
  return { channel: 'DOCUMENT', desc: 'DOCUMENT 模块配置通道(文档)', reason: '命中文档分组' };
418
- if (has((c) => c.serviceMark === 'customer' || c.serviceMark === 'scrm')) {
405
+ if (has((c) => c.serviceMark === 'customer' || c.serviceMark === 'crm' || c.serviceMark === 'scrm')) {
419
406
  return { channel: 'CRM', desc: 'CRM 模块配置通道(客户/商机/线索)', reason: '命中 CRM 分组' };
420
407
  }
421
408
  if (has((c) => c.serviceMark === 'esb'))
@@ -431,9 +418,11 @@ export async function dsFind(input, host) {
431
418
  const pages = Math.min(Math.max(Number(input.pages || '1') || 1, 1), 50);
432
419
  const concurrency = Math.max(1, Number(input.concurrency || '10') || 10);
433
420
  const appId = explicitAppId(input);
434
- const picked = pickFindGroups(input, keyword);
421
+ const live = await fetchGroups(host);
422
+ const index = groupIndex(live);
423
+ const picked = pickFindGroups(input, keyword, live);
435
424
  const startedAt = Date.now();
436
- let scan = await scanGroups(host, picked.groups, keyword, sourceType, pageSize, concurrency, appId, pages);
425
+ let scan = await scanGroups(host, index, picked.groups, keyword, sourceType, pageSize, concurrency, appId, pages);
437
426
  const keywordNorm = keyword.replace(/\s+/g, '').toLowerCase();
438
427
  const looseSample = [];
439
428
  let looseDropped = 0;
@@ -462,8 +451,8 @@ export async function dsFind(input, host) {
462
451
  if (!scan.some((result) => result.records.length) && picked.mode === 'core' && !input.no_escalate && escalateOk) {
463
452
  escalated = true;
464
453
  const seen = new Set(picked.groups);
465
- const extra = DS_GROUPS.map((item) => item[2]).filter((groupId) => !seen.has(groupId));
466
- scan = scan.concat(applyStrict(await scanGroups(host, extra, keyword, sourceType, pageSize, concurrency, appId, pages)));
454
+ const extra = live.map((item) => item.groupId).filter((groupId) => !seen.has(groupId));
455
+ scan = scan.concat(applyStrict(await scanGroups(host, index, extra, keyword, sourceType, pageSize, concurrency, appId, pages)));
467
456
  }
468
457
  const elapsedMs = Date.now() - startedAt;
469
458
  const okScan = scan.filter((result) => !result.error);
@@ -596,6 +585,14 @@ export async function dsDescribe(input, host) {
596
585
  const tableId = String(needArg(input, 'table'));
597
586
  const sourceType = String(input.source_type || 'LOGIC');
598
587
  const startedAt = Date.now();
588
+ // 分组名 / serviceMark 仅用于输出提示:取不到时降级为 null,不影响 describe 主流程。
589
+ let index = null;
590
+ try {
591
+ index = groupIndex(await fetchGroups(host));
592
+ }
593
+ catch {
594
+ index = null;
595
+ }
599
596
  const branches = await Promise.all([
600
597
  (async () => {
601
598
  try {
@@ -651,7 +648,7 @@ export async function dsDescribe(input, host) {
651
648
  }
652
649
  })(),
653
650
  ]);
654
- const data = { groupId, groupLabel: groupLabel(groupId), tableId, sourceType, branches: branches.length };
651
+ const data = { groupId, groupLabel: groupLabel(index, groupId), tableId, sourceType, branches: branches.length };
655
652
  const errors = [];
656
653
  for (const branch of branches) {
657
654
  if (branch.error) {
@@ -663,7 +660,7 @@ export async function dsDescribe(input, host) {
663
660
  }
664
661
  }
665
662
  data.relatedFields = relatedHint(groupId, data.fields?.detailCount || 0);
666
- data.channelHint = routeHint([{ groupId, serviceMark: groupMark(groupId) }]);
663
+ data.channelHint = routeHint([{ groupId, serviceMark: groupMark(index, groupId) }]);
667
664
  data.permissionNote = groupId === 'weaver-ebuilder-form-service'
668
665
  ? '该分组是 EB 建模表单:取数不再做权限前置校验,--app-id 直接取 ebdf_obj.app_id(obj_id = ebdf_obj.id = 数据源 tableId)'
669
666
  : '非 EB 分组,数据源通道无需 appId';
@@ -681,4 +678,4 @@ export async function dsDescribe(input, host) {
681
678
  lines.push(`权限: ${data.permissionNote}`);
682
679
  return { data, text: lines.join('\n') };
683
680
  }
684
- export { DS_GROUPS, groupLabel, groupMark };
681
+ export { groupLabel, groupMark };
@@ -4,12 +4,13 @@ import { dsChart, dsCount, dsDescribe, dsFields, dsFieldsDsl, dsFind, dsGroups,
4
4
  import { attendStatis } from './attend.js';
5
5
  import { fieldName2id, fieldOptions } from './field.js';
6
6
  import { nounList, nounScope } from './noun.js';
7
+ import { attributionMetric } from './attribution.js';
7
8
  import { confAdd, confAddFile, confBatch, confBatchFile, confDelete, confGet, confGroup, confGroupFile, confResolve, confResolveFile, confUpdate, } from './conf.js';
8
9
  import { moduleCall } from './module.js';
9
10
  import { sceneGroups, sceneItems, sceneSearch } from './scene.js';
10
11
  const DEFINITIONS = [
11
12
  { name: 'data.dsl.query', summary: '直接执行 DSL 查询(executeQueryDsl;与 ds list/chart/stat/count 为独立通道)', capability: 'dsl', handler: executeQuery, command: 'query' },
12
- { name: 'data.ds.groups', summary: '内置数据源分组清单(仅用于 ds find 的默认扫描候选集)', capability: 'discovery', handler: dsGroups, command: 'ds groups' },
13
+ { name: 'data.ds.groups', summary: '数据源分组清单(实时 /api/dw/ds/group,sourceType=LOGIC)', capability: 'discovery', handler: dsGroups, command: 'ds groups' },
13
14
  { name: 'data.ds.find', summary: '按关键词跨分组找表(进程内并发扇出 + 本地过滤 + 路由建议)', capability: 'discovery', handler: dsFind, command: 'ds find' },
14
15
  { name: 'data.ds.describe', summary: '一次并发取回字段元数据 + 词库,并给出关联字段/通道提示', capability: 'discovery', handler: dsDescribe, command: 'ds describe' },
15
16
  { name: 'data.ds.tables', summary: '列某个分组下的数据集(表)清单', capability: 'metadata', handler: dsTables, command: 'ds tables' },
@@ -21,6 +22,7 @@ const DEFINITIONS = [
21
22
  { name: 'data.ds.count', summary: '计数(getCountData)', capability: 'fetch', handler: dsCount, command: 'ds count' },
22
23
  { name: 'data.noun.list', summary: '按 skill 取词库(ChatBI 名词解释)', capability: 'lexicon', handler: nounList, command: 'noun list' },
23
24
  { name: 'data.noun.scope', summary: '按数据集生效范围批量取词库(getChatBiDocByScopeId)', capability: 'lexicon', handler: nounScope, command: 'noun scope' },
25
+ { name: 'data.attribution.metric', summary: '按生效范围批量取归因分析设置(getAttributionMetricByScopeId;分组级 / 条目级绑定)', capability: 'attribution', handler: attributionMetric, command: 'attribution metric' },
24
26
  { name: 'data.field.name2id', summary: '名称 → 字段值 id 候选(浏览按钮类字段)', capability: 'field', handler: fieldName2id, command: 'field name2id' },
25
27
  { name: 'data.field.options', summary: 'Select/Radio/Checkbox 选项值字典(id↔name)', capability: 'field', handler: fieldOptions, command: 'field options' },
26
28
  { name: 'data.conf.get', summary: '按 confKey 取单条配置(confType 由前缀推导或 --type 指定)', capability: 'config', handler: confGet, command: 'conf get' },
@@ -40,6 +40,11 @@ export const builtinShortcuts = [
40
40
  description: '泛微E10招聘助手(JD生成/简历建档/AI面试邀约)CLI',
41
41
  load: async () => (await import('./recruit-stage/index.js')).recruitStageShortcut,
42
42
  }),
43
+ lazyShortcut({
44
+ name: 'performance',
45
+ description: '泛微E10绩效方案(文档导入/实体解析/落草稿/确认发布)CLI',
46
+ load: async () => (await import('./performance/index.js')).performanceShortcut,
47
+ }),
43
48
  lazyShortcut({
44
49
  name: 'cowork',
45
50
  description: '泛微E10协作区(协作事项/讨论/审批/共享权限)CLI',
@@ -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
- shaped.crm_members = rows;
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
- const skipPreflight = args.skipPreflight === true;
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
- let entryResolved = String(args.entryMode ?? '').trim();
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
- const resolvedAddressId = resolvedAddress?.id || addressId;
1853
- const addressDisplay = resolvedAddress?.name || addressId;
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
- if (addressInput && roomConfirmed && roomConflictData?.hasConflict === true) {
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
- * 建会入口选择记录:解决"流程工具已经问过、会议 skill 又问一遍"的重复询问。
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), `entry-${scope}.json`);
17
+ return join(meetingStateDir(env.ctx), 'entry-' + scope + '.json');
19
18
  }
20
- /** 读取当前会话的入口选择;过期或无记录返回 null。 */
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',