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

推荐订阅源

Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
GbyAI
GbyAI
aimingoo的专栏
aimingoo的专栏
L
LangChain Blog
I
InfoQ
D
Docker
F
Fortinet All Blogs
Y
Y Combinator Blog
Martin Fowler
Martin Fowler
月光博客
月光博客
B
Blog
Engineering at Meta
Engineering at Meta
T
Tailwind CSS Blog
罗磊的独立博客
博客园_首页
G
Google Developers Blog
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
D
DataBreaches.Net
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
B
Blog RSS Feed
IT之家
IT之家
V
V2EX

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
fix(openai): send image edits as multipart uploads (#7065...
steipete · 2026-04-24 · via Recent Commits to openclaw:main

@@ -4,11 +4,13 @@ import { buildOpenAIImageGenerationProvider } from "./image-generation-provider.

44

const {

55

resolveApiKeyForProviderMock,

66

postJsonRequestMock,

7+

postMultipartRequestMock,

78

assertOkOrThrowHttpErrorMock,

89

resolveProviderHttpRequestConfigMock,

910

} = vi.hoisted(() => ({

1011

resolveApiKeyForProviderMock: vi.fn(async () => ({ apiKey: "openai-key" })),

1112

postJsonRequestMock: vi.fn(),

13+

postMultipartRequestMock: vi.fn(),

1214

assertOkOrThrowHttpErrorMock: vi.fn(async () => {}),

1315

resolveProviderHttpRequestConfigMock: vi.fn((params) => ({

1416

baseUrl: params.baseUrl ?? params.defaultBaseUrl,

@@ -25,16 +27,22 @@ vi.mock("openclaw/plugin-sdk/provider-auth-runtime", () => ({

2527

vi.mock("openclaw/plugin-sdk/provider-http", () => ({

2628

assertOkOrThrowHttpError: assertOkOrThrowHttpErrorMock,

2729

postJsonRequest: postJsonRequestMock,

30+

postMultipartRequest: postMultipartRequestMock,

2831

resolveProviderHttpRequestConfig: resolveProviderHttpRequestConfigMock,

2932

}));

30333134

function mockGeneratedPngResponse() {

35+

const response = {

36+

json: async () => ({

37+

data: [{ b64_json: Buffer.from("png-bytes").toString("base64") }],

38+

}),

39+

};

3240

postJsonRequestMock.mockResolvedValue({

33-

response: {

34-

json: async () => ({

35-

data: [{ b64_json: Buffer.from("png-bytes").toString("base64") }],

36-

}),

37-

},

41+

response,

42+

release: vi.fn(async () => {}),

43+

});

44+

postMultipartRequestMock.mockResolvedValue({

45+

response,

3846

release: vi.fn(async () => {}),

3947

});

4048

}

@@ -43,6 +51,7 @@ describe("openai image generation provider", () => {

4351

afterEach(() => {

4452

resolveApiKeyForProviderMock.mockClear();

4553

postJsonRequestMock.mockReset();

54+

postMultipartRequestMock.mockReset();

4655

assertOkOrThrowHttpErrorMock.mockClear();

4756

resolveProviderHttpRequestConfigMock.mockClear();

4857

vi.unstubAllEnvs();

@@ -212,28 +221,71 @@ describe("openai image generation provider", () => {

212221

],

213222

});

214223215-

expect(postJsonRequestMock).toHaveBeenCalledWith(

224+

expect(postMultipartRequestMock).toHaveBeenCalledWith(

216225

expect.objectContaining({

217226

url: "https://api.openai.com/v1/images/edits",

218-

body: expect.objectContaining({

219-

model: "gpt-image-2",

220-

prompt: "Change only the background to pale blue",

221-

n: 2,

222-

size: "1024x1536",

223-

images: [

224-

{

225-

image_url: "data:image/png;base64,cG5nLWJ5dGVz",

226-

},

227-

{

228-

image_url: "data:image/jpeg;base64,anBlZy1ieXRlcw==",

229-

},

230-

],

231-

}),

227+

body: expect.any(FormData),

228+

allowPrivateNetwork: false,

229+

dispatcherPolicy: undefined,

230+

fetchFn: fetch,

232231

}),

233232

);

233+

const editCallArgs = postMultipartRequestMock.mock.calls[0]?.[0] as {

234+

headers: Headers;

235+

body: FormData;

236+

};

237+

expect(editCallArgs.headers.has("Content-Type")).toBe(false);

238+

const form = editCallArgs.body;

239+

expect(form.get("model")).toBe("gpt-image-2");

240+

expect(form.get("prompt")).toBe("Change only the background to pale blue");

241+

expect(form.get("n")).toBe("2");

242+

expect(form.get("size")).toBe("1024x1536");

243+

const images = form.getAll("image[]") as File[];

244+

expect(images).toHaveLength(2);

245+

expect(images[0]?.name).toBe("reference.png");

246+

expect(images[0]?.type).toBe("image/png");

247+

expect(images[1]?.name).toBe("style.jpg");

248+

expect(images[1]?.type).toBe("image/jpeg");

249+

expect(postJsonRequestMock).not.toHaveBeenCalledWith(

250+

expect.objectContaining({ url: "https://api.openai.com/v1/images/edits" }),

251+

);

234252

expect(result.images).toHaveLength(1);

235253

});

236254255+

it("forwards SSRF guard fields to multipart edit requests", async () => {

256+

mockGeneratedPngResponse();

257+258+

const provider = buildOpenAIImageGenerationProvider();

259+

await provider.generateImage({

260+

provider: "openai",

261+

model: "gpt-image-2",

262+

prompt: "Edit cat",

263+

cfg: {

264+

models: {

265+

providers: {

266+

openai: {

267+

baseUrl: "http://127.0.0.1:44080/v1",

268+

models: [],

269+

},

270+

},

271+

},

272+

},

273+

inputImages: [{ buffer: Buffer.from("png-bytes"), mimeType: "image/png" }],

274+

});

275+276+

expect(postMultipartRequestMock).toHaveBeenCalledWith(

277+

expect.objectContaining({

278+

url: "http://127.0.0.1:44080/v1/images/edits",

279+

allowPrivateNetwork: false,

280+

dispatcherPolicy: undefined,

281+

fetchFn: fetch,

282+

}),

283+

);

284+

expect(postJsonRequestMock).not.toHaveBeenCalledWith(

285+

expect.objectContaining({ url: "http://127.0.0.1:44080/v1/images/edits" }),

286+

);

287+

});

288+237289

describe("azure openai support", () => {

238290

it("uses api-key header and deployment-scoped URL for Azure .openai.azure.com hosts", async () => {

239291

mockGeneratedPngResponse();

@@ -386,9 +438,10 @@ describe("openai image generation provider", () => {

386438

],

387439

});

388440389-

expect(postJsonRequestMock).toHaveBeenCalledWith(

441+

expect(postMultipartRequestMock).toHaveBeenCalledWith(

390442

expect.objectContaining({

391443

url: "https://myresource.openai.azure.com/openai/deployments/gpt-image-2/images/edits?api-version=2024-12-01-preview",

444+

body: expect.any(FormData),

392445

}),

393446

);

394447

});