mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 13:00:33 +00:00
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:
parent
13b8af1f36
commit
575dcb2676
5 changed files with 18 additions and 14 deletions
|
|
@ -302,9 +302,11 @@ function createClient(model: Model<"openai-completions">, context: Context, apiK
|
|||
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";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue