( request: ProviderRequest, providerId: ProviderId | string )
| 106 | * and BYOK keys both work. |
| 107 | */ |
| 108 | export async function uploadLargeFilesToProvider( |
| 109 | request: ProviderRequest, |
| 110 | providerId: ProviderId | string |
| 111 | ): Promise<void> { |
| 112 | if (getProviderFileStrategy(providerId) !== 'files-api') return |
| 113 | |
| 114 | const groups = groupUploadableFiles(request.messages) |
| 115 | if (groups.length === 0) return |
| 116 | |
| 117 | const maxBytes = getProviderAttachmentMaxBytes(providerId) |
| 118 | const ai = providerId === 'google' ? new GoogleGenAI({ apiKey: request.apiKey }) : null |
| 119 | |
| 120 | for (const group of groups) { |
| 121 | const [representative] = group |
| 122 | await assertFileAccessForUpload(representative, request.userId) |
| 123 | if (providerId === 'openai') { |
| 124 | await uploadOpenAIFile(representative, request.apiKey, maxBytes, request.abortSignal) |
| 125 | } else if (ai) { |
| 126 | await uploadGeminiFile(representative, ai, maxBytes, request.abortSignal) |
| 127 | } |
| 128 | for (const file of group) { |
| 129 | file.providerFileId = representative.providerFileId |
| 130 | file.providerFileUri = representative.providerFileUri |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Verifies the caller may read this file before its bytes are uploaded to a provider. Enforced |
no test coverage detected