mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-19 14:01:15 +00:00
Release v0.27.8 - OAuth takes priority over settings.json API keys
This commit is contained in:
parent
60768b90f3
commit
a965b6f160
14 changed files with 426 additions and 102 deletions
|
|
@ -328,21 +328,25 @@ export function discoverSlashCommands(cwd?: string, agentDir?: string): FileSlas
|
|||
|
||||
/**
|
||||
* Create the default API key resolver.
|
||||
* Priority: settings.json apiKeys > custom providers (models.json) > OAuth > environment variables.
|
||||
* Priority: OAuth > custom providers (models.json) > environment variables > settings.json apiKeys.
|
||||
*
|
||||
* OAuth takes priority so users logged in with a plan (e.g. unlimited tokens) aren't
|
||||
* accidentally billed via a PAYG API key sitting in settings.json.
|
||||
*/
|
||||
export function defaultGetApiKey(
|
||||
settingsManager?: SettingsManager,
|
||||
): (model: Model<any>) => Promise<string | undefined> {
|
||||
return async (model: Model<any>) => {
|
||||
// Check settings.json apiKeys first
|
||||
if (settingsManager) {
|
||||
const settingsKey = settingsManager.getApiKey(model.provider);
|
||||
if (settingsKey) {
|
||||
return settingsKey;
|
||||
}
|
||||
// Check OAuth, custom providers, env vars first
|
||||
const resolvedKey = await getApiKeyForModel(model);
|
||||
if (resolvedKey) {
|
||||
return resolvedKey;
|
||||
}
|
||||
// Fall back to existing resolution (custom providers, OAuth, env vars)
|
||||
return getApiKeyForModel(model);
|
||||
// Fall back to settings.json apiKeys
|
||||
if (settingsManager) {
|
||||
return settingsManager.getApiKey(model.provider);
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue