Skip to content
Merged
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
14 changes: 14 additions & 0 deletions apps/vscode-e2e/fixtures/openrouter.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
{
"fixtures": [
{
"match": {
"userMessage": "openrouter-image-e2e"
},
"response": {
"toolCalls": [
{
"name": "attempt_completion",
"arguments": "{\"result\":\"Red\"}",
"id": "call_openrouter_image_001"
}
]
}
},
{
"match": {
"userMessage": "openrouter-identity-smoke"
Expand Down
50 changes: 49 additions & 1 deletion apps/vscode-e2e/src/suite/providers/openrouter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type CapturedOpenRouterRequest = {
xTitle: string | undefined
httpReferer: string | undefined
userAgent: string | undefined
userMessageContent?: unknown
}

function getRequestUrl(input: RequestInfo | URL): string {
Expand Down Expand Up @@ -40,10 +41,22 @@ function installOpenRouterRequestCapture(capture: CapturedOpenRouterRequest[], b
if (new URL(url).origin === targetOrigin) {
const xTitle = getHeaderValue(init, "X-Title") ?? getHeaderValue(init, "x-title")
if (xTitle !== undefined) {
let userMessageContent: unknown
if (init?.body && typeof init.body === "string") {
try {
const body = JSON.parse(init.body)
const messages: Array<{ role?: string; content?: unknown }> = body.messages ?? []
const lastUser = [...messages].reverse().find((m) => m.role === "user")
userMessageContent = lastUser?.content
} catch {
// ignore parse errors
}
}
capture.push({
xTitle,
httpReferer: getHeaderValue(init, "HTTP-Referer") ?? getHeaderValue(init, "http-referer"),
userAgent: getHeaderValue(init, "User-Agent") ?? getHeaderValue(init, "user-agent"),
userMessageContent,
})
}
}
Expand Down Expand Up @@ -82,7 +95,7 @@ suite("OpenRouter provider", function () {
await globalThis.api.setConfiguration({
apiProvider: "openrouter" as const,
openRouterApiKey: aimockUrl && !isRecord ? "mock-key" : OPENROUTER_API_KEY!,
openRouterModelId: "openai/gpt-4.1",
openRouterModelId: "anthropic/claude-haiku-4-5",
...(aimockUrl && { openRouterBaseUrl: `${aimockUrl}/v1` }),
})
})
Expand All @@ -92,6 +105,41 @@ suite("OpenRouter provider", function () {
restoreFetch = undefined
})

test("Should forward base64 images as image_url content parts in outbound request", async () => {
requests.length = 0

// 8x8 red PNG (1x1 is too small and rejected by Anthropic's vision API)
const base64Png =
"iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAEklEQVR4nGP4z8CAFWEXHbQSACj/P8Fu7N9hAAAAAElFTkSuQmCC"
const dataUri = `data:image/png;base64,${base64Png}`

const api = globalThis.api
const taskId = await api.startNewTask({
configuration: { mode: "ask", autoApprovalEnabled: true },
text: "openrouter-image-e2e: describe the image in one word.",
images: [dataUri],
})

await waitUntilCompleted({ api, taskId })

// Find the first request that contains the probe tag
const probeRequest = requests.find((r) => {
const content = r.userMessageContent
return Array.isArray(content) && JSON.stringify(content).includes("openrouter-image-e2e")
})

assert.ok(probeRequest, "Should have captured an outbound request containing the probe tag")

const content = probeRequest.userMessageContent as Array<{ type: string; image_url?: { url: string } }>
const imagePart = content.find((p) => p.type === "image_url")
assert.ok(imagePart, "User message should contain an image_url content part")
assert.strictEqual(
imagePart?.image_url?.url,
dataUri,
"image_url.url should be the original data URI passed via startNewTask",
)
})

test("Should identify as Zoo Code in outbound DEFAULT_HEADERS", async () => {
requests.length = 0

Expand Down
Loading
Loading