@vercel/geistdocs 2.4.2 → 2.6.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.
Files changed (66) hide show
  1. package/dist/cli/index.js +1 -1
  2. package/dist/config.d.ts +14 -0
  3. package/dist/config.d.ts.map +1 -1
  4. package/dist/config.js +13 -0
  5. package/dist/internal/chat/context.d.ts +1 -0
  6. package/dist/internal/chat/context.d.ts.map +1 -1
  7. package/dist/internal/chat/context.js +1 -0
  8. package/dist/internal/chat/shell.d.ts.map +1 -1
  9. package/dist/internal/chat/shell.js +32 -10
  10. package/dist/internal/eve-agent-session.d.ts +12 -0
  11. package/dist/internal/eve-agent-session.d.ts.map +1 -0
  12. package/dist/internal/eve-agent-session.js +26 -0
  13. package/dist/internal/eve-agent.d.ts +9 -5
  14. package/dist/internal/eve-agent.d.ts.map +1 -1
  15. package/dist/internal/eve-agent.js +63 -15
  16. package/dist/internal/mdx-to-markdown.d.ts.map +1 -1
  17. package/dist/internal/mdx-to-markdown.js +68 -1
  18. package/dist/internal/provider-client.d.ts +13 -1
  19. package/dist/internal/provider-client.d.ts.map +1 -1
  20. package/dist/internal/provider-client.js +1 -1
  21. package/dist/internal/search.d.ts +23 -1
  22. package/dist/internal/search.d.ts.map +1 -1
  23. package/dist/internal/search.js +19 -4
  24. package/dist/internal/webmcp-client.d.ts +3 -4
  25. package/dist/internal/webmcp-client.d.ts.map +1 -1
  26. package/dist/internal/webmcp-client.js +9 -12
  27. package/dist/internal/webmcp.d.ts +2 -6
  28. package/dist/internal/webmcp.d.ts.map +1 -1
  29. package/dist/internal/webmcp.js +28 -79
  30. package/dist/proxy.d.ts.map +1 -1
  31. package/dist/proxy.js +10 -2
  32. package/dist/routes/agents.d.ts.map +1 -1
  33. package/dist/routes/agents.js +2 -0
  34. package/dist/routes/chat.d.ts.map +1 -1
  35. package/dist/routes/chat.js +51 -13
  36. package/dist/routes/discovery.d.ts +3 -2
  37. package/dist/routes/discovery.d.ts.map +1 -1
  38. package/dist/routes/discovery.js +49 -1
  39. package/dist/routes/mcp.d.ts +7 -2
  40. package/dist/routes/mcp.d.ts.map +1 -1
  41. package/dist/routes/mcp.js +101 -1
  42. package/dist/routes/openapi.d.ts +64 -0
  43. package/dist/routes/openapi.d.ts.map +1 -0
  44. package/dist/routes/openapi.js +481 -0
  45. package/docs/agents.md +1 -1
  46. package/docs/llms.txt +95 -29
  47. package/docs/manifest.json +1 -1
  48. package/docs/pages/agent-readiness.md +30 -0
  49. package/docs/pages/ask-ai.md +6 -1
  50. package/docs/pages/configuration.md +7 -1
  51. package/docs/pages/migration.md +1 -0
  52. package/docs/pages/provider.md +23 -0
  53. package/docs/pages/webmcp.md +27 -26
  54. package/package.json +9 -3
  55. package/template/AGENTS.md +2 -2
  56. package/template/app/[lang]/openapi.json/route.ts +6 -0
  57. package/template/app/api/mcp/route.ts +7 -0
  58. package/template/content/docs/agent-readiness.mdx +30 -0
  59. package/template/content/docs/ask-ai.mdx +6 -1
  60. package/template/content/docs/configuration.mdx +7 -1
  61. package/template/content/docs/migration.mdx +1 -0
  62. package/template/content/docs/provider.mdx +23 -0
  63. package/template/content/docs/webmcp.mdx +27 -26
  64. package/template/geistdocs.tsx +3 -0
  65. package/template/lib/geistdocs/config.tsx +1 -0
  66. package/template/package.json +1 -1
@@ -1,6 +1,19 @@
1
1
  import { type SharedProps } from "fumadocs-ui/components/dialog/search";
2
- export declare const GeistdocsSearchDialog: ({ basePath, tag, ...props }: SharedProps & {
2
+ import type { TagItem } from "fumadocs-ui/contexts/search";
3
+ export declare const GeistdocsSearchDialog: ({ allowClear, basePath, onTagChange, tag, tags, ...props }: SharedProps & {
4
+ /**
5
+ * Let a reader clear the selected scope and search everything. Only meaningful
6
+ * alongside `tags`.
7
+ *
8
+ * @defaultValue false
9
+ */
10
+ allowClear?: boolean;
3
11
  basePath?: string;
12
+ /**
13
+ * Called when a reader picks a scope, for consumers that persist the choice
14
+ * across sessions. The dialog holds the selection either way.
15
+ */
16
+ onTagChange?: (tag: string | undefined) => void;
4
17
  /**
5
18
  * Scope passed through to the search route as fumadocs' `tag` query
6
19
  * parameter, for sites whose index is partitioned (by version, section, or
@@ -16,5 +29,14 @@ export declare const GeistdocsSearchDialog: ({ basePath, tag, ...props }: Shared
16
29
  * entry, and the second would be served the first's results.
17
30
  */
18
31
  tag?: string | string[];
32
+ /**
33
+ * Scopes a reader can switch between, rendered as a row of pills under the
34
+ * results. Without them the scope is whatever `tag` says and the reader
35
+ * cannot change it; with them `tag` is the initial selection.
36
+ *
37
+ * Pills carry a single scope each, so `tag` should be a string when they are
38
+ * used. An array scope stays in force but selects no pill.
39
+ */
40
+ tags?: TagItem[];
19
41
  }) => import("react/jsx-runtime").JSX.Element;
20
42
  //# sourceMappingURL=search.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/internal/search.tsx"],"names":[],"mappings":"AAGA,OAAO,EAUL,KAAK,WAAW,EACjB,MAAM,sCAAsC,CAAC;AAI9C,eAAO,MAAM,qBAAqB,GAAI,6BAInC,WAAW,GAAG;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;;;;;;;;;OAaG;IACH,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACzB,4CAyCA,CAAC"}
1
+ {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/internal/search.tsx"],"names":[],"mappings":"AAIA,OAAO,EAWL,KAAK,WAAW,EAGjB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAI3D,eAAO,MAAM,qBAAqB,GAAI,4DAOnC,WAAW,GAAG;IACf;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;IAChD;;;;;;;;;;;;;OAaG;IACH,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;CAClB,4CAuEA,CAAC"}
@@ -1,16 +1,31 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useDocsSearch } from "fumadocs-core/search/client";
4
- import { SearchDialog as FumadocsSearchDialog, SearchDialogClose, SearchDialogContent, SearchDialogHeader, SearchDialogIcon, SearchDialogInput, SearchDialogList, SearchDialogListItem, SearchDialogOverlay, } from "fumadocs-ui/components/dialog/search";
4
+ import { useOnChange } from "fumadocs-core/utils/use-on-change";
5
+ import { SearchDialog as FumadocsSearchDialog, SearchDialogClose, SearchDialogContent, SearchDialogFooter, SearchDialogHeader, SearchDialogIcon, SearchDialogInput, SearchDialogList, SearchDialogListItem, SearchDialogOverlay, TagsList, TagsListItem, } from "fumadocs-ui/components/dialog/search";
5
6
  import { useI18n } from "fumadocs-ui/contexts/i18n";
7
+ import { useState } from "react";
6
8
  import { getPublicPath } from "../config";
7
- export const GeistdocsSearchDialog = ({ basePath, tag, ...props }) => {
9
+ export const GeistdocsSearchDialog = ({ allowClear = false, basePath, onTagChange, tag, tags, ...props }) => {
8
10
  const { locale } = useI18n();
11
+ const hasTags = tags !== undefined && tags.length > 0;
12
+ // Holds whatever scope is in force, which is not always a pill: an array scope
13
+ // has no single pill to select, and it stays in force until a reader picks
14
+ // one. Narrowing it to a string here would silently drop it.
15
+ const [selected, setSelected] = useState(tag);
16
+ // Follow the incoming scope: a consumer that derives it from the current page
17
+ // changes it on navigation, and the selection should move with it.
18
+ useOnChange(tag, (value) => {
19
+ setSelected(value);
20
+ });
9
21
  const { search, setSearch, query } = useDocsSearch({
10
22
  type: "fetch",
11
23
  locale,
12
- tag,
24
+ tag: hasTags ? selected : tag,
13
25
  api: getPublicPath("/api/search", basePath),
14
26
  });
15
- return (_jsxs(FumadocsSearchDialog, { isLoading: query.isLoading, onSearchChange: setSearch, search: search, ...props, children: [_jsx(SearchDialogOverlay, { className: "bg-background-100/80 backdrop-blur-none" }), _jsxs(SearchDialogContent, { className: "w-[640px] max-w-[calc(100vw-1rem)] border-none shadow-[var(--ds-shadow-modal)]", "data-geistdocs-command-modal": true, onEscapeKeyDown: () => props.onOpenChange(false), children: [_jsxs(SearchDialogHeader, { children: [_jsx(SearchDialogIcon, {}), _jsx(SearchDialogInput, {}), _jsx(SearchDialogClose, {})] }), _jsx(SearchDialogList, { "aria-label": "Search results", Item: (itemProps) => (_jsx(SearchDialogListItem, { ...itemProps, role: "option" })), items: query.data === "empty" ? null : query.data, role: "listbox" })] })] }));
27
+ return (_jsxs(FumadocsSearchDialog, { isLoading: query.isLoading, onSearchChange: setSearch, search: search, ...props, children: [_jsx(SearchDialogOverlay, { className: "bg-background-100/80 backdrop-blur-none" }), _jsxs(SearchDialogContent, { className: "w-[640px] max-w-[calc(100vw-1rem)] border-none shadow-[var(--ds-shadow-modal)]", "data-geistdocs-command-modal": true, onEscapeKeyDown: () => props.onOpenChange(false), children: [_jsxs(SearchDialogHeader, { children: [_jsx(SearchDialogIcon, {}), _jsx(SearchDialogInput, {}), _jsx(SearchDialogClose, {})] }), _jsx(SearchDialogList, { "aria-label": "Search results", Item: (itemProps) => (_jsx(SearchDialogListItem, { ...itemProps, role: "option" })), items: query.data === "empty" ? null : query.data, role: "listbox" }), hasTags ? (_jsx(SearchDialogFooter, { children: _jsx(TagsList, { allowClear: allowClear, onTagChange: (value) => {
28
+ setSelected(value);
29
+ onTagChange?.(value);
30
+ }, tag: typeof selected === "string" ? selected : undefined, children: tags.map((item) => (_jsx(TagsListItem, { value: item.value, children: item.name }, item.value))) }) })) : null] })] }));
16
31
  };
@@ -1,6 +1,5 @@
1
- import type { GeistdocsConfig } from "../config";
2
- export declare const GeistdocsWebMCP: ({ config, lang, }: {
1
+ import { type GeistdocsConfig } from "../config";
2
+ export declare const GeistdocsWebMCP: ({ config }: {
3
3
  config: GeistdocsConfig;
4
- lang?: string;
5
- }) => null;
4
+ }) => import("react/jsx-runtime").JSX.Element | null;
6
5
  //# sourceMappingURL=webmcp-client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webmcp-client.d.ts","sourceRoot":"","sources":["../../src/internal/webmcp-client.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAOjD,eAAO,MAAM,eAAe,GAAI,mBAG7B;IACD,MAAM,EAAE,eAAe,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,SAiBA,CAAC"}
1
+ {"version":3,"file":"webmcp-client.d.ts","sourceRoot":"","sources":["../../src/internal/webmcp-client.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,WAAW,CAAC;AAOhE,eAAO,MAAM,eAAe,GAAI,YAAY;IAAE,MAAM,EAAE,eAAe,CAAA;CAAE,mDAqBtE,CAAC"}
@@ -1,21 +1,18 @@
1
1
  "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import Script from "next/script";
2
4
  import { useEffect } from "react";
5
+ import { getPublicPath } from "../config";
3
6
  import { createWebMCPTools, registerWebMCPTools, } from "./webmcp";
4
- export const GeistdocsWebMCP = ({ config, lang, }) => {
7
+ export const GeistdocsWebMCP = ({ config }) => {
8
+ const enabled = config.webmcp?.enabled;
5
9
  useEffect(() => {
6
10
  const context = document
7
11
  .modelContext;
8
- if (!(config.webmcp?.enabled && context?.registerTool)) {
12
+ if (!(enabled && context?.registerTool)) {
9
13
  return;
10
14
  }
11
- const tools = createWebMCPTools({
12
- config,
13
- lang,
14
- location: window.location,
15
- });
16
- return registerWebMCPTools(context, tools, (error) => {
17
- console.warn("Geistdocs WebMCP registration failed:", error);
18
- });
19
- }, [config, lang]);
20
- return null;
15
+ return registerWebMCPTools(context, createWebMCPTools({ location: window.location }), (error) => console.warn("Geistdocs WebMCP registration failed:", error));
16
+ }, [enabled]);
17
+ return enabled ? (_jsx(Script, { id: "geistdocs-webmcp", src: `${getPublicPath("/api/mcp", config.basePath)}?webmcp-script` })) : null;
21
18
  };
@@ -1,4 +1,3 @@
1
- import { type GeistdocsConfig } from "../config.js";
2
1
  interface ToolExecutionContext {
3
2
  signal?: AbortSignal;
4
3
  }
@@ -17,14 +16,11 @@ export interface WebMCPContext {
17
16
  signal: AbortSignal;
18
17
  }) => Promise<void>;
19
18
  }
20
- interface WebMCPOptions {
21
- config: GeistdocsConfig;
19
+ export declare const createWebMCPTools: ({ fetcher, location, requestTimeoutMs, }: {
22
20
  fetcher?: typeof fetch;
23
- lang?: string;
24
21
  location: Pick<Location, "href">;
25
22
  requestTimeoutMs?: number;
26
- }
27
- export declare const createWebMCPTools: ({ config, fetcher, lang, location, requestTimeoutMs, }: WebMCPOptions) => WebMCPTool[];
23
+ }) => WebMCPTool[];
28
24
  export declare const registerWebMCPTools: (context: WebMCPContext, tools: WebMCPTool[], onError: (error: unknown) => void) => () => void;
29
25
  export {};
30
26
  //# sourceMappingURL=webmcp.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webmcp.d.ts","sourceRoot":"","sources":["../../src/internal/webmcp.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EAGrB,MAAM,cAAc,CAAC;AAEtB,UAAU,oBAAoB;IAC5B,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,UAAU,UAAU;IAClB,WAAW,EAAE;QAAE,YAAY,EAAE,OAAO,CAAC;QAAC,oBAAoB,EAAE,OAAO,CAAA;KAAE,CAAC;IACtE,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,CACP,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,CAAC,EAAE,oBAAoB,KAC3B,OAAO,CAAC,MAAM,CAAC,CAAC;IACrB,WAAW,EAAE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Y,EAAE,CACZ,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE;QAAE,MAAM,EAAE,WAAW,CAAA;KAAE,KAC7B,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB;AAED,eAAO,MAAM,iBAAiB,GAAI,0CAI/B;IACD,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;IACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACjC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,KAAG,UAAU,EAkCb,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,SAAS,aAAa,EACtB,OAAO,UAAU,EAAE,EACnB,SAAS,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,eAoBlC,CAAC"}
@@ -1,84 +1,33 @@
1
- import { getPublicPath, withBasePath, } from "../config.js";
2
- export const createWebMCPTools = ({ config, fetcher = fetch, lang, location, requestTimeoutMs = 15_000, }) => {
3
- const getRequestSignal = (signal) => {
4
- const deadline = AbortSignal.timeout(requestTimeoutMs);
5
- return signal ? AbortSignal.any([signal, deadline]) : deadline;
6
- };
7
- const annotations = { readOnlyHint: true, untrustedContentHint: true };
8
- return [
9
- {
10
- name: "search_docs",
11
- description: `Search ${config.title} documentation in the current language. Returns matching titles, excerpts, and page URLs.`,
12
- annotations,
13
- inputSchema: {
14
- type: "object",
15
- properties: { query: { type: "string", minLength: 1, maxLength: 500 } },
16
- required: ["query"],
17
- additionalProperties: false,
18
- },
19
- execute: async (input, { signal } = {}) => {
20
- if (typeof input.query !== "string" ||
21
- !input.query.trim() ||
22
- input.query.length > 500) {
23
- throw new Error("query must contain between 1 and 500 characters.");
24
- }
25
- const url = new URL(getPublicPath("/api/search", config.basePath), location.href);
26
- url.searchParams.set("query", input.query.trim());
27
- url.searchParams.set("locale", lang ?? config.defaultLanguage ?? "en");
28
- const response = await fetcher(url, {
29
- signal: getRequestSignal(signal),
30
- redirect: "error",
31
- });
32
- if (!response.ok) {
33
- throw new Error(`Documentation search failed (${response.status}).`);
34
- }
35
- const results = await response.json();
36
- if (!Array.isArray(results)) {
37
- throw new Error("Documentation search returned an invalid response.");
38
- }
39
- return JSON.stringify(results.map((result) => {
40
- if (typeof result !== "object" ||
41
- result === null ||
42
- !("url" in result) ||
43
- typeof result.url !== "string") {
44
- throw new Error("Documentation search returned an invalid result.");
45
- }
46
- return {
47
- ...result,
48
- url: withBasePath(result.url, config.basePath),
49
- };
50
- }));
51
- },
1
+ export const createWebMCPTools = ({ fetcher = fetch, location, requestTimeoutMs = 15_000, }) => [
2
+ {
3
+ name: "read_current_page",
4
+ description: "Read the current documentation page as Markdown. Navigate to a documentation page before calling this tool.",
5
+ annotations: { readOnlyHint: true, untrustedContentHint: true },
6
+ inputSchema: {
7
+ type: "object",
8
+ properties: {},
9
+ additionalProperties: false,
52
10
  },
53
- {
54
- name: "read_current_page",
55
- description: "Read the current documentation page as Markdown. Navigate to a documentation page before calling this tool.",
56
- annotations,
57
- inputSchema: {
58
- type: "object",
59
- properties: {},
60
- additionalProperties: false,
61
- },
62
- execute: async (_input, { signal } = {}) => {
63
- const url = new URL(location.href);
64
- url.hash = "";
65
- url.search = "";
66
- const response = await fetcher(url, {
67
- headers: { Accept: "text/markdown" },
68
- redirect: "error",
69
- signal: getRequestSignal(signal),
70
- });
71
- if (!response.ok) {
72
- throw new Error(`Documentation page could not be read (${response.status}).`);
73
- }
74
- if (!response.headers.get("content-type")?.includes("text/markdown")) {
75
- throw new Error("The current page does not provide documentation Markdown.");
76
- }
77
- return response.text();
78
- },
11
+ execute: async (_input, { signal } = {}) => {
12
+ const url = new URL(location.href);
13
+ url.hash = "";
14
+ url.search = "";
15
+ const deadline = AbortSignal.timeout(requestTimeoutMs);
16
+ const response = await fetcher(url, {
17
+ headers: { Accept: "text/markdown" },
18
+ redirect: "error",
19
+ signal: signal ? AbortSignal.any([signal, deadline]) : deadline,
20
+ });
21
+ if (!response.ok) {
22
+ throw new Error(`Documentation page could not be read (${response.status}).`);
23
+ }
24
+ if (!response.headers.get("content-type")?.includes("text/markdown")) {
25
+ throw new Error("The current page does not provide documentation Markdown.");
26
+ }
27
+ return response.text();
79
28
  },
80
- ];
81
- };
29
+ },
30
+ ];
82
31
  export const registerWebMCPTools = (context, tools, onError) => {
83
32
  const controller = new AbortController();
84
33
  const register = async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,WAAW,EAEjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,eAAe,EAGrB,MAAM,UAAU,CAAC;AASlB,MAAM,MAAM,eAAe,GACvB,UAAU,GACV,iBAAiB,GACjB,WAAW,GACX,IAAI,CAAC;AAET,MAAM,WAAW,yBAAyB;IACxC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,WAAW,CAAC,EAAE,QAAQ,GAAG,mBAAmB,GAAG,eAAe,CAAC;IAC/D,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,cAAc,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,WAAW,CAAC;CACtB;AAED,KAAK,eAAe,GAAG,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAC;AAEnD,MAAM,MAAM,kBAAkB,GAAG,CAC/B,OAAO,EAAE,qBAAqB,KAC3B,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,CAAC;AAEhD,MAAM,MAAM,yBAAyB,GAAG,CACtC,QAAQ,EAAE,IAAI,MAAM,EAAE,EACtB,OAAO,EAAE,qBAAqB,KAC3B,OAAO,CAAC,I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EAAE,MAAM,CAAC;KAClB,KAAK,IAAI,MAAM,EAAE,CAAC,CAAC;CACzB;AAED,MAAM,WAAW,kBAAkB;IACjC,4EAA4E;IAC5E,wBAAwB,CAAC,EAAE,sBAAsB,EAAE,CAAC;IACpD,KAAK,CAAC,EAAE,kBAAkB,GAAG,kBAAkB,EAAE,CAAC;IAClD,MAAM,CAAC,EAAE,kBAAkB,GAAG,kBAAkB,EAAE,CAAC;IACnD,MAAM,EAAE,IAAI,CACV,eAAe,EACf,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,iBAAiB,GAAG,cAAc,CACtE,CAAC;IACF,sFAAsF;IACtF,gBAAgB,CAAC,EACb,OAAO,GACP,CAAC,CAAC,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,CAAC;IACnE,cAAc,CAAC,EAAE,sBAAsB,EAAE,CAAC;IAC1C,oBAAoB,CAAC,EAAE,CACrB,KAAK,EAAE,yBAAyB,KAC7B,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC1B,8EAA8E;IAC9E,gBAAgB,CAAC,EAAE,yBAAyB,CAAC;CAC9C;AAqKD,eAAO,MAAM,WAAW,GAAI,gIASzB,kBAAkB,MA6VL,SAAS,WAAW,EAAE,SAAS,cAAc,sBA0D5D,CAAC"}
package/dist/proxy.js CHANGED
@@ -2,7 +2,7 @@ import { applyMarkdownHeaders, createNotFoundResponse, } from "@vercel/agent-rea
2
2
  import { defineI18n } from "fumadocs-core/i18n";
3
3
  import { createI18nMiddleware } from "fumadocs-core/i18n/middleware";
4
4
  import { NextResponse, } from "next/server";
5
- import { getPublicPath, normalizeBasePath, } from "./config";
5
+ import { getPublicPath, normalizeBasePath, stripBasePath, } from "./config";
6
6
  import { matchesAppRoute, parseAppRouteManifest, } from "./internal/app-route-manifest";
7
7
  import { getMarkdownDecision } from "./internal/markdown-negotiation";
8
8
  import { renderNotFoundMarkdown } from "./internal/not-found";
@@ -23,6 +23,7 @@ const PACKAGE_ROUTE_PATHS = new Set([
23
23
  "/.well-known/mcp.json",
24
24
  "/agents.md",
25
25
  "/llms.txt",
26
+ "/openapi.json",
26
27
  "/rss.xml",
27
28
  "/sitemap.md",
28
29
  ]);
@@ -139,6 +140,13 @@ export const createProxy = ({ additionalMarkdownRoutes, after, before, config, m
139
140
  hideLocale: "default-locale",
140
141
  });
141
142
  const configuredBasePath = normalizeBasePath(config.basePath);
143
+ // The site OpenAPI document can be mounted at a custom path; like the other
144
+ // package routes it must never be captured by a Markdown mapping.
145
+ const packageRoutePaths = new Set(PACKAGE_ROUTE_PATHS);
146
+ const siteOpenApiPath = config.agent?.api?.siteOpenApiUrl;
147
+ if (siteOpenApiPath) {
148
+ packageRoutePaths.add(stripBasePath(siteOpenApiPath, configuredBasePath));
149
+ }
142
150
  const internationalizer = createI18nMiddleware({
143
151
  ...i18n,
144
152
  format: (locale, path) => getPublicPath(`/${locale}${path}`, configuredBasePath),
@@ -249,7 +257,7 @@ export const createProxy = ({ additionalMarkdownRoutes, after, before, config, m
249
257
  }
250
258
  const localized = getLocalizedPathname(pathname, languages, defaultLanguage);
251
259
  if ((localized.hasLanguagePrefix && localized.language === defaultLanguage) ||
252
- PACKAGE_ROUTE_PATHS.has(localized.pathname)) {
260
+ packageRoutePaths.has(localized.pathname)) {
253
261
  return null;
254
262
  }
255
263
  const extensionResponse = await handleMarkdownExtensionRequest(request, context, proxyContext, localized.pathname, localized.language, pathname);
@@ -1 +1 @@
1
- {"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/routes/agents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,WAAW,CAAC;AASnB,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,IAAI,CACV,eAAe,EACb,OAAO,GACP,UAAU,GACV,SAAS,GACT,iBAAiB,GACjB,QAAQ,GACR,KAAK,GACL,OAAO,GACP,cAAc,GACd,UAAU,CACb,CAAC;IACF,SAAS,CAAC,EAAE,CACV,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,WAAW,CAAA;KAAE,KAC7C,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;CAC/B;AAsTD,eAAO,MAAM,iBAAiB,GAAI,wBAG/B,wBAAwB;mBAId,WAAW,eACR;QAAE,MAAM,CAAC,EAAE,OAAO,CAAC;YAAE,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE;;;;;CA2BtD,CAAC"}
1
+ {"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/routes/agents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,WAAW,CAAC;AASnB,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,IAAI,CACV,eAAe,EACb,OAAO,GACP,UAAU,GACV,SAAS,GACT,iBAAiB,GACjB,QAAQ,GACR,KAAK,GACL,OAAO,GACP,cAAc,GACd,UAAU,CACb,CAAC;IACF,SAAS,CAAC,EAAE,CACV,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,WAAW,CAAA;KAAE,KAC7C,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;CAC/B;AA4TD,eAAO,MAAM,iBAAiB,GAAI,wBAG/B,wBAAwB;mBAId,WAAW,eACR;QAAE,MAAM,CAAC,EAAE,OAAO,CAAC;YAAE,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE;;;;;CA2BtD,CAAC"}
@@ -95,6 +95,8 @@ const getApiLinks = (api, config, origin) => [
95
95
  renderLink("Rate limits", toSiteUrl(config, origin, api.rateLimitsUrl)),
96
96
  api?.errorsUrl &&
97
97
  renderLink("Error handling", toSiteUrl(config, origin, api.errorsUrl)),
98
+ api?.siteOpenApiUrl &&
99
+ renderLink("Documentation site API (OpenAPI)", toSiteUrl(config, origin, api.siteOpenApiUrl), "HTTP endpoints of this documentation site itself, not the product API"),
98
100
  ].filter((link) => Boolean(link));
99
101
  const renderApiSection = (api, config, origin) => {
100
102
  const links = getApiLinks(api, config, origin);
@@ -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;AAQpC,OAAO,EACL,KAAK,mBAAmB,EAEzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEvD,KAAK,YAAY,GAAG,qBAAqB,CAAC;AAyB1C,UAAU,eAAe;IACvB,OAAO,CAAC,EAAE,WAAW,GAAG,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IACnE,GAAG,EAAE,MAAM,CAAC;CACb;AAED,UAAU,mBAAmB;IAC3B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,WAAW,GAAG,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IACnE,qEAAqE;IACrE,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,UAAU,sBAAsB;IAC9B,MAAM,EAAE,IAAI,CACV,eAAe,EACf,IAAI,GAAG,UAAU,GAAG,iBAAiB,GAAG,QAAQ,GAAG,cAAc,CAClE,CAAC;IACF;;;OAGG;IACH,QAAQ,CAAC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AAG,cAAc,CAClE,CAAC;IACF;;;OAGG;IACH,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAC/B,4DAA4D;IAC5D,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC;;;OAGG;IACH,UAAU,CAAC,EAAE,qBAAqB,CAAC;IACnC;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;CAC1B;AAy/BD,eAAO,MAAM,eAAe,GAAI,8EAS7B,sBAAsB;gBAeE,OAAO;;CAqLjC,CAAC"}
@@ -5,7 +5,8 @@ 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, getEveAgentSessionHandle, resolveEveAgentUrl, runEveAgentTurn, } from "../internal/eve-agent";
8
+ import { buildEveAgentTranscript, capLastUserMessageText, getEveAgentSessionHandle, prewarmEveAgentSession, resolveEveAgentUrl, runEveAgentTurn, } from "../internal/eve-agent";
9
+ import { isEveAgentSessionHandle } from "../internal/eve-agent-session.js";
9
10
  import { isPageVisibleForSurface, } from "../page-visibility";
10
11
  const DEFAULT_CHAT_MODEL = "openai/gpt-5.6-sol";
11
12
  const MAX_CONTEXT_CHARS = 1500;
@@ -77,6 +78,9 @@ const isPageContextMessage = (message) => message.metadata?.isPageContext;
77
78
  const isChatRequestBody = (value) => typeof value === "object" &&
78
79
  value !== null &&
79
80
  Array.isArray(value.messages);
81
+ const isEveAgentPrewarmRequestBody = (value) => typeof value === "object" &&
82
+ value !== null &&
83
+ value.prewarm === true;
80
84
  const getPageData = (page) => page.data;
81
85
  const getStructuredContent = (page) => JSON.stringify(getPageData(page).structuredData?.contents ?? "");
82
86
  const isChatPageVisible = (page, lang, source, filterPage) => isPageVisibleForSurface(page, "chat") &&
@@ -535,7 +539,38 @@ const createChatErrorResponse = (error, status) => new Response(JSON.stringify({
535
539
  status,
536
540
  headers: { "Content-Type": "application/json" },
537
541
  });
538
- const createEveAgentResponse = async ({ actualMessages, agentUrl, config, currentRoute, defaultLanguage, eveAgent, filterPage, languages, messages, pageContext, req, routeSources, searchDocuments, }) => {
542
+ const createEveAgentPrewarmResponse = async ({ agentUrl, enabled, eveAgent, req, }) => {
543
+ if (!(agentUrl && enabled)) {
544
+ return createChatErrorResponse("Invalid chat request: eve agent prewarming is not enabled.", 400);
545
+ }
546
+ const headers = await getEveAgentRequestHeaders({ eveAgent, req });
547
+ const session = await prewarmEveAgentSession({
548
+ agentUrl,
549
+ headers,
550
+ signal: req.signal,
551
+ });
552
+ return Response.json(session, { status: 202 });
553
+ };
554
+ const resolveChatRequestBody = async ({ eveAgent, eveAgentUrl, prewarmEnabled, req, }) => {
555
+ const body = await req.json();
556
+ if (isEveAgentPrewarmRequestBody(body)) {
557
+ return {
558
+ response: await createEveAgentPrewarmResponse({
559
+ agentUrl: eveAgentUrl,
560
+ enabled: prewarmEnabled,
561
+ eveAgent,
562
+ req,
563
+ }),
564
+ };
565
+ }
566
+ if (!isChatRequestBody(body)) {
567
+ return {
568
+ response: createChatErrorResponse("Invalid chat request: messages must be an array.", 400),
569
+ };
570
+ }
571
+ return { body };
572
+ };
573
+ const createEveAgentResponse = async ({ actualMessages, agentUrl, config, currentRoute, defaultLanguage, eveAgent, filterPage, languages, messages, pageContext, prewarmedHandle, req, routeSources, searchDocuments, }) => {
539
574
  const cappedMessages = capLastUserMessageText(actualMessages, MAX_EVE_AGENT_MESSAGE_CHARS);
540
575
  const { messages: contextMessages, sourceDocs } = await buildProxyMessages({
541
576
  actualMessages: cappedMessages,
@@ -553,12 +588,14 @@ const createEveAgentResponse = async ({ actualMessages, agentUrl, config, curren
553
588
  return createChatErrorResponse("Invalid chat request: expected a user message.", 400);
554
589
  }
555
590
  const lastMessageText = getMessageText(lastMessage);
556
- const handle = getEveAgentSessionHandle(cappedMessages);
591
+ const persistedHandle = getEveAgentSessionHandle(cappedMessages);
592
+ const handle = persistedHandle ??
593
+ (isEveAgentSessionHandle(prewarmedHandle) ? prewarmedHandle : null);
557
594
  // A fresh eve session (no handle, or the handle turned out to be
558
595
  // unusable) receives the prior turns inlined so it still sees the
559
596
  // conversation so far.
560
597
  const transcriptMessage = buildEveAgentTranscript(contextMessages, lastMessageText);
561
- const outboundMessage = handle ? lastMessageText : transcriptMessage;
598
+ const outboundMessage = persistedHandle ? lastMessageText : transcriptMessage;
562
599
  if (!outboundMessage.trim()) {
563
600
  return createChatErrorResponse("Invalid chat request: message must not be empty.", 400);
564
601
  }
@@ -604,16 +641,16 @@ export const createChatRoute = ({ config, eveAgent, filterPage, mixedbread, mode
604
641
  });
605
642
  const POST = async (req) => {
606
643
  try {
607
- const requestBody = await req.json();
608
- if (!isChatRequestBody(requestBody)) {
609
- return new Response(JSON.stringify({
610
- error: "Invalid chat request: messages must be an array.",
611
- }), {
612
- status: 400,
613
- headers: { "Content-Type": "application/json" },
614
- });
644
+ const resolvedRequest = await resolveChatRequestBody({
645
+ eveAgent,
646
+ eveAgentUrl,
647
+ prewarmEnabled: config.ai?.eveAgent?.prewarm === true,
648
+ req,
649
+ });
650
+ if ("response" in resolvedRequest) {
651
+ return resolvedRequest.response;
615
652
  }
616
- const { messages, currentRoute, pageContext } = requestBody;
653
+ const { currentRoute, eveAgentSession, messages, pageContext } = resolvedRequest.body;
617
654
  const actualMessages = messages.filter((message) => !isPageContextMessage(message));
618
655
  if (eveAgentUrl) {
619
656
  return await createEveAgentResponse({
@@ -627,6 +664,7 @@ export const createChatRoute = ({ config, eveAgent, filterPage, mixedbread, mode
627
664
  languages,
628
665
  messages,
629
666
  pageContext,
667
+ prewarmedHandle: eveAgentSession,
630
668
  req,
631
669
  routeSources,
632
670
  searchDocuments,
@@ -1,4 +1,4 @@
1
- import { type GeistdocsConfig } from "../config";
1
+ import { type GeistdocsConfig } from "../config.js";
2
2
  type DiscoveryConfig = Pick<GeistdocsConfig, "agent">;
3
3
  export declare const getDiscoveryLanguages: (config: Pick<GeistdocsConfig, "defaultLanguage" | "translations">) => string[];
4
4
  export declare const toAbsoluteUrl: ({ basePath, href, origin, }: {
@@ -12,7 +12,8 @@ export declare const toPublicUrl: ({ basePath, href, origin, }: {
12
12
  origin: string;
13
13
  }) => string;
14
14
  export declare const toSiteUrl: (config: Pick<GeistdocsConfig, "basePath">, origin: string, href: string) => string;
15
- export declare const validateAgentDiscoveryConfig: (config: DiscoveryConfig) => void;
15
+ type SiteOpenApiPathConfig = Pick<GeistdocsConfig, "basePath" | "defaultLanguage" | "translations">;
16
+ export declare const validateAgentDiscoveryConfig: (config: DiscoveryConfig & SiteOpenApiPathConfig) => void;
16
17
  export declare const validateMcpManifestConfig: (config: DiscoveryConfig) => void;
17
18
  export {};
18
19
  //# sourceMappingURL=discovery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../src/routes/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAA+B,MAAM,WAAW,CAAC;AAE9E,KAAK,eAAe,GAAG,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;AAItD,eAAO,MAAM,qBAAqB,GAChC,QAAQ,IAAI,CAAC,eAAe,EAAE,iBAAiB,GAAG,cAAc,CAAC,aAMlE,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,6BAI3B;IACD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB,WAMA,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,6BAIzB;IACD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB,WAMA,CAAC;AA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BasePath } from "../config";
1
+ import { getPublicPath, stripBasePath, withBasePath, } from "../config.js";
2
2
  const ABSOLUTE_URL_PATTERN = /^[a-z][a-z\d+.-]*:/i;
3
+ const QUERY_OR_FRAGMENT_PATTERN = /[?#]/;
4
+ const TRAILING_SLASH_PATTERN = /\/$/;
5
+ const MARKDOWN_EXTENSION_PATTERN = /\.mdx?$/i;
6
+ /** Paths the OpenAPI document already describes; the document cannot live at one of them. */
7
+ const RESERVED_SITE_PATHS = new Set([
8
+ "/.well-known/mcp.json",
9
+ "/agents.md",
10
+ "/api/chat",
11
+ "/api/search",
12
+ "/llms.txt",
13
+ "/sitemap.md",
14
+ ]);
3
15
  export const getDiscoveryLanguages = (config) => {
4
16
  const defaultLanguage = config.defaultLanguage ?? "en";
5
17
  const languages = Object.keys(config.translations ?? {});
@@ -42,11 +54,47 @@ const assertDiscoveryUrl = (value, field) => {
42
54
  throw new Error(`${field} must use http or https.`);
43
55
  }
44
56
  };
57
+ /**
58
+ * The site OpenAPI path is matched against language-stripped request
59
+ * pathnames by the proxy and echoed as the document's own path, so only a
60
+ * plain, language-neutral route path that a request can carry is accepted.
61
+ */
62
+ const assertSiteOpenApiPath = (value, { basePath, ...languagesConfig }) => {
63
+ const field = "agent.api.siteOpenApiUrl";
64
+ if (ABSOLUTE_URL_PATTERN.test(value)) {
65
+ throw new Error(`${field} must be a root-relative path.`);
66
+ }
67
+ assertDiscoveryUrl(value, field);
68
+ if (QUERY_OR_FRAGMENT_PATTERN.test(value)) {
69
+ throw new Error(`${field} must not include a query string or fragment.`);
70
+ }
71
+ const appLocalPath = stripBasePath(value, basePath);
72
+ if (appLocalPath === "/") {
73
+ throw new Error(`${field} must not be the site root.`);
74
+ }
75
+ if (TRAILING_SLASH_PATTERN.test(value)) {
76
+ throw new Error(`${field} must not end with a slash.`);
77
+ }
78
+ if (RESERVED_SITE_PATHS.has(appLocalPath)) {
79
+ throw new Error(`${field} must not be a path the document already describes (${appLocalPath}).`);
80
+ }
81
+ // `.md` and `.mdx` URLs are page-level Markdown everywhere else on the site.
82
+ if (MARKDOWN_EXTENSION_PATTERN.test(appLocalPath)) {
83
+ throw new Error(`${field} must not end with .md or .mdx.`);
84
+ }
85
+ const firstSegment = appLocalPath.split("/")[1];
86
+ if (getDiscoveryLanguages(languagesConfig).includes(firstSegment)) {
87
+ throw new Error(`${field} must not start with a language prefix (/${firstSegment}); the document is served for every language.`);
88
+ }
89
+ };
45
90
  export const validateAgentDiscoveryConfig = (config) => {
46
91
  if (!config.agent || config.agent.enabled === false) {
47
92
  return;
48
93
  }
49
94
  const api = config.agent?.api;
95
+ if (api?.siteOpenApiUrl !== undefined) {
96
+ assertSiteOpenApiPath(api.siteOpenApiUrl, config);
97
+ }
50
98
  api?.openApiSpecs?.forEach((spec, index) => {
51
99
  if (spec.label.trim() === "") {
52
100
  throw new Error(`agent.api.openApiSpecs[${index}].label must not be empty.`);
@@ -1,5 +1,10 @@
1
- import type { NextRequest } from "next/server";
2
- import type { GeistdocsConfig } from "../config";
1
+ import { NextRequest } from "next/server.js";
2
+ import { type GeistdocsConfig } from "../config.js";
3
+ export interface CreateMcpRouteOptions {
4
+ config: Pick<GeistdocsConfig, "title" | "basePath" | "defaultLanguage" | "translations" | "webmcp">;
5
+ search: (request: NextRequest) => Response | Promise<Response>;
6
+ }
7
+ export declare const createMcpRoute: ({ config, search }: CreateMcpRouteOptions) => (request: Request) => Promise<Response>;
3
8
  export interface GeistdocsMcpManifestServer {
4
9
  description?: string;
5
10
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/routes/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAOjD,MAAM,WAAW,0BAA0B;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG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