An open-source, faster Devin alternative
TypeScript
docs: polish agent sessions examples
Igor Zalutski77c4af08828f
diff --git a/docs/agent-sessions/agents.mdx b/docs/agent-sessions/agents.mdxindex 8928b069..e760478d 100644--- a/docs/agent-sessions/agents.mdx+++ b/docs/agent-sessions/agents.mdx@@ -14,7 +14,7 @@ Content-Type: application/json"name": "reviewer","runtime": "claude","model": "anthropic/claude-opus-4-8",- "prompt": "Review the target repo. Run tests, summarize risks, and say the final result.",+ "prompt": "Review the repo. Run tests. Summarize risks.","key": "sk-ant-..."}```diff --git a/docs/agent-sessions/api-reference.mdx b/docs/agent-sessions/api-reference.mdxindex 7081e4ff..776ff625 100644--- a/docs/agent-sessions/api-reference.mdx+++ b/docs/agent-sessions/api-reference.mdx@@ -9,17 +9,19 @@ Base URL `https://api.opencomputer.dev/v3`. Management calls authenticate with y| Method · Path | Purpose || --- | --- |-| `POST /sessions` | Start a session. Body: `agent` (required), `input`, `key?`, `webhook?`, `destinations?[]`, `limits?: { tokens?, turn_seconds?, turns? }`. Returns `{ session, client_token }`. |+| `POST /sessions` | Start a session. Returns `{ session, client_token }`. || `GET /sessions/:id` | Fetch a session. || `GET /sessions?status=&agent=&key=&after=&before=&limit=` | List sessions (filtered, paginated). || `POST /sessions/:id/archive` | Cancel any active turn, then close (read-only). || `POST /sessions/:id/cancel` | Cooperatively stop the active turn (no-op if not running). || `GET /sessions/:id/result` | The result helper — `{ last_turn, result? }` (the resolved final event). || `GET /sessions/:id/turns` · `GET …/turns/:turnId` | Per-turn history: timing, usage, error. |-| `POST /sessions/:id/client-tokens` | Mint a client token. Body: `scopes?` (subset of `read`, `steer`), `ttl?` (seconds; clamped to 60–86400). |+| `POST /sessions/:id/client-tokens` | Mint a client token. |`agent` is **required** (create a saved [agent](#agents) first); a resolvable Anthropic [credential](#credentials) is also required (`422 no_credential` otherwise). `key` gives get-or-create (one session per key); a request-level `Idempotency-Key` header makes a keyless create retry-safe. `input` is the task — a string or a full [envelope](/agent-sessions/messaging#the-envelope) (structured context rides `input.refs`: `repo`/`branch`/`commit`/`issue`/…). `limits` `{ tokens, turn_seconds, turns }` are **non-monetary** — token budget, per-turn wall-clock, auto-run count; hitting one ends the turn with a matching `last_turn.yield_reason`. Destinations on an idempotent create-replay are ignored — manage them via the [destinations API](#destinations).+Client tokens accept `scopes?` (subset of `read`, `steer`) and `ttl?` seconds, clamped to 60–86400.+```Session = { id, status, head, input_cursor,agent_snapshot: { prompt_hash, model, runtime, revision },@@ -27,8 +29,10 @@ Session = { id, status, head, input_cursor,last_turn: { id, state, yield_reason?, result_event_id? },usage, limits: { tokens?, turn_seconds?, turns? }, key?, created_at }-Turn = { id, state, yield_reason?, started_at?, completed_at?, // from GET …/result and …/turns- result_event_id?, error?, active_seconds, usage }+Turn = {+ id, state, yield_reason?, result_event_id?, error?,+ started_at?, completed_at?, active_seconds, usage+}````yield_reason` (`completed | needs_input | error | budget_exceeded | deadline_exceeded | max_turns | canceled`; `requires_action` is reserved, not emitted yet) is the machine-readable "why the turn ended" — `needs_input` means the agent asked a question; answer it by [steering](#steer).@@ -37,34 +41,42 @@ Turn = { id, state, yield_reason?, started_at?, completed_at?, // from GET| Method · Path | Purpose || --- | --- |-| `GET /sessions/:id/events?after=<seq>&level=<lvl>&type=&turn_id=&limit=<n>` | Read events since a cursor (filter by `type` exact or `prefix.*`, or `turn_id`). |+| `GET /sessions/:id/events?after=<seq>&level=<lvl>` | Read events since a cursor. || `GET /sessions/:id/events?after=<seq>&level=<lvl>&stream=sse` | Live SSE stream from a cursor. || `GET /sessions/:id/events/:eventId` | Fetch one event (resolve `result_event_id`). || `GET /sessions/:id/events/:eventId/content` | Fetch a blob-backed body (large outputs). |-| `GET /sessions/:id/messages?after=<seq>&limit=<n>` | User-message history (alias for `level=user` + `type=*.message`). |+| `GET /sessions/:id/messages` | User-message history. |++Filter events by `type` (exact or `prefix.*`), `turn_id`, and `limit`. `GET …/messages` is an alias for `level=user` + `type=*.message`.`after` resumes from a `seq`; `level` is a **visibility threshold** — `user` returns only user-facing events, `progress` adds work updates, `internal` adds everything (see [levels](/agent-sessions/events#levels)). Omitting `level` defaults to `internal` (you get everything). Switch on [`type`](/agent-sessions/events#event-shape), don't parse prose.```-Event = { id, seq, ts, session, actor, type, level, body, refs, turn_id?,- content_ref?, body_truncated?, body_bytes? } // content_ref + body_* present when the body spilled to a blob+Event = {+ id, seq, ts, session, actor, type, level, body, refs, turn_id?,+ content_ref?, body_truncated?, body_bytes?+}```## Steer| Method · Path | Purpose || --- | --- |-| `POST /sessions/:id/messages` | Append an input message; wakes the session. Body: `{ text, idempotency_key? }` or `{ envelope }`. `202` (or `200` on an idempotent replay) → `{ event: { id, seq }, session: { id, status, head } }`. |+| `POST /sessions/:id/messages` | Append an input message; wakes the session. |++Body: `{ text, idempotency_key? }` or `{ envelope }`. Returns `202` (or `200` on idempotent replay) with `{ event: { id, seq }, session: { id, status, head } }`.## Destinations| Method · Path | Purpose || --- | --- |-| `POST /sessions/:id/destinations` | Register a webhook. Body: `url`, `secret?`, `level?` (`user`), `types?[]` (event-type filter; exact or `prefix.*`), `include_raw?` (`false`), `enabled?` (`true`). |+| `POST /sessions/:id/destinations` | Register a webhook destination. || `GET /sessions/:id/destinations` · `GET …/:did` | List / fetch. || `PATCH /sessions/:id/destinations/:did` | Pause/resume (`enabled`), retune `level`/`types`, rotate `secret`. || `DELETE /sessions/:id/destinations/:did` | Remove. |+Destination body: `url`, `secret?`, `level?` (`user`), `types?[]`, `include_raw?` (`false`), `enabled?` (`true`). `types` accepts exact event types or `prefix.*`.+## Deliveries| Method · Path | Purpose |@@ -76,19 +88,25 @@ Event = { id, seq, ts, session, actor, type, level, body, refs, turn_id?,See [Webhooks](/agent-sessions/webhooks#delivery-contract) for the signing and delivery contract.```-Destination = { id, session, kind, url, level, types, include_raw, enabled,- has_secret, created_after_seq, created_at, updated_at } // secret never returned — has_secret signals it's set-Delivery = { id, session, destination, event_id, event_seq, status, attempts,- last_attempt_at, response_code?, error?, created_at, updated_at }+Destination = {+ id, session, kind, url, level, types, include_raw, enabled,+ has_secret, created_after_seq, created_at, updated_at+}+Delivery = {+ id, session, destination, event_id, event_seq, status, attempts,+ last_attempt_at, response_code?, error?, created_at, updated_at+}```## Agents| Method · Path | Purpose || --- | --- |-| `POST /agents` | Create a reusable agent. Body: `name`, `prompt`, `model`, `runtime?` (`claude`), `key?` (Anthropic key — creates + attaches a [credential](#credentials)), `credential?` (reference an existing one), `limits?: { tokens?, turn_seconds?, turns? }`. Idempotent by `(owner, name)`. |+| `POST /agents` | Create a reusable agent. || `GET /agents/:id` · `GET /agents` | Fetch / list. |-| `PATCH /agents/:id` | Update `prompt?` / `model?` / `key?` (rotate) / `credential?` / `limits?`. Never affects existing sessions (snapshots are pinned). |+| `PATCH /agents/:id` | Update the agent for future sessions. |++Create body: `name`, `prompt`, `model`, `runtime?` (`claude`), `key?`, `credential?`, `limits?`. Patch accepts `prompt?`, `model?`, `key?`, `credential?`, and `limits?`.Pass `key` **or** `credential` (or neither → org default). The agent's `limits` are the defaults for its sessions; a session's own `limits` override. Each agent has a monotonic `revision` (bumped on PATCH) that sessions pin in `agent_snapshot.revision`, so you can tell which version produced a run.@@ -96,10 +114,12 @@ Pass `key` **or** `credential` (or neither → org default). The agent's `limits| Method · Path | Purpose || --- | --- |-| `POST /credentials` | Add a provider key (Anthropic). Body: `provider`, `key`, `name?`, `is_default?`. Key is write-only. **Required** — sessions run on your key (no platform billing yet). |+| `POST /credentials` | Add a provider key. || `GET /credentials` · `DELETE /credentials/:id` | List / remove. || `PUT /credentials/default` | Set the org default to a credential (its provider is derived). Body: `credential`. |+Credential body: `provider`, `key`, `name?`, `is_default?`. Keys are write-only. A credential is **required**; sessions run on your key (no platform billing yet).+```Credential = { id, provider, name?, last4, is_default, created_at }ClientToken = { token, scopes, expires_at }diff --git a/docs/agent-sessions/artifacts.mdx b/docs/agent-sessions/artifacts.mdxindex 4fd9940e..8f1984d4 100644--- a/docs/agent-sessions/artifacts.mdx+++ b/docs/agent-sessions/artifacts.mdx@@ -28,9 +28,9 @@ Each publish appends a `user`-level event and upserts the artifact, so it reacheThe same snapshot-plus-stream pattern as [events](/agent-sessions/events): list on load, subscribe for changes.```-GET /v3/sessions/:id/artifacts → [Artifact] # the panel on load (survives refresh)-GET /v3/sessions/:id/artifacts/:key/content # durable file bytes-events: artifact.published | artifact.updated | artifact.removed (level: user)+GET /v3/sessions/:id/artifacts+GET /v3/sessions/:id/artifacts/:key/content+events: artifact.published | artifact.updated | artifact.removedArtifact = { key, kind: "preview" | "file" | "link", title?, status?, url?,content_type?, bytes?, created_at, updated_at }diff --git a/docs/agent-sessions/authentication.mdx b/docs/agent-sessions/authentication.mdxindex be0cf4a2..b26e9412 100644--- a/docs/agent-sessions/authentication.mdx+++ b/docs/agent-sessions/authentication.mdx@@ -38,9 +38,10 @@ The pattern: your backend creates the session with the org key, then hands the `<Warning>A client token isn't free to hand out: each `steer` starts a turn, which **consumes tokens on your Anthropic key** for the session it's scoped to. Mint short-lived tokens, and rely on the session's [limits](/agent-sessions/sessions#limits) (`tokens`/`turn_seconds`/`turns`) to cap exposure.</Warning>```-browser ──(create task)──▶ your backend ──(org key)──▶ POST /v3/sessions-browser ◀──(client_token)── your backend-browser ──(client_token)──▶ GET …/events (SSE) · POST …/messages+browser -> your backend: create task+backend -> OpenComputer: POST /v3/sessions (org key)+backend -> browser: client_token+browser -> OpenComputer: stream + steer (client_token)```For the SSE stream the browser passes the client token as `?token=` (native `EventSource` can't set an `Authorization` header); other calls use the `Authorization` header normally.diff --git a/docs/agent-sessions/durability.mdx b/docs/agent-sessions/durability.mdxindex e89fc561..8e249581 100644--- a/docs/agent-sessions/durability.mdx+++ b/docs/agent-sessions/durability.mdx@@ -52,10 +52,12 @@ What's guaranteed today, and what isn't:| --- | --- || Client disconnects | Reconnect from your cursor; nothing lost. || Session idles | Sandbox hibernates; resumes intact on the next message. |-| Runtime **crashes** | **Auto-restarted in the same sandbox; continues from the on-box journal** — work since the last journaled step may repeat (make side effects idempotent). |+| Runtime **crashes** | Auto-restarted; continues from the on-box journal. || Runtime **hangs** | Bounded by the turn deadline; the turn ends `deadline_exceeded` — steer to continue. |-| Sandbox lost **while idle** | Recreated and **restored from the last checkpoint**; conversation resumes from the last completed turn. **Uncommitted hands-sandbox files are not restored** — commit/push to keep them. |-| Sandbox lost **mid-turn** | That one turn **re-runs** from the log. Only **logged / committed / delivered** work product is guaranteed. |+| Sandbox lost **while idle** | Recreated from the last checkpoint. |+| Sandbox lost **mid-turn** | That turn re-runs from the log. |++Work since the last journaled step may repeat, so make side effects idempotent. Uncommitted hands-sandbox files are not restored after sandbox loss; commit or push to keep them.<Warning>The one edge not yet covered: a sandbox lost **mid-turn** re-runs that turn rather than resuming mid-thought — so in-flight, unlogged work can be redone. Build idempotent side effects, and treat the event log (and delivered webhooks) as your durable record. Byte-exact **mid-turn** resume is coming in a later release.diff --git a/docs/agent-sessions/events.mdx b/docs/agent-sessions/events.mdxindex 4f6f5987..24a1352f 100644--- a/docs/agent-sessions/events.mdx+++ b/docs/agent-sessions/events.mdx@@ -46,11 +46,13 @@ The stable contract is the top-level **`type`** — **switch on it, don't parseEvery event carries a `level` saying **who it's for**. You filter the stream (and webhook deliveries) by it, so each surface shows the right amount of detail.-| Level | What lands here | Reach for it when you want… |+| Level | Contains | Use for || --- | --- | --- |-| `user` | What a person is meant to read — the answer, results, a question back to them. The default for webhook delivery. | a chat bubble, the final result, a notification |-| `progress` | Plain-language step updates: "cloning the repo", "running tests", "found 3 failures". | a live "what's it doing right now" feed or status line |-| `internal` | Tool calls and runtime detail — verbose, not meant for end users (the model's private reasoning is never surfaced). | debugging, an audit trail, your own internal console |+| `user` | Answers, results, and questions. | Chat, final results, notifications. |+| `progress` | Plain-language work updates. | Activity feeds and status lines. |+| `internal` | Tool calls and runtime detail. | Debug consoles and audit trails. |++The model's private reasoning is never surfaced. Webhooks default to `user`.Filtering is **cumulative** — `user` is the narrowest, `internal` is everything:diff --git a/docs/agent-sessions/prompting.mdx b/docs/agent-sessions/prompting.mdxindex df2776d0..95efb10f 100644--- a/docs/agent-sessions/prompting.mdx+++ b/docs/agent-sessions/prompting.mdx@@ -28,13 +28,15 @@ Operating rules:- Prefer small, verifiable changes over large rewrites.- Run the relevant tests or commands before saying the work is done.- Keep commands idempotent where possible. A turn may be retried after a crash.-- Do not hide failures. If a command fails, inspect the output, fix the issue, and retry.-- If you need a decision, ask one clear question and stop. Otherwise choose a reasonable default and continue.+- Do not hide failures. Inspect output, fix the issue, and retry.+- If blocked, ask one clear question and stop.+- Otherwise choose a reasonable default and continue.Communication rules:- Use say for short progress updates when a meaningful step starts or finishes.-- Do not narrate private chain-of-thought. Report observable work: files changed, commands run, results found.-- End each successful turn with a final say that includes what changed and how to verify it.+- Do not narrate private chain-of-thought.+- Report observable work: files changed, commands run, results found.+- End with a final say: what changed and how to verify it.- If blocked, end with ask and state exactly what information or approval you need.Task:@@ -46,7 +48,9 @@ Task:For a Lovable-style builder, add a clear build target and preview convention:```txt-You are an app-building agent. Turn the user's request into a working web app in your sandbox, then keep improving it as they chat with you.+You are an app-building agent.+Build a working web app in your sandbox.+Keep improving it as the user chats with you.Build rules:- Work in /workspace.@@ -56,9 +60,9 @@ Build rules:- Keep each follow-up change small, then verify the app still starts.User communication:-- Say what you are doing at useful milestones: scaffolding, installing, editing, running, verifying.+- Say useful milestones: scaffolding, installing, editing, running, verifying.- When the app is running, say what was built and what the user can ask for next.-- Ask only when the request is ambiguous enough that proceeding would likely waste the user's time.+- Ask only when proceeding would likely waste the user's time.```<Note>First-class preview artifacts are coming soon. Until then, treat preview instructions as a convention for your app and event renderer, not as a guaranteed platform event.</Note>@@ -84,7 +88,8 @@ Do not bury machine-readable context in prose. Pass it in the message envelope oThen include a rule in the prompt:```txt-If refs.repo, refs.branch, refs.commit, refs.issue, or refs.pr are present, treat them as authoritative task context. Do not infer those values from prose.+Treat refs.repo, refs.branch, refs.commit, refs.issue, and refs.pr+as authoritative task context. Do not infer those values from prose.```## Make outputs easy to renderdiff --git a/docs/agent-sessions/quickstart.mdx b/docs/agent-sessions/quickstart.mdxindex d76571b0..0c814753 100644--- a/docs/agent-sessions/quickstart.mdx+++ b/docs/agent-sessions/quickstart.mdx@@ -38,7 +38,7 @@ Content-Type: application/json"name": "quickstart-coder","runtime": "claude","model": "anthropic/claude-opus-4-8",- "prompt": "You are a coding agent. Work in /workspace. Use bash/read/write/ls for all work. Use say for concise progress and final results. Ask only when blocked.",+ "prompt": "Work in /workspace. Say progress. Ask only when blocked.","key": "sk-ant-...","limits": { "turns": 4, "turn_seconds": 600 }}@@ -81,15 +81,21 @@ Response:Use the `client_token` in the browser. Ask for `progress` for a good activity feed, or `internal` for an operator/debug view.```http-GET https://api.opencomputer.dev/v3/sessions/sess_.../events?stream=sse&level=progress&token=ct_...+GET /v3/sessions/sess_.../events?stream=sse&level=progress&token=ct_...+Host: api.opencomputer.dev```In a browser:```js-const events = new EventSource(- `${OC}/v3/sessions/${sessionId}/events?stream=sse&level=progress&token=${clientToken}`,-);+const url = new URL(`${OC}/v3/sessions/${sessionId}/events`);+url.search = new URLSearchParams({+ stream: "sse",+ level: "progress",+ token: clientToken,+});++const events = new EventSource(url.toString());events.onmessage = (message) => {const event = JSON.parse(message.data);@@ -104,10 +110,12 @@ Each event's `seq` is sent as the SSE `id`, so `EventSource` resumes automaticalSwitch on the event `type`. Do not parse prose to decide whether work finished or failed.```json-{ "type": "agent.message", "level": "user", "body": { "text": "Done. I built..." } }-{ "type": "tool.call", "level": "progress", "body": { "tool": "bash", "args_summary": "npm test" } }-{ "type": "exec.completed", "level": "progress", "body": { "exit_code": 0, "summary": "12 tests passed" } }-{ "type": "turn.completed", "level": "user", "body": { "yield_reason": "completed", "result_event_id": "evt_..." } }+[+ { "type": "agent.message", "body": { "text": "Done." } },+ { "type": "tool.call", "body": { "args_summary": "npm test" } },+ { "type": "exec.completed", "body": { "exit_code": 0 } },+ { "type": "turn.completed", "body": { "yield_reason": "completed" } }+]```Handle `turn.completed.body.yield_reason` explicitly:diff --git a/docs/agent-sessions/runtime-tools.mdx b/docs/agent-sessions/runtime-tools.mdxindex d309880e..c6aed53c 100644--- a/docs/agent-sessions/runtime-tools.mdx+++ b/docs/agent-sessions/runtime-tools.mdx@@ -9,13 +9,15 @@ When you write a prompt for the `claude` [runtime](/agent-sessions/runtimes), it| Tool | What it does || --- | --- |-| `bash` | Run a shell command in the sandbox — the **only** place commands run. Each call is a fresh shell, so use absolute paths or `cd /workspace && …`. Returns exit code + stdout/stderr. |+| `bash` | Run a shell command in the sandbox. || `read` | Read a file from the sandbox. || `write` | Write a file to the sandbox. || `ls` | List a directory in the sandbox. |-| `use_repo` | Check out a **public** git repository into the workspace. (Private-repo access and prepared [workspaces](/agent-sessions/workspaces) — connections, repo catalog, scoped tokens — are coming soon; for launch, point it at a public URL or `git clone` via `bash`.) |+| `use_repo` | Check out a public git repository. |-These map to events you can stream: a `bash` run surfaces as an [`exec.completed`](/agent-sessions/events#event-shape) event (`{ command, exit_code, summary }`), with large output available via `content_ref`.+`bash` is the only place commands run. Each call is a fresh shell, so use absolute paths or `cd /workspace && ...`. A run surfaces as an [`exec.completed`](/agent-sessions/events#event-shape) event (`{ command, exit_code, summary }`), with large output available via `content_ref`.++For launch, `use_repo` works with public repos. Private-repo access and prepared [workspaces](/agent-sessions/workspaces) are coming soon; until then, use a public URL or `git clone` via `bash`.<Note>**Network:** the sandbox has **open outbound internet** by default (so `git clone`, package installs, and API calls just work), with private, loopback, link-local, and cloud-metadata addresses blocked. Per-agent egress allowlists are coming.</Note>@@ -23,10 +25,12 @@ These map to events you can stream: a `bash` run surfaces as an [`exec.completed| Tool | What it does || --- | --- |-| `say` | Emit a message to the user — a `user`-level [`message`](/agent-sessions/events) event. The agent's final `say` is the session's result. |-| `ask` | Ask the user a question and **pause** — the turn ends with `yield_reason: "needs_input"`. Answer by [steering](/agent-sessions/messaging) a reply, which wakes the session. |+| `say` | Emit a `user`-level message. |+| `ask` | Ask a question and pause the turn. |++The agent's final `say` is the session result. `ask` ends the turn with `yield_reason: "needs_input"`; answer by [steering](/agent-sessions/messaging) a reply, which wakes the session.-<Note>`ask` is how an agent gets a decision today. The turn yields rather than blocking; your app sees `last_turn.yield_reason = "needs_input"` and replies with a steer. The formal blocking `ask` state is coming soon.</Note>+<Note>The formal blocking `ask` state is coming soon. Today the turn yields rather than blocking.</Note>## Delivering work to external systemsdiff --git a/docs/agent-sessions/runtimes.mdx b/docs/agent-sessions/runtimes.mdxindex 915d6447..1729542e 100644--- a/docs/agent-sessions/runtimes.mdx+++ b/docs/agent-sessions/runtimes.mdx@@ -18,7 +18,7 @@ Content-Type: application/json"name": "reviewer","runtime": "claude","model": "anthropic/claude-opus-4-8",- "prompt": "Review code in the sandbox. Run tests, explain risks, and say the final result.",+ "prompt": "Review code in the sandbox. Run tests. Explain risks.","credential": "cred_..."}```diff --git a/docs/agent-sessions/webhooks.mdx b/docs/agent-sessions/webhooks.mdxindex b086e934..fb9d590c 100644--- a/docs/agent-sessions/webhooks.mdx+++ b/docs/agent-sessions/webhooks.mdx@@ -44,7 +44,10 @@ Every send and its outcome — the data behind a deliveries dashboard.A delivery moves `pending → delivering → delivered`, or `failed` (retrying) → `dead_letter` after the max attempts.```-Delivery = { id, session, destination, event_id, event_seq, status, attempts, last_attempt_at, response_code?, error?, created_at, updated_at }+Delivery = {+ id, session, destination, event_id, event_seq, status, attempts,+ last_attempt_at, response_code?, error?, created_at, updated_at+}```<Note>Coming soon: full request/response **body** capture in delivery detail (today records status, attempts, response code, and error); a **test-ping** for a destination; and **org/agent-scoped** destinations that persist across sessions.</Note>