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

Function applyOpenPlatformConfig

packages/oauth/src/open-platform.ts:156–218  ·  view source on GitHub ↗
(
  config: ManagedKimiConfigShape,
  options: {
    readonly platform: OpenPlatformDefinition;
    readonly models: readonly ManagedKimiCodeModelInfo[];
    readonly selectedModel: ManagedKimiCodeModelInfo;
    readonly thinking: boolean;
    /** Concrete thinking effort to persist (e.g. 'low'/'high'/'max'). Omit
     * for boolean models, where thinking is simply enabled with no effort. */
    readonly effort?: string;
    readonly apiKey: string;
  },
)

Source from the content-addressed store, hash-verified

154}
155
156export function applyOpenPlatformConfig(
157 config: ManagedKimiConfigShape,
158 options: {
159 readonly platform: OpenPlatformDefinition;
160 readonly models: readonly ManagedKimiCodeModelInfo[];
161 readonly selectedModel: ManagedKimiCodeModelInfo;
162 readonly thinking: boolean;
163 /** Concrete thinking effort to persist (e.g. 'low'/'high'/'max'). Omit
164 * for boolean models, where thinking is simply enabled with no effort. */
165 readonly effort?: string;
166 readonly apiKey: string;
167 },
168): ApplyOpenPlatformResult {
169 const providerKey = options.platform.id;
170 const modelKey = `${providerKey}/${options.selectedModel.id}`;
171
172 config.providers[providerKey] = {
173 type: 'kimi',
174 baseUrl: options.platform.baseUrl,
175 apiKey: options.apiKey,
176 };
177
178 const existingModels = config.models ?? {};
179 // Selectively merge upstream models into the existing config so any fields
180 // the user added by hand (or that upstream does not declare) survive a
181 // refresh. Models that upstream no longer lists are removed; the rest are
182 // merged field-by-field.
183 const upstreamKeys = new Set(options.models.map((m) => `${providerKey}/${m.id}`));
184 for (const [key, model] of Object.entries(existingModels)) {
185 if (isRecord(model) && model['provider'] === providerKey && !upstreamKeys.has(key)) {
186 delete existingModels[key];
187 }
188 }
189
190 for (const model of options.models) {
191 const aliasKey = `${providerKey}/${model.id}`;
192 const existing = isRecord(existingModels[aliasKey]) ? existingModels[aliasKey] : {};
193 const remoteAlias: ManagedKimiModelAlias = {
194 provider: providerKey,
195 model: model.id,
196 maxContextSize: model.contextLength,
197 capabilities: capabilitiesForModel(model),
198 ...(model.displayName !== undefined ? { displayName: model.displayName } : {}),
199 ...(model.supportEfforts !== undefined ? { supportEfforts: model.supportEfforts } : {}),
200 ...(model.defaultEffort !== undefined ? { defaultEffort: model.defaultEffort } : {}),
201 };
202 existingModels[aliasKey] = mergeRefreshedModelAlias(
203 existing,
204 remoteAlias,
205 MANAGED_KIMI_MODEL_FIELDS,
206 );
207 }
208
209 config.models = existingModels;
210 config.defaultModel = modelKey;
211 config.thinking = {
212 ...config.thinking,
213 enabled: options.thinking,

Callers 3

refreshProviderModelsFunction · 0.90
handleOpenPlatformLoginFunction · 0.85

Calls 4

isRecordFunction · 0.90
mergeRefreshedModelAliasFunction · 0.90
capabilitiesForModelFunction · 0.70
hasMethod · 0.65

Tested by

no test coverage detected