// Select a declared module without guessing a provider from the model id. // Legacy entries may map through exactly one enabled module; ambiguity fails closed. export function selectModelProvider(modules, selection) { const candidates = modules.filter(({name, module}) => { if (selection?.module && selection.module !== name) return false; try { const route = module.route({selection, harness:null}); return route && !route.code && route.provider === selection?.provider && route.model === selection?.model; } catch { return false; } }); return candidates.length === 1 ? candidates[0] : null; }