@adep/cli 0.5.7 → 0.5.8

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/index.js CHANGED
@@ -26,6 +26,9 @@ function resolvePaths(env = process.env) {
26
26
  function resolveServer(env = process.env) {
27
27
  return (env["ADEP_SERVER"] ?? "https://adep.top").replace(/\/+$/, "");
28
28
  }
29
+ function normalizeFunctionsPrefix(prefix) {
30
+ return prefix.replace(/^\/+|\/+$/g, "");
31
+ }
29
32
  function resolveElectronMirror(env = process.env) {
30
33
  return env["ELECTRON_MIRROR"] ?? DEFAULT_ELECTRON_MIRROR;
31
34
  }
@@ -1298,7 +1301,9 @@ var init_worker_executor = __esm({
1298
1301
  ...input2.env === void 0 ? {} : { env: input2.env },
1299
1302
  ...deps === void 0 ? {} : { deps },
1300
1303
  ...this.parity ? { parity: true } : {},
1301
- ...effectiveFetchConfig === void 0 ? {} : { fetch: effectiveFetchConfig }
1304
+ ...effectiveFetchConfig === void 0 ? {} : { fetch: effectiveFetchConfig },
1305
+ // W2:预编译提示随 workerData 下发(结构化克隆可跨线程;缺省不传 = 全量编译路径)。
1306
+ ...input2.compileHints === void 0 ? {} : { compileHints: input2.compileHints }
1302
1307
  },
1303
1308
  resourceLimits: { maxOldGenerationSizeMb: memoryLimitMb }
1304
1309
  });
@@ -1397,14 +1402,14 @@ var init_dialect = __esm({
1397
1402
  placeholder: () => "?",
1398
1403
  quote: (identifier) => `"${identifier.replace(/"/g, '""')}"`,
1399
1404
  lastInsertIdClause: () => "",
1400
- upsertConflictClause: (columns) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")}) DO NOTHING`
1405
+ upsertConflictClause: (columns, doUpdateSet) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")})` + (doUpdateSet ? ` DO UPDATE SET ${doUpdateSet}` : " DO NOTHING")
1401
1406
  };
1402
1407
  postgresDialect = {
1403
1408
  name: "postgres",
1404
1409
  placeholder: (index) => `$${index + 1}`,
1405
1410
  quote: (identifier) => `"${identifier.replace(/"/g, '""')}"`,
1406
1411
  lastInsertIdClause: () => " RETURNING id",
1407
- upsertConflictClause: (columns) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")}) DO NOTHING`
1412
+ upsertConflictClause: (columns, doUpdateSet) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")})` + (doUpdateSet ? ` DO UPDATE SET ${doUpdateSet}` : " DO NOTHING")
1408
1413
  };
1409
1414
  }
1410
1415
  });
@@ -1745,6 +1750,9 @@ function compileWhere(wheres, dialect, params) {
1745
1750
  if (value === null) {
1746
1751
  if (where.operator === "=") return `${quoted} IS NULL`;
1747
1752
  if (where.operator === "!=") return `${quoted} IS NOT NULL`;
1753
+ throw unsafeOperation(
1754
+ `NULL \u53EA\u80FD\u4E0E = / != \u6BD4\u8F83\uFF08${where.operator} NULL \u6052\u4E3A UNKNOWN\uFF0C\u4F1A\u9759\u9ED8\u8FD4\u56DE\u7A7A\u96C6\uFF09\uFF1A\u5217 ${where.column}`
1755
+ );
1748
1756
  }
1749
1757
  const mark = pushParam(params, dialect, value);
1750
1758
  return `${quoted} ${where.operator} ${mark}`;
@@ -1819,6 +1827,44 @@ function compileInsertMany(table, rows, dialect) {
1819
1827
  params
1820
1828
  };
1821
1829
  }
1830
+ function resolveUpsertPlan(row, options) {
1831
+ const target = [...options.target];
1832
+ if (target.length === 0) {
1833
+ throw unsafeOperation("upsert \u7684 target \u5FC5\u987B\u81F3\u5C11\u4E00\u5217\uFF08\u51B2\u7A81\u5224\u5B9A\u65E0\u5217\u5219\u65E0\u4ECE\u8C08\u8D77\uFF09");
1834
+ }
1835
+ target.forEach(assertUserColumn);
1836
+ const targetSet = new Set(target);
1837
+ const rowColumns = new Set(Object.keys(row));
1838
+ if (rowColumns.size === 0) {
1839
+ throw unsafeOperation("upsert \u81F3\u5C11\u9700\u8981\u4E00\u4E2A\u5B57\u6BB5");
1840
+ }
1841
+ const update = options.update === void 0 ? [...rowColumns].filter((name) => !targetSet.has(name)) : [...options.update];
1842
+ update.forEach(assertUserColumn);
1843
+ const overlapping = update.filter((name) => targetSet.has(name));
1844
+ if (overlapping.length > 0) {
1845
+ throw unsafeOperation(`upsert \u7684 update \u5217\u4E0D\u80FD\u4E0E target \u91CD\u53E0\uFF08\u51B2\u7A81\u884C\u4E3B\u952E\u4E0D\u6539\uFF09\uFF1A${overlapping.join(", ")}`);
1846
+ }
1847
+ const missing = update.filter((name) => !rowColumns.has(name));
1848
+ if (missing.length > 0) {
1849
+ throw unsafeOperation(`upsert \u7684 update \u5217\u5FC5\u987B\u51FA\u73B0\u5728 row \u4E2D\uFF08\u503C\u53D6\u81EA row\uFF09\uFF1A${missing.join(", ")}`);
1850
+ }
1851
+ return { target, update };
1852
+ }
1853
+ function compileUpsert(table, row, options, dialect) {
1854
+ const { target, update } = resolveUpsertPlan(row, options);
1855
+ const params = [];
1856
+ const entries = Object.entries(row);
1857
+ const columns = entries.map(([name]) => {
1858
+ assertUserColumn(name);
1859
+ return dialect.quote(name);
1860
+ }).join(", ");
1861
+ const marks = entries.map(([, value]) => pushParam(params, dialect, value));
1862
+ const doUpdateSet = update.length === 0 ? null : update.map((name) => `${dialect.quote(name)} = ${pushParam(params, dialect, row[name])}`).join(", ");
1863
+ return {
1864
+ sql: `INSERT INTO ${dialect.quote(table)} (${columns}) VALUES (${marks.join(", ")})${dialect.upsertConflictClause(target, doUpdateSet)}`,
1865
+ params
1866
+ };
1867
+ }
1822
1868
  function compileUpdate(table, wheres, values, dialect) {
1823
1869
  const entries = Object.entries(values);
1824
1870
  if (entries.length === 0) {
@@ -1959,6 +2005,17 @@ function createTableBuilder(table, driver, dialect, options = {}) {
1959
2005
  const compiled = compileInsertMany(state.table, rows, dialect);
1960
2006
  await driver.run(compiled.sql, compiled.params);
1961
2007
  },
2008
+ async upsert(row, conflict) {
2009
+ guardWrite();
2010
+ Object.keys(row).forEach(assertUserColumn);
2011
+ if (await resolveOwned(state, driver)) {
2012
+ throw unsafeOperation(
2013
+ "upsert \u4E0D\u652F\u6301 owned \u8868\uFF1A\u53D8\u66F4\u6D41\u65E0\u6CD5\u8868\u8FBE\u300C\u63D2\u5165\u8FD8\u662F\u66F4\u65B0\u300D\u7684\u4E8C\u4E49\uFF08before/after \u987B\u786E\u5B9A\uFF09\uFF0C\u8BF7\u6539\u7528 insert / update"
2014
+ );
2015
+ }
2016
+ const compiled = compileUpsert(state.table, row, conflict, dialect);
2017
+ await driver.run(compiled.sql, compiled.params);
2018
+ },
1962
2019
  async update(values) {
1963
2020
  guardWrite();
1964
2021
  assertHasWhere(state);
@@ -2251,13 +2308,23 @@ var init_cloud = __esm({
2251
2308
  CLOUD_DB_SPEC = {
2252
2309
  kind: "cloud-db",
2253
2310
  rootMethod: "table",
2254
- stepMethods: ["select", "where", "orderBy", "limit", "offset"],
2255
- terminalMethods: ["get", "first", "count", "insert", "insertMany", "update", "delete"],
2311
+ // 规格清单必须与构建器公开方法面一致(防漂移门 spec-drift.test.ts 双向咬合):
2312
+ // - owned:DB-006 的 owned 声明(step);
2313
+ // - execute:BUG-4 统一执行入口(direct,宿主侧 DB_RPC.execute 分支早已在);
2314
+ // - upsert:DB-010 终端(漏登记过一次,真机 500,见 spec-drift.test.ts 头注释)。
2315
+ stepMethods: ["select", "where", "orderBy", "limit", "offset", "owned"],
2316
+ terminalMethods: ["get", "first", "count", "insert", "insertMany", "update", "delete", "upsert"],
2256
2317
  // CF-013:writeQuery 是 D1 shim 的写路径(INSERT/UPDATE/DELETE),与 query 并列直通方法。
2257
- directMethods: ["query", "writeQuery", "changes"],
2318
+ directMethods: ["query", "writeQuery", "execute", "changes"],
2258
2319
  transactionMethod: "transaction"
2259
2320
  };
2260
- WRITE_TERMINALS = /* @__PURE__ */ new Set(["insert", "insertMany", "update", "delete"]);
2321
+ WRITE_TERMINALS = /* @__PURE__ */ new Set([
2322
+ "insert",
2323
+ "insertMany",
2324
+ "update",
2325
+ "delete",
2326
+ "upsert"
2327
+ ]);
2261
2328
  }
2262
2329
  });
2263
2330
 
@@ -5719,13 +5786,32 @@ var init_runtime2 = __esm({
5719
5786
  }
5720
5787
  /**
5721
5788
  * alarm 轮询:把到期对象唤醒并调 onAlarm(CF-037)。
5789
+ * - 到期集合 = 后端落库到期记录 ∪ **驻留实例的内存 alarmAt(驻留时以内存值为准)**:
5790
+ * `setAlarm`/`clearAlarm` 只写内存、`alarmAt` 随 `flush()` 落库——若 pump 只读后端,
5791
+ * 「setAlarm 后没 flush」会静默丢调度(rift-brawl 实锤:先 flush 再 setAlarm,闹钟永不触发),
5792
+ * 反向「clearAlarm 后没 flush」会因 DB 残留到期值误触发。重启续接仍以落库值为准
5793
+ * (实例不驻留时后端值是唯一事实;要重启不丢 alarm,方法内仍须 flush——见 features/state-objects.md)。
5722
5794
  * - onAlarm 后统一持久化(flush):onAlarm 内改的 state 与 setAlarm 重调度 / clearAlarm
5723
5795
  * 的新 alarmAt 都落库;
5724
5796
  * - 单对象 onAlarm 抛错**不阻塞**同 tick 其余对象:失败对象不落库、alarmAt 保留
5725
5797
  * → 下轮 dueAlarms 仍命中重试;错误折叠进 failed(不泄漏内部栈)。
5726
5798
  */
5727
5799
  async pump(now) {
5728
- const due = await this.backend.dueAlarms(now);
5800
+ const dueMap = /* @__PURE__ */ new Map();
5801
+ for (const d of await this.backend.dueAlarms(now)) {
5802
+ dueMap.set(this.key(d.type, d.id), d);
5803
+ }
5804
+ for (const [k, inst] of this.instances) {
5805
+ const typeName = inst.constructor.typeName;
5806
+ if (typeName === void 0) continue;
5807
+ const raw = inst;
5808
+ if (raw.alarmAt === null || raw.alarmAt > now) {
5809
+ dueMap.delete(k);
5810
+ continue;
5811
+ }
5812
+ dueMap.set(k, { type: typeName, id: inst.id, alarmAt: raw.alarmAt });
5813
+ }
5814
+ const due = [...dueMap.values()].toSorted((a, b) => a.alarmAt - b.alarmAt);
5729
5815
  const fired = [];
5730
5816
  const failed = [];
5731
5817
  for (const d of due) {
@@ -6315,7 +6401,7 @@ ${DYNAMIC_IMPORT_HINT}` : "";
6315
6401
  if (typeof code === "string") wrapped.code = code;
6316
6402
  return wrapped;
6317
6403
  }
6318
- function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths = false) {
6404
+ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths = false, hints) {
6319
6405
  const cached2 = cache.get(path);
6320
6406
  if (cached2 !== void 0) return cached2;
6321
6407
  const source = files[path];
@@ -6336,7 +6422,7 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
6336
6422
  }
6337
6423
  const resolved = resolveModulePath(dir, request, files);
6338
6424
  if (resolved !== null) {
6339
- return loadModule(resolved, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths);
6425
+ return loadModule(resolved, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths, hints);
6340
6426
  }
6341
6427
  if (resolveBare !== void 0 && !request.startsWith("./") && !request.startsWith("../")) {
6342
6428
  const cachedModule = bareCache?.get(request);
@@ -6351,21 +6437,33 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
6351
6437
  error62.code = SANDBOX_BUILTIN_REJECTED;
6352
6438
  throw error62;
6353
6439
  };
6354
- let transformed;
6440
+ const hint = hints?.[path];
6441
+ let scriptSource;
6355
6442
  try {
6356
- transformed = transformExports(transpile(source));
6443
+ scriptSource = hint !== void 0 ? hint.js : `${WRAPPER_PREFIX}${transformExports(transpile(source))}${WRAPPER_SUFFIX}`;
6357
6444
  } catch (error62) {
6358
6445
  throw syntaxErrorWithLocation(error62, path, source);
6359
6446
  }
6360
6447
  const context = createSandboxContext(sandboxGlobals);
6361
6448
  let wrapper;
6362
6449
  try {
6363
- wrapper = vm.runInContext(
6364
- `(function (module, exports, require) { ${transformed}
6365
- })`,
6366
- context,
6367
- { filename: path }
6368
- );
6450
+ if (hint !== void 0 && hint.cachedData !== void 0) {
6451
+ const script = new vm.Script(scriptSource, {
6452
+ filename: path,
6453
+ cachedData: Buffer.from(
6454
+ hint.cachedData.buffer,
6455
+ hint.cachedData.byteOffset,
6456
+ hint.cachedData.byteLength
6457
+ )
6458
+ });
6459
+ if (script.cachedDataRejected !== true) {
6460
+ wrapper = script.runInContext(context);
6461
+ } else {
6462
+ wrapper = vm.runInContext(scriptSource, context, { filename: path });
6463
+ }
6464
+ } else {
6465
+ wrapper = vm.runInContext(scriptSource, context, { filename: path });
6466
+ }
6369
6467
  } catch (error62) {
6370
6468
  throw syntaxErrorWithLocation(error62, path, source);
6371
6469
  }
@@ -6375,7 +6473,7 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
6375
6473
  }
6376
6474
  return exports;
6377
6475
  }
6378
- function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPaths = false) {
6476
+ function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPaths = false, hints) {
6379
6477
  const cache = /* @__PURE__ */ new Map();
6380
6478
  const bareCache = /* @__PURE__ */ new Map();
6381
6479
  const entryExports = loadModule(
@@ -6385,15 +6483,18 @@ function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPat
6385
6483
  cache,
6386
6484
  resolveBare,
6387
6485
  bareCache,
6388
- strictPaths
6486
+ strictPaths,
6487
+ hints
6389
6488
  );
6390
6489
  const handler = entryExports["default"];
6391
6490
  if (typeof handler !== "function") {
6392
- throw new Error(`\u5165\u53E3\u6587\u4EF6 ${entry} \u7F3A\u5C11 default \u5BFC\u51FA\u7684\u51FD\u6570`);
6491
+ const base = entry.replace(/^.*\//, "");
6492
+ const hint = base === "state-objects.ts" || entry.startsWith("durable-objects/") ? '\u3002\u8BE5\u6587\u4EF6\u662F\u72B6\u6001\u5BF9\u8C61\u58F0\u660E\u6587\u4EF6\uFF0C\u653E\u5728 functions/ \u76EE\u5F55\u5185\u4F1A\u540C\u65F6\u88AB\u5F53\u4F5C\u4E91\u51FD\u6570\u5165\u53E3\uFF1A\u8865\u4E00\u4E2A default \u5BFC\u51FA\u7684\u5360\u4F4D handler\uFF0C\u4F8B\u5982 `export default async () => ({ error: "state objects \u8BF7\u8D70 /api/state/<type>/<id>/<method>" })`' : "";
6493
+ throw new Error(`\u5165\u53E3\u6587\u4EF6 ${entry} \u7F3A\u5C11 default \u5BFC\u51FA\u7684\u51FD\u6570${hint}`);
6393
6494
  }
6394
6495
  return { handler };
6395
6496
  }
6396
- var bunTranspiler, SANDBOX_BUILTIN_REJECTED, REALM_VALUE_KEY, DYNAMIC_IMPORT_HINT;
6497
+ var bunTranspiler, SANDBOX_BUILTIN_REJECTED, REALM_VALUE_KEY, DYNAMIC_IMPORT_HINT, WRAPPER_PREFIX, WRAPPER_SUFFIX;
6397
6498
  var init_sandbox = __esm({
6398
6499
  "packages/runtime/src/functions/runtime/sandbox.ts"() {
6399
6500
  "use strict";
@@ -6402,6 +6503,8 @@ var init_sandbox = __esm({
6402
6503
  SANDBOX_BUILTIN_REJECTED = "FN_SANDBOX_BUILTIN_BLOCKED";
6403
6504
  REALM_VALUE_KEY = "__adepRealmValue";
6404
6505
  DYNAMIC_IMPORT_HINT = "\u63D0\u793A\uFF1AM1 \u6C99\u7BB1\u4E0D\u652F\u6301\u52A8\u6001 import\uFF0C\u6539\u9759\u6001 import";
6506
+ WRAPPER_PREFIX = "(function (module, exports, require) { ";
6507
+ WRAPPER_SUFFIX = " \n})";
6405
6508
  }
6406
6509
  });
6407
6510
 
@@ -7205,7 +7308,9 @@ function runWorker(input2, port) {
7205
7308
  sandboxGlobals,
7206
7309
  input2.deps === void 0 ? void 0 : createBareResolver(input2.deps),
7207
7310
  // CORE-154:--parity 严格模式连带 `../` 越根引用报错(与容器形态真实 fs 同形)。
7208
- input2.parity === true
7311
+ input2.parity === true,
7312
+ // W2:预编译提示透传(缺省 undefined = 全量编译路径,零回归)。
7313
+ input2.compileHints
7209
7314
  );
7210
7315
  const result = Promise.resolve(handler(ctx));
7211
7316
  void result.then(
@@ -7624,14 +7729,14 @@ async function loadConfig(cwd) {
7624
7729
  return {
7625
7730
  name: config2?.name ?? name,
7626
7731
  functionsDir: config2?.functionsDir ?? "functions",
7627
- functionsPrefix: config2?.functions_prefix ?? "",
7732
+ functionsPrefix: normalizeFunctionsPrefix(config2?.functions_prefix ?? ""),
7628
7733
  ...config2?.environment === void 0 ? {} : { environment: config2.environment },
7629
7734
  ...config2?.db_environment === void 0 ? {} : { dbEnvironment: config2.db_environment }
7630
7735
  };
7631
7736
  }
7632
7737
  function resolveRouteFnName(pathname, prefix) {
7633
7738
  const segments = pathname.split("/").filter((segment) => segment.length > 0);
7634
- const normalizedPrefix = prefix.replace(/^\/+|\/+$/g, "");
7739
+ const normalizedPrefix = normalizeFunctionsPrefix(prefix);
7635
7740
  if (normalizedPrefix.length === 0) {
7636
7741
  const first = segments[0];
7637
7742
  return first === void 0 ? {} : { fnName: first };
@@ -7675,7 +7780,7 @@ async function startDevServer(options) {
7675
7780
  `));
7676
7781
  const config2 = await loadConfig(cwd);
7677
7782
  if (options.prefix !== void 0) {
7678
- config2.functionsPrefix = options.prefix.replace(/^\/+|\/+$/g, "");
7783
+ config2.functionsPrefix = normalizeFunctionsPrefix(options.prefix);
7679
7784
  }
7680
7785
  const functionsDir = join13(cwd, config2.functionsDir);
7681
7786
  const coldStartAt = Date.now();
@@ -7853,7 +7958,7 @@ async function startDevServer(options) {
7853
7958
  return;
7854
7959
  }
7855
7960
  if (fnName === "state") {
7856
- const normalizedPrefix = config2.functionsPrefix.replace(/^\/+|\/+$/g, "");
7961
+ const normalizedPrefix = normalizeFunctionsPrefix(config2.functionsPrefix);
7857
7962
  const rest = normalizedPrefix.length === 0 ? url2.pathname : url2.pathname.replace(new RegExp(`^/${normalizedPrefix}`), "");
7858
7963
  const parsed = parseStatePath(rest);
7859
7964
  if (parsed === null) {
@@ -7964,13 +8069,19 @@ async function startDevServer(options) {
7964
8069
  const baseUrl = `http://127.0.0.1:${actualPort}`;
7965
8070
  runtime.storage.signer.baseUrl = baseUrl;
7966
8071
  const coldStartMs = Date.now() - coldStartAt;
7967
- const curlPath = config2.functionsPrefix.length === 0 ? "/hello" : `/${config2.functionsPrefix}/hello`;
8072
+ const functionNames = listFunctionNames(files);
8073
+ const firstFunction = functionNames[0];
8074
+ const curlPath = firstFunction === void 0 ? null : config2.functionsPrefix.length === 0 ? `/${firstFunction}` : `/${config2.functionsPrefix}/${firstFunction}`;
7968
8075
  const dbLabel = db.mode === "sqlite" ? `SQLite \u771F\u5B9E\u5E93${db.module === null ? "" : `\uFF08${db.module}\uFF09`}` : "sim \u5F15\u64CE\uFF08\u5185\u7F6E\u6A21\u62DF\uFF09";
7969
8076
  const dbTargetText = db.file === null ? simDbTarget(cwd) : displayPath(cwd, db.file);
7970
8077
  log(
7971
8078
  `[adep] dev server listening on ${baseUrl}\uFF08\u672C\u5730\u8FD0\u884C\u65F6 / ${dbLabel}\uFF0C\u51B7\u542F\u52A8 ${coldStartMs}ms\uFF09`
7972
8079
  );
7973
- log(`[adep] curl \u793A\u4F8B\uFF1Acurl ${baseUrl}${curlPath}`);
8080
+ if (curlPath === null) {
8081
+ log("[adep] functions/ \u76EE\u5F55\u4E3A\u7A7A\uFF1A\u6682\u65E0\u51FD\u6570\u53EF\u8C03\u7528\u3002\u65B0\u5EFA functions/<name>.ts \u540E\u81EA\u52A8\u70ED\u91CD\u8F7D\u3002");
8082
+ } else {
8083
+ log(`[adep] curl \u793A\u4F8B\uFF1Acurl ${baseUrl}${curlPath}`);
8084
+ }
7974
8085
  printBoundaries(log);
7975
8086
  if (simUser.resolver !== void 0) {
7976
8087
  log(
@@ -8008,6 +8119,7 @@ var init_dev = __esm({
8008
8119
  init_fetch_safe_port();
8009
8120
  init_port_in_use();
8010
8121
  init_env();
8122
+ init_config();
8011
8123
  init_fetch_config();
8012
8124
  init_invoke();
8013
8125
  init_builtin_deps2();
@@ -8497,7 +8609,7 @@ function renderBanner(options) {
8497
8609
  lines.push("");
8498
8610
  lines.push(" \u80FD\u529B:");
8499
8611
  if (functions.length > 0) {
8500
- const route = options.functionsPrefix === void 0 || options.functionsPrefix.length === 0 ? `${baseUrl}/api/{fn}` : `${baseUrl}/${options.functionsPrefix.replace(/^\/+|\/+$/g, "")}/{fn}`;
8612
+ const route = options.functionsPrefix === void 0 || options.functionsPrefix.length === 0 ? `${baseUrl}/api/{fn}` : `${baseUrl}/${normalizeFunctionsPrefix(options.functionsPrefix)}/{fn}`;
8501
8613
  lines.push(` - \u51FD\u6570\u8DEF\u7531: ${route}\uFF08${functions.length} \u4E2A\u51FD\u6570: ${functions.join(", ")}\uFF09`);
8502
8614
  } else {
8503
8615
  lines.push(" - \u51FD\u6570\u8DEF\u7531: \u65E0\uFF08functions/ \u76EE\u5F55\u4E3A\u7A7A\uFF09");
@@ -8580,6 +8692,7 @@ var init_banner = __esm({
8580
8692
  "packages/cli/src/serve/banner.ts"() {
8581
8693
  "use strict";
8582
8694
  init_dev_shared();
8695
+ init_config();
8583
8696
  }
8584
8697
  });
8585
8698
 
@@ -9150,7 +9263,7 @@ async function startServeServer(options) {
9150
9263
  );
9151
9264
  return;
9152
9265
  }
9153
- const normalizedPrefix = config2.functionsPrefix.replace(/^\/+|\/+$/g, "");
9266
+ const normalizedPrefix = normalizeFunctionsPrefix(config2.functionsPrefix);
9154
9267
  const fnRest = normalizedPrefix.length > 0 ? pathname === `/${normalizedPrefix}` || pathname.startsWith(`/${normalizedPrefix}/`) ? pathname.slice(normalizedPrefix.length + 1) : null : pathname === "/api" ? "" : pathname.startsWith("/api/") ? pathname.slice("/api/".length) : null;
9155
9268
  if (fnRest !== null) {
9156
9269
  const { fnName, error: routeError } = resolveRouteFnName(fnRest, "");
@@ -9349,6 +9462,7 @@ var init_server = __esm({
9349
9462
  init_worker_executor();
9350
9463
  init_signature();
9351
9464
  init_driver();
9465
+ init_config();
9352
9466
  init_builtin_deps2();
9353
9467
  init_runtime();
9354
9468
  init_storage();
@@ -10998,7 +11112,7 @@ var init_version = __esm({
10998
11112
  manifest = requireJson("../package.json");
10999
11113
  CLI_VERSION = typeof manifest.version === "string" && manifest.version.length > 0 ? manifest.version : "0.0.0";
11000
11114
  RELEASE_TASKS = Array.isArray(manifest.adep?.releaseTasks) ? manifest.adep.releaseTasks.filter((item) => typeof item === "string") : [];
11001
- BUILD_COMMIT = "d44d78c7".trim() !== "" ? "d44d78c7".trim() : null;
11115
+ BUILD_COMMIT = "08ca68b9".trim() !== "" ? "08ca68b9".trim() : null;
11002
11116
  }
11003
11117
  });
11004
11118
 
@@ -11919,8 +12033,8 @@ var GENERATED_TEMPLATES = {
11919
12033
  },
11920
12034
  "files": [
11921
12035
  {
11922
- "path": "README-EMPTY.md",
11923
- "content": "// AgentDeploy \u9879\u76EE\u5165\u53E3\u3002\u6A21\u677F\u6682\u65E0\u66F4\u591A\u5185\u5BB9\u2014\u2014\u51FD\u6570\u653E functions/\uFF0C\u524D\u7AEF\u653E web/src/\uFF0C\u914D\u7F6E\u89C1 adep.config.ts\u3002\n"
12036
+ "path": "README.md",
12037
+ "content": '# {{name}}\n\nAgentDeploy **\u7A7A\u6A21\u677F**\u9879\u76EE\u2014\u2014\u8FD9\u91CC\u53EA\u6709\u6700\u5C0F\u5DE5\u7A0B\u9AA8\u67B6\uFF1A\u6CA1\u6709 `functions/`\uFF08\u6CA1\u6709\u4E91\u51FD\u6570\uFF09\uFF0C\n\u4E5F\u6CA1\u6709\u524D\u7AEF\u5DE5\u7A0B\u3002\n\n## \u8FD9\u4E2A\u6A21\u677F\u91CC\u6709\u4EC0\u4E48\n\n- `package.json`\uFF1A\u5E94\u7528\u5B9A\u4E49\uFF08\u4EC5 `@adep/cli` \u4F9D\u8D56\uFF1B\u65E0\u524D\u7AEF\u4F9D\u8D56\uFF09\n- `adep.config.ts`\uFF1A\u9879\u76EE\u914D\u7F6E\uFF08name / template / functionsDir / functions_prefix\uFF0C\u9ED8\u8BA4 `/api`\uFF09\n- `tsconfig.json`\uFF1ATypeScript \u7F16\u8F91\u5668\u914D\u7F6E\uFF08strict + noEmit\uFF09\n- `adep.d.ts`\uFF1A\u4E91\u51FD\u6570\u4E0A\u4E0B\u6587\u73AF\u5883\u7C7B\u578B\u58F0\u660E\uFF08`ctx: AdepContext` \u8865\u5168\uFF0C\u65E0\u9700\u88C5\u4F9D\u8D56\uFF09\n\n## \u600E\u4E48\u7528\n\n\u8FD9\u662F**\u8D77\u70B9**\uFF0C\u4E0D\u662F\u6210\u54C1\u3002\u6309\u9700\u8981\u4E8C\u9009\u4E00\uFF1A\n\n- **\u53EA\u8981\u4E91\u51FD\u6570**\uFF1A`adep init <name> -t function` \u2014\u2014 \u5E26\u4E00\u4E2A\u793A\u4F8B\u51FD\u6570\uFF08`functions/hello.ts`\uFF09\u3002\n- **\u8981\u524D\u7AEF\uFF08Vue 3 + Vite\uFF09**\uFF1A`adep init <name> -t fullstack` \u2014\u2014 \u5E26 `web/src/` \u6E90\u7801\u3001\n `vite.config.ts`\u3001`index.html` \u4E0E `database/schema.sql`\u3002\n\n\u5728\u672C\u76EE\u5F55\u91CC\u624B\u5199\u4E5F\u53EF\u4EE5\uFF1A\u65B0\u5EFA `functions/<name>.ts`\uFF0C\u5BFC\u51FA\n`export default async (ctx: AdepContext) => Response`\u3002\n\n## \u5E38\u7528\u547D\u4EE4\n\n- `pnpm dev`\uFF08= `adep dev`\uFF09\uFF1A\u51FD\u6570\u4FA7\u6A21\u62DF\u8FD0\u884C\u65F6\u2014\u2014\u8FDB\u7A0B\u5185\u6267\u884C\u4E91\u51FD\u6570\uFF0C\u4E0D\u8FDE\u4E91\u7AEF\u3001\u4E0D\u88C5 Docker\uFF0C\n \u65AD\u7F51\u4E5F\u80FD\u5F00\u53D1\uFF1B\u81EA\u52A8\u88C5\u914D `cloud.db` / `cloud.storage` / `cloud.realtime`\uFF0C\u6587\u4EF6\u53D8\u66F4\u81EA\u52A8\u70ED\u91CD\u8F7D\u3002\n- `pnpm serve`\uFF08= `adep serve`\uFF09\uFF1A\u5F00\u53D1\u6001\u670D\u52A1\u5668\uFF08\u51FD\u6570 `/api/{prefix}/{fn}` + `/healthz` + \u9759\u6001\u6258\u7BA1\uFF09\n- `pnpm deploy`\uFF08= `adep publish --only functions`\uFF09\uFF1A\u589E\u91CF\u90E8\u7F72\u4E91\u51FD\u6570\uFF08\u5BF9\u6BD4\u8FDC\u7AEF\u54C8\u5E0C \u2192 \u4EC5\u4E0A\u4F20\u53D8\u66F4 \u2192 \u53D1\u5E03 \u2192 \u8F93\u51FA\u8BBF\u95EE\u57DF\u540D\uFF09\n- `pnpm doctor`\uFF08= `adep doctor`\uFF09\uFF1A\u672C\u5730\u73AF\u5883\u79BB\u7EBF\u8BCA\u65AD\n\n> \u672C\u6A21\u677F**\u6CA1\u6709** `build` / `site:deploy` \u811A\u672C\uFF1A\u6CA1\u6709\u524D\u7AEF\u5DE5\u7A0B\u5C31\u6CA1\u6709\u524D\u7AEF\u4EA7\u7269\u53EF\u6784\u5EFA\u3002\n\n## pnpm \u4E0E\u4F9D\u8D56\u6784\u5EFA\u811A\u672C\uFF08pnpm 10 \u8D77\u9ED8\u8BA4\u4E0D\u8DD1\uFF09\n\n\u9879\u76EE\u6839\u7684 `pnpm-workspace.yaml` \u5DF2\u653E\u884C `esbuild` \u7684\u6784\u5EFA\u811A\u672C\uFF08`onlyBuiltDependencies` \u4E0E\n`allowBuilds` \u53CC\u5199\uFF1Apnpm 10 \u8BFB\u524D\u8005\uFF0Cpnpm 11+ \u8BFB\u540E\u8005\uFF09\u3002pnpm 10 \u8D77**\u9ED8\u8BA4\u4E0D\u6267\u884C\u4F9D\u8D56\u7684\n\u6784\u5EFA\u811A\u672C**\uFF0C\u5220\u6389\u8FD9\u4EFD\u914D\u7F6E\u540E `pnpm install` \u4F1A\u4EE5 `ERR_PNPM_IGNORED_BUILDS` \u62A5\u9519\n\uFF08`@adep/cli` \u4F9D\u8D56 esbuild\uFF0C\u5176\u539F\u751F\u4E8C\u8FDB\u5236\u6CA1\u51C6\u5907\u597D\uFF0C\u6784\u5EFA\u53EF\u80FD\u5931\u8D25\uFF09\u3002\u4ECD\u7528 pnpm 9 \u65F6\u7B49\u4EF7\u5199\u6CD5\u662F\u5728\n`package.json` \u91CC\u5199 `"pnpm": { "onlyBuiltDependencies": ["esbuild"] }`\u3002\n'
11924
12038
  }
11925
12039
  ]
11926
12040
  },
@@ -12040,7 +12154,7 @@ var GENERATED_TEMPLATES = {
12040
12154
  },
12041
12155
  {
12042
12156
  "path": "functions/_shared/date.test.ts",
12043
- "content": "/**\n * \u670D\u52A1\u7AEF\u65E5\u671F/\u6392\u5E8F\u5355\u5143\u6D4B\u8BD5\uFF08\u79FB\u690D\u903B\u8F91\u7684\u56DE\u5F52\u4FDD\u62A4\uFF09\u3002\n * \u54CD\u5E94\u4FE1\u5C01\u7684\u6D4B\u8BD5\u5728\u5B98\u65B9\u5305 `@adep/runtime` \u4FA7\uFF08FN-029 \u8D77 ok/fail \u6536\u7F16\u8FDB\u5E73\u53F0\uFF09\u3002\n * \u8FD0\u884C\uFF1Anpm run test\n */\nimport { describe, it, expect } from 'vitest'\nimport { isValidDate, calcDays, toDTO, sortEvents } from './date'\nimport type { EventRow } from './store'\n\ndescribe('isValidDate', () => {\n it('\u63A5\u53D7\u5408\u6CD5 YYYY-MM-DD', () => {\n expect(isValidDate('2026-09-20')).toBe(true)\n expect(isValidDate('2024-02-29')).toBe(true)\n })\n it('\u62D2\u7EDD\u975E\u6CD5\u65E5\u671F\u4E0E\u683C\u5F0F', () => {\n expect(isValidDate('2026-13-01')).toBe(false)\n expect(isValidDate('2026-02-30')).toBe(false)\n expect(isValidDate('2026/09/20')).toBe(false)\n expect(isValidDate('')).toBe(false)\n expect(isValidDate(null)).toBe(false)\n })\n})\n\ndescribe('calcDays\uFF08\u5317\u4EAC\u65F6\u95F4\u81EA\u7136\u65E5\uFF09', () => {\n it('\u5012\u8BA1\u65F6\uFF1A\u672A\u6765\u4E3A\u6B63\uFF0C\u5F53\u5929\u4E3A 0', () => {\n const today = new Date()\n const beijing = new Date(today.getTime() + 8 * 3600_000)\n const todayStr = `${beijing.getUTCFullYear()}-${String(beijing.getUTCMonth() + 1).padStart(2, '0')}-${String(\n beijing.getUTCDate()\n ).padStart(2, '0')}`\n expect(calcDays(todayStr)).toBe(0)\n })\n it('\u8FC7\u53BB\u65E5\u671F\u4E3A\u8D1F\uFF1Bcountup \u53D6\u7EDD\u5BF9\u503C', () => {\n expect(calcDays('2020-01-01')).toBeLessThan(0)\n expect(calcDays('2020-01-01', 'countup')).toBeGreaterThan(0)\n })\n it('\u975E\u6CD5\u65E5\u671F\u8FD4\u56DE 0', () => {\n expect(calcDays('bad-date')).toBe(0)\n })\n})\n\ndescribe('toDTO + sortEvents', () => {\n const base = {\n id: '1',\n user_id: 'u1',\n title: '\u4E8B\u4EF6',\n target_date: '2030-01-01',\n note: null,\n category: null,\n direction: 'countdown',\n is_pinned: 0,\n sort_order: 0,\n created_at: '2026-01-01T00:00:00.000Z',\n updated_at: '2026-01-01T00:00:00.000Z',\n } as EventRow\n\n it('toDTO \u8865\u9ED8\u8BA4\u503C\u5E76\u7B97 days', () => {\n const dto = toDTO(base)\n expect(dto.note).toBe('')\n expect(dto.category).toBe('other')\n expect(dto.is_pinned).toBe(false)\n expect(dto.days).toBeGreaterThan(0)\n })\n\n it('\u6392\u5E8F\uFF1A\u7F6E\u9876\u4F18\u5148\uFF0C\u5176\u4F59\u6309\u5269\u4F59\u5929\u6570\u5347\u5E8F\uFF08\u8FC7\u53BB\u6392\u6700\u540E\uFF09', () => {\n const far = { ...base, id: 'far', target_date: '2031-01-01' } as EventRow\n const near = { ...base, id: 'near', target_date: '2026-10-01' } as EventRow\n const past = { ...base, id: 'past', target_date: '2020-01-01' } as EventRow\n const pinnedFar = { ...far, id: 'pinnedFar', is_pinned: 1 } as EventRow\n const sorted = sortEvents([far, near, past, pinnedFar].map((r) => toDTO(r)))\n expect(sorted.map((e) => e.id)).toEqual(['pinnedFar', 'near', 'far', 'past'])\n })\n})\n"
12157
+ "content": "/**\n * \u670D\u52A1\u7AEF\u65E5\u671F/\u6392\u5E8F\u5355\u5143\u6D4B\u8BD5\uFF08\u79FB\u690D\u903B\u8F91\u7684\u56DE\u5F52\u4FDD\u62A4\uFF09\u3002\n * \u54CD\u5E94\u4FE1\u5C01\u7684\u6D4B\u8BD5\u5728\u5B98\u65B9\u5305 `@adep/runtime` \u4FA7\uFF08FN-029 \u8D77 ok/fail \u6536\u7F16\u8FDB\u5E73\u53F0\uFF09\u3002\n * \u8FD0\u884C\uFF1Anpm run test\n */\nimport { describe, it, expect } from 'vitest'\nimport { isValidDate, calcDays, toDTO, sortEvents } from './date'\nimport type { EventRow } from './store'\n\n/** \u76F8\u5BF9\u951A\u9020 YYYY-MM-DD\uFF08+8h \u5BF9\u9F50\u672C\u6587\u4EF6\u300C\u5317\u4EAC\u81EA\u7136\u65E5\u300D\u53E3\u5F84\uFF09\uFF1A\u5199\u6B7B\u65E5\u5386\u65E5\u671F\u7684\u5939\u5177\u662F\u5B9A\u65F6\u70B8\u5F39\uFF082026-10-01 \u8FC7\u671F\u5373\u7EA2\u5B9E\u8BC1\uFF09\u3002 */\nfunction dateOffset(days: number): string {\n const d = new Date(Date.now() + days * 86_400_000 + 8 * 3600_000)\n return d.toISOString().slice(0, 10)\n}\n\ndescribe('isValidDate', () => {\n it('\u63A5\u53D7\u5408\u6CD5 YYYY-MM-DD', () => {\n expect(isValidDate('2026-09-20')).toBe(true)\n expect(isValidDate('2024-02-29')).toBe(true)\n })\n it('\u62D2\u7EDD\u975E\u6CD5\u65E5\u671F\u4E0E\u683C\u5F0F', () => {\n expect(isValidDate('2026-13-01')).toBe(false)\n expect(isValidDate('2026-02-30')).toBe(false)\n expect(isValidDate('2026/09/20')).toBe(false)\n expect(isValidDate('')).toBe(false)\n expect(isValidDate(null)).toBe(false)\n })\n})\n\ndescribe('calcDays\uFF08\u5317\u4EAC\u65F6\u95F4\u81EA\u7136\u65E5\uFF09', () => {\n it('\u5012\u8BA1\u65F6\uFF1A\u672A\u6765\u4E3A\u6B63\uFF0C\u5F53\u5929\u4E3A 0', () => {\n const today = new Date()\n const beijing = new Date(today.getTime() + 8 * 3600_000)\n const todayStr = `${beijing.getUTCFullYear()}-${String(beijing.getUTCMonth() + 1).padStart(2, '0')}-${String(\n beijing.getUTCDate()\n ).padStart(2, '0')}`\n expect(calcDays(todayStr)).toBe(0)\n })\n it('\u8FC7\u53BB\u65E5\u671F\u4E3A\u8D1F\uFF1Bcountup \u53D6\u7EDD\u5BF9\u503C', () => {\n expect(calcDays('2020-01-01')).toBeLessThan(0)\n expect(calcDays('2020-01-01', 'countup')).toBeGreaterThan(0)\n })\n it('\u975E\u6CD5\u65E5\u671F\u8FD4\u56DE 0', () => {\n expect(calcDays('bad-date')).toBe(0)\n })\n})\n\ndescribe('toDTO + sortEvents', () => {\n const base = {\n id: '1',\n user_id: 'u1',\n title: '\u4E8B\u4EF6',\n target_date: dateOffset(30),\n note: null,\n category: null,\n direction: 'countdown',\n is_pinned: 0,\n sort_order: 0,\n created_at: '2026-01-01T00:00:00.000Z',\n updated_at: '2026-01-01T00:00:00.000Z',\n } as EventRow\n\n it('toDTO \u8865\u9ED8\u8BA4\u503C\u5E76\u7B97 days', () => {\n const dto = toDTO(base)\n expect(dto.note).toBe('')\n expect(dto.category).toBe('other')\n expect(dto.is_pinned).toBe(false)\n expect(dto.days).toBeGreaterThan(0)\n })\n\n it('\u6392\u5E8F\uFF1A\u7F6E\u9876\u4F18\u5148\uFF0C\u5176\u4F59\u6309\u5269\u4F59\u5929\u6570\u5347\u5E8F\uFF08\u8FC7\u53BB\u6392\u6700\u540E\uFF09', () => {\n // \u5939\u5177\u65E5\u671F\u5FC5\u987B\u76F8\u5BF9\u951A\uFF1A\u5199\u6B7B\u65E5\u5386\u65E5\u671F\u662F\u5B9A\u65F6\u70B8\u5F39\uFF082026-10-01 \u8FC7\u671F\u5373\u7EA2\u5B9E\u8BC1\uFF0C398 \u6279\u540C\u6B3E\uFF09\u3002\n const far = { ...base, id: 'far', target_date: dateOffset(1460) } as EventRow\n const near = { ...base, id: 'near', target_date: dateOffset(7) } as EventRow\n const past = { ...base, id: 'past', target_date: dateOffset(-7) } as EventRow\n const pinnedFar = { ...far, id: 'pinnedFar', is_pinned: 1 } as EventRow\n const sorted = sortEvents([far, near, past, pinnedFar].map((r) => toDTO(r)))\n expect(sorted.map((e) => e.id)).toEqual(['pinnedFar', 'near', 'far', 'past'])\n })\n})\n"
12044
12158
  },
12045
12159
  {
12046
12160
  "path": "functions/_shared/date.ts",
@@ -14600,6 +14714,18 @@ interface AdepCloudDbTable {
14600
14714
  insert(row: Record<string, AdepSqlValue>): Promise<void>
14601
14715
  /** \u6279\u91CF\u63D2\u5165\u3002 */
14602
14716
  insertMany(rows: ReadonlyArray<Record<string, AdepSqlValue>>): Promise<void>
14717
+ /**
14718
+ * \u63D2\u5165\u6216\u66F4\u65B0\uFF08INSERT ... ON CONFLICT (target) DO UPDATE SET ...\uFF09\u3002
14719
+ * \u66FF\u4EE3\u300C\u5148\u67E5\u4E00\u904D\u3001\u6CA1\u6709\u5C31 insert\u3001\u6709\u5C31 update\u300D\u6A21\u677F\u2014\u2014\u90A3\u6761\u8DEF\u5728\u5E76\u53D1\u4E0B\u4E24\u4E2A\u8BF7\u6C42
14720
+ * \u90FD\u4F1A\u67E5\u5230\u300C\u6CA1\u6709\u300D\uFF0C\u7136\u540E\u53CC\u53CC insert\uFF0C\u649E\u552F\u4E00\u7EA6\u675F\u76F4\u63A5 500\uFF08\u590D\u5408\u4E3B\u952E\u8868\u5C24\u5176\u5E38\u89C1\uFF09\u3002
14721
+ *
14722
+ * target \u5FC5\u987B\u547D\u4E2D\u8868\u4E0A\u7684\u552F\u4E00\u7EA6\u675F\uFF08\u4E3B\u952E\u6216 UNIQUE \u7D22\u5F15\uFF09\uFF0C\u5426\u5219\u9A71\u52A8\u5C42\u62A5\u9519\u3002
14723
+ * \u51B2\u7A81\u65F6\u7684\u66F4\u65B0\u5217\u7531 options.update \u6307\u5B9A\uFF08\u503C\u53D6\u81EA row\uFF09\uFF0C\u7F3A\u7701 = row \u4E2D\u9664 target
14724
+ * \u5916\u7684\u5168\u90E8\u5217\uFF1B\u663E\u5F0F update: [] \u8868\u793A\u51B2\u7A81\u65F6\u4FDD\u6301\u65E7\u884C\u4E0D\u53D8\uFF08DO NOTHING\uFF09\u3002
14725
+ *
14726
+ * owned \u8868\u4E0D\u652F\u6301\uFF08\u53D8\u66F4\u6D41\u65E0\u6CD5\u8868\u8FBE insert/update \u4E8C\u4E49\uFF09\uFF0C\u629B DB_UNSAFE_OP\u3002
14727
+ */
14728
+ upsert(row: Record<string, AdepSqlValue>, options: UpsertOptions): Promise<void>
14603
14729
  /** \u66F4\u65B0\uFF08\u5FC5\u987B\u5148 where\uFF0C\u5426\u5219 DB_UNSAFE_OP\uFF09\uFF1B\u8FD4\u56DE\u53D7\u5F71\u54CD\u884C\u6570\u3002 */
14604
14730
  update(values: Record<string, AdepSqlValue>): Promise<number>
14605
14731
  /** \u5220\u9664\uFF08\u5FC5\u987B\u5148 where\uFF0C\u5426\u5219 DB_UNSAFE_OP\uFF09\uFF1B\u8FD4\u56DE\u53D7\u5F71\u54CD\u884C\u6570\u3002 */
@@ -15001,30 +15127,41 @@ var ADEP_CONFIG_HEADER = `// adep \u9879\u76EE\u914D\u7F6E\uFF1ACLI\uFF08dev / s
15001
15127
  // dev / serve / \u5E73\u53F0\u8BBF\u95EE\u8DEF\u5F84\u4E00\u81F4\u4E3A /{prefix}/{fnName}\uFF08\u5982 /api/hello\uFF09\u3002
15002
15128
  // vite \u63D2\u4EF6\uFF08vite.config.ts \u7684 adepPlugin()\uFF09\u6309\u6B64\u524D\u7F00\u628A\u524D\u7AEF /{prefix}/* \u8BF7\u6C42\u4EE3\u7406\u5230\u4E91\u51FD\u6570\u3002
15003
15129
  // \u8FB9\u754C\uFF1A\u53EA\u5F71\u54CD\u672C\u5730 HTTP \u5165\u53E3\u8DEF\u7531\uFF1B\u51FD\u6570\u4E92\u8C03\uFF08ctx.cloud.invoke\uFF09\u4E0E\u7EBF\u4E0A\u90E8\u7F72\u8DEF\u5F84\u6309\u51FD\u6570\u540D\uFF0C\u4E0D\u53D7\u5F71\u54CD\u3002`;
15004
- var PACKAGE_JSON = (name, template, cliVersion) => {
15130
+ var PACKAGE_JSON = (ctx) => {
15131
+ const { name, template, cliVersion, hasFrontend } = ctx;
15132
+ const scripts = hasFrontend ? {
15133
+ dev: "vite",
15134
+ build: "vite build",
15135
+ "site:deploy": "adep hosting deploy site --spa",
15136
+ serve: "adep serve",
15137
+ // 容器内启动入口(Dockerfile 的 CMD 只有 `bun run start`):静态目录 / 端口口径
15138
+ // 只在这一个地方定档——Dockerfile 与 package.json 各写一套必然漂移(2026-10-08 收敛)。
15139
+ // fullstack 的前端产物在 site/(vite build);function / empty 无前端产物,故不指目录。
15140
+ start: template === "fullstack" ? "adep serve --host 0.0.0.0 --static site" : "adep serve --host 0.0.0.0",
15141
+ deploy: "adep publish --only functions",
15142
+ doctor: "adep doctor"
15143
+ } : {
15144
+ // 无前端模板:dev 走**函数侧**模拟运行时(进程内、不连云端、不装 Docker)。
15145
+ // 不能写 vite——没有 vite 工程根,启动后只会白屏一个空页。
15146
+ dev: "adep dev",
15147
+ serve: "adep serve",
15148
+ start: "adep serve --host 0.0.0.0",
15149
+ deploy: "adep publish --only functions",
15150
+ doctor: "adep doctor"
15151
+ };
15005
15152
  const pkg = {
15006
15153
  name,
15007
15154
  version: "0.1.0",
15008
15155
  private: true,
15009
15156
  type: "module",
15010
- description: `AgentDeploy \u5168\u6808\u9879\u76EE\uFF08\u6A21\u677F\uFF1A${template}\uFF09\u2014\u2014functions/ \u4E91\u51FD\u6570 + web/src/ \u524D\u7AEF\u6E90\u7801 + site/ \u524D\u7AEF\u6784\u5EFA\u4EA7\u7269`,
15011
- scripts: {
15012
- dev: "vite",
15013
- build: "vite build",
15014
- "site:deploy": "adep hosting deploy site --spa",
15015
- serve: "adep serve",
15016
- // 容器内启动入口(Dockerfile 的 CMD 只有 `bun run start`):静态目录 / 端口口径
15017
- // 只在这一个地方定档——Dockerfile 与 package.json 各写一套必然漂移(2026-10-08 收敛)。
15018
- // fullstack 的前端产物在 site/(vite build);function / empty 无前端产物,故不指目录。
15019
- start: template === "fullstack" ? "adep serve --host 0.0.0.0 --static site" : "adep serve --host 0.0.0.0",
15020
- deploy: "adep publish --only functions",
15021
- doctor: "adep doctor"
15022
- },
15157
+ description: hasFrontend ? `AgentDeploy \u5168\u6808\u9879\u76EE\uFF08\u6A21\u677F\uFF1A${template}\uFF09\u2014\u2014functions/ \u4E91\u51FD\u6570 + web/src/ \u524D\u7AEF\u6E90\u7801 + site/ \u524D\u7AEF\u6784\u5EFA\u4EA7\u7269` : template === "empty" ? "AgentDeploy \u7A7A\u6A21\u677F\u9879\u76EE\u2014\u2014\u4EC5\u9879\u76EE\u9AA8\u67B6\uFF08\u65E0 functions/\u3001\u65E0\u524D\u7AEF\u5DE5\u7A0B\uFF09" : `AgentDeploy \u4E91\u51FD\u6570\u9879\u76EE\uFF08\u6A21\u677F\uFF1A${template}\uFF09\u2014\u2014functions/ \u4E91\u51FD\u6570\uFF08\u65E0\u524D\u7AEF\u5DE5\u7A0B\uFF09`,
15158
+ scripts,
15023
15159
  dependencies: {
15024
15160
  "@adep/cli": cliVersion,
15025
- ...WEB_DEPENDENCIES
15161
+ // 前端依赖只在有前端工程时才声明(vue / @adep/client 运行时不需要)。
15162
+ ...hasFrontend ? WEB_DEPENDENCIES : {}
15026
15163
  },
15027
- devDependencies: WEB_DEV_DEPENDENCIES,
15164
+ devDependencies: hasFrontend ? WEB_DEV_DEPENDENCIES : {},
15028
15165
  engines: {
15029
15166
  node: ">=18",
15030
15167
  bun: ">=1.0"
@@ -15066,7 +15203,7 @@ var COUNTDOWN_PACKAGE_JSON = (name, cliVersion) => {
15066
15203
  "@adep/runtime": "^0.3.0",
15067
15204
  "@vitejs/plugin-vue": "^6.0.0",
15068
15205
  "esbuild-wasm": "^0.25.12",
15069
- typescript: "5.9.3",
15206
+ typescript: "6.0.3",
15070
15207
  vite: "^7.0.0",
15071
15208
  // vitest 用 ^3.2.4:vitest 4.x 的 packument 触发 npm 10.9 arborist edgesOut 崩溃(官方源同样),
15072
15209
  // 与 countdown 模板保持一致。
@@ -15195,7 +15332,7 @@ var DOCKER_ASSETS = (name) => [
15195
15332
  { path: ".dockerignore", content: DOCKERIGNORE },
15196
15333
  { path: ".env.example", content: ENV_EXAMPLE }
15197
15334
  ];
15198
- var README = (name, template) => `# ${name}
15335
+ var README_FULLSTACK = (name, template) => `# ${name}
15199
15336
 
15200
15337
  AgentDeploy \u5168\u6808\u9879\u76EE\uFF08\u6A21\u677F\uFF1A${template}\uFF09\u3002
15201
15338
 
@@ -15306,6 +15443,66 @@ console.log(result.message)
15306
15443
  \`web/src/\` \u5B58\u653E\u524D\u7AEF\u6E90\u7801\uFF08\`main.ts\` / \`App.vue\`\uFF09\uFF0C\u4E0E Web IDE \u5185 \`web/\` \u5DE5\u7A0B\u7684 \`src/\`
15307
15444
  \u5B8C\u5168\u540C\u6784\uFF1Bvite \u5DE5\u7A0B\u6839\u5728\u9879\u76EE\u6839\u76EE\u5F55\uFF08\`vite.config.ts\` / \`index.html\` / \`package.json\`\uFF09\u3002
15308
15445
  `;
15446
+ var README_FUNCTION_ONLY = (name, template) => `# ${name}
15447
+
15448
+ ${template === "empty" ? "AgentDeploy \u7A7A\u6A21\u677F\u9879\u76EE\u2014\u2014**\u4EC5\u9879\u76EE\u9AA8\u67B6**\uFF1A\u6CA1\u6709 functions/ \u76EE\u5F55\uFF0C\u4E5F\u6CA1\u6709\u524D\u7AEF\u5DE5\u7A0B\u3002" : "AgentDeploy \u4E91\u51FD\u6570\u9879\u76EE\uFF08\u6A21\u677F\uFF1A" + template + "\uFF09\u2014\u2014**\u53EA\u6709 functions/ \u4E91\u51FD\u6570\uFF0C\u6CA1\u6709\u524D\u7AEF\u5DE5\u7A0B**\u3002"}
15449
+
15450
+ ## \u5E38\u7528\u547D\u4EE4
15451
+
15452
+ - \`pnpm dev\`\uFF08= \`adep dev\`\uFF09\uFF1A**\u51FD\u6570\u4FA7**\u6A21\u62DF\u8FD0\u884C\u65F6\u2014\u2014\u8FDB\u7A0B\u5185\u6267\u884C\u4E91\u51FD\u6570\uFF0C\u4E0D\u8FDE\u4E91\u7AEF\u3001\u4E0D\u88C5 Docker\uFF0C
15453
+ \u65AD\u7F51\u4E5F\u80FD\u5F00\u53D1\uFF1B\u81EA\u52A8\u88C5\u914D \`cloud.db\` / \`cloud.storage\` / \`cloud.realtime\`\uFF0C\u6587\u4EF6\u53D8\u66F4\u81EA\u52A8\u70ED\u91CD\u8F7D\u3002
15454
+ \u542F\u52A8\u6A2A\u5E45\u4F1A\u6253\u5370\u4E00\u6761**\u53EF\u76F4\u63A5\u590D\u5236**\u7684 curl \u547D\u4EE4\uFF08\u5F62\u5982 \`curl http://127.0.0.1:8787/api/hello\`\uFF09\uFF0C
15455
+ \u7AEF\u53E3\u88AB\u5360\u7528\u4F1A\u81EA\u52A8\u987A\u5EF6\uFF0C\u4EE5\u6A2A\u5E45\u5B9E\u9645\u6253\u5370\u7684\u4E3A\u51C6\u3002
15456
+ - \`pnpm serve\`\uFF08= \`adep serve\`\uFF09\uFF1A\u5F00\u53D1\u6001\u670D\u52A1\u5668\uFF08\u51FD\u6570 \`/api/{prefix}/{fn}\` + \`/healthz\` + \u9759\u6001\u6258\u7BA1\uFF09
15457
+ - \`pnpm deploy\`\uFF08= \`adep publish --only functions\`\uFF09\uFF1A\u589E\u91CF\u90E8\u7F72\u4E91\u51FD\u6570\uFF08\u5BF9\u6BD4\u8FDC\u7AEF\u54C8\u5E0C \u2192 \u4EC5\u4E0A\u4F20\u53D8\u66F4 \u2192 \u53D1\u5E03 \u2192 \u8F93\u51FA\u8BBF\u95EE\u57DF\u540D\uFF09
15458
+ - \`pnpm doctor\`\uFF08= \`adep doctor\`\uFF09\uFF1A\u672C\u5730\u73AF\u5883\u79BB\u7EBF\u8BCA\u65AD
15459
+
15460
+ > \u672C\u6A21\u677F**\u6CA1\u6709** \`build\` / \`site:deploy\` \u811A\u672C\uFF1A\u6CA1\u6709\u524D\u7AEF\u5DE5\u7A0B\u5C31\u6CA1\u6709\u524D\u7AEF\u4EA7\u7269\u53EF\u6784\u5EFA\u3002
15461
+ > \u9700\u8981\u524D\u7AEF\uFF08Vue 3 + Vite\uFF09\u8BF7\u6539\u7528 \`adep init <name> -t fullstack\`\u3002
15462
+
15463
+ ## pnpm \u4E0E\u4F9D\u8D56\u6784\u5EFA\u811A\u672C\uFF08pnpm 10 \u8D77\u9ED8\u8BA4\u4E0D\u8DD1\uFF09
15464
+
15465
+ \u9879\u76EE\u6839\u7684 \`pnpm-workspace.yaml\` \u5DF2\u653E\u884C \`esbuild\` \u7684\u6784\u5EFA\u811A\u672C\uFF08\`onlyBuiltDependencies\` \u4E0E
15466
+ \`allowBuilds\` \u53CC\u5199\uFF1Apnpm 10 \u8BFB\u524D\u8005\uFF0Cpnpm 11+ \u8BFB\u540E\u8005\uFF09\u3002pnpm 10 \u8D77**\u9ED8\u8BA4\u4E0D\u6267\u884C\u4F9D\u8D56\u7684
15467
+ \u6784\u5EFA\u811A\u672C**\uFF0C\u5220\u6389\u8FD9\u4EFD\u914D\u7F6E\u540E \`pnpm install\` \u4F1A\u4EE5 \`ERR_PNPM_IGNORED_BUILDS\` \u62A5\u9519
15468
+ \uFF08\`@adep/cli\` \u4F9D\u8D56 esbuild\uFF0C\u5176\u539F\u751F\u4E8C\u8FDB\u5236\u6CA1\u51C6\u5907\u597D\uFF0C\u6784\u5EFA\u53EF\u80FD\u5931\u8D25\uFF09\u3002\u4ECD\u7528 pnpm 9 \u65F6\u7B49\u4EF7\u5199\u6CD5\u662F\u5728
15469
+ \`package.json\` \u91CC\u5199 \`"pnpm": { "onlyBuiltDependencies": ["esbuild"] }\`\u3002
15470
+
15471
+ ${DOCKER_README_SECTION()}
15472
+
15473
+ ## \u76EE\u5F55\u7ED3\u6784
15474
+
15475
+ - \`package.json\`\uFF1A\u5E94\u7528\u5B9A\u4E49\uFF08\u4EC5 \`@adep/cli\` \u4F9D\u8D56\uFF1B**\u65E0\u524D\u7AEF\u4F9D\u8D56**\uFF09
15476
+ - \`adep.config.ts\`\uFF1A\u9879\u76EE\u914D\u7F6E\uFF08name / template / functionsDir / functions_prefix\uFF0C\u9ED8\u8BA4 /api\uFF09
15477
+ - \`functions/\`\uFF1A\u4E91\u51FD\u6570\u76EE\u5F55\u2014\u2014\`functions/<name>.ts\` \u4E0E \`functions/<name>/index.ts\`
15478
+ \u662F\u540C\u4E00\u4E2A\u51FD\u6570\u7684\u4E24\u79CD**\u7B49\u4EF7**\u5199\u6CD5\uFF08\u540E\u8005\u4E3A\u76EE\u5F55\u5F62\u6001\uFF0C\u5165\u53E3\u56FA\u5B9A \`index.ts\`\uFF0C\u76EE\u5F55\u5185\u5176\u4F59\u6587\u4EF6\u662F\u8BE5
15479
+ \u51FD\u6570\u7684\u79C1\u6709\u6587\u4EF6\uFF09\uFF1B\u9ED8\u8BA4\u5BFC\u51FA \`(ctx: AdepContext) => Response\`\u3002\`functions/_shared/**\` \u662F
15480
+ \u9879\u76EE\u7EA7\u5171\u4EAB\u6E90\u7801\uFF08\u4FDD\u7559\u5B57\uFF0C\u5168\u9879\u76EE\u5355\u4EFD\uFF0C\u4E0D\u5C5E\u4E8E\u4EFB\u4F55\u51FD\u6570\uFF09\u3002\u8BE6\u89C1 \`functions/README.md\`
15481
+ - \`tsconfig.json\`\uFF1ATypeScript \u7F16\u8F91\u5668\u914D\u7F6E\uFF08strict + noEmit\uFF09
15482
+ - \`adep.d.ts\`\uFF1A\u4E91\u51FD\u6570\u4E0A\u4E0B\u6587\u73AF\u5883\u7C7B\u578B\u58F0\u660E\uFF08\`ctx: AdepContext\` \u8865\u5168\uFF0C\u65E0\u9700\u88C5\u4F9D\u8D56\uFF09
15483
+
15484
+ ## \u4E91\u51FD\u6570\u8DEF\u7531\u524D\u7F00\uFF08functions_prefix\uFF09
15485
+
15486
+ \`adep.config.ts\` \u7684 \`functions_prefix\`\uFF08\u9ED8\u8BA4 \`/api\`\uFF09\uFF1A
15487
+ - \`adep dev\`\uFF1A\`/{prefix}/{fn}\`\uFF0C\u5982 \`/api/hello\`\u3002
15488
+ - \`adep serve\`\uFF1A\`/api/{prefix}/{fn}\`\uFF08\u524D\u7F00\u62FC\u63A5\uFF09\u3002
15489
+ - **\u8FB9\u754C**\uFF1A\u53EA\u5F71\u54CD\u672C\u5730 HTTP \u5165\u53E3\uFF1B\u51FD\u6570\u4E92\u8C03 \`ctx.cloud.invoke('name')\` \u4E0E\u7EBF\u4E0A\u90E8\u7F72\u8DEF\u5F84\u6309\u51FD\u6570\u540D\uFF0C
15490
+ \u4E0D\u968F\u524D\u7F00\u53D8\u5316\uFF08\u4E0E\u7EBF\u4E0A\u540C\u6784\uFF09\u3002
15491
+
15492
+ ## \u4E91\u51FD\u6570\u7C7B\u578B\u63D0\u793A
15493
+
15494
+ \u7528 VSCode \u6253\u5F00\u672C\u76EE\u5F55\uFF0C\u4EFB\u610F \`functions/**\` \u4E0B\u7684 TS \u6587\u4EF6\u5373\u53EF\u83B7\u5F97 \`AdepContext\` / \`ctx.cloud.*\` \u8865\u5168\uFF1A
15495
+ \`tsconfig.json\` \u4F1A\u628A \`adep.d.ts\` \u7EB3\u5165 include\uFF0C\u51FD\u6570\u53C2\u6570\u5199 \`ctx: AdepContext\` \u5373\u53EF\u3002
15496
+ \`ctx\` \u4E0E \`AdepContext\` \u662F\u5168\u5C40\u5F00\u53D1\u671F\u58F0\u660E\uFF0C\u51FD\u6570\u8FD0\u884C\u671F\u7ECF\u53C2\u6570\u6CE8\u5165\uFF08\u4E0D\u8BFB\u53D6\u5168\u5C40\uFF09\u3002
15497
+
15498
+ ## \u6A21\u677F\u8BF4\u660E\uFF08adep init\uFF09
15499
+
15500
+ - \`adep init <name>\`\uFF1A\u9ED8\u8BA4 \`fullstack\` \u6A21\u677F\uFF08functions/ + web/src/ \u524D\u7AEF\u6E90\u7801 + database/\uFF09
15501
+ - \`adep init <name> -t function\`\uFF1A\u4EC5\u4E91\u51FD\u6570\uFF08\u5355\u4E2A\u793A\u4F8B\u51FD\u6570\uFF09\u2014\u2014**\u672C\u6A21\u677F**
15502
+ - \`adep init <name> -t empty\`\uFF1A\u7A7A\u6A21\u677F\uFF08\u4EC5\u9879\u76EE\u9AA8\u67B6\uFF09
15503
+ - \`adep init --list\`\uFF1A\u4ECE\u5E73\u53F0 /api/v1/templates \u5217\u51FA\u53EF\u7528\u6A21\u677F
15504
+ - \`adep init --list -s <server>\`\uFF1A\u6307\u5B9A\u5E73\u53F0\u5730\u5740
15505
+ `;
15309
15506
  var FUNCTION_INDEX = `// \u51FD\u6570\u6A21\u5757\u5165\u53E3\uFF1A\u9879\u76EE\u91CC\u7684\u6BCF\u4E2A\u51FD\u6570\u662F functions/ \u4E0B\u7684\u72EC\u7ACB\u6A21\u5757\uFF0C
15310
15507
  // \u9ED8\u8BA4\u5BFC\u51FA (ctx: AdepContext) => Response \u5F62\u72B6\u7684\u5904\u7406\u5668\uFF08\u5951\u7EA6\u89C1 adep.d.ts\uFF09\u3002
15311
15508
  //
@@ -15377,10 +15574,17 @@ var SHARED_ASSETS = {
15377
15574
  packageJson: (ctx) => [
15378
15575
  {
15379
15576
  path: "package.json",
15380
- content: ctx.template === "countdown" ? COUNTDOWN_PACKAGE_JSON(ctx.name, ctx.cliVersion) : PACKAGE_JSON(ctx.name, ctx.template, ctx.cliVersion)
15577
+ content: ctx.template === "countdown" ? COUNTDOWN_PACKAGE_JSON(ctx.name, ctx.cliVersion) : PACKAGE_JSON(ctx)
15578
+ }
15579
+ ],
15580
+ readme: (ctx) => [
15581
+ {
15582
+ path: "README.md",
15583
+ // README 的口径必须与 package.json 的 scripts 一致(两份不许各说一套):
15584
+ // 无前端模板给函数侧版本,否则会写出跑不通的 vite 命令与不存在的目录。
15585
+ content: ctx.hasFrontend ? README_FULLSTACK(ctx.name, ctx.template) : README_FUNCTION_ONLY(ctx.name, ctx.template)
15381
15586
  }
15382
15587
  ],
15383
- readme: (ctx) => [{ path: "README.md", content: README(ctx.name, ctx.template) }],
15384
15588
  adepConfig: (ctx) => [
15385
15589
  {
15386
15590
  path: "adep.config.ts",
@@ -15505,6 +15709,10 @@ function cliPackageRoot() {
15505
15709
  function localTemplateDir(code) {
15506
15710
  return join2(cliPackageRoot(), "src", "templates", code);
15507
15711
  }
15712
+ var FRONTEND_ASSETS = /* @__PURE__ */ new Set(["webSrc", "viteConfig", "indexHtml"]);
15713
+ function hasFrontendAssets(sharedAssets) {
15714
+ return (sharedAssets ?? []).some((asset) => FRONTEND_ASSETS.has(asset));
15715
+ }
15508
15716
  function templateFiles(code, name) {
15509
15717
  const generated = GENERATED_TEMPLATES[code];
15510
15718
  if (generated === void 0) {
@@ -15518,7 +15726,12 @@ function renderTemplatePackage(pkg, name) {
15518
15726
  const vars = { name, template: pkg.code };
15519
15727
  const dirFiles = renderTemplateFiles(pkg.files, vars, manifest2);
15520
15728
  const code = pkg.code;
15521
- const ctx = { name, template: code, cliVersion: cliVersionOf() };
15729
+ const ctx = {
15730
+ name,
15731
+ template: code,
15732
+ cliVersion: cliVersionOf(),
15733
+ hasFrontend: hasFrontendAssets(manifest2.sharedAssets)
15734
+ };
15522
15735
  const sharedFiles = (manifest2.sharedAssets ?? []).flatMap((assetName) => {
15523
15736
  const asset = SHARED_ASSETS[assetName];
15524
15737
  if (asset === void 0) {
package/dist/vite.js CHANGED
@@ -375,7 +375,9 @@ var WorkerFunctionExecutor = class {
375
375
  ...input.env === void 0 ? {} : { env: input.env },
376
376
  ...deps === void 0 ? {} : { deps },
377
377
  ...this.parity ? { parity: true } : {},
378
- ...effectiveFetchConfig === void 0 ? {} : { fetch: effectiveFetchConfig }
378
+ ...effectiveFetchConfig === void 0 ? {} : { fetch: effectiveFetchConfig },
379
+ // W2:预编译提示随 workerData 下发(结构化克隆可跨线程;缺省不传 = 全量编译路径)。
380
+ ...input.compileHints === void 0 ? {} : { compileHints: input.compileHints }
379
381
  },
380
382
  resourceLimits: { maxOldGenerationSizeMb: memoryLimitMb }
381
383
  });
@@ -469,14 +471,14 @@ var sqliteDialect = {
469
471
  placeholder: () => "?",
470
472
  quote: (identifier) => `"${identifier.replace(/"/g, '""')}"`,
471
473
  lastInsertIdClause: () => "",
472
- upsertConflictClause: (columns) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")}) DO NOTHING`
474
+ upsertConflictClause: (columns, doUpdateSet) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")})` + (doUpdateSet ? ` DO UPDATE SET ${doUpdateSet}` : " DO NOTHING")
473
475
  };
474
476
  var postgresDialect = {
475
477
  name: "postgres",
476
478
  placeholder: (index) => `$${index + 1}`,
477
479
  quote: (identifier) => `"${identifier.replace(/"/g, '""')}"`,
478
480
  lastInsertIdClause: () => " RETURNING id",
479
- upsertConflictClause: (columns) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")}) DO NOTHING`
481
+ upsertConflictClause: (columns, doUpdateSet) => ` ON CONFLICT (${columns.map((column) => `"${column.replace(/"/g, '""')}"`).join(", ")})` + (doUpdateSet ? ` DO UPDATE SET ${doUpdateSet}` : " DO NOTHING")
480
482
  };
481
483
  function dialectFor(driver) {
482
484
  return driver.engine === "pg" ? postgresDialect : sqliteDialect;
@@ -803,6 +805,9 @@ function compileWhere(wheres, dialect, params) {
803
805
  if (value === null) {
804
806
  if (where.operator === "=") return `${quoted} IS NULL`;
805
807
  if (where.operator === "!=") return `${quoted} IS NOT NULL`;
808
+ throw unsafeOperation(
809
+ `NULL \u53EA\u80FD\u4E0E = / != \u6BD4\u8F83\uFF08${where.operator} NULL \u6052\u4E3A UNKNOWN\uFF0C\u4F1A\u9759\u9ED8\u8FD4\u56DE\u7A7A\u96C6\uFF09\uFF1A\u5217 ${where.column}`
810
+ );
806
811
  }
807
812
  const mark = pushParam(params, dialect, value);
808
813
  return `${quoted} ${where.operator} ${mark}`;
@@ -877,6 +882,44 @@ function compileInsertMany(table, rows, dialect) {
877
882
  params
878
883
  };
879
884
  }
885
+ function resolveUpsertPlan(row, options) {
886
+ const target = [...options.target];
887
+ if (target.length === 0) {
888
+ throw unsafeOperation("upsert \u7684 target \u5FC5\u987B\u81F3\u5C11\u4E00\u5217\uFF08\u51B2\u7A81\u5224\u5B9A\u65E0\u5217\u5219\u65E0\u4ECE\u8C08\u8D77\uFF09");
889
+ }
890
+ target.forEach(assertUserColumn);
891
+ const targetSet = new Set(target);
892
+ const rowColumns = new Set(Object.keys(row));
893
+ if (rowColumns.size === 0) {
894
+ throw unsafeOperation("upsert \u81F3\u5C11\u9700\u8981\u4E00\u4E2A\u5B57\u6BB5");
895
+ }
896
+ const update = options.update === void 0 ? [...rowColumns].filter((name) => !targetSet.has(name)) : [...options.update];
897
+ update.forEach(assertUserColumn);
898
+ const overlapping = update.filter((name) => targetSet.has(name));
899
+ if (overlapping.length > 0) {
900
+ throw unsafeOperation(`upsert \u7684 update \u5217\u4E0D\u80FD\u4E0E target \u91CD\u53E0\uFF08\u51B2\u7A81\u884C\u4E3B\u952E\u4E0D\u6539\uFF09\uFF1A${overlapping.join(", ")}`);
901
+ }
902
+ const missing = update.filter((name) => !rowColumns.has(name));
903
+ if (missing.length > 0) {
904
+ throw unsafeOperation(`upsert \u7684 update \u5217\u5FC5\u987B\u51FA\u73B0\u5728 row \u4E2D\uFF08\u503C\u53D6\u81EA row\uFF09\uFF1A${missing.join(", ")}`);
905
+ }
906
+ return { target, update };
907
+ }
908
+ function compileUpsert(table, row, options, dialect) {
909
+ const { target, update } = resolveUpsertPlan(row, options);
910
+ const params = [];
911
+ const entries = Object.entries(row);
912
+ const columns = entries.map(([name]) => {
913
+ assertUserColumn(name);
914
+ return dialect.quote(name);
915
+ }).join(", ");
916
+ const marks = entries.map(([, value]) => pushParam(params, dialect, value));
917
+ const doUpdateSet = update.length === 0 ? null : update.map((name) => `${dialect.quote(name)} = ${pushParam(params, dialect, row[name])}`).join(", ");
918
+ return {
919
+ sql: `INSERT INTO ${dialect.quote(table)} (${columns}) VALUES (${marks.join(", ")})${dialect.upsertConflictClause(target, doUpdateSet)}`,
920
+ params
921
+ };
922
+ }
880
923
  function compileUpdate(table, wheres, values, dialect) {
881
924
  const entries = Object.entries(values);
882
925
  if (entries.length === 0) {
@@ -1017,6 +1060,17 @@ function createTableBuilder(table, driver, dialect, options = {}) {
1017
1060
  const compiled = compileInsertMany(state.table, rows, dialect);
1018
1061
  await driver.run(compiled.sql, compiled.params);
1019
1062
  },
1063
+ async upsert(row, conflict) {
1064
+ guardWrite();
1065
+ Object.keys(row).forEach(assertUserColumn);
1066
+ if (await resolveOwned(state, driver)) {
1067
+ throw unsafeOperation(
1068
+ "upsert \u4E0D\u652F\u6301 owned \u8868\uFF1A\u53D8\u66F4\u6D41\u65E0\u6CD5\u8868\u8FBE\u300C\u63D2\u5165\u8FD8\u662F\u66F4\u65B0\u300D\u7684\u4E8C\u4E49\uFF08before/after \u987B\u786E\u5B9A\uFF09\uFF0C\u8BF7\u6539\u7528 insert / update"
1069
+ );
1070
+ }
1071
+ const compiled = compileUpsert(state.table, row, conflict, dialect);
1072
+ await driver.run(compiled.sql, compiled.params);
1073
+ },
1020
1074
  async update(values) {
1021
1075
  guardWrite();
1022
1076
  assertHasWhere(state);
@@ -1155,13 +1209,23 @@ function createCloudDb(driver, options = {}) {
1155
1209
  var CLOUD_DB_SPEC = {
1156
1210
  kind: "cloud-db",
1157
1211
  rootMethod: "table",
1158
- stepMethods: ["select", "where", "orderBy", "limit", "offset"],
1159
- terminalMethods: ["get", "first", "count", "insert", "insertMany", "update", "delete"],
1212
+ // 规格清单必须与构建器公开方法面一致(防漂移门 spec-drift.test.ts 双向咬合):
1213
+ // - owned:DB-006 的 owned 声明(step);
1214
+ // - execute:BUG-4 统一执行入口(direct,宿主侧 DB_RPC.execute 分支早已在);
1215
+ // - upsert:DB-010 终端(漏登记过一次,真机 500,见 spec-drift.test.ts 头注释)。
1216
+ stepMethods: ["select", "where", "orderBy", "limit", "offset", "owned"],
1217
+ terminalMethods: ["get", "first", "count", "insert", "insertMany", "update", "delete", "upsert"],
1160
1218
  // CF-013:writeQuery 是 D1 shim 的写路径(INSERT/UPDATE/DELETE),与 query 并列直通方法。
1161
- directMethods: ["query", "writeQuery", "changes"],
1219
+ directMethods: ["query", "writeQuery", "execute", "changes"],
1162
1220
  transactionMethod: "transaction"
1163
1221
  };
1164
- var WRITE_TERMINALS = /* @__PURE__ */ new Set(["insert", "insertMany", "update", "delete"]);
1222
+ var WRITE_TERMINALS = /* @__PURE__ */ new Set([
1223
+ "insert",
1224
+ "insertMany",
1225
+ "update",
1226
+ "delete",
1227
+ "upsert"
1228
+ ]);
1165
1229
  function errorWithCode(error) {
1166
1230
  if (error instanceof Error) {
1167
1231
  const sqlite = /no such table: (\S+)/.exec(error.message);
@@ -3839,6 +3903,11 @@ async function loadSimEnv(cwd, config = {}) {
3839
3903
  return merged;
3840
3904
  }
3841
3905
 
3906
+ // packages/cli/src/config.ts
3907
+ function normalizeFunctionsPrefix(prefix) {
3908
+ return prefix.replace(/^\/+|\/+$/g, "");
3909
+ }
3910
+
3842
3911
  // packages/cli/src/sim/fetch-config.ts
3843
3912
  var LOCAL_FETCH_TIMEOUT_MS_DEFAULT = 1e4;
3844
3913
  function resolveLocalFetchConfig(simEnv) {
@@ -4336,13 +4405,32 @@ var StateObjectRuntime = class {
4336
4405
  }
4337
4406
  /**
4338
4407
  * alarm 轮询:把到期对象唤醒并调 onAlarm(CF-037)。
4408
+ * - 到期集合 = 后端落库到期记录 ∪ **驻留实例的内存 alarmAt(驻留时以内存值为准)**:
4409
+ * `setAlarm`/`clearAlarm` 只写内存、`alarmAt` 随 `flush()` 落库——若 pump 只读后端,
4410
+ * 「setAlarm 后没 flush」会静默丢调度(rift-brawl 实锤:先 flush 再 setAlarm,闹钟永不触发),
4411
+ * 反向「clearAlarm 后没 flush」会因 DB 残留到期值误触发。重启续接仍以落库值为准
4412
+ * (实例不驻留时后端值是唯一事实;要重启不丢 alarm,方法内仍须 flush——见 features/state-objects.md)。
4339
4413
  * - onAlarm 后统一持久化(flush):onAlarm 内改的 state 与 setAlarm 重调度 / clearAlarm
4340
4414
  * 的新 alarmAt 都落库;
4341
4415
  * - 单对象 onAlarm 抛错**不阻塞**同 tick 其余对象:失败对象不落库、alarmAt 保留
4342
4416
  * → 下轮 dueAlarms 仍命中重试;错误折叠进 failed(不泄漏内部栈)。
4343
4417
  */
4344
4418
  async pump(now) {
4345
- const due = await this.backend.dueAlarms(now);
4419
+ const dueMap = /* @__PURE__ */ new Map();
4420
+ for (const d of await this.backend.dueAlarms(now)) {
4421
+ dueMap.set(this.key(d.type, d.id), d);
4422
+ }
4423
+ for (const [k, inst] of this.instances) {
4424
+ const typeName = inst.constructor.typeName;
4425
+ if (typeName === void 0) continue;
4426
+ const raw = inst;
4427
+ if (raw.alarmAt === null || raw.alarmAt > now) {
4428
+ dueMap.delete(k);
4429
+ continue;
4430
+ }
4431
+ dueMap.set(k, { type: typeName, id: inst.id, alarmAt: raw.alarmAt });
4432
+ }
4433
+ const due = [...dueMap.values()].toSorted((a, b) => a.alarmAt - b.alarmAt);
4346
4434
  const fired = [];
4347
4435
  const failed = [];
4348
4436
  for (const d of due) {
@@ -4906,7 +4994,7 @@ ${DYNAMIC_IMPORT_HINT}` : "";
4906
4994
  if (typeof code === "string") wrapped.code = code;
4907
4995
  return wrapped;
4908
4996
  }
4909
- function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths = false) {
4997
+ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths = false, hints) {
4910
4998
  const cached = cache.get(path);
4911
4999
  if (cached !== void 0) return cached;
4912
5000
  const source = files[path];
@@ -4927,7 +5015,7 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
4927
5015
  }
4928
5016
  const resolved = resolveModulePath(dir, request, files);
4929
5017
  if (resolved !== null) {
4930
- return loadModule(resolved, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths);
5018
+ return loadModule(resolved, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths, hints);
4931
5019
  }
4932
5020
  if (resolveBare !== void 0 && !request.startsWith("./") && !request.startsWith("../")) {
4933
5021
  const cachedModule = bareCache?.get(request);
@@ -4942,21 +5030,33 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
4942
5030
  error.code = SANDBOX_BUILTIN_REJECTED;
4943
5031
  throw error;
4944
5032
  };
4945
- let transformed;
5033
+ const hint = hints?.[path];
5034
+ let scriptSource;
4946
5035
  try {
4947
- transformed = transformExports(transpile(source));
5036
+ scriptSource = hint !== void 0 ? hint.js : `${WRAPPER_PREFIX}${transformExports(transpile(source))}${WRAPPER_SUFFIX}`;
4948
5037
  } catch (error) {
4949
5038
  throw syntaxErrorWithLocation(error, path, source);
4950
5039
  }
4951
5040
  const context = createSandboxContext(sandboxGlobals);
4952
5041
  let wrapper;
4953
5042
  try {
4954
- wrapper = vm.runInContext(
4955
- `(function (module, exports, require) { ${transformed}
4956
- })`,
4957
- context,
4958
- { filename: path }
4959
- );
5043
+ if (hint !== void 0 && hint.cachedData !== void 0) {
5044
+ const script = new vm.Script(scriptSource, {
5045
+ filename: path,
5046
+ cachedData: Buffer.from(
5047
+ hint.cachedData.buffer,
5048
+ hint.cachedData.byteOffset,
5049
+ hint.cachedData.byteLength
5050
+ )
5051
+ });
5052
+ if (script.cachedDataRejected !== true) {
5053
+ wrapper = script.runInContext(context);
5054
+ } else {
5055
+ wrapper = vm.runInContext(scriptSource, context, { filename: path });
5056
+ }
5057
+ } else {
5058
+ wrapper = vm.runInContext(scriptSource, context, { filename: path });
5059
+ }
4960
5060
  } catch (error) {
4961
5061
  throw syntaxErrorWithLocation(error, path, source);
4962
5062
  }
@@ -4966,7 +5066,9 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
4966
5066
  }
4967
5067
  return exports;
4968
5068
  }
4969
- function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPaths = false) {
5069
+ var WRAPPER_PREFIX = "(function (module, exports, require) { ";
5070
+ var WRAPPER_SUFFIX = " \n})";
5071
+ function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPaths = false, hints) {
4970
5072
  const cache = /* @__PURE__ */ new Map();
4971
5073
  const bareCache = /* @__PURE__ */ new Map();
4972
5074
  const entryExports = loadModule(
@@ -4976,11 +5078,14 @@ function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPat
4976
5078
  cache,
4977
5079
  resolveBare,
4978
5080
  bareCache,
4979
- strictPaths
5081
+ strictPaths,
5082
+ hints
4980
5083
  );
4981
5084
  const handler = entryExports["default"];
4982
5085
  if (typeof handler !== "function") {
4983
- throw new Error(`\u5165\u53E3\u6587\u4EF6 ${entry} \u7F3A\u5C11 default \u5BFC\u51FA\u7684\u51FD\u6570`);
5086
+ const base = entry.replace(/^.*\//, "");
5087
+ const hint = base === "state-objects.ts" || entry.startsWith("durable-objects/") ? '\u3002\u8BE5\u6587\u4EF6\u662F\u72B6\u6001\u5BF9\u8C61\u58F0\u660E\u6587\u4EF6\uFF0C\u653E\u5728 functions/ \u76EE\u5F55\u5185\u4F1A\u540C\u65F6\u88AB\u5F53\u4F5C\u4E91\u51FD\u6570\u5165\u53E3\uFF1A\u8865\u4E00\u4E2A default \u5BFC\u51FA\u7684\u5360\u4F4D handler\uFF0C\u4F8B\u5982 `export default async () => ({ error: "state objects \u8BF7\u8D70 /api/state/<type>/<id>/<method>" })`' : "";
5088
+ throw new Error(`\u5165\u53E3\u6587\u4EF6 ${entry} \u7F3A\u5C11 default \u5BFC\u51FA\u7684\u51FD\u6570${hint}`);
4984
5089
  }
4985
5090
  return { handler };
4986
5091
  }
@@ -5723,7 +5828,9 @@ function runWorker(input, port) {
5723
5828
  sandboxGlobals,
5724
5829
  input.deps === void 0 ? void 0 : createBareResolver(input.deps),
5725
5830
  // CORE-154:--parity 严格模式连带 `../` 越根引用报错(与容器形态真实 fs 同形)。
5726
- input.parity === true
5831
+ input.parity === true,
5832
+ // W2:预编译提示透传(缺省 undefined = 全量编译路径,零回归)。
5833
+ input.compileHints
5727
5834
  );
5728
5835
  const result = Promise.resolve(handler(ctx));
5729
5836
  void result.then(
@@ -6087,7 +6194,7 @@ async function loadConfig(cwd) {
6087
6194
  return {
6088
6195
  name: config?.name ?? name,
6089
6196
  functionsDir: config?.functionsDir ?? "functions",
6090
- functionsPrefix: config?.functions_prefix ?? "",
6197
+ functionsPrefix: normalizeFunctionsPrefix(config?.functions_prefix ?? ""),
6091
6198
  ...config?.environment === void 0 ? {} : { environment: config.environment },
6092
6199
  ...config?.db_environment === void 0 ? {} : { dbEnvironment: config.db_environment }
6093
6200
  };
@@ -6095,7 +6202,7 @@ async function loadConfig(cwd) {
6095
6202
  var parseEnvFile = parseEnv;
6096
6203
  function resolveRouteFnName(pathname, prefix) {
6097
6204
  const segments = pathname.split("/").filter((segment) => segment.length > 0);
6098
- const normalizedPrefix = prefix.replace(/^\/+|\/+$/g, "");
6205
+ const normalizedPrefix = normalizeFunctionsPrefix(prefix);
6099
6206
  if (normalizedPrefix.length === 0) {
6100
6207
  const first = segments[0];
6101
6208
  return first === void 0 ? {} : { fnName: first };
@@ -6139,7 +6246,7 @@ async function startDevServer(options) {
6139
6246
  `));
6140
6247
  const config = await loadConfig(cwd);
6141
6248
  if (options.prefix !== void 0) {
6142
- config.functionsPrefix = options.prefix.replace(/^\/+|\/+$/g, "");
6249
+ config.functionsPrefix = normalizeFunctionsPrefix(options.prefix);
6143
6250
  }
6144
6251
  const functionsDir = join10(cwd, config.functionsDir);
6145
6252
  const coldStartAt = Date.now();
@@ -6317,7 +6424,7 @@ async function startDevServer(options) {
6317
6424
  return;
6318
6425
  }
6319
6426
  if (fnName === "state") {
6320
- const normalizedPrefix = config.functionsPrefix.replace(/^\/+|\/+$/g, "");
6427
+ const normalizedPrefix = normalizeFunctionsPrefix(config.functionsPrefix);
6321
6428
  const rest = normalizedPrefix.length === 0 ? url.pathname : url.pathname.replace(new RegExp(`^/${normalizedPrefix}`), "");
6322
6429
  const parsed = parseStatePath(rest);
6323
6430
  if (parsed === null) {
@@ -6428,13 +6535,19 @@ async function startDevServer(options) {
6428
6535
  const baseUrl = `http://127.0.0.1:${actualPort}`;
6429
6536
  runtime.storage.signer.baseUrl = baseUrl;
6430
6537
  const coldStartMs = Date.now() - coldStartAt;
6431
- const curlPath = config.functionsPrefix.length === 0 ? "/hello" : `/${config.functionsPrefix}/hello`;
6538
+ const functionNames = listFunctionNames(files);
6539
+ const firstFunction = functionNames[0];
6540
+ const curlPath = firstFunction === void 0 ? null : config.functionsPrefix.length === 0 ? `/${firstFunction}` : `/${config.functionsPrefix}/${firstFunction}`;
6432
6541
  const dbLabel = db.mode === "sqlite" ? `SQLite \u771F\u5B9E\u5E93${db.module === null ? "" : `\uFF08${db.module}\uFF09`}` : "sim \u5F15\u64CE\uFF08\u5185\u7F6E\u6A21\u62DF\uFF09";
6433
6542
  const dbTargetText = db.file === null ? simDbTarget(cwd) : displayPath(cwd, db.file);
6434
6543
  log(
6435
6544
  `[adep] dev server listening on ${baseUrl}\uFF08\u672C\u5730\u8FD0\u884C\u65F6 / ${dbLabel}\uFF0C\u51B7\u542F\u52A8 ${coldStartMs}ms\uFF09`
6436
6545
  );
6437
- log(`[adep] curl \u793A\u4F8B\uFF1Acurl ${baseUrl}${curlPath}`);
6546
+ if (curlPath === null) {
6547
+ log("[adep] functions/ \u76EE\u5F55\u4E3A\u7A7A\uFF1A\u6682\u65E0\u51FD\u6570\u53EF\u8C03\u7528\u3002\u65B0\u5EFA functions/<name>.ts \u540E\u81EA\u52A8\u70ED\u91CD\u8F7D\u3002");
6548
+ } else {
6549
+ log(`[adep] curl \u793A\u4F8B\uFF1Acurl ${baseUrl}${curlPath}`);
6550
+ }
6438
6551
  printBoundaries(log);
6439
6552
  if (simUser.resolver !== void 0) {
6440
6553
  log(
@@ -489,7 +489,7 @@ ${DYNAMIC_IMPORT_HINT}` : "";
489
489
  if (typeof code === "string") wrapped.code = code;
490
490
  return wrapped;
491
491
  }
492
- function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths = false) {
492
+ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths = false, hints) {
493
493
  const cached = cache.get(path);
494
494
  if (cached !== void 0) return cached;
495
495
  const source = files[path];
@@ -510,7 +510,7 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
510
510
  }
511
511
  const resolved = resolveModulePath(dir, request, files);
512
512
  if (resolved !== null) {
513
- return loadModule(resolved, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths);
513
+ return loadModule(resolved, files, sandboxGlobals, cache, resolveBare, bareCache, strictPaths, hints);
514
514
  }
515
515
  if (resolveBare !== void 0 && !request.startsWith("./") && !request.startsWith("../")) {
516
516
  const cachedModule = bareCache?.get(request);
@@ -525,21 +525,33 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
525
525
  error.code = SANDBOX_BUILTIN_REJECTED;
526
526
  throw error;
527
527
  };
528
- let transformed;
528
+ const hint = hints?.[path];
529
+ let scriptSource;
529
530
  try {
530
- transformed = transformExports(transpile(source));
531
+ scriptSource = hint !== void 0 ? hint.js : `${WRAPPER_PREFIX}${transformExports(transpile(source))}${WRAPPER_SUFFIX}`;
531
532
  } catch (error) {
532
533
  throw syntaxErrorWithLocation(error, path, source);
533
534
  }
534
535
  const context = createSandboxContext(sandboxGlobals);
535
536
  let wrapper;
536
537
  try {
537
- wrapper = vm.runInContext(
538
- `(function (module, exports, require) { ${transformed}
539
- })`,
540
- context,
541
- { filename: path }
542
- );
538
+ if (hint !== void 0 && hint.cachedData !== void 0) {
539
+ const script = new vm.Script(scriptSource, {
540
+ filename: path,
541
+ cachedData: Buffer.from(
542
+ hint.cachedData.buffer,
543
+ hint.cachedData.byteOffset,
544
+ hint.cachedData.byteLength
545
+ )
546
+ });
547
+ if (script.cachedDataRejected !== true) {
548
+ wrapper = script.runInContext(context);
549
+ } else {
550
+ wrapper = vm.runInContext(scriptSource, context, { filename: path });
551
+ }
552
+ } else {
553
+ wrapper = vm.runInContext(scriptSource, context, { filename: path });
554
+ }
543
555
  } catch (error) {
544
556
  throw syntaxErrorWithLocation(error, path, source);
545
557
  }
@@ -549,7 +561,9 @@ function loadModule(path, files, sandboxGlobals, cache, resolveBare, bareCache,
549
561
  }
550
562
  return exports;
551
563
  }
552
- function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPaths = false) {
564
+ var WRAPPER_PREFIX = "(function (module, exports, require) { ";
565
+ var WRAPPER_SUFFIX = " \n})";
566
+ function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPaths = false, hints) {
553
567
  const cache = /* @__PURE__ */ new Map();
554
568
  const bareCache = /* @__PURE__ */ new Map();
555
569
  const entryExports = loadModule(
@@ -559,11 +573,14 @@ function loadFunctionModule(files, entry, sandboxGlobals, resolveBare, strictPat
559
573
  cache,
560
574
  resolveBare,
561
575
  bareCache,
562
- strictPaths
576
+ strictPaths,
577
+ hints
563
578
  );
564
579
  const handler = entryExports["default"];
565
580
  if (typeof handler !== "function") {
566
- throw new Error(`\u5165\u53E3\u6587\u4EF6 ${entry} \u7F3A\u5C11 default \u5BFC\u51FA\u7684\u51FD\u6570`);
581
+ const base = entry.replace(/^.*\//, "");
582
+ const hint = base === "state-objects.ts" || entry.startsWith("durable-objects/") ? '\u3002\u8BE5\u6587\u4EF6\u662F\u72B6\u6001\u5BF9\u8C61\u58F0\u660E\u6587\u4EF6\uFF0C\u653E\u5728 functions/ \u76EE\u5F55\u5185\u4F1A\u540C\u65F6\u88AB\u5F53\u4F5C\u4E91\u51FD\u6570\u5165\u53E3\uFF1A\u8865\u4E00\u4E2A default \u5BFC\u51FA\u7684\u5360\u4F4D handler\uFF0C\u4F8B\u5982 `export default async () => ({ error: "state objects \u8BF7\u8D70 /api/state/<type>/<id>/<method>" })`' : "";
583
+ throw new Error(`\u5165\u53E3\u6587\u4EF6 ${entry} \u7F3A\u5C11 default \u5BFC\u51FA\u7684\u51FD\u6570${hint}`);
567
584
  }
568
585
  return { handler };
569
586
  }
@@ -1254,7 +1271,9 @@ function runWorker(input, port) {
1254
1271
  sandboxGlobals,
1255
1272
  input.deps === void 0 ? void 0 : createBareResolver(input.deps),
1256
1273
  // CORE-154:--parity 严格模式连带 `../` 越根引用报错(与容器形态真实 fs 同形)。
1257
- input.parity === true
1274
+ input.parity === true,
1275
+ // W2:预编译提示透传(缺省 undefined = 全量编译路径,零回归)。
1276
+ input.compileHints
1258
1277
  );
1259
1278
  const result = Promise.resolve(handler(ctx));
1260
1279
  void result.then(
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "homepage": "https://adep.top",
9
9
  "bugs": "https://gitcode.com/yunqiang_wu/ai-yunke/issues",
10
- "version": "0.5.7",
10
+ "version": "0.5.8",
11
11
  "adep": {
12
12
  "releaseTasks": [
13
13
  "CORE-485"
@@ -36,13 +36,13 @@
36
36
  "yaml": "2.9.1",
37
37
  "zod": "^4.6.6",
38
38
  "@adep/app-runtime": "0.1.1",
39
- "@adep/runtime": "0.3.12",
40
- "@adep/cf-compat": "0.1.4",
41
39
  "@adep/crypto": "0.1.1",
42
- "@adep/vite-plugin": "0.1.13"
40
+ "@adep/cf-compat": "0.1.4",
41
+ "@adep/vite-plugin": "0.1.13",
42
+ "@adep/runtime": "0.3.16"
43
43
  },
44
44
  "devDependencies": {
45
- "@adep/types": "0.4.3"
45
+ "@adep/types": "0.4.5"
46
46
  },
47
47
  "scripts": {
48
48
  "test": "vitest run",
@@ -20,6 +20,6 @@
20
20
  "@capacitor/cli": "^7.0.0",
21
21
  "@capacitor/ios": "^7.0.0",
22
22
  "@capacitor/android": "^7.0.0",
23
- "typescript": "5.9.3"
23
+ "typescript": "6.0.3"
24
24
  }
25
25
  }