# Harness API reference

[中文](harness-api.zh-CN.md)

This page lists every method, notification, event, feature and error of the Harness API, protocol 1. The TypeScript
types are in `packages/protocol/src/harness.ts` (`AdapterToDaemon`, `DaemonToAdapter`, `HarnessEvent`). For what to do
with them, start at [Integrating Open Artifacts](../integrating.md).

## Transport

| | |
| --- | --- |
| WebSocket | `ws://127.0.0.1:<port>/__harness`, subprotocol `open-artifacts-harness` |
| Messages | JSON-RPC 2.0; both sides send requests |
| Port and token | `<home>/daemon.json` (`port`, `token`, `pid`, `version`) |
| stdio | `open-artifacts harness --stdio --harness <name>`: the same methods as JSON lines ([other languages](../integrating/non-node.md)) |
| HTTP polling | [below](#http-polling) |

The first request must be `hello`. Anything else before it is refused `unauthorized`.

## Versions and the compatibility promise

`PROTOCOL_MIN` and `PROTOCOL_MAX` are both `1`. The adapter says the versions it speaks in `hello` (`protocols: { min,
max }`; left out means 1); the daemon answers with the highest both speak. When none is shared, `hello` fails with
`unsupported_protocol` and a fix line saying which side to upgrade.

Within one protocol version, methods, optional fields, events and feature names are only ever **added**. Check a
feature by name before using it; never compare daemon versions. Ignore fields and events you do not know.

From 0.14.0, every release whose Harness API, Shell or wake messages, kit, shipped profiles or stdio framing changed has
an `### Integrators` section in [CHANGELOG.md](https://github.com/openartifactsai/open-artifacts/blob/main/CHANGELOG.md) saying what changed for you.

### Names from before the rename

Up to 0.22 the product was Open Artifact, and its names had no `s`. Use the names on this page. The daemon still
answers an adapter built on 0.22: the subprotocol `open-artifact-harness`, the routes `/api/open-artifact.*` and
`/__open-artifact/health` (which answers `openArtifact: 1` beside `openArtifacts: 1`), the headers `X-Open-Artifact-*`,
and links `open-artifact://artifact/<id>` and `open-artifact://type/<id>` in tool arguments (answers give
`open-artifacts://`). An adapter that asked for `open-artifact-harness` only, or attached at
`/api/open-artifact.session.attach`, gets wakes whose `source.kind` is `open-artifact.event`; every other adapter gets
`open-artifacts.event`. A connection by `open-artifact-harness` is also sent every `open-artifacts://` link as
`open-artifact://`, the scheme a 0.22 kit's `owns()` knows. The kit asks for both subprotocols, the new one first; it
still finds a 0.22 daemon that is running (by `/__open-artifact/health`) and calls its Library API at
`/api/open-artifact.*`, so `ensureDaemon` replaces it with a newer runtime as it does any older daemon.

## Features

`hello`'s answer lists `features`. A daemon lists only what it implements.

| Feature | The daemon |
| --- | --- |
| `hello.profile` | keeps the profile an adapter reports in `hello` |
| `skill.get` | answers `skill.get` |
| `commands.list` | answers `commands.list` |
| `embed.origins` | answers `embed.origins` and sends `embed/origins` events |
| `shell.command` | answers `shell.command` |
| `shell.event` | calls `shell.event` for top-level views |
| `view.context` | answers `view.context` and sends `view/context` events |
| `session.may` | enforces `session.attach`'s `may` and `role` |
| `wake.drafted` | takes the answer `drafted` |
| `wake.held` | takes the answer `held`: the message waits in the session's inbox, and the profile's nudge is not run |
| `wake.session` | takes `{ status, session }` and moves ownership to that session |
| `wake.from` | puts `reason` and `from` in a wake's `source` |
| `tools.actions` | gives each tool's `actions` (action → kind) in `tools.list` |
| `quickstart.steps` | `quickstart` answers `steps`, `existing`, `rules`, `replaces`, and takes `type` |
| `types.remote` | describes types with `remote` and `origin`, gives `remoteActions`, and puts `remote` in `host.open` |
| `hello.runtime` | records `hello`'s `runtime` and starts the newest compatible runtime |
| `runtime.update` | answers `runtime.status` and `runtime.update`, and sends `runtime/update` events |
| `types.source` | describes types with `source` (`builtin`, `local`, `installed`) and, for an installed one, `installed_from` and `third_party_notice`, wherever types are listed and when an artifact is read; puts `third_party_notice` next to `instructions` when one is created or adopted; a project type not trusted yet gets its own `third_party_notice`, and reads of an artifact of either (`Artifact`, `ArtifactData`, `ArtifactComments`) add a page-content one |
| `view.open` | answers `view.open`: the addresses to show one of its own artifacts in your app, with no session |
| `inbox.return` | answers `inbox.return`: messages you took from a session's inbox and could not hand to its agent wait there again |
| `wake.request.parts` | may put `userText` (the person's words) and `selectionSnapshot` (what was selected at Send) on a wake's `source.requests` entries |
| `sample.create` | calls `sample.create` on an adapter whose caps declare `sample`, takes its `sample.delta` notifications and sends `sample.cancel` |
| `mcp.proxy` | sends a page's call of `host:<name>` to an adapter whose caps declare `mcp`: calls `mcp.listTools` and `mcp.callTool`, and sends `mcp.cancel` |
| `session.start` | calls `session.start` on an adapter whose caps declare `sessions.start`, when the person picks its app for an artifact no session owns |
| `session.models` | calls `session.models` on an adapter whose caps declare `sessions.models` too, and `session.start` then carries the `model` and `effort` the person picked from its answer |

`session.*`, `tools.list`, `tools.call`, `agent.wrote`, `artifact.open`, `inbox.take`, `inbox.wait` and `subscribe` are
the base protocol and need no feature.

## `hello`

| Param | Type | |
| --- | --- | --- |
| `harness` | string | `^[a-z0-9][a-z0-9._-]{0,40}$` |
| `token` | string | from `daemon.json` (not over stdio) |
| `caps` | `AdapterCaps` | below |
| `protocols` | `{ min, max }` | |
| `kit` | `{ name, version }` | the SDK you build on |
| `profile` | part of a [profile](profile.md) | kept when the daemon lists `hello.profile`; never `nudge` |
| `runtime` | `{ dir, version, update? }` | the runtime you carry ([runtime](../integrating/runtime.md)) |

Result: `{ protocol, daemon, connection, features }`.

### `AdapterCaps`

| Field | Type | Means |
| --- | --- | --- |
| `wake` | `{ resume?, mode?: 'auto' \| 'draft' }` | you take `wake.deliver`; `resume`: you can bring back a closed session; `draft`: you put the text in the input |
| `open` | `true` or `{ embed: 'frame' \| 'view', origins, remote?: 'allow' \| 'ask' \| 'deny' }` | you take `host.open` |
| `agentName` | string | what your app calls its agent |
| `tools` | `'cli' \| 'mcp' \| 'native'` | how your agent reaches the tools |
| `commands` | `{ names, menu? }` | your command names; `menu`: you list one entry per type |
| `library` | `'home' \| 'cards' \| 'own'` | where the person finds artifacts; informational only (see below) |
| `sample` | `{ tiers?, images?, tools?, stream?, inherit? }` | you answer `sample.create`: a page's model round on your app's own model ([below](#samplecreate)) |
| `mcp` | boolean | you answer `mcp.listTools` and `mcp.callTool`: you lend your app's MCP servers to pages as `host:<name>` ([below](#mcpcalltool)) |
| `sessions` | `{ start?: boolean, models?: boolean }` | `start`: you take `session.start`: your app can start a new session whose first turn gets a message ([below](#sessionstart)). `models`: you also answer `session.models`: the models such a session can run on, for the person to pick one ([below](#sessionmodels)); it says nothing without `start` |

`library` changes nothing the daemon or the Shell does: the daemon checks the value, records it, writes it in its log
and in `GET /api/open-artifacts.harnesses`, and `doctor --session` prints it (`library (not said)` when it is left out).
Artifact events, the home page and `embedLibrary` work the same with any value or none. Leave it out when your app has
no place that lists artifacts; there is no separate value for that.

## Adapter → daemon

| Method | Params | Result |
| --- | --- | --- |
| `session.attach` | `session`, `workspace`, `title?`, `status?` (`idle` \| `running`), `pid?`, `may?`, `role?` | `{ key, inbox }` |
| `session.status` | `session`, `workspace`, `status` | `{ ok }` |
| `session.detach` | `session`, `workspace` | `{ ok }` |
| `session.rename` | `session`, `workspace`, `title` | `{ ok }` |
| `tools.list` | — | `{ tools }` (name, description, inputSchema, `actions`, `remoteActions`) |
| `tools.call` | `name`, `arguments`, `caller?` | the tool's result |
| `agent.wrote` | `paths`, `caller?` or `session`/`workspace` | `{ ok, artifacts? }` |
| `artifact.open` | `url`, `caller?` or `session`/`workspace` | `{ opened, view_url? }` |
| `inbox.take` | `session`/`workspace` or `caller` | `{ messages }` |
| `inbox.wait` | the same, `timeoutMs?` (default 10 minutes, at most an hour) | `{ messages }` |
| `inbox.return` | `session`/`workspace` or `caller`, `messages` (as `session.attach`'s `inbox` gave them, at most 500) | `{ ok, returned }`; feature `inbox.return` |
| `subscribe` | `on` | `{ ok }`; `event` notifications follow while on |
| `skill.get` | `form?` (`entry` \| `full`), `command?`, `agentName?`, `tools?`, `toolNames?`, `opens?`, `locale?` | `{ name, description, argumentHint, body, version, etag, prompt? }` |
| `commands.list` | `command?`, `locale?` | `{ commands }`: `text`, `type`, `title`, `description`, `templates?`, `remote?`, `origin?` |
| `embed.origins` | — | `{ origins, entries }`; an entry has `origin` or `pattern`, `kind` (`daemon` \| `frame` \| `server` \| `url`), `type?`, `remote` |
| `shell.command` | `view`, `command` (a host message) | `{ ok }` |
| `view.context` | `url`, `session?`, `workspace?` | `{ at, context, changed }`; owner session only |
| `runtime.status` | — | `RuntimeStatus` |
| `runtime.update` | `version?` | `{ installed, pending, message }` |
| `view.open` | `url` (`open-artifacts://artifact/<id>`, or this daemon's `http://<host>:<port>/a/<id>`) | `{ url, view_url, title?, view?, embed_url?, remote? }`: what `host.open` carries, without `session` |

`session.status` (and `session.attach`'s `status`) is what the person sees: while a session is `running`, the pages of
the artifacts its turn works on say its agent is working (the Shell's top bar, the library's badge, and the page
itself). A turn works on an artifact once it calls an artifact tool on it or makes it, opens it, writes its files
(`agent.wrote`), or takes a wake for it; a wake that reaches an idle session counts for the turn it starts. The pages of
its other artifacts stay as they are, and the turn's end forgets them all. Set it back to `idle` when the turn ends,
also when it fails or is stopped, or those pages keep saying so.

`skill.get` `opens` picks the skill's "show it" step: `host` (your app shows the page by itself), `agent-browser` (the
agent opens `view_url` in its own browser panel), `system` (the computer's browser), `link` (the agent gives the person
`view_url`). Left out, the daemon uses `host` when your caps (from `hello` or the profile) have `open`, else a general
step that covers a built-in browser and the computer's browser.

`view.open` is for the person opening an artifact from your app (a recent list, a link), when no agent asked. It
takes only this daemon's artifacts: another daemon's address, a published page or a `/page/` address is
`invalid_argument`, and an unknown id `not_found`. An adapter with `caps.open.embed: 'view'` gets a `view` and a
ticketed `embed_url`; any other gets `embed_url` without a ticket. The daemon shows nothing by itself.

`session` and `workspace` name a session of the calling harness. A session with no id is keyed by its workspace.
`may` is `{ create?, modify?, remove?, reply? }` ([tools](../integrating/tools.md#session-permissions)).

## Daemon → adapter

| Method | Params | Result |
| --- | --- | --- |
| `wake.deliver` | `session`, `workspace`, `artifact`, `artifactId`, `text`, `source` | `{ status, session? }`; `status` is `delivered`, `resumed`, `queued`, `drafted`, `held` or `failed` |
| `host.open` | `session`, `url`, `view_url`, `title?`, `view?`, `embed_url?`, `remote?` (`{ type, origins }`) | `{ opened }` |
| `shell.event` | `view`, `session`, `event` (a Shell message) | `{ ok }` |
| `sample.create` | `id`, `session?`, `workspace?`, `artifactId`, `artifact`, `system`, `turns`, `tier`, `model?`, `effort?`, `maxOutputTokens`, `tools?`, `lastRound?` | `{ text, stop, toolCalls?, model?, usage? }`; feature `sample.create`, [below](#samplecreate) |
| `mcp.listTools` | `server?`, `artifactId?` | `{ servers: [{ server, tools, authStatus? }] }`; feature `mcp.proxy`, [below](#mcpcalltool) |
| `mcp.callTool` | `id`, `server`, `tool`, `arguments`, `artifactId` | `{ content, structuredContent?, isError? }`; feature `mcp.proxy`, [below](#mcpcalltool) |
| `session.start` | `text`, `artifact` (`{ id, url, title, type, root }`), `model?`, `effort?` | `{ started, session?, workspace? }`; feature `session.start`, [below](#sessionstart) |
| `session.models` | none (`{}`) | `{ models: [{ id, label, group?, efforts?, defaultEffort? }], default? }`; feature `session.models`, [below](#sessionmodels) |

Over stdio the bridge forwards `wake.deliver` only when your caps have `wake`, and `host.open` and `shell.event` only
when they have `open`. Without them you get no such call;
the daemon does not send it, and one that came anyway is answered `method_not_found` by the bridge. It forwards
`sample.create` and `sample.cancel` only when your caps have `sample`, and passes your `sample.delta` on. It forwards `mcp.listTools`, `mcp.callTool` and `mcp.cancel` only when your caps have `mcp`, and `session.start` only when they have `sessions.start` (`session.models` only when they have `sessions.models` as well).

The daemon waits 30 seconds for an answer (`sample.create`: longer, `session.models`: 10 seconds, below). No answer, an error, `failed` or `held` keeps a
wake in the inbox ([wake](../integrating/wake.md)); only `held` skips the profile's nudge.

### `sample.create`

One model round of a page's `sample` call, sent only to an adapter whose `hello` caps declare `sample` and only when
the person chose that app as the page's model source. The daemon keeps consent, limits, the cache, the framing (the
`system` it sends) and the loop of page tool rounds; the adapter answers the one round. A walk-through is in
[sampling](https://github.com/openartifactsai/open-artifacts/blob/main/docs/integrating/sampling.md); the types are `HarnessSampleCreateParams` and `HarnessSampleCreateResult` in
`packages/protocol/src/sample.ts`.

It is not the session's agent answering. The round carries no conversation history and none of the session's tools;
`session` and `workspace` are informational only (the session that owns the artifact), and the round is not part of
that session's conversation.

| `caps.sample` field | Means |
| --- | --- |
| `tiers` | the tiers you have a model for (`quick`, `default`, `complex`); default all three |
| `images` | you take `images` on the final user turn |
| `tools` | you take `tools` and answer `toolCalls`; without it the daemon describes page tools in the text |
| `stream` | you send `sample.delta` while you write |
| `inherit` | you can answer `tier: 'inherit'` with the model the session uses |

| Param | |
| --- | --- |
| `id` | the round's id; `sample.delta` and `sample.cancel` name it |
| `turns` | `{ role: 'user', content, images? }`, `{ role: 'assistant', content, toolCalls? }`, `{ role: 'tool', results }` |
| `tier` | `quick`, `default`, `complex` or `inherit` |
| `maxOutputTokens` | the round's output cap |
| `tools` | the page's tools (`name`, `description`, `inputSchema?`), when you declared `caps.tools` |
| `lastRound` | answer, call no tool |

The result's `stop` is `end`, `length`, `tools` (with `toolCalls`: `{ id, name, input }`) or `refusal`; `usage` is
`{ input, output }` tokens. `model` is your app's own name for the model that answered, shown as it is in usage. On a
`lastRound`, tool calls in the answer are not run: the daemon takes the round's text as the answer and runs no other
round.

Two notifications go with it, each naming the round's `id`:

| Notification | Direction | Params | |
| --- | --- | --- | --- |
| `sample.delta` | adapter → daemon | `{ id, text }` | more text of the round (the delta, not the text so far), before the answer; only with `caps.sample.stream` |
| `sample.cancel` | daemon → adapter | `{ id }` | stop the round: abort the model call, and send nothing more for it (no delta, no answer) |

The daemon waits `SAMPLE_ROUND_TIMEOUT_MS` (295 000 ms) for the answer, then sends `sample.cancel`. Several rounds may
be in flight at once. A dropped connection ends every round on it.

To refuse, answer a JSON-RPC error whose `data.code` is one of:

| `data.code` | |
| --- | --- |
| `rate_limited` | your model or account is rate limited now |
| `unavailable` | your app cannot answer now |
| `not_granted` | your app's own rules do not let it answer for this page |
| `session_expired` | your app's own sign-in or key was rejected: the page hears `session_expired`, and the person is told to sign in to your app |
| `prompt_too_large` | the round does not fit your model's context |

Any other error is a failed round. An adapter without `caps.sample` answers `method_not_found`.

### `mcp.callTool`

One tool call of a page on a server your app lends, sent only to a WebSocket adapter whose `hello` caps declare `mcp`
(an adapter that polls is never asked). The page names the server `host:<name>`; the params name it without the
prefix. Before it calls you, the daemon checked that the page declared the tool, that the person allowed the page the
connector, and, for a tool your listing does not mark `readOnlyHint: true`, that the person confirmed the call. A
walk-through is in [connectors](https://github.com/openartifactsai/open-artifacts/blob/main/docs/integrating/connectors.md); the types are in `packages/protocol/src/page-mcp.ts`.

`mcp.listTools` answers the servers you lend: `{ servers: [{ server, tools, authStatus? }] }`, each tool
`{ name, description?, inputSchema?, outputSchema?, annotations? }`, `authStatus` `connected` (the default) or
`needs_reauth`. With `server`, only that one. The daemon routes `host:<name>` to the adapter whose listing has `<name>`,
the app whose session owns the artifact first; it waits 15 seconds for a listing and keeps it until the connection
goes.

| Param of `mcp.callTool` | |
| --- | --- |
| `id` | the call's id; `mcp.cancel` names it |
| `server`, `tool` | the server (without `host:`) and the tool |
| `arguments` | the page's input, an object |
| `artifactId` | the artifact whose page calls |

The result is the tool's: `content` (an array), `structuredContent?`, `isError?`. A tool that ran and failed is a
result with `isError: true`; the page hears `tool_error` with it. The daemon waits `HARNESS_MCP_CALL_TIMEOUT_MS`
(120 000 ms), and sends the notification `mcp.cancel` `{ id }` when the page stops waiting or the time passes: stop
the call and send no answer.

To refuse, answer a JSON-RPC error whose `data.code` is one of:

| `data.code` | The page hears |
| --- | --- |
| `rate_limited` | `rate_limited`, retryable; `data.retryAfterMs` passes on |
| `needs_reauth` | `needs_reauth` |
| `server_unavailable` | `server_unavailable`, retryable |
| `timeout` | `upstream_error`, retryable |

Any other error is `upstream_error`. An adapter without `caps.mcp` answers `method_not_found`.

### `session.start`

Start a new session of your app, sent only to a WebSocket adapter whose `hello` caps declare `sessions: { start: true }`
(an adapter that polls is never asked). It is only ever sent because the person picked your app ("New session") in the
page of an artifact no session owns (`POST /api/open-artifacts.artifacts.start`, [below](#other-http-routes-an-adapter-uses));
an agent's call of that route is refused. Declaring it is what gets your app offered there, also while none of its
sessions is attached. A walk-through is in [wake](../integrating/wake.md#starting-a-new-session).

| Param | |
| --- | --- |
| `text` | what the new session's first turn gets: what the person asked for, then how to take the artifact over (`Artifact {action: "adopt", url}`). Give it to the agent as it is |
| `artifact` | the artifact the session is started for: `{ id, url, title, type, root }` (`url` is `open-artifacts://artifact/<id>`, `root` its folder) |
| `model?` | the model the person picked: an `id` from your `session.models` answer ([below](#sessionmodels)). Only sent when your caps declare `sessions.models`; left out, the session runs on your app's default |
| `effort?` | the reasoning effort the person picked: the `id` of one of that model's `efforts`. Only ever sent with `model` |

Answer `{ started: true }` once the session exists, within `SESSION_START_TIMEOUT_MS` (30 000 ms); do not wait for its
turn to end. Add `session` (the new session's id, as you will attach it) when you know it at once: the daemon makes
that session the artifact's owner, and what was sent from the artifact meanwhile goes to it as after
`artifacts.assign`. Add `workspace` when you know the folder the session works in. Without `session` the owner stays
empty until the new session adopts the artifact, which `text` tells it to do. `{ started: false }`, an error or no
answer in time is a session that was not started: the person is told, and nothing changes.

An app with no adapter can be offered for a new session too: the daemon runs the `start` command of its profile
itself, which only a shipped profile or the person's own may have ([profile](profile.md#start)).

The daemon passes `model` and `effort` on without asking for your list again: check them yourself, and refuse a model
or an effort your app does not offer now (`{ started: false }` or an error) instead of starting on another one.

### `session.models`

The models a new session of your app can run on, sent only to an adapter that takes `session.start` and whose caps
also declare `sessions: { start: true, models: true }`. The daemon asks each time the person is about to pick your app
for an artifact (`GET /api/open-artifacts.harnesses.models`, [below](#other-http-routes-an-adapter-uses)); the params are
`{}`. Answer within `SESSION_MODELS_TIMEOUT_MS` (10 000 ms):

```json
{
  "models": [
    { "id": "opus", "label": "Opus", "group": "Anthropic",
      "efforts": [{ "id": "low", "label": "Low" }, { "id": "high", "label": "High" }], "defaultEffort": "high" }
  ],
  "default": { "model": "opus", "effort": "high" }
}
```

| Field | |
| --- | --- |
| `models[].id` | your own id for the model: what `session.start` gets back as `model` |
| `models[].label` | its name, as your app shows it |
| `models[].group?` | a heading to list it under (its provider), when your app has more than one |
| `models[].efforts?` | the reasoning efforts it offers, each `{ id, label }`; left out or empty: none to pick. `session.start` gets the `id` back as `effort` |
| `models[].defaultEffort?` | the effort it uses when none is picked: the `id` of one of its `efforts` |
| `default?` | `{ model, effort? }`: what a new session runs on when the person picks nothing; the picker starts on it. Left out, the picker starts on **Default model** instead, which sends no `model`: you start on your own default |

The daemon cuts the answer down before the person sees it. It keeps the first 200 models that are objects with an `id`
of their own: a non-empty string of at most 200 characters with no whitespace at either end; a second model with the
same `id` is dropped. A `label` or `group` longer than 200 characters is cut, and a missing `label` is the `id`. It
keeps the first 20 `efforts` of a model by the same rule, `defaultEffort` only when it is one of them, and `default`
only when its `model` is one of the models kept (its `effort` only when that model offers it). An error, no answer in
time or an answer with no usable model is no models, not a failure: the person starts the session on your app's
default, and `session.start` carries no `model`.

## Events

Besides `event`, the notifications are `sample.delta` and `sample.cancel` ([above](#samplecreate)), and `mcp.cancel` ([above](#mcpcalltool)). The notification
`event` carries one of these, while you are subscribed:

| `type` | Fields | When |
| --- | --- | --- |
| `artifacts/changed` | `id`, `author?`, `paths?`, `removed?` | an artifact was created, written or removed |
| `types/changed` | — | types were installed, removed or changed |
| `harness/changed` | — | adapters or sessions changed |
| `wake/state` | `artifactId`, `via`, `status?` | how a wake went; `via: "taken"` when the owner session took its waiting wakes from the inbox |
| `view/context` | `id`, `at` (`url` too, from the Harness API) | the owner's selection on a page changed (best effort) |
| `embed/origins` | `origins`, `entries` | the result of `embed.origins` changed |
| `runtime/update` | `current`, `available`, `installed` | an update exists, or was installed |

## Errors

A failure is a JSON-RPC error whose `data` is `{ code, message, fix? }`. `fix` is one line saying what to do.

| JSON-RPC code | When |
| --- | --- |
| `-32700` | the message is not JSON (`data.code` `parse_error`) |
| `-32601` | unknown method (`data.code` `method_not_found`) |
| `-32602` | bad params (`data.code` `invalid_argument`) |
| `-32000` | any other failure; read `data.code` |

Decide by `data.code`, not by the JSON-RPC code.

The WebSocket and the stdio bridge answer with the same numbers (`rpcErrorCode` in `@openartifactsai/protocol`); HTTP
polling answers with an HTTP status and the same `{ code, message, fix? }` body.

| `data.code` | Meaning |
| --- | --- |
| `invalid_argument` | a param is missing or wrong |
| `parse_error` | the line or message is not JSON |
| `method_not_found` | no such method, or one the adapter did not declare in its caps (stdio) |
| `unauthorized` | no `hello` yet, or a bad token |
| `unsupported_protocol` | no protocol version both sides speak |
| `unknown_session` | polling before `session.attach` |
| `not_found` | the artifact, session, file or version does not exist |
| `not_granted` | session permissions, owner-only reads, person-only actions, updates turned off |
| `conflict` | the thing changed under you, or already exists |
| `duplicate` | a comment reply identical to the last one |
| `too_large` | the body or file is over the limit |
| `bad_path` | a path leaves the artifact folder, names its bookkeeping, or has quotes or control characters |
| `rate_limited` | too many calls; try later |
| `unsupported` | the daemon or type does not do this (for example a feature it does not list) |
| `unknown_action`, `unknown_tool` | the type has no such action; no such tool |
| `type_missing`, `type_not_runnable` | the type is not installed (an import names its id, uid and source); it is installed but cannot run |
| `type_mismatch` | the artifact was made with another type of the same id (its `typeUid` differs): not opened or written |
| `server_failed` | a type server or remote type failed |
| `unavailable` | the service needed is not there right now |
| `newer_release` | the artifact was written by a newer Open Artifacts; update first |
| `redirected` | a link host answered with a redirect; nothing was sent on |
| `download_failed`, `integrity_failed`, `bad_archive` | a runtime update or type package could not be fetched, did not match its integrity, or did not unpack safely (also an archive to import that is not one) |
| `connect_failed`, `disconnected`, `timeout` | a connection could not be made, closed, or took too long; from the kit also: the app stopped the daemon (`harness.daemon.stop()`) and has not started it again |
| `no_daemon`, `daemon_failed` | the kit or CLI found no daemon, or could not start one |
| `error` | anything else |

Types may add codes of their own. A tool's own failure comes back as a normal result with `error`, not as a JSON-RPC
error.

## HTTP polling

For an adapter that cannot keep a WebSocket. Every route is `POST` with `Authorization: Bearer <token>` and
`X-Open-Artifacts-Harness: <name>`; the body is JSON.

| Route | Body | Answer |
| --- | --- | --- |
| `/api/open-artifacts.session.attach` | attach params, `agentName?` | `{ key, inbox }` |
| `/api/open-artifacts.session.wait` | `session`, `workspace`, `timeoutMs?` (default 25 s, 1 s to 60 s) | `{ messages }`, `[]` after the timeout |
| `/api/open-artifacts.session.status` | `session`, `workspace`, `status` | `{ ok }` |
| `/api/open-artifacts.session.detach` | `session`, `workspace` | `{ ok }` |
| `/api/open-artifacts.tools` | — | `{ tools }` |
| `/api/open-artifacts.tools.call` | `name`, `arguments`, `caller?` | the tool's result |

One `session.wait` at a time per session; a new one ends the old with `[]`. A polling adapter not seen for 20 seconds
counts as disconnected, and its wakes go to the inbox. Polling adapters get no events and no `host.open`, `shell.event`
or `wake.deliver`: their wakes arrive as `session.wait` messages.

## Other HTTP routes an adapter uses

| Route | |
| --- | --- |
| `GET /__open-artifacts/health` | the daemon is up |
| `GET /api/open-artifacts.harnesses` | adapters, their caps, the sessions (token). Also `starters`, left out when there are none: the apps the daemon can start a session of itself now, by the `start` command of their profile ([profile](profile.md#start)), each `{ id: "profile:<harness>", harness, title, models }` (`models`: it lists models to pick from). An app with a connected adapter that declares `caps.sessions.start` (not a polling one) is not among them: its adapter is asked. Then each agent of an app that hosts several that the daemon can start through that app's command line: `{ id: "host:<host>:<agent>", harness: "<host>:<agent>", title: "<App> · <agent's name>", models: true }`, `host` being `paseo` (the providers that Paseo's running daemon has enabled and available, `paseo provider ls --json`) or `orca` (`orca agent installed --json`, while Orca runs). What a host lists is kept a minute; when none is kept yet the route waits up to 1.5 seconds for it, and agents listed later show on the next call. The daemon finds `paseo` and `orca` on `PATH` or where the apps install them; `OPEN_ARTIFACTS_PASEO` and `OPEN_ARTIFACTS_ORCA` name another path, or `off` to leave the app out. And `recent`, left out when there are none: the sessions that are not attached but that the daemon can still start a turn in, each `{ key, harness, harnessTitle?, session, workspace, title?, seenAt }`: ones it heard from in the last 24 hours (a hook, a tool call) of an app whose profile has a `nudge` that can run now ([profile](profile.md#nudge)), the latest first, at most 5 an app. The person can hand an artifact no session owns to one of them: `POST /api/open-artifacts.artifacts.assign` `{ id, session: key }`, which also takes the key of a session that is online; the daemon runs the nudge first, with how to take the artifact over as its message, and makes the session the owner only when the command succeeds (502 `unavailable` otherwise, and nothing changes). An artifact that has an owner is refused (`conflict`) unless `move: true` is sent, which moves it: what still waited with the session it leaves follows it |
| `GET /api/open-artifacts.harnesses.models?adapter=<id>` | the models a new session of the app of adapter connection `adapter` (`adapters[].id` of `harnesses`) can run on: your `session.models` answer, cut down as [above](#sessionmodels), `{ models, default? }`. `{ models: [] }` for an adapter that does not declare `caps.sessions.start` and `caps.sessions.models`, is not connected, or did not answer. With `adapter=profile:<harness>` (a `starters[].id`): the models the running app lists when that profile's `start` has `modelsFrom`, else its `models`, each `{ id, label }`, with no efforts and no `default`. With `adapter=host:<host>:<agent>`: the models that host lists for that agent (`paseo provider models --json -- <provider>`, each with its thinking options as efforts; `orca agent models --agent=<agent> --json`, each with its efforts, and the model Orca marks as its default as `default`), kept a minute; none for an agent that takes no model at launch. From the Shell or the command line only (`not_granted`, 403, from another origin); `invalid_argument` without `adapter`, and for a `POST` (405) |
| `POST /api/open-artifacts.artifacts.start` | the person's call, from the Shell or the command line (never from inside a session, never from another origin): `{ id, adapter, text?, model?, effort? }` has the app of the adapter connection `adapter` (`adapters[].id` of `harnesses`, with `caps.sessions.start`) start a session for artifact `id`, which no session owns. `text`: the first message (trimmed, at most 8,000 UTF-8 bytes); the take-over prompt is added unless the text names the artifact's link already, and is the whole message when `text` is left out. `model` and `effort`: what the person picked from `harnesses.models` (each trimmed, at most 200 characters), handed to `session.start` as they are; `invalid_argument` for `effort` without `model`, and for `model` when the adapter does not declare `caps.sessions.models`. Answers `{ artifact, started: true, session? }`; `not_found` when no such adapter can start a session, `conflict` when the artifact has an owner, unless `move: true` is sent: the person picked a new session for an artifact a session has, and the artifact leaves that one (`artifacts.assign` takes `move` the same way). `unavailable` (502) when the app did not start one, `timeout` (504) when it did not answer. `adapter` may also be a `starters[].id` (`profile:<harness>`): the daemon then runs that profile's `start` command itself, and the session id it prints, when it prints one, is the `session`. There `effort` is `invalid_argument` (the app takes a model, not a reasoning effort), and so is a `model` the profile does not list; `not_found` when the profile has no `start`; `unavailable` (502) when the app is not running or its program is not found (the fix: open the app and try again), and when the command fails or runs longer than 30 seconds. `adapter` may be a `host:<host>:<agent>` too: the daemon has that app start the agent, in the folder of the project the artifact was made for, else the artifact's own folder, with the person's text and the take-over prompt: `paseo run --no-wait --json --provider=<agent> [--model=<model>] [--thinking=<effort>] --cwd=<folder> --title=<title> -- <text>`, or `orca agent launch --agent=<agent> [--model=<model>] [--effort=<effort>] --prompt=<text> --json` run in the folder (a folder no Orca workspace contains is added first: `orca repo add --path=<folder> --kind=folder`). Neither says the new session's id, so the answer has no `session`: the session adopts the artifact itself. `not_found` when the app does not list that agent now; `invalid_argument` for a `model` or `effort` that agent's list (when the daemon has one) does not have, or one that begins with `-`; `unavailable` (502) when the app is not running or its command fails |
| `GET /api/open-artifacts.embed` | the declared host origins (`hosts`) and `embed.origins` |
