Skip to content

Commit cec3482

Browse files
committed
fix: support codex app-server image understanding
1 parent df58839 commit cec3482

517 files changed

Lines changed: 15142 additions & 276 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Docs: https://docs.openclaw.ai
1616

1717
### Fixes
1818

19+
- Codex/media understanding: support `codex/*` image models through bounded Codex app-server image turns, while keeping `openai-codex/*` on the OpenAI Codex OAuth route and validating app-server responses against generated protocol contracts. Fixes #70201.
1920
- Providers/Google: honor the private-network SSRF opt-in for Gemini image generation requests, so trusted proxy setups that resolve Google API hosts to private addresses can use `image_generate`. Fixes #67216.
2021
- Agents/transport: stop embedded runs from lowering the process-wide undici stream timeouts, so slow Gemini image generation and other long-running provider requests no longer inherit short run-attempt headers timeouts. Fixes #70423. Thanks @giangthb.
2122
- Providers/OpenRouter: send image-understanding prompts as user text before image parts, restoring non-empty vision responses for OpenRouter multimodal models. Fixes #70410.

‎docs/cli/infer.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ This table maps common inference tasks to the corresponding infer command.
121121
- Use `--json` when the output will be consumed by another command or script.
122122
- Use `--provider` or `--model provider/model` when a specific backend is required.
123123
- For `image describe`, `audio transcribe`, and `video describe`, `--model` must use the form `<provider/model>`.
124-
- For `image describe`, an explicit `--model` runs that provider/model directly. The model must be image-capable in the model catalog or provider config.
124+
- For `image describe`, an explicit `--model` runs that provider/model directly. The model must be image-capable in the model catalog or provider config. `codex/<model>` runs a bounded Codex app-server image-understanding turn; `openai-codex/<model>` uses the OpenAI Codex OAuth provider path.
125125
- Stateless execution commands default to local.
126126
- Gateway-managed state commands default to gateway.
127127
- The normal local path does not require the gateway to be running.

‎docs/nodes/media-understanding.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,11 @@ If you omit `capabilities`, the entry is eligible for the list it appears in.
222222

223223
## Provider support matrix (OpenClaw integrations)
224224

225-
| Capability | Provider integration | Notes |
226-
| ---------- | -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
227-
| Image | OpenAI, OpenRouter, Anthropic, Google, MiniMax, Moonshot, Qwen, Z.AI, config providers | Vendor plugins register image support; MiniMax and MiniMax OAuth both use `MiniMax-VL-01`; image-capable config providers auto-register. |
228-
| Audio | OpenAI, Groq, Deepgram, Google, Mistral | Provider transcription (Whisper/Deepgram/Gemini/Voxtral). |
229-
| Video | Google, Qwen, Moonshot | Provider video understanding via vendor plugins; Qwen video understanding uses the Standard DashScope endpoints. |
225+
| Capability | Provider integration | Notes |
226+
| ---------- | ---------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
227+
| Image | OpenAI, OpenAI Codex OAuth, Codex app-server, OpenRouter, Anthropic, Google, MiniMax, Moonshot, Qwen, Z.AI, config providers | Vendor plugins register image support; `openai-codex/*` uses OAuth provider plumbing; `codex/*` uses a bounded Codex app-server turn; MiniMax and MiniMax OAuth both use `MiniMax-VL-01`; image-capable config providers auto-register. |
228+
| Audio | OpenAI, Groq, Deepgram, Google, Mistral | Provider transcription (Whisper/Deepgram/Gemini/Voxtral). |
229+
| Video | Google, Qwen, Moonshot | Provider video understanding via vendor plugins; Qwen video understanding uses the Standard DashScope endpoints. |
230230

231231
MiniMax note:
232232

‎docs/plugins/codex-harness.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ Codex OAuth configs should use `openai-codex/gpt-*`; new native app-server
5757
harness configs should use `openai/gpt-*` plus `embeddedHarness.runtime:
5858
"codex"`.
5959

60+
`agents.defaults.imageModel` follows the same prefix split. Use
61+
`openai-codex/gpt-*` when image understanding should run through the OpenAI
62+
Codex OAuth provider path. Use `codex/gpt-*` when image understanding should run
63+
through a bounded Codex app-server turn. The Codex app-server model must
64+
advertise image input support; text-only Codex models fail before the media turn
65+
starts.
66+
6067
Use `/status` to confirm the effective harness for the current session. If the
6168
selection is surprising, enable debug logging for the `agents/harness` subsystem
6269
and inspect the gateway's structured `agent harness selected` record. It

‎extensions/codex/index.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe("codex plugin", () => {
1616
it("registers the codex provider and agent harness", () => {
1717
const registerAgentHarness = vi.fn();
1818
const registerCommand = vi.fn();
19+
const registerMediaUnderstandingProvider = vi.fn();
1920
const registerProvider = vi.fn();
2021

2122
plugin.register(
@@ -28,6 +29,7 @@ describe("codex plugin", () => {
2829
runtime: {} as never,
2930
registerAgentHarness,
3031
registerCommand,
32+
registerMediaUnderstandingProvider,
3133
registerProvider,
3234
}),
3335
);
@@ -38,6 +40,13 @@ describe("codex plugin", () => {
3840
label: "Codex agent harness",
3941
dispose: expect.any(Function),
4042
});
43+
expect(registerMediaUnderstandingProvider.mock.calls[0]?.[0]).toMatchObject({
44+
id: "codex",
45+
capabilities: ["image"],
46+
defaultModels: { image: "gpt-5.5" },
47+
describeImage: expect.any(Function),
48+
describeImages: expect.any(Function),
49+
});
4150
expect(registerCommand.mock.calls[0]?.[0]).toMatchObject({
4251
name: "codex",
4352
description: "Inspect and control the Codex app-server harness",

‎extensions/codex/index.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
22
import { createCodexAppServerAgentHarness } from "./harness.js";
3+
import { buildCodexMediaUnderstandingProvider } from "./media-understanding-provider.js";
34
import { buildCodexProvider } from "./provider.js";
45
import { createCodexCommand } from "./src/commands.js";
56

@@ -10,6 +11,9 @@ export default definePluginEntry({
1011
register(api) {
1112
api.registerAgentHarness(createCodexAppServerAgentHarness({ pluginConfig: api.pluginConfig }));
1213
api.registerProvider(buildCodexProvider({ pluginConfig: api.pluginConfig }));
14+
api.registerMediaUnderstandingProvider(
15+
buildCodexMediaUnderstandingProvider({ pluginConfig: api.pluginConfig }),
16+
);
1317
api.registerCommand(createCodexCommand({ pluginConfig: api.pluginConfig }));
1418
},
1519
});
Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
import { describe, expect, it, vi } from "vitest";
2+
import { buildCodexMediaUnderstandingProvider } from "./media-understanding-provider.js";
3+
import type { CodexAppServerClient } from "./src/app-server/client.js";
4+
import type { CodexServerNotification, JsonValue } from "./src/app-server/protocol.js";
5+
6+
function codexModel(inputModalities: string[] = ["text", "image"]) {
7+
return {
8+
id: "gpt-5.4",
9+
model: "gpt-5.4",
10+
upgrade: null,
11+
upgradeInfo: null,
12+
availabilityNux: null,
13+
displayName: "gpt-5.4",
14+
description: "GPT-5.4",
15+
hidden: false,
16+
supportedReasoningEfforts: [{ reasoningEffort: "low", description: "fast" }],
17+
defaultReasoningEffort: "low",
18+
inputModalities,
19+
supportsPersonality: false,
20+
additionalSpeedTiers: [],
21+
isDefault: true,
22+
};
23+
}
24+
25+
function threadStartResult() {
26+
return {
27+
thread: {
28+
id: "thread-1",
29+
forkedFromId: null,
30+
preview: "",
31+
ephemeral: true,
32+
modelProvider: "openai",
33+
createdAt: 1,
34+
updatedAt: 1,
35+
status: { type: "idle" },
36+
path: null,
37+
cwd: "/tmp/openclaw-agent",
38+
cliVersion: "0.118.0",
39+
source: "unknown",
40+
agentNickname: null,
41+
agentRole: null,
42+
gitInfo: null,
43+
name: null,
44+
turns: [],
45+
},
46+
model: "gpt-5.4",
47+
modelProvider: "openai",
48+
serviceTier: null,
49+
cwd: "/tmp/openclaw-agent",
50+
instructionSources: [],
51+
approvalPolicy: "never",
52+
approvalsReviewer: "user",
53+
sandbox: { type: "dangerFullAccess" },
54+
permissionProfile: null,
55+
reasoningEffort: null,
56+
};
57+
}
58+
59+
function turnStartResult(status = "inProgress", items: JsonValue[] = []) {
60+
return {
61+
turn: {
62+
id: "turn-1",
63+
status,
64+
items,
65+
error: null,
66+
startedAt: null,
67+
completedAt: null,
68+
durationMs: null,
69+
},
70+
};
71+
}
72+
73+
function createFakeClient(options?: {
74+
inputModalities?: string[];
75+
completeWithItems?: boolean;
76+
notifyError?: string;
77+
}) {
78+
const notifications = new Set<(notification: CodexServerNotification) => void>();
79+
const requests: Array<{ method: string; params?: JsonValue }> = [];
80+
const request = vi.fn(async (method: string, params?: JsonValue) => {
81+
requests.push({ method, params });
82+
if (method === "model/list") {
83+
return {
84+
data: [codexModel(options?.inputModalities)],
85+
nextCursor: null,
86+
};
87+
}
88+
if (method === "thread/start") {
89+
return threadStartResult();
90+
}
91+
if (method === "turn/start") {
92+
if (options?.notifyError) {
93+
for (const notify of notifications) {
94+
notify({
95+
method: "error",
96+
params: {
97+
threadId: "thread-1",
98+
turnId: "turn-1",
99+
error: {
100+
message: options.notifyError,
101+
codexErrorInfo: null,
102+
additionalDetails: null,
103+
},
104+
willRetry: false,
105+
},
106+
});
107+
}
108+
} else if (!options?.completeWithItems) {
109+
for (const notify of notifications) {
110+
notify({
111+
method: "item/agentMessage/delta",
112+
params: {
113+
threadId: "thread-1",
114+
turnId: "turn-1",
115+
itemId: "msg-1",
116+
delta: "A red square.",
117+
},
118+
});
119+
notify({
120+
method: "turn/completed",
121+
params: {
122+
threadId: "thread-1",
123+
turnId: "turn-1",
124+
turn: turnStartResult("completed").turn,
125+
},
126+
});
127+
}
128+
}
129+
return turnStartResult(
130+
options?.completeWithItems ? "completed" : "inProgress",
131+
options?.completeWithItems
132+
? [
133+
{
134+
id: "msg-1",
135+
type: "agentMessage",
136+
text: "A blue circle.",
137+
phase: null,
138+
memoryCitation: null,
139+
},
140+
]
141+
: [],
142+
);
143+
}
144+
return {};
145+
});
146+
147+
const client = {
148+
request,
149+
addNotificationHandler(handler: (notification: CodexServerNotification) => void) {
150+
notifications.add(handler);
151+
return () => notifications.delete(handler);
152+
},
153+
} as unknown as CodexAppServerClient;
154+
155+
return { client, requests };
156+
}
157+
158+
describe("codex media understanding provider", () => {
159+
it("runs image understanding through a bounded Codex app-server turn", async () => {
160+
const { client, requests } = createFakeClient();
161+
const provider = buildCodexMediaUnderstandingProvider({
162+
clientFactory: async () => client,
163+
});
164+
165+
const result = await provider.describeImage?.({
166+
buffer: Buffer.from("image-bytes"),
167+
fileName: "image.png",
168+
mime: "image/png",
169+
provider: "codex",
170+
model: "gpt-5.4",
171+
prompt: "Describe briefly.",
172+
timeoutMs: 30_000,
173+
cfg: {},
174+
agentDir: "/tmp/openclaw-agent",
175+
});
176+
177+
expect(result).toEqual({ text: "A red square.", model: "gpt-5.4" });
178+
expect(requests.map((entry) => entry.method)).toEqual([
179+
"model/list",
180+
"thread/start",
181+
"turn/start",
182+
]);
183+
expect(requests[1]?.params).toMatchObject({
184+
model: "gpt-5.4",
185+
modelProvider: "openai",
186+
approvalPolicy: "never",
187+
sandbox: "read-only",
188+
dynamicTools: [],
189+
ephemeral: true,
190+
persistExtendedHistory: false,
191+
});
192+
expect(requests[2]?.params).toMatchObject({
193+
threadId: "thread-1",
194+
approvalPolicy: "never",
195+
model: "gpt-5.4",
196+
input: [
197+
{ type: "text", text: "Describe briefly.", text_elements: [] },
198+
{ type: "image", url: "data:image/png;base64,aW1hZ2UtYnl0ZXM=" },
199+
],
200+
});
201+
});
202+
203+
it("extracts text from terminal turn items", async () => {
204+
const { client } = createFakeClient({ completeWithItems: true });
205+
const provider = buildCodexMediaUnderstandingProvider({
206+
clientFactory: async () => client,
207+
});
208+
209+
const result = await provider.describeImages?.({
210+
images: [{ buffer: Buffer.from("image-bytes"), fileName: "image.png", mime: "image/png" }],
211+
provider: "codex",
212+
model: "gpt-5.4",
213+
prompt: "Describe briefly.",
214+
timeoutMs: 30_000,
215+
cfg: {},
216+
agentDir: "/tmp/openclaw-agent",
217+
});
218+
219+
expect(result).toEqual({ text: "A blue circle.", model: "gpt-5.4" });
220+
});
221+
222+
it("rejects text-only Codex app-server models before starting a turn", async () => {
223+
const { client, requests } = createFakeClient({ inputModalities: ["text"] });
224+
const provider = buildCodexMediaUnderstandingProvider({
225+
clientFactory: async () => client,
226+
});
227+
228+
await expect(
229+
provider.describeImage?.({
230+
buffer: Buffer.from("image-bytes"),
231+
fileName: "image.png",
232+
mime: "image/png",
233+
provider: "codex",
234+
model: "gpt-5.4",
235+
timeoutMs: 30_000,
236+
cfg: {},
237+
agentDir: "/tmp/openclaw-agent",
238+
}),
239+
).rejects.toThrow("Codex app-server model does not support images: gpt-5.4");
240+
expect(requests.map((entry) => entry.method)).toEqual(["model/list"]);
241+
});
242+
243+
it("surfaces Codex app-server turn errors", async () => {
244+
const { client } = createFakeClient({ notifyError: "vision unavailable" });
245+
const provider = buildCodexMediaUnderstandingProvider({
246+
clientFactory: async () => client,
247+
});
248+
249+
await expect(
250+
provider.describeImage?.({
251+
buffer: Buffer.from("image-bytes"),
252+
fileName: "image.png",
253+
mime: "image/png",
254+
provider: "codex",
255+
model: "gpt-5.4",
256+
timeoutMs: 30_000,
257+
cfg: {},
258+
agentDir: "/tmp/openclaw-agent",
259+
}),
260+
).rejects.toThrow("vision unavailable");
261+
});
262+
});

0 commit comments

Comments
 (0)