π OpenHands: AI-Driven Development
Update Suggestions Service API to use new V1 endpoint with pagination (#13872)
Tim O'Farrelld3d916745ab8
diff --git a/frontend/src/api/suggestions-service/suggestions-service.api.ts b/frontend/src/api/suggestions-service/suggestions-service.api.tsindex 2989cf28b3..b9219a0b7c 100644--- a/frontend/src/api/suggestions-service/suggestions-service.api.ts+++ b/frontend/src/api/suggestions-service/suggestions-service.api.ts@@ -1,9 +1,31 @@import { SuggestedTask } from "#/utils/types";import { openHands } from "../open-hands-axios";+interface SuggestedTaskPage {+ items: SuggestedTask[];+ next_page_id: string | null;+}+export class SuggestionsService {- static async getSuggestedTasks(): Promise<SuggestedTask[]> {- const { data } = await openHands.get("/api/user/suggested-tasks");- return data;+ /**+ * Get suggested tasks for the user with pagination.+ *+ * @param pageId - Optional cursor for the next page (from previous response's next_page_id)+ * @param limit - Max number of results per page (default: 30, max: 100)+ */+ static async getSuggestedTasks(+ pageId?: string,+ limit: number = 30,+ ): Promise<SuggestedTask[]> {+ const { data } = await openHands.get<SuggestedTaskPage>(+ "/api/v1/git/suggested-tasks/search",+ {+ params: {+ page_id: pageId ?? undefined,+ limit,+ },+ },+ );+ return data.items;}}diff --git a/frontend/src/hooks/query/use-suggested-tasks.ts b/frontend/src/hooks/query/use-suggested-tasks.tsindex 9f2d121943..e2e36b6dd4 100644--- a/frontend/src/hooks/query/use-suggested-tasks.ts+++ b/frontend/src/hooks/query/use-suggested-tasks.ts@@ -8,7 +8,7 @@ export const useSuggestedTasks = () => {return useQuery({queryKey: ["tasks"],- queryFn: SuggestionsService.getSuggestedTasks,+ queryFn: () => SuggestionsService.getSuggestedTasks(),select: groupSuggestedTasks,enabled: shouldShowUserFeatures,});diff --git a/frontend/src/mocks/task-suggestions-handlers.ts b/frontend/src/mocks/task-suggestions-handlers.tsindex 0d532f5ff6..c09c8db7ec 100644--- a/frontend/src/mocks/task-suggestions-handlers.ts+++ b/frontend/src/mocks/task-suggestions-handlers.ts@@ -80,6 +80,25 @@ const TASKS_2: SuggestedTask[] = [export const MOCK_TASKS = [...TASKS_1, ...TASKS_2];export const TASK_SUGGESTIONS_HANDLERS = [+ // New V1 endpoint with pagination+ http.get("/api/v1/git/suggested-tasks/search", async ({ request }) => {+ const url = new URL(request.url);+ const limit = url.searchParams.get("limit");+ const pageId = url.searchParams.get("page_id");++ // Simple pagination: return all items if no pagination params, otherwise apply limit+ let tasks = [...MOCK_TASKS];+ if (pageId || limit) {+ const limitNum = limit ? parseInt(limit, 10) : 30;+ tasks = tasks.slice(0, limitNum);+ }++ return HttpResponse.json({+ items: tasks,+ next_page_id: null, // No pagination in mock data+ });+ }),+ // Deprecated V0 endpoint (keep for backward compatibility)http.get("/api/user/suggested-tasks", async () =>HttpResponse.json(MOCK_TASKS),),