@farm.js/core 0.1.35 → 0.1.36
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/{metadata-WGpBYcGn.d.mts → agent-mcp-BVExL8rZ.d.mts} +45 -2
- package/dist/agent-mcp-handler-LPJ2CADR.mjs +19 -0
- package/dist/agent-mcp-handler-SJAHFSPI.cjs +19 -0
- package/dist/{metadata-BnLDsUOS.d.ts → agent-mcp-luzfXK-P.d.ts} +45 -2
- package/dist/agent-runtime.cjs +5 -3
- package/dist/agent-runtime.d.mts +1 -1
- package/dist/agent-runtime.d.ts +1 -1
- package/dist/agent-runtime.mjs +4 -2
- package/dist/api/route-manager.cjs +6 -6
- package/dist/api/route-manager.d.mts +10 -4
- package/dist/api/route-manager.d.ts +10 -4
- package/dist/api/route-manager.mjs +5 -5
- package/dist/api/runtime.cjs +4 -4
- package/dist/api/runtime.d.mts +4 -62
- package/dist/api/runtime.d.ts +4 -62
- package/dist/api/runtime.mjs +3 -3
- package/dist/api.cjs +8 -8
- package/dist/api.d.mts +3 -3
- package/dist/api.d.ts +3 -3
- package/dist/api.mjs +7 -7
- package/dist/{app-D_j9AAVL.d.mts → app-BukwkFIu.d.mts} +17 -3
- package/dist/{app-BXB3JZYc.d.ts → app-Yfa2dsFy.d.ts} +17 -3
- package/dist/app-markdown.cjs +4 -4
- package/dist/app-markdown.d.mts +2 -2
- package/dist/app-markdown.d.ts +2 -2
- package/dist/app-markdown.mjs +3 -3
- package/dist/{chunk-4KU5Q7C2.mjs → chunk-276VJSM6.mjs} +221 -48
- package/dist/{chunk-PFQKNERH.cjs → chunk-2YTDKNH3.cjs} +364 -197
- package/dist/{chunk-UAORZ7QA.mjs → chunk-35GKZR22.mjs} +2 -2
- package/dist/{chunk-QAU5JD57.mjs → chunk-35WV46VL.mjs} +203 -36
- package/dist/{chunk-EFCQPQMG.cjs → chunk-42NHY7HW.cjs} +54 -4
- package/dist/{chunk-SOMHP6GF.mjs → chunk-4E5AEDKY.mjs} +2 -2
- package/dist/{chunk-UJD4PHYB.mjs → chunk-4E5WBPEG.mjs} +72 -354
- package/dist/{chunk-2G2NNLE2.mjs → chunk-4GLOOWKE.mjs} +4 -4
- package/dist/{chunk-62XKI4Z3.cjs → chunk-4NU4GGTC.cjs} +2 -2
- package/dist/{chunk-4JHOT46A.mjs → chunk-4WCZJQUO.mjs} +54 -4
- package/dist/chunk-4WQ6PGSJ.cjs +367 -0
- package/dist/{chunk-SMHH4VDG.mjs → chunk-4WVJLURN.mjs} +1 -1
- package/dist/chunk-6SJ2KJTA.mjs +314 -0
- package/dist/{chunk-IPXLADVO.cjs → chunk-ADEA7PN3.cjs} +122 -61
- package/dist/{chunk-CP6X4AEU.mjs → chunk-AJQTP4OO.mjs} +1 -1
- package/dist/{chunk-4MMGO7YW.cjs → chunk-AO6RYU5N.cjs} +31 -28
- package/dist/{chunk-GFHLGIYC.cjs → chunk-BO36SELV.cjs} +6 -6
- package/dist/{chunk-6TJOML4E.mjs → chunk-BPOF5U4N.mjs} +4 -4
- package/dist/{chunk-JHWOVJ3M.mjs → chunk-BUGNQIHC.mjs} +5 -0
- package/dist/{chunk-FTFYRMQQ.cjs → chunk-CBJJH36A.cjs} +50 -25
- package/dist/{chunk-7GLPRTTF.cjs → chunk-CGBDNNSM.cjs} +2 -2
- package/dist/chunk-CI6E3UOH.cjs +314 -0
- package/dist/{chunk-X6W5FFH6.cjs → chunk-D2BB47NB.cjs} +8 -8
- package/dist/chunk-DTSROJ5J.mjs +367 -0
- package/dist/{chunk-YC6V7PWE.cjs → chunk-DZ5ZVB2K.cjs} +1 -1
- package/dist/{chunk-DBNKI4NF.cjs → chunk-ECKF2BAM.cjs} +6 -2
- package/dist/{chunk-Q3VLETLE.mjs → chunk-EWET4D2Y.mjs} +1 -1
- package/dist/{chunk-HUMR6LSU.mjs → chunk-F5QO4FNE.mjs} +1 -1
- package/dist/{chunk-XBML5KMG.cjs → chunk-FO427P6I.cjs} +22 -12
- package/dist/{chunk-SAZVVAJH.mjs → chunk-GQRWBCWK.mjs} +8 -5
- package/dist/{chunk-F6Z3Y5KL.mjs → chunk-HOXTWRGB.mjs} +1 -1
- package/dist/{chunk-3BHT4WMP.cjs → chunk-JNUWCDTF.cjs} +6 -6
- package/dist/{chunk-73MC7ZL6.cjs → chunk-JZVADIOD.cjs} +2 -2
- package/dist/{chunk-OMVAU7NT.cjs → chunk-KIIMAWOJ.cjs} +11 -1
- package/dist/{chunk-43FMW62B.mjs → chunk-KMTGADN3.mjs} +28 -0
- package/dist/{chunk-6ETPZTJI.mjs → chunk-LSZAVSGY.mjs} +116 -55
- package/dist/{chunk-HMIJDL7S.mjs → chunk-MKYBIIAQ.mjs} +30 -5
- package/dist/{chunk-RU3M2FIK.cjs → chunk-MRMI32SN.cjs} +87 -369
- package/dist/{chunk-7L5V3KQO.cjs → chunk-N2NAS2AM.cjs} +2 -2
- package/dist/{chunk-ICUQICNC.cjs → chunk-NMHWYWDR.cjs} +654 -481
- package/dist/{chunk-G5RT7EXW.mjs → chunk-O6I6VWKK.mjs} +20 -5
- package/dist/{chunk-PDOCJ6RY.mjs → chunk-O6WAEAX3.mjs} +1 -1
- package/dist/{chunk-6DU6UFUE.mjs → chunk-OHLSEQ57.mjs} +16 -8
- package/dist/{chunk-3PXS2MHU.mjs → chunk-OO7GXVSR.mjs} +1 -1
- package/dist/chunk-PTZ2TVNE.cjs +178 -0
- package/dist/{chunk-6WCPV6G2.mjs → chunk-Q2KB32T4.mjs} +1 -1
- package/dist/{chunk-XCACDAZZ.cjs → chunk-S6VYG6XU.cjs} +23 -8
- package/dist/{chunk-VFQT3LAO.cjs → chunk-SDOTRX3V.cjs} +5 -5
- package/dist/{chunk-BMWDEBXO.cjs → chunk-SHLXACIO.cjs} +31 -3
- package/dist/{chunk-22LTEMGQ.mjs → chunk-T4OGRVNS.mjs} +13 -3
- package/dist/{chunk-ZXGAFZDO.cjs → chunk-T5OJPTVN.cjs} +2 -2
- package/dist/{chunk-VZJR7UTG.cjs → chunk-TE2G5ION.cjs} +2 -2
- package/dist/chunk-UH6QN5NL.mjs +178 -0
- package/dist/{chunk-F7JZENPF.cjs → chunk-UVW64BCB.cjs} +38 -30
- package/dist/{chunk-OKZUAXHF.mjs → chunk-VILIPRS6.mjs} +1 -1
- package/dist/{chunk-3UH7MRCP.cjs → chunk-VQLJWDVW.cjs} +13 -13
- package/dist/{chunk-VPTDD5XF.cjs → chunk-WBKEZXWE.cjs} +5 -0
- package/dist/{chunk-EJQT6KZN.cjs → chunk-WC5UV2HQ.cjs} +2 -2
- package/dist/{chunk-YULD7ICZ.mjs → chunk-WZ77PUAM.mjs} +1 -1
- package/dist/{chunk-C35ZBVRD.mjs → chunk-YWMZUGIS.mjs} +6 -2
- package/dist/{chunk-Y7RKTKYI.mjs → chunk-ZMMBIVQM.mjs} +10 -0
- package/dist/{chunk-ULAWS2PA.cjs → chunk-ZWM5KGAA.cjs} +6 -6
- package/dist/{client-plugins-CvIslxWi.d.mts → client-plugins-C3mK9Pol.d.mts} +98 -5
- package/dist/{client-plugins-HIyulDym.d.ts → client-plugins-r1mOtSC1.d.ts} +98 -5
- package/dist/client-plugins.d.mts +1 -1
- package/dist/client-plugins.d.ts +1 -1
- package/dist/client.d.mts +5 -5
- package/dist/client.d.ts +5 -5
- package/dist/config.d.mts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/{devtools-EE5RIBTH.mjs → devtools-ERIKFEXX.mjs} +9 -8
- package/dist/{devtools-EAUY43BS.cjs → devtools-JZJJY5CK.cjs} +10 -9
- package/dist/docs.cjs +12 -11
- package/dist/docs.d.mts +2 -2
- package/dist/docs.d.ts +2 -2
- package/dist/docs.mjs +11 -10
- package/dist/image/server.cjs +3 -3
- package/dist/image/server.mjs +2 -2
- package/dist/image/sharp.cjs +10 -10
- package/dist/image/sharp.mjs +2 -2
- package/dist/index.cjs +39 -35
- package/dist/index.d.mts +13 -13
- package/dist/index.d.ts +13 -13
- package/dist/index.mjs +38 -34
- package/dist/integrations.cjs +7 -3
- package/dist/integrations.d.mts +1 -1
- package/dist/integrations.d.ts +1 -1
- package/dist/integrations.mjs +6 -2
- package/dist/internal/app-markdown-runtime.cjs +3 -3
- package/dist/internal/app-markdown-runtime.d.mts +2 -2
- package/dist/internal/app-markdown-runtime.d.ts +2 -2
- package/dist/internal/app-markdown-runtime.mjs +2 -2
- package/dist/internal/build-runtime.cjs +27 -25
- package/dist/internal/build-runtime.d.mts +3 -3
- package/dist/internal/build-runtime.d.ts +3 -3
- package/dist/internal/build-runtime.mjs +26 -24
- package/dist/internal/cli-runtime.cjs +14 -13
- package/dist/internal/cli-runtime.mjs +13 -12
- package/dist/internal/client-error-overlay.cjs +4 -4
- package/dist/internal/client-error-overlay.mjs +1 -1
- package/dist/internal/compression-runtime.d.mts +1 -1
- package/dist/internal/compression-runtime.d.ts +1 -1
- package/dist/internal/config-runtime.cjs +10 -9
- package/dist/internal/config-runtime.d.mts +2 -2
- package/dist/internal/config-runtime.d.ts +2 -2
- package/dist/internal/config-runtime.mjs +9 -8
- package/dist/internal/isolated-boundary.cjs +2 -2
- package/dist/internal/isolated-boundary.d.mts +0 -1
- package/dist/internal/isolated-boundary.d.ts +0 -1
- package/dist/internal/isolated-boundary.mjs +1 -1
- package/dist/internal/metadata-image-runtime.cjs +3 -3
- package/dist/internal/metadata-image-runtime.mjs +2 -2
- package/dist/internal/product-telemetry-runtime.cjs +2 -2
- package/dist/internal/product-telemetry-runtime.mjs +1 -1
- package/dist/internal/production-runtime.cjs +23 -9
- package/dist/internal/production-runtime.d.mts +67 -27
- package/dist/internal/production-runtime.d.ts +67 -27
- package/dist/internal/production-runtime.mjs +26 -12
- package/dist/{layers-BRQF5ETU.mjs → layers-UTB43B7A.mjs} +1 -1
- package/dist/layers-VUWIOFEO.cjs +18 -0
- package/dist/markdown.cjs +1 -1
- package/dist/markdown.d.mts +1 -1
- package/dist/markdown.d.ts +1 -1
- package/dist/markdown.mjs +1 -1
- package/dist/middleware.cjs +6 -6
- package/dist/middleware.d.mts +3 -3
- package/dist/middleware.d.ts +3 -3
- package/dist/middleware.mjs +5 -5
- package/dist/navigation.d.mts +4 -4
- package/dist/navigation.d.ts +4 -4
- package/dist/{nitro-OVPLKPE2.cjs → nitro-7F65EZZS.cjs} +3 -3
- package/dist/{nitro-MXRDCXWZ.mjs → nitro-MPZJGPXK.mjs} +2 -2
- package/dist/plugin.cjs +23 -21
- package/dist/plugin.d.mts +1 -1
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.mjs +22 -20
- package/dist/{production-runtime-0sRnuYc-.d.mts → production-runtime-CCeVZXst.d.mts} +1 -1
- package/dist/{production-runtime-Crq6CJ-2.d.ts → production-runtime-DPnsggY3.d.ts} +1 -1
- package/dist/{render-plan-gs9GGPzw.d.mts → render-plan-BuGaPFe6.d.mts} +1 -1
- package/dist/{render-plan-8ozZh2Qv.d.ts → render-plan-Cw4f5E_R.d.ts} +1 -1
- package/dist/renderer/react/server.cjs +3 -3
- package/dist/renderer/react/server.mjs +1 -1
- package/dist/renderer-client.d.mts +3 -3
- package/dist/renderer-client.d.ts +3 -3
- package/dist/{request-B5G8rLBH.d.ts → request-Bkg-hERy.d.ts} +1 -1
- package/dist/{request-fkhiynXe.d.mts → request-CsGARcAw.d.mts} +1 -1
- package/dist/request.d.mts +2 -2
- package/dist/request.d.ts +2 -2
- package/dist/{route-rendering-lS5nUMua.d.ts → route-rendering-BUZMH_64.d.ts} +1 -1
- package/dist/{route-rendering-CLnS7AZj.d.mts → route-rendering-f11yh5dp.d.mts} +1 -1
- package/dist/{router-4iuiYnOW.d.ts → router-B8CR9GbD.d.ts} +1 -1
- package/dist/{router-ifU8Dui1.d.mts → router-Cp6yRE8A.d.mts} +1 -1
- package/dist/routes.d.mts +1 -1
- package/dist/routes.d.ts +1 -1
- package/dist/runtime-CAEv36S_.d.mts +69 -0
- package/dist/runtime-CQVsT330.d.ts +69 -0
- package/dist/server-action-security.cjs +3 -3
- package/dist/server-action-security.mjs +2 -2
- package/dist/server-fn.cjs +4 -4
- package/dist/server-fn.mjs +3 -3
- package/dist/server-plugins.d.mts +2 -2
- package/dist/server-plugins.d.ts +2 -2
- package/dist/server-query.cjs +5 -5
- package/dist/server-query.mjs +4 -4
- package/dist/server.cjs +42 -40
- package/dist/server.d.mts +7 -7
- package/dist/server.d.ts +7 -7
- package/dist/server.mjs +25 -23
- package/dist/{spa-router-DaJk5Re4.d.ts → spa-router-BuciWGCZ.d.ts} +2 -2
- package/dist/{spa-router-Bq7VCOwx.d.mts → spa-router-DwbqGkGj.d.mts} +2 -2
- package/dist/testing.cjs +8 -8
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.mjs +6 -6
- package/dist/{utils-XJn0c9bj.d.mts → utils-B9V0S_yL.d.mts} +1 -1
- package/dist/{utils-BXLmFsVR.d.ts → utils-CaoWKtYM.d.ts} +1 -1
- package/dist/version.cjs +2 -2
- package/dist/version.mjs +1 -1
- package/dist/vite.cjs +23 -21
- package/dist/vite.d.mts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.mjs +22 -20
- package/dist/workflows.cjs +3 -3
- package/dist/workflows.mjs +2 -2
- package/package.json +1 -1
- package/dist/layers-4PNE2HOY.cjs +0 -18
- package/dist/{chunk-2F2ER724.cjs → chunk-BPMATOP2.cjs} +2 -2
- package/dist/{chunk-IHNMMXHV.mjs → chunk-OTC5BDGO.mjs} +3 -3
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
isFarmMetadataNoIndex
|
|
3
|
+
} from "./chunk-DTSROJ5J.mjs";
|
|
4
|
+
import {
|
|
4
5
|
matchesFarmMarkdownRoutePattern
|
|
5
6
|
} from "./chunk-WWIKMBRN.mjs";
|
|
6
|
-
import {
|
|
7
|
-
FARM_INTERNAL_READ_HEADER
|
|
8
|
-
} from "./chunk-MVL2RAJW.mjs";
|
|
9
7
|
import {
|
|
10
8
|
_markFarmOwnedResponse,
|
|
11
9
|
_withFarmResponseHeaders
|
|
@@ -17,348 +15,6 @@ import {
|
|
|
17
15
|
__name
|
|
18
16
|
} from "./chunk-LPEX4YW6.mjs";
|
|
19
17
|
|
|
20
|
-
// src/llms-txt.ts
|
|
21
|
-
function resolveFarmLlmsTxtConfig(input) {
|
|
22
|
-
if (!input) return { enabled: false, include: [], exclude: [], full: false };
|
|
23
|
-
if (input === true) return { enabled: true, include: [], exclude: [], full: true };
|
|
24
|
-
if (typeof input !== "object") {
|
|
25
|
-
throw new TypeError("agent.llmsTxt must be true, false, or an options object.");
|
|
26
|
-
}
|
|
27
|
-
if (input.enabled === false) return { enabled: false, include: [], exclude: [], full: false };
|
|
28
|
-
for (const key of ["title", "summary", "details"]) {
|
|
29
|
-
if (input[key] !== void 0 && typeof input[key] !== "string") {
|
|
30
|
-
throw new TypeError(`agent.llmsTxt.${key} must be a string.`);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (input.full !== void 0 && typeof input.full !== "boolean") {
|
|
34
|
-
throw new TypeError("agent.llmsTxt.full must be a boolean.");
|
|
35
|
-
}
|
|
36
|
-
if (input.revalidate !== void 0 && (typeof input.revalidate !== "number" || !Number.isFinite(input.revalidate) || input.revalidate < 0)) {
|
|
37
|
-
throw new TypeError("agent.llmsTxt.revalidate must be a number of seconds.");
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
enabled: true,
|
|
41
|
-
...input.title ? { title: input.title } : {},
|
|
42
|
-
...input.summary ? { summary: input.summary } : {},
|
|
43
|
-
...input.details ? { details: input.details } : {},
|
|
44
|
-
include: resolveRoutePatterns(input.include, "include"),
|
|
45
|
-
exclude: resolveRoutePatterns(input.exclude, "exclude"),
|
|
46
|
-
full: input.full !== false,
|
|
47
|
-
...input.revalidate !== void 0 ? { revalidate: input.revalidate } : {}
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
__name(resolveFarmLlmsTxtConfig, "resolveFarmLlmsTxtConfig");
|
|
51
|
-
function resolveRoutePatterns(value, key) {
|
|
52
|
-
if (value === void 0) return [];
|
|
53
|
-
if (!Array.isArray(value)) {
|
|
54
|
-
throw new TypeError(`agent.llmsTxt.${key} must be an array of route patterns.`);
|
|
55
|
-
}
|
|
56
|
-
return value.map((pattern, index) => {
|
|
57
|
-
if (typeof pattern !== "string" || !pattern.startsWith("/")) {
|
|
58
|
-
throw new TypeError(
|
|
59
|
-
`agent.llmsTxt.${key}[${index}] must be a route pattern starting with "/", such as "/docs/[...slug]".`
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
return pattern;
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
__name(resolveRoutePatterns, "resolveRoutePatterns");
|
|
66
|
-
function collectFarmLlmsTxtPages(sources, options) {
|
|
67
|
-
const include = options.include ?? [];
|
|
68
|
-
const exclude = options.exclude ?? [];
|
|
69
|
-
const pages = /* @__PURE__ */ new Map();
|
|
70
|
-
for (const source of sources) {
|
|
71
|
-
const path = source.pattern;
|
|
72
|
-
if (path.includes("[") || pages.has(path)) continue;
|
|
73
|
-
if (include.length && !include.some((pattern) => matchesFarmMarkdownRoutePattern(pattern, path))) {
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
if (exclude.some((pattern) => matchesFarmMarkdownRoutePattern(pattern, path))) continue;
|
|
77
|
-
if (isMetadataNoIndex(source.metadata)) continue;
|
|
78
|
-
const target = isFarmMarkdownMirrorExposed(options.markdown, path) ? getFarmMarkdownMirrorPath(path) : path;
|
|
79
|
-
const description = readMetadataString(source.metadata, "description");
|
|
80
|
-
pages.set(path, {
|
|
81
|
-
path,
|
|
82
|
-
title: readMetadataTitle(source.metadata) ?? fallbackPageTitle(path),
|
|
83
|
-
url: `${options.origin}${applyFarmBasePath(target, options.basePath)}`,
|
|
84
|
-
...description ? { description } : {}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
return [...pages.values()].sort((left, right) => left.path.localeCompare(right.path));
|
|
88
|
-
}
|
|
89
|
-
__name(collectFarmLlmsTxtPages, "collectFarmLlmsTxtPages");
|
|
90
|
-
function isMetadataNoIndex(metadata) {
|
|
91
|
-
if (!metadata || typeof metadata !== "object") return false;
|
|
92
|
-
const robots = metadata.robots;
|
|
93
|
-
if (typeof robots === "string") {
|
|
94
|
-
return robots.split(",").map((directive) => directive.trim().toLowerCase()).some((directive) => directive === "noindex" || directive === "none");
|
|
95
|
-
}
|
|
96
|
-
return Boolean(
|
|
97
|
-
robots && typeof robots === "object" && robots.index === false
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
__name(isMetadataNoIndex, "isMetadataNoIndex");
|
|
101
|
-
function createFarmDefaultLlmsTxt(options) {
|
|
102
|
-
const { config, pages } = options;
|
|
103
|
-
const mcp = options.mcp ?? [];
|
|
104
|
-
const summary = config.summary ?? readMetadataString(options.rootMetadata, "description");
|
|
105
|
-
return {
|
|
106
|
-
title: config.title ?? readMetadataTitle(options.rootMetadata) ?? pages.find((page) => page.path === "/")?.title ?? new URL(options.origin).host,
|
|
107
|
-
...summary ? { summary } : {},
|
|
108
|
-
...config.details ? { details: config.details } : {},
|
|
109
|
-
sections: [
|
|
110
|
-
...pages.length ? [
|
|
111
|
-
{
|
|
112
|
-
title: "Pages",
|
|
113
|
-
links: pages.map(({ title, url, description }) => ({
|
|
114
|
-
title,
|
|
115
|
-
url,
|
|
116
|
-
...description ? { description } : {}
|
|
117
|
-
}))
|
|
118
|
-
}
|
|
119
|
-
] : [],
|
|
120
|
-
...mcp.length ? [{ title: "MCP", links: mcp }] : []
|
|
121
|
-
]
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
__name(createFarmDefaultLlmsTxt, "createFarmDefaultLlmsTxt");
|
|
125
|
-
function serializeFarmLlmsTxt(value) {
|
|
126
|
-
if (typeof value === "string") {
|
|
127
|
-
if (!value.trim()) throw new TypeError("llms.ts returned an empty llms.txt");
|
|
128
|
-
return value.endsWith("\n") ? value : `${value}
|
|
129
|
-
`;
|
|
130
|
-
}
|
|
131
|
-
if (!isRecord(value)) {
|
|
132
|
-
throw new TypeError("llms.ts must return llms.txt text, an llms.txt object, or a Response");
|
|
133
|
-
}
|
|
134
|
-
const title = requireText(value.title, "llms.ts must return a non-empty title");
|
|
135
|
-
const summary = optionalText(value.summary, "llms.ts summary must be a string");
|
|
136
|
-
const details = optionalText(value.details, "llms.ts details must be a string");
|
|
137
|
-
if (value.sections !== void 0 && !Array.isArray(value.sections)) {
|
|
138
|
-
throw new TypeError("llms.ts sections must be an array");
|
|
139
|
-
}
|
|
140
|
-
const blocks = [`# ${toSingleLine(title)}`];
|
|
141
|
-
if (summary?.trim()) blocks.push(`> ${toSingleLine(summary)}`);
|
|
142
|
-
if (details?.trim()) blocks.push(details.trim());
|
|
143
|
-
for (const [sectionIndex, section] of (value.sections ?? []).entries()) {
|
|
144
|
-
if (!isRecord(section)) {
|
|
145
|
-
throw new TypeError(`llms.ts section ${sectionIndex} must be an object`);
|
|
146
|
-
}
|
|
147
|
-
const sectionTitle = requireText(
|
|
148
|
-
section.title,
|
|
149
|
-
`llms.ts section ${sectionIndex} must include a non-empty title`
|
|
150
|
-
);
|
|
151
|
-
if (!Array.isArray(section.links)) {
|
|
152
|
-
throw new TypeError(`llms.ts section "${sectionTitle}" must include a links array`);
|
|
153
|
-
}
|
|
154
|
-
const links = section.links.map((link, linkIndex) => {
|
|
155
|
-
const where = `llms.ts section "${sectionTitle}" link ${linkIndex}`;
|
|
156
|
-
if (!isRecord(link)) throw new TypeError(`${where} must be an object`);
|
|
157
|
-
const linkTitle = requireText(link.title, `${where} must include a non-empty title`);
|
|
158
|
-
const url = requireText(link.url, `${where} must include a non-empty url`);
|
|
159
|
-
const description = optionalText(link.description, `${where} description must be a string`);
|
|
160
|
-
return `- [${escapeLinkText(linkTitle)}](${escapeLinkUrl(url)})${description?.trim() ? `: ${toSingleLine(description)}` : ""}`;
|
|
161
|
-
});
|
|
162
|
-
blocks.push(`## ${toSingleLine(sectionTitle)}`, links.join("\n"));
|
|
163
|
-
}
|
|
164
|
-
return `${blocks.filter(Boolean).join("\n\n")}
|
|
165
|
-
`;
|
|
166
|
-
}
|
|
167
|
-
__name(serializeFarmLlmsTxt, "serializeFarmLlmsTxt");
|
|
168
|
-
function createFarmLlmsMarkdownReader(fetchMarkdown) {
|
|
169
|
-
return async (url) => {
|
|
170
|
-
try {
|
|
171
|
-
const response = await fetchMarkdown(
|
|
172
|
-
new Request(url, {
|
|
173
|
-
headers: { accept: "text/markdown", [FARM_INTERNAL_READ_HEADER]: "llms-full" }
|
|
174
|
-
})
|
|
175
|
-
);
|
|
176
|
-
const type = response.headers.get("content-type") ?? "";
|
|
177
|
-
if (!response.ok || !type.toLowerCase().startsWith("text/markdown")) {
|
|
178
|
-
await response.body?.cancel();
|
|
179
|
-
return null;
|
|
180
|
-
}
|
|
181
|
-
return await response.text();
|
|
182
|
-
} catch {
|
|
183
|
-
return null;
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
__name(createFarmLlmsMarkdownReader, "createFarmLlmsMarkdownReader");
|
|
188
|
-
var FARM_LLMS_FULL_PAGE_TIMEOUT_MS = 3e4;
|
|
189
|
-
var LLMS_PAGE_TIMED_OUT = /* @__PURE__ */ Symbol("farm.llms.pageTimedOut");
|
|
190
|
-
async function renderFarmLlmsFullTxt(value, options) {
|
|
191
|
-
const index = serializeFarmLlmsTxt(value);
|
|
192
|
-
if (typeof value === "string") return index;
|
|
193
|
-
const llms = value;
|
|
194
|
-
const links = [];
|
|
195
|
-
const seen = /* @__PURE__ */ new Set();
|
|
196
|
-
for (const section of llms.sections ?? []) {
|
|
197
|
-
for (const link of section.links) {
|
|
198
|
-
if (seen.has(link.url)) continue;
|
|
199
|
-
seen.add(link.url);
|
|
200
|
-
links.push(link);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
const pageTimeout = options.pageTimeout ?? FARM_LLMS_FULL_PAGE_TIMEOUT_MS;
|
|
204
|
-
const readWithinTimeout = /* @__PURE__ */ __name(async (url) => {
|
|
205
|
-
let timer;
|
|
206
|
-
const timedOut = new Promise((resolve) => {
|
|
207
|
-
timer = setTimeout(resolve, pageTimeout, LLMS_PAGE_TIMED_OUT);
|
|
208
|
-
});
|
|
209
|
-
try {
|
|
210
|
-
const content = await Promise.race([options.readMarkdown(url), timedOut]);
|
|
211
|
-
if (content !== LLMS_PAGE_TIMED_OUT) return content;
|
|
212
|
-
options.onIncomplete?.();
|
|
213
|
-
return null;
|
|
214
|
-
} finally {
|
|
215
|
-
clearTimeout(timer);
|
|
216
|
-
}
|
|
217
|
-
}, "readWithinTimeout");
|
|
218
|
-
const contents = await mapWithConcurrency(
|
|
219
|
-
links,
|
|
220
|
-
options.concurrency ?? 4,
|
|
221
|
-
(link) => shouldInlineLlmsLink(link.url, options.origin) ? readWithinTimeout(link.url) : null
|
|
222
|
-
);
|
|
223
|
-
const blocks = [`# ${toSingleLine(llms.title)}`];
|
|
224
|
-
if (llms.summary?.trim()) blocks.push(`> ${toSingleLine(llms.summary)}`);
|
|
225
|
-
if (llms.details?.trim()) blocks.push(llms.details.trim());
|
|
226
|
-
const pages = links.map((link, index2) => {
|
|
227
|
-
const parts = [`## ${toSingleLine(link.title)}`, `URL: ${escapeLinkUrl(link.url)}`];
|
|
228
|
-
if (link.description?.trim()) parts.push(toSingleLine(link.description));
|
|
229
|
-
const content = stripFrontmatter(contents[index2] ?? "").trim();
|
|
230
|
-
if (content) parts.push(content);
|
|
231
|
-
return parts.join("\n\n");
|
|
232
|
-
});
|
|
233
|
-
if (pages.length) blocks.push(pages.join("\n\n---\n\n"));
|
|
234
|
-
return `${blocks.join("\n\n")}
|
|
235
|
-
`;
|
|
236
|
-
}
|
|
237
|
-
__name(renderFarmLlmsFullTxt, "renderFarmLlmsFullTxt");
|
|
238
|
-
function createFarmLlmsFullRenderer(options = {}) {
|
|
239
|
-
const now = options.now ?? Date.now;
|
|
240
|
-
const ttl = (options.revalidate ?? 0) * 1e3;
|
|
241
|
-
const maxEntries = options.maxEntries ?? 16;
|
|
242
|
-
const entries = /* @__PURE__ */ new Map();
|
|
243
|
-
let queue = Promise.resolve();
|
|
244
|
-
const settle = /* @__PURE__ */ __name((body, complete, onSettled) => onSettled ? body.then((value) => (onSettled(complete()), value)) : body, "settle");
|
|
245
|
-
return (origin, render, onSettled) => {
|
|
246
|
-
const entry = entries.get(origin);
|
|
247
|
-
if (entry && entry.expires > now()) return settle(entry.body, entry.complete, onSettled);
|
|
248
|
-
entries.delete(origin);
|
|
249
|
-
let complete = true;
|
|
250
|
-
const body = queue.then(
|
|
251
|
-
() => render({
|
|
252
|
-
incomplete: /* @__PURE__ */ __name(() => {
|
|
253
|
-
complete = false;
|
|
254
|
-
}, "incomplete")
|
|
255
|
-
})
|
|
256
|
-
);
|
|
257
|
-
queue = body.catch(() => {
|
|
258
|
-
});
|
|
259
|
-
const pending = { body, expires: Number.POSITIVE_INFINITY, complete: /* @__PURE__ */ __name(() => complete, "complete") };
|
|
260
|
-
entries.set(origin, pending);
|
|
261
|
-
if (entries.size > maxEntries) entries.delete(entries.keys().next().value);
|
|
262
|
-
body.then(
|
|
263
|
-
() => {
|
|
264
|
-
if (entries.get(origin) !== pending) return;
|
|
265
|
-
if (ttl > 0 && complete) pending.expires = now() + ttl;
|
|
266
|
-
else entries.delete(origin);
|
|
267
|
-
},
|
|
268
|
-
() => {
|
|
269
|
-
if (entries.get(origin) === pending) entries.delete(origin);
|
|
270
|
-
}
|
|
271
|
-
);
|
|
272
|
-
return settle(body, pending.complete, onSettled);
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
__name(createFarmLlmsFullRenderer, "createFarmLlmsFullRenderer");
|
|
276
|
-
function stripFrontmatter(markdown) {
|
|
277
|
-
const match = /^\uFEFF?---\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$)/.exec(markdown);
|
|
278
|
-
return match ? markdown.slice(match[0].length) : markdown;
|
|
279
|
-
}
|
|
280
|
-
__name(stripFrontmatter, "stripFrontmatter");
|
|
281
|
-
function shouldInlineLlmsLink(url, origin) {
|
|
282
|
-
let target;
|
|
283
|
-
try {
|
|
284
|
-
target = new URL(url, origin);
|
|
285
|
-
} catch {
|
|
286
|
-
return false;
|
|
287
|
-
}
|
|
288
|
-
return target.origin === origin && !/\/llms(-full)?\.txt$/.test(target.pathname);
|
|
289
|
-
}
|
|
290
|
-
__name(shouldInlineLlmsLink, "shouldInlineLlmsLink");
|
|
291
|
-
async function mapWithConcurrency(items, limit, run) {
|
|
292
|
-
const results = [];
|
|
293
|
-
let next = 0;
|
|
294
|
-
const worker = /* @__PURE__ */ __name(async () => {
|
|
295
|
-
while (next < items.length) {
|
|
296
|
-
const index = next++;
|
|
297
|
-
results[index] = await run(items[index]);
|
|
298
|
-
}
|
|
299
|
-
}, "worker");
|
|
300
|
-
await Promise.all(Array.from({ length: Math.min(Math.max(limit, 1), items.length) }, worker));
|
|
301
|
-
return results;
|
|
302
|
-
}
|
|
303
|
-
__name(mapWithConcurrency, "mapWithConcurrency");
|
|
304
|
-
function readMetadataTitle(metadata) {
|
|
305
|
-
if (!isRecord(metadata)) return void 0;
|
|
306
|
-
const { title } = metadata;
|
|
307
|
-
if (typeof title === "string") return title.trim() || void 0;
|
|
308
|
-
if (isRecord(title)) {
|
|
309
|
-
for (const key of ["absolute", "default"]) {
|
|
310
|
-
const value = title[key];
|
|
311
|
-
if (typeof value === "string" && value.trim()) return value.trim();
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
return void 0;
|
|
315
|
-
}
|
|
316
|
-
__name(readMetadataTitle, "readMetadataTitle");
|
|
317
|
-
function readMetadataString(metadata, key) {
|
|
318
|
-
if (!isRecord(metadata)) return void 0;
|
|
319
|
-
const value = metadata[key];
|
|
320
|
-
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
321
|
-
}
|
|
322
|
-
__name(readMetadataString, "readMetadataString");
|
|
323
|
-
function fallbackPageTitle(path) {
|
|
324
|
-
if (path === "/") return "Home";
|
|
325
|
-
const segments = path.split("/").filter(Boolean);
|
|
326
|
-
const segment = segments[segments.length - 1] ?? path;
|
|
327
|
-
const words = segment.replace(/[-_]+/g, " ").trim();
|
|
328
|
-
return words ? words[0].toUpperCase() + words.slice(1) : path;
|
|
329
|
-
}
|
|
330
|
-
__name(fallbackPageTitle, "fallbackPageTitle");
|
|
331
|
-
function toSingleLine(value) {
|
|
332
|
-
return value.replace(/\s+/g, " ").trim();
|
|
333
|
-
}
|
|
334
|
-
__name(toSingleLine, "toSingleLine");
|
|
335
|
-
function escapeLinkText(value) {
|
|
336
|
-
return toSingleLine(value).replace(/[\\[\]]/g, "\\$&");
|
|
337
|
-
}
|
|
338
|
-
__name(escapeLinkText, "escapeLinkText");
|
|
339
|
-
function escapeLinkUrl(value) {
|
|
340
|
-
return value.trim().replace(
|
|
341
|
-
/[\s()<>]/g,
|
|
342
|
-
(character) => character === "(" ? "%28" : character === ")" ? "%29" : encodeURIComponent(character)
|
|
343
|
-
);
|
|
344
|
-
}
|
|
345
|
-
__name(escapeLinkUrl, "escapeLinkUrl");
|
|
346
|
-
function requireText(value, message) {
|
|
347
|
-
if (typeof value !== "string" || !value.trim()) throw new TypeError(message);
|
|
348
|
-
return value;
|
|
349
|
-
}
|
|
350
|
-
__name(requireText, "requireText");
|
|
351
|
-
function optionalText(value, message) {
|
|
352
|
-
if (value === void 0) return void 0;
|
|
353
|
-
if (typeof value !== "string") throw new TypeError(message);
|
|
354
|
-
return value;
|
|
355
|
-
}
|
|
356
|
-
__name(optionalText, "optionalText");
|
|
357
|
-
function isRecord(value) {
|
|
358
|
-
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
359
|
-
}
|
|
360
|
-
__name(isRecord, "isRecord");
|
|
361
|
-
|
|
362
18
|
// src/agent-crawlers.ts
|
|
363
19
|
var FARM_AI_CRAWLERS = {
|
|
364
20
|
search: [
|
|
@@ -489,6 +145,73 @@ function resolveDefaultSitemap(options) {
|
|
|
489
145
|
}
|
|
490
146
|
__name(resolveDefaultSitemap, "resolveDefaultSitemap");
|
|
491
147
|
|
|
148
|
+
// src/agent-sitemap.ts
|
|
149
|
+
function resolveFarmAgentSitemap(input) {
|
|
150
|
+
if (!input) return { enabled: false, include: [], exclude: [] };
|
|
151
|
+
if (input === true) return { enabled: true, include: [], exclude: [] };
|
|
152
|
+
if (typeof input !== "object") {
|
|
153
|
+
throw new TypeError("agent.sitemap must be true, false, or an options object.");
|
|
154
|
+
}
|
|
155
|
+
if (input.enabled === false) return { enabled: false, include: [], exclude: [] };
|
|
156
|
+
return {
|
|
157
|
+
enabled: true,
|
|
158
|
+
include: resolveRoutePatterns(input.include, "include"),
|
|
159
|
+
exclude: resolveRoutePatterns(input.exclude, "exclude")
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
__name(resolveFarmAgentSitemap, "resolveFarmAgentSitemap");
|
|
163
|
+
function resolveRoutePatterns(value, key) {
|
|
164
|
+
if (value === void 0) return [];
|
|
165
|
+
if (!Array.isArray(value)) {
|
|
166
|
+
throw new TypeError(`agent.sitemap.${key} must be an array of route patterns.`);
|
|
167
|
+
}
|
|
168
|
+
return value.map((pattern, index) => {
|
|
169
|
+
if (typeof pattern !== "string" || !pattern.startsWith("/")) {
|
|
170
|
+
throw new TypeError(
|
|
171
|
+
`agent.sitemap.${key}[${index}] must be a route pattern starting with "/", such as "/admin/[...path]".`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
return pattern;
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
__name(resolveRoutePatterns, "resolveRoutePatterns");
|
|
178
|
+
function createFarmDefaultSitemap(sources, options) {
|
|
179
|
+
const { include, exclude } = options.config;
|
|
180
|
+
const base = toAbsoluteHttpOrigin(options.metadataBase) ?? options.origin;
|
|
181
|
+
const entries = /* @__PURE__ */ new Map();
|
|
182
|
+
for (const source of sources) {
|
|
183
|
+
const path = source.pattern;
|
|
184
|
+
if (path.includes("[") || path.includes("(") || entries.has(path)) continue;
|
|
185
|
+
if (include.length && !include.some((pattern) => matchesFarmMarkdownRoutePattern(pattern, path))) {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (exclude.some((pattern) => matchesFarmMarkdownRoutePattern(pattern, path))) continue;
|
|
189
|
+
const module = isRecord(source.module) ? source.module : void 0;
|
|
190
|
+
if (isFarmMetadataNoIndex(module?.metadata)) continue;
|
|
191
|
+
if (module?.__farmRouteGuard) continue;
|
|
192
|
+
entries.set(path, {
|
|
193
|
+
url: new URL(applyFarmBasePath(path, options.basePath), base).href,
|
|
194
|
+
...source.lastModified ? { lastModified: source.lastModified } : {}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
return [...entries.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([, entry]) => entry);
|
|
198
|
+
}
|
|
199
|
+
__name(createFarmDefaultSitemap, "createFarmDefaultSitemap");
|
|
200
|
+
function toAbsoluteHttpOrigin(value) {
|
|
201
|
+
if (typeof value !== "string" && !(value instanceof URL)) return void 0;
|
|
202
|
+
try {
|
|
203
|
+
const url = new URL(String(value));
|
|
204
|
+
return url.protocol === "https:" || url.protocol === "http:" ? url.origin : void 0;
|
|
205
|
+
} catch {
|
|
206
|
+
return void 0;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
__name(toAbsoluteHttpOrigin, "toAbsoluteHttpOrigin");
|
|
210
|
+
function isRecord(value) {
|
|
211
|
+
return Boolean(value && typeof value === "object");
|
|
212
|
+
}
|
|
213
|
+
__name(isRecord, "isRecord");
|
|
214
|
+
|
|
492
215
|
// src/security.ts
|
|
493
216
|
function resolveFarmSecurityConfig(input) {
|
|
494
217
|
if (input === void 0) return { csp: false };
|
|
@@ -1411,15 +1134,10 @@ function applyFarmPreviewRobotsTag(response) {
|
|
|
1411
1134
|
__name(applyFarmPreviewRobotsTag, "applyFarmPreviewRobotsTag");
|
|
1412
1135
|
|
|
1413
1136
|
export {
|
|
1414
|
-
resolveFarmLlmsTxtConfig,
|
|
1415
|
-
collectFarmLlmsTxtPages,
|
|
1416
|
-
createFarmDefaultLlmsTxt,
|
|
1417
|
-
serializeFarmLlmsTxt,
|
|
1418
|
-
createFarmLlmsMarkdownReader,
|
|
1419
|
-
renderFarmLlmsFullTxt,
|
|
1420
|
-
createFarmLlmsFullRenderer,
|
|
1421
1137
|
resolveFarmAgentCrawlers,
|
|
1422
1138
|
createFarmAgentRobots,
|
|
1139
|
+
resolveFarmAgentSitemap,
|
|
1140
|
+
createFarmDefaultSitemap,
|
|
1423
1141
|
resolveFarmSecurityConfig,
|
|
1424
1142
|
getFarmSecurityHeader,
|
|
1425
1143
|
createFarmCspNonce,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
APITypeGenerator
|
|
3
|
+
} from "./chunk-F3VB7ONA.mjs";
|
|
1
4
|
import {
|
|
2
5
|
readSchemaTables
|
|
3
6
|
} from "./chunk-HALDNTIV.mjs";
|
|
4
7
|
import {
|
|
5
8
|
resolveSchemaModels
|
|
6
9
|
} from "./chunk-ZMSZZXOR.mjs";
|
|
7
|
-
import {
|
|
8
|
-
APITypeGenerator
|
|
9
|
-
} from "./chunk-F3VB7ONA.mjs";
|
|
10
10
|
import {
|
|
11
11
|
mergeRouteRenderingDirectiveConfig
|
|
12
12
|
} from "./chunk-DAO7JGTS.mjs";
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
import {
|
|
21
21
|
getFarmAppDirectories,
|
|
22
22
|
getFarmSourceRoots
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-BUGNQIHC.mjs";
|
|
24
24
|
import {
|
|
25
25
|
resolveFarmComponentExtensions
|
|
26
26
|
} from "./chunk-DAATZTKJ.mjs";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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
|
-
var
|
|
3
|
+
var _chunkZWM5KGAAcjs = require('./chunk-ZWM5KGAA.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunkHLJ6MBUZcjs = require('./chunk-HLJ6MBUZ.cjs');
|
|
@@ -415,7 +415,7 @@ function farmMiddlewarePlugin(options = {}) {
|
|
|
415
415
|
mode: server.config.mode === "production" ? "production" : "development",
|
|
416
416
|
basePath: _nullishCoalesce(options.basePath, () => ( "/"))
|
|
417
417
|
});
|
|
418
|
-
manager = new (0,
|
|
418
|
+
manager = new (0, _chunkZWM5KGAAcjs.MiddlewareManager)(
|
|
419
419
|
getMiddlewareAppDirectory(server.config.root, srcDir),
|
|
420
420
|
server,
|
|
421
421
|
options.middleware,
|
|
@@ -112,6 +112,55 @@ function isFarmMarkdownPublicSourceResponse(response) {
|
|
|
112
112
|
return publicSourceResponses.has(response);
|
|
113
113
|
}
|
|
114
114
|
__name(isFarmMarkdownPublicSourceResponse, "isFarmMarkdownPublicSourceResponse");
|
|
115
|
+
var ANONYMOUS_REQUEST_HEADERS = /* @__PURE__ */ new Set([
|
|
116
|
+
"accept",
|
|
117
|
+
"accept-encoding",
|
|
118
|
+
"accept-language",
|
|
119
|
+
"cache-control",
|
|
120
|
+
"connection",
|
|
121
|
+
"dnt",
|
|
122
|
+
"forwarded",
|
|
123
|
+
"host",
|
|
124
|
+
"if-match",
|
|
125
|
+
"if-modified-since",
|
|
126
|
+
"if-none-match",
|
|
127
|
+
"if-range",
|
|
128
|
+
"if-unmodified-since",
|
|
129
|
+
"keep-alive",
|
|
130
|
+
"origin",
|
|
131
|
+
"pragma",
|
|
132
|
+
"priority",
|
|
133
|
+
"purpose",
|
|
134
|
+
"range",
|
|
135
|
+
"referer",
|
|
136
|
+
"save-data",
|
|
137
|
+
"sec-gpc",
|
|
138
|
+
"sec-purpose",
|
|
139
|
+
"te",
|
|
140
|
+
"traceparent",
|
|
141
|
+
"tracestate",
|
|
142
|
+
"upgrade-insecure-requests",
|
|
143
|
+
"user-agent",
|
|
144
|
+
"via",
|
|
145
|
+
"x-forwarded-for",
|
|
146
|
+
"x-forwarded-host",
|
|
147
|
+
"x-forwarded-port",
|
|
148
|
+
"x-forwarded-proto",
|
|
149
|
+
"x-real-ip",
|
|
150
|
+
"x-request-id"
|
|
151
|
+
]);
|
|
152
|
+
function isAnonymousRequestHeader(name) {
|
|
153
|
+
const lower = name.toLowerCase();
|
|
154
|
+
return ANONYMOUS_REQUEST_HEADERS.has(lower) || lower.startsWith("sec-fetch-") || lower.startsWith("sec-ch-");
|
|
155
|
+
}
|
|
156
|
+
__name(isAnonymousRequestHeader, "isAnonymousRequestHeader");
|
|
157
|
+
function hasOnlyAnonymousHeaders(headers) {
|
|
158
|
+
for (const name of headers.keys()) {
|
|
159
|
+
if (!isAnonymousRequestHeader(name)) return false;
|
|
160
|
+
}
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
__name(hasOnlyAnonymousHeaders, "hasOnlyAnonymousHeaders");
|
|
115
164
|
async function createFarmMarkdownSourceResponse(options) {
|
|
116
165
|
if (options.request.method !== "GET" && options.request.method !== "HEAD") {
|
|
117
166
|
return null;
|
|
@@ -129,13 +178,14 @@ async function createFarmMarkdownSourceResponse(options) {
|
|
|
129
178
|
if (!source) {
|
|
130
179
|
return null;
|
|
131
180
|
}
|
|
132
|
-
const anonymous =
|
|
181
|
+
const anonymous = hasOnlyAnonymousHeaders(options.request.headers);
|
|
133
182
|
if (options.renderPage && (hasMarkdownExtension || !anonymous)) {
|
|
134
183
|
const publicUrl = new URL(url);
|
|
135
184
|
publicUrl.pathname = targetPathname;
|
|
136
|
-
const publicHeaders = new Headers(
|
|
137
|
-
|
|
138
|
-
|
|
185
|
+
const publicHeaders = new Headers();
|
|
186
|
+
for (const [name, value] of options.request.headers) {
|
|
187
|
+
if (isAnonymousRequestHeader(name)) publicHeaders.append(name, value);
|
|
188
|
+
}
|
|
139
189
|
publicHeaders.set("accept", "text/markdown");
|
|
140
190
|
const publicResponse = await options.renderPage(
|
|
141
191
|
new Request(publicUrl, {
|