@faapi/faapi 6.23.0 → 6.24.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.
package/dist/cli/index.js CHANGED
@@ -649,9 +649,9 @@ var init_constants = __esm({
649
649
  });
650
650
 
651
651
  // src/utils/normalizePath.ts
652
- function normalizePath(path35) {
653
- if (!path35) return "";
654
- let result = path35.replace(/\\/g, "/");
652
+ function normalizePath(path34) {
653
+ if (!path34) return "";
654
+ let result = path34.replace(/\\/g, "/");
655
655
  result = result.replace(/\/+/g, "/");
656
656
  result = result.replace(/\/+$/, "");
657
657
  if (result && !result.startsWith("/")) {
@@ -3082,8 +3082,6 @@ var init_generateToolArtifacts = __esm({
3082
3082
 
3083
3083
  // src/agents/scanAgents.ts
3084
3084
  import fg3 from "fast-glob";
3085
- import path15 from "path";
3086
- import fs12 from "fs";
3087
3085
  function extractAgentNameFromPath(filePath) {
3088
3086
  const normalized = filePath.replace(/\\/g, "/");
3089
3087
  const match = normalized.match(/(?:^|\/)agents\/(.+)\/handler\.ts$/);
@@ -3094,11 +3092,6 @@ function extractAgentNameFromPath(filePath) {
3094
3092
  }
3095
3093
  return match[1].replace(/\//g, ".");
3096
3094
  }
3097
- function detectAgentExports(source) {
3098
- return {
3099
- hasRun: RUN_EXPORT_RE.test(source)
3100
- };
3101
- }
3102
3095
  async function scanAgents(rootDir, patterns) {
3103
3096
  const files = await fg3(patterns, {
3104
3097
  cwd: rootDir,
@@ -3113,9 +3106,6 @@ async function scanAgents(rootDir, patterns) {
3113
3106
  if (fileName !== "handler.ts" && fileName !== "handler.js") {
3114
3107
  continue;
3115
3108
  }
3116
- const absPath = path15.resolve(rootDir, normalizedFile);
3117
- const source = await fs12.promises.readFile(absPath, "utf8").catch(() => "");
3118
- const { hasRun } = detectAgentExports(source);
3119
3109
  const name = extractAgentNameFromPath(normalizedFile);
3120
3110
  const prevFile = seen.get(name);
3121
3111
  if (prevFile) {
@@ -3126,18 +3116,16 @@ async function scanAgents(rootDir, patterns) {
3126
3116
  seen.set(name, normalizedFile);
3127
3117
  agents.push({
3128
3118
  name,
3129
- filePath: normalizedFile,
3130
- hasRun
3119
+ filePath: normalizedFile
3131
3120
  });
3132
3121
  }
3133
3122
  return agents;
3134
3123
  }
3135
- var DEFAULT_AGENT_PATTERNS, RUN_EXPORT_RE;
3124
+ var DEFAULT_AGENT_PATTERNS;
3136
3125
  var init_scanAgents = __esm({
3137
3126
  "src/agents/scanAgents.ts"() {
3138
3127
  "use strict";
3139
3128
  DEFAULT_AGENT_PATTERNS = ["src/agents/**/handler.ts"];
3140
- RUN_EXPORT_RE = /export\s+(?:async\s+)?(?:function\s+|const\s+)run\b/;
3141
3129
  }
3142
3130
  });
3143
3131
 
@@ -3146,12 +3134,21 @@ import ts11 from "typescript";
3146
3134
  function extractAgentMetadata(program, filePath, pathMeta) {
3147
3135
  const sourceFile = program.getSourceFile(filePath);
3148
3136
  if (!sourceFile) return null;
3137
+ const runOwner = findRunExportOwner(sourceFile);
3138
+ if (runOwner) {
3139
+ throw SchemaExtractionError.at(
3140
+ runOwner,
3141
+ "run",
3142
+ "agent \u81EA\u5B9A\u4E49 run \u5DF2\u79FB\u9664\u2014\u2014agent \u7EDF\u4E00\u4E3A\u58F0\u660E\u5F0F\u6267\u884C\uFF08config + \u9ED8\u8BA4 reactLoop\uFF09\u3002\u7F16\u6392\u573A\u666F\u8BF7\u6CE8\u518C tool\uFF08src/tools/ \u4E0B\u5BFC\u51FA\u51FD\u6570\uFF0C\u6709 schema/trace/\u9274\u6743\u94A9\u5B50\uFF09\uFF0C\u591A agent \u534F\u4F5C\u7528 config.agents \u58F0\u660E sub-agent",
3143
+ sourceFile
3144
+ );
3145
+ }
3149
3146
  const configFound = findConfigExport(sourceFile);
3150
3147
  if (!configFound) {
3151
3148
  throw SchemaExtractionError.at(
3152
3149
  sourceFile,
3153
3150
  "config.systemPrompt",
3154
- "agent \u5FC5\u586B\u2014\u2014\u8BF7\u5728 config \u5757\u58F0\u660E\u7CFB\u7EDF\u63D0\u793A\u8BCD\uFF08\u5B57\u7B26\u4E32\u5B57\u9762\u91CF\u3001\u65E0\u63D2\u503C\u6A21\u677F\u5B57\u7B26\u4E32\u6216\u5176 + \u62FC\u63A5\uFF09",
3151
+ "agent \u5FC5\u586B\u2014\u2014\u8BF7\u5728 config \u5757\u58F0\u660E systemPrompt\uFF08\u5B57\u7B26\u4E32\u5B57\u9762\u91CF\u3001\u65E0\u63D2\u503C\u6A21\u677F\u5B57\u7B26\u4E32\u6216\u5176 + \u62FC\u63A5\uFF09\u6216 systemPromptFile\uFF08\u76F8\u5BF9 resources \u76EE\u5F55\u7684\u8DEF\u5F84\u5B57\u9762\u91CF\uFF09\u4E8C\u9009\u4E00",
3155
3152
  sourceFile
3156
3153
  );
3157
3154
  }
@@ -3167,16 +3164,13 @@ function extractAgentMetadata(program, filePath, pathMeta) {
3167
3164
  const jsDoc = getJSDocFromNode(configFound.jsDocOwner);
3168
3165
  const description = extractDescription(jsDoc);
3169
3166
  const agentNameOverride = extractJSDocTagValue(jsDoc, "agent");
3170
- const { systemPrompt, tools, agents, model, maxTurns, inputDescription } = extractConfigFields(
3171
- objectLiteral,
3172
- sourceFile
3173
- );
3167
+ const { systemPrompt, systemPromptFile, tools, agents, model, maxTurns, inputDescription } = extractConfigFields(objectLiteral, sourceFile);
3174
3168
  return {
3175
3169
  name: agentNameOverride ?? pathMeta.name,
3176
3170
  description,
3177
3171
  filePath: pathMeta.filePath,
3178
- hasRun: pathMeta.hasRun,
3179
3172
  systemPrompt,
3173
+ systemPromptFile,
3180
3174
  tools,
3181
3175
  agents,
3182
3176
  model,
@@ -3184,6 +3178,25 @@ function extractAgentMetadata(program, filePath, pathMeta) {
3184
3178
  inputDescription
3185
3179
  };
3186
3180
  }
3181
+ function findRunExportOwner(sourceFile) {
3182
+ let result = null;
3183
+ ts11.forEachChild(sourceFile, (node) => {
3184
+ if (result) return;
3185
+ if (ts11.isFunctionDeclaration(node) && hasExportModifier(node) && node.name?.text === "run") {
3186
+ result = node;
3187
+ return;
3188
+ }
3189
+ if (ts11.isVariableStatement(node) && hasExportModifier(node)) {
3190
+ for (const decl of node.declarationList.declarations) {
3191
+ if (ts11.isIdentifier(decl.name) && decl.name.text === "run") {
3192
+ result = node;
3193
+ return;
3194
+ }
3195
+ }
3196
+ }
3197
+ });
3198
+ return result;
3199
+ }
3187
3200
  function findConfigExport(sourceFile) {
3188
3201
  let result = null;
3189
3202
  ts11.forEachChild(sourceFile, (node) => {
@@ -3226,6 +3239,7 @@ function getReturnObjectLiteral(fn) {
3226
3239
  }
3227
3240
  function extractConfigFields(objLit, sourceFile) {
3228
3241
  let systemPrompt;
3242
+ let systemPromptFile;
3229
3243
  let tools;
3230
3244
  let agents;
3231
3245
  let model;
@@ -3249,6 +3263,9 @@ function extractConfigFields(objLit, sourceFile) {
3249
3263
  case "systemPrompt":
3250
3264
  systemPrompt = requireStringValue(prop, "systemPrompt", sourceFile);
3251
3265
  break;
3266
+ case "systemPromptFile":
3267
+ systemPromptFile = requireStringValue(prop, "systemPromptFile", sourceFile);
3268
+ break;
3252
3269
  case "tools":
3253
3270
  tools = requireStringArrayValue(prop, "tools", sourceFile);
3254
3271
  break;
@@ -3268,20 +3285,28 @@ function extractConfigFields(objLit, sourceFile) {
3268
3285
  throw SchemaExtractionError.at(
3269
3286
  prop,
3270
3287
  `config.${propName}`,
3271
- "\u672A\u77E5 config \u5B57\u6BB5\u2014\u2014\u4EC5\u652F\u6301 systemPrompt / tools / agents / model / maxTurns / inputDescription",
3288
+ "\u672A\u77E5 config \u5B57\u6BB5\u2014\u2014\u4EC5\u652F\u6301 systemPrompt / systemPromptFile / tools / agents / model / maxTurns / inputDescription",
3272
3289
  sourceFile
3273
3290
  );
3274
3291
  }
3275
3292
  }
3276
- if (systemPrompt === void 0) {
3293
+ if (systemPrompt !== void 0 && systemPromptFile !== void 0) {
3294
+ throw SchemaExtractionError.at(
3295
+ objLit,
3296
+ "config.systemPrompt",
3297
+ "systemPrompt \u4E0E systemPromptFile \u4E92\u65A5\u2014\u2014\u5185\u8054\u7CFB\u7EDF\u63D0\u793A\u8BCD\u4E0E resources \u6587\u4EF6\u4E8C\u9009\u4E00",
3298
+ sourceFile
3299
+ );
3300
+ }
3301
+ if (systemPrompt === void 0 && systemPromptFile === void 0) {
3277
3302
  throw SchemaExtractionError.at(
3278
3303
  objLit,
3279
3304
  "config.systemPrompt",
3280
- "agent \u5FC5\u586B\u2014\u2014\u8BF7\u5728 config \u5757\u58F0\u660E\u7CFB\u7EDF\u63D0\u793A\u8BCD\uFF08\u5B57\u7B26\u4E32\u5B57\u9762\u91CF\u3001\u65E0\u63D2\u503C\u6A21\u677F\u5B57\u7B26\u4E32\u6216\u5176 + \u62FC\u63A5\uFF09",
3305
+ "agent \u5FC5\u586B\u2014\u2014\u8BF7\u5728 config \u5757\u58F0\u660E systemPrompt\uFF08\u5B57\u7B26\u4E32\u5B57\u9762\u91CF\u3001\u65E0\u63D2\u503C\u6A21\u677F\u5B57\u7B26\u4E32\u6216\u5176 + \u62FC\u63A5\uFF09\u6216 systemPromptFile\uFF08\u76F8\u5BF9 resources \u76EE\u5F55\u7684\u8DEF\u5F84\u5B57\u9762\u91CF\uFF09\u4E8C\u9009\u4E00",
3281
3306
  sourceFile
3282
3307
  );
3283
3308
  }
3284
- return { systemPrompt, tools, agents, model, maxTurns, inputDescription };
3309
+ return { systemPrompt, systemPromptFile, tools, agents, model, maxTurns, inputDescription };
3285
3310
  }
3286
3311
  function getPropertyName(name) {
3287
3312
  if (ts11.isIdentifier(name)) return name.text;
@@ -3364,13 +3389,13 @@ var init_extractAgentMetadata = __esm({
3364
3389
  });
3365
3390
 
3366
3391
  // src/cli/generateAgentArtifacts.ts
3367
- import path16 from "path";
3392
+ import path15 from "path";
3368
3393
  function serializeAgents(agents, dist = "dist") {
3369
3394
  return agents.map((a) => ({
3370
3395
  name: a.name,
3371
3396
  description: a.description,
3372
- hasRun: a.hasRun,
3373
3397
  systemPrompt: a.systemPrompt,
3398
+ systemPromptFile: a.systemPromptFile,
3374
3399
  tools: a.tools,
3375
3400
  agents: a.agents,
3376
3401
  model: a.model,
@@ -3390,8 +3415,8 @@ function hydrateAgents(manifest) {
3390
3415
  name: a.name,
3391
3416
  description: a.description ?? void 0,
3392
3417
  filePath: a.filePath,
3393
- hasRun: a.hasRun,
3394
3418
  systemPrompt: a.systemPrompt ?? void 0,
3419
+ systemPromptFile: a.systemPromptFile ?? void 0,
3395
3420
  tools: a.tools ?? void 0,
3396
3421
  agents: a.agents ?? void 0,
3397
3422
  model: a.model ?? void 0,
@@ -3423,14 +3448,13 @@ function validateAgentList(metadata) {
3423
3448
  }
3424
3449
  async function generateAgentArtifacts(agents, rootDir, dist) {
3425
3450
  const metadata = [];
3426
- const programByFile = createPrograms(agents.map((m) => path16.resolve(rootDir, m.filePath)));
3451
+ const programByFile = createPrograms(agents.map((m) => path15.resolve(rootDir, m.filePath)));
3427
3452
  for (const manifest of agents) {
3428
- const absPath = path16.resolve(rootDir, manifest.filePath);
3453
+ const absPath = path15.resolve(rootDir, manifest.filePath);
3429
3454
  const program = programByFile.get(absPath);
3430
3455
  const result = extractAgentMetadata(program, absPath, {
3431
3456
  name: manifest.name,
3432
- filePath: manifest.filePath,
3433
- hasRun: manifest.hasRun
3457
+ filePath: manifest.filePath
3434
3458
  });
3435
3459
  if (!result) {
3436
3460
  throw new Error(
@@ -3441,7 +3465,7 @@ async function generateAgentArtifacts(agents, rootDir, dist) {
3441
3465
  }
3442
3466
  validateAgentList(metadata);
3443
3467
  const serialized = serializeAgents(metadata, dist);
3444
- const agentsPath = path16.resolve(rootDir, dist, AGENTS_FILE);
3468
+ const agentsPath = path15.resolve(rootDir, dist, AGENTS_FILE);
3445
3469
  await writeAgentsModule(serialized, agentsPath);
3446
3470
  return metadata;
3447
3471
  }
@@ -3459,8 +3483,8 @@ var init_generateAgentArtifacts = __esm({
3459
3483
 
3460
3484
  // src/task/scanTasks.ts
3461
3485
  import fg4 from "fast-glob";
3462
- import path17 from "path";
3463
- import fs13 from "fs";
3486
+ import path16 from "path";
3487
+ import fs12 from "fs";
3464
3488
  function parseNumericLiteral(raw) {
3465
3489
  return Number(raw.replace(/_/g, ""));
3466
3490
  }
@@ -3482,12 +3506,12 @@ async function scanTasks(rootDir, patterns) {
3482
3506
  const seen = /* @__PURE__ */ new Map();
3483
3507
  for (const file of files) {
3484
3508
  const normalizedFile = file.replace(/\\/g, "/");
3485
- const fileName = path17.posix.basename(normalizedFile);
3509
+ const fileName = path16.posix.basename(normalizedFile);
3486
3510
  if (fileName !== TASK_FILENAME) {
3487
3511
  continue;
3488
3512
  }
3489
- const absPath = path17.resolve(rootDir, normalizedFile);
3490
- const source = await fs13.promises.readFile(absPath, "utf8").catch(() => "");
3513
+ const absPath = path16.resolve(rootDir, normalizedFile);
3514
+ const source = await fs12.promises.readFile(absPath, "utf8").catch(() => "");
3491
3515
  const name = filePathToTaskName(normalizedFile);
3492
3516
  const prevFile = seen.get(name);
3493
3517
  if (prevFile) {
@@ -3536,7 +3560,7 @@ var init_scanTasks = __esm({
3536
3560
  });
3537
3561
 
3538
3562
  // src/cli/generateTaskArtifacts.ts
3539
- import path18 from "path";
3563
+ import path17 from "path";
3540
3564
  function serializeTasks(tasks, dist = "dist") {
3541
3565
  return tasks.map((t) => ({
3542
3566
  name: t.name,
@@ -3569,7 +3593,7 @@ function collectTaskSchemaSources(tasks, rootDir) {
3569
3593
  const tasksByFile = /* @__PURE__ */ new Map();
3570
3594
  for (const task of tasks) {
3571
3595
  if (!task.inputTypeName) continue;
3572
- const absPath = path18.resolve(rootDir, task.filePath);
3596
+ const absPath = path17.resolve(rootDir, task.filePath);
3573
3597
  let list = tasksByFile.get(absPath);
3574
3598
  if (!list) {
3575
3599
  list = [];
@@ -3626,9 +3650,9 @@ function generateTaskSchemaFileSource(sources, resolveType, helpersImportPath) {
3626
3650
  async function generateTaskArtifacts(manifests, rootDir, dist) {
3627
3651
  const metadata = [];
3628
3652
  if (manifests.length > 0) {
3629
- const programByFile = createPrograms(manifests.map((m) => path18.resolve(rootDir, m.filePath)));
3653
+ const programByFile = createPrograms(manifests.map((m) => path17.resolve(rootDir, m.filePath)));
3630
3654
  for (const manifest of manifests) {
3631
- const absPath = path18.resolve(rootDir, manifest.filePath);
3655
+ const absPath = path17.resolve(rootDir, manifest.filePath);
3632
3656
  const result = extractToolMetadata(programByFile.get(absPath), absPath, "run", {
3633
3657
  name: manifest.name,
3634
3658
  filePath: manifest.filePath
@@ -3639,7 +3663,7 @@ async function generateTaskArtifacts(manifests, rootDir, dist) {
3639
3663
  }
3640
3664
  }
3641
3665
  const serialized = serializeTasks(manifests, dist);
3642
- const tasksPath = path18.resolve(rootDir, dist, TASKS_FILE);
3666
+ const tasksPath = path17.resolve(rootDir, dist, TASKS_FILE);
3643
3667
  await writeTasksModule(serialized, tasksPath);
3644
3668
  if (metadata.length === 0) {
3645
3669
  return hydrateTasks(serialized);
@@ -3672,8 +3696,8 @@ var init_generateTaskArtifacts = __esm({
3672
3696
  });
3673
3697
 
3674
3698
  // src/cli/compileSourceFiles.ts
3675
- import path19 from "path";
3676
- import fs14 from "fs";
3699
+ import path18 from "path";
3700
+ import fs13 from "fs";
3677
3701
  import fg5 from "fast-glob";
3678
3702
  async function compileSourceFiles(options) {
3679
3703
  const { rootDir, dist, files, logLevel = "silent", production, atomicWrite } = options;
@@ -3686,11 +3710,11 @@ async function compileSourceFiles(options) {
3686
3710
  if (entryPoints.length === 0) {
3687
3711
  return { compiledFiles: [] };
3688
3712
  }
3689
- const absDist = path19.resolve(rootDir, dist);
3690
- await fs14.promises.mkdir(absDist, { recursive: true });
3713
+ const absDist = path18.resolve(rootDir, dist);
3714
+ await fs13.promises.mkdir(absDist, { recursive: true });
3691
3715
  const plugins = buildAliasPlugins(rootDir);
3692
3716
  const esbuild = await import("esbuild");
3693
- const outbase = path19.resolve(rootDir, APP_DIR);
3717
+ const outbase = path18.resolve(rootDir, APP_DIR);
3694
3718
  const result = await esbuild.build({
3695
3719
  entryPoints,
3696
3720
  outdir: absDist,
@@ -3710,10 +3734,10 @@ async function compileSourceFiles(options) {
3710
3734
  if (atomicWrite && result.outputFiles) {
3711
3735
  await Promise.all(
3712
3736
  result.outputFiles.map(async (file) => {
3713
- await fs14.promises.mkdir(path19.dirname(file.path), { recursive: true });
3737
+ await fs13.promises.mkdir(path18.dirname(file.path), { recursive: true });
3714
3738
  const tmp = `${file.path}.tmp-${process.pid}-${Math.random().toString(36).slice(2)}`;
3715
- await fs14.promises.writeFile(tmp, file.contents);
3716
- await fs14.promises.rename(tmp, file.path);
3739
+ await fs13.promises.writeFile(tmp, file.contents);
3740
+ await fs13.promises.rename(tmp, file.path);
3717
3741
  })
3718
3742
  );
3719
3743
  }
@@ -3741,12 +3765,12 @@ var init_compileDevRoutes = __esm({
3741
3765
  });
3742
3766
 
3743
3767
  // src/cli/compileOnDemand.ts
3744
- import path20 from "path";
3745
- import fs15 from "fs";
3768
+ import path19 from "path";
3769
+ import fs14 from "fs";
3746
3770
  function isProductFresh(sourceAbsPath, productAbsPath) {
3747
3771
  try {
3748
- const srcStat = fs15.statSync(sourceAbsPath);
3749
- const prodStat = fs15.statSync(productAbsPath);
3772
+ const srcStat = fs14.statSync(sourceAbsPath);
3773
+ const prodStat = fs14.statSync(productAbsPath);
3750
3774
  return prodStat.mtimeMs >= srcStat.mtimeMs;
3751
3775
  } catch {
3752
3776
  return false;
@@ -3776,7 +3800,7 @@ async function ensureCompiled(sourceAbsPath, rootDir, dist) {
3776
3800
  if (state.compiledFiles.has(sourceAbsPath)) {
3777
3801
  return false;
3778
3802
  }
3779
- if (!fs15.existsSync(sourceAbsPath)) {
3803
+ if (!fs14.existsSync(sourceAbsPath)) {
3780
3804
  return false;
3781
3805
  }
3782
3806
  const productPath = prodSourcePathToProductPath(sourceAbsPath, rootDir, dist);
@@ -3826,11 +3850,11 @@ async function ensureMiddlewaresCompiled(middlewarePaths, rootDir) {
3826
3850
  }
3827
3851
  }
3828
3852
  function prodSourcePathToProductPath(sourceAbsPath, rootDir, dist) {
3829
- const rel = path20.relative(rootDir, sourceAbsPath).replace(/\\/g, "/");
3853
+ const rel = path19.relative(rootDir, sourceAbsPath).replace(/\\/g, "/");
3830
3854
  if (!rel.startsWith("src/")) return null;
3831
3855
  const relWithoutSrc = rel.slice(4);
3832
3856
  const jsRel = relWithoutSrc.replace(/\.ts$/, ".js");
3833
- return path20.resolve(rootDir, dist, jsRel);
3857
+ return path19.resolve(rootDir, dist, jsRel);
3834
3858
  }
3835
3859
  function clearGeneratedSchemas() {
3836
3860
  state.generatedSchemas.clear();
@@ -3845,9 +3869,9 @@ async function ensureSchemaGenerated(schemaPath, routeFilePath, routes, rootDir,
3845
3869
  if (state.generatedSchemas.has(schemaPath)) {
3846
3870
  return false;
3847
3871
  }
3848
- const prodAbsPath = path20.resolve(rootDir, routeFilePath);
3872
+ const prodAbsPath = path19.resolve(rootDir, routeFilePath);
3849
3873
  const sourceAbsPath = prodPathToSourcePath(prodAbsPath, rootDir, dist);
3850
- if (!fs15.existsSync(sourceAbsPath)) {
3874
+ if (!fs14.existsSync(sourceAbsPath)) {
3851
3875
  return false;
3852
3876
  }
3853
3877
  if (isProductFresh(sourceAbsPath, schemaPath)) {
@@ -3859,7 +3883,7 @@ async function ensureSchemaGenerated(schemaPath, routeFilePath, routes, rootDir,
3859
3883
  if (fileRoutes.length === 0 && fileWsRoutes.length === 0) {
3860
3884
  return false;
3861
3885
  }
3862
- const sourceRelPath = path20.relative(rootDir, sourceAbsPath).replace(/\\/g, "/");
3886
+ const sourceRelPath = path19.relative(rootDir, sourceAbsPath).replace(/\\/g, "/");
3863
3887
  const sourceRoutes = fileRoutes.map((r) => ({ ...r, filePath: sourceRelPath }));
3864
3888
  const sourceWsRoutes = fileWsRoutes.map((r) => ({ ...r, filePath: sourceRelPath }));
3865
3889
  const generatePromise = (async () => {
@@ -3881,7 +3905,7 @@ async function deleteSchemaFiles(routes, rootDir, dist) {
3881
3905
  if (deleted.has(schemaPath)) continue;
3882
3906
  deleted.add(schemaPath);
3883
3907
  try {
3884
- await fs15.promises.unlink(schemaPath);
3908
+ await fs14.promises.unlink(schemaPath);
3885
3909
  } catch {
3886
3910
  }
3887
3911
  }
@@ -3889,19 +3913,19 @@ async function deleteSchemaFiles(routes, rootDir, dist) {
3889
3913
  function prodPathToSourcePath(prodAbsPath, rootDir, dist) {
3890
3914
  const cached = sourcePathCache.get(prodAbsPath);
3891
3915
  if (cached) return cached;
3892
- const rel = path20.relative(rootDir, prodAbsPath).replace(/\\/g, "/");
3916
+ const rel = path19.relative(rootDir, prodAbsPath).replace(/\\/g, "/");
3893
3917
  let relWithoutDist = rel;
3894
3918
  if (relWithoutDist.startsWith(`${dist}/`)) {
3895
3919
  relWithoutDist = relWithoutDist.slice(dist.length + 1);
3896
3920
  }
3897
3921
  const srcRel = `src/${relWithoutDist}`;
3898
3922
  const tsRel = srcRel.replace(/\.js$/, ".ts");
3899
- const tsAbs = path20.resolve(rootDir, tsRel);
3923
+ const tsAbs = path19.resolve(rootDir, tsRel);
3900
3924
  let result;
3901
- if (fs15.existsSync(tsAbs)) {
3925
+ if (fs14.existsSync(tsAbs)) {
3902
3926
  result = tsAbs;
3903
3927
  } else {
3904
- result = path20.resolve(rootDir, srcRel);
3928
+ result = path19.resolve(rootDir, srcRel);
3905
3929
  }
3906
3930
  sourcePathCache.set(prodAbsPath, result);
3907
3931
  return result;
@@ -3932,15 +3956,15 @@ var init_compileOnDemand = __esm({
3932
3956
  });
3933
3957
 
3934
3958
  // src/config/loadConfig.ts
3935
- import path21 from "path";
3936
- import fs16 from "fs";
3959
+ import path20 from "path";
3960
+ import fs15 from "fs";
3937
3961
  async function loadConfig(rootDir, dist) {
3938
- const configProductPath = path21.resolve(rootDir, dist, CONFIG_PRODUCT_FILE);
3939
- if (fs16.existsSync(configProductPath)) {
3962
+ const configProductPath = path20.resolve(rootDir, dist, CONFIG_PRODUCT_FILE);
3963
+ if (fs15.existsSync(configProductPath)) {
3940
3964
  const module = await importWithCacheBust(configProductPath);
3941
3965
  return module.default ?? {};
3942
3966
  }
3943
- const hasSourceConfig = fs16.existsSync(path21.join(rootDir, "faapi.config.ts")) || fs16.existsSync(path21.join(rootDir, "faapi.config.js"));
3967
+ const hasSourceConfig = fs15.existsSync(path20.join(rootDir, "faapi.config.ts")) || fs15.existsSync(path20.join(rootDir, "faapi.config.js"));
3944
3968
  if (hasSourceConfig) {
3945
3969
  throw new Error(
3946
3970
  `[faapi] ${dist}/${CONFIG_PRODUCT_FILE} \u4E0D\u5B58\u5728\uFF0C\u8BF7\u5148\u6267\u884C \`faapi build\`\uFF08\u6216 \`faapi dev\`\uFF09\u751F\u6210\u4EA7\u7269\u3002`
@@ -3958,8 +3982,8 @@ var init_loadConfig = __esm({
3958
3982
  });
3959
3983
 
3960
3984
  // src/cli/loadEnv.ts
3961
- import fs17 from "fs";
3962
- import path22 from "path";
3985
+ import fs16 from "fs";
3986
+ import path21 from "path";
3963
3987
  function resolveEnv() {
3964
3988
  return process.env.NODE_ENV || "development";
3965
3989
  }
@@ -4026,9 +4050,9 @@ function loadEnv(rootDir) {
4026
4050
  const files = getEnvFiles(env);
4027
4051
  const merged = {};
4028
4052
  for (const file of files) {
4029
- const filePath = path22.join(rootDir, file);
4030
- if (!fs17.existsSync(filePath)) continue;
4031
- const content = fs17.readFileSync(filePath, "utf-8");
4053
+ const filePath = path21.join(rootDir, file);
4054
+ if (!fs16.existsSync(filePath)) continue;
4055
+ const content = fs16.readFileSync(filePath, "utf-8");
4032
4056
  const parsed = parseEnvFile(content, merged);
4033
4057
  Object.assign(merged, parsed);
4034
4058
  }
@@ -4134,7 +4158,7 @@ var init_esm = __esm({
4134
4158
  this._directoryFilter = normalizeFilter(opts.directoryFilter);
4135
4159
  const statMethod = opts.lstat ? lstat : stat;
4136
4160
  if (wantBigintFsStats) {
4137
- this._stat = (path35) => statMethod(path35, { bigint: true });
4161
+ this._stat = (path34) => statMethod(path34, { bigint: true });
4138
4162
  } else {
4139
4163
  this._stat = statMethod;
4140
4164
  }
@@ -4159,8 +4183,8 @@ var init_esm = __esm({
4159
4183
  const par = this.parent;
4160
4184
  const fil = par && par.files;
4161
4185
  if (fil && fil.length > 0) {
4162
- const { path: path35, depth } = par;
4163
- const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path35));
4186
+ const { path: path34, depth } = par;
4187
+ const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path34));
4164
4188
  const awaited = await Promise.all(slice);
4165
4189
  for (const entry of awaited) {
4166
4190
  if (!entry)
@@ -4200,20 +4224,20 @@ var init_esm = __esm({
4200
4224
  this.reading = false;
4201
4225
  }
4202
4226
  }
4203
- async _exploreDir(path35, depth) {
4227
+ async _exploreDir(path34, depth) {
4204
4228
  let files;
4205
4229
  try {
4206
- files = await readdir(path35, this._rdOptions);
4230
+ files = await readdir(path34, this._rdOptions);
4207
4231
  } catch (error) {
4208
4232
  this._onError(error);
4209
4233
  }
4210
- return { files, depth, path: path35 };
4234
+ return { files, depth, path: path34 };
4211
4235
  }
4212
- async _formatEntry(dirent, path35) {
4236
+ async _formatEntry(dirent, path34) {
4213
4237
  let entry;
4214
4238
  const basename3 = this._isDirent ? dirent.name : dirent;
4215
4239
  try {
4216
- const fullPath = presolve(pjoin(path35, basename3));
4240
+ const fullPath = presolve(pjoin(path34, basename3));
4217
4241
  entry = { path: prelative(this._root, fullPath), fullPath, basename: basename3 };
4218
4242
  entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
4219
4243
  } catch (err) {
@@ -4274,16 +4298,16 @@ import { watchFile, unwatchFile, watch as fs_watch } from "fs";
4274
4298
  import { open, stat as stat2, lstat as lstat2, realpath as fsrealpath } from "fs/promises";
4275
4299
  import * as sysPath from "path";
4276
4300
  import { type as osType } from "os";
4277
- function createFsWatchInstance(path35, options, listener, errHandler, emitRaw) {
4301
+ function createFsWatchInstance(path34, options, listener, errHandler, emitRaw) {
4278
4302
  const handleEvent = (rawEvent, evPath) => {
4279
- listener(path35);
4280
- emitRaw(rawEvent, evPath, { watchedPath: path35 });
4281
- if (evPath && path35 !== evPath) {
4282
- fsWatchBroadcast(sysPath.resolve(path35, evPath), KEY_LISTENERS, sysPath.join(path35, evPath));
4303
+ listener(path34);
4304
+ emitRaw(rawEvent, evPath, { watchedPath: path34 });
4305
+ if (evPath && path34 !== evPath) {
4306
+ fsWatchBroadcast(sysPath.resolve(path34, evPath), KEY_LISTENERS, sysPath.join(path34, evPath));
4283
4307
  }
4284
4308
  };
4285
4309
  try {
4286
- return fs_watch(path35, {
4310
+ return fs_watch(path34, {
4287
4311
  persistent: options.persistent
4288
4312
  }, handleEvent);
4289
4313
  } catch (error) {
@@ -4628,12 +4652,12 @@ var init_handler = __esm({
4628
4652
  listener(val1, val2, val3);
4629
4653
  });
4630
4654
  };
4631
- setFsWatchListener = (path35, fullPath, options, handlers) => {
4655
+ setFsWatchListener = (path34, fullPath, options, handlers) => {
4632
4656
  const { listener, errHandler, rawEmitter } = handlers;
4633
4657
  let cont = FsWatchInstances.get(fullPath);
4634
4658
  let watcher;
4635
4659
  if (!options.persistent) {
4636
- watcher = createFsWatchInstance(path35, options, listener, errHandler, rawEmitter);
4660
+ watcher = createFsWatchInstance(path34, options, listener, errHandler, rawEmitter);
4637
4661
  if (!watcher)
4638
4662
  return;
4639
4663
  return watcher.close.bind(watcher);
@@ -4644,7 +4668,7 @@ var init_handler = __esm({
4644
4668
  addAndConvert(cont, KEY_RAW, rawEmitter);
4645
4669
  } else {
4646
4670
  watcher = createFsWatchInstance(
4647
- path35,
4671
+ path34,
4648
4672
  options,
4649
4673
  fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
4650
4674
  errHandler,
@@ -4659,7 +4683,7 @@ var init_handler = __esm({
4659
4683
  cont.watcherUnusable = true;
4660
4684
  if (isWindows && error.code === "EPERM") {
4661
4685
  try {
4662
- const fd = await open(path35, "r");
4686
+ const fd = await open(path34, "r");
4663
4687
  await fd.close();
4664
4688
  broadcastErr(error);
4665
4689
  } catch (err) {
@@ -4690,7 +4714,7 @@ var init_handler = __esm({
4690
4714
  };
4691
4715
  };
4692
4716
  FsWatchFileInstances = /* @__PURE__ */ new Map();
4693
- setFsWatchFileListener = (path35, fullPath, options, handlers) => {
4717
+ setFsWatchFileListener = (path34, fullPath, options, handlers) => {
4694
4718
  const { listener, rawEmitter } = handlers;
4695
4719
  let cont = FsWatchFileInstances.get(fullPath);
4696
4720
  const copts = cont && cont.options;
@@ -4712,7 +4736,7 @@ var init_handler = __esm({
4712
4736
  });
4713
4737
  const currmtime = curr.mtimeMs;
4714
4738
  if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
4715
- foreach(cont.listeners, (listener2) => listener2(path35, curr));
4739
+ foreach(cont.listeners, (listener2) => listener2(path34, curr));
4716
4740
  }
4717
4741
  })
4718
4742
  };
@@ -4740,13 +4764,13 @@ var init_handler = __esm({
4740
4764
  * @param listener on fs change
4741
4765
  * @returns closer for the watcher instance
4742
4766
  */
4743
- _watchWithNodeFs(path35, listener) {
4767
+ _watchWithNodeFs(path34, listener) {
4744
4768
  const opts = this.fsw.options;
4745
- const directory = sysPath.dirname(path35);
4746
- const basename3 = sysPath.basename(path35);
4769
+ const directory = sysPath.dirname(path34);
4770
+ const basename3 = sysPath.basename(path34);
4747
4771
  const parent = this.fsw._getWatchedDir(directory);
4748
4772
  parent.add(basename3);
4749
- const absolutePath = sysPath.resolve(path35);
4773
+ const absolutePath = sysPath.resolve(path34);
4750
4774
  const options = {
4751
4775
  persistent: opts.persistent
4752
4776
  };
@@ -4756,12 +4780,12 @@ var init_handler = __esm({
4756
4780
  if (opts.usePolling) {
4757
4781
  const enableBin = opts.interval !== opts.binaryInterval;
4758
4782
  options.interval = enableBin && isBinaryPath(basename3) ? opts.binaryInterval : opts.interval;
4759
- closer = setFsWatchFileListener(path35, absolutePath, options, {
4783
+ closer = setFsWatchFileListener(path34, absolutePath, options, {
4760
4784
  listener,
4761
4785
  rawEmitter: this.fsw._emitRaw
4762
4786
  });
4763
4787
  } else {
4764
- closer = setFsWatchListener(path35, absolutePath, options, {
4788
+ closer = setFsWatchListener(path34, absolutePath, options, {
4765
4789
  listener,
4766
4790
  errHandler: this._boundHandleError,
4767
4791
  rawEmitter: this.fsw._emitRaw
@@ -4783,7 +4807,7 @@ var init_handler = __esm({
4783
4807
  let prevStats = stats;
4784
4808
  if (parent.has(basename3))
4785
4809
  return;
4786
- const listener = async (path35, newStats) => {
4810
+ const listener = async (path34, newStats) => {
4787
4811
  if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
4788
4812
  return;
4789
4813
  if (!newStats || newStats.mtimeMs === 0) {
@@ -4797,11 +4821,11 @@ var init_handler = __esm({
4797
4821
  this.fsw._emit(EV.CHANGE, file, newStats2);
4798
4822
  }
4799
4823
  if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
4800
- this.fsw._closeFile(path35);
4824
+ this.fsw._closeFile(path34);
4801
4825
  prevStats = newStats2;
4802
4826
  const closer2 = this._watchWithNodeFs(file, listener);
4803
4827
  if (closer2)
4804
- this.fsw._addPathCloser(path35, closer2);
4828
+ this.fsw._addPathCloser(path34, closer2);
4805
4829
  } else {
4806
4830
  prevStats = newStats2;
4807
4831
  }
@@ -4833,7 +4857,7 @@ var init_handler = __esm({
4833
4857
  * @param item basename of this item
4834
4858
  * @returns true if no more processing is needed for this entry.
4835
4859
  */
4836
- async _handleSymlink(entry, directory, path35, item) {
4860
+ async _handleSymlink(entry, directory, path34, item) {
4837
4861
  if (this.fsw.closed) {
4838
4862
  return;
4839
4863
  }
@@ -4843,7 +4867,7 @@ var init_handler = __esm({
4843
4867
  this.fsw._incrReadyCount();
4844
4868
  let linkPath;
4845
4869
  try {
4846
- linkPath = await fsrealpath(path35);
4870
+ linkPath = await fsrealpath(path34);
4847
4871
  } catch (e) {
4848
4872
  this.fsw._emitReady();
4849
4873
  return true;
@@ -4853,12 +4877,12 @@ var init_handler = __esm({
4853
4877
  if (dir.has(item)) {
4854
4878
  if (this.fsw._symlinkPaths.get(full) !== linkPath) {
4855
4879
  this.fsw._symlinkPaths.set(full, linkPath);
4856
- this.fsw._emit(EV.CHANGE, path35, entry.stats);
4880
+ this.fsw._emit(EV.CHANGE, path34, entry.stats);
4857
4881
  }
4858
4882
  } else {
4859
4883
  dir.add(item);
4860
4884
  this.fsw._symlinkPaths.set(full, linkPath);
4861
- this.fsw._emit(EV.ADD, path35, entry.stats);
4885
+ this.fsw._emit(EV.ADD, path34, entry.stats);
4862
4886
  }
4863
4887
  this.fsw._emitReady();
4864
4888
  return true;
@@ -4887,9 +4911,9 @@ var init_handler = __esm({
4887
4911
  return;
4888
4912
  }
4889
4913
  const item = entry.path;
4890
- let path35 = sysPath.join(directory, item);
4914
+ let path34 = sysPath.join(directory, item);
4891
4915
  current.add(item);
4892
- if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path35, item)) {
4916
+ if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path34, item)) {
4893
4917
  return;
4894
4918
  }
4895
4919
  if (this.fsw.closed) {
@@ -4898,8 +4922,8 @@ var init_handler = __esm({
4898
4922
  }
4899
4923
  if (item === target || !target && !previous.has(item)) {
4900
4924
  this.fsw._incrReadyCount();
4901
- path35 = sysPath.join(dir, sysPath.relative(dir, path35));
4902
- this._addToNodeFs(path35, initialAdd, wh, depth + 1);
4925
+ path34 = sysPath.join(dir, sysPath.relative(dir, path34));
4926
+ this._addToNodeFs(path34, initialAdd, wh, depth + 1);
4903
4927
  }
4904
4928
  }).on(EV.ERROR, this._boundHandleError);
4905
4929
  return new Promise((resolve3, reject) => {
@@ -4968,13 +4992,13 @@ var init_handler = __esm({
4968
4992
  * @param depth Child path actually targeted for watch
4969
4993
  * @param target Child path actually targeted for watch
4970
4994
  */
4971
- async _addToNodeFs(path35, initialAdd, priorWh, depth, target) {
4995
+ async _addToNodeFs(path34, initialAdd, priorWh, depth, target) {
4972
4996
  const ready = this.fsw._emitReady;
4973
- if (this.fsw._isIgnored(path35) || this.fsw.closed) {
4997
+ if (this.fsw._isIgnored(path34) || this.fsw.closed) {
4974
4998
  ready();
4975
4999
  return false;
4976
5000
  }
4977
- const wh = this.fsw._getWatchHelpers(path35);
5001
+ const wh = this.fsw._getWatchHelpers(path34);
4978
5002
  if (priorWh) {
4979
5003
  wh.filterPath = (entry) => priorWh.filterPath(entry);
4980
5004
  wh.filterDir = (entry) => priorWh.filterDir(entry);
@@ -4990,8 +5014,8 @@ var init_handler = __esm({
4990
5014
  const follow = this.fsw.options.followSymlinks;
4991
5015
  let closer;
4992
5016
  if (stats.isDirectory()) {
4993
- const absPath = sysPath.resolve(path35);
4994
- const targetPath = follow ? await fsrealpath(path35) : path35;
5017
+ const absPath = sysPath.resolve(path34);
5018
+ const targetPath = follow ? await fsrealpath(path34) : path34;
4995
5019
  if (this.fsw.closed)
4996
5020
  return;
4997
5021
  closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
@@ -5001,29 +5025,29 @@ var init_handler = __esm({
5001
5025
  this.fsw._symlinkPaths.set(absPath, targetPath);
5002
5026
  }
5003
5027
  } else if (stats.isSymbolicLink()) {
5004
- const targetPath = follow ? await fsrealpath(path35) : path35;
5028
+ const targetPath = follow ? await fsrealpath(path34) : path34;
5005
5029
  if (this.fsw.closed)
5006
5030
  return;
5007
5031
  const parent = sysPath.dirname(wh.watchPath);
5008
5032
  this.fsw._getWatchedDir(parent).add(wh.watchPath);
5009
5033
  this.fsw._emit(EV.ADD, wh.watchPath, stats);
5010
- closer = await this._handleDir(parent, stats, initialAdd, depth, path35, wh, targetPath);
5034
+ closer = await this._handleDir(parent, stats, initialAdd, depth, path34, wh, targetPath);
5011
5035
  if (this.fsw.closed)
5012
5036
  return;
5013
5037
  if (targetPath !== void 0) {
5014
- this.fsw._symlinkPaths.set(sysPath.resolve(path35), targetPath);
5038
+ this.fsw._symlinkPaths.set(sysPath.resolve(path34), targetPath);
5015
5039
  }
5016
5040
  } else {
5017
5041
  closer = this._handleFile(wh.watchPath, stats, initialAdd);
5018
5042
  }
5019
5043
  ready();
5020
5044
  if (closer)
5021
- this.fsw._addPathCloser(path35, closer);
5045
+ this.fsw._addPathCloser(path34, closer);
5022
5046
  return false;
5023
5047
  } catch (error) {
5024
5048
  if (this.fsw._handleError(error)) {
5025
5049
  ready();
5026
- return path35;
5050
+ return path34;
5027
5051
  }
5028
5052
  }
5029
5053
  }
@@ -5062,26 +5086,26 @@ function createPattern(matcher) {
5062
5086
  }
5063
5087
  return () => false;
5064
5088
  }
5065
- function normalizePath2(path35) {
5066
- if (typeof path35 !== "string")
5089
+ function normalizePath2(path34) {
5090
+ if (typeof path34 !== "string")
5067
5091
  throw new Error("string expected");
5068
- path35 = sysPath2.normalize(path35);
5069
- path35 = path35.replace(/\\/g, "/");
5092
+ path34 = sysPath2.normalize(path34);
5093
+ path34 = path34.replace(/\\/g, "/");
5070
5094
  let prepend = false;
5071
- if (path35.startsWith("//"))
5095
+ if (path34.startsWith("//"))
5072
5096
  prepend = true;
5073
5097
  const DOUBLE_SLASH_RE2 = /\/\//;
5074
- while (path35.match(DOUBLE_SLASH_RE2))
5075
- path35 = path35.replace(DOUBLE_SLASH_RE2, "/");
5098
+ while (path34.match(DOUBLE_SLASH_RE2))
5099
+ path34 = path34.replace(DOUBLE_SLASH_RE2, "/");
5076
5100
  if (prepend)
5077
- path35 = "/" + path35;
5078
- return path35;
5101
+ path34 = "/" + path34;
5102
+ return path34;
5079
5103
  }
5080
5104
  function matchPatterns(patterns, testString, stats) {
5081
- const path35 = normalizePath2(testString);
5105
+ const path34 = normalizePath2(testString);
5082
5106
  for (let index = 0; index < patterns.length; index++) {
5083
5107
  const pattern = patterns[index];
5084
- if (pattern(path35, stats)) {
5108
+ if (pattern(path34, stats)) {
5085
5109
  return true;
5086
5110
  }
5087
5111
  }
@@ -5142,19 +5166,19 @@ var init_esm2 = __esm({
5142
5166
  }
5143
5167
  return str;
5144
5168
  };
5145
- normalizePathToUnix = (path35) => toUnix(sysPath2.normalize(toUnix(path35)));
5146
- normalizeIgnored = (cwd = "") => (path35) => {
5147
- if (typeof path35 === "string") {
5148
- return normalizePathToUnix(sysPath2.isAbsolute(path35) ? path35 : sysPath2.join(cwd, path35));
5169
+ normalizePathToUnix = (path34) => toUnix(sysPath2.normalize(toUnix(path34)));
5170
+ normalizeIgnored = (cwd = "") => (path34) => {
5171
+ if (typeof path34 === "string") {
5172
+ return normalizePathToUnix(sysPath2.isAbsolute(path34) ? path34 : sysPath2.join(cwd, path34));
5149
5173
  } else {
5150
- return path35;
5174
+ return path34;
5151
5175
  }
5152
5176
  };
5153
- getAbsolutePath = (path35, cwd) => {
5154
- if (sysPath2.isAbsolute(path35)) {
5155
- return path35;
5177
+ getAbsolutePath = (path34, cwd) => {
5178
+ if (sysPath2.isAbsolute(path34)) {
5179
+ return path34;
5156
5180
  }
5157
- return sysPath2.join(cwd, path35);
5181
+ return sysPath2.join(cwd, path34);
5158
5182
  };
5159
5183
  EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
5160
5184
  DirEntry = class {
@@ -5209,10 +5233,10 @@ var init_esm2 = __esm({
5209
5233
  STAT_METHOD_F = "stat";
5210
5234
  STAT_METHOD_L = "lstat";
5211
5235
  WatchHelper = class {
5212
- constructor(path35, follow, fsw) {
5236
+ constructor(path34, follow, fsw) {
5213
5237
  this.fsw = fsw;
5214
- const watchPath = path35;
5215
- this.path = path35 = path35.replace(REPLACER_RE, "");
5238
+ const watchPath = path34;
5239
+ this.path = path34 = path34.replace(REPLACER_RE, "");
5216
5240
  this.watchPath = watchPath;
5217
5241
  this.fullWatchPath = sysPath2.resolve(watchPath);
5218
5242
  this.dirParts = [];
@@ -5334,20 +5358,20 @@ var init_esm2 = __esm({
5334
5358
  this._closePromise = void 0;
5335
5359
  let paths = unifyPaths(paths_);
5336
5360
  if (cwd) {
5337
- paths = paths.map((path35) => {
5338
- const absPath = getAbsolutePath(path35, cwd);
5361
+ paths = paths.map((path34) => {
5362
+ const absPath = getAbsolutePath(path34, cwd);
5339
5363
  return absPath;
5340
5364
  });
5341
5365
  }
5342
- paths.forEach((path35) => {
5343
- this._removeIgnoredPath(path35);
5366
+ paths.forEach((path34) => {
5367
+ this._removeIgnoredPath(path34);
5344
5368
  });
5345
5369
  this._userIgnored = void 0;
5346
5370
  if (!this._readyCount)
5347
5371
  this._readyCount = 0;
5348
5372
  this._readyCount += paths.length;
5349
- Promise.all(paths.map(async (path35) => {
5350
- const res = await this._nodeFsHandler._addToNodeFs(path35, !_internal, void 0, 0, _origAdd);
5373
+ Promise.all(paths.map(async (path34) => {
5374
+ const res = await this._nodeFsHandler._addToNodeFs(path34, !_internal, void 0, 0, _origAdd);
5351
5375
  if (res)
5352
5376
  this._emitReady();
5353
5377
  return res;
@@ -5369,17 +5393,17 @@ var init_esm2 = __esm({
5369
5393
  return this;
5370
5394
  const paths = unifyPaths(paths_);
5371
5395
  const { cwd } = this.options;
5372
- paths.forEach((path35) => {
5373
- if (!sysPath2.isAbsolute(path35) && !this._closers.has(path35)) {
5396
+ paths.forEach((path34) => {
5397
+ if (!sysPath2.isAbsolute(path34) && !this._closers.has(path34)) {
5374
5398
  if (cwd)
5375
- path35 = sysPath2.join(cwd, path35);
5376
- path35 = sysPath2.resolve(path35);
5399
+ path34 = sysPath2.join(cwd, path34);
5400
+ path34 = sysPath2.resolve(path34);
5377
5401
  }
5378
- this._closePath(path35);
5379
- this._addIgnoredPath(path35);
5380
- if (this._watched.has(path35)) {
5402
+ this._closePath(path34);
5403
+ this._addIgnoredPath(path34);
5404
+ if (this._watched.has(path34)) {
5381
5405
  this._addIgnoredPath({
5382
- path: path35,
5406
+ path: path34,
5383
5407
  recursive: true
5384
5408
  });
5385
5409
  }
@@ -5443,38 +5467,38 @@ var init_esm2 = __esm({
5443
5467
  * @param stats arguments to be passed with event
5444
5468
  * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
5445
5469
  */
5446
- async _emit(event, path35, stats) {
5470
+ async _emit(event, path34, stats) {
5447
5471
  if (this.closed)
5448
5472
  return;
5449
5473
  const opts = this.options;
5450
5474
  if (isWindows)
5451
- path35 = sysPath2.normalize(path35);
5475
+ path34 = sysPath2.normalize(path34);
5452
5476
  if (opts.cwd)
5453
- path35 = sysPath2.relative(opts.cwd, path35);
5454
- const args = [path35];
5477
+ path34 = sysPath2.relative(opts.cwd, path34);
5478
+ const args = [path34];
5455
5479
  if (stats != null)
5456
5480
  args.push(stats);
5457
5481
  const awf = opts.awaitWriteFinish;
5458
5482
  let pw;
5459
- if (awf && (pw = this._pendingWrites.get(path35))) {
5483
+ if (awf && (pw = this._pendingWrites.get(path34))) {
5460
5484
  pw.lastChange = /* @__PURE__ */ new Date();
5461
5485
  return this;
5462
5486
  }
5463
5487
  if (opts.atomic) {
5464
5488
  if (event === EVENTS.UNLINK) {
5465
- this._pendingUnlinks.set(path35, [event, ...args]);
5489
+ this._pendingUnlinks.set(path34, [event, ...args]);
5466
5490
  setTimeout(() => {
5467
- this._pendingUnlinks.forEach((entry, path36) => {
5491
+ this._pendingUnlinks.forEach((entry, path35) => {
5468
5492
  this.emit(...entry);
5469
5493
  this.emit(EVENTS.ALL, ...entry);
5470
- this._pendingUnlinks.delete(path36);
5494
+ this._pendingUnlinks.delete(path35);
5471
5495
  });
5472
5496
  }, typeof opts.atomic === "number" ? opts.atomic : 100);
5473
5497
  return this;
5474
5498
  }
5475
- if (event === EVENTS.ADD && this._pendingUnlinks.has(path35)) {
5499
+ if (event === EVENTS.ADD && this._pendingUnlinks.has(path34)) {
5476
5500
  event = EVENTS.CHANGE;
5477
- this._pendingUnlinks.delete(path35);
5501
+ this._pendingUnlinks.delete(path34);
5478
5502
  }
5479
5503
  }
5480
5504
  if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
@@ -5492,16 +5516,16 @@ var init_esm2 = __esm({
5492
5516
  this.emitWithAll(event, args);
5493
5517
  }
5494
5518
  };
5495
- this._awaitWriteFinish(path35, awf.stabilityThreshold, event, awfEmit);
5519
+ this._awaitWriteFinish(path34, awf.stabilityThreshold, event, awfEmit);
5496
5520
  return this;
5497
5521
  }
5498
5522
  if (event === EVENTS.CHANGE) {
5499
- const isThrottled = !this._throttle(EVENTS.CHANGE, path35, 50);
5523
+ const isThrottled = !this._throttle(EVENTS.CHANGE, path34, 50);
5500
5524
  if (isThrottled)
5501
5525
  return this;
5502
5526
  }
5503
5527
  if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
5504
- const fullPath = opts.cwd ? sysPath2.join(opts.cwd, path35) : path35;
5528
+ const fullPath = opts.cwd ? sysPath2.join(opts.cwd, path34) : path34;
5505
5529
  let stats2;
5506
5530
  try {
5507
5531
  stats2 = await stat3(fullPath);
@@ -5532,23 +5556,23 @@ var init_esm2 = __esm({
5532
5556
  * @param timeout duration of time to suppress duplicate actions
5533
5557
  * @returns tracking object or false if action should be suppressed
5534
5558
  */
5535
- _throttle(actionType, path35, timeout) {
5559
+ _throttle(actionType, path34, timeout) {
5536
5560
  if (!this._throttled.has(actionType)) {
5537
5561
  this._throttled.set(actionType, /* @__PURE__ */ new Map());
5538
5562
  }
5539
5563
  const action = this._throttled.get(actionType);
5540
5564
  if (!action)
5541
5565
  throw new Error("invalid throttle");
5542
- const actionPath = action.get(path35);
5566
+ const actionPath = action.get(path34);
5543
5567
  if (actionPath) {
5544
5568
  actionPath.count++;
5545
5569
  return false;
5546
5570
  }
5547
5571
  let timeoutObject;
5548
5572
  const clear = () => {
5549
- const item = action.get(path35);
5573
+ const item = action.get(path34);
5550
5574
  const count = item ? item.count : 0;
5551
- action.delete(path35);
5575
+ action.delete(path34);
5552
5576
  clearTimeout(timeoutObject);
5553
5577
  if (item)
5554
5578
  clearTimeout(item.timeoutObject);
@@ -5556,7 +5580,7 @@ var init_esm2 = __esm({
5556
5580
  };
5557
5581
  timeoutObject = setTimeout(clear, timeout);
5558
5582
  const thr = { timeoutObject, clear, count: 0 };
5559
- action.set(path35, thr);
5583
+ action.set(path34, thr);
5560
5584
  return thr;
5561
5585
  }
5562
5586
  _incrReadyCount() {
@@ -5570,44 +5594,44 @@ var init_esm2 = __esm({
5570
5594
  * @param event
5571
5595
  * @param awfEmit Callback to be called when ready for event to be emitted.
5572
5596
  */
5573
- _awaitWriteFinish(path35, threshold, event, awfEmit) {
5597
+ _awaitWriteFinish(path34, threshold, event, awfEmit) {
5574
5598
  const awf = this.options.awaitWriteFinish;
5575
5599
  if (typeof awf !== "object")
5576
5600
  return;
5577
5601
  const pollInterval = awf.pollInterval;
5578
5602
  let timeoutHandler;
5579
- let fullPath = path35;
5580
- if (this.options.cwd && !sysPath2.isAbsolute(path35)) {
5581
- fullPath = sysPath2.join(this.options.cwd, path35);
5603
+ let fullPath = path34;
5604
+ if (this.options.cwd && !sysPath2.isAbsolute(path34)) {
5605
+ fullPath = sysPath2.join(this.options.cwd, path34);
5582
5606
  }
5583
5607
  const now = /* @__PURE__ */ new Date();
5584
5608
  const writes = this._pendingWrites;
5585
5609
  function awaitWriteFinishFn(prevStat) {
5586
5610
  statcb(fullPath, (err, curStat) => {
5587
- if (err || !writes.has(path35)) {
5611
+ if (err || !writes.has(path34)) {
5588
5612
  if (err && err.code !== "ENOENT")
5589
5613
  awfEmit(err);
5590
5614
  return;
5591
5615
  }
5592
5616
  const now2 = Number(/* @__PURE__ */ new Date());
5593
5617
  if (prevStat && curStat.size !== prevStat.size) {
5594
- writes.get(path35).lastChange = now2;
5618
+ writes.get(path34).lastChange = now2;
5595
5619
  }
5596
- const pw = writes.get(path35);
5620
+ const pw = writes.get(path34);
5597
5621
  const df = now2 - pw.lastChange;
5598
5622
  if (df >= threshold) {
5599
- writes.delete(path35);
5623
+ writes.delete(path34);
5600
5624
  awfEmit(void 0, curStat);
5601
5625
  } else {
5602
5626
  timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
5603
5627
  }
5604
5628
  });
5605
5629
  }
5606
- if (!writes.has(path35)) {
5607
- writes.set(path35, {
5630
+ if (!writes.has(path34)) {
5631
+ writes.set(path34, {
5608
5632
  lastChange: now,
5609
5633
  cancelWait: () => {
5610
- writes.delete(path35);
5634
+ writes.delete(path34);
5611
5635
  clearTimeout(timeoutHandler);
5612
5636
  return event;
5613
5637
  }
@@ -5618,8 +5642,8 @@ var init_esm2 = __esm({
5618
5642
  /**
5619
5643
  * Determines whether user has asked to ignore this path.
5620
5644
  */
5621
- _isIgnored(path35, stats) {
5622
- if (this.options.atomic && DOT_RE.test(path35))
5645
+ _isIgnored(path34, stats) {
5646
+ if (this.options.atomic && DOT_RE.test(path34))
5623
5647
  return true;
5624
5648
  if (!this._userIgnored) {
5625
5649
  const { cwd } = this.options;
@@ -5629,17 +5653,17 @@ var init_esm2 = __esm({
5629
5653
  const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
5630
5654
  this._userIgnored = anymatch(list, void 0);
5631
5655
  }
5632
- return this._userIgnored(path35, stats);
5656
+ return this._userIgnored(path34, stats);
5633
5657
  }
5634
- _isntIgnored(path35, stat4) {
5635
- return !this._isIgnored(path35, stat4);
5658
+ _isntIgnored(path34, stat4) {
5659
+ return !this._isIgnored(path34, stat4);
5636
5660
  }
5637
5661
  /**
5638
5662
  * Provides a set of common helpers and properties relating to symlink handling.
5639
5663
  * @param path file or directory pattern being watched
5640
5664
  */
5641
- _getWatchHelpers(path35) {
5642
- return new WatchHelper(path35, this.options.followSymlinks, this);
5665
+ _getWatchHelpers(path34) {
5666
+ return new WatchHelper(path34, this.options.followSymlinks, this);
5643
5667
  }
5644
5668
  // Directory helpers
5645
5669
  // -----------------
@@ -5671,63 +5695,63 @@ var init_esm2 = __esm({
5671
5695
  * @param item base path of item/directory
5672
5696
  */
5673
5697
  _remove(directory, item, isDirectory) {
5674
- const path35 = sysPath2.join(directory, item);
5675
- const fullPath = sysPath2.resolve(path35);
5676
- isDirectory = isDirectory != null ? isDirectory : this._watched.has(path35) || this._watched.has(fullPath);
5677
- if (!this._throttle("remove", path35, 100))
5698
+ const path34 = sysPath2.join(directory, item);
5699
+ const fullPath = sysPath2.resolve(path34);
5700
+ isDirectory = isDirectory != null ? isDirectory : this._watched.has(path34) || this._watched.has(fullPath);
5701
+ if (!this._throttle("remove", path34, 100))
5678
5702
  return;
5679
5703
  if (!isDirectory && this._watched.size === 1) {
5680
5704
  this.add(directory, item, true);
5681
5705
  }
5682
- const wp = this._getWatchedDir(path35);
5706
+ const wp = this._getWatchedDir(path34);
5683
5707
  const nestedDirectoryChildren = wp.getChildren();
5684
- nestedDirectoryChildren.forEach((nested) => this._remove(path35, nested));
5708
+ nestedDirectoryChildren.forEach((nested) => this._remove(path34, nested));
5685
5709
  const parent = this._getWatchedDir(directory);
5686
5710
  const wasTracked = parent.has(item);
5687
5711
  parent.remove(item);
5688
5712
  if (this._symlinkPaths.has(fullPath)) {
5689
5713
  this._symlinkPaths.delete(fullPath);
5690
5714
  }
5691
- let relPath = path35;
5715
+ let relPath = path34;
5692
5716
  if (this.options.cwd)
5693
- relPath = sysPath2.relative(this.options.cwd, path35);
5717
+ relPath = sysPath2.relative(this.options.cwd, path34);
5694
5718
  if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
5695
5719
  const event = this._pendingWrites.get(relPath).cancelWait();
5696
5720
  if (event === EVENTS.ADD)
5697
5721
  return;
5698
5722
  }
5699
- this._watched.delete(path35);
5723
+ this._watched.delete(path34);
5700
5724
  this._watched.delete(fullPath);
5701
5725
  const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
5702
- if (wasTracked && !this._isIgnored(path35))
5703
- this._emit(eventName, path35);
5704
- this._closePath(path35);
5726
+ if (wasTracked && !this._isIgnored(path34))
5727
+ this._emit(eventName, path34);
5728
+ this._closePath(path34);
5705
5729
  }
5706
5730
  /**
5707
5731
  * Closes all watchers for a path
5708
5732
  */
5709
- _closePath(path35) {
5710
- this._closeFile(path35);
5711
- const dir = sysPath2.dirname(path35);
5712
- this._getWatchedDir(dir).remove(sysPath2.basename(path35));
5733
+ _closePath(path34) {
5734
+ this._closeFile(path34);
5735
+ const dir = sysPath2.dirname(path34);
5736
+ this._getWatchedDir(dir).remove(sysPath2.basename(path34));
5713
5737
  }
5714
5738
  /**
5715
5739
  * Closes only file-specific watchers
5716
5740
  */
5717
- _closeFile(path35) {
5718
- const closers = this._closers.get(path35);
5741
+ _closeFile(path34) {
5742
+ const closers = this._closers.get(path34);
5719
5743
  if (!closers)
5720
5744
  return;
5721
5745
  closers.forEach((closer) => closer());
5722
- this._closers.delete(path35);
5746
+ this._closers.delete(path34);
5723
5747
  }
5724
- _addPathCloser(path35, closer) {
5748
+ _addPathCloser(path34, closer) {
5725
5749
  if (!closer)
5726
5750
  return;
5727
- let list = this._closers.get(path35);
5751
+ let list = this._closers.get(path34);
5728
5752
  if (!list) {
5729
5753
  list = [];
5730
- this._closers.set(path35, list);
5754
+ this._closers.set(path34, list);
5731
5755
  }
5732
5756
  list.push(closer);
5733
5757
  }
@@ -5819,41 +5843,41 @@ var init_rebuildScheduler = __esm({
5819
5843
  });
5820
5844
 
5821
5845
  // src/cli/copyResources.ts
5822
- import path23 from "path";
5823
- import fs18 from "fs";
5846
+ import path22 from "path";
5847
+ import fs17 from "fs";
5824
5848
  function isResourceSourcePath(rootDir, absPath) {
5825
- return isInsideDir(absPath, path23.resolve(rootDir, RESOURCES_DIR));
5849
+ return isInsideDir(absPath, path22.resolve(rootDir, RESOURCES_DIR));
5826
5850
  }
5827
5851
  function resolveResourcesDir(rootDir, dist) {
5828
- return path23.resolve(rootDir, dist, RESOURCES_OUTPUT_DIR);
5852
+ return path22.resolve(rootDir, dist, RESOURCES_OUTPUT_DIR);
5829
5853
  }
5830
5854
  async function copyResources(rootDir, dist) {
5831
- const sourceDir = path23.resolve(rootDir, RESOURCES_DIR);
5832
- if (!fs18.existsSync(sourceDir)) return false;
5855
+ const sourceDir = path22.resolve(rootDir, RESOURCES_DIR);
5856
+ if (!fs17.existsSync(sourceDir)) return false;
5833
5857
  const outDir = resolveResourcesDir(rootDir, dist);
5834
- await fs18.promises.rm(outDir, { recursive: true, force: true });
5835
- await fs18.promises.cp(sourceDir, outDir, { recursive: true });
5858
+ await fs17.promises.rm(outDir, { recursive: true, force: true });
5859
+ await fs17.promises.cp(sourceDir, outDir, { recursive: true });
5836
5860
  return true;
5837
5861
  }
5838
5862
  async function copyResourceFile(rootDir, dist, absSourceFile) {
5839
- const sourceDir = path23.resolve(rootDir, RESOURCES_DIR);
5863
+ const sourceDir = path22.resolve(rootDir, RESOURCES_DIR);
5840
5864
  if (!isInsideDir(absSourceFile, sourceDir)) {
5841
5865
  throw new Error(`[faapi] copyResourceFile: ${absSourceFile} is not under ${RESOURCES_DIR}`);
5842
5866
  }
5843
- if (!fs18.existsSync(absSourceFile)) return;
5844
- const rel = path23.relative(sourceDir, absSourceFile);
5845
- const dest = path23.join(resolveResourcesDir(rootDir, dist), rel);
5846
- await fs18.promises.mkdir(path23.dirname(dest), { recursive: true });
5847
- await fs18.promises.cp(absSourceFile, dest);
5867
+ if (!fs17.existsSync(absSourceFile)) return;
5868
+ const rel = path22.relative(sourceDir, absSourceFile);
5869
+ const dest = path22.join(resolveResourcesDir(rootDir, dist), rel);
5870
+ await fs17.promises.mkdir(path22.dirname(dest), { recursive: true });
5871
+ await fs17.promises.cp(absSourceFile, dest);
5848
5872
  }
5849
5873
  async function removeResourceFile(rootDir, dist, absSourceFile) {
5850
- const sourceDir = path23.resolve(rootDir, RESOURCES_DIR);
5874
+ const sourceDir = path22.resolve(rootDir, RESOURCES_DIR);
5851
5875
  if (!isInsideDir(absSourceFile, sourceDir)) {
5852
5876
  throw new Error(`[faapi] removeResourceFile: ${absSourceFile} is not under ${RESOURCES_DIR}`);
5853
5877
  }
5854
- const rel = path23.relative(sourceDir, absSourceFile);
5855
- const dest = path23.join(resolveResourcesDir(rootDir, dist), rel);
5856
- await fs18.promises.rm(dest, { force: true });
5878
+ const rel = path22.relative(sourceDir, absSourceFile);
5879
+ const dest = path22.join(resolveResourcesDir(rootDir, dist), rel);
5880
+ await fs17.promises.rm(dest, { force: true });
5857
5881
  }
5858
5882
  var RESOURCES_DIR, RESOURCES_OUTPUT_DIR;
5859
5883
  var init_copyResources = __esm({
@@ -5866,7 +5890,7 @@ var init_copyResources = __esm({
5866
5890
  });
5867
5891
 
5868
5892
  // src/cli/watcher.ts
5869
- import path24 from "path";
5893
+ import path23 from "path";
5870
5894
  import { existsSync as existsSync2 } from "fs";
5871
5895
  function startWatcher(options) {
5872
5896
  const { rootDir, app, devDist } = options;
@@ -5901,9 +5925,9 @@ function startWatcher(options) {
5901
5925
  }
5902
5926
  });
5903
5927
  const CONFIG_FILES = ["faapi.config.ts", "faapi.config.js"];
5904
- const configAbsPaths = new Set(CONFIG_FILES.map((f) => path24.resolve(rootDir, f)));
5928
+ const configAbsPaths = new Set(CONFIG_FILES.map((f) => path23.resolve(rootDir, f)));
5905
5929
  const watchPaths = ["src", "tsconfig.json", ...CONFIG_FILES];
5906
- const scheduleOnly = /* @__PURE__ */ new Set([...configAbsPaths, path24.resolve(rootDir, "tsconfig.json")]);
5930
+ const scheduleOnly = /* @__PURE__ */ new Set([...configAbsPaths, path23.resolve(rootDir, "tsconfig.json")]);
5907
5931
  const watcher = esm_default.watch(watchPaths, {
5908
5932
  cwd: rootDir,
5909
5933
  ignoreInitial: true,
@@ -5914,14 +5938,14 @@ function startWatcher(options) {
5914
5938
  }
5915
5939
  if (!stats) return false;
5916
5940
  if (stats.isDirectory()) return false;
5917
- if (isResourceSourcePath(rootDir, path24.resolve(rootDir, filePath))) return false;
5941
+ if (isResourceSourcePath(rootDir, path23.resolve(rootDir, filePath))) return false;
5918
5942
  return !filePath.endsWith(".ts") && !filePath.endsWith(".js");
5919
5943
  }
5920
5944
  });
5921
5945
  watcher.on("add", (file) => handleFileEvent(file));
5922
5946
  watcher.on("change", (file) => handleFileEvent(file));
5923
5947
  function handleFileEvent(file) {
5924
- const abs = path24.resolve(rootDir, file);
5948
+ const abs = path23.resolve(rootDir, file);
5925
5949
  if (isResourceSourcePath(rootDir, abs)) {
5926
5950
  void copyResourceFile(rootDir, devDist, abs).catch((err) => {
5927
5951
  console.error(
@@ -5941,7 +5965,7 @@ function startWatcher(options) {
5941
5965
  scheduler.addFiles([abs]);
5942
5966
  }
5943
5967
  watcher.on("unlink", (file) => {
5944
- const abs = path24.resolve(rootDir, file);
5968
+ const abs = path23.resolve(rootDir, file);
5945
5969
  if (isResourceSourcePath(rootDir, abs)) {
5946
5970
  void removeResourceFile(rootDir, devDist, abs).catch((err) => {
5947
5971
  console.error(
@@ -6056,25 +6080,25 @@ function getWsIndex(routes) {
6056
6080
  wsIndexCache.set(routes, index);
6057
6081
  return index;
6058
6082
  }
6059
- function matchRoute(routes, method, path35) {
6083
+ function matchRoute(routes, method, path34) {
6060
6084
  const index = getHttpIndex(routes);
6061
6085
  const upper = method.toUpperCase();
6062
- const hit = matchByMethod(index, upper, path35);
6086
+ const hit = matchByMethod(index, upper, path34);
6063
6087
  if (hit) return hit;
6064
6088
  if (upper === "HEAD") {
6065
- return matchByMethod(index, "GET", path35);
6089
+ return matchByMethod(index, "GET", path34);
6066
6090
  }
6067
6091
  return null;
6068
6092
  }
6069
- function matchByMethod(index, method, path35) {
6070
- const staticHit = index.static.get(`${method}|${path35}`);
6093
+ function matchByMethod(index, method, path34) {
6094
+ const staticHit = index.static.get(`${method}|${path34}`);
6071
6095
  if (staticHit) {
6072
6096
  return { route: staticHit, params: {} };
6073
6097
  }
6074
6098
  if (index.dynamics.length === 0) {
6075
6099
  return null;
6076
6100
  }
6077
- const pathSegments = path35.split("/").filter(Boolean);
6101
+ const pathSegments = path34.split("/").filter(Boolean);
6078
6102
  for (const entry of index.dynamics) {
6079
6103
  const route = entry.route;
6080
6104
  if (route.method !== method) {
@@ -6087,31 +6111,31 @@ function matchByMethod(index, method, path35) {
6087
6111
  }
6088
6112
  return null;
6089
6113
  }
6090
- function matchWsRoute(wsRoutes, path35) {
6114
+ function matchWsRoute(wsRoutes, path34) {
6091
6115
  const index = getWsIndex(wsRoutes);
6092
- const staticHit = index.static.get(path35);
6116
+ const staticHit = index.static.get(path34);
6093
6117
  if (staticHit) {
6094
6118
  return { route: staticHit, params: {} };
6095
6119
  }
6096
6120
  for (const route of index.dynamics) {
6097
- const params = matchDynamicPath(route.urlPath, path35, route.paramNames, route.isCatchAll);
6121
+ const params = matchDynamicPath(route.urlPath, path34, route.paramNames, route.isCatchAll);
6098
6122
  if (params !== null) {
6099
6123
  return { route, params };
6100
6124
  }
6101
6125
  }
6102
6126
  return null;
6103
6127
  }
6104
- function findAllowedMethods(routes, path35) {
6128
+ function findAllowedMethods(routes, path34) {
6105
6129
  const index = getHttpIndex(routes);
6106
6130
  const methods = /* @__PURE__ */ new Set();
6107
- const staticMethods = index.methodsByStaticPath.get(path35);
6131
+ const staticMethods = index.methodsByStaticPath.get(path34);
6108
6132
  if (staticMethods) {
6109
6133
  for (const method of staticMethods) {
6110
6134
  methods.add(method);
6111
6135
  }
6112
6136
  }
6113
6137
  if (index.dynamics.length > 0) {
6114
- const pathSegments = path35.split("/").filter(Boolean);
6138
+ const pathSegments = path34.split("/").filter(Boolean);
6115
6139
  for (const entry of index.dynamics) {
6116
6140
  const params = matchSegments(
6117
6141
  entry.segments,
@@ -6129,10 +6153,10 @@ function findAllowedMethods(routes, path35) {
6129
6153
  }
6130
6154
  return Array.from(methods);
6131
6155
  }
6132
- function matchDynamicPath(pattern, path35, paramNames, isCatchAll) {
6156
+ function matchDynamicPath(pattern, path34, paramNames, isCatchAll) {
6133
6157
  return matchSegments(
6134
6158
  pattern.split("/").filter(Boolean),
6135
- path35.split("/").filter(Boolean),
6159
+ path34.split("/").filter(Boolean),
6136
6160
  paramNames,
6137
6161
  isCatchAll
6138
6162
  );
@@ -6611,14 +6635,14 @@ var init_httpErrors = __esm({
6611
6635
  issues;
6612
6636
  };
6613
6637
  RouteNotFoundError = class extends FaapiError {
6614
- constructor(path35) {
6615
- super("ROUTE_NOT_FOUND", `Route not found: ${path35}`, 404);
6638
+ constructor(path34) {
6639
+ super("ROUTE_NOT_FOUND", `Route not found: ${path34}`, 404);
6616
6640
  this.name = "RouteNotFoundError";
6617
6641
  }
6618
6642
  };
6619
6643
  MethodNotAllowedError = class extends FaapiError {
6620
- constructor(method, path35, allowedMethods) {
6621
- super("METHOD_NOT_ALLOWED", `Method ${method} not allowed for ${path35}`, 405);
6644
+ constructor(method, path34, allowedMethods) {
6645
+ super("METHOD_NOT_ALLOWED", `Method ${method} not allowed for ${path34}`, 405);
6622
6646
  this.allowedMethods = allowedMethods;
6623
6647
  this.name = "MethodNotAllowedError";
6624
6648
  }
@@ -6754,17 +6778,17 @@ var init_formatEntry = __esm({
6754
6778
  });
6755
6779
 
6756
6780
  // src/logger/fileSink.ts
6757
- import fs19 from "fs";
6758
- import path25 from "path";
6781
+ import fs18 from "fs";
6782
+ import path24 from "path";
6759
6783
  function createFileLogSink(options) {
6760
- fs19.mkdirSync(options.dir, { recursive: true });
6784
+ fs18.mkdirSync(options.dir, { recursive: true });
6761
6785
  const streams = /* @__PURE__ */ new Map();
6762
6786
  const getStream = (name) => {
6763
6787
  if (streams.has(name)) return streams.get(name);
6764
6788
  return void 0;
6765
6789
  };
6766
6790
  const openStream = (name) => {
6767
- const stream = fs19.createWriteStream(path25.join(options.dir, `${name}.log`), { flags: "a" });
6791
+ const stream = fs18.createWriteStream(path24.join(options.dir, `${name}.log`), { flags: "a" });
6768
6792
  stream.on("error", () => {
6769
6793
  });
6770
6794
  streams.set(name, stream);
@@ -7972,9 +7996,9 @@ async function validateInput(schemaPath, method, inputType, input) {
7972
7996
  function mapZodIssues(error) {
7973
7997
  return error.issues.map((issue) => {
7974
7998
  const code = mapZodCode(issue);
7975
- const path35 = issue.path.map(String).join(".") || "";
7999
+ const path34 = issue.path.map(String).join(".") || "";
7976
8000
  return {
7977
- path: path35,
8001
+ path: path34,
7978
8002
  code,
7979
8003
  expected: issue.expected ?? mapExpectedFromMessage(issue.message),
7980
8004
  received: issue.received ?? mapReceivedFromMessage(issue.message),
@@ -8498,9 +8522,9 @@ var init_wsHandler = __esm({
8498
8522
  });
8499
8523
 
8500
8524
  // src/server/handleWsUpgrade.ts
8501
- import fs20 from "fs";
8525
+ import fs19 from "fs";
8502
8526
  import { WebSocketServer, WebSocket } from "ws";
8503
- import path26 from "path";
8527
+ import path25 from "path";
8504
8528
  function getPathname(req) {
8505
8529
  const url = req.url ?? "/";
8506
8530
  const idx = url.indexOf("?");
@@ -8511,7 +8535,7 @@ async function loadWsHandler(filePath, ctx, rootDir) {
8511
8535
  const dist = getDevDist();
8512
8536
  if (dist) {
8513
8537
  const sourcePath = prodPathToSourcePath(filePath, rootDir, dist);
8514
- if (sourcePath && fs20.existsSync(sourcePath)) {
8538
+ if (sourcePath && fs19.existsSync(sourcePath)) {
8515
8539
  await ensureCompiled(sourcePath, rootDir, dist);
8516
8540
  }
8517
8541
  }
@@ -8653,7 +8677,7 @@ function attachWebSocket(options) {
8653
8677
  let upgraded = false;
8654
8678
  const finalHandler = async () => {
8655
8679
  const schemaPath = getRuntimeSchemaPath(route.filePath, dist, rootDir);
8656
- if (fs20.existsSync(schemaPath)) {
8680
+ if (fs19.existsSync(schemaPath)) {
8657
8681
  if (isDevOnDemandEnabled()) {
8658
8682
  const devDist = getDevDist();
8659
8683
  if (devDist) {
@@ -8692,7 +8716,7 @@ function attachWebSocket(options) {
8692
8716
  }
8693
8717
  let handlers;
8694
8718
  try {
8695
- const absoluteFilePath = path26.resolve(rootDir, route.filePath);
8719
+ const absoluteFilePath = path25.resolve(rootDir, route.filePath);
8696
8720
  handlers = await loadWsHandler(absoluteFilePath, ctx, rootDir);
8697
8721
  } catch (err) {
8698
8722
  const reason = err instanceof Error ? err.message : String(err);
@@ -8773,7 +8797,7 @@ import {
8773
8797
  import { createSecureServer as createHttp2SecureServer } from "http2";
8774
8798
  import { readFileSync } from "fs";
8775
8799
  import { Readable as Readable3 } from "stream";
8776
- import path27 from "path";
8800
+ import path26 from "path";
8777
8801
  function toWebRequest(req, bodyLimit = DEFAULT_BODY_LIMIT, requestSignal) {
8778
8802
  const forwardedProto = req.headers["x-forwarded-proto"];
8779
8803
  const protocol = Array.isArray(forwardedProto) ? forwardedProto[0]?.split(",")[0]?.trim() ?? "http" : forwardedProto?.split(",")[0]?.trim() ?? "http";
@@ -8979,7 +9003,7 @@ function getRoutePaths(route, rootDir, dist) {
8979
9003
  let cached = routePathCache.get(route);
8980
9004
  if (!cached) {
8981
9005
  cached = {
8982
- absFilePath: path27.resolve(rootDir, route.filePath),
9006
+ absFilePath: path26.resolve(rootDir, route.filePath),
8983
9007
  schemaPath: getRuntimeSchemaPath(route.filePath, dist, rootDir)
8984
9008
  };
8985
9009
  routePathCache.set(route, cached);
@@ -9412,7 +9436,11 @@ async function runTaskInWorker(options) {
9412
9436
  worker.postMessage({
9413
9437
  type: "run",
9414
9438
  payload,
9415
- taskCtx: { config: safeConfig(taskCtx.config), job: taskCtx.job },
9439
+ taskCtx: {
9440
+ config: safeConfig(taskCtx.config),
9441
+ resourcesDir: taskCtx.resourcesDir,
9442
+ job: taskCtx.job
9443
+ },
9416
9444
  registries: options.registries,
9417
9445
  log: options.log
9418
9446
  });
@@ -9538,7 +9566,7 @@ function createTaskLogger(level, scope, fields) {
9538
9566
  });
9539
9567
 
9540
9568
  // src/task/taskQueue.ts
9541
- import path28 from "path";
9569
+ import path27 from "path";
9542
9570
  function createTaskQueue(deps) {
9543
9571
  const { registry, rootDir, driver } = deps;
9544
9572
  const registriesView = deps.registries ?? createEmptyTaskRegistriesView();
@@ -9568,7 +9596,7 @@ function createTaskQueue(deps) {
9568
9596
  }
9569
9597
  const loadTaskModule = deps.loadTaskModule ?? (async (filePath) => await import(filePath));
9570
9598
  const loadPayloadSchema = deps.loadPayloadSchema ?? (async (filePath) => {
9571
- const zodPath = path28.join(path28.dirname(filePath), "zod.js");
9599
+ const zodPath = path27.join(path27.dirname(filePath), "zod.js");
9572
9600
  try {
9573
9601
  const mod = await import(zodPath);
9574
9602
  const schemaKey = Object.keys(mod).find((k) => k.endsWith("Schema"));
@@ -9596,7 +9624,7 @@ function createTaskQueue(deps) {
9596
9624
  const meta = registry.get(name);
9597
9625
  schemaCache.set(
9598
9626
  name,
9599
- await loadPayloadSchema(path28.resolve(rootDir, meta.filePath)).catch(() => void 0)
9627
+ await loadPayloadSchema(path27.resolve(rootDir, meta.filePath)).catch(() => void 0)
9600
9628
  );
9601
9629
  }
9602
9630
  const schema = schemaCache.get(name);
@@ -9632,10 +9660,11 @@ function createTaskQueue(deps) {
9632
9660
  let result;
9633
9661
  if (meta.timeoutMs !== void 0 && meta.timeoutMs > 0) {
9634
9662
  result = await (deps.runIsolated ?? runTaskInWorker)({
9635
- taskModulePath: path28.resolve(rootDir, meta.filePath),
9663
+ taskModulePath: path27.resolve(rootDir, meta.filePath),
9636
9664
  payload: job.payload,
9637
9665
  taskCtx: {
9638
9666
  config: deps.config,
9667
+ resourcesDir: deps.resourcesDir,
9639
9668
  job: { id: job.id, name: job.name, attempt: job.attempt }
9640
9669
  },
9641
9670
  registries: snapshotRegistries(),
@@ -9657,7 +9686,7 @@ function createTaskQueue(deps) {
9657
9686
  } else {
9658
9687
  let mod = moduleCache2.get(job.name);
9659
9688
  if (!mod) {
9660
- mod = await loadTaskModule(path28.resolve(rootDir, meta.filePath));
9689
+ mod = await loadTaskModule(path27.resolve(rootDir, meta.filePath));
9661
9690
  moduleCache2.set(job.name, mod);
9662
9691
  }
9663
9692
  if (typeof mod.run !== "function") {
@@ -9666,6 +9695,7 @@ function createTaskQueue(deps) {
9666
9695
  const taskCtx = {
9667
9696
  signal: job.signal,
9668
9697
  config: deps.config,
9698
+ resourcesDir: deps.resourcesDir,
9669
9699
  job: { id: job.id, name: job.name, attempt: job.attempt },
9670
9700
  registries: registriesView,
9671
9701
  log: createLogger(`task:${job.name}`, {
@@ -9946,8 +9976,8 @@ var init_cronScheduler = __esm({
9946
9976
  });
9947
9977
 
9948
9978
  // src/cli/loadPlugins.ts
9949
- import path29 from "path";
9950
- import fs21 from "fs";
9979
+ import path28 from "path";
9980
+ import fs20 from "fs";
9951
9981
  import { pathToFileURL as pathToFileURL3 } from "url";
9952
9982
  async function loadPlugins(declarations, ctx, rootDir, dist) {
9953
9983
  const handlerWrappers = [];
@@ -10010,30 +10040,30 @@ async function loadPlugins(declarations, ctx, rootDir, dist) {
10010
10040
  return { handlerWrappers, upgradeWrappers, failures };
10011
10041
  }
10012
10042
  function resolveLocalPluginSource(specifier, baseDir) {
10013
- const base = path29.isAbsolute(specifier) ? specifier : path29.resolve(baseDir, specifier);
10014
- if ((TS_EXTS.test(base) || JS_EXTS.test(base)) && fs21.existsSync(base)) return base;
10043
+ const base = path28.isAbsolute(specifier) ? specifier : path28.resolve(baseDir, specifier);
10044
+ if ((TS_EXTS.test(base) || JS_EXTS.test(base)) && fs20.existsSync(base)) return base;
10015
10045
  for (const ext of [".ts", ".js"]) {
10016
- if (fs21.existsSync(base + ext)) return base + ext;
10046
+ if (fs20.existsSync(base + ext)) return base + ext;
10017
10047
  }
10018
10048
  for (const indexExt of ["/index.ts", "/index.js"]) {
10019
- if (fs21.existsSync(base + indexExt)) return base + indexExt;
10049
+ if (fs20.existsSync(base + indexExt)) return base + indexExt;
10020
10050
  }
10021
10051
  return null;
10022
10052
  }
10023
10053
  function mirrorProductPath(sourcePath, baseDir, distDir) {
10024
- let rel = path29.relative(baseDir, sourcePath).replace(/\\/g, "/");
10054
+ let rel = path28.relative(baseDir, sourcePath).replace(/\\/g, "/");
10025
10055
  if (rel.startsWith("src/")) rel = rel.slice(4);
10026
- return path29.resolve(distDir, rel.replace(TS_EXTS, ".js"));
10056
+ return path28.resolve(distDir, rel.replace(TS_EXTS, ".js"));
10027
10057
  }
10028
10058
  async function importPluginModule(specifier, baseDir, dist) {
10029
10059
  const isRelative = specifier.startsWith("./") || specifier.startsWith("../");
10030
- if (!isRelative && !path29.isAbsolute(specifier)) {
10060
+ if (!isRelative && !path28.isAbsolute(specifier)) {
10031
10061
  return import(specifier);
10032
10062
  }
10033
- const distDir = dist ? path29.resolve(baseDir, dist) : null;
10063
+ const distDir = dist ? path28.resolve(baseDir, dist) : null;
10034
10064
  const sourcePath = resolveLocalPluginSource(specifier, baseDir);
10035
10065
  const productPath = sourcePath && distDir ? mirrorProductPath(sourcePath, baseDir, distDir) : null;
10036
- if (productPath !== null && fs21.existsSync(productPath) && (sourcePath === null || isProductFresh(sourcePath, productPath))) {
10066
+ if (productPath !== null && fs20.existsSync(productPath) && (sourcePath === null || isProductFresh(sourcePath, productPath))) {
10037
10067
  return import(pathToFileURL3(productPath).href);
10038
10068
  }
10039
10069
  if (sourcePath && TS_EXTS.test(sourcePath)) {
@@ -10042,13 +10072,13 @@ async function importPluginModule(specifier, baseDir, dist) {
10042
10072
  `Local plugin "${specifier}" has no up-to-date build artifact (dist is stale or missing). Run "faapi build" first, or use "faapi dev" for on-demand compilation.`
10043
10073
  );
10044
10074
  }
10045
- const relFromRoot = path29.relative(baseDir, sourcePath).replace(/\\/g, "/");
10075
+ const relFromRoot = path28.relative(baseDir, sourcePath).replace(/\\/g, "/");
10046
10076
  if (relFromRoot.startsWith("src/")) {
10047
10077
  await ensureCompiled(sourcePath, baseDir, dist);
10048
10078
  } else {
10049
10079
  await compileProjectModules([sourcePath], baseDir, dist);
10050
10080
  }
10051
- if (productPath && fs21.existsSync(productPath)) {
10081
+ if (productPath && fs20.existsSync(productPath)) {
10052
10082
  return import(pathToFileURL3(productPath).href);
10053
10083
  }
10054
10084
  }
@@ -10060,7 +10090,7 @@ async function importPluginModule(specifier, baseDir, dist) {
10060
10090
  `${specifier}/index.ts`,
10061
10091
  `${specifier}.js`,
10062
10092
  `${specifier}/index.js`
10063
- ].map((c) => path29.isAbsolute(c) ? c : path29.join(baseDir, c));
10093
+ ].map((c) => path28.isAbsolute(c) ? c : path28.join(baseDir, c));
10064
10094
  throw new Error(
10065
10095
  `Cannot find local plugin "${specifier}" (resolved from ${baseDir}). Expected one of:
10066
10096
  ${candidates.join("\n ")}
@@ -10095,11 +10125,11 @@ var init_loadPlugins = __esm({
10095
10125
  });
10096
10126
 
10097
10127
  // src/cli/manifestLoader.ts
10098
- import fs22 from "fs";
10099
- import path30 from "path";
10128
+ import fs21 from "fs";
10129
+ import path29 from "path";
10100
10130
  async function loadAndHydrateTools(rootDir, dist, registries = defaultRegistries) {
10101
- const toolsPath = path30.resolve(rootDir, dist, TOOLS_FILE2);
10102
- if (!fs22.existsSync(toolsPath)) {
10131
+ const toolsPath = path29.resolve(rootDir, dist, TOOLS_FILE2);
10132
+ if (!fs21.existsSync(toolsPath)) {
10103
10133
  return [];
10104
10134
  }
10105
10135
  const serialized = await importWithCacheBust(toolsPath);
@@ -10108,8 +10138,8 @@ async function loadAndHydrateTools(rootDir, dist, registries = defaultRegistries
10108
10138
  return hydrated;
10109
10139
  }
10110
10140
  async function loadAndHydrateAgents(rootDir, dist, registries = defaultRegistries) {
10111
- const agentsPath = path30.resolve(rootDir, dist, AGENTS_FILE2);
10112
- if (!fs22.existsSync(agentsPath)) {
10141
+ const agentsPath = path29.resolve(rootDir, dist, AGENTS_FILE2);
10142
+ if (!fs21.existsSync(agentsPath)) {
10113
10143
  return [];
10114
10144
  }
10115
10145
  const serialized = await importWithCacheBust(agentsPath);
@@ -10124,8 +10154,8 @@ function getTaskDriverOptions(config) {
10124
10154
  return void 0;
10125
10155
  }
10126
10156
  async function loadAndHydrateTasks(rootDir, dist, registries = defaultRegistries) {
10127
- const tasksPath = path30.resolve(rootDir, dist, TASKS_FILE);
10128
- if (!fs22.existsSync(tasksPath)) {
10157
+ const tasksPath = path29.resolve(rootDir, dist, TASKS_FILE);
10158
+ if (!fs21.existsSync(tasksPath)) {
10129
10159
  return [];
10130
10160
  }
10131
10161
  const serialized = await importWithCacheBust(tasksPath);
@@ -10272,8 +10302,8 @@ var init_injectMock = __esm({
10272
10302
  });
10273
10303
 
10274
10304
  // src/cli/createAppCore.ts
10275
- import fs23 from "fs";
10276
- import path31 from "path";
10305
+ import fs22 from "fs";
10306
+ import path30 from "path";
10277
10307
  function isFaapiConfigKey(key) {
10278
10308
  return FAAPI_CONFIG_KEYS.has(key);
10279
10309
  }
@@ -10299,8 +10329,7 @@ function logStartupSummary(routes, wsRoutes, tools, agents, taskMetas, p) {
10299
10329
  if (agents.length > 0) {
10300
10330
  console.log(`- Loaded ${agents.length} agent(s):`);
10301
10331
  for (const agent of agents) {
10302
- const exports = agent.hasRun ? "run" : "-";
10303
- console.log(` ${agent.name} [${exports}] ${agent.filePath}`);
10332
+ console.log(` ${agent.name} ${agent.filePath}`);
10304
10333
  }
10305
10334
  }
10306
10335
  if (taskMetas.length > 0) {
@@ -10315,8 +10344,8 @@ async function createAppBase(options) {
10315
10344
  const rootDir = options?.rootDir ?? process.cwd();
10316
10345
  const dist = options?.dist ?? process.env.FAAPI_DIST ?? DEFAULT_DIST;
10317
10346
  const resourcesDir = resolveResourcesDir(rootDir, dist);
10318
- const routesPath = path31.resolve(rootDir, dist, ROUTES_FILE);
10319
- if (!fs23.existsSync(routesPath)) {
10347
+ const routesPath = path30.resolve(rootDir, dist, ROUTES_FILE);
10348
+ if (!fs22.existsSync(routesPath)) {
10320
10349
  throw new Error(
10321
10350
  `[faapi] ${dist}/${ROUTES_FILE} \u4E0D\u5B58\u5728\uFF0C\u8BF7\u5148\u6267\u884C \`faapi build\`\uFF08\u6216 \`faapi dev\`\uFF09\u751F\u6210\u4EA7\u7269\u3002`
10322
10351
  );
@@ -10337,6 +10366,7 @@ async function createAppBase(options) {
10337
10366
  registry: registries.task,
10338
10367
  rootDir,
10339
10368
  config,
10369
+ resourcesDir,
10340
10370
  registries: createTaskRegistriesView(registries),
10341
10371
  driver: taskDriver,
10342
10372
  onFailed: config?.task?.onFailed
@@ -10378,6 +10408,7 @@ async function createAppBase(options) {
10378
10408
  config?.plugins,
10379
10409
  {
10380
10410
  rootDir,
10411
+ resourcesDir,
10381
10412
  registries,
10382
10413
  routes: sorted,
10383
10414
  getRoutes: () => sorted,
@@ -10578,7 +10609,7 @@ var init_createAppCore = __esm({
10578
10609
  });
10579
10610
 
10580
10611
  // src/cli/createDevApp.ts
10581
- import path32 from "path";
10612
+ import path31 from "path";
10582
10613
  async function createDevApp(options) {
10583
10614
  const { app, ctx } = await createAppBase(options);
10584
10615
  const devApp = app;
@@ -10628,7 +10659,7 @@ async function createDevApp(options) {
10628
10659
  if (!suppressProgramInvalidation) invalidateProgramCache();
10629
10660
  const tasks = await scanTasks(ctx.rootDir, TASK_PATTERNS);
10630
10661
  for (const task of tasks) {
10631
- await ensureCompiled(path32.resolve(ctx.rootDir, task.filePath), ctx.rootDir, ctx.dist);
10662
+ await ensureCompiled(path31.resolve(ctx.rootDir, task.filePath), ctx.rootDir, ctx.dist);
10632
10663
  }
10633
10664
  await generateTaskArtifacts(tasks, ctx.rootDir, ctx.dist);
10634
10665
  ctx.taskQueue.invalidateModules();
@@ -10685,7 +10716,7 @@ __export(devCommand_exports, {
10685
10716
  generateTaskArtifactsForDev: () => generateTaskArtifactsForDev,
10686
10717
  generateToolArtifactsForDev: () => generateToolArtifactsForDev
10687
10718
  });
10688
- import path33 from "path";
10719
+ import path32 from "path";
10689
10720
  async function devCommand(options) {
10690
10721
  const rootDir = process.cwd();
10691
10722
  if (!process.env.NODE_ENV) process.env.NODE_ENV = "development";
@@ -10709,7 +10740,7 @@ async function devCommand(options) {
10709
10740
  console.log("- Copying resources...");
10710
10741
  const copied = await copyResources(rootDir, devDist);
10711
10742
  if (copied)
10712
- console.log(` Copied src/resources \u2192 ${path33.resolve(rootDir, devDist, "resources")}`);
10743
+ console.log(` Copied src/resources \u2192 ${path32.resolve(rootDir, devDist, "resources")}`);
10713
10744
  console.log("- Starting dev app...");
10714
10745
  const app = await createDevApp({ rootDir, port: options?.port });
10715
10746
  await app.listen();
@@ -10718,7 +10749,7 @@ async function devCommand(options) {
10718
10749
  async function generateRouteArtifacts(rootDir, patterns, dist) {
10719
10750
  const { routes, wsRoutes } = await scanRoutes(rootDir, patterns, dist);
10720
10751
  const sorted = sortRoutes(routes);
10721
- const routesPath = path33.resolve(rootDir, dist, ROUTES_FILE2);
10752
+ const routesPath = path32.resolve(rootDir, dist, ROUTES_FILE2);
10722
10753
  const serialized = serializeRoutes(sorted, wsRoutes, rootDir, dist);
10723
10754
  await writeRoutesModule(serialized, routesPath);
10724
10755
  }
@@ -10733,7 +10764,7 @@ async function generateAgentArtifactsForDev(rootDir, dist) {
10733
10764
  async function generateTaskArtifactsForDev(rootDir, dist) {
10734
10765
  const tasks = await scanTasks(rootDir, TASK_PATTERNS);
10735
10766
  for (const task of tasks) {
10736
- await ensureCompiled(path33.resolve(rootDir, task.filePath), rootDir, dist);
10767
+ await ensureCompiled(path32.resolve(rootDir, task.filePath), rootDir, dist);
10737
10768
  }
10738
10769
  await generateTaskArtifacts(tasks, rootDir, dist);
10739
10770
  }
@@ -10782,15 +10813,15 @@ var buildCommand_exports = {};
10782
10813
  __export(buildCommand_exports, {
10783
10814
  buildCommand: () => buildCommand
10784
10815
  });
10785
- import path34 from "path";
10786
- import fs24 from "fs";
10816
+ import path33 from "path";
10817
+ import fs23 from "fs";
10787
10818
  async function buildCommand(options) {
10788
10819
  const rootDir = options?.rootDir ?? process.cwd();
10789
10820
  const outdir = options?.dist ?? DEFAULT_DIST2;
10790
- const absOut = path34.resolve(rootDir, outdir);
10791
- const realRoot = toRealPath(path34.resolve(rootDir));
10821
+ const absOut = path33.resolve(rootDir, outdir);
10822
+ const realRoot = toRealPath(path33.resolve(rootDir));
10792
10823
  if (isInsideDir(toRealPath(absOut), realRoot)) {
10793
- fs24.rmSync(absOut, { recursive: true, force: true });
10824
+ fs23.rmSync(absOut, { recursive: true, force: true });
10794
10825
  } else {
10795
10826
  console.warn(
10796
10827
  `! Output directory "${outdir}" is outside the project root, skipping clean (stale artifacts may remain)`
@@ -10798,10 +10829,10 @@ async function buildCommand(options) {
10798
10829
  }
10799
10830
  await compileConfig({ rootDir, dist: outdir });
10800
10831
  const _config = await loadConfig(rootDir, outdir);
10801
- const pkgPath = path34.resolve(rootDir, "package.json");
10802
- if (fs24.existsSync(pkgPath)) {
10832
+ const pkgPath = path33.resolve(rootDir, "package.json");
10833
+ if (fs23.existsSync(pkgPath)) {
10803
10834
  try {
10804
- const pkg = JSON.parse(fs24.readFileSync(pkgPath, "utf-8"));
10835
+ const pkg = JSON.parse(fs23.readFileSync(pkgPath, "utf-8"));
10805
10836
  if (pkg.type !== "module") {
10806
10837
  console.warn(
10807
10838
  '! package.json is missing "type": "module" \u2014 build output is ESM and `node dist/main` will fail without it'
@@ -10829,7 +10860,7 @@ async function buildCommand(options) {
10829
10860
  if (localPluginSources.length > 0) {
10830
10861
  console.log("\n[2.5/9] Compiling local plugins...");
10831
10862
  const outside = localPluginSources.filter((p) => {
10832
- const rel = path34.relative(rootDir, p).replace(/\\/g, "/");
10863
+ const rel = path33.relative(rootDir, p).replace(/\\/g, "/");
10833
10864
  return !rel.startsWith("src/");
10834
10865
  });
10835
10866
  if (outside.length > 0) {
@@ -10844,9 +10875,9 @@ async function buildCommand(options) {
10844
10875
  reportRouteConflicts(sorted);
10845
10876
  console.log("\n[4/9] Generating schema...");
10846
10877
  await generateSchemaFiles(sorted, rootDir, outdir, wsRoutes);
10847
- console.log(` Schema: zod.js files under ${path34.resolve(rootDir, outdir)}`);
10878
+ console.log(` Schema: zod.js files under ${path33.resolve(rootDir, outdir)}`);
10848
10879
  console.log("\n[5/9] Generating routes manifest...");
10849
- const routesPath = path34.resolve(rootDir, outdir, "faapi-routes.js");
10880
+ const routesPath = path33.resolve(rootDir, outdir, "faapi-routes.js");
10850
10881
  const serialized = serializeRoutes(sorted, wsRoutes, rootDir, outdir);
10851
10882
  await writeRoutesModule(serialized, routesPath);
10852
10883
  console.log(` Written to ${routesPath}`);
@@ -10854,24 +10885,24 @@ async function buildCommand(options) {
10854
10885
  const tools = await scanTools(rootDir, TOOL_PATTERNS);
10855
10886
  const toolMeta = await generateToolArtifacts(tools, rootDir, outdir);
10856
10887
  console.log(` Found ${toolMeta.length} tool(s)`);
10857
- console.log(` Tool manifest: ${path34.resolve(rootDir, outdir, "faapi-tools.js")}`);
10888
+ console.log(` Tool manifest: ${path33.resolve(rootDir, outdir, "faapi-tools.js")}`);
10858
10889
  console.log("\n[7/9] Generating agent manifest...");
10859
10890
  const agents = await scanAgents(rootDir, DEFAULT_AGENT_PATTERNS);
10860
10891
  const agentMeta = await generateAgentArtifacts(agents, rootDir, outdir);
10861
10892
  console.log(` Found ${agentMeta.length} agent(s)`);
10862
- console.log(` Agent manifest: ${path34.resolve(rootDir, outdir, "faapi-agents.js")}`);
10893
+ console.log(` Agent manifest: ${path33.resolve(rootDir, outdir, "faapi-agents.js")}`);
10863
10894
  console.log("\n[7.5/9] Generating task manifest and schema...");
10864
10895
  const tasks = await scanTasks(rootDir, TASK_PATTERNS);
10865
10896
  const taskMeta = await generateTaskArtifacts(tasks, rootDir, outdir);
10866
10897
  console.log(` Found ${taskMeta.length} task(s)`);
10867
- console.log(` Task manifest: ${path34.resolve(rootDir, outdir, "faapi-tasks.js")}`);
10898
+ console.log(` Task manifest: ${path33.resolve(rootDir, outdir, "faapi-tasks.js")}`);
10868
10899
  console.log("\n[8/9] Copying resources...");
10869
10900
  const resourcesCopied = await copyResources(rootDir, outdir);
10870
10901
  if (resourcesCopied) {
10871
- console.log(` Copied src/resources \u2192 ${path34.resolve(rootDir, outdir, "resources")}`);
10902
+ console.log(` Copied src/resources \u2192 ${path33.resolve(rootDir, outdir, "resources")}`);
10872
10903
  }
10873
10904
  console.log("\n[9/9] Generating entry file...");
10874
- const mainPath = path34.resolve(rootDir, outdir, "main.js");
10905
+ const mainPath = path33.resolve(rootDir, outdir, "main.js");
10875
10906
  const createProdAppArgs = options?.dist && options.dist !== DEFAULT_DIST2 ? `{ dist: ${JSON.stringify(outdir)} }` : "";
10876
10907
  const mainContent = `// \u7531 faapi build \u81EA\u52A8\u751F\u6210\uFF0C\u8BF7\u52FF\u624B\u52A8\u7F16\u8F91
10877
10908
  import { createProdApp, loadEnv } from '@faapi/faapi';
@@ -10883,7 +10914,7 @@ loadEnv(process.cwd());
10883
10914
  const app = await createProdApp(${createProdAppArgs});
10884
10915
  await app.listen();
10885
10916
  `;
10886
- await fs24.promises.writeFile(mainPath, mainContent, "utf-8");
10917
+ await fs23.promises.writeFile(mainPath, mainContent, "utf-8");
10887
10918
  console.log(` Written to ${mainPath}`);
10888
10919
  console.log("\nfaapi build completed");
10889
10920
  }
@@ -10897,7 +10928,7 @@ function extractLocalPluginSources(declarations, rootDir) {
10897
10928
  else if (Array.isArray(decl)) specifier = decl[0];
10898
10929
  else if ("path" in decl) specifier = decl.path;
10899
10930
  if (!specifier) continue;
10900
- if (!specifier.startsWith("./") && !specifier.startsWith("../") && !path34.isAbsolute(specifier)) {
10931
+ if (!specifier.startsWith("./") && !specifier.startsWith("../") && !path33.isAbsolute(specifier)) {
10901
10932
  continue;
10902
10933
  }
10903
10934
  const source = resolveLocalPluginSource(specifier, rootDir);