Skip to content

Commit 285e2bf

Browse files
authored
fix(openai-responses): round-trip image-gen namespace (#588)
* fix(openai-responses): round-trip image-gen namespace Lower Codex's private image_gen namespace to safe API-key aliases, restore function calls in JSON and SSE responses, and encode replayed history without changing ChatGPT forward mode. * fix(openai-responses): preserve hosted image fallback Remove hosted image_generation only when a usable client alias replaces it, while retaining the hosted tool for malformed namespaces and replay-only calls. * fix(openai-responses): restore legacy image aliases Build the reverse map from explicitly declared dotted image-gen functions so safe upstream aliases return to Codex with an explicit namespace without guessing unrelated double-underscore names. * fix(responses): preserve eager relay invariant Keep the win32 eager branch free of client rewrite wrappers and align the source invariant and transport documentation with the no-client-rewrite gate. * test(responses): name SSE rewrite coverage accurately Describe the integration test as the platform-neutral passthrough rewrite path while the separate source invariant continues to guard the win32 native relay branch. * docs(codex): describe generic image aliases Document the generic image_gen__<inner-name> contract and clarify that hosted image generation is removed only after a usable client alias replaces it. * docs(i18n): sync image namespace behavior Update the Japanese, Korean, Russian, and Simplified Chinese Codex integration guides with the API-key alias, response restoration, replay, and forward-mode compatibility contract. * docs(code): clarify image alias helpers Document the request-normalization and response-restoration helper contracts without changing the deferred SSE relay structure. * fix(openai-responses): normalize image tool choices * refactor(responses): share tool-group collection
1 parent 0338b78 commit 285e2bf

16 files changed

Lines changed: 1241 additions & 103 deletions

docs-site/src/content/docs/guides/codex-integration.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ Standalone `/images/generations` calls never enter that bridge.
6363
tool offered at all, disable it in Codex with `codex features disable image_generation`
6464
(`[features] image_generation = false` in `config.toml`).
6565

66+
The tool declaration still travels with the model's Responses request. For API-key Responses
67+
providers, opencodex lowers Codex's private `image_gen` namespace to an upstream-safe
68+
`image_gen__<inner-name>` alias (for example `image_gen__imagegen`). When that usable alias replaces
69+
the client declaration, opencodex removes a duplicate hosted `image_generation` declaration. It maps
70+
the function call to the explicit `image_gen` namespace before Codex sees it, and encodes the native
71+
call again when later history is replayed upstream. This keeps client-side image generation callable
72+
on public-compatible upstreams that reserve the namespace or reject dotted function names. ChatGPT
73+
forward mode remains untouched and keeps its native Responses Lite shape.
74+
6675
For an OpenAI-compatible custom gateway, configure a dedicated provider and select it only for
6776
standalone Images requests:
6877

docs-site/src/content/docs/ja/guides/codex-integration.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ ChatGPT bearer 認証で直接 POST します。注入された `base_url` が o
5757
`codex features disable image_generation`(`config.toml``[features] image_generation = false`)を
5858
使ってください。
5959

60+
ツール宣言はモデルへの Responses リクエストにも引き続き含まれます。API キー方式の Responses
61+
プロバイダーでは、opencodex は Codex のプライベートな `image_gen` 名前空間を、上流で安全な
62+
`image_gen__<inner-name>` エイリアス(例: `image_gen__imagegen`)に変換します。その利用可能な
63+
エイリアスがクライアント宣言を置き換える場合にのみ、重複する hosted `image_generation` 宣言を
64+
削除します。関数呼び出しは Codex に届く前に明示的な `image_gen` 名前空間へ戻され、後続の履歴を
65+
上流へ再送するときは再びエンコードされます。これにより、名前空間を予約している、またはドットを
66+
含む関数名を拒否する OpenAI 互換の上流でも、クライアント側の画像生成を呼び出せます。ChatGPT
67+
forward モードは変更されず、ネイティブな Responses Lite 形式を維持します。
68+
6069
`hostname` がループバックアドレスでない場合、Codex が自動生成した API 認証ヘッダーを送る必要があります。このとき専用
6170
プロバイダーを注入します。
6271

docs-site/src/content/docs/ko/guides/codex-integration.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ ChatGPT bearer 인증으로 직접 POST합니다. 주입된 `base_url`이 openco
5656
`codex features disable image_generation`(`config.toml``[features] image_generation = false`)을
5757
사용하세요.
5858

59+
도구 선언은 모델의 Responses 요청에도 계속 포함됩니다. API key 방식 Responses 프로바이더에서는
60+
opencodex가 Codex의 비공개 `image_gen` namespace를 업스트림에서 안전한
61+
`image_gen__<inner-name>` alias(예: `image_gen__imagegen`)로 변환합니다. 이 사용 가능한 alias가
62+
클라이언트 선언을 대체할 때만 중복된 hosted `image_generation` 선언을 제거합니다. 함수 호출은
63+
Codex에 도달하기 전에 명시적인 `image_gen` namespace로 복원되고, 이후 기록을 업스트림으로
64+
replay할 때 다시 인코딩됩니다. 따라서 namespace를 예약하거나 점이 포함된 함수 이름을 거부하는
65+
OpenAI 호환 업스트림에서도 클라이언트 측 이미지 생성을 호출할 수 있습니다. ChatGPT forward
66+
모드는 변경되지 않으며 네이티브 Responses Lite 형식을 유지합니다.
67+
5968
`hostname`이 loopback 주소가 아니면 Codex가 자동 생성된 API 인증 헤더를 보내야 합니다. 이때는 전용
6069
프로바이더를 주입합니다.
6170

docs-site/src/content/docs/ru/guides/codex-integration.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ fast_mode = true
6464
командой `codex features disable image_generation`
6565
(`[features] image_generation = false` в `config.toml`).
6666

67+
Объявление инструмента по-прежнему передаётся в Responses-запросе к модели. Для Responses-
68+
провайдеров с API-ключом opencodex преобразует приватное пространство имён Codex `image_gen`
69+
в безопасный для вышестоящей стороны псевдоним `image_gen__<inner-name>` (например,
70+
`image_gen__imagegen`). Дублирующее объявление hosted-инструмента `image_generation` удаляется
71+
только тогда, когда такой рабочий псевдоним заменяет клиентское объявление. Перед передачей в
72+
Codex вызов функции восстанавливается с явным пространством имён `image_gen`, а при последующем
73+
воспроизведении истории во вышестоящий сервис снова кодируется. Это сохраняет клиентскую
74+
генерацию изображений у OpenAI-совместимых провайдеров, которые резервируют это пространство
75+
имён или отклоняют имена функций с точками. Режим ChatGPT forward не изменяется и сохраняет
76+
свой нативный формат Responses Lite.
77+
6778
Если `hostname` не является loopback-адресом, Codex должен отправлять сгенерированный заголовок
6879
API-аутентификации. Поэтому инжектор в этом случае использует выделенного провайдера:
6980

docs-site/src/content/docs/zh-cn/guides/codex-integration.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ OpenAI 上游:
5454
`codex features disable image_generation`(即 `config.toml`
5555
`[features] image_generation = false`)。
5656

57+
工具声明仍会随模型的 Responses 请求一同发送。对于 API key 方式的 Responses 提供商,
58+
opencodex 会把 Codex 私有的 `image_gen` namespace 转换为上游安全的
59+
`image_gen__<inner-name>` alias(例如 `image_gen__imagegen`)。只有当这个可用 alias 替代了
60+
客户端声明时,才会移除重复的 hosted `image_generation` 声明。函数调用会在到达 Codex 前恢复为
61+
显式的 `image_gen` namespace,后续将历史记录重放到上游时再重新编码。因此,即使 OpenAI 兼容
62+
上游保留了该 namespace,或拒绝包含点号的函数名,客户端图像生成仍可正常调用。ChatGPT forward
63+
模式保持不变,并继续使用其原生 Responses Lite 格式。
64+
5765
如果 `hostname` 不是 loopback 地址,Codex 必须发送自动生成的 API 认证请求头。此时注入器会改用
5866
专用提供商:
5967

0 commit comments

Comments
 (0)