codex-grok-bridge 1.8.0 → 1.8.1

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.8.1 — 2026-10-03
4
+
5
+ - Grok reasoning ciphertext is removed from the stream back to Codex, so a later switch to an OpenAI model does not try to decrypt a Grok reasoning blob. This was already on main after 1.8.0 and was not in the 1.8.0 npm tarball.
6
+ - The Linux and Windows installers install `opusscript@0.1.1` and `werift@0.24.4` into the bridge directory.
7
+ - App-server startup survives a missing voice package. `opusscript` and `werift` load with dynamic import, so a missing module does not exit before Codex reads organization settings.
8
+ - Local JSON Schema `$ref` values (`#/$defs` and `#/definitions`) are inlined before tool parameters are sent to Grok.
9
+
3
10
  ## 1.8.0 — 2026-10-02
4
11
 
5
12
  - 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.
package/README.md CHANGED
@@ -233,7 +233,7 @@ multi-call turn can continue its own reasoning. The upstream has been observed
233
233
  to accept this shape. The same pass keeps only the fields Grok’s Responses
234
234
  input accepts on each item and content part — `status`, unknown Codex keys,
235
235
  and every `internal_*` field are dropped so a new client field cannot 422 the
236
- upstream.
236
+ upstream. The same ciphertext is removed from the stream back to Codex, so a later switch to an OpenAI model does not try to decrypt a Grok reasoning blob. A thread that already stored those items still has them.
237
237
 
238
238
  ### Concurrency
239
239
 
@@ -636,7 +636,7 @@ Codex `reasoning` 항목의 평문 요약은 상류로 전달합니다. 요약
636
636
  턴에서 모델이 자기 추론을 이어받게 하기 위한 것이며, 상류가 이 형태를 수락하는
637
637
  것을 확인했습니다. 같은 과정에서 아이템과 content part는 Grok Responses가
638
638
  받는 필드만 남깁니다. `status`, 알 수 없는 Codex 키, `internal_*` 필드는
639
- 버려서 새 클라이언트 필드가 상류 422를 내지 않게 합니다.
639
+ 버려서 새 클라이언트 필드가 상류 422를 내지 않게 합니다. 응답으로 돌아가는 암호문도 빼서, 나중에 OpenAI 모델로 바꿔도 Grok 추론 blob을 복호화하려 하지 않습니다. 이미 저장된 스레드는 그 항목이 남아 있습니다.
640
640
 
641
641
  ### 동시성
642
642
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-grok-bridge",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
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",
@@ -52,6 +52,36 @@ function Resolve-NodeExe {
52
52
  }
53
53
 
54
54
  $Node = Resolve-NodeExe
55
+ $npm = Join-Path (Split-Path -Parent $Node) "npm.cmd"
56
+ if (-not (Test-Path -LiteralPath $npm)) {
57
+ $npmSh = Join-Path (Split-Path -Parent $Node) "npm"
58
+ if (Test-Path -LiteralPath $npmSh) { $npm = $npmSh }
59
+ else {
60
+ $npmCmd = Get-Command npm -ErrorAction SilentlyContinue
61
+ if ($npmCmd -and $npmCmd.Source) { $npm = $npmCmd.Source }
62
+ }
63
+ }
64
+ if (-not $npm -or -not (Test-Path -LiteralPath $npm)) {
65
+ Write-Error "no npm on PATH; voice packages were not installed"
66
+ }
67
+ @"
68
+ {
69
+ "name": "codex-grok-bridge-runtime",
70
+ "private": true,
71
+ "dependencies": {
72
+ "opusscript": "0.1.1",
73
+ "werift": "0.24.4"
74
+ }
75
+ }
76
+ "@ | Set-Content -Path (Join-Path $App "package.json") -Encoding ASCII
77
+ Push-Location $App
78
+ try {
79
+ & $npm install --omit=dev --no-fund --no-audit
80
+ if ($LASTEXITCODE -ne 0) { Write-Error "npm install of opusscript and werift failed" }
81
+ } finally {
82
+ Pop-Location
83
+ }
84
+
55
85
  $Launcher = Join-Path $App "codex-grok-desktop.cmd"
56
86
  @"
57
87
  @echo off
@@ -94,6 +94,32 @@ for dir in scripts src; do
94
94
  done
95
95
  [ "$status" -eq 0 ] || { echo "bundle did not match the checkout" >&2; exit 1; }
96
96
 
97
+ install_voice_runtime() {
98
+ node_bin="${NODE:-$(command -v node || true)}"
99
+ [ -n "$node_bin" ] || { echo "no node on PATH; set NODE=/path/to/node" >&2; exit 1; }
100
+ npm_bin=""
101
+ node_dir="$(dirname "$node_bin")"
102
+ if [ -x "$node_dir/npm" ]; then
103
+ npm_bin="$node_dir/npm"
104
+ elif command -v npm >/dev/null 2>&1; then
105
+ npm_bin="$(command -v npm)"
106
+ fi
107
+ [ -n "$npm_bin" ] || { echo "no npm on PATH; voice packages were not installed" >&2; exit 1; }
108
+ cat > "$BRIDGE/package.json" <<'EOF'
109
+ {
110
+ "name": "codex-grok-bridge-runtime",
111
+ "private": true,
112
+ "dependencies": {
113
+ "opusscript": "0.1.1",
114
+ "werift": "0.24.4"
115
+ }
116
+ }
117
+ EOF
118
+ (cd "$BRIDGE" && "$npm_bin" install --omit=dev --no-fund --no-audit)
119
+ }
120
+
121
+ install_voice_runtime
122
+
97
123
  write_linux_wrapper() {
98
124
  NODE="${NODE:-$(command -v node || true)}"
99
125
  [ -n "$NODE" ] || { echo "no node on PATH; set NODE=/path/to/node" >&2; exit 1; }
package/src/tools.mjs CHANGED
@@ -163,22 +163,100 @@ function emitObjectParameters(source, overrides = {}) {
163
163
  return next;
164
164
  }
165
165
 
166
+ function decodeJsonPointerToken(token) {
167
+ return token.replace(/~1/g, "/").replace(/~0/g, "~");
168
+ }
169
+
170
+ // `#/$defs/Name` and `#/definitions/Name` are document-local. Grok rejects
171
+ // those pointers, so the copy sent upstream has the target schema inlined.
172
+ function definitionPointer(ref) {
173
+ if (typeof ref !== "string" || !ref.startsWith("#/")) return null;
174
+ const tokens = ref.slice(2).split("/").map(decodeJsonPointerToken);
175
+ if (tokens.length < 2) return null;
176
+ if (tokens[0] !== "$defs" && tokens[0] !== "definitions") return null;
177
+ return tokens;
178
+ }
179
+
180
+ function readPointer(root, tokens) {
181
+ let node = root;
182
+ for (const token of tokens) {
183
+ if (Array.isArray(node)) {
184
+ if (!/^(0|[1-9]\d*)$/.test(token)) return undefined;
185
+ node = node[Number(token)];
186
+ } else if (
187
+ plainObject(node) &&
188
+ Object.prototype.hasOwnProperty.call(node, token)
189
+ ) {
190
+ node = node[token];
191
+ } else {
192
+ return undefined;
193
+ }
194
+ }
195
+ return node;
196
+ }
197
+
198
+ function inlineLocalSchemaRefs(schema) {
199
+ function resolve(ref, trail) {
200
+ const tokens = definitionPointer(ref);
201
+ if (!tokens || trail.includes(ref))
202
+ throw new Error(`Unresolvable schema $ref: ${ref}`);
203
+ const target = readPointer(schema, tokens);
204
+ if (target === undefined)
205
+ throw new Error(`Unresolvable schema $ref: ${ref}`);
206
+ return walk(structuredClone(target), trail.concat(ref));
207
+ }
208
+
209
+ function walk(node, trail) {
210
+ if (Array.isArray(node)) return node.map((item) => walk(item, trail));
211
+ if (!plainObject(node)) return node;
212
+ if (Object.prototype.hasOwnProperty.call(node, "$ref")) {
213
+ if (typeof node.$ref !== "string")
214
+ throw new Error("Unresolvable schema $ref");
215
+ const resolved = resolve(node.$ref, trail);
216
+ const rest = {};
217
+ for (const [key, value] of Object.entries(node)) {
218
+ if (key !== "$ref") rest[key] = value;
219
+ }
220
+ if (Object.keys(rest).length === 0) return resolved;
221
+ if (!plainObject(resolved))
222
+ throw new Error(`Unresolvable schema $ref: ${node.$ref}`);
223
+ return walk({ ...resolved, ...rest }, trail);
224
+ }
225
+ const next = {};
226
+ for (const [key, value] of Object.entries(node)) {
227
+ if (key === "$defs" || key === "definitions") continue;
228
+ next[key] = walk(value, trail);
229
+ }
230
+ return next;
231
+ }
232
+
233
+ return walk(schema, []);
234
+ }
235
+
236
+ function emitsObjectParameters(schema) {
237
+ return (
238
+ schema.type === "object" ||
239
+ (schema.type == null && plainObject(schema.properties))
240
+ );
241
+ }
242
+
166
243
  function usableParameters(parameters) {
167
244
  if (!parameters || typeof parameters !== "object" || Array.isArray(parameters))
168
245
  return OBJECT_SCHEMA;
246
+ parameters = inlineLocalSchemaRefs(parameters);
169
247
  const variants = Array.isArray(parameters.oneOf)
170
248
  ? parameters.oneOf
171
249
  : Array.isArray(parameters.anyOf)
172
250
  ? parameters.anyOf
173
251
  : null;
174
252
  if (!variants) {
175
- return parameters.type === "object"
253
+ return emitsObjectParameters(parameters)
176
254
  ? emitObjectParameters(parameters)
177
255
  : OBJECT_SCHEMA;
178
256
  }
179
257
  const fragments = variants.filter(isObjectFragment);
180
258
  if (fragments.length === 0) {
181
- return parameters.type === "object"
259
+ return emitsObjectParameters(parameters)
182
260
  ? emitObjectParameters(parameters)
183
261
  : OBJECT_SCHEMA;
184
262
  }
@@ -879,6 +957,24 @@ function originForResponseName(map, name) {
879
957
  return found;
880
958
  }
881
959
 
960
+ // Grok ciphertext is not an OpenAI reasoning blob. If Codex stores it, a later
961
+ // switch to an OpenAI model fails with "could not be decrypted or parsed".
962
+ function stripEncryptedReasoning(node) {
963
+ if (!node || typeof node !== "object") return;
964
+ if (Array.isArray(node)) {
965
+ for (let i = node.length - 1; i >= 0; i -= 1) {
966
+ const part = node[i];
967
+ if (part && typeof part === "object" && part.type === "encrypted_content")
968
+ node.splice(i, 1);
969
+ else stripEncryptedReasoning(part);
970
+ }
971
+ return;
972
+ }
973
+ delete node.encrypted_content;
974
+ delete node.encrypted_function_args;
975
+ for (const value of Object.values(node)) stripEncryptedReasoning(value);
976
+ }
977
+
882
978
  function rewriteResponseItem(node, map, state) {
883
979
  if (!node || typeof node !== "object") return;
884
980
  const origin =
@@ -930,6 +1026,7 @@ const USAGE_EVENTS = new Set(["response.completed", "response.incomplete"]);
930
1026
 
931
1027
  function rewriteResponseEvent(value, map, state) {
932
1028
  if (!value || typeof value !== "object") return value;
1029
+ stripEncryptedReasoning(value);
933
1030
  if (
934
1031
  USAGE_EVENTS.has(value.type) &&
935
1032
  value.response &&
package/src/voice.mjs CHANGED
@@ -1,13 +1,51 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
- import OpusScript from "opusscript";
3
- import {
4
- MediaStreamTrack,
5
- RTCPeerConnection,
6
- RtpHeader,
7
- RtpPacket,
8
- useOPUS,
9
- usePCMU,
10
- } from "werift";
2
+
3
+ let OpusScript;
4
+ let MediaStreamTrack;
5
+ let RTCPeerConnection;
6
+ let RtpHeader;
7
+ let RtpPacket;
8
+ let useOPUS;
9
+ let usePCMU;
10
+ let voicePackagesError;
11
+
12
+ try {
13
+ const opusMod = await import("opusscript");
14
+ const weriftMod = await import("werift");
15
+ OpusScript = opusMod.default ?? opusMod;
16
+ ({ MediaStreamTrack, RTCPeerConnection, RtpHeader, RtpPacket, useOPUS, usePCMU } = weriftMod);
17
+ if (
18
+ typeof OpusScript !== "function" ||
19
+ typeof MediaStreamTrack !== "function" ||
20
+ typeof RTCPeerConnection !== "function" ||
21
+ typeof RtpHeader !== "function" ||
22
+ typeof RtpPacket !== "function" ||
23
+ typeof useOPUS !== "function" ||
24
+ typeof usePCMU !== "function"
25
+ ) {
26
+ throw new Error("opusscript or werift did not export the voice runtime");
27
+ }
28
+ } catch (error) {
29
+ OpusScript = undefined;
30
+ MediaStreamTrack = undefined;
31
+ RTCPeerConnection = undefined;
32
+ RtpHeader = undefined;
33
+ RtpPacket = undefined;
34
+ useOPUS = undefined;
35
+ usePCMU = undefined;
36
+ voicePackagesError = error;
37
+ }
38
+
39
+ function voicePackages() {
40
+ if (OpusScript && MediaStreamTrack && RTCPeerConnection && RtpHeader && RtpPacket && useOPUS && usePCMU) {
41
+ return { OpusScript, MediaStreamTrack, RTCPeerConnection, RtpHeader, RtpPacket, useOPUS, usePCMU };
42
+ }
43
+ const detail = voicePackagesError instanceof Error ? voicePackagesError.message : "missing";
44
+ throw new Error(
45
+ `Voice needs opusscript and werift installed in the bridge directory (${detail}). Re-run the Codex Grok installer.`,
46
+ voicePackagesError instanceof Error ? { cause: voicePackagesError } : undefined,
47
+ );
48
+ }
11
49
 
12
50
  export const VOICE_SOCKET_URL = "wss://api.x.ai/v1/realtime?model=grok-voice-latest";
13
51
 
@@ -25,6 +63,7 @@ const sessionsById = new Map();
25
63
  const OPUS_FRAME = 960;
26
64
 
27
65
  function peerConfig() {
66
+ const { useOPUS, usePCMU } = voicePackages();
28
67
  return {
29
68
  iceServers: [],
30
69
  iceUseIpv4: true,
@@ -188,6 +227,7 @@ export function audioCodecFromSdp(sdp) {
188
227
  }
189
228
 
190
229
  function createOpus() {
230
+ const { OpusScript } = voicePackages();
191
231
  return new OpusScript(48000, 2, OpusScript.Application.VOIP);
192
232
  }
193
233
 
@@ -423,6 +463,7 @@ export function playoutGap(state, now) {
423
463
 
424
464
  function writeAudio(track, state, payload, clockStep, forceMarker = false) {
425
465
  if (payload.length === 0) return;
466
+ const { RtpHeader, RtpPacket } = voicePackages();
426
467
  const now = Date.now();
427
468
  const extra = playoutGap(state, now);
428
469
  const sequence = (state.sequence + 1) & 0xffff;
@@ -1213,6 +1254,7 @@ export async function answerVoiceCall({
1213
1254
  developerContext = "",
1214
1255
  initialItems,
1215
1256
  }) {
1257
+ const { MediaStreamTrack, RTCPeerConnection } = voicePackages();
1216
1258
  const pc = new RTCPeerConnection(peerConfig());
1217
1259
  const track = new MediaStreamTrack({ kind: "audio" });
1218
1260
  let socket;