From 5bf804b266c73e6cdc01adc0822b5a6b262e2bf4 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Fri, 31 Oct 2025 13:35:49 +0100 Subject: [PATCH] Fixes pagination ID consistency in model sorting Recomputes pagination first and last IDs after sorting models to ensure consistent ID references match the sorted array order. Prevents potential misalignment between sorted model list and pagination metadata --- api/anthropicClient.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/api/anthropicClient.ts b/api/anthropicClient.ts index 02601c6..597b51c 100644 --- a/api/anthropicClient.ts +++ b/api/anthropicClient.ts @@ -222,12 +222,17 @@ export class AnthropicClient { (a.display_name ?? a.id).localeCompare(b.display_name ?? b.id) ); + // Recompute pagination IDs from sorted array to maintain consistency + // with returned data (original IDs were from unsorted API responses) + const sortedFirstId = sorted.length > 0 ? sorted[0].id : firstId; + const sortedLastId = sorted.length > 0 ? sorted[sorted.length - 1].id : lastId; + // Return combined response with all models return { data: sorted, - first_id: firstId, + first_id: sortedFirstId, has_more: false, // We've fetched all pages - last_id: lastId + last_id: sortedLastId }; } catch (error) { if (error instanceof Error) {