MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / stripEnvModelConfig

Function stripEnvModelConfig

packages/agent-core/src/config/env-model.ts:170–197  ·  view source on GitHub ↗
(config: KimiConfig)

Source from the content-addressed store, hash-verified

168 * config.toml survive the round-trip.
169 */
170export function stripEnvModelConfig(config: KimiConfig): KimiConfig {
171 const hasProvider = ENV_MODEL_PROVIDER_KEY in config.providers;
172 const hasModel = config.models !== undefined && ENV_MODEL_ALIAS_KEY in config.models;
173 const defaultIsEnv = config.defaultModel === ENV_MODEL_ALIAS_KEY;
174 if (!hasProvider && !hasModel && !defaultIsEnv) return config;
175
176 const providers = { ...config.providers };
177 delete providers[ENV_MODEL_PROVIDER_KEY];
178
179 let models = config.models;
180 if (models !== undefined && ENV_MODEL_ALIAS_KEY in models) {
181 models = { ...models };
182 delete models[ENV_MODEL_ALIAS_KEY];
183 }
184
185 return {
186 ...config,
187 providers,
188 ...(models !== undefined ? { models } : {}),
189 // Restore env-injected top-level fields from raw instead of persisting the
190 // shell overrides: the env default_model (when it points at the env alias),
191 // and the env thinking. Reaching here means env-model mode is active (the
192 // synthetic provider/model exist), so these may be env values; an unset raw
193 // field restores to undefined (i.e. drops it).
194 ...(defaultIsEnv ? { defaultModel: rawDefaultModel(config) } : {}),
195 thinking: rawThinking(config),
196 };
197}
198
199function rawDefaultModel(config: KimiConfig): string | undefined {
200 const raw = config.raw?.['default_model'];

Callers 2

env-model.test.tsFile · 0.90
writeConfigFileFunction · 0.90

Calls 2

rawDefaultModelFunction · 0.85
rawThinkingFunction · 0.85

Tested by

no test coverage detected