mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-01 17:00:21 +08:00
migrate ai format conversion to responses adapters
This commit is contained in:
@@ -85,13 +85,19 @@ pub fn infer_internal_finalize_signature(payload: &GatewaySyncReportRequest) ->
|
||||
return Some("openai:chat".to_string());
|
||||
}
|
||||
if report_kind.starts_with("openai_compact_") {
|
||||
return Some("openai:compact".to_string());
|
||||
return Some("openai:responses:compact".to_string());
|
||||
}
|
||||
if report_kind.starts_with("openai_responses_compact_") {
|
||||
return Some("openai:responses:compact".to_string());
|
||||
}
|
||||
if report_kind.starts_with("openai_responses_") {
|
||||
return Some("openai:responses".to_string());
|
||||
}
|
||||
if report_kind.starts_with("openai_image_") {
|
||||
return Some("openai:image".to_string());
|
||||
}
|
||||
if report_kind.starts_with("openai_cli_") {
|
||||
return Some("openai:cli".to_string());
|
||||
return Some("openai:responses".to_string());
|
||||
}
|
||||
if report_kind.starts_with("openai_video_") {
|
||||
return Some("openai:video".to_string());
|
||||
@@ -121,15 +127,15 @@ pub fn resolve_internal_finalize_route(signature: &str) -> Option<InternalFinali
|
||||
route_family: "openai",
|
||||
route_kind: "chat",
|
||||
}),
|
||||
"openai:cli" => Some(InternalFinalizeRoute {
|
||||
"openai:responses" | "openai:cli" => Some(InternalFinalizeRoute {
|
||||
public_path: "/v1/responses",
|
||||
route_family: "openai",
|
||||
route_kind: "cli",
|
||||
route_kind: "responses",
|
||||
}),
|
||||
"openai:compact" => Some(InternalFinalizeRoute {
|
||||
"openai:responses:compact" | "openai:compact" => Some(InternalFinalizeRoute {
|
||||
public_path: "/v1/responses/compact",
|
||||
route_family: "openai",
|
||||
route_kind: "compact",
|
||||
route_kind: "responses:compact",
|
||||
}),
|
||||
"openai:image" => Some(InternalFinalizeRoute {
|
||||
public_path: "/v1/images/generations",
|
||||
@@ -231,6 +237,10 @@ pub fn is_local_ai_sync_report_kind(report_kind: &str) -> bool {
|
||||
| "openai_chat_sync_error"
|
||||
| "claude_chat_sync_error"
|
||||
| "gemini_chat_sync_error"
|
||||
| "openai_responses_sync_success"
|
||||
| "openai_responses_compact_sync_success"
|
||||
| "openai_responses_sync_error"
|
||||
| "openai_responses_compact_sync_error"
|
||||
| "openai_cli_sync_success"
|
||||
| "openai_image_sync_success"
|
||||
| "claude_cli_sync_success"
|
||||
@@ -262,6 +272,8 @@ pub fn is_local_ai_stream_report_kind(report_kind: &str) -> bool {
|
||||
"openai_chat_stream_success"
|
||||
| "claude_chat_stream_success"
|
||||
| "gemini_chat_stream_success"
|
||||
| "openai_responses_stream_success"
|
||||
| "openai_responses_compact_stream_success"
|
||||
| "openai_cli_stream_success"
|
||||
| "claude_cli_stream_success"
|
||||
| "gemini_cli_stream_success"
|
||||
@@ -415,6 +427,12 @@ mod tests {
|
||||
assert!(is_local_ai_sync_report_kind(
|
||||
"openai_video_create_sync_success"
|
||||
));
|
||||
assert!(is_local_ai_sync_report_kind(
|
||||
"openai_responses_compact_sync_success"
|
||||
));
|
||||
assert!(is_local_ai_sync_report_kind(
|
||||
"openai_responses_compact_sync_error"
|
||||
));
|
||||
assert!(is_local_ai_sync_report_kind("openai_image_sync_success"));
|
||||
assert!(is_local_ai_sync_report_kind("gemini_files_delete_mapping"));
|
||||
assert!(!is_local_ai_sync_report_kind("unknown_sync_kind"));
|
||||
@@ -423,6 +441,9 @@ mod tests {
|
||||
#[test]
|
||||
fn classifies_local_ai_stream_report_kinds() {
|
||||
assert!(is_local_ai_stream_report_kind("openai_chat_stream_success"));
|
||||
assert!(is_local_ai_stream_report_kind(
|
||||
"openai_responses_compact_stream_success"
|
||||
));
|
||||
assert!(!is_local_ai_stream_report_kind("openai_chat_stream_error"));
|
||||
}
|
||||
|
||||
@@ -483,6 +504,13 @@ mod tests {
|
||||
Some("openai:image".to_string())
|
||||
);
|
||||
|
||||
let from_compact_report_kind =
|
||||
sample_sync_report_with_context("openai_responses_compact_sync_finalize", json!({}));
|
||||
assert_eq!(
|
||||
infer_internal_finalize_signature(&from_compact_report_kind),
|
||||
Some("openai:responses:compact".to_string())
|
||||
);
|
||||
|
||||
let unknown = sample_sync_report("unknown_sync_finalize", 200);
|
||||
assert_eq!(infer_internal_finalize_signature(&unknown), None);
|
||||
}
|
||||
@@ -490,13 +518,17 @@ mod tests {
|
||||
#[test]
|
||||
fn resolves_internal_finalize_route_for_supported_signatures() {
|
||||
assert_eq!(
|
||||
resolve_internal_finalize_route("openai:compact"),
|
||||
resolve_internal_finalize_route("openai:responses:compact"),
|
||||
Some(InternalFinalizeRoute {
|
||||
public_path: "/v1/responses/compact",
|
||||
route_family: "openai",
|
||||
route_kind: "compact",
|
||||
route_kind: "responses:compact",
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_internal_finalize_route("openai:compact"),
|
||||
resolve_internal_finalize_route("openai:responses:compact")
|
||||
);
|
||||
assert_eq!(
|
||||
resolve_internal_finalize_route("gemini:video"),
|
||||
Some(InternalFinalizeRoute {
|
||||
|
||||
@@ -291,7 +291,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}),
|
||||
"openai:cli",
|
||||
"openai:responses",
|
||||
);
|
||||
|
||||
assert_eq!(usage.input_tokens, 14);
|
||||
@@ -313,7 +313,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}),
|
||||
"openai:cli",
|
||||
"openai:responses",
|
||||
);
|
||||
|
||||
assert_eq!(usage.input_tokens, 52_600);
|
||||
@@ -392,7 +392,7 @@ mod tests {
|
||||
}
|
||||
]
|
||||
}),
|
||||
"openai:cli",
|
||||
"openai:responses",
|
||||
);
|
||||
|
||||
assert_eq!(usage.input_tokens, 9);
|
||||
|
||||
@@ -2448,7 +2448,7 @@ mod tests {
|
||||
})),
|
||||
stream: false,
|
||||
client_api_format: "claude:cli".to_string(),
|
||||
provider_api_format: "openai:cli".to_string(),
|
||||
provider_api_format: "openai:responses".to_string(),
|
||||
model_name: Some("gpt-5.4".to_string()),
|
||||
proxy: None,
|
||||
tls_profile: None,
|
||||
@@ -2515,7 +2515,7 @@ mod tests {
|
||||
body: RequestBody::from_json(json!({"model": "gpt-5.4"})),
|
||||
stream: true,
|
||||
client_api_format: "claude:cli".to_string(),
|
||||
provider_api_format: "openai:cli".to_string(),
|
||||
provider_api_format: "openai:responses".to_string(),
|
||||
model_name: Some("gpt-5.4".to_string()),
|
||||
proxy: None,
|
||||
tls_profile: None,
|
||||
@@ -2572,7 +2572,7 @@ mod tests {
|
||||
body: RequestBody::from_json(json!({"model": "gpt-5.4"})),
|
||||
stream: false,
|
||||
client_api_format: "claude:cli".to_string(),
|
||||
provider_api_format: "openai:cli".to_string(),
|
||||
provider_api_format: "openai:responses".to_string(),
|
||||
model_name: Some("gpt-5.4".to_string()),
|
||||
proxy: None,
|
||||
tls_profile: None,
|
||||
@@ -2583,7 +2583,7 @@ mod tests {
|
||||
report_kind: "claude_cli_sync_success".to_string(),
|
||||
report_context: Some(json!({
|
||||
"client_api_format": "claude:cli",
|
||||
"provider_api_format": "openai:cli",
|
||||
"provider_api_format": "openai:responses",
|
||||
"needs_conversion": true,
|
||||
"original_request_body": nested,
|
||||
"provider_request_body": {"input": "safe"}
|
||||
@@ -2635,7 +2635,7 @@ mod tests {
|
||||
},
|
||||
stream: true,
|
||||
client_api_format: "openai:chat".to_string(),
|
||||
provider_api_format: "openai:cli".to_string(),
|
||||
provider_api_format: "openai:responses".to_string(),
|
||||
model_name: Some("gpt-5.4".to_string()),
|
||||
proxy: None,
|
||||
tls_profile: None,
|
||||
@@ -2646,7 +2646,7 @@ mod tests {
|
||||
report_kind: "openai_chat_stream_success".to_string(),
|
||||
report_context: Some(json!({
|
||||
"client_api_format": "openai:chat",
|
||||
"provider_api_format": "openai:cli",
|
||||
"provider_api_format": "openai:responses",
|
||||
"needs_conversion": true
|
||||
})),
|
||||
status_code: 200,
|
||||
@@ -2730,7 +2730,7 @@ mod tests {
|
||||
},
|
||||
stream: true,
|
||||
client_api_format: "openai:chat".to_string(),
|
||||
provider_api_format: "openai:cli".to_string(),
|
||||
provider_api_format: "openai:responses".to_string(),
|
||||
model_name: Some("gpt-5.4".to_string()),
|
||||
proxy: None,
|
||||
tls_profile: None,
|
||||
@@ -2746,7 +2746,7 @@ mod tests {
|
||||
report_kind: "openai_chat_stream_success".to_string(),
|
||||
report_context: Some(json!({
|
||||
"client_api_format": "openai:chat",
|
||||
"provider_api_format": "openai:cli",
|
||||
"provider_api_format": "openai:responses",
|
||||
"needs_conversion": true
|
||||
})),
|
||||
status_code: 200,
|
||||
@@ -2761,6 +2761,7 @@ mod tests {
|
||||
response_id: Some("resp_summary_1".to_string()),
|
||||
model: Some("gpt-5.4".to_string()),
|
||||
observed_finish: true,
|
||||
unknown_event_count: 0,
|
||||
parser_error: None,
|
||||
}),
|
||||
telemetry: None,
|
||||
@@ -2799,8 +2800,8 @@ mod tests {
|
||||
body_ref: None,
|
||||
},
|
||||
stream: true,
|
||||
client_api_format: "openai:cli".to_string(),
|
||||
provider_api_format: "openai:cli".to_string(),
|
||||
client_api_format: "openai:responses".to_string(),
|
||||
provider_api_format: "openai:responses".to_string(),
|
||||
model_name: Some("gpt-5.5".to_string()),
|
||||
proxy: None,
|
||||
tls_profile: None,
|
||||
@@ -2852,8 +2853,8 @@ mod tests {
|
||||
trace_id: "trace-stream-provider-chunks-usage-1".to_string(),
|
||||
report_kind: "openai_cli_stream_success".to_string(),
|
||||
report_context: Some(json!({
|
||||
"client_api_format": "openai:cli",
|
||||
"provider_api_format": "openai:cli",
|
||||
"client_api_format": "openai:responses",
|
||||
"provider_api_format": "openai:responses",
|
||||
})),
|
||||
status_code: 200,
|
||||
headers: BTreeMap::new(),
|
||||
@@ -2869,6 +2870,7 @@ mod tests {
|
||||
response_id: Some("resp_123".to_string()),
|
||||
model: Some("gpt-5.5".to_string()),
|
||||
observed_finish: true,
|
||||
unknown_event_count: 0,
|
||||
parser_error: None,
|
||||
}),
|
||||
telemetry: None,
|
||||
@@ -2904,8 +2906,8 @@ mod tests {
|
||||
body_ref: None,
|
||||
},
|
||||
stream: true,
|
||||
client_api_format: "openai:cli".to_string(),
|
||||
provider_api_format: "openai:cli".to_string(),
|
||||
client_api_format: "openai:responses".to_string(),
|
||||
provider_api_format: "openai:responses".to_string(),
|
||||
model_name: Some("gpt-5.4".to_string()),
|
||||
proxy: None,
|
||||
tls_profile: None,
|
||||
@@ -2924,8 +2926,8 @@ mod tests {
|
||||
trace_id: "trace-stream-usage-2".to_string(),
|
||||
report_kind: "openai_cli_stream_success".to_string(),
|
||||
report_context: Some(json!({
|
||||
"client_api_format": "openai:cli",
|
||||
"provider_api_format": "openai:cli",
|
||||
"client_api_format": "openai:responses",
|
||||
"provider_api_format": "openai:responses",
|
||||
})),
|
||||
status_code: 200,
|
||||
headers: BTreeMap::new(),
|
||||
@@ -3135,8 +3137,8 @@ mod tests {
|
||||
body_ref: None,
|
||||
},
|
||||
stream: false,
|
||||
client_api_format: "openai:cli".to_string(),
|
||||
provider_api_format: "openai:cli".to_string(),
|
||||
client_api_format: "openai:responses".to_string(),
|
||||
provider_api_format: "openai:responses".to_string(),
|
||||
model_name: Some("gpt-5.4".to_string()),
|
||||
proxy: None,
|
||||
tls_profile: None,
|
||||
@@ -3146,8 +3148,8 @@ mod tests {
|
||||
trace_id: "trace-sync-upstream-stream-1".to_string(),
|
||||
report_kind: "openai_cli_sync_success".to_string(),
|
||||
report_context: Some(json!({
|
||||
"client_api_format": "openai:cli",
|
||||
"provider_api_format": "openai:cli",
|
||||
"client_api_format": "openai:responses",
|
||||
"provider_api_format": "openai:responses",
|
||||
"upstream_is_stream": true
|
||||
})),
|
||||
status_code: 200,
|
||||
@@ -3315,8 +3317,8 @@ mod tests {
|
||||
body_ref: Some("blob://provider-request-1".to_string()),
|
||||
},
|
||||
stream: false,
|
||||
client_api_format: "openai:cli".to_string(),
|
||||
provider_api_format: "openai:cli".to_string(),
|
||||
client_api_format: "openai:responses".to_string(),
|
||||
provider_api_format: "openai:responses".to_string(),
|
||||
model_name: Some("gpt-5.4".to_string()),
|
||||
proxy: None,
|
||||
tls_profile: None,
|
||||
@@ -3326,8 +3328,8 @@ mod tests {
|
||||
trace_id: "trace-sync-body-ref-1".to_string(),
|
||||
report_kind: "openai_cli_sync_success".to_string(),
|
||||
report_context: Some(json!({
|
||||
"client_api_format": "openai:cli",
|
||||
"provider_api_format": "openai:cli",
|
||||
"client_api_format": "openai:responses",
|
||||
"provider_api_format": "openai:responses",
|
||||
"trace_id": "trace-sync-body-ref-1"
|
||||
})),
|
||||
status_code: 200,
|
||||
@@ -3379,7 +3381,7 @@ mod tests {
|
||||
},
|
||||
stream: true,
|
||||
client_api_format: "openai:chat".to_string(),
|
||||
provider_api_format: "openai:cli".to_string(),
|
||||
provider_api_format: "openai:responses".to_string(),
|
||||
model_name: Some("gpt-5.4".to_string()),
|
||||
proxy: None,
|
||||
tls_profile: None,
|
||||
@@ -3390,7 +3392,7 @@ mod tests {
|
||||
report_kind: "openai_chat_stream_success".to_string(),
|
||||
report_context: Some(json!({
|
||||
"client_api_format": "openai:chat",
|
||||
"provider_api_format": "openai:cli",
|
||||
"provider_api_format": "openai:responses",
|
||||
"trace_id": "trace-stream-bytes-1"
|
||||
})),
|
||||
status_code: 200,
|
||||
@@ -3464,8 +3466,8 @@ mod tests {
|
||||
body_ref: None,
|
||||
},
|
||||
stream: true,
|
||||
client_api_format: "openai:cli".to_string(),
|
||||
provider_api_format: "openai:cli".to_string(),
|
||||
client_api_format: "openai:responses".to_string(),
|
||||
provider_api_format: "openai:responses".to_string(),
|
||||
model_name: Some("gpt-5.4".to_string()),
|
||||
proxy: None,
|
||||
tls_profile: None,
|
||||
@@ -3475,8 +3477,8 @@ mod tests {
|
||||
trace_id: "trace-stream-usage-large-1".to_string(),
|
||||
report_kind: "openai_cli_stream_success".to_string(),
|
||||
report_context: Some(json!({
|
||||
"client_api_format": "openai:cli",
|
||||
"provider_api_format": "openai:cli",
|
||||
"client_api_format": "openai:responses",
|
||||
"provider_api_format": "openai:responses",
|
||||
})),
|
||||
status_code: 200,
|
||||
headers: BTreeMap::new(),
|
||||
@@ -3531,7 +3533,7 @@ mod tests {
|
||||
})),
|
||||
stream: false,
|
||||
client_api_format: "claude:cli".to_string(),
|
||||
provider_api_format: "openai:cli".to_string(),
|
||||
provider_api_format: "openai:responses".to_string(),
|
||||
model_name: Some("gpt-5.4".to_string()),
|
||||
proxy: None,
|
||||
tls_profile: None,
|
||||
@@ -3542,7 +3544,7 @@ mod tests {
|
||||
report_kind: "claude_cli_sync_success".to_string(),
|
||||
report_context: Some(json!({
|
||||
"client_api_format": "claude:cli",
|
||||
"provider_api_format": "openai:cli",
|
||||
"provider_api_format": "openai:responses",
|
||||
"needs_conversion": true,
|
||||
"original_request_body": null,
|
||||
})),
|
||||
@@ -3585,7 +3587,7 @@ mod tests {
|
||||
body: RequestBody::from_json(json!({"model": "gpt-5.4"})),
|
||||
stream: false,
|
||||
client_api_format: "claude:cli".to_string(),
|
||||
provider_api_format: "openai:cli".to_string(),
|
||||
provider_api_format: "openai:responses".to_string(),
|
||||
model_name: Some("gpt-5.4".to_string()),
|
||||
proxy: None,
|
||||
tls_profile: None,
|
||||
@@ -3596,7 +3598,7 @@ mod tests {
|
||||
report_kind: "claude_cli_sync_success".to_string(),
|
||||
report_context: Some(json!({
|
||||
"client_api_format": "claude:cli",
|
||||
"provider_api_format": "openai:cli",
|
||||
"provider_api_format": "openai:responses",
|
||||
"needs_conversion": true,
|
||||
})),
|
||||
status_code: 200,
|
||||
|
||||
Reference in New Issue
Block a user