@lark-apaas/fullstack-cli 1.1.68-alpha.20261019102946 → 1.1.68-beta.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.
Files changed (3) hide show
  1. package/README.md +10 -0
  2. package/dist/index.js +526 -391
  3. package/package.json +3 -1
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/index.ts
2
- import fs29 from "fs";
3
- import path25 from "path";
2
+ import fs31 from "fs";
3
+ import path26 from "path";
4
4
  import { fileURLToPath as fileURLToPath5 } from "url";
5
5
  import { config as dotenvConfig } from "dotenv";
6
6
 
@@ -2478,8 +2478,8 @@ var genDbSchemaCommand = {
2478
2478
  };
2479
2479
 
2480
2480
  // src/commands/sync/run.handler.ts
2481
- import path5 from "path";
2482
- import fs7 from "fs";
2481
+ import path6 from "path";
2482
+ import fs9 from "fs";
2483
2483
  import { fileURLToPath as fileURLToPath3 } from "url";
2484
2484
 
2485
2485
  // src/config/sync.ts
@@ -2581,6 +2581,9 @@ function buildDefaultRules(opts) {
2581
2581
  type: "file",
2582
2582
  overwrite: true
2583
2583
  },
2584
+ // UI 位于 server/mcp/ui,检查配置由 Agent 随 UI 代码创建。
2585
+ // 不生成 UI 目录;仅给已有 Nest 工程增量补服务端排除项。
2586
+ { onlyNestjs: true, type: "typescript-exclude", to: "tsconfig.node.json", path: "server/mcp/ui" },
2584
2587
  // 9. 把模板版本的 lint 脚本替换为支持 --files 的 runner
2585
2588
  // 只识别平台模板生成的 `concurrently ...` 形态,用户真正改写过的脚本保持原样
2586
2589
  {
@@ -2750,18 +2753,68 @@ function activateGitHooks(userProjectRoot) {
2750
2753
  return { action: "already-active" };
2751
2754
  }
2752
2755
 
2756
+ // src/commands/sync/typescript-exclude.ts
2757
+ import fs7 from "fs";
2758
+ import { applyEdits, modify, parse } from "jsonc-parser";
2759
+ function excludeTypeScriptPath(filename, excludedPath) {
2760
+ if (!fs7.existsSync(filename)) return false;
2761
+ const source = fs7.readFileSync(filename, "utf8");
2762
+ const errors = [];
2763
+ const raw = parse(source, errors, { allowTrailingComma: true });
2764
+ if (errors.length || !raw || typeof raw !== "object") throw new Error(`Invalid exclude array: ${filename}`);
2765
+ if (raw.exclude === void 0) {
2766
+ console.warn(`Cannot safely update inherited excludes in ${filename}; add ${excludedPath} to the effective TypeScript exclude configuration.`);
2767
+ return false;
2768
+ }
2769
+ if (!Array.isArray(raw.exclude) || raw.exclude.some((p) => typeof p !== "string")) throw new Error(`Invalid exclude array: ${filename}`);
2770
+ if (raw.exclude.includes(excludedPath)) return false;
2771
+ fs7.writeFileSync(filename, applyEdits(source, modify(source, ["exclude", raw.exclude.length], excludedPath, {
2772
+ isArrayInsertion: true,
2773
+ formattingOptions: { insertSpaces: true, tabSize: 2, eol: source.includes("\r\n") ? "\r\n" : "\n" }
2774
+ })));
2775
+ return true;
2776
+ }
2777
+
2778
+ // src/commands/sync/resolve-stack.ts
2779
+ import fs8 from "fs";
2780
+ import path5 from "path";
2781
+ function resolveStack(userProjectRoot) {
2782
+ const sparkMetaPath = path5.join(userProjectRoot, ".spark", "meta.json");
2783
+ if (!fs8.existsSync(sparkMetaPath)) {
2784
+ return void 0;
2785
+ }
2786
+ try {
2787
+ const meta = JSON.parse(fs8.readFileSync(sparkMetaPath, "utf-8"));
2788
+ return typeof meta.stack === "string" ? meta.stack : void 0;
2789
+ } catch (error) {
2790
+ const message = error instanceof Error ? error.message : String(error);
2791
+ console.warn(`[fullstack-cli] \u26A0 Failed to read .spark/meta.json, fallback to default sync: ${message}`);
2792
+ return void 0;
2793
+ }
2794
+ }
2795
+ function isNestjsProject(root, stack) {
2796
+ if (stack === "nestjs-react-fullstack") return true;
2797
+ if (stack) return false;
2798
+ try {
2799
+ const pkg2 = JSON.parse(fs8.readFileSync(path5.join(root, "package.json"), "utf8"));
2800
+ return Boolean(pkg2.dependencies?.["@nestjs/core"]) && fs8.existsSync(path5.join(root, "tsconfig.node.json"));
2801
+ } catch {
2802
+ return false;
2803
+ }
2804
+ }
2805
+
2753
2806
  // src/commands/sync/run.handler.ts
2754
2807
  async function run2(options) {
2755
2808
  const userProjectRoot = process.env.INIT_CWD || process.cwd();
2756
2809
  const __filename = fileURLToPath3(import.meta.url);
2757
- const __dirname2 = path5.dirname(__filename);
2758
- const pluginRoot = path5.resolve(__dirname2, "..");
2810
+ const __dirname2 = path6.dirname(__filename);
2811
+ const pluginRoot = path6.resolve(__dirname2, "..");
2759
2812
  if (userProjectRoot === pluginRoot) {
2760
2813
  console.log("[fullstack-cli] Skip syncing (installing plugin itself)");
2761
2814
  process.exit(0);
2762
2815
  }
2763
- const userPackageJson = path5.join(userProjectRoot, "package.json");
2764
- if (!fs7.existsSync(userPackageJson)) {
2816
+ const userPackageJson = path6.join(userProjectRoot, "package.json");
2817
+ if (!fs9.existsSync(userPackageJson)) {
2765
2818
  console.log("[fullstack-cli] Skip syncing (not a valid npm project)");
2766
2819
  process.exit(0);
2767
2820
  }
@@ -2775,7 +2828,9 @@ async function run2(options) {
2775
2828
  console.warn("[fullstack-cli] No sync configuration found");
2776
2829
  process.exit(0);
2777
2830
  }
2831
+ const isNestjs = isNestjsProject(userProjectRoot, stack);
2778
2832
  for (const rule of config.sync) {
2833
+ if (rule.onlyNestjs && !isNestjs) continue;
2779
2834
  await syncRule(rule, pluginRoot, userProjectRoot);
2780
2835
  }
2781
2836
  if (config.permissions) {
@@ -2796,23 +2851,13 @@ async function run2(options) {
2796
2851
  process.exit(1);
2797
2852
  }
2798
2853
  }
2799
- function resolveStack(userProjectRoot) {
2800
- const sparkMetaPath = path5.join(userProjectRoot, ".spark", "meta.json");
2801
- if (!fs7.existsSync(sparkMetaPath)) {
2802
- return void 0;
2803
- }
2804
- try {
2805
- const meta = JSON.parse(fs7.readFileSync(sparkMetaPath, "utf-8"));
2806
- return typeof meta.stack === "string" ? meta.stack : void 0;
2807
- } catch (error) {
2808
- const message = error instanceof Error ? error.message : String(error);
2809
- console.warn(`[fullstack-cli] \u26A0 Failed to read .spark/meta.json, fallback to default sync: ${message}`);
2810
- return void 0;
2811
- }
2812
- }
2813
2854
  async function syncRule(rule, pluginRoot, userProjectRoot) {
2855
+ if (rule.type === "typescript-exclude") {
2856
+ excludeTypeScriptPath(path6.join(userProjectRoot, rule.to), rule.path);
2857
+ return;
2858
+ }
2814
2859
  if (rule.type === "delete-file" || rule.type === "delete-directory") {
2815
- const destPath2 = path5.join(userProjectRoot, rule.to);
2860
+ const destPath2 = path6.join(userProjectRoot, rule.to);
2816
2861
  if (rule.type === "delete-file") {
2817
2862
  deleteFile(destPath2);
2818
2863
  } else {
@@ -2821,37 +2866,37 @@ async function syncRule(rule, pluginRoot, userProjectRoot) {
2821
2866
  return;
2822
2867
  }
2823
2868
  if (rule.type === "remove-line") {
2824
- const destPath2 = path5.join(userProjectRoot, rule.to);
2869
+ const destPath2 = path6.join(userProjectRoot, rule.to);
2825
2870
  removeLineFromFile(destPath2, rule.pattern);
2826
2871
  return;
2827
2872
  }
2828
2873
  if (rule.type === "add-script") {
2829
- const packageJsonPath = path5.join(userProjectRoot, "package.json");
2874
+ const packageJsonPath = path6.join(userProjectRoot, "package.json");
2830
2875
  addScript(packageJsonPath, rule.name, rule.command, rule.overwrite ?? false);
2831
2876
  return;
2832
2877
  }
2833
2878
  if (rule.type === "patch-script") {
2834
- const packageJsonPath = path5.join(userProjectRoot, "package.json");
2879
+ const packageJsonPath = path6.join(userProjectRoot, "package.json");
2835
2880
  patchScript(packageJsonPath, rule.name, rule.to, rule.ifStartsWith);
2836
2881
  return;
2837
2882
  }
2838
2883
  if (rule.type === "add-line") {
2839
- const destPath2 = path5.join(userProjectRoot, rule.to);
2884
+ const destPath2 = path6.join(userProjectRoot, rule.to);
2840
2885
  addLineToFile(destPath2, rule.line);
2841
2886
  return;
2842
2887
  }
2843
2888
  if (rule.type === "merge-json") {
2844
- const srcPath2 = path5.join(pluginRoot, rule.from);
2845
- const destPath2 = path5.join(userProjectRoot, rule.to);
2889
+ const srcPath2 = path6.join(pluginRoot, rule.from);
2890
+ const destPath2 = path6.join(userProjectRoot, rule.to);
2846
2891
  mergeJsonFile(srcPath2, destPath2, rule.arrayMerge);
2847
2892
  return;
2848
2893
  }
2849
2894
  if (!("from" in rule)) {
2850
2895
  return;
2851
2896
  }
2852
- const srcPath = path5.join(pluginRoot, rule.from);
2853
- const destPath = path5.join(userProjectRoot, rule.to);
2854
- if (!fs7.existsSync(srcPath)) {
2897
+ const srcPath = path6.join(pluginRoot, rule.from);
2898
+ const destPath = path6.join(userProjectRoot, rule.to);
2899
+ if (!fs9.existsSync(srcPath)) {
2855
2900
  console.warn(`[fullstack-cli] Source not found: ${rule.from}`);
2856
2901
  return;
2857
2902
  }
@@ -2868,68 +2913,68 @@ async function syncRule(rule, pluginRoot, userProjectRoot) {
2868
2913
  }
2869
2914
  }
2870
2915
  function syncFile(src, dest, overwrite = true, onlyIfExists = false) {
2871
- if (onlyIfExists && !fs7.existsSync(dest)) {
2872
- console.log(`[fullstack-cli] \u25CB ${path5.basename(dest)} (skipped, target not exists)`);
2916
+ if (onlyIfExists && !fs9.existsSync(dest)) {
2917
+ console.log(`[fullstack-cli] \u25CB ${path6.basename(dest)} (skipped, target not exists)`);
2873
2918
  return;
2874
2919
  }
2875
- const destDir = path5.dirname(dest);
2876
- if (!fs7.existsSync(destDir)) {
2877
- fs7.mkdirSync(destDir, { recursive: true });
2920
+ const destDir = path6.dirname(dest);
2921
+ if (!fs9.existsSync(destDir)) {
2922
+ fs9.mkdirSync(destDir, { recursive: true });
2878
2923
  }
2879
- if (fs7.existsSync(dest) && !overwrite) {
2880
- console.log(`[fullstack-cli] \u25CB ${path5.basename(dest)} (skipped, already exists)`);
2924
+ if (fs9.existsSync(dest) && !overwrite) {
2925
+ console.log(`[fullstack-cli] \u25CB ${path6.basename(dest)} (skipped, already exists)`);
2881
2926
  return;
2882
2927
  }
2883
- fs7.copyFileSync(src, dest);
2884
- console.log(`[fullstack-cli] \u2713 ${path5.basename(dest)}`);
2928
+ fs9.copyFileSync(src, dest);
2929
+ console.log(`[fullstack-cli] \u2713 ${path6.basename(dest)}`);
2885
2930
  }
2886
2931
  function syncDirectory(src, dest, overwrite = true) {
2887
- if (!fs7.existsSync(dest)) {
2888
- fs7.mkdirSync(dest, { recursive: true });
2932
+ if (!fs9.existsSync(dest)) {
2933
+ fs9.mkdirSync(dest, { recursive: true });
2889
2934
  }
2890
- const files = fs7.readdirSync(src);
2935
+ const files = fs9.readdirSync(src);
2891
2936
  let count = 0;
2892
2937
  files.forEach((file) => {
2893
- const srcFile = path5.join(src, file);
2894
- const destFile = path5.join(dest, file);
2895
- const stats = fs7.statSync(srcFile);
2938
+ const srcFile = path6.join(src, file);
2939
+ const destFile = path6.join(dest, file);
2940
+ const stats = fs9.statSync(srcFile);
2896
2941
  if (stats.isDirectory()) {
2897
2942
  syncDirectory(srcFile, destFile, overwrite);
2898
2943
  } else {
2899
- if (overwrite || !fs7.existsSync(destFile)) {
2900
- fs7.copyFileSync(srcFile, destFile);
2901
- console.log(`[fullstack-cli] \u2713 ${path5.relative(dest, destFile)}`);
2944
+ if (overwrite || !fs9.existsSync(destFile)) {
2945
+ fs9.copyFileSync(srcFile, destFile);
2946
+ console.log(`[fullstack-cli] \u2713 ${path6.relative(dest, destFile)}`);
2902
2947
  count++;
2903
2948
  }
2904
2949
  }
2905
2950
  });
2906
2951
  if (count > 0) {
2907
- console.log(`[fullstack-cli] Synced ${count} files to ${path5.basename(dest)}/`);
2952
+ console.log(`[fullstack-cli] Synced ${count} files to ${path6.basename(dest)}/`);
2908
2953
  }
2909
2954
  }
2910
2955
  function appendToFile(src, dest) {
2911
- const content = fs7.readFileSync(src, "utf-8");
2956
+ const content = fs9.readFileSync(src, "utf-8");
2912
2957
  let existingContent = "";
2913
- if (fs7.existsSync(dest)) {
2914
- existingContent = fs7.readFileSync(dest, "utf-8");
2958
+ if (fs9.existsSync(dest)) {
2959
+ existingContent = fs9.readFileSync(dest, "utf-8");
2915
2960
  }
2916
2961
  if (existingContent.includes(content.trim())) {
2917
- console.log(`[fullstack-cli] \u25CB ${path5.basename(dest)} (already contains content)`);
2962
+ console.log(`[fullstack-cli] \u25CB ${path6.basename(dest)} (already contains content)`);
2918
2963
  return;
2919
2964
  }
2920
- fs7.appendFileSync(dest, content);
2921
- console.log(`[fullstack-cli] \u2713 ${path5.basename(dest)} (appended)`);
2965
+ fs9.appendFileSync(dest, content);
2966
+ console.log(`[fullstack-cli] \u2713 ${path6.basename(dest)} (appended)`);
2922
2967
  }
2923
2968
  function setPermissions(permissions, projectRoot) {
2924
2969
  for (const [pattern, mode] of Object.entries(permissions)) {
2925
2970
  if (pattern === "**/*.sh") {
2926
- const scriptsDir = path5.join(projectRoot, "scripts");
2927
- if (fs7.existsSync(scriptsDir)) {
2928
- const files = fs7.readdirSync(scriptsDir);
2971
+ const scriptsDir = path6.join(projectRoot, "scripts");
2972
+ if (fs9.existsSync(scriptsDir)) {
2973
+ const files = fs9.readdirSync(scriptsDir);
2929
2974
  files.forEach((file) => {
2930
2975
  if (file.endsWith(".sh")) {
2931
- const filePath = path5.join(scriptsDir, file);
2932
- fs7.chmodSync(filePath, mode);
2976
+ const filePath = path6.join(scriptsDir, file);
2977
+ fs9.chmodSync(filePath, mode);
2933
2978
  }
2934
2979
  });
2935
2980
  }
@@ -2937,27 +2982,27 @@ function setPermissions(permissions, projectRoot) {
2937
2982
  }
2938
2983
  }
2939
2984
  function deleteFile(filePath) {
2940
- if (fs7.existsSync(filePath)) {
2941
- fs7.unlinkSync(filePath);
2942
- console.log(`[fullstack-cli] \u2713 ${path5.basename(filePath)} (deleted)`);
2985
+ if (fs9.existsSync(filePath)) {
2986
+ fs9.unlinkSync(filePath);
2987
+ console.log(`[fullstack-cli] \u2713 ${path6.basename(filePath)} (deleted)`);
2943
2988
  } else {
2944
- console.log(`[fullstack-cli] \u25CB ${path5.basename(filePath)} (not found)`);
2989
+ console.log(`[fullstack-cli] \u25CB ${path6.basename(filePath)} (not found)`);
2945
2990
  }
2946
2991
  }
2947
2992
  function deleteDirectory(dirPath) {
2948
- if (fs7.existsSync(dirPath)) {
2949
- fs7.rmSync(dirPath, { recursive: true });
2950
- console.log(`[fullstack-cli] \u2713 ${path5.basename(dirPath)} (deleted)`);
2993
+ if (fs9.existsSync(dirPath)) {
2994
+ fs9.rmSync(dirPath, { recursive: true });
2995
+ console.log(`[fullstack-cli] \u2713 ${path6.basename(dirPath)} (deleted)`);
2951
2996
  } else {
2952
- console.log(`[fullstack-cli] \u25CB ${path5.basename(dirPath)} (not found)`);
2997
+ console.log(`[fullstack-cli] \u25CB ${path6.basename(dirPath)} (not found)`);
2953
2998
  }
2954
2999
  }
2955
3000
  function addScript(packageJsonPath, name, command, overwrite) {
2956
- if (!fs7.existsSync(packageJsonPath)) {
3001
+ if (!fs9.existsSync(packageJsonPath)) {
2957
3002
  console.log(`[fullstack-cli] \u25CB package.json (not found)`);
2958
3003
  return;
2959
3004
  }
2960
- const content = fs7.readFileSync(packageJsonPath, "utf-8");
3005
+ const content = fs9.readFileSync(packageJsonPath, "utf-8");
2961
3006
  const pkg2 = JSON.parse(content);
2962
3007
  if (!pkg2.scripts) {
2963
3008
  pkg2.scripts = {};
@@ -2969,16 +3014,16 @@ function addScript(packageJsonPath, name, command, overwrite) {
2969
3014
  }
2970
3015
  }
2971
3016
  pkg2.scripts[name] = command;
2972
- fs7.writeFileSync(packageJsonPath, JSON.stringify(pkg2, null, 2) + "\n");
3017
+ fs9.writeFileSync(packageJsonPath, JSON.stringify(pkg2, null, 2) + "\n");
2973
3018
  console.log(`[fullstack-cli] \u2713 scripts.${name}`);
2974
3019
  }
2975
3020
  function patchScript(packageJsonPath, name, to, ifStartsWith) {
2976
- if (!fs7.existsSync(packageJsonPath)) {
3021
+ if (!fs9.existsSync(packageJsonPath)) {
2977
3022
  console.log(`[fullstack-cli] \u25CB package.json (not found)`);
2978
3023
  return;
2979
3024
  }
2980
3025
  try {
2981
- const content = fs7.readFileSync(packageJsonPath, "utf-8");
3026
+ const content = fs9.readFileSync(packageJsonPath, "utf-8");
2982
3027
  const pkg2 = JSON.parse(content);
2983
3028
  const current = pkg2.scripts?.[name];
2984
3029
  if (!current) {
@@ -2996,7 +3041,7 @@ function patchScript(packageJsonPath, name, to, ifStartsWith) {
2996
3041
  return;
2997
3042
  }
2998
3043
  pkg2.scripts[name] = to;
2999
- fs7.writeFileSync(packageJsonPath, JSON.stringify(pkg2, null, 2) + "\n");
3044
+ fs9.writeFileSync(packageJsonPath, JSON.stringify(pkg2, null, 2) + "\n");
3000
3045
  console.log(`[fullstack-cli] \u2713 Patched scripts.${name}`);
3001
3046
  } catch (error) {
3002
3047
  const message = error instanceof Error ? error.message : String(error);
@@ -3004,38 +3049,38 @@ function patchScript(packageJsonPath, name, to, ifStartsWith) {
3004
3049
  }
3005
3050
  }
3006
3051
  function addLineToFile(filePath, line) {
3007
- const fileName = path5.basename(filePath);
3008
- if (!fs7.existsSync(filePath)) {
3052
+ const fileName = path6.basename(filePath);
3053
+ if (!fs9.existsSync(filePath)) {
3009
3054
  console.log(`[fullstack-cli] \u25CB ${fileName} (not found, skipped)`);
3010
3055
  return;
3011
3056
  }
3012
- const content = fs7.readFileSync(filePath, "utf-8");
3057
+ const content = fs9.readFileSync(filePath, "utf-8");
3013
3058
  const lines = content.split("\n").map((l) => l.trim());
3014
3059
  if (lines.includes(line)) {
3015
3060
  console.log(`[fullstack-cli] \u25CB ${fileName} (line already exists: ${line})`);
3016
3061
  return;
3017
3062
  }
3018
3063
  const appendContent = (content.endsWith("\n") ? "" : "\n") + line + "\n";
3019
- fs7.appendFileSync(filePath, appendContent);
3064
+ fs9.appendFileSync(filePath, appendContent);
3020
3065
  console.log(`[fullstack-cli] \u2713 ${fileName} (added: ${line})`);
3021
3066
  }
3022
3067
  function mergeJsonFile(src, dest, arrayMerge) {
3023
- const fileName = path5.basename(dest);
3024
- if (!fs7.existsSync(src)) {
3068
+ const fileName = path6.basename(dest);
3069
+ if (!fs9.existsSync(src)) {
3025
3070
  console.warn(`[fullstack-cli] Source not found: ${src}`);
3026
3071
  return;
3027
3072
  }
3028
- const templateContent = JSON.parse(fs7.readFileSync(src, "utf-8"));
3029
- if (!fs7.existsSync(dest)) {
3030
- const destDir = path5.dirname(dest);
3031
- if (!fs7.existsSync(destDir)) {
3032
- fs7.mkdirSync(destDir, { recursive: true });
3073
+ const templateContent = JSON.parse(fs9.readFileSync(src, "utf-8"));
3074
+ if (!fs9.existsSync(dest)) {
3075
+ const destDir = path6.dirname(dest);
3076
+ if (!fs9.existsSync(destDir)) {
3077
+ fs9.mkdirSync(destDir, { recursive: true });
3033
3078
  }
3034
- fs7.writeFileSync(dest, JSON.stringify(templateContent, null, 2) + "\n");
3079
+ fs9.writeFileSync(dest, JSON.stringify(templateContent, null, 2) + "\n");
3035
3080
  console.log(`[fullstack-cli] \u2713 ${fileName} (created)`);
3036
3081
  return;
3037
3082
  }
3038
- const userContent = JSON.parse(fs7.readFileSync(dest, "utf-8"));
3083
+ const userContent = JSON.parse(fs9.readFileSync(dest, "utf-8"));
3039
3084
  const merged = deepMergeJson(userContent, templateContent, arrayMerge ?? {});
3040
3085
  const userStr = JSON.stringify(userContent, null, 2);
3041
3086
  const mergedStr = JSON.stringify(merged, null, 2);
@@ -3043,7 +3088,7 @@ function mergeJsonFile(src, dest, arrayMerge) {
3043
3088
  console.log(`[fullstack-cli] \u25CB ${fileName} (already up to date)`);
3044
3089
  return;
3045
3090
  }
3046
- fs7.writeFileSync(dest, mergedStr + "\n");
3091
+ fs9.writeFileSync(dest, mergedStr + "\n");
3047
3092
  console.log(`[fullstack-cli] \u2713 ${fileName} (merged)`);
3048
3093
  }
3049
3094
 
@@ -3058,6 +3103,105 @@ var syncCommand = {
3058
3103
  }
3059
3104
  };
3060
3105
 
3106
+ // src/utils/api-error.ts
3107
+ var LOGID_HEADER = "x-tt-logid";
3108
+ var ERROR_RESPONSE_PREVIEW_LIMIT = 2e3;
3109
+ var InnerApiError = class _InnerApiError extends Error {
3110
+ constructor(message, detail = {}) {
3111
+ super(message);
3112
+ this.name = "InnerApiError";
3113
+ this.logId = detail.logId ?? "";
3114
+ this.status = detail.status;
3115
+ this.body = detail.body;
3116
+ if (detail.cause !== void 0) {
3117
+ this.cause = detail.cause;
3118
+ }
3119
+ Object.setPrototypeOf(this, _InnerApiError.prototype);
3120
+ }
3121
+ };
3122
+ function getLogId(response) {
3123
+ const headers = response?.headers;
3124
+ if (!headers || typeof headers !== "object") {
3125
+ return "";
3126
+ }
3127
+ try {
3128
+ const getter = headers.get;
3129
+ if (typeof getter === "function") {
3130
+ return getter.call(headers, LOGID_HEADER) ?? "";
3131
+ }
3132
+ const value = headers[LOGID_HEADER];
3133
+ return typeof value === "string" ? value : "";
3134
+ } catch {
3135
+ return "";
3136
+ }
3137
+ }
3138
+ function formatLogId(response) {
3139
+ const logId = getLogId(response);
3140
+ return logId ? `, logid: ${logId}` : "";
3141
+ }
3142
+ async function readErrorBody(response) {
3143
+ try {
3144
+ if (typeof response.text === "function") {
3145
+ const text = await response.text();
3146
+ return text ? text.slice(0, ERROR_RESPONSE_PREVIEW_LIMIT) : "";
3147
+ }
3148
+ if (typeof response.json === "function") {
3149
+ const serialized = JSON.stringify(await response.json());
3150
+ return serialized ? serialized.slice(0, ERROR_RESPONSE_PREVIEW_LIMIT) : "";
3151
+ }
3152
+ } catch {
3153
+ return "";
3154
+ }
3155
+ return "";
3156
+ }
3157
+ function asHttpErrorResponse(error) {
3158
+ if (!error || typeof error !== "object") {
3159
+ return void 0;
3160
+ }
3161
+ const response = error.response;
3162
+ return response && typeof response === "object" ? response : void 0;
3163
+ }
3164
+ async function buildError(message, response, cause) {
3165
+ if (!response) {
3166
+ const reason = cause instanceof Error ? cause.message : String(cause);
3167
+ return new InnerApiError(`${message}: ${reason}`, { cause });
3168
+ }
3169
+ const logId = getLogId(response);
3170
+ const body = await readErrorBody(response);
3171
+ const parts = [`${message}: ${response.status ?? "unknown"}`];
3172
+ if (response.statusText) {
3173
+ parts.push(` ${response.statusText}`);
3174
+ }
3175
+ if (logId) {
3176
+ parts.push(`, logid: ${logId}`);
3177
+ }
3178
+ if (body) {
3179
+ parts.push(`, response: ${body}`);
3180
+ }
3181
+ return new InnerApiError(parts.join(""), {
3182
+ logId,
3183
+ status: response.status,
3184
+ body,
3185
+ cause
3186
+ });
3187
+ }
3188
+ async function requestWithLogId(send, message, options = {}) {
3189
+ let response;
3190
+ try {
3191
+ response = await send();
3192
+ } catch (error) {
3193
+ throw await buildError(message, asHttpErrorResponse(error), error);
3194
+ }
3195
+ if (!response) {
3196
+ throw new InnerApiError(`${message}: \u672A\u62FF\u5230\u54CD\u5E94\u5BF9\u8C61`);
3197
+ }
3198
+ const isOk = options.expectStatus200 ? response.ok !== false && response.status === 200 : response.ok === true;
3199
+ if (!isOk) {
3200
+ throw await buildError(message, response, void 0);
3201
+ }
3202
+ return response;
3203
+ }
3204
+
3061
3205
  // src/utils/telemetry.ts
3062
3206
  async function reportEvents(events) {
3063
3207
  if (events.length === 0) {
@@ -3065,14 +3209,13 @@ async function reportEvents(events) {
3065
3209
  }
3066
3210
  try {
3067
3211
  const client = getHttpClient();
3068
- const response = await client.post("/api/v1/studio/innerapi/resource_events", { events });
3069
- if (!response.ok) {
3070
- console.warn(`[telemetry] Failed to report events: ${response.status} ${response.statusText}`);
3071
- return false;
3072
- }
3212
+ const response = await requestWithLogId(
3213
+ () => client.post("/api/v1/studio/innerapi/resource_events", { events }),
3214
+ "resource_events \u8BF7\u6C42\u5931\u8D25"
3215
+ );
3073
3216
  const result = await response.json();
3074
3217
  if (result.status_code !== "0") {
3075
- console.warn(`[telemetry] API error: ${result.message}`);
3218
+ console.warn(`[telemetry] API error: ${result.message}${formatLogId(response)}`);
3076
3219
  return false;
3077
3220
  }
3078
3221
  return true;
@@ -3104,12 +3247,12 @@ async function reportCreateInstanceEvent(pluginKey, version) {
3104
3247
 
3105
3248
  // src/utils/git.ts
3106
3249
  import { execSync, spawnSync as spawnSync3 } from "child_process";
3107
- import fs8 from "fs";
3108
- import path6 from "path";
3250
+ import fs10 from "fs";
3251
+ import path7 from "path";
3109
3252
  function isGitRepository(cwd = process.cwd()) {
3110
3253
  try {
3111
- const gitDir = path6.join(cwd, ".git");
3112
- if (fs8.existsSync(gitDir)) {
3254
+ const gitDir = path7.join(cwd, ".git");
3255
+ if (fs10.existsSync(gitDir)) {
3113
3256
  return true;
3114
3257
  }
3115
3258
  const result = spawnSync3("git", ["rev-parse", "--git-dir"], {
@@ -3138,7 +3281,7 @@ function getChangedFiles(cwd = process.cwd()) {
3138
3281
  function gitAddUpgradeFiles(cwd = process.cwd(), filesToStage) {
3139
3282
  const filteredFiles = [];
3140
3283
  for (const filePath of filesToStage) {
3141
- if (fs8.existsSync(path6.join(cwd, filePath))) {
3284
+ if (fs10.existsSync(path7.join(cwd, filePath))) {
3142
3285
  filteredFiles.push(filePath);
3143
3286
  continue;
3144
3287
  }
@@ -3223,20 +3366,20 @@ Auto-committed by fullstack-cli`;
3223
3366
  }
3224
3367
 
3225
3368
  // src/utils/package-json.ts
3226
- import fs9 from "fs";
3227
- import path7 from "path";
3369
+ import fs11 from "fs";
3370
+ import path8 from "path";
3228
3371
  function readPackageJson(cwd = process.cwd()) {
3229
- const pkgPath = path7.join(cwd, "package.json");
3230
- if (!fs9.existsSync(pkgPath)) {
3372
+ const pkgPath = path8.join(cwd, "package.json");
3373
+ if (!fs11.existsSync(pkgPath)) {
3231
3374
  throw new Error(`package.json not found at ${pkgPath}`);
3232
3375
  }
3233
- const content = fs9.readFileSync(pkgPath, "utf-8");
3376
+ const content = fs11.readFileSync(pkgPath, "utf-8");
3234
3377
  return JSON.parse(content);
3235
3378
  }
3236
3379
  function writePackageJson(pkg2, cwd = process.cwd()) {
3237
- const pkgPath = path7.join(cwd, "package.json");
3380
+ const pkgPath = path8.join(cwd, "package.json");
3238
3381
  const content = JSON.stringify(pkg2, null, 2) + "\n";
3239
- fs9.writeFileSync(pkgPath, content, "utf-8");
3382
+ fs11.writeFileSync(pkgPath, content, "utf-8");
3240
3383
  }
3241
3384
  function removeUpgradeScript(pkg2) {
3242
3385
  if (!pkg2.scripts?.upgrade) {
@@ -3281,15 +3424,15 @@ function cleanupPackageJson(cwd = process.cwd()) {
3281
3424
  }
3282
3425
 
3283
3426
  // src/commands/upgrade/shared/utils.ts
3284
- import path8 from "path";
3285
- import fs10 from "fs";
3427
+ import path9 from "path";
3428
+ import fs12 from "fs";
3286
3429
  import { fileURLToPath as fileURLToPath4 } from "url";
3287
3430
  function getCliVersion() {
3288
3431
  try {
3289
3432
  const __filename = fileURLToPath4(import.meta.url);
3290
- const __dirname2 = path8.dirname(__filename);
3291
- const pkgPath = path8.resolve(__dirname2, "../../../package.json");
3292
- const pkgContent = fs10.readFileSync(pkgPath, "utf-8");
3433
+ const __dirname2 = path9.dirname(__filename);
3434
+ const pkgPath = path9.resolve(__dirname2, "../../../package.json");
3435
+ const pkgContent = fs12.readFileSync(pkgPath, "utf-8");
3293
3436
  const pkg2 = JSON.parse(pkgContent);
3294
3437
  return pkg2.version || "unknown";
3295
3438
  } catch {
@@ -3298,11 +3441,14 @@ function getCliVersion() {
3298
3441
  }
3299
3442
 
3300
3443
  // src/commands/upgrade/get-upgrade-files.ts
3301
- function getUpgradeFilesToStage(disableGenOpenapi = true) {
3302
- const syncConfig = genSyncConfig(void 0, { disableGenOpenapi });
3444
+ function getUpgradeFilesToStage(disableGenOpenapi = true, userProjectRoot = process.env.INIT_CWD || process.cwd()) {
3445
+ const stack = resolveStack(userProjectRoot);
3446
+ const isNestjs = isNestjsProject(userProjectRoot, stack);
3447
+ const syncConfig = genSyncConfig(stack, { disableGenOpenapi });
3303
3448
  const filesToStage = /* @__PURE__ */ new Set();
3304
3449
  syncConfig.sync.forEach((rule) => {
3305
- if (rule.type === "file" || rule.type === "directory" || rule.type === "merge-json") {
3450
+ if (rule.onlyNestjs && !isNestjs) return;
3451
+ if (rule.type === "file" || rule.type === "directory" || rule.type === "merge-json" || rule.type === "typescript-exclude") {
3306
3452
  filesToStage.add(rule.to);
3307
3453
  } else if (rule.type === "remove-line" || rule.type === "add-line") {
3308
3454
  filesToStage.add(rule.to);
@@ -3333,7 +3479,7 @@ async function run3(options = {}) {
3333
3479
  if (shouldCommit) {
3334
3480
  console.log("[fullstack-cli] Step 3/3: Committing changes...");
3335
3481
  const version = getCliVersion();
3336
- const filesToStage = getUpgradeFilesToStage(options.disableGenOpenapi ?? true);
3482
+ const filesToStage = getUpgradeFilesToStage(options.disableGenOpenapi ?? true, userProjectRoot);
3337
3483
  autoCommitUpgradeChanges(version, userProjectRoot, filesToStage);
3338
3484
  } else {
3339
3485
  console.log("[fullstack-cli] Step 3/3: Skipping commit (--no-commit flag)");
@@ -3348,8 +3494,8 @@ async function run3(options = {}) {
3348
3494
 
3349
3495
  // src/commands/upgrade/deps/run.handler.ts
3350
3496
  import { spawnSync as spawnSync4 } from "child_process";
3351
- import fs11 from "fs";
3352
- import path9 from "path";
3497
+ import fs13 from "fs";
3498
+ import path10 from "path";
3353
3499
 
3354
3500
  // src/utils/grayscale/config.ts
3355
3501
  function getGrayscaleConfig(configJson) {
@@ -3597,8 +3743,8 @@ function installGrayscaleVersions(packages, grayscaleVersions, cwd, dryRun, mode
3597
3743
  if (version) {
3598
3744
  let current = "";
3599
3745
  try {
3600
- const installedPkgPath = path9.join(cwd, "node_modules", pkg2, "package.json");
3601
- const installedPkg = JSON.parse(fs11.readFileSync(installedPkgPath, "utf-8"));
3746
+ const installedPkgPath = path10.join(cwd, "node_modules", pkg2, "package.json");
3747
+ const installedPkg = JSON.parse(fs13.readFileSync(installedPkgPath, "utf-8"));
3602
3748
  current = installedPkg.version || "";
3603
3749
  } catch (err) {
3604
3750
  const code = err?.code;
@@ -3716,8 +3862,8 @@ var depsCommand = {
3716
3862
 
3717
3863
  // src/commands/upgrade/global-deps/run.handler.ts
3718
3864
  import { spawnSync as spawnSync5 } from "child_process";
3719
- import fs12 from "fs";
3720
- import path10 from "path";
3865
+ import fs14 from "fs";
3866
+ import path11 from "path";
3721
3867
  var MANAGED_GLOBAL_CLIS = [
3722
3868
  "@lark-apaas/fullstack-cli",
3723
3869
  "@lark-apaas/miaoda-cli"
@@ -3728,15 +3874,15 @@ function readGlobalInstalledVersion(pkg2) {
3728
3874
  if (process.env.NPM_CONFIG_PREFIX) candidates.push(process.env.NPM_CONFIG_PREFIX);
3729
3875
  candidates.push("/usr");
3730
3876
  candidates.push("/usr/local");
3731
- if (process.env.HOME) candidates.push(path10.join(process.env.HOME, ".npm-global"));
3877
+ if (process.env.HOME) candidates.push(path11.join(process.env.HOME, ".npm-global"));
3732
3878
  const seen = /* @__PURE__ */ new Set();
3733
3879
  for (const prefix of candidates) {
3734
3880
  if (seen.has(prefix)) continue;
3735
3881
  seen.add(prefix);
3736
3882
  try {
3737
- const pkgPath = path10.join(prefix, "lib", "node_modules", pkg2, "package.json");
3738
- if (fs12.existsSync(pkgPath)) {
3739
- const meta = JSON.parse(fs12.readFileSync(pkgPath, "utf-8"));
3883
+ const pkgPath = path11.join(prefix, "lib", "node_modules", pkg2, "package.json");
3884
+ if (fs14.existsSync(pkgPath)) {
3885
+ const meta = JSON.parse(fs14.readFileSync(pkgPath, "utf-8"));
3740
3886
  if (meta && typeof meta.version === "string") return meta.version;
3741
3887
  }
3742
3888
  } catch (err) {
@@ -3833,8 +3979,8 @@ var upgradeCommand = {
3833
3979
  };
3834
3980
 
3835
3981
  // src/commands/action-plugin/utils.ts
3836
- import fs13 from "fs";
3837
- import path11 from "path";
3982
+ import fs15 from "fs";
3983
+ import path12 from "path";
3838
3984
  import { spawnSync as spawnSync6, execSync as execSync2 } from "child_process";
3839
3985
  function parsePluginName(input) {
3840
3986
  const match = input.match(/^(@[^/]+\/[^@]+)(?:@(.+))?$/);
@@ -3852,18 +3998,18 @@ function getProjectRoot() {
3852
3998
  return process.cwd();
3853
3999
  }
3854
4000
  function getPackageJsonPath() {
3855
- return path11.join(getProjectRoot(), "package.json");
4001
+ return path12.join(getProjectRoot(), "package.json");
3856
4002
  }
3857
4003
  function getPluginPath(pluginName) {
3858
- return path11.join(getProjectRoot(), "node_modules", pluginName);
4004
+ return path12.join(getProjectRoot(), "node_modules", pluginName);
3859
4005
  }
3860
4006
  function readPackageJson2() {
3861
4007
  const pkgPath = getPackageJsonPath();
3862
- if (!fs13.existsSync(pkgPath)) {
4008
+ if (!fs15.existsSync(pkgPath)) {
3863
4009
  throw new Error("package.json not found in current directory");
3864
4010
  }
3865
4011
  try {
3866
- const content = fs13.readFileSync(pkgPath, "utf-8");
4012
+ const content = fs15.readFileSync(pkgPath, "utf-8");
3867
4013
  return JSON.parse(content);
3868
4014
  } catch {
3869
4015
  throw new Error("Failed to parse package.json");
@@ -3871,7 +4017,7 @@ function readPackageJson2() {
3871
4017
  }
3872
4018
  function writePackageJson2(pkg2) {
3873
4019
  const pkgPath = getPackageJsonPath();
3874
- fs13.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
4020
+ fs15.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
3875
4021
  }
3876
4022
  function readActionPlugins() {
3877
4023
  const pkg2 = readPackageJson2();
@@ -3904,12 +4050,12 @@ function npmInstall(tgzPath) {
3904
4050
  }
3905
4051
  }
3906
4052
  function getPackageVersion(pluginName) {
3907
- const pkgJsonPath = path11.join(getPluginPath(pluginName), "package.json");
3908
- if (!fs13.existsSync(pkgJsonPath)) {
4053
+ const pkgJsonPath = path12.join(getPluginPath(pluginName), "package.json");
4054
+ if (!fs15.existsSync(pkgJsonPath)) {
3909
4055
  return null;
3910
4056
  }
3911
4057
  try {
3912
- const content = fs13.readFileSync(pkgJsonPath, "utf-8");
4058
+ const content = fs15.readFileSync(pkgJsonPath, "utf-8");
3913
4059
  const pkg2 = JSON.parse(content);
3914
4060
  return pkg2.version || null;
3915
4061
  } catch {
@@ -3917,49 +4063,49 @@ function getPackageVersion(pluginName) {
3917
4063
  }
3918
4064
  }
3919
4065
  function readPluginPackageJson(pluginPath) {
3920
- const pkgJsonPath = path11.join(pluginPath, "package.json");
3921
- if (!fs13.existsSync(pkgJsonPath)) {
4066
+ const pkgJsonPath = path12.join(pluginPath, "package.json");
4067
+ if (!fs15.existsSync(pkgJsonPath)) {
3922
4068
  return null;
3923
4069
  }
3924
4070
  try {
3925
- const content = fs13.readFileSync(pkgJsonPath, "utf-8");
4071
+ const content = fs15.readFileSync(pkgJsonPath, "utf-8");
3926
4072
  return JSON.parse(content);
3927
4073
  } catch {
3928
4074
  return null;
3929
4075
  }
3930
4076
  }
3931
4077
  function extractTgzToNodeModules(tgzPath, pluginName) {
3932
- const nodeModulesPath = path11.join(getProjectRoot(), "node_modules");
3933
- const targetDir = path11.join(nodeModulesPath, pluginName);
3934
- const scopeDir = path11.dirname(targetDir);
3935
- if (!fs13.existsSync(scopeDir)) {
3936
- fs13.mkdirSync(scopeDir, { recursive: true });
4078
+ const nodeModulesPath = path12.join(getProjectRoot(), "node_modules");
4079
+ const targetDir = path12.join(nodeModulesPath, pluginName);
4080
+ const scopeDir = path12.dirname(targetDir);
4081
+ if (!fs15.existsSync(scopeDir)) {
4082
+ fs15.mkdirSync(scopeDir, { recursive: true });
3937
4083
  }
3938
- if (fs13.existsSync(targetDir)) {
3939
- fs13.rmSync(targetDir, { recursive: true });
4084
+ if (fs15.existsSync(targetDir)) {
4085
+ fs15.rmSync(targetDir, { recursive: true });
3940
4086
  }
3941
- const tempDir = path11.join(nodeModulesPath, ".cache", "fullstack-cli", "extract-temp");
3942
- if (fs13.existsSync(tempDir)) {
3943
- fs13.rmSync(tempDir, { recursive: true });
4087
+ const tempDir = path12.join(nodeModulesPath, ".cache", "fullstack-cli", "extract-temp");
4088
+ if (fs15.existsSync(tempDir)) {
4089
+ fs15.rmSync(tempDir, { recursive: true });
3944
4090
  }
3945
- fs13.mkdirSync(tempDir, { recursive: true });
4091
+ fs15.mkdirSync(tempDir, { recursive: true });
3946
4092
  try {
3947
4093
  execSync2(`tar -xzf "${tgzPath}" -C "${tempDir}"`, { stdio: "pipe" });
3948
- const extractedDir = path11.join(tempDir, "package");
3949
- if (fs13.existsSync(extractedDir)) {
3950
- fs13.renameSync(extractedDir, targetDir);
4094
+ const extractedDir = path12.join(tempDir, "package");
4095
+ if (fs15.existsSync(extractedDir)) {
4096
+ fs15.renameSync(extractedDir, targetDir);
3951
4097
  } else {
3952
- const files = fs13.readdirSync(tempDir);
4098
+ const files = fs15.readdirSync(tempDir);
3953
4099
  if (files.length === 1) {
3954
- fs13.renameSync(path11.join(tempDir, files[0]), targetDir);
4100
+ fs15.renameSync(path12.join(tempDir, files[0]), targetDir);
3955
4101
  } else {
3956
4102
  throw new Error("Unexpected tgz structure");
3957
4103
  }
3958
4104
  }
3959
4105
  return targetDir;
3960
4106
  } finally {
3961
- if (fs13.existsSync(tempDir)) {
3962
- fs13.rmSync(tempDir, { recursive: true });
4107
+ if (fs15.existsSync(tempDir)) {
4108
+ fs15.rmSync(tempDir, { recursive: true });
3963
4109
  }
3964
4110
  }
3965
4111
  }
@@ -3968,10 +4114,10 @@ function checkMissingPeerDeps(peerDeps) {
3968
4114
  return [];
3969
4115
  }
3970
4116
  const missing = [];
3971
- const nodeModulesPath = path11.join(getProjectRoot(), "node_modules");
4117
+ const nodeModulesPath = path12.join(getProjectRoot(), "node_modules");
3972
4118
  for (const [depName, _version] of Object.entries(peerDeps)) {
3973
- const depPath = path11.join(nodeModulesPath, depName);
3974
- if (!fs13.existsSync(depPath)) {
4119
+ const depPath = path12.join(nodeModulesPath, depName);
4120
+ if (!fs15.existsSync(depPath)) {
3975
4121
  missing.push(depName);
3976
4122
  }
3977
4123
  }
@@ -3995,27 +4141,28 @@ function installMissingDeps(deps) {
3995
4141
  }
3996
4142
  function removePluginDirectory(pluginName) {
3997
4143
  const pluginPath = getPluginPath(pluginName);
3998
- if (fs13.existsSync(pluginPath)) {
3999
- fs13.rmSync(pluginPath, { recursive: true });
4144
+ if (fs15.existsSync(pluginPath)) {
4145
+ fs15.rmSync(pluginPath, { recursive: true });
4000
4146
  console.log(`[action-plugin] Removed ${pluginName}`);
4001
4147
  }
4002
4148
  }
4003
4149
 
4004
4150
  // src/commands/action-plugin/api-client.ts
4005
4151
  import { HttpClient as HttpClient2 } from "@lark-apaas/http-client";
4006
- import fs14 from "fs";
4007
- import path12 from "path";
4152
+ import fs16 from "fs";
4153
+ import path13 from "path";
4008
4154
  var PLUGIN_CACHE_DIR = "node_modules/.cache/fullstack-cli/plugins";
4009
4155
  async function getPluginVersions(keys, latestOnly = true) {
4010
4156
  const client = getHttpClient();
4011
- const response = await client.post(`/api/v1/studio/innerapi/plugins/-/versions/batch_get?keys=${keys.join(",")}&latest_only=${latestOnly}`);
4012
- if (!response.ok || response.status !== 200) {
4013
- throw new Error(`Failed to get plugin versions: ${response.status} ${response.statusText}`);
4014
- }
4157
+ const response = await requestWithLogId(
4158
+ () => client.post(`/api/v1/studio/innerapi/plugins/-/versions/batch_get?keys=${keys.join(",")}&latest_only=${latestOnly}`),
4159
+ "Failed to get plugin versions",
4160
+ { expectStatus200: true }
4161
+ );
4015
4162
  const result = await response.json();
4016
4163
  console.log("getPluginVersions response:", result);
4017
4164
  if (result.status_code !== "0") {
4018
- throw new Error(`API error: ${result.message}`);
4165
+ throw new Error(`API error: ${result.message}${formatLogId(response)}`);
4019
4166
  }
4020
4167
  return result.data.pluginVersions;
4021
4168
  }
@@ -4049,10 +4196,10 @@ async function downloadFromInner(pluginKey, version) {
4049
4196
  const { scope, name } = parsePluginKey(pluginKey);
4050
4197
  const url = `/api/v1/studio/innerapi/plugins/${scope}/${name}/versions/${version}/package`;
4051
4198
  console.log(`[action-plugin] Downloading plugin from inner API: ${url}`);
4052
- const response = await client.get(url);
4053
- if (!response.ok) {
4054
- throw new Error(`Failed to download plugin: ${response.status} ${response.statusText}`);
4055
- }
4199
+ const response = await requestWithLogId(
4200
+ () => client.get(url),
4201
+ "Failed to download plugin"
4202
+ );
4056
4203
  const arrayBuffer = await response.arrayBuffer();
4057
4204
  return Buffer.from(arrayBuffer);
4058
4205
  }
@@ -4060,27 +4207,27 @@ async function downloadFromPublic(downloadURL) {
4060
4207
  const client = new HttpClient2({
4061
4208
  timeout: 6e4
4062
4209
  });
4063
- const response = await client.get(downloadURL);
4064
- if (!response.ok) {
4065
- throw new Error(`Failed to download plugin from public URL: ${response.status} ${response.statusText}`);
4066
- }
4210
+ const response = await requestWithLogId(
4211
+ () => client.get(downloadURL),
4212
+ "Failed to download plugin from public URL"
4213
+ );
4067
4214
  const arrayBuffer = await response.arrayBuffer();
4068
4215
  return Buffer.from(arrayBuffer);
4069
4216
  }
4070
4217
  function getPluginCacheDir() {
4071
- return path12.join(process.cwd(), PLUGIN_CACHE_DIR);
4218
+ return path13.join(process.cwd(), PLUGIN_CACHE_DIR);
4072
4219
  }
4073
4220
  function ensureCacheDir() {
4074
4221
  const cacheDir = getPluginCacheDir();
4075
- if (!fs14.existsSync(cacheDir)) {
4076
- fs14.mkdirSync(cacheDir, { recursive: true });
4222
+ if (!fs16.existsSync(cacheDir)) {
4223
+ fs16.mkdirSync(cacheDir, { recursive: true });
4077
4224
  }
4078
4225
  }
4079
4226
  function getTempFilePath(pluginKey, version) {
4080
4227
  ensureCacheDir();
4081
4228
  const safeKey = pluginKey.replace(/[/@]/g, "_");
4082
4229
  const filename = `${safeKey}@${version}.tgz`;
4083
- return path12.join(getPluginCacheDir(), filename);
4230
+ return path13.join(getPluginCacheDir(), filename);
4084
4231
  }
4085
4232
  var MAX_RETRIES = 2;
4086
4233
  async function withRetry(operation, description, maxRetries = MAX_RETRIES) {
@@ -4117,7 +4264,7 @@ async function downloadPlugin(pluginKey, requestedVersion) {
4117
4264
  );
4118
4265
  }
4119
4266
  const tgzPath = getTempFilePath(pluginKey, pluginInfo.version);
4120
- fs14.writeFileSync(tgzPath, tgzBuffer);
4267
+ fs16.writeFileSync(tgzPath, tgzBuffer);
4121
4268
  console.log(`[action-plugin] Downloaded to ${tgzPath} (${(tgzBuffer.length / 1024).toFixed(2)} KB)`);
4122
4269
  return {
4123
4270
  tgzPath,
@@ -4131,18 +4278,18 @@ function getCachePath(pluginKey, version) {
4131
4278
  ensureCacheDir();
4132
4279
  const safeKey = pluginKey.replace(/[/@]/g, "_");
4133
4280
  const filename = `${safeKey}@${version}.tgz`;
4134
- return path12.join(getPluginCacheDir(), filename);
4281
+ return path13.join(getPluginCacheDir(), filename);
4135
4282
  }
4136
4283
  function hasCachedPlugin(pluginKey, version) {
4137
4284
  const cachePath = getCachePath(pluginKey, version);
4138
- return fs14.existsSync(cachePath);
4285
+ return fs16.existsSync(cachePath);
4139
4286
  }
4140
4287
  function listCachedPlugins() {
4141
4288
  const cacheDir = getPluginCacheDir();
4142
- if (!fs14.existsSync(cacheDir)) {
4289
+ if (!fs16.existsSync(cacheDir)) {
4143
4290
  return [];
4144
4291
  }
4145
- const files = fs14.readdirSync(cacheDir);
4292
+ const files = fs16.readdirSync(cacheDir);
4146
4293
  const result = [];
4147
4294
  for (const file of files) {
4148
4295
  if (!file.endsWith(".tgz")) continue;
@@ -4150,8 +4297,8 @@ function listCachedPlugins() {
4150
4297
  if (!match) continue;
4151
4298
  const [, rawName, version] = match;
4152
4299
  const name = rawName.replace(/^_/, "@").replace(/_/, "/");
4153
- const filePath = path12.join(cacheDir, file);
4154
- const stat = fs14.statSync(filePath);
4300
+ const filePath = path13.join(cacheDir, file);
4301
+ const stat = fs16.statSync(filePath);
4155
4302
  result.push({
4156
4303
  name,
4157
4304
  version,
@@ -4164,14 +4311,14 @@ function listCachedPlugins() {
4164
4311
  }
4165
4312
  function cleanAllCache() {
4166
4313
  const cacheDir = getPluginCacheDir();
4167
- if (!fs14.existsSync(cacheDir)) {
4314
+ if (!fs16.existsSync(cacheDir)) {
4168
4315
  return 0;
4169
4316
  }
4170
- const files = fs14.readdirSync(cacheDir);
4317
+ const files = fs16.readdirSync(cacheDir);
4171
4318
  let count = 0;
4172
4319
  for (const file of files) {
4173
4320
  if (file.endsWith(".tgz")) {
4174
- fs14.unlinkSync(path12.join(cacheDir, file));
4321
+ fs16.unlinkSync(path13.join(cacheDir, file));
4175
4322
  count++;
4176
4323
  }
4177
4324
  }
@@ -4179,21 +4326,21 @@ function cleanAllCache() {
4179
4326
  }
4180
4327
  function cleanPluginCache(pluginKey, version) {
4181
4328
  const cacheDir = getPluginCacheDir();
4182
- if (!fs14.existsSync(cacheDir)) {
4329
+ if (!fs16.existsSync(cacheDir)) {
4183
4330
  return 0;
4184
4331
  }
4185
4332
  const safeKey = pluginKey.replace(/[/@]/g, "_");
4186
- const files = fs14.readdirSync(cacheDir);
4333
+ const files = fs16.readdirSync(cacheDir);
4187
4334
  let count = 0;
4188
4335
  for (const file of files) {
4189
4336
  if (version) {
4190
4337
  if (file === `${safeKey}@${version}.tgz`) {
4191
- fs14.unlinkSync(path12.join(cacheDir, file));
4338
+ fs16.unlinkSync(path13.join(cacheDir, file));
4192
4339
  count++;
4193
4340
  }
4194
4341
  } else {
4195
4342
  if (file.startsWith(`${safeKey}@`) && file.endsWith(".tgz")) {
4196
- fs14.unlinkSync(path12.join(cacheDir, file));
4343
+ fs16.unlinkSync(path13.join(cacheDir, file));
4197
4344
  count++;
4198
4345
  }
4199
4346
  }
@@ -4620,45 +4767,45 @@ var actionPluginCommandGroup = {
4620
4767
  };
4621
4768
 
4622
4769
  // src/commands/capability/utils.ts
4623
- import fs15 from "fs";
4770
+ import fs17 from "fs";
4624
4771
  import { createRequire as createRequire2 } from "module";
4625
- import path13 from "path";
4772
+ import path14 from "path";
4626
4773
  var CAPABILITIES_DIR = "server/capabilities";
4627
4774
  var SHARED_CAPABILITIES_DIR = "shared/capabilities";
4628
4775
  function getProjectRoot2() {
4629
4776
  return process.cwd();
4630
4777
  }
4631
4778
  function getCapabilitiesDir() {
4632
- const sharedDir = path13.join(getProjectRoot2(), SHARED_CAPABILITIES_DIR);
4633
- if (fs15.existsSync(sharedDir)) {
4779
+ const sharedDir = path14.join(getProjectRoot2(), SHARED_CAPABILITIES_DIR);
4780
+ if (fs17.existsSync(sharedDir)) {
4634
4781
  return sharedDir;
4635
4782
  }
4636
- return path13.join(getProjectRoot2(), CAPABILITIES_DIR);
4783
+ return path14.join(getProjectRoot2(), CAPABILITIES_DIR);
4637
4784
  }
4638
4785
  function getCapabilityPath(id) {
4639
- return path13.join(getCapabilitiesDir(), `${id}.json`);
4786
+ return path14.join(getCapabilitiesDir(), `${id}.json`);
4640
4787
  }
4641
4788
  function getPluginManifestPath(pluginKey) {
4642
- return path13.join(getProjectRoot2(), "node_modules", pluginKey, "manifest.json");
4789
+ return path14.join(getProjectRoot2(), "node_modules", pluginKey, "manifest.json");
4643
4790
  }
4644
4791
  function capabilitiesDirExists() {
4645
- return fs15.existsSync(getCapabilitiesDir());
4792
+ return fs17.existsSync(getCapabilitiesDir());
4646
4793
  }
4647
4794
  function listCapabilityIds() {
4648
4795
  const dir = getCapabilitiesDir();
4649
- if (!fs15.existsSync(dir)) {
4796
+ if (!fs17.existsSync(dir)) {
4650
4797
  return [];
4651
4798
  }
4652
- const files = fs15.readdirSync(dir);
4799
+ const files = fs17.readdirSync(dir);
4653
4800
  return files.filter((f) => f.endsWith(".json") && f !== "capabilities.json").map((f) => f.replace(/\.json$/, ""));
4654
4801
  }
4655
4802
  function readCapability(id) {
4656
4803
  const filePath = getCapabilityPath(id);
4657
- if (!fs15.existsSync(filePath)) {
4804
+ if (!fs17.existsSync(filePath)) {
4658
4805
  throw new Error(`Capability not found: ${id}`);
4659
4806
  }
4660
4807
  try {
4661
- const content = fs15.readFileSync(filePath, "utf-8");
4808
+ const content = fs17.readFileSync(filePath, "utf-8");
4662
4809
  return JSON.parse(content);
4663
4810
  } catch (error) {
4664
4811
  if (error instanceof SyntaxError) {
@@ -4685,11 +4832,11 @@ function readAllCapabilities() {
4685
4832
  }
4686
4833
  function readPluginManifest(pluginKey) {
4687
4834
  const manifestPath = getPluginManifestPath(pluginKey);
4688
- if (!fs15.existsSync(manifestPath)) {
4835
+ if (!fs17.existsSync(manifestPath)) {
4689
4836
  throw new Error(`Plugin not installed: ${pluginKey} (manifest.json not found)`);
4690
4837
  }
4691
4838
  try {
4692
- const content = fs15.readFileSync(manifestPath, "utf-8");
4839
+ const content = fs17.readFileSync(manifestPath, "utf-8");
4693
4840
  return JSON.parse(content);
4694
4841
  } catch (error) {
4695
4842
  if (error instanceof SyntaxError) {
@@ -4706,7 +4853,7 @@ function hasValidParamsSchema(paramsSchema) {
4706
4853
  }
4707
4854
  async function loadPlugin(pluginKey) {
4708
4855
  try {
4709
- const userRequire = createRequire2(path13.join(getProjectRoot2(), "package.json"));
4856
+ const userRequire = createRequire2(path14.join(getProjectRoot2(), "package.json"));
4710
4857
  const resolvedPath = userRequire.resolve(pluginKey);
4711
4858
  const pluginModule = await import(resolvedPath);
4712
4859
  const pluginPackage = pluginModule.default ?? pluginModule;
@@ -4869,8 +5016,8 @@ var capabilityCommandGroup = {
4869
5016
  import { execFile } from "child_process";
4870
5017
 
4871
5018
  // src/commands/component/registry-preparer.ts
4872
- import fs16 from "fs";
4873
- import path14 from "path";
5019
+ import fs18 from "fs";
5020
+ import path15 from "path";
4874
5021
  import os from "os";
4875
5022
 
4876
5023
  // src/commands/component/service.ts
@@ -4884,49 +5031,53 @@ var debug = createDebug("component");
4884
5031
  async function getComponents(keys) {
4885
5032
  const client = getHttpClient();
4886
5033
  debug("\u8C03\u7528 /components/batch_get %o", keys);
4887
- const response = await client.post(
4888
- `/api/v1/studio/innerapi/components/batch_get?keys=${keys.join(",")}`
5034
+ const response = await requestWithLogId(
5035
+ () => client.post(
5036
+ `/api/v1/studio/innerapi/components/batch_get?keys=${keys.join(",")}`
5037
+ ),
5038
+ "\u83B7\u53D6\u7EC4\u4EF6\u4FE1\u606F\u5931\u8D25",
5039
+ { expectStatus200: true }
4889
5040
  );
4890
- if (response.status !== 200) {
4891
- throw new Error(
4892
- `\u83B7\u53D6\u7EC4\u4EF6\u4FE1\u606F\u5931\u8D25\uFF1A${response.status} ${response.statusText}`
4893
- );
4894
- }
4895
5041
  const result = await response.json();
4896
5042
  if (result.status_code !== "0") {
4897
5043
  debug("\u63A5\u53E3\u8FD4\u56DE\u9519\u8BEF\uFF1A%o", result);
4898
- throw new Error(`\u83B7\u53D6\u7EC4\u4EF6\u4FE1\u606F\u5931\u8D25\uFF1A${result.error_msg}`);
5044
+ throw new Error(`\u83B7\u53D6\u7EC4\u4EF6\u4FE1\u606F\u5931\u8D25\uFF1A${result.error_msg}${formatLogId(response)}`);
4899
5045
  }
4900
5046
  return mapValues(result.data.components, ([component]) => component);
4901
5047
  }
4902
5048
  async function getRegistryItem(url) {
4903
5049
  const client = getHttpClient();
4904
5050
  debug("\u4E0B\u8F7D registry-item.json\uFF1A%s", url);
4905
- const response = await client.get(url);
4906
- if (!response.ok) {
4907
- throw new Error(
4908
- `\u4E0B\u8F7D registry-item.json \u5931\u8D25\uFF1A${response.status} ${response.statusText}`
4909
- );
4910
- }
5051
+ const response = await requestWithLogId(
5052
+ () => client.get(url),
5053
+ "\u4E0B\u8F7D registry-item.json \u5931\u8D25"
5054
+ );
4911
5055
  const item = await response.json();
4912
5056
  return item;
4913
5057
  }
4914
5058
  async function sendInstallEvent(key) {
4915
5059
  const client = getHttpClient();
4916
- await client.post("/api/v1/studio/innerapi/resource_events", {
4917
- events: [
4918
- {
4919
- resourceType: "component",
4920
- resourceKey: key,
4921
- eventType: "install",
4922
- details: {}
4923
- }
4924
- ]
4925
- });
5060
+ try {
5061
+ await requestWithLogId(
5062
+ () => client.post("/api/v1/studio/innerapi/resource_events", {
5063
+ events: [
5064
+ {
5065
+ resourceType: "component",
5066
+ resourceKey: key,
5067
+ eventType: "install",
5068
+ details: {}
5069
+ }
5070
+ ]
5071
+ }),
5072
+ "\u4E0A\u62A5\u7EC4\u4EF6\u5B89\u88C5\u4E8B\u4EF6\u5931\u8D25"
5073
+ );
5074
+ } catch (error) {
5075
+ console.warn(`[component] ${error instanceof Error ? error.message : error}`);
5076
+ }
4926
5077
  }
4927
5078
 
4928
5079
  // src/commands/component/registry-preparer.ts
4929
- var REGISTRY_TEMP_DIR = path14.join(os.tmpdir(), "miaoda-registry");
5080
+ var REGISTRY_TEMP_DIR = path15.join(os.tmpdir(), "miaoda-registry");
4930
5081
  function parseComponentKey(key) {
4931
5082
  const match = key.match(/^@([^/]+)\/(.+)$/);
4932
5083
  if (!match) {
@@ -4938,11 +5089,11 @@ function parseComponentKey(key) {
4938
5089
  }
4939
5090
  function getLocalRegistryPath(key) {
4940
5091
  const { scope, name } = parseComponentKey(key);
4941
- return path14.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
5092
+ return path15.join(REGISTRY_TEMP_DIR, scope, `${name}.json`);
4942
5093
  }
4943
5094
  function ensureDir(dirPath) {
4944
- if (!fs16.existsSync(dirPath)) {
4945
- fs16.mkdirSync(dirPath, { recursive: true });
5095
+ if (!fs18.existsSync(dirPath)) {
5096
+ fs18.mkdirSync(dirPath, { recursive: true });
4946
5097
  }
4947
5098
  }
4948
5099
  async function prepareRecursive(key, visited) {
@@ -4975,8 +5126,8 @@ async function prepareRecursive(key, visited) {
4975
5126
  registryDependencies: deps.map((dep) => getLocalRegistryPath(dep))
4976
5127
  };
4977
5128
  const localPath = getLocalRegistryPath(key);
4978
- ensureDir(path14.dirname(localPath));
4979
- fs16.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
5129
+ ensureDir(path15.dirname(localPath));
5130
+ fs18.writeFileSync(localPath, JSON.stringify(rewrittenItem, null, 2), "utf-8");
4980
5131
  debug("\u4FDD\u5B58\u5230: %s", localPath);
4981
5132
  }
4982
5133
  async function prepareComponentRegistryItems(id) {
@@ -4986,18 +5137,18 @@ async function prepareComponentRegistryItems(id) {
4986
5137
  }
4987
5138
  function cleanupTempDir() {
4988
5139
  try {
4989
- if (fs16.existsSync(REGISTRY_TEMP_DIR)) {
4990
- fs16.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
5140
+ if (fs18.existsSync(REGISTRY_TEMP_DIR)) {
5141
+ fs18.rmSync(REGISTRY_TEMP_DIR, { recursive: true, force: true });
4991
5142
  }
4992
5143
  } catch {
4993
5144
  }
4994
5145
  }
4995
5146
  function getDownloadedRegistryItem(itemId) {
4996
5147
  const localPath = getLocalRegistryPath(itemId);
4997
- if (!fs16.existsSync(localPath)) {
5148
+ if (!fs18.existsSync(localPath)) {
4998
5149
  return null;
4999
5150
  }
5000
- const content = fs16.readFileSync(localPath, "utf-8");
5151
+ const content = fs18.readFileSync(localPath, "utf-8");
5001
5152
  return JSON.parse(content);
5002
5153
  }
5003
5154
 
@@ -5165,58 +5316,58 @@ var componentCommandGroup = {
5165
5316
  };
5166
5317
 
5167
5318
  // src/commands/migration/version-manager.ts
5168
- import fs17 from "fs";
5169
- import path15 from "path";
5319
+ import fs19 from "fs";
5320
+ import path16 from "path";
5170
5321
  var PACKAGE_JSON = "package.json";
5171
5322
  var VERSION_FIELD = "migrationVersion";
5172
5323
  function getPackageJsonPath2() {
5173
- return path15.join(process.cwd(), PACKAGE_JSON);
5324
+ return path16.join(process.cwd(), PACKAGE_JSON);
5174
5325
  }
5175
5326
  function getCurrentVersion() {
5176
5327
  const pkgPath = getPackageJsonPath2();
5177
- if (!fs17.existsSync(pkgPath)) {
5328
+ if (!fs19.existsSync(pkgPath)) {
5178
5329
  throw new Error("package.json not found");
5179
5330
  }
5180
- const pkg2 = JSON.parse(fs17.readFileSync(pkgPath, "utf-8"));
5331
+ const pkg2 = JSON.parse(fs19.readFileSync(pkgPath, "utf-8"));
5181
5332
  return pkg2[VERSION_FIELD] ?? 0;
5182
5333
  }
5183
5334
  function setCurrentVersion(version) {
5184
5335
  const pkgPath = getPackageJsonPath2();
5185
- const pkg2 = JSON.parse(fs17.readFileSync(pkgPath, "utf-8"));
5336
+ const pkg2 = JSON.parse(fs19.readFileSync(pkgPath, "utf-8"));
5186
5337
  pkg2[VERSION_FIELD] = version;
5187
- fs17.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
5338
+ fs19.writeFileSync(pkgPath, JSON.stringify(pkg2, null, 2) + "\n", "utf-8");
5188
5339
  }
5189
5340
 
5190
5341
  // src/commands/migration/versions/v001_capability/json-migrator/detector.ts
5191
- import fs19 from "fs";
5192
- import path17 from "path";
5342
+ import fs21 from "fs";
5343
+ import path18 from "path";
5193
5344
 
5194
5345
  // src/commands/migration/versions/v001_capability/utils.ts
5195
- import fs18 from "fs";
5196
- import path16 from "path";
5346
+ import fs20 from "fs";
5347
+ import path17 from "path";
5197
5348
  var CAPABILITIES_DIR2 = "server/capabilities";
5198
5349
  function getProjectRoot3() {
5199
5350
  return process.cwd();
5200
5351
  }
5201
5352
  function getCapabilitiesDir2() {
5202
- return path16.join(getProjectRoot3(), CAPABILITIES_DIR2);
5353
+ return path17.join(getProjectRoot3(), CAPABILITIES_DIR2);
5203
5354
  }
5204
5355
  function getPluginManifestPath2(pluginKey) {
5205
- return path16.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
5356
+ return path17.join(getProjectRoot3(), "node_modules", pluginKey, "manifest.json");
5206
5357
  }
5207
5358
 
5208
5359
  // src/commands/migration/versions/v001_capability/json-migrator/detector.ts
5209
5360
  function detectJsonMigration() {
5210
5361
  const capabilitiesDir = getCapabilitiesDir2();
5211
- const oldFilePath = path17.join(capabilitiesDir, "capabilities.json");
5212
- if (!fs19.existsSync(oldFilePath)) {
5362
+ const oldFilePath = path18.join(capabilitiesDir, "capabilities.json");
5363
+ if (!fs21.existsSync(oldFilePath)) {
5213
5364
  return {
5214
5365
  needsMigration: false,
5215
5366
  reason: "capabilities.json not found"
5216
5367
  };
5217
5368
  }
5218
5369
  try {
5219
- const content = fs19.readFileSync(oldFilePath, "utf-8");
5370
+ const content = fs21.readFileSync(oldFilePath, "utf-8");
5220
5371
  const parsed = JSON.parse(content);
5221
5372
  if (!Array.isArray(parsed)) {
5222
5373
  return {
@@ -5267,8 +5418,8 @@ async function check(options) {
5267
5418
  }
5268
5419
 
5269
5420
  // src/commands/migration/versions/v001_capability/json-migrator/index.ts
5270
- import fs20 from "fs";
5271
- import path18 from "path";
5421
+ import fs22 from "fs";
5422
+ import path19 from "path";
5272
5423
 
5273
5424
  // src/commands/migration/versions/v001_capability/mapping.ts
5274
5425
  var DEFAULT_PLUGIN_VERSION = "1.0.0";
@@ -5498,18 +5649,18 @@ function transformCapabilities(oldCapabilities) {
5498
5649
  // src/commands/migration/versions/v001_capability/json-migrator/index.ts
5499
5650
  function loadExistingCapabilities() {
5500
5651
  const capabilitiesDir = getCapabilitiesDir2();
5501
- if (!fs20.existsSync(capabilitiesDir)) {
5652
+ if (!fs22.existsSync(capabilitiesDir)) {
5502
5653
  return [];
5503
5654
  }
5504
- const files = fs20.readdirSync(capabilitiesDir);
5655
+ const files = fs22.readdirSync(capabilitiesDir);
5505
5656
  const capabilities = [];
5506
5657
  for (const file of files) {
5507
5658
  if (file === "capabilities.json" || !file.endsWith(".json")) {
5508
5659
  continue;
5509
5660
  }
5510
5661
  try {
5511
- const filePath = path18.join(capabilitiesDir, file);
5512
- const content = fs20.readFileSync(filePath, "utf-8");
5662
+ const filePath = path19.join(capabilitiesDir, file);
5663
+ const content = fs22.readFileSync(filePath, "utf-8");
5513
5664
  const capability = JSON.parse(content);
5514
5665
  if (capability.id && capability.pluginKey) {
5515
5666
  capabilities.push(capability);
@@ -5567,9 +5718,9 @@ async function migrateJsonFiles(options) {
5567
5718
  }
5568
5719
  const capabilitiesDir = getCapabilitiesDir2();
5569
5720
  for (const cap of newCapabilities) {
5570
- const filePath = path18.join(capabilitiesDir, `${cap.id}.json`);
5721
+ const filePath = path19.join(capabilitiesDir, `${cap.id}.json`);
5571
5722
  const content = JSON.stringify(cap, null, 2);
5572
- fs20.writeFileSync(filePath, content, "utf-8");
5723
+ fs22.writeFileSync(filePath, content, "utf-8");
5573
5724
  console.log(` \u2713 Created: ${cap.id}.json`);
5574
5725
  }
5575
5726
  return {
@@ -5581,11 +5732,11 @@ async function migrateJsonFiles(options) {
5581
5732
  }
5582
5733
 
5583
5734
  // src/commands/migration/versions/v001_capability/plugin-installer/detector.ts
5584
- import fs21 from "fs";
5735
+ import fs23 from "fs";
5585
5736
  function isPluginInstalled2(pluginKey) {
5586
5737
  const actionPlugins = readActionPlugins();
5587
5738
  const manifestPath = getPluginManifestPath2(pluginKey);
5588
- return fs21.existsSync(manifestPath) && !!actionPlugins[pluginKey];
5739
+ return fs23.existsSync(manifestPath) && !!actionPlugins[pluginKey];
5589
5740
  }
5590
5741
  function detectPluginsToInstall(capabilities) {
5591
5742
  const pluginKeys = /* @__PURE__ */ new Set();
@@ -5661,12 +5812,12 @@ async function installPlugins(capabilities, options) {
5661
5812
  }
5662
5813
 
5663
5814
  // src/commands/migration/versions/v001_capability/code-migrator/index.ts
5664
- import path20 from "path";
5815
+ import path21 from "path";
5665
5816
  import { Project as Project3 } from "ts-morph";
5666
5817
 
5667
5818
  // src/commands/migration/versions/v001_capability/code-migrator/scanner.ts
5668
- import fs22 from "fs";
5669
- import path19 from "path";
5819
+ import fs24 from "fs";
5820
+ import path20 from "path";
5670
5821
  var EXCLUDED_DIRS = [
5671
5822
  "node_modules",
5672
5823
  "dist",
@@ -5681,9 +5832,9 @@ var EXCLUDED_PATTERNS = [
5681
5832
  /\.d\.ts$/
5682
5833
  ];
5683
5834
  function scanDirectory(dir, files = []) {
5684
- const entries = fs22.readdirSync(dir, { withFileTypes: true });
5835
+ const entries = fs24.readdirSync(dir, { withFileTypes: true });
5685
5836
  for (const entry of entries) {
5686
- const fullPath = path19.join(dir, entry.name);
5837
+ const fullPath = path20.join(dir, entry.name);
5687
5838
  if (entry.isDirectory()) {
5688
5839
  if (EXCLUDED_DIRS.includes(entry.name)) {
5689
5840
  continue;
@@ -5699,14 +5850,14 @@ function scanDirectory(dir, files = []) {
5699
5850
  return files;
5700
5851
  }
5701
5852
  function scanServerFiles() {
5702
- const serverDir = path19.join(getProjectRoot3(), "server");
5703
- if (!fs22.existsSync(serverDir)) {
5853
+ const serverDir = path20.join(getProjectRoot3(), "server");
5854
+ if (!fs24.existsSync(serverDir)) {
5704
5855
  return [];
5705
5856
  }
5706
5857
  return scanDirectory(serverDir);
5707
5858
  }
5708
5859
  function hasCapabilityImport(filePath) {
5709
- const content = fs22.readFileSync(filePath, "utf-8");
5860
+ const content = fs24.readFileSync(filePath, "utf-8");
5710
5861
  return /import\s+.*from\s+['"][^'"]*capabilities[^'"]*['"]/.test(content);
5711
5862
  }
5712
5863
  function scanFilesToMigrate() {
@@ -6083,7 +6234,7 @@ function analyzeFile(project, filePath, actionNameMap) {
6083
6234
  const callSites = analyzeCallSites(sourceFile, imports);
6084
6235
  const classInfo = analyzeClass(sourceFile);
6085
6236
  const { canMigrate, reason } = canAutoMigrate(classInfo);
6086
- const relativePath = path20.relative(getProjectRoot3(), filePath);
6237
+ const relativePath = path21.relative(getProjectRoot3(), filePath);
6087
6238
  return {
6088
6239
  filePath: relativePath,
6089
6240
  imports,
@@ -6094,7 +6245,7 @@ function analyzeFile(project, filePath, actionNameMap) {
6094
6245
  };
6095
6246
  }
6096
6247
  function migrateFile(project, analysis, dryRun) {
6097
- const absolutePath = path20.join(getProjectRoot3(), analysis.filePath);
6248
+ const absolutePath = path21.join(getProjectRoot3(), analysis.filePath);
6098
6249
  if (!analysis.canAutoMigrate) {
6099
6250
  return {
6100
6251
  filePath: analysis.filePath,
@@ -6197,17 +6348,17 @@ function getSuggestion(analysis) {
6197
6348
  }
6198
6349
 
6199
6350
  // src/commands/migration/versions/v001_capability/cleanup.ts
6200
- import fs23 from "fs";
6201
- import path21 from "path";
6351
+ import fs25 from "fs";
6352
+ import path22 from "path";
6202
6353
  function cleanupOldFiles(capabilities, dryRun) {
6203
6354
  const deletedFiles = [];
6204
6355
  const errors = [];
6205
6356
  const capabilitiesDir = getCapabilitiesDir2();
6206
- const oldJsonPath = path21.join(capabilitiesDir, "capabilities.json");
6207
- if (fs23.existsSync(oldJsonPath)) {
6357
+ const oldJsonPath = path22.join(capabilitiesDir, "capabilities.json");
6358
+ if (fs25.existsSync(oldJsonPath)) {
6208
6359
  try {
6209
6360
  if (!dryRun) {
6210
- fs23.unlinkSync(oldJsonPath);
6361
+ fs25.unlinkSync(oldJsonPath);
6211
6362
  }
6212
6363
  deletedFiles.push("capabilities.json");
6213
6364
  } catch (error) {
@@ -6215,11 +6366,11 @@ function cleanupOldFiles(capabilities, dryRun) {
6215
6366
  }
6216
6367
  }
6217
6368
  for (const cap of capabilities) {
6218
- const tsFilePath = path21.join(capabilitiesDir, `${cap.id}.ts`);
6219
- if (fs23.existsSync(tsFilePath)) {
6369
+ const tsFilePath = path22.join(capabilitiesDir, `${cap.id}.ts`);
6370
+ if (fs25.existsSync(tsFilePath)) {
6220
6371
  try {
6221
6372
  if (!dryRun) {
6222
- fs23.unlinkSync(tsFilePath);
6373
+ fs25.unlinkSync(tsFilePath);
6223
6374
  }
6224
6375
  deletedFiles.push(`${cap.id}.ts`);
6225
6376
  } catch (error) {
@@ -6235,8 +6386,8 @@ function cleanupOldFiles(capabilities, dryRun) {
6235
6386
  }
6236
6387
 
6237
6388
  // src/commands/migration/versions/v001_capability/report-generator.ts
6238
- import fs24 from "fs";
6239
- import path22 from "path";
6389
+ import fs26 from "fs";
6390
+ import path23 from "path";
6240
6391
  var REPORT_FILE = "capability-migration-report.md";
6241
6392
  function printSummary(result) {
6242
6393
  const { jsonMigration, pluginInstallation, codeMigration, cleanup } = result;
@@ -6399,15 +6550,15 @@ async function generateReport(result) {
6399
6550
  }
6400
6551
  lines.push("");
6401
6552
  const logDir = process.env.LOG_DIR || "logs";
6402
- if (!fs24.existsSync(logDir)) {
6553
+ if (!fs26.existsSync(logDir)) {
6403
6554
  return;
6404
6555
  }
6405
- const reportDir = path22.join(logDir, "migration");
6406
- if (!fs24.existsSync(reportDir)) {
6407
- fs24.mkdirSync(reportDir, { recursive: true });
6556
+ const reportDir = path23.join(logDir, "migration");
6557
+ if (!fs26.existsSync(reportDir)) {
6558
+ fs26.mkdirSync(reportDir, { recursive: true });
6408
6559
  }
6409
- const reportPath = path22.join(reportDir, REPORT_FILE);
6410
- fs24.writeFileSync(reportPath, lines.join("\n"), "utf-8");
6560
+ const reportPath = path23.join(reportDir, REPORT_FILE);
6561
+ fs26.writeFileSync(reportPath, lines.join("\n"), "utf-8");
6411
6562
  console.log(`\u{1F4C4} Report generated: ${reportPath}`);
6412
6563
  }
6413
6564
 
@@ -6939,10 +7090,10 @@ var migrationCommand = {
6939
7090
  };
6940
7091
 
6941
7092
  // src/commands/read-logs/index.ts
6942
- import path23 from "path";
7093
+ import path24 from "path";
6943
7094
 
6944
7095
  // src/commands/read-logs/std-utils.ts
6945
- import fs25 from "fs";
7096
+ import fs27 from "fs";
6946
7097
  function formatStdPrefixTime(localTime) {
6947
7098
  const match = localTime.match(/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/);
6948
7099
  if (!match) return localTime;
@@ -6972,11 +7123,11 @@ function stripPrefixFromStdLine(line) {
6972
7123
  return `[${time}] ${content}`;
6973
7124
  }
6974
7125
  function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarker) {
6975
- const stat = fs25.statSync(filePath);
7126
+ const stat = fs27.statSync(filePath);
6976
7127
  if (stat.size === 0) {
6977
7128
  return { lines: [], markerFound: false, totalLinesCount: 0 };
6978
7129
  }
6979
- const fd = fs25.openSync(filePath, "r");
7130
+ const fd = fs27.openSync(filePath, "r");
6980
7131
  const chunkSize = 64 * 1024;
6981
7132
  let position = stat.size;
6982
7133
  let remainder = "";
@@ -6990,7 +7141,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
6990
7141
  const length = Math.min(chunkSize, position);
6991
7142
  position -= length;
6992
7143
  const buffer = Buffer.alloc(length);
6993
- fs25.readSync(fd, buffer, 0, length, position);
7144
+ fs27.readSync(fd, buffer, 0, length, position);
6994
7145
  let chunk = buffer.toString("utf8");
6995
7146
  if (remainder) {
6996
7147
  chunk += remainder;
@@ -7032,7 +7183,7 @@ function readStdLinesTailFromLastMarkerPaged(filePath, maxLines, offset, isMarke
7032
7183
  }
7033
7184
  }
7034
7185
  } finally {
7035
- fs25.closeSync(fd);
7186
+ fs27.closeSync(fd);
7036
7187
  }
7037
7188
  return { lines: collected.reverse(), markerFound, totalLinesCount };
7038
7189
  }
@@ -7053,21 +7204,21 @@ function readServerStdSegment(filePath, maxLines, offset) {
7053
7204
  }
7054
7205
 
7055
7206
  // src/commands/read-logs/tail.ts
7056
- import fs26 from "fs";
7207
+ import fs28 from "fs";
7057
7208
  function fileExists(filePath) {
7058
7209
  try {
7059
- fs26.accessSync(filePath, fs26.constants.F_OK | fs26.constants.R_OK);
7210
+ fs28.accessSync(filePath, fs28.constants.F_OK | fs28.constants.R_OK);
7060
7211
  return true;
7061
7212
  } catch {
7062
7213
  return false;
7063
7214
  }
7064
7215
  }
7065
7216
  function readFileTailLines(filePath, maxLines) {
7066
- const stat = fs26.statSync(filePath);
7217
+ const stat = fs28.statSync(filePath);
7067
7218
  if (stat.size === 0) {
7068
7219
  return [];
7069
7220
  }
7070
- const fd = fs26.openSync(filePath, "r");
7221
+ const fd = fs28.openSync(filePath, "r");
7071
7222
  const chunkSize = 64 * 1024;
7072
7223
  const chunks = [];
7073
7224
  let position = stat.size;
@@ -7077,13 +7228,13 @@ function readFileTailLines(filePath, maxLines) {
7077
7228
  const length = Math.min(chunkSize, position);
7078
7229
  position -= length;
7079
7230
  const buffer = Buffer.alloc(length);
7080
- fs26.readSync(fd, buffer, 0, length, position);
7231
+ fs28.readSync(fd, buffer, 0, length, position);
7081
7232
  chunks.unshift(buffer.toString("utf8"));
7082
7233
  const chunkLines = buffer.toString("utf8").split("\n").length - 1;
7083
7234
  collectedLines += chunkLines;
7084
7235
  }
7085
7236
  } finally {
7086
- fs26.closeSync(fd);
7237
+ fs28.closeSync(fd);
7087
7238
  }
7088
7239
  const content = chunks.join("");
7089
7240
  const allLines = content.split("\n");
@@ -7099,11 +7250,11 @@ function readFileTailLines(filePath, maxLines) {
7099
7250
  return allLines.slice(allLines.length - maxLines);
7100
7251
  }
7101
7252
  function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
7102
- const stat = fs26.statSync(filePath);
7253
+ const stat = fs28.statSync(filePath);
7103
7254
  if (stat.size === 0) {
7104
7255
  return { lines: [], totalLinesCount: 0 };
7105
7256
  }
7106
- const fd = fs26.openSync(filePath, "r");
7257
+ const fd = fs28.openSync(filePath, "r");
7107
7258
  const chunkSize = 64 * 1024;
7108
7259
  let position = stat.size;
7109
7260
  let remainder = "";
@@ -7115,7 +7266,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
7115
7266
  const length = Math.min(chunkSize, position);
7116
7267
  position -= length;
7117
7268
  const buffer = Buffer.alloc(length);
7118
- fs26.readSync(fd, buffer, 0, length, position);
7269
+ fs28.readSync(fd, buffer, 0, length, position);
7119
7270
  let chunk = buffer.toString("utf8");
7120
7271
  if (remainder) {
7121
7272
  chunk += remainder;
@@ -7146,7 +7297,7 @@ function readFileTailNonEmptyLinesWithOffset(filePath, maxLines, offset) {
7146
7297
  }
7147
7298
  }
7148
7299
  } finally {
7149
- fs26.closeSync(fd);
7300
+ fs28.closeSync(fd);
7150
7301
  }
7151
7302
  return { lines: collected.reverse(), totalLinesCount };
7152
7303
  }
@@ -7288,7 +7439,7 @@ function readDevStdSegment(filePath, maxLines, offset) {
7288
7439
  }
7289
7440
 
7290
7441
  // src/commands/read-logs/json-lines.ts
7291
- import fs27 from "fs";
7442
+ import fs29 from "fs";
7292
7443
 
7293
7444
  // src/commands/read-logs/structured-log.ts
7294
7445
  function normalizeLevelName(value) {
@@ -7364,11 +7515,11 @@ function buildWantedLevelSet(levels) {
7364
7515
  return set.size > 0 ? set : null;
7365
7516
  }
7366
7517
  function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
7367
- const stat = fs27.statSync(filePath);
7518
+ const stat = fs29.statSync(filePath);
7368
7519
  if (stat.size === 0) {
7369
7520
  return { lines: [], totalLinesCount: 0 };
7370
7521
  }
7371
- const fd = fs27.openSync(filePath, "r");
7522
+ const fd = fs29.openSync(filePath, "r");
7372
7523
  const chunkSize = 64 * 1024;
7373
7524
  let position = stat.size;
7374
7525
  let remainder = "";
@@ -7383,7 +7534,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
7383
7534
  const length = Math.min(chunkSize, position);
7384
7535
  position -= length;
7385
7536
  const buffer = Buffer.alloc(length);
7386
- fs27.readSync(fd, buffer, 0, length, position);
7537
+ fs29.readSync(fd, buffer, 0, length, position);
7387
7538
  let chunk = buffer.toString("utf8");
7388
7539
  if (remainder) {
7389
7540
  chunk += remainder;
@@ -7445,7 +7596,7 @@ function readJsonLinesLastPid(filePath, maxLines, offset, levels) {
7445
7596
  }
7446
7597
  }
7447
7598
  } finally {
7448
- fs27.closeSync(fd);
7599
+ fs29.closeSync(fd);
7449
7600
  }
7450
7601
  return { lines: collected.reverse(), totalLinesCount };
7451
7602
  }
@@ -7488,11 +7639,11 @@ function extractTraceId(obj) {
7488
7639
  function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
7489
7640
  const wanted = traceId.trim();
7490
7641
  if (!wanted) return { lines: [], totalLinesCount: 0 };
7491
- const stat = fs27.statSync(filePath);
7642
+ const stat = fs29.statSync(filePath);
7492
7643
  if (stat.size === 0) {
7493
7644
  return { lines: [], totalLinesCount: 0 };
7494
7645
  }
7495
- const fd = fs27.openSync(filePath, "r");
7646
+ const fd = fs29.openSync(filePath, "r");
7496
7647
  const chunkSize = 64 * 1024;
7497
7648
  let position = stat.size;
7498
7649
  let remainder = "";
@@ -7505,7 +7656,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
7505
7656
  const length = Math.min(chunkSize, position);
7506
7657
  position -= length;
7507
7658
  const buffer = Buffer.alloc(length);
7508
- fs27.readSync(fd, buffer, 0, length, position);
7659
+ fs29.readSync(fd, buffer, 0, length, position);
7509
7660
  let chunk = buffer.toString("utf8");
7510
7661
  if (remainder) {
7511
7662
  chunk += remainder;
@@ -7558,7 +7709,7 @@ function readJsonLinesByTraceId(filePath, traceId, maxLines, offset, levels) {
7558
7709
  }
7559
7710
  }
7560
7711
  } finally {
7561
- fs27.closeSync(fd);
7712
+ fs29.closeSync(fd);
7562
7713
  }
7563
7714
  return { lines: collected.reverse(), totalLinesCount };
7564
7715
  }
@@ -7567,11 +7718,11 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
7567
7718
  if (!wantedLevelSet) {
7568
7719
  return { lines: [], totalLinesCount: 0 };
7569
7720
  }
7570
- const stat = fs27.statSync(filePath);
7721
+ const stat = fs29.statSync(filePath);
7571
7722
  if (stat.size === 0) {
7572
7723
  return { lines: [], totalLinesCount: 0 };
7573
7724
  }
7574
- const fd = fs27.openSync(filePath, "r");
7725
+ const fd = fs29.openSync(filePath, "r");
7575
7726
  const chunkSize = 64 * 1024;
7576
7727
  let position = stat.size;
7577
7728
  let remainder = "";
@@ -7583,7 +7734,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
7583
7734
  const length = Math.min(chunkSize, position);
7584
7735
  position -= length;
7585
7736
  const buffer = Buffer.alloc(length);
7586
- fs27.readSync(fd, buffer, 0, length, position);
7737
+ fs29.readSync(fd, buffer, 0, length, position);
7587
7738
  let chunk = buffer.toString("utf8");
7588
7739
  if (remainder) {
7589
7740
  chunk += remainder;
@@ -7630,7 +7781,7 @@ function readJsonLinesTailByLevel(filePath, maxLines, offset, levels) {
7630
7781
  }
7631
7782
  }
7632
7783
  } finally {
7633
- fs27.closeSync(fd);
7784
+ fs29.closeSync(fd);
7634
7785
  }
7635
7786
  return { lines: collected.reverse(), totalLinesCount };
7636
7787
  }
@@ -8005,30 +8156,30 @@ async function readLogsJsonResult(options) {
8005
8156
  };
8006
8157
  }
8007
8158
  function resolveLogFilePath(logDir, type) {
8008
- const base = path23.isAbsolute(logDir) ? logDir : path23.join(process.cwd(), logDir);
8159
+ const base = path24.isAbsolute(logDir) ? logDir : path24.join(process.cwd(), logDir);
8009
8160
  if (type === "server") {
8010
- return path23.join(base, "server.log");
8161
+ return path24.join(base, "server.log");
8011
8162
  }
8012
8163
  if (type === "trace") {
8013
- return path23.join(base, "trace.log");
8164
+ return path24.join(base, "trace.log");
8014
8165
  }
8015
8166
  if (type === "server-std") {
8016
- return path23.join(base, "server.std.log");
8167
+ return path24.join(base, "server.std.log");
8017
8168
  }
8018
8169
  if (type === "client-std") {
8019
- return path23.join(base, "client.std.log");
8170
+ return path24.join(base, "client.std.log");
8020
8171
  }
8021
8172
  if (type === "dev") {
8022
- return path23.join(base, "dev.log");
8173
+ return path24.join(base, "dev.log");
8023
8174
  }
8024
8175
  if (type === "dev-std") {
8025
- return path23.join(base, "dev.std.log");
8176
+ return path24.join(base, "dev.std.log");
8026
8177
  }
8027
8178
  if (type === "install-dep-std") {
8028
- return path23.join(base, "install-dep.std.log");
8179
+ return path24.join(base, "install-dep.std.log");
8029
8180
  }
8030
8181
  if (type === "browser") {
8031
- return path23.join(base, "browser.log");
8182
+ return path24.join(base, "browser.log");
8032
8183
  }
8033
8184
  throw new Error(`Unsupported log type: ${type}`);
8034
8185
  }
@@ -8114,70 +8265,54 @@ var UPLOAD_STATIC_DEFAULTS = {
8114
8265
  };
8115
8266
 
8116
8267
  // src/commands/build/api-client.ts
8117
- var ERROR_RESPONSE_PREVIEW_LIMIT = 2e3;
8118
- async function getErrorResponseDetails(response) {
8119
- try {
8120
- if (typeof response.text === "function") {
8121
- const text = await response.text();
8122
- if (!text) {
8123
- return "";
8124
- }
8125
- return `, response: ${text.slice(0, ERROR_RESPONSE_PREVIEW_LIMIT)}`;
8126
- }
8127
- if (typeof response.json === "function") {
8128
- const data = await response.json();
8129
- const serialized = JSON.stringify(data);
8130
- if (!serialized) {
8131
- return "";
8132
- }
8133
- return `, response: ${serialized.slice(0, ERROR_RESPONSE_PREVIEW_LIMIT)}`;
8134
- }
8135
- } catch {
8136
- return "";
8137
- }
8138
- return "";
8139
- }
8140
- async function throwIfResponseNotOk(response, message) {
8141
- if (response.ok && response.status === 200) {
8142
- return;
8143
- }
8144
- const details = await getErrorResponseDetails(response);
8145
- throw new Error(`${message}: ${response.status} ${response.statusText}${details}`);
8146
- }
8147
8268
  async function genArtifactUploadCredential(appId, body) {
8148
8269
  const client = getHttpClient();
8149
8270
  const url = `/v1/app/${appId}/pipeline/gen_artifact_upload_credential`;
8150
- const response = await client.post(url, body);
8151
- await throwIfResponseNotOk(response, "gen_artifact_upload_credential \u8BF7\u6C42\u5931\u8D25");
8271
+ const response = await requestWithLogId(
8272
+ () => client.post(url, body),
8273
+ "gen_artifact_upload_credential \u8BF7\u6C42\u5931\u8D25",
8274
+ { expectStatus200: true }
8275
+ );
8152
8276
  return response.json();
8153
8277
  }
8154
8278
  async function getDefaultBucketId(appId) {
8155
8279
  const client = getHttpClient();
8156
8280
  const url = `/v1/app/${appId}/storage/inner/staticBucket`;
8157
- const response = await client.post(url, {});
8158
- await throwIfResponseNotOk(response, "getOrCreateStaticBucket \u8BF7\u6C42\u5931\u8D25");
8281
+ const response = await requestWithLogId(
8282
+ () => client.post(url, {}),
8283
+ "getOrCreateStaticBucket \u8BF7\u6C42\u5931\u8D25",
8284
+ { expectStatus200: true }
8285
+ );
8159
8286
  const data = await response.json();
8160
8287
  if (data.status_code !== "0") {
8161
- throw new Error(`getOrCreateStaticBucket \u8FD4\u56DE\u5F02\u5E38, status_code: ${data.status_code}`);
8288
+ throw new Error(
8289
+ `getOrCreateStaticBucket \u8FD4\u56DE\u5F02\u5E38, status_code: ${data.status_code}${formatLogId(response)}`
8290
+ );
8162
8291
  }
8163
8292
  const bucketId = data?.data?.bucketID;
8164
8293
  if (!bucketId) {
8165
- throw new Error(`\u672A\u627E\u5230\u5E94\u7528 ${appId} \u7684\u9759\u6001\u8D44\u6E90\u5B58\u50A8\u6876`);
8294
+ throw new Error(`\u672A\u627E\u5230\u5E94\u7528 ${appId} \u7684\u9759\u6001\u8D44\u6E90\u5B58\u50A8\u6876${formatLogId(response)}`);
8166
8295
  }
8167
8296
  return bucketId;
8168
8297
  }
8169
8298
  async function preUploadStaticAttachment(appId, bucketId) {
8170
8299
  const client = getHttpClient();
8171
8300
  const url = `/v1/app/${appId}/storage/bucket/${bucketId}/preUploadStatic`;
8172
- const response = await client.post(url, {});
8173
- await throwIfResponseNotOk(response, "preUploadStatic \u8BF7\u6C42\u5931\u8D25");
8301
+ const response = await requestWithLogId(
8302
+ () => client.post(url, {}),
8303
+ "preUploadStatic \u8BF7\u6C42\u5931\u8D25",
8304
+ { expectStatus200: true }
8305
+ );
8174
8306
  return response.json();
8175
8307
  }
8176
8308
  async function uploadStaticAttachmentCallback(appId, bucketId, body) {
8177
8309
  const client = getHttpClient();
8178
8310
  const url = `/v1/app/${appId}/storage/bucket/${bucketId}/object/callbackStatic`;
8179
- const response = await client.post(url, body);
8180
- await throwIfResponseNotOk(response, "callbackStatic \u8BF7\u6C42\u5931\u8D25");
8311
+ const response = await requestWithLogId(
8312
+ () => client.post(url, body),
8313
+ "callbackStatic \u8BF7\u6C42\u5931\u8D25",
8314
+ { expectStatus200: true }
8315
+ );
8181
8316
  return response.json();
8182
8317
  }
8183
8318
 
@@ -8214,9 +8349,9 @@ function camelToKebab(str) {
8214
8349
  }
8215
8350
 
8216
8351
  // src/commands/build/upload-static.handler.ts
8217
- import * as fs28 from "fs";
8352
+ import * as fs30 from "fs";
8218
8353
  import * as os2 from "os";
8219
- import * as path24 from "path";
8354
+ import * as path25 from "path";
8220
8355
  import { execFileSync } from "child_process";
8221
8356
  function readCredentialsFromEnv() {
8222
8357
  const uploadPrefix = process.env.STATIC_UPLOAD_PREFIX;
@@ -8240,8 +8375,8 @@ async function uploadStatic(options) {
8240
8375
  endpoint = UPLOAD_STATIC_DEFAULTS.endpoint,
8241
8376
  region = UPLOAD_STATIC_DEFAULTS.region
8242
8377
  } = options;
8243
- const resolvedStaticDir = path24.resolve(staticDir);
8244
- if (!fs28.existsSync(resolvedStaticDir)) {
8378
+ const resolvedStaticDir = path25.resolve(staticDir);
8379
+ if (!fs30.existsSync(resolvedStaticDir)) {
8245
8380
  console.error(`${LOG_PREFIX} \u76EE\u5F55\u4E0D\u5B58\u5728: ${resolvedStaticDir}\uFF0C\u8DF3\u8FC7\u4E0A\u4F20`);
8246
8381
  return;
8247
8382
  }
@@ -8274,8 +8409,8 @@ async function uploadStatic(options) {
8274
8409
  ({ AccessKeyID: accessKeyID, SecretAccessKey: secretAccessKey, SessionToken: sessionToken } = uploadCredential);
8275
8410
  }
8276
8411
  console.error(`${LOG_PREFIX} \u4E0A\u4F20\u76EE\u6807: ${uploadPrefix}`);
8277
- const confPath = path24.join(os2.tmpdir(), `.tosutilconfig-static-${process.pid}`);
8278
- fs28.writeFileSync(confPath, "");
8412
+ const confPath = path25.join(os2.tmpdir(), `.tosutilconfig-static-${process.pid}`);
8413
+ fs30.writeFileSync(confPath, "");
8279
8414
  try {
8280
8415
  console.error(`${LOG_PREFIX} \u914D\u7F6E tosutil...`);
8281
8416
  configureTosutil(resolvedTosutil, confPath, {
@@ -8289,7 +8424,7 @@ async function uploadStatic(options) {
8289
8424
  uploadToTos(resolvedTosutil, confPath, resolvedStaticDir, uploadPrefix);
8290
8425
  } finally {
8291
8426
  try {
8292
- fs28.unlinkSync(confPath);
8427
+ fs30.unlinkSync(confPath);
8293
8428
  } catch {
8294
8429
  }
8295
8430
  }
@@ -8309,8 +8444,8 @@ async function uploadStatic(options) {
8309
8444
  }
8310
8445
  }
8311
8446
  function resolveTosutilPath(tosutilPath) {
8312
- if (path24.isAbsolute(tosutilPath)) {
8313
- return fs28.existsSync(tosutilPath) ? tosutilPath : null;
8447
+ if (path25.isAbsolute(tosutilPath)) {
8448
+ return fs30.existsSync(tosutilPath) ? tosutilPath : null;
8314
8449
  }
8315
8450
  try {
8316
8451
  const resolved = execFileSync("which", [tosutilPath], { encoding: "utf-8" }).trim();
@@ -8355,7 +8490,7 @@ async function resolveBucketId(appId) {
8355
8490
  return bucketId;
8356
8491
  }
8357
8492
  function isDirEmpty(dirPath) {
8358
- const entries = fs28.readdirSync(dirPath);
8493
+ const entries = fs30.readdirSync(dirPath);
8359
8494
  return entries.length === 0;
8360
8495
  }
8361
8496
 
@@ -8451,13 +8586,13 @@ var commands = [
8451
8586
 
8452
8587
  // src/index.ts
8453
8588
  for (const filename of [".env.local", ".env"]) {
8454
- const envPath = path25.join(process.cwd(), filename);
8455
- if (fs29.existsSync(envPath)) {
8589
+ const envPath = path26.join(process.cwd(), filename);
8590
+ if (fs31.existsSync(envPath)) {
8456
8591
  dotenvConfig({ path: envPath });
8457
8592
  }
8458
8593
  }
8459
- var __dirname = path25.dirname(fileURLToPath5(import.meta.url));
8460
- var pkg = JSON.parse(fs29.readFileSync(path25.join(__dirname, "../package.json"), "utf-8"));
8594
+ var __dirname = path26.dirname(fileURLToPath5(import.meta.url));
8595
+ var pkg = JSON.parse(fs31.readFileSync(path26.join(__dirname, "../package.json"), "utf-8"));
8461
8596
  var cli = new FullstackCLI(pkg.version);
8462
8597
  cli.useAll(commands);
8463
8598
  cli.run();