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

@@ -20,7 +20,7 @@ import { createPatchTool } from '../tools/patch.js';
import { createRmTool } from '../tools/rm.js';
import { createSearchImagesTool } from '../tools/search-images.js';
import { createAnalyzeImageTool } from '../tools/analyze-image.js';
import { resolveOpenRouterKey } from '../tools/llm-key.js';
import { resolveOpenRouterKey, resolveDefaultModel, RETIRED_MODELS, hasConfiguredOpenRouterKey } from '../tools/llm-key.js';
const KEEP_ALIVE_MS = 20_000;
@@ -345,12 +345,15 @@ export class ConversationManager {
if (conversation.provider !== 'openrouter') {
throw new Error(`Unsupported provider: ${conversation.provider}`);
}
// Fall back to the configured default when the stored model is missing or blank, so
// an old or malformed conversation row cannot send an empty `model` and make the
// provider return an empty response.
const model = (typeof conversation.model === 'string' && conversation.model.trim())
? conversation.model.trim()
: env.defaultModel;
// Fall back to the configured default when the stored model is missing, blank, or
// retired. If the stored model was defaulted to the free model and the company now has
// a custom key configured, transition to the configured paid default model.
const defaultModel = await resolveDefaultModel(googleAuthId);
const hasCustomKey = await hasConfiguredOpenRouterKey(googleAuthId);
const storedModel = typeof conversation.model === 'string' ? conversation.model.trim() : '';
const model = (!storedModel || RETIRED_MODELS.has(storedModel) || (storedModel === env.openrouterFreeModel && hasCustomKey))
? defaultModel
: storedModel;
const apiKey = await resolveOpenRouterKey(googleAuthId);
// Transcript comes from the database (includes user, assistant, tool, reasoning).