"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("../providers/ChatRuntime.cjs.js"),o=require("react"),d="agent-chat:selected-model",i={get:t=>typeof window>"u"?null:localStorage.getItem(t),set:(t,s)=>{typeof window>"u"||localStorage.setItem(t,s)}};function y(){const{apiUrl:t,identity:s}=m.useChatRuntime(),[g,S]=o.useState([]),[r,l]=o.useState(()=>i.get(d)??""),[h,c]=o.useState(!1),u=o.useCallback(async()=>{if(s?.authToken){c(!0);try{const a=await fetch(`${t}/agents/models`,{headers:{Authorization:`Bearer ${s.authToken}`}});if(!a.ok)return;const f=await a.json(),n=(Array.isArray(f.data)?f.data:[]).filter(e=>!/embed|rerank/i.test(e.id)).map(e=>({id:e.id,name:e.name??e.id}));S(n),n.length>0&&!n.find(e=>e.id===r)&&(l(n[0].id),i.set(d,n[0].id))}catch{}finally{c(!1)}}},[t,s?.authToken,r]);return o.useEffect(()=>{u()},[u]),{models:g,selectedModel:r,setSelectedModel:a=>{l(a),i.set(d,a)},loading:h}}exports.useModels=y;
//# sourceMappingURL=use-models.cjs.js.map
