mirror of
https://github.com/zyycn/codex-proxy-rs.git
synced 2026-12-04 16:01:04 +00:00
Compare commits
5
Commits
v3.61.1-rc.5
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2891e14ce | ||
|
|
b28eee6e18 | ||
|
|
6bf182677a | ||
|
|
8d4b0496e2 | ||
|
|
9b08c3a50d |
No files matched your search
@@ -1,4 +1,4 @@
|
||||
//! 为 Claude 原生生成补齐能唯一配对的工具 ID,保留其余原始 JSON 字节
|
||||
//! 按 GenAI 工具关联规则为 Claude 原生生成补齐 ID,保留其余原始 JSON 字节
|
||||
|
||||
use std::{borrow::Cow, collections::BTreeMap};
|
||||
|
||||
@@ -83,15 +83,14 @@ fn tools<'a>(content: &Content<'a>) -> Option<Vec<Tool<'a>>> {
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Pair {
|
||||
call: Option<usize>,
|
||||
response: Option<usize>,
|
||||
ambiguous: bool,
|
||||
struct ToolGroup<'a> {
|
||||
calls: Vec<&'a Tool<'a>>,
|
||||
responses: Vec<&'a Tool<'a>>,
|
||||
}
|
||||
|
||||
pub(super) fn repair(body: Box<RawValue>) -> Result<Box<RawValue>, serde_json::Error> {
|
||||
// AGY CLI 1.5.20 的 convertToVertexV1 清空两侧 ID,见 #807
|
||||
// https://github.com/zyycn/codex-proxy-rs/issues/807
|
||||
// AGY CLI / ACP 1.5.24 的 Gateway/GenAI 路径仍清空两侧 ID,见 #807、#848
|
||||
// https://github.com/zyycn/codex-proxy-rs/issues/848
|
||||
// 客户端恢复保留 ID 后移除此补偿;不为格式错误或有歧义的历史猜测关联
|
||||
let Ok(request) = serde_json::from_str::<Request<'_>>(body.get()) else {
|
||||
return Ok(body);
|
||||
@@ -118,48 +117,62 @@ pub(super) fn repair(body: Box<RawValue>) -> Result<Box<RawValue>, serde_json::E
|
||||
}
|
||||
let calls = &turns[turn];
|
||||
let responses = &turns[turn + 1];
|
||||
let mut pairs = BTreeMap::<&str, Pair>::new();
|
||||
for (index, call) in calls.iter().enumerate() {
|
||||
let pair = pairs.entry(&call.name).or_default();
|
||||
pair.ambiguous |= pair.call.replace(index).is_some();
|
||||
let mut groups = BTreeMap::<&str, ToolGroup<'_>>::new();
|
||||
for call in calls {
|
||||
groups.entry(&call.name).or_default().calls.push(call);
|
||||
}
|
||||
for (index, response) in responses.iter().enumerate() {
|
||||
let pair = pairs.entry(&response.name).or_default();
|
||||
pair.ambiguous |= pair.response.replace(index).is_some();
|
||||
for response in responses {
|
||||
groups
|
||||
.entry(&response.name)
|
||||
.or_default()
|
||||
.responses
|
||||
.push(response);
|
||||
}
|
||||
for pair in pairs.values().filter(|pair| !pair.ambiguous) {
|
||||
let (Some(call), Some(response)) = (pair.call, pair.response) else {
|
||||
for group in groups.values() {
|
||||
if group.calls.len() != group.responses.len() {
|
||||
continue;
|
||||
};
|
||||
let (call, response) = (&calls[call], &responses[response]);
|
||||
let id = match (call.id.as_deref(), response.id.as_deref()) {
|
||||
(Some(_), Some(_)) => continue,
|
||||
(Some(id), None) | (None, Some(id)) => {
|
||||
if ids.get(id) != Some(&1) {
|
||||
continue;
|
||||
}
|
||||
id.to_owned()
|
||||
}
|
||||
(None, None) => {
|
||||
// 轮次与 part 位置使追加历史和重试保持稳定;同时避开客户端已有 ID
|
||||
let mut id = format!("toolu_cpr_{turn}_{}", call.part);
|
||||
while ids.contains_key(id.as_str()) {
|
||||
id.push('_');
|
||||
}
|
||||
id
|
||||
}
|
||||
};
|
||||
ids.insert(Cow::Owned(id.clone()), 2);
|
||||
let insertion = format!(",\"id\":{}", serde_json::to_string(&id)?);
|
||||
for tool in [call, response]
|
||||
.into_iter()
|
||||
.filter(|tool| tool.id.is_none())
|
||||
}
|
||||
// GenAI 无 ID 时按同名出现顺序配对;混有 ID 时可能按 ID 重排,不能套用顺序
|
||||
// https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/tools/function-calling#parallel_function_calling
|
||||
if group.calls.len() > 1
|
||||
&& group
|
||||
.calls
|
||||
.iter()
|
||||
.chain(&group.responses)
|
||||
.any(|tool| tool.id.is_some())
|
||||
{
|
||||
// RawValue 来自同一正文,插入点由解析器确定,不重编码参数、结果或签名
|
||||
let end = tool.raw.get().as_ptr() as usize - body.get().as_ptr() as usize
|
||||
+ tool.raw.get().len()
|
||||
- 1;
|
||||
insertions.insert(end, insertion.clone());
|
||||
continue;
|
||||
}
|
||||
for (call, response) in group.calls.iter().zip(&group.responses) {
|
||||
let id = match (call.id.as_deref(), response.id.as_deref()) {
|
||||
(Some(_), Some(_)) => continue,
|
||||
(Some(id), None) | (None, Some(id)) => {
|
||||
if ids.get(id) != Some(&1) {
|
||||
continue;
|
||||
}
|
||||
id.to_owned()
|
||||
}
|
||||
(None, None) => {
|
||||
// 轮次与 part 位置使追加历史和重试保持稳定;同时避开客户端已有 ID
|
||||
let mut id = format!("toolu_cpr_{turn}_{}", call.part);
|
||||
while ids.contains_key(id.as_str()) {
|
||||
id.push('_');
|
||||
}
|
||||
id
|
||||
}
|
||||
};
|
||||
ids.insert(Cow::Owned(id.clone()), 2);
|
||||
let insertion = format!(",\"id\":{}", serde_json::to_string(&id)?);
|
||||
for tool in [call, response]
|
||||
.into_iter()
|
||||
.filter(|tool| tool.id.is_none())
|
||||
{
|
||||
// RawValue 来自同一正文,插入点由解析器确定,不重编码参数、结果或签名
|
||||
let end = tool.raw.get().as_ptr() as usize - body.get().as_ptr() as usize
|
||||
+ tool.raw.get().len()
|
||||
- 1;
|
||||
insertions.insert(end, insertion.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,9 +71,9 @@ fn history(calls: Vec<Value>, responses: Vec<Value>) -> Value {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn missing_ids_pair_by_unique_name_without_reencoding_business_fields() {
|
||||
async fn missing_ids_pair_by_name_and_parallel_order_without_reencoding_business_fields() {
|
||||
let (server, client) = client().await;
|
||||
let contents = r#"[{"role":"model","parts":[{"thought":true,"text":"reason","thoughtSignature":"opaque=="},{"functionCall":{"name":"look\u0075p","args":{"large":98765432109876543210987654,"n":1e+09,"n":2}}},{"function_call":{"name":"read","args":{}}}]},{"role":"user","parts":[{"function_response":{"name":"read","response":{"output":"second"}}},{"functionResponse":{"name":"lookup","response":{"output":"first","functionCall":{"name":"nested"}}}}]}]"#;
|
||||
let contents = r#"[{"role":"model","parts":[{"thought":true,"text":"reason","thoughtSignature":"opaque=="},{"functionCall":{"name":"look\u0075p","args":{"large":98765432109876543210987654,"n":1e+09,"n":2}}},{"function_call":{"name":"read","args":{}}},{"text":"next"},{"functionCall":{"name":"lookup","args":{"key":"third"}}}]},{"role":"user","parts":[{"function_response":{"name":"read","response":{"output":"second"}}},{"functionResponse":{"name":"lookup","response":{"output":"first","functionCall":{"name":"nested"}}}},{"text":"next"},{"function_response":{"name":"lookup","response":{"output":"third"}}}]}]"#;
|
||||
let body = format!(r#"{{"contents":{contents},"unknown":1e+09,"unknown":2}}"#);
|
||||
for mode in [GenerateMode::Json, GenerateMode::Stream] {
|
||||
let outgoing = generate(&server, &client, &body, "claude-opus-5-5-medium", mode).await;
|
||||
@@ -84,8 +84,17 @@ async fn missing_ids_pair_by_unique_name_without_reencoding_business_fields() {
|
||||
let second = value["contents"][0]["parts"][2]["function_call"]["id"]
|
||||
.as_str()
|
||||
.unwrap();
|
||||
let third = value["contents"][0]["parts"][4]["functionCall"]["id"]
|
||||
.as_str()
|
||||
.unwrap();
|
||||
assert!(!first.is_empty());
|
||||
assert_ne!(first, second);
|
||||
assert_ne!(first, third);
|
||||
assert_ne!(second, third);
|
||||
assert_eq!(
|
||||
value["contents"][1]["parts"][3]["function_response"]["id"],
|
||||
third
|
||||
);
|
||||
assert_eq!(
|
||||
value["contents"][1]["parts"][1]["functionResponse"]["id"],
|
||||
first
|
||||
@@ -97,7 +106,8 @@ async fn missing_ids_pair_by_unique_name_without_reencoding_business_fields() {
|
||||
let restored = outgoing
|
||||
.get()
|
||||
.replace(&format!(",\"id\":\"{first}\""), "")
|
||||
.replace(&format!(",\"id\":\"{second}\""), "");
|
||||
.replace(&format!(",\"id\":\"{second}\""), "")
|
||||
.replace(&format!(",\"id\":\"{third}\""), "");
|
||||
assert!(restored.contains(contents));
|
||||
assert!(restored.contains(r#""unknown":1e+09,"unknown":2"#));
|
||||
assert!(
|
||||
@@ -116,11 +126,13 @@ async fn existing_ids_are_reused_and_generated_ids_survive_retries_and_appended_
|
||||
call("run", None),
|
||||
call("read", Some("existing-call")),
|
||||
call("lookup", None),
|
||||
call("run", None),
|
||||
],
|
||||
vec![
|
||||
response("lookup", Some("existing-result")),
|
||||
response("read", None),
|
||||
response("run", None),
|
||||
response("run", None),
|
||||
],
|
||||
);
|
||||
let first = generate(
|
||||
@@ -147,6 +159,13 @@ async fn existing_ids_are_reused_and_generated_ids_survive_retries_and_appended_
|
||||
first_value["contents"][0]["parts"][2]["functionCall"]["id"],
|
||||
"existing-result"
|
||||
);
|
||||
let parallel_id = &first_value["contents"][0]["parts"][3]["functionCall"]["id"];
|
||||
assert!(parallel_id.as_str().is_some_and(|id| !id.is_empty()));
|
||||
assert_ne!(parallel_id, id);
|
||||
assert_eq!(
|
||||
first_value["contents"][1]["parts"][3]["functionResponse"]["id"],
|
||||
*parallel_id
|
||||
);
|
||||
let retry = generate(
|
||||
&server,
|
||||
&client,
|
||||
@@ -185,8 +204,12 @@ async fn existing_ids_are_reused_and_generated_ids_survive_retries_and_appended_
|
||||
|
||||
// 客户端已有的 ID 即使占用补偿命名空间,也不能和新配对共用
|
||||
let collision = history(
|
||||
vec![call("run", None), call("read", Some(id))],
|
||||
vec![response("run", None), response("read", Some(id))],
|
||||
vec![call("run", None), call("read", Some(id)), call("run", None)],
|
||||
vec![
|
||||
response("run", None),
|
||||
response("read", Some(id)),
|
||||
response("run", None),
|
||||
],
|
||||
);
|
||||
let collision = generate(
|
||||
&server,
|
||||
@@ -213,12 +236,28 @@ async fn ambiguous_or_invalid_history_and_existing_ids_remain_unchanged() {
|
||||
let mut cases = vec![
|
||||
history(
|
||||
vec![call("run", None), call("run", None)],
|
||||
vec![response("run", None), response("run", None)],
|
||||
vec![response("run", None)],
|
||||
),
|
||||
history(
|
||||
vec![call("run", None)],
|
||||
vec![response("run", None), response("run", None)],
|
||||
),
|
||||
history(
|
||||
vec![call("run", Some("a")), call("run", None)],
|
||||
vec![response("run", None), response("run", None)],
|
||||
),
|
||||
history(
|
||||
vec![call("run", None), call("run", None)],
|
||||
vec![response("run", None), response("run", Some("b"))],
|
||||
),
|
||||
history(
|
||||
vec![call("run", Some("a")), call("run", None)],
|
||||
vec![response("run", None), response("run", Some("a"))],
|
||||
),
|
||||
history(
|
||||
vec![call("run", Some("a")), call("run", Some("b"))],
|
||||
vec![response("run", Some("b")), response("run", Some("a"))],
|
||||
),
|
||||
history(vec![call("run", None)], vec![response("other", None)]),
|
||||
history(
|
||||
vec![call("run", Some("a"))],
|
||||
@@ -257,7 +296,10 @@ async fn ambiguous_or_invalid_history_and_existing_ids_remain_unchanged() {
|
||||
#[tokio::test]
|
||||
async fn compatibility_is_limited_to_native_claude_generation() {
|
||||
let (server, client) = client().await;
|
||||
let body = history(vec![call("run", None)], vec![response("run", None)]);
|
||||
let body = history(
|
||||
vec![call("run", None), call("run", None)],
|
||||
vec![response("run", None), response("run", None)],
|
||||
);
|
||||
for (model, mode) in [
|
||||
("gemini-4-hydrogen", GenerateMode::Json),
|
||||
(
|
||||
|
||||
@@ -133,7 +133,23 @@ fn normalize_codex_oauth_options(body: &mut Map<String, Value>) {
|
||||
///
|
||||
/// 兼容基准是 Codex Core/Desktop 的模型请求,不是公开 OpenAI Responses API
|
||||
/// 未知字段继续透传,不能因官方请求结构中没有某个字段就将其列入过滤规则
|
||||
pub(crate) fn normalize_codex_request_body(body: &mut Map<String, Value>) {
|
||||
pub(crate) fn normalize_codex_request_body(
|
||||
body: &mut Map<String, Value>,
|
||||
should_replace_none_with_low: impl FnOnce() -> bool,
|
||||
) {
|
||||
// 整个请求共用所选账号的目录判断,首次遇到显式 none 才读取快照
|
||||
let replace_none = std::cell::LazyCell::new(should_replace_none_with_low);
|
||||
let normalize_effort = |fields: &mut Map<String, Value>| {
|
||||
if let Some(effort) = fields
|
||||
.get_mut("reasoning")
|
||||
.and_then(|reasoning| reasoning.get_mut("effort"))
|
||||
&& effort.as_str() == Some("none")
|
||||
&& *replace_none
|
||||
{
|
||||
*effort = Value::from("low");
|
||||
}
|
||||
};
|
||||
normalize_effort(body);
|
||||
// 官方 Core/Desktop 显式发送 store=false;仅为缺字段的下游请求补齐,保留显式值
|
||||
body.entry("store").or_insert(Value::Bool(false));
|
||||
|
||||
@@ -159,10 +175,12 @@ pub(crate) fn normalize_codex_request_body(body: &mut Map<String, Value>) {
|
||||
let Some(item) = item.as_object_mut() else {
|
||||
continue;
|
||||
};
|
||||
if item.get("type").and_then(Value::as_str) == Some("message")
|
||||
&& item.get("role").and_then(Value::as_str) == Some("system")
|
||||
{
|
||||
item.insert("role".to_owned(), Value::String("developer".to_owned()));
|
||||
match item.get("type").and_then(Value::as_str) {
|
||||
Some("configuration_update") => normalize_effort(item),
|
||||
Some("message") if item.get("role").and_then(Value::as_str) == Some("system") => {
|
||||
item.insert("role".to_owned(), Value::String("developer".to_owned()));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -503,6 +503,20 @@ impl CodexCredentialCatalogService {
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn should_replace_none_with_low(
|
||||
&self,
|
||||
account: &ProviderAccount,
|
||||
model: &UpstreamModelId,
|
||||
) -> bool {
|
||||
self.cached().ok().flatten().is_some_and(|snapshot| {
|
||||
snapshot.account_model(account, model).is_some_and(|entry| {
|
||||
let levels = entry.capabilities().reasoning_efforts();
|
||||
levels.iter().any(|level| level == "low")
|
||||
&& !levels.iter().any(|level| level == "none")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn messages_model_capabilities(
|
||||
&self,
|
||||
account: &ProviderAccount,
|
||||
|
||||
@@ -553,7 +553,7 @@ impl Provider for CodexProvider {
|
||||
..Default::default()
|
||||
};
|
||||
};
|
||||
let Ok(encoded) = encode_generate_payload(request, "observability") else {
|
||||
let Ok(encoded) = encode_generate_payload(request, "observability", || false) else {
|
||||
return ProviderRequestObservation::default();
|
||||
};
|
||||
let previous_reasoning_effort_override = request
|
||||
@@ -694,7 +694,7 @@ impl Provider for CodexProvider {
|
||||
}
|
||||
// 跨协议转换必须在选号后执行;选号前只按各自协议读取明确会话身份
|
||||
let upstream = (generate.protocol_payload().protocol() == OPENAI_PROTOCOL)
|
||||
.then(|| encode_generate_payload(generate, upstream_model.as_str()))
|
||||
.then(|| encode_generate_payload(generate, upstream_model.as_str(), || false))
|
||||
.transpose()
|
||||
.map_err(map_request_error)?;
|
||||
// 固定调度约束:Guardian 分类先于选号,不能随原生/适配器发送路径改变
|
||||
@@ -976,8 +976,11 @@ impl CodexProvider {
|
||||
"provider_input",
|
||||
None,
|
||||
);
|
||||
let mut upstream = encode_generate_payload(&generate, upstream_model.as_str())
|
||||
.map_err(map_request_error)?;
|
||||
let mut upstream = encode_generate_payload(&generate, upstream_model.as_str(), || {
|
||||
self.catalog
|
||||
.should_replace_none_with_low(lease.account(), &upstream_model)
|
||||
})
|
||||
.map_err(map_request_error)?;
|
||||
upstream.client_account_follow_only = crate::request_identity::follows_session_with_headers(
|
||||
generate.protocol_payload().body(),
|
||||
generate.protocol_payload().context(),
|
||||
|
||||
@@ -107,7 +107,7 @@ pub fn encode_generate_request(
|
||||
upstream_model: &str,
|
||||
location: Option<&CodexRequestLocation>,
|
||||
) -> Result<CodexResponsesRequest, CodexRequestEncodeError> {
|
||||
let mut encoded = encode_generate_payload(request, upstream_model)?;
|
||||
let mut encoded = encode_generate_payload(request, upstream_model, || false)?;
|
||||
apply_codex_request_country(
|
||||
encoded.body_mut(),
|
||||
location,
|
||||
@@ -121,6 +121,7 @@ pub fn encode_generate_request(
|
||||
pub(crate) fn encode_generate_payload(
|
||||
request: &GenerateRequest,
|
||||
upstream_model: &str,
|
||||
should_replace_none_with_low: impl FnOnce() -> bool,
|
||||
) -> Result<CodexResponsesRequest, CodexRequestEncodeError> {
|
||||
let payload = request.protocol_payload();
|
||||
if payload.protocol() != OPENAI_PROTOCOL {
|
||||
@@ -128,7 +129,7 @@ pub(crate) fn encode_generate_payload(
|
||||
}
|
||||
let mut body = payload.body().clone();
|
||||
body.insert("model".to_owned(), Value::String(upstream_model.to_owned()));
|
||||
normalize_codex_request_body(&mut body);
|
||||
normalize_codex_request_body(&mut body, should_replace_none_with_low);
|
||||
let mut encoded = CodexResponsesRequest::from_body(body);
|
||||
encoded.explicit_prompt_cache_key = encoded.prompt_cache_key().is_some();
|
||||
extract_request_context(&mut encoded);
|
||||
|
||||
@@ -937,17 +937,26 @@ async fn capture_downstream_request(
|
||||
websocket: bool,
|
||||
lite: bool,
|
||||
) -> Value {
|
||||
capture_downstream_with_country(original, api_key, websocket, lite, None, Default::default())
|
||||
.await
|
||||
capture_downstream_with_settings(
|
||||
original,
|
||||
api_key,
|
||||
websocket,
|
||||
lite,
|
||||
None,
|
||||
Default::default(),
|
||||
None,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn capture_downstream_with_country(
|
||||
async fn capture_downstream_with_settings(
|
||||
original: Value,
|
||||
api_key: bool,
|
||||
websocket: bool,
|
||||
lite: bool,
|
||||
location: Option<gateway_core::account::RequestLocation>,
|
||||
country: OpenAiRequestCountry,
|
||||
catalog: Option<Value>,
|
||||
) -> Value {
|
||||
let http = MockServer::start().await;
|
||||
let (base_url, websocket_server) = if websocket {
|
||||
@@ -1010,7 +1019,12 @@ async fn capture_downstream_with_country(
|
||||
),
|
||||
])),
|
||||
));
|
||||
let provider = provider_with_base_url(&store, base_url);
|
||||
let provider = if let Some(catalog) = catalog {
|
||||
seed_account_catalog(&store, "acct_provider_contract", u8::from(api_key), catalog).await;
|
||||
provider_with_catalog_and_base_url(&store, base_url).await
|
||||
} else {
|
||||
provider_with_base_url(&store, base_url)
|
||||
};
|
||||
let mut stream = provider
|
||||
.execute(
|
||||
planned_request("openai", operation),
|
||||
@@ -8356,20 +8370,26 @@ async fn completed_response_persists_session_affinity_before_stream_consumer_sto
|
||||
}
|
||||
|
||||
async fn seed_service_tiers(store: &MemoryAccountStore, id: &str, model: &str, tiers: &[&str]) {
|
||||
use gateway_core::account::AccountCatalogObservation;
|
||||
let account = store.account(id).unwrap();
|
||||
let tiers: Vec<_> = tiers
|
||||
.iter()
|
||||
.map(|id| json!({"id":id,"name":id,"description":""}))
|
||||
.collect();
|
||||
let mut document = vec![0];
|
||||
serde_json::to_writer(
|
||||
&mut document,
|
||||
&json!({"models":[{
|
||||
seed_account_catalog(
|
||||
store,
|
||||
id,
|
||||
0,
|
||||
json!({"models":[{
|
||||
"slug":model, "display_name":model, "service_tiers":tiers,
|
||||
}]}),
|
||||
)
|
||||
.unwrap();
|
||||
.await;
|
||||
}
|
||||
|
||||
async fn seed_account_catalog(store: &MemoryAccountStore, id: &str, protocol: u8, catalog: Value) {
|
||||
use gateway_core::account::AccountCatalogObservation;
|
||||
let account = store.account(id).unwrap();
|
||||
let mut document = vec![protocol];
|
||||
serde_json::to_writer(&mut document, &catalog).unwrap();
|
||||
assert!(
|
||||
store
|
||||
.save_account_catalog(
|
||||
|
||||
@@ -130,13 +130,14 @@ async fn request_country_follows_the_selected_account_across_transports() {
|
||||
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(
|
||||
let sent = capture_downstream_with_settings(
|
||||
body.clone(),
|
||||
api_key,
|
||||
websocket,
|
||||
false,
|
||||
location.cloned(),
|
||||
policy.clone(),
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(
|
||||
@@ -411,6 +412,59 @@ async fn websocket_messages_preserve_text_and_metadata_despite_unrecognized_json
|
||||
assert_eq!(&delivered[1..delivered.len() - 1], messages);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn none_effort_follows_the_selected_models_catalog_on_both_transports() {
|
||||
for (levels, expected) in [
|
||||
(&["high", "minimal", "low"][..], "low"),
|
||||
(&["high", "medium"], "none"),
|
||||
(&["low", "none"], "none"),
|
||||
(&[], "none"),
|
||||
] {
|
||||
let levels: Vec<_> = levels
|
||||
.iter()
|
||||
.map(|effort| json!({"effort": effort}))
|
||||
.collect();
|
||||
let catalog = json!({"models":[
|
||||
{"slug":"client-alias","display_name":"alias","supported_reasoning_levels":[{"effort":"minimal"}]},
|
||||
{"slug":"gpt-5.4","display_name":"target","supported_reasoning_levels":levels}
|
||||
]});
|
||||
let body = json!({
|
||||
"model":"client-alias", "reasoning":{"effort":"none","summary":"auto"},
|
||||
"input":[
|
||||
{"type":"configuration_update","reasoning":{"effort":"none","other":1}},
|
||||
{"type":"configuration_update","reasoning":{"effort":"high"}},
|
||||
{"type":"configuration_update","reasoning":{"effort":"none"}},
|
||||
{"type":"configuration_update","reasoning":{"summary":"auto"}},
|
||||
{"type":"future","reasoning":{"effort":"none"}}
|
||||
]
|
||||
});
|
||||
let mut expected_input = body["input"].clone();
|
||||
for index in [0, 2] {
|
||||
expected_input[index]["reasoning"]["effort"] = json!(expected);
|
||||
}
|
||||
for api_key in [false, true] {
|
||||
for websocket in [false, true] {
|
||||
let sent = capture_downstream_with_settings(
|
||||
body.clone(),
|
||||
api_key,
|
||||
websocket,
|
||||
false,
|
||||
None,
|
||||
Default::default(),
|
||||
Some(catalog.clone()),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(sent["model"], "gpt-5.4");
|
||||
assert_eq!(
|
||||
sent["reasoning"],
|
||||
json!({"effort":expected,"summary":"auto"})
|
||||
);
|
||||
assert_eq!(sent["input"], expected_input);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn responses_service_tiers_reach_each_upstream_on_both_transports() {
|
||||
for tier in [
|
||||
|
||||
+5
-1
@@ -276,7 +276,9 @@ CPR 在 AGY 的原生与转换入口透传未被过滤的 HTTP 扩展头,保
|
||||
|
||||
Cloud Code 生成封套使用 `userAgent: "antigravity"` 与 `requestType: "agent"`,独立搜索使用 `web_search`。原生正文在 `systemInstruction.parts` 前添加画像提示词。普通 Chat 转换只发送调用方系统指令及其配置的改写结果。网关移除 `labels` 中 Gateway 添加的 `client`、`goog-originating-logical-product-id`、`goog-originating-service-id`。系统指令也接受 `system_instruction`,两者同时提供时以 `systemInstruction` 为准,出站统一使用驼峰名称。其余字段保留原始 JSON 表达与顺序,不经 Chat 或 canonical 请求重建
|
||||
|
||||
Claude 原生生成兼容缺失工具 ID 的历史:仅在相邻 `model`/`user` 轮次中,调用和结果的工具名各自唯一时补齐缺失的 `id`。一侧已有 ID 时沿用该 ID;两侧均缺失时生成确定性配对 ID,并避开正文已有 ID。已有字段、参数、结果和思考签名保持原样;同名并行调用、孤立结果、ID 冲突或格式错误不猜测配对,继续由上游校验。该兼容不作用于 Gemini、Chat 转换、独立搜索或输入计数
|
||||
Claude 原生生成在相邻 `model`/`user` 轮次中补齐缺失的工具 `id`,按工具名配对。同名调用和结果各只有一个时,一侧已有 ID 就沿用,两侧均缺失时生成确定性配对 ID。同名并行调用要求调用与结果数量一致、两侧全部缺失 ID,按各自的出现顺序配对,遵循 [GenAI 并行函数调用规则](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/tools/function-calling#parallel_function_calling)
|
||||
|
||||
生成的 ID 避开正文已有 ID,工具参数、结果、思考签名及已有字段保留原始表达。同名并行历史混有 ID、数量不匹配、孤立结果、ID 冲突或格式错误时保留原样,由上游校验。该兼容只适用于 Claude 原生生成
|
||||
|
||||
原生响应的思考签名保持上游原值,不添加网关标记。Claude/Gemini 生成根据已知原生封套识别来源,只移除可识别的异家族签名及对应思考内容,保留普通文本、工具调用和结果。导入 Gemini 的工具历史中,各轮首个工具调用缺少签名时使用官方 `skip_thought_signature_validator` 占位
|
||||
|
||||
@@ -610,6 +612,8 @@ WS 握手的轮次元数据头只随首次请求转发,后续帧在正文中
|
||||
不删除工具参数 schema、输入内容或 `client_metadata` 内的同名业务字段;其他未知字段继续透传。
|
||||
`prompt_cache_key` 不用于补造会话或线程请求头;客户端未提供缓存键、会话或线程身份时保持缺省
|
||||
|
||||
顶层和 `input` 中每条 `configuration_update` 的 `reasoning.effort` 显式为 `"none"` 时,仅当所选账号的上游模型目录列出 `low` 且未列出 `none` 时,网关才将该值改为 `"low"`。其他情况保留原值
|
||||
|
||||
发往 Codex/OAuth 的 Responses 请求另按下表处理;API Key 上游保留这些字段。规则只匹配表中列出的位置
|
||||
|
||||
| 请求字段 | Codex/OAuth 出站行为 |
|
||||
|
||||
+3
-15
@@ -1,18 +1,6 @@
|
||||
# v3.61.1-rc.5
|
||||
|
||||
## 新增功能
|
||||
|
||||
- OpenAI 原生账号触发轮次限流后,仅暂停该账号对应模型的调度,等待时间取自 `Retry-After`,缺省为 60 秒;账号列表可查看受限模型和恢复时间
|
||||
# v3.61.1-rc.6
|
||||
|
||||
## 问题修复
|
||||
|
||||
- OpenAI 模型目录在后台重试或手动刷新时,只要持续收到数据就能继续下载,连续 30 秒无进展才超时(#845)
|
||||
- Chat 转 Responses 支持有名称但没有调用 ID 的工具结果,并正确转换自定义工具的语法定义(#844)
|
||||
- Chat 经 Codex OAuth 调用工具时可配对过长的历史调用 ID,支持特殊字符工具名和旧版搜索工具名,流式与非流式响应均保留客户端原工具名(#844)
|
||||
- Codex OAuth 流式请求重发完整历史时,可在只有本轮元数据变化或没有新增输入时复用上一轮响应
|
||||
- 客户端 Key 恢复并发和每分钟请求计数时排除插件内部子请求,并支持配置较大的限额
|
||||
- Antigravity 核验客户端安装包时使用运行数据目录,避免容器临时目录空间不足导致下载失败
|
||||
|
||||
## 优化改进
|
||||
|
||||
- 管理端列表在矮窗口中保留表格滚动与分页空间,独立应用模式保留页面底部间距
|
||||
- OpenAI 请求显式指定 `reasoning.effort: none` 时,若所选账号的模型目录支持 `low` 但不支持 `none`,自动改用 `low`,并同步处理历史中的推理配置更新
|
||||
- Antigravity 调用 Claude 时,同名并行工具的调用与结果数量一致且均缺失 ID,可按出现顺序补齐配对,修复下一轮请求因缺少工具 ID 失败的问题(#848)
|
||||
@@ -1,7 +1,7 @@
|
||||
version: 3.61.1-rc.5
|
||||
version: 3.61.1-rc.6
|
||||
published:
|
||||
'3':
|
||||
stable: 3.61.0
|
||||
rc: 3.61.1-rc.4
|
||||
beta: 3.61.1-rc.4
|
||||
alpha: 3.61.1-rc.4
|
||||
rc: 3.61.1-rc.6
|
||||
beta: 3.61.1-rc.6
|
||||
alpha: 3.61.1-rc.6
|
||||
Reference in new issue
Block a user