# Secretary guide: add the assistant to your web app

> How to add Hibira Secretary to a web app: the script tag, signing your users in, what it may and may not do, page tools, reading images, continuing on a phone, handing over to Live Chat, the task record, frameworks, API tokens and plans.

Source: https://hibira.io/secretary/guide

## Before you start

Secretary is an assistant that works inside your web app the way a person does: it reads the page, clicks, types and moves between pages to get a task done, and asks before anything that saves, sends or pays.

- **Create a workspace** on the [Secretary plans](https://hibira.io/secretary) page or with an API token. Each workspace has a public key (`pk_...`) for the script tag and a secret key (`sk_...`) for your server.
- **Add your sites** to the workspace's allowed origins, such as `https://app.example.com`. The assistant answers only on those sites.
- **Keep the secret key on your server.** It signs your users in; it must never reach a browser.

## Adding the script tag

Put one tag before `</body>` on every page where the assistant should appear:

```html
<script src="https://hibira.io/secretary/v1.js" data-key="pk_live_..." async></script>
```

A button appears in the corner of the page. Optional attributes:

| Attribute | What it does |
| --- | --- |
| `data-session-url` | A URL on your site that signs the current user in (next section). |
| `data-lang` | The assistant's language: `en`, `zh-TW`, `zh-CN`, `ja`, `ko`, `th` or `vi`. By default it follows the page. |
| `data-position="left"` | Puts the button on the left. |
| `data-open` | Opens the panel when the page loads. |
| `data-navigate-once` | For sites that swap pages without a full load (Livewire `wire:navigate`, Turbo). |

The script sets `window.HibiraSecretary`, with `open()`, `close()`, `tool()` and `destroy()`. It fires `hibira-secretary:ready` on `window` once it is set.

## Signing users in

The assistant acts as the person who is signed in to your app, with their own permissions. To tell Hibira who that is, add an endpoint to your app that asks Hibira for a short-lived session token and returns it:

```js
app.post('/secretary/session', requireLogin, async (req, res) => {
  const r = await fetch('https://hibira.io/secretary/v1/sessions', {
    method: 'POST',
    headers: { Authorization: `Bearer ${process.env.HIBIRA_SECRETARY_SECRET}`, 'Content-Type': 'application/json' },
    body: JSON.stringify({ user_id: String(req.user.id), name: req.user.name, ttl: 3600 }),
  });
  res.json({ token: (await r.json()).token });
});
```

Then point the tag at it with `data-session-url="/secretary/session"`. The script calls it with the page's cookies (and a Laravel `csrf-token` meta tag, if there is one).

- `user_id` is 1 to 128 letters, digits or `. _ @ : + -`. Use your own user ID: the task record is kept by it.
- `ttl` is in seconds, up to the default of 12 hours.
- With **signed-in users only** turned on in the workspace settings, visitors without a token cannot use the assistant.

## What it does and doesn't do

The assistant does what a person would do with the page in front of them, and nothing the page cannot do.

- **It asks first** before a click or Enter that submits, saves, sends, deletes or pays. The person sees what it is about to do and which fields it filled, and approves or declines.
- **It never acts on** sign-in, sign-up or password pages, or pages with a robot check (CAPTCHA). The person does those themselves.
- **Auto mode** lets the person skip the questions for the rest of a task. It is off unless the workspace allows it, and the person turns it on themselves.
- **Private areas:** add `data-secretary="private"` to any element the assistant must not read or touch, such as a card form or another customer's notes. Password and card fields are always masked.
- **Your own rules:** `data-secretary="confirm"` on an element makes a click on it always wait for approval, `data-secretary="never"` stops the assistant from clicking it, and `data-secretary="safe"` lets it click without asking.

![The assistant waits for approval before saving an order: it says what it will save and lists the fields it filled.](https://hibira.io/portal/secretary/guide/approve-en-light.webp)

## Page tools

Your page can give the assistant tools of its own, for things that are quicker as a function call than as clicks, such as a search across records:

```js
window.addEventListener('hibira-secretary:ready', (e) => {
  e.detail.tool({
    name: 'find_orders',
    description: 'Finds orders by customer name, email or order number.',
    inputSchema: { type: 'object', properties: { query: { type: 'string' } }, required: ['query'] },
    execute: async ({ query }) => (await fetch(`/api/orders?q=${encodeURIComponent(query)}`)).json(),
  });
});
```

- Set `write: true` on a tool that changes something: the person approves each call, and `summary(input)` is the line they see.
- Tools your page already registers with the browser's WebMCP (`document.modelContext`) are picked up too.

## Images

The assistant can look at a picture on the page when the text is not enough, such as a chart, a product photo or a scanned receipt. It uses this only when it needs to, because it costs more than reading text.

- Images inside `data-secretary="private"` areas, hidden images and images from another site that does not allow it are never read.
- Each look counts as a step of the task, like a click.

![Asked about a delivery slip, the assistant looks at the scanned slip on the order page and reads the tracking number from it.](https://hibira.io/portal/secretary/guide/look-light.webp)

## Continuing on the phone

When a task needs an approval and the person has stepped away, they can carry on from their phone: the panel shows a QR code, and the phone shows the same steps with Approve and Decline. The page on the desk follows along.

![The panel offers a QR code to continue on the phone.](https://hibira.io/portal/secretary/guide/handoff-qr-light.webp)

![On the phone: the same approval, with the fields it will save.](https://hibira.io/portal/secretary/guide/handoff-phone-light.webp)

## Handing over to Live Chat

On a site that also has [Hibira Live Chat](https://hibira.io/live-chat), there is one button for both. When the assistant cannot help, it offers to hand the conversation over to your support team, with a short summary of what was tried. Your team sees the steps and the names of the fields involved, never what was typed in them.

![When the assistant cannot finish, Live Chat opens with a message about what was tried, for the person to read and send.](https://hibira.io/portal/secretary/guide/lc-handover-light.webp)

## The record

Every task is kept in the workspace's task log: who asked, on which page, each step, whether it was approved, declined or refused, and the names of the fields that were sent. What was typed into the fields is not kept.

- Download the log as CSV from the workspace page, or with the API.
- Logs are kept for 7, 30, 90 or 365 days, by plan.

![The task log: each step with its outcome and the fields that were sent.](https://hibira.io/portal/secretary/guide/audit-light.webp)

## Frameworks

- **Filament:** the [Hibira Filament plugin](https://hibira.io/use-cases/filament) adds the assistant to a panel with `->secretary()` and signs the panel's user in for you. Set `HIBIRA_SECRETARY_KEY` and `HIBIRA_SECRETARY_SECRET` in `.env`.
- **Livewire and Turbo:** add `data-navigate-once` to the tag. The assistant stays open as pages change without a full load.
- **Single-page apps** (React, Vue and others) need nothing extra: the assistant reads the page as it is now.

## API tokens

Everything in the portal can also be done with an API token, under `https://hibira.io/api/v1`:

| Request | What it does |
| --- | --- |
| `GET /secretary/plans` | The plans and their limits. |
| `GET /secretary/workspaces` | Your workspaces. |
| `POST /secretary/workspaces` | Creates a workspace; the answer holds its secret key, once. |
| `PATCH /secretary/workspaces/{id}` | Changes its name, origins and settings. |
| `POST /secretary/workspaces/{id}/rotate-secret` | Makes a new secret key. |
| `GET /secretary/workspaces/{id}/tasks` | The task log. |
| `GET /secretary/workspaces/{id}/tasks.csv` | The task log as CSV. |
| `GET /secretary/workspaces/{id}/usage` | Tasks used, by month. |

A setting your plan does not include is refused with a message that names the plan that has it.

## Plans and limits

A task is one question answered, however many pages and steps it took, up to 20 steps.

| Plan | Price | Tasks a month | Workspaces | Log kept |
| --- | --- | --- | --- | --- |
| Free | $0 | 50 | 1 | 7 days |
| Starter | $49 | 1,000 | 3 | 30 days |
| Team | $149 | 3,000 | 10 | 90 days |
| Business | $399 | 8,000 | 25 | 365 days |

- On Free, the assistant stops for the month at 50 tasks. On paid plans extra tasks are $0.05 each, and **stop at the limit** in the settings stops it instead.
- Auto mode and hiding the Hibira name are on Starter and up.
- Team and Business can run on your own model key instead, for $79 or $199 a month, and those tasks are not counted against the plan.
