Compare commits

...
4 Commits
Author SHA1 Message Date
ZyyandCodex 8b69fa4882 chore: bump version to 3.54.2
Co-authored-by: Codex <noreply@openai.com>
2026-11-21 20:35:59 +08:00
ZyyandCodex d05d38718e feat(frontend): show CPR wordmark and repository link in the browser console
Co-authored-by: Codex <noreply@openai.com>
2026-11-21 19:23:03 +08:00
Zyy a1954c4746 fix(openai): limit request country overrides to Codex OAuth
Preserve the incoming request country on API key routes. Show quota refresh only for supported accounts and keep peer discovery in the account menu.

Clarify the policy scope in settings and tighten shared help icon spacing.

Refs #758
2026-11-21 18:37:59 +08:00
github-actions[bot] 636a3d2a26 chore(release): update release channels to 3.54.1 2026-11-21 04:18:44 +00:00
21 changed files with 148 additions and 108 deletions
@@ -87,7 +87,7 @@ use crate::transport::protocol::responses::{
};
use crate::transport::request::{
CodexRequestEncodeError, RequestAccountScope, align_structured_location_fields,
encode_generate_payload, scope_request_to_account,
apply_codex_request_country, encode_generate_payload, scope_request_to_account,
};
use crate::transport::session::CodexSessionIdentity;
use crate::transport::usage::normalize_service_tier;
@@ -1090,6 +1090,10 @@ impl CodexProvider {
"after": crate::transport::diagnostics::evidence::request_state(&upstream_request),
}));
}
let location = lease
.account()
.request_location()
.or(context.request_location());
if codex_oauth {
if matches!(
guardian_role,
@@ -1104,16 +1108,13 @@ impl CodexProvider {
&middleware_headers,
context.request_id().as_str(),
);
apply_codex_request_country(
upstream_request.body_mut(),
location,
context.openai_request_country(),
);
}
let location = lease
.account()
.request_location()
.or(context.request_location());
align_structured_location_fields(
upstream_request.body_mut(),
location,
context.openai_request_country(),
);
align_structured_location_fields(upstream_request.body_mut(), location);
let requirement = transport_requirement(&upstream_request);
let http_only = lease.transport() == crate::credential::ResponsesTransport::Http;
if http_only && requirement.requires_websocket() {
@@ -108,11 +108,12 @@ pub fn encode_generate_request(
location: Option<&CodexRequestLocation>,
) -> Result<CodexResponsesRequest, CodexRequestEncodeError> {
let mut encoded = encode_generate_payload(request, upstream_model)?;
align_structured_location_fields(
apply_codex_request_country(
encoded.body_mut(),
location,
&OpenAiRequestCountry::default(),
);
align_structured_location_fields(encoded.body_mut(), location);
Ok(encoded)
}
@@ -135,7 +136,7 @@ pub(crate) fn encode_generate_payload(
Ok(encoded)
}
pub(crate) fn align_structured_location_fields(
pub(crate) fn apply_codex_request_country(
body: &mut Map<String, Value>,
location: Option<&CodexRequestLocation>,
country: &OpenAiRequestCountry,
@@ -155,6 +156,12 @@ pub(crate) fn align_structured_location_fields(
body.insert("request_country".into(), Value::from(country.as_str()));
}
}
}
pub(crate) fn align_structured_location_fields(
body: &mut Map<String, Value>,
location: Option<&CodexRequestLocation>,
) {
let Some(location) = location else { return };
if let Some(input) = body.get_mut("input").and_then(Value::as_array_mut) {
for item in input {
@@ -13463,10 +13463,12 @@ async fn downstream_client_markers_preserve_instruction_content() {
)]);
let sent = capture_client_request(body.clone(), context, api_key).await;
let mut expected = body;
expected.insert(
"request_country".to_owned(),
json!(global_request_location().country),
);
if !api_key {
expected.insert(
"request_country".to_owned(),
json!(global_request_location().country),
);
}
assert_eq!(sent, expected);
}
}
@@ -53,8 +53,7 @@ async fn responses_options_follow_the_selected_upstream_on_both_transports() {
"model": "gpt-5.4", "input": "hello",
"max_output_tokens": 1, "max_completion_tokens": 32, "max_tokens": 64,
"stream_options": {"include_usage": true, "reasoning_summary_delivery": "sequential_cutoff"},
"request_country": "US",
"client_metadata": {"user": "keep", "request_country": "US"},
"client_metadata": {"user": "keep"},
"tools": [{"type": "function", "name": "sample", "parameters": {
"type": "object", "properties": {"top_p": {"type": "number"}}
}}]
@@ -86,102 +85,86 @@ async fn responses_options_follow_the_selected_upstream_on_both_transports() {
);
}
assert_eq!(sent["client_metadata"]["user"], "keep");
assert_eq!(sent.get("request_country"), Some(&Value::Null));
assert_eq!(sent["client_metadata"]["request_country"], "US");
assert_eq!(sent["tools"], body["tools"]);
}
}
}
#[tokio::test]
async fn request_country_modes_only_change_the_top_level_across_transports() {
async fn request_country_follows_the_selected_account_across_transports() {
use OpenAiRequestCountry::{Custom, Default, FollowLocation, Passthrough};
for (api_key, websocket, policy, input, expected) in [
let location = global_request_location();
for (policy, location, input, oauth_country) in [
(FollowLocation {}, None, None, Some(Value::Null)),
(FollowLocation {}, Some(&location), None, Some(json!("NZ"))),
(
false,
false,
Default {},
Some(&location),
Some(json!("CA")),
Some(Value::Null),
),
(true, true, Default {}, None, Some(Value::Null)),
(false, true, Passthrough {}, None, None),
(Passthrough {}, Some(&location), None, None),
(
true,
false,
Passthrough {},
Some(Value::Null),
Some(Value::Null),
),
(
false,
false,
Passthrough {},
Some(&location),
Some(json!("CA")),
Some(json!("CA")),
),
(
true,
true,
FollowLocation {},
Some(json!("CA")),
Some(json!("NZ")),
),
(
true,
false,
Custom {
country: "JP".into(),
},
None,
Some(json!("JP")),
),
(
false,
true,
Custom {
country: "JP".into(),
},
Some(&location),
Some(Value::Null),
Some(json!("JP")),
),
] {
let location = global_request_location();
let mut body = json!({
"model": "gpt-5.4",
"input": "hello",
"client_metadata": {"request_country":"business"},
"tools": [{"type":"web_search"}],
"model": "gpt-5.4", "input": "hello",
"client_metadata": {"request_country": "business"},
"tools": [{"type": "web_search"}],
});
if let Some(input) = input {
body["request_country"] = input;
if let Some(country) = &input {
body["request_country"] = country.clone();
}
for api_key in [false, true] {
let expected = if api_key { &input } else { &oauth_country };
for websocket in [false, true] {
let sent = capture_downstream_with_country(
body.clone(),
api_key,
websocket,
false,
location.cloned(),
policy.clone(),
)
.await;
assert_eq!(
sent.get("request_country"),
expected.as_ref(),
"{policy:?}, api_key={api_key}, websocket={websocket}",
);
assert_eq!(
sent.pointer("/client_metadata/request_country"),
body.pointer("/client_metadata/request_country"),
);
assert_eq!(
sent.pointer("/tools/0/user_location/country")
.and_then(Value::as_str),
location.map(|location| location.country.as_str()),
);
assert_eq!(
sent.pointer("/tools/0/user_location/city")
.and_then(Value::as_str),
location.map(|location| location.city.as_str()),
);
assert_eq!(
sent.pointer("/tools/0/user_location/timezone")
.and_then(Value::as_str),
location.map(|location| location.timezone.name()),
);
}
}
let sent = capture_downstream_with_country(
body,
api_key,
websocket,
false,
Some(location.clone()),
policy,
)
.await;
assert_eq!(sent.get("request_country"), expected.as_ref());
assert_eq!(
sent.pointer("/client_metadata/request_country"),
Some(&json!("business"))
);
assert_eq!(
sent.pointer("/tools/0/user_location/country"),
Some(&json!(location.country))
);
assert_eq!(
sent.pointer("/tools/0/user_location/city"),
Some(&json!(location.city))
);
assert_eq!(
sent.pointer("/tools/0/user_location/timezone"),
Some(&json!(location.timezone.name()))
);
}
}
+2 -2
View File
@@ -418,7 +418,7 @@ PostgreSQL/Redis 启动密码。日常校验使用 `config --quiet`
| 并发与排队 | “系统设置 → 运行设置”;Key 与账号分别设置排队容量和超时,可选择账号排队失败后换号,见[排队规则](../docs/api.md#并发与排队) |
| 账号错误保护 | “系统设置 → 运行设置 → 错误保护”;默认关闭,按[自定义规则](../docs/api.md#账号错误保护)暂停账号调度 |
| 全局请求位置 | “系统设置 → 上游配置 → 请求位置覆盖”,默认关闭 |
| OpenAI 请求国家 | “系统设置 → 上游配置 → 请求国家”,默认跟随位置,也可选择“空值”“透传”或“自定义” |
| Codex OAuth 请求国家 | “系统设置 → 上游配置 → 请求国家”,默认跟随位置,也可选择“空值”“透传”或“自定义” |
| OpenAI OAuth 同步审核模型 | “系统设置 → 上游配置 → 模型映射”中的“专用审核模型”默认开启,关闭后沿用客户端模型。[适用条件](../docs/api.md#正文兼容) |
| 代理位置 | “代理管理”;优先于全局位置,全局关闭时仍可独立生效 |
@@ -438,7 +438,7 @@ PostgreSQL/Redis 启动密码。日常校验使用 `config --quiet`
在下游导入或编辑 OpenAI API Key 账号,填写上游 API 地址和该 Key,后台自动发现 CPR 互联能力。
地址包含自定义前缀时保留完整前缀,后台在该地址下请求 `cpr/link`。
列表与详情显示已保存的观测。展开账号可查看上游密钥限制,普通账号并发留空时跟随上游有效的正数上限。启用的 OpenAI API Key 账号可点击「刷新额度」重新识别。上游明确关闭共享或不支持互联时,账号显示为 API,重新识别成功后显示 CPR
可在账号行的「更多操作」中选择「检测 CPR 互联」手动识别。识别成功后账号显示为 CPR,展开可查看上游密钥限制和刷新额度。普通账号并发留空时跟随上游有效的正数上限。上游明确关闭共享或不支持互联时,账号显示为 API
第三方网关通过插件实现相同协议也可被识别,不按软件名称判定兼容。
上游明确返回 Key 预算耗尽时,下游暂停该账号;后续同步确认允许使用后自动恢复,普通限流冷却独立保留。
+3 -3
View File
@@ -1386,7 +1386,7 @@ Key 消费窗口的 `localUsage` 按各自 `[resetAt - windowSeconds, resetAt)`
- 收到有效快照时显示 CPR 互联。明确返回不支持协议(HTTP 404、405、501),或返回 `403 peer_sharing_disabled` 时,清除互联身份和共享数据,显示普通 API Key
- 普通 401/403 保留原识别结果并清除已撤销的共享内容。超时、限流、服务异常或无效响应保留原识别结果和已有观测。无观测时 `observedAt` 与 `pool` 为 `null`,额度窗口为空
- 展开可探测的 API Key 后,点击「刷新额度」可重新识别互联。卡片显示已有更新时间,手动刷新结果通过通知反馈。明确不支持协议的连接停止周期探测,共享关闭的连接按授权退避周期复查
- 可探测但尚未识别为互联的 API Key,可在账号行的「更多操作」中选择「检测 CPR 互联」。识别成功后可在额度卡点击「刷新额度」。明确不支持协议的连接停止周期探测,共享关闭的连接按授权退避周期复查
账号地址、密钥或出口变更使旧观测与识别身份失效,重新识别当前连接。
账号停用后停止同步,重新启用后按当前连接的识别结果恢复后台任务
@@ -1508,7 +1508,7 @@ API 的 `autoLocation` 默认为 `false`;开启时使用已检测位置,测
只改位置不清空连通性测试结果,也不更改账号凭据版本
关联账号的 OpenAI/Codex Responses 请求(HTTP/SSE、WebSocket)优先使用代理位置,否则使用全局
运行设置中已开启的 `requestLocation`。出站正文的顶层 `request_country` 默认跟随位置,也可在[请求位置](#请求位置)选择“空值”“透传”或“自定义”。
运行设置中已开启的 `requestLocation`。Codex OAuth 请求的顶层国家字段由[请求国家策略](#请求位置)控制。
位置覆盖同时更新客户端时间上下文的时区和 Web Search 的结构化位置,未启用覆盖时这两项保留客户端原值。
全局覆盖按请求冻结,保存后对新请求生效。代理覆盖按每次执行选定的账号解析,包括换号和换出口。
位置覆盖不改变 epoch 时间戳、真实出口 IP、服务或管理端时区、数据驻留约束及 xAI 请求
@@ -2272,7 +2272,7 @@ HTTP 返回 `429`,`error.code` 为 `key_daily_budget_exceeded` 或 `key_weekly
关联代理配置了自定义位置时优先使用代理值。保存后通过现有配置发布机制对新请求生效,
已开始请求及其重试保持同一份全局值;普通文本、绝对时间戳和数据驻留要求不受影响
`openaiRequestCountry` 单独控制 OpenAI Responses 出站正文顶层的 `request_country`。保存后对新请求生效。
`openaiRequestCountry` 仅控制发往 Codex OAuth 上游的 Responses 请求顶层字段 `request_country`。API Key 上游保留客户端原值,包括显式 `null`,客户端省略时也省略。保存后对新请求生效
| 管理端选项 | 设置值 | 发往上游的字段 |
| --- | --- | --- |
+27
View File
@@ -0,0 +1,27 @@
import type { Plugin } from 'vite'
const banner = `
██████╗ ██████╗ ██████╗
██╔════╝ ██╔══██╗ ██╔══██╗
██║ ██████╔╝ ██████╔╝
██║ ██╔═══╝ ██╔═██╗
╚██████╗ ██║ ██║ ██╗
╚═════╝ ╚═╝ ╚═╝ ╚═╝
https://github.com/zyycn/codex-proxy-rs`
export function consoleBanner(): Plugin {
return {
name: 'cpr-console-banner',
transformIndexHtml: {
order: 'pre',
handler: () => [
{
tag: 'script',
attrs: { type: 'module' },
children: `console.info(${JSON.stringify(banner)})`,
},
],
},
}
}
+1 -1
View File
@@ -9,7 +9,7 @@ const canHover = useMediaQuery('(hover: hover)')
</script>
<template>
<ZPopover class="h-4 items-center" :trigger="canHover ? 'hover-click' : 'click'" placement="top-start" :hover-delay="240">
<ZPopover class="-ms-1.5 h-4 items-center" :trigger="canHover ? 'hover-click' : 'click'" placement="top-start" :hover-delay="240">
<template #reference="{ open }">
<ZIconButton variant="link" size="small" :aria-label="label" :aria-expanded="open" aria-haspopup="dialog">
<CircleAlert class="size-3.5" aria-hidden="true" />
@@ -283,6 +283,7 @@
"actions": {
"deleteAccount": "Delete account",
"moreActions": "More actions",
"discoverPeer": "Detect CPR Link",
"disableScheduling": "Disable",
"enableScheduling": "Enable",
"refreshToken": "Refresh token",
@@ -316,6 +316,7 @@
"location": {
"requestCountry": "Request country",
"requestCountryDescription": "Choose how Codex requests send the country code",
"requestCountryScope": "Applies only to Codex OAuth accounts",
"countryHelp": "Request country mode help",
"countryMode": "Policy",
"countryModes": {
@@ -283,6 +283,7 @@
"actions": {
"deleteAccount": "删除账号",
"moreActions": "更多操作",
"discoverPeer": "检测 CPR 互联",
"disableScheduling": "停用",
"enableScheduling": "启用",
"refreshToken": "刷新令牌",
@@ -316,6 +316,7 @@
"location": {
"requestCountry": "请求国家",
"requestCountryDescription": "设置 Codex 请求如何发送国家代码",
"requestCountryScope": "仅用于 Codex OAuth 账号",
"countryHelp": "请求国家模式说明",
"countryMode": "策略",
"countryModes": {
@@ -283,6 +283,7 @@
"actions": {
"deleteAccount": "刪除賬號",
"moreActions": "更多操作",
"discoverPeer": "偵測 CPR 互聯",
"disableScheduling": "停用",
"enableScheduling": "啓用",
"refreshToken": "刷新令牌",
@@ -316,6 +316,7 @@
"location": {
"requestCountry": "請求國家",
"requestCountryDescription": "設定 Codex 請求如何傳送國家代碼",
"requestCountryScope": "僅用於 Codex OAuth 帳號",
"countryHelp": "請求國家模式說明",
"countryMode": "策略",
"countryModes": {
@@ -3,7 +3,7 @@ import type { Account } from '@/api'
import { ZIconButton, ZMenuItem } from '@codex-proxy/ui'
import { Download, KeyRound, Pencil, Power, RefreshCw, RotateCcw, Trash2, Wifi } from '@lucide/vue'
import { Download, KeyRound, Link2, Pencil, Power, RefreshCw, RotateCcw, Trash2, Wifi } from '@lucide/vue'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
@@ -15,6 +15,7 @@ const props = defineProps<{
downloadingCatalog: boolean
recovering: boolean
refreshing: boolean
refreshingQuota: boolean
testing: boolean
togglingScheduling: boolean
}>()
@@ -25,6 +26,7 @@ const emit = defineEmits<{
recover: [accountId: string]
test: [account: Account]
refresh: [accountId: string]
discoverPeer: [accountId: string]
reauthorize: [account: Account]
downloadModelCatalog: [account: Account]
toggleScheduling: [account: Account]
@@ -65,6 +67,17 @@ const credentialEligible = computed(() => props.account.authenticationKind === '
</template>
{{ t('accounts.connectionTest.title') }}
</ZMenuItem>
<ZMenuItem
v-if="account.upstream && !account.upstream.discovered"
:loading="refreshingQuota"
:disabled="refreshingQuota"
@click.stop="emit('discoverPeer', account.id)"
>
<template #icon>
<Link2 class="size-3.5 text-z-text-quaternary" />
</template>
{{ t('accounts.actions.discoverPeer') }}
</ZMenuItem>
<ZMenuItem
:loading="togglingScheduling"
:disabled="togglingScheduling"
@@ -47,7 +47,7 @@ const forecastOpen = shallowRef(false)
const hasPlanBadge = computed(() => Boolean(props.account.planType) || props.account.authenticationKind === 'api_key')
const hasForecast = computed(() => props.account.authenticationKind !== 'api_key')
const hasPersonalInfo = computed(() => props.account.capabilities.profile || props.account.capabilities.subscription)
const canRefresh = computed(() => props.account.capabilities.quotaRefresh || props.account.upstream != null)
const canRefresh = computed(() => props.account.capabilities.quotaRefresh || props.account.upstream?.discovered)
const hasActions = computed(() => hasPersonalInfo.value || hasForecast.value || canRefresh.value || props.account.capabilities.resetCredits)
const lastRefreshed = computed(() => {
const { upstream, quota } = props.account
+2
View File
@@ -353,11 +353,13 @@ const {
:downloading-catalog="downloadingCatalogAccountIds.has(row.id)"
:recovering="recoveringAccountIds.has(row.id)"
:refreshing="refreshingAccountIds.has(row.id)"
:refreshing-quota="refreshingQuotaAccountIds.has(row.id)"
:testing="testingAccountId === row.id"
:toggling-scheduling="togglingSchedulingAccountIds.has(row.id)"
@edit="openAccountEdit"
@delete="requestDeleteAccount"
@download-model-catalog="handleDownloadModelCatalog"
@discover-peer="handleRefreshQuota"
@recover="handleRecover"
@refresh="handleRefresh"
@reauthorize="openReauthorizeAccount"
@@ -49,6 +49,9 @@ function setMode(mode: OpenAiRequestCountry['mode'] | undefined) {
<span class="inline-flex items-center gap-1.5">
{{ t('settings.location.requestCountry') }}
<HelpPopover :label="t('settings.location.countryHelp')">
<p class="mb-2 font-emphasis text-z-text">
{{ t('settings.location.requestCountryScope') }}
</p>
<dl class="grid grid-cols-[auto_1fr] gap-x-3 gap-y-2">
<template v-for="mode in modes" :key="mode.value">
<dt class="font-emphasis text-z-text">
+2
View File
@@ -4,6 +4,7 @@ import VueI18n from '@intlify/unplugin-vue-i18n/vite'
import tailwindcss from '@tailwindcss/vite'
import vue from '@vitejs/plugin-vue'
import { defineConfig, loadEnv } from 'vite'
import { consoleBanner } from './build/console-banner.ts'
import { pluginBridge } from './build/plugin-bridge.ts'
export default defineConfig(({ mode }) => {
@@ -23,6 +24,7 @@ export default defineConfig(({ mode }) => {
source: sourceUi ? uiRoot : undefined,
}),
pluginBridge(),
consoleBanner(),
],
resolve: {
alias: {
+3 -9
View File
@@ -1,15 +1,9 @@
# v3.54.1
# v3.54.2
## 问题修复
- 修复 Safari 等 WebKit 浏览器中固定表头遮挡数据行的问题
- 统一用量记录的时间列,管理端和密钥用量页都分行显示时间和日期
- 「请求国家」策略仅对 Codex OAuth 账号生效,OpenAI API Key 请求保留客户端的 `request_country` 原值,省略时也保持省略
## 优化改进
- 创建或编辑账号分组时,可像编辑账号一样搜索、手动添加模型,并在白名单中一键添加常用图片模型
- 「请求国家」现位于「系统设置 → 上游配置」,可独立于「请求位置覆盖」选择策略
## 升级须知
- Docker Compose 部署使用的 PostgreSQL 镜像更新至 18.7,Redis 镜像更新至 8.10.3
- 尚未识别为 CPR 互联的 OpenAI API Key 账号可在「更多操作」中选择「检测 CPR 互联」,识别成功后可在额度卡片中刷新额度
+5 -5
View File
@@ -1,7 +1,7 @@
version: 3.54.1
version: 3.54.2
published:
'3':
stable: 3.54.0
rc: 3.54.0
beta: 3.54.0
alpha: 3.54.0
stable: 3.54.1
rc: 3.54.1
beta: 3.54.1
alpha: 3.54.1