2026-02-16 04:34:29 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"net/http"
|
|
|
|
|
"time"
|
|
|
|
|
|
refactor: strip to pure package library (#3)
- Fix remaining 187 pkg/ files referencing core/cli → core/go
- Move SDK library code from internal/cmd/sdk/ → pkg/sdk/ (new package)
- Create pkg/rag/helpers.go with convenience functions from internal/cmd/rag/
- Fix pkg/mcp/tools_rag.go to use pkg/rag instead of internal/cmd/rag
- Fix pkg/build/buildcmd/cmd_sdk.go and pkg/release/sdk.go to use pkg/sdk
- Remove all non-library content: main.go, internal/, cmd/, docker/,
scripts/, tasks/, tools/, .core/, .forgejo/, .woodpecker/, Taskfile.yml
- Run go mod tidy to trim unused dependencies
core/go is now a pure Go package suite (library only).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Claude <developers@lethean.io>
Reviewed-on: https://forge.lthn.ai/core/go/pulls/3
2026-02-16 14:23:45 +00:00
|
|
|
"forge.lthn.ai/core/go/pkg/lab"
|
2026-02-16 04:34:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type APIHandler struct {
|
|
|
|
|
store *lab.Store
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewAPIHandler(s *lab.Store) *APIHandler {
|
|
|
|
|
return &APIHandler{store: s}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type apiResponse struct {
|
|
|
|
|
Status string `json:"status"`
|
|
|
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
|
|
|
Data any `json:"data"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *APIHandler) writeJSON(w http.ResponseWriter, data any) {
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
|
json.NewEncoder(w).Encode(apiResponse{
|
|
|
|
|
Status: "ok",
|
|
|
|
|
UpdatedAt: time.Now(),
|
|
|
|
|
Data: data,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *APIHandler) Status(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
h.writeJSON(w, h.store.Overview())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *APIHandler) Models(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
h.writeJSON(w, h.store.GetModels())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *APIHandler) Training(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
h.writeJSON(w, h.store.GetTraining())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *APIHandler) Agents(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
h.writeJSON(w, h.store.GetAgents())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *APIHandler) Services(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
h.writeJSON(w, h.store.GetServices())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *APIHandler) GoldenSet(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
h.writeJSON(w, h.store.GetGoldenSet())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *APIHandler) Runs(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
h.writeJSON(w, h.store.GetBenchmarks())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *APIHandler) Health(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
|
json.NewEncoder(w).Encode(map[string]string{"status": "ok"})
|
|
|
|
|
}
|