PageSourceSearch

https://repsshield.com/assets/CostSegEstimatorChatPage-DVRrvdxT.js

js repsshield.com collected 2026-10-02 02:01:08 UTC 15,799 bytes, 14 lines download raw bytes

1import{z as Y,j as e,cZ as ae,aF as ne,B as oe,cV as le,aL as $,c_ as ie,M as ce,bo as de,p as ue,cv as fe}from"./index-DGo-vssZ.js";import{r as t,L as U}from"./vendor-Qgthw7N1.js";/**
2 * @license lucide-react v0.453.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const me=Y("PanelLeftClose",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m16 15-3-3 3-3",key:"14y99z"}]]);/**
7 * @license lucide-react v0.453.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const pe=Y("PanelLeft",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]]),he=new Set(["showAddressInput","showPreviewCard","showEmailGate","showFullEstimate"]);function xe(a={}){const{initialMessages:d=[],autoStart:r=!0,onMessagesChange:m}=a,u=t.useRef(!1),i=t.useRef(new Map),o=t.useRef(!1),x=t.useRef(m),[h,f]=t.useState(d),s=t.useRef([]);s.current=h;const[c,p]=t.useState(!1),[y,b]=t.useState(!1),[E,g]=t.useState(),[j,w]=t.useState(null),[z,v]=t.useState(null);t.useEffect(()=>{x.current=m},[m]),t.useEffect(()=>{var T;(T=x.current)==null||T.call(x,h)},[h]);const N=t.useCallback(async T=>{var L;if(o.current)return;o.current=!0,i.current.clear();const D=T.trim()?{id:`user-${Date.now()}`,role:"user",parts:[{type:"text",text:T}]}:null,A=D?[...s.current,D]:s.current;D&&f(A),p(!0),b(!0),g(void 0),w("streaming"),v("Thinking…");const I=`assistant-${Date.now()}`,B={id:I,role:"assistant",parts:[],metadata:{status:"streaming"}};f(C=>[...C,B]);try{const C=localStorage.getItem("accessToken"),n={"Content-Type":"application/json"};C&&(n.Authorization=`Bearer ${C}`);const K=new AbortController,Z=setTimeout(()=>K.abort(),12e4);let O;try{O=await fetch("/api/tools/cost-seg/chat",{method:"POST",credentials:"include",headers:n,signal:K.signal,body:JSON.stringify({messages:A})})}finally{clearTimeout(Z)}if(!O.ok)throw new Error(`HTTP error: ${O.status}`);const V=(L=O.body)==null?void 0:L.getReader();if(!V)throw new Error("No response body");const Q=new TextDecoder;let F="",J="";for(;;){const{done:ee,value:te}=await V.read();if(ee)break;F+=Q.decode(te,{stream:!0});const G=F.split(`
12
13`);F=G.pop()??"";for(const se of G){const re=se.split(`
14`);for(const H of re)if(H.startsWith("data: "))try{const l=JSON.parse(H.slice(6));if(l.type==="text")J+=l.content,w(null),v(null),f(M=>M.map(k=>{if(k.id!==I)return k;const S=k.parts.filter(P=>P.type!=="text");return{...k,parts:[...S,{type:"text",text:J}]}}));else if(l.type==="tool-call")if(w("tool-call"),v(l.toolName),l.actualToolName&&he.has(l.actualToolName)){const M={type:`tool-${l.actualToolName}`,toolCallId:l.toolCallId,input:l.input,state:"output-available"};f(k=>k.map(S=>S.id===I?{...S,parts:[...S.parts,M]}:S))}else l.toolCallId&&i.current.set(l.toolCallId,l.input);else if(l.type==="tool-result"){l.toolName==="lookupProperty"?(w("streaming"),v("Preparing savings estimate…")):l.toolName==="captureEmail"&&(w("streaming"),v("Preparing full estimate…"));const M=i.current.get(l.toolCallId);i.current.delete(l.toolCallId);const k={type:`tool-${l.toolName}`,toolCallId:l.toolCallId,input:M,output:l.output,state:"output-available"};f(S=>S.map(P=>P.id===I?{...P,parts:[...P.parts,k]}:P))}else if(l.type==="status")w(l.status),v(l.label);else if(l.type==="done"){w(null),v(null);const M=new Date().toISOString();f(k=>k.map(S=>S.id===I?{...S,metadata:{...S.metadata??{},provider:l.provider,model:l.model,status:"done",completedAt:M}}:S))}else l.type==="error"&&g(l.error)}catch(l){console.error("[CostSeg] Failed to parse SSE data:",l)}}}}catch(C){console.error("[CostSeg] Stream error:",C),g(C instanceof Error?C.message:"Stream failed")}finally{o.current=!1,p(!1),b(!1),w(null),v(null)}},[]);t.useEffect(()=>{if(r&&!u.current){if(s.current.length>0){u.current=!0;return}u.current=!0,N("")}},[r,N]);function R(){o.current=!1,f([]),g(void 0),u.current=!1}return{messages:h,send:N,clearMessages:R,setMessages:f,isLoading:c,isStreaming:y,error:E,pipelineStatus:j,pipelineStatusLabel:z}}function ge({message:a,onAddressSubmit:d,onViewFullEstimate:r,onEmailSubmit:m,isAuthenticated:u=!1,autoSubmitAddress:i}){return a.role==="user"?e.jsx("div",{className:"flex justify-end mb-3",children:e.jsx("div",{className:"bg-gray-100 rounded-2xl rounded-tr-sm px-4 py-2 max-w-xs text-sm text-gray-800",children:a.parts.map(o=>o.type==="text"?e.jsx("span",{children:o.text},`${a.id}-user-text`):null)})}):e.jsx("div",{className:"flex flex-col gap-3 mb-3",children:a.parts.map((o,x)=>{const h=o.type,f=`${a.id}-${h}-${x}`;if(h==="text"){const s=o.text;return s!=null&&s.trim()?e.jsx("div",{className:"text-sm text-gray-800 whitespace-pre-wrap leading-relaxed",children:s},f):null}return h==="tool-showAddressInput"||h==="tool-showPreviewCard"||h==="tool-showEmailGate"||h==="tool-showFullEstimate"?e.jsx(ae,{type:h,input:o.input??{},onAddressSubmit:d,onViewFullEstimate:r,onEmailSubmit:m,isAuthenticated:u,autoSubmitAddress:i},f):null})})}function ye({isAuthenticated:a=!1,initialMessages:d=[],initialAddress:r,onMessagesChange:m,onAddressSubmitted:u,showComposer:i=!1}){const o=(r==null?void 0:r.trim())||"",x=o.length>0&&d.length===0,{messages:h,send:f,isLoading:s,isStreaming:c,error:p,pipelineStatusLabel:y}=xe({initialMessages:d,autoStart:!x,onMessagesChange:m}),b=t.useRef(null),E=t.useRef(null),g=t.useRef(!1),[j,w]=t.useState(""),[z]=t.useState(null),v=h.length,N=s||c;t.useEffect(()=>{if(v===0&&!c)return;const n=b.current;n&&n.scrollTo({top:n.scrollHeight,behavior:c?"auto":"smooth"})},[v,c]);const R=t.useCallback(n=>{u==null||u(n),f(n)},[f,u]);t.useEffect(()=>{x&&(g.current||(g.current=!0,R(o)))},[x,o,R]);const T=t.useCallback(()=>{f("view full estimate")},[f]),D=t.useCallback(n=>{f(n)},[f]),A=t.useCallback(()=>{const n=E.current;n&&(n.style.height="auto",n.style.height=`${Math.min(n.scrollHeight,64)}px`)},[]),I=t.useCallback(()=>{const n=j.trim();!n||N||(f(n),w(""),requestAnimationFrame(()=>A()))},[j,N,f,A]);t.useEffect(()=>{A()},[A]),t.useEffect(()=>{var n;N||(n=E.current)==null||n.focus()},[N]);const B=t.useCallback(n=>{n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),I())},[I]),L=s||c,C=y??"Thinking…";return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsxs("div",{ref:b,className:"flex-1 min-h-0 overflow-y-auto px-4 py-4 space-y-1",children:[h.map(n=>e.jsx(ge,{message:n,onAddressSubmit:R,onViewFullEstimate:T,onEmailSubmit:D,isAuthenticated:a,autoSubmitAddress:z},n.id)),L&&e.jsxs("div",{className:"flex items-center gap-2 py-2",children:[e.jsxs("div",{className:"flex gap-1",children:[e.jsx("span",{className:"w-1.5 h-1.5 bg-gray-400 rounded-full animate-bounce [animation-delay:-0.3s]"}),e.jsx("span",{className:"w-1.5 h-1.5 bg-gray-400 rounded-full animate-bounce [animation-delay:-0.15s]"}),e.jsx("span",{className:"w-1.5 h-1.5 bg-gray-400 rounded-full animate-bounce"})]}),e.jsx("span",{className:"text-xs text-gray-400",children:C})]}),p&&e.jsx("div",{className:"text-sm text-red-500 bg-red-50 border border-red-200 rounded-lg px-3 py-2",children:p})]}),i&&e.jsx("div",{className:"border-t border-gray-200 bg-white px-4 py-3",children:e.jsx("form",{onSubmit:n=>{n.preventDefault(),I()},children:e.jsx("div",{className:"rounded-2xl border bg-muted/40 transition-colors duration-200 border-input focus-within:border-ring px-3 py-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ne,{ref:E,value:j,onChange:n=>{w(n.target.value),requestAnimationFrame(()=>A())},onKeyDown:B,placeholder:"Ask follow-up questions about your estimate...",disabled:N,rows:1,style:{height:"28px"},className:"flex-1 border-0 shadow-none focus-visible:ring-0 focus-visible:ring-offset-0 bg-transparent !min-h-0 px-0 py-0 !resize-none overflow-y-auto text-sm leading-6"}),e.jsx(oe,{type:"submit",className:$("!h-8 !w-8 rounded-full transition-colors bg-[var(--color-primary)] hover:bg-[var(--color-primary-dark)] text-white shrink-0",(!j.trim()||N)&&"opacity-40"),disabled:N||!j.trim(),children:e.jsx(le,{className:"h-3.5 w-3.5"})})]})})})})]})}function W({sessions:a,activeSessionId:d,onSelectSession:r,onNewChat:m,onDeleteSession:u}){return e.jsxs("aside",{className:"h-full border-r border-gray-200 bg-[#f8fafc]",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-3 border-b border-gray-200",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-gray-500",children:"Cost Seg Chats"}),e.jsxs("button",{type:"button",onClick:m,className:"inline-flex items-center gap-1 rounded-md border border-gray-300 bg-white px-2 py-1 text-xs font-medium text-gray-700 transition hover:bg-gray-50",children:[e.jsx(ie,{className:"h-3.5 w-3.5"}),"New"]})]}),e.jsx("div",{className:"overflow-y-auto h-[calc(100%-53px)] px-2 py-2 space-y-1",children:a.map(i=>{const o=i.id===d;return e.jsx("button",{type:"button",onClick:()=>r(i.id),className:$("group w-full text-left rounded-md px-2 py-2 cursor-pointer border transition",o?"border-[var(--color-primary)] bg-[var(--color-accent-light)]":"border-transparent hover:border-gray-200 hover:bg-white"),children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(ce,{className:$("h-4 w-4 mt-0.5",o?"text-[var(--color-primary)]":"text-gray-400")}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:$("truncate text-sm font-medium",o?"text-[var(--color-primary)]":"text-gray-700"),children:i.title}),e.jsx("p",{className:"text-[11px] text-gray-400 mt-0.5",children:new Date(i.updatedAt).toLocaleDateString("en-US",{month:"short",day:"numeric"})})]}),e.jsx("button",{type:"button","aria-label":"Delete chat",className:"opacity-0 group-hover:opacity-100 text-gray-400 hover:text-red-500 transition",onClick:x=>{x.stopPropagation(),u(i.id)},children:e.jsx(de,{className:"h-3.5 w-3.5"})})]})},i.id)})})]})}const q="cost-seg-chat-sessions-v1",be=20;function Se(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`costseg-${Date.now()}-${Math.random().toString(36).slice(2,9)}`}function _(a){const d=new Date().toISOString(),r=(a==null?void 0:a.trim())||null;return{id:Se(),title:r||"New Cost Seg Chat",address:r,createdAt:d,updatedAt:d,messages:[]}}function X(a){if(!a)return null;try{const d=JSON.parse(a);return Array.isArray(d.sessions)?{sessions:d.sessions.filter(r=>r&&typeof r.id=="string"),activeSessionId:d.activeSessionId??null}:null}catch{return null}}function we(a,d){var m;if(d)return d;const r=(m=a.find(u=>u.role==="user"))==null?void 0:m.parts.find(u=>u.type==="text");if(r&&"text"in r){const u=String(r.text??"").trim();if(u.length>0)return u.slice(0,80)}return"New Cost Seg Chat"}function ve(){const[a,d]=t.useState(()=>{const s=X(typeof window<"u"?localStorage.getItem(q):null);return s&&s.sessions.length>0?s.sessions:[_()]}),[r,m]=t.useState(()=>{var c,p;const s=X(typeof window<"u"?localStorage.getItem(q):null);return s!=null&&s.activeSessionId?s.activeSessionId:((p=(c=s==null?void 0:s.sessions)==null?void 0:c[0])==null?void 0:p.id)??null});t.useEffect(()=>{if(typeof window>"u")return;const s={sessions:a,activeSessionId:r};localStorage.setItem(q,JSON.stringify(s))},[a,r]),t.useEffect(()=>{var s;
14if(!r&&a[0]){m(a[0].id);return}r&&!a.some(c=>c.id===r)&&m(((s=a[0])==null?void 0:s.id)??null)},[a,r]);const u=t.useMemo(()=>a.find(s=>s.id===r)??null,[a,r]),i=t.useCallback(s=>{const c=_(s);return d(p=>[c,...p].slice(0,be)),m(c.id),c.id},[]),o=t.useCallback(s=>{m(s)},[]),x=t.useCallback(s=>{d(c=>{const p=c.filter(y=>y.id!==s);return p.length>0?p:[_()]}),m(c=>c===s?null:c)},[]),h=t.useCallback((s,c)=>{d(p=>p.map(y=>{if(y.id!==s)return y;const b=c.slice(-120),E=y.address;return{...y,messages:b,updatedAt:new Date().toISOString(),title:we(b,E)}}))},[]),f=t.useCallback((s,c)=>{const p=c.trim();p&&d(y=>y.map(b=>b.id!==s?b:{...b,address:p,title:p,updatedAt:new Date().toISOString()}))},[]);return{sessions:a,activeSessionId:r,activeSession:u,startNewSession:i,selectSession:o,deleteSession:x,updateSessionMessages:h,setSessionAddress:f}}function Ce(){const{isAuthenticated:a}=ue();fe();const[d,r]=t.useState(!1),m=t.useRef(!1),{sessions:u,activeSessionId:i,activeSession:o,startNewSession:x,selectSession:h,deleteSession:f,updateSessionMessages:s,setSessionAddress:c}=ve();t.useEffect(()=>{document.title="Cost Seg Chat Workspace | REPSShield"},[]),t.useEffect(()=>{var j;if(m.current)return;const g=(j=new URLSearchParams(window.location.search).get("address"))==null?void 0:j.trim();g&&(m.current=!0,x(g),window.history.replaceState({},document.title,"/tools/cost-seg-estimator/chat"))},[x]);const p=t.useMemo(()=>o&&o.address?`${o.address} - Property Analysis`:"New Property Analysis",[o]),y=o&&o.messages.length===0?o.address:null,b=t.useCallback(g=>{i&&s(i,g)},[i,s]),E=t.useCallback(g=>{i&&c(i,g)},[i,c]);return e.jsxs("div",{className:"h-screen overflow-hidden flex flex-col bg-[#eef2f6] text-gray-900",children:[e.jsx("header",{className:"flex-none border-b border-gray-200 bg-white/90 backdrop-blur",children:e.jsxs("div",{className:"mx-auto max-w-[1400px] px-4 py-3 flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{type:"button",onClick:()=>r(g=>!g),className:"md:hidden inline-flex items-center justify-center rounded-md border border-gray-300 bg-white p-2","aria-label":"Toggle sessions sidebar",children:d?e.jsx(me,{className:"h-4 w-4"}):e.jsx(pe,{className:"h-4 w-4"})}),e.jsxs(U,{href:"/tools/cost-seg-estimator",className:"flex items-center gap-2",children:[e.jsx("img",{src:"/repsshield-logo-main.png",alt:"REPSShield",className:"h-7 w-7"}),e.jsx("span",{className:"font-semibold text-lg text-[var(--color-primary)]",children:"REPSShield"})]})]}),a?e.jsx(U,{href:"/dashboard",className:"rounded-full border border-[var(--color-primary)] px-5 py-2 text-sm font-semibold text-[var(--color-primary)] hover:bg-[var(--color-primary)] hover:text-white transition",children:"Dashboard"}):e.jsx(U,{href:"/login",className:"rounded-full border border-[var(--color-primary)] px-5 py-2 text-sm font-semibold text-[var(--color-primary)] hover:bg-[var(--color-primary)] hover:text-white transition",children:"Log In"})]})}),e.jsx("main",{className:"flex-1 min-h-0 mx-auto w-full max-w-[1400px] px-4 py-4 flex flex-col",children:e.jsx("div",{className:"flex-1 min-h-0 relative overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-sm",children:e.jsxs("div",{className:"md:grid md:grid-cols-[280px_1fr] h-full min-h-0 overflow-hidden",children:[e.jsx("div",{className:"hidden md:block h-full min-h-0 overflow-hidden",children:e.jsx(W,{sessions:u,activeSessionId:i,onSelectSession:h,onDeleteSession:f,onNewChat:()=>x()})}),d&&e.jsxs("div",{className:"md:hidden absolute inset-0 z-30",children:[e.jsx("button",{type:"button",className:"absolute inset-0 bg-black/30","aria-label":"Close sessions sidebar",onClick:()=>r(!1)}),e.jsx("div",{className:"relative h-full w-[86%] max-w-xs bg-white",children:e.jsx(W,{sessions:u,activeSessionId:i,onSelectSession:g=>{h(g),r(!1)},onDeleteSession:f,onNewChat:()=>{x(),r(!1)}})})]}),e.jsxs("section",{className:"h-full min-h-0 min-w-0 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex-none border-b border-gray-200 px-4 py-3",children:[e.jsx("p",{className:"text-sm font-semibold truncate",children:p}),e.jsx("p",{className:"text-xs text-gray-500 mt-0.5",children:"Cost Segregation Workspace"})]}),e.jsx("div",{className:"flex-1 min-h-0",children:o&&i&&e.jsx(ye,{isAuthenticated:a,initialMessages:o.messages,initialAddress:y,onMessagesChange:b,onAddressSubmitted:E,showComposer:!0},i)})]})]})})})]})}export{Ce as default};

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.