mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-26 02:24:43 +00:00
fix: github copilot enterprise integration (#17847)
This commit is contained in:
@@ -185,12 +185,10 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
|
|||||||
const deploymentType = inputs.deploymentType || "github.com"
|
const deploymentType = inputs.deploymentType || "github.com"
|
||||||
|
|
||||||
let domain = "github.com"
|
let domain = "github.com"
|
||||||
let actualProvider = "github-copilot"
|
|
||||||
|
|
||||||
if (deploymentType === "enterprise") {
|
if (deploymentType === "enterprise") {
|
||||||
const enterpriseUrl = inputs.enterpriseUrl
|
const enterpriseUrl = inputs.enterpriseUrl
|
||||||
domain = normalizeDomain(enterpriseUrl!)
|
domain = normalizeDomain(enterpriseUrl!)
|
||||||
actualProvider = "github-copilot-enterprise"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const urls = getUrls(domain)
|
const urls = getUrls(domain)
|
||||||
@@ -262,8 +260,7 @@ export async function CopilotAuthPlugin(input: PluginInput): Promise<Hooks> {
|
|||||||
expires: 0,
|
expires: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actualProvider === "github-copilot-enterprise") {
|
if (deploymentType === "enterprise") {
|
||||||
result.provider = "github-copilot-enterprise"
|
|
||||||
result.enterpriseUrl = domain
|
result.enterpriseUrl = domain
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -197,16 +197,6 @@ export namespace Provider {
|
|||||||
options: {},
|
options: {},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"github-copilot-enterprise": async () => {
|
|
||||||
return {
|
|
||||||
autoload: false,
|
|
||||||
async getModel(sdk: any, modelID: string, _options?: Record<string, any>) {
|
|
||||||
if (useLanguageModel(sdk)) return sdk.languageModel(modelID)
|
|
||||||
return shouldUseCopilotResponsesApi(modelID) ? sdk.responses(modelID) : sdk.chat(modelID)
|
|
||||||
},
|
|
||||||
options: {},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
azure: async (provider) => {
|
azure: async (provider) => {
|
||||||
const resource = iife(() => {
|
const resource = iife(() => {
|
||||||
const name = provider.options?.resourceName
|
const name = provider.options?.resourceName
|
||||||
@@ -863,20 +853,6 @@ export namespace Provider {
|
|||||||
|
|
||||||
const configProviders = Object.entries(config.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: ProviderID.githubCopilotEnterprise,
|
|
||||||
name: "GitHub Copilot Enterprise",
|
|
||||||
models: mapValues(githubCopilot.models, (model) => ({
|
|
||||||
...model,
|
|
||||||
providerID: ProviderID.githubCopilotEnterprise,
|
|
||||||
})),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function mergeProvider(providerID: ProviderID, provider: Partial<Info>) {
|
function mergeProvider(providerID: ProviderID, provider: Partial<Info>) {
|
||||||
const existing = providers[providerID]
|
const existing = providers[providerID]
|
||||||
if (existing) {
|
if (existing) {
|
||||||
@@ -1003,46 +979,16 @@ export namespace Provider {
|
|||||||
const providerID = ProviderID.make(plugin.auth.provider)
|
const providerID = ProviderID.make(plugin.auth.provider)
|
||||||
if (disabled.has(providerID)) continue
|
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)
|
const auth = await Auth.get(providerID)
|
||||||
if (auth) hasAuth = true
|
if (!auth) continue
|
||||||
|
|
||||||
// Special handling for github-copilot: also check for enterprise auth
|
|
||||||
if (providerID === ProviderID.githubCopilot && !hasAuth) {
|
|
||||||
const enterpriseAuth = await Auth.get("github-copilot-enterprise")
|
|
||||||
if (enterpriseAuth) hasAuth = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hasAuth) continue
|
|
||||||
if (!plugin.auth.loader) continue
|
if (!plugin.auth.loader) continue
|
||||||
|
|
||||||
// Load for the main provider if auth exists
|
|
||||||
if (auth) {
|
if (auth) {
|
||||||
const options = await plugin.auth.loader(() => Auth.get(providerID) as any, database[plugin.auth.provider])
|
const options = await plugin.auth.loader(() => Auth.get(providerID) as any, database[plugin.auth.provider])
|
||||||
const opts = options ?? {}
|
const opts = options ?? {}
|
||||||
const patch: Partial<Info> = providers[providerID] ? { options: opts } : { source: "custom", options: opts }
|
const patch: Partial<Info> = providers[providerID] ? { options: opts } : { source: "custom", options: opts }
|
||||||
mergeProvider(providerID, patch)
|
mergeProvider(providerID, patch)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is github-copilot plugin, also register for github-copilot-enterprise if auth exists
|
|
||||||
if (providerID === ProviderID.githubCopilot) {
|
|
||||||
const enterpriseProviderID = ProviderID.githubCopilotEnterprise
|
|
||||||
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],
|
|
||||||
)
|
|
||||||
const opts = enterpriseOptions ?? {}
|
|
||||||
const patch: Partial<Info> = providers[enterpriseProviderID]
|
|
||||||
? { options: opts }
|
|
||||||
: { source: "custom", options: opts }
|
|
||||||
mergeProvider(enterpriseProviderID, patch)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const [id, fn] of Object.entries(CUSTOM_LOADERS)) {
|
for (const [id, fn] of Object.entries(CUSTOM_LOADERS)) {
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ export const ProviderID = providerIdSchema.pipe(
|
|||||||
google: schema.makeUnsafe("google"),
|
google: schema.makeUnsafe("google"),
|
||||||
googleVertex: schema.makeUnsafe("google-vertex"),
|
googleVertex: schema.makeUnsafe("google-vertex"),
|
||||||
githubCopilot: schema.makeUnsafe("github-copilot"),
|
githubCopilot: schema.makeUnsafe("github-copilot"),
|
||||||
githubCopilotEnterprise: schema.makeUnsafe("github-copilot-enterprise"),
|
|
||||||
amazonBedrock: schema.makeUnsafe("amazon-bedrock"),
|
amazonBedrock: schema.makeUnsafe("amazon-bedrock"),
|
||||||
azure: schema.makeUnsafe("azure"),
|
azure: schema.makeUnsafe("azure"),
|
||||||
openrouter: schema.makeUnsafe("openrouter"),
|
openrouter: schema.makeUnsafe("openrouter"),
|
||||||
|
|||||||
Reference in New Issue
Block a user