Compare commits

...
Author SHA1 Message Date
Sonarly Claude Code 498770b7b4 fix: refresh AI model registry when config variables are updated via admin panel
https://sonarly.com/issue/22695?type=bug

Setting AI provider API keys through the admin panel's config variables UI stores the value in the database but does not rebuild the AI model registry, leaving all AI features broken until the server restarts.

Fix: Added `this.aiModelRegistryService.refreshRegistry()` calls to the three generic config variable mutations in `admin-panel.resolver.ts`:
- `createDatabaseConfigVariable` — called when a user sets a new config variable (e.g., `MISTRAL_API_KEY`) via the admin panel
- `updateDatabaseConfigVariable` — called when updating an existing config variable
- `deleteDatabaseConfigVariable` — called when removing a config variable

These mutations are the code path that the admin panel UI routes users through when setting AI provider API keys for catalog providers (like Mistral, OpenAI, Anthropic). The AI provider detail page shows the `apiKeyConfigVariable` as a link to the config variable settings page, where users enter their API key.

Previously, only the AI-specific mutations (`addAiProvider`, `removeAiProvider`, `addModelToProvider`, `removeModelFromProvider`) called `refreshRegistry()`. The generic config variable mutations did not, which meant the AI model registry remained stale after API keys were saved — it was still using the initial state from server startup where the key was undefined.

The fix follows the exact same pattern already used 4 times in the same file. The `refreshRegistry()` call is synchronous and rebuilds in-memory maps, making it safe and cheap to call on every config variable change (which are rare admin-only operations).
2026-04-08 02:43:43 +00:00
@@ -268,6 +268,7 @@ export class AdminPanelResolver {
value: ConfigVariables[keyof ConfigVariables],
): Promise<boolean> {
await this.twentyConfigService.set(key, value);
this.aiModelRegistryService.refreshRegistry();
return true;
}
@@ -280,6 +281,7 @@ export class AdminPanelResolver {
value: ConfigVariables[keyof ConfigVariables],
): Promise<boolean> {
await this.twentyConfigService.update(key, value);
this.aiModelRegistryService.refreshRegistry();
return true;
}
@@ -290,6 +292,7 @@ export class AdminPanelResolver {
@Args('key', { type: () => String }) key: keyof ConfigVariables,
): Promise<boolean> {
await this.twentyConfigService.delete(key);
this.aiModelRegistryService.refreshRegistry();
return true;
}