bpmax-cli 0.1.30 → 0.1.32
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 +158 -38
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
- package/skills/bpmax-project/SKILL.md +4 -4
package/dist/bin.js
CHANGED
|
@@ -665,7 +665,7 @@ async function parseJsonInput(input, label = "JSON input") {
|
|
|
665
665
|
// package.json
|
|
666
666
|
var package_default = {
|
|
667
667
|
name: "bpmax-cli",
|
|
668
|
-
version: "0.1.
|
|
668
|
+
version: "0.1.32",
|
|
669
669
|
description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
|
|
670
670
|
type: "module",
|
|
671
671
|
bin: {
|
|
@@ -779,11 +779,12 @@ function buildBpmaxUrl(profile, kind, params = {}) {
|
|
|
779
779
|
const flowType = params.flowType || "default";
|
|
780
780
|
const flowKey = params.flowKey || "";
|
|
781
781
|
const initValue = params.initValue ? JSON.stringify(params.initValue) : void 0;
|
|
782
|
+
const prefillToken = params.prefillToken;
|
|
782
783
|
const query = {
|
|
783
784
|
flow_type: flowType,
|
|
784
785
|
flow_key: flowKey,
|
|
785
786
|
...flowKey ? { key: flowKey } : {},
|
|
786
|
-
init_value: initValue
|
|
787
|
+
...prefillToken ? { prefill_token: prefillToken } : { init_value: initValue }
|
|
787
788
|
};
|
|
788
789
|
path6 = withQuery(`${basePath}/project/create`, query);
|
|
789
790
|
result.flow_type = flowType;
|
|
@@ -2607,17 +2608,49 @@ async function validateCreateForm(client, options) {
|
|
|
2607
2608
|
- ${result.errors.join("\n- ")}`);
|
|
2608
2609
|
}
|
|
2609
2610
|
}
|
|
2610
|
-
function
|
|
2611
|
+
async function storeCreateFormPrefill(client, flowIdentifiers, initValue, prefillContext) {
|
|
2612
|
+
const result = await apiRequest(
|
|
2613
|
+
client,
|
|
2614
|
+
"POST",
|
|
2615
|
+
"/project_staging/prefill",
|
|
2616
|
+
{
|
|
2617
|
+
data: {
|
|
2618
|
+
flow_type: flowIdentifiers.flow_type,
|
|
2619
|
+
flow_key: flowIdentifiers.flow_key,
|
|
2620
|
+
init_value: initValue,
|
|
2621
|
+
...prefillContext ? { prefill_context: prefillContext } : {}
|
|
2622
|
+
}
|
|
2623
|
+
}
|
|
2624
|
+
);
|
|
2625
|
+
if (typeof result.token !== "string" || !result.token) {
|
|
2626
|
+
throw new Error("Project create prefill endpoint did not return a token.");
|
|
2627
|
+
}
|
|
2628
|
+
return {
|
|
2629
|
+
token: result.token,
|
|
2630
|
+
expires_in: result.expires_in,
|
|
2631
|
+
expires_at: result.expires_at
|
|
2632
|
+
};
|
|
2633
|
+
}
|
|
2634
|
+
async function printCreateFormHandoff(client, format, profile, flowIdentifiers, options) {
|
|
2611
2635
|
const initValue = {
|
|
2612
2636
|
project: { name: options.name },
|
|
2613
2637
|
key_to_value: options.form
|
|
2614
2638
|
};
|
|
2639
|
+
const prefillContext = buildPrefillContext(options.fields ?? [], options.form);
|
|
2640
|
+
let prefill;
|
|
2641
|
+
let prefillError;
|
|
2642
|
+
try {
|
|
2643
|
+
prefill = await storeCreateFormPrefill(client, flowIdentifiers, initValue, prefillContext);
|
|
2644
|
+
} catch (error) {
|
|
2645
|
+
prefillError = error instanceof Error ? error.message : String(error);
|
|
2646
|
+
}
|
|
2615
2647
|
const url = buildBpmaxUrl(profile, "project-create", {
|
|
2616
2648
|
flowType: flowIdentifiers.flow_type,
|
|
2617
2649
|
flowKey: flowIdentifiers.flow_key,
|
|
2618
|
-
initValue
|
|
2650
|
+
initValue,
|
|
2651
|
+
...prefill ? { prefillToken: prefill.token } : {}
|
|
2619
2652
|
});
|
|
2620
|
-
assertCreateFormHandoffUrl(url, initValue, Object.keys(options.form));
|
|
2653
|
+
assertCreateFormHandoffUrl(url, initValue, Object.keys(options.form), prefill?.token);
|
|
2621
2654
|
const replyMarkdown = `[\u586B\u5199\u8868\u5355](${url.url})`;
|
|
2622
2655
|
const agentWarning = [
|
|
2623
2656
|
"Agent must reply with the full create form URL exactly as provided.",
|
|
@@ -2632,35 +2665,50 @@ function printCreateFormHandoff(format, profile, flowIdentifiers, options) {
|
|
|
2632
2665
|
mobile_path: url.mobile_path,
|
|
2633
2666
|
reply_markdown: replyMarkdown,
|
|
2634
2667
|
agent_warning: agentWarning,
|
|
2668
|
+
...prefill ? {
|
|
2669
|
+
prefill_token: prefill.token,
|
|
2670
|
+
prefill_expires_in: prefill.expires_in,
|
|
2671
|
+
prefill_expires_at: prefill.expires_at
|
|
2672
|
+
} : {
|
|
2673
|
+
prefill_fallback: "init_value",
|
|
2674
|
+
...prefillError ? { prefill_error: prefillError } : {}
|
|
2675
|
+
},
|
|
2635
2676
|
init_value: initValue,
|
|
2636
2677
|
init_value_keys: Object.keys(options.form),
|
|
2678
|
+
prefill_context: prefillContext,
|
|
2637
2679
|
message: options.message
|
|
2638
2680
|
});
|
|
2639
2681
|
}
|
|
2640
|
-
function
|
|
2641
|
-
const base = rawUrl.startsWith("http") ? void 0 : "https://bpmax.local";
|
|
2642
|
-
const initValue = new URL(rawUrl, base).searchParams.get("init_value");
|
|
2643
|
-
if (!initValue) {
|
|
2644
|
-
return void 0;
|
|
2645
|
-
}
|
|
2646
|
-
return JSON.parse(initValue);
|
|
2647
|
-
}
|
|
2648
|
-
function assertCreateFormHandoffUrl(url, expectedInitValue, expectedFormKeys) {
|
|
2682
|
+
function assertCreateFormHandoffUrl(url, expectedInitValue, expectedFormKeys, expectedPrefillToken) {
|
|
2649
2683
|
const targets = [url.url, url.pc_url, url.mobile_path].filter((item) => Boolean(item));
|
|
2650
2684
|
for (const target of targets) {
|
|
2651
|
-
const
|
|
2652
|
-
const
|
|
2653
|
-
|
|
2685
|
+
const base = target.startsWith("http") ? void 0 : "https://bpmax.local";
|
|
2686
|
+
const params = new URL(target, base).searchParams;
|
|
2687
|
+
const prefillToken = params.get("prefill_token");
|
|
2688
|
+
if (expectedPrefillToken) {
|
|
2689
|
+
if (prefillToken !== expectedPrefillToken) {
|
|
2690
|
+
throw new Error("Generated project create handoff URL is missing prefill_token; refusing to output an un-prefilled link.");
|
|
2691
|
+
}
|
|
2692
|
+
continue;
|
|
2693
|
+
}
|
|
2694
|
+
const initValueRaw = params.get("init_value");
|
|
2695
|
+
if (!initValueRaw) {
|
|
2696
|
+
throw new Error("Generated project create handoff URL is missing init_value fallback; refusing to output an un-prefilled link.");
|
|
2697
|
+
}
|
|
2698
|
+
const initValue = JSON.parse(initValueRaw);
|
|
2699
|
+
const keyToValue2 = initValue.key_to_value;
|
|
2700
|
+
if (typeof keyToValue2 !== "object" || keyToValue2 === null || Array.isArray(keyToValue2)) {
|
|
2654
2701
|
throw new Error("Generated project create handoff URL is missing init_value.key_to_value; refusing to output an un-prefilled link.");
|
|
2655
2702
|
}
|
|
2656
|
-
const
|
|
2657
|
-
if (
|
|
2658
|
-
throw new Error(`Generated project create handoff URL is missing prefilled form keys: ${
|
|
2703
|
+
const missingKeys2 = expectedFormKeys.filter((key) => !Object.prototype.hasOwnProperty.call(keyToValue2, key));
|
|
2704
|
+
if (missingKeys2.length > 0) {
|
|
2705
|
+
throw new Error(`Generated project create handoff URL is missing prefilled form keys: ${missingKeys2.join(", ")}`);
|
|
2659
2706
|
}
|
|
2660
2707
|
}
|
|
2661
|
-
const
|
|
2662
|
-
|
|
2663
|
-
|
|
2708
|
+
const keyToValue = expectedInitValue.key_to_value;
|
|
2709
|
+
const missingKeys = expectedFormKeys.filter((key) => !Object.prototype.hasOwnProperty.call(keyToValue, key));
|
|
2710
|
+
if (missingKeys.length > 0) {
|
|
2711
|
+
throw new Error(`Generated project create handoff output is missing prefilled form keys: ${missingKeys.join(", ")}`);
|
|
2664
2712
|
}
|
|
2665
2713
|
}
|
|
2666
2714
|
function fieldsForValidation(flowDetail, projectFormTemplate) {
|
|
@@ -2683,18 +2731,87 @@ function metaUsesTemplateProjectName(flowDetail) {
|
|
|
2683
2731
|
function formValidationErrors(fields, form) {
|
|
2684
2732
|
return validateFormAgainstFields(form, fields).errors;
|
|
2685
2733
|
}
|
|
2686
|
-
function
|
|
2687
|
-
|
|
2734
|
+
function isRequiredMissingError(error) {
|
|
2735
|
+
return / is required$/.test(error);
|
|
2736
|
+
}
|
|
2737
|
+
function assertHandoffFormCompatible(fields, form) {
|
|
2738
|
+
const errors = formValidationErrors(fields, form).filter((error) => !isRequiredMissingError(error));
|
|
2688
2739
|
if (errors.length > 0) {
|
|
2689
2740
|
throw new Error(
|
|
2690
2741
|
[
|
|
2691
|
-
"Form handoff cannot be generated because collected values are
|
|
2692
|
-
"
|
|
2742
|
+
"Form handoff cannot be generated because collected values are not page-compatible.",
|
|
2743
|
+
"Ask the user to correct invalid values, or ask them to choose complex selector fields in the BPMAX page.",
|
|
2693
2744
|
`Validation errors: ${errors.join("; ")}`
|
|
2694
2745
|
].join("\n")
|
|
2695
2746
|
);
|
|
2696
2747
|
}
|
|
2697
2748
|
}
|
|
2749
|
+
function isEmptyValue(value) {
|
|
2750
|
+
return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
|
|
2751
|
+
}
|
|
2752
|
+
function isSuggestedManualField(field) {
|
|
2753
|
+
const type = field.type?.toLowerCase() ?? "";
|
|
2754
|
+
return /(plugin_|selector|relation_|sub[_-]?form|associated[_-]?form|table|upload|image|file|attachment)/.test(type);
|
|
2755
|
+
}
|
|
2756
|
+
function contextField(field, reason, options = {}) {
|
|
2757
|
+
return {
|
|
2758
|
+
key: options.path ?? field.key,
|
|
2759
|
+
...field.label ? { label: field.label } : {},
|
|
2760
|
+
...field.type ? { type: field.type } : {},
|
|
2761
|
+
required: field.required,
|
|
2762
|
+
reason,
|
|
2763
|
+
...options.path ? { path: options.path } : {},
|
|
2764
|
+
...options.rootKey ? { root_key: options.rootKey } : {},
|
|
2765
|
+
...options.parentKey ? { parent_key: options.parentKey } : {}
|
|
2766
|
+
};
|
|
2767
|
+
}
|
|
2768
|
+
function collectPrefillContextForFields(fields, form, result, options = {}) {
|
|
2769
|
+
for (const field of fields) {
|
|
2770
|
+
const value = form[field.key];
|
|
2771
|
+
const path6 = options.prefix ? `${options.prefix}.${field.key}` : field.key;
|
|
2772
|
+
const fieldOptions = {
|
|
2773
|
+
path: path6,
|
|
2774
|
+
rootKey: options.rootKey ?? field.key,
|
|
2775
|
+
parentKey: options.parentKey
|
|
2776
|
+
};
|
|
2777
|
+
if (isEmptyValue(value)) {
|
|
2778
|
+
if (field.required) {
|
|
2779
|
+
result.missing_fields.push(contextField(field, "required_empty", fieldOptions));
|
|
2780
|
+
} else if (isSuggestedManualField(field)) {
|
|
2781
|
+
result.suggested_fields.push(contextField(field, "manual_confirm_recommended", fieldOptions));
|
|
2782
|
+
}
|
|
2783
|
+
continue;
|
|
2784
|
+
}
|
|
2785
|
+
result.filled_fields.push(contextField(field, "prefilled", fieldOptions));
|
|
2786
|
+
if (isSubFormField(field) && Array.isArray(value) && field.children?.length) {
|
|
2787
|
+
value.forEach((row, index) => {
|
|
2788
|
+
if (isRecord5(row)) {
|
|
2789
|
+
collectPrefillContextForFields(field.children ?? [], row, result, {
|
|
2790
|
+
prefix: `${field.key}[${index}]`,
|
|
2791
|
+
rootKey: field.key,
|
|
2792
|
+
parentKey: field.key
|
|
2793
|
+
});
|
|
2794
|
+
}
|
|
2795
|
+
});
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
2799
|
+
function buildPrefillContext(fields, form) {
|
|
2800
|
+
const result = {
|
|
2801
|
+
missing_fields: [],
|
|
2802
|
+
suggested_fields: [],
|
|
2803
|
+
filled_fields: []
|
|
2804
|
+
};
|
|
2805
|
+
collectPrefillContextForFields(fields, form, result);
|
|
2806
|
+
return {
|
|
2807
|
+
...result,
|
|
2808
|
+
summary: {
|
|
2809
|
+
missing_count: result.missing_fields.length,
|
|
2810
|
+
suggested_count: result.suggested_fields.length,
|
|
2811
|
+
filled_count: result.filled_fields.length
|
|
2812
|
+
}
|
|
2813
|
+
};
|
|
2814
|
+
}
|
|
2698
2815
|
function isRecord5(value) {
|
|
2699
2816
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2700
2817
|
}
|
|
@@ -2884,10 +3001,12 @@ function registerProjectCommands(program2) {
|
|
|
2884
3001
|
return;
|
|
2885
3002
|
}
|
|
2886
3003
|
if (projectFormTemplate && hasAutoInitLambda(projectFormTemplate.template)) {
|
|
2887
|
-
|
|
2888
|
-
|
|
3004
|
+
const handoffFields = fieldsForValidation(flowDetail, projectFormTemplate);
|
|
3005
|
+
assertHandoffFormCompatible(handoffFields, form);
|
|
3006
|
+
await printCreateFormHandoff(client, options.format, profile, flowIdentifiers, {
|
|
2889
3007
|
name,
|
|
2890
3008
|
form,
|
|
3009
|
+
fields: handoffFields,
|
|
2891
3010
|
reason: "form_template_auto_init_lambda",
|
|
2892
3011
|
message: "\u68C0\u6D4B\u5230\u8868\u5355\u6A21\u677F\u5305\u542B\u81EA\u52A8\u521D\u59CB\u5316\u811A\u672C\uFF0C\u5DF2\u751F\u6210 BPMAX \u521B\u5EFA\u9875\u94FE\u63A5\uFF0C\u8BF7\u70B9\u51FB\u7EE7\u7EED\u586B\u5199\u5E76\u63D0\u4EA4\u3002"
|
|
2893
3012
|
});
|
|
@@ -2897,10 +3016,12 @@ function registerProjectCommands(program2) {
|
|
|
2897
3016
|
if (!options.allowFormHandoff) {
|
|
2898
3017
|
throw new Error("Form handoff requires --allow-form-handoff. Continue interactive filling by default.");
|
|
2899
3018
|
}
|
|
2900
|
-
|
|
2901
|
-
|
|
3019
|
+
const handoffFields = fieldsForValidation(flowDetail, projectFormTemplate);
|
|
3020
|
+
assertHandoffFormCompatible(handoffFields, form);
|
|
3021
|
+
await printCreateFormHandoff(client, options.format, profile, flowIdentifiers, {
|
|
2902
3022
|
name,
|
|
2903
3023
|
form,
|
|
3024
|
+
fields: handoffFields,
|
|
2904
3025
|
message: "\u5DF2\u751F\u6210 BPMAX \u521B\u5EFA\u9875\u94FE\u63A5\uFF0C\u8BF7\u70B9\u51FB\u7EE7\u7EED\u586B\u5199\u5E76\u63D0\u4EA4\u3002"
|
|
2905
3026
|
});
|
|
2906
3027
|
return;
|
|
@@ -2912,20 +3033,19 @@ function registerProjectCommands(program2) {
|
|
|
2912
3033
|
projectFormTemplate = await loadProjectFormTemplate();
|
|
2913
3034
|
if (projectFormTemplate && hasAutoInitLambda(projectFormTemplate.template)) {
|
|
2914
3035
|
const handoffFields = fieldsForValidation(flowDetail, projectFormTemplate);
|
|
2915
|
-
|
|
2916
|
-
if (!useInteractive && missingFields.length > 0) {
|
|
3036
|
+
if (Object.keys(form).length === 0) {
|
|
2917
3037
|
throw new Error(
|
|
2918
3038
|
[
|
|
2919
|
-
"Form template has auto initialization scripts and cannot be handed off before
|
|
2920
|
-
"Rerun without --no-interactive to guide the user through the form, or provide --json.form with the missing values."
|
|
2921
|
-
`Missing required fields: ${missingFields.join(", ")}`
|
|
3039
|
+
"Form template has auto initialization scripts and cannot be handed off before any form values are collected.",
|
|
3040
|
+
"Rerun without --no-interactive to guide the user through the form, or provide --json.form with the missing values."
|
|
2922
3041
|
].join("\n")
|
|
2923
3042
|
);
|
|
2924
3043
|
}
|
|
2925
|
-
|
|
2926
|
-
printCreateFormHandoff(options.format, profile, flowIdentifiers, {
|
|
3044
|
+
assertHandoffFormCompatible(handoffFields, form);
|
|
3045
|
+
await printCreateFormHandoff(client, options.format, profile, flowIdentifiers, {
|
|
2927
3046
|
name: name ?? "",
|
|
2928
3047
|
form,
|
|
3048
|
+
fields: handoffFields,
|
|
2929
3049
|
reason: "form_template_auto_init_lambda",
|
|
2930
3050
|
message: "\u68C0\u6D4B\u5230\u8868\u5355\u6A21\u677F\u5305\u542B\u81EA\u52A8\u521D\u59CB\u5316\u811A\u672C\uFF0C\u5DF2\u751F\u6210 BPMAX \u521B\u5EFA\u9875\u94FE\u63A5\uFF0C\u8BF7\u70B9\u51FB\u7EE7\u7EED\u586B\u5199\u5E76\u63D0\u4EA4\u3002"
|
|
2931
3051
|
});
|