# Show a run result

Show one agent run to your staff inside your own admin tool with <provenance-run-result>, keep its session alive with getToken(), and put your own next step beside it.

`<provenance-run-result>` shows one agent [run](https://provenanceauth.com/docs/mandate/guides/halt-a-run.md) to your staff, inside your own admin tool: whether it's active, halted or ended, what the team has spent against the budget, each agent's place in the chain, and the agents' newest purchases and refusals. Every row is one line, with a dot and a word. Beside it, a slot holds your own next step; Provenance shows the facts and never picks the action.

**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; the same rows show on the console's run page on every plan.

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

## 1. Mint a session on your server

Your server mints a short session for one run with [`POST /v1/embed/tokens`](https://provenanceauth.com/docs/api/embeds.md#post-v1-embed-tokens), `widget: "run_result"` and the run's ID. 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_result", "object_id": "run_01M7KR2Y8QW5TZ0D9H3XNB4C6E", "ttl": 900 }'
```

**Node**

```ts
// GET /admin/provenance/session?run=run_01M7… (your route, behind your staff sign-in)
const session = await prov.embed.createToken({ widget: "run_result", objectId: runId, ttl: 900 });
res.json({ token: session.embedToken });
```

**Python**

```python
token = prov.embed.create_token(widget="run_result", object_id=run_id, ttl=900)["embed_token"]
```

**Go**

```go
session, err := embed.CreateToken(ctx, pv.EmbedTokenParams{Widget: pv.WidgetRunResult, ObjectID: runID, TTL: 900})
```

| Field | What it does |
| --- | --- |
| `object_id` | One run (`run_…`) of your account. Another kind of ID is `400` [`embed_object_kind_mismatch`](https://provenanceauth.com/docs/platform/errors.md#embed_object_kind_mismatch); another account's is `404`. |
| `ttl` | Seconds, up to 900 (15 minutes). |

A key without the `mandate` scope gets `403` [`insufficient_scope`](https://provenanceauth.com/docs/platform/errors.md#insufficient_scope). A copied session opens only this run, and only until it expires. For a phone, mint a [hosted page link](https://provenanceauth.com/docs/embeds/hosted-page.md) with the same body instead.

## 2. Drop the element in your page

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

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

<provenance-run-result base-url="https://sandbox-api.provenanceauth.com" publishable-key="prv_pub_1D10TzJo8F73Z7ZHhWGKPpn0K7suJ0se" theme="inherit">
  <div slot="actions"><button id="review-trip" hidden>Review the trip</button></div>
</provenance-run-result>

<script>
  const el = document.querySelector("provenance-run-result");
  el.getToken = async () => (await (await fetch("/admin/provenance/session?run=run_01M7KR2Y8QW5TZ0D9H3XNB4C6E")).json()).token;
</script>
```

The element calls `getToken()` on load and one minute before each session ends, and swaps the new session in place. If your server can't answer, it says **Session ended** with **Reload** and fires `pv:token_refresh_failed`. See [capture result in your admin](https://provenanceauth.com/docs/embeds/capture-result.md#3-keep-the-session-alive-with-gettoken) for the details; they're the same here.

If your server adds a tag of its own to the end of the run's name, name it in `hide-suffix` and the element shows the run's name without it.

In React:

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

<ProvenanceRunResult
  baseUrl={process.env.NEXT_PUBLIC_PROVENANCE_API!}
  publishableKey="prv_pub_1D10TzJo8F73Z7ZHhWGKPpn0K7suJ0se"
  getToken={async () => (await (await fetch(`/admin/provenance/session?run=${runId}`)).json()).token}
  onResult={(r) => setResult(r)}
>
  <ReviewTrip result={result} />
</ProvenanceRunResult>;
```

## 3. Put your own next step in the slot

The `actions` slot is yours. Decide what to show from `pv:result`, which carries enums only:

```js
el.addEventListener("pv:result", (e) => {
  const { status, outcome } = e.detail;
  // Your rule, in your code: a halted run, or an agent's purchase refused.
  document.querySelector("#review-trip").hidden = !(status === "halted" || outcome === "denied");
});
```

| Detail | Values |
| --- | --- |
| `status` | The run's: `active`, `halted` or `ended` |
| `outcome` | The newest action's result: `valid`, `denied` or `pending`, or null before the first |

The slot can't cover or restyle the status line, the outcome words or the "Powered by Provenance" foot.

## What it shows

Each row, and where it comes from in the API, so you can find the same fact in [`GET /v1/mandate/runs/{id}`](https://provenanceauth.com/docs/api/runs.md#get-v1-mandate-runs-id) and [`GET /v1/mandate/assessments`](https://provenanceauth.com/docs/api/decisions.md#get-v1-mandate-assessments) (with `run_id`):

| Row | Example | From |
| --- | --- | --- |
| Status line | Active · 3 agents, what the team spent of the budget | The run's `status`; how many `members`; the root grant's `spent` and `share` |
| Budget | Spent, Budget, Available | The root member's `mandate.spent`, `mandate.share` and `mandate.available` ([spend per grant](https://provenanceauth.com/docs/mandate/guides/give-subagents-their-own-limits.md)) |
| Team | Valet › Valet Flights, with its spend of its share | Each member's agent name (else its grant's `purpose`), its chain through `grant.parent_grant_id`, and its `spent` and `share` |
| Proposals | Kestrel Broadband support · Accepted, the offer, its price and the answer | The run's proposals from outside agents, when it has any: the same cards as [`<provenance-counter-offers>`](https://provenanceauth.com/docs/embeds/counter-offers.md#what-it-shows) |
| Timeline | Valet Flights · Approved, the amount and the merchant | The run's `verify` decisions, newest first, at most 10: `result`, `facts.transaction_amount`, `facts.payee` or `facts.counterparty`, `reason`, `created_at` |
| Timeline | Started, Halted, Resumed, Ended | The run's `created_at`, `halted_at` with `halt_reason`, `resumed_at`, `ended_at` |

A chain longer than two names shows its root and its member with the count between: **Valet › +1 › Seat picker**. An action reads Approved, Rejected or In review, the product's [outcome words](https://provenanceauth.com/docs/reference/outcomes.md). A halt says who stopped it by kind (the run guard, a person, or a call with a key), never which key or person.

The element never receives an ID: no session, agent, grant, decision or token ID reaches it. To see what it gets, call `GET /v1/embed/run_result` with the session.

While the run is active, the element reads it again every 15 seconds. A run that can't be read shows that it's unavailable, never a made-up result.

## Events

| Event | When | Detail |
| --- | --- | --- |
| `pv:ready` | The session opened | `widget`, `object_id`, `mode` |
| `pv:result` | First read, and whenever the run changes | `kind: "run"`, `status`, `outcome` |
| `pv:token_refresh_failed` | `getToken()` couldn't renew the session | `widget` |
| `pv:error` | The element couldn't start | `code`, `message` |

## Embed, console or your own

|  | This embed | The console | Your own UI on the API |
| --- | --- | --- | --- |
| Where | Your admin tool | **Mandate › Runs**, the run page | Anywhere you like |
| Plan | Pro, or the Free trial | Every plan | Every plan |
| Work | Mint a session, drop the tag | None | Read the run and its decisions, walk the chain, format the spend |

To build your own, read the run page and the run's decisions from your server; the table above names the field behind each row.

## Errors you might see

| Symptom | Cause | Fix |
| --- | --- | --- |
| `400` [`embed_object_kind_mismatch`](https://provenanceauth.com/docs/platform/errors.md#embed_object_kind_mismatch) | The ID isn't a run | Pass the `run_…` ID. |
| `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 run couldn't be read | Retry shortly. |

## See also

- [Embeds](https://provenanceauth.com/docs/embeds.md)
- [Admin results and requests](https://provenanceauth.com/docs/embeds/admin-tools.md)
- [Proposals in your pages](https://provenanceauth.com/docs/embeds/counter-offers.md)
- [Halt a run](https://provenanceauth.com/docs/mandate/guides/halt-a-run.md)
- [Give subagents their own limits](https://provenanceauth.com/docs/mandate/guides/give-subagents-their-own-limits.md)
