67 lines
2.2 KiB
Go
67 lines
2.2 KiB
Go
package webui
|
|
|
|
import (
|
|
"log/slog"
|
|
"net/http"
|
|
|
|
controlpb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
|
|
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
|
)
|
|
|
|
// tasksAPI owns the /api/tasks routes and /api/task-meta. Optional
|
|
// dependencies (steps, taskLogs, sandbox, chat) stay nil-safe: each handler
|
|
// reports the feature unavailable rather than the module being absent.
|
|
type tasksAPI struct {
|
|
store storecontract.TaskStore
|
|
steps storecontract.StepReader
|
|
taskLogs TaskLogSource
|
|
sandbox SandboxView
|
|
chat *ChatService
|
|
log *slog.Logger
|
|
|
|
authorize func(http.ResponseWriter, *http.Request) bool
|
|
configSource func() ConfigViewSource
|
|
recovery func(*http.Request, *task.Task) *taskRecoveryView
|
|
controlPlane controlpb.ControlPlaneServiceClient
|
|
}
|
|
|
|
func newTasksAPI(s *Server) *tasksAPI {
|
|
return &tasksAPI{
|
|
store: s.Store,
|
|
steps: s.Steps,
|
|
taskLogs: s.TaskLogs,
|
|
sandbox: s.SandboxView,
|
|
chat: s.Chat,
|
|
log: s.Log,
|
|
authorize: s.authorizeTaskMutation,
|
|
configSource: s.configSource,
|
|
recovery: s.taskRecovery,
|
|
controlPlane: s.ControlPlane,
|
|
}
|
|
}
|
|
|
|
func (a *tasksAPI) logf(msg string, args ...any) { warnf(a.log, msg, args...) }
|
|
|
|
// warnf logs at warn level and tolerates a nil logger, as tests construct
|
|
// servers without one.
|
|
func warnf(log *slog.Logger, msg string, args ...any) {
|
|
if log != nil {
|
|
log.Warn(msg, args...)
|
|
}
|
|
}
|
|
|
|
func (a *tasksAPI) register(mux *http.ServeMux) {
|
|
mux.HandleFunc("GET /api/tasks", a.handleTasks)
|
|
mux.HandleFunc("GET /api/task-meta", a.handleTaskMeta)
|
|
mux.HandleFunc("POST /api/tasks/{id}/action", a.handleTaskAction)
|
|
mux.HandleFunc("GET /api/tasks/{id}", a.handleTask)
|
|
mux.HandleFunc("GET /api/tasks/{id}/attempts", a.handleTaskAttempts)
|
|
mux.HandleFunc("GET /api/tasks/{id}/changes", a.handleTaskChanges)
|
|
mux.HandleFunc("GET /api/tasks/{id}/debug", a.handleTaskDebug)
|
|
mux.HandleFunc("GET /api/tasks/{id}/logs", a.handleTaskLogs)
|
|
mux.HandleFunc("GET /api/tasks/{id}/transcript", a.handleTaskTranscript)
|
|
mux.HandleFunc("GET /api/tasks/{id}/sandbox", a.handleTaskSandbox)
|
|
mux.HandleFunc("GET /api/tasks/{id}/logs/download", a.handleTaskLogDownload)
|
|
}
|