-
Couldn't load subscription status.
- Fork 715
refactor(env): modernize model configuration environment variables #1375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the model configuration system by modernizing environment variable names from OPENAI_* to MODEL_* and VL_MODE to LOCATOR_MODE, improving clarity and semantic accuracy while maintaining backward compatibility for documented public API variables.
Key Changes:
- Renamed public API variables (
OPENAI_API_KEY→MODEL_API_KEY,OPENAI_BASE_URL→MODEL_BASE_URL) with backward compatibility - Updated internal variables from
OPENAItoMODELprefix across all intent types (VQA, planning, grounding) - Renamed
VL_MODEtoLOCATOR_MODEfor better semantic clarity - Improved type system by separating public
TModelConfigFnfrom internalTModelConfigFnInternal
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/shared/src/env/types.ts | Updated type definitions, added new MODEL_* constants, deprecated old OPENAI_* constants, separated public/internal type definitions |
| packages/shared/src/env/constants.ts | Updated constant mappings to use new MODEL_* and LOCATOR_MODE naming |
| packages/shared/src/env/decide-model-config.ts | Implemented backward compatibility logic for legacy OPENAI_* variables |
| packages/shared/src/env/model-config-manager.ts | Added type casting to support internal type while maintaining public API simplicity |
| packages/shared/src/env/init-debug.ts | Updated debug variable references from DEBUG_AI_* to DEBUG_MODEL_* |
| packages/shared/tests/unit-test/env/*.test.ts | Updated test files to use new variable names |
| packages/web-integration/tests/unit-test/*.test.ts | Updated mock configurations to use new variable names |
| packages/core/tests/unit-test/*.test.ts | Updated test configurations and comments to reflect new naming |
| packages/android/tests/unit-test/agent.test.ts | Updated mock configuration to use new variable names |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
This PR refactors the model configuration system with improved naming conventions
and better type safety while maintaining backward compatibility.
Key Changes:
1. Environment Variable Naming Convention Updates:
- Renamed OPENAI_* → MODEL_* for public API variables
* OPENAI_API_KEY → MODEL_API_KEY (deprecated, backward compatible)
* OPENAI_BASE_URL → MODEL_BASE_URL (deprecated, backward compatible)
- Renamed MIDSCENE_*_VL_MODE → MIDSCENE_*_LOCATOR_MODE across all intents
* MIDSCENE_VL_MODE → MIDSCENE_LOCATOR_MODE
* MIDSCENE_VQA_VL_MODE → MIDSCENE_VQA_LOCATOR_MODE
* MIDSCENE_PLANNING_VL_MODE → MIDSCENE_PLANNING_LOCATOR_MODE
* MIDSCENE_GROUNDING_VL_MODE → MIDSCENE_GROUNDING_LOCATOR_MODE
- Updated all internal MIDSCENE_*_OPENAI_* → MIDSCENE_*_MODEL_*
* MIDSCENE_VQA_OPENAI_API_KEY → MIDSCENE_VQA_MODEL_API_KEY
* MIDSCENE_PLANNING_OPENAI_API_KEY → MIDSCENE_PLANNING_MODEL_API_KEY
* MIDSCENE_GROUNDING_OPENAI_API_KEY → MIDSCENE_GROUNDING_MODEL_API_KEY
* (and corresponding BASE_URL variables)
2. Type System Improvements:
- Split TModelConfigFn into public and internal types
- Public API (TModelConfigFn) no longer exposes 'intent' parameter
- Internal type (TModelConfigFnInternal) maintains intent parameter
- Users can still optionally use intent parameter via type casting
3. Backward Compatibility:
- Maintained compatibility for documented public variables (OPENAI_API_KEY, OPENAI_BASE_URL)
- New variables take precedence, fallback to legacy names if not set
- Only public documented variables are deprecated, internal variables renamed directly
4. Updated Files:
- packages/shared/src/env/types.ts - Type definitions and constants
- packages/shared/src/env/constants.ts - Config key mappings
- packages/shared/src/env/decide-model-config.ts - Compatibility logic
- packages/shared/src/env/model-config-manager.ts - Type casting implementation
- packages/shared/src/env/init-debug.ts - Debug variable updates
- All test files updated to use new variable names
Testing:
- All 24 model-config-manager tests passing
- Overall test suite: 241 tests passing
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Co-authored-by: Copilot <[email protected]>
2e0da2f to
155a9fd
Compare
…* variables - Added test suite to verify MODEL_API_KEY/MODEL_BASE_URL take precedence - Added test to ensure OPENAI_API_KEY/OPENAI_BASE_URL still work as fallback - Fixed compatibility logic to prioritize new variables over legacy ones - All 13 tests passing, including 5 new backward compatibility tests Test coverage: ✓ Using only legacy variables (OPENAI_API_KEY) ✓ Using only new variables (MODEL_API_KEY) ✓ Mixing new and legacy variables (new takes precedence) ✓ Individual precedence for API_KEY and BASE_URL 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The test 'should return the correct value from override' was failing because .env file sets MIDSCENE_CACHE=1. This was polluting the test environment and causing the test to expect false but receive true. Fixed by explicitly resetting MIDSCENE_CACHE to empty string in beforeEach. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…uration examples for agents
Summary
This PR refactors the model configuration system with improved naming conventions and better type safety while maintaining backward compatibility for publicly documented environment variables.
Motivation
MODEL_*pattern instead ofOPENAI_*, better reflecting that the system supports multiple model providersVL_MODE→LOCATOR_MODEto more accurately describe the element localization modeKey Changes
1. Environment Variable Naming Updates
Public API Variables (with backward compatibility):
OPENAI_API_KEY→MODEL_API_KEY(old name deprecated but still works)OPENAI_BASE_URL→MODEL_BASE_URL(old name deprecated but still works)Locator Mode Variables (VL_MODE → LOCATOR_MODE):
MIDSCENE_VL_MODE→MIDSCENE_LOCATOR_MODEMIDSCENE_VQA_VL_MODE→MIDSCENE_VQA_LOCATOR_MODEMIDSCENE_PLANNING_VL_MODE→MIDSCENE_PLANNING_LOCATOR_MODEMIDSCENE_GROUNDING_VL_MODE→MIDSCENE_GROUNDING_LOCATOR_MODEInternal Model Configuration Variables (OPENAI → MODEL):
MIDSCENE_VQA_OPENAI_API_KEY→MIDSCENE_VQA_MODEL_API_KEYMIDSCENE_VQA_OPENAI_BASE_URL→MIDSCENE_VQA_MODEL_BASE_URLMIDSCENE_PLANNING_OPENAI_API_KEY→MIDSCENE_PLANNING_MODEL_API_KEYMIDSCENE_PLANNING_OPENAI_BASE_URL→MIDSCENE_PLANNING_MODEL_BASE_URLMIDSCENE_GROUNDING_OPENAI_API_KEY→MIDSCENE_GROUNDING_MODEL_API_KEYMIDSCENE_GROUNDING_OPENAI_BASE_URL→MIDSCENE_GROUNDING_MODEL_BASE_URL2. Type System Improvements
Before:
After:
Users no longer see the
intentparameter in the public API, making it simpler to use. The parameter is still available internally and can be optionally used by advanced users.3. Backward Compatibility Implementation
For documented public variables, the system now:
MODEL_API_KEY)OPENAI_API_KEY)Example in
decide-model-config.ts:Testing
✅ All 24 model-config-manager tests passing
✅ Overall test suite: 241 tests passing
✅ Backward compatibility verified for
OPENAI_API_KEYandOPENAI_BASE_URLMigration Guide
For Users
No immediate action required! Old environment variables continue to work:
OPENAI_API_KEYandOPENAI_BASE_URLare still supportedRecommended (optional): Update to new variable names for better clarity:
For Contributors
When working with the codebase:
packages/shared/src/env/types.ts@deprecatedJSDoc commentsFiles Changed
Core Implementation:
packages/shared/src/env/types.ts- Type definitions and constantspackages/shared/src/env/constants.ts- Config key mappingspackages/shared/src/env/decide-model-config.ts- Compatibility logicpackages/shared/src/env/model-config-manager.ts- Type casting implementationpackages/shared/src/env/init-debug.ts- Debug variable updatesTests:
Breaking Changes
The following internal variables were renamed directly (no backward compatibility):
MIDSCENE_VQA_OPENAI_*→MIDSCENE_VQA_MODEL_*MIDSCENE_PLANNING_OPENAI_*→MIDSCENE_PLANNING_MODEL_*MIDSCENE_GROUNDING_OPENAI_*→MIDSCENE_GROUNDING_MODEL_*These were never publicly documented and are considered internal implementation details.
🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]