11import { AISDK } from "@opencode-ai/core/aisdk"
2- import { App } from "@opencode-ai/core/app"
32import { describe , expect , test } from "bun:test"
43import { Effect } from "effect"
54import { Catalog } from "@opencode-ai/core/catalog"
65import { Model } from "@opencode-ai/core/model"
76import { Plugin } from "@opencode-ai/core/plugin"
87import { PluginHost } from "@opencode-ai/core/plugin/host"
98import { copilotBaseURL , copilotFetch , GithubCopilotPlugin } from "@opencode-ai/core/plugin/provider/github-copilot"
9+ import { CopilotModels } from "@opencode-ai/core/github-copilot/models"
1010import { Provider } from "@opencode-ai/core/provider"
1111import { Integration } from "@opencode-ai/core/integration"
12+ import { Credential } from "@opencode-ai/core/credential"
13+ import { ModelResolver } from "@opencode-ai/core/model-resolver"
1214import type { LanguageModelV3 } from "@ai-sdk/provider"
1315import { testEffect } from "../lib/effect"
1416import { PluginTestLayer } from "./fixture"
@@ -98,7 +100,6 @@ describe("GithubCopilotPlugin", () => {
98100 return Response . json ( { ok : true } )
99101 } ,
100102 false ,
101- App . make ( { name : "test" , version : "1.2.3" , channel : "beta" } ) ,
102103 )
103104 yield * Effect . promise ( ( ) =>
104105 send ( "https://api.githubcopilot.com/chat/completions" , {
@@ -114,7 +115,10 @@ describe("GithubCopilotPlugin", () => {
114115 expect ( requests [ 0 ] ?. get ( "x-initiator" ) ) . toBe ( "user" )
115116 expect ( requests [ 0 ] ?. get ( "copilot-vision-request" ) ) . toBe ( "true" )
116117 expect ( requests [ 0 ] ?. get ( "x-github-api-version" ) ) . toBe ( "2026-06-01" )
117- expect ( requests [ 0 ] ?. get ( "user-agent" ) ) . toBe ( "opencode/beta/1.2.3/test" )
118+ expect ( requests [ 0 ] ?. get ( "user-agent" ) ) . toBe ( "GitHubCopilotChat/0.26.7" )
119+ expect ( requests [ 0 ] ?. get ( "editor-version" ) ) . toBe ( "vscode/1.99.3" )
120+ expect ( requests [ 0 ] ?. get ( "editor-plugin-version" ) ) . toBe ( "copilot-chat/0.26.7" )
121+ expect ( requests [ 0 ] ?. get ( "copilot-integration-id" ) ) . toBe ( "vscode-chat" )
118122 } ) ,
119123 )
120124
@@ -146,6 +150,54 @@ describe("GithubCopilotPlugin", () => {
146150 } ) ,
147151 )
148152
153+ it . effect ( "routes all Copilot protocols through Copilot-owned SDK hooks" , ( ) =>
154+ Effect . gen ( function * ( ) {
155+ const catalog = yield * Catalog . Service
156+ yield * catalog . transform ( ( draft ) => {
157+ draft . provider . update ( Provider . ID . githubCopilot , ( provider ) => {
158+ provider . package = Provider . aisdk ( "@ai-sdk/openai-compatible" )
159+ } )
160+ draft . model . update ( Provider . ID . githubCopilot , Model . ID . make ( "claude-sonnet" ) , ( model ) => {
161+ model . package = Provider . aisdk ( "@ai-sdk/anthropic" )
162+ } )
163+ } )
164+ yield * addPlugin ( )
165+
166+ expect ( required ( yield * catalog . provider . get ( Provider . ID . githubCopilot ) ) . package ) . toBe (
167+ Provider . aisdk ( CopilotModels . Package . OpenAI ) ,
168+ )
169+ expect (
170+ required ( yield * catalog . model . get ( Provider . ID . githubCopilot , Model . ID . make ( "claude-sonnet" ) ) ) . package ,
171+ ) . toBe ( Provider . aisdk ( CopilotModels . Package . Anthropic ) )
172+
173+ const fallback = yield * ModelResolver . fromCatalogModel (
174+ Model . Info . make ( {
175+ ...Model . Info . default ( Provider . ID . openai , Model . ID . make ( "fallback" ) ) ,
176+ package : Provider . aisdk ( "@ai-sdk/openai" ) ,
177+ settings : { baseURL : "https://openai.example/v1" } ,
178+ } ) ,
179+ )
180+ const resolved = yield * ModelResolver . fromCatalogModel (
181+ required ( yield * catalog . model . get ( Provider . ID . githubCopilot , Model . ID . make ( "claude-sonnet" ) ) ) ,
182+ Credential . OAuth . make ( {
183+ type : "oauth" ,
184+ methodID : Integration . MethodID . make ( "device" ) ,
185+ refresh : "github-token" ,
186+ access : "github-token" ,
187+ expires : 0 ,
188+ } ) ,
189+ {
190+ loadAISDK : ( runtime ) =>
191+ Effect . sync ( ( ) => {
192+ expect ( runtime . settings ?. apiKey ) . toBe ( "github-token" )
193+ return fallback
194+ } ) ,
195+ } ,
196+ )
197+ expect ( resolved ) . toBe ( fallback )
198+ } ) ,
199+ )
200+
149201 it . effect ( "selects languageModel when responses and chat are absent" , ( ) =>
150202 Effect . gen ( function * ( ) {
151203 const plugin = yield * Plugin . Service
0 commit comments