Files
viettranx 74dc086a80 fix(providers): post-merge fixes for Codex OAuth pools (#450)
- fix Rules of Hooks violation in chatgpt-oauth-routing-section
- add stale-while-revalidate with atomic dedup for RouteEligibility
- move raw SQL from HTTP handler to TracingStore.ListCodexPoolSpans
- persist round-robin state in Registry shared counter
- extract duplicated frontend helpers to agent-display-utils
- split oversized frontend files (964→214 lines max)
- add GIN indexes for spans.metadata and sessions.metadata
- fix tenant-aware provider lookup in handleQuota
- separate empty-role vs error handling in resolveTenantHint
- scope pool validation to chatgpt_oauth providers only
- wrap buildEntries in useCallback for stable useMemo deps
- document OAuth concurrent auth limitation and RoleAdmin breaking change
2026-03-27 10:19:16 +07:00

42 lines
1.2 KiB
Go

package http
import (
"net/http"
"github.com/nextlevelbuilder/goclaw/internal/i18n"
"github.com/nextlevelbuilder/goclaw/internal/oauth"
"github.com/nextlevelbuilder/goclaw/internal/store"
)
func (h *OAuthHandler) handleQuota(w http.ResponseWriter, r *http.Request) {
locale := extractLocale(r)
providerName := oauthProviderName(r)
if !isValidSlug(providerName) {
writeJSON(w, http.StatusBadRequest, map[string]string{"error": i18n.T(locale, i18n.MsgInvalidSlug, "provider")})
return
}
tenantID := store.TenantIDFromContext(r.Context())
provider, err := lookupProviderByNameWithMasterFallback(r.Context(), h.provStore, tenantID, providerName)
if err != nil {
writeJSON(w, http.StatusNotFound, map[string]string{
"error": err.Error(),
"code": "provider_not_found",
})
return
}
if provider.ProviderType != store.ProviderChatGPTOAuth {
writeJSON(w, http.StatusConflict, map[string]string{
"error": (&oauth.ProviderTypeConflictError{
ProviderName: providerName,
ProviderType: provider.ProviderType,
}).Error(),
"code": "provider_type_conflict",
})
return
}
result := oauth.FetchOpenAIQuota(r.Context(), provider, h.newTokenSource(r.Context(), providerName, "", ""))
writeJSON(w, http.StatusOK, result)
}