codex-grok-bridge 1.8.5 → 1.8.7
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 +10 -0
- package/README.md +26 -6
- package/package.json +1 -1
- package/src/bridge.mjs +43 -13
- package/src/provider-align.mjs +168 -32
- package/src/videogen.mjs +56 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.8.7 — 2026-11-20
|
|
4
|
+
|
|
5
|
+
- Tracked Codex CLI is 0.171.0 (https://github.com/openai/codex/releases/tag/rust-v0.171.0). verify-app-server passed.
|
|
6
|
+
- Tracked Grok CLI is 1.0.92 (https://x.ai/build/changelog). No bridge change.
|
|
7
|
+
|
|
8
|
+
## 1.8.6 — 2026-11-10
|
|
9
|
+
|
|
10
|
+
- Two app-server wrappers that share `CODEX_HOME` keep a live owner on the provider baseline. Startup recovery and exit restore no longer treat another running wrapper's marker as a crash, so the configured provider returns to its original value only after the last wrapper exits.
|
|
11
|
+
- A video response that also contains an ordinary Codex tool call is handed to Codex first. The video result is sent upstream only after that tool's output arrives, instead of being submitted beside an unanswered function call.
|
|
12
|
+
|
|
3
13
|
## 1.8.5 — 2026-11-10
|
|
4
14
|
|
|
5
15
|
- Codex CLI 0.166 and newer reject a turn when the thread's provider differs from the app-server's configured provider. The desktop wrapper sets `model_provider` for that process, updates the saved thread provider, and archives then unarchives the loaded thread so Codex reloads it, before `thread/resume`. A new Grok turn and an openai ↔ `grok_build_cli` switch both pass `verify-app-server`. The previous `model_provider` value is restored when the wrapper exits.
|
package/README.md
CHANGED
|
@@ -55,6 +55,16 @@ the bridge runs. See Release history.
|
|
|
55
55
|
|
|
56
56
|
What each recent version added. Older cuts are in `CHANGELOG.md`.
|
|
57
57
|
|
|
58
|
+
### 1.8.7 — 2026-11-20
|
|
59
|
+
|
|
60
|
+
- Tracked Codex CLI is 0.171.0 (https://github.com/openai/codex/releases/tag/rust-v0.171.0). verify-app-server passed.
|
|
61
|
+
- Tracked Grok CLI is 1.0.92 (https://x.ai/build/changelog). No bridge change.
|
|
62
|
+
|
|
63
|
+
### 1.8.6 — 2026-11-10
|
|
64
|
+
|
|
65
|
+
- Two app-server wrappers that share `CODEX_HOME` keep a live owner on the provider baseline. Startup recovery and exit restore no longer treat another running wrapper's marker as a crash, so the configured provider returns to its original value only after the last wrapper exits.
|
|
66
|
+
- A video response that also contains an ordinary Codex tool call is handed to Codex first. The video result is sent upstream only after that tool's output arrives, instead of being submitted beside an unanswered function call.
|
|
67
|
+
|
|
58
68
|
### 1.8.5 — 2026-11-10
|
|
59
69
|
|
|
60
70
|
- Codex CLI 0.166 and newer reject a turn when the thread's provider differs from the app-server's configured provider. The desktop wrapper sets `model_provider` for that process, updates the saved thread provider, and archives then unarchives the loaded thread so Codex reloads it, before `thread/resume`. A new Grok turn and an openai ↔ `grok_build_cli` switch both pass `verify-app-server`. The previous `model_provider` value is restored when the wrapper exits.
|
|
@@ -136,7 +146,7 @@ The `.command` launcher resolves paths from its own location, so moving the
|
|
|
136
146
|
folder does not require edits. Set `NODE=/path/to/node` if `node` is not on
|
|
137
147
|
`PATH`.
|
|
138
148
|
|
|
139
|
-
Verified against: Codex CLI 0.
|
|
149
|
+
Verified against: Codex CLI 0.171.0 and Node 22. Tracked Grok CLI: 1.0.92.
|
|
140
150
|
An app update that changes `CODEX_CLI_PATH` or the app-server protocol needs
|
|
141
151
|
re-verification.
|
|
142
152
|
|
|
@@ -158,7 +168,7 @@ starts, and tears the provider down with that process.
|
|
|
158
168
|
```sh
|
|
159
169
|
git clone https://github.com/deximple/codex-grok-bridge.git
|
|
160
170
|
cd codex-grok-bridge
|
|
161
|
-
npm test #
|
|
171
|
+
npm test # 318 tests, no network, no inference
|
|
162
172
|
node scripts/codex-grok.mjs
|
|
163
173
|
```
|
|
164
174
|
|
|
@@ -425,7 +435,7 @@ Start here when something breaks. Do not open `~/.grok/auth.json` or
|
|
|
425
435
|
## Verify
|
|
426
436
|
|
|
427
437
|
```sh
|
|
428
|
-
npm test #
|
|
438
|
+
npm test # 318 tests, no remote inference
|
|
429
439
|
npm run test:coverage # 80% line / branch / function gate
|
|
430
440
|
npm run verify:app-server # real app-server routing; also runs against an installed bundle
|
|
431
441
|
npm audit --omit=dev
|
|
@@ -520,6 +530,16 @@ Codex `web_search`는 브리지가 실행하는 함수가 아니라 xAI 서버
|
|
|
520
530
|
|
|
521
531
|
최근 버전이 더한 것입니다. 그 이전은 `CHANGELOG.md`에 있습니다.
|
|
522
532
|
|
|
533
|
+
### 1.8.7 — 2026-11-20
|
|
534
|
+
|
|
535
|
+
- 추적하는 Codex CLI는 0.171.0입니다 (https://github.com/openai/codex/releases/tag/rust-v0.171.0). verify-app-server를 통과했습니다.
|
|
536
|
+
- 추적하는 Grok CLI는 1.0.92입니다 (https://x.ai/build/changelog). 브리지 변경은 없습니다.
|
|
537
|
+
|
|
538
|
+
### 1.8.6 — 2026-11-10
|
|
539
|
+
|
|
540
|
+
- `CODEX_HOME`을 같이 쓰는 앱 서버 래퍼 둘은 제공자 기준값에 살아있는 소유자를 남깁니다. 시작 복구와 종료 복원은 다른 래퍼가 쓰는 마커를 비정상 종료로 보지 않으므로, 설정된 제공자는 마지막 래퍼가 끝난 뒤에만 원래 값으로 돌아갑니다.
|
|
541
|
+
- 영상 응답에 Codex 도구 호출이 같이 있으면 그 호출을 먼저 Codex에 넘깁니다. 영상 결과는 그 도구 출력이 도착한 뒤에만 상류로 보내고, 답이 없는 함수 호출 옆에 붙이지 않습니다.
|
|
542
|
+
|
|
523
543
|
### 1.8.5 — 2026-11-10
|
|
524
544
|
|
|
525
545
|
- Codex CLI 0.166부터는 스레드 제공자와 앱 서버에 설정된 제공자가 다르면 턴을 거절합니다. 데스크톱 래퍼가 그 프로세스의 `model_provider`를 맞추고, 저장된 스레드 제공자를 갱신한 뒤, 메모리에 있는 스레드를 archive/unarchive해서 Codex가 다시 읽게 합니다. `thread/resume` 전에 합니다. 새 Grok 턴과 openai ↔ `grok_build_cli` 전환이 `verify-app-server`를 통과합니다. 래퍼가 끝나면 이전 `model_provider` 값으로 되돌립니다.
|
|
@@ -600,7 +620,7 @@ Codex `web_search`는 브리지가 실행하는 함수가 아니라 xAI 서버
|
|
|
600
620
|
`.command` 런처는 자기 위치를 기준으로 경로를 잡으므로 폴더를 옮겨도 수정할
|
|
601
621
|
필요가 없습니다. `PATH`에 `node`가 없으면 `NODE=/path/to/node`로 지정합니다.
|
|
602
622
|
|
|
603
|
-
검증 버전: Codex CLI 0.
|
|
623
|
+
검증 버전: Codex CLI 0.171.0, Node 22. 추적 중인 Grok CLI: 1.0.92.
|
|
604
624
|
앱 업데이트가 `CODEX_CLI_PATH`나 app-server 프로토콜을 바꾸면 재검증이
|
|
605
625
|
필요합니다.
|
|
606
626
|
|
|
@@ -622,7 +642,7 @@ codex-grok exec --skip-git-repo-check --sandbox workspace-write '작업 내용'
|
|
|
622
642
|
```sh
|
|
623
643
|
git clone https://github.com/deximple/codex-grok-bridge.git
|
|
624
644
|
cd codex-grok-bridge
|
|
625
|
-
npm test #
|
|
645
|
+
npm test # 318건, 네트워크·추론 없음
|
|
626
646
|
node scripts/codex-grok.mjs
|
|
627
647
|
```
|
|
628
648
|
|
|
@@ -873,7 +893,7 @@ URL과 저장한 파일 경로를 함께 넣습니다. 다운로드가 실패하
|
|
|
873
893
|
## 검증
|
|
874
894
|
|
|
875
895
|
```sh
|
|
876
|
-
npm test #
|
|
896
|
+
npm test # 318건, 외부 추론 없음
|
|
877
897
|
npm run test:coverage # line/branch/function 80% 게이트
|
|
878
898
|
npm run verify:app-server # 실제 app-server 라우팅. 설치된 앱 번들에서도 실행
|
|
879
899
|
npm audit --omit=dev
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codex-grok-bridge",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.7",
|
|
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",
|
package/src/bridge.mjs
CHANGED
|
@@ -11,6 +11,9 @@ import {
|
|
|
11
11
|
import { emitProxySse, readRelayProxySse } from "./proxy.mjs";
|
|
12
12
|
import {
|
|
13
13
|
addUsage,
|
|
14
|
+
applyVideoHandoff,
|
|
15
|
+
noteVideoHandoff,
|
|
16
|
+
ordinaryFunctionCalls,
|
|
14
17
|
retainedInputItems,
|
|
15
18
|
stampUsage,
|
|
16
19
|
stripVideoToolEvents,
|
|
@@ -45,7 +48,11 @@ export { MODEL_INFO };
|
|
|
45
48
|
const VIDEO_FOLLOW_UPS = 2;
|
|
46
49
|
|
|
47
50
|
async function relayWithVideo(options, output, map, usageBox, onClientByte) {
|
|
48
|
-
|
|
51
|
+
const handoffKey = options.sessionId || options.convId || "default";
|
|
52
|
+
let body = {
|
|
53
|
+
...options.body,
|
|
54
|
+
input: applyVideoHandoff(handoffKey, options.body?.input),
|
|
55
|
+
};
|
|
49
56
|
let totalUsage = {};
|
|
50
57
|
for (let step = 0; step <= VIDEO_FOLLOW_UPS; step += 1) {
|
|
51
58
|
const parts = await readRelayProxySse({ ...options, body }, output);
|
|
@@ -60,25 +67,48 @@ async function relayWithVideo(options, output, map, usageBox, onClientByte) {
|
|
|
60
67
|
// The videos API poll can sit for minutes. Keepalive is safe here: this
|
|
61
68
|
// upstream reply is finished, and nothing has been written to Codex yet.
|
|
62
69
|
onClientByte();
|
|
63
|
-
const
|
|
70
|
+
const videos = [];
|
|
64
71
|
for (const call of calls) {
|
|
65
|
-
|
|
66
|
-
|
|
72
|
+
videos.push({
|
|
73
|
+
name: call.name,
|
|
74
|
+
call_id: call.call_id,
|
|
75
|
+
arguments: call.arguments,
|
|
76
|
+
output: await videoToolOutput(call, options.video),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
const ordinary = ordinaryFunctionCalls(parts);
|
|
80
|
+
if (ordinary.length) {
|
|
81
|
+
noteVideoHandoff(handoffKey, {
|
|
82
|
+
waiting: ordinary.map((call) => call.call_id).filter(Boolean),
|
|
83
|
+
videos,
|
|
84
|
+
});
|
|
85
|
+
await emitProxySse(
|
|
86
|
+
stampUsage(stripVideoToolEvents(parts), totalUsage),
|
|
87
|
+
output,
|
|
88
|
+
map,
|
|
89
|
+
usageBox,
|
|
90
|
+
onClientByte,
|
|
91
|
+
);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const additions = [
|
|
95
|
+
...retainedInputItems(parts),
|
|
96
|
+
...videos.flatMap((video) => [
|
|
67
97
|
{
|
|
68
98
|
type: "function_call",
|
|
69
|
-
name:
|
|
70
|
-
call_id:
|
|
71
|
-
arguments:
|
|
99
|
+
name: video.name,
|
|
100
|
+
call_id: video.call_id,
|
|
101
|
+
arguments: video.arguments,
|
|
72
102
|
},
|
|
73
103
|
{
|
|
74
104
|
type: "function_call_output",
|
|
75
|
-
name:
|
|
76
|
-
call_id:
|
|
77
|
-
output:
|
|
105
|
+
name: video.name,
|
|
106
|
+
call_id: video.call_id,
|
|
107
|
+
output: video.output,
|
|
78
108
|
},
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
body = { ...body, input: [...body.input, ...additions] };
|
|
109
|
+
]),
|
|
110
|
+
];
|
|
111
|
+
body = { ...body, input: [...(body.input ?? []), ...additions] };
|
|
82
112
|
}
|
|
83
113
|
}
|
|
84
114
|
|
package/src/provider-align.mjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// config.toml for that process only; the baseline is restored on exit.
|
|
6
6
|
|
|
7
7
|
import { randomUUID } from "node:crypto";
|
|
8
|
-
import { existsSync, readFileSync, writeFileSync, mkdirSync, rmSync } from "node:fs";
|
|
8
|
+
import { constants, existsSync, openSync, closeSync, readFileSync, writeFileSync, mkdirSync, rmSync, statSync, unlinkSync } from "node:fs";
|
|
9
9
|
import { lstat, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
10
10
|
import path from "node:path";
|
|
11
11
|
import { rewriteRolloutProviderText } from "./rollout.mjs";
|
|
@@ -16,6 +16,133 @@ export function providerMarkerPath(codexHome) {
|
|
|
16
16
|
return path.join(codexHome, "grok-bridge-provider.json");
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
function processStartedAt(pid) {
|
|
20
|
+
try {
|
|
21
|
+
const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
22
|
+
const rest = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
|
23
|
+
return rest[19] || null;
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const PROCESS_OWNER = {
|
|
30
|
+
pid: process.pid,
|
|
31
|
+
token: randomUUID(),
|
|
32
|
+
startedAt: processStartedAt(process.pid),
|
|
33
|
+
};
|
|
34
|
+
let ownerAliveForTests = null;
|
|
35
|
+
|
|
36
|
+
export function setOwnerAliveForTests(fn) {
|
|
37
|
+
ownerAliveForTests = fn;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function ownerKey(owner) {
|
|
41
|
+
return owner && Number.isInteger(owner.pid) ? `${owner.pid}:${owner.token ?? ""}` : "";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function ownerRecord(owner) {
|
|
45
|
+
const startedAt = owner.startedAt || processStartedAt(owner.pid);
|
|
46
|
+
return {
|
|
47
|
+
pid: owner.pid,
|
|
48
|
+
token: owner.token,
|
|
49
|
+
...(startedAt ? { startedAt } : {}),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function ownerAlive(owner) {
|
|
54
|
+
if (!ownerKey(owner)) return false;
|
|
55
|
+
if (ownerAliveForTests) return ownerAliveForTests(owner);
|
|
56
|
+
if (owner.pid === PROCESS_OWNER.pid && owner.token === PROCESS_OWNER.token) return true;
|
|
57
|
+
const startedAt = processStartedAt(owner.pid);
|
|
58
|
+
if (owner.startedAt) return startedAt === owner.startedAt;
|
|
59
|
+
if (!startedAt) {
|
|
60
|
+
try {
|
|
61
|
+
process.kill(owner.pid, 0);
|
|
62
|
+
return true;
|
|
63
|
+
} catch (error) {
|
|
64
|
+
return error?.code === "EPERM";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function liveOwners(marker, except) {
|
|
71
|
+
const skip = ownerKey(except);
|
|
72
|
+
const seen = new Set();
|
|
73
|
+
const live = [];
|
|
74
|
+
for (const owner of marker?.owners ?? []) {
|
|
75
|
+
const key = ownerKey(owner);
|
|
76
|
+
if (!key || key === skip || seen.has(key) || !ownerAlive(owner)) continue;
|
|
77
|
+
seen.add(key);
|
|
78
|
+
live.push(ownerRecord(owner));
|
|
79
|
+
}
|
|
80
|
+
return live;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function readMarker(codexHome) {
|
|
84
|
+
const markerPath = providerMarkerPath(codexHome);
|
|
85
|
+
if (!existsSync(markerPath)) return null;
|
|
86
|
+
try {
|
|
87
|
+
const marker = JSON.parse(readFileSync(markerPath, "utf8"));
|
|
88
|
+
return marker && typeof marker === "object" ? marker : null;
|
|
89
|
+
} catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function writeMarker(codexHome, marker) {
|
|
95
|
+
const markerPath = providerMarkerPath(codexHome);
|
|
96
|
+
const tmp = `${markerPath}.${process.pid}.${randomUUID()}.tmp`;
|
|
97
|
+
writeFileSync(tmp, `${JSON.stringify(marker)}\n`, { mode: 0o600 });
|
|
98
|
+
try {
|
|
99
|
+
rmSync(markerPath, { force: true });
|
|
100
|
+
const fd = openSync(markerPath, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY, 0o600);
|
|
101
|
+
try {
|
|
102
|
+
writeFileSync(fd, `${JSON.stringify(marker)}\n`);
|
|
103
|
+
} finally {
|
|
104
|
+
closeSync(fd);
|
|
105
|
+
}
|
|
106
|
+
} finally {
|
|
107
|
+
rmSync(tmp, { force: true });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function withProviderLock(codexHome, fn) {
|
|
112
|
+
mkdirSync(codexHome, { recursive: true, mode: 0o700 });
|
|
113
|
+
const lockPath = path.join(codexHome, "grok-bridge-provider.lock");
|
|
114
|
+
const started = Date.now();
|
|
115
|
+
let fd;
|
|
116
|
+
for (;;) {
|
|
117
|
+
try {
|
|
118
|
+
fd = openSync(lockPath, constants.O_CREAT | constants.O_EXCL | constants.O_RDWR, 0o600);
|
|
119
|
+
break;
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (error?.code !== "EEXIST") throw error;
|
|
122
|
+
try {
|
|
123
|
+
if (Date.now() - statSync(lockPath).mtimeMs > 2_000) unlinkSync(lockPath);
|
|
124
|
+
} catch {
|
|
125
|
+
// The holder removed it between the stat and the unlink.
|
|
126
|
+
}
|
|
127
|
+
if (Date.now() - started > 5_000) throw new Error("provider baseline lock timed out");
|
|
128
|
+
const until = Date.now() + 15;
|
|
129
|
+
while (Date.now() < until) {
|
|
130
|
+
// The critical section is synchronous, so the wait has to be too.
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
return fn();
|
|
136
|
+
} finally {
|
|
137
|
+
closeSync(fd);
|
|
138
|
+
try {
|
|
139
|
+
unlinkSync(lockPath);
|
|
140
|
+
} catch {
|
|
141
|
+
// A stale-lock recovery may already have removed it.
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
19
146
|
export function readModelProvider(text) {
|
|
20
147
|
let inTable = false;
|
|
21
148
|
for (const line of String(text ?? "").split(/\r?\n/)) {
|
|
@@ -104,40 +231,49 @@ export function applyModelProvider(codexHome, provider) {
|
|
|
104
231
|
return true;
|
|
105
232
|
}
|
|
106
233
|
|
|
107
|
-
export function captureProviderBaseline(codexHome) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
234
|
+
export function captureProviderBaseline(codexHome, owner = PROCESS_OWNER) {
|
|
235
|
+
return withProviderLock(codexHome, () => {
|
|
236
|
+
const marker = readMarker(codexHome);
|
|
237
|
+
const trusted = marker?.codexHome === codexHome ? marker : null;
|
|
238
|
+
const others = liveOwners(trusted, owner);
|
|
239
|
+
if (others.length) {
|
|
240
|
+
writeMarker(codexHome, {
|
|
241
|
+
codexHome,
|
|
242
|
+
original: trusted.original ?? null,
|
|
243
|
+
owners: [...others, ownerRecord(owner)],
|
|
244
|
+
});
|
|
245
|
+
return trusted.original ?? null;
|
|
116
246
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
);
|
|
127
|
-
return original;
|
|
247
|
+
if (trusted) applyModelProvider(codexHome, trusted.original ?? null);
|
|
248
|
+
const file = configPath(codexHome);
|
|
249
|
+
const original = existsSync(file) ? readModelProvider(readFileSync(file, "utf8")) : null;
|
|
250
|
+
writeMarker(codexHome, {
|
|
251
|
+
codexHome,
|
|
252
|
+
original,
|
|
253
|
+
owners: [ownerRecord(owner)],
|
|
254
|
+
});
|
|
255
|
+
return original;
|
|
256
|
+
});
|
|
128
257
|
}
|
|
129
258
|
|
|
130
|
-
export function restoreProviderBaseline(codexHome) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
if (
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
259
|
+
export function restoreProviderBaseline(codexHome, owner = PROCESS_OWNER) {
|
|
260
|
+
return withProviderLock(codexHome, () => {
|
|
261
|
+
const markerPath = providerMarkerPath(codexHome);
|
|
262
|
+
if (!existsSync(markerPath)) return false;
|
|
263
|
+
const marker = readMarker(codexHome);
|
|
264
|
+
if (!marker || marker.codexHome !== codexHome) {
|
|
265
|
+
rmSync(markerPath, { force: true });
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
const others = liveOwners(marker, owner);
|
|
269
|
+
if (others.length) {
|
|
270
|
+
writeMarker(codexHome, { ...marker, owners: others });
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
applyModelProvider(codexHome, marker.original ?? null);
|
|
274
|
+
rmSync(markerPath, { force: true });
|
|
275
|
+
return true;
|
|
276
|
+
});
|
|
141
277
|
}
|
|
142
278
|
|
|
143
279
|
async function updateStateDb(file, threadId, provider, model) {
|
package/src/videogen.mjs
CHANGED
|
@@ -360,27 +360,65 @@ function doneItems(parts) {
|
|
|
360
360
|
return items;
|
|
361
361
|
}
|
|
362
362
|
|
|
363
|
+
const videoHandoffs = new Map();
|
|
364
|
+
|
|
365
|
+
function functionCallItem(item) {
|
|
366
|
+
return {
|
|
367
|
+
type: "function_call",
|
|
368
|
+
name: item.name,
|
|
369
|
+
call_id: item.call_id,
|
|
370
|
+
arguments:
|
|
371
|
+
typeof item.arguments === "string" ? item.arguments : JSON.stringify(item.arguments ?? {}),
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export function ordinaryFunctionCalls(parts) {
|
|
376
|
+
return doneItems(parts)
|
|
377
|
+
.filter((item) => item?.type === "function_call" && item.name !== GROK_VIDEO_TOOL_NAME)
|
|
378
|
+
.map(functionCallItem);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export function clearVideoHandoffs() {
|
|
382
|
+
videoHandoffs.clear();
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export function noteVideoHandoff(threadId, handoff) {
|
|
386
|
+
videoHandoffs.set(threadId || "default", handoff);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export function applyVideoHandoff(threadId, input) {
|
|
390
|
+
const pending = videoHandoffs.get(threadId || "default");
|
|
391
|
+
if (!pending || !Array.isArray(input) || !pending.waiting?.length) return input;
|
|
392
|
+
const outputs = new Set(
|
|
393
|
+
input
|
|
394
|
+
.filter((item) => item?.type === "function_call_output" && item.call_id)
|
|
395
|
+
.map((item) => item.call_id),
|
|
396
|
+
);
|
|
397
|
+
if (!pending.waiting.every((id) => outputs.has(id))) return input;
|
|
398
|
+
videoHandoffs.delete(threadId || "default");
|
|
399
|
+
const items = (pending.videos ?? []).flatMap((video) => [
|
|
400
|
+
functionCallItem(video),
|
|
401
|
+
{
|
|
402
|
+
type: "function_call_output",
|
|
403
|
+
name: video.name,
|
|
404
|
+
call_id: video.call_id,
|
|
405
|
+
output: video.output,
|
|
406
|
+
},
|
|
407
|
+
]);
|
|
408
|
+
const at = input.findIndex(
|
|
409
|
+
(item) => item?.type === "function_call" && pending.waiting.includes(item.call_id),
|
|
410
|
+
);
|
|
411
|
+
if (at < 0) return [...items, ...input];
|
|
412
|
+
return [...input.slice(0, at), ...items, ...input.slice(at)];
|
|
413
|
+
}
|
|
414
|
+
|
|
363
415
|
export function retainedInputItems(parts) {
|
|
364
416
|
const items = [];
|
|
365
417
|
for (const item of doneItems(parts)) {
|
|
366
|
-
if (item?.type
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
name: item.name,
|
|
371
|
-
call_id: item.call_id,
|
|
372
|
-
arguments:
|
|
373
|
-
typeof item.arguments === "string"
|
|
374
|
-
? item.arguments
|
|
375
|
-
: JSON.stringify(item.arguments ?? {}),
|
|
376
|
-
});
|
|
377
|
-
continue;
|
|
378
|
-
}
|
|
379
|
-
if (item?.type === "reasoning" || item?.type === "message") {
|
|
380
|
-
const copy = structuredClone(item);
|
|
381
|
-
stripCiphertext(copy);
|
|
382
|
-
items.push(copy);
|
|
383
|
-
}
|
|
418
|
+
if (item?.type !== "reasoning" && item?.type !== "message") continue;
|
|
419
|
+
const copy = structuredClone(item);
|
|
420
|
+
stripCiphertext(copy);
|
|
421
|
+
items.push(copy);
|
|
384
422
|
}
|
|
385
423
|
return items;
|
|
386
424
|
}
|