@farm.js/core 0.1.25 → 0.1.27
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/agent-runtime.d.mts +8 -10
- package/dist/agent-runtime.d.ts +8 -10
- package/dist/api/client.cjs +3 -3
- package/dist/api/client.d.mts +4 -5
- package/dist/api/client.d.ts +4 -5
- package/dist/api/client.mjs +2 -2
- package/dist/api/route-manager.cjs +6 -5
- package/dist/api/route-manager.d.mts +7 -9
- package/dist/api/route-manager.d.ts +7 -9
- package/dist/api/route-manager.mjs +5 -4
- package/dist/api/runtime.cjs +10 -4
- package/dist/api/runtime.d.mts +35 -3
- package/dist/api/runtime.d.ts +35 -3
- package/dist/api/runtime.mjs +9 -3
- package/dist/{api-client-Cx54IR5g.d.mts → api-client-BjMmY8OD.d.mts} +2 -3
- package/dist/{api-client-DykpaKcY.d.ts → api-client-CyFtZFJ4.d.ts} +2 -3
- package/dist/api.cjs +9 -8
- package/dist/api.d.mts +9 -11
- package/dist/api.d.ts +9 -11
- package/dist/api.mjs +9 -8
- package/dist/{app-ZuWrAMc_.d.mts → app-BfzZdjgX.d.mts} +3 -4
- package/dist/{app-BF-ctoxh.d.ts → app-CXK7Prrt.d.ts} +3 -4
- package/dist/app-markdown.cjs +12 -4
- package/dist/app-markdown.d.mts +9 -11
- package/dist/app-markdown.d.ts +9 -11
- package/dist/app-markdown.mjs +11 -3
- package/dist/{chunk-2BIJGZR3.mjs → chunk-3PTVHMLD.mjs} +1 -1
- package/dist/{chunk-XME4TCLB.mjs → chunk-4FHDV7VM.mjs} +2 -2
- package/dist/{chunk-KLSSO6YD.mjs → chunk-4UNKCNSL.mjs} +1 -1
- package/dist/chunk-5MKEDGLD.cjs +53 -0
- package/dist/{chunk-E3RDL2DA.cjs → chunk-DQMTHWPI.cjs} +61 -31
- package/dist/{chunk-TTVHACQV.cjs → chunk-FOT7LZEO.cjs} +1 -1
- package/dist/{chunk-2KI3CL3N.mjs → chunk-FPW4W3VW.mjs} +1 -1
- package/dist/{chunk-6K4SPQWL.cjs → chunk-HF5SIACK.cjs} +3 -3
- package/dist/{chunk-T2OPSH6S.mjs → chunk-HG237IEY.mjs} +12 -5
- package/dist/chunk-J63ZH5OQ.cjs +62 -0
- package/dist/{chunk-BD2U4ZL6.cjs → chunk-JQGDQO2I.cjs} +8 -8
- package/dist/{chunk-RR6UGYUT.mjs → chunk-JT25KHDI.mjs} +39 -9
- package/dist/{chunk-O5DVPF3R.cjs → chunk-KAERLFD3.cjs} +16 -11
- package/dist/{chunk-H7CJRJ4L.cjs → chunk-LAHZ7LZA.cjs} +16 -16
- package/dist/{chunk-XM4ZDVD7.mjs → chunk-MBFURXAC.mjs} +1 -1
- package/dist/{chunk-6VEHUKZ2.mjs → chunk-MM5D6VLP.mjs} +4 -20
- package/dist/chunk-MVL2RAJW.mjs +62 -0
- package/dist/{chunk-YA6LLTIJ.cjs → chunk-ND224OE2.cjs} +4 -20
- package/dist/{chunk-RYDW7GPR.cjs → chunk-NPFGGBM5.cjs} +13 -13
- package/dist/{chunk-VZWO3XVL.mjs → chunk-O2LV5XDG.mjs} +2 -2
- package/dist/chunk-O6XNAMBV.mjs +53 -0
- package/dist/{chunk-N2Z4ZFDE.mjs → chunk-OGHTEYXS.mjs} +22 -14
- package/dist/{chunk-U4MP7XTD.mjs → chunk-POXI72VV.mjs} +180 -16
- package/dist/{chunk-QGG336NI.mjs → chunk-Q4BHBO6V.mjs} +1 -1
- package/dist/{chunk-AXYTGLF3.cjs → chunk-QI7WQSMI.cjs} +4 -4
- package/dist/{chunk-WOI2HOGA.mjs → chunk-QQQNJS2E.mjs} +1 -1
- package/dist/{chunk-CFNOGDUS.cjs → chunk-TDWFCC2T.cjs} +2 -2
- package/dist/{chunk-R7LCG3BT.cjs → chunk-UNSKL6BI.cjs} +89 -81
- package/dist/{chunk-WJYCI56T.mjs → chunk-UWTQTZFN.mjs} +52 -33
- package/dist/{chunk-5YYJ6Q2L.mjs → chunk-WIVTGKLY.mjs} +7 -2
- package/dist/{chunk-65P6OGYN.cjs → chunk-WJKVTJJR.cjs} +12 -5
- package/dist/{chunk-OAVTUMJP.cjs → chunk-YXM74XOW.cjs} +9 -9
- package/dist/{chunk-QYMRIVG6.cjs → chunk-YZBV7733.cjs} +120 -101
- package/dist/{chunk-2ITKVAIF.cjs → chunk-ZSO5GWGD.cjs} +203 -39
- package/dist/{client-plugins-DPG0NeZN.d.mts → client-plugins-1GS4zubE.d.mts} +1940 -1677
- package/dist/{client-plugins-Fgni-_25.d.ts → client-plugins-B1Za6F5x.d.ts} +1940 -1677
- package/dist/client-plugins.d.mts +8 -10
- package/dist/client-plugins.d.ts +8 -10
- package/dist/client.cjs +4 -4
- package/dist/client.d.mts +10 -12
- package/dist/client.d.ts +10 -12
- package/dist/client.mjs +3 -3
- package/dist/config.d.mts +8 -10
- package/dist/config.d.ts +8 -10
- package/dist/{devtools-I7TBFOKD.mjs → devtools-6RN6KHTW.mjs} +8 -3
- package/dist/{devtools-6OA7FEF6.cjs → devtools-CQJ3H6MX.cjs} +9 -4
- package/dist/docs.cjs +11 -6
- package/dist/docs.mjs +10 -5
- package/dist/{endpoint-1zA994xL.d.ts → endpoint-CA-TNX60.d.ts} +1 -1
- package/dist/{endpoint-DAc96i93.d.mts → endpoint-CCHFqyTE.d.mts} +1 -1
- package/dist/index.cjs +26 -21
- package/dist/index.d.mts +16 -18
- package/dist/index.d.ts +16 -18
- package/dist/index.mjs +26 -21
- package/dist/{integration-api-BbaiokCC.d.ts → integration-api-0y4FXJpC.d.mts} +128 -1
- package/dist/{integration-api-BbaiokCC.d.mts → integration-api-BPJo5oXb.d.ts} +128 -1
- package/dist/integrations.d.mts +8 -10
- package/dist/integrations.d.ts +8 -10
- package/dist/internal/app-markdown-runtime.cjs +11 -3
- package/dist/internal/app-markdown-runtime.d.mts +9 -10
- package/dist/internal/app-markdown-runtime.d.ts +9 -10
- package/dist/internal/app-markdown-runtime.mjs +10 -2
- package/dist/internal/build-runtime.cjs +19 -17
- package/dist/internal/build-runtime.d.mts +10 -12
- package/dist/internal/build-runtime.d.ts +10 -12
- package/dist/internal/build-runtime.mjs +18 -16
- package/dist/internal/cli-runtime.cjs +9 -5
- package/dist/internal/cli-runtime.mjs +8 -4
- 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 +8 -10
- package/dist/internal/compression-runtime.d.ts +8 -10
- package/dist/internal/config-runtime.cjs +9 -4
- package/dist/internal/config-runtime.d.mts +9 -11
- package/dist/internal/config-runtime.d.ts +9 -11
- package/dist/internal/config-runtime.mjs +8 -3
- package/dist/internal/infra-analytics-runtime.cjs +4 -3
- package/dist/internal/infra-analytics-runtime.mjs +2 -1
- package/dist/internal/product-telemetry-runtime.cjs +2 -2
- package/dist/internal/product-telemetry-runtime.mjs +1 -1
- package/dist/internal/production-runtime.cjs +8 -5
- package/dist/internal/production-runtime.d.mts +16 -16
- package/dist/internal/production-runtime.d.ts +16 -16
- package/dist/internal/production-runtime.mjs +7 -4
- package/dist/markdown.cjs +10 -2
- package/dist/markdown.d.mts +35 -153
- package/dist/markdown.d.ts +35 -153
- package/dist/markdown.mjs +9 -1
- package/dist/{metadata-CDnRHKVq.d.ts → metadata-7LKgQEWF.d.ts} +1 -1
- package/dist/{metadata-D0EF7esB.d.mts → metadata-B9mCxKgp.d.mts} +1 -1
- package/dist/middleware.d.mts +9 -11
- package/dist/middleware.d.ts +9 -11
- package/dist/navigation.d.mts +10 -12
- package/dist/navigation.d.ts +10 -12
- package/dist/{nitro-ZKLGOTVY.mjs → nitro-NAKCRVHX.mjs} +4 -3
- package/dist/{nitro-KQDU7CFE.cjs → nitro-VYDZGYFY.cjs} +4 -3
- package/dist/observability-BupkiN0m.d.mts +447 -0
- package/dist/observability-BupkiN0m.d.ts +447 -0
- package/dist/observability.d.mts +2 -417
- package/dist/observability.d.ts +2 -417
- package/dist/plugin.cjs +14 -12
- package/dist/plugin.d.mts +9 -11
- package/dist/plugin.d.ts +9 -11
- package/dist/plugin.mjs +13 -11
- package/dist/{production-runtime-DpCt0opU.d.ts → production-runtime-B3xnY6fI.d.ts} +1 -1
- package/dist/{production-runtime-x3W4wVqx.d.mts → production-runtime-DramhI0c.d.mts} +1 -1
- package/dist/{render-plan-D5oFRVBV.d.ts → render-plan-CpW32tOL.d.ts} +1 -1
- package/dist/{render-plan-tazUJalK.d.mts → render-plan-CtQB-zHS.d.mts} +1 -1
- package/dist/renderer-client.d.mts +6 -8
- package/dist/renderer-client.d.ts +6 -8
- package/dist/{request-CzZX0Aew.d.ts → request-BVGGeQv4.d.ts} +1 -1
- package/dist/{request-CXmQy5ks.d.mts → request-DlLVBKe3.d.mts} +1 -1
- package/dist/request.d.mts +9 -11
- package/dist/request.d.ts +9 -11
- package/dist/{route-rendering-Dw3C362T.d.ts → route-rendering-BdEldajn.d.ts} +1 -1
- package/dist/{route-rendering-B-qpe32B.d.mts → route-rendering-DChYLNdh.d.mts} +1 -1
- package/dist/{router-CLl3xHwl.d.ts → router-D0Az-1Nu.d.ts} +1 -1
- package/dist/{router-CafM2jlw.d.mts → router-D5htHn_M.d.mts} +1 -1
- package/dist/routes.d.mts +6 -8
- package/dist/routes.d.ts +6 -8
- package/dist/server-fn-client.d.mts +3 -4
- package/dist/server-fn-client.d.ts +3 -4
- package/dist/server-fn.d.mts +1 -1
- package/dist/server-fn.d.ts +1 -1
- package/dist/server-plugins.d.mts +8 -10
- package/dist/server-plugins.d.ts +8 -10
- package/dist/server-query-client.d.mts +1 -1
- package/dist/server-query-client.d.ts +1 -1
- package/dist/server-query.d.mts +1 -1
- package/dist/server-query.d.ts +1 -1
- package/dist/server.cjs +292 -141
- package/dist/server.d.mts +13 -15
- package/dist/server.d.ts +13 -15
- package/dist/server.mjs +278 -127
- package/dist/{spa-router-6sJfsMlQ.d.mts → spa-router-DVfSJZ5o.d.mts} +2 -2
- package/dist/{spa-router-DePr2aZ6.d.ts → spa-router-DmwP_7QL.d.ts} +2 -2
- package/dist/testing.cjs +6 -5
- package/dist/testing.d.mts +7 -9
- package/dist/testing.d.ts +7 -9
- package/dist/testing.mjs +5 -4
- package/dist/{utils-BPHr-1mP.d.mts → utils-B_Rmr0-n.d.mts} +1 -1
- package/dist/{utils-BBKC3cf3.d.ts → utils-Dv0OuLtF.d.ts} +1 -1
- package/dist/version.cjs +2 -2
- package/dist/version.mjs +1 -1
- package/dist/vite.cjs +14 -12
- package/dist/vite.d.mts +8 -10
- package/dist/vite.d.ts +8 -10
- package/dist/vite.mjs +13 -11
- package/package.json +1 -1
- package/dist/route-B0XrsrFk.d.mts +0 -128
- package/dist/route-DOEpbyWZ.d.ts +0 -128
- package/dist/{chunk-GDUYXFIS.mjs → chunk-6EG7U4NF.mjs} +3 -3
- package/dist/{chunk-YAOX43YI.cjs → chunk-C7OUJ6JI.cjs} +2 -2
- package/dist/{chunk-IXTFU4PL.cjs → chunk-NL3ZSMZB.cjs} +2 -2
- package/dist/{chunk-L6V3P73N.mjs → chunk-UOXGA6TO.mjs} +4 -4
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkZSO5GWGDcjs = require('./chunk-ZSO5GWGD.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkJ63ZH5OQcjs = require('./chunk-J63ZH5OQ.cjs');
|
|
6
9
|
|
|
7
10
|
|
|
8
11
|
var _chunkI57LW5VZcjs = require('./chunk-I57LW5VZ.cjs');
|
|
@@ -63,12 +66,12 @@ function collectFarmLlmsTxtPages(sources, options) {
|
|
|
63
66
|
for (const source of sources) {
|
|
64
67
|
const path = source.pattern;
|
|
65
68
|
if (path.includes("[") || pages.has(path)) continue;
|
|
66
|
-
if (include.length && !include.some((pattern) =>
|
|
69
|
+
if (include.length && !include.some((pattern) => _chunkZSO5GWGDcjs.matchesFarmMarkdownRoutePattern.call(void 0, pattern, path))) {
|
|
67
70
|
continue;
|
|
68
71
|
}
|
|
69
|
-
if (exclude.some((pattern) =>
|
|
72
|
+
if (exclude.some((pattern) => _chunkZSO5GWGDcjs.matchesFarmMarkdownRoutePattern.call(void 0, pattern, path))) continue;
|
|
70
73
|
if (isMetadataNoIndex(source.metadata)) continue;
|
|
71
|
-
const target =
|
|
74
|
+
const target = _chunkZSO5GWGDcjs.isFarmMarkdownMirrorExposed.call(void 0, options.markdown, path) ? _chunkZSO5GWGDcjs.getFarmMarkdownMirrorPath.call(void 0, path) : path;
|
|
72
75
|
const description = readMetadataString(source.metadata, "description");
|
|
73
76
|
pages.set(path, {
|
|
74
77
|
path,
|
|
@@ -158,7 +161,9 @@ function createFarmLlmsMarkdownReader(fetchMarkdown) {
|
|
|
158
161
|
return async (url) => {
|
|
159
162
|
try {
|
|
160
163
|
const response = await fetchMarkdown(
|
|
161
|
-
new Request(url, {
|
|
164
|
+
new Request(url, {
|
|
165
|
+
headers: { accept: "text/markdown", [_chunkJ63ZH5OQcjs.FARM_INTERNAL_READ_HEADER]: "llms-full" }
|
|
166
|
+
})
|
|
162
167
|
);
|
|
163
168
|
const type = _nullishCoalesce(response.headers.get("content-type"), () => ( ""));
|
|
164
169
|
if (!response.ok || !type.toLowerCase().startsWith("text/markdown")) {
|
|
@@ -172,6 +177,8 @@ function createFarmLlmsMarkdownReader(fetchMarkdown) {
|
|
|
172
177
|
};
|
|
173
178
|
}
|
|
174
179
|
_chunkS3JO3N4Hcjs.__name.call(void 0, createFarmLlmsMarkdownReader, "createFarmLlmsMarkdownReader");
|
|
180
|
+
var FARM_LLMS_FULL_PAGE_TIMEOUT_MS = 3e4;
|
|
181
|
+
var LLMS_PAGE_TIMED_OUT = /* @__PURE__ */ Symbol("farm.llms.pageTimedOut");
|
|
175
182
|
async function renderFarmLlmsFullTxt(value, options) {
|
|
176
183
|
const index = serializeFarmLlmsTxt(value);
|
|
177
184
|
if (typeof value === "string") return index;
|
|
@@ -185,17 +192,32 @@ async function renderFarmLlmsFullTxt(value, options) {
|
|
|
185
192
|
links.push(link);
|
|
186
193
|
}
|
|
187
194
|
}
|
|
195
|
+
const pageTimeout = _nullishCoalesce(options.pageTimeout, () => ( FARM_LLMS_FULL_PAGE_TIMEOUT_MS));
|
|
196
|
+
const readWithinTimeout = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, async (url) => {
|
|
197
|
+
let timer;
|
|
198
|
+
const timedOut = new Promise((resolve) => {
|
|
199
|
+
timer = setTimeout(resolve, pageTimeout, LLMS_PAGE_TIMED_OUT);
|
|
200
|
+
});
|
|
201
|
+
try {
|
|
202
|
+
const content = await Promise.race([options.readMarkdown(url), timedOut]);
|
|
203
|
+
if (content !== LLMS_PAGE_TIMED_OUT) return content;
|
|
204
|
+
_optionalChain([options, 'access', _14 => _14.onIncomplete, 'optionalCall', _15 => _15()]);
|
|
205
|
+
return null;
|
|
206
|
+
} finally {
|
|
207
|
+
clearTimeout(timer);
|
|
208
|
+
}
|
|
209
|
+
}, "readWithinTimeout");
|
|
188
210
|
const contents = await mapWithConcurrency(
|
|
189
211
|
links,
|
|
190
212
|
_nullishCoalesce(options.concurrency, () => ( 4)),
|
|
191
|
-
(link) => shouldInlineLlmsLink(link.url, options.origin) ?
|
|
213
|
+
(link) => shouldInlineLlmsLink(link.url, options.origin) ? readWithinTimeout(link.url) : null
|
|
192
214
|
);
|
|
193
215
|
const blocks = [`# ${toSingleLine(llms.title)}`];
|
|
194
|
-
if (_optionalChain([llms, 'access',
|
|
195
|
-
if (_optionalChain([llms, 'access',
|
|
216
|
+
if (_optionalChain([llms, 'access', _16 => _16.summary, 'optionalAccess', _17 => _17.trim, 'call', _18 => _18()])) blocks.push(`> ${toSingleLine(llms.summary)}`);
|
|
217
|
+
if (_optionalChain([llms, 'access', _19 => _19.details, 'optionalAccess', _20 => _20.trim, 'call', _21 => _21()])) blocks.push(llms.details.trim());
|
|
196
218
|
const pages = links.map((link, index2) => {
|
|
197
219
|
const parts = [`## ${toSingleLine(link.title)}`, `URL: ${escapeLinkUrl(link.url)}`];
|
|
198
|
-
if (_optionalChain([link, 'access',
|
|
220
|
+
if (_optionalChain([link, 'access', _22 => _22.description, 'optionalAccess', _23 => _23.trim, 'call', _24 => _24()])) parts.push(toSingleLine(link.description));
|
|
199
221
|
const content = stripFrontmatter(_nullishCoalesce(contents[index2], () => ( ""))).trim();
|
|
200
222
|
if (content) parts.push(content);
|
|
201
223
|
return parts.join("\n\n");
|
|
@@ -211,27 +233,35 @@ function createFarmLlmsFullRenderer(options = {}) {
|
|
|
211
233
|
const maxEntries = _nullishCoalesce(options.maxEntries, () => ( 16));
|
|
212
234
|
const entries = /* @__PURE__ */ new Map();
|
|
213
235
|
let queue = Promise.resolve();
|
|
214
|
-
|
|
236
|
+
const settle = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, (body, complete, onSettled) => onSettled ? body.then((value) => (onSettled(complete()), value)) : body, "settle");
|
|
237
|
+
return (origin, render, onSettled) => {
|
|
215
238
|
const entry = entries.get(origin);
|
|
216
|
-
if (entry && entry.expires > now()) return entry.body;
|
|
239
|
+
if (entry && entry.expires > now()) return settle(entry.body, entry.complete, onSettled);
|
|
217
240
|
entries.delete(origin);
|
|
218
|
-
|
|
241
|
+
let complete = true;
|
|
242
|
+
const body = queue.then(
|
|
243
|
+
() => render({
|
|
244
|
+
incomplete: /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, () => {
|
|
245
|
+
complete = false;
|
|
246
|
+
}, "incomplete")
|
|
247
|
+
})
|
|
248
|
+
);
|
|
219
249
|
queue = body.catch(() => {
|
|
220
250
|
});
|
|
221
|
-
const pending = { body, expires: Number.POSITIVE_INFINITY };
|
|
251
|
+
const pending = { body, expires: Number.POSITIVE_INFINITY, complete: /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, () => complete, "complete") };
|
|
222
252
|
entries.set(origin, pending);
|
|
223
253
|
if (entries.size > maxEntries) entries.delete(entries.keys().next().value);
|
|
224
254
|
body.then(
|
|
225
255
|
() => {
|
|
226
256
|
if (entries.get(origin) !== pending) return;
|
|
227
|
-
if (ttl > 0) pending.expires = now() + ttl;
|
|
257
|
+
if (ttl > 0 && complete) pending.expires = now() + ttl;
|
|
228
258
|
else entries.delete(origin);
|
|
229
259
|
},
|
|
230
260
|
() => {
|
|
231
261
|
if (entries.get(origin) === pending) entries.delete(origin);
|
|
232
262
|
}
|
|
233
263
|
);
|
|
234
|
-
return body;
|
|
264
|
+
return settle(body, pending.complete, onSettled);
|
|
235
265
|
};
|
|
236
266
|
}
|
|
237
267
|
_chunkS3JO3N4Hcjs.__name.call(void 0, createFarmLlmsFullRenderer, "createFarmLlmsFullRenderer");
|
|
@@ -623,7 +653,7 @@ async function applyFarmCspHashesToHtml(html, security) {
|
|
|
623
653
|
_chunkS3JO3N4Hcjs.__name.call(void 0, applyFarmCspHashesToHtml, "applyFarmCspHashesToHtml");
|
|
624
654
|
function applyFarmCspNonceToResponse(response, security) {
|
|
625
655
|
if (!security.csp || !security.csp.nonce) return response;
|
|
626
|
-
if (!_optionalChain([response, 'access',
|
|
656
|
+
if (!_optionalChain([response, 'access', _25 => _25.headers, 'access', _26 => _26.get, 'call', _27 => _27("content-type"), 'optionalAccess', _28 => _28.toLowerCase, 'call', _29 => _29(), 'access', _30 => _30.includes, 'call', _31 => _31("text/html")])) return response;
|
|
627
657
|
const nonce = createFarmCspNonce(security);
|
|
628
658
|
const securityHeader = getFarmSecurityHeader(security, nonce);
|
|
629
659
|
const headers = new Headers(response.headers);
|
|
@@ -844,7 +874,7 @@ var rawTextElements = /* @__PURE__ */ new Map([
|
|
|
844
874
|
["xmp", /<\/xmp(?=[\s/>]|$)/gi]
|
|
845
875
|
]);
|
|
846
876
|
function stampScriptTag(tag, nonce) {
|
|
847
|
-
const opening = _optionalChain([tag, 'access',
|
|
877
|
+
const opening = _optionalChain([tag, 'access', _32 => _32.match, 'call', _33 => _33(/^<script\b/i), 'optionalAccess', _34 => _34[0]]);
|
|
848
878
|
if (!opening) return tag;
|
|
849
879
|
const attributes = stripScriptNonceAttribute(tag).slice(opening.length, -1);
|
|
850
880
|
return `<script nonce="${nonce}"${attributes}>`;
|
|
@@ -900,7 +930,7 @@ function collectFarmInlineScriptContents(html) {
|
|
|
900
930
|
}
|
|
901
931
|
_chunkS3JO3N4Hcjs.__name.call(void 0, collectFarmInlineScriptContents, "collectFarmInlineScriptContents");
|
|
902
932
|
function findScriptTagAttributeRange(tag, expectedName) {
|
|
903
|
-
const opening = _optionalChain([tag, 'access',
|
|
933
|
+
const opening = _optionalChain([tag, 'access', _35 => _35.match, 'call', _36 => _36(/^<script\b/i), 'optionalAccess', _37 => _37[0]]);
|
|
904
934
|
if (!opening) return void 0;
|
|
905
935
|
let offset = opening.length;
|
|
906
936
|
while (offset < tag.length - 1) {
|
|
@@ -930,7 +960,7 @@ _chunkS3JO3N4Hcjs.__name.call(void 0, findScriptTagAttributeRange, "findScriptTa
|
|
|
930
960
|
function findRawTextEnd(input, tagName, offset = 0) {
|
|
931
961
|
const closing = rawTextElements.get(tagName);
|
|
932
962
|
closing.lastIndex = offset;
|
|
933
|
-
return _nullishCoalesce(_optionalChain([closing, 'access',
|
|
963
|
+
return _nullishCoalesce(_optionalChain([closing, 'access', _38 => _38.exec, 'call', _39 => _39(input), 'optionalAccess', _40 => _40.index]), () => ( -1));
|
|
934
964
|
}
|
|
935
965
|
_chunkS3JO3N4Hcjs.__name.call(void 0, findRawTextEnd, "findRawTextEnd");
|
|
936
966
|
function matchingSuffixLength(input, token) {
|
|
@@ -976,9 +1006,9 @@ var MAX_REPORTED_PRELOAD_WARNINGS = 256;
|
|
|
976
1006
|
function resolveFarmPerformanceConfig(config) {
|
|
977
1007
|
return {
|
|
978
1008
|
preload: {
|
|
979
|
-
mode: _optionalChain([config, 'optionalAccess',
|
|
980
|
-
maxImages: normalizeBudget(_optionalChain([config, 'optionalAccess',
|
|
981
|
-
maxFonts: normalizeBudget(_optionalChain([config, 'optionalAccess',
|
|
1009
|
+
mode: _optionalChain([config, 'optionalAccess', _41 => _41.preload, 'optionalAccess', _42 => _42.mode]) === "warn" ? "warn" : "enforce",
|
|
1010
|
+
maxImages: normalizeBudget(_optionalChain([config, 'optionalAccess', _43 => _43.preload, 'optionalAccess', _44 => _44.maxImages]), DEFAULT_PRELOAD_CONFIG.maxImages),
|
|
1011
|
+
maxFonts: normalizeBudget(_optionalChain([config, 'optionalAccess', _45 => _45.preload, 'optionalAccess', _46 => _46.maxFonts]), DEFAULT_PRELOAD_CONFIG.maxFonts)
|
|
982
1012
|
}
|
|
983
1013
|
};
|
|
984
1014
|
}
|
|
@@ -992,7 +1022,7 @@ function manageFarmHtmlPreloads(html, config) {
|
|
|
992
1022
|
index,
|
|
993
1023
|
kind,
|
|
994
1024
|
href: readHtmlAttribute(element.value, "href"),
|
|
995
|
-
highPriority: _optionalChain([readHtmlAttribute, 'call',
|
|
1025
|
+
highPriority: _optionalChain([readHtmlAttribute, 'call', _47 => _47(element.value, "fetchpriority"), 'optionalAccess', _48 => _48.toLowerCase, 'call', _49 => _49()]) === "high"
|
|
996
1026
|
}
|
|
997
1027
|
] : [];
|
|
998
1028
|
});
|
|
@@ -1016,7 +1046,7 @@ function manageFarmLinkHeaderPreloads(value, config) {
|
|
|
1016
1046
|
index,
|
|
1017
1047
|
kind,
|
|
1018
1048
|
href: getLinkHeaderTarget(link),
|
|
1019
|
-
highPriority: _optionalChain([getLinkHeaderParameter, 'call',
|
|
1049
|
+
highPriority: _optionalChain([getLinkHeaderParameter, 'call', _50 => _50(link, "fetchpriority"), 'optionalAccess', _51 => _51.toLowerCase, 'call', _52 => _52()]) === "high"
|
|
1020
1050
|
}
|
|
1021
1051
|
] : [];
|
|
1022
1052
|
});
|
|
@@ -1039,7 +1069,7 @@ function manageFarmDocumentPreloads(html, linkHeader, config) {
|
|
|
1039
1069
|
index,
|
|
1040
1070
|
kind,
|
|
1041
1071
|
href: readHtmlAttribute(element.value, "href"),
|
|
1042
|
-
highPriority: _optionalChain([readHtmlAttribute, 'call',
|
|
1072
|
+
highPriority: _optionalChain([readHtmlAttribute, 'call', _53 => _53(element.value, "fetchpriority"), 'optionalAccess', _54 => _54.toLowerCase, 'call', _55 => _55()]) === "high"
|
|
1043
1073
|
});
|
|
1044
1074
|
}
|
|
1045
1075
|
for (const [index, link] of links.entries()) {
|
|
@@ -1049,7 +1079,7 @@ function manageFarmDocumentPreloads(html, linkHeader, config) {
|
|
|
1049
1079
|
index: headerOffset + index,
|
|
1050
1080
|
kind,
|
|
1051
1081
|
href: getLinkHeaderTarget(link),
|
|
1052
|
-
highPriority: _optionalChain([getLinkHeaderParameter, 'call',
|
|
1082
|
+
highPriority: _optionalChain([getLinkHeaderParameter, 'call', _56 => _56(link, "fetchpriority"), 'optionalAccess', _57 => _57.toLowerCase, 'call', _58 => _58()]) === "high"
|
|
1053
1083
|
});
|
|
1054
1084
|
}
|
|
1055
1085
|
const budget = selectPreloadsWithinBudget(candidates, config);
|
|
@@ -1130,13 +1160,13 @@ function selectPreloadsWithinBudget(candidates, config) {
|
|
|
1130
1160
|
}
|
|
1131
1161
|
_chunkS3JO3N4Hcjs.__name.call(void 0, selectPreloadsWithinBudget, "selectPreloadsWithinBudget");
|
|
1132
1162
|
function getHtmlPreloadKind(link) {
|
|
1133
|
-
const rel = _optionalChain([readHtmlAttribute, 'call',
|
|
1163
|
+
const rel = _optionalChain([readHtmlAttribute, 'call', _59 => _59(link, "rel"), 'optionalAccess', _60 => _60.toLowerCase, 'call', _61 => _61(), 'access', _62 => _62.split, 'call', _63 => _63(/\s+/)]) || [];
|
|
1134
1164
|
if (!rel.includes("preload")) return void 0;
|
|
1135
1165
|
return normalizePreloadKind(readHtmlAttribute(link, "as"));
|
|
1136
1166
|
}
|
|
1137
1167
|
_chunkS3JO3N4Hcjs.__name.call(void 0, getHtmlPreloadKind, "getHtmlPreloadKind");
|
|
1138
1168
|
function getLinkHeaderPreloadKind(link) {
|
|
1139
|
-
const relations = _nullishCoalesce(_optionalChain([getLinkHeaderParameter, 'call',
|
|
1169
|
+
const relations = _nullishCoalesce(_optionalChain([getLinkHeaderParameter, 'call', _64 => _64(link, "rel"), 'optionalAccess', _65 => _65.toLowerCase, 'call', _66 => _66(), 'access', _67 => _67.split, 'call', _68 => _68(/\s+/)]), () => ( []));
|
|
1140
1170
|
if (!relations.includes("preload")) return void 0;
|
|
1141
1171
|
return normalizePreloadKind(getLinkHeaderParameter(link, "as"));
|
|
1142
1172
|
}
|
|
@@ -1182,7 +1212,7 @@ function splitLinkParameters(value) {
|
|
|
1182
1212
|
}
|
|
1183
1213
|
_chunkS3JO3N4Hcjs.__name.call(void 0, splitLinkParameters, "splitLinkParameters");
|
|
1184
1214
|
function normalizePreloadKind(value) {
|
|
1185
|
-
const normalized = _optionalChain([value, 'optionalAccess',
|
|
1215
|
+
const normalized = _optionalChain([value, 'optionalAccess', _69 => _69.toLowerCase, 'call', _70 => _70()]);
|
|
1186
1216
|
return normalized === "image" || normalized === "font" ? normalized : void 0;
|
|
1187
1217
|
}
|
|
1188
1218
|
_chunkS3JO3N4Hcjs.__name.call(void 0, normalizePreloadKind, "normalizePreloadKind");
|
|
@@ -1190,7 +1220,7 @@ function readHtmlAttribute(element, name) {
|
|
|
1190
1220
|
const match = element.match(
|
|
1191
1221
|
new RegExp(`\\s${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i")
|
|
1192
1222
|
);
|
|
1193
|
-
return _nullishCoalesce(_nullishCoalesce(_optionalChain([match, 'optionalAccess',
|
|
1223
|
+
return _nullishCoalesce(_nullishCoalesce(_optionalChain([match, 'optionalAccess', _71 => _71[1]]), () => ( _optionalChain([match, 'optionalAccess', _72 => _72[2]]))), () => ( _optionalChain([match, 'optionalAccess', _73 => _73[3]])));
|
|
1194
1224
|
}
|
|
1195
1225
|
_chunkS3JO3N4Hcjs.__name.call(void 0, readHtmlAttribute, "readHtmlAttribute");
|
|
1196
1226
|
function findHtmlLinkElements(html) {
|
|
@@ -1214,7 +1244,7 @@ function findHtmlLinkElements(html) {
|
|
|
1214
1244
|
}
|
|
1215
1245
|
rawTextTag.lastIndex = start;
|
|
1216
1246
|
const rawText = rawTextTag.exec(lowerHtml);
|
|
1217
|
-
if (_optionalChain([rawText, 'optionalAccess',
|
|
1247
|
+
if (_optionalChain([rawText, 'optionalAccess', _74 => _74[1]])) {
|
|
1218
1248
|
const openingEnd = findHtmlTagEnd2(html, start);
|
|
1219
1249
|
if (openingEnd === -1) break;
|
|
1220
1250
|
if (rawText[1] === "svg" && html[openingEnd - 2] === "/") {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } 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
|
|
4
|
+
var _chunkZSO5GWGDcjs = require('./chunk-ZSO5GWGD.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
var _chunkS3JO3N4Hcjs = require('./chunk-S3JO3N4H.cjs');
|
|
@@ -116,7 +116,7 @@ async function createFarmMarkdownSourceResponse(options) {
|
|
|
116
116
|
}
|
|
117
117
|
const url = new URL(options.request.url);
|
|
118
118
|
const hasMarkdownExtension = url.pathname.toLowerCase().endsWith(".md");
|
|
119
|
-
if (!hasMarkdownExtension && !
|
|
119
|
+
if (!hasMarkdownExtension && !_chunkZSO5GWGDcjs.requestAcceptsMarkdown.call(void 0, options.request.headers.get("accept"))) {
|
|
120
120
|
return null;
|
|
121
121
|
}
|
|
122
122
|
const targetPathname = normalizeFarmMarkdownRoutePath(url.pathname);
|
|
@@ -134,7 +134,7 @@ async function createFarmMarkdownSourceResponse(options) {
|
|
|
134
134
|
if (!hasMarkdownExtension) {
|
|
135
135
|
headers.set("Vary", "Accept");
|
|
136
136
|
}
|
|
137
|
-
return
|
|
137
|
+
return _chunkZSO5GWGDcjs.createFarmMarkdownViewResponse.call(void 0, {
|
|
138
138
|
request: options.request,
|
|
139
139
|
requestUrl: url,
|
|
140
140
|
markdown: source.source,
|
|
@@ -3,17 +3,20 @@ import {
|
|
|
3
3
|
} from "./chunk-XAXTTBUT.mjs";
|
|
4
4
|
import {
|
|
5
5
|
serializeFarmLlmsTxt
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-JT25KHDI.mjs";
|
|
7
|
+
import {
|
|
8
|
+
emitFarmAgentRead
|
|
9
|
+
} from "./chunk-MVL2RAJW.mjs";
|
|
7
10
|
import {
|
|
8
11
|
resolveFarmThemeConfig
|
|
9
12
|
} from "./chunk-AELACLOB.mjs";
|
|
13
|
+
import {
|
|
14
|
+
omitFarmResponseBody
|
|
15
|
+
} from "./chunk-5WI2S4CO.mjs";
|
|
10
16
|
import {
|
|
11
17
|
resolveFarmAPIServerBasePath,
|
|
12
18
|
resolveFarmAPIServerRoutePath
|
|
13
19
|
} from "./chunk-I6XDAKWQ.mjs";
|
|
14
|
-
import {
|
|
15
|
-
omitFarmResponseBody
|
|
16
|
-
} from "./chunk-5WI2S4CO.mjs";
|
|
17
20
|
import {
|
|
18
21
|
localizeFarmPathname
|
|
19
22
|
} from "./chunk-L3KT7IXV.mjs";
|
|
@@ -201,6 +204,9 @@ function createFarmMetadataRouteResponse(kind, value, routeModule = {}, options
|
|
|
201
204
|
if (method !== "GET" && method !== "HEAD") {
|
|
202
205
|
return new Response(null, { status: 405, headers: { Allow: "GET, HEAD" } });
|
|
203
206
|
}
|
|
207
|
+
if ((kind === "llms" || kind === "llms-full") && options.request) {
|
|
208
|
+
emitFarmAgentRead(options.request, kind, isResponse(value) ? value.status : 200);
|
|
209
|
+
}
|
|
204
210
|
if (isResponse(value)) {
|
|
205
211
|
return method === "HEAD" ? omitFarmResponseBody(value) : value;
|
|
206
212
|
}
|
|
@@ -486,7 +492,7 @@ function createFarmApiCatalog(input) {
|
|
|
486
492
|
};
|
|
487
493
|
}
|
|
488
494
|
__name(createFarmApiCatalog, "createFarmApiCatalog");
|
|
489
|
-
function createFarmApiCatalogResponse(method, input) {
|
|
495
|
+
function createFarmApiCatalogResponse(method, input, request) {
|
|
490
496
|
const upperMethod = method.toUpperCase();
|
|
491
497
|
if (upperMethod !== "GET" && upperMethod !== "HEAD") {
|
|
492
498
|
return new Response("Method Not Allowed", {
|
|
@@ -494,6 +500,7 @@ function createFarmApiCatalogResponse(method, input) {
|
|
|
494
500
|
headers: { Allow: "GET, HEAD", "Content-Type": "text/plain; charset=utf-8" }
|
|
495
501
|
});
|
|
496
502
|
}
|
|
503
|
+
if (request) emitFarmAgentRead(request, "api-catalog", 200);
|
|
497
504
|
const catalog = createFarmApiCatalog(input);
|
|
498
505
|
return new Response(upperMethod === "HEAD" ? null : JSON.stringify(catalog), {
|
|
499
506
|
status: 200,
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
var _chunkE3UK5IIBcjs = require('./chunk-E3UK5IIB.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkS3JO3N4Hcjs = require('./chunk-S3JO3N4H.cjs');
|
|
7
|
+
|
|
8
|
+
// src/agent-identity.ts
|
|
9
|
+
var AGENT_TOKENS = [
|
|
10
|
+
["ChatGPT-User", "openai", "agent"],
|
|
11
|
+
["OAI-SearchBot", "openai", "crawler"],
|
|
12
|
+
["GPTBot", "openai", "crawler"],
|
|
13
|
+
["Claude-User", "anthropic", "agent"],
|
|
14
|
+
["Claude-SearchBot", "anthropic", "crawler"],
|
|
15
|
+
["ClaudeBot", "anthropic", "crawler"],
|
|
16
|
+
["Perplexity-User", "perplexity", "agent"],
|
|
17
|
+
["PerplexityBot", "perplexity", "crawler"],
|
|
18
|
+
["CCBot", "other", "crawler"],
|
|
19
|
+
["Bytespider", "other", "crawler"],
|
|
20
|
+
["Meta-ExternalAgent", "other", "crawler"]
|
|
21
|
+
];
|
|
22
|
+
var AGENT_PATTERNS = AGENT_TOKENS.map(([token, family, category]) => ({
|
|
23
|
+
pattern: new RegExp(`(?:^|[\\s;(])${token}(?=[/\\s;)]|$)`, "i"),
|
|
24
|
+
family,
|
|
25
|
+
category
|
|
26
|
+
}));
|
|
27
|
+
var UNKNOWN = { family: "unknown", category: "unknown", identity: "unknown" };
|
|
28
|
+
function classifyFarmAgent(userAgent) {
|
|
29
|
+
const value = (_nullishCoalesce(userAgent, () => ( ""))).slice(0, 2048);
|
|
30
|
+
const matches = AGENT_PATTERNS.filter(({ pattern }) => pattern.test(value));
|
|
31
|
+
if (matches.length === 1) {
|
|
32
|
+
const { family, category } = matches[0];
|
|
33
|
+
return { family, category, identity: "self-reported" };
|
|
34
|
+
}
|
|
35
|
+
return { ...UNKNOWN };
|
|
36
|
+
}
|
|
37
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, classifyFarmAgent, "classifyFarmAgent");
|
|
38
|
+
var FARM_INTERNAL_READ_HEADER = "x-farm-internal-read";
|
|
39
|
+
function emitFarmAgentRead(request, surface, status, view) {
|
|
40
|
+
if (request.headers.has(FARM_INTERNAL_READ_HEADER)) return;
|
|
41
|
+
let route;
|
|
42
|
+
try {
|
|
43
|
+
route = new URL(request.url).pathname;
|
|
44
|
+
} catch (e) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
_chunkE3UK5IIBcjs.emitFarmEvent.call(void 0, {
|
|
48
|
+
type: "agent.read",
|
|
49
|
+
surface,
|
|
50
|
+
route,
|
|
51
|
+
...view ? { view } : {},
|
|
52
|
+
status,
|
|
53
|
+
agent: classifyFarmAgent(request.headers.get("user-agent"))
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, emitFarmAgentRead, "emitFarmAgentRead");
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
exports.classifyFarmAgent = classifyFarmAgent; exports.FARM_INTERNAL_READ_HEADER = FARM_INTERNAL_READ_HEADER; exports.emitFarmAgentRead = emitFarmAgentRead;
|
|
@@ -17,7 +17,7 @@ var _chunkLYLEZIG3cjs = require('./chunk-LYLEZIG3.cjs');
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
var
|
|
20
|
+
var _chunkC7OUJ6JIcjs = require('./chunk-C7OUJ6JI.cjs');
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
var _chunkWMAPPDMMcjs = require('./chunk-WMAPPDMM.cjs');
|
|
@@ -93,7 +93,7 @@ var _APIRouteManager = class _APIRouteManager {
|
|
|
93
93
|
await this.loadProgrammaticApiRoutes(appDir);
|
|
94
94
|
}
|
|
95
95
|
this.routes = new Map(
|
|
96
|
-
|
|
96
|
+
_chunkC7OUJ6JIcjs.mergePluginAPIRoutes.call(void 0, [...this.routes.values()], this.plugins, void 0, {
|
|
97
97
|
bodySizeLimit: this.bodySizeLimit
|
|
98
98
|
}).map((route) => [route.path, route])
|
|
99
99
|
);
|
|
@@ -140,7 +140,7 @@ var _APIRouteManager = class _APIRouteManager {
|
|
|
140
140
|
const routeModule = await this.loadModule(filePath);
|
|
141
141
|
const endpoints = {};
|
|
142
142
|
const availableMethods = [];
|
|
143
|
-
for (const method of
|
|
143
|
+
for (const method of _chunkC7OUJ6JIcjs.API_ROUTE_METHODS) {
|
|
144
144
|
if (routeModule[method]) {
|
|
145
145
|
endpoints[method] = routeModule[method];
|
|
146
146
|
availableMethods.push(method);
|
|
@@ -322,7 +322,7 @@ var _APIRouteManager = class _APIRouteManager {
|
|
|
322
322
|
const url = new URL(request.url);
|
|
323
323
|
const pathname = url.pathname;
|
|
324
324
|
const method = request.method.toUpperCase();
|
|
325
|
-
const match =
|
|
325
|
+
const match = _chunkC7OUJ6JIcjs.matchAPIRouteAtBasePath.call(void 0, this.routes, pathname, this.basePath);
|
|
326
326
|
if (!match) {
|
|
327
327
|
return new Response(JSON.stringify({ error: "Not Found" }), {
|
|
328
328
|
status: 404,
|
|
@@ -330,19 +330,19 @@ var _APIRouteManager = class _APIRouteManager {
|
|
|
330
330
|
});
|
|
331
331
|
}
|
|
332
332
|
const { route, params } = match;
|
|
333
|
-
const endpoint =
|
|
333
|
+
const endpoint = _chunkC7OUJ6JIcjs.resolveAPIRouteEndpoint.call(void 0, route, method);
|
|
334
334
|
if (!endpoint) {
|
|
335
335
|
return new Response(JSON.stringify({ error: "Method Not Allowed" }), {
|
|
336
336
|
status: 405,
|
|
337
337
|
headers: {
|
|
338
|
-
Allow:
|
|
338
|
+
Allow: _chunkC7OUJ6JIcjs.getAllowedAPIRouteMethods.call(void 0, route).join(", "),
|
|
339
339
|
"Content-Type": "application/json"
|
|
340
340
|
}
|
|
341
341
|
});
|
|
342
342
|
}
|
|
343
343
|
const invoke = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, async () => {
|
|
344
344
|
try {
|
|
345
|
-
return await
|
|
345
|
+
return await _chunkC7OUJ6JIcjs.invokeAPIRouteEndpoint.call(void 0, endpoint, request, params, this.bodySizeLimit);
|
|
346
346
|
} catch (error) {
|
|
347
347
|
if (options.throwOnError) throw error;
|
|
348
348
|
console.error(`[API Error] ${pathname}:`, error);
|
|
@@ -364,7 +364,7 @@ var _APIRouteManager = class _APIRouteManager {
|
|
|
364
364
|
return Boolean(this.matchRoute(pathname));
|
|
365
365
|
}
|
|
366
366
|
matchRoute(pathname) {
|
|
367
|
-
return
|
|
367
|
+
return _chunkC7OUJ6JIcjs.matchAPIRouteAtBasePath.call(void 0, this.routes, pathname, this.basePath);
|
|
368
368
|
}
|
|
369
369
|
/**
|
|
370
370
|
* Get all routes for client type generation
|
|
@@ -2,7 +2,10 @@ import {
|
|
|
2
2
|
getFarmMarkdownMirrorPath,
|
|
3
3
|
isFarmMarkdownMirrorExposed,
|
|
4
4
|
matchesFarmMarkdownRoutePattern
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-POXI72VV.mjs";
|
|
6
|
+
import {
|
|
7
|
+
FARM_INTERNAL_READ_HEADER
|
|
8
|
+
} from "./chunk-MVL2RAJW.mjs";
|
|
6
9
|
import {
|
|
7
10
|
applyFarmBasePath
|
|
8
11
|
} from "./chunk-4RB44K6Z.mjs";
|
|
@@ -158,7 +161,9 @@ function createFarmLlmsMarkdownReader(fetchMarkdown) {
|
|
|
158
161
|
return async (url) => {
|
|
159
162
|
try {
|
|
160
163
|
const response = await fetchMarkdown(
|
|
161
|
-
new Request(url, {
|
|
164
|
+
new Request(url, {
|
|
165
|
+
headers: { accept: "text/markdown", [FARM_INTERNAL_READ_HEADER]: "llms-full" }
|
|
166
|
+
})
|
|
162
167
|
);
|
|
163
168
|
const type = response.headers.get("content-type") ?? "";
|
|
164
169
|
if (!response.ok || !type.toLowerCase().startsWith("text/markdown")) {
|
|
@@ -172,6 +177,8 @@ function createFarmLlmsMarkdownReader(fetchMarkdown) {
|
|
|
172
177
|
};
|
|
173
178
|
}
|
|
174
179
|
__name(createFarmLlmsMarkdownReader, "createFarmLlmsMarkdownReader");
|
|
180
|
+
var FARM_LLMS_FULL_PAGE_TIMEOUT_MS = 3e4;
|
|
181
|
+
var LLMS_PAGE_TIMED_OUT = /* @__PURE__ */ Symbol("farm.llms.pageTimedOut");
|
|
175
182
|
async function renderFarmLlmsFullTxt(value, options) {
|
|
176
183
|
const index = serializeFarmLlmsTxt(value);
|
|
177
184
|
if (typeof value === "string") return index;
|
|
@@ -185,10 +192,25 @@ async function renderFarmLlmsFullTxt(value, options) {
|
|
|
185
192
|
links.push(link);
|
|
186
193
|
}
|
|
187
194
|
}
|
|
195
|
+
const pageTimeout = options.pageTimeout ?? FARM_LLMS_FULL_PAGE_TIMEOUT_MS;
|
|
196
|
+
const readWithinTimeout = /* @__PURE__ */ __name(async (url) => {
|
|
197
|
+
let timer;
|
|
198
|
+
const timedOut = new Promise((resolve) => {
|
|
199
|
+
timer = setTimeout(resolve, pageTimeout, LLMS_PAGE_TIMED_OUT);
|
|
200
|
+
});
|
|
201
|
+
try {
|
|
202
|
+
const content = await Promise.race([options.readMarkdown(url), timedOut]);
|
|
203
|
+
if (content !== LLMS_PAGE_TIMED_OUT) return content;
|
|
204
|
+
options.onIncomplete?.();
|
|
205
|
+
return null;
|
|
206
|
+
} finally {
|
|
207
|
+
clearTimeout(timer);
|
|
208
|
+
}
|
|
209
|
+
}, "readWithinTimeout");
|
|
188
210
|
const contents = await mapWithConcurrency(
|
|
189
211
|
links,
|
|
190
212
|
options.concurrency ?? 4,
|
|
191
|
-
(link) => shouldInlineLlmsLink(link.url, options.origin) ?
|
|
213
|
+
(link) => shouldInlineLlmsLink(link.url, options.origin) ? readWithinTimeout(link.url) : null
|
|
192
214
|
);
|
|
193
215
|
const blocks = [`# ${toSingleLine(llms.title)}`];
|
|
194
216
|
if (llms.summary?.trim()) blocks.push(`> ${toSingleLine(llms.summary)}`);
|
|
@@ -211,27 +233,35 @@ function createFarmLlmsFullRenderer(options = {}) {
|
|
|
211
233
|
const maxEntries = options.maxEntries ?? 16;
|
|
212
234
|
const entries = /* @__PURE__ */ new Map();
|
|
213
235
|
let queue = Promise.resolve();
|
|
214
|
-
|
|
236
|
+
const settle = /* @__PURE__ */ __name((body, complete, onSettled) => onSettled ? body.then((value) => (onSettled(complete()), value)) : body, "settle");
|
|
237
|
+
return (origin, render, onSettled) => {
|
|
215
238
|
const entry = entries.get(origin);
|
|
216
|
-
if (entry && entry.expires > now()) return entry.body;
|
|
239
|
+
if (entry && entry.expires > now()) return settle(entry.body, entry.complete, onSettled);
|
|
217
240
|
entries.delete(origin);
|
|
218
|
-
|
|
241
|
+
let complete = true;
|
|
242
|
+
const body = queue.then(
|
|
243
|
+
() => render({
|
|
244
|
+
incomplete: /* @__PURE__ */ __name(() => {
|
|
245
|
+
complete = false;
|
|
246
|
+
}, "incomplete")
|
|
247
|
+
})
|
|
248
|
+
);
|
|
219
249
|
queue = body.catch(() => {
|
|
220
250
|
});
|
|
221
|
-
const pending = { body, expires: Number.POSITIVE_INFINITY };
|
|
251
|
+
const pending = { body, expires: Number.POSITIVE_INFINITY, complete: /* @__PURE__ */ __name(() => complete, "complete") };
|
|
222
252
|
entries.set(origin, pending);
|
|
223
253
|
if (entries.size > maxEntries) entries.delete(entries.keys().next().value);
|
|
224
254
|
body.then(
|
|
225
255
|
() => {
|
|
226
256
|
if (entries.get(origin) !== pending) return;
|
|
227
|
-
if (ttl > 0) pending.expires = now() + ttl;
|
|
257
|
+
if (ttl > 0 && complete) pending.expires = now() + ttl;
|
|
228
258
|
else entries.delete(origin);
|
|
229
259
|
},
|
|
230
260
|
() => {
|
|
231
261
|
if (entries.get(origin) === pending) entries.delete(origin);
|
|
232
262
|
}
|
|
233
263
|
);
|
|
234
|
-
return body;
|
|
264
|
+
return settle(body, pending.complete, onSettled);
|
|
235
265
|
};
|
|
236
266
|
}
|
|
237
267
|
__name(createFarmLlmsFullRenderer, "createFarmLlmsFullRenderer");
|