@publish.os/nextjs 0.0.1-alpha.91 → 0.0.1-alpha.92
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/compiler-assets/nextjs/defaults/group/index.tsx +16 -11
- package/compiler-assets/nextjs/defaults/group/layout.tsx +6 -2
- package/compiler-assets/nextjs/defaults/group/page.tsx +7 -6
- package/compiler-assets/nextjs/defaults/project/next.config.mjs +2 -1
- package/compiler-assets/nextjs/defaults/root/index.tsx +16 -11
- package/compiler-assets/nextjs/defaults/root/layout.tsx +7 -3
- package/compiler-assets/nextjs/shims/agent-user-agents.ts +65 -0
- package/compiler-assets/nextjs/shims/document.tsx +9 -1
- package/compiler-assets/nextjs/shims/generated-leaf-page.tsx +3 -0
- package/compiler-assets/nextjs/shims/proxy.ts +156 -54
- package/dist/{build-operation-5QMLXF7N.js → build-operation-CJDUL4OW.js} +5 -5
- package/dist/{chunk-GBPLER5H.js → chunk-3T4HVDSC.js} +2 -2
- package/dist/{chunk-UYGCOWRF.js → chunk-DX7PXFCM.js} +860 -50
- package/dist/{chunk-F3AGNDF4.js → chunk-DZ3VWEV5.js} +860 -575
- package/dist/{chunk-OXOFRXEI.js → chunk-NHSLTARU.js} +1284 -1164
- package/dist/{chunk-ORIUWJBQ.js → chunk-SBMDONTV.js} +3 -2
- package/dist/compiler.js +42 -23
- package/dist/components/blocks/agent-actions.d.ts +7 -7
- package/dist/components/blocks/agent-actions.js +1 -32
- package/dist/components/blocks/toc.d.ts +7 -7
- package/dist/components/ui/button.d.ts +1 -2
- package/dist/{compose-CVBJRAF6.js → compose-44GJSMXD.js} +2 -2
- package/dist/config/createNextConfig.js +2 -0
- package/dist/{dev-operation-OSHHWRWK.js → dev-operation-WNECBHZ5.js} +17 -7
- package/dist/{ide-support-CU6Z5PVR.js → ide-support-TG74L4FF.js} +3 -3
- package/dist/index.d.ts +143 -126
- package/dist/index.js +25 -0
- package/dist/kernel/components/blocks/AgentActions.d.ts +7 -7
- package/dist/kernel/components/blocks/AgentActions.js +1 -32
- package/dist/kernel/components/blocks/agent-actions.d.ts +1 -2
- package/dist/kernel/components/blocks/agent-actions.js +1 -32
- package/dist/kernel/components/blocks/animated-icon-swap.d.ts +2 -2
- package/dist/kernel/components/blocks/color-palette.d.ts +2 -2
- package/dist/kernel/components/blocks/logo-block.d.ts +2 -2
- package/dist/kernel/components/blocks/nav-breadcrumb.d.ts +6 -5
- package/dist/kernel/components/blocks/nav-breadcrumb.js +19 -13
- package/dist/kernel/components/blocks/navbar.d.ts +5 -4
- package/dist/kernel/components/blocks/navbar.js +62 -42
- package/dist/kernel/components/blocks/navigation-progress.d.ts +2 -2
- package/dist/kernel/components/blocks/next-prev.d.ts +4 -4
- package/dist/kernel/components/blocks/next-prev.js +29 -6
- package/dist/kernel/components/blocks/page-list.d.ts +4 -4
- package/dist/kernel/components/blocks/page-list.js +30 -7
- package/dist/kernel/components/blocks/search.d.ts +9 -15
- package/dist/kernel/components/blocks/sidebar-node.d.ts +3 -5
- package/dist/kernel/components/blocks/sidebar-node.js +12 -2
- package/dist/kernel/components/blocks/sidebar.d.ts +6 -7
- package/dist/kernel/components/blocks/sidebar.js +132 -26
- package/dist/kernel/components/blocks/theme-toggle.d.ts +3 -4
- package/dist/kernel/components/blocks/toc-client.d.ts +7 -7
- package/dist/kernel/components/blocks/toc.d.ts +3 -3
- package/dist/kernel/components/mdx/components/blockquote.d.ts +2 -2
- package/dist/kernel/components/mdx/components/callout.d.ts +3 -3
- package/dist/kernel/components/mdx/components/code-block.d.ts +2 -2
- package/dist/kernel/components/mdx/components/copy-code-button.d.ts +2 -2
- package/dist/kernel/components/mdx/components/figure-caption.d.ts +2 -2
- package/dist/kernel/components/mdx/components/figure.d.ts +3 -3
- package/dist/kernel/components/mdx/components/footnotes.d.ts +2 -2
- package/dist/kernel/components/mdx/components/heading-copy-link.d.ts +2 -2
- package/dist/kernel/components/mdx/components/heading.d.ts +2 -2
- package/dist/kernel/components/mdx/components/hr.d.ts +4 -4
- package/dist/kernel/components/mdx/components/image-zoom.d.ts +3 -3
- package/dist/kernel/components/mdx/components/image-zoom.js +3 -2
- package/dist/kernel/components/mdx/components/image.d.ts +2 -2
- package/dist/kernel/components/mdx/components/image.js +1 -1
- package/dist/kernel/components/mdx/components/inline-code.d.ts +2 -2
- package/dist/kernel/components/mdx/components/kbd.d.ts +3 -3
- package/dist/kernel/components/mdx/components/link.d.ts +3 -3
- package/dist/kernel/components/mdx/components/paragraph.d.ts +2 -2
- package/dist/kernel/components/mdx/components/strikethrough.d.ts +2 -2
- package/dist/kernel/components/mdx/components/table.d.ts +7 -7
- package/dist/kernel/components/mdx/components/task-list.d.ts +3 -3
- package/dist/kernel/components/mdx/components/video-player.d.ts +2 -2
- package/dist/kernel/components/mdx/components/video.d.ts +2 -3
- package/dist/kernel/components/mdx/error-boundary.d.ts +2 -3
- package/dist/kernel/components/mdx/error-fallback.d.ts +2 -2
- package/dist/kernel/components/mdx/mdx.d.ts +42 -11
- package/dist/kernel/components/mdx/mdx.js +1 -1
- package/dist/kernel/components/next-image.d.ts +3 -3
- package/dist/kernel/components/ui/accordion.d.ts +7 -7
- package/dist/kernel/components/ui/breadcrumb-trail.d.ts +2 -3
- package/dist/kernel/components/ui/breadcrumb.d.ts +13 -13
- package/dist/kernel/components/ui/button-group.d.ts +5 -5
- package/dist/kernel/components/ui/button.d.ts +3 -3
- package/dist/kernel/components/ui/card.d.ts +7 -7
- package/dist/kernel/components/ui/dialog.d.ts +10 -10
- package/dist/kernel/components/ui/drawer.d.ts +12 -12
- package/dist/kernel/components/ui/kbd.d.ts +3 -3
- package/dist/kernel/components/ui/link.d.ts +3 -3
- package/dist/kernel/components/ui/menu.d.ts +22 -22
- package/dist/kernel/components/ui/mod-key.d.ts +2 -3
- package/dist/kernel/components/ui/navigation-menu.d.ts +15 -15
- package/dist/kernel/components/ui/popover.d.ts +11 -11
- package/dist/kernel/components/ui/progress.d.ts +7 -7
- package/dist/kernel/components/ui/scroll-area.d.ts +1 -2
- package/dist/kernel/components/ui/select.d.ts +16 -16
- package/dist/kernel/components/ui/separator.d.ts +3 -3
- package/dist/kernel/components/ui/table.d.ts +7 -7
- package/dist/kernel/components/ui/tabs.d.ts +12 -12
- package/dist/kernel/components/ui/tag.d.ts +3 -3
- package/dist/kernel/components/ui/text.d.ts +4 -4
- package/dist/kernel/components/ui/toast.d.ts +11 -11
- package/dist/kernel/components/ui/tooltip.d.ts +9 -9
- package/dist/kernel/defaults.registry.d.ts +2 -2
- package/dist/kernel/defaults.registry.js +2 -2
- package/dist/kernel/routes/agent/markdown.d.ts +4 -0
- package/dist/kernel/routes/agent/markdown.js +11 -7
- package/dist/kernel/routes/layouts/group.d.ts +1 -1
- package/dist/kernel/routes/metadata/feed.d.ts +1 -2
- package/dist/kernel/routes/metadata/feed.js +34 -29
- package/dist/kernel/routes/metadata/llms.d.ts +3 -31
- package/dist/kernel/routes/metadata/llms.js +2 -200
- package/dist/kernel/routes/metadata/robots.d.ts +5 -3
- package/dist/kernel/routes/metadata/robots.js +4 -25
- package/dist/kernel/routes/metadata/sitemap.d.ts +15 -1
- package/dist/kernel/routes/metadata/sitemap.js +200 -112
- package/dist/kernel/routes/not-found.js +1 -1
- package/dist/kernel/routes/pages/group.d.ts +3 -3
- package/dist/kernel/routes/pages/group.js +10 -4
- package/dist/kernel/routes/pages/leaf.d.ts +9 -4
- package/dist/kernel/routes/pages/leaf.js +16 -8
- package/dist/kernel/routes/pages/root.d.ts +3 -3
- package/dist/kernel/routes/pages/root.js +20 -5
- package/dist/keyboard-shortcuts.d.ts +2 -2
- package/dist/manifest-types-CcVPH_jh.d.ts +83 -0
- package/dist/resolvers/manifest-resolver.d.ts +2 -2
- package/dist/resolvers/manifest-resolver.js +65 -35
- package/dist/search.d.ts +2 -9
- package/dist/search.js +2 -7
- package/dist/sidebar-types-CMrMM0Nj.d.ts +105 -0
- package/dist/theme-scope.d.ts +2 -2
- package/dist/types-BbqmOzLC.d.ts +168 -0
- package/dist/types-TjH1ek0X.d.ts +22 -0
- package/dist/types.d.ts +116 -91
- package/dist/{validate-local-source-SV44DBQT.js → validate-local-source-EN2GW4FR.js} +3 -3
- package/dist/{validate-publish-os-source-NZJF3TB2.js → validate-publish-os-source-OEWQDB7B.js} +2 -2
- package/init/seed/minimal/publish.os/blog/index.tsx +25 -22
- package/init/seed/minimal/publish.os/blog/page.tsx +31 -16
- package/init/seed/minimal/publish.os/components/blog/copy-link.tsx +1 -1
- package/init/seed/minimal/publish.os/components/blog/frontmatter.ts +41 -0
- package/init/seed/minimal/publish.os/publish.os.config.json +13 -2
- package/init/seed/minimal/seed.json +1 -0
- package/init/seed/scratch/publish.os/publish.os.config.json +1 -1
- package/package.json +4 -4
- package/release/app/phosphor/package.json +1 -1
- package/release/app/phosphor/pnpm-lock.yaml.template +53 -127
- package/release/compiler/pnpm-lock.yaml.template +49 -123
- package/release/release.json +4 -4
- package/dist/sidebar-types-DKpR27II.d.ts +0 -25
- package/dist/types-CJWRG05y.d.ts +0 -76
- package/dist/types-CUtrppxt.d.ts +0 -69
- package/dist/types-J2w_puPF.d.ts +0 -128
- package/dist/{button-BdCScEKi.d.ts → button-D6Xp2HBm.d.ts} +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isMarkdownClient } from "@app/agent-user-agents";
|
|
1
2
|
import {
|
|
2
3
|
createNotFoundTextResponse,
|
|
3
4
|
resolveNotFoundScope,
|
|
@@ -6,8 +7,6 @@ import { agentRouteConfig } from "@source/.publishos/agent-route-config.generate
|
|
|
6
7
|
import type { NextRequest } from "next/server";
|
|
7
8
|
import { NextResponse } from "next/server";
|
|
8
9
|
|
|
9
|
-
const AGENT_USER_AGENT_PATTERN =
|
|
10
|
-
/\b(?:axios|got|node-fetch|undici|curl|wget|python-requests|httpx|aiohttp|claude-code|claudebot|claude|cursor|chatgpt|openai|perplexity|anthropic-ai)\b/i;
|
|
11
10
|
const INTERNAL_MARKDOWN_PREFIX = "/__publishos/md";
|
|
12
11
|
const FRAMEWORK_PREFIX = "__PUBLISHOS_FRAMEWORK_PREFIX__";
|
|
13
12
|
const TEXT_METHODS = new Set(["GET", "HEAD"]);
|
|
@@ -36,11 +35,15 @@ function normalizePagePath(pathname: string): string {
|
|
|
36
35
|
return pathname.replace(/\/+$/, "");
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
function markdownRoutePath(
|
|
38
|
+
function markdownRoutePath(
|
|
39
|
+
pathname: string,
|
|
40
|
+
reason: "accept" | "extension",
|
|
41
|
+
): string {
|
|
40
42
|
const normalized = normalizePagePath(pathname);
|
|
41
|
-
const pagePath =
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
const pagePath =
|
|
44
|
+
reason === "extension" && normalized.endsWith(".md")
|
|
45
|
+
? normalized.slice(0, -".md".length)
|
|
46
|
+
: normalized;
|
|
44
47
|
return pagePath === "/"
|
|
45
48
|
? INTERNAL_MARKDOWN_PREFIX
|
|
46
49
|
: `${INTERNAL_MARKDOWN_PREFIX}${pagePath}`;
|
|
@@ -51,13 +54,21 @@ function markdownAlternatePath(pathname: string): string {
|
|
|
51
54
|
if (normalized === "/") {
|
|
52
55
|
return agentRouteConfig.discoveryLinks.sitemap ?? "/sitemap.md";
|
|
53
56
|
}
|
|
54
|
-
return
|
|
57
|
+
return `${normalized}.md`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function rootMarkdownSitemapPath(requestUrl: URL): string {
|
|
61
|
+
return new URL(
|
|
62
|
+
agentRouteConfig.discoveryLinks.sitemap ?? "/sitemap.md",
|
|
63
|
+
requestUrl,
|
|
64
|
+
).pathname;
|
|
55
65
|
}
|
|
56
66
|
|
|
57
67
|
function explicitAcceptQuality(accept: string, mimeType: string): number {
|
|
58
|
-
if (!accept) return
|
|
68
|
+
if (!accept.trim()) return 1;
|
|
59
69
|
|
|
60
70
|
const [targetType, targetSubtype] = mimeType.toLowerCase().split("/");
|
|
71
|
+
let bestSpecificity = -1;
|
|
61
72
|
let bestQuality = 0;
|
|
62
73
|
|
|
63
74
|
for (const entry of accept.split(",")) {
|
|
@@ -69,17 +80,31 @@ function explicitAcceptQuality(accept: string, mimeType: string): number {
|
|
|
69
80
|
if (!rawType) continue;
|
|
70
81
|
|
|
71
82
|
const [type, subtype] = rawType.split("/");
|
|
72
|
-
|
|
83
|
+
const specificity =
|
|
84
|
+
type === targetType && subtype === targetSubtype
|
|
85
|
+
? 2
|
|
86
|
+
: type === targetType && subtype === "*"
|
|
87
|
+
? 1
|
|
88
|
+
: type === "*" && subtype === "*"
|
|
89
|
+
? 0
|
|
90
|
+
: -1;
|
|
91
|
+
if (specificity < 0) continue;
|
|
73
92
|
|
|
74
93
|
let quality = 1;
|
|
75
94
|
for (const param of rawParams) {
|
|
76
95
|
const [key, value] = param.split("=").map((part) => part.trim());
|
|
77
96
|
if (key !== "q") continue;
|
|
78
|
-
const parsed = Number
|
|
79
|
-
quality =
|
|
97
|
+
const parsed = Number(value);
|
|
98
|
+
quality =
|
|
99
|
+
Number.isFinite(parsed) && parsed >= 0 && parsed <= 1 ? parsed : 0;
|
|
80
100
|
}
|
|
81
101
|
|
|
82
|
-
if (
|
|
102
|
+
if (specificity > bestSpecificity) {
|
|
103
|
+
bestSpecificity = specificity;
|
|
104
|
+
bestQuality = quality;
|
|
105
|
+
} else if (specificity === bestSpecificity) {
|
|
106
|
+
bestQuality = Math.max(bestQuality, quality);
|
|
107
|
+
}
|
|
83
108
|
}
|
|
84
109
|
|
|
85
110
|
return bestQuality;
|
|
@@ -87,48 +112,99 @@ function explicitAcceptQuality(accept: string, mimeType: string): number {
|
|
|
87
112
|
|
|
88
113
|
function negotiatedTextType(
|
|
89
114
|
request: NextRequest,
|
|
90
|
-
): "text/markdown; charset=utf-8" | "text/
|
|
91
|
-
if (!TEXT_METHODS.has(request.method)) return undefined;
|
|
92
|
-
|
|
115
|
+
): "text/markdown; charset=utf-8" | "text/html; charset=utf-8" | undefined {
|
|
93
116
|
const accept = request.headers.get("accept") ?? "";
|
|
94
117
|
const markdownQuality = agentRouteConfig.markdownAccept
|
|
95
118
|
? explicitAcceptQuality(accept, "text/markdown")
|
|
96
119
|
: 0;
|
|
97
|
-
const
|
|
98
|
-
|
|
120
|
+
const htmlQuality = explicitAcceptQuality(accept, "text/html");
|
|
121
|
+
|
|
122
|
+
if (markdownQuality === 0 && htmlQuality === 0) return undefined;
|
|
123
|
+
if (markdownQuality > htmlQuality) return "text/markdown; charset=utf-8";
|
|
124
|
+
if (markdownQuality < htmlQuality) return "text/html; charset=utf-8";
|
|
125
|
+
if (looksLikeAgent(request)) return "text/markdown; charset=utf-8";
|
|
126
|
+
return htmlQuality > 0 && markdownQuality > 0
|
|
127
|
+
? "text/html; charset=utf-8"
|
|
128
|
+
: undefined;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function negotiatedPlainNotFound(request: NextRequest): boolean {
|
|
132
|
+
if (!TEXT_METHODS.has(request.method)) return false;
|
|
133
|
+
|
|
134
|
+
const accept = request.headers.get("accept") ?? "";
|
|
135
|
+
const plainQuality = explicitAcceptQuality(accept, "text/plain");
|
|
136
|
+
const markdownQuality = agentRouteConfig.markdownAccept
|
|
137
|
+
? explicitAcceptQuality(accept, "text/markdown")
|
|
99
138
|
: 0;
|
|
100
139
|
const htmlQuality = explicitAcceptQuality(accept, "text/html");
|
|
101
140
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
141
|
+
return plainQuality > Math.max(markdownQuality, htmlQuality);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function removeDisabledDiscoveryHeaders(response: Response): Response {
|
|
145
|
+
if (!agentRouteConfig.enabled || !agentRouteConfig.discoveryHeaders) {
|
|
146
|
+
for (const name of ["link", "x-publishos-llms", "x-publishos-sitemap"])
|
|
147
|
+
response.headers.delete(name);
|
|
107
148
|
}
|
|
108
|
-
return
|
|
149
|
+
return response;
|
|
109
150
|
}
|
|
110
151
|
|
|
111
152
|
function looksLikeAgent(request: NextRequest): boolean {
|
|
112
153
|
if (!TEXT_METHODS.has(request.method)) return false;
|
|
113
154
|
if (!agentRouteConfig.agentDetection) return false;
|
|
114
|
-
|
|
115
|
-
|
|
155
|
+
return isMarkdownClient(request.headers.get("user-agent") ?? "");
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function mergeVary(response: Response, values: string[]): void {
|
|
159
|
+
const existing = (response.headers.get("vary") ?? "")
|
|
160
|
+
.split(",")
|
|
161
|
+
.map((value) => value.trim())
|
|
162
|
+
.filter(Boolean);
|
|
163
|
+
if (existing.some((value) => value === "*")) return;
|
|
164
|
+
const merged = [...existing];
|
|
165
|
+
for (const value of values) {
|
|
166
|
+
if (!merged.some((item) => item.toLowerCase() === value.toLowerCase()))
|
|
167
|
+
merged.push(value);
|
|
116
168
|
}
|
|
117
|
-
|
|
169
|
+
if (merged.length) response.headers.set("vary", merged.join(", "));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function negotiationVary(): string[] {
|
|
173
|
+
if (!agentRouteConfig.enabled || !agentRouteConfig.markdownAccept) return [];
|
|
174
|
+
return ["Accept", ...(agentRouteConfig.agentDetection ? ["User-Agent"] : [])];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function isNextNavigationRequest(request: NextRequest): boolean {
|
|
178
|
+
return [
|
|
179
|
+
"rsc",
|
|
180
|
+
"next-router-prefetch",
|
|
181
|
+
"next-router-state-tree",
|
|
182
|
+
"next-router-segment-prefetch",
|
|
183
|
+
].some((name) => request.headers.has(name));
|
|
118
184
|
}
|
|
119
185
|
|
|
120
186
|
function markdownRequestReason(
|
|
121
187
|
request: NextRequest,
|
|
122
|
-
): "accept" | "
|
|
188
|
+
): "accept" | "extension" | undefined {
|
|
123
189
|
if (!agentRouteConfig.enabled) return undefined;
|
|
190
|
+
if (!TEXT_METHODS.has(request.method) || isNextNavigationRequest(request))
|
|
191
|
+
return undefined;
|
|
124
192
|
if (
|
|
125
193
|
agentRouteConfig.markdownRoutes &&
|
|
126
194
|
request.nextUrl.pathname.endsWith(".md")
|
|
127
195
|
) {
|
|
128
|
-
|
|
196
|
+
let decoded: string;
|
|
197
|
+
try {
|
|
198
|
+
decoded = normalizePagePath(
|
|
199
|
+
decodeURIComponent(request.nextUrl.pathname),
|
|
200
|
+
).normalize("NFC");
|
|
201
|
+
} catch {
|
|
202
|
+
decoded = request.nextUrl.pathname;
|
|
203
|
+
}
|
|
204
|
+
if (!PUBLIC_PATHS.has(decoded)) return "extension";
|
|
129
205
|
}
|
|
130
|
-
|
|
131
|
-
if (
|
|
206
|
+
const selectedType = negotiatedTextType(request);
|
|
207
|
+
if (selectedType === "text/markdown; charset=utf-8") return "accept";
|
|
132
208
|
return undefined;
|
|
133
209
|
}
|
|
134
210
|
|
|
@@ -171,14 +247,14 @@ function rewriteToMarkdown({
|
|
|
171
247
|
requestHeaders,
|
|
172
248
|
}: {
|
|
173
249
|
request: NextRequest;
|
|
174
|
-
reason: "accept" | "
|
|
250
|
+
reason: "accept" | "extension";
|
|
175
251
|
requestHeaders: Headers;
|
|
176
252
|
}): NextResponse {
|
|
177
253
|
const url = new URL(request.url);
|
|
178
254
|
url.pathname =
|
|
179
255
|
normalizePagePath(url.pathname) === "/"
|
|
180
|
-
?
|
|
181
|
-
: markdownRoutePath(url.pathname);
|
|
256
|
+
? rootMarkdownSitemapPath(url)
|
|
257
|
+
: markdownRoutePath(url.pathname, reason);
|
|
182
258
|
const revision = request.nextUrl.searchParams.get("publishos_revision");
|
|
183
259
|
url.search = "";
|
|
184
260
|
url.hash = "";
|
|
@@ -195,20 +271,25 @@ function rewriteToMarkdown({
|
|
|
195
271
|
userAgent: request.headers.get("user-agent") ?? undefined,
|
|
196
272
|
});
|
|
197
273
|
|
|
198
|
-
|
|
274
|
+
const response = NextResponse.rewrite(url, {
|
|
199
275
|
request: {
|
|
200
276
|
headers: requestHeaders,
|
|
201
277
|
},
|
|
202
278
|
});
|
|
279
|
+
if (reason !== "extension") mergeVary(response, negotiationVary());
|
|
280
|
+
return response;
|
|
203
281
|
}
|
|
204
282
|
|
|
205
283
|
function withDiscoveryHeaders(
|
|
206
284
|
response: NextResponse,
|
|
207
285
|
pathname: string,
|
|
208
286
|
): NextResponse {
|
|
287
|
+
mergeVary(response, negotiationVary());
|
|
209
288
|
const markdownUrl = markdownAlternatePath(pathname);
|
|
210
289
|
const links = [
|
|
211
|
-
|
|
290
|
+
agentRouteConfig.markdownRoutes
|
|
291
|
+
? `<${markdownUrl}>; rel="alternate"; type="text/markdown"`
|
|
292
|
+
: undefined,
|
|
212
293
|
agentRouteConfig.discoveryLinks.llms
|
|
213
294
|
? `<${agentRouteConfig.discoveryLinks.llms}>; rel="llms-txt"; type="text/plain"`
|
|
214
295
|
: undefined,
|
|
@@ -216,8 +297,9 @@ function withDiscoveryHeaders(
|
|
|
216
297
|
? `<${agentRouteConfig.discoveryLinks.sitemap}>; rel="alternate"; type="text/markdown"; title="Markdown sitemap"`
|
|
217
298
|
: undefined,
|
|
218
299
|
].filter((link): link is string => Boolean(link));
|
|
219
|
-
response.headers.set("link", links.join(", "));
|
|
220
|
-
|
|
300
|
+
if (links.length) response.headers.set("link", links.join(", "));
|
|
301
|
+
if (agentRouteConfig.markdownRoutes)
|
|
302
|
+
response.headers.set("x-publishos-markdown", markdownUrl);
|
|
221
303
|
if (agentRouteConfig.discoveryLinks.llms) {
|
|
222
304
|
response.headers.set(
|
|
223
305
|
"x-publishos-llms",
|
|
@@ -283,10 +365,13 @@ export function proxy(request: NextRequest) {
|
|
|
283
365
|
if (markdownReason) {
|
|
284
366
|
let htmlPath: string | undefined;
|
|
285
367
|
try {
|
|
286
|
-
const decoded = normalizePagePath(decodeURIComponent(pathname))
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
368
|
+
const decoded = normalizePagePath(decodeURIComponent(pathname)).normalize(
|
|
369
|
+
"NFC",
|
|
370
|
+
);
|
|
371
|
+
htmlPath =
|
|
372
|
+
markdownReason === "extension" && decoded.endsWith(".md")
|
|
373
|
+
? decoded.slice(0, -3) || "/"
|
|
374
|
+
: decoded;
|
|
290
375
|
} catch {
|
|
291
376
|
htmlPath = undefined;
|
|
292
377
|
}
|
|
@@ -296,7 +381,7 @@ export function proxy(request: NextRequest) {
|
|
|
296
381
|
});
|
|
297
382
|
const hasArtifact =
|
|
298
383
|
htmlPath === "/"
|
|
299
|
-
? OUTPUT_PATHS.has(
|
|
384
|
+
? OUTPUT_PATHS.has(rootMarkdownSitemapPath(new URL(request.url)))
|
|
300
385
|
: htmlPath !== undefined && MARKDOWN_PATHS.has(htmlPath);
|
|
301
386
|
if (!scope || !hasArtifact) {
|
|
302
387
|
const response = createNotFoundTextResponse({
|
|
@@ -307,16 +392,7 @@ export function proxy(request: NextRequest) {
|
|
|
307
392
|
markdownReason === "accept" ? negotiatedTextType(request) : undefined,
|
|
308
393
|
vary: markdownReason !== "extension",
|
|
309
394
|
});
|
|
310
|
-
|
|
311
|
-
for (const name of [
|
|
312
|
-
"link",
|
|
313
|
-
"x-publishos-llms",
|
|
314
|
-
"x-publishos-sitemap",
|
|
315
|
-
]) {
|
|
316
|
-
response.headers.delete(name);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
return response;
|
|
395
|
+
return removeDisabledDiscoveryHeaders(response);
|
|
320
396
|
}
|
|
321
397
|
return rewriteToMarkdown({
|
|
322
398
|
request,
|
|
@@ -327,7 +403,7 @@ export function proxy(request: NextRequest) {
|
|
|
327
403
|
|
|
328
404
|
let pagePath: string;
|
|
329
405
|
try {
|
|
330
|
-
pagePath = normalizePagePath(decodeURIComponent(pathname));
|
|
406
|
+
pagePath = normalizePagePath(decodeURIComponent(pathname)).normalize("NFC");
|
|
331
407
|
} catch {
|
|
332
408
|
pagePath = pathname;
|
|
333
409
|
}
|
|
@@ -337,6 +413,17 @@ export function proxy(request: NextRequest) {
|
|
|
337
413
|
scopes: agentRouteConfig.notFoundScopes,
|
|
338
414
|
pathname,
|
|
339
415
|
});
|
|
416
|
+
if (negotiatedPlainNotFound(request)) {
|
|
417
|
+
return removeDisabledDiscoveryHeaders(
|
|
418
|
+
createNotFoundTextResponse({
|
|
419
|
+
scope,
|
|
420
|
+
pathname,
|
|
421
|
+
method: request.method,
|
|
422
|
+
contentType: "text/plain; charset=utf-8",
|
|
423
|
+
vary: true,
|
|
424
|
+
}),
|
|
425
|
+
);
|
|
426
|
+
}
|
|
340
427
|
requestHeaders.set(NOT_FOUND_SCOPE_HEADER, scope?.id ?? "none");
|
|
341
428
|
const url = new URL(request.url);
|
|
342
429
|
url.pathname = "/_not-found";
|
|
@@ -365,6 +452,17 @@ export function proxy(request: NextRequest) {
|
|
|
365
452
|
return response;
|
|
366
453
|
}
|
|
367
454
|
|
|
455
|
+
if (
|
|
456
|
+
agentRouteConfig.enabled &&
|
|
457
|
+
TEXT_METHODS.has(request.method) &&
|
|
458
|
+
!isNextNavigationRequest(request) &&
|
|
459
|
+
!negotiatedTextType(request)
|
|
460
|
+
) {
|
|
461
|
+
const response = new NextResponse(null, { status: 406 });
|
|
462
|
+
mergeVary(response, negotiationVary());
|
|
463
|
+
return response;
|
|
464
|
+
}
|
|
465
|
+
|
|
368
466
|
if (!agentRouteConfig.enabled || !agentRouteConfig.discoveryHeaders) {
|
|
369
467
|
debugAgentRoute("pass", {
|
|
370
468
|
method: request.method,
|
|
@@ -373,7 +471,11 @@ export function proxy(request: NextRequest) {
|
|
|
373
471
|
? "discovery-disabled"
|
|
374
472
|
: "agent-routes-disabled",
|
|
375
473
|
});
|
|
376
|
-
|
|
474
|
+
const response = NextResponse.next({
|
|
475
|
+
request: { headers: requestHeaders },
|
|
476
|
+
});
|
|
477
|
+
mergeVary(response, negotiationVary());
|
|
478
|
+
return response;
|
|
377
479
|
}
|
|
378
480
|
|
|
379
481
|
debugAgentRoute("html", {
|
|
@@ -7,18 +7,18 @@ import {
|
|
|
7
7
|
} from "./chunk-IL4RJOKI.js";
|
|
8
8
|
import {
|
|
9
9
|
prepareIdeSupport
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-3T4HVDSC.js";
|
|
11
11
|
import "./chunk-6D2E6UMD.js";
|
|
12
12
|
import {
|
|
13
13
|
composeFrameworkSource
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-NHSLTARU.js";
|
|
15
15
|
import {
|
|
16
16
|
validateLocalSource
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-SBMDONTV.js";
|
|
18
18
|
import "./chunk-NNBJZPFM.js";
|
|
19
|
-
import "./chunk-
|
|
19
|
+
import "./chunk-DZ3VWEV5.js";
|
|
20
20
|
import "./chunk-7NY22B5U.js";
|
|
21
|
-
import "./chunk-
|
|
21
|
+
import "./chunk-DX7PXFCM.js";
|
|
22
22
|
import "./chunk-EFO6AWXN.js";
|
|
23
23
|
import "./chunk-5KAD7W53.js";
|
|
24
24
|
import "./chunk-WL75GQ5M.js";
|
|
@@ -5,14 +5,14 @@ import {
|
|
|
5
5
|
} from "./chunk-6D2E6UMD.js";
|
|
6
6
|
import {
|
|
7
7
|
createIdeSourceArtifacts
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-NHSLTARU.js";
|
|
9
9
|
import {
|
|
10
10
|
assertFrameworkSelection,
|
|
11
11
|
readCheckoutTypeScriptConfig
|
|
12
12
|
} from "./chunk-NNBJZPFM.js";
|
|
13
13
|
import {
|
|
14
14
|
supportedNextjsSourceImports
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-DX7PXFCM.js";
|
|
16
16
|
import {
|
|
17
17
|
runtimePackageVersion
|
|
18
18
|
} from "./chunk-AI2UULNX.js";
|