All checks were successful
Beta Release / beta (push) Successful in 37s
- Add POST /api/providers/validate backend endpoint that sends a test request to the provider's chat/completions API to verify the key - Add validateProvider to frontend API client - Redesign PanelProviders: show token input inline with Validate button, display valid/invalid badge after validation, Save only appears after successful validation - Add i18n keys (EN/FR) for validation flow 💾 Generated with Crush Assisted-by: GLM-5-Turbo via Crush <crush@charm.land>
71 lines
2.3 KiB
Go
71 lines
2.3 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/muyue/muyue/internal/config"
|
|
"github.com/muyue/muyue/internal/scanner"
|
|
)
|
|
|
|
type Server struct {
|
|
config *config.MuyueConfig
|
|
scanResult *scanner.ScanResult
|
|
mux *http.ServeMux
|
|
convStore *ConversationStore
|
|
}
|
|
|
|
func NewServer(cfg *config.MuyueConfig) *Server {
|
|
s := &Server{
|
|
config: cfg,
|
|
mux: http.NewServeMux(),
|
|
}
|
|
s.scanResult = scanner.ScanSystem()
|
|
s.convStore = NewConversationStore()
|
|
s.routes()
|
|
return s
|
|
}
|
|
|
|
func (s *Server) routes() {
|
|
s.mux.HandleFunc("/api/info", s.handleInfo)
|
|
s.mux.HandleFunc("/api/system", s.handleSystem)
|
|
s.mux.HandleFunc("/api/tools", s.handleTools)
|
|
s.mux.HandleFunc("/api/config", s.handleConfig)
|
|
s.mux.HandleFunc("/api/providers", s.handleProviders)
|
|
s.mux.HandleFunc("/api/skills", s.handleSkills)
|
|
s.mux.HandleFunc("/api/lsp", s.handleLSP)
|
|
s.mux.HandleFunc("/api/mcp", s.handleMCP)
|
|
s.mux.HandleFunc("/api/updates", s.handleUpdates)
|
|
s.mux.HandleFunc("/api/install", s.handleInstall)
|
|
s.mux.HandleFunc("/api/scan", s.handleScan)
|
|
s.mux.HandleFunc("/api/preferences", s.handleUpdatePreferences)
|
|
s.mux.HandleFunc("/api/terminal", s.handleTerminal)
|
|
s.mux.HandleFunc("/api/ws/terminal", s.handleTerminalWS)
|
|
s.mux.HandleFunc("/api/terminal/sessions", s.handleTerminalSessions)
|
|
s.mux.HandleFunc("/api/terminal/sessions/", s.handleTerminalSessionsDelete)
|
|
s.mux.HandleFunc("/api/mcp/configure", s.handleMCPConfigure)
|
|
s.mux.HandleFunc("/api/config/profile", s.handleSaveProfile)
|
|
s.mux.HandleFunc("/api/config/provider", s.handleSaveProvider)
|
|
s.mux.HandleFunc("/api/providers/validate", s.handleValidateProvider)
|
|
s.mux.HandleFunc("/api/update/run", s.handleRunUpdate)
|
|
s.mux.HandleFunc("/api/chat", s.handleChat)
|
|
s.mux.HandleFunc("/api/chat/history", s.handleChatHistory)
|
|
s.mux.HandleFunc("/api/chat/clear", s.handleChatClear)
|
|
}
|
|
|
|
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
if strings.HasPrefix(r.URL.Path, "/api/ws/") {
|
|
s.mux.ServeHTTP(w, r)
|
|
return
|
|
}
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
|
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, OPTIONS")
|
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
|
if r.Method == "OPTIONS" {
|
|
w.WriteHeader(http.StatusOK)
|
|
return
|
|
}
|
|
s.mux.ServeHTTP(w, r)
|
|
}
|