luckfun233 commited on
Commit ·
b0074f5
1
Parent(s): 9c953d6
feat(agy): 内嵌 agy2api,接入 Gemini 模型与独立 AGY 面板
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .dockerignore +10 -0
- .env.example +5 -0
- .github/workflows/sync-to-hf.yml +1 -0
- .gitignore +3 -0
- API.en.md +15 -4
- API.md +15 -4
- Dockerfile +13 -2
- README.en.md +19 -2
- README.md +35 -3
- agy2api/.dockerignore +17 -0
- agy2api/.env.example +154 -0
- agy2api/.gitignore +106 -0
- agy2api/AGENTS.md +52 -0
- agy2api/CONTRIBUTING.md +169 -0
- agy2api/Dockerfile +41 -0
- agy2api/LICENSE +83 -0
- agy2api/README.md +348 -0
- agy2api/config.py +791 -0
- agy2api/darwin-install.sh +55 -0
- agy2api/dist/assets/index-CqsIYAIJ.js +0 -0
- agy2api/dist/assets/index-xC348ENO.css +1 -0
- agy2api/dist/favicon-32.png +0 -0
- agy2api/dist/favicon.ico +0 -0
- agy2api/dist/index.html +24 -0
- agy2api/docker-compose.yml +25 -0
- agy2api/docs/README_EN.md +681 -0
- agy2api/docs/README_JA.md +680 -0
- agy2api/frontend/index.html +23 -0
- agy2api/frontend/package-lock.json +0 -0
- agy2api/frontend/package.json +24 -0
- agy2api/frontend/postcss.config.js +6 -0
- agy2api/frontend/public/favicon-32.png +0 -0
- agy2api/frontend/public/favicon.ico +0 -0
- agy2api/frontend/src/App.jsx +116 -0
- agy2api/frontend/src/api.js +31 -0
- agy2api/frontend/src/basePath.js +8 -0
- agy2api/frontend/src/components/Modal.jsx +49 -0
- agy2api/frontend/src/components/Select.jsx +100 -0
- agy2api/frontend/src/index.css +77 -0
- agy2api/frontend/src/main.jsx +10 -0
- agy2api/frontend/src/pages/About.jsx +177 -0
- agy2api/frontend/src/pages/Config.jsx +512 -0
- agy2api/frontend/src/pages/Credentials.jsx +909 -0
- agy2api/frontend/src/pages/Login.jsx +89 -0
- agy2api/frontend/src/pages/OAuth.jsx +230 -0
- agy2api/frontend/src/pages/Upload.jsx +199 -0
- agy2api/frontend/src/pages/UsageLogs.jsx +510 -0
- agy2api/frontend/tailwind.config.js +25 -0
- agy2api/frontend/vite.config.js +43 -0
- agy2api/install.ps1 +35 -0
.dockerignore
CHANGED
|
@@ -13,6 +13,16 @@ develop-eggs/
|
|
| 13 |
dist/*
|
| 14 |
!dist/docker-input/
|
| 15 |
!dist/docker-input/*.tar.gz
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
downloads/
|
| 17 |
eggs/
|
| 18 |
.eggs/
|
|
|
|
| 13 |
dist/*
|
| 14 |
!dist/docker-input/
|
| 15 |
!dist/docker-input/*.tar.gz
|
| 16 |
+
# 内嵌 agy2api 的预编译前端资源需要进入镜像
|
| 17 |
+
!agy2api/dist/
|
| 18 |
+
!agy2api/dist/**
|
| 19 |
+
# 本地开发产物不进入镜像
|
| 20 |
+
agy2api/.venv/
|
| 21 |
+
agy2api/creds/
|
| 22 |
+
agy2api/data/
|
| 23 |
+
agy2api/frontend/node_modules/
|
| 24 |
+
agy2api/**/__pycache__/
|
| 25 |
+
agy2api/**/*.py[cod]
|
| 26 |
downloads/
|
| 27 |
eggs/
|
| 28 |
.eggs/
|
.env.example
CHANGED
|
@@ -18,3 +18,8 @@ DS2API_CONFIG_PATH=/app/config.json
|
|
| 18 |
|
| 19 |
# Optional: static admin assets path
|
| 20 |
# DS2API_STATIC_ADMIN_DIR=/app/static/admin
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
# Optional: static admin assets path
|
| 20 |
# DS2API_STATIC_ADMIN_DIR=/app/static/admin
|
| 21 |
+
|
| 22 |
+
# Embedded agy2api sidecar (Gemini / Antigravity)
|
| 23 |
+
# AGY2API_BASE_URL=http://127.0.0.1:7861
|
| 24 |
+
# AGY2API_API_PASSWORD=change-me
|
| 25 |
+
# AGY2API_PANEL_PASSWORD=change-me
|
.github/workflows/sync-to-hf.yml
CHANGED
|
@@ -3,6 +3,7 @@ name: Sync to Hugging Face
|
|
| 3 |
on:
|
| 4 |
push:
|
| 5 |
branches: [main]
|
|
|
|
| 6 |
|
| 7 |
jobs:
|
| 8 |
sync-to-hf:
|
|
|
|
| 3 |
on:
|
| 4 |
push:
|
| 5 |
branches: [main]
|
| 6 |
+
workflow_dispatch:
|
| 7 |
|
| 8 |
jobs:
|
| 9 |
sync-to-hf:
|
.gitignore
CHANGED
|
@@ -35,6 +35,9 @@ pnpm-lock.yaml
|
|
| 35 |
|
| 36 |
# Build artifacts
|
| 37 |
dist/
|
|
|
|
|
|
|
|
|
|
| 38 |
*.tsbuildinfo
|
| 39 |
.cache/
|
| 40 |
.parcel-cache/
|
|
|
|
| 35 |
|
| 36 |
# Build artifacts
|
| 37 |
dist/
|
| 38 |
+
# 内嵌 agy2api 的预编译前端资源必须入库
|
| 39 |
+
!agy2api/dist/
|
| 40 |
+
!agy2api/dist/**
|
| 41 |
*.tsbuildinfo
|
| 42 |
.cache/
|
| 43 |
.parcel-cache/
|
API.en.md
CHANGED
|
@@ -123,10 +123,14 @@ Gemini-compatible clients can also send `x-goog-api-key`, `?key=`, or `?api_key=
|
|
| 123 |
| POST | `/messages` | Business | Claude shortcut path |
|
| 124 |
| POST | `/v1/messages/count_tokens` | Business | Claude token counting shortcut |
|
| 125 |
| POST | `/messages/count_tokens` | Business | Claude token counting shortcut |
|
|
|
|
|
|
|
| 126 |
| POST | `/v1beta/models/{model}:generateContent` | Business | Gemini non-stream |
|
| 127 |
| POST | `/v1beta/models/{model}:streamGenerateContent` | Business | Gemini stream |
|
| 128 |
| POST | `/v1/models/{model}:generateContent` | Business | Gemini non-stream compat path |
|
| 129 |
| POST | `/v1/models/{model}:streamGenerateContent` | Business | Gemini stream compat path |
|
|
|
|
|
|
|
| 130 |
| GET | `/api/version` | None | Ollama version endpoint |
|
| 131 |
| GET | `/api/tags` | None | Ollama model list |
|
| 132 |
| POST | `/api/show` | None | Ollama model capability query (returns `id` + `capabilities`) |
|
|
@@ -204,7 +208,7 @@ Server-side records are essentially an archive of DeepSeek upstream responses: O
|
|
| 204 |
|
| 205 |
### `GET /v1/models`
|
| 206 |
|
| 207 |
-
No auth required. Returns the currently supported DeepSeek native
|
| 208 |
|
| 209 |
**Response**:
|
| 210 |
|
|
@@ -215,11 +219,17 @@ No auth required. Returns the currently supported DeepSeek native model list.
|
|
| 215 |
{"id": "deepseek-v4-flash", "object": "model", "created": 1677610602, "owned_by": "deepseek", "permission": []},
|
| 216 |
{"id": "deepseek-v4-flash-nothinking", "object": "model", "created": 1677610602, "owned_by": "deepseek", "permission": []},
|
| 217 |
{"id": "deepseek-v4-flash-search", "object": "model", "created": 1677610602, "owned_by": "deepseek", "permission": []},
|
| 218 |
-
{"id": "deepseek-v4-flash-search-nothinking", "object": "model", "created": 1677610602, "owned_by": "deepseek", "permission": []}
|
|
|
|
|
|
|
| 219 |
]
|
| 220 |
}
|
| 221 |
```
|
| 222 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
> Note: `/v1/models` returns normalized DeepSeek native model IDs. Common aliases are accepted only as request input and are not expanded as separate items in this endpoint. A `-nothinking` suffix means thinking/reasoning is always off, regardless of what the request asks for.
|
| 224 |
>
|
| 225 |
> The model line has collapsed to the four flash variants above: `deepseek-v4-pro` / `deepseek-v4-pro-search` / `deepseek-v4-vision` and their `-nothinking` forms are retired and no longer appear in this endpoint, Ollama `/api/tags`, or `/anthropic/v1/models`. Old names still work as request input and are silently mapped to the matching flash model (see the next section).
|
|
@@ -228,6 +238,7 @@ No auth required. Returns the currently supported DeepSeek native model list.
|
|
| 228 |
|
| 229 |
For `chat` / `responses` / `embeddings`, DS2API follows a wide-input/strict-output policy:
|
| 230 |
|
|
|
|
| 231 |
1. Match DeepSeek native model IDs first.
|
| 232 |
2. Then match exact keys in `model_aliases`.
|
| 233 |
3. If the request name ends with `-nothinking`, resolve the base alias and append the corresponding no-thinking variant.
|
|
@@ -238,7 +249,7 @@ Built-in aliases come from `internal/config/models.go`; `config.model_aliases` c
|
|
| 238 |
- OpenAI / Codex: `gpt-4o`, `gpt-4.1`, `gpt-5`, `gpt-5.5`, `gpt-5-codex`, `gpt-5.3-codex`, `codex-mini-latest` → `deepseek-v4-flash`
|
| 239 |
- OpenAI reasoning: `o1`, `o3`, `o4-mini` → `deepseek-v4-flash`; `o3-deep-research`, `o4-mini-deep-research` → `deepseek-v4-flash-search`
|
| 240 |
- Claude: `claude-opus-4-6`, `claude-sonnet-4-6`, `claude-haiku-4-5`, `claude-3-5-sonnet-latest` → `deepseek-v4-flash`
|
| 241 |
-
- Gemini: `gemini-2.5-pro`, `gemini-2.5-flash`, `gemini-3.1-pro`, `gemini-3-pro`, `gemini-3-flash`, `gemini-3.1-flash-lite`, `gemini-pro-vision` → `deepseek-v4-flash`
|
| 242 |
- Other exact built-in aliases: `llama-3.1-70b-instruct`, `qwen-max` → `deepseek-v4-flash`
|
| 243 |
|
| 244 |
Aliases with a `-nothinking` suffix also map to the corresponding forced no-thinking DeepSeek model.
|
|
@@ -304,7 +315,7 @@ Content-Type: application/json
|
|
| 304 |
|
| 305 |
| Field | Type | Required | Notes |
|
| 306 |
| --- | --- | --- | --- |
|
| 307 |
-
| `model` | string | ✅ | DeepSeek native models + common aliases (`gpt-5.5`, `gpt-5.4-mini`, `gpt-5.3-codex`, `o3`, `claude-opus-4-6`, `
|
| 308 |
| `messages` | array | ✅ | OpenAI-style messages |
|
| 309 |
| `stream` | boolean | ❌ | Default `false` |
|
| 310 |
| `tools` | array | ❌ | Function calling schema |
|
|
|
|
| 123 |
| POST | `/messages` | Business | Claude shortcut path |
|
| 124 |
| POST | `/v1/messages/count_tokens` | Business | Claude token counting shortcut |
|
| 125 |
| POST | `/messages/count_tokens` | Business | Claude token counting shortcut |
|
| 126 |
+
| GET | `/v1beta/models` | None | Gemini model list (static catalog + agy2api live discovery) |
|
| 127 |
+
| GET | `/v1beta/models/{model}` | None | Gemini single-model lookup |
|
| 128 |
| POST | `/v1beta/models/{model}:generateContent` | Business | Gemini non-stream |
|
| 129 |
| POST | `/v1beta/models/{model}:streamGenerateContent` | Business | Gemini stream |
|
| 130 |
| POST | `/v1/models/{model}:generateContent` | Business | Gemini non-stream compat path |
|
| 131 |
| POST | `/v1/models/{model}:streamGenerateContent` | Business | Gemini stream compat path |
|
| 132 |
+
| GET | `/agy/` | AGY panel password | Embedded agy2api panel (Antigravity OAuth / credentials) |
|
| 133 |
+
| ANY | `/agy/*` | AGY panel password / API password | agy2api native OpenAI / Gemini / Claude endpoints |
|
| 134 |
| GET | `/api/version` | None | Ollama version endpoint |
|
| 135 |
| GET | `/api/tags` | None | Ollama model list |
|
| 136 |
| POST | `/api/show` | None | Ollama model capability query (returns `id` + `capabilities`) |
|
|
|
|
| 208 |
|
| 209 |
### `GET /v1/models`
|
| 210 |
|
| 211 |
+
No auth required. Returns the currently supported DeepSeek native models plus the embedded agy2api Gemini models.
|
| 212 |
|
| 213 |
**Response**:
|
| 214 |
|
|
|
|
| 219 |
{"id": "deepseek-v4-flash", "object": "model", "created": 1677610602, "owned_by": "deepseek", "permission": []},
|
| 220 |
{"id": "deepseek-v4-flash-nothinking", "object": "model", "created": 1677610602, "owned_by": "deepseek", "permission": []},
|
| 221 |
{"id": "deepseek-v4-flash-search", "object": "model", "created": 1677610602, "owned_by": "deepseek", "permission": []},
|
| 222 |
+
{"id": "deepseek-v4-flash-search-nothinking", "object": "model", "created": 1677610602, "owned_by": "deepseek", "permission": []},
|
| 223 |
+
{"id": "gemini-2.5-pro", "object": "model", "created": 1715635200, "owned_by": "google", "permission": []},
|
| 224 |
+
{"id": "gemini-3-pro-preview", "object": "model", "created": 1715635200, "owned_by": "google", "permission": []}
|
| 225 |
]
|
| 226 |
}
|
| 227 |
```
|
| 228 |
|
| 229 |
+
The static Gemini set is: `gemini-2.5-flash`, `gemini-2.5-pro`, `gemini-2.5-pro-high`, `gemini-2.5-pro-low`, `gemini-2.5-pro-search`, `gemini-3-flash-preview`, `gemini-3-pro-preview`, `gemini-3.1-pro-preview`, `gemini-3.1-flash-image`. They are served by the embedded agy2api sidecar, whose separate panel lives at `/agy/`.
|
| 230 |
+
|
| 231 |
+
When agy2api has Antigravity credentials configured, the list also merges the Gemini models returned by its live `/v1/models` endpoint (including new upstream IDs and `抗截断-` variants). The result is cached for 60 seconds, with automatic fallback to the static catalog if the sidecar is unavailable.
|
| 232 |
+
|
| 233 |
> Note: `/v1/models` returns normalized DeepSeek native model IDs. Common aliases are accepted only as request input and are not expanded as separate items in this endpoint. A `-nothinking` suffix means thinking/reasoning is always off, regardless of what the request asks for.
|
| 234 |
>
|
| 235 |
> The model line has collapsed to the four flash variants above: `deepseek-v4-pro` / `deepseek-v4-pro-search` / `deepseek-v4-vision` and their `-nothinking` forms are retired and no longer appear in this endpoint, Ollama `/api/tags`, or `/anthropic/v1/models`. Old names still work as request input and are silently mapped to the matching flash model (see the next section).
|
|
|
|
| 238 |
|
| 239 |
For `chat` / `responses` / `embeddings`, DS2API follows a wide-input/strict-output policy:
|
| 240 |
|
| 241 |
+
0. If the model name (after stripping the `抗截断-` prefix) starts with `gemini-`, `/v1/chat/completions`, `/v1/messages` and the Gemini-native routes are forwarded to the embedded agy2api sidecar before this chain.
|
| 242 |
1. Match DeepSeek native model IDs first.
|
| 243 |
2. Then match exact keys in `model_aliases`.
|
| 244 |
3. If the request name ends with `-nothinking`, resolve the base alias and append the corresponding no-thinking variant.
|
|
|
|
| 249 |
- OpenAI / Codex: `gpt-4o`, `gpt-4.1`, `gpt-5`, `gpt-5.5`, `gpt-5-codex`, `gpt-5.3-codex`, `codex-mini-latest` → `deepseek-v4-flash`
|
| 250 |
- OpenAI reasoning: `o1`, `o3`, `o4-mini` → `deepseek-v4-flash`; `o3-deep-research`, `o4-mini-deep-research` → `deepseek-v4-flash-search`
|
| 251 |
- Claude: `claude-opus-4-6`, `claude-sonnet-4-6`, `claude-haiku-4-5`, `claude-3-5-sonnet-latest` → `deepseek-v4-flash`
|
| 252 |
+
- Gemini (only on interfaces not dispatched to agy2api, such as `/v1/responses`): `gemini-2.5-pro`, `gemini-2.5-flash`, `gemini-3.1-pro`, `gemini-3-pro`, `gemini-3-flash`, `gemini-3.1-flash-lite`, `gemini-pro-vision` → `deepseek-v4-flash`
|
| 253 |
- Other exact built-in aliases: `llama-3.1-70b-instruct`, `qwen-max` → `deepseek-v4-flash`
|
| 254 |
|
| 255 |
Aliases with a `-nothinking` suffix also map to the corresponding forced no-thinking DeepSeek model.
|
|
|
|
| 315 |
|
| 316 |
| Field | Type | Required | Notes |
|
| 317 |
| --- | --- | --- | --- |
|
| 318 |
+
| `model` | string | ✅ | DeepSeek native models + common aliases (`gpt-5.5`, `gpt-5.4-mini`, `gpt-5.3-codex`, `o3`, `claude-opus-4-6`, `claude-sonnet-4-6`, etc.); `gemini-*` models (`gemini-2.5-pro`, `gemini-3-pro-preview`, ...) are forwarded to the embedded agy2api; `-nothinking` on DeepSeek models forces thinking / reasoning off |
|
| 319 |
| `messages` | array | ✅ | OpenAI-style messages |
|
| 320 |
| `stream` | boolean | ❌ | Default `false` |
|
| 321 |
| `tools` | array | ❌ | Function calling schema |
|
API.md
CHANGED
|
@@ -123,10 +123,14 @@ Gemini 兼容客户端还可以使用 `x-goog-api-key`、`?key=` 或 `?api_key=`
|
|
| 123 |
| POST | `/messages` | 业务 | Claude 消息快捷路径 |
|
| 124 |
| POST | `/v1/messages/count_tokens` | 业务 | Claude token 计数快捷路径 |
|
| 125 |
| POST | `/messages/count_tokens` | 业务 | Claude token 计数快捷路径 |
|
|
|
|
|
|
|
| 126 |
| POST | `/v1beta/models/{model}:generateContent` | 业务 | Gemini 非流式 |
|
| 127 |
| POST | `/v1beta/models/{model}:streamGenerateContent` | 业务 | Gemini 流式 |
|
| 128 |
| POST | `/v1/models/{model}:generateContent` | 业务 | Gemini 非流式兼容路径 |
|
| 129 |
| POST | `/v1/models/{model}:streamGenerateContent` | 业务 | Gemini 流式兼容路径 |
|
|
|
|
|
|
|
| 130 |
| GET | `/api/version` | 无 | Ollama 版本接口 |
|
| 131 |
| GET | `/api/tags` | 无 | Ollama 模型列表 |
|
| 132 |
| POST | `/api/show` | 无 | Ollama 单模型能力查询(返回 `id` 与 `capabilities`) |
|
|
@@ -204,7 +208,7 @@ OpenAI `/v1/*` 仍是规范路径。对于只配置 DS2API 根地址的客户端
|
|
| 204 |
|
| 205 |
### `GET /v1/models`
|
| 206 |
|
| 207 |
-
无需鉴权。返回当前支持的 DeepSeek 原生模型列表。
|
| 208 |
|
| 209 |
**响应示例**:
|
| 210 |
|
|
@@ -215,11 +219,17 @@ OpenAI `/v1/*` 仍是规范路径。对于只配置 DS2API 根地址的客户端
|
|
| 215 |
{"id": "deepseek-v4-flash", "object": "model", "created": 1677610602, "owned_by": "deepseek", "permission": []},
|
| 216 |
{"id": "deepseek-v4-flash-nothinking", "object": "model", "created": 1677610602, "owned_by": "deepseek", "permission": []},
|
| 217 |
{"id": "deepseek-v4-flash-search", "object": "model", "created": 1677610602, "owned_by": "deepseek", "permission": []},
|
| 218 |
-
{"id": "deepseek-v4-flash-search-nothinking", "object": "model", "created": 1677610602, "owned_by": "deepseek", "permission": []}
|
|
|
|
|
|
|
| 219 |
]
|
| 220 |
}
|
| 221 |
```
|
| 222 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
> 说明:`/v1/models` 返回的是规范化后的 DeepSeek 原生模型 ID;常见 alias 仅用于请求入参解析,不会在该接口中单独展开返回。带 `-nothinking` 后缀的模型表示无论请求里是否显式开启 thinking / reasoning,都会强制关闭思考输出。
|
| 224 |
>
|
| 225 |
> 模型系列已收敛到上表 4 个 flash 变体:`deepseek-v4-pro` / `deepseek-v4-pro-search` / `deepseek-v4-vision` 及其 `-nothinking` 形式已下线,不再出现在本接口、Ollama `/api/tags` 与 `/anthropic/v1/models` 中,但旧名字仍可被请求,解析时静默映射到 flash 对应项(见下一节)。
|
|
@@ -228,6 +238,7 @@ OpenAI `/v1/*` 仍是规范路径。对于只配置 DS2API 根地址的客户端
|
|
| 228 |
|
| 229 |
对 `chat` / `responses` / `embeddings` 的 `model` 字段采用“宽进严出”:
|
| 230 |
|
|
|
|
| 231 |
1. 先匹配 DeepSeek 原生模型。
|
| 232 |
2. 再匹配 `model_aliases` 精确映射。
|
| 233 |
3. 如果请求名以 `-nothinking` 结尾,则在最终解析出的规范模型上追加对应的无思考变体。
|
|
@@ -238,7 +249,7 @@ OpenAI `/v1/*` 仍是规范路径。对于只配置 DS2API 根地址的客户端
|
|
| 238 |
- OpenAI / Codex:`gpt-4o`、`gpt-4.1`、`gpt-5`、`gpt-5.5`、`gpt-5-codex`、`gpt-5.3-codex`、`codex-mini-latest` → `deepseek-v4-flash`
|
| 239 |
- OpenAI reasoning:`o1`、`o3`、`o4-mini` → `deepseek-v4-flash`;`o3-deep-research`、`o4-mini-deep-research` → `deepseek-v4-flash-search`
|
| 240 |
- Claude:`claude-opus-4-6`、`claude-sonnet-4-6`、`claude-haiku-4-5`、`claude-3-5-sonnet-latest` → `deepseek-v4-flash`
|
| 241 |
-
- Gemini:`gemini-2.5-pro`、`gemini-2.5-flash`、`gemini-3.1-pro`、`gemini-3-pro`、`gemini-3-flash`、`gemini-3.1-flash-lite`、`gemini-pro-vision` → `deepseek-v4-flash`
|
| 242 |
- 其他内置精确 alias:`llama-3.1-70b-instruct`、`qwen-max` → `deepseek-v4-flash`
|
| 243 |
|
| 244 |
上述 alias 若在请求名后追加 `-nothinking` 后缀,也会映射到对应的强制关闭 thinking 版本。
|
|
@@ -304,7 +315,7 @@ Content-Type: application/json
|
|
| 304 |
|
| 305 |
| 字段 | 类型 | 必填 | 说明 |
|
| 306 |
| --- | --- | --- | --- |
|
| 307 |
-
| `model` | string | ✅ | 支持 DeepSeek 原生模型 + 常见 alias(如 `gpt-5.5`、`gpt-5.4-mini`、`gpt-5.3-codex`、`o3`、`claude-opus-4-6`、`claude-sonnet-4-6`
|
| 308 |
| `messages` | array | ✅ | OpenAI 风格消息数组 |
|
| 309 |
| `stream` | boolean | ❌ | 默认 `false` |
|
| 310 |
| `tools` | array | ❌ | Function Calling 定义 |
|
|
|
|
| 123 |
| POST | `/messages` | 业务 | Claude 消息快捷路径 |
|
| 124 |
| POST | `/v1/messages/count_tokens` | 业务 | Claude token 计数快捷路径 |
|
| 125 |
| POST | `/messages/count_tokens` | 业务 | Claude token 计数快捷路径 |
|
| 126 |
+
| GET | `/v1beta/models` | 无 | Gemini 模型列表(静态清单 + agy2api 动态发现) |
|
| 127 |
+
| GET | `/v1beta/models/{model}` | 无 | Gemini 单模型查询 |
|
| 128 |
| POST | `/v1beta/models/{model}:generateContent` | 业务 | Gemini 非流式 |
|
| 129 |
| POST | `/v1beta/models/{model}:streamGenerateContent` | 业务 | Gemini 流式 |
|
| 130 |
| POST | `/v1/models/{model}:generateContent` | 业务 | Gemini 非流式兼容路径 |
|
| 131 |
| POST | `/v1/models/{model}:streamGenerateContent` | 业务 | Gemini 流式兼容路径 |
|
| 132 |
+
| GET | `/agy/` | AGY 面板密码 | 内嵌 agy2api 独立面板(Antigravity OAuth / 凭证管理) |
|
| 133 |
+
| ANY | `/agy/*` | AGY 面板密码 / API 密码 | agy2api 原生 OpenAI / Gemini / Claude 接口 |
|
| 134 |
| GET | `/api/version` | 无 | Ollama 版本接口 |
|
| 135 |
| GET | `/api/tags` | 无 | Ollama 模型列表 |
|
| 136 |
| POST | `/api/show` | 无 | Ollama 单模型能力查询(返回 `id` 与 `capabilities`) |
|
|
|
|
| 208 |
|
| 209 |
### `GET /v1/models`
|
| 210 |
|
| 211 |
+
无需鉴权。返回当前支持的 DeepSeek 原生模型与内嵌 agy2api 的 Gemini 模型列表。
|
| 212 |
|
| 213 |
**响应示例**:
|
| 214 |
|
|
|
|
| 219 |
{"id": "deepseek-v4-flash", "object": "model", "created": 1677610602, "owned_by": "deepseek", "permission": []},
|
| 220 |
{"id": "deepseek-v4-flash-nothinking", "object": "model", "created": 1677610602, "owned_by": "deepseek", "permission": []},
|
| 221 |
{"id": "deepseek-v4-flash-search", "object": "model", "created": 1677610602, "owned_by": "deepseek", "permission": []},
|
| 222 |
+
{"id": "deepseek-v4-flash-search-nothinking", "object": "model", "created": 1677610602, "owned_by": "deepseek", "permission": []},
|
| 223 |
+
{"id": "gemini-2.5-pro", "object": "model", "created": 1715635200, "owned_by": "google", "permission": []},
|
| 224 |
+
{"id": "gemini-3-pro-preview", "object": "model", "created": 1715635200, "owned_by": "google", "permission": []}
|
| 225 |
]
|
| 226 |
}
|
| 227 |
```
|
| 228 |
|
| 229 |
+
Gemini 模型固定包含:`gemini-2.5-flash`、`gemini-2.5-pro`、`gemini-2.5-pro-high`、`gemini-2.5-pro-low`、`gemini-2.5-pro-search`、`gemini-3-flash-preview`、`gemini-3-pro-preview`、`gemini-3.1-pro-preview`、`gemini-3.1-flash-image`。这些模型由内嵌 agy2api 承接,独立面板位于 `/agy/`。
|
| 230 |
+
|
| 231 |
+
当 agy2api 已配置 Antigravity 凭证时,列表还会合并其 `/v1/models` 动态返回的 Gemini 模型(含上游新增型号与 `抗截断-` 变体),结果缓存 60 秒;旁车不可用时自动回退到上述静态清单。
|
| 232 |
+
|
| 233 |
> 说明:`/v1/models` 返回的是规范化后的 DeepSeek 原生模型 ID;常见 alias 仅用于请求入参解析,不会在该接口中单独展开返回。带 `-nothinking` 后缀的模型表示无论请求里是否显式开启 thinking / reasoning,都会强制关闭思考输出。
|
| 234 |
>
|
| 235 |
> 模型系列已收敛到上表 4 个 flash 变体:`deepseek-v4-pro` / `deepseek-v4-pro-search` / `deepseek-v4-vision` 及其 `-nothinking` 形式已下线,不再出现在本接口、Ollama `/api/tags` 与 `/anthropic/v1/models` 中,但旧名字仍可被请求,解析时静默映射到 flash 对应项(见下一节)。
|
|
|
|
| 238 |
|
| 239 |
对 `chat` / `responses` / `embeddings` 的 `model` 字段采用“宽进严出”:
|
| 240 |
|
| 241 |
+
0. 若模型名(去掉 `抗截断-` 前缀后)以 `gemini-` 开头,`/v1/chat/completions`、`/v1/messages`、Gemini 原生接口会直接转发给内嵌 agy2api,不进入下述 DeepSeek 解析链。
|
| 242 |
1. 先匹配 DeepSeek 原生模型。
|
| 243 |
2. 再匹配 `model_aliases` 精确映射。
|
| 244 |
3. 如果请求名以 `-nothinking` 结尾,则在最终解析出的规范模型上追加对应的无思考变体。
|
|
|
|
| 249 |
- OpenAI / Codex:`gpt-4o`、`gpt-4.1`、`gpt-5`、`gpt-5.5`、`gpt-5-codex`、`gpt-5.3-codex`、`codex-mini-latest` → `deepseek-v4-flash`
|
| 250 |
- OpenAI reasoning:`o1`、`o3`、`o4-mini` → `deepseek-v4-flash`;`o3-deep-research`、`o4-mini-deep-research` → `deepseek-v4-flash-search`
|
| 251 |
- Claude:`claude-opus-4-6`、`claude-sonnet-4-6`、`claude-haiku-4-5`、`claude-3-5-sonnet-latest` → `deepseek-v4-flash`
|
| 252 |
+
- Gemini(仅未分流到 agy2api 的接口,例如 `/v1/responses`):`gemini-2.5-pro`、`gemini-2.5-flash`、`gemini-3.1-pro`、`gemini-3-pro`、`gemini-3-flash`、`gemini-3.1-flash-lite`、`gemini-pro-vision` → `deepseek-v4-flash`
|
| 253 |
- 其他内置精确 alias:`llama-3.1-70b-instruct`、`qwen-max` → `deepseek-v4-flash`
|
| 254 |
|
| 255 |
上述 alias 若在请求名后追加 `-nothinking` 后缀,也会映射到对应的强制关闭 thinking 版本。
|
|
|
|
| 315 |
|
| 316 |
| 字段 | 类型 | 必填 | 说明 |
|
| 317 |
| --- | --- | --- | --- |
|
| 318 |
+
| `model` | string | ✅ | 支持 DeepSeek 原生模型 + 常见 alias(如 `gpt-5.5`、`gpt-5.4-mini`、`gpt-5.3-codex`、`o3`、`claude-opus-4-6`、`claude-sonnet-4-6` 等);`gemini-*` 模型(如 `gemini-2.5-pro`、`gemini-3-pro-preview`)会转发给内嵌 agy2api;DeepSeek 模型名带 `-nothinking` 后缀时强制关闭 thinking / reasoning |
|
| 319 |
| `messages` | array | ✅ | OpenAI 风格消息数组 |
|
| 320 |
| `stream` | boolean | ❌ | 默认 `false` |
|
| 321 |
| `tools` | array | ❌ | Function Calling 定义 |
|
Dockerfile
CHANGED
|
@@ -24,18 +24,29 @@ RUN set -eux; \
|
|
| 24 |
|
| 25 |
FROM busybox:1.36.1-musl AS busybox-tools
|
| 26 |
|
| 27 |
-
FROM
|
| 28 |
WORKDIR /app
|
| 29 |
RUN apt-get update \
|
| 30 |
&& apt-get install -y --no-install-recommends ca-certificates gosu \
|
| 31 |
&& groupadd -r ds2api && useradd -r -g ds2api -d /app -s /sbin/nologin ds2api \
|
| 32 |
-
&& mkdir -p /app/data /data
|
|
|
|
| 33 |
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
COPY --from=busybox-tools /bin/busybox /usr/local/bin/busybox
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
EXPOSE 7860
|
| 36 |
ENV PORT=7860
|
| 37 |
ENV DS2API_CONFIG_PATH=/data/config.json
|
| 38 |
ENV DS2API_CHAT_HISTORY_PATH=/data/chat_history.json
|
|
|
|
| 39 |
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
| 40 |
RUN chmod +x /usr/local/bin/entrypoint.sh
|
| 41 |
CMD ["/usr/local/bin/entrypoint.sh"]
|
|
|
|
| 24 |
|
| 25 |
FROM busybox:1.36.1-musl AS busybox-tools
|
| 26 |
|
| 27 |
+
FROM python:3.13-slim AS runtime-base
|
| 28 |
WORKDIR /app
|
| 29 |
RUN apt-get update \
|
| 30 |
&& apt-get install -y --no-install-recommends ca-certificates gosu \
|
| 31 |
&& groupadd -r ds2api && useradd -r -g ds2api -d /app -s /sbin/nologin ds2api \
|
| 32 |
+
&& mkdir -p /app/data /data /data/agy2api/creds /data/agy2api/data \
|
| 33 |
+
&& chown -R ds2api:ds2api /app /data \
|
| 34 |
&& rm -rf /var/lib/apt/lists/*
|
| 35 |
+
# 内嵌 agy2api 的 Python 依赖(复用 requirements.txt 提升层缓存命中率)
|
| 36 |
+
COPY agy2api/requirements.txt /tmp/agy2api-requirements.txt
|
| 37 |
+
RUN pip install --no-cache-dir -r /tmp/agy2api-requirements.txt \
|
| 38 |
+
&& rm -f /tmp/agy2api-requirements.txt
|
| 39 |
COPY --from=busybox-tools /bin/busybox /usr/local/bin/busybox
|
| 40 |
+
# 内嵌 agy2api(已含编译好的前端 dist),data/creds 指向持久化目录。
|
| 41 |
+
COPY --chown=ds2api:ds2api agy2api /app/agy2api
|
| 42 |
+
RUN rm -rf /app/agy2api/data /app/agy2api/creds \
|
| 43 |
+
&& ln -s /data/agy2api/data /app/agy2api/data \
|
| 44 |
+
&& ln -s /data/agy2api/creds /app/agy2api/creds
|
| 45 |
EXPOSE 7860
|
| 46 |
ENV PORT=7860
|
| 47 |
ENV DS2API_CONFIG_PATH=/data/config.json
|
| 48 |
ENV DS2API_CHAT_HISTORY_PATH=/data/chat_history.json
|
| 49 |
+
ENV AGY2API_BASE_URL=http://127.0.0.1:7861
|
| 50 |
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
| 51 |
RUN chmod +x /usr/local/bin/entrypoint.sh
|
| 52 |
CMD ["/usr/local/bin/entrypoint.sh"]
|
README.en.md
CHANGED
|
@@ -139,6 +139,7 @@ For the full module-by-module architecture and directory responsibilities, see [
|
|
| 139 |
| Tool Calling | **Off by default** (`tools.enabled`); when enabled: anti-leak handling, non-code-block feature match, early `delta.tool_calls`, structured incremental output |
|
| 140 |
| Admin API | Config management, runtime settings hot-reload, proxy management, account testing/batch test, session cleanup, import/export, Vercel sync, version check |
|
| 141 |
| WebUI Admin Panel | SPA at `/admin` (bilingual Chinese/English, dark mode, with server-side conversation history) |
|
|
|
|
| 142 |
| Health Probes | `GET /healthz` (liveness), `GET /readyz` (readiness) |
|
| 143 |
|
| 144 |
OpenAI `/v1/*` routes remain canonical, and DS2API also accepts root shortcuts such as `/models`, `/chat/completions`, `/responses`, `/embeddings`, `/files`, and `/files/{file_id}` for clients configured with the bare service URL.
|
|
@@ -176,7 +177,23 @@ Upstream has merged the former pro / vision lanes into flash, so `/v1/models`, O
|
|
| 176 |
|
| 177 |
The upstream `model_type` is now only `default`; there is no separate expert or vision lane.
|
| 178 |
|
| 179 |
-
Besides native IDs, DS2API also accepts common aliases as input (for example `gpt-4.1`, `gpt-5`, `gpt-5-codex`, `o3`, `claude-*`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
Thinking and native search are resolved in one shared path: model default → explicit client signal (`thinking`, `reasoning`, `reasoning_effort`, `enable_search`, `web_search_options`) → `-nothinking` models always force thinking off. Full rules: [prompt compatibility doc](docs/prompt-compatibility.md) (Chinese) and [API.en.md](API.en.md).
|
| 182 |
|
|
@@ -202,7 +219,7 @@ Besides the primary aliases above, `/anthropic/v1/models` also returns Claude 4.
|
|
| 202 |
|
| 203 |
### Gemini Endpoint
|
| 204 |
|
| 205 |
-
|
| 206 |
|
| 207 |
## Quick Start
|
| 208 |
|
|
|
|
| 139 |
| Tool Calling | **Off by default** (`tools.enabled`); when enabled: anti-leak handling, non-code-block feature match, early `delta.tool_calls`, structured incremental output |
|
| 140 |
| Admin API | Config management, runtime settings hot-reload, proxy management, account testing/batch test, session cleanup, import/export, Vercel sync, version check |
|
| 141 |
| WebUI Admin Panel | SPA at `/admin` (bilingual Chinese/English, dark mode, with server-side conversation history) |
|
| 142 |
+
| Embedded AGY2API | Separate Antigravity panel at `/agy/` with OAuth, credential management and usage logs; Gemini models are proxied in the same container |
|
| 143 |
| Health Probes | `GET /healthz` (liveness), `GET /readyz` (readiness) |
|
| 144 |
|
| 145 |
OpenAI `/v1/*` routes remain canonical, and DS2API also accepts root shortcuts such as `/models`, `/chat/completions`, `/responses`, `/embeddings`, `/files`, and `/files/{file_id}` for clients configured with the bare service URL.
|
|
|
|
| 177 |
|
| 178 |
The upstream `model_type` is now only `default`; there is no separate expert or vision lane.
|
| 179 |
|
| 180 |
+
Besides native IDs, DS2API also accepts common aliases as input (for example `gpt-4.1`, `gpt-5`, `gpt-5-codex`, `o3`, `claude-*`), but `/v1/models` returns normalized DeepSeek native model IDs. All built-in aliases point at the flash models; `o3-deep-research` and `o4-mini-deep-research` point at `deepseek-v4-flash-search`. The complete alias behavior is documented in [API.en.md](API.en.md#model-alias-resolution) and `config.example.json`.
|
| 181 |
+
|
| 182 |
+
### Gemini via Embedded AGY2API
|
| 183 |
+
|
| 184 |
+
The repository vendors [agy2api](https://github.com/su-kaka/agy2api) (CNC-1.0) as a local Python sidecar. `/v1/models` now publishes:
|
| 185 |
+
|
| 186 |
+
`gemini-2.5-flash`, `gemini-2.5-pro`, `gemini-2.5-pro-high`, `gemini-2.5-pro-low`, `gemini-2.5-pro-search`, `gemini-3-flash-preview`, `gemini-3-pro-preview`, `gemini-3.1-pro-preview`, `gemini-3.1-flash-image`.
|
| 187 |
+
|
| 188 |
+
Any OpenAI/Claude/Gemini-native request whose model starts with `gemini-` (including the `抗截断-` prefix variant) is forwarded to agy2api before the DeepSeek alias chain. The proxy validates your DS2API API key (`Authorization`, `x-api-key`, `x-goog-api-key` or `?key=`) and injects the sidecar password upstream.
|
| 189 |
+
|
| 190 |
+
- Separate panel: `/agy/` (the DS2API panel remains at `/admin`)
|
| 191 |
+
- Sidecar data: `/data/agy2api/`
|
| 192 |
+
- `AGY2API_BASE_URL` (default `http://127.0.0.1:7861`, set `off` to disable)
|
| 193 |
+
- `AGY2API_API_PASSWORD` (default: `DS2API_ADMIN_KEY`, then `pwd`)
|
| 194 |
+
- `AGY2API_PANEL_PASSWORD` (default: same as API password)
|
| 195 |
+
|
| 196 |
+
Interfaces agy2api does not implement (for example `/v1/responses`) keep the legacy DeepSeek alias behavior.
|
| 197 |
|
| 198 |
Thinking and native search are resolved in one shared path: model default → explicit client signal (`thinking`, `reasoning`, `reasoning_effort`, `enable_search`, `web_search_options`) → `-nothinking` models always force thinking off. Full rules: [prompt compatibility doc](docs/prompt-compatibility.md) (Chinese) and [API.en.md](API.en.md).
|
| 199 |
|
|
|
|
| 219 |
|
| 220 |
### Gemini Endpoint
|
| 221 |
|
| 222 |
+
Gemini-native requests for `gemini-*` models are forwarded to the embedded agy2api sidecar, supporting `generateContent`, `streamGenerateContent` and `countTokens` with Antigravity thinking/image variants. Requests for DeepSeek model names (or legacy aliases) still use the native adapter, which maps names via `model_aliases`/built-in aliases and keeps full Tool Calling support (`functionDeclarations` → `functionCall`). If a DeepSeek model name has a `-nothinking` suffix, such as `deepseek-v4-flash-nothinking`, it forces thinking off.
|
| 223 |
|
| 224 |
## Quick Start
|
| 225 |
|
README.md
CHANGED
|
@@ -9,12 +9,44 @@ pinned: false
|
|
| 9 |
|
| 10 |
# DS2API - DeepSeek to OpenAI API Adapter
|
| 11 |
|
| 12 |
-
DeepSeek web chat to OpenAI-compatible API adapter with multi-protocol support (OpenAI, Claude, Gemini).
|
| 13 |
|
| 14 |
## Quick Start
|
| 15 |
|
| 16 |
-
1. Visit /admin to configure your DeepSeek accounts and API keys
|
| 17 |
-
2.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
## Documentation
|
| 20 |
|
|
|
|
| 9 |
|
| 10 |
# DS2API - DeepSeek to OpenAI API Adapter
|
| 11 |
|
| 12 |
+
DeepSeek web chat to OpenAI-compatible API adapter with multi-protocol support (OpenAI, Claude, Gemini), plus an embedded [agy2api](https://github.com/su-kaka/agy2api) sidecar for Google Antigravity / Gemini models.
|
| 13 |
|
| 14 |
## Quick Start
|
| 15 |
|
| 16 |
+
1. Visit `/admin` to configure your DeepSeek accounts and API keys
|
| 17 |
+
2. Visit `/agy/` to complete Antigravity OAuth and manage Gemini credentials (separate panel)
|
| 18 |
+
3. Use the OpenAI-compatible API at `/v1/chat/completions`; requests whose `model` starts with `gemini-` are routed to agy2api automatically
|
| 19 |
+
|
| 20 |
+
### Local development (Go + Python sidecar)
|
| 21 |
+
|
| 22 |
+
```bash
|
| 23 |
+
./scripts/dev-agy.sh # terminal 1: agy2api on 127.0.0.1:7861
|
| 24 |
+
go run ./cmd/ds2api # terminal 2: DS2API on :5001
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
`dev-agy.sh` creates `agy2api/.venv`, installs `agy2api/requirements.txt`, and honors `AGY2API_API_PASSWORD`, `AGY2API_PANEL_PASSWORD` and `DS2API_ADMIN_KEY`. Set `AGY2API_BASE_URL=off` to disable the sidecar integration.
|
| 28 |
+
|
| 29 |
+
## Embedded AGY2API (Gemini / Antigravity)
|
| 30 |
+
|
| 31 |
+
The repository vendors agy2api (CNC-1.0) under `agy2api/` and runs it as a local Python sidecar inside the same container:
|
| 32 |
+
|
| 33 |
+
- Separate panel: `/agy/` (Antigravity OAuth, credentials, usage logs). The original DS2API panel stays at `/admin`.
|
| 34 |
+
- OpenAI-compatible: `/v1/chat/completions` (and `/chat/completions`) with a `gemini-*` model.
|
| 35 |
+
- Claude-compatible: `/v1/messages` with a `gemini-*` model.
|
| 36 |
+
- Gemini native: `/v1beta/models/{model}:generateContent`, `:streamGenerateContent`, `:countTokens` (and the `/v1/models/...` aliases).
|
| 37 |
+
- Model list: `/v1/models` publishes the static Gemini catalog (`gemini-2.5-flash`, `gemini-2.5-pro` with `-high` / `-low` / `-search`, `gemini-3-flash-preview`, `gemini-3-pro-preview`, `gemini-3.1-pro-preview`, `gemini-3.1-flash-image`) and merges agy2api's live model list with a 60s cache and static fallback. Gemini-native `GET /v1beta/models` and `GET /v1beta/models/{model}` are also available.
|
| 38 |
+
- Authentication: the same DS2API API keys work (`Authorization: Bearer`, `x-api-key`, `x-goog-api-key`, or `?key=`). The proxy validates the key and injects the agy2api password upstream.
|
| 39 |
+
- Data: credentials and request logs live in `/data/agy2api/`.
|
| 40 |
+
|
| 41 |
+
Environment variables:
|
| 42 |
+
|
| 43 |
+
| Variable | Default | Description |
|
| 44 |
+
| --- | --- | --- |
|
| 45 |
+
| `AGY2API_BASE_URL` | `http://127.0.0.1:7861` | Sidecar address; set `off` to disable routing |
|
| 46 |
+
| `AGY2API_API_PASSWORD` | `DS2API_ADMIN_KEY`, then `pwd` | API password used between DS2API and agy2api |
|
| 47 |
+
| `AGY2API_PANEL_PASSWORD` | same as API password | Login password for the `/agy/` panel |
|
| 48 |
+
|
| 49 |
+
> Gemini models are dispatched before the DeepSeek alias chain, so they no longer fall back to DeepSeek. Interfaces that agy2api does not implement (for example `/v1/responses`) keep the old alias behavior.
|
| 50 |
|
| 51 |
## Documentation
|
| 52 |
|
agy2api/.dockerignore
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Docker ignore
|
| 2 |
+
.venv/
|
| 3 |
+
venv/
|
| 4 |
+
__pycache__/
|
| 5 |
+
*.py[cod]
|
| 6 |
+
.git/
|
| 7 |
+
.github/
|
| 8 |
+
.idea/
|
| 9 |
+
.vscode/
|
| 10 |
+
.claude/
|
| 11 |
+
.pytest_cache/
|
| 12 |
+
frontend/node_modules/
|
| 13 |
+
creds/
|
| 14 |
+
*.log
|
| 15 |
+
log.txt
|
| 16 |
+
.env
|
| 17 |
+
tests/
|
agy2api/.env.example
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ================================================================
|
| 2 |
+
# AGY2API 环境变量配置示例文件
|
| 3 |
+
# 复制此文件为 .env 并根据需要修改配置值
|
| 4 |
+
# ================================================================
|
| 5 |
+
|
| 6 |
+
# ================================================================
|
| 7 |
+
# 服务器配置
|
| 8 |
+
# ================================================================
|
| 9 |
+
|
| 10 |
+
# 服务器监听地址
|
| 11 |
+
# 默认: 0.0.0.0 (监听所有网络接口)
|
| 12 |
+
HOST=0.0.0.0
|
| 13 |
+
|
| 14 |
+
# 服务器端口
|
| 15 |
+
# 默认: 7861
|
| 16 |
+
PORT=7861
|
| 17 |
+
|
| 18 |
+
# 反代保留路径前缀时需剥掉的前缀 (如 /AGY2API)
|
| 19 |
+
# 仅在反代将 /AGY2API/xxx 原样转发到本服务时配置; 反代已剥掉前缀时留空
|
| 20 |
+
# 默认: 空 (不剥离)
|
| 21 |
+
PATH_PREFIX=
|
| 22 |
+
|
| 23 |
+
# ================================================================
|
| 24 |
+
# 密码配置 (分离密码)
|
| 25 |
+
# ================================================================
|
| 26 |
+
|
| 27 |
+
# 聊天API访问密码 (用于OpenAI/Gemini/Claude API端点认证)
|
| 28 |
+
# 默认: pwd
|
| 29 |
+
API_PASSWORD=your_api_password
|
| 30 |
+
|
| 31 |
+
# 控制面板访问密码 (用于Web界面登录认证)
|
| 32 |
+
# 默认: pwd
|
| 33 |
+
PANEL_PASSWORD=your_panel_password
|
| 34 |
+
|
| 35 |
+
# IP 白名单 (可选)
|
| 36 |
+
# 启用开关 + 逗号或换行分隔的白名单列表
|
| 37 |
+
# 每条支持: 单个IP / CIDR网段 / 起止范围(- 或 ~ 分隔), IPv4/IPv6 均可
|
| 38 |
+
# 开启后仅白名单内 IP 可访问面板和 API, 其余 IP 直接 403
|
| 39 |
+
# 默认: 关闭 (不限制)
|
| 40 |
+
IP_WHITELIST_ENABLED=false
|
| 41 |
+
IP_WHITELIST=
|
| 42 |
+
|
| 43 |
+
# 模型名复写 (可选)
|
| 44 |
+
# 启用后按规则匹配请求模型名(支持正则), 命中则替换为指定模型名
|
| 45 |
+
# 规则格式: JSON 数组 [匹配正则, 替换模型名] 的数组; 也支持 "正则->替换名" 逗号分隔
|
| 46 |
+
# 替换名支持正则反向引用 (如 \1)
|
| 47 |
+
# 默认: 关闭
|
| 48 |
+
MODEL_REWRITE_ENABLED=false
|
| 49 |
+
MODEL_REWRITE_RULES=[["^gpt-4$","gemini-2.5-pro"],["^claude-3-5-sonnet.*$","claude-sonnet-4-5"]]
|
| 50 |
+
|
| 51 |
+
# ================================================================
|
| 52 |
+
# 存储配置
|
| 53 |
+
# ================================================================
|
| 54 |
+
|
| 55 |
+
# 存储后端优先级: PostgreSQL > 本地sqlite文件存储
|
| 56 |
+
# 系统会自动选择可用的最高优先级存储后端
|
| 57 |
+
|
| 58 |
+
# PostgreSQL 分布式存储模式配置 (最高优先级)
|
| 59 |
+
# 设置 POSTGRESQL_URI 后自动启用 PostgreSQL 模式
|
| 60 |
+
# 格式: postgresql://user:password@localhost:5432/agy2api
|
| 61 |
+
# 默认: 无 (不启用 PostgreSQL 存储,使用本地SQLite)
|
| 62 |
+
POSTGRESQL_URI=
|
| 63 |
+
|
| 64 |
+
# ================================================================
|
| 65 |
+
# Google API 配置
|
| 66 |
+
# ================================================================
|
| 67 |
+
|
| 68 |
+
# 凭证文件目录 (仅在文件存储模式下使用)
|
| 69 |
+
# 默认: ./creds
|
| 70 |
+
CREDENTIALS_DIR=./creds
|
| 71 |
+
|
| 72 |
+
# 代理配置 (可选)
|
| 73 |
+
# 支持 http, https, socks5 代理
|
| 74 |
+
# 格式: http://proxy:port, https://proxy:port, socks5://proxy:port
|
| 75 |
+
PROXY=http://localhost:7890
|
| 76 |
+
|
| 77 |
+
# Google API 代理 URL 配置 (可选)
|
| 78 |
+
|
| 79 |
+
# Google OAuth2 端点
|
| 80 |
+
# 默认: https://oauth2.googleapis.com
|
| 81 |
+
OAUTH_PROXY_URL=https://oauth2.googleapis.com
|
| 82 |
+
|
| 83 |
+
# 用于Google APIs调用的代理URL
|
| 84 |
+
# 默认: https://www.googleapis.com
|
| 85 |
+
GOOGLEAPIS_PROXY_URL=https://www.googleapis.com
|
| 86 |
+
|
| 87 |
+
# 用于Google Antigravity API的URL
|
| 88 |
+
# 默认: https://daily-cloudcode-pa.googleapis.com
|
| 89 |
+
ANTIGRAVITY_API_URL=https://daily-cloudcode-pa.googleapis.com
|
| 90 |
+
|
| 91 |
+
# ================================================================
|
| 92 |
+
# 错误处理和重试配置
|
| 93 |
+
# ================================================================
|
| 94 |
+
|
| 95 |
+
# 是否启用自动封禁功能
|
| 96 |
+
# 当凭证返回特定错误码时自动禁用该凭证
|
| 97 |
+
# 默认: false
|
| 98 |
+
AUTO_BAN=false
|
| 99 |
+
|
| 100 |
+
# 自动封禁的错误码列表 (逗号分隔)
|
| 101 |
+
# 默认: 403
|
| 102 |
+
AUTO_BAN_ERROR_CODES=403
|
| 103 |
+
|
| 104 |
+
# 是否启用 429 错误重试
|
| 105 |
+
# 默认: true
|
| 106 |
+
RETRY_429_ENABLED=true
|
| 107 |
+
|
| 108 |
+
# 429 错误最大重试次数
|
| 109 |
+
# 默认: 5
|
| 110 |
+
RETRY_429_MAX_RETRIES=5
|
| 111 |
+
|
| 112 |
+
# 429 错误重试间隔 (秒)
|
| 113 |
+
# 默认: 1
|
| 114 |
+
RETRY_429_INTERVAL=1
|
| 115 |
+
|
| 116 |
+
# ================================================================
|
| 117 |
+
# 日志配置
|
| 118 |
+
# ================================================================
|
| 119 |
+
|
| 120 |
+
# 日志级别
|
| 121 |
+
# 可选值: debug, info, warning, error, critical
|
| 122 |
+
# 默认: info
|
| 123 |
+
LOG_LEVEL=info
|
| 124 |
+
|
| 125 |
+
# 完全静默:不打印任何日志到控制台输出
|
| 126 |
+
# 默认: 1(打印日志)
|
| 127 |
+
ENABLE_LOG=1
|
| 128 |
+
|
| 129 |
+
# ================================================================
|
| 130 |
+
# 高级功能配置
|
| 131 |
+
# ================================================================
|
| 132 |
+
|
| 133 |
+
# 抗截断最大尝试次数
|
| 134 |
+
# 用于 "抗截断-" 前缀的模型
|
| 135 |
+
# 默认: 3
|
| 136 |
+
ANTI_TRUNCATION_MAX_ATTEMPTS=3
|
| 137 |
+
|
| 138 |
+
# ================================================================
|
| 139 |
+
# 环境变量使用说明
|
| 140 |
+
# ================================================================
|
| 141 |
+
|
| 142 |
+
# 1. 存储模式配置 (按优先级自动选择):
|
| 143 |
+
# - PostgreSQL 分布式模式 (最高优先级): 设置 POSTGRESQL_URI,数据存储在 PostgreSQL 数据库
|
| 144 |
+
# - SQLite 本地模式 (默认): 不设置上述 URI,数据存储在本地 creds/credentials.db
|
| 145 |
+
|
| 146 |
+
# 2. 密码配置:
|
| 147 |
+
# API_PASSWORD(聊天API)与 PANEL_PASSWORD(控制面板)独立设置,默认均为 pwd
|
| 148 |
+
|
| 149 |
+
# 3. 通用配置优先级:
|
| 150 |
+
# 环境变量 > 默认值
|
| 151 |
+
|
| 152 |
+
# 4. 布尔值环境变量:
|
| 153 |
+
# true/1/yes/on 表示启用
|
| 154 |
+
# false/0/no/off 表示禁用
|
agy2api/.gitignore
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Credential files - should never be committed
|
| 2 |
+
*.json
|
| 3 |
+
!package.json
|
| 4 |
+
!package-lock.json
|
| 5 |
+
!tsconfig.json
|
| 6 |
+
*.toml
|
| 7 |
+
!pyproject.toml
|
| 8 |
+
creds/
|
| 9 |
+
data/
|
| 10 |
+
CLAUDE.md
|
| 11 |
+
GEMINI.md
|
| 12 |
+
.kiro
|
| 13 |
+
# Environment configuration
|
| 14 |
+
.env
|
| 15 |
+
|
| 16 |
+
# Python
|
| 17 |
+
uv.lock
|
| 18 |
+
.python-version
|
| 19 |
+
__pycache__/
|
| 20 |
+
*.py[cod]
|
| 21 |
+
*$py.class
|
| 22 |
+
*.so
|
| 23 |
+
.Python
|
| 24 |
+
build/
|
| 25 |
+
develop-eggs/
|
| 26 |
+
!dist/
|
| 27 |
+
!dist/**
|
| 28 |
+
downloads/
|
| 29 |
+
eggs/
|
| 30 |
+
.eggs/
|
| 31 |
+
lib/
|
| 32 |
+
lib64/
|
| 33 |
+
parts/
|
| 34 |
+
sdist/
|
| 35 |
+
var/
|
| 36 |
+
wheels/
|
| 37 |
+
pip-wheel-metadata/
|
| 38 |
+
share/python-wheels/
|
| 39 |
+
*.egg-info/
|
| 40 |
+
.installed.cfg
|
| 41 |
+
*.egg
|
| 42 |
+
MANIFEST
|
| 43 |
+
|
| 44 |
+
# Node (frontend)
|
| 45 |
+
frontend/node_modules/
|
| 46 |
+
|
| 47 |
+
# PyInstaller
|
| 48 |
+
*.manifest
|
| 49 |
+
*.spec
|
| 50 |
+
|
| 51 |
+
# Installer logs
|
| 52 |
+
pip-log.txt
|
| 53 |
+
pip-delete-this-directory.txt
|
| 54 |
+
|
| 55 |
+
# Unit test / coverage reports
|
| 56 |
+
htmlcov/
|
| 57 |
+
.tox/
|
| 58 |
+
.nox/
|
| 59 |
+
.coverage
|
| 60 |
+
.coverage.*
|
| 61 |
+
.cache
|
| 62 |
+
nosetests.xml
|
| 63 |
+
coverage.xml
|
| 64 |
+
*.cover
|
| 65 |
+
*.py,cover
|
| 66 |
+
.hypothesis/
|
| 67 |
+
.pytest_cache/
|
| 68 |
+
|
| 69 |
+
# Virtual environments
|
| 70 |
+
.env
|
| 71 |
+
.venv
|
| 72 |
+
env/
|
| 73 |
+
venv/
|
| 74 |
+
ENV/
|
| 75 |
+
env.bak/
|
| 76 |
+
venv.bak/
|
| 77 |
+
|
| 78 |
+
# IDE
|
| 79 |
+
.vscode/
|
| 80 |
+
.idea/
|
| 81 |
+
.claude/
|
| 82 |
+
*.swp
|
| 83 |
+
*.swo
|
| 84 |
+
*~
|
| 85 |
+
|
| 86 |
+
# OS
|
| 87 |
+
.DS_Store
|
| 88 |
+
.DS_Store?
|
| 89 |
+
._*
|
| 90 |
+
.Spotlight-V100
|
| 91 |
+
.Trashes
|
| 92 |
+
ehthumbs.db
|
| 93 |
+
Thumbs.db
|
| 94 |
+
|
| 95 |
+
# Logs
|
| 96 |
+
*.log
|
| 97 |
+
log.txt
|
| 98 |
+
|
| 99 |
+
# Temporary files
|
| 100 |
+
*.tmp
|
| 101 |
+
*.temp
|
| 102 |
+
*.bak
|
| 103 |
+
|
| 104 |
+
tools/
|
| 105 |
+
aicode/
|
| 106 |
+
streamchat/
|
agy2api/AGENTS.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AGENTS.md
|
| 2 |
+
|
| 3 |
+
本仓库使用 `uv` 管理依赖(`pyproject.toml` / `uv.lock`)。
|
| 4 |
+
|
| 5 |
+
## Python 环境(重要)
|
| 6 |
+
|
| 7 |
+
**在执行任何 Python 相关命令(运行、测试、安装依赖等)时,请始终使用 backend 目录下的虚拟环境解释器:**
|
| 8 |
+
|
| 9 |
+
```bash
|
| 10 |
+
.venv\Scripts\python.exe
|
| 11 |
+
```
|
| 12 |
+
|
| 13 |
+
例如:
|
| 14 |
+
|
| 15 |
+
```bash
|
| 16 |
+
# 运行后端
|
| 17 |
+
.venv\Scripts\python.exe web.py
|
| 18 |
+
|
| 19 |
+
# 安装依赖(优先使用 uv)
|
| 20 |
+
.venv\Scripts\python.exe -m pip install -r requirements.txt
|
| 21 |
+
|
| 22 |
+
# 查看已安装的包
|
| 23 |
+
.venv\Scripts\python.exe -m pip list
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
不要使用系统全局的 `python` / `python3`,也不要自行新建虚拟环境。
|
| 27 |
+
|
| 28 |
+
## 前端构建
|
| 29 |
+
|
| 30 |
+
前端位于 `frontend/` 目录,使用 `pnpm` 作为包管理器:
|
| 31 |
+
|
| 32 |
+
```bash
|
| 33 |
+
cd frontend
|
| 34 |
+
pnpm install
|
| 35 |
+
pnpm build
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
不要使用 `npm` / `yarn` 或创建 `package-lock.json` / `yarn.lock`。
|
| 39 |
+
|
| 40 |
+
## 依赖导入规范
|
| 41 |
+
|
| 42 |
+
**所有依赖导入(`import` / `from ... import ...`)必须统一放在文件顶部(module docstring、`__future__` 导入和 `__all__` 之后)。**
|
| 43 |
+
|
| 44 |
+
唯一的例外:**存在循环依赖时**,可以在函数/方法内部延迟导入,并在导入语句旁注释说明原因,例如:
|
| 45 |
+
|
| 46 |
+
```python
|
| 47 |
+
def some_func():
|
| 48 |
+
# 循环依赖,延迟导入
|
| 49 |
+
from src.auth import verify_token
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
除上述例外,禁止在函数内部、条件分支中随意散落导入语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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Contributing to agy2api
|
| 2 |
+
|
| 3 |
+
First off, thank you for considering contributing to agy2api! It's people like you that make agy2api such a great tool.
|
| 4 |
+
|
| 5 |
+
## Code of Conduct
|
| 6 |
+
|
| 7 |
+
This project is intended for personal learning and research purposes only. By participating, you are expected to uphold this code and respect the CNC-1.0 license restrictions on commercial use.
|
| 8 |
+
|
| 9 |
+
## How Can I Contribute?
|
| 10 |
+
|
| 11 |
+
### Reporting Bugs
|
| 12 |
+
|
| 13 |
+
Before creating bug reports, please check the existing issues to avoid duplicates. When you create a bug report, include as many details as possible:
|
| 14 |
+
|
| 15 |
+
* **Use a clear and descriptive title**
|
| 16 |
+
* **Describe the exact steps to reproduce the problem**
|
| 17 |
+
* **Provide specific examples** - Include code snippets, configuration files, or log outputs
|
| 18 |
+
* **Describe the behavior you observed** and what you expected to see
|
| 19 |
+
* **Include environment details**: OS, Python version, Docker version (if applicable)
|
| 20 |
+
|
| 21 |
+
### Suggesting Enhancements
|
| 22 |
+
|
| 23 |
+
Enhancement suggestions are tracked as GitHub issues. When creating an enhancement suggestion, include:
|
| 24 |
+
|
| 25 |
+
* **Use a clear and descriptive title**
|
| 26 |
+
* **Provide a detailed description** of the suggested enhancement
|
| 27 |
+
* **Explain why this enhancement would be useful**
|
| 28 |
+
* **List any alternative solutions** you've considered
|
| 29 |
+
|
| 30 |
+
### Pull Requests
|
| 31 |
+
|
| 32 |
+
1. Fork the repo and create your branch from `master`
|
| 33 |
+
2. If you've added code that should be tested, add tests
|
| 34 |
+
3. If you've changed APIs, update the documentation
|
| 35 |
+
4. Ensure the test suite passes
|
| 36 |
+
5. Make sure your code follows the existing style
|
| 37 |
+
6. Write a clear commit message
|
| 38 |
+
|
| 39 |
+
## Development Setup
|
| 40 |
+
|
| 41 |
+
### Prerequisites
|
| 42 |
+
|
| 43 |
+
* Python 3.12 or higher
|
| 44 |
+
* pip or uv package manager
|
| 45 |
+
|
| 46 |
+
### Setting Up Your Development Environment
|
| 47 |
+
|
| 48 |
+
```bash
|
| 49 |
+
# Clone your fork
|
| 50 |
+
git clone https://github.com/YOUR_USERNAME/agy2api.git
|
| 51 |
+
cd agy2api
|
| 52 |
+
|
| 53 |
+
# Install development dependencies
|
| 54 |
+
make install-dev
|
| 55 |
+
# or
|
| 56 |
+
pip install -e ".[dev]"
|
| 57 |
+
|
| 58 |
+
# Copy environment example
|
| 59 |
+
cp .env.example .env
|
| 60 |
+
# Edit .env with your configuration
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
### Development Workflow
|
| 64 |
+
|
| 65 |
+
```bash
|
| 66 |
+
# Run tests
|
| 67 |
+
make test
|
| 68 |
+
|
| 69 |
+
# Format code
|
| 70 |
+
make format
|
| 71 |
+
|
| 72 |
+
# Run linters
|
| 73 |
+
make lint
|
| 74 |
+
|
| 75 |
+
# Run the application locally
|
| 76 |
+
make run
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
### Testing
|
| 80 |
+
|
| 81 |
+
We use pytest for testing. All new features should include appropriate tests.
|
| 82 |
+
|
| 83 |
+
```bash
|
| 84 |
+
# Run all tests
|
| 85 |
+
make test
|
| 86 |
+
|
| 87 |
+
# Run with coverage
|
| 88 |
+
make test-cov
|
| 89 |
+
|
| 90 |
+
# Run specific test file
|
| 91 |
+
python -m pytest test_tool_calling.py -v
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
### Code Style
|
| 95 |
+
|
| 96 |
+
* We use [Black](https://black.readthedocs.io/) for code formatting (line length: 100)
|
| 97 |
+
* We use [flake8](https://flake8.pycqa.org/) for linting
|
| 98 |
+
* We use [mypy](http://mypy-lang.org/) for type checking (optional, but encouraged)
|
| 99 |
+
|
| 100 |
+
```bash
|
| 101 |
+
# Format your code before committing
|
| 102 |
+
make format
|
| 103 |
+
|
| 104 |
+
# Check if code is properly formatted
|
| 105 |
+
make format-check
|
| 106 |
+
|
| 107 |
+
# Run linters
|
| 108 |
+
make lint
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
## Project Structure
|
| 112 |
+
|
| 113 |
+
```
|
| 114 |
+
agy2api/
|
| 115 |
+
├── src/ # Main source code
|
| 116 |
+
│ ├── auth.py # Authentication and OAuth
|
| 117 |
+
│ ├── credential_manager.py # Credential rotation
|
| 118 |
+
│ ├── openai_router.py # OpenAI-compatible endpoints
|
| 119 |
+
│ ├── gemini_router.py # Gemini native endpoints
|
| 120 |
+
│ ├── openai_transfer.py # Format conversion
|
| 121 |
+
│ ├── storage/ # Storage backends (Redis, MongoDB, Postgres, File)
|
| 122 |
+
│ └── ...
|
| 123 |
+
├── dist/ # Compiled frontend static files
|
| 124 |
+
├── tests/ # Test directory (to be created)
|
| 125 |
+
├── test_*.py # Test files (root level)
|
| 126 |
+
├── web.py # Main application entry point
|
| 127 |
+
├── config.py # Configuration management
|
| 128 |
+
└── requirements.txt # Production dependencies
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
## Coding Guidelines
|
| 132 |
+
|
| 133 |
+
### Python Style
|
| 134 |
+
|
| 135 |
+
* Follow PEP 8 guidelines
|
| 136 |
+
* Use type hints where appropriate
|
| 137 |
+
* Write docstrings for classes and functions
|
| 138 |
+
* Keep functions focused and concise
|
| 139 |
+
|
| 140 |
+
### Commit Messages
|
| 141 |
+
|
| 142 |
+
* Use the present tense ("Add feature" not "Added feature")
|
| 143 |
+
* Use the imperative mood ("Move cursor to..." not "Moves cursor to...")
|
| 144 |
+
* Limit the first line to 72 characters or less
|
| 145 |
+
* Reference issues and pull requests liberally after the first line
|
| 146 |
+
|
| 147 |
+
### Documentation
|
| 148 |
+
|
| 149 |
+
* Update the README.md if you change functionality
|
| 150 |
+
* Comment your code where necessary
|
| 151 |
+
* Update the .env.example if you add new configuration options
|
| 152 |
+
|
| 153 |
+
## License
|
| 154 |
+
|
| 155 |
+
By contributing to agy2api, you agree that your contributions will be licensed under the CNC-1.0 license. This is a strict anti-commercial license - see [LICENSE](LICENSE) for details.
|
| 156 |
+
|
| 157 |
+
### Important License Restrictions
|
| 158 |
+
|
| 159 |
+
* ❌ No commercial use
|
| 160 |
+
* ❌ No use by companies with revenue > $1M USD
|
| 161 |
+
* ❌ No use by VC-backed or publicly traded companies
|
| 162 |
+
* ✅ Personal learning, research, and educational use only
|
| 163 |
+
* ✅ Open source integration (must follow same license)
|
| 164 |
+
|
| 165 |
+
## Questions?
|
| 166 |
+
|
| 167 |
+
Feel free to open an issue with your question or reach out to the maintainers.
|
| 168 |
+
|
| 169 |
+
Thank you for contributing! 🎉
|
agy2api/Dockerfile
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Multi-stage build for agy2api
|
| 2 |
+
FROM python:3.13-slim as base
|
| 3 |
+
|
| 4 |
+
# Set environment variables
|
| 5 |
+
ENV PYTHONUNBUFFERED=1 \
|
| 6 |
+
PYTHONDONTWRITEBYTECODE=1 \
|
| 7 |
+
PIP_NO_CACHE_DIR=1 \
|
| 8 |
+
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
| 9 |
+
TZ=Asia/Shanghai
|
| 10 |
+
|
| 11 |
+
# Install tzdata, jemalloc and set timezone
|
| 12 |
+
# jemalloc 替代 glibc malloc,大幅减少内存碎片化
|
| 13 |
+
RUN apt-get update && \
|
| 14 |
+
apt-get install -y --no-install-recommends tzdata libjemalloc2 && \
|
| 15 |
+
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
|
| 16 |
+
echo "Asia/Shanghai" > /etc/timezone && \
|
| 17 |
+
apt-get clean && \
|
| 18 |
+
rm -rf /var/lib/apt/lists/*
|
| 19 |
+
|
| 20 |
+
# 使用 jemalloc 替代 glibc malloc
|
| 21 |
+
# jemalloc 会主动将空闲内存归还给操作系统,避免 RSS 持续增长
|
| 22 |
+
ENV LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2
|
| 23 |
+
# jemalloc 配置:启用后台线程回收、脏页衰减时间 5 秒(默认 10 秒)
|
| 24 |
+
ENV MALLOC_CONF="background_thread:true,dirty_decay_ms:5000,muzzy_decay_ms:5000"
|
| 25 |
+
|
| 26 |
+
WORKDIR /app
|
| 27 |
+
|
| 28 |
+
# Copy only requirements first for better caching
|
| 29 |
+
COPY requirements.txt .
|
| 30 |
+
|
| 31 |
+
# Install Python dependencies
|
| 32 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 33 |
+
|
| 34 |
+
# Copy application code
|
| 35 |
+
COPY . .
|
| 36 |
+
|
| 37 |
+
# Expose port
|
| 38 |
+
EXPOSE 7861
|
| 39 |
+
|
| 40 |
+
# 通过 web.py 启动,使 HOST/PORT 环境变量生效
|
| 41 |
+
CMD ["python", "web.py"]
|
agy2api/LICENSE
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Cooperative Non-Commercial License (CNC-1.0)
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2024 agy2api contributors
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person or organization
|
| 6 |
+
obtaining a copy of this software and associated documentation files (the
|
| 7 |
+
"Software"), to use, copy, modify, merge, publish, distribute, and/or
|
| 8 |
+
sublicense the Software, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
TERMS AND CONDITIONS:
|
| 11 |
+
|
| 12 |
+
1. NON-COMMERCIAL USE ONLY
|
| 13 |
+
The Software may only be used for non-commercial purposes. Commercial use
|
| 14 |
+
is strictly prohibited without explicit written permission from the
|
| 15 |
+
copyright holders.
|
| 16 |
+
|
| 17 |
+
2. DEFINITION OF COMMERCIAL USE
|
| 18 |
+
"Commercial use" includes but is not limited to:
|
| 19 |
+
a) Using the Software to provide paid services or products
|
| 20 |
+
b) Integrating the Software into commercial products or services
|
| 21 |
+
c) Using the Software in any business operation that generates revenue
|
| 22 |
+
d) Offering the Software as part of a paid subscription or service
|
| 23 |
+
e) Using the Software to compete with the original project commercially
|
| 24 |
+
|
| 25 |
+
3. COPYLEFT REQUIREMENT
|
| 26 |
+
Any derivative works, modifications, or substantial portions of the Software
|
| 27 |
+
must be licensed under the same or substantially similar terms. This ensures
|
| 28 |
+
that all derivatives remain non-commercial and freely available.
|
| 29 |
+
|
| 30 |
+
4. SOURCE CODE AVAILABILITY
|
| 31 |
+
If you distribute the Software or any derivative works, you must make the
|
| 32 |
+
complete source code available under the same license terms at no charge.
|
| 33 |
+
|
| 34 |
+
5. ATTRIBUTION REQUIREMENT
|
| 35 |
+
You must retain all copyright notices, license notices, and attribution
|
| 36 |
+
statements in all copies or substantial portions of the Software.
|
| 37 |
+
|
| 38 |
+
6. ANTI-CORPORATE CLAUSE
|
| 39 |
+
This Software may not be used by corporations with annual revenue exceeding
|
| 40 |
+
$1 million USD, venture capital backed companies, or publicly traded
|
| 41 |
+
companies without explicit written permission from the copyright holders.
|
| 42 |
+
|
| 43 |
+
7. EDUCATIONAL AND RESEARCH EXEMPTION
|
| 44 |
+
Use by educational institutions, non-profit research organizations, and
|
| 45 |
+
individual researchers for educational or research purposes is explicitly
|
| 46 |
+
permitted and encouraged.
|
| 47 |
+
|
| 48 |
+
8. MODIFICATION AND CONTRIBUTION
|
| 49 |
+
Modifications and contributions to the Software are welcomed and encouraged,
|
| 50 |
+
provided they comply with these license terms. Contributors grant the same
|
| 51 |
+
license to their contributions.
|
| 52 |
+
|
| 53 |
+
9. PATENT GRANT
|
| 54 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free patent
|
| 55 |
+
license to make, have made, use, offer to sell, sell, import, and otherwise
|
| 56 |
+
transfer the Work for non-commercial purposes only.
|
| 57 |
+
|
| 58 |
+
10. TERMINATION
|
| 59 |
+
This license automatically terminates if you violate any of its terms.
|
| 60 |
+
Upon termination, you must cease all use and distribution of the Software
|
| 61 |
+
and destroy all copies in your possession.
|
| 62 |
+
|
| 63 |
+
11. LIABILITY DISCLAIMER
|
| 64 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 65 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 66 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 67 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 68 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 69 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 70 |
+
SOFTWARE.
|
| 71 |
+
|
| 72 |
+
12. JURISDICTION
|
| 73 |
+
This license shall be governed by and construed in accordance with the laws
|
| 74 |
+
of the jurisdiction where the copyright holder resides.
|
| 75 |
+
|
| 76 |
+
SUMMARY:
|
| 77 |
+
This license allows free use, modification, and distribution of the Software
|
| 78 |
+
for non-commercial purposes only. It explicitly prohibits commercial use and
|
| 79 |
+
ensures that all derivatives remain freely available under the same terms.
|
| 80 |
+
The license promotes cooperative development while preventing commercial
|
| 81 |
+
exploitation of the community's work.
|
| 82 |
+
|
| 83 |
+
For commercial licensing inquiries, please contact the copyright holders.
|
agy2api/README.md
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AGY2API
|
| 2 |
+
|
| 3 |
+
**将 Google Antigravity 转换为 OpenAI、Gemini 和 Claude API 兼容接口**
|
| 4 |
+
|
| 5 |
+
[](https://www.python.org/downloads/)
|
| 6 |
+
[](LICENSE)
|
| 7 |
+
[](https://github.com/su-kaka/agy2api/pkgs/container/agy2api)
|
| 8 |
+
|
| 9 |
+
[English](docs/README_EN.md) | 中文 | [日本語](docs/README_JA.md)
|
| 10 |
+
|
| 11 |
+
> **⚠️ 重要变更**:GeminiCLI 端点已被谷歌抛弃,本项目已完全移除 GeminiCLI 相关代码,仅保留 Antigravity 模式。
|
| 12 |
+
|
| 13 |
+
## 安装指南
|
| 14 |
+
|
| 15 |
+
### Termux 环境
|
| 16 |
+
|
| 17 |
+
**初始安装**
|
| 18 |
+
```bash
|
| 19 |
+
curl -o termux-install.sh "https://raw.githubusercontent.com/su-kaka/agy2api/refs/heads/master/termux-install.sh" && chmod +x termux-install.sh && ./termux-install.sh
|
| 20 |
+
```
|
| 21 |
+
|
| 22 |
+
**重启服务**
|
| 23 |
+
```bash
|
| 24 |
+
cd agy2api
|
| 25 |
+
bash termux-start.sh
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
### Windows 环境
|
| 29 |
+
|
| 30 |
+
**初始安装**
|
| 31 |
+
```powershell
|
| 32 |
+
iex (iwr "https://raw.githubusercontent.com/su-kaka/agy2api/refs/heads/master/install.ps1" -UseBasicParsing).Content
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
**重启服务**
|
| 36 |
+
双击执行 `start.bat`
|
| 37 |
+
|
| 38 |
+
### Linux 环境
|
| 39 |
+
|
| 40 |
+
**初始安装**
|
| 41 |
+
```bash
|
| 42 |
+
curl -o install.sh "https://raw.githubusercontent.com/su-kaka/agy2api/refs/heads/master/install.sh" && chmod +x install.sh && ./install.sh
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
**重启服务**
|
| 46 |
+
```bash
|
| 47 |
+
cd agy2api
|
| 48 |
+
bash start.sh
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
### macOS 环境
|
| 52 |
+
|
| 53 |
+
**初始安装**
|
| 54 |
+
```bash
|
| 55 |
+
curl -o darwin-install.sh "https://raw.githubusercontent.com/su-kaka/agy2api/refs/heads/master/darwin-install.sh" && chmod +x darwin-install.sh && ./darwin-install.sh
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
**重启服务**
|
| 59 |
+
```bash
|
| 60 |
+
cd agy2api
|
| 61 |
+
bash start.sh
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
### Docker 环境
|
| 65 |
+
|
| 66 |
+
**Docker 运行命令**
|
| 67 |
+
```bash
|
| 68 |
+
docker run -d --name agy2api --network host -e API_PASSWORD=api_pwd -e PANEL_PASSWORD=panel_pwd -e PORT=7861 -v $(pwd)/data/creds:/app/creds -v $(pwd)/data/request_logs:/app/data/request_logs ghcr.io/su-kaka/agy2api:latest
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
**Docker Compose 运行命令**
|
| 72 |
+
1. 使用仓库中的 `docker-compose.yml`,或参考以下内容:
|
| 73 |
+
```yaml
|
| 74 |
+
version: '3.8'
|
| 75 |
+
|
| 76 |
+
services:
|
| 77 |
+
agy2api:
|
| 78 |
+
image: ghcr.io/su-kaka/agy2api:latest
|
| 79 |
+
container_name: agy2api
|
| 80 |
+
restart: unless-stopped
|
| 81 |
+
network_mode: host
|
| 82 |
+
environment:
|
| 83 |
+
# 密码配置(分离密码)
|
| 84 |
+
- API_PASSWORD=your_api_password
|
| 85 |
+
- PANEL_PASSWORD=your_panel_password
|
| 86 |
+
- PORT=7861
|
| 87 |
+
volumes:
|
| 88 |
+
- ./data/creds:/app/creds
|
| 89 |
+
- ./data/request_logs:/app/data/request_logs
|
| 90 |
+
```
|
| 91 |
+
2. 启动服务:
|
| 92 |
+
```bash
|
| 93 |
+
docker-compose up -d
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
## 核心功能
|
| 97 |
+
|
| 98 |
+
### 🔄 API 端点和格式支持
|
| 99 |
+
|
| 100 |
+
**Antigravity 多端点多格式支持**
|
| 101 |
+
- **OpenAI 格式端点**:`/v1/chat/completions` 和 `/v1/models`
|
| 102 |
+
- **Gemini 原生端点**:`/v1/models/{model}:generateContent` 和 `streamGenerateContent`
|
| 103 |
+
- **Claude 格式端点**:`/v1/messages`
|
| 104 |
+
- 支持所有 Antigravity 模型(Claude、Gemini 等)
|
| 105 |
+
- 自动模型名称映射和思维模式检测
|
| 106 |
+
- 多种认证方式:Bearer 头部、x-api-key、x-goog-api-key、URL 参数 key
|
| 107 |
+
|
| 108 |
+
### 📊 智能凭证管理系统
|
| 109 |
+
|
| 110 |
+
- 多个 Google OAuth 凭证自动轮换(随机负载均衡)
|
| 111 |
+
- 模型级冷却(429 错误自动设置对应模型家族的 CD:image / argon / gemini / claude+gpt 共享冷却)
|
| 112 |
+
- 自动故障检测和凭证禁用
|
| 113 |
+
- 凭证使用统计和配额/额度查询
|
| 114 |
+
- 批量操作(启用、禁用、删除)
|
| 115 |
+
- 以邮箱为唯一键,重复导入自动覆盖去重
|
| 116 |
+
- 自动获取 Google 账户邮箱地址、订阅等级(Tier)和 Project ID
|
| 117 |
+
|
| 118 |
+
### 🌊 流式传输和响应处理
|
| 119 |
+
|
| 120 |
+
- 真正的实时流式响应(SSE)
|
| 121 |
+
- 流式抗截断功能(防止回答被截断,通过"抗截断-"前缀启用)
|
| 122 |
+
- 思维链(Thinking)内容分离
|
| 123 |
+
|
| 124 |
+
### 🎛️ Web 管理控制台
|
| 125 |
+
|
| 126 |
+
基于 React + Vite + Tailwind 编译的现代化前端界面:
|
| 127 |
+
- Antigravity OAuth 认证流程(支持回调 URL 快捷方式)
|
| 128 |
+
- 凭证文件上传(JSON/ZIP)、下载、详情查看
|
| 129 |
+
- 凭证导出(规范 JSON:refresh_token/access_token/expiry/email/tier/project_id)
|
| 130 |
+
- 系统配置管理(环境变量锁定提示、热更新)
|
| 131 |
+
- 批量凭证操作和状态筛选、批量导入(缺失字段自动获取)
|
| 132 |
+
- 移动端自适应
|
| 133 |
+
|
| 134 |
+
## 支持的模型
|
| 135 |
+
|
| 136 |
+
模型列表从 Antigravity API 动态获取,支持所有 Antigravity 模型:
|
| 137 |
+
|
| 138 |
+
- **Claude 系列**:`claude-sonnet-4-5`、`claude-opus-4-5` 等
|
| 139 |
+
- **Gemini 系列**:`gemini-2.5-flash`、`gemini-3-flash-preview` 等
|
| 140 |
+
|
| 141 |
+
**特殊功能变体:**
|
| 142 |
+
- **抗截断模式**:在模型名称前添加 `抗截断-` 前缀
|
| 143 |
+
- 例:`抗截断-gemini-2.5-pro`
|
| 144 |
+
- 通过合成工具调用绕过截断限制,确保完整回答(流式和非流式均有效)
|
| 145 |
+
- **图像生成模型**支持分辨率(`-2k`、`-4k`)和比例(`-16x9`、`-9x16` 等)后缀
|
| 146 |
+
|
| 147 |
+
## 配置说明
|
| 148 |
+
|
| 149 |
+
1. 访问 `http://127.0.0.1:7861`(默认端口,可通过 PORT 环境变量修改)
|
| 150 |
+
2. 完成 Antigravity OAuth 认证流程(默认密码:`pwd`,可通过环境变量修改)
|
| 151 |
+
3. 配置客户端:
|
| 152 |
+
|
| 153 |
+
**OpenAI 兼容客户端:**
|
| 154 |
+
- **端点地址**:`http://127.0.0.1:7861/v1`
|
| 155 |
+
- **API 密钥**:`pwd`(默认值,可通过 API_PASSWORD 环境变量修改)
|
| 156 |
+
|
| 157 |
+
**Gemini 原生客户端:**
|
| 158 |
+
- **端点地址**:`http://127.0.0.1:7861`
|
| 159 |
+
- **认证方式**:`Authorization: Bearer 密钥`、`x-goog-api-key: 密钥` 或 URL 参数 `?key=密钥`
|
| 160 |
+
|
| 161 |
+
**Claude 客户端:**
|
| 162 |
+
- **端点地址**:`http://127.0.0.1:7861/v1/messages`
|
| 163 |
+
- **认证方式**:`x-api-key: 密钥` 或 `Authorization: Bearer 密钥`
|
| 164 |
+
|
| 165 |
+
## 💾 数据存储
|
| 166 |
+
|
| 167 |
+
### 存储后端
|
| 168 |
+
|
| 169 |
+
| 后端 | 说明 | 启用方式 |
|
| 170 |
+
|------|------|----------|
|
| 171 |
+
| **SQLite**(默认) | 本地文件存储,开箱即用 | 无需配置,数据存储在 `creds/credentials.db` |
|
| 172 |
+
| **PostgreSQL** | 云端分布式存储,多实例部署 | 设置 `POSTGRESQL_URI` 环境变量 |
|
| 173 |
+
|
| 174 |
+
### 凭证数据结构
|
| 175 |
+
|
| 176 |
+
凭证以**邮箱(email)为唯一键**存储,字段为结构化数据库列(不再使用 JSON blob):
|
| 177 |
+
`email`、`access_token`、`refresh_token`、`client_id`、`client_secret`、`project_id`、`expiry`、`tier`
|
| 178 |
+
|
| 179 |
+
凭证导入/导出使用规范 JSON 格式:`{"refresh_token": "...", "access_token": "...", "expiry": "...", "email": "...", "tier": "...", "project_id": "..."}`(仅 `refresh_token` 必填,`access_token` 未过期时直接复用,其余字段可自动获取)。
|
| 180 |
+
|
| 181 |
+
### 环境变量配置
|
| 182 |
+
|
| 183 |
+
**基础配置**
|
| 184 |
+
- `PORT`: 服务端口(默认:7861)
|
| 185 |
+
- `HOST`: 服务器监听地址(默认:0.0.0.0)
|
| 186 |
+
|
| 187 |
+
**密码配置**
|
| 188 |
+
- `API_PASSWORD`: 聊天 API 访问密码(默认:pwd)
|
| 189 |
+
- `PANEL_PASSWORD`: 控制面板访问密码(默认:pwd)
|
| 190 |
+
|
| 191 |
+
**访问控制配置**
|
| 192 |
+
- `IP_WHITELIST_ENABLED`: 启用 IP 白名单(默认:false,不限制)
|
| 193 |
+
- `IP_WHITELIST`: IP 白名单列表,逗号或换行分隔(默认:空)。每条支持单个 IP(`192.168.1.1`)、CIDR 网段(`192.168.1.0/24`)、起止范围(`10.0.0.1-10.0.0.100`),IPv4 / IPv6 均可。开启后仅白名单内 IP 可访问面板和 API,其余 IP 直接 403;面板保存后立即生效
|
| 194 |
+
|
| 195 |
+
**模型名复写配置**
|
| 196 |
+
- `MODEL_REWRITE_ENABLED`: 启用模型名复写(默认:false)
|
| 197 |
+
- `MODEL_REWRITE_RULES`: 复写规则,每条为 `[匹配正则, 替换模型名]`(默认:空)。自上而下首条命中即替换,替换支持正则反向引用(如 `\1`)。例:把 `gpt-4o` 映射到 `gemini-2.5-pro`。面板保存后立即生效
|
| 198 |
+
|
| 199 |
+
**存储配置**
|
| 200 |
+
- `CREDENTIALS_DIR`: 凭证数据库目录(默认:./creds)
|
| 201 |
+
- `POSTGRESQL_URI`: PostgreSQL 连接字符串(设置后启用 PostgreSQL 模式)
|
| 202 |
+
|
| 203 |
+
**网络和代理配置**
|
| 204 |
+
- `PROXY`: 代理地址(支持 `http://`、`https://`、`socks5://`、`socks5h://`,可带账号密码 `user:pass@host:port`)
|
| 205 |
+
- `OAUTH_PROXY_URL`: OAuth 认证代理端点
|
| 206 |
+
- `GOOGLEAPIS_PROXY_URL`: Google APIs 代理端点
|
| 207 |
+
- `ANTIGRAVITY_API_URL`: Antigravity API 端点
|
| 208 |
+
- `PATH_PREFIX`: 反代保留路径前缀(如 `/AGY2API`)时配置,由后端在路由匹配前剥掉该前缀;默认:空(不剥离)
|
| 209 |
+
|
| 210 |
+
**性能和稳定性配置**
|
| 211 |
+
- `RETRY_429_ENABLED`: 启用错误自动重试(默认:true)
|
| 212 |
+
- `RETRY_429_MAX_RETRIES`: 最大重试次数(默认:5)
|
| 213 |
+
- `RETRY_429_INTERVAL`: 重试间隔,秒(默认:1)
|
| 214 |
+
- `ANTI_TRUNCATION_MAX_ATTEMPTS`: 抗截断最大重试次数(默认:3)
|
| 215 |
+
|
| 216 |
+
**自动化配置**
|
| 217 |
+
- `AUTO_BAN`: 启用凭证自动封禁(默认:false)
|
| 218 |
+
- `AUTO_BAN_ERROR_CODES`: 触发自动封禁的错误码(默认:403)
|
| 219 |
+
|
| 220 |
+
**响应行为配置**
|
| 221 |
+
- `RETURN_THOUGHTS_TO_FRONTEND`: 返回思维链到前端(默认:true)
|
| 222 |
+
|
| 223 |
+
**敏感词过滤配置**
|
| 224 |
+
- `SENSITIVE_WORDS_ENABLED`: 启用敏感词过滤(默认:false)
|
| 225 |
+
- `SENSITIVE_WORDS`: 敏感词列表,逗号或换行分隔(默认:空)。命中后整词替换为空,不区分大小写,支持中文,面板保存后立即生效
|
| 226 |
+
|
| 227 |
+
**请求日志配置**
|
| 228 |
+
- `USAGE_LOG_ENABLED`: 启用请求日志(默认:true)。记录每次 API 请求(模型、凭证、token 用量、耗时、状态)到数据库,不自动清理,可在面板手动清理或清空
|
| 229 |
+
|
| 230 |
+
**请求体详细日志配置**
|
| 231 |
+
- `REQUEST_LOG_ENABLED`: 启用请求体详细日志(默认:false)。开启后,当请求命中指定错误码时,把发往上游的完整请求头(已脱敏)与请求体保存为 JSON 文件到 `data/request_logs/`,数据库仅记录文件索引,在"请求日志"详情中查看。主要用于请求体错误时排查 debug;清理/清空日志时会同步删除对应文件(Docker 部署请挂载 `./data/request_logs:/app/data/request_logs` 以持久化)
|
| 232 |
+
- `REQUEST_LOG_ERROR_CODES`: 触发详细日志的错误码列表,逗号分隔(默认:400)
|
| 233 |
+
|
| 234 |
+
**凭证选择模式**
|
| 235 |
+
- `CREDENTIAL_SELECT_MODE`: 凭证选择模式(默认:cache)
|
| 236 |
+
- `random` — 完全随机负载均衡,每次请求随机挑选凭证
|
| 237 |
+
- `cache` — 缓存匹配(推荐):以"模型 + system 指令(���首条 user 消息)"哈希会话 key,相同会话复用同一凭证,命中 Google 上游 prompt cache;凭证 CD 后自动切换并重新绑定
|
| 238 |
+
- `sticky` — 凭证粘性:所有请求锁定同一凭证,直到其进入 CD 或被禁用
|
| 239 |
+
- `REDIS_URL`: Redis 连接串(可选)。设置后缓存匹配的会话绑定存入 Redis,多实例共享;未设置时使用进程内存后端
|
| 240 |
+
|
| 241 |
+
**日志配置**
|
| 242 |
+
- `LOG_LEVEL`: 日志级别(DEBUG/INFO/WARNING/ERROR,默认:INFO)
|
| 243 |
+
- `ENABLE_LOG`: 完全静默,不打印任何日志(设为 0 启用静默,默认:1)
|
| 244 |
+
|
| 245 |
+
## API 使用示例
|
| 246 |
+
|
| 247 |
+
### OpenAI 格式
|
| 248 |
+
|
| 249 |
+
```bash
|
| 250 |
+
curl -X POST "http://127.0.0.1:7861/v1/chat/completions" \
|
| 251 |
+
-H "Authorization: Bearer your_api_password" \
|
| 252 |
+
-H "Content-Type: application/json" \
|
| 253 |
+
-d '{
|
| 254 |
+
"model": "claude-sonnet-4-5",
|
| 255 |
+
"messages": [
|
| 256 |
+
{"role": "user", "content": "Hello"}
|
| 257 |
+
],
|
| 258 |
+
"stream": true
|
| 259 |
+
}'
|
| 260 |
+
```
|
| 261 |
+
|
| 262 |
+
### Gemini 原生格式
|
| 263 |
+
|
| 264 |
+
```bash
|
| 265 |
+
curl -X POST "http://127.0.0.1:7861/v1/models/gemini-2.5-flash:generateContent?key=your_api_password" \
|
| 266 |
+
-H "Content-Type: application/json" \
|
| 267 |
+
-d '{
|
| 268 |
+
"contents": [
|
| 269 |
+
{"role": "user", "parts": [{"text": "Hello"}]}
|
| 270 |
+
]
|
| 271 |
+
}'
|
| 272 |
+
```
|
| 273 |
+
|
| 274 |
+
### Claude 格式
|
| 275 |
+
|
| 276 |
+
```bash
|
| 277 |
+
curl -X POST "http://127.0.0.1:7861/v1/messages" \
|
| 278 |
+
-H "x-api-key: your_api_password" \
|
| 279 |
+
-H "anthropic-version: 2023-06-01" \
|
| 280 |
+
-H "Content-Type: application/json" \
|
| 281 |
+
-d '{
|
| 282 |
+
"model": "claude-sonnet-4-5",
|
| 283 |
+
"max_tokens": 1024,
|
| 284 |
+
"messages": [
|
| 285 |
+
{"role": "user", "content": "Hello, Claude!"}
|
| 286 |
+
]
|
| 287 |
+
}'
|
| 288 |
+
```
|
| 289 |
+
|
| 290 |
+
### 图像生成(Gemini 原生 SDK)
|
| 291 |
+
|
| 292 |
+
```python
|
| 293 |
+
from io import BytesIO
|
| 294 |
+
from PIL import Image
|
| 295 |
+
from google.genai import Client
|
| 296 |
+
from google.genai.types import HttpOptions
|
| 297 |
+
from google.genai import types
|
| 298 |
+
|
| 299 |
+
client = Client(
|
| 300 |
+
api_key="pwd",
|
| 301 |
+
http_options=HttpOptions(base_url="http://127.0.0.1:7861"),
|
| 302 |
+
)
|
| 303 |
+
|
| 304 |
+
prompt = "画一只猫"
|
| 305 |
+
|
| 306 |
+
response = client.models.generate_content(
|
| 307 |
+
model="gemini-3.1-flash-image",
|
| 308 |
+
contents=[prompt],
|
| 309 |
+
config=types.GenerateContentConfig(
|
| 310 |
+
image_config=types.ImageConfig(
|
| 311 |
+
aspect_ratio="16:9",
|
| 312 |
+
)
|
| 313 |
+
)
|
| 314 |
+
)
|
| 315 |
+
for part in response.candidates[0].content.parts:
|
| 316 |
+
if part.text is not None:
|
| 317 |
+
print(part.text)
|
| 318 |
+
elif part.inline_data is not None:
|
| 319 |
+
image = Image.open(BytesIO(part.inline_data.data))
|
| 320 |
+
image.save("generated_image.png")
|
| 321 |
+
```
|
| 322 |
+
|
| 323 |
+
## 🛠️ 前端开发
|
| 324 |
+
|
| 325 |
+
控制面板前端源码位于 `frontend/` 目录(React + Vite + Tailwind CSS):
|
| 326 |
+
|
| 327 |
+
```bash
|
| 328 |
+
cd frontend
|
| 329 |
+
npm install
|
| 330 |
+
npm run dev # 开发模式,端口 3000,代理后端 API
|
| 331 |
+
npm run build # 构建到 dist/(生产模式使用)
|
| 332 |
+
```
|
| 333 |
+
|
| 334 |
+
后端直接托管 `dist/` 下编译后的静态文件,无需 Node.js 运行时。
|
| 335 |
+
|
| 336 |
+
## 💬 交流群
|
| 337 |
+
|
| 338 |
+
欢迎加入 QQ 群交流讨论!
|
| 339 |
+
|
| 340 |
+
**QQ 群号:1083250744**
|
| 341 |
+
|
| 342 |
+
## 许可证与免责声明
|
| 343 |
+
|
| 344 |
+
本项目仅供学习研究使用,禁止商业用途和倒卖。
|
| 345 |
+
|
| 346 |
+
## ⚠️ 许可证声明
|
| 347 |
+
|
| 348 |
+
本项目使用 [CNC-1.0 许可证](LICENSE)(反商业许可证)。
|
agy2api/config.py
ADDED
|
@@ -0,0 +1,791 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Configuration constants for the Geminicli2api proxy server.
|
| 3 |
+
Centralizes all configuration to avoid duplication across modules.
|
| 4 |
+
|
| 5 |
+
- 启动时加载一次配置到内存
|
| 6 |
+
- 修改配置时调用 reload_config() 重新从数据库加载
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import ipaddress
|
| 10 |
+
import json
|
| 11 |
+
import os
|
| 12 |
+
import re
|
| 13 |
+
from typing import Any, Optional
|
| 14 |
+
|
| 15 |
+
from log import log
|
| 16 |
+
|
| 17 |
+
# 全局配置缓存
|
| 18 |
+
_config_cache: dict[str, Any] = {}
|
| 19 |
+
_config_initialized = False
|
| 20 |
+
|
| 21 |
+
# Client Configuration
|
| 22 |
+
|
| 23 |
+
# 需要自动封禁的错误码 (默认值,可通过环境变量或配置覆盖)
|
| 24 |
+
AUTO_BAN_ERROR_CODES = [403]
|
| 25 |
+
|
| 26 |
+
# ====================== 环境变量映射表 ======================
|
| 27 |
+
# 统一维护环境变量名和配置键名的映射关系
|
| 28 |
+
# 格式: "环境变量名": "配置键名"
|
| 29 |
+
ENV_MAPPINGS = {
|
| 30 |
+
"CREDENTIALS_DIR": "credentials_dir",
|
| 31 |
+
"PROXY": "proxy",
|
| 32 |
+
"OAUTH_PROXY_URL": "oauth_proxy_url",
|
| 33 |
+
"GOOGLEAPIS_PROXY_URL": "googleapis_proxy_url",
|
| 34 |
+
"ANTIGRAVITY_API_URL": "antigravity_api_url",
|
| 35 |
+
"AUTO_BAN": "auto_ban_enabled",
|
| 36 |
+
"AUTO_BAN_ERROR_CODES": "auto_ban_error_codes",
|
| 37 |
+
"RETRY_429_MAX_RETRIES": "retry_429_max_retries",
|
| 38 |
+
"RETRY_429_ENABLED": "retry_429_enabled",
|
| 39 |
+
"RETRY_429_INTERVAL": "retry_429_interval",
|
| 40 |
+
"ANTI_TRUNCATION_MAX_ATTEMPTS": "anti_truncation_max_attempts",
|
| 41 |
+
"RETURN_THOUGHTS_TO_FRONTEND": "return_thoughts_to_frontend",
|
| 42 |
+
"SENSITIVE_WORDS": "sensitive_words",
|
| 43 |
+
"SENSITIVE_WORDS_ENABLED": "sensitive_words_enabled",
|
| 44 |
+
"IP_WHITELIST": "ip_whitelist",
|
| 45 |
+
"IP_WHITELIST_ENABLED": "ip_whitelist_enabled",
|
| 46 |
+
"MODEL_REWRITE_ENABLED": "model_rewrite_enabled",
|
| 47 |
+
"MODEL_REWRITE_RULES": "model_rewrite_rules",
|
| 48 |
+
"USAGE_LOG_ENABLED": "usage_log_enabled",
|
| 49 |
+
"REQUEST_LOG_ENABLED": "request_log_enabled",
|
| 50 |
+
"REQUEST_LOG_ERROR_CODES": "request_log_error_codes",
|
| 51 |
+
"CREDENTIAL_SELECT_MODE": "credential_select_mode",
|
| 52 |
+
"HOST": "host",
|
| 53 |
+
"PORT": "port",
|
| 54 |
+
"API_PASSWORD": "api_password",
|
| 55 |
+
"PANEL_PASSWORD": "panel_password",
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
# ====================== 配置系统 ======================
|
| 60 |
+
|
| 61 |
+
async def init_config():
|
| 62 |
+
"""初始化配置缓存(启动时调用一次)"""
|
| 63 |
+
global _config_cache, _config_initialized
|
| 64 |
+
|
| 65 |
+
if _config_initialized:
|
| 66 |
+
return
|
| 67 |
+
|
| 68 |
+
try:
|
| 69 |
+
from src.storage.database import get_database
|
| 70 |
+
database = await get_database()
|
| 71 |
+
_config_cache = await database.get_all_config()
|
| 72 |
+
_config_initialized = True
|
| 73 |
+
except Exception:
|
| 74 |
+
# 初始化失败时使用空缓存
|
| 75 |
+
_config_cache = {}
|
| 76 |
+
_config_initialized = True
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
async def reload_config():
|
| 80 |
+
"""重新加载配置(修改配置后调用)"""
|
| 81 |
+
global _config_cache, _config_initialized
|
| 82 |
+
|
| 83 |
+
try:
|
| 84 |
+
from src.storage.database import get_database
|
| 85 |
+
database = await get_database()
|
| 86 |
+
|
| 87 |
+
# 重新加载数据库配置缓存
|
| 88 |
+
await database.reload_config_cache()
|
| 89 |
+
|
| 90 |
+
# 重新加载配置缓存
|
| 91 |
+
_config_cache = await database.get_all_config()
|
| 92 |
+
_config_initialized = True
|
| 93 |
+
except Exception:
|
| 94 |
+
pass
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def _get_cached_config(key: str, default: Any = None) -> Any:
|
| 98 |
+
"""从内存缓存获取配置(同步)"""
|
| 99 |
+
return _config_cache.get(key, default)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
async def get_config_value(key: str, default: Any = None, env_var: Optional[str] = None) -> Any:
|
| 103 |
+
"""Get configuration value with priority: ENV > Storage > default."""
|
| 104 |
+
# 确保配置已初始化
|
| 105 |
+
if not _config_initialized:
|
| 106 |
+
await init_config()
|
| 107 |
+
|
| 108 |
+
# Priority 1: Environment variable
|
| 109 |
+
if env_var and os.getenv(env_var):
|
| 110 |
+
return os.getenv(env_var)
|
| 111 |
+
|
| 112 |
+
# Priority 2: Memory cache
|
| 113 |
+
value = _get_cached_config(key)
|
| 114 |
+
if value is not None:
|
| 115 |
+
return value
|
| 116 |
+
|
| 117 |
+
return default
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
# Configuration getters - all async
|
| 121 |
+
async def get_proxy_config():
|
| 122 |
+
"""Get proxy configuration, validating the URL format.
|
| 123 |
+
|
| 124 |
+
Supports http://, https://, socks5://, socks5h:// schemes, all with
|
| 125 |
+
optional embedded credentials (user:pass@host:port).
|
| 126 |
+
"""
|
| 127 |
+
proxy_url = await get_config_value("proxy", env_var="PROXY")
|
| 128 |
+
if not proxy_url:
|
| 129 |
+
return None
|
| 130 |
+
|
| 131 |
+
proxy_url = proxy_url.strip()
|
| 132 |
+
scheme = proxy_url.split("://", 1)[0].lower()
|
| 133 |
+
if scheme not in ("http", "https", "socks5", "socks5h"):
|
| 134 |
+
log.warning(
|
| 135 |
+
f"不支持的代理协议: {scheme}://(支持 http/https/socks5/socks5h),已忽略代理"
|
| 136 |
+
)
|
| 137 |
+
return None
|
| 138 |
+
return proxy_url
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
async def get_auto_ban_enabled() -> bool:
|
| 142 |
+
"""Get auto ban enabled setting."""
|
| 143 |
+
env_value = os.getenv("AUTO_BAN")
|
| 144 |
+
if env_value:
|
| 145 |
+
return env_value.lower() in ("true", "1", "yes", "on")
|
| 146 |
+
|
| 147 |
+
return bool(await get_config_value("auto_ban_enabled", False))
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
async def get_auto_ban_error_codes() -> list:
|
| 151 |
+
"""
|
| 152 |
+
Get auto ban error codes.
|
| 153 |
+
|
| 154 |
+
Environment variable: AUTO_BAN_ERROR_CODES (comma-separated, e.g., "400,403")
|
| 155 |
+
Database config key: auto_ban_error_codes
|
| 156 |
+
Default: [400, 403]
|
| 157 |
+
"""
|
| 158 |
+
env_value = os.getenv("AUTO_BAN_ERROR_CODES")
|
| 159 |
+
if env_value:
|
| 160 |
+
try:
|
| 161 |
+
return [int(code.strip()) for code in env_value.split(",") if code.strip()]
|
| 162 |
+
except ValueError:
|
| 163 |
+
pass
|
| 164 |
+
|
| 165 |
+
codes = await get_config_value("auto_ban_error_codes")
|
| 166 |
+
if codes and isinstance(codes, list):
|
| 167 |
+
return codes
|
| 168 |
+
return AUTO_BAN_ERROR_CODES
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
async def get_retry_429_max_retries() -> int:
|
| 172 |
+
"""Get max retries for 429 errors."""
|
| 173 |
+
env_value = os.getenv("RETRY_429_MAX_RETRIES")
|
| 174 |
+
if env_value:
|
| 175 |
+
try:
|
| 176 |
+
return int(env_value)
|
| 177 |
+
except ValueError:
|
| 178 |
+
pass
|
| 179 |
+
|
| 180 |
+
return int(await get_config_value("retry_429_max_retries", 5))
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
async def get_retry_429_enabled() -> bool:
|
| 184 |
+
"""Get 429 retry enabled setting."""
|
| 185 |
+
env_value = os.getenv("RETRY_429_ENABLED")
|
| 186 |
+
if env_value:
|
| 187 |
+
return env_value.lower() in ("true", "1", "yes", "on")
|
| 188 |
+
|
| 189 |
+
return bool(await get_config_value("retry_429_enabled", True))
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
async def get_retry_429_interval() -> float:
|
| 193 |
+
"""Get 429 retry interval in seconds."""
|
| 194 |
+
env_value = os.getenv("RETRY_429_INTERVAL")
|
| 195 |
+
if env_value:
|
| 196 |
+
try:
|
| 197 |
+
return float(env_value)
|
| 198 |
+
except ValueError:
|
| 199 |
+
pass
|
| 200 |
+
|
| 201 |
+
return float(await get_config_value("retry_429_interval", 1))
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
async def get_anti_truncation_max_attempts() -> int:
|
| 205 |
+
"""
|
| 206 |
+
Get maximum attempts for anti-truncation continuation.
|
| 207 |
+
|
| 208 |
+
Environment variable: ANTI_TRUNCATION_MAX_ATTEMPTS
|
| 209 |
+
Database config key: anti_truncation_max_attempts
|
| 210 |
+
Default: 3
|
| 211 |
+
"""
|
| 212 |
+
env_value = os.getenv("ANTI_TRUNCATION_MAX_ATTEMPTS")
|
| 213 |
+
if env_value:
|
| 214 |
+
try:
|
| 215 |
+
return int(env_value)
|
| 216 |
+
except ValueError:
|
| 217 |
+
pass
|
| 218 |
+
|
| 219 |
+
return int(await get_config_value("anti_truncation_max_attempts", 3))
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
# Server Configuration
|
| 223 |
+
async def get_server_host() -> str:
|
| 224 |
+
"""
|
| 225 |
+
Get server host setting.
|
| 226 |
+
|
| 227 |
+
Environment variable: HOST
|
| 228 |
+
Database config key: host
|
| 229 |
+
Default: 0.0.0.0
|
| 230 |
+
"""
|
| 231 |
+
return str(await get_config_value("host", "0.0.0.0", "HOST"))
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
async def get_server_port() -> int:
|
| 235 |
+
"""
|
| 236 |
+
Get server port setting.
|
| 237 |
+
|
| 238 |
+
Environment variable: PORT
|
| 239 |
+
Database config key: port
|
| 240 |
+
Default: 7861
|
| 241 |
+
"""
|
| 242 |
+
env_value = os.getenv("PORT")
|
| 243 |
+
if env_value:
|
| 244 |
+
try:
|
| 245 |
+
return int(env_value)
|
| 246 |
+
except ValueError:
|
| 247 |
+
pass
|
| 248 |
+
|
| 249 |
+
return int(await get_config_value("port", 7861))
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
async def get_api_password() -> str:
|
| 253 |
+
"""
|
| 254 |
+
Get API password setting for chat endpoints.
|
| 255 |
+
|
| 256 |
+
Environment variable: API_PASSWORD
|
| 257 |
+
Database config key: api_password
|
| 258 |
+
Default: pwd
|
| 259 |
+
"""
|
| 260 |
+
return str(await get_config_value("api_password", "pwd", "API_PASSWORD"))
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
async def get_panel_password() -> str:
|
| 264 |
+
"""
|
| 265 |
+
Get panel password setting for web interface.
|
| 266 |
+
|
| 267 |
+
Environment variable: PANEL_PASSWORD
|
| 268 |
+
Database config key: panel_password
|
| 269 |
+
Default: pwd
|
| 270 |
+
"""
|
| 271 |
+
return str(await get_config_value("panel_password", "pwd", "PANEL_PASSWORD"))
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
async def get_credentials_dir() -> str:
|
| 275 |
+
"""
|
| 276 |
+
Get credentials directory setting.
|
| 277 |
+
|
| 278 |
+
Environment variable: CREDENTIALS_DIR
|
| 279 |
+
Database config key: credentials_dir
|
| 280 |
+
Default: ./creds
|
| 281 |
+
"""
|
| 282 |
+
return str(await get_config_value("credentials_dir", "./creds", "CREDENTIALS_DIR"))
|
| 283 |
+
|
| 284 |
+
async def get_return_thoughts_to_frontend() -> bool:
|
| 285 |
+
"""
|
| 286 |
+
Get return thoughts to frontend setting.
|
| 287 |
+
|
| 288 |
+
控制是否将思维链返回到前端。
|
| 289 |
+
启用后,思维链会在响应中返回;禁用后,思维链会在响应中被过滤掉。
|
| 290 |
+
|
| 291 |
+
Environment variable: RETURN_THOUGHTS_TO_FRONTEND
|
| 292 |
+
Database config key: return_thoughts_to_frontend
|
| 293 |
+
Default: True
|
| 294 |
+
"""
|
| 295 |
+
env_value = os.getenv("RETURN_THOUGHTS_TO_FRONTEND")
|
| 296 |
+
if env_value:
|
| 297 |
+
return env_value.lower() in ("true", "1", "yes", "on")
|
| 298 |
+
|
| 299 |
+
return bool(await get_config_value("return_thoughts_to_frontend", True))
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
# ====================== 敏感词过滤 ======================
|
| 303 |
+
|
| 304 |
+
# 敏感词正则编译缓存: (原始词表指纹, 编译后的 pattern 列表)
|
| 305 |
+
_sensitive_words_cache: dict = {"fingerprint": None, "patterns": []}
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
async def get_sensitive_words_enabled() -> bool:
|
| 309 |
+
"""
|
| 310 |
+
敏感词过滤开关。
|
| 311 |
+
|
| 312 |
+
Environment variable: SENSITIVE_WORDS_ENABLED
|
| 313 |
+
Database config key: sensitive_words_enabled
|
| 314 |
+
Default: False
|
| 315 |
+
"""
|
| 316 |
+
env_value = os.getenv("SENSITIVE_WORDS_ENABLED")
|
| 317 |
+
if env_value:
|
| 318 |
+
return env_value.lower() in ("true", "1", "yes", "on")
|
| 319 |
+
|
| 320 |
+
return bool(await get_config_value("sensitive_words_enabled", False))
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
async def get_sensitive_words() -> list:
|
| 324 |
+
"""
|
| 325 |
+
敏感词列表(支持正则),每行一个;空列表表示不过滤。
|
| 326 |
+
|
| 327 |
+
Environment variable: SENSITIVE_WORDS (逗号或换行分隔)
|
| 328 |
+
Database config key: sensitive_words
|
| 329 |
+
Default: []
|
| 330 |
+
"""
|
| 331 |
+
env_value = os.getenv("SENSITIVE_WORDS")
|
| 332 |
+
if env_value:
|
| 333 |
+
words = [w.strip() for w in re.split(r"[,\n]", env_value) if w.strip()]
|
| 334 |
+
return words
|
| 335 |
+
|
| 336 |
+
value = await get_config_value("sensitive_words")
|
| 337 |
+
if isinstance(value, list):
|
| 338 |
+
return [str(w) for w in value if str(w).strip()]
|
| 339 |
+
if isinstance(value, str) and value.strip():
|
| 340 |
+
return [w.strip() for w in re.split(r"[,\n]", value) if w.strip()]
|
| 341 |
+
return []
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
def compile_sensitive_words(words: list):
|
| 345 |
+
"""
|
| 346 |
+
编译敏感词为大小写不敏感的正则列表(带缓存)。
|
| 347 |
+
|
| 348 |
+
每个词按字面量转义后编译(用户输入的是词/短语而非正则语法),
|
| 349 |
+
触发后整词替换为空。支持中文(re.UNICODE 默认开启)。
|
| 350 |
+
|
| 351 |
+
Returns:
|
| 352 |
+
编译后的 Pattern 列表;无效条目跳过并告警。
|
| 353 |
+
"""
|
| 354 |
+
fingerprint = tuple(words)
|
| 355 |
+
if _sensitive_words_cache["fingerprint"] == fingerprint:
|
| 356 |
+
return _sensitive_words_cache["patterns"]
|
| 357 |
+
|
| 358 |
+
patterns = []
|
| 359 |
+
for word in words:
|
| 360 |
+
word = str(word).strip()
|
| 361 |
+
if not word:
|
| 362 |
+
continue
|
| 363 |
+
try:
|
| 364 |
+
patterns.append(re.compile(re.escape(word), re.IGNORECASE | re.UNICODE))
|
| 365 |
+
except re.error as e:
|
| 366 |
+
log.warning(f"敏感词编译失败,已跳过: {word!r} ({e})")
|
| 367 |
+
|
| 368 |
+
_sensitive_words_cache["fingerprint"] = fingerprint
|
| 369 |
+
_sensitive_words_cache["patterns"] = patterns
|
| 370 |
+
return patterns
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
def apply_sensitive_word_filter(text: str, patterns) -> str:
|
| 374 |
+
"""将文本中命中的敏感词(大小写不敏感)替换为空"""
|
| 375 |
+
if not text or not patterns:
|
| 376 |
+
return text
|
| 377 |
+
for pattern in patterns:
|
| 378 |
+
text = pattern.sub("", text)
|
| 379 |
+
return text
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
async def get_sensitive_word_filter():
|
| 383 |
+
"""
|
| 384 |
+
获取生效的敏感词过滤条件(供请求处理管道调用)。
|
| 385 |
+
|
| 386 |
+
Returns:
|
| 387 |
+
(enabled, patterns);未启用时 patterns 为空列表。
|
| 388 |
+
"""
|
| 389 |
+
if not await get_sensitive_words_enabled():
|
| 390 |
+
return False, []
|
| 391 |
+
words = await get_sensitive_words()
|
| 392 |
+
if not words:
|
| 393 |
+
return False, []
|
| 394 |
+
return True, compile_sensitive_words(words)
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
# ====================== IP 白名单 ======================
|
| 398 |
+
|
| 399 |
+
# IP 白名单规则缓存: (原始条目指纹, 解析结果 (rules, invalid))
|
| 400 |
+
_ip_whitelist_cache: dict = {"fingerprint": None, "result": ([], [])}
|
| 401 |
+
|
| 402 |
+
|
| 403 |
+
def parse_ip_whitelist_line(line: str):
|
| 404 |
+
"""
|
| 405 |
+
解析单条白名单条目为 (lo, hi, version) 网络对象;无效时抛出 ValueError。
|
| 406 |
+
|
| 407 |
+
支持格式(IPv4 / IPv6):
|
| 408 |
+
- 单个 IP: 192.168.1.1 / ::1
|
| 409 |
+
- CIDR 网段: 192.168.1.0/24 / 2001:db8::/32
|
| 410 |
+
- IP 起止范围(- 或 ~ 分隔): 192.168.1.1-192.168.1.100 / ::1-::10
|
| 411 |
+
"""
|
| 412 |
+
line = str(line).strip()
|
| 413 |
+
if not line:
|
| 414 |
+
raise ValueError("空条目")
|
| 415 |
+
|
| 416 |
+
for sep in ("~", "-"):
|
| 417 |
+
if sep in line:
|
| 418 |
+
start_str, _, end_str = line.partition(sep)
|
| 419 |
+
if start_str.strip() and end_str.strip():
|
| 420 |
+
start = ipaddress.ip_address(start_str.strip())
|
| 421 |
+
end = ipaddress.ip_address(end_str.strip())
|
| 422 |
+
if start.version != end.version:
|
| 423 |
+
raise ValueError(f"起止 IP 版本不一致: {line}")
|
| 424 |
+
if int(start) > int(end):
|
| 425 |
+
start, end = end, start
|
| 426 |
+
return start, end, start.version
|
| 427 |
+
|
| 428 |
+
if "/" in line:
|
| 429 |
+
net = ipaddress.ip_network(line, strict=False)
|
| 430 |
+
return net.network_address, net.broadcast_address, net.version
|
| 431 |
+
|
| 432 |
+
addr = ipaddress.ip_address(line)
|
| 433 |
+
return addr, addr, addr.version
|
| 434 |
+
|
| 435 |
+
|
| 436 |
+
def compile_ip_whitelist(entries: list):
|
| 437 |
+
"""
|
| 438 |
+
解析白名单条目列表为规则列表(带缓存)。
|
| 439 |
+
|
| 440 |
+
Returns:
|
| 441 |
+
(rules, invalid)——rules 为 [(lo, hi, version), ...],invalid 为解析失败的原始条目。
|
| 442 |
+
"""
|
| 443 |
+
fingerprint = tuple(str(e) for e in entries)
|
| 444 |
+
if _ip_whitelist_cache["fingerprint"] == fingerprint:
|
| 445 |
+
return _ip_whitelist_cache["result"]
|
| 446 |
+
|
| 447 |
+
rules = []
|
| 448 |
+
invalid = []
|
| 449 |
+
for entry in entries:
|
| 450 |
+
entry = str(entry).strip()
|
| 451 |
+
if not entry:
|
| 452 |
+
continue
|
| 453 |
+
try:
|
| 454 |
+
rules.append(parse_ip_whitelist_line(entry))
|
| 455 |
+
except ValueError:
|
| 456 |
+
invalid.append(entry)
|
| 457 |
+
|
| 458 |
+
result = (rules, invalid)
|
| 459 |
+
_ip_whitelist_cache["fingerprint"] = fingerprint
|
| 460 |
+
_ip_whitelist_cache["result"] = result
|
| 461 |
+
return result
|
| 462 |
+
|
| 463 |
+
|
| 464 |
+
def ip_in_whitelist(client_ip: str, rules: list) -> bool:
|
| 465 |
+
"""判断客户端 IP 是否命中白名单规则(IPv4/IPv6 均支持)"""
|
| 466 |
+
if not client_ip:
|
| 467 |
+
return False
|
| 468 |
+
try:
|
| 469 |
+
addr = ipaddress.ip_address(client_ip)
|
| 470 |
+
except ValueError:
|
| 471 |
+
return False
|
| 472 |
+
return any(lo.version == addr.version and lo <= addr <= hi for lo, hi, _ in rules)
|
| 473 |
+
|
| 474 |
+
|
| 475 |
+
async def get_ip_whitelist_enabled() -> bool:
|
| 476 |
+
"""
|
| 477 |
+
IP 白名单开关。
|
| 478 |
+
|
| 479 |
+
Environment variable: IP_WHITELIST_ENABLED
|
| 480 |
+
Database config key: ip_whitelist_enabled
|
| 481 |
+
Default: False
|
| 482 |
+
"""
|
| 483 |
+
env_value = os.getenv("IP_WHITELIST_ENABLED")
|
| 484 |
+
if env_value:
|
| 485 |
+
return env_value.lower() in ("true", "1", "yes", "on")
|
| 486 |
+
|
| 487 |
+
return bool(await get_config_value("ip_whitelist_enabled", False))
|
| 488 |
+
|
| 489 |
+
|
| 490 |
+
async def get_ip_whitelist() -> list:
|
| 491 |
+
"""
|
| 492 |
+
IP 白名单列表,每行一条;空列表表示不限制。
|
| 493 |
+
|
| 494 |
+
支持单个 IP、CIDR 网段、起止范围(- 或 ~ 分隔),IPv4/IPv6 均可。
|
| 495 |
+
仅在开关开启时生效,命中白名单以外 IP 的所有请求(面板 + API)将直接返回 403。
|
| 496 |
+
|
| 497 |
+
Environment variable: IP_WHITELIST (逗号或换行分隔)
|
| 498 |
+
Database config key: ip_whitelist
|
| 499 |
+
Default: []
|
| 500 |
+
"""
|
| 501 |
+
env_value = os.getenv("IP_WHITELIST")
|
| 502 |
+
if env_value is not None and env_value.strip():
|
| 503 |
+
return [e.strip() for e in re.split(r"[,\n]", env_value) if e.strip()]
|
| 504 |
+
|
| 505 |
+
value = await get_config_value("ip_whitelist")
|
| 506 |
+
if isinstance(value, list):
|
| 507 |
+
return [str(e).strip() for e in value if str(e).strip()]
|
| 508 |
+
if isinstance(value, str) and value.strip():
|
| 509 |
+
return [e.strip() for e in re.split(r"[,\n]", value) if e.strip()]
|
| 510 |
+
return []
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
async def get_ip_whitelist_rules():
|
| 514 |
+
"""
|
| 515 |
+
获取生效的 IP 白名单规则(供请求拦截中间件调用)。
|
| 516 |
+
|
| 517 |
+
Returns:
|
| 518 |
+
(enabled, rules);开关关闭或白名单为空时不启用限制。
|
| 519 |
+
"""
|
| 520 |
+
if not await get_ip_whitelist_enabled():
|
| 521 |
+
return False, []
|
| 522 |
+
entries = await get_ip_whitelist()
|
| 523 |
+
if not entries:
|
| 524 |
+
return False, []
|
| 525 |
+
rules, invalid = compile_ip_whitelist(entries)
|
| 526 |
+
if invalid:
|
| 527 |
+
log.warning(f"IP 白名单中存在无效条目(已跳过): {invalid}")
|
| 528 |
+
return bool(rules), rules
|
| 529 |
+
|
| 530 |
+
|
| 531 |
+
# ====================== 模型名复写 ======================
|
| 532 |
+
|
| 533 |
+
# 模型名复写规则缓存: (指纹, (编译后的规则列表, 无效规则列表))
|
| 534 |
+
_model_rewrite_cache: dict = {"fingerprint": None, "result": ([], [])}
|
| 535 |
+
|
| 536 |
+
|
| 537 |
+
async def get_model_rewrite_enabled() -> bool:
|
| 538 |
+
"""
|
| 539 |
+
模型名复写开关。
|
| 540 |
+
|
| 541 |
+
Environment variable: MODEL_REWRITE_ENABLED
|
| 542 |
+
Database config key: model_rewrite_enabled
|
| 543 |
+
Default: False
|
| 544 |
+
"""
|
| 545 |
+
env_value = os.getenv("MODEL_REWRITE_ENABLED")
|
| 546 |
+
if env_value:
|
| 547 |
+
return env_value.lower() in ("true", "1", "yes", "on")
|
| 548 |
+
|
| 549 |
+
return bool(await get_config_value("model_rewrite_enabled", False))
|
| 550 |
+
|
| 551 |
+
|
| 552 |
+
async def get_model_rewrite_rules_config() -> list:
|
| 553 |
+
"""
|
| 554 |
+
模型名复写规则列表,每条为 [pattern, replacement]。
|
| 555 |
+
|
| 556 |
+
pattern 支持正则(对模型名做全匹配搜索,命中任意一处即替换),
|
| 557 |
+
replacement 中可使用正则反向引用(如 \\1)。
|
| 558 |
+
|
| 559 |
+
Environment variable: MODEL_REWRITE_RULES (JSON 数组,如 [["gpt-4","gemini-2.5-pro"]];也支持 "pat->rep" 逗号分隔的简化格式)
|
| 560 |
+
Database config key: model_rewrite_rules
|
| 561 |
+
Default: []
|
| 562 |
+
"""
|
| 563 |
+
env_value = os.getenv("MODEL_REWRITE_RULES")
|
| 564 |
+
if env_value is not None and env_value.strip():
|
| 565 |
+
parsed = _parse_model_rewrite_rules_value(env_value)
|
| 566 |
+
if parsed is not None:
|
| 567 |
+
return parsed
|
| 568 |
+
|
| 569 |
+
value = await get_config_value("model_rewrite_rules")
|
| 570 |
+
return _parse_model_rewrite_rules_value(value) or []
|
| 571 |
+
|
| 572 |
+
|
| 573 |
+
def _parse_model_rewrite_rules_value(value: Any) -> Optional[list]:
|
| 574 |
+
"""将配置值解析为 [[pattern, replacement], ...];无法解析时返回 None"""
|
| 575 |
+
if isinstance(value, list):
|
| 576 |
+
rules = []
|
| 577 |
+
for item in value:
|
| 578 |
+
if isinstance(item, (list, tuple)) and len(item) == 2 and all(isinstance(x, str) for x in item):
|
| 579 |
+
rules.append([item[0], item[1]])
|
| 580 |
+
elif isinstance(item, dict) and isinstance(item.get("pattern"), str) and isinstance(item.get("replacement"), str):
|
| 581 |
+
rules.append([item["pattern"], item["replacement"]])
|
| 582 |
+
return rules
|
| 583 |
+
if isinstance(value, str) and value.strip():
|
| 584 |
+
# 优先尝试 JSON 数组格式(环境变量推荐格式)
|
| 585 |
+
if value.strip().startswith("["):
|
| 586 |
+
try:
|
| 587 |
+
parsed = json.loads(value)
|
| 588 |
+
if isinstance(parsed, list):
|
| 589 |
+
inner = _parse_model_rewrite_rules_value(parsed)
|
| 590 |
+
if inner is not None:
|
| 591 |
+
return inner
|
| 592 |
+
except (json.JSONDecodeError, ValueError):
|
| 593 |
+
pass
|
| 594 |
+
# 兼容 "pat->rep,pat->rep" 简化格式
|
| 595 |
+
rules = []
|
| 596 |
+
for pair in value.split(","):
|
| 597 |
+
pair = pair.strip()
|
| 598 |
+
if "->" in pair:
|
| 599 |
+
pat, _, rep = pair.partition("->")
|
| 600 |
+
rules.append([pat.strip(), rep.strip()])
|
| 601 |
+
return rules or None
|
| 602 |
+
return None
|
| 603 |
+
|
| 604 |
+
|
| 605 |
+
def compile_model_rewrite_rules(rules: list):
|
| 606 |
+
"""
|
| 607 |
+
编译复写规则为 (pattern, replacement) 元组列表(带缓存)。
|
| 608 |
+
|
| 609 |
+
Returns:
|
| 610 |
+
(compiled, invalid)——invalid 为编译失败的原始规则。
|
| 611 |
+
"""
|
| 612 |
+
fingerprint = tuple(tuple(r) for r in rules)
|
| 613 |
+
if _model_rewrite_cache["fingerprint"] == fingerprint:
|
| 614 |
+
return _model_rewrite_cache["result"]
|
| 615 |
+
|
| 616 |
+
compiled = []
|
| 617 |
+
invalid = []
|
| 618 |
+
for rule in rules:
|
| 619 |
+
if not (isinstance(rule, (list, tuple)) and len(rule) == 2):
|
| 620 |
+
continue
|
| 621 |
+
pattern, replacement = rule[0], rule[1]
|
| 622 |
+
try:
|
| 623 |
+
compiled.append((re.compile(str(pattern)), str(replacement)))
|
| 624 |
+
except re.error:
|
| 625 |
+
invalid.append(rule)
|
| 626 |
+
|
| 627 |
+
result = (compiled, invalid)
|
| 628 |
+
_model_rewrite_cache["fingerprint"] = fingerprint
|
| 629 |
+
_model_rewrite_cache["result"] = result
|
| 630 |
+
return result
|
| 631 |
+
|
| 632 |
+
|
| 633 |
+
def rewrite_model_name(model_name: str, compiled_rules: list) -> str:
|
| 634 |
+
"""
|
| 635 |
+
按规则顺序应用模型名复写(命中第一条即停止)。
|
| 636 |
+
|
| 637 |
+
使用 re.sub 全字符串搜索替换;replacement 支持 \\1 等反向引用。
|
| 638 |
+
"""
|
| 639 |
+
for pattern, replacement in compiled_rules:
|
| 640 |
+
if pattern.search(model_name):
|
| 641 |
+
return pattern.sub(replacement, model_name)
|
| 642 |
+
return model_name
|
| 643 |
+
|
| 644 |
+
|
| 645 |
+
async def get_model_rewrite_filter():
|
| 646 |
+
"""
|
| 647 |
+
获取生效的模型名复写规则(供请求处理管道调用)。
|
| 648 |
+
|
| 649 |
+
Returns:
|
| 650 |
+
(enabled, compiled_rules);未启用时 compiled_rules 为空列表。
|
| 651 |
+
"""
|
| 652 |
+
if not await get_model_rewrite_enabled():
|
| 653 |
+
return False, []
|
| 654 |
+
rules = await get_model_rewrite_rules_config()
|
| 655 |
+
if not rules:
|
| 656 |
+
return False, []
|
| 657 |
+
compiled, invalid = compile_model_rewrite_rules(rules)
|
| 658 |
+
if invalid:
|
| 659 |
+
log.warning(f"模型名复写规则中存在无效正则(已跳过): {invalid}")
|
| 660 |
+
return bool(compiled), compiled
|
| 661 |
+
|
| 662 |
+
|
| 663 |
+
# ====================== 请求日志 ======================
|
| 664 |
+
|
| 665 |
+
async def get_usage_log_enabled() -> bool:
|
| 666 |
+
"""
|
| 667 |
+
请求日志(usage_log)开关。
|
| 668 |
+
|
| 669 |
+
Environment variable: USAGE_LOG_ENABLED
|
| 670 |
+
Database config key: usage_log_enabled
|
| 671 |
+
Default: True
|
| 672 |
+
"""
|
| 673 |
+
env_value = os.getenv("USAGE_LOG_ENABLED")
|
| 674 |
+
if env_value:
|
| 675 |
+
return env_value.lower() in ("true", "1", "yes", "on")
|
| 676 |
+
|
| 677 |
+
return bool(await get_config_value("usage_log_enabled", True))
|
| 678 |
+
|
| 679 |
+
|
| 680 |
+
async def get_request_log_enabled() -> bool:
|
| 681 |
+
"""
|
| 682 |
+
请求体详细日志开关。
|
| 683 |
+
|
| 684 |
+
Environment variable: REQUEST_LOG_ENABLED
|
| 685 |
+
Database config key: request_log_enabled
|
| 686 |
+
Default: False
|
| 687 |
+
"""
|
| 688 |
+
env_value = os.getenv("REQUEST_LOG_ENABLED")
|
| 689 |
+
if env_value:
|
| 690 |
+
return env_value.lower() in ("true", "1", "yes", "on")
|
| 691 |
+
|
| 692 |
+
return bool(await get_config_value("request_log_enabled", False))
|
| 693 |
+
|
| 694 |
+
|
| 695 |
+
async def get_request_log_error_codes() -> list:
|
| 696 |
+
"""
|
| 697 |
+
请求体详细日志记录的错误码列表(仅命中时写盘)。
|
| 698 |
+
|
| 699 |
+
Environment variable: REQUEST_LOG_ERROR_CODES (逗号分隔, 如 "400,429")
|
| 700 |
+
Database config key: request_log_error_codes
|
| 701 |
+
Default: [400]
|
| 702 |
+
"""
|
| 703 |
+
env_value = os.getenv("REQUEST_LOG_ERROR_CODES")
|
| 704 |
+
if env_value:
|
| 705 |
+
try:
|
| 706 |
+
return [int(code.strip()) for code in env_value.split(",") if code.strip()]
|
| 707 |
+
except ValueError:
|
| 708 |
+
pass
|
| 709 |
+
|
| 710 |
+
codes = await get_config_value("request_log_error_codes")
|
| 711 |
+
if codes and isinstance(codes, list):
|
| 712 |
+
return codes
|
| 713 |
+
return [400]
|
| 714 |
+
|
| 715 |
+
|
| 716 |
+
# ====================== 凭证选择模式 ======================
|
| 717 |
+
|
| 718 |
+
# 合法的凭证选择模式
|
| 719 |
+
CREDENTIAL_SELECT_MODES = ("random", "cache", "sticky")
|
| 720 |
+
|
| 721 |
+
|
| 722 |
+
async def get_credential_select_mode() -> str:
|
| 723 |
+
"""
|
| 724 |
+
凭证选择模式:
|
| 725 |
+
- random: 完全随机负载均衡(无亲和)
|
| 726 |
+
- cache: 会话缓存匹配(默认)——相同会话内容复用同一凭证,命中上游 prompt cache
|
| 727 |
+
- sticky: 凭证粘性——尽量保持同一凭证直到其进入 CD 或被禁用
|
| 728 |
+
|
| 729 |
+
Environment variable: CREDENTIAL_SELECT_MODE
|
| 730 |
+
Database config key: credential_select_mode
|
| 731 |
+
Default: cache
|
| 732 |
+
"""
|
| 733 |
+
value = await get_config_value("credential_select_mode", "cache", "CREDENTIAL_SELECT_MODE")
|
| 734 |
+
value = str(value).strip().lower()
|
| 735 |
+
if value not in CREDENTIAL_SELECT_MODES:
|
| 736 |
+
log.warning(f"无效的凭证选择模式: {value},回落为 cache")
|
| 737 |
+
return "cache"
|
| 738 |
+
return value
|
| 739 |
+
|
| 740 |
+
|
| 741 |
+
async def get_oauth_proxy_url() -> str:
|
| 742 |
+
"""
|
| 743 |
+
Get OAuth proxy URL setting.
|
| 744 |
+
|
| 745 |
+
用于Google OAuth2认证的代理URL。
|
| 746 |
+
|
| 747 |
+
Environment variable: OAUTH_PROXY_URL
|
| 748 |
+
Database config key: oauth_proxy_url
|
| 749 |
+
Default: https://oauth2.googleapis.com
|
| 750 |
+
"""
|
| 751 |
+
return str(
|
| 752 |
+
await get_config_value(
|
| 753 |
+
"oauth_proxy_url", "https://oauth2.googleapis.com", "OAUTH_PROXY_URL"
|
| 754 |
+
)
|
| 755 |
+
)
|
| 756 |
+
|
| 757 |
+
|
| 758 |
+
async def get_googleapis_proxy_url() -> str:
|
| 759 |
+
"""
|
| 760 |
+
Get Google APIs proxy URL setting.
|
| 761 |
+
|
| 762 |
+
用于Google APIs调用的代理URL。
|
| 763 |
+
|
| 764 |
+
Environment variable: GOOGLEAPIS_PROXY_URL
|
| 765 |
+
Database config key: googleapis_proxy_url
|
| 766 |
+
Default: https://www.googleapis.com
|
| 767 |
+
"""
|
| 768 |
+
return str(
|
| 769 |
+
await get_config_value(
|
| 770 |
+
"googleapis_proxy_url", "https://www.googleapis.com", "GOOGLEAPIS_PROXY_URL"
|
| 771 |
+
)
|
| 772 |
+
)
|
| 773 |
+
|
| 774 |
+
|
| 775 |
+
async def get_antigravity_api_url() -> str:
|
| 776 |
+
"""
|
| 777 |
+
Get Antigravity API URL setting.
|
| 778 |
+
|
| 779 |
+
用于Google Antigravity API的URL。
|
| 780 |
+
|
| 781 |
+
Environment variable: ANTIGRAVITY_API_URL
|
| 782 |
+
Database config key: antigravity_api_url
|
| 783 |
+
Default: https://daily-cloudcode-pa.googleapis.com
|
| 784 |
+
"""
|
| 785 |
+
return str(
|
| 786 |
+
await get_config_value(
|
| 787 |
+
"antigravity_api_url",
|
| 788 |
+
"https://daily-cloudcode-pa.googleapis.com",
|
| 789 |
+
"ANTIGRAVITY_API_URL",
|
| 790 |
+
)
|
| 791 |
+
)
|
agy2api/darwin-install.sh
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# macOS 安装脚本 (支持 Intel 和 Apple Silicon)
|
| 3 |
+
|
| 4 |
+
# 确保 Homebrew 已安装
|
| 5 |
+
if ! command -v brew &> /dev/null; then
|
| 6 |
+
echo "未检测到 Homebrew,开始安装..."
|
| 7 |
+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
| 8 |
+
|
| 9 |
+
# 检测 Homebrew 安装路径并设置环境变量
|
| 10 |
+
if [[ -f "/opt/homebrew/bin/brew" ]]; then
|
| 11 |
+
# Apple Silicon Mac
|
| 12 |
+
eval "$(/opt/homebrew/bin/brew shellenv)"
|
| 13 |
+
elif [[ -f "/usr/local/bin/brew" ]]; then
|
| 14 |
+
# Intel Mac
|
| 15 |
+
eval "$(/usr/local/bin/brew shellenv)"
|
| 16 |
+
fi
|
| 17 |
+
fi
|
| 18 |
+
|
| 19 |
+
# 更新 brew 并安装 git
|
| 20 |
+
brew update
|
| 21 |
+
brew install git
|
| 22 |
+
|
| 23 |
+
# 安装 uv (Python 环境管理工具)
|
| 24 |
+
curl -Ls https://astral.sh/uv/install.sh | sh
|
| 25 |
+
|
| 26 |
+
# 确保 uv 在 PATH 中
|
| 27 |
+
export PATH="$HOME/.local/bin:$PATH"
|
| 28 |
+
|
| 29 |
+
# 克隆或进入项目目录
|
| 30 |
+
if [ -f "./web.py" ]; then
|
| 31 |
+
# 已经在目标目录
|
| 32 |
+
:
|
| 33 |
+
elif [ -f "./agy2api/web.py" ]; then
|
| 34 |
+
cd ./agy2api
|
| 35 |
+
else
|
| 36 |
+
git clone https://github.com/su-kaka/agy2api.git
|
| 37 |
+
cd ./agy2api
|
| 38 |
+
fi
|
| 39 |
+
|
| 40 |
+
# 拉取最新代码
|
| 41 |
+
git pull
|
| 42 |
+
|
| 43 |
+
# 创建并同步虚拟环境
|
| 44 |
+
uv sync
|
| 45 |
+
|
| 46 |
+
# 激活虚拟环境
|
| 47 |
+
if [ -f ".venv/bin/activate" ]; then
|
| 48 |
+
source .venv/bin/activate
|
| 49 |
+
else
|
| 50 |
+
echo "❌ 未找到虚拟环境,请检查 uv 是否安装成功"
|
| 51 |
+
exit 1
|
| 52 |
+
fi
|
| 53 |
+
|
| 54 |
+
# 启动项目
|
| 55 |
+
python3 web.py
|
agy2api/dist/assets/index-CqsIYAIJ.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
agy2api/dist/assets/index-xC348ENO.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
*,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:#e5e7eb}:before,:after{--tw-content: ""}html,:host{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-variation-settings:normal;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;letter-spacing:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]:where(:not([hidden=until-found])){display:none}.fixed{position:fixed}.absolute{position:absolute}.relative{position:relative}.sticky{position:sticky}.inset-0{top:0;right:0;bottom:0;left:0}.bottom-full{bottom:100%}.left-0{left:0}.left-0\.5{left:.125rem}.right-0{right:0}.right-3{right:.75rem}.top-0{top:0}.top-0\.5{top:.125rem}.top-1\/2{top:50%}.top-full{top:100%}.z-10{z-index:10}.z-20{z-index:20}.z-30{z-index:30}.z-50{z-index:50}.z-\[60\]{z-index:60}.col-span-3{grid-column:span 3 / span 3}.-mx-1{margin-left:-.25rem;margin-right:-.25rem}.mx-auto{margin-left:auto;margin-right:auto}.mb-1{margin-bottom:.25rem}.mb-1\.5{margin-bottom:.375rem}.mb-2{margin-bottom:.5rem}.mb-3{margin-bottom:.75rem}.mb-4{margin-bottom:1rem}.mb-6{margin-bottom:1.5rem}.mb-8{margin-bottom:2rem}.ml-2{margin-left:.5rem}.mr-2{margin-right:.5rem}.mt-0\.5{margin-top:.125rem}.mt-1{margin-top:.25rem}.mt-1\.5{margin-top:.375rem}.mt-2{margin-top:.5rem}.mt-3{margin-top:.75rem}.mt-4{margin-top:1rem}.block{display:block}.inline-block{display:inline-block}.flex{display:flex}.inline-flex{display:inline-flex}.grid{display:grid}.hidden{display:none}.h-10{height:2.5rem}.h-12{height:3rem}.h-16{height:4rem}.h-2{height:.5rem}.h-4{height:1rem}.h-40{height:10rem}.h-5{height:1.25rem}.h-6{height:1.5rem}.h-7{height:1.75rem}.max-h-56{max-height:14rem}.max-h-60{max-height:15rem}.max-h-64{max-height:16rem}.max-h-96{max-height:24rem}.max-h-\[60vh\]{max-height:60vh}.max-h-\[80vh\]{max-height:80vh}.max-h-\[85vh\]{max-height:85vh}.min-h-screen{min-height:100vh}.w-10{width:2.5rem}.w-11{width:2.75rem}.w-12{width:3rem}.w-16{width:4rem}.w-4{width:1rem}.w-40{width:10rem}.w-5{width:1.25rem}.w-7{width:1.75rem}.w-full{width:100%}.min-w-0{min-width:0px}.max-w-2xl{max-width:42rem}.max-w-4xl{max-width:56rem}.max-w-6xl{max-width:72rem}.max-w-lg{max-width:32rem}.max-w-md{max-width:28rem}.flex-1{flex:1 1 0%}.flex-shrink-0,.shrink-0{flex-shrink:0}.-translate-y-1\/2{--tw-translate-y: -50%;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.translate-x-5{--tw-translate-x: 1.25rem;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.rotate-180{--tw-rotate: 180deg;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}@keyframes pulse{50%{opacity:.5}}.animate-pulse{animation:pulse 2s cubic-bezier(.4,0,.6,1) infinite}@keyframes spin{to{transform:rotate(360deg)}}.animate-spin{animation:spin 1s linear infinite}.cursor-not-allowed{cursor:not-allowed}.cursor-pointer{cursor:pointer}.select-none{-webkit-user-select:none;-moz-user-select:none;user-select:none}.list-inside{list-style-position:inside}.list-decimal{list-style-type:decimal}.grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.items-start{align-items:flex-start}.items-center{align-items:center}.justify-center{justify-content:center}.justify-between{justify-content:space-between}.gap-1{gap:.25rem}.gap-1\.5{gap:.375rem}.gap-2{gap:.5rem}.gap-2\.5{gap:.625rem}.gap-3{gap:.75rem}.gap-4{gap:1rem}.gap-x-3{-moz-column-gap:.75rem;column-gap:.75rem}.gap-y-0\.5{row-gap:.125rem}.gap-y-2{row-gap:.5rem}.space-y-1>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(.25rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.25rem * var(--tw-space-y-reverse))}.space-y-1\.5>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(.375rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.375rem * var(--tw-space-y-reverse))}.space-y-2>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(.5rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.5rem * var(--tw-space-y-reverse))}.space-y-3>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(.75rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(.75rem * var(--tw-space-y-reverse))}.space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(1rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1rem * var(--tw-space-y-reverse))}.space-y-5>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(1.25rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1.25rem * var(--tw-space-y-reverse))}.space-y-6>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(1.5rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1.5rem * var(--tw-space-y-reverse))}.overflow-auto{overflow:auto}.overflow-hidden{overflow:hidden}.overflow-x-auto{overflow-x:auto}.overflow-y-auto{overflow-y:auto}.truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.whitespace-nowrap{white-space:nowrap}.whitespace-pre-wrap{white-space:pre-wrap}.break-all{word-break:break-all}.rounded{border-radius:.25rem}.rounded-2xl{border-radius:1rem}.rounded-full{border-radius:9999px}.rounded-lg{border-radius:.5rem}.rounded-xl{border-radius:.75rem}.border{border-width:1px}.border-2{border-width:2px}.border-b{border-bottom-width:1px}.border-b-2{border-bottom-width:2px}.border-t{border-top-width:1px}.border-dashed{border-style:dashed}.border-amber-500\/20{border-color:#f59e0b33}.border-amber-500\/30{border-color:#f59e0b4d}.border-blue-500\/30{border-color:#3b82f64d}.border-blue-500\/40{border-color:#3b82f666}.border-dark-600{--tw-border-opacity: 1;border-color:rgb(71 85 105 / var(--tw-border-opacity, 1))}.border-dark-700{--tw-border-opacity: 1;border-color:rgb(51 65 85 / var(--tw-border-opacity, 1))}.border-emerald-700\/30{border-color:#0478574d}.border-green-500\/30{border-color:#22c55e4d}.border-green-500\/40{border-color:#22c55e66}.border-orange-700\/30{border-color:#c2410c4d}.border-purple-500{--tw-border-opacity: 1;border-color:rgb(168 85 247 / var(--tw-border-opacity, 1))}.border-purple-500\/30{border-color:#a855f74d}.border-purple-500\/50{border-color:#a855f780}.border-red-500\/20{border-color:#ef444433}.border-red-500\/30{border-color:#ef44444d}.border-red-500\/40{border-color:#ef444466}.border-red-700\/30{border-color:#b91c1c4d}.border-white{--tw-border-opacity: 1;border-color:rgb(255 255 255 / var(--tw-border-opacity, 1))}.bg-amber-500\/10{background-color:#f59e0b1a}.bg-amber-500\/15{background-color:#f59e0b26}.bg-amber-600\/20{background-color:#d9770633}.bg-black\/60{background-color:#0009}.bg-black\/70{background-color:#000000b3}.bg-blue-500\/10{background-color:#3b82f61a}.bg-blue-500\/15{background-color:#3b82f626}.bg-blue-600\/20{background-color:#2563eb33}.bg-dark-600{--tw-bg-opacity: 1;background-color:rgb(71 85 105 / var(--tw-bg-opacity, 1))}.bg-dark-700{--tw-bg-opacity: 1;background-color:rgb(51 65 85 / var(--tw-bg-opacity, 1))}.bg-dark-800{--tw-bg-opacity: 1;background-color:rgb(30 41 59 / var(--tw-bg-opacity, 1))}.bg-dark-800\/60{background-color:#1e293b99}.bg-dark-900{--tw-bg-opacity: 1;background-color:rgb(15 23 42 / var(--tw-bg-opacity, 1))}.bg-dark-900\/60{background-color:#0f172a99}.bg-dark-950\/95{background-color:#020617f2}.bg-emerald-600\/20{background-color:#05966933}.bg-emerald-900\/20{background-color:#064e3b33}.bg-green-500{--tw-bg-opacity: 1;background-color:rgb(34 197 94 / var(--tw-bg-opacity, 1))}.bg-green-500\/10{background-color:#22c55e1a}.bg-green-500\/15{background-color:#22c55e26}.bg-green-600\/20{background-color:#16a34a33}.bg-orange-500{--tw-bg-opacity: 1;background-color:rgb(249 115 22 / var(--tw-bg-opacity, 1))}.bg-purple-500\/10{background-color:#a855f71a}.bg-purple-600{--tw-bg-opacity: 1;background-color:rgb(147 51 234 / var(--tw-bg-opacity, 1))}.bg-purple-600\/20{background-color:#9333ea33}.bg-red-500{--tw-bg-opacity: 1;background-color:rgb(239 68 68 / var(--tw-bg-opacity, 1))}.bg-red-500\/10{background-color:#ef44441a}.bg-red-500\/15{background-color:#ef444426}.bg-red-600{--tw-bg-opacity: 1;background-color:rgb(220 38 38 / var(--tw-bg-opacity, 1))}.bg-red-600\/10{background-color:#dc26261a}.bg-red-600\/20{background-color:#dc262633}.bg-red-900\/20{background-color:#7f1d1d33}.bg-white{--tw-bg-opacity: 1;background-color:rgb(255 255 255 / var(--tw-bg-opacity, 1))}.bg-yellow-500{--tw-bg-opacity: 1;background-color:rgb(234 179 8 / var(--tw-bg-opacity, 1))}.bg-gradient-to-br{background-image:linear-gradient(to bottom right,var(--tw-gradient-stops))}.from-emerald-900\/30{--tw-gradient-from: rgb(6 78 59 / .3) var(--tw-gradient-from-position);--tw-gradient-to: rgb(6 78 59 / 0) var(--tw-gradient-to-position);--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to)}.from-orange-900\/30{--tw-gradient-from: rgb(124 45 18 / .3) var(--tw-gradient-from-position);--tw-gradient-to: rgb(124 45 18 / 0) var(--tw-gradient-to-position);--tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to)}.to-emerald-800\/10{--tw-gradient-to: rgb(6 95 70 / .1) var(--tw-gradient-to-position)}.to-orange-800\/10{--tw-gradient-to: rgb(154 52 18 / .1) var(--tw-gradient-to-position)}.p-0{padding:0}.p-1\.5{padding:.375rem}.p-10{padding:2.5rem}.p-2{padding:.5rem}.p-2\.5{padding:.625rem}.p-3{padding:.75rem}.p-4{padding:1rem}.p-5{padding:1.25rem}.p-8{padding:2rem}.px-1{padding-left:.25rem;padding-right:.25rem}.px-1\.5{padding-left:.375rem;padding-right:.375rem}.px-2{padding-left:.5rem;padding-right:.5rem}.px-3{padding-left:.75rem;padding-right:.75rem}.px-4{padding-left:1rem;padding-right:1rem}.py-0\.5{padding-top:.125rem;padding-bottom:.125rem}.py-1{padding-top:.25rem;padding-bottom:.25rem}.py-1\.5{padding-top:.375rem;padding-bottom:.375rem}.py-12{padding-top:3rem;padding-bottom:3rem}.py-2{padding-top:.5rem;padding-bottom:.5rem}.py-2\.5{padding-top:.625rem;padding-bottom:.625rem}.py-3{padding-top:.75rem;padding-bottom:.75rem}.py-4{padding-top:1rem;padding-bottom:1rem}.py-6{padding-top:1.5rem;padding-bottom:1.5rem}.py-8{padding-top:2rem;padding-bottom:2rem}.pb-1{padding-bottom:.25rem}.pb-1\.5{padding-bottom:.375rem}.pb-3{padding-bottom:.75rem}.pb-4{padding-bottom:1rem}.pr-12{padding-right:3rem}.pt-1{padding-top:.25rem}.pt-2{padding-top:.5rem}.text-left{text-align:left}.text-center{text-align:center}.text-right{text-align:right}.font-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}.text-2xl{font-size:1.5rem;line-height:2rem}.text-3xl{font-size:1.875rem;line-height:2.25rem}.text-base{font-size:1rem;line-height:1.5rem}.text-lg{font-size:1.125rem;line-height:1.75rem}.text-sm{font-size:.875rem;line-height:1.25rem}.text-xl{font-size:1.25rem;line-height:1.75rem}.text-xs{font-size:.75rem;line-height:1rem}.font-bold{font-weight:700}.font-medium{font-weight:500}.font-semibold{font-weight:600}.leading-relaxed{line-height:1.625}.leading-snug{line-height:1.375}.text-amber-400{--tw-text-opacity: 1;color:rgb(251 191 36 / var(--tw-text-opacity, 1))}.text-amber-400\/80{color:#fbbf24cc}.text-blue-400{--tw-text-opacity: 1;color:rgb(96 165 250 / var(--tw-text-opacity, 1))}.text-cyan-400{--tw-text-opacity: 1;color:rgb(34 211 238 / var(--tw-text-opacity, 1))}.text-emerald-300\/80{color:#6ee7b7cc}.text-emerald-400{--tw-text-opacity: 1;color:rgb(52 211 153 / var(--tw-text-opacity, 1))}.text-emerald-500\/80{color:#10b981cc}.text-gray-200{--tw-text-opacity: 1;color:rgb(229 231 235 / var(--tw-text-opacity, 1))}.text-gray-300{--tw-text-opacity: 1;color:rgb(209 213 219 / var(--tw-text-opacity, 1))}.text-gray-400{--tw-text-opacity: 1;color:rgb(156 163 175 / var(--tw-text-opacity, 1))}.text-gray-500{--tw-text-opacity: 1;color:rgb(107 114 128 / var(--tw-text-opacity, 1))}.text-gray-600{--tw-text-opacity: 1;color:rgb(75 85 99 / var(--tw-text-opacity, 1))}.text-green-400{--tw-text-opacity: 1;color:rgb(74 222 128 / var(--tw-text-opacity, 1))}.text-orange-400{--tw-text-opacity: 1;color:rgb(251 146 60 / var(--tw-text-opacity, 1))}.text-purple-300{--tw-text-opacity: 1;color:rgb(216 180 254 / var(--tw-text-opacity, 1))}.text-purple-400{--tw-text-opacity: 1;color:rgb(192 132 252 / var(--tw-text-opacity, 1))}.text-purple-500{--tw-text-opacity: 1;color:rgb(168 85 247 / var(--tw-text-opacity, 1))}.text-red-300{--tw-text-opacity: 1;color:rgb(252 165 165 / var(--tw-text-opacity, 1))}.text-red-400{--tw-text-opacity: 1;color:rgb(248 113 113 / var(--tw-text-opacity, 1))}.text-white{--tw-text-opacity: 1;color:rgb(255 255 255 / var(--tw-text-opacity, 1))}.text-yellow-400{--tw-text-opacity: 1;color:rgb(250 204 21 / var(--tw-text-opacity, 1))}.placeholder-gray-500::-moz-placeholder{--tw-placeholder-opacity: 1;color:rgb(107 114 128 / var(--tw-placeholder-opacity, 1))}.placeholder-gray-500::placeholder{--tw-placeholder-opacity: 1;color:rgb(107 114 128 / var(--tw-placeholder-opacity, 1))}.accent-purple-600{accent-color:#9333ea}.opacity-40{opacity:.4}.shadow-xl{--tw-shadow: 0 20px 25px -5px rgb(0 0 0 / .1), 0 8px 10px -6px rgb(0 0 0 / .1);--tw-shadow-colored: 0 20px 25px -5px var(--tw-shadow-color), 0 8px 10px -6px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow, 0 0 #0000),var(--tw-ring-shadow, 0 0 #0000),var(--tw-shadow)}.ring-2{--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)}.ring-purple-500\/50{--tw-ring-color: rgb(168 85 247 / .5)}.filter{filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.backdrop-blur{--tw-backdrop-blur: blur(8px);-webkit-backdrop-filter:var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia);backdrop-filter:var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia)}.transition-colors{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-transform{transition-property:transform;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.duration-200{transition-duration:.2s}body{--tw-bg-opacity: 1;background-color:rgb(2 6 23 / var(--tw-bg-opacity, 1));--tw-text-opacity: 1;color:rgb(243 244 246 / var(--tw-text-opacity, 1));font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif}::-webkit-scrollbar{width:8px;height:8px}::-webkit-scrollbar-track{--tw-bg-opacity: 1;background-color:rgb(15 23 42 / var(--tw-bg-opacity, 1))}::-webkit-scrollbar-thumb{border-radius:9999px;--tw-bg-opacity: 1;background-color:rgb(71 85 105 / var(--tw-bg-opacity, 1))}::-webkit-scrollbar-thumb:hover{--tw-bg-opacity: 1;background-color:rgb(100 116 139 / var(--tw-bg-opacity, 1))}input:focus,textarea:focus,select:focus{outline:2px solid transparent;outline-offset:2px;--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000);--tw-ring-color: rgb(168 85 247 / .5)}.btn{border-radius:.5rem;padding:.5rem 1rem;font-weight:500;transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.2s}.btn-primary{--tw-bg-opacity: 1;background-color:rgb(147 51 234 / var(--tw-bg-opacity, 1));--tw-text-opacity: 1;color:rgb(255 255 255 / var(--tw-text-opacity, 1))}.btn-primary:hover{--tw-bg-opacity: 1;background-color:rgb(126 34 206 / var(--tw-bg-opacity, 1))}.btn-secondary{--tw-bg-opacity: 1;background-color:rgb(51 65 85 / var(--tw-bg-opacity, 1));--tw-text-opacity: 1;color:rgb(229 231 235 / var(--tw-text-opacity, 1))}.btn-secondary:hover{--tw-bg-opacity: 1;background-color:rgb(71 85 105 / var(--tw-bg-opacity, 1))}.btn-danger{--tw-bg-opacity: 1;background-color:rgb(220 38 38 / var(--tw-bg-opacity, 1));--tw-text-opacity: 1;color:rgb(255 255 255 / var(--tw-text-opacity, 1))}.btn-danger:hover{--tw-bg-opacity: 1;background-color:rgb(185 28 28 / var(--tw-bg-opacity, 1))}.card{border-radius:.75rem;border-width:1px;--tw-border-opacity: 1;border-color:rgb(51 65 85 / var(--tw-border-opacity, 1));--tw-bg-opacity: 1;background-color:rgb(15 23 42 / var(--tw-bg-opacity, 1));padding:1.5rem}.table-container{overflow-x:auto;border-radius:.5rem;border-width:1px;--tw-border-opacity: 1;border-color:rgb(51 65 85 / var(--tw-border-opacity, 1))}table{width:100%}th{--tw-bg-opacity: 1;background-color:rgb(30 41 59 / var(--tw-bg-opacity, 1));padding:.75rem 1rem;text-align:left;font-size:.875rem;line-height:1.25rem;font-weight:500;--tw-text-opacity: 1;color:rgb(156 163 175 / var(--tw-text-opacity, 1))}td{border-top-width:1px;--tw-border-opacity: 1;border-color:rgb(51 65 85 / var(--tw-border-opacity, 1));padding:.75rem 1rem;font-size:.875rem;line-height:1.25rem}tr:hover td{background-color:#1e293b80}.hover\:border-dark-500:hover{--tw-border-opacity: 1;border-color:rgb(100 116 139 / var(--tw-border-opacity, 1))}.hover\:border-purple-500\/40:hover{border-color:#a855f766}.hover\:bg-amber-600\/30:hover{background-color:#d977064d}.hover\:bg-dark-600:hover{--tw-bg-opacity: 1;background-color:rgb(71 85 105 / var(--tw-bg-opacity, 1))}.hover\:bg-dark-700:hover{--tw-bg-opacity: 1;background-color:rgb(51 65 85 / var(--tw-bg-opacity, 1))}.hover\:bg-emerald-600\/30:hover{background-color:#0596694d}.hover\:bg-red-600\/20:hover{background-color:#dc262633}.hover\:bg-red-700:hover{--tw-bg-opacity: 1;background-color:rgb(185 28 28 / var(--tw-bg-opacity, 1))}.hover\:text-blue-300:hover{--tw-text-opacity: 1;color:rgb(147 197 253 / var(--tw-text-opacity, 1))}.hover\:text-gray-200:hover{--tw-text-opacity: 1;color:rgb(229 231 235 / var(--tw-text-opacity, 1))}.hover\:text-gray-300:hover{--tw-text-opacity: 1;color:rgb(209 213 219 / var(--tw-text-opacity, 1))}.hover\:text-purple-300:hover{--tw-text-opacity: 1;color:rgb(216 180 254 / var(--tw-text-opacity, 1))}.hover\:text-red-300:hover{--tw-text-opacity: 1;color:rgb(252 165 165 / var(--tw-text-opacity, 1))}.hover\:text-red-400:hover{--tw-text-opacity: 1;color:rgb(248 113 113 / var(--tw-text-opacity, 1))}.hover\:text-white:hover{--tw-text-opacity: 1;color:rgb(255 255 255 / var(--tw-text-opacity, 1))}.focus\:outline-none:focus{outline:2px solid transparent;outline-offset:2px}.focus\:ring-2:focus{--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 #0000)}.focus\:ring-purple-500\/50:focus{--tw-ring-color: rgb(168 85 247 / .5)}.disabled\:opacity-40:disabled{opacity:.4}.disabled\:opacity-50:disabled{opacity:.5}@media (min-width: 640px){.sm\:inline{display:inline}.sm\:flex{display:flex}.sm\:w-24{width:6rem}.sm\:w-28{width:7rem}.sm\:w-32{width:8rem}.sm\:w-40{width:10rem}.sm\:w-64{width:16rem}.sm\:flex-row{flex-direction:row}.sm\:flex-wrap{flex-wrap:wrap}.sm\:items-center{align-items:center}.sm\:gap-2{gap:.5rem}.sm\:gap-3{gap:.75rem}.sm\:gap-4{gap:1rem}.sm\:space-y-6>:not([hidden])~:not([hidden]){--tw-space-y-reverse: 0;margin-top:calc(1.5rem * calc(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1.5rem * var(--tw-space-y-reverse))}.sm\:p-4{padding:1rem}.sm\:p-5{padding:1.25rem}.sm\:p-6{padding:1.5rem}.sm\:px-4{padding-left:1rem;padding-right:1rem}.sm\:px-5{padding-left:1.25rem;padding-right:1.25rem}.sm\:py-2{padding-top:.5rem;padding-bottom:.5rem}.sm\:text-2xl{font-size:1.5rem;line-height:2rem}.sm\:text-base{font-size:1rem;line-height:1.5rem}.sm\:text-sm{font-size:.875rem;line-height:1.25rem}}@media (min-width: 768px){.md\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}}@media (min-width: 1024px){.lg\:grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}}@media (min-width: 1280px){.xl\:grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}}
|
agy2api/dist/favicon-32.png
ADDED
|
|
agy2api/dist/favicon.ico
ADDED
|
|
agy2api/dist/index.html
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="zh-CN" class="dark">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<link rel="icon" href="./favicon.ico" type="image/x-icon" />
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
+
<title>AGY2API - Antigravity 控制面板</title>
|
| 8 |
+
<script>
|
| 9 |
+
// 反代把面板挂在子路径下时,访问地址可能不带末尾斜杠(如 /AGY2API),
|
| 10 |
+
// 相对路径资源会因此解析到根域;此处补齐为目录形式,保证资源请求落在同一子路径内。
|
| 11 |
+
// 需置于模块脚本之前:模块脚本加载失败时内联脚本仍会执行,跳转后才能正确加载
|
| 12 |
+
if (!location.pathname.endsWith("/")) {
|
| 13 |
+
location.replace(
|
| 14 |
+
location.pathname + "/" + location.search + location.hash
|
| 15 |
+
);
|
| 16 |
+
}
|
| 17 |
+
</script>
|
| 18 |
+
<script type="module" crossorigin src="./assets/index-CqsIYAIJ.js"></script>
|
| 19 |
+
<link rel="stylesheet" crossorigin href="./assets/index-xC348ENO.css">
|
| 20 |
+
</head>
|
| 21 |
+
<body class="dark">
|
| 22 |
+
<div id="root"></div>
|
| 23 |
+
</body>
|
| 24 |
+
</html>
|
agy2api/docker-compose.yml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
agy2api:
|
| 5 |
+
image: ghcr.io/su-kaka/agy2api:latest
|
| 6 |
+
container_name: agy2api
|
| 7 |
+
restart: unless-stopped
|
| 8 |
+
network_mode: host
|
| 9 |
+
environment:
|
| 10 |
+
# 密码配置(分离密码)
|
| 11 |
+
- API_PASSWORD=${API_PASSWORD:-your_api_password}
|
| 12 |
+
- PANEL_PASSWORD=${PANEL_PASSWORD:-your_panel_password}
|
| 13 |
+
|
| 14 |
+
# 服务器配置
|
| 15 |
+
- PORT=${PORT:-7861}
|
| 16 |
+
- HOST=${HOST:-0.0.0.0}
|
| 17 |
+
|
| 18 |
+
# 可选: PostgreSQL 配置 (分布式存储)
|
| 19 |
+
# - POSTGRESQL_URI=${POSTGRESQL_URI}
|
| 20 |
+
|
| 21 |
+
# 可选: 代理配置
|
| 22 |
+
# - PROXY=${PROXY}
|
| 23 |
+
volumes:
|
| 24 |
+
- ./data/creds:/app/cre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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AGY2API
|
| 2 |
+
|
| 3 |
+
**Convert Google Antigravity to OpenAI, Gemini, and Claude API Compatible Interfaces**
|
| 4 |
+
|
| 5 |
+
[](https://www.python.org/downloads/)
|
| 6 |
+
[](../LICENSE)
|
| 7 |
+
[](https://github.com/su-kaka/agy2api/pkgs/container/agy2api)
|
| 8 |
+
|
| 9 |
+
[中文](../README.md) | English | [日本語](./README_JA.md)
|
| 10 |
+
|
| 11 |
+
> **⚠️ Important Change**: The GeminiCLI endpoint has been deprecated by Google. All GeminiCLI-related code has been completely removed; only the Antigravity mode remains.
|
| 12 |
+
|
| 13 |
+
## Installation Guide
|
| 14 |
+
|
| 15 |
+
### Termux Environment
|
| 16 |
+
|
| 17 |
+
**Initial Installation**
|
| 18 |
+
```bash
|
| 19 |
+
curl -o termux-install.sh "https://raw.githubusercontent.com/su-kaka/agy2api/refs/heads/master/termux-install.sh" && chmod +x termux-install.sh && ./termux-install.sh
|
| 20 |
+
```
|
| 21 |
+
|
| 22 |
+
**Restart Service**
|
| 23 |
+
```bash
|
| 24 |
+
cd agy2api
|
| 25 |
+
bash termux-start.sh
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
### Windows Environment
|
| 29 |
+
|
| 30 |
+
**Initial Installation**
|
| 31 |
+
```powershell
|
| 32 |
+
iex (iwr "https://raw.githubusercontent.com/su-kaka/agy2api/refs/heads/master/install.ps1" -UseBasicParsing).Content
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
**Restart Service**
|
| 36 |
+
Double-click to execute `start.bat`
|
| 37 |
+
|
| 38 |
+
### Linux Environment
|
| 39 |
+
|
| 40 |
+
**Initial Installation**
|
| 41 |
+
```bash
|
| 42 |
+
curl -o install.sh "https://raw.githubusercontent.com/su-kaka/agy2api/refs/heads/master/install.sh" && chmod +x install.sh && ./install.sh
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
**Restart Service**
|
| 46 |
+
```bash
|
| 47 |
+
cd agy2api
|
| 48 |
+
bash start.sh
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
### macOS Environment
|
| 52 |
+
|
| 53 |
+
**Initial Installation**
|
| 54 |
+
```bash
|
| 55 |
+
curl -o darwin-install.sh "https://raw.githubusercontent.com/su-kaka/agy2api/refs/heads/master/darwin-install.sh" && chmod +x darwin-install.sh && ./darwin-install.sh
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
**Restart Service**
|
| 59 |
+
```bash
|
| 60 |
+
cd agy2api
|
| 61 |
+
bash start.sh
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
### Docker Environment
|
| 65 |
+
|
| 66 |
+
**Docker Run Command**
|
| 67 |
+
```bash
|
| 68 |
+
docker run -d --name agy2api --network host -e API_PASSWORD=api_pwd -e PANEL_PASSWORD=panel_pwd -e PORT=7861 -v $(pwd)/data/creds:/app/creds -v $(pwd)/data/request_logs:/app/data/request_logs ghcr.io/su-kaka/agy2api:latest
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
**Docker Mac**
|
| 72 |
+
```bash
|
| 73 |
+
docker run -d \
|
| 74 |
+
--name agy2api \
|
| 75 |
+
-p 7861:7861 \
|
| 76 |
+
-p 8080:8080 \
|
| 77 |
+
-e API_PASSWORD=api_pwd \
|
| 78 |
+
-e PANEL_PASSWORD=panel_pwd \
|
| 79 |
+
-e PORT=7861 \
|
| 80 |
+
-v "$(pwd)/data/creds":/app/creds \
|
| 81 |
+
-v "$(pwd)/data/request_logs":/app/data/request_logs \
|
| 82 |
+
ghcr.io/su-kaka/agy2api:latest
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
**Docker Compose Run Command**
|
| 86 |
+
1. Save the following content as `docker-compose.yml` file:
|
| 87 |
+
```yaml
|
| 88 |
+
version: '3.8'
|
| 89 |
+
|
| 90 |
+
services:
|
| 91 |
+
agy2api:
|
| 92 |
+
image: ghcr.io/su-kaka/agy2api:latest
|
| 93 |
+
container_name: agy2api
|
| 94 |
+
restart: unless-stopped
|
| 95 |
+
network_mode: host
|
| 96 |
+
environment:
|
| 97 |
+
# Password configuration (separate passwords)
|
| 98 |
+
- API_PASSWORD=your_api_password
|
| 99 |
+
- PANEL_PASSWORD=your_panel_password
|
| 100 |
+
- PORT=7861
|
| 101 |
+
volumes:
|
| 102 |
+
- ./data/creds:/app/creds
|
| 103 |
+
- ./data/request_logs:/app/data/request_logs
|
| 104 |
+
healthcheck:
|
| 105 |
+
test: ["CMD-SHELL", "python -c \"import sys, urllib.request, os; port = os.environ.get('PORT', '7861'); req = urllib.request.Request(f'http://localhost:{port}/v1/models', headers={'Authorization': 'Bearer ' + os.environ.get('API_PASSWORD', 'pwd')}); sys.exit(0 if urllib.request.urlopen(req, timeout=5).getcode() == 200 else 1)\""]
|
| 106 |
+
interval: 30s
|
| 107 |
+
timeout: 10s
|
| 108 |
+
retries: 3
|
| 109 |
+
start_period: 40s
|
| 110 |
+
```
|
| 111 |
+
2. Start the service:
|
| 112 |
+
```bash
|
| 113 |
+
docker-compose up -d
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
## Core Features
|
| 117 |
+
|
| 118 |
+
### 🔄 API Endpoints and Format Support
|
| 119 |
+
|
| 120 |
+
**Multi-endpoint Multi-format Support**
|
| 121 |
+
- **OpenAI Compatible Endpoints**: `/v1/chat/completions` and `/v1/models`
|
| 122 |
+
- Supports standard OpenAI format (messages structure)
|
| 123 |
+
- Supports Gemini native format (contents structure)
|
| 124 |
+
- Automatic format detection and conversion, no manual switching required
|
| 125 |
+
- Supports multimodal input (text + images)
|
| 126 |
+
- **Gemini Native Endpoints**: `/v1/models/{model}:generateContent` and `streamGenerateContent`
|
| 127 |
+
- Supports complete Gemini native API specifications
|
| 128 |
+
- Multiple authentication methods: Bearer Token, x-goog-api-key header, URL parameter key
|
| 129 |
+
- **Claude Format Compatibility**: Full support for Claude API format
|
| 130 |
+
- Endpoint: `/v1/messages` (follows Claude API specification)
|
| 131 |
+
- Supports Claude standard messages format
|
| 132 |
+
- Supports system parameter and Claude-specific features
|
| 133 |
+
- Automatically converts to backend-supported format
|
| 134 |
+
- **Antigravity API Support**: Supports OpenAI, Gemini, and Claude formats
|
| 135 |
+
- OpenAI format endpoint: `/v1/chat/completions`
|
| 136 |
+
- Gemini format endpoint: `/v1/models/{model}:generateContent` and `streamGenerateContent`
|
| 137 |
+
- Claude format endpoint: `/v1/messages`
|
| 138 |
+
- Supports all Antigravity models (Claude, Gemini, etc.)
|
| 139 |
+
- Automatic model name mapping and thinking mode detection
|
| 140 |
+
|
| 141 |
+
### 🔐 Authentication and Security Management
|
| 142 |
+
|
| 143 |
+
**Flexible Password Management**
|
| 144 |
+
- **Separate Password Support**: API password (chat endpoints) and control panel password can be set independently
|
| 145 |
+
- **Multiple Authentication Methods**: Supports Authorization Bearer, x-goog-api-key header, URL parameters, etc.
|
| 146 |
+
- **JWT Token Authentication**: Control panel supports JWT token authentication
|
| 147 |
+
- **User Email Retrieval**: Automatically retrieves and displays Google account email addresses
|
| 148 |
+
|
| 149 |
+
### 📊 Intelligent Credential Management System
|
| 150 |
+
|
| 151 |
+
**Advanced Credential Management**
|
| 152 |
+
- Multiple Google OAuth credential automatic rotation
|
| 153 |
+
- Enhanced stability through redundant authentication
|
| 154 |
+
- Load balancing and concurrent request support
|
| 155 |
+
- Automatic failure detection and credential disabling
|
| 156 |
+
- Credential usage statistics and quota management
|
| 157 |
+
- Credentials keyed by email (unique); re-importing the same email overwrites automatically
|
| 158 |
+
- Batch operations (enable, disable, delete)
|
| 159 |
+
|
| 160 |
+
**Credential Status Monitoring**
|
| 161 |
+
- Real-time credential health checks
|
| 162 |
+
- Error code tracking (429, 403, 500, etc.)
|
| 163 |
+
- Automatic banning mechanism (configurable)
|
| 164 |
+
|
| 165 |
+
### 🌊 Streaming and Response Processing
|
| 166 |
+
|
| 167 |
+
**Multiple Streaming Support**
|
| 168 |
+
- True real-time streaming responses
|
| 169 |
+
- Streaming anti-truncation feature (prevents answer truncation)
|
| 170 |
+
- Asynchronous task management and timeout handling
|
| 171 |
+
|
| 172 |
+
**Response Optimization**
|
| 173 |
+
- Thinking chain content separation
|
| 174 |
+
- Reasoning process (reasoning_content) handling
|
| 175 |
+
- Multi-turn conversation context management
|
| 176 |
+
|
| 177 |
+
### 🎛️ Web Management Console
|
| 178 |
+
|
| 179 |
+
**Full-featured Web Interface**
|
| 180 |
+
- Antigravity OAuth authentication flow (with callback URL shortcut)
|
| 181 |
+
- Credential file upload, download, and management
|
| 182 |
+
- System configuration management
|
| 183 |
+
- Usage statistics and monitoring dashboard
|
| 184 |
+
- Mobile-friendly interface
|
| 185 |
+
|
| 186 |
+
**Batch Operation Support**
|
| 187 |
+
- ZIP/JSON batch credential upload (Antigravity)
|
| 188 |
+
- Batch enable/disable/delete credentials
|
| 189 |
+
- Batch user email retrieval
|
| 190 |
+
- Batch configuration management
|
| 191 |
+
- Unified batch upload interface for all credential types
|
| 192 |
+
|
| 193 |
+
### 🔧 Advanced Configuration and Customization
|
| 194 |
+
|
| 195 |
+
**Network and Proxy Configuration**
|
| 196 |
+
- HTTP/HTTPS proxy support
|
| 197 |
+
- Proxy endpoint configuration (OAuth, Google APIs, metadata service)
|
| 198 |
+
- Timeout and retry configuration
|
| 199 |
+
- Network error handling and recovery
|
| 200 |
+
|
| 201 |
+
**Performance and Stability Configuration**
|
| 202 |
+
- 429 error automatic retry (configurable interval and attempts)
|
| 203 |
+
- Anti-truncation maximum retry attempts
|
| 204 |
+
|
| 205 |
+
**Logging and Debugging**
|
| 206 |
+
- Multi-level logging system (DEBUG, INFO, WARNING, ERROR)
|
| 207 |
+
- Console-only logging (`ENABLE_LOG=0` for full silence)
|
| 208 |
+
|
| 209 |
+
### 🔄 Environment Variables and Configuration Management
|
| 210 |
+
|
| 211 |
+
**Flexible Configuration Methods**
|
| 212 |
+
- Environment variable configuration
|
| 213 |
+
- Hot configuration updates (partial configuration items)
|
| 214 |
+
- Configuration locking (environment variable priority)
|
| 215 |
+
|
| 216 |
+
## Supported Models
|
| 217 |
+
|
| 218 |
+
All models have 1M context window capacity. Each credential file provides 1000 request quota.
|
| 219 |
+
|
| 220 |
+
### 🤖 Base Models
|
| 221 |
+
- `gemini-2.5-pro`
|
| 222 |
+
- `gemini-3-pro-preview`
|
| 223 |
+
- `gemini-3.1-pro-preview`
|
| 224 |
+
|
| 225 |
+
### 🧠 Thinking Models
|
| 226 |
+
- `gemini-2.5-pro-high`: Thinking mode
|
| 227 |
+
- `gemini-2.5-pro-low`: Low thinking mode
|
| 228 |
+
- Supports custom thinking budget configuration
|
| 229 |
+
- Automatic separation of thinking content and final answers
|
| 230 |
+
|
| 231 |
+
### 🔍 Search-Enhanced Models
|
| 232 |
+
- `gemini-2.5-pro-search`: Model with integrated search functionality
|
| 233 |
+
|
| 234 |
+
### 🖼️ Image Generation Models (Antigravity)
|
| 235 |
+
- `gemini-3.1-flash-image`: Base image generation model
|
| 236 |
+
- **Resolution Suffixes**:
|
| 237 |
+
- `-2k`: 2K resolution
|
| 238 |
+
- `-4k`: 4K HD resolution
|
| 239 |
+
- **Aspect Ratio Suffixes**:
|
| 240 |
+
- `-1x1`: Square (avatar)
|
| 241 |
+
- `-16x9`: Landscape (desktop wallpaper)
|
| 242 |
+
- `-9x16`: Portrait (mobile wallpaper)
|
| 243 |
+
- `-21x9`: Ultra-wide (ultrawide monitor)
|
| 244 |
+
- `-4x3`: Traditional display
|
| 245 |
+
- `-3x4`: Portrait poster
|
| 246 |
+
- **Combination Examples**:
|
| 247 |
+
- `gemini-3.1-flash-image-4k-16x9`: 4K landscape
|
| 248 |
+
- `gemini-3.1-flash-image-2k-9x16`: 2K portrait
|
| 249 |
+
- When no ratio is specified, the API automatically decides the aspect ratio
|
| 250 |
+
|
| 251 |
+
### 🌊 Special Feature Variants
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
- **Anti-truncation Mode**: Add `抗截断-` prefix to model name
|
| 256 |
+
- Example: `抗截断-gemini-2.5-pro`
|
| 257 |
+
- Uses synthetic tool calls to bypass truncation limits and ensure complete answers (works for both streaming and non-streaming)
|
| 258 |
+
|
| 259 |
+
### 🔧 Automatic Model Feature Detection
|
| 260 |
+
- System automatically recognizes feature identifiers in model names
|
| 261 |
+
- Transparently handles feature mode transitions
|
| 262 |
+
- Supports feature combination usage
|
| 263 |
+
|
| 264 |
+
---
|
| 265 |
+
|
| 266 |
+
## Configuration Instructions
|
| 267 |
+
|
| 268 |
+
1. Visit `http://127.0.0.1:7861` (default port, modifiable via PORT environment variable)
|
| 269 |
+
2. Complete OAuth authentication flow (default password: `pwd`, modifiable via environment variables)
|
| 270 |
+
3. Configure client:
|
| 271 |
+
|
| 272 |
+
**OpenAI Compatible Client:**
|
| 273 |
+
- **Endpoint Address**: `http://127.0.0.1:7861/v1`
|
| 274 |
+
- **API Key**: `pwd` (default value, modifiable via API_PASSWORD environment variable)
|
| 275 |
+
|
| 276 |
+
**Gemini Native Client:**
|
| 277 |
+
- **Endpoint Address**: `http://127.0.0.1:7861`
|
| 278 |
+
- **Authentication Methods**:
|
| 279 |
+
- `Authorization: Bearer your_api_password`
|
| 280 |
+
- `x-goog-api-key: your_api_password`
|
| 281 |
+
- URL parameter: `?key=your_api_password`
|
| 282 |
+
|
| 283 |
+
## 💾 Data Storage Mode
|
| 284 |
+
|
| 285 |
+
### 🌟 Storage Backend Support
|
| 286 |
+
|
| 287 |
+
agy2api supports two storage backends: **Local SQLite (Default)** and **PostgreSQL (Cloud Distributed Storage)**
|
| 288 |
+
|
| 289 |
+
### 📁 Local SQLite Storage (Default)
|
| 290 |
+
|
| 291 |
+
**Default Storage Method**
|
| 292 |
+
- No configuration required, works out of the box
|
| 293 |
+
- Data is stored in a local SQLite database (`creds/credentials.db`)
|
| 294 |
+
- Suitable for single-machine deployment and personal use
|
| 295 |
+
|
| 296 |
+
**Credential Structure**
|
| 297 |
+
|
| 298 |
+
Credentials are stored as structured database columns (no JSON blobs), keyed uniquely by **email**:
|
| 299 |
+
`email`, `access_token`, `refresh_token`, `client_id`, `client_secret`, `project_id`, `expiry`, `tier`
|
| 300 |
+
|
| 301 |
+
Import/export uses a standardized JSON format: `{"refresh_token": "...", "access_token": "...", "expiry": "...", "email": "...", "tier": "...", "project_id": "..."}` (only `refresh_token` is required; an unexpired `access_token` is reused directly; the rest are fetched automatically).
|
| 302 |
+
|
| 303 |
+
### Environment Variable Configuration
|
| 304 |
+
|
| 305 |
+
**Basic Configuration**
|
| 306 |
+
- `PORT`: Service port (default: 7861)
|
| 307 |
+
- `HOST`: Server listen address (default: 0.0.0.0)
|
| 308 |
+
|
| 309 |
+
**Password Configuration**
|
| 310 |
+
- `API_PASSWORD`: Chat API access password (default: pwd)
|
| 311 |
+
- `PANEL_PASSWORD`: Control panel access password (default: pwd)
|
| 312 |
+
|
| 313 |
+
**Access Control Configuration**
|
| 314 |
+
- `IP_WHITELIST_ENABLED`: Enable IP whitelist (default: false, no restriction)
|
| 315 |
+
- `IP_WHITELIST`: IP whitelist, comma or newline separated (default: empty). Each entry supports a single IP (`192.168.1.1`), CIDR range (`192.168.1.0/24`), or start-end range (`10.0.0.1-10.0.0.100`), for both IPv4 / IPv6. Once enabled, only whitelisted IPs can access the panel and API; all others get 403. Effective immediately after panel save
|
| 316 |
+
|
| 317 |
+
**Model Name Rewrite**
|
| 318 |
+
- `MODEL_REWRITE_ENABLED`: Enable model name rewriting (default: false)
|
| 319 |
+
- `MODEL_REWRITE_RULES`: Rewrite rules, each `[match regex, replacement model name]` (default: empty). First match from top wins; replacements support regex backreferences (e.g. `\1`). Example: map `gpt-4o` to `gemini-2.5-pro`. Effective immediately after panel save
|
| 320 |
+
|
| 321 |
+
**Performance and Stability Configuration**
|
| 322 |
+
- `RETRY_429_ENABLED`: Enable 429 error automatic retry (default: true)
|
| 323 |
+
- `RETRY_429_MAX_RETRIES`: Maximum retry attempts for 429 errors (default: 5)
|
| 324 |
+
- `RETRY_429_INTERVAL`: Retry interval for 429 errors, in seconds (default: 1.0)
|
| 325 |
+
- `ANTI_TRUNCATION_MAX_ATTEMPTS`: Maximum retry attempts for anti-truncation (default: 3)
|
| 326 |
+
|
| 327 |
+
**Network and Proxy Configuration**
|
| 328 |
+
- `PROXY`: Proxy address (supports `http://`, `https://`, `socks5://`, `socks5h://`, optionally with credentials `user:pass@host:port`)
|
| 329 |
+
- `OAUTH_PROXY_URL`: OAuth authentication proxy endpoint
|
| 330 |
+
- `GOOGLEAPIS_PROXY_URL`: Google APIs proxy endpoint
|
| 331 |
+
- `PATH_PREFIX`: When the reverse proxy preserves the path prefix (e.g. `/AGY2API`), set this so the backend strips it before routing; default: empty (no stripping)
|
| 332 |
+
|
| 333 |
+
**Automation Configuration**
|
| 334 |
+
- `AUTO_BAN`: Enable automatic credential banning (default: false)
|
| 335 |
+
- `AUTO_BAN_ERROR_CODES`: Error codes that trigger automatic banning (default: 403)
|
| 336 |
+
|
| 337 |
+
**Logging Configuration**
|
| 338 |
+
- `LOG_LEVEL`: Log level (DEBUG/INFO/WARNING/ERROR, default: INFO)
|
| 339 |
+
- `ENABLE_LOG`: Full silence, no log output (set to 0 to enable, default: 1)
|
| 340 |
+
|
| 341 |
+
**Response Behavior Configuration**
|
| 342 |
+
- `RETURN_THOUGHTS_TO_FRONTEND`: Return thinking chain to the frontend (default: true)
|
| 343 |
+
|
| 344 |
+
**Sensitive Word Filtering**
|
| 345 |
+
- `SENSITIVE_WORDS_ENABLED`: Enable sensitive word filtering (default: false)
|
| 346 |
+
- `SENSITIVE_WORDS`: Sensitive word list, comma or newline separated (default: empty). Matches are replaced with empty string, case-insensitive, Chinese supported, effective immediately after panel save
|
| 347 |
+
|
| 348 |
+
**Usage Log**
|
| 349 |
+
- `USAGE_LOG_ENABLED`: Enable request logging (default: true). Records every API request (model, credential, token usage, latency, status) to the database. No automatic cleanup; use the panel to clear logs manually
|
| 350 |
+
|
| 351 |
+
**Request Body Debug Log**
|
| 352 |
+
- `REQUEST_LOG_ENABLED`: Enable request body debug logging (default: false). When enabled and the final status code matches the configured codes, the full request headers (redacted) and body sent upstream are saved as JSON files under `data/request_logs/`. Only the file index is stored in the database; view it from the request log detail modal. Mainly for debugging request body errors (e.g. 400); clearing/truncating logs also deletes these files (mount `./data/request_logs:/app/data/request_logs` in Docker to persist)
|
| 353 |
+
- `REQUEST_LOG_ERROR_CODES`: Status codes that trigger debug logging, comma separated (default: 400)
|
| 354 |
+
|
| 355 |
+
**Credential Select Mode**
|
| 356 |
+
- `CREDENTIAL_SELECT_MODE`: Credential selection mode (default: cache)
|
| 357 |
+
- `random` — Fully random load balancing, each request picks a random credential
|
| 358 |
+
- `cache` — Cache affinity (recommended): hashes "model + system instruction (or first user message)" into a session key; the same session reuses the same credential, hitting Google's upstream prompt cache; automatically switches and rebinds after credential cooldown
|
| 359 |
+
- `sticky` — Sticky: all requests lock onto one credential until it enters cooldown or gets disabled
|
| 360 |
+
- `REDIS_URL`: Redis connection string (optional). When set, cache-mode session bindings are stored in Redis for multi-instance sharing; otherwise an in-process memory backend is used
|
| 361 |
+
|
| 362 |
+
**Storage Configuration**
|
| 363 |
+
|
| 364 |
+
**SQLite (Default)**
|
| 365 |
+
- No configuration required, database file created in `creds/` automatically
|
| 366 |
+
|
| 367 |
+
**PostgreSQL (Optional Cloud Storage)**
|
| 368 |
+
- `POSTGRESQL_URI`: PostgreSQL connection string (enables PostgreSQL mode when set)
|
| 369 |
+
|
| 370 |
+
**Docker Usage Example**
|
| 371 |
+
```bash
|
| 372 |
+
docker run -d --name agy2api \
|
| 373 |
+
-e API_PASSWORD=my_api_password \
|
| 374 |
+
-e PANEL_PASSWORD=my_panel_password \
|
| 375 |
+
-e PORT=7861 \
|
| 376 |
+
ghcr.io/su-kaka/agy2api:latest
|
| 377 |
+
```
|
| 378 |
+
|
| 379 |
+
### API Usage Methods
|
| 380 |
+
|
| 381 |
+
This service supports multiple complete sets of API endpoints:
|
| 382 |
+
|
| 383 |
+
#### 3. Claude API Format Endpoints
|
| 384 |
+
|
| 385 |
+
**Endpoint:** `/v1/messages`
|
| 386 |
+
**Authentication:** `x-api-key: your_api_password` or `Authorization: Bearer your_api_password`
|
| 387 |
+
|
| 388 |
+
**Request Example:**
|
| 389 |
+
```bash
|
| 390 |
+
curl -X POST "http://127.0.0.1:7861/v1/messages" \
|
| 391 |
+
-H "x-api-key: your_api_password" \
|
| 392 |
+
-H "anthropic-version: 2023-06-01" \
|
| 393 |
+
-H "Content-Type: application/json" \
|
| 394 |
+
-d '{
|
| 395 |
+
"model": "gemini-2.5-pro",
|
| 396 |
+
"max_tokens": 1024,
|
| 397 |
+
"messages": [
|
| 398 |
+
{"role": "user", "content": "Hello, Claude!"}
|
| 399 |
+
]
|
| 400 |
+
}'
|
| 401 |
+
```
|
| 402 |
+
|
| 403 |
+
**Support for system parameter:**
|
| 404 |
+
```json
|
| 405 |
+
{
|
| 406 |
+
"model": "gemini-2.5-pro",
|
| 407 |
+
"max_tokens": 1024,
|
| 408 |
+
"system": "You are a helpful assistant",
|
| 409 |
+
"messages": [
|
| 410 |
+
{"role": "user", "content": "Hello"}
|
| 411 |
+
]
|
| 412 |
+
}
|
| 413 |
+
```
|
| 414 |
+
|
| 415 |
+
**Notes:**
|
| 416 |
+
- Fully compatible with Claude API format specification
|
| 417 |
+
- Automatically converts to Gemini format for backend calls
|
| 418 |
+
- Supports all Claude standard parameters
|
| 419 |
+
- Response format follows Claude API specification
|
| 420 |
+
|
| 421 |
+
#### 4. Antigravity API Endpoints
|
| 422 |
+
|
| 423 |
+
**Supports three formats: OpenAI, Gemini, and Claude**
|
| 424 |
+
|
| 425 |
+
##### Antigravity OpenAI Format Endpoints
|
| 426 |
+
|
| 427 |
+
**Endpoint:** `/v1/chat/completions`
|
| 428 |
+
**Authentication:** `Authorization: Bearer your_api_password`
|
| 429 |
+
|
| 430 |
+
**Request Example:**
|
| 431 |
+
```bash
|
| 432 |
+
curl -X POST "http://127.0.0.1:7861/v1/chat/completions" \
|
| 433 |
+
-H "Authorization: Bearer your_api_password" \
|
| 434 |
+
-H "Content-Type: application/json" \
|
| 435 |
+
-d '{
|
| 436 |
+
"model": "claude-sonnet-4-5",
|
| 437 |
+
"messages": [
|
| 438 |
+
{"role": "user", "content": "Hello"}
|
| 439 |
+
],
|
| 440 |
+
"stream": true
|
| 441 |
+
}'
|
| 442 |
+
```
|
| 443 |
+
|
| 444 |
+
##### Antigravity Gemini Format Endpoints
|
| 445 |
+
|
| 446 |
+
**Non-streaming Endpoint:** `/v1/models/{model}:generateContent`
|
| 447 |
+
**Streaming Endpoint:** `/v1/models/{model}:streamGenerateContent`
|
| 448 |
+
|
| 449 |
+
**Authentication Methods (choose one):**
|
| 450 |
+
- `Authorization: Bearer your_api_password`
|
| 451 |
+
- `x-goog-api-key: your_api_password`
|
| 452 |
+
- URL parameter: `?key=your_api_password`
|
| 453 |
+
|
| 454 |
+
**Request Examples:**
|
| 455 |
+
```bash
|
| 456 |
+
# Gemini format non-streaming request
|
| 457 |
+
curl -X POST "http://127.0.0.1:7861/v1/models/claude-sonnet-4-5:generateContent" \
|
| 458 |
+
-H "x-goog-api-key: your_api_password" \
|
| 459 |
+
-H "Content-Type: application/json" \
|
| 460 |
+
-d '{
|
| 461 |
+
"contents": [
|
| 462 |
+
{"role": "user", "parts": [{"text": "Hello"}]}
|
| 463 |
+
],
|
| 464 |
+
"generationConfig": {
|
| 465 |
+
"temperature": 0.7
|
| 466 |
+
}
|
| 467 |
+
}'
|
| 468 |
+
|
| 469 |
+
# Gemini format streaming request
|
| 470 |
+
curl -X POST "http://127.0.0.1:7861/v1/models/gemini-2.5-flash:streamGenerateContent?key=your_api_password" \
|
| 471 |
+
-H "Content-Type: application/json" \
|
| 472 |
+
-d '{
|
| 473 |
+
"contents": [
|
| 474 |
+
{"role": "user", "parts": [{"text": "Hello"}]}
|
| 475 |
+
]
|
| 476 |
+
}'
|
| 477 |
+
```
|
| 478 |
+
|
| 479 |
+
##### Antigravity Claude Format Endpoints
|
| 480 |
+
|
| 481 |
+
**Endpoint:** `/v1/messages`
|
| 482 |
+
**Authentication:** `x-api-key: your_api_password`
|
| 483 |
+
|
| 484 |
+
**Request Example:**
|
| 485 |
+
```bash
|
| 486 |
+
curl -X POST "http://127.0.0.1:7861/v1/messages" \
|
| 487 |
+
-H "x-api-key: your_api_password" \
|
| 488 |
+
-H "anthropic-version: 2023-06-01" \
|
| 489 |
+
-H "Content-Type: application/json" \
|
| 490 |
+
-d '{
|
| 491 |
+
"model": "claude-sonnet-4-5",
|
| 492 |
+
"max_tokens": 1024,
|
| 493 |
+
"messages": [
|
| 494 |
+
{"role": "user", "content": "Hello"}
|
| 495 |
+
]
|
| 496 |
+
}'
|
| 497 |
+
```
|
| 498 |
+
|
| 499 |
+
**Supported Antigravity Models:**
|
| 500 |
+
- Claude series: `claude-sonnet-4-5`, `claude-opus-4-5`, etc.
|
| 501 |
+
- Gemini series: `gemini-2.5-flash`, `gemini-2.5-pro`, etc.
|
| 502 |
+
- Automatically supports thinking models
|
| 503 |
+
|
| 504 |
+
**Gemini Native Example:**
|
| 505 |
+
```python
|
| 506 |
+
from io import BytesIO
|
| 507 |
+
from PIL import Image
|
| 508 |
+
from google.genai import Client
|
| 509 |
+
from google.genai.types import HttpOptions
|
| 510 |
+
from google.genai import types
|
| 511 |
+
# The client gets the API key from the environment variable `GEMINI_API_KEY`.
|
| 512 |
+
|
| 513 |
+
client = Client(
|
| 514 |
+
api_key="pwd",
|
| 515 |
+
http_options=HttpOptions(base_url="http://127.0.0.1:7861"),
|
| 516 |
+
)
|
| 517 |
+
|
| 518 |
+
prompt = (
|
| 519 |
+
"""
|
| 520 |
+
Draw a cat
|
| 521 |
+
"""
|
| 522 |
+
)
|
| 523 |
+
|
| 524 |
+
response = client.models.generate_content(
|
| 525 |
+
model="gemini-3.1-flash-image",
|
| 526 |
+
contents=[prompt],
|
| 527 |
+
config=types.GenerateContentConfig(
|
| 528 |
+
image_config=types.ImageConfig(
|
| 529 |
+
aspect_ratio="16:9",
|
| 530 |
+
)
|
| 531 |
+
)
|
| 532 |
+
)
|
| 533 |
+
for part in response.candidates[0].content.parts:
|
| 534 |
+
if part.text is not None:
|
| 535 |
+
print(part.text)
|
| 536 |
+
elif part.inline_data is not None:
|
| 537 |
+
image = Image.open(BytesIO(part.inline_data.data))
|
| 538 |
+
image.save("generated_image.png")
|
| 539 |
+
|
| 540 |
+
```
|
| 541 |
+
|
| 542 |
+
**Notes:**
|
| 543 |
+
- OpenAI endpoints return OpenAI-compatible format
|
| 544 |
+
- Gemini endpoints return Gemini native format
|
| 545 |
+
- Both endpoints use the same API password
|
| 546 |
+
|
| 547 |
+
## 📋 Complete API Reference
|
| 548 |
+
|
| 549 |
+
### Web Console API
|
| 550 |
+
|
| 551 |
+
**Authentication Endpoints**
|
| 552 |
+
- `POST /auth/login` - User login
|
| 553 |
+
- `POST /auth/start` - Start Antigravity OAuth authentication
|
| 554 |
+
- `POST /auth/callback` - Handle OAuth callback
|
| 555 |
+
- `POST /auth/callback-url` - Complete authentication directly from callback URL
|
| 556 |
+
- `GET /auth/status/{project_id}` - Check authentication status
|
| 557 |
+
|
| 558 |
+
**Credential Management Endpoints**
|
| 559 |
+
- `POST /creds/upload` - Batch upload credential files (supports JSON and ZIP)
|
| 560 |
+
- `GET /creds/status` - Get credential status list (supports pagination and filtering)
|
| 561 |
+
- `GET /creds/detail/{email}` - Get single credential details
|
| 562 |
+
- `POST /creds/action` - Single credential operation (enable/disable/delete)
|
| 563 |
+
- `POST /creds/batch-action` - Batch credential operations
|
| 564 |
+
- `GET /creds/export/{email}` - Export single credential as standardized JSON
|
| 565 |
+
- `GET /creds/download-all` - Package download all credentials (standardized JSON, one file per email)
|
| 566 |
+
- `GET /creds/quota/{email}` - Get credential quota information
|
| 567 |
+
|
| 568 |
+
**Configuration Management Endpoints**
|
| 569 |
+
- `GET /config/get` - Get current configuration
|
| 570 |
+
- `POST /config/save` - Save configuration
|
| 571 |
+
|
| 572 |
+
**Version Information Endpoints**
|
| 573 |
+
- `GET /version/info` - Get version information (optional `check_update=true` parameter to check for updates)
|
| 574 |
+
|
| 575 |
+
### Chat API Features
|
| 576 |
+
|
| 577 |
+
**Multimodal Support**
|
| 578 |
+
```json
|
| 579 |
+
{
|
| 580 |
+
"model": "gemini-2.5-pro",
|
| 581 |
+
"messages": [
|
| 582 |
+
{
|
| 583 |
+
"role": "user",
|
| 584 |
+
"content": [
|
| 585 |
+
{"type": "text", "text": "Describe this image"},
|
| 586 |
+
{
|
| 587 |
+
"type": "image_url",
|
| 588 |
+
"image_url": {
|
| 589 |
+
"url": "data:image/jpeg;base64,/9j/4AAQSkZJRgABA..."
|
| 590 |
+
}
|
| 591 |
+
}
|
| 592 |
+
]
|
| 593 |
+
}
|
| 594 |
+
]
|
| 595 |
+
}
|
| 596 |
+
```
|
| 597 |
+
|
| 598 |
+
**Thinking Mode Support**
|
| 599 |
+
```json
|
| 600 |
+
{
|
| 601 |
+
"model": "gemini-2.5-pro-high",
|
| 602 |
+
"messages": [
|
| 603 |
+
{"role": "user", "content": "Complex math problem"}
|
| 604 |
+
]
|
| 605 |
+
}
|
| 606 |
+
```
|
| 607 |
+
|
| 608 |
+
Response will include separated thinking content:
|
| 609 |
+
```json
|
| 610 |
+
{
|
| 611 |
+
"choices": [{
|
| 612 |
+
"message": {
|
| 613 |
+
"role": "assistant",
|
| 614 |
+
"content": "Final answer",
|
| 615 |
+
"reasoning_content": "Detailed thought process..."
|
| 616 |
+
}
|
| 617 |
+
}]
|
| 618 |
+
}
|
| 619 |
+
```
|
| 620 |
+
|
| 621 |
+
**Anti-truncation Usage**
|
| 622 |
+
```json
|
| 623 |
+
{
|
| 624 |
+
"model": "抗截断-gemini-2.5-pro",
|
| 625 |
+
"messages": [
|
| 626 |
+
{"role": "user", "content": "Write a long article"}
|
| 627 |
+
],
|
| 628 |
+
"stream": true
|
| 629 |
+
}
|
| 630 |
+
```
|
| 631 |
+
|
| 632 |
+
---
|
| 633 |
+
|
| 634 |
+
## 🛠️ Frontend Development
|
| 635 |
+
|
| 636 |
+
The panel frontend source lives in `frontend/` (React + Vite + Tailwind CSS):
|
| 637 |
+
|
| 638 |
+
```bash
|
| 639 |
+
cd frontend
|
| 640 |
+
npm install
|
| 641 |
+
npm run dev # Development mode, port 3000, proxies backend API
|
| 642 |
+
npm run build # Build to dist/ (used in production)
|
| 643 |
+
```
|
| 644 |
+
|
| 645 |
+
The backend serves the compiled static files under `dist/` directly; no Node.js runtime required.
|
| 646 |
+
|
| 647 |
+
## 💬 Community
|
| 648 |
+
|
| 649 |
+
Welcome to join the QQ group for discussion!
|
| 650 |
+
|
| 651 |
+
**QQ Group: 1083250744**
|
| 652 |
+
|
| 653 |
+
---
|
| 654 |
+
|
| 655 |
+
## License and Disclaimer
|
| 656 |
+
|
| 657 |
+
This project is for learning and research purposes only. Using this project indicates that you agree to:
|
| 658 |
+
- Not use this project for any commercial purposes
|
| 659 |
+
- Bear all risks and responsibilities of using this project
|
| 660 |
+
- Comply with relevant terms of service and legal regulations
|
| 661 |
+
|
| 662 |
+
The project authors are not responsible for any direct or indirect losses arising from the use of this project.
|
| 663 |
+
|
| 664 |
+
## ⚠️ License Declaration
|
| 665 |
+
|
| 666 |
+
**This project is licensed under the Cooperative Non-Commercial License (CNC-1.0)**
|
| 667 |
+
|
| 668 |
+
This is a strict anti-commercial open source license. Please refer to the [LICENSE](../LICENSE) file for details.
|
| 669 |
+
|
| 670 |
+
### ✅ Permitted Uses:
|
| 671 |
+
- Personal learning, research, and educational purposes
|
| 672 |
+
- Non-profit organization use
|
| 673 |
+
- Open source project integration (must comply with the same license)
|
| 674 |
+
- Academic research and publication
|
| 675 |
+
|
| 676 |
+
### ❌ Prohibited Uses:
|
| 677 |
+
- Any form of commercial use
|
| 678 |
+
- Enterprise use with annual revenue exceeding $1 million
|
| 679 |
+
- Venture capital-backed or publicly traded companies
|
| 680 |
+
- Providing paid services or products
|
| 681 |
+
- Commercial competitive use
|
agy2api/docs/README_JA.md
ADDED
|
@@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|
|
|
| 1 |
+
# AGY2API
|
| 2 |
+
|
| 3 |
+
**Google AntigravityをOpenAI、Gemini、Claude API互換インターフェースに変換**
|
| 4 |
+
|
| 5 |
+
[](https://www.python.org/downloads/)
|
| 6 |
+
[](../LICENSE)
|
| 7 |
+
[](https://github.com/su-kaka/agy2api/pkgs/container/agy2api)
|
| 8 |
+
|
| 9 |
+
[中文](../README.md) | [English](README_EN.md) | 日本語
|
| 10 |
+
|
| 11 |
+
## インストールガイド
|
| 12 |
+
|
| 13 |
+
### Termux環境
|
| 14 |
+
|
| 15 |
+
**初期インストール**
|
| 16 |
+
```bash
|
| 17 |
+
curl -o termux-install.sh "https://raw.githubusercontent.com/su-kaka/agy2api/refs/heads/master/termux-install.sh" && chmod +x termux-install.sh && ./termux-install.sh
|
| 18 |
+
```
|
| 19 |
+
|
| 20 |
+
**サービス再起動**
|
| 21 |
+
```bash
|
| 22 |
+
cd agy2api
|
| 23 |
+
bash termux-start.sh
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
### Windows環境
|
| 27 |
+
|
| 28 |
+
**初期インストール**
|
| 29 |
+
```powershell
|
| 30 |
+
iex (iwr "https://raw.githubusercontent.com/su-kaka/agy2api/refs/heads/master/install.ps1" -UseBasicParsing).Content
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
**サービス再起動**
|
| 34 |
+
`start.bat` をダブルクリックして実行
|
| 35 |
+
|
| 36 |
+
### Linux環境
|
| 37 |
+
|
| 38 |
+
**初期インストール**
|
| 39 |
+
```bash
|
| 40 |
+
curl -o install.sh "https://raw.githubusercontent.com/su-kaka/agy2api/refs/heads/master/install.sh" && chmod +x install.sh && ./install.sh
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
**サービス再起動**
|
| 44 |
+
```bash
|
| 45 |
+
cd agy2api
|
| 46 |
+
bash start.sh
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
### macOS環境
|
| 50 |
+
|
| 51 |
+
**初期インストール**
|
| 52 |
+
```bash
|
| 53 |
+
curl -o darwin-install.sh "https://raw.githubusercontent.com/su-kaka/agy2api/refs/heads/master/darwin-install.sh" && chmod +x darwin-install.sh && ./darwin-install.sh
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
**サービス再起動**
|
| 57 |
+
```bash
|
| 58 |
+
cd agy2api
|
| 59 |
+
bash start.sh
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
### Docker環境
|
| 63 |
+
|
| 64 |
+
**Docker Runコマンド**
|
| 65 |
+
```bash
|
| 66 |
+
docker run -d --name agy2api --network host -e API_PASSWORD=api_pwd -e PANEL_PASSWORD=panel_pwd -e PORT=7861 -v $(pwd)/data/creds:/app/creds -v $(pwd)/data/request_logs:/app/data/request_logs ghcr.io/su-kaka/agy2api:latest
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
**Docker Mac**
|
| 70 |
+
```bash
|
| 71 |
+
docker run -d \
|
| 72 |
+
--name agy2api \
|
| 73 |
+
-p 7861:7861 \
|
| 74 |
+
-p 8080:8080 \
|
| 75 |
+
-e API_PASSWORD=api_pwd \
|
| 76 |
+
-e PANEL_PASSWORD=panel_pwd \
|
| 77 |
+
-e PORT=7861 \
|
| 78 |
+
-v $(pwd)/data/creds:/app/creds \
|
| 79 |
+
-v $(pwd)/data/request_logs:/app/data/request_logs \
|
| 80 |
+
ghcr.io/su-kaka/agy2api:latest
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
**Docker Compose Runコマンド**
|
| 84 |
+
1. 以下の内容を `docker-compose.yml` ファイルとして保存:
|
| 85 |
+
```yaml
|
| 86 |
+
version: '3.8'
|
| 87 |
+
|
| 88 |
+
services:
|
| 89 |
+
agy2api:
|
| 90 |
+
image: ghcr.io/su-kaka/agy2api:latest
|
| 91 |
+
container_name: agy2api
|
| 92 |
+
restart: unless-stopped
|
| 93 |
+
network_mode: host
|
| 94 |
+
environment:
|
| 95 |
+
# パスワード設定(個別パスワード)
|
| 96 |
+
- API_PASSWORD=your_api_password
|
| 97 |
+
- PANEL_PASSWORD=your_panel_password
|
| 98 |
+
- PORT=7861
|
| 99 |
+
volumes:
|
| 100 |
+
- ./data/creds:/app/creds
|
| 101 |
+
- ./data/request_logs:/app/data/request_logs
|
| 102 |
+
healthcheck:
|
| 103 |
+
test: ["CMD-SHELL", "python -c \"import sys, urllib.request, os; port = os.environ.get('PORT', '7861'); req = urllib.request.Request(f'http://localhost:{port}/v1/models', headers={'Authorization': 'Bearer ' + os.environ.get('API_PASSWORD', 'pwd')}); sys.exit(0 if urllib.request.urlopen(req, timeout=5).getcode() == 200 else 1)\""]
|
| 104 |
+
interval: 30s
|
| 105 |
+
timeout: 10s
|
| 106 |
+
retries: 3
|
| 107 |
+
start_period: 40s
|
| 108 |
+
```
|
| 109 |
+
2. サービスを起動:
|
| 110 |
+
```bash
|
| 111 |
+
docker-compose up -d
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
## コア機能
|
| 115 |
+
|
| 116 |
+
### 🔄 APIエンドポイントとフォーマット対応
|
| 117 |
+
|
| 118 |
+
**マルチエンドポイント・マルチフォーマット対応**
|
| 119 |
+
- **OpenAI互換エンドポイント**: `/v1/chat/completions` および `/v1/models`
|
| 120 |
+
- 標準OpenAIフォーマット(messages構造)に対応
|
| 121 |
+
- Geminiネイティブフォーマット(contents構造)に対応
|
| 122 |
+
- フォーマットの自動検出・変換、手動切替不要
|
| 123 |
+
- マルチモーダル入力に対応(テキスト+画像)
|
| 124 |
+
- **Geminiネイティブエンドポイント**: `/v1/models/{model}:generateContent` および `streamGenerateContent`
|
| 125 |
+
- Geminiネイティブ API仕様に完全対応
|
| 126 |
+
- 複数の認証方式: Bearer Token、x-goog-api-keyヘッダー、URLパラメータkey
|
| 127 |
+
- **Claudeフォーマット互換**: Claude APIフォーマットに完全対応
|
| 128 |
+
- エンドポイント: `/v1/messages`(Claude API仕様に準拠)
|
| 129 |
+
- Claude標準messagesフォーマットに対応
|
| 130 |
+
- systemパラメータおよびClaude固有機能に対応
|
| 131 |
+
- バックエンド対応フォーマットへの自動変換
|
| 132 |
+
- **Antigravity API対応**: OpenAI、Gemini、Claudeフォーマットに対応
|
| 133 |
+
- OpenAIフォーマットエンドポイント: `/v1/chat/completions`
|
| 134 |
+
- Geminiフォーマットエンドポイント: `/v1/models/{model}:generateContent` および `streamGenerateContent`
|
| 135 |
+
- Claudeフォーマットエンドポイント: `/v1/messages`
|
| 136 |
+
- 全Antigravityモデルに対応(Claude、Geminiなど)
|
| 137 |
+
- モデル名の自動マッピングおよびThinkingモード検出
|
| 138 |
+
|
| 139 |
+
### 🔐 認証とセキュリテ��管理
|
| 140 |
+
|
| 141 |
+
**柔軟なパスワード管理**
|
| 142 |
+
- **個別パスワード対応**: APIパスワード(チャットエンドポイント)とコントロールパネルパスワードを個別に設定可能
|
| 143 |
+
- **複数の認証方式**: Authorization Bearer、x-goog-api-keyヘッダー、URLパラメータなどに対応
|
| 144 |
+
- **JWTトークン認証**: コントロールパネルはJWTトークン認証に対応
|
| 145 |
+
- **ユーザーメール取得**: Googleアカウントのメールアドレスを自動取得・表示
|
| 146 |
+
|
| 147 |
+
### 📊 インテリジェントなクレデンシャル管理システム
|
| 148 |
+
|
| 149 |
+
**高度なクレデンシャル管理**
|
| 150 |
+
- 複数のGoogle OAuthクレデンシャルの自動ローテーション
|
| 151 |
+
- 冗長認証による安定性の向上
|
| 152 |
+
- ロードバランシングと同時リクエスト対応
|
| 153 |
+
- 自動障害検出とクレデンシャル無効化
|
| 154 |
+
- クレデンシャル使用統計とクォータ管理
|
| 155 |
+
- クレデンシャルファイルの手動有効化/無効化に対応
|
| 156 |
+
- クレデンシャルファイルの一括操作(有効化、無効化、削除)
|
| 157 |
+
|
| 158 |
+
**クレデンシャルステータス監視**
|
| 159 |
+
- リアルタイムのクレデンシャルヘルスチェック
|
| 160 |
+
- エラーコードの追跡(429、403、500など)
|
| 161 |
+
- 自動BAN機能(設定可能)
|
| 162 |
+
|
| 163 |
+
### 🌊 ストリーミングとレスポンス処理
|
| 164 |
+
|
| 165 |
+
**複数のストリーミング対応**
|
| 166 |
+
- リアルタイムストリーミングレスポンス
|
| 167 |
+
- ストリーミング途切れ防止機能(回答の途切れを防止)
|
| 168 |
+
- 非同期タスク管理とタイムアウト処理
|
| 169 |
+
|
| 170 |
+
**レスポンス最適化**
|
| 171 |
+
- 思考チェーン内容の分離
|
| 172 |
+
- 推論プロセス(reasoning_content)の処理
|
| 173 |
+
- マルチターン会話のコンテキスト管理
|
| 174 |
+
|
| 175 |
+
### 🎛️ Web管理コンソール
|
| 176 |
+
|
| 177 |
+
**フル機能のWebインターフェース**
|
| 178 |
+
- Antigravity OAuth認証フロー(コールバックURLショートカット対応)
|
| 179 |
+
- クレデンシャルファイルのアップロード、ダウンロード、管理
|
| 180 |
+
- システム設定管理
|
| 181 |
+
- 使用統計と監視ダッシュボード
|
| 182 |
+
- モバイル対応インターフェース
|
| 183 |
+
|
| 184 |
+
**一括操作対応**
|
| 185 |
+
- ZIP/JSON一括クレデンシャルアップロード(Antigravity)
|
| 186 |
+
- クレデンシャルの一括有効化/無効化/削除
|
| 187 |
+
- ユーザーメールの一括取得
|
| 188 |
+
- 設定の一括管理
|
| 189 |
+
- 全クレデンシャルタイプ統合一括アップロードインターフェース
|
| 190 |
+
|
| 191 |
+
### 🔧 高度な設定とカスタマイズ
|
| 192 |
+
|
| 193 |
+
**ネットワークとプロキシ設定**
|
| 194 |
+
- HTTP/HTTPSプロキシ対応
|
| 195 |
+
- プロキシエンドポイント設定(OAuth、Google APIs、メタデータサービス)
|
| 196 |
+
- タイムアウトとリトライ設定
|
| 197 |
+
- ネットワークエラー処理とリカバリ
|
| 198 |
+
|
| 199 |
+
**パフォーマンスと安定性の設定**
|
| 200 |
+
- 429エラーの自動リトライ(間隔と回数を設定可能)
|
| 201 |
+
- 途切れ防止の最大リトライ回数
|
| 202 |
+
|
| 203 |
+
**ログとデバッグ**
|
| 204 |
+
- マルチレベルログシステム(DEBUG、INFO、WARNING、ERROR)
|
| 205 |
+
- コンソールのみのログ出力(`ENABLE_LOG=0` で完全サイレント)
|
| 206 |
+
|
| 207 |
+
### 🔄 環境変数と設定管理
|
| 208 |
+
|
| 209 |
+
**柔軟な設定方法**
|
| 210 |
+
- 環境変数による設定
|
| 211 |
+
- ホット設定更新(一部設定項目)
|
| 212 |
+
- 設定ロック(環境変数優先)
|
| 213 |
+
|
| 214 |
+
## 対応モデル
|
| 215 |
+
|
| 216 |
+
全モデルが100万トークンのコンテキストウィンドウに対応。各クレデンシャルファイルで1000リクエストのクォータを提供。
|
| 217 |
+
|
| 218 |
+
### 🤖 基本モデル
|
| 219 |
+
- `gemini-2.5-pro`
|
| 220 |
+
- `gemini-3-pro-preview`
|
| 221 |
+
- `gemini-3.1-pro-preview`
|
| 222 |
+
|
| 223 |
+
### 🧠 Thinkingモデル
|
| 224 |
+
- `gemini-2.5-pro-high`: Thinkingモード
|
| 225 |
+
- `gemini-2.5-pro-low`: 低Thinkingモード
|
| 226 |
+
- カスタムThinkingバジェット設定に対応
|
| 227 |
+
- 思考内容と最終回答の自動分離
|
| 228 |
+
|
| 229 |
+
### 🔍 検索拡張モデル
|
| 230 |
+
- `gemini-2.5-pro-search`: 検索機能統合モデル
|
| 231 |
+
|
| 232 |
+
### 🖼️ 画像生成モデル(Antigravity)
|
| 233 |
+
- `gemini-3.1-flash-image`: 基本画像生成モデル
|
| 234 |
+
- **解像度サフィックス**:
|
| 235 |
+
- `-2k`: 2K解像度
|
| 236 |
+
- `-4k`: 4K HD解像度
|
| 237 |
+
- **アスペクト比サフィックス**:
|
| 238 |
+
- `-1x1`: 正方形(アバター)
|
| 239 |
+
- `-16x9`: 横長(デスクトップ壁紙)
|
| 240 |
+
- `-9x16`: 縦長(モバイル壁紙)
|
| 241 |
+
- `-21x9`: ウルトラワイド(ウルトラワイドモニター)
|
| 242 |
+
- `-4x3`: 従来のディスプレイ
|
| 243 |
+
- `-3x4`: 縦型ポスター
|
| 244 |
+
- **組み合わせ例**:
|
| 245 |
+
- `gemini-3.1-flash-image-4k-16x9`: 4K横長
|
| 246 |
+
- `gemini-3.1-flash-image-2k-9x16`: 2K縦長
|
| 247 |
+
- 比率未指定時はAPIが自動的にアスペクト比を決定
|
| 248 |
+
|
| 249 |
+
### 🌊 特殊機能バリアント
|
| 250 |
+
- **途切れ防止モード**: モデル名に `抗截断-` プレフィックスを追加
|
| 251 |
+
- 例: `抗截断-gemini-2.5-pro`
|
| 252 |
+
- 合成ツール呼び出しで途切れ制限を回避し、完全な回答を保証(ストリーミング・非ストリーミング両対応)
|
| 253 |
+
|
| 254 |
+
### 🔧 モデル機能の自動検出
|
| 255 |
+
- システムがモデル名内の機能識別子を自動認識
|
| 256 |
+
- 機能モード切替を透過的に処理
|
| 257 |
+
- 機能の組み合わせ使用に対応
|
| 258 |
+
|
| 259 |
+
---
|
| 260 |
+
|
| 261 |
+
## 設定手順
|
| 262 |
+
|
| 263 |
+
1. `http://127.0.0.1:7861` にアクセス(デフォルトポート、PORT環境変数で変更可能)
|
| 264 |
+
2. OAuth認証フローを完了(デフォルトパスワード: `pwd`、環境変数で変更可能)
|
| 265 |
+
- **GCLIモード**: Google Cloud Gemini APIクレデンシャルの取得用
|
| 266 |
+
3. クライアントを設定:
|
| 267 |
+
|
| 268 |
+
**OpenAI互換クライアント:**
|
| 269 |
+
- **エンドポイントアドレス**: `http://127.0.0.1:7861/v1`
|
| 270 |
+
- **APIキー**: `pwd`(デフォルト値、API_PASSWORD環境変数で変更可能)
|
| 271 |
+
|
| 272 |
+
**Geminiネイティブクライアント:**
|
| 273 |
+
- **エンドポイントアドレス**: `http://127.0.0.1:7861`
|
| 274 |
+
- **認証方式**:
|
| 275 |
+
- `Authorization: Bearer your_api_password`
|
| 276 |
+
- `x-goog-api-key: your_api_password`
|
| 277 |
+
- URLパラメータ: `?key=your_api_password`
|
| 278 |
+
|
| 279 |
+
## 💾 データストレージモード
|
| 280 |
+
|
| 281 |
+
### 🌟 ストレージバックエンド対応
|
| 282 |
+
|
| 283 |
+
agy2apiは2つのストレージバックエンドに対応: **ローカルSQLite(デフォルト)** と **PostgreSQL(クラウド分散ストレージ)**
|
| 284 |
+
|
| 285 |
+
### 📁 ローカルSQLiteストレージ(デフォルト)
|
| 286 |
+
|
| 287 |
+
**デフォルトストレージ方式**
|
| 288 |
+
- 設定不要、すぐに利用可能
|
| 289 |
+
- データはローカルSQLiteデータベース(`creds/credentials.db`)に保存
|
| 290 |
+
- 単一マシンデプロイおよび個人利用に最適
|
| 291 |
+
|
| 292 |
+
**クレデンシャル構造**
|
| 293 |
+
|
| 294 |
+
クレデンシャルは**メールアドレス(email)を一意キー**として構造化データベースカラムで保存されます(JSON blobは不使用):
|
| 295 |
+
`email`、`access_token`、`refresh_token`、`client_id`、`client_secret`、`project_id`、`expiry`、`tier`
|
| 296 |
+
|
| 297 |
+
インポート/エクスポートは標準化JSON形式: `{"refresh_token": "...", "access_token": "...", "expiry": "...", "email": "...", "tier": "...", "project_id": "..."}`(`refresh_token` のみ必須、有効期限内の `access_token` はそのまま再利用、残りは自動取得)。
|
| 298 |
+
|
| 299 |
+
### 環境変数設定
|
| 300 |
+
|
| 301 |
+
**基本設定**
|
| 302 |
+
- `PORT`: サービスポート(デフォルト: 7861)
|
| 303 |
+
- `HOST`: サーバーリッスンアドレス(デフォルト: 0.0.0.0)
|
| 304 |
+
|
| 305 |
+
**パスワード設定**
|
| 306 |
+
- `API_PASSWORD`: チャットAPIアクセスパスワード(デフォルト: pwd)
|
| 307 |
+
- `PANEL_PASSWORD`: コントロールパネルアクセスパスワード(デフォルト: pwd)
|
| 308 |
+
|
| 309 |
+
**アクセス制御設定**
|
| 310 |
+
- `IP_WHITELIST_ENABLED`: IPホワイトリストの有効化(デフォルト: false、制限なし)
|
| 311 |
+
- `IP_WHITELIST`: IPホワイトリスト、カンマまたは改行区切り(デフォルト: 空)。各エントリは単一IP(`192.168.1.1`)、CIDR範囲(`192.168.1.0/24`)、開始-終了範囲(`10.0.0.1-10.0.0.100`)に対応、IPv4 / IPv6 両方可。有効化するとホワイトリスト内のIPのみがパネルとAPIにアクセスでき、それ以外は 403。パネル保存後すぐに有効
|
| 312 |
+
|
| 313 |
+
**モデル名リライト設定**
|
| 314 |
+
- `MODEL_REWRITE_ENABLED`: モデル名リライトの有効化(デフォルト: false)
|
| 315 |
+
- `MODEL_REWRITE_RULES`: リライトルール、各 `[マッチ正規表現, 置換モデル名]`(デフォルト: 空)。上から最初にマッチしたものが有効、置換は正規表現の後方参照(例: `\1`)に対応。例: `gpt-4o` を `gemini-2.5-pro` にマッピング。パネル保存後すぐに有効
|
| 316 |
+
|
| 317 |
+
**パフォーマンスと安定性の設定**
|
| 318 |
+
- `RETRY_429_ENABLED`: 429エラー自動リトライの有効化(デフォルト: true)
|
| 319 |
+
- `RETRY_429_MAX_RETRIES`: 429エラーの最大リトライ回数(デフォルト: 5)
|
| 320 |
+
- `RETRY_429_INTERVAL`: 429エラーのリトライ間隔、秒単位(デフォルト: 1.0)
|
| 321 |
+
- `ANTI_TRUNCATION_MAX_ATTEMPTS`: 途切れ防止の最大リトライ回数(デフォルト: 3)
|
| 322 |
+
|
| 323 |
+
**ネットワークとプロキシ設定**
|
| 324 |
+
- `PROXY`: プロキシアドレス(`http://`、`https://`、`socks5://`、`socks5h://` 対応、`user:pass@host:port` 形式の認証情報付きも可)
|
| 325 |
+
- `OAUTH_PROXY_URL`: OAuth認証プロキシエンドポイント
|
| 326 |
+
- `GOOGLEAPIS_PROXY_URL`: Google APIsプロキシエンドポイント
|
| 327 |
+
- `PATH_PREFIX`: リバースプロキシがパスプレフィックスを保持する場合(例: `/AGY2API`)、バックエンドがルーティング前にプレフィックスを剥がすよう設定。デフォルト: 空(剥がさない)
|
| 328 |
+
|
| 329 |
+
**自動化設定**
|
| 330 |
+
- `AUTO_BAN`: クレデンシャル自動BANの有効化(デフォルト: false)
|
| 331 |
+
- `AUTO_BAN_ERROR_CODES`: 自動BANをトリガーするエラーコード(デフォルト: 403)
|
| 332 |
+
|
| 333 |
+
**ログ設定**
|
| 334 |
+
- `LOG_LEVEL`: ログレベル(DEBUG/INFO/WARNING/ERROR、デフォルト: INFO)
|
| 335 |
+
- `ENABLE_LOG`: 完全サイレント(0で無効化、デフォルト: 1)
|
| 336 |
+
|
| 337 |
+
**レスポンス動作設定**
|
| 338 |
+
- `RETURN_THOUGHTS_TO_FRONTEND`: 思考チェーンをフロントエンドに返す(デフォルト: true)
|
| 339 |
+
|
| 340 |
+
**センシティブワードフィルタリング**
|
| 341 |
+
- `SENSITIVE_WORDS_ENABLED`: センシティブワードフィルタリングの有効化(デフォルト: false)
|
| 342 |
+
- `SENSITIVE_WORDS`: センシティブワードリスト、カンマまたは改行区切り(デフォルト: 空)。ヒットすると空文字列に置換、大文字小文字を区別しない、中国語対応、パネル保存後すぐに有効
|
| 343 |
+
|
| 344 |
+
**使用ログ**
|
| 345 |
+
- `USAGE_LOG_ENABLED`: リクエストログの有効化(デフォルト: true)。すべてのAPIリクエスト(モデル、クレデンシャル、トークン使用量、レイテンシ、ステータス)をデータベースに記録。自動削除なし、パネルから手動クリア可能
|
| 346 |
+
|
| 347 |
+
**リクエストボディデバッグログ**
|
| 348 |
+
- `REQUEST_LOG_ENABLED`: リクエストボディ詳細ログの有効化(デフォルト: false)。有効化すると、最終ステータスコードが指定コードに一致した場合、上流へ送信した完全なリクエストヘッダー(マスク済み)とボディを JSON ファイルとして `data/request_logs/` に保存。データベースにはファイル索引のみ記録し、リクエストログ詳細から閲覧可能。主にリクエストボディエラー(例: 400)のデバッグ用。ログのクリア/全削除時にこれらのファイルも削除(Docker では `./data/request_logs:/app/data/request_logs` をマウントして永続化)
|
| 349 |
+
- `REQUEST_LOG_ERROR_CODES`: デバッグログを記録するステータスコードリスト、カンマ区切り(デフォルト: 400)
|
| 350 |
+
|
| 351 |
+
**クレデンシャル選択モード**
|
| 352 |
+
- `CREDENTIAL_SELECT_MODE`: クレデンシャル選択モード(デフォルト: cache)
|
| 353 |
+
- `random` — 完全ランダムな負荷分散、各リクエストはランダムにクレデンシャルを選択
|
| 354 |
+
- `cache` — キャッシュマッチング(推奨):「モデル + システム指示(または最初の user メッセージ)」をハッシュ化したセッションキーで、同じセッションは同じクレデンシャルを再利用し、Google 上流の prompt cache にヒット。クールダウン後は自動切替と再バインド
|
| 355 |
+
- `sticky` — スティッキー: すべてのリクエストが CD に入るか無効化されるまで同じクレデンシャルに固定
|
| 356 |
+
- `REDIS_URL`: Redis 接続文字列(オプション)。設定するとキャッシュモードのセッションバインドを Redis に保存しマルチインスタンス共有。未設定時はプロセス内メモリバックエンドを使用
|
| 357 |
+
|
| 358 |
+
**ストレージ設定**
|
| 359 |
+
|
| 360 |
+
**SQLite(デフォルト)**
|
| 361 |
+
- 設定不要、`creds/` にデータベースファイルを自動作成
|
| 362 |
+
|
| 363 |
+
**PostgreSQL(オプションのクラウドストレージ)**
|
| 364 |
+
- `POSTGRESQL_URI`: PostgreSQL接続文字列(設定するとPostgreSQLモードが有効)
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
**Docker使用例**
|
| 368 |
+
```bash
|
| 369 |
+
docker run -d --name agy2api \
|
| 370 |
+
-e API_PASSWORD=my_api_password \
|
| 371 |
+
-e PANEL_PASSWORD=my_panel_password \
|
| 372 |
+
-e PORT=7861 \
|
| 373 |
+
ghcr.io/su-kaka/agy2api:latest
|
| 374 |
+
```
|
| 375 |
+
|
| 376 |
+
### API使用方法
|
| 377 |
+
|
| 378 |
+
本サービスは複数の完全なAPIエンドポイントセットに対応しています:
|
| 379 |
+
|
| 380 |
+
#### 3. Claude APIフォーマットエンドポイント
|
| 381 |
+
|
| 382 |
+
**エンドポイント:** `/v1/messages`
|
| 383 |
+
**認証:** `x-api-key: your_api_password` または `Authorization: Bearer your_api_password`
|
| 384 |
+
|
| 385 |
+
**リクエスト例:**
|
| 386 |
+
```bash
|
| 387 |
+
curl -X POST "http://127.0.0.1:7861/v1/messages" \
|
| 388 |
+
-H "x-api-key: your_api_password" \
|
| 389 |
+
-H "anthropic-version: 2023-06-01" \
|
| 390 |
+
-H "Content-Type: application/json" \
|
| 391 |
+
-d '{
|
| 392 |
+
"model": "gemini-2.5-pro",
|
| 393 |
+
"max_tokens": 1024,
|
| 394 |
+
"messages": [
|
| 395 |
+
{"role": "user", "content": "Hello, Claude!"}
|
| 396 |
+
]
|
| 397 |
+
}'
|
| 398 |
+
```
|
| 399 |
+
|
| 400 |
+
**systemパラメータの対応:**
|
| 401 |
+
```json
|
| 402 |
+
{
|
| 403 |
+
"model": "gemini-2.5-pro",
|
| 404 |
+
"max_tokens": 1024,
|
| 405 |
+
"system": "You are a helpful assistant",
|
| 406 |
+
"messages": [
|
| 407 |
+
{"role": "user", "content": "Hello"}
|
| 408 |
+
]
|
| 409 |
+
}
|
| 410 |
+
```
|
| 411 |
+
|
| 412 |
+
**注意事項:**
|
| 413 |
+
- Claude APIフォーマット仕様に完全互換
|
| 414 |
+
- バックエンド呼び出し時にGeminiフォーマットへ自動変換
|
| 415 |
+
- すべてのClaude標準パラメータに対応
|
| 416 |
+
- レスポンスフォーマットはClaude API仕様に準拠
|
| 417 |
+
|
| 418 |
+
#### Antigravity APIエンドポイント
|
| 419 |
+
|
| 420 |
+
**OpenAI、Gemini、Claudeの3フォーマットに対応**
|
| 421 |
+
|
| 422 |
+
##### Antigravity OpenAIフォーマットエンドポイント
|
| 423 |
+
|
| 424 |
+
**エンドポイント:** `/v1/chat/completions`
|
| 425 |
+
**認証:** `Authorization: Bearer your_api_password`
|
| 426 |
+
|
| 427 |
+
**リクエスト例:**
|
| 428 |
+
```bash
|
| 429 |
+
curl -X POST "http://127.0.0.1:7861/v1/chat/completions" \
|
| 430 |
+
-H "Authorization: Bearer your_api_password" \
|
| 431 |
+
-H "Content-Type: application/json" \
|
| 432 |
+
-d '{
|
| 433 |
+
"model": "claude-sonnet-4-5",
|
| 434 |
+
"messages": [
|
| 435 |
+
{"role": "user", "content": "Hello"}
|
| 436 |
+
],
|
| 437 |
+
"stream": true
|
| 438 |
+
}'
|
| 439 |
+
```
|
| 440 |
+
|
| 441 |
+
##### Antigravity Geminiフォーマットエンドポイント
|
| 442 |
+
|
| 443 |
+
**非ストリーミングエンドポイント:** `/v1/models/{model}:generateContent`
|
| 444 |
+
**ストリーミングエンドポイント:** `/v1/models/{model}:streamGenerateContent`
|
| 445 |
+
|
| 446 |
+
**認証方式(いずれか1つを選択):**
|
| 447 |
+
- `Authorization: Bearer your_api_password`
|
| 448 |
+
- `x-goog-api-key: your_api_password`
|
| 449 |
+
- URLパラメータ: `?key=your_api_password`
|
| 450 |
+
|
| 451 |
+
**リクエスト例:**
|
| 452 |
+
```bash
|
| 453 |
+
# Geminiフォーマット非ストリーミングリクエスト
|
| 454 |
+
curl -X POST "http://127.0.0.1:7861/v1/models/claude-sonnet-4-5:generateContent" \
|
| 455 |
+
-H "x-goog-api-key: your_api_password" \
|
| 456 |
+
-H "Content-Type: application/json" \
|
| 457 |
+
-d '{
|
| 458 |
+
"contents": [
|
| 459 |
+
{"role": "user", "parts": [{"text": "Hello"}]}
|
| 460 |
+
],
|
| 461 |
+
"generationConfig": {
|
| 462 |
+
"temperature": 0.7
|
| 463 |
+
}
|
| 464 |
+
}'
|
| 465 |
+
|
| 466 |
+
# Geminiフォーマットストリーミングリクエスト
|
| 467 |
+
curl -X POST "http://127.0.0.1:7861/v1/models/gemini-2.5-flash:streamGenerateContent?key=your_api_password" \
|
| 468 |
+
-H "Content-Type: application/json" \
|
| 469 |
+
-d '{
|
| 470 |
+
"contents": [
|
| 471 |
+
{"role": "user", "parts": [{"text": "Hello"}]}
|
| 472 |
+
]
|
| 473 |
+
}'
|
| 474 |
+
```
|
| 475 |
+
|
| 476 |
+
##### Antigravity Claudeフォーマットエンドポイント
|
| 477 |
+
|
| 478 |
+
**エンドポイント:** `/v1/messages`
|
| 479 |
+
**認証:** `x-api-key: your_api_password`
|
| 480 |
+
|
| 481 |
+
**リクエスト例:**
|
| 482 |
+
```bash
|
| 483 |
+
curl -X POST "http://127.0.0.1:7861/v1/messages" \
|
| 484 |
+
-H "x-api-key: your_api_password" \
|
| 485 |
+
-H "anthropic-version: 2023-06-01" \
|
| 486 |
+
-H "Content-Type: application/json" \
|
| 487 |
+
-d '{
|
| 488 |
+
"model": "claude-sonnet-4-5",
|
| 489 |
+
"max_tokens": 1024,
|
| 490 |
+
"messages": [
|
| 491 |
+
{"role": "user", "content": "Hello"}
|
| 492 |
+
]
|
| 493 |
+
}'
|
| 494 |
+
```
|
| 495 |
+
|
| 496 |
+
**対応Antigravityモデル:**
|
| 497 |
+
- Claudeシリーズ: `claude-sonnet-4-5`、`claude-opus-4-5` など
|
| 498 |
+
- Geminiシリーズ: `gemini-2.5-flash`、`gemini-2.5-pro` など
|
| 499 |
+
- Thinkingモデルに自動対応
|
| 500 |
+
|
| 501 |
+
**Geminiネイティブの例:**
|
| 502 |
+
```python
|
| 503 |
+
from io import BytesIO
|
| 504 |
+
from PIL import Image
|
| 505 |
+
from google.genai import Client
|
| 506 |
+
from google.genai.types import HttpOptions
|
| 507 |
+
from google.genai import types
|
| 508 |
+
# クライアントは環境変数 `GEMINI_API_KEY` からAPIキーを取得します。
|
| 509 |
+
|
| 510 |
+
client = Client(
|
| 511 |
+
api_key="pwd",
|
| 512 |
+
http_options=HttpOptions(base_url="http://127.0.0.1:7861"),
|
| 513 |
+
)
|
| 514 |
+
|
| 515 |
+
prompt = (
|
| 516 |
+
"""
|
| 517 |
+
猫を描いて
|
| 518 |
+
"""
|
| 519 |
+
)
|
| 520 |
+
|
| 521 |
+
response = client.models.generate_content(
|
| 522 |
+
model="gemini-3.1-flash-image",
|
| 523 |
+
contents=[prompt],
|
| 524 |
+
config=types.GenerateContentConfig(
|
| 525 |
+
image_config=types.ImageConfig(
|
| 526 |
+
aspect_ratio="16:9",
|
| 527 |
+
)
|
| 528 |
+
)
|
| 529 |
+
)
|
| 530 |
+
for part in response.candidates[0].content.parts:
|
| 531 |
+
if part.text is not None:
|
| 532 |
+
print(part.text)
|
| 533 |
+
elif part.inline_data is not None:
|
| 534 |
+
image = Image.open(BytesIO(part.inline_data.data))
|
| 535 |
+
image.save("generated_image.png")
|
| 536 |
+
|
| 537 |
+
```
|
| 538 |
+
|
| 539 |
+
**注意事項:**
|
| 540 |
+
- OpenAIエンドポイントはOpenAI互換フォーマットを返します
|
| 541 |
+
- GeminiエンドポイントはGeminiネイティブフォーマットを返します
|
| 542 |
+
- 両エンドポイントとも同一のAPIパスワードを使用
|
| 543 |
+
|
| 544 |
+
## 📋 完全なAPIリファレンス
|
| 545 |
+
|
| 546 |
+
### Webコンソール API
|
| 547 |
+
|
| 548 |
+
**認証エンドポイント**
|
| 549 |
+
- `POST /auth/login` - ユーザーログイン
|
| 550 |
+
- `POST /auth/start` - Antigravity OAuth認証の開始
|
| 551 |
+
- `POST /auth/callback` - OAuthコールバックの処理
|
| 552 |
+
- `POST /auth/callback-url` - コールバックURLから直接認証を完了
|
| 553 |
+
- `GET /auth/status/{project_id}` - 認証ステータスの確認
|
| 554 |
+
|
| 555 |
+
**クレデンシャル管理エンドポイント**
|
| 556 |
+
- `POST /creds/upload` - クレデンシャルファイルの一括アップロード(JSONおよびZIP対応)
|
| 557 |
+
- `GET /creds/status` - クレデンシャルステータス一覧の取得(ページネーションとフィルタリング対応)
|
| 558 |
+
- `GET /creds/detail/{email}` - 単一クレデンシャルの詳細取得
|
| 559 |
+
- `POST /creds/action` - 単一クレデンシャル操作(有効化/無効化/削除)
|
| 560 |
+
- `POST /creds/batch-action` - クレデンシャルの一括操作
|
| 561 |
+
- `GET /creds/export/{email}` - 単一クレデンシャルを標準化JSONでエクスポート
|
| 562 |
+
- `GET /creds/download-all` - 全クレデンシャルの一括ダウンロード
|
| 563 |
+
- `POST /creds/refresh-all-emails` - ユーザーメールの一括更新
|
| 564 |
+
- `POST /creds/deduplicate-by-email` - メールによるクレデンシャルの重複排除
|
| 565 |
+
- `GET /creds/quota/{email}` - クレデンシャルのクォータ情報取得
|
| 566 |
+
|
| 567 |
+
**設定管理エンドポイント**
|
| 568 |
+
- `GET /config/get` - 現在の設定の取得
|
| 569 |
+
- `POST /config/save` - 設定の保存
|
| 570 |
+
|
| 571 |
+
**バージョン情報エンドポイント**
|
| 572 |
+
- `GET /version/info` - バージョン情報の取得(オプション `check_update=true` パラメータで更新確認)
|
| 573 |
+
|
| 574 |
+
### チャットAPI機能
|
| 575 |
+
|
| 576 |
+
**マルチモーダル対応**
|
| 577 |
+
```json
|
| 578 |
+
{
|
| 579 |
+
"model": "gemini-2.5-pro",
|
| 580 |
+
"messages": [
|
| 581 |
+
{
|
| 582 |
+
"role": "user",
|
| 583 |
+
"content": [
|
| 584 |
+
{"type": "text", "text": "この画像を説明してください"},
|
| 585 |
+
{
|
| 586 |
+
"type": "image_url",
|
| 587 |
+
"image_url": {
|
| 588 |
+
"url": "data:image/jpeg;base64,/9j/4AAQSkZJRgABA..."
|
| 589 |
+
}
|
| 590 |
+
}
|
| 591 |
+
]
|
| 592 |
+
}
|
| 593 |
+
]
|
| 594 |
+
}
|
| 595 |
+
```
|
| 596 |
+
|
| 597 |
+
**Thinkingモード対応**
|
| 598 |
+
```json
|
| 599 |
+
{
|
| 600 |
+
"model": "gemini-2.5-pro-high",
|
| 601 |
+
"messages": [
|
| 602 |
+
{"role": "user", "content": "複雑な数学の問題"}
|
| 603 |
+
]
|
| 604 |
+
}
|
| 605 |
+
```
|
| 606 |
+
|
| 607 |
+
レスポンスには分離された思考内容が含まれます:
|
| 608 |
+
```json
|
| 609 |
+
{
|
| 610 |
+
"choices": [{
|
| 611 |
+
"message": {
|
| 612 |
+
"role": "assistant",
|
| 613 |
+
"content": "最終回答",
|
| 614 |
+
"reasoning_content": "詳細な思考プロセス..."
|
| 615 |
+
}
|
| 616 |
+
}]
|
| 617 |
+
}
|
| 618 |
+
```
|
| 619 |
+
|
| 620 |
+
**途切れ防止の使用方法**
|
| 621 |
+
```json
|
| 622 |
+
{
|
| 623 |
+
"model": "抗截断-gemini-2.5-pro",
|
| 624 |
+
"messages": [
|
| 625 |
+
{"role": "user", "content": "長い記事を書いてください"}
|
| 626 |
+
],
|
| 627 |
+
"stream": true
|
| 628 |
+
}
|
| 629 |
+
```
|
| 630 |
+
|
| 631 |
+
---
|
| 632 |
+
|
| 633 |
+
## 🛠️ フロントエンド開発
|
| 634 |
+
|
| 635 |
+
パネルのフロントエンドソースは `frontend/` にあります(React + Vite + Tailwind CSS):
|
| 636 |
+
|
| 637 |
+
```bash
|
| 638 |
+
cd frontend
|
| 639 |
+
npm install
|
| 640 |
+
npm run dev # 開発モード、ポート3000、バックエンドAPIをプロキシ
|
| 641 |
+
npm run build # dist/ にビルド(本番で使用)
|
| 642 |
+
```
|
| 643 |
+
|
| 644 |
+
バックエンドは `dist/` のコンパイル済み静的ファイルを直接配信します。Node.jsランタイムは不要です。
|
| 645 |
+
|
| 646 |
+
## 💬 コミュニティ
|
| 647 |
+
|
| 648 |
+
QQグループへの参加をお待ちしています!
|
| 649 |
+
|
| 650 |
+
**QQグループ: 1083250744**
|
| 651 |
+
|
| 652 |
+
---
|
| 653 |
+
|
| 654 |
+
## ライセンスと免責事項
|
| 655 |
+
|
| 656 |
+
本プロジェクトは学習および研究目的のみに使用できます。本プロジェクトの使用は、以下に同意したことを意味します:
|
| 657 |
+
- 本プロジェクトをいかなる商用目的にも使用しないこと
|
| 658 |
+
- 本プロジェクトの使用に伴うすべてのリスクと責任を負うこと
|
| 659 |
+
- 関連するサービス利用規約および法的規制を遵守すること
|
| 660 |
+
|
| 661 |
+
プロジェクトの作者は、本プロジェクトの使用から生じるいかなる直接的または間接的な損害についても責任を負いません。
|
| 662 |
+
|
| 663 |
+
## ⚠️ ライセンスについて
|
| 664 |
+
|
| 665 |
+
**本プロジェクトはCooperative Non-Commercial License (CNC-1.0) の下でライセンスされています**
|
| 666 |
+
|
| 667 |
+
これは厳格な非商用オープンソースライセンスです。詳細は [LICENSE](../LICENSE) ファイルをご参照ください。
|
| 668 |
+
|
| 669 |
+
### ✅ 許可される用途:
|
| 670 |
+
- 個人の学習、研究、教育目的
|
| 671 |
+
- 非営利団体での利用
|
| 672 |
+
- オープンソースプロジェクトへの統合(同一ライセンスの遵守が必要)
|
| 673 |
+
- 学術研究および論文発表
|
| 674 |
+
|
| 675 |
+
### ❌ 禁止される用途:
|
| 676 |
+
- あらゆる形態の商用利用
|
| 677 |
+
- 年間売上が100万ドルを超える企業での利用
|
| 678 |
+
- ベンチャーキャピタルの出資を受けた企業または上場企業
|
| 679 |
+
- 有料サービスまたは製品の提供
|
| 680 |
+
- 商業的な競合利用
|
agy2api/frontend/index.html
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="zh-CN" class="dark">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<link rel="icon" href="./favicon.ico" type="image/x-icon" />
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
+
<title>AGY2API - Antigravity 控制面板</title>
|
| 8 |
+
<script>
|
| 9 |
+
// 反代把面板挂在子路径下时,访问地址可能不带末尾斜杠(如 /AGY2API),
|
| 10 |
+
// 相对路径资源会因此解析到根域;此处补齐为目录形式,保证资源请求落在同一子路径内。
|
| 11 |
+
// 需置于模块脚本之前:模块脚本加载失败时内联脚本仍会执行,跳转后才能正确加载
|
| 12 |
+
if (!location.pathname.endsWith("/")) {
|
| 13 |
+
location.replace(
|
| 14 |
+
location.pathname + "/" + location.search + location.hash
|
| 15 |
+
);
|
| 16 |
+
}
|
| 17 |
+
</script>
|
| 18 |
+
</head>
|
| 19 |
+
<body class="dark">
|
| 20 |
+
<div id="root"></div>
|
| 21 |
+
<script type="module" src="/src/main.jsx"></script>
|
| 22 |
+
</body>
|
| 23 |
+
</html>
|
agy2api/frontend/package-lock.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
agy2api/frontend/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "agy2api-frontend",
|
| 3 |
+
"private": true,
|
| 4 |
+
"version": "1.0.0",
|
| 5 |
+
"type": "module",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"dev": "vite",
|
| 8 |
+
"build": "vite build",
|
| 9 |
+
"preview": "vite preview"
|
| 10 |
+
},
|
| 11 |
+
"dependencies": {
|
| 12 |
+
"axios": "^1.6.2",
|
| 13 |
+
"lucide-react": "^0.294.0",
|
| 14 |
+
"react": "^18.2.0",
|
| 15 |
+
"react-dom": "^18.2.0"
|
| 16 |
+
},
|
| 17 |
+
"devDependencies": {
|
| 18 |
+
"@vitejs/plugin-react": "^4.2.1",
|
| 19 |
+
"autoprefixer": "^10.4.16",
|
| 20 |
+
"postcss": "^8.4.32",
|
| 21 |
+
"tailwindcss": "^3.3.6",
|
| 22 |
+
"vite": "^5.0.8"
|
| 23 |
+
}
|
| 24 |
+
}
|
agy2api/frontend/postcss.config.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default {
|
| 2 |
+
plugins: {
|
| 3 |
+
tailwindcss: {},
|
| 4 |
+
autoprefixer: {},
|
| 5 |
+
},
|
| 6 |
+
};
|
agy2api/frontend/public/favicon-32.png
ADDED
|
|
agy2api/frontend/public/favicon.ico
ADDED
|
|
agy2api/frontend/src/App.jsx
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {
|
| 2 |
+
LogOut,
|
| 3 |
+
Rocket,
|
| 4 |
+
Settings,
|
| 5 |
+
KeyRound,
|
| 6 |
+
Upload,
|
| 7 |
+
Info,
|
| 8 |
+
BarChart3,
|
| 9 |
+
} from "lucide-react";
|
| 10 |
+
import { useEffect, useState } from "react";
|
| 11 |
+
import api from "./api";
|
| 12 |
+
import Login from "./pages/Login";
|
| 13 |
+
import OAuth from "./pages/OAuth";
|
| 14 |
+
import Credentials from "./pages/Credentials";
|
| 15 |
+
import UploadPage from "./pages/Upload";
|
| 16 |
+
import Config from "./pages/Config";
|
| 17 |
+
import About from "./pages/About";
|
| 18 |
+
import UsageLogs from "./pages/UsageLogs";
|
| 19 |
+
|
| 20 |
+
export default function App() {
|
| 21 |
+
const [loggedIn, setLoggedIn] = useState(() => !!localStorage.getItem("panelToken"));
|
| 22 |
+
const [activeTab, setActiveTab] = useState("oauth");
|
| 23 |
+
const [version, setVersion] = useState(null);
|
| 24 |
+
const [checkingUpdate, setCheckingUpdate] = useState(false);
|
| 25 |
+
|
| 26 |
+
const checkUpdate = () => {
|
| 27 |
+
setCheckingUpdate(true);
|
| 28 |
+
api
|
| 29 |
+
.get("/version/info", { params: { check_update: "true" } })
|
| 30 |
+
.then((res) => setVersion(res.data))
|
| 31 |
+
.catch(() => {})
|
| 32 |
+
.finally(() => setCheckingUpdate(false));
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
useEffect(() => {
|
| 36 |
+
api
|
| 37 |
+
.get("/version/info")
|
| 38 |
+
.then((res) => setVersion(res.data))
|
| 39 |
+
.catch(() => {});
|
| 40 |
+
}, []);
|
| 41 |
+
|
| 42 |
+
const logout = () => {
|
| 43 |
+
localStorage.removeItem("panelToken");
|
| 44 |
+
setLoggedIn(false);
|
| 45 |
+
};
|
| 46 |
+
|
| 47 |
+
if (!loggedIn) {
|
| 48 |
+
return <Login onSuccess={() => setLoggedIn(true)} />;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
const tabs = [
|
| 52 |
+
{ id: "oauth", label: "OAuth 认证", icon: Rocket },
|
| 53 |
+
{ id: "credentials", label: "凭证管理", icon: KeyRound },
|
| 54 |
+
{ id: "upload", label: "批量导入", icon: Upload },
|
| 55 |
+
{ id: "usage-logs", label: "请求日志", icon: BarChart3 },
|
| 56 |
+
{ id: "config", label: "配置管理", icon: Settings },
|
| 57 |
+
{ id: "about", label: "项目信息", icon: Info },
|
| 58 |
+
];
|
| 59 |
+
|
| 60 |
+
return (
|
| 61 |
+
<div className="min-h-screen">
|
| 62 |
+
{/* 导航栏 */}
|
| 63 |
+
<nav className="bg-dark-900 border-b border-dark-700 sticky top-0 z-10">
|
| 64 |
+
<div className="max-w-6xl mx-auto px-4 py-4">
|
| 65 |
+
<div className="flex items-center justify-between">
|
| 66 |
+
<div className="flex items-center gap-3">
|
| 67 |
+
<div>
|
| 68 |
+
<span className="text-xl font-bold">AGY2API</span>
|
| 69 |
+
{version?.version && (
|
| 70 |
+
<span className="ml-2 text-xs text-gray-500">v{version.version}</span>
|
| 71 |
+
)}
|
| 72 |
+
</div>
|
| 73 |
+
</div>
|
| 74 |
+
<button
|
| 75 |
+
onClick={logout}
|
| 76 |
+
className="px-3 py-1.5 sm:px-4 sm:py-2 bg-red-600 hover:bg-red-700 text-white rounded-lg flex items-center gap-1 sm:gap-2 text-sm"
|
| 77 |
+
>
|
| 78 |
+
<LogOut size={16} />
|
| 79 |
+
<span className="hidden sm:inline">退出登录</span>
|
| 80 |
+
</button>
|
| 81 |
+
</div>
|
| 82 |
+
|
| 83 |
+
{/* Tab 导航 */}
|
| 84 |
+
<div className="flex items-center gap-1 sm:gap-2 mt-4 overflow-x-auto pb-1">
|
| 85 |
+
{tabs.map((tab) => {
|
| 86 |
+
const Icon = tab.icon;
|
| 87 |
+
return (
|
| 88 |
+
<button
|
| 89 |
+
key={tab.id}
|
| 90 |
+
onClick={() => setActiveTab(tab.id)}
|
| 91 |
+
className={`px-3 sm:px-4 py-2 text-xs sm:text-sm font-medium rounded-lg whitespace-nowrap flex items-center gap-1.5 transition-colors ${
|
| 92 |
+
activeTab === tab.id
|
| 93 |
+
? "bg-purple-600 text-white"
|
| 94 |
+
: "text-gray-400 hover:text-white hover:bg-dark-700"
|
| 95 |
+
}`}
|
| 96 |
+
>
|
| 97 |
+
<Icon size={15} />
|
| 98 |
+
{tab.label}
|
| 99 |
+
</button>
|
| 100 |
+
);
|
| 101 |
+
})}
|
| 102 |
+
</div>
|
| 103 |
+
</div>
|
| 104 |
+
</nav>
|
| 105 |
+
|
| 106 |
+
<div className="max-w-6xl mx-auto px-4 py-6">
|
| 107 |
+
{activeTab === "oauth" && <OAuth />}
|
| 108 |
+
{activeTab === "credentials" && <Credentials />}
|
| 109 |
+
{activeTab === "upload" && <UploadPage />}
|
| 110 |
+
{activeTab === "usage-logs" && <UsageLogs />}
|
| 111 |
+
{activeTab === "config" && <Config />}
|
| 112 |
+
{activeTab === "about" && <About version={version} onCheckUpdate={checkUpdate} checkingUpdate={checkingUpdate} />}
|
| 113 |
+
</div>
|
| 114 |
+
</div>
|
| 115 |
+
);
|
| 116 |
+
}
|
agy2api/frontend/src/api.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import axios from "axios";
|
| 2 |
+
import { getBasePath } from "./basePath.js";
|
| 3 |
+
|
| 4 |
+
const api = axios.create({
|
| 5 |
+
// 基径取面板页面所在路径(末尾补斜杠),反代到子路径下时请求仍落在同一子路径内
|
| 6 |
+
baseURL: getBasePath(),
|
| 7 |
+
timeout: 120000,
|
| 8 |
+
});
|
| 9 |
+
|
| 10 |
+
// 请求拦截器 - 添加token
|
| 11 |
+
api.interceptors.request.use((config) => {
|
| 12 |
+
const token = localStorage.getItem("panelToken");
|
| 13 |
+
if (token) {
|
| 14 |
+
config.headers.Authorization = `Bearer ${token}`;
|
| 15 |
+
}
|
| 16 |
+
return config;
|
| 17 |
+
});
|
| 18 |
+
|
| 19 |
+
// 响应拦截器 - 处理错误
|
| 20 |
+
api.interceptors.response.use(
|
| 21 |
+
(response) => response,
|
| 22 |
+
(error) => {
|
| 23 |
+
if (error.response?.status === 401) {
|
| 24 |
+
localStorage.removeItem("panelToken");
|
| 25 |
+
window.location.href = getBasePath();
|
| 26 |
+
}
|
| 27 |
+
return Promise.reject(error);
|
| 28 |
+
}
|
| 29 |
+
);
|
| 30 |
+
|
| 31 |
+
export default api;
|
agy2api/frontend/src/basePath.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// 计算控制面板的基径(以 "/" 开头并以 "/" 结尾)
|
| 2 |
+
// 面板是单入口应用,文档地址即挂载点:根路径部署为 "/",反代子路径部署为
|
| 3 |
+
// "/AGY2API/" 等形式。部分反代不补齐末尾斜杠,访问地址可能为 "/AGY2API",
|
| 4 |
+
// 此处统一补齐,保证 API 请求与页面跳转落在同一子路径下
|
| 5 |
+
export function getBasePath() {
|
| 6 |
+
const { pathname } = window.location;
|
| 7 |
+
return pathname.endsWith("/") ? pathname : pathname + "/";
|
| 8 |
+
}
|
agy2api/frontend/src/components/Modal.jsx
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useEffect } from "react";
|
| 2 |
+
import { AlertCircle, CheckCircle, Info, X } from "lucide-react";
|
| 3 |
+
|
| 4 |
+
/**
|
| 5 |
+
* 通用消息弹窗
|
| 6 |
+
* type: success / error / info
|
| 7 |
+
*/
|
| 8 |
+
export default function Modal({ type = "info", title, children, onClose }) {
|
| 9 |
+
useEffect(() => {
|
| 10 |
+
const onKey = (e) => {
|
| 11 |
+
if (e.key === "Escape") onClose?.();
|
| 12 |
+
};
|
| 13 |
+
document.addEventListener("keydown", onKey);
|
| 14 |
+
return () => document.removeEventListener("keydown", onKey);
|
| 15 |
+
}, [onClose]);
|
| 16 |
+
|
| 17 |
+
const styles = {
|
| 18 |
+
success: { icon: <CheckCircle size={20} className="text-green-400" />, border: "border-green-500/40", iconBg: "bg-green-500/15" },
|
| 19 |
+
error: { icon: <AlertCircle size={20} className="text-red-400" />, border: "border-red-500/40", iconBg: "bg-red-500/15" },
|
| 20 |
+
info: { icon: <Info size={20} className="text-blue-400" />, border: "border-blue-500/40", iconBg: "bg-blue-500/15" },
|
| 21 |
+
}[type] || {};
|
| 22 |
+
|
| 23 |
+
return (
|
| 24 |
+
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60" onClick={onClose}>
|
| 25 |
+
<div
|
| 26 |
+
className={`card max-w-md w-full border ${styles.border} p-0 overflow-hidden`}
|
| 27 |
+
onClick={(e) => e.stopPropagation()}
|
| 28 |
+
>
|
| 29 |
+
<div className="flex items-center justify-between px-4 py-3 border-b border-dark-700">
|
| 30 |
+
<div className="flex items-center gap-2">
|
| 31 |
+
<span className={`p-1.5 rounded-lg ${styles.iconBg}`}>{styles.icon}</span>
|
| 32 |
+
<h3 className="text-sm font-semibold text-gray-200">{title}</h3>
|
| 33 |
+
</div>
|
| 34 |
+
<button onClick={onClose} className="text-gray-400 hover:text-white">
|
| 35 |
+
<X size={16} />
|
| 36 |
+
</button>
|
| 37 |
+
</div>
|
| 38 |
+
<div className="px-4 py-3 text-sm text-gray-300 max-h-[60vh] overflow-y-auto break-all">
|
| 39 |
+
{children}
|
| 40 |
+
</div>
|
| 41 |
+
<div className="px-4 py-3 border-t border-dark-700 text-right">
|
| 42 |
+
<button onClick={onClose} className="btn btn-secondary text-xs px-4 py-1.5">
|
| 43 |
+
关闭
|
| 44 |
+
</button>
|
| 45 |
+
</div>
|
| 46 |
+
</div>
|
| 47 |
+
</div>
|
| 48 |
+
);
|
| 49 |
+
}
|
agy2api/frontend/src/components/Select.jsx
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Check, ChevronDown } from "lucide-react";
|
| 2 |
+
import { useEffect, useRef, useState } from "react";
|
| 3 |
+
|
| 4 |
+
/**
|
| 5 |
+
* 自定义下拉选择器:选项面板由自身渲染(非原生 select 弹窗),
|
| 6 |
+
* 面板与触发器左右边缘完全对齐;空间不足时自动向上弹出。
|
| 7 |
+
*/
|
| 8 |
+
export default function Select({ value, onChange, options, className = "", disabled = false }) {
|
| 9 |
+
const [open, setOpen] = useState(false);
|
| 10 |
+
const [placement, setPlacement] = useState({ dropUp: false, maxHeight: 240 });
|
| 11 |
+
const rootRef = useRef(null);
|
| 12 |
+
|
| 13 |
+
useEffect(() => {
|
| 14 |
+
if (!open) return;
|
| 15 |
+
const onPointerDown = (e) => {
|
| 16 |
+
if (rootRef.current && !rootRef.current.contains(e.target)) setOpen(false);
|
| 17 |
+
};
|
| 18 |
+
const onKey = (e) => {
|
| 19 |
+
if (e.key === "Escape") setOpen(false);
|
| 20 |
+
};
|
| 21 |
+
document.addEventListener("mousedown", onPointerDown);
|
| 22 |
+
document.addEventListener("touchstart", onPointerDown);
|
| 23 |
+
document.addEventListener("keydown", onKey);
|
| 24 |
+
return () => {
|
| 25 |
+
document.removeEventListener("mousedown", onPointerDown);
|
| 26 |
+
document.removeEventListener("touchstart", onPointerDown);
|
| 27 |
+
document.removeEventListener("keydown", onKey);
|
| 28 |
+
};
|
| 29 |
+
}, [open]);
|
| 30 |
+
|
| 31 |
+
const toggle = () => {
|
| 32 |
+
if (disabled) return;
|
| 33 |
+
if (!open && rootRef.current) {
|
| 34 |
+
const rect = rootRef.current.getBoundingClientRect();
|
| 35 |
+
const spaceBelow = window.innerHeight - rect.bottom;
|
| 36 |
+
const spaceAbove = rect.top;
|
| 37 |
+
// 面板高度按选项数量估算(每项约 40px,含内边距),上限 240px
|
| 38 |
+
const desired = Math.min(options.length * 40 + 10, 240);
|
| 39 |
+
if (spaceBelow >= desired || spaceBelow >= spaceAbove) {
|
| 40 |
+
setPlacement({ dropUp: false, maxHeight: Math.min(spaceBelow - 8, desired) });
|
| 41 |
+
} else {
|
| 42 |
+
setPlacement({ dropUp: true, maxHeight: Math.min(spaceAbove - 8, desired) });
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
setOpen((v) => !v);
|
| 46 |
+
};
|
| 47 |
+
|
| 48 |
+
const current = options.find((o) => o.value === value);
|
| 49 |
+
|
| 50 |
+
return (
|
| 51 |
+
<div ref={rootRef} className={`relative ${className}`}>
|
| 52 |
+
<button
|
| 53 |
+
type="button"
|
| 54 |
+
disabled={disabled}
|
| 55 |
+
aria-haspopup="listbox"
|
| 56 |
+
aria-expanded={open}
|
| 57 |
+
onClick={toggle}
|
| 58 |
+
className={`w-full flex items-center justify-between gap-1 text-left bg-dark-800 border border-dark-600 rounded-lg px-3 py-2 text-gray-200 text-xs sm:text-sm focus:outline-none focus:ring-2 focus:ring-purple-500/50 ${
|
| 59 |
+
open ? "ring-2 ring-purple-500/50 border-purple-500/50" : ""
|
| 60 |
+
} ${disabled ? "opacity-40 cursor-not-allowed" : "cursor-pointer"}`}
|
| 61 |
+
>
|
| 62 |
+
<span className="truncate">{current ? current.label : ""}</span>
|
| 63 |
+
<ChevronDown
|
| 64 |
+
size={14}
|
| 65 |
+
className={`shrink-0 text-gray-400 transition-transform duration-200 ${open ? "rotate-180" : ""}`}
|
| 66 |
+
/>
|
| 67 |
+
</button>
|
| 68 |
+
{open && (
|
| 69 |
+
<div
|
| 70 |
+
role="listbox"
|
| 71 |
+
style={{ maxHeight: Math.max(placement.maxHeight, 96) }}
|
| 72 |
+
className={`absolute left-0 right-0 z-20 overflow-y-auto rounded-lg border border-dark-600 bg-dark-800 py-1 shadow-xl ${
|
| 73 |
+
placement.dropUp ? "bottom-full mb-1" : "top-full mt-1"
|
| 74 |
+
}`}
|
| 75 |
+
>
|
| 76 |
+
{options.map((o) => (
|
| 77 |
+
<button
|
| 78 |
+
key={o.value}
|
| 79 |
+
type="button"
|
| 80 |
+
role="option"
|
| 81 |
+
aria-selected={o.value === value}
|
| 82 |
+
onClick={() => {
|
| 83 |
+
onChange(o.value);
|
| 84 |
+
setOpen(false);
|
| 85 |
+
}}
|
| 86 |
+
className={`flex w-full items-center justify-between gap-2 px-3 py-2.5 sm:py-2 text-left text-xs sm:text-sm ${
|
| 87 |
+
o.value === value
|
| 88 |
+
? "bg-purple-600/20 text-purple-300"
|
| 89 |
+
: "text-gray-200 hover:bg-dark-700"
|
| 90 |
+
}`}
|
| 91 |
+
>
|
| 92 |
+
<span className="truncate">{o.label}</span>
|
| 93 |
+
{o.value === value && <Check size={14} className="shrink-0" />}
|
| 94 |
+
</button>
|
| 95 |
+
))}
|
| 96 |
+
</div>
|
| 97 |
+
)}
|
| 98 |
+
</div>
|
| 99 |
+
);
|
| 100 |
+
}
|
agy2api/frontend/src/index.css
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@tailwind base;
|
| 2 |
+
@tailwind components;
|
| 3 |
+
@tailwind utilities;
|
| 4 |
+
|
| 5 |
+
body {
|
| 6 |
+
@apply bg-dark-950 text-gray-100;
|
| 7 |
+
font-family:
|
| 8 |
+
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
/* 自定义滚动条 */
|
| 12 |
+
::-webkit-scrollbar {
|
| 13 |
+
width: 8px;
|
| 14 |
+
height: 8px;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
::-webkit-scrollbar-track {
|
| 18 |
+
@apply bg-dark-900;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
::-webkit-scrollbar-thumb {
|
| 22 |
+
@apply bg-dark-600 rounded-full;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
::-webkit-scrollbar-thumb:hover {
|
| 26 |
+
@apply bg-dark-500;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
/* 输入框聚焦样式 */
|
| 30 |
+
input:focus,
|
| 31 |
+
textarea:focus,
|
| 32 |
+
select:focus {
|
| 33 |
+
@apply outline-none ring-2 ring-purple-500/50;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
/* 按钮基础样式 */
|
| 37 |
+
.btn {
|
| 38 |
+
@apply px-4 py-2 rounded-lg font-medium transition-all duration-200;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
.btn-primary {
|
| 42 |
+
@apply bg-purple-600 hover:bg-purple-700 text-white;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
.btn-secondary {
|
| 46 |
+
@apply bg-dark-700 hover:bg-dark-600 text-gray-200;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
.btn-danger {
|
| 50 |
+
@apply bg-red-600 hover:bg-red-700 text-white;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
/* 卡片样式 */
|
| 54 |
+
.card {
|
| 55 |
+
@apply bg-dark-900 border border-dark-700 rounded-xl p-6;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/* 表格样式 */
|
| 59 |
+
.table-container {
|
| 60 |
+
@apply overflow-x-auto rounded-lg border border-dark-700;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
table {
|
| 64 |
+
@apply w-full;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
th {
|
| 68 |
+
@apply bg-dark-800 px-4 py-3 text-left text-sm font-medium text-gray-400;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
td {
|
| 72 |
+
@apply px-4 py-3 text-sm border-t border-dark-700;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
tr:hover td {
|
| 76 |
+
@apply bg-dark-800/50;
|
| 77 |
+
}
|
agy2api/frontend/src/main.jsx
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from "react";
|
| 2 |
+
import ReactDOM from "react-dom/client";
|
| 3 |
+
import App from "./App";
|
| 4 |
+
import "./index.css";
|
| 5 |
+
|
| 6 |
+
ReactDOM.createRoot(document.getElementById("root")).render(
|
| 7 |
+
<React.StrictMode>
|
| 8 |
+
<App />
|
| 9 |
+
</React.StrictMode>,
|
| 10 |
+
);
|
agy2api/frontend/src/pages/About.jsx
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { ExternalLink, Github, Info, RefreshCw, Rocket, Zap } from "lucide-react";
|
| 2 |
+
import { getBasePath } from "../basePath.js";
|
| 3 |
+
|
| 4 |
+
export default function About({ version, onCheckUpdate, checkingUpdate }) {
|
| 5 |
+
const apiBase = `${window.location.origin}${getBasePath()}`;
|
| 6 |
+
const apiEndpoints = [
|
| 7 |
+
{ label: "OpenAI 格式", value: `${apiBase}v1/chat/completions` },
|
| 8 |
+
{ label: "Gemini 格式", value: `${apiBase}v1beta/models` },
|
| 9 |
+
{ label: "Claude 格式", value: `${apiBase}v1/messages` },
|
| 10 |
+
];
|
| 11 |
+
|
| 12 |
+
const copyText = (text) => {
|
| 13 |
+
navigator.clipboard.writeText(text);
|
| 14 |
+
};
|
| 15 |
+
|
| 16 |
+
return (
|
| 17 |
+
<div className="space-y-6">
|
| 18 |
+
{/* API 端点 */}
|
| 19 |
+
<div className="card p-4 sm:p-6">
|
| 20 |
+
<h3 className="text-sm font-medium text-gray-400 mb-3 flex items-center gap-2">
|
| 21 |
+
<Zap size={16} className="text-amber-400" />
|
| 22 |
+
API 端点(点击复制)
|
| 23 |
+
</h3>
|
| 24 |
+
<div className="space-y-2">
|
| 25 |
+
{apiEndpoints.map((ep) => (
|
| 26 |
+
<div key={ep.label} className="flex flex-col sm:flex-row sm:items-center gap-1 sm:gap-3 text-sm">
|
| 27 |
+
<span className="text-gray-500 sm:w-24 flex-shrink-0">{ep.label}</span>
|
| 28 |
+
<code
|
| 29 |
+
className="bg-dark-800 border border-dark-600 rounded px-2 py-1 text-xs text-gray-300 cursor-pointer hover:text-white break-all"
|
| 30 |
+
onClick={() => copyText(ep.value)}
|
| 31 |
+
>
|
| 32 |
+
{ep.value}
|
| 33 |
+
</code>
|
| 34 |
+
</div>
|
| 35 |
+
))}
|
| 36 |
+
</div>
|
| 37 |
+
</div>
|
| 38 |
+
|
| 39 |
+
{/* 项目简介 */}
|
| 40 |
+
<div className="card">
|
| 41 |
+
<div className="flex items-center gap-3 mb-4">
|
| 42 |
+
<div className="inline-flex items-center justify-center w-12 h-12 rounded-2xl bg-purple-600/20">
|
| 43 |
+
<Rocket className="w-7 h-7 text-purple-400" />
|
| 44 |
+
</div>
|
| 45 |
+
<div>
|
| 46 |
+
<h2 className="text-2xl font-bold text-white">AGY2API</h2>
|
| 47 |
+
<p className="text-gray-400 text-sm">
|
| 48 |
+
{version?.version ? `版本: ${version.version}` : "Antigravity API 代理服务"}
|
| 49 |
+
</p>
|
| 50 |
+
</div>
|
| 51 |
+
</div>
|
| 52 |
+
<p className="text-gray-400 text-sm leading-relaxed">
|
| 53 |
+
将 Google Antigravity API 转换为 OpenAI、Gemini 和 Anthropic
|
| 54 |
+
兼容格式的代理工具。支持多账户管理(邮箱去重)、自动轮换、模型级冷却、凭证导入导出等功能。
|
| 55 |
+
</p>
|
| 56 |
+
<div className="flex flex-wrap items-center gap-4 mt-4">
|
| 57 |
+
<a
|
| 58 |
+
href="https://github.com/su-kaka/agy2api"
|
| 59 |
+
target="_blank"
|
| 60 |
+
rel="noopener noreferrer"
|
| 61 |
+
className="text-purple-400 hover:text-purple-300 text-sm flex items-center gap-1.5"
|
| 62 |
+
>
|
| 63 |
+
<Github size={15} />
|
| 64 |
+
GitHub 仓库
|
| 65 |
+
<ExternalLink size={12} />
|
| 66 |
+
</a>
|
| 67 |
+
<button
|
| 68 |
+
onClick={onCheckUpdate}
|
| 69 |
+
disabled={checkingUpdate}
|
| 70 |
+
className="text-blue-400 hover:text-blue-300 text-sm flex items-center gap-1.5 disabled:opacity-50"
|
| 71 |
+
>
|
| 72 |
+
{checkingUpdate ? (
|
| 73 |
+
<Info size={14} className="animate-pulse" />
|
| 74 |
+
) : (
|
| 75 |
+
<RefreshCw size={14} />
|
| 76 |
+
)}
|
| 77 |
+
{checkingUpdate ? "检查中..." : "检查更新"}
|
| 78 |
+
</button>
|
| 79 |
+
{version?.check_update && version?.has_update && (
|
| 80 |
+
<span className="text-emerald-400 text-sm flex items-center gap-1.5">
|
| 81 |
+
<Info size={14} />
|
| 82 |
+
有新版本可用: {version.latest_version}
|
| 83 |
+
</span>
|
| 84 |
+
)}
|
| 85 |
+
{version?.check_update && version?.has_update === false && (
|
| 86 |
+
<span className="text-gray-400 text-sm flex items-center gap-1.5">
|
| 87 |
+
<Info size={14} />
|
| 88 |
+
已是最新版本
|
| 89 |
+
</span>
|
| 90 |
+
)}
|
| 91 |
+
</div>
|
| 92 |
+
</div>
|
| 93 |
+
|
| 94 |
+
{/* 主要功能 */}
|
| 95 |
+
<div className="card">
|
| 96 |
+
<h3 className="text-lg font-semibold text-blue-400 mb-4">✨ 主要功能</h3>
|
| 97 |
+
<div className="grid md:grid-cols-2 gap-4 text-sm">
|
| 98 |
+
<div className="space-y-3">
|
| 99 |
+
<div className="text-gray-300">
|
| 100 |
+
<span className="text-amber-400">⚡</span>{" "}
|
| 101 |
+
<strong>多格式兼容:</strong>OpenAI / Gemini / Anthropic 三种 API 格式
|
| 102 |
+
</div>
|
| 103 |
+
<div className="text-gray-300">
|
| 104 |
+
<span className="text-cyan-400">🔄</span>{" "}
|
| 105 |
+
<strong>自动轮换:</strong>随机负载均衡,自动跳过冷却和禁用的凭证
|
| 106 |
+
</div>
|
| 107 |
+
<div className="text-gray-300">
|
| 108 |
+
<span className="text-emerald-400">🛡️</span>{" "}
|
| 109 |
+
<strong>自动封禁:</strong>遇到指定错误码自动禁用异常凭证
|
| 110 |
+
</div>
|
| 111 |
+
<div className="text-gray-300">
|
| 112 |
+
<span className="text-purple-400">❄️</span>{" "}
|
| 113 |
+
<strong>模型级冷却:</strong>429 错误自动设置模型级 CD
|
| 114 |
+
</div>
|
| 115 |
+
</div>
|
| 116 |
+
<div className="space-y-3">
|
| 117 |
+
<div className="text-gray-300">
|
| 118 |
+
<span className="text-red-400">✂️</span>{" "}
|
| 119 |
+
<strong>抗截断:</strong>"抗截断-" 前缀模型自动续传截断的响应
|
| 120 |
+
</div>
|
| 121 |
+
<div className="text-gray-300">
|
| 122 |
+
<span className="text-emerald-400">📊</span>{" "}
|
| 123 |
+
<strong>实时监控:</strong>凭证状态、错误码、额度查询
|
| 124 |
+
</div>
|
| 125 |
+
<div className="text-gray-300">
|
| 126 |
+
<span className="text-gray-400">📱</span>{" "}
|
| 127 |
+
<strong>响应式界面:</strong>桌面/移动端自适应
|
| 128 |
+
</div>
|
| 129 |
+
</div>
|
| 130 |
+
</div>
|
| 131 |
+
</div>
|
| 132 |
+
|
| 133 |
+
{/* 交流群 */}
|
| 134 |
+
<div className="card text-center">
|
| 135 |
+
<h3 className="text-lg font-semibold text-blue-400 mb-4">💬 交流群</h3>
|
| 136 |
+
<p className="text-gray-400 text-sm mb-3">欢迎加入 QQ 群交流讨论!</p>
|
| 137 |
+
<div className="inline-block bg-white rounded-xl p-3">
|
| 138 |
+
<img
|
| 139 |
+
src={`${getBasePath()}docs/qq-group.jpg`}
|
| 140 |
+
alt="QQ 群二维码"
|
| 141 |
+
className="w-40 h-40 rounded-lg"
|
| 142 |
+
/>
|
| 143 |
+
</div>
|
| 144 |
+
<p className="text-blue-400 font-semibold mt-3">QQ 群号:1083250744</p>
|
| 145 |
+
</div>
|
| 146 |
+
|
| 147 |
+
{/* 使用声明 */}
|
| 148 |
+
<div className="bg-amber-500/10 border border-amber-500/30 rounded-xl p-5">
|
| 149 |
+
<div className="text-amber-400 font-medium mb-2">⚠️ 使用声明</div>
|
| 150 |
+
<p className="text-sm text-amber-400/80">
|
| 151 |
+
本项目仅供学习研究使用,禁止商业用途和倒卖。
|
| 152 |
+
</p>
|
| 153 |
+
</div>
|
| 154 |
+
|
| 155 |
+
{/* 版本信息 */}
|
| 156 |
+
{version && (
|
| 157 |
+
<div className="card">
|
| 158 |
+
<h3 className="text-base font-semibold text-gray-300 mb-3">版本信息</h3>
|
| 159 |
+
<div className="grid grid-cols-2 gap-3 text-sm">
|
| 160 |
+
<div className="text-gray-500">
|
| 161 |
+
当前版本: <span className="text-gray-300">{version.version || "-"}</span>
|
| 162 |
+
</div>
|
| 163 |
+
<div className="text-gray-500">
|
| 164 |
+
构建哈希: <span className="text-gray-300">{version.full_hash || "-"}</span>
|
| 165 |
+
</div>
|
| 166 |
+
<div className="text-gray-500">
|
| 167 |
+
更新说明: <span className="text-gray-300">{version.message || "-"}</span>
|
| 168 |
+
</div>
|
| 169 |
+
<div className="text-gray-500">
|
| 170 |
+
构建日期: <span className="text-gray-300">{version.date || "-"}</span>
|
| 171 |
+
</div>
|
| 172 |
+
</div>
|
| 173 |
+
</div>
|
| 174 |
+
)}
|
| 175 |
+
</div>
|
| 176 |
+
);
|
| 177 |
+
}
|
agy2api/frontend/src/pages/Config.jsx
ADDED
|
@@ -0,0 +1,512 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Loader2, Plus, RefreshCw, Save, Trash2 } from "lucide-react";
|
| 2 |
+
import { useEffect, useRef, useState } from "react";
|
| 3 |
+
import Modal from "../components/Modal";
|
| 4 |
+
import Select from "../components/Select";
|
| 5 |
+
import api from "../api";
|
| 6 |
+
|
| 7 |
+
// 错误码输入:编辑期间保留原始文本,仅在按键时把已解析的数组回写配置(保证保存时取到最新值),
|
| 8 |
+
// 失焦时再归一化显示。原实现在每次按键即时解析并回写数组,导致分隔符与未成形的中间输入被即时
|
| 9 |
+
// 过滤/截断,无法输入多个错误码,也无法输入小于 100 的中间数字。
|
| 10 |
+
function CsvNumbersField({ value, onChange, placeholder }) {
|
| 11 |
+
const toText = (v) => (Array.isArray(v) ? v.join(", ") : (v ?? ""));
|
| 12 |
+
const [text, setText] = useState(() => toText(value));
|
| 13 |
+
const focusedRef = useRef(false);
|
| 14 |
+
|
| 15 |
+
// 仅在非编辑态(失焦)时同步外部配置变化,避免编辑过程中被即时覆盖
|
| 16 |
+
useEffect(() => {
|
| 17 |
+
if (!focusedRef.current) setText(toText(value));
|
| 18 |
+
}, [value]);
|
| 19 |
+
|
| 20 |
+
const commitText = (raw) => {
|
| 21 |
+
const nums = raw
|
| 22 |
+
.split(/[,\s]+/)
|
| 23 |
+
.map((x) => parseInt(x, 10))
|
| 24 |
+
.filter((n) => Number.isInteger(n) && n >= 100 && n <= 599);
|
| 25 |
+
onChange([...new Set(nums)].sort((a, b) => a - b));
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
return (
|
| 29 |
+
<input
|
| 30 |
+
type="text"
|
| 31 |
+
value={text}
|
| 32 |
+
onFocus={() => {
|
| 33 |
+
focusedRef.current = true;
|
| 34 |
+
}}
|
| 35 |
+
onChange={(e) => {
|
| 36 |
+
const raw = e.target.value;
|
| 37 |
+
setText(raw);
|
| 38 |
+
commitText(raw);
|
| 39 |
+
}}
|
| 40 |
+
onBlur={() => {
|
| 41 |
+
focusedRef.current = false;
|
| 42 |
+
commitText(text);
|
| 43 |
+
}}
|
| 44 |
+
placeholder={placeholder}
|
| 45 |
+
className="w-full sm:w-64 px-3 py-2 bg-dark-800 border border-dark-600 rounded-lg text-sm text-white placeholder-gray-500 font-mono"
|
| 46 |
+
/>
|
| 47 |
+
);
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
// 多行文本(敏感词 / IP 白名单等,每行一条):编辑期间保留原始文本(允许末尾空行与连续回车),
|
| 51 |
+
// 仅在按键时把清洗后的数组回写配置(保证保存时取到最新值),失焦时再归一化显示。
|
| 52 |
+
// 原实现在每次按键即时 split + 过滤空行,末尾按回车产生的新空行被立即移除,
|
| 53 |
+
// 导致"最后一行按回车没反应"、无法换行新增词条。
|
| 54 |
+
function LinesField({ value, onChange, placeholder }) {
|
| 55 |
+
const toText = (v) => (Array.isArray(v) ? v.join("\n") : v ?? "");
|
| 56 |
+
const [text, setText] = useState(() => toText(value));
|
| 57 |
+
const focusedRef = useRef(false);
|
| 58 |
+
|
| 59 |
+
// 仅在非编辑态(失焦)时同步外部配置变化,避免编辑过程中被即时覆盖
|
| 60 |
+
useEffect(() => {
|
| 61 |
+
if (!focusedRef.current) setText(toText(value));
|
| 62 |
+
}, [value]);
|
| 63 |
+
|
| 64 |
+
const commitText = (raw) => {
|
| 65 |
+
const lines = raw
|
| 66 |
+
.split(/\r?\n/)
|
| 67 |
+
.map((w) => w.replace(/\s+$/, ""))
|
| 68 |
+
.filter((w) => w.trim() !== "");
|
| 69 |
+
onChange(lines);
|
| 70 |
+
};
|
| 71 |
+
|
| 72 |
+
return (
|
| 73 |
+
<textarea
|
| 74 |
+
value={text}
|
| 75 |
+
onFocus={() => {
|
| 76 |
+
focusedRef.current = true;
|
| 77 |
+
}}
|
| 78 |
+
onChange={(e) => {
|
| 79 |
+
const raw = e.target.value;
|
| 80 |
+
setText(raw);
|
| 81 |
+
commitText(raw);
|
| 82 |
+
}}
|
| 83 |
+
onBlur={() => {
|
| 84 |
+
focusedRef.current = false;
|
| 85 |
+
commitText(text);
|
| 86 |
+
}}
|
| 87 |
+
placeholder={placeholder}
|
| 88 |
+
rows={6}
|
| 89 |
+
className="w-full px-3 py-2 bg-dark-800 border border-dark-600 rounded-lg text-sm text-white placeholder-gray-500 font-mono"
|
| 90 |
+
/>
|
| 91 |
+
);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
const CONFIG_GROUPS = [
|
| 95 |
+
{
|
| 96 |
+
title: "服务器配置",
|
| 97 |
+
fields: [
|
| 98 |
+
{ key: "host", label: "服务器主机地址", type: "text", note: "服务器监听的主机地址,0.0.0.0表示监听所有接口(重启生效)" },
|
| 99 |
+
{ key: "port", label: "服务器端口", type: "number", note: "服务器监听的端口号(重启生效)" },
|
| 100 |
+
{ key: "api_password", label: "API 访问密码", type: "text", note: "聊天API访问密码,用于 OpenAI / Gemini / Claude 端点认证" },
|
| 101 |
+
{ key: "panel_password", label: "控制面板密码", type: "text", note: "控制面板访问密码" },
|
| 102 |
+
],
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
title: "IP 白名单",
|
| 106 |
+
fields: [
|
| 107 |
+
{ key: "ip_whitelist_enabled", label: "启用 IP 白名单", type: "bool", note: "开启后仅白名单内的 IP 可访问面板和 API,其余 IP 直接 403。留空列表或关闭开关则不限制。保存后立即生效(热更新)" },
|
| 108 |
+
{ key: "ip_whitelist", label: "IP 白名单列表", type: "textarea", showIf: (cfg) => !!cfg.ip_whitelist_enabled, note: "每行一条,支持单个 IP、CIDR 网段、起止范围(- 或 ~ 分隔),IPv4 / IPv6 均可", placeholder: "例如:\n127.0.0.1\n192.168.1.0/24\n10.0.0.1-10.0.0.100\n::1\n2001:db8::/32" },
|
| 109 |
+
],
|
| 110 |
+
},
|
| 111 |
+
{
|
| 112 |
+
title: "基础配置",
|
| 113 |
+
fields: [
|
| 114 |
+
{ key: "credentials_dir", label: "凭证目录路径", type: "text", note: "存储认证文件的目录路径" },
|
| 115 |
+
{ key: "proxy", label: "代理设置", type: "text", note: "支持 http/https/socks5/socks5h,可带账号密码(user:pass@host:port),留空不使用(重启生效)", placeholder: "http://user:pass@proxy:port ��� socks5h://proxy:port" },
|
| 116 |
+
],
|
| 117 |
+
},
|
| 118 |
+
{
|
| 119 |
+
title: "端点配置",
|
| 120 |
+
fields: [
|
| 121 |
+
{ key: "oauth_proxy_url", label: "OAuth Endpoint", type: "text", note: "Google OAuth2 端点,用于 token 获取和刷新" },
|
| 122 |
+
{ key: "googleapis_proxy_url", label: "Google APIs Endpoint", type: "text", note: "Google APIs 端点" },
|
| 123 |
+
{ key: "antigravity_api_url", label: "Antigravity API Endpoint", type: "text", note: "Antigravity API 端点" },
|
| 124 |
+
],
|
| 125 |
+
},
|
| 126 |
+
{
|
| 127 |
+
title: "自动封禁配置",
|
| 128 |
+
fields: [
|
| 129 |
+
{ key: "auto_ban_enabled", label: "启用自动封禁", type: "bool", note: "遇到指定错误码时自动禁用凭证" },
|
| 130 |
+
{ key: "auto_ban_error_codes", label: "自动封禁错误码", type: "text", note: "JSON 数组格式,如 [403, 400]" },
|
| 131 |
+
],
|
| 132 |
+
},
|
| 133 |
+
{
|
| 134 |
+
title: "重试配置",
|
| 135 |
+
fields: [
|
| 136 |
+
{ key: "retry_429_enabled", label: "启用错误重试", type: "bool", note: "遇到错误时自动重试" },
|
| 137 |
+
{ key: "retry_429_max_retries", label: "最大重试次数", type: "number", note: "遇到错误时的最大重试次数" },
|
| 138 |
+
{ key: "retry_429_interval", label: "重试间隔(秒)", type: "number", note: "两次重试间的等待秒数,允许 0(立即重试),范围 0-3600" },
|
| 139 |
+
],
|
| 140 |
+
},
|
| 141 |
+
{
|
| 142 |
+
title: "凭证选择模式",
|
| 143 |
+
fields: [
|
| 144 |
+
{
|
| 145 |
+
key: "credential_select_mode",
|
| 146 |
+
label: "选择模式",
|
| 147 |
+
type: "select",
|
| 148 |
+
note: "决定每次 API 请求如何挑选凭证",
|
| 149 |
+
options: [
|
| 150 |
+
{ value: "random", label: "完全随机" },
|
| 151 |
+
{ value: "cache", label: "缓存匹配(推荐)" },
|
| 152 |
+
{ value: "sticky", label: "凭证不变直到 CD" },
|
| 153 |
+
],
|
| 154 |
+
descriptions: {
|
| 155 |
+
random: "完全随机负载均衡:每次请求从可用凭证中随机挑选一个,最均匀地分摊负载,但相同会话可能命中不同凭证,无法利用上游 prompt cache。",
|
| 156 |
+
cache: "缓存匹配(默认推荐):以\"模型 + system 指令(或首条 user 消息)\"哈希出会话 key,相同会话始终复用同一凭证——命中 Google 上游的 prompt cache,长对话更快、更省 token。凭证进入 CD 后自动切换并重新绑定。建议搭配 Redis(REDIS_URL)实现多实例共享。",
|
| 157 |
+
sticky: "凭证粘性:所有请求锁定同一个凭证,直到该凭证进入冷却(CD)或被禁用才切换到下一个。适合最大化单凭证的缓存命中,但负载不均——单凭证扛满全量请求,其余凭证闲置。",
|
| 158 |
+
},
|
| 159 |
+
},
|
| 160 |
+
],
|
| 161 |
+
},
|
| 162 |
+
{
|
| 163 |
+
title: "响应配置",
|
| 164 |
+
fields: [
|
| 165 |
+
{ key: "return_thoughts_to_frontend", label: "返回思维链到前端", type: "bool", note: "启用后思维链会在响应中返回;禁用后过滤掉" },
|
| 166 |
+
],
|
| 167 |
+
},
|
| 168 |
+
{
|
| 169 |
+
title: "抗截断配置",
|
| 170 |
+
fields: [
|
| 171 |
+
{ key: "anti_truncation_max_attempts", label: "抗截断最大重试次数", type: "number", note: "检测到输出截断时的最大续传尝试次数(1-10)。使用'抗截断-'前缀的模型生效" },
|
| 172 |
+
],
|
| 173 |
+
},
|
| 174 |
+
{
|
| 175 |
+
title: "敏感词过滤",
|
| 176 |
+
fields: [
|
| 177 |
+
{ key: "sensitive_words_enabled", label: "启用敏感词过滤", type: "bool", note: "请求中命中敏感词的内容会被替换为空,避免触发 Google API 端点的敏感词拦截" },
|
| 178 |
+
{ key: "sensitive_words", label: "敏感词列表", type: "textarea", showIf: (cfg) => !!cfg.sensitive_words_enabled, note: "每行一个词或短语,不区分大小写,支持中文。命中后整词替换为空。保存后立即生效(热更新)", placeholder: "例如:\nsensitive word\n敏感词\n另一个词" },
|
| 179 |
+
],
|
| 180 |
+
},
|
| 181 |
+
{
|
| 182 |
+
title: "模型名复写",
|
| 183 |
+
fields: [
|
| 184 |
+
{ key: "model_rewrite_enabled", label: "启用模型名复写", type: "bool", note: "开启后按规则匹配请求中的模型名(支持正则),命中则替换为规则指定的模型名。常用于把客户端固定模型名映射到实际可用的上游模型。保存后立即生效(热更新)" },
|
| 185 |
+
{
|
| 186 |
+
key: "model_rewrite_rules",
|
| 187 |
+
label: "复写规则",
|
| 188 |
+
type: "rules",
|
| 189 |
+
showIf: (cfg) => !!cfg.model_rewrite_enabled,
|
| 190 |
+
note: "每行一条规则:匹配正则 + 替换模型名。自上而下首条命中即生效,替换支持正则反向引用(如 \\1)",
|
| 191 |
+
},
|
| 192 |
+
],
|
| 193 |
+
},
|
| 194 |
+
{
|
| 195 |
+
title: "请求日志",
|
| 196 |
+
fields: [
|
| 197 |
+
{ key: "usage_log_enabled", label: "启用请求日志", type: "bool", note: "记录每次 API 请求(模型、凭证、token 用量、耗时、状态)到数据库,在\"请求日志\"页面查看。日志不自动清理,可在该页面手动清理或清空" },
|
| 198 |
+
{ key: "request_log_enabled", label: "启用请求体详细日志", type: "bool", note: "开启后,当请求命中下方错误码时,把发往上游的完整请求头(已脱敏)与请求体保存为 JSON 文件(data/request_logs/)。主要用于请求体错误时排查 debug;清理/清空日志时会同步删除这些文件" },
|
| 199 |
+
{ key: "request_log_error_codes", label: "详细日志错误码", type: "csv_numbers", showIf: (cfg) => !!cfg.request_log_enabled, note: "仅当最终响应状态码命中此列表时记录详细日志,逗号分隔,如 400, 429。留空默认只记录 400", placeholder: "400, 429" },
|
| 200 |
+
],
|
| 201 |
+
},
|
| 202 |
+
];
|
| 203 |
+
|
| 204 |
+
export default function Config() {
|
| 205 |
+
const [config, setConfig] = useState({});
|
| 206 |
+
const [envLocked, setEnvLocked] = useState([]);
|
| 207 |
+
const [loading, setLoading] = useState(true);
|
| 208 |
+
const [saving, setSaving] = useState(false);
|
| 209 |
+
const [message, setMessage] = useState(null);
|
| 210 |
+
|
| 211 |
+
useEffect(() => {
|
| 212 |
+
loadConfig();
|
| 213 |
+
}, []);
|
| 214 |
+
|
| 215 |
+
const loadConfig = async ({ silent = false } = {}) => {
|
| 216 |
+
setLoading(true);
|
| 217 |
+
try {
|
| 218 |
+
const res = await api.get("/config/get");
|
| 219 |
+
setConfig(res.data.config || {});
|
| 220 |
+
setEnvLocked(res.data.env_locked || []);
|
| 221 |
+
if (!silent) setMessage(null);
|
| 222 |
+
} catch (err) {
|
| 223 |
+
setMessage({ type: "error", text: err.response?.data?.detail || "加载配置失败" });
|
| 224 |
+
} finally {
|
| 225 |
+
setLoading(false);
|
| 226 |
+
}
|
| 227 |
+
};
|
| 228 |
+
|
| 229 |
+
const saveConfig = async () => {
|
| 230 |
+
setSaving(true);
|
| 231 |
+
try {
|
| 232 |
+
const res = await api.post("/config/save", { config });
|
| 233 |
+
setMessage({ type: "success", text: res.data.message || "配置保存成功" });
|
| 234 |
+
// 静默刷新配置(不清空刚显示的弹窗消息)
|
| 235 |
+
await loadConfig({ silent: true });
|
| 236 |
+
} catch (err) {
|
| 237 |
+
setMessage({ type: "error", text: err.response?.data?.detail || "保存配置失败" });
|
| 238 |
+
} finally {
|
| 239 |
+
setSaving(false);
|
| 240 |
+
}
|
| 241 |
+
};
|
| 242 |
+
|
| 243 |
+
const setField = (key, value) => {
|
| 244 |
+
setConfig((prev) => ({ ...prev, [key]: value }));
|
| 245 |
+
};
|
| 246 |
+
|
| 247 |
+
// 一键镜像/官方端点(墙内访问 Google 官方端点的反代方案)
|
| 248 |
+
const MIRROR_BASE = "https://gcli-api.sukaka.top";
|
| 249 |
+
const OFFICIAL_ENDPOINTS = {
|
| 250 |
+
oauth_proxy_url: "https://oauth2.googleapis.com",
|
| 251 |
+
googleapis_proxy_url: "https://www.googleapis.com",
|
| 252 |
+
antigravity_api_url: "https://daily-cloudcode-pa.googleapis.com",
|
| 253 |
+
};
|
| 254 |
+
const MIRROR_PATHS = {
|
| 255 |
+
oauth_proxy_url: "/oauth2",
|
| 256 |
+
googleapis_proxy_url: "/googleapis",
|
| 257 |
+
antigravity_api_url: "/daily-cloudcode-pa",
|
| 258 |
+
};
|
| 259 |
+
|
| 260 |
+
const useMirrorUrls = () => {
|
| 261 |
+
setConfig((prev) => {
|
| 262 |
+
const next = { ...prev };
|
| 263 |
+
for (const [key, path] of Object.entries(MIRROR_PATHS)) {
|
| 264 |
+
if (!envLocked.includes(key)) next[key] = MIRROR_BASE + path;
|
| 265 |
+
}
|
| 266 |
+
return next;
|
| 267 |
+
});
|
| 268 |
+
};
|
| 269 |
+
|
| 270 |
+
const restoreOfficialUrls = () => {
|
| 271 |
+
setConfig((prev) => {
|
| 272 |
+
const next = { ...prev };
|
| 273 |
+
for (const [key, url] of Object.entries(OFFICIAL_ENDPOINTS)) {
|
| 274 |
+
if (!envLocked.includes(key)) next[key] = url;
|
| 275 |
+
}
|
| 276 |
+
return next;
|
| 277 |
+
});
|
| 278 |
+
};
|
| 279 |
+
|
| 280 |
+
const renderField = (field) => {
|
| 281 |
+
const isLocked = envLocked.includes(field.key);
|
| 282 |
+
const value = config[field.key] ?? "";
|
| 283 |
+
|
| 284 |
+
if (isLocked) {
|
| 285 |
+
return (
|
| 286 |
+
<div className="text-xs text-amber-400/80 bg-amber-500/10 border border-amber-500/20 rounded-lg px-3 py-2">
|
| 287 |
+
该配置已被环境变量锁定,修改环境变量后重启生效
|
| 288 |
+
</div>
|
| 289 |
+
);
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
if (field.type === "bool") {
|
| 293 |
+
return (
|
| 294 |
+
<label className="flex items-center gap-3 cursor-pointer select-none">
|
| 295 |
+
<button
|
| 296 |
+
type="button"
|
| 297 |
+
onClick={() => setField(field.key, !value)}
|
| 298 |
+
className={`relative w-11 h-6 rounded-full transition-colors ${
|
| 299 |
+
value ? "bg-purple-600" : "bg-dark-600"
|
| 300 |
+
}`}
|
| 301 |
+
>
|
| 302 |
+
<span
|
| 303 |
+
className={`absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform ${
|
| 304 |
+
value ? "translate-x-5" : ""
|
| 305 |
+
}`}
|
| 306 |
+
/>
|
| 307 |
+
</button>
|
| 308 |
+
<span className="text-sm text-gray-300">{value ? "已启用" : "已禁用"}</span>
|
| 309 |
+
</label>
|
| 310 |
+
);
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
if (field.type === "select") {
|
| 314 |
+
const current = field.options.find((o) => o.value === value) || field.options[0];
|
| 315 |
+
return (
|
| 316 |
+
<div className="space-y-2">
|
| 317 |
+
<Select
|
| 318 |
+
value={current?.value ?? ""}
|
| 319 |
+
onChange={(v) => setField(field.key, v)}
|
| 320 |
+
options={field.options}
|
| 321 |
+
className="w-full sm:w-64"
|
| 322 |
+
/>
|
| 323 |
+
{field.descriptions && current && (
|
| 324 |
+
<div className="bg-dark-800/60 border border-dark-600 rounded-lg p-3 text-xs sm:text-sm text-gray-300 leading-relaxed">
|
| 325 |
+
{field.descriptions[current.value]}
|
| 326 |
+
</div>
|
| 327 |
+
)}
|
| 328 |
+
</div>
|
| 329 |
+
);
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
if (field.type === "csv_numbers") {
|
| 333 |
+
return (
|
| 334 |
+
<CsvNumbersField
|
| 335 |
+
value={value}
|
| 336 |
+
onChange={(v) => setField(field.key, v)}
|
| 337 |
+
placeholder={field.placeholder}
|
| 338 |
+
/>
|
| 339 |
+
);
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
if (field.type === "rules") {
|
| 343 |
+
const rules = Array.isArray(value)
|
| 344 |
+
? value.map((r) => (Array.isArray(r) ? [String(r[0] ?? ""), String(r[1] ?? "")] : ["", ""]))
|
| 345 |
+
: [];
|
| 346 |
+
const updateRule = (idx, col, val) => {
|
| 347 |
+
const next = rules.map((r) => [...r]);
|
| 348 |
+
next[idx][col] = val;
|
| 349 |
+
setField(field.key, next);
|
| 350 |
+
};
|
| 351 |
+
const removeRule = (idx) => {
|
| 352 |
+
setField(field.key, rules.filter((_, i) => i !== idx));
|
| 353 |
+
};
|
| 354 |
+
const addRule = () => {
|
| 355 |
+
setField(field.key, [...rules, ["", ""]]);
|
| 356 |
+
};
|
| 357 |
+
return (
|
| 358 |
+
<div className="space-y-2">
|
| 359 |
+
{rules.length === 0 && (
|
| 360 |
+
<div className="text-xs text-gray-500 bg-dark-800/60 border border-dark-700 rounded-lg px-3 py-2">
|
| 361 |
+
暂无规则,点击下方按钮新增
|
| 362 |
+
</div>
|
| 363 |
+
)}
|
| 364 |
+
{rules.map((rule, idx) => (
|
| 365 |
+
<div key={idx} className="flex items-center gap-2">
|
| 366 |
+
<input
|
| 367 |
+
type="text"
|
| 368 |
+
value={rule[0]}
|
| 369 |
+
onChange={(e) => updateRule(idx, 0, e.target.value)}
|
| 370 |
+
placeholder="匹配正则,如 ^gpt-4$"
|
| 371 |
+
className="flex-1 min-w-0 px-3 py-2 bg-dark-800 border border-dark-600 rounded-lg text-sm text-white placeholder-gray-500 font-mono"
|
| 372 |
+
/>
|
| 373 |
+
<span className="text-gray-500 text-sm shrink-0">→</span>
|
| 374 |
+
<input
|
| 375 |
+
type="text"
|
| 376 |
+
value={rule[1]}
|
| 377 |
+
onChange={(e) => updateRule(idx, 1, e.target.value)}
|
| 378 |
+
placeholder="替换模型名,如 gemini-2.5-pro"
|
| 379 |
+
className="flex-1 min-w-0 px-3 py-2 bg-dark-800 border border-dark-600 rounded-lg text-sm text-white placeholder-gray-500 font-mono"
|
| 380 |
+
/>
|
| 381 |
+
<button
|
| 382 |
+
type="button"
|
| 383 |
+
onClick={() => removeRule(idx)}
|
| 384 |
+
className="shrink-0 p-2 text-gray-500 hover:text-red-400 transition-colors"
|
| 385 |
+
title="删除该规则"
|
| 386 |
+
>
|
| 387 |
+
<Trash2 size={16} />
|
| 388 |
+
</button>
|
| 389 |
+
</div>
|
| 390 |
+
))}
|
| 391 |
+
<button
|
| 392 |
+
type="button"
|
| 393 |
+
onClick={addRule}
|
| 394 |
+
className="btn btn-secondary text-xs px-3 py-1.5 flex items-center gap-1.5"
|
| 395 |
+
>
|
| 396 |
+
<Plus size={14} />
|
| 397 |
+
新增规则
|
| 398 |
+
</button>
|
| 399 |
+
</div>
|
| 400 |
+
);
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
if (field.type === "textarea") {
|
| 404 |
+
return (
|
| 405 |
+
<LinesField
|
| 406 |
+
value={value}
|
| 407 |
+
onChange={(v) => setField(field.key, v)}
|
| 408 |
+
placeholder={field.placeholder}
|
| 409 |
+
/>
|
| 410 |
+
);
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
return (
|
| 414 |
+
<input
|
| 415 |
+
type={field.type}
|
| 416 |
+
value={value}
|
| 417 |
+
onChange={(e) =>
|
| 418 |
+
setField(
|
| 419 |
+
field.key,
|
| 420 |
+
field.type === "number" ? Number(e.target.value) : e.target.value
|
| 421 |
+
)
|
| 422 |
+
}
|
| 423 |
+
placeholder={field.placeholder}
|
| 424 |
+
className="w-full px-3 py-2 bg-dark-800 border border-dark-600 rounded-lg text-sm text-white placeholder-gray-500"
|
| 425 |
+
/>
|
| 426 |
+
);
|
| 427 |
+
};
|
| 428 |
+
|
| 429 |
+
return (
|
| 430 |
+
<div className="space-y-6">
|
| 431 |
+
{/* 操作按钮(sticky 常驻视口顶部) */}
|
| 432 |
+
<div className="sticky top-0 z-30 -mx-1 px-1 py-2 bg-dark-950/95 backdrop-blur border-b border-dark-700 rounded-lg">
|
| 433 |
+
<div className="flex items-center gap-2">
|
| 434 |
+
<button
|
| 435 |
+
onClick={loadConfig}
|
| 436 |
+
disabled={loading}
|
| 437 |
+
className="btn btn-secondary text-sm flex items-center gap-1.5"
|
| 438 |
+
>
|
| 439 |
+
<RefreshCw size={15} className={loading ? "animate-spin" : ""} />
|
| 440 |
+
刷新配置
|
| 441 |
+
</button>
|
| 442 |
+
<button
|
| 443 |
+
onClick={saveConfig}
|
| 444 |
+
disabled={saving || loading}
|
| 445 |
+
className="btn btn-primary text-sm flex items-center gap-1.5 disabled:opacity-50"
|
| 446 |
+
>
|
| 447 |
+
{saving ? <Loader2 size={15} className="animate-spin" /> : <Save size={15} />}
|
| 448 |
+
{saving ? "保存中..." : "保存配置"}
|
| 449 |
+
</button>
|
| 450 |
+
</div>
|
| 451 |
+
</div>
|
| 452 |
+
|
| 453 |
+
{/* 消息弹窗 */}
|
| 454 |
+
{message && (
|
| 455 |
+
<Modal type={message.type} title={message.type === "success" ? "操作成功" : "操作失败"} onClose={() => setMessage(null)}>
|
| 456 |
+
<span className="whitespace-pre-wrap break-all">{message.text}</span>
|
| 457 |
+
</Modal>
|
| 458 |
+
)}
|
| 459 |
+
|
| 460 |
+
{loading ? (
|
| 461 |
+
<div className="flex items-center justify-center py-12">
|
| 462 |
+
<Loader2 className="animate-spin text-purple-500" size={28} />
|
| 463 |
+
</div>
|
| 464 |
+
) : (
|
| 465 |
+
<div className="space-y-6">
|
| 466 |
+
{CONFIG_GROUPS.map((group) => (
|
| 467 |
+
<div key={group.title} className="card">
|
| 468 |
+
<h3 className="text-base font-semibold text-purple-400 mb-4 border-b border-dark-700 pb-3">
|
| 469 |
+
{group.title}
|
| 470 |
+
</h3>
|
| 471 |
+
|
| 472 |
+
{group.title === "端点配置" && (
|
| 473 |
+
<div className="flex flex-wrap gap-2 mb-4">
|
| 474 |
+
<button
|
| 475 |
+
type="button"
|
| 476 |
+
onClick={useMirrorUrls}
|
| 477 |
+
className="btn btn-secondary text-xs px-3 py-1.5"
|
| 478 |
+
>
|
| 479 |
+
🚀 一键使用镜像网址
|
| 480 |
+
</button>
|
| 481 |
+
<button
|
| 482 |
+
type="button"
|
| 483 |
+
onClick={restoreOfficialUrls}
|
| 484 |
+
className="btn btn-secondary text-xs px-3 py-1.5"
|
| 485 |
+
>
|
| 486 |
+
🔄 还原官方端点
|
| 487 |
+
</button>
|
| 488 |
+
</div>
|
| 489 |
+
)}
|
| 490 |
+
|
| 491 |
+
<div className="space-y-5">
|
| 492 |
+
{group.fields
|
| 493 |
+
.filter((field) => !field.showIf || field.showIf(config))
|
| 494 |
+
.map((field) => (
|
| 495 |
+
<div key={field.key}>
|
| 496 |
+
<label className="block text-sm font-medium text-gray-300 mb-1.5">
|
| 497 |
+
{field.label}
|
| 498 |
+
</label>
|
| 499 |
+
{renderField(field)}
|
| 500 |
+
{field.note && (
|
| 501 |
+
<p className="text-xs text-gray-500 mt-1.5">{field.note}</p>
|
| 502 |
+
)}
|
| 503 |
+
</div>
|
| 504 |
+
))}
|
| 505 |
+
</div>
|
| 506 |
+
</div>
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {
|
| 2 |
+
AlertCircle,
|
| 3 |
+
Ban,
|
| 4 |
+
BarChart3,
|
| 5 |
+
CheckCircle,
|
| 6 |
+
ChevronDown,
|
| 7 |
+
ChevronUp,
|
| 8 |
+
Clock,
|
| 9 |
+
Cpu,
|
| 10 |
+
Download,
|
| 11 |
+
Loader2,
|
| 12 |
+
RefreshCw,
|
| 13 |
+
Shield,
|
| 14 |
+
Snowflake,
|
| 15 |
+
Trash2,
|
| 16 |
+
Zap,
|
| 17 |
+
} from "lucide-react";
|
| 18 |
+
import { useCallback, useEffect, useState } from "react";
|
| 19 |
+
import Modal from "../components/Modal";
|
| 20 |
+
import Select from "../components/Select";
|
| 21 |
+
import api from "../api";
|
| 22 |
+
|
| 23 |
+
export default function Credentials() {
|
| 24 |
+
const [items, setItems] = useState([]);
|
| 25 |
+
const [stats, setStats] = useState({ total: 0, normal: 0, disabled: 0 });
|
| 26 |
+
const [total, setTotal] = useState(0);
|
| 27 |
+
const [page, setPage] = useState(1);
|
| 28 |
+
const [pageSize, setPageSize] = useState(20);
|
| 29 |
+
const [statusFilter, setStatusFilter] = useState("all");
|
| 30 |
+
const [errorCodeFilter, setErrorCodeFilter] = useState("all");
|
| 31 |
+
const [cooldownFilter, setCooldownFilter] = useState("all");
|
| 32 |
+
const [tierFilter, setTierFilter] = useState("all");
|
| 33 |
+
const [loading, setLoading] = useState(true);
|
| 34 |
+
const [selected, setSelected] = useState(new Set());
|
| 35 |
+
const [message, setMessage] = useState(null);
|
| 36 |
+
const [errorModal, setErrorModal] = useState(null);
|
| 37 |
+
const [busyFiles, setBusyFiles] = useState(new Set());
|
| 38 |
+
const [now, setNow] = useState(Date.now() / 1000);
|
| 39 |
+
// 额度预览相关状态
|
| 40 |
+
const [quotaModal, setQuotaModal] = useState(null); // { email } 额度弹窗
|
| 41 |
+
const [quotaCache, setQuotaCache] = useState({}); // 缓存额度数据 { email: { claude, gemini } | { error } }
|
| 42 |
+
// 支持模型弹窗状态
|
| 43 |
+
const [modelsModal, setModelsModal] = useState(null); // { email, models: [] }
|
| 44 |
+
|
| 45 |
+
useEffect(() => {
|
| 46 |
+
const t = setInterval(() => setNow(Date.now() / 1000), 1000);
|
| 47 |
+
return () => clearInterval(t);
|
| 48 |
+
}, []);
|
| 49 |
+
|
| 50 |
+
const fetchCreds = useCallback(async () => {
|
| 51 |
+
setLoading(true);
|
| 52 |
+
try {
|
| 53 |
+
const offset = (page - 1) * pageSize;
|
| 54 |
+
const res = await api.get("/creds/status", {
|
| 55 |
+
params: {
|
| 56 |
+
offset,
|
| 57 |
+
limit: pageSize,
|
| 58 |
+
status_filter: statusFilter,
|
| 59 |
+
error_code_filter: errorCodeFilter,
|
| 60 |
+
cooldown_filter: cooldownFilter,
|
| 61 |
+
tier_filter: tierFilter,
|
| 62 |
+
},
|
| 63 |
+
});
|
| 64 |
+
setItems(res.data.items);
|
| 65 |
+
setTotal(res.data.total);
|
| 66 |
+
setStats(res.data.stats || { total: 0, normal: 0, disabled: 0 });
|
| 67 |
+
setSelected(new Set());
|
| 68 |
+
} catch (err) {
|
| 69 |
+
showMessage("error", err.response?.data?.detail || "加载凭证失败");
|
| 70 |
+
} finally {
|
| 71 |
+
setLoading(false);
|
| 72 |
+
}
|
| 73 |
+
}, [page, pageSize, statusFilter, errorCodeFilter, cooldownFilter, tierFilter]);
|
| 74 |
+
|
| 75 |
+
useEffect(() => {
|
| 76 |
+
fetchCreds();
|
| 77 |
+
}, [fetchCreds]);
|
| 78 |
+
|
| 79 |
+
const showMessage = useCallback((type, text, title) => {
|
| 80 |
+
setMessage({ type, text, title: title || (type === "success" ? "操作成功" : type === "error" ? "操作失败" : "提示") });
|
| 81 |
+
}, []);
|
| 82 |
+
|
| 83 |
+
const setBusy = (email, busy) => {
|
| 84 |
+
setBusyFiles((prev) => {
|
| 85 |
+
const next = new Set(prev);
|
| 86 |
+
if (busy) next.add(email);
|
| 87 |
+
else next.delete(email);
|
| 88 |
+
return next;
|
| 89 |
+
});
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
const doAction = async (email, action) => {
|
| 93 |
+
setBusy(email, true);
|
| 94 |
+
try {
|
| 95 |
+
const res = await api.post("/creds/action", { email, action });
|
| 96 |
+
showMessage("success", res.data.message);
|
| 97 |
+
fetchCreds();
|
| 98 |
+
} catch (err) {
|
| 99 |
+
showMessage("error", err.response?.data?.detail || "操作失败");
|
| 100 |
+
} finally {
|
| 101 |
+
setBusy(email, false);
|
| 102 |
+
}
|
| 103 |
+
};
|
| 104 |
+
|
| 105 |
+
const doBatchAction = async (action) => {
|
| 106 |
+
if (selected.size === 0) return;
|
| 107 |
+
setBusy("__batch__", true);
|
| 108 |
+
try {
|
| 109 |
+
const res = await api.post("/creds/batch-action", {
|
| 110 |
+
action,
|
| 111 |
+
emails: Array.from(selected),
|
| 112 |
+
});
|
| 113 |
+
showMessage(res.data.errors?.length ? "error" : "success", res.data.message);
|
| 114 |
+
fetchCreds();
|
| 115 |
+
} catch (err) {
|
| 116 |
+
showMessage("error", err.response?.data?.detail || "批量操作失败");
|
| 117 |
+
} finally {
|
| 118 |
+
setBusy("__batch__", false);
|
| 119 |
+
}
|
| 120 |
+
};
|
| 121 |
+
|
| 122 |
+
const verifyProject = async (email) => {
|
| 123 |
+
setBusy(email, true);
|
| 124 |
+
try {
|
| 125 |
+
const res = await api.post(`/creds/verify-project/${encodeURIComponent(email)}`);
|
| 126 |
+
if (res.data.success) {
|
| 127 |
+
const modelCount = Array.isArray(res.data.supported_models)
|
| 128 |
+
? res.data.supported_models.length
|
| 129 |
+
: 0;
|
| 130 |
+
showMessage(
|
| 131 |
+
"success",
|
| 132 |
+
`Project=${res.data.project_id}, Tier=${res.data.subscription_tier}, 模型数=${modelCount}`,
|
| 133 |
+
`检验成功: ${email}`
|
| 134 |
+
);
|
| 135 |
+
} else {
|
| 136 |
+
showMessage("error", res.data.message || res.data.error || "检验失败", `检验失败: ${email}`);
|
| 137 |
+
}
|
| 138 |
+
fetchCreds();
|
| 139 |
+
} catch (err) {
|
| 140 |
+
showMessage(
|
| 141 |
+
"error",
|
| 142 |
+
err.response?.data?.detail || err.response?.data?.error || err.response?.data?.message || "检验失败",
|
| 143 |
+
`检验失败: ${email}`
|
| 144 |
+
);
|
| 145 |
+
} finally {
|
| 146 |
+
setBusy(email, false);
|
| 147 |
+
}
|
| 148 |
+
};
|
| 149 |
+
|
| 150 |
+
const refreshCredentialModels = async (email) => {
|
| 151 |
+
setBusy(email, true);
|
| 152 |
+
try {
|
| 153 |
+
const res = await api.post(`/creds/refresh-models/${encodeURIComponent(email)}`);
|
| 154 |
+
if (res.data.success) {
|
| 155 |
+
const newModels = res.data.supported_models || [];
|
| 156 |
+
setModelsModal((prev) =>
|
| 157 |
+
prev && prev.email === email ? { ...prev, models: newModels } : prev
|
| 158 |
+
);
|
| 159 |
+
fetchCreds();
|
| 160 |
+
}
|
| 161 |
+
} catch (err) {
|
| 162 |
+
showMessage(
|
| 163 |
+
"error",
|
| 164 |
+
err.response?.data?.detail || "刷新模型列表失败",
|
| 165 |
+
`刷新失败: ${email}`
|
| 166 |
+
);
|
| 167 |
+
} finally {
|
| 168 |
+
setBusy(email, false);
|
| 169 |
+
}
|
| 170 |
+
};
|
| 171 |
+
|
| 172 |
+
const testCredential = async (email) => {
|
| 173 |
+
setBusy(email, true);
|
| 174 |
+
try {
|
| 175 |
+
const res = await api.post(`/creds/test/${encodeURIComponent(email)}`);
|
| 176 |
+
// 200 = 可用;429 = 限流但有效
|
| 177 |
+
showMessage(
|
| 178 |
+
"success",
|
| 179 |
+
res.data.message || (res.status === 429 ? "凭证被限流(429)但有效" : "凭证测试通过"),
|
| 180 |
+
`测试成功: ${email}`
|
| 181 |
+
);
|
| 182 |
+
fetchCreds();
|
| 183 |
+
} catch (err) {
|
| 184 |
+
const data = err.response?.data || {};
|
| 185 |
+
const status = err.response?.status;
|
| 186 |
+
// 透明透传上游错误:优先后端返回的 error 原文
|
| 187 |
+
const upstreamError = data.error || data.detail || data.message || "测试失败";
|
| 188 |
+
showMessage(
|
| 189 |
+
status === 429 ? "info" : "error",
|
| 190 |
+
`HTTP ${status}\n${upstreamError}`,
|
| 191 |
+
`测试失败: ${email}`
|
| 192 |
+
);
|
| 193 |
+
fetchCreds();
|
| 194 |
+
} finally {
|
| 195 |
+
setBusy(email, false);
|
| 196 |
+
}
|
| 197 |
+
};
|
| 198 |
+
|
| 199 |
+
// 额度弹窗:打开并强制刷新(不使用旧缓存)
|
| 200 |
+
const openQuotaModal = async (email) => {
|
| 201 |
+
setQuotaModal({ email });
|
| 202 |
+
setBusy(email, true);
|
| 203 |
+
try {
|
| 204 |
+
const res = await api.get(`/creds/quota/${encodeURIComponent(email)}`);
|
| 205 |
+
if (res.data.success) {
|
| 206 |
+
const aggregated = aggregateQuota(res.data.quotaGroups || []);
|
| 207 |
+
setQuotaCache((prev) => ({ ...prev, [email]: aggregated }));
|
| 208 |
+
} else {
|
| 209 |
+
setQuotaCache((prev) => ({ ...prev, [email]: { error: res.data.error || "获取额度失败" } }));
|
| 210 |
+
}
|
| 211 |
+
} catch (err) {
|
| 212 |
+
setQuotaCache((prev) => ({
|
| 213 |
+
...prev,
|
| 214 |
+
[email]: { error: err.response?.data?.detail || err.response?.data?.error || "获取额度失败" },
|
| 215 |
+
}));
|
| 216 |
+
} finally {
|
| 217 |
+
setBusy(email, false);
|
| 218 |
+
}
|
| 219 |
+
};
|
| 220 |
+
|
| 221 |
+
// 聚合额度分组 -> Claude / Gemini 各自的剩余百分比(多组取平均,组内取 weekly/5h 较小值)
|
| 222 |
+
const aggregateQuota = (groups) => {
|
| 223 |
+
const result = {
|
| 224 |
+
claude: { remaining: 0, count: 0, resetTime: "" },
|
| 225 |
+
gemini: { remaining: 0, count: 0, resetTime: "" },
|
| 226 |
+
};
|
| 227 |
+
|
| 228 |
+
groups.forEach((group) => {
|
| 229 |
+
const name = (group.displayName || "").toLowerCase();
|
| 230 |
+
const target = name.includes("claude") ? result.claude : result.gemini;
|
| 231 |
+
target.count += 1;
|
| 232 |
+
|
| 233 |
+
// 每组取 weekly / 5h 中较小的 remainingFraction(短板效应)
|
| 234 |
+
let minPct = null;
|
| 235 |
+
let minResetTime = "";
|
| 236 |
+
(group.buckets || []).forEach((bucket) => {
|
| 237 |
+
const pct = (bucket.remainingFraction || 0) * 100;
|
| 238 |
+
if (minPct === null || pct < minPct) {
|
| 239 |
+
minPct = pct;
|
| 240 |
+
minResetTime = bucket.resetTime || "";
|
| 241 |
+
}
|
| 242 |
+
});
|
| 243 |
+
|
| 244 |
+
if (minPct !== null) {
|
| 245 |
+
target.remaining += Math.round(minPct * 10) / 10;
|
| 246 |
+
if (!target.resetTime && minResetTime) {
|
| 247 |
+
try {
|
| 248 |
+
target.resetTime = new Date(minResetTime).toLocaleString("zh-CN");
|
| 249 |
+
} catch {
|
| 250 |
+
target.resetTime = minResetTime;
|
| 251 |
+
}
|
| 252 |
+
}
|
| 253 |
+
}
|
| 254 |
+
});
|
| 255 |
+
|
| 256 |
+
// 多组时取平均值
|
| 257 |
+
if (result.claude.count > 1)
|
| 258 |
+
result.claude.remaining = Math.round(result.claude.remaining / result.claude.count);
|
| 259 |
+
if (result.gemini.count > 1)
|
| 260 |
+
result.gemini.remaining = Math.round(result.gemini.remaining / result.gemini.count);
|
| 261 |
+
|
| 262 |
+
return result;
|
| 263 |
+
};
|
| 264 |
+
|
| 265 |
+
// 额度进度条颜色
|
| 266 |
+
const getQuotaColor = (remaining) => {
|
| 267 |
+
if (remaining >= 80) return { bar: "bg-green-500", text: "text-green-400" };
|
| 268 |
+
if (remaining >= 40) return { bar: "bg-yellow-500", text: "text-yellow-400" };
|
| 269 |
+
if (remaining >= 20) return { bar: "bg-orange-500", text: "text-orange-400" };
|
| 270 |
+
return { bar: "bg-red-500", text: "text-red-400" };
|
| 271 |
+
};
|
| 272 |
+
|
| 273 |
+
const exportCredential = async (email) => {
|
| 274 |
+
try {
|
| 275 |
+
const res = await api.get(`/creds/export/${encodeURIComponent(email)}`, {
|
| 276 |
+
responseType: "blob",
|
| 277 |
+
});
|
| 278 |
+
const url = URL.createObjectURL(res.data);
|
| 279 |
+
const a = document.createElement("a");
|
| 280 |
+
a.href = url;
|
| 281 |
+
a.download = `${email}.json`;
|
| 282 |
+
a.click();
|
| 283 |
+
URL.revokeObjectURL(url);
|
| 284 |
+
showMessage("success", `已导出 ${email}.json`);
|
| 285 |
+
} catch (err) {
|
| 286 |
+
showMessage("error", err.response?.data?.detail || "导出失败");
|
| 287 |
+
}
|
| 288 |
+
};
|
| 289 |
+
|
| 290 |
+
const downloadAll = async () => {
|
| 291 |
+
setBusy("__batch__", true);
|
| 292 |
+
try {
|
| 293 |
+
const res = await api.get("/creds/download-all", {
|
| 294 |
+
responseType: "blob",
|
| 295 |
+
});
|
| 296 |
+
const url = URL.createObjectURL(res.data);
|
| 297 |
+
const a = document.createElement("a");
|
| 298 |
+
a.href = url;
|
| 299 |
+
a.download = "antigravity_credentials.zip";
|
| 300 |
+
a.click();
|
| 301 |
+
URL.revokeObjectURL(url);
|
| 302 |
+
} catch (err) {
|
| 303 |
+
showMessage("error", err.response?.data?.detail || "下载失败");
|
| 304 |
+
} finally {
|
| 305 |
+
setBusy("__batch__", false);
|
| 306 |
+
}
|
| 307 |
+
};
|
| 308 |
+
|
| 309 |
+
const openErrors = async (email) => {
|
| 310 |
+
try {
|
| 311 |
+
const res = await api.get(`/creds/errors/${encodeURIComponent(email)}`);
|
| 312 |
+
setErrorModal(res.data);
|
| 313 |
+
} catch (err) {
|
| 314 |
+
showMessage("error", err.response?.data?.detail || "获取错误信息失败");
|
| 315 |
+
}
|
| 316 |
+
};
|
| 317 |
+
|
| 318 |
+
const toggleSelect = (email) => {
|
| 319 |
+
setSelected((prev) => {
|
| 320 |
+
const next = new Set(prev);
|
| 321 |
+
if (next.has(email)) next.delete(email);
|
| 322 |
+
else next.add(email);
|
| 323 |
+
return next;
|
| 324 |
+
});
|
| 325 |
+
};
|
| 326 |
+
|
| 327 |
+
const toggleSelectAll = () => {
|
| 328 |
+
if (selected.size === items.length) setSelected(new Set());
|
| 329 |
+
else setSelected(new Set(items.map((i) => i.email)));
|
| 330 |
+
};
|
| 331 |
+
|
| 332 |
+
const totalPages = Math.max(1, Math.ceil(total / pageSize));
|
| 333 |
+
|
| 334 |
+
const formatTime = (ts) => {
|
| 335 |
+
if (!ts) return "-";
|
| 336 |
+
return new Date(ts * 1000).toLocaleString();
|
| 337 |
+
};
|
| 338 |
+
|
| 339 |
+
const getCooldownText = (cooldowns) => {
|
| 340 |
+
const active = Object.entries(cooldowns || {}).filter(
|
| 341 |
+
([, until]) => until > now
|
| 342 |
+
);
|
| 343 |
+
if (!active.length) return null;
|
| 344 |
+
const longest = Math.max(...active.map(([, until]) => until));
|
| 345 |
+
const remain = longest - now;
|
| 346 |
+
const h = Math.floor(remain / 3600);
|
| 347 |
+
const m = Math.floor((remain % 3600) / 60);
|
| 348 |
+
const s = Math.floor(remain % 60);
|
| 349 |
+
return h > 0 ? `${h}h${m}m` : m > 0 ? `${m}m${s}s` : `${s}s`;
|
| 350 |
+
};
|
| 351 |
+
|
| 352 |
+
const tierStyle = (tier) =>
|
| 353 |
+
tier === "ultra"
|
| 354 |
+
? "bg-red-500/10 text-red-400 border-red-500/30"
|
| 355 |
+
: tier === "pro"
|
| 356 |
+
? "bg-amber-500/10 text-amber-400 border-amber-500/30"
|
| 357 |
+
: "bg-blue-500/10 text-blue-400 border-blue-500/30";
|
| 358 |
+
|
| 359 |
+
return (
|
| 360 |
+
<div className="space-y-4 sm:space-y-6">
|
| 361 |
+
{/* 消息弹窗 */}
|
| 362 |
+
{message && (
|
| 363 |
+
<Modal
|
| 364 |
+
type={message.type}
|
| 365 |
+
title={message.title}
|
| 366 |
+
onClose={() => setMessage(null)}
|
| 367 |
+
>
|
| 368 |
+
<span className="whitespace-pre-wrap">{message.text}</span>
|
| 369 |
+
</Modal>
|
| 370 |
+
)}
|
| 371 |
+
|
| 372 |
+
{/* 状态统计 */}
|
| 373 |
+
<div className="grid grid-cols-3 gap-2 sm:gap-4">
|
| 374 |
+
<div className="bg-dark-800 border border-dark-600 rounded-xl p-3 sm:p-4 text-center">
|
| 375 |
+
<div className="text-xl sm:text-2xl font-bold text-white">{stats.total}</div>
|
| 376 |
+
<div className="text-xs text-gray-500 mt-0.5">总计</div>
|
| 377 |
+
</div>
|
| 378 |
+
<div className="bg-emerald-900/20 border border-emerald-700/30 rounded-xl p-3 sm:p-4 text-center">
|
| 379 |
+
<div className="text-xl sm:text-2xl font-bold text-emerald-400">{stats.normal}</div>
|
| 380 |
+
<div className="text-xs text-gray-500 mt-0.5">正常</div>
|
| 381 |
+
</div>
|
| 382 |
+
<div className="bg-red-900/20 border border-red-700/30 rounded-xl p-3 sm:p-4 text-center">
|
| 383 |
+
<div className="text-xl sm:text-2xl font-bold text-red-400">{stats.disabled}</div>
|
| 384 |
+
<div className="text-xs text-gray-500 mt-0.5">禁用</div>
|
| 385 |
+
</div>
|
| 386 |
+
</div>
|
| 387 |
+
|
| 388 |
+
{/* 操作按钮 */}
|
| 389 |
+
<div className="flex flex-wrap items-center gap-2">
|
| 390 |
+
<button
|
| 391 |
+
onClick={fetchCreds}
|
| 392 |
+
disabled={loading}
|
| 393 |
+
className="btn btn-secondary text-xs sm:text-sm px-3 py-1.5 sm:px-4 sm:py-2 flex items-center gap-1.5"
|
| 394 |
+
>
|
| 395 |
+
<RefreshCw size={15} className={loading ? "animate-spin" : ""} />
|
| 396 |
+
刷新状态
|
| 397 |
+
</button>
|
| 398 |
+
<button
|
| 399 |
+
onClick={downloadAll}
|
| 400 |
+
disabled={busyFiles.has("__batch__")}
|
| 401 |
+
className="btn btn-secondary text-xs sm:text-sm px-3 py-1.5 sm:px-4 sm:py-2 flex items-center gap-1.5"
|
| 402 |
+
>
|
| 403 |
+
<Download size={15} />
|
| 404 |
+
打包导出
|
| 405 |
+
</button>
|
| 406 |
+
</div>
|
| 407 |
+
|
| 408 |
+
{/* 筛选器 */}
|
| 409 |
+
<div className="grid grid-cols-2 sm:flex sm:flex-wrap gap-2 sm:gap-3 text-sm">
|
| 410 |
+
<Select
|
| 411 |
+
value={statusFilter}
|
| 412 |
+
onChange={(v) => {
|
| 413 |
+
setStatusFilter(v);
|
| 414 |
+
setPage(1);
|
| 415 |
+
}}
|
| 416 |
+
className="w-full sm:w-32"
|
| 417 |
+
options={[
|
| 418 |
+
{ value: "all", label: "全部凭证" },
|
| 419 |
+
{ value: "enabled", label: "仅启用" },
|
| 420 |
+
{ value: "disabled", label: "仅禁用" },
|
| 421 |
+
]}
|
| 422 |
+
/>
|
| 423 |
+
<Select
|
| 424 |
+
value={errorCodeFilter}
|
| 425 |
+
onChange={(v) => {
|
| 426 |
+
setErrorCodeFilter(v);
|
| 427 |
+
setPage(1);
|
| 428 |
+
}}
|
| 429 |
+
className="w-full sm:w-32"
|
| 430 |
+
options={[
|
| 431 |
+
{ value: "all", label: "错误码: 全部" },
|
| 432 |
+
{ value: "none", label: "无错误" },
|
| 433 |
+
{ value: "400", label: "400" },
|
| 434 |
+
{ value: "403", label: "403" },
|
| 435 |
+
{ value: "429", label: "429" },
|
| 436 |
+
{ value: "500", label: "500" },
|
| 437 |
+
]}
|
| 438 |
+
/>
|
| 439 |
+
<Select
|
| 440 |
+
value={cooldownFilter}
|
| 441 |
+
onChange={(v) => {
|
| 442 |
+
setCooldownFilter(v);
|
| 443 |
+
setPage(1);
|
| 444 |
+
}}
|
| 445 |
+
className="w-full sm:w-32"
|
| 446 |
+
options={[
|
| 447 |
+
{ value: "all", label: "冷��: 全部" },
|
| 448 |
+
{ value: "in_cooldown", label: "CD中" },
|
| 449 |
+
{ value: "no_cooldown", label: "未CD" },
|
| 450 |
+
]}
|
| 451 |
+
/>
|
| 452 |
+
<Select
|
| 453 |
+
value={tierFilter}
|
| 454 |
+
onChange={(v) => {
|
| 455 |
+
setTierFilter(v);
|
| 456 |
+
setPage(1);
|
| 457 |
+
}}
|
| 458 |
+
className="w-full sm:w-32"
|
| 459 |
+
options={[
|
| 460 |
+
{ value: "all", label: "Tier: 全部" },
|
| 461 |
+
{ value: "free", label: "Free" },
|
| 462 |
+
{ value: "pro", label: "Pro" },
|
| 463 |
+
{ value: "ultra", label: "Ultra" },
|
| 464 |
+
]}
|
| 465 |
+
/>
|
| 466 |
+
<Select
|
| 467 |
+
value={pageSize}
|
| 468 |
+
onChange={(v) => {
|
| 469 |
+
setPageSize(Number(v));
|
| 470 |
+
setPage(1);
|
| 471 |
+
}}
|
| 472 |
+
className="w-full sm:w-32"
|
| 473 |
+
options={[20, 50, 100, 200, 500, 1000].map((n) => ({
|
| 474 |
+
value: n,
|
| 475 |
+
label: `每页 ${n}`,
|
| 476 |
+
}))}
|
| 477 |
+
/>
|
| 478 |
+
</div>
|
| 479 |
+
|
| 480 |
+
{/* 批量操作 */}
|
| 481 |
+
<div className="card p-3 sm:p-4">
|
| 482 |
+
<div className="flex flex-wrap items-center gap-x-3 gap-y-2 text-sm">
|
| 483 |
+
<label className="flex items-center gap-2 text-gray-400 cursor-pointer select-none">
|
| 484 |
+
<input
|
| 485 |
+
type="checkbox"
|
| 486 |
+
checked={selected.size === items.length && items.length > 0}
|
| 487 |
+
onChange={toggleSelectAll}
|
| 488 |
+
className="accent-purple-600 w-4 h-4"
|
| 489 |
+
/>
|
| 490 |
+
全选
|
| 491 |
+
</label>
|
| 492 |
+
<span className="text-gray-500 text-xs">已选 {selected.size} 项</span>
|
| 493 |
+
<div className="flex flex-wrap gap-2">
|
| 494 |
+
<button
|
| 495 |
+
onClick={() => doBatchAction("enable")}
|
| 496 |
+
disabled={selected.size === 0 || busyFiles.has("__batch__")}
|
| 497 |
+
className="btn btn-secondary text-xs px-3 py-1.5 disabled:opacity-40"
|
| 498 |
+
>
|
| 499 |
+
批量启用
|
| 500 |
+
</button>
|
| 501 |
+
<button
|
| 502 |
+
onClick={() => doBatchAction("disable")}
|
| 503 |
+
disabled={selected.size === 0 || busyFiles.has("__batch__")}
|
| 504 |
+
className="btn btn-secondary text-xs px-3 py-1.5 disabled:opacity-40"
|
| 505 |
+
>
|
| 506 |
+
批量禁用
|
| 507 |
+
</button>
|
| 508 |
+
<button
|
| 509 |
+
onClick={() => doBatchAction("refresh_models")}
|
| 510 |
+
disabled={selected.size === 0 || busyFiles.has("__batch__")}
|
| 511 |
+
className="btn btn-secondary text-xs px-3 py-1.5 disabled:opacity-40"
|
| 512 |
+
>
|
| 513 |
+
批量刷新模型
|
| 514 |
+
</button>
|
| 515 |
+
<button
|
| 516 |
+
onClick={() => doBatchAction("delete")}
|
| 517 |
+
disabled={selected.size === 0 || busyFiles.has("__batch__")}
|
| 518 |
+
className="btn btn-danger text-xs px-3 py-1.5 disabled:opacity-40"
|
| 519 |
+
>
|
| 520 |
+
批量删除
|
| 521 |
+
</button>
|
| 522 |
+
</div>
|
| 523 |
+
</div>
|
| 524 |
+
</div>
|
| 525 |
+
|
| 526 |
+
{/* 凭证卡片列表 */}
|
| 527 |
+
{loading ? (
|
| 528 |
+
<div className="flex items-center justify-center py-12">
|
| 529 |
+
<Loader2 className="animate-spin text-purple-500" size={28} />
|
| 530 |
+
</div>
|
| 531 |
+
) : items.length === 0 ? (
|
| 532 |
+
<div className="card text-center py-12 text-gray-500 text-sm">
|
| 533 |
+
没有凭证。请先通过 OAuth 认证或批量导入添加凭证。
|
| 534 |
+
</div>
|
| 535 |
+
) : (
|
| 536 |
+
<div className="grid gap-3 sm:gap-4 grid-cols-1 md:grid-cols-2 xl:grid-cols-3">
|
| 537 |
+
{items.map((cred) => {
|
| 538 |
+
const cooldownText = getCooldownText(cred.model_cooldowns);
|
| 539 |
+
const busy = busyFiles.has(cred.email);
|
| 540 |
+
return (
|
| 541 |
+
<div
|
| 542 |
+
key={cred.email}
|
| 543 |
+
className={`card p-3 sm:p-4 space-y-3 transition-colors ${
|
| 544 |
+
cred.disabled ? "border-red-500/30" : ""
|
| 545 |
+
}`}
|
| 546 |
+
>
|
| 547 |
+
{/* 头部:选择框 + 邮箱 + 状态标签 */}
|
| 548 |
+
<div className="flex items-start gap-2.5">
|
| 549 |
+
<input
|
| 550 |
+
type="checkbox"
|
| 551 |
+
checked={selected.has(cred.email)}
|
| 552 |
+
onChange={() => toggleSelect(cred.email)}
|
| 553 |
+
className="accent-purple-600 w-4 h-4 flex-shrink-0 mt-0.5"
|
| 554 |
+
/>
|
| 555 |
+
<div className="flex-1 min-w-0 space-y-1.5">
|
| 556 |
+
<div className="text-sm font-medium text-white break-all leading-snug">
|
| 557 |
+
{cred.email}
|
| 558 |
+
</div>
|
| 559 |
+
<div className="flex items-center gap-1.5 flex-wrap">
|
| 560 |
+
<span
|
| 561 |
+
className={`text-xs px-2 py-0.5 rounded-full border ${tierStyle(cred.tier)}`}
|
| 562 |
+
>
|
| 563 |
+
{cred.tier || "pro"}
|
| 564 |
+
</span>
|
| 565 |
+
{cred.disabled ? (
|
| 566 |
+
<span className="text-red-400 text-xs flex items-center gap-1">
|
| 567 |
+
<Ban size={12} /> 禁用
|
| 568 |
+
</span>
|
| 569 |
+
) : (
|
| 570 |
+
<span className="text-emerald-400 text-xs flex items-center gap-1">
|
| 571 |
+
<CheckCircle size={12} /> 启用
|
| 572 |
+
</span>
|
| 573 |
+
)}
|
| 574 |
+
</div>
|
| 575 |
+
</div>
|
| 576 |
+
</div>
|
| 577 |
+
|
| 578 |
+
{/* 信息区 */}
|
| 579 |
+
<div className="space-y-1 text-xs">
|
| 580 |
+
<div className="flex items-center justify-between gap-2">
|
| 581 |
+
{cooldownText ? (
|
| 582 |
+
<span className="text-cyan-400 flex items-center gap-1">
|
| 583 |
+
<Snowflake size={12} /> CD {cooldownText}
|
| 584 |
+
</span>
|
| 585 |
+
) : (
|
| 586 |
+
<span className="text-gray-600 flex items-center gap-1">
|
| 587 |
+
<Clock size={12} /> 无CD
|
| 588 |
+
</span>
|
| 589 |
+
)}
|
| 590 |
+
{cred.error_codes?.length ? (
|
| 591 |
+
<button
|
| 592 |
+
onClick={() => openErrors(cred.email)}
|
| 593 |
+
className="text-red-400 hover:text-red-300 flex items-center gap-1"
|
| 594 |
+
>
|
| 595 |
+
<AlertCircle size={12} />
|
| 596 |
+
{cred.error_codes.join(",")}
|
| 597 |
+
</button>
|
| 598 |
+
) : (
|
| 599 |
+
<span className="text-gray-600 flex items-center gap-1">
|
| 600 |
+
<CheckCircle size={12} /> 无错误
|
| 601 |
+
</span>
|
| 602 |
+
)}
|
| 603 |
+
</div>
|
| 604 |
+
<div className="flex items-center justify-between gap-2 text-gray-500">
|
| 605 |
+
<div className="flex items-center gap-1 min-w-0">
|
| 606 |
+
<Clock size={12} className="flex-shrink-0" />
|
| 607 |
+
<span className="truncate" title={formatTime(cred.last_success)}>
|
| 608 |
+
{formatTime(cred.last_success)}
|
| 609 |
+
</span>
|
| 610 |
+
</div>
|
| 611 |
+
<button
|
| 612 |
+
onClick={() =>
|
| 613 |
+
setModelsModal({
|
| 614 |
+
email: cred.email,
|
| 615 |
+
models: cred.supported_models || [],
|
| 616 |
+
})
|
| 617 |
+
}
|
| 618 |
+
className="text-purple-400 hover:text-purple-300 flex items-center gap-1 flex-shrink-0"
|
| 619 |
+
title="点击查看或刷新该凭证支持的模型列表"
|
| 620 |
+
>
|
| 621 |
+
<Cpu size={12} />
|
| 622 |
+
{cred.supported_models?.length
|
| 623 |
+
? `模型 ${cred.supported_models.length}`
|
| 624 |
+
: "模型未检测"}
|
| 625 |
+
</button>
|
| 626 |
+
</div>
|
| 627 |
+
</div>
|
| 628 |
+
|
| 629 |
+
{/* 操作按钮(2×3 网格铺满卡片) */}
|
| 630 |
+
<div className="grid grid-cols-3 gap-1.5 pt-1 border-t border-dark-700">
|
| 631 |
+
{busy ? (
|
| 632 |
+
<div className="col-span-3 flex items-center justify-center py-1.5">
|
| 633 |
+
<Loader2 size={16} className="animate-spin text-purple-400" />
|
| 634 |
+
</div>
|
| 635 |
+
) : (
|
| 636 |
+
<>
|
| 637 |
+
<button
|
| 638 |
+
onClick={() => verifyProject(cred.email)}
|
| 639 |
+
className="text-xs px-2 py-1.5 rounded-lg bg-dark-700 hover:bg-dark-600 text-gray-300 flex items-center justify-center gap-1"
|
| 640 |
+
title="检验 Project ID / Tier(可修复 403)"
|
| 641 |
+
>
|
| 642 |
+
<Shield size={13} /> 检验
|
| 643 |
+
</button>
|
| 644 |
+
<button
|
| 645 |
+
onClick={() => testCredential(cred.email)}
|
| 646 |
+
className="text-xs px-2 py-1.5 rounded-lg bg-dark-700 hover:bg-dark-600 text-gray-300 flex items-center justify-center gap-1"
|
| 647 |
+
title="测试凭证"
|
| 648 |
+
>
|
| 649 |
+
<Zap size={13} /> 测试
|
| 650 |
+
</button>
|
| 651 |
+
<button
|
| 652 |
+
onClick={() => openQuotaModal(cred.email)}
|
| 653 |
+
disabled={cred.disabled}
|
| 654 |
+
className="text-xs px-2 py-1.5 rounded-lg bg-dark-700 hover:bg-dark-600 text-gray-300 flex items-center justify-center gap-1 disabled:opacity-40"
|
| 655 |
+
title="查看额度"
|
| 656 |
+
>
|
| 657 |
+
<BarChart3 size={13} /> 额度
|
| 658 |
+
</button>
|
| 659 |
+
<button
|
| 660 |
+
onClick={() => exportCredential(cred.email)}
|
| 661 |
+
className="text-xs px-2 py-1.5 rounded-lg bg-dark-700 hover:bg-dark-600 text-gray-300 flex items-center justify-center gap-1"
|
| 662 |
+
title="导出凭证(邮箱.json)"
|
| 663 |
+
>
|
| 664 |
+
<Download size={13} /> 导出
|
| 665 |
+
</button>
|
| 666 |
+
<button
|
| 667 |
+
onClick={() =>
|
| 668 |
+
doAction(cred.email, cred.disabled ? "enable" : "disable")
|
| 669 |
+
}
|
| 670 |
+
className={`text-xs px-2 py-1.5 rounded-lg flex items-center justify-center gap-1 ${
|
| 671 |
+
cred.disabled
|
| 672 |
+
? "bg-emerald-600/20 hover:bg-emerald-600/30 text-emerald-400"
|
| 673 |
+
: "bg-amber-600/20 hover:bg-amber-600/30 text-amber-400"
|
| 674 |
+
}`}
|
| 675 |
+
>
|
| 676 |
+
{cred.disabled ? <CheckCircle size={13} /> : <Ban size={13} />}
|
| 677 |
+
{cred.disabled ? "启用" : "禁用"}
|
| 678 |
+
</button>
|
| 679 |
+
<button
|
| 680 |
+
onClick={() => doAction(cred.email, "delete")}
|
| 681 |
+
className="text-xs px-2 py-1.5 rounded-lg bg-red-600/10 hover:bg-red-600/20 text-red-400 flex items-center justify-center gap-1"
|
| 682 |
+
title="删除"
|
| 683 |
+
>
|
| 684 |
+
<Trash2 size={13} /> 删除
|
| 685 |
+
</button>
|
| 686 |
+
</>
|
| 687 |
+
)}
|
| 688 |
+
</div>
|
| 689 |
+
</div>
|
| 690 |
+
);
|
| 691 |
+
})}
|
| 692 |
+
</div>
|
| 693 |
+
)}
|
| 694 |
+
|
| 695 |
+
{/* 分页 */}
|
| 696 |
+
{total > pageSize && (
|
| 697 |
+
<div className="flex items-center justify-between text-sm">
|
| 698 |
+
<span className="text-gray-500 text-xs sm:text-sm">
|
| 699 |
+
共 {total} 个凭证,第 {page}/{totalPages} 页
|
| 700 |
+
</span>
|
| 701 |
+
<div className="flex items-center gap-2">
|
| 702 |
+
<button
|
| 703 |
+
onClick={() => setPage((p) => Math.max(1, p - 1))}
|
| 704 |
+
disabled={page <= 1}
|
| 705 |
+
className="btn btn-secondary text-xs px-3 py-1.5 disabled:opacity-40"
|
| 706 |
+
>
|
| 707 |
+
上一页
|
| 708 |
+
</button>
|
| 709 |
+
<span className="text-gray-400 text-xs sm:text-sm">
|
| 710 |
+
{page} / {totalPages}
|
| 711 |
+
</span>
|
| 712 |
+
<button
|
| 713 |
+
onClick={() => setPage((p) => Math.min(totalPages, p + 1))}
|
| 714 |
+
disabled={page >= totalPages}
|
| 715 |
+
className="btn btn-secondary text-xs px-3 py-1.5 disabled:opacity-40"
|
| 716 |
+
>
|
| 717 |
+
下一页
|
| 718 |
+
</button>
|
| 719 |
+
</div>
|
| 720 |
+
</div>
|
| 721 |
+
)}
|
| 722 |
+
|
| 723 |
+
|
| 724 |
+
{/* 支持模型列表弹窗 */}
|
| 725 |
+
{modelsModal && (
|
| 726 |
+
<Modal
|
| 727 |
+
type="info"
|
| 728 |
+
title={`支持模型列表 - ${modelsModal.email}`}
|
| 729 |
+
onClose={() => setModelsModal(null)}
|
| 730 |
+
>
|
| 731 |
+
<div className="space-y-3">
|
| 732 |
+
{busyFiles.has(modelsModal.email) ? (
|
| 733 |
+
<div className="flex items-center justify-center py-6 text-gray-500">
|
| 734 |
+
<RefreshCw size={16} className="animate-spin mr-2" />
|
| 735 |
+
正在获取模型列表...
|
| 736 |
+
</div>
|
| 737 |
+
) : modelsModal.models?.length > 0 ? (
|
| 738 |
+
<div className="space-y-2">
|
| 739 |
+
<div className="text-xs text-gray-400">
|
| 740 |
+
共支持 {modelsModal.models.length} 个模型:
|
| 741 |
+
</div>
|
| 742 |
+
<div className="flex flex-wrap gap-1.5 max-h-60 overflow-y-auto p-2 bg-dark-900/60 border border-dark-700 rounded-lg">
|
| 743 |
+
{modelsModal.models.map((m) => (
|
| 744 |
+
<span
|
| 745 |
+
key={m}
|
| 746 |
+
className="text-xs px-2 py-0.5 rounded bg-dark-700 text-gray-200 border border-dark-600 font-mono"
|
| 747 |
+
>
|
| 748 |
+
{m}
|
| 749 |
+
</span>
|
| 750 |
+
))}
|
| 751 |
+
</div>
|
| 752 |
+
</div>
|
| 753 |
+
) : (
|
| 754 |
+
<div className="text-center py-4 text-gray-500 text-sm">
|
| 755 |
+
尚未记录该凭证的模型列表,请点击下方按钮检测。
|
| 756 |
+
</div>
|
| 757 |
+
)}
|
| 758 |
+
<button
|
| 759 |
+
onClick={() => refreshCredentialModels(modelsModal.email)}
|
| 760 |
+
disabled={busyFiles.has(modelsModal.email)}
|
| 761 |
+
className="w-full text-xs text-gray-300 hover:text-white py-2 rounded-lg bg-dark-700 hover:bg-dark-600 flex items-center justify-center gap-1.5 disabled:opacity-50"
|
| 762 |
+
>
|
| 763 |
+
<RefreshCw
|
| 764 |
+
size={12}
|
| 765 |
+
className={busyFiles.has(modelsModal.email) ? "animate-spin" : ""}
|
| 766 |
+
/>
|
| 767 |
+
刷新模型列表
|
| 768 |
+
</button>
|
| 769 |
+
</div>
|
| 770 |
+
</Modal>
|
| 771 |
+
)}
|
| 772 |
+
|
| 773 |
+
{/* 额度弹窗 */}
|
| 774 |
+
{quotaModal && (
|
| 775 |
+
<Modal
|
| 776 |
+
type="info"
|
| 777 |
+
title={`额度信息 - ${quotaModal.email}`}
|
| 778 |
+
onClose={() => setQuotaModal(null)}
|
| 779 |
+
>
|
| 780 |
+
{busyFiles.has(quotaModal.email) ? (
|
| 781 |
+
<div className="flex items-center justify-center py-6 text-gray-500">
|
| 782 |
+
<RefreshCw size={16} className="animate-spin mr-2" />
|
| 783 |
+
加载额度中...
|
| 784 |
+
</div>
|
| 785 |
+
) : quotaCache[quotaModal.email]?.error ? (
|
| 786 |
+
<div className="text-center py-4 text-red-400">{quotaCache[quotaModal.email].error}</div>
|
| 787 |
+
) : quotaCache[quotaModal.email] ? (
|
| 788 |
+
<div className="space-y-3">
|
| 789 |
+
{quotaCache[quotaModal.email].claude?.count > 0 && (
|
| 790 |
+
<div>
|
| 791 |
+
<div className="flex items-center justify-between mb-1.5">
|
| 792 |
+
<span className="text-purple-400 text-sm">Claude</span>
|
| 793 |
+
<span className={`text-sm font-medium ${getQuotaColor(quotaCache[quotaModal.email].claude.remaining).text}`}>
|
| 794 |
+
{quotaCache[quotaModal.email].claude.remaining.toFixed(1)}%
|
| 795 |
+
</span>
|
| 796 |
+
</div>
|
| 797 |
+
<div className="bg-dark-600 rounded-full h-2">
|
| 798 |
+
<div
|
| 799 |
+
className={`h-2 rounded-full ${getQuotaColor(quotaCache[quotaModal.email].claude.remaining).bar}`}
|
| 800 |
+
style={{ width: `${Math.min(quotaCache[quotaModal.email].claude.remaining, 100)}%` }}
|
| 801 |
+
/>
|
| 802 |
+
</div>
|
| 803 |
+
</div>
|
| 804 |
+
)}
|
| 805 |
+
{quotaCache[quotaModal.email].gemini?.count > 0 && (
|
| 806 |
+
<div>
|
| 807 |
+
<div className="flex items-center justify-between mb-1.5">
|
| 808 |
+
<span className="text-cyan-400 text-sm">Gemini</span>
|
| 809 |
+
<span className={`text-sm font-medium ${getQuotaColor(quotaCache[quotaModal.email].gemini.remaining).text}`}>
|
| 810 |
+
{quotaCache[quotaModal.email].gemini.remaining.toFixed(1)}%
|
| 811 |
+
</span>
|
| 812 |
+
</div>
|
| 813 |
+
<div className="bg-dark-600 rounded-full h-2">
|
| 814 |
+
<div
|
| 815 |
+
className={`h-2 rounded-full ${getQuotaColor(quotaCache[quotaModal.email].gemini.remaining).bar}`}
|
| 816 |
+
style={{ width: `${Math.min(quotaCache[quotaModal.email].gemini.remaining, 100)}%` }}
|
| 817 |
+
/>
|
| 818 |
+
</div>
|
| 819 |
+
</div>
|
| 820 |
+
)}
|
| 821 |
+
{!quotaCache[quotaModal.email].claude?.count &&
|
| 822 |
+
!quotaCache[quotaModal.email].gemini?.count && (
|
| 823 |
+
<div className="text-center py-3 text-gray-500">暂无额度数据</div>
|
| 824 |
+
)}
|
| 825 |
+
{(quotaCache[quotaModal.email].claude?.resetTime ||
|
| 826 |
+
quotaCache[quotaModal.email].gemini?.resetTime) && (
|
| 827 |
+
<div className="text-xs text-gray-500 text-right pt-1">
|
| 828 |
+
重置:{" "}
|
| 829 |
+
{quotaCache[quotaModal.email].claude?.resetTime ||
|
| 830 |
+
quotaCache[quotaModal.email].gemini?.resetTime}
|
| 831 |
+
</div>
|
| 832 |
+
)}
|
| 833 |
+
<button
|
| 834 |
+
onClick={() => openQuotaModal(quotaModal.email)}
|
| 835 |
+
disabled={busyFiles.has(quotaModal.email)}
|
| 836 |
+
className="w-full text-xs text-gray-400 hover:text-white py-2 rounded-lg bg-dark-700 hover:bg-dark-600 flex items-center justify-center gap-1.5 disabled:opacity-50"
|
| 837 |
+
>
|
| 838 |
+
<RefreshCw size={12} className={busyFiles.has(quotaModal.email) ? "animate-spin" : ""} />
|
| 839 |
+
刷新额度
|
| 840 |
+
</button>
|
| 841 |
+
</div>
|
| 842 |
+
) : (
|
| 843 |
+
<div className="text-center py-4 text-gray-500">加载中...</div>
|
| 844 |
+
)}
|
| 845 |
+
</Modal>
|
| 846 |
+
)}
|
| 847 |
+
|
| 848 |
+
{/* 错误详情弹窗 */}
|
| 849 |
+
{errorModal && (
|
| 850 |
+
<div
|
| 851 |
+
className="fixed inset-0 bg-black/60 flex items-center justify-center p-4 z-50"
|
| 852 |
+
onClick={() => setErrorModal(null)}
|
| 853 |
+
>
|
| 854 |
+
<div
|
| 855 |
+
className="bg-dark-900 border border-dark-600 rounded-xl max-w-2xl w-full max-h-[80vh] overflow-hidden flex flex-col"
|
| 856 |
+
onClick={(e) => e.stopPropagation()}
|
| 857 |
+
>
|
| 858 |
+
<div className="flex items-center justify-between px-4 sm:px-5 py-4 border-b border-dark-700">
|
| 859 |
+
<h3 className="font-semibold flex items-center gap-2 text-sm sm:text-base break-all">
|
| 860 |
+
<AlertCircle size={16} className="text-red-400 flex-shrink-0" />
|
| 861 |
+
错误详情 - {errorModal.email}
|
| 862 |
+
</h3>
|
| 863 |
+
<button
|
| 864 |
+
onClick={() => setErrorModal(null)}
|
| 865 |
+
className="text-gray-400 hover:text-white flex-shrink-0"
|
| 866 |
+
>
|
| 867 |
+
✕
|
| 868 |
+
</button>
|
| 869 |
+
</div>
|
| 870 |
+
<div className="p-4 sm:p-5 overflow-y-auto space-y-4">
|
| 871 |
+
<div>
|
| 872 |
+
<div className="text-sm text-gray-400 mb-1">错误码</div>
|
| 873 |
+
<div className="text-red-400 text-sm">
|
| 874 |
+
{(errorModal.error_codes || []).join(", ") || "无"}
|
| 875 |
+
</div>
|
| 876 |
+
</div>
|
| 877 |
+
<div>
|
| 878 |
+
<div className="text-sm text-gray-400 mb-1">错误信息</div>
|
| 879 |
+
<pre className="bg-dark-800 border border-dark-600 rounded-lg p-3 sm:p-4 text-xs text-gray-300 overflow-auto max-h-56 whitespace-pre-wrap">
|
| 880 |
+
{JSON.stringify(errorModal.error_messages, null, 2)}
|
| 881 |
+
</pre>
|
| 882 |
+
</div>
|
| 883 |
+
<div className="flex flex-wrap gap-2">
|
| 884 |
+
<button
|
| 885 |
+
onClick={() => {
|
| 886 |
+
verifyProject(errorModal.email);
|
| 887 |
+
setErrorModal(null);
|
| 888 |
+
}}
|
| 889 |
+
className="btn btn-primary text-sm"
|
| 890 |
+
>
|
| 891 |
+
检验修复(重新获取Project ID)
|
| 892 |
+
</button>
|
| 893 |
+
<button
|
| 894 |
+
onClick={() => {
|
| 895 |
+
testCredential(errorModal.email);
|
| 896 |
+
setErrorModal(null);
|
| 897 |
+
}}
|
| 898 |
+
className="btn btn-secondary text-sm"
|
| 899 |
+
>
|
| 900 |
+
测试凭证
|
| 901 |
+
</button>
|
| 902 |
+
</div>
|
| 903 |
+
</div>
|
| 904 |
+
</div>
|
| 905 |
+
</div>
|
| 906 |
+
)}
|
| 907 |
+
</div>
|
| 908 |
+
);
|
| 909 |
+
}
|
agy2api/frontend/src/pages/Login.jsx
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Eye, EyeOff, Rocket } from "lucide-react";
|
| 2 |
+
import { useState } from "react";
|
| 3 |
+
import api from "../api";
|
| 4 |
+
|
| 5 |
+
export default function Login({ onSuccess }) {
|
| 6 |
+
const [password, setPassword] = useState("");
|
| 7 |
+
const [showPassword, setShowPassword] = useState(false);
|
| 8 |
+
const [error, setError] = useState("");
|
| 9 |
+
const [loading, setLoading] = useState(false);
|
| 10 |
+
|
| 11 |
+
const handleSubmit = async (e) => {
|
| 12 |
+
e.preventDefault();
|
| 13 |
+
setError("");
|
| 14 |
+
setLoading(true);
|
| 15 |
+
|
| 16 |
+
try {
|
| 17 |
+
const res = await api.post("/auth/login", { password });
|
| 18 |
+
localStorage.setItem("panelToken", res.data.token);
|
| 19 |
+
onSuccess();
|
| 20 |
+
} catch (err) {
|
| 21 |
+
setError(err.response?.data?.detail || "登录失败");
|
| 22 |
+
} finally {
|
| 23 |
+
setLoading(false);
|
| 24 |
+
}
|
| 25 |
+
};
|
| 26 |
+
|
| 27 |
+
return (
|
| 28 |
+
<div className="min-h-screen flex items-center justify-center p-4">
|
| 29 |
+
<div className="w-full max-w-md">
|
| 30 |
+
{/* Logo */}
|
| 31 |
+
<div className="text-center mb-8">
|
| 32 |
+
<div className="inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-purple-600/20 mb-4">
|
| 33 |
+
<Rocket className="w-10 h-10 text-purple-400" />
|
| 34 |
+
</div>
|
| 35 |
+
<h1 className="text-3xl font-bold text-white">AGY2API</h1>
|
| 36 |
+
<p className="text-gray-400 mt-2">Antigravity API 代理服务控制面板</p>
|
| 37 |
+
</div>
|
| 38 |
+
|
| 39 |
+
{/* 登录卡片 */}
|
| 40 |
+
<div className="card">
|
| 41 |
+
<h2 className="text-xl font-semibold mb-6 text-center">登录控制面板</h2>
|
| 42 |
+
|
| 43 |
+
{error && (
|
| 44 |
+
<div className="bg-red-500/10 border border-red-500/30 text-red-400 px-4 py-3 rounded-lg mb-4">
|
| 45 |
+
{error}
|
| 46 |
+
</div>
|
| 47 |
+
)}
|
| 48 |
+
|
| 49 |
+
<form onSubmit={handleSubmit} className="space-y-4">
|
| 50 |
+
<div>
|
| 51 |
+
<label className="block text-sm font-medium text-gray-300 mb-2">
|
| 52 |
+
密码
|
| 53 |
+
</label>
|
| 54 |
+
<div className="relative">
|
| 55 |
+
<input
|
| 56 |
+
type={showPassword ? "text" : "password"}
|
| 57 |
+
value={password}
|
| 58 |
+
onChange={(e) => setPassword(e.target.value)}
|
| 59 |
+
className="w-full px-4 py-3 bg-dark-800 border border-dark-600 rounded-lg text-white placeholder-gray-500 pr-12"
|
| 60 |
+
placeholder="请输入控制面板密码"
|
| 61 |
+
required
|
| 62 |
+
/>
|
| 63 |
+
<button
|
| 64 |
+
type="button"
|
| 65 |
+
onClick={() => setShowPassword(!showPassword)}
|
| 66 |
+
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-300"
|
| 67 |
+
>
|
| 68 |
+
{showPassword ? <EyeOff size={20} /> : <Eye size={20} />}
|
| 69 |
+
</button>
|
| 70 |
+
</div>
|
| 71 |
+
</div>
|
| 72 |
+
|
| 73 |
+
<button
|
| 74 |
+
type="submit"
|
| 75 |
+
disabled={loading}
|
| 76 |
+
className="w-full btn btn-primary py-3 flex items-center justify-center disabled:opacity-50"
|
| 77 |
+
>
|
| 78 |
+
{loading ? (
|
| 79 |
+
<span className="animate-spin rounded-full h-5 w-5 border-b-2 border-white"></span>
|
| 80 |
+
) : (
|
| 81 |
+
"登录"
|
| 82 |
+
)}
|
| 83 |
+
</button>
|
| 84 |
+
</form>
|
| 85 |
+
</div>
|
| 86 |
+
</div>
|
| 87 |
+
</div>
|
| 88 |
+
);
|
| 89 |
+
}
|
agy2api/frontend/src/pages/OAuth.jsx
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Check, ChevronDown, Copy, ExternalLink, Loader2, Rocket } from "lucide-react";
|
| 2 |
+
import { useState } from "react";
|
| 3 |
+
import Modal from "../components/Modal";
|
| 4 |
+
import api from "../api";
|
| 5 |
+
|
| 6 |
+
export default function OAuth() {
|
| 7 |
+
const [loading, setLoading] = useState(false);
|
| 8 |
+
const [fetching, setFetching] = useState(false);
|
| 9 |
+
const [authUrl, setAuthUrl] = useState("");
|
| 10 |
+
const [callbackUrl, setCallbackUrl] = useState("");
|
| 11 |
+
const [showCallbackInput, setShowCallbackInput] = useState(false);
|
| 12 |
+
const [credsContent, setCredsContent] = useState("");
|
| 13 |
+
const [message, setMessage] = useState(null);
|
| 14 |
+
const [copied, setCopied] = useState(false);
|
| 15 |
+
|
| 16 |
+
const startAuth = async () => {
|
| 17 |
+
setLoading(true);
|
| 18 |
+
setMessage(null);
|
| 19 |
+
setAuthUrl("");
|
| 20 |
+
setCredsContent("");
|
| 21 |
+
|
| 22 |
+
try {
|
| 23 |
+
const res = await api.post("/auth/start", {});
|
| 24 |
+
setAuthUrl(res.data.auth_url);
|
| 25 |
+
setMessage({ type: "info", text: "已生成认证链接,请在新窗口完成 Google 授权" });
|
| 26 |
+
} catch (err) {
|
| 27 |
+
setMessage({
|
| 28 |
+
type: "error",
|
| 29 |
+
text: err.response?.data?.detail || "获取认证链接失败",
|
| 30 |
+
});
|
| 31 |
+
} finally {
|
| 32 |
+
setLoading(false);
|
| 33 |
+
}
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
const fetchCredentials = async () => {
|
| 37 |
+
setFetching(true);
|
| 38 |
+
try {
|
| 39 |
+
const res = await api.post("/auth/callback", {});
|
| 40 |
+
setCredsContent(JSON.stringify(res.data.credentials, null, 2));
|
| 41 |
+
setMessage({
|
| 42 |
+
type: "success",
|
| 43 |
+
text: `认证成功!凭证已保存:${res.data.email || "未知邮箱"}`,
|
| 44 |
+
});
|
| 45 |
+
} catch (err) {
|
| 46 |
+
setMessage({
|
| 47 |
+
type: "error",
|
| 48 |
+
text: err.response?.data?.detail || "获取凭证失败,请确认已完成授权",
|
| 49 |
+
});
|
| 50 |
+
} finally {
|
| 51 |
+
setFetching(false);
|
| 52 |
+
}
|
| 53 |
+
};
|
| 54 |
+
|
| 55 |
+
const processCallbackUrl = async () => {
|
| 56 |
+
if (!callbackUrl.trim()) {
|
| 57 |
+
setMessage({ type: "error", text: "请粘贴完整的回调URL" });
|
| 58 |
+
return;
|
| 59 |
+
}
|
| 60 |
+
setFetching(true);
|
| 61 |
+
try {
|
| 62 |
+
const res = await api.post("/auth/callback-url", {
|
| 63 |
+
callback_url: callbackUrl.trim(),
|
| 64 |
+
});
|
| 65 |
+
setCredsContent(JSON.stringify(res.data.credentials, null, 2));
|
| 66 |
+
setMessage({
|
| 67 |
+
type: "success",
|
| 68 |
+
text: `认证成功!凭证已保存:${res.data.email || "未知邮箱"}`,
|
| 69 |
+
});
|
| 70 |
+
} catch (err) {
|
| 71 |
+
setMessage({
|
| 72 |
+
type: "error",
|
| 73 |
+
text: err.response?.data?.detail || "从回调URL获取凭证失败",
|
| 74 |
+
});
|
| 75 |
+
} finally {
|
| 76 |
+
setFetching(false);
|
| 77 |
+
}
|
| 78 |
+
};
|
| 79 |
+
|
| 80 |
+
const copyUrl = () => {
|
| 81 |
+
navigator.clipboard.writeText(authUrl);
|
| 82 |
+
setCopied(true);
|
| 83 |
+
setTimeout(() => setCopied(false), 1500);
|
| 84 |
+
};
|
| 85 |
+
|
| 86 |
+
const downloadCreds = () => {
|
| 87 |
+
const blob = new Blob([credsContent], { type: "application/json" });
|
| 88 |
+
const url = URL.createObjectURL(blob);
|
| 89 |
+
const a = document.createElement("a");
|
| 90 |
+
a.href = url;
|
| 91 |
+
a.download = "antigravity-credentials.json";
|
| 92 |
+
a.click();
|
| 93 |
+
URL.revokeObjectURL(url);
|
| 94 |
+
};
|
| 95 |
+
|
| 96 |
+
return (
|
| 97 |
+
<div className="space-y-6">
|
| 98 |
+
{/* 说明卡片 */}
|
| 99 |
+
<div className="bg-gradient-to-br from-orange-900/30 to-orange-800/10 border border-orange-700/30 rounded-xl p-5">
|
| 100 |
+
<div className="flex items-center gap-2 mb-2">
|
| 101 |
+
<Rocket className="w-5 h-5 text-orange-400" />
|
| 102 |
+
<h3 className="text-lg font-semibold text-orange-400">Antigravity 认证模式</h3>
|
| 103 |
+
</div>
|
| 104 |
+
<p className="text-sm text-gray-400">
|
| 105 |
+
通过 Google OAuth 获取 Antigravity 凭证。授权成功后系统会自动获取 Project ID
|
| 106 |
+
和订阅等级,并保存凭证到数据库。
|
| 107 |
+
</p>
|
| 108 |
+
</div>
|
| 109 |
+
|
| 110 |
+
{/* 消息提示弹窗 */}
|
| 111 |
+
{message && (
|
| 112 |
+
<Modal
|
| 113 |
+
type={message.type}
|
| 114 |
+
title={message.type === "success" ? "操作成功" : message.type === "error" ? "操作失败" : "提示"}
|
| 115 |
+
onClose={() => setMessage(null)}
|
| 116 |
+
>
|
| 117 |
+
<span className="whitespace-pre-wrap break-all">{message.text}</span>
|
| 118 |
+
</Modal>
|
| 119 |
+
)}
|
| 120 |
+
|
| 121 |
+
{/* 获取认证链接按钮 */}
|
| 122 |
+
<button
|
| 123 |
+
onClick={startAuth}
|
| 124 |
+
disabled={loading}
|
| 125 |
+
className="btn btn-primary flex items-center gap-2 disabled:opacity-50"
|
| 126 |
+
>
|
| 127 |
+
{loading ? (
|
| 128 |
+
<Loader2 className="animate-spin" size={18} />
|
| 129 |
+
) : (
|
| 130 |
+
<Rocket size={18} />
|
| 131 |
+
)}
|
| 132 |
+
获取 Antigravity 认证链接
|
| 133 |
+
</button>
|
| 134 |
+
|
| 135 |
+
{/* 认证链接 */}
|
| 136 |
+
{authUrl && (
|
| 137 |
+
<div className="card space-y-4">
|
| 138 |
+
<h3 className="font-semibold">认证链接</h3>
|
| 139 |
+
<div className="bg-dark-800 border border-purple-500/30 rounded-lg p-4 flex items-center justify-between gap-3">
|
| 140 |
+
<a
|
| 141 |
+
href={authUrl}
|
| 142 |
+
target="_blank"
|
| 143 |
+
rel="noopener noreferrer"
|
| 144 |
+
className="text-purple-400 hover:text-purple-300 break-all text-sm flex items-center gap-1"
|
| 145 |
+
>
|
| 146 |
+
点击此链接进行 Google 认证 <ExternalLink size={14} />
|
| 147 |
+
</a>
|
| 148 |
+
<button
|
| 149 |
+
onClick={copyUrl}
|
| 150 |
+
className="btn btn-secondary text-xs px-3 py-1.5 flex items-center gap-1 flex-shrink-0"
|
| 151 |
+
>
|
| 152 |
+
{copied ? <Check size={14} /> : <Copy size={14} />}
|
| 153 |
+
{copied ? "已复制" : "复制"}
|
| 154 |
+
</button>
|
| 155 |
+
</div>
|
| 156 |
+
|
| 157 |
+
<div className="bg-blue-500/10 border border-blue-500/30 rounded-lg p-4 text-sm text-gray-400">
|
| 158 |
+
<p className="font-medium text-blue-400 mb-2">使用说明</p>
|
| 159 |
+
<ol className="list-decimal list-inside space-y-1">
|
| 160 |
+
<li>点击上方认证链接,在新窗口中完成 Google 账号授权</li>
|
| 161 |
+
<li>授权成功后会跳转到 localhost 显示成功页面</li>
|
| 162 |
+
<li>关闭 OAuth 窗口,返回本页面</li>
|
| 163 |
+
<li>点击下方"获取凭证"按钮完成流程</li>
|
| 164 |
+
</ol>
|
| 165 |
+
</div>
|
| 166 |
+
|
| 167 |
+
{/* 快捷回调URL */}
|
| 168 |
+
<div className="border border-dark-600 rounded-lg">
|
| 169 |
+
<button
|
| 170 |
+
onClick={() => setShowCallbackInput(!showCallbackInput)}
|
| 171 |
+
className="w-full flex items-center justify-between px-4 py-3 text-sm text-gray-400 hover:text-gray-200"
|
| 172 |
+
>
|
| 173 |
+
<span>🚀 无法回源?试试快捷方式(粘贴回调URL)</span>
|
| 174 |
+
<ChevronDown
|
| 175 |
+
size={16}
|
| 176 |
+
className={`transition-transform ${showCallbackInput ? "rotate-180" : ""}`}
|
| 177 |
+
/>
|
| 178 |
+
</button>
|
| 179 |
+
{showCallbackInput && (
|
| 180 |
+
<div className="px-4 pb-4 space-y-3">
|
| 181 |
+
<p className="text-xs text-gray-500">
|
| 182 |
+
适用场景:云服务器/VPS、Docker 容器、防火墙阻止回调端口等。
|
| 183 |
+
完成 Google 授权后,复制浏览器地址栏的完整 URL 粘贴到下方。
|
| 184 |
+
</p>
|
| 185 |
+
<textarea
|
| 186 |
+
value={callbackUrl}
|
| 187 |
+
onChange={(e) => setCallbackUrl(e.target.value)}
|
| 188 |
+
placeholder="http://localhost:11451/?state=xxx&code=xxx&scope=xxx..."
|
| 189 |
+
className="w-full px-3 py-2 bg-dark-800 border border-dark-600 rounded-lg text-sm text-white placeholder-gray-500"
|
| 190 |
+
rows={3}
|
| 191 |
+
/>
|
| 192 |
+
<button
|
| 193 |
+
onClick={processCallbackUrl}
|
| 194 |
+
disabled={fetching}
|
| 195 |
+
className="btn btn-secondary text-sm flex items-center gap-2 disabled:opacity-50"
|
| 196 |
+
>
|
| 197 |
+
{fetching && <Loader2 className="animate-spin" size={14} />}
|
| 198 |
+
从回调URL获取凭证
|
| 199 |
+
</button>
|
| 200 |
+
</div>
|
| 201 |
+
)}
|
| 202 |
+
</div>
|
| 203 |
+
|
| 204 |
+
{/* 获取凭证按钮 */}
|
| 205 |
+
<button
|
| 206 |
+
onClick={fetchCredentials}
|
| 207 |
+
disabled={fetching}
|
| 208 |
+
className="btn btn-primary flex items-center gap-2 disabled:opacity-50"
|
| 209 |
+
>
|
| 210 |
+
{fetching && <Loader2 className="animate-spin" size={18} />}
|
| 211 |
+
获取 Antigravity 凭证
|
| 212 |
+
</button>
|
| 213 |
+
</div>
|
| 214 |
+
)}
|
| 215 |
+
|
| 216 |
+
{/* 凭证内容 */}
|
| 217 |
+
{credsContent && (
|
| 218 |
+
<div className="card space-y-4">
|
| 219 |
+
<h3 className="font-semibold">凭证内容</h3>
|
| 220 |
+
<pre className="bg-dark-800 border border-dark-600 rounded-lg p-4 text-xs text-gray-300 overflow-x-auto max-h-96 overflow-y-auto">
|
| 221 |
+
{credsContent}
|
| 222 |
+
</pre>
|
| 223 |
+
<button onClick={downloadCreds} className="btn btn-secondary text-sm">
|
| 224 |
+
下载凭证文件
|
| 225 |
+
</button>
|
| 226 |
+
</div>
|
| 227 |
+
)}
|
| 228 |
+
</div>
|
| 229 |
+
);
|
| 230 |
+
}
|
agy2api/frontend/src/pages/Upload.jsx
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { CheckCircle, FileJson, Loader2, Trash2, Upload, X } from "lucide-react";
|
| 2 |
+
import { useRef, useState } from "react";
|
| 3 |
+
import api from "../api";
|
| 4 |
+
|
| 5 |
+
export default function UploadPage() {
|
| 6 |
+
const [files, setFiles] = useState([]);
|
| 7 |
+
const [uploading, setUploading] = useState(false);
|
| 8 |
+
const [results, setResults] = useState(null);
|
| 9 |
+
const [dragOver, setDragOver] = useState(false);
|
| 10 |
+
const inputRef = useRef(null);
|
| 11 |
+
|
| 12 |
+
const addFiles = (fileList) => {
|
| 13 |
+
const valid = Array.from(fileList).filter(
|
| 14 |
+
(f) => f.name.endsWith(".json") || f.name.endsWith(".zip")
|
| 15 |
+
);
|
| 16 |
+
setFiles((prev) => {
|
| 17 |
+
const names = new Set(prev.map((f) => f.name));
|
| 18 |
+
return [...prev, ...valid.filter((f) => !names.has(f.name))];
|
| 19 |
+
});
|
| 20 |
+
setResults(null);
|
| 21 |
+
};
|
| 22 |
+
|
| 23 |
+
const removeFile = (name) => {
|
| 24 |
+
setFiles((prev) => prev.filter((f) => f.name !== name));
|
| 25 |
+
};
|
| 26 |
+
|
| 27 |
+
const upload = async () => {
|
| 28 |
+
if (files.length === 0) return;
|
| 29 |
+
setUploading(true);
|
| 30 |
+
setResults(null);
|
| 31 |
+
|
| 32 |
+
try {
|
| 33 |
+
const formData = new FormData();
|
| 34 |
+
files.forEach((f) => formData.append("files", f));
|
| 35 |
+
|
| 36 |
+
const res = await api.post("/creds/upload", formData, {
|
| 37 |
+
headers: { "Content-Type": "multipart/form-data" },
|
| 38 |
+
});
|
| 39 |
+
setResults(res.data);
|
| 40 |
+
} catch (err) {
|
| 41 |
+
setResults({
|
| 42 |
+
error: err.response?.data?.detail || "上传失败",
|
| 43 |
+
});
|
| 44 |
+
} finally {
|
| 45 |
+
setUploading(false);
|
| 46 |
+
}
|
| 47 |
+
};
|
| 48 |
+
|
| 49 |
+
const successCount = results?.uploaded_count || 0;
|
| 50 |
+
const totalCount = results?.total_count || 0;
|
| 51 |
+
|
| 52 |
+
return (
|
| 53 |
+
<div className="space-y-6">
|
| 54 |
+
<div className="bg-gradient-to-br from-emerald-900/30 to-emerald-800/10 border border-emerald-700/30 rounded-xl p-5">
|
| 55 |
+
<h3 className="text-lg font-semibold text-emerald-400 mb-2">批量导入凭证</h3>
|
| 56 |
+
<p className="text-sm text-gray-400">
|
| 57 |
+
支持批量导入 Antigravity 凭证(.json 或包含 JSON 文件的 .zip)。
|
| 58 |
+
</p>
|
| 59 |
+
<div className="mt-3 text-xs text-gray-500 bg-dark-800/60 rounded-lg p-3">
|
| 60 |
+
<p className="mb-1 font-medium text-gray-400">规范 JSON 格式:</p>
|
| 61 |
+
<pre className="text-emerald-300/80 whitespace-pre-wrap font-mono">{`{
|
| 62 |
+
"refresh_token": "必填",
|
| 63 |
+
"access_token": "可选,未过期时直接复用",
|
| 64 |
+
"expiry": "可选,access_token 过期时间",
|
| 65 |
+
"email": "可选,缺失自动获取",
|
| 66 |
+
"tier": "可选,缺失自动获取",
|
| 67 |
+
"project_id": "可选,缺失自动获取"
|
| 68 |
+
}`}</pre>
|
| 69 |
+
<p className="mt-2">refresh_token 无效的凭证将导入失败;同邮箱凭证自动去重(覆盖更新)。</p>
|
| 70 |
+
</div>
|
| 71 |
+
</div>
|
| 72 |
+
|
| 73 |
+
{/* 上传区域 */}
|
| 74 |
+
<div
|
| 75 |
+
className={`border-2 border-dashed rounded-xl p-10 text-center cursor-pointer transition-colors ${
|
| 76 |
+
dragOver
|
| 77 |
+
? "border-purple-500 bg-purple-500/10"
|
| 78 |
+
: "border-dark-600 hover:border-dark-500"
|
| 79 |
+
}`}
|
| 80 |
+
onClick={() => inputRef.current?.click()}
|
| 81 |
+
onDragOver={(e) => {
|
| 82 |
+
e.preventDefault();
|
| 83 |
+
setDragOver(true);
|
| 84 |
+
}}
|
| 85 |
+
onDragLeave={() => setDragOver(false)}
|
| 86 |
+
onDrop={(e) => {
|
| 87 |
+
e.preventDefault();
|
| 88 |
+
setDragOver(false);
|
| 89 |
+
addFiles(e.dataTransfer.files);
|
| 90 |
+
}}
|
| 91 |
+
>
|
| 92 |
+
<Upload className="mx-auto text-purple-400 mb-3" size={32} />
|
| 93 |
+
<p className="text-gray-300">点击选择文件或拖拽文件到此区域</p>
|
| 94 |
+
<p className="text-gray-500 text-sm mt-1">支持 .json 和 .zip 格式,ZIP 会自动提取其中的 JSON 凭证</p>
|
| 95 |
+
<input
|
| 96 |
+
ref={inputRef}
|
| 97 |
+
type="file"
|
| 98 |
+
multiple
|
| 99 |
+
accept=".json,.zip"
|
| 100 |
+
className="hidden"
|
| 101 |
+
onChange={(e) => {
|
| 102 |
+
addFiles(e.target.files);
|
| 103 |
+
e.target.value = "";
|
| 104 |
+
}}
|
| 105 |
+
/>
|
| 106 |
+
</div>
|
| 107 |
+
|
| 108 |
+
{/* 文件列表 */}
|
| 109 |
+
{files.length > 0 && (
|
| 110 |
+
<div className="card space-y-3">
|
| 111 |
+
<div className="flex items-center justify-between">
|
| 112 |
+
<h4 className="text-sm font-medium text-gray-300">
|
| 113 |
+
已选择 {files.length} 个文件
|
| 114 |
+
</h4>
|
| 115 |
+
<div className="flex gap-2">
|
| 116 |
+
<button
|
| 117 |
+
onClick={upload}
|
| 118 |
+
disabled={uploading}
|
| 119 |
+
className="btn btn-primary text-sm flex items-center gap-1.5 disabled:opacity-50"
|
| 120 |
+
>
|
| 121 |
+
{uploading ? (
|
| 122 |
+
<Loader2 size={14} className="animate-spin" />
|
| 123 |
+
) : (
|
| 124 |
+
<Upload size={14} />
|
| 125 |
+
)}
|
| 126 |
+
{uploading ? "上传中..." : "上传文件"}
|
| 127 |
+
</button>
|
| 128 |
+
<button
|
| 129 |
+
onClick={() => setFiles([])}
|
| 130 |
+
disabled={uploading}
|
| 131 |
+
className="btn btn-secondary text-sm"
|
| 132 |
+
>
|
| 133 |
+
清空列表
|
| 134 |
+
</button>
|
| 135 |
+
</div>
|
| 136 |
+
</div>
|
| 137 |
+
<div className="space-y-1.5 max-h-64 overflow-y-auto">
|
| 138 |
+
{files.map((f) => (
|
| 139 |
+
<div
|
| 140 |
+
key={f.name}
|
| 141 |
+
className="flex items-center justify-between bg-dark-800 border border-dark-600 rounded-lg px-3 py-2 text-sm"
|
| 142 |
+
>
|
| 143 |
+
<div className="flex items-center gap-2 text-gray-300 min-w-0">
|
| 144 |
+
<FileJson size={15} className="text-purple-400 flex-shrink-0" />
|
| 145 |
+
<span className="truncate">{f.name}</span>
|
| 146 |
+
</div>
|
| 147 |
+
<div className="flex items-center gap-3 flex-shrink-0">
|
| 148 |
+
<span className="text-gray-500 text-xs">
|
| 149 |
+
{(f.size / 1024).toFixed(1)} KB
|
| 150 |
+
</span>
|
| 151 |
+
<button
|
| 152 |
+
onClick={() => removeFile(f.name)}
|
| 153 |
+
className="text-gray-500 hover:text-red-400"
|
| 154 |
+
>
|
| 155 |
+
<X size={14} />
|
| 156 |
+
</button>
|
| 157 |
+
</div>
|
| 158 |
+
</div>
|
| 159 |
+
))}
|
| 160 |
+
</div>
|
| 161 |
+
</div>
|
| 162 |
+
)}
|
| 163 |
+
|
| 164 |
+
{/* 上传结果 */}
|
| 165 |
+
{results && (
|
| 166 |
+
<div className="card space-y-3">
|
| 167 |
+
{results.error ? (
|
| 168 |
+
<div className="bg-red-500/10 border border-red-500/30 text-red-400 px-4 py-3 rounded-lg">
|
| 169 |
+
{results.error}
|
| 170 |
+
</div>
|
| 171 |
+
) : (
|
| 172 |
+
<>
|
| 173 |
+
<div className="bg-green-500/10 border border-green-500/30 text-green-400 px-4 py-3 rounded-lg flex items-center gap-2">
|
| 174 |
+
<CheckCircle size={16} />
|
| 175 |
+
{results.message ||
|
| 176 |
+
`上传完成: 成功 ${successCount}/${totalCount} 个文件`}
|
| 177 |
+
</div>
|
| 178 |
+
{results.results?.some((r) => r.status === "error") && (
|
| 179 |
+
<div className="space-y-1.5">
|
| 180 |
+
<div className="text-sm text-gray-400">失败详情:</div>
|
| 181 |
+
{results.results
|
| 182 |
+
.filter((r) => r.status === "error")
|
| 183 |
+
.map((r, i) => (
|
| 184 |
+
<div
|
| 185 |
+
key={i}
|
| 186 |
+
className="bg-red-500/10 border border-red-500/20 text-red-400 text-xs px-3 py-2 rounded-lg"
|
| 187 |
+
>
|
| 188 |
+
<span className="font-medium">{r.filename}</span>: {r.message}
|
| 189 |
+
</div>
|
| 190 |
+
))}
|
| 191 |
+
</div>
|
| 192 |
+
)}
|
| 193 |
+
</>
|
| 194 |
+
)}
|
| 195 |
+
</div>
|
| 196 |
+
)}
|
| 197 |
+
</div>
|
| 198 |
+
);
|
| 199 |
+
}
|
agy2api/frontend/src/pages/UsageLogs.jsx
ADDED
|
@@ -0,0 +1,510 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {
|
| 2 |
+
AlertTriangle,
|
| 3 |
+
BarChart3,
|
| 4 |
+
CheckCircle,
|
| 5 |
+
Clock,
|
| 6 |
+
Cpu,
|
| 7 |
+
Database,
|
| 8 |
+
FileText,
|
| 9 |
+
Loader2,
|
| 10 |
+
RefreshCw,
|
| 11 |
+
Trash2,
|
| 12 |
+
XCircle,
|
| 13 |
+
} from "lucide-react";
|
| 14 |
+
import { useCallback, useEffect, useState } from "react";
|
| 15 |
+
import Modal from "../components/Modal";
|
| 16 |
+
import Select from "../components/Select";
|
| 17 |
+
import api from "../api";
|
| 18 |
+
|
| 19 |
+
const PAGE_SIZES = [20, 50, 100, 200].map((n) => ({ value: n, label: `每页 ${n}` }));
|
| 20 |
+
|
| 21 |
+
function formatTime(ts) {
|
| 22 |
+
const d = new Date(ts * 1000);
|
| 23 |
+
const pad = (x) => String(x).padStart(2, "0");
|
| 24 |
+
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
function formatTokens(n) {
|
| 28 |
+
if (!n) return "0";
|
| 29 |
+
if (n >= 1000000) return `${(n / 1000000).toFixed(1)}M`;
|
| 30 |
+
if (n >= 1000) return `${(n / 1000).toFixed(1)}K`;
|
| 31 |
+
return String(n);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
function formatMaybeJson(text) {
|
| 35 |
+
if (typeof text !== "string") return JSON.stringify(text ?? null, null, 2);
|
| 36 |
+
try {
|
| 37 |
+
return JSON.stringify(JSON.parse(text), null, 2);
|
| 38 |
+
} catch {
|
| 39 |
+
return text;
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
export default function UsageLogs() {
|
| 44 |
+
const [items, setItems] = useState([]);
|
| 45 |
+
const [total, setTotal] = useState(0);
|
| 46 |
+
const [stats, setStats] = useState(null);
|
| 47 |
+
const [page, setPage] = useState(1);
|
| 48 |
+
const [pageSize, setPageSize] = useState(20);
|
| 49 |
+
const [statusFilter, setStatusFilter] = useState("all");
|
| 50 |
+
const [formatFilter, setFormatFilter] = useState("");
|
| 51 |
+
const [modelFilter, setModelFilter] = useState("");
|
| 52 |
+
const [statusCodeFilter, setStatusCodeFilter] = useState("");
|
| 53 |
+
const [loading, setLoading] = useState(true);
|
| 54 |
+
const [clearing, setClearing] = useState(false);
|
| 55 |
+
const [message, setMessage] = useState(null);
|
| 56 |
+
const [detail, setDetail] = useState(null);
|
| 57 |
+
const [detailBody, setDetailBody] = useState(null);
|
| 58 |
+
const [detailBodyLoading, setDetailBodyLoading] = useState(false);
|
| 59 |
+
const [copyStatus, setCopyStatus] = useState(null); // null | "ok" | "fail",请求体详细日志复制结果,弹窗内就地反馈
|
| 60 |
+
|
| 61 |
+
// 时间范围(小时)
|
| 62 |
+
const [rangeHours, setRangeHours] = useState(24);
|
| 63 |
+
|
| 64 |
+
const fetchLogs = useCallback(async () => {
|
| 65 |
+
setLoading(true);
|
| 66 |
+
try {
|
| 67 |
+
const params = {
|
| 68 |
+
offset: (page - 1) * pageSize,
|
| 69 |
+
limit: pageSize,
|
| 70 |
+
status: statusFilter,
|
| 71 |
+
};
|
| 72 |
+
if (formatFilter) params.api_format = formatFilter;
|
| 73 |
+
if (modelFilter.trim()) params.model_name = modelFilter.trim();
|
| 74 |
+
const code = parseInt(statusCodeFilter, 10);
|
| 75 |
+
if (statusCodeFilter.trim() !== "" && Number.isInteger(code)) params.status_code = code;
|
| 76 |
+
if (rangeHours > 0) params.start_timestamp = Math.floor(Date.now() / 1000) - rangeHours * 3600;
|
| 77 |
+
|
| 78 |
+
const res = await api.get("/usage-logs/list", { params });
|
| 79 |
+
setItems(res.data.items);
|
| 80 |
+
setTotal(res.data.total);
|
| 81 |
+
} catch (err) {
|
| 82 |
+
setMessage({ type: "error", text: err.response?.data?.detail || "加载日志失败" });
|
| 83 |
+
} finally {
|
| 84 |
+
setLoading(false);
|
| 85 |
+
}
|
| 86 |
+
}, [page, pageSize, statusFilter, formatFilter, modelFilter, statusCodeFilter, rangeHours]);
|
| 87 |
+
|
| 88 |
+
const fetchStats = useCallback(async () => {
|
| 89 |
+
try {
|
| 90 |
+
const params = {};
|
| 91 |
+
if (rangeHours > 0) params.start_timestamp = Math.floor(Date.now() / 1000) - rangeHours * 3600;
|
| 92 |
+
if (formatFilter) params.api_format = formatFilter;
|
| 93 |
+
if (modelFilter.trim()) params.model_name = modelFilter.trim();
|
| 94 |
+
const res = await api.get("/usage-logs/stats", { params });
|
| 95 |
+
setStats(res.data);
|
| 96 |
+
} catch (err) {
|
| 97 |
+
/* 统计失败不阻塞 */
|
| 98 |
+
}
|
| 99 |
+
}, [rangeHours, formatFilter, modelFilter]);
|
| 100 |
+
|
| 101 |
+
useEffect(() => {
|
| 102 |
+
fetchLogs();
|
| 103 |
+
}, [fetchLogs]);
|
| 104 |
+
|
| 105 |
+
useEffect(() => {
|
| 106 |
+
fetchStats();
|
| 107 |
+
}, [fetchStats]);
|
| 108 |
+
|
| 109 |
+
const refresh = () => {
|
| 110 |
+
fetchLogs();
|
| 111 |
+
fetchStats();
|
| 112 |
+
};
|
| 113 |
+
|
| 114 |
+
const clearLogs = async () => {
|
| 115 |
+
if (!window.confirm("确定要清理 3 天前的日志吗?此操作不可恢复。")) return;
|
| 116 |
+
setClearing(true);
|
| 117 |
+
try {
|
| 118 |
+
const res = await api.post("/usage-logs/clear", null, { params: { days: 3 } });
|
| 119 |
+
setMessage({ type: "success", text: res.data.message || "清理成功" });
|
| 120 |
+
refresh();
|
| 121 |
+
} catch (err) {
|
| 122 |
+
setMessage({ type: "error", text: err.response?.data?.detail || "清理失败" });
|
| 123 |
+
} finally {
|
| 124 |
+
setClearing(false);
|
| 125 |
+
}
|
| 126 |
+
};
|
| 127 |
+
|
| 128 |
+
const truncateLogs = async () => {
|
| 129 |
+
if (!window.confirm("确定要清空全部请求日志吗?\n整张日志表将被删除重建,不留任何残留,此操作不可恢复。")) return;
|
| 130 |
+
setClearing(true);
|
| 131 |
+
try {
|
| 132 |
+
const res = await api.post("/usage-logs/truncate");
|
| 133 |
+
setMessage({ type: "success", text: res.data.message || "已清空全部日志" });
|
| 134 |
+
refresh();
|
| 135 |
+
} catch (err) {
|
| 136 |
+
setMessage({ type: "error", text: err.response?.data?.detail || "清空失败" });
|
| 137 |
+
} finally {
|
| 138 |
+
setClearing(false);
|
| 139 |
+
}
|
| 140 |
+
};
|
| 141 |
+
|
| 142 |
+
const totalPages = Math.max(1, Math.ceil(total / pageSize));
|
| 143 |
+
|
| 144 |
+
// 请求体详细日志:按索引从磁盘读取
|
| 145 |
+
const openRequestBody = async () => {
|
| 146 |
+
if (!detail?.request_log_file) return;
|
| 147 |
+
setCopyStatus(null);
|
| 148 |
+
setDetailBodyLoading(true);
|
| 149 |
+
try {
|
| 150 |
+
const res = await api.get("/usage-logs/request-body", { params: { path: detail.request_log_file } });
|
| 151 |
+
setDetailBody(res.data);
|
| 152 |
+
} catch (err) {
|
| 153 |
+
// 文件可能已被清理或手动删除,仅在详情弹窗内提示,不弹全局错误
|
| 154 |
+
setDetailBody({ __missing: true, __message: err.response?.data?.detail || "详细日志文件不存在或已清理" });
|
| 155 |
+
} finally {
|
| 156 |
+
setDetailBodyLoading(false);
|
| 157 |
+
}
|
| 158 |
+
};
|
| 159 |
+
|
| 160 |
+
const copyDetailBody = async () => {
|
| 161 |
+
if (!detailBody || detailBody.__missing) return;
|
| 162 |
+
const text = JSON.stringify(detailBody, null, 2);
|
| 163 |
+
let ok = false;
|
| 164 |
+
try {
|
| 165 |
+
if (navigator.clipboard?.writeText) {
|
| 166 |
+
await navigator.clipboard.writeText(text);
|
| 167 |
+
ok = true;
|
| 168 |
+
} else {
|
| 169 |
+
// 非安全上下文(http + 局域网 IP)下 navigator.clipboard 不可用,退回 execCommand 兜底
|
| 170 |
+
const ta = document.createElement("textarea");
|
| 171 |
+
ta.value = text;
|
| 172 |
+
ta.style.position = "fixed";
|
| 173 |
+
ta.style.top = "-9999px";
|
| 174 |
+
ta.style.opacity = "0";
|
| 175 |
+
document.body.appendChild(ta);
|
| 176 |
+
ta.select();
|
| 177 |
+
ok = document.execCommand("copy");
|
| 178 |
+
document.body.removeChild(ta);
|
| 179 |
+
}
|
| 180 |
+
} catch {
|
| 181 |
+
ok = false;
|
| 182 |
+
}
|
| 183 |
+
setCopyStatus(ok ? "ok" : "fail");
|
| 184 |
+
};
|
| 185 |
+
|
| 186 |
+
return (
|
| 187 |
+
<div className="space-y-4">
|
| 188 |
+
{/* 统计卡片 */}
|
| 189 |
+
{stats && (
|
| 190 |
+
<div className="grid grid-cols-2 lg:grid-cols-4 gap-3">
|
| 191 |
+
<div className="card p-4 flex items-center gap-3">
|
| 192 |
+
<div className="p-2.5 bg-purple-600/20 rounded-lg">
|
| 193 |
+
<Database size={20} className="text-purple-400" />
|
| 194 |
+
</div>
|
| 195 |
+
<div className="min-w-0">
|
| 196 |
+
<div className="text-xl font-bold">{stats.total_requests}</div>
|
| 197 |
+
<div className="text-xs text-gray-500">总请求</div>
|
| 198 |
+
</div>
|
| 199 |
+
</div>
|
| 200 |
+
<div className="card p-4 flex items-center gap-3">
|
| 201 |
+
<div className="p-2.5 bg-green-600/20 rounded-lg">
|
| 202 |
+
<CheckCircle size={20} className="text-green-400" />
|
| 203 |
+
</div>
|
| 204 |
+
<div className="min-w-0">
|
| 205 |
+
<div className="text-xl font-bold text-green-400">{stats.success_count}</div>
|
| 206 |
+
<div className="text-xs text-gray-500">成功</div>
|
| 207 |
+
</div>
|
| 208 |
+
</div>
|
| 209 |
+
<div className="card p-4 flex items-center gap-3">
|
| 210 |
+
<div className="p-2.5 bg-red-600/20 rounded-lg">
|
| 211 |
+
<XCircle size={20} className="text-red-400" />
|
| 212 |
+
</div>
|
| 213 |
+
<div className="min-w-0">
|
| 214 |
+
<div className="text-xl font-bold text-red-400">{stats.error_count}</div>
|
| 215 |
+
<div className="text-xs text-gray-500">失败</div>
|
| 216 |
+
</div>
|
| 217 |
+
</div>
|
| 218 |
+
<div className="card p-4 flex items-center gap-3">
|
| 219 |
+
<div className="p-2.5 bg-blue-600/20 rounded-lg">
|
| 220 |
+
<Cpu size={20} className="text-blue-400" />
|
| 221 |
+
</div>
|
| 222 |
+
<div className="min-w-0">
|
| 223 |
+
<div className="text-xl font-bold">{formatTokens(stats.total_tokens)}</div>
|
| 224 |
+
<div className="text-xs text-gray-500">
|
| 225 |
+
总 Tokens{stats.cached_tokens > 0 ? `(缓存 ${formatTokens(stats.cached_tokens)})` : ""}
|
| 226 |
+
</div>
|
| 227 |
+
</div>
|
| 228 |
+
</div>
|
| 229 |
+
</div>
|
| 230 |
+
)}
|
| 231 |
+
|
| 232 |
+
{/* 操作栏 */}
|
| 233 |
+
<div className="flex flex-wrap items-center gap-2">
|
| 234 |
+
<button onClick={refresh} disabled={loading} className="btn btn-secondary text-xs sm:text-sm px-3 py-1.5 sm:px-4 sm:py-2 flex items-center gap-1.5">
|
| 235 |
+
<RefreshCw size={15} className={loading ? "animate-spin" : ""} />
|
| 236 |
+
刷新
|
| 237 |
+
</button>
|
| 238 |
+
<button onClick={clearLogs} disabled={clearing} className="btn btn-secondary text-xs sm:text-sm px-3 py-1.5 sm:px-4 sm:py-2 flex items-center gap-1.5">
|
| 239 |
+
{clearing ? <Loader2 size={15} className="animate-spin" /> : <Trash2 size={15} />}
|
| 240 |
+
清理3天前日志
|
| 241 |
+
</button>
|
| 242 |
+
<button onClick={truncateLogs} disabled={clearing} className="btn btn-danger text-xs sm:text-sm px-3 py-1.5 sm:px-4 sm:py-2 flex items-center gap-1.5">
|
| 243 |
+
<Trash2 size={15} />
|
| 244 |
+
清空全部日志
|
| 245 |
+
</button>
|
| 246 |
+
</div>
|
| 247 |
+
|
| 248 |
+
{/* 消息弹窗 */}
|
| 249 |
+
{message && (
|
| 250 |
+
<Modal type={message.type} title={message.type === "success" ? "操作成功" : "操作失败"} onClose={() => setMessage(null)}>
|
| 251 |
+
<span className="whitespace-pre-wrap break-all">{message.text}</span>
|
| 252 |
+
</Modal>
|
| 253 |
+
)}
|
| 254 |
+
|
| 255 |
+
{/* 筛选器 */}
|
| 256 |
+
<div className="grid grid-cols-2 sm:flex sm:flex-wrap gap-2 sm:gap-3 text-sm">
|
| 257 |
+
<Select
|
| 258 |
+
value={rangeHours}
|
| 259 |
+
onChange={(v) => { setRangeHours(Number(v)); setPage(1); }}
|
| 260 |
+
className="w-full sm:w-32"
|
| 261 |
+
options={[
|
| 262 |
+
{ value: 1, label: "最近 1 小时" },
|
| 263 |
+
{ value: 6, label: "最近 6 小时" },
|
| 264 |
+
{ value: 24, label: "最近 24 小时" },
|
| 265 |
+
{ value: 24 * 7, label: "最近 7 天" },
|
| 266 |
+
{ value: 24 * 30, label: "最近 30 天" },
|
| 267 |
+
{ value: 0, label: "全部时间" },
|
| 268 |
+
]}
|
| 269 |
+
/>
|
| 270 |
+
<Select
|
| 271 |
+
value={statusFilter}
|
| 272 |
+
onChange={(v) => { setStatusFilter(v); setPage(1); }}
|
| 273 |
+
className="w-full sm:w-32"
|
| 274 |
+
options={[
|
| 275 |
+
{ value: "all", label: "状态: 全部" },
|
| 276 |
+
{ value: "success", label: "仅成功" },
|
| 277 |
+
{ value: "error", label: "仅失败" },
|
| 278 |
+
]}
|
| 279 |
+
/>
|
| 280 |
+
<Select
|
| 281 |
+
value={formatFilter}
|
| 282 |
+
onChange={(v) => { setFormatFilter(v); setPage(1); }}
|
| 283 |
+
className="w-full sm:w-32"
|
| 284 |
+
options={[
|
| 285 |
+
{ value: "", label: "格式: 全部" },
|
| 286 |
+
{ value: "openai", label: "OpenAI" },
|
| 287 |
+
{ value: "gemini", label: "Gemini" },
|
| 288 |
+
{ value: "anthropic", label: "Claude" },
|
| 289 |
+
]}
|
| 290 |
+
/>
|
| 291 |
+
<input
|
| 292 |
+
value={modelFilter}
|
| 293 |
+
onChange={(e) => { setModelFilter(e.target.value); setPage(1); }}
|
| 294 |
+
placeholder="模型名筛选"
|
| 295 |
+
className="w-full sm:w-40 bg-dark-800 border border-dark-600 rounded-lg px-3 py-2 text-gray-200 text-xs sm:text-sm placeholder-gray-500"
|
| 296 |
+
/>
|
| 297 |
+
<input
|
| 298 |
+
value={statusCodeFilter}
|
| 299 |
+
onChange={(e) => { setStatusCodeFilter(e.target.value); setPage(1); }}
|
| 300 |
+
placeholder="错误码筛选"
|
| 301 |
+
inputMode="numeric"
|
| 302 |
+
className="w-full sm:w-28 bg-dark-800 border border-dark-600 rounded-lg px-3 py-2 text-gray-200 text-xs sm:text-sm placeholder-gray-500"
|
| 303 |
+
/>
|
| 304 |
+
<Select
|
| 305 |
+
value={pageSize}
|
| 306 |
+
onChange={(v) => { setPageSize(Number(v)); setPage(1); }}
|
| 307 |
+
className="w-full sm:w-32"
|
| 308 |
+
options={PAGE_SIZES}
|
| 309 |
+
/>
|
| 310 |
+
</div>
|
| 311 |
+
|
| 312 |
+
{/* 列表 */}
|
| 313 |
+
{loading ? (
|
| 314 |
+
<div className="flex items-center justify-center py-12">
|
| 315 |
+
<Loader2 className="animate-spin text-purple-500" size={28} />
|
| 316 |
+
</div>
|
| 317 |
+
) : items.length === 0 ? (
|
| 318 |
+
<div className="card p-8 text-center text-gray-500">暂无请求日志</div>
|
| 319 |
+
) : (
|
| 320 |
+
<div className="space-y-2">
|
| 321 |
+
{items.map((item) => (
|
| 322 |
+
<button
|
| 323 |
+
key={item.id}
|
| 324 |
+
onClick={() => { setDetail(item); setDetailBody(null); }}
|
| 325 |
+
className="card p-3 sm:p-4 w-full text-left hover:border-purple-500/40 transition-colors cursor-pointer"
|
| 326 |
+
>
|
| 327 |
+
<div className="flex items-start justify-between gap-2">
|
| 328 |
+
<div className="min-w-0 flex-1">
|
| 329 |
+
<div className="flex items-center gap-2 flex-wrap">
|
| 330 |
+
<span className={`text-xs px-1.5 py-0.5 rounded ${item.success ? "bg-green-500/15 text-green-400" : "bg-red-500/15 text-red-400"}`}>
|
| 331 |
+
{item.success ? "✓ 成功" : `✗ ${item.status_code || "失败"}`}
|
| 332 |
+
</span>
|
| 333 |
+
<span className="text-sm font-medium text-gray-200 truncate">{item.model_name || "(unknown)"}</span>
|
| 334 |
+
{item.upstream_model_name && item.upstream_model_name !== item.model_name && (
|
| 335 |
+
<span className="text-xs text-gray-500 truncate" title="后端真实模型名">→ {item.upstream_model_name}</span>
|
| 336 |
+
)}
|
| 337 |
+
<span className="text-xs px-1.5 py-0.5 rounded bg-dark-700 text-gray-400">
|
| 338 |
+
{item.api_format === "openai" ? "OpenAI" : item.api_format === "gemini" ? "Gemini" : item.api_format === "anthropic" ? "Claude" : item.api_format || "?"}
|
| 339 |
+
</span>
|
| 340 |
+
{item.is_stream && <span className="text-xs px-1.5 py-0.5 rounded bg-blue-500/15 text-blue-400">流式</span>}
|
| 341 |
+
{item.request_log_file && <span className="text-xs px-1.5 py-0.5 rounded bg-amber-500/15 text-amber-400">详细</span>}
|
| 342 |
+
</div>
|
| 343 |
+
<div className="text-xs text-gray-500 mt-1 flex flex-wrap gap-x-3 gap-y-0.5">
|
| 344 |
+
<span className="flex items-center gap-1"><Clock size={11} />{formatTime(item.created_at)}</span>
|
| 345 |
+
<span>{(item.use_time || 0).toFixed(1)}s</span>
|
| 346 |
+
<span>{item.credential_email || "-"}</span>
|
| 347 |
+
</div>
|
| 348 |
+
</div>
|
| 349 |
+
<div className="text-right shrink-0 text-xs text-gray-400">
|
| 350 |
+
<div>{formatTokens(item.total_tokens)} tokens</div>
|
| 351 |
+
<div className="text-gray-600">
|
| 352 |
+
↑{formatTokens(item.prompt_tokens)} ↓{formatTokens(item.completion_tokens)}
|
| 353 |
+
</div>
|
| 354 |
+
{item.cached_tokens > 0 && (
|
| 355 |
+
<div className="text-emerald-500/80" title="Prompt 中命中缓存的 token">
|
| 356 |
+
⚡缓存 {formatTokens(item.cached_tokens)}
|
| 357 |
+
</div>
|
| 358 |
+
)}
|
| 359 |
+
</div>
|
| 360 |
+
</div>
|
| 361 |
+
</button>
|
| 362 |
+
))}
|
| 363 |
+
</div>
|
| 364 |
+
)}
|
| 365 |
+
|
| 366 |
+
{/* 分页 */}
|
| 367 |
+
{total > 0 && (
|
| 368 |
+
<div className="flex items-center justify-between text-sm text-gray-400">
|
| 369 |
+
<span>共 {total} 条</span>
|
| 370 |
+
<div className="flex items-center gap-2">
|
| 371 |
+
<button
|
| 372 |
+
onClick={() => setPage((p) => Math.max(1, p - 1))}
|
| 373 |
+
disabled={page <= 1}
|
| 374 |
+
className="btn btn-secondary text-xs px-3 py-1.5 disabled:opacity-40"
|
| 375 |
+
>
|
| 376 |
+
上一页
|
| 377 |
+
</button>
|
| 378 |
+
<span>{page} / {totalPages}</span>
|
| 379 |
+
<button
|
| 380 |
+
onClick={() => setPage((p) => Math.min(totalPages, p + 1))}
|
| 381 |
+
disabled={page >= totalPages}
|
| 382 |
+
className="btn btn-secondary text-xs px-3 py-1.5 disabled:opacity-40"
|
| 383 |
+
>
|
| 384 |
+
下一页
|
| 385 |
+
</button>
|
| 386 |
+
</div>
|
| 387 |
+
</div>
|
| 388 |
+
)}
|
| 389 |
+
|
| 390 |
+
{/* 详情弹窗 */}
|
| 391 |
+
{detail && (
|
| 392 |
+
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60" onClick={() => setDetail(null)}>
|
| 393 |
+
<div className="card max-w-lg w-full max-h-[80vh] overflow-y-auto" onClick={(e) => e.stopPropagation()}>
|
| 394 |
+
<div className="flex items-center justify-between mb-4">
|
| 395 |
+
<h3 className="text-base font-semibold text-purple-400">请求详情</h3>
|
| 396 |
+
<button onClick={() => setDetail(null)} className="text-gray-400 hover:text-white">✕</button>
|
| 397 |
+
</div>
|
| 398 |
+
<div className="space-y-2 text-sm">
|
| 399 |
+
{[
|
| 400 |
+
["时间", formatTime(detail.created_at)],
|
| 401 |
+
["请求 ID", detail.request_id || "-"],
|
| 402 |
+
["状态", detail.success ? "成功" : `失败 (${detail.status_code})`],
|
| 403 |
+
["API 格式", detail.api_format || "-"],
|
| 404 |
+
["客户端 IP", detail.client_ip || "-"],
|
| 405 |
+
["请求模型", detail.model_name || "-"],
|
| 406 |
+
["真实模型", detail.upstream_model_name || detail.model_name || "-"],
|
| 407 |
+
["凭证", detail.credential_email || "-"],
|
| 408 |
+
["流式", detail.is_stream ? "是" : "否"],
|
| 409 |
+
["耗时", `${(detail.use_time || 0).toFixed(2)}s`],
|
| 410 |
+
["Prompt Tokens", String(detail.prompt_tokens)],
|
| 411 |
+
["Completion Tokens", String(detail.completion_tokens)],
|
| 412 |
+
["Total Tokens", String(detail.total_tokens)],
|
| 413 |
+
...(detail.cached_tokens > 0 ? [["缓存 Tokens", String(detail.cached_tokens)]] : []),
|
| 414 |
+
].map(([k, v]) => (
|
| 415 |
+
<div key={k} className="flex justify-between gap-4 border-b border-dark-700 pb-1.5">
|
| 416 |
+
<span className="text-gray-500 shrink-0">{k}</span>
|
| 417 |
+
<span className="text-gray-200 text-right break-all">{v}</span>
|
| 418 |
+
</div>
|
| 419 |
+
))}
|
| 420 |
+
{detail.error_message && (
|
| 421 |
+
<div>
|
| 422 |
+
<div className="text-gray-500 mb-1">错误信息</div>
|
| 423 |
+
<div className="bg-red-500/10 border border-red-500/30 rounded-lg p-2.5 text-xs text-red-300 break-all">
|
| 424 |
+
{detail.error_message}
|
| 425 |
+
</div>
|
| 426 |
+
</div>
|
| 427 |
+
)}
|
| 428 |
+
{detail.request_log_file && (
|
| 429 |
+
<div className="pt-2">
|
| 430 |
+
<div className="flex items-center justify-between gap-2">
|
| 431 |
+
<div className="text-gray-500">请求体详细日志</div>
|
| 432 |
+
<button
|
| 433 |
+
onClick={openRequestBody}
|
| 434 |
+
disabled={detailBodyLoading}
|
| 435 |
+
className="btn btn-secondary text-xs px-3 py-1.5 flex items-center gap-1.5"
|
| 436 |
+
>
|
| 437 |
+
{detailBodyLoading ? <Loader2 size={13} className="animate-spin" /> : <FileText size={13} />}
|
| 438 |
+
查看详细内容
|
| 439 |
+
</button>
|
| 440 |
+
</div>
|
| 441 |
+
<p className="text-xs text-gray-500 mt-1.5">
|
| 442 |
+
命中指定错误码时保存了发往上游的完整请求头与请求体,用于排查请求体错误(如 400)
|
| 443 |
+
</p>
|
| 444 |
+
</div>
|
| 445 |
+
)}
|
| 446 |
+
</div>
|
| 447 |
+
</div>
|
| 448 |
+
</div>
|
| 449 |
+
)}
|
| 450 |
+
|
| 451 |
+
{/* 请求体详细日志弹窗 */}
|
| 452 |
+
{detailBody && (
|
| 453 |
+
<div className="fixed inset-0 z-[60] flex items-center justify-center p-4 bg-black/70" onClick={() => setDetailBody(null)}>
|
| 454 |
+
<div className="card max-w-4xl w-full max-h-[85vh] overflow-y-auto" onClick={(e) => e.stopPropagation()}>
|
| 455 |
+
{detailBody.__missing ? (
|
| 456 |
+
<div className="py-8 text-center text-sm text-gray-400">
|
| 457 |
+
<AlertTriangle size={28} className="mx-auto mb-3 text-amber-400" />
|
| 458 |
+
<div>{detailBody.__message}</div>
|
| 459 |
+
<div className="text-xs text-gray-500 mt-2">磁盘上的详细日志文件可能已被清理或手动删除</div>
|
| 460 |
+
</div>
|
| 461 |
+
) : (
|
| 462 |
+
<>
|
| 463 |
+
<div className="flex items-center justify-between mb-3">
|
| 464 |
+
<h3 className="text-base font-semibold text-purple-400">请求体详细日志</h3>
|
| 465 |
+
<div className="flex items-center gap-2">
|
| 466 |
+
{copyStatus === "ok" && <span className="text-xs text-green-400">已复制</span>}
|
| 467 |
+
{copyStatus === "fail" && <span className="text-xs text-red-400">复制失败</span>}
|
| 468 |
+
<button onClick={copyDetailBody} className="btn btn-secondary text-xs px-3 py-1.5">
|
| 469 |
+
复制 JSON
|
| 470 |
+
</button>
|
| 471 |
+
<button onClick={() => setDetailBody(null)} className="text-gray-400 hover:text-white">✕</button>
|
| 472 |
+
</div>
|
| 473 |
+
</div>
|
| 474 |
+
<p className="text-xs text-gray-500 mb-3">
|
| 475 |
+
命中指定错误码时保存,用于排查请求体错误:完整记录发往上游的请求头(已脱敏)与请求体。响应体为上游返回的原始错误。
|
| 476 |
+
</p>
|
| 477 |
+
<div className="space-y-3 text-xs">
|
| 478 |
+
<div>
|
| 479 |
+
<div className="text-gray-400 mb-1">请求 URL</div>
|
| 480 |
+
<pre className="bg-dark-800 border border-dark-600 rounded-lg p-2.5 overflow-x-auto text-gray-200 whitespace-pre-wrap break-all">{detailBody.url || "-"}</pre>
|
| 481 |
+
</div>
|
| 482 |
+
<div>
|
| 483 |
+
<div className="text-gray-400 mb-1">请求头(已脱敏)</div>
|
| 484 |
+
<pre className="bg-dark-800 border border-dark-600 rounded-lg p-2.5 overflow-x-auto text-gray-200">{JSON.stringify(detailBody.request_headers || {}, null, 2)}</pre>
|
| 485 |
+
</div>
|
| 486 |
+
<div>
|
| 487 |
+
<div className="text-gray-400 mb-1">请求体</div>
|
| 488 |
+
<pre className="bg-dark-800 border border-dark-600 rounded-lg p-2.5 overflow-x-auto text-gray-200">{JSON.stringify(detailBody.request_body ?? {}, null, 2)}</pre>
|
| 489 |
+
</div>
|
| 490 |
+
{detailBody.response_body && (
|
| 491 |
+
<div>
|
| 492 |
+
<div className="text-gray-400 mb-1">上游响应</div>
|
| 493 |
+
<pre className="bg-dark-800 border border-dark-600 rounded-lg p-2.5 overflow-x-auto text-gray-200 whitespace-pre-wrap break-all">{formatMaybeJson(detailBody.response_body)}</pre>
|
| 494 |
+
</div>
|
| 495 |
+
)}
|
| 496 |
+
{detailBody.error_message && (
|
| 497 |
+
<div>
|
| 498 |
+
<div className="text-gray-400 mb-1">错误摘要</div>
|
| 499 |
+
<pre className="bg-red-500/10 border border-red-500/30 rounded-lg p-2.5 overflow-x-auto text-red-300 whitespace-pre-wrap break-all">{detailBody.error_message}</pre>
|
| 500 |
+
</div>
|
| 501 |
+
)}
|
| 502 |
+
</div>
|
| 503 |
+
</>
|
| 504 |
+
)}
|
| 505 |
+
</div>
|
| 506 |
+
</div>
|
| 507 |
+
)}
|
| 508 |
+
</div>
|
| 509 |
+
);
|
| 510 |
+
}
|
agy2api/frontend/tailwind.config.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/** @type {import('tailwindcss').Config} */
|
| 2 |
+
export default {
|
| 3 |
+
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
|
| 4 |
+
darkMode: "class",
|
| 5 |
+
theme: {
|
| 6 |
+
extend: {
|
| 7 |
+
colors: {
|
| 8 |
+
dark: {
|
| 9 |
+
50: "#f8fafc",
|
| 10 |
+
100: "#f1f5f9",
|
| 11 |
+
200: "#e2e8f0",
|
| 12 |
+
300: "#cbd5e1",
|
| 13 |
+
400: "#94a3b8",
|
| 14 |
+
500: "#64748b",
|
| 15 |
+
600: "#475569",
|
| 16 |
+
700: "#334155",
|
| 17 |
+
800: "#1e293b",
|
| 18 |
+
900: "#0f172a",
|
| 19 |
+
950: "#020617",
|
| 20 |
+
},
|
| 21 |
+
},
|
| 22 |
+
},
|
| 23 |
+
},
|
| 24 |
+
plugins: [],
|
| 25 |
+
};
|
agy2api/frontend/vite.config.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import react from "@vitejs/plugin-react";
|
| 2 |
+
import { defineConfig } from "vite";
|
| 3 |
+
|
| 4 |
+
export default defineConfig({
|
| 5 |
+
// 相对基径:构建产物中的 JS/CSS 等资源引用相对于页面地址解析,
|
| 6 |
+
// 支持把面板反向代理到任意子路径(如 /AGY2API/)下访问
|
| 7 |
+
base: "./",
|
| 8 |
+
plugins: [react()],
|
| 9 |
+
server: {
|
| 10 |
+
port: 3000,
|
| 11 |
+
proxy: {
|
| 12 |
+
"/auth": {
|
| 13 |
+
target: "http://localhost:7861",
|
| 14 |
+
changeOrigin: true,
|
| 15 |
+
},
|
| 16 |
+
"/creds": {
|
| 17 |
+
target: "http://localhost:7861",
|
| 18 |
+
changeOrigin: true,
|
| 19 |
+
},
|
| 20 |
+
"/config": {
|
| 21 |
+
target: "http://localhost:7861",
|
| 22 |
+
changeOrigin: true,
|
| 23 |
+
},
|
| 24 |
+
"/usage-logs": {
|
| 25 |
+
target: "http://localhost:7861",
|
| 26 |
+
changeOrigin: true,
|
| 27 |
+
},
|
| 28 |
+
"/logs": {
|
| 29 |
+
target: "http://localhost:7861",
|
| 30 |
+
changeOrigin: true,
|
| 31 |
+
ws: true,
|
| 32 |
+
},
|
| 33 |
+
"/version": {
|
| 34 |
+
target: "http://localhost:7861",
|
| 35 |
+
changeOrigin: true,
|
| 36 |
+
},
|
| 37 |
+
},
|
| 38 |
+
},
|
| 39 |
+
build: {
|
| 40 |
+
outDir: "../dist",
|
| 41 |
+
emptyOutDir: true,
|
| 42 |
+
},
|
| 43 |
+
});
|
agy2api/install.ps1
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 检测是否为管理员
|
| 2 |
+
$IsElevated = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).
|
| 3 |
+
IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
| 4 |
+
|
| 5 |
+
# Skip Scoop install if already present to avoid stopping the script
|
| 6 |
+
if (Get-Command scoop -ErrorAction SilentlyContinue) {
|
| 7 |
+
Write-Host "Scoop is already installed. Skipping installation."
|
| 8 |
+
} else {
|
| 9 |
+
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
|
| 10 |
+
if ($IsElevated) {
|
| 11 |
+
# 管理员:使用官方一行命令并传入 -RunAsAdmin
|
| 12 |
+
Invoke-Expression "& {$(Invoke-RestMethod get.scoop.sh)} -RunAsAdmin"
|
| 13 |
+
} else {
|
| 14 |
+
# 普通用户安装
|
| 15 |
+
Invoke-WebRequest -useb get.scoop.sh | Invoke-Expression
|
| 16 |
+
}
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
scoop install git uv
|
| 20 |
+
if (Test-Path -LiteralPath "./web.py") {
|
| 21 |
+
# Already in target directory; skip clone and cd
|
| 22 |
+
}
|
| 23 |
+
elseif (Test-Path -LiteralPath "./agy2api/web.py") {
|
| 24 |
+
Set-Location ./agy2api
|
| 25 |
+
}
|
| 26 |
+
else {
|
| 27 |
+
git clone https://github.com/su-kaka/agy2api.git
|
| 28 |
+
Set-Location ./agy2api
|
| 29 |
+
}
|
| 30 |
+
# Create relocatable virtual environment to ensure portability
|
| 31 |
+
$env:UV_VENV_CLEAR = "1"
|
| 32 |
+
uv venv --relocatable
|
| 33 |
+
uv sync
|
| 34 |
+
.venv/Scripts/activate.ps1
|
| 35 |
+
python web.py
|