module.exports=[36162,e=>{"use strict";let t={baseUrl:process.env.OLLAMA_BASE_URL||"http://localhost:11434",defaultModel:process.env.OLLAMA_MODEL||"granite3.1-moe",fallbackModel:"llama3.2",maxTokens:2048,temperature:.7};function a(){return t.baseUrl.replace(/\/$/,"")}async function r(e,o,n){let l=a(),s=o||t.defaultModel;try{let a=await fetch(`${l}/api/chat`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:s,messages:e,stream:!1,options:{temperature:n?.temperature??t.temperature,num_predict:n?.maxTokens??t.maxTokens,top_p:n?.topP,frequency_penalty:n?.frequencyPenalty,presence_penalty:n?.presencePenalty}})});if(!a.ok)throw Error(`Ollama API error: ${a.status} ${a.statusText}`);return(await a.json()).response}catch(a){if(!o&&t.fallbackModel)return console.warn(`Model ${s} failed, trying fallback ${t.fallbackModel}:`,a instanceof Error?a.message:a),r(e,t.fallbackModel,n);throw a}}async function o(e){let t=a(),r=await fetch(`${t}/api/embeddings`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:"nomic-embed-text",prompt:e})});if(!r.ok)throw Error(`Embedding API error: ${r.status} ${r.statusText}`);return(await r.json()).embedding}async function n(){let e=a(),t=await fetch(`${e}/api/tags`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!t.ok)throw Error(`Failed to list models: ${t.status}`);return(await t.json()).models||[]}async function l(){try{let e=a(),t=new AbortController,r=setTimeout(()=>t.abort(),5e3),o=await fetch(`${e}/api/tags`,{method:"GET",signal:t.signal});return clearTimeout(r),o.ok}catch{return!1}}async function s(e,r,o,n){let l=a(),i=o||t.defaultModel,c="";try{let a=await fetch(`${l}/api/chat`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:i,messages:e,stream:!0,options:{temperature:n?.temperature??t.temperature,num_predict:n?.maxTokens??t.maxTokens}})});if(!a.ok||!a.body)throw Error(`Ollama streaming error: ${a.status}`);let o=a.body.getReader(),s=new TextDecoder;for(;;){let{done:e,value:t}=await o.read();if(e)break;for(let e of s.decode(t,{stream:!0}).split("\n").filter(Boolean))try{let t=JSON.parse(e);if(t.response&&(c+=t.response,r(t.response)),t.done)break}catch{}}return c}catch(a){if(!o&&t.fallbackModel)return console.warn(`Stream model ${i} failed, trying fallback ${t.fallbackModel}`),s(e,r,t.fallbackModel,n);throw a}}async function i(e,t,a){let o=[];return a&&o.push({role:"system",content:a}),o.push({role:"user",content:e}),r(o,t)}e.s(["chatCompletion",()=>r,"generate",()=>i,"generateEmbedding",()=>o,"isHealthy",()=>l,"listModels",()=>n,"streamChat",()=>s],36162)}];

//# sourceMappingURL=src_lib_ai_ollama_ts_4e7a8530._.js.map