bpmax-cli 0.2.1-beta.7 → 0.2.1-beta.9

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/bin.js CHANGED
@@ -469,7 +469,7 @@ function pluginAgentCapabilityForRequest(method, normalizedPath) {
469
469
  // package.json
470
470
  var package_default = {
471
471
  name: "bpmax-cli",
472
- version: "0.2.1-beta.7",
472
+ version: "0.2.1-beta.9",
473
473
  description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
474
474
  type: "module",
475
475
  bin: {
@@ -4339,6 +4339,277 @@ function validateFlowTemplateStandardPageCreateFormTemplate(value, errors) {
4339
4339
  }
4340
4340
  throw new Error(message);
4341
4341
  }
4342
+ function startConditionalJumpScriptLooksLikeIndexReturn(script) {
4343
+ const text5 = script.trim();
4344
+ if (!text5) {
4345
+ return false;
4346
+ }
4347
+ const directReturns = Array.from(text5.matchAll(/\breturn\s+([^;]+)\s*;?/g));
4348
+ if (!directReturns.length) {
4349
+ return false;
4350
+ }
4351
+ return directReturns.some((match) => {
4352
+ const expression = match[1].trim();
4353
+ if (/[=!<>]=?|&&|\|\||\?/.test(expression)) {
4354
+ return false;
4355
+ }
4356
+ return /^-?\d+$/.test(expression) || /^(routeIndex|resultIndex|targetIndex|index)\b/.test(expression) || /\b(result|options)\.indexOf\s*\(/.test(expression) || /^Number(?:\.parseInt)?\s*\(/.test(expression);
4357
+ });
4358
+ }
4359
+ function startConditionalJumpScriptIsCatchAll(script) {
4360
+ const text5 = script.trim();
4361
+ return /^return\s+true\s*;?\s*$/.test(text5) || /^return\s+Boolean\s*\(\s*true\s*\)\s*;?\s*$/.test(text5);
4362
+ }
4363
+ function validateFlowTemplateStartConditionalJump(value, errors) {
4364
+ const nextErrors = [];
4365
+ const data = isRecord3(value.data) ? value.data : {};
4366
+ const meta = isRecord3(data.meta) ? data.meta : {};
4367
+ const jumps = meta.condational_jump;
4368
+ if (jumps === void 0 || jumps === null || jumps === "") {
4369
+ return;
4370
+ }
4371
+ if (!Array.isArray(jumps)) {
4372
+ nextErrors.push("data.meta.condational_jump must be an array when start conditional routing is configured.");
4373
+ } else if (jumps.length === 0) {
4374
+ return;
4375
+ }
4376
+ const nodes = Array.isArray(data.nodes) ? data.nodes.filter(isRecord3) : [];
4377
+ const firstNodeId = nodes.length ? String(nodes[0].id ?? "").trim() : "";
4378
+ const nodeIds = new Set(nodes.map((node) => String(node.id ?? "").trim()).filter(Boolean));
4379
+ if (Array.isArray(jumps) && jumps.length && !nodes.length) {
4380
+ nextErrors.push("data.meta.condational_jump is configured but data.nodes is empty; start jump targets must point to real nodes or -1.");
4381
+ }
4382
+ if (Array.isArray(jumps) && jumps.length) {
4383
+ nodes.forEach((node, index) => {
4384
+ const id = String(node.id ?? "").trim();
4385
+ if (!id) {
4386
+ nextErrors.push(`data.nodes[${index}].id is required when data.meta.condational_jump is configured.`);
4387
+ }
4388
+ });
4389
+ }
4390
+ let lastJumpScript = "";
4391
+ let lastJumpResult = "";
4392
+ if (Array.isArray(jumps)) {
4393
+ jumps.forEach((jump, index) => {
4394
+ const pathName = `data.meta.condational_jump[${index}]`;
4395
+ if (!isRecord3(jump)) {
4396
+ nextErrors.push(`${pathName} must be an object with name, result, condition_mode, and a boolean condition script.`);
4397
+ return;
4398
+ }
4399
+ const name = typeof jump.name === "string" ? jump.name.trim() : "";
4400
+ if (!name) {
4401
+ nextErrors.push(`${pathName}.name is required so every explicit start route can be audited.`);
4402
+ }
4403
+ const rawResult = jump.result;
4404
+ if (Array.isArray(rawResult) || isRecord3(rawResult) || rawResult === void 0 || rawResult === null || String(rawResult).trim() === "") {
4405
+ nextErrors.push(`${pathName}.result must be a target node id or -1; it must not be empty, an array, an object, or a node name.`);
4406
+ } else {
4407
+ const result = String(rawResult).trim();
4408
+ if (result !== "-1" && !nodeIds.has(result)) {
4409
+ nextErrors.push(`${pathName}.result (${result}) must point to an existing data.nodes[].id or -1 for success end.`);
4410
+ }
4411
+ lastJumpResult = result;
4412
+ }
4413
+ const mode = typeof jump.condition_mode === "string" && jump.condition_mode.trim() ? jump.condition_mode.trim() : "code";
4414
+ let script = "";
4415
+ if (mode === "standard") {
4416
+ if (typeof jump.standard_condition === "string" && jump.standard_condition.trim()) {
4417
+ script = jump.standard_condition.trim();
4418
+ } else {
4419
+ nextErrors.push(`${pathName}.standard_condition is required when condition_mode is standard; condition is ignored by the backend in this mode.`);
4420
+ }
4421
+ } else if (mode === "code") {
4422
+ if (typeof jump.condition === "string" && jump.condition.trim()) {
4423
+ script = jump.condition.trim();
4424
+ } else {
4425
+ nextErrors.push(`${pathName}.condition is required when condition_mode is code or omitted; standard_condition is ignored by the backend in code mode.`);
4426
+ }
4427
+ } else {
4428
+ nextErrors.push(`${pathName}.condition_mode must be code or standard.`);
4429
+ }
4430
+ if (script) {
4431
+ lastJumpScript = script;
4432
+ if (index < jumps.length - 1 && startConditionalJumpScriptIsCatchAll(script)) {
4433
+ nextErrors.push(
4434
+ `${pathName} is a catch-all start route but is not the final item; return true must only appear on the last explicit fallback route.`
4435
+ );
4436
+ }
4437
+ if (startConditionalJumpScriptLooksLikeIndexReturn(script)) {
4438
+ nextErrors.push(
4439
+ `${pathName} must return boolean/truthy for this explicit start edge, not a node-level result index; do not copy node.condational_nodes scripts such as return 0/1/-1 into data.meta.condational_jump.`
4440
+ );
4441
+ }
4442
+ }
4443
+ });
4444
+ }
4445
+ if (Array.isArray(jumps) && jumps.length && nodes.length) {
4446
+ if (!lastJumpResult || !startConditionalJumpScriptIsCatchAll(lastJumpScript)) {
4447
+ nextErrors.push(
4448
+ "data.meta.condational_jump must end with an explicit catch-all route using condition script return true; this documents the default start path instead of relying on implicit fallback."
4449
+ );
4450
+ }
4451
+ }
4452
+ if (!nextErrors.length) {
4453
+ return;
4454
+ }
4455
+ if (errors) {
4456
+ errors.push(...nextErrors);
4457
+ return;
4458
+ }
4459
+ throw new Error(`flow-template start conditional jump gate failed: ${nextErrors.join("; ")}`);
4460
+ }
4461
+ function isFlowTemplateEndpointTarget(value) {
4462
+ return /^-\d+$/.test(value.trim());
4463
+ }
4464
+ function isFlowTemplateSpecialStepTarget(value) {
4465
+ const normalized = value.trim();
4466
+ return normalized === "[source]" || normalized === "anyNode";
4467
+ }
4468
+ function isFlowTemplateBackSourceTarget(value) {
4469
+ return value.trim() === "[source]";
4470
+ }
4471
+ function isFlowTemplateConditionalTarget(value, conditionNames) {
4472
+ const match = value.trim().match(/^(.+)\[condition\]\d+$/);
4473
+ if (!match) {
4474
+ return false;
4475
+ }
4476
+ return conditionNames.has(match[1].trim());
4477
+ }
4478
+ function validateFlowTemplateActionTarget(errors, pathName, target, nodeIds, conditionNames, options = {}) {
4479
+ const normalizedTarget = target.trim();
4480
+ if (!normalizedTarget) {
4481
+ if (options.actionString) {
4482
+ errors.push(`${pathName} target step is required after "|"; use "\u6309\u94AE\u6587\u6848|\u76EE\u6807\u8282\u70B9ID" or "\u6309\u94AE\u6587\u6848|\u6761\u4EF6\u540D[condition]0".`);
4483
+ } else {
4484
+ errors.push(`${pathName} target step is required; use a node id, -1, [source], anyNode, or \u6761\u4EF6\u540D[condition]0.`);
4485
+ }
4486
+ return;
4487
+ }
4488
+ const conditionalTargetAllowed = options.allowConditionalTarget !== false;
4489
+ const specialTargetAllowed = options.allowAnyNode === false ? isFlowTemplateBackSourceTarget(normalizedTarget) : isFlowTemplateSpecialStepTarget(normalizedTarget);
4490
+ if (!nodeIds.has(normalizedTarget) && !isFlowTemplateEndpointTarget(normalizedTarget) && !specialTargetAllowed && !(conditionalTargetAllowed && isFlowTemplateConditionalTarget(normalizedTarget, conditionNames))) {
4491
+ const allowedTargets = conditionalTargetAllowed ? "an existing data.nodes[].id, an endpoint like -1, [source], anyNode, or a condational_nodes reference like \u6761\u4EF6\u540D[condition]0" : options.allowAnyNode === false ? "an existing data.nodes[].id, an endpoint like -1, or [source]" : "an existing data.nodes[].id, an endpoint like -1, [source], or anyNode";
4492
+ errors.push(`${pathName} target (${normalizedTarget}) must be ${allowedTargets}.`);
4493
+ }
4494
+ }
4495
+ function validateFlowTemplateApproveActionShape(value, errors) {
4496
+ const nextErrors = [];
4497
+ const data = isRecord3(value.data) ? value.data : {};
4498
+ const nodes = Array.isArray(data.nodes) ? data.nodes.filter(isRecord3) : [];
4499
+ const nodeIds = new Set(nodes.map((node) => String(node.id ?? "").trim()).filter(Boolean));
4500
+ nodes.forEach((node, nodeIndex) => {
4501
+ const nodeName = typeof node.name === "string" && node.name.trim() ? node.name.trim() : `nodes[${nodeIndex}]`;
4502
+ const conditionNames = /* @__PURE__ */ new Set();
4503
+ if (node.condational_nodes !== void 0 && node.condational_nodes !== null && node.condational_nodes !== "" && !Array.isArray(node.condational_nodes)) {
4504
+ nextErrors.push(`${nodeName}.condational_nodes must be an array of condition route objects.`);
4505
+ }
4506
+ const conditionalNodes = Array.isArray(node.condational_nodes) ? node.condational_nodes : [];
4507
+ conditionalNodes.forEach((conditionNode, conditionIndex) => {
4508
+ const conditionPath = `${nodeName}.condational_nodes[${conditionIndex}]`;
4509
+ if (!isRecord3(conditionNode)) {
4510
+ nextErrors.push(`${conditionPath} must be an object with name, result, condition_mode, and an index-returning condition script.`);
4511
+ return;
4512
+ }
4513
+ const conditionName = typeof conditionNode.name === "string" ? conditionNode.name.trim() : "";
4514
+ if (conditionName) {
4515
+ conditionNames.add(conditionName);
4516
+ } else {
4517
+ nextErrors.push(`${conditionPath}.name is required so approve_to_step/approve_actions can reference this condational_nodes entry.`);
4518
+ }
4519
+ const conditionMode = typeof conditionNode.condition_mode === "string" && conditionNode.condition_mode.trim() ? conditionNode.condition_mode.trim() : "code";
4520
+ if (conditionMode === "standard") {
4521
+ if (typeof conditionNode.standard_condition !== "string" || !conditionNode.standard_condition.trim()) {
4522
+ nextErrors.push(`${conditionPath}.standard_condition is required when condition_mode is standard; condition is ignored by the backend in this mode.`);
4523
+ }
4524
+ } else if (conditionMode === "code") {
4525
+ if (typeof conditionNode.condition !== "string" || !conditionNode.condition.trim()) {
4526
+ nextErrors.push(`${conditionPath}.condition is required when condition_mode is code or omitted; standard_condition is ignored by the backend in code mode.`);
4527
+ }
4528
+ } else {
4529
+ nextErrors.push(`${conditionPath}.condition_mode must be code or standard.`);
4530
+ }
4531
+ const conditionResult = conditionNode.result;
4532
+ const resultPath = `${conditionPath}.result`;
4533
+ if (!Array.isArray(conditionResult) || !conditionResult.length) {
4534
+ nextErrors.push(`${resultPath} must be a non-empty array of target node ids.`);
4535
+ return;
4536
+ }
4537
+ conditionResult.forEach((target, targetIndex) => {
4538
+ const targetPath = `${resultPath}[${targetIndex}]`;
4539
+ if (Array.isArray(target) || isRecord3(target) || target === void 0 || target === null) {
4540
+ nextErrors.push(`${targetPath} must be a target node id, endpoint like -1, or [source].`);
4541
+ return;
4542
+ }
4543
+ validateFlowTemplateActionTarget(
4544
+ nextErrors,
4545
+ targetPath,
4546
+ String(target),
4547
+ nodeIds,
4548
+ conditionNames,
4549
+ { allowConditionalTarget: false, allowAnyNode: false }
4550
+ );
4551
+ });
4552
+ });
4553
+ [
4554
+ ["approve_to_step", node.approve_to_step],
4555
+ ["approve_fail", node.approve_fail]
4556
+ ].forEach(([fieldName, fieldValue]) => {
4557
+ if (fieldValue === void 0 || fieldValue === null || fieldValue === "") {
4558
+ return;
4559
+ }
4560
+ if (Array.isArray(fieldValue) || isRecord3(fieldValue)) {
4561
+ nextErrors.push(`${nodeName}.${fieldName} must be a target node id, endpoint like -1, [source], anyNode, or \u6761\u4EF6\u540D[condition]0.`);
4562
+ return;
4563
+ }
4564
+ validateFlowTemplateActionTarget(nextErrors, `${nodeName}.${fieldName}`, String(fieldValue), nodeIds, conditionNames);
4565
+ });
4566
+ const actionGroups = [
4567
+ ["approve_actions", node.approve_actions],
4568
+ ["approve_fail_actions", node.approve_fail_actions]
4569
+ ];
4570
+ actionGroups.forEach(([fieldName, fieldValue]) => {
4571
+ if (fieldValue === void 0 || fieldValue === null || fieldValue === "") {
4572
+ return;
4573
+ }
4574
+ const pathPrefix = `${nodeName}.${fieldName}`;
4575
+ if (!Array.isArray(fieldValue)) {
4576
+ nextErrors.push(`${pathPrefix} must be an array of action strings.`);
4577
+ return;
4578
+ }
4579
+ fieldValue.forEach((action, actionIndex) => {
4580
+ const pathName = `${pathPrefix}[${actionIndex}]`;
4581
+ if (typeof action !== "string") {
4582
+ nextErrors.push(`${pathName} must be a string action in "\u6309\u94AE\u6587\u6848|\u76EE\u6807\u8282\u70B9ID" format.`);
4583
+ return;
4584
+ }
4585
+ const parts = action.split("|");
4586
+ if (parts.length < 2) {
4587
+ const raw = action.trim();
4588
+ if (raw && (nodeIds.has(raw) || isFlowTemplateEndpointTarget(raw) || isFlowTemplateSpecialStepTarget(raw) || isFlowTemplateConditionalTarget(raw, conditionNames))) {
4589
+ nextErrors.push(`${pathName} is a bare target (${raw}); action strings must be "\u6309\u94AE\u6587\u6848|\u76EE\u6807\u8282\u70B9ID", not just a node id.`);
4590
+ } else {
4591
+ nextErrors.push(`${pathName} must contain "|" and use "\u6309\u94AE\u6587\u6848|\u76EE\u6807\u8282\u70B9ID" or "\u6309\u94AE\u6587\u6848|\u6761\u4EF6\u540D[condition]0".`);
4592
+ }
4593
+ return;
4594
+ }
4595
+ const label = parts[0].trim();
4596
+ const target = parts[1].trim();
4597
+ if (!label) {
4598
+ nextErrors.push(`${pathName} label is required before "|".`);
4599
+ }
4600
+ validateFlowTemplateActionTarget(nextErrors, pathName, target, nodeIds, conditionNames, { actionString: true });
4601
+ });
4602
+ });
4603
+ });
4604
+ if (!nextErrors.length) {
4605
+ return;
4606
+ }
4607
+ if (errors) {
4608
+ errors.push(...nextErrors);
4609
+ return;
4610
+ }
4611
+ throw new Error(`flow-template approve action gate failed: ${nextErrors.join("; ")}`);
4612
+ }
4342
4613
  function looksLikeParseEvalFunctionBody(script) {
4343
4614
  const text5 = script.trim();
4344
4615
  if (!text5) {
@@ -5013,6 +5284,8 @@ function normalizeFlowTemplatePayload(work) {
5013
5284
  validateFlowTemplateRemoteTemplateRefs({ ...work, data });
5014
5285
  validateFlowTemplateProjectAfterCreatePath({ ...work, data });
5015
5286
  validateFlowTemplateStandardPageCreateFormTemplate({ ...work, data });
5287
+ validateFlowTemplateStartConditionalJump({ ...work, data });
5288
+ validateFlowTemplateApproveActionShape({ ...work, data });
5016
5289
  validateFlowTemplateCodeModeMessages({ ...work, data });
5017
5290
  validateFlowTemplateRuntimeScripts({ ...work, data });
5018
5291
  validateFlowTemplateFeishuChatPlugin({ ...work, data });
@@ -6888,6 +7161,8 @@ async function createFlowTemplateFromWork(config, profile, workFile, confirm3, o
6888
7161
  validateFlowTemplateRemoteTemplateRefs(work);
6889
7162
  validateFlowTemplateProjectAfterCreatePath(work);
6890
7163
  validateFlowTemplateStandardPageCreateFormTemplate(work);
7164
+ validateFlowTemplateStartConditionalJump(work);
7165
+ validateFlowTemplateApproveActionShape(work);
6891
7166
  validateFlowTemplateCodeModeMessages(work);
6892
7167
  validateFlowTemplateRuntimeScripts(work);
6893
7168
  validateFlowTemplateFeishuChatPlugin(work);
@@ -7783,6 +8058,8 @@ async function lintConfigWorkFile(file, options = {}) {
7783
8058
  validateFlowTemplateRemoteTemplateRefs(flowWork, errors);
7784
8059
  validateFlowTemplateProjectAfterCreatePath(flowWork, errors);
7785
8060
  validateFlowTemplateStandardPageCreateFormTemplate(flowWork, errors);
8061
+ validateFlowTemplateStartConditionalJump(flowWork, errors);
8062
+ validateFlowTemplateApproveActionShape(flowWork, errors);
7786
8063
  validateFlowTemplateCodeModeMessages(flowWork, errors);
7787
8064
  validateFlowTemplateRuntimeScripts(flowWork, errors);
7788
8065
  validateFlowTemplateFeishuChatPlugin(flowWork, errors);
@@ -8135,6 +8412,8 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
8135
8412
  validateFlowTemplateRemoteTemplateRefs(submit.payload);
8136
8413
  validateFlowTemplateProjectAfterCreatePath(submit.payload);
8137
8414
  validateFlowTemplateStandardPageCreateFormTemplate(submit.payload);
8415
+ validateFlowTemplateStartConditionalJump(submit.payload);
8416
+ validateFlowTemplateApproveActionShape(submit.payload);
8138
8417
  validateFlowTemplateCodeModeMessages(submit.payload);
8139
8418
  validateFlowTemplateRuntimeScripts(submit.payload);
8140
8419
  validateFlowTemplateFeishuChatPlugin(submit.payload);