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, 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 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, 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}/logs/download", a.handleTaskLogDownload) }