mirror of
https://github.com/coleam00/Archon.git
synced 2025-12-24 02:39:17 -05:00
Address CodeRabbit review: Improve openrouterService robustness
1. Lazy initialization of baseUrl via getBaseUrl() method - Allows API URL to be updated at runtime without stale URL issues 2. Runtime validation of API response structure - Validates embedding_models array exists before caching - Prevents invalid responses from being cached Addresses CodeRabbit nitpick comments on PR #852 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -23,7 +23,7 @@ export interface OpenRouterModelListResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class OpenRouterService {
|
class OpenRouterService {
|
||||||
private baseUrl = getApiUrl();
|
private getBaseUrl = () => getApiUrl();
|
||||||
private cacheKey = "openrouter_models_cache";
|
private cacheKey = "openrouter_models_cache";
|
||||||
private cacheTTL = 5 * 60 * 1000; // 5 minutes
|
private cacheTTL = 5 * 60 * 1000; // 5 minutes
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ class OpenRouterService {
|
|||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(`${this.baseUrl}/api/openrouter/models`, {
|
const response = await fetch(`${this.getBaseUrl()}/api/openrouter/models`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -115,6 +115,11 @@ class OpenRouterService {
|
|||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
|
// Validate response structure
|
||||||
|
if (!data.embedding_models || !Array.isArray(data.embedding_models)) {
|
||||||
|
throw new Error("Invalid response structure from OpenRouter API");
|
||||||
|
}
|
||||||
|
|
||||||
// Cache the successful response
|
// Cache the successful response
|
||||||
this.cacheModels(data);
|
this.cacheModels(data);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user