# Show a run list

List your agent runs for your staff inside your own admin tool with <provenance-run-list>, with tabs, filters, a sort and paging, and open the selected run in its own panel.

`<provenance-run-list>` lists your agent runs (each [run](https://provenanceauth.com/docs/mandate/guides/halt-a-run.md), a team of agents under one grant) for your staff, inside your own admin tool, newest first. Each row is one line: the status with a dot, the run's name, how many agents it has, who halted it and the time. Your staff filter it, search it by name or ID, sort it and page through it; a selected row opens in a panel beside the rows.

**Before you begin:** a publishable key (see [embeds](https://provenanceauth.com/docs/embeds.md#1-create-a-publishable-key)) and a secret key with the `mandate` scope. The embed needs Pro or the Free trial in live, and works on any plan in sandbox; the same status words show on the console's **Runs** page on every plan.

```bash
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_ent_E7nT2vQ9bW4mK8sYd3cFjLh6gAe1pR5x
```

## 1. Mint a list session on your server

Your server mints a short session for the list with [`POST /v1/embed/tokens`](https://provenanceauth.com/docs/api/embeds.md#post-v1-embed-tokens) and `widget: "run_list"`. A list takes no `object_id`: it's scoped to your account. Put it behind a route your admin page calls, after your own sign-in check:

In the SDK tabs, `prov` (Node, Python) and `embed` (Go) are your server-side clients, set up as in [admin results and requests](https://provenanceauth.com/docs/embeds/admin-tools.md#3-mint-a-session-for-an-embed).

**curl**

```bash
curl -s -X POST $PROVENANCE_API/v1/embed/tokens \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "widget": "run_list", "filters": { "status": "halted" }, "ttl": 900 }'
```

**Node**

```ts
// GET /admin/provenance/session?widget=run_list (your route, behind your staff sign-in)
const session = await prov.embed.createToken({ widget: "run_list", filters: { status: "halted" }, ttl: 900 });
res.json({ token: session.embedToken });
```

**Python**

```python
token = prov.embed.create_token(widget="run_list", filters={"status": "halted"}, ttl=900)["embed_token"]
```

**Go**

```go
session, err := embed.CreateToken(ctx, pv.EmbedTokenParams{
	Widget:  pv.WidgetRunList,
	Filters: &pv.RunListFilters{Status: "halted"},
	TTL:     900,
})
```

| Field | What it does |
| --- | --- |
| `filters` | Optional. Filters the session always applies, which the browser can't change: `status` (`active`, `halted`, `ended`, or several separated by commas), `q` (the name or ID contains it), `created_gte`, `created_lte`, `outside_agent` (`proposed`, `took_part` or `none`). Pin `status: "halted"` for a page of stopped teams, or `outside_agent: "proposed"` for the runs with an outside agent's proposal. |
| `ttl` | Seconds, up to 900 (15 minutes). |

A run list takes no `show`. A key without the `mandate` scope gets `403` [`insufficient_scope`](https://provenanceauth.com/docs/platform/errors.md#insufficient_scope). A filter that isn't one of the list's, or a value it doesn't take, is `400` [`parameter_invalid`](https://provenanceauth.com/docs/platform/errors.md#parameter_invalid).

## 2. Drop the list in your page

```bash
npm install @provenance/embed
```

```html
<script type="module" src="https://unpkg.com/@provenance/embed"></script>

<provenance-run-list id="runs" base-url="https://sandbox-api.provenanceauth.com" publishable-key="prv_pub_1D10TzJo8F73Z7ZHhWGKPpn0K7suJ0se"
  filters="status,search,created" page-size="25"></provenance-run-list>

<script>
  const list = document.querySelector("provenance-run-list");
  // No context: the list's own session. { objectId, widget }: the session for the row its panel opens.
  list.getToken = async ({ objectId, widget } = {}) => {
    const q = objectId ? `widget=${widget}&id=${objectId}` : "widget=run_list";
    return (await (await fetch(`/admin/provenance/session?${q}`)).json()).token;
  };
</script>
```

A selected row opens in the list's own panel: beside the rows on a column 600 px or wider, with the run's reference, **Previous**, **Next** and **Close**; narrower, as the whole element with **Back**. One "Powered by Provenance" sits under both.

The panel asks the list's `getToken({ objectId, widget: "run_result" })` for the run's ID (`run_…`), and your server mints a `run_result` session for exactly that run, so the list never widens what it can read.

| Attribute | What it does |
| --- | --- |
| `filters` | The filters shown, from `status` (Active, Halted, Ended), `search` (the name or ID) and `created` (Any time, Today, Last 7 days, Last 30 days). `status,created` when absent. A pinned filter has no tab, chip or menu entry. |
| `sort` | The order on load, one of **Newest first** (`-created`) or **Oldest first** (`created`). Newest first when absent. |
| `sorts` | The orders the sort button offers, a comma list (for example `-created,created`). All of them when absent. |
| `detail` | `panel` (the default) opens a selected row in the list's own panel. `none` only emits `pv:select`. |
| `page-size` | Rows per page, 10 to 100. 25 when absent. |
| `select-first` | Select the first row on load (with the panel, it opens on that row). |
| `hide-suffix` | Text your server adds to the end of each run's name, such as a tenant's tag. Rows and the panel show the name without it. The search and a pinned `q` still match the whole name. |

Above the rows: tabs for `status` (All, Active and Halted), a **Filter** chip for the other filters you show, a chip for each filter in use (its button removes it) and a sort button that names the current order.

Under the rows, the range ("1–25") and **Newer** and **Older** page by cursor, with no page numbers or totals. The filters, the sort and the page stay inside the element; to keep them in your page's address, listen for `pv:list_change`.

To show the run somewhere else on your page, set `detail="none"` and either handle `pv:select` yourself or put a `<provenance-run-result for="runs">` beside it (a list that a result element follows never opens its own panel):

```js
list.addEventListener("pv:select", (e) => {
  const { kind, id } = e.detail; // kind: "run", id: "run_…"
  openRun(id);
});
```

In React:

```tsx
import { ProvenanceRunList } from "@provenance/embed/react";

<ProvenanceRunList
  id="runs"
  baseUrl={process.env.NEXT_PUBLIC_PROVENANCE_API!}
  publishableKey="prv_pub_1D10TzJo8F73Z7ZHhWGKPpn0K7suJ0se"
  filters={["status", "search", "created"]}
  sort="created"
  getToken={async ({ objectId, widget } = {}) => {
    const q = objectId ? `widget=${widget}&id=${objectId}` : "widget=run_list";
    return (await (await fetch(`/admin/provenance/session?${q}`)).json()).token;
  }}
/>;
```

## What it shows

Each row, and where it comes from in [`GET /v1/mandate/runs`](https://provenanceauth.com/docs/api/runs.md#get-v1-mandate-runs):

| Part | Example | From |
| --- | --- | --- |
| Status | Active, Halted or Ended | `status` |
| Name | Lisbon trip, or the run's ID when it has no name | `name`, else `id` |
| Detail | 3 agents · Run guard | `members_count`, and who halted it by kind (`halted_by`) while it's halted |
| Time | 1:23 pm today, Nov 14 before | `created_at` |

The list's filters are the API list's own, the ones a session can pin (step 1); the search matches any part of the name or ID, in any case. The element never gets the root grant, the agents, their sessions, the halt reason or who halted it by ID. To see what it gets, call `GET /v1/embed/run_list` with the session.

## Events

| Event | When | Detail |
| --- | --- | --- |
| `pv:ready` | The session opened | `widget`, `object_id`, `mode` |
| `pv:select` | A row was selected (click, Enter or Space) | `kind: "run"`, `id` |
| `pv:list_change` | The filters, the sort or the page changed | `filters`, `cursor`, `sort` |
| `pv:token_refresh_failed` | `getToken()` couldn't renew the session | `widget` |
| `pv:error` | The element couldn't start or read a page | `code`, `message` |

## Embed, console or your own

|  | This embed | The console | Your own UI on the API |
| --- | --- | --- | --- |
| Where | Your admin tool | **Mandate › Runs** | Anywhere you like |
| Plan | Pro, or the Free trial; any plan in sandbox | Every plan | Every plan |
| Work | Mint two kinds of session, drop one tag | None | Page the list, map the words |

## Errors you might see

| Symptom | Cause | Fix |
| --- | --- | --- |
| `400` [`embed_filter_pinned`](https://provenanceauth.com/docs/platform/errors.md#embed_filter_pinned) | The page asked for another value of a pinned filter | Leave it out; the session applies it. |
| `400` [`parameter_invalid`](https://provenanceauth.com/docs/platform/errors.md#parameter_invalid) on `sort` or `cursor` | A `sort` the list doesn't take, or a cursor made in another order | Use an order from the `sort` row above; start again without the cursor. |
| `403` [`insufficient_scope`](https://provenanceauth.com/docs/platform/errors.md#insufficient_scope) | The key has no `mandate` scope | Mint with a Mandate key. |
| `401` [`embed_token_invalid`](https://provenanceauth.com/docs/platform/errors.md#embed_token_invalid) | The session expired or is for another widget | Mint a new one, or give the element `getToken()`. |
| `503` [`embed_result_unavailable`](https://provenanceauth.com/docs/platform/errors.md#embed_result_unavailable) | The list couldn't be read | Retry shortly. |

## See also

- [Embeds](https://provenanceauth.com/docs/embeds.md)
- [Run result in your admin](https://provenanceauth.com/docs/embeds/run-result.md)
- [Checkout list in your admin](https://provenanceauth.com/docs/embeds/checkout-list.md)
- [Admin results and requests](https://provenanceauth.com/docs/embeds/admin-tools.md)
