feat: add INVALID_MODEL_ID retry config + detailed request logging
- Config: new InvalidModelRetries field (default 3, range 0-20) - Admin API: /admin/api/general GET/POST for general settings - Admin UI: new "通用设置" card with retry count input - CallKiroAPI: same-endpoint retry on HTTP 400 INVALID_MODEL_ID before falling back to next endpoint - CallKiroAPI: switched to log.Printf with timestamp, account, model, attempt counter, elapsed time, error body truncation
This commit is contained in:
@@ -1781,6 +1781,10 @@ func (h *Handler) handleAdminAPI(w http.ResponseWriter, r *http.Request) {
|
||||
h.apiGetEndpointConfig(w, r)
|
||||
case path == "/endpoint" && r.Method == "POST":
|
||||
h.apiUpdateEndpointConfig(w, r)
|
||||
case path == "/general" && r.Method == "GET":
|
||||
h.apiGetGeneralConfig(w, r)
|
||||
case path == "/general" && r.Method == "POST":
|
||||
h.apiUpdateGeneralConfig(w, r)
|
||||
case path == "/version" && r.Method == "GET":
|
||||
h.apiGetVersion(w, r)
|
||||
case path == "/export" && r.Method == "POST":
|
||||
@@ -2745,6 +2749,41 @@ func (h *Handler) apiUpdateEndpointConfig(w http.ResponseWriter, r *http.Request
|
||||
json.NewEncoder(w).Encode(map[string]bool{"success": true})
|
||||
}
|
||||
|
||||
// apiGetGeneralConfig 获取通用设置
|
||||
func (h *Handler) apiGetGeneralConfig(w http.ResponseWriter, r *http.Request) {
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"invalidModelRetries": config.GetInvalidModelRetries(),
|
||||
})
|
||||
}
|
||||
|
||||
// apiUpdateGeneralConfig 更新通用设置
|
||||
func (h *Handler) apiUpdateGeneralConfig(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
InvalidModelRetries *int `json:"invalidModelRetries"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
w.WriteHeader(400)
|
||||
json.NewEncoder(w).Encode(map[string]string{"error": "Invalid JSON"})
|
||||
return
|
||||
}
|
||||
|
||||
if req.InvalidModelRetries != nil {
|
||||
n := *req.InvalidModelRetries
|
||||
if n < 0 || n > 20 {
|
||||
w.WriteHeader(400)
|
||||
json.NewEncoder(w).Encode(map[string]string{"error": "invalidModelRetries must be 0-20"})
|
||||
return
|
||||
}
|
||||
if err := config.UpdateInvalidModelRetries(n); err != nil {
|
||||
w.WriteHeader(500)
|
||||
json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(map[string]bool{"success": true})
|
||||
}
|
||||
|
||||
// apiGetVersion 获取版本信息
|
||||
func (h *Handler) apiGetVersion(w http.ResponseWriter, r *http.Request) {
|
||||
json.NewEncoder(w).Encode(map[string]string{
|
||||
|
||||
Reference in New Issue
Block a user