feat(byok): add model selection to BYOK settings panel and overlay custom model on route resolution
This commit is contained in:
@@ -51,12 +51,12 @@ export async function getActiveByokKey(userId: string, provider: string) {
|
||||
export async function resolveByokApiKey(
|
||||
userId: string,
|
||||
providerType: string,
|
||||
): Promise<{ plaintext: string; provider: string } | null> {
|
||||
): Promise<{ plaintext: string; provider: string; model: string | null } | null> {
|
||||
const row = await getActiveByokKey(userId, providerType);
|
||||
if (!row) return null;
|
||||
try {
|
||||
const plaintext = await decryptApiKey(row.encryptedKey);
|
||||
return { plaintext, provider: row.provider };
|
||||
return { plaintext, provider: row.provider, model: row.model };
|
||||
} catch (err) {
|
||||
console.error('[byok] Failed to decrypt key for provider', providerType, err);
|
||||
return null;
|
||||
@@ -67,16 +67,17 @@ export async function applyByokToConfig(
|
||||
billingUserId: string,
|
||||
providerType: string,
|
||||
config: Record<string, string>,
|
||||
): Promise<{ config: Record<string, string>; usedByok: boolean }> {
|
||||
): Promise<{ config: Record<string, string>; usedByok: boolean; model: string | null }> {
|
||||
const byok = await resolveByokApiKey(billingUserId, providerType);
|
||||
if (!byok) return { config, usedByok: false };
|
||||
if (!byok) return { config, usedByok: false, model: null };
|
||||
|
||||
const { apiKeyConfigKey } = getProviderConfigKeys(providerType);
|
||||
if (!apiKeyConfigKey) return { config, usedByok: false };
|
||||
if (!apiKeyConfigKey) return { config, usedByok: false, model: null };
|
||||
|
||||
return {
|
||||
config: { ...config, [apiKeyConfigKey]: byok.plaintext },
|
||||
usedByok: true,
|
||||
model: byok.model,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user