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
+295 -42
View File
@@ -21,24 +21,99 @@ import (
"github.com/oapi-codegen/runtime"
)
// Defines values for TaskStatus.
// Defines values for AgentSessionRole.
const (
Active TaskStatus = "active"
Completed TaskStatus = "completed"
Implementer AgentSessionRole = "implementer"
)
// Valid indicates whether the value is a known member of the TaskStatus enum.
func (e TaskStatus) Valid() bool {
// Valid indicates whether the value is a known member of the AgentSessionRole enum.
func (e AgentSessionRole) Valid() bool {
switch e {
case Active:
return true
case Completed:
case Implementer:
return true
default:
return false
}
}
// Defines values for AgentSessionState.
const (
AgentSessionStateCompleted AgentSessionState = "completed"
AgentSessionStateIdle AgentSessionState = "idle"
AgentSessionStateRunning AgentSessionState = "running"
)
// Valid indicates whether the value is a known member of the AgentSessionState enum.
func (e AgentSessionState) Valid() bool {
switch e {
case AgentSessionStateCompleted:
return true
case AgentSessionStateIdle:
return true
case AgentSessionStateRunning:
return true
default:
return false
}
}
// Defines values for AgentSessionVendor.
const (
Claude AgentSessionVendor = "claude"
)
// Valid indicates whether the value is a known member of the AgentSessionVendor enum.
func (e AgentSessionVendor) Valid() bool {
switch e {
case Claude:
return true
default:
return false
}
}
// Defines values for TaskStatus.
const (
TaskStatusActive TaskStatus = "active"
TaskStatusCompleted TaskStatus = "completed"
)
// Valid indicates whether the value is a known member of the TaskStatus enum.
func (e TaskStatus) Valid() bool {
switch e {
case TaskStatusActive:
return true
case TaskStatusCompleted:
return true
default:
return false
}
}
// AgentSession defines model for AgentSession.
type AgentSession struct {
CreatedAt time.Time `json:"created_at"`
CreatedBy string `json:"created_by"`
Id string `json:"id"`
// Model Requested model; empty means the vendor's default.
Model string `json:"model"`
Role AgentSessionRole `json:"role"`
State AgentSessionState `json:"state"`
TaskId string `json:"task_id"`
Vendor AgentSessionVendor `json:"vendor"`
VendorSessionId string `json:"vendor_session_id"`
}
// AgentSessionRole defines model for AgentSession.Role.
type AgentSessionRole string
// AgentSessionState defines model for AgentSession.State.
type AgentSessionState string
// AgentSessionVendor defines model for AgentSession.Vendor.
type AgentSessionVendor string
// Error defines model for Error.
type Error struct {
Message string `json:"message"`
@@ -46,13 +121,19 @@ type Error struct {
// Event defines model for Event.
type Event struct {
Actor string `json:"actor"`
CreatedAt time.Time `json:"created_at"`
Kind string `json:"kind"`
Payload map[string]interface{} `json:"payload"`
ProjectId *string `json:"project_id,omitempty"`
Seq int64 `json:"seq"`
TaskId *string `json:"task_id,omitempty"`
Actor string `json:"actor"`
AgentSessionId *string `json:"agent_session_id,omitempty"`
CreatedAt time.Time `json:"created_at"`
Kind string `json:"kind"`
Payload map[string]interface{} `json:"payload"`
ProjectId *string `json:"project_id,omitempty"`
Seq int64 `json:"seq"`
TaskId *string `json:"task_id,omitempty"`
}
// MessageCreate defines model for MessageCreate.
type MessageCreate struct {
Text string `json:"text"`
}
// Project defines model for Project.
@@ -72,14 +153,23 @@ type ProjectCreate struct {
RepoPath string `json:"repo_path"`
}
// SessionCreate defines model for SessionCreate.
type SessionCreate struct {
Model *string `json:"model,omitempty"`
Prompt string `json:"prompt"`
}
// Status defines model for Status.
type Status struct {
ActiveTasks int `json:"active_tasks"`
DbBytes int64 `json:"db_bytes"`
LastEventSeq int64 `json:"last_event_seq"`
Projects int `json:"projects"`
SseClients int `json:"sse_clients"`
StartedAt time.Time `json:"started_at"`
ActiveTasks int `json:"active_tasks"`
DbBytes int64 `json:"db_bytes"`
LastEventSeq int64 `json:"last_event_seq"`
// LiveAgents Agent processes currently running.
LiveAgents int `json:"live_agents"`
Projects int `json:"projects"`
SseClients int `json:"sse_clients"`
StartedAt time.Time `json:"started_at"`
}
// Task defines model for Task.
@@ -133,6 +223,12 @@ type CreateProjectJSONRequestBody = ProjectCreate
// CreateTaskJSONRequestBody defines body for CreateTask for application/json ContentType.
type CreateTaskJSONRequestBody = TaskCreate
// SendMessageJSONRequestBody defines body for SendMessage for application/json ContentType.
type SendMessageJSONRequestBody = MessageCreate
// CreateSessionJSONRequestBody defines body for CreateSession for application/json ContentType.
type CreateSessionJSONRequestBody = SessionCreate
// ServerInterface represents all server handlers.
type ServerInterface interface {
@@ -163,11 +259,26 @@ type ServerInterface interface {
// (POST /api/projects/{projectId}/tasks)
CreateTask(w http.ResponseWriter, r *http.Request, projectId string)
// (GET /api/sessions/{sessionId})
GetSession(w http.ResponseWriter, r *http.Request, sessionId string)
// (POST /api/sessions/{sessionId}/interrupt)
InterruptSession(w http.ResponseWriter, r *http.Request, sessionId string)
// (POST /api/sessions/{sessionId}/messages)
SendMessage(w http.ResponseWriter, r *http.Request, sessionId string)
// (GET /api/tasks/{taskId})
GetTask(w http.ResponseWriter, r *http.Request, taskId string)
// (POST /api/tasks/{taskId}/complete)
CompleteTask(w http.ResponseWriter, r *http.Request, taskId string)
// (GET /api/tasks/{taskId}/sessions)
ListSessions(w http.ResponseWriter, r *http.Request, taskId string)
// (POST /api/tasks/{taskId}/sessions)
CreateSession(w http.ResponseWriter, r *http.Request, taskId string)
}
// ServerInterfaceWrapper converts contexts to parameters.
@@ -381,6 +492,84 @@ func (siw *ServerInterfaceWrapper) CreateTask(w http.ResponseWriter, r *http.Req
handler.ServeHTTP(w, r)
}
// GetSession operation middleware
func (siw *ServerInterfaceWrapper) GetSession(w http.ResponseWriter, r *http.Request) {
var err error
_ = err
// ------------- Path parameter "sessionId" -------------
var sessionId string
err = runtime.BindStyledParameterWithOptions("simple", "sessionId", r.PathValue("sessionId"), &sessionId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "", ValueIsUnescaped: true})
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "sessionId", Err: err})
return
}
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.GetSession(w, r, sessionId)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// InterruptSession operation middleware
func (siw *ServerInterfaceWrapper) InterruptSession(w http.ResponseWriter, r *http.Request) {
var err error
_ = err
// ------------- Path parameter "sessionId" -------------
var sessionId string
err = runtime.BindStyledParameterWithOptions("simple", "sessionId", r.PathValue("sessionId"), &sessionId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "", ValueIsUnescaped: true})
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "sessionId", Err: err})
return
}
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.InterruptSession(w, r, sessionId)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// SendMessage operation middleware
func (siw *ServerInterfaceWrapper) SendMessage(w http.ResponseWriter, r *http.Request) {
var err error
_ = err
// ------------- Path parameter "sessionId" -------------
var sessionId string
err = runtime.BindStyledParameterWithOptions("simple", "sessionId", r.PathValue("sessionId"), &sessionId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "", ValueIsUnescaped: true})
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "sessionId", Err: err})
return
}
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.SendMessage(w, r, sessionId)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// GetTask operation middleware
func (siw *ServerInterfaceWrapper) GetTask(w http.ResponseWriter, r *http.Request) {
@@ -433,6 +622,58 @@ func (siw *ServerInterfaceWrapper) CompleteTask(w http.ResponseWriter, r *http.R
handler.ServeHTTP(w, r)
}
// ListSessions operation middleware
func (siw *ServerInterfaceWrapper) ListSessions(w http.ResponseWriter, r *http.Request) {
var err error
_ = err
// ------------- Path parameter "taskId" -------------
var taskId string
err = runtime.BindStyledParameterWithOptions("simple", "taskId", r.PathValue("taskId"), &taskId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "", ValueIsUnescaped: true})
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "taskId", Err: err})
return
}
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.ListSessions(w, r, taskId)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// CreateSession operation middleware
func (siw *ServerInterfaceWrapper) CreateSession(w http.ResponseWriter, r *http.Request) {
var err error
_ = err
// ------------- Path parameter "taskId" -------------
var taskId string
err = runtime.BindStyledParameterWithOptions("simple", "taskId", r.PathValue("taskId"), &taskId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "", ValueIsUnescaped: true})
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "taskId", Err: err})
return
}
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.CreateSession(w, r, taskId)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
type UnescapedCookieParamError struct {
ParamName string
Err error
@@ -562,6 +803,11 @@ func HandlerWithOptions(si ServerInterface, options StdHTTPServerOptions) http.H
m.HandleFunc(http.MethodPost+" "+options.BaseURL+"/api/projects/{projectId}/tasks", wrapper.CreateTask)
m.HandleFunc(http.MethodGet+" "+options.BaseURL+"/api/tasks/{taskId}", wrapper.GetTask)
m.HandleFunc(http.MethodPost+" "+options.BaseURL+"/api/tasks/{taskId}/complete", wrapper.CompleteTask)
m.HandleFunc(http.MethodGet+" "+options.BaseURL+"/api/tasks/{taskId}/sessions", wrapper.ListSessions)
m.HandleFunc(http.MethodPost+" "+options.BaseURL+"/api/tasks/{taskId}/sessions", wrapper.CreateSession)
m.HandleFunc(http.MethodGet+" "+options.BaseURL+"/api/sessions/{sessionId}", wrapper.GetSession)
m.HandleFunc(http.MethodPost+" "+options.BaseURL+"/api/sessions/{sessionId}/messages", wrapper.SendMessage)
m.HandleFunc(http.MethodPost+" "+options.BaseURL+"/api/sessions/{sessionId}/interrupt", wrapper.InterruptSession)
m.HandleFunc(http.MethodGet+" "+options.BaseURL+"/api/events", wrapper.StreamEvents)
m.HandleFunc(http.MethodGet+" "+options.BaseURL+"/api/admin/status", wrapper.GetStatus)
@@ -573,27 +819,34 @@ func HandlerWithOptions(si ServerInterface, options StdHTTPServerOptions) http.H
// const string: with thousands of chunks the chained `+` fold is several
// times slower for the Go compiler than parsing a slice literal.
var swaggerSpec = []string{
"zFhbb+M2E/0rBL8PSAsottsNCtR96iUoUmzbRZN92gYCLY1tbiRSGY69NQL994KkrjblS2p3+xRZJIdn",
"Ds8ZDfPCE50XWoEiw6cvHMEUWhlwP24RNdqHRCsCRfZRFEUmE0FSq/FHo5V9Z5Il5MI+/R9hzqf8f+M2",
"6tiPmrGPVpZlxFMwCcrCBuFTv82I24Fqbm/zAnUBSNJjysEYsQD7SJsC+JQbQqkWbjnC80oipHz6oZn4",
"GNUT9ewjJMTLiN+uq2z6sUVCfsutyBFPEARBGgu3aq4xt088FQTXJHPg0e6aJ6nSYLBCbDItumMtsgK1",
"fYxleKmB5x4Aqeibm3ZzqQgWgHYmCfMUjrLFkw1ZgY0qBlqIvcxDTL7zeHe5fA1j9ZrZJph8CnOxyiie",
"oVDJMjhlgDYlcggOIOSahoYKHReClocplJYot0d32Q7gZrtepsdS/KObtUv0ntyOTmAHewjHPQlamaBr",
"5BpiKzjT2aqjxXQWzzbkZx8h3UwYisFaND5e75VxBhAYA3GSybrKBSaQwNPkum2jNkAn4Z1kOkCjPnN9",
"kKEDeBDmaZf+mTAQu7Ib0MAeq9gKncFrLXpGWw949lAlbNQIapXbE/Bs8k5mHRbbh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