Skip to content

Commit c0f09af

Browse files
feat(copilot): send X-Interaction-Id header with session id (anomalyco#47215)
Co-authored-by: rekram1-node <[email protected]>
1 parent 8a6cf2c commit c0f09af

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

‎packages/opencode/src/plugin/github-copilot/copilot.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
361361
if (!incoming.model.providerID.includes("github-copilot")) return
362362

363363
output.headers["X-GitHub-Api-Version"] = API_VERSION
364+
output.headers["X-Interaction-Id"] = incoming.sessionID
364365
if (incoming.agent === "title") {
365366
output.headers["X-Interaction-Type"] = "agent-session-name-generation"
366367
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { expect, test } from "bun:test"
2+
import type { Hooks } from "@opencode-ai/plugin"
3+
import { CopilotAuthPlugin } from "@/plugin/github-copilot/copilot"
4+
5+
type ChatHeaders = NonNullable<Hooks["chat.headers"]>
6+
7+
async function hook() {
8+
const hooks = await CopilotAuthPlugin({
9+
directory: "",
10+
project: {} as never,
11+
worktree: "",
12+
experimental_workspace: { register() {} },
13+
serverUrl: new URL("http://localhost"),
14+
$: {} as never,
15+
client: {
16+
session: {
17+
message: async () => ({ data: { parts: [] } }),
18+
get: async () => ({ data: {} }),
19+
},
20+
} as never,
21+
})
22+
return hooks["chat.headers"]!
23+
}
24+
25+
function input(sessionID: string, providerID: string, npm: string) {
26+
return {
27+
sessionID,
28+
agent: "build",
29+
model: { providerID, api: { npm } },
30+
message: { id: "msg_test", sessionID },
31+
} as Parameters<ChatHeaders>[0]
32+
}
33+
34+
test.each([
35+
["github-copilot", "@ai-sdk/github-copilot"],
36+
["github-copilot", "@ai-sdk/anthropic"],
37+
["github-copilot-enterprise", "@ai-sdk/github-copilot"],
38+
["github-copilot-enterprise", "@ai-sdk/anthropic"],
39+
])("uses the session ID for %s interaction headers with %s", async (providerID, npm) => {
40+
const headers = await hook()
41+
for (const sessionID of ["ses_one", "ses_one", "ses_two"]) {
42+
const output = { headers: { "x-existing": "preserved" } }
43+
await headers(input(sessionID, providerID, npm), output)
44+
expect(output.headers).toMatchObject({
45+
"X-Interaction-Id": sessionID,
46+
"x-existing": "preserved",
47+
})
48+
}
49+
})
50+
51+
test("does not add interaction headers to other providers", async () => {
52+
const headers = await hook()
53+
const output = { headers: { "x-existing": "preserved" } }
54+
await headers(input("ses_one", "openai", "@ai-sdk/openai"), output)
55+
expect(output.headers).toEqual({ "x-existing": "preserved" })
56+
})

0 commit comments

Comments
 (0)