@vercel/geistdocs 2.7.10 → 2.9.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/assets/icons/icon-fullscreen-close.d.ts +26 -0
- package/dist/assets/icons/icon-fullscreen-close.d.ts.map +1 -0
- package/dist/assets/icons/icon-fullscreen-close.js +25 -0
- package/dist/assets/icons/icon-fullscreen.d.ts +26 -0
- package/dist/assets/icons/icon-fullscreen.d.ts.map +1 -0
- package/dist/assets/icons/icon-fullscreen.js +25 -0
- package/dist/assets/icons/icon-thumb-down.d.ts +26 -0
- package/dist/assets/icons/icon-thumb-down.d.ts.map +1 -0
- package/dist/assets/icons/icon-thumb-down.js +25 -0
- package/dist/assets/icons/index.d.ts +3 -0
- package/dist/assets/icons/index.d.ts.map +1 -1
- package/dist/assets/icons/index.js +3 -0
- package/dist/cli/index.js +1 -1
- package/dist/config.d.ts +67 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/controls.d.ts +23 -1
- package/dist/controls.d.ts.map +1 -1
- package/dist/controls.js +44 -3
- package/dist/footer.js +1 -1
- package/dist/internal/chat/activity.d.ts +5 -1
- package/dist/internal/chat/activity.d.ts.map +1 -1
- package/dist/internal/chat/activity.js +11 -4
- package/dist/internal/chat/chat-user.d.ts +12 -0
- package/dist/internal/chat/chat-user.d.ts.map +1 -0
- package/dist/internal/chat/chat-user.js +27 -0
- package/dist/internal/chat/commands.d.ts +91 -0
- package/dist/internal/chat/commands.d.ts.map +1 -0
- package/dist/internal/chat/commands.js +165 -0
- package/dist/internal/chat/context.d.ts +49 -2
- package/dist/internal/chat/context.d.ts.map +1 -1
- package/dist/internal/chat/context.js +57 -4
- package/dist/internal/chat/message-actions.d.ts +15 -0
- package/dist/internal/chat/message-actions.d.ts.map +1 -0
- package/dist/internal/chat/message-actions.js +113 -0
- package/dist/internal/chat/message-feedback.d.ts +68 -0
- package/dist/internal/chat/message-feedback.d.ts.map +1 -0
- package/dist/internal/chat/message-feedback.js +188 -0
- package/dist/internal/chat/message-metadata.d.ts.map +1 -1
- package/dist/internal/chat/message-metadata.js +7 -1
- package/dist/internal/chat/message-text.d.ts +9 -0
- package/dist/internal/chat/message-text.d.ts.map +1 -0
- package/dist/internal/chat/message-text.js +15 -0
- package/dist/internal/chat/message.d.ts +4 -2
- package/dist/internal/chat/message.d.ts.map +1 -1
- package/dist/internal/chat/message.js +8 -1
- package/dist/internal/chat/options.d.ts +94 -0
- package/dist/internal/chat/options.d.ts.map +1 -0
- package/dist/internal/chat/options.js +171 -0
- package/dist/internal/chat/page-attachment.d.ts +12 -0
- package/dist/internal/chat/page-attachment.d.ts.map +1 -0
- package/dist/internal/chat/page-attachment.js +18 -0
- package/dist/internal/chat/session-provider.d.ts +33 -0
- package/dist/internal/chat/session-provider.d.ts.map +1 -0
- package/dist/internal/chat/session-provider.js +138 -0
- package/dist/internal/chat/session.d.ts +60 -0
- package/dist/internal/chat/session.d.ts.map +1 -0
- package/dist/internal/chat/session.js +85 -0
- package/dist/internal/chat/shell.d.ts.map +1 -1
- package/dist/internal/chat/shell.js +86 -157
- package/dist/internal/chat/use-chat-commands.d.ts +28 -0
- package/dist/internal/chat/use-chat-commands.d.ts.map +1 -0
- package/dist/internal/chat/use-chat-commands.js +62 -0
- package/dist/internal/chat/user-avatar.d.ts +7 -0
- package/dist/internal/chat/user-avatar.d.ts.map +1 -0
- package/dist/internal/chat/user-avatar.js +27 -0
- package/dist/internal/eve-agent-session-cookie.d.ts +68 -0
- package/dist/internal/eve-agent-session-cookie.d.ts.map +1 -0
- package/dist/internal/eve-agent-session-cookie.js +164 -0
- package/dist/internal/eve-agent-session.d.ts +9 -7
- package/dist/internal/eve-agent-session.d.ts.map +1 -1
- package/dist/internal/eve-agent-session.js +10 -13
- package/dist/internal/eve-agent.d.ts +96 -24
- package/dist/internal/eve-agent.d.ts.map +1 -1
- package/dist/internal/eve-agent.js +74 -51
- package/dist/internal/feedback-action.d.ts +14 -0
- package/dist/internal/feedback-action.d.ts.map +1 -1
- package/dist/internal/feedback-action.js +37 -5
- package/dist/internal/mdx-to-markdown.d.ts.map +1 -1
- package/dist/internal/mdx-to-markdown.js +226 -19
- package/dist/internal/page-actions-client.d.ts +9 -0
- package/dist/internal/page-actions-client.d.ts.map +1 -1
- package/dist/internal/page-actions-client.js +8 -4
- package/dist/internal/provider-client.d.ts.map +1 -1
- package/dist/internal/provider-client.js +10 -4
- package/dist/internal/use-mobile.d.ts +7 -0
- package/dist/internal/use-mobile.d.ts.map +1 -1
- package/dist/internal/use-mobile.js +17 -1
- package/dist/internal/webmcp-client.d.ts.map +1 -1
- package/dist/internal/webmcp-client.js +13 -3
- package/dist/internal/webmcp.d.ts +5 -1
- package/dist/internal/webmcp.d.ts.map +1 -1
- package/dist/internal/webmcp.js +31 -1
- package/dist/pages/changelog.d.ts.map +1 -1
- package/dist/pages/changelog.js +4 -0
- package/dist/pages/docs.d.ts.map +1 -1
- package/dist/pages/docs.js +2 -0
- package/dist/routes/chat.d.ts +83 -5
- package/dist/routes/chat.d.ts.map +1 -1
- package/dist/routes/chat.js +517 -80
- package/dist/routes/discovery.d.ts +1 -1
- package/dist/routes/discovery.d.ts.map +1 -1
- package/dist/routes/discovery.js +7 -11
- package/dist/routes/openapi.d.ts.map +1 -1
- package/dist/routes/openapi.js +47 -25
- package/docs/agents.md +3 -3
- package/docs/llms.txt +634 -37
- package/docs/manifest.json +3 -3
- package/docs/pages/agent-readiness.md +1 -1
- package/docs/pages/ask-ai.md +570 -26
- package/docs/pages/configuration.md +21 -1
- package/docs/pages/env.md +17 -3
- package/docs/pages/feedback.md +4 -0
- package/docs/pages/webmcp.md +18 -3
- package/docs/sitemap.md +1 -1
- package/package.json +1 -2
- package/template/.env.example +5 -0
- package/template/AGENTS.md +2 -0
- package/template/content/docs/agent-readiness.mdx +1 -1
- package/template/content/docs/ask-ai.cn.mdx +466 -15
- package/template/content/docs/ask-ai.mdx +570 -26
- package/template/content/docs/configuration.cn.mdx +39 -0
- package/template/content/docs/configuration.mdx +21 -1
- package/template/content/docs/env.cn.mdx +15 -1
- package/template/content/docs/env.mdx +18 -4
- package/template/content/docs/feedback.cn.mdx +4 -0
- package/template/content/docs/feedback.mdx +4 -0
- package/template/content/docs/webmcp.mdx +18 -3
- package/template/package.json +1 -2
package/dist/routes/chat.js
CHANGED
|
@@ -5,15 +5,25 @@ import { z } from "zod";
|
|
|
5
5
|
import { getPublicPath } from "../config";
|
|
6
6
|
import { createSourceChunk, createSourceChunks, } from "../internal/chat/source-chunks";
|
|
7
7
|
import { createChatDocumentSearch, } from "../internal/chat-retrieval";
|
|
8
|
-
import { buildEveAgentTranscript, capLastUserMessageText,
|
|
9
|
-
import {
|
|
8
|
+
import { buildEveAgentTranscript, capLastUserMessageText, createEmptyEveAgentSession, getEveAgentMessageMetadata, hasPriorEveAgentTurn, normalizeAgentUrl, resolveEveAgentUrl, startOrContinueEveAgentSession, streamEveAgentTurn, } from "../internal/eve-agent";
|
|
9
|
+
import { CHAT_SECRET_ENV, createEveAgentSessionCookieCodec, EVE_AGENT_SESSION_COOKIE, isSameSessionTag, readCookieValues, serializeEveAgentSessionCookie, } from "../internal/eve-agent-session-cookie";
|
|
10
10
|
import { isPageVisibleForSurface, } from "../page-visibility";
|
|
11
11
|
const DEFAULT_CHAT_MODEL = "openai/gpt-5.6-sol";
|
|
12
|
+
const DEFAULT_MAX_REQUEST_BYTES = 1_000_000;
|
|
13
|
+
const DEFAULT_MAX_MESSAGES = 200;
|
|
14
|
+
const DEFAULT_MAX_PAGE_CONTEXT_CHARS = 200_000;
|
|
15
|
+
const MAX_PAGE_CONTEXT_URL_CHARS = 2048;
|
|
16
|
+
const MAX_CLIENT_CONTEXT_TITLE_CHARS = 256;
|
|
17
|
+
const CONTEXT_INJECTION_MODES = [
|
|
18
|
+
"auto",
|
|
19
|
+
"page-only",
|
|
20
|
+
];
|
|
12
21
|
const MAX_CONTEXT_CHARS = 1500;
|
|
13
22
|
const MAX_EVE_AGENT_MESSAGE_CHARS = 4000;
|
|
14
23
|
const MAX_PROXY_RELATED_PAGES = 5;
|
|
15
24
|
const MAX_TOOL_RESULTS = 8;
|
|
16
25
|
const TRAILING_SLASH_PATTERN = /\/$/;
|
|
26
|
+
const LEADING_SLASHES_PATTERN = /^\/+/;
|
|
17
27
|
const normalizePathname = (value) => {
|
|
18
28
|
if (!value) {
|
|
19
29
|
return "/";
|
|
@@ -214,16 +224,7 @@ const findCurrentPage = ({ basePath, currentRoute, filterPage, lang, sources, })
|
|
|
214
224
|
}
|
|
215
225
|
return null;
|
|
216
226
|
};
|
|
217
|
-
const
|
|
218
|
-
if (pageContext) {
|
|
219
|
-
return {
|
|
220
|
-
title: pageContext.title,
|
|
221
|
-
description: "",
|
|
222
|
-
content: pageContext.content,
|
|
223
|
-
slug: pageContext.url,
|
|
224
|
-
url: pageContext.url,
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
+
const getVisiblePageDoc = async ({ basePath, currentRoute, filterPage, lang, sources, }) => {
|
|
227
228
|
const result = findCurrentPage({
|
|
228
229
|
basePath,
|
|
229
230
|
currentRoute,
|
|
@@ -243,6 +244,140 @@ const getCurrentPageDoc = async ({ basePath, currentRoute, filterPage, lang, pag
|
|
|
243
244
|
url: getPublicPath(result.page.url, basePath),
|
|
244
245
|
};
|
|
245
246
|
};
|
|
247
|
+
/**
|
|
248
|
+
* Document for a request's `pageContext`. The legacy shape is used as sent;
|
|
249
|
+
* a url-only reference resolves to the full Markdown of a page Ask AI may
|
|
250
|
+
* see, in the language of the referenced path. Returns `null` when the
|
|
251
|
+
* reference names no such page, so the request is answered without it.
|
|
252
|
+
*/
|
|
253
|
+
const resolvePageContextDoc = async ({ basePath, defaultLanguage, filterPage, languages, pageContext, sources, }) => {
|
|
254
|
+
if (!pageContext) {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
if ("content" in pageContext) {
|
|
258
|
+
return {
|
|
259
|
+
title: pageContext.title ?? pageContext.url,
|
|
260
|
+
description: "",
|
|
261
|
+
content: pageContext.content,
|
|
262
|
+
slug: pageContext.url,
|
|
263
|
+
url: pageContext.url,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
return await getVisiblePageDoc({
|
|
267
|
+
basePath,
|
|
268
|
+
currentRoute: pageContext.url,
|
|
269
|
+
filterPage,
|
|
270
|
+
lang: getRequestLanguage({
|
|
271
|
+
basePath,
|
|
272
|
+
currentRoute: pageContext.url,
|
|
273
|
+
defaultLanguage,
|
|
274
|
+
languages,
|
|
275
|
+
}),
|
|
276
|
+
sources,
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
const getCurrentPageDoc = async ({ basePath, currentRoute, defaultLanguage, filterPage, lang, languages, pageContext, sources, }) => (await resolvePageContextDoc({
|
|
280
|
+
basePath,
|
|
281
|
+
defaultLanguage,
|
|
282
|
+
filterPage,
|
|
283
|
+
languages,
|
|
284
|
+
pageContext,
|
|
285
|
+
sources,
|
|
286
|
+
})) ??
|
|
287
|
+
(await getVisiblePageDoc({
|
|
288
|
+
basePath,
|
|
289
|
+
currentRoute,
|
|
290
|
+
filterPage,
|
|
291
|
+
lang,
|
|
292
|
+
sources,
|
|
293
|
+
}));
|
|
294
|
+
/**
|
|
295
|
+
* The user message with an attached page inlined ahead of the question, in
|
|
296
|
+
* the format the Vercel docs Vertex route uses.
|
|
297
|
+
*/
|
|
298
|
+
const formatPageContextQuestion = (doc, userQuestion) => `Here's the content from the current page:\n\n**Page:** ${doc.title}\n**URL:** ${doc.url}\n\n---\n\n${doc.content}\n\n---\n\nUser question: ${userQuestion}`;
|
|
299
|
+
/** Public origin page URLs are built on: `siteUrl`, else the request's. */
|
|
300
|
+
const getSiteBaseUrl = (siteUrl, req) => siteUrl || new URL(req.url).origin;
|
|
301
|
+
/**
|
|
302
|
+
* The page a request attaches with `pageContext`, for page-only context.
|
|
303
|
+
* A page resolved from the site's sources gets its absolute public URL and
|
|
304
|
+
* Markdown truncated to `maxChars`; the legacy shape is used as sent (its
|
|
305
|
+
* content was already capped at parse time).
|
|
306
|
+
*/
|
|
307
|
+
const resolveAttachedPageDoc = async ({ baseUrl, basePath, defaultLanguage, filterPage, languages, maxChars, pageContext, sources, }) => {
|
|
308
|
+
const doc = await resolvePageContextDoc({
|
|
309
|
+
basePath,
|
|
310
|
+
defaultLanguage,
|
|
311
|
+
filterPage,
|
|
312
|
+
languages,
|
|
313
|
+
pageContext,
|
|
314
|
+
sources,
|
|
315
|
+
});
|
|
316
|
+
if (!(doc && pageContext) || "content" in pageContext) {
|
|
317
|
+
return doc;
|
|
318
|
+
}
|
|
319
|
+
return {
|
|
320
|
+
...doc,
|
|
321
|
+
content: doc.content.slice(0, maxChars),
|
|
322
|
+
url: new URL(doc.url, baseUrl).toString(),
|
|
323
|
+
};
|
|
324
|
+
};
|
|
325
|
+
/**
|
|
326
|
+
* Page-only proxy messages: the last user message is rewritten only when
|
|
327
|
+
* the request attaches a visible page; otherwise messages pass unchanged.
|
|
328
|
+
*/
|
|
329
|
+
const buildPageOnlyProxyMessages = (actualMessages, attachedDoc) => {
|
|
330
|
+
const lastMessage = actualMessages.at(-1);
|
|
331
|
+
if (!attachedDoc || lastMessage?.role !== "user") {
|
|
332
|
+
return actualMessages;
|
|
333
|
+
}
|
|
334
|
+
return [
|
|
335
|
+
...actualMessages.slice(0, -1),
|
|
336
|
+
{
|
|
337
|
+
...lastMessage,
|
|
338
|
+
parts: [
|
|
339
|
+
{
|
|
340
|
+
type: "text",
|
|
341
|
+
text: formatPageContextQuestion(attachedDoc, getMessageText(lastMessage)),
|
|
342
|
+
},
|
|
343
|
+
],
|
|
344
|
+
},
|
|
345
|
+
];
|
|
346
|
+
};
|
|
347
|
+
/**
|
|
348
|
+
* eve `clientContext` naming the page the reader is viewing. Returns
|
|
349
|
+
* `undefined` without a usable `currentRoute`. The URL is built from the
|
|
350
|
+
* route's path only, so a client cannot point it at another origin.
|
|
351
|
+
*/
|
|
352
|
+
const getEveClientContext = ({ basePath, baseUrl, currentRoute, defaultLanguage, filterPage, languages, sources, }) => {
|
|
353
|
+
if (typeof currentRoute !== "string" ||
|
|
354
|
+
!currentRoute.trim() ||
|
|
355
|
+
currentRoute.length > MAX_PAGE_CONTEXT_URL_CHARS) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
// Collapse leading slashes so a path like "//host/x" cannot resolve as a
|
|
359
|
+
// protocol-relative URL on another origin.
|
|
360
|
+
const pathname = stripBasePath(normalizePathname(currentRoute), basePath).replace(LEADING_SLASHES_PATTERN, "/");
|
|
361
|
+
const url = new URL(getPublicPath(pathname, basePath), baseUrl).toString();
|
|
362
|
+
const page = findCurrentPage({
|
|
363
|
+
basePath,
|
|
364
|
+
currentRoute,
|
|
365
|
+
filterPage,
|
|
366
|
+
lang: getRequestLanguage({
|
|
367
|
+
basePath,
|
|
368
|
+
currentRoute,
|
|
369
|
+
defaultLanguage,
|
|
370
|
+
languages,
|
|
371
|
+
}),
|
|
372
|
+
sources,
|
|
373
|
+
});
|
|
374
|
+
const title = page ? getPageData(page.page).title?.trim() : undefined;
|
|
375
|
+
return {
|
|
376
|
+
currentPage: title
|
|
377
|
+
? { url, title: title.slice(0, MAX_CLIENT_CONTEXT_TITLE_CHARS) }
|
|
378
|
+
: { url },
|
|
379
|
+
};
|
|
380
|
+
};
|
|
246
381
|
const isFirstUserMessage = (messages) => messages.filter((message) => message.role === "user").length === 1;
|
|
247
382
|
const buildProxyMessages = async ({ actualMessages, config, currentRoute, defaultLanguage, filterPage, languages, pageContext, routeSources, searchDocuments, }) => {
|
|
248
383
|
if (!isFirstUserMessage(actualMessages)) {
|
|
@@ -262,8 +397,10 @@ const buildProxyMessages = async ({ actualMessages, config, currentRoute, defaul
|
|
|
262
397
|
const currentPageDoc = await getCurrentPageDoc({
|
|
263
398
|
basePath: config.basePath,
|
|
264
399
|
currentRoute,
|
|
400
|
+
defaultLanguage,
|
|
265
401
|
filterPage,
|
|
266
402
|
lang,
|
|
403
|
+
languages,
|
|
267
404
|
pageContext,
|
|
268
405
|
sources: routeSources,
|
|
269
406
|
});
|
|
@@ -301,9 +438,9 @@ const buildProxyMessages = async ({ actualMessages, config, currentRoute, defaul
|
|
|
301
438
|
sourceDocs: [currentPageDoc, ...filteredRelatedDocs].filter((doc) => Boolean(doc)),
|
|
302
439
|
};
|
|
303
440
|
};
|
|
304
|
-
const
|
|
441
|
+
const resolveUpstreamHeaders = async (headers, req) => (typeof headers === "function" ? await headers(req) : headers);
|
|
305
442
|
const getProxyRequestHeaders = async ({ proxy, req, }) => {
|
|
306
|
-
const headers = new Headers(await
|
|
443
|
+
const headers = new Headers(await resolveUpstreamHeaders(proxy.headers, req));
|
|
307
444
|
const clientJa4 = req.headers.get("x-vercel-ja4-digest");
|
|
308
445
|
const clientIp = req.headers.get("x-forwarded-for");
|
|
309
446
|
headers.set("Content-Type", "application/json");
|
|
@@ -316,7 +453,7 @@ const getProxyRequestHeaders = async ({ proxy, req, }) => {
|
|
|
316
453
|
return headers;
|
|
317
454
|
};
|
|
318
455
|
const getEveAgentRequestHeaders = async ({ eveAgent, req, }) => {
|
|
319
|
-
const headers = new Headers(await
|
|
456
|
+
const headers = new Headers(await resolveUpstreamHeaders(eveAgent?.headers, req));
|
|
320
457
|
const clientJa4 = req.headers.get("x-vercel-ja4-digest");
|
|
321
458
|
const clientIp = req.headers.get("x-forwarded-for");
|
|
322
459
|
headers.set("Content-Type", "application/json");
|
|
@@ -539,20 +676,144 @@ const createChatErrorResponse = (error, status) => new Response(JSON.stringify({
|
|
|
539
676
|
status,
|
|
540
677
|
headers: { "Content-Type": "application/json" },
|
|
541
678
|
});
|
|
542
|
-
const
|
|
543
|
-
|
|
679
|
+
const resolveLimits = (limits) => {
|
|
680
|
+
const resolved = {
|
|
681
|
+
maxMessages: limits?.maxMessages ?? DEFAULT_MAX_MESSAGES,
|
|
682
|
+
maxPageContextChars: limits?.maxPageContextChars ?? DEFAULT_MAX_PAGE_CONTEXT_CHARS,
|
|
683
|
+
maxRequestBytes: limits?.maxRequestBytes ?? DEFAULT_MAX_REQUEST_BYTES,
|
|
684
|
+
};
|
|
685
|
+
for (const [name, value] of Object.entries(resolved)) {
|
|
686
|
+
if (!(Number.isSafeInteger(value) && value > 0)) {
|
|
687
|
+
throw new Error(`createChatRoute limits.${name} must be a positive integer.`);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
return resolved;
|
|
691
|
+
};
|
|
692
|
+
/**
|
|
693
|
+
* Read the request body as text without buffering more than `maxBytes`.
|
|
694
|
+
* Returns `null` as soon as the declared or streamed size exceeds the cap.
|
|
695
|
+
*/
|
|
696
|
+
const readBodyTextWithLimit = async (req, maxBytes) => {
|
|
697
|
+
const declaredLength = Number(req.headers.get("content-length"));
|
|
698
|
+
if (Number.isFinite(declaredLength) && declaredLength > maxBytes) {
|
|
699
|
+
return null;
|
|
700
|
+
}
|
|
701
|
+
if (!req.body) {
|
|
702
|
+
return "";
|
|
703
|
+
}
|
|
704
|
+
const reader = req.body.getReader();
|
|
705
|
+
const decoder = new TextDecoder();
|
|
706
|
+
let received = 0;
|
|
707
|
+
let text = "";
|
|
708
|
+
for (;;) {
|
|
709
|
+
const { done, value } = await reader.read();
|
|
710
|
+
if (done) {
|
|
711
|
+
break;
|
|
712
|
+
}
|
|
713
|
+
received += value.byteLength;
|
|
714
|
+
if (received > maxBytes) {
|
|
715
|
+
await reader.cancel().catch(() => {
|
|
716
|
+
// The body may already be errored; the request is rejected anyway.
|
|
717
|
+
});
|
|
718
|
+
return null;
|
|
719
|
+
}
|
|
720
|
+
text += decoder.decode(value, { stream: true });
|
|
721
|
+
}
|
|
722
|
+
return text + decoder.decode();
|
|
723
|
+
};
|
|
724
|
+
let warnedMissingChatSecret = false;
|
|
725
|
+
const resolveEveAgentSessionCodec = ({ agentUrl, secret, }) => {
|
|
726
|
+
if (!agentUrl) {
|
|
727
|
+
return null;
|
|
728
|
+
}
|
|
729
|
+
if (!secret) {
|
|
730
|
+
if (!warnedMissingChatSecret) {
|
|
731
|
+
warnedMissingChatSecret = true;
|
|
732
|
+
console.warn(`[Geistdocs chat] ${CHAT_SECRET_ENV} is not set, so eve agent session continuity and prewarming are disabled: every Ask AI turn starts a new eve session with the conversation inlined. Set ${CHAT_SECRET_ENV} to a random value of at least 32 bytes (for example, \`openssl rand -base64 32\`) to enable them.`);
|
|
733
|
+
}
|
|
734
|
+
return null;
|
|
735
|
+
}
|
|
736
|
+
return createEveAgentSessionCookieCodec({
|
|
737
|
+
agentUrl: normalizeAgentUrl(agentUrl),
|
|
738
|
+
secret,
|
|
739
|
+
});
|
|
740
|
+
};
|
|
741
|
+
/**
|
|
742
|
+
* The eve session this browser's cookie binds it to, or `null` when the
|
|
743
|
+
* request carries no cookie that verifies for this agent and secret.
|
|
744
|
+
*/
|
|
745
|
+
const readEveAgentCookieSession = (req, sessionCodec) => {
|
|
746
|
+
for (const value of readCookieValues(req.headers.get("cookie"), EVE_AGENT_SESSION_COOKIE)) {
|
|
747
|
+
const session = sessionCodec.open(value);
|
|
748
|
+
if (session) {
|
|
749
|
+
return session;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
return null;
|
|
753
|
+
};
|
|
754
|
+
const createEveAgentPrewarmResponse = async ({ agentUrl, enabled, eveAgent, req, sessionCodec, }) => {
|
|
755
|
+
// Without a signing secret a prewarmed session could not be bound to the
|
|
756
|
+
// browser, so prewarming is refused rather than allocating sessions
|
|
757
|
+
// nobody can reuse.
|
|
758
|
+
if (!(agentUrl && enabled && sessionCodec)) {
|
|
544
759
|
return createChatErrorResponse("Invalid chat request: eve agent prewarming is not enabled.", 400);
|
|
545
760
|
}
|
|
546
761
|
const headers = await getEveAgentRequestHeaders({ eveAgent, req });
|
|
547
|
-
const
|
|
762
|
+
const { sessionId } = await createEmptyEveAgentSession({
|
|
548
763
|
agentUrl,
|
|
549
764
|
headers,
|
|
550
765
|
signal: req.signal,
|
|
551
766
|
});
|
|
552
|
-
return Response.json(
|
|
767
|
+
return Response.json({ ok: true }, {
|
|
768
|
+
status: 202,
|
|
769
|
+
headers: {
|
|
770
|
+
"Set-Cookie": serializeEveAgentSessionCookie(sessionCodec.seal({ prewarmed: true, sessionId }), req),
|
|
771
|
+
},
|
|
772
|
+
});
|
|
773
|
+
};
|
|
774
|
+
const parsePageContext = (value, limits) => {
|
|
775
|
+
if (value === undefined || value === null) {
|
|
776
|
+
return { value: undefined };
|
|
777
|
+
}
|
|
778
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
779
|
+
return { error: "pageContext must be an object." };
|
|
780
|
+
}
|
|
781
|
+
const { content, title, url } = value;
|
|
782
|
+
if (typeof url !== "string" ||
|
|
783
|
+
!url.trim() ||
|
|
784
|
+
url.length > MAX_PAGE_CONTEXT_URL_CHARS) {
|
|
785
|
+
return {
|
|
786
|
+
error: `pageContext.url must be a non-empty string of at most ${MAX_PAGE_CONTEXT_URL_CHARS} characters.`,
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
if (content === undefined) {
|
|
790
|
+
return { value: { url } };
|
|
791
|
+
}
|
|
792
|
+
if (typeof content !== "string") {
|
|
793
|
+
return { error: "pageContext.content must be a string." };
|
|
794
|
+
}
|
|
795
|
+
if (content.length > limits.maxPageContextChars) {
|
|
796
|
+
return {
|
|
797
|
+
error: `pageContext.content exceeds ${limits.maxPageContextChars} characters.`,
|
|
798
|
+
};
|
|
799
|
+
}
|
|
800
|
+
return {
|
|
801
|
+
value: {
|
|
802
|
+
content,
|
|
803
|
+
title: typeof title === "string" && title ? title : undefined,
|
|
804
|
+
url,
|
|
805
|
+
},
|
|
806
|
+
};
|
|
553
807
|
};
|
|
554
|
-
const resolveChatRequestBody = async ({ eveAgent, eveAgentUrl, prewarmEnabled, req, }) => {
|
|
555
|
-
const
|
|
808
|
+
const resolveChatRequestBody = async ({ eveAgent, eveAgentUrl, limits, prewarmEnabled, req, sessionCodec, }) => {
|
|
809
|
+
const text = await readBodyTextWithLimit(req, limits.maxRequestBytes);
|
|
810
|
+
if (text === null) {
|
|
811
|
+
return {
|
|
812
|
+
response: createChatErrorResponse(`Invalid chat request: body exceeds ${limits.maxRequestBytes} bytes.`, 413),
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
// Invalid JSON throws and is reported as a 500, as documented.
|
|
816
|
+
const body = JSON.parse(text);
|
|
556
817
|
if (isEveAgentPrewarmRequestBody(body)) {
|
|
557
818
|
return {
|
|
558
819
|
response: await createEveAgentPrewarmResponse({
|
|
@@ -560,6 +821,7 @@ const resolveChatRequestBody = async ({ eveAgent, eveAgentUrl, prewarmEnabled, r
|
|
|
560
821
|
enabled: prewarmEnabled,
|
|
561
822
|
eveAgent,
|
|
562
823
|
req,
|
|
824
|
+
sessionCodec,
|
|
563
825
|
}),
|
|
564
826
|
};
|
|
565
827
|
}
|
|
@@ -568,55 +830,200 @@ const resolveChatRequestBody = async ({ eveAgent, eveAgentUrl, prewarmEnabled, r
|
|
|
568
830
|
response: createChatErrorResponse("Invalid chat request: messages must be an array.", 400),
|
|
569
831
|
};
|
|
570
832
|
}
|
|
571
|
-
|
|
833
|
+
if (body.messages.length > limits.maxMessages) {
|
|
834
|
+
return {
|
|
835
|
+
response: createChatErrorResponse(`Invalid chat request: at most ${limits.maxMessages} messages are allowed.`, 400),
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
const pageContext = parsePageContext(body.pageContext, limits);
|
|
839
|
+
if ("error" in pageContext) {
|
|
840
|
+
return {
|
|
841
|
+
response: createChatErrorResponse(`Invalid chat request: ${pageContext.error}`, 400),
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
return { body: { ...body, pageContext: pageContext.value } };
|
|
572
845
|
};
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
846
|
+
/**
|
|
847
|
+
* Leading `Page context:` part for an attached page, in the shape the
|
|
848
|
+
* Vercel docs eve client sends: the page as one line of JSON.
|
|
849
|
+
*/
|
|
850
|
+
const createEvePageContextPart = (doc) => ({
|
|
851
|
+
type: "text",
|
|
852
|
+
text: `Page context:\n${JSON.stringify({
|
|
853
|
+
title: doc.title,
|
|
854
|
+
url: doc.url,
|
|
855
|
+
content: doc.content,
|
|
856
|
+
})}`,
|
|
857
|
+
});
|
|
858
|
+
/**
|
|
859
|
+
* Decide which eve session, if any, this turn continues. The session ID
|
|
860
|
+
* only ever comes from a verified cookie; the browser's messages decide
|
|
861
|
+
* whether that session belongs to this conversation and supply the stream
|
|
862
|
+
* position.
|
|
863
|
+
*/
|
|
864
|
+
const resolveEveAgentContinuation = ({ messages, req, sessionCodec, }) => {
|
|
865
|
+
const cookieSession = sessionCodec
|
|
866
|
+
? readEveAgentCookieSession(req, sessionCodec)
|
|
867
|
+
: null;
|
|
868
|
+
if (!(sessionCodec && cookieSession)) {
|
|
869
|
+
return { continuation: null, prewarmed: false };
|
|
870
|
+
}
|
|
871
|
+
const metadata = getEveAgentMessageMetadata(messages);
|
|
872
|
+
if (metadata &&
|
|
873
|
+
isSameSessionTag(metadata.session, sessionCodec.tag(cookieSession.sessionId))) {
|
|
874
|
+
return {
|
|
875
|
+
continuation: {
|
|
876
|
+
sessionId: cookieSession.sessionId,
|
|
877
|
+
startIndex: metadata.streamIndex,
|
|
878
|
+
},
|
|
879
|
+
prewarmed: false,
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
// A prewarmed session has not seen a turn yet, so it can take the first
|
|
883
|
+
// message of a conversation that has no eve session of its own.
|
|
884
|
+
if (cookieSession.prewarmed && !hasPriorEveAgentTurn(messages)) {
|
|
885
|
+
return {
|
|
886
|
+
continuation: { sessionId: cookieSession.sessionId, startIndex: 0 },
|
|
887
|
+
prewarmed: true,
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
// The conversation belongs to another session (or none): the reader
|
|
891
|
+
// cleared the chat, another tab started a new session, or the cookie
|
|
892
|
+
// expired. Start fresh rather than mixing conversations.
|
|
893
|
+
return { continuation: null, prewarmed: false };
|
|
894
|
+
};
|
|
895
|
+
const createEveAgentErrorStreamResponse = ({ error, messages, signal, }) => {
|
|
896
|
+
// A reader who stops the response before the agent accepts the message
|
|
897
|
+
// is not an agent failure.
|
|
898
|
+
if (!signal.aborted) {
|
|
899
|
+
console.error("[Geistdocs chat] eve agent request failed:", error);
|
|
900
|
+
}
|
|
901
|
+
// Same client-facing outcome as a failure mid-stream: an `error` part in
|
|
902
|
+
// the 200 UI message stream, which the chat panel shows as a toast.
|
|
903
|
+
const stream = createUIMessageStream({
|
|
904
|
+
originalMessages: messages,
|
|
905
|
+
onError: () => "Something went wrong with your query.",
|
|
906
|
+
execute: () => {
|
|
907
|
+
throw error;
|
|
908
|
+
},
|
|
585
909
|
});
|
|
910
|
+
return createUIMessageStreamResponse({ stream });
|
|
911
|
+
};
|
|
912
|
+
const createEveAgentResponse = async ({ actualMessages, agentUrl, config, contextInjection, currentRoute, defaultLanguage, eveAgent, filterPage, languages, limits, messages, pageContext, req, routeSources, searchDocuments, sessionCodec, }) => {
|
|
913
|
+
const cappedMessages = capLastUserMessageText(actualMessages, MAX_EVE_AGENT_MESSAGE_CHARS);
|
|
914
|
+
const baseUrl = getSiteBaseUrl(config.siteUrl, req);
|
|
915
|
+
const pageOnly = contextInjection === "page-only";
|
|
916
|
+
const { messages: contextMessages, sourceDocs } = pageOnly
|
|
917
|
+
? { messages: cappedMessages, sourceDocs: [] }
|
|
918
|
+
: await buildProxyMessages({
|
|
919
|
+
actualMessages: cappedMessages,
|
|
920
|
+
config,
|
|
921
|
+
currentRoute,
|
|
922
|
+
defaultLanguage,
|
|
923
|
+
filterPage,
|
|
924
|
+
languages,
|
|
925
|
+
pageContext,
|
|
926
|
+
routeSources,
|
|
927
|
+
searchDocuments,
|
|
928
|
+
});
|
|
586
929
|
const lastMessage = contextMessages.at(-1);
|
|
587
930
|
if (lastMessage?.role !== "user") {
|
|
588
931
|
return createChatErrorResponse("Invalid chat request: expected a user message.", 400);
|
|
589
932
|
}
|
|
590
933
|
const lastMessageText = getMessageText(lastMessage);
|
|
591
|
-
const
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
//
|
|
934
|
+
const { continuation, prewarmed } = resolveEveAgentContinuation({
|
|
935
|
+
messages: cappedMessages,
|
|
936
|
+
req,
|
|
937
|
+
sessionCodec,
|
|
938
|
+
});
|
|
939
|
+
// A fresh eve session (no continuation, a prewarmed session that has not
|
|
940
|
+
// seen a turn, or a continuation that turned out to be inactive) receives
|
|
941
|
+
// the prior turns inlined so it still sees the conversation so far.
|
|
597
942
|
const transcriptMessage = buildEveAgentTranscript(contextMessages, lastMessageText);
|
|
598
|
-
const outboundMessage =
|
|
943
|
+
const outboundMessage = continuation && !prewarmed ? lastMessageText : transcriptMessage;
|
|
599
944
|
if (!outboundMessage.trim()) {
|
|
600
945
|
return createChatErrorResponse("Invalid chat request: message must not be empty.", 400);
|
|
601
946
|
}
|
|
947
|
+
const attachedDoc = pageOnly
|
|
948
|
+
? await resolveAttachedPageDoc({
|
|
949
|
+
basePath: config.basePath,
|
|
950
|
+
baseUrl,
|
|
951
|
+
defaultLanguage,
|
|
952
|
+
filterPage,
|
|
953
|
+
languages,
|
|
954
|
+
maxChars: limits.maxPageContextChars,
|
|
955
|
+
pageContext,
|
|
956
|
+
sources: routeSources,
|
|
957
|
+
})
|
|
958
|
+
: null;
|
|
959
|
+
// Page-only mode sends the attached page as a leading text part ahead of
|
|
960
|
+
// the question, the way the Vercel docs eve client sends it.
|
|
961
|
+
const withPageContext = (message) => attachedDoc
|
|
962
|
+
? [createEvePageContextPart(attachedDoc), { type: "text", text: message }]
|
|
963
|
+
: message;
|
|
964
|
+
const clientContext = eveAgent?.clientContext
|
|
965
|
+
? getEveClientContext({
|
|
966
|
+
basePath: config.basePath,
|
|
967
|
+
baseUrl,
|
|
968
|
+
currentRoute,
|
|
969
|
+
defaultLanguage,
|
|
970
|
+
filterPage,
|
|
971
|
+
languages,
|
|
972
|
+
sources: routeSources,
|
|
973
|
+
})
|
|
974
|
+
: undefined;
|
|
602
975
|
const headers = await getEveAgentRequestHeaders({ eveAgent, req });
|
|
976
|
+
let session;
|
|
977
|
+
// The session must be settled before the response starts so the cookie
|
|
978
|
+
// that binds it to this browser can be set on the response.
|
|
979
|
+
try {
|
|
980
|
+
session = await startOrContinueEveAgentSession({
|
|
981
|
+
agentUrl,
|
|
982
|
+
clientContext,
|
|
983
|
+
continuation,
|
|
984
|
+
fallbackMessage: withPageContext(transcriptMessage),
|
|
985
|
+
headers,
|
|
986
|
+
message: withPageContext(outboundMessage),
|
|
987
|
+
signal: req.signal,
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
catch (error) {
|
|
991
|
+
return createEveAgentErrorStreamResponse({
|
|
992
|
+
error,
|
|
993
|
+
messages,
|
|
994
|
+
signal: req.signal,
|
|
995
|
+
});
|
|
996
|
+
}
|
|
603
997
|
const stream = createUIMessageStream({
|
|
604
998
|
originalMessages: messages,
|
|
605
999
|
onError: () => "Something went wrong with your query.",
|
|
606
1000
|
execute: async ({ writer }) => {
|
|
607
|
-
await
|
|
1001
|
+
await streamEveAgentTurn({
|
|
608
1002
|
agentUrl,
|
|
609
|
-
fallbackMessage: transcriptMessage,
|
|
610
|
-
handle,
|
|
611
1003
|
headers,
|
|
612
1004
|
initialChunks: createSourceChunks(sourceDocs),
|
|
613
|
-
|
|
1005
|
+
session,
|
|
1006
|
+
sessionTag: sessionCodec?.tag(session.sessionId) ?? null,
|
|
614
1007
|
signal: req.signal,
|
|
1008
|
+
toolCitations: eveAgent?.toolCitations ?? true,
|
|
1009
|
+
visibleTools: eveAgent?.visibleTools,
|
|
615
1010
|
writer,
|
|
616
1011
|
});
|
|
617
1012
|
},
|
|
618
1013
|
});
|
|
619
|
-
return createUIMessageStreamResponse({
|
|
1014
|
+
return createUIMessageStreamResponse({
|
|
1015
|
+
stream,
|
|
1016
|
+
...(sessionCodec
|
|
1017
|
+
? {
|
|
1018
|
+
headers: {
|
|
1019
|
+
"Set-Cookie": serializeEveAgentSessionCookie(sessionCodec.seal({
|
|
1020
|
+
prewarmed: false,
|
|
1021
|
+
sessionId: session.sessionId,
|
|
1022
|
+
}), req),
|
|
1023
|
+
},
|
|
1024
|
+
}
|
|
1025
|
+
: {}),
|
|
1026
|
+
});
|
|
620
1027
|
};
|
|
621
1028
|
const resolveSources = (source, sources) => {
|
|
622
1029
|
const resolvedSources = sources ?? (source ? [source] : []);
|
|
@@ -625,7 +1032,21 @@ const resolveSources = (source, sources) => {
|
|
|
625
1032
|
}
|
|
626
1033
|
return resolvedSources;
|
|
627
1034
|
};
|
|
628
|
-
|
|
1035
|
+
/** Reject option values that would otherwise fail silently per request. */
|
|
1036
|
+
const validateRouteOptions = ({ contextInjection, eveAgent, }) => {
|
|
1037
|
+
if (contextInjection !== undefined &&
|
|
1038
|
+
!CONTEXT_INJECTION_MODES.includes(contextInjection)) {
|
|
1039
|
+
throw new Error(`createChatRoute contextInjection must be "auto" or "page-only". Received ${JSON.stringify(contextInjection)}.`);
|
|
1040
|
+
}
|
|
1041
|
+
const visibleTools = eveAgent?.visibleTools;
|
|
1042
|
+
if (visibleTools !== undefined &&
|
|
1043
|
+
!(Array.isArray(visibleTools) &&
|
|
1044
|
+
visibleTools.every((name) => typeof name === "string"))) {
|
|
1045
|
+
throw new Error("createChatRoute eveAgent.visibleTools must be an array of tool names.");
|
|
1046
|
+
}
|
|
1047
|
+
};
|
|
1048
|
+
export const createChatRoute = ({ config, contextInjection = "auto", eveAgent, filterPage, limits, mixedbread, model = DEFAULT_CHAT_MODEL, proxy, source, sources, }) => {
|
|
1049
|
+
validateRouteOptions({ contextInjection, eveAgent });
|
|
629
1050
|
const { defaultLanguage, languages } = getLanguages(config);
|
|
630
1051
|
const routeSources = resolveSources(source, sources);
|
|
631
1052
|
const searchDocuments = createDocumentSearch({
|
|
@@ -639,49 +1060,72 @@ export const createChatRoute = ({ config, eveAgent, filterPage, mixedbread, mode
|
|
|
639
1060
|
hasProxy: Boolean(proxy),
|
|
640
1061
|
optionUrl: eveAgent?.url,
|
|
641
1062
|
});
|
|
1063
|
+
const resolvedLimits = resolveLimits(limits);
|
|
1064
|
+
const sessionCodec = resolveEveAgentSessionCodec({
|
|
1065
|
+
agentUrl: eveAgentUrl,
|
|
1066
|
+
secret: eveAgent?.secret || process.env[CHAT_SECRET_ENV] || undefined,
|
|
1067
|
+
});
|
|
642
1068
|
const POST = async (req) => {
|
|
643
1069
|
try {
|
|
644
1070
|
const resolvedRequest = await resolveChatRequestBody({
|
|
645
1071
|
eveAgent,
|
|
646
1072
|
eveAgentUrl,
|
|
1073
|
+
limits: resolvedLimits,
|
|
647
1074
|
prewarmEnabled: config.ai?.eveAgent?.prewarm === true,
|
|
648
1075
|
req,
|
|
1076
|
+
sessionCodec,
|
|
649
1077
|
});
|
|
650
1078
|
if ("response" in resolvedRequest) {
|
|
651
1079
|
return resolvedRequest.response;
|
|
652
1080
|
}
|
|
653
|
-
const { currentRoute,
|
|
1081
|
+
const { currentRoute, messages, pageContext } = resolvedRequest.body;
|
|
654
1082
|
const actualMessages = messages.filter((message) => !isPageContextMessage(message));
|
|
655
1083
|
if (eveAgentUrl) {
|
|
656
1084
|
return await createEveAgentResponse({
|
|
657
1085
|
actualMessages,
|
|
658
1086
|
agentUrl: eveAgentUrl,
|
|
659
1087
|
config,
|
|
1088
|
+
contextInjection,
|
|
660
1089
|
currentRoute,
|
|
661
1090
|
defaultLanguage,
|
|
662
1091
|
eveAgent,
|
|
663
1092
|
filterPage,
|
|
664
1093
|
languages,
|
|
1094
|
+
limits: resolvedLimits,
|
|
665
1095
|
messages,
|
|
666
1096
|
pageContext,
|
|
667
|
-
prewarmedHandle: eveAgentSession,
|
|
668
1097
|
req,
|
|
669
1098
|
routeSources,
|
|
670
1099
|
searchDocuments,
|
|
1100
|
+
sessionCodec,
|
|
671
1101
|
});
|
|
672
1102
|
}
|
|
673
1103
|
if (proxy) {
|
|
674
|
-
const { messages: proxyMessages, sourceDocs } =
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
1104
|
+
const { messages: proxyMessages, sourceDocs } = contextInjection === "page-only"
|
|
1105
|
+
? {
|
|
1106
|
+
messages: buildPageOnlyProxyMessages(actualMessages, await resolveAttachedPageDoc({
|
|
1107
|
+
basePath: config.basePath,
|
|
1108
|
+
baseUrl: getSiteBaseUrl(config.siteUrl, req),
|
|
1109
|
+
defaultLanguage,
|
|
1110
|
+
filterPage,
|
|
1111
|
+
languages,
|
|
1112
|
+
maxChars: resolvedLimits.maxPageContextChars,
|
|
1113
|
+
pageContext,
|
|
1114
|
+
sources: routeSources,
|
|
1115
|
+
})),
|
|
1116
|
+
sourceDocs: [],
|
|
1117
|
+
}
|
|
1118
|
+
: await buildProxyMessages({
|
|
1119
|
+
actualMessages,
|
|
1120
|
+
config,
|
|
1121
|
+
currentRoute,
|
|
1122
|
+
defaultLanguage,
|
|
1123
|
+
filterPage,
|
|
1124
|
+
languages,
|
|
1125
|
+
pageContext,
|
|
1126
|
+
routeSources,
|
|
1127
|
+
searchDocuments,
|
|
1128
|
+
});
|
|
685
1129
|
const stream = createUIMessageStream({
|
|
686
1130
|
originalMessages: messages,
|
|
687
1131
|
onError: () => "Something went wrong with your query.",
|
|
@@ -711,26 +1155,19 @@ export const createChatRoute = ({ config, eveAgent, filterPage, mixedbread, mode
|
|
|
711
1155
|
}
|
|
712
1156
|
let processedMessages = actualMessages;
|
|
713
1157
|
let localSourceDocs = [];
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
1158
|
+
const lastMessage = actualMessages.at(-1);
|
|
1159
|
+
if (pageContext && lastMessage?.role === "user") {
|
|
1160
|
+
const contextDoc = await resolvePageContextDoc({
|
|
1161
|
+
basePath: config.basePath,
|
|
1162
|
+
defaultLanguage,
|
|
1163
|
+
filterPage,
|
|
1164
|
+
languages,
|
|
1165
|
+
pageContext,
|
|
1166
|
+
sources: routeSources,
|
|
1167
|
+
});
|
|
1168
|
+
if (contextDoc) {
|
|
717
1169
|
const userQuestion = getMessageText(lastMessage);
|
|
718
|
-
|
|
719
|
-
basePath: config.basePath,
|
|
720
|
-
currentRoute,
|
|
721
|
-
filterPage,
|
|
722
|
-
lang: getRequestLanguage({
|
|
723
|
-
basePath: config.basePath,
|
|
724
|
-
currentRoute,
|
|
725
|
-
defaultLanguage,
|
|
726
|
-
languages,
|
|
727
|
-
}),
|
|
728
|
-
pageContext,
|
|
729
|
-
sources: routeSources,
|
|
730
|
-
});
|
|
731
|
-
if (contextDoc) {
|
|
732
|
-
localSourceDocs = [contextDoc];
|
|
733
|
-
}
|
|
1170
|
+
localSourceDocs = [contextDoc];
|
|
734
1171
|
processedMessages = [
|
|
735
1172
|
...actualMessages.slice(0, -1),
|
|
736
1173
|
{
|
|
@@ -738,7 +1175,7 @@ export const createChatRoute = ({ config, eveAgent, filterPage, mixedbread, mode
|
|
|
738
1175
|
parts: [
|
|
739
1176
|
{
|
|
740
1177
|
type: "text",
|
|
741
|
-
text:
|
|
1178
|
+
text: formatPageContextQuestion(contextDoc, userQuestion),
|
|
742
1179
|
},
|
|
743
1180
|
],
|
|
744
1181
|
},
|