weaver-work-cli 0.1.44 → 0.1.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -5
- package/dist/chunks/{archive-P6TBQGKL.js → archive-ZQ4A4TV6.js} +388 -44
- package/dist/chunks/{archive-oa-7TQ2NXOH.js → archive-oa-BBDP7AKJ.js} +2 -2
- package/dist/chunks/{asset-3ELRG37G.js → asset-ZOJVBWZH.js} +2 -2
- package/dist/chunks/{asset-idle-WIGMUFMD.js → asset-idle-XGB5IPGT.js} +2 -2
- package/dist/chunks/{attachment-content-E3276UOV.js → attachment-content-CE3GMWTS.js} +3 -3
- package/dist/chunks/{blog-C5NMZAAC.js → blog-QSHLZSFW.js} +2 -2
- package/dist/chunks/caizhilian-KCQYFH72.js +204 -0
- package/dist/chunks/{calendar-FI2WNSBO.js → calendar-DLGMRJQA.js} +2 -2
- package/dist/chunks/{chunk-CWYGFU5B.js → chunk-3WBIQLMB.js} +2 -2
- package/dist/chunks/{chunk-PUQS5MWL.js → chunk-3YV7PKRL.js} +1 -1
- package/dist/chunks/{chunk-PC7VKEB5.js → chunk-3ZMAQQ3W.js} +161 -33
- package/dist/chunks/{chunk-GM6J7Q4B.js → chunk-4EXOIQDI.js} +40 -10
- package/dist/chunks/{chunk-ETNJSKMM.js → chunk-6NXT4ICB.js} +148 -21
- package/dist/chunks/chunk-762M5XJS.js +215 -0
- package/dist/chunks/{chunk-GAMZLAG2.js → chunk-77YP6I52.js} +1 -1
- package/dist/chunks/{chunk-WSF4NNMR.js → chunk-CZNZKOHR.js} +2 -2
- package/dist/chunks/{chunk-Z7VYWPZV.js → chunk-DGMYACGJ.js} +1 -1
- package/dist/chunks/{chunk-TA7FXXJD.js → chunk-DLY5GUXX.js} +1 -1
- package/dist/chunks/{chunk-BCVYBYYT.js → chunk-GR76ZDDX.js} +2 -2
- package/dist/chunks/{chunk-GRDRG6HP.js → chunk-HFXK54M4.js} +2 -2
- package/dist/chunks/{chunk-XNIK66I4.js → chunk-JB34OE7R.js} +790 -77
- package/dist/chunks/{chunk-QVSWRLLU.js → chunk-JWWTI63L.js} +55 -5
- package/dist/chunks/{chunk-FRZKBMSW.js → chunk-LGKWL4OH.js} +176 -39
- package/dist/chunks/{chunk-XHK4MDR5.js → chunk-LRCPNDZA.js} +38 -6
- package/dist/chunks/{chunk-OF4S23UB.js → chunk-LXFVWZLM.js} +4 -4
- package/dist/chunks/{chunk-D4ADSZ7H.js → chunk-O6CMPO65.js} +24 -1
- package/dist/chunks/{chunk-N4M2DDFE.js → chunk-OAE3AZBQ.js} +11 -11
- package/dist/chunks/chunk-P5GQRWDC.js +60 -0
- package/dist/chunks/{caizhilian-5XSM2DFP.js → chunk-PGO4ILMQ.js} +41 -521
- package/dist/chunks/{chunk-HIT4Y6OI.js → chunk-T4MWQAQB.js} +7 -5
- package/dist/chunks/{chunk-F4E4EM35.js → chunk-TGAGQV4I.js} +2 -2
- package/dist/chunks/{chunk-UFIT2UU3.js → chunk-U6R6FZHD.js} +168 -14
- package/dist/chunks/{chunk-FAZTGX7S.js → chunk-VIMCY4DI.js} +5 -5
- package/dist/chunks/chunk-VRPH24IC.js +76 -0
- package/dist/chunks/{chunk-3YBDYOC4.js → chunk-YIKSL36S.js} +2 -2
- package/dist/chunks/{chunk-IAZ3UPY6.js → chunk-Z6UUBY37.js} +2 -2
- package/dist/chunks/{conflict-ARLSZJ6V.js → conflict-IYJETSGT.js} +2 -2
- package/dist/chunks/continuation-GW6PRWK3.js +12 -0
- package/dist/chunks/{contract-DNIIW5VJ.js → contract-3QLAGYQL.js} +5793 -4591
- package/dist/chunks/{cowork-GMLRGVIW.js → cowork-3ACICHDQ.js} +2 -2
- package/dist/chunks/{create-flow-J22BO65E.js → create-flow-7JLC7UID.js} +6 -6
- package/dist/chunks/{ebuilder-form-ANV2FHYV.js → ebuilder-form-GWDTKEI2.js} +5 -5
- package/dist/chunks/{ehr-GSTGAIY3.js → ehr-MYRDCHZ4.js} +121 -49
- package/dist/chunks/{employee-22BGJ3QS.js → employee-NOHNXC46.js} +1 -1
- package/dist/chunks/{env-BX3VRFS7.js → env-3MBHAWBL.js} +2 -2
- package/dist/chunks/{esb-ATAIASX2.js → esb-4BQHNP5C.js} +4 -4
- package/dist/chunks/{factory-PETTFME6.js → factory-TZEVU4DU.js} +1 -1
- package/dist/chunks/{fna-YEKBSFSX.js → fna-ZVB2IILI.js} +2 -2
- package/dist/chunks/{group-chat-BFVXAYFX.js → group-chat-KL3HFKRM.js} +3 -3
- package/dist/chunks/{host-WIKN2EJ5.js → host-3TNBMDTR.js} +3 -3
- package/dist/chunks/host-7NTIBSPK.js +25 -0
- package/dist/chunks/{host-SZGV4UNT.js → host-7OWWPLM4.js} +3 -3
- package/dist/chunks/{host-HRBXEPDQ.js → host-G3VU7SDW.js} +3 -3
- package/dist/chunks/{host-LR55CTHP.js → host-M4XP5URR.js} +3 -3
- package/dist/chunks/{host-SUOY6VYQ.js → host-TUOIOEMC.js} +3 -3
- package/dist/chunks/{hrm-NRDO4W5G.js → hrm-UNKCCCGP.js} +5 -5
- package/dist/chunks/{im-IQ2HN23S.js → im-NJB7ZYMH.js} +3 -3
- package/dist/chunks/{invoice-MNRW76PP.js → invoice-OQP3TMKQ.js} +3 -3
- package/dist/chunks/{jiuchuanhui-DTRBAX4N.js → jiuchuanhui-ASFZBMPU.js} +2 -2
- package/dist/chunks/{lazy-dispatch-ZVWAI25B.js → lazy-dispatch-UH6HGK2I.js} +4 -4
- package/dist/chunks/{mail-ZVAUXOJA.js → mail-M3HJF5ER.js} +2 -2
- package/dist/chunks/{meeting-FEVPZ67S.js → meeting-C67EHQ4Z.js} +12 -12
- package/dist/chunks/{okr-SDH3E5RA.js → okr-EVX7FB5G.js} +2 -2
- package/dist/chunks/operations-J7PUIVWZ.js +15 -0
- package/dist/chunks/{plan-E35JFDI7.js → plan-2QJQEPBO.js} +2 -2
- package/dist/chunks/{project-73QXBAB2.js → project-XELELW2T.js} +2 -2
- package/dist/chunks/{reception-UWZVACBN.js → reception-5WITA44R.js} +2 -2
- package/dist/chunks/{recruit-stage-4MAOCKFY.js → recruit-stage-AHY5QAMF.js} +450 -117
- package/dist/chunks/{registry-JDUS4E7D.js → registry-AQVGHUM6.js} +2 -2
- package/dist/chunks/{registry-KNKSCJNT.js → registry-QJCZ2GVG.js} +4 -4
- package/dist/chunks/{registry-PO7SI256.js → registry-VWXWPVAG.js} +2 -2
- package/dist/chunks/{registry-IM5G23LS.js → registry-XPWPGHYE.js} +10 -10
- package/dist/chunks/{room-recommend-H7KLXA5R.js → room-recommend-CNWE5WQK.js} +6 -4
- package/dist/chunks/{schedule-ESZIBAUO.js → schedule-YYNYBQIE.js} +4 -4
- package/dist/chunks/{workflow-CWJFJLQU.js → workflow-BSYT5TGL.js} +6 -4
- package/dist/index.js +30 -30
- package/dist/internal/e10/auth/commands.js +32 -0
- package/dist/internal/e10/auth/error-log.js +156 -26
- package/dist/internal/e10/auth/xiaoe.js +176 -13
- package/dist/internal/e10/context.js +12 -1
- package/dist/shortcuts/archive/operations/borrow-list.js +105 -14
- package/dist/shortcuts/archive/operations/flow-url.js +182 -22
- package/dist/shortcuts/archive/operations/getPageUrl.js +75 -0
- package/dist/shortcuts/archive/operations/prelib.js +33 -4
- package/dist/shortcuts/archive/operations/shared.js +52 -0
- package/dist/shortcuts/contract/host.js +111 -4
- package/dist/shortcuts/contract/index.js +19 -0
- package/dist/shortcuts/contract/manifest.js +125 -0
- package/dist/shortcuts/contract/ooxml/clause-insert.js +249 -0
- package/dist/shortcuts/contract/operations/clause-insert.js +56 -0
- package/dist/shortcuts/contract/operations/customer.js +192 -0
- package/dist/shortcuts/contract/operations/file-download.js +75 -0
- package/dist/shortcuts/contract/operations/flow.js +44 -2
- package/dist/shortcuts/contract/operations/form-info.js +162 -62
- package/dist/shortcuts/contract/operations/registry.js +8 -0
- package/dist/shortcuts/contract/operations/review.js +116 -1
- package/dist/shortcuts/contract/operations/summary.js +177 -0
- package/dist/shortcuts/contract/operations/upload.js +64 -4
- package/dist/shortcuts/contract/upload-cache.js +104 -0
- package/dist/shortcuts/ehr/operations/recruit-candidate-import.js +4 -2
- package/dist/shortcuts/ehr/operations/recruit-position.js +136 -35
- package/dist/shortcuts/ehr/operations/recruit-write.js +17 -18
- package/dist/shortcuts/ehr/operations/recruit.js +17 -5
- package/dist/shortcuts/hrm/operations/employee.js +29 -1
- package/dist/shortcuts/meeting/operations/eb/create-flow.js +182 -58
- package/dist/shortcuts/meeting/operations/eb/draft-memory.js +56 -0
- package/dist/shortcuts/meeting/operations/eb/factory.js +58 -3
- package/dist/shortcuts/meeting/operations/eb/person-cache.js +2 -2
- package/dist/shortcuts/meeting/operations/eb/room-recommend.js +47 -5
- package/dist/shortcuts/meeting/operations/invitation-publish.js +132 -0
- package/dist/shortcuts/meeting/operations/registry.js +2 -0
- package/dist/shortcuts/recruit-stage/operations/interview-arrange.js +86 -16
- package/dist/shortcuts/recruit-stage/operations/interview-feedback.js +6 -4
- package/dist/shortcuts/recruit-stage/operations/jd-create.js +208 -56
- package/dist/shortcuts/recruit-stage/operations/resume-import.js +42 -16
- package/dist/shortcuts/recruit-stage/shared.js +161 -18
- package/dist/shortcuts/workflow/index.js +2 -0
- package/dist/shortcuts/workflow/operations/read.js +8 -3
- package/dist/shortcuts/workflow/operations/todoSmartConvert/aigroupRules.js +92 -5
- package/dist/shortcuts/workflow/operations/todoSmartConvert/priorityExpr.js +509 -0
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoListRows.js +22 -1
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.collect.js +32 -6
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.core.js +57 -11
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.group.js +165 -52
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.js +57 -14
- package/dist/shortcuts/workflow/operations/todoSmartConvert/todoSmartConvert.smartGroup.js +44 -18
- package/docs/contract.md +1 -0
- package/docs/e10-auth.md +4 -2
- package/docs/todo-smart-convert/data-contract.md +7 -0
- package/package.json +1 -1
- package/skill-template/domains/jinchengda.md +2 -0
- package/skills/weaver-e10-jinchengda/SKILL.md +198 -205
- package/skills/weaver-e10-jinchengda/references/contract-action-card.md +759 -0
- package/skills/weaver-e10-jinchengda/references/contract-action-engine.md +250 -0
- package/skills/weaver-e10-jinchengda/references/contract-ai-review.md +146 -7
- package/skills/weaver-e10-jinchengda/references/contract-clause-insert.md +178 -0
- package/skills/weaver-e10-jinchengda/references/contract-command-index.md +75 -0
- package/skills/weaver-e10-jinchengda/references/contract-compare-report-template.html +137 -0
- package/skills/weaver-e10-jinchengda/references/contract-compare-report.md +163 -0
- package/skills/weaver-e10-jinchengda/references/contract-credit-page.md +52 -3
- package/skills/weaver-e10-jinchengda/references/contract-doc-compare.md +92 -5
- package/skills/weaver-e10-jinchengda/references/contract-doc-triage.md +602 -0
- package/skills/weaver-e10-jinchengda/references/contract-element-extract.md +209 -0
- package/skills/weaver-e10-jinchengda/references/contract-execution-rules.md +126 -0
- package/skills/weaver-e10-jinchengda/references/contract-field-extract-new-customer.md +312 -0
- package/skills/weaver-e10-jinchengda/references/contract-field-extract-other-flows.md +555 -0
- package/skills/weaver-e10-jinchengda/references/contract-flow-launch.md +47 -12
- package/skills/weaver-e10-jinchengda/references/contract-object-detect.md +469 -0
- package/skills/weaver-e10-jinchengda/references/contract-quote-to-contract.md +154 -1
- package/skills/weaver-e10-jinchengda/references/contract-type-fingerprints.md +224 -0
- package/skills/weaver-e10-jinchengda/references/orchestration.md +355 -0
- package/skills/weaver-e10-jucailin/references/recruit-create.md +5 -3
- package/skills/weaver-e10-jucailin/references/recruit-write.md +2 -2
- package/skills/weaver-e10-meeting/SKILL.md +57 -9
- package/skills/weaver-e10-recruit-stage/SKILL.md +11 -6
- package/skills/weaver-e10-recruit-stage/agents/openai.yaml +10 -2
- package/skills/weaver-e10-recruit-stage/references/position-templates.md +3 -1
- package/skills/weaver-e10-recruit-stage/references/recruit-arrange-interview.md +13 -1
- package/skills/weaver-e10-recruit-stage/references/recruit-jd-create.md +19 -18
- package/skills/weaver-e10-recruit-stage/references/recruit-output-links.md +27 -14
- package/skills/weaver-e10-recruit-stage/references/recruit-resume-import.md +7 -1
- package/skills/weaver-e10-shared/references/e10-auth-and-session.md +4 -2
- package/skills/weaver-e10-wenshuding/SKILL.md +17 -7
- package/skills/weaver-e10-wenshuding/references/archive-borrow-list.md +28 -0
- package/skills/weaver-e10-wenshuding/references/archive-flow.md +24 -8
- package/skills/weaver-e10-wenshuding/references/archive-prelib-list.md +3 -0
- package/skills/weaver-e10-wenshuding/references/archive-prelib-open.md +4 -0
- package/skills/weaver-e10-wenshuding/references/archive-search.md +3 -1
- package/skills/weaver-e10-workflow/SKILL.md +19 -17
- package/skills/weaver-e10-workflow/aigroup/default.json +10 -6
- package/skills/weaver-e10-workflow/references/todo-smart-convert.md +36 -3
- package/skills/weaver-e10-workflow/references/workflow-memory.md +1 -1
- package/skills/weaver-e10-workflow/references/workflow-query.md +9 -6
- package/skills/weaver-e10-workflow/tools/todo-summary.cjs +152 -1
- package/skills/weaver-e10-yimiaoban/SKILL.md +17 -5
- package/skills/weaver-e10-yimiaoban/references/msg-write.md +30 -0
- package/skills/weaver-e10-yimiaoban/references/session-sysmsg.md +72 -0
- package/skills/weaver-e10-yimiaoban/references/source-manifest.json +7 -7
|
@@ -1,12 +1,55 @@
|
|
|
1
1
|
import { archiveValidationError } from '../errors.js';
|
|
2
2
|
import { READ, WRITE, archiveSuccess, schemaOf, } from './types.js';
|
|
3
|
-
import { unwrapData } from './shared.js';
|
|
3
|
+
import { buildOpenAction, unwrapData } from './shared.js';
|
|
4
4
|
import { assertLeaseTarget, issueLease, verifyLease } from './confirm.js';
|
|
5
5
|
const BORROW_CAR_APPLY = 'archive.flow.borrow-car.apply';
|
|
6
6
|
const SEARCH_APPLY = 'archive.flow.search.apply';
|
|
7
7
|
const RENEW_APPLY = 'archive.flow.renew.apply';
|
|
8
8
|
const ARC_ID_PATTERN = /^\d+_\d+$/;
|
|
9
9
|
const NUMERIC_PATTERN = /^\d+$/;
|
|
10
|
+
const DATE_ONLY_PATTERN = /^\d{4}-\d{2}-\d{2}$/u;
|
|
11
|
+
const DATE_TIME_PATTERN = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(:\d{2})?$/u;
|
|
12
|
+
/** 未给预计归还时间时的默认借期(天)。 */
|
|
13
|
+
const DEFAULT_BORROW_DAYS = 7;
|
|
14
|
+
/** 借阅原因:必填,最多 200 字。 */
|
|
15
|
+
function requireReason(value) {
|
|
16
|
+
const reason = String(value ?? '').trim();
|
|
17
|
+
if (!reason) {
|
|
18
|
+
throw archiveValidationError('reason_required', '请先向用户确认借阅原因(reason)后再发起借阅');
|
|
19
|
+
}
|
|
20
|
+
if (reason.length > 200) {
|
|
21
|
+
throw archiveValidationError('reason_too_long', '借阅原因不能超过 200 字');
|
|
22
|
+
}
|
|
23
|
+
return reason;
|
|
24
|
+
}
|
|
25
|
+
/** 统一输出 `YYYY-MM-DD`:流程页日期字段只认日期,带时间会被 URL 转义成 `+`/`%3A`。 */
|
|
26
|
+
function formatDate(date) {
|
|
27
|
+
const pad = (value) => String(value).padStart(2, '0');
|
|
28
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 预计归还时间:接受 `YYYY-MM-DD` 或 `YYYY-MM-DD HH:mm[:ss]`,统一归一成 `YYYY-MM-DD`(时间部分忽略)。
|
|
32
|
+
* 未提供时默认「当前日期 + 7 天」,并在结果里标记 `returnDateTimeDefaulted=true`。
|
|
33
|
+
*/
|
|
34
|
+
function resolveReturnDateTime(value, now = new Date()) {
|
|
35
|
+
const raw = String(value ?? '').trim();
|
|
36
|
+
if (!raw) {
|
|
37
|
+
return { text: formatDate(new Date(now.getTime() + DEFAULT_BORROW_DAYS * 24 * 3600 * 1000)), defaulted: true };
|
|
38
|
+
}
|
|
39
|
+
const normalized = raw.replace('T', ' ');
|
|
40
|
+
const withTime = DATE_ONLY_PATTERN.test(normalized) ? `${normalized} 00:00:00` : normalized;
|
|
41
|
+
if (!DATE_TIME_PATTERN.test(withTime)) {
|
|
42
|
+
throw archiveValidationError('return_date_time_invalid', '预计归还时间格式应为 YYYY-MM-DD 或 YYYY-MM-DD HH:mm:ss');
|
|
43
|
+
}
|
|
44
|
+
const parsed = Date.parse(withTime.replace(' ', 'T'));
|
|
45
|
+
if (Number.isNaN(parsed)) {
|
|
46
|
+
throw archiveValidationError('return_date_time_invalid', '预计归还时间无法解析,请检查日期是否有效');
|
|
47
|
+
}
|
|
48
|
+
if (parsed < now.getTime()) {
|
|
49
|
+
throw archiveValidationError('return_date_time_invalid', '预计归还时间不能早于当前时间');
|
|
50
|
+
}
|
|
51
|
+
return { text: formatDate(new Date(parsed)), defaulted: false };
|
|
52
|
+
}
|
|
10
53
|
function requireArcIds(value, field) {
|
|
11
54
|
if (!Array.isArray(value) || value.length === 0) {
|
|
12
55
|
throw archiveValidationError('arc_ids_required', `${field} 必填且至少一项`);
|
|
@@ -58,16 +101,31 @@ async function addCache(host, value, logFlag) {
|
|
|
58
101
|
}
|
|
59
102
|
function buildFlowUrl(baseUrl, workflowId, params) {
|
|
60
103
|
const root = baseUrl.replace(/\/+$/, '');
|
|
61
|
-
|
|
104
|
+
// 不用 URLSearchParams:它把空格编码成 `+`,流程页按 `+` 解码会得到错误值;这里统一用 %20
|
|
105
|
+
const search = Object.entries(params)
|
|
106
|
+
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
|
|
107
|
+
.join('&');
|
|
62
108
|
return `${root}/sp/workflow/flowpage/fullCreate/${workflowId}?${search}`;
|
|
63
109
|
}
|
|
64
|
-
function flowResult(action, baseUrl, workflowId, params, extra = {}) {
|
|
110
|
+
function flowResult(ctx, action, baseUrl, workflowId, params, extra = {}) {
|
|
111
|
+
const url = buildFlowUrl(baseUrl, workflowId, params);
|
|
112
|
+
// 与流程 workflow.open 同结构:markdown + clientAction + requiresHostAction(CLI 不自己打开)
|
|
113
|
+
const open = buildOpenAction(ctx, url, '填写并提交');
|
|
65
114
|
return archiveSuccess(action, {
|
|
66
115
|
...extra,
|
|
67
116
|
workflowId,
|
|
68
|
-
url
|
|
117
|
+
url,
|
|
69
118
|
params,
|
|
70
|
-
|
|
119
|
+
markdown: open.markdown,
|
|
120
|
+
hasXiaoEEnv: open.hasXiaoEEnv,
|
|
121
|
+
// 小E 环境:给出 <browsertool> 需要的参数,由调用方渲染成单行标签放在业务数据之后
|
|
122
|
+
...(open.browserTool ? { browserTool: open.browserTool } : {}),
|
|
123
|
+
requiresHostAction: open.requiresHostAction,
|
|
124
|
+
opened: open.opened,
|
|
125
|
+
clientAction: open.clientAction,
|
|
126
|
+
hint: open.hasXiaoEEnv
|
|
127
|
+
? '始终把 markdown 的 Markdown 超链接(a 标签)返回,保证可点击;browserTool 是 <browsertool> 的参数,序列化成单行标签后放在这条数据之后单独一行渲染,小E 客户端据此在右侧内置浏览器打开;opened 恒为 false'
|
|
128
|
+
: '始终把 markdown 的 Markdown 超链接(a 标签)返回,保证可点击;打开动作按 clientAction(type: openUrl)由宿主执行,走系统默认浏览器;CLI 与 Agent 都不要执行 open/start',
|
|
71
129
|
}, { wrote: true });
|
|
72
130
|
}
|
|
73
131
|
const flowBorrowCarPrepare = {
|
|
@@ -81,18 +139,40 @@ const flowBorrowCarPrepare = {
|
|
|
81
139
|
inputSchema: schemaOf({
|
|
82
140
|
arcIds: { type: 'array', items: { type: 'string' }, description: '档案标识数组,元素为 {档案ID}_{表单ID}' },
|
|
83
141
|
carIds: { type: 'array', items: { type: 'string' }, description: '借阅车记录 ID 数组,与 arcIds 一一对应' },
|
|
84
|
-
|
|
142
|
+
reason: { type: 'string', description: '借阅原因(必填,对话中向用户确认)' },
|
|
143
|
+
returnDateTime: {
|
|
144
|
+
type: 'string',
|
|
145
|
+
description: '预计归还时间 YYYY-MM-DD 或 YYYY-MM-DD HH:mm:ss;不传时默认当前时间 + 7 天',
|
|
146
|
+
},
|
|
147
|
+
}, { required: ['arcIds', 'carIds', 'reason'], description: '从借阅车发起借阅' }),
|
|
85
148
|
handler: async (args, env) => {
|
|
86
149
|
const arcIds = requireArcIds(args.arcIds, 'arcIds');
|
|
87
150
|
const carIds = requireIdList(args.carIds, 'carIds');
|
|
88
151
|
if (arcIds.length !== carIds.length) {
|
|
89
152
|
throw archiveValidationError('id_count_mismatch', 'arcIds 与 carIds 数量必须一致');
|
|
90
153
|
}
|
|
154
|
+
const reason = requireReason(args.reason);
|
|
155
|
+
const returnDateTime = resolveReturnDateTime(args.returnDateTime);
|
|
91
156
|
const workflowId = await fetchWorkflowId(env.host);
|
|
92
|
-
const { continuation, expiresInMs } = await issueLease(env, BORROW_CAR_APPLY, {
|
|
157
|
+
const { continuation, expiresInMs } = await issueLease(env, BORROW_CAR_APPLY, {
|
|
158
|
+
workflowId,
|
|
159
|
+
arcIds,
|
|
160
|
+
carIds,
|
|
161
|
+
reason,
|
|
162
|
+
returnDateTime: returnDateTime.text,
|
|
163
|
+
returnDateTimeDefaulted: returnDateTime.defaulted,
|
|
164
|
+
});
|
|
93
165
|
return archiveSuccess('archive.flow.borrow-car.prepare', {
|
|
94
|
-
preview: {
|
|
95
|
-
|
|
166
|
+
preview: {
|
|
167
|
+
workflowId,
|
|
168
|
+
count: arcIds.length,
|
|
169
|
+
arcIds,
|
|
170
|
+
carIds,
|
|
171
|
+
reason,
|
|
172
|
+
returnDateTime: returnDateTime.text,
|
|
173
|
+
...(returnDateTime.defaulted ? { returnDateTimeDefaulted: true } : {}),
|
|
174
|
+
},
|
|
175
|
+
hint: '票据已就绪:直接调用 archive.flow.borrow-car.apply(CLI:archive flow borrow-car-apply --continuation <token> --yes),不要再向用户二次确认——用户打开链接点「填写并提交」即为确认',
|
|
96
176
|
continuation,
|
|
97
177
|
}, { requiresConfirmation: true, expiresInMs });
|
|
98
178
|
},
|
|
@@ -118,17 +198,28 @@ const flowBorrowCarApply = {
|
|
|
118
198
|
if (!workflowId || arcIds.length === 0 || arcIds.length !== carIds.length) {
|
|
119
199
|
throw archiveValidationError('continuation_payload_invalid', '确认票据缺少 workflowId / arcIds / carIds');
|
|
120
200
|
}
|
|
201
|
+
const reason = requireReason(lease.reason);
|
|
202
|
+
const returnDateTime = resolveReturnDateTime(lease.returnDateTime);
|
|
121
203
|
const arcIndex = await addCache(env.host, arcIds.join(','), 'borrowCart');
|
|
122
204
|
const carIndex = await addCache(env.host, carIds.join(','), 'borrowCart');
|
|
123
205
|
const session = await env.host.getSession();
|
|
124
|
-
return flowResult(BORROW_CAR_APPLY, session.baseUrl, workflowId, {
|
|
206
|
+
return flowResult(env.ctx, BORROW_CAR_APPLY, session.baseUrl, workflowId, {
|
|
125
207
|
workflowId,
|
|
126
208
|
isCreate: '1',
|
|
127
209
|
isAddIdentify: '1',
|
|
128
210
|
isBorrow: '1',
|
|
129
211
|
arcDataId: `arcCache_${arcIndex}`,
|
|
130
212
|
arcBorrowCarIds: `arcCache_${carIndex}`,
|
|
131
|
-
|
|
213
|
+
reason,
|
|
214
|
+
return_date_time: returnDateTime.text,
|
|
215
|
+
}, {
|
|
216
|
+
mode: 'borrowCar',
|
|
217
|
+
count: arcIds.length,
|
|
218
|
+
caches: { arcDataId: arcIndex, arcBorrowCarIds: carIndex },
|
|
219
|
+
reason,
|
|
220
|
+
returnDateTime: returnDateTime.text,
|
|
221
|
+
...(returnDateTime.defaulted ? { returnDateTimeDefaulted: true } : {}),
|
|
222
|
+
});
|
|
132
223
|
},
|
|
133
224
|
};
|
|
134
225
|
const flowSearchPrepare = {
|
|
@@ -139,14 +230,36 @@ const flowSearchPrepare = {
|
|
|
139
230
|
summary: '从全文检索结果直接发起借阅:检查流程绑定并生成确认票据(不写数据)',
|
|
140
231
|
capability: 'archive',
|
|
141
232
|
risk: READ,
|
|
142
|
-
inputSchema: schemaOf({
|
|
233
|
+
inputSchema: schemaOf({
|
|
234
|
+
arcIds: { type: 'array', items: { type: 'string' }, description: '档案标识数组,元素为 {档案ID}_{表单ID}' },
|
|
235
|
+
reason: { type: 'string', description: '借阅原因(必填,对话中向用户确认)' },
|
|
236
|
+
returnDateTime: {
|
|
237
|
+
type: 'string',
|
|
238
|
+
description: '预计归还时间 YYYY-MM-DD 或 YYYY-MM-DD HH:mm:ss;不传时默认当前时间 + 7 天',
|
|
239
|
+
},
|
|
240
|
+
}, { required: ['arcIds', 'reason'], description: '从检索结果发起借阅' }),
|
|
143
241
|
handler: async (args, env) => {
|
|
144
242
|
const arcIds = requireArcIds(args.arcIds, 'arcIds');
|
|
243
|
+
const reason = requireReason(args.reason);
|
|
244
|
+
const returnDateTime = resolveReturnDateTime(args.returnDateTime);
|
|
145
245
|
const workflowId = await fetchWorkflowId(env.host);
|
|
146
|
-
const { continuation, expiresInMs } = await issueLease(env, SEARCH_APPLY, {
|
|
246
|
+
const { continuation, expiresInMs } = await issueLease(env, SEARCH_APPLY, {
|
|
247
|
+
workflowId,
|
|
248
|
+
arcIds,
|
|
249
|
+
reason,
|
|
250
|
+
returnDateTime: returnDateTime.text,
|
|
251
|
+
returnDateTimeDefaulted: returnDateTime.defaulted,
|
|
252
|
+
});
|
|
147
253
|
return archiveSuccess('archive.flow.search.prepare', {
|
|
148
|
-
preview: {
|
|
149
|
-
|
|
254
|
+
preview: {
|
|
255
|
+
workflowId,
|
|
256
|
+
count: arcIds.length,
|
|
257
|
+
arcIds,
|
|
258
|
+
reason,
|
|
259
|
+
returnDateTime: returnDateTime.text,
|
|
260
|
+
...(returnDateTime.defaulted ? { returnDateTimeDefaulted: true } : {}),
|
|
261
|
+
},
|
|
262
|
+
hint: '票据已就绪:直接调用 archive.flow.search.apply(CLI:archive flow search-apply --continuation <token> --yes),不要再向用户二次确认——用户打开链接点「填写并提交」即为确认',
|
|
150
263
|
continuation,
|
|
151
264
|
}, { requiresConfirmation: true, expiresInMs });
|
|
152
265
|
},
|
|
@@ -171,15 +284,26 @@ const flowSearchApply = {
|
|
|
171
284
|
if (!workflowId || arcIds.length === 0) {
|
|
172
285
|
throw archiveValidationError('continuation_payload_invalid', '确认票据缺少 workflowId / arcIds');
|
|
173
286
|
}
|
|
287
|
+
const reason = requireReason(lease.reason);
|
|
288
|
+
const returnDateTime = resolveReturnDateTime(lease.returnDateTime);
|
|
174
289
|
const arcIndex = await addCache(env.host, arcIds.join(','));
|
|
175
290
|
const session = await env.host.getSession();
|
|
176
|
-
return flowResult(SEARCH_APPLY, session.baseUrl, workflowId, {
|
|
291
|
+
return flowResult(env.ctx, SEARCH_APPLY, session.baseUrl, workflowId, {
|
|
177
292
|
workflowId,
|
|
178
293
|
isCreate: '1',
|
|
179
294
|
isAddIdentify: '1',
|
|
180
295
|
isBorrow: '1',
|
|
181
296
|
arcDataId: `arcCache_${arcIndex}`,
|
|
182
|
-
|
|
297
|
+
reason,
|
|
298
|
+
return_date_time: returnDateTime.text,
|
|
299
|
+
}, {
|
|
300
|
+
mode: 'search',
|
|
301
|
+
count: arcIds.length,
|
|
302
|
+
caches: { arcDataId: arcIndex },
|
|
303
|
+
reason,
|
|
304
|
+
returnDateTime: returnDateTime.text,
|
|
305
|
+
...(returnDateTime.defaulted ? { returnDateTimeDefaulted: true } : {}),
|
|
306
|
+
});
|
|
183
307
|
},
|
|
184
308
|
};
|
|
185
309
|
const flowRenewPrepare = {
|
|
@@ -190,17 +314,38 @@ const flowRenewPrepare = {
|
|
|
190
314
|
summary: '借阅单续借:检查流程绑定并生成确认票据(不写数据)',
|
|
191
315
|
capability: 'archive',
|
|
192
316
|
risk: READ,
|
|
193
|
-
inputSchema: schemaOf({
|
|
317
|
+
inputSchema: schemaOf({
|
|
318
|
+
dataId: { type: 'string', pattern: '^\\d+$', description: '借阅单主表数据 ID' },
|
|
319
|
+
reason: { type: 'string', description: '续借事由(必填,对话中向用户确认)' },
|
|
320
|
+
returnDateTime: {
|
|
321
|
+
type: 'string',
|
|
322
|
+
description: '续借后的预计归还时间 YYYY-MM-DD;不传时默认当前日期 + 7 天',
|
|
323
|
+
},
|
|
324
|
+
}, { required: ['dataId', 'reason'], description: '借阅单续借' }),
|
|
194
325
|
handler: async (args, env) => {
|
|
195
326
|
const dataId = String(args.dataId ?? '').trim();
|
|
196
327
|
if (!NUMERIC_PATTERN.test(dataId)) {
|
|
197
328
|
throw archiveValidationError('data_id_invalid', 'dataId 必填且为数字 ID');
|
|
198
329
|
}
|
|
330
|
+
const reason = requireReason(args.reason);
|
|
331
|
+
const returnDateTime = resolveReturnDateTime(args.returnDateTime);
|
|
199
332
|
const workflowId = await fetchWorkflowId(env.host);
|
|
200
|
-
const { continuation, expiresInMs } = await issueLease(env, RENEW_APPLY, {
|
|
333
|
+
const { continuation, expiresInMs } = await issueLease(env, RENEW_APPLY, {
|
|
334
|
+
workflowId,
|
|
335
|
+
dataId,
|
|
336
|
+
reason,
|
|
337
|
+
returnDateTime: returnDateTime.text,
|
|
338
|
+
returnDateTimeDefaulted: returnDateTime.defaulted,
|
|
339
|
+
});
|
|
201
340
|
return archiveSuccess('archive.flow.renew.prepare', {
|
|
202
|
-
preview: {
|
|
203
|
-
|
|
341
|
+
preview: {
|
|
342
|
+
workflowId,
|
|
343
|
+
dataId,
|
|
344
|
+
reason,
|
|
345
|
+
returnDateTime: returnDateTime.text,
|
|
346
|
+
...(returnDateTime.defaulted ? { returnDateTimeDefaulted: true } : {}),
|
|
347
|
+
},
|
|
348
|
+
hint: '票据已就绪:直接调用 archive.flow.renew.apply(CLI:archive flow renew-apply --continuation <token> --yes),不要再向用户二次确认——用户打开链接点「填写并提交」即为确认',
|
|
204
349
|
continuation,
|
|
205
350
|
}, { requiresConfirmation: true, expiresInMs });
|
|
206
351
|
},
|
|
@@ -226,8 +371,23 @@ const flowRenewApply = {
|
|
|
226
371
|
throw archiveValidationError('continuation_payload_invalid', '确认票据缺少 workflowId / dataId');
|
|
227
372
|
}
|
|
228
373
|
assertLeaseTarget(lease, args, ['dataId'], RENEW_APPLY);
|
|
374
|
+
const reason = requireReason(lease.reason);
|
|
375
|
+
const returnDateTime = resolveReturnDateTime(lease.returnDateTime);
|
|
229
376
|
const session = await env.host.getSession();
|
|
230
|
-
return flowResult(RENEW_APPLY, session.baseUrl, workflowId, {
|
|
377
|
+
return flowResult(env.ctx, RENEW_APPLY, session.baseUrl, workflowId, {
|
|
378
|
+
workflowId,
|
|
379
|
+
isCreate: '1',
|
|
380
|
+
arcDataId: dataId,
|
|
381
|
+
isReNew: '1',
|
|
382
|
+
reason,
|
|
383
|
+
return_date_time: returnDateTime.text,
|
|
384
|
+
}, {
|
|
385
|
+
mode: 'renew',
|
|
386
|
+
dataId,
|
|
387
|
+
reason,
|
|
388
|
+
returnDateTime: returnDateTime.text,
|
|
389
|
+
...(returnDateTime.defaulted ? { returnDateTimeDefaulted: true } : {}),
|
|
390
|
+
});
|
|
231
391
|
},
|
|
232
392
|
};
|
|
233
393
|
export const flowUrlOperations = [
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { mkdirSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { stateDir } from '../../../core/state.js';
|
|
5
|
+
import { writeWithRetry } from '../../../core/write-with-retry.js';
|
|
2
6
|
import { archiveValidationError } from '../errors.js';
|
|
3
7
|
import { unwrapData } from './shared.js';
|
|
4
8
|
/**
|
|
@@ -135,3 +139,74 @@ export async function fetchArchiveListDatas(host, target, pageNo, logFlag) {
|
|
|
135
139
|
...(total === undefined ? {} : { total }),
|
|
136
140
|
};
|
|
137
141
|
}
|
|
142
|
+
/** 借阅单表单 ID 的进程内缓存:同一「环境 + 租户」只解析一次。 */
|
|
143
|
+
const borrowFormIdCache = new Map();
|
|
144
|
+
/** 借阅单表单 ID 的落盘缓存文件名(放在 CLI state 目录,跨命令复用)。 */
|
|
145
|
+
const FORM_ID_CACHE_FILE = 'archive-form-ids.json';
|
|
146
|
+
function borrowFormIdCacheKey(session) {
|
|
147
|
+
const baseUrl = String(session?.baseUrl ?? '').replace(/\/+$/, '');
|
|
148
|
+
return `${baseUrl}|${String(session?.tenantKey ?? '')}`;
|
|
149
|
+
}
|
|
150
|
+
function readFormIdCache(ctx) {
|
|
151
|
+
try {
|
|
152
|
+
const raw = readFileSync(join(stateDir(ctx), FORM_ID_CACHE_FILE), 'utf8');
|
|
153
|
+
const parsed = JSON.parse(raw);
|
|
154
|
+
const forms = parsed?.forms;
|
|
155
|
+
if (!forms || typeof forms !== 'object')
|
|
156
|
+
return {};
|
|
157
|
+
const out = {};
|
|
158
|
+
for (const [key, value] of Object.entries(forms)) {
|
|
159
|
+
const text = String(value ?? '').trim();
|
|
160
|
+
if (text)
|
|
161
|
+
out[key] = text;
|
|
162
|
+
}
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
// 缓存缺失或损坏都按未命中处理
|
|
167
|
+
return {};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function persistFormIdCache(ctx, key, formId) {
|
|
171
|
+
try {
|
|
172
|
+
const dir = stateDir(ctx);
|
|
173
|
+
mkdirSync(dir, { recursive: true });
|
|
174
|
+
const forms = { ...readFormIdCache(ctx), [key]: formId };
|
|
175
|
+
writeWithRetry(join(dir, FORM_ID_CACHE_FILE), `${JSON.stringify({ version: 1, forms }, null, 2)}\n`, { mode: 0o600 });
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
// 落盘失败不影响正常查询
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/** 清空借阅单表单 ID 的进程内缓存(测试与切换环境时使用)。 */
|
|
182
|
+
export function clearBorrowFormIdCache() {
|
|
183
|
+
borrowFormIdCache.clear();
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* 借阅单(我的借阅)的表单 ID:走 getPageUrl 链路取 `objId`,按「环境 + 租户」缓存。
|
|
187
|
+
* 先查进程内缓存,再查 state 目录下的落盘缓存;都没有才发请求,拿到后回写两处。
|
|
188
|
+
* 解析失败返回空串,不抛出,调用方按无链接降级。
|
|
189
|
+
*/
|
|
190
|
+
export async function resolveBorrowFormId(host, session, ctx) {
|
|
191
|
+
const key = borrowFormIdCacheKey(session);
|
|
192
|
+
const cached = borrowFormIdCache.get(key);
|
|
193
|
+
if (cached)
|
|
194
|
+
return cached;
|
|
195
|
+
const persisted = readFormIdCache(ctx)[key];
|
|
196
|
+
if (persisted) {
|
|
197
|
+
borrowFormIdCache.set(key, persisted);
|
|
198
|
+
return persisted;
|
|
199
|
+
}
|
|
200
|
+
try {
|
|
201
|
+
const target = await resolveArchiveListTarget(host, { sign: BORROWING_TAG, viewMode: 'myBorrow' });
|
|
202
|
+
const formId = String(target?.objId ?? '').trim();
|
|
203
|
+
if (!formId)
|
|
204
|
+
return '';
|
|
205
|
+
borrowFormIdCache.set(key, formId);
|
|
206
|
+
persistFormIdCache(ctx, key, formId);
|
|
207
|
+
return formId;
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return '';
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto';
|
|
2
2
|
import { archiveValidationError } from '../errors.js';
|
|
3
3
|
import { READ, WRITE, archiveSuccess, schemaOf, } from './types.js';
|
|
4
|
-
import { positiveInt, toStringIdList, unwrapData } from './shared.js';
|
|
4
|
+
import { buildBrowserToolCell, buildOpenAction, positiveInt, toStringIdList, unwrapData, } from './shared.js';
|
|
5
5
|
import { issueLease, verifyLease } from './confirm.js';
|
|
6
6
|
/**
|
|
7
7
|
* 预归档电子文件库列表链路。
|
|
@@ -209,7 +209,7 @@ const prelibList = {
|
|
|
209
209
|
},
|
|
210
210
|
pageNo: { type: 'integer', minimum: 1, description: '页码,默认 1' },
|
|
211
211
|
}, { description: '查询电子文件库列表' }),
|
|
212
|
-
handler: async (args, { host }) => {
|
|
212
|
+
handler: async (args, { ctx, host }) => {
|
|
213
213
|
const node = await resolveEfileNode(host, optionalText(args.treeId));
|
|
214
214
|
const detail = await fetchTreeDetail(host, node.treeId);
|
|
215
215
|
const page = await fetchPrelibDatas(host, node, detail, args.pageNo);
|
|
@@ -221,6 +221,19 @@ const prelibList = {
|
|
|
221
221
|
const path = `${PRELIB_FILE_LIB_EDIT_PATH}?${new URLSearchParams({ singleMetaId: id, treeId: node.treeId }).toString()}`;
|
|
222
222
|
return id && root ? `${root}${path}` : '';
|
|
223
223
|
});
|
|
224
|
+
// 与 openUrls 行序对齐的带点击事件 a 标签(点击时在控制台打印诊断日志)
|
|
225
|
+
const firstColumn = String(page.visibleColumns[0]?.dataIndex ?? '');
|
|
226
|
+
const rowNames = openUrls.map((url, index) => {
|
|
227
|
+
if (!url)
|
|
228
|
+
return '';
|
|
229
|
+
return String(page.displayData[index]?.[firstColumn] ?? page.rows[index]?.[firstColumn] ?? '打开档案');
|
|
230
|
+
});
|
|
231
|
+
// 列表场景只下发环境标记:第一列正常渲染 a 标签,打开动作由宿主按 clientAction 执行
|
|
232
|
+
const openEnv = buildOpenAction(ctx, openUrls[0] ?? '', '打开档案');
|
|
233
|
+
// 小E 环境:表格增加“操作”列,档案所在行该列单独一个单元格放单行 <browsertool>;非小E 不返回该字段
|
|
234
|
+
const browserToolCells = openEnv.hasXiaoEEnv
|
|
235
|
+
? openUrls.map((url, index) => (url ? buildBrowserToolCell(url, rowNames[index]) : ''))
|
|
236
|
+
: undefined;
|
|
224
237
|
return archiveSuccess('archive.prelib.list', {
|
|
225
238
|
treeId: node.treeId,
|
|
226
239
|
nodeName: node.nodeName,
|
|
@@ -231,6 +244,9 @@ const prelibList = {
|
|
|
231
244
|
...(detail.boxUrl ? { boxUrl: detail.boxUrl } : {}),
|
|
232
245
|
...page,
|
|
233
246
|
openUrls,
|
|
247
|
+
hasXiaoEEnv: openEnv.hasXiaoEEnv,
|
|
248
|
+
...(browserToolCells ? { browserToolCells } : {}),
|
|
249
|
+
requiresHostAction: openEnv.requiresHostAction,
|
|
234
250
|
}, { count: page.rows.length, nodeName: node.nodeName });
|
|
235
251
|
},
|
|
236
252
|
};
|
|
@@ -451,14 +467,27 @@ const prelibOpen = {
|
|
|
451
467
|
url: root ? `${root}${path}` : path,
|
|
452
468
|
};
|
|
453
469
|
});
|
|
470
|
+
const open = links.length === 1 ? buildOpenAction(env.ctx, String(links[0].url), '打开档案') : null;
|
|
454
471
|
return archiveSuccess('archive.prelib.open', {
|
|
455
472
|
nodeName: node.nodeName,
|
|
456
473
|
systemId,
|
|
457
474
|
metadataId,
|
|
458
475
|
count: links.length,
|
|
459
476
|
links,
|
|
460
|
-
...(
|
|
461
|
-
|
|
477
|
+
...(open
|
|
478
|
+
? {
|
|
479
|
+
url: open.url,
|
|
480
|
+
markdown: open.markdown,
|
|
481
|
+
hasXiaoEEnv: open.hasXiaoEEnv,
|
|
482
|
+
...(open.browserTool ? { browserTool: open.browserTool } : {}),
|
|
483
|
+
requiresHostAction: open.requiresHostAction,
|
|
484
|
+
opened: open.opened,
|
|
485
|
+
clientAction: open.clientAction,
|
|
486
|
+
}
|
|
487
|
+
: {}),
|
|
488
|
+
hint: open?.hasXiaoEEnv
|
|
489
|
+
? '始终把 markdown 的 Markdown 超链接(a 标签)返回,保证可点击(需已登录该环境且有该档案查看权限);browserTool 是 <browsertool> 的参数,序列化成单行标签后放在这条数据之后单独一行渲染,小E 客户端据此在右侧内置浏览器打开;opened 恒为 false'
|
|
490
|
+
: '始终把 markdown 的 Markdown 超链接(a 标签)返回,保证可点击(需已登录该环境且有该档案查看权限);打开动作按 clientAction(type: openUrl)由宿主执行,走系统默认浏览器;CLI 不自动打开浏览器',
|
|
462
491
|
});
|
|
463
492
|
},
|
|
464
493
|
};
|
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
import { archiveValidationError } from '../errors.js';
|
|
2
|
+
import { hasXiaoEEnv } from '../../../internal/e10/auth/xiaoe.js';
|
|
2
3
|
/** 原型污染防护:禁止出现在输入对象中的键。 */
|
|
3
4
|
const FORBIDDEN_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
5
|
+
/**
|
|
6
|
+
* 链接打开方式:
|
|
7
|
+
* - 任何环境都给 `markdown`(渲染即标准 a 标签),保证链接可点;
|
|
8
|
+
* - **小E 环境(`hasXiaoEEnv=true`)**额外给 `browserTool` 参数(`toolId: open_web`),
|
|
9
|
+
* 由调用方把该参数序列化成单行 `<browsertool>…</browsertool>`,放在该条数据内容之后单独一行渲染;
|
|
10
|
+
* - 非小E 只给 a 标签,点击走系统默认浏览器;
|
|
11
|
+
* - 任何环境都带 `clientAction: { type: 'openUrl', url }` + `requiresHostAction`;
|
|
12
|
+
* CLI 自己**不**拉起浏览器,所以 `opened` 恒为 false。
|
|
13
|
+
*/
|
|
14
|
+
export function buildOpenAction(ctx, url, title = '打开链接') {
|
|
15
|
+
const base = {
|
|
16
|
+
url,
|
|
17
|
+
markdown: `[${title}](${url})`,
|
|
18
|
+
requiresHostAction: true,
|
|
19
|
+
opened: false,
|
|
20
|
+
clientAction: { type: 'openUrl', url },
|
|
21
|
+
};
|
|
22
|
+
if (!isXiaoECtx(ctx))
|
|
23
|
+
return { ...base, hasXiaoEEnv: false };
|
|
24
|
+
return {
|
|
25
|
+
...base,
|
|
26
|
+
hasXiaoEEnv: true,
|
|
27
|
+
browserTool: buildBrowserToolPayload(url, title),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** 当前上下文是否小E 环境(`hasXiaoEEnv` 的唯一入口;测试或轻量调用可能没有完整 ctx)。 */
|
|
31
|
+
export function isXiaoECtx(ctx) {
|
|
32
|
+
const options = typeof ctx?.getGlobalOptions === 'function' ? ctx.getGlobalOptions() : undefined;
|
|
33
|
+
return hasXiaoEEnv(ctx?.env ?? process.env, options);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 小E 的打开载荷(`toolId: open_web`):`callId` 固定为 `archive_open`,只随 `url` / `title` 变。
|
|
37
|
+
* 不指定 `width`,由客户端使用默认宽度。
|
|
38
|
+
*/
|
|
39
|
+
function buildBrowserToolPayload(url, title) {
|
|
40
|
+
return {
|
|
41
|
+
version: '1.0',
|
|
42
|
+
callId: 'archive_open',
|
|
43
|
+
toolId: 'open_web',
|
|
44
|
+
// activate: false / autoOpen: false —— 不自动激活、不自动弹出,由用户在客户端里自行点击打开
|
|
45
|
+
arguments: { url, title, activate: false, autoOpen: false },
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 表格最后一列“操作”的单元格:**单行** `<browsertool>`(`open_web`)。
|
|
50
|
+
* 列表/明细的题名列仍用标准 a 标签;小E 环境在表格最后增加一列“操作”,该列单独一个 `<td>` 单元格、
|
|
51
|
+
* 与档案数据处在同一行,单元格直接放本函数的返回值,宿主识别标签后在该行对应地址上内置打开。
|
|
52
|
+
*/
|
|
53
|
+
export function buildBrowserToolCell(url, title = '打开档案') {
|
|
54
|
+
return `<browsertool>${JSON.stringify(buildBrowserToolPayload(url, title))}</browsertool>`;
|
|
55
|
+
}
|
|
4
56
|
export function asObject(value) {
|
|
5
57
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
6
58
|
throw archiveValidationError('input_not_object', '输入必须是 JSON 对象');
|