mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 08:00:59 +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
|
|
@ -175,7 +175,7 @@ describe("GitHub Copilot Headers", () => {
|
|||
expect(lastOpenAIConfig?.defaultHeaders?.["X-Initiator"]).toBe("user");
|
||||
});
|
||||
|
||||
it("sets X-Initiator: agent when assistant message exists in history", async () => {
|
||||
it("sets X-Initiator: agent when last message is assistant", async () => {
|
||||
const context: Context = {
|
||||
messages: [{ role: "user", content: "Hello", timestamp: Date.now() }, assistantMessage],
|
||||
};
|
||||
|
|
@ -186,7 +186,7 @@ describe("GitHub Copilot Headers", () => {
|
|||
expect(lastOpenAIConfig?.defaultHeaders?.["X-Initiator"]).toBe("agent");
|
||||
});
|
||||
|
||||
it("sets X-Initiator: agent when toolResult exists in history", async () => {
|
||||
it("sets X-Initiator: agent when last message is toolResult", async () => {
|
||||
const context: Context = {
|
||||
messages: [{ role: "user", content: "Hello", timestamp: Date.now() }, toolResultMessage],
|
||||
};
|
||||
|
|
@ -197,7 +197,7 @@ describe("GitHub Copilot Headers", () => {
|
|||
expect(lastOpenAIConfig?.defaultHeaders?.["X-Initiator"]).toBe("agent");
|
||||
});
|
||||
|
||||
it("sets X-Initiator: agent for multi-turn conversation (last is user, but assistant in history)", async () => {
|
||||
it("sets X-Initiator: user for multi-turn conversation when last message is user", async () => {
|
||||
const context: Context = {
|
||||
messages: [
|
||||
{ role: "user", content: "Hello", timestamp: Date.now() },
|
||||
|
|
@ -209,7 +209,7 @@ describe("GitHub Copilot Headers", () => {
|
|||
const stream = streamOpenAICompletions(copilotCompletionsModel, context, { apiKey: "test-key" });
|
||||
await consumeStream(stream);
|
||||
|
||||
expect(lastOpenAIConfig?.defaultHeaders?.["X-Initiator"]).toBe("agent");
|
||||
expect(lastOpenAIConfig?.defaultHeaders?.["X-Initiator"]).toBe("user");
|
||||
});
|
||||
|
||||
it("sets X-Initiator: user when there are no messages", async () => {
|
||||
|
|
@ -259,7 +259,7 @@ describe("GitHub Copilot Headers", () => {
|
|||
expect(lastOpenAIConfig?.defaultHeaders?.["X-Initiator"]).toBe("user");
|
||||
});
|
||||
|
||||
it("sets X-Initiator: agent when assistant message exists in history", async () => {
|
||||
it("sets X-Initiator: agent when last message is assistant", async () => {
|
||||
const context: Context = {
|
||||
messages: [
|
||||
{ role: "user", content: "Hello", timestamp: Date.now() },
|
||||
|
|
@ -273,7 +273,7 @@ describe("GitHub Copilot Headers", () => {
|
|||
expect(lastOpenAIConfig?.defaultHeaders?.["X-Initiator"]).toBe("agent");
|
||||
});
|
||||
|
||||
it("sets X-Initiator: agent when toolResult exists in history", async () => {
|
||||
it("sets X-Initiator: agent when last message is toolResult", async () => {
|
||||
const context: Context = {
|
||||
messages: [{ role: "user", content: "Hello", timestamp: Date.now() }, toolResultMessage],
|
||||
};
|
||||
|
|
@ -284,7 +284,7 @@ describe("GitHub Copilot Headers", () => {
|
|||
expect(lastOpenAIConfig?.defaultHeaders?.["X-Initiator"]).toBe("agent");
|
||||
});
|
||||
|
||||
it("sets X-Initiator: agent for multi-turn conversation (last is user, but assistant in history)", async () => {
|
||||
it("sets X-Initiator: user for multi-turn conversation when last message is user", async () => {
|
||||
const context: Context = {
|
||||
messages: [
|
||||
{ role: "user", content: "Hello", timestamp: Date.now() },
|
||||
|
|
@ -296,7 +296,7 @@ describe("GitHub Copilot Headers", () => {
|
|||
const stream = streamOpenAIResponses(copilotResponsesModel, context, { apiKey: "test-key" });
|
||||
await consumeStream(stream);
|
||||
|
||||
expect(lastOpenAIConfig?.defaultHeaders?.["X-Initiator"]).toBe("agent");
|
||||
expect(lastOpenAIConfig?.defaultHeaders?.["X-Initiator"]).toBe("user");
|
||||
});
|
||||
|
||||
it("sets X-Initiator: user when there are no messages", async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue