feat(provider): add GitHub Enterprise support for Copilot (#2522)
Co-authored-by: Jon-Mikkel Korsvik <48263282+jkorsvik@users.noreply.github.com> Co-authored-by: GitHub Action <action@github.com> Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
This commit is contained in:
@@ -283,6 +283,18 @@ export namespace Provider {
|
||||
|
||||
const configProviders = Object.entries(config.provider ?? {})
|
||||
|
||||
// Add GitHub Copilot Enterprise provider that inherits from GitHub Copilot
|
||||
if (database["github-copilot"]) {
|
||||
const githubCopilot = database["github-copilot"]
|
||||
database["github-copilot-enterprise"] = {
|
||||
...githubCopilot,
|
||||
id: "github-copilot-enterprise",
|
||||
name: "GitHub Copilot Enterprise",
|
||||
// Enterprise uses a different API endpoint - will be set dynamically based on auth
|
||||
api: undefined,
|
||||
}
|
||||
}
|
||||
|
||||
for (const [providerID, provider] of configProviders) {
|
||||
const existing = database[providerID]
|
||||
const parsed: ModelsDev.Provider = {
|
||||
@@ -378,14 +390,44 @@ export namespace Provider {
|
||||
if (!plugin.auth) continue
|
||||
const providerID = plugin.auth.provider
|
||||
if (disabled.has(providerID)) continue
|
||||
|
||||
// For github-copilot plugin, check if auth exists for either github-copilot or github-copilot-enterprise
|
||||
let hasAuth = false
|
||||
const auth = await Auth.get(providerID)
|
||||
if (!auth) continue
|
||||
if (auth) hasAuth = true
|
||||
|
||||
// Special handling for github-copilot: also check for enterprise auth
|
||||
if (providerID === "github-copilot" && !hasAuth) {
|
||||
const enterpriseAuth = await Auth.get("github-copilot-enterprise")
|
||||
if (enterpriseAuth) hasAuth = true
|
||||
}
|
||||
|
||||
if (!hasAuth) continue
|
||||
if (!plugin.auth.loader) continue
|
||||
const options = await plugin.auth.loader(
|
||||
() => Auth.get(providerID) as any,
|
||||
database[plugin.auth.provider],
|
||||
)
|
||||
mergeProvider(plugin.auth.provider, options ?? {}, "custom")
|
||||
|
||||
// Load for the main provider if auth exists
|
||||
if (auth) {
|
||||
const options = await plugin.auth.loader(
|
||||
() => Auth.get(providerID) as any,
|
||||
database[plugin.auth.provider],
|
||||
)
|
||||
mergeProvider(plugin.auth.provider, options ?? {}, "custom")
|
||||
}
|
||||
|
||||
// If this is github-copilot plugin, also register for github-copilot-enterprise if auth exists
|
||||
if (providerID === "github-copilot") {
|
||||
const enterpriseProviderID = "github-copilot-enterprise"
|
||||
if (!disabled.has(enterpriseProviderID)) {
|
||||
const enterpriseAuth = await Auth.get(enterpriseProviderID)
|
||||
if (enterpriseAuth) {
|
||||
const enterpriseOptions = await plugin.auth.loader(
|
||||
() => Auth.get(enterpriseProviderID) as any,
|
||||
database[enterpriseProviderID],
|
||||
)
|
||||
mergeProvider(enterpriseProviderID, enterpriseOptions ?? {}, "custom")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// load config
|
||||
@@ -458,7 +500,8 @@ export namespace Provider {
|
||||
: installedPath
|
||||
const mod = await import(modPath)
|
||||
if (options["timeout"] !== undefined && options["timeout"] !== null) {
|
||||
// Only override fetch if user explicitly sets timeout
|
||||
// Preserve custom fetch if it exists, wrap it with timeout logic
|
||||
const customFetch = options["fetch"]
|
||||
options["fetch"] = async (input: any, init?: BunFetchRequestInit) => {
|
||||
const { signal, ...rest } = init ?? {}
|
||||
|
||||
@@ -468,7 +511,8 @@ export namespace Provider {
|
||||
|
||||
const combined = signals.length > 1 ? AbortSignal.any(signals) : signals[0]
|
||||
|
||||
return fetch(input, {
|
||||
const fetchFn = customFetch ?? fetch
|
||||
return fetchFn(input, {
|
||||
...rest,
|
||||
signal: combined,
|
||||
// @ts-ignore see here: https://github.com/oven-sh/bun/issues/16682
|
||||
|
||||
Reference in New Issue
Block a user