Adds dynamic Claude model fetching and management #1

Merged
AlexKucera merged 60 commits from dynamic-models into master 2025-10-31 13:42:04 +01:00
Showing only changes of commit e5c7a523c5 - Show all commits
+23 -5
View File
3
@@ -133,8 +133,14 @@ export class AnthropicClient {
// Fetch all pages // Fetch all pages
while (hasMore) { while (hasMore) {
// Build URL with pagination parameter if needed // Build URL with pagination parameters
const url = afterId ? `${this.modelsUrl}?after=${afterId}` : this.modelsUrl; // Use limit=1000 (Anthropic's max) to minimize round trips
const params = new URLSearchParams();
params.set('limit', '1000');
if (afterId) {
params.set('after', afterId);
}
const url = `${this.modelsUrl}?${params.toString()}`;
const response = await requestUrl({ const response = await requestUrl({
url, url,
1
@@ -273,7 +279,12 @@ export class AnthropicClient {
throw new Error('No content received from API'); throw new Error('No content received from API');
} }
const text = response.content[0].text; // Parse all text blocks, not just the first one
// Anthropic API can return multiple content blocks
const text = response.content
.filter(c => c && c.type === 'text' && typeof c.text === 'string')
.map(c => c.text)
.join('\n');
const lines = text.split('\n') const lines = text.split('\n')
.map(line => line.trim()) .map(line => line.trim())
.filter(line => line.length > 0); .filter(line => line.length > 0);
@@ -362,9 +373,16 @@ export class AnthropicClient {
const response = await this.makeRequest(testRequest); const response = await this.makeRequest(testRequest);
const responseTime = Date.now() - startTime; const responseTime = Date.now() - startTime;
// Validate that the assistant actually returned "ping"
// This ensures the API is working correctly, not just returning a 2xx status
const returnedText = (response.content?.[0]?.text || '').trim().toLowerCase();
const isValid = returnedText === 'ping';
return { return {
success: true, success: isValid,
message: 'API key is valid and working correctly', message: isValid
? 'API key is valid and working correctly'
: 'API responded but returned unexpected content',
details: { details: {
model: response.model, model: response.model,
responseTime, responseTime,