PageSourceSearch

https://www.architect.new/_next/static/chunks/2988-5e3886cc7c57b1a2.js?dpl=dpl_APmwJ4sfr1ZZMiqssAejcG3MqAHC

js architect.new collected 2026-10-04 13:32:22 UTC 96,020 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2988],{65532:function(e,t,n){n.d(t,{D:function(){return p},MixpanelProvider:function(){return d}});var r=n(57437),i=n(2265),a=n(99376),o=n(59010),s=n(48522),l=n(46214),c=n(71487),u=n(4147);function d(e){let{children:t}=e,{user:n,isLoggedIn:d}=(0,o.a)(),{tenant_id:p,display_name:h}=(0,s.S)(),m=(0,a.usePathname)(),f=(0,i.useRef)(null),g=(0,i.useRef)(null),v=(0,i.useRef)(0),_=(0,i.useRef)(new Set),y=(0,i.useRef)(!1);return(0,i.useEffect)(()=>{(0,c.initMixpanel)(),(0,c.captureUTMParams)()},[]),(0,i.useEffect)(()=>{if(d&&(null==n?void 0:n.id)){let e=n.email||n.id,t="mp_login_tracked_".concat(n.id);sessionStorage.getItem(t)||((0,c.trackUserLoggedIn)(n.id),sessionStorage.setItem(t,"1")),(0,c.identifyUser)(n.id,{$email:e,$name:n.email?n.email.split("@")[0]:n.id});try{let t=(0,c.captureUTMParams)();l.ZP.identify(n.id,{email:e,name:n.email?n.email.split("@")[0]:n.id,memberstack_id:n.id,last_login:new Date().toISOString(),utm_source:t.utm_source,utm_medium:t.utm_medium,utm_campaign:t.utm_campaign}),l.ZP.setPersonProperties({},{initial_utm_source:t.utm_source,initial_utm_medium:t.utm_medium,initial_utm_campaign:t.utm_campaign,initial_utm_content:t.utm_content,initial_utm_term:t.utm_term,first_seen:new Date().toISOString(),initial_url:window.location.pathname})}catch(e){console.warn("[PostHog] Error during identify:",e)}try{window.clarity&&(window.clarity("identify",n.id,{email:e,memberstack_id:n.id}),window.clarity("set","email",e),window.clarity("set","memberstack_id",n.id),window.clarity("set","name",n.email?n.email.split("@")[0]:n.id))}catch(e){console.warn("[Clarity] Error during identify:",e)}(0,c.setSuperProperties)(e,{id:p,name:h}),(0,c.updateLastLogin)(n.id,e),f.current||(f.current=(0,u.Z)(),g.current=Date.now(),(0,c.trackSessionStarted)(n.id,f.current,m||"/")),y.current=!0}else if(!d&&y.current){if(f.current&&g.current&&(null==n?void 0:n.id)){let e=Math.floor((Date.now()-g.current)/1e3);(0,c.trackSessionEnded)(n.id,f.current,e,v.current,Array.from(_.current))}(0,c.resetMixpanel)();try{l.ZP.reset()}catch(e){console.warn("[PostHog] Error during reset:",e)}f.current=null,g.current=null,v.current=0,_.current.clear(),y.current=!1}},[d,n,m,p,h]),(0,i.useEffect)(()=>{"/"===m&&(0,c.trackHomepageViewed)(null==n?void 0:n.id),(0,c.trackPageView)(m,null==n?void 0:n.id)},[m,null==n?void 0:n.id]),(0,i.useEffect)(()=>{let e=()=>{if(f.current&&g.current&&(null==n?void 0:n.id)){let e=Math.floor((Date.now()-g.current)/1e3);if(navigator.sendBeacon){let t={event:"session_ended",properties:{user_id:n.id,session_id:f.current,duration_seconds:e,messages_sent:v.current,modes_used:Array.from(_.current),timestamp:new Date().toISOString(),token:"f4cdae196cbbc0ba44b76a81ea8a123a"}};navigator.sendBeacon("https://api.mixpanel.com/track",new Blob([JSON.stringify(t)],{type:"application/json"}))}}};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[null==n?void 0:n.id]),(0,i.useEffect)(()=>{window.__mixpanelSession={getSessionId:()=>f.current,incrementMessages:()=>v.current++,addMode:e=>_.current.add(e)}},[]),(0,r.jsx)(r.Fragment,{children:t})}let p=()=>({getSessionId:()=>{var e;return(null===(e=window.__mixpanelSession)||void 0===e?void 0:e.getSessionId())||null},incrementMessages:()=>{var e;null===(e=window.__mixpanelSession)||void 0===e||e.incrementMessages()},addMode:e=>{var t;null===(t=window.__mixpanelSession)||void 0===t||t.addMode(e)}})},93022:function(e,t,n){n.d(t,{N:function(){return o},O:function(){return a}});var r=n(57437),i=n(94508);function a(e){let{className:t,...n}=e;return(0,r.jsx)("div",{"aria-hidden":!0,className:(0,i.cn)("skeleton-shimmer rounded-md",t),...n})}function o(e){let{lines:t=3,widths:n,className:o}=e,s=null!=n?n:["100%","92%","68%","88%","74%"];return(0,r.jsx)("div",{className:(0,i.cn)("space-y-2",o),children:Array.from({length:t},(e,t)=>(0,r.jsx)(a,{className:"h-3",style:{width:s[t%s.length]}},t))})}},32174:function(e,t,n){n.d(t,{CL:function(){return o},GM:function(){return u},My:function(){return d},Nh:function(){return a},SR:function(){return s},Yl:function(){return h},mP:function(){return i},tb:function(){return l}});var r=n(95566);function i(e){return(null==e?void 0:e.agent_kind)==="voice"||(null==e?void 0:e.type)==="voice"}function a(e){var t,n,r,a,o;if(!e)return{hasKB:!1};if(i(e))return{hasKB:!!e.has_knowledge_base,ragId:e.rag_id||void 0,ragName:e.rag_name||void 0};let s=null===(t=e.features)||void 0===t?void 0:t.find(e=>"KNOWLEDGE_BASE"===e.type);return{hasKB:!!s,ragId:null==s?void 0:null===(r=s.config)||void 0===r?void 0:null===(n=r.lyzr_rag)||void 0===n?void 0:n.rag_id,ragName:null==s?void 0:null===(o=s.config)||void 0===o?void 0:null===(a=o.lyzr_rag)||void 0===a?void 0:a.rag_name}}function o(e){return e?i(e)?e.lyzr_tools||[]:e.tool_configs||[]:[]}function s(e,t){var n,i,a,o,s,l,c,u,d,p,h,m,f;let g=(null==t?void 0:null===(n=t.engine)||void 0===n?void 0:n.kind)==="realtime"?t.engine:void 0;return{...e,agent_kind:"voice",agent_name:null!==(c=null==t?void 0:t.agent_name)&&void 0!==c?c:null==e?void 0:e.name,description:null!==(u=null==t?void 0:t.agent_description)&&void 0!==u?u:null==e?void 0:e.description,engine:g,tools:null!==(d=null==t?void 0:t.tools)&&void 0!==d?d:null==e?void 0:e.tools,lyzr_tools:Array.isArray(f=null!==(p=null==t?void 0:t.lyzr_tools)&&void 0!==p?p:null==e?void 0:e.lyzr_tools)?f.map(e=>({...e,tool_name:(0,r.eE)(String((null==e?void 0:e.tool_name)||""))})):f,has_knowledge_base:!!(null==t?void 0:null===(i=t.knowledge_base)||void 0===i?void 0:i.enabled),rag_id:null!==(h=null==t?void 0:null===(o=t.knowledge_base)||void 0===o?void 0:null===(a=o.lyzr_rag)||void 0===a?void 0:a.rag_id)&&void 0!==h?h:null==e?void 0:e.rag_id,rag_name:null!==(m=null==t?void 0:null===(l=t.knowledge_base)||void 0===l?void 0:null===(s=l.lyzr_rag)||void 0===s?void 0:s.rag_name)&&void 0!==m?m:null==e?void 0:e.rag_name}}function l(e,t){let n={...e||{}};for(let[e,r]of Object.entries(t||{}))null!=r&&""!==r&&(Array.isArray(r)&&0===r.length||(n[e]=r));return n}function c(e){return String(e||"").toLowerCase().replace(/[^a-z0-9]+/g," ").trim()}function u(e){return(null==e?void 0:e.agent_kind)==="voice"||(null==e?void 0:e.type)==="voice"}function d(e,t){let n=e||[];if(!Array.isArray(t)||!t.some(u))return n;let r=!1,a=n.map(e=>!e||i(e)||!u(p(e,t))?e:(r=!0,{...e,agent_kind:"voice"}));return r?a:n}function p(e,t){var n;let r=(null==e?void 0:e.agent_id)&&t.find(t=>(null==t?void 0:t.agent_id)&&String(t.agent_id)===String(e.agent_id));if(r)return r;let i=(null==e?void 0:e.workflow_node_id)&&t.find(t=>(null==t?void 0:t.id)&&String(t.id)===String(e.workflow_node_id));if(i)return i;let a=c(null!==(n=null==e?void 0:e.name)&&void 0!==n?n:null==e?void 0:e.agent_name);if(a)return t.find(e=>!(null==e?void 0:e.agent_id)&&c(null==e?void 0:e.label)===a)}function h(e,t){if(!(null==e?void 0:e.agent_id))return"unknown";if(i(e))return"voice";if(!Array.isArray(t)||0===t.length)return"unknown";let n=p(e,t);return n?u(n)?"voice":"hosted":"unknown"}},29659:function(e,t,n){n.d(t,{a:function(){return L},m:function(){return N}});var r=n(57437),i=n(2265),a=n(17624),o=n(32174),s=n(65993),l=n(39004);let c="data: ",u={chat_stream:!0,chat_stream_end:!0,chat_stream_error:!0};function d(e){let t=e.data;if(null===t||"object"!=typeof t||!("app_id"in t))return;let n=t.app_id;return"string"==typeof n&&n.length>0?n:void 0}class p{persistActiveStream(){try{this.activeStream?sessionStorage.setItem(p.ACTIVE_STREAM_KEY,JSON.stringify(this.activeStream)):sessionStorage.removeItem(p.ACTIVE_STREAM_KEY)}catch(e){}}restoreActiveStream(){try{let e=sessionStorage.getItem(p.ACTIVE_STREAM_KEY);e&&(this.activeStream=JSON.parse(e))}catch(e){}}
1shouldDeliverStreamFrame(e,t){var n,r;if((null===(n=e.data)||void 0===n?void 0:n.message_id)!==t)return!1;let i=d(e);if(null!==this.activeStream&&void 0!==i&&i!==this.activeStream.appId)return!1;let a=e.data.sequence;return"number"!=typeof a||!!(this.activeStream&&this.activeStream.messageId===t&&(r=this.activeStream.lastSequence,"number"!=typeof a||Number.isFinite(a)&&a>r))&&(this.activeStream={...this.activeStream,lastSequence:a},this.persistActiveStream(),!0)}clearActiveStream(e){var t;(null===(t=this.activeStream)||void 0===t?void 0:t.messageId)===e&&(this.activeStream=null,this.persistActiveStream())}clearActiveStreamForApp(e){var t;(null===(t=this.activeStream)||void 0===t?void 0:t.appId)===e&&(this.activeStream=null,this.persistActiveStream())}setCurrentAppId(e){this.currentAppId=e}hasActiveChatListeners(){return null!==this.activeChatCleanup}replaceActiveChatCleanup(e){var t;null===(t=this.activeChatCleanup)||void 0===t||t.call(this),this.activeChatCleanup=e}async connect(){return new Promise((e,t)=>{try{if(this.ws){let e=this.ws;e.onclose=null,e.onerror=null,e.onmessage=null,e.close(),this.ws=null}this.ws=new WebSocket(this.url),this.ws.onopen=()=>{this.authenticate().then(()=>{this.reconnectAttempts=0,this.startHeartbeat(),e()}).catch(e=>{console.error("❌ Authentication failed:",e),t(e)})},this.ws.onmessage=e=>{try{let t=JSON.parse(e.data);this.handleMessage(t)}catch(e){console.error("Failed to parse WebSocket message:",e)}},this.ws.onerror=e=>{console.error("❌ WebSocket error:",e),t(e)},this.ws.onclose=e=>{this.stopHeartbeat(),this.authenticated=!1,t(Error("WebSocket closed with code ".concat(e.code,": ").concat(e.reason||"unknown"))),this.onDisconnectCallback&&this.onDisconnectCallback(),this.shouldReconnect&&this.handleReconnect()}}catch(e){console.error("❌ Failed to create WebSocket:",e),t(e)}})}async authenticate(){var e;let t=this.generateId(),n=(null===(e=this.getBearerToken)||void 0===e?void 0:e.call(this))||void 0;if(!n){this.shouldReconnect=!1;let e=new s.un({errorCode:"MISSING_TOKEN",message:"No valid session token is available for the WebSocket connection.",retryable:!1,requestId:t});throw(0,l.lG)("websocket: no token available"),e}return new Promise((e,r)=>{let i=!1,a=e=>{(0,s.id)(e)&&(this.shouldReconnect=!1,(0,l.lG)("websocket: server rejected the session token")),r(e)},o=setTimeout(()=>{i||(i=!0,this.pendingRequests.delete(t),r(new s.un({errorCode:"CLIENT_TIMEOUT",message:"WebSocket authentication timed out.",retryable:!0,requestId:t})))},15e3);this.pendingRequests.set(t,{resolve:n=>{i||(i=!0,clearTimeout(o),"success"===n.status?(this.authenticated=!0,this.connectionGeneration+=1,this.resumeAttempt=null,e()):a((0,s.O3)(n,{requestId:t})))},reject:e=>{i||(i=!0,clearTimeout(o),a(e))},timeout:o}),this.send({event:"auth",request_id:t,data:{...n?{bearer_token:n}:{},api_key:this.apiKey,...this.userId?{user_id:this.userId}:{}}})})}async createApp(e){return this.ensureAuthenticated(),this.sendRequest("create_app",e,3e4)}async createRepository(e,t){this.ensureAuthenticated();let n=t?e=>{var n,r;(null===(n=e.data)||void 0===n?void 0:n.progress)!==void 0&&(null===(r=e.data)||void 0===r?void 0:r.message)&&t(e.data.progress,e.data.message)}:null;n&&this.on("repository_progress",n);try{return await this.sendRequest("create_repository",{app_id:e},6e4)}finally{n&&this.off("repository_progress",n)}}async createDeployment(e,t){this.ensureAuthenticated();let n=t?e=>{var n,r;(null===(n=e.data)||void 0===n?void 0:n.progress)!==void 0&&(null===(r=e.data)||void 0===r?void 0:r.message)&&t(e.data.progress,e.data.message)}:null;n&&this.on("deployment_progress",n);try{return await this.sendRequest("create_deployment",{app_id:e},12e4)}finally{n&&this.off("deployment_progress",n)}}async getApp(e){return this.ensureAuthenticated(),this.sendRequest("get_app",{app_id:e},1e4)}async listApps(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:100;return this.ensureAuthenticated(),this.sendRequest("list_apps",{user_id:e,skip:t,limit:n},1e4)}subscribe(e,t){this.ensureAuthenticated(),this.subscriptions.set(e,t),this.send({event:"subscribe",data:{app_id:e}});let n=n=>{var r;(null===(r=n.data)||void 0===r?void 0:r.app_id)===e&&t(n.data)},r="subscribe:".concat(e);
1(this.handlers.get(r)||[]).forEach(e=>this.off("state_update",e)),this.handlers.set(r,[n]),this.on("state_update",n)}unsubscribe(e){this.subscriptions.delete(e),(this.handlers.get("subscribe:".concat(e))||[]).forEach(e=>this.off("state_update",e)),this.handlers.delete("subscribe:".concat(e)),this.isConnected()&&this.send({event:"unsubscribe",data:{app_id:e}})}async getStateSnapshot(e){return this.ensureAuthenticated(),this.sendRequest("state_snapshot",{app_id:e},1e4)}async getStateHistory(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.ensureAuthenticated(),this.sendRequest("state_history",{app_id:e,limit:t.limit||50,skip:t.skip||0,event_type:t.eventType},1e4)}async updateAppState(e,t){return this.ensureAuthenticated(),this.sendRequest("update_app_state",{app_id:e,state_update:t},1e4)}reauthenticate(){if(this.reauthPromise)return this.reauthPromise;this.authenticated=!1;let e=this.authenticate().finally(()=>{this.reauthPromise===e&&(this.reauthPromise=null)});return this.reauthPromise=e,e}sendRequest(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:3e4,r=!(arguments.length>3)||void 0===arguments[3]||arguments[3],i=this.generateId();return new Promise((a,o)=>{let l=setTimeout(()=>{this.pendingRequests.delete(i),o(new s.un({errorCode:"CLIENT_TIMEOUT",message:"WebSocket request timed out after ".concat(n,"ms."),retryable:!0,requestId:i}))},n);this.pendingRequests.set(i,{resolve:c=>{if(clearTimeout(l),"success"===c.status)a(c);else if("error"===c.status){let l=(0,s.O3)(c,{requestId:i});if(r&&this.authenticated&&"UNAUTHORIZED"===l.errorCode){console.warn("[WS] ".concat(e," rejected as unauthorized on an authenticated socket — re-authenticating")),this.reauthenticate().then(()=>this.sendRequest(e,t,n,!1)).then(a).catch(e=>o(null!=e?e:l));return}o(l)}},reject:e=>{clearTimeout(l),o((0,s.UH)(e,{errorCode:"WEBSOCKET_REQUEST_FAILED",message:"The WebSocket request failed.",retryable:!1,requestId:i}))},timeout:l}),this.send({event:e,request_id:i,data:t})})}send(e){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)throw Error("WebSocket is not connected");try{this.ws.send(JSON.stringify(e))}catch(e){throw console.error("Failed to send WebSocket message:",e),e}}handleMessage(e){this.lastMessageAt=Date.now();let t=e.event;if(u[t]&&!this.isStreamFrameForCurrentApp(t,e))return;"chat_stream"===t&&this.activeStream&&(this.lastStreamEventAt=Date.now());let n=e.request_id;if(n&&this.pendingRequests.has(n)){let t=this.pendingRequests.get(n);this.pendingRequests.delete(n),t.timeout&&clearTimeout(t.timeout),("success"===e.status||"error"===e.status)&&t.resolve(e)}this.handlers.has(t)&&this.handlers.get(t).forEach(n=>{try{n(e)}catch(e){console.error("Error in event handler for ".concat(t,":"),e)}})}isStreamFrameForCurrentApp(e,t){let n=d(t);return void 0===n?(console.warn("[WS] Dropping ".concat(e," frame without app_id")),!1):null===this.currentAppId||n===this.currentAppId}on(e,t){this.handlers.has(e)||this.handlers.set(e,[]),this.handlers.get(e).push(t)}off(e,t){if(t){if(this.handlers.has(e)){let n=this.handlers.get(e),r=n.indexOf(t);r>-1&&n.splice(r,1)}}else this.handlers.delete(e)}startHeartbeat(){this.stopHeartbeat(),this.lastMessageAt=Date.now(),this.lastStreamEventAt=Date.now(),this.heartbeatTimer=setInterval(()=>{if(!this.isConnected())return;let e=Date.now();if(this.activeStream&&this.lastStreamEventAt>0){let t=e-this.lastStreamEventAt;if(t>p.STREAM_STALE_THRESHOLD_MS){console.warn("[WS] No stream events in ".concat(Math.round(t/1e3),"s during active stream — forcing reconnect")),this.forceReconnect();return}}let t=e-this.lastMessageAt;if(t>p.STALE_THRESHOLD_MS){console.warn("[WS] No messages in ".concat(Math.round(t/1e3),"s — forcing reconnect")),this.forceReconnect();return}try{this.send({event:"ping"})}catch(e){}},p.HEARTBEAT_INTERVAL_MS)}stopHeartbeat(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}forceReconnect(){if(this.stopHeartbeat(),this.authenticated=!1,this.ws){let e=this.ws;e.onclose=null,e.onerror=null,e.onmessage=null;
1try{e.close(4e3,"Stale connection")}catch(e){}this.ws=null}this.onDisconnectCallback&&this.onDisconnectCallback(),this.shouldReconnect&&this.handleReconnect()}handleReconnect(){if(this.reconnectAttempts>=this.maxReconnectAttempts){console.error("❌ Max reconnection attempts reached");return}this.reconnectAttempts++;let e=Math.min(1e3*Math.pow(2,this.reconnectAttempts),3e4);this.reconnectTimeout=setTimeout(()=>{this.connect().then(async()=>{this.subscriptions.forEach((e,t)=>{this.send({event:"subscribe",data:{app_id:t}})});let e=[];this.subscriptions.forEach((t,n)=>{e.push([n,t])});for(let n=0;n<e.length;n++){let[r,i]=e[n];try{var t;let e=await this.getStateSnapshot(r);(null==e?void 0:null===(t=e.data)||void 0===t?void 0:t.state)&&i({event_type:"state_snapshot",state:e.data.state.state||e.data.state,app_id:r,app_status:e.data.state.status,sandbox_health:e.data.sandbox_health})}catch(e){console.error("❌ Failed to fetch state snapshot for app ".concat(r,":"),e)}}this.onReconnectCallback&&this.onReconnectCallback()}).catch(e=>{console.error("❌ Reconnection failed:",e)})},e)}async sendChatMessage(e,t,n,r,i,a,o,s,l,c){this.ensureAuthenticated();let u=(await this.sendRequest("chat_message",{app_id:e,message:t,bearer_token:n,...o?{permission_mode:o}:{},...s?{is_plan_handoff:!0}:{},..."boolean"==typeof l?{feature_testing:l}:{},...c?{unified_agent_thread:!0}:{}},3e4)).data.message_id;this.activeStream={appId:e,messageId:u,lastSequence:-1},this.setCurrentAppId(e),this.lastStreamEventAt=Date.now(),this.persistActiveStream();let d=e=>{this.shouldDeliverStreamFrame(e,u)&&r(e.data)},p=e=>{var t;(null===(t=e.data)||void 0===t?void 0:t.message_id)===u&&(this.clearActiveStream(u),m(),i(e.data))},h=e=>{var t;(null===(t=e.data)||void 0===t?void 0:t.message_id)===u&&(this.clearActiveStream(u),m(),a(e.data))};this.on("chat_stream",d),this.on("chat_stream_end",p),this.on("chat_stream_error",h);let m=()=>{this.off("chat_stream",d),this.off("chat_stream_end",p),this.off("chat_stream_error",h),this.activeChatCleanup===m&&(this.activeChatCleanup=null)};return this.replaceActiveChatCleanup(m),{messageId:u,cleanup:m}}async fixSandboxError(e,t,n,r){var i,a,o,s;this.ensureAuthenticated();let l=(null===(i=this.getBearerToken)||void 0===i?void 0:i.call(this))||void 0,c=await this.sendRequest("fix_sandbox_error",{app_id:e,...l?{bearer_token:l}:{}},3e4),u=null===(a=c.data)||void 0===a?void 0:a.message_id;if(!u)return{messageId:null,cleanup:()=>{},status:null===(s=c.data)||void 0===s?void 0:s.status};this.activeStream={appId:e,messageId:u,lastSequence:-1},this.setCurrentAppId(e),this.lastStreamEventAt=Date.now(),this.persistActiveStream();let d=e=>{this.shouldDeliverStreamFrame(e,u)&&t(e.data)},p=e=>{var t;(null===(t=e.data)||void 0===t?void 0:t.message_id)===u&&(this.clearActiveStream(u),m(),n(e.data))},h=e=>{var t;(null===(t=e.data)||void 0===t?void 0:t.message_id)===u&&(this.clearActiveStream(u),m(),r(e.data))};this.on("chat_stream",d),this.on("chat_stream_end",p),this.on("chat_stream_error",h);let m=()=>{this.off("chat_stream",d),this.off("chat_stream_end",p),this.off("chat_stream_error",h),this.activeChatCleanup===m&&(this.activeChatCleanup=null)};return this.replaceActiveChatCleanup(m),{messageId:u,cleanup:m,status:null===(o=c.data)||void 0===o?void 0:o.status}}async stopBuild(e){this.ensureAuthenticated();try{return await this.sendRequest("stop_build",{app_id:e},1e4)}finally{this.clearActiveStreamForApp(e)}}async skipFeatureTest(e){return this.ensureAuthenticated(),this.sendRequest("skip_feature_test",{app_id:e},1e4)}async resumeChat(e,t,n){return this.ensureAuthenticated(),this.sendRequest("chat_resume",{app_id:e,message_id:t,cursor:n},8e3)}async checkActiveStream(e){try{var t;this.ensureAuthenticated();let n=await this.sendRequest("check_active_stream",{app_id:e},1e4);return null!==(t=n.data)&&void 0!==t?t:null}catch(e){return console.error("Failed to check active stream:",e),null}}getActiveStream(){return this.activeStream}async resumeActiveStream(e,t,n,r){let i=this.resumeAttempt;if((null==i?void 0:i.generation)===this.connectionGeneration)return i.promise;let a=this.resumeActiveStreamAttempt(e,t,n,r);return this.resumeAttempt={generation:this.connectionGeneration,promise:a},a}async resumeActiveStreamAttempt(e,t,n,r){var i,a;let o=null!=r?r:this.activeStream;if(!o)return null;if(r){let e=(null===(i=this.activeStream)||void 0===i?void 0:i.messageId)===r.messageId&&this.activeStream.appId===r.appId?this.activeStream.lastSequence:-1;this.activeStream={...r,lastSequence:Math.max(r.lastSequence,e)},this.persistActiveStream()}this.ensureAuthenticated();let{appId:s,messageId:l,lastSequence:u}=null!==(a=this.activeStream)&&void 0!==a?a:o;this.setCurrentAppId(s),this.lastStreamEventAt=Date.now();let d=!1,p=t=>{var n;
1this.shouldDeliverStreamFrame(t,l)&&(d||(d=function(e){if("string"!=typeof e)return!1;let t=e.startsWith(c)?e.slice(c.length):e;try{let e=JSON.parse(t);if(null===e||"object"!=typeof e||Array.isArray(e))return!1;let n=e.event_type;return"chat_completed"===n||"chat_failed"===n}catch(e){if(e instanceof SyntaxError)return!1;throw e}}(null===(n=t.data)||void 0===n?void 0:n.line)),e(t.data))},h=e=>{var n;(null===(n=e.data)||void 0===n?void 0:n.message_id)===l&&(this.clearActiveStream(l),f(),t({...null===e.data||"object"!=typeof e.data||Array.isArray(e.data)?{}:e.data,replay_terminal_seen:d}))},m=e=>{var t;(null===(t=e.data)||void 0===t?void 0:t.message_id)===l&&(this.clearActiveStream(l),f(),n(e.data))};this.on("chat_stream",p),this.on("chat_stream_end",h),this.on("chat_stream_error",m);let f=()=>{this.off("chat_stream",p),this.off("chat_stream_end",h),this.off("chat_stream_error",m),this.activeChatCleanup===f&&(this.activeChatCleanup=null)};this.replaceActiveChatCleanup(f);try{await this.resumeChat(s,l,u+1)}catch(e){throw f(),e}return{messageId:l,cleanup:f}}onDisconnect(e){this.onDisconnectCallback=e}onReconnect(e){this.onReconnectCallback=e}close(){this.shouldReconnect=!1,this.stopHeartbeat(),this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null),this.ws&&(this.ws.onclose=null,this.ws.onerror=null,this.ws.onmessage=null,this.ws.close(),this.ws=null),this.pendingRequests.forEach(e=>{let{timeout:t,reject:n}=e;t&&clearTimeout(t),n(Error("WebSocket closed"))}),this.pendingRequests.clear(),this.handlers.clear(),this.subscriptions.clear(),this.authenticated=!1,this.reconnectAttempts=0,this.activeStream=null,this.onDisconnectCallback=null,this.onReconnectCallback=null}isConnected(){return null!==this.ws&&this.ws.readyState===WebSocket.OPEN}isReconnecting(){return this.shouldReconnect&&this.reconnectAttempts<this.maxReconnectAttempts}isAuthenticated(){return this.authenticated}ensureAuthenticated(){if(!this.authenticated)throw Error("Not authenticated. Call connect() first.");if(!this.isConnected())throw Error("WebSocket not connected")}generateId(){return"req-".concat(Date.now(),"-").concat(Math.random().toString(36).substr(2,9))}constructor(e,t,n,r){this.ws=null,this.authenticated=!1,this.reauthPromise=null,this.handlers=new Map,this.pendingRequests=new Map,this.reconnectAttempts=0,this.maxReconnectAttempts=15,this.reconnectTimeout=null,this.shouldReconnect=!0,this.activeStream=null,this.currentAppId=null,this.onDisconnectCallback=null,this.onReconnectCallback=null,this.subscriptions=new Map,this.activeChatCleanup=null,this.connectionGeneration=0,this.resumeAttempt=null,this.heartbeatTimer=null,this.lastMessageAt=0,this.lastStreamEventAt=0,this.url=e,this.apiKey=t,this.userId=n,this.getBearerToken=r,this.restoreActiveStream()}}p.ACTIVE_STREAM_KEY="ws_active_stream",p.HEARTBEAT_INTERVAL_MS=3e4,p.STALE_THRESHOLD_MS=6e4,p.STREAM_STALE_THRESHOLD_MS=9e4;var h=n(42097),m=n(14581),f=n(54012),g=n(91041);function v(){{let e=localStorage.getItem("tenant_pagos_base_url");if(e)return"".concat(e,"/api/v1/views/groups")}return"https://pagos-prod.studio.lyzr.ai/api/v1/views/groups"}async function _(e,t,n,r){try{let i=await fetch("".concat(v(),"/"),{method:"POST",headers:{Authorization:"Bearer ".concat(n),"Content-Type":"application/json","x-api-key":r},body:JSON.stringify({group_name:e,group_type:"agent",organization_id:t})});if(!i.ok){if(400===i.status){let a;try{a=await i.json()}catch(e){a={}}if((null==a?void 0:a.detail)&&"string"==typeof a.detail&&a.detail.includes("already exists")){let i=await A(e,t,n,r);if(i)return i.group_id}}let a=await i.text().catch(()=>"");throw Error("Failed to create group (".concat(i.status,"): ").concat(a))}return await i.json()}catch(e){throw console.error("❌ Error creating agent group:",e),e}}async function y(e,t,n){try{let r=await fetch("".concat(v(),"/?organization_id=").concat(e,"&group_type=agent"),{method:"GET",headers:{Authorization:"Bearer ".concat(t),"Content-Type":"application/json","x-api-key":n}});if(!r.ok){let e=await r.text();throw Error("Failed to fetch groups (".concat(r.status,"): ").concat(e))}return await r.json()}catch(e){throw console.error("❌ Error fetching agent groups:",e),e}}function w(e,t){return"hosted"===e||(console.warn('⛔ Not adding "'.concat(t,'" to a Studio folder — agent kind is "').concat(e,'".')+("voice"===e?" Voice agents live on the voice service and have no Studio asset.":" Kind could not be established; a later pass will retry.")),!1)}
1async function S(e,t,n,r,i,a,o,s){if(w(i,n))try{let i=await fetch("".concat(v(),"/").concat(encodeURIComponent(e),"/agent/assets?organization_id=").concat(a),{method:"POST",headers:{Authorization:"Bearer ".concat(o),"Content-Type":"application/json","x-api-key":s},body:JSON.stringify({asset_id:t,asset_type:"agent",asset_name:n,metadata:{description:r||""}})});if(!i.ok){let e=await i.text();throw Error("Failed to add agent to group (".concat(i.status,"): ").concat(e))}}catch(e){throw console.error("❌ Error adding agent to group:",e),e}}async function b(e,t,n,r,i){let a=t.filter(e=>w(e.kind,e.name)),o=0,s=0,l=[];for(let t of a)try{await S(e,t.agent_id,t.name,t.description,t.kind,n,r,i),o++}catch(n){s++;let e="Failed to add ".concat(t.name,": ").concat(n instanceof Error?n.message:"Unknown error");l.push(e),console.error(e)}return{success:o,failed:s,errors:l}}async function A(e,t,n,r){try{return(await y(t,n,r)).find(t=>t.group_name===e)||null}catch(e){return console.error("❌ Error finding group for project:",e),null}}var T=n(59010),E=n(48522),k=n(51082),C=n(14438),R=n(71487),I=n(65532),x=n(95704),P=n(24526),M=n(4660);function D(e){let{app_id:t,serial:n,result:r}=e,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:C.Am;if("success"!==r)return!1;let a="runtime-updated:".concat(JSON.stringify([t,n]));try{if(sessionStorage.getItem(a))return!1;sessionStorage.setItem(a,"1")}catch(e){}return i("App runtime updated.",{description:"Your app now runs on the latest runtime. Your code and data are unchanged.",duration:6e3}),!0}let O=(0,i.createContext)(void 0),N=()=>{let e=(0,i.useContext)(O);if(!e)throw Error("useChatContext must be used within a ChatProvider");return e},L=e=>{var t,n;let{children:l}=e,{apiKey:c,organizationId:u,policyId:d,setPolicyId:v}=(0,h.Z)(),{getToken:y,userId:w}=(0,T.a)(),S=y(),{getSessionId:N}=(0,I.D)(),{tenant_id:L}=(0,E.S)(),F="default"!==L,[q,j]=(0,i.useState)([]),[B,z]=(0,i.useState)([]),[W,U]=(0,i.useState)([]),[G,H]=(0,i.useState)([]),[Y,K]=(0,i.useState)([]),[$,V]=(0,i.useState)("build"),[Z,J]=(0,i.useState)(0),[X,Q]=(0,i.useState)(0),[ee,et]=(0,i.useState)(null),[en,er]=(0,i.useState)(!1),[ei,ea]=(0,i.useState)(!1),eo=(0,i.useRef)(null),es=(0,i.useRef)(!1),el=(0,i.useRef)([]),ec=(0,i.useCallback)(e=>{if(es.current=e,!e)for(let e of el.current.splice(0))D(e)},[]),eu=(0,i.useRef)(null),[ed,ep]=(0,i.useState)(null),[eh,em]=(0,i.useState)(!1),[ef,eg]=(0,i.useState)(""),[ev,e_]=(0,i.useState)(""),[ey,ew]=(0,i.useState)(""),[eS,eb]=(0,i.useState)("auto"),[eA,eT]=(0,i.useState)([]),[eE,ek]=(0,i.useState)(!1),[eC,eR]=(0,i.useState)(!1),[eI,ex]=(0,i.useState)(!1),[eP,eM]=(0,i.useState)([]),[eD,eO]=(0,i.useState)(new Set),[eN,eL]=(0,i.useState)(!1),[eF,eq]=(0,i.useState)([]),[ej,eB]=(0,i.useState)(null),ez=(0,i.useMemo)(()=>(0,o.My)(eP,null==ej?void 0:ej.nodes),[eP,ej]),[eW,eU]=(0,i.useState)(null),[eG,eH]=(0,i.useState)(!1),[eY,eK]=(0,i.useState)(()=>{try{return Number(sessionStorage.getItem("buildProgress"))||0}catch(e){return 0}}),[e$,eV]=(0,i.useState)(()=>{try{return sessionStorage.getItem("buildMessage")||""}catch(e){return""}}),[eZ,eJ]=(0,i.useState)(!1),[eX,eQ]=(0,i.useState)(!1),[e0,e1]=(0,i.useState)(null),[e4,e2]=(0,i.useState)(()=>{try{if("true"!==sessionStorage.getItem("isBuildingApp"))return!1;let e=Number(sessionStorage.getItem("buildStateTimestamp")||"0");if(Date.now()-e>3e5)return sessionStorage.removeItem("isBuildingApp"),sessionStorage.removeItem("buildProgress"),sessionStorage.removeItem("buildMessage"),sessionStorage.removeItem("buildStateTimestamp"),!1;return!0}catch(e){return!1}});(0,i.useEffect)(()=>{try{e4?(sessionStorage.setItem("isBuildingApp","true"),sessionStorage.setItem("buildProgress",String(eY)),sessionStorage.setItem("buildMessage",e$),sessionStorage.getItem("buildStateTimestamp")||sessionStorage.setItem("buildStateTimestamp",String(Date.now()))):(sessionStorage.removeItem("isBuildingApp"),sessionStorage.removeItem("buildProgress"),sessionStorage.removeItem("buildMessage"),sessionStorage.removeItem("buildStateTimestamp"))}catch(e){}},[e4,eY,e$]);let[e3,e5]=(0,i.useState)(()=>{let e=sessionStorage.getItem("pendingPrompt");return e?(sessionStorage.removeItem("pendingPrompt"),e):null}),e6=(0,i.useRef)(null),[e9,e7]=(0,i.useState)(!1),e8=(0,i.useRef)(0),te=(0,i.useRef)(!1),tt=(0,i.useRef)(null),tn=(0,i.useRef)(null!==(t=null==eW?void 0:eW.id)&&void 0!==t?t:null);tn.current=null!==(n=null==eW?void 0:eW.id)&&void 0!==n?n:null;let tr=(0,i.useCallback)(e=>{let t=tn.current;if(!t)return Promise.resolve(null);let n=tt.current;if((null==n?void 0:n.appId)===t)return n.promise;let r=(async()=>{for(let n=0;n<M.bn;n++){let r="sandbox_unreachable",i=new AbortController,a=setTimeout(()=>i.abort(),15e3);try{let e=y(),n=await fetch("".concat("https://api.beta.architect.new","/api/v1/sandboxes/state"),{method:"POST",headers:{"Content-Type":"application/json",...e&&{Authorization:"Bearer ".concat(e)}},body:JSON.stringify({app_id:t}),signal:i.signal});if(clearTimeout(a),!n.ok)throw r=401===n.status||403===n.status?"sandbox_auth_failed":"health_unknown",Error("HTTP ".concat(n.status));let o=(0,M.VC)(await n.json());if(tn.current!==t)return null;return e1(o),"running"===(0,M.G2)(o)&&(eJ(!0),eQ(!1)),o}catch(c){if(clearTimeout(a),i.signal.aborted&&(r="sandbox_probe_timeout"),n===M.bn-1){if(console.warn("[s
1andbox-health] refresh failed after ".concat(M.bn," attempts (").concat(e,")"),c),tn.current!==t)return null;let n={sandbox_id:null,app_id:t,status:"unknown",health:"unknown",pid_alive:!1,http_code:null,last_error:{message:c instanceof Error?c.message:"Sandbox health request failed",source:"frontend"},last_updated:null,timeout_at:null,source:"stale",error_code:r};return e1(n),n}let o=(0,M.br)(n);console.warn("[sandbox-health] refresh failed (".concat(e,", attempt ").concat(n+1,"); retrying in ").concat(o,"ms"),c);let{promise:s,resolve:l}=Promise.withResolvers();setTimeout(l,o),await s}}return null})();return tt.current={appId:t,promise:r},r.finally(()=>{var e;(null===(e=tt.current)||void 0===e?void 0:e.promise)===r&&(tt.current=null)}),r},[y]);(0,i.useEffect)(()=>{if(!(null==eW?void 0:eW.id)){e1(null);return}tr("mount");let e=setInterval(()=>{tr("periodic")},12e4);return()=>clearInterval(e)},[null==eW?void 0:eW.id,tr]);let ti=(0,i.useRef)(null),ta=(0,i.useRef)(null),to=(0,i.useRef)(null),ts=(0,i.useRef)(null),tl=(0,i.useRef)(null),tc=(0,i.useRef)(null),tu=(0,i.useRef)(null),td=(0,i.useRef)({myra:!1,mira:!1,prd:!1,agents:!1,workflow:!1}),tp=(0,i.useRef)(""),th=(0,i.useRef)(null),tm=(0,i.useRef)(!1);(0,i.useEffect)(()=>{tm.current=eE||eC||eI},[eE,eC,eI]),(0,i.useEffect)(()=>{(null==eW?void 0:eW.user_github_repo_url)&&H(e=>e.some(e=>{var t;return"commit_card"===e.eventType&&(null===(t=e.metadata)||void 0===t?void 0:t.pushed)!==!0})?e.map(e=>"commit_card"===e.eventType?{...e,metadata:{...e.metadata,pushed:!0,push_status:"Pushed"}}:e):e)},[null==eW?void 0:eW.user_github_repo_url,eh]);let tf=e=>{j(t=>[...t,e])},tg=(e,t)=>{j(n=>n.map(n=>n.id===e?{...n,...t}:n))},tv=()=>{j([])},t_=e=>{z(t=>[...t,e])},ty=(e,t)=>{z(n=>n.map(n=>n.id===e?{...n,...t}:n))},tw=()=>{z([])},tS=e=>{K(t=>[...t,e])},tb=(e,t)=>{K(n=>n.map(n=>n.id===e?{...n,...t}:n))},tA=()=>{K([])},tT=e=>{U(t=>[...t,e])},tE=(e,t)=>{U(n=>n.map(n=>n.id===e?{...n,...t}:n))},tk=()=>{U([])},tC=e=>{var t,n,r;let i=e;if(("User"===e.type||"user_message"===e.eventType)&&(i={...e,content:(0,f.XY)(e.content||"")}),"debug_event"===e.eventType){let e=i.metadata,n=(null==e?void 0:e.tool_use_id)?"".concat(e.tool_use_id,":").concat(null===(t=i.content)||void 0===t?void 0:t.slice(0,40)):i.content;H(t=>t.some(t=>{var r;return"debug_event"===t.eventType&&((null==e?void 0:e.tool_use_id)?(null===(r=t.metadata)||void 0===r?void 0:r.tool_use_id)===e.tool_use_id:t.content===n)})?t:[...t,i]);return}if("commit_card"===e.eventType){let e=(null===(n=i.metadata)||void 0===n?void 0:n.commit_id)||(null===(r=i.metadata)||void 0===r?void 0:r.commit_hash)||"";if(e){H(t=>{for(let i=t.length-1;i>=0;i--){let a=t[i];if((null==a?void 0:a.eventType)==="commit_card"){var n,r;let i=(null==a?void 0:null===(n=a.metadata)||void 0===n?void 0:n.commit_id)||(null==a?void 0:null===(r=a.metadata)||void 0===r?void 0:r.commit_hash)||"";if(i&&i===e)return t;break}}return[...t,i]});return}}if(("User"===i.type||"user_message"===i.eventType)&&(0,f.PH)(e.content||"")){H(e=>e.some(e=>("User"===e.type||"user_message"===e.eventType)&&!(0,f.PH)(e.content||""))?e:[...e,i]);return}H(e=>(0,g.Q4)(e,i)?e:[...e,i])},tR=(e,t)=>{H(n=>n.map(n=>n.id===e?{...n,...t}:n))},tI=()=>{H([])},tx=async()=>{if(!e3||!w){console.warn("Cannot execute pending prompt: missing prompt or user");return}if(!c){console.warn("Cannot execute pending prompt: API key not initialized yet");return}try{(0,R.trackPendingPromptExecuted)(e3.length),(0,R.trackMessageSent)(w,"guided",e3.length,!1),(0,R.trackUserPrompt)(w,N()||"pending-session-".concat(Date.now()),e3,"initial_homepage",!1),await t0(e3,w),e5(null)}catch(e){console.error("Failed to execute pending prompt:",e),C.Am.error("Failed to submit your prompt. Please try again.")}},tP=async()=>{eg(""),e_(""),ew(""),ek(!1),eR(!1),ex(!1)},tM=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];e&&"string"==typeof e&&"undefined"!==e&&(t?(tp.current="",null!==th.current&&(cancelAnimationFrame(th.current),th.current=null),eg(e)):(tp.current+=e,null===th.current&&(th.current=requestAnimationFrame(()=>{let e=tp.current;tp.current="",th.current=null,e&&eg(t=>t+e)}))))},tD=async()=>
1{if(!(null==eW?void 0:eW.id)||!e6.current||!e9){console.warn("⚠️ Cannot sync PRD: No app or WebSocket not connected");return}try{await e6.current.updateAppState(eW.id,{prdContent:ef,mermaidDiagram:ev,colorPalette:ey,selectedThemeId:eS}),w&&(0,R.trackPrdEdited)(w,N(),"ai_generated")}catch(e){console.error("❌ Failed to sync PRD content:",e)}},tO=async e=>{let t=[];eM(n=>{let r=e=>{var t;return null!==(t=e.agent_id)&&void 0!==t?t:e.slug},i=n.find(t=>void 0!==r(t)&&r(t)===r(e));if(i)return t=n.map(t=>t===i?(0,o.tb)(t,e):t);if(t=[...n,e],w&&e.agent_id){var a,s,l;let t=(null===(a=e.features)||void 0===a?void 0:a.some(e=>"KNOWLEDGE_BASE"===e.type))||!1;null===(s=e.features)||void 0===s||s.some(e=>"DATABASE"===e.type);let n=(null===(l=e.tool_configs)||void 0===l?void 0:l.length)>0,r=e.agent_role,i=r&&["single","manager","sub-agent","independent"].includes(r)?r:"independent";(0,R.trackAgentCreated)(w,N()||"",e.agent_id,e.name,i,t,n)}return t})},tN=async(e,t)=>{eM(eP.map(n=>n.agent_id===e?{...n,...t}:n))},tL=async()=>{eM([]),eO(new Set)},tF=e=>{eq(t=>t.find(t=>t.id===e.id)?(console.warn("⚠️ Knowledge base already exists:",e.i
1d),t):[...t,e])},tq=()=>{let e=["Amazing","Brilliant","Creative","Dynamic","Elegant","Fantastic","Genius","Innovative","Magnificent","Outstanding","Perfect","Quantum","Revolutionary","Spectacular","Ultimate","Visionary","Wonderful","Extraordinary","Phenomenal","Incredible"];return e[Math.floor(Math.random()*e.length)]},tj=async(e,t)=>{try{let n=await fetch("/api/generate-name",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:e,userId:t})});if(!n.ok)return console.warn("⚠️ Name generator API returned non-OK status:",n.status),tq();let r=await n.json();if(r.name&&"string"==typeof r.name&&r.name.trim())return r.name;return console.warn("⚠️ Name generator returned empty or invalid response, falling back to random name"),tq()}catch(e){return console.error("❌ Error generating app name from AI:",e),tq()}},tB=()=>Math.random().toString(36).substring(2)+Date.now().toString(36),tz=e=>e.map(e=>({...e,timestamp:e.timestamp instanceof Date?e.timestamp:new Date(e.timestamp)})),tW=e=>(0,o.Yl)(e,null==ej?void 0:ej.nodes),tU=e=>(e||[]).filter(e=>"hosted"===tW(e)),tG=async(e,t)=>{try{let r=e||eW,i=tU(t||ez);if(!r||!i||0===i.length)return;let a=r.generated_name||r.name;if(!S||!c){console.warn("⚠️ Cannot setup group: missing credentials");return}let o=d;if(!o){let e=await (0,k.BN)(S);if(o=(null==e?void 0:e.policyId)||"")v(o);else{console.warn("⚠️ Could not get policyId, skipping group setup");return}}if(r.group_id){let e=await A(a,o,S,c);if(e){var n;let t=(null===(n=e.assets)||void 0===n?void 0:n.map(e=>e.asset_id))||[],r=i.filter(e=>!t.includes(e.agent_id));if(r.length>0){let{success:e,failed:t,errors:n}=await b(a,r.map(e=>({agent_id:e.agent_id,name:e.name,description:e.description||"",kind:tW(e)})),o,S,c);n.length>0&&console.warn("⚠️ Some agents failed to be added:",n)}}else console.warn("⚠️ Group_id exists but group not found, creating new group..."),r.group_id=void 0}if(!r.group_id){let t=null,n=await A(a,o,S,c);if(t=n?n.group_id:await tQ(a)){let n={...r,group_id:t};e&&e.id!==(null==eW?void 0:eW.id)||eU(n);let{success:s,failed:l,errors:u}=await b(a,i.map(e=>({agent_id:e.agent_id,name:e.name,description:e.description||"",kind:tW(e)})),o,S,c);u.length>0&&console.warn("⚠️ Some agents failed to be added:",u)}}}catch(e){console.error("❌ Failed to setup group for existing project (non-critical):",e)}},tH=(e,t)=>{var n,r;let i=tm.current;e.prdContent&&!i?eg(e.prdContent):e.prdContent&&i||e.prdContent,e.mermaidDiagram&&!i?e_(e.mermaidDiagram):e.mermaidDiagram,e.colorPalette&&!i?ew(e.colorPalette):e.colorPalette;if(e.agents&&Array.isArray(e.agents)){let t=new Map,n=[];for(let r of e.agents)(null==r?void 0:r.agent_id)?t.set(r.agent_id,r):n.push(r);eM([...n,...Array.from(t.values())]),eO(new Set(e.agents.map(e=>{var t;return null!==(t=e.agent_id)&&void 0!==t?t:e.slug}).filter(Boolean)))}e.knowledgeBases&&Array.isArray(e.knowledgeBases)&&eq(e.knowledgeBases),e.workflowData&&eB(e.workflowData);let a=tm.current;e.requirementsMessages&&Array.isArray(e.requirementsMessages)&&j(t=>0===e.requirementsMessages.length&&t.length>0?t:tz(e.requirementsMessages)),e.myraChatMessages&&Array.isArray(e.myraChatMessages)&&!a?z(tz(e.myraChatMessages)):e.myraChatMessages,e.miraChatMessages&&Array.isArray(e.miraChatMessages)&&U(tz(e.miraChatMessages)),e.changePlannerMessages&&Array.isArray(e.changePlannerMessages)&&K(t=>{let n=tz(e.changePlannerMessages),r=new Map(t.map(e=>[e.id,e]));return n.map(e=>{var t;let n=r.get(e.id),i=e.content;n&&n.content.includes("```plan-consumed")&&!i.includes("```plan-consumed")&&(i=n.content);let a=null!==(t=null==n?void 0:n.isStreaming)&&void 0!==t&&t;return a||i!==e.content?{...e,content:i,isStreaming:a}:e})}),("plan"===e.changePlannerMode||"build"===e.changePlannerMode)&&V(e.changePlannerMode),"number"==typeof e.changePlannerPromptCooldown&&J(e.changePlannerPromptCooldown),"number"==typeof e.plannerSessionEpoch&&Q(e.plannerSessionEpoch),e.activeChangePlan&&"object"==typeof e.activeChangePlan&&et(e.activeChangePlan);let o=null!==(n=e.currentCommitId)&&void 0!==n?n:null;if(!o){let t=Array.isArray(e.lyraChatMessages)&&e.lyraChatMessages.length>0?e.lyraChatMessages:G;for(let e=t.length-1;e>=0;e--){let n=t[e],i=(null==n?void 0:null===(r=n.metadata)||void 0===r?void 0:r.commit_id)||(null==n?void 0:n.commitId)||null;if(i){o=i;break}}}ep(o)},tY=(e,t)=>
1{e&&"object"==typeof e&&tH(e,t)},tK=e=>{var t,n,r,i,o,s,l,c,u,d,p,m,f,g,v,_,y,w,S,b,A,T,E;let k=e.event_type;if("chat_started"===k){let n=e.session_id||(null===(t=e.data)||void 0===t?void 0:t.session_id)||null,r=eu.current;n&&r&&n!==r&&(K([]),et(null),Q(e=>e+1)),n&&(eu.current=n)}if("credits_exhausted"===k){h.Z.getState().setShowCreditsExhausted(!0);return}if("commit_pushed"===k){let t=e.repo_url||"";H(e=>e.map(e=>"commit_card"===e.eventType?{...e,metadata:{...e.metadata,pushed:!0,push_status:"Pushed",...t&&{repo_url:t}}}:e));return}if("git_agents_updated"===k){(0,a.Ld)();let t=(null===(n=e.changes)||void 0===n?void 0:n.git_agents_pending_redeploy)||e.git_agents_pending_redeploy||[],r=t.length>1?"Agents ".concat(t.join(", ")):"Agent ".concat(t[0]||"");C.Am.info("".concat(r," updated on GitHub"),{description:"Redeploy your app to ship the updated agent to your live deployment.",duration:1e4});return}if("git_agents_pending_publish"===k){(0,a.Ld)();let t=(null===(r=e.changes)||void 0===r?void 0:r.git_agents_pending_publish)||e.git_agents_pending_publish||[];if(0===t.length)return;let n=t.length>1?"Agents ".concat(t.join(", ")," are"):"Agent ".concat(t[0]," is");C.Am.info("".concat(n," not on GitHub yet"),{description:"Your agent files are safely backed up. Connect GitHub to publish them to your own repositories.",duration:1e4});return}if("github_pulled"===k){let t=e.sha||"";H(n=>{for(let e=n.length-1;e>=0;e--){let i=n[e];if((null==i?void 0:i.type)==="GithubPull"){var r;if((null==i?void 0:null===(r=i.metadata)||void 0===r?void 0:r.sha)&&i.metadata.sha===t)return n;break}}return[...n,{id:"github-pull-".concat(Date.now()),type:"GithubPull",eventType:"github_pull_card",content:e.message||"Pulled latest from GitHub",icon:"GitPullRequest",timestamp:new Date().toISOString(),metadata:{sha:t,short_sha:e.short_sha||"",repo_url:e.repo_url||"",success:!1!==e.success,message:e.message||"Pulled latest from GitHub",...e.recovery?{recovery:e.recovery}:{}}}]});return}if("database_state_changed"===k){let t=(null===(i=e.changes)||void 0===i?void 0:i.database)||(null===(o=e.state)||void 0===o?void 0:o.database);t&&eU(e=>e?{...e,state:{...e.state||{},database:t}}:e);return}switch(k){case"build_started":e2(!0),eV("Building..."),eK(e=>Math.max(e,10));return;case"build_success":eK(100),eV("Build successful!"),eU(t=>{var n,r;if(!t)return t;let i=(null===(n=e.changes)||void 0===n?void 0:n.deployment_url)||(null===(r=e.state)||void 0===r?void 0:r.deployment_url)||t.deployment_url;return{...t,status:"deployed",is_deployed:!0,deployment_url:i||t.deployment_url}}),setTimeout(()=>{e2(!1),eK(0),eV("")},3e3);return;case"build_failed":eV((null===(s=e.changes)||void 0===s?void 0:s.error_message)||(null===(l=e.changes)||void 0===l?void 0:l.message)||"Build failed"),eK(0),e2(!1),eU(e=>e?{...e,status:"build_failed"}:e);return;case"build_permanently_failed":eV((null===(c=e.changes)||void 0===c?void 0:c.message)||"Build has failed permanently. Please review errors."),eK(0),e2(!1),eU(e=>e?{...e,status:"permanently_failed"}:e);return;case"repository_creating":e2(!0),eV("Creating repository..."),eK(e=>Math.max(e,20));return;case"repository_created":eV("Repository created"),eK(e=>Math.max(e,50));return;case"repository_failed":eV((null===(u=e.changes)||void 0===u?void 0:u.error)||(null===(d=e.changes)||void 0===d?void 0:d.message)||"Repository creation failed"),eK(0),e2(!1);return;case"deployment_starting":e2(!0),eV("Starting deployment..."),eK(e=>Math.max(e,60));return;case"deployment_created":null===(p=e.changes)||void 0===p||p.deployment_url,e.changes&&tH(e.changes),eK(100),eV("Deployment complete!"),setTimeout(()=>{e2(!1),eK(0),eV("")},3e3);return;case"deployment_failed":case"deployment_error":eV((null===(m=e.changes)||void 0===m?void 0:m.error)||(null===(f=e.changes)||void 0===f?void 0:f.message)||"Deployment failed"),eK(0),e2(!1);return;case"sandbox_ready":case"init_completed":eJ(!0),eQ(!1);return;case"sandbox_failed":eQ(!0);return;case"runtime_updated":{let t=null!==(S=e.app_id)&&void 0!==S?S:null===(g=e.data)||void 0===g?void 0:g.app_id,n=null!==(b=e.serial)&&void 0!==b?b:null===(v=e.data)||void 0===v?void 0:v.serial,r=null!==(A=e.tag)&&void 0!==A?A:null===(_=e.data)||void 0===_?void 0:_.tag,i=null!==(T=e.path)&&void 0!==T?T:null===(y=e.data)||void 0===y?void 0:y.path,a=null!==(E=e.result)&&void 0!==E?E:null===(w=e.data)||void 0===w?void 0:w.result;if("string"!=typeof t||"number"!=typeof n&&"string"!=typeof n||null!=r&&"string"!=typeof r||"harness_only"!==i&&"full"!==i||"success"!==a&&"rolled_back"!==a&&"rejected"!==a&&"failed"!==a)return;let o={app_id:t,serial:n,tag:"string"==typeof r?r:void 0,path:i,result:a};es.current?el.current.push(o):D(o);return}case"sandbox_status":let R=(0,M.VC)(e);e1(R),"running"===(0,M.G2)(R)&&(eJ(!0),eQ(!1));return;case"state_snapshot":if(e.state&&tH(e.state),e.sandbox_health){let t=(0,M.VC)(e.sandbox_health);e1(t),"running"===(0,M.G2)(t)&&(eJ(!0),eQ(!1))}if(e.app_status){let t=["building","creating_repository"].includes(e.app_status),n=["deployed","build_failed","permanently_failed","deployment_failed","repository_failed"].includes(e.app_status);t&&!e4?(e2(!0),eV("building"===e.app_status?"Building...":"Creating repository...")):n&&e4&&(e2(!1),eK(0),eV(""))}return}(e.changes||e.state)&&tH(e.changes||e.state)},t$=async e=>{try{if(e6.current&&e9)try{var t,n,r,i;let a=await e6.current.getStateSnapshot(e),o=(null===(n=a.data)||void 0===n?void 0:null===(t=n.state)||void 0===t?void 0:t.state)||{},s=(null===(r=a.data)||void 0===r?void 0:r.state)||{};null===(i=a.data)||void 0===i||i.sandbox_health,eW&&eW.id===s.id||eU(s),tH(o,{skipLyraChat:!0});return}catch(e){console.warn("⚠️ WebSocket state load failed, falling back to REST:",e)}let a=y(),o=await fetch("".concat("https://api.beta.architect.new","/api/v1/apps/").concat(e),{headers:{...a&&{Authorization:"Bearer ".concat(a)}}});if(!o.ok)throw Error("HTTP error! status: ".concat(o.status));let s=await o.json(),l=s.state||{};eW&&eW.id===s.id||eU(s),tH(l,{skipLyraChat:!0})}catch(e){console.error("❌ Failed to load state from server:",e)}},tV=async(e,t)=>{let n="https://api.beta.architect.new",r=y(),i=t?1:2,a=t?"".concat(n,"/api/v1/apps/").concat(e,"/messages?rounds=").concat(i,"&before=").concat(encodeURIComponent(t)):"".concat(n,"/api/v1/apps/").concat(e,"/messages?rounds=").concat(i),o=await fetch(a,{headers:{...r&&{Authorization:"Bearer ".concat(r)}}});if(!o.ok)throw Error("Messages fetch failed: ".concat(o.status));return o.json()},tZ=async e=>{try{var t;let n=await tV(e),r=(0,f.W)(n.messages);H(e=>(0,g.aL)((0,f.W)(e),r)),er(n.has_more),eo.current=null!==(t=n.next_cursor)&&void 0!==t?t:null}catch(e){console.error("❌ Failed to fetch initial Lyra messages:",e)}},tJ=async e=>{try{var t;let n=await tV(e),r=(0,g.Zf)((0,f.W)(n.messages));H(e=>(0,g.aL)(e,r)),er(n.has_more),eo.current=null!==(t=n.next_cursor)&&void 0!==t?t:null}catch(e){console.error("❌ Failed to refetch Lyra messages:",e)}},tX=async()=>
1{if((null==eW?void 0:eW.id)&&en&&!ei&&eo.current){ea(!0);try{var e;let t=await tV(eW.id,eo.current);t.messages.length>0&&H(e=>(0,g.aL)((0,g.Zf)((0,f.W)(t.messages)),e)),er(t.has_more),eo.current=null!==(e=t.next_cursor)&&void 0!==e?e:null}catch(e){console.error("❌ Failed to fetch older Lyra messages:",e)}finally{ea(!1)}}},tQ=async(e,t)=>{try{let n=t||c;if(!S||!n)return console.warn("⚠️ Missing token or apiKey for group creation, skipping..."),null;let r=d;if(!r){let e=await (0,k.BN)(S);if(!(r=(null==e?void 0:e.policyId)||""))return console.warn("⚠️ Could not get policyId, skipping group creation"),null;v(r)}return await _(e,r,S,c)}catch(e){return console.error("❌ Failed to create agent group (non-critical):",e),null}},t0=async(e,t,n,r)=>{var i,a,o;let l=null!==(i=null==r?void 0:r.skipPlan)&&void 0!==i&&i;eH(!0),eK(0),eV(""),e2(!1),eV("Generating app name...");let d=l?tq():await tj(e,t),h=tB(),m=n||c;try{if(m){(e6.current||te.current)&&(null===(a=e6.current)||void 0===a||a.close(),e6.current=null,te.current=!1,e7(!1)),te.current=!1;let e=new p("wss://api.beta.architect.new/api/v1/ws",m,t||void 0,()=>y());e8.current++;try{let n,r;eV("Connecting..."),await e.connect(),eK(5),e6.current=e,e7(!0),e.onDisconnect(()=>e7(!1)),e.onReconnect(()=>{e7(!0),em(!1),tr("websocket-reconnect"),(null==eW?void 0:eW.id)&&t$(eW.id).finally(()=>{em(!0)})});try{let e=await (0,x.PR)(t,S);n=(null==e?void 0:e.group_id)||void 0}catch(e){}u||console.error("❌ organizationId is empty when creating app — Pagos org not loaded yet"),n||console.warn("⚠️ group_id is empty when creating app — will be resolved from user record on backend");let i=eS.startsWith("ds:")?eS.slice(3):void 0;if(!i&&eS&&"auto"!==eS){let e=(0,P.jY)(eS);e&&(r=function(e){let t=function(e){var t;let n=e.colors;return[["--background",n.background],["--foreground",n.foreground],["--card",n.card],["--card-foreground",n.cardForeground],["--popover",n.popover],["--popover-foreground",n.popoverForeground],["--primary",n.primary],["--primary-foreground",n.primaryForeground],["--secondary",n.secondary],["--secondary-foreground",n.secondaryForeground],["--muted",n.muted],["--muted-foreground",n.mutedForeground],["--accent",n.accent],["--accent-foreground",n.accentForeground],["--destructive",n.destructive],["--destructive-foreground",n.destructiveForeground],["--border",n.border],["--input",n.input],["--ring",n.ring],["--chart-1",n.chart1],["--chart-2",n.chart2],["--chart-3",n.chart3],["--chart-4",n.chart4],["--chart-5",n.chart5],["--sidebar-background",n.sidebar],["--sidebar-foreground",n.sidebarForeground],["--sidebar-primary",n.sidebarPrimary],["--sidebar-primary-foreground",n.sidebarPrimaryForeground],["--sidebar-accent",n.sidebarAccent],["--sidebar-accent-foreground",n.sidebarAccentForeground],["--sidebar-border",n.sidebarBorder],["--sidebar-ring",n.ring],["--radius",(null===(t=e.design)||void 0===t?void 0:t.radius)||"0.5rem"]].map(e=>{let[t,n]=e;return"    ".concat(t,": ").concat(n,";")}).join("\n")}(e),n=function(e){let t=[];return e.fontSans&&t.push("    --font-sans: ".concat(e.fontSans,";")),e.fontSerif&&t.push("    --font-serif: ".concat(e.fontSerif,";")),e.fontMono&&t.push("    --font-mono: ".concat(e.fontMono,";")),t.join("\n")}(e),r=n?"\n".concat(n):"";return"@tailwind base;\n@tailwind components;\n@tailwind utilities;\n\n@layer base {\n  :root {\n".concat(t).concat(r,"\n  }\n  .dark {\n").concat(t).concat(r,"\n  }\n}\n\n@layer base {\n  * {\n    @apply border-border;\n  }\n  body {\n    @apply bg-background text-foreground font-sans;\n  }\n}\n")}(e))}eV("Creating app...");let a=await e.createApp({name:d,user_id:t,session_id:h,deployment_provider:F?"coolify":"netlify",org_id:u||void 0,group_id:n,bearer_token:y()||void 0,design_system_id:i,design_system_css:r,skip_plan:l||void 0}),c=null===(o=a.data)||void 0===o?void 0:o.app;if(!c)throw new s.un({errorCode:"OPERATION_FAILED",message:"App creation completed without returning the new app record.",retryable:!1,requestId:"string"==typeof a.request_id?a.request_id:void 0});if(c.id)try{sessionStorage.setItem("planTheme_".concat(c.id),eS)}catch(e){}(0,R.trackAppCreated)(t,h||"",c.id,c.generated_name||c.name||d);let p={...c,session_id:h};return eU(p),eK(20),e.subscribe(c.id,tK),e2(!1),eV("App created. Starting its sandbox…"),p}catch(n){let t=(0,s.UH)(n,{errorCode:"OPERATION_FAILED",message:"App creation failed.",retryable:!1});throw console.error("WebSocket app creation failed:",t),e.close(),e6.current===e&&(e6.current=null),e7(!1),e2(!1),eK(0),eV((0,s.fs)(t,"create_app").headline),t}}else{let e=new s.un({errorCode:"UNAUTHORIZED",message:"An API key is required to create an app.",retryable:!1});
1throw eV((0,s.fs)(e,"create_app").headline),e}}catch(t){let e=(0,s.UH)(t,{errorCode:"OPERATION_FAILED",message:"App creation failed.",retryable:!1});throw console.error("❌ Error creating app:",e),eV((0,s.fs)(e,"create_app").headline),e}finally{eH(!1)}};(0,i.useEffect)(()=>{let e=async()=>{if(!c){console.warn("⚠️ No API key found, WebSocket state sync disabled");return}if(!(null==eW?void 0:eW.id)||e6.current||te.current)return;te.current=!0,e8.current++;let e=e8.current,t=null;try{if(t=new p("wss://api.beta.architect.new/api/v1/ws",c,w||void 0,()=>y()),await t.connect(),e!==e8.current){te.current=!1,t.close();return}e6.current=t,te.current=!1,e7(!0),t.onDisconnect(()=>e7(!1)),t.onReconnect(()=>{e7(!0),em(!1),tr("websocket-reconnect"),(null==eW?void 0:eW.id)&&t$(eW.id).finally(()=>{em(!0)})}),t.subscribe(eW.id,tK)}catch(e){console.error("❌ Failed to initialize WebSocket for state sync:",e),te.current=!1,t&&t.isReconnecting()?(e6.current=t,e7(!1),t.onDisconnect(()=>e7(!1)),t.onReconnect(()=>{e7(!0),em(!1),tr("websocket-reconnect"),(null==eW?void 0:eW.id)&&t$(eW.id).finally(()=>{em(!0)})})):(t&&t.close(),e7(!1))}};(null==eW?void 0:eW.id)&&c&&w&&!e6.current&&!te.current&&e();let t=e8.current;return()=>{t===e8.current&&e6.current&&(null==eW?void 0:eW.id)&&(te.current=!1,e6.current.unsubscribe(eW.id),e6.current.close(),e6.current=null,e7(!1))}},[null==eW?void 0:eW.id,c,w]);let t1=(0,i.useRef)(new Map),t4=(0,i.useMemo)(()=>tU(ez).length,[ez,ej]);(0,i.useEffect)(()=>{var e;if(!(null==eW?void 0:eW.id)||0===t4||!S||!c)return;let t=null!==(e=t1.current.get(eW.id))&&void 0!==e?e:0;if(t4<=t)return;t1.current.set(eW.id,t4);let n=setTimeout(()=>{tG(eW,ez)},2e3);return()=>{clearTimeout(n),t1.current.set(eW.id,t)}},[null==eW?void 0:eW.id,t4,S,c]);let t2=(0,i.useRef)(null),t3=(0,i.useRef)(null);(0,i.useEffect)(()=>{if((null==eW?void 0:eW.id)&&t2.current!==eW.id){em(!1),(0,g.gC)(eW.id),t3.current&&(clearTimeout(t3.current),t3.current=null),H([]),er(!1),eo.current=null,K([]),et(null),eu.current=null;let e=eW.id;Promise.all([t$(eW.id),tZ(eW.id)]).finally(()=>{em(!0);let t=0,n=()=>{t3.current=null,t2.current===e&&(t+=1,tJ(e),t<3&&(t3.current=setTimeout(n,2e3)))};t3.current=setTimeout(n,2500)}),t2.current=eW.id}},[null==eW?void 0:eW.id]);let t5=(0,i.useRef)(null);(0,i.useEffect)(()=>((null==eW?void 0:eW.id)&&e6.current&&e9&&eh&&q.length>0&&(t5.current&&clearTimeout(t5.current),t5.current=setTimeout(async()=>{try{await e6.current.updateAppState(eW.id,{requirementsMessages:q})}catch(e){console.error("Failed to sync Requirements messages:",e)}},1e3)),()=>{t5.current&&clearTimeout(t5.current)}),[q,null==eW?void 0:eW.id,e9,eh]),(0,i.useEffect)(()=>((null==eW?void 0:eW.id)&&e6.current&&e9&&eh&&B.length>0&&(ti.current&&clearTimeout(ti.current),ti.current=setTimeout(async()=>{if(!td.current.myra){td.current.myra=!0;try{await e6.current.updateAppState(eW.id,{myraChatMessages:B})}catch(e){console.error("Failed to sync Myra messages:",e)}finally{td.current.myra=!1}}},1e3)),()=>{ti.current&&clearTimeout(ti.current)}),[B,null==eW?void 0:eW.id,e9,eh]);let t6=Y.some(e=>e.isStreaming);(0,i.useEffect)(()=>{if(!t6||!(null==eW?void 0:eW.id)||!e6.current||!e9||!eh)return;let e=!1,t=setTimeout(()=>{let t=e6.current,n=t.getActiveStream();(null==n?void 0:n.appId)!==eW.id&&t.checkActiveStream(eW.id).then(t=>{!e&&(null!=t&&t.active||K(e=>e.some(e=>e.isStreaming)?e.map(e=>e.isStreaming?{...e,isStreaming:!1}:e):e))}).catch(()=>{})},5e3);return()=>{e=!0,clearTimeout(t)}},[t6,null==eW?void 0:eW.id,e9,eh]),(0,i.useEffect)(()=>((null==eW?void 0:eW.id)&&"legacy"===(0,m.Ik)(eW.id)&&e6.current&&e9&&eh&&Y.length>0&&(tc.current&&clearTimeout(tc.current),tc.current=setTimeout(async()=>{try{await e6.current.updateAppState(eW.id,{changePlannerMessages:Y})}catch(e){console.error("Failed to sync Change Planner messages:",e)}},1e3)),()=>{tc.current&&clearTimeout(tc.current)}),[Y,null==eW?void 0:eW.id,e9,eh]),(0,i.useEffect)(()=>((null==eW?void 0:eW.id)&&e6.current&&e9&&eh&&(tu.current&&clearTimeout(tu.current),tu.current=setTimeout(async()=>{try{await e6.current.updateAppState(eW.id,{changePlannerMode:$,changePlannerPromptCooldown:Z,activeChangePlan:ee,plannerSessionEpoch:X})}catch(e){console.error("Failed to sync Change Planner meta:",e)}},500)),()=>{tu.current&&clearTimeout(tu.current)}),[$,Z,ee,X,null==eW?void 0:eW.id,e9,eh]),(0,i.useEffect)(()=>((null==eW?void 0:eW.id)&&e6.current&&e9&&eh&&W.length>0&&(ta.current&&clearTimeout(ta.current),ta.current=setTimeout(async()=>
1{if(!td.current.mira){td.current.mira=!0;try{await e6.current.updateAppState(eW.id,{miraChatMessages:W})}catch(e){console.error("Failed to sync Mira messages:",e)}finally{td.current.mira=!1}}},1e3)),()=>{ta.current&&clearTimeout(ta.current)}),[W,null==eW?void 0:eW.id,e9,eh]),(0,i.useEffect)(()=>{let e=eE||eC||eI;return(null==eW?void 0:eW.id)&&e6.current&&e9&&eh&&ef&&!e&&(to.current&&clearTimeout(to.current),to.current=setTimeout(async()=>{if(!td.current.prd){td.current.prd=!0;try{await e6.current.updateAppState(eW.id,{prdContent:ef,mermaidDiagram:ev,colorPalette:ey,selectedThemeId:eS})}catch(e){console.error("Failed to sync PRD:",e)}finally{td.current.prd=!1}}},2e3)),()=>{to.current&&clearTimeout(to.current)}},[ef,ev,ey,eS,null==eW?void 0:eW.id,e9,eh,eE,eC,eI]),(0,i.useEffect)(()=>((null==eW?void 0:eW.id)&&e6.current&&e9&&eh&&eP.length>0&&!eN&&(ts.current&&clearTimeout(ts.current),ts.current=setTimeout(async()=>{if(!td.current.agents){td.current.agents=!0;try{await e6.current.updateAppState(eW.id,{agents:ez})}catch(e){console.error("Failed to sync agents:",e)}finally{td.current.agents=!1}}},1e3)),()=>{ts.current&&clearTimeout(ts.current)}),[eP,ez,null==eW?void 0:eW.id,e9,eh,eN]);let t9=(0,i.useRef)(eN);(0,i.useEffect)(()=>{!0===t9.current&&!1===eN&&eP.length>0&&(null==eW?void 0:eW.id)&&e6.current&&e9&&(async()=>{try{await e6.current.updateAppState(eW.id,{agents:ez})}catch(e){console.error("Failed to sync agents after creation:",e)}})(),t9.current=eN},[eN,eP,ez,null==eW?void 0:eW.id,e9]),(0,i.useEffect)(()=>{var e;if(!ej||!(null===(e=ej.nodes)||void 0===e?void 0:e.length)||0===eP.length)return;let t=!1,n=ej.nodes.map(e=>{var n;if(e.agent_id)return e;let r=null!==(n=e.nodeCategory)&&void 0!==n?n:e.node_category;if(r&&"agent"!==r)return e;let i=eP.find(t=>t.name===e.label);return i&&i.agent_id?(t=!0,{...e,agent_id:i.agent_id}):e});t&&eB({...ej,nodes:n})},[ej,eP]),(0,i.useEffect)(()=>((null==eW?void 0:eW.id)&&e6.current&&e9&&eh&&ej&&(tl.current&&clearTimeout(tl.current),tl.current=setTimeout(async()=>{if(!td.current.workflow){td.current.workflow=!0;try{await e6.current.updateAppState(eW.id,{workflowData:ej})}catch(e){console.error("Failed to sync workflow:",e)}finally{td.current.workflow=!1}}},1e3)),()=>{tl.current&&clearTimeout(tl.current)}),[ej,null==eW?void 0:eW.id,e9,eh]);let t7=async e=>{if(!(null==eW?void 0:eW.id))throw console.error("❌ Cannot update app state: No current app"),Error("No current app");if(!e6.current||!e9)throw console.error("❌ Cannot update app state: WebSocket not connected"),Error("WebSocket not connected");try{await e6.current.updateAppState(eW.id,e)}catch(e){throw console.error("❌ Failed to update app state:",e),e}},t8=e6.current,ne=(0,i.useMemo)(()=>({requirementsMessages:q,setRequirementsMessages:j,addRequirementsMessage:tf,updateRequirementsMessage:tg,clearRequirementsMessages:tv,myraChatMessages:B,setMyraChatMessages:z,addMyraMessage:t_,updateMyraMessage:ty,clearMyraChat:tw,miraChatMessages:W,setMiraChatMessages:U,addMiraMessage:tT,updateMiraMessage:tE,clearMiraChat:tk,lyraChatMessages:G,setLyraChatMessages:H,addLyraMessage:tC,updateLyraMessage:tR,clearLyraChat:tI,changePlannerMessages:Y,setChangePlannerMessages:K,addChangePlannerMessage:tS,updateChangePlannerMessage:tb,clearChangePlannerChat:tA,changePlannerMode:$,setChangePlannerMode:V,changePlannerPromptCooldown:Z,setChangePlannerPromptCooldown:J,activeChangePlan:ee,setActiveChangePlan:et,plannerSessionEpoch:X,setPlannerSessionEpoch:Q,prdContent:ef,setPrdContent:eg,mermaidDiagram:ev,setMermaidDiagram:e_,colorPalette:ey,setColorPalette:ew,selectedThemeId:eS,setSelectedThemeId:eb,selectedAgents:eA,setSelectedAgents:eT,isPrdLoading:eE,setIsPrdLoading:ek,isPrdLoadingRef:tm,isMermaidLoading:eC,setIsMermaidLoading:eR,isColorPaletteLoading:eI,setIsColorPaletteLoading:ex,agents:ez,setAgents:eM,addAgent:tO,updateAgent:tN,clearAgents:tL,newAgentIds:eD,setNewAgentIds:eO,isAgentCreating:eN,setIsAgentCreating:eL,knowledgeBases:eF,setKnowledgeBases:eq,addKnowledgeBase:tF,workflowData:ej,setWorkflowData:eB,currentApp:eW,setCurrentApp:eU,isCreatingApp:eG,setIsCreatingApp:eH,createApp:t0,buildProgress:eY,setBuildProgress:eK,buildMessage:e$,setBuildMessage:eV,isBuildingApp:e4,setIsBuildingApp:e2,isSandboxReady:eZ,setIsSandboxReady:eJ,isSandboxFailed:eX,setIsSandboxFailed:eQ,sandboxHealth:e0,refreshSandboxHealth:tr,isWsConnected:e9,wsClient:t8,pendingPrompt:e3,setPendingPrompt:e5,executePendingPrompt:tx,clearPrdData:tP,updatePrdContent:tM,syncPrdContent:tD,updateAppState:t7,hasMoreLyraMessages:en,isLoadingOlderMessages:e
1i,fetchOlderLyraMessages:tX,isServerStateLoaded:eh,hydrateFromAppState:tY,refetchLyraMessages:tJ,setLyraBuildStreamActive:ec,currentCommitId:ed,setCurrentCommitId:ep}),[q,B,W,G,Y,$,Z,ee,en,ei,ef,ev,ey,eS,eE,tm,eC,eI,ez,eD,eN,eA,eF,ej,eW,eG,eY,e$,e4,eZ,e0,tr,e9,t8,e3,eh,ed,ep]);return(0,r.jsx)(O.Provider,{value:ne,children:l})}},54012:function(e,t,n){n.d(t,{PH:function(){return s},W:function(){return h},XY:function(){return u},iq:function(){return c},pz:function(){return p},sm:function(){return d},vb:function(){return l}});let r=["## PRD Document Analysis","**Complete PRD Document:**","**Skills authored during planning","**Design artifacts from planning","**Planning artifacts on disk:**","On-disk handoff:"],i=["Implement the following change plan:","Switching from Plan to Build."];function a(e){return!!e&&i.some(t=>e.includes(t))}function o(e){return!!e&&!(e.length<400)&&r.some(t=>e.includes(t))}function s(e){return a(e)||o(e)}function l(e){let t=e.trim();return t?"Implement change plan: ".concat(t):"Implement approved change plan"}function c(e){let t=e||"";return t.includes("plan-handoff/")||t.includes("Planning artifacts on disk")?"Build the app from [PRD Document] (planning artifacts on disk)":t.includes("## Skill Files")||t.includes("## UI Wireframes")||t.includes("## Design Artifacts")||t.includes("planning skills and design artifacts")||t.includes("**Skills authored during planning")?"Build the app from [PRD Document] (includes planning skills and design artifacts)":t.includes("**Available Agents:**")||t.includes("use [PRD Document] to generate")?"Use the [PRD Document] and [Agents Data] to generate the app":"Build the app from [PRD Document]"}function u(e){return a(e)?function(e){let t=e.match(/^Title:\s*(.+)$/m);return(null==t?void 0:t[1])?"Implement change plan: ".concat(t[1].trim()):e.includes("Switching from Plan to Build")?"Switch to Build — implementing latest change plan":"Implement approved change plan"}(e):o(e)?c(e):e}function d(e,t){let n=String(e||"").replace(/\\[nrt]/g,e=>"\\n"===e?"\n":"\\t"===e?"	":"\r").trim().toLowerCase(),r=String(t||"").trim().toLowerCase();return"thinking_tokens"===n.replace(/^system:\s*/i,"").trim()||"thinking_tokens"===r}function p(e,t,n){if("user_message"===t){let t=n.request_id;if(t&&e.some(e=>{var n;return("User"===e.type||"user_message"===e.eventType)&&((null===(n=e.metadata)||void 0===n?void 0:n.request_id)===t||e.id==="user-".concat(t.slice(0,12)))}))return!0;let r="string"==typeof n.content?n.content:"";if(s(r)&&e.some(e=>("User"===e.type||"user_message"===e.eventType)&&!s(e.content||"")))return!0;let i=u(r);if(i&&e.some(e=>("User"===e.type||"user_message"===e.eventType)&&u(e.content||"")===i))return!0}if("chat_started"===t){let t=n.session_id;if(t&&e.some(e=>("session_card"===e.eventType||"Session"===e.type)&&"string"==typeof e.content&&e.content.includes(t.slice(0,8))))return!0}return!1}function h(e){let t=e.filter(e=>!function(e){var t;let n="string"==typeof(null===(t=e.metadata)||void 0===t?void 0:t.message_type)?e.metadata.message_type:void 0;return d(e.content,n)}(e)).map(e=>{if("User"!==e.type&&"user_message"!==e.eventType)return e;let t=e.content||"",n=u(t);return n===t?e:{...e,content:n}});return t.some(e=>("User"===e.type||"user_message"===e.eventType)&&!s(e.content||"")&&(/^Implement change plan:/.test(e.content||"")||/^Build the app from \[PRD Document\]/.test(e.content||"")||/^Switch to Build —/.test(e.content||"")))?t.filter(e=>!(("User"===e.type||"user_message"===e.eventType)&&s(e.content||""))):t}},17624:function(e,t,n){n.d(t,{Bx:function(){return o},D4:function(){return a},Ld:function(){return s}});let r=new Map,i=(e,t)=>"".concat(e,"::").concat(t);function a(e,t){return r.get(i(e,t))}function o(e,t,n){r.set(i(e,t),n)}function s(e,t){if(e&&t)r.delete(i(e,t));else if(e){let t="".concat(e,"::");for(let e of Array.from(r.keys()))e.startsWith(t)&&r.delete(e)}else r.clear()}},91041:function(e,t,n){n.d(t,{Kg:function(){return f},Lb:function(){return v},Q4:function(){return u},Zf:function(){return p},aL:function(){return d},gC:function(){return g},t3:function(){return m}});var r=n(54012);function i(e){return e.metadata}function a(e){var t,n,r;return(null===(t=i(e))||void 0===t?void 0:t.request_id)||((null===(n=e.id)||void 0===n?void 0:n.startsWith("architect-"))?e.id.slice(10):(null===(r=e.id)||void 0===r?void 0:r.startsWith("user-"))&&e.id.length>5?e.id.slice(5):void 0)}function o(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:160;return(e.content||"").trim().slice(0,t)}function s(e){return(e.content||"").trim().replace(/\s+/g," ").toLowerCase()}function l(e,t){var n,r,o,l;
1if("github_sync_indicator"!==e.eventType||"github_sync_indicator"!==t.eventType)return!1;let c=a(e),u=a(t);return(!c||!u||c.slice(0,12)===u.slice(0,12))&&(null===(n=i(e))||void 0===n?void 0:n.github_sync_status)===(null===(r=i(t))||void 0===r?void 0:r.github_sync_status)&&((null===(o=i(e))||void 0===o?void 0:o.github_sync_phase)||"pull")===((null===(l=i(t))||void 0===l?void 0:l.github_sync_phase)||"pull")&&s(e)===s(t)}function c(e){var t,n,l,c,u,d,p,h,m,f,g,v;if("ui_compile_status"===e.eventType){let t=a(e),n=null===(c=i(e))||void 0===c?void 0:c.generation,r="number"==typeof n||"string"==typeof n?String(n):"";return t&&r?"ui-compile:".concat(t,":").concat(r):e.id?"ui-compile-id:".concat(e.id):null}if("ui_preview_frame"===e.eventType){let t=a(e),n=null===(u=i(e))||void 0===u?void 0:u.capture_id,r=null===(d=i(e))||void 0===d?void 0:d.generation,o="string"==typeof n&&n?n:"number"==typeof r||"string"==typeof r?"generation-".concat(r):"";return t&&o?"ui-preview:".concat(t,":").concat(o):e.id?"ui-preview-id:".concat(e.id):null}if("commit_card"===e.eventType){let t=(null===(p=i(e))||void 0===p?void 0:p.commit_id)||(null===(h=i(e))||void 0===h?void 0:h.commit_hash)||"";return t?"commit:".concat(t):null}if("User"===e.type||"user_message"===e.eventType){let t=a(e);if(t&&t.length>=8)return"user:".concat(t.slice(0,12));let n=(0,r.XY)(e.content||"");return n?"user-content:".concat(n):null}if("session_card"===e.eventType||"Session"===e.type){let t=function(e){var t,n;let r=null===(t=i(e))||void 0===t?void 0:t.session_id;if(r)return r.slice(0,8);let a=(e.content||"").match(/New Session\s*[•·]\s*([a-f0-9]{6,12})/i);return null!==(n=null==a?void 0:a[1])&&void 0!==n?n:null}(e);return t?"session:".concat(t):null}if("github_sync_indicator"===e.eventType){let t=a(e),n=(null===(m=i(e))||void 0===m?void 0:m.github_sync_status)||"unknown",r=(null===(f=i(e))||void 0===f?void 0:f.github_sync_phase)||"pull",o=s(e),l=t?"".concat(t.slice(0,12),":"):"";return o?"github-sync:".concat(l).concat(r,":").concat(n,":").concat(o):null}if((null===(t=e.id)||void 0===t?void 0:t.startsWith("architect-"))||"Architect"===e.type||"message_block"===e.eventType){let t=a(e),n=(e.content||"").toLowerCase().replace(/[^a-z0-9]+/g,"").slice(0,200);return t&&n?"architect:".concat(t.slice(0,12),":").concat(n):n?"architect-content:".concat(n):e.id?"architect-id:".concat(e.id):null}let _=null===(n=i(e))||void 0===n?void 0:n.request_id;if("message_received"===e.eventType&&"string"==typeof _&&_.length>0&&(v=e.content||"",/<comment>[\s\S]*<\/comment>/.test(v)||/<step\s+kind=/.test(v)||/<edit>/.test(v)||/<file[\s>]/.test(v)||/\[OPTIONS\]/.test(v)||/\[SELECT\]/.test(v)||/\[SUGGEST\]/.test(v)||/\[READY-FOR-PRD\]/.test(v))){let t=(e.content||"").toLowerCase().replace(/[^a-z0-9]+/g,"").slice(0,200);return t?"architect:".concat(_.slice(0,12),":").concat(t):"architect-content:".concat(_.slice(0,12))}let y=null===(l=i(e))||void 0===l?void 0:l.tool_use_id;if(y){let t=e.eventType||e.type||"tool";return"tool:".concat(y,":").concat(t)}if("todo_panel"===e.eventType){let t=a(e),n=null===(g=i(e))||void 0===g?void 0:g.todos,r=Array.isArray(n)&&n.length?JSON.stringify(n.map(e=>({c:e.content,s:e.status}))):o(e,80);return t?"todo:".concat(t.slice(0,12),":").concat(r):"todo:".concat(r)}let w=a(e),S=e.eventType||e.type,b=o(e,120);return w&&S?"evt:".concat(w.slice(0,12),":").concat(S,":").concat(b):S&&b?"evt:".concat(S,":").concat(b):e.id?"id:".concat(e.id):null}function u(e,t){if(e.some(e=>e.id===t.id))return!0;if("github_sync_indicator"===t.eventType)return e.some(e=>l(e,t));let n=c(t);return!!n&&e.some(e=>c(e)===n)}function d(e,t){if(0===t.length)return e;if(0===e.length)return p(t);let n=[...e];for(let e of t){let t=function(e,t){let n=e.findIndex(e=>e.id===t.id);if(-1!==n)return n;if("github_sync_indicator"===t.eventType)return e.findIndex(e=>l(e,t));let r=c(t);return r?e.findIndex(e=>c(e)===r):-1}(n,e);-1===t?n.push(e):"number"==typeof e.seq&&n[t].seq!==e.seq&&(n[t]={...n[t],seq:e.seq})}return p(n)}function p(e){let t=[],n=new Set,i=new Set;
1for(let a of(0,r.W)(e)){if(i.has(a.id)||"github_sync_indicator"===a.eventType&&t.some(e=>l(e,a)))continue;let e=c(a);if(e){if(n.has(e))continue;n.add(e)}i.add(a.id),t.push(a)}return t}let h="lyraAutoSendDone:";function m(e,t){e&&sessionStorage.setItem("".concat(h).concat(e),t||"1")}function f(e){return!!e&&!!sessionStorage.getItem("".concat(h).concat(e))}function g(e){e&&sessionStorage.removeItem("".concat(h).concat(e))}function v(e,t,n){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Date.now();if(!e)return!1;let i="".concat(e,":").concat(t,":").concat(n),a="lyraPlanEventClaim:".concat(i),o=sessionStorage.getItem(a),s=null===o?void 0:Number(o);return(!(void 0!==s&&Number.isFinite(s))||!(r-s<1500))&&(sessionStorage.setItem(a,String(r)),!0)}},45425:function(e,t,n){n.d(t,{FD:function(){return o},Ik:function(){return i},RX:function(){return c},mw:function(){return s},sN:function(){return a},ux:function(){return l}});let r=new Map;function i(e){if(!e)return"unknown";let t=r.get(e);return t?t.has("unified_agent_thread")?"unified":"legacy":"unknown"}let a="The planning sandbox is still initializing. Please try again in a moment.";function o(e){return"unified"===i(e)}function s(e){let t=i(e);return"unknown"===t?"unready":t}async function l(e,t){let n=s(e);return"unready"===n&&(await t(),n=s(e)),n}function c(e,t){let n=t&&"object"==typeof t&&!Array.isArray(t)?t:void 0,i=n&&"features"in n?n.features:void 0,a=Array.isArray(i)?i.filter(e=>"string"==typeof e):[];r.set(e,new Set(a))}},14581:function(e,t,n){n.d(t,{FD:function(){return o.FD},FX:function(){return y},Gh:function(){return v},Ik:function(){return o.Ik},Mw:function(){return g},Ne:function(){return b},RS:function(){return S},Z:function(){return m},bb:function(){return A},lS:function(){return E},mw:function(){return o.mw},qn:function(){return f},sN:function(){return o.sN},sO:function(){return h},ux:function(){return o.ux}});var r=n(84125),i=n(92470),a=n(65770),o=n(45425);let s=new Map,l=new Map,c=new Map,u=new Map,d="https://api.beta.architect.new",p=null;function h(e,t){t&&(e?u.set(t,e):u.delete(t))}function m(e){var t;return e&&null!==(t=u.get(e))&&void 0!==t?t:null}function f(){return(0,a.rd)()}function g(e){p&&(p.abort(),p=null),e?(l.delete(e),s.delete(e),c.delete(e),u.delete(e)):(l.clear(),s.clear(),c.clear(),u.clear())}function v(e,t,n,i){var a,o;let s=arguments.length>4&&void 0!==arguments[4]&&arguments[4],l=((null==i?void 0:i.trim())||(null===(a=[...e].reverse().find(e=>"user"===e.role&&e.content.trim()))||void 0===a?void 0:a.content)||"").trim();if(s)return[l,null==n?void 0:n.trim()].filter(Boolean).join("\n\n");let c=e.slice(-8);for(l&&!c.some(e=>"user"===e.role&&e.content.trim()===l)&&(c=[...c.slice(-7),{role:"user",content:l}]);c.length>1&&"assistant"===c[0].role;)c=c.slice(1);let u=[];for(let e of c){if(!(null===(o=e.content)||void 0===o?void 0:o.trim()))continue;let t="user"===e.role?"User":"Assistant",n="assistant"===e.role?(0,r.Qb)(e.content.trim()):e.content.trim();u.push("".concat(t,":\n").concat(n))}!u.some(e=>e.startsWith("User:"))&&l&&u.push("User:\n".concat(l));let d=u.join("\n\n");return t.trim()&&(d+="\n\n---\n[CURRENT PLAN — this is the exact, current plan text. To change it, emit surgical <edit><old>…</old><new>…</new></edit> blocks whose <old> is copied VERBATIM from the text below. Do NOT re-emit the whole plan unless the change is large/structural. If nothing about the plan changes, leave it alone and just reply in a <comment>.]\n\n"+t.trim()),(null==n?void 0:n.trim())&&(d+="\n\n"+n.trim()),d}async function _(e,t,n,r){return!!await w(e,t,n,r)&&(c.get(e)||(await new Promise(e=>setTimeout(e,2e3)),c.set(e,!0)),!0)}function y(e,t,n,r){return w(e,t,n,r)}async function w(e,t,n,r){if(l.get(e))return!0;let a=s.get(e);if(a)return a;let o=(async()=>{let a=sessionStorage.getItem("templateId_".concat(e)),o={LYZR_API_KEY:n||"",VITE_LYZR_API_KEY:n||"",...r&&{LYZR_USER_ID:r,VITE_LYZR_USER_ID:r,NEXT_LYZR_USER_ID:r}};try{return await (0,i.n)(e,a,o,t,n),l.set(e,!0),!0}catch(e){return console.warn("[plan] sandbox initialization failed",e),!1}})();s.set(e,o);try{return await o}finally{s.delete(e)}}async function S(e,t){try{await fetch("".concat(d,"/api/v1/apps/").concat(e,"/plan/cancel"),{method:"POST",headers:{Accept:"application/json",...t?{Authorization:"Bearer ".concat(t)}:{}}})}catch(e){}}async function b(e,t){try{await fetch("".concat(d,"/api/v1/apps/").concat(e,"/plan/reset"),{method:"POST",headers:{Accept:"application/json",...t?{Authorization:"Bearer ".concat(t)}:{}}})}catch(e){}}async function A(e,t){try{await fetch("".concat(d,"/api/v1/apps/").concat(e,"/plan/keepalive"),{method:"POST",headers:{Accept:"application/json",...t?{Authorization:"Bearer ".concat(t)}:{}}})}catch(e){}}function T(e,t,n,r){if(!t.startsWith("data: "))return!1;try{let i=JSON.parse(t.slice(6)),a=i.event_type,o=i.data||{};if("plan_turn_started"===a&&o.session_id)return h(o.session_id,e),!1;if("message_received"===a&&"text"===o.type){let e=o.content;return"string"==typeof e&&e&&n.onToken(e),!1}if("plan_turn_completed"===a||"chat_completed"===a||"plan_mode_completed"===a){if(r.failed)return!0;return r.completed=!0,n.onDone(),!0}if("error"===a)return r.failed=!0,n.onError(o.error||"Plan stream error"),!0}catch(e){}return!1}async function E(e,t,n,r,i,o,s,l){let c=!1;try{var u,h,f,g,v,y;let i,w;if(!await _(e,r,n,o))throw Error("Sandbox initialization failed");(0,a.Vv)(e),c=!0,p&&(p.abort(),await S(e,r));let b=new AbortController;p=b;let A=!1,E=()=>setTimeout(()=>{A=!0,b.abort()},18e4),k=E(),C=()=>{clearTimeout(k),k=E()},R=()=>b.abort();null==l||null===(u=l.signal)||void 0===u||u.addEventListener("abort",R,{once:!0});try{i=await fetch("".concat(d,"/api/v1/apps/").concat(e,"/plan/turn"),{method:"POST",signal:b.signal,headers:{Accept:"text/event-stream","Content-Type":"application/json",...r?{Authorization:"Bearer ".concat(r)}:{}},body:JSON.stringify({message:t,session_id:m(e)})})}catch(t){clearTimeout(k),null==l||null===(h=l.signal)||void 0===h||h.removeEventListener("abort",R),p===b&&(p=null);let e=t instanceof Error&&"AbortError"===t.name?"Plan turn timed out or was cancelled. Please retry.":t instanceof Error?t.message:String(t);throw Error(e)}if(!i.ok){clearTimeout(k),null==l||null===(f=l.signal)||void 0===f||f.removeEventListener("abort",R),p===b&&(p=null);let e=await i.text().catch(()=>"");throw Error(e||"Plan turn failed (".concat(i.status,")"))}if(!i.body)throw clearTimeout(k),null==l||null===(g=l.signal)||void 0===g||g.removeEventListener("abort",R),p===b&&(p=null),Error("Plan stream returned no body");let I=i.body.getReader(),x=new TextDecoder,P="",M={completed:!1,failed:!1},D={onToken:s.onToken,onDone:()=>
1{M.completed=!0,s.onDone()},onError:e=>{w=e,s.onError(e)}};try{for(;;){let{done:t,value:n}=await I.read();if(t)break;C();let r=(P+=x.decode(n,{stream:!0})).split("\n");for(let t of(P=null!==(v=r.pop())&&void 0!==v?v:"",r)){let n=t.trim();if(n&&T(e,n,D,M))return{completed:M.completed,error:w}}}return P.trim()&&T(e,P.trim(),D,M),{completed:M.completed,error:w}}catch(t){let e=A?"The planning agent stopped sending updates for 3 minutes. Please retry.":t instanceof Error?t.message:String(t);throw D.onError(e),t instanceof Error?t:Error(e)}finally{clearTimeout(k),null==l||null===(y=l.signal)||void 0===y||y.removeEventListener("abort",R),p===b&&(p=null)}}finally{c&&(0,a.Wm)(e)}}},84125:function(e,t,n){n.d(t,{$p:function(){return I},Cz:function(){return b},Qb:function(){return h},RC:function(){return v},UO:function(){return C},Z4:function(){return E},a9:function(){return f},aU:function(){return k},au:function(){return d},bi:function(){return p},e0:function(){return x},ij:function(){return c},lG:function(){return s},m$:function(){return w},nj:function(){return y},ny:function(){return R},q1:function(){return T},sS:function(){return m},uV:function(){return i},w8:function(){return A},y6:function(){return S}});var r=n(91036);function i(e){var t,n;return"design"===("file"===e.type?e.fileType:e.type)&&/app\s+mockup/i.test(null!==(n=e.title)&&void 0!==n?n:"")&&!!(null===(t=e.content)||void 0===t?void 0:t.trim())}let a=/\[SELECTED_THEME:\s*((?:tw:)?[a-z0-9-]+)\s*\]/gi;function o(e){let t=new RegExp(a.source,a.flags);return Array.from(e.matchAll(t),e=>e[1].toLowerCase())}function s(e){let t=new RegExp(a.source,a.flags);return e.replace(t,"")}function l(e,t,n){return{status:"invalid",error:{kind:"selected-theme-marker",code:e,message:t,markerIds:n}}}function c(e){let t=/<comment>([\s\S]*?)<\/comment>/.exec(e);if(!t||void 0===t.index)return{status:"pending"};let n=t.index,i=n+t[0].length,a=o(e.slice(0,n)+"\n"+e.slice(i));if(a.length>0)return l("outside-comment","The selected-theme marker must be inside the completed <comment> block.",a);let s=o(t[1]);if(0===s.length)return l("missing","The completed <comment> block must contain exactly one selected-theme marker.",[]);if(s.length>1)return l("multiple","The completed <comment> block contains more than one selected-theme marker.",s);let c=s[0];return c.startsWith("tw:")?(0,r.qX)(c)?{status:"valid",themeId:c}:{status:"unknown",themeId:c,error:{kind:"selected-theme-marker",code:"unknown",message:"The selected-theme marker names an unknown theme: ".concat(c,"."),markerIds:s}}:l("invalid-namespace","The selected-theme marker must use the tw: namespace.",s)}let u=/^[-*•]\s*/;function d(e){let t=[];for(let n of e.match(/<rich>[\s\S]*?<\/rich>/g)||[])t.push(n.replace(/^<rich>/,"").replace(/<\/rich>$/,""));let n=e.lastIndexOf("<rich>");if(-1!==n){let r=e.slice(n);/<\/rich>/.test(r)||t.push(r.replace(/^<rich>/,""))}return t.join("\n")}function p(e){let t;let n=[],r=/<file\s+type="(webpage|design)"\s+title="([^"]*)"\s*>([\s\S]*?)<\/file>/g;for(;t=r.exec(e);)n.push({type:t[1],title:t[2].trim()||"Design",content:t[3].trim()});let i=e.match(/<file\s+type="(webpage|design)"\s+title="([^"]*)"\s*>([\s\S]*)$/);if(i){let e=i[2].trim()||"Design";!n.some(t=>t.title===e)&&i[3].trim()&&n.push({type:i[1],title:e,content:i[3].trim()})}let a=new Map;for(let e of n)a.set("".concat(e.type,":").concat(e.title.toLowerCase()),e);return Array.from(a.values())}function h(e){let t=e.replace(/<file\s+type="[^"]*"[^>]*>[\s\S]*?<\/file>/g,"[design artifact omitted]");return(t=(t=t.replace(/<file\s+type="[^"]*"[^>]*>[\s\S]*$/g,"[design in progress]")).replace(/<artifact\s+type="html"[^>]*>[\s\S]*?<\/artifact>/g,"[wireframe omitted]")).length>4e3&&(t="".concat(t.slice(0,4e3),"\n…[truncated for context]")),t}function m(e){return"file-".concat(e.type,"-").concat(e.title.toLowerCase().replace(/\s+/g,"-"))}function f(e){let t;let n=function(e){let t=e;for(;;){let e=function(e){let t;let n=/\[(OPTIONS|SELECT)\]/g;for(;t=n.exec(e);){let n=t[1],r=t.index+t[0].length,i=e.slice(r),a=i.search(new RegExp("\\[/".concat(n,"\\]"))),o=i.search(/\[(OPTIONS|SELECT)\]/);if(!(-1===a||-1!==o&&o<a))continue;let s=0,l=-1;for(let e of i.split("\n")){let t=e.trim();if(u.test(t))l=s+e.length;else if(t)break;s+=e.length+1}if(-1===l)break;let c=r+l;return"".concat(e.slice(0,c),"\n[/").concat(n,"]").concat(e.slice(c))}return null}(t);if(null===e)return t;t=e}}(function(e){var t;let n="<rich>",r=e.lastIndexOf(n);if(-1===r)return e;let i=r+n.length,a=e.slice(i);if(/<\/rich>/.test(a))return e;let o=a.match(/\[(?:SUGGEST|OPTIONS|SELECT|READY-FOR-PRD)\]/),s=null!==(t=null==o?void 0:o.index)&&void 0!==t?t:a.length,l=a.slice(0,s).lastIndexOf(">"),c=i+(-1===l?s:l+1);return e.slice(0,c)+"</rich>"+e.slice(c)}(e)),r=[],i=/\[(OPTIONS|SELECT)\]([\s\S]*?)\[\/\1\]|<rich>([\s\S]*?)<\/rich>/g,a=0,o=0;for(;t=i.exec(n);){let e=n.slice(a,t.index).trim();if(e&&r.push({type:"text",text:e}),t[1]){let e="OPTIONS"===t[1]?"radio":"checkbox";r.push({type:"options",kind:e,id:"seg-".concat(o++),options:t[2].split("\n").map(e=>e.trim()).filter(e=>u.test(e)).map(e=>{let t,n=e.replace(u,""),r=n.match(/^\[([xX ])\]\s*/);r&&(t="x"===r[1].toLowerCase()||void 0,n=n.slice(r[0].length));let i=n.split("|");return{label:i[0].trim(),description:i.slice(1).join("|").trim()||void 0,defaultChecked:t}}).filter(e=>e.label)})}else{let e=(t[3]||"").trim();e&&r.push({type:"rich",id:"seg-".concat(o++),html:e})}a=i.lastIndex}let s=n.slice(a).trim();return s&&r.push({type:"text",text:s}),r}let g=new Set(["research","read","write","skill","design","diagram","plan","integrate"]);function v(e){let t=e.trim().toLowerCase();return g.has(t)?t:"write"}let _=/^#{1,3} \S/m;function y(e){let t=e.trim();if(!t)return{comment:"",plan:""};if(/^\s*#/.test(t))return{comment:"",plan:t};let n=_.exec(t);if(!n)return{comment:t,plan:""};let r=t.slice(n.index);return r.length<40?{comment:t,plan:""}:{comment:t.slice(0,n.index).trim(),plan:r.trim()}}function w(e){let t,n,r,i="",a=c(e),o="valid"===a.status||"unknown"===a.status?a.themeId:void 0,l=function(e){let t;let n=[],r=e,i=/<step\s+kind="([^"]*)"\s*>([\s\S]*?)<\/step>/g;for(;t=i.exec(e);){let e=t[2].trim();e&&n.push({kind:v(t[1]),label:e,done:!0})}let a=(r=r.replace(i,"")).match(/<step\s+kind="([^"]*)"\s*>([^<]*)$/);if(a){let e=a[2].trim();e&&n.push({kind:v(a[1]),label:e,done:!1}),r=r.slice(0,r.indexOf(a[0]))}return{steps:n,rest:r}}(e),u=l.steps,d=l.rest,p=function(e){let t=e.lastIndexOf("<comment>");if(-1===t)return e;let n=t+9,r=e.indexOf("</comment>",n),i=-1===r?e.slice(n):e.slice(n,r),a=_.exec(i);if(!a||i.length-a.index<40)return e;let o=n+a.index,s=-1===r?e.slice(o):e.slice(o,r)+e.slice(r+10);return"".concat(e.slice(0,o),"</comment>\n").concat(s)}(d),h=Array.from(p.matchAll(/<comment>([\s\S]*?)<\/comment>/g));if(h.length>0)i=h.map(e=>e[1]).join("\n\n"),d=p.replace(/<comment>[\s\S]*?<\/comment>/g,"");else{let e=p.indexOf("<comment>");-1!==e&&(i=p.slice(e+9),d=p.slice(0,e))}i=s(i),d=s(d);let m=[],f=/<artifact\s+type="html"\s+title="([^"]*)"\s*>([\s\S]*?)<\/artifact>/g;for(;t=f.exec(d);)m.push({title:t[1].trim()||"Wireframe",content:t[2].trim()});let g=(d=d.replace(f,"")).match(/<artifact\s+type="html"\s+title="([^"]*)"\s*>
1/);if(g){let e=d.indexOf(g[0]),t=d.slice(e+g[0].length);t.trim()&&m.push({title:g[1].trim()||"Wireframe",content:t.trim()}),d=d.slice(0,e)}let w=[],S=/<file\s+type="(webpage|pdf|docx|pptx|design|skill)"\s+title="([^"]*)"\s*>([\s\S]*?)<\/file>/g;for(;n=S.exec(d);)w.push({type:n[1],title:n[2].trim()||"Document",content:n[3].trim()});let b=new Map;for(let e of w)b.set("".concat(e.type,":").concat(e.title.toLowerCase()),e);let A=Array.from(b.values());d=(d=d.replace(S,"")).replace(/<file\s+type="[^"]*"\s+title="[^"]*"\s*>[\s\S]*$/g,"");let T=[],E=/<edit>\s*<old>([\s\S]*?)<\/old>\s*<new>([\s\S]*?)<\/new>\s*<\/edit>/g;for(;r=E.exec(d);)T.push({old:r[1],new:r[2]});let k=(d=(d=d.replace(E,"")).replace(/<edit>[\s\S]*$/g,"")).match(/<rich>[\s\S]*?<\/rich>/g);k&&k.length&&(i="".concat(i,"\n").concat(k.join("\n")),d=d.replace(/<rich>[\s\S]*?<\/rich>/g,""));let C=(d=d.replace(/<rich>[\s\S]*$/g,"")).match(/<svg[\s\S]*?<\/svg>/gi);C&&C.length&&(i="".concat(i,"\n").concat(C.map(e=>"<rich>".concat(e,"</rich>")).join("\n")),d=d.replace(/<svg[\s\S]*?<\/svg>/gi,""));let R=(d=d.replace(/<svg[\s\S]*$/gi,"")).trim();if(0===h.length&&-1===e.indexOf("<comment>")&&R){let e=y(R);e.comment&&(i=i?"".concat(i,"\n").concat(e.comment):e.comment),R=e.plan}let I=/\[READY-FOR-PRD\]/.test(i),{suggestions:x,comment:P}=function(e){let t;let n=[],r=/\[SUGGEST\]([\s\S]*?)\[\/SUGGEST\]/g;for(;t=r.exec(e);)for(let e of t[1].split("\n")){let t=e.trim().replace(/^[-*]\s*/,"").trim();t&&n.push(function(e){let t=e.trim(),n=!1;return/^★\s*/.test(t)&&(n=!0,t=t.replace(/^★\s*/,"")),/[[(]\s*(recommended|rec)\s*[\])]/i.test(t)&&(n=!0,t=t.replace(/\s*[[(]\s*(recommended|rec)\s*[\])]\s*/gi," ").trim()),{text:t.trim(),recommended:n}}(t))}let i=e.replace(r,"");return{suggestions:n,comment:i=i.replace(/\[SUGGEST\][\s\S]*$/g,"")}}(i);return{comment:P,ready:I,autoThemeId:o,themeMarker:a,plan:R,planEdits:T,htmls:m,files:A,steps:u,suggestions:x}}function S(e,t){let n=e,r=0;for(let e of t){let t=[e.old,e.old.trim()],i=!1;for(let r of t){if(!r)continue;let t=n.indexOf(r);if(-1!==t){let a=r===e.old?e.new:e.new.trim();n=n.slice(0,t)+a+n.slice(t+r.length),i=!0;break}}!i&&r++}return{content:n,missed:r}}function b(e){return e.replace(/\*{0,3}\s*\[READY-FOR-PRD\]\s*\*{0,3}/g," ").replace(/`\s*`/g,"").replace(/\*\*\s*\*\*/g,"").replace(/\*[ \t]+\*/g,"").replace(/\(\s*(?:,\s*)*\)/g,"").replace(/(^|\s)\*{2,}(?=\s|$)/g,"$1").replace(/[ \t]{2,}/g," ").replace(/ +([.,!?])/g,"$1").replace(/\(\s+/g,"(").replace(/\s+\)/g,")").trim()}function A(e){return e.replace(/\[(OPTIONS|SELECT)\][\s\S]*?\[\/\1\]/g,"").replace(/\[(OPTIONS|SELECT)\][\s\S]*$/g,"").replace(/\[[A-Z-]*$/g,"").trim()}function T(e){return e.replace(/\[(OPTIONS|SELECT)\](?![\s\S]*?\[\/\1\])[\s\S]*$/gm,"").replace(/\[[A-Z-]*$/g,"").trim()}function E(e){var t,n;let r=e.trim();if(!r||/^\s*<(?:!--|svg|g[\s>]|rect|text|line|path|polyline|circle|!doctype|html|div)/i.test(r)||/<svg[\s>]/i.test(r)||/<\/(?:svg|rect|text|g)>/i.test(r))return!1;if(/(^|\n)#{1,6}\s/.test(r))return!0;let i=null!==(n=null===(t=r.match(/\n/g))||void 0===t?void 0:t.length)&&void 0!==n?n:0;return r.length>400&&i>=6}function k(e){return 0===e.trim().length}function C(e,t,n,r){let i=E(e),a=!r&&i?e:null!=t?t:e,o=null!==t?E(t):i,s=E(a)&&(n&&i||r&&o);return{plan:a,readyForBuild:s}}function R(e){return e?[{text:"Generate a workflow diagram of the app",recommended:!0},{text:"Create an on-brand design file for the key screen"},{text:"Draft a skill.md for the core agent"}]:[{text:"Draft the plan now",recommended:!0},{text:"Ask me a few questions to sharpen the scope"}]}function I(e){var t,n,r;if(null===(t=e.rawModelOutput)||void 0===t?void 0:t.trim())return e.rawModelOutput.trim();if(null===(n=e.text)||void 0===n?void 0:n.trim())return e.text.trim();if(null===(r=e.suggestions)||void 0===r?void 0:r.length){let t=e.suggestions.map(e=>{let t=e.recommended?"★ ":"";return"- ".concat(t).concat(e.text)});return"[SUGGEST]\n".concat(t.join("\n"),"\n[/SUGGEST]")}return""}function x(e){let t=e.match(/^\s*#\s+(.+)$/m);return t?t[1].trim():"Plan"}},4660:function(e,t,n){n.d(t,{G2:function(){return a},VC:function(){return o},bn:function(){return r},br:function(){return i}});let r=4;function i(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Math.random();return Math.min(Math.round(Math.min(500*2**Math.max(0,Math.floor(e)),8e3)*(.75+.5*Math.min(1,Math.max(0,t)))),8e3)}function a(e){return e?"sandbox_not_found"===e.error_code?"dead":null!==e.error_code||"dead"===e.status?"unknown":e.status:"unknown"}function o(e){return{sandbox_id:e.sandbox_id,app_id:e.app_id,status:e.status,health:e.health,pid_alive:e.pid_alive,http_code:e.http_code,last_error:e.last_error,last_updated:e.last_updated,timeout_at:e.timeout_at,source:e.source,error_code:e.error_code}}},65770:function(e,t,n){n.d(t,{To:function(){return g},Vv:function(){return l},Wm:function(){return c},m8:function(){return p},rd:function(){return d}});var r=n(65993);let i=new Map,a=new Map,o=new Map;function s(e,t){let n=i.get(e);if(n)return n;let r=t().finally(()=>i.delete(e));return i.set(e,r),r}function l(e){var t;a.set(e,(null!==(t=a.get(e))&&void 0!==t?t:0)+1)}function c(e){let t=a.get(e);if(t){if(t>1){a.set(e,t-1);return}a.delete(e),function(e){if(u(e))return;let t=o.get(e);t&&(o.delete(e),s(e,t.fire).then(e=>
1t.waiters.forEach(t=>{let{resolve:n}=t;return n(e)}),e=>t.waiters.forEach(t=>{let{reject:n}=t;return n(e)})))}(e)}}function u(e){var t;return(null!==(t=a.get(e))&&void 0!==t?t:0)>0}function d(){return a.size>0}function p(e,t){let n=i.get(e);if(n)return n;let r=o.get(e);if(r){let{promise:e,resolve:t,reject:n}=Promise.withResolvers();return r.waiters.push({resolve:e=>t(e),reject:n}),e}if(!u(e))return s(e,t);let{promise:a,resolve:l,reject:c}=Promise.withResolvers();return o.set(e,{fire:t,waiters:[{resolve:e=>l(e),reject:c}]}),a}let h=[1e3,3e3];function m(){return new r.un({errorCode:"CLIENT_ABORTED",message:"Sandbox initialization was cancelled.",retryable:!1})}function f(e,t){if(null==t?void 0:t.aborted)return Promise.reject(m());let{promise:n,resolve:r,reject:i}=Promise.withResolvers(),a=()=>{clearTimeout(o),i(m())},o=setTimeout(()=>{null==t||t.removeEventListener("abort",a),r()},e);return null==t||t.addEventListener("abort",a,{once:!0}),n}async function g(e){let t,{attempt:n,signal:i,onTerminalError:a,sleep:o=f,random:s=Math.random}=e;for(let e=0;e<=h.length;e+=1){if(null==i?void 0:i.aborted)throw m();try{return await n(e+1,i)}catch(l){let n=(0,r.UH)(l,{errorCode:"NETWORK_ERROR",message:"The sandbox initialization request could not reach the server.",retryable:!0});if(t=n,e===h.length||!function(e){let t=e.errorCode.toLowerCase();return 400!==e.status&&401!==e.status&&403!==e.status&&"sandbox_not_found"!==t&&"database_provision_pending"!==t&&"database_connectivity_failed"!==t&&"client_aborted"!==t&&(e.retryable||"network_error"===t)}(n))break;let a=Math.min(500,Math.floor(501*Math.max(0,s())));await o(h[e]+a,i)}}let l=null!=t?t:new r.un({errorCode:"UNKNOWN_ERROR",message:"Sandbox initialization failed.",retryable:!1});throw"CLIENT_ABORTED"!==l.errorCode&&(null==a||a(l)),l}},92470:function(e,t,n){n.d(t,{n:function(){return o}});var r=n(65993),i=n(65770),a=n(45425);function o(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=arguments.length>3?arguments[3]:void 0,o=arguments.length>4?arguments[4]:void 0,l=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};return(0,i.m8)(e,()=>(0,i.To)({signal:l.signal,onTerminalError:l.onTerminalError,attempt:(i,a)=>s(e,t,n,r,o,a,l.timeoutMs)})).then(t=>((0,a.RX)(e,t.lyraCapabilities),t))}async function s(e,t,n,i,a,o){let s=arguments.length>6&&void 0!==arguments[6]?arguments[6]:54e4,l=new AbortController,c=!1,u=()=>l.abort(null==o?void 0:o.reason);null==o||o.addEventListener("abort",u,{once:!0});let d=setTimeout(()=>{c=!0,l.abort()},s);try{let o=await fetch("".concat("https://api.beta.architect.new","/api/v1/apps/").concat(e,"/init"),{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json",...i&&{Authorization:"Bearer ".concat(i)}},body:JSON.stringify({env_vars:n,...t&&{template_id:t},...a&&{api_key:a}}),signal:l.signal});if(!o.ok)throw await (0,r.Wl)(o);let s=await o.json();if(!s||"object"!=typeof s||Array.isArray(s))throw new r.un({errorCode:"INVALID_INIT_RESPONSE",message:"Sandbox initialization returned an invalid response.",retryable:!1,status:o.status});let c="string"==typeof s.sandbox_id?s.sandbox_id:void 0,u="string"==typeof s.app_uri?s.app_uri:void 0;return sessionStorage.setItem("sandbox_initialized_".concat(e),"true"),c&&sessionStorage.setItem("sandbox_id_".concat(e),c),u&&sessionStorage.setItem("app_uri_".concat(e),u),{success:!0,sandboxId:c,appUri:u,lyraCapabilities:s.lyra_capabilities,response:s}}catch(e){if(e instanceof r.un)throw e;if(l.signal.aborted)throw new r.un({errorCode:c?"CLIENT_TIMEOUT":"CLIENT_ABORTED",message:c?"Sandbox initialization timed out before the app responded.":"Sandbox initialization was cancelled.",retryable:!1,cause:e});throw(0,r.UH)(e,{errorCode:"NETWORK_ERROR",message:"The sandbox initialization request could not reach the server.",retryable:!0})}finally{clearTimeout(d),null==o||o.removeEventListener("abort",u)}}n(40257).env.NEXT_PUBLIC_E2B_TEMPLATE_ID},48522:function(e,t,n){n.d(t,{S:function(){return s},TenantProvider:function(){return l}});var r=n(57437),i=n(2265);let a={tenant_id:"default",display_name:"Architect",auth_provider:"memberstack",auth_config:{},features:{marketplace:!0,marketplace_clone:!0,billing:!0,public_signup:!0,support_chat:!0,analytics_tracking:!0,referral_program:!0,new_studio:!1,blank_projects_enabled:!1},branding:{app_name:"Architect"},api_urls:{agent_base_url:"https://agent-prod.studio.lyzr.ai",rag_base_url:"https://rag-prod.studio.lyzr.ai",pagos_base_url:"https://pagos-prod.studio.lyzr.ai",crawler_base_url:"https://crawler-prod.studio.lyzr.ai",asset_service_url:"https://asset.lyzr.app",studio_base_url:"https://studio.lyzr.ai",metrics_ws_url:"wss://metrics.studio.lyzr.ai"},credits_divisor:1},o=(0,i.createContext)(a),s=()=>(0,i.useContext)(o);function l(e){let{children:t}=e,[n,s]=(0,i.useState)(null);return((0,i.useEffect)(()=>{let e=window.location.hostname,t="tenant_config_"+e;try{let e=localStorage.getItem(t);if(e){let t=JSON.parse(e);Date.now()-t.timestamp<3e5&&s(t.config)}}catch(e){}fetch("".concat("https://api.beta.architect.new","/api/v1/tenant/config?domain=").concat(e)).then(e=>{if(!e.ok)throw Error("HTTP ".concat(e.status));return e.json()}).then(e=>{s(e),localStorage.setItem("tenant_agent_base_url",e.api_urls.agent_base_url),localStorage.setItem("tenant_pagos_base_url",e.api_urls.pagos_base_url),localStorage.setItem("tenant_rag_base_url",e.api_urls.rag_base_url),localStorage.setItem("tenant_crawler_base_url",e.api_urls.crawler_base_url),localStorage.setItem("tenant_studio_base_url",e.api_urls.studio_base_url||"https://studio.lyzr.ai"),localStorage.setItem("tenant_metrics_ws_url",e.api_urls.metrics_ws_url||"wss://metrics.studio.lyzr.ai"),document.cookie="tenant_urls=".concat(encodeURIComponent(JSON.stringify(e.api_urls)),";path=/;max-age=300;SameSite=Lax"),localStorage.setItem(t,JSON.stringify({config:e,timestamp:Date.now()}))}).catch(e=>{console.warn("[Tenant] Failed to fetch config, using default:",e),n||s(a)})},[]),n)?(0,r.jsx)(o.Provider,{value:n,children:t}):(0,r.jsxs)("div",{style:{minHeight:"100vh",display:"flex",alignItems:"center",justifyContent:"center"},children:[(0,r.jsx)("div",{style:{width:24,height:24,border:"2px s
1olid #e5e7eb",borderTopColor:"#6b7280",borderRadius:"50%",animation:"spin 0.6s linear infinite"}}),(0,r.jsx)("style",{children:"@keyframes spin { to { transform: rotate(360deg) } }"})]})}},95566:function(e,t,n){function r(e){let t=String(e||"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");return t?"architect-".concat(t):"architect-app"}function i(e){let t=String(e||"").indexOf("-architect-");return t>=0?e.slice(0,t):e}function a(e){let t=String(e.toolName||"").trim(),n=String(e.toolSource||"").trim().toLowerCase();if("mcp"===n||"openapi"===n)return t;let r=e.canonicalProviderId||i(t),a=(e.credentialName||"").trim();return a?"".concat(r,"-").concat(a):r}n.d(t,{EF:function(){return r},eE:function(){return i},ry:function(){return a}})}}]);

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.