@vercel/geistdocs 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +1 -1
- package/dist/internal/page-tree-visibility.d.ts +4 -0
- package/dist/internal/page-tree-visibility.d.ts.map +1 -0
- package/dist/internal/page-tree-visibility.js +42 -0
- package/dist/internal/sidebar-tree.d.ts +7 -0
- package/dist/internal/sidebar-tree.d.ts.map +1 -1
- package/dist/internal/sidebar-tree.js +7 -0
- package/dist/internal/sidebar.d.ts.map +1 -1
- package/dist/internal/sidebar.js +3 -3
- package/dist/page-visibility.d.ts +7 -0
- package/dist/page-visibility.d.ts.map +1 -1
- package/dist/pages/docs.d.ts +23 -21
- package/dist/pages/docs.d.ts.map +1 -1
- package/dist/pages/docs.js +44 -15
- package/dist/proxy.d.ts +4 -1
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +42 -12
- package/dist/routes/chat.d.ts +4 -1
- package/dist/routes/chat.d.ts.map +1 -1
- package/dist/routes/chat.js +58 -25
- package/dist/routes/llms.d.ts +14 -10
- package/dist/routes/llms.d.ts.map +1 -1
- package/dist/routes/llms.js +50 -8
- package/dist/routes/search-export.d.ts +3 -1
- package/dist/routes/search-export.d.ts.map +1 -1
- package/dist/routes/search-export.js +4 -3
- package/dist/routes/search.d.ts +3 -1
- package/dist/routes/search.d.ts.map +1 -1
- package/dist/routes/search.js +4 -3
- package/dist/routes/sitemap.d.ts +3 -2
- package/dist/routes/sitemap.d.ts.map +1 -1
- package/dist/routes/sitemap.js +7 -4
- package/dist/source.d.ts +1 -0
- package/dist/source.d.ts.map +1 -1
- package/docs/agents.md +1 -1
- package/docs/llms.txt +74 -1
- package/docs/manifest.json +1 -1
- package/docs/pages/configuration.md +53 -0
- package/docs/pages/llms-txt.md +2 -0
- package/docs/pages/md.md +4 -0
- package/docs/pages/proxy.md +14 -0
- package/package.json +1 -1
- package/template/AGENTS.md +2 -1
- package/template/content/docs/configuration.mdx +53 -0
- package/template/content/docs/llms-txt.mdx +2 -0
- package/template/content/docs/md.mdx +4 -0
- package/template/content/docs/proxy.mdx +14 -0
- package/template/package.json +1 -1
package/dist/proxy.js
CHANGED
|
@@ -121,7 +121,7 @@ const getLocalizedPathname = (pathname, languages, defaultLanguage) => {
|
|
|
121
121
|
pathname: `/${segments.slice(1).join("/")}`,
|
|
122
122
|
};
|
|
123
123
|
};
|
|
124
|
-
export const createProxy = ({ additionalMarkdownRoutes, after, before, config, markdownNotFound, markdownRoutes, trackMarkdownRequest, }) => {
|
|
124
|
+
export const createProxy = ({ additionalMarkdownRoutes, after, before, config, markdownNotFound, markdownRoutes, trackMarkdownRequest, transformRewrite, }) => {
|
|
125
125
|
const agentEnabled = config.agent !== undefined && config.agent.enabled !== false;
|
|
126
126
|
const contentRouteMappings = [
|
|
127
127
|
...(additionalMarkdownRoutes ?? []),
|
|
@@ -195,7 +195,10 @@ export const createProxy = ({ additionalMarkdownRoutes, after, before, config, m
|
|
|
195
195
|
}
|
|
196
196
|
return null;
|
|
197
197
|
};
|
|
198
|
-
const
|
|
198
|
+
const resolveInternalPathname = async (pathname, proxyContext) => transformRewrite
|
|
199
|
+
? transformRewrite(pathname, proxyContext)
|
|
200
|
+
: pathname;
|
|
201
|
+
const tryMarkdownRewrite = async (request, context, proxyContext, pathname, language, options) => {
|
|
199
202
|
const result = resolveMarkdownRewrite(pathname, language);
|
|
200
203
|
if (!result) {
|
|
201
204
|
return null;
|
|
@@ -212,7 +215,7 @@ export const createProxy = ({ additionalMarkdownRoutes, after, before, config, m
|
|
|
212
215
|
if (configuredBasePath) {
|
|
213
216
|
rewriteUrl.basePath = configuredBasePath;
|
|
214
217
|
}
|
|
215
|
-
rewriteUrl.pathname = result;
|
|
218
|
+
rewriteUrl.pathname = await resolveInternalPathname(result, proxyContext);
|
|
216
219
|
const response = NextResponse.rewrite(rewriteUrl);
|
|
217
220
|
// The destination route adds a canonical only after it resolves a page.
|
|
218
221
|
// The proxy cannot distinguish valid pages from smart not-found responses.
|
|
@@ -221,26 +224,26 @@ export const createProxy = ({ additionalMarkdownRoutes, after, before, config, m
|
|
|
221
224
|
};
|
|
222
225
|
const isMdExtensionRequest = (pathname, language) => (pathname.endsWith(".md") || pathname.endsWith(".mdx")) &&
|
|
223
226
|
Boolean(resolveMarkdownRewrite(pathname.replace(MDX_EXTENSION_PATTERN, ""), language));
|
|
224
|
-
const handleMarkdownExtensionRequest = (request, context, pathname, language, trackPath) => {
|
|
227
|
+
const handleMarkdownExtensionRequest = (request, context, proxyContext, pathname, language, trackPath) => {
|
|
225
228
|
if (!isMdExtensionRequest(pathname, language)) {
|
|
226
229
|
return null;
|
|
227
230
|
}
|
|
228
|
-
return tryMarkdownRewrite(request, context, pathname.replace(MDX_EXTENSION_PATTERN, ""), language, {
|
|
231
|
+
return tryMarkdownRewrite(request, context, proxyContext, pathname.replace(MDX_EXTENSION_PATTERN, ""), language, {
|
|
229
232
|
requestType: "md-url",
|
|
230
233
|
trackPath,
|
|
231
234
|
});
|
|
232
235
|
};
|
|
233
|
-
const handleNegotiatedMarkdownRequest = (request, context, pathname, language, trackPath, decision) => {
|
|
236
|
+
const handleNegotiatedMarkdownRequest = (request, context, proxyContext, pathname, language, trackPath, decision) => {
|
|
234
237
|
if (!decision.serve) {
|
|
235
238
|
return null;
|
|
236
239
|
}
|
|
237
|
-
return tryMarkdownRewrite(request, context, pathname, language, {
|
|
240
|
+
return tryMarkdownRewrite(request, context, proxyContext, pathname, language, {
|
|
238
241
|
requestType: decision.reason === "agent" ? "agent-rewrite" : "header-negotiated",
|
|
239
242
|
detectionMethod: decision.reason === "agent" ? decision.detection.method : undefined,
|
|
240
243
|
trackPath,
|
|
241
244
|
});
|
|
242
245
|
};
|
|
243
|
-
const handleMarkdownNegotiation = (request, context, pathname) => {
|
|
246
|
+
const handleMarkdownNegotiation = async (request, context, proxyContext, pathname) => {
|
|
244
247
|
if (!MARKDOWN_REQUEST_METHODS.has(request.method)) {
|
|
245
248
|
return null;
|
|
246
249
|
}
|
|
@@ -249,14 +252,14 @@ export const createProxy = ({ additionalMarkdownRoutes, after, before, config, m
|
|
|
249
252
|
PACKAGE_ROUTE_PATHS.has(localized.pathname)) {
|
|
250
253
|
return null;
|
|
251
254
|
}
|
|
252
|
-
const extensionResponse = handleMarkdownExtensionRequest(request, context, localized.pathname, localized.language, pathname);
|
|
255
|
+
const extensionResponse = await handleMarkdownExtensionRequest(request, context, proxyContext, localized.pathname, localized.language, pathname);
|
|
253
256
|
if (extensionResponse) {
|
|
254
257
|
return extensionResponse;
|
|
255
258
|
}
|
|
256
259
|
const markdownDecision = getMarkdownDecision(request);
|
|
257
260
|
if (resolveMarkdownRewrite(localized.pathname, localized.language) &&
|
|
258
261
|
!localized.pathname.includes("/llms.mdx/")) {
|
|
259
|
-
const negotiatedResponse = handleNegotiatedMarkdownRequest(request, context, localized.pathname, localized.language, pathname, markdownDecision);
|
|
262
|
+
const negotiatedResponse = await handleNegotiatedMarkdownRequest(request, context, proxyContext, localized.pathname, localized.language, pathname, markdownDecision);
|
|
260
263
|
if (negotiatedResponse) {
|
|
261
264
|
return negotiatedResponse;
|
|
262
265
|
}
|
|
@@ -277,6 +280,33 @@ export const createProxy = ({ additionalMarkdownRoutes, after, before, config, m
|
|
|
277
280
|
}
|
|
278
281
|
return response;
|
|
279
282
|
};
|
|
283
|
+
const transformI18nResponse = async (response, request, proxyContext, pathname) => {
|
|
284
|
+
if (!transformRewrite || response.headers.has("location")) {
|
|
285
|
+
return response;
|
|
286
|
+
}
|
|
287
|
+
const rewrite = response.headers.get("x-middleware-rewrite");
|
|
288
|
+
let internalPathname = pathname;
|
|
289
|
+
let rewriteUrl = new URL(request.url);
|
|
290
|
+
if (rewrite) {
|
|
291
|
+
rewriteUrl = new URL(rewrite);
|
|
292
|
+
internalPathname = rewriteUrl.pathname;
|
|
293
|
+
}
|
|
294
|
+
if (configuredBasePath &&
|
|
295
|
+
(internalPathname === configuredBasePath ||
|
|
296
|
+
internalPathname.startsWith(`${configuredBasePath}/`))) {
|
|
297
|
+
internalPathname =
|
|
298
|
+
internalPathname.slice(configuredBasePath.length) || "/";
|
|
299
|
+
}
|
|
300
|
+
const transformed = await resolveInternalPathname(internalPathname, proxyContext);
|
|
301
|
+
rewriteUrl.pathname = getPublicPath(transformed, configuredBasePath);
|
|
302
|
+
const transformedResponse = NextResponse.rewrite(rewriteUrl);
|
|
303
|
+
for (const [key, value] of response.headers) {
|
|
304
|
+
if (key !== "x-middleware-next" && key !== "x-middleware-rewrite") {
|
|
305
|
+
transformedResponse.headers.set(key, value);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return transformedResponse;
|
|
309
|
+
};
|
|
280
310
|
return async (request, context) => {
|
|
281
311
|
const pathname = request.nextUrl.pathname;
|
|
282
312
|
const proxyContext = {
|
|
@@ -298,7 +328,7 @@ export const createProxy = ({ additionalMarkdownRoutes, after, before, config, m
|
|
|
298
328
|
acceptHeader: request.headers.get("accept"),
|
|
299
329
|
});
|
|
300
330
|
}
|
|
301
|
-
const markdownResponse = handleMarkdownNegotiation(request, context, pathname);
|
|
331
|
+
const markdownResponse = await handleMarkdownNegotiation(request, context, proxyContext, pathname);
|
|
302
332
|
if (markdownResponse) {
|
|
303
333
|
return markdownResponse;
|
|
304
334
|
}
|
|
@@ -306,7 +336,7 @@ export const createProxy = ({ additionalMarkdownRoutes, after, before, config, m
|
|
|
306
336
|
if (afterResponse) {
|
|
307
337
|
return afterResponse;
|
|
308
338
|
}
|
|
309
|
-
const response = await handleI18nRequest(request, context);
|
|
339
|
+
const response = await transformI18nResponse(await handleI18nRequest(request, context), request, proxyContext, pathname);
|
|
310
340
|
if (MARKDOWN_REQUEST_METHODS.has(request.method) &&
|
|
311
341
|
resolveMarkdownRewrite(localized.pathname, localized.language)) {
|
|
312
342
|
applyMarkdownHeaders(response.headers);
|
package/dist/routes/chat.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type LanguageModel } from "ai";
|
|
2
2
|
import { type GeistdocsConfig } from "../config";
|
|
3
3
|
import { type ChatMixedbreadOptions } from "../internal/chat-retrieval";
|
|
4
|
+
import { type GeistdocsPageFilter } from "../page-visibility";
|
|
4
5
|
import type { GeistdocsSourceBundle } from "../source";
|
|
5
6
|
type SourceBundle = GeistdocsSourceBundle;
|
|
6
7
|
interface ChatProxyConfig {
|
|
@@ -25,6 +26,8 @@ interface CreateChatRouteOptions {
|
|
|
25
26
|
* `config.ai.eveAgent`. Mutually exclusive with `proxy`.
|
|
26
27
|
*/
|
|
27
28
|
eveAgent?: ChatEveAgentOptions;
|
|
29
|
+
/** Narrows the stable public corpus available to Ask AI. */
|
|
30
|
+
filterPage?: GeistdocsPageFilter;
|
|
28
31
|
/**
|
|
29
32
|
* Server-only Mixedbread overrides. Environment variables are used when
|
|
30
33
|
* these values are omitted.
|
|
@@ -42,7 +45,7 @@ interface CreateChatRouteOptions {
|
|
|
42
45
|
source?: SourceBundle;
|
|
43
46
|
sources?: SourceBundle[];
|
|
44
47
|
}
|
|
45
|
-
export declare const createChatRoute: ({ config, eveAgent, mixedbread, model, proxy, source, sources, }: CreateChatRouteOptions) => {
|
|
48
|
+
export declare const createChatRoute: ({ config, eveAgent, filterPage, mixedbread, model, proxy, source, sources, }: CreateChatRouteOptions) => {
|
|
46
49
|
POST: (req: Request) => Promise<Response>;
|
|
47
50
|
maxDuration: 800;
|
|
48
51
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/routes/chat.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,aAAa,EAQnB,MAAM,IAAI,CAAC;AAGZ,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,WAAW,CAAC;AAKhE,OAAO,EAEL,KAAK,qBAAqB,EAG3B,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/routes/chat.ts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/dist/routes/chat.js
CHANGED
|
@@ -6,7 +6,7 @@ import { getPublicPath } from "../config";
|
|
|
6
6
|
import { createSourceChunk, createSourceChunks, } from "../internal/chat/source-chunks";
|
|
7
7
|
import { createChatDocumentSearch, } from "../internal/chat-retrieval";
|
|
8
8
|
import { buildEveAgentTranscript, capLastUserMessageText, getEveAgentSessionHandle, resolveEveAgentUrl, runEveAgentTurn, } from "../internal/eve-agent";
|
|
9
|
-
import { isPageVisibleForSurface } from "../page-visibility";
|
|
9
|
+
import { isPageVisibleForSurface, } from "../page-visibility";
|
|
10
10
|
const DEFAULT_CHAT_MODEL = "openai/gpt-5.6-sol";
|
|
11
11
|
const MAX_CONTEXT_CHARS = 1500;
|
|
12
12
|
const MAX_EVE_AGENT_MESSAGE_CHARS = 4000;
|
|
@@ -79,10 +79,12 @@ const isChatRequestBody = (value) => typeof value === "object" &&
|
|
|
79
79
|
Array.isArray(value.messages);
|
|
80
80
|
const getPageData = (page) => page.data;
|
|
81
81
|
const getStructuredContent = (page) => JSON.stringify(getPageData(page).structuredData?.contents ?? "");
|
|
82
|
-
const
|
|
82
|
+
const isChatPageVisible = (page, lang, source, filterPage) => isPageVisibleForSurface(page, "chat") &&
|
|
83
|
+
(filterPage?.(page, { lang, source }) ?? true);
|
|
84
|
+
const createSearchServer = (sources, lang, filterPage) => {
|
|
83
85
|
const indexes = sources.flatMap((source) => source.source
|
|
84
86
|
.getPages(lang)
|
|
85
|
-
.filter((page) =>
|
|
87
|
+
.filter((page) => isChatPageVisible(page, lang, source, filterPage))
|
|
86
88
|
.map((page) => {
|
|
87
89
|
const data = getPageData(page);
|
|
88
90
|
const structuredData = data.structuredData ??
|
|
@@ -97,14 +99,18 @@ const createSearchServer = (sources, lang) => {
|
|
|
97
99
|
}));
|
|
98
100
|
return initAdvancedSearch({ indexes });
|
|
99
101
|
};
|
|
100
|
-
const resolveSearchResult = ({ basePath, content, lang, sources, url, }) => {
|
|
101
|
-
const
|
|
102
|
-
.map((source) =>
|
|
103
|
-
.
|
|
104
|
-
|
|
102
|
+
const resolveSearchResult = ({ basePath, content, filterPage, lang, sources, url, }) => {
|
|
103
|
+
const match = sources
|
|
104
|
+
.map((source) => ({
|
|
105
|
+
result: source.source.getPageByHref(url, { language: lang }),
|
|
106
|
+
source,
|
|
107
|
+
}))
|
|
108
|
+
.find(({ result }) => result?.page);
|
|
109
|
+
if (!(match?.result?.page &&
|
|
110
|
+
isChatPageVisible(match.result.page, lang, match.source, filterPage))) {
|
|
105
111
|
return null;
|
|
106
112
|
}
|
|
107
|
-
const { page } = result;
|
|
113
|
+
const { page } = match.result;
|
|
108
114
|
const data = getPageData(page);
|
|
109
115
|
return {
|
|
110
116
|
title: data.title ?? page.url,
|
|
@@ -114,14 +120,15 @@ const resolveSearchResult = ({ basePath, content, lang, sources, url, }) => {
|
|
|
114
120
|
url: getPublicPath(page.url, basePath),
|
|
115
121
|
};
|
|
116
122
|
};
|
|
117
|
-
const searchDocsWithOrama = async ({ basePath, lang, limit, query, sources, }) => {
|
|
118
|
-
const searchServer = createSearchServer(sources, lang);
|
|
123
|
+
const searchDocsWithOrama = async ({ basePath, filterPage, lang, limit, query, sources, }) => {
|
|
124
|
+
const searchServer = createSearchServer(sources, lang, filterPage);
|
|
119
125
|
const results = await searchServer.search(query);
|
|
120
126
|
const seenSlugs = new Set();
|
|
121
127
|
return results
|
|
122
128
|
.map(({ content, type, url }) => resolveSearchResult({
|
|
123
129
|
basePath,
|
|
124
130
|
content: type === "text" ? content : undefined,
|
|
131
|
+
filterPage,
|
|
125
132
|
lang,
|
|
126
133
|
sources,
|
|
127
134
|
url,
|
|
@@ -136,15 +143,16 @@ const searchDocsWithOrama = async ({ basePath, lang, limit, query, sources, }) =
|
|
|
136
143
|
})
|
|
137
144
|
.slice(0, limit);
|
|
138
145
|
};
|
|
139
|
-
const createDocumentSearch = ({ config, mixedbread, sources, }) => {
|
|
146
|
+
const createDocumentSearch = ({ config, filterPage, mixedbread, sources, }) => {
|
|
140
147
|
const fallback = ({ lang, limit, query }) => searchDocsWithOrama({
|
|
141
148
|
basePath: config.basePath,
|
|
149
|
+
filterPage,
|
|
142
150
|
lang,
|
|
143
151
|
limit,
|
|
144
152
|
query,
|
|
145
153
|
sources,
|
|
146
154
|
});
|
|
147
|
-
|
|
155
|
+
const search = createChatDocumentSearch({
|
|
148
156
|
fallback,
|
|
149
157
|
mixedbread: {
|
|
150
158
|
...mixedbread,
|
|
@@ -162,6 +170,18 @@ const createDocumentSearch = ({ config, mixedbread, sources, }) => {
|
|
|
162
170
|
provider: config.ai?.retrieval,
|
|
163
171
|
siteId: config.siteId,
|
|
164
172
|
});
|
|
173
|
+
return async (input) => {
|
|
174
|
+
const documents = await search({ ...input, limit: input.limit * 3 });
|
|
175
|
+
return documents
|
|
176
|
+
.filter((document) => sources.some((source) => {
|
|
177
|
+
const result = source.source.getPageByHref(document.slug, {
|
|
178
|
+
language: input.lang,
|
|
179
|
+
});
|
|
180
|
+
return Boolean(result?.page &&
|
|
181
|
+
isChatPageVisible(result.page, input.lang, source, filterPage));
|
|
182
|
+
}))
|
|
183
|
+
.slice(0, input.limit);
|
|
184
|
+
};
|
|
165
185
|
};
|
|
166
186
|
const formatDocForContext = (doc) => `**${doc.title}**\nURL: ${doc.url}\n${doc.description || ""}\n\n${doc.content.slice(0, MAX_CONTEXT_CHARS)}${doc.content.length > MAX_CONTEXT_CHARS ? "..." : ""}`;
|
|
167
187
|
const getRouteCandidates = ({ basePath, currentRoute, lang, }) => {
|
|
@@ -170,18 +190,19 @@ const getRouteCandidates = ({ basePath, currentRoute, lang, }) => {
|
|
|
170
190
|
const withoutLanguage = stripLanguagePrefix(withoutBasePath, lang);
|
|
171
191
|
return Array.from(new Set([pathname, withoutBasePath, withoutLanguage]));
|
|
172
192
|
};
|
|
173
|
-
const findCurrentPage = ({ basePath, currentRoute, lang, sources, }) => {
|
|
193
|
+
const findCurrentPage = ({ basePath, currentRoute, filterPage, lang, sources, }) => {
|
|
174
194
|
const candidates = getRouteCandidates({ basePath, currentRoute, lang });
|
|
175
195
|
for (const source of sources) {
|
|
176
196
|
for (const candidate of candidates) {
|
|
177
197
|
const result = source.source.getPageByHref(candidate, { language: lang });
|
|
178
|
-
if (result?.page &&
|
|
198
|
+
if (result?.page &&
|
|
199
|
+
isChatPageVisible(result.page, lang, source, filterPage)) {
|
|
179
200
|
return { page: result.page, source };
|
|
180
201
|
}
|
|
181
202
|
}
|
|
182
203
|
const page = source.source
|
|
183
204
|
.getPages(lang)
|
|
184
|
-
.filter((entry) =>
|
|
205
|
+
.filter((entry) => isChatPageVisible(entry, lang, source, filterPage))
|
|
185
206
|
.find((entry) => candidates.includes(normalizePathname(entry.url)));
|
|
186
207
|
if (page) {
|
|
187
208
|
return { page, source };
|
|
@@ -189,7 +210,7 @@ const findCurrentPage = ({ basePath, currentRoute, lang, sources, }) => {
|
|
|
189
210
|
}
|
|
190
211
|
return null;
|
|
191
212
|
};
|
|
192
|
-
const getCurrentPageDoc = async ({ basePath, currentRoute, lang, pageContext, sources, }) => {
|
|
213
|
+
const getCurrentPageDoc = async ({ basePath, currentRoute, filterPage, lang, pageContext, sources, }) => {
|
|
193
214
|
if (pageContext) {
|
|
194
215
|
return {
|
|
195
216
|
title: pageContext.title,
|
|
@@ -199,7 +220,13 @@ const getCurrentPageDoc = async ({ basePath, currentRoute, lang, pageContext, so
|
|
|
199
220
|
url: pageContext.url,
|
|
200
221
|
};
|
|
201
222
|
}
|
|
202
|
-
const result = findCurrentPage({
|
|
223
|
+
const result = findCurrentPage({
|
|
224
|
+
basePath,
|
|
225
|
+
currentRoute,
|
|
226
|
+
filterPage,
|
|
227
|
+
lang,
|
|
228
|
+
sources,
|
|
229
|
+
});
|
|
203
230
|
if (!result) {
|
|
204
231
|
return null;
|
|
205
232
|
}
|
|
@@ -213,7 +240,7 @@ const getCurrentPageDoc = async ({ basePath, currentRoute, lang, pageContext, so
|
|
|
213
240
|
};
|
|
214
241
|
};
|
|
215
242
|
const isFirstUserMessage = (messages) => messages.filter((message) => message.role === "user").length === 1;
|
|
216
|
-
const buildProxyMessages = async ({ actualMessages, config, currentRoute, defaultLanguage, languages, pageContext, routeSources, searchDocuments, }) => {
|
|
243
|
+
const buildProxyMessages = async ({ actualMessages, config, currentRoute, defaultLanguage, filterPage, languages, pageContext, routeSources, searchDocuments, }) => {
|
|
217
244
|
if (!isFirstUserMessage(actualMessages)) {
|
|
218
245
|
return { messages: actualMessages, sourceDocs: [] };
|
|
219
246
|
}
|
|
@@ -231,6 +258,7 @@ const buildProxyMessages = async ({ actualMessages, config, currentRoute, defaul
|
|
|
231
258
|
const currentPageDoc = await getCurrentPageDoc({
|
|
232
259
|
basePath: config.basePath,
|
|
233
260
|
currentRoute,
|
|
261
|
+
filterPage,
|
|
234
262
|
lang,
|
|
235
263
|
pageContext,
|
|
236
264
|
sources: routeSources,
|
|
@@ -405,7 +433,7 @@ You are a helpful assistant specializing in answering questions strictly. If inf
|
|
|
405
433
|
- Be friendly, clear, and specific.`;
|
|
406
434
|
return [basePrompt, config.ai?.prompt].filter(Boolean).join("\n\n");
|
|
407
435
|
};
|
|
408
|
-
const createTools = (writer, sources, searchDocuments, defaultLanguage, basePath) => {
|
|
436
|
+
const createTools = (writer, sources, searchDocuments, defaultLanguage, basePath, filterPage) => {
|
|
409
437
|
const log = (message) => {
|
|
410
438
|
console.log(`[Geistdocs chat] ${message}`);
|
|
411
439
|
};
|
|
@@ -461,7 +489,7 @@ const createTools = (writer, sources, searchDocuments, defaultLanguage, basePath
|
|
|
461
489
|
const doc = sources
|
|
462
490
|
.flatMap((source) => source.source
|
|
463
491
|
.getPages(lang)
|
|
464
|
-
.filter((page) =>
|
|
492
|
+
.filter((page) => isChatPageVisible(page, lang, source, filterPage))
|
|
465
493
|
.map((page) => ({ page, source })))
|
|
466
494
|
.find(({ page }) => page.url === sourceSlug || page.url.endsWith(sourceSlug));
|
|
467
495
|
if (!doc) {
|
|
@@ -490,7 +518,7 @@ const createTools = (writer, sources, searchDocuments, defaultLanguage, basePath
|
|
|
490
518
|
execute: ({ lang }) => {
|
|
491
519
|
const pages = sources.flatMap((source) => source.source
|
|
492
520
|
.getPages(lang)
|
|
493
|
-
.filter((page) =>
|
|
521
|
+
.filter((page) => isChatPageVisible(page, lang, source, filterPage)));
|
|
494
522
|
const docsList = pages
|
|
495
523
|
.map((doc) => `- **${doc.data.title}** (${getPublicPath(doc.url, basePath)}): ${doc.data.description}`)
|
|
496
524
|
.join("\n");
|
|
@@ -507,13 +535,14 @@ const createChatErrorResponse = (error, status) => new Response(JSON.stringify({
|
|
|
507
535
|
status,
|
|
508
536
|
headers: { "Content-Type": "application/json" },
|
|
509
537
|
});
|
|
510
|
-
const createEveAgentResponse = async ({ actualMessages, agentUrl, config, currentRoute, defaultLanguage, eveAgent, languages, messages, pageContext, req, routeSources, searchDocuments, }) => {
|
|
538
|
+
const createEveAgentResponse = async ({ actualMessages, agentUrl, config, currentRoute, defaultLanguage, eveAgent, filterPage, languages, messages, pageContext, req, routeSources, searchDocuments, }) => {
|
|
511
539
|
const cappedMessages = capLastUserMessageText(actualMessages, MAX_EVE_AGENT_MESSAGE_CHARS);
|
|
512
540
|
const { messages: contextMessages, sourceDocs } = await buildProxyMessages({
|
|
513
541
|
actualMessages: cappedMessages,
|
|
514
542
|
config,
|
|
515
543
|
currentRoute,
|
|
516
544
|
defaultLanguage,
|
|
545
|
+
filterPage,
|
|
517
546
|
languages,
|
|
518
547
|
pageContext,
|
|
519
548
|
routeSources,
|
|
@@ -559,11 +588,12 @@ const resolveSources = (source, sources) => {
|
|
|
559
588
|
}
|
|
560
589
|
return resolvedSources;
|
|
561
590
|
};
|
|
562
|
-
export const createChatRoute = ({ config, eveAgent, mixedbread, model = DEFAULT_CHAT_MODEL, proxy, source, sources, }) => {
|
|
591
|
+
export const createChatRoute = ({ config, eveAgent, filterPage, mixedbread, model = DEFAULT_CHAT_MODEL, proxy, source, sources, }) => {
|
|
563
592
|
const { defaultLanguage, languages } = getLanguages(config);
|
|
564
593
|
const routeSources = resolveSources(source, sources);
|
|
565
594
|
const searchDocuments = createDocumentSearch({
|
|
566
595
|
config,
|
|
596
|
+
filterPage,
|
|
567
597
|
mixedbread,
|
|
568
598
|
sources: routeSources,
|
|
569
599
|
});
|
|
@@ -593,6 +623,7 @@ export const createChatRoute = ({ config, eveAgent, mixedbread, model = DEFAULT_
|
|
|
593
623
|
currentRoute,
|
|
594
624
|
defaultLanguage,
|
|
595
625
|
eveAgent,
|
|
626
|
+
filterPage,
|
|
596
627
|
languages,
|
|
597
628
|
messages,
|
|
598
629
|
pageContext,
|
|
@@ -607,6 +638,7 @@ export const createChatRoute = ({ config, eveAgent, mixedbread, model = DEFAULT_
|
|
|
607
638
|
config,
|
|
608
639
|
currentRoute,
|
|
609
640
|
defaultLanguage,
|
|
641
|
+
filterPage,
|
|
610
642
|
languages,
|
|
611
643
|
pageContext,
|
|
612
644
|
routeSources,
|
|
@@ -648,6 +680,7 @@ export const createChatRoute = ({ config, eveAgent, mixedbread, model = DEFAULT_
|
|
|
648
680
|
const contextDoc = await getCurrentPageDoc({
|
|
649
681
|
basePath: config.basePath,
|
|
650
682
|
currentRoute,
|
|
683
|
+
filterPage,
|
|
651
684
|
lang: getRequestLanguage({
|
|
652
685
|
basePath: config.basePath,
|
|
653
686
|
currentRoute,
|
|
@@ -685,7 +718,7 @@ export const createChatRoute = ({ config, eveAgent, mixedbread, model = DEFAULT_
|
|
|
685
718
|
model,
|
|
686
719
|
messages: modelMessages,
|
|
687
720
|
stopWhen: stepCountIs(10),
|
|
688
|
-
tools: createTools(writer, routeSources, searchDocuments, defaultLanguage, config.basePath),
|
|
721
|
+
tools: createTools(writer, routeSources, searchDocuments, defaultLanguage, config.basePath, filterPage),
|
|
689
722
|
system: createSystemPrompt(currentRoute ?? "/", config),
|
|
690
723
|
prepareStep: ({ stepNumber }) => {
|
|
691
724
|
if (stepNumber === 0) {
|
package/dist/routes/llms.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { NextRequest } from "next/server";
|
|
2
2
|
import { type GeistdocsConfig } from "../config.js";
|
|
3
|
+
import { type GeistdocsPageFilter } from "../page-visibility.js";
|
|
3
4
|
import type { GeistdocsSourceBundle } from "../source.js";
|
|
4
5
|
type SourceBundle = GeistdocsSourceBundle;
|
|
5
6
|
type GeistdocsPage = NonNullable<ReturnType<SourceBundle["source"]["getPage"]>>;
|
|
6
|
-
interface DocsMarkdownParams {
|
|
7
|
+
export interface DocsMarkdownParams extends Record<string, string | string[] | undefined> {
|
|
7
8
|
lang: string;
|
|
8
9
|
slug?: string[];
|
|
9
10
|
}
|
|
@@ -14,9 +15,7 @@ interface MarkdownTransformContext {
|
|
|
14
15
|
}
|
|
15
16
|
type MarkdownTransform = (markdown: string, context: MarkdownTransformContext) => Promise<string> | string;
|
|
16
17
|
interface CreateLlmsRouteOptions {
|
|
17
|
-
filterPage?:
|
|
18
|
-
lang: string;
|
|
19
|
-
}) => boolean;
|
|
18
|
+
filterPage?: GeistdocsPageFilter;
|
|
20
19
|
source?: SourceBundle;
|
|
21
20
|
sources?: SourceBundle[];
|
|
22
21
|
transform?: MarkdownTransform;
|
|
@@ -29,7 +28,15 @@ export declare const createLlmsRoute: ({ filterPage, source, sources, transform,
|
|
|
29
28
|
}) => Promise<Response>;
|
|
30
29
|
revalidate: false;
|
|
31
30
|
};
|
|
32
|
-
export interface
|
|
31
|
+
export interface MarkdownPageAccessContext<Params extends DocsMarkdownParams = DocsMarkdownParams> {
|
|
32
|
+
params: Params;
|
|
33
|
+
request: Request;
|
|
34
|
+
source: SourceBundle;
|
|
35
|
+
}
|
|
36
|
+
export type MarkdownPageAccessFilter<Params extends DocsMarkdownParams = DocsMarkdownParams> = (page: GeistdocsPage, context: MarkdownPageAccessContext<Params>) => boolean | Promise<boolean>;
|
|
37
|
+
export interface CreateDocsMarkdownRouteOptions<Params extends DocsMarkdownParams = DocsMarkdownParams> {
|
|
38
|
+
/** Return false to serve the same response as a missing page. */
|
|
39
|
+
canViewPage?: MarkdownPageAccessFilter<Params>;
|
|
33
40
|
config?: Pick<GeistdocsConfig, "basePath" | "defaultLanguage" | "siteUrl" | "translations">;
|
|
34
41
|
filterStaticParams?: (params: DocsMarkdownParams) => boolean;
|
|
35
42
|
/** Customize the agent-readable Markdown response for missing pages, or disable it. */
|
|
@@ -63,12 +70,9 @@ export interface MarkdownNotFoundOptions {
|
|
|
63
70
|
*/
|
|
64
71
|
status?: 200 | 404 | 410;
|
|
65
72
|
}
|
|
66
|
-
export declare const createDocsMarkdownRoute: ({ config, filterStaticParams, notFound: notFoundOptions, source, sources, transform, }: CreateDocsMarkdownRouteOptions) => {
|
|
73
|
+
export declare const createDocsMarkdownRoute: <Params extends DocsMarkdownParams = DocsMarkdownParams>({ canViewPage, config, filterStaticParams, notFound: notFoundOptions, source, sources, transform, }: CreateDocsMarkdownRouteOptions<Params>) => {
|
|
67
74
|
GET: (request: Request, { params }: {
|
|
68
|
-
params: Promise<
|
|
69
|
-
lang: string;
|
|
70
|
-
slug?: string[];
|
|
71
|
-
}>;
|
|
75
|
+
params: Promise<Params>;
|
|
72
76
|
}) => Promise<Response>;
|
|
73
77
|
generateStaticParams: ({ params, }?: {
|
|
74
78
|
params?: Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llms.d.ts","sourceRoot":"","sources":["../../src/routes/llms.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"llms.d.ts","sourceRoot":"","sources":["../../src/routes/llms.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,cAAc,CAAC;AAQtB,OAAO,EACL,KAAK,mBAAmB,EAEzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,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N5B,OAAO,cACJ;QAAE,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;KAAE;yCAwEtC;QACD,MAAM,CAAC,EAAE,OAAO,CAAC;YAAE,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KACrC;;CAgBF,CAAC"}
|
package/dist/routes/llms.js
CHANGED
|
@@ -4,10 +4,12 @@ import { getPublicPath, normalizeBasePath, withBasePath, } from "../config.js";
|
|
|
4
4
|
import { resolveAgentProductContext } from "../internal/agent-product.js";
|
|
5
5
|
import { resolvePageMarkdownUrl } from "../internal/markdown-url.js";
|
|
6
6
|
import { findSmartNotFoundSuggestions, renderSmartNotFoundMarkdown, } from "../internal/smart-not-found.js";
|
|
7
|
-
import { isPageVisibleForSurface } from "../page-visibility.js";
|
|
7
|
+
import { isPageVisibleForSurface, } from "../page-visibility.js";
|
|
8
8
|
const INDEX_MARKDOWN_PATTERN = /\/index\.md$/;
|
|
9
9
|
const MARKDOWN_PATTERN = /\.md$/;
|
|
10
10
|
const MARKDOWN_CACHE_CONTROL = "public, max-age=0, s-maxage=86400, stale-while-revalidate=604800";
|
|
11
|
+
const DEFAULT_MAX_SUGGESTIONS = 5;
|
|
12
|
+
const SUGGESTION_ACCESS_CANDIDATE_MULTIPLIER = 3;
|
|
11
13
|
const resolveSources = (source, sources, caller) => {
|
|
12
14
|
const resolvedSources = sources ?? (source ? [source] : []);
|
|
13
15
|
if (resolvedSources.length === 0) {
|
|
@@ -138,7 +140,7 @@ export const createLlmsRoute = ({ filterPage, source, sources, transform, }) =>
|
|
|
138
140
|
const scanned = await Promise.all(routeSources.flatMap((entry) => entry.source
|
|
139
141
|
.getPages(lang)
|
|
140
142
|
.filter((page) => isPageVisibleForSurface(page, "llms") &&
|
|
141
|
-
(filterPage?.(page, { lang }) ?? true))
|
|
143
|
+
(filterPage?.(page, { lang, source: entry }) ?? true))
|
|
142
144
|
.map(async (page) => {
|
|
143
145
|
const rendered = await entry.getPageMarkdown(page);
|
|
144
146
|
return transform
|
|
@@ -157,7 +159,7 @@ export const createLlmsRoute = ({ filterPage, source, sources, transform, }) =>
|
|
|
157
159
|
revalidate: false,
|
|
158
160
|
};
|
|
159
161
|
};
|
|
160
|
-
export const createDocsMarkdownRoute = ({ config, filterStaticParams, notFound: notFoundOptions = {}, source, sources, transform, }) => {
|
|
162
|
+
export const createDocsMarkdownRoute = ({ canViewPage, config, filterStaticParams, notFound: notFoundOptions = {}, source, sources, transform, }) => {
|
|
161
163
|
const routeSources = resolveSources(source, sources, "createDocsMarkdownRoute");
|
|
162
164
|
const routingConfig = {
|
|
163
165
|
...(routeSources[0].routingConfig ?? {}),
|
|
@@ -217,6 +219,7 @@ export const createDocsMarkdownRoute = ({ config, filterStaticParams, notFound:
|
|
|
217
219
|
description: data.description ?? data.summary,
|
|
218
220
|
keywords: data.keywords,
|
|
219
221
|
path,
|
|
222
|
+
page,
|
|
220
223
|
scope: getPageScope(path, page.slugs.length),
|
|
221
224
|
source: entry,
|
|
222
225
|
url,
|
|
@@ -254,13 +257,34 @@ export const createDocsMarkdownRoute = ({ config, filterStaticParams, notFound:
|
|
|
254
257
|
? routeSources.filter((source) => mappedSources.has(source))
|
|
255
258
|
: baseUrlMatches;
|
|
256
259
|
};
|
|
257
|
-
const createSmartNotFoundResponse = ({ pathContext, }) => {
|
|
260
|
+
const createSmartNotFoundResponse = async ({ pathContext, request, params, }) => {
|
|
258
261
|
const { localePrefix, localizedPath, requestedPath } = pathContext;
|
|
259
262
|
const suggestionPages = selectSuggestionPages(localizedPath, getSuggestionPages(pathContext.lang));
|
|
260
|
-
const
|
|
261
|
-
|
|
263
|
+
const maxSuggestions = Number.isFinite(smartNotFoundOptions.maxSuggestions)
|
|
264
|
+
? Math.max(0, Math.floor(smartNotFoundOptions.maxSuggestions ?? 0))
|
|
265
|
+
: DEFAULT_MAX_SUGGESTIONS;
|
|
266
|
+
const rankedSuggestions = findSmartNotFoundSuggestions(localizedPath, suggestionPages, {
|
|
267
|
+
limit: maxSuggestions * SUGGESTION_ACCESS_CANDIDATE_MULTIPLIER,
|
|
262
268
|
minScore: smartNotFoundOptions.minScore,
|
|
263
269
|
});
|
|
270
|
+
const pagesByUrl = new Map(suggestionPages.map((page) => [page.url, page]));
|
|
271
|
+
const access = await Promise.all(rankedSuggestions.map(async (suggestion) => {
|
|
272
|
+
const candidate = pagesByUrl.get(suggestion.url);
|
|
273
|
+
return {
|
|
274
|
+
suggestion,
|
|
275
|
+
visible: !candidate ||
|
|
276
|
+
((await canViewPage?.(candidate.page, {
|
|
277
|
+
params,
|
|
278
|
+
request,
|
|
279
|
+
source: candidate.source,
|
|
280
|
+
})) ??
|
|
281
|
+
true),
|
|
282
|
+
};
|
|
283
|
+
}));
|
|
284
|
+
const suggestions = access
|
|
285
|
+
.filter(({ visible }) => visible)
|
|
286
|
+
.map(({ suggestion }) => suggestion)
|
|
287
|
+
.slice(0, maxSuggestions);
|
|
264
288
|
const allPagesUrl = getPublicPath(joinPath(localePrefix, "/llms.txt"), routingConfig.basePath);
|
|
265
289
|
return createNotFoundResponse(requestedPath, {
|
|
266
290
|
headers: {
|
|
@@ -272,11 +296,12 @@ export const createDocsMarkdownRoute = ({ config, filterStaticParams, notFound:
|
|
|
272
296
|
requestedPath,
|
|
273
297
|
suggestions,
|
|
274
298
|
}),
|
|
275
|
-
status: smartNotFoundOptions.status === 410 ? 410 : 404,
|
|
299
|
+
status: !canViewPage && smartNotFoundOptions.status === 410 ? 410 : 404,
|
|
276
300
|
});
|
|
277
301
|
};
|
|
278
302
|
const GET = async (request, { params }) => {
|
|
279
|
-
const
|
|
303
|
+
const resolvedParams = await params;
|
|
304
|
+
const { slug, lang } = resolvedParams;
|
|
280
305
|
const pathContext = notFoundOptions
|
|
281
306
|
? getRequestedPathContext({ lang, slug })
|
|
282
307
|
: undefined;
|
|
@@ -290,9 +315,26 @@ export const createDocsMarkdownRoute = ({ config, filterStaticParams, notFound:
|
|
|
290
315
|
}
|
|
291
316
|
return createSmartNotFoundResponse({
|
|
292
317
|
pathContext,
|
|
318
|
+
request,
|
|
319
|
+
params: resolvedParams,
|
|
293
320
|
});
|
|
294
321
|
}
|
|
295
322
|
const { page, source: pageSource } = result;
|
|
323
|
+
const canView = (await canViewPage?.(page, {
|
|
324
|
+
params: resolvedParams,
|
|
325
|
+
request,
|
|
326
|
+
source: pageSource,
|
|
327
|
+
})) ?? true;
|
|
328
|
+
if (!canView) {
|
|
329
|
+
if (!pathContext) {
|
|
330
|
+
notFound();
|
|
331
|
+
}
|
|
332
|
+
return createSmartNotFoundResponse({
|
|
333
|
+
pathContext,
|
|
334
|
+
request,
|
|
335
|
+
params: resolvedParams,
|
|
336
|
+
});
|
|
337
|
+
}
|
|
296
338
|
const rendered = await pageSource.getPageMarkdown(page);
|
|
297
339
|
const pageData = page.data;
|
|
298
340
|
const canonicalPath = withBasePath(pageData.canonical ?? page.url, routingConfig.basePath);
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { type GeistdocsConfig } from "../config";
|
|
2
|
+
import { type GeistdocsPageFilter } from "../page-visibility";
|
|
2
3
|
import type { GeistdocsSourceBundle } from "../source";
|
|
3
4
|
interface CreateSearchExportRouteOptions {
|
|
4
5
|
config: Pick<GeistdocsConfig, "ai" | "basePath" | "defaultLanguage" | "siteId" | "translations">;
|
|
6
|
+
filterPage?: GeistdocsPageFilter;
|
|
5
7
|
source?: GeistdocsSourceBundle;
|
|
6
8
|
sources?: GeistdocsSourceBundle[];
|
|
7
9
|
}
|
|
8
|
-
export declare const createSearchExportRoute: ({ config, source, sources, }: CreateSearchExportRouteOptions) => {
|
|
10
|
+
export declare const createSearchExportRoute: ({ config, filterPage, source, sources, }: CreateSearchExportRouteOptions) => {
|
|
9
11
|
GET: () => Promise<Response>;
|
|
10
12
|
};
|
|
11
13
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search-export.d.ts","sourceRoot":"","sources":["../../src/routes/search-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"search-export.d.ts","sourceRoot":"","sources":["../../src/routes/search-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,WAAW,CAAC;AAMhE,OAAO,EACL,KAAK,mBAAmB,EAEzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEvD,UAAU,8BAA8B;IACtC,MAAM,EAAE,IAAI,CACV,eAAe,EACf,IAAI,GAAG,UAAU,GAAG,iBAAiB,GAAG,QAAQ,GAAG,cAAc,CAClE,CAAC;IACF,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B,OAAO,CAAC,EAAE,qBAAqB,EAAE,CAAC;CACnC;AAwBD,eAAO,MAAM,uBAAuB,GAAI,0CAKrC,8BAA8B;;CA6ChC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getPublicPath } from "../config";
|
|
2
2
|
import { GEISTDOCS_SEARCH_EXPORT_VERSION, } from "../internal/search-export";
|
|
3
|
-
import { isPageVisibleForSurface } from "../page-visibility";
|
|
3
|
+
import { isPageVisibleForSurface, } from "../page-visibility";
|
|
4
4
|
const resolveSources = (source, sources) => {
|
|
5
5
|
const resolvedSources = sources ?? (source ? [source] : []);
|
|
6
6
|
if (resolvedSources.length === 0) {
|
|
@@ -12,14 +12,15 @@ const getLanguages = (config) => {
|
|
|
12
12
|
const defaultLanguage = config.defaultLanguage ?? "en";
|
|
13
13
|
return Array.from(new Set([defaultLanguage, ...Object.keys(config.translations ?? {})]));
|
|
14
14
|
};
|
|
15
|
-
export const createSearchExportRoute = ({ config, source, sources, }) => {
|
|
15
|
+
export const createSearchExportRoute = ({ config, filterPage, source, sources, }) => {
|
|
16
16
|
const routeSources = resolveSources(source, sources);
|
|
17
17
|
const GET = async () => {
|
|
18
18
|
const documents = await Promise.all(getLanguages(config).flatMap((locale) => routeSources.flatMap((entry, sourceIndex) => {
|
|
19
19
|
const sourceId = entry.id ?? `source-${sourceIndex + 1}`;
|
|
20
20
|
return entry.source
|
|
21
21
|
.getPages(locale)
|
|
22
|
-
.filter((page) => isPageVisibleForSurface(page, "chat")
|
|
22
|
+
.filter((page) => isPageVisibleForSurface(page, "chat") &&
|
|
23
|
+
(filterPage?.(page, { lang: locale, source: entry }) ?? true))
|
|
23
24
|
.map(async (page) => ({
|
|
24
25
|
content: await entry.getPageMarkdown(page),
|
|
25
26
|
description: page.data.description ?? "",
|