Files
archie/internal/webui/tasks.go
T
sam 0a37b551f5
Quality / check (push) Successful in 3m47s
deploy / gate (push) Successful in 4m32s
deploy / archied-image (push) Successful in 2m51s
deploy / agent-image (push) Successful in 10s
deploy / dist-zip (push) Skipped
refactor(webui): extract the tasks resource module (#1778)
2026-11-03 08:06:56 +11:00

61 lines
1.9 KiB
Go

package webui
import (
"log/slog"
"net/http"
"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
}
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,
}
}
func (a *tasksAPI) logf(msg string, args ...any) {
if a.log == nil {
return
}
a.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)
}