1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4851],{2135:(e,t,n)=>{n.d(t,{A:()=>y});var a=n(37876),r=n(13734),l=n(81521),o=n(69334),i=n(4703),s=n(10875),c=n(39245);let d=(e,t,n)=>{var a;if(!n)return null;let r=e.tempRoutine.pages.find(e=>e.url===n);return!(null==r?void 0:r.htmlContent)||(null==(a=r.shortDesc)?void 0:a.includes("onload:dynamic"))?null:{pageUrl:n,htmlContent:r.htmlContent}},u=async(e,t,n,a,r,c)=>{let u=(e=>{try{var t,n;let a=null==e?void 0:e.actionType;if("special4rthAINavigation"!==a&&"navigate"!==a)return null;return null!=(n=null==e||null==(t=e.payload)?void 0:t.route)?n:null}catch(e){return null}})(n);if(u){let t=d(o.store.getState(),a,u);if(t)return e((0,i.ID)({routineId:a,htmlContent:t.htmlContent,url:t.pageUrl,source:"navigation"})),null}let p=r?{id:r.id,instructions:r.instructions,llm_wrapper:r.llm_wrapper}:null,{data:m,status:g}=await l.A.post("/api/v1/ask_llm/start",{payload:n,routineId:a,currentUrl:t.url,optionalRoutine:p,buildId:c},{timeout:9e4}),h=await (0,s.H)(m,g),f=h.htmlContent||(()=>{var e;let t=d(o.store.getState(),a,h.pageUrl);return null!=(e=null==t?void 0:t.htmlContent)?e:null})();if(f){let r=h.pageUrl&&h.pageUrl!==t.url,l=(null==n?void 0:n.actionType)==="PAGE_LOAD"?"page_load":u||r?"navigation":"user_action";e((0,i.ID)({routineId:a,htmlContent:f,url:h.pageUrl,source:l})),e((0,i.zw)({routineId:a,userSummary:(e=>{var t,n;let a=(null==e||null==(t=e.payload)?void 0:t.message)||(null==e||null==(n=e.payload)?void 0:n.text)||(null==e?void 0:e.query)||"";return a?a.slice(0,80):(null==e?void 0:e.actionType)||"action"})(n),pageUrl:h.pageUrl,htmlContent:f}))}return h.message},p=function(e,t,n,a){let l=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;u(e,{url:t},{actionType:"PAGE_LOAD",type:"PAGE_LOAD",source:"4rthAI"},n,a,l).catch(a=>{console.warn("[triggerDynamicPageLoad] failed:",a),"FORBIDDEN"!==a.code&&r.oR.error((0,c.u1)(a.code),{position:"bottom-right"});let l=o.store.getState().tempRoutine.pages.find(e=>e.url===t);(null==l?void 0:l.htmlContent)&&e((0,i.ID)({routineId:n,htmlContent:l.htmlContent,url:l.url,source:"page_load"}))})};var m=n(31777),g=n(14232),h=n(80813);let f=["localhost","4rth.ai"];var x=n(6365),v=n(90589);async function w(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=[],r={};Object.entries(e).forEach(e=>{let[t,n]=e;r[t]=function e(t,n){return t instanceof File?(a.push({id:n,file:t}),n):Array.isArray(t)?t.map((t,a)=>e(t,"".concat(n,"::").concat(a))):t}(n,t)});let l=await Promise.all(a.map(async e=>({...e,hash:await (0,v._)(e.file)}))),{uploaded:o,failed:i}=await (0,v.A)(l,()=>{},t,0,n),s={};o.forEach(e=>{s[e.id]=e});let c={};a.forEach(e=>{let{id:t,file:n}=e;c[t]=n});let d={};return Object.entries(r).forEach(e=>{let[t,n]=e,a=function e(t){if(Array.isArray(t))return t.map(e).filter(e=>null!==e);let n=s[t];if(!n)return null;let a=c[t];return{url:n.public_url,name:n.filename||a.name,size:n.file_size||a.size,mime_type:a.type,file_id:n.file_id}}(n);null!==a&&(d[t]=a)}),{fileObjects:d,failed:i}}function y(e){let t,{routineId:n,optionalRoutine:o=!1}=e,s=(0,m.wA)(),d=(0,m.d4)(e=>e.tempRoutine.draftBuildId),v=(0,m.d4)(e=>e.tempRoutine.webPage),y=(0,m.d4)(e=>e.tempRoutine.pages),b=(0,m.d4)(e=>e.tempRoutine.chat.aiStatus),{startUpload:_}=(0,h.k)(n),E=(0,g.useRef)(null),j="GTM-PWXL6WCX";async function A(e,t){let a=(null==e?void 0:e.payload)||{},l=a.files||[];if(!Array.isArray(l)||0===l.length)return r.oR.warning("No files received for upload.",{position:"top-right"}),null;try{var o,c,u,p;r.oR.info("Uploading files...",{position:"top-right"});let m=await t(l),g=null!=(u=null==m||null==(o=m.uploaded)?void 0:o.length)?u:0,h=null!=(p=null==m?void 0:m.invalidCount)?p:0;if(0===g){let e=!!d,t=h>0?"Unsupported file type or file too large. Please check the file and try again.":e?(null==m?void 0:m.error)||"File upload failed. Please try again.":"File upload is temporarily unavailable. Please try again later.";return r.oR.error(t,{position:"top-right"}),s((0,i.ID)({routineId:n,htmlContent:v.htmlContent,url:v.url,source:"user_action"})),null}return(null==m||null==(c=m.failed)?void 0:c.length)>0?r.oR.warning("".concat(m.failed.length," file(s) failed to upload."),{position:"top-right"}):r.oR.success("Files uploaded successfully.",{position:"top-right"}),{...e,payload:{...a,files:m}}}catch(t){console.error("File upload failed:",t),r.oR.error(t.message||"File upload failed. Please try again.",{position:"top-right"});let e=y.find(e=>e.url===v.url);return(null==e?void 0:e.htmlContent)&&s((0,i.ID)({routineId:n,htmlContent:e.htmlContent,url:e.url,source:"user_action"})),null}}return!function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=(0,g.useRef)(!1);(0,g.useEffect)(()=>{let t=async t=>{if(!n.current){n.current=!0;try{await e(t.origin,t.data)}catch(e){console.error("Error handling iframe message:",e)}finally{n.current=!1}}};return window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}},t)}(async(e,t)=>{if(console.log("Received iframe message:",e,t),!function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:f;return!!e&&"string"==typeof e&&t.some(t=>e.includes(t))}(e))return void console.warn("Blocked message from disallowed origin: ".concat(e));if(t&&"resize"!==t.actionType&&"iframeHeight"!==t.type&&"setHeight"!==t.actionType&&"react-devtools-bri
1dge"!==t.source&&"react-devtools-content-script"!==t.source&&"4rthAI"===t.source){if("running"===b)return void r.oR.warning("The page is still being created, kindly wait",{position:"top-right"});if("__pageScriptLoopDetected"===t.actionType)return void window.dispatchEvent(new CustomEvent("pageScriptLoopDetected"));if("openExternalLink"===t.actionType){var a;let e=null==t||null==(a=t.payload)?void 0:a.url;e&&window.open(e,"_blank","noopener,noreferrer");return}if("fileIncludedSpecial"!==t.actionType){let{fileFieldMap:e,cleanPayload:a}=function(e){let t={},n={};return Object.entries(e||{}).forEach(e=>{let[a,r]=e;!function e(t){return t instanceof File||!!Array.isArray(t)&&t.some(e)}(r)?n[a]=r:t[a]=r}),{fileFieldMap:t,cleanPayload:n}}(t.payload||{});if(Object.keys(e).length>0){r.oR.info("Uploading files...",{position:"top-right"});let{fileObjects:l,failed:o}=await w(e,n,d||null);if(o.length>0&&r.oR.warning("".concat(o.length," file(s) failed to upload."),{position:"top-right"}),0===Object.keys(l).length)return void r.oR.error("File upload failed. Please try again.",{position:"top-right"});t={...t,payload:{...a,...l}},r.oR.success("Files uploaded.",{position:"top-right"})}}if("fileIncludedSpecial"===t.actionType&&!(t=await A(t,_)))return;try{let e=await u(s,v,t,n,o,d);e&&r.oR.success(e.slice(0,50),{position:"top-right"})}catch(t){"FORBIDDEN"!==t.code&&r.oR.error((0,c.u1)(t.code),{position:"bottom-right"});let e=y.find(e=>e.url===v.url);(null==e?void 0:e.htmlContent)&&s((0,i.ID)({routineId:n,htmlContent:e.htmlContent,url:e.url,source:"user_action"}))}}},[v,s,n,o,d]),(e=>{let{routineId:t,pageUrl:n}=e;(0,g.useEffect)(()=>{t&&n&&l.A.post("/api/log-page-visit",{routineId:t,pageUrl:n}).catch(e=>{console.error("Failed to log page visit:",e)})},[t,n])})({routineId:n,pageUrl:v.url||window.location.href}),(0,a.jsx)(a.Fragment,{children:(0,a.jsx)("iframe",{ref:E,title:"auto-height-iframe",srcDoc:(t=null==v?void 0:v.htmlContent,"".concat((0,x.$)(),"\n\x3c!-- Google Tag Manager --\x3e\n<script>\n(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\nnew Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\nj=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;
1j.src=\n'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\n})(window,document,'script','dataLayer','").concat(j,"');\n<\/script>\n\x3c!-- End Google Tag Manager --\x3e\n").concat(t,'\n<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=').concat(j,'"\nheight="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>\n')),onLoad:()=>{var e,t,a;v.isDynamic&&"build"===v.source&&(null==(a=E.current)||null==(t=a.contentWindow)||null==(e=t.__applyVars)||e.call(t,{is_loading:!0}),p(s,v.url,n,o,null!=d?d:null))},style:{width:"100%",height:"100%",border:"none",display:"block"},"data-hj-allow-iframe":"",allow:"microphone *",sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox allow-pointer-lock allow-modals allow-top-navigation"},v.version)})}},6365:(e,t,n)=>{n.d(t,{$:()=>a});function a(){let{threshold:e=1e3,windowMs:t=1e3}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return"<script>\n(function() {\n 'use strict';\n var _Orig = window.MutationObserver;\n if (!_Orig || window.__4rthMOGuardInstalled) return;\n window.__4rthMOGuardInstalled = true;\n\n var THRESHOLD = ".concat(e,";\n var WINDOW_MS = ").concat(t,";\n\n function _notifyParent() {\n try {\n window.parent.postMessage(\n { source: '4rthAI', actionType: '__pageScriptLoopDetected' }, '*'\n );\n } catch (_) {}\n }\n\n function _showBanner() {\n if (document.getElementById('__4rth_loop_err')) return;\n function _render() {\n var overlay = document.createElement('div');\n overlay.id = '__4rth_loop_err';\n overlay.setAttribute('role', 'alert');\n overlay.style.cssText = [\n 'position:fixed', 'inset:0', 'z-index:2147483647',\n 'background:rgba(0,0,0,0.82)',\n 'display:flex', 'align-items:center', 'justify-content:center',\n 'pointer-events:all', 'cursor:default',\n 'user-select:none', '-webkit-user-select:none',\n ].join(';');\n overlay.addEventListener('click', function(e) { e.stopPropagation(); });\n overlay.addEventListener('keydown', function(e) { e.stopPropagation(); });\n overlay.addEventListener('mousedown',function(e) { e.stopPropagation(); });\n overlay.addEventListener('touchstart',function(e){ e.stopPropagation(); e.preventDefault(); }, { passive: false });\n var card = document.createElement('div');\n card.style.cssText = [\n 'background:#fff', 'border-radius:12px',\n 'padding:32px 28px', 'max-width:380px', 'width:90%',\n 'text-align:center', 'box-shadow:0 8px 32px rgba(0,0,0,.4)',\n 'font-family:sans-serif',\n ].join(';');\n var icon = document.createElement('div');\n icon.textContent = '\\u26a0\\ufe0f';\n icon.style.cssText = 'font-size:36px;margin-bottom:12px;';\n var title = document.createElement('p');\n title.style.cssText = 'font-size:15px;font-weight:700;color:#111;margin:0 0 8px;';\n title.textContent = 'Page stopped';\n var msg = document.createElement('p');\n msg.style.cssText = 'font-size:13px;color:#555;margin:0;line-height:1.5;';\n msg.textContent = 'This page stopped responding. Regenerate to fix it.';\n card.appendChild(icon);\n card.appendChild(title);\n card.appendChild(msg);\n overlay.appendChild(card);\n document.body.appendChild(overlay);\n }\n document.body ? _render() : document.addEventListener('DOMContentLoaded', _render);\n }\n\n function GuardedMO(cb) {\n var count = 0, resetAt = Date.now(), stopped = false;\n var obs = new _Orig(function(mutations, inner) {\n if (stopped) return;\n var now = Date.now();\n if (now - resetAt > WINDOW_MS) { count = 0; resetAt = now; }\n count++;\n if (count > THRESHOLD) {\n stopped = true;\n inner.disconnect();\n console.error(\n '[4rth guard] MutationObserver loop stopped â ' + count +\n ' fires in ' + WINDOW_MS + 'ms. Callback: ' +\n cb.toString().slice(0, 150)\n );\n _showBanner();\n _notifyParent();\n return;\n }
1\n try { cb(mutations, inner); } catch (e) {\n console.error('[4rth guard] MutationObserver callback threw:', e);\n }\n });\n return obs;\n }\n\n GuardedMO.prototype = _Orig.prototype;\n Object.defineProperty(GuardedMO, Symbol.hasInstance, {\n value: function(inst) { return inst instanceof _Orig; },\n });\n\n window.MutationObserver = GuardedMO;\n})();\n<\/script>")}},10875:(e,t,n)=>{n.d(t,{H:()=>s,y:()=>o});var a=n(81521),r=n(21338),l=n(39245);let o=async e=>{let{routineId:t}=e,{fetchHomePage:r}=await Promise.resolve().then(n.bind(n,69467));try{let{data:e}=await a.A.post("/api/v1/execution/start",{routineId:t}),{pageUrl:n,htmlContent:r,isDynamic:l}=e;return{url:null!=n?n:null,htmlContent:null!=r?r:null,isDynamic:null!=l&&l}}catch(e){return console.error("[fetchAppStart] failed, falling back to static homepage:",e),r({routineId:t})}},i={200:e=>Promise.resolve(e.result),202:e=>(e=>{let t=Date.now();return new Promise((n,o)=>{let i=setInterval(async()=>{if(Date.now()-t>18e4){clearInterval(i),o(new l.hD(l.pH.TIMEOUT.msg,l.pH.TIMEOUT.code));return}try{let{data:s}=await a.A.get("/api/v1/ask_llm/status",{params:{task_id:e}});"SUCCESS"===s.state&&(clearInterval(i),(0,r.u)("build_duration",{endpoint:"/api/v1/ask_llm/status",duration_ms:Date.now()-t,task_id:e}),n(s.result)),"FAILURE"===s.state&&(clearInterval(i),(0,r.u)("app_run_failed",{endpoint:"/api/v1/ask_llm/status",task_id:e,error:s.message||"FAILURE"}),o(new l.hD(l.pH.TASK_FAILED.msg,l.pH.TASK_FAILED.code)))}catch(e){clearInterval(i),o(e)}},3e3)})})(e.task_id)},s=(e,t)=>{var n;return(null!=(n=i[t])?n:i[202])(e)}},12722:(e,t,n)=>{n.d(t,{zy:()=>a});let a=e=>{let{instructions:t,instructionAttachments:n}=(e=>{let t=[],n=[];return e.forEach(e=>{t.push(e.text),n.push(e.attachments)}),{instructions:t,instructionAttachments:n}})(e.instructions||[]);return{...e,instructions:t,instructionAttachments:n}}},37699:(e,t,n)=>{n.d(t,{I:()=>r});var a=n(81521);async function r(){let{data:e}=await a.A.post("".concat("/api/v1","/reset_task"));return e}},44107:(e,t,n)=>{n.d(t,{d:()=>o});var a=n(37876),r=n(18847);let l=n.n(r)()(()=>Promise.all([n.e(3504),n.e(3283),n.e(6104)]).then(n.bind(n,6104)),{loadableGenerated:{webpack:()=>[6104]},ssr:!1}),o={code(e){let{node:t,inline:n,className:r,children:o,...i}=e,s=/language-(\w+)/.exec(r||"");return!n&&s?(0,a.jsx)(l,{language:s[1],value:String(o).trim()}):(0,a.jsx)("code",{className:r,...i,children:o})},table(e){let{children:t}=e;return(0,a.jsx)("div",{style:{overflowX:"auto",margin:"1rem 0"},children:(0,a.jsx)("table",{style:{width:"100%",borderCollapse:"collapse"},children:t})})},th(e){let{children:t}=e;return(0,a.jsx)("th",{style:{padding:"0.5rem",textAlign:"left",borderBottom:"1px solid #ddd",backgroundColor:"#f9f9f9"},children:t})},td(e){let{children:t}=e;return(0,a.jsx)("td",{style:{padding:"0.5rem",borderBottom:"1px solid #eee"},children:t})},ul(e){let{children:t}=e;return(0,a.jsx)("ul",{style:{listStyleType:"disc",paddingLeft:"1.25rem",margin:"0.25rem 0"},children:t})},ol(e){let{children:t}=e;return(0,a.jsx)("ol",{style:{listStyleType:"decimal",paddingLeft:"1.25rem",margin:"0.25rem 0"},children:t})},li(e){let{children:t}=e;return(0,a.jsx)("li",{style:{margin:"0.15rem 0"},children:t})}}},57492:(e,t,n)=>{n.d(t,{do:()=>c});var a=n(81521),r=n(39245),l=n(21338);let o="/api/v1";async function i(e,t,n){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],{data:l}=await a.A.post("".concat(o,"/execute_task/start"),{routineId:e,optionalRoutine:t,userInput:n,userInputAttachment:r});return l.task_id}async function s(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:3e3,n=Date.now();for(;;){if(Date.now()-n>3e5)throw new r.hD("Task is taking too long. Please try again.",r.pH.TIMEOUT.code);await new Promise(e=>setTimeout(e,t));let{data:i}=await a.A.get("".concat(o,"/execute_task/status"),{params:{task_id:e}});if("SUCCESS"===i.state)return(0,l.u)("build_duration",{endpoint:"".concat(o,"/execute_task/status"),duration_ms:Date.now()-n,task_id:e}),i;if("FAILURE"===i.state)throw(0,l.u)("app_run_failed",{endpoint:"".concat(o,"/execute_task/status"),task_id:e,error:i.message||"FAILURE"}),new r.hD(r.pH.TASK_FAILED.msg,r.pH.TASK_FAILED.code)}}
1async function c(e,t,n){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],r=await i(e,t,n,a);return await s(r)}},80813:(e,t,n)=>{n.d(t,{k:()=>s});var a=n(14232),r=n(13734),l=n(1608),o=n(90589);let i=["pdf","doc","docx","pptx","txt","md","json","csv","xlsx","xls","svg","py","java","jpg","jpeg","png","webp","gif"];function s(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,[s,c]=(0,a.useState)([]),d=(e,t)=>c(n=>n.map(n=>n.id===e?{...n,...t}:n));return{startUpload:async a=>{if(!(null==a?void 0:a.length))return[];let{valid:u,invalid:p}=((e,t)=>{let n=[],a=[];return e.forEach(e=>{let t=e.name.split(".").pop().toLowerCase();i.includes(t)?e.size>0xa00000?a.push({file:e,errorMessage:"File is ".concat((e.size/1024/1024).toFixed(1)," MB. Max allowed is ").concat(10," MB.")}):n.push(e):a.push({file:e,errorMessage:"Unsupported file type. Allowed: ".concat(i.join(", "),".")})}),{valid:n,invalid:a}})(a,0),m=((e,t)=>{let n=t.reduce((e,t)=>e+(t.size||0),0),a=e.reduce((e,t)=>e+t.size,0);return n+a>0x6400000?"Cannot add ".concat((a/1024/1024).toFixed(1)," MB â total would exceed the ").concat(100," MB request limit. You currently have ").concat((n/1024/1024).toFixed(1)," MB attached."):null})(u,s);if(m)return{totalError:m};if(p.length>0){let e=p.map(e=>{let{file:t,errorMessage:n}=e;return{id:"invalid-".concat(t.name,"-").concat(Date.now(),"-").concat(Math.random().toString(36).slice(2,6)),filename:t.name,size:t.size,status:"invalid",errorMessage:n,progress:0}});c(t=>[...t,...e])}if(!u.length)return{uploaded:[],failed:[],invalidCount:p.length};let g=await (0,l.s)(u);c(e=>[...e,...g.map(e=>({...e,status:"uploading",progress:1}))]);let h=await Promise.all(g.map(async e=>{let t=u.find(t=>t.name===e.filename),n=await (0,o._)(t);return{id:e.id,file:t,hash:n}}));try{let{uploaded:a,failed:l}=await (0,o.A)(h,d,e,t,n);return l.length>0&&r.oR.error("".concat(l.length," file(s) failed to upload.")),{uploaded:a,failed:l,invalidCount:p.length}}catch(e){return console.error("Upload error:",e),g.forEach(e=>{let{id:t}=e;return d(t,{status:"error",progress:0})}),{error:e.message||"Upload failed. Please remove the file and try again later.",uploaded:[]}}},attachedFiles:s,updateFile:d,removeFile:e=>c(t=>t.filter(t=>t.id!==e))}}},95443:(e,t,n)=>{n.d(t,{A:()=>j});var a=n(37876),r=n(14232);n(48230);var l=n(13734),o=n(39180),i=n(87979);n(93754);var s=n(44107);let c=e=>{let{message:t="4rthAI is thinking..."}=e;return(0,a.jsxs)("div",{className:"flex items-center gap-1.5 py-2 px-3",children:[(0,a.jsxs)("div",{className:"flex gap-1",children:[(0,a.jsx)("div",{className:"w-2 h-2 bg-[#4F46E5] rounded-full animate-ping"}),(0,a.jsx)("div",{className:"w-2 h-2 bg-[#4F46E5] rounded-full animate-bounce [animation-delay:150ms]"}),(0,a.jsx)("div",{className:"w-2 h-2 bg-[#4F46E5] rounded-full animate-bounce [animation-delay:300ms]"})]}),(0,a.jsx)("p",{className:"text-sm text-gray-500",children:t})]})};var d=n(20656),u=n(31777),p=n(89099),m=n(12572),g=n(1328),h=n(34297),f=n(28249),x=n(28113),v=n(57466),w=n(12722),y=n(57492);let b={message:"",attachments:[]},_={FILE_READ:"reading a file",FILE_WRITE:"writing a file",WEB_SEARCH:"searching the web",CREATE_TABLE:"creating tables",SHELL_CMD:"running a shell command",GRAPH_GEN:"creating a graph"},E=()=>(0,a.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3 mx-2 mb-2 w-fit rounded-[10px] bg-[rgba(44,127,255,0.06)] border border-[rgba(44,127,255,0.15)]",children:[(0,a.jsx)("div",{className:"w-4 h-4 rounded-full flex-shrink-0 border-2 border-[rgba(44,127,255,0.2)] border-t-[#2C7FFF] [animation:spin_0.75s_linear_infinite]"}),(0,a.jsx)("span",{className:"text-[#2C7FFF] italic text-[0.78rem] font-medium",children:"Starting upâ¦"})]});function j(e){let{routineId:t,savedInstructions:n=[],setIsLoginFormVisible:j=()=>{},autoStart:A=!0}=e,C=(0,u.wA)();(0,p.useRouter)();let[k,F]=(0,r.useState)(null),D=(0,u.d4)(e=>e.conversation),N=(0,u.d4)(e=>e.tempRoutine.chat.aiStatus),[R,I]=(0,r.useState)(!0),[L,T]=(0,r.useState)(b),S=n.find(e=>e.id===t),P="running"===N&&!D.isFetching&&0===D.messages.length,O=async()=>{I(!1),C((0,v.rt)(!0));try{var e;if(0==L.message.length&&0==L.attachments.length)return;C((0,v.pk)({content:L.message,role:"user",attachments:L.attachments})),T(e=>({...e,message:"",attachments:[]}));let n=(0,w.zy)(S),a=(e=L.message,/search|google|find/i.test(e)?_.WEB_SEARCH:/read|open.*file/i.test(e)?_.FILE_READ:/write|save/i.test(e)?_.FILE_WRITE:/table|schema/i.test(e)?_.CREATE_TABLE:/command|bash|shell/i.test(e)?_.SHELL_CMD:/graph|chart|plot/i.test(e)?_.GRAPH_GEN:null);F(a);let r=await (0,y.do)(t,n,L.message,L.attachments);F(null);let{mode:l,message:o,isFileOps:i}=r;i&&C((0,d.Qt)(S.id)),C((0,v.pk)({content:o,role:"assistant",attachments:[]}))}catch(e){l.oR.error(e.message||"Something went wrong. Please try again.")}finally{I(!0),C((0,v.rt)(!1))}},M=e=>{let{filename:t,content:n,type:a}=e;console.log("Attachment to download:",e);try{let e=atob(n),r=Array.from(e).map(e=>e.charCodeAt(0)),l=new Uint8Array(r),o=a||"application/octet-stream";"text/plain"===a?o="text/plain":"application/pdf"===a?o="application/pdf":"application/vnd.openxmlformats-officedocument.wordprocessingml.document"===a?o="application/vnd.openxmlformats-officedocument.wordprocessingml.document":console.warn("Unsupported file type: ".concat(a,". Defaulting to application/octet-stream."));let i=new Blob([l],{type:o}),s=document.createElement("a");s.href=URL.createObjectURL(i),s.download=t||"downloaded_file",document.body.appendChild(s),s.click(),document.body.removeChild(s)}catch(e){console.error("Error downloading attachment:",e),l.oR.error("Failed to download the file. Please try again.")}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"flex flex-col gap-1"}),(0,a.jsxs)("div",{id:"chat-box-wrapper",className:"border border-[#
1E5E3D5] rounded-[6px] flex flex-col mt-14 lg:mt-10 overflow-hidden w-full h-[calc(100dvh-200px)]",children:[(0,a.jsx)("div",{className:"flex items-center px-4 py-4 bg-[#FCFCFF] border-b border-[#E5E3D5] flex-shrink-0",children:(0,a.jsx)("span",{className:"font-medium text-[#1C1917] text-sm",children:(null==S?void 0:S.name)||"Chat App Preview"})}),(0,a.jsxs)("div",{className:"overflow-y-auto p-6 bg-white flex-1 pb-24 lg:pb-6",children:[D.messages.map((e,t)=>{var n,r;return(0,a.jsxs)("div",{className:"flex items-start gap-2 mb-4 ".concat("user"===e.role?"flex-row-reverse":"flex-row"),children:[(0,a.jsx)("div",{className:"w-8 h-8 rounded-full flex items-center justify-center flex-shrink-0 ".concat("user"===e.role?"bg-gradient-to-br from-[#0f172a] to-[#334155]":"bg-gradient-to-br from-[#059669] to-[#10b981]"),children:"user"===e.role?(0,a.jsx)(m.A,{size:16,color:"white"}):(0,a.jsx)(g.A,{size:16,color:"white"})}),(0,a.jsxs)("div",{className:"mb-2 px-4 py-3 rounded-[10px] max-w-[85%] break-words text-sm font-medium leading-relaxed ".concat("user"===e.role?"bg-[#2C7FFF] text-white shadow-[0_2px_8px_rgba(0,0,0,0.1)] ml-auto":"bg-[#ffffff] text-[#3C4555] border border-[rgba(0,0,0,0.08)] shadow-[0_2px_8px_rgba(0,0,0,0.05)]"),children:[(0,a.jsx)(o.oz,{components:s.d,remarkPlugins:[i.A],children:(null==(n=e.attachments)?void 0:n.length)==0&&e.content}),(null==(r=e.attachments)?void 0:r.length)>0&&(0,a.jsx)("div",{className:"flex flex-wrap flex-col mt-2",children:e.attachments.map((e,t)=>(0,a.jsxs)("div",{className:"flex items-center gap-2 bg-black/4 rounded px-2 py-1 my-1",children:[(0,a.jsx)("button",{className:"mr-2 cursor-pointer p-0 bg-transparent border-none",onClick:()=>M(e),children:(0,a.jsx)(h.A,{size:14})}),(0,a.jsx)("span",{className:"text-sm text-[#78716C] cursor-pointer hover:underline",onClick:()=>M(e),children:e.filename})]},t))})]})]},t)}),P&&(0,a.jsx)(E,{}),k&&(0,a.jsx)("p",{className:"text-xs text-[#A8A29E] italic mt-1 ml-2",children:k}),D.isFetching&&(0,a.jsx)("div",{className:"flex",children:(0,a.jsx)("div",{className:"mb-2 px-4 py-3 rounded-xl flex items-center gap-2 text-sm font-medium bg-[#ffffff] text-[#3C4555] border border-[rgba(0,0,0,0.08)]",children:(0,a.jsx)(c,{message:"Generating the response..."})})})]}),L.attachments.length>0&&(0,a.jsx)("div",{className:"overflow-y-auto mt-2 max-h-[100px] bg-[#F3F3F5] border border-[#C1C1C1] rounded-lg p-2 w-full box-border mx-0",children:L.attachments.map((e,t)=>(0,a.jsxs)("div",{className:"flex items-center py-0.5 pl-2 pr-2",children:[(0,a.jsx)("div",{className:"min-w-[36px]",children:(0,a.jsx)("img",{src:"/Frame11.svg",alt:"Upload Icon",className:"w-[23px] h-[23px] object-contain"})}),(0,a.jsx)("span",{className:"flex-1 text-sm font-medium text-[#4A4A53] truncate",children:e.filename}),(0,a.jsxs)("div",{className:"flex items-center gap-2 ml-2",children:[(0,a.jsx)("button",{className:"p-1 hover:opacity-70 transition-opacity",onClick:()=>M(e),children:(0,a.jsx)("img",{src:"/download.png",alt:"Download",className:"w-6 h-6"})}),(0,a.jsx)("button",{className:"p-1 hover:opacity-70 transition-opacity ml-2",onClick:()=>(e=>{T(t=>({...t,attachments:t.attachments.filter((t,n)=>n!==e)}));let t=document.getElementById("chat-attachment");t&&(t.value="")}
1)(t),children:(0,a.jsx)(f.A,{size:16,className:"text-black"})})]})]},t))}),(0,a.jsx)("div",{className:"border-t border-[#E5E3D5] p-2 flex gap-2 items-center bg-white flex-shrink-0",children:(0,a.jsxs)("div",{className:"flex items-center w-full h-[54px] px-1 rounded-md shadow-[0px_0px_4px_0px_rgba(0,0,0,0.06)]",children:[(0,a.jsx)("input",{type:"text",value:L.message,onChange:e=>T(t=>({...t,message:e.target.value})),onKeyPress:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),O())},placeholder:"Type your message...",className:"flex-1 mr-2 text-[15px] font-medium text-black bg-transparent outline-none border-none px-2 placeholder-[#4D5765]"}),(0,a.jsx)("input",{accept:"*/*",className:"hidden",id:"chat-attachment",multiple:!0,type:"file",onChange:e=>{Promise.all(Array.from(e.target.files).map(e=>new Promise((t,n)=>{let a=new FileReader;a.onload=()=>{let n=a.result.split(",")[1];t({filename:e.name,content:n})},a.onerror=e=>n(e),a.readAsDataURL(e)}))).then(e=>{T(t=>({...t,attachments:[...t.attachments,...e]}))}).catch(e=>{console.error("Error reading chat attachments:",e),l.oR.error("Failed to read files.")}).finally(()=>{e.target.value=""})}},L.attachments.length),(0,a.jsx)("label",{htmlFor:"chat-attachment",className:"p-2 cursor-pointer",children:(0,a.jsx)(h.A,{size:18,color:"#1C1917"})}),(0,a.jsx)("button",{onClick:O,className:"w-10 h-10 flex items-center justify-center rounded-[6px] bg-[#2C7FFF] hover:bg-[#1e5ed8] transition-colors flex-shrink-0",children:(0,a.jsx)(x.A,{size:20,color:"#fff"})})]})})]})]})}}}]);
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.