# Outlevo console inside your admin panel

For a product that uses Outlevo to find its own customers and wants the people who run it to work from the product's own admin panel: the same chat as app.outlevo.com, what needs a person, campaigns, replies, meetings. This is "Outlevo works for your own company" (case 1 in https://developers.outlevo.com/llms.txt): one key on your server, and only your platform's admins ever see these screens. Your customers never do.

Build it in the order below. Each screen says what it reads, how it behaves and what it must not do.

## What stays in Outlevo

People open app.outlevo.com for these and nothing else. No API or key can do them, so never build a button that pretends to. Show that the step is waiting and link straight to it.

| Step | Where |
|---|---|
| Connect an ad account | `/audiences` (Google Ads, LinkedIn audiences), `/ad-campaigns` (Reddit, Meta, X, LinkedIn Ads) |
| Approve a launch | the request's `approval_url` (`/launch/{id}`) |
| Review a campaign's first emails | `/campaigns/{id}` |
| Approve an ICP, an outbound policy, the first campaign's messages | `/approvals/{policy_id}` |
| Connect Smartlead, import a CSV | `/integrations`, `/import` |
| Create API keys | `/developers` |

Everything else, including starting the work that leads to those steps, happens in your panel.

## 1. The key and who may reach it

- One key for the whole installation, stored on your server (env var or platform settings). Start with a test key (`olv_test_…`): it works on the sandbox, nothing is sent, no credits are spent. Show plainly on the screen that it is a test key.
- Create it at app.outlevo.com → Developers with **Acts as me**, from the **Integration** preset (companies, signals, campaigns, policy drafts, webhooks, `assistant:read`, `assistant:write`), plus `ads:read` and `usage:read` for screens 5 and 6. Add a scope only when a screen needs it. Confirm cards run the calls the assistant proposed, so the key needs their scopes too: a call it lacks answers 403, which your screen shows as it is.
- Every console route checks that the signed-in person is a platform admin, on the server, before anything else. Hiding the menu item is not access control.

## 2. Three server routes, never a catch-all proxy

The browser never sees the key, and it never chooses what is called with it. A route that forwards any path the browser names hands the key's full power to anyone who gets a script into your admin. Give the browser these routes and nothing else:

| Your route | What your server does |
|---|---|
| `GET …/thread` | `GET /v1/assistant/thread` and returns `messages` and `chat.answering` |
| `POST …/messages { message }` | `POST /v1/assistant/messages { message, page }` |
| `POST …/cards { message_id, index, keep? }` | Reads the thread **itself**, finds that message's card, runs the card's `calls`, marks it done |

The cards route takes numbers, not calls. A card's `calls` come from Outlevo's copy of the thread, and your server refuses anything whose path does not start with `/v1/`, whose method is not `POST` or `PUT`, or whose card is already `done`. For a `companies` card, `keep` is the row indexes the person left ticked; your server takes those `records` from the thread and posts them to `/v1/companies/bulk`.

Any undo route takes an event id only (`POST /v1/assistant/events/{id}/undo`). Send every write with an `Idempotency-Key`.

`@outlevo/components` (`<OutlevoAssistant />`, `<outlevo-assistant endpoint="…">`) are fine in a customer-free React app, but they call whatever path the card names through your endpoint, so they need the catch-all this section rules out. In an admin panel holding a live key, render the chat yourself as below.

## 3. Screen: Needs you

The first thing on the page, because it is the reason to open the page. Read after the page has rendered, cache for about a minute, and list only what is waiting on a person, each with a link into Outlevo:

- `GET /v1/campaigns`, then for each campaign that is not finished, `GET /v1/campaigns/{id}/launch-request`: `launch_request.status` `pending` means a launch waits at `approval_url` until `expires_at`.
- `GET /v1/campaigns/{id}/first-batch`: `status` `pending` with `ready_at` set means the first emails wait at `/campaigns/{id}`.
- `GET /v1/campaigns/{id}`: `problems.approval` and `problems.senders` say in words what blocks it.
- `GET /v1/policies?status=pending`: each waits at `/approvals/{id}`.

An empty list says so ("Nothing is waiting for you"). A failed read says that it failed, and never reads as "nothing is waiting".

## 4. Screen: Chat

The same assistant and the same thread as app.outlevo.com: a conversation started in one continues in the other.

**Sending.** Add the person's message to the list and show a sentence saying the assistant is working on the click, before the network. Disable the box and the buttons until the answer. Send one request per message.

**Slow answers.** A turn that searches the web can take minutes, longer than your web server waits. Give your request a timeout under your proxy's limit (say 50 s) and answer "still working" when it passes. Outlevo keeps going: read the thread every few seconds until `chat.answering` is false, and give up with a message after about three minutes so the screen cannot freeze.

**Rendering.** `messages[]` has `id`, `role` (`user`, `assistant`, `staff`, `event`), `body`, `author`, `mine`, and on assistant messages `widgets`, `choices` and `links`. Render text as text, never as HTML: replies quote other people's websites.

- `role: event` is a quiet one-line note of what changed; with `undoable: true` it gets an Undo button that sends its `id`.
- `choices.options`, on the last message only: buttons that send that text, with the free-text box still there.
- `links`: `path` and `label`, relative to https://app.outlevo.com.

**Cards** (`widgets[]`). A card with `done` shows `done.text` and no button.

| `type` | Show |
|---|---|
| `table` | `title`, `columns`, `rows` |
| `confirm` | `title`, `detail`, `credits` on the button; on Confirm call your cards route. Never run it without the click |
| `companies` | `rows` with a tick each, all ticked; the button adds the ticked ones through your cards route |
| `chart` | `series` of `day`, `sent`, `replied`; a small table is enough |
| `link` | `title`, `detail`, a link to `path` labelled `label` |
| `launch`, `first_batch`, `angles`, `people` | `title` and a link to `/campaigns/{campaign_id}` |
| `form` | `title` and a link: `csv_import` to `/import`, `api_key` and `webhook` to `/developers`, the rest to `/integrations` |
| anything else | `title` and a link to https://app.outlevo.com. New types appear, so an unknown one must not break the list |

**Limits.** 429 `RATE_LIMITED` shows its `fix` as a sentence. The assistant never approves, starts or sends; if a person asks it to, it answers with a card that leads to Outlevo.

## 5. Screen: Campaigns

`GET /v1/campaigns` with `GET /v1/campaigns/{id}/stats` for each one that is not a `draft`: sent, replied, interested replies, meetings, reply and bounce rates, cost per meeting. Load after the page renders, one call per campaign, cached about 5 minutes. Each row links to `/campaigns/{id}`. Do not offer Start or Approve.

## 6. Screen: Replies and meetings

Do not poll for these. Subscribe once (`POST /v1/webhooks`, https://developers.outlevo.com/webhooks.html) to `lead.replied`, `lead.classified`, `lead.answered`, `meeting.booked`, `lead.bounced`, `lead.unsubscribed` and `company.qualified`, verify `Outlevo-Signature`, dedupe on `Outlevo-Event-Id`, and store them against your own record through `external_id`. The screen reads your database, so it opens instantly and works while Outlevo is down. Show a reply in full: it is what the person came to read.

## 7. Screen: Ad accounts and credits

- `GET /v1/ads/connections` (scope `ads:read`): each connection's `provider`, `ad_account_name`, `status` (`awaiting_account`, `active`, `token_error`), `run_by`. Beside it, one link to Connect in Outlevo: `/audiences` for Google Ads and LinkedIn audiences, `/ad-campaigns` for the others. A connection in `awaiting_account` or `token_error` links there too. There is no API for connecting, on purpose: granting access to an ad account is done by a person signed in to Outlevo.
- `GET /v1/usage` (scope `usage:read`): `available` credits, `plan`, `cycle.end`. Add `GET /v1/usage/forecast` for the warning that they are running out.

## When it is done

- [ ] A person who is not a platform admin gets 403 from every console route, and the page does not appear in their menu.
- [ ] The browser's network log holds no key, and no route accepts a path or a `calls` list from it.
- [ ] The page renders before any call to Outlevo, and each panel has its own loading, empty and failed state.
- [ ] Without a key the page says what to do and where, and calls nothing.
- [ ] A click shows its result at once; a dropped request cannot freeze the screen.
- [ ] On the sandbox: ask "add acme.com and qualify it", press Confirm, see the card done and the change in the thread at app.outlevo.com.
- [ ] Nothing about Outlevo appears on a screen, email or help page your customers can reach.

Laravel client, webhook controller and keys: https://developers.outlevo.com/quickstarts/laravel.md. In Filament, keep the page's panels out of the first render (Livewire `wire:init` or plain `fetch` from Alpine) and keep chat state in the browser: a `wire:model` per keystroke and a round trip for every click are what make these panels slow.
