Merge pull request #2125 from zhzy0077/fix/copilot-invalid-initiator
fix(chat-headers): skip x-initiator override for @ai-sdk/github-copilot models
This commit is contained in:
@@ -106,4 +106,41 @@ describe("createChatHeadersHandler", () => {
|
||||
|
||||
expect(output.headers["x-initiator"]).toBeUndefined()
|
||||
})
|
||||
|
||||
test("skips x-initiator override when model uses @ai-sdk/github-copilot", async () => {
|
||||
const handler = createChatHeadersHandler({
|
||||
ctx: {
|
||||
client: {
|
||||
session: {
|
||||
message: async () => ({
|
||||
data: {
|
||||
parts: [
|
||||
{
|
||||
type: "text",
|
||||
text: `notification\n${OMO_INTERNAL_INITIATOR_MARKER}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
},
|
||||
},
|
||||
} as never,
|
||||
})
|
||||
const output: { headers: Record<string, string> } = { headers: {} }
|
||||
|
||||
await handler(
|
||||
{
|
||||
sessionID: "ses_4",
|
||||
provider: { id: "github-copilot" },
|
||||
model: { api: { npm: "@ai-sdk/github-copilot" } },
|
||||
message: {
|
||||
id: "msg_4",
|
||||
role: "user",
|
||||
},
|
||||
},
|
||||
output,
|
||||
)
|
||||
|
||||
expect(output.headers["x-initiator"]).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -123,6 +123,17 @@ export function createChatHeadersHandler(args: { ctx: PluginContext }): (input:
|
||||
if (!isChatHeadersOutput(output)) return
|
||||
|
||||
if (!isCopilotProvider(normalizedInput.provider.id)) return
|
||||
|
||||
// Do not override x-initiator when @ai-sdk/github-copilot is active.
|
||||
// OpenCode's copilot fetch wrapper already sets x-initiator based on
|
||||
// the actual request body content. Overriding it here causes a mismatch
|
||||
// that the Copilot API rejects with "invalid initiator".
|
||||
const model = isRecord(input) && isRecord((input as Record<string, unknown>).model)
|
||||
? (input as Record<string, unknown>).model as Record<string, unknown>
|
||||
: undefined
|
||||
const api = model && isRecord(model.api) ? model.api as Record<string, unknown> : undefined
|
||||
if (api?.npm === "@ai-sdk/github-copilot") return
|
||||
|
||||
if (!(await isOmoInternalMessage(normalizedInput, ctx.client))) return
|
||||
|
||||
output.headers["x-initiator"] = "agent"
|
||||
|
||||
Reference in New Issue
Block a user