u
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user