942 lines
30 KiB
Go
942 lines
30 KiB
Go
//go:build go1.22
|
|
|
|
// Package api provides primitives to interact with the openapi HTTP API.
|
|
//
|
|
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.8.0 DO NOT EDIT.
|
|
package api
|
|
|
|
import (
|
|
"bytes"
|
|
"compress/flate"
|
|
"encoding/base64"
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"path"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/getkin/kin-openapi/openapi3"
|
|
"github.com/oapi-codegen/runtime"
|
|
)
|
|
|
|
// Defines values for AgentSessionRole.
|
|
const (
|
|
Implementer AgentSessionRole = "implementer"
|
|
)
|
|
|
|
// Valid indicates whether the value is a known member of the AgentSessionRole enum.
|
|
func (e AgentSessionRole) Valid() bool {
|
|
switch e {
|
|
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"`
|
|
}
|
|
|
|
// Event defines model for Event.
|
|
type Event struct {
|
|
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.
|
|
type Project struct {
|
|
CreatedAt time.Time `json:"created_at"`
|
|
CreatedBy string `json:"created_by"`
|
|
DefaultBranch string `json:"default_branch"`
|
|
Id string `json:"id"`
|
|
Name string `json:"name"`
|
|
Remote string `json:"remote"`
|
|
RepoPath string `json:"repo_path"`
|
|
}
|
|
|
|
// ProjectCreate defines model for ProjectCreate.
|
|
type ProjectCreate struct {
|
|
Name string `json:"name"`
|
|
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"`
|
|
|
|
// 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.
|
|
type Task struct {
|
|
BaseRef string `json:"base_ref"`
|
|
Branch string `json:"branch"`
|
|
CompletedAt *time.Time `json:"completed_at,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
CreatedBy string `json:"created_by"`
|
|
Id string `json:"id"`
|
|
ProjectId string `json:"project_id"`
|
|
Status TaskStatus `json:"status"`
|
|
Title string `json:"title"`
|
|
WorktreePath string `json:"worktree_path"`
|
|
}
|
|
|
|
// TaskStatus defines model for Task.Status.
|
|
type TaskStatus string
|
|
|
|
// TaskCreate defines model for TaskCreate.
|
|
type TaskCreate struct {
|
|
Title string `json:"title"`
|
|
}
|
|
|
|
// User defines model for User.
|
|
type User struct {
|
|
DisplayName string `json:"display_name"`
|
|
GitEmail string `json:"git_email"`
|
|
GitName string `json:"git_name"`
|
|
Login string `json:"login"`
|
|
}
|
|
|
|
// UserUpdate defines model for UserUpdate.
|
|
type UserUpdate struct {
|
|
GitEmail string `json:"git_email"`
|
|
GitName string `json:"git_name"`
|
|
}
|
|
|
|
// StreamEventsParams defines parameters for StreamEvents.
|
|
type StreamEventsParams struct {
|
|
After *int64 `form:"after,omitempty" json:"after,omitempty"`
|
|
LastEventID *int64 `json:"Last-Event-ID,omitempty"`
|
|
}
|
|
|
|
// UpdateMeJSONRequestBody defines body for UpdateMe for application/json ContentType.
|
|
type UpdateMeJSONRequestBody = UserUpdate
|
|
|
|
// CreateProjectJSONRequestBody defines body for CreateProject for application/json ContentType.
|
|
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 {
|
|
|
|
// (GET /api/admin/status)
|
|
GetStatus(w http.ResponseWriter, r *http.Request)
|
|
|
|
// (GET /api/events)
|
|
StreamEvents(w http.ResponseWriter, r *http.Request, params StreamEventsParams)
|
|
|
|
// (GET /api/me)
|
|
GetMe(w http.ResponseWriter, r *http.Request)
|
|
|
|
// (PUT /api/me)
|
|
UpdateMe(w http.ResponseWriter, r *http.Request)
|
|
|
|
// (GET /api/projects)
|
|
ListProjects(w http.ResponseWriter, r *http.Request)
|
|
|
|
// (POST /api/projects)
|
|
CreateProject(w http.ResponseWriter, r *http.Request)
|
|
|
|
// (GET /api/projects/{projectId})
|
|
GetProject(w http.ResponseWriter, r *http.Request, projectId string)
|
|
|
|
// (GET /api/projects/{projectId}/tasks)
|
|
ListTasks(w http.ResponseWriter, r *http.Request, projectId string)
|
|
|
|
// (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.
|
|
type ServerInterfaceWrapper struct {
|
|
Handler ServerInterface
|
|
HandlerMiddlewares []MiddlewareFunc
|
|
ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
|
|
}
|
|
|
|
type MiddlewareFunc func(http.Handler) http.Handler
|
|
|
|
// GetStatus operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetStatus(w http.ResponseWriter, r *http.Request) {
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.GetStatus(w, r)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// StreamEvents operation middleware
|
|
func (siw *ServerInterfaceWrapper) StreamEvents(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var err error
|
|
_ = err
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params StreamEventsParams
|
|
|
|
// ------------- Optional query parameter "after" -------------
|
|
|
|
err = runtime.BindQueryParameterWithOptions("form", true, false, "after", r.URL.Query(), ¶ms.After, runtime.BindQueryParameterOptions{Type: "integer", Format: "int64"})
|
|
if err != nil {
|
|
var requiredError *runtime.RequiredParameterError
|
|
if errors.As(err, &requiredError) {
|
|
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "after"})
|
|
} else {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "after", Err: err})
|
|
}
|
|
return
|
|
}
|
|
|
|
headers := r.Header
|
|
|
|
// ------------- Optional header parameter "Last-Event-ID" -------------
|
|
if valueList, found := headers[http.CanonicalHeaderKey("Last-Event-ID")]; found {
|
|
var LastEventID int64
|
|
n := len(valueList)
|
|
if n != 1 {
|
|
siw.ErrorHandlerFunc(w, r, &TooManyValuesForParamError{ParamName: "Last-Event-ID", Count: n})
|
|
return
|
|
}
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "Last-Event-ID", valueList[0], &LastEventID, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationHeader, Explode: false, Required: false, Type: "integer", Format: "int64"})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "Last-Event-ID", Err: err})
|
|
return
|
|
}
|
|
|
|
params.LastEventID = &LastEventID
|
|
|
|
}
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.StreamEvents(w, r, params)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// GetMe operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetMe(w http.ResponseWriter, r *http.Request) {
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.GetMe(w, r)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// UpdateMe operation middleware
|
|
func (siw *ServerInterfaceWrapper) UpdateMe(w http.ResponseWriter, r *http.Request) {
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.UpdateMe(w, r)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// ListProjects operation middleware
|
|
func (siw *ServerInterfaceWrapper) ListProjects(w http.ResponseWriter, r *http.Request) {
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.ListProjects(w, r)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// CreateProject operation middleware
|
|
func (siw *ServerInterfaceWrapper) CreateProject(w http.ResponseWriter, r *http.Request) {
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.CreateProject(w, r)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// GetProject operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetProject(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var err error
|
|
_ = err
|
|
|
|
// ------------- Path parameter "projectId" -------------
|
|
var projectId string
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "projectId", r.PathValue("projectId"), &projectId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "", ValueIsUnescaped: true})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "projectId", Err: err})
|
|
return
|
|
}
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.GetProject(w, r, projectId)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// ListTasks operation middleware
|
|
func (siw *ServerInterfaceWrapper) ListTasks(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var err error
|
|
_ = err
|
|
|
|
// ------------- Path parameter "projectId" -------------
|
|
var projectId string
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "projectId", r.PathValue("projectId"), &projectId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "", ValueIsUnescaped: true})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "projectId", Err: err})
|
|
return
|
|
}
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.ListTasks(w, r, projectId)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// CreateTask operation middleware
|
|
func (siw *ServerInterfaceWrapper) CreateTask(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var err error
|
|
_ = err
|
|
|
|
// ------------- Path parameter "projectId" -------------
|
|
var projectId string
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "projectId", r.PathValue("projectId"), &projectId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "", ValueIsUnescaped: true})
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "projectId", Err: err})
|
|
return
|
|
}
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.CreateTask(w, r, projectId)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
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) {
|
|
|
|
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.GetTask(w, r, taskId)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// CompleteTask operation middleware
|
|
func (siw *ServerInterfaceWrapper) CompleteTask(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.CompleteTask(w, r, taskId)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
func (e *UnescapedCookieParamError) Error() string {
|
|
return fmt.Sprintf("error unescaping cookie parameter '%s'", e.ParamName)
|
|
}
|
|
|
|
func (e *UnescapedCookieParamError) Unwrap() error {
|
|
return e.Err
|
|
}
|
|
|
|
type UnmarshalingParamError struct {
|
|
ParamName string
|
|
Err error
|
|
}
|
|
|
|
func (e *UnmarshalingParamError) Error() string {
|
|
return fmt.Sprintf("Error unmarshaling parameter %s as JSON: %s", e.ParamName, e.Err.Error())
|
|
}
|
|
|
|
func (e *UnmarshalingParamError) Unwrap() error {
|
|
return e.Err
|
|
}
|
|
|
|
type RequiredParamError struct {
|
|
ParamName string
|
|
}
|
|
|
|
func (e *RequiredParamError) Error() string {
|
|
return fmt.Sprintf("Query argument %s is required, but not found", e.ParamName)
|
|
}
|
|
|
|
type RequiredHeaderError struct {
|
|
ParamName string
|
|
Err error
|
|
}
|
|
|
|
func (e *RequiredHeaderError) Error() string {
|
|
return fmt.Sprintf("Header parameter %s is required, but not found", e.ParamName)
|
|
}
|
|
|
|
func (e *RequiredHeaderError) Unwrap() error {
|
|
return e.Err
|
|
}
|
|
|
|
type InvalidParamFormatError struct {
|
|
ParamName string
|
|
Err error
|
|
}
|
|
|
|
func (e *InvalidParamFormatError) Error() string {
|
|
return fmt.Sprintf("Invalid format for parameter %s: %s", e.ParamName, e.Err.Error())
|
|
}
|
|
|
|
func (e *InvalidParamFormatError) Unwrap() error {
|
|
return e.Err
|
|
}
|
|
|
|
type TooManyValuesForParamError struct {
|
|
ParamName string
|
|
Count int
|
|
}
|
|
|
|
func (e *TooManyValuesForParamError) Error() string {
|
|
return fmt.Sprintf("Expected one value for %s, got %d", e.ParamName, e.Count)
|
|
}
|
|
|
|
// Handler creates http.Handler with routing matching OpenAPI spec.
|
|
func Handler(si ServerInterface) http.Handler {
|
|
return HandlerWithOptions(si, StdHTTPServerOptions{})
|
|
}
|
|
|
|
// ServeMux is an abstraction of [http.ServeMux].
|
|
type ServeMux interface {
|
|
HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
|
|
http.Handler
|
|
}
|
|
|
|
type StdHTTPServerOptions struct {
|
|
BaseURL string
|
|
BaseRouter ServeMux
|
|
Middlewares []MiddlewareFunc
|
|
ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
|
|
}
|
|
|
|
// HandlerFromMux creates http.Handler with routing matching OpenAPI spec based on the provided mux.
|
|
func HandlerFromMux(si ServerInterface, m ServeMux) http.Handler {
|
|
return HandlerWithOptions(si, StdHTTPServerOptions{
|
|
BaseRouter: m,
|
|
})
|
|
}
|
|
|
|
func HandlerFromMuxWithBaseURL(si ServerInterface, m ServeMux, baseURL string) http.Handler {
|
|
return HandlerWithOptions(si, StdHTTPServerOptions{
|
|
BaseURL: baseURL,
|
|
BaseRouter: m,
|
|
})
|
|
}
|
|
|
|
// HandlerWithOptions creates http.Handler with additional options
|
|
func HandlerWithOptions(si ServerInterface, options StdHTTPServerOptions) http.Handler {
|
|
m := options.BaseRouter
|
|
|
|
if m == nil {
|
|
m = http.NewServeMux()
|
|
}
|
|
if options.ErrorHandlerFunc == nil {
|
|
options.ErrorHandlerFunc = func(w http.ResponseWriter, r *http.Request, err error) {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
}
|
|
}
|
|
|
|
wrapper := ServerInterfaceWrapper{
|
|
Handler: si,
|
|
HandlerMiddlewares: options.Middlewares,
|
|
ErrorHandlerFunc: options.ErrorHandlerFunc,
|
|
}
|
|
|
|
m.HandleFunc(http.MethodGet+" "+options.BaseURL+"/api/me", wrapper.GetMe)
|
|
m.HandleFunc(http.MethodPut+" "+options.BaseURL+"/api/me", wrapper.UpdateMe)
|
|
m.HandleFunc(http.MethodGet+" "+options.BaseURL+"/api/projects", wrapper.ListProjects)
|
|
m.HandleFunc(http.MethodPost+" "+options.BaseURL+"/api/projects", wrapper.CreateProject)
|
|
m.HandleFunc(http.MethodGet+" "+options.BaseURL+"/api/projects/{projectId}", wrapper.GetProject)
|
|
m.HandleFunc(http.MethodGet+" "+options.BaseURL+"/api/projects/{projectId}/tasks", wrapper.ListTasks)
|
|
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)
|
|
|
|
return m
|
|
}
|
|
|
|
// Base64 encoded, compressed with deflate, json marshaled OpenAPI spec.
|
|
// Stored as a slice of fixed-width chunks rather than one concatenated
|
|
// 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{
|
|
"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",
|
|
"02eeHPYpZ7Yv6HfHP0wlW6//DgAA//8=",
|
|
}
|
|
|
|
// decodeSpec returns the embedded OpenAPI spec as raw JSON bytes,
|
|
// after base64-decoding and flate-decompressing the embedded blob.
|
|
func decodeSpec() ([]byte, error) {
|
|
encoded := strings.Join(swaggerSpec, "")
|
|
compressed, err := base64.StdEncoding.DecodeString(encoded)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error base64 decoding spec: %w", err)
|
|
}
|
|
zr := flate.NewReader(bytes.NewReader(compressed))
|
|
var buf bytes.Buffer
|
|
if _, err := buf.ReadFrom(zr); err != nil {
|
|
return nil, fmt.Errorf("read flate: %w", err)
|
|
}
|
|
if err := zr.Close(); err != nil {
|
|
return nil, fmt.Errorf("close flate reader: %w", err)
|
|
}
|
|
|
|
return buf.Bytes(), nil
|
|
}
|
|
|
|
var rawSpec = decodeSpecCached()
|
|
|
|
// a naive cache of the decoded OpenAPI spec
|
|
func decodeSpecCached() func() ([]byte, error) {
|
|
data, err := decodeSpec()
|
|
return func() ([]byte, error) {
|
|
return data, err
|
|
}
|
|
}
|
|
|
|
// Constructs a synthetic filesystem for resolving external references when loading openapi specifications.
|
|
func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error) {
|
|
res := make(map[string]func() ([]byte, error))
|
|
if len(pathToFile) > 0 {
|
|
res[pathToFile] = rawSpec
|
|
}
|
|
|
|
return res
|
|
}
|
|
|
|
// GetSpec returns the OpenAPI specification corresponding to the generated
|
|
// code in this file. External references in the spec are resolved through
|
|
// PathToRawSpec; externally-referenced files must be embedded in their
|
|
// corresponding Go packages (via the import-mapping feature). URL-based
|
|
// external refs are not supported.
|
|
func GetSpec() (swagger *openapi3.T, err error) {
|
|
resolvePath := PathToRawSpec("")
|
|
|
|
loader := openapi3.NewLoader()
|
|
loader.IsExternalRefsAllowed = true
|
|
loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) {
|
|
pathToFile := url.String()
|
|
pathToFile = path.Clean(pathToFile)
|
|
getSpec, ok := resolvePath[pathToFile]
|
|
if !ok {
|
|
err1 := fmt.Errorf("path not found: %s", pathToFile)
|
|
return nil, err1
|
|
}
|
|
return getSpec()
|
|
}
|
|
var specData []byte
|
|
specData, err = rawSpec()
|
|
if err != nil {
|
|
return
|
|
}
|
|
swagger, err = loader.LoadFromData(specData)
|
|
if err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// GetSpecJSON returns the raw JSON bytes of the embedded OpenAPI
|
|
// specification: decompressed but not unmarshaled. External references
|
|
// are not resolved here; the bytes are the spec exactly as embedded by
|
|
// codegen. The result is cached at package init time, so repeated calls
|
|
// are cheap.
|
|
func GetSpecJSON() ([]byte, error) {
|
|
return rawSpec()
|
|
}
|
|
|
|
// GetSwagger returns the OpenAPI specification corresponding to the
|
|
// generated code in this file.
|
|
//
|
|
// Deprecated: GetSwagger predates kin-openapi renaming openapi3.Swagger
|
|
// to openapi3.T. Use [GetSpec] instead. This wrapper is retained for
|
|
// backwards compatibility.
|
|
func GetSwagger() (*openapi3.T, error) {
|
|
return GetSpec()
|
|
}
|