Files
archie/internal/webui/tasks.go
T
sam 1830a89898
Quality / check (push) Successful in 3m56s
deploy / gate (push) Successful in 4m34s
deploy / archied-image (push) Successful in 2m55s
deploy / agent-image (push) Successful in 12s
deploy / dist-zip (push) Skipped
refactor(webui): extract the harness resource module (#1778)
2026-11-03 08:17:12 +11:00

64 lines
2.1 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) { 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)
}