Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/CodexAcpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ function buildPromptItems(prompt: acp.ContentBlock[]): UserInput[] {
case "text":
return {type: "text", text: block.text, text_elements: []};
case "image": {
const url = block.uri ?? `data:${block.mimeType};base64,${block.data}`;
const url = isSupportedImageUrl(block.uri) ? block.uri : imageDataUrl(block);
return {type: "image", url};
}
case "resource_link":
Expand All @@ -729,6 +729,22 @@ function buildPromptItems(prompt: acp.ContentBlock[]): UserInput[] {
}).filter((block): block is UserInput => block !== null);
}

function imageDataUrl(block: acp.ContentBlock & { type: "image" }): string {
return `data:${block.mimeType};base64,${block.data}`;
}

function isSupportedImageUrl(uri: string | null | undefined): uri is string {
if (!uri) {
return false;
}
try {
const protocol = new URL(uri).protocol;
return protocol === "http:" || protocol === "https:" || protocol === "data:";
} catch {
return false;
}
}

function isImageMimeType(mimeType: string | null | undefined): mimeType is string {
return mimeType?.startsWith("image/") ?? false;
}
Expand Down
36 changes: 36 additions & 0 deletions src/__tests__/CodexACPAgent/CodexAcpClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,42 @@ describe('ACP server test', { timeout: 40_000 }, () => {
}));
});

it ('should use inline image data when image uri is a local file', async () => {
const { mockFixture, turnStartSpy } = setupPromptFixture({
supportedInputModalities: ["text", "image"],
});

const prompt: acp.ContentBlock[] = [
{ type: "image", mimeType: "image/png", data: "abc123", uri: "file:///Users/test/Desktop/Screenshot%201.png" },
];

await mockFixture.getCodexAcpAgent().prompt({ sessionId: "id", prompt });

expect(turnStartSpy).toHaveBeenCalledWith(expect.objectContaining({
input: [
{ type: "image", url: "data:image/png;base64,abc123" },
]
}));
});

it ('should use inline image data when image uri is client-internal', async () => {
const { mockFixture, turnStartSpy } = setupPromptFixture({
supportedInputModalities: ["text", "image"],
});

const prompt: acp.ContentBlock[] = [
{ type: "image", mimeType: "image/png", data: "abc123", uri: "zed:///agent/pasted-image?name=Image" },
];

await mockFixture.getCodexAcpAgent().prompt({ sessionId: "id", prompt });

expect(turnStartSpy).toHaveBeenCalledWith(expect.objectContaining({
input: [
{ type: "image", url: "data:image/png;base64,abc123" },
]
}));
});

it ('should show rate limits from multiple sources in status', async () => {
const rateLimits: RateLimitsMap = new Map();
rateLimits.set("limit-1", {
Expand Down
Loading