# Installation · Booki

> Install @booki-aui/core, @booki-aui/react, and optional styles.

Source: https://booki.dev/docs/installation

# Add Booki to your app

Quickest: copy the prompt into your coding agent. It explains Booki, suggests one screen and asks before changing anything.

By hand, five steps: install, wrap the app, replace one amount input and one voucher table, then give an agent a bridge with your approval rules. The code below uses the React package; the same controls ship for Vue, Svelte, Solid and Web Components.

To start with a single button, try [your first agent action](https://booki.dev/docs/first-action).

## Install

Install Booki and its pinned dependencies together.

- Your app's frameworkReact 19 or later with the NO and US profiles is supported. Vue, Svelte, Solid, Web Components and the SE, DK, GB and DE profiles are experimental.
- Two pinned dependenciesRun these commands in a POSIX shell such as Bash or Zsh. They read the exact UI SDK version required by the published Booki release.

```
booki_version=$(npm view @booki-aui/react@latest version) &&
ui_sdk_version=$(npm view "@booki-aui/react@$booki_version" peerDependencies.@ui-sdk/core) &&
npm install --save-exact "@booki-aui/core@$booki_version" "@booki-aui/react@$booki_version" "@booki-aui/styles@$booki_version" \
  "@ui-sdk/core@$ui_sdk_version" "@ui-sdk/react@$ui_sdk_version"
```

```
booki_version=$(npm view @booki-aui/react@latest version) &&
ui_sdk_version=$(npm view "@booki-aui/react@$booki_version" peerDependencies.@ui-sdk/core) &&
pnpm add --save-exact "@booki-aui/core@$booki_version" "@booki-aui/react@$booki_version" "@booki-aui/styles@$booki_version" \
  "@ui-sdk/core@$ui_sdk_version" "@ui-sdk/react@$ui_sdk_version"
```

The optional @booki-aui/styles package provides the default look.

## Wrap the app

The provider sets currency, VAT codes, bank formats and language.

```
import { BookiLocaleProvider } from "@booki-aui/react"
import "@booki-aui/styles"

createRoot(root).render(
  <BookiLocaleProvider defaultCountry="NO">
    <App />
  </BookiLocaleProvider>,
)
```

Use `NO` or `US`. The stylesheet is optional: the controls are unstyled without it, and it reads `--bk-*` variables you can override on any wrapper.

## Replace an amount input

Amounts are whole minor units: 312500 is 3 125,00.

```
import { AmountField } from "@booki-aui/react"

// Before: <input name="amount" type="number" step="0.01" />
<form action="/invoices" method="post">
  <AmountField
    name="amount"
    aria-label="Amount excl. tax"
    defaultValue={312500}
    required
  />
  <button type="submit">Save</button>
</form>
```

With `name` the field submits with the form as integer minor units, so the server never parses a formatted number. It also takes `id`, `disabled`, `readOnly` and `required`. A disabled or read-only field refuses an agent as well as a person. The other inputs and selects take the same props; see [AmountField](https://booki.dev/docs/amount-field).

## Replace a voucher table

One table for the person and the agent, held to the same rules.

```
import { VoucherComposer, type VoucherLine } from "@booki-aui/react"

const [lines, setLines] = useState<VoucherLine[]>(voucher.lines)

<VoucherComposer
  editable
  aria-label="Voucher lines"
  lines={lines}
  onLinesChange={setLines}
  accounts={chartOfAccounts}
  departments={departments}
  projects={projects}
/>
```

With `editable` a person can change account, VAT code, department, project, debit and credit, and add or remove lines. Without it the table is read-only and only an agent edits. An edit that breaks a rule leaves the line as it was and says why on that row. See [VoucherComposer](https://booki.dev/docs/voucher-composer).

## Create the bridge

Once, in its own module, before the app renders.

```
import { createBookiAgent, registerTools } from "@booki-aui/react"

type PersonPrompt = (text: string) => Promise<boolean> | boolean

let prompt: PersonPrompt | null = null

/** A page that can ask the person registers its prompt here. */
export function setPersonPrompt(next: PersonPrompt): () => void {
  prompt = next
  return () => {
    if (prompt === next) prompt = null
  }
}

/** Unmarked steps run. Marked steps wait for the person, or are refused. */
const allow = (step: { confirm?: string }) =>
  step.confirm ? (prompt ? prompt(step.confirm) : false) : true

const agent = createBookiAgent({ agentId: "bookkeeper", allow })

// Try it in the console: window.agent.snapshot()
Object.assign(window, { agent })

// The same snapshot / act / query tools, for the browser's own agent.
const unregister = registerTools(agent, { allow: "bridge" })

if (import.meta.hot) {
  import.meta.hot.dispose(unregister)
}

export { agent }
```

Import it first in your entry file, so the bridge sees every control as it mounts.

```
// Create the agent bridge before anything renders, so it sees every control.
import "./agent"
import { createRoot } from "react-dom/client"
```

`registerTools` publishes `snapshot`, `query` and `act` over WebMCP, so an agent in a browser that supports it can use your product with no tools of your own to write. In other browsers the call does nothing. The bridge's actions per control are in [the agent catalog](https://github.com/Walgermo/booki/blob/main/packages/react/docs/llms.txt).

## Approval rules

What an agent may do alone is decided in allow, in one place.

Mark the draft save with data-agent-confirm so it can run after the person agrees. Posting the voucher is a person's action. `personOnly` makes the bridge refuse that action even if the policy allows other marked steps.

```
import { useEffect } from "react"
import { Button } from "@ui-sdk/react/button"
import { personOnly } from "@booki-aui/react"
import { setPersonPrompt } from "./agent"

type Props = {
  saveDraft: () => void
  postVoucher: () => void
}

export function VoucherActions({ saveDraft, postVoucher }: Props) {
  useEffect(() => setPersonPrompt((text) => window.confirm(text)), [])

  return (
    <>
      <Button
        data-agent-confirm="Save changes to draft 1042?"
        onClick={saveDraft}
      >
        Save draft
      </Button>
      <Button
        data-agent-confirm={personOnly("Post voucher 1042?")}
        onClick={postVoucher}
      >
        Post voucher
      </Button>
    </>
  )
}
```

The bridge passes `step.confirm` to its `allow` callback. The example refuses marked steps until a prompt is registered. WebMCP delegates to the same callback with `allow: "bridge"`, so the person is asked once.

Enforce person-only decisions on the server too. Pass the authenticated actor to the write guard from `@booki-aui/core/server`.

## Check it

In the browser console, with your screen open.

```
window.agent.snapshot()

await window.agent.act({
  steps: [{ ref: "Amount excl. tax", action: "setMinor", args: [125000] }],
})
```

The snapshot lists each control with its value and the actions it takes. The step sets the amount to 1 250,00 and reports the change with `source: "agent"`, which is what your audit log should record. Next: [the demo](https://booki.dev/demo) shows a full posting flow.
