Codex commited on
Commit ·
86b1bf7
1
Parent(s): 8f75a35
Fill Luna completed output
Browse files- codex-luna-compat.patch +15 -6
codex-luna-compat.patch
CHANGED
|
@@ -139,10 +139,10 @@ index 697cc96..299247f 100644
|
|
| 139 |
if streamResponse.Response != nil {
|
| 140 |
diff --git a/relay/channel/openai/responses_codex_compat.go b/relay/channel/openai/responses_codex_compat.go
|
| 141 |
new file mode 100644
|
| 142 |
-
index 0000000..
|
| 143 |
--- /dev/null
|
| 144 |
+++ b/relay/channel/openai/responses_codex_compat.go
|
| 145 |
-
@@ -0,0 +1,
|
| 146 |
+package openai
|
| 147 |
+
|
| 148 |
+import (
|
|
@@ -166,6 +166,7 @@ index 0000000..00aa2f6
|
|
| 166 |
+ contentStartedBy map[string]bool
|
| 167 |
+ contentDoneBy map[string]bool
|
| 168 |
+ textByID map[string]*strings.Builder
|
|
|
|
| 169 |
+}
|
| 170 |
+
|
| 171 |
+func newCodexResponsesStreamState() *codexResponsesStreamState {
|
|
@@ -207,6 +208,9 @@ index 0000000..00aa2f6
|
|
| 207 |
+ s.nextOutputIndex = *outputIndex + 1
|
| 208 |
+ }
|
| 209 |
+ s.outputIndexByID[itemID] = *outputIndex
|
|
|
|
|
|
|
|
|
|
| 210 |
+ }
|
| 211 |
+ if outputIndex == nil && itemID != "" {
|
| 212 |
+ if idx, ok := s.outputIndexByID[itemID]; ok {
|
|
@@ -291,7 +295,13 @@ index 0000000..00aa2f6
|
|
| 291 |
+ }
|
| 292 |
+ }
|
| 293 |
+ case "response.completed", "response.done":
|
| 294 |
-
+ if event.Response != nil && len(event.Response.Output) == 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
+ text := ""
|
| 296 |
+ if builder := s.textByID[itemID]; builder != nil {
|
| 297 |
+ text = builder.String()
|
|
@@ -389,10 +399,10 @@ index 0000000..00aa2f6
|
|
| 389 |
+}
|
| 390 |
diff --git a/relay/channel/openai/responses_codex_compat_test.go b/relay/channel/openai/responses_codex_compat_test.go
|
| 391 |
new file mode 100644
|
| 392 |
-
index 0000000..
|
| 393 |
--- /dev/null
|
| 394 |
+++ b/relay/channel/openai/responses_codex_compat_test.go
|
| 395 |
-
@@ -0,0 +1,
|
| 396 |
+package openai
|
| 397 |
+
|
| 398 |
+import (
|
|
@@ -476,7 +486,6 @@ index 0000000..aa59f50
|
|
| 476 |
+
|
| 477 |
+ completed := dto.ResponsesStreamResponse{
|
| 478 |
+ Type: "response.completed",
|
| 479 |
-
+ ItemID: "item_1",
|
| 480 |
+ Response: &dto.OpenAIResponsesResponse{Model: "gemini-3.7-flash", Output: []dto.ResponsesOutput{}},
|
| 481 |
+ }
|
| 482 |
+ _, completedData, _, err := state.normalize(&completed, `{"type":"response.completed","response":{"model":"gemini-3.7-flash","output":[]}}`)
|
|
|
|
| 139 |
if streamResponse.Response != nil {
|
| 140 |
diff --git a/relay/channel/openai/responses_codex_compat.go b/relay/channel/openai/responses_codex_compat.go
|
| 141 |
new file mode 100644
|
| 142 |
+
index 0000000..c7df595
|
| 143 |
--- /dev/null
|
| 144 |
+++ b/relay/channel/openai/responses_codex_compat.go
|
| 145 |
+
@@ -0,0 +1,254 @@
|
| 146 |
+package openai
|
| 147 |
+
|
| 148 |
+import (
|
|
|
|
| 166 |
+ contentStartedBy map[string]bool
|
| 167 |
+ contentDoneBy map[string]bool
|
| 168 |
+ textByID map[string]*strings.Builder
|
| 169 |
+
+ lastMessageID string
|
| 170 |
+}
|
| 171 |
+
|
| 172 |
+func newCodexResponsesStreamState() *codexResponsesStreamState {
|
|
|
|
| 208 |
+ s.nextOutputIndex = *outputIndex + 1
|
| 209 |
+ }
|
| 210 |
+ s.outputIndexByID[itemID] = *outputIndex
|
| 211 |
+
+ if event.Item != nil && event.Item.Type == "message" {
|
| 212 |
+
+ s.lastMessageID = itemID
|
| 213 |
+
+ }
|
| 214 |
+ }
|
| 215 |
+ if outputIndex == nil && itemID != "" {
|
| 216 |
+ if idx, ok := s.outputIndexByID[itemID]; ok {
|
|
|
|
| 295 |
+ }
|
| 296 |
+ }
|
| 297 |
+ case "response.completed", "response.done":
|
| 298 |
+
+ if event.Response != nil && len(event.Response.Output) == 0 {
|
| 299 |
+
+ if itemID == "" {
|
| 300 |
+
+ itemID = s.lastMessageID
|
| 301 |
+
+ }
|
| 302 |
+
+ if itemID == "" {
|
| 303 |
+
+ break
|
| 304 |
+
+ }
|
| 305 |
+ text := ""
|
| 306 |
+ if builder := s.textByID[itemID]; builder != nil {
|
| 307 |
+ text = builder.String()
|
|
|
|
| 399 |
+}
|
| 400 |
diff --git a/relay/channel/openai/responses_codex_compat_test.go b/relay/channel/openai/responses_codex_compat_test.go
|
| 401 |
new file mode 100644
|
| 402 |
+
index 0000000..5944b97
|
| 403 |
--- /dev/null
|
| 404 |
+++ b/relay/channel/openai/responses_codex_compat_test.go
|
| 405 |
+
@@ -0,0 +1,90 @@
|
| 406 |
+package openai
|
| 407 |
+
|
| 408 |
+import (
|
|
|
|
| 486 |
+
|
| 487 |
+ completed := dto.ResponsesStreamResponse{
|
| 488 |
+ Type: "response.completed",
|
|
|
|
| 489 |
+ Response: &dto.OpenAIResponsesResponse{Model: "gemini-3.7-flash", Output: []dto.ResponsesOutput{}},
|
| 490 |
+ }
|
| 491 |
+ _, completedData, _, err := state.normalize(&completed, `{"type":"response.completed","response":{"model":"gemini-3.7-flash","output":[]}}`)
|