fix: ensure copilot plugin properly sets headers for new messages api
This commit is contained in:
@@ -61,12 +61,13 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
|
|||||||
const info = await getAuth()
|
const info = await getAuth()
|
||||||
if (info.type !== "oauth") return fetch(request, init)
|
if (info.type !== "oauth") return fetch(request, init)
|
||||||
|
|
||||||
|
const url = request instanceof URL ? request.href : request.toString()
|
||||||
const { isVision, isAgent } = iife(() => {
|
const { isVision, isAgent } = iife(() => {
|
||||||
try {
|
try {
|
||||||
const body = typeof init?.body === "string" ? JSON.parse(init.body) : init?.body
|
const body = typeof init?.body === "string" ? JSON.parse(init.body) : init?.body
|
||||||
|
|
||||||
// Completions API
|
// Completions API
|
||||||
if (body?.messages) {
|
if (body?.messages && url.includes("completions")) {
|
||||||
const last = body.messages[body.messages.length - 1]
|
const last = body.messages[body.messages.length - 1]
|
||||||
return {
|
return {
|
||||||
isVision: body.messages.some(
|
isVision: body.messages.some(
|
||||||
@@ -88,6 +89,28 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
|
|||||||
isAgent: last?.role !== "user",
|
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 {}
|
} catch {}
|
||||||
return { isVision: false, isAgent: false }
|
return { isVision: false, isAgent: false }
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user