1import{r as m,j as e,v as z,w as p,N as J}from"./vendor-react-14ONC-yq.js";import{E as K,as as V,am as P,P as H}from"./index-B3ArjiUf.js";import{p as Y}from"./middleware-BoeWS_xQ.js";import{c as G,l as X,d as Z,g as $,h as ee,f as se,b as te,e as re}from"./chatApi-91TYogVg.js";import{s as We}from"./chatApi-91TYogVg.js";import{P as oe}from"./plus-Dxvqbdxq.js";import{M as ae}from"./message-square-Ciq_aEoX.js";import{T as ne}from"./trash-2-o5NH4M5r.js";import"./vendor-query-DF2mAjY6.js";import"./vendor-charts-Byh2YVOQ.js";import"./vendor-radix-CeIbOqmj.js";import"./vendor-markdown-TRQC3W4o.js";const le=K()(Y(d=>({conversations:[],activeConversationId:null,setActiveConversation:r=>d({activeConversationId:r}),addConversation:r=>d(n=>({conversations:[...n.conversations,r]})),deleteConversation:r=>d(n=>({conversations:n.conversations.filter(h=>h.id!==r),activeConversationId:n.activeConversationId===r?null:n.activeConversationId})),documents:[],addDocument:r=>d(n=>({documents:[...n.documents,r]})),deleteDocument:r=>d(n=>({documents:n.documents.filter(h=>h.id!==r)})),selectedModels:["vllm"],setSelectedModels:r=>d({selectedModels:r}),voiceEnabled:!1,voiceSpeed:1,setVoiceEnabled:r=>d({voiceEnabled:r}),setVoiceSpeed:r=>d({voiceSpeed:r}),sidebarOpen:!0,toggleSidebar:()=>d(r=>({sidebarOpen:!r.sidebarOpen}))}),{name:"dblchat-storage",partialize:d=>({voiceEnabled:d.voiceEnabled,voiceSpeed:d.voiceSpeed,sidebarOpen:d.sidebarOpen,selectedModels:d.selectedModels})})),ie=G(),{sendMultiModelChat:Oe,sendMultiModelChatStream:de,closeWebSocket:Le,getAvailableModels:ce,getModelDisplayName:Re,getModelProvider:Be,formatCost:me,formatTokens:ue}=ie;function xe({currentConversationId:d,onSelectConversation:r,onNewConversation:n}){const[h,l]=m.useState([]),[j,N]=m.useState(!0),[E,w]=m.useState(null);m.useEffect(()=>{y()},[]);const y=async()=>{try{N(!0),w(null);const a=await X();l(a)}catch(a){console.error("Failed to load conversations:",a),w("Failed to load conversations")}finally{N(!1)}},_=async(a,v)=>{if(v.stopPropagation(),!!confirm("Delete this conversation?"))try{await Z(a),l(h.filter(t=>t.id!==a)),a===d&&n()}catch(t){console.error("Failed to delete conversation:",t),alert("Failed to delete conversation")}},f=a=>{const v=new Date(a),S=new Date().getTime()-v.getTime(),g=Math.floor(S/6e4),C=Math.floor(S/36e5),M=Math.floor(S/864e5);return g<1?"Just now":g<60?`${g}m ago`:C<24?`${C}h ago`:M===1?"Yesterday":M<7?`${M}d ago`:v.toLocaleDateString()};return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("div",{className:"p-4 border-b border-border",children:e.jsxs("button",{onClick:n,className:"w-full flex items-center justify-center gap-2 px-4 py-2 bg-primary text-primary-foreground rounded-lg hover:bg-primary/90 transition-colors",children:[e.jsx(oe,{className:"w-4 h-4"}),"New Chat"]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[j&&e.jsx("div",{className:"p-4 text-center text-muted-foreground",children:"Loading conversations..."}),E&&e.jsx("div",{className:"p-4 text-center text-destructive text-sm",children:E}),!j&&h.length===0&&e.jsxs("div",{className:"p-4 text-center text-muted-foreground text-sm",children:["No conversations yet.",e.jsx("br",{}),"Start a new chat to begin!"]}),!j&&h.length>0&&e.jsx("div",{className:"space-y-1 p-2",children:h.map(a=>e.jsx("div",{className:` 2 relative w-full text-left p-3 rounded-lg transition-colors group cursor-pointer 3 ${a.id===d?"bg-primary/10 border border-primary/30":"hover:bg-muted border border-transparent"} 4 `,onClick:()=>r(a.id),children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(ae,{className:"w-4 h-4 mt-0.5 flex-shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm truncate",children:a.title}),e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:f(a.updated_at)})]}),e.jsx("button",{onClick:v=>_(a.id,v),className:"opacity-0 group-hover:opacity-100 p-1 hover:bg-destructive/10 rounded transition-opacity",title:"Delete conversation",children:e.jsx(ne,{className:"w-3 h-3 text-destructive"})})]})},a.id))})]})]})}function he({model:d,messages:r,isLoading:n}){const h=m.useRef(null);return m.useEffect(()=>{var l;(l=h.current)==null||l.scrollIntoView({behavior:"smooth"})},[r,n]),e.jsxs("div",{className:"flex flex-col h-full border-r border-border last:border-r-0",children:[e.jsxs("div",{className:"p-4 border-b border-border bg-card",children:[e.jsx("h3",{className:"font-semibold text-foreground",children:d.name}),e.jsx("p",{className:"text-sm text-muted-foreground",children:d.provider})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-4 max-h-[calc(100vh-350px)]",children:[r.length===0&&!n&&e.jsx("div",{className:"text-center text-muted-foreground py-8",children:"Send a message to start chatting"}),r.map(l=>e.jsx("div",{children:e.jsxs("div",{className:`p-3 rounded-lg ${l.role==="user"?"bg-primary text-white ml-8":l.error?"bg-red-500/10 border border-red-500/30 mr-8 text-red-400":"bg-card border border-border mr-8 text-foreground"}`,children:[e.jsx("div",{className:"text-sm font-semibold mb-1",children:l.role==="user"?"You":l.model||"Assistant"}),e.jsx("div",{className:"whitespace-pre-wrap break-words",children:l.content||l.error}),l.tokens_used!==void 0&&l.cost_usd!==void 0&&e.jsxs("div",{className:"text-xs text-muted-foreground mt-2 flex gap-4",children:[e.jsxs("span",{children:[ue(l.tokens_used)," tokens"]}),e.jsx("span",{children:me(l.cost_usd)})]})]})},l.id)),n&&e.jsxs("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[e.jsx("div",{className:"animate-pulse",children:"â"}),e.jsx("div",{className:"animate-pulse animation-delay-200",children:"â"}),e.jsx("div",{className:"animate-pulse animation-delay-400",children:"â"}),e.jsx("span",{className:"ml-2",children:"Thinking..."})]}),e.jsx("div",{ref:h})]})]})}function pe(){const{selectedModels:d,setSelectedModels:r}=le(),[n,h]=m.useState([]),[l,j]=m.useState({}),[N,E]=m.useState(""),[w,y]=m.useState(!1),[_,f]=m.useState(null),[a,v]=m.useState(null),[t,S]=m.useState(()=>{const s=localStorage.getItem("dblchat_models_to_run");return s?JSON.parse(s):[]}),[g,C]=m.useState([]),[M,F]=m.useState(!1);m.useEffect(()=>{O()},[]),m.useEffect(()=>{localStorage.setItem("dblchat_models_to_run",JSON.stringify(t))},[t]);const O=async()=>{try{const s=await ce();h(s.models);const i=s.models.map(o=>o.id),u=t.filter(o=>i.includes(o));u.length!==t.length&&S(u),u.length===0&&s.models.length>0&&S([s.models[0].id])}catch(s){console.error("Failed to load available models:",s),f("Failed to load available models. Please check your AI settings.")}},L=s=>{t.includes(s)?t.length>1&&(S(t.filter(i=>i!==s)),C(g.filter(i=>i!==s))):S([...t,s])},R=s=>{if(g.includes(s))C(g.filter(i=>i!==s));else{if(g.length>=2){f("Maximum 2 models can be displayed at once. Uncheck one first."),setTimeout(()=>f(null),3e3);return}C([...g,s])}},T=async()=>
4{if(!N.trim()||w||t.length===0)return;f(null);const s={id:$(),role:"user",content:N,timestamp:new Date},i={...l};t.forEach(o=>{i[o]=[...i[o]||[],s]}),j(i);const u=N;E(""),y(!0);try{let o=a==null?void 0:a.id;if(!o){const c=ee(u),D=await se({title:c,model:t[0]});v(D),o=D.id}const x={...i},b={};de({prompt:u,models:t,temperature:.7},c=>{console.log(`Response received from ${c.model}`),b[c.model]=c;const D={id:$(),role:"assistant",content:c.content,model:c.model,timestamp:new Date,tokens_used:c.tokens_used,cost_usd:c.estimated_cost_usd,error:c.error};x[c.model]=[...x[c.model]||[],D],j({...x}),C(A=>!A.includes(c.model)&&A.length<2?[...A,c.model]:A)},()=>{console.log("All models completed"),y(!1),o&&W(o,u,b)},c=>{console.error("Stream error:",c),f(c),y(!1)})}catch(o){console.error("Error sending message:",o),f(o.message||"Failed to send message"),y(!1)}},B=s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),T())},U=async s=>{try{y(!0),f(null);const[i,u]=await Promise.all([te(s),re(s)]);v(i);const o={};u.forEach(x=>{const b={id:x.id,role:x.role,content:x.content,model:x.model,timestamp:new Date(x.created_at),tokens_used:(x.tokens_input||0)+(x.tokens_output||0),cost_usd:x.cost_usd};b.role==="user"?t.forEach(c=>{o[c]||(o[c]=[]),o[c].push(b)}):b.model&&(o[b.model]||(o[b.model]=[]),o[b.model].push(b))}),j(o)}catch(i){console.error("Failed to load conversation:",i),f("Failed to load conversation")}finally{y(!1)}},q=()=>{v(null),j({}),f(null),C([])},Q=async s=>{await U(s)},W=async(s,i,u)=>{console.debug("WebSocket messages are not persisted to DB")},I=Object.keys(l).filter(s=>l[s].some(i=>i.role==="assistant")),k=n.filter(s=>g.includes(s.id));return e.jsxs("div",{className:"flex h-full bg-background",children:[e.jsx("aside",{className:"w-64 border-r border-border bg-card overflow-y-auto",children:e.jsx(xe,{currentConversationId:a==null?void 0:a.id,onSelectConversation:Q,onNewConversation:q})}),e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsxs("div",{className:"border-b border-border p-4 bg-card",children:[_&&e.jsx("div",{className:"mb-4 p-3 bg-red-500/10 border border-red-500/30 rounded text-sm text-red-400",children:_}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsxs("button",{onClick:()=>F(!M),className:"flex items-center gap-2 px-3 py-2 bg-muted rounded-md hover:bg-accent transition-colors text-sm text-foreground",children:[e.jsx(V,{className:"w-4 h-4"}),e.jsxs("span",{children:["AI Models (",n.length,")"]})]}),t.map(s=>{const i=n.find(x=>x.id===s);if(!i)return null;const u=I.includes(s),o=g.includes(s);return e.jsxs("button",{onClick:()=>u&&R(s),disabled:!u,className:`px-4 py-2 rounded-md text-sm font-medium transition-all ${o?"bg-primary text-white":u?"bg-muted text-foreground hover:bg-accent":"bg-muted text-muted-foreground cursor-default"}`,children:[i.name,u&&e.jsx(P,{className:`w-3 h-3 ml-2 inline ${o?"text-white":"text-primary"}`})]},s)})]}),M&&e.jsxs("div",{className:"mt-4 p-4 bg-background rounded-lg border border-border",children:[e.jsx("h3",{className:"text-sm font-medium text-foreground mb-3",children:"Select AI Models to Compare"}),e.jsx("div",{className:"space-y-2",children:n.length===0?e.jsxs("div",{className:"text-sm text-muted-foreground",children:["No models available. Configure API keys in"," ",e.jsx("a",{href:"/settings",className:"text-blue-500 hover:underline",children:"Settings"})]}):n.map(s=>e.jsxs("label",{className:"flex items-center justify-between p-3 hover:bg-card cursor-pointer rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative flex items-center",children:[e.jsx("input",{type:"checkbox",checked:t.includes(s.id),onChange:()=>L(s.id),className:"w-5 h-5 rounded border-2 border-accent bg-background checked:bg-primary checked:border-primary appearance-none cursor-pointer"}),t.includes(s.id)&&e.jsx(P,{className:"w-4 h-4 text-white absolute left-0.5 top-0.5 pointer-events-none"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-foreground",children:s.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s.provider})]})]}
4),I.includes(s.id)&&e.jsx(P,{className:"w-4 h-4 text-primary"})]},s.id))})]})]}),e.jsxs("div",{className:"border-b border-border p-4 bg-card",children:[e.jsxs("div",{className:"flex space-x-2 items-center",children:[e.jsx("input",{type:"text",value:N,onChange:s=>E(s.target.value),onKeyPress:B,placeholder:"Ask a question to compare models...",className:"flex-1 p-3 border border-accent rounded-lg bg-background text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent",disabled:w||t.length===0}),e.jsx("button",{onClick:T,disabled:w||!N.trim()||t.length===0,className:"px-6 py-3 bg-primary text-white rounded-lg hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed font-medium",children:"Send"})]}),e.jsx("div",{className:"mt-2 text-sm text-muted-foreground",children:"Press Enter to send"})]}),e.jsx("div",{className:`flex-1 grid ${k.length===1?"grid-cols-1":k.length===2?"grid-cols-2":k.length===3?"grid-cols-3":k.length>=4?"grid-cols-2 lg:grid-cols-4":"grid-cols-1"} overflow-hidden bg-background`,children:k.length===0?e.jsx("div",{className:"flex items-center justify-center text-center p-8",children:e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:"Send a message to start chatting"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t.length>0?`${t.length} model${t.length>1?"s":""} selected`:"Select models to compare"})]})}):k.map(s=>e.jsx(he,{model:s,messages:l[s.id]||[],isLoading:w},s.id))})]})]})}const fe=()=>e.jsx("div",{className:"p-8",children:"Semantic Search Simulator - Coming Soon"}),ge=()=>e.jsx("div",{className:"p-8",children:"Compatibility Calculator - Coming Soon"}),ve=()=>e.jsx("div",{className:"p-8",children:"Risk Assessment Analyzer - Coming Soon"}),be=()=>e.jsx("div",{className:"p-8",children:"Market Research Dashboard - Coming Soon"}),je=()=>e.jsx("div",{className:"p-8",children:"Location Intelligence Map - Coming Soon"}),Ne=()=>e.jsx("div",{className:"p-8",children:"User Segmentation Explorer - Coming Soon"}),ye=()=>e.jsx("div",{className:"p-8",children:"Processing Queue Monitor - Coming Soon"}),Se=()=>e.jsx("div",{className:"p-8",children:"AI Insights Browser - Coming Soon"}),Ce=()=>e.jsx("div",{className:"p-8",children:"Model Performance Analytics - Coming Soon"}),we=()=>e.jsx("div",{className:"p-8",children:"Qdrant Collection Explorer - Coming Soon"});function Ue(){return e.jsx(H,{hideHeader:!0,fullWidth:!0,children:e.jsx("div",{className:"h-full overflow-auto",children:e.jsxs(z,{children:[e.jsx(p,{path:"/",element:e.jsx(pe,{})}),e.jsx(p,{path:"/semantic-search",element:e.jsx(fe,{})}),e.jsx(p,{path:"/compatibility",element:e.jsx(ge,{})}),e.jsx(p,{path:"/risk",element:e.jsx(ve,{})}),e.jsx(p,{path:"/market",element:e.jsx(be,{})}),e.jsx(p,{path:"/location",element:e.jsx(je,{})}),e.jsx(p,{path:"/segments",element:e.jsx(Ne,{})}),e.jsx(p,{path:"/queue",element:e.jsx(ye,{})}),e.jsx(p,{path:"/insights",element:e.jsx(Se,{})}),e.jsx(p,{path:"/analytics",element:e.jsx(Ce,{})}),e.jsx(p,{path:"/qdrant",element:e.jsx(we,{})}),e.jsx(p,{path:"*",element:e.jsx(J,{to:"/dblchat",replace:!0})})]})})})}export{Ue as Dblchat,pe as MultiModelChat,Le as closeWebSocket,se as createConversation,Z as deleteConversation,me as formatCost,ue as formatTokens,ee as generateTitle,ce as getAvailableModels,te as getConversation,re as getMessages,Re as getModelDisplayName,Be as getModelProvider,X as listConversations,We as sendMessage,Oe as sendMultiModelChat,de as sendMultiModelChatStream,le as useDblchatStore};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.