@vite-hub/docs 0.3.1 → 0.4.1

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 (42) hide show
  1. package/README.md +15 -13
  2. package/dist/{agent-copy-BJp_Yf5d.js → agent-copy-xPaWye_g.js} +1 -1
  3. package/dist/assistant-pages-BN7hNsSZ.js +37 -0
  4. package/dist/{assistant-shared-Dll_F_yy.d.ts → assistant-shared-CWIKRtBv.d.ts} +3 -2
  5. package/dist/{assistant-shared-CdtXowot.js → assistant-shared-WzButktj.js} +23 -7
  6. package/dist/assistant-worker.d.ts +1 -1
  7. package/dist/assistant-worker.js +1 -1
  8. package/dist/assistant.d.ts +1 -1
  9. package/dist/assistant.js +1 -1
  10. package/dist/{content-9CINWiRf.js → content-CPZGnn3S.js} +3 -33
  11. package/dist/{draft-DUBx--r9.js → draft-BjWmaiLn.js} +1 -1
  12. package/dist/error-diagnostics-B_ZOy7kF.js +93 -0
  13. package/dist/files-UY4h1_36.js +38 -0
  14. package/dist/index.d.ts +2 -2
  15. package/dist/index.js +1 -1
  16. package/dist/link-checker-redirects.js +1 -1
  17. package/dist/{manifest-Dzp5-_AJ.d.ts → manifest-CMoxcwPm.d.ts} +8 -2
  18. package/dist/{manifest-D66AEF8F.js → manifest-ZdxLrcvt.js} +47 -33
  19. package/dist/{markdown-Cn9-4oVG.js → markdown-DUWnEMPp.js} +1 -1
  20. package/dist/navigation.d.ts +1 -2
  21. package/dist/navigation.js +1 -2
  22. package/dist/{nuxt-B5LrERKc.d.ts → nuxt-CAGpKl_-.d.ts} +5 -4
  23. package/dist/nuxt.d.ts +1 -1
  24. package/dist/nuxt.js +465 -82
  25. package/dist/{page-BbmSfZO8.js → page-GPt09oex.js} +2 -1
  26. package/dist/primitive-rail.d.ts +1 -1
  27. package/dist/primitive-rail.js +7 -2
  28. package/dist/{raw-C03EUJKw.js → raw-BChwipz_.js} +6 -0
  29. package/dist/{redirects-BrbWFSzW.js → redirects-CmR1yu5A.js} +18 -6
  30. package/dist/runtime/app/components/content/McpClient.vue +170 -0
  31. package/dist/runtime/app/components/content/McpInstall.vue +238 -0
  32. package/dist/runtime/server/llms.js +1 -1
  33. package/dist/runtime/server/markdown.js +1 -1
  34. package/dist/runtime/server/mcp.js +1 -1
  35. package/dist/runtime/server/page.js +3 -3
  36. package/dist/runtime/server/raw.js +1 -1
  37. package/dist/runtime/server/search.js +2 -2
  38. package/dist/runtime/server/sitemap.js +1 -1
  39. package/dist/server.d.ts +1 -1
  40. package/dist/server.js +4 -4
  41. package/package.json +11 -11
  42. package/dist/error-diagnostics-BoOsP6Y4.js +0 -53
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # @vite-hub/docs
2
2
 
3
- [![npm version](https://comark-ui.onmax.me/badge.svg?source=npm-version&package=%40vite-hub%2Fdocs&icon=npm)](https://www.npmjs.com/package/@vite-hub/docs)
4
- [![license](https://comark-ui.onmax.me/badge.svg?label=license&value=Apache-2.0)](https://github.com/vite-hub/vitehub/blob/main/LICENSE)
5
- [![docs](https://comark-ui.onmax.me/badge.svg?label=docs&value=vitehub.dev)](https://vitehub.dev/docs/docs-site)
3
+ [![npm version](https://img.shields.io/npm/v/@vite-hub/docs)](https://www.npmjs.com/package/@vite-hub/docs)
4
+ [![license](https://img.shields.io/static/v1?label=license&message=Apache-2.0&color=blue)](https://github.com/vite-hub/vitehub/blob/main/LICENSE)
5
+ [![docs](https://img.shields.io/static/v1?label=docs&message=vitehub.dev&color=blue)](https://vitehub.dev/docs/docs-site)
6
6
 
7
7
  `@vite-hub/docs` turns a folder of Markdown files into a documentation site. It is a Nuxt module. It gives you the docs shell, four page layouts, search, a Markdown copy of each page for agents, llms.txt, an MCP server, and an optional docs assistant. [vitehub.dev](https://vitehub.dev) runs on it.
8
8
 
@@ -71,7 +71,7 @@ content/
71
71
 
72
72
  A page's URL is its path in the folder. With a `content/docs/` folder, the docs are at `/docs`. Without one, the docs are the whole site: `content/index.md` is `/`, and each folder in `content/` is a section. `content/docs/index.md` is the page at `/docs`. Without it, `/docs` is not found, and the Docs links open the first section. Each folder under `content/docs/` is a section: one entry in the rail and its own sidebar. A site with three sections or fewer, or with no section icons, has no rail: the sidebar lists every section with its pages. Pages outside `content/docs/`, such as `about.md`, render as plain articles under the site header. `dir` changes the content folder, and `base` sets the URL prefix of the sections when the default does not fit.
73
73
 
74
- The module reads the folder at build time. In development it watches the folder: a body edit shows on the next page load, and a new page, title, or order restarts the app.
74
+ The module reads the folder at build time. In development it watches the folder. A body edit, a new or removed page, a title, or an order shows on the next page load without a restart, and the server code reloads once. The app restarts when adding or removing `content/docs/` changes the inferred base, or when a new page changes a route that the module adds at startup: the first page outside `/docs`, a page outside `/docs`, or any new page of an app with an `app.baseURL`, whose Markdown routes list each page. It also restarts for a new page when Nitro does not run in Vite (`experimental.nitroViteEnvironment: false`).
75
75
 
76
76
  ### Multiple sources and Markdown components
77
77
 
@@ -79,7 +79,7 @@ Read pages from more than one place with `sources`. It replaces `dir`. Each entr
79
79
 
80
80
  The module reads the `.md` and `.navigation.yml` files of every source through ViteHub Content when it builds. In development the server reads folders through Nitro server assets, and the module watches them. The build copies the pages of any other Source into `.nuxt/docs/sources/docs-<index>/` and serves that copy, so a `github()` Source shows its branch as it was at build time. A production build packs the Markdown and rewritten agent copies into one gzip module to stay below Cloudflare’s module limit. A `glob()` Source lists dot files only when its `include` names them, such as `**/.navigation.yml`, and reads only below the app root.
81
81
 
82
- `sources` configures the site pages, search, and Markdown resources. It does not configure the app-owned `docsAssistant` Agent, whose default Workspace reads `content/**/*.md`. To let the assistant read mapped pages, configure its Workspace sources too, as described in [Docs assistant](#docs-assistant).
82
+ `sources` configures the site pages, search, Markdown resources, and the pages that the docs assistant reads.
83
83
 
84
84
  ```ts
85
85
  import { github, glob } from "vite-hub/source"
@@ -204,8 +204,8 @@ Most changes are options in `nuxt.config.ts`:
204
204
  | `sitemap` | `[]` | More paths for `/sitemap.xml`. Every docs page is listed already. |
205
205
  | `mcp` | On | `{ name, guide }`, or `false` to turn off the MCP server. |
206
206
  | `llms` | None | `{ details, sections }`. Text under the description of `/llms.txt`, and sections of links before the page sections. |
207
- | `linkChecker` | On | `false` turns off `nuxt-link-checker`, which fails the build on detected link errors in prerendered pages. Fragments on other pages are checked against the final built HTML. Remote URLs are not fetched. A link to an exact `redirect` route rule passes, and the build checks that the rule leads to a docs page instead. Set the app's own `linkChecker` options to change it. |
208
- | `seoAudit` | `"warn"` | The search check of prerendered pages. `"warn"` logs the problems, `"error"` or `true` stops the build with `DOCS_SEO_FAILED`, and `false` turns it off. It reports a sitemap URL that is not a prerendered page, a title or description that is missing, shared, or outside 10 to 60 and 70 to 160 characters, a page that has no single `h1`, skips a heading level, has fewer than 150 words, or has no link to it, an indexed page without `og:title`, `og:type`, `og:image`, and `og:url`, a page over 2 MB of HTML, which Googlebot cuts, and links to a redirect page or to `/mcp`. A page without a share image (`seo.image: false`, or `ogImage: false`) needs no `og:image`, and a site without `site.url` needs no `og:url`. |
207
+ | `linkChecker` | On | `false` turns off the link checks. The build first runs `vitehub content check` on the Markdown of every page, also the pages it does not prerender, and stops with `DOCS_LINKS_BROKEN` on a link to a missing page, named by file and line. Then `nuxt-link-checker` fails the build on detected link errors in prerendered pages, such as links in the navigation and app pages. Fragments on other pages are checked against the final built HTML. Remote URLs are not fetched. A link to an exact `redirect` route rule passes, and the build checks that the rule leads to a docs page instead. Set the app's own `linkChecker` options to change it. |
208
+ | `seoAudit` | `"warn"` | The search check of prerendered pages. `"warn"` reports one hint for each kind of problem, such as `DOCS_SEO_TITLE_INVALID`, in the build output and in `.vitehub/hints.json`. `"error"` or `true` stops the build with `DOCS_SEO_FAILED`, and `false` turns it off. The audit checks the rendered title and description, including duplicates across indexed pages. When the rendered title or description has the same problem in `vitehub content check`, the audit includes the frontmatter file and line. It also checks sitemap URLs, `h1` and heading order, word count, inbound links, Open Graph tags, HTML over 2 MB, and links to redirects or `/mcp`. A page without a share image (`seo.image: false`, or `ogImage: false`) needs no `og:image`, and a site without `site.url` needs no `og:url`. |
209
209
  | `ogImage` | On | Share images. `{ component }` renders the app's own template from `components/OgImage/`, or `false` turns them off. See [Search and share](#search-and-share). |
210
210
  | `assistant` | `false` | `true`, or `{ agent }`. See [Docs assistant](#docs-assistant). |
211
211
  | `comments` | On with `vite-hub/nuxt` | `false` turns Comments off, or `{ database, dialect, overlay }`. See [Comments](#comments). |
@@ -229,7 +229,7 @@ The shell is a set of Nuxt components. Create a component with the same name in
229
229
  | `DocsCatalogFooter` | The catalog at the end of an Overview. |
230
230
  | `DocsCodePanel`, `DocsCodePre` | The tutorial code panel and code blocks. |
231
231
 
232
- Markdown blocks are components in `components/content/`. The package has `::tutorial-step`, `::product-features` with `:::product-feature-item`, `::example` and `::examples`, `::correct` and `::incorrect`, `::code-tree`, `::page-list`, and `::agent-only`. Add your own in `app/components/content/`, for example `ProductHero.vue` for `::product-hero`. An app `app.vue`, `error.vue`, `layouts/docs.vue`, or `layouts/default.vue` also replaces the package one. In an app with its own `app.vue`, the plain articles outside the sections use the `docs-article` layout, so the app's `default` layout stays on its own pages. A catch-all page replaces the docs page only at the docs prefix: `pages/[...slug].vue` for docs at `/`, and `pages/docs/[...slug].vue` for docs at `/docs`. One at another prefix, such as `pages/blog/[...slug].vue`, does not.
232
+ Markdown blocks are components in `components/content/`. The package has `::tutorial-step`, `::product-features` with `:::product-feature-item`, `::example` and `::examples`, `::correct` and `::incorrect`, `::code-tree`, `::page-list`, `::mcp-install` with `:::mcp-client`, and `::agent-only`. Add your own in `app/components/content/`, for example `ProductHero.vue` for `::product-hero`. An app `app.vue`, `error.vue`, `layouts/docs.vue`, or `layouts/default.vue` also replaces the package one. In an app with its own `app.vue`, the plain articles outside the sections use the `docs-article` layout, so the app's `default` layout stays on its own pages. A catch-all page replaces the docs page only at the docs prefix: `pages/[...slug].vue` for docs at `/`, and `pages/docs/[...slug].vue` for docs at `/docs`. One at another prefix, such as `pages/blog/[...slug].vue`, does not.
233
233
 
234
234
  A replacement docs layout or sidebar keeps the site header. Render `<DocsSidebars panel head />` to supply the sidebar controls and hide the desktop header. A replacement `DocsSidebars` can opt in with `data-docs-sidebar-head` on its root after it supplies the brand, badge tooltip, search, and `<DocsAsideFooter />`. The header owns one `DocsHeaderActions` instance and moves it into the mounted footer on wide screens.
235
235
 
@@ -265,6 +265,8 @@ With `name`, the preview is a Vue file in `app/examples/`, and Code shows its so
265
265
 
266
266
  `::page-list` lists the pages of the page's section under their sidebar groups, with their icons and descriptions, for an Overview. On a panel Overview it lists the pages of the panel. `section` lists another section, `group="Runtime errors"` lists one group, and `exclude="Start"` leaves groups out. `compact` shows one line for each page, without icons: use it for long lists, such as one page per error code, because a Markdown table of a thousand rows is more HTML than crawlers read. Put a plain Markdown list or table inside it: the site doesn't show it, and agents read it in the Markdown copy.
267
267
 
268
+ `::mcp-install` connects a reader's agent to the site's MCP server at `/mcp`. Its Client tab shows each `:::mcp-client{label icon method}` as a logo, and the steps of the client that the reader picks. The pick is kept for the next visit. Write the steps as a numbered list. `install="cursor"` or `install="vscode"` adds a one-click install button, and `note` adds a footer line. The Prompt, MCP URL, and Command tabs come from the `mcp` option, so they always name the real server. Agents get every client's steps under its name in the Markdown copy.
269
+
268
270
  ### Comark plugins
269
271
 
270
272
  The server parses each page with Comark, and the browser renders the nodes with [comark-ui](https://comark-ui.onmax.me)'s blocks: GitHub callouts (`> [!NOTE]`, and `::note`, `::tip`, `::warning`, `::caution`, `::important`), tabs and code groups, steps, code with a copy bar, zoomable images, charts, diagrams, file trees, cards, and the rest. comark-ui's typeset is off, since the design styles the prose. Chips are off too: they turn every web link into a chip and fetch its favicon. Annotated screenshots, diffs, quizzes, and comments have no Vue components, so the server draws them as HTML in a `comark-html` node, with the block's tag in `block`.
@@ -376,7 +378,7 @@ export default defineNuxtConfig({
376
378
 
377
379
  ```ts
378
380
  // server/agents/docs.ts
379
- // server/agents/docs/agent.ts. `workspace: {}` says that this Agent owns the pages Workspace of the preset, so a build bundles the pages for hosts without a file system.
381
+ // server/agents/docs/agent.ts. `workspace: {}` says that this Agent owns the pages Workspace of the preset.
380
382
  import { docsAssistant } from "@vite-hub/docs/assistant"
381
383
  import { defineAgent } from "vite-hub/agent"
382
384
 
@@ -405,9 +407,9 @@ The Agent and the Connection are app files on purpose. ViteHub discovers Agents
405
407
 
406
408
  Set `VITEHUB_CONNECTIONS_KEY` to 32 random bytes in `.env`, start the app, and sign in once with `pnpm vitehub connections connect chatgpt --url http://localhost:3000`. Every page then shows an **Ask** button. `⌘I` (`Ctrl+I` on Windows and Linux) opens and closes the panel, and `Esc` closes it. On wide screens the panel is a column beside the page that you resize from its left edge. On narrow screens it is a sheet. `useDocsAssistant().toggle()` opens the panel from your own control.
407
409
 
408
- The preset reads `content/**/*.md` from a read-only Workspace, answers in the `web` Chat Channel at `/api/_vitehub/agents/docs/chat`, and gets the path of the open page. It allows 30 questions per hour for the whole site, 2 answers at a time, and 8 waiting. Change any part with `defineAgent({ extends: docsAssistant, ... })`, for example `driver: { instructions }`, `driver: { gateway: openai(), model }` for an API key, or `docsRateLimit({ limit, identity })`. Set `docs: { assistant: { agent: "support" } }` to use an Agent with another name.
410
+ The preset reads the site's pages from a read-only Workspace, answers in the `web` Chat Channel at `/_vitehub/agents/docs/chat`, and gets the path of the open page. It allows 30 questions per hour for the whole site, 2 answers at a time, and 8 waiting. Change any part with `defineAgent({ extends: docsAssistant, ... })`, for example `driver: { instructions }`, `driver: { gateway: openai(), model }` for an API key, or `docsRateLimit({ limit, identity })`. Set `docs: { assistant: { agent: "support" } }` to use an Agent with another name.
409
411
 
410
- The preset does not inherit `docs.dir` or `docs.sources`. With another `dir`, import `glob` from `@vite-hub/workspace` and override `workspace: { sources: { pages: glob({ cwd: dir, include: ["**/*.md"], keyCache: false }) } }`. With `sources`, replace the default `pages` Source and add a glob for each folder. Mirror each source's `exclude` as `ignore`, and set each glob's Workspace `mount` to `pages` plus its public mount, such as `pages/zoom`. This keeps file paths aligned with the assistant's page-link instructions. All glob folders must be inside the Workspace's `sourceRootDir`; use a common project root when pages live outside the Nuxt app. Frontmatter adapters apply to site metadata only; the assistant reads the source Markdown.
412
+ The Workspace has every page of the site in its `pages` folder, at its URL path: `/docs/guide/setup` is `pages/docs/guide/setup.md`. It reads the same pages as the site, from `docs.dir` or `docs.sources`, for each question. In development a new page shows at once, and a Worker reads the pages that the docs build packed. The assistant reads the source Markdown, so frontmatter adapters change only the site metadata. To read other files, override the Source: `workspace: { sources: { pages: glob({ cwd, include: ["**/*.md"], keyCache: false }) } }` with `glob` from `@vite-hub/workspace`.
411
413
 
412
414
  Limits:
413
415
 
@@ -429,7 +431,7 @@ import cms from "vite-hub/cms"
429
431
  import { docsCollection } from "@vite-hub/docs"
430
432
 
431
433
  export default defineContent({
432
- extends: [cms, { repo: "owner/name", publish: "pr", access: "roles" }],
434
+ extends: [cms, { repo: "owner/name", publish: "pr", roles: true }],
433
435
  collections: { docs: docsCollection() },
434
436
  })
435
437
  ```
@@ -441,7 +443,7 @@ export default defineContent({
441
443
  | Code | When | Fix |
442
444
  | --- | --- | --- |
443
445
  | `DOCS_CONTENT_INVALID` | A page frontmatter or a `.navigation.yml` file does not match the schema. The message names the file and the field. | Fix the field. The schema is `docsPageSchema` and `docsSectionSchema` from `@vite-hub/docs`. |
444
- | `DOCS_REDIRECTS_BROKEN` | A production build with the link checker on finds a redirect route rule into the docs that no page answers, or one that hides a docs page. | Point the rule to a page, or remove it. |
446
+ | `DOCS_REDIRECTS_BROKEN` | A production build with the link checker on finds a redirect route rule into the docs that no page or server route answers, or one that hides a docs page. | Point the rule to a page, or remove it. |
445
447
  | `DOCS_ASSISTANT_AGENTS_MISSING` | `assistant` is on, and `vite-hub/nuxt` with `agent: true` is missing. | Add `vite-hub/nuxt` with `agent: true` and `connections: true`, or turn `assistant` off. |
446
448
 
447
449
  ## Inspect
@@ -1,5 +1,5 @@
1
1
  import { docsManifestPages, docsRawSectionLinks } from "./navigation.js";
2
- import { t as toRawMarkdown } from "./raw-C03EUJKw.js";
2
+ import { t as toRawMarkdown } from "./raw-BChwipz_.js";
3
3
  //#region src/agent-copy.ts
4
4
  /**
5
5
  * The copy of a page that agents read at `/raw/<page>.md`: the source as plain Markdown with absolute links, then the
@@ -0,0 +1,37 @@
1
+ import { docsManifestPages } from "./navigation.js";
2
+ import { t as docsErrorDiagnostics } from "./error-diagnostics-B_ZOy7kF.js";
3
+ import { n as readDocsFile, t as hasDocsFile } from "./files-UY4h1_36.js";
4
+ import manifest from "#docs/manifest";
5
+ //#region src/runtime/assistant-pages.ts
6
+ /**
7
+ * The Workspace path of a page: its URL path as a Markdown file, and `index.md` for a folder page. The assistant's rules
8
+ * turn a path back into the URL, so `docs/guide/setup.md` is `/docs/guide/setup`, whatever the source and mount of the page.
9
+ */
10
+ function docsAssistantPagePath(page) {
11
+ if (page.path === "/") return "index.md";
12
+ const path = page.path.replace(/^\/+/, "");
13
+ return /(?:^|\/)index\.md$/.test(page.file) ? `${path}/index.md` : `${path}.md`;
14
+ }
15
+ let pageIndex;
16
+ function docsAssistantPages() {
17
+ const snapshot = manifest;
18
+ if (!pageIndex || pageIndex.manifest !== snapshot) pageIndex = {
19
+ manifest: snapshot,
20
+ pages: new Map(docsManifestPages(snapshot).map((page) => [docsAssistantPagePath(page), page]))
21
+ };
22
+ return pageIndex.pages;
23
+ }
24
+ function listDocsAssistantPagePaths() {
25
+ const paths = [];
26
+ for (const [path, page] of docsAssistantPages()) if (hasDocsFile(page.source ?? "docs", page.file)) paths.push(path);
27
+ return paths;
28
+ }
29
+ /** The source Markdown of a page at its Workspace path, from the same files that the docs Content reads. */
30
+ async function readDocsAssistantPage(path) {
31
+ const page = docsAssistantPages().get(path);
32
+ const text = page ? await readDocsFile(page.source ?? "docs", page.file) : null;
33
+ if (text === null) throw docsErrorDiagnostics.DOCS_ASSISTANT_PAGE_MISSING({ path });
34
+ return text;
35
+ }
36
+ //#endregion
37
+ export { listDocsAssistantPagePaths, readDocsAssistantPage };
@@ -1,6 +1,7 @@
1
1
  import { RateLimitIdentity } from "@vite-hub/agent/capabilities";
2
2
  import { AgentCapabilityDefinition, WorkspaceAgentDefinition } from "@vite-hub/agent";
3
- import { RateLimitWindow } from "@vite-hub/rate-limit";
3
+ import { RateLimitPolicy } from "@vite-hub/rate-limit";
4
+ import "@vite-hub/workspace";
4
5
  //#region src/assistant-shared.d.ts
5
6
  /** Invocation context key that holds the path of the page the reader has open. */
6
7
  declare const docsPageContextKey = "docsPage";
@@ -10,7 +11,7 @@ interface DocsRateLimitOptions {
10
11
  /** Questions per window. Defaults to 30. */
11
12
  limit?: number;
12
13
  /** Defaults to `1h`. */
13
- window?: RateLimitWindow;
14
+ window?: RateLimitPolicy["window"];
14
15
  /**
15
16
  * Who shares one budget. Defaults to the whole site, because anonymous readers have no stable identity. Use `"ip"`
16
17
  * with `trustedIpHeaders` behind a proxy that sets them, or a function of the Invocation context.
@@ -4,7 +4,7 @@ import { defineAgent } from "@vite-hub/agent";
4
4
  import { webChat } from "@vite-hub/agent/channels";
5
5
  import { createRateLimiter } from "@vite-hub/rate-limit";
6
6
  import { memoryRateLimitDriver } from "@vite-hub/rate-limit/drivers/memory";
7
- import { glob } from "@vite-hub/workspace";
7
+ import { custom } from "@vite-hub/workspace";
8
8
  //#region src/assistant-shared.ts
9
9
  /** Invocation context key that holds the path of the page the reader has open. */
10
10
  const docsPageContextKey = "docsPage";
@@ -54,10 +54,30 @@ function docsRateLimit(options = {}) {
54
54
  }
55
55
  /** The model of the Worker build. A model ID from the ChatGPT plan catalog: `vitehub connections models chatgpt`. */
56
56
  const docsAssistantModel = "gpt-6.1-sol";
57
+ /**
58
+ * The pages Source: every page of the docs site, read from the same manifest and files as the site's Content. It covers
59
+ * `docs.dir` and `docs.sources`, and lays each page out at its URL path, as the docs rules expect. The Workspace reads it
60
+ * for each Invocation (`lazy`, no cache), so a page that development adds shows at once, and a Worker reads the pages
61
+ * that the docs build packed, with no second copy. It loads the docs server modules on the first read, so the Agent
62
+ * needs the `@vite-hub/docs` Nuxt module.
63
+ */
64
+ function docsPagesSource() {
65
+ return custom({
66
+ name: "docs-pages",
67
+ materialize: "lazy",
68
+ cache: false,
69
+ getKeys: async () => (await import("./assistant-pages-BN7hNsSZ.js")).listDocsAssistantPagePaths(),
70
+ getItem: async (key) => ({
71
+ key,
72
+ content: await (await import("./assistant-pages-BN7hNsSZ.js")).readDocsAssistantPage(key),
73
+ mediaType: "text/markdown"
74
+ })
75
+ });
76
+ }
57
77
  /** The docs rules, the developer's instructions in their place, and the reader's page. */
58
78
  const docsInstructions = { template: [docsRules, currentPageInstructions] };
59
79
  /**
60
- * The parts of the docs assistant that do not depend on the host: a read-only Workspace with the pages in `content/`,
80
+ * The parts of the docs assistant that do not depend on the host: a read-only Workspace with the pages of the docs site,
61
81
  * the `web` Chat Channel with the reader's current page, a site-wide rate limit, and Driver capacity.
62
82
  */
63
83
  function defineDocsAssistant(driver, capabilities = []) {
@@ -67,11 +87,7 @@ function defineDocsAssistant(driver, capabilities = []) {
67
87
  workspace: {
68
88
  mode: "read",
69
89
  sourceRootDir: process.cwd(),
70
- sources: { pages: glob({
71
- cwd: "content",
72
- include: ["**/*.md"],
73
- keyCache: false
74
- }) }
90
+ sources: { pages: docsPagesSource() }
75
91
  },
76
92
  channels: { web: webChat({ route: { admission: { context: ({ body }) => {
77
93
  const appBase = docsPageFromBody({ page: Reflect.get(body, "appBase") });
@@ -1,4 +1,4 @@
1
- import { i as docsRateLimit, n as docsPageContextKey, r as docsPageFromBody, t as DocsRateLimitOptions } from "./assistant-shared-Dll_F_yy.js";
1
+ import { i as docsRateLimit, n as docsPageContextKey, r as docsPageFromBody, t as DocsRateLimitOptions } from "./assistant-shared-CWIKRtBv.js";
2
2
  import { WorkspaceAgentDefinition } from "@vite-hub/agent";
3
3
  //#region src/assistant-worker.d.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { a as docsPageFromBody, i as docsPageContextKey, n as docsAssistantModel, o as docsRateLimit, r as docsInstructions, t as defineDocsAssistant } from "./assistant-shared-CdtXowot.js";
1
+ import { a as docsPageFromBody, i as docsPageContextKey, n as docsAssistantModel, o as docsRateLimit, r as docsInstructions, t as defineDocsAssistant } from "./assistant-shared-WzButktj.js";
2
2
  import { workspaceShell } from "@vite-hub/agent/capabilities";
3
3
  import { chatgpt } from "@vite-hub/gateways";
4
4
  //#region src/assistant-worker.ts
@@ -1,4 +1,4 @@
1
- import { i as docsRateLimit, n as docsPageContextKey, r as docsPageFromBody, t as DocsRateLimitOptions } from "./assistant-shared-Dll_F_yy.js";
1
+ import { i as docsRateLimit, n as docsPageContextKey, r as docsPageFromBody, t as DocsRateLimitOptions } from "./assistant-shared-CWIKRtBv.js";
2
2
  import { WorkspaceAgentDefinition } from "@vite-hub/agent";
3
3
  //#region src/assistant.d.ts
4
4
  /**
package/dist/assistant.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as docsPageFromBody, i as docsPageContextKey, o as docsRateLimit, r as docsInstructions, t as defineDocsAssistant } from "./assistant-shared-CdtXowot.js";
1
+ import { a as docsPageFromBody, i as docsPageContextKey, o as docsRateLimit, r as docsInstructions, t as defineDocsAssistant } from "./assistant-shared-WzButktj.js";
2
2
  import { chatgpt } from "@vite-hub/gateways";
3
3
  import { codexDriver } from "@vite-hub/agent";
4
4
  //#region src/assistant.ts
@@ -1,6 +1,7 @@
1
1
  import { docsManifestPages, docsRawPath, findDocsPage } from "./navigation.js";
2
- import { n as docsAgentPages, r as docsContentSource, t as docsAgentCopy } from "./agent-copy-BJp_Yf5d.js";
3
- import { i as docsMarkdown, n as docsDocumentOf, r as docsImageSizes, t as createDocsParser } from "./markdown-Cn9-4oVG.js";
2
+ import { n as docsAgentPages, r as docsContentSource, t as docsAgentCopy } from "./agent-copy-xPaWye_g.js";
3
+ import { i as docsMarkdown, n as docsDocumentOf, r as docsImageSizes, t as createDocsParser } from "./markdown-DUWnEMPp.js";
4
+ import { n as readDocsFile } from "./files-UY4h1_36.js";
4
5
  import "node:module";
5
6
  import { defu } from "defu";
6
7
  import { contentSource, defineContent } from "@vite-hub/content";
@@ -10,7 +11,6 @@ import { useRuntimeConfig } from "nitro/runtime-config";
10
11
  import examples from "#docs/example-sources";
11
12
  import imageSizes from "#docs/image-sizes";
12
13
  import parser, { githubRepo } from "#docs/parser";
13
- import files from "#docs/files";
14
14
  //#region \0rolldown/runtime.js
15
15
  var __defProp = Object.defineProperty;
16
16
  var __exportAll = (all, no_symbols) => {
@@ -37,36 +37,6 @@ const docsParserOptions = {
37
37
  };
38
38
  const parseDocsDocument = createDocsParser(docsParserOptions);
39
39
  //#endregion
40
- //#region src/runtime/files.ts
41
- const decoder = new TextDecoder();
42
- let unpacked;
43
- async function unpack(base64) {
44
- const zlib = globalThis.process?.getBuiltinModule?.("node:zlib");
45
- const buffer = globalThis.process?.getBuiltinModule?.("node:buffer");
46
- if (zlib && buffer) {
47
- const bytes = zlib.gunzipSync(buffer.Buffer.from(base64, "base64"));
48
- return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
49
- }
50
- const binary = atob(base64);
51
- const gzip = new Uint8Array(binary.length);
52
- for (let index = 0; index < binary.length; index++) gzip[index] = binary.charCodeAt(index);
53
- return new Uint8Array(await new Response(new Response(gzip).body.pipeThrough(new DecompressionStream("gzip"))).arrayBuffer());
54
- }
55
- /**
56
- * A Markdown file of a docs store: a content folder (`docs`, `docs-1`, ...) or the raw copies (`docs-raw`), or null.
57
- * A production build packs every file into one module. Nitro server assets would add one module per file, and
58
- * Cloudflare rejects a Worker upload with more than 5,000 modules. Development loads each file through Vite.
59
- * Nitro gives no build warning for that limit (https://github.com/nitrojs/nitro/issues/5149).
60
- */
61
- async function readDocsFile(store, file) {
62
- if ("read" in files) return await files.read(store, file);
63
- const ranges = Object.hasOwn(files.index, store) ? files.index[store] : void 0;
64
- const range = ranges && Object.hasOwn(ranges, file) ? ranges[file] : void 0;
65
- if (!range) return null;
66
- const bytes = await (unpacked ??= unpack(files.packed));
67
- return decoder.decode(bytes.subarray(range[0], range[1]));
68
- }
69
- //#endregion
70
40
  //#region src/runtime/content.ts
71
41
  var content_exports = /* @__PURE__ */ __exportAll({
72
42
  docsContent: () => docsContent,
@@ -1,6 +1,6 @@
1
1
  import { docsSectionForPath, findDocsPage, normalizeDocsPath } from "./navigation.js";
2
2
  import { i as docsPageSchema, t as docsFrontmatter } from "./schema-DwpXW0VZ.js";
3
- import { i as docsPageResponse, n as docsPageOf } from "./page-BbmSfZO8.js";
3
+ import { i as docsPageResponse, n as docsPageOf } from "./page-GPt09oex.js";
4
4
  //#region src/draft.ts
5
5
  /**
6
6
  * The draft of the page at `path`, parsed like a published page, or null when the request shows the published file.
@@ -0,0 +1,93 @@
1
+ import { defineDiagnostics } from "nostics";
2
+ //#region src/error-diagnostics.ts
3
+ const docsErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
4
+ docsBase: "https://vitehub.dev/docs/docs-site/diagnostics",
5
+ codes: {
6
+ DOCS_ASSISTANT_AGENTS_MISSING: {
7
+ why: ({ agent }) => `[@vite-hub/docs] docs.assistant needs ViteHub Agents to answer from the "${agent}" Agent.`,
8
+ fix: "Add `vite-hub/nuxt` to modules and set `vitehub: { agent: true, connections: true }` in nuxt.config.ts, or set `docs: { assistant: false }`."
9
+ },
10
+ DOCS_ASSISTANT_PAGE_MISSING: {
11
+ why: ({ path }) => `[@vite-hub/docs] The docs assistant's Workspace has no page at ${path}. The pages changed after the Workspace listed them.`,
12
+ fix: "Ask the question again. The next Invocation lists the current pages."
13
+ },
14
+ DOCS_COMMENTS_DATABASE_OFF: {
15
+ why: "[@vite-hub/docs] Docs sites on vite-hub/nuxt have Comments on, which keeps threads in the Database, but vitehub sets database: false.",
16
+ fix: "Remove `database: false` from the `vitehub` options in nuxt.config.ts, or set `docs: { comments: false }`."
17
+ },
18
+ DOCS_COMMENTS_PACKAGE_MISSING: {
19
+ why: "[@vite-hub/docs] Docs sites on vite-hub/nuxt have Comments on, which needs @vite-hub/comments.",
20
+ fix: "Run `pnpm add @vite-hub/comments`, or set `docs: { comments: false }` in nuxt.config.ts."
21
+ },
22
+ DOCS_COMMENTS_VITEHUB_MISSING: {
23
+ why: "[@vite-hub/docs] docs.comments needs vite-hub/nuxt, which keeps the threads in a ViteHub Database.",
24
+ fix: "Add `vite-hub/nuxt` to modules in nuxt.config.ts, or set `docs: { comments: false }`."
25
+ },
26
+ DOCS_CONTENT_INVALID: {
27
+ why: ({ details, file }) => `Invalid docs frontmatter in ${file}: ${details}`,
28
+ fix: "Fix the field that the message names in the page frontmatter or the `.navigation.yml` file. The schemas are `docsPageSchema` and `docsSectionSchema` from `@vite-hub/docs`."
29
+ },
30
+ DOCS_EXAMPLE_MISSING: {
31
+ why: ({ name }) => `::example names "${name}", but the examples folder has no ${name}.vue.`,
32
+ fix: "Add the component that the message names to the examples folder of the docs, or correct the `name` of the `::example` block."
33
+ },
34
+ DOCS_LINKS_BROKEN: {
35
+ why: ({ problems }) => `Broken docs links:\n${problems.map((problem) => `- ${problem}`).join("\n")}`,
36
+ fix: "Fix each link that the message lists in the page that it names, or add the target to `checkDocsLinks({ excludeLinks })` when it is served outside the docs output."
37
+ },
38
+ DOCS_OUTPUT_MISSING: {
39
+ why: ({ root }) => `Docs output does not exist: ${root}`,
40
+ fix: "Build the docs site first, or pass `checkDocsLinks({ dir })` the folder that the build writes."
41
+ },
42
+ DOCS_REDIRECTS_BROKEN: {
43
+ why: ({ problems }) => `Docs redirects break links:\n${problems.map((problem) => `- ${problem}`).join("\n")}`,
44
+ fix: "Point each redirect route rule that the message lists to a docs page, or remove the rule when the page that it hides still exists."
45
+ },
46
+ DOCS_SEO_DESCRIPTION_INVALID: {
47
+ why: ({ problems }) => `Docs pages have no description, one of the wrong length, or the description of another page:\n${problems.map((problem) => `- ${problem}`).join("\n")}`,
48
+ fix: "Set `description` in the frontmatter of each page that the message lists, with 70 to 160 characters, and give each page its own."
49
+ },
50
+ DOCS_SEO_FAILED: {
51
+ why: ({ problems }) => `Docs pages fail the search checks:\n${problems.map((problem) => `- ${problem}`).join("\n")}`,
52
+ fix: "Fix each page that the message lists, or set `docs: { seoAudit: \"warn\" }` to report them as hints in `.vitehub/hints.json` without stopping the build."
53
+ },
54
+ DOCS_SEO_HEADINGS_INVALID: {
55
+ why: ({ problems }) => `Docs pages have headings that search engines flag:\n${problems.map((problem) => `- ${problem}`).join("\n")}`,
56
+ fix: "Give each page that the message lists one `h1`, and go down one heading level at a time, such as `##` and then `###`."
57
+ },
58
+ DOCS_SEO_HTML_TOO_LARGE: {
59
+ why: ({ problems }) => `Docs pages have more HTML than the 2 MB that Googlebot reads:\n${problems.map((problem) => `- ${problem}`).join("\n")}`,
60
+ fix: "Split each page that the message lists, or show long lists with a component that renders less markup than a Markdown table."
61
+ },
62
+ DOCS_SEO_LINK_NOT_PAGE: {
63
+ why: ({ problems }) => `Docs pages link to a redirect or to an endpoint, not to a page:\n${problems.map((problem) => `- ${problem}`).join("\n")}`,
64
+ fix: "Link to the page that the redirect goes to. Write the URL of an endpoint, such as `/mcp`, as code instead of a link."
65
+ },
66
+ DOCS_SEO_OPEN_GRAPH_INCOMPLETE: {
67
+ why: ({ problems }) => `Docs pages have incomplete Open Graph tags, so their share previews are incomplete:\n${problems.map((problem) => `- ${problem}`).join("\n")}`,
68
+ fix: "Set the head of each page that the message lists with `useDocsSeo()`. A page that writes its own head must set `og:title`, `og:type`, `og:image`, and `og:url`."
69
+ },
70
+ DOCS_SEO_PAGE_THIN: {
71
+ why: ({ problems }) => `Docs pages have fewer than 150 words, and site audits call them thin content:\n${problems.map((problem) => `- ${problem}`).join("\n")}`,
72
+ fix: "Write at least 150 words on each page that the message lists, or merge it into a related page."
73
+ },
74
+ DOCS_SEO_PAGE_UNLINKED: {
75
+ why: ({ problems }) => `No other page links to these docs pages, so crawlers find them only in the sitemap:\n${problems.map((problem) => `- ${problem}`).join("\n")}`,
76
+ fix: "Link each page that the message lists from the navigation, the footer, or a related page."
77
+ },
78
+ DOCS_SEO_SITEMAP_NOT_PAGE: {
79
+ why: ({ problems }) => `The sitemap lists URLs that are not prerendered pages:\n${problems.map((problem) => `- ${problem}`).join("\n")}`,
80
+ fix: "Remove each URL that the message lists from the sitemap, list the page that it redirects to, or make it a page."
81
+ },
82
+ DOCS_SEO_TITLE_INVALID: {
83
+ why: ({ problems }) => `Docs pages have no title, one of the wrong length, or the title of another page:\n${problems.map((problem) => `- ${problem}`).join("\n")}`,
84
+ fix: "Set `title` in the frontmatter of each page that the message lists, with 10 to 60 characters, and give each page its own. Use `seo.title` when the heading must stay."
85
+ },
86
+ DOCS_SOURCE_MOUNT_INVALID: {
87
+ why: ({ mount }) => `Invalid docs source mount: ${mount}`,
88
+ fix: "Set the `mount` of the docs source to a URL path such as `/guide`, without `.`, `..`, `?`, `#`, or backslash segments."
89
+ }
90
+ }
91
+ });
92
+ //#endregion
93
+ export { docsErrorDiagnostics as t };
@@ -0,0 +1,38 @@
1
+ import files from "#docs/files";
2
+ //#region src/runtime/files.ts
3
+ const decoder = new TextDecoder();
4
+ let unpacked;
5
+ async function unpack(base64) {
6
+ const zlib = globalThis.process?.getBuiltinModule?.("node:zlib");
7
+ const buffer = globalThis.process?.getBuiltinModule?.("node:buffer");
8
+ if (zlib && buffer) {
9
+ const bytes = zlib.gunzipSync(buffer.Buffer.from(base64, "base64"));
10
+ return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
11
+ }
12
+ const binary = atob(base64);
13
+ const gzip = new Uint8Array(binary.length);
14
+ for (let index = 0; index < binary.length; index++) gzip[index] = binary.charCodeAt(index);
15
+ return new Uint8Array(await new Response(new Response(gzip).body.pipeThrough(new DecompressionStream("gzip"))).arrayBuffer());
16
+ }
17
+ function packedFileRange(index, store, file) {
18
+ const ranges = Object.hasOwn(index, store) ? index[store] : void 0;
19
+ return ranges && Object.hasOwn(ranges, file) ? ranges[file] : void 0;
20
+ }
21
+ function hasDocsFile(store, file) {
22
+ return "read" in files ? files.has(store, file) : packedFileRange(files.index, store, file) !== void 0;
23
+ }
24
+ /**
25
+ * A Markdown file of a docs store: a content folder (`docs`, `docs-1`, ...) or the raw copies (`docs-raw`), or null.
26
+ * A production build packs every file into one module. Nitro server assets would add one module per file, and
27
+ * Cloudflare rejects a Worker upload with more than 5,000 modules. Development loads each file through Vite.
28
+ * Nitro gives no build warning for that limit (https://github.com/nitrojs/nitro/issues/5149).
29
+ */
30
+ async function readDocsFile(store, file) {
31
+ if ("read" in files) return await files.read(store, file);
32
+ const range = packedFileRange(files.index, store, file);
33
+ if (!range) return null;
34
+ const bytes = await (unpacked ??= unpack(files.packed));
35
+ return decoder.decode(bytes.subarray(range[0], range[1]));
36
+ }
37
+ //#endregion
38
+ export { readDocsFile as n, hasDocsFile as t };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { a as DocsSection, c as DocsPageFile, d as DocsSectionFile, f as docsLayouts, g as expandDottedKeys, h as docsSectionSchema, i as DocsSearchSection, l as DocsPageFrontmatter, m as docsPageSchema, n as DocsManifest, o as DocsTocLink, p as docsPageFields, r as DocsPage, s as DocsLayout, t as DocsAppPage, u as DocsPageNavigation } from "./types-BhG6vGfG.js";
2
2
  import { i as DocsDocument, n as DocsPageResponse, t as DocsPageLink } from "./page-Dx2JD3y1.js";
3
- import { a as DocsPublicConfig, n as DocsLogo, o as DocsSiteOptions, r as DocsModuleOptions, s as DocsStartOptions } from "./nuxt-B5LrERKc.js";
4
- import { i as DocsSourceInput, r as DocsSource, t as DocsContentSource } from "./manifest-Dzp5-_AJ.js";
3
+ import { a as DocsPublicConfig, n as DocsLogo, o as DocsSiteOptions, r as DocsModuleOptions, s as DocsStartOptions } from "./nuxt-CAGpKl_-.js";
4
+ import { i as DocsSourceInput, r as DocsSource, t as DocsContentSource } from "./manifest-CMoxcwPm.js";
5
5
  import { DocsCatalogGroup, DocsGroup, DocsIcons, DocsLink, DocsMarkdownLinks, DocsPanelLoaders, DocsRailEntry, DocsSidebarGroup, DocsSidebarSection, DocsSidebarSectionBlock, docsCatalog, docsManifestPages, docsMarkdownLinks, docsMcpInstallLinks, docsPageIcon, docsRailEntries, docsRailEntry, docsRailGroups, docsRailIcon, docsRawPath, docsRelatedSections, docsSectionForPath, docsSectionGroup, docsSectionIcon, docsSidebarCollapses, docsSidebarGroups, docsSidebarSections, docsTutorialNavigationCookie, findDocsPage, normalizeDocsBase, normalizeDocsPath } from "./navigation.js";
6
6
  import { ContentLabel, DocumentsDefinition } from "@vite-hub/content";
7
7
  //#region src/collection.d.ts
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { docsCatalog, docsManifestPages, docsMarkdownLinks, docsMcpInstallLinks, docsPageIcon, docsRailEntries, docsRailEntry, docsRailGroups, docsRailIcon, docsRawPath, docsRelatedSections, docsSectionForPath, docsSectionGroup, docsSectionIcon, docsSidebarCollapses, docsSidebarGroups, docsSidebarSections, docsTutorialNavigationCookie, findDocsPage, normalizeDocsBase, normalizeDocsPath } from "./navigation.js";
2
2
  import { a as docsSectionSchema, i as docsPageSchema, n as docsLayouts, o as expandDottedKeys, r as docsPageFields } from "./schema-DwpXW0VZ.js";
3
- import { r as docsPagePath } from "./page-BbmSfZO8.js";
3
+ import { r as docsPagePath } from "./page-GPt09oex.js";
4
4
  import { documents } from "@vite-hub/content/collections";
5
5
  //#region src/collection.ts
6
6
  /**
@@ -1,5 +1,5 @@
1
1
  import { docsAppPath } from "./navigation.js";
2
- import { r as docsRedirects } from "./redirects-BrbWFSzW.js";
2
+ import { r as docsRedirects } from "./redirects-CmR1yu5A.js";
3
3
  import { defineNuxtModule } from "@nuxt/kit";
4
4
  //#region src/link-checker-redirects.ts
5
5
  /**
@@ -1,6 +1,6 @@
1
1
  import { d as DocsSectionFile, n as DocsManifest } from "./types-BhG6vGfG.js";
2
2
  import "nostics";
3
- import { ContentRuntime } from "@vite-hub/content";
3
+ import { ContentCheckOptions, ContentRuntime } from "@vite-hub/content";
4
4
  import { Source } from "@vite-hub/source";
5
5
  //#region src/check-links.d.ts
6
6
  interface DocsLinkCheckOptions {
@@ -67,7 +67,13 @@ interface DocsManifestOptions {
67
67
  * One Content Source per docs source, with its Markdown pages and its `.navigation.yml` files as YAML documents. A
68
68
  * folder is a `glob()` Source of those files. A Content Source, such as `github()`, is read as it is, from `rootDir`.
69
69
  */
70
- declare function createDocsContent(sources: readonly Pick<ResolvedDocsSource, "dir" | "source">[], rootDir?: string): ContentRuntime;
70
+ declare function createDocsContent(sources: readonly Pick<ResolvedDocsSource, "dir" | "source">[], rootDir?: string, options?: DocsContentOptions): ContentRuntime;
71
+ /** What `createDocsContent()` adds for `content.check()`. */
72
+ interface DocsContentOptions {
73
+ /** The page URL of a document of the source at `index`, by its Content id, such as `guide/start`, or null for no page. */
74
+ url?: (index: number, id: string) => string | null;
75
+ check?: ContentCheckOptions;
76
+ }
71
77
  /** Read every docs source through Content and compute sections, pages, and their order. */
72
78
  declare function createDocsManifest(options: DocsManifestOptions): Promise<DocsManifest>;
73
79
  //#endregion