mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-20 18:57:17 +03:00
fix(core): flag images returned by tools for Copilot vision
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user