Fix X-Initiator header logic for GitHub Copilot
Check last message role instead of any message in history. This matches the original correct implementation from PR #200. fixes #209
This commit is contained in:
@@ -310,9 +310,11 @@ function createClient(model: Model<"openai-responses">, context: Context, apiKey
|
||||
const headers = { ...model.headers };
|
||||
if (model.provider === "github-copilot") {
|
||||
// Copilot expects X-Initiator to indicate whether the request is user-initiated
|
||||
// or agent-initiated. It's an agent call if ANY message in history has assistant/tool role.
|
||||
// or agent-initiated (e.g. follow-up after assistant/tool messages). If there is
|
||||
// no prior message, default to user-initiated.
|
||||
const messages = context.messages || [];
|
||||
const isAgentCall = messages.some((msg) => msg.role === "assistant" || msg.role === "toolResult");
|
||||
const lastMessage = messages[messages.length - 1];
|
||||
const isAgentCall = lastMessage ? lastMessage.role !== "user" : false;
|
||||
headers["X-Initiator"] = isAgentCall ? "agent" : "user";
|
||||
headers["Openai-Intent"] = "conversation-edits";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user