Skip to content

armgit / ODS

Public Imported from GitHub
0

ODS V3 Pre-Release: Public testing and refinement ahead of the official V3 launch. Turn your PC, Mac, or Linux box into a private AI server.

48.7 KB
Raw Blame
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1220],{19219:(e,t,r)=>{r.d(t,{ChatProvider:()=>g,Y:()=>u});var a=r(95155),s=r(12115),l=r(34015),d=r.n(l),o=r(73321),i=r(66609),n=r(66662),c=r(55570),x=r(76298);let h=async(e,t,r,a)=>{try{let a=localStorage.getItem("chatModelKey"),s=localStorage.getItem("chatModelProviderId"),l=localStorage.getItem("embeddingModelKey"),d=localStorage.getItem("embeddingModelProviderId"),o=await fetch("/api/providers",{headers:{"Content-Type":"application/json"}});if(!o.ok)throw Error(`Provider fetching failed with status code ${o.status}`);let i=(await o.json()).providers;if(0===i.length)throw Error("No chat model providers found, please configure them in the settings page.");let n=i.find(e=>e.id===s)??i.find(e=>e.chatModels.length>0);if(!n)throw Error("No chat models found, pleae configure them in the settings page.");s=n.id,a=(n.chatModels.find(e=>e.key===a)??n.chatModels[0]).key;let c=i.find(e=>e.id===d)??i.find(e=>e.embeddingModels.length>0);if(!c)throw Error("No embedding models found, pleae configure them in the settings page.");d=c.id,l=(c.embeddingModels.find(e=>e.key===l)??c.embeddingModels[0]).key,localStorage.setItem("chatModelKey",a),localStorage.setItem("chatModelProviderId",s),localStorage.setItem("embeddingModelKey",l),localStorage.setItem("embeddingModelProviderId",d),e({key:a,providerId:s}),t({key:l,providerId:d}),r(!0)}catch(e){console.error("An error occurred while checking the configuration:",e),i.o.error(e.message),r(!1),a(!0)}},p=async(e,t,r,a,s,l,d,o)=>{let i=await fetch(`/api/chats/${e}`,{method:"GET",headers:{"Content-Type":"application/json"}});if(404===i.status){l(!0),r(!0);return}let n=await i.json(),c=n.messages;t(c);let x=[];c.forEach(e=>{x.push(["human",e.query]);let t=e.responseBlocks.filter(e=>"text"===e.type).map(e=>e.data).join("\n");t&&x.push(["assistant",t])}),console.debug(new Date,"app:messages_loaded"),c.length>0&&(document.title=c[0].query);let h=n.chat.files.map(e=>({fileName:e.name,fileExtension:e.name.split(".").pop(),fileId:e.fileId}));d(h),o(h.map(e=>e.fileId)),a.current=x,s(n.chat.sources),r(!0)},m=(0,s.createContext)({chatHistory:[],chatId:"",fileIds:[],files:[],sources:[],hasError:!1,isMessagesLoaded:!1,isReady:!1,loading:!1,messageAppeared:!1,messages:[],sections:[],notFound:!1,optimizationMode:"",chatModelProvider:{key:"",providerId:""},embeddingModelProvider:{key:"",providerId:""},researchEnded:!1,rewrite:()=>{},sendMessage:async()=>{},setFileIds:()=>{},setFiles:()=>{},setSources:()=>{},setOptimizationMode:()=>{},setChatModelProvider:()=>{},setEmbeddingModelProvider:()=>{},setResearchEnded:()=>{}}),g=({children:e})=>{let t=(0,o.useParams)(),r=(0,o.useSearchParams)().get("q"),[l,g]=(0,s.useState)(t.chatId),[u,f]=(0,s.useState)(!1),[k,b]=(0,s.useState)(!1),[y,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(!1),N=(0,s.useRef)([]),[S,M]=(0,s.useState)([]),[I,C]=(0,s.useState)([]),[A,E]=(0,s.useState)([]),[P,$]=(0,s.useState)(["web"]),[T,z]=(0,s.useState)("speed"),[F,B]=(0,s.useState)(!1),[O,D]=(0,s.useState)(!1),[q,J]=(0,s.useState)({key:"",providerId:""}),[L,K]=(0,s.useState)({key:"",providerId:""}),[G,R]=(0,s.useState)(!1),[V,_]=(0,s.useState)(!1),[U,H]=(0,s.useState)(!1),W=(0,s.useRef)([]),Y=(0,s.useMemo)(()=>S.map(e=>{let t=[],r="",a=!1,s=[],l=e.responseBlocks.filter(e=>"source"===e.type).flatMap(e=>e.data),d=e.responseBlocks.filter(e=>"widget"===e.type).map(e=>e.data);return e.responseBlocks.forEach(e=>{if("text"===e.type){let s=e.data,d=/\[(\d+)\]/g;if(s.includes("<think>")){let e=s.match(/<think>/g)?.length||0,t=s.match(/<\/think>/g)?.length||0;e&&!t&&(s+="</think> <a> </a>")}e.data.includes("</think>")&&(a=!0),s=l.length>0?s.replace(/\[([^\]]+)\]/g,(e,t)=>t.split(",").map(e=>e.trim()).map(e=>{let t=parseInt(e);if(isNaN(t)||t<=0)return`[${e}]`;let r=l[t-1],a=r?.metadata?.url;return a?`<citation href="${a}">${e}</citation>`:""}).join("")):s.replace(d,""),r+=e.data.replace(d,""),t.push(s)}else"suggestion"===e.type&&(s=e.data)}),{message:e,parsedTextBlocks:t,speechMessage:r,thinkingEnded:a,suggestions:s,widgets:d}}),[S]),Z=(0,s.useRef)(!1),X=(0,s.useRef)(new Set),Q=async()=>{if(!Z.current&&(H(!0),console.debug(new Date,"app:ready"),S.length>0)){let e=S[S.length-1];if("answering"===e.status){b(!0),w(!1),v(!1),Z.current=!0;let t=await fetch(`/api/reconnect/${e.backendId}`,{method:"POST"});if(!t.body)throw Error("No response body");let r=t.body?.getReader(),a=new TextDecoder("utf-8"),s="",l=ee(e);try{for(;;){let{value:e,done:t}=await r.read();if(t)break;s+=a.decode(e,{stream:!0});try{for(let e of s.split("\n")){if(!e.trim())continue;let t=JSON.parse(e);l(t)}s=""}catch(e){console.warn("Incomplete JSON, waiting for next chunk...")}}}finally{Z.current=!1}}}};(0,s.useEffect)(()=>{h(J,K,R,_)},[]),(0,s.useEffect)(()=>{t.chatId&&t.chatId!==l&&(g(t.chatId),M([]),N.current=[],C([]),E([]),B(!1),D(!1),f(!1))},[t.chatId,l]),(0,s.useEffect)(()=>{!l||u||F||0!==S.length?l||(f(!0),B(!0),g(d().randomBytes(20).toString("hex"))):p(l,M,B,N,$,D,C,E)},[l,F,u,S.length]),(0,s.useEffect)(()=>{W.current=S},[S]),(0,s.useEffect)(()=>{F&&G&&u?(H(!0),console.debug(new Date,"app:ready")):F&&G&&!u?Q():H(!1)},[F,G,u]),(0,s.useEffect)(()=>{if(U&&r&&G){if(!G)return void i.o.error("Cannot send message before the configuration is ready");et(r)}},[G,U,r]);let ee=e=>{let t=e.messageId;return async r=>{if("error"===r.type){i.o.error(r.data),b(!1),M(e=>e.map(e=>e.messageId===t?{...e,status:"error"}:e));return}if("researchComplete"===r.type&&(w(!0),e.responseBlocks.find(e=>"source"===e.type&&e.data.length>0)&&v(!0)),"block"===r.type&&(M(e=>e.map(e=>{if(e.messageId===t){let t=e.responseBlocks.findIndex(e=>e.id===r.block.id);if(-1!==t){let a=[...e.responseBlocks];return a[t]=r.block,{...e,responseBlocks:a}}return{...e,responseBlocks:[...e.responseBlocks,r.block]}}return e})),("source"===r.block.type&&r.block.data.length>0||"text"===r.block.type)&&v(!0)),"updateBlock"===r.type&&M(e=>e.map(e=>{if(e.messageId===t){let t=e.responseBlocks.map(e=>{if(e.id===r.blockId){let t={...e};return(0,x.X6)(t,r.patch),t}return e});return{...e,responseBlocks:t}}return e})),"messageEnd"===r.type){if(X.current.has(t))return;X.current.add(t);let r=W.current.find(e=>e.messageId===t),a=[...N.current,["human",e.query],["assistant",r?.responseBlocks.find(e=>"text"===e.type)?.data||""]];N.current=a,M(e=>e.map(e=>e.messageId===t?{...e,status:"completed"}:e)),b(!1);let s=W.current[W.current.length-1];(0,c.o1)()&&setTimeout(()=>{document.getElementById(`search-images-${s.messageId}`)?.click(),document.getElementById(`search-videos-${s.messageId}`)?.click()},200);let l=r?.responseBlocks.some(e=>"source"===e.type&&e.data.length>0),o=r?.responseBlocks.some(e=>"suggestion"===e.type);if(l&&!o){let e=await (0,n.K)(a),r={id:d().randomBytes(7).toString("hex"),type:"suggestion",data:e};M(e=>e.map(e=>e.messageId===t?{...e,responseBlocks:[...e.responseBlocks,r]}:e))}}}},et=async(e,t,r=!1)=>{if(k||!e)return;b(!0),w(!1),v(!1),S.length<=1&&window.history.replaceState(null,"",`/c/${l}`),t=t??d().randomBytes(7).toString("hex");let a=d().randomBytes(20).toString("hex"),s={messageId:t,chatId:l,backendId:a,query:e,responseBlocks:[],status:"answering",createdAt:new Date};M(e=>[...e,s]);let o=S.findIndex(e=>e.messageId===t),i=await fetch("/api/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:e,message:{messageId:t,chatId:l,content:e},chatId:l,files:A,sources:P,optimizationMode:T,history:r?N.current.slice(0,-1===o?void 0:o):N.current,chatModel:{key:q.key,providerId:q.providerId},embeddingModel:{key:L.key,providerId:L.providerId},systemInstructions:localStorage.getItem("systemInstructions")})});if(!i.body)throw Error("No response body");let n=i.body?.getReader(),c=new TextDecoder("utf-8"),x="",h=ee(s);for(;;){let{value:e,done:t}=await n.read();if(t)break;x+=c.decode(e,{stream:!0});try{for(let e of x.split("\n")){if(!e.trim())continue;let t=JSON.parse(e);h(t)}x=""}catch(e){console.warn("Incomplete JSON, waiting for next chunk...")}}};return(0,a.jsx)(m.Provider,{value:{messages:S,sections:Y,chatHistory:N.current,files:I,fileIds:A,sources:P,chatId:l,hasError:V,isMessagesLoaded:F,isReady:U,loading:k,messageAppeared:y,notFound:O,optimizationMode:T,setFileIds:E,setFiles:C,setSources:$,setOptimizationMode:z,rewrite:e=>{let t=S.findIndex(t=>t.messageId===e);if(-1===t)return;M(e=>e.slice(0,t)),N.current=N.current.slice(0,2*t);let r=S[t];et(r.query,r.messageId,!0)},sendMessage:et,setChatModelProvider:J,chatModelProvider:q,embeddingModelProvider:L,setEmbeddingModelProvider:K,researchEnded:j,setResearchEnded:w},children:e})},u=()=>(0,s.useContext)(m)},40980:(e,t,r)=>{r.d(t,{S:()=>d,cn:()=>l});var a=r(29722),s=r(622);let l=(...e)=>(0,s.QP)((0,a.A)(...e)),d=(e,t)=>{e=new Date(e);let r=Math.floor(Math.abs((t=new Date(t)).getTime()-e.getTime())/1e3);return r<60?`${r} second${1!==r?"s":""}`:r<3600?`${Math.floor(r/60)} minute${1!==Math.floor(r/60)?"s":""}`:r<86400?`${Math.floor(r/3600)} hour${1!==Math.floor(r/3600)?"s":""}`:r<31536e3?`${Math.floor(r/86400)} day${1!==Math.floor(r/86400)?"s":""}`:`${Math.floor(r/31536e3)} year${1!==Math.floor(r/31536e3)?"s":""}`}},44999:(e,t,r)=>{r.d(t,{A:()=>i});var a=r(95155),s=r(40980),l=r(6296),d=r(66088);let o=(0,r(12115).forwardRef)(({className:e,options:t,loading:r=!1,disabled:o,...i},n)=>(0,a.jsxs)("div",{className:(0,s.cn)("relative inline-flex w-full items-center",o&&"opacity-60"),children:[(0,a.jsx)("select",{...i,ref:n,disabled:o||r,className:(0,s.cn)("bg-light-secondary dark:bg-dark-secondary px-3 py-2 flex items-center overflow-hidden border border-light-200 dark:border-dark-200 dark:text-white rounded-lg appearance-none w-full pr-10 text-xs lg:text-sm",e),children:t.map(({label:e,value:t,disabled:r})=>(0,a.jsx)("option",{value:t,disabled:r,children:e},t))}),(0,a.jsx)("span",{className:"pointer-events-none absolute right-3 flex h-4 w-4 items-center justify-center text-black/50 dark:text-white/60",children:r?(0,a.jsx)(l.A,{className:"h-4 w-4 animate-spin"}):(0,a.jsx)(d.A,{className:"h-4 w-4"})})]}));o.displayName="Select";let i=o},55570:(e,t,r)=>{r.d(t,{Jp:()=>o,XD:()=>d,o1:()=>s,yF:()=>l});let a=(e,t)=>localStorage.getItem(e)??t??void 0,s=()=>"true"===a("autoMediaSearch","true"),l=()=>"true"===a("showWeatherWidget","true"),d=()=>"true"===a("showNewsWidget","true"),o=()=>{let e=a("measureUnit")??a("measurementUnit","metric");return"string"!=typeof e?"metric":e.toLowerCase()}},66662:(e,t,r)=>{r.d(t,{K:()=>a,Y:()=>s});let a=async e=>{let t=localStorage.getItem("chatModelKey"),r=localStorage.getItem("chatModelProviderId"),a=await fetch("/api/suggestions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chatHistory:e,chatModel:{providerId:r,key:t}})});return(await a.json()).suggestions},s=async()=>{let e=await fetch("https://free.freeipapi.com/api/json",{method:"GET"}),t=await e.json();return{latitude:t.latitude,longitude:t.longitude,city:t.cityName}}},76878:(e,t,r)=>{r.d(t,{A:()=>h});var a=r(95155),s=r(17879),l=r(51914),d=r(6296),o=r(12115),i=r(80642),n=r(84286),c=r(44999),x=r(66609);let h=({modelProviders:e,setProviders:t})=>{let[r,h]=(0,o.useState)(!1),[p,m]=(0,o.useState)(e[0]?.key||null),[g,u]=(0,o.useState)({}),[f,k]=(0,o.useState)(""),[b,y]=(0,o.useState)(!1),v=(0,o.useMemo)(()=>{let t={};return e.forEach(e=>{t[e.key]={name:e.name,fields:e.fields}}),t},[e]),j=(0,o.useMemo)(()=>{if(!p)return[];let e=v[p]?.fields||[],t={};return e.forEach(e=>{t[e.key]=e.default||""}),u(t),e},[p,v]),w=async e=>{e.preventDefault(),y(!0);try{let e=await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:p,name:f,config:g})});if(!e.ok)throw Error("Failed to add provider");let r=(await e.json()).provider;t(e=>[...e,r]),x.o.success("Connection added successfully.")}catch(e){console.error("Error adding provider:",e),x.o.error("Failed to add connection.")}finally{y(!1),h(!1)}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("button",{onClick:()=>h(!0),className:"px-3 md:px-4 py-1.5 md:py-2 rounded-lg text-xs sm:text-xs border border-light-200 dark:border-dark-200 text-black dark:text-white bg-light-secondary/50 dark:bg-dark-secondary/50 hover:bg-light-secondary hover:dark:bg-dark-secondary hover:border-light-300 hover:dark:border-dark-300 flex flex-row items-center space-x-1 active:scale-95 transition duration-200",children:[(0,a.jsx)(l.A,{className:"w-3.5 h-3.5 md:w-4 md:h-4"}),(0,a.jsx)("span",{children:"Add Connection"})]}),(0,a.jsx)(i.N,{children:r&&(0,a.jsx)(s.lG,{static:!0,open:r,onClose:()=>h(!1),className:"relative z-[60]",children:(0,a.jsx)(n.P.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.1},className:"fixed inset-0 flex w-screen items-center justify-center p-4 bg-black/30 backdrop-blur-sm",children:(0,a.jsx)(s.Lj,{className:"w-full mx-4 lg:w-[600px] max-h-[85vh] flex flex-col border bg-light-primary dark:bg-dark-primary border-light-secondary dark:border-dark-secondary rounded-lg",children:(0,a.jsxs)("form",{onSubmit:w,className:"flex flex-col flex-1",children:[(0,a.jsx)("div",{className:"px-6 pt-6 pb-4",children:(0,a.jsx)("h3",{className:"text-black/90 dark:text-white/90 font-medium text-sm",children:"Add new connection"})}),(0,a.jsx)("div",{className:"border-t border-light-200 dark:border-dark-200"}),(0,a.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-4",children:(0,a.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,a.jsxs)("div",{className:"flex flex-col items-start space-y-2",children:[(0,a.jsx)("label",{className:"text-xs text-black/70 dark:text-white/70",children:"Select connection type"}),(0,a.jsx)(c.A,{value:p??"",onChange:e=>m(e.target.value),options:Object.entries(v).map(([e,t])=>({label:t.name,value:e}))})]}),(0,a.jsxs)("div",{className:"flex flex-col items-start space-y-2",children:[(0,a.jsx)("label",{className:"text-xs text-black/70 dark:text-white/70",children:"Connection Name*"}),(0,a.jsx)("input",{value:f,onChange:e=>k(e.target.value),className:"w-full rounded-lg border border-light-200 dark:border-dark-200 bg-light-primary dark:bg-dark-primary px-4 py-3 pr-10 text-sm text-black/80 dark:text-white/80 placeholder:text-black/40 dark:placeholder:text-white/40 focus-visible:outline-none focus-visible:border-light-300 dark:focus-visible:border-dark-300 transition-colors disabled:cursor-not-allowed disabled:opacity-60",placeholder:"e.g., My OpenAI Connection",type:"text",required:!0})]},"name"),j.map(e=>(0,a.jsxs)("div",{className:"flex flex-col items-start space-y-2",children:[(0,a.jsxs)("label",{className:"text-xs text-black/70 dark:text-white/70",children:[e.name,e.required&&"*"]}),(0,a.jsx)("input",{value:g[e.key]??e.default??"",onChange:t=>u(r=>({...r,[e.key]:t.target.value})),className:"w-full rounded-lg border border-light-200 dark:border-dark-200 bg-light-primary dark:bg-dark-primary px-4 py-3 pr-10 text-[13px] text-black/80 dark:text-white/80 placeholder:text-black/40 dark:placeholder:text-white/40 focus-visible:outline-none focus-visible:border-light-300 dark:focus-visible:border-dark-300 transition-colors disabled:cursor-not-allowed disabled:opacity-60",placeholder:e.placeholder,type:"text",required:e.required})]},e.key))]})}),(0,a.jsx)("div",{className:"border-t border-light-200 dark:border-dark-200"}),(0,a.jsx)("div",{className:"px-6 py-4 flex justify-end",children:(0,a.jsx)("button",{type:"submit",disabled:b,className:"px-4 py-2 rounded-lg text-[13px] bg-sky-500 text-white font-medium disabled:opacity-85 hover:opacity-85 active:scale-95 transition duration-200",children:b?(0,a.jsx)(d.A,{className:"animate-spin",size:16}):"Add Connection"})})]})})})})})]})}},81220:(e,t,r)=>{r.d(t,{A:()=>P});var a=r(95155),s=r(17879),l=r(31093),d=r(17577),o=r(80508),i=r(61878),n=r(41641),c=r(22164),x=r(80723),h=r(12115),p=r(44999),m=r(66609),g=r(70460),u=r(6296),f=r(9271);let k=()=>{window.dispatchEvent(new Event("client-config-changed"))},b=({field:e,value:t,setValue:r,dataAdd:s})=>{let[l,d]=(0,h.useState)(!1),{setTheme:o}=(0,g.D)(),i=async t=>{d(!0),r(t);try{if("client"===e.scope)localStorage.setItem(e.key,t),"theme"===e.key&&o(t),k();else{let r=await fetch("/api/config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:`${s}.${e.key}`,value:t})});if(!r.ok)throw console.error("Failed to save config:",await r.text()),Error("Failed to save configuration")}}catch(e){console.error("Error saving config:",e),m.o.error("Failed to save configuration.")}finally{setTimeout(()=>d(!1),150)}};return(0,a.jsx)("section",{className:"rounded-xl border border-light-200 bg-light-primary/80 p-4 lg:p-6 transition-colors dark:border-dark-200 dark:bg-dark-primary/80",children:(0,a.jsxs)("div",{className:"space-y-3 lg:space-y-5",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("h4",{className:"text-sm lg:text-sm text-black dark:text-white",children:e.name}),(0,a.jsx)("p",{className:"text-[11px] lg:text-xs text-black/50 dark:text-white/50",children:e.description})]}),(0,a.jsx)(p.A,{value:t,onChange:e=>i(e.target.value),options:e.options.map(e=>({value:e.value,label:e.name})),className:"!text-xs lg:!text-sm",loading:l,disabled:l})]})})},y=({field:e,value:t,setValue:r,dataAdd:s})=>{let[l,d]=(0,h.useState)(!1),o=async t=>{d(!0),r(t);try{if("client"===e.scope)localStorage.setItem(e.key,t),k();else{let r=await fetch("/api/config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:`${s}.${e.key}`,value:t})});if(!r.ok)throw console.error("Failed to save config:",await r.text()),Error("Failed to save configuration")}}catch(e){console.error("Error saving config:",e),m.o.error("Failed to save configuration.")}finally{setTimeout(()=>d(!1),150)}};return(0,a.jsx)("section",{className:"rounded-xl border border-light-200 bg-light-primary/80 p-4 lg:p-6 transition-colors dark:border-dark-200 dark:bg-dark-primary/80",children:(0,a.jsxs)("div",{className:"space-y-3 lg:space-y-5",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("h4",{className:"text-sm lg:text-sm text-black dark:text-white",children:e.name}),(0,a.jsx)("p",{className:"text-[11px] lg:text-xs text-black/50 dark:text-white/50",children:e.description})]}),(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)("input",{value:t??e.default??"",onChange:e=>r(e.target.value),onBlur:e=>o(e.target.value),className:"w-full rounded-lg border border-light-200 dark:border-dark-200 bg-light-primary dark:bg-dark-primary px-3 py-2 lg:px-4 lg:py-3 pr-10 !text-xs lg:!text-[13px] text-black/80 dark:text-white/80 placeholder:text-black/40 dark:placeholder:text-white/40 focus-visible:outline-none focus-visible:border-light-300 dark:focus-visible:border-dark-300 transition-colors disabled:cursor-not-allowed disabled:opacity-60",placeholder:e.placeholder,type:"text",disabled:l}),l&&(0,a.jsx)("span",{className:"pointer-events-none absolute right-3 top-1/2 -translate-y-1/2 text-black/40 dark:text-white/40",children:(0,a.jsx)(u.A,{className:"h-4 w-4 animate-spin"})})]})]})})},v=({field:e,value:t,setValue:r,dataAdd:s})=>{let[l,d]=(0,h.useState)(!1),o=async t=>{d(!0),r(t);try{if("client"===e.scope)localStorage.setItem(e.key,t),k();else{let r=await fetch("/api/config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:`${s}.${e.key}`,value:t})});if(!r.ok)throw console.error("Failed to save config:",await r.text()),Error("Failed to save configuration")}}catch(e){console.error("Error saving config:",e),m.o.error("Failed to save configuration.")}finally{setTimeout(()=>d(!1),150)}};return(0,a.jsx)("section",{className:"rounded-xl border border-light-200 bg-light-primary/80 p-4 lg:p-6 transition-colors dark:border-dark-200 dark:bg-dark-primary/80",children:(0,a.jsxs)("div",{className:"space-y-3 lg:space-y-5",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("h4",{className:"text-sm lg:text-sm text-black dark:text-white",children:e.name}),(0,a.jsx)("p",{className:"text-[11px] lg:text-xs text-black/50 dark:text-white/50",children:e.description})]}),(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsx)("textarea",{value:t??e.default??"",onChange:e=>r(e.target.value),onBlur:e=>o(e.target.value),className:"w-full rounded-lg border border-light-200 dark:border-dark-200 bg-light-primary dark:bg-dark-primary px-3 py-2 lg:px-4 lg:py-3 pr-10 !text-xs lg:!text-[13px] text-black/80 dark:text-white/80 placeholder:text-black/40 dark:placeholder:text-white/40 focus-visible:outline-none focus-visible:border-light-300 dark:focus-visible:border-dark-300 transition-colors disabled:cursor-not-allowed disabled:opacity-60",placeholder:e.placeholder,rows:4,disabled:l}),l&&(0,a.jsx)("span",{className:"pointer-events-none absolute right-3 translate-y-3 text-black/40 dark:text-white/40",children:(0,a.jsx)(u.A,{className:"h-4 w-4 animate-spin"})})]})]})})},j=({field:e,value:t,setValue:r,dataAdd:s})=>{let[l,d]=(0,h.useState)(!1),o=async t=>{d(!0),r(t);try{if("client"===e.scope)localStorage.setItem(e.key,String(t)),k();else{let r=await fetch("/api/config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:`${s}.${e.key}`,value:t})});if(!r.ok)throw console.error("Failed to save config:",await r.text()),Error("Failed to save configuration")}}catch(e){console.error("Error saving config:",e),m.o.error("Failed to save configuration.")}finally{setTimeout(()=>d(!1),150)}};return(0,a.jsx)("section",{className:"rounded-xl border border-light-200 bg-light-primary/80 p-4 lg:p-6 transition-colors dark:border-dark-200 dark:bg-dark-primary/80",children:(0,a.jsxs)("div",{className:"flex flex-row items-center space-x-3 lg:space-x-5 w-full justify-between",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("h4",{className:"text-sm lg:text-sm text-black dark:text-white",children:e.name}),(0,a.jsx)("p",{className:"text-[11px] lg:text-xs text-black/50 dark:text-white/50",children:e.description})]}),(0,a.jsx)(f.dO,{checked:!0===t||"true"===t,onChange:o,disabled:l,className:"group relative flex h-6 w-12 shrink-0 cursor-pointer rounded-full bg-light-200 dark:bg-white/10 p-1 duration-200 ease-in-out focus:outline-none transition-colors disabled:opacity-60 disabled:cursor-not-allowed data-[checked]:bg-sky-500 dark:data-[checked]:bg-sky-500",children:(0,a.jsx)("span",{"aria-hidden":"true",className:"pointer-events-none inline-block size-4 translate-x-0 rounded-full bg-white shadow-lg ring-0 transition duration-200 ease-in-out group-data-[checked]:translate-x-6"})})]})})},w=({field:e,value:t,dataAdd:r})=>{let[s,l]=(0,h.useState)(t);switch(e.type){case"select":return(0,a.jsx)(b,{field:e,value:s,setValue:l,dataAdd:r});case"string":return(0,a.jsx)(y,{field:e,value:s,setValue:l,dataAdd:r});case"textarea":return(0,a.jsx)(v,{field:e,value:s,setValue:l,dataAdd:r});case"switch":return(0,a.jsx)(j,{field:e,value:s,setValue:l,dataAdd:r});default:return(0,a.jsxs)("div",{children:["Unsupported field type: ",e.type]})}};var N=r(84286),S=r(98394),M=r(40980),I=r(76878),C=r(97904),A=r(92671);let E=[{key:"preferences",name:"Preferences",description:"Customize your application preferences.",icon:l.A,component:({fields:e,values:t})=>(0,a.jsx)("div",{className:"flex-1 space-y-6 overflow-y-auto px-6 py-6",children:e.map(e=>(0,a.jsx)(w,{field:e,value:("client"===e.scope?localStorage.getItem(e.key):t[e.key])??e.default,dataAdd:"preferences"},e.key))}),dataAdd:"preferences"},{key:"personalization",name:"Personalization",description:"Customize the behavior and tone of the model.",icon:d.A,component:({fields:e,values:t})=>(0,a.jsx)("div",{className:"flex-1 space-y-6 overflow-y-auto px-6 py-6",children:e.map(e=>(0,a.jsx)(w,{field:e,value:("client"===e.scope?localStorage.getItem(e.key):t[e.key])??e.default,dataAdd:"personalization"},e.key))}),dataAdd:"personalization"},{key:"models",name:"Models",description:"Connect to AI services and manage connections.",icon:o.A,component:({fields:e,values:t})=>{let[r,s]=(0,h.useState)(t);return(0,a.jsxs)("div",{className:"flex-1 space-y-6 overflow-y-auto py-6",children:[(0,a.jsxs)("div",{className:"flex flex-col px-6 gap-y-4",children:[(0,a.jsx)("h3",{className:"text-xs lg:text-xs text-black/70 dark:text-white/70",children:"Select models"}),(0,a.jsx)(A.A,{providers:t.filter(e=>e.chatModels.some(e=>"error"!=e.key)),type:"chat"}),(0,a.jsx)(A.A,{providers:t.filter(e=>e.embeddingModels.some(e=>"error"!=e.key)),type:"embedding"})]}),(0,a.jsx)("div",{className:"border-t border-light-200 dark:border-dark-200"}),(0,a.jsxs)("div",{className:"flex flex-row justify-between items-center px-6 ",children:[(0,a.jsx)("p",{className:"text-xs lg:text-xs text-black/70 dark:text-white/70",children:"Manage connections"}),(0,a.jsx)(I.A,{modelProviders:e,setProviders:s})]}),(0,a.jsx)("div",{className:"flex flex-col px-6 gap-y-4",children:0===r.length?(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 px-4 rounded-lg border-2 border-dashed border-light-200 dark:border-dark-200 bg-light-secondary/10 dark:bg-dark-secondary/10",children:[(0,a.jsx)("div",{className:"p-3 rounded-full bg-sky-500/10 dark:bg-sky-500/10 mb-3",children:(0,a.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"w-8 h-8 text-sky-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})})}),(0,a.jsx)("p",{className:"text-sm font-medium text-black/70 dark:text-white/70 mb-1",children:"No connections yet"}),(0,a.jsx)("p",{className:"text-xs text-black/50 dark:text-white/50 text-center max-w-sm mb-4",children:"Add your first connection to start using AI models. Connect to OpenAI, Anthropic, Ollama, and more."})]}):r.map(t=>(0,a.jsx)(C.A,{fields:e.find(e=>e.key===t.type)?.fields??[],modelProvider:t,setProviders:s},`provider-${t.id}`))})]})},dataAdd:"modelProviders"},{key:"search",name:"Search",description:"Manage search settings.",icon:i.A,component:({fields:e,values:t})=>(0,a.jsx)("div",{className:"flex-1 space-y-6 overflow-y-auto px-6 py-6",children:e.map(e=>(0,a.jsx)(w,{field:e,value:("client"===e.scope?localStorage.getItem(e.key):t[e.key])??e.default,dataAdd:"search"},e.key))}),dataAdd:"search"}],P=({isOpen:e,setIsOpen:t})=>{let[r,l]=(0,h.useState)(!0),[d,o]=(0,h.useState)(null),[i,g]=(0,h.useState)(E[0].key),[u,f]=(0,h.useState)(E[0]);return(0,h.useEffect)(()=>{f(E.find(e=>e.key===i))},[i]),(0,h.useEffect)(()=>{e&&(async()=>{try{let e=await fetch("/api/config",{method:"GET",headers:{"Content-Type":"application/json"}}),t=await e.json();o(t)}catch(e){console.error("Error fetching config:",e),m.o.error("Failed to load configuration.")}finally{l(!1)}})()},[e]),(0,a.jsx)(s.lG,{open:e,onClose:()=>t(!1),className:"relative z-50",children:(0,a.jsx)(N.P.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.1},className:"fixed inset-0 flex w-screen items-center justify-center p-4 bg-black/30 backdrop-blur-sm h-screen",children:(0,a.jsx)(s.Lj,{className:"space-y-4 border border-light-200 dark:border-dark-200 bg-light-primary dark:bg-dark-primary backdrop-blur-lg rounded-xl h-[calc(100vh-2%)] w-[calc(100vw-2%)] md:h-[calc(100vh-7%)] md:w-[calc(100vw-7%)] lg:h-[calc(100vh-20%)] lg:w-[calc(100vw-30%)] overflow-hidden flex flex-col",children:r?(0,a.jsx)("div",{className:"flex items-center justify-center h-full w-full",children:(0,a.jsx)(S.A,{})}):(0,a.jsxs)("div",{className:"flex flex-1 inset-0 h-full overflow-hidden",children:[(0,a.jsxs)("div",{className:"hidden lg:flex flex-col justify-between w-[240px] border-r border-white-200 dark:border-dark-200 h-full px-3 pt-3 overflow-y-auto",children:[(0,a.jsxs)("div",{className:"flex flex-col",children:[(0,a.jsxs)("button",{onClick:()=>t(!1),className:"group flex flex-row items-center hover:bg-light-200 hover:dark:bg-dark-200 p-2 rounded-lg",children:[(0,a.jsx)(n.A,{size:18,className:"text-black/50 dark:text-white/50 group-hover:text-black/70 group-hover:dark:text-white/70"}),(0,a.jsx)("p",{className:"text-black/50 dark:text-white/50 group-hover:text-black/70 group-hover:dark:text-white/70 text-[14px]",children:"Back"})]}),(0,a.jsx)("div",{className:"flex flex-col items-start space-y-1 mt-8",children:E.map(e=>(0,a.jsxs)("button",{className:(0,M.cn)("flex flex-row items-center space-x-2 px-2 py-1.5 rounded-lg w-full text-sm hover:bg-light-200 hover:dark:bg-dark-200 transition duration-200 active:scale-95",i===e.key?"bg-light-200 dark:bg-dark-200 text-black/90 dark:text-white/90":" text-black/70 dark:text-white/70"),onClick:()=>g(e.key),children:[(0,a.jsx)(e.icon,{size:17}),(0,a.jsx)("p",{children:e.name})]},e.dataAdd))})]}),(0,a.jsxs)("div",{className:"flex flex-col space-y-1 py-[18px] px-2",children:[(0,a.jsxs)("p",{className:"text-xs text-black/70 dark:text-white/70",children:["Version: ","1.12.2"]}),(0,a.jsxs)("a",{href:"https://github.com/itzcrazykns/vane",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-black/70 dark:text-white/70 flex flex-row space-x-1 items-center transition duration-200 hover:text-black/90 hover:dark:text-white/90",children:[(0,a.jsx)("span",{children:"GitHub"}),(0,a.jsx)(c.A,{size:12})]})]})]}),(0,a.jsxs)("div",{className:"w-full flex flex-col overflow-hidden",children:[(0,a.jsxs)("div",{className:"flex flex-row lg:hidden w-full justify-between px-[20px] my-4 flex-shrink-0",children:[(0,a.jsx)("button",{onClick:()=>t(!1),className:"group flex flex-row items-center hover:bg-light-200 hover:dark:bg-dark-200 rounded-lg mr-[40%]",children:(0,a.jsx)(x.A,{size:18,className:"text-black/50 dark:text-white/50 group-hover:text-black/70 group-hover:dark:text-white/70"})}),(0,a.jsx)(p.A,{options:E.map(e=>({value:e.key,key:e.key,label:e.name})),value:i,onChange:e=>{g(e.target.value)},className:"!text-xs lg:!text-sm"})]}),u.component&&(0,a.jsxs)("div",{className:"flex flex-1 flex-col overflow-hidden",children:[(0,a.jsx)("div",{className:"border-b border-light-200/60 px-6 pb-6 lg:pt-6 dark:border-dark-200/60 flex-shrink-0",children:(0,a.jsxs)("div",{className:"flex flex-col",children:[(0,a.jsx)("h4",{className:"font-medium text-black dark:text-white text-sm lg:text-sm",children:u.name}),(0,a.jsx)("p",{className:"text-[11px] lg:text-xs text-black/50 dark:text-white/50",children:u.description})]})}),(0,a.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,a.jsx)(u.component,{fields:d.fields[u.dataAdd],values:d.values[u.dataAdd]})})]})]})]})})})})}},92671:(e,t,r)=>{r.d(t,{A:()=>i});var a=r(95155),s=r(44999),l=r(19219),d=r(12115),o=r(66609);let i=({providers:e,type:t})=>{let[r,i]=(0,d.useState)("chat"===t?`${localStorage.getItem("chatModelProviderId")}/${localStorage.getItem("chatModelKey")}`:`${localStorage.getItem("embeddingModelProviderId")}/${localStorage.getItem("embeddingModelKey")}`),[n,c]=(0,d.useState)(!1),{setChatModelProvider:x,setEmbeddingModelProvider:h}=(0,l.Y)(),p=async e=>{c(!0),i(e);try{if("chat"===t){let t=e.split("/")[0],r=e.split("/").slice(1).join("/");localStorage.setItem("chatModelProviderId",t),localStorage.setItem("chatModelKey",r),x({providerId:t,key:r})}else{let t=e.split("/")[0],r=e.split("/").slice(1).join("/");localStorage.setItem("embeddingModelProviderId",t),localStorage.setItem("embeddingModelKey",r),h({providerId:t,key:r})}}catch(e){console.error("Error saving config:",e),o.o.error("Failed to save configuration.")}finally{c(!1)}};return(0,a.jsx)("section",{className:"rounded-xl border border-light-200 bg-light-primary/80 p-4 lg:p-6 transition-colors dark:border-dark-200 dark:bg-dark-primary/80",children:(0,a.jsxs)("div",{className:"space-y-3 lg:space-y-5",children:[(0,a.jsxs)("div",{children:[(0,a.jsxs)("h4",{className:"text-sm lg:text-sm text-black dark:text-white",children:["Select ","chat"===t?"Chat Model":"Embedding Model"]}),(0,a.jsx)("p",{className:"text-[11px] lg:text-xs text-black/50 dark:text-white/50",children:"chat"===t?"Choose which model to use for generating responses":"Choose which model to use for generating embeddings"})]}),(0,a.jsx)(s.A,{value:r,onChange:e=>p(e.target.value),options:"chat"===t?e.flatMap(e=>e.chatModels.map(t=>({value:`${e.id}/${t.key}`,label:`${e.name} - ${t.name}`}))):e.flatMap(e=>e.embeddingModels.map(t=>({value:`${e.id}/${t.key}`,label:`${e.name} - ${t.name}`}))),className:"!text-xs lg:!text-[13px]",loading:n,disabled:n})]})})}},97904:(e,t,r)=>{r.d(t,{A:()=>b});var a=r(95155),s=r(37061),l=r(13545),d=r(33210),o=r(12115),i=r(66609),n=r(17879),c=r(51914),x=r(6296),h=r(80642),p=r(84286);let m=({providerId:e,setProviders:t,type:r})=>{let[s,l]=(0,o.useState)(!1),[d,m]=(0,o.useState)(""),[g,u]=(0,o.useState)(""),[f,k]=(0,o.useState)(!1),b=async a=>{a.preventDefault(),k(!0);try{if(!(await fetch(`/api/providers/${e}/models`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:d,key:g,type:r})})).ok)throw Error("Failed to add model");t(t=>t.map(t=>{if(t.id===e){let e={name:d,key:g};return{...t,chatModels:"chat"===r?[...t.chatModels,e]:t.chatModels,embeddingModels:"embedding"===r?[...t.embeddingModels,e]:t.embeddingModels}}return t})),i.o.success("Model added successfully."),m(""),u(""),l(!1)}catch(e){console.error("Error adding model:",e),i.o.error("Failed to add model.")}finally{k(!1)}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("button",{onClick:()=>l(!0),className:"text-xs text-black/70 dark:text-white/70 hover:text-black hover:dark:text-white flex flex-row items-center space-x-1 active:scale-95 transition duration-200",children:[(0,a.jsx)(c.A,{size:12}),(0,a.jsx)("span",{children:"Add"})]}),(0,a.jsx)(h.N,{children:s&&(0,a.jsx)(n.lG,{static:!0,open:s,onClose:()=>l(!1),className:"relative z-[60]",children:(0,a.jsx)(p.P.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.1},className:"fixed inset-0 flex w-screen items-center justify-center p-4 bg-black/30 backdrop-blur-sm",children:(0,a.jsxs)(n.Lj,{className:"w-full mx-4 lg:w-[600px] max-h-[85vh] flex flex-col border bg-light-primary dark:bg-dark-primary border-light-secondary dark:border-dark-secondary rounded-lg",children:[(0,a.jsx)("div",{className:"px-6 pt-6 pb-4",children:(0,a.jsxs)("h3",{className:"text-black/90 dark:text-white/90 font-medium text-sm",children:["Add new ","chat"===r?"chat":"embedding"," model"]})}),(0,a.jsx)("div",{className:"border-t border-light-200 dark:border-dark-200"}),(0,a.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-4",children:(0,a.jsxs)("form",{onSubmit:b,className:"flex flex-col h-full",children:[(0,a.jsxs)("div",{className:"flex flex-col space-y-4 flex-1",children:[(0,a.jsxs)("div",{className:"flex flex-col items-start space-y-2",children:[(0,a.jsx)("label",{className:"text-xs text-black/70 dark:text-white/70",children:"Model name*"}),(0,a.jsx)("input",{value:d,onChange:e=>m(e.target.value),className:"w-full rounded-lg border border-light-200 dark:border-dark-200 bg-light-primary dark:bg-dark-primary px-4 py-3 text-[13px] text-black/80 dark:text-white/80 placeholder:text-black/40 dark:placeholder:text-white/40 focus-visible:outline-none focus-visible:border-light-300 dark:focus-visible:border-dark-300 transition-colors disabled:cursor-not-allowed disabled:opacity-60",placeholder:"e.g., GPT-4",type:"text",required:!0})]}),(0,a.jsxs)("div",{className:"flex flex-col items-start space-y-2",children:[(0,a.jsx)("label",{className:"text-xs text-black/70 dark:text-white/70",children:"Model key*"}),(0,a.jsx)("input",{value:g,onChange:e=>u(e.target.value),className:"w-full rounded-lg border border-light-200 dark:border-dark-200 bg-light-primary dark:bg-dark-primary px-4 py-3 text-[13px] text-black/80 dark:text-white/80 placeholder:text-black/40 dark:placeholder:text-white/40 focus-visible:outline-none focus-visible:border-light-300 dark:focus-visible:border-dark-300 transition-colors disabled:cursor-not-allowed disabled:opacity-60",placeholder:"e.g., gpt-4",type:"text",required:!0})]})]}),(0,a.jsx)("div",{className:"border-t border-light-200 dark:border-dark-200 -mx-6 my-4"}),(0,a.jsx)("div",{className:"flex justify-end",children:(0,a.jsx)("button",{type:"submit",disabled:f,className:"px-4 py-2 rounded-lg text-[13px] bg-sky-500 text-white font-medium disabled:opacity-85 hover:opacity-85 active:scale-95 transition duration-200",children:f?(0,a.jsx)(x.A,{className:"animate-spin",size:16}):"Add Model"})})]})})]})})})})]})};var g=r(49387);let u=({modelProvider:e,fields:t,setProviders:r})=>{let[s,l]=(0,o.useState)(!1),[d,c]=(0,o.useState)({}),[m,u]=(0,o.useState)(e.name),[f,k]=(0,o.useState)(!1);(0,o.useEffect)(()=>{let r={name:e.name};t.forEach(t=>{r[t.key]=e.config[t.key]||t.default||""}),c(r)},[t]);let b=async t=>{t.preventDefault(),k(!0);try{let t=await fetch(`/api/providers/${e.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:m,config:d})});if(!t.ok)throw Error("Failed to update provider");let a=(await t.json()).provider;r(t=>t.map(t=>t.id===e.id?a:t)),i.o.success("Connection updated successfully.")}catch(e){console.error("Error updating provider:",e),i.o.error("Failed to update connection.")}finally{k(!1),l(!1)}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{onClick:e=>{e.stopPropagation(),l(!0)},className:"group p-1.5 rounded-md hover:bg-light-200 hover:dark:bg-dark-200 transition-colors group",children:(0,a.jsx)(g.A,{size:14,className:"text-black/60 dark:text-white/60 group-hover:text-black group-hover:dark:text-white"})}),(0,a.jsx)(h.N,{children:s&&(0,a.jsx)(n.lG,{static:!0,open:s,onClose:()=>l(!1),className:"relative z-[60]",children:(0,a.jsx)(p.P.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.1},className:"fixed inset-0 flex w-screen items-center justify-center p-4 bg-black/30 backdrop-blur-sm",children:(0,a.jsx)(n.Lj,{className:"w-full mx-4 lg:w-[600px] max-h-[85vh] flex flex-col border bg-light-primary dark:bg-dark-primary border-light-secondary dark:border-dark-secondary rounded-lg",children:(0,a.jsxs)("form",{onSubmit:b,className:"flex flex-col flex-1",children:[(0,a.jsx)("div",{className:"px-6 pt-6 pb-4",children:(0,a.jsx)("h3",{className:"text-black/90 dark:text-white/90 font-medium text-sm",children:"Update connection"})}),(0,a.jsx)("div",{className:"border-t border-light-200 dark:border-dark-200"}),(0,a.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-4",children:(0,a.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,a.jsxs)("div",{className:"flex flex-col items-start space-y-2",children:[(0,a.jsx)("label",{className:"text-xs text-black/70 dark:text-white/70",children:"Connection Name*"}),(0,a.jsx)("input",{value:m,onChange:e=>u(e.target.value),className:"w-full rounded-lg border border-light-200 dark:border-dark-200 bg-light-primary dark:bg-dark-primary px-4 py-3 pr-10 text-sm text-black/80 dark:text-white/80 placeholder:text-black/40 dark:placeholder:text-white/40 focus-visible:outline-none focus-visible:border-light-300 dark:focus-visible:border-dark-300 transition-colors disabled:cursor-not-allowed disabled:opacity-60",placeholder:"Connection Name",type:"text",required:!0})]},"name"),t.map(e=>(0,a.jsxs)("div",{className:"flex flex-col items-start space-y-2",children:[(0,a.jsxs)("label",{className:"text-xs text-black/70 dark:text-white/70",children:[e.name,e.required&&"*"]}),(0,a.jsx)("input",{value:d[e.key]??e.default??"",onChange:t=>c(r=>({...r,[e.key]:t.target.value})),className:"w-full rounded-lg border border-light-200 dark:border-dark-200 bg-light-primary dark:bg-dark-primary px-4 py-3 pr-10 text-[13px] text-black/80 dark:text-white/80 placeholder:text-black/40 dark:placeholder:text-white/40 focus-visible:outline-none focus-visible:border-light-300 dark:focus-visible:border-dark-300 transition-colors disabled:cursor-not-allowed disabled:opacity-60",placeholder:e.placeholder,type:"text",required:e.required})]},e.key))]})}),(0,a.jsx)("div",{className:"border-t border-light-200 dark:border-dark-200"}),(0,a.jsx)("div",{className:"px-6 py-4 flex justify-end",children:(0,a.jsx)("button",{type:"submit",disabled:f,className:"px-4 py-2 rounded-lg text-[13px] bg-sky-500 text-white font-medium disabled:opacity-85 hover:opacity-85 active:scale-95 transition duration-200",children:f?(0,a.jsx)(x.A,{className:"animate-spin",size:16}):"Update Connection"})})]})})})})})]})};var f=r(68459);let k=({modelProvider:e,setProviders:t})=>{let[r,s]=(0,o.useState)(!1),[l,d]=(0,o.useState)(!1),c=async r=>{r.preventDefault(),d(!0);try{if(!(await fetch(`/api/providers/${e.id}`,{method:"DELETE",headers:{"Content-Type":"application/json"}})).ok)throw Error("Failed to delete provider");t(t=>t.filter(t=>t.id!==e.id)),i.o.success("Connection deleted successfully.")}catch(e){console.error("Error deleting provider:",e),i.o.error("Failed to delete connection.")}finally{d(!1)}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{onClick:e=>{e.stopPropagation(),s(!0)},className:"group p-1.5 rounded-md hover:bg-light-200 hover:dark:bg-dark-200 transition-colors group",title:"Delete connection",children:(0,a.jsx)(f.A,{size:14,className:"text-black/60 dark:text-white/60 group-hover:text-red-500 group-hover:dark:text-red-400"})}),(0,a.jsx)(h.N,{children:r&&(0,a.jsx)(n.lG,{static:!0,open:r,onClose:()=>s(!1),className:"relative z-[60]",children:(0,a.jsx)(p.P.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.1},className:"fixed inset-0 flex w-screen items-center justify-center p-4 bg-black/30 backdrop-blur-sm",children:(0,a.jsxs)(n.Lj,{className:"w-full mx-4 lg:w-[600px] max-h-[85vh] flex flex-col border bg-light-primary dark:bg-dark-primary border-light-secondary dark:border-dark-secondary rounded-lg",children:[(0,a.jsx)("div",{className:"px-6 pt-6 pb-4",children:(0,a.jsx)("h3",{className:"text-black/90 dark:text-white/90 font-medium",children:"Delete connection"})}),(0,a.jsx)("div",{className:"border-t border-light-200 dark:border-dark-200"}),(0,a.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-4",children:(0,a.jsxs)("p",{className:"text-sm text-black/60 dark:text-white/60",children:['Are you sure you want to delete the connection "',e.name,'"? This action cannot be undone. All associated models will also be removed.']})}),(0,a.jsxs)("div",{className:"px-6 py-6 flex justify-end space-x-2",children:[(0,a.jsx)("button",{disabled:l,onClick:()=>s(!1),className:"px-4 py-2 rounded-lg text-sm border border-light-200 dark:border-dark-200 text-black dark:text-white bg-light-secondary/50 dark:bg-dark-secondary/50 hover:bg-light-secondary hover:dark:bg-dark-secondary hover:border-light-300 hover:dark:border-dark-300 flex flex-row items-center space-x-1 active:scale-95 transition duration-200",children:"Cancel"}),(0,a.jsx)("button",{disabled:l,onClick:c,className:"px-4 py-2 rounded-lg text-sm bg-red-500 text-white font-medium disabled:opacity-85 hover:opacity-85 active:scale-95 transition duration-200",children:l?(0,a.jsx)(x.A,{className:"animate-spin",size:16}):"Delete"})]})]})})})})]})},b=({modelProvider:e,setProviders:t,fields:r})=>{let[n,c]=(0,o.useState)(!0),x=async(r,a)=>{try{let s=await fetch(`/api/providers/${e.id}/models`,{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:a,type:r})});if(!s.ok)throw Error("Failed to delete model: "+await s.text());t(t=>t.map(t=>t.id===e.id?{...t,..."chat"===r?{chatModels:t.chatModels.filter(e=>e.key!==a)}:{embeddingModels:t.embeddingModels.filter(e=>e.key!==a)}}:t)),i.o.success("Model deleted successfully.")}catch(e){console.error("Failed to delete model",e),i.o.error("Failed to delete model.")}},h=e.chatModels.filter(e=>"error"!==e.key).length+e.embeddingModels.filter(e=>"error"!==e.key).length,p=e.chatModels.some(e=>"error"===e.key)||e.embeddingModels.some(e=>"error"===e.key);return(0,a.jsxs)("div",{className:"border border-light-200 dark:border-dark-200 rounded-lg overflow-hidden bg-light-primary dark:bg-dark-primary",children:[(0,a.jsxs)("div",{className:"px-5 py-3.5 flex flex-row justify-between w-full items-center border-b border-light-200 dark:border-dark-200 bg-light-secondary/30 dark:bg-dark-secondary/30",children:[(0,a.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,a.jsx)("div",{className:"p-1.5 rounded-md bg-sky-500/10 dark:bg-sky-500/10",children:(0,a.jsx)(s.A,{size:14,className:"text-sky-500"})}),(0,a.jsxs)("div",{className:"flex flex-col",children:[(0,a.jsx)("p",{className:"text-sm lg:text-sm text-black dark:text-white font-medium",children:e.name}),h>0&&(0,a.jsxs)("p",{className:"text-[10px] lg:text-[11px] text-black/50 dark:text-white/50",children:[h," model",1!==h?"s":""," configured"]})]})]}),(0,a.jsxs)("div",{className:"flex flex-row items-center gap-1",children:[(0,a.jsx)(u,{fields:r,modelProvider:e,setProviders:t}),(0,a.jsx)(k,{modelProvider:e,setProviders:t})]})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-y-4 px-5 py-4",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-y-2",children:[(0,a.jsxs)("div",{className:"flex flex-row w-full justify-between items-center",children:[(0,a.jsx)("p",{className:"text-[11px] lg:text-[11px] font-medium text-black/70 dark:text-white/70 uppercase tracking-wide",children:"Chat Models"}),!e.chatModels.some(e=>"error"===e.key)&&(0,a.jsx)(m,{providerId:e.id,setProviders:t,type:"chat"})]}),(0,a.jsx)("div",{className:"flex flex-col gap-2",children:e.chatModels.some(e=>"error"===e.key)?(0,a.jsxs)("div",{className:"flex flex-row items-center gap-2 text-xs lg:text-xs text-red-500 dark:text-red-400 rounded-lg bg-red-50 dark:bg-red-950/20 px-3 py-2 border border-red-200 dark:border-red-900/30",children:[(0,a.jsx)(l.A,{size:16,className:"shrink-0"}),(0,a.jsx)("span",{className:"break-words",children:e.chatModels.find(e=>"error"===e.key)?.name})]}):0!==e.chatModels.filter(e=>"error"!==e.key).length||p?e.chatModels.filter(e=>"error"!==e.key).length>0?(0,a.jsx)("div",{className:"flex flex-row flex-wrap gap-2",children:e.chatModels.map((t,r)=>(0,a.jsxs)("div",{className:"flex flex-row items-center space-x-1.5 text-xs lg:text-xs text-black/70 dark:text-white/70 rounded-lg bg-light-secondary dark:bg-dark-secondary px-3 py-1.5 border border-light-200 dark:border-dark-200",children:[(0,a.jsx)("span",{children:t.name}),(0,a.jsx)("button",{onClick:()=>{x("chat",t.key)},className:"hover:text-red-500 dark:hover:text-red-400 transition-colors",children:(0,a.jsx)(d.A,{size:12})})]},`${e.id}-chat-${t.key}-${r}`))}):null:(0,a.jsx)("div",{className:"flex flex-col items-center justify-center py-4 px-4 rounded-lg border-2 border-dashed border-light-200 dark:border-dark-200 bg-light-secondary/20 dark:bg-dark-secondary/20",children:(0,a.jsx)("p",{className:"text-xs text-black/50 dark:text-white/50 text-center",children:"No chat models configured"})})})]}),(0,a.jsxs)("div",{className:"flex flex-col gap-y-2",children:[(0,a.jsxs)("div",{className:"flex flex-row w-full justify-between items-center",children:[(0,a.jsx)("p",{className:"text-[11px] lg:text-[11px] font-medium text-black/70 dark:text-white/70 uppercase tracking-wide",children:"Embedding Models"}),!e.embeddingModels.some(e=>"error"===e.key)&&(0,a.jsx)(m,{providerId:e.id,setProviders:t,type:"embedding"})]}),(0,a.jsx)("div",{className:"flex flex-col gap-2",children:e.embeddingModels.some(e=>"error"===e.key)?(0,a.jsxs)("div",{className:"flex flex-row items-center gap-2 text-xs lg:text-xs text-red-500 dark:text-red-400 rounded-lg bg-red-50 dark:bg-red-950/20 px-3 py-2 border border-red-200 dark:border-red-900/30",children:[(0,a.jsx)(l.A,{size:16,className:"shrink-0"}),(0,a.jsx)("span",{className:"break-words",children:e.embeddingModels.find(e=>"error"===e.key)?.name})]}):0!==e.embeddingModels.filter(e=>"error"!==e.key).length||p?e.embeddingModels.filter(e=>"error"!==e.key).length>0?(0,a.jsx)("div",{className:"flex flex-row flex-wrap gap-2",children:e.embeddingModels.map((t,r)=>(0,a.jsxs)("div",{className:"flex flex-row items-center space-x-1.5 text-xs lg:text-xs text-black/70 dark:text-white/70 rounded-lg bg-light-secondary dark:bg-dark-secondary px-3 py-1.5 border border-light-200 dark:border-dark-200",children:[(0,a.jsx)("span",{children:t.name}),(0,a.jsx)("button",{onClick:()=>{x("embedding",t.key)},className:"hover:text-red-500 dark:hover:text-red-400 transition-colors",children:(0,a.jsx)(d.A,{size:12})})]},`${e.id}-embedding-${t.key}-${r}`))}):null:(0,a.jsx)("div",{className:"flex flex-col items-center justify-center py-4 px-4 rounded-lg border-2 border-dashed border-light-200 dark:border-dark-200 bg-light-secondary/20 dark:bg-dark-secondary/20",children:(0,a.jsx)("p",{className:"text-xs text-black/50 dark:text-white/50 text-center",children:"No embedding models configured"})})})]})]})]},e.id)}},98394:(e,t,r)=>{r.d(t,{A:()=>s});var a=r(95155);let s=()=>(0,a.jsxs)("svg",{"aria-hidden":"true",className:"w-8 h-8 text-light-200 fill-light-secondary dark:text-[#202020] animate-spin dark:fill-[#ffffff3b]",viewBox:"0 0 100 101",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,a.jsx)("path",{d:"M100 50.5908C100.003 78.2051 78.1951 100.003 50.5908 100C22.9765 99.9972 0.997224 78.018 1 50.4037C1.00281 22.7993 22.8108 0.997224 50.4251 1C78.0395 1.00281 100.018 22.8108 100 50.4251ZM9.08164 50.594C9.06312 73.3997 27.7909 92.1272 50.5966 92.1457C73.4023 92.1642 92.1298 73.4365 92.1483 50.6308C92.1669 27.8251 73.4392 9.0973 50.6335 9.07878C27.8278 9.06026 9.10003 27.787 9.08164 50.594Z",fill:"currentColor"}),(0,a.jsx)("path",{d:"M93.9676 39.0409C96.393 38.4037 97.8624 35.9116 96.9801 33.5533C95.1945 28.8227 92.871 24.3692 90.0681 20.348C85.6237 14.1775 79.4473 9.36872 72.0454 6.45794C64.6435 3.54717 56.3134 2.65431 48.3133 3.89319C45.869 4.27179 44.3768 6.77534 45.014 9.20079C45.6512 11.6262 48.1343 13.0956 50.5786 12.717C56.5073 11.8281 62.5542 12.5399 68.0406 14.7911C73.527 17.0422 78.2187 20.7487 81.5841 25.4923C83.7976 28.5886 85.4467 32.059 86.4416 35.7474C87.1273 38.1189 89.5423 39.6781 91.9676 39.0409Z",fill:"currentFill"})]})}}]);