惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
J
Java Code Geeks
博客园 - 聂微东
量子位
C
Check Point Blog
T
The Blog of Author Tim Ferriss
T
Tailwind CSS Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
B
Blog
罗磊的独立博客
腾讯CDC
GbyAI
GbyAI
博客园 - 【当耐特】
A
About on SuperTechFans
M
MIT News - Artificial intelligence
U
Unit 42
D
Docker
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Y
Y Combinator Blog
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
feat(media-understanding): add structured extraction runt...
2026-05-11 · via Recent Commits to openclaw:main

@@ -76,6 +76,7 @@ function createFakeClient(options?: {

7676

completeWithItems?: boolean;

7777

notifyError?: string;

7878

approvalRequestMethod?: string;

79+

responseText?: string;

7980

}) {

8081

const notifications = new Set<(notification: CodexServerNotification) => void>();

8182

const requestHandlers = new Set<(request: { method: string }) => JsonValue | undefined>();

@@ -125,7 +126,7 @@ function createFakeClient(options?: {

125126

threadId: "thread-1",

126127

turnId: "turn-1",

127128

itemId: "msg-1",

128-

delta: "A red square.",

129+

delta: options?.responseText ?? "A red square.",

129130

},

130131

});

131132

notify({

@@ -145,7 +146,7 @@ function createFakeClient(options?: {

145146

{

146147

id: "msg-1",

147148

type: "agentMessage",

148-

text: "A blue circle.",

149+

text: options?.responseText ?? "A blue circle.",

149150

phase: null,

150151

memoryCitation: null,

151152

},

@@ -298,4 +299,161 @@ describe("codex media understanding provider", () => {

298299

}),

299300

).rejects.toThrow("vision unavailable");

300301

});

302+303+

it("runs structured extraction through the same bounded Codex app-server path", async () => {

304+

const { client, requests } = createFakeClient({

305+

responseText: '{"summary":"red square","tags":["shape"]}',

306+

});

307+

const provider = buildCodexMediaUnderstandingProvider({

308+

clientFactory: async () => client,

309+

});

310+311+

const result = await provider.extractStructured?.({

312+

input: [

313+

{ type: "text", text: "Extract searchable evidence." },

314+

{

315+

type: "image",

316+

buffer: Buffer.from("image-bytes"),

317+

fileName: "image.png",

318+

mime: "image/png",

319+

},

320+

],

321+

instructions: "Return a compact evidence object.",

322+

schemaName: "example.media",

323+

jsonSchema: {

324+

type: "object",

325+

properties: {

326+

summary: { type: "string" },

327+

tags: { type: "array", items: { type: "string" } },

328+

},

329+

required: ["summary"],

330+

},

331+

provider: "codex",

332+

model: "gpt-5.4",

333+

timeoutMs: 30_000,

334+

cfg: {},

335+

agentDir: "/tmp/openclaw-agent",

336+

});

337+338+

expect(result).toEqual({

339+

text: '{"summary":"red square","tags":["shape"]}',

340+

parsed: { summary: "red square", tags: ["shape"] },

341+

model: "gpt-5.4",

342+

provider: "codex",

343+

contentType: "json",

344+

});

345+

expect(requests.map((entry) => entry.method)).toEqual([

346+

"model/list",

347+

"thread/start",

348+

"turn/start",

349+

]);

350+

expect(requests[1]?.params).toMatchObject({

351+

model: "gpt-5.4",

352+

modelProvider: "openai",

353+

approvalPolicy: "on-request",

354+

sandbox: "read-only",

355+

dynamicTools: [],

356+

ephemeral: true,

357+

persistExtendedHistory: false,

358+

});

359+

expect(requests[2]?.params).toMatchObject({

360+

threadId: "thread-1",

361+

approvalPolicy: "on-request",

362+

model: "gpt-5.4",

363+

input: [

364+

expect.objectContaining({

365+

type: "text",

366+

text: expect.stringContaining("Return valid JSON only"),

367+

}),

368+

{ type: "text", text: "Extract searchable evidence.", text_elements: [] },

369+

{ type: "image", url: "data:image/png;base64,aW1hZ2UtYnl0ZXM=" },

370+

],

371+

});

372+

});

373+374+

it("rejects text-only structured extraction before starting a turn", async () => {

375+

const { client, requests } = createFakeClient({

376+

inputModalities: ["text"],

377+

responseText: '{"summary":"only text"}',

378+

});

379+

const provider = buildCodexMediaUnderstandingProvider({

380+

clientFactory: async () => client,

381+

});

382+383+

await expect(

384+

provider.extractStructured?.({

385+

input: [{ type: "text", text: "The answer is only text." }],

386+

instructions: "Return summary JSON.",

387+

provider: "codex",

388+

model: "gpt-5.4",

389+

timeoutMs: 30_000,

390+

cfg: {},

391+

agentDir: "/tmp/openclaw-agent",

392+

}),

393+

).rejects.toThrow("Codex structured extraction requires at least one image input.");

394+

expect(requests).toEqual([]);

395+

});

396+397+

it("returns a controlled error when structured JSON parsing fails", async () => {

398+

const { client } = createFakeClient({ responseText: "not json" });

399+

const provider = buildCodexMediaUnderstandingProvider({

400+

clientFactory: async () => client,

401+

});

402+403+

await expect(

404+

provider.extractStructured?.({

405+

input: [

406+

{ type: "text", text: "Extract JSON." },

407+

{

408+

type: "image",

409+

buffer: Buffer.from("image-bytes"),

410+

fileName: "image.png",

411+

mime: "image/png",

412+

},

413+

],

414+

instructions: "Return summary JSON.",

415+

provider: "codex",

416+

model: "gpt-5.4",

417+

timeoutMs: 30_000,

418+

cfg: {},

419+

agentDir: "/tmp/openclaw-agent",

420+

}),

421+

).rejects.toThrow("Codex structured extraction returned invalid JSON.");

422+

});

423+424+

it("validates structured extraction JSON against the requested schema", async () => {

425+

const { client } = createFakeClient({

426+

responseText: '{"summary":123,"tags":["shape"]}',

427+

});

428+

const provider = buildCodexMediaUnderstandingProvider({

429+

clientFactory: async () => client,

430+

});

431+432+

await expect(

433+

provider.extractStructured?.({

434+

input: [

435+

{ type: "text", text: "Extract JSON." },

436+

{

437+

type: "image",

438+

buffer: Buffer.from("image-bytes"),

439+

fileName: "image.png",

440+

mime: "image/png",

441+

},

442+

],

443+

instructions: "Return summary JSON.",

444+

jsonSchema: {

445+

type: "object",

446+

properties: {

447+

summary: { type: "string" },

448+

},

449+

required: ["summary"],

450+

},

451+

provider: "codex",

452+

model: "gpt-5.4",

453+

timeoutMs: 30_000,

454+

cfg: {},

455+

agentDir: "/tmp/openclaw-agent",

456+

}),

457+

).rejects.toThrow("Codex structured extraction JSON did not match schema");

458+

});

301459

});