fix(core): don't override source in custom provider loaders

This commit is contained in:
adamelmore
2026-01-25 19:40:28 -06:00
committed by Adam
parent c323d96deb
commit 5993a098b4
2 changed files with 15 additions and 15 deletions

View File

@@ -854,10 +854,9 @@ export namespace Provider {
// Load for the main provider if auth exists // 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])
mergeProvider(plugin.auth.provider, { const opts = options ?? {}
source: "custom", const patch: Partial<Info> = providers[providerID] ? { options: opts } : { source: "custom", options: opts }
options: options, mergeProvider(providerID, patch)
})
} }
// If this is github-copilot plugin, also register for github-copilot-enterprise if auth exists // If this is github-copilot plugin, also register for github-copilot-enterprise if auth exists
@@ -870,10 +869,11 @@ export namespace Provider {
() => Auth.get(enterpriseProviderID) as any, () => Auth.get(enterpriseProviderID) as any,
database[enterpriseProviderID], database[enterpriseProviderID],
) )
mergeProvider(enterpriseProviderID, { const opts = enterpriseOptions ?? {}
source: "custom", const patch: Partial<Info> = providers[enterpriseProviderID]
options: enterpriseOptions, ? { options: opts }
}) : { source: "custom", options: opts }
mergeProvider(enterpriseProviderID, patch)
} }
} }
} }
@@ -889,10 +889,9 @@ export namespace Provider {
const result = await fn(data) const result = await fn(data)
if (result && (result.autoload || providers[providerID])) { if (result && (result.autoload || providers[providerID])) {
if (result.getModel) modelLoaders[providerID] = result.getModel if (result.getModel) modelLoaders[providerID] = result.getModel
mergeProvider(providerID, { const opts = result.options ?? {}
source: "custom", const patch: Partial<Info> = providers[providerID] ? { options: opts } : { source: "custom", options: opts }
options: result.options, mergeProvider(providerID, patch)
})
} }
} }

View File

@@ -46,9 +46,10 @@ test("provider loaded from env variable", async () => {
fn: async () => { fn: async () => {
const providers = await Provider.list() const providers = await Provider.list()
expect(providers["anthropic"]).toBeDefined() expect(providers["anthropic"]).toBeDefined()
// Note: source becomes "custom" because CUSTOM_LOADERS run after env loading // Provider should retain its connection source even if custom loaders
// and anthropic has a custom loader that merges additional options // merge additional options.
expect(providers["anthropic"].source).toBe("custom") expect(providers["anthropic"].source).toBe("env")
expect(providers["anthropic"].options.headers["anthropic-beta"]).toBeDefined()
}, },
}) })
}) })