feat: add region configuration for Mistral OCR on Vertex AI#11539
feat: add region configuration for Mistral OCR on Vertex AI#11539devanchohan wants to merge 2 commits intodanny-avila:mainfrom
Conversation
Add separate region configuration for Mistral OCR to resolve conflicts with Gemini 3 models that require the global endpoint. Changes: - Add `region` field to OCR schema in data-provider - Add `MISTRAL_VERTEX_REGION` environment variable support - Add `getRegionConfig()` helper function - Update `performGoogleVertexOCR()` to accept region parameter - Add region resolution logic with priority: config > MISTRAL_VERTEX_REGION > GOOGLE_LOC - Maintains full backward compatibility This follows the pattern established by Anthropic Vertex AI configuration.
There was a problem hiding this comment.
Pull request overview
Adds an explicit region configuration path for Google Vertex AI Mistral OCR to avoid conflicts with other Vertex model region requirements.
Changes:
- Adds
regionto the OCR config schema (data-provider). - Introduces
getRegionConfig()to resolve region from config/env placeholders. - Updates Vertex OCR call path to accept/use a
regionparameter with fallback precedence.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/data-provider/src/config.ts | Extends OCR schema with a region field intended to support Mistral Vertex region configuration. |
| packages/api/src/files/mistral/crud.ts | Adds region resolution helper and wires region into Vertex OCR request URL construction. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| function getRegionConfig(ocrConfig?: TCustomConfig['ocr']): string | undefined { | ||
| const regionConfig = ocrConfig?.region || ''; | ||
|
|
||
| if (!regionConfig.trim()) { | ||
| return undefined; | ||
| } | ||
|
|
||
| if (envVarRegex.test(regionConfig)) { | ||
| return extractEnvVariable(regionConfig) || undefined; | ||
| } | ||
|
|
||
| return regionConfig.trim(); | ||
| } |
There was a problem hiding this comment.
getRegionConfig() can return an unresolved env placeholder. extractEnvVariable('${MISTRAL_VERTEX_REGION}') returns the original string when the env var is missing (see extractEnvVariable implementation), and || undefined won’t remove it since the placeholder is truthy. This causes callers to treat '${...}' as a real region. After extracting, check envVarRegex on the resolved value and return undefined (or otherwise fall back) when it’s still unresolved.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
| // Priority: function parameter > MISTRAL_VERTEX_REGION > GOOGLE_LOC > default | ||
| const location = region || process.env.MISTRAL_VERTEX_REGION || process.env.GOOGLE_LOC || 'us-central1'; |
There was a problem hiding this comment.
The new region resolution path isn’t covered by tests in this module. Add unit tests that verify location selection precedence (explicit ocr.region string, ocr.region env placeholder with env set, fallback to MISTRAL_VERTEX_REGION, then GOOGLE_LOC, then default) and that unresolved placeholders are not used to build the Vertex endpoint URL.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
Co-authored-by: Copilot <[email protected]>
Add separate region configuration for Mistral OCR to resolve conflicts with Gemini 3 models that require the global endpoint.
Changes:
regionfield to OCR schema in data-providerMISTRAL_VERTEX_REGIONenvironment variable supportgetRegionConfig()helper functionperformGoogleVertexOCR()to accept region parameterThis follows the pattern established by Anthropic Vertex AI configuration.
Pull Request Template
Summary
Please provide a brief summary of your changes and the related issue. Include any motivation and context that is relevant to your changes. If there are any dependencies necessary for your changes, please list them here.
Change Type
Please delete any irrelevant options.
Testing
Please describe your test process and include instructions so that we can reproduce your test. If there are any important variables for your testing configuration, list them here.
Test Configuration:
Checklist
Please delete any irrelevant options.