@vite-hub/docs 0.4.1 → 0.5.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 (75) hide show
  1. package/README.md +167 -7
  2. package/dist/{agent-copy-xPaWye_g.js → agent-copy-CY9_RkHN.js} +2 -3
  3. package/dist/{assistant-pages-BN7hNsSZ.js → assistant-pages-BbWfd69g.js} +3 -4
  4. package/dist/{assistant-shared-CWIKRtBv.d.ts → assistant-shared-BWeRcmVS.d.ts} +0 -2
  5. package/dist/{assistant-shared-WzButktj.js → assistant-shared-JcfjK-qg.js} +3 -4
  6. package/dist/assistant-worker.d.ts +1 -3
  7. package/dist/assistant-worker.js +2 -3
  8. package/dist/assistant.d.ts +1 -3
  9. package/dist/assistant.js +2 -3
  10. package/dist/{content-CPZGnn3S.js → content-C_WXjV3y.js} +60 -28
  11. package/dist/{draft-BjWmaiLn.js → draft-rOGhtXch.js} +3 -4
  12. package/dist/{error-diagnostics-B_ZOy7kF.js → error-diagnostics-Daz9oBJS.js} +65 -2
  13. package/dist/{files-UY4h1_36.js → files-BBoAGhhM.js} +1 -2
  14. package/dist/index.d.ts +7 -8
  15. package/dist/index.js +5 -6
  16. package/dist/link-checker-redirects.d.ts +0 -2
  17. package/dist/link-checker-redirects.js +2 -3
  18. package/dist/{manifest-ZdxLrcvt.js → manifest-Bti_WxDZ.js} +64 -30
  19. package/dist/{manifest-CMoxcwPm.d.ts → manifest-DJ2DyNue.d.ts} +1 -5
  20. package/dist/{page-Dx2JD3y1.d.ts → markdown-B97RuMXs.d.ts} +2 -27
  21. package/dist/{markdown-DUWnEMPp.js → markdown-BzZkYb24.js} +2 -3
  22. package/dist/navigation.d.ts +10 -6
  23. package/dist/navigation.js +23 -10
  24. package/dist/{nuxt-CAGpKl_-.d.ts → nuxt-CYAIBEHE.d.ts} +74 -8
  25. package/dist/nuxt.d.ts +3 -3
  26. package/dist/nuxt.js +1286 -89
  27. package/dist/page-B8_70-5D.d.ts +24 -0
  28. package/dist/{page-GPt09oex.js → page-DWsretqk.js} +20 -5
  29. package/dist/primitive-rail.d.ts +1 -10
  30. package/dist/primitive-rail.js +4 -10
  31. package/dist/{raw-BChwipz_.js → raw-CQukuLuj.js} +1 -2
  32. package/dist/{redirects-CmR1yu5A.js → redirects-BEFu4KLR.js} +35 -23
  33. package/dist/runnable.d.ts +33 -0
  34. package/dist/runnable.js +104 -0
  35. package/dist/runtime/app/components/DocsAsideLeftBody.vue +2 -8
  36. package/dist/runtime/app/components/DocsLearn.vue +215 -0
  37. package/dist/runtime/app/components/DocsLearnCodePre.vue +98 -0
  38. package/dist/runtime/app/components/DocsLearnFile.vue +21 -0
  39. package/dist/runtime/app/components/DocsPage.vue +11 -5
  40. package/dist/runtime/app/components/DocsPlayground.vue +117 -0
  41. package/dist/runtime/app/components/content/Example.vue +18 -49
  42. package/dist/runtime/app/components/content/PageList.vue +1 -5
  43. package/dist/runtime/app/layouts/docs.vue +36 -8
  44. package/dist/runtime/app/middleware/docs-layout.ts +2 -2
  45. package/dist/runtime/app/utils/docs-learn.ts +31 -0
  46. package/dist/runtime/app/utils/docs-playground.ts +3 -0
  47. package/dist/runtime/server/llms.d.ts +0 -2
  48. package/dist/runtime/server/llms.js +2 -3
  49. package/dist/runtime/server/markdown.d.ts +0 -7
  50. package/dist/runtime/server/markdown.js +11 -3
  51. package/dist/runtime/server/mcp.d.ts +0 -2
  52. package/dist/runtime/server/mcp.js +2 -3
  53. package/dist/runtime/server/page.d.ts +1 -3
  54. package/dist/runtime/server/page.js +4 -5
  55. package/dist/runtime/server/raw.d.ts +0 -2
  56. package/dist/runtime/server/raw.js +3 -11
  57. package/dist/runtime/server/search.d.ts +1 -3
  58. package/dist/runtime/server/search.js +4 -4
  59. package/dist/runtime/server/sitemap.d.ts +0 -2
  60. package/dist/runtime/server/sitemap.js +3 -5
  61. package/dist/runtime/server/trailing-slash.d.ts +0 -2
  62. package/dist/runtime/server/trailing-slash.js +1 -2
  63. package/dist/schema-CmSiwC4t.js +189 -0
  64. package/dist/server.d.ts +3 -4
  65. package/dist/server.js +4 -4
  66. package/dist/snapshot-worker.mjs +40 -0
  67. package/dist/steps-C3tGwhNK.d.ts +103 -0
  68. package/dist/steps-muDP1nYT.js +31 -0
  69. package/dist/{theme-BXyu4uFL.d.ts → theme-CgJRnVdT.d.ts} +0 -4
  70. package/dist/{theme-DzC8LtMH.js → theme-CxBzPBZ9.js} +2 -4
  71. package/dist/theme.d.ts +1 -1
  72. package/dist/theme.js +1 -2
  73. package/dist/{types-BhG6vGfG.d.ts → types-B6YlHil4.d.ts} +69 -8
  74. package/package.json +40 -32
  75. package/dist/schema-DwpXW0VZ.js +0 -98
package/README.md CHANGED
@@ -26,6 +26,8 @@ export default defineNuxtConfig({
26
26
 
27
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
28
 
29
+ The module turns off Nuxt's idle prefetch of lazy chunks in the whole app, such as the editor and the comark blocks. A page loads the chunks that it renders. A link loads its page and payload when the reader points at it or focuses it, unless the app sets `experimental.defaults.nuxtLink.prefetchOn`.
30
+
29
31
  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
32
 
31
33
  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`.
@@ -81,6 +83,25 @@ The module reads the `.md` and `.navigation.yml` files of every source through V
81
83
 
82
84
  `sources` configures the site pages, search, Markdown resources, and the pages that the docs assistant reads.
83
85
 
86
+ A page that the build generates, such as a list of the skills in a repository, is a `files()` Source. Its loader runs when the build reads the pages, so nothing writes the page into the content folder first:
87
+
88
+ ```ts
89
+ import { readdir } from "node:fs/promises"
90
+ import { files } from "vite-hub/source"
91
+
92
+ async function skillCatalog() {
93
+ const skills = await readdir("../skills")
94
+ return ["---", "title: All skills", "---", ...skills.map(name => `- \`${name}\``)].join("\n")
95
+ }
96
+
97
+ export default defineNuxtConfig({
98
+ docs: {
99
+ base: "/",
100
+ sources: ["content", { source: files({ "catalog.md": skillCatalog }), mount: "/skills" }],
101
+ },
102
+ })
103
+ ```
104
+
84
105
  ```ts
85
106
  import { github, glob } from "vite-hub/source"
86
107
 
@@ -115,12 +136,14 @@ The `components` module exports a default map of Comark tags to Vue components.
115
136
  | `credits` | None | Inline Markdown at the end of the page, such as `Icons from [Lucide](https://lucide.dev).` |
116
137
  | `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
138
  | `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. |
139
+ | `layout` | `article` | `article`, `tutorial`, `landing`, `home`, `playground`, or `learn`. See [Workspace pages](#workspace-pages). |
140
+ | `sidebar` | `true`, `collapsed` on `playground` and `learn` | `false` hides the left navigation on this page. `collapsed` starts it as a narrow column that the reader opens. |
141
+ | `toc` | `true`, `false` on `landing`, `home`, `playground`, and `learn` | `false` hides the "On this page" outline. |
121
142
  | `codePanel` | `false` | Tutorials only. Shows the files of the current step beside the prose. |
122
143
  | `tutorial` | None | Tutorials only. `project` or `quickstart`, for your own tutorial catalog. |
123
144
  | `navigation` | Listed | `false` keeps the page out of the sidebar. Or `{ title, order, group, kind, panel }`. See [Panels](#panels). |
145
+ | `examples`, `tabs`, `render`, `connect`, `port` | None | `layout: playground` only. See [Workspace pages](#workspace-pages). |
146
+ | `fixture`, `guide`, `lesson`, `preview`, `port` | None | `layout: learn` only. See [Workspace pages](#workspace-pages). |
124
147
  | `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
148
 
126
149
  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.
@@ -163,9 +186,10 @@ navigation.panel: true
163
186
  - `article` is prose with the outline on the right.
164
187
  - `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
188
  - `landing` is a wide Overview page without the outline. A section Overview ends with the catalog of every section.
189
+ - `playground` and `learn` fill the page with a code workspace. See [Workspace pages](#workspace-pages).
166
190
  - `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
191
 
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.
192
+ 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" })`. That page fills the viewport under the header and the window does not scroll: the root element of the page is exactly as tall as the viewport, so `height: 100%` inside it fills the screen, and content that is taller scrolls inside the page. A code panel tutorial starts collapsed too.
169
193
 
170
194
  ````md
171
195
  ---
@@ -183,6 +207,140 @@ console.log("hello")
183
207
  ::
184
208
  ````
185
209
 
210
+ ### Workspace pages
211
+
212
+ Two layouts fill the page with a code workspace: an editor, a file tree, a preview, and a terminal. The frontmatter of the page sets the workspace, so you add no app page and no config. On a phone or in a browser without WebContainer support, the page shows its own text instead.
213
+
214
+ `layout: playground` opens the apps of `examples`. Each example is a folder of the app, relative to the app root. Without `render`, the examples run in a WebContainer: it runs `npm install`, then `npm run dev`, and the preview shows the server on `port`.
215
+
216
+ ```md [content/docs/try/playground.md]
217
+ ---
218
+ title: Playground
219
+ layout: playground
220
+ examples:
221
+ - { id: hello, label: Hello, group: Servers, dir: examples/hello, open: message.txt }
222
+ - { id: clock, label: Clock, group: Servers, dir: examples/clock, open: server.mjs }
223
+ tabs:
224
+ - { value: messages, label: Messages }
225
+ ---
226
+
227
+ The text of the page shows when the workspace cannot run.
228
+ ```
229
+
230
+ | Field | Default | Use |
231
+ | --- | --- | --- |
232
+ | `examples` | Required | `{ id, label, group, description, dir, open, preview, readonly }`, in menu order. `id` is the `?example=` value. `group` is the heading in the examples menu. `open` is the file that the editor opens first. `preview` is the path that the preview opens. `readonly` lists text files of `dir` that the reader cannot edit. With more than one example and no `?example=`, the page opens on a start screen. |
233
+ | `tabs` | None | `{ value, label }`: more output tabs. The tab `messages` renders `app/components/playground/PlaygroundTabMessages.vue`, which reads the workspace with `useWorkspace()` from `@vite-hub/ui/workspace`. A missing component fails the build with `DOCS_WORKSPACE_TAB_MISSING`. |
234
+ | `render` | None | A module relative to the app root, such as `app/playground/render.ts`. The page runs its default export on the files 200 ms after each edit, and shows the HTML in an Output tab. No WebContainer starts, so the page works on every device. |
235
+ | `connect` | None | Accounts that the reader can connect in a Connect tab: `anthropic`, `github`, `netlify`, `openai`, or `vercel`. Each one takes a token in the tab. Any other name, such as `cloudflare`, which needs a relay, fails the build with `DOCS_CONTENT_INVALID`. A token stays in the browser tab, and the app gets it as an environment variable of the dev server, such as `GITHUB_TOKEN`. Not with `render`. |
236
+ | `port` | `3000` | The port of the dev server. Not with `render`. |
237
+
238
+ ```ts [app/playground/render.ts]
239
+ import type { DocsRenderFunction } from "@vite-hub/docs/runnable"
240
+
241
+ const render: DocsRenderFunction = (files) => {
242
+ const html = files["index.html"]
243
+ if (html === undefined) return { html: "", issues: [{ message: "Create index.html." }] }
244
+ return { html }
245
+ }
246
+
247
+ export default render
248
+ ```
249
+
250
+ #### Read-only files, binary files, and issues
251
+
252
+ `readonly` marks files of an example that the reader can read but not edit, such as a model that a build trained. The editor refuses typing in them and shows "Read-only". `useWorkspace().setFile` in a tab component can still change them. A path that is not a text file of `dir` fails the build with `DOCS_WORKSPACE_READONLY_MISSING`.
253
+
254
+ ```md [content/docs/try/models.md]
255
+ ---
256
+ title: Models
257
+ layout: playground
258
+ render: app/playground/render.ts
259
+ examples:
260
+ - { id: recipes, label: Recipes, dir: examples/recipes, open: input.txt, readonly: [recipes.model.ts] }
261
+ ---
262
+ ```
263
+
264
+ A file of `dir` that is not valid UTF-8, such as `weights.bin`, is a binary asset. It needs no frontmatter. The tree and the editor never show it. The page module carries it as base64 and turns it back into bytes when it loads. A `render` function reads it from `example.assets`, and a WebContainer example mounts it next to the files. An issue with `file` shows `file:line`, and a click opens that file.
265
+
266
+ ```ts [app/playground/render.ts]
267
+ import type { DocsRenderFunction } from "@vite-hub/docs/runnable"
268
+
269
+ const render: DocsRenderFunction = (files, { example }) => {
270
+ const weights = example.assets?.["weights.bin"]
271
+ if (!weights) return { html: "", issues: [{ message: "Train the model first.", file: "recipes.model.ts", line: 1 }] }
272
+ return { html: `<p>${files["input.txt"] ?? ""}: ${weights.byteLength} bytes of weights</p>` }
273
+ }
274
+
275
+ export default render
276
+ ```
277
+
278
+ `layout: learn` and `#build/playground-templates.mjs` read the text files of a fixture only.
279
+
280
+ `layout: learn` is a lesson. Its `::tutorial-step` blocks become the steps of the workspace, and the guide shows the text of the current step. `fixture` is a folder in the `runnable.fixtures` folder (`fixtures` by default) with the app after the last step, as for [runnable lessons](#runnable-lessons-and-examples). Each step loads the files of the fixture that its code blocks name. A file name in inline code, such as `` `greeting.mjs` ``, opens the file. A file code block gets "Show in editor", and a `curl` block gets "Run in workspace". `?step=2` opens step 2, and Solve writes the files of the step.
281
+
282
+ ````md [content/docs/try/first-server.md]
283
+ ---
284
+ title: Your first server
285
+ layout: learn
286
+ fixture: first-server
287
+ ---
288
+
289
+ ::tutorial-step{title="Write a greeting"}
290
+ ## Write a greeting
291
+
292
+ ```js [greeting.mjs]
293
+ export default () => "Hello."
294
+ ```
295
+ ::
296
+ ````
297
+
298
+ | Field | Default | Use |
299
+ | --- | --- | --- |
300
+ | `fixture` | Required | The folder of the app after the last step. |
301
+ | `guide` | `side` | `side` puts the step text in a column beside the code, `top` puts it over the code. |
302
+ | `lesson` | This page | The URL of another docs page whose `::tutorial-step` blocks are the steps, such as a get started guide, so the prose has one source. The page then has a canonical link to that page. |
303
+ | `preview` | `/` | The path that the preview opens. |
304
+ | `port` | `3000` | The port of the dev server. |
305
+
306
+ A WebContainer runs only in a cross-origin isolated page. The module lists every `learn` page and every `playground` page without `render`, and passes them to `vite-hub/nuxt` as `webContainer.routes`, in either module order. The app needs `vite-hub/nuxt` and `@vite-hub/web-container`; without them, the build fails with `DOCS_WORKSPACE_VITEHUB_MISSING`. A `render` page stays a plain page. A missing `dir`, `fixture`, or `render` file fails the build with `DOCS_WORKSPACE_DIR_MISSING` or `DOCS_WORKSPACE_RENDER_MISSING`, and a `readonly` path that is not a text file of its `dir` with `DOCS_WORKSPACE_READONLY_MISSING`. Each workspace page gets an id from its path, such as `learn-first-agent` for `/learn/first-agent`, and the id names its snapshots, its examples, and its zip. Two pages with one id, such as `/docs/a/b` and `/docs/a-b`, fail the build with `DOCS_WORKSPACE_ID_COLLISION`, and so does a page id that matches a `slug` in `runnable.lessons` or an `id` in `runnable.examples`.
307
+
308
+ The frontmatter is the one source of truth for workspace pages. `runnable.lessons` and `runnable.examples` stay for app pages that read `#build/runnable-tutorials.mjs` and `#build/playground-templates.mjs`, such as a custom `/learn/[slug]` page. Both use one snapshot build: an example with the dependencies of a lesson mounts the snapshot of that lesson, and `nuxt build` writes the snapshots of workspace pages as it does for `runnable`. A `layout: tutorial` page with `codePanel` works as before.
309
+
310
+ ### Runnable lessons and examples
311
+
312
+ `runnable` runs lessons and starting apps in the reader's browser, in a WebContainer. Each one is an app in the fixtures folder. The page stays the lesson text, and the fixture is the app after the last step: every file code block of a `::tutorial-step` must equal the fixture file.
313
+
314
+ ```ts [nuxt.config.ts]
315
+ export default defineNuxtConfig({
316
+ modules: ["@vite-hub/docs/nuxt"],
317
+ docs: {
318
+ runnable: {
319
+ lessons: [{ slug: "first-route", page: "/docs/first-route", fixture: "first-route" }],
320
+ examples: [{ id: "kv", label: "KV", description: "Store and read a value.", fixture: "kv", open: "server/api/kv.post.ts", preview: "/api/kv" }],
321
+ },
322
+ },
323
+ })
324
+ ```
325
+
326
+ | Option | Default | Description |
327
+ | --- | --- | --- |
328
+ | `fixtures` | `fixtures` | The folder of the apps, relative to the app root. |
329
+ | `lessons` | `[]` | `{ slug, page, fixture }`. `slug` names the lesson and its snapshot. `page` is the URL of a docs page with `::tutorial-step` blocks, from `dir` or from `sources`. |
330
+ | `examples` | `[]` | `{ id, label, description, fixture, open, preview }`, in menu order. `open` is the file that the editor opens first, and `preview` is the path that the preview opens. |
331
+ | `start` | None | The URL of a docs page whose code blocks give a file before the step that writes it, such as an Installation page. Without it, that file does not exist before its step. |
332
+ | `pnpmWorkspace` | None | The folder of `pnpm-workspace.yaml`, relative to the app root. Set it when fixtures use `catalog:` or `workspace:` specifiers: the build rewrites them to npm versions, and packs the workspace packages that a fixture uses into its snapshot. The packages are the folders that its `packages` patterns match, as pnpm finds them. |
333
+
334
+ The build writes three modules that app pages import, and does not add pages:
335
+
336
+ - `#build/runnable-tutorials.mjs` exports `runnableTutorials`: the files before step 1 and the files of each step.
337
+ - `#build/playground-templates.mjs` exports `playgroundTemplates`: the files of each example.
338
+ - `#build/learn-facts.mjs` exports `learnFacts`: the step count and reading time of each `layout: tutorial` and `layout: learn` page, by URL.
339
+
340
+ Their types and the browser helpers, such as `tutorialStepFiles()`, come from `@vite-hub/docs/runnable`.
341
+
342
+ `nuxt build` also writes a `node_modules` snapshot of each fixture to `/_tutorials/snapshots/<slug>.<hash>.<part>.bin` under the app base, so the workspace skips `npm install`. The snapshot holds the `dependencies` of the fixture, so the package that its `dev` script runs, such as `vite`, must be in `dependencies`. An example with the dependencies of a lesson uses the snapshot of that lesson. The npm lockfile `<fixture>.package-lock.json` beside each fixture pins the install. The build writes it when it is missing or no longer matches the dependencies: commit it. `nuxi prepare` never builds snapshots. `nuxt dev` reuses the last ones while the dependencies match, and builds them with `TUTORIAL_SNAPSHOTS=1`. `TUTORIAL_SNAPSHOTS=0` skips them in a build, and the workspace runs `npm install`. An app page that boots a WebContainer needs cross-origin isolation: list its routes in `vitehub.webContainer.routes`. Workspace pages get theirs from the module.
343
+
186
344
  ## Customize
187
345
 
188
346
  Most changes are options in `nuxt.config.ts`:
@@ -190,7 +348,7 @@ Most changes are options in `nuxt.config.ts`:
190
348
  | Option | Default | Use |
191
349
  | --- | --- | --- |
192
350
  | `dir` | `content` | Folder of Markdown pages. |
193
- | `base` | `/docs`, or `/` without a `docs/` folder | URL prefix whose folders are sections. |
351
+ | `base` | `/docs`, or `/` without a `docs/` folder in `dir` | URL prefix whose folders are sections. With `sources`, the default is always `/docs`. If all pages are outside the default base, setup warns with `DOCS_BASE_EMPTY`. Set `base: '/docs'` to keep them standalone without the warning. |
194
352
  | `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
353
  | `categories` | `[]` | Order of section categories in the rail and the catalog. |
196
354
  | `railExclude` | `[]` | Categories that the catalog lists but the rail leaves out. |
@@ -305,6 +463,8 @@ The design follows the comark-ui site on top of the ViteHub design system (`@vit
305
463
  - `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`.
306
464
  - 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.
307
465
 
466
+ If a font provider fails, the build reports the error and continues. The browser can use the fallback fonts. To fail the build instead, set `fonts.throwOnError: true` in `nuxt.config.ts`.
467
+
308
468
  In an app with its own `app.vue`, the theme stays on the docs pages:
309
469
 
310
470
  - The theme's CSS applies below the `vh-docs` class. The docs layouts put it on `<html>` on docs pages only.
@@ -355,14 +515,14 @@ The module sets the `comments` option of `vite-hub/nuxt`, which turns on the Dat
355
515
  - `@` suggests the users of ViteHub Auth when the app has Auth, else the people who wrote in the threads.
356
516
  - The Console's Comments section lists the threads.
357
517
 
358
- 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`.
518
+ Turn it off with `docs: { comments: false }`. The `comments` option of `vite-hub/nuxt` wins: when it turns Comments on, setup warns with `DOCS_COMMENTS_OFF_IGNORED`. 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`.
359
519
 
360
520
  ## Docs assistant
361
521
 
362
522
  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.
363
523
 
364
524
  ```sh
365
- 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
525
+ pnpm add vite-hub @vite-hub/agent @vite-hub/workflow @vite-hub/connections @vite-hub/database drizzle-orm@1.0.0-rc.6 @openai/codex
366
526
  ```
367
527
 
368
528
  ```ts
@@ -1,6 +1,6 @@
1
1
  import { docsManifestPages, docsRawSectionLinks } from "./navigation.js";
2
- import { t as toRawMarkdown } from "./raw-BChwipz_.js";
3
- //#region src/agent-copy.ts
2
+ import { t as toRawMarkdown } from "./raw-CQukuLuj.js";
3
+ // 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
6
6
  * links of its section. `siteUrl` is the public origin with the app base, such as `https://docs.example.com/portal`.
@@ -29,5 +29,4 @@ function docsAgentPages(manifest) {
29
29
  }
30
30
  return sources;
31
31
  }
32
- //#endregion
33
32
  export { docsAgentPages as n, docsContentSource as r, docsAgentCopy as t };
@@ -1,8 +1,8 @@
1
+ import { t as docsErrorDiagnostics } from "./error-diagnostics-Daz9oBJS.js";
1
2
  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";
3
+ import { n as readDocsFile, t as hasDocsFile } from "./files-BBoAGhhM.js";
4
4
  import manifest from "#docs/manifest";
5
- //#region src/runtime/assistant-pages.ts
5
+ // src/runtime/assistant-pages.ts
6
6
  /**
7
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
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.
@@ -33,5 +33,4 @@ async function readDocsAssistantPage(path) {
33
33
  if (text === null) throw docsErrorDiagnostics.DOCS_ASSISTANT_PAGE_MISSING({ path });
34
34
  return text;
35
35
  }
36
- //#endregion
37
36
  export { listDocsAssistantPagePaths, readDocsAssistantPage };
@@ -2,7 +2,6 @@ import { RateLimitIdentity } from "@vite-hub/agent/capabilities";
2
2
  import { AgentCapabilityDefinition, WorkspaceAgentDefinition } from "@vite-hub/agent";
3
3
  import { RateLimitPolicy } from "@vite-hub/rate-limit";
4
4
  import "@vite-hub/workspace";
5
- //#region src/assistant-shared.d.ts
6
5
  /** Invocation context key that holds the path of the page the reader has open. */
7
6
  declare const docsPageContextKey = "docsPage";
8
7
  /** Returns the page path from a chat request body, or an empty string when it is missing or not a plain path. */
@@ -24,5 +23,4 @@ interface DocsRateLimitOptions {
24
23
  * memory: they reset on restart and do not span processes.
25
24
  */
26
25
  declare function docsRateLimit(options?: DocsRateLimitOptions): AgentCapabilityDefinition;
27
- //#endregion
28
26
  export { docsRateLimit as i, docsPageContextKey as n, docsPageFromBody as r, DocsRateLimitOptions as t };
@@ -5,7 +5,7 @@ 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
7
  import { custom } from "@vite-hub/workspace";
8
- //#region src/assistant-shared.ts
8
+ // 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";
11
11
  const docsRules = `You answer questions from readers of this documentation site.
@@ -66,10 +66,10 @@ function docsPagesSource() {
66
66
  name: "docs-pages",
67
67
  materialize: "lazy",
68
68
  cache: false,
69
- getKeys: async () => (await import("./assistant-pages-BN7hNsSZ.js")).listDocsAssistantPagePaths(),
69
+ getKeys: async () => (await import("./assistant-pages-BbWfd69g.js")).listDocsAssistantPagePaths(),
70
70
  getItem: async (key) => ({
71
71
  key,
72
- content: await (await import("./assistant-pages-BN7hNsSZ.js")).readDocsAssistantPage(key),
72
+ content: await (await import("./assistant-pages-BbWfd69g.js")).readDocsAssistantPage(key),
73
73
  mediaType: "text/markdown"
74
74
  })
75
75
  });
@@ -109,5 +109,4 @@ function defineDocsAssistant(driver, capabilities = []) {
109
109
  }
110
110
  });
111
111
  }
112
- //#endregion
113
112
  export { docsPageFromBody as a, docsPageContextKey as i, docsAssistantModel as n, docsRateLimit as o, docsInstructions as r, defineDocsAssistant as t };
@@ -1,11 +1,9 @@
1
- import { i as docsRateLimit, n as docsPageContextKey, r as docsPageFromBody, t as DocsRateLimitOptions } from "./assistant-shared-CWIKRtBv.js";
1
+ import { i as docsRateLimit, n as docsPageContextKey, r as docsPageFromBody, t as DocsRateLimitOptions } from "./assistant-shared-BWeRcmVS.js";
2
2
  import { WorkspaceAgentDefinition } from "@vite-hub/agent";
3
- //#region src/assistant-worker.d.ts
4
3
  /**
5
4
  * The docs assistant in a Worker build: the `docsAssistant` of Node.js with a model-backed Driver on the same ChatGPT
6
5
  * plan, because a Worker cannot start Codex. The model reads the pages with the read-only Workspace shell, which
7
6
  * Codex does not need: it has its own.
8
7
  */
9
8
  export declare const docsAssistant: WorkspaceAgentDefinition;
10
- //#endregion
11
9
  export { type DocsRateLimitOptions, docsPageContextKey, docsPageFromBody, docsRateLimit };
@@ -1,7 +1,7 @@
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";
1
+ import { a as docsPageFromBody, i as docsPageContextKey, n as docsAssistantModel, o as docsRateLimit, r as docsInstructions, t as defineDocsAssistant } from "./assistant-shared-JcfjK-qg.js";
2
2
  import { workspaceShell } from "@vite-hub/agent/capabilities";
3
3
  import { chatgpt } from "@vite-hub/gateways";
4
- //#region src/assistant-worker.ts
4
+ // src/assistant-worker.ts
5
5
  /**
6
6
  * The docs assistant in a Worker build: the `docsAssistant` of Node.js with a model-backed Driver on the same ChatGPT
7
7
  * plan, because a Worker cannot start Codex. The model reads the pages with the read-only Workspace shell, which
@@ -12,5 +12,4 @@ const docsAssistant = defineDocsAssistant({
12
12
  gateway: chatgpt(),
13
13
  instructions: docsInstructions
14
14
  }, [workspaceShell()]);
15
- //#endregion
16
15
  export { docsAssistant, docsPageContextKey, docsPageFromBody, docsRateLimit };
@@ -1,6 +1,5 @@
1
- import { i as docsRateLimit, n as docsPageContextKey, r as docsPageFromBody, t as DocsRateLimitOptions } from "./assistant-shared-CWIKRtBv.js";
1
+ import { i as docsRateLimit, n as docsPageContextKey, r as docsPageFromBody, t as DocsRateLimitOptions } from "./assistant-shared-BWeRcmVS.js";
2
2
  import { WorkspaceAgentDefinition } from "@vite-hub/agent";
3
- //#region src/assistant.d.ts
4
3
  /**
5
4
  * The docs assistant: a ViteHub Agent that answers from the site's Markdown pages, on the site owner's ChatGPT plan
6
5
  * through the `chatgpt` Connection, so no API key is needed.
@@ -10,5 +9,4 @@ import { WorkspaceAgentDefinition } from "@vite-hub/agent";
10
9
  * `defineAgent({ extends: docsAssistant, ... })` to change any part.
11
10
  */
12
11
  export declare const docsAssistant: WorkspaceAgentDefinition;
13
- //#endregion
14
12
  export { type DocsRateLimitOptions, docsPageContextKey, docsPageFromBody, docsRateLimit };
package/dist/assistant.js CHANGED
@@ -1,7 +1,7 @@
1
- import { a as docsPageFromBody, i as docsPageContextKey, o as docsRateLimit, r as docsInstructions, t as defineDocsAssistant } from "./assistant-shared-WzButktj.js";
1
+ import { a as docsPageFromBody, i as docsPageContextKey, o as docsRateLimit, r as docsInstructions, t as defineDocsAssistant } from "./assistant-shared-JcfjK-qg.js";
2
2
  import { chatgpt } from "@vite-hub/gateways";
3
3
  import { codexDriver } from "@vite-hub/agent";
4
- //#region src/assistant.ts
4
+ // src/assistant.ts
5
5
  /**
6
6
  * The docs assistant: a ViteHub Agent that answers from the site's Markdown pages, on the site owner's ChatGPT plan
7
7
  * through the `chatgpt` Connection, so no API key is needed.
@@ -15,5 +15,4 @@ const docsAssistant = defineDocsAssistant(codexDriver({
15
15
  permissions: "allow-edits-unattended",
16
16
  instructions: docsInstructions
17
17
  }));
18
- //#endregion
19
18
  export { docsAssistant, docsPageContextKey, docsPageFromBody, docsRateLimit };
@@ -1,7 +1,7 @@
1
- import { docsManifestPages, docsRawPath, findDocsPage } from "./navigation.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";
1
+ import { n as docsAgentPages, r as docsContentSource, t as docsAgentCopy } from "./agent-copy-CY9_RkHN.js";
2
+ import { i as docsMarkdown, n as docsDocumentOf, r as docsImageSizes, t as createDocsParser } from "./markdown-BzZkYb24.js";
3
+ import { docsAppPath, docsManifestPages, docsRawPath } from "./navigation.js";
4
+ import { n as readDocsFile } from "./files-BBoAGhhM.js";
5
5
  import "node:module";
6
6
  import { defu } from "defu";
7
7
  import { contentSource, defineContent } from "@vite-hub/content";
@@ -11,7 +11,7 @@ import { useRuntimeConfig } from "nitro/runtime-config";
11
11
  import examples from "#docs/example-sources";
12
12
  import imageSizes from "#docs/image-sizes";
13
13
  import parser, { githubRepo } from "#docs/parser";
14
- //#region \0rolldown/runtime.js
14
+ // \0rolldown/runtime.js
15
15
  var __defProp = Object.defineProperty;
16
16
  var __exportAll = (all, no_symbols) => {
17
17
  let target = {};
@@ -22,8 +22,7 @@ var __exportAll = (all, no_symbols) => {
22
22
  if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
23
23
  return target;
24
24
  };
25
- //#endregion
26
- //#region src/runtime/documents.ts
25
+ // src/runtime/documents.ts
27
26
  const references = githubRepo ? { github: { references: { repo: githubRepo } } } : {};
28
27
  /**
29
28
  * The one parser configuration of the site. The runtime Content of the page route and search, drafts, and credits parse
@@ -36,13 +35,8 @@ const docsParserOptions = {
36
35
  plugins: [...parser.plugins ?? [], docsImageSizes(imageSizes)]
37
36
  };
38
37
  const parseDocsDocument = createDocsParser(docsParserOptions);
39
- //#endregion
40
- //#region src/runtime/content.ts
41
- var content_exports = /* @__PURE__ */ __exportAll({
42
- docsContent: () => docsContent,
43
- readDocsPage: () => readDocsPage,
44
- readDocsRawCopy: () => readDocsRawCopy
45
- });
38
+ // src/runtime/content.ts
39
+ var content_exports = /* @__PURE__ */ __exportAll({ docsMarkdownContent: () => docsMarkdownContent });
46
40
  /** One docs folder as a Content Source, from the production bundle or development server assets. */
47
41
  function bundledPages(base) {
48
42
  const read = (key) => readDocsFile(base, key);
@@ -53,26 +47,65 @@ function bundledPages(base) {
53
47
  };
54
48
  }
55
49
  let content;
50
+ let rawPages;
51
+ function docsRawPage(path) {
52
+ rawPages ??= new Map(docsManifestPages(manifest).map((page) => [docsRawPath(page.path), page]));
53
+ return rawPages.get(path);
54
+ }
55
+ function docsSiteUrl(config) {
56
+ return `${config.site.url}${config.appBase.replace(/\/+$/, "")}`;
57
+ }
56
58
  /** The agent copy of a page from its file. The `rawMarkdown` option runs at build time, and the build keeps each page that it changed. */
57
59
  async function docsPageCopy(page, text, siteUrl) {
58
60
  const rewritten = await readDocsFile("docs-agent", `${docsContentSource(page)}/${page.file}`);
59
61
  return docsAgentCopy(manifest, page, rewritten === null ? text : String(rewritten), siteUrl);
60
62
  }
61
- /**
62
- * The agent copy at a raw path such as `/raw/docs/kv.md`, or null. Content finds a Source page by its URL only after it lists every file,
63
- * which costs a cold Worker about 250 ms on a large site. The manifest knows the file of each URL, so this reads the
64
- * one file and renders it with the copy that Content serves in `llms-full.txt` and the MCP server.
65
- */
66
- async function readDocsRawCopy(rawPath) {
67
- const path = rawPath.replace(/^\/raw/, "").replace(/\.md$/, "");
68
- const found = findDocsPage(manifest, path === "/index" ? "/" : path);
69
- if (!found || docsRawPath(found.page.path) !== rawPath) return null;
70
- const config = useRuntimeConfig().public.docs;
71
- const text = await readDocsFile(found.page.source ?? "docs", found.page.file);
63
+ async function readDocsPageCopy(page) {
64
+ const text = await readDocsFile(page.source ?? "docs", page.file);
72
65
  if (text === null) return null;
73
- const copy = await docsPageCopy(found.page, String(text), `${config.site.url}${config.appBase.replace(/\/+$/, "")}`);
66
+ const copy = await docsPageCopy(page, text, docsSiteUrl(useRuntimeConfig().public.docs));
74
67
  return `${copy.markdown}${copy.footer}`;
75
68
  }
69
+ /** Read an exact manifest URL without listing or parsing the Content Sources. */
70
+ async function readDocsRawCopy(pathname) {
71
+ const prefix = docsAppPath("/raw/", useRuntimeConfig().public.docs.appBase);
72
+ if (!pathname.startsWith(prefix)) return null;
73
+ let rawPath;
74
+ try {
75
+ rawPath = `/raw/${decodeURIComponent(pathname.slice(prefix.length))}`;
76
+ } catch (error) {
77
+ if (!(error instanceof URIError)) throw error;
78
+ return null;
79
+ }
80
+ const page = docsRawPage(rawPath);
81
+ return page ? await readDocsPageCopy(page) : null;
82
+ }
83
+ /** Use the manifest for canonical Docs twins and Content for other page lookups. */
84
+ function docsMarkdownContent(raw = false) {
85
+ const runtime = docsContent();
86
+ const base = useRuntimeConfig().public.docs.appBase.replace(/\/+$/, "");
87
+ const relativePath = (path) => base && path.startsWith(`${base}/`) ? path.slice(base.length) : path;
88
+ function twin(path) {
89
+ const relative = relativePath(path);
90
+ try {
91
+ return docsRawPage(`/raw${decodeURI(relative)}`);
92
+ } catch (error) {
93
+ if (!(error instanceof URIError)) throw error;
94
+ }
95
+ }
96
+ return {
97
+ seo: runtime.seo,
98
+ async markdown(path, options) {
99
+ if (raw) return await readDocsRawCopy(path);
100
+ const page = twin(path);
101
+ return page ? await readDocsPageCopy(page) : await runtime.markdown(path, options);
102
+ },
103
+ async hasMarkdown(path) {
104
+ const page = twin(path);
105
+ return page ? await readDocsFile(page.source ?? "docs", page.file) !== null : await runtime.hasMarkdown(path);
106
+ }
107
+ };
108
+ }
76
109
  /**
77
110
  * The docs pages as Content, parsed with the site's parser. The first read creates it. Each page has its URL from the
78
111
  * manifest, so Content serves the agent files: the `/raw/<page>.md` copies, `llms.txt`, `llms-full.txt`, `sitemap.md`,
@@ -80,7 +113,7 @@ async function readDocsRawCopy(rawPath) {
80
113
  */
81
114
  function docsContent() {
82
115
  const config = useRuntimeConfig().public.docs;
83
- const siteUrl = `${config.site.url}${config.appBase.replace(/\/+$/, "")}`;
116
+ const siteUrl = docsSiteUrl(config);
84
117
  if (content?.siteUrl === siteUrl) return content.runtime;
85
118
  const pages = docsAgentPages(manifest);
86
119
  const assets = new Map(docsManifestPages(manifest).map((page) => [docsContentSource(page), page.source ?? "docs"]));
@@ -137,5 +170,4 @@ async function readDocsPage(page) {
137
170
  const document = await docsContent().get(`${docsContentSource(page)}/${page.file}`, { fresh: import.meta.dev });
138
171
  return document ? docsDocumentOf(document) : null;
139
172
  }
140
- //#endregion
141
173
  export { parseDocsDocument as a, readDocsRawCopy as i, docsContent as n, readDocsPage as r, content_exports as t };
@@ -1,7 +1,7 @@
1
1
  import { docsSectionForPath, findDocsPage, normalizeDocsPath } from "./navigation.js";
2
- import { i as docsPageSchema, t as docsFrontmatter } from "./schema-DwpXW0VZ.js";
3
- import { i as docsPageResponse, n as docsPageOf } from "./page-GPt09oex.js";
4
- //#region src/draft.ts
2
+ import { i as docsPageResponse, n as docsPageOf } from "./page-DWsretqk.js";
3
+ import { i as docsPageSchema, t as docsFrontmatter } from "./schema-CmSiwC4t.js";
4
+ // 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.
7
7
  * A preview frame shows the draft of its one document, also before the page is published. A preview cookie shows the
@@ -41,5 +41,4 @@ function pageId(manifest, path, section) {
41
41
  if (!section) return "";
42
42
  return path === section ? "index" : path.slice(section.length + 1);
43
43
  }
44
- //#endregion
45
44
  export { docsDraftResponse };