From e94814b59ec26b8bca4eeec41e0dbe6006c92504 Mon Sep 17 00:00:00 2001 From: Mark McDonald Date: Thu, 11 Sep 2025 02:02:31 +0800 Subject: [PATCH 1/2] Use correct pager logic for files.list The existing syntax worked but is very clunky, and not idiomatic. There's an example in cache.list too but the tests there are failing. --- javascript/files.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/javascript/files.js b/javascript/files.js index 16a1ba1..e806adb 100644 --- a/javascript/files.js +++ b/javascript/files.js @@ -159,17 +159,12 @@ export async function filesList() { // import {GoogleGenAI} from '@google/genai'; const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY }); console.log("My files:"); - // Using the pager style to list files - const pager = await ai.files.list({ config: { pageSize: 10 } }); - let page = pager.page; + // Using the pager to list files across multiple API requests. + const files= await ai.files.list({ config: { pageSize: 10 } }); const names = []; - while (true) { - for (const f of page) { - console.log(" ", f.name); - names.push(f.name); - } - if (!pager.hasNextPage()) break; - page = await pager.nextPage(); + for await (const f of files) { + console.log(" ", f.name); + names.push(f.name); } // [END files_list] return names; From 069d2d0ce74b098bca6a9f216c8e6ef7e13facee Mon Sep 17 00:00:00 2001 From: Mark McDonald Date: Sat, 13 Sep 2025 04:50:45 +0800 Subject: [PATCH 2/2] Update javascript/files.js Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- javascript/files.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/files.js b/javascript/files.js index e806adb..9a210e2 100644 --- a/javascript/files.js +++ b/javascript/files.js @@ -160,7 +160,7 @@ export async function filesList() { const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY }); console.log("My files:"); // Using the pager to list files across multiple API requests. - const files= await ai.files.list({ config: { pageSize: 10 } }); + const files = await ai.files.list({ config: { pageSize: 10 } }); const names = []; for await (const f of files) { console.log(" ", f.name);