feat(env): add backward compatibility for MIDSCENE_OPENAI_* environment variables #1388
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds backward compatibility support for legacy
MIDSCENE_OPENAI_*environment variables that were renamed during the recent refactoring. This ensures existing users can continue using the old variable names without breaking their configurations.Background
During the recent environment variable refactoring (#1375), the following variables were renamed but backward compatibility was not fully implemented:
MIDSCENE_OPENAI_INIT_CONFIG_JSON→MIDSCENE_MODEL_INIT_CONFIG_JSONMIDSCENE_OPENAI_HTTP_PROXY→MIDSCENE_MODEL_HTTP_PROXYMIDSCENE_OPENAI_SOCKS_PROXY→MIDSCENE_MODEL_SOCKS_PROXYThis caused
overrideAIConfig()to reject these legacy variable names with the error:Changes
Code Changes
packages/shared/src/env/types.ts@deprecatedJSDoc tagsMODEL_ENV_KEYSarray to supportoverrideAIConfig()IModelConfigForDefaultLegacyinterface to use legacy variable namespackages/shared/src/env/constants.tsDEFAULT_MODEL_CONFIG_KEYS_LEGACYto use legacy variable names for proxy and init configpackages/shared/src/env/decide-model-config.tsdecideOpenaiSdkConfig():OPENAI_API_KEY/OPENAI_BASE_URLDocumentation Updates
apps/site/docs/zh/model-provider.mdx(Chinese)apps/site/docs/en/model-provider.mdx(English)Priority Logic
When both old and new variables are set, new variables take precedence:
MIDSCENE_OPENAI_INIT_CONFIG_JSONMIDSCENE_MODEL_INIT_CONFIG_JSONMIDSCENE_OPENAI_HTTP_PROXYMIDSCENE_MODEL_HTTP_PROXYMIDSCENE_OPENAI_SOCKS_PROXYMIDSCENE_MODEL_SOCKS_PROXYTesting
✅ All 139 tests pass in
packages/sharedBackward Compatibility
This PR ensures:
overrideAIConfig()accepts legacy variable namesRelated
🤖 Generated with Claude Code