@farm.js/core 0.1.37 → 0.1.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (242) hide show
  1. package/dist/{agent-mcp-BC0bAGVF.d.mts → agent-mcp-BwKlpnc7.d.mts} +1 -1
  2. package/dist/{agent-mcp-jyDHbQKe.d.ts → agent-mcp-De1imoMS.d.ts} +1 -1
  3. package/dist/{agent-mcp-handler-SJAHFSPI.cjs → agent-mcp-handler-MRGP3WJ3.cjs} +5 -5
  4. package/dist/{agent-mcp-handler-LPJ2CADR.mjs → agent-mcp-handler-OLRMZONF.mjs} +4 -4
  5. package/dist/agent-runtime.cjs +2 -2
  6. package/dist/agent-runtime.d.mts +1 -1
  7. package/dist/agent-runtime.d.ts +1 -1
  8. package/dist/agent-runtime.mjs +1 -1
  9. package/dist/api/client.cjs +3 -3
  10. package/dist/api/client.mjs +2 -2
  11. package/dist/api/route-manager.cjs +5 -5
  12. package/dist/api/route-manager.d.mts +3 -3
  13. package/dist/api/route-manager.d.ts +3 -3
  14. package/dist/api/route-manager.mjs +4 -4
  15. package/dist/api/runtime.cjs +4 -4
  16. package/dist/api/runtime.d.mts +2 -2
  17. package/dist/api/runtime.d.ts +2 -2
  18. package/dist/api/runtime.mjs +3 -3
  19. package/dist/api.cjs +7 -7
  20. package/dist/api.d.mts +3 -3
  21. package/dist/api.d.ts +3 -3
  22. package/dist/api.mjs +6 -6
  23. package/dist/{app-Cbkj9ufe.d.mts → app-CFZt-srr.d.mts} +21 -3
  24. package/dist/{app-CKO3iN1c.d.ts → app-kT_QXTdx.d.ts} +21 -3
  25. package/dist/app-markdown.cjs +4 -4
  26. package/dist/app-markdown.d.mts +2 -2
  27. package/dist/app-markdown.d.ts +2 -2
  28. package/dist/app-markdown.mjs +3 -3
  29. package/dist/{chunk-LOFKRKO7.cjs → chunk-2DD4JMQC.cjs} +113 -22
  30. package/dist/chunk-2ZYGC6SS.cjs +576 -0
  31. package/dist/{chunk-75X755YZ.cjs → chunk-34UCJRQO.cjs} +2 -2
  32. package/dist/{chunk-CVH2BXPY.cjs → chunk-3LOLJTFV.cjs} +6 -6
  33. package/dist/{chunk-4GPOC4LN.cjs → chunk-472NCAZ7.cjs} +3 -3
  34. package/dist/{chunk-WT4TGLXT.cjs → chunk-4E5QXOCL.cjs} +6 -6
  35. package/dist/{chunk-7DWNJI73.cjs → chunk-4IE345DM.cjs} +37 -19
  36. package/dist/{chunk-O6WAEAX3.mjs → chunk-5BWWFHR2.mjs} +70 -15
  37. package/dist/{chunk-6LGFV2CQ.cjs → chunk-5OKBARDN.cjs} +2 -2
  38. package/dist/{chunk-3IP27TCG.cjs → chunk-5PWXMJOH.cjs} +19 -19
  39. package/dist/chunk-6BK3K2GB.mjs +318 -0
  40. package/dist/{chunk-HEVMCTSR.mjs → chunk-6HB6V3R7.mjs} +1 -1
  41. package/dist/{chunk-NICDYKBS.cjs → chunk-6XWDE2P2.cjs} +22 -4
  42. package/dist/{chunk-Z7LA7MHQ.mjs → chunk-7FPTZLKH.mjs} +1 -1
  43. package/dist/{chunk-JPNFPAZ4.mjs → chunk-7PEP3BUT.mjs} +1 -1
  44. package/dist/{chunk-XOPOIFTJ.mjs → chunk-A3EAIURZ.mjs} +25 -7
  45. package/dist/{chunk-LBDP3YT3.mjs → chunk-ARC7I3O2.mjs} +1 -1
  46. package/dist/{chunk-LBGILORX.mjs → chunk-B6G5CKMC.mjs} +101 -10
  47. package/dist/{chunk-MCIZVNOQ.mjs → chunk-BZHXGVMA.mjs} +1 -1
  48. package/dist/{chunk-KDTBF3UU.mjs → chunk-CNNOLE4O.mjs} +1 -1
  49. package/dist/{chunk-TDNWPAVR.mjs → chunk-CUM5NYL5.mjs} +1 -1
  50. package/dist/{chunk-HITLGIAO.cjs → chunk-CY2ZQ5C6.cjs} +7 -6
  51. package/dist/{chunk-KPFKMDM7.mjs → chunk-DRLKAXDM.mjs} +1 -1
  52. package/dist/{chunk-VR4GD5I3.cjs → chunk-EIPC3FDA.cjs} +12 -4
  53. package/dist/{chunk-K3SAEIM3.mjs → chunk-EKF7KDFD.mjs} +1 -1
  54. package/dist/{chunk-B5PFZLKV.cjs → chunk-EKN7NSZO.cjs} +25 -8
  55. package/dist/{chunk-ATWHHSY2.cjs → chunk-EMO6K4YY.cjs} +4 -4
  56. package/dist/{chunk-6SJ2KJTA.mjs → chunk-EPYU2EBL.mjs} +1 -1
  57. package/dist/{chunk-PTZ2TVNE.cjs → chunk-H5CLOUZS.cjs} +5 -5
  58. package/dist/{chunk-DTSROJ5J.mjs → chunk-HD5CF3OE.mjs} +1 -1
  59. package/dist/{chunk-IAIYV4RZ.mjs → chunk-HXRYZWTA.mjs} +1 -1
  60. package/dist/{chunk-Z5BEWYVO.mjs → chunk-IBUQWVYA.mjs} +16 -0
  61. package/dist/{chunk-HMRSWN47.mjs → chunk-INL3THCU.mjs} +1 -1
  62. package/dist/{chunk-FBOJ55OM.mjs → chunk-IVLZZZEI.mjs} +1 -1
  63. package/dist/{chunk-ENLZ4R3Y.mjs → chunk-J7K2NZD6.mjs} +7 -6
  64. package/dist/{chunk-NFMDCAOS.mjs → chunk-JCKYH4LG.mjs} +2 -2
  65. package/dist/{chunk-PMQHMWZU.cjs → chunk-JCYYXBAJ.cjs} +3 -3
  66. package/dist/{chunk-LPFV45AY.cjs → chunk-KCQBAKIY.cjs} +9 -9
  67. package/dist/{chunk-FGRYBX5X.mjs → chunk-KHKLMNI5.mjs} +1 -1
  68. package/dist/{chunk-NQ6QFZWD.cjs → chunk-KKSTAEMY.cjs} +1 -1
  69. package/dist/{chunk-7O5M4UKW.cjs → chunk-L4DD7ODZ.cjs} +2 -2
  70. package/dist/{chunk-YCKO6FRS.mjs → chunk-LI2F57NI.mjs} +1 -1
  71. package/dist/{chunk-TW4GYDBJ.mjs → chunk-MLY2RP5R.mjs} +10 -2
  72. package/dist/{chunk-5BXGGEC7.cjs → chunk-N32CC42M.cjs} +5 -5
  73. package/dist/{chunk-BHY547NB.cjs → chunk-NBBEQLOK.cjs} +9 -9
  74. package/dist/{chunk-WQ7T2263.mjs → chunk-OAHTRMIC.mjs} +3 -3
  75. package/dist/{chunk-K4I4O5TS.mjs → chunk-OCIEZME4.mjs} +790 -671
  76. package/dist/{chunk-UH6QN5NL.mjs → chunk-P664ZVTV.mjs} +2 -2
  77. package/dist/{chunk-TE2G5ION.cjs → chunk-PGZDEPTM.cjs} +88 -33
  78. package/dist/{chunk-3KGDJLJK.mjs → chunk-POSPE3IO.mjs} +19 -1
  79. package/dist/{chunk-3A4KGQYI.cjs → chunk-Q3NXS4MU.cjs} +16 -14
  80. package/dist/{chunk-TPLJVC7E.mjs → chunk-QFW2IH5E.mjs} +23 -6
  81. package/dist/{chunk-S3VWVTVA.mjs → chunk-QRKIMN7T.mjs} +13 -1
  82. package/dist/chunk-QTXBII4Z.cjs +632 -0
  83. package/dist/{chunk-CI6E3UOH.cjs → chunk-RG4A6LB2.cjs} +7 -7
  84. package/dist/{chunk-7SQ5SGYZ.cjs → chunk-RW63BOV7.cjs} +2 -2
  85. package/dist/{chunk-U6MPZ35Q.cjs → chunk-RWFLWR5J.cjs} +8 -8
  86. package/dist/{chunk-EUV4YR3V.cjs → chunk-SGBJ247Q.cjs} +18 -2
  87. package/dist/{chunk-J3ANCZKA.mjs → chunk-SKVTP5PR.mjs} +1 -1
  88. package/dist/{chunk-6TJITR2B.cjs → chunk-TGFQVLLF.cjs} +870 -751
  89. package/dist/{chunk-4P6ULFMD.mjs → chunk-TUBTR2OP.mjs} +221 -102
  90. package/dist/{chunk-EMMQ64QW.cjs → chunk-TYJALEHQ.cjs} +2 -2
  91. package/dist/{chunk-WRPHYQVY.mjs → chunk-TYMMBFN2.mjs} +1 -1
  92. package/dist/chunk-U6QLDL3G.mjs +576 -0
  93. package/dist/{chunk-OW67PDDS.cjs → chunk-ULASELLA.cjs} +13 -1
  94. package/dist/{chunk-WWIKMBRN.mjs → chunk-VNGH5MLF.mjs} +17 -1
  95. package/dist/{chunk-NNSAQX3U.mjs → chunk-VT4WFRHA.mjs} +1 -1
  96. package/dist/{chunk-UJZLSXUB.cjs → chunk-VU6AAZVY.cjs} +17 -1
  97. package/dist/{chunk-ADOAUDQ6.cjs → chunk-VXEEATVD.cjs} +2 -2
  98. package/dist/{chunk-RRMVL6CJ.mjs → chunk-W36M2BQ4.mjs} +1 -1
  99. package/dist/{chunk-4WQ6PGSJ.cjs → chunk-WEW2JVA4.cjs} +4 -4
  100. package/dist/{chunk-4E5WBPEG.mjs → chunk-WFRT7JPX.mjs} +8 -533
  101. package/dist/{chunk-VXAWRDK7.mjs → chunk-WLL43JMO.mjs} +1 -1
  102. package/dist/chunk-WW46B6HA.cjs +318 -0
  103. package/dist/{chunk-D3C5LBQY.cjs → chunk-WXJLNP33.cjs} +2 -2
  104. package/dist/{chunk-NDILNQ4L.cjs → chunk-XKG2BLFN.cjs} +2 -2
  105. package/dist/{chunk-W2YDNK66.cjs → chunk-XKVVMZP5.cjs} +2 -2
  106. package/dist/{chunk-Q5FYSK45.cjs → chunk-YR2VBEMO.cjs} +619 -500
  107. package/dist/{chunk-EXG5LD6B.mjs → chunk-ZJD2PN6Z.mjs} +10 -8
  108. package/dist/{chunk-G2TEB74S.cjs → chunk-ZXH4TS3F.cjs} +2 -2
  109. package/dist/{client-plugins-C8DjftDF.d.ts → client-plugins-BvlNhGEB.d.ts} +40 -7
  110. package/dist/{client-plugins-CV4eJ9De.d.mts → client-plugins-DUrIYX9B.d.mts} +40 -7
  111. package/dist/client-plugins.d.mts +1 -1
  112. package/dist/client-plugins.d.ts +1 -1
  113. package/dist/client.cjs +5 -5
  114. package/dist/client.d.mts +5 -5
  115. package/dist/client.d.ts +5 -5
  116. package/dist/client.mjs +4 -4
  117. package/dist/config.d.mts +1 -1
  118. package/dist/config.d.ts +1 -1
  119. package/dist/{devtools-KVOY2TCZ.mjs → devtools-JYJNOLPQ.mjs} +7 -5
  120. package/dist/{devtools-JXFQNWSH.cjs → devtools-VQWJANJV.cjs} +8 -6
  121. package/dist/docs.cjs +11 -9
  122. package/dist/docs.d.mts +20 -2
  123. package/dist/docs.d.ts +20 -2
  124. package/dist/docs.mjs +10 -8
  125. package/dist/headers.cjs +6 -4
  126. package/dist/headers.d.mts +11 -1
  127. package/dist/headers.d.ts +11 -1
  128. package/dist/headers.mjs +5 -3
  129. package/dist/index.cjs +52 -39
  130. package/dist/index.d.mts +15 -15
  131. package/dist/index.d.ts +15 -15
  132. package/dist/index.mjs +52 -39
  133. package/dist/integrations.cjs +4 -2
  134. package/dist/integrations.d.mts +1 -1
  135. package/dist/integrations.d.ts +1 -1
  136. package/dist/integrations.mjs +3 -1
  137. package/dist/internal/app-markdown-runtime.cjs +3 -3
  138. package/dist/internal/app-markdown-runtime.d.mts +2 -2
  139. package/dist/internal/app-markdown-runtime.d.ts +2 -2
  140. package/dist/internal/app-markdown-runtime.mjs +2 -2
  141. package/dist/internal/build-runtime.cjs +28 -27
  142. package/dist/internal/build-runtime.d.mts +3 -3
  143. package/dist/internal/build-runtime.d.ts +3 -3
  144. package/dist/internal/build-runtime.mjs +27 -26
  145. package/dist/internal/cli-runtime.cjs +10 -8
  146. package/dist/internal/cli-runtime.mjs +9 -7
  147. package/dist/internal/client-error-overlay.cjs +4 -4
  148. package/dist/internal/client-error-overlay.mjs +1 -1
  149. package/dist/internal/compression-runtime.d.mts +1 -1
  150. package/dist/internal/compression-runtime.d.ts +1 -1
  151. package/dist/internal/config-runtime.cjs +8 -6
  152. package/dist/internal/config-runtime.d.mts +2 -2
  153. package/dist/internal/config-runtime.d.ts +2 -2
  154. package/dist/internal/config-runtime.mjs +7 -5
  155. package/dist/internal/docs-precompiled-runtime.cjs +19 -13
  156. package/dist/internal/docs-precompiled-runtime.d.mts +5 -0
  157. package/dist/internal/docs-precompiled-runtime.d.ts +5 -0
  158. package/dist/internal/docs-precompiled-runtime.mjs +14 -8
  159. package/dist/internal/infra-analytics-runtime.cjs +5 -5
  160. package/dist/internal/infra-analytics-runtime.mjs +3 -3
  161. package/dist/internal/product-telemetry-runtime.cjs +2 -2
  162. package/dist/internal/product-telemetry-runtime.mjs +1 -1
  163. package/dist/internal/production-node-env.cjs +6 -2
  164. package/dist/internal/production-node-env.d.mts +10 -1
  165. package/dist/internal/production-node-env.d.ts +10 -1
  166. package/dist/internal/production-node-env.mjs +5 -1
  167. package/dist/internal/production-runtime.cjs +34 -14
  168. package/dist/internal/production-runtime.d.mts +51 -11
  169. package/dist/internal/production-runtime.d.ts +51 -11
  170. package/dist/internal/production-runtime.mjs +36 -16
  171. package/dist/markdown.cjs +8 -2
  172. package/dist/markdown.d.mts +1 -1
  173. package/dist/markdown.d.ts +1 -1
  174. package/dist/markdown.mjs +7 -1
  175. package/dist/middleware.cjs +9 -7
  176. package/dist/middleware.d.mts +24 -4
  177. package/dist/middleware.d.ts +24 -4
  178. package/dist/middleware.mjs +9 -7
  179. package/dist/navigation.cjs +4 -4
  180. package/dist/navigation.d.mts +4 -4
  181. package/dist/navigation.d.ts +4 -4
  182. package/dist/navigation.mjs +3 -3
  183. package/dist/plugin.cjs +21 -20
  184. package/dist/plugin.d.mts +1 -1
  185. package/dist/plugin.d.ts +1 -1
  186. package/dist/plugin.mjs +20 -19
  187. package/dist/{production-runtime-Du_FHb2-.d.mts → production-runtime-BQ4_WLwQ.d.mts} +1 -1
  188. package/dist/{production-runtime-C2kkrPVZ.d.ts → production-runtime-D2aMyzjr.d.ts} +1 -1
  189. package/dist/query/client.cjs +2 -2
  190. package/dist/query/client.mjs +1 -1
  191. package/dist/{render-plan-BnnPTpus.d.ts → render-plan-25p4hrj4.d.ts} +1 -1
  192. package/dist/{render-plan-Cgx7v8tJ.d.mts → render-plan-DtkXMN8D.d.mts} +1 -1
  193. package/dist/renderer-client.d.mts +3 -3
  194. package/dist/renderer-client.d.ts +3 -3
  195. package/dist/renderer.d.mts +13 -4
  196. package/dist/renderer.d.ts +13 -4
  197. package/dist/{request-sKayKcop.d.mts → request-DgCkIdcn.d.mts} +4 -2
  198. package/dist/{request-BNWr7r5e.d.ts → request-jF4jwx8f.d.ts} +4 -2
  199. package/dist/request.cjs +3 -3
  200. package/dist/request.d.mts +2 -2
  201. package/dist/request.d.ts +2 -2
  202. package/dist/request.mjs +2 -2
  203. package/dist/{route-rendering-Bx4Auw6Q.d.ts → route-rendering-Bji6S6a_.d.ts} +1 -1
  204. package/dist/{route-rendering-DWFp3Yq4.d.mts → route-rendering-CSBF78Ya.d.mts} +1 -1
  205. package/dist/{router-BK6K42Ij.d.mts → router-B09Ui3Qm.d.mts} +1 -1
  206. package/dist/{router-DnW_2tQi.d.ts → router-CPB9cXtG.d.ts} +1 -1
  207. package/dist/routes.d.mts +1 -1
  208. package/dist/routes.d.ts +1 -1
  209. package/dist/{runtime-DJDaCMd_.d.mts → runtime-CM6E6yuI.d.mts} +1 -1
  210. package/dist/{runtime-CA3Ei5k_.d.ts → runtime-EDMwLdjv.d.ts} +1 -1
  211. package/dist/server-fn.cjs +3 -3
  212. package/dist/server-fn.mjs +2 -2
  213. package/dist/server-plugins.cjs +5 -5
  214. package/dist/server-plugins.d.mts +2 -2
  215. package/dist/server-plugins.d.ts +2 -2
  216. package/dist/server-plugins.mjs +4 -4
  217. package/dist/server-query.cjs +4 -4
  218. package/dist/server-query.mjs +3 -3
  219. package/dist/server.cjs +47 -46
  220. package/dist/server.d.mts +7 -7
  221. package/dist/server.d.ts +7 -7
  222. package/dist/server.mjs +25 -24
  223. package/dist/{spa-router-Mwbd7g2L.d.ts → spa-router-B_N8XgVu.d.ts} +2 -2
  224. package/dist/{spa-router-D6fUA4Rn.d.mts → spa-router-Cgimzfbi.d.mts} +2 -2
  225. package/dist/testing.cjs +5 -5
  226. package/dist/testing.d.mts +1 -1
  227. package/dist/testing.d.ts +1 -1
  228. package/dist/testing.mjs +4 -4
  229. package/dist/theme/server.cjs +4 -4
  230. package/dist/theme/server.mjs +3 -3
  231. package/dist/{utils-BwVcAfUR.d.ts → utils-BNxAKAuT.d.ts} +1 -1
  232. package/dist/{utils-p9Hs-jCc.d.mts → utils-DZciYXYl.d.mts} +1 -1
  233. package/dist/version.cjs +2 -2
  234. package/dist/version.mjs +1 -1
  235. package/dist/vite.cjs +21 -20
  236. package/dist/vite.d.mts +1 -1
  237. package/dist/vite.d.ts +1 -1
  238. package/dist/vite.mjs +20 -19
  239. package/package.json +1 -1
  240. package/dist/chunk-655RLQQL.mjs +0 -43
  241. package/dist/chunk-MRMI32SN.cjs +0 -1157
  242. package/dist/chunk-MT763TDW.cjs +0 -43
@@ -0,0 +1,318 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-LPEX4YW6.mjs";
4
+
5
+ // src/nitro/node-server-entry.ts
6
+ var FARM_NODE_ENV_MODULE_FILE = "farm-node-env.mjs";
7
+ var FARM_NODE_ENV_MODULE_SOURCE = `if (!process.env.NODE_ENV) process.env.NODE_ENV = "production";
8
+ `;
9
+ function createFarmNodeServerEntry(options) {
10
+ const serverConfig = JSON.stringify(options.server);
11
+ const nitroEntryImport = `./${options.nitroEntryFile.replace(/^\.\//, "")}`;
12
+ return `
13
+ import "./${FARM_NODE_ENV_MODULE_FILE}";
14
+ import "#nitro/virtual/polyfills";
15
+ import { NodeRequest, serve } from ${JSON.stringify(options.nodeAdapterModule)};
16
+ import wsAdapter from ${JSON.stringify(options.websocketAdapterModule)};
17
+ import { resolveWebsocketHooks, useNitroApp, useNitroHooks } from "#nitro/runtime/app";
18
+ import { useRuntimeConfig } from "#nitro/runtime/runtime-config";
19
+ import { trapUnhandledErrors } from "#nitro/runtime/error/hooks";
20
+ import { setupCloseHooks } from "#nitro/runtime/shutdown";
21
+ import { startScheduleRunner } from "#nitro/runtime/task";
22
+ import { tracingSrvxPlugins } from "#nitro/virtual/tracing";
23
+ import { farmProductionLifecycle } from ${JSON.stringify(nitroEntryImport)};
24
+
25
+ const farmServerConfig = ${serverConfig};
26
+ if (!process.env.NITRO_SHUTDOWN_TIMEOUT) {
27
+ process.env.NITRO_SHUTDOWN_TIMEOUT = String(farmServerConfig.gracefulShutdownTimeout);
28
+ }
29
+ const shutdownConfig = {
30
+ disabled: Boolean(process.env.NITRO_SHUTDOWN_DISABLED),
31
+ signals: (process.env.NITRO_SHUTDOWN_SIGNALS || "SIGTERM SIGINT")
32
+ .split(" ")
33
+ .map((signal) => signal.trim())
34
+ .filter(Boolean),
35
+ timeout: Number.parseInt(process.env.NITRO_SHUTDOWN_TIMEOUT || "", 10) || 30000,
36
+ forceExit: !process.env.NITRO_SHUTDOWN_NO_FORCE_EXIT,
37
+ };
38
+
39
+ const nitroApp = useNitroApp();
40
+ useNitroHooks().hook("close", async () => {
41
+ try {
42
+ await farmProductionLifecycle.close("production-server-closed");
43
+ } catch (error) {
44
+ process.exitCode = 1;
45
+ throw error;
46
+ }
47
+ });
48
+
49
+ let startupSignal;
50
+ let resolveStartupSignal;
51
+ const startupSignalPromise = new Promise((resolve) => {
52
+ resolveStartupSignal = resolve;
53
+ });
54
+ const startupSignalListeners = new Map();
55
+ if (!shutdownConfig.disabled) {
56
+ for (const signal of shutdownConfig.signals) {
57
+ const listener = (receivedSignal) => {
58
+ if (!startupSignal) {
59
+ startupSignal = receivedSignal;
60
+ resolveStartupSignal(receivedSignal);
61
+ }
62
+ farmProductionLifecycle.beginDrain(receivedSignal);
63
+ };
64
+ startupSignalListeners.set(signal, listener);
65
+ process.once(signal, listener);
66
+ }
67
+ }
68
+
69
+ try {
70
+ await Promise.race([
71
+ Promise.resolve().then(() => farmProductionLifecycle.start()),
72
+ startupSignalPromise,
73
+ ]);
74
+ } catch (error) {
75
+ await farmProductionLifecycle.close("production-start-failed").catch((closeError) => {
76
+ console.error("[Farm] Runtime cleanup after startup failure failed:", closeError);
77
+ });
78
+ throw error;
79
+ } finally {
80
+ for (const [signal, listener] of startupSignalListeners) {
81
+ process.removeListener(signal, listener);
82
+ }
83
+ }
84
+
85
+ if (startupSignal) {
86
+ let startupCloseTimer;
87
+ const startupCloseCompleted = await Promise.race([
88
+ Promise.resolve()
89
+ .then(() => farmProductionLifecycle.close(startupSignal))
90
+ .then(
91
+ () => true,
92
+ (error) => {
93
+ console.error("[Farm] Runtime shutdown during startup failed:", error);
94
+ process.exitCode = 1;
95
+ return true;
96
+ },
97
+ ),
98
+ new Promise((resolve) => {
99
+ startupCloseTimer = setTimeout(() => resolve(false), farmServerConfig.gracefulShutdownTimeout);
100
+ }),
101
+ ]);
102
+ clearTimeout(startupCloseTimer);
103
+ if (!startupCloseCompleted) {
104
+ console.warn("[Farm] Runtime startup did not settle before shutdown; forcing cleanup");
105
+ let forcedCloseTimer;
106
+ const forcedCloseCompleted = await Promise.race([
107
+ Promise.resolve()
108
+ .then(() => farmProductionLifecycle.forceClose(startupSignal))
109
+ .then(
110
+ () => true,
111
+ (error) => {
112
+ console.error("[Farm] Forced runtime shutdown during startup failed:", error);
113
+ process.exitCode = 1;
114
+ return true;
115
+ },
116
+ ),
117
+ new Promise((resolve) => {
118
+ forcedCloseTimer = setTimeout(
119
+ () => resolve(false),
120
+ farmServerConfig.gracefulShutdownTimeout,
121
+ );
122
+ }),
123
+ ]);
124
+ clearTimeout(forcedCloseTimer);
125
+ if (!forcedCloseCompleted) {
126
+ console.error("[Farm] Forced runtime shutdown during startup timed out");
127
+ process.exitCode = 1;
128
+ }
129
+ }
130
+ process.exit(process.exitCode || 0);
131
+ }
132
+
133
+ const cert = process.env.NITRO_SSL_CERT;
134
+ const key = process.env.NITRO_SSL_KEY;
135
+ const configuredPort = Number(process.env.NITRO_PORT || process.env.PORT);
136
+ const port = Number.isFinite(configuredPort) && configuredPort > 0 ? configuredPort : 3000;
137
+ const host = process.env.NITRO_HOST || process.env.HOST;
138
+ const socketPath = process.env.NITRO_UNIX_SOCKET;
139
+ const server = serve({
140
+ manual: true,
141
+ silent: true,
142
+ gracefulShutdown: false,
143
+ port,
144
+ hostname: host,
145
+ node: socketPath ? { path: socketPath } : undefined,
146
+ tls: cert && key ? { cert, key } : undefined,
147
+ fetch: nitroApp.fetch,
148
+ plugins: [...tracingSrvxPlugins],
149
+ });
150
+ const nodeServer = server.node?.server;
151
+ if (!nodeServer) throw new Error("[Farm] Nitro did not create a Node server");
152
+
153
+ nodeServer.headersTimeout = farmServerConfig.headersTimeout;
154
+ nodeServer.requestTimeout = farmServerConfig.requestTimeout;
155
+ nodeServer.keepAliveTimeout = farmServerConfig.keepAliveTimeout;
156
+
157
+ let isShuttingDown = false;
158
+ nodeServer.on("request", (_request, response) => {
159
+ response.once("finish", () => {
160
+ if (isShuttingDown) nodeServer.closeIdleConnections?.();
161
+ });
162
+ });
163
+
164
+ if (import.meta._websocket) {
165
+ const { handleUpgrade } = wsAdapter({ resolve: resolveWebsocketHooks });
166
+ nodeServer.on("upgrade", (request, socket, head) => {
167
+ handleUpgrade(
168
+ request,
169
+ socket,
170
+ head,
171
+ new NodeRequest({ req: request, upgrade: { socket, head } }),
172
+ );
173
+ });
174
+ }
175
+
176
+ setupCloseHooks(server);
177
+ trapUnhandledErrors();
178
+
179
+ let shutdownPromise;
180
+ async function shutdown(signal) {
181
+ isShuttingDown = true;
182
+ farmProductionLifecycle.beginDrain(signal);
183
+
184
+ const gracefulClose = server.close().then(
185
+ () => true,
186
+ (error) => {
187
+ console.error("[Farm] Runtime shutdown failed:", error);
188
+ process.exitCode = 1;
189
+ return true;
190
+ },
191
+ );
192
+ nodeServer.closeIdleConnections?.();
193
+ let gracefulTimer;
194
+ const gracefullyClosed = await Promise.race([
195
+ gracefulClose,
196
+ new Promise((resolve) => {
197
+ gracefulTimer = setTimeout(() => resolve(false), shutdownConfig.timeout);
198
+ }),
199
+ ]);
200
+ clearTimeout(gracefulTimer);
201
+
202
+ if (!gracefullyClosed) {
203
+ console.warn("[Farm] Graceful shutdown timed out; forcing cleanup");
204
+ void server.close(true).catch((error) => {
205
+ console.error("[Farm] Forced server shutdown failed:", error);
206
+ process.exitCode = 1;
207
+ });
208
+
209
+ let forceTimer;
210
+ const forceClosed = await Promise.race([
211
+ Promise.resolve()
212
+ .then(() => farmProductionLifecycle.forceClose("production-server-closed"))
213
+ .then(
214
+ () => true,
215
+ (error) => {
216
+ console.error("[Farm] Forced runtime shutdown failed:", error);
217
+ process.exitCode = 1;
218
+ return true;
219
+ },
220
+ ),
221
+ new Promise((resolve) => {
222
+ forceTimer = setTimeout(() => resolve(false), shutdownConfig.timeout);
223
+ }),
224
+ ]);
225
+ clearTimeout(forceTimer);
226
+ if (!forceClosed) {
227
+ console.error("[Farm] Forced runtime shutdown timed out");
228
+ process.exitCode = 1;
229
+ }
230
+ }
231
+
232
+ if (shutdownConfig.forceExit) process.exit(process.exitCode || 0);
233
+ }
234
+
235
+ if (!shutdownConfig.disabled) {
236
+ for (const signal of shutdownConfig.signals) {
237
+ process.once(signal, (receivedSignal) => {
238
+ shutdownPromise ||= shutdown(receivedSignal);
239
+ });
240
+ }
241
+ }
242
+
243
+ try {
244
+ await server.serve();
245
+ const protocol = cert && key ? "https" : "http";
246
+ const addressInfo = nodeServer.address();
247
+ if (typeof addressInfo === "string") {
248
+ console.log(\`Listening on unix socket \${addressInfo}\`);
249
+ } else if (addressInfo) {
250
+ const configuredBaseURL = useRuntimeConfig().app.baseURL || "";
251
+ const baseURL = configuredBaseURL.endsWith("/")
252
+ ? configuredBaseURL.slice(0, -1)
253
+ : configuredBaseURL;
254
+ const address = addressInfo.family === "IPv6"
255
+ ? \`[\${addressInfo.address}]\`
256
+ : addressInfo.address;
257
+ console.log(\`Listening on \${protocol}://\${address}:\${addressInfo.port}\${baseURL}\`);
258
+ }
259
+ } catch (error) {
260
+ console.error(error);
261
+ process.exitCode = 1;
262
+ await farmProductionLifecycle.close("production-listen-error").catch((closeError) => {
263
+ console.error("[Farm] Runtime cleanup after listen failure failed:", closeError);
264
+ });
265
+ throw error;
266
+ }
267
+
268
+ if (import.meta._tasks) {
269
+ startScheduleRunner({ waitUntil: server.waitUntil });
270
+ }
271
+
272
+ export default {};
273
+ `.trim();
274
+ }
275
+ __name(createFarmNodeServerEntry, "createFarmNodeServerEntry");
276
+
277
+ // src/build/production-node-env.ts
278
+ var productionNodeEnvStateKey = /* @__PURE__ */ Symbol.for("@farm.js/core/production-node-env-state");
279
+ function getProductionNodeEnvState() {
280
+ return Reflect.get(globalThis, productionNodeEnvStateKey);
281
+ }
282
+ __name(getProductionNodeEnvState, "getProductionNodeEnvState");
283
+ async function withProductionNodeEnv(operation) {
284
+ let state = getProductionNodeEnvState();
285
+ if (state) {
286
+ state.depth += 1;
287
+ } else {
288
+ state = {
289
+ depth: 1,
290
+ original: process.env.NODE_ENV
291
+ };
292
+ Reflect.set(globalThis, productionNodeEnvStateKey, state);
293
+ }
294
+ process.env.NODE_ENV = "production";
295
+ try {
296
+ return await operation();
297
+ } finally {
298
+ state.depth -= 1;
299
+ if (state.depth > 0) {
300
+ process.env.NODE_ENV = "production";
301
+ } else {
302
+ Reflect.deleteProperty(globalThis, productionNodeEnvStateKey);
303
+ if (state.original === void 0) {
304
+ delete process.env.NODE_ENV;
305
+ } else {
306
+ process.env.NODE_ENV = state.original;
307
+ }
308
+ }
309
+ }
310
+ }
311
+ __name(withProductionNodeEnv, "withProductionNodeEnv");
312
+
313
+ export {
314
+ FARM_NODE_ENV_MODULE_FILE,
315
+ FARM_NODE_ENV_MODULE_SOURCE,
316
+ createFarmNodeServerEntry,
317
+ withProductionNodeEnv
318
+ };
@@ -34,7 +34,7 @@ import {
34
34
  } from "./chunk-4SIYUGRY.mjs";
35
35
  import {
36
36
  _runWithCurrentRequest
37
- } from "./chunk-3KGDJLJK.mjs";
37
+ } from "./chunk-POSPE3IO.mjs";
38
38
  import {
39
39
  __name
40
40
  } from "./chunk-LPEX4YW6.mjs";
@@ -1,7 +1,8 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
3
 
4
- var _chunkOW67PDDScjs = require('./chunk-OW67PDDS.cjs');
4
+
5
+ var _chunkULASELLAcjs = require('./chunk-ULASELLA.cjs');
5
6
 
6
7
 
7
8
  var _chunkS3JO3N4Hcjs = require('./chunk-S3JO3N4H.cjs');
@@ -66,8 +67,24 @@ function getAppRequestView(request) {
66
67
  return view;
67
68
  }
68
69
  _chunkS3JO3N4Hcjs.__name.call(void 0, getAppRequestView, "getAppRequestView");
69
- _chunkOW67PDDScjs._setCurrentRequestResolver.call(void 0, () => requestStore.getStore());
70
- _chunkOW67PDDScjs._setAppRequestView.call(void 0, getAppRequestView);
70
+ _chunkULASELLAcjs._setCurrentRequestResolver.call(void 0, () => requestStore.getStore());
71
+ var CSP_NONCE_STORAGE_KEY = /* @__PURE__ */ Symbol.for("@farm.js/core/csp-nonce-storage");
72
+ function getCspNonceStore() {
73
+ const runtime = globalThis;
74
+ const existing = runtime[CSP_NONCE_STORAGE_KEY];
75
+ if (existing instanceof _async_hooks.AsyncLocalStorage) return existing;
76
+ const storage = new (0, _async_hooks.AsyncLocalStorage)();
77
+ runtime[CSP_NONCE_STORAGE_KEY] = storage;
78
+ return storage;
79
+ }
80
+ _chunkS3JO3N4Hcjs.__name.call(void 0, getCspNonceStore, "getCspNonceStore");
81
+ var cspNonceStore = getCspNonceStore();
82
+ _chunkULASELLAcjs._setCspNonceResolver.call(void 0, () => cspNonceStore.getStore());
83
+ function _runWithFarmCspNonce(nonce, fn) {
84
+ return nonce ? cspNonceStore.run(nonce, fn) : fn();
85
+ }
86
+ _chunkS3JO3N4Hcjs.__name.call(void 0, _runWithFarmCspNonce, "_runWithFarmCspNonce");
87
+ _chunkULASELLAcjs._setAppRequestView.call(void 0, getAppRequestView);
71
88
  function resolveFarmRequestURL(req, options = {}) {
72
89
  if (options.origin) {
73
90
  return new URL(req.url || "/", options.origin);
@@ -176,4 +193,5 @@ _chunkS3JO3N4Hcjs.__name.call(void 0, getCurrentRequestOrNull, "getCurrentReques
176
193
 
177
194
 
178
195
 
179
- exports.resolveFarmRequestURL = resolveFarmRequestURL; exports.resolveFarmWebRequestOrigin = resolveFarmWebRequestOrigin; exports.createWebRequestFromFarmRequest = createWebRequestFromFarmRequest; exports._runWithCurrentRequest = _runWithCurrentRequest; exports.getCurrentRequest = getCurrentRequest; exports._getRequestReadCount = _getRequestReadCount; exports.getCurrentRequestOrNull = getCurrentRequestOrNull;
196
+
197
+ exports._runWithFarmCspNonce = _runWithFarmCspNonce; exports.resolveFarmRequestURL = resolveFarmRequestURL; exports.resolveFarmWebRequestOrigin = resolveFarmWebRequestOrigin; exports.createWebRequestFromFarmRequest = createWebRequestFromFarmRequest; exports._runWithCurrentRequest = _runWithCurrentRequest; exports.getCurrentRequest = getCurrentRequest; exports._getRequestReadCount = _getRequestReadCount; exports.getCurrentRequestOrNull = getCurrentRequestOrNull;
@@ -27,7 +27,7 @@ import {
27
27
  } from "./chunk-ZMSZZXOR.mjs";
28
28
  import {
29
29
  getIntegrationSchemas
30
- } from "./chunk-Z5BEWYVO.mjs";
30
+ } from "./chunk-IBUQWVYA.mjs";
31
31
  import {
32
32
  __name
33
33
  } from "./chunk-LPEX4YW6.mjs";
@@ -13,7 +13,7 @@ import {
13
13
  } from "./chunk-IHQIOZLC.mjs";
14
14
  import {
15
15
  _resolveCurrentRequest
16
- } from "./chunk-S3VWVTVA.mjs";
16
+ } from "./chunk-QRKIMN7T.mjs";
17
17
  import {
18
18
  stripFarmLocaleFromPathname
19
19
  } from "./chunk-L3KT7IXV.mjs";
@@ -1,20 +1,21 @@
1
1
  import {
2
2
  discoverFarmDocsPages,
3
+ getFarmDocsMarkdownPath,
3
4
  loadFarmDocsPage,
4
5
  resolveFarmDocsContentDir,
5
6
  toFarmDocsMarkdownPage
6
- } from "./chunk-O6WAEAX3.mjs";
7
+ } from "./chunk-5BWWFHR2.mjs";
7
8
  import {
8
9
  docsEngine,
9
10
  loadFarmDocsEngine
10
11
  } from "./chunk-2VQKKQ6D.mjs";
11
12
  import {
12
13
  resolveDocsConfig
13
- } from "./chunk-EXG5LD6B.mjs";
14
+ } from "./chunk-ZJD2PN6Z.mjs";
14
15
  import {
15
16
  getFarmDocsAdapterConfigModule,
16
17
  isSecretDocsConfigKey
17
- } from "./chunk-ENLZ4R3Y.mjs";
18
+ } from "./chunk-J7K2NZD6.mjs";
18
19
  import {
19
20
  __name
20
21
  } from "./chunk-LPEX4YW6.mjs";
@@ -27,6 +28,15 @@ function hasFarmDocsRuntimeAdapter(docs) {
27
28
  return Boolean(docs?.enabled && docs.adapter?.server && docs.adapter.react);
28
29
  }
29
30
  __name(hasFarmDocsRuntimeAdapter, "hasFarmDocsRuntimeAdapter");
31
+ function assertFarmDocsAdapterServesNoGuardedPages(docs, options, isPathGuarded) {
32
+ if (!isPathGuarded || !hasFarmDocsRuntimeAdapter(docs)) return;
33
+ const guarded = discoverFarmDocsPages(resolveFarmDocsContentDir(docs, options), docs).filter((page) => isPathGuarded(page.href) || isPathGuarded(getFarmDocsMarkdownPath(page.href))).map((page) => page.href);
34
+ if (guarded.length === 0) return;
35
+ throw new Error(
36
+ `Docs pages behind a path guard (${guarded.join(", ")}) would be public: the docs adapter ${JSON.stringify(docs.adapter.id)} serves their content in llms-full.txt, search, Markdown, and MCP without running the app's guards. Move those pages out of the docs content directory, or set docs.adapter = false to use Farm's built-in docs runtime, which keeps guarded pages off anonymous surfaces.`
37
+ );
38
+ }
39
+ __name(assertFarmDocsAdapterServesNoGuardedPages, "assertFarmDocsAdapterServesNoGuardedPages");
30
40
  async function loadFarmDocsConfigModule(docs, loadModule) {
31
41
  const configModule = getFarmDocsAdapterConfigModule(docs);
32
42
  if (!configModule) return void 0;
@@ -99,6 +109,7 @@ async function createFarmDocsAdapterHandler(docs, options) {
99
109
  if (!hasFarmDocsRuntimeAdapter(docs)) {
100
110
  throw new Error("Farm docs adapter requires server and react runtime entrypoints.");
101
111
  }
112
+ assertFarmDocsAdapterServesNoGuardedPages(docs, options, options.isPathGuarded);
102
113
  const serverModule = await options.loadModule(
103
114
  docs.adapter.server
104
115
  );
@@ -277,7 +288,7 @@ function getDocsDescription(docs) {
277
288
  }
278
289
  __name(getDocsDescription, "getDocsDescription");
279
290
  function getLoadedDocsPages(context) {
280
- return discoverFarmDocsPages(context.contentDir, context.docs).map((page) => loadFarmDocsPage(context.contentDir, context.docs, page.slug)).filter((page) => Boolean(page));
291
+ return discoverFarmDocsPages(context.contentDir, context.docs).filter((page) => !context.isPathGuarded(page.href)).map((page) => loadFarmDocsPage(context.contentDir, context.docs, page.slug)).filter((page) => Boolean(page));
281
292
  }
282
293
  __name(getLoadedDocsPages, "getLoadedDocsPages");
283
294
  function toDocsSourcePage(page) {
@@ -389,7 +400,9 @@ __name(renderAgentsDocument, "renderAgentsDocument");
389
400
  function buildAgentSpec(context, request) {
390
401
  const url = new URL(request.url);
391
402
  const origin = url.origin;
392
- const pages = discoverFarmDocsPages(context.contentDir, context.docs);
403
+ const pages = discoverFarmDocsPages(context.contentDir, context.docs).filter(
404
+ (page) => !context.isPathGuarded(page.href)
405
+ );
393
406
  const spec = docsEngine().buildDocsAgentDiscoverySpec(getDocsDiscoveryOptions(context, request));
394
407
  const title = getDocsTitle(context.docs);
395
408
  return {
@@ -552,12 +565,14 @@ async function resolveAPIContext(options) {
552
565
  configPath: options.configPath
553
566
  };
554
567
  const docs = isResolvedDocsConfig(docsInput) ? docsInput : await resolveDocsConfig(docsInput, { root, srcDir });
568
+ const guardedPaths = new Set(runtimeConfig?.guardedPaths ?? []);
555
569
  return {
556
570
  root,
557
571
  srcDir,
558
572
  docs,
559
573
  contentDir: resolveFarmDocsContentDir(docs, { root, srcDir }),
560
- diagnostics: options.diagnostics === true
574
+ diagnostics: options.diagnostics === true,
575
+ isPathGuarded: options.isPathGuarded ?? ((pathname) => guardedPaths.has(pathname))
561
576
  };
562
577
  }
563
578
  __name(resolveAPIContext, "resolveAPIContext");
@@ -616,7 +631,9 @@ async function handleDocsAPIGet(request, context) {
616
631
  const pathParam = url.searchParams.get("path") || url.searchParams.get("slug");
617
632
  const slug = normalizeDocsApiSlug(pathParam ?? pathTarget.slug ?? "", context.docs);
618
633
  const page = loadFarmDocsPage(context.contentDir, context.docs, slug);
619
- if (!page) return text("Docs page not found\n", "text/plain; charset=utf-8", { status: 404 });
634
+ if (!page || context.isPathGuarded(page.href)) {
635
+ return text("Docs page not found\n", "text/plain; charset=utf-8", { status: 404 });
636
+ }
620
637
  return text(
621
638
  docsEngine().renderDocsMarkdownDocument(toFarmDocsMarkdownPage(page), {
622
639
  origin: new URL(request.url).origin,
@@ -688,6 +705,7 @@ __name(createFarmDocsAPIHandler, "createFarmDocsAPIHandler");
688
705
 
689
706
  export {
690
707
  hasFarmDocsRuntimeAdapter,
708
+ assertFarmDocsAdapterServesNoGuardedPages,
691
709
  compileFarmDocsAdapterEdgeManifest,
692
710
  createFarmDocsAdapterHandler,
693
711
  isFarmDocsAPIRequest,
@@ -34,7 +34,7 @@ import {
34
34
  } from "./chunk-4SIYUGRY.mjs";
35
35
  import {
36
36
  _resolveCurrentRequest
37
- } from "./chunk-S3VWVTVA.mjs";
37
+ } from "./chunk-QRKIMN7T.mjs";
38
38
  import {
39
39
  __name
40
40
  } from "./chunk-LPEX4YW6.mjs";
@@ -1,18 +1,29 @@
1
1
  import {
2
2
  FARM_DEFAULT_MCP_TOOLS
3
- } from "./chunk-UH6QN5NL.mjs";
3
+ } from "./chunk-P664ZVTV.mjs";
4
4
  import {
5
5
  DEFAULT_ERROR_STYLES
6
6
  } from "./chunk-XAXTTBUT.mjs";
7
7
  import {
8
8
  serializeFarmLlmsTxt
9
- } from "./chunk-DTSROJ5J.mjs";
9
+ } from "./chunk-HD5CF3OE.mjs";
10
+ import {
11
+ stampFarmCspNonce
12
+ } from "./chunk-U6QLDL3G.mjs";
10
13
  import {
11
14
  emitFarmAgentRead
12
15
  } from "./chunk-MVL2RAJW.mjs";
13
16
  import {
14
17
  resolveFarmThemeConfig
15
18
  } from "./chunk-AELACLOB.mjs";
19
+ import {
20
+ integrationMiddlewareMayHandlePath
21
+ } from "./chunk-IBUQWVYA.mjs";
22
+ import {
23
+ compileMiddlewareConfig,
24
+ matchesCompiledMiddlewareConfig,
25
+ matchesMiddlewareRoute
26
+ } from "./chunk-HZFM2LWQ.mjs";
16
27
  import {
17
28
  omitFarmResponseBody
18
29
  } from "./chunk-5WI2S4CO.mjs";
@@ -25,12 +36,13 @@ import {
25
36
  matchesFarmIfNoneMatch
26
37
  } from "./chunk-ZMMBIVQM.mjs";
27
38
  import {
39
+ createFarmAPIMiddlewarePathnames,
28
40
  resolveFarmAPIServerBasePath,
29
41
  resolveFarmAPIServerRoutePath
30
42
  } from "./chunk-BTHHUD7Q.mjs";
31
43
  import {
32
44
  FARM_VERSION
33
- } from "./chunk-YCKO6FRS.mjs";
45
+ } from "./chunk-LI2F57NI.mjs";
34
46
  import {
35
47
  localizeFarmPathname
36
48
  } from "./chunk-L3KT7IXV.mjs";
@@ -219,6 +231,71 @@ ${html}`;
219
231
  }
220
232
  __name(composeFarmFullDocument, "composeFarmFullDocument");
221
233
 
234
+ // src/middleware/may-handle.ts
235
+ function hasFarmMiddlewareConfig(config) {
236
+ if (!config) return false;
237
+ if (Array.isArray(config)) return config.length > 0;
238
+ const configRecord = config;
239
+ return Boolean(
240
+ configRecord.matcher || configRecord.exclude || configRecord.runtime || configRecord.handler || Array.isArray(configRecord.handlers) && configRecord.handlers.length > 0
241
+ );
242
+ }
243
+ __name(hasFarmMiddlewareConfig, "hasFarmMiddlewareConfig");
244
+ function configMiddlewareMayHandlePath(config, pathname) {
245
+ if (!hasFarmMiddlewareConfig(config)) return false;
246
+ const entries = Array.isArray(config) ? config : [config];
247
+ return entries.some((entry) => {
248
+ if (!entry.matcher && !entry.exclude) return true;
249
+ const matchers = entry.matcher ? (Array.isArray(entry.matcher) ? entry.matcher : [entry.matcher]).map(
250
+ (matcher) => (
251
+ // A request-aware matcher cannot be proven safe at build time.
252
+ typeof matcher === "function" ? () => true : matcher
253
+ )
254
+ ) : void 0;
255
+ const compiled = compileMiddlewareConfig({ matcher: matchers, exclude: entry.exclude });
256
+ return matchesCompiledMiddlewareConfig(pathname, compiled, {}).matched;
257
+ });
258
+ }
259
+ __name(configMiddlewareMayHandlePath, "configMiddlewareMayHandlePath");
260
+ function appMiddlewareMayHandlePath(middlewareRoutes, pathname) {
261
+ return middlewareRoutes.some((route) => matchesMiddlewareRoute(pathname, route).matched);
262
+ }
263
+ __name(appMiddlewareMayHandlePath, "appMiddlewareMayHandlePath");
264
+ var CATCH_ALL_PROBE = "/__farm-listing-probe__/0";
265
+ function isPathSpecificMatcher(matcher) {
266
+ if (typeof matcher === "function") return false;
267
+ const compiled = compileMiddlewareConfig({ matcher });
268
+ return !matchesCompiledMiddlewareConfig(CATCH_ALL_PROBE, compiled, {}).matched;
269
+ }
270
+ __name(isPathSpecificMatcher, "isPathSpecificMatcher");
271
+ function pathSpecificConfigMiddlewareCovers(config, pathname) {
272
+ if (!hasFarmMiddlewareConfig(config)) return false;
273
+ const entries = Array.isArray(config) ? config : [config];
274
+ return entries.some((entry) => {
275
+ if (!entry.matcher) return false;
276
+ const matchers = (Array.isArray(entry.matcher) ? entry.matcher : [entry.matcher]).filter(
277
+ isPathSpecificMatcher
278
+ );
279
+ if (matchers.length === 0) return false;
280
+ const compiled = compileMiddlewareConfig({ matcher: matchers, exclude: entry.exclude });
281
+ return matchesCompiledMiddlewareConfig(pathname, compiled, {}).matched;
282
+ });
283
+ }
284
+ __name(pathSpecificConfigMiddlewareCovers, "pathSpecificConfigMiddlewareCovers");
285
+ function farmPathGuardCoversPage(options, pathname) {
286
+ return appMiddlewareMayHandlePath(
287
+ options.middlewareRoutes.filter((route) => route.path !== "/"),
288
+ pathname
289
+ ) || pathSpecificConfigMiddlewareCovers(options.config.middleware, pathname) || integrationMiddlewareMayHandlePath(options.config.integrations, pathname, CATCH_ALL_PROBE);
290
+ }
291
+ __name(farmPathGuardCoversPage, "farmPathGuardCoversPage");
292
+ function farmPathGuardCoversEndpoint(options, path, apiServerBasePath) {
293
+ return createFarmAPIMiddlewarePathnames(apiServerBasePath)(path).some(
294
+ (pathname) => farmPathGuardCoversPage(options, pathname)
295
+ );
296
+ }
297
+ __name(farmPathGuardCoversEndpoint, "farmPathGuardCoversEndpoint");
298
+
222
299
  // src/i18n/alternates.ts
223
300
  function renderFarmLocaleAlternateLinks(pathname, config, options = {}) {
224
301
  if (config.routing === "none") return "";
@@ -269,13 +346,19 @@ function isLateRedirectTarget(url) {
269
346
  }
270
347
  }
271
348
  __name(isLateRedirectTarget, "isLateRedirectTarget");
272
- function createLateRedirectRecovery(url) {
349
+ function createLateRedirectRecovery(url, nonce) {
273
350
  if (!isLateRedirectTarget(url)) return "";
274
- return `<script>window.location.replace(${serializeForInlineScript(url)})</script>`;
351
+ return stampFarmCspNonce(
352
+ `<script>window.location.replace(${serializeForInlineScript(url)})</script>`,
353
+ nonce
354
+ );
275
355
  }
276
356
  __name(createLateRedirectRecovery, "createLateRedirectRecovery");
277
- function createLateNotFoundRecovery(content) {
278
- return `<template id="${TEMPLATE_ID}">${content}</template><script>(function(){var t=document.getElementById("${TEMPLATE_ID}");var p=document.getElementById("${PAGE_CONTAINER_ID}");if(t&&p){p.replaceChildren(t.content.cloneNode(true));}if(t)t.remove();document.documentElement.dataset.farmLateNotFound="true";var m=document.createElement("meta");m.name="robots";m.content="noindex";document.head.appendChild(m);})();</script>`;
357
+ function createLateNotFoundRecovery(content, nonce) {
358
+ return `<template id="${TEMPLATE_ID}">${content}</template>` + stampFarmCspNonce(
359
+ `<script>(function(){var t=document.getElementById("${TEMPLATE_ID}");var p=document.getElementById("${PAGE_CONTAINER_ID}");if(t&&p){p.replaceChildren(t.content.cloneNode(true));}if(t)t.remove();document.documentElement.dataset.farmLateNotFound="true";var m=document.createElement("meta");m.name="robots";m.content="noindex";document.head.appendChild(m);})();</script>`,
360
+ nonce
361
+ );
279
362
  }
280
363
  __name(createLateNotFoundRecovery, "createLateNotFoundRecovery");
281
364
 
@@ -763,7 +846,9 @@ function createFarmThemeDocumentParts(input, basePath = "/", serverTheme) {
763
846
  const script = createFarmThemeBootstrapScript(config, hydrationTheme);
764
847
  return {
765
848
  attributes: ` data-theme="${initialTheme}"`,
766
- head: `<style id="${THEME_STYLE_ID}">:root[data-theme="light"]{color-scheme:light}:root[data-theme="dark"]{color-scheme:dark}</style><script id="${THEME_SCRIPT_ID}">${script}</script>`
849
+ head: stampFarmCspNonce(
850
+ `<style id="${THEME_STYLE_ID}">:root[data-theme="light"]{color-scheme:light}:root[data-theme="dark"]{color-scheme:dark}</style><script id="${THEME_SCRIPT_ID}">${script}</script>`
851
+ )
767
852
  };
768
853
  }
769
854
  __name(createFarmThemeDocumentParts, "createFarmThemeDocumentParts");
@@ -920,12 +1005,13 @@ function createFarmAppManifest(input, { full = false } = {}) {
920
1005
  packages: input.packages,
921
1006
  mcp: {
922
1007
  servers: _listFarmMCPCatalogs().map(({ server, tools, details }) => {
923
- const listed = full || details?.public === true;
1008
+ const open = details?.public === true && !input.guardCoversPath?.(server.path);
1009
+ const listed = full || open;
924
1010
  return {
925
1011
  name: server.name,
926
1012
  version: server.version,
927
1013
  path: server.path,
928
- authorization: details?.public === true ? "none" : "required",
1014
+ authorization: open ? "none" : "required",
929
1015
  resources: listed ? [...details?.resources ?? []] : [],
930
1016
  prompts: listed ? [...details?.prompts ?? []] : [],
931
1017
  tools: (listed ? tools : []).map((tool) => {
@@ -1078,6 +1164,11 @@ export {
1078
1164
  removeFarmDocumentTitles,
1079
1165
  ensureFarmDocumentMeta,
1080
1166
  composeFarmFullDocument,
1167
+ hasFarmMiddlewareConfig,
1168
+ configMiddlewareMayHandlePath,
1169
+ appMiddlewareMayHandlePath,
1170
+ farmPathGuardCoversPage,
1171
+ farmPathGuardCoversEndpoint,
1081
1172
  renderFarmLocaleAlternateLinks,
1082
1173
  createLateRedirectRecovery,
1083
1174
  createLateNotFoundRecovery,