bpmax-cli 0.1.25 → 0.1.27

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
@@ -812,7 +812,7 @@ function registerFlowCommands(program2) {
812
812
  // package.json
813
813
  var package_default = {
814
814
  name: "bpmax-cli",
815
- version: "0.1.25",
815
+ version: "0.1.27",
816
816
  description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
817
817
  type: "module",
818
818
  bin: {
@@ -1246,13 +1246,35 @@ function extractFormFields(flowDetail) {
1246
1246
  function isEmpty(value) {
1247
1247
  return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
1248
1248
  }
1249
+ function validateComplexSelector(field, value) {
1250
+ const type = field.type?.toLowerCase() ?? "";
1251
+ if (!/(plugin_.*selector|selector|picker)/.test(type)) {
1252
+ return null;
1253
+ }
1254
+ const validObject = (item) => isRecord2(item);
1255
+ if (Array.isArray(value)) {
1256
+ return value.every(validObject) ? null : `${field.key} must contain selector option object(s), not scalar values`;
1257
+ }
1258
+ if (validObject(value)) {
1259
+ return null;
1260
+ }
1261
+ return `${field.key} must be a selector option object or array of option objects, not a scalar value`;
1262
+ }
1249
1263
  function validateType(field, value) {
1250
1264
  const type = field.type?.toLowerCase() ?? "";
1251
1265
  if (!type || isEmpty(value)) {
1252
1266
  return null;
1253
1267
  }
1254
1268
  if (isSubFormField(field)) {
1255
- return Array.isArray(value) ? null : `${field.key} must be a JSON array of row objects`;
1269
+ if (!Array.isArray(value)) {
1270
+ return `${field.key} must be a JSON array of row objects`;
1271
+ }
1272
+ const invalidRowIndex = value.findIndex((row) => !isRecord2(row));
1273
+ return invalidRowIndex >= 0 ? `${field.key}[${invalidRowIndex}] must be a row object` : null;
1274
+ }
1275
+ const selectorError = validateComplexSelector(field, value);
1276
+ if (selectorError) {
1277
+ return selectorError;
1256
1278
  }
1257
1279
  if (field.options) {
1258
1280
  const values = Array.isArray(value) ? value.map(String) : [String(value)];
@@ -1813,12 +1835,20 @@ function printCreateFormHandoff(format, profile, flowIdentifiers, options) {
1813
1835
  initValue
1814
1836
  });
1815
1837
  assertCreateFormHandoffUrl(url, initValue, Object.keys(options.form));
1838
+ const replyMarkdown = `[\u586B\u5199\u8868\u5355](${url.url})`;
1839
+ const agentWarning = [
1840
+ "Agent must reply with the full create form URL exactly as provided.",
1841
+ 'Use the Markdown link text "\u586B\u5199\u8868\u5355" and the complete URL from reply_markdown/url/pc_url.',
1842
+ "Do not shorten, truncate, rebuild, or replace the URL with a bare flow_type link."
1843
+ ].join(" ");
1816
1844
  printResult(format, {
1817
1845
  handoff: true,
1818
1846
  ...options.reason ? { reason: options.reason } : {},
1819
1847
  url: url.url,
1820
1848
  pc_url: url.pc_url,
1821
1849
  mobile_path: url.mobile_path,
1850
+ reply_markdown: replyMarkdown,
1851
+ agent_warning: agentWarning,
1822
1852
  init_value: initValue,
1823
1853
  init_value_keys: Object.keys(options.form),
1824
1854
  message: options.message
@@ -1850,11 +1880,24 @@ function assertCreateFormHandoffUrl(url, expectedInitValue, expectedFormKeys) {
1850
1880
  throw new Error(`Generated project create handoff URL did not include init_value (${encoded.length} bytes).`);
1851
1881
  }
1852
1882
  }
1853
- function isEmptyFormValue(value) {
1854
- return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
1883
+ function fieldsForValidation(flowDetail, projectFormTemplate) {
1884
+ const templateFields = projectFormTemplate ? extractFormFields(projectFormTemplate.template) : [];
1885
+ return templateFields.length > 0 ? templateFields : extractFormFields(flowDetail);
1855
1886
  }
1856
- function missingRequiredFormFields(fields, form) {
1857
- return fields.filter((field) => field.required && isEmptyFormValue(form[field.key])).map((field) => field.label ? `${field.label} (${field.key})` : field.key);
1887
+ function formValidationErrors(fields, form) {
1888
+ return validateFormAgainstFields(form, fields).errors;
1889
+ }
1890
+ function assertHandoffFormReady(fields, form) {
1891
+ const errors = formValidationErrors(fields, form);
1892
+ if (errors.length > 0) {
1893
+ throw new Error(
1894
+ [
1895
+ "Form handoff cannot be generated because collected values are incomplete or not page-compatible.",
1896
+ "Continue guiding the user to fill missing fields, or ask them to choose complex selector fields in the BPMAX page.",
1897
+ `Validation errors: ${errors.join("; ")}`
1898
+ ].join("\n")
1899
+ );
1900
+ }
1858
1901
  }
1859
1902
  function registerProjectCommands(program2) {
1860
1903
  const project = program2.command("project").description("Project commands");
@@ -1961,6 +2004,7 @@ function registerProjectCommands(program2) {
1961
2004
  }
1962
2005
  projectFormTemplate = await loadProjectFormTemplate();
1963
2006
  if (projectFormTemplate && hasAutoInitLambda(projectFormTemplate.template)) {
2007
+ assertHandoffFormReady(fieldsForValidation(flowDetail, projectFormTemplate), form);
1964
2008
  printCreateFormHandoff(options.format, profile, flowIdentifiers, {
1965
2009
  name,
1966
2010
  form,
@@ -1973,6 +2017,7 @@ function registerProjectCommands(program2) {
1973
2017
  if (!options.allowFormHandoff) {
1974
2018
  throw new Error("Form handoff requires --allow-form-handoff. Continue interactive filling by default.");
1975
2019
  }
2020
+ assertHandoffFormReady(fieldsForValidation(flowDetail, projectFormTemplate), form);
1976
2021
  printCreateFormHandoff(options.format, profile, flowIdentifiers, {
1977
2022
  name,
1978
2023
  form,
@@ -1986,7 +2031,8 @@ function registerProjectCommands(program2) {
1986
2031
  }
1987
2032
  projectFormTemplate = await loadProjectFormTemplate();
1988
2033
  if (projectFormTemplate && hasAutoInitLambda(projectFormTemplate.template)) {
1989
- const missingFields = missingRequiredFormFields(extractFormFields(flowDetail), form);
2034
+ const handoffFields = fieldsForValidation(flowDetail, projectFormTemplate);
2035
+ const missingFields = formValidationErrors(handoffFields, form);
1990
2036
  if (!useInteractive && missingFields.length > 0) {
1991
2037
  throw new Error(
1992
2038
  [
@@ -1996,6 +2042,7 @@ function registerProjectCommands(program2) {
1996
2042
  ].join("\n")
1997
2043
  );
1998
2044
  }
2045
+ assertHandoffFormReady(handoffFields, form);
1999
2046
  printCreateFormHandoff(options.format, profile, flowIdentifiers, {
2000
2047
  name,
2001
2048
  form,