This commit is contained in:
seb
2026-10-05 11:56:17 +02:00
parent 4a08e7f20b
commit 296fceedc0
6 changed files with 53 additions and 19 deletions

View File

@@ -23,4 +23,37 @@ export async function resolveOpenRouterKey(googleAuthId) {
if (!apiKey) apiKey = env.openrouterFreeKey?.trim();
if (!apiKey) throw new Error('OpenRouter API key not configured (companysetting: keys.openrouter)');
return apiKey;
}
// Model ids that are known to return empty responses from OpenRouter. Requests naming one of
// these are transparently rerouted to the default model instead of failing at generation time.
export const RETIRED_MODELS = new Set(['stealth/space-bunny-alpha']);
/**
* Check if the user's selected company has a custom OpenRouter key configured.
*
* @param {number} googleAuthId
* @returns {Promise<boolean>}
*/
export async function hasConfiguredOpenRouterKey(googleAuthId) {
if (!googleAuthId) return false;
try {
const setting = await dbCompanySetting.getByKey(googleAuthId, 'keys.openrouter', { maskWriteonly: false });
return Boolean(setting?.value?.trim());
} catch {
return false;
}
}
/**
* Resolve the default model for a user/company:
* - As soon as the user/company has configured `keys.openrouter`, use `env.openrouterPaidModel`.
* - Otherwise (using the server's free key), use `env.openrouterFreeModel`.
*
* @param {number} [googleAuthId]
* @returns {Promise<string>}
*/
export async function resolveDefaultModel(googleAuthId) {
const hasKey = await hasConfiguredOpenRouterKey(googleAuthId);
return hasKey ? env.openrouterPaidModel : env.openrouterFreeModel;
}