PageSourceSearch

https://www.selfstorming.com/_next/static/chunks/pages/tools/deep-research-7f8618b8717decc4.js

js selfstorming.com collected 2026-10-07 19:50:26 UTC 33,960 bytes, 29 lines download raw bytes

1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4588],{1046:(e,t,r)=>{"use strict";r.d(t,{A:()=>s});let s=(0,r(19297).A)("ArrowUp",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]])},28498:(e,t,r)=>{"use strict";r.d(t,{e:()=>i});var s=r(37876),a=r(14232),o=r(89099),n=r(59606),l=r(3256);let i=e=>{let{researchHistory:t,currentJobId:r,currentJobData:i,onSelectJob:c,onJobDeleted:d}=e,[u,h]=(0,a.useState)(!1),[x,p]=(0,a.useState)(!1),[m,f]=(0,a.useState)(null),[g,y]=(0,a.useState)(!1),b=(0,a.useRef)(null),j=(0,a.useRef)(null),w=(0,o.useRouter)();(0,a.useEffect)(()=>{let e=e=>{u&&j.current&&!j.current.contains(e.target)&&b.current&&!b.current.contains(e.target)&&h(!1)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[u]);let v=e=>{c?c(e):"new"===e?w.push("/tools/research"):w.push(`/tools/deep-research?jobId=${e}`),h(!1)},k=async()=>{if(m){p(!1),y(!0);try{let{data:{session:e}}=await l.N.auth.getSession();if(!(null==e?void 0:e.access_token))throw Error("No authentication token");let t=await fetch(`/api/research/${m.id}/delete`,{method:"DELETE",headers:{Authorization:`Bearer ${e.access_token}`}});if(!t.ok){let e=await t.json().catch(()=>({})),r=e.error||`Failed to delete research (${t.status})`;throw console.error("Delete error:",r,e),Error(r)}d&&d(),m.id===r&&w.push("/tools/research")}catch(e){console.error("Error deleting research:",e),alert("Failed to delete research. Please try again.")}finally{y(!1),f(null)}}};return(0,s.jsxs)("div",{className:"relative z-[40]",children:[(0,s.jsx)("button",{ref:b,type:"button",onClick:()=>h(!u),className:"flex items-center gap-3 px-3 py-1.5 text-sm transition-colors flex-wrap justify-center rounded-lg bg-[#CEFF1A] hover:bg-[#CEFF1A]/90 text-black",children:i?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"font-bold text-black",children:i.brand}),i.region&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 text-black",children:[(0,s.jsxs)("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:[(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"}),(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 11a3 3 0 11-6 0 3 3 0 016 0z"})]}),(0,s.jsx)("span",{children:i.region})]}),i.language&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 text-black",children:[(0,s.jsx)("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 5h12M9 3v2m1.048 9.5A18.022 18.022 0 016.412 9m6.088 9h7M11 21l5-10 5 10M12.751 5C11.783 10.77 8.07 15.61 3 18.129"})}),(0,s.jsx)("span",{children:i.language})]}),(0,s.jsx)("svg",{className:"w-4 h-4 hidden md:block text-black",fill:"none",stroke:"currentColor",strokeWidth:"2",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})})]}):(0,s.jsxs)(s.Fragment,{children:["Load previous research",(0,s.jsx)("svg",{className:"w-4 h-4 hidden md:block text-black",fill:"none",stroke:"currentColor",strokeWidth:"2",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})})]})}),u&&(0,s.jsx)("div",{ref:j,className:"absolute left-1/2 -translate-x-1/2 mt-2 w-[calc(100vw-2rem)] sm:w-[500px] md:w-[650px] rounded-lg shadow-lg bg-white ring-1 ring-black ring-opacity-5 z-[40] max-h-96 overflow-y-auto article-modal-scrollbar",children:(0,s.jsxs)("ul",{className:"py-2",children:[(0,s.jsx)("li",{children:(0,s.jsx)("button",{onClick:()=>v("new"),className:"block w-full text-left px-4 py-3 text-sm font-bold transition-colors hover:bg-slate-100",style:{color:"#39615F"},children:"+ Create new research"})}),t.filter(e=>e.id!==r).map(e=>{let t=new Date(e.created_at),r=`${String(t.getDate()).padStart(2,"0")}/${String(t.getMonth()+1).padStart(2,"0")}/${String(t.getFullYear()).slice(-2)}`;return(0,s.jsx)("li",{children:(0,s.jsxs)("div",{className:"flex items-center group hover:bg-gray-100 transition-colors",children:[(0,s.jsx)("button",{onClick:()=>v(e.id),className:"flex-1 text-left px-4 py-3 text-sm",children:(0,s.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,s.jsx)("span",{className:"font-bold text-gray-900 transition-colors",children:e.brand}
1),e.region&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsxs)("svg",{className:"w-3.5 h-3.5 text-gray-400 transition-colors",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:[(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"}),(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 11a3 3 0 11-6 0 3 3 0 016 0z"})]}),(0,s.jsx)("span",{className:"text-gray-400 text-xs transition-colors",children:e.region})]}),e.language&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)("svg",{className:"w-3.5 h-3.5 text-gray-400 transition-colors",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 5h12M9 3v2m1.048 9.5A18.022 18.022 0 016.412 9m6.088 9h7M11 21l5-10 5 10M12.751 5C11.783 10.77 8.07 15.61 3 18.129"})}),(0,s.jsx)("span",{className:"text-gray-400 text-xs transition-colors",children:e.language})]}),(0,s.jsx)("span",{className:"text-gray-400 text-xs transition-colors",children:r})]})}),(0,s.jsx)("button",{onClick:t=>{t.stopPropagation(),f(e),p(!0)},disabled:g,className:"p-2 text-gray-400 hover:text-red-600 transition-colors disabled:opacity-50","aria-label":"Delete research",children:(0,s.jsx)("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})},e.id)})]})}),(0,s.jsx)(n.T,{isOpen:x,title:"Delete Research?",message:"Delete this research permanently?",confirmText:"Delete",cancelText:"Cancel",onConfirm:k,onCancel:()=>{p(!1),f(null)},confirmButtonClass:"bg-[#E40066] hover:bg-[#E40066]/90"})]})}},59606:(e,t,r)=>{"use strict";r.d(t,{T:()=>l});var s=r(37876);r(14232);var a=r(75784),o=r(46100),n=r(98477);let l=e=>{let{isOpen:t,title:r,message:l,confirmText:i="Confirm",cancelText:c="Cancel",onConfirm:d,onCancel:u,confirmButtonClass:h="bg-red-600 hover:bg-red-700"}=e,x=(0,s.jsx)(a.N,{children:t&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(o.P.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},transition:{duration:.2},className:"fixed inset-0 bg-black/50 backdrop-blur-sm z-[99999]",onClick:u}),(0,s.jsx)("div",{className:"fixed inset-0 flex items-center justify-center z-[99999] p-4 pointer-events-none",children:(0,s.jsxs)(o.P.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},transition:{duration:.2,ease:[.16,1,.3,1]},className:"bg-white rounded-2xl shadow-2xl p-6 md:p-8 max-w-md w-full pointer-events-auto",onClick:e=>e.stopPropagation(),children:[(0,s.jsx)("h3",{className:"text-xl md:text-2xl font-bold text-gray-900 mb-3 text-center",children:r}),(0,s.jsx)("p",{className:"text-base text-gray-600 mb-6 leading-relaxed text-center",children:l}),(0,s.jsxs)("div",{className:"flex gap-3 justify-center",children:[(0,s.jsx)("button",{onClick:u,className:"px-5 py-2.5 text-gray-700 bg-gray-100 hover:bg-gray-200 rounded-xl font-medium transition-colors",children:c}),(0,s.jsx)("button",{onClick:d,className:`px-5 py-2.5 text-white rounded-xl font-medium transition-colors ${h}`,children:i})]})]})})]})});return"undefined"!=typeof document?(0,n.createPortal)(x,document.body):null}},75784:(e,t,r)=>{"use strict";r.d(t,{N:()=>b});var s=r(37876),a=r(14232),o=r(5048),n=r(91200),l=r(50181),i=r(3866),c=r(7990),d=r(39751);function u(e,t){if("function"==typeof e)return e(t);null!=e&&(e.current=t)}class h extends a.Component{getSnapshotBeforeUpdate(e){let t=this.props.childRef.current;if(t&&e.isPresent&&!this.props.isPresent){let e=t.offsetParent,r=(0,c.s)(e)&&e.offsetWidth||0,s=this.props.sizeRef.current;s.height=t.offsetHeight||0,s.width=t.offsetWidth||0,s.top=t.offsetTop,s.left=t.offsetLeft,s.right=r-s.width-s.left}return null}componentDidUpdate(){}render(){return this.props.children}}function x({children:e,isPresent:t,anchorX:r,root:o}){let n=(0,a.useId)(),l=(0,a.useRef)(null),i=(0,a.useRef)({width:0,height:0,top:0,left:0,right:0}),{nonce:c}=(0,a.useContext)(d.Q),x=function(...e){return a.useCallback(function(...e){return t=>{let r=!1,s=e.map(e=>{let s=u(e,t);return r||"function"!=typeof s||(r=!0),s});if(r)return()=>{for(let t=0;t<s.length;t++){let r=s[t];"function"==typeof r?r():u(e[t],null)}}}}(...e),e)}(l,e?.ref);return(0,a.useInsertionEffect)(()=>{let{width:e,height:s,top:a,left:d,right:u}=i.current;if(t||!l.current||!e||!s)return;let h="left"===r?`left: ${d}`:`right: ${u}`;l.current.dataset.motionPopId=n;let x=document.createElement("style");c&&(x.nonce=c);let p=o??document.head;return p.appendChild(x),x.sheet&&x.sheet.insertRule(`
2          [data-motion-pop-id="${n}"] {
3            position: absolute !important;
4            width: ${e}px !important;
5            height: ${s}px !important;
6            ${h}px !important;
7            top: ${a}px !important;
8          }
9        `),()=>{p.contains(x)&&p.removeChild(x)}},[t]),(0,s.jsx)(h,{isPresent:t,childRef:l,sizeRef:i,children:a.cloneElement(e,{ref:x})})}let p=({children:e,initial:t,isPresent:r,onExitComplete:o,custom:l,presenceAffectsLayout:c,mode:d,anchorX:u,root:h})=>{let p=(0,n.M)(m),f=(0,a.useId)(),g=!0,y=(0,a.useMemo)(()=>(g=!1,{id:f,initial:t,isPresent:r,custom:l,onExitComplete:e=>{for(let t of(p.set(e,!0),p.values()))if(!t)return;o&&o()},register:e=>(p.set(e,!1),()=>p.delete(e))}),[r,p,o]);return c&&g&&(y={...y}),(0,a.useMemo)(()=>{p.forEach((e,t)=>p.set(t,!1))},[r]),a.useEffect(()=>{r||p.size||!o||o()},[r]),"popLayout"===d&&(e=(0,s.jsx)(x,{isPresent:r,anchorX:u,root:h,children:e})),(0,s.jsx)(i.t.Provider,{value:y,children:e})};function m(){return new Map}var f=r(83885);let g=e=>e.key||"";function y(e){let t=[];return a.Children.forEach(e,e=>{(0,a.isValidElement)(e)&&t.push(e)}),t}let b=({children:e,custom:t,initial:r=!0,onExitComplete:i,presenceAffectsLayout:c=!0,mode:d="sync",propagate:u=!1,anchorX:h="left",root:x})=>{let[m,b]=(0,f.xQ)(u),j=(0,a.useMemo)(()=>y(e),[e]),w=u&&!m?[]:j.map(g),v=(0,a.useRef)(!0),k=(0,a.useRef)(j),N=(0,n.M)(()=>new Map),[C,S]=(0,a.useState)(j),[E,_]=(0,a.useState)(j);(0,l.E)(()=>{v.current=!1,k.current=j;for(let e=0;e<E.length;e++){let t=g(E[e]);w.includes(t)?N.delete(t):!0!==N.get(t)&&N.set(t,!1)}},[E,w.length,w.join("-")]);let L=[];if(j!==C){let e=[...j];for(let t=0;t<E.length;t++){let r=E[t],s=g(r);w.includes(s)||(e.splice(t,0,r),L.push(r))}return"wait"===d&&L.length&&(e=L),_(y(e)),S(j),null}let{forceRender:F}=(0,a.useContext)(o.L);return(0,s.jsx)(s.Fragment,{children:E.map(e=>{let a=g(e),o=(!u||!!m)&&(j===E||w.includes(a));return(0,s.jsx)(p,{isPresent:o,initial:(!v.current||!!r)&&void 0,custom:t,presenceAffectsLayout:c,mode:d,root:x,onExitComplete:o?void 0:()=>
9{if(!N.has(a))return;N.set(a,!0);let e=!0;N.forEach(t=>{t||(e=!1)}),e&&(F?.(),_(k.current),u&&b?.(),i&&i())},anchorX:h,children:e},a)})})}},80756:(e,t,r)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/tools/deep-research",function(){return r(85094)}])},85094:(e,t,r)=>{"use strict";r.r(t),r.d(t,{__N_SSP:()=>N,default:()=>C});var s=r(37876),a=r(89099),o=r(3256),n=r(9002),l=r(14232),i=r(77328),c=r.n(i),d=r(19491),u=r(63300),h=r(5622),x=r(21913),p=r(28498),m=r(1046);let f=e=>{var t;let{jobId:r,currentArticle:a,onArticleExtended:n}=e,[i,c]=(0,l.useState)([]),[d,u]=(0,l.useState)(!1),[h,x]=(0,l.useState)(!1),[p,f]=(0,l.useState)(""),[g,y]=(0,l.useState)(null),b=async()=>{u(!0),y(null);try{let{data:{session:e}}=await o.N.auth.getSession(),t=await fetch(`/api/research/${r}/hints`,{headers:{...(null==e?void 0:e.access_token)&&{Authorization:`Bearer ${e.access_token}`}}});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`Failed to load hints: ${t.status} ${t.statusText}`)}let s=await t.json();c(s.hints||[])}catch(e){console.error("Error loading hints:",e),c([])}finally{u(!1)}};(0,l.useEffect)(()=>{r&&b()},[r,null==(t=a.sections)?void 0:t.length]);let j=async e=>{if(e.trim()&&!h){x(!0),y(null);try{let t=new AbortController,s=setTimeout(()=>t.abort(),3e5),{data:{session:a}}=await o.N.auth.getSession(),l=await fetch(`/api/research/${r}/extend`,{method:"POST",headers:{"Content-Type":"application/json",...(null==a?void 0:a.access_token)&&{Authorization:`Bearer ${a.access_token}`}},body:JSON.stringify({prompt:e.trim()}),signal:t.signal});if(clearTimeout(s),!l.ok){let e=await l.json().catch(()=>({}));throw Error(e.error||"Failed to extend research")}let i=await l.json();if(i.success&&i.updatedArticle)n(i.updatedArticle),f(""),await b();else throw Error("Failed to extend research")}catch(e){console.error("Error extending research:",e),"AbortError"===e.name?y("Request timed out. The AI is taking too long to respond. Please try again with a shorter or simpler question."):y(e.message||"Failed to extend research. Please try again.")}finally{x(!1)}}};return(0,s.jsxs)("div",{className:"p-8 pt-16 text-center",children:[(0,s.jsx)("h1",{className:"text-[3rem] font-bold mb-6",children:"Extend Your Research"}),d?(0,s.jsx)("div",{className:"mb-6 text-slate-500",children:"Loading suggestions..."}):i.length>0?(0,s.jsx)("div",{className:"mb-6",children:(0,s.jsx)("div",{className:"flex flex-wrap justify-center gap-3",children:i.map((e,t)=>(0,s.jsx)("button",{onClick:()=>{f(e),j(e)},disabled:h,className:"px-4 py-2 text-xs bg-white dark:bg-slate-700 text-slate-700 dark:text-slate-200 rounded-full border border-slate-300 dark:border-slate-600 hover:bg-slate-100 dark:hover:bg-slate-600 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:e},t))})}):null,(0,s.jsx)("form",{onSubmit:e=>{e.preventDefault(),p.trim()&&j(p)},className:"max-w-2xl mx-auto",children:(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("input",{type:"text",value:p,onChange:e=>f(e.target.value),placeholder:"Ask additional question",disabled:h,className:"w-full px-4 py-3 pr-12 rounded-full border-2 border-black bg-white dark:bg-slate-700 text-slate-900 dark:text-slate-100 placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-black focus:border-black disabled:opacity-50 disabled:cursor-not-allowed"}),(0,s.jsx)("button",{type:"submit",disabled:!p.trim()||h,className:"absolute right-2 top-1/2 -translate-y-1/2 p-2 rounded-full bg-[#CEFF1A] hover:bg-[#CEFF1A]/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center",children:h?(0,s.jsx)("span",{className:"text-sm text-black",children:"..."}):(0,s.jsx)(m.A,{className:"w-5 h-5",style:{color:"#000000"},strokeWidth:3})})]})}),g&&(0,s.jsx)("div",{className:"mt-4 p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg text-red-700 dark:text-red-400 text-sm",children:g}),h&&(0,s.jsxs)("div",{className:"mt-4 flex flex-col items-center gap-4",children:[(0,s.jsx)("div",{className:"text-slate-500 text-sm",children:"Generating new research sections... This takes 2-3 minutes."}),(0,s.jsxs)("div",{className:"inline-flex items-center justify-center",children:[(0,s.jsx)("style",{dangerouslySetInnerHTML:{__html:`
10                @keyframes float {
11                  0%, 100% { transform: translateY(0px); }
12                  50% { transform: translateY(-8px); }
13                }
14                @keyframes pulse-blink {
15                  0%, 100% { opacity: 1; }
16                  50% { opacity: 0.4; }
17                }
18                .animate-cloud-loader { animation: float 1s ease-in-out infinite, pulse-blink 1.6s ease-in-out infinite; }
19              `}}),(0,s.jsx)("img",{src:"/lovable-uploads/cloud-loader.png",alt:"Loading",width:64,height:64,className:"animate-cloud-loader"})]})]})]})};var g=r(75784),y=r(46100),b=r(98477);let j=e=>{let{isOpen:t,shareUrl:r,onClose:a}=e,[o,n]=(0,l.useState)(!1),i=async()=>{try{await navigator.clipboard.writeText(r),n(!0),setTimeout(()=>n(!1),2e3)}catch(e){console.error("Failed to copy URL:",e)}},c=(0,s.jsx)(g.N,{children:t&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(y.P.div,{initial:{opacity:0}
19,animate:{opacity:1},exit:{opacity:0},transition:{duration:.2},className:"fixed inset-0 bg-black/50 backdrop-blur-sm z-[100]",onClick:a}),(0,s.jsx)("div",{className:"fixed inset-0 flex items-center justify-center z-[100] p-4 pointer-events-none",children:(0,s.jsxs)(y.P.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},transition:{duration:.2,ease:[.16,1,.3,1]},className:"bg-white rounded-2xl shadow-2xl p-6 md:p-8 max-w-md w-full pointer-events-auto",onClick:e=>e.stopPropagation(),children:[(0,s.jsx)("div",{className:"flex justify-center mb-4",children:(0,s.jsx)("div",{className:"w-16 h-16 rounded-full bg-[#39615F]/10 flex items-center justify-center",children:(0,s.jsx)("svg",{className:"w-8 h-8 text-[#39615F]",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})})}),(0,s.jsx)("h3",{className:"text-xl md:text-2xl font-bold text-gray-900 mb-3 text-center",children:"Shareable research ready!"}),(0,s.jsx)("p",{className:"text-base text-gray-600 mb-6 leading-relaxed text-center",children:"URL copied to clipboard. Ready to share your research insights with anyone."}),(0,s.jsx)("div",{className:"mb-6",children:(0,s.jsxs)("div",{className:"bg-gray-50 rounded-lg p-3 flex items-center gap-2",children:[(0,s.jsx)("input",{type:"text",value:r,readOnly:!0,className:"flex-1 text-sm text-gray-700 bg-transparent border-none outline-none"}),(0,s.jsx)("button",{onClick:i,className:`px-3 py-1.5 rounded-lg font-medium transition-colors ${o?"bg-[#39615F] text-white":"bg-gray-200 text-gray-700 hover:bg-gray-300"}`,children:o?"Copied!":"Copy"})]})}),(0,s.jsxs)("div",{className:"flex gap-3 justify-center",children:[(0,s.jsx)("button",{onClick:a,className:"px-6 py-2.5 text-gray-700 bg-gray-100 hover:bg-gray-200 rounded-xl font-medium transition-colors",children:"Close"}),(0,s.jsx)("button",{onClick:()=>{window.open(r,"_blank"),a()},className:"px-6 py-2.5 text-white bg-[#39615F] hover:bg-[#2d4d4a] rounded-xl font-medium transition-colors",children:"View research"})]})]})})]})});return"undefined"!=typeof document?(0,b.createPortal)(c,document.body):null};var w=r(8598),v=r(71579),k=r(59688),N=!0;let C=e=>{let{initialOgMeta:t}=e,r=(0,a.useRouter)(),{user:i,setRedirectUrl:m,getRedirectUrl:g,clearRedirectUrl:y}=(0,u.A)(),[b,N]=(0,l.useState)("your topic"),[C,S]=(0,l.useState)(""),[E,_]=(0,l.useState)(null),[L,F]=(0,l.useState)(null),[P,T]=(0,l.useState)([]),[$,M]=(0,l.useState)(!1),[R,A]=(0,l.useState)("loading"),[I,B]=(0,l.useState)(""),[V,z]=(0,l.useState)(""),[D,W]=(0,l.useState)("opacity-100"),[J,H]=(0,l.useState)([]),[O,q]=(0,l.useState)(null),[X,Z]=(0,l.useState)(null),[U,Y]=(0,l.useState)(!1),[G,Q]=(0,l.useState)(!1),[K,ee]=(0,l.useState)(!1),[et,er]=(0,l.useState)(""),[es,ea]=(0,l.useState)(null),[eo,en]=(0,l.useState)([]),[el,ei]=(0,l.useState)(!1),[ec,ed]=(0,l.useState)(!1);(0,l.useEffect)(()=>{H((0,x.v)())},[]),(0,l.useEffect)(()=>{if(r.isReady){let e=r.query.brand||"",t=r.query.jobId||null;e&&N(e),F(t)}},[r.isReady,r.query.brand,r.query.jobId]),(0,l.useEffect)(()=>{(async()=>{M(!0);try{let{data:{session:e}}=await o.N.auth.getSession();if(!(null==e?void 0:e.access_token))throw Error("No auth token");let t=await fetch("/api/research/list",{headers:{Authorization:`Bearer ${e.access_token}`}});if(t.ok){let e=await t.json();T(e.jobs||[])}else console.error("Failed to fetch research list")}catch(e){console.error("Error fetching research history",e)}finally{M(!1)}})()},[]),(0,l.useEffect)(()=>{if(!r.isReady)return;let e=window.location.pathname+window.location.search;i?(g?g():null)===e&&y():m(e)},[r.isReady,r.asPath,i,m,g,y]);let eu=async e=>{try{let{data:{session:t}}=await o.N.auth.getSession();if(!(null==t?void 0:t.access_token)){console.error("❌ No auth token available for research trigger"),A("failed"),q("Session expired. Please log in again and retry.");return}let r=await fetch("/api/workflows/research",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t.access_token}`},body:JSON.stringify({jobId:e.id,formType:e.form_type,formData:e.form_data})});if(!r.ok){let e=await r.json().catch(()=>({error:"Unknown error"}));console.error(`❌ Processing trigger failed: `,e),A("failed"),q("Failed to start research. Please try again.")}}catch(e){console.error("❌ Failed to trigger processing:",e),A("failed"),q("Failed to start research. Please try again.")}},eh=async()=>
19{if(L){try{let e=await fetch(`/api/jobs/${L}/status`);if(e.ok){let t=await e.json();if("completed"===t.status){A("completed"),t.research_data&&Z(t.research_data);let e=new Audio("https://cdn.pixabay.com/audio/2022/07/26/audio_124bfae5c8.mp3");e.volume=.2,e.play().catch(()=>{})}else"failed"===t.status?(A("failed"),q(t.webhook_error_message||"Failed to generate research. Please try again.")):"processing"===t.status&&A("processing");return t}}catch(e){console.error("Failed to poll job status:",e)}return null}};(0,l.useEffect)(()=>{if(!r.isReady)return;let e=r.query.jobId||null;if(!e){A("failed"),q("No job ID provided");return}A("loading"),Z(null),q(null),ea(null),en([]),(async()=>{let t=async()=>{try{let t=await fetch(`/api/jobs/${e}/status`);if(t.ok)return await t.json()}catch(e){console.error("Failed to fetch job status:",e)}return null},r=await t();if(r){var s,a,o,n;let e=(null==(s=r.form_data)?void 0:s.Brand)||(null==(a=r.form_data)?void 0:a.Topic)||"";if(e&&N(e),(null==(o=r.form_data)?void 0:o["Country/Region"])&&_(r.form_data["Country/Region"]),(null==(n=r.form_data)?void 0:n.brief)&&S(r.form_data.brief),"completed"===r.status){A("completed"),r.research_data&&Z(r.research_data);return}if("failed"===r.status){A("failed"),q(r.webhook_error_message||"Failed to generate research. Please try again.");return}"submitted"===r.status&&(A("processing"),B(J[0]),await eu(r)),"processing"===r.status&&(A("processing"),B(J[0]))}else A("failed"),q("Job not found")})()},[r.isReady,r.query.jobId,J,L]),(0,l.useEffect)(()=>{W("opacity-0");let e=setTimeout(()=>{z(I),W("opacity-100")},700);return()=>clearTimeout(e)},[I]),(0,l.useEffect)(()=>{if("processing"!==R&&"loading"!==R||0===J.length)return;let e=setInterval(()=>{B(e=>{let t=(J.indexOf(e)+1)%J.length;return J[t]})},5500);return()=>clearInterval(e)},[R,J]),(0,l.useEffect)(()=>{if("processing"!==R)return;let e=setInterval(eh,1e4);return()=>clearInterval(e)},[R,L]);let ex=(0,l.useMemo)(()=>X?{...X,region:E}:null,[X,E]),ep=(0,l.useCallback)((e,t)=>{ea(()=>e),en(t)},[]),em=(null==t?void 0:t.title)||`${"completed"===R?`Research for ${b} is ready!`:"failed"===R?"Something went wrong":`Conducting research for ${b}...`} | Selfstorming`,ef=(null==t?void 0:t.description)||"Two search engines race. Third agent delivers a visual dossier in 3 minutes.",eg=(null==t?void 0:t.image)||"/og-images/Research-session.png",ey=null==t?void 0:t.url;return(0,s.jsxs)(d.A,{children:[(0,s.jsxs)(c(),{children:[(0,s.jsx)("title",{children:em}),(0,s.jsx)("meta",{name:"description",content:ef}),(0,s.jsx)("meta",{property:"og:type",content:"article"}),(0,s.jsx)("meta",{property:"og:title",content:em}),(0,s.jsx)("meta",{property:"og:description",content:ef}),(0,s.jsx)("meta",{property:"og:image",content:eg}),ey&&(0,s.jsx)("meta",{property:"og:url",content:ey}),(0,s.jsx)("meta",{property:"og:site_name",content:"Selfstorming"}),(0,s.jsx)("meta",{name:"twitter:card",content:"summary_large_image"}),(0,s.jsx)("meta",{name:"twitter:title",content:em}),(0,s.jsx)("meta",{name:"twitter:description",content:ef}),(0,s.jsx)("meta",{name:"twitter:image",content:eg})]}),L&&"completed"===R&&(0,s.jsxs)("div",{className:"w-full mb-2 flex justify-center items-center gap-4 flex-wrap",children:[C&&(0,s.jsxs)("button",{onClick:()=>Q(!0),className:"flex items-center gap-2 hover:opacity-80 transition-opacity cursor-pointer text-[#39615F]",children:[(0,s.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:[(0,s.jsx)("path",{d:"M5.625 1.5c-1.036 0-1.875.84-1.875 1.875v17.25c0 1.035.84 1.875 1.875 1.875h12.75c1.035 0 1.875-.84 1.875-1.875V12.75A3.75 3.75 0 0 0 16.5 9h-1.875a1.875 1.875 0 0 1-1.875-1.875V5.25A3.75 3.75 0 0 0 9 1.5H5.625Z"}),(0,s.jsx)("path",{d:"M12.971 1.816A5.23 5.23 0 0 1 14.25 5.25v1.875c0 .207.168.375.375.375H16.5a5.23 5.23 0 0 1 3.434 1.279 9.768 9.768 0 0 0-6.963-6.963Z"})]}),(0,s.jsx)("span",{className:"text-sm",children:"View brief"})]}),(0,s.jsxs)("button",{onClick:()=>{let e=`${window.location.origin}/tools/deep-research/share/${L}`;er(e),navigator.clipboard.writeText(e).catch(console.error),Y(!0)},className:"flex items-center gap-2 hover:opacity-80 transition-opacity cursor-pointer text-[#39615F]",children:[(0,s.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"
19currentColor",className:"w-4 h-4",children:(0,s.jsx)("path",{d:"M11.47 1.72a.75.75 0 0 1 1.06 0l3 3a.75.75 0 0 1-1.06 1.06l-1.72-1.72V7.5h-1.5V4.06L9.53 5.78a.75.75 0 0 1-1.06-1.06l3-3ZM11.25 7.5V15a.75.75 0 0 0 1.5 0V7.5h3.75a3 3 0 0 1 3 3v9a3 3 0 0 1-3 3h-9a3 3 0 0 1-3-3v-9a3 3 0 0 1 3-3h3.75Z"})}),(0,s.jsx)("span",{className:"text-sm",children:"Share this research"})]}),(0,s.jsx)(p.e,{researchHistory:P,currentJobId:L??void 0,currentJobData:null,onSelectJob:e=>{"new"===e?window.location.href="/tools/research":window.location.href=`/tools/deep-research?jobId=${e}`},onJobDeleted:()=>{T([]),r.reload()}}),es&&(0,s.jsxs)("button",{onClick:async()=>{if(!el&&es){ei(!0),k.oR.loading("Exporting presentation...",{id:"export-pptx"});try{await es(),k.oR.success("Presentation exported successfully!",{id:"export-pptx"})}catch(e){console.error("Error exporting to PPTX:",e),k.oR.error("Failed to export presentation. Please try again.",{id:"export-pptx"})}finally{ei(!1)}}},disabled:el,className:"flex items-center gap-2 hover:opacity-80 transition-opacity cursor-pointer text-[#39615F] disabled:opacity-50 disabled:cursor-not-allowed",children:[(0,s.jsx)(v.A,{className:"w-4 h-4"}),(0,s.jsx)("span",{className:"text-sm",children:el?"Exporting...":"Export to PPTX"})]})]}),(!L||"failed"===R)&&(0,s.jsx)("div",{className:"w-full mb-4 flex justify-center",children:(0,s.jsx)(p.e,{researchHistory:P,currentJobId:L??void 0,currentJobData:null,onSelectJob:e=>{"new"===e?window.location.href="/tools/research":window.location.href=`/tools/deep-research?jobId=${e}`},onJobDeleted:()=>{T([]),r.reload()}})}),(0,s.jsx)("main",{className:"flex flex-1 flex-col items-center justify-center w-full px-4 pb-12 bg-white min-h-screen",children:X&&ex?(0,s.jsxs)("div",{className:"w-full my-8",children:[(0,s.jsx)(h.Se,{article:ex,onExportReady:ep,scrollToExtendedCategory:ec}),L&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(f,{jobId:L,currentArticle:X,onArticleExtended:e=>{Z(e),ed(!0),setTimeout(()=>ed(!1),2e3)}}),"completed"===R&&(0,s.jsxs)("div",{className:"w-full mt-8 flex justify-center items-center gap-4 flex-wrap",children:[C&&(0,s.jsxs)("button",{onClick:()=>Q(!0),className:"flex items-center gap-2 hover:opacity-80 transition-opacity cursor-pointer text-[#39615F]",children:[(0,s.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:[(0,s.jsx)("path",{d:"M5.625 1.5c-1.036 0-1.875.84-1.875 1.875v17.25c0 1.035.84 1.875 1.875 1.875h12.75c1.035 0 1.875-.84 1.875-1.875V12.75A3.75 3.75 0 0 0 16.5 9h-1.875a1.875 1.875 0 0 1-1.875-1.875V5.25A3.75 3.75 0 0 0 9 1.5H5.625Z"}),(0,s.jsx)("path",{d:"M12.971 1.816A5.23 5.23 0 0 1 14.25 5.25v1.875c0 .207.168.375.375.375H16.5a5.23 5.23 0 0 1 3.434 1.279 9.768 9.768 0 0 0-6.963-6.963Z"})]}),(0,s.jsx)("span",{className:"text-sm",children:"View brief"})]}),(0,s.jsxs)("button",{onClick:()=>{let e=`${window.location.origin}/tools/deep-research/share/${L}`;er(e),navigator.clipboard.writeText(e).catch(console.error),Y(!0)},className:"flex items-center gap-2 hover:opacity-80 transition-opacity cursor-pointer text-[#39615F]",children:[(0,s.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:(0,s.jsx)("path",{d:"M11.47 1.72a.75.75 0 0 1 1.06 0l3 3a.75.75 0 0 1-1.06 1.06l-1.72-1.72V7.5h-1.5V4.06L9.53 5.78a.75.75 0 0 1-1.06-1.06l3-3ZM11.25 7.5V15a.75.75 0 0 0 1.5 0V7.5h3.75a3 3 0 0 1 3 3v9a3 3 0 0 1-3 3h-9a3 3 0 0 1-3-3v-9a3 3 0 0 1 3-3h3.75Z"})}),(0,s.jsx)("span",{className:"text-sm",children:"Share this research"})]}),(0,s.jsx)(p.e,{researchHistory:P,currentJobId:L??void 0,currentJobData:null,onSelectJob:e=>{"new"===e?window.location.href="/tools/research":window.location.href=`/tools/deep-research?jobId=${e}`},onJobDeleted:()=>{T([]),r.reload()}}),es&&(0,s.jsxs)("button",{onClick:async()=>{if(!el&&es){ei(!0),k.oR.loading("Exporting presentation...",{id:"export-pptx"});try{await es(),k.oR.success("Presentation exported successfully!",{id:"export-pptx"})}catch(e){console.error("Error exporting to PPTX:",e),k.oR.error("Failed to export presentation. Please try again.",{id:"export-pptx"})}finally{ei(!1)}}},disabled:el,className:"flex items-center gap-2 hover:opacity-80 transition-opacity cursor-pointer text-[#39615F] disabled:opacity-50 disabled:cursor-not-allowed",children:[(0,s.jsx)(v.A,{className:"w-4 h-4"}),(0,s.jsx)("span",{className:"text-sm",children:el?"Exporting...":"Export to PPTX"})]})]})]})]}):(0,s.jsx)("div",{className:"text-center max-w-2xl",children:"failed"===R?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("h1",{className:"text-4xl md:text-5xl font-gloock text-slate-900 dark:text-slate-100 mb-6 text-center",children:(null==O?void 0:O.toLowerCase().includes("timed out"))?"Research timed out":"Something went wrong"}),(0,s.jsx)("p",{className:"text-slate-700 dark:text-slate-300 text-lg mb-8 leading-relaxed",children:(null==O?void 0:O.toLowerCase().includes("timed out"))?"The research service timed out. This usually happens with very long or complex briefs. Try shortening your brief or being more specific about what you need researched.":O||"We encountered an issue conducting your research."}),(0,s.jsxs)("div",{className:"flex gap-4 justify-center flex-wrap",children:[(0,s.jsx)(n.$,{onClick:()=>r.push("/tools/research"),className:"bg-white text-brand-blue text-lg rounded-xl py-4 px-6 hover:bg-gray-100 transition",children:"Go back and edit brief"}),(0,s.jsx)(n.$,{onClick:()=>window.history.back(),variant:"outline",className:"text-lg rounded-xl py-4 px-6 transition",children:"Try again"})]})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"text-slate-600 text-base font-medium leading-relaxed mb-8",children:"Give us 2-3 minutes to dig up something smart."}),(0,s.jsx)("h1",{className:`text-4xl md:text-5xl font-gloock mb-8 text-center min-h-[120px] md:min-
19h-[140px] flex items-center justify-center transition-opacity duration-700 leading-relaxed ${D}`,style:{color:"#39615F"},children:V||`Conducting research for ${b}...`}),(0,s.jsxs)("div",{className:"inline-flex items-center justify-center mb-8",children:[(0,s.jsx)("style",{dangerouslySetInnerHTML:{__html:`
20                          @keyframes float {
21                            0%, 100% { transform: translateY(0px); }
22                            50% { transform: translateY(-8px); }
23                          }
24                          @keyframes pulse-blink {
25                            0%, 100% { opacity: 1; }
26                            50% { opacity: 0.4; }
27                          }
28                          .animate-cloud-loader { animation: float 1s ease-in-out infinite, pulse-blink 1.6s ease-in-out infinite; }
29                        `}}),(0,s.jsx)("img",{src:"/lovable-uploads/cloud-loader.png",alt:"Loading",width:64,height:64,className:"animate-cloud-loader"})]})]})})}),(0,s.jsx)(j,{isOpen:U,shareUrl:et,onClose:()=>Y(!1)}),(0,s.jsx)(w.lG,{open:G,onOpenChange:Q,children:(0,s.jsxs)(w.Cf,{className:"max-w-2xl max-h-[80vh] flex flex-col p-0 overflow-hidden",children:[(0,s.jsx)(w.c7,{className:"px-6 pt-6 pb-3 border-b border-slate-200",children:(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)(w.L3,{className:"text-xs uppercase tracking-[0.15em] text-slate-500 font-semibold",children:"Original brief"}),(0,s.jsx)("button",{type:"button",onClick:async()=>{try{await navigator.clipboard.writeText(C),ee(!0),setTimeout(()=>ee(!1),2e3)}catch(e){console.error("Copy failed:",e)}},className:"text-slate-500 hover:text-black transition-colors","aria-label":K?"Copied":"Copy brief",title:K?"Copied":"Copy brief",children:K?(0,s.jsx)("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:3,children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}):(0,s.jsxs)("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[(0,s.jsx)("rect",{x:"9",y:"9",width:"11",height:"11",rx:"2"}),(0,s.jsx)("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})]})}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-5",children:(0,s.jsx)("p",{className:"text-sm md:text-base text-slate-700 leading-relaxed whitespace-pre-wrap break-words",children:C||"(no brief captured)"})})]})})]})}}},e=>{e.O(0,[8230,8684,1377,7490,6100,3490,6860,9036,9491,4693,5622,636,6593,8792],()=>e(e.s=80756)),_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.