PageSourceSearch

https://www.cladia.ai/_next/static/chunks/1416.7e49c8262a022184.js

js cladia.ai collected 2026-10-09 22:57:03 UTC 65,406 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1416],{31416:function(e,t,r){r.r(t),r.d(t,{ChatLayout:function(){return j}});var o=r(27573),n=r(7653),i=r(28764);let l="wick-chat-sync";function a(){if("undefined"!=typeof BroadcastChannel){let e=new BroadcastChannel(l);return{postMessage:t=>e.postMessage(t),onMessage:t=>{let r=e=>t(e.data);return e.addEventListener("message",r),()=>e.removeEventListener("message",r)}}}return{postMessage:e=>{localStorage.setItem(l,JSON.stringify({...e,_ts:Date.now()})),setTimeout(()=>localStorage.removeItem(l),100)},onMessage:e=>{let t=t=>{if(t.key===l&&t.newValue)try{e(JSON.parse(t.newValue))}catch(e){}};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)}}}let s=a(),d=a(),c=a();function u(e){let{onClose:t,onCreate:r}=e,l=function(e){let t=(0,n.useRef)(null),r=(0,n.useRef)(null);return(0,n.useEffect)(()=>{if(!e)return;r.current=document.activeElement;let o=t.current;if(!o)return;let n=Array.from(o.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])')),i=n[0],l=n[n.length-1];null==i||i.focus();let a=e=>{"Tab"===e.key&&0!==n.length&&(e.shiftKey?document.activeElement===i&&(e.preventDefault(),l.focus()):document.activeElement===l&&(e.preventDefault(),i.focus()))};return document.addEventListener("keydown",a),()=>{document.removeEventListener("keydown",a),r.current instanceof HTMLElement&&r.current.focus()}},[e]),t}(!0),[a,s]=(0,n.useState)(""),[d,c]=(0,n.useState)(!1),[u,p]=(0,n.useState)(null),[h,g]=(0,n.useState)(null),[x,f]=(0,n.useState)([]),[y,m]=(0,n.use
1State)([]),[S,b]=(0,n.useState)(!1);(0,n.useEffect)(()=>{fetch("/api/clients?limit=200").then(e=>e.json()).then(e=>f(e.data||[])).catch(()=>{})},[]),(0,n.useEffect)(()=>{u?fetch("/api/projects?clientId=".concat(u,"&limit=200")).then(e=>e.json()).then(e=>m(e.data||e.projects||[])).catch(()=>{}):(m([]),g(null))},[u]);let v=async e=>{if(e.preventDefault(),a.trim()){b(!0);try{await r({name:a.trim(),isShared:d,clientId:u,projectId:h}),t()}catch(e){b(!1)}}},k=(0,n.useCallback)(e=>{"Escape"===e.key&&t()},[t]);return(0,o.jsx)("div",{onClick:t,style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.4)",zIndex:1100,display:"flex",alignItems:"center",justifyContent:"center"},children:(0,o.jsxs)("div",{ref:l,role:"dialog","aria-modal":"true","aria-labelledby":"create-folder-title",onClick:e=>e.stopPropagation(),onKeyDown:k,style:{background:i.rS.colors.bgSecondary,borderRadius:i.rS.borderRadius.lg,padding:24,width:400,maxWidth:"90vw",boxShadow:i.rS.shadows.lg,position:"relative"},children:[(0,o.jsx)("button",{type:"button",onClick:t,"aria-label":"Close",style:{position:"absolute",top:12,right:12,width:28,height:28,borderRadius:6,border:"none",background:"transparent",color:i.rS.colors.textMuted,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:(0,o.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,o.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,o.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),(0,o.jsx)("div",{id:"create-folder-title",style:{fontSize:16,fontWeight:600,color:i.rS.colors.textPrimary,marginBottom:16,paddingRight:24},children:"New Folder"}),(0,o.jsxs)("form",{onSubmit:v,style:{display:"flex",flexDirection:"column",gap:14},children:[(0,o.jsxs)("div",{children:[(0,o.jsx)("label",{style:{display:"block",fontSize:12,fontWeight:500,color:i.rS.colors.textSecondary,marginBottom:4},children:"Name"}),(0,o.jsx)("input",{autoFocus:!0,value:a,onChange:e=>s(e.target.value),placeholder:"e.g. Client X, General, Ideas...",style:{width:"100%",padding:"8px 12px",borderRadius:i.rS.borderRadius.md,border:"1px solid ".concat(i.rS.colors.borderLight),fontSize:13,outline:"none",boxSizing:"border-box"}})]}),(0,o.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:13,color:i.rS.colors.textPrimary},children:[(0,o.jsx)("input",{type:"checkbox",checked:d,onChange:e=>c(e.target.checked),style:{accentColor:i.rS.colors.primary}}),"Shared with team"]}),(0,o.jsxs)("div",{children:[(0,o.jsx)("label",{style:{display:"block",fontSize:12,fontWeight:500,color:i.rS.colors.textSecondary,marginBottom:4},children:"Link to Client (optional)"}),(0,o.jsxs)("select",{value:u||"",onChange:e=>p(e.target.value||null),style:{width:"100%",padding:"8px 12px",borderRadius:i.rS.borderRadius.md,border:"1px solid ".concat(i.rS.colors.borderLight),fontSize:13,outline:"none",boxSizing:"border-box",background:i.rS.colors.bgSecondary},children:[(0,o.jsx)("option",{value:"",children:"None"}),x.map(e=>(0,o.jsx)("option",{value:e.id,children:e.name},e.id))]})]}),u&&y.length>0&&(0,o.jsxs)("div",{children:[(0,o.jsx)("label",{style:{display:"block",fontSize:12,fontWeight:500,color:i.rS.colors.textSecondary,marginBottom:4},children:"Link to Project (optional)"}),(0,o.jsxs)("select",{value:h||"",onChange:e=>g(e.target.value||null),style:{width:"100%",padding:"8px 12px",borderRadius:i.rS.borderRadius.md,border:"1px solid ".concat(i.rS.colors.borderLight),fontSize:13,outline:"none",boxSizing:"border-box",background:i.rS.colors.bgSecondary},children:[(0,o.jsx)("option",{value:"",children:"None"}),y.map(e=>(0,o.jsx)("option",{value:e.id,children:e.name},e.id))]})]}),(0,o.jsxs)("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",marginTop:8},children:[(0,o.jsx)("button",{type:"button",onClick:t,style:{padding:"8px 16px",borderRadius:i.rS.borderRadius.md,border:"1px solid ".concat(i.rS.colors.borderLight),background:"transparent",fontSize:13,color:i.rS.colors.textSecondary,cursor:"pointer"},children:"Cancel"}),(0,o.jsx)("button",{type:"submit",disabled:S||!a.trim(),style:{padding:"8px 16px",borderRadius:i.rS.borderRadius.md,border:"none",background:a.trim()?i.rS.gradients.primary:i.rS.colors.borderLight,color:"white",fontSize:13,fontWeight:500,cursor:a.trim()?"pointer":"not-allowed"},children:S?"Creating...":"Create"})]})]})]})})}function p(e){let{folders:t,loading:r,error:l,onRetry:a,selectedFolderId:s,onSelectFolder:d,onCreateFolder:c,onDeleteFolder:p,onUpdateFolder:h,collapsed:g,onToggleCollapse:x,onDropConversation:f}
1=e,[y,m]=(0,n.useState)(!1),[S,b]=(0,n.useState)(null),[v,k]=(0,n.useState)(""),[j,w]=(0,n.useState)(null);return g?(0,o.jsxs)("div",{style:{width:40,flexShrink:0,borderRight:"1px solid ".concat(i.rS.colors.borderLight),display:"flex",flexDirection:"column",alignItems:"center",paddingTop:12,gap:8},children:[(0,o.jsx)("button",{onClick:x,title:"Expand folders",style:{width:28,height:28,borderRadius:6,border:"none",background:"transparent",color:i.rS.colors.textSecondary,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:(0,o.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,o.jsx)("polyline",{points:"9 18 15 12 9 6"})})}),(0,o.jsx)("div",{style:{fontSize:10,color:i.rS.colors.textMuted,writingMode:"vertical-rl",letterSpacing:1},children:"FOLDERS"})]}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("div",{style:{width:220,flexShrink:0,borderRight:"1px solid ".concat(i.rS.colors.borderLight),display:"flex",flexDirection:"column",overflow:"hidden"},children:[(0,o.jsxs)("div",{style:{padding:"12px 14px",borderBottom:"1px solid ".concat(i.rS.colors.borderLight),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,o.jsx)("span",{style:{fontSize:13,fontWeight:600,color:i.rS.colors.textPrimary},children:"Folders"}),(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,o.jsx)("button",{onClick:()=>m(!0),style:{width:26,height:26,borderRadius:6,border:"none",background:i.rS.colors.primaryBg,color:i.rS.colors.primary,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",fontSize:16,lineHeight:1},title:"New Folder",children:"+"}),(0,o.jsx)("button",{onClick:x,title:"Collapse folders",style:{width:26,height:26,borderRadius:6,border:"none",background:"transparent",color:i.rS.colors.textMuted,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:(0,o.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,o.jsx)("polyline",{points:"15 18 9 12 15 6"})})})]})]}),(0,o.jsxs)("div",{style:{flex:1,overflowY:"auto",padding:"4px"},children:[(0,o.jsx)("div",{onClick:()=>d(null),onDragOver:e=>{e.preventDefault(),e.currentTarget.style.background=i.rS.colors.primaryBg},onDragLeave:e=>{e.currentTarget.style.background=null===s?i.rS.colors.primaryBg:"transparent"},onDrop:e=>{e.preventDefault(),e.currentTarget.style.background=null===s?i.rS.colors.primaryBg:"transparent";let t=e.dataTransfer.getData("text/plain");t&&(null==f||f(null,t))},style:{padding:"8px 10px",borderRadius:i.rS.borderRadius.md,cursor:"pointer",fontSize:13,color:null===s?i.rS.colors.primary:i.rS.colors.textSecondary,fontWeight:null===s?600:400,background:null===s?i.rS.colors.primaryBg:"transparent",marginBottom:2},children:"All Chats"}),l?(0,o.jsxs)("div",{style:{padding:"8px 10px"},children:[(0,o.jsx)("div",{style:{fontSize:12,color:"#dc2626",marginBottom:6},children:l}),a&&(0,o.jsx)("button",{onClick:a,style:{padding:"4px 10px",borderRadius:6,border:"1px solid ".concat(i.rS.colors.borderLight),background:"white",fontSize:12,cursor:"pointer"},children:"Retry"})]}):r?(0,o.jsx)("div",{style:{padding:"8px 10px",fontSize:12,color:i.rS.colors.textMuted},children:"Loading..."}):0===t.length?(0,o.jsx)("div",{style:{padding:"8px 10px",fontSize:12,color:i.rS.colors.textMuted},children:"No folders yet"}):t.map(e=>(0,o.jsxs)("div",{onClick:()=>d(e.id),onContextMenu:t=>{t.preventDefault(),w(j===e.id?null:e.id)},onDragOver:e=>{e.preventDefault(),e.currentTarget.style.background=i.rS.colors.primaryBg},onDragLeave:t=>{t.currentTarget.style.background=s===e.id?i.rS.colors.primaryBg:"transparent"},onDrop:t=>{t.preventDefault(),t.currentTarget.style.background=s===e.id?i.rS.colors.primaryBg:"transparent";let r=t.dataTransfer.getData("text/plain");r&&(null==f||f(e.id,r))},style:{padding:"8px 10px",borderRadius:i.rS.borderRadius.md,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:13,color:s===e.id?i.rS.colors.primary:i.rS.colors.textSecondary,fontWeight:s===e.id?600:400,background:s===e.id?i.rS.colors.primaryBg:"transparent",marginBottom:2,gap:6,position:"relative"},children:[(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,minWidth:0,flex:1},children:[(0,o.jsx)("span",{style:{flexShrink:0,fontSize:14},children:e.isShared?(0,o.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[(0,o.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,o.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,o.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,o.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}):(0,o.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:(0,o.jsx)("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}),S===e.id?(0,o.jsx)("input",{type:"text",value:v,autoFocus:!0,onChange:e=>k(e.target.value),onKeyDown:t=>{"Enter"===t.key&&v.trim()&&(null==h||h(e.id,{name:v.trim()}),b(null)),"Escape"===t.key&&b(null)},onBlur:()=>{v.trim()&&v!==e.name&&(null==h||h(e.id,{name:v.trim()})),b(null)},onClick:e=>e.stopPropagation(),style:{width:"100%",fontSize:13,padding:"2px 4px",border:"1px solid ".concat(i.rS.colors.primary),borderRadius:4,outline:"none",background:i.rS.colors.bgPrimary,color:i.rS.colors.textPrimary}}):(0,o.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name})]}),S!==e.id&&e._count&&(0,o.jsx)("span",{style:{fontSize:11,color:i.rS.colors.textMuted,flexShrink:0},children:e._count.conversations}),j===e.id&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,zIndex:998},onClick:()=>w(null)}),(0,o.jsxs)("div",{style:{position:"absolute",top:"100%",right:0,zIndex:999,background:i.rS.colors.bgSecondary,border:"1px solid ".concat(i.rS.colors.borderLight),borderRadius:8,boxShadow:"0 4px 12px rgba(0,0,0,0.1)",padding:4,minWidth:120},children:[(0,o.jsx)("button",{onClick:t=>{t.stopPropagation(),b(e.id),k(e.name),w(null)},style:{display:"block",width:"100%",padding:"6px 10px",fontSize:12,background:"transparent",border:"none",color:i.rS.colors.textPrimary,cursor:"pointer",textAlign:"left",borderRadius:4},children:"Rename"}),(0,o.jsx)("button",{onClick:t=>{t.stopPropagation(),w(null),confirm('Delete folder "'.concat(e.name,'"? Conversations will be moved to root.'))&&p(e.id)},style:{display:"block",width:"100%",padding:"6px 10px",fontSize:12,background:"transparent",border:"none",color:i.rS.colors.error,cursor:"pointer",textAlign:"left",borderRadius:4},children:"Delete"})]})]})]},e.id))]})]}),y&&(0,o.jsx)(u,{onClose:()=>m(!1),onCreate:async e=>{await c(e)}})]})}function h(e){var t;let{conversations:r,loading:l,error:a,onRetry:s,activeConversationId:d,onSelectConversation:c,onCreateConversation:u,onDeleteConversation:p,onRenameConversation:h,onTogglePin:x,collapsed:f,onToggleCollapse:y,onDragConversation:m,hasMore:S,loadMore:b,onSearchServerSide:v,serverSearchCount:k=null}
1=e,[j,w]=(0,n.useState)(!1),[C,R]=(0,n.useState)(null),[T,L]=(0,n.useState)(""),[z,D]=(0,n.useState)(""),[I,E]=(0,n.useState)(null),[M,B]=(0,n.useState)(""),[W,P]=(0,n.useState)(null),A=(0,n.useRef)("");(0,n.useEffect)(()=>{if(!v)return;let e=T.trim();if(e.length<3){""!==A.current&&(A.current="",D(""),v("").catch(()=>{}));return}let t=setTimeout(()=>{A.current=e,D(e),v(e).catch(()=>{})},300);return()=>clearTimeout(t)},[T,v]);let N=[...r].sort((e,t)=>e.isPinned&&!t.isPinned?-1:!e.isPinned&&t.isPinned?1:0),F=T.trim(),O=!!v&&null!==k&&F.length>=3&&z===F,K=F&&!O?N.filter(e=>e.title.toLowerCase().includes(F.toLowerCase())):N;if(f)return(0,o.jsxs)("div",{style:{width:40,flexShrink:0,borderRight:"1px solid ".concat(i.rS.colors.borderLight),display:"flex",flexDirection:"column",alignItems:"center",paddingTop:12,gap:8},children:[(0,o.jsx)("button",{onClick:y,title:"Expand conversations",style:{width:28,height:28,borderRadius:6,border:"none",background:"transparent",color:i.rS.colors.textSecondary,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:(0,o.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,o.jsx)("polyline",{points:"9 18 15 12 9 6"})})}),(0,o.jsx)("div",{style:{fontSize:10,color:i.rS.colors.textMuted,writingMode:"vertical-rl",letterSpacing:1},children:"CHATS"})]});let H=async()=>{w(!0);try{let e=await u();c(e.id)}catch(e){}w(!1)},U=async(e,t)=>{e.stopPropagation(),confirm("Delete this conversation?")&&await p(t)},_=e=>{var t,r;let o=null===(t=e.messages)||void 0===t?void 0:t[0];return(null==o?void 0:null===(r=o.content)||void 0===r?void 0:r.slice(0,80))||"Empty conversation"};return(0,o.jsxs)("div",{style:{width:280,flexShrink:0,borderRight:"1px solid ".concat(i.rS.colors.borderLight),display:"flex",flexDirection:"column",overflow:"hidden"},children:[(0,o.jsxs)("div",{style:{padding:"12px 14px",borderBottom:"1px solid ".concat(i.rS.colors.borderLight),display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,o.jsx)("span",{style:{fontSize:13,fontWeight:600,color:i.rS.colors.textPrimary},children:"Conversations"}),(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:4},children:[(0,o.jsx)("button",{onClick:H,disabled:j,style:{width:26,height:26,borderRadius:6,border:"none",background:i.rS.colors.primaryBg,color:i.rS.colors.primary,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",fontSize:16,lineHeight:1,fontWeight:600},title:"New Chat",children:"+"}),(0,o.jsx)("button",{onClick:y,title:"Collapse conversations",style:{width:26,height:26,borderRadius:6,border:"none",background:"transparent",color:i.rS.colors.textMuted,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:(0,o.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,o.jsx)("polyline",{points:"15 18 9 12 15 6"})})})]})]}),!l&&(0,o.jsxs)("div",{style:{padding:"4px 8px 0"},children:[(0,o.jsx)("input",{type:"text",placeholder:"Search titles & messages…",value:T,onChange:e=>L(e.target.value),style:{width:"100%",padding:"6px 10px",borderRadius:6,border:"1px solid ".concat(i.rS.colors.borderLight),fontSize:12,outline:"none",background:i.rS.colors.bgPrimary,color:i.rS.colors.textPrimary,boxSizing:"border-box"}}),v&&T.trim().length>=3&&null!==k&&(0,o.jsxs)("div",{style:{fontSize:11,color:i.rS.colors.textMuted,padding:"4px 2px 0"},children:[k," chat",1===k?"":"s"," match “",T.trim(),"” in titles or messages"]})]}),(0,o.jsxs)("div",{style:{flex:1,overflowY:"auto",padding:"4px"},children:[a?(0,o.jsxs)("div",{style:{padding:"12px 14px",textAlign:"center"},children:[(0,o.jsx)("div",{style:{fontSize:12,color:"#dc2626",marginBottom:8},children:a}),s&&(0,o.jsx)("button",{onClick:s,style:{padding:"4px 10px",borderRadius:6,border:"1px solid ".concat(i.rS.colors.borderLight),background:"white",fontSize:12,cursor:"pointer"},children:"Retry"})]}):l?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("style",{children:".skeleton-pulse{animation:skeletonPulse 1.5s ease-in-out infinite}@keyframes skeletonPulse{0%,100%{opacity:1}50%{opacity:0.4}}"}),(0,o.jsx)("div",{style:{padding:"4px"},children:Array.from({length:5}).map((e,t)=>(0,o.jsx)("div",{className:"skeleton-pulse",style:{height:42,borderRadius:8,marginBottom:4,opacity:1-.12*t}},t))})]}):0===r.length?(0,o.jsx)("div",{style:{padding:"12px 14px",fontSize:12,color:i.rS.colors.textMuted,textAlign:"center"},children:O?"No chats match “".concat(F,"” in titles or messages"):"No conversations yet"}):0===K.length?(0,o.jsx)("div",{style:{padding:"12px 14px",fontSize:12,color:i.rS.colors.textMuted,textAlign:"center"},children:"No title matches yet — searching messages…"}):K.map(e=>(0,o.jsxs)("div",{draggable:!!m,onDragStart:t=>{t.dataTransfer.setData("text/plain",e.id),t.dataTransfer.effectAllowed="move"},onContextMenu:t=>{t.preventDefault(),P({convId:e.id,x:t.clientX,y:t.clientY})},onClick:()=>c(e.id),onMouseEnter:()=>R(e.id),onMouseLeave:()=>R(null),style:{padding:"10px 12px",borderRadius:i.rS.borderRadius.md,cursor:"pointer",background:d===e.id?i.rS.colors.primaryBg:"transparent",marginBottom:2,display:"flex",justifyContent:"space-between",alignItems:"flex-start",ga
1p:8},children:[(0,o.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,o.jsx)("div",{style:{fontSize:13,fontWeight:d===e.id?600:500,color:i.rS.colors.textPrimary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",marginBottom:2},children:I===e.id?(0,o.jsx)("input",{autoFocus:!0,value:M,onChange:e=>B(e.target.value),onBlur:async()=>{M.trim()&&M!==e.title&&await (null==h?void 0:h(e.id,M.trim())),E(null)},onKeyDown:async t=>{"Enter"===t.key?(M.trim()&&M!==e.title&&await (null==h?void 0:h(e.id,M.trim())),E(null)):"Escape"===t.key&&E(null)},onClick:e=>e.stopPropagation(),style:{width:"100%",padding:"1px 4px",border:"1px solid ".concat(i.rS.colors.primary),borderRadius:4,fontSize:13,fontWeight:600,outline:"none",background:"white",color:i.rS.colors.textPrimary,boxSizing:"border-box"}}):(0,o.jsx)("span",{onDoubleClick:t=>{t.stopPropagation(),E(e.id),B(e.title)},title:"Double-click to rename",children:e.title})}),(0,o.jsxs)("div",{style:{fontSize:11,color:i.rS.colors.textMuted,overflow:"hidden",display:"-webkit-box",WebkitBoxOrient:"vertical",WebkitLineClamp:2,overflowWrap:"anywhere"},children:[_(e)," \xb7 ",function(e){let t=Math.floor((Date.now()-new Date(e).getTime())/1e3);if(t<60)return"just now";let r=Math.floor(t/60);if(r<60)return"".concat(r,"m ago");let o=Math.floor(r/60);if(o<24)return"".concat(o,"h ago");let n=Math.floor(o/24);return n<7?"".concat(n,"d ago"):n<30?"".concat(Math.floor(n/7),"w ago"):new Date(e).toLocaleDateString([],{month:"short",day:"numeric"})}(e.updatedAt)]})]}),(C===e.id||e.isPinned)&&(0,o.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:2,flexShrink:0,marginTop:2},children:[(0,o.jsx)("button",{onClick:async t=>{t.stopPropagation(),await (null==x?void 0:x(e.id,!e.isPinned))},style:{width:22,height:22,borderRadius:i.rS.borderRadius.sm,border:"none",background:"transparent",color:e.isPinned?i.rS.colors.primary:i.rS.colors.textMuted,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},title:e.isPinned?"Unpin":"Pin",children:(0,o.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:e.isPinned?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",children:(0,o.jsx)("path",{d:"M12 2L15.09 8.26L22 9.27L17 14.14L18.18 21.02L12 17.77L5.82 21.02L7 14.14L2 9.27L8.91 8.26L12 2Z"})})}),C===e.id&&(0,o.jsx)("button",{onClick:t=>U(t,e.id),style:{width:22,height:22,borderRadius:i.rS.borderRadius.sm,border:"none",background:"transparent",color:i.rS.colors.textMuted,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",fontSize:12},title:"Delete",children:(0,o.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,o.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,o.jsx)("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]})})]})]},e.id)),S&&(0,o.jsx)("div",{style:{padding:"8px 4px",textAlign:"center"},children:(0,o.jsx)("button",{onClick:b,disabled:l,style:{padding:"6px 12px",borderRadius:6,border:"1px solid ".concat(i.rS.colors.borderLight),background:i.rS.colors.bgPrimary,color:i.rS.colors.textSecondary,fontSize:12,cursor:l?"not-allowed":"pointer",opacity:l?.6:1},children:l?"Loading…":"Load more"})})]}),W&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("div",{onClick:()=>P(null),style:{position:"fixed",inset:0,zIndex:99}}),(0,o.jsxs)("div",{style:{position:"fixed",top:W.y,left:W.x,zIndex:100,background:i.rS.colors.bgSecondary,border:"1px solid ".concat(i.rS.colors.borderLight),borderRadius:8,boxShadow:i.rS.shadows.lg,padding:4,minWidth:160},children:[(0,o.jsx)("button",{onClick:()=>{var e;E(W.convId),B((null===(e=r.find(e=>e.id===W.convId))||void 0===e?void 0:e.title)||""),P(null)},style:g,children:"✏️ Rename"}),(0,o.jsxs)("button",{onClick:async()=>{let e=r.find(e=>e.id===W.convId);e&&await (null==x?void 0:x(W.convId,!e.isPinned)),P(null)},style:g,children:["\uD83D\uDCCC ",(null===(t=r.find(e=>e.id===W.convId))||void 0===t?void 0:t.isPinned)?"Unpin":"Pin"]}),(0,o.jsx)("button",{onClick:()=>{U({stopPropagation:()=>{}},W.convId),P(null)},style:{...g,color:i.rS.colors.error},children:"\uD83D\uDDD1️ Delete"})]})]})]})}let g={display:"block",width:"100%",padding:"6px 12px",border:"none",background:"transparent",color:i.rS.colors.textPrimary,fontSize:12,cursor:"pointer",textAlign:"left",borderRadius:4};var x=r(25145),f=r(94654);function y(e){let{onCreateChat:t}=e;return(0,o.jsxs)("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",padding:40,gap:16},children:[(0,o.jsx)("div",{style:{width:64,height:64,borderRadius:i.rS.borderRadius.xl,background:i.rS.colors.primaryBg,display:"flex",alignItems:"center",justifyContent:"center"},children:(0,o.jsx)("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:i.rS.colors.primary,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,o.jsx)("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),(0,o.jsxs)("div",{style:{textAlign:"center"},children:[(0,o.jsx)("div",{style:{fontSize:16,fontWeight:600,color:i.rS.colors.textPrimary,marginBottom:4},children:"Start a conversation"}),(0,o.jsx)("div",{style:{fontSize:13,color:i.rS.colors.textMuted,marginBottom:16},children:"Chat with AI to get help with tasks, research, writing, and more."})]}),(0,o.jsx)("button",{onClick:t,style:{padding:"10px 24px",borderRadius:i.rS.borderRadius.md,background:i.rS.gradients.primary,color:"white",border:"none",fontSize:14,fontWeight:500,cursor:"pointer"},children:"New Chat"})]})}function m(e){let{onCopy:t,onDelete:r,onRegenerate:l,disabled:a}
1=e,[s,d]=(0,n.useState)(!1),c=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(!s)return;let e=e=>{var t;(null===(t=c.current)||void 0===t?void 0:t.contains(e.target))||d(!1)},t=e=>{"Escape"===e.key&&d(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[s]);let u={display:"flex",alignItems:"center",gap:8,width:"100%",padding:"6px 10px",border:"none",background:"transparent",color:i.rS.colors.textPrimary,fontSize:12,cursor:"pointer",textAlign:"left",borderRadius:4};return(0,o.jsxs)("div",{ref:c,style:{position:"relative",display:"inline-flex"},children:[(0,o.jsx)("button",{onClick:()=>d(e=>!e),disabled:a,"aria-haspopup":"menu","aria-expanded":s,"aria-label":"Message actions",style:{width:22,height:22,borderRadius:6,border:"none",background:"transparent",color:i.rS.colors.textMuted,cursor:a?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",opacity:.7},children:(0,o.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,o.jsx)("circle",{cx:"5",cy:"12",r:"2"}),(0,o.jsx)("circle",{cx:"12",cy:"12",r:"2"}),(0,o.jsx)("circle",{cx:"19",cy:"12",r:"2"})]})}),s&&(0,o.jsxs)("div",{role:"menu",style:{position:"absolute",top:"100%",right:0,zIndex:20,minWidth:140,background:i.rS.colors.bgSecondary,border:"1px solid ".concat(i.rS.colors.borderLight),borderRadius:8,boxShadow:i.rS.shadows.lg,padding:4,marginTop:4},children:[(0,o.jsxs)("button",{role:"menuitem",onClick:()=>{t(),d(!1)},style:u,children:[(0,o.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,o.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),(0,o.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),"Copy"]}),l&&(0,o.jsxs)("button",{role:"menuitem",onClick:()=>{null==l||l(),d(!1)},style:u,children:[(0,o.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,o.jsx)("polyline",{points:"1 4 1 10 7 10"}),(0,o.jsx)("path",{d:"M3.51 15a9 9 0 1 0 2.13-9.36L1 10"})]}),"Regenerate"]}),r&&(0,o.jsxs)("button",{role:"menuitem",onClick:()=>{null==r||r(),d(!1)},style:{...u,color:i.rS.colors.error},children:[(0,o.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,o.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,o.jsx)("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]}),"Delete"]})]})]})}r(87376).Buffer;let S=["localhost","127.0.0.1","0.0.0.0","[::1]"],b=[/^10\./,/^172\.(1[6-9]|2\d|3[01])\./,/^192\.168\./,/^169\.254\./,/^fc00:/,/^fe80:/],v=["Help me draft a proposal","Summarize this document","Brainstorm campaign ideas","Write a client email","Analyze this data"];function k(e){let{messages:t,sending:r,streaming:l,error:a,status:s,activeConversationId:d,onSendMessage:c,onStopStreaming:u,onCreateChat:p,onConversationIdChange:h,onDeleteMessage:g,messagesLoading:k,onBack:j}
1=e,[w,C]=(0,n.useState)(""),[R,T]=(0,n.useState)([]),[L,z]=(0,n.useState)(!1),[D,I]=(0,n.useState)(!1),[E,M]=(0,n.useState)(null),[B,W]=(0,n.useState)({}),[P,A]=(0,n.useState)([]),[N,F]=(0,n.useState)(null),[O,K]=(0,n.useState)(!1),H=(0,n.useRef)(l),U=(0,n.useRef)(null),_=(0,n.useRef)(null),V=(0,n.useRef)(null),$=(0,n.useRef)(null),J=(0,n.useRef)([]),q=Array.from(new Set(w.match(/https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*)/gi)||[])).filter(e=>e.startsWith("https://")).filter(e=>null!==function(e){try{let t=new URL(e);if("https:"!==t.protocol)return null;let r=t.hostname.toLowerCase();if(S.includes(r))return null;for(let e of b)if(e.test(r))return null;return t}catch(e){return null}}(e)),Y=(0,n.useCallback)(()=>{let e=V.current;if(!e)return;e.style.height="0px";let t=L?600:220;e.style.height="".concat(Math.min(Math.max(e.scrollHeight,60),t),"px")},[L]);(0,n.useEffect)(()=>{Y()},[w,Y]);let G=(0,n.useCallback)(()=>{var e;null===(e=U.current)||void 0===e||e.scrollIntoView({behavior:"smooth"}),I(!1)},[]);(0,n.useEffect)(()=>{G()},[t]),(0,n.useEffect)(()=>{d&&(K(!0),fetch("/api/chat/models?conversationId=".concat(d)).then(async e=>{if(!e.ok)return;let t=await e.json();A(t.allowedModels||[]),F(t.currentModelId||null)}).catch(()=>{}).finally(()=>K(!1)))},[d]),(0,n.useEffect)(()=>{let e=_.current;if(!e)return;let t=()=>{let{scrollTop:t,scrollHeight:r,clientHeight:o}=e;I(r-t-o>200)};return e.addEventListener("scroll",t,{passive:!0}),()=>e.removeEventListener("scroll",t)},[]),(0,n.useEffect)(()=>{var e;window.innerWidth<768||null===(e=V.current)||void 0===e||e.focus()},[d]);let X=async()=>{let e=(0,x.yn)(w.trim());if(!e&&0===R.length||r||l)return;let t=R.filter(e=>!e.uploading).map(e=>({r2Key:e.r2Key,fileName:e.fileName,mimeType:e.mimeType,fileSize:e.fileSize}));J.current=t,C(""),T(e=>e.filter(e=>e.uploading)),z(!1);let o=await c(d,e||"Please analyze the attached files.",t);o&&!d&&h(o)},Z=async()=>{let e=[...t].reverse().find(e=>"USER"===e.role);!e||r||l||await c(d,e.content,J.current)};(0,n.useEffect)(()=>{if(H.current&&!l&&!a)try{let e=new(window.AudioContext||window.webkitAudioContext),t=e.createOscillator(),r=e.createGain();t.connect(r),r.connect(e.destination),t.frequency.value=880,t.type="sine",r.gain.setValueAtTime(.1,e.currentTime),r.gain.exponentialRampToValueAtTime(.001,e.currentTime+.25),t.start(e.currentTime),t.stop(e.currentTime+.25)}catch(e){}H.current=l},[l,a]);let Q=async()=>{if(d)try{let e=await fetch("/api/chat/conversations/".concat(d,"/share"),{method:"POST"});if(e.ok){let t=await e.json();M(t.url);try{await navigator.clipboard.writeText(t.url)}catch(e){}}}catch(e){}},ee=async e=>{let t=e.target.files;if(t){for(let e=0;e<t.length;e++){let r=t[e],o="pending-".concat(Date.now(),"-").concat(e);T(e=>[...e,{r2Key:o,fileName:r.name,mimeType:r.type,fileSize:r.size,uploading:!0}]);try{let e=await fetch("/api/chat/upload-url",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({fileName:r.name,mimeType:r.type,fileSize:r.size})}),t=await e.json();if(!e.ok)throw Error(t.error);await fetch(t.uploadUrl,{method:"PUT",body:r,headers:{"Content-Type":r.type}}),T(e=>e.map(e=>e.r2Key===o&&e.fileName===r.name?{...e,r2Key:t.r2Key,uploading:!1}:e))}catch(e){console.error("File upload failed:",e),T(e=>e.filter(e=>e.r2Key!==o))}}e.target.value=""}};if(!d)return(0,o.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:(0,o.jsx)(y,{onCreateChat:p})});if(k)return(0,o.jsx)("div",{style:{flex:1,display:"flex",flexDirection:"column",padding:20,gap:8},children:Array.from({length:5}).map((e,t)=>(0,o.jsx)("div",{className:"skeleton-pulse",style:{height:40,borderRadius:8,width:"".concat(60+10*t,"%")}},t))});let et=(w.trim().length>0||R.length>0)&&!r;return(0,o.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},children:[(0,o.jsxs)("div",{ref:_,style:{flex:1,overflowY:"auto",paddingBottom:8,position:"relative"},children:[(0,o.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"4px 16px",gap:8},children:[j?(0,o.jsxs)("button",{onClick:j,"aria-label":"Back to conversations",style:{display:"flex",alignItems:"center",gap:4,padding:"4px 8px",borderRadius:6,border:"1px solid ".concat(i.rS.colors.borderLight),background:"transparent",color:i.rS.colors.textSecondary,fontSize:12,cursor:"pointer"},children:[(0,o.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,o.jsx)("polyline",{points:"15 18 9 12 15 6"})}),"Back"]}):(0,o.jsx)("span",{}),t.length>0&&(0,o.jsxs)("div",{style:{display:"flex",gap:4},children:[(0,o.jsx)("button",{onClick:()=>
1{if(0===t.length)return;let e=new Blob([t.map(e=>{let t="USER"===e.role?"**You**":"**Assistant**",r=new Date(e.createdAt).toLocaleString();return"### ".concat(t," — ").concat(r,"\n\n").concat(e.content,"\n")}).join("\n---\n\n")],{type:"text/markdown"}),r=URL.createObjectURL(e),o=document.createElement("a");o.href=r,o.download="chat-export-".concat(new Date().toISOString().slice(0,10),".md"),o.click(),URL.revokeObjectURL(r)},title:"Export as Markdown",style:{padding:"3px 8px",borderRadius:4,border:"1px solid ".concat(i.rS.colors.borderLight),background:"transparent",color:i.rS.colors.textMuted,fontSize:10,cursor:"pointer"},children:"Export"}),(0,o.jsx)("button",{onClick:Q,title:"Copy share link",style:{padding:"3px 8px",borderRadius:4,border:"1px solid ".concat(i.rS.colors.borderLight),background:"transparent",color:i.rS.colors.textMuted,fontSize:10,cursor:"pointer"},children:E?"Copied!":"Share"})]})]}),0===t.length?(0,o.jsxs)("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",gap:16,padding:20},children:[(0,o.jsx)("div",{style:{fontSize:13,color:i.rS.colors.textMuted,marginBottom:8},children:"Send a message to start"}),(0,o.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:8,justifyContent:"center",maxWidth:400},children:v.map(e=>(0,o.jsx)("button",{onClick:()=>{C(e),X()},style:{padding:"6px 12px",borderRadius:16,border:"1px solid ".concat(i.rS.colors.borderLight),background:i.rS.colors.bgSecondary,color:i.rS.colors.textSecondary,fontSize:12,cursor:"pointer",whiteSpace:"nowrap",transition:"background 0.15s"},onMouseEnter:e=>{e.currentTarget.style.background=i.rS.colors.primaryBg},onMouseLeave:e=>{e.currentTarget.style.background=i.rS.colors.bgSecondary},children:e},e))})]}):t.map((e,r)=>{let n=t[r-1],i=!n||new Date(e.createdAt).getTime()-new Date(n.createdAt).getTime()>3e5,a=e.content.startsWith("Error:"),s=e.content.startsWith("(No"),c="ASSISTANT"===e.role&&e.content&&!a&&!s,u=g&&d&&!l;return(0,o.jsxs)("div",{style:{position:"relative"},children:[(0,o.jsx)(f.Y,{message:e,showTimestamp:i}),(c||u)&&(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"USER"===e.role?"flex-end":"flex-start",gap:6,padding:"0 16px",marginTop:2},children:[c&&(0,o.jsxs)("div",{style:{display:"flex",gap:2},children:[(0,o.jsx)("button",{onClick:()=>W(t=>({...t,[e.id]:"up"===t[e.id]?null:"up"})),style:{padding:"2px 4px",borderRadius:4,border:"none",background:"transparent",cursor:"pointer",fontSize:12,opacity:"up"===B[e.id]?1:.4},title:"Helpful","aria-label":"Helpful",children:"\uD83D\uDC4D"}),(0,o.jsx)("button",{onClick:()=>W(t=>({...t,[e.id]:"down"===t[e.id]?null:"down"})),style:{padding:"2px 4px",borderRadius:4,border:"none",background:"transparent",cursor:"pointer",fontSize:12,opacity:"down"===B[e.id]?1:.4},title:"Not helpful","aria-label":"Not helpful",children:"\uD83D\uDC4E"})]}),u&&(0,o.jsx)(m,{onCopy:()=>{navigator.clipboard.writeText(e.content).catch(()=>{})},onDelete:()=>g(d,e.id)})]})]},e.id)}),(0,o.jsx)("div",{ref:U}),D&&(0,o.jsx)("button",{onClick:G,"aria-label":"Scroll to bottom",style:{position:"sticky",bottom:12,left:"50%",transform:"translateX(-50%)",width:36,height:36,borderRadius:"50%",border:"1px solid ".concat(i.rS.colors.borderLight),background:i.rS.colors.bgSecondary,boxShadow:i.rS.shadows.md,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:i.rS.colors.textSecondary,zIndex:10},children:(0,o.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,o.jsx)("polyline",{points:"6 9 12 15 18 9"})})})]}),a&&(0,o.jsx)("div",{style:{padding:"6px 16px",fontSize:12,color:i.rS.colors.error,background:i.rS.colors.errorBg,borderTop:"1px solid ".concat(i.rS.colors.borderLight)},children:a}),function(e){let{status:t,error:r,sending:o,streaming:n}=e;return!!t&&!r&&(o||n)}({status:s,error:a,sending:r,streaming:l})&&(0,o.jsxs)("div",{style:{padding:"6px 16px",fontSize:12,color:i.rS.colors.primary,background:i.rS.colors.primaryBg,borderTop:"1px solid ".concat(i.rS.colors.borderLight),display:"flex",alignItems:"center",gap:6},children:[(0,o.jsx)("span",{style:{display:"inline-block",width:10,height:10,borderRadius:i.rS.borderRadius.full,border:"2px s
1olid ".concat(i.rS.colors.primary),borderTopColor:"transparent",animation:"spin 0.8s linear infinite"}}),s]}),q.length>0&&!r&&!l&&(0,o.jsxs)("div",{style:{padding:"4px 16px 0",display:"flex",gap:6,flexWrap:"wrap"},children:[q.slice(0,3).map(e=>{let t=e;try{t=new URL(e).hostname}catch(e){}return(0,o.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,padding:"2px 8px",borderRadius:10,background:i.rS.colors.primaryBg,fontSize:11,color:i.rS.colors.primary,fontWeight:500},children:[(0,o.jsx)("span",{style:{opacity:.6},children:"\uD83D\uDD17"}),t]},e)}),q.length>3&&(0,o.jsxs)("span",{style:{fontSize:11,color:i.rS.colors.textMuted,padding:"2px 0"},children:["+",q.length-3," more"]})]}),R.length>0&&(0,o.jsx)("div",{style:{padding:"8px 16px",display:"flex",gap:8,flexWrap:"wrap",borderTop:"1px solid ".concat(i.rS.colors.borderLight),background:i.rS.colors.bgPrimary},children:R.map((e,t)=>(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"4px 10px",borderRadius:6,background:e.uploading?i.rS.colors.warningBg:i.rS.colors.primaryBg,fontSize:11,color:i.rS.colors.textSecondary},children:[e.uploading?"Uploading…":e.fileName,(0,o.jsx)("button",{onClick:()=>T(e=>e.filter((e,r)=>r!==t)),style:{border:"none",background:"transparent",cursor:"pointer",fontSize:14,color:i.rS.colors.textMuted,padding:0,lineHeight:1},children:"\xd7"})]},"".concat(e.r2Key,"-").concat(t)))}),P.length>0&&(0,o.jsxs)("div",{style:{padding:"8px 16px 4px",display:"flex",alignItems:"center"},children:[(0,o.jsx)("select",{"aria-label":"Chat model",disabled:O||l,value:null!=N?N:"",onChange:async e=>{let t=e.target.value;F(t),d&&await fetch("/api/chat/conversations/".concat(d),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({model:t})})},style:{padding:"4px 8px",borderRadius:6,border:"1px solid ".concat(i.rS.colors.borderLight),background:i.rS.colors.bgPrimary,color:i.rS.colors.textSecondary,fontSize:12,cursor:l?"not-allowed":"pointer"},children:P.map(e=>(0,o.jsx)("option",{value:e.id,children:e.label},e.id))}),(0,o.jsx)("a",{href:"/faq/ai-models",target:"_blank",rel:"noopener noreferrer",title:"Guide: which AI model to use for each task, and what each one costs",style:{marginLeft:12,fontSize:12,color:i.rS.colors.textSecondary,textDecoration:"none",whiteSpace:"nowrap",flexShrink:0},children:"Stuck choosing a model? ↗"})]}),(0,o.jsxs)("div",{style:{padding:"12px 16px",borderTop:"1px solid ".concat(i.rS.colors.borderLight),display:"flex",gap:8,alignItems:"flex-end"},children:[(0,o.jsx)("button",{onClick:()=>{var e;return null===(e=$.current)||void 0===e?void 0:e.click()},"aria-label":"Attach file",style:{width:32,height:32,borderRadius:i.rS.borderRadius.md,border:"1px solid ".concat(i.rS.colors.borderLight),background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:i.rS.colors.textSecondary,flexShrink:0},children:(0,o.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8","aria-hidden":"true",children:(0,o.jsx)("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}),(0,o.jsx)("input",{ref:$,type:"file",multiple:!0,onChange:ee,style:{display:"none"},accept:"image/*,.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt,.csv,.json,.zip,.rar"}),(0,o.jsxs)("div",{style:{flex:1,position:"relative"},children:[(0,o.jsx)("textarea",{ref:V,value:w,onChange:e=>C((0,x.sv)(e.target.value)),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||e.ctrlKey||e.metaKey||(e.preventDefault(),X())},placeholder:"Type a message…",name:"chat-input",rows:2,style:{width:"100%",padding:"10px 12px",borderRadius:i.rS.borderRadius.lg,border:"1px solid ".concat(i.rS.colors.borderLight),fontSize:13,outline:"none",resize:"none",overflowY:"auto",fontFamily:"inherit",boxSizing:"border-box",lineHeight:1.5}}),w.length>300&&(0,o.jsxs)("button",{onClick:()=>z(!L),style:{position:"absolute",bottom:6,right:6,display:"flex",alignItems:"center",gap:4,padding:"2px 8px",borderRadius:6,border:"1px solid ".concat(i.rS.colors.borderLight),background:i.rS.colors.bgPrimary,cursor:"pointer",fontSize:10,
1color:i.rS.colors.textMuted},title:L?"Collapse":"Expand",children:[L?(0,o.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,o.jsx)("polyline",{points:"18 15 12 9 6 15"})}):(0,o.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,o.jsx)("polyline",{points:"6 9 12 15 18 9"})}),L?"Collapse":"Expand"]})]}),t.length>0&&!l&&!r&&(0,o.jsx)("button",{onClick:Z,"aria-label":"Regenerate last response",title:"Regenerate",style:{width:32,height:32,borderRadius:i.rS.borderRadius.md,border:"1px solid ".concat(i.rS.colors.borderLight),background:"transparent",color:i.rS.colors.textMuted,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:(0,o.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,o.jsx)("polyline",{points:"1 4 1 10 7 10"}),(0,o.jsx)("path",{d:"M3.51 15a9 9 0 1 0 2.13-9.36L1 10"})]})}),l?(0,o.jsx)("button",{onClick:u,"aria-label":"Stop generating",style:{padding:"8px 14px",borderRadius:i.rS.borderRadius.md,border:"1px solid ".concat(i.rS.colors.borderLight),background:i.rS.colors.bgPrimary,fontSize:13,fontWeight:500,color:i.rS.colors.textPrimary,cursor:"pointer",flexShrink:0},children:"Stop"}):(0,o.jsx)("button",{onClick:X,disabled:!et,"aria-label":"Send message",style:{padding:"8px 14px",borderRadius:i.rS.borderRadius.md,border:"none",background:et?i.rS.gradients.primary:i.rS.colors.borderLight,color:"white",fontSize:13,fontWeight:500,cursor:et?"pointer":"not-allowed",flexShrink:0},children:"Send"})]}),(0,o.jsx)("div",{style:{padding:"4px 16px 8px",fontSize:10,color:i.rS.colors.textMuted,userSelect:"none"},children:"Enter to send \xb7 Shift+Enter for newline"})]})}function j(){let[e,t]=(0,n.useState)(null),[r,l]=(0,n.useState)(null),[a,u]=(0,n.use
1State)("conversations"),[g,x]=(0,n.useState)(!1),[f,y]=(0,n.useState)(!1),[m,S]=(0,n.useState)(!1),[b,v]=(0,n.useState)(!1),{folders:j,loading:w,error:C,createFolder:R,updateFolder:T,deleteFolder:L,fetchFolders:z}=function(){let[e,t]=(0,n.useState)([]),[r,o]=(0,n.useState)(!0),[i,l]=(0,n.useState)(null),[a,d]=(0,n.useState)(0),[c,u]=(0,n.useState)(1),[p,h]=(0,n.useState)(1),g=(0,n.useCallback)(async()=>{o(!0),l(null);try{let o=new URLSearchParams;o.set("page",String(c)),o.set("limit","50");let n=await fetch("/api/chat/folders?".concat(o));if(n.ok){var e,r;let o=await n.json();t(o.data||[]),d((null===(e=o.pagination)||void 0===e?void 0:e.total)||0),h((null===(r=o.pagination)||void 0===r?void 0:r.totalPages)||1)}else{let e=await n.json().catch(()=>({}));l(e.error||"Failed to load folders")}}catch(e){console.error("Failed to fetch folders:",e),l("Failed to load folders")}finally{o(!1)}},[c]);(0,n.useEffect)(()=>{g()},[g]);let x=(0,n.useRef)(0);return(0,n.useEffect)(()=>s.onMessage(e=>{if((null==e?void 0:e.type)==="message-sent"||(null==e?void 0:e.type)==="folder-created"||(null==e?void 0:e.type)==="folder-deleted"){let e=Date.now();e-x.current<300||(x.current=e,g())}}),[g]),{folders:e,loading:r,error:i,total:a,page:c,totalPages:p,setPage:u,fetchFolders:g,createFolder:(0,n.useCallback)(async e=>{let r=await fetch("/api/chat/folders",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(r.ok){let e=await r.json();return t(t=>[e.data,...t]),s.postMessage({type:"folder-created"}),e.data}throw Error("Failed to create folder")},[]),updateFolder:(0,n.useCallback)(async(e,r)=>{let o=await fetch("/api/chat/folders/".concat(e),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(o.ok){let r=await o.json();return t(t=>t.map(t=>t.id===e?{...t,...r.data}:t)),r.data}throw Error("Failed to update folder")},[]),deleteFolder:(0,n.useCallback)(async e=>{if((await fetch("/api/chat/folders/".concat(e),{method:"DELETE"})).ok)t(t=>t.filter(t=>t.id!==e)),s.postMessage({type:"folder-deleted"});else throw Error("Failed to delete folder")},[])}}(),{conversations:D,loading:I,error:E,hasMore:M,loadMore:B,createConversation:W,deleteConversation:P,updateConversation:A,fetchConversations:N,searchQuery:F,setSearchQuery:O}=function(e){let[t,r]=(0,n.useState)([]),[o,i]=(0,n.useState)(!0),[l,a]=(0,n.useState)(null),[s,c]=(0,n.useState)(0),[u,p]=(0,n.useState)(1),[h,g]=(0,n.useState)(""),x=(0,n.useRef)(0),f=(0,n.useCallback)(async function(t){let o=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=null!=t?t:u;i(!0),a(null);try{let t=new URLSearchParams;null!==e&&t.set("folderId",e),h&&t.set("search",h),t.set("page",String(n)),t.set("limit","50");let i=await fetch("/api/chat/conversations?".concat(t));if(i.ok){var l;let e=await i.json();r(t=>o?[...t,...e.data||[]]:e.data||[]),c((null===(l=e.pagination)||void 0===l?void 0:l.total)||0),p(n)}else{let e=await i.json().catch(()=>({}));a(e.error||"Failed to load conversations")}}catch(e){console.error("Failed to fetch conversations:",e),a("Failed to load conversations")}finally{i(!1)}},[e,u,h]);(0,n.useEffect)(()=>d.onMessage(e=>{if((null==e?void 0:e.type)==="message-sent"||(null==e?void 0:e.type)==="conversation-created"){let e=Date.now();e-x.current<300||(x.current=e,f())}}),[f]),(0,n.useEffect)(()=>{p(1),f(1)},[e]),(0,n.useEffect)(()=>{p(1),f(1)},[h]);let y=(0,n.useCallback)(async e=>{let t=await fetch("/api/chat/conversations",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e||{})});if(t.ok){let e=await t.json();return r(t=>[e.data,...t]),e.data}throw Error("Failed to create conversation")},[]),m=(0,n.useCallback)(async(e,t)=>{let o=await fetch("/api/chat/conversations/".concat(e),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(o.ok){let t=await o.json();return r(r=>r.map(r=>r.id===e?{...r,...t.data}:r)),t.data}throw Error("Failed to update conversation")},[]),S=(0,n.useCallback)(async e=>{if((await fetch("/api/chat/conversations/".concat(e),{method:"DELETE"})).ok)r(t=>t.filter(t=>t.id!==e));else throw Error("Failed to delete conversation")},[]),b=t.length<s,v=(0,n.useCallback)(()=>{b&&!o&&f(u+1,!0)},[b,o,u,f]);return{conversations:t,loading:o,error:l,total:s,page:u,hasMore:b,loadMore:v,setPage:p,fetchConversations:f,createConversation:y,updateConversation:m,deleteConversation:S,searchQuery:h,setSearchQuery:g}}(e),{messages:K,sending:H,streaming:U,error:_,status:V,sendMessage:$,stopStreaming:J,loadMessages:q,clearMessages:Y,deleteMessage:G}
1=function(){let[e,t]=(0,n.useState)([]),[r,o]=(0,n.useState)(!1),[i,l]=(0,n.useState)(!1),[a,s]=(0,n.useState)(null),[d,u]=(0,n.useState)(null),p=(0,n.useRef)(null),h=(0,n.useRef)(!1),g=(0,n.useCallback)(async e=>{try{let o=await fetch("/api/chat/conversations/".concat(e));if(o.ok){var r;let e=await o.json();t((null===(r=e.data)||void 0===r?void 0:r.messages)||[])}}catch(e){console.error("Failed to load messages:",e)}},[]),x=(0,n.useCallback)(()=>{t([]),s(null)},[]),f=(0,n.useCallback)(async function(e,r){var n,i;let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];o(!0),l(!1),s(null),u(null);let d={id:"temp-".concat(Date.now()),role:"USER",content:r,inputTokens:null,outputTokens:null,model:null,createdAt:new Date().toISOString(),attachments:a.map((e,t)=>({id:"temp-att-".concat(Date.now(),"-").concat(t),fileName:e.fileName,mimeType:e.mimeType,fileSize:e.fileSize}))},g={id:"temp-assistant-".concat(Date.now()),role:"ASSISTANT",content:"",inputTokens:null,outputTokens:null,model:null,createdAt:new Date().toISOString()};t(e=>[...e,d,g]);let x=new AbortController;p.current=x,h.current=!1;let f=setTimeout(()=>{h.current=!0,x.abort()},82e4),y=e,m=crypto.randomUUID();try{let i=await fetch("/api/chat/send",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({conversationId:e,message:r,messageKey:m,attachmentR2Keys:a.map(e=>({r2Key:e.r2Key,fileName:e.fileName,mimeType:e.mimeType,fileSize:e.fileSize}))}),signal:x.signal});if(clearTimeout(f),!i.ok){let e=await i.json().catch(()=>({error:"Request failed"}));throw Error(e.error||"Request failed")}o(!1),l(!0);let d=null===(n=i.body)||void 0===n?void 0:n.getReader();if(!d)throw Error("No response body");let p=new TextDecoder,h="",S="";for(;;){let{done:e,value:r}=await d.read();if(e)break;let o=(h+=p.decode(r,{stream:!0})).split("\n");for(let e of(h=o.pop()||"",o)){if(!e.startsWith("data: "))continue;let r=e.slice(6);try{let e=JSON.parse(r);if("text"===e.type)S+=e.text,t(e=>{let t=[...e],r=t[t.length-1];return(null==r?void 0:r.role)==="ASSISTANT"&&r.id===g.id&&(t[t.length-1]={...r,content:S}),t});else if("status"===e.type)u(e.status||null);else if("done"===e.type)return y=e.conversationId||y,t(t=>{let r=[...t],o=r[r.length-1];if((null==o?void 0:o.role)==="ASSISTANT"&&o.id===g.id){var n;r[r.length-1]={...o,inputTokens:e.inputTokens,outputTokens:e.outputTokens,model:e.model,attachments:(null===(n=e.attachments)||void 0===n?void 0:n.length)?e.attachments:o.attachments}}return r}),l(!1),c.postMessage({type:"message-sent",conversationId:y}),y||"";else if("error"===e.type)return s(e.error),l(!1),c.postMessage({type:"message-sent",conversationId:y}),y||""}catch(e){console.warn("[chat] dropped unparseable SSE frame:",null==e?void 0:e.message,"\xb7",r.slice(0,120))}}}return t(e=>{let t=[...e],r=t[t.length-1];return(null==r?void 0:r.role)!=="ASSISTANT"||r.id!==g.id||r.content||(t[t.length-1]={...r,content:"(No response)"}),t}),l(!1),y||""}catch(d){if(clearTimeout(f),"AbortError"===d.name){if(h.current){let r="Request timed out — try sending fewer or smaller files in one message.";return s(r),t(e=>{let t=[...e],o=t[t.length-1];return(null==o?void 0:o.role)==="ASSISTANT"&&o.id===g.id&&(t[t.length-1]={...o,content:"Error: ".concat(r)}),t}),o(!1),l(!1),e||""}return l(!1),e||""}if(!h.current&&!d.__retried){d.__retried=!0,u("Connection lost, retrying…");try{let o=await fetch("/api/chat/send",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({conversationId:e,message:r,messageKey:m,attachmentR2Keys:a.map(e=>({r2Key:e.r2Key,fileName:e.fileName,mimeType:e.mimeType,fileSize:e.fileSize}))})});if(o.ok){u(null);let e=null===(i=o.body)||void 0===i?void 0:i.getReader();if(!e)throw Error("No response body");let r=new TextDecoder,n="",a="";for(;;){let{done:o,value:i}=await e.read();if(o)break;let s=(n+=r.decode(i,{stream:!0})).split("\n");for(let e of(n=s.pop()||"",s))if(e.startsWith("data: "))try{let r=JSON.parse(e.slice(6));if("text"===r.type)a+=r.text,t(e=>{let t=[...e],r=t[t.length-1];return(null==r?void 0:r.role)==="ASSISTANT"&&r.id===g.id&&(t[t.length-1]={...r,content:a}),t});else if("done"===r.type)return t(e=>{let t=[...e],o=t[t.length-1];if((null==o?void 0:o.role)==="ASSISTANT"&&o.id===g.id){var n;t[t.length-1]={...o,inputTokens:r.inputTokens,outputTokens:r.outputTokens,model:r.model,attachments:(null===(n=r.attachments)||void 0===n?void 0:n.length)?r.attachments:o.attachments}}return t}),l(!1),c.postMessage({type:"message-sent",conversationId:y}),y||"";else if("error"===r.type)throw Error(r.error)}catch(e){}}return l(!1),y||""}}catch(e){}}let n=d.message||"Failed to send message";return s(n),t(e=>{let t=[...e],r=t[t.length-1];return(null==r?void 0:r.role)==="ASSISTANT"&&r.id===g.id&&(t[t.length-1]={...r,content:"Error: ".concat(n)}),t}),o(!1),l(!1),e||""}},[]),y=(0,n.useCallback)(()=>{var e;null===(e=p.current)||void 0===e||e.abort(),l(!1),o(!1)},[]),m=(0,n.useCallback)(async(r,o)=>{let n=e.find(e=>e.id===o);t(e=>e.filter(e=>e.id!==o));try{await fetch("/api/chat/conversations/".concat(r,"/messages/").concat(o),{method:"DELETE"})}catch(e){console.error("Failed to delete message:",e),n&&t(e=>{let t=[...e,n];return t.sort((e,t)=>
1new Date(e.createdAt).getTime()-new Date(t.createdAt).getTime()),t})}},[e]);return{messages:e,sending:r,streaming:i,error:a,status:d,sendMessage:f,stopStreaming:y,loadMessages:g,clearMessages:x,deleteMessage:m}}();(0,n.useEffect)(()=>{let e=()=>x(window.innerWidth<768);return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),(0,n.useEffect)(()=>{r?(y(!0),q(r).finally(()=>y(!1))):Y()},[r]);let X=(0,n.useCallback)(e=>{l(e),g&&u("chat")},[g]),Z=(0,n.useCallback)(async()=>await W({folderId:e}),[W,e]),Q=(0,n.useCallback)(async e=>{await P(e),r===e&&(l(null),Y()),N()},[P,r,Y,N]),ee=(0,n.useCallback)(async(e,t,r)=>{let o=await $(e,t,r);return o&&(l(o),N()),z(),o},[$,N,z]),et=(0,n.useCallback)(async()=>{l((await Z()).id),g&&u("chat")},[Z,g]),er=(0,n.useCallback)(async e=>{O(e)},[O]);return g?(0,o.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,o.jsxs)("div",{style:{display:"flex",borderBottom:"1px solid ".concat(i.rS.colors.borderLight),background:i.rS.colors.bgSecondary},children:[(0,o.jsx)("button",{onClick:()=>u("folders"),style:{flex:1,padding:"10px 8px",border:"none",background:"folders"===a?i.rS.colors.primaryBg:"transparent",color:"folders"===a?i.rS.colors.primary:i.rS.colors.textSecondary,fontSize:12,fontWeight:"folders"===a?600:400,cursor:"pointer",borderBottom:"folders"===a?"2px solid ".concat(i.rS.colors.primary):"2px solid transparent"},children:"Folders"}),(0,o.jsx)("button",{onClick:()=>u("conversations"),style:{flex:1,padding:"10px 8px",border:"none",background:"conversations"===a?i.rS.colors.primaryBg:"transparent",color:"conversations"===a?i.rS.colors.primary:i.rS.colors.textSecondary,fontSize:12,fontWeight:"conversations"===a?600:400,cursor:"pointer",borderBottom:"conversations"===a?"2px solid ".concat(i.rS.colors.primary):"2px solid transparent"},children:"Chats"}),(0,o.jsx)("button",{onClick:()=>u("chat"),style:{flex:1,padding:"10px 8px",border:"none",background:"chat"===a?i.rS.colors.primaryBg:"transparent",color:"chat"===a?i.rS.colors.primary:i.rS.colors.textSecondary,fontSize:12,fontWeight:"chat"===a?600:400,cursor:"pointer",borderBottom:"chat"===a?"2px solid ".concat(i.rS.colors.primary):"2px solid transparent",opacity:r?1:.5},disabled:!r,children:"Chat"})]}),(0,o.jsxs)("div",{style:{flex:1,overflow:"hidden"},children:["folders"===a&&(0,o.jsx)(p,{folders:j,loading:w,error:C,onRetry:z,selectedFolderId:e,onSelectFolder:e=>{t(e),u("conversations")},onCreateFolder:R,onUpdateFolder:T,onDeleteFolder:L}),"conversations"===a&&(0,o.jsx)(h,{conversations:D,loading:I,error:E,onRetry:N,hasMore:M,loadMore:B,activeConversationId:r,onSelectConversation:X,onCreateConversation:Z,onDeleteConversation:Q,onSearchServerSide:er,serverSearchCount:null}),"chat"===a&&(0,o.jsx)(k,{messages:K,sending:H,streaming:U,error:_,status:V,activeConversationId:r,onSendMessage:ee,onStopStreaming:J,onCreateChat:et,onConversationIdChange:l,onBack:()=>u("conversations")})]})]}):(0,o.jsxs)("div",{style:{display:"flex",height:"100%",overflow:"hidden"},children:[(0,o.jsx)(p,{folders:j,loading:w,error:C,onRetry:z,selectedFolderId:e,onSelectFolder:t,onCreateFolder:R,onUpdateFolder:T,onDeleteFolder:L,collapsed:m,onToggleCollapse:()=>S(!m),onDropConversation:async(e,t)=>{await A(t,{folderId:e}),N()}}),(0,o.jsx)(h,{conversations:D,loading:I,error:E,onRetry:N,hasMore:M,loadMore:B,activeConversationId:r,onSelectConversation:X,onCreateConversation:Z,onDeleteConversation:Q,onRenameConversation:async(e,t)=>{await A(e,{title:t})},collapsed:b,onToggleCollapse:()=>v(!b),onDragConversation:()=>{},onTogglePin:async(e,t)=>{await A(e,{isPinned:t})},onSearchServerSide:er,serverSearchCount:null}),(0,o.jsx)(k,{messages:K,sending:H,streaming:U,error:_,status:V,activeConversationId:r,onSendMessage:ee,onStopStreaming:J,onCreateChat:et,onConversationIdChange:l,onDeleteMessage:(e,t)=>G(e,t)})]})}},94654:function(e,t,r){r.d(t,{Y:function(){return p}});var o=r(27573),n=r(7653),i=r(28764);function l(e){return e<1024?"".concat(e,"B"):e<1048576?"".concat((e/1024).toFixed(1),"KB"):"".concat((e/1048576).toFixed(1),"MB")}function a(e){var t,r,a,s;let{attachment:d}
1=e,[c,u]=(0,n.useState)(!1),p=(t=d.fileName).includes("_screenshot")||t.startsWith("Screenshot"),h=(r=d.fileName).endsWith("_screenshot.png")?r.replace(/_screenshot\.png$/,""):r;return(a=d.mimeType).startsWith("image/")&&!a.includes("svg")&&d.url?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("div",{onClick:()=>u(!0),style:{cursor:"pointer",borderRadius:i.rS.borderRadius.md,overflow:"hidden",maxWidth:280,border:"1px solid ".concat(i.rS.colors.borderLight)},children:[(0,o.jsx)("img",{src:d.url,alt:h,width:280,height:200,style:{width:"100%",height:"auto",display:"block",maxHeight:200,objectFit:"cover"}}),(0,o.jsxs)("div",{style:{padding:"4px 8px",fontSize:11,color:i.rS.colors.textMuted,background:i.rS.colors.bgPrimary,borderTop:"1px solid ".concat(i.rS.colors.borderLight),display:"flex",alignItems:"center",gap:4},children:[p&&(0,o.jsxs)("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[(0,o.jsx)("path",{d:"M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"}),(0,o.jsx)("circle",{cx:"12",cy:"13",r:"4"})]}),p?"Scraped ".concat(h):h,!p&&" \xb7 ".concat(l(Number(d.fileSize)))]})]}),c&&(0,o.jsx)("div",{onClick:()=>u(!1),style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.8)",zIndex:9999,display:"flex",alignItems:"center",justifyContent:"center",cursor:"zoom-out"},children:(0,o.jsx)("img",{src:d.url,alt:h,width:1440,height:900,style:{maxWidth:"90vw",maxHeight:"90vh",borderRadius:i.rS.borderRadius.md},onClick:e=>e.stopPropagation()})})]}):(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 12px",borderRadius:i.rS.borderRadius.md,background:i.rS.colors.bgPrimary,border:"1px solid ".concat(i.rS.colors.borderLight),maxWidth:300,cursor:d.url?"pointer":"default"},onClick:()=>{d.url&&window.open(d.url,"_blank")},children:[(0,o.jsx)("div",{style:{width:36,height:36,borderRadius:6,background:i.rS.colors.primaryBg,display:"flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:700,color:i.rS.colors.primary,flexShrink:0},children:("application/pdf"===(s=d.mimeType)?"PDF":s.includes("word")||s.includes("document")?"DOC":s.includes("spreadsheet")||s.includes("excel")?"XLS":s.includes("presentation")||s.includes("powerpoint")?"PPT":s.startsWith("text/")?"TXT":"")||(0,o.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2","aria-hidden":"true",children:[(0,o.jsx)("path",{d:"M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"}),(0,o.jsx)("polyline",{points:"13 2 13 9 20 9"})]})}),(0,o.jsxs)("div",{style:{minWidth:0},children:[(0,o.jsx)("div",{style:{fontSize:12,fontWeight:500,color:i.rS.colors.textPrimary,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:p?"Scraped ".concat(h):h}),(0,o.jsx)("div",{style:{fontSize:11,color:i.rS.colors.textMuted},children:l(Number(d.fileSize))})]})]})}let s={"deepseek-v4-pro":"DeepSeek V4 Pro","claude-sonnet-4-6":"Claude Sonnet 4.6","claude-sonnet-5":"Claude Sonnet 5","claude-sonnet-4-5":"Claude Sonnet 4.5","claude-sonnet-4-5-20250929":"Claude Sonnet 4.5","claude-haiku-4-5-20251001":"Claude Haiku 4.5","claude-opus-4-8":"Claude Opus 4.8","kimi-k2.6":"Kimi K2.6","kimi-k2-7":"Kimi K2.6","kimi-k3":"Kimi K3","kimi-k2.7-code":"Kimi K2.7 Code","deepseek-flash":"DeepSeek V4.1 Flash","claude-sonnet-5-5":"Claude Sonnet 5.5","claude-opus-5-5":"Claude Opus 5.5","glm-5.3":"GLM 5.3","glm-5.3-flash":"GLM 5.3 Flash"};function d(e){var t;if(!e)return null;let r=e.trim();return r&&"unknown"!==r?null!==(t=s[r])&&void 0!==t?t:r:null}function c(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function u(){return(0,o.jsxs)("span",{style:{display:"inline-flex",gap:3,alignItems:"center",padding:"2px 0"},children:[(0,o.jsx)("style",{children:"@keyframes dotPulse{0%,80%,100%{opacity:0.2;transform:scale(0.8)}40%{opacity:1;transform:scale(1)}}"}),[0,1,2].map(e=>(0,o.jsx)("span",{style:{width:6,height:6,borderRadius:"50%",background:i.rS.colors.primary,animation:"dotPulse 1.2s ease-in-out ".concat(.2*e,"s infinite")}},e))]})}let p=n.memo(function(e){let{message:t,showTimestamp:r=!0}=e,l="USER"===t.role,s="ASSISTANT"===t.role&&!t.content,p=t.content.startsWith("Error:"),h="ASSISTANT"===t.role&&"(No response)"===t.content,g=(0,n.useRef)(null),x=(0,n.useMemo)(()=>s?"":l?t.content.replace(/\n/g,"<br/>"):function(e,t,r){let o=c(e),n=[];return(o=(o=(o=(o=(o=(o=(o=(o=(o=(o=(o=(o=o.replace(/```(\w*)\n([\s\S]*?)```/g,(e,r,o)=>{let i=n.length;return n.push('<div style="position:relative;margin:8px 0;"><pre style="background:'.concat(t,';border-radius:8px;padding:12px 40px 12px 16px;overflow-x:auto;font-size:12px;line-height:1.5;margin:0;"><code>').concat(o,'</code></pre><button data-code="').concat(o.replace(/"/g,"&quot;"),'" style="position:absolute;top:8px;right:8px;padding:2px 8px;border-radius:4px;border:none;background:rgba(255,255,255,0.1);color:inherit;font-size:10px;cursor:pointer;opacity:0.7">Copy</button></div>')),"\0CODEBLOCK".concat(i,"\0")})).replace(/`([^`]+)`/g,'<code style="background:'.concat(r,';padding:1px 5px;border-radius:4px;font-size:12.5px;">$1</code>'))).replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>")).replace(/\*(.+?)\*/g,"<em>$1</em>")).replace(/^### (.+)$/gm,'<h3 style="font-size:14px;font-weight:600;margin:12px 0 4px;">$1</h3>')).replace(/^## (.+)$/gm,'<h2 style="font-size:15px;font-weight:600;margin:14px 0 6px;">$1</h2>')).replace(/^# (.+)$/gm,'<h1 style="font-size:16px;font-weight:600;margin:16px 0 8px;">$1</h1>')).replace(/^&gt; (.+)$/gm,'<blockquote style="border-left:3px solid rgba(155,109,163,0.5);margin:8px 0;padding:4px 0 4px 12px;opacity:0.85;">$1</blockquote>')).replace(/((?:^- .+\n)+)/gm,e=>{let t=e.trim().split("\n").map(e=>e.replace(/^- (.+)$/,'<li style="margin-left:16px;">$1</li>')).join("");return'<ul style="padding-left:20px;margin:4px 0;">'.concat(t,"</ul>")})).replace(/((?:^\d+\. .+\n)+)/gm,e=>{let t=e.trim().split("\n").map(e=>e.replace(/^\d+\. (.+)$/,'<li style="margin-left:16px;">$1</li>')).join("");return'<ol style="padding-left:20px;margin:4px 0;">'.concat(t,"</ol>")})).replace(/\n/g,"<br/>")).replace(/(https?:\/\/[^\s<>"']+)/g,e=>{let t=function(e){try{let t=new URL(e);if("http:"!==t.protocol&&"https:"!==t.protocol)return null;return t.href}catch(e){return null}}(e);return t?'<a href="'.concat(c(t),'" target="_blank" rel="noopener noreferrer" style="color:var(--link, #76527c);text-decoration:underline;">').concat(c(e),"</a>"):c(e)})).replace(/\x00CODEBLOCK(\d+)\x00/g,(e,t)=>n[parseInt(t,10)]||"")}(t.content,i.rS.colors.bgTertiary,i.rS.colors.primaryBg),[l,s,t.content]);return(0,n.useEffect)(()=>{let e=g.current;if(!e)return;let t=e.querySelectorAll("button[data-code]");if(0===t.length)return;let r=new Map;
1return t.forEach(e=>{let t=async()=>{let t=e.getAttribute("data-code")||"";try{await navigator.clipboard.writeText(t);let r=e.textContent;e.textContent="Copied!",setTimeout(()=>{e&&(e.textContent=r||"Copy")},1500)}catch(e){}};e.addEventListener("click",t),r.set(e,t)}),()=>{r.forEach((e,t)=>t.removeEventListener("click",e))}},[x]),(0,o.jsxs)("div",{style:{display:"flex",flexDirection:"column",alignItems:l?"flex-end":"flex-start",padding:"4px 16px"},children:[(0,o.jsxs)("div",{style:{maxWidth:"85%",padding:"10px 14px",borderRadius:i.rS.borderRadius.lg,background:l?i.rS.colors.primaryBg:p?i.rS.colors.errorBg:i.rS.colors.bgPrimary,border:l?"none":"1px solid ".concat(i.rS.colors.borderLight),fontSize:13,lineHeight:1.6,color:p?i.rS.colors.error:h?i.rS.colors.textMuted:i.rS.colors.textPrimary,position:"relative"},children:[s?(0,o.jsx)(u,{}):(0,o.jsx)("div",{ref:g,dangerouslySetInnerHTML:{__html:x}}),t.attachments&&t.attachments.length>0&&(0,o.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8,marginTop:8},children:t.attachments.map(e=>(0,o.jsx)(a,{attachment:e},e.id))})]}),(r||!l&&d(t.model))&&(0,o.jsx)("div",{style:{fontSize:10.5,color:i.rS.colors.textMuted,marginTop:2,padding:"0 4px"},children:[r?new Date(t.createdAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):null,l?null:d(t.model)].filter(Boolean).join(" \xb7 ")})]})})}}]);

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.