File size: 986 Bytes
f500658 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import type { AgentSessionRuntimeDiagnostic } from "./agent-session-services.ts";
import type { SettingsManager } from "./settings-manager.ts";
export function collectSettingsDiagnostics(settingsManager: SettingsManager): AgentSessionRuntimeDiagnostic[] {
return settingsManager.drainErrors().map(({ scope, path, error }) => ({
type: "warning",
message: path ? `Invalid settings file ${path}: ${error.message}` : `Invalid ${scope} settings: ${error.message}`,
}));
}
/**
* Remove duplicate type/message diagnostics while preserving their first occurrence.
* Startup and runtime settings managers can report the same file error.
*/
export function deduplicateDiagnostics(
diagnostics: readonly AgentSessionRuntimeDiagnostic[],
): AgentSessionRuntimeDiagnostic[] {
const seen = new Set<string>();
return diagnostics.filter((diagnostic) => {
const key = `${diagnostic.type}\0${diagnostic.message}`;
if (seen.has(key)) return false;
seen.add(key);
return true;
});
}
|