diff --git a/packages/llm/llm-deepseek/src/file-store.ts b/packages/llm/llm-deepseek/src/file-store.ts index c402a3d5ed..da6f87654a 100644 --- a/packages/llm/llm-deepseek/src/file-store.ts +++ b/packages/llm/llm-deepseek/src/file-store.ts @@ -32,12 +32,6 @@ export interface DeepSeekFileReference { uploaded: boolean } -/** One request-image version with the exact remote id a model request rejected. */ -export interface DeepSeekRejectedUpload { - version: RequestImageAttachment - fileId: DeepSeekFileId -} - interface FileStoreOptions { index?: DeepSeekUploadIndex now?: () => number @@ -251,17 +245,14 @@ export class DeepSeekFileStore { /** * Invalidate exact local mappings in one index update after a model request rejects their remote ids. - * @param rejected - request-image versions with the exact file id the request used for each. + * @param generations - request-image variants with the exact file id the request used for each. * @param connection - endpoint and API-key snapshot. */ async invalidate( - rejected: readonly DeepSeekRejectedUpload[], + generations: readonly Pick[], connection: DeepSeekFileConnection, ): Promise { - await this.index.remove( - fileScope(connection), - rejected.map(({ version, fileId }) => ({ variantId: version.variantId, fileId })), - ) + await this.index.remove(fileScope(connection), generations) } /** diff --git a/packages/llm/llm-deepseek/src/index.ts b/packages/llm/llm-deepseek/src/index.ts index 53d565ce3f..623dbea335 100644 --- a/packages/llm/llm-deepseek/src/index.ts +++ b/packages/llm/llm-deepseek/src/index.ts @@ -28,7 +28,7 @@ export { } from './request-pricing.ts' export { deepSeekImageTokens, deepSeekRequestImageDimensions } from './image-tokens.ts' export { DeepSeekFileStore, MAX_IMAGE_BYTES } from './file-store.ts' -export type { DeepSeekFileConnection, DeepSeekFilePolicy, DeepSeekFileReference, DeepSeekRejectedUpload } from './file-store.ts' +export type { DeepSeekFileConnection, DeepSeekFilePolicy, DeepSeekFileReference } from './file-store.ts' export { DeepSeekFilesClient, MAX_FILE_EXPIRY_SECONDS, MAX_FILE_UPLOAD_BYTES, MAX_STORED_FILE_BYTES, MAX_STORED_FILE_COUNT, MIN_FILE_EXPIRY_SECONDS } from './files-api.ts' export type { DeepSeekFileObject, DeepSeekFilePage } from './files-api.ts' export { DeepSeekFileId } from './file-id.ts' diff --git a/packages/llm/llm-deepseek/src/request-files.ts b/packages/llm/llm-deepseek/src/request-files.ts index cfee416482..85e1460903 100644 --- a/packages/llm/llm-deepseek/src/request-files.ts +++ b/packages/llm/llm-deepseek/src/request-files.ts @@ -134,7 +134,10 @@ export class RequestFiles { */ async retry(detail: string): Promise { if (this.used.length === 0 || !providerRejectedFileId(detail)) return false - await this.files.invalidate(staleMappings(this.used, detail), this.connection) + await this.files.invalidate( + staleMappings(this.used, detail).map(file => ({ variantId: file.version.variantId, fileId: file.fileId })), + this.connection, + ) if (this.retried) return false this.retried = true return true diff --git a/packages/llm/llm-deepseek/tests/file-store.spec.ts b/packages/llm/llm-deepseek/tests/file-store.spec.ts index b27a7e3078..a8cb1458a4 100644 --- a/packages/llm/llm-deepseek/tests/file-store.spec.ts +++ b/packages/llm/llm-deepseek/tests/file-store.spec.ts @@ -98,10 +98,10 @@ describe('DeepSeekFileStore', () => { expect((await store.ensureUploaded(VERSION, { ...CONNECTION, baseURL: `${CONNECTION.baseURL}/v1/` }, POLICY)).record).toEqual(first.record) const reopened = new DeepSeekFileStore({ index, fetch: remote.fetchImpl, now: () => now }) expect((await reopened.ensureUploaded(VERSION, CONNECTION, POLICY)).record).toEqual(first.record) - await reopened.invalidate([{ version: VERSION, fileId: other.record.fileId }], CONNECTION) + await reopened.invalidate([{ variantId: VERSION.variantId, fileId: other.record.fileId }], CONNECTION) expect((await reopened.ensureUploaded(VERSION, CONNECTION, POLICY)).record).toEqual(first.record) expect(remote.uploads()).toBe(2) - await reopened.invalidate([{ version: VERSION, fileId: first.record.fileId }], CONNECTION) + await reopened.invalidate([{ variantId: VERSION.variantId, fileId: first.record.fileId }], CONNECTION) const replacement = await reopened.ensureUploaded(VERSION, CONNECTION, POLICY) expect(replacement.record.fileId).not.toBe(first.record.fileId) expect((await reopened.ensureUploaded(VERSION, alternate, POLICY)).record).toEqual(other.record) diff --git a/packages/llm/llm-deepseek/tests/files.spec.ts b/packages/llm/llm-deepseek/tests/files.spec.ts index 13e226ce9c..bb44326318 100644 --- a/packages/llm/llm-deepseek/tests/files.spec.ts +++ b/packages/llm/llm-deepseek/tests/files.spec.ts @@ -73,10 +73,7 @@ describe('Messages Files requests', () => { vi.stubGlobal('fetch', fetchImpl) const h = harness() await chunks(h.adapter.stream(request([ref, second]))) - expect(h.invalidate).toHaveBeenCalledExactlyOnceWith( - [expect.objectContaining({ version: expect.objectContaining({ attachment: ref }), fileId: 'file-a' })], - expect.objectContaining({}), - ) + expect(h.invalidate).toHaveBeenCalledExactlyOnceWith([{ variantId: version(ref).variantId, fileId: 'file-a' }], expect.objectContaining({})) expect(fetchImpl).toHaveBeenCalledTimes(2) expect(h.prepare).toHaveBeenCalledTimes(2) expect(h.ensureUploaded).toHaveBeenCalledTimes(4)