PageSourceSearch

https://studio--billsense-nprrn.us-central1.hosted.app/_next/stati…/app/assistant/page-9122b2b54d260f7d.js

js studio--billsense-nprrn.us-central1.hosted.app collected 2026-10-03 05:34:27 UTC 15,821 bytes, 1 lines download raw bytes

1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5125],{68949:(e,s,t)=>{Promise.resolve().then(t.bind(t,61280))},79749:(e,s,t)=>{"use strict";t.d(s,{A:()=>c});let a={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};for(var i,r=new Uint8Array(16),n=[],l=0;l<256;++l)n.push((l+256).toString(16).slice(1));let c=function(e,s,t){if(a.randomUUID&&!s&&!e)return a.randomUUID();var l=(e=e||{}).random||(e.rng||function(){if(!i&&!(i="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)))throw Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return i(r)})();if(l[6]=15&l[6]|64,l[8]=63&l[8]|128,s){t=t||0;for(var c=0;c<16;++c)s[t+c]=l[c];return s}return function(e,s=0){return(n[e[s+0]]+n[e[s+1]]+n[e[s+2]]+n[e[s+3]]+"-"+n[e[s+4]]+n[e[s+5]]+"-"+n[e[s+6]]+n[e[s+7]]+"-"+n[e[s+8]]+n[e[s+9]]+"-"+n[e[s+10]]+n[e[s+11]]+n[e[s+12]]+n[e[s+13]]+n[e[s+14]]+n[e[s+15]]).toLowerCase()}(l)}},61280:(e,s,t)=>{"use strict";t.r(s),t.d(s,{default:()=>V});var a=t(95155),i=t(12115),r=t(65423),n=t(76046),l=t(73312),c=t(33900),d=t(77995);let o=(0,t(14057).A)("Link",[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",key:"1cjeqo"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",key:"19qd67"}]]);var h=t(46822),u=t(35524),p=t(22783),m=t(48070),x=t(68313),f=t(29609),j=t(21567),g=t(39124),y=t(55546),v=t(82496),b=t(75828);let N=(0,b.createServerReference)("407ce041551418fe348c7c2688daa881f3a096a9bf",b.callServer,void 0,b.findSourceMapURL,"getConversations"),w=(0,b.createServerReference)("707c2b7522a8c0361a370d20df6d732e53643e25ea",b.callServer,void 0,b.findSourceMapURL,"saveConversation"),k=(0,b.createServerReference)("603ab2d2e1b1c3826850067d5772d860c4935f9682",b.callServer,void 0,b.findSourceMapURL,"deleteConversation");var A=t(34029),S=t(69343),C=t(15157),I=t(65564),U=t(53601),M=t(79749),D=t(27058),R=t(44595),T=t(8896),E=t(59699),O=t(39760),P=t(78483),$=t(4976),L=t(22311),W=t(60582),H=t(24715),_=t(46087);let B=e=>{let{content:s,onLinkClick:t,isDesktop:i}=e;(0,n.useRouter)();let r=function(e){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=[],r=0;for(let n of e.matchAll(/\[(.*?)\]\((billsense:\/\/(bill|receipt|asset)\/.*?)\):?/g)){let[d,h,u,p]=n,m=n.index,x=u.split("/").pop();m>r&&i.push(c(e.substring(r,m)));let f=h.length>30,g=f?"".concat(h.substring(0,30),"..."):h,y=(0,a.jsxs)(l.$,{variant:"link",className:"p-0 h-auto inline-flex items-center text-left",onClick:()=>t(p,x),children:[(0,a.jsx)(o,{className:"mr-1 h-3 w-3 shrink-0"}),(0,a.jsx)("span",{className:(0,j.cn)(s&&"truncate"),children:s?g:h})]},"".concat(x,"-").concat(n.index));s&&f?i.push((0,a.jsx)(U.Bc,{children:(0,a.jsxs)(U.m_,{children:[(0,a.jsx)(U.k$,{asChild:!0,children:y}),(0,a.jsx)(U.ZI,{children:(0,a.jsx)("p",{children:h})})]})},n.index)):i.push(y),r=m+d.length}return r<e.length&&i.push(c(e.substring(r))),i},c=e=>{let s=[],t=0;for(let i of e.matchAll(/\*\*(.*?)\*\*/g)){let[r,n]=i,l=i.index;l>t&&s.push(e.substring(t,l)),s.push((0,a.jsx)("strong",{children:n},l)),t=l+r.length}return t<e.length&&s.push(e.substring(t)),s};return(0,a.jsx)("div",{className:"prose prose-sm dark:prose-invert max-w-none min-w-0",children:(e=>{let s=e.split("\n"),t=[],n=!1,l=[],c=[],d=[],o=()=>{if(n){if(i)t.push((0,a.jsx)("div",{className:"overflow-x-auto my-4 border rounded-lg",children:(0,a.jsxs)("table",{className:"min-w-full divide-y divide-border",children:[(0,a.jsx)("thead",{className:"bg-muted/50",children:(0,a.jsx)("tr",{children:l.map((e,s)=>(0,a.jsx)("th",{className:"px-4 py-3 text-left text-sm font-semibold",style:{textAlign:c[s]},children:e},s))})}),(0,a.jsx)("tbody",{className:"divide-y divide-border bg-card",children:d.map((e,s)=>(0,a.jsx)("tr",{children:e.map((e,t)=>(0,a.jsx)("td",{className:"px-4 py-3 text-sm whitespace-nowrap",style:{textAlign:c[t]},children:e},"".concat(s,"-").concat(t)))},s))})]})},"table-wrapper-".concat(t.length)));else{let e=d.map((e,s)=>{let t=e[0],i=e.slice(1);return(0,a.jsxs)("div",{className:"border rounded-lg p-3 bg-card shadow-sm mb-2",children:[(0,a.jsx)("div",{className:"font-bold text-base mb-2",children:t}),(0,a.jsx)("div",{className:"space-y-1 text-sm",children:i.map((e,s)=>(0,a.jsxs)("div",{className:"flex justify-between items-start",children:[(0,a.jsxs)("span",{className:"font-semibold text-muted-foreground mr-2",children:[l[s+1],":"]}),(0,a.jsx)("div",{className:"text-right",children:e})]},s))})]},"card-".concat(s))});t.push((0,a.jsx)("div",{className:"space-y-2 my-4",children:e},"mobile-table-".concat(t.length)))}n=!1,l=[],d=[],c=[]}};
1return s.forEach((e,s)=>{if(e.startsWith("|")){let s=e.split("|").slice(1,-1).map(e=>e.trim());n?s.every(e=>/^[-: ]+$/.test(e))?c=s.map(e=>e.startsWith(":")&&e.endsWith(":")?"center":e.endsWith(":")?"right":"left"):d.push(s.map(e=>r(e,!0))):(n=!0,l=s);return}o(),e.startsWith("# ")?t.push((0,a.jsx)("h1",{className:"text-2xl font-bold my-2",children:r(e.substring(2))},s)):e.startsWith("## ")?t.push((0,a.jsx)("h2",{className:"text-xl font-bold my-2",children:r(e.substring(3))},s)):e.startsWith("### ")?t.push((0,a.jsx)("h3",{className:"text-lg font-bold my-2",children:r(e.substring(4))},s)):e.startsWith("* ")||e.startsWith("- ")?t.push((0,a.jsx)("li",{className:"ml-4 list-disc",children:r(e.substring(2))},s)):""===e.trim()?t.push((0,a.jsx)("div",{className:"h-4"},s)):t.push((0,a.jsx)("p",{children:r(e)},s))}),o(),t})(s)})},z={role:"assistant",content:'Hello! I\'m BillSnap AI. I can help you understand your finances. Here are a few things you can ask me:\n\n*   "What bills are due this week?"\n*   "Show me my receipts from Bunnings."\n*   "How much did I spend on groceries last month?"\n\nHow can I help you today?'},F=e=>"ai-chat-session-".concat(e);function q(e){let{conversations:s,onLoad:t,onDelete:i,activeId:r,isCollapsed:n}=e;return(0,a.jsx)("div",{className:"space-y-2",children:s.map(e=>(0,a.jsxs)("div",{className:"group relative",children:[(0,a.jsxs)(l.$,{variant:"ghost",className:(0,j.cn)("w-full justify-start gap-2",n?"px-2":"px-4",r===e.id&&"bg-primary/10 text-primary hover:bg-primary/10"),onClick:()=>t(e.id),children:[(0,a.jsx)(h.A,{className:"h-4 w-4 shrink-0"}),!n&&(0,a.jsx)("span",{className:"truncate flex-1 text-left",children:e.title})]}),!n&&(0,a.jsxs)(S.Lt,{children:[(0,a.jsx)(S.tv,{asChild:!0,children:(0,a.jsx)(l.$,{variant:"ghost",size:"icon",className:"absolute right-1 top-1/2 -translate-y-1/2 h-7 w-7 opacity-0 group-hover:opacity-100",children:(0,a.jsx)(u.A,{className:"h-4 w-4 text-destructive"})})}),(0,a.jsxs)(S.EO,{children:[(0,a.jsxs)(S.wd,{children:[(0,a.jsx)(S.r7,{children:"Delete this conversation?"}),(0,a.jsxs)(S.$v,{children:['This will permanently delete the chat history for "',e.title,'". This action cannot be undone.']})]}),(0,a.jsxs)(S.ck,{children:[(0,a.jsx)(S.Zr,{children:"Cancel"}),(0,a.jsx)(S.Rx,{onClick:()=>i(e.id),className:"bg-destructive hover:bg-destructive/90",children:"Delete"})]})]})]})]},e.id))})}function J(){let{user:e,loading:s}=(0,r.A)(),t=(0,n.useRouter)(),o=(0,n.useSearchParams)(),[h,u]=(0,i.useState)({id:null,messages:[z]}),[b,S]=(0,i.useState)([]),[U,J]=(0,i.useState)(""),[V,G]=(0,i.useState)(!1),Q=(0,i.useRef)(null),Z=(0,y.U)("(min-width: 768px)");(0,W.a)();let[K,X]=(0,i.useState)(!1),[Y,ee]=(0,i.useState)(!1),{toast:es}=(0,I.dj)(),[et,ea]=(0,i.useTransition)(),[ei,er]=(0,i.useState)([]),[en,el]=(0,i.useState)([]),ec=o.get("billId"),ed=o.get("receiptId"),eo=(0,i.useMemo)(()=>{var e;return ec&&null!==(e=ei.find(e=>e.id===ec))&&void 0!==e?e:null},[ei,ec]),eh=(0,i.useMemo)(()=>{var e;return ed&&null!==(e=en.find(e=>e.id===ed))&&void 0!==e?e:null},[en,ed]);(0,i.useEffect)(()=>{if(e){let s=(0,D.P)((0,D.rJ)(R.db,"bills"),(0,D._M)("userId","==",e.uid)),t=(0,D.aQ)(s,e=>{er(e.docs.map(H.MA).filter(e=>null!==e))}),a=(0,D.P)((0,D.rJ)(R.db,"receipts"),(0,D._M)("userId","==",e.uid)),i=(0,D.aQ)(a,e=>{el(e.docs.map(H.PD).filter(e=>null!==e))});return()=>{t(),i()}}},[e]);let eu=(0,i.useCallback)(()=>{u({id:"client-".concat((0,M.A)()),messages:[z]}),e&&localStorage.removeItem(F(e.uid)),ee(!1)},[e]);(0,i.useEffect)(()=>{if(e&&!s){N(e.uid).then(S);let s=localStorage.getItem(F(e.uid));if(s)try{let e=JSON.parse(s);e.id?u(e):eu()}catch(s){console.error("Failed to parse saved session",s),localStorage.removeItem(F(e.uid)),eu()}else eu()}},[e,s,eu]),(0,i.useEffect)(()=>{var e;null===(e=Q.current)||void 0===e||e.scrollIntoView({behavior:"smooth"})},[h.messages]),(0,i.useEffect)(()=>{if(e&&h.id){let s=JSON.stringify(h);localStorage.setItem(F(e.uid),s)}},[h,e]);let ep=async s=>{if(null==s||s.preventDefault(),!U.trim()||!e)return;(0,_.b)();let t={...h,messages:[...h.messages,{role:"user",content:U}]};u(t),J(""),G(!0);try{let s=await fetch("/api/assistant/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userId:e.uid,history:t.messages,conversationId:t.id})});if(!s.ok){let e="Could not read error body.";try{e=await s.text()}catch(e){}throw console.error("AI chat API error: ".concat(s.status," ").concat(s.statusText),e),Error("API responded with status: ".concat(s.status))}let a=await s.json(),i={role:"assistant",content:a.answer},r={...t,messages:[...t.messages,i]};u(r),ea(async()=>{let s=await w(e.uid,r.messages,r.id);
1u({id:s.id,messages:s.messages}),S(e=>{let t=e.findIndex(e=>e.id===s.id);if(-1===t)return[s,...e].sort((e,s)=>s.updatedAt.getTime()-e.updatedAt.getTime());{let a=[...e];return a[t]=s,a.sort((e,s)=>s.updatedAt.getTime()-e.updatedAt.getTime())}})})}catch(s){console.error("Error asking financial assistant:",s);let e={role:"assistant",content:"Sorry, I couldn't reach the assistant service. Please try again."};u(s=>({...s,messages:[...s.messages,e]}))}finally{G(!1)}},em=e=>{let s=b.find(s=>s.id===e);s&&u({id:s.id,messages:s.messages}),ee(!1)},ex=async s=>{e&&(await k(e.uid,s),S(e=>e.filter(e=>e.id!==s)),h.id===s&&eu(),es({title:"Conversation Deleted"}))},ef=(e,s)=>{"bill"===e?t.push("/assistant?billId=".concat(s)):"receipt"===e?t.push("/assistant?receiptId=".concat(s)):"asset"===e&&t.push("/assets?assetId=".concat(s))};return s||!e?(0,a.jsx)("div",{className:"flex items-center justify-center min-h-screen",children:(0,a.jsx)(p.A,{className:"h-8 w-8 animate-spin text-primary"})}):(0,a.jsxs)("div",{className:"h-dvh bg-muted/40 flex flex-col",children:[(0,a.jsx)($.j,{allBills:ei,allReceipts:en,onBillSelect:e=>{t.push("/?tab=bills&billId=".concat(e))},onReceiptSelect:e=>{t.push("/?tab=receipts&receiptId=".concat(e))}}),(0,a.jsxs)("main",{className:"flex-1 flex overflow-hidden",children:[Z&&(0,a.jsx)("div",{className:"w-64 bg-card/50 border-r",children:(0,a.jsxs)("div",{className:"p-2 space-y-2 h-full flex flex-col",children:[(0,a.jsxs)(l.$,{variant:"outline",className:"w-full justify-start",onClick:eu,children:[(0,a.jsx)(m.A,{className:"h-4 w-4 mr-2"}),"New Chat"]}),(0,a.jsx)(C.w,{}),(0,a.jsx)(d.F,{className:"flex-1 -mr-2",children:(0,a.jsx)("div",{className:"pr-2",children:(0,a.jsx)(q,{conversations:b,onLoad:em,onDelete:ex,activeId:h.id,isCollapsed:!1})})})]})}),(0,a.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden relative",children:[(0,a.jsx)(d.F,{className:"flex-1",children:(0,a.jsxs)("div",{className:"space-y-8 p-4 md:pt-12 max-w-3xl mx-auto w-full pb-44 md:pb-28",children:[h.messages.map((e,s)=>(0,a.jsx)(g.P.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.3},children:"user"===e.role?(0,a.jsx)("div",{className:"flex justify-end",children:(0,a.jsx)("div",{className:"p-4 rounded-2xl max-w-[85%] break-words bg-primary text-primary-foreground rounded-br-none",children:(0,a.jsx)("p",{className:"whitespace-pre-wrap",children:e.content})})}):(0,a.jsx)(B,{content:e.content,onLinkClick:ef,isDesktop:Z})},"".concat(h.id,"-").concat(s))),V&&(0,a.jsx)(g.P.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"flex items-start gap-4",children:(0,a.jsx)(p.A,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),(0,a.jsx)("div",{ref:Q})]})}),(0,a.jsx)("div",{className:(0,j.cn)("p-4 border-t bg-card/80 backdrop-blur-sm",Z?"sticky bottom-0":"fixed bottom-[88px] left-0 right-0"),children:(0,a.jsxs)("form",{onSubmit:ep,className:"max-w-3xl mx-auto flex items-center gap-2",children:[!Z&&(0,a.jsxs)(A.cj,{open:Y,onOpenChange:ee,children:[(0,a.jsx)(A.CG,{asChild:!0,children:(0,a.jsxs)(l.$,{type:"button",variant:"outline",size:"icon",className:"flex-shrink-0",children:[(0,a.jsx)(x.A,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"sr-only",children:"History"})]})}),(0,a.jsxs)(A.h,{side:"bottom",className:"p-0 h-[90vh] flex flex-col",children:[(0,a.jsx)(A.Fm,{className:"p-4 border-b",children:(0,a.jsx)(A.qp,{children:"Conversation History"})}),(0,a.jsxs)("div",{className:"p-2 space-y-2",children:[(0,a.jsxs)(l.$,{variant:"outline",className:"w-full justify-start",onClick:eu,children:[(0,a.jsx)(m.A,{className:"h-4 w-4 mr-2"}),"New Chat"]}),(0,a.jsx)(C.w,{})]}),(0,a.jsx)(d.F,{className:"flex-1 px-4 pb-4",children:(0,a.jsx)(q,{conversations:b,onLoad:em,onDelete:ex,activeId:h.id,isCollapsed:!1})})]})]}),(0,a.jsx)(c.p,{value:U,onChange:e=>J(e.target.value),placeholder:"Ask about your finances...",className:"flex-1",disabled:V||et}),(0,a.jsx)(l.$,{type:"submit",size:"icon",disabled:V||et||!U.trim(),className:"flex-shrink-0",children:(0,a.jsx)(f.A,{className:"h-4 w-4"})})]})})]})]}),!Z&&(0,a.jsx)(L.X,{onQuickAdd:()=>X(!0)}),(0,a.jsx)(v.Y,{open:K,onOpenChange:X,sharedFile:null,clearSharedFile:()=>{}}),(0,a.jsx)(T.C,{bill:eo,isOpen:!!ec,onOpenChange:e=>!e&&t.push("/assistant"),onUpdateStatus:O.rS,onUpdateCategory:()=>{},onUpdateTaxStatus:O.G8,onDeleteBill:O.LM,onAddNote:O.Ks,onUpdateNote:O.g$,onDeleteNote:O.r,activeTab:"details"}),(0,a.jsx)(E.l,{receipt:eh,isOpen:!!ed,onOpenChange:e=>!e&&t.push("/assistant"),onUpdateCategory:()=>{},onUpdateTaxStatus:P.Rd,onDeleteReceipt:P.qH,onAddNote:P.Hg,onUpdateNote:P.fG,onDeleteNote:P.u$,activeTab:"details"})]})}function V(){return(0,a.jsx)(i.Suspense,{children:(0,a.jsx)(J,{})})}},60582:(e,s,t)=>{"use strict";t.d(s,{a:()=>r});var a=t(12115),i=t(55546);function r(){let[e,s]=(0,a.useState)(!1),t=(0,i.U)("(max-width: 767px)");return(0,a.useEffect)(()=>{let e="ontouchstart"in window||navigator.maxTouchPoints>0;s(t&&e)},[t]),e}},27822:(e,s,t)=>{"use strict";t.d(s,{R:()=>i});var a=t(77833);function i(e){return+(0,a.a)(e)<Date.now()}},67863:(e,s,t)=>{"use strict";t.d(s,{c:()=>r});var a=t(90627),i=t(75844);function r(e){return(0,i.r)(e,(0,a.A)(e))}},92433:(e,s,t)=>{"use strict";t.d(s,{A:()=>a});let a=(0,t(14057).A)("Banknote",[["rect",{width:"20",height:"12",x:"2",y:"6",rx:"2",key:"9lu3g6"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"M6 12h.01M18 12h.01",key:"113zkx"}]])},13261:(e,s,t)=>{"use strict";t.d(s,{A:()=>a});let a=(0,t(14057).A)("CircleCheckBig",[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]])},96758:(e,s,t)=>{"use strict";t.d(s,{A:()=>a});
1let a=(0,t(14057).A)("Copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]])},1068:(e,s,t)=>{"use strict";t.d(s,{A:()=>a});let a=(0,t(14057).A)("TriangleAlert",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]])},42558:(e,s,t)=>{"use strict";t.d(s,{A:()=>a});let a=(0,t(14057).A)("Undo2",[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]])}},e=>{var s=s=>e(e.s=s);e.O(0,[2992,3644,4324,69,4900,9122,5565,4722,143,7776,9353,4621,8150,8207,5971,8896,8441,8590,7358],()=>s(68949)),_N_E=e.O()}]);

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.