Skip to content

Commit fd8d1b2

Browse files
committed
feat(core): embed proxy and model policy features
1 parent a4a52a9 commit fd8d1b2

62 files changed

Lines changed: 2042 additions & 1989 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/dependabot.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,3 @@ updates:
1212
directory: /cliproxyapi-pro-core
1313
schedule:
1414
interval: weekly
15-
- package-ecosystem: gomod
16-
directory: /cliproxyapi-pro-plugins/proxy-pool
17-
schedule:
18-
interval: weekly
19-
- package-ecosystem: gomod
20-
directory: /cliproxyapi-pro-plugins/oauth-model-policy
21-
schedule:
22-
interval: weekly

.github/workflows/release-core.yml

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,7 @@ jobs:
270270
rm -rf "${context_dir}"
271271
mkdir -p \
272272
"${context_dir}/binaries/linux/amd64" \
273-
"${context_dir}/binaries/linux/arm64" \
274-
"${context_dir}/plugins/linux/amd64" \
275-
"${context_dir}/plugins/linux/arm64"
273+
"${context_dir}/binaries/linux/arm64"
276274
277275
amd64_archive="docker-assets/linux-amd64/CLIProxyAPI_${RELEASE_TAG#v}_linux_amd64.tar.gz"
278276
arm64_archive="docker-assets/linux-arm64/CLIProxyAPI_${RELEASE_TAG#v}_linux_aarch64.tar.gz"
@@ -288,10 +286,6 @@ jobs:
288286
289287
cp "${tmp_dir}/amd64/cli-proxy-api" "${context_dir}/binaries/linux/amd64/CLIProxyAPI"
290288
cp "${tmp_dir}/arm64/cli-proxy-api" "${context_dir}/binaries/linux/arm64/CLIProxyAPI"
291-
cp "${tmp_dir}/amd64/plugins/linux/amd64/proxy-pool.so" "${context_dir}/plugins/linux/amd64/proxy-pool.so"
292-
cp "${tmp_dir}/arm64/plugins/linux/arm64/proxy-pool.so" "${context_dir}/plugins/linux/arm64/proxy-pool.so"
293-
cp "${tmp_dir}/amd64/plugins/linux/amd64/oauth-model-policy.so" "${context_dir}/plugins/linux/amd64/oauth-model-policy.so"
294-
cp "${tmp_dir}/arm64/plugins/linux/arm64/oauth-model-policy.so" "${context_dir}/plugins/linux/arm64/oauth-model-policy.so"
295289
cp "${tmp_dir}/amd64/config.example.yaml" "${context_dir}/config.example.yaml"
296290
cp docker-assets/management/management.html "${context_dir}/management.html"
297291
cp customizations-repo/cliproxyapi-pro-core/entrypoint.sh "${context_dir}/entrypoint.sh"
@@ -303,10 +297,6 @@ jobs:
303297
ls -lh \
304298
"${context_dir}/binaries/linux/amd64/CLIProxyAPI" \
305299
"${context_dir}/binaries/linux/arm64/CLIProxyAPI" \
306-
"${context_dir}/plugins/linux/amd64/proxy-pool.so" \
307-
"${context_dir}/plugins/linux/arm64/proxy-pool.so" \
308-
"${context_dir}/plugins/linux/amd64/oauth-model-policy.so" \
309-
"${context_dir}/plugins/linux/arm64/oauth-model-policy.so" \
310300
"${context_dir}/management.html"
311301
312302
- name: Set up QEMU
@@ -534,30 +524,13 @@ jobs:
534524
-ldflags="-s -w -X main.Version=${RELEASE_TAG} -X main.Commit=release-${CORE_TAG} -X main.BuildDate=${BUILD_DATE}" \
535525
-o "${archive_dir}/${binary_name}" ./cmd/server/
536526
537-
plugin_extension="so"
538-
if [ "${GOOS}" = "darwin" ]; then plugin_extension="dylib"; fi
539-
if [ "${GOOS}" = "windows" ]; then plugin_extension="dll"; fi
540-
mkdir -p "${archive_dir}/plugins/${GOOS}/${GOARCH}"
541-
plugin_relatives=()
542-
for plugin_name in proxy-pool oauth-model-policy; do
543-
plugin_relative="plugins/${GOOS}/${GOARCH}/${plugin_name}.${plugin_extension}"
544-
plugin_source=".${plugin_name}-build"
545-
rm -rf "${plugin_source}"
546-
cp -R "../customizations-repo/cliproxyapi-pro-plugins/${plugin_name}" "${plugin_source}"
547-
go -C "${plugin_source}" mod edit -replace github.com/router-for-me/CLIProxyAPI/v7=..
548-
CGO_ENABLED=1 GOOS="${GOOS}" GOARCH="${GOARCH}" go -C "${plugin_source}" build \
549-
-buildvcs=false -trimpath -buildmode=c-shared \
550-
-o "${PWD}/${archive_dir}/${plugin_relative}" .
551-
plugin_relatives+=("${plugin_relative}")
552-
done
553-
554527
cp LICENSE README.md README_EN.md config.example.yaml "${archive_dir}/"
555528
python ../customizations-repo/scripts/build/create_reproducible_archive.py \
556529
--format "${ARCHIVE_FORMAT}" \
557530
--output "dist/${archive_name}" \
558531
--root "${archive_dir}" \
559532
--source-date-epoch "${SOURCE_DATE_EPOCH}" \
560-
"${binary_name}" LICENSE README.md README_EN.md config.example.yaml "${plugin_relatives[@]}"
533+
"${binary_name}" LICENSE README.md README_EN.md config.example.yaml
561534
562535
- name: Build Linux glibc plugin-capable archive
563536
if: matrix.kind == 'linux-glibc-plugin'
@@ -577,10 +550,6 @@ jobs:
577550
archive_name="CLIProxyAPI_${RELEASE_TAG#v}_linux_${ASSET_ARCH}.tar.gz"
578551
rm -rf "dist/linux-${GOARCH}"
579552
mkdir -p "${archive_dir}"
580-
for plugin_name in proxy-pool oauth-model-policy; do
581-
rm -rf ".${plugin_name}-build"
582-
cp -R "../customizations-repo/cliproxyapi-pro-plugins/${plugin_name}" ".${plugin_name}-build"
583-
done
584553
585554
go_archive="go${GO_VERSION}.linux-${GOARCH}.tar.gz"
586555
go_sha256="$(
@@ -614,14 +583,6 @@ jobs:
614583
-ldflags="-s -w -X main.Version=${RELEASE_TAG} -X main.Commit=release-${CORE_TAG} -X main.BuildDate=${BUILD_DATE}" \
615584
-o "'"${archive_dir}"'/cli-proxy-api" ./cmd/server/
616585
617-
mkdir -p "'"${archive_dir}"'/plugins/linux/${GOARCH}"
618-
for plugin_name in proxy-pool oauth-model-policy; do
619-
go -C ".${plugin_name}-build" mod edit -replace github.com/router-for-me/CLIProxyAPI/v7=/src
620-
CGO_ENABLED=1 GOOS=linux GOARCH="${GOARCH}" go -C ".${plugin_name}-build" build \
621-
-buildvcs=false -trimpath -buildmode=c-shared \
622-
-o "/src/'"${archive_dir}"'/plugins/linux/${GOARCH}/${plugin_name}.so" .
623-
done
624-
625586
glibc_versions="$(readelf --version-info "'"${archive_dir}"'/cli-proxy-api" | sed -n "s/.*Name: GLIBC_\([0-9.]*\).*/\1/p" | sort -Vu)"
626587
if [ -n "${glibc_versions}" ]; then
627588
printf "GLIBC versions:\n%s\n" "${glibc_versions}"
@@ -639,9 +600,7 @@ jobs:
639600
--output "dist/${archive_name}" \
640601
--root "${archive_dir}" \
641602
--source-date-epoch "${SOURCE_DATE_EPOCH}" \
642-
cli-proxy-api LICENSE README.md README_EN.md config.example.yaml \
643-
"plugins/linux/${GOARCH}/proxy-pool.so" \
644-
"plugins/linux/${GOARCH}/oauth-model-policy.so"
603+
cli-proxy-api LICENSE README.md README_EN.md config.example.yaml
645604
646605
- name: Install FreeBSD plugin build dependencies
647606
if: matrix.kind == 'freebsd-plugin'

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ CLIProxyAPI Pro 是对两个 upstream 项目的最小化定制层集合:
1515
- 账号巡检支持自动化启用、禁用、删除、主动刷新令牌
1616
- 账号巡检针对 Antigravity 软封禁和 xAI 可用性异常提供可选深度检测
1717
- 路由策略页面统一管理 upstream 路由行为与按 provider 配置的请求状态保护
18-
- 内置动态代理池插件,把多个 HTTP/SOCKS 节点汇聚为固定的本地 SOCKS5 地址,支持轮询、加权、健康隔离与故障转移
19-
- 内置 OAuth 模型策略插件,可按多个提供商的账号套餐分别排除不可用模型,并同步约束模型列表和账号调度
18+
- 二进制内建代理池,把多个 HTTP/SOCKS 节点汇聚为固定的本地 SOCKS5 地址,支持轮询、加权、健康隔离与故障转移
19+
- 二进制内建 OAuth 模型策略,可按多个提供商的账号套餐分别排除不可用模型,并同步约束模型列表和账号调度
2020

2121
## 项目结构
2222

@@ -36,10 +36,6 @@ CLIProxyAPI Pro 是对两个 upstream 项目的最小化定制层集合:
3636
│ ├── monitoring-locales.json
3737
│ └── overlay/
3838
39-
├── cliproxyapi-pro-plugins/
40-
│ ├── proxy-pool/
41-
│ └── oauth-model-policy/
42-
4339
├── scripts/validation/
4440
└── .github/workflows/
4541
├── ci.yml
@@ -64,12 +60,12 @@ CLIProxyAPI Pro 是对两个 upstream 项目的最小化定制层集合:
6460
- 支持 SQLite-backed quota cache。
6561
- 支持模型价格持久化。
6662
- 支持 QuotaProvider 插件协议和 Gemini CLI legacy adapter。
67-
- 支持通用 `AuthModelFilter` 插件协议;预打包的 `oauth-model-policy` 可按 xAI、Codex、Claude、Gemini CLI、Antigravity 和 Kimi OAuth 套餐排除模型。
63+
- 内建 OAuth 模型策略,可按 xAI、Codex、Claude、Gemini CLI、Antigravity 和 Kimi OAuth 套餐排除模型。
6864
- 启动时在内存中强制必要 upstream 配置;仅修改 YAML 中已存在的键,禁止自动新增键。
6965
- 支持后端账号巡检调度器和执行器,巡检探测前可刷新 token。
7066
- 支持统一路由策略与请求状态保护 API。
7167
- 支持 Komari agent 可选启动。
72-
- 标准 macOS、Windows amd64、Linux Release 和 Docker 镜像预打包 `proxy-pool``oauth-model-policy` 动态插件;Windows ARM64、FreeBSD 与 `_no-plugin` 产物暂不内置动态插件
68+
- 代理池与 OAuth 模型策略直接编译进所有 Pro 二进制,包括 `_no-plugin` 产物;其配置持久化在 usage SQLite,不写入 `config.yaml`
7369
-`/` 跳转到 `/management.html`
7470
- 增强 `/healthz` 返回信息。
7571

README_EN.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ This project does not maintain a full fork of either upstream project. Instead,
1515
- Optional automatic enable, disable, delete, and token-refresh actions.
1616
- Optional deep probes for Antigravity soft bans and xAI availability anomalies.
1717
- A routing-policy page for upstream routing behavior and provider-scoped request-state protection.
18-
- A bundled dynamic proxy-pool plugin that aggregates HTTP/SOCKS nodes behind one fixed loopback SOCKS5 endpoint with rotation, health isolation, and failover.
19-
- A bundled OAuth model-policy plugin that removes unavailable models per provider and account plan, constraining both model listing and auth scheduling.
18+
- A statically linked proxy pool that aggregates HTTP/SOCKS nodes behind one fixed loopback SOCKS5 endpoint with rotation, health isolation, and failover.
19+
- A statically linked OAuth model policy that removes unavailable models per provider and account plan, constraining both model listing and auth scheduling.
2020

2121
## Repository layout
2222

@@ -36,10 +36,6 @@ This project does not maintain a full fork of either upstream project. Instead,
3636
│ ├── monitoring-locales.json
3737
│ └── overlay/
3838
39-
├── cliproxyapi-pro-plugins/
40-
│ ├── proxy-pool/
41-
│ └── oauth-model-policy/
42-
4339
├── scripts/validation/
4440
└── .github/workflows/
4541
├── ci.yml
@@ -64,12 +60,12 @@ Main capabilities:
6460
- Supports SQLite-backed quota cache.
6561
- Supports model price persistence.
6662
- Supports the QuotaProvider plugin protocol and a Gemini CLI legacy adapter.
67-
- Supports a generic `AuthModelFilter` plugin protocol; the bundled `oauth-model-policy` filters OAuth models by account plan for xAI, Codex, Claude, Gemini CLI, Antigravity, and Kimi.
63+
- Includes an OAuth model policy for xAI, Codex, Claude, Gemini CLI, Antigravity, and Kimi account plans.
6864
- Forces required upstream startup config: `usage-statistics-enabled=true` and the Pro management panel repository.
6965
- Adds a backend account-inspection scheduler and executor with token refresh before probing.
7066
- Adds unified routing-policy and request-state-protection APIs.
7167
- Optionally starts the Komari agent.
72-
- Prebundles the `proxy-pool` and `oauth-model-policy` dynamic libraries in standard macOS, Windows amd64, and Linux releases plus Docker images; Windows ARM64, FreeBSD, and `_no-plugin` assets do not currently bundle dynamic plugins.
68+
- Links the proxy pool and OAuth model policy into every Pro binary, including `_no-plugin` assets; their settings live in the usage SQLite database and are never written to `config.yaml`.
7369
- Redirects `/` to `/management.html`.
7470
- Enhances the `/healthz` response.
7571

cliproxyapi-pro-core/Dockerfile

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,9 @@ RUN set -eux; \
4545

4646
COPY cliproxyapi-pro-core/embeddedusage /tmp/embeddedusage
4747
COPY cliproxyapi-pro-core/patches /tmp/patches
48-
COPY cliproxyapi-pro-plugins/proxy-pool /tmp/proxy-pool
49-
COPY cliproxyapi-pro-plugins/oauth-model-policy /tmp/oauth-model-policy
5048

5149
RUN python3 /tmp/patches/apply_upstream_patches.py
5250

53-
RUN set -eux; \
54-
cd /tmp/proxy-pool; \
55-
go mod edit -replace github.com/router-for-me/CLIProxyAPI/v7=/src/CLIProxyAPI; \
56-
go mod tidy; \
57-
CGO_ENABLED=1 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64} \
58-
go build -buildvcs=false -trimpath -buildmode=c-shared -o /out/proxy-pool.so .
59-
60-
RUN set -eux; \
61-
cd /tmp/oauth-model-policy; \
62-
go mod edit -replace github.com/router-for-me/CLIProxyAPI/v7=/src/CLIProxyAPI; \
63-
go mod tidy; \
64-
CGO_ENABLED=1 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64} \
65-
go build -buildvcs=false -trimpath -buildmode=c-shared -o /out/oauth-model-policy.so .
66-
6751
RUN set -eux; \
6852
go mod tidy; \
6953
CLIPROXY_SOURCE_VERSION="$(cat /tmp/cliproxy-version)"; \
@@ -93,8 +77,6 @@ RUN set -eux; \
9377
WORKDIR /CLIProxyAPI
9478

9579
COPY --from=builder /out/CLIProxyAPI /CLIProxyAPI/CLIProxyAPI
96-
COPY --from=builder /out/proxy-pool.so /CLIProxyAPI/plugins/linux/${TARGETARCH}/proxy-pool.so
97-
COPY --from=builder /out/oauth-model-policy.so /CLIProxyAPI/plugins/linux/${TARGETARCH}/oauth-model-policy.so
9880
COPY --from=builder /src/CLIProxyAPI/config.example.yaml /CLIProxyAPI/config.example.yaml
9981
COPY --from=builder /tmp/pro-management.html /CLIProxyAPI/static/management.html
10082
COPY cliproxyapi-pro-core/entrypoint.sh /CLIProxyAPI/entrypoint.sh

cliproxyapi-pro-core/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
本目录不维护 upstream 的完整 fork。Docker 构建时会下载指定 upstream release,复制本地 `embeddedusage/` 包,执行 `patches/` 中的补丁脚本,然后构建 Pro 部署使用的多架构镜像。
66

7-
标准 macOS、Windows amd64、Linux Pro Release 与 Docker 镜像会预打包 `proxy-pool``oauth-model-policy` 动态插件。前者在回环地址提供固定 SOCKS5 入口;后者按多个提供商的 OAuth 套餐排除账号不可用的模型。Windows ARM64、FreeBSD 与 `_no-plugin` 资产暂不内置动态插件
7+
代理池和 OAuth 模型策略直接编译到 Core 二进制中,所有 Pro 构建(包括 `_no-plugin`)都具备这两项能力。配置保存在 usage SQLite 的 `pro_settings`,不会写入 `config.yaml`
88

99
## 定制内容
1010

@@ -81,7 +81,7 @@ detail 还会保留 upstream `ClientRequestMetadata` 提供的 `client_ip`、`x_
8181
- `model_prices` — 基础价格兼容数据和完整的全局 model 价格规则。
8282
- `quota_cache` — 配额卡片和账号级刷新使用的 SQLite-backed quota snapshots。
8383
- `monitoring_settings` — 监控日志保留时间、WebDAV 备份配置和 models.dev 定期同步配置。
84-
- `pro_settings` — Pro 私有设置;当前包含请求状态保护策略
84+
- `pro_settings` — Pro 私有设置;当前包含请求状态保护、代理池和 OAuth 模型策略
8585
- `routing_cursor_state` — 账号路由轮转游标。
8686
- `auth_runtime_stats` — 账号选择、成功/失败和近期请求桶统计。
8787
- `account_inspection_schedule` — 后端账号巡检调度设置。
@@ -137,11 +137,11 @@ detail 还会保留 upstream `ClientRequestMetadata` 提供的 `client_ip`、`x_
137137
`Executor.HttpRequest` 提供兼容适配;插件未来原生实现协议后会自动优先使用原生能力。
138138
协议字段与兼容策略见 [QUOTA_PROVIDER.md](QUOTA_PROVIDER.md)
139139

140-
### OAuth 套餐模型策略插件
140+
### 内建代理池与 OAuth 套餐模型策略
141141

142-
补丁层为 upstream 插件 SDK/ABI 增加通用 `AuthModelFilter` 能力。Core 只提供当前 auth、原始模型集合和受控 HTTP callback,并强制插件只能减去已有模型;套餐识别与规则均位于预打包的 `oauth-model-policy` 插件中
142+
Core 内建回环 SOCKS5 代理池以及 xAI、Codex、Claude、Gemini CLI、Antigravity、Kimi 的 OAuth 套餐模型策略。代理接管只在运行时替换全局传输路径,不改写 `config.yaml`,凭证级代理和显式 `direct` 不受影响。模型处理顺序为 upstream `excluded_models`、内建套餐过滤、OAuth alias/prefix、模型注册,最终结果同时约束 `/v1/models` 聚合和请求调度候选账号
143143

144-
插件支持 xAI、Codex、Claude、Gemini CLI、Antigravity 和 Kimi OAuth,并为所有提供商提供 `_unknown``_default` 与自定义套餐规则。处理顺序为 upstream `excluded_models`、插件套餐过滤、OAuth alias/prefix、模型注册。最终注册结果同时约束 `/v1/models` 聚合和请求调度候选账号。配置与探测细节见 `cliproxyapi-pro-plugins/oauth-model-policy/README.md`
144+
首次启动会读取旧 `plugins.configs.proxy-pool``plugins.configs.oauth-model-policy`,校验并写入 SQLite,回读确认成功后再原子清除旧 YAML。旧代理接管若处于启用状态,会先把根 `proxy-url` 恢复为旧 `restore-proxy-url`;其他第三方插件配置保持不变
145145

146146
### 后端账号巡检调度器
147147

@@ -237,7 +237,7 @@ https://github.com/ssfun/CLIProxyAPI-Pro
237237
- `Dockerfile` — 下载 upstream CLIProxyAPI,应用定制层,并构建最终镜像。
238238
- `Dockerfile.runtime` — GitHub Actions 使用预构建 Linux 二进制组装运行时镜像。
239239
- `QUOTA_PROVIDER.md` — QuotaProvider 插件协议和兼容策略。
240-
- `../cliproxyapi-pro-plugins/oauth-model-policy/`按 OAuth 套餐过滤账号模型的动态插件
240+
- `patches/sources/internal/profeatures/`内建代理池、模型策略的 SQLite 迁移与运行时编排
241241
- `entrypoint.sh` — 启动 Komari、主 API 和 WebDAV usage 恢复逻辑。
242242
- `embeddedusage/` — 内嵌 SQLite usage service 和 management routes。
243243
- `patches/apply_upstream_patches.py` — Docker build 阶段 patch upstream 源码。

0 commit comments

Comments
 (0)