MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / isAuthBlockedForModel

Function isAuthBlockedForModel

sdk/cliproxy/auth/selector.go:305–362  ·  view source on GitHub ↗
(auth *Auth, model string, now time.Time)

Source from the content-addressed store, hash-verified

303}
304
305func isAuthBlockedForModel(auth *Auth, model string, now time.Time) (bool, blockReason, time.Time) {
306 if auth == nil {
307 return true, blockReasonOther, time.Time{}
308 }
309 if auth.Disabled || auth.Status == StatusDisabled {
310 return true, blockReasonDisabled, time.Time{}
311 }
312 if model != "" {
313 if len(auth.ModelStates) > 0 {
314 state, ok := auth.ModelStates[model]
315 if (!ok || state == nil) && model != "" {
316 baseModel := canonicalModelKey(model)
317 if baseModel != "" && baseModel != model {
318 state, ok = auth.ModelStates[baseModel]
319 }
320 }
321 if ok && state != nil {
322 if state.Status == StatusDisabled {
323 return true, blockReasonDisabled, time.Time{}
324 }
325 if state.Unavailable {
326 if state.NextRetryAfter.IsZero() {
327 return false, blockReasonNone, time.Time{}
328 }
329 if state.NextRetryAfter.After(now) {
330 next := state.NextRetryAfter
331 if !state.Quota.NextRecoverAt.IsZero() && state.Quota.NextRecoverAt.After(now) {
332 next = state.Quota.NextRecoverAt
333 }
334 if next.Before(now) {
335 next = now
336 }
337 if state.Quota.Exceeded {
338 return true, blockReasonCooldown, next
339 }
340 return true, blockReasonOther, next
341 }
342 }
343 return false, blockReasonNone, time.Time{}
344 }
345 }
346 return false, blockReasonNone, time.Time{}
347 }
348 if auth.Unavailable && auth.NextRetryAfter.After(now) {
349 next := auth.NextRetryAfter
350 if !auth.Quota.NextRecoverAt.IsZero() && auth.Quota.NextRecoverAt.After(now) {
351 next = auth.Quota.NextRecoverAt
352 }
353 if next.Before(now) {
354 next = now
355 }
356 if auth.Quota.Exceeded {
357 return true, blockReasonCooldown, next
358 }
359 return true, blockReasonOther, next
360 }
361 return false, blockReasonNone, time.Time{}
362}

Calls 1

canonicalModelKeyFunction · 0.85