# Vite integrations and Provider Output

A Vite integration plugs a package into Vite dev and builds. Provider Output is what it generates for a host: routes, functions, bindings, workers, crons, or runtime files.

Your app code uses the package's documented server API, not generated internals.

## Configure the integration

### Nuxt

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  modules: ['vite-hub/nuxt'],
  vitehub: { host: 'node', agent: true, kv: true },
})
```

### Nitro

```ts [vite.config.ts]
import { defineConfig } from 'vite'
import { nitro } from 'nitro/vite'
import { vitehub } from 'vite-hub'

export default defineConfig({
  plugins: [
    vitehub({ host: 'node', agent: true, kv: true }),
    nitro(),
  ],
})
```

### Vite

```ts [vite.config.ts]
import { defineConfig } from 'vite'
import { vitehub } from 'vite-hub'

export default defineConfig({
  plugins: [
    vitehub({ host: 'node', agent: true, kv: true }),
  ],
})
```

Options that affect discovery, generated files, provider bindings, or deployment go in the ViteHub options in `nuxt.config.ts` or `vite.config.ts`. Options for one named item go in its Definition.

## Use Provider Output as build evidence

Inspect generated output to verify routes, bindings, or host wiring. Import it from application code only when the package documents a path such as `#vitehub/emails/<name>`.

| Need | Surface |
| --- | --- |
| Development and build wiring | The package Vite integration. |
| One named declaration | A Definition file. |
| Host deployment files | Provider Output from the integration. |
| Server code access | A documented package or generated import. |

Read [Definition discovery](https://vitehub.dev/docs/development/definition-discovery), [Runtime Helpers and stable imports](https://vitehub.dev/docs/reference/runtime-helpers), and [Provider Output](https://vitehub.dev/docs/reference/provider-output) for details.

## Persistent Node storage

Set `dataDir` in the ViteHub options to pick one local storage directory on a Node host:

### Nuxt

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  modules: ['vite-hub/nuxt'],
  vitehub: {
    host: "node",
    dataDir: "/var/lib/app",
    agent: true,
    console: { authorize: "./server/console-authorize.ts" },
    kv: true,
    blob: true,
    workspace: true,
  },
})
```

### Nitro

```ts [vite.config.ts]
import { defineConfig } from 'vite'
import { nitro } from 'nitro/vite'
import { vitehub } from 'vite-hub'

export default defineConfig({
  plugins: [
    vitehub({
      host: "node",
      dataDir: "/var/lib/app",
      agent: true,
      console: { authorize: "./server/console-authorize.ts" },
      kv: true,
      blob: true,
      workspace: true,
    }),
    nitro(),
  ],
})
```

### Vite

```ts [vite.config.ts]
import { defineConfig } from 'vite'
import { vitehub } from 'vite-hub'

export default defineConfig({
  plugins: [
    vitehub({
      host: "node",
      dataDir: "/var/lib/app",
      agent: true,
      console: { authorize: "./server/console-authorize.ts" },
      kv: true,
      blob: true,
      workspace: true,
    }),
  ],
})
```

Turned-on integrations use `agent-state.sqlite`, `agent-invocations.sqlite`, `kv/`, `blob/`, and `workspaces/` in this directory. Named local KV and Blob stores get their own subdirectories. Explicit paths and remote providers win, and disabled services stay off. Relative paths resolve from the working directory of the configuration process.

> **Warning**

The host must give a persistent, writable filesystem at this path. The option does not create a volume or make a temporary filesystem durable. Other hosts reject it. For hosted storage, keep your provider configuration.

To keep an existing storage location, use `agent.providers.state.url`, `agent.invocations.databaseUrl`, or each store's path option. Runtime database URL overrides still win. Changing the directory does not move stored data.

Without `dataDir`, a `file:` URL in `agent.providers.state.url` also moves the default Agent Invocation journal to `agent-invocations.sqlite` in the same directory. For example, `file:.data/agent-state.db` puts the journal at `.data/agent-invocations.sqlite`, so a Docker image needs only one writable volume. A relative path resolves from the working directory of the server, as it does for State. When `VITEHUB_AGENT_STATE_URL` replaces the State URL at runtime, the journal follows it. `VITEHUB_AGENT_INVOCATIONS_DATABASE_URL` still selects another file or a libSQL endpoint.

## Public URL

Set `publicUrl` in the ViteHub options to your deployed app's public origin. ViteHub uses it for Console invocation links, GitHub activity links, Chat error links, trigger `failed` events, telemetry `session_url` values, the default Auth `baseURL`, and the Connections OAuth callback and origin check:

### Nuxt

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  modules: ['vite-hub/nuxt'],
  vitehub: {
    host: "node",
    publicUrl: "https://agents.example.com",
  },
})
```

### Nitro

```ts [vite.config.ts]
import { defineConfig } from 'vite'
import { nitro } from 'nitro/vite'
import { vitehub } from 'vite-hub'

export default defineConfig({
  plugins: [
    vitehub({
      host: "node",
      publicUrl: "https://agents.example.com",
    }),
    nitro(),
  ],
})
```

### Vite

```ts [vite.config.ts]
import { defineConfig } from 'vite'
import { vitehub } from 'vite-hub'

export default defineConfig({
  plugins: [
    vitehub({
      host: "node",
      publicUrl: "https://agents.example.com",
    }),
  ],
})
```

Use a function when one build serves Agents from different origins. ViteHub calls it once per Agent at build time, with the name from its file. An explicit definition name gets the same origin at runtime. A shared definition found under several names gets no implicit alias:

### Nuxt

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  modules: ['vite-hub/nuxt'],
  vitehub: {
    host: "node",
    publicUrl: agent => agent === "bot" ? "https://agent.example.com" : "https://agent-dev.example.com",
  },
})
```

### Nitro

```ts [vite.config.ts]
import { defineConfig } from 'vite'
import { nitro } from 'nitro/vite'
import { vitehub } from 'vite-hub'

export default defineConfig({
  plugins: [
    vitehub({
      host: "node",
      publicUrl: agent => agent === "bot" ? "https://agent.example.com" : "https://agent-dev.example.com",
    }),
    nitro(),
  ],
})
```

### Vite

```ts [vite.config.ts]
import { defineConfig } from 'vite'
import { vitehub } from 'vite-hub'

export default defineConfig({
  plugins: [
    vitehub({
      host: "node",
      publicUrl: agent => agent === "bot" ? "https://agent.example.com" : "https://agent-dev.example.com",
    }),
  ],
})
```

Standalone provider bundles get the origin and app base from their own build configuration. Concurrent builds do not share URL constants.

- It must be an `http(s)` origin without a path. ViteHub adds the app base path.
- It applies to `vite build` only. In `vite dev`, Console links and Auth inside a request use the request origin.
- GitHub activity and evlog session links have no request-origin fallback. In development, set `activity.publicUrl` on the GitHub Channel or the evlog `sessionUrl` callback.
- Without `publicUrl`, links and Auth inside a request use the request origin. Links made outside a request are left out. Then the host or proxy in front of the app must send only requests for your own domains to it, because the `Host` header selects the origin. Set `publicUrl` for production builds.
- A configured origin always wins over the request Host. With the function form, request-bound code uses the origin of the Agent, else the configured origin whose host matches the request host, else the only configured origin. When the function gives several origins and the request host is none of them, Auth fails with `AUTH_R0022`, Connections returns `403` with `CONNECTIONS_ORIGIN_REJECTED`, and Console one-time links return `403`.

### Read the public URL in server code

`resolvePublicUrl()` from `vite-hub/runtime` returns the origin, or `undefined` when `publicUrl` is unset or in `vite dev`. It needs no request, so a Workflow step, a Schedule, or a Channel reply can build absolute links:

```ts
import { resolvePublicUrl } from "vite-hub/runtime"

const dashboardUrl = new URL("/dashboard", resolvePublicUrl() ?? "http://localhost:3000").href
```

With the function form, pass the Agent name: `resolvePublicUrl({ agentName: "bot" })`. In a request handler, pass `{ request }` to fall back to the request origin.

### Register webhooks at the public URL

When `publicUrl` is a string, `vitehub channels sync` and `vitehub channels history` use it as the default `--url`. A `--url` flag still wins. `channels sync --apply` needs `--confirm-origin` only for a `--url` you type. See [Synchronize Channel webhooks](https://vitehub.dev/docs/development/cli#synchronize-channel-webhooks).

### Serve a Cloudflare Worker on its custom domain

On the `cloudflare` host, a string `publicUrl` with an HTTPS DNS hostname outside `workers.dev` and no port also writes the custom domain into the generated `wrangler.json`. IP addresses, `localhost`, and invalid hostnames leave routing alone:

### Nuxt

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  modules: ['vite-hub/nuxt'],
  vitehub: {
    host: "cloudflare",
    publicUrl: process.env.APP_URL, // https://calories.example.com
  },
})
```

### Nitro

```ts [vite.config.ts]
import { defineConfig } from 'vite'
import { nitro } from 'nitro/vite'
import { vitehub } from 'vite-hub'

export default defineConfig({
  plugins: [
    vitehub({
      host: "cloudflare",
      publicUrl: process.env.APP_URL, // https://calories.example.com
    }),
    nitro(),
  ],
})
```

### Vite

```ts [vite.config.ts]
import { defineConfig } from 'vite'
import { vitehub } from 'vite-hub'

export default defineConfig({
  plugins: [
    vitehub({
      host: "cloudflare",
      publicUrl: process.env.APP_URL, // https://calories.example.com
    }),
  ],
})
```

```json [.output/server/wrangler.json]
{
  "routes": [{ "pattern": "calories.example.com", "custom_domain": true }],
  "workers_dev": false
}
```

ViteHub leaves routing to you when `nitro.cloudflare.wrangler` or the project `wrangler.json`, `wrangler.jsonc`, or `wrangler.toml` sets `route`, `routes`, or `workers_dev`. Nitro merges these keys from both places, so keep all routing in one place. Without `publicUrl`, or with a `workers.dev` origin, the Worker keeps its `workers.dev` host.


Use `agent.providers.state.url`, `agent.invocations.databaseUrl`, or each store's path option to preserve an existing location. Existing runtime database URL overrides still take precedence. Changing the directory does not migrate stored data.

<!-- vitehub-docs:section-links -->
## In this section

- [Local tools](https://vitehub.dev/raw/docs/development.md)
- Build state
  - [Provisioning](https://vitehub.dev/raw/docs/development/provisioning.md)
  - [Definition discovery](https://vitehub.dev/raw/docs/development/definition-discovery.md)
  - [Vite integrations and Provider Output](https://vitehub.dev/raw/docs/development/integrations-and-output.md) (this page)
  - [Generated files](https://vitehub.dev/raw/docs/development/generated-files.md)
- [Proof and recovery](https://vitehub.dev/raw/docs/development/testing.md)

Next: [RUNTIME_R0007](https://vitehub.dev/raw/docs/development/diagnostics/runtime_r0007.md)

All pages: [llms.txt](https://vitehub.dev/llms.txt)
