mirror of
https://github.com/zyycn/codex-proxy-rs.git
synced 2026-12-04 08:00:59 +00:00
fix(antigravity): mark account unverified on upstream VALIDATION_REQUIRED
This commit is contained in:
@@ -19,7 +19,10 @@ impl AntigravityProvider {
|
||||
error: ProviderError,
|
||||
) -> ProviderError {
|
||||
if error.send_state() != UpstreamSendState::Sent
|
||||
|| !matches!(error.kind(), Kind::Unauthorized | Kind::RateLimited)
|
||||
|| !matches!(
|
||||
error.kind(),
|
||||
Kind::Unauthorized | Kind::RateLimited | Kind::PermissionDenied
|
||||
)
|
||||
{
|
||||
return error;
|
||||
}
|
||||
@@ -30,6 +33,26 @@ impl AntigravityProvider {
|
||||
}
|
||||
let feedback = async {
|
||||
match error.kind() {
|
||||
Kind::PermissionDenied => {
|
||||
// 只有 Google 明确要求账号级人工验证才改账号状态;
|
||||
// 其他 PermissionDenied 可能只是模型或项目级限制
|
||||
if !crate::transport::is_validation_required(&error) {
|
||||
return Ok(());
|
||||
}
|
||||
self.accounts
|
||||
.apply_state_change(gateway_core::account::AccountStateChange {
|
||||
account_id: account.id().clone(),
|
||||
expected_revision: account.revision(),
|
||||
credential_state: gateway_core::account::CredentialState::Invalid,
|
||||
observed_at: SystemTime::now(),
|
||||
error_reason: Some(
|
||||
gateway_core::account::AccountErrorReason::AccountUnverified,
|
||||
),
|
||||
message: Some("上游要求完成账号验证(VALIDATION_REQUIRED)".into()),
|
||||
})
|
||||
.await
|
||||
.map_err(|_| ())?;
|
||||
}
|
||||
Kind::Unauthorized => {
|
||||
if account.authentication_kind() == crate::credential::api_key::API_KEY {
|
||||
self.accounts
|
||||
|
||||
@@ -131,6 +131,26 @@ fn google_error_detail<'a>(error: &'a Value, kind: &str) -> Option<&'a Value> {
|
||||
.find(|detail| detail["@type"] == kind)
|
||||
}
|
||||
|
||||
/// Google 明确要求账号级人工验证;这是账号事实,不是单模型限制
|
||||
pub(crate) fn is_validation_required(error: &ProviderError) -> bool {
|
||||
let Some(raw) = error.raw_upstream_error() else {
|
||||
return false;
|
||||
};
|
||||
let Ok(document) = serde_json::from_str::<Value>(raw.as_str()) else {
|
||||
return false;
|
||||
};
|
||||
let Some(failure) = google_error(&document) else {
|
||||
return false;
|
||||
};
|
||||
let Some(detail) = google_error_detail(
|
||||
failure,
|
||||
"type.googleapis.com/google.rpc.ErrorInfo",
|
||||
) else {
|
||||
return false;
|
||||
};
|
||||
detail.get("reason").and_then(|reason| reason.as_str()) == Some("VALIDATION_REQUIRED")
|
||||
}
|
||||
|
||||
fn retry_info(body: &str) -> Option<Duration> {
|
||||
let document: Value = serde_json::from_str(body).ok()?;
|
||||
let detail = google_error_detail(
|
||||
|
||||
@@ -14,7 +14,7 @@ mod tool_ids;
|
||||
pub(crate) use api_key::GenAiClient;
|
||||
pub(crate) use client::{Catalog, CloudCodeClient, GenerateMode, Model, unwrap_frame};
|
||||
pub(crate) use count::count_events;
|
||||
pub(crate) use failure::{connection_test_error, sent, unsent};
|
||||
pub(crate) use failure::{connection_test_error, is_validation_required, sent, unsent};
|
||||
pub(crate) use headers::request_headers;
|
||||
pub(crate) use pool::ClientPool;
|
||||
pub(crate) use response::{ResponseContext, events, genai_events};
|
||||
|
||||
Reference in New Issue
Block a user