codex-grok-bridge 1.7.2 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +80 -14
- package/package.json +5 -1
- package/src/bridge.mjs +99 -2
- package/src/imagine.mjs +42 -8
- package/src/realtime.mjs +212 -0
- package/src/runtime.mjs +3 -0
- package/src/tools.mjs +193 -20
- package/src/videogen.mjs +157 -8
- package/src/voice.mjs +1359 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.8.0 — 2026-10-02
|
|
4
|
+
|
|
5
|
+
- When xAI rejects a Codex voice offer on `POST /v1/realtime/calls` or `POST /v1/live`, the bridge reads the SDP part of the multipart body, whether the parts use CRLF or LF, and answers locally with werift. Opus is used when that is the offered codec. Audio is bridged to the xAI voice socket. The sideband for that answered call stays on the bridge. An offer the local peer cannot answer stays the upstream response. An offer xAI accepts is still forwarded. Codex cloud tasks are not in this package.
|
|
6
|
+
- Runtime dependencies are `werift` 0.24.4 and `opusscript` 0.1.1. There is still no `XAI_API_KEY`.
|
|
7
|
+
- Codex image `size` is sent to Imagine as `aspect_ratio` (`1024x1024` → `1:1`, `1536x1024` → `3:2`, `1024x1536` → `2:3`) for new pictures and edits. `quality: high` is `2k`, `low` is `1k`, and `auto` omits resolution. `n` is capped at 10. A local file path on an image edit is refused.
|
|
8
|
+
- A generated image is saved once. The completed response carries that file note instead of the raw image bytes.
|
|
9
|
+
- `grok_bridge_generate_video` accepts `480p`, `720p`, or `1080p`. A bad duration, aspect ratio, resolution, or local image path is rejected without calling the API. The finished clip is downloaded, without the login bearer, into `~/.local/share/codex-grok-bridge/generated-videos/`. The tool result names the temporary URL and the saved file. A moderation withhold is a tool message, not a failed turn. If the download fails, the result is still the URL.
|
|
10
|
+
- A custom tool call that comes back under its Codex name is restored when that name belongs to one tool, including streamed argument events and the completed response output. A custom tool result is restored even when it only has a call id.
|
|
11
|
+
- A function result that arrives as a list of content parts is forwarded as text. A remote image URL in that list is included. An inline PNG, JPEG, or WebP is attached after the tool result so the model can see it.
|
|
12
|
+
- A previous web search keeps its query and the pages it found.
|
|
13
|
+
- Command stdout, stderr, or an aggregated log stays in the forwarded history, with a non-zero exit code.
|
|
14
|
+
- A chat audio attachment is replaced with an explanation so its bytes do not reject the turn.
|
|
15
|
+
- When a reasoning summary is empty, plain text in the reasoning content is forwarded. Encrypted reasoning stays dropped.
|
|
16
|
+
|
|
3
17
|
## 1.7.2 — 2026-09-30
|
|
4
18
|
|
|
5
19
|
- Readable compaction summaries are passed through as user messages. A compaction item that only carries encrypted or internal fields is still dropped.
|
package/README.md
CHANGED
|
@@ -42,6 +42,16 @@ the bridge runs. See Release history.
|
|
|
42
42
|
|
|
43
43
|
What each recent version added. Older cuts are in `CHANGELOG.md`.
|
|
44
44
|
|
|
45
|
+
### 1.8.0 — 2026-10-02
|
|
46
|
+
|
|
47
|
+
- When xAI rejects a Codex voice offer, the bridge reads the SDP part of the multipart body (CRLF or LF) and answers locally with werift, including Opus when that is the offered codec. Audio is bridged to the xAI voice socket, and that call's sideband stays on the bridge. An offer xAI accepts is still forwarded. Codex cloud tasks are not in this package.
|
|
48
|
+
- Runtime dependencies are `werift` 0.24.4 and `opusscript` 0.1.1. No `XAI_API_KEY`.
|
|
49
|
+
- Codex image `size` maps to Imagine `aspect_ratio` on new pictures and edits. `quality: high` is `2k`, `low` is `1k`, and `auto` omits resolution. `n` is capped at 10. A local file path on an image edit is refused.
|
|
50
|
+
- A generated image is saved once, and the completed response carries that file note.
|
|
51
|
+
- Video generation accepts `480p`, `720p`, or `1080p`. The finished clip is saved under `~/.local/share/codex-grok-bridge/generated-videos/` without the login bearer. The tool result names the URL and the file.
|
|
52
|
+
- Custom tool names and results are restored, including a result that only has a call id. Function results that arrive as content parts are forwarded as text, with an inline PNG, JPEG, or WebP attached so the model can see it.
|
|
53
|
+
- A previous web search keeps its query and the pages it found. Command output and a non-zero exit code stay in history. A chat audio attachment is replaced with an explanation. An empty reasoning summary falls back to plain reasoning text.
|
|
54
|
+
|
|
45
55
|
### 1.7.2 — 2026-09-30
|
|
46
56
|
|
|
47
57
|
- Readable compaction summaries are passed through as user messages. A compaction item that only carries encrypted or internal fields is still dropped.
|
|
@@ -171,7 +181,11 @@ before any of it is sent.
|
|
|
171
181
|
Codex keeps the conversation and sends the whole turn each time. Grok can
|
|
172
182
|
treat the unchanged beginning as a cache. If the connection drops before
|
|
173
183
|
Codex has been sent any bytes, the bridge tries again. Codex does not send
|
|
174
|
-
that same request again. Voice
|
|
184
|
+
that same request again. Voice call setup (`POST /v1/realtime/calls` and
|
|
185
|
+
`POST /v1/live`) is forwarded raw when xAI accepts it. When xAI rejects that
|
|
186
|
+
offer, the bridge reads the SDP part of Codex's multipart body, whether the parts use CRLF or LF, answers with
|
|
187
|
+
its own WebRTC peer, including Opus when that is the offered codec, and
|
|
188
|
+
bridges the audio to the xAI voice socket. Microphone audio is held until `session.updated`, up to two seconds of it, and released after 2 seconds if that ack never arrives. A resumed socket waits for its own `session.updated` again. Requests queued on the old socket are dropped, so the new `session.update` goes out first. Audio still waiting to play is dropped with that socket, and the resumed session is told how much was already sent. It does not keep the previous interrupt or a deferred `response.create`, and later audio still plays. Voice audio accepts `response.output_audio.delta` and `response.audio.delta`, fields `delta` or `audio`. A reply shorter than one audio frame is still sent when the turn ends. Playback is paced at one Opus frame per 20 ms. When the user starts speaking, playback of the current reply stops, and a waiting tool reply is held until they stop. A transcript that arrives after that stop is not shown, and the turn closes on the words already sent. Once that caption has closed, the next user utterance leaves the following reply's words visible. Audio that arrives after that reply ends stays silent until the next response starts. A desktop `response.cancel` stops that playback too, without holding later tool replies for speech that did not start. A reply already waiting stays held if the user is still speaking. If playback was still queued, the assistant item is truncated to the audio already sent. A tool reply waits until the voice response is done and queued playback has been sent. If the socket drops first, that reply is sent after the resumed session is ready. A `response.create` that races an active response is sent again after that response finishes, and after any tool reply that was waiting. The answer is the DTLS server and lists only this machine's host addresses, including 127.0.0.1, as plain host candidates, so the desktop voice helper opens its event channel. The sideband for that answered call stays on the bridge. A dropped voice socket redials once on the same xAI conversation (resumption enabled). A second drop tells the desktop "Voice connection closed." An intentional hangup does not. A recoverable xAI error does not, because the desktop would end the call. The first sideband event is `session.updated`, sent when the desktop connects so the call is not held for the xAI session ack. `session.close` from the desktop hangs up without waiting for TCP. xAI transcript events are rewritten into the desktop v3 sideband names. Text replies from `response.output_text.delta` and `response.text.delta` use that same transcript. The chunk may be in `delta` or `text`. If the audio transcript never sends a done event, `response.done` still closes the turn. A new user utterance closes the previous user caption when its completed event never arrived. A later completed event for that same caption is not sent again. The call's session instructions and earlier messages are kept. Developer history from the call is added to those instructions and kept on a later session update. If the call asks for a delegation acknowledgement, those instructions say to speak one short sentence before calling `codex`. A later session update keeps that sentence. Split context appends are joined. A streamed codex reply is spoken once after a pause. Several codex results that finish together are all sent before the spoken reply, or before one continuation. If that spoken turn is rejected before it starts, the next reply is not left waiting. Commentary closes the tool without being read aloud. `[STATUS]` does not finish the call. A `codex` tool call becomes the desktop handoff.
|
|
175
189
|
Codex cloud tasks are not in this package.
|
|
176
190
|
|
|
177
191
|
If the Responses path misbehaves, `GROK_BRIDGE_INFERENCE=cli` falls back to the
|
|
@@ -211,7 +225,9 @@ not read Codex’s `imagegen` skill and do not send the picture to OpenAI.
|
|
|
211
225
|
|
|
212
226
|
### Reasoning
|
|
213
227
|
|
|
214
|
-
Plain-text summaries on Codex `reasoning` items are forwarded.
|
|
228
|
+
Plain-text summaries on Codex `reasoning` items are forwarded. When that
|
|
229
|
+
summary is empty, plain text in the reasoning content is forwarded instead.
|
|
230
|
+
Encrypted
|
|
215
231
|
`encrypted_content` and Codex’s own item ids are stripped. This is so a
|
|
216
232
|
multi-call turn can continue its own reasoning. The upstream has been observed
|
|
217
233
|
to accept this shape. The same pass keeps only the fields Grok’s Responses
|
|
@@ -230,9 +246,17 @@ that overlap the parent turn.
|
|
|
230
246
|
### Tools
|
|
231
247
|
|
|
232
248
|
Ordinary function tools, namespaced function tools, and freeform custom tools
|
|
233
|
-
are translated.
|
|
234
|
-
|
|
235
|
-
|
|
249
|
+
are translated. A custom tool call that comes back under the Codex name is
|
|
250
|
+
restored when that name belongs to one tool. The same name is restored on a
|
|
251
|
+
streamed arguments event and inside the completed response output. A custom
|
|
252
|
+
tool result is restored too, including when it only carries the call id. A function result that arrives as a list of content parts is
|
|
253
|
+
forwarded as text. A remote image URL in that list is included. An inline
|
|
254
|
+
PNG, JPEG, or WebP is attached after the tool result so the model can see it.
|
|
255
|
+
A previous web search keeps its query and the page URLs it found. Command output
|
|
256
|
+
in stdout, stderr, or an aggregated log stays in the history. A non-zero exit
|
|
257
|
+
code stays with that output. File edits, MCP,
|
|
258
|
+
and similar work inside whatever Codex exposed, at whatever approval policy the
|
|
259
|
+
user set. Not every tool has been live-tested individually.
|
|
236
260
|
|
|
237
261
|
### Image attachments (vision)
|
|
238
262
|
|
|
@@ -244,11 +268,13 @@ One unusable attachment no longer kills the conversation. The bridge walks the
|
|
|
244
268
|
whole history; a single over-limit image used to make every later turn fail
|
|
245
269
|
with 400. Now that attachment is replaced with an explanation and the rest
|
|
246
270
|
goes through. Usable images stay `input_image` (Grok reads them). Remote URLs
|
|
247
|
-
are not fetched.
|
|
271
|
+
are not fetched. An audio attachment is replaced with an explanation so its
|
|
272
|
+
bytes do not reject the turn.
|
|
248
273
|
|
|
249
274
|
### Image generation
|
|
250
275
|
|
|
251
|
-
|
|
276
|
+
A generated image is saved once. The completed response carries that same
|
|
277
|
+
file note instead of the raw image bytes. The bridge declares `{ type: "image_generation" }` on the upstream request.
|
|
252
278
|
Codex does not offer an image-generation tool to this provider (263 tools, none
|
|
253
279
|
of them generate — `view_image` only), so without the declaration Codex’s
|
|
254
280
|
`imagegen` skill falls back to OpenAI (`image_gen` or `OPENAI_API_KEY` +
|
|
@@ -277,6 +303,13 @@ The bridge inspects the saved file. If there is no alpha channel it tells the
|
|
|
277
303
|
model not to describe the picture as transparent. If you need a real alpha
|
|
278
304
|
channel or accurate inpainting, use Codex’s OpenAI path.
|
|
279
305
|
|
|
306
|
+
### Video generation
|
|
307
|
+
|
|
308
|
+
A finished clip is a temporary URL. The bridge downloads that file, without
|
|
309
|
+
the login bearer, into `~/.local/share/codex-grok-bridge/generated-videos/`
|
|
310
|
+
and the tool result names both the URL and the saved file. If the download
|
|
311
|
+
fails, the result is still the URL.
|
|
312
|
+
|
|
280
313
|
### GPT ↔ Grok switching
|
|
281
314
|
|
|
282
315
|
Supported on an idle persisted root thread. `turn/start`,
|
|
@@ -290,7 +323,7 @@ starting a new thread, before the first turn is saved.
|
|
|
290
323
|
|
|
291
324
|
### Not in this release
|
|
292
325
|
|
|
293
|
-
|
|
326
|
+
A voice session still depends on the xAI voice socket accepting the login, and on the desktop completing ICE with the bridge. Codex cloud tasks are not in this package.
|
|
294
327
|
|
|
295
328
|
Upstream sometimes resets the connection mid-response (three measured cases:
|
|
296
329
|
25 s / 27 s / 253 s, 726 KB–22 MB). The bridge holds the reply and, if that
|
|
@@ -422,6 +455,16 @@ Codex `web_search`는 브리지가 실행하는 함수가 아니라 xAI 서버
|
|
|
422
455
|
|
|
423
456
|
최근 버전이 더한 것입니다. 그 이전은 `CHANGELOG.md`에 있습니다.
|
|
424
457
|
|
|
458
|
+
### 1.8.0 — 2026-10-02
|
|
459
|
+
|
|
460
|
+
- xAI가 Codex 음성 offer를 거절하면 브리지가 multipart 본문의 SDP를 읽습니다. 파트 구분이 CRLF든 LF든 같습니다. werift로 로컬에서 답하고, offer가 Opus이면 Opus로 답합니다. 오디오는 xAI 음성 소켓으로 잇고, 그 통화의 sideband는 브리지에 남습니다. xAI가 수락한 offer는 그대로 넘깁니다. Codex 클라우드 작업은 이 패키지에 없습니다.
|
|
461
|
+
- 런타임 의존성은 `werift` 0.24.4와 `opusscript` 0.1.1입니다. `XAI_API_KEY`는 쓰지 않습니다.
|
|
462
|
+
- Codex 이미지 `size`는 새 그림과 편집 모두 Imagine `aspect_ratio`로 보냅니다. `quality: high`는 `2k`, `low`는 `1k`이고, `auto`는 해상도를 비웁니다. `n`은 최대 10장입니다. 이미지 편집의 로컬 파일 경로는 거절합니다.
|
|
463
|
+
- 생성된 이미지는 한 번만 저장하고, 완료된 응답에는 그 파일 설명을 실습니다.
|
|
464
|
+
- 영상 생성은 `480p`, `720p`, `1080p`를 받습니다. 끝난 클립은 로그인 베어러 없이 `~/.local/share/codex-grok-bridge/generated-videos/`에 저장하고, 도구 결과에는 URL과 파일을 함께 넣습니다.
|
|
465
|
+
- 커스텀 도구 이름과 결과를 다시 맞춥니다. call id만 있는 결과도 맞춥니다. 내용 목록으로 온 함수 결과는 텍스트로 넘기고, 인라인 PNG·JPEG·WebP는 모델이 보게 붙입니다.
|
|
466
|
+
- 이전 웹 검색은 질의와 찾은 페이지를 남깁니다. 명령 출력과 0이 아닌 종료 코드도 이력에 남습니다. 채팅 오디오 첨부는 설명으로 바꿉니다. reasoning 요약이 비어 있으면 평문 내용을 넘깁니다.
|
|
467
|
+
|
|
425
468
|
### 1.7.2 — 2026-09-30
|
|
426
469
|
|
|
427
470
|
- 읽을 수 있는 compaction 요약을 사용자 메시지로 넘깁니다. 암호화된 내용이나 내부 필드만 있는 compaction 항목은 그대로 버립니다.
|
|
@@ -546,7 +589,12 @@ Codex 창에도 보일 수 있습니다.
|
|
|
546
589
|
Codex가 대화를 갖고 있고, 턴마다 그 턴 전체를 보냅니다. 앞부분이 그대로면
|
|
547
590
|
Grok는 그 부분을 캐시로 볼 수 있습니다. Codex에 바이트를 보내기 전에 연결이
|
|
548
591
|
끊기면 브리지가 다시 시도합니다. Codex는 그 요청을 또 보내지 않습니다. 음성
|
|
549
|
-
|
|
592
|
+
통화 설정(`POST /v1/realtime/calls`, `POST /v1/live`)은 xAI가 수락하면 원문
|
|
593
|
+
그대로 넘깁니다. xAI가 그 offer를 거절하면 브리지가 Codex multipart 본문에서 SDP를 읽습니다. 파트 구분이 CRLF든 LF든 같습니다.
|
|
594
|
+
자체 WebRTC 피어로 답합니다. offer가 Opus이면 Opus로 답하고, 오디오를 xAI
|
|
595
|
+
음성 소켓으로 잇습니다. 마이크 오디오는 `session.updated`까지 최대 2초분을 붙들고, 그 확인이 없으면 2초 뒤에 보냅니다. 다시 붙은 소켓은 자기 `session.updated`를 다시 기다립니다. 이전 소켓에 쌓인 요청은 버리고, 새 `session.update`를 먼저 보냅니다. 아직 재생되지 않은 음성도 그 소켓과 함께 버리고, 이미 보낸 길이는 다시 붙은 세션에 알립니다. 이전 말끊기나 미뤄 둔 `response.create`는 따라가지 않고, 이후 음성은 재생됩니다. 음성 오디오는 `response.output_audio.delta`와 `response.audio.delta`를 받으며, 필드는 `delta` 또는 `audio`입니다. 한 프레임보다 짧은 답도 턴이 끝나면 보냅니다. 재생은 Opus 프레임을 20 ms마다 하나씩 보냅니다. 사용자가 말하기 시작하면 현재 답의 재생을 멈추고, 기다리던 도구 답은 말이 끝날 때까지 붙듭니다. 그 뒤에 도착한 자막은 보내지 않고, 이미 보낸 말로 턴을 닫습니다. 그 자막이 닫힌 뒤에는 다음 답의 말을 숨기지 않습니다. 그 답이 끝난 뒤의 음성은 다음 응답이 시작되기 전에는 재생하지 않습니다. 데스크톱의 `response.cancel`도 재생을 멈추며, 말하지 않은 뒤의 도구 답은 붙들지 않습니다. 이미 기다리던 답은 사용자가 아직 말하는 동안 붙듭니다. 재생이 아직 남아 있으면 어시스턴트 항목은 이미 보낸 음성 길이까지만 남깁니다. 도구 답은 음성 응답이 끝나고 대기 중인 재생을 보낸 뒤에 나갑니다. 그 전에 소켓이 끊기면, 다시 붙은 세션이 준비된 뒤에 보냅니다. 진행 중인 응답과 겹친 `response.create`는 기다리던 도구 답 다음에, 그 응답이 끝난 뒤에 다시 보냅니다. 답변은 DTLS 서버이고, 이 기기의 호스트 주소만 넣으며 127.0.0.1도
|
|
596
|
+
일반 호스트 후보로 포함해서, 데스크톱 음성 헬퍼가 이벤트 채널을 엽니다. 그렇게 답한 통화의 sideband는 브리지에
|
|
597
|
+
남습니다. 끊긴 음성 소켓은 같은 xAI 대화로 한 번 다시 연결합니다(resumption 사용). 두 번째로 끊기면 데스크톱에 “Voice connection closed.”를 알립니다. 의도한 종료는 알리지 않습니다. 복구 가능한 xAI 오류는 알리지 않습니다. 데스크톱이 통화를 끝내기 때문입니다. sideband가 연결되면 바로 `session.updated`를 보내 xAI 세션 확인을 기다리지 않습니다. 데스크톱의 `session.close`는 TCP를 기다리지 않고 통화를 끊습니다. xAI 전사 이벤트는 데스크톱 v3 sideband가 읽는 이름으로 바꿉니다. `response.output_text.delta`와 `response.text.delta` 텍스트 답도 같은 자막으로 보냅니다. 조각은 `delta` 또는 `text`에 있을 수 있습니다. 음성 자막의 완료 이벤트가 없어도 `response.done`이 그 턴을 닫습니다. 사용자가 다시 말하기 시작하면, 완료 이벤트가 없던 이전 사용자 자막도 닫습니다. 그 자막의 늦은 완료 이벤트는 다시 보내지 않습니다. 통화의 세션 지시문과 이전 메시지는 유지합니다. 개발자 이력은 그 지시문에 넣고, 나중 세션 갱신에도 남깁니다. 도구 호출 전에 짧게 말하라는 설정이 있으면, `codex`를 부르기 전에 한 문장을 말하도록 지시문에 넣습니다. 나중 세션 갱신에도 그 문장을 남깁니다. 나뉜 문맥 추가는 이어 붙입니다. 스트리밍된 codex 답은 잠시 멈춘 뒤 한 번만 말합니다. 같이 끝난 여러 codex 결과는 말을 잇기 전에 모두 보냅니다. 말로 읽는 답이 시작 전에 거절되면 다음 답은 기다리지 않습니다. commentary는 소리 내 읽지 않고 도구를 닫습니다. `[STATUS]`는 통화를 끝내지 않습니다. `codex` 도구 호출은 데스크톱 handoff가 됩니다. Codex 클라우드 작업은 이 패키지에 없습니다.
|
|
550
598
|
|
|
551
599
|
Responses 경로가 이상하면 `GROK_BRIDGE_INFERENCE=cli`로 이전 CLI 봉투 경로를
|
|
552
600
|
씁니다. 매 턴 전체 JSON을 프롬프트로 넣으므로 더 느리고 비싸며, 토큰 단위
|
|
@@ -582,7 +630,8 @@ OpenAI로 보내지 말라는 뜻입니다. `GROK_BRIDGE_IMAGE_GEN=off`면 도
|
|
|
582
630
|
|
|
583
631
|
### reasoning
|
|
584
632
|
|
|
585
|
-
Codex `reasoning` 항목의 평문 요약은 상류로 전달합니다.
|
|
633
|
+
Codex `reasoning` 항목의 평문 요약은 상류로 전달합니다. 요약이 비어 있으면
|
|
634
|
+
내용의 평문을 대신 전달합니다. 암호화된
|
|
586
635
|
`encrypted_content`와 Codex 자체 아이템 id는 제거합니다. 여러 번 호출이 이어지는
|
|
587
636
|
턴에서 모델이 자기 추론을 이어받게 하기 위한 것이며, 상류가 이 형태를 수락하는
|
|
588
637
|
것을 확인했습니다. 같은 과정에서 아이템과 content part는 Grok Responses가
|
|
@@ -598,7 +647,15 @@ Codex `reasoning` 항목의 평문 요약은 상류로 전달합니다. 암호
|
|
|
598
647
|
|
|
599
648
|
### 도구
|
|
600
649
|
|
|
601
|
-
일반 함수 도구, namespace 함수 도구, freeform 커스텀 도구를 변환합니다.
|
|
650
|
+
일반 함수 도구, namespace 함수 도구, freeform 커스텀 도구를 변환합니다. 커스텀
|
|
651
|
+
도구 호출이 Codex 이름으로 돌아와도, 그 이름이 도구 하나뿐이면 다시 맞춥니다.
|
|
652
|
+
스트리밍된 인자 이벤트와 완료된 응답 목록의 이름도 같이 맞춥니다. 커스텀
|
|
653
|
+
도구 결과도 맞추며, call id만 있어도 맞춥니다. 내용
|
|
654
|
+
목록으로 온 함수 결과는 텍스트로 넘깁니다. 원격 이미지 주소는 그 글에
|
|
655
|
+
넣고, 인라인 PNG·JPEG·WebP는 도구 결과 뒤에 붙여 모델이 보게 합니다. 이전
|
|
656
|
+
웹 검색은 질의와 찾은 페이지 주소를 이력에 남깁니다. stdout,
|
|
657
|
+
stderr, 합쳐진 명령 출력도 이력에 남습니다. 0이 아닌 종료 코드도 그 출력과
|
|
658
|
+
함께 남습니다. 파일
|
|
602
659
|
변경·MCP 등은 Codex가 노출한 도구와 사용자가 정한 승인 정책 안에서 동작합니다.
|
|
603
660
|
개별 기능을 모두 실검증한 것은 아닙니다.
|
|
604
661
|
|
|
@@ -612,11 +669,13 @@ PNG / JPEG / WebP. **이미지당 10 MiB, 요청 전체 20 MiB**, 서로 다른
|
|
|
612
669
|
때문에, 예전에는 한도를 넘는 이미지가 히스토리에 한 번 들어가면 이후 모든 턴이
|
|
613
670
|
영구히 400이었습니다. 지금은 그 첨부만 이유를 밝힌 텍스트로 바꾸고 나머지는
|
|
614
671
|
그대로 보냅니다. 쓸 수 있는 이미지는 `input_image` 그대로 넘어가며 Grok가 직접
|
|
615
|
-
읽습니다. 원격 URL은 가져오지 않습니다.
|
|
672
|
+
읽습니다. 원격 URL은 가져오지 않습니다. 오디오 첨부는 설명으로 바꿔서, 그
|
|
673
|
+
바이트가 턴을 거절하지 않게 합니다.
|
|
616
674
|
|
|
617
675
|
### 이미지 생성
|
|
618
676
|
|
|
619
|
-
|
|
677
|
+
생성된 이미지는 한 번만 저장하고, 완료된 응답에는 그 파일 설명을 실어 원본
|
|
678
|
+
바이트를 남기지 않습니다. 브리지가 상류 요청에 `{ type: "image_generation" }`을 직접 선언합니다. Codex는
|
|
620
679
|
이 프로바이더에 이미지 생성 도구를 주지 않습니다(263개 중 없음, `view_image`
|
|
621
680
|
뿐). 선언이 없으면 Codex `imagegen` 스킬이 OpenAI 경로(`image_gen` 또는
|
|
622
681
|
`OPENAI_API_KEY` + `gpt-image-*`)로 가서, 추론은 Grok인데 그림만 다른 벤더가
|
|
@@ -644,6 +703,13 @@ Grok의 `image_generation`은 텍스트→이미지만 제대로 됩니다.
|
|
|
644
703
|
설명하지 말라고 적습니다. 진짜 알파나 정확한 인페인팅이 필요하면 Codex의
|
|
645
704
|
OpenAI 경로가 맞습니다.
|
|
646
705
|
|
|
706
|
+
### 영상 생성
|
|
707
|
+
|
|
708
|
+
끝난 클립은 임시 URL입니다. 브리지는 로그인 베어러 없이 그 파일을
|
|
709
|
+
`~/.local/share/codex-grok-bridge/generated-videos/`에 받고, 도구 결과에는
|
|
710
|
+
URL과 저장한 파일 경로를 함께 넣습니다. 다운로드가 실패하면 결과는 URL만
|
|
711
|
+
남습니다.
|
|
712
|
+
|
|
647
713
|
### GPT ↔ Grok 전환
|
|
648
714
|
|
|
649
715
|
대기 중인 저장된 루트 작업에서만 됩니다. `turn/start`,
|
|
@@ -656,7 +722,7 @@ OpenAI 경로가 맞습니다.
|
|
|
656
722
|
|
|
657
723
|
### 이번 릴리스에 없는 것
|
|
658
724
|
|
|
659
|
-
음성
|
|
725
|
+
음성 세션은 xAI 음성 소켓이 로그인을 수락하는지, 그리고 데스크톱이 브리지와 ICE를 끝내는지를 따릅니다. Codex 클라우드 작업은 이 패키지에 없습니다.
|
|
660
726
|
|
|
661
727
|
상류가 응답 중간에 연결을 리셋하는 경우가 있습니다(실측 3건: 25초 / 27초 /
|
|
662
728
|
253초, 726 KB–22 MB). 브리지는 응답을 들고 있다가, Codex에 그 응답을 보내기
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codex-grok-bridge",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Run Grok 4.7 as the model inside Codex, with Codex still owning tools, permissions, history and MCP. Uses the grok login session, not an API key.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,5 +51,9 @@
|
|
|
51
51
|
"prepublishOnly": "npm test",
|
|
52
52
|
"test": "node --test",
|
|
53
53
|
"test:coverage": "node --test --experimental-test-coverage --test-coverage-include='src/*.mjs' --test-coverage-lines=80 --test-coverage-functions=80 --test-coverage-branches=80"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"opusscript": "0.1.1",
|
|
57
|
+
"werift": "0.24.4"
|
|
54
58
|
}
|
|
55
59
|
}
|
package/src/bridge.mjs
CHANGED
|
@@ -11,6 +11,15 @@ import {
|
|
|
11
11
|
import { emitProxySse, readRelayProxySse } from "./proxy.mjs";
|
|
12
12
|
import { videoCallsFromParts, videoToolOutput } from "./videogen.mjs";
|
|
13
13
|
import { forwardImagine } from "./imagine.mjs";
|
|
14
|
+
import { attachSidebandUpgrade, forwardRealtime } from "./realtime.mjs";
|
|
15
|
+
import {
|
|
16
|
+
answerVoiceCall,
|
|
17
|
+
developerTextFromCallBody,
|
|
18
|
+
initialItemsFromCallBody,
|
|
19
|
+
instructionsFromCallBody,
|
|
20
|
+
ackFillerFromCallBody,
|
|
21
|
+
offerFromCallBody,
|
|
22
|
+
} from "./voice.mjs";
|
|
14
23
|
import {
|
|
15
24
|
applyCacheUsage,
|
|
16
25
|
createPrefixMemory,
|
|
@@ -108,6 +117,84 @@ async function relayImagine(req, res, json, kind, options) {
|
|
|
108
117
|
}
|
|
109
118
|
}
|
|
110
119
|
|
|
120
|
+
function requestSearch(url) {
|
|
121
|
+
const query = String(url ?? "").indexOf("?");
|
|
122
|
+
return query === -1 ? "" : String(url).slice(query);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function relayRealtime(req, res, json, upstreamPath, options) {
|
|
126
|
+
const controller = new AbortController();
|
|
127
|
+
res.on("close", () => controller.abort());
|
|
128
|
+
const chunks = [];
|
|
129
|
+
let size = 0;
|
|
130
|
+
const limit = options.maxBodyBytes ?? 40 * 1024 * 1024;
|
|
131
|
+
try {
|
|
132
|
+
for await (const chunk of req) {
|
|
133
|
+
size += chunk.length;
|
|
134
|
+
if (size > limit) return json(413, { error: "Request too large" });
|
|
135
|
+
chunks.push(chunk);
|
|
136
|
+
}
|
|
137
|
+
} catch {
|
|
138
|
+
if (!res.writableEnded && !res.destroyed) json(400, { error: "Invalid request" });
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
try {
|
|
142
|
+
const session = options.grokSession ?? readGrokBearerToken(options.grokHome);
|
|
143
|
+
const forwarded = await forwardRealtime({
|
|
144
|
+
path: upstreamPath,
|
|
145
|
+
search: requestSearch(req.url),
|
|
146
|
+
body: Buffer.concat(chunks),
|
|
147
|
+
contentType: req.headers["content-type"],
|
|
148
|
+
token: session.token,
|
|
149
|
+
fetchImpl: options.realtimeFetch,
|
|
150
|
+
baseUrl: options.realtimeBaseUrl,
|
|
151
|
+
signal: controller.signal,
|
|
152
|
+
});
|
|
153
|
+
if (res.writableEnded || res.destroyed) return;
|
|
154
|
+
if (forwarded.status >= 200 && forwarded.status < 300) {
|
|
155
|
+
const headers = {};
|
|
156
|
+
if (forwarded.contentType) headers["content-type"] = forwarded.contentType;
|
|
157
|
+
if (forwarded.location) headers.location = forwarded.location;
|
|
158
|
+
res.writeHead(forwarded.status, headers);
|
|
159
|
+
res.end(forwarded.body);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
const body = Buffer.concat(chunks);
|
|
164
|
+
const answered = await answerVoiceCall({
|
|
165
|
+
offer: offerFromCallBody(body, req.headers["content-type"]),
|
|
166
|
+
instructions: instructionsFromCallBody(body, req.headers["content-type"]),
|
|
167
|
+
ackFiller: ackFillerFromCallBody(body, req.headers["content-type"]),
|
|
168
|
+
developerContext: developerTextFromCallBody(body, req.headers["content-type"]),
|
|
169
|
+
initialItems: initialItemsFromCallBody(body, req.headers["content-type"]),
|
|
170
|
+
token: session.token,
|
|
171
|
+
webSocketFactory: options.voiceWebSocket,
|
|
172
|
+
});
|
|
173
|
+
if (res.writableEnded || res.destroyed) {
|
|
174
|
+
answered.close();
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
res.writeHead(201, {
|
|
178
|
+
"content-type": "application/sdp",
|
|
179
|
+
location: answered.location,
|
|
180
|
+
});
|
|
181
|
+
res.end(answered.sdp);
|
|
182
|
+
return;
|
|
183
|
+
} catch {
|
|
184
|
+
// An offer werift cannot answer stays the upstream response.
|
|
185
|
+
}
|
|
186
|
+
const headers = {};
|
|
187
|
+
if (forwarded.contentType) headers["content-type"] = forwarded.contentType;
|
|
188
|
+
if (forwarded.location) headers.location = forwarded.location;
|
|
189
|
+
res.writeHead(forwarded.status, headers);
|
|
190
|
+
res.end(forwarded.body);
|
|
191
|
+
} catch (error) {
|
|
192
|
+
if (res.writableEnded || res.destroyed) return;
|
|
193
|
+
if (error instanceof GrokAuthError) return json(401, { error: error.message });
|
|
194
|
+
return json(502, { error: "Realtime call failed." });
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
111
198
|
export function publicBridgeError(error, context = {}) {
|
|
112
199
|
if (error instanceof GrokAuthError) return error.message;
|
|
113
200
|
const message = String(error?.message ?? "");
|
|
@@ -128,7 +215,7 @@ export function createBridgeServer(options = {}) {
|
|
|
128
215
|
queueLimit: options.maxQueuedInference,
|
|
129
216
|
});
|
|
130
217
|
const prefixes = createPrefixMemory();
|
|
131
|
-
|
|
218
|
+
const server = http.createServer(async (req, res) => {
|
|
132
219
|
const json = (status, data) => {
|
|
133
220
|
res.writeHead(status, { "content-type": "application/json" });
|
|
134
221
|
res.end(JSON.stringify(data));
|
|
@@ -142,7 +229,13 @@ export function createBridgeServer(options = {}) {
|
|
|
142
229
|
: route === "/v1/images/edits"
|
|
143
230
|
? "edits"
|
|
144
231
|
: null;
|
|
145
|
-
|
|
232
|
+
const realtimePath =
|
|
233
|
+
route === "/v1/realtime/calls"
|
|
234
|
+
? "/realtime/calls"
|
|
235
|
+
: route === "/v1/live"
|
|
236
|
+
? "/live"
|
|
237
|
+
: null;
|
|
238
|
+
if (req.method !== "POST" || (!imagineKind && !realtimePath && route !== "/v1/responses"))
|
|
146
239
|
return json(404, { error: "Not found" });
|
|
147
240
|
const auth = Buffer.from(req.headers.authorization ?? "");
|
|
148
241
|
if (auth.length !== token.length || !timingSafeEqual(auth, token))
|
|
@@ -150,6 +243,7 @@ export function createBridgeServer(options = {}) {
|
|
|
150
243
|
if (req.headers.origin)
|
|
151
244
|
return json(403, { error: "Browser requests are not accepted" });
|
|
152
245
|
if (imagineKind) return relayImagine(req, res, json, imagineKind, options);
|
|
246
|
+
if (realtimePath) return relayRealtime(req, res, json, realtimePath, options);
|
|
153
247
|
let body;
|
|
154
248
|
let requestBytes = 0;
|
|
155
249
|
try {
|
|
@@ -294,6 +388,7 @@ export function createBridgeServer(options = {}) {
|
|
|
294
388
|
baseUrl: options.videoBaseUrl,
|
|
295
389
|
pause: options.videoPause,
|
|
296
390
|
signal: controller.signal,
|
|
391
|
+
dir: options.videoDir,
|
|
297
392
|
},
|
|
298
393
|
},
|
|
299
394
|
res,
|
|
@@ -347,4 +442,6 @@ export function createBridgeServer(options = {}) {
|
|
|
347
442
|
res.end();
|
|
348
443
|
}
|
|
349
444
|
});
|
|
445
|
+
attachSidebandUpgrade(server, options);
|
|
446
|
+
return server;
|
|
350
447
|
}
|
package/src/imagine.mjs
CHANGED
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
// XAI_API_KEY. The bodies are not the same: Codex hardcodes `gpt-image-2`
|
|
5
5
|
// plus `size` / `quality` / `background`, and edits use `{image_url}` or
|
|
6
6
|
// `{file_id}`. Imagine wants `grok-imagine-image-quality`, `response_format:
|
|
7
|
-
// b64_json`, and `{url}` references.
|
|
7
|
+
// b64_json`, and `{url}` references. Codex `size` maps to `aspect_ratio`.
|
|
8
|
+
// Codex `quality: high` maps to resolution `2k`, and `low` to `1k`.
|
|
9
|
+
// `auto` omits resolution so Imagine keeps its own default. `quality` itself
|
|
10
|
+
// is not sent: that field belongs to a different Imagine model.
|
|
8
11
|
|
|
9
12
|
export const DEFAULT_IMAGINE_API_BASE = "https://api.x.ai/v1";
|
|
10
13
|
export const IMAGINE_MODEL = "grok-imagine-image-quality";
|
|
@@ -26,13 +29,39 @@ function basePayload(prompt) {
|
|
|
26
29
|
model: IMAGINE_MODEL,
|
|
27
30
|
prompt,
|
|
28
31
|
n: 1,
|
|
29
|
-
resolution: "1k",
|
|
30
32
|
response_format: "b64_json",
|
|
31
33
|
};
|
|
32
34
|
}
|
|
33
35
|
|
|
36
|
+
const SIZE_ASPECT = {
|
|
37
|
+
"1024x1024": "1:1",
|
|
38
|
+
"1536x1024": "3:2",
|
|
39
|
+
"1024x1536": "2:3",
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
function aspectFromSize(size) {
|
|
43
|
+
if (typeof size !== "string") return "";
|
|
44
|
+
return SIZE_ASPECT[size.trim()] ?? "";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function imageCount(value) {
|
|
48
|
+
const n = typeof value === "string" && /^\d+$/.test(value) ? Number(value) : value;
|
|
49
|
+
if (!Number.isInteger(n) || n < 1) return 1;
|
|
50
|
+
return Math.min(n, 10);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function applyImageOptions(payload, input) {
|
|
54
|
+
const aspect = aspectFromSize(input?.size);
|
|
55
|
+
if (aspect) payload.aspect_ratio = aspect;
|
|
56
|
+
if (input?.quality === "high") payload.resolution = "2k";
|
|
57
|
+
else if (input?.quality === "low") payload.resolution = "1k";
|
|
58
|
+
else delete payload.resolution;
|
|
59
|
+
payload.n = imageCount(input?.n);
|
|
60
|
+
return payload;
|
|
61
|
+
}
|
|
62
|
+
|
|
34
63
|
export function imagineGenerationBody(input) {
|
|
35
|
-
return basePayload(promptOf(input));
|
|
64
|
+
return applyImageOptions(basePayload(promptOf(input)), input);
|
|
36
65
|
}
|
|
37
66
|
|
|
38
67
|
export function imagineEditBody(input) {
|
|
@@ -42,7 +71,13 @@ export function imagineEditBody(input) {
|
|
|
42
71
|
for (const image of images) {
|
|
43
72
|
if (!image || typeof image !== "object") continue;
|
|
44
73
|
if (typeof image.image_url === "string" && image.image_url.trim()) {
|
|
45
|
-
|
|
74
|
+
const url = image.image_url.trim();
|
|
75
|
+
if (!/^https?:\/\//i.test(url) && !/^data:/i.test(url)) {
|
|
76
|
+
const error = new Error("Image edit requires an http(s) URL or a data URL.");
|
|
77
|
+
error.status = 400;
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
urls.push(url);
|
|
46
81
|
continue;
|
|
47
82
|
}
|
|
48
83
|
if (typeof image.file_id === "string" && image.file_id.trim()) {
|
|
@@ -58,10 +93,9 @@ export function imagineEditBody(input) {
|
|
|
58
93
|
}
|
|
59
94
|
const payload = basePayload(prompt);
|
|
60
95
|
if (urls.length === 1) payload.image = { url: urls[0] };
|
|
61
|
-
else {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
96
|
+
else payload.images = urls.map((url) => ({ url }));
|
|
97
|
+
applyImageOptions(payload, input);
|
|
98
|
+
if (!payload.aspect_ratio && urls.length > 1) payload.aspect_ratio = "auto";
|
|
65
99
|
return payload;
|
|
66
100
|
}
|
|
67
101
|
|