Skip to content

Commit 5a0b3ee

Browse files
committed
fix: ensure copilot plugin properly sets headers for new messages api
1 parent 3bb1077 commit 5a0b3ee

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

packages/opencode/src/plugin/copilot.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
6161
const info = await getAuth()
6262
if (info.type !== "oauth") return fetch(request, init)
6363

64+
const url = request instanceof URL ? request.href : request.toString()
6465
const { isVision, isAgent } = iife(() => {
6566
try {
6667
const body = typeof init?.body === "string" ? JSON.parse(init.body) : init?.body
6768

6869
// Completions API
69-
if (body?.messages) {
70+
if (body?.messages && url.includes("completions")) {
7071
const last = body.messages[body.messages.length - 1]
7172
return {
7273
isVision: body.messages.some(
@@ -88,6 +89,28 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
8889
isAgent: last?.role !== "user",
8990
}
9091
}
92+
93+
// Messages API
94+
if (body?.messages) {
95+
const last = body.messages[body.messages.length - 1]
96+
const hasNonToolCalls =
97+
Array.isArray(last?.content) && last.content.some((part: any) => part?.type !== "tool_result")
98+
return {
99+
isVision: body.messages.some(
100+
(item: any) =>
101+
Array.isArray(item?.content) &&
102+
item.content.some(
103+
(part: any) =>
104+
part?.type === "image" ||
105+
// images can be nested inside tool_result content
106+
(part?.type === "tool_result" &&
107+
Array.isArray(part?.content) &&
108+
part.content.some((nested: any) => nested?.type === "image")),
109+
),
110+
),
111+
isAgent: !(last?.role === "user" && hasNonToolCalls),
112+
}
113+
}
91114
} catch {}
92115
return { isVision: false, isAgent: false }
93116
})

0 commit comments

Comments
 (0)