Run Claude sessions on tasks with event streaming and restart recovery

This commit is contained in:
Ian Gulliver
2026-10-13 22:30:39 -07:00
parent 2328904131
commit 09951e64e7
16 changed files with 1630 additions and 170 deletions
+111 -1
View File
@@ -125,6 +125,87 @@ paths:
"404": { $ref: "#/components/responses/Error" }
"409": { $ref: "#/components/responses/Error" }
/api/tasks/{taskId}/sessions:
parameters:
- { name: taskId, in: path, required: true, schema: { type: string } }
get:
operationId: listSessions
responses:
"200":
description: The task's agent sessions, oldest first.
content:
application/json:
schema:
type: array
items: { $ref: "#/components/schemas/AgentSession" }
"404": { $ref: "#/components/responses/Error" }
post:
operationId: createSession
description: Starts an agent session in the task's worktree and sends it the prompt as its first turn.
requestBody:
required: true
content:
application/json:
schema: { $ref: "#/components/schemas/SessionCreate" }
responses:
"201":
description: The new session.
content:
application/json:
schema: { $ref: "#/components/schemas/AgentSession" }
"400": { $ref: "#/components/responses/Error" }
"404": { $ref: "#/components/responses/Error" }
"409": { $ref: "#/components/responses/Error" }
/api/sessions/{sessionId}:
parameters:
- { name: sessionId, in: path, required: true, schema: { type: string } }
get:
operationId: getSession
responses:
"200":
description: The session.
content:
application/json:
schema: { $ref: "#/components/schemas/AgentSession" }
"404": { $ref: "#/components/responses/Error" }
/api/sessions/{sessionId}/messages:
parameters:
- { name: sessionId, in: path, required: true, schema: { type: string } }
post:
operationId: sendMessage
description: Starts a new turn with this message. The session must be idle.
requestBody:
required: true
content:
application/json:
schema: { $ref: "#/components/schemas/MessageCreate" }
responses:
"202":
description: The turn has started.
content:
application/json:
schema: { $ref: "#/components/schemas/AgentSession" }
"400": { $ref: "#/components/responses/Error" }
"404": { $ref: "#/components/responses/Error" }
"409": { $ref: "#/components/responses/Error" }
/api/sessions/{sessionId}/interrupt:
parameters:
- { name: sessionId, in: path, required: true, schema: { type: string } }
post:
operationId: interruptSession
description: Ends the current turn.
responses:
"202":
description: The interrupt was delivered.
content:
application/json:
schema: { $ref: "#/components/schemas/AgentSession" }
"404": { $ref: "#/components/responses/Error" }
"409": { $ref: "#/components/responses/Error" }
/api/events:
get:
operationId: streamEvents
@@ -222,6 +303,33 @@ components:
properties:
title: { type: string }
AgentSession:
type: object
required: [id, task_id, vendor, model, vendor_session_id, state, role, created_by, created_at]
properties:
id: { type: string }
task_id: { type: string }
vendor: { type: string, enum: [claude] }
model: { type: string, description: Requested model; empty means the vendor's default. }
vendor_session_id: { type: string }
state: { type: string, enum: [idle, running, completed] }
role: { type: string, enum: [implementer] }
created_by: { type: string }
created_at: { type: string, format: date-time }
SessionCreate:
type: object
required: [prompt]
properties:
prompt: { type: string }
model: { type: string }
MessageCreate:
type: object
required: [text]
properties:
text: { type: string }
Event:
type: object
required: [seq, kind, actor, payload, created_at]
@@ -230,14 +338,16 @@ components:
kind: { type: string }
project_id: { type: string }
task_id: { type: string }
agent_session_id: { type: string }
actor: { type: string }
payload: { type: object }
created_at: { type: string, format: date-time }
Status:
type: object
required: [started_at, db_bytes, last_event_seq, projects, active_tasks, sse_clients]
required: [started_at, db_bytes, last_event_seq, projects, active_tasks, sse_clients, live_agents]
properties:
live_agents: { type: integer, description: Agent processes currently running. }
started_at: { type: string, format: date-time }
db_bytes: { type: integer, format: int64 }
last_event_seq: { type: integer, format: int64 }