Skip to content

Commit a85120a

Browse files
committed
Support data URLs for image prompts
1 parent 0b39f9e commit a85120a

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/CodexAcpClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ function buildPromptItems(prompt: acp.ContentBlock[]): UserInput[] {
703703
case "text":
704704
return {type: "text", text: block.text, text_elements: []};
705705
case "image": {
706-
const url = shouldUseImageUri(block.uri) ? block.uri : imageDataUrl(block);
706+
const url = isSupportedImageUrl(block.uri) ? block.uri : imageDataUrl(block);
707707
return {type: "image", url};
708708
}
709709
case "resource_link":
@@ -733,13 +733,13 @@ function imageDataUrl(block: acp.ContentBlock & { type: "image" }): string {
733733
return `data:${block.mimeType};base64,${block.data}`;
734734
}
735735

736-
function shouldUseImageUri(uri: string | null | undefined): uri is string {
736+
function isSupportedImageUrl(uri: string | null | undefined): uri is string {
737737
if (!uri) {
738738
return false;
739739
}
740740
try {
741741
const protocol = new URL(uri).protocol;
742-
return protocol === "http:" || protocol === "https:";
742+
return protocol === "http:" || protocol === "https:" || protocol === "data:";
743743
} catch {
744744
return false;
745745
}

src/__tests__/CodexACPAgent/CodexAcpClient.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,24 @@ describe('ACP server test', { timeout: 40_000 }, () => {
14301430
}));
14311431
});
14321432

1433+
it ('should use inline image data when image uri is client-internal', async () => {
1434+
const { mockFixture, turnStartSpy } = setupPromptFixture({
1435+
supportedInputModalities: ["text", "image"],
1436+
});
1437+
1438+
const prompt: acp.ContentBlock[] = [
1439+
{ type: "image", mimeType: "image/png", data: "abc123", uri: "zed:///agent/pasted-image?name=Image" },
1440+
];
1441+
1442+
await mockFixture.getCodexAcpAgent().prompt({ sessionId: "id", prompt });
1443+
1444+
expect(turnStartSpy).toHaveBeenCalledWith(expect.objectContaining({
1445+
input: [
1446+
{ type: "image", url: "data:image/png;base64,abc123" },
1447+
]
1448+
}));
1449+
});
1450+
14331451
it ('should show rate limits from multiple sources in status', async () => {
14341452
const rateLimits: RateLimitsMap = new Map();
14351453
rateLimits.set("limit-1", {

0 commit comments

Comments
 (0)