@stalfh233/omc-cli 0.8.32 → 0.8.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arg-vocabulary.js +223 -0
- package/dist/artifact-cmd.js +443 -0
- package/dist/batch-call.js +56 -3
- package/dist/call-command.js +70 -0
- package/dist/call-execute.js +228 -0
- package/dist/call-input.js +557 -0
- package/dist/call-output.js +240 -0
- package/dist/cli.js +13 -1359
- package/dist/command-transport.js +4 -1
- package/dist/form-support.js +14 -3
- package/dist/intent/plan-apply.js +14 -24
- package/dist/lanes/datarule.js +21 -0
- package/dist/lanes/field.js +31 -0
- package/dist/lanes/list-view-shapes.js +8 -1
- package/dist/lanes/list-view.js +64 -2
- package/dist/lanes/runtime-data/aggregate-support.js +209 -0
- package/dist/lanes/runtime-data/aggregate.js +679 -0
- package/dist/lanes/runtime-data/field-options.js +52 -0
- package/dist/lanes/runtime-data/lane.js +4 -0
- package/dist/lanes/runtime-data/record-delete.js +419 -0
- package/dist/lanes/runtime-data/record-read.js +984 -0
- package/dist/lanes/runtime-data/record-write.js +562 -0
- package/dist/lanes/runtime-data/registration.js +22 -0
- package/dist/lanes/runtime-data/shapes.js +594 -0
- package/dist/lanes/runtime-data/submission.js +1293 -0
- package/dist/lanes/runtime-data/write-support.js +875 -0
- package/dist/lanes/runtime-data.js +10 -5590
- package/dist/lanes/workflow/approval-ops.js +983 -0
- package/dist/lanes/workflow/instance-read.js +284 -0
- package/dist/lanes/workflow/lifecycle-write.js +1499 -0
- package/dist/lanes/workflow/permissions.js +571 -0
- package/dist/lanes/workflow/recovery.js +361 -0
- package/dist/lanes/workflow/registration.js +14 -0
- package/dist/lanes/workflow/shapes.js +811 -0
- package/dist/lanes/workflow/template-fetch.js +197 -0
- package/dist/lanes/workflow/template-merge.js +1351 -0
- package/dist/lanes/workflow/template-read.js +327 -0
- package/dist/lanes/workflow.js +11 -6312
- package/dist/read-projection.js +442 -0
- package/dist/read.js +40 -335
- package/dist/rollback.js +17 -23
- package/dist/runtime-support.js +1 -1
- package/dist/verification.js +39 -0
- package/dist/write-coordinator.js +152 -0
- package/dist/write-outcome.js +295 -0
- package/dist/write.js +34 -115
- package/package.json +3 -3
- package/skills/omc-refusals.md +1 -1
- package/skills/omc-start-here.md +2 -2
|
@@ -0,0 +1,1499 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ENDPOINTS } from "../../endpoints.js";
|
|
3
|
+
import { ToolRefusalError, isRequiredAlternativePlaceholder } from "../../tool-types.js";
|
|
4
|
+
import { writeTool } from "../../write.js";
|
|
5
|
+
import { registerPackageTool } from "../../package-tool.js";
|
|
6
|
+
import { writeSummary } from "../../human-summary.js";
|
|
7
|
+
import { wireCall, wireRows, WireError } from "../../wire.js";
|
|
8
|
+
import { readSchemaFormButtons } from "../../form-support.js";
|
|
9
|
+
import { workflowTemplateArg } from "../workflow-contract.js";
|
|
10
|
+
import { decodeActionRow } from "../list-view-shapes.js";
|
|
11
|
+
import { PLATFORM_TRIGGER_RULE_CODES } from "../rule-graph.js";
|
|
12
|
+
import { executeRuleEnableWrite } from "../rule-lifecycle.js";
|
|
13
|
+
import { flattenTreeRows, resolveApplicationScope } from "../../support.js";
|
|
14
|
+
import { WORKFLOW_LANE, WORKFLOW_TOOLS, WORKFLOW_LIST_MODEL_CAP, resolveBindTarget, findTemplateActivity, mapTemplateActivity, templateActivityCodes, inheritedBranchEdges, effectiveActivityName, bindTargetHandlerOf } from "./shapes.js";
|
|
15
|
+
import { workflowValidationWarnings, assertWorkflowWriteAccepted, unregisteredParticipantFunctions, rejectToStartCancelWarnings, participantReferenceWarnings, approvalByOriginatorWarnings } from "./recovery.js";
|
|
16
|
+
import { assertFirstActivityIsOriginator, validateWorkflowRouteConditions, countStrippedEmptyConditionGroups, assertTemplateNotMinimal, lintWorkflowTemplate, validateCallerActivities, assertRoleParticipantScopes, workflowRenderCompat, validateWorkflowRender, activitiesLackBoundaries, backfillDesignerDefaults, renamedActivityPairs, inPlaceRenames, refuseRequiredOnChildTableFields, mergedTemplateBody } from "./template-merge.js";
|
|
17
|
+
import { resolveWorkflowName, workflowRollbackSpec, countPendingWorkItems, isWorkflowAbsent, getWorkflowHeaderOrNull, getWorkflowDraftOrNull } from "./template-fetch.js";
|
|
18
|
+
export function registerLifecycleTools(tools) {
|
|
19
|
+
/**
|
|
20
|
+
* A workflow event handler (start/cancel/activate/end) binds a business rule by
|
|
21
|
+
* CODE. The platform's designer rule picker only offers CUSTOM rules — the
|
|
22
|
+
* preset trigger rows (Create/Update/Delete/Load/GetList/Available/Cancel, all
|
|
23
|
+
* `defaultRule:true`) are NOT selectable there, because they already run on the
|
|
24
|
+
* data event itself. Binding one (2026-09-28: bench59 bound `Create` to `end`)
|
|
25
|
+
* produces a handler the designer cannot represent. Refuse before any write.
|
|
26
|
+
*/
|
|
27
|
+
async function assertBindableWorkflowRules(session, schemaCode, codes) {
|
|
28
|
+
const presets = codes.filter((code) => PLATFORM_TRIGGER_RULE_CODES.has(code));
|
|
29
|
+
if (presets.length > 0)
|
|
30
|
+
throw new ToolRefusalError({
|
|
31
|
+
status: "refused",
|
|
32
|
+
blocker: "workflow-bind-preset-rule",
|
|
33
|
+
ruleCodes: presets,
|
|
34
|
+
message: `流程事件只能绑定【自定义】业务规则,不能绑定平台预置触发规则(${presets.join("、")})——预置规则已在数据事件上运行,设计器的流程事件规则选择器不提供它们。要「审批通过后执行某逻辑」,请新建一条自定义规则(自定义 ruleCode),把动作节点写进它,再 bindRule 到对应 handler;或在预置 Create/Update 规则里直接追加节点。`,
|
|
35
|
+
});
|
|
36
|
+
// Cross-check the authoritative `defaultRule` flag (covers preset codes not in
|
|
37
|
+
// the local set, and a schema that renamed one).
|
|
38
|
+
let rows;
|
|
39
|
+
try {
|
|
40
|
+
const list = await wireCall(session, { path: ENDPOINTS.businessRuleListBySchemaCode, query: { schemaCode } });
|
|
41
|
+
rows = wireRows(list.data);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return new Map(); // a read failure must not block an otherwise-valid bind
|
|
45
|
+
}
|
|
46
|
+
const byCode = new Map(rows.map((row) => [String(row.code ?? ""), row]));
|
|
47
|
+
const defaults = codes.filter((code) => byCode.get(code)?.defaultRule === true && !PLATFORM_TRIGGER_RULE_CODES.has(code));
|
|
48
|
+
if (defaults.length > 0)
|
|
49
|
+
throw new ToolRefusalError({
|
|
50
|
+
status: "refused",
|
|
51
|
+
blocker: "workflow-bind-preset-rule",
|
|
52
|
+
ruleCodes: defaults,
|
|
53
|
+
message: `流程事件只能绑定自定义业务规则;${defaults.join("、")} 是平台预置默认规则(defaultRule:true),设计器不可选。改用自定义规则。`,
|
|
54
|
+
});
|
|
55
|
+
return byCode;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A rule bound to a workflow event handler is INERT while disabled — the
|
|
59
|
+
* designer shows it 失效/未启用 and the event handler will not run it. Binding a
|
|
60
|
+
* workflow rule therefore GUARANTEES the bound custom rule is enabled: a
|
|
61
|
+
* disabled/never-published rule (the state `rule.save` leaves) is published +
|
|
62
|
+
* enabled here via the same `rule.enable` chain. Live 2026-10-08 (SCM sandbox):
|
|
63
|
+
* rules created with `rule.save` (DRAFT/DISABLED) and bound with
|
|
64
|
+
* `workflow.bindRule` read back 「失效·未启用」 in the workflow designer — a
|
|
65
|
+
* workflow-bound rule MUST be enabled.
|
|
66
|
+
*/
|
|
67
|
+
async function ensureWorkflowRulesEnabled(session, schemaCode, codes, byCode) {
|
|
68
|
+
const enabledRuleCodes = [];
|
|
69
|
+
const alreadyEnabledRuleCodes = [];
|
|
70
|
+
if (byCode.size === 0)
|
|
71
|
+
return { enabledRuleCodes, alreadyEnabledRuleCodes }; // list read failed → cannot judge
|
|
72
|
+
for (const code of codes) {
|
|
73
|
+
const row = byCode.get(code);
|
|
74
|
+
if (!row)
|
|
75
|
+
throw new ToolRefusalError({
|
|
76
|
+
status: "refused",
|
|
77
|
+
blocker: "workflow-bind-rule-absent",
|
|
78
|
+
schemaCode,
|
|
79
|
+
ruleCodes: [code],
|
|
80
|
+
message: `流程事件要绑定的规则 "${code}" 不存在(${schemaCode} 的 list_by_schemacode 无此 code)——流程事件只能绑已存在的【自定义】规则。先用 rule.save 建该规则(CUSTOM_NODE + 动作节点),再 bindRule。`,
|
|
81
|
+
});
|
|
82
|
+
if (row.enabled === true) {
|
|
83
|
+
alreadyEnabledRuleCodes.push(code);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
// Disabled/DRAFT: publish + enable so the event handler actually runs it.
|
|
87
|
+
await executeRuleEnableWrite(session, { schemaCode, ruleCode: code });
|
|
88
|
+
enabledRuleCodes.push(code);
|
|
89
|
+
}
|
|
90
|
+
return { enabledRuleCodes, alreadyEnabledRuleCodes };
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* unbindRule 的读回+校验上下文——execute 与 dryRunPayload **共用这一个函数**
|
|
94
|
+
* (同 rule.node.update 的 loadRuleNodePatchGraph 模式),保证 dry-run 与真写
|
|
95
|
+
* 对「不存在流程 / 不存在活动 / absent code」给出完全相同的 refusal:此前
|
|
96
|
+
* dry-run 走 write.ts 的泛型 plan 信封,打错 ruleCode 也回 wouldChange:true,
|
|
97
|
+
* 真写才拒 absent。本函数只读草稿 + 本地校验(含模板渲染检查),零写入。
|
|
98
|
+
*/
|
|
99
|
+
async function unbindRuleContext(session, args) {
|
|
100
|
+
const target = resolveBindTarget(args.handler, args.nodeEvent, args.activityCode);
|
|
101
|
+
const codes = (args.ruleCodes ?? [args.ruleCode]).map(String);
|
|
102
|
+
const shouldPublish = args.publish !== false;
|
|
103
|
+
const draft = (await getWorkflowDraftOrNull(session, args.workflowCode)) ?? {};
|
|
104
|
+
if (Object.keys(draft).length === 0) {
|
|
105
|
+
throw new ToolRefusalError({
|
|
106
|
+
status: "refused",
|
|
107
|
+
blocker: "workflow-not-found",
|
|
108
|
+
workflowCode: args.workflowCode,
|
|
109
|
+
message: `流程 ${args.workflowCode} 不存在(get_draft 401001 缺席)——先 workflow.create,再 unbindRule`,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (target.scope === "activity" && !findTemplateActivity(draft, target.activityCode)) {
|
|
113
|
+
throw new ToolRefusalError({
|
|
114
|
+
status: "refused",
|
|
115
|
+
blocker: "workflow-activity-not-found",
|
|
116
|
+
workflowCode: args.workflowCode,
|
|
117
|
+
activityCode: target.activityCode,
|
|
118
|
+
activities: templateActivityCodes(draft),
|
|
119
|
+
message: `流程 ${args.workflowCode} 的草稿里没有活动 ${target.activityCode}——节点级事件必须指向已存在的活动。可用活动:${templateActivityCodes(draft).join("、") || "(无)"}(先用 workflow.get_draft 看 code,别用节点名)`,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
const existing = bindTargetHandlerOf(draft, target);
|
|
123
|
+
const priorActions = Array.isArray(existing.bizActions)
|
|
124
|
+
? existing.bizActions.filter((value) => typeof value === "string")
|
|
125
|
+
: [];
|
|
126
|
+
// Fail closed BEFORE any wire call when the caller names codes the handler
|
|
127
|
+
// does not carry — a typo'd ruleCode must not report a phantom success,
|
|
128
|
+
// and the existing codes are the fix's raw material.
|
|
129
|
+
const absent = codes.filter((code) => !priorActions.includes(code));
|
|
130
|
+
if (absent.length > 0) {
|
|
131
|
+
throw new ToolRefusalError({
|
|
132
|
+
status: "refused",
|
|
133
|
+
blocker: "workflow-unbind-rule-absent",
|
|
134
|
+
workflowCode: args.workflowCode,
|
|
135
|
+
absentRuleCodes: absent,
|
|
136
|
+
bizActions: priorActions,
|
|
137
|
+
...(target.scope === "activity" ? { activityCode: target.activityCode, nodeEvent: target.key } : { handler: target.key }),
|
|
138
|
+
message: `该处理器当前没有绑定 ${absent.join("、")}——现有绑定:${priorActions.join("、") || "(无)"}。解绑只对已绑定的 code 生效;要换目标先看 workflow.get_draft 的 ruleBindings/nodeRuleBindings`,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
const nextActions = priorActions.filter((code) => !codes.includes(code));
|
|
142
|
+
// 移空后的写回形状按平台 canonical 未绑态:handler 对象保留、bizActions 与
|
|
143
|
+
// bizActionType 置 null(WorkflowTemplateController 的模板示例即此形状;平台
|
|
144
|
+
// 判空走 CollectionUtils.isEmpty,null 与 [] 等价,null 是平台自己的存量拼写)。
|
|
145
|
+
const mergedHandler = nextActions.length > 0
|
|
146
|
+
? { ...(typeof existing === "object" && existing ? existing : {}), bizActions: nextActions, bizActionType: "BIZ_RULE" }
|
|
147
|
+
: { ...(typeof existing === "object" && existing ? existing : {}), bizActions: null, bizActionType: null };
|
|
148
|
+
let nextTemplate;
|
|
149
|
+
if (target.scope === "workflow") {
|
|
150
|
+
nextTemplate = { ...draft, [target.field]: mergedHandler, workflowCode: args.workflowCode, schemaCode: args.schemaCode };
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
// Keep the draft's activities container shape (array or index-keyed
|
|
154
|
+
// object) — only the selected row's handler field changes.
|
|
155
|
+
nextTemplate = mapTemplateActivity(draft, target.activityCode, (row) => ({ ...row, [target.field]: mergedHandler })).template;
|
|
156
|
+
nextTemplate = { ...nextTemplate, workflowCode: args.workflowCode, schemaCode: args.schemaCode };
|
|
157
|
+
}
|
|
158
|
+
validateWorkflowRender(nextTemplate, "workflow.unbindRule");
|
|
159
|
+
return { target, codes, shouldPublish, nextTemplate, priorActions, nextActions };
|
|
160
|
+
}
|
|
161
|
+
// Sibling registry for the high-level `configure_workflow` (reuses each atomic
|
|
162
|
+
// tool's own writeExecute so every gate + readback is identical).
|
|
163
|
+
const siblings = tools;
|
|
164
|
+
writeTool({
|
|
165
|
+
tools,
|
|
166
|
+
name: "workflow.create",
|
|
167
|
+
search: { intents: ["新建流程", "建流程", "建审批流", "新建审批流", "配审批流", "配置审批流", "审批流模板", "流程模板"] },
|
|
168
|
+
lane: WORKFLOW_LANE,
|
|
169
|
+
scope: WORKFLOW_TOOLS["workflow.create"].scope,
|
|
170
|
+
description: WORKFLOW_TOOLS["workflow.create"].description,
|
|
171
|
+
inputSchema: {
|
|
172
|
+
schemaCode: z.string().min(1),
|
|
173
|
+
// 2026-10-27 用户需求:流程名默认与表单名一致。省略时的解析链见
|
|
174
|
+
// resolveWorkflowName——表单名 → 模型名 → 拒绝(不拿 schemaCode 冒充)。
|
|
175
|
+
name: z.string().min(1).optional().describe("流程名称;省略时默认 = 该模型默认表单的名字(无表单草稿时用模型名),与设计器行为一致"),
|
|
176
|
+
code: z.string().min(1),
|
|
177
|
+
},
|
|
178
|
+
execute: async (session, args) => {
|
|
179
|
+
// Ticket 76 idempotent retry: get_header FIRST — a post-timeout
|
|
180
|
+
// re-create of the same code short-circuits with the existing header
|
|
181
|
+
// and ZERO create wires. On the happy path this read REPLACES the
|
|
182
|
+
// post-create header read (same wire count), because a successful
|
|
183
|
+
// create implies the header.
|
|
184
|
+
const existingHeader = await getWorkflowHeaderOrNull(session, args.code);
|
|
185
|
+
if (existingHeader != null) {
|
|
186
|
+
return { performed: { skipped: "already-present" }, readback: { alreadyPresent: true, header: existingHeader } };
|
|
187
|
+
}
|
|
188
|
+
const { name: workflowName, resolvedFrom } = await resolveWorkflowName(session, args.name, args.schemaCode);
|
|
189
|
+
let performed;
|
|
190
|
+
try {
|
|
191
|
+
performed = await wireCall(session, {
|
|
192
|
+
path: ENDPOINTS.workflowCreate,
|
|
193
|
+
method: "POST",
|
|
194
|
+
body: { workflowCode: args.code, workflowName, schemaCode: args.schemaCode, icon: "h-icon-all-logic" },
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
// Ticket 76 live: the platform answers an envelope with NO numeric
|
|
199
|
+
// errcode when the SCHEMA already has a workflow (a second, differently
|
|
200
|
+
// coded one is refused). Decode it as a duplicate-create — same-code
|
|
201
|
+
// presence was already excluded by the pre-check, so this is the
|
|
202
|
+
// different-code case — instead of surfacing a malformed-envelope
|
|
203
|
+
// transport-looking failure on a business duplicate.
|
|
204
|
+
if (error instanceof WireError && error.kind === "malformed-envelope") {
|
|
205
|
+
const has = await wireCall(session, { path: ENDPOINTS.workflowIsWorkflow, query: { schemaCode: args.schemaCode } });
|
|
206
|
+
if (has.data === true) {
|
|
207
|
+
throw new ToolRefusalError({
|
|
208
|
+
status: "refused",
|
|
209
|
+
blocker: "workflow-already-exists",
|
|
210
|
+
schemaCode: args.schemaCode,
|
|
211
|
+
workflowCode: args.code,
|
|
212
|
+
message: `模型 ${args.schemaCode} 已有流程(平台对重复创建返回非数字 errcode 的 envelope)——一个模型只能有一个流程。要改现有流程用 workflow.update/workflow.publish(先 workflow.get_draft 取当前模板),不要另建新 code`,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
throw error;
|
|
217
|
+
}
|
|
218
|
+
const draft = await getWorkflowDraftOrNull(session, args.code);
|
|
219
|
+
return {
|
|
220
|
+
performed: { errcode: performed.errcode },
|
|
221
|
+
readback: { workflowCode: args.code, name: workflowName, nameResolvedFrom: resolvedFrom, headerPresent: true, draftPresent: draft != null, templateId: draft?.id ?? null },
|
|
222
|
+
};
|
|
223
|
+
},
|
|
224
|
+
rollback: workflowRollbackSpec("workflow.create"),
|
|
225
|
+
});
|
|
226
|
+
writeTool({
|
|
227
|
+
tools,
|
|
228
|
+
name: "workflow.update",
|
|
229
|
+
search: { intents: ["更新流程", "修改流程", "改流程", "加审批节点", "退回给", "退回到", "签一下", "自己批"] },
|
|
230
|
+
lane: WORKFLOW_LANE,
|
|
231
|
+
scope: WORKFLOW_TOOLS["workflow.update"].scope,
|
|
232
|
+
description: WORKFLOW_TOOLS["workflow.update"].description,
|
|
233
|
+
inputSchema: { schemaCode: z.string().min(1), code: z.string().min(1).describe("流程编码——本参数名是 code,传 workflowCode 会被 schema 拒绝"), template: workflowTemplateArg.describe(`${workflowTemplateArg.description ?? ""}**省 type 的边界**:既有节点编辑行只给 activityCode 即可(participant / propertyPermissions / btnConfigList / 改名),工具按草稿同 code 节点的现有 type 补齐后上送——因为平台对收到的每个 activities 元素都跑 ActivityType.valueOf,缺类型会被吞成残缺模型(50000);activityCode 不在草稿(新节点)仍必须显式给 type,同 code 多候选直接拒并给候选清单。`), merge: z.boolean().optional().describe("增量 merge:只发改动/新增节点与路由,按 activityCode 并入草稿;模板缺 START/END 自动增量、给全 START..END 才整模板替换。并集绝不删边,少边拒 workflow-merge-would-drop-routes;--dry-run 回 routesBefore/routesAfter/routesAdded/routesDropped") },
|
|
234
|
+
execute: async (session, args) => {
|
|
235
|
+
const template = args.template ?? {};
|
|
236
|
+
validateCallerActivities(template, "workflow.update");
|
|
237
|
+
validateWorkflowRouteConditions(template, "workflow.update");
|
|
238
|
+
// r85(issue 02):平台存量的空条件组写法在 validator 放行、merge 写前剥键;
|
|
239
|
+
// 回执带计数让调用方看见剥离发生了。
|
|
240
|
+
const strippedEmptyConditionGroups = countStrippedEmptyConditionGroups(template);
|
|
241
|
+
assertTemplateNotMinimal(template, "workflow.update");
|
|
242
|
+
lintWorkflowTemplate(template, "workflow.update");
|
|
243
|
+
await refuseRequiredOnChildTableFields(session, args.schemaCode, template, "workflow.update");
|
|
244
|
+
// Ticket 112: merge onto the full draft row — a verbatim minimal post
|
|
245
|
+
// leaves converter holes and answers errcode 50000 on the platform.
|
|
246
|
+
// Delta semantics: explicit `true` forces merge, explicit `false` forces
|
|
247
|
+
// replace, and the default auto-detects a partial template (missing
|
|
248
|
+
// START/END) as a delta — see activitiesLackBoundaries.
|
|
249
|
+
const merge = args.merge === true || (args.merge !== false && activitiesLackBoundaries(template));
|
|
250
|
+
const body = await mergedTemplateBody(session, args.schemaCode, args.code, template, merge);
|
|
251
|
+
await backfillDesignerDefaults(session, args.schemaCode, body, template);
|
|
252
|
+
assertFirstActivityIsOriginator(template, "workflow.update", body);
|
|
253
|
+
validateWorkflowRender(body, "workflow.update");
|
|
254
|
+
await assertRoleParticipantScopes(session, body);
|
|
255
|
+
// Live: workflow/update does NOT run the template validator — it stores a
|
|
256
|
+
// refused participant silently and only /publish answers the
|
|
257
|
+
// ValidateMessage[]. So the guard belongs on publish/bindRule, not here.
|
|
258
|
+
const performed = await wireCall(session, { path: ENDPOINTS.workflowUpdate, method: "POST", body });
|
|
259
|
+
const draft = await wireCall(session, { path: ENDPOINTS.workflowGetDraft, query: { workflowCode: args.code } });
|
|
260
|
+
const data = (draft.data ?? null);
|
|
261
|
+
if (!data)
|
|
262
|
+
throw new ToolRefusalError({ status: "refused", blocker: "workflow-render-readback-invalid", message: "workflow.update returned no draft" });
|
|
263
|
+
validateWorkflowRender(data, "workflow.update readback");
|
|
264
|
+
const participantWarnings = participantReferenceWarnings(data);
|
|
265
|
+
// Evaluate on `body` (post-backfill): the readback may drop the handler
|
|
266
|
+
// keys, and the backfilled permittedAction is exactly what will run.
|
|
267
|
+
const rejectWarnings = rejectToStartCancelWarnings(body);
|
|
268
|
+
const originatorWarnings = approvalByOriginatorWarnings(body);
|
|
269
|
+
const renamedActivities = renamedActivityPairs(template, data);
|
|
270
|
+
const renamedInPlace = inPlaceRenames(data);
|
|
271
|
+
// Caller sent no routes at all: the draft's edges (branches included) are
|
|
272
|
+
// what rides the wire. Say so, and name the branch edges, because the only
|
|
273
|
+
// other trace is a missing edge in a later getPublished readback.
|
|
274
|
+
const callerSentRoutes = template.routes !== undefined || template.edges !== undefined || template.rules !== undefined;
|
|
275
|
+
const branchEdges = callerSentRoutes ? [] : inheritedBranchEdges(data);
|
|
276
|
+
// 改名验收的权威读数:每个节点的当前显示名(platform may keep
|
|
277
|
+
// activityName or sync it; effectiveActivityName resolves both shapes).
|
|
278
|
+
const rawActivityRows = Array.isArray(data.activities)
|
|
279
|
+
? data.activities
|
|
280
|
+
: data.activities && typeof data.activities === "object"
|
|
281
|
+
? Object.values(data.activities)
|
|
282
|
+
: [];
|
|
283
|
+
const activityNames = Object.fromEntries(rawActivityRows
|
|
284
|
+
.map((row) => [String(row.activityCode ?? ""), effectiveActivityName(row)])
|
|
285
|
+
.filter(([code]) => code !== ""));
|
|
286
|
+
return { performed: { errcode: performed.errcode }, readback: { workflowCode: args.code, activities: Array.isArray(data.activities) ? data.activities.length : rawActivityRows.length, templateType: data.templateType ?? null, ...(strippedEmptyConditionGroups > 0 ? { strippedEmptyConditionGroups, strippedEmptyConditionGroupsNote: "调用方连线里有 N 条带平台存量写法 ruleConditionGroup:[](=无条件);工具写前已剥离该键,未上送" } : {}), activityNames, rollbackHint: `本次改动的 before 快照已记录:omc rollback plan --target workflow:${args.schemaCode}/${args.code} 查看可回退项,omc rollback apply --target … --step <n> 执行(草稿回退后仍需 workflow.publish 才生效)`, ...(participantWarnings.length ? { participantWarnings } : {}), ...(rejectWarnings.length || originatorWarnings.length ? { workflowWarnings: [...rejectWarnings, ...originatorWarnings] } : {}), ...(branchEdges.length ? { routesInherited: { edges: branchEdges, hint: "本次未传 routes/edges:以上分支边沿用草稿(含 else 兜底)。要改连线请显式回传完整 routes" } } : {}), ...(renamedInPlace.length ? { renamedInPlace, renamedInPlaceHint: "改名已同 code 原地生效(载体 name_i18n,displayName 才是当前名;activityName 是首建值,平台不再变更)" } : {}), ...(renamedActivities.length ? { renamedActivities, renamedHint: "类型变更铸了新码(上表 from→to)且旧码已失效——后续读写一律用 to;再用旧码 from 会被当作新节点追加" } : {}), workflowRenderCompat: workflowRenderCompat(data) } };
|
|
287
|
+
},
|
|
288
|
+
preflight: (args) => {
|
|
289
|
+
// Zero-wire refusal (ticket 77): fires in semanticGate BEFORE the
|
|
290
|
+
// governed pipeline — including the rollback before-capture read.
|
|
291
|
+
assertTemplateNotMinimal(args.template ?? {}, "workflow.update");
|
|
292
|
+
},
|
|
293
|
+
dryRunPayload: // Dry-run must actually look at the merge result: shape-only previews said
|
|
294
|
+
// "wouldChange" while the write silently dropped 15 of 46 edges (issue
|
|
295
|
+
// 2026-10-22 §1.2). The payload runs the SAME merge as the write (reads
|
|
296
|
+
// only) and reports the edge delta; the contraction refusal fires here too.
|
|
297
|
+
async (session, args) => {
|
|
298
|
+
const template = args.template ?? {};
|
|
299
|
+
// R75-B(2026-11-18):dry-run 逐个补上真写的本地门——此前只跑 merge +
|
|
300
|
+
// render + 条件枚举,validateCallerActivities / lintWorkflowTemplate /
|
|
301
|
+
// 子表必填 / 首活动发起人 / 参与人 scope 都只在 execute(investigate-B E8:
|
|
302
|
+
// 首活动非 Originator 的 dry-run 与真写给出不同 blocker)。
|
|
303
|
+
validateCallerActivities(template, "workflow.update");
|
|
304
|
+
validateWorkflowRouteConditions(template, "workflow.update");
|
|
305
|
+
lintWorkflowTemplate(template, "workflow.update");
|
|
306
|
+
await refuseRequiredOnChildTableFields(session, args.schemaCode, template, "workflow.update");
|
|
307
|
+
const strippedEmptyConditionGroups = countStrippedEmptyConditionGroups(template);
|
|
308
|
+
const merge = args.merge === true || (args.merge !== false && activitiesLackBoundaries(template));
|
|
309
|
+
const draft = await getWorkflowDraftOrNull(session, args.code);
|
|
310
|
+
if (draft === null)
|
|
311
|
+
throw new ToolRefusalError({
|
|
312
|
+
status: "refused",
|
|
313
|
+
blocker: "workflow-not-found",
|
|
314
|
+
workflowCode: args.code,
|
|
315
|
+
message: `流程 ${args.code} 不存在(get_draft 401001 缺席)——先 workflow.create 再 update/publish`,
|
|
316
|
+
});
|
|
317
|
+
const body = await mergedTemplateBody(session, args.schemaCode, args.code, template, merge);
|
|
318
|
+
await backfillDesignerDefaults(session, args.schemaCode, body, template);
|
|
319
|
+
// 与 execute 同序:首活动发起人 → render → 参与人 scope。
|
|
320
|
+
assertFirstActivityIsOriginator(template, "workflow.update", body);
|
|
321
|
+
validateWorkflowRender(body, "workflow.update");
|
|
322
|
+
await assertRoleParticipantScopes(session, body);
|
|
323
|
+
// r62a-F2(P1-6):条件枚举校验必须在 dry-run 同门跑——GE/GT= 这类直觉
|
|
324
|
+
// 缩写此前只有真写才拒,dry-run 假绿(wouldChange:true 无 issues)。
|
|
325
|
+
validateWorkflowRouteConditions(body, "workflow.update");
|
|
326
|
+
const edgeKeys = (rules) => (Array.isArray(rules) ? rules : []).map((rule) => `${String(rule.preActivityCode ?? "")}->${String(rule.postActivityCode ?? "")}`);
|
|
327
|
+
const beforeEdges = edgeKeys(draft.rules);
|
|
328
|
+
const afterEdges = edgeKeys(body.rules);
|
|
329
|
+
// Multiset difference: two conditional lines can share one node pair, so a
|
|
330
|
+
// Set would hide a real drop.
|
|
331
|
+
const remaining = [...afterEdges];
|
|
332
|
+
const routesDropped = [];
|
|
333
|
+
for (const edge of beforeEdges) {
|
|
334
|
+
const index = remaining.indexOf(edge);
|
|
335
|
+
if (index >= 0)
|
|
336
|
+
remaining.splice(index, 1);
|
|
337
|
+
else
|
|
338
|
+
routesDropped.push(edge);
|
|
339
|
+
}
|
|
340
|
+
const beforeLeft = [...beforeEdges];
|
|
341
|
+
const routesAdded = [];
|
|
342
|
+
for (const edge of afterEdges) {
|
|
343
|
+
const index = beforeLeft.indexOf(edge);
|
|
344
|
+
if (index >= 0)
|
|
345
|
+
beforeLeft.splice(index, 1);
|
|
346
|
+
else
|
|
347
|
+
routesAdded.push(edge);
|
|
348
|
+
}
|
|
349
|
+
const activityCodes = (rows) => {
|
|
350
|
+
const list = Array.isArray(rows) ? rows : rows && typeof rows === "object" ? Object.values(rows) : [];
|
|
351
|
+
return list.map((row) => String(row?.activityCode ?? "")).filter((code) => code !== "");
|
|
352
|
+
};
|
|
353
|
+
const callerSentRoutes = template.routes !== undefined || template.edges !== undefined || template.rules !== undefined;
|
|
354
|
+
return {
|
|
355
|
+
merge,
|
|
356
|
+
callerSentRoutes,
|
|
357
|
+
...(strippedEmptyConditionGroups > 0 ? { strippedEmptyConditionGroups, strippedEmptyConditionGroupsNote: "调用方连线里有 N 条带平台存量写法 ruleConditionGroup:[](=无条件);真写会在上送前剥离该键" } : {}),
|
|
358
|
+
activitiesBefore: activityCodes(draft.activities).length,
|
|
359
|
+
activitiesAfter: activityCodes(body.activities).length,
|
|
360
|
+
routesBefore: beforeEdges.length,
|
|
361
|
+
routesAfter: afterEdges.length,
|
|
362
|
+
routesAdded,
|
|
363
|
+
routesDropped,
|
|
364
|
+
hint: callerSentRoutes
|
|
365
|
+
? "本次显式给了连线:merge 是并集(草稿边 + 你的边),不会删边"
|
|
366
|
+
: "本次未给 routes/edges/rules:草稿连线原样沿用(新增节点才会自动接链)",
|
|
367
|
+
};
|
|
368
|
+
},
|
|
369
|
+
lintScope: "full",
|
|
370
|
+
lintUnchecked: ["platform-side-validation", "post-write-readback"],
|
|
371
|
+
rollback: workflowRollbackSpec("workflow.update"),
|
|
372
|
+
});
|
|
373
|
+
writeTool({
|
|
374
|
+
tools,
|
|
375
|
+
name: "workflow.publish",
|
|
376
|
+
search: { intents: ["发布流程"] },
|
|
377
|
+
lane: WORKFLOW_LANE,
|
|
378
|
+
scope: WORKFLOW_TOOLS["workflow.publish"].scope,
|
|
379
|
+
description: WORKFLOW_TOOLS["workflow.publish"].description,
|
|
380
|
+
inputSchema: { schemaCode: z.string().min(1), code: z.string().min(1).describe("流程编码——本参数名是 code,传 workflowCode 会被 schema 拒绝"), template: workflowTemplateArg.describe("可省略——省略即把已存草稿原样发布(平台原生路径,先 workflow.update 写草稿)。要带模板时形状/连线/参与人/体积铁律与 workflow.update 的 template 完全同源,见 `omc describe workflow.update --param template`(此处不复制第二份,防漂移)").optional() },
|
|
381
|
+
execute: async (session, args) => {
|
|
382
|
+
// An absent template publishes the stored draft as-is — the platform's own
|
|
383
|
+
// path. The schema is optional so the contract no longer contradicts it.
|
|
384
|
+
const template = args.template ?? {};
|
|
385
|
+
validateCallerActivities(template, "workflow.publish");
|
|
386
|
+
validateWorkflowRouteConditions(template, "workflow.publish");
|
|
387
|
+
const strippedEmptyConditionGroups = countStrippedEmptyConditionGroups(template);
|
|
388
|
+
assertTemplateNotMinimal(template, "workflow.publish");
|
|
389
|
+
await refuseRequiredOnChildTableFields(session, args.schemaCode, template, "workflow.publish");
|
|
390
|
+
lintWorkflowTemplate(template, "workflow.publish");
|
|
391
|
+
// Ticket 112: same merge-before-write as update. A template without both
|
|
392
|
+
// boundaries is a partial edit → delta merge (see activitiesLackBoundaries).
|
|
393
|
+
const body = await mergedTemplateBody(session, args.schemaCode, args.code, template, activitiesLackBoundaries(template));
|
|
394
|
+
await backfillDesignerDefaults(session, args.schemaCode, body, template);
|
|
395
|
+
assertFirstActivityIsOriginator(template, "workflow.publish", body);
|
|
396
|
+
await assertRoleParticipantScopes(session, body);
|
|
397
|
+
const unregistered = unregisteredParticipantFunctions(body);
|
|
398
|
+
if (unregistered.length > 0)
|
|
399
|
+
throw new ToolRefusalError({
|
|
400
|
+
status: "refused",
|
|
401
|
+
blocker: "workflow-participant-function-unregistered",
|
|
402
|
+
workflowCode: args.code,
|
|
403
|
+
activities: unregistered,
|
|
404
|
+
message: `流程发布被拒:参与人函数 ${[...new Set(unregistered.map((entry) => entry.functionName + "()"))].join("、")} 在 AI-Platform v1.1.25 未注册(节点 ${unregistered.map((entry) => entry.activityCode).join("、")})。` +
|
|
405
|
+
`发布能过,但运行期 ParticipantActivityRuntime 抛 FunctionNotFoundException:实例卡 PROCESSING、不生成待办,而 data.submit 仍回 errCode 0(r4-training 真机)。` +
|
|
406
|
+
`AI-Platform v1.1.25 已验证的内置写法是 FindUserByRole({Originator.OU},"<roleCode>","random");CloudPivot 8.6.26 另注册上级族函数(如 FindUsersByDirectSupervisor、OUManager、RecurseManager),但目标环境使用前先真机跑一单。跨部门/全局角色改用参与者对象数组(角色 id)。` +
|
|
407
|
+
`这两个名字常见于 workflow.get_published 读回与种子流程,不要回抄。`,
|
|
408
|
+
});
|
|
409
|
+
validateWorkflowRender(body, "workflow.publish");
|
|
410
|
+
const performed = await wireCall(session, { path: ENDPOINTS.workflowPublish, method: "POST", body });
|
|
411
|
+
// A refused publish answers errcode 0 — the ValidateMessage[] is the truth.
|
|
412
|
+
assertWorkflowWriteAccepted(performed, "workflow.publish", args.code);
|
|
413
|
+
const published = await wireCall(session, { path: ENDPOINTS.workflowGetPublished, query: { workflowCode: args.code } });
|
|
414
|
+
const data = (published.data ?? null);
|
|
415
|
+
// Ticket 77: publish evidence is the published-face MARKER, not data
|
|
416
|
+
// presence (the endpoint answers the draft shape when unpublished).
|
|
417
|
+
const isPublished = data !== null && (data.templateType === "PUBLISH" || data.published === true);
|
|
418
|
+
if (!data)
|
|
419
|
+
throw new ToolRefusalError({ status: "refused", blocker: "workflow-render-readback-invalid", message: "workflow.publish returned no published template" });
|
|
420
|
+
const warnings = workflowValidationWarnings(performed.data);
|
|
421
|
+
// The platform accepted the write (no ERROR) yet the published face still
|
|
422
|
+
// shows the draft marker: surface that honestly instead of implying the
|
|
423
|
+
// flow went live.
|
|
424
|
+
if (!isPublished)
|
|
425
|
+
throw new ToolRefusalError({
|
|
426
|
+
status: "refused",
|
|
427
|
+
blocker: "workflow-publish-not-applied",
|
|
428
|
+
workflowCode: args.code,
|
|
429
|
+
message: `workflow.publish: 平台接受写入(errcode 0)但读回仍是草稿形态(templateType=${String(data.templateType ?? "null")}, published=${String(data.published ?? "null")})——流程未生效。先 workflow.validate 复核模板,修正后重试`,
|
|
430
|
+
});
|
|
431
|
+
validateWorkflowRender(data, "workflow.publish readback");
|
|
432
|
+
const participantWarnings = participantReferenceWarnings(data);
|
|
433
|
+
const rejectWarnings = rejectToStartCancelWarnings(data);
|
|
434
|
+
const originatorWarnings = approvalByOriginatorWarnings(data);
|
|
435
|
+
// F10(0.8.6):平台 publish 成功后在**首次发布**(workflowVersion=1,两族同
|
|
436
|
+
// 语义:2.1.5 ProcessDefineAssemblyServiceImpl:141-147 / 8.6.26 :175-181)会
|
|
437
|
+
// 静默把该模型各列表视图的 add 动作改成 setQueryActionRelativeType(WORKFLOW)
|
|
438
|
+
// + setRelativeCode(流程码)(WorkflowTemplateController.publish →
|
|
439
|
+
// updateBizQueryBindWorkflowCode → updateBizQueryAddAction,8.6.26 :805/:830-846;
|
|
440
|
+
// 2.1.5 :695-711/:741-761)。不告知的话清理期只在 workflow.delete 撞 303024。
|
|
441
|
+
// 代价:平台列表面 listQueryList 只回 code/name,确认绑定需 1 次 list + 每视图
|
|
442
|
+
// 1 次 get(本模型通常 1-3 个视图)。
|
|
443
|
+
const addBindings = await listviewAddBindings(session, args.schemaCode, args.code);
|
|
444
|
+
const firstPublish = Number(data.workflowVersion) === 1;
|
|
445
|
+
const firstBoundView = addBindings.bound[0];
|
|
446
|
+
// Same query/get response as the binding scan — no extra wire round-trip.
|
|
447
|
+
// The unbind recipe mirrors workflow.delete's 303024 recovery (live-proven:
|
|
448
|
+
// empty actions + replaceActions:true).
|
|
449
|
+
const unbindCommand = firstBoundView === undefined
|
|
450
|
+
? undefined
|
|
451
|
+
: `omc call listview.configure --env <env> --args '${JSON.stringify({
|
|
452
|
+
schemaCode: args.schemaCode,
|
|
453
|
+
code: firstBoundView.code,
|
|
454
|
+
fieldCodes: firstBoundView.fieldCodes.length > 0 ? firstBoundView.fieldCodes : ["createdTime", "creater", "name", "sequenceNo"],
|
|
455
|
+
actions: [],
|
|
456
|
+
replaceActions: true,
|
|
457
|
+
})}'`;
|
|
458
|
+
// F8(0.8.16 探针 J):`workflow.delete` 已支持 `unbindListviews:true`——它
|
|
459
|
+
// 只解本流程的视图绑定,不动视图其它动作。旧的 beforeWorkflowDelete 只
|
|
460
|
+
// 指向 listview.configure `actions:[] + replaceActions:true`,那会把
|
|
461
|
+
// add/delete/import/export/editowner 等其它动作一起清掉。首选 unbindListviews。
|
|
462
|
+
const workflowDeleteCommand = `omc call workflow.delete --env <env> --args '${JSON.stringify({
|
|
463
|
+
schemaCode: args.schemaCode,
|
|
464
|
+
code: args.code,
|
|
465
|
+
unbindListviews: true,
|
|
466
|
+
})}'`;
|
|
467
|
+
const listviewBinding = {
|
|
468
|
+
bound: addBindings.bound.map(({ code, actionCode }) => ({ code, actionCode })),
|
|
469
|
+
...(firstPublish ? {} : { firstPublish: false }),
|
|
470
|
+
note: addBindings.bound.length > 0
|
|
471
|
+
? firstPublish
|
|
472
|
+
? "首次发布已把本模型各列表视图的 add 动作绑到本流程;删流程前用 workflow.delete 的 nextCommand(unbindListviews:true)解绑"
|
|
473
|
+
: "列表视图的 add 动作已绑定本流程(本次不是首次发布,绑定沿用既有配置);删流程前用 workflow.delete 的 nextCommand(unbindListviews:true)解绑"
|
|
474
|
+
: addBindings.readable
|
|
475
|
+
? "无隐式绑定"
|
|
476
|
+
: "列表视图读取失败,未能确认 add 绑定;删流程前先 listview.get 复核",
|
|
477
|
+
...(addBindings.bound.length > 0
|
|
478
|
+
? {
|
|
479
|
+
beforeWorkflowDelete: "删流程前先解绑:首选 nextCommand —— workflow.delete 带 unbindListviews:true,本工具会先逐个视图解绑(只清本流程的绑定,不动视图其它动作),再删流程;否则会撞 workflow-bound-to-listview(303024,列表还绑着流程)。多个视图绑定时由 unbindListviews 逐视图处理。",
|
|
480
|
+
...(unbindCommand !== undefined
|
|
481
|
+
? {
|
|
482
|
+
unbindCommand,
|
|
483
|
+
unbindCommandNote: "次选(只在你想手工改视图时用):listview.configure 清 actions:[] + replaceActions:true 会**顺带清掉该视图的其它动作**(add/delete/import/export/editowner 等),不是只解本流程绑定;只想解本流程绑定请用 nextCommand。",
|
|
484
|
+
}
|
|
485
|
+
: {}),
|
|
486
|
+
nextCommand: workflowDeleteCommand,
|
|
487
|
+
}
|
|
488
|
+
: {}),
|
|
489
|
+
};
|
|
490
|
+
return { performed: { errcode: performed.errcode }, readback: { workflowCode: args.code, published: isPublished, workflowVersion: data.workflowVersion ?? null, listviewBinding, ...(strippedEmptyConditionGroups > 0 ? { strippedEmptyConditionGroups, strippedEmptyConditionGroupsNote: "调用方连线里有 N 条带平台存量写法 ruleConditionGroup:[](=无条件);工具写前已剥离该键,未上送" } : {}), ...(warnings.length ? { warnings } : {}), ...(participantWarnings.length ? { participantWarnings } : {}), ...(rejectWarnings.length || originatorWarnings.length ? { workflowWarnings: [...rejectWarnings, ...originatorWarnings] } : {}), workflowRenderCompat: workflowRenderCompat(data) } };
|
|
491
|
+
},
|
|
492
|
+
preflight: (args) => {
|
|
493
|
+
assertTemplateNotMinimal(args.template ?? {}, "workflow.publish");
|
|
494
|
+
},
|
|
495
|
+
rollback: workflowRollbackSpec("workflow.publish"),
|
|
496
|
+
});
|
|
497
|
+
writeTool({
|
|
498
|
+
tools,
|
|
499
|
+
name: "workflow.bindRule",
|
|
500
|
+
search: { intents: ["绑定规则", "流程绑定规则", "给流程绑规则"] },
|
|
501
|
+
lane: WORKFLOW_LANE,
|
|
502
|
+
scope: WORKFLOW_TOOLS["workflow.bindRule"].scope,
|
|
503
|
+
description: WORKFLOW_TOOLS["workflow.bindRule"].description,
|
|
504
|
+
inputSchema: {
|
|
505
|
+
schemaCode: z.string().min(1),
|
|
506
|
+
workflowCode: z.string().min(1),
|
|
507
|
+
ruleCode: z.string().min(1).optional().describe("single-rule form: the rule to bind (mutually exclusive with ruleCodes)"),
|
|
508
|
+
ruleCodes: z.array(z.string().min(1)).min(1).optional().describe("batch form: several rules bound in ONE update + publish; MERGE semantics — the handler's existing bizActions are preserved and the listed rules appended (deduplicated)"),
|
|
509
|
+
handler: z
|
|
510
|
+
.string()
|
|
511
|
+
.optional()
|
|
512
|
+
.describe("FLOW-level event handler to bind: start | cancel | activate | end (default end). 与 activityCode+nodeEvent 互斥"),
|
|
513
|
+
activityCode: z
|
|
514
|
+
.string()
|
|
515
|
+
.min(1)
|
|
516
|
+
.optional()
|
|
517
|
+
.describe("NODE-level target activity (草稿里的 activityCode,如 Activity2). 必须与 nodeEvent 同时给;节点不存在时报 workflow-activity-not-found 并列出可用 code"),
|
|
518
|
+
nodeEvent: z
|
|
519
|
+
.enum(["beforeActivate", "afterActivate", "endActivity", "cancelActivity", "activityApproved", "activityRejected", "jobSubmitted", "jobRejected"])
|
|
520
|
+
.optional()
|
|
521
|
+
.describe("NODE-level event on activityCode: beforeActivate|afterActivate|endActivity|cancelActivity|activityApproved|activityRejected|jobSubmitted|jobRejected(如填写节点 endActivity = 申请人提交离开该节点时). 与 handler 互斥"),
|
|
522
|
+
publish: z.boolean().optional(),
|
|
523
|
+
},
|
|
524
|
+
execute: async (session, args) => {
|
|
525
|
+
const target = resolveBindTarget(args.handler, args.nodeEvent, args.activityCode);
|
|
526
|
+
const codes = (args.ruleCodes ?? [args.ruleCode]).map(String);
|
|
527
|
+
// Only CUSTOM rules are bindable to workflow events — the designer's picker
|
|
528
|
+
// does not offer preset trigger rows (bench59 bound `Create` to `end`).
|
|
529
|
+
const bindableByCode = await assertBindableWorkflowRules(session, args.schemaCode, codes);
|
|
530
|
+
// A bound workflow rule MUST be enabled (else 失效/未启用). Enable any
|
|
531
|
+
// disabled bound custom rule before writing the binding.
|
|
532
|
+
const { enabledRuleCodes, alreadyEnabledRuleCodes } = await ensureWorkflowRulesEnabled(session, args.schemaCode, codes, bindableByCode);
|
|
533
|
+
const shouldPublish = args.publish !== false;
|
|
534
|
+
const draft = (await getWorkflowDraftOrNull(session, args.workflowCode)) ?? {};
|
|
535
|
+
if (Object.keys(draft).length === 0) {
|
|
536
|
+
throw new ToolRefusalError({
|
|
537
|
+
status: "refused",
|
|
538
|
+
blocker: "workflow-not-found",
|
|
539
|
+
workflowCode: args.workflowCode,
|
|
540
|
+
message: `流程 ${args.workflowCode} 不存在(get_draft 401001 缺席)——先 workflow.create,再 bindRule`,
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
// Node-level: fail closed BEFORE the wire when the activity code is not in
|
|
544
|
+
// the draft, and name the codes that ARE (the designer's own codes like
|
|
545
|
+
// Activity2 are the common miss).
|
|
546
|
+
if (target.scope === "activity" && !findTemplateActivity(draft, target.activityCode)) {
|
|
547
|
+
throw new ToolRefusalError({
|
|
548
|
+
status: "refused",
|
|
549
|
+
blocker: "workflow-activity-not-found",
|
|
550
|
+
workflowCode: args.workflowCode,
|
|
551
|
+
activityCode: target.activityCode,
|
|
552
|
+
activities: templateActivityCodes(draft),
|
|
553
|
+
message: `流程 ${args.workflowCode} 的草稿里没有活动 ${target.activityCode}——节点级事件必须指向已存在的活动。可用活动:${templateActivityCodes(draft).join("、") || "(无)"}(先用 workflow.get_draft 看 code,别用节点名)`,
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
const handlerOf = (template) => {
|
|
557
|
+
if (target.scope === "workflow")
|
|
558
|
+
return (template?.[target.field] ?? {}) ?? {};
|
|
559
|
+
return (findTemplateActivity(template, target.activityCode)?.[target.field] ?? {}) ?? {};
|
|
560
|
+
};
|
|
561
|
+
const existing = handlerOf(draft);
|
|
562
|
+
const priorActions = Array.isArray(existing.bizActions)
|
|
563
|
+
? existing.bizActions.filter((value) => typeof value === "string")
|
|
564
|
+
: [];
|
|
565
|
+
// MERGE: existing bizActions are preserved; the listed rules are
|
|
566
|
+
// appended in order, deduplicated (same semantics the single-rule form
|
|
567
|
+
// has always had — replace is NOT the contract).
|
|
568
|
+
const nextActions = [...priorActions];
|
|
569
|
+
for (const code of codes)
|
|
570
|
+
if (!nextActions.includes(code))
|
|
571
|
+
nextActions.push(code);
|
|
572
|
+
const mergedHandler = {
|
|
573
|
+
...(typeof existing === "object" && existing ? existing : {}),
|
|
574
|
+
bizActions: nextActions,
|
|
575
|
+
bizActionType: "BIZ_RULE",
|
|
576
|
+
};
|
|
577
|
+
let nextTemplate;
|
|
578
|
+
if (target.scope === "workflow") {
|
|
579
|
+
nextTemplate = { ...draft, [target.field]: mergedHandler, workflowCode: args.workflowCode, schemaCode: args.schemaCode };
|
|
580
|
+
}
|
|
581
|
+
else {
|
|
582
|
+
// Keep the draft's activities container shape (array or index-keyed
|
|
583
|
+
// object) — only the selected row's handler field changes.
|
|
584
|
+
nextTemplate = mapTemplateActivity(draft, target.activityCode, (row) => ({ ...row, [target.field]: mergedHandler })).template;
|
|
585
|
+
nextTemplate = { ...nextTemplate, workflowCode: args.workflowCode, schemaCode: args.schemaCode };
|
|
586
|
+
}
|
|
587
|
+
validateWorkflowRender(nextTemplate, "workflow.bindRule");
|
|
588
|
+
const performed = await wireCall(session, {
|
|
589
|
+
path: ENDPOINTS.workflowUpdate,
|
|
590
|
+
method: "POST",
|
|
591
|
+
body: nextTemplate,
|
|
592
|
+
});
|
|
593
|
+
let publishedReadback = null;
|
|
594
|
+
let publishMarked = false;
|
|
595
|
+
if (shouldPublish) {
|
|
596
|
+
const publishPerformed = await wireCall(session, {
|
|
597
|
+
path: ENDPOINTS.workflowPublish,
|
|
598
|
+
method: "POST",
|
|
599
|
+
body: nextTemplate,
|
|
600
|
+
});
|
|
601
|
+
// A refused publish answers errcode 0 with the truth in ValidateMessage[].
|
|
602
|
+
assertWorkflowWriteAccepted(publishPerformed, "workflow.bindRule", args.workflowCode);
|
|
603
|
+
const pub = await wireCall(session, { path: ENDPOINTS.workflowGetPublished, query: { workflowCode: args.workflowCode } });
|
|
604
|
+
publishedReadback = (pub.data ?? null);
|
|
605
|
+
// Authoritative marker, not the request echo (ticket 77 semantics).
|
|
606
|
+
publishMarked = publishedReadback !== null && (publishedReadback.templateType === "PUBLISH" || publishedReadback.published === true);
|
|
607
|
+
}
|
|
608
|
+
const draftReadback = await wireCall(session, { path: ENDPOINTS.workflowGetDraft, query: { workflowCode: args.workflowCode } });
|
|
609
|
+
const data = (draftReadback.data ?? null);
|
|
610
|
+
if (!data)
|
|
611
|
+
throw new ToolRefusalError({ status: "refused", blocker: "workflow-render-readback-invalid", message: "workflow.bindRule returned no draft" });
|
|
612
|
+
validateWorkflowRender(data, "workflow.bindRule readback");
|
|
613
|
+
const handler = handlerOf(data);
|
|
614
|
+
const bizActions = Array.isArray(handler?.bizActions) ? handler.bizActions.filter((value) => typeof value === "string") : [];
|
|
615
|
+
const publishedHandler = publishedReadback ? handlerOf(publishedReadback) : undefined;
|
|
616
|
+
const publishedBizActions = Array.isArray(publishedHandler?.bizActions)
|
|
617
|
+
? publishedHandler.bizActions.filter((value) => typeof value === "string")
|
|
618
|
+
: [];
|
|
619
|
+
const targetShape = target.scope === "workflow"
|
|
620
|
+
? { handler: target.key, handlerField: target.field }
|
|
621
|
+
: { activityCode: target.activityCode, nodeEvent: target.key, nodeEventField: target.field };
|
|
622
|
+
return {
|
|
623
|
+
performed: { errcode: performed.errcode, scope: target.scope, ...targetShape, addedRuleCodes: codes, bizActions, publishRequested: shouldPublish },
|
|
624
|
+
readback: {
|
|
625
|
+
workflowCode: args.workflowCode,
|
|
626
|
+
scope: target.scope,
|
|
627
|
+
...targetShape,
|
|
628
|
+
semantics: "merge",
|
|
629
|
+
bound: codes.every((code) => bizActions.includes(code)),
|
|
630
|
+
bizActions,
|
|
631
|
+
// Workflow-bound rules must be enabled; report the enable delta.
|
|
632
|
+
enabledRuleCodes,
|
|
633
|
+
alreadyEnabledRuleCodes,
|
|
634
|
+
bizActionType: typeof handler?.bizActionType === "string" ? handler.bizActionType : null,
|
|
635
|
+
templateFieldsPreserved: target.scope === "workflow"
|
|
636
|
+
? Object.keys(draft).every((key) => key === target.field || data[key] !== undefined)
|
|
637
|
+
: Object.keys(draft).every((key) => data[key] !== undefined),
|
|
638
|
+
// Authoritative published-face marker, NOT the request echo: a
|
|
639
|
+
// refused publish keeps errcode 0 and the draft marker (live 8.6.26).
|
|
640
|
+
published: publishMarked,
|
|
641
|
+
publishedBound: codes.every((code) => publishedBizActions.includes(code)),
|
|
642
|
+
publishedBizActions,
|
|
643
|
+
publishedBizActionType: typeof publishedHandler?.bizActionType === "string" ? publishedHandler.bizActionType : null,
|
|
644
|
+
...(participantReferenceWarnings(data).length ? { participantWarnings: participantReferenceWarnings(data) } : {}),
|
|
645
|
+
...(bizActions.length > 1
|
|
646
|
+
? { advisory: `同一事件处理器绑定了 ${bizActions.length} 条规则,它们会**全部执行**(没有互斥):审批通过/驳回这类互斥结果不要用两条各自 FIXED 赋值的规则——两次都会写、后者覆盖前者(bench22 病灶:通过→已通过、驳回→已驳回 两条各自 FIXED 赋值都绑 endEventHandler)。正确做法二选一:① **绑定到不同处理器/触发**——通过绑流程结束处理器 \`end\`(endEventHandler)或流程生效规则 \`Available\`,驳回绑流程作废处理器 \`cancel\`(cancelEventHandler)或规则 \`Cancel\`;② **一条规则内部按条件分支**(规则图用 BRANCH/filterCondition/dataCondition 读审批结果,多分支各写各的)。真实生产(2026-09-23,case_info_update)只在 endEventHandler 绑一条多分支图(updateData),由该图内部分支完成回写。` }
|
|
647
|
+
: {}),
|
|
648
|
+
workflowRenderCompat: workflowRenderCompat(data),
|
|
649
|
+
},
|
|
650
|
+
};
|
|
651
|
+
},
|
|
652
|
+
preflight: (args) => {
|
|
653
|
+
resolveBindTarget(args.handler, args.nodeEvent, args.activityCode);
|
|
654
|
+
const hasSingle = typeof args.ruleCode === "string" && args.ruleCode.length > 0;
|
|
655
|
+
const hasMany = Array.isArray(args.ruleCodes);
|
|
656
|
+
if (hasSingle && hasMany)
|
|
657
|
+
throw new ToolRefusalError({ status: "refused", blocker: "workflow-bindrule-codes-exclusive", message: "ruleCode 与 ruleCodes 互斥:单规则用 ruleCode,多规则用 ruleCodes[]" });
|
|
658
|
+
if (!hasSingle && !hasMany)
|
|
659
|
+
throw new ToolRefusalError({ status: "refused", blocker: "workflow-bindrule-codes-invalid", message: "需要 ruleCode(单个)或 ruleCodes(数组)之一" });
|
|
660
|
+
if (hasMany) {
|
|
661
|
+
const codes = args.ruleCodes;
|
|
662
|
+
if (codes.length === 0 || new Set(codes.map(String)).size !== codes.length || codes.some((code) => typeof code !== "string" || code.length === 0))
|
|
663
|
+
throw new ToolRefusalError({ status: "refused", blocker: "workflow-bindrule-codes-invalid", message: "ruleCodes 必须是非空、去重的规则 code 数组" });
|
|
664
|
+
}
|
|
665
|
+
},
|
|
666
|
+
rollback: workflowRollbackSpec("workflow.bindRule"),
|
|
667
|
+
});
|
|
668
|
+
// r85(retro 2026-11-19 issue 01):bindRule 只有 merge 语义,误绑无法用 CLI
|
|
669
|
+
// 撤销,只能 get_draft 导出整模板→手改→update(还要绕空条件组拒绝)→publish,
|
|
670
|
+
// 一次撤销 4 次工具调用。unbindRule 镜像 bindRule 的两种目标形态做减法。
|
|
671
|
+
writeTool({
|
|
672
|
+
tools,
|
|
673
|
+
name: "workflow.unbindRule",
|
|
674
|
+
search: { intents: ["解绑规则", "解绑流程规则", "取消流程绑定", "移除规则绑定", "unbind rule"] },
|
|
675
|
+
lane: WORKFLOW_LANE,
|
|
676
|
+
scope: WORKFLOW_TOOLS["workflow.unbindRule"].scope,
|
|
677
|
+
description: WORKFLOW_TOOLS["workflow.unbindRule"].description,
|
|
678
|
+
inputSchema: {
|
|
679
|
+
schemaCode: z.string().min(1),
|
|
680
|
+
workflowCode: z.string().min(1),
|
|
681
|
+
ruleCode: z.string().min(1).optional().describe("single-rule form: the rule to unbind (mutually exclusive with ruleCodes)"),
|
|
682
|
+
ruleCodes: z.array(z.string().min(1)).min(1).optional().describe("batch form: several rules removed in ONE update + publish; only the listed codes are removed, the handler's other bindings are preserved"),
|
|
683
|
+
handler: z
|
|
684
|
+
.string()
|
|
685
|
+
.optional()
|
|
686
|
+
.describe("FLOW-level event handler to unbind from: start | cancel | activate | end (default end). 与 activityCode+nodeEvent 互斥"),
|
|
687
|
+
activityCode: z
|
|
688
|
+
.string()
|
|
689
|
+
.min(1)
|
|
690
|
+
.optional()
|
|
691
|
+
.describe("NODE-level target activity (草稿里的 activityCode). 必须与 nodeEvent 同时给;节点不存在时报 workflow-activity-not-found 并列出可用 code"),
|
|
692
|
+
nodeEvent: z
|
|
693
|
+
.enum(["beforeActivate", "afterActivate", "endActivity", "cancelActivity", "activityApproved", "activityRejected", "jobSubmitted", "jobRejected"])
|
|
694
|
+
.optional()
|
|
695
|
+
.describe("NODE-level event on activityCode(与 bindRule 同一枚举). 与 handler 互斥"),
|
|
696
|
+
publish: z.boolean().optional(),
|
|
697
|
+
},
|
|
698
|
+
execute: async (session, args) => {
|
|
699
|
+
// 读回+校验与 dry-run 共用 unbindRuleContext(同 refusal、同答案)。
|
|
700
|
+
const { target, codes, shouldPublish, nextTemplate } = await unbindRuleContext(session, args);
|
|
701
|
+
const handlerOf = (template) => bindTargetHandlerOf(template, target);
|
|
702
|
+
const performed = await wireCall(session, {
|
|
703
|
+
path: ENDPOINTS.workflowUpdate,
|
|
704
|
+
method: "POST",
|
|
705
|
+
body: nextTemplate,
|
|
706
|
+
});
|
|
707
|
+
let publishedReadback = null;
|
|
708
|
+
let publishMarked = false;
|
|
709
|
+
if (shouldPublish) {
|
|
710
|
+
const publishPerformed = await wireCall(session, {
|
|
711
|
+
path: ENDPOINTS.workflowPublish,
|
|
712
|
+
method: "POST",
|
|
713
|
+
body: nextTemplate,
|
|
714
|
+
});
|
|
715
|
+
assertWorkflowWriteAccepted(publishPerformed, "workflow.unbindRule", args.workflowCode);
|
|
716
|
+
const pub = await wireCall(session, { path: ENDPOINTS.workflowGetPublished, query: { workflowCode: args.workflowCode } });
|
|
717
|
+
publishedReadback = (pub.data ?? null);
|
|
718
|
+
publishMarked = publishedReadback !== null && (publishedReadback.templateType === "PUBLISH" || publishedReadback.published === true);
|
|
719
|
+
}
|
|
720
|
+
const draftReadback = await wireCall(session, { path: ENDPOINTS.workflowGetDraft, query: { workflowCode: args.workflowCode } });
|
|
721
|
+
const data = (draftReadback.data ?? null);
|
|
722
|
+
if (!data)
|
|
723
|
+
throw new ToolRefusalError({ status: "refused", blocker: "workflow-render-readback-invalid", message: "workflow.unbindRule returned no draft" });
|
|
724
|
+
validateWorkflowRender(data, "workflow.unbindRule readback");
|
|
725
|
+
const handler = handlerOf(data);
|
|
726
|
+
const bizActions = Array.isArray(handler?.bizActions) ? handler.bizActions.filter((value) => typeof value === "string") : [];
|
|
727
|
+
const publishedHandler = publishedReadback ? handlerOf(publishedReadback) : undefined;
|
|
728
|
+
const publishedBizActions = Array.isArray(publishedHandler?.bizActions)
|
|
729
|
+
? publishedHandler.bizActions.filter((value) => typeof value === "string")
|
|
730
|
+
: [];
|
|
731
|
+
const targetShape = target.scope === "workflow"
|
|
732
|
+
? { handler: target.key, handlerField: target.field }
|
|
733
|
+
: { activityCode: target.activityCode, nodeEvent: target.key, nodeEventField: target.field };
|
|
734
|
+
return {
|
|
735
|
+
performed: { errcode: performed.errcode, scope: target.scope, ...targetShape, removedRuleCodes: codes, bizActions, publishRequested: shouldPublish },
|
|
736
|
+
readback: {
|
|
737
|
+
workflowCode: args.workflowCode,
|
|
738
|
+
scope: target.scope,
|
|
739
|
+
...targetShape,
|
|
740
|
+
semantics: "remove",
|
|
741
|
+
unbound: codes.every((code) => !bizActions.includes(code)),
|
|
742
|
+
bizActions,
|
|
743
|
+
handlerCleared: bizActions.length === 0,
|
|
744
|
+
// 解绑不回滚 bindRule 的 enable 副作用:规则可能被其它流程/事件绑定,
|
|
745
|
+
// 这里绝不自动 disable。确认无引用(rule.references kind=rule)后要停用
|
|
746
|
+
// 再单独 rule.disable。
|
|
747
|
+
ruleEnableUntouched: true,
|
|
748
|
+
published: publishMarked,
|
|
749
|
+
publishedUnbound: codes.every((code) => !publishedBizActions.includes(code)),
|
|
750
|
+
publishedBizActions,
|
|
751
|
+
workflowRenderCompat: workflowRenderCompat(data),
|
|
752
|
+
},
|
|
753
|
+
};
|
|
754
|
+
},
|
|
755
|
+
preflight: (args) => {
|
|
756
|
+
resolveBindTarget(args.handler, args.nodeEvent, args.activityCode);
|
|
757
|
+
const hasSingle = typeof args.ruleCode === "string" && args.ruleCode.length > 0;
|
|
758
|
+
const hasMany = Array.isArray(args.ruleCodes);
|
|
759
|
+
if (hasSingle && hasMany)
|
|
760
|
+
throw new ToolRefusalError({ status: "refused", blocker: "workflow-bindrule-codes-exclusive", message: "ruleCode 与 ruleCodes 互斥:单规则用 ruleCode,多规则用 ruleCodes[]" });
|
|
761
|
+
if (!hasSingle && !hasMany)
|
|
762
|
+
throw new ToolRefusalError({ status: "refused", blocker: "workflow-bindrule-codes-invalid", message: "需要 ruleCode(单个)或 ruleCodes(数组)之一" });
|
|
763
|
+
if (hasMany) {
|
|
764
|
+
const codes = args.ruleCodes;
|
|
765
|
+
if (codes.length === 0 || new Set(codes.map(String)).size !== codes.length || codes.some((code) => typeof code !== "string" || code.length === 0))
|
|
766
|
+
throw new ToolRefusalError({ status: "refused", blocker: "workflow-bindrule-codes-invalid", message: "ruleCodes 必须是非空、去重的规则 code 数组" });
|
|
767
|
+
}
|
|
768
|
+
},
|
|
769
|
+
// dry-run 与真写同答案:读回+校验走 execute 同一个 unbindRuleContext——
|
|
770
|
+
// 不存在流程 / 不存在活动 / absent code 在 dry-run 就拿到与真写完全相同的
|
|
771
|
+
// refusal(打错 ruleCode 不再先亮 wouldChange:true);全过则回预览载荷。
|
|
772
|
+
dryRunPayload: async (session, args) => {
|
|
773
|
+
const ctx = await unbindRuleContext(session, args);
|
|
774
|
+
const targetShape = ctx.target.scope === "workflow"
|
|
775
|
+
? { handler: ctx.target.key, handlerField: ctx.target.field }
|
|
776
|
+
: { activityCode: ctx.target.activityCode, nodeEvent: ctx.target.key, nodeEventField: ctx.target.field };
|
|
777
|
+
return {
|
|
778
|
+
workflowCode: args.workflowCode,
|
|
779
|
+
scope: ctx.target.scope,
|
|
780
|
+
...targetShape,
|
|
781
|
+
removedRuleCodes: ctx.codes,
|
|
782
|
+
currentBizActions: ctx.priorActions,
|
|
783
|
+
remainingBizActions: ctx.nextActions,
|
|
784
|
+
handlerWillBeCleared: ctx.nextActions.length === 0,
|
|
785
|
+
publish: ctx.shouldPublish,
|
|
786
|
+
ruleEnableUntouched: true,
|
|
787
|
+
summary: writeSummary("workflow.unbindRule", args, undefined, "plan"),
|
|
788
|
+
};
|
|
789
|
+
},
|
|
790
|
+
lintScope: "full",
|
|
791
|
+
lintUnchecked: ["platform-side-validation", "post-write-readback"],
|
|
792
|
+
rollback: workflowRollbackSpec("workflow.unbindRule"),
|
|
793
|
+
});
|
|
794
|
+
/**
|
|
795
|
+
* Friendly writer for the designer's 「表单操作」 checkboxes: each PARTICIPANT
|
|
796
|
+
* activity carries `buttonPermission.customBtns[]` = the form-toolbar buttons
|
|
797
|
+
* enabled at that node (ActionPermissionHandler.setProcessButtonPermission
|
|
798
|
+
* filters `getByTriggerTypeAndCode(FORM, formCode)` by this list; a code that
|
|
799
|
+
* is absent or enabled:false does not render). Writing the whole
|
|
800
|
+
* `buttonPermission` object by hand means re-sending containerCode +
|
|
801
|
+
* childTableBtns, which is exactly how a caller drops the child-table
|
|
802
|
+
* defaults — this tool merges per node.
|
|
803
|
+
*/
|
|
804
|
+
writeTool({
|
|
805
|
+
tools,
|
|
806
|
+
name: "workflow.setButtons",
|
|
807
|
+
search: { intents: ["勾选按钮", "表单操作按钮", "节点按钮", "按钮权限"] },
|
|
808
|
+
lane: WORKFLOW_LANE,
|
|
809
|
+
scope: WORKFLOW_TOOLS["workflow.setButtons"].scope,
|
|
810
|
+
description: WORKFLOW_TOOLS["workflow.setButtons"].description,
|
|
811
|
+
inputSchema: {
|
|
812
|
+
schemaCode: z.string().min(1),
|
|
813
|
+
workflowCode: z.string().min(1),
|
|
814
|
+
nodes: z
|
|
815
|
+
.array(z.object({
|
|
816
|
+
activityCode: z.string().min(1).describe("活动 code(workflow.get_draft 的 activities[].code)"),
|
|
817
|
+
buttonCodes: z.array(z.string().min(1)).describe("该节点要**启用**的表单按钮 code(按 form.get 的 formButtonCodes);未列出的置为 enabled:false,不删除子表按钮配置"),
|
|
818
|
+
}))
|
|
819
|
+
.min(1),
|
|
820
|
+
publish: z.boolean().optional().describe("默认 true:写草稿后发布,表单页立即生效;false 只写草稿"),
|
|
821
|
+
},
|
|
822
|
+
execute: async (session, args) => {
|
|
823
|
+
const draft = (await getWorkflowDraftOrNull(session, args.workflowCode)) ?? {};
|
|
824
|
+
if (Object.keys(draft).length === 0)
|
|
825
|
+
throw new ToolRefusalError({
|
|
826
|
+
status: "refused",
|
|
827
|
+
blocker: "workflow-not-found",
|
|
828
|
+
workflowCode: args.workflowCode,
|
|
829
|
+
message: `流程 ${args.workflowCode} 不存在(get_draft 401001 缺席)`,
|
|
830
|
+
});
|
|
831
|
+
const available = await readSchemaFormButtons(session, args.schemaCode);
|
|
832
|
+
const availableCodes = Object.keys(available);
|
|
833
|
+
const draftCodes = templateActivityCodes(draft);
|
|
834
|
+
const patches = [];
|
|
835
|
+
const names = {};
|
|
836
|
+
for (const node of args.nodes) {
|
|
837
|
+
const row = findTemplateActivity(draft, node.activityCode);
|
|
838
|
+
if (!row) {
|
|
839
|
+
throw new ToolRefusalError({
|
|
840
|
+
status: "refused",
|
|
841
|
+
blocker: "workflow-activity-not-found",
|
|
842
|
+
workflowCode: args.workflowCode,
|
|
843
|
+
activityCode: node.activityCode,
|
|
844
|
+
activities: draftCodes,
|
|
845
|
+
message: `流程 ${args.workflowCode} 没有活动 ${node.activityCode};可用:${draftCodes.join("、") || "(无)"}`,
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
const unknown = node.buttonCodes.filter((code) => available[code] === undefined);
|
|
849
|
+
if (unknown.length > 0) {
|
|
850
|
+
throw new ToolRefusalError({
|
|
851
|
+
status: "refused",
|
|
852
|
+
blocker: "form-button-absent",
|
|
853
|
+
schemaCode: args.schemaCode,
|
|
854
|
+
activityCode: node.activityCode,
|
|
855
|
+
buttonCodes: unknown,
|
|
856
|
+
available: availableCodes,
|
|
857
|
+
message: `按钮 ${unknown.join("、")} 不在模型 ${args.schemaCode} 的表单按钮里;先 form.publish {buttons:[…]} 生成。可用:${availableCodes.join("、") || "(无)"}`,
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
const existing = (row.buttonPermission ?? {});
|
|
861
|
+
const existingBtns = Array.isArray(existing.customBtns) ? existing.customBtns : [];
|
|
862
|
+
const wanted = new Set(node.buttonCodes);
|
|
863
|
+
const merged = [];
|
|
864
|
+
for (const button of existingBtns) {
|
|
865
|
+
const code = String(button.code ?? "");
|
|
866
|
+
if (code === "")
|
|
867
|
+
continue;
|
|
868
|
+
merged.push({ ...button, enabled: wanted.has(code) });
|
|
869
|
+
wanted.delete(code);
|
|
870
|
+
}
|
|
871
|
+
for (const code of wanted) {
|
|
872
|
+
const source = available[code];
|
|
873
|
+
names[code] = String(source.name ?? code);
|
|
874
|
+
merged.push({ code, name: String(source.name ?? code), name_i18n: source.name_i18n ?? null, enabled: true, type: "form" });
|
|
875
|
+
}
|
|
876
|
+
patches.push({
|
|
877
|
+
activityCode: node.activityCode,
|
|
878
|
+
buttonPermission: {
|
|
879
|
+
...existing,
|
|
880
|
+
containerCode: existing.containerCode ?? args.schemaCode,
|
|
881
|
+
customBtns: merged,
|
|
882
|
+
childTableBtns: existing.childTableBtns ?? [],
|
|
883
|
+
// 2.1.5(AI-Platform v2.1.5,客户口径 8.8)把节点按钮拆成审批态/查看态:
|
|
884
|
+
// 非审批态只读 viewCustomBtns/viewChildTableBtns,缺失即空数组
|
|
885
|
+
// (ActionPermissionHandler:91-105)。旧模板没有这三个字段,2.1.5 上
|
|
886
|
+
// 「已办/查看页按钮会全部消失」。只写审批态时,若节点没有任何查看态
|
|
887
|
+
// 配置,就显式声明「查看态等同审批态」(8.6 语义),不动已有独立配置。
|
|
888
|
+
...(existing.viewCustomBtns === undefined && existing.viewChildTableBtns === undefined && existing.viewBtnPermissionEqualApproval === undefined
|
|
889
|
+
? { viewBtnPermissionEqualApproval: true }
|
|
890
|
+
: {}),
|
|
891
|
+
},
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
const body = await mergedTemplateBody(session, args.schemaCode, args.workflowCode, { activities: patches }, true);
|
|
895
|
+
validateWorkflowRender(body, "workflow.setButtons");
|
|
896
|
+
const performed = await wireCall(session, { path: ENDPOINTS.workflowUpdate, method: "POST", body });
|
|
897
|
+
const shouldPublish = args.publish !== false;
|
|
898
|
+
let publishMarked = false;
|
|
899
|
+
// issue 2026-11 F1:发布后必须读**发布面**。此前只读草稿,草稿里空
|
|
900
|
+
// customBtns 容器还在、发布面却被平台归一化成 buttonPermission:null——
|
|
901
|
+
// 回执说「容器内按钮 enabled:false」而真实效果是「容器没了」,调用方据此
|
|
902
|
+
// 判断「仍命中节点权限分支」,把方案引向错误结论。
|
|
903
|
+
let authoritative = null;
|
|
904
|
+
if (shouldPublish) {
|
|
905
|
+
const publishPerformed = await wireCall(session, { path: ENDPOINTS.workflowPublish, method: "POST", body });
|
|
906
|
+
assertWorkflowWriteAccepted(publishPerformed, "workflow.setButtons", args.workflowCode);
|
|
907
|
+
const pub = await wireCall(session, { path: ENDPOINTS.workflowGetPublished, query: { workflowCode: args.workflowCode } });
|
|
908
|
+
authoritative = (pub.data ?? null);
|
|
909
|
+
publishMarked = authoritative !== null && (authoritative.templateType === "PUBLISH" || authoritative.published === true);
|
|
910
|
+
}
|
|
911
|
+
const readback = shouldPublish
|
|
912
|
+
? authoritative
|
|
913
|
+
: (await wireCall(session, { path: ENDPOINTS.workflowGetDraft, query: { workflowCode: args.workflowCode } })).data;
|
|
914
|
+
const nodeButtons = (readback ? readback.activities : draft.activities);
|
|
915
|
+
const rows = Array.isArray(nodeButtons)
|
|
916
|
+
? nodeButtons
|
|
917
|
+
: nodeButtons && typeof nodeButtons === "object"
|
|
918
|
+
? Object.values(nodeButtons)
|
|
919
|
+
: [];
|
|
920
|
+
// 以权威面为准区分三种真实状态:容器不存在 / 容器在但按钮全禁用 / 有启用按钮。
|
|
921
|
+
const state = args.nodes.map((node) => {
|
|
922
|
+
const row = rows.find((entry) => String(entry.activityCode ?? "") === node.activityCode) ?? {};
|
|
923
|
+
const rawPerm = row.buttonPermission;
|
|
924
|
+
const buttonPermissionIsNull = rawPerm === null || rawPerm === undefined;
|
|
925
|
+
const bp = (rawPerm ?? {});
|
|
926
|
+
const btns = Array.isArray(bp.customBtns) ? bp.customBtns : [];
|
|
927
|
+
const enabled = btns.filter((button) => button.enabled === true).map((button) => String(button.code ?? ""));
|
|
928
|
+
const disabled = btns.filter((button) => button.enabled !== true).map((button) => String(button.code ?? ""));
|
|
929
|
+
const containers = Array.isArray(bp.childTableBtns) ? bp.childTableBtns.length : 0;
|
|
930
|
+
return {
|
|
931
|
+
activityCode: node.activityCode,
|
|
932
|
+
enabled,
|
|
933
|
+
disabled,
|
|
934
|
+
buttonPermissionIsNull,
|
|
935
|
+
mode: buttonPermissionIsNull ? "absent" : enabled.length > 0 ? "enabled-in-container" : "disabled-in-container",
|
|
936
|
+
childTableButtonContainerCount: containers,
|
|
937
|
+
};
|
|
938
|
+
});
|
|
939
|
+
const cleared = state.filter((entry) => entry.buttonPermissionIsNull);
|
|
940
|
+
return {
|
|
941
|
+
performed: { errcode: performed.errcode, publishRequested: shouldPublish, nodes: args.nodes.map((node) => node.activityCode) },
|
|
942
|
+
readback: {
|
|
943
|
+
workflowCode: args.workflowCode,
|
|
944
|
+
nodes: state,
|
|
945
|
+
published: publishMarked,
|
|
946
|
+
readbackFace: shouldPublish ? "published" : "draft",
|
|
947
|
+
buttonNames: names,
|
|
948
|
+
buttonPermissionIsNull: cleared.length > 0,
|
|
949
|
+
...(cleared.length > 0 ? { clearedNodes: cleared.map((entry) => entry.activityCode) } : {}),
|
|
950
|
+
note: cleared.length > 0
|
|
951
|
+
? "权威读回显示这些节点的 buttonPermission 为 null(容器被平台清空/归一化,不是容器仍在但按钮均被禁用):节点不再命中节点权限分支,表单按钮会回落到权限组。子表按钮配置也未保留——需要保留时请只传有内容的 buttonCodes,不要传空数组。"
|
|
952
|
+
: "权威读回显示 buttonPermission 容器仍在;未列出的表单按钮为 enabled:false,子表按钮配置保留。表单页只在 enabled:true 的节点显示该按钮。",
|
|
953
|
+
},
|
|
954
|
+
};
|
|
955
|
+
},
|
|
956
|
+
rollback: workflowRollbackSpec("workflow.update"),
|
|
957
|
+
});
|
|
958
|
+
/**
|
|
959
|
+
* F7(0.8.15,探针 I):候选 workflowCode 列表——解析失败时给可复制的核对面。
|
|
960
|
+
* 平台没有「流程全集」端点(WorkflowTemplateController 只有按 schemaCode 的
|
|
961
|
+
* list/getAllWorkflow),所以沿用 workflow.list 的模型索引骨架,并共用同一模型
|
|
962
|
+
* 上限(WORKFLOW_LIST_MODEL_CAP=50,超出标 candidatesTruncated)。差异:本枚举
|
|
963
|
+
* 只做 schemaCode→workflowCode 的点查询(每模型 1 wire getWorkflow,不经
|
|
964
|
+
* isworkflow、不读 get_published 摘要),只服务失败路径,不替代 workflow.list
|
|
965
|
+
* 的完整清单(那里有存在性/发布态/规则绑定计数)。
|
|
966
|
+
*/
|
|
967
|
+
const WORKFLOW_DELETE_CANDIDATE_MODEL_CAP = WORKFLOW_LIST_MODEL_CAP;
|
|
968
|
+
async function availableWorkflowCodes(session) {
|
|
969
|
+
try {
|
|
970
|
+
const scope = await resolveApplicationScope(session, undefined);
|
|
971
|
+
const tree = wireRows((await wireCall(session, { path: ENDPOINTS.applicationTree, query: { appCode: scope.code } })).data);
|
|
972
|
+
const models = flattenTreeRows(tree).filter((row) => row.type === "BizModel" && typeof row.code === "string" && row.code.length > 0);
|
|
973
|
+
const scan = models.slice(0, WORKFLOW_DELETE_CANDIDATE_MODEL_CAP);
|
|
974
|
+
const codes = [];
|
|
975
|
+
for (const model of scan) {
|
|
976
|
+
try {
|
|
977
|
+
const linked = (await wireCall(session, { path: ENDPOINTS.workflowGetBySchema, query: { schemaCode: String(model.code) } })).data;
|
|
978
|
+
const code = linked !== null && typeof linked.workflowCode === "string" && linked.workflowCode.length > 0 ? linked.workflowCode : undefined;
|
|
979
|
+
if (code !== undefined)
|
|
980
|
+
codes.push(code);
|
|
981
|
+
}
|
|
982
|
+
catch {
|
|
983
|
+
// 单模型读失败不中断候选枚举(同 workflow.list 的容错口径)
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
return { codes: [...new Set(codes)], scannedModels: scan.length, truncated: models.length > scan.length };
|
|
987
|
+
}
|
|
988
|
+
catch {
|
|
989
|
+
return { codes: [], scannedModels: 0, truncated: false };
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* F7(0.8.15,探针 I):只给流程码(code / workflowCode 别名)时反查所属模型。
|
|
994
|
+
* 依据:平台 get_published 把 header 的 schemaCode 写回模板
|
|
995
|
+
* (WorkflowTemplateController.getPublished,8.6.26 :618-655 ——
|
|
996
|
+
* `templateModel.setSchemaCode(headerModel.getSchemaCode())`),一次读即可;
|
|
997
|
+
* 模型侧 getWorkflow 只反方向(schemaCode → workflowCode),不能当本用途。
|
|
998
|
+
* 解析不出就零写入拒绝,并列出当前应用可用的 workflowCode + workflow.list 指引。
|
|
999
|
+
*/
|
|
1000
|
+
async function resolveWorkflowDeleteSchema(session, args) {
|
|
1001
|
+
if (!isRequiredAlternativePlaceholder(args.schemaCode))
|
|
1002
|
+
return;
|
|
1003
|
+
let published;
|
|
1004
|
+
try {
|
|
1005
|
+
published = await wireCall(session, { path: ENDPOINTS.workflowGetPublished, query: { workflowCode: args.code } });
|
|
1006
|
+
}
|
|
1007
|
+
catch (error) {
|
|
1008
|
+
if (!isWorkflowAbsent(error))
|
|
1009
|
+
throw error;
|
|
1010
|
+
}
|
|
1011
|
+
const data = (published?.data ?? null);
|
|
1012
|
+
const schemaCode = data !== null && typeof data.schemaCode === "string" && data.schemaCode.length > 0 ? data.schemaCode : undefined;
|
|
1013
|
+
if (schemaCode !== undefined) {
|
|
1014
|
+
args.schemaCode = schemaCode;
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
const candidates = await availableWorkflowCodes(session);
|
|
1018
|
+
throw new ToolRefusalError({
|
|
1019
|
+
status: "refused",
|
|
1020
|
+
blocker: "workflow-not-found",
|
|
1021
|
+
workflowCode: args.code,
|
|
1022
|
+
candidates: candidates.codes,
|
|
1023
|
+
scannedModels: candidates.scannedModels,
|
|
1024
|
+
...(candidates.truncated ? { candidatesTruncated: true } : {}),
|
|
1025
|
+
nextCommand: `omc call workflow.list --args '{}'`,
|
|
1026
|
+
message: `workflow.delete 只给了流程码 ${args.code},但流程读面解析不出它所属的模型(workflow/get_published ${args.code} 缺席或未带回 schemaCode)——无法定位要删的流程,本次零写入。` +
|
|
1027
|
+
(candidates.codes.length > 0
|
|
1028
|
+
? `当前应用可用的 workflowCode:${candidates.codes.join("、")}。`
|
|
1029
|
+
: `当前应用未扫到可用 workflowCode(scannedModels=${candidates.scannedModels})。`) +
|
|
1030
|
+
`核对流程码后重发(也可同时显式给 schemaCode);流程清单用 nextCommand:omc call workflow.list(按模型索引,可传 applicationCode)。`,
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
writeTool({
|
|
1034
|
+
tools,
|
|
1035
|
+
name: "workflow.delete",
|
|
1036
|
+
search: { intents: ["删除流程", "删掉审批流", "删除流程模板"] },
|
|
1037
|
+
lane: WORKFLOW_LANE,
|
|
1038
|
+
scope: WORKFLOW_TOOLS["workflow.delete"].scope,
|
|
1039
|
+
description: WORKFLOW_TOOLS["workflow.delete"].description,
|
|
1040
|
+
inputSchema: {
|
|
1041
|
+
schemaCode: z.string().min(1).describe("模型 code;只给 code/workflowCode 时可省略——工具用 workflow/get_published 一次读反查所属模型"),
|
|
1042
|
+
code: z.string().min(1).describe("流程编码——本参数名是 code"),
|
|
1043
|
+
unbindListviews: z
|
|
1044
|
+
.boolean()
|
|
1045
|
+
.optional()
|
|
1046
|
+
.describe("先解绑列表视图再删流程:true 时对每个绑定了本流程的列表视图,只移除其 add 动作里指向本流程的那一条(保留 delete/import/export/editowner 等其它动作),再删流程;任一步解绑失败即停、不删流程。**会改动视图配置(移除该视图 add 动作的平台关联),必须显式确认才做。** 默认 false 只删流程,遇 303024 仍拒绝并给 nextCommand"),
|
|
1047
|
+
},
|
|
1048
|
+
// F7(0.8.8):dry-run 与真写共用同一份只读扫描——预览列出会被解绑的视图,
|
|
1049
|
+
// 真写在任何写 wire 之前也先跑这里。两者都不写。
|
|
1050
|
+
writeLint: async (session, args) => {
|
|
1051
|
+
await resolveWorkflowDeleteSchema(session, args);
|
|
1052
|
+
if (args.unbindListviews !== true) {
|
|
1053
|
+
return {
|
|
1054
|
+
wouldChange: true,
|
|
1055
|
+
summary: `即将删除流程 ${args.code}(未请求解绑列表视图)`,
|
|
1056
|
+
listviewUnbind: {
|
|
1057
|
+
requested: false,
|
|
1058
|
+
note: "未传 unbindListviews;不改任何视图配置。若平台回 303024,重发时带 unbindListviews:true 让本工具先解绑。",
|
|
1059
|
+
},
|
|
1060
|
+
};
|
|
1061
|
+
}
|
|
1062
|
+
const scan = await scanListviewsBoundToWorkflow(session, args.schemaCode, args.code);
|
|
1063
|
+
return {
|
|
1064
|
+
wouldChange: true,
|
|
1065
|
+
summary: scan.bound.length > 0
|
|
1066
|
+
? `先解绑 ${scan.bound.length} 个列表视图,再删除流程 ${args.code}`
|
|
1067
|
+
: `未发现绑定本流程的列表视图;将直接删除流程 ${args.code}`,
|
|
1068
|
+
listviewUnbind: {
|
|
1069
|
+
requested: true,
|
|
1070
|
+
readable: scan.readable,
|
|
1071
|
+
...(scan.bound.length > 0
|
|
1072
|
+
? {
|
|
1073
|
+
views: scan.bound.map(({ code, name, fieldCodes }) => ({
|
|
1074
|
+
code,
|
|
1075
|
+
name,
|
|
1076
|
+
...(fieldCodes.length > 0 ? { fieldCodes } : {}),
|
|
1077
|
+
action: "移除指向本流程的 add 动作(add 的语义就是发起本流程,整条会消失,不是只删关联);其余动作原样保留。需要恢复新增按钮时用 listview.configure {actions:[], defaultActions:true} 重建(defaultActions 需要 actions 意图才生效)。",
|
|
1078
|
+
})),
|
|
1079
|
+
}
|
|
1080
|
+
: {}),
|
|
1081
|
+
...(scan.unreadableViews.length > 0 ? { unreadableViews: scan.unreadableViews } : {}),
|
|
1082
|
+
then: "workflow.delete",
|
|
1083
|
+
...(scan.readable
|
|
1084
|
+
? {}
|
|
1085
|
+
: { note: "视图清单读取失败:真写仍会先读;读不到绑定时只删流程,平台 303024 会挡住,不误放行。" }),
|
|
1086
|
+
},
|
|
1087
|
+
};
|
|
1088
|
+
},
|
|
1089
|
+
execute: async (session, args) => {
|
|
1090
|
+
await resolveWorkflowDeleteSchema(session, args);
|
|
1091
|
+
const steps = [];
|
|
1092
|
+
// Opt-in unbind (F7): the workflow.publish side effect binds every list
|
|
1093
|
+
// view's `add` action to this workflow, and workflow.delete then answers
|
|
1094
|
+
// 303024 until those associations are gone. Unbind FIRST, and stop
|
|
1095
|
+
// before the delete if any view cannot be cleared (never half-delete).
|
|
1096
|
+
if (args.unbindListviews === true) {
|
|
1097
|
+
const scan = await scanListviewsBoundToWorkflow(session, args.schemaCode, args.code);
|
|
1098
|
+
const configure = siblings.find((tool) => tool.name === "listview.configure");
|
|
1099
|
+
if (scan.bound.length > 0 && configure?.writeExecute === undefined)
|
|
1100
|
+
throw new ToolRefusalError({
|
|
1101
|
+
status: "refused",
|
|
1102
|
+
blocker: "workflow-unbind-step-unavailable",
|
|
1103
|
+
workflowCode: args.code,
|
|
1104
|
+
message: "workflow.delete 需要 listview.configure 来解绑视图,但它未注册写执行;零写入停止",
|
|
1105
|
+
});
|
|
1106
|
+
const boundViews = new Map();
|
|
1107
|
+
for (const view of scan.bound)
|
|
1108
|
+
if (!boundViews.has(view.code))
|
|
1109
|
+
boundViews.set(view.code, view);
|
|
1110
|
+
for (const view of boundViews.values()) {
|
|
1111
|
+
const fieldCodes = view.fieldCodes.length > 0 ? view.fieldCodes : ["createdTime", "creater", "name", "sequenceNo"];
|
|
1112
|
+
// F8(0.8.16):只移除指向本流程的 add 行,其余动作原样回写。
|
|
1113
|
+
const remainingActions = actionsWithoutWorkflowBinding(view.actions, args.code, args.schemaCode);
|
|
1114
|
+
try {
|
|
1115
|
+
const outcome = await configure.writeExecute(session, {
|
|
1116
|
+
schemaCode: args.schemaCode,
|
|
1117
|
+
code: view.code,
|
|
1118
|
+
fieldCodes,
|
|
1119
|
+
actions: remainingActions,
|
|
1120
|
+
replaceActions: true,
|
|
1121
|
+
});
|
|
1122
|
+
if ("status" in outcome)
|
|
1123
|
+
throw new ToolRefusalError({
|
|
1124
|
+
status: "refused",
|
|
1125
|
+
blocker: "workflow-unbind-step-stopped",
|
|
1126
|
+
workflowCode: args.code,
|
|
1127
|
+
viewCode: view.code,
|
|
1128
|
+
message: `解绑视图 ${view.code} 中途停止(${String(outcome.envelope?.message ?? outcome.status)})`,
|
|
1129
|
+
});
|
|
1130
|
+
steps.push({
|
|
1131
|
+
step: "listview.configure",
|
|
1132
|
+
status: "ok",
|
|
1133
|
+
viewCode: view.code,
|
|
1134
|
+
viewName: view.name,
|
|
1135
|
+
actions: "selective-unbind",
|
|
1136
|
+
removedActions: view.actions
|
|
1137
|
+
.filter((action) => isWorkflowAddBinding(action, args.code, args.schemaCode))
|
|
1138
|
+
.map((action) => ({
|
|
1139
|
+
actionCode: action.actionCode ?? null,
|
|
1140
|
+
associationCode: action.associationCode ?? null,
|
|
1141
|
+
})),
|
|
1142
|
+
keptActions: remainingActions.map((action) => action.actionCode),
|
|
1143
|
+
replaceActions: true,
|
|
1144
|
+
note: "add 动作已移除,平台读面不会自动补回(也不会重新绑定本流程);需要恢复新增按钮时用 listview.configure defaultActions:true 重建内置动作。",
|
|
1145
|
+
readback: outcome.readback,
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
catch (error) {
|
|
1149
|
+
const cause = error instanceof Error ? error.message : String(error);
|
|
1150
|
+
throw new ToolRefusalError({
|
|
1151
|
+
status: "refused",
|
|
1152
|
+
blocker: "workflow-unbind-failed",
|
|
1153
|
+
workflowCode: args.code,
|
|
1154
|
+
schemaCode: args.schemaCode,
|
|
1155
|
+
viewCode: view.code,
|
|
1156
|
+
steps,
|
|
1157
|
+
nextCommand: `omc call listview.configure --env <env> --args '${JSON.stringify({ schemaCode: args.schemaCode, code: view.code, fieldCodes, actions: remainingActions, replaceActions: true })}'`,
|
|
1158
|
+
message: `解绑列表视图 ${view.code} 失败,已停止:**流程 ${args.code} 未删除**(不半删)。原因:${cause}。` +
|
|
1159
|
+
`按 nextCommand 修好该视图后重发 workflow.delete(仍带 unbindListviews:true);已成功解绑的视图在 steps 里。`,
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
let performed;
|
|
1165
|
+
try {
|
|
1166
|
+
performed = await wireCall(session, { path: ENDPOINTS.workflowDelete, method: "POST", query: { workflowCode: args.code } });
|
|
1167
|
+
}
|
|
1168
|
+
catch (error) {
|
|
1169
|
+
// 402508 流程实例已存在 — the platform refuses on purpose. Previously it
|
|
1170
|
+
// arrived as a bare wire code, so the caller's next move was to delete the
|
|
1171
|
+
// MODEL instead (which cascades the template away and leaves orphan todos
|
|
1172
|
+
// pointing at nothing — r14's 8× 50000). Name the order.
|
|
1173
|
+
if (error instanceof WireError && error.kind === "business" && error.errcode === 402508) {
|
|
1174
|
+
const pending = await countPendingWorkItems(session, args.code);
|
|
1175
|
+
throw new ToolRefusalError({
|
|
1176
|
+
status: "refused",
|
|
1177
|
+
blocker: "workflow-has-instances",
|
|
1178
|
+
workflowCode: args.code,
|
|
1179
|
+
...(pending > 0 ? { pendingWorkItems: pending } : {}),
|
|
1180
|
+
nextCommand: `omc call workitem.list --args '${JSON.stringify({ workflowCode: args.code })}'`,
|
|
1181
|
+
message: `流程 ${args.code} 还有流程实例,平台拒绝删除(402508)。**不要改用 model.delete 绕过**——那会把流程模板级联删掉,` +
|
|
1182
|
+
`留下指向空模板的待办,而平台全局待办搜索会给每条待办解析模板,**一条缺失就整页 NPE(50000),所有用户的待办列表一起坏掉**(r14 实测 8 连击,需维护者清库)。` +
|
|
1183
|
+
`正确顺序:① 先完结/清理实例的待办(workitem.list --workflowCode ${args.code} 看还有哪些在办);② 再 workflow.delete;③ 最后才 model.delete。`,
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
// 303024 列表绑定了流程 — workflow.create auto-binds the default list
|
|
1187
|
+
// view; delete refuses until that WORKFLOW association is removed
|
|
1188
|
+
// (r30d F12/F13; r31 F48). Name the bound view + a pasteable unbind
|
|
1189
|
+
// command that already carries real fieldCodes (no listview.get dig).
|
|
1190
|
+
if (error instanceof WireError && error.kind === "business" && error.errcode === 303024) {
|
|
1191
|
+
const bound = await findListviewsBoundToWorkflow(session, args.schemaCode, args.code);
|
|
1192
|
+
const primary = bound[0];
|
|
1193
|
+
const viewCode = primary?.code ?? args.schemaCode;
|
|
1194
|
+
const fieldCodes = primary?.fieldCodes?.length
|
|
1195
|
+
? primary.fieldCodes
|
|
1196
|
+
: ["createdTime", "creater", "name", "sequenceNo"];
|
|
1197
|
+
// Live-proven unbind (sandbox-r31f 2026-11-05): empty actions +
|
|
1198
|
+
// replaceActions:true clears the WORKFLOW add binding; platform then
|
|
1199
|
+
// re-injects non-workflow defaults. Prefer this over rewriting ADD→BIZSHEET
|
|
1200
|
+
// so the pasted command needs no action surgery.
|
|
1201
|
+
const detachArgs = {
|
|
1202
|
+
schemaCode: args.schemaCode,
|
|
1203
|
+
code: viewCode,
|
|
1204
|
+
fieldCodes,
|
|
1205
|
+
actions: [],
|
|
1206
|
+
replaceActions: true,
|
|
1207
|
+
};
|
|
1208
|
+
const detachExample = `omc call listview.configure --env <env> --args '${JSON.stringify(detachArgs)}'`;
|
|
1209
|
+
// F8(0.8.16 复核):安全路径优先——workflow.delete 带 unbindListviews
|
|
1210
|
+
// 只移除本流程的 add 绑定,保留 delete/import/export/editowner 等其它
|
|
1211
|
+
// 动作;listview.configure actions:[] 是全清次选,必须标明代价。
|
|
1212
|
+
const safeUnbindDeleteCommand = `omc call workflow.delete --env <env> --args '${JSON.stringify({
|
|
1213
|
+
schemaCode: args.schemaCode,
|
|
1214
|
+
code: args.code,
|
|
1215
|
+
unbindListviews: true,
|
|
1216
|
+
})}'`;
|
|
1217
|
+
throw new ToolRefusalError({
|
|
1218
|
+
status: "refused",
|
|
1219
|
+
blocker: "workflow-bound-to-listview",
|
|
1220
|
+
errcode: 303024,
|
|
1221
|
+
workflowCode: args.code,
|
|
1222
|
+
schemaCode: args.schemaCode,
|
|
1223
|
+
boundListviews: bound.map(({ code, name, actionCode, associationCode, fieldCodes: cols }) => ({
|
|
1224
|
+
code,
|
|
1225
|
+
name,
|
|
1226
|
+
actionCode,
|
|
1227
|
+
associationCode,
|
|
1228
|
+
...(cols.length > 0 ? { fieldCodes: cols } : {}),
|
|
1229
|
+
})),
|
|
1230
|
+
nextCommand: safeUnbindDeleteCommand,
|
|
1231
|
+
unbindCommand: detachExample,
|
|
1232
|
+
unbindCommandNote: "次选(只在你想手工改视图时用):listview.configure 清 actions:[] + replaceActions:true 会**顺带清掉该视图的其它动作**(add/delete/import/export/editowner 等),不是只解本流程绑定;只想解本流程绑定请用 nextCommand(workflow.delete 带 unbindListviews:true)。",
|
|
1233
|
+
message: `流程 ${args.code} 仍被列表视图绑定(303024「列表绑定了流程」)。` +
|
|
1234
|
+
(bound.length > 0
|
|
1235
|
+
? `绑在:${bound.map((view) => `${view.code}(${view.name})action=${view.actionCode ?? "?"}`).join("、")}。`
|
|
1236
|
+
: `默认视图多半是 ${args.schemaCode}(workflow.create 会自动绑)。`) +
|
|
1237
|
+
`先解绑再删:nextCommand 是 workflow.delete 带 unbindListviews:true(只移除本流程的 add 绑定,保留 delete/import/export/editowner 等其它动作)。` +
|
|
1238
|
+
`次选 unbindCommand(listview.configure actions:[] + replaceActions:true + 现有 fieldCodes)会**清掉该视图其它动作**,只在你想手工改视图时用。` +
|
|
1239
|
+
(args.unbindListviews === true
|
|
1240
|
+
? `本次已带 unbindListviews:true,但仍有绑定未被清掉(见 boundListviews / unreadableViews);可重发 nextCommand,若仍 303024 用 unbindCommand 逐视图手工处理。`
|
|
1241
|
+
: "") +
|
|
1242
|
+
`整体清理也可用 omc model-purge --code ${args.schemaCode}(级联带走流程模板与视图)。`,
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
throw error;
|
|
1246
|
+
}
|
|
1247
|
+
const header = await wireCall(session, { path: ENDPOINTS.workflowGetHeader, query: { workflowCode: args.code } }).catch(() => ({ data: null }));
|
|
1248
|
+
const absent = header.data === null || header.data === undefined;
|
|
1249
|
+
if (args.unbindListviews === true) {
|
|
1250
|
+
steps.push({ step: "workflow.delete", status: "ok", workflowCode: args.code, errcode: performed.errcode, absent });
|
|
1251
|
+
}
|
|
1252
|
+
return {
|
|
1253
|
+
performed: { errcode: performed.errcode },
|
|
1254
|
+
readback: {
|
|
1255
|
+
workflowCode: args.code,
|
|
1256
|
+
absent,
|
|
1257
|
+
...(args.unbindListviews === true
|
|
1258
|
+
? {
|
|
1259
|
+
listviewUnbind: {
|
|
1260
|
+
requested: true,
|
|
1261
|
+
unboundViews: steps.filter((step) => step.step === "listview.configure").map((step) => step.viewCode),
|
|
1262
|
+
note: "只移除了指向本流程的 add 绑定;平台读面不会自动补回。需要恢复新增按钮时用 listview.configure defaultActions:true 重建内置动作。",
|
|
1263
|
+
},
|
|
1264
|
+
}
|
|
1265
|
+
: {}),
|
|
1266
|
+
},
|
|
1267
|
+
...(steps.length > 0 ? { steps } : {}),
|
|
1268
|
+
};
|
|
1269
|
+
},
|
|
1270
|
+
rollback: workflowRollbackSpec("workflow.delete"),
|
|
1271
|
+
});
|
|
1272
|
+
// ---- high-level greenfield orchestration (round 10 ergonomics) --------
|
|
1273
|
+
// The survey's write-face gap: a first workflow took create → update →
|
|
1274
|
+
// publish (+ bindRule for rules), 3–4 separate CLI calls. configure_workflow
|
|
1275
|
+
// runs the SAME atomic steps through each tool's own writeExecute, so the
|
|
1276
|
+
// gates/readbacks are identical, in one governed package.
|
|
1277
|
+
registerPackageTool(tools, {
|
|
1278
|
+
name: "configure_workflow",
|
|
1279
|
+
search: { intents: ["配置工作流"] },
|
|
1280
|
+
lane: WORKFLOW_LANE,
|
|
1281
|
+
scope: WORKFLOW_TOOLS["configure_workflow"].scope,
|
|
1282
|
+
description: WORKFLOW_TOOLS["configure_workflow"].description,
|
|
1283
|
+
inputSchema: {
|
|
1284
|
+
schemaCode: z.string().min(1),
|
|
1285
|
+
name: z.string().min(1),
|
|
1286
|
+
code: z.string().min(1).describe("workflowCode"),
|
|
1287
|
+
template: workflowTemplateArg.describe("完整模板(activities + routes);工具内部合并到草稿,含条件分支写法见 workflow.update"),
|
|
1288
|
+
bindRules: z
|
|
1289
|
+
.array(z.object({ handler: z.string().optional(), ruleCodes: z.array(z.string().min(1)).min(1) }))
|
|
1290
|
+
.optional()
|
|
1291
|
+
.describe("可选:发布后绑定业务规则;每项 {handler?,ruleCodes[]},handler 取 start|cancel|activate|end(缺省 end)"),
|
|
1292
|
+
},
|
|
1293
|
+
// r62a-F2(P1-6):条件枚举校验进 preflight——semanticGate 在 dry-run 与真写
|
|
1294
|
+
// 都跑(r29c F1b 同门原则),GE/GT= 这类直觉缩写此前 dry-run 假绿、真写才拒。
|
|
1295
|
+
preflight: (args) => {
|
|
1296
|
+
validateWorkflowRouteConditions((args.template ?? {}), "configure_workflow");
|
|
1297
|
+
},
|
|
1298
|
+
plan: (args) => {
|
|
1299
|
+
const actions = [
|
|
1300
|
+
{ tool: "workflow.create", args: { schemaCode: args.schemaCode, name: args.name, code: args.code } },
|
|
1301
|
+
{ tool: "workflow.update", args: { schemaCode: args.schemaCode, code: args.code, template: args.template } },
|
|
1302
|
+
{ tool: "workflow.publish", args: { schemaCode: args.schemaCode, code: args.code } },
|
|
1303
|
+
];
|
|
1304
|
+
for (const binding of args.bindRules ?? [])
|
|
1305
|
+
actions.push({ tool: "workflow.bindRule", args: { schemaCode: args.schemaCode, workflowCode: args.code, ruleCodes: binding.ruleCodes, ...(binding.handler ? { handler: binding.handler } : {}) } });
|
|
1306
|
+
return { summary: writeSummary("configure_workflow", args, undefined, "plan"), actions };
|
|
1307
|
+
},
|
|
1308
|
+
execute: async (session, args) => {
|
|
1309
|
+
const steps = [];
|
|
1310
|
+
const run = async (toolName, toolArgs) => {
|
|
1311
|
+
const target = siblings.find((tool) => tool.name === toolName);
|
|
1312
|
+
if (!target?.writeExecute)
|
|
1313
|
+
throw new ToolRefusalError({ status: "refused", blocker: "configure-workflow-step-unavailable", message: `configure_workflow 需要 ${toolName},但它未注册写执行` });
|
|
1314
|
+
try {
|
|
1315
|
+
const outcome = await target.writeExecute(session, toolArgs);
|
|
1316
|
+
if ("status" in outcome)
|
|
1317
|
+
throw new ToolRefusalError({ status: "refused", blocker: "configure-workflow-inner-stop", message: `步骤 ${toolName} 返回中途停止:${String(outcome.envelope?.message ?? outcome.status)}` });
|
|
1318
|
+
steps.push({ step: toolName, ...outcome });
|
|
1319
|
+
return outcome.readback;
|
|
1320
|
+
}
|
|
1321
|
+
catch (error) {
|
|
1322
|
+
const envelope = error instanceof ToolRefusalError ? { ...error.payload } : error instanceof WireError ? { blocker: `wire-${error.kind}`, errcode: error.errcode, message: error.message } : { blocker: "configure-workflow-step-failed", message: String(error) };
|
|
1323
|
+
return { __failed: true, tool: toolName, index: steps.length, envelope };
|
|
1324
|
+
}
|
|
1325
|
+
};
|
|
1326
|
+
for (const [toolName, toolArgs] of [
|
|
1327
|
+
["workflow.create", { schemaCode: args.schemaCode, name: args.name, code: args.code }],
|
|
1328
|
+
["workflow.update", { schemaCode: args.schemaCode, code: args.code, template: args.template }],
|
|
1329
|
+
["workflow.publish", { schemaCode: args.schemaCode, code: args.code }],
|
|
1330
|
+
]) {
|
|
1331
|
+
const readback = await run(toolName, toolArgs);
|
|
1332
|
+
if (readback && readback.__failed)
|
|
1333
|
+
return { status: "refused", steps, failedStep: { index: steps.length, tool: toolName }, envelope: readback.envelope };
|
|
1334
|
+
}
|
|
1335
|
+
for (const binding of args.bindRules ?? []) {
|
|
1336
|
+
const readback = await run("workflow.bindRule", { schemaCode: args.schemaCode, workflowCode: args.code, ruleCodes: binding.ruleCodes, ...(binding.handler ? { handler: binding.handler } : {}) });
|
|
1337
|
+
if (readback && readback.__failed)
|
|
1338
|
+
return { status: "refused", steps, failedStep: { index: steps.length, tool: "workflow.bindRule" }, envelope: readback.envelope };
|
|
1339
|
+
}
|
|
1340
|
+
return { steps, readback: { workflowCode: args.code, published: true, boundHandlers: (args.bindRules ?? []).map((binding) => binding.handler ?? "end") } };
|
|
1341
|
+
},
|
|
1342
|
+
summarize: (args, _outcome, phase) => writeSummary("configure_workflow", args, undefined, phase),
|
|
1343
|
+
});
|
|
1344
|
+
/**
|
|
1345
|
+
* F10(0.8.6):workflow.publish 的隐式绑定回执。平台首次发布后会把该模型
|
|
1346
|
+
* 各列表视图 `add` 动作的 relativeType 改成 WORKFLOW、relativeCode 改成流程码
|
|
1347
|
+
* (8.6.26 WorkflowTemplateController.publish:805 → updateBizQueryAddAction:830-846;
|
|
1348
|
+
* 2.1.5 publish:695-711 → :741-761)。列表面只回 code/name,故需 1 次 list +
|
|
1349
|
+
* 每视图 1 次 get;读失败时 readable=false,回执不得谎称「无绑定」。
|
|
1350
|
+
*/
|
|
1351
|
+
async function listviewAddBindings(session, schemaCode, workflowCode) {
|
|
1352
|
+
const bound = [];
|
|
1353
|
+
let readable = false;
|
|
1354
|
+
try {
|
|
1355
|
+
const listed = wireRows((await wireCall(session, { path: ENDPOINTS.listQueryList, query: { schemaCode, clientType: "PC" } })).data);
|
|
1356
|
+
readable = true;
|
|
1357
|
+
for (const row of listed) {
|
|
1358
|
+
const code = String(row.code ?? "");
|
|
1359
|
+
if (!code)
|
|
1360
|
+
continue;
|
|
1361
|
+
try {
|
|
1362
|
+
const got = await wireCall(session, { path: ENDPOINTS.listQueryGet, query: { schemaCode, code, clientType: "PC" } });
|
|
1363
|
+
const model = (got.data ?? null);
|
|
1364
|
+
const actions = model !== null && Array.isArray(model.queryActions) ? model.queryActions : [];
|
|
1365
|
+
const hit = actions.some((action) => {
|
|
1366
|
+
if (String(action.actionCode ?? "") !== "add")
|
|
1367
|
+
return false;
|
|
1368
|
+
const association = action.queryActionRelativeType ?? action.associationType;
|
|
1369
|
+
const associationCode = String(action.relativeCode ?? action.associationCode ?? "");
|
|
1370
|
+
const isWorkflow = association === 1 ||
|
|
1371
|
+
association === "1" ||
|
|
1372
|
+
String(association ?? "").toUpperCase() === "WORKFLOW";
|
|
1373
|
+
return isWorkflow && (associationCode === workflowCode || associationCode === "");
|
|
1374
|
+
});
|
|
1375
|
+
if (hit) {
|
|
1376
|
+
// Reuse the SAME query/get response for the unbind command's
|
|
1377
|
+
// fieldCodes — no extra wire round-trip at publish time.
|
|
1378
|
+
const fieldCodes = (model !== null && Array.isArray(model.queryColumns) ? model.queryColumns : [])
|
|
1379
|
+
.map((column) => String(column.propertyCode ?? ""))
|
|
1380
|
+
.filter((column) => column.length > 0);
|
|
1381
|
+
bound.push({ code, actionCode: "add", fieldCodes });
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
catch {
|
|
1385
|
+
readable = false;
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
catch {
|
|
1390
|
+
readable = false;
|
|
1391
|
+
}
|
|
1392
|
+
return { bound, readable };
|
|
1393
|
+
}
|
|
1394
|
+
/**
|
|
1395
|
+
* Which list views bind this workflow, plus whether the READ succeeded.
|
|
1396
|
+
* `readable:false` means "could not list views" (NOT "none bound") — callers
|
|
1397
|
+
* must fail open to the platform's 303024 rather than deleting blind
|
|
1398
|
+
* (F7 0.8.8). Bindings are only ever created on the `add` action by
|
|
1399
|
+
* workflow.publish → updateBizQueryAddAction (8.6.26
|
|
1400
|
+
* WorkflowTemplateController.java:791,818-846; 2.1.5 :695-711,741-761).
|
|
1401
|
+
*
|
|
1402
|
+
* 0.8.16 F8: `actions` carries the view's decoded action rows (the same
|
|
1403
|
+
* `query/get` response), so workflow.delete can remove ONLY the workflow-bound
|
|
1404
|
+
* `add` row and write the remaining set back — delete/import/export/editowner
|
|
1405
|
+
* and caller-authored actions survive the unbind.
|
|
1406
|
+
*/
|
|
1407
|
+
async function scanListviewsBoundToWorkflow(session, schemaCode, workflowCode) {
|
|
1408
|
+
const bound = [];
|
|
1409
|
+
const unreadableViews = [];
|
|
1410
|
+
let listed;
|
|
1411
|
+
try {
|
|
1412
|
+
listed = wireRows((await wireCall(session, { path: ENDPOINTS.listQueryList, query: { schemaCode, clientType: "PC" } })).data);
|
|
1413
|
+
}
|
|
1414
|
+
catch {
|
|
1415
|
+
return { bound, readable: false, unreadableViews };
|
|
1416
|
+
}
|
|
1417
|
+
for (const row of listed) {
|
|
1418
|
+
const code = String(row.code ?? "");
|
|
1419
|
+
if (!code)
|
|
1420
|
+
continue;
|
|
1421
|
+
try {
|
|
1422
|
+
const got = await wireCall(session, { path: ENDPOINTS.listQueryGet, query: { schemaCode, code, clientType: "PC" } });
|
|
1423
|
+
const model = (got.data ?? null);
|
|
1424
|
+
if (!model)
|
|
1425
|
+
continue;
|
|
1426
|
+
const actions = Array.isArray(model.queryActions) ? model.queryActions : [];
|
|
1427
|
+
const fieldCodes = (Array.isArray(model.queryColumns) ? model.queryColumns : [])
|
|
1428
|
+
.map((column) => String(column.propertyCode ?? ""))
|
|
1429
|
+
.filter(Boolean);
|
|
1430
|
+
const decodedActions = actions.map(decodeActionRow);
|
|
1431
|
+
for (const action of actions) {
|
|
1432
|
+
const association = action.associationType ?? action.queryActionRelativeType;
|
|
1433
|
+
const associationCode = String(action.associationCode ?? action.relativeCode ?? "");
|
|
1434
|
+
const isWorkflow = association === 1 ||
|
|
1435
|
+
association === "1" ||
|
|
1436
|
+
association === "WORKFLOW" ||
|
|
1437
|
+
String(association).toUpperCase() === "WORKFLOW";
|
|
1438
|
+
if (!isWorkflow)
|
|
1439
|
+
continue;
|
|
1440
|
+
if (associationCode && associationCode !== workflowCode && associationCode !== schemaCode)
|
|
1441
|
+
continue;
|
|
1442
|
+
bound.push({
|
|
1443
|
+
code,
|
|
1444
|
+
name: String(row.name ?? model.name ?? code),
|
|
1445
|
+
actionCode: action.actionCode === undefined || action.actionCode === null ? null : String(action.actionCode),
|
|
1446
|
+
associationCode: associationCode || null,
|
|
1447
|
+
fieldCodes,
|
|
1448
|
+
actions: decodedActions,
|
|
1449
|
+
});
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
catch {
|
|
1453
|
+
// one view unreadable — keep scanning, but remember it: it may still
|
|
1454
|
+
// carry the binding, so an opted-in delete must not claim "clean".
|
|
1455
|
+
unreadableViews.push(code);
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
return { bound, readable: true, unreadableViews };
|
|
1459
|
+
}
|
|
1460
|
+
/** Best-effort: which list views still bind this workflow (303024 recovery). */
|
|
1461
|
+
async function findListviewsBoundToWorkflow(session, schemaCode, workflowCode) {
|
|
1462
|
+
return (await scanListviewsBoundToWorkflow(session, schemaCode, workflowCode)).bound;
|
|
1463
|
+
}
|
|
1464
|
+
/**
|
|
1465
|
+
* F8(0.8.16): is this the workflow-bound `add` row? The platform only ever
|
|
1466
|
+
* binds the `add` action to a workflow (publish → updateBizQueryAddAction),
|
|
1467
|
+
* so that single row is what must go; every other action stays untouched.
|
|
1468
|
+
*/
|
|
1469
|
+
const isWorkflowAddBinding = (action, workflowCode, schemaCode) => {
|
|
1470
|
+
if (String(action.actionCode ?? "") !== "add")
|
|
1471
|
+
return false;
|
|
1472
|
+
if (String(action.associationType ?? "").toUpperCase() !== "WORKFLOW")
|
|
1473
|
+
return false;
|
|
1474
|
+
const associationCode = String(action.associationCode ?? "");
|
|
1475
|
+
return associationCode === workflowCode || associationCode === schemaCode || associationCode === "";
|
|
1476
|
+
};
|
|
1477
|
+
/**
|
|
1478
|
+
* Build the configure `actions` payload that keeps every action except the
|
|
1479
|
+
* workflow-bound `add` row. Decoded read rows are converted back to the
|
|
1480
|
+
* configure arg shape (nulls dropped — optional zod fields reject null) and
|
|
1481
|
+
* renumbered, because query/update assigns `sortKey` by array position.
|
|
1482
|
+
*/
|
|
1483
|
+
const actionsWithoutWorkflowBinding = (actions, workflowCode, schemaCode) => actions
|
|
1484
|
+
.filter((action) => !isWorkflowAddBinding(action, workflowCode, schemaCode))
|
|
1485
|
+
.map((action, index) => {
|
|
1486
|
+
const row = {
|
|
1487
|
+
actionCode: String(action.actionCode ?? ""),
|
|
1488
|
+
queryActionType: String(action.queryActionType ?? ""),
|
|
1489
|
+
sortKey: index + 1,
|
|
1490
|
+
};
|
|
1491
|
+
for (const key of ["name", "icon", "systemAction", "serviceCode", "serviceMethod", "customService", "associationCode", "associationType"]) {
|
|
1492
|
+
const value = action[key];
|
|
1493
|
+
if (value !== null && value !== undefined)
|
|
1494
|
+
row[key] = value;
|
|
1495
|
+
}
|
|
1496
|
+
return row;
|
|
1497
|
+
});
|
|
1498
|
+
}
|
|
1499
|
+
//# sourceMappingURL=lifecycle-write.js.map
|