diff options
| author | Aiden Cline <[email protected]> | 2026-01-28 02:04:21 -0500 |
|---|---|---|
| committer | Aiden Cline <[email protected]> | 2026-01-28 02:04:30 -0500 |
| commit | 5a0b3ee673a99944da2d611fd3a60e70054cd481 (patch) | |
| tree | eb63db583668d74e0411e692ac508334815f44d9 /packages | |
| parent | 3bb10773e6b852dd00e09c9ac5afb42ff737ae4e (diff) | |
| download | opencode-5a0b3ee673a99944da2d611fd3a60e70054cd481.tar.gz opencode-5a0b3ee673a99944da2d611fd3a60e70054cd481.zip | |
fix: ensure copilot plugin properly sets headers for new messages api
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/opencode/src/plugin/copilot.ts | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/packages/opencode/src/plugin/copilot.ts b/packages/opencode/src/plugin/copilot.ts index 0be134587..51f29db5e 100644 --- a/packages/opencode/src/plugin/copilot.ts +++ b/packages/opencode/src/plugin/copilot.ts @@ -61,12 +61,13 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> { const info = await getAuth() if (info.type !== "oauth") return fetch(request, init) + const url = request instanceof URL ? request.href : request.toString() const { isVision, isAgent } = iife(() => { try { const body = typeof init?.body === "string" ? JSON.parse(init.body) : init?.body // Completions API - if (body?.messages) { + if (body?.messages && url.includes("completions")) { const last = body.messages[body.messages.length - 1] return { isVision: body.messages.some( @@ -88,6 +89,28 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> { isAgent: last?.role !== "user", } } + + // Messages API + if (body?.messages) { + const last = body.messages[body.messages.length - 1] + const hasNonToolCalls = + Array.isArray(last?.content) && last.content.some((part: any) => part?.type !== "tool_result") + return { + isVision: body.messages.some( + (item: any) => + Array.isArray(item?.content) && + item.content.some( + (part: any) => + part?.type === "image" || + // images can be nested inside tool_result content + (part?.type === "tool_result" && + Array.isArray(part?.content) && + part.content.some((nested: any) => nested?.type === "image")), + ), + ), + isAgent: !(last?.role === "user" && hasNonToolCalls), + } + } } catch {} return { isVision: false, isAgent: false } }) |
