doccupine 0.0.140 → 0.0.141
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/README.md +14 -7
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +191 -0
- package/dist/index.d.ts +3 -7
- package/dist/index.js +5 -1894
- package/dist/lib/config-manager.d.ts +1 -0
- package/dist/lib/config-manager.js +63 -3
- package/dist/lib/generated-artifacts.d.ts +26 -0
- package/dist/lib/generated-artifacts.js +147 -0
- package/dist/lib/layout.js +30 -30
- package/dist/lib/metadata.js +58 -30
- package/dist/lib/openapi-types.d.ts +2 -2
- package/dist/lib/openapi.d.ts +6 -3
- package/dist/lib/openapi.js +330 -50
- package/dist/lib/output-safety.d.ts +15 -0
- package/dist/lib/output-safety.js +428 -0
- package/dist/lib/structures.js +11 -0
- package/dist/lib/utils.d.ts +10 -5
- package/dist/lib/utils.js +108 -5
- package/dist/mdx-to-nextjs-generator.d.ts +166 -0
- package/dist/mdx-to-nextjs-generator.js +2229 -0
- package/dist/templates/app/api/gate/route.d.ts +1 -1
- package/dist/templates/app/api/gate/route.js +18 -6
- package/dist/templates/app/api/mcp/route.d.ts +1 -1
- package/dist/templates/app/api/mcp/route.js +181 -111
- package/dist/templates/app/api/playground/route.d.ts +1 -1
- package/dist/templates/app/api/playground/route.js +45 -13
- package/dist/templates/app/api/rag/route.d.ts +1 -1
- package/dist/templates/app/api/rag/route.js +72 -20
- package/dist/templates/app/api/search/route.d.ts +1 -1
- package/dist/templates/app/api/search/route.js +5 -0
- package/dist/templates/app/robots.d.ts +1 -1
- package/dist/templates/app/robots.js +1 -26
- package/dist/templates/app/theme.d.ts +1 -1
- package/dist/templates/app/theme.js +31 -19
- package/dist/templates/components/Chat.d.ts +1 -1
- package/dist/templates/components/Chat.js +342 -34
- package/dist/templates/components/SearchDocs.d.ts +1 -1
- package/dist/templates/components/SearchDocs.js +63 -11
- package/dist/templates/components/SearchModalContent.d.ts +1 -1
- package/dist/templates/components/SearchModalContent.js +191 -49
- package/dist/templates/components/SideBar.d.ts +1 -1
- package/dist/templates/components/SideBar.js +8 -2
- package/dist/templates/components/layout/Accordion.d.ts +1 -1
- package/dist/templates/components/layout/Accordion.js +26 -3
- package/dist/templates/components/layout/Badge.d.ts +1 -1
- package/dist/templates/components/layout/Badge.js +1 -1
- package/dist/templates/components/layout/Button.d.ts +1 -1
- package/dist/templates/components/layout/Button.js +4 -4
- package/dist/templates/components/layout/Callout.d.ts +1 -1
- package/dist/templates/components/layout/Callout.js +6 -6
- package/dist/templates/components/layout/Card.d.ts +1 -1
- package/dist/templates/components/layout/Card.js +9 -4
- package/dist/templates/components/layout/CherryThemeProvider.d.ts +1 -1
- package/dist/templates/components/layout/CherryThemeProvider.js +63 -12
- package/dist/templates/components/layout/Code.d.ts +1 -1
- package/dist/templates/components/layout/Code.js +5 -5
- package/dist/templates/components/layout/CopyButton.d.ts +1 -1
- package/dist/templates/components/layout/CopyButton.js +1 -1
- package/dist/templates/components/layout/DemoTheme.d.ts +1 -1
- package/dist/templates/components/layout/DemoTheme.js +8 -28
- package/dist/templates/components/layout/DocsComponents.d.ts +1 -1
- package/dist/templates/components/layout/DocsComponents.js +57 -6
- package/dist/templates/components/layout/GlobalStyles.d.ts +1 -1
- package/dist/templates/components/layout/GlobalStyles.js +15 -9
- package/dist/templates/components/layout/Prompt.d.ts +1 -1
- package/dist/templates/components/layout/Prompt.js +4 -7
- package/dist/templates/components/layout/Steps.d.ts +1 -1
- package/dist/templates/components/layout/Steps.js +7 -1
- package/dist/templates/components/layout/Tabs.d.ts +1 -1
- package/dist/templates/components/layout/Tabs.js +108 -19
- package/dist/templates/env.example.d.ts +1 -1
- package/dist/templates/env.example.js +11 -0
- package/dist/templates/eslint.config.d.ts +1 -1
- package/dist/templates/eslint.config.js +20 -0
- package/dist/templates/gitignore.d.ts +1 -1
- package/dist/templates/gitignore.js +4 -3
- package/dist/templates/lib/access.d.ts +1 -0
- package/dist/templates/lib/access.js +41 -0
- package/dist/templates/mdx/ai-assistant.mdx.d.ts +1 -1
- package/dist/templates/mdx/ai-assistant.mdx.js +17 -1
- package/dist/templates/mdx/api-playground.mdx.d.ts +1 -1
- package/dist/templates/mdx/api-playground.mdx.js +5 -3
- package/dist/templates/mdx/authentication.mdx.d.ts +1 -1
- package/dist/templates/mdx/authentication.mdx.js +5 -3
- package/dist/templates/mdx/commands.mdx.d.ts +1 -1
- package/dist/templates/mdx/commands.mdx.js +20 -6
- package/dist/templates/mdx/components.mdx.d.ts +1 -1
- package/dist/templates/mdx/components.mdx.js +3 -0
- package/dist/templates/mdx/deployment-and-hosting.mdx.d.ts +1 -1
- package/dist/templates/mdx/deployment-and-hosting.mdx.js +2 -2
- package/dist/templates/mdx/globals.mdx.d.ts +1 -1
- package/dist/templates/mdx/globals.mdx.js +14 -11
- package/dist/templates/mdx/model-context-protocol.mdx.d.ts +1 -1
- package/dist/templates/mdx/model-context-protocol.mdx.js +22 -35
- package/dist/templates/mdx/platform/ai-assistant.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/ai-assistant.mdx.js +23 -0
- package/dist/templates/mdx/platform/api-playground.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/api-playground.mdx.js +7 -0
- package/dist/templates/mdx/platform/authentication.mdx.d.ts +1 -0
- package/dist/templates/mdx/platform/authentication.mdx.js +63 -0
- package/dist/templates/mdx/platform/import-from-github.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/import-from-github.mdx.js +2 -2
- package/dist/templates/mdx/platform/index.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/index.mdx.js +1 -0
- package/dist/templates/mdx/platform/mcp.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/mcp.mdx.js +2 -1
- package/dist/templates/mdx/platform/navigation-settings.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/navigation-settings.mdx.js +12 -1
- package/dist/templates/mdx/platform/publishing.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/publishing.mdx.js +43 -10
- package/dist/templates/mdx/platform/self-updating-docs.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/self-updating-docs.mdx.js +48 -9
- package/dist/templates/mdx/sections.mdx.d.ts +1 -1
- package/dist/templates/mdx/sections.mdx.js +4 -0
- package/dist/templates/mdx/space.mdx.d.ts +1 -0
- package/dist/templates/mdx/space.mdx.js +125 -0
- package/dist/templates/mdx/tabs.mdx.d.ts +1 -1
- package/dist/templates/mdx/tabs.mdx.js +4 -0
- package/dist/templates/next.config.js +20 -8
- package/dist/templates/package.js +3 -3
- package/dist/templates/prettierignore.d.ts +1 -1
- package/dist/templates/prettierignore.js +1 -0
- package/dist/templates/proxy.js +47 -19
- package/dist/templates/scripts/build-docs-index.d.ts +1 -1
- package/dist/templates/scripts/build-docs-index.js +1 -0
- package/dist/templates/services/mcp/docsContentStub.d.ts +1 -0
- package/dist/templates/services/mcp/docsContentStub.js +1 -0
- package/dist/templates/services/mcp/server.d.ts +1 -1
- package/dist/templates/services/mcp/server.js +140 -83
- package/dist/templates/services/mcp/tools.d.ts +1 -1
- package/dist/templates/services/mcp/tools.js +65 -137
- package/dist/templates/utils/playgroundAllowlist.d.ts +1 -1
- package/dist/templates/utils/playgroundAllowlist.js +13 -4
- package/dist/templates/utils/rateLimit.d.ts +1 -1
- package/dist/templates/utils/rateLimit.js +40 -3
- package/dist/templates/utils/requestBody.d.ts +1 -0
- package/dist/templates/utils/requestBody.js +56 -0
- package/dist/templates/utils/ssrfGuard.d.ts +1 -1
- package/dist/templates/utils/ssrfGuard.js +138 -33
- package/package.json +14 -9
- package/dist/lib/mdxToMarkdown.d.ts +0 -1
- package/dist/lib/mdxToMarkdown.js +0 -134
- package/dist/templates/mdx/image-and-embeds.mdx.d.ts +0 -1
- package/dist/templates/mdx/image-and-embeds.mdx.js +0 -118
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { DoccupineConfig, NormalizedOpenApiSpec } from "./types.js";
|
|
2
|
+
export declare function validateConfig(value: unknown, rootDir?: string): DoccupineConfig;
|
|
2
3
|
/**
|
|
3
4
|
* Collapses every accepted `openapi` config shape (a single path, a list of
|
|
4
5
|
* paths, or named-spec objects) into a uniform `NormalizedOpenApiSpec[]`. Names
|
|
@@ -2,6 +2,63 @@ import fs from "fs-extra";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import chalk from "chalk";
|
|
4
4
|
import prompts from "prompts";
|
|
5
|
+
import { isPathInside } from "./output-safety.js";
|
|
6
|
+
function pathsOverlap(a, b) {
|
|
7
|
+
return isPathInside(a, b) || isPathInside(b, a);
|
|
8
|
+
}
|
|
9
|
+
function isValidOpenApiConfig(value) {
|
|
10
|
+
if (value === undefined || typeof value === "string")
|
|
11
|
+
return true;
|
|
12
|
+
if (!Array.isArray(value))
|
|
13
|
+
return false;
|
|
14
|
+
return value.every((entry) => typeof entry === "string" ||
|
|
15
|
+
(entry !== null &&
|
|
16
|
+
typeof entry === "object" &&
|
|
17
|
+
typeof entry.file === "string" &&
|
|
18
|
+
(entry.name === undefined ||
|
|
19
|
+
typeof entry.name === "string")));
|
|
20
|
+
}
|
|
21
|
+
export function validateConfig(value, rootDir = process.cwd()) {
|
|
22
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
23
|
+
throw new Error("doccupine.json must contain a JSON object.");
|
|
24
|
+
}
|
|
25
|
+
const config = value;
|
|
26
|
+
if (typeof config.watchDir !== "string" || !config.watchDir.trim()) {
|
|
27
|
+
throw new Error("doccupine.json watchDir must be a non-empty string.");
|
|
28
|
+
}
|
|
29
|
+
if (typeof config.outputDir !== "string" || !config.outputDir.trim()) {
|
|
30
|
+
throw new Error("doccupine.json outputDir must be a non-empty string.");
|
|
31
|
+
}
|
|
32
|
+
const watchDir = path.resolve(rootDir, config.watchDir);
|
|
33
|
+
const outputDir = path.resolve(rootDir, config.outputDir);
|
|
34
|
+
if (outputDir === path.resolve(rootDir)) {
|
|
35
|
+
throw new Error("outputDir cannot be the project root.");
|
|
36
|
+
}
|
|
37
|
+
if (pathsOverlap(watchDir, outputDir)) {
|
|
38
|
+
throw new Error("watchDir and outputDir must not overlap.");
|
|
39
|
+
}
|
|
40
|
+
const port = config.port ?? "3000";
|
|
41
|
+
if (typeof port !== "string" ||
|
|
42
|
+
!/^\d+$/.test(port) ||
|
|
43
|
+
Number(port) < 1 ||
|
|
44
|
+
Number(port) > 65535) {
|
|
45
|
+
throw new Error("doccupine.json port must be an integer from 1 to 65535.");
|
|
46
|
+
}
|
|
47
|
+
if (config.packageManager !== undefined &&
|
|
48
|
+
config.packageManager !== "npm" &&
|
|
49
|
+
config.packageManager !== "pnpm") {
|
|
50
|
+
throw new Error('packageManager must be either "npm" or "pnpm".');
|
|
51
|
+
}
|
|
52
|
+
if (!isValidOpenApiConfig(config.openapi)) {
|
|
53
|
+
throw new Error("openapi must be a path or an array of paths/{ name, file } objects.");
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
...config,
|
|
57
|
+
watchDir: config.watchDir,
|
|
58
|
+
outputDir: config.outputDir,
|
|
59
|
+
port,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
5
62
|
/** Strips a `.json`/`.yaml`/`.yml` extension to derive a spec's default name. */
|
|
6
63
|
function basenameWithoutExt(file) {
|
|
7
64
|
return path.basename(file).replace(/\.(json|ya?ml)$/i, "");
|
|
@@ -127,13 +184,15 @@ export class ConfigManager {
|
|
|
127
184
|
try {
|
|
128
185
|
if (await fs.pathExists(this.configPath)) {
|
|
129
186
|
const configContent = await fs.readFile(this.configPath, "utf8");
|
|
130
|
-
const config = JSON.parse(configContent);
|
|
187
|
+
const config = validateConfig(JSON.parse(configContent));
|
|
131
188
|
console.log(chalk.blue("📄 Using existing configuration from doccupine.json"));
|
|
132
189
|
return config;
|
|
133
190
|
}
|
|
134
191
|
}
|
|
135
192
|
catch (error) {
|
|
136
|
-
|
|
193
|
+
if (await fs.pathExists(this.configPath)) {
|
|
194
|
+
throw new Error(`Unable to use ${this.configPath}: ${error instanceof Error ? error.message : String(error)}. Run "doccupine config --reset" to repair the configuration.`);
|
|
195
|
+
}
|
|
137
196
|
}
|
|
138
197
|
return null;
|
|
139
198
|
}
|
|
@@ -200,7 +259,7 @@ export class ConfigManager {
|
|
|
200
259
|
}
|
|
201
260
|
if (!config || options.reset) {
|
|
202
261
|
console.log(chalk.blue("🔧 Setting up Doccupine configuration..."));
|
|
203
|
-
config = await this.promptForConfig(config || {});
|
|
262
|
+
config = validateConfig(await this.promptForConfig(config || {}));
|
|
204
263
|
dirty = true;
|
|
205
264
|
}
|
|
206
265
|
else {
|
|
@@ -217,6 +276,7 @@ export class ConfigManager {
|
|
|
217
276
|
config.port = options.port;
|
|
218
277
|
dirty = true;
|
|
219
278
|
}
|
|
279
|
+
config = validateConfig(config);
|
|
220
280
|
if (dirty) {
|
|
221
281
|
await this.saveConfig(config);
|
|
222
282
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type RouteOwnerKind = "mdx" | "openapi";
|
|
2
|
+
interface RouteArtifact {
|
|
3
|
+
kind: RouteOwnerKind;
|
|
4
|
+
source: string;
|
|
5
|
+
slug: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class GeneratedArtifacts {
|
|
8
|
+
private readonly outputDir;
|
|
9
|
+
private routes;
|
|
10
|
+
private llmsFiles;
|
|
11
|
+
constructor(outputDir: string);
|
|
12
|
+
private manifestPath;
|
|
13
|
+
private routeKey;
|
|
14
|
+
load(): Promise<void>;
|
|
15
|
+
routeFor(kind: RouteOwnerKind, source: string): string | undefined;
|
|
16
|
+
routesFor(kind: RouteOwnerKind): RouteArtifact[];
|
|
17
|
+
replaceRoutes(kind: RouteOwnerKind, routes: Iterable<{
|
|
18
|
+
source: string;
|
|
19
|
+
slug: string;
|
|
20
|
+
}>): void;
|
|
21
|
+
removeRoute(kind: RouteOwnerKind, source: string): void;
|
|
22
|
+
llmsPageFiles(): Set<string>;
|
|
23
|
+
replaceLlmsPageFiles(files: Iterable<string>): void;
|
|
24
|
+
save(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { readOutputFileIfPresent, resolveOutputPath } from "./output-safety.js";
|
|
4
|
+
import { writeFileAtomic } from "./utils.js";
|
|
5
|
+
const MANIFEST_FILE = ".doccupine-artifacts.json";
|
|
6
|
+
const LEGACY_LLMS_MANIFEST = ".doccupine-llms-manifest.json";
|
|
7
|
+
const LEGACY_API_MANIFEST = ".doccupine-api-manifest.json";
|
|
8
|
+
function normalizeRelativePath(value, allowEmpty = false) {
|
|
9
|
+
const normalized = value.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
10
|
+
if ((allowEmpty && normalized === "") || normalized === "") {
|
|
11
|
+
return allowEmpty ? "" : null;
|
|
12
|
+
}
|
|
13
|
+
if (path.posix.isAbsolute(normalized))
|
|
14
|
+
return null;
|
|
15
|
+
const parts = normalized.split("/");
|
|
16
|
+
if (parts.some((part) => part === "" || part === "." || part === "..")) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return normalized;
|
|
20
|
+
}
|
|
21
|
+
function normalizeRoute(value) {
|
|
22
|
+
if (!value || typeof value !== "object")
|
|
23
|
+
return null;
|
|
24
|
+
const route = value;
|
|
25
|
+
if (route.kind !== "mdx" && route.kind !== "openapi")
|
|
26
|
+
return null;
|
|
27
|
+
if (typeof route.source !== "string" || typeof route.slug !== "string") {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const source = normalizeRelativePath(route.source);
|
|
31
|
+
const slug = normalizeRelativePath(route.slug, true);
|
|
32
|
+
return source === null || slug === null
|
|
33
|
+
? null
|
|
34
|
+
: { kind: route.kind, source, slug };
|
|
35
|
+
}
|
|
36
|
+
function normalizeLlmsPageFile(value) {
|
|
37
|
+
if (typeof value !== "string")
|
|
38
|
+
return null;
|
|
39
|
+
const normalized = normalizeRelativePath(value);
|
|
40
|
+
return normalized?.endsWith(".md") ? normalized : null;
|
|
41
|
+
}
|
|
42
|
+
export class GeneratedArtifacts {
|
|
43
|
+
outputDir;
|
|
44
|
+
routes = new Map();
|
|
45
|
+
llmsFiles = new Set();
|
|
46
|
+
constructor(outputDir) {
|
|
47
|
+
this.outputDir = outputDir;
|
|
48
|
+
}
|
|
49
|
+
manifestPath(fileName) {
|
|
50
|
+
return resolveOutputPath(this.outputDir, fileName);
|
|
51
|
+
}
|
|
52
|
+
routeKey(kind, source) {
|
|
53
|
+
return `${kind}:${source.replace(/\\/g, "/")}`;
|
|
54
|
+
}
|
|
55
|
+
async load() {
|
|
56
|
+
this.routes.clear();
|
|
57
|
+
this.llmsFiles.clear();
|
|
58
|
+
const manifestContent = await readOutputFileIfPresent(this.outputDir, MANIFEST_FILE);
|
|
59
|
+
if (manifestContent !== null) {
|
|
60
|
+
try {
|
|
61
|
+
const parsed = JSON.parse(manifestContent);
|
|
62
|
+
if (Array.isArray(parsed.routes)) {
|
|
63
|
+
for (const value of parsed.routes) {
|
|
64
|
+
const route = normalizeRoute(value);
|
|
65
|
+
if (route)
|
|
66
|
+
this.routes.set(this.routeKey(route.kind, route.source), route);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (Array.isArray(parsed.llmsPageFiles)) {
|
|
70
|
+
for (const value of parsed.llmsPageFiles) {
|
|
71
|
+
const file = normalizeLlmsPageFile(value);
|
|
72
|
+
if (file)
|
|
73
|
+
this.llmsFiles.add(file);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// A corrupt manifest owns nothing. Generated output is rebuilt safely.
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Import only valid paths from the old llms manifest. This preserves stale
|
|
82
|
+
// mirror cleanup across upgrades without trusting its historical contents.
|
|
83
|
+
const legacyContent = await readOutputFileIfPresent(this.outputDir, LEGACY_LLMS_MANIFEST);
|
|
84
|
+
if (legacyContent !== null) {
|
|
85
|
+
try {
|
|
86
|
+
const parsed = JSON.parse(legacyContent);
|
|
87
|
+
if (Array.isArray(parsed.pageFiles)) {
|
|
88
|
+
for (const value of parsed.pageFiles) {
|
|
89
|
+
const file = normalizeLlmsPageFile(value);
|
|
90
|
+
if (file)
|
|
91
|
+
this.llmsFiles.add(file);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// Ignore corrupt legacy state.
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
await Promise.all([
|
|
100
|
+
fs.remove(this.manifestPath(LEGACY_LLMS_MANIFEST)),
|
|
101
|
+
fs.remove(this.manifestPath(LEGACY_API_MANIFEST)),
|
|
102
|
+
]);
|
|
103
|
+
}
|
|
104
|
+
routeFor(kind, source) {
|
|
105
|
+
return this.routes.get(this.routeKey(kind, source))?.slug;
|
|
106
|
+
}
|
|
107
|
+
routesFor(kind) {
|
|
108
|
+
return [...this.routes.values()].filter((route) => route.kind === kind);
|
|
109
|
+
}
|
|
110
|
+
replaceRoutes(kind, routes) {
|
|
111
|
+
for (const [key, route] of this.routes) {
|
|
112
|
+
if (route.kind === kind)
|
|
113
|
+
this.routes.delete(key);
|
|
114
|
+
}
|
|
115
|
+
for (const value of routes) {
|
|
116
|
+
const route = normalizeRoute({ kind, ...value });
|
|
117
|
+
if (!route) {
|
|
118
|
+
throw new Error(`Refusing to record unsafe ${kind} route ownership`);
|
|
119
|
+
}
|
|
120
|
+
this.routes.set(this.routeKey(kind, route.source), route);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
removeRoute(kind, source) {
|
|
124
|
+
this.routes.delete(this.routeKey(kind, source));
|
|
125
|
+
}
|
|
126
|
+
llmsPageFiles() {
|
|
127
|
+
return new Set(this.llmsFiles);
|
|
128
|
+
}
|
|
129
|
+
replaceLlmsPageFiles(files) {
|
|
130
|
+
const next = new Set();
|
|
131
|
+
for (const value of files) {
|
|
132
|
+
const file = normalizeLlmsPageFile(value);
|
|
133
|
+
if (!file)
|
|
134
|
+
throw new Error("Refusing to record an unsafe llms page path");
|
|
135
|
+
next.add(file);
|
|
136
|
+
}
|
|
137
|
+
this.llmsFiles = next;
|
|
138
|
+
}
|
|
139
|
+
async save() {
|
|
140
|
+
const manifest = {
|
|
141
|
+
schemaVersion: 1,
|
|
142
|
+
routes: [...this.routes.values()].sort((a, b) => `${a.kind}:${a.source}`.localeCompare(`${b.kind}:${b.source}`)),
|
|
143
|
+
llmsPageFiles: [...this.llmsFiles].sort(),
|
|
144
|
+
};
|
|
145
|
+
await writeFileAtomic(this.manifestPath(MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\n`);
|
|
146
|
+
}
|
|
147
|
+
}
|
package/dist/lib/layout.js
CHANGED
|
@@ -62,24 +62,25 @@ function fontDeclLine(fontConfig) {
|
|
|
62
62
|
});`
|
|
63
63
|
: 'const font = Inter({ subsets: ["latin"] });';
|
|
64
64
|
}
|
|
65
|
-
// The inline blocking script that resolves dark mode before first paint.
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
//
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
|
|
65
|
+
// The inline blocking script that resolves dark mode before the first paint.
|
|
66
|
+
// It only has to decide the mode and record it on <html>: every painted color
|
|
67
|
+
// in the app resolves through the CSS custom properties that GlobalStyles
|
|
68
|
+
// emits under :root and :root[data-theme="dark"], so that one attribute is
|
|
69
|
+
// enough to make a statically rendered page arrive dark. Nothing is hidden and
|
|
70
|
+
// nothing waits for hydration — the markup streams and paints in the right
|
|
71
|
+
// theme exactly like a light visit does.
|
|
72
|
+
//
|
|
73
|
+
// The mode lives on our own data-theme attribute rather than on the "dark"
|
|
74
|
+
// class, because that class belongs to Cherry's ClientThemeProvider, which
|
|
75
|
+
// syncs it from the theme object: releases before 0.2.12 strip it for a frame
|
|
76
|
+
// on mount, since the server render is always the light theme, and every color
|
|
77
|
+
// on the page would flash light with it. The class is still set here so CSS
|
|
78
|
+
// written against it — Cherry's own, or a user's — keeps working.
|
|
79
|
+
//
|
|
80
|
+
// The mode comes from the "theme" cookie, falling back to the OS preference
|
|
81
|
+
// and seeding the cookie so Cherry's ClientThemeProvider reconciles against
|
|
82
|
+
// the same answer on mount instead of flipping the class back.
|
|
83
|
+
const THEME_INIT_SCRIPT = `(function(){try{var c=document.cookie.split(";").map(function(s){return s.trim();}).find(function(s){return s.indexOf("theme=")===0;});var v=c?c.split("=")[1]:null;var d=v?v==="dark":(window.matchMedia&&window.matchMedia("(prefers-color-scheme:dark)").matches);if(!v){document.cookie="theme="+(d?"dark":"light")+";path=/;max-age=31536000;SameSite=Lax";}var r=document.documentElement;r.dataset.theme=d?"dark":"light";if(d){r.classList.add("dark");}}catch(e){}})();`;
|
|
83
84
|
/**
|
|
84
85
|
* Root layout ("app/layout.tsx"). Minimal shell: html/body, fonts, the theme
|
|
85
86
|
* provider stack, and (optionally) PostHog. It renders `children` directly so
|
|
@@ -133,16 +134,13 @@ export default function RootLayout({
|
|
|
133
134
|
return (
|
|
134
135
|
<html lang="en" suppressHydrationWarning>
|
|
135
136
|
<head>
|
|
136
|
-
{/* Resolves dark mode before first paint
|
|
137
|
-
<html
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
would still show a flash. suppressHydrationWarning on <html>
|
|
144
|
-
tells React the class/colorScheme attributes are intentionally
|
|
145
|
-
different between server (no class) and client (after script). */}
|
|
137
|
+
{/* Resolves dark mode before the first paint by stamping data-theme
|
|
138
|
+
on <html>, which flips the CSS variables in GlobalStyles.
|
|
139
|
+
Inlined as a plain <script> (not next/script) so it ships in the
|
|
140
|
+
SSR HTML and runs synchronously before paint — next/script with
|
|
141
|
+
beforeInteractive is async in App Router and would flash.
|
|
142
|
+
suppressHydrationWarning on <html> tells React the class is
|
|
143
|
+
intentionally different between server (none) and client. */}
|
|
146
144
|
<script
|
|
147
145
|
dangerouslySetInnerHTML={{
|
|
148
146
|
__html: \`${THEME_INIT_SCRIPT}\`,
|
|
@@ -198,8 +196,10 @@ ${hasSections
|
|
|
198
196
|
? ""
|
|
199
197
|
: `import { StaticLinks } from "@/components/layout/StaticLinks";
|
|
200
198
|
`}import { verifyBrandingKey } from "@/utils/branding";
|
|
201
|
-
|
|
202
|
-
|
|
199
|
+
${hasSections
|
|
200
|
+
? ""
|
|
201
|
+
: `import navigation from "@/navigation.json";
|
|
202
|
+
`}
|
|
203
203
|
${hasSections
|
|
204
204
|
? `import { SectionBar } from "@/components/layout/SectionBar";
|
|
205
205
|
import { SectionNavProvider } from "@/components/SectionNavProvider";
|
package/dist/lib/metadata.js
CHANGED
|
@@ -88,22 +88,34 @@ export function generateJsonLdScript(opts) {
|
|
|
88
88
|
}
|
|
89
89
|
function buildFieldExpression(staticValue, configKey, defaultValue) {
|
|
90
90
|
if (staticValue)
|
|
91
|
-
return staticValue;
|
|
92
|
-
return
|
|
91
|
+
return JSON.stringify(String(staticValue));
|
|
92
|
+
return `config.${configKey} || ${JSON.stringify(defaultValue)}`;
|
|
93
93
|
}
|
|
94
94
|
function buildTitleExpression(opts) {
|
|
95
|
-
const title = opts.title || opts.titleFallback;
|
|
95
|
+
const title = String(opts.title || opts.titleFallback);
|
|
96
96
|
if (opts.titleOrder === "page-first") {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return
|
|
97
|
+
if (opts.name) {
|
|
98
|
+
return JSON.stringify(`${title} - ${String(opts.name)}`);
|
|
99
|
+
}
|
|
100
|
+
return `[
|
|
101
|
+
${JSON.stringify(title)},
|
|
102
|
+
config.name ? "- " + config.name : ${JSON.stringify(`- ${DEFAULT_SITE_NAME}`)},
|
|
103
|
+
].join(" ")`;
|
|
101
104
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
if (opts.name) {
|
|
106
|
+
return JSON.stringify(`${String(opts.name)} - ${title}`);
|
|
107
|
+
}
|
|
108
|
+
return `[
|
|
109
|
+
config.name ? config.name + " -" : ${JSON.stringify(`${DEFAULT_SITE_NAME} -`)},
|
|
110
|
+
${JSON.stringify(title)},
|
|
111
|
+
].join(" ")`;
|
|
112
|
+
}
|
|
113
|
+
function formatProperty(indent, name, expression) {
|
|
114
|
+
const prefix = " ".repeat(indent);
|
|
115
|
+
const inline = `${prefix}${name}: ${expression},`;
|
|
116
|
+
return inline.length <= 80
|
|
117
|
+
? inline
|
|
118
|
+
: `${prefix}${name}:\n${prefix} ${expression},`;
|
|
107
119
|
}
|
|
108
120
|
function buildAlternatesBlock(canonicalPath, rssPath) {
|
|
109
121
|
if (canonicalPath === undefined)
|
|
@@ -130,31 +142,47 @@ export function generateMetadataBlock(opts) {
|
|
|
130
142
|
const icon = buildFieldExpression(opts.icon, "icon", DEFAULT_FAVICON);
|
|
131
143
|
const image = buildFieldExpression(opts.image, "image", DEFAULT_OG_IMAGE);
|
|
132
144
|
const canonical = buildAlternatesBlock(opts.canonicalPath, opts.rssPath);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
145
|
+
const inlineTitleDeclaration = `const pageTitle = ${title};`;
|
|
146
|
+
const titleDeclaration = title.includes("\n") || inlineTitleDeclaration.length <= 80
|
|
147
|
+
? inlineTitleDeclaration
|
|
148
|
+
: `const pageTitle =\n ${title};`;
|
|
149
|
+
const descriptionLine = formatProperty(2, "description", desc);
|
|
150
|
+
const iconLine = formatProperty(2, "icons", icon);
|
|
151
|
+
const openGraphDescriptionLine = formatProperty(4, "description", desc);
|
|
152
|
+
const imageLine = formatProperty(4, "images", image);
|
|
153
|
+
return `${titleDeclaration}
|
|
154
|
+
|
|
155
|
+
export const metadata: Metadata = {
|
|
156
|
+
title: pageTitle,
|
|
157
|
+
${descriptionLine}
|
|
158
|
+
${iconLine}${canonical}
|
|
137
159
|
openGraph: {
|
|
138
|
-
title:
|
|
139
|
-
|
|
140
|
-
|
|
160
|
+
title: pageTitle,
|
|
161
|
+
${openGraphDescriptionLine}
|
|
162
|
+
${imageLine}
|
|
141
163
|
},
|
|
142
164
|
};`;
|
|
143
165
|
}
|
|
144
166
|
export function generateRuntimeOnlyMetadataBlock() {
|
|
145
|
-
const title =
|
|
146
|
-
const desc =
|
|
147
|
-
const icon =
|
|
148
|
-
const image =
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
167
|
+
const title = `config.name || ${JSON.stringify(DEFAULT_SITE_NAME)}`;
|
|
168
|
+
const desc = `config.description || ${JSON.stringify(DEFAULT_META_DESCRIPTION)}`;
|
|
169
|
+
const icon = `config.icon || ${JSON.stringify(DEFAULT_FAVICON)}`;
|
|
170
|
+
const image = `config.image || ${JSON.stringify(DEFAULT_OG_IMAGE)}`;
|
|
171
|
+
const descriptionLine = formatProperty(2, "description", desc);
|
|
172
|
+
const iconLine = formatProperty(2, "icons", icon);
|
|
173
|
+
const openGraphDescriptionLine = formatProperty(4, "description", desc);
|
|
174
|
+
const imageLine = formatProperty(4, "images", image);
|
|
175
|
+
return `const pageTitle = ${title};
|
|
176
|
+
|
|
177
|
+
export const metadata: Metadata = {
|
|
178
|
+
title: pageTitle,
|
|
179
|
+
${descriptionLine}
|
|
180
|
+
${iconLine}
|
|
153
181
|
alternates: { canonical: "/" },
|
|
154
182
|
openGraph: {
|
|
155
|
-
title:
|
|
156
|
-
|
|
157
|
-
|
|
183
|
+
title: pageTitle,
|
|
184
|
+
${openGraphDescriptionLine}
|
|
185
|
+
${imageLine}
|
|
158
186
|
},
|
|
159
187
|
};`;
|
|
160
188
|
}
|
|
@@ -107,8 +107,8 @@ export interface OperationDescriptor {
|
|
|
107
107
|
* A single entry in the request-execution allowlist emitted at build time from
|
|
108
108
|
* the union of every spec's `servers[]`. The proxy route (server) and the
|
|
109
109
|
* playground component (client) both read this to decide whether a target URL
|
|
110
|
-
* may be called. `allowPrivate` is set ONLY
|
|
111
|
-
*
|
|
110
|
+
* may be called. `allowPrivate` is set ONLY for an explicit loopback server
|
|
111
|
+
* (the local-development case); other private and metadata targets stay blocked.
|
|
112
112
|
*/
|
|
113
113
|
export interface AllowlistEntry {
|
|
114
114
|
scheme: "http" | "https";
|
package/dist/lib/openapi.d.ts
CHANGED
|
@@ -15,14 +15,16 @@ export declare function slugifySegment(input: string): string;
|
|
|
15
15
|
* properties append their parent path: `param-body-user-address-city`.
|
|
16
16
|
*/
|
|
17
17
|
export declare function buildParamAnchor(name: string, location: string, parentPath?: string[]): string;
|
|
18
|
+
export declare function isLocalOpenApiPath(reference: string): boolean;
|
|
18
19
|
/**
|
|
19
20
|
* Parses one or more OpenAPI specs and exposes everything the generator needs:
|
|
20
21
|
* the operation descriptors, lookup indices for the MDX frontmatter path,
|
|
21
22
|
* synthetic sidebar/sitemap `PageMeta` objects, per-endpoint markdown bodies
|
|
22
23
|
* (for llms output), and the request-execution allowlist.
|
|
23
24
|
*
|
|
24
|
-
* `load()`
|
|
25
|
-
*
|
|
25
|
+
* `load()` is transactional: every configured spec must parse and process
|
|
26
|
+
* successfully before the current registry is replaced. A failed reload throws
|
|
27
|
+
* and leaves the last-known-good state available to callers.
|
|
26
28
|
*/
|
|
27
29
|
export declare class OpenApiRegistry {
|
|
28
30
|
private operations;
|
|
@@ -47,6 +49,7 @@ export declare class OpenApiRegistry {
|
|
|
47
49
|
/**
|
|
48
50
|
* Builds the MDX body for a generated endpoint page: the operation description,
|
|
49
51
|
* followed by `<Field>` documentation for the parameters and request body, and
|
|
50
|
-
* a schema/example code block per response.
|
|
52
|
+
* a schema/example code block per response. Spec-derived strings are emitted
|
|
53
|
+
* only through serialized JSX expressions. Rendered above the playground.
|
|
51
54
|
*/
|
|
52
55
|
export declare function buildEndpointDoc(op: OperationDescriptor): string;
|