const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./BYXFvmSx.js","./DsanjglN.js","./CbGRcr-D.js"])))=>i.map(i=>d[i]);
import{s as e}from"./DrKWWDpL.js";import{n as t,t as n}from"./DsQIgu-4.js";import{t as r}from"./DYP3EJMY.js";import{t as i}from"./DTkg6Mnx.js";import{n as a}from"./DeO5NWhN.js";import{n as o,r as s,t as c}from"./DXsj0Ygw.js";import{t as l}from"./Dw1eNzkF.js";var u=e(r(),1);t();var d=i(`llm-catalog-resolver`),f;function p(){if(f!==void 0)return f;try{let e=(0,u.join)((0,u.dirname)((0,u.fileURLToPath)(import.meta.url)),`curated-catalog.json`);f=JSON.parse((0,u.readFileSync)(e,`utf-8`))}catch(e){d.warn({err:e instanceof Error?e.message:String(e)},`catalog-resolver: shipped seed unreadable`),f=null}return f}async function m(e){return e?.db===void 0?(await a(`global`)).db:e.db}async function h(e,t){let{desc:r,eq:i}=await n(async()=>{let{desc:e,eq:t}=await import(`./BYXFvmSx.js`);return{desc:e,eq:t}},__vite__mapDeps([0,1,2]),import.meta.url),a=(await e.select({id:l.id,providerId:l.providerId,releaseDate:l.releaseDate,contextLimit:l.contextLimit}).from(l).where(i(l.providerId,t)).orderBy(r(l.releaseDate),r(l.id)).limit(1))[0];return a?{id:a.id,providerId:a.providerId,releaseDate:a.releaseDate,contextLimit:a.contextLimit??null,source:`table`}:null}function g(e,t,n){let r=null,i=``,a=null;for(let[t,n]of Object.entries(e)){let e=n.release_date;e&&(e>i||e===i&&r!==null&&t>r)&&(i=e,r=t,a=n.limit?.context??null)}return r===null?null:{id:r,providerId:t,releaseDate:i,contextLimit:a,source:n}}async function _(e,t){let n=e.toLowerCase();try{let e=await h(await m(t),n);if(e)return e}catch(e){d.warn({err:e instanceof Error?e.message:String(e),providerId:n},`catalog-resolver: models_catalog read failed; falling back to disk cache`)}let r=c(t?.cacheDir??o());if(r){let e=s(r)?.[n];if(e?.models){let t=g(e.models,n,`disk-cache`);if(t)return t}}let i=p()?.models?.[n];if(i){let e=g(i,n,`shipped-seed`);if(e)return e}return null}export{_ as resolveCatalogEntry};