Skip to main content

API

Use this page to inspect the WebSocket methods, events, and errors exposed by the engine.

The engine is driven through one API. The afe command line and the web UI are its clients.

The protocol​

The API is JSON-RPC 2.0 over a WebSocket at /rpc. The handshake must carry Authorization: Bearer <token>, or a valid session cookie from the server's own Origin. The token is the bootstrap token, a service account token or an OpenID Connect access token. See Identity and audit.

MethodParamsResult
caller.get—{caller, everything, roles, capabilities}: the caller, whether it reaches everything, its roles per project and what it may reach
flow.list—flows with their input Schema, the workspace they need, their projects, the current revision and can_start
flow.bpmnflow, revision?{xml, nodes}: the flow as BPMN 2.0 XML, with no layout, and each clickable element's domain kind (agent, human, script, lane, map, start, end, when, choose, join, pause)
ticket.startflow, input, project?, revision?, traceparent?{ticket_id} as soon as it is accepted
ticket.rerunticket_id{ticket_id} of a new ticket on the same flow, input, project and revision
revision.getrevision_id{id, manifests, manifest_count, current}: the frozen configuration
ticket.start_formflow, rerun_of?{flow, revision, input_schema, initial, projects, project_required}: the form that starts a flow, at a ticket's revision on a rerun
meta.get—{states, open_states, waiting_states, sort_columns, search_max, audit_actions, audit_outcomes}: the engine's own catalogues
ticket.resumeticket_id, answer? (action, comment?){ticket_id}
ticket.pause, ticket.cancelticket_idnull
ticket.cleanticket_ida note naming the repository whose branches stayed, or null: the worktrees, branches, sandbox and bundles of a finished ticket go, repeatable
ticket.getticket_idstate, round, revision, artifacts, totals, pending question, last error, last and highlighted node, actions
ticket.liststate?, flow?, search?, sort?, descending?, pending_request?, cursor?, limit?{items, next}: a page of tickets, newest first, with their totals, actions, and the pending question of the waiting ones
ticket.countsnone{states: {state: count}, total, pending_requests}: the tickets the caller sees per state, their total, and how many wait on a person
ticket.eventsticket_id, cursor?, limit?, node?, descending?{items, next}: a page of the ticket's events, in order, or newest first
events.subscribeticket_id?, after?{subscription}, then events.event notifications
events.unsubscribesubscriptiontrue or false
workers.status—queue metrics (waiting, claimed) and the live workers, each with its tickets and active_tickets
audit.listsince?, until?, actor?, action?, object_id?, project?, outcome?, before?, limit?a page of the audit trail, newest first (global administrators, or project administrators for their projects)
service_account.createname, expires_at?{account, token}, the token shown once (administrators only)
service_account.list—the service accounts, with no tokens (administrators only)
service_account.revokenamenull (administrators only)

caller.get returns {caller, everything, roles, capabilities}. roles maps each project to the roles the caller holds there, and everything is true for a global administrator and for local. It is a read and leaves no entry.

capabilities says what the caller may reach, so a client hides a page without working it out.

  • workers: the caller reads the workers and the queue.
  • revisions: the caller reads a configuration revision.
  • audit: the caller reads some part of the audit trail.
  • audit_projects: the projects whose trail it reads, sorted.
  • sees_projects: the caller sees at least one project, or every ticket because it has every right.

actions on a ticket lists what the caller may do now, from pause, cancel, resume, answer and rerun. It depends on the caller's role in the ticket's project and on the ticket's state. A client shows a button only when its action is there. The role matrix is in the Project reference.

flow.list lists every flow, and each flow's projects holds only the projects where the caller may start it. A ticket of a project the caller cannot see answers -32001, as an unknown ticket does. can_start is true when ticket.start would accept the flow for this caller now. It follows the same checks: the role, the flow limits of the grant, and the project's folder or repository.

A grant limited to some flows counts only for those, in every list, read and command.

ticket.list and ticket.events return one page. limit is 1 to 1,000 and defaults to 100. Any other value answers -32002. next is an opaque cursor: pass it as cursor to read the next page, and it is null on the last. Events come ordered by seq. A client that needs everything reads pages until next is null.

ticket.list filters and sorts on the server:

  • state keeps one state, flow keeps one flow.
  • search keeps the tickets whose id, uid or project contains the text, ignoring case. It is at most 100 characters.
  • sort is one of id, flow, state, round, revision, project and cost. The default is id, and ids order numerically (T-0010 after T-0009). Ties break by id.
  • descending is optional: left out, the server picks the order, newest first except on the Approvals list. When sent, it wins either way.
  • pending_request keeps only the tickets with an unanswered request, filtered before the page: the Approvals list, where id ascending puts the longest wait first.
  • A cursor carries its sort and descending. Reused with another sort or descending, it answers INVALID_INPUT (-32002). It does not carry the filters: send the same state, flow and search with it, since the server does not check them.

ticket.events takes node, which keeps one node's events, and descending, which returns the newest first with the cursor walking the earlier events.

ticket.counts takes no parameters and counts every ticket the caller sees, whatever page a client has loaded. A state with no ticket is absent from states. total counts them all and pending_requests counts the tickets with an unanswered request, the Approvals badge.

ticket.clean takes a finished ticket. It removes the worktrees, branches, sandbox and stored bundles, and writes a ticket.clean audit entry. An open ticket answers INVALID_INPUT (-32002). A second call finds nothing and succeeds. The result is null, or a branches kept: <repository> note when the repository is not a clone the engine made. See afe clean.

ticket.start_form returns what a form needs: the input Schema, the initial values (the original input on a rerun), the projects the caller may pass and project_required. Pass rerun_of to read the Schema at that ticket's revision. meta.get returns the engine's own catalogues, so a client does not copy them. They are the ticket states, the open and waiting ones, the sortable columns, the search limit, and the audit actions and outcomes.

The pending question of a ticket, in ticket.get and ticket.list, carries kind, node, question, actions and require_comment. For a budget, loop or hand-over question it also carries a message code and its raw params, so a client translates it. question stays the English line. A flow's own question has code: null and empty params.

  • budget.ticket, budget.branch, budget.activation: dimension, threshold, used, limit, node and branch.
  • loop.repeated: node and repeats.
  • handover.<cause>: node, plus comment for rejected, reason for gave_up and detail for every other cause.
  • handover.error: node and detail.

The hand-over causes are rejected, taken_over, gave_up, budget_exceeded, loop_handover, artifact_invalid, harness_failed, feedback_exhausted, stalled, write_conflict and merge_not_approved. Any other cause answers handover.error.

revision.get adds manifest_count, the number of manifests, and current, true when the revision is the one the engine runs now.

ticket.get carries cleanup: "pending" when a cancelled ticket's sandbox removal has failed and is being retried, and nothing otherwise. last_node is the node of the newest event that has one. highlight_node is the pending request's node, else last_node, else null. totals carries total_tokens and fresh_tokens beside the billed counts.

Tickets run in the background. Their progress arrives as events.event notifications on the same connection. A late subscriber first gets the ticket's past events, then the live ones, with no duplicates.

events.subscribe takes after, the last seq the client saw, and replays only what follows it. A connection holds at most 32 subscriptions, and one caller at most 256 across all its connections. A request past either answers -32009 and starts no stream. Unsubscribing, closing the connection or a stream that ends frees the slot. A subscriber that cannot keep up (its queue of 1,000 events is full) is stopped, not skipped: the server closes the socket with code 4008. The CLI and the web UI reconnect and pass their last seq as after, so no event is lost.

Event kinds​

KindMeaning
ticket_startedThe ticket was accepted and the engine started it.
ticket_resumedA person answered, or the ticket was restarted.
ticket_recoveredA worker took over a ticket whose worker died.
ticket_cancelledThe ticket was cancelled.
ticket_doneThe flow reached END.
node_startedA node began an activation.
node_finishedA node finished an activation.
budget_alertA budget crossed an alert fraction or a limit; waits for a person.
loop_detectedThe same tool call repeated; waits for a person.
human_requestA human node asks a person.
human_responseA person answered a human node.
cleanup_failedRemoving a cancelled ticket's sandbox failed, and it is retried. The payload carries error_class and error.
cleanup_doneA cancelled ticket's sandbox and bundles were removed.
needs_humanA hand-over; the ticket stops for a person.
errorThe ticket failed; the payload carries state and error.

Errors​

Error codeMeaning
-32602Invalid params
-32001Unknown flow or ticket, or a ticket of a project the caller cannot see
-32002Invalid input; data.fields names the field that is wrong
-32003Action not offered
-32004The ticket is running, or closed
-32005Unknown revision
-32006The ticket has no revision (created before revisions existed)
-32007The ticket was started by an earlier engine version (finish it there, or rerun it)
-32008The caller is not allowed to do this
-32009The caller holds too many event subscriptions (32 per connection, 256 per caller)

See also​