import{d as q,i as T,b as H,a as k,f as N,s as V}from"../chunks/DoGIJDSZ.js";import{p as z,s as n,q as J,v as Q,w as W,g as t,b as r,x as _,d as g,c as b,r as c,t as X}from"../chunks/kzeZOqU5.js";import{e as K,I as Z,B as ee,s as te,i as ae,P as I}from"../chunks/aiM7Bbhi.js";import{i as se,N as S}from"../chunks/CnsJhNGt.js";import{P as O}from"../chunks/C87ZRWX0.js";var re=N('<div class="provider-bar svelte-sjabew"></div>'),ie=N("<div> </div>"),oe=N('<div class="page svelte-sjabew"><header class="svelte-sjabew"><h1 class="svelte-sjabew">NeuroLink</h1> <span class="version svelte-sjabew">new NeuroLink()</span> <!></header> <!> <div class="log svelte-sjabew" id="log"></div> <div class="input-bar svelte-sjabew"><!> <!></div></div>');function pe(M,p){z(p,!0);let u=n(null),m=n(null),h=n(J([])),d=n(""),v=n(!1),f=n(!1),o=n("litellm");function i(e,a="info"){r(h,[...t(h),{text:e,type:a}],!0)}function R(){const e=globalThis.process;if(!e?.env)return;const a=e.env;p.data.litellmBaseUrl&&(a.LITELLM_BASE_URL=p.data.litellmBaseUrl),p.data.litellmModel&&(a.LITELLM_MODEL=p.data.litellmModel);const s=window.__aiProviders;s?.["google-ai"]&&(a.GOOGLE_AI_API_KEY="proxy-via-server"),s?.anthropic&&(a.ANTHROPIC_API_KEY="proxy-via-server"),s?.openai&&(a.OPENAI_API_KEY="proxy-via-server"),s?.mistral&&(a.MISTRAL_API_KEY="proxy-via-server")}Q(async()=>{$(),se(),R(),i("Loading NeuroLink from CDN..."),i(S,"dim");try{r(u,await import(S),!0),i(`Loaded! ${Object.keys(t(u)??{}).length} exports`,"pass"),r(m,new(t(u)).NeuroLink({provider:t(o)}),!0),i(`NeuroLink ready · provider: ${t(o)}`,"pass"),r(f,!0)}catch(e){i(`Failed to load: ${e instanceof Error?e.message:String(e)}`,"fail")}});function D(e){!t(u)||e===t(o)||(r(o,e,!0),r(m,new(t(u)).NeuroLink({provider:e}),!0),i(`Switched to provider: ${e}`,"dim"))}function $(){typeof globalThis.process>"u"&&(globalThis.process={cwd:()=>"/",env:{},platform:"browser",version:"v24.0.0"}),typeof globalThis.global>"u"&&(globalThis.global=globalThis)}async function P(){if(!t(d).trim()||!t(m)||t(v))return;const e=t(d).trim();r(d,""),r(v,!0),i(`> ${e}`,"user");const a=O.find(s=>s.id===t(o));if(!a){r(v,!1);return}try{const s=await t(m).generate({input:{text:e},model:a.model,provider:a.id}),l=typeof s.content=="string"?s.content:"(empty response)",E=s.usage;i(l,"ai"),i(`${a.id}/${a.model} | ${E?.total??"?"} tokens`,"dim")}catch(s){i(`Error: ${s instanceof Error?s.message:String(s)}`,"fail")}r(v,!1)}function B(e){e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),P())}var y=oe(),w=b(y),U=g(b(w),4);{var C=e=>{I(e,{text:"Connected",classes:"pill-connected"})},Y=e=>{I(e,{text:"Loading...",classes:"pill-loading"})};T(U,e=>{t(f)?e(C):e(Y,-1)})}c(w);var j=g(w,2);{var F=e=>{var a=re();K(a,21,()=>O,s=>s.id,(s,l)=>{{let E=_(()=>t(o)===t(l).id?"prov-pill--active":"");I(s,{get text(){return t(l).label},get classes(){return`prov-pill ${t(E)??""}`},onclick:()=>{D(t(l).id)}})}}),c(a),k(e,a)};T(j,e=>{t(f)&&e(F)})}var L=g(j,2);K(L,21,()=>t(h),ae,(e,a)=>{var s=ie(),l=b(s,!0);c(s),X(()=>{te(s,1,`log-entry ${t(a).type??""}`,"svelte-sjabew"),V(l,t(a).text)}),k(e,s)}),c(L);var x=g(L,2),A=b(x);{let e=_(()=>t(f)?`Ask anything... [${t(o)}]`:"Loading SDK...");Z(A,{name:"prompt",get placeholder(){return t(e)},classes:"input-prompt",get value(){return t(d)},set value(a){r(d,a,!0)}})}var G=g(A,2);{let e=_(()=>!t(f)||t(v)||!t(d).trim()),a=_(()=>t(v)?"...":"Send");ee(G,{classes:"btn-primary",onclick:P,get disabled(){return t(e)},get text(){return t(a)}})}c(x),c(y),H("keydown",x,B),k(M,y),W()}q(["keydown"]);export{pe as component};
