fix(core): flag images returned by tools for Copilot vision

This commit is contained in:
exe.dev user
2026-11-05 18:03:11 +00:00
Unverified
parent 0a56c0c45e
commit 897cd7733b
2 changed files with 29 additions and 2 deletions
@@ -465,11 +465,13 @@ function requestMetadata(url: string, body: unknown) {
const last = body.input.at(-1)
return {
agent: !isRecord(last) || last.role !== "user",
// Tool results carry their images in `output`, user messages in `content`.
vision: body.input.some(
(item) =>
isRecord(item) &&
Array.isArray(item.content) &&
item.content.some((part) => isRecord(part) && part.type === "input_image"),
[item.content, item.output].some(
(parts) => Array.isArray(parts) && parts.some((part) => isRecord(part) && part.type === "input_image"),
),
),
}
}
@@ -437,6 +437,31 @@ describe("GithubCopilotPlugin", () => {
}),
)
it.effect("flags images returned by tools in Responses requests", () =>
Effect.gen(function* () {
yield* addPlugin()
const event = yield* httpRequest(
new Request("https://api.githubcopilot.com/responses", {
method: "POST",
headers: { authorization: "Bearer token" },
body: JSON.stringify({
input: [
{ role: "user", content: [{ type: "input_text", text: "Take a screenshot." }] },
{ type: "function_call", call_id: "call_1", name: "screenshot", arguments: "{}" },
{
type: "function_call_output",
call_id: "call_1",
output: [{ type: "input_image", image_url: "data:image/png;base64,AAAA" }],
},
],
}),
}),
)
expect(event.request.headers.get("copilot-vision-request")).toBe("true")
expect(event.request.headers.get("x-initiator")).toBe("agent")
}),
)
it.effect("keeps a declared agent initiator when the body looks user-initiated", () =>
Effect.gen(function* () {
yield* addPlugin()