@stalfh233/omc-cli 0.6.100 → 0.8.0
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/conformance/README.md +267 -0
- package/conformance/frontend-behavior-probe.mjs +1986 -0
- package/conformance/frontend-scenarios/calc-visibility.json +22 -0
- package/conformance/frontend-scenarios/form-buttons.json +19 -0
- package/conformance/frontend-scenarios/list-buttons.json +28 -0
- package/conformance/frontend-scenarios/onlinejs.json +19 -0
- package/coverage/m1-coverage-manifest-v1.json +88 -2
- package/dist/capability-overview.js +16 -4
- package/dist/cli-stdout.js +4 -0
- package/dist/cli.js +190 -7
- package/dist/contract-resources.js +2 -0
- package/dist/coverage-registry.js +4 -0
- package/dist/coverage.js +16 -2
- package/dist/endpoints.js +65 -0
- package/dist/environment-policy.js +15 -1
- package/dist/field-change.js +9 -2
- package/dist/field-families.js +27 -6
- package/dist/governed-execution.js +18 -12
- package/dist/human-summary.js +8 -0
- package/dist/intent/capabilities/field.js +6 -0
- package/dist/lanes/environment.js +3 -0
- package/dist/lanes/field-contract.js +117 -6
- package/dist/lanes/file-contract.js +69 -0
- package/dist/lanes/file-coverage.js +16 -0
- package/dist/lanes/file.js +257 -0
- package/dist/lanes/lane-ids.js +1 -0
- package/dist/lanes/list-view-contract.js +3 -3
- package/dist/lanes/list-view-shapes.js +56 -0
- package/dist/lanes/list-view.js +40 -5
- package/dist/lanes/meta.js +4 -3
- package/dist/lanes/model.js +8 -4
- package/dist/lanes/org-query-contract.js +62 -0
- package/dist/lanes/org-query-coverage.js +27 -0
- package/dist/lanes/org-query.js +610 -0
- package/dist/lanes/organization.js +44 -11
- package/dist/lanes/runtime-data.js +228 -59
- package/dist/lanes/workflow-contract.js +100 -1
- package/dist/lanes/workflow-coverage.js +13 -0
- package/dist/lanes/workflow.js +615 -15
- package/dist/package.js +3 -1
- package/dist/read-shapes.js +3 -3
- package/dist/recipes/runtime-data.js +8 -6
- package/dist/refusal-guidance.js +1 -1
- package/dist/rule-support.js +15 -17
- package/dist/session.js +16 -1
- package/dist/tool-types.js +15 -1
- package/dist/tools.js +7 -0
- package/dist/version-family-gaps.js +8 -1
- package/dist/version-partition.js +633 -0
- package/dist/wire.js +8 -2
- package/dist/write.js +11 -2
- package/package.json +6 -4
- package/skills/omc-capabilities.md +8 -1
package/dist/lanes/workflow.js
CHANGED
|
@@ -16,6 +16,7 @@ import { WORKFLOW_EVENT_HANDLER_FIELDS, WORKFLOW_NODE_EVENT_HANDLER_FIELDS, WORK
|
|
|
16
16
|
import { PLATFORM_TRIGGER_RULE_CODES } from "./rule-graph.js";
|
|
17
17
|
import { executeRuleEnableWrite } from "./rule-lifecycle.js";
|
|
18
18
|
import { PLATFORM_ADMIN_START_BYPASS, resolvePermissionActor } from "../identity.js";
|
|
19
|
+
import { decodeSessionAccount } from "../session-account.js";
|
|
19
20
|
import { applicationResolutionOf, flattenTreeRows, resolveApplicationScope } from "../support.js";
|
|
20
21
|
const WORKFLOW_LANE = WORKFLOW_LANE_CONTRACT.lane;
|
|
21
22
|
const WORKFLOW_TOOLS = WORKFLOW_LANE_CONTRACT.tools;
|
|
@@ -795,12 +796,26 @@ export function rejectToStartCancelWarnings(template) {
|
|
|
795
796
|
function participantReferenceWarnings(template) {
|
|
796
797
|
const activities = Array.isArray(template.activities) ? template.activities : [];
|
|
797
798
|
const warnings = [];
|
|
799
|
+
// 第一个 PARTICIPANT 是「填写」节点(发起人),平台允许 participant 为空并自动补
|
|
800
|
+
// {Originator};之后的空 participant 才是危险信号。t248 1.1.25/1.1.30 实测:
|
|
801
|
+
// workflow.create 自动草稿的审批节点 participant 恒为空,平台把待办静默派给
|
|
802
|
+
// 发起人(自审自批),而旧实现直接 continue,publish 不告警。
|
|
803
|
+
const firstParticipantCode = String(activities.find((activity) => String(activity.activityType ?? "") === "PARTICIPANT")?.activityCode ?? "");
|
|
798
804
|
for (const activity of activities) {
|
|
799
805
|
if (String(activity.activityType ?? "") !== "PARTICIPANT")
|
|
800
806
|
continue;
|
|
801
807
|
const raw = activity.participant;
|
|
802
|
-
|
|
803
|
-
|
|
808
|
+
const activityCode = String(activity.activityCode ?? "");
|
|
809
|
+
if (raw === undefined || raw === null || String(raw).trim().length === 0) {
|
|
810
|
+
if (activityCode === firstParticipantCode)
|
|
811
|
+
continue; // 填写节点:平台补 {Originator}
|
|
812
|
+
warnings.push({
|
|
813
|
+
activityCode,
|
|
814
|
+
participant: "",
|
|
815
|
+
warning: `节点 ${activityCode} 的 participant 为空:平台会按发起人处理(待办派给发起人,形成自审自批),不是「稍后由平台填写」。用 workflow.setButtons/update 给该节点填真实参与者({Originator}、角色对象数组或 FindUserByRole(...));确认自审自批符合业务意图则显式写 {Originator}。`,
|
|
816
|
+
});
|
|
817
|
+
continue;
|
|
818
|
+
}
|
|
804
819
|
const participant = String(raw).trim();
|
|
805
820
|
// r4-training 2026-10-20: two function names that show up in read-back /
|
|
806
821
|
// seeded templates are NOT registered at runtime in AI-Platform v1.1.25 —
|
|
@@ -4713,11 +4728,19 @@ export function registerWorkflowLane(tools) {
|
|
|
4713
4728
|
// 造/推测试数据用;真实流程与权限验证必须走 data.submit 正常链(换过审批人/
|
|
4714
4729
|
// 跳过节点的实例,权限语义已变)。端点形状全部真机实证(详见 r64 TASK-RESULT)。
|
|
4715
4730
|
// ──────────────────────────────────────────────────────────────────────────
|
|
4716
|
-
/**
|
|
4731
|
+
/**
|
|
4732
|
+
* 把 participants(userId 或姓名)解析成 userId 列表;姓名走 user/search。
|
|
4733
|
+
*
|
|
4734
|
+
* 审计 H2(2026-11-24):无精确同名时**绝不**回退到模糊命中的第一条——旧代码
|
|
4735
|
+
* `rows.find(…精确…) ?? rows[0]` 会把「张伟」的审批人换成「张伟华」,静默改错人。
|
|
4736
|
+
* 现在只有 name 完全相等(或平台 userId/username 完全相等)才算命中;否则进
|
|
4737
|
+
* `unresolved` 并把最多 5 个候选(candidates)带回拒绝回执,由调用方决定下一步。
|
|
4738
|
+
*/
|
|
4717
4739
|
const resolveOpsParticipants = async (session, participants) => {
|
|
4718
4740
|
const ids = [];
|
|
4719
4741
|
const resolved = [];
|
|
4720
4742
|
const unresolved = [];
|
|
4743
|
+
const candidates = [];
|
|
4721
4744
|
for (const entry of participants) {
|
|
4722
4745
|
if (/^[0-9a-f]{16,}$/i.test(entry)) {
|
|
4723
4746
|
ids.push(entry);
|
|
@@ -4726,16 +4749,19 @@ export function registerWorkflowLane(tools) {
|
|
|
4726
4749
|
}
|
|
4727
4750
|
const data = (await wireCall(session, { path: ENDPOINTS.organizationUserSearch, method: "POST", body: { wd: entry, page: 0, size: 5 } })).data;
|
|
4728
4751
|
const rows = Array.isArray(data?.content) ? data.content : [];
|
|
4729
|
-
const exact = rows.find((row) => String(row.name ?? "") === entry) ??
|
|
4752
|
+
const exact = rows.find((row) => String(row.name ?? "") === entry || String(row.username ?? "") === entry || String(row.userId ?? "") === entry);
|
|
4730
4753
|
if (exact && typeof exact.id === "string") {
|
|
4731
4754
|
ids.push(exact.id);
|
|
4732
4755
|
resolved.push({ name: String(exact.name ?? entry), id: exact.id });
|
|
4756
|
+
continue;
|
|
4733
4757
|
}
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4758
|
+
unresolved.push(entry);
|
|
4759
|
+
candidates.push({
|
|
4760
|
+
entry,
|
|
4761
|
+
matches: rows.slice(0, 5).map((row) => ({ id: wireString(row.id) ?? "", name: wireString(row.name), username: wireString(row.username) })),
|
|
4762
|
+
});
|
|
4737
4763
|
}
|
|
4738
|
-
return { ids, resolved, unresolved };
|
|
4764
|
+
return { ids, resolved, unresolved, candidates };
|
|
4739
4765
|
};
|
|
4740
4766
|
const opsApproval = (activityCode, comment) => ({
|
|
4741
4767
|
activityCode,
|
|
@@ -4757,13 +4783,13 @@ export function registerWorkflowLane(tools) {
|
|
|
4757
4783
|
writeTool({
|
|
4758
4784
|
tools,
|
|
4759
4785
|
name: "workflow.transfer",
|
|
4760
|
-
search: { intents: ["换审批人", "
|
|
4786
|
+
search: { intents: ["换审批人", "改审批人", "调整审批人", "审批人换成", "替换节点参与者"] },
|
|
4761
4787
|
lane: WORKFLOW_LANE,
|
|
4762
4788
|
scope: "runtime workflow admin adjust participant",
|
|
4763
|
-
description: "
|
|
4789
|
+
description: "流程运维·**替换节点参与者**(换当前审批人;`POST /api/api/runtime/workflow/workflow_operation`,operationType=ADJUST_PARTICIPANT;approval 是**对象** {activityCode,commonSet,deleted,resources,content},传字符串 10009;adjust_workItem_participators 是加签面不是换人)。**这是运维换人,不是「转办」**——把某个人的待办交给他自己处理用 `workflow.forward`(OpenAPI 审批动作),把单据发给他人知会用 `workflow.circulate`。回执带 `newWorkItems`:transfer 的 wire 回执只有布尔值,工具按 实例+目标审批人 补查 list_workitems 解析新 workItemId(原 id 换人后失效,重提报 405022)。**测试提速工具**:换过审批人的实例权限语义已变,不能用于真实流程/权限验证——正常审批链走 data.submit。实例必须在途且有激活节点;默认取第一个激活节点,也可显式 activityCode。",
|
|
4764
4790
|
inputSchema: {
|
|
4765
4791
|
workflowInstanceId: z.string().min(1).describe("流程实例 id(data.submit 读回 / workflow.instanceActivity)"),
|
|
4766
|
-
participants: z.array(z.string().min(1)).min(1).describe("目标审批人:userId
|
|
4792
|
+
participants: z.array(z.string().min(1)).min(1).describe("目标审批人:userId 或姓名(混收;姓名必须与 organization/user/search 的 name/username **精确相等**,无精确命中即拒绝并给 candidates——不做模糊回退)"),
|
|
4767
4793
|
activityCode: z.string().optional().describe("目标节点 code;省略=当前第一个激活节点"),
|
|
4768
4794
|
comment: z.string().optional().describe("运维意见(进审批记录)"),
|
|
4769
4795
|
},
|
|
@@ -4780,9 +4806,17 @@ export function registerWorkflowLane(tools) {
|
|
|
4780
4806
|
const target = args.activityCode !== undefined ? active.find((row) => row.activityCode === args.activityCode) : active[0];
|
|
4781
4807
|
if (target === undefined)
|
|
4782
4808
|
throw new ToolRefusalError({ status: "refused", blocker: "workflow-activity-not-active", activityCode: args.activityCode, activeActivities: active.map((row) => row.activityCode), message: `节点 ${args.activityCode} 不是当前激活节点;激活中的是 ${active.map((row) => row.activityCode).join("、")}` });
|
|
4783
|
-
const { ids, resolved, unresolved } = await resolveOpsParticipants(session, args.participants);
|
|
4809
|
+
const { ids, resolved, unresolved, candidates } = await resolveOpsParticipants(session, args.participants);
|
|
4784
4810
|
if (unresolved.length > 0 || ids.length === 0)
|
|
4785
|
-
throw new ToolRefusalError({
|
|
4811
|
+
throw new ToolRefusalError({
|
|
4812
|
+
status: "refused",
|
|
4813
|
+
blocker: "workflow-participant-unresolved",
|
|
4814
|
+
unresolved,
|
|
4815
|
+
candidates,
|
|
4816
|
+
resolved,
|
|
4817
|
+
message: `participants 里 ${unresolved.join("、")} 在 organization/user/search 里**没有精确同名/同 username 的用户**——不会拿模糊命中的第一条去换人(那会静默换错审批人)。按 candidates 里的 id 直接传 userId 可跳过解析。`,
|
|
4818
|
+
nextCommand: `omc call org.user.search --args '{"wd":"${unresolved[0] ?? "<姓名>"}"}'`,
|
|
4819
|
+
});
|
|
4786
4820
|
const currentIds = new Set(target.participants.map((person) => person.id));
|
|
4787
4821
|
if (ids.every((id) => currentIds.has(id)))
|
|
4788
4822
|
throw new ToolRefusalError({ status: "refused", blocker: "workflow-transfer-noop", message: `目标审批人与当前完全相同(${[...currentIds].join("、")})——换成同一批人是 no-op,平台可能拒绝;要真实换人请给不同的用户` });
|
|
@@ -4865,9 +4899,15 @@ export function registerWorkflowLane(tools) {
|
|
|
4865
4899
|
const activeBefore = rows.filter((row) => Number(row.status) === 1).map((row) => wireString(row.activityCode));
|
|
4866
4900
|
let participantIds;
|
|
4867
4901
|
if (args.participants !== undefined) {
|
|
4868
|
-
const { ids, unresolved } = await resolveOpsParticipants(session, args.participants);
|
|
4902
|
+
const { ids, unresolved, candidates } = await resolveOpsParticipants(session, args.participants);
|
|
4869
4903
|
if (unresolved.length > 0)
|
|
4870
|
-
throw new ToolRefusalError({
|
|
4904
|
+
throw new ToolRefusalError({
|
|
4905
|
+
status: "refused",
|
|
4906
|
+
blocker: "workflow-participant-unresolved",
|
|
4907
|
+
unresolved,
|
|
4908
|
+
candidates,
|
|
4909
|
+
message: `participants 里 ${unresolved.join("、")} 在 organization/user/search 里没有精确同名用户——不做模糊回退;按 candidates 的 id 直接传 userId。`,
|
|
4910
|
+
});
|
|
4871
4911
|
participantIds = ids;
|
|
4872
4912
|
}
|
|
4873
4913
|
const activeRow = rows.find((row) => Number(row.status) === 1);
|
|
@@ -4937,6 +4977,566 @@ export function registerWorkflowLane(tools) {
|
|
|
4937
4977
|
};
|
|
4938
4978
|
},
|
|
4939
4979
|
});
|
|
4980
|
+
// ──────────────────────────────────────────────────────────────────────────
|
|
4981
|
+
// 审批动作(驳回/转办/加签/协办/传阅/撤回/作废 + 可驳回节点)
|
|
4982
|
+
//
|
|
4983
|
+
// **默认通道 = 会话面**:门户 UI 自己就走 WorkflowInstanceController
|
|
4984
|
+
// `/api/runtime/workflow/*`(+ context-path /api ⇒ `/api/api/...`),登录
|
|
4985
|
+
// token 的 authorities 是 AUTH_SYSTEM_MANAGE,USER,直接可用。
|
|
4986
|
+
//
|
|
4987
|
+
// **可选通道 = OpenAPI v2**(`channel:"openapi"`):`/openapi/**` 在 launcher
|
|
4988
|
+
// 的 ResourceConfig 里是 hasAuthority("openapi"),只有开放接口客户端
|
|
4989
|
+
// (base_security_client.authorities=openapi,如种子 xclient /
|
|
4990
|
+
// client_credentials)满足;门户登录 token 没有该 authority,AccessDenied
|
|
4991
|
+
// 会以 HTTP 401 返回(真机 2026-11-24:errcode 401「权限不够,请联系管理员」)。
|
|
4992
|
+
// 该通道还要 `userId` 头(8.6.26 @RequestHeader String userId),由登录 JWT
|
|
4993
|
+
// 的 user_id 补。
|
|
4994
|
+
//
|
|
4995
|
+
// 两版端点形状逐字一致(8.6.26 / AI-Platform 2.1.5):
|
|
4996
|
+
// session POST /reject_workItem, /forward_workItem, /adjust_workItem_participators,
|
|
4997
|
+
// /assist_workItem, /circulate_workItem;GET /revoke_workitem,
|
|
4998
|
+
// /abort_instance, /list_reject_activities
|
|
4999
|
+
// openapi POST /reject_workitem, /forward_workitem, /adjust_workitem,
|
|
5000
|
+
// /assist_workitem, /circulate_workitem;GET /revoke_workitem,
|
|
5001
|
+
// /abort_instance, /list_reject_activities
|
|
5002
|
+
// ──────────────────────────────────────────────────────────────────────────
|
|
5003
|
+
/** 审批动作通道。默认 session(登录 token);openapi 需开放接口客户端。 */
|
|
5004
|
+
const APPROVAL_CHANNELS = ["session", "openapi"];
|
|
5005
|
+
const approvalChannelArg = z
|
|
5006
|
+
.enum(APPROVAL_CHANNELS)
|
|
5007
|
+
.optional()
|
|
5008
|
+
.describe("鉴权通道:session(默认,门户登录 token → /api/api/runtime/workflow/*)| openapi(开放接口客户端 → /api/openapi/v2/runtime/workflow/*,要求 client authorities 含 openapi 且需要 userId 头;门户登录 token 走这里会 401)。");
|
|
5009
|
+
const approvalChannel = (args) => args.channel ?? "session";
|
|
5010
|
+
/**
|
|
5011
|
+
* OpenAPI v2 的 `userId` 头:当前登录用户 id。
|
|
5012
|
+
*
|
|
5013
|
+
* 首选 0-wire 路径:登录 JWT 的 `user_id`(AuthUtils/CustomAccessTokenConverter
|
|
5014
|
+
* 认的就是这个 claim,单据 creater 也记它)。token 不是 JWT(个别部署发不透明
|
|
5015
|
+
* token)时才退到 `resolvePermissionActor`(user/search 反查,+1 wire),两条
|
|
5016
|
+
* 都拿不到就 fail closed——绝不猜一个 id 去当操作人。
|
|
5017
|
+
*/
|
|
5018
|
+
const openApiUserHeaders = async (session) => {
|
|
5019
|
+
const authorization = session.headers().Authorization ?? "";
|
|
5020
|
+
const token = authorization.replace(/^Bearer\s+/i, "");
|
|
5021
|
+
const account = decodeSessionAccount(token);
|
|
5022
|
+
if (!("unavailableReason" in account))
|
|
5023
|
+
return { userId: account.id };
|
|
5024
|
+
const actor = await resolvePermissionActor(session);
|
|
5025
|
+
if (actor.userId !== null && actor.userId.length > 0)
|
|
5026
|
+
return { userId: actor.userId };
|
|
5027
|
+
throw new ToolRefusalError({
|
|
5028
|
+
status: "refused",
|
|
5029
|
+
blocker: "workflow-openapi-user-id-unavailable",
|
|
5030
|
+
reason: ("unavailableReason" in account ? account.unavailableReason : "user-search-unresolved"),
|
|
5031
|
+
message: "OpenAPI v2 审批动作要求 userId 请求头:当前 token 解不出 user_id,user/search 也反查不到当前账号。" +
|
|
5032
|
+
"重新 omc env login 取新 token;本工具不会猜一个 id 去当操作人。",
|
|
5033
|
+
});
|
|
5034
|
+
};
|
|
5035
|
+
/**
|
|
5036
|
+
* 审批动作统一回执判定。六个动作(reject/forward/adjust/assist/circulate/abort)
|
|
5037
|
+
* 平台用 `getOkResponseResult(Boolean, ErrorCode)` 回包——失败也是 errcode 0,
|
|
5038
|
+
* 只有 errmsg 不同(「…失败」),所以成败只能看 data。这一层把
|
|
5039
|
+
* `errcode 0 + data:false` 转成 refused,避免「看似成功」。
|
|
5040
|
+
*/
|
|
5041
|
+
const approvalActionReceipt = (result, tool, args) => {
|
|
5042
|
+
const applied = result.data === true;
|
|
5043
|
+
if (!applied)
|
|
5044
|
+
throw new ToolRefusalError({
|
|
5045
|
+
status: "refused",
|
|
5046
|
+
blocker: "workflow-approval-action-not-applied",
|
|
5047
|
+
tool,
|
|
5048
|
+
platformErrcode: 0,
|
|
5049
|
+
platformErrmsg: result.errmsg ?? null,
|
|
5050
|
+
args,
|
|
5051
|
+
message: `平台回了 errcode 0 但 data:false(errmsg: ${result.errmsg ?? "(空)"})——这是平台的「动作未生效」,不是成功。` +
|
|
5052
|
+
"常见原因:workItemId 已被处理/取消(405022)、操作人不是该待办持有人、目标节点不可驳回。用 workflow.instanceActivity 与 workitem.list 核对当前状态后重取 workItemId。",
|
|
5053
|
+
nextCommand: typeof args.workflowInstanceId === "string"
|
|
5054
|
+
? `omc call workflow.instanceActivity --args '{"workflowInstanceId":"${args.workflowInstanceId}"}'`
|
|
5055
|
+
: "omc call workitem.list --args '{}'",
|
|
5056
|
+
});
|
|
5057
|
+
return { applied };
|
|
5058
|
+
};
|
|
5059
|
+
/** OpenAPI v2 单条待办动作的公共请求体(forward/adjust/assist/circulate 同形 Model)。 */
|
|
5060
|
+
const workItemParticipantBody = (args) => ({
|
|
5061
|
+
workItemId: args.workItemId,
|
|
5062
|
+
participantors: [...args.participantors],
|
|
5063
|
+
...(args.comment === undefined ? {} : { comment: args.comment }),
|
|
5064
|
+
});
|
|
5065
|
+
/**
|
|
5066
|
+
* 会话面单条待办动作的请求体(WorkItemSendToVO)。
|
|
5067
|
+
*
|
|
5068
|
+
* `workflowInstanceId` 不是可选装饰:WorkflowAspect.addUserFavoriteAspect
|
|
5069
|
+
* (8.6.26 WorkflowAspect.java:346-388)对 forward/assist/circulate/adjust
|
|
5070
|
+
* 调 addUserFavoriteModelByInstanceId(vo.getWorkflowInstanceId()) →
|
|
5071
|
+
* WorkflowInstanceFacadeImpl.getWorkflowInstance(null) 抛 WORKFLOW_INS_EMPTY。
|
|
5072
|
+
*/
|
|
5073
|
+
const sessionWorkItemBody = (args) => ({
|
|
5074
|
+
workflowInstanceId: args.workflowInstanceId,
|
|
5075
|
+
workItemId: args.workItemId,
|
|
5076
|
+
participantors: [...args.participantors],
|
|
5077
|
+
...(args.activityCode === undefined ? {} : { activityCode: args.activityCode }),
|
|
5078
|
+
...(args.comment === undefined ? {} : { comment: args.comment }),
|
|
5079
|
+
});
|
|
5080
|
+
/**
|
|
5081
|
+
* 会话面驳回体(WorkItemRejectVO extends WorkItemDataVO)。
|
|
5082
|
+
*
|
|
5083
|
+
* 与 OpenAPI v2 的 RejectWorkItemModel 有两处形状差异(模式适配,不拒绝):
|
|
5084
|
+
* 1. 意见是 `approval`(BizCommentModel) 而不是顶层 `comment`——门户
|
|
5085
|
+
* 34987 的 reject() 就是 buildSaveParams().approval(content 装意见);
|
|
5086
|
+
* 2. `data` 要自己组成 `bizObject`:平台按实例 schemaCode/bizObjectId 补全
|
|
5087
|
+
* (portal 也一样),所以仅当调用方给了 data 才多一次
|
|
5088
|
+
* getBizObjectByWfInstanceId 解析。
|
|
5089
|
+
* `formType:"1"` = 流程表单(WorkItemDataVO.FORM_TYPE_WF),与门户一致。
|
|
5090
|
+
*/
|
|
5091
|
+
const sessionRejectBody = async (session, args) => {
|
|
5092
|
+
let bizObject;
|
|
5093
|
+
if (args.data !== undefined) {
|
|
5094
|
+
const resolved = await resolveBizObjectIdByInstance(session, args.workflowInstanceId);
|
|
5095
|
+
if (resolved.schemaCode === null || resolved.bizObjectId === null)
|
|
5096
|
+
throw new ToolRefusalError({
|
|
5097
|
+
status: "refused",
|
|
5098
|
+
blocker: "workflow-reject-bizobject-unresolved",
|
|
5099
|
+
workflowInstanceId: args.workflowInstanceId,
|
|
5100
|
+
message: "带 data 的驳回要组 bizObject,但 getBizObjectByWfInstanceId 没解析出 schemaCode/bizObjectId(实例不存在/无访问权)。" +
|
|
5101
|
+
"不带 data 驳回(只退回节点)可省略该参数;要保存表单数据请先用 data.get 核对实例。",
|
|
5102
|
+
nextCommand: `omc call workflow.instanceActivity --args '{"workflowInstanceId":"${args.workflowInstanceId}"}'`,
|
|
5103
|
+
});
|
|
5104
|
+
bizObject = { schemaCode: resolved.schemaCode, id: resolved.bizObjectId, data: args.data };
|
|
5105
|
+
}
|
|
5106
|
+
return {
|
|
5107
|
+
workflowInstanceId: args.workflowInstanceId,
|
|
5108
|
+
workItemId: args.workItemId,
|
|
5109
|
+
rejectToActivityCode: args.rejectToActivityCode,
|
|
5110
|
+
formType: "1",
|
|
5111
|
+
...(args.submitToReject === undefined ? {} : { submitToReject: args.submitToReject }),
|
|
5112
|
+
...(args.comment === undefined
|
|
5113
|
+
? {}
|
|
5114
|
+
: { approval: { workItemId: args.workItemId, workflowInstanceId: args.workflowInstanceId, content: args.comment } }),
|
|
5115
|
+
...(bizObject === undefined ? {} : { bizObject }),
|
|
5116
|
+
};
|
|
5117
|
+
};
|
|
5118
|
+
// 这四个动作拒绝空 participantors:平台侧 validateParticipantors 会抛
|
|
5119
|
+
// ParamException,本工具的数组 schema 已 min(1),这里再兜一层(域内空串)。
|
|
5120
|
+
const assertParticipantIds = (participantors, tool) => {
|
|
5121
|
+
const ids = participantors.map((entry) => entry.trim()).filter((entry) => entry.length > 0);
|
|
5122
|
+
if (ids.length === 0 || ids.length !== participantors.length)
|
|
5123
|
+
throw new ToolRefusalError({
|
|
5124
|
+
status: "refused",
|
|
5125
|
+
blocker: "workflow-participant-ids-invalid",
|
|
5126
|
+
tool,
|
|
5127
|
+
participantors,
|
|
5128
|
+
message: "participantors 必须是平台用户 id 列表(不能为空、不能有空串);姓名先经 org.user.search 解析成 id。",
|
|
5129
|
+
});
|
|
5130
|
+
};
|
|
5131
|
+
/** 转办只认第一个接收人(平台 participantors.get(0)),多人必须在 wire 之前拒绝。 */
|
|
5132
|
+
const assertSingleForwardParticipant = (args) => {
|
|
5133
|
+
if (args.participants.length > 1)
|
|
5134
|
+
throw new ToolRefusalError({
|
|
5135
|
+
status: "refused",
|
|
5136
|
+
blocker: "workflow-forward-single-participant",
|
|
5137
|
+
participants: args.participants,
|
|
5138
|
+
message: "转办只支持一个接收人:平台实现是 participantors.get(0)(WorkflowInstanceRuntimeController.handleForwardWorkItem:627),第 2 个起会被静默丢弃。" +
|
|
5139
|
+
"要给多人看单据用 workflow.circulate(传阅);要让多人共同审批用 workflow.adjust(加签)。",
|
|
5140
|
+
nextCommand: `omc call workflow.adjust --args '{"workItemId":"${args.workItemId}","participants":["<userId>","<userId>"]}'`,
|
|
5141
|
+
});
|
|
5142
|
+
};
|
|
5143
|
+
writeTool({
|
|
5144
|
+
tools,
|
|
5145
|
+
name: "workflow.reject",
|
|
5146
|
+
search: { intents: ["驳回", "驳回待办", "退回上一节点", "驳回到指定节点", "审批驳回"] },
|
|
5147
|
+
lane: WORKFLOW_LANE,
|
|
5148
|
+
scope: WORKFLOW_TOOLS["workflow.reject"].scope,
|
|
5149
|
+
description: WORKFLOW_TOOLS["workflow.reject"].description,
|
|
5150
|
+
inputSchema: {
|
|
5151
|
+
workflowInstanceId: z.string().min(1).describe("流程实例 id(workitem.list 的 instanceId;会话面 WorkflowAspect.addUserFavoriteModelByInstanceId 必需,缺了平台报流程实例不存在)"),
|
|
5152
|
+
workItemId: z.string().min(1).describe("待办任务 id(workitem.list 的 workItemId;一次只能驳回一条)"),
|
|
5153
|
+
rejectToActivityCode: z.string().min(1).describe("驳回目标节点 code,必须是可驳回节点(先 workflow.rejectActivities 查)"),
|
|
5154
|
+
submitToReject: z.boolean().optional().describe("重新提交时是否直接跳到驳回节点(**省略=false**:平台 WorkItemRejectVO.getSubmitToReject 对 null 回 false,WorkItemRejectVO.java:21-30)"),
|
|
5155
|
+
comment: z.string().optional().describe("审批意见(会话面写进 approval.content,OpenAPI 面写进 comment;两边都落审批记录 result=REJECT)"),
|
|
5156
|
+
data: z.record(z.string(), z.unknown()).optional().describe("随驳回一并保存的业务数据(部分字段即可;会话面自动解析实例的 schemaCode/bizObjectId 组 bizObject)"),
|
|
5157
|
+
channel: approvalChannelArg,
|
|
5158
|
+
},
|
|
5159
|
+
execute: async (session, args) => {
|
|
5160
|
+
const channel = approvalChannel(args);
|
|
5161
|
+
const result = channel === "openapi"
|
|
5162
|
+
? await wireCall(session, {
|
|
5163
|
+
path: ENDPOINTS.openApiWorkflowReject,
|
|
5164
|
+
method: "POST",
|
|
5165
|
+
headers: await openApiUserHeaders(session),
|
|
5166
|
+
body: {
|
|
5167
|
+
workItemId: args.workItemId,
|
|
5168
|
+
rejectToActivityCode: args.rejectToActivityCode,
|
|
5169
|
+
...(args.submitToReject === undefined ? {} : { submitToReject: args.submitToReject }),
|
|
5170
|
+
...(args.comment === undefined ? {} : { comment: args.comment }),
|
|
5171
|
+
...(args.data === undefined ? {} : { data: args.data }),
|
|
5172
|
+
},
|
|
5173
|
+
})
|
|
5174
|
+
: await wireCall(session, {
|
|
5175
|
+
path: ENDPOINTS.workflowReject,
|
|
5176
|
+
method: "POST",
|
|
5177
|
+
body: await sessionRejectBody(session, args),
|
|
5178
|
+
});
|
|
5179
|
+
const { applied } = approvalActionReceipt(result, "workflow.reject", args);
|
|
5180
|
+
return {
|
|
5181
|
+
performed: {
|
|
5182
|
+
channel,
|
|
5183
|
+
errcode: result.errcode,
|
|
5184
|
+
platformErrmsg: result.errmsg,
|
|
5185
|
+
workItemId: args.workItemId,
|
|
5186
|
+
rejectToActivityCode: args.rejectToActivityCode,
|
|
5187
|
+
},
|
|
5188
|
+
readback: {
|
|
5189
|
+
applied,
|
|
5190
|
+
// 平台回执只有一个布尔值,没有新待办 id——退回后的待办要按实例查。
|
|
5191
|
+
note: "驳回已受理:退回节点的新待办用 workflow.instanceActivity / workitem.list 查(平台回执不含新 workItemId;待办在原审批人名下时用 participant 参数)。",
|
|
5192
|
+
nextCommand: `omc call workitem.list --args '{"participant":"<审批人 userId>"}'`,
|
|
5193
|
+
},
|
|
5194
|
+
};
|
|
5195
|
+
},
|
|
5196
|
+
});
|
|
5197
|
+
writeTool({
|
|
5198
|
+
tools,
|
|
5199
|
+
name: "workflow.forward",
|
|
5200
|
+
search: { intents: ["转办", "转发待办", "把待办转给别人", "处理人转交"] },
|
|
5201
|
+
lane: WORKFLOW_LANE,
|
|
5202
|
+
scope: WORKFLOW_TOOLS["workflow.forward"].scope,
|
|
5203
|
+
description: WORKFLOW_TOOLS["workflow.forward"].description,
|
|
5204
|
+
inputSchema: {
|
|
5205
|
+
workflowInstanceId: z.string().min(1).describe("流程实例 id(workitem.list 的 instanceId;会话面 WorkflowAspect 必需)"),
|
|
5206
|
+
workItemId: z.string().min(1).describe("待办任务 id(必须是当前登录人名下的待办)"),
|
|
5207
|
+
participants: z
|
|
5208
|
+
.array(z.string().min(1))
|
|
5209
|
+
.min(1)
|
|
5210
|
+
.describe("接收人 userId 列表——**平台只取第一个**(handleForwardWorkItem 用 participantors.get(0)),传多个本工具直接拒绝"),
|
|
5211
|
+
comment: z.string().optional().describe("转办意见(写入审批记录)"),
|
|
5212
|
+
channel: approvalChannelArg,
|
|
5213
|
+
},
|
|
5214
|
+
// 纯参数门:dry-run 与真写同答案(多人转办=静默丢弃,必须在 wire 之前拒)。
|
|
5215
|
+
preflight: (args) => {
|
|
5216
|
+
assertSingleForwardParticipant(args);
|
|
5217
|
+
assertParticipantIds(args.participants, "workflow.forward");
|
|
5218
|
+
},
|
|
5219
|
+
execute: async (session, args) => {
|
|
5220
|
+
assertSingleForwardParticipant(args);
|
|
5221
|
+
assertParticipantIds(args.participants, "workflow.forward");
|
|
5222
|
+
const channel = approvalChannel(args);
|
|
5223
|
+
const result = channel === "openapi"
|
|
5224
|
+
? await wireCall(session, {
|
|
5225
|
+
path: ENDPOINTS.openApiWorkflowForward,
|
|
5226
|
+
method: "POST",
|
|
5227
|
+
headers: await openApiUserHeaders(session),
|
|
5228
|
+
body: workItemParticipantBody({ workItemId: args.workItemId, participantors: args.participants, ...(args.comment === undefined ? {} : { comment: args.comment }) }),
|
|
5229
|
+
})
|
|
5230
|
+
: await wireCall(session, {
|
|
5231
|
+
path: ENDPOINTS.workflowForward,
|
|
5232
|
+
method: "POST",
|
|
5233
|
+
body: sessionWorkItemBody({ workflowInstanceId: args.workflowInstanceId, workItemId: args.workItemId, participantors: args.participants, ...(args.comment === undefined ? {} : { comment: args.comment }) }),
|
|
5234
|
+
});
|
|
5235
|
+
const { applied } = approvalActionReceipt(result, "workflow.forward", args);
|
|
5236
|
+
return {
|
|
5237
|
+
performed: { channel, errcode: result.errcode, platformErrmsg: result.errmsg, workItemId: args.workItemId, participantor: args.participants[0] },
|
|
5238
|
+
readback: {
|
|
5239
|
+
applied,
|
|
5240
|
+
note: "转办后原 workItemId 失效(新待办在接收人名下):用 workitem.list --participant <接收人 userId> 取新 id。",
|
|
5241
|
+
nextCommand: `omc call workitem.list --args '{"participant":"${args.participants[0]}"}'`,
|
|
5242
|
+
},
|
|
5243
|
+
};
|
|
5244
|
+
},
|
|
5245
|
+
});
|
|
5246
|
+
writeTool({
|
|
5247
|
+
tools,
|
|
5248
|
+
name: "workflow.adjust",
|
|
5249
|
+
search: { intents: ["加签", "加审批人", "追加审批人", "多一个人审批"] },
|
|
5250
|
+
lane: WORKFLOW_LANE,
|
|
5251
|
+
scope: WORKFLOW_TOOLS["workflow.adjust"].scope,
|
|
5252
|
+
description: WORKFLOW_TOOLS["workflow.adjust"].description,
|
|
5253
|
+
inputSchema: {
|
|
5254
|
+
workflowInstanceId: z.string().min(1).describe("流程实例 id(workitem.list 的 instanceId;会话面 WorkflowAspect 必需)"),
|
|
5255
|
+
workItemId: z.string().min(1).describe("待办任务 id(加签在它所在节点上)"),
|
|
5256
|
+
participants: z.array(z.string().min(1)).min(1).describe("加签人 userId 列表(可多个;原审批人待办保留)"),
|
|
5257
|
+
comment: z.string().optional().describe("加签意见(写入审批记录)"),
|
|
5258
|
+
channel: approvalChannelArg,
|
|
5259
|
+
},
|
|
5260
|
+
preflight: (args) => assertParticipantIds(args.participants, "workflow.adjust"),
|
|
5261
|
+
execute: async (session, args) => {
|
|
5262
|
+
assertParticipantIds(args.participants, "workflow.adjust");
|
|
5263
|
+
const channel = approvalChannel(args);
|
|
5264
|
+
const result = channel === "openapi"
|
|
5265
|
+
? await wireCall(session, {
|
|
5266
|
+
path: ENDPOINTS.openApiWorkflowAdjust,
|
|
5267
|
+
method: "POST",
|
|
5268
|
+
headers: await openApiUserHeaders(session),
|
|
5269
|
+
body: workItemParticipantBody({ workItemId: args.workItemId, participantors: args.participants, ...(args.comment === undefined ? {} : { comment: args.comment }) }),
|
|
5270
|
+
})
|
|
5271
|
+
: await wireCall(session, {
|
|
5272
|
+
path: ENDPOINTS.workflowAdjustWorkItemParticipators,
|
|
5273
|
+
method: "POST",
|
|
5274
|
+
body: sessionWorkItemBody({ workflowInstanceId: args.workflowInstanceId, workItemId: args.workItemId, participantors: args.participants, ...(args.comment === undefined ? {} : { comment: args.comment }) }),
|
|
5275
|
+
});
|
|
5276
|
+
const { applied } = approvalActionReceipt(result, "workflow.adjust", args);
|
|
5277
|
+
return {
|
|
5278
|
+
performed: { channel, errcode: result.errcode, platformErrmsg: result.errmsg, workItemId: args.workItemId, participantors: args.participants },
|
|
5279
|
+
readback: {
|
|
5280
|
+
applied,
|
|
5281
|
+
note: "加签后该节点同时存在多个待办(原审批人 + 加签人);加签人不能是自己(平台 402512「不允许加签给自己」)。",
|
|
5282
|
+
},
|
|
5283
|
+
};
|
|
5284
|
+
},
|
|
5285
|
+
});
|
|
5286
|
+
writeTool({
|
|
5287
|
+
tools,
|
|
5288
|
+
name: "workflow.assist",
|
|
5289
|
+
search: { intents: ["协办", "找人协办", "协同处理", "协助审批"] },
|
|
5290
|
+
lane: WORKFLOW_LANE,
|
|
5291
|
+
scope: WORKFLOW_TOOLS["workflow.assist"].scope,
|
|
5292
|
+
description: WORKFLOW_TOOLS["workflow.assist"].description,
|
|
5293
|
+
inputSchema: {
|
|
5294
|
+
workflowInstanceId: z.string().min(1).describe("流程实例 id(workitem.list 的 instanceId;会话面 WorkflowAspect 必需)"),
|
|
5295
|
+
workItemId: z.string().min(1).describe("待办任务 id"),
|
|
5296
|
+
participants: z.array(z.string().min(1)).min(1).describe("协办人 userId 列表"),
|
|
5297
|
+
comment: z.string().optional().describe("协办意见(写入审批记录)"),
|
|
5298
|
+
channel: approvalChannelArg,
|
|
5299
|
+
},
|
|
5300
|
+
preflight: (args) => assertParticipantIds(args.participants, "workflow.assist"),
|
|
5301
|
+
execute: async (session, args) => {
|
|
5302
|
+
assertParticipantIds(args.participants, "workflow.assist");
|
|
5303
|
+
const channel = approvalChannel(args);
|
|
5304
|
+
const result = channel === "openapi"
|
|
5305
|
+
? await wireCall(session, {
|
|
5306
|
+
path: ENDPOINTS.openApiWorkflowAssist,
|
|
5307
|
+
method: "POST",
|
|
5308
|
+
headers: await openApiUserHeaders(session),
|
|
5309
|
+
body: workItemParticipantBody({ workItemId: args.workItemId, participantors: args.participants, ...(args.comment === undefined ? {} : { comment: args.comment }) }),
|
|
5310
|
+
})
|
|
5311
|
+
: await wireCall(session, {
|
|
5312
|
+
path: ENDPOINTS.workflowAssist,
|
|
5313
|
+
method: "POST",
|
|
5314
|
+
body: sessionWorkItemBody({ workflowInstanceId: args.workflowInstanceId, workItemId: args.workItemId, participantors: args.participants, ...(args.comment === undefined ? {} : { comment: args.comment }) }),
|
|
5315
|
+
});
|
|
5316
|
+
const { applied } = approvalActionReceipt(result, "workflow.assist", args);
|
|
5317
|
+
return {
|
|
5318
|
+
performed: { channel, errcode: result.errcode, platformErrmsg: result.errmsg, workItemId: args.workItemId, participantors: args.participants },
|
|
5319
|
+
readback: {
|
|
5320
|
+
applied,
|
|
5321
|
+
note: "协办人拿到的是 assist 面任务,不是原待办:审批结果仍由原审批人提交(协办人可在 workflow.instanceActivity 里看到节点参与人)。",
|
|
5322
|
+
},
|
|
5323
|
+
};
|
|
5324
|
+
},
|
|
5325
|
+
});
|
|
5326
|
+
writeTool({
|
|
5327
|
+
tools,
|
|
5328
|
+
name: "workflow.circulate",
|
|
5329
|
+
search: { intents: ["传阅", "发给他人看", "知会", "抄送"] },
|
|
5330
|
+
lane: WORKFLOW_LANE,
|
|
5331
|
+
scope: WORKFLOW_TOOLS["workflow.circulate"].scope,
|
|
5332
|
+
description: WORKFLOW_TOOLS["workflow.circulate"].description,
|
|
5333
|
+
inputSchema: {
|
|
5334
|
+
workflowInstanceId: z.string().min(1).describe("流程实例 id(workitem.list 的 instanceId;会话面 WorkflowAspect 必需)"),
|
|
5335
|
+
workItemId: z.string().min(1).describe("待办任务 id(传阅的是这张单据)"),
|
|
5336
|
+
participants: z.array(z.string().min(1)).min(1).describe("传阅对象 userId 列表"),
|
|
5337
|
+
comment: z.string().optional().describe("传阅意见"),
|
|
5338
|
+
channel: approvalChannelArg,
|
|
5339
|
+
},
|
|
5340
|
+
preflight: (args) => assertParticipantIds(args.participants, "workflow.circulate"),
|
|
5341
|
+
execute: async (session, args) => {
|
|
5342
|
+
assertParticipantIds(args.participants, "workflow.circulate");
|
|
5343
|
+
const channel = approvalChannel(args);
|
|
5344
|
+
const result = channel === "openapi"
|
|
5345
|
+
? await wireCall(session, {
|
|
5346
|
+
path: ENDPOINTS.openApiWorkflowCirculate,
|
|
5347
|
+
method: "POST",
|
|
5348
|
+
headers: await openApiUserHeaders(session),
|
|
5349
|
+
body: workItemParticipantBody({ workItemId: args.workItemId, participantors: args.participants, ...(args.comment === undefined ? {} : { comment: args.comment }) }),
|
|
5350
|
+
})
|
|
5351
|
+
: await wireCall(session, {
|
|
5352
|
+
path: ENDPOINTS.workflowCirculate,
|
|
5353
|
+
method: "POST",
|
|
5354
|
+
body: sessionWorkItemBody({ workflowInstanceId: args.workflowInstanceId, workItemId: args.workItemId, participantors: args.participants, ...(args.comment === undefined ? {} : { comment: args.comment }) }),
|
|
5355
|
+
});
|
|
5356
|
+
const { applied } = approvalActionReceipt(result, "workflow.circulate", args);
|
|
5357
|
+
return {
|
|
5358
|
+
performed: { channel, errcode: result.errcode, platformErrmsg: result.errmsg, workItemId: args.workItemId, participantors: args.participants },
|
|
5359
|
+
readback: {
|
|
5360
|
+
applied,
|
|
5361
|
+
note: "传阅不产生待办、不改变流程走向:传阅记录看 workflow.instanceActivity / list_workitem_approvals,别指望 workitem.list 出现新待办。",
|
|
5362
|
+
},
|
|
5363
|
+
};
|
|
5364
|
+
},
|
|
5365
|
+
});
|
|
5366
|
+
writeTool({
|
|
5367
|
+
tools,
|
|
5368
|
+
name: "workflow.revoke",
|
|
5369
|
+
search: { intents: ["撤回", "撤回已办", "撤回审批", "把流程撤回来"] },
|
|
5370
|
+
lane: WORKFLOW_LANE,
|
|
5371
|
+
scope: WORKFLOW_TOOLS["workflow.revoke"].scope,
|
|
5372
|
+
description: WORKFLOW_TOOLS["workflow.revoke"].description,
|
|
5373
|
+
inputSchema: {
|
|
5374
|
+
workflowInstanceId: z.string().min(1).describe("流程实例 id"),
|
|
5375
|
+
activityCode: z.string().min(1).describe("要撤回的节点 code(当前激活节点,从 workflow.instanceActivity 的 status=1 行取)"),
|
|
5376
|
+
workItemId: z.string().min(1).optional().describe("待办任务 id(可选;会话面 WorkflowAspect 用它校验「已办任务是本人」并写撤回日志;门户 UI 传)"),
|
|
5377
|
+
channel: approvalChannelArg,
|
|
5378
|
+
},
|
|
5379
|
+
execute: async (session, args) => {
|
|
5380
|
+
const channel = approvalChannel(args);
|
|
5381
|
+
let result;
|
|
5382
|
+
try {
|
|
5383
|
+
result = channel === "openapi"
|
|
5384
|
+
? await wireCall(session, {
|
|
5385
|
+
path: ENDPOINTS.openApiWorkflowRevoke,
|
|
5386
|
+
method: "GET",
|
|
5387
|
+
headers: await openApiUserHeaders(session),
|
|
5388
|
+
query: { workflowInstanceId: args.workflowInstanceId, activityCode: args.activityCode },
|
|
5389
|
+
})
|
|
5390
|
+
: await wireCall(session, {
|
|
5391
|
+
path: ENDPOINTS.workflowRevoke,
|
|
5392
|
+
method: "GET",
|
|
5393
|
+
query: {
|
|
5394
|
+
workflowInstanceId: args.workflowInstanceId,
|
|
5395
|
+
activityCode: args.activityCode,
|
|
5396
|
+
...(args.workItemId === undefined ? {} : { workItemId: args.workItemId }),
|
|
5397
|
+
},
|
|
5398
|
+
});
|
|
5399
|
+
}
|
|
5400
|
+
catch (error) {
|
|
5401
|
+
// 平台对「不可撤回」回非 0 errcode(WORKFLOW_CURRENT_OPERATION_CANNOT_BE_REVOKE),
|
|
5402
|
+
// 转成带恢复指引的 refused,而不是把裸 wire 错误抛给调用方。
|
|
5403
|
+
if (error instanceof WireError && error.kind === "business")
|
|
5404
|
+
throw new ToolRefusalError({
|
|
5405
|
+
status: "refused",
|
|
5406
|
+
blocker: "workflow-revoke-refused-by-platform",
|
|
5407
|
+
workflowInstanceId: args.workflowInstanceId,
|
|
5408
|
+
activityCode: args.activityCode,
|
|
5409
|
+
platformErrcode: error.errcode ?? null,
|
|
5410
|
+
platformErrmsg: error.message,
|
|
5411
|
+
message: "平台拒绝撤回(WORKFLOW_CURRENT_OPERATION_CANNOT_BE_REVOKE 家族):只有发起人、且只对允许撤回的节点有效。" +
|
|
5412
|
+
"先用 workflow.instanceActivity 确认该节点仍是激活态(status=1);不可撤时改用 workflow.abort 作废实例,或 workflow.transfer 换审批人。",
|
|
5413
|
+
nextCommand: `omc call workflow.instanceActivity --args '{"workflowInstanceId":"${args.workflowInstanceId}"}'`,
|
|
5414
|
+
});
|
|
5415
|
+
throw error;
|
|
5416
|
+
}
|
|
5417
|
+
const { applied } = approvalActionReceipt(result, "workflow.revoke", args);
|
|
5418
|
+
return {
|
|
5419
|
+
performed: { channel, errcode: result.errcode, platformErrmsg: result.errmsg, workflowInstanceId: args.workflowInstanceId, activityCode: args.activityCode },
|
|
5420
|
+
readback: {
|
|
5421
|
+
applied,
|
|
5422
|
+
note: "撤回成功后流程回到该节点之前的状态:用 workflow.instanceActivity 复核激活节点,发起人会重新拿到待办。",
|
|
5423
|
+
nextCommand: `omc call workflow.instanceActivity --args '{"workflowInstanceId":"${args.workflowInstanceId}"}'`,
|
|
5424
|
+
},
|
|
5425
|
+
};
|
|
5426
|
+
},
|
|
5427
|
+
});
|
|
5428
|
+
writeTool({
|
|
5429
|
+
tools,
|
|
5430
|
+
name: "workflow.abort",
|
|
5431
|
+
search: { intents: ["作废流程", "作废实例", "终止流程", "撤销流程实例"] },
|
|
5432
|
+
lane: WORKFLOW_LANE,
|
|
5433
|
+
scope: WORKFLOW_TOOLS["workflow.abort"].scope,
|
|
5434
|
+
description: WORKFLOW_TOOLS["workflow.abort"].description,
|
|
5435
|
+
inputSchema: {
|
|
5436
|
+
workflowInstanceId: z.string().min(1).describe("流程实例 id"),
|
|
5437
|
+
workItemId: z.string().min(1).optional().describe("待办任务 id(可选;会话面用于乐观锁上下文/审批记录,门户 UI 传)"),
|
|
5438
|
+
version: z.string().min(1).optional().describe("流程表单数据版本号(可选;会话面 GET abort_instance 带 version 时平台先 checkBizObjectVersion 乐观锁校验)"),
|
|
5439
|
+
channel: approvalChannelArg,
|
|
5440
|
+
},
|
|
5441
|
+
execute: async (session, args) => {
|
|
5442
|
+
const before = await getInstanceBaseInfo(session, args.workflowInstanceId);
|
|
5443
|
+
if (before === null)
|
|
5444
|
+
throw new ToolRefusalError({
|
|
5445
|
+
status: "refused",
|
|
5446
|
+
blocker: "workflow-instance-not-found",
|
|
5447
|
+
workflowInstanceId: args.workflowInstanceId,
|
|
5448
|
+
message: `流程实例 ${args.workflowInstanceId} 不存在(get_instance_baseinfo 空)——实例 id 来自 data.submit 读回的 workflowInstanceId`,
|
|
5449
|
+
});
|
|
5450
|
+
const statusBefore = wireString(before.status);
|
|
5451
|
+
const channel = approvalChannel(args);
|
|
5452
|
+
const result = channel === "openapi"
|
|
5453
|
+
? await wireCall(session, {
|
|
5454
|
+
path: ENDPOINTS.openApiWorkflowAbort,
|
|
5455
|
+
method: "GET",
|
|
5456
|
+
headers: await openApiUserHeaders(session),
|
|
5457
|
+
query: { workflowInstanceId: args.workflowInstanceId },
|
|
5458
|
+
})
|
|
5459
|
+
: await wireCall(session, {
|
|
5460
|
+
path: ENDPOINTS.workflowAbortInstance,
|
|
5461
|
+
method: "GET",
|
|
5462
|
+
query: {
|
|
5463
|
+
workflowInstanceId: args.workflowInstanceId,
|
|
5464
|
+
...(args.workItemId === undefined ? {} : { workItemId: args.workItemId }),
|
|
5465
|
+
...(args.version === undefined ? {} : { version: args.version }),
|
|
5466
|
+
},
|
|
5467
|
+
});
|
|
5468
|
+
const { applied } = approvalActionReceipt(result, "workflow.abort", args);
|
|
5469
|
+
const after = await getInstanceBaseInfo(session, args.workflowInstanceId);
|
|
5470
|
+
const statusAfter = after ? wireString(after.status) : null;
|
|
5471
|
+
return {
|
|
5472
|
+
performed: { channel, errcode: result.errcode, platformErrmsg: result.errmsg, workflowInstanceId: args.workflowInstanceId, statusBefore },
|
|
5473
|
+
readback: {
|
|
5474
|
+
applied,
|
|
5475
|
+
instanceStatus: statusAfter,
|
|
5476
|
+
// 作废走 handleCancelWorkflowInstance(WorkflowEndStatus.VOIDED_APPROVER):
|
|
5477
|
+
// 实例终态是 CANCELED(WorkflowInstanceStatus.java:15-22 只有
|
|
5478
|
+
// DRAFT/PROCESSING/COMPLETED/CANCELED/EXCEPTION/APPROVED/TOPPING_OFF/PAUSE
|
|
5479
|
+
// ——没有 VOIDED 这个实例态,VOIDED_APPROVER 是 endStatus),所以只认
|
|
5480
|
+
// CANCEL 家族;绝不能把 COMPLETED 也算作废成功(那是 workflow.finish 的终态)。
|
|
5481
|
+
voided: statusAfter !== null && /CANCEL/i.test(statusAfter),
|
|
5482
|
+
endRulesNote: "作废走 cancelInstance(WorkflowEndStatus.VOIDED_APPROVER):实例终态 CANCELED,end handler 规则不保证执行;要正常完结(COMPLETED)并触发 end 规则用 workflow.finish(finish_instance_by_post)。",
|
|
5483
|
+
},
|
|
5484
|
+
};
|
|
5485
|
+
},
|
|
5486
|
+
});
|
|
5487
|
+
// ── 只读:可驳回节点 ───────────────────────────────────────────────────────
|
|
5488
|
+
tools.push(defineTool({
|
|
5489
|
+
name: "workflow.rejectActivities",
|
|
5490
|
+
search: { intents: ["可驳回节点", "能驳回到哪些节点", "驳回目标", "退回节点清单"] },
|
|
5491
|
+
layer: "low",
|
|
5492
|
+
kind: "read",
|
|
5493
|
+
lane: WORKFLOW_LANE,
|
|
5494
|
+
scope: WORKFLOW_TOOLS["workflow.rejectActivities"].scope,
|
|
5495
|
+
description: WORKFLOW_TOOLS["workflow.rejectActivities"].description,
|
|
5496
|
+
inputSchema: {
|
|
5497
|
+
environment: environmentArg,
|
|
5498
|
+
workflowInstanceId: z.string().min(1).describe("流程实例 id"),
|
|
5499
|
+
activityCode: z.string().min(1).describe("当前待办节点 code(workitem.list / workflow.instanceActivity 取)"),
|
|
5500
|
+
channel: approvalChannelArg,
|
|
5501
|
+
capability: capabilityArg,
|
|
5502
|
+
},
|
|
5503
|
+
handler: async (ctx, args, self) => governedRead(ctx, self, args, async (session) => {
|
|
5504
|
+
const channel = approvalChannel(args);
|
|
5505
|
+
const rows = wireRows((await wireCall(session, channel === "openapi"
|
|
5506
|
+
? {
|
|
5507
|
+
path: ENDPOINTS.openApiWorkflowRejectActivities,
|
|
5508
|
+
headers: await openApiUserHeaders(session),
|
|
5509
|
+
query: { workflowInstanceId: args.workflowInstanceId, activityCode: args.activityCode },
|
|
5510
|
+
}
|
|
5511
|
+
: {
|
|
5512
|
+
path: ENDPOINTS.workflowListRejectActivities,
|
|
5513
|
+
query: { workflowInstanceId: args.workflowInstanceId, activityCode: args.activityCode },
|
|
5514
|
+
})).data);
|
|
5515
|
+
const activities = rows.map((row) => ({
|
|
5516
|
+
activityCode: wireString(row.activityCode),
|
|
5517
|
+
activityName: wireString(row.activityName),
|
|
5518
|
+
activityType: row.activityType ?? null,
|
|
5519
|
+
status: row.status ?? null,
|
|
5520
|
+
checkbox: row.checkbox === true,
|
|
5521
|
+
}));
|
|
5522
|
+
return {
|
|
5523
|
+
channel,
|
|
5524
|
+
workflowInstanceId: args.workflowInstanceId,
|
|
5525
|
+
activityCode: args.activityCode,
|
|
5526
|
+
count: activities.length,
|
|
5527
|
+
activities,
|
|
5528
|
+
...(activities.length === 0
|
|
5529
|
+
? {
|
|
5530
|
+
note: "空数组:该节点在**实例已走过的节点**里没有可退目标(平台先算模板允许的驳回目标,再按 h_workflow_token 里实际有 token 的节点过滤)。" +
|
|
5531
|
+
"这不是「平台不支持驳回」——检查节点 permittedAction(reject/rejectToStart/rejectToFixed/rejectToAllPreActivity)与流程是否刚发起(发起节点没有前序)。",
|
|
5532
|
+
}
|
|
5533
|
+
: {
|
|
5534
|
+
note: "checkbox=true 表示可多选(并行分支可一次退回多个节点)。驳回时把选中的 activityCode 传给 workflow.reject 的 rejectToActivityCode(单条)。",
|
|
5535
|
+
nextCommand: `omc call workflow.reject --args '{"workflowInstanceId":"${args.workflowInstanceId}","workItemId":"<workItemId>","rejectToActivityCode":"${activities[0]?.activityCode ?? "<code>"}"}'`,
|
|
5536
|
+
}),
|
|
5537
|
+
};
|
|
5538
|
+
}),
|
|
5539
|
+
}));
|
|
4940
5540
|
}
|
|
4941
5541
|
/** Flatten a role-group/role row into the participant-construction fields. */
|
|
4942
5542
|
/**
|