GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(copilot): send X-Interaction-Id header with session id (#47215) · krumpstead/opencode@c0f09af

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/opencode
    • src/plugin/github-copilot
      • copilot.ts
    • test/plugin
      • github-copilot.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: packages/opencode/src/plugin/github-copilot/copilot.ts
+1Lines 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
}
Collapse file

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

Copy file name to clipboard
+56Lines 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 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.