mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 13:05:14 +03:00
fix(core): mark Copilot steps with tool images as agent-initiated
This commit is contained in:
@@ -478,8 +478,10 @@ function requestMetadata(url: string, body: unknown) {
|
||||
if (!Array.isArray(body.messages)) return { agent: false, vision: false }
|
||||
const last = body.messages.at(-1)
|
||||
if (url.includes("completions")) {
|
||||
const previous = body.messages.at(-2)
|
||||
return {
|
||||
agent: !isRecord(last) || last.role !== "user",
|
||||
// Chat Completions moves tool-result images into a user message after the tool messages.
|
||||
agent: !isRecord(last) || last.role !== "user" || (isRecord(previous) && previous.role === "tool"),
|
||||
vision: body.messages.some(
|
||||
(message) =>
|
||||
isRecord(message) &&
|
||||
|
||||
@@ -462,6 +462,32 @@ describe("GithubCopilotPlugin", () => {
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("treats tool images moved into a Chat Completions user message as agent-initiated", () =>
|
||||
Effect.gen(function* () {
|
||||
yield* addPlugin()
|
||||
const event = yield* httpRequest(
|
||||
new Request("https://api.githubcopilot.com/chat/completions", {
|
||||
method: "POST",
|
||||
headers: { authorization: "Bearer token" },
|
||||
body: JSON.stringify({
|
||||
messages: [
|
||||
{ role: "user", content: "Take a screenshot." },
|
||||
{
|
||||
role: "assistant",
|
||||
content: null,
|
||||
tool_calls: [{ id: "call_1", type: "function", function: { name: "screenshot", arguments: "{}" } }],
|
||||
},
|
||||
{ role: "tool", tool_call_id: "call_1", content: "" },
|
||||
{ role: "user", content: [{ type: "image_url", image_url: { url: "data:image/png;base64,AAAA" } }] },
|
||||
],
|
||||
}),
|
||||
}),
|
||||
)
|
||||
expect(event.request.headers.get("x-initiator")).toBe("agent")
|
||||
expect(event.request.headers.get("copilot-vision-request")).toBe("true")
|
||||
}),
|
||||
)
|
||||
|
||||
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