bpmax-cli 0.1.31 → 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 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.31",
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: {
@@ -2637,13 +2637,20 @@ async function printCreateFormHandoff(client, format, profile, flowIdentifiers,
2637
2637
  key_to_value: options.form
2638
2638
  };
2639
2639
  const prefillContext = buildPrefillContext(options.fields ?? [], options.form);
2640
- const prefill = await storeCreateFormPrefill(client, flowIdentifiers, initValue, prefillContext);
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
+ }
2641
2647
  const url = buildBpmaxUrl(profile, "project-create", {
2642
2648
  flowType: flowIdentifiers.flow_type,
2643
2649
  flowKey: flowIdentifiers.flow_key,
2644
- prefillToken: prefill.token
2650
+ initValue,
2651
+ ...prefill ? { prefillToken: prefill.token } : {}
2645
2652
  });
2646
- assertCreateFormHandoffUrl(url, initValue, Object.keys(options.form), prefill.token);
2653
+ assertCreateFormHandoffUrl(url, initValue, Object.keys(options.form), prefill?.token);
2647
2654
  const replyMarkdown = `[\u586B\u5199\u8868\u5355](${url.url})`;
2648
2655
  const agentWarning = [
2649
2656
  "Agent must reply with the full create form URL exactly as provided.",
@@ -2658,9 +2665,14 @@ async function printCreateFormHandoff(client, format, profile, flowIdentifiers,
2658
2665
  mobile_path: url.mobile_path,
2659
2666
  reply_markdown: replyMarkdown,
2660
2667
  agent_warning: agentWarning,
2661
- prefill_token: prefill.token,
2662
- prefill_expires_in: prefill.expires_in,
2663
- prefill_expires_at: prefill.expires_at,
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
+ },
2664
2676
  init_value: initValue,
2665
2677
  init_value_keys: Object.keys(options.form),
2666
2678
  prefill_context: prefillContext,
@@ -2671,9 +2683,26 @@ function assertCreateFormHandoffUrl(url, expectedInitValue, expectedFormKeys, ex
2671
2683
  const targets = [url.url, url.pc_url, url.mobile_path].filter((item) => Boolean(item));
2672
2684
  for (const target of targets) {
2673
2685
  const base = target.startsWith("http") ? void 0 : "https://bpmax.local";
2674
- const prefillToken = new URL(target, base).searchParams.get("prefill_token");
2675
- if (prefillToken !== expectedPrefillToken) {
2676
- throw new Error("Generated project create handoff URL is missing prefill_token; refusing to output an un-prefilled link.");
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)) {
2701
+ throw new Error("Generated project create handoff URL is missing init_value.key_to_value; refusing to output an un-prefilled link.");
2702
+ }
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(", ")}`);
2677
2706
  }
2678
2707
  }
2679
2708
  const keyToValue = expectedInitValue.key_to_value;