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

Function salvageConfigData

packages/agent-core/src/config/toml.ts:212–247  ·  view source on GitHub ↗
(transformed: Record<string, unknown>)

Source from the content-addressed store, hash-verified

210}
211
212function salvageConfigData(transformed: Record<string, unknown>): SalvageResult {
213 const dropped: string[] = [];
214 for (;;) {
215 const result = KimiConfigSchema.safeParse(transformed);
216 if (result.success) {
217 return { config: result.data, dropped };
218 }
219 let deletedAny = false;
220 for (const issue of result.error.issues) {
221 const [section, entry] = issue.path;
222 if (typeof section !== 'string' || !(section in transformed)) continue;
223 const sectionValue = transformed[section];
224 if (
225 ENTRY_KEYED_SECTIONS.has(section) &&
226 typeof entry === 'string' &&
227 isPlainObject(sectionValue)
228 ) {
229 // Issues on entry-keyed sections only ever drop that entry. An entry
230 // with several issues is deleted by the first one; later issues are
231 // no-ops and must not escalate to deleting the whole section.
232 if (entry in sectionValue) {
233 delete sectionValue[entry];
234 dropped.push(`${camelToSnake(section)}.${entry}`);
235 deletedAny = true;
236 }
237 continue;
238 }
239 delete transformed[section];
240 dropped.push(camelToSnake(section));
241 deletedAny = true;
242 }
243 if (!deletedAny) {
244 return { config: undefined, dropped, error: result.error };
245 }
246 }
247}
248
249function describeUnknownError(error: unknown): string {
250 return error instanceof Error ? error.message : String(error);

Callers 1

loadRuntimeConfigSafeFunction · 0.85

Calls 4

isPlainObjectFunction · 0.70
camelToSnakeFunction · 0.70
hasMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected