@vite-hub/docs 0.0.0 → 0.3.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 (111) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +454 -0
  3. package/dist/agent-copy-BJp_Yf5d.js +33 -0
  4. package/dist/assistant-shared-CdtXowot.js +97 -0
  5. package/dist/assistant-shared-Dll_F_yy.d.ts +27 -0
  6. package/dist/assistant-worker.d.ts +11 -0
  7. package/dist/assistant-worker.js +16 -0
  8. package/dist/assistant.d.ts +14 -0
  9. package/dist/assistant.js +19 -0
  10. package/dist/content-9CINWiRf.js +171 -0
  11. package/dist/draft-DUBx--r9.js +45 -0
  12. package/dist/error-diagnostics-BoOsP6Y4.js +53 -0
  13. package/dist/index.d.ts +28 -0
  14. package/dist/index.js +27 -0
  15. package/dist/link-checker-redirects.d.ts +13 -0
  16. package/dist/link-checker-redirects.js +25 -0
  17. package/dist/manifest-D66AEF8F.js +420 -0
  18. package/dist/manifest-Dzp5-_AJ.d.ts +74 -0
  19. package/dist/markdown-Cn9-4oVG.js +378 -0
  20. package/dist/navigation.d.ts +284 -0
  21. package/dist/navigation.js +520 -0
  22. package/dist/nuxt-B5LrERKc.d.ts +240 -0
  23. package/dist/nuxt.d.ts +3 -0
  24. package/dist/nuxt.js +1485 -0
  25. package/dist/page-BbmSfZO8.js +81 -0
  26. package/dist/page-Dx2JD3y1.d.ts +74 -0
  27. package/dist/primitive-rail.d.ts +110 -0
  28. package/dist/primitive-rail.js +284 -0
  29. package/dist/raw-C03EUJKw.js +851 -0
  30. package/dist/redirects-BrbWFSzW.js +62 -0
  31. package/dist/runtime/app/app.vue +11 -0
  32. package/dist/runtime/app/assistant/DocsAssistant.vue +81 -0
  33. package/dist/runtime/app/assistant/DocsAssistantOff.vue +8 -0
  34. package/dist/runtime/app/assistant/DocsAssistantPanel.vue +322 -0
  35. package/dist/runtime/app/components/AppHeader.vue +368 -0
  36. package/dist/runtime/app/components/AppSearch.vue +68 -0
  37. package/dist/runtime/app/components/DocsAppShell.vue +62 -0
  38. package/dist/runtime/app/components/DocsArticle.vue +184 -0
  39. package/dist/runtime/app/components/DocsAsideFooter.vue +94 -0
  40. package/dist/runtime/app/components/DocsAsideLeftBody.vue +584 -0
  41. package/dist/runtime/app/components/DocsAsideLeftTop.vue +132 -0
  42. package/dist/runtime/app/components/DocsBrandMark.vue +52 -0
  43. package/dist/runtime/app/components/DocsCatalogFooter.vue +129 -0
  44. package/dist/runtime/app/components/DocsCodePanel.vue +388 -0
  45. package/dist/runtime/app/components/DocsCodePre.vue +120 -0
  46. package/dist/runtime/app/components/DocsHeaderActions.vue +4 -0
  47. package/dist/runtime/app/components/DocsLanding.vue +83 -0
  48. package/dist/runtime/app/components/DocsMarkdown.vue +64 -0
  49. package/dist/runtime/app/components/DocsPage.vue +149 -0
  50. package/dist/runtime/app/components/DocsPageCredits.vue +41 -0
  51. package/dist/runtime/app/components/DocsPageHeaderLinks.vue +120 -0
  52. package/dist/runtime/app/components/DocsRail.vue +239 -0
  53. package/dist/runtime/app/components/DocsSidebarStrip.vue +81 -0
  54. package/dist/runtime/app/components/DocsSidebars.vue +63 -0
  55. package/dist/runtime/app/components/OgImage/DocsPage.takumi.vue +33 -0
  56. package/dist/runtime/app/components/content/AgentOnly.vue +9 -0
  57. package/dist/runtime/app/components/content/CodeTree.vue +203 -0
  58. package/dist/runtime/app/components/content/ComarkHtml.vue +31 -0
  59. package/dist/runtime/app/components/content/Correct.vue +17 -0
  60. package/dist/runtime/app/components/content/Example.vue +260 -0
  61. package/dist/runtime/app/components/content/ExamplePreview.vue +6 -0
  62. package/dist/runtime/app/components/content/Examples.vue +71 -0
  63. package/dist/runtime/app/components/content/Incorrect.vue +17 -0
  64. package/dist/runtime/app/components/content/PageList.vue +206 -0
  65. package/dist/runtime/app/components/content/ProductFeatureItem.vue +43 -0
  66. package/dist/runtime/app/components/content/ProductFeatures.vue +17 -0
  67. package/dist/runtime/app/components/content/TutorialStep.vue +39 -0
  68. package/dist/runtime/app/composables/docs-assistant-problem.ts +59 -0
  69. package/dist/runtime/app/composables/docs-theme.ts +15 -0
  70. package/dist/runtime/app/composables/docs.ts +83 -0
  71. package/dist/runtime/app/composables/headerActions.ts +6 -0
  72. package/dist/runtime/app/composables/icons.ts +14 -0
  73. package/dist/runtime/app/composables/seo.ts +64 -0
  74. package/dist/runtime/app/composables/tutorial.ts +40 -0
  75. package/dist/runtime/app/composables/useDocsAssistant.ts +17 -0
  76. package/dist/runtime/app/error.vue +88 -0
  77. package/dist/runtime/app/layouts/default.vue +7 -0
  78. package/dist/runtime/app/layouts/docs.vue +104 -0
  79. package/dist/runtime/app/middleware/docs-layout.ts +23 -0
  80. package/dist/runtime/app/pages/docs-page.vue +3 -0
  81. package/dist/runtime/app/plugins/comark-css.ts +14 -0
  82. package/dist/runtime/app/plugins/icon-stroke.ts +12 -0
  83. package/dist/runtime/app/plugins/theme-color.ts +18 -0
  84. package/dist/runtime/app/utils/docs-theme.ts +43 -0
  85. package/dist/runtime/app/utils/file-tree.ts +40 -0
  86. package/dist/runtime/server/llms.d.ts +6 -0
  87. package/dist/runtime/server/llms.js +7 -0
  88. package/dist/runtime/server/markdown.d.ts +10 -0
  89. package/dist/runtime/server/markdown.js +11 -0
  90. package/dist/runtime/server/mcp.d.ts +6 -0
  91. package/dist/runtime/server/mcp.js +7 -0
  92. package/dist/runtime/server/page.d.ts +7 -0
  93. package/dist/runtime/server/page.js +27 -0
  94. package/dist/runtime/server/raw.d.ts +10 -0
  95. package/dist/runtime/server/raw.js +23 -0
  96. package/dist/runtime/server/search.d.ts +6 -0
  97. package/dist/runtime/server/search.js +32 -0
  98. package/dist/runtime/server/sitemap.d.ts +6 -0
  99. package/dist/runtime/server/sitemap.js +52 -0
  100. package/dist/runtime/server/trailing-slash.d.ts +10 -0
  101. package/dist/runtime/server/trailing-slash.js +28 -0
  102. package/dist/runtime/theme/design.css +464 -0
  103. package/dist/schema-DwpXW0VZ.js +98 -0
  104. package/dist/server.d.ts +15 -0
  105. package/dist/server.js +5 -0
  106. package/dist/theme-BXyu4uFL.d.ts +32 -0
  107. package/dist/theme-DzC8LtMH.js +237 -0
  108. package/dist/theme.d.ts +2 -0
  109. package/dist/theme.js +2 -0
  110. package/dist/types-BhG6vGfG.d.ts +212 -0
  111. package/package.json +144 -1
package/README.md ADDED
@@ -0,0 +1,454 @@
1
+ # @vite-hub/docs
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)
6
+
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
+
9
+ You write Markdown. The defaults give you a complete site. When a default does not fit, you change one option, one frontmatter field, or one component.
10
+
11
+ ## Install
12
+
13
+ ```sh
14
+ pnpm add @vite-hub/docs nuxt @nuxt/ui tailwindcss comark @comark/vue @comark/html comark-ui
15
+ ```
16
+
17
+ ```ts
18
+ // nuxt.config.ts
19
+ export default defineNuxtConfig({
20
+ modules: ["@vite-hub/docs/nuxt"],
21
+ docs: {
22
+ site: { name: "Acme", url: "https://docs.acme.dev" },
23
+ },
24
+ })
25
+ ```
26
+
27
+ The module installs Nuxt UI, `@vite-hub/ui`, `nuxt-agent-discovery`, and `nuxt-link-checker` for you, so a new site does not add them to `modules`. An app that already lists `@nuxt/ui` keeps it before the docs module, as in [Add docs to an existing app](#add-docs-to-an-existing-app). Content serves the agent files: `/raw/<page>.md`, `llms.txt`, `llms-full.txt`, `sitemap.md`, `sitemap.xml`, and the MCP server. Set `site.url` to the public origin: llms.txt, canonical links, and the raw Markdown links use it.
28
+
29
+ The shell uses Lucide, Simple Icons, and VS Code Icons. Install `@iconify-json/lucide`, `@iconify-json/simple-icons`, and `@iconify-json/vscode-icons` to serve them from your app. Without them, `@nuxt/icon` gets them from the Iconify API.
30
+
31
+ Apps that use `vite-hub` add `vite-hub/docs/nuxt` to `modules` in place of `@vite-hub/docs/nuxt`, and import the root and the assistant from `vite-hub/docs` and `vite-hub/docs/assistant`.
32
+
33
+ ### Add docs to an existing app
34
+
35
+ Put the pages in `content/docs/`. The module serves them at `/docs`, and the rest of the site stays the app's:
36
+
37
+ ```txt
38
+ content/docs/
39
+ index.md → /docs
40
+ guide/
41
+ index.md → /docs/guide
42
+ install.md → /docs/guide/install
43
+ ```
44
+
45
+ ```ts
46
+ // nuxt.config.ts
47
+ export default defineNuxtConfig({
48
+ modules: ["@nuxt/ui", "@vite-hub/docs/nuxt"],
49
+ docs: { site: { name: "Acme", url: "https://acme.dev" } },
50
+ })
51
+ ```
52
+
53
+ - The docs page answers only below `/docs`. The app keeps its own pages, its layouts, and its error page, also next to its own `pages/[...slug].vue`.
54
+ - The app keeps its `app.vue`. The docs layouts draw the site header, the search, and the page head on docs pages only. The `app.vue` must wrap `<NuxtPage />` in `<UApp>` and `<NuxtLayout>`, as Nuxt UI and Nuxt layouts need. The development server warns when one is missing.
55
+ - The build prerenders every docs page and crawls nothing else, so the app's own pages stay server-rendered.
56
+ - The docs theme applies to the docs pages only. The app's pages keep its Nuxt UI theme. See [Theme](#theme).
57
+
58
+ ## Content
59
+
60
+ ```txt
61
+ content/
62
+ index.md → /
63
+ about.md → /about
64
+ docs/
65
+ index.md → /docs
66
+ guide/
67
+ .navigation.yml section title, icon, order, category, group, fold
68
+ index.md → /docs/guide
69
+ install.md → /docs/guide/install
70
+ ```
71
+
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
+
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.
75
+
76
+ ### Multiple sources and Markdown components
77
+
78
+ Read pages from more than one place with `sources`. It replaces `dir`. Each entry is a folder relative to the app root, a Source from `vite-hub/source`, such as `glob()` or `github()`, or `{ source, mount?, exclude?, frontmatter? }` with one of them. `mount` is the public path of the pages, `exclude` leaves out file globs, and `frontmatter` adapts metadata before schema validation.
79
+
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
+
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).
83
+
84
+ ```ts
85
+ import { github, glob } from "vite-hub/source"
86
+
87
+ export default defineNuxtConfig({
88
+ modules: ["@vite-hub/docs/nuxt"],
89
+ docs: {
90
+ base: "/",
91
+ sources: [
92
+ { source: "pages", exclude: ["partials/**"] },
93
+ { source: "../packages/zoom/docs", mount: "/zoom" },
94
+ { source: glob({ cwd: "guides", include: ["**/*.md", "**/.navigation.yml"] }), mount: "/guides" },
95
+ { source: github({ repo: "acme/api", root: "docs" }), mount: "/api" },
96
+ ],
97
+ sections: { zoom: { category: "Packages", order: 1 } },
98
+ components: "./markdown-components.ts",
99
+ },
100
+ })
101
+ ```
102
+
103
+ `sections` overrides `.navigation.yml` fields by section id. A source's synchronous `frontmatter(data, { file, path, markdown })` callback can supply generated titles or migrate legacy fields. Its return value still passes the full docs schema. `file` stays relative to the source; `path` is the public page path.
104
+
105
+ The `components` module exports a default map of Comark tags to Vue components. Components passed directly to `DocsMarkdown` override that map. Both maps override app blocks in `components/content/`, which override the built-in Comark blocks and load on demand.
106
+
107
+ ### Frontmatter
108
+
109
+ | Field | Default | Use |
110
+ | --- | --- | --- |
111
+ | `title` | Required | Page heading and browser title. |
112
+ | `description` | None | Text under the heading, the meta description, and the llms.txt entry. |
113
+ | `tagline` | `description` | Text under the heading, when it must differ from the meta description. |
114
+ | `eyebrow` | none | A short label above the title, such as the package that the page documents. |
115
+ | `credits` | None | Inline Markdown at the end of the page, such as `Icons from [Lucide](https://lucide.dev).` |
116
+ | `keywords` | None | Words that find the page in search besides its own text: a list, or one string with commas. They rank below the page title and with headings. |
117
+ | `icon` | `i-lucide-file-text` | Sidebar icon, as an Iconify name. |
118
+ | `layout` | `article` | `article`, `tutorial`, `landing`, or `home`. |
119
+ | `sidebar` | `true` | `false` hides the left navigation on this page. `collapsed` starts it as a narrow column that the reader opens. |
120
+ | `toc` | `true`, `false` on `landing` | `false` hides the "On this page" outline. |
121
+ | `codePanel` | `false` | Tutorials only. Shows the files of the current step beside the prose. |
122
+ | `tutorial` | None | Tutorials only. `project` or `quickstart`, for your own tutorial catalog. |
123
+ | `navigation` | Listed | `false` keeps the page out of the sidebar. Or `{ title, order, group, kind, panel }`. See [Panels](#panels). |
124
+ | `seo` | None | `{ title, description, image, index }` for search results and shares when they must differ from the page. `image` is a path in `public/` or a URL, or `false` for no share image. `index: false` asks search engines not to index the page. See [Pages that search engines skip](#pages-that-search-engines-skip). |
125
+
126
+ Dotted keys work too, such as `navigation.order: 2`. A wrong field stops the build with `DOCS_CONTENT_INVALID`. In development, the terminal shows the error and the site keeps the last valid pages until you fix the file.
127
+
128
+ `.navigation.yml` in a section folder:
129
+
130
+ | Field | Use |
131
+ | --- | --- |
132
+ | `title` | Section name. Defaults to the title of `index.md`, then to the folder name. |
133
+ | `icon` | Section icon. |
134
+ | `order` | Position in the rail. Lower comes first. |
135
+ | `category` | Rail group and catalog group. List the categories in the `categories` option to order them. |
136
+ | `group` | Title of the group of the section. See `groups`. |
137
+ | `fold` | `true` folds each page group of the sidebar. The group of the current page opens itself. |
138
+ | `related` | Section ids listed under Related in the sidebar. |
139
+
140
+ ### Panels
141
+
142
+ A long list of pages, such as one page for each error code, would bury the other pages of a section. Set `navigation.panel: true` on the `index.md` of a folder inside the section, and the folder becomes a panel:
143
+
144
+ - The section sidebar shows one link to the panel, with the number of its pages, after the section pages.
145
+ - On a page of the panel, the sidebar lists only the panel: a link back to the section, the panel Overview, and its pages by `navigation.group`. Each group folds. A page title that is a code, such as `QUEUE_DISABLED`, shows in monospace on one line. Search finds the panel pages by title, so the panel has no filter of its own.
146
+ - The rail keeps the reader in the panel. On `/docs/queue/diagnostics/queue_disabled`, the KV item opens `/docs/kv/diagnostics` when that folder is a panel too, and `/docs/kv` when it is not.
147
+ - Previous and next stay inside the panel.
148
+
149
+ ```md [content/docs/queue/diagnostics/index.md]
150
+ ---
151
+ title: Queue diagnostics
152
+ navigation.title: Diagnostics
153
+ navigation.panel: true
154
+ ---
155
+ ```
156
+
157
+ ### Pages that search engines skip
158
+
159
+ `seo.index: false` adds `<meta name="robots" content="noindex, follow">` and leaves the page out of `sitemap.xml`, llms.txt, `llms-full.txt`, and the share images. The site search lists it by its title and description only. The build does not prerender the page: the server renders it on request, so a site with thousands of generated pages builds as fast as before. Links to the page stay valid for the link checker, and its raw Markdown copy stays at `/raw/...`. Use it for long tails of thin pages, such as one page for each error code, and keep the page that lists them indexed.
160
+
161
+ ## Layouts and rails
162
+
163
+ - `article` is prose with the outline on the right.
164
+ - `tutorial` numbers each `::tutorial-step` block. With `codePanel: true`, a sticky panel on wide screens shows the file tree and the file that the reader is on. Code blocks named `commands/...` or `output/...`, and shell blocks, stay in the prose.
165
+ - `landing` is a wide Overview page without the outline. A section Overview ends with the catalog of every section.
166
+ - `home` is a product home page under the site header, with no title, actions, sidebar, or outline. Your `components/content/` blocks, such as a `::product-hero`, take the full width. The Markdown between them, such as a heading, a list, or a code group, gets the prose styles and the width of a docs page. The page keeps its search entry, Markdown copy, and share image.
167
+
168
+ The left navigation (the section rail and the page sidebar) and the right outline show on every docs page. Turn them off for one page with `sidebar: false` or `toc: false`. A page that needs the width, such as a playground, sets `sidebar: collapsed`: wide screens show a narrow column with the logo, a button that opens the navigation, search, and the site links, or the rail on a site that has one. An app page in the docs layout sets it with `definePageMeta({ layout: "docs", sidebar: "collapsed" })`. A code panel tutorial starts collapsed too.
169
+
170
+ ````md
171
+ ---
172
+ title: Build a CLI
173
+ layout: tutorial
174
+ codePanel: true
175
+ ---
176
+
177
+ ::tutorial-step{title="Create the project"}
178
+ ## Create the project
179
+
180
+ ```ts [src/cli.ts]
181
+ console.log("hello")
182
+ ```
183
+ ::
184
+ ````
185
+
186
+ ## Customize
187
+
188
+ Most changes are options in `nuxt.config.ts`:
189
+
190
+ | Option | Default | Use |
191
+ | --- | --- | --- |
192
+ | `dir` | `content` | Folder of Markdown pages. |
193
+ | `base` | `/docs`, or `/` without a `docs/` folder | URL prefix whose folders are sections. |
194
+ | `site` | `{ name: "Docs" }` | `name`, `url` (canonical origin), `description`, `logo`, `badge` (`{ label, tooltip }`). A `logo` path is a one-color SVG that the theme fills with the text color. `{ light, dark }` shows a colored logo as it is, with `dark` in dark mode. |
195
+ | `categories` | `[]` | Order of section categories in the rail and the catalog. |
196
+ | `railExclude` | `[]` | Categories that the catalog lists but the rail leaves out. |
197
+ | `groups` | `[]` | `[{ title, icon, sections }]`: rail items that hold several sections, such as every component package of a library. The sidebar of a member lists every section of its group, one row per section. A section also joins with `group` in its `.navigation.yml`. |
198
+ | `start` | None | `{ section, links }`: the section that new readers open first, and site pages listed at its top. |
199
+ | `socials` | `[]` | Community links at the foot of the docs sidebar and in the header of other pages, or in its menu on narrow screens. |
200
+ | `footer` | `[]` | Site pages linked at the end of every docs page, such as About and Privacy. |
201
+ | `banner` | None | One line above every docs page. |
202
+ | `github` | `false` | `{ repo, branch, dir }`. Adds a GitHub link beside the socials, with the star count when available. |
203
+ | `icons` | Lucide fallbacks | Icon maps of the rail and the sidebar. |
204
+ | `sitemap` | `[]` | More paths for `/sitemap.xml`. Every docs page is listed already. |
205
+ | `mcp` | On | `{ name, guide }`, or `false` to turn off the MCP server. |
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`. |
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
+ | `assistant` | `false` | `true`, or `{ agent }`. See [Docs assistant](#docs-assistant). |
211
+ | `comments` | On with `vite-hub/nuxt` | `false` turns Comments off, or `{ database, dialect, overlay }`. See [Comments](#comments). |
212
+ | `rawMarkdown` | None | `(markdown, page) => string`. Rewrites a page before agents read it. |
213
+ | `markdownPages` | `true` | A Markdown copy of each app page that is not a docs page, converted from its HTML, at its URL plus `.md` and for `Accept: text/markdown`. `false` turns it off. |
214
+ | `parser` | None | Path of a module whose default export is the parser options: `{ comarkUi, examples, plugins }`. See [Comark plugins](#comark-plugins). |
215
+ | `examples` | `examples` | Folder, inside `app/`, of the Vue files that `::example{name}` shows. See [Examples](#examples). |
216
+
217
+ ### Components
218
+
219
+ The shell is a set of Nuxt components. Create a component with the same name in your app, and it replaces the default. For example, `app/components/DocsPageHeaderLinks.vue` replaces the page actions.
220
+
221
+ | Component | Part |
222
+ | --- | --- |
223
+ | `AppHeader` | Site header, with search, GitHub, social links, and the color mode button. On wide screens it hides beside the docs sidebar. |
224
+ | `AppSearch` | The search dialog. |
225
+ | `DocsRail`, `DocsSidebars`, `DocsAsideLeftTop`, `DocsAsideLeftBody`, `DocsAsideFooter` | The section rail, the page sidebar with its brand, search, and title, and the row of links at its foot. |
226
+ | `DocsPage`, `DocsArticle`, `DocsLanding`, `DocsMarkdown` | The page and its layouts. |
227
+ | `DocsHeaderActions` | Empty. Replace it to add items to the site header or the desktop sidebar footer. |
228
+ | `DocsPageHeaderLinks` | Copy page, View as Markdown, Open in ChatGPT or Claude, and the MCP links. |
229
+ | `DocsCatalogFooter` | The catalog at the end of an Overview. |
230
+ | `DocsCodePanel`, `DocsCodePre` | The tutorial code panel and code blocks. |
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.
233
+
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
+
236
+ Components read the site with auto-imported composables: `useDocsConfig()`, `useDocsManifest()`, `useDocsPage()`, `useDocsSection()`, `useDocsIcons()`, and `useDocsAssistant()`.
237
+
238
+ A Vue entry holds the parts that docs pages share with other ViteHub surfaces. Their styles are in `@vite-hub/ui/styles.css`, which the module loads.
239
+
240
+ | Entry | Parts |
241
+ | --- | --- |
242
+ | `@vite-hub/docs/primitive-rail` | `PrimitiveRail`, `PrimitiveRailGroup`, `PrimitiveRailItem`, and `PrimitiveIcon`, which draws a [`@vite-hub/icons`](../icons/README.md) icon inline so its rail item can move it on hover. The docs rail and the Console use them. They are internal and can change in any release. |
243
+
244
+ ### Examples
245
+
246
+ `::example` shows a preview and its source, with a Preview and Code switch. Around an `md`, `markdown`, `mdc`, or `comark` code block, the preview is that Markdown, rendered with the same plugins as the page:
247
+
248
+ `````md
249
+ ::example
250
+ ````md
251
+ Some **bold** text.
252
+ ````
253
+ ::
254
+ `````
255
+
256
+ With `name`, the preview is a Vue file in `app/examples/`, and Code shows its source. `::example{name="ButtonExample"}` renders `app/examples/ButtonExample.vue`. `height` keeps that many rem for it before its module loads, `flush` shows it edge to edge at that height, and `reset` adds a control that mounts it again. `play` links the example to a playground that opens it.
257
+
258
+ `::examples` puts several `:::example` blocks in underlined tabs named by their `label`. The examples share one view, so a reader who picks Code keeps reading code from tab to tab. A site that renders the preview itself, as comark-ui does to write `play`, passes a parser plugin named `docs-examples`.
259
+
260
+ `::correct` and `::incorrect` are examples titled Correct and Incorrect, as on a lint rule's page. Any example takes a `#title` slot that leads its bar, and these two fill it; `title` renames them. Markdown that doesn't parse, such as broken frontmatter on purpose, shows its source alone.
261
+
262
+ ### Code trees and page lists
263
+
264
+ `::code-tree` shows its code blocks as a project: file tabs beside the open file, or above it in a narrow panel. Each block names its file, such as ```` ```ts [server/api/kv.ts] ````, and `default-value` picks the file that opens first.
265
+
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
+
268
+ ### Comark plugins
269
+
270
+ 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`.
271
+
272
+ An image from `public/`, such as `![Console](/screenshots/console.png)`, gets its `width` and `height` from the file, so the page does not move when the picture loads. The build measures the pictures in the `public/` folders of the app and its layers. A side that the page sets, such as `{width=640}`, stays, and the other follows the picture's ratio. Restart the development server to measure a picture added while it runs.
273
+
274
+ `::examples` and `:::example{label play}` show rendered Markdown next to its source, with underlined tabs, a Preview and Code switch, and an optional link to a playground. The parser renders the example's first fenced block as its preview, with the page's plugins. An example whose Markdown doesn't parse shows its source alone. A site's parser can still supply its own `example-preview` node. Content without a preview node stays visible.
275
+
276
+ Parser options go in a module that `parser` names, since Comark plugins are functions:
277
+
278
+ ```ts
279
+ // docs.parser.ts
280
+ import type { DocsParserOptions } from "@vite-hub/docs/server"
281
+ import emoji from "comark/plugins/emoji"
282
+
283
+ export default {
284
+ plugins: [emoji()],
285
+ comarkUi: { chips: true },
286
+ examples: { play: source => `/play#md=${encodeURIComponent(source)}` },
287
+ } satisfies DocsParserOptions
288
+ ```
289
+
290
+ Set `docs: { parser: "./docs.parser.ts" }`. The page route, search, and Console drafts parse with these options. The page route reads each page with `content.get()` from a Content runtime over the bundled pages, so Content caches the parsed page. To parse docs pages in your own `server/content.ts`, pass `defineContent({ markdown: docsMarkdown(options) })` from `@vite-hub/docs/server`. It turns off Content's own comark-ui preset, so the output is the same as the page route's.
291
+
292
+ | Option | Default | Use |
293
+ | --- | --- | --- |
294
+ | `comarkUi` | `{ typeset: false, chips: false, diagrams: false, badge: { download: false } }` | Options of comark-ui's preset, merged over the defaults, such as `{ chips: true }`. `mermaid` fences render as SVG on the server with no network request. `diagrams: true` draws D2, PlantUML, and Graphviz fences through kroki.io, which receives their source; `diagrams: { server }` uses your own Kroki server. When `docs.github` is set, `github.references.repo` defaults to its repository, so `#123` links to its issues. |
295
+ | `examples.tags` | `["example", "correct", "incorrect"]` | Tags of the blocks that get a preview of their first fenced block, such as `["example", "correct", "incorrect"]`. |
296
+ | `examples.play` | None | `(source, tag) => url`: a playground URL for the block's Markdown, written as its `play`. Return `undefined` for no link. |
297
+ | `plugins` | `[]` | More Comark plugins, after the built-in ones. A plugin with a built-in name, such as `alert` or `comark-tabs`, replaces it. A plugin that adds a tag that comark-ui doesn't render needs a component for it in `app/components/content/`. |
298
+
299
+ ### Design
300
+
301
+ The design follows the comark-ui site on top of the ViteHub design system (`@vite-hub/ui/theme.css` and `vitehubTheme`): Geist, neutral grays, hairline rings, 6px controls and 8px cards, one blue focus ring, a faint grain on the page, and GitHub code colors. On docs pages the sidebar holds the brand, search, a rail of sections or groups next to the page list, and a row at its foot with GitHub, the socials, and the color mode button. Other pages, and phones, get a header with the same parts. Text, code, and focus rings pass WCAG AA in light and dark mode. Change it in two places:
302
+
303
+ - `app.config.ts` `ui` keys. Your values win over the design. The design wins over the Nuxt UI defaults, also when `@nuxt/ui` comes first in `modules`.
304
+ - CSS variables in your stylesheet, such as `--vh-content-width` (prose width), `--vh-toc-width`, `--vh-panel-width`, `--vh-grain` (`none` turns the grain off), `--font-sans`, and the Nuxt UI `--ui-*` colors.
305
+
306
+ In an app with its own `app.vue`, the theme stays on the docs pages:
307
+
308
+ - The theme's CSS applies below the `vh-docs` class. The docs layouts put it on `<html>` on docs pages only.
309
+ - The docs layouts give the theme's slot classes and default props to Nuxt UI's `<UTheme>`, with the live `app.config.ts` UI values above the design. The app's pages keep their look.
310
+ - The docs pages use the app's Nuxt UI colors and icons. To change the docs pages only, set the CSS variables on `:root.vh-docs`.
311
+
312
+ ### Link checks
313
+
314
+ The build also checks cross-page fragments in the final HTML output. Routes excluded by `routeRules` with `prerender: false` or `nitro.prerender.ignore`, including the enabled ViteHub Console, do not need output files: the server can answer them at request time. Files that do exist still have their fragments checked. More specific `prerender: true` rules remain checked.
315
+
316
+ `docs.linkChecker` accepts `excludeLinks` for intentionally unchecked URLs, `excludePages` for embedded documents, `ignoreFragments` for pages that use the hash as application state, and `redirect(url)` for application redirects. Lists accept exact public paths, globs such as `/blog/**`, or regular expressions; include `app.baseURL` when it is not `/`. The app's `linkChecker.excludeLinks` and `docs.linkChecker.excludeLinks` are combined. `linkChecker: false` disables both checks. For a standalone output check, use `checkDocsLinks({ dir, siteUrl, appBase?, excludeLinks?, excludePages?, ignoreFragments?, redirect?, isRuntimePath? })` from `@vite-hub/docs/server`; `isRuntimePath(pathname)` identifies server routes whose output files may be absent.
317
+
318
+ ## Agent resources
319
+
320
+ Every page has a Markdown copy for coding agents. You get these routes with no setup:
321
+
322
+ | Route | Content |
323
+ | --- | --- |
324
+ | `/raw/<page>.md` | The page as Markdown, with absolute links. `::agent-only` blocks stay in it. It ends with the pages of its section, the next page, and a link to `/llms.txt`. |
325
+ | `/llms.txt`, `/llms-full.txt` | An index of every page, and every page in one file without the section links. |
326
+ | `/sitemap.md`, `/sitemap.xml` | Every page, for agents and for search engines. |
327
+ | `/mcp` | An MCP server with the `list-pages` and `get-page` tools. |
328
+ | `/.well-known/skills/<name>/SKILL.md` | Agent Skills from the `skills/` folder of the app, when it has one. |
329
+ | `/<page>.md` | Any other app page, such as `/index.md` for the home page, converted from its HTML by Content. `markdownPages: false` turns it off. |
330
+
331
+ Product landing components become plain Markdown, with the hero tagline, hosts, channels, linked feature titles, and descriptions. Component syntax inside code examples stays literal.
332
+
333
+ `::agent-only` content shows only to agents. The site renders nothing for it, and search skips it. Use `rawMarkdown` to expand your own components into plain Markdown in the agent copy. Each page header links to its Markdown copy and opens it in ChatGPT or Claude.
334
+
335
+ ## Search and share
336
+
337
+ Every page gets its title, description, canonical link, Open Graph and Twitter tags, Schema.org (`WebSite`, `WebPage`, `TechArticle`, and a breadcrumb), and a share image, from its frontmatter and the `site` options. [Nuxt SEO](https://nuxtseo.com) does the work: `nuxt-site-config` takes `site`, `nuxt-schema-org` writes the graph, and `nuxt-og-image` renders each image while the build prerenders, so the server carries no renderer and a Worker stays small. The default image shows the site, the section, the page title, and the description. A page sets `seo.image` to share a file of its own. For another design, add `components/OgImage/Docs.takumi.vue` with the props `title`, `description`, `site`, `section`, `logo`, and `host`, and set `ogImage: { component: "Docs" }`. An app page, such as a playground, calls `useDocsSeo({ title, description })` to get the same tags and image.
338
+
339
+ Search indexes every page by heading. `⌘K` opens it. Page titles rank first, then headings, then text, and a typo still finds the page. The index loads the first time the dialog opens, from `/api/_docs/search.json`. `::agent-only` content is not indexed.
340
+
341
+ ## Comments
342
+
343
+ A docs site on `vite-hub/nuxt` has ViteHub Comments on every page. The team pins comments, replies, mentions people with `@`, and resolves threads. Install `@vite-hub/comments` beside `vite-hub`:
344
+
345
+ ```sh
346
+ pnpm add @vite-hub/comments
347
+ ```
348
+
349
+ The module sets the `comments` option of `vite-hub/nuxt`, which turns on the Database. Run `vitehub database generate` and `vitehub database migrate` once. No `server/comments.ts` is needed; add one to set `authorize` or `people`.
350
+
351
+ - A thread belongs to the page path, such as `/docs/kv`, so it stays on its page across deploys.
352
+ - Readers see nothing. The overlay loads only with `?vitehub` or the `vitehub-tools` cookie, for people that `authorize` lets read. Without `authorize`, a production build admits the people of the Console's Comments section and people signed in with GitHub who can push to the repository.
353
+ - `@` suggests the users of ViteHub Auth when the app has Auth, else the people who wrote in the threads.
354
+ - The Console's Comments section lists the threads.
355
+
356
+ Turn it off with `docs: { comments: false }`. An object goes to the `comments` option of `vite-hub/nuxt`, such as `{ database: "docs" }` or `{ overlay: false }`. A site without `vite-hub/nuxt` has no Comments; `comments: true` there fails the build with `DOCS_COMMENTS_VITEHUB_MISSING`.
357
+
358
+ ## Docs assistant
359
+
360
+ The docs assistant answers reader questions from your pages and links the pages that it used. It is a ViteHub Agent preset, `docsAssistant`. By default it runs on your ChatGPT plan, so you need no API key: with Codex on Node.js, and with a model-backed Driver in a Cloudflare Worker build.
361
+
362
+ ```sh
363
+ pnpm add vite-hub @vite-hub/agent @vite-hub/workflow @vite-hub/connections @vite-hub/database drizzle-orm@1.0.0-rc.5 @openai/codex
364
+ ```
365
+
366
+ ```ts
367
+ // nuxt.config.ts
368
+ export default defineNuxtConfig({
369
+ modules: [
370
+ ["vite-hub/nuxt", { host: "node", agent: true, connections: true, database: true }],
371
+ "@vite-hub/docs/nuxt",
372
+ ],
373
+ docs: { assistant: true },
374
+ })
375
+ ```
376
+
377
+ ```ts
378
+ // 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.
380
+ import { docsAssistant } from "@vite-hub/docs/assistant"
381
+ import { defineAgent } from "vite-hub/agent"
382
+
383
+ export default defineAgent({ extends: docsAssistant, workspace: {} })
384
+ ```
385
+
386
+ ```ts
387
+ // server/connections/chatgpt.ts
388
+ import { defineConnection } from "vite-hub/connections"
389
+ import { chatgpt } from "vite-hub/connections/chatgpt"
390
+
391
+ export default defineConnection({
392
+ provider: chatgpt({ appName: "Acme docs", appVersion: "1.0.0" }),
393
+ access: { "agent:docs": { read: true } },
394
+ })
395
+ ```
396
+
397
+ ```ts
398
+ // server/databases/default.ts: Connections keeps the grant in the app Database. Skip it when the app has one.
399
+ import { defineDatabase } from "vite-hub/database"
400
+
401
+ export default defineDatabase({ schema: {} })
402
+ ```
403
+
404
+ The Agent and the Connection are app files on purpose. ViteHub discovers Agents and Connections from `server/`, so the ViteHub CLI and the Console show them like every other Agent and Connection. The Connection grants the Agent use of your ChatGPT plan, and a grant of that kind stays in your code, where you can read it. `docs.assistant` only adds the panel and checks this setup.
405
+
406
+ 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
+
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.
409
+
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.
411
+
412
+ Limits:
413
+
414
+ - **Worker builds.** Under the `workerd` and `worker` conditions, `docsAssistant` uses `driver: { model: "gpt-6.1-sol", gateway: chatgpt() }`, because a Worker cannot start Codex. The model reads the pages with the read-only Workspace shell. Change the model with `driver: { model }`, from `vitehub connections models chatgpt`. An Agent that sets `codexDriver()` itself fails a Worker build with `AGENT_B0019`.
415
+ - **Plan use.** OpenAI allows plan usage for open-source projects, personal apps that run locally, and selected private apps. Paid or remotely hosted apps must join OpenAI's waitlist first.
416
+ - **Shell access.** Codex reads the pages with shell commands in a temporary copy. It cannot write outside that copy or use the network, but it can read other files that the server user can read, and a reader can ask for them. Run a public assistant as a user that can read only the app.
417
+ - **Rate limit and budget.** The default limit is in process memory. It resets on restart, does not span processes, and one reader can use the whole hour. The token budget records an answer over 200,000 tokens; it does not stop it.
418
+
419
+ The [assistant guide](https://vitehub.dev/docs/docs-site/assistant) has every default and option.
420
+
421
+ ## Edit in the Console
422
+
423
+ The ViteHub Console edits, previews, and publishes pages through the CMS. Add `vite-hub/nuxt` and one file:
424
+
425
+ ```ts
426
+ // server/content.ts
427
+ import { defineContent } from "vite-hub/content"
428
+ import cms from "vite-hub/cms"
429
+ import { docsCollection } from "@vite-hub/docs"
430
+
431
+ export default defineContent({
432
+ extends: [cms, { repo: "owner/name", publish: "pr", access: "roles" }],
433
+ collections: { docs: docsCollection() },
434
+ })
435
+ ```
436
+
437
+ `docsCollection({ path?, label? })` is a `documents()` collection over `content/**/*.md` with the page frontmatter as fields, and each document URL is its page URL. With `repo`, a save commits to a draft branch and a publish opens a pull request, so the site shows the change after it merges and builds. In the Console preview pane the page route renders the draft, uncached. Leave out the Content `seo` option: the docs module serves the sitemap and the Markdown copies, and Content's `.md` copies would compete with them in another format. See [Edit in the Console](https://vitehub.dev/docs/docs-site/configure#edit-in-the-console).
438
+
439
+ ## Errors
440
+
441
+ | Code | When | Fix |
442
+ | --- | --- | --- |
443
+ | `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. |
445
+ | `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
+
447
+ ## Inspect
448
+
449
+ - The manifest, every section and page with its resolved title, order, layout, and flags, is in `.nuxt/docs/manifest.mjs`. The server reads it. Components read the copy in `.nuxt/docs/app-manifest.mjs` with `useDocsManifest()`: each page has only its `DocsAppPage` fields, such as `title`, `description`, `icon`, and `layout`. The page route returns the other fields of a page, such as `seo`, `tagline`, and `credits`. The build lists the pages and `.navigation.yml` files through ViteHub Content: `createDocsContent()` gives one Content Source per docs source, named `docs_<index>`: a `glob()` Source for a folder, or the Source that `sources` names. A script reads the whole manifest with `await createDocsManifest({ dir, base })`, or `{ dir, base, sources, rootDir }`, from `@vite-hub/docs/server`.
450
+ - The agent copy of each page is in `.nuxt/docs/raw/`.
451
+ - The Markdown blocks that pages can use are in `.nuxt/docs/components.mjs`.
452
+ - A running site serves the parsed page at `/api/_docs/page/<page>.json` and the search index at `/api/_docs/search.json`.
453
+
454
+ See the [docs site documentation](https://vitehub.dev/docs/docs-site).
@@ -0,0 +1,33 @@
1
+ import { docsManifestPages, docsRawSectionLinks } from "./navigation.js";
2
+ import { t as toRawMarkdown } from "./raw-C03EUJKw.js";
3
+ //#region src/agent-copy.ts
4
+ /**
5
+ * The copy of a page that agents read at `/raw/<page>.md`: the source as plain Markdown with absolute links, then the
6
+ * links of its section. `siteUrl` is the public origin with the app base, such as `https://docs.example.com/portal`.
7
+ */
8
+ function docsAgentCopy(manifest, page, source, siteUrl) {
9
+ return {
10
+ markdown: toRawMarkdown(source, {
11
+ siteUrl,
12
+ pagePath: page.path
13
+ }),
14
+ footer: docsRawSectionLinks(manifest, page.path, siteUrl)
15
+ };
16
+ }
17
+ /** The Content Source of a page, named like `createDocsContent()` names it: `docs_<index>` for the server asset `docs-<index>`. */
18
+ function docsContentSource(page) {
19
+ return `docs_${page.source ? page.source.slice(5) : 0}`;
20
+ }
21
+ /** The pages of each Content Source of the docs, `docs_<index>`, by their file in the Source. */
22
+ function docsAgentPages(manifest) {
23
+ const sources = /* @__PURE__ */ new Map();
24
+ for (const page of docsManifestPages(manifest)) {
25
+ const name = docsContentSource(page);
26
+ const pages = sources.get(name) ?? /* @__PURE__ */ new Map();
27
+ pages.set(page.file, page);
28
+ sources.set(name, pages);
29
+ }
30
+ return sources;
31
+ }
32
+ //#endregion
33
+ export { docsAgentPages as n, docsContentSource as r, docsAgentCopy as t };
@@ -0,0 +1,97 @@
1
+ import { docsAppPath } from "./navigation.js";
2
+ import { rateLimit } from "@vite-hub/agent/capabilities";
3
+ import { defineAgent } from "@vite-hub/agent";
4
+ import { webChat } from "@vite-hub/agent/channels";
5
+ import { createRateLimiter } from "@vite-hub/rate-limit";
6
+ import { memoryRateLimitDriver } from "@vite-hub/rate-limit/drivers/memory";
7
+ import { glob } from "@vite-hub/workspace";
8
+ //#region src/assistant-shared.ts
9
+ /** Invocation context key that holds the path of the page the reader has open. */
10
+ const docsPageContextKey = "docsPage";
11
+ const docsRules = `You answer questions from readers of this documentation site.
12
+
13
+ The pages of the site are Markdown files in the \`pages\` folder of your working directory. Search and read them with read-only shell commands such as \`rg\`, \`ls\`, and \`cat\` before you answer.
14
+
15
+ A page URL is its file path without \`pages\` and \`.md\`. An \`index.md\` file is the URL of its folder. For example, \`pages/docs/guide/setup.md\` is \`/docs/guide/setup\`, and \`pages/docs/guide/index.md\` is \`/docs/guide\`. Apply the site's app base, when specified below, to every page link.
16
+
17
+ - Answer only from these pages. Do not use what you know about the product from other sources.
18
+ - Link each page that you used, as a Markdown link to its URL, for example [Setup](/docs/guide/setup).
19
+ - If the pages do not answer the question, say that the documentation does not cover it. Do not guess.
20
+ - Keep answers short and concrete. Put code in fenced code blocks.
21
+ - Do not change files. Do not run commands that do not read the pages.
22
+
23
+ {{{ instructions }}}`;
24
+ /** Page paths only: the value goes into the instructions, so it must not carry Markdown or template syntax. */
25
+ const pagePathPattern = /^\/[\w\-./~%]{0,299}$/;
26
+ /** Returns the page path from a chat request body, or an empty string when it is missing or not a plain path. */
27
+ function docsPageFromBody(body) {
28
+ const page = body.page;
29
+ return typeof page === "string" && pagePathPattern.test(page) && !page.includes("..") ? page : "";
30
+ }
31
+ function currentPageInstructions({ context }) {
32
+ const page = context.get(docsPageContextKey);
33
+ const appBase = context.get("docsAppBase");
34
+ return [typeof appBase === "string" && appBase !== "/" ? `Prefix every page link with ${appBase}, for example [Setup](${docsAppPath("/docs/guide/setup", appBase)}). The reader's page path below is relative to this app base.` : "", typeof page === "string" && page ? `The reader has the page ${page} open. When the question is not clear, answer for that page first.` : ""].filter(Boolean).join("\n\n") || void 0;
35
+ }
36
+ /**
37
+ * The assistant's question limit, with the id `docs-rate-limit` that replaces the default one. Counters live in process
38
+ * memory: they reset on restart and do not span processes.
39
+ */
40
+ function docsRateLimit(options = {}) {
41
+ return rateLimit({
42
+ id: "docs-rate-limit",
43
+ identity: options.identity ?? (() => "site"),
44
+ trustedIpHeaders: options.trustedIpHeaders,
45
+ limiter: createRateLimiter({
46
+ driver: memoryRateLimitDriver(),
47
+ enforcement: "strict",
48
+ limit: options.limit ?? 30,
49
+ name: "docs-assistant",
50
+ window: options.window ?? "1h"
51
+ }),
52
+ message: "The docs assistant reached its limit of questions for now. Try again later."
53
+ });
54
+ }
55
+ /** The model of the Worker build. A model ID from the ChatGPT plan catalog: `vitehub connections models chatgpt`. */
56
+ const docsAssistantModel = "gpt-6.1-sol";
57
+ /** The docs rules, the developer's instructions in their place, and the reader's page. */
58
+ const docsInstructions = { template: [docsRules, currentPageInstructions] };
59
+ /**
60
+ * The parts of the docs assistant that do not depend on the host: a read-only Workspace with the pages in `content/`,
61
+ * the `web` Chat Channel with the reader's current page, a site-wide rate limit, and Driver capacity.
62
+ */
63
+ function defineDocsAssistant(driver, capabilities = []) {
64
+ return defineAgent({
65
+ description: "Answers reader questions from the documentation pages.",
66
+ driver,
67
+ workspace: {
68
+ mode: "read",
69
+ sourceRootDir: process.cwd(),
70
+ sources: { pages: glob({
71
+ cwd: "content",
72
+ include: ["**/*.md"],
73
+ keyCache: false
74
+ }) }
75
+ },
76
+ channels: { web: webChat({ route: { admission: { context: ({ body }) => {
77
+ const appBase = docsPageFromBody({ page: Reflect.get(body, "appBase") });
78
+ return { context: {
79
+ [docsPageContextKey]: docsPageFromBody(body),
80
+ ...appBase && appBase !== "/" && !appBase.startsWith("//") ? { docsAppBase: appBase } : {}
81
+ } };
82
+ } } } }) },
83
+ capabilities: [docsRateLimit(), ...capabilities],
84
+ budget: {
85
+ tokens: 2e5,
86
+ capacity: {
87
+ concurrency: 2,
88
+ queue: {
89
+ maxPending: 8,
90
+ timeout: 12e4
91
+ }
92
+ }
93
+ }
94
+ });
95
+ }
96
+ //#endregion
97
+ export { docsPageFromBody as a, docsPageContextKey as i, docsAssistantModel as n, docsRateLimit as o, docsInstructions as r, defineDocsAssistant as t };
@@ -0,0 +1,27 @@
1
+ import { RateLimitIdentity } from "@vite-hub/agent/capabilities";
2
+ import { AgentCapabilityDefinition, WorkspaceAgentDefinition } from "@vite-hub/agent";
3
+ import { RateLimitWindow } from "@vite-hub/rate-limit";
4
+ //#region src/assistant-shared.d.ts
5
+ /** Invocation context key that holds the path of the page the reader has open. */
6
+ declare const docsPageContextKey = "docsPage";
7
+ /** Returns the page path from a chat request body, or an empty string when it is missing or not a plain path. */
8
+ declare function docsPageFromBody(body: Readonly<Record<string, unknown>>): string;
9
+ interface DocsRateLimitOptions {
10
+ /** Questions per window. Defaults to 30. */
11
+ limit?: number;
12
+ /** Defaults to `1h`. */
13
+ window?: RateLimitWindow;
14
+ /**
15
+ * Who shares one budget. Defaults to the whole site, because anonymous readers have no stable identity. Use `"ip"`
16
+ * with `trustedIpHeaders` behind a proxy that sets them, or a function of the Invocation context.
17
+ */
18
+ identity?: RateLimitIdentity;
19
+ trustedIpHeaders?: string[];
20
+ }
21
+ /**
22
+ * The assistant's question limit, with the id `docs-rate-limit` that replaces the default one. Counters live in process
23
+ * memory: they reset on restart and do not span processes.
24
+ */
25
+ declare function docsRateLimit(options?: DocsRateLimitOptions): AgentCapabilityDefinition;
26
+ //#endregion
27
+ export { docsRateLimit as i, docsPageContextKey as n, docsPageFromBody as r, DocsRateLimitOptions as t };
@@ -0,0 +1,11 @@
1
+ import { i as docsRateLimit, n as docsPageContextKey, r as docsPageFromBody, t as DocsRateLimitOptions } from "./assistant-shared-Dll_F_yy.js";
2
+ import { WorkspaceAgentDefinition } from "@vite-hub/agent";
3
+ //#region src/assistant-worker.d.ts
4
+ /**
5
+ * The docs assistant in a Worker build: the `docsAssistant` of Node.js with a model-backed Driver on the same ChatGPT
6
+ * plan, because a Worker cannot start Codex. The model reads the pages with the read-only Workspace shell, which
7
+ * Codex does not need: it has its own.
8
+ */
9
+ export declare const docsAssistant: WorkspaceAgentDefinition;
10
+ //#endregion
11
+ export { type DocsRateLimitOptions, docsPageContextKey, docsPageFromBody, docsRateLimit };