mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-11-21 17:32:43 +08:00
fix(openai/responses): drop response.metadata for non-Codex clients
The Codex backend now sends a response.metadata event with prompt-moderation flags. It is not a public Responses event, and clients that parse a closed event list (Grok Build 1.0.60 and 1.0.70: "unknown variant response.metadata") fail the whole turn on it. Filter it for standard Responses clients like the other private Codex events; official Codex clients still receive it.
This commit is contained in:
@@ -161,8 +161,10 @@ func (f *responsesSSEFramer) shouldFilterPrivateEvent(streamEvent, payloadType s
|
||||
return false
|
||||
}
|
||||
|
||||
// For standard Responses API clients: filter any codex.* private events.
|
||||
if strings.HasPrefix(name, "codex.") {
|
||||
// For standard Responses API clients: filter any codex.* private events, and the Codex
|
||||
// backend's moderation metadata, which is not a public Responses event: clients that parse
|
||||
// a closed event list fail on it.
|
||||
if strings.HasPrefix(name, "codex.") || name == "response.metadata" {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -625,6 +625,9 @@ func TestResponsesSSEFramer_FiltersUpstreamPrivateEvents(t *testing.T) {
|
||||
subscriptionUsageFrame := []byte("event: response.subscription_usage\ndata: {\"subscription\":{\"tier\":\"1234567890123456\",\"weekly\":{\"resets_at\":1792368000,\"used_percent\":80},\"window\":{\"resets_at\":1792272519,\"used_percent\":10,\"window_duration_mins\":300}},\"type\":\"response.subscription_usage\"}\n\n")
|
||||
framer.WriteChunk(&output, subscriptionUsageFrame)
|
||||
|
||||
moderationFrame := []byte("event: response.metadata\ndata: {\"type\":\"response.metadata\",\"metadata\":{\"openai_chatgpt_moderation_metadata\":{\"prompt\":{}}}}\n\n")
|
||||
framer.WriteChunk(&output, moderationFrame)
|
||||
|
||||
completedFrame := []byte("event: response.completed\ndata: {\"type\":\"response.completed\",\"response\":{\"id\":\"resp-1\",\"status\":\"completed\"}}\n\n")
|
||||
framer.WriteChunk(&output, completedFrame)
|
||||
|
||||
@@ -632,6 +635,9 @@ func TestResponsesSSEFramer_FiltersUpstreamPrivateEvents(t *testing.T) {
|
||||
if strings.Contains(got, "codex.rate_limits") {
|
||||
t.Fatalf("expected codex.rate_limits to be stripped, got: %q", got)
|
||||
}
|
||||
if strings.Contains(got, "event: response.metadata") || strings.Contains(got, "openai_chatgpt_moderation_metadata") {
|
||||
t.Fatalf("expected response.metadata to be stripped, got: %q", got)
|
||||
}
|
||||
if strings.Contains(got, "codex.response.metadata") {
|
||||
t.Fatalf("expected codex.response.metadata to be stripped, got: %q", got)
|
||||
}
|
||||
@@ -692,6 +698,9 @@ func TestResponsesSSEFramer_PreservesMetadataForCodexClient(t *testing.T) {
|
||||
createdFrame := []byte("event: response.created\ndata: {\"type\":\"response.created\",\"response\":{\"id\":\"resp-1\"}}\n\n")
|
||||
framer.WriteChunk(&output, createdFrame)
|
||||
|
||||
moderationFrame := []byte("event: response.metadata\ndata: {\"type\":\"response.metadata\",\"metadata\":{\"openai_chatgpt_moderation_metadata\":{\"prompt\":{}}}}\n\n")
|
||||
framer.WriteChunk(&output, moderationFrame)
|
||||
|
||||
completedFrame := []byte("event: response.completed\ndata: {\"type\":\"response.completed\",\"response\":{\"id\":\"resp-1\",\"status\":\"completed\"}}\n\n")
|
||||
framer.WriteChunk(&output, completedFrame)
|
||||
|
||||
@@ -699,6 +708,9 @@ func TestResponsesSSEFramer_PreservesMetadataForCodexClient(t *testing.T) {
|
||||
if !strings.Contains(got, "codex.response.metadata") {
|
||||
t.Fatalf("expected codex.response.metadata to be preserved for official Codex client, got: %q", got)
|
||||
}
|
||||
if !strings.Contains(got, "event: response.metadata") {
|
||||
t.Fatalf("expected response.metadata to be preserved for official Codex client, got: %q", got)
|
||||
}
|
||||
if !strings.Contains(got, "event: response.created") {
|
||||
t.Fatalf("expected response.created in output, got: %q", got)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user