MCPcopy Create free account
hub / github.com/continuedev/continue / setupProviderConfig

Function setupProviderConfig

core/config/onboarding.ts:132–171  ·  view source on GitHub ↗
(
  config: ConfigYaml,
  provider: string,
  apiKey: string,
)

Source from the content-addressed store, hash-verified

130}
131
132export function setupProviderConfig(
133 config: ConfigYaml,
134 provider: string,
135 apiKey: string,
136): ConfigYaml {
137 let newModels: OnboardingModel[];
138
139 switch (provider) {
140 case "openai":
141 newModels = OPENAI_ONBOARDING_MODELS(apiKey);
142 break;
143 case "anthropic":
144 newModels = ANTHROPIC_ONBOARDING_MODELS(apiKey);
145 break;
146 case "gemini":
147 newModels = GEMINI_ONBOARDING_MODELS(apiKey);
148 break;
149 default:
150 throw new Error(`Unknown provider: ${provider}`);
151 }
152
153 const existingModels = config.models ?? [];
154
155 const isSameModel = (m: OnboardingModel, n: OnboardingModel) =>
156 "provider" in m &&
157 "provider" in n &&
158 m.provider === n.provider &&
159 m.model === n.model;
160
161 // Update API key on existing models; add new entries for any missing models
162 const updatedModels = existingModels.map((m) => {
163 const match = newModels.find((n) => isSameModel(m, n));
164 return match ? { ...m, apiKey } : m;
165 });
166 const modelsToAdd = newModels.filter(
167 (n) => !existingModels.some((m) => isSameModel(m, n)),
168 );
169
170 return { ...config, models: [...updatedModels, ...modelsToAdd] };
171}

Callers 1

Calls 4

OPENAI_ONBOARDING_MODELSFunction · 0.85
GEMINI_ONBOARDING_MODELSFunction · 0.85
isSameModelFunction · 0.85

Tested by

no test coverage detected