diff --git a/src/resources/vector-stores/file-batches.ts b/src/resources/vector-stores/file-batches.ts index cf0fd8dc61..2e4a9dc035 100644 --- a/src/resources/vector-stores/file-batches.ts +++ b/src/resources/vector-stores/file-batches.ts @@ -68,7 +68,7 @@ export class FileBatches extends APIResource { body: FileBatchCreateParams, options?: RequestOptions & { pollIntervalMs?: number }, ): Promise { - const batch = await this.create(vectorStoreId, body); + const batch = await this.create(vectorStoreId, body, options); return await this.poll(vectorStoreId, batch.id, options); } @@ -182,9 +182,13 @@ export class FileBatches extends APIResource { // Wait for all processing to complete. await allSettledWithThrow(workers); - return await this.createAndPoll(vectorStoreId, { - file_ids: allFileIds, - }); + return await this.createAndPoll( + vectorStoreId, + { + file_ids: allFileIds, + }, + options, + ); } } diff --git a/tests/api-resources/vector-stores/file-batches.test.ts b/tests/api-resources/vector-stores/file-batches.test.ts index 0ca505ae78..bc9ecc418c 100644 --- a/tests/api-resources/vector-stores/file-batches.test.ts +++ b/tests/api-resources/vector-stores/file-batches.test.ts @@ -80,4 +80,57 @@ describe('resource fileBatches', () => { order: 'asc', }); }); + + test('uploadAndPoll passes options through to batch creation and polling', async () => { + const requests: Array<{ url: string; init: RequestInit | undefined }> = []; + const batch = { + id: 'vsfb_abc123', + object: 'vector_store.files_batch', + created_at: 0, + vector_store_id: 'vs_abc123', + status: 'completed', + file_counts: { in_progress: 0, completed: 1, failed: 0, cancelled: 0, total: 1 }, + }; + const testClient = new OpenAI({ + apiKey: 'My API Key', + baseURL: 'http://127.0.0.1:4010', + fetch: async (url, init) => { + requests.push({ url: String(url), init }); + const pathname = new URL(String(url)).pathname; + const body = + pathname === '/files' ? + { + id: 'file_abc123', + object: 'file', + bytes: 0, + created_at: 0, + filename: 'README.md', + purpose: 'assistants', + } + : batch; + + return new Response(JSON.stringify(body), { + headers: { 'Content-Type': 'application/json' }, + }); + }, + }); + + const response = await testClient.vectorStores.fileBatches.uploadAndPoll( + 'vs_abc123', + { files: [new File(['Example data'], 'README.md')] }, + { pollIntervalMs: 1, headers: { 'X-Test-Header': 'present' } }, + ); + + const apiRequests = requests.filter(({ url }) => url.startsWith('http://127.0.0.1')); + + expect(response.id).toBe('vsfb_abc123'); + expect(apiRequests.map(({ url }) => new URL(url).pathname)).toEqual([ + '/files', + '/vector_stores/vs_abc123/file_batches', + '/vector_stores/vs_abc123/file_batches/vsfb_abc123', + ]); + expect(new Headers(apiRequests[1]?.init?.headers).get('x-test-header')).toBe('present'); + expect(new Headers(apiRequests[2]?.init?.headers).get('x-test-header')).toBe('present'); + expect(new Headers(apiRequests[2]?.init?.headers).get('x-stainless-custom-poll-interval')).toBe('1'); + }); });