(
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;
},
)
| 154 | } |
| 155 | |
| 156 | export 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, |
no test coverage detected