codex-grok-bridge 1.8.5 → 1.8.6
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 +5 -0
- package/README.md +14 -4
- 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,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.8.6 — 2026-11-10
|
|
4
|
+
|
|
5
|
+
- 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.
|
|
6
|
+
- 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.
|
|
7
|
+
|
|
3
8
|
## 1.8.5 — 2026-11-10
|
|
4
9
|
|
|
5
10
|
- 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,11 @@ 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.6 — 2026-11-10
|
|
59
|
+
|
|
60
|
+
- 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.
|
|
61
|
+
- 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.
|
|
62
|
+
|
|
58
63
|
### 1.8.5 — 2026-11-10
|
|
59
64
|
|
|
60
65
|
- 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.
|
|
@@ -158,7 +163,7 @@ starts, and tears the provider down with that process.
|
|
|
158
163
|
```sh
|
|
159
164
|
git clone https://github.com/deximple/codex-grok-bridge.git
|
|
160
165
|
cd codex-grok-bridge
|
|
161
|
-
npm test #
|
|
166
|
+
npm test # 317 tests, no network, no inference
|
|
162
167
|
node scripts/codex-grok.mjs
|
|
163
168
|
```
|
|
164
169
|
|
|
@@ -425,7 +430,7 @@ Start here when something breaks. Do not open `~/.grok/auth.json` or
|
|
|
425
430
|
## Verify
|
|
426
431
|
|
|
427
432
|
```sh
|
|
428
|
-
npm test #
|
|
433
|
+
npm test # 317 tests, no remote inference
|
|
429
434
|
npm run test:coverage # 80% line / branch / function gate
|
|
430
435
|
npm run verify:app-server # real app-server routing; also runs against an installed bundle
|
|
431
436
|
npm audit --omit=dev
|
|
@@ -520,6 +525,11 @@ Codex `web_search`는 브리지가 실행하는 함수가 아니라 xAI 서버
|
|
|
520
525
|
|
|
521
526
|
최근 버전이 더한 것입니다. 그 이전은 `CHANGELOG.md`에 있습니다.
|
|
522
527
|
|
|
528
|
+
### 1.8.6 — 2026-11-10
|
|
529
|
+
|
|
530
|
+
- `CODEX_HOME`을 같이 쓰는 앱 서버 래퍼 둘은 제공자 기준값에 살아있는 소유자를 남깁니다. 시작 복구와 종료 복원은 다른 래퍼가 쓰는 마커를 비정상 종료로 보지 않으므로, 설정된 제공자는 마지막 래퍼가 끝난 뒤에만 원래 값으로 돌아갑니다.
|
|
531
|
+
- 영상 응답에 Codex 도구 호출이 같이 있으면 그 호출을 먼저 Codex에 넘깁니다. 영상 결과는 그 도구 출력이 도착한 뒤에만 상류로 보내고, 답이 없는 함수 호출 옆에 붙이지 않습니다.
|
|
532
|
+
|
|
523
533
|
### 1.8.5 — 2026-11-10
|
|
524
534
|
|
|
525
535
|
- Codex CLI 0.166부터는 스레드 제공자와 앱 서버에 설정된 제공자가 다르면 턴을 거절합니다. 데스크톱 래퍼가 그 프로세스의 `model_provider`를 맞추고, 저장된 스레드 제공자를 갱신한 뒤, 메모리에 있는 스레드를 archive/unarchive해서 Codex가 다시 읽게 합니다. `thread/resume` 전에 합니다. 새 Grok 턴과 openai ↔ `grok_build_cli` 전환이 `verify-app-server`를 통과합니다. 래퍼가 끝나면 이전 `model_provider` 값으로 되돌립니다.
|
|
@@ -622,7 +632,7 @@ codex-grok exec --skip-git-repo-check --sandbox workspace-write '작업 내용'
|
|
|
622
632
|
```sh
|
|
623
633
|
git clone https://github.com/deximple/codex-grok-bridge.git
|
|
624
634
|
cd codex-grok-bridge
|
|
625
|
-
npm test #
|
|
635
|
+
npm test # 317건, 네트워크·추론 없음
|
|
626
636
|
node scripts/codex-grok.mjs
|
|
627
637
|
```
|
|
628
638
|
|
|
@@ -873,7 +883,7 @@ URL과 저장한 파일 경로를 함께 넣습니다. 다운로드가 실패하
|
|
|
873
883
|
## 검증
|
|
874
884
|
|
|
875
885
|
```sh
|
|
876
|
-
npm test #
|
|
886
|
+
npm test # 317건, 외부 추론 없음
|
|
877
887
|
npm run test:coverage # line/branch/function 80% 게이트
|
|
878
888
|
npm run verify:app-server # 실제 app-server 라우팅. 설치된 앱 번들에서도 실행
|
|
879
889
|
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.6",
|
|
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
|
}
|