feat(backend): implement gemini quota simulation and rate limiting
- feat: add local quota tracking for gemini tiers (Legacy/Pro/Ultra) - feat: implement PreCheckUsage in RateLimitService - feat: align gemini daily reset window with PST - fix: sticky session fallback logic
This commit is contained in:
@@ -86,3 +86,11 @@ GEMINI_OAUTH_CLIENT_ID=
|
||||
GEMINI_OAUTH_CLIENT_SECRET=
|
||||
# Optional; leave empty to auto-select scopes based on oauth_type
|
||||
GEMINI_OAUTH_SCOPES=
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Gemini Quota Policy (OPTIONAL, local simulation)
|
||||
# -----------------------------------------------------------------------------
|
||||
# JSON overrides for local quota simulation (Code Assist only).
|
||||
# Example:
|
||||
# GEMINI_QUOTA_POLICY={"tiers":{"LEGACY":{"pro_rpd":50,"flash_rpd":1500,"cooldown_minutes":30},"PRO":{"pro_rpd":1500,"flash_rpd":4000,"cooldown_minutes":5},"ULTRA":{"pro_rpd":2000,"flash_rpd":0,"cooldown_minutes":5}}}
|
||||
GEMINI_QUOTA_POLICY=
|
||||
|
||||
@@ -123,6 +123,7 @@ docker-compose down -v
|
||||
| `GEMINI_OAUTH_CLIENT_ID` | No | *(builtin)* | Google OAuth client ID (Gemini OAuth). Leave empty to use the built-in Gemini CLI client. |
|
||||
| `GEMINI_OAUTH_CLIENT_SECRET` | No | *(builtin)* | Google OAuth client secret (Gemini OAuth). Leave empty to use the built-in Gemini CLI client. |
|
||||
| `GEMINI_OAUTH_SCOPES` | No | *(default)* | OAuth scopes (Gemini OAuth) |
|
||||
| `GEMINI_QUOTA_POLICY` | No | *(empty)* | JSON overrides for Gemini local quota simulation (Code Assist only). |
|
||||
|
||||
See `.env.example` for all available options.
|
||||
|
||||
|
||||
@@ -156,3 +156,19 @@ gemini:
|
||||
client_secret: "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"
|
||||
# Optional scopes (space-separated). Leave empty to auto-select based on oauth_type.
|
||||
scopes: ""
|
||||
quota:
|
||||
# Optional: local quota simulation for Gemini Code Assist (local billing).
|
||||
# These values are used for UI progress + precheck scheduling, not official Google quotas.
|
||||
tiers:
|
||||
LEGACY:
|
||||
pro_rpd: 50
|
||||
flash_rpd: 1500
|
||||
cooldown_minutes: 30
|
||||
PRO:
|
||||
pro_rpd: 1500
|
||||
flash_rpd: 4000
|
||||
cooldown_minutes: 5
|
||||
ULTRA:
|
||||
pro_rpd: 2000
|
||||
flash_rpd: 0
|
||||
cooldown_minutes: 5
|
||||
|
||||
@@ -90,6 +90,7 @@ services:
|
||||
- GEMINI_OAUTH_CLIENT_ID=${GEMINI_OAUTH_CLIENT_ID:-}
|
||||
- GEMINI_OAUTH_CLIENT_SECRET=${GEMINI_OAUTH_CLIENT_SECRET:-}
|
||||
- GEMINI_OAUTH_SCOPES=${GEMINI_OAUTH_SCOPES:-}
|
||||
- GEMINI_QUOTA_POLICY=${GEMINI_QUOTA_POLICY:-}
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
|
||||
21
deploy/docker-compose.override.yml
Normal file
21
deploy/docker-compose.override.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
# =============================================================================
|
||||
# Docker Compose Override for Local Development
|
||||
# =============================================================================
|
||||
# This file automatically extends docker-compose-test.yml
|
||||
# Usage: docker-compose -f docker-compose-test.yml up -d
|
||||
# =============================================================================
|
||||
|
||||
services:
|
||||
# ===========================================================================
|
||||
# PostgreSQL - 暴露端口用于本地开发
|
||||
# ===========================================================================
|
||||
postgres:
|
||||
ports:
|
||||
- "127.0.0.1:5432:5432"
|
||||
|
||||
# ===========================================================================
|
||||
# Redis - 暴露端口用于本地开发
|
||||
# ===========================================================================
|
||||
redis:
|
||||
ports:
|
||||
- "127.0.0.1:6379:6379"
|
||||
@@ -90,6 +90,7 @@ services:
|
||||
- GEMINI_OAUTH_CLIENT_ID=${GEMINI_OAUTH_CLIENT_ID:-}
|
||||
- GEMINI_OAUTH_CLIENT_SECRET=${GEMINI_OAUTH_CLIENT_SECRET:-}
|
||||
- GEMINI_OAUTH_SCOPES=${GEMINI_OAUTH_SCOPES:-}
|
||||
- GEMINI_QUOTA_POLICY=${GEMINI_QUOTA_POLICY:-}
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
|
||||
Reference in New Issue
Block a user