Skip to content

Instrument your app ​

Veya's white-box channel comes from three packages:

  • @veya/vite-plugin — injects the runtime in development and annotates JSX host elements with source locations.
  • @veya/runtime — the in-page sensors and transport.
  • @veya/react — the provider, component boundary, state bridge and error boundary.

Everything here is development only. Do not ship @veya/* or the virtual runtime module in a production build.

Requirements ​

  • Vite+ (Vite) and React 19.
  • The app must be served by the Vite dev server. The plugin uses apply: "serve".
  • The app must be on the same machine as the running Veya app, with the hub reachable at ws://127.0.0.1:7317/v1/runtime.

Only Vite + React apps get the white-box channel in v0.1. A page without the runtime does not create a session; either product window can load it, but there is no evidence to inspect.

1. Add the Vite plugin ​

ts
import { defineConfig } from "vite-plus";
import { veyaPlugin } from "@veya/vite-plugin";

export default defineConfig({
  plugins: [
    veyaPlugin({
      hubUrl: "ws://127.0.0.1:7317/v1/runtime",
      appName: "my-app",
    }),
  ],
});

veyaPlugin accepts:

OptionMeaning
hubUrlRuntime WebSocket URL. Without it, the runtime collects locally but sends nothing to the hub.
appNameReported in session.hello, useful when several apps share a hub.
enabledfalse disables JSX annotation and index injection. Defaults to true.

The plugin injects the runtime client into index.html and adds source annotations during the dev transform.

2. Create the runtime and provide it ​

The plugin's virtual module starts the runtime and exports it:

tsx
// src/main.tsx
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { VeyaProvider } from "@veya/react";
import runtime from "virtual:veya-client";
import { App } from "./App.tsx";

createRoot(document.getElementById("root") ?? document.body).render(
  <StrictMode>
    <VeyaProvider runtime={runtime}>
      <App />
    </VeyaProvider>
  </StrictMode>,
);

Declare the virtual module for TypeScript:

ts
// src/virtual.d.ts
declare module "virtual:veya-client" {
  import { type VeyaRuntime } from "@veya/runtime";

  const runtime: VeyaRuntime;

  export default runtime;
}

VeyaProvider is required by AgentComponent, useVeyaState and VeyaErrorBoundary. It does not start the runtime; the virtual client does.

Development-only import

virtual:veya-client is provided by the plugin in serve mode. A production build that imports it will not resolve. Keep the import in a development entry, or wire the runtime manually for a dev-only build. Instrumentation is not part of the shipped product.

3. Mark semantic components ​

Wrap the parts an agent should reason about:

tsx
import { AgentComponent } from "@veya/react";

<AgentComponent
  id="dashboard.revenue"
  name="RevenueChart"
  purpose="Show the revenue trend for the current quarter"
  productRole="content"
>
  <RevenueChart />
</AgentComponent>;

AgentComponent renders a div wrapper and registers the node with the runtime. The wrapper participates in layout, so place it where a block container is acceptable.

PropMeaning
idSemantic identity. Events and commands refer to this id.
nameComponent name shown in the snapshot. Defaults to id.
purposeWhy the component exists, in one sentence.
productRoleprimary-action, navigation, content, status or form.

Use stable, product-level ids. project.create or dashboard.revenue is useful; div-17 is not.

4. Report business state ​

tsx
import { useVeyaState } from "@veya/react";

useVeyaState("dashboard", {
  projectCount: projects.length,
  dialogOpen,
});

The first argument is the state id; the second is a JSON-serialisable value. Veya diffs the value and emits state.changed only for the keys that moved. Dates, maps, sets and cycles are sanitised, not thrown.

Read it back with veya_state and a dotted path:

json
{
  "tool": "veya_state",
  "arguments": { "path": "dashboard.projectCount" }
}

5. Add an error boundary ​

tsx
import { VeyaErrorBoundary } from "@veya/react";

<VeyaErrorBoundary
  id="dashboard.revenue"
  fallback={<p>Revenue unavailable.</p>}
>
  <RevenueChart />
</VeyaErrorBoundary>;

A caught render error is emitted as error.uncaught with the boundary's id, so signal R001 can attach the component and its source location.

6. Annotate controls and status ​

AgentComponent covers regions. For individual controls, add data-veya-id directly:

tsx
<button
  type="button"
  data-veya-id="project.create"
  onClick={() => setDialogOpen(true)}
>
  Create project
</button>

data-veya-id makes the control addressable by commands and interaction events. It does not create a component node by itself; wrap the region in AgentComponent when it needs to appear in the snapshot.

For status, put data-veya-status on the element that reflects it:

tsx
<section className="panel" data-veya-status={status}>
  {status === "loading" ? <Spinner /> : <RevenueChart />}
</section>

Accepted values are idle, loading, ready and error. loading also sets the component's loading flag, which signal R004 uses.

These attributes are optional for elements covered by AgentComponent; they are required for controls inside a region that should be addressable on their own.

7. Source locations ​

The Vite plugin annotates JSX host elements with data-veya-loc during the dev transform. The runtime turns that attribute into source: { file, line, column } on the component snapshot.

  • Source locations are a build fact, not a guess.
  • source: null is a real finding. It usually means the component was not rendered through an annotated JSX element, or the file was not transformed by the plugin.
  • Signal R008 reports every reported component without a source location.

Do not hand-write data-veya-loc; if the plugin is working, it is already there.

8. Verify the channel ​

Open the product in Veya, then ask for a snapshot:

json
{
  "tool": "veya_inspect",
  "arguments": { "depth": 3 }
}

Confirm:

  • channel.runtime is true.
  • Your components appear in components, with purpose and source.
  • state contains the keys passed to useVeyaState.
  • Clicking a marked control produces interaction.started and, when relevant, state.changed or network events in the same trace.

Then evaluate signals:

json
{
  "tool": "veya_signals",
  "arguments": { "viewport": { "width": 390, "height": 844 } }
}

Manual wiring ​

If you do not want the virtual module, create the runtime yourself and pass it to VeyaProvider:

ts
import { createRuntime } from "@veya/runtime";

const runtime = createRuntime({
  hubUrl: "ws://127.0.0.1:7317/v1/runtime",
  appName: "my-app",
});

runtime.start();

You are then responsible for calling runtime.start(), for the provider tree and for keeping the runtime out of production bundles.

Limitations ​

  • No Fast Refresh. Vite+ inlines Vite, so @vitejs/plugin-react has no vite package to resolve against. Saving a file causes a full reload.
  • Vite + React only. The plugin annotates JSX; other frameworks and other bundlers do not get component identity, state or source mapping.
  • Dev only. The plugin applies in serve mode and is not part of production builds.
  • Workspace packages. @veya/* are not published to npm in v0.1.

Next ​

Released under the Apache-2.0 License.