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 d7497c1259 - Show all commits
-1
View File
@@ -50,7 +50,6 @@ export class AnthropicClient {
} catch (error) { } catch (error) {
console.error('Error generating prompts:', error); console.error('Error generating prompts:', error);
if (error instanceof Error) { if (error instanceof Error) {
new Notice(`Failed to generate prompts: ${error.message}`);
throw error; throw error;
} }
coderabbitai[bot] commented 2025-10-24 13:05:44 +02:00 (Migrated from github.com)
Review

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Pagination is not handled for model listing.

The ModelsListResponse interface includes has_more, first_id, and last_id fields that indicate pagination support, but fetchModels() only retrieves the first page of results. If Anthropic returns more than one page of models, subsequent pages are silently ignored.

Verify whether pagination is needed:

If pagination is required, consider implementing it or documenting the limitation. Otherwise, if all Claude models fit in a single page, add a comment explaining why pagination isn't needed.


🏁 Script executed:

#!/bin/bash
# Check if the ModelsListResponse type definition includes pagination fields
rg -A 5 "interface ModelsListResponse" types.ts

Length of output: 128


I'll verify whether pagination is actually used or documented elsewhere in the codebase.


Additionally, let me search for API documentation references or comments about Anthropic's models endpoint:




---

🏁 Script executed:

```shell
#!/bin/bash
# Check if pagination fields are used anywhere in the codebase
echo "=== Searching for usage of pagination fields ==="
rg -n "(has_more|first_id|last_id)" --type ts --type js -C 2

echo ""
echo "=== Searching for fetchModels calls ==="
rg -n "fetchModels" --type ts --type js -C 2

echo ""
echo "=== Searching for pagination-related comments or TODOs ==="
rg -n "(pagination|TODO|FIXME)" --type ts --type js api/

Length of output: 1321


🏁 Script executed:

#!/bin/bash
# Check for documentation or API-related comments in the anthropicClient file
echo "=== Full anthropicClient.ts file structure ==="
rg -n "^(class|interface|export|async|const|function)" api/anthropicClient.ts

echo ""
echo "=== Check file for any comments about models endpoint ==="
rg -n "(models|API|pagination|page)" api/anthropicClient.ts -i

Length of output: 2163


🌐 Web query:

Anthropic models API endpoint pagination how many models returned

💡 Result:

By default the List Models endpoint returns 20 models per page. You can set the query param limit to any integer 1–1000 to change this. Pagination uses before_id / after_id with has_more, first_id and last_id in the response. [1]


Implement pagination in fetchModels() or document why it's not needed.

Verification confirms the issue: The ModelsListResponse interface includes pagination fields, but the implementation only retrieves the first page. Anthropic's models API endpoint returns 20 models per page by default, and pagination fields are never used anywhere in the codebase. If Anthropic returns more than 20 models, subsequent pages are silently ignored.

Either:

  • Implement pagination to fetch all available models (loop using has_more, last_id)
  • Or verify all Claude models fit within 20 and add a comment explaining why pagination isn't needed
🤖 Prompt for AI Agents
In api/anthropicClient.ts around lines 63–95, fetchModels only returns the first
page of models but ModelsListResponse includes pagination fields; implement
pagination: perform the initial GET then loop while response.data.has_more is
true, using the response.data.last_id (or the API's paging token) as a query
parameter to request the next page, concatenate each page's data array into a
single array, and after all pages are fetched return a ModelsListResponse
containing the combined data and final pagination fields (has_more false and
last_id from the last page). Ensure headers and error handling remain the same
and preserve type annotations; alternatively, if you choose not to paginate, add
a clear comment and a runtime assertion verifying the total models never exceed
one page and document why pagination is unnecessary.

✅ Addressed in commits e96ef65 to ee7faef

_⚠️ Potential issue_ | _🔴 Critical_ <details> <summary>🧩 Analysis chain</summary> **Pagination is not handled for model listing.** The `ModelsListResponse` interface includes `has_more`, `first_id`, and `last_id` fields that indicate pagination support, but `fetchModels()` only retrieves the first page of results. If Anthropic returns more than one page of models, subsequent pages are silently ignored. Verify whether pagination is needed: If pagination is required, consider implementing it or documenting the limitation. Otherwise, if all Claude models fit in a single page, add a comment explaining why pagination isn't needed. --- 🏁 Script executed: ```shell #!/bin/bash # Check if the ModelsListResponse type definition includes pagination fields rg -A 5 "interface ModelsListResponse" types.ts ``` Length of output: 128 --- I'll verify whether pagination is actually used or documented elsewhere in the codebase. ``` Additionally, let me search for API documentation references or comments about Anthropic's models endpoint: ``` ``` --- 🏁 Script executed: ```shell #!/bin/bash # Check if pagination fields are used anywhere in the codebase echo "=== Searching for usage of pagination fields ===" rg -n "(has_more|first_id|last_id)" --type ts --type js -C 2 echo "" echo "=== Searching for fetchModels calls ===" rg -n "fetchModels" --type ts --type js -C 2 echo "" echo "=== Searching for pagination-related comments or TODOs ===" rg -n "(pagination|TODO|FIXME)" --type ts --type js api/ ``` Length of output: 1321 --- 🏁 Script executed: ```shell #!/bin/bash # Check for documentation or API-related comments in the anthropicClient file echo "=== Full anthropicClient.ts file structure ===" rg -n "^(class|interface|export|async|const|function)" api/anthropicClient.ts echo "" echo "=== Check file for any comments about models endpoint ===" rg -n "(models|API|pagination|page)" api/anthropicClient.ts -i ``` Length of output: 2163 --- 🌐 Web query: ```web Anthropic models API endpoint pagination how many models returned ``` 💡 Result: By default the List Models endpoint returns 20 models per page. You can set the query param limit to any integer 1–1000 to change this. Pagination uses before_id / after_id with has_more, first_id and last_id in the response. [1] --- </details> **Implement pagination in `fetchModels()` or document why it's not needed.** Verification confirms the issue: The `ModelsListResponse` interface includes pagination fields, but the implementation only retrieves the first page. Anthropic's models API endpoint returns 20 models per page by default, and pagination fields are never used anywhere in the codebase. If Anthropic returns more than 20 models, subsequent pages are silently ignored. Either: - Implement pagination to fetch all available models (loop using `has_more`, `last_id`) - Or verify all Claude models fit within 20 and add a comment explaining why pagination isn't needed <details> <summary>🤖 Prompt for AI Agents</summary> ``` In api/anthropicClient.ts around lines 63–95, fetchModels only returns the first page of models but ModelsListResponse includes pagination fields; implement pagination: perform the initial GET then loop while response.data.has_more is true, using the response.data.last_id (or the API's paging token) as a query parameter to request the next page, concatenate each page's data array into a single array, and after all pages are fetched return a ModelsListResponse containing the combined data and final pagination fields (has_more false and last_id from the last page). Ensure headers and error handling remain the same and preserve type annotations; alternatively, if you choose not to paginate, add a clear comment and a runtime assertion verifying the total models never exceed one page and document why pagination is unnecessary. ``` </details> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commits e96ef65 to ee7faef
throw new Error('Unknown error occurred while generating prompts'); throw new Error('Unknown error occurred while generating prompts');
3