An open-source, faster Devin alternative
TypeScript
docs: questions closures and dismiss, held receipts and events, Linear page gaps
Igor Zalutski6d7105feecbc
diff --git a/docs/agents/api.mdx b/docs/agents/api.mdxindex 810ac204..7da90628 100644--- a/docs/agents/api.mdx+++ b/docs/agents/api.mdx@@ -59,6 +59,7 @@ deployment it was created on; see [Sessions and turns](/agents/sessions).| Labels | `PATCH /sessions/<id>/labels` | `200` with the session || End | `POST /sessions/<id>/end` | `200` with the ended session || Interrupt | `POST /sessions/<id>/interrupt` | `200` with the session |+| Dismiss a question | `POST /sessions/<id>/questions/<questionId>/dismiss` | `200`; see [Questions](#questions) |### Create@@ -341,25 +342,36 @@ idempotency_conflict` and admits nothing. A retry after a lost reply istherefore safe with the same body, and a different request never lands onanother request's key.-While the session has an open question, a turn sent without `answers` is-held rather than run: the response is `202 { status: "held", duplicate }`-with no `turnId`. The held input is delivered with the answer, in order, as-the answering turn's `steering`. A repeat of its key after the answer returns-the answering turn's receipt; after the session is stopped from-[Linear](/agents/linear#stop), it returns `status: "discarded"`.--A turn with `answers` resolves the question and runs as the answer, in one-step, idempotent on its key. Naming a question that is not the open one, or-answering when none is open, is `409 question_stale`; read the session and-answer its current question.-Codes: `400 invalid_turn`, `400 invalid_payload` (over 32 KB),`402 insufficient_credits`, `409 idempotency_conflict`,-`409 question_stale`,+`409 question_stale`, `409 held_inputs_full` (answer or dismiss first),`409 memory_admission_pending` (retry the session creation with its keyfirst), `409 memory_admission_rejected` (the session is ended; create a newone).+### Questions++While the session has an open [question](/agents/sessions#questions), a turn+sent without `answers` is held rather than run: the response is+`202 { status: "held", questionId, duplicate }` with no `turnId`, and `200`+for a repeated key. The held input is delivered with the answer, in order, as+the answering turn's `steering`, up to a bounded number and 64 KiB; the rest+run as ordinary turns after it. A repeat of its key after delivery returns the+receipt of the turn that carried it; after a [Linear](/agents/linear#stop)+stop, it returns `status: "discarded"`. A turn already queued when the+question was asked keeps its `turnId` and settles as `cancelled` with+reason `held` and the `questionId`.++A turn with `answers` resolves the question and runs as the answer, in one+step, idempotent on its key; the same key with a different `answers` is+`409 idempotency_conflict`. Naming a question that is not the open one, or+answering when none is open, is `409 question_stale`; read the session and+answer its current question.++`POST /sessions/<id>/questions/<questionId>/dismiss` closes the open question+with reason `dismissed`; its held inputs run as ordinary turns, in order.+Ending the session closes it with `ended`. Interrupt does not close it.+### Start work from an applicationAn application that turns a form submission into agent work makes two calls,@@ -527,8 +539,9 @@ treat that text as data about another agent's work, not as instructions.## Linear connectionsA [Linear connection](/agents/linear) binds a Linear app in your workspace to-one agent in one environment. The dashboard drives these routes; they need an-organization API key, and project-scoped keys are refused.+one agent in one environment. The dashboard drives these routes. A+project-scoped key may list its own project's connections; every other route+needs an organization API key and is `403 forbidden` otherwise.| Operation | Method and path | Body or query | Success || --- | --- | --- | --- |@@ -539,7 +552,9 @@ organization API key, and project-scoped keys are refused.| Disconnect | `DELETE /linear/connections/<id>` | None | `200` with `{ connection, revoked }` |`createAppUrl` opens Linear's create-app page prefilled with the name, the-callback URL and `webhookUrl`. `webhookUrl` contains the connection's secret;+callback URL and `webhookUrl`. Creating again for a pending binding resets it+with the new name and a new `webhookUrl`, so an earlier `createAppUrl` stops+working. `webhookUrl` contains the connection's secret;treat it as a credential. `authorizeUrl` is Linear's consent page for the app;a workspace admin completes it, and Linear returns to OpenComputer's callback,which stores the tokens and redirects to the project's Connections tab.@@ -560,7 +575,10 @@ lastEventAt? }`, with `state` one of `awaiting_credentials`,| `400 invalid_linear_app_name` | The name must be 1 to 64 characters || `400 linear_app_name_reserved` | Linear does not allow app names that contain "Linear" || `400 invalid_linear_credentials` | `clientId`, `clientSecret` and `signingSecret` are all required |+| `403 forbidden` | A project-scoped key on a route other than List |+| `404 project_not_found` | No such project for this key || `404 linear_connection_not_found` | No such connection, or it was disconnected |+| `409 project_archived` | Restore the project before creating a connection || `409 linear_already_connected` | The agent already has a connection in this environment; `error.connectionId` names it || `409 linear_app_already_connected` | That Linear app is connected to another agent or environment; create a separate app || `409 linear_connection_connected` | The connection is authorized with a different Linear app; disconnect it first |diff --git a/docs/agents/events.mdx b/docs/agents/events.mdxindex 8c34b9d6..ad6be8e1 100644--- a/docs/agents/events.mdx+++ b/docs/agents/events.mdx@@ -127,14 +127,18 @@ only when one happened.| --- | --- | --- || `question.asked` | The agent called [`ask`](/agents/tools#ask-a-question); the asking turn completes with `outcome: "question"` | `questionId`, `text`, `options`: `{ label, value }` choices, empty for free text || `question.answered` | A turn answering the question was admitted | `questionId`, `answer`: `{ questionId, text, value? }` |-| `question.closed` | The question closed without an answer | `questionId`, `reason`: `stopped` |+| `question.closed` | The question closed without an answer | `questionId`, `reason`: `stopped`, `dismissed`, `ended` or `undeliverable` |+| `message.held` | An input sent without `answers` was held behind the open question | `questionId` and the held input |+| `message.delivered` | A held input was delivered, as `steering` or as an ordinary turn | `turnId`: the turn that carried it |+| `message.discarded` | A held input will not run | none |`turn.completed` with `outcome: "question"` is the turn's terminal event, so aconsumer that knows only completed turns reads an asking turn correctly, and[outcome subscriptions](/agents/api#event-subscriptions) deliver it as acompleted turn. The open question is also on the session as-[`question`](/agents/sessions#questions). A question closes with `stopped`-when the session is stopped from [Linear](/agents/linear#stop).+[`question`](/agents/sessions#questions), where each closure `reason` is+explained. A held input is recorded once, however often its key is repeated,+so a client can rebuild held messages after a reload.### Messagesdiff --git a/docs/agents/inputs.mdx b/docs/agents/inputs.mdxindex e4a7e5e1..1c532391 100644--- a/docs/agents/inputs.mdx+++ b/docs/agents/inputs.mdx@@ -60,12 +60,14 @@ read.A message from a [Linear connection](/agents/linear) also arrives with`source: "channel"`, with `channel.provider` set to `linear`,`channel.workspaceId` the Linear workspace, `channel.conversationId` the-Linear agent session and `channel.userId` the person who wrote the message.+Linear agent session and `channel.userId` the person who wrote the message+(on the first message, the session's creator; absent when automation started+it).Its `payload` is a `LinearInputPayload`: the issue, the session, the thread'scomments, your workspace's guidance for agents, and `origin`, which sayswhether the issue had a parent and whether this agent's own app created it.`origin` is read when the session starts and does not change afterwards. The-fields are listed on [Linear agents](/agents/linear#what-it-receives).+fields are listed on [Linear connections](/agents/linear#what-it-receives).```tsximport { useInput, type LinearInputPayload } from "@opencomputer/agent";@@ -176,7 +178,9 @@ reply is the next input, from any source, with `answer` set:Input that arrives while the question is open without answering it does notrun a turn of its own. It is held and delivered with the answer as-`steering`, in the order it arrived:+`steering`, in the order it arrived; past a bounded number of items or 64 KiB,+the rest run as ordinary turns after the answer. In Linear, `steering` is+usually empty; see [Ask before acting](/agents/linear#ask-before-acting).| Field | Meaning || --- | --- |diff --git a/docs/agents/linear.mdx b/docs/agents/linear.mdxindex 8facbfb1..18bd465b 100644--- a/docs/agents/linear.mdx+++ b/docs/agents/linear.mdx@@ -1,11 +1,11 @@----title: "Linear agents"+title: "Linear connections"description: "Make a deployed agent a teammate people delegate issues to and mention in Linear"----Connect an agent to Linear and people can delegate issues to it and mention it,-under the name you give it. Its tool calls and replies appear in the issue's-thread. You write no webhook or Linear client code.+Connect an agent to Linear and people can delegate issues to it and mention it.+It appears under your Linear app's name and icon. Its tool calls and replies+appear in the issue's thread. You write no webhook or Linear client code.```tsximport { useInput } from "@opencomputer/agent";@@ -25,8 +25,8 @@ export default function Agent() {4. Choose **Authorize in Linear**. A workspace admin must approve.5. Delegate an issue to the agent. The panel shows **First session received**.-Each environment needs its own Linear app. Tokens never reach the agent, its-logs or the browser.+Each environment needs its own Linear app. Linear access tokens never reach the+agent, its logs or the browser.## Talking to it@@ -39,47 +39,54 @@ reply; the agent answers the thread, not a person.## What it receivesEach message is a [channel input](/agents/inputs) with-`channel.provider: "linear"`. `text` is the message, or Linear's prompt-context for the first one. `payload` is a `LinearInputPayload`:+`channel.provider: "linear"`. `text` is the message; for the first one it is+Linear's prompt context, or `<identifier>: <title>` without one. `payload` is a+`LinearInputPayload`:| Field | Meaning || --- | --- || `issue` | `{ id, identifier, title, description, url, team }` |-| `origin` | `{ parent?, createdByAgent }`, read when the session starts and fixed for its life |+| `origin` | `{ parent?, createdByAgent }`, read when the session starts and fixed for its life; `createdByAgent` is true when this agent's Linear app created the issue, whoever delegated it || `action` | `created` for the first message, `prompted` after |-| `session`, `comment`, `previousComments`, `guidance` | The thread and your workspace's agent guidance, as Linear sent them |+| `session` | `{ id, url?, creator? }`; `creator` is the person responsible, absent when automation started it |+| `promptContext`, `comment`, `previousComments`, `guidance` | The thread and your workspace's agent guidance, as Linear sent them |## What it writes| The agent | Linear shows || --- | --- |-| Calls a tool | An action with a one-line summary (never raw arguments) |-| Finishes its turn | The final message as a response |+| Receives a session | "Reading the issue.", at once |+| Calls a tool | An action with a short subject such as a file path, never full arguments or output |+| Finishes its turn | The final message as a response, or "Done." without one || Calls `ask` | A question awaiting input, options as buttons |-| Fails or is stopped | An error |+| Is stopped | An error: "Stopped." |+| Fails | An error: "OpenComputer could not complete this request." |A GitHub pull request URL in the final message becomes the session's link.## Ask before acting```tsx-import { useInput, useTool } from "@opencomputer/agent";-import { createSubIssues } from "./tools/create-sub-issues"; // a defineTool that writes+import { useInput, useService, useTool } from "@opencomputer/agent";+import { applyPlan } from "./tools/apply-plan"; // a defineTool that calls Linearexport default function Agent() {+ useService("linear");const input = useInput();if (!input.answer) {useTool("ask");return `Propose a plan, then ask whether to go:\n\n${input.text ?? ""}`;}- useTool(createSubIssues);+ useTool(applyPlan);return `You were told "${input.answer.text}". If that means go, do it.`;}```-The reply arrives with `input.answer`. Messages written in the meantime arrive-with it in `input.steering`. Linear holds messages typed while the agent works-until it finishes, so tell people to send them before answering.+Any reply after the question is the answer, `input.answer`. Linear holds+messages typed while the agent works and releases them only when it finishes,+so they arrive after the answer as ordinary turns and `input.steering` is+usually empty; a stop discards them. Say so in the question, so people send+constraints before answering.## Stop@@ -88,11 +95,10 @@ any open question. A later reply continues the same session.## Call Linear-For documents, sub-issues or status changes, declare the service in the agent-and call Linear's GraphQL API from a tool:+Declare the service in the agent and call Linear's GraphQL API from a tool:```tsx-// agent.ts+// in the agent componentuseService("linear");// in a tooldiff --git a/docs/agents/react.mdx b/docs/agents/react.mdxindex daa4a41d..54a6ff1b 100644--- a/docs/agents/react.mdx+++ b/docs/agents/react.mdx@@ -273,7 +273,9 @@ question that is no longer open rejects with a `SendError` whose code isWhile a question is open, `send` without `answers` resolves with a heldreceipt, `{ status: "held", questionId }` and no `turnId`: the message stays-in `messages` and reaches the agent with the answer.+in `messages`, rebuilt from the log's `message.held` events after a reload,+and reaches the agent with the answer. `dismiss(questionId)` closes the+question without an answer; held messages then run as ordinary turns.## Stop and reopen@@ -370,6 +372,7 @@ code.| `stop()` | Request an interrupt; rejects with `SendError` on a failed request, settlement arrives in `turns` || `question` | The open question, `{ id, text, options, turnId? }`, or `null` || `answer(questionId, text, options?)` | Answer the open question; same receipt and errors as `send` |+| `dismiss(questionId)` | Close the open question without an answer || `sessionId` | Attached session, or the created one after the first send || `isRunning` | Running activity or this instance's unsettled admissions; not a session status || `isReplaying` | Attach mode: existing history is still loading |diff --git a/docs/agents/services.mdx b/docs/agents/services.mdxindex 6359a7a8..15eb1201 100644--- a/docs/agents/services.mdx+++ b/docs/agents/services.mdx@@ -229,9 +229,7 @@ people delegate to, with the app's token attached by the platform.- The deployment must declare `useService("linear")`.- Only `POST /graphql` is accepted, as everywhere.-The agent's code is the same in both kinds of session. Writes made through-the app, such as a sub-issue or a comment, are attributed to the agent in-Linear.+The agent's code is the same in both kinds of session.## 4. Several accountsdiff --git a/docs/agents/sessions.mdx b/docs/agents/sessions.mdxindex afb3ec66..dc90a7e8 100644--- a/docs/agents/sessions.mdx+++ b/docs/agents/sessions.mdx@@ -115,14 +115,28 @@ question.While a question is open, a turn sent without `answers` does not run on itsown. It is held, and delivered with the answer, in order, as `steering`, sothe turn that interprets the answer sees every constraint written in the-meantime. The API answers a held input with `status: "held"`; see-[Turns](/agents/api#turns). A turn already queued behind the asking turn is-held the same way.+meantime. `steering` carries a bounded number of held inputs, up to 64 KiB;+the rest run as ordinary turns after the answer, in order. The API answers a+held input with `202 { status: "held", questionId }` and no `turnId`; see+[Turns](/agents/api#turns). A turn already queued behind the asking turn+settles as `cancelled` with reason `held` and keeps its turn id. Held inputs+are in the [event log](/agents/events#questions) as `message.held`, then+`message.delivered` or `message.discarded`.One question is open at a time. The answering turn may ask again, which opens-a new question. A question closes without an answer only when the session is-stopped from [Linear](/agents/linear#stop), which also discards the held-inputs.+a new question. A question closes without an answer with+`question.closed { reason }`:++| `reason` | Cause | Held inputs |+| --- | --- | --- |+| `stopped` | The session was stopped from [Linear](/agents/linear#stop) | Discarded |+| `dismissed` | [Dismiss](/agents/api#questions) was called | Run as ordinary turns, in order |+| `ended` | The session was ended | Not run |+| `undeliverable` | The question could not be posted to Linear | Run as ordinary turns, in order |++Interrupting a turn does not close a question. In Linear, messages typed+while the agent works usually arrive after the answer; see+[Ask before acting](/agents/linear#ask-before-acting).## Durability and recoverydiff --git a/docs/agents/tools.mdx b/docs/agents/tools.mdxindex 24bbbfd3..3df0a602 100644--- a/docs/agents/tools.mdx+++ b/docs/agents/tools.mdx@@ -301,7 +301,8 @@ Calling `ask` ends the turn with an open question. The turn completes with`question.asked` is recorded in the [event log](/agents/events#questions).The reply arrives as the next input with[`answer`](/agents/inputs#answers-and-steering) set, and anything written-meanwhile arrives with it as `steering`. A session has at most one open+meanwhile arrives with it as `steering`, within+[bounds](/agents/sessions#questions). A session has at most one openquestion; the turn that interprets the answer may ask again.How the question reaches a person depends on where the session lives: andiff --git a/docs/reference/typescript-sdk/agents.mdx b/docs/reference/typescript-sdk/agents.mdxindex d1287d94..3d637f66 100644--- a/docs/reference/typescript-sdk/agents.mdx+++ b/docs/reference/typescript-sdk/agents.mdx@@ -116,7 +116,8 @@ its contents affect application correctness or access.| `sessions.end(id)` | `POST /sessions/<id>/end` | The ended session || `sessions.interrupt(id)` | `POST /sessions/<id>/interrupt` | The session || `sessions.setLabels(id, { set?, unset? })` | `PATCH /sessions/<id>/labels` | The session |-| `sessions.turns.send(id, params)` | `POST /sessions/<id>/turns` | `{ turnId, status, duplicate }` |+| `sessions.turns.send(id, params)` | `POST /sessions/<id>/turns` | `{ turnId, status, duplicate }`, or a held receipt |+| `sessions.questions.dismiss(id, questionId)` | `POST /sessions/<id>/questions/<questionId>/dismiss` | Closes the open question with `dismissed` || `sessions.events.list(id, { after? })` | `GET /sessions/<id>/events` | The events with `seq` greater than `after`, up to 500 || `sessions.startOnDocument(params)` | `PUT` the document, then `POST /sessions` | `{ document, session }` with `created` on each |